From 11248b2a7920fb1df34837cf59a130ac6c5786c2 Mon Sep 17 00:00:00 2001 From: ben Date: Sun, 23 Sep 2007 12:31:38 +0000 Subject: [PATCH] add cmd and stat into lldrv structure git-svn-id: svn+ssh://en.codiert.org/home/staff/ben/dev/misc.svn/projects/fpgafs@418 766a2236-cff9-0310-b0c0-a81a5f92509a --- files.c | 50 ++-------------------------------------------- fpgafs.h | 8 ++++++++ fpgafs_lldrv_dbg.c | 45 +++++++++++++++++++++++++++++++++++++++++ llmgmt.c | 18 +++++++++++++++++ 4 files changed, 73 insertions(+), 48 deletions(-) diff --git a/files.c b/files.c index be6306e..85c206c 100644 --- a/files.c +++ b/files.c @@ -9,20 +9,6 @@ #include #include "fpgafs.h" -static unsigned int stat; - -static int do_cmd(u32 cmd, u32 data) -{ - switch(cmd) { - case BLA: - stat = data; - break; - default: - return -EFAULT; - } - return 0; -} - /* generic open function for all pipe-like files */ static int fpgafs_open(struct inode *inode, struct file *file) { @@ -32,46 +18,14 @@ static int fpgafs_open(struct inode *inode, struct file *file) return nonseekable_open(inode, file); } -static ssize_t fpgafs_stat_read(struct file *file, char __user *buf, - size_t len, loff_t *pos) -{ - //struct fpga_context *ctx = file->private_data; - u32 data; - data=stat; - - if (copy_to_user(buf, &data, sizeof(data))) - return -EFAULT; - - return 4; -} - -static ssize_t fpgafs_cmd_write(struct file *file, const char __user *buf, - size_t len, loff_t *pos) -{ - u32 data, __user *udata; - - 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; -} - static const struct file_operations fpgafs_stat_fops = { .open = fpgafs_open, - .read = fpgafs_stat_read, + .read = fpgafs_read_stat, }; static const struct file_operations fpgafs_cmd_fops = { .open = fpgafs_open, - .write = fpgafs_cmd_write, + .write = fpgafs_write_cmd, }; static const struct file_operations fpgafs_load_fops = { diff --git a/fpgafs.h b/fpgafs.h index f42a924..b6abf46 100644 --- a/fpgafs.h +++ b/fpgafs.h @@ -44,6 +44,9 @@ struct fpgafs_lldrv { int (*send) (struct fpga_context *ctx, const char __user *buf, int len); int (*recv) (struct fpga_context *ctx, unsigned char *buf, int len); + int (*cmd) (struct fpga_context *ctx, const char __user *buf, int len); + int (*stat) (struct fpga_context *ctx, unsigned char *buf, int len); + int (*read_load) (struct fpga_context *ctx, unsigned char *buf, int len); int (*write_load) (struct fpga_context *ctx, const char __user *buf, int len); }; @@ -66,6 +69,11 @@ ssize_t fpgafs_write_lldrv(struct file *file, const char __user *buf, ssize_t fpgafs_read_lldrv(struct file *file, char __user *buf, size_t len, loff_t *pos); +ssize_t fpgafs_read_stat(struct file *file, char __user *buf, + size_t len, loff_t *pos); +ssize_t fpgafs_write_cmd(struct file *file, const char __user *buf, + size_t len, loff_t *pos); + struct fpga_context* alloc_fpga_context(void); void free_fpga_context(struct fpga_context *ctx); #endif /* FPGAFS_H */ diff --git a/fpgafs_lldrv_dbg.c b/fpgafs_lldrv_dbg.c index b942920..8131252 100644 --- a/fpgafs_lldrv_dbg.c +++ b/fpgafs_lldrv_dbg.c @@ -11,6 +11,49 @@ #define MEM_SIZE 255 /* some test memory */ static char *mem; +static unsigned int stat; + +static int do_cmd(u32 cmd, u32 data) +{ + 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; + u32 data; + 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) +{ + u32 data, __user *udata; + + 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; +} static int fpgafs_send_data_dbg(struct fpga_context *ctx, const char __user *buf, int len) { @@ -106,6 +149,8 @@ static struct fpgafs_lldrv fpgafs_lldrv_dbg = { .exit = fpgafs_exit_dbg, .send = &fpgafs_send_data_dbg, .recv = &fpgafs_recv_data_dbg, + .stat = &fpgafs_stat_dbg, + .cmd = &fpgafs_cmd_dbg, .read_load = &fpgafs_read_load_dbg, .write_load = &fpgafs_write_load_dbg, }; diff --git a/llmgmt.c b/llmgmt.c index a7eed42..662175b 100644 --- a/llmgmt.c +++ b/llmgmt.c @@ -128,6 +128,24 @@ ssize_t fpgafs_write_lldrv(struct file *file, const char __user *buf, } //EXPORT_SYMBOL_GPL(fpgafs_write_lldrv); +ssize_t fpgafs_read_stat(struct file *file, char __user *buf, + size_t len, loff_t *pos) +{ + struct fpga_context *fcur = (struct fpga_context*)file->private_data; + return (fcur->lldrv > -1) ? + lldrv[fcur->lldrv]->stat(fcur, buf, len) + : -EBUSY; +} + +ssize_t fpgafs_write_cmd(struct file *file, const char __user *buf, + size_t len, loff_t *pos) +{ + struct fpga_context *fcur = (struct fpga_context*)file->private_data; + return (fcur->lldrv > -1) ? + lldrv[fcur->lldrv]->cmd(fcur, buf, len) + : -EBUSY; +} + /* low level un-/register functions */ int fpgafs_register_lldrv(struct fpgafs_lldrv *drv) {