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>
16 #include <linux/slab.h>
17 #include <linux/init.h>
18 #include <linux/smp_lock.h>
19 #include <asm/uaccess.h>
21 #include <asm/pgtable.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
;
31 mmapper_read(struct file
*file
, char *buf
, size_t count
, loff_t
*ppos
)
33 if(*ppos
> mmapper_size
)
36 if(count
+ *ppos
> mmapper_size
)
37 count
= count
+ *ppos
- mmapper_size
;
42 copy_to_user(buf
,&v_buf
[*ppos
],count
);
48 mmapper_write(struct file
*file
, const char *buf
, size_t count
, loff_t
*ppos
)
50 if(*ppos
> mmapper_size
)
53 if(count
+ *ppos
> mmapper_size
)
54 count
= count
+ *ppos
- mmapper_size
;
59 copy_from_user(&v_buf
[*ppos
],buf
,count
);
65 mmapper_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
,
72 mmapper_mmap(struct file
*file
, struct vm_area_struct
* vma
)
78 if (vma
->vm_pgoff
!= 0)
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
,
97 mmapper_open(struct inode
*inode
, struct file
*file
)
103 mmapper_release(struct inode
*inode
, struct file
*file
)
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");
130 devfs_mk_cdev(MKDEV(30, 0), S_IFCHR
|S_IRUGO
|S_IWUGO
, "mmapper");
131 devfs_mk_symlink("mmapper0", "mmapper");
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 * ---------------------------------------------------------------------------
147 * c-file-style: "linux"