2007-07-01 23:30:51 +02:00
|
|
|
/*********************************************
|
|
|
|
* Benjamin Krill <ben@codiert.org>
|
|
|
|
*********************************************/
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
2007-07-09 18:03:50 +02:00
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/mm.h>
|
2007-07-01 23:30:51 +02:00
|
|
|
#include "fpgafs.h"
|
|
|
|
|
2007-07-10 17:07:35 +02:00
|
|
|
static int fpgafs_send_data_dbg(struct fpga_context *ctx, const char __user *buf, int len)
|
2007-07-01 23:30:51 +02:00
|
|
|
{
|
2007-07-06 09:37:25 +02:00
|
|
|
printk("fpgafs: send data DEBUG\n");
|
2007-07-01 23:30:51 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-10 17:07:35 +02:00
|
|
|
static int fpgafs_recv_data_dbg(struct fpga_context *ctx, unsigned char *buf, int len)
|
2007-07-01 23:30:51 +02:00
|
|
|
{
|
2007-07-06 09:37:25 +02:00
|
|
|
printk("fpgafs: receive data DEBUG\n");
|
2007-07-01 23:30:51 +02:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
2007-07-10 17:07:35 +02:00
|
|
|
static int fpgafs_read_load_dbg(struct fpga_context *ctx, unsigned char *buf, int len)
|
2007-07-09 15:12:16 +02:00
|
|
|
{
|
2007-07-10 17:07:35 +02:00
|
|
|
if (ctx->load_buf == NULL)
|
2007-07-09 18:03:50 +02:00
|
|
|
return -EBUSY;
|
|
|
|
|
2007-07-10 17:07:35 +02:00
|
|
|
len = len > sizeof(ctx->load_buf)?sizeof(ctx->load_buf):len;
|
2007-07-09 18:03:50 +02:00
|
|
|
|
2007-07-10 17:07:35 +02:00
|
|
|
if (copy_to_user(buf, ctx->load_buf, len))
|
2007-07-09 18:03:50 +02:00
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
return len;
|
2007-07-09 15:12:16 +02:00
|
|
|
}
|
|
|
|
|
2007-07-10 17:07:35 +02:00
|
|
|
static int fpgafs_write_load_dbg(struct fpga_context *ctx, const char __user *buf, int len)
|
2007-07-09 15:12:16 +02:00
|
|
|
{
|
2007-07-09 18:03:50 +02:00
|
|
|
u32 cp = 0;
|
|
|
|
u8 __user *usr;
|
|
|
|
|
2007-07-10 17:07:35 +02:00
|
|
|
if (ctx->load_buf != NULL)
|
2007-07-09 18:03:50 +02:00
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
if (len < 2)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!access_ok(VERIFY_READ, buf, len))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2007-07-10 17:07:35 +02:00
|
|
|
ctx->load_buf = kmalloc(len,GFP_USER);
|
2007-07-09 18:03:50 +02:00
|
|
|
|
|
|
|
while (cp < len) {
|
|
|
|
usr = (u8*)&buf[cp];
|
2007-07-10 17:07:35 +02:00
|
|
|
if (__get_user(ctx->load_buf[cp], usr))
|
2007-07-09 18:03:50 +02:00
|
|
|
return -EFAULT;
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
2007-07-09 15:12:16 +02:00
|
|
|
}
|
|
|
|
|
2007-07-01 23:30:51 +02:00
|
|
|
static struct fpgafs_lldrv fpgafs_lldrv_dbg = {
|
|
|
|
.name = "dbg",
|
|
|
|
.init = NULL,
|
|
|
|
.exit = NULL,
|
|
|
|
.send = &fpgafs_send_data_dbg,
|
2007-07-09 15:12:16 +02:00
|
|
|
.recv = &fpgafs_recv_data_dbg,
|
|
|
|
.read_load = &fpgafs_read_load_dbg,
|
|
|
|
.write_load = &fpgafs_write_load_dbg,
|
2007-07-01 23:30:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* init exit functions ... */
|
|
|
|
int __init fpgafs_lldrv_dbg_init(void)
|
|
|
|
{
|
|
|
|
return fpgafs_register_lldrv(&fpgafs_lldrv_dbg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __exit fpgafs_lldrv_dbg_exit(void)
|
|
|
|
{
|
|
|
|
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>");
|