2005-04-16 15:20:36 -07:00
|
|
|
/*
|
|
|
|
* arch/um/drivers/mmapper_kern.c
|
|
|
|
*
|
|
|
|
* BRIEF MODULE DESCRIPTION
|
|
|
|
*
|
|
|
|
* Copyright (C) 2000 RidgeRun, Inc.
|
|
|
|
* Author: RidgeRun, Inc.
|
|
|
|
* Greg Lonnon glonnon@ridgerun.com or info@ridgerun.com
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-08-26 22:48:15 -07:00
|
|
|
#include <linux/init.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/mm.h>
|
2005-06-08 15:47:50 -07:00
|
|
|
#include <linux/miscdevice.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
#include <asm/uaccess.h>
|
|
|
|
#include "mem_user.h"
|
|
|
|
#include "user_util.h"
|
|
|
|
|
|
|
|
/* These are set in mmapper_init, which is called at boot time */
|
|
|
|
static unsigned long mmapper_size;
|
|
|
|
static unsigned long p_buf = 0;
|
|
|
|
static char *v_buf = NULL;
|
|
|
|
|
|
|
|
static ssize_t
|
2005-08-26 22:48:15 -07:00
|
|
|
mmapper_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2005-08-26 22:48:15 -07:00
|
|
|
return simple_read_from_buffer(buf, count, ppos, v_buf, mmapper_size);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t
|
2005-08-26 22:48:15 -07:00
|
|
|
mmapper_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2005-08-26 22:48:15 -07:00
|
|
|
if (*ppos > mmapper_size)
|
2005-04-16 15:20:36 -07:00
|
|
|
return -EINVAL;
|
|
|
|
|
2005-08-26 22:48:15 -07:00
|
|
|
if (count > mmapper_size - *ppos)
|
|
|
|
count = mmapper_size - *ppos;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-08-26 22:48:15 -07:00
|
|
|
if (copy_from_user(&v_buf[*ppos], buf, count))
|
|
|
|
return -EFAULT;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mmapper_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
|
|
|
|
unsigned long arg)
|
|
|
|
{
|
|
|
|
return(-ENOIOCTLCMD);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mmapper_mmap(struct file *file, struct vm_area_struct * vma)
|
|
|
|
{
|
|
|
|
int ret = -EINVAL;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
if (vma->vm_pgoff != 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
size = vma->vm_end - vma->vm_start;
|
|
|
|
if(size > mmapper_size) return(-EFAULT);
|
|
|
|
|
|
|
|
/* XXX A comment above remap_pfn_range says it should only be
|
|
|
|
* called when the mm semaphore is held
|
|
|
|
*/
|
|
|
|
if (remap_pfn_range(vma, vma->vm_start, p_buf >> PAGE_SHIFT, size,
|
|
|
|
vma->vm_page_prot))
|
|
|
|
goto out;
|
|
|
|
ret = 0;
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mmapper_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mmapper_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct file_operations mmapper_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.read = mmapper_read,
|
|
|
|
.write = mmapper_write,
|
|
|
|
.ioctl = mmapper_ioctl,
|
|
|
|
.mmap = mmapper_mmap,
|
|
|
|
.open = mmapper_open,
|
|
|
|
.release = mmapper_release,
|
|
|
|
};
|
|
|
|
|
2005-06-08 15:47:50 -07:00
|
|
|
static struct miscdevice mmapper_dev = {
|
|
|
|
.minor = MISC_DYNAMIC_MINOR,
|
|
|
|
.name = "mmapper",
|
|
|
|
.fops = &mmapper_fops
|
|
|
|
};
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
static int __init mmapper_init(void)
|
|
|
|
{
|
2005-06-08 15:47:50 -07:00
|
|
|
int err;
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
printk(KERN_INFO "Mapper v0.1\n");
|
|
|
|
|
|
|
|
v_buf = (char *) find_iomem("mmapper", &mmapper_size);
|
|
|
|
if(mmapper_size == 0){
|
|
|
|
printk(KERN_ERR "mmapper_init - find_iomem failed\n");
|
2005-06-08 15:47:50 -07:00
|
|
|
goto out;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2005-06-08 15:47:50 -07:00
|
|
|
err = misc_register(&mmapper_dev);
|
|
|
|
if(err){
|
|
|
|
printk(KERN_ERR "mmapper - misc_register failed, err = %d\n",
|
|
|
|
err);
|
|
|
|
goto out;
|
|
|
|
}
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-06-08 15:47:50 -07:00
|
|
|
p_buf = __pa(v_buf);
|
|
|
|
out:
|
|
|
|
return 0;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void mmapper_exit(void)
|
|
|
|
{
|
2005-06-08 15:47:50 -07:00
|
|
|
misc_deregister(&mmapper_dev);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(mmapper_init);
|
|
|
|
module_exit(mmapper_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Greg Lonnon <glonnon@ridgerun.com>");
|
|
|
|
MODULE_DESCRIPTION("DSPLinux simulator mmapper driver");
|
|
|
|
/*
|
|
|
|
* ---------------------------------------------------------------------------
|
|
|
|
* Local variables:
|
|
|
|
* c-file-style: "linux"
|
|
|
|
* End:
|
|
|
|
*/
|