blob: e41a08f04694ab74b531d31f0c9b50fb0249a3f5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/um/drivers/mmapper_kern.c
3 *
4 * BRIEF MODULE DESCRIPTION
5 *
6 * Copyright (C) 2000 RidgeRun, Inc.
7 * Author: RidgeRun, Inc.
8 * Greg Lonnon glonnon@ridgerun.com or info@ridgerun.com
9 *
10 */
11
Al Viro6a029a92005-08-27 06:48:15 +010012#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/module.h>
14#include <linux/mm.h>
Jeff Dike3df59522005-06-08 15:47:50 -070015#include <linux/miscdevice.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <asm/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include "mem_user.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19/* These are set in mmapper_init, which is called at boot time */
20static unsigned long mmapper_size;
21static unsigned long p_buf = 0;
22static char *v_buf = NULL;
23
24static ssize_t
Al Viro6a029a92005-08-27 06:48:15 +010025mmapper_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070026{
Al Viro6a029a92005-08-27 06:48:15 +010027 return simple_read_from_buffer(buf, count, ppos, v_buf, mmapper_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028}
29
30static ssize_t
Al Viro6a029a92005-08-27 06:48:15 +010031mmapper_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032{
Al Viro6a029a92005-08-27 06:48:15 +010033 if (*ppos > mmapper_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 return -EINVAL;
35
Al Viro6a029a92005-08-27 06:48:15 +010036 if (count > mmapper_size - *ppos)
37 count = mmapper_size - *ppos;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Al Viro6a029a92005-08-27 06:48:15 +010039 if (copy_from_user(&v_buf[*ppos], buf, count))
40 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42 return count;
43}
44
45static int
46mmapper_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
47 unsigned long arg)
48{
49 return(-ENOIOCTLCMD);
50}
51
52static int
53mmapper_mmap(struct file *file, struct vm_area_struct * vma)
54{
55 int ret = -EINVAL;
56 int size;
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 if (vma->vm_pgoff != 0)
59 goto out;
60
61 size = vma->vm_end - vma->vm_start;
62 if(size > mmapper_size) return(-EFAULT);
63
64 /* XXX A comment above remap_pfn_range says it should only be
65 * called when the mm semaphore is held
66 */
67 if (remap_pfn_range(vma, vma->vm_start, p_buf >> PAGE_SHIFT, size,
68 vma->vm_page_prot))
69 goto out;
70 ret = 0;
71out:
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 return ret;
73}
74
75static int
76mmapper_open(struct inode *inode, struct file *file)
77{
78 return 0;
79}
80
81static int
82mmapper_release(struct inode *inode, struct file *file)
83{
84 return 0;
85}
86
Jeff Dike5e7672e2006-09-27 01:50:33 -070087static const struct file_operations mmapper_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 .owner = THIS_MODULE,
89 .read = mmapper_read,
90 .write = mmapper_write,
91 .ioctl = mmapper_ioctl,
92 .mmap = mmapper_mmap,
93 .open = mmapper_open,
94 .release = mmapper_release,
95};
96
Paolo 'Blaisorblade' Giarrusso1ba0ce62006-10-19 23:28:26 -070097/* No locking needed - only used (and modified) by below initcall and exitcall. */
98static struct miscdevice mmapper_dev = {
Jeff Dike3df59522005-06-08 15:47:50 -070099 .minor = MISC_DYNAMIC_MINOR,
100 .name = "mmapper",
101 .fops = &mmapper_fops
102};
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104static int __init mmapper_init(void)
105{
Jeff Dike3df59522005-06-08 15:47:50 -0700106 int err;
107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 printk(KERN_INFO "Mapper v0.1\n");
109
110 v_buf = (char *) find_iomem("mmapper", &mmapper_size);
111 if(mmapper_size == 0){
112 printk(KERN_ERR "mmapper_init - find_iomem failed\n");
Jeff Dike3df59522005-06-08 15:47:50 -0700113 goto out;
114 }
115
116 err = misc_register(&mmapper_dev);
117 if(err){
118 printk(KERN_ERR "mmapper - misc_register failed, err = %d\n",
119 err);
120 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 }
122
123 p_buf = __pa(v_buf);
Jeff Dike3df59522005-06-08 15:47:50 -0700124out:
125 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126}
127
128static void mmapper_exit(void)
129{
Jeff Dike3df59522005-06-08 15:47:50 -0700130 misc_deregister(&mmapper_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131}
132
133module_init(mmapper_init);
134module_exit(mmapper_exit);
135
136MODULE_AUTHOR("Greg Lonnon <glonnon@ridgerun.com>");
137MODULE_DESCRIPTION("DSPLinux simulator mmapper driver");
138/*
139 * ---------------------------------------------------------------------------
140 * Local variables:
141 * c-file-style: "linux"
142 * End:
143 */