2007-06-28 22:43:40 +02:00
|
|
|
/*********************************************
|
|
|
|
* Benjamin Krill <ben@codiert.org>
|
|
|
|
*********************************************/
|
2007-06-28 18:20:34 +02:00
|
|
|
#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"
|
|
|
|
|
2007-07-01 11:55:49 +02:00
|
|
|
static unsigned int stat;
|
|
|
|
|
|
|
|
static int do_cmd(u32 cmd, u32 data)
|
|
|
|
{
|
|
|
|
switch(cmd) {
|
|
|
|
case BLA:
|
|
|
|
stat = data;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-06-28 18:20:34 +02:00
|
|
|
/* generic open function for all pipe-like files */
|
2007-07-01 11:55:49 +02:00
|
|
|
static int fpgafs_open(struct inode *inode, struct file *file)
|
2007-06-28 18:20:34 +02:00
|
|
|
{
|
2007-07-10 17:07:35 +02:00
|
|
|
struct fpgafs_inode_info *i = FPGAFS_I(inode);
|
|
|
|
file->private_data = i->i_ctx;
|
2007-06-28 18:20:34 +02:00
|
|
|
|
2007-07-10 17:07:35 +02:00
|
|
|
return nonseekable_open(inode, file);
|
2007-06-28 18:20:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t fpgafs_stat_read(struct file *file, char __user *buf,
|
2007-07-01 11:55:49 +02:00
|
|
|
size_t len, loff_t *pos)
|
2007-07-10 09:29:41 +02:00
|
|
|
{
|
2007-06-28 22:45:45 +02:00
|
|
|
//struct fpga_context *ctx = file->private_data;
|
2007-07-01 11:55:49 +02:00
|
|
|
u32 data;
|
|
|
|
data=stat;
|
2007-06-28 18:20:34 +02:00
|
|
|
|
2007-07-01 11:55:49 +02:00
|
|
|
if (copy_to_user(buf, &data, sizeof(data)))
|
|
|
|
return -EFAULT;
|
2007-06-28 18:20:34 +02:00
|
|
|
|
2007-07-01 11:55:49 +02:00
|
|
|
return 4;
|
|
|
|
}
|
2007-06-28 18:20:34 +02:00
|
|
|
|
2007-07-01 11:55:49 +02:00
|
|
|
static ssize_t fpgafs_cmd_write(struct file *file, const char __user *buf,
|
|
|
|
size_t len, loff_t *pos)
|
|
|
|
{
|
|
|
|
u32 data, __user *udata;
|
2007-06-28 18:20:34 +02:00
|
|
|
|
2007-07-01 11:55:49 +02:00
|
|
|
if (len < 4)
|
|
|
|
return -EINVAL;
|
2007-06-28 18:20:34 +02:00
|
|
|
|
2007-07-01 11:55:49 +02:00
|
|
|
udata = (void __user *)buf;
|
|
|
|
if (!access_ok(VERIFY_READ, buf, len))
|
|
|
|
return -EFAULT;
|
2007-06-28 18:20:34 +02:00
|
|
|
|
2007-07-01 11:55:49 +02:00
|
|
|
if (__get_user(data, udata))
|
|
|
|
return -EFAULT;
|
2007-06-28 18:20:34 +02:00
|
|
|
|
2007-07-01 11:55:49 +02:00
|
|
|
do_cmd(BLA,data);
|
|
|
|
return 4;
|
2007-06-28 18:20:34 +02:00
|
|
|
}
|
|
|
|
|
2007-09-10 09:45:12 +02:00
|
|
|
static const struct file_operations fpgafs_stat_fops = {
|
|
|
|
.open = fpgafs_open,
|
|
|
|
.read = fpgafs_stat_read,
|
|
|
|
};
|
|
|
|
|
2007-07-01 11:55:49 +02:00
|
|
|
static const struct file_operations fpgafs_cmd_fops = {
|
|
|
|
.open = fpgafs_open,
|
|
|
|
.write = fpgafs_cmd_write,
|
2007-06-28 18:20:34 +02:00
|
|
|
};
|
|
|
|
|
2007-07-09 15:12:16 +02:00
|
|
|
static const struct file_operations fpgafs_load_fops = {
|
|
|
|
.open = fpgafs_open,
|
2007-07-10 16:18:07 +02:00
|
|
|
.write = fpgafs_write_load,
|
|
|
|
.read = fpgafs_read_load,
|
2007-07-09 15:12:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2007-09-10 09:45:12 +02:00
|
|
|
static const struct file_operations fpgafs_lldrv_fops = {
|
|
|
|
.open = fpgafs_open,
|
|
|
|
.write = fpgafs_write_lldrv,
|
|
|
|
.read = fpgafs_read_lldrv,
|
|
|
|
};
|
|
|
|
|
2007-06-28 18:20:34 +02:00
|
|
|
struct tree_descr fpgafs_dir_contents[] = {
|
2007-07-01 11:55:49 +02:00
|
|
|
{ "din", &fpgafs_din_fops, 0222, },
|
|
|
|
{ "dout", &fpgafs_dout_fops, 0444, },
|
|
|
|
{ "load", &fpgafs_load_fops, 0666, },
|
|
|
|
{ "cmd", &fpgafs_cmd_fops, 0222, },
|
2007-06-28 18:20:34 +02:00
|
|
|
{ "stat", &fpgafs_stat_fops, 0444, },
|
2007-09-10 09:45:12 +02:00
|
|
|
{ "lldrv", &fpgafs_lldrv_fops, 0444, },
|
2007-06-28 18:20:34 +02:00
|
|
|
{},
|
|
|
|
};
|