2007-10-21 12:11:55 +02:00
|
|
|
/* *****************************************************************
|
|
|
|
* (C) Copyright 2007 Benjamin Krill <ben@codiert.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
|
|
|
* MA 02110-1301 USA
|
|
|
|
* *****************************************************************/
|
2007-07-01 23:30:51 +02:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
2007-07-09 18:03:50 +02:00
|
|
|
#include <linux/pagemap.h>
|
2011-03-23 12:55:48 +01:00
|
|
|
#include <linux/slab.h>
|
2007-07-09 18:03:50 +02:00
|
|
|
#include <linux/mm.h>
|
2007-07-01 23:30:51 +02:00
|
|
|
#include "fpgafs.h"
|
|
|
|
|
2007-09-12 17:45:28 +02:00
|
|
|
#define MEM_SIZE 255
|
|
|
|
/* some test memory */
|
|
|
|
static char *mem;
|
2007-09-23 14:31:38 +02:00
|
|
|
static unsigned int stat;
|
|
|
|
|
2011-03-23 22:36:58 +01:00
|
|
|
static int do_cmd(uint32_t cmd, uint32_t data)
|
2007-09-23 14:31:38 +02:00
|
|
|
{
|
|
|
|
switch(cmd) {
|
|
|
|
case BLA:
|
|
|
|
stat = data;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fpgafs_stat_dbg(struct fpga_context *ctx, unsigned char *buf, int len)
|
|
|
|
{
|
|
|
|
//struct fpga_context *ctx = file->private_data;
|
2011-03-23 22:36:58 +01:00
|
|
|
uint32_t data;
|
2007-09-23 14:31:38 +02:00
|
|
|
data=stat;
|
|
|
|
|
|
|
|
if (copy_to_user(buf, &data, sizeof(data)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fpgafs_cmd_dbg(struct fpga_context *ctx, const char __user *buf, int len)
|
|
|
|
{
|
2011-03-23 22:36:58 +01:00
|
|
|
uint32_t data, __user *udata;
|
2007-09-23 14:31:38 +02:00
|
|
|
|
|
|
|
if (len < 4)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
udata = (void __user *)buf;
|
|
|
|
if (!access_ok(VERIFY_READ, buf, len))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
if (__get_user(data, udata))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
do_cmd(BLA,data);
|
|
|
|
return 4;
|
|
|
|
}
|
2007-09-12 17:45:28 +02:00
|
|
|
|
2007-07-10 17:07:35 +02:00
|
|
|
static int fpgafs_send_data_dbg(struct fpga_context *ctx, const char __user *buf, int len)
|
2007-07-01 23:30:51 +02:00
|
|
|
{
|
2011-03-23 22:36:58 +01:00
|
|
|
uint32_t cp = 0;
|
|
|
|
uint8_t __user *usr;
|
2007-09-12 17:45:28 +02:00
|
|
|
|
|
|
|
if (mem == NULL)
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
len = (len > MEM_SIZE)?MEM_SIZE:len;
|
|
|
|
|
|
|
|
if (len < 2)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!access_ok(VERIFY_READ, buf, len))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
while (cp < len) {
|
2011-03-23 22:36:58 +01:00
|
|
|
usr = (uint8_t*)&buf[cp];
|
2007-09-12 17:45:28 +02:00
|
|
|
if (__get_user(mem[cp], usr))
|
|
|
|
return -EFAULT;
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
2007-07-01 23:30:51 +02:00
|
|
|
}
|
|
|
|
|
2007-07-10 17:07:35 +02:00
|
|
|
static int fpgafs_recv_data_dbg(struct fpga_context *ctx, unsigned char *buf, int len)
|
2007-07-01 23:30:51 +02:00
|
|
|
{
|
2007-07-06 09:37:25 +02:00
|
|
|
printk("fpgafs: receive data DEBUG\n");
|
2007-09-12 17:45:28 +02:00
|
|
|
len = (len > MEM_SIZE)?MEM_SIZE:len;
|
|
|
|
if (copy_to_user(buf, mem, len))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
return len;
|
2007-07-01 23:30:51 +02:00
|
|
|
}
|
|
|
|
|
2007-07-10 17:07:35 +02:00
|
|
|
static int fpgafs_read_load_dbg(struct fpga_context *ctx, unsigned char *buf, int len)
|
2007-07-09 15:12:16 +02:00
|
|
|
{
|
2007-07-10 17:07:35 +02:00
|
|
|
if (ctx->load_buf == NULL)
|
2007-07-09 18:03:50 +02:00
|
|
|
return -EBUSY;
|
|
|
|
|
2007-07-10 17:07:35 +02:00
|
|
|
len = len > sizeof(ctx->load_buf)?sizeof(ctx->load_buf):len;
|
2007-07-09 18:03:50 +02:00
|
|
|
|
2007-07-10 17:07:35 +02:00
|
|
|
if (copy_to_user(buf, ctx->load_buf, len))
|
2007-07-09 18:03:50 +02:00
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
return len;
|
2007-07-09 15:12:16 +02:00
|
|
|
}
|
|
|
|
|
2007-07-10 17:07:35 +02:00
|
|
|
static int fpgafs_write_load_dbg(struct fpga_context *ctx, const char __user *buf, int len)
|
2007-07-09 15:12:16 +02:00
|
|
|
{
|
2011-03-23 22:36:58 +01:00
|
|
|
uint32_t cp = 0;
|
|
|
|
uint8_t __user *usr;
|
2007-07-10 17:07:35 +02:00
|
|
|
if (ctx->load_buf != NULL)
|
2007-07-09 18:03:50 +02:00
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
if (len < 2)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!access_ok(VERIFY_READ, buf, len))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2011-03-23 22:36:58 +01:00
|
|
|
ctx->load_buf = kmalloc(len, GFP_USER);
|
2007-07-09 18:03:50 +02:00
|
|
|
|
|
|
|
while (cp < len) {
|
2011-03-23 22:36:58 +01:00
|
|
|
usr = (uint8_t*)&buf[cp];
|
2007-07-10 17:07:35 +02:00
|
|
|
if (__get_user(ctx->load_buf[cp], usr))
|
2007-07-09 18:03:50 +02:00
|
|
|
return -EFAULT;
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
2007-07-09 15:12:16 +02:00
|
|
|
}
|
|
|
|
|
2007-09-12 17:45:28 +02:00
|
|
|
|
|
|
|
static int fpgafs_init_dbg(void)
|
|
|
|
{
|
2011-03-23 22:36:58 +01:00
|
|
|
mem = kmalloc(MEM_SIZE, GFP_USER);
|
2007-09-12 17:45:28 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fpgafs_exit_dbg(void)
|
|
|
|
{
|
|
|
|
kfree(mem);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-01 23:30:51 +02:00
|
|
|
static struct fpgafs_lldrv fpgafs_lldrv_dbg = {
|
|
|
|
.name = "dbg",
|
2007-09-12 17:45:28 +02:00
|
|
|
.init = fpgafs_init_dbg,
|
|
|
|
.exit = fpgafs_exit_dbg,
|
2007-07-01 23:30:51 +02:00
|
|
|
.send = &fpgafs_send_data_dbg,
|
2007-07-09 15:12:16 +02:00
|
|
|
.recv = &fpgafs_recv_data_dbg,
|
2007-09-23 14:31:38 +02:00
|
|
|
.stat = &fpgafs_stat_dbg,
|
|
|
|
.cmd = &fpgafs_cmd_dbg,
|
2007-07-09 15:12:16 +02:00
|
|
|
.read_load = &fpgafs_read_load_dbg,
|
|
|
|
.write_load = &fpgafs_write_load_dbg,
|
2007-07-01 23:30:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* init exit functions ... */
|
|
|
|
int __init fpgafs_lldrv_dbg_init(void)
|
|
|
|
{
|
|
|
|
return fpgafs_register_lldrv(&fpgafs_lldrv_dbg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __exit fpgafs_lldrv_dbg_exit(void)
|
|
|
|
{
|
|
|
|
fpgafs_unregister_lldrv(&fpgafs_lldrv_dbg);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(fpgafs_lldrv_dbg_init);
|
|
|
|
module_exit(fpgafs_lldrv_dbg_exit);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Benjamin Krill <ben@codiert.org>");
|