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
This commit is contained in:
ben 2007-09-23 12:31:38 +00:00
parent 0ae8873d37
commit 11248b2a79
4 changed files with 73 additions and 48 deletions

50
files.c
View File

@ -9,20 +9,6 @@
#include <linux/pagemap.h>
#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 = {

View File

@ -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 */

View File

@ -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,
};

View File

@ -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)
{