MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / arch / um / drivers / mmapper_kern.c
blob1862691b91469ea41fe4172bb66d3f79a3b1a906
1 /*
2 * arch/um/drivers/mmapper_kern.c
4 * BRIEF MODULE DESCRIPTION
6 * Copyright (C) 2000 RidgeRun, Inc.
7 * Author: RidgeRun, Inc.
8 * Greg Lonnon glonnon@ridgerun.com or info@ridgerun.com
11 #include <linux/kdev_t.h>
12 #include <linux/time.h>
13 #include <linux/devfs_fs_kernel.h>
14 #include <linux/module.h>
15 #include <linux/mm.h>
16 #include <linux/slab.h>
17 #include <linux/init.h>
18 #include <linux/smp_lock.h>
19 #include <asm/uaccess.h>
20 #include <asm/irq.h>
21 #include <asm/pgtable.h>
22 #include "mem_user.h"
23 #include "user_util.h"
25 /* These are set in mmapper_init, which is called at boot time */
26 static unsigned long mmapper_size;
27 static unsigned long p_buf = 0;
28 static char *v_buf = NULL;
30 static ssize_t
31 mmapper_read(struct file *file, char *buf, size_t count, loff_t *ppos)
33 if(*ppos > mmapper_size)
34 return -EINVAL;
36 if(count + *ppos > mmapper_size)
37 count = count + *ppos - mmapper_size;
39 if(count < 0)
40 return -EINVAL;
42 copy_to_user(buf,&v_buf[*ppos],count);
44 return count;
47 static ssize_t
48 mmapper_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
50 if(*ppos > mmapper_size)
51 return -EINVAL;
53 if(count + *ppos > mmapper_size)
54 count = count + *ppos - mmapper_size;
56 if(count < 0)
57 return -EINVAL;
59 copy_from_user(&v_buf[*ppos],buf,count);
61 return count;
64 static int
65 mmapper_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
66 unsigned long arg)
68 return(-ENOIOCTLCMD);
71 static int
72 mmapper_mmap(struct file *file, struct vm_area_struct * vma)
74 int ret = -EINVAL;
75 int size;
77 lock_kernel();
78 if (vma->vm_pgoff != 0)
79 goto out;
81 size = vma->vm_end - vma->vm_start;
82 if(size > mmapper_size) return(-EFAULT);
84 /* XXX A comment above remap_page_range says it should only be
85 * called when the mm semaphore is held
87 if (remap_page_range(vma, vma->vm_start, p_buf, size,
88 vma->vm_page_prot))
89 goto out;
90 ret = 0;
91 out:
92 unlock_kernel();
93 return ret;
96 static int
97 mmapper_open(struct inode *inode, struct file *file)
99 return 0;
102 static int
103 mmapper_release(struct inode *inode, struct file *file)
105 return 0;
108 static struct file_operations mmapper_fops = {
109 .owner = THIS_MODULE,
110 .read = mmapper_read,
111 .write = mmapper_write,
112 .ioctl = mmapper_ioctl,
113 .mmap = mmapper_mmap,
114 .open = mmapper_open,
115 .release = mmapper_release,
118 static int __init mmapper_init(void)
120 printk(KERN_INFO "Mapper v0.1\n");
122 v_buf = (char *) find_iomem("mmapper", &mmapper_size);
123 if(mmapper_size == 0){
124 printk(KERN_ERR "mmapper_init - find_iomem failed\n");
125 return(0);
128 p_buf = __pa(v_buf);
130 devfs_mk_cdev(MKDEV(30, 0), S_IFCHR|S_IRUGO|S_IWUGO, "mmapper");
131 devfs_mk_symlink("mmapper0", "mmapper");
132 return(0);
135 static void mmapper_exit(void)
139 module_init(mmapper_init);
140 module_exit(mmapper_exit);
142 MODULE_AUTHOR("Greg Lonnon <glonnon@ridgerun.com>");
143 MODULE_DESCRIPTION("DSPLinux simulator mmapper driver");
145 * ---------------------------------------------------------------------------
146 * Local variables:
147 * c-file-style: "linux"
148 * End: