fpgafs/files.c
ben 24c36a0d8d add multi low level driver support, use kernel<->user-space copy functions
git-svn-id: svn+ssh://en.codiert.org/home/staff/ben/dev/misc.svn/projects/fpgafs@389 766a2236-cff9-0310-b0c0-a81a5f92509a
2007-09-10 07:45:12 +00:00

108 lines
2.3 KiB
C

/*********************************************
* Benjamin Krill <ben@codiert.org>
*********************************************/
#include <linux/fs.h>
#include <linux/module.h>
#include <linux/version.h>
#include <linux/init.h>
#include <linux/fs.h>
#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)
{
struct fpgafs_inode_info *i = FPGAFS_I(inode);
file->private_data = i->i_ctx;
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,
};
static const struct file_operations fpgafs_cmd_fops = {
.open = fpgafs_open,
.write = fpgafs_cmd_write,
};
static const struct file_operations fpgafs_load_fops = {
.open = fpgafs_open,
.write = fpgafs_write_load,
.read = fpgafs_read_load,
};
static const struct file_operations fpgafs_din_fops = {
.open = fpgafs_open,
.read = fpgafs_recv_data,
};
static const struct file_operations fpgafs_dout_fops = {
.open = fpgafs_open,
.write = fpgafs_send_data,
};
static const struct file_operations fpgafs_lldrv_fops = {
.open = fpgafs_open,
.write = fpgafs_write_lldrv,
.read = fpgafs_read_lldrv,
};
struct tree_descr fpgafs_dir_contents[] = {
{ "din", &fpgafs_din_fops, 0222, },
{ "dout", &fpgafs_dout_fops, 0444, },
{ "load", &fpgafs_load_fops, 0666, },
{ "cmd", &fpgafs_cmd_fops, 0222, },
{ "stat", &fpgafs_stat_fops, 0444, },
{ "lldrv", &fpgafs_lldrv_fops, 0444, },
{},
};