2007-10-21 12:11:55 +02:00
|
|
|
/* *****************************************************************
|
|
|
|
* (C) Copyright 2007 Benjamin Krill <ben@codiert.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
|
|
|
* MA 02110-1301 USA
|
|
|
|
* *****************************************************************/
|
2007-07-01 23:30:51 +02:00
|
|
|
#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-09-12 17:45:28 +02:00
|
|
|
#define MEM_SIZE 255
|
|
|
|
/* some test memory */
|
|
|
|
static char *mem;
|
2007-09-23 14:31:38 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fpgafs_stat_dbg(struct fpga_context *ctx, unsigned char *buf, int len)
|
|
|
|
{
|
|
|
|
//struct fpga_context *ctx = file->private_data;
|
|
|
|
u32 data;
|
|
|
|
data=stat;
|
|
|
|
|
|
|
|
if (copy_to_user(buf, &data, sizeof(data)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fpgafs_cmd_dbg(struct fpga_context *ctx, const char __user *buf, int len)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2007-09-12 17:45:28 +02:00
|
|
|
|
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-09-12 17:45:28 +02:00
|
|
|
u32 cp = 0;
|
|
|
|
u8 __user *usr;
|
|
|
|
|
|
|
|
if (mem == NULL)
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
len = (len > MEM_SIZE)?MEM_SIZE:len;
|
|
|
|
|
|
|
|
if (len < 2)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!access_ok(VERIFY_READ, buf, len))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
while (cp < len) {
|
|
|
|
usr = (u8*)&buf[cp];
|
|
|
|
if (__get_user(mem[cp], usr))
|
|
|
|
return -EFAULT;
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
2007-07-01 23:30:51 +02:00
|
|
|
}
|
|
|
|
|
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-09-12 17:45:28 +02:00
|
|
|
len = (len > MEM_SIZE)?MEM_SIZE:len;
|
|
|
|
if (copy_to_user(buf, mem, len))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
return len;
|
2007-07-01 23:30:51 +02:00
|
|
|
}
|
|
|
|
|
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-09-12 17:45:28 +02:00
|
|
|
|
|
|
|
static int fpgafs_init_dbg(void)
|
|
|
|
{
|
|
|
|
mem = kmalloc(MEM_SIZE,GFP_USER);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fpgafs_exit_dbg(void)
|
|
|
|
{
|
|
|
|
kfree(mem);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-01 23:30:51 +02:00
|
|
|
static struct fpgafs_lldrv fpgafs_lldrv_dbg = {
|
|
|
|
.name = "dbg",
|
2007-09-12 17:45:28 +02:00
|
|
|
.init = fpgafs_init_dbg,
|
|
|
|
.exit = fpgafs_exit_dbg,
|
2007-07-01 23:30:51 +02:00
|
|
|
.send = &fpgafs_send_data_dbg,
|
2007-07-09 15:12:16 +02:00
|
|
|
.recv = &fpgafs_recv_data_dbg,
|
2007-09-23 14:31:38 +02:00
|
|
|
.stat = &fpgafs_stat_dbg,
|
|
|
|
.cmd = &fpgafs_cmd_dbg,
|
2007-07-09 15:12:16 +02:00
|
|
|
.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>");
|