2005-04-17 02:20:36 +04:00
/*
* arch / um / drivers / mmapper_kern . c
*
* BRIEF MODULE DESCRIPTION
*
* Copyright ( C ) 2000 RidgeRun , Inc .
* Author : RidgeRun , Inc .
* Greg Lonnon glonnon @ ridgerun . com or info @ ridgerun . com
*
*/
2007-10-16 12:27:34 +04:00
# include <linux/stddef.h>
# include <linux/types.h>
2007-07-30 02:36:13 +04:00
# include <linux/fs.h>
2007-10-16 12:27:34 +04:00
# include <linux/init.h>
2005-06-09 02:47:50 +04:00
# include <linux/miscdevice.h>
2007-10-16 12:27:34 +04:00
# include <linux/module.h>
# include <linux/mm.h>
2008-05-20 21:16:56 +04:00
# include <linux/smp_lock.h>
2005-04-17 02:20:36 +04:00
# include <asm/uaccess.h>
# include "mem_user.h"
2007-10-16 12:27:34 +04:00
2005-04-17 02:20:36 +04:00
/* These are set in mmapper_init, which is called at boot time */
static unsigned long mmapper_size ;
2007-10-16 12:27:34 +04:00
static unsigned long p_buf ;
static char * v_buf ;
2005-04-17 02:20:36 +04:00
2007-10-16 12:27:34 +04:00
static ssize_t mmapper_read ( struct file * file , char __user * buf , size_t count ,
loff_t * ppos )
2005-04-17 02:20:36 +04:00
{
2005-08-27 09:48:15 +04:00
return simple_read_from_buffer ( buf , count , ppos , v_buf , mmapper_size ) ;
2005-04-17 02:20:36 +04:00
}
2007-10-16 12:27:34 +04:00
static ssize_t mmapper_write ( struct file * file , const char __user * buf ,
size_t count , loff_t * ppos )
2005-04-17 02:20:36 +04:00
{
2005-08-27 09:48:15 +04:00
if ( * ppos > mmapper_size )
2005-04-17 02:20:36 +04:00
return - EINVAL ;
2005-08-27 09:48:15 +04:00
if ( count > mmapper_size - * ppos )
count = mmapper_size - * ppos ;
2005-04-17 02:20:36 +04:00
2005-08-27 09:48:15 +04:00
if ( copy_from_user ( & v_buf [ * ppos ] , buf , count ) )
return - EFAULT ;
2007-10-16 12:27:34 +04:00
2005-04-17 02:20:36 +04:00
return count ;
}
2007-10-16 12:27:34 +04:00
static int mmapper_ioctl ( struct inode * inode , struct file * file ,
unsigned int cmd , unsigned long arg )
2005-04-17 02:20:36 +04:00
{
2007-10-16 12:27:34 +04:00
return - ENOIOCTLCMD ;
2005-04-17 02:20:36 +04:00
}
2007-10-16 12:27:34 +04:00
static int mmapper_mmap ( struct file * file , struct vm_area_struct * vma )
2005-04-17 02:20:36 +04:00
{
int ret = - EINVAL ;
int size ;
if ( vma - > vm_pgoff ! = 0 )
goto out ;
2007-10-16 12:27:34 +04:00
2005-04-17 02:20:36 +04:00
size = vma - > vm_end - vma - > vm_start ;
2007-10-16 12:27:34 +04:00
if ( size > mmapper_size )
return - EFAULT ;
2005-04-17 02:20:36 +04:00
2007-10-16 12:27:34 +04:00
/*
* XXX A comment above remap_pfn_range says it should only be
2005-04-17 02:20:36 +04:00
* called when the mm semaphore is held
*/
if ( remap_pfn_range ( vma , vma - > vm_start , p_buf > > PAGE_SHIFT , size ,
2007-10-16 12:27:34 +04:00
vma - > vm_page_prot ) )
2005-04-17 02:20:36 +04:00
goto out ;
ret = 0 ;
out :
return ret ;
}
2007-10-16 12:27:34 +04:00
static int mmapper_open ( struct inode * inode , struct file * file )
2005-04-17 02:20:36 +04:00
{
2008-05-20 21:16:56 +04:00
cycle_kernel_lock ( ) ;
2005-04-17 02:20:36 +04:00
return 0 ;
}
2007-10-16 12:27:34 +04:00
static int mmapper_release ( struct inode * inode , struct file * file )
2005-04-17 02:20:36 +04:00
{
return 0 ;
}
2006-09-27 12:50:33 +04:00
static const struct file_operations mmapper_fops = {
2005-04-17 02:20:36 +04:00
. owner = THIS_MODULE ,
. read = mmapper_read ,
. write = mmapper_write ,
. ioctl = mmapper_ioctl ,
. mmap = mmapper_mmap ,
. open = mmapper_open ,
. release = mmapper_release ,
} ;
2007-10-16 12:27:34 +04:00
/*
* No locking needed - only used ( and modified ) by below initcall and exitcall .
*/
2006-10-20 10:28:26 +04:00
static struct miscdevice mmapper_dev = {
2005-06-09 02:47:50 +04:00
. minor = MISC_DYNAMIC_MINOR ,
. name = " mmapper " ,
. fops = & mmapper_fops
} ;
2005-04-17 02:20:36 +04:00
static int __init mmapper_init ( void )
{
2005-06-09 02:47:50 +04:00
int err ;
2005-04-17 02:20:36 +04:00
printk ( KERN_INFO " Mapper v0.1 \n " ) ;
v_buf = ( char * ) find_iomem ( " mmapper " , & mmapper_size ) ;
2007-10-16 12:27:34 +04:00
if ( mmapper_size = = 0 ) {
2005-04-17 02:20:36 +04:00
printk ( KERN_ERR " mmapper_init - find_iomem failed \n " ) ;
2005-06-09 02:47:50 +04:00
goto out ;
2005-04-17 02:20:36 +04:00
}
2005-06-09 02:47:50 +04:00
err = misc_register ( & mmapper_dev ) ;
2007-10-16 12:27:34 +04:00
if ( err ) {
2005-06-09 02:47:50 +04:00
printk ( KERN_ERR " mmapper - misc_register failed, err = %d \n " ,
err ) ;
goto out ;
}
2005-04-17 02:20:36 +04:00
2005-06-09 02:47:50 +04:00
p_buf = __pa ( v_buf ) ;
out :
return 0 ;
2005-04-17 02:20:36 +04:00
}
static void mmapper_exit ( void )
{
2005-06-09 02:47:50 +04:00
misc_deregister ( & mmapper_dev ) ;
2005-04-17 02:20:36 +04:00
}
module_init ( mmapper_init ) ;
module_exit ( mmapper_exit ) ;
MODULE_AUTHOR ( " Greg Lonnon <glonnon@ridgerun.com> " ) ;
MODULE_DESCRIPTION ( " DSPLinux simulator mmapper driver " ) ;