davinci: Add NOR flash support for da850/omap-l138
[linux-ginger.git] / arch / um / drivers / mmapper_kern.c
blobeb240323c40ad6a52883b079f2324c57ae9eb09f
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
12 #include <linux/stddef.h>
13 #include <linux/types.h>
14 #include <linux/fs.h>
15 #include <linux/init.h>
16 #include <linux/miscdevice.h>
17 #include <linux/module.h>
18 #include <linux/mm.h>
19 #include <linux/smp_lock.h>
20 #include <asm/uaccess.h>
21 #include "mem_user.h"
23 /* These are set in mmapper_init, which is called at boot time */
24 static unsigned long mmapper_size;
25 static unsigned long p_buf;
26 static char *v_buf;
28 static ssize_t mmapper_read(struct file *file, char __user *buf, size_t count,
29 loff_t *ppos)
31 return simple_read_from_buffer(buf, count, ppos, v_buf, mmapper_size);
34 static ssize_t mmapper_write(struct file *file, const char __user *buf,
35 size_t count, loff_t *ppos)
37 if (*ppos > mmapper_size)
38 return -EINVAL;
40 if (count > mmapper_size - *ppos)
41 count = mmapper_size - *ppos;
43 if (copy_from_user(&v_buf[*ppos], buf, count))
44 return -EFAULT;
46 return count;
49 static int mmapper_ioctl(struct inode *inode, struct file *file,
50 unsigned int cmd, unsigned long arg)
52 return -ENOIOCTLCMD;
55 static int mmapper_mmap(struct file *file, struct vm_area_struct *vma)
57 int ret = -EINVAL;
58 int size;
60 if (vma->vm_pgoff != 0)
61 goto out;
63 size = vma->vm_end - vma->vm_start;
64 if (size > mmapper_size)
65 return -EFAULT;
68 * XXX A comment above remap_pfn_range says it should only be
69 * called when the mm semaphore is held
71 if (remap_pfn_range(vma, vma->vm_start, p_buf >> PAGE_SHIFT, size,
72 vma->vm_page_prot))
73 goto out;
74 ret = 0;
75 out:
76 return ret;
79 static int mmapper_open(struct inode *inode, struct file *file)
81 cycle_kernel_lock();
82 return 0;
85 static int mmapper_release(struct inode *inode, struct file *file)
87 return 0;
90 static const struct file_operations mmapper_fops = {
91 .owner = THIS_MODULE,
92 .read = mmapper_read,
93 .write = mmapper_write,
94 .ioctl = mmapper_ioctl,
95 .mmap = mmapper_mmap,
96 .open = mmapper_open,
97 .release = mmapper_release,
101 * No locking needed - only used (and modified) by below initcall and exitcall.
103 static struct miscdevice mmapper_dev = {
104 .minor = MISC_DYNAMIC_MINOR,
105 .name = "mmapper",
106 .fops = &mmapper_fops
109 static int __init mmapper_init(void)
111 int err;
113 printk(KERN_INFO "Mapper v0.1\n");
115 v_buf = (char *) find_iomem("mmapper", &mmapper_size);
116 if (mmapper_size == 0) {
117 printk(KERN_ERR "mmapper_init - find_iomem failed\n");
118 goto out;
121 err = misc_register(&mmapper_dev);
122 if (err) {
123 printk(KERN_ERR "mmapper - misc_register failed, err = %d\n",
124 err);
125 goto out;
128 p_buf = __pa(v_buf);
129 out:
130 return 0;
133 static void mmapper_exit(void)
135 misc_deregister(&mmapper_dev);
138 module_init(mmapper_init);
139 module_exit(mmapper_exit);
141 MODULE_AUTHOR("Greg Lonnon <glonnon@ridgerun.com>");
142 MODULE_DESCRIPTION("DSPLinux simulator mmapper driver");