diff --git a/fpgafs_lldrv_dbg.c b/fpgafs_lldrv_dbg.c index f457c1b..b942920 100644 --- a/fpgafs_lldrv_dbg.c +++ b/fpgafs_lldrv_dbg.c @@ -8,16 +8,44 @@ #include #include "fpgafs.h" +#define MEM_SIZE 255 +/* some test memory */ +static char *mem; + static int fpgafs_send_data_dbg(struct fpga_context *ctx, const char __user *buf, int len) { - printk("fpgafs: send data DEBUG\n"); - return 0; + u32 cp = 0; + u8 __user *usr; + + 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) { + usr = (u8*)&buf[cp]; + if (__get_user(mem[cp], usr)) + return -EFAULT; + cp++; + } + + return len; } static int fpgafs_recv_data_dbg(struct fpga_context *ctx, unsigned char *buf, int len) { printk("fpgafs: receive data DEBUG\n"); - return 4; + len = (len > MEM_SIZE)?MEM_SIZE:len; + if (copy_to_user(buf, mem, len)) + return -EFAULT; + + return len; } static int fpgafs_read_load_dbg(struct fpga_context *ctx, unsigned char *buf, int len) @@ -59,10 +87,23 @@ static int fpgafs_write_load_dbg(struct fpga_context *ctx, const char __user *bu return len; } + +static int fpgafs_init_dbg(void) +{ + mem = kmalloc(MEM_SIZE,GFP_USER); + return 0; +} + +static int fpgafs_exit_dbg(void) +{ + kfree(mem); + return 0; +} + static struct fpgafs_lldrv fpgafs_lldrv_dbg = { .name = "dbg", - .init = NULL, - .exit = NULL, + .init = fpgafs_init_dbg, + .exit = fpgafs_exit_dbg, .send = &fpgafs_send_data_dbg, .recv = &fpgafs_recv_data_dbg, .read_load = &fpgafs_read_load_dbg,