fpgafs/files.c

102 lines
2.1 KiB
C
Raw Normal View History

/*********************************************
* 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);
return 0;
}
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 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);
return 4;
}
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,
};
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, },
{},
};