37bc27371a
git-svn-id: svn+ssh://en.codiert.org/home/staff/ben/dev/misc.svn/projects/fpgafs@345 766a2236-cff9-0310-b0c0-a81a5f92509a
89 lines
1.9 KiB
C
89 lines
1.9 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 0; // 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;
|
|
|
|
fpgafs_recv_data(NULL, 1);
|
|
return 4;
|
|
}
|
|
|
|
static const struct file_operations fpgafs_stat_fops = {
|
|
.open = fpgafs_open,
|
|
.read = fpgafs_stat_read,
|
|
};
|
|
|
|
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);
|
|
fpgafs_send_data(NULL, 1);
|
|
return 4;
|
|
}
|
|
|
|
static const struct file_operations fpgafs_cmd_fops = {
|
|
.open = fpgafs_open,
|
|
.write = fpgafs_cmd_write,
|
|
};
|
|
|
|
struct tree_descr fpgafs_dir_contents[] = {
|
|
#if 0
|
|
{ "din", &fpgafs_din_fops, 0222, },
|
|
{ "dout", &fpgafs_dout_fops, 0444, },
|
|
{ "load", &fpgafs_load_fops, 0666, },
|
|
#endif
|
|
{ "cmd", &fpgafs_cmd_fops, 0222, },
|
|
{ "stat", &fpgafs_stat_fops, 0444, },
|
|
{},
|
|
};
|