PageRenderTime 30ms CodeModel.GetById 16ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 1ms

/arch/um/drivers/mmapper_kern.c

https://bitbucket.org/evzijst/gittest
C | 150 lines | 103 code | 27 blank | 20 comment | 12 complexity | 2d5f17beab1b9d4abd5d73c41cd9d81b MD5 | raw file
  1/*
  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
 12#include <linux/types.h>
 13#include <linux/kdev_t.h>
 14#include <linux/time.h>
 15#include <linux/devfs_fs_kernel.h>
 16#include <linux/module.h>
 17#include <linux/mm.h> 
 18#include <linux/slab.h>
 19#include <linux/init.h> 
 20#include <linux/smp_lock.h>
 21#include <asm/uaccess.h>
 22#include <asm/irq.h>
 23#include <asm/pgtable.h>
 24#include "mem_user.h"
 25#include "user_util.h"
 26 
 27/* These are set in mmapper_init, which is called at boot time */
 28static unsigned long mmapper_size;
 29static unsigned long p_buf = 0;
 30static char *v_buf = NULL;
 31
 32static ssize_t
 33mmapper_read(struct file *file, char *buf, size_t count, loff_t *ppos)
 34{
 35	if(*ppos > mmapper_size)
 36		return -EINVAL;
 37
 38	if(count + *ppos > mmapper_size)
 39		count = count + *ppos - mmapper_size;
 40
 41	if(count < 0)
 42		return -EINVAL;
 43 
 44	copy_to_user(buf,&v_buf[*ppos],count);
 45	
 46	return count;
 47}
 48
 49static ssize_t
 50mmapper_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
 51{
 52	if(*ppos > mmapper_size)
 53		return -EINVAL;
 54
 55	if(count + *ppos > mmapper_size)
 56		count = count + *ppos - mmapper_size;
 57
 58	if(count < 0)
 59		return -EINVAL;
 60
 61	copy_from_user(&v_buf[*ppos],buf,count);
 62	
 63	return count;
 64}
 65
 66static int 
 67mmapper_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
 68	 unsigned long arg)
 69{
 70	return(-ENOIOCTLCMD);
 71}
 72
 73static int 
 74mmapper_mmap(struct file *file, struct vm_area_struct * vma)
 75{
 76	int ret = -EINVAL;
 77	int size;
 78
 79	lock_kernel();
 80	if (vma->vm_pgoff != 0)
 81		goto out;
 82	
 83	size = vma->vm_end - vma->vm_start;
 84	if(size > mmapper_size) return(-EFAULT);
 85
 86	/* XXX A comment above remap_pfn_range says it should only be
 87	 * called when the mm semaphore is held
 88	 */
 89	if (remap_pfn_range(vma, vma->vm_start, p_buf >> PAGE_SHIFT, size,
 90			     vma->vm_page_prot))
 91		goto out;
 92	ret = 0;
 93out:
 94	unlock_kernel();
 95	return ret;
 96}
 97
 98static int
 99mmapper_open(struct inode *inode, struct file *file)
100{
101	return 0;
102}
103
104static int 
105mmapper_release(struct inode *inode, struct file *file)
106{
107	return 0;
108}
109
110static struct file_operations mmapper_fops = {
111	.owner		= THIS_MODULE,
112	.read		= mmapper_read,
113	.write		= mmapper_write,
114	.ioctl		= mmapper_ioctl,
115	.mmap		= mmapper_mmap,
116	.open		= mmapper_open,
117	.release	= mmapper_release,
118};
119
120static int __init mmapper_init(void)
121{
122	printk(KERN_INFO "Mapper v0.1\n");
123
124	v_buf = (char *) find_iomem("mmapper", &mmapper_size);
125	if(mmapper_size == 0){
126		printk(KERN_ERR "mmapper_init - find_iomem failed\n");
127		return(0);
128	}
129
130	p_buf = __pa(v_buf);
131
132	devfs_mk_cdev(MKDEV(30, 0), S_IFCHR|S_IRUGO|S_IWUGO, "mmapper");
133	return(0);
134}
135
136static void mmapper_exit(void)
137{
138}
139
140module_init(mmapper_init);
141module_exit(mmapper_exit);
142
143MODULE_AUTHOR("Greg Lonnon <glonnon@ridgerun.com>");
144MODULE_DESCRIPTION("DSPLinux simulator mmapper driver");
145/*
146 * ---------------------------------------------------------------------------
147 * Local variables:
148 * c-file-style: "linux"
149 * End:
150 */