blob: 867666a023397182c26f3b1f7e011f589acacba1 [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>
Alexey Dobriyan4e950f62007-07-30 02:36:13 +040015#include <linux/fs.h>
Jeff Dike3df59522005-06-08 15:47:50 -070016#include <linux/miscdevice.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "mem_user.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20/* These are set in mmapper_init, which is called at boot time */
21static unsigned long mmapper_size;
22static unsigned long p_buf = 0;
23static char *v_buf = NULL;
24
25static ssize_t
Al Viro6a029a92005-08-27 06:48:15 +010026mmapper_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070027{
Al Viro6a029a92005-08-27 06:48:15 +010028 return simple_read_from_buffer(buf, count, ppos, v_buf, mmapper_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070029}
30
31static ssize_t
Al Viro6a029a92005-08-27 06:48:15 +010032mmapper_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033{
Al Viro6a029a92005-08-27 06:48:15 +010034 if (*ppos > mmapper_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 return -EINVAL;
36
Al Viro6a029a92005-08-27 06:48:15 +010037 if (count > mmapper_size - *ppos)
38 count = mmapper_size - *ppos;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Al Viro6a029a92005-08-27 06:48:15 +010040 if (copy_from_user(&v_buf[*ppos], buf, count))
41 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43 return count;
44}
45
46static int
47mmapper_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
48 unsigned long arg)
49{
50 return(-ENOIOCTLCMD);
51}
52
53static int
54mmapper_mmap(struct file *file, struct vm_area_struct * vma)
55{
56 int ret = -EINVAL;
57 int size;
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 if (vma->vm_pgoff != 0)
60 goto out;
61
62 size = vma->vm_end - vma->vm_start;
63 if(size > mmapper_size) return(-EFAULT);
64
65 /* XXX A comment above remap_pfn_range says it should only be
66 * called when the mm semaphore is held
67 */
68 if (remap_pfn_range(vma, vma->vm_start, p_buf >> PAGE_SHIFT, size,
69 vma->vm_page_prot))
70 goto out;
71 ret = 0;
72out:
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 return ret;
74}
75
76static int
77mmapper_open(struct inode *inode, struct file *file)
78{
79 return 0;
80}
81
82static int
83mmapper_release(struct inode *inode, struct file *file)
84{
85 return 0;
86}
87
Jeff Dike5e7672e2006-09-27 01:50:33 -070088static const struct file_operations mmapper_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 .owner = THIS_MODULE,
90 .read = mmapper_read,
91 .write = mmapper_write,
92 .ioctl = mmapper_ioctl,
93 .mmap = mmapper_mmap,
94 .open = mmapper_open,
95 .release = mmapper_release,
96};
97
Paolo 'Blaisorblade' Giarrusso1ba0ce62006-10-19 23:28:26 -070098/* No locking needed - only used (and modified) by below initcall and exitcall. */
99static struct miscdevice mmapper_dev = {
Jeff Dike3df59522005-06-08 15:47:50 -0700100 .minor = MISC_DYNAMIC_MINOR,
101 .name = "mmapper",
102 .fops = &mmapper_fops
103};
104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105static int __init mmapper_init(void)
106{
Jeff Dike3df59522005-06-08 15:47:50 -0700107 int err;
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 printk(KERN_INFO "Mapper v0.1\n");
110
111 v_buf = (char *) find_iomem("mmapper", &mmapper_size);
112 if(mmapper_size == 0){
113 printk(KERN_ERR "mmapper_init - find_iomem failed\n");
Jeff Dike3df59522005-06-08 15:47:50 -0700114 goto out;
115 }
116
117 err = misc_register(&mmapper_dev);
118 if(err){
119 printk(KERN_ERR "mmapper - misc_register failed, err = %d\n",
120 err);
121 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 }
123
124 p_buf = __pa(v_buf);
Jeff Dike3df59522005-06-08 15:47:50 -0700125out:
126 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127}
128
129static void mmapper_exit(void)
130{
Jeff Dike3df59522005-06-08 15:47:50 -0700131 misc_deregister(&mmapper_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132}
133
134module_init(mmapper_init);
135module_exit(mmapper_exit);
136
137MODULE_AUTHOR("Greg Lonnon <glonnon@ridgerun.com>");
138MODULE_DESCRIPTION("DSPLinux simulator mmapper driver");
139/*
140 * ---------------------------------------------------------------------------
141 * Local variables:
142 * c-file-style: "linux"
143 * End:
144 */