diff -Naur -X exclude-files ac_cur/arch/um/drivers/mmapper_kern.c ac/arch/um/drivers/mmapper_kern.c --- ac_cur/arch/um/drivers/mmapper_kern.c Fri Oct 5 13:57:59 2001 +++ ac/arch/um/drivers/mmapper_kern.c Fri Oct 5 13:57:17 2001 @@ -13,49 +13,63 @@ #include #include #include -#include +#include #include #include #include #include #include - +#include "mem_user.h" #include "user_util.h" -int mmapper_size = 100 *1024; -char *mmapper_buffer = NULL; +static unsigned long mmapper_size; +static char *p_buf = NULL; +static char *v_buf = NULL; static ssize_t mmapper_read(struct file *file, char *buf, size_t count, loff_t *ppos) { - return(-EINVAL); + if(*ppos > mmapper_size) + return -EINVAL; + + if(count + *ppos > mmapper_size) + count = count + *ppos - mmapper_size; + + if(count < 0) + return -EINVAL; + + copy_to_user(buf,&v_buf[*ppos],count); + + return count; } static ssize_t mmapper_write(struct file *file, const char *buf, size_t count, loff_t *ppos) { - return(-EINVAL); + if(*ppos > mmapper_size) + return -EINVAL; + + if(count + *ppos > mmapper_size) + count = count + *ppos - mmapper_size; + + if(count < 0) + return -EINVAL; + + copy_from_user(&v_buf[*ppos],buf,count); + + return count; } static int mmapper_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) { - switch(cmd) { - - case 1: - return mmapper_size; - break; - case 2: - break; - } - return 0; + return(-ENOIOCTLCMD); } static int mmapper_mmap(struct file *file, struct vm_area_struct * vma) { - unsigned long mystart = (unsigned long)mmapper_buffer; int ret = -EINVAL; int size; @@ -64,8 +78,11 @@ goto out; size = vma->vm_end - vma->vm_start; - - if (remap_page_range(vma->vm_start,mmapper_buffer, + + /* XXX A comment above remap_page_range says it should only be + * called when the mm semaphore is held + */ + if (remap_page_range(vma->vm_start, (unsigned long) p_buf, size, vma->vm_page_prot)) goto out; ret = 0; @@ -86,7 +103,6 @@ return 0; } - static struct file_operations mmapper_fops = { owner: THIS_MODULE, read: mmapper_read, @@ -97,34 +113,30 @@ release: mmapper_release, }; -static int mmapper_installed = 0; - static int __init mmapper_init(void) { - int link; printk(KERN_INFO "Mapper v0.1\n"); - - if(mmapper_installed++) - return 0; - mmapper_buffer = find_iomem("mmapper", &mmapper_size); + p_buf = find_iomem("mmapper", &mmapper_size); - link = devfs_register (NULL, "mmapper", DEVFS_FL_DEFAULT, - 30, 0, S_IFCHR | S_IRUGO | S_IWUGO, - &mmapper_fops, NULL); - devfs_mk_symlink(NULL, "mmapper" , DEVFS_FL_DEFAULT, "mmaper0", + v_buf = p_buf; + + devfs_register (NULL, "mmapper", DEVFS_FL_DEFAULT, + 30, 0, S_IFCHR | S_IRUGO | S_IWUGO, + &mmapper_fops, NULL); + devfs_mk_symlink(NULL, "mmapper", DEVFS_FL_DEFAULT, "mmapper0", NULL, NULL); + return(0); } static void mmapper_exit(void) { - if(mmapper_installed--) { - } } + module_init(mmapper_init); module_exit(mmapper_exit); -MODULE_AUTHOR("Greg Lonnon "); +MODULE_AUTHOR("Greg Lonnon "); MODULE_DESCRIPTION("DSPLinux simulator mmapper driver"); /* * ---------------------------------------------------------------------------