501ef6658d
git-svn-id: svn+ssh://en.codiert.org/home/staff/ben/dev/misc.svn/projects/fpgafs@358 766a2236-cff9-0310-b0c0-a81a5f92509a
94 lines
1.8 KiB
C
94 lines
1.8 KiB
C
/*********************************************
|
|
* Benjamin Krill <ben@codiert.org>
|
|
*********************************************/
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/init.h>
|
|
#include <linux/pagemap.h>
|
|
#include <linux/mm.h>
|
|
#include "fpgafs.h"
|
|
|
|
static int load = 0;
|
|
static unsigned char *load_buf;
|
|
|
|
static int fpgafs_send_data_dbg(const char __user *buf, int len)
|
|
{
|
|
printk("fpgafs: send data DEBUG\n");
|
|
return 0;
|
|
}
|
|
|
|
static int fpgafs_recv_data_dbg(unsigned char *buf, int len)
|
|
{
|
|
printk("fpgafs: receive data DEBUG\n");
|
|
return 4;
|
|
}
|
|
|
|
static int fpgafs_read_load_dbg(unsigned char *buf, int len)
|
|
{
|
|
if (load == 0)
|
|
return -EBUSY;
|
|
|
|
len = len > sizeof(load_buf)?sizeof(load_buf):len;
|
|
|
|
if (copy_to_user(buf, load_buf, len))
|
|
return -EFAULT;
|
|
|
|
return len;
|
|
}
|
|
|
|
static int fpgafs_write_load_dbg(const char __user *buf, int len)
|
|
{
|
|
u32 cp = 0;
|
|
u8 __user *usr;
|
|
|
|
if (load == 1)
|
|
return -EBUSY;
|
|
|
|
if (len < 2)
|
|
return -EINVAL;
|
|
|
|
if (!access_ok(VERIFY_READ, buf, len))
|
|
return -EFAULT;
|
|
|
|
load_buf = kmalloc(len,GFP_USER);
|
|
|
|
while (cp < len) {
|
|
usr = (u8*)&buf[cp];
|
|
if (__get_user(load_buf[cp], usr))
|
|
return -EFAULT;
|
|
cp++;
|
|
}
|
|
|
|
load = 1;
|
|
return len;
|
|
}
|
|
|
|
static struct fpgafs_lldrv fpgafs_lldrv_dbg = {
|
|
.name = "dbg",
|
|
.init = NULL,
|
|
.exit = NULL,
|
|
.send = &fpgafs_send_data_dbg,
|
|
.recv = &fpgafs_recv_data_dbg,
|
|
.read_load = &fpgafs_read_load_dbg,
|
|
.write_load = &fpgafs_write_load_dbg,
|
|
};
|
|
|
|
/* init exit functions ... */
|
|
int __init fpgafs_lldrv_dbg_init(void)
|
|
{
|
|
return fpgafs_register_lldrv(&fpgafs_lldrv_dbg);
|
|
}
|
|
|
|
void __exit fpgafs_lldrv_dbg_exit(void)
|
|
{
|
|
load = 0;
|
|
kfree(load_buf);
|
|
fpgafs_unregister_lldrv(&fpgafs_lldrv_dbg);
|
|
}
|
|
|
|
module_init(fpgafs_lldrv_dbg_init);
|
|
module_exit(fpgafs_lldrv_dbg_exit);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_AUTHOR("Benjamin Krill <ben@codiert.org>");
|