add basic write/read commands for file cmd and stat
git-svn-id: svn+ssh://en.codiert.org/home/staff/ben/dev/misc.svn/projects/fpgafs@343 766a2236-cff9-0310-b0c0-a81a5f92509a
This commit is contained in:
parent
267d5afeab
commit
593371de82
88
files.c
88
files.c
@ -9,66 +9,78 @@
|
|||||||
#include <linux/pagemap.h>
|
#include <linux/pagemap.h>
|
||||||
#include "fpgafs.h"
|
#include "fpgafs.h"
|
||||||
|
|
||||||
/* generic open function for all pipe-like files */
|
static unsigned int stat;
|
||||||
static int fpgafs_pipe_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 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,
|
static ssize_t fpgafs_stat_read(struct file *file, char __user *buf,
|
||||||
size_t len, loff_t *pos)
|
size_t len, loff_t *pos)
|
||||||
{
|
{
|
||||||
//struct fpga_context *ctx = file->private_data;
|
//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;
|
u32 data, __user *udata;
|
||||||
ssize_t count;
|
|
||||||
|
|
||||||
if (len < 4)
|
if (len < 4)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (!access_ok(VERIFY_WRITE, buf, len))
|
udata = (void __user *)buf;
|
||||||
|
if (!access_ok(VERIFY_READ, buf, len))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
udata = (void __user *)buf;
|
if (__get_user(data, udata))
|
||||||
|
return -EFAULT;
|
||||||
|
|
||||||
for (count = 0; (count + 4) <= len; count += 4, udata++) {
|
do_cmd(BLA,data);
|
||||||
int ret;
|
return 4;
|
||||||
|
|
||||||
/* operation to read the status ... */
|
|
||||||
data=0x42;
|
|
||||||
ret = 0;
|
|
||||||
if (ret == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
ret = __put_user(data, udata);
|
|
||||||
|
|
||||||
if (ret) {
|
|
||||||
if (!count)
|
|
||||||
count = -EFAULT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!count)
|
static const struct file_operations fpgafs_cmd_fops = {
|
||||||
count = -EAGAIN;
|
.open = fpgafs_open,
|
||||||
|
.write = fpgafs_cmd_write,
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const struct file_operations fpgafs_stat_fops = {
|
|
||||||
.open = fpgafs_pipe_open,
|
|
||||||
.read = fpgafs_stat_read,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct tree_descr fpgafs_dir_contents[] = {
|
struct tree_descr fpgafs_dir_contents[] = {
|
||||||
#if 0
|
#if 0
|
||||||
{ "cmd", &fpgafs_cmd_fops, 0222, },
|
{ "din", &fpgafs_din_fops, 0222, },
|
||||||
{ "din", &spufs_mbox_fops, 0222, },
|
{ "dout", &fpgafs_dout_fops, 0444, },
|
||||||
{ "dout", &spufs_ibox_fops, 0444, },
|
{ "load", &fpgafs_load_fops, 0666, },
|
||||||
{ "load", &spufs_wbox_fops, 0666, },
|
|
||||||
#endif
|
#endif
|
||||||
|
{ "cmd", &fpgafs_cmd_fops, 0222, },
|
||||||
{ "stat", &fpgafs_stat_fops, 0444, },
|
{ "stat", &fpgafs_stat_fops, 0444, },
|
||||||
{},
|
{},
|
||||||
};
|
};
|
||||||
|
2
fpgafs.h
2
fpgafs.h
@ -26,4 +26,6 @@ extern struct tree_descr fpgafs_dir_contents[];
|
|||||||
#define FPGAFS_I(inode) \
|
#define FPGAFS_I(inode) \
|
||||||
container_of(inode, struct fpgafs_inode_info, vfs_inode)
|
container_of(inode, struct fpgafs_inode_info, vfs_inode)
|
||||||
|
|
||||||
|
#define BLA 0
|
||||||
|
|
||||||
#endif /* FPGAFS_H */
|
#endif /* FPGAFS_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user