From 96948e503d36a1d6a0a127639cefec55332dca33 Mon Sep 17 00:00:00 2001 From: ben Date: Wed, 12 Sep 2007 15:45:28 +0000 Subject: [PATCH] pimp up the debug low level driver git-svn-id: svn+ssh://en.codiert.org/home/staff/ben/dev/misc.svn/projects/fpgafs@398 766a2236-cff9-0310-b0c0-a81a5f92509a --- fpgafs_lldrv_dbg.c | 51 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-) 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,