~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/um/drivers/mmapper_kern.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*
  3  * arch/um/drivers/mmapper_kern.c
  4  *
  5  * BRIEF MODULE DESCRIPTION
  6  *
  7  * Copyright (C) 2000 RidgeRun, Inc.
  8  * Author: RidgeRun, Inc.
  9  *         Greg Lonnon glonnon@ridgerun.com or info@ridgerun.com
 10  *
 11  */
 12 
 13 #include <linux/stddef.h>
 14 #include <linux/types.h>
 15 #include <linux/fs.h>
 16 #include <linux/init.h>
 17 #include <linux/miscdevice.h>
 18 #include <linux/module.h>
 19 #include <linux/mm.h>
 20 
 21 #include <linux/uaccess.h>
 22 #include <mem_user.h>
 23 
 24 /* These are set in mmapper_init, which is called at boot time */
 25 static unsigned long mmapper_size;
 26 static unsigned long p_buf;
 27 static char *v_buf;
 28 
 29 static ssize_t mmapper_read(struct file *file, char __user *buf, size_t count,
 30                             loff_t *ppos)
 31 {
 32         return simple_read_from_buffer(buf, count, ppos, v_buf, mmapper_size);
 33 }
 34 
 35 static ssize_t mmapper_write(struct file *file, const char __user *buf,
 36                              size_t count, loff_t *ppos)
 37 {
 38         if (*ppos > mmapper_size)
 39                 return -EINVAL;
 40 
 41         return simple_write_to_buffer(v_buf, mmapper_size, ppos, buf, count);
 42 }
 43 
 44 static long mmapper_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 45 {
 46         return -ENOIOCTLCMD;
 47 }
 48 
 49 static int mmapper_mmap(struct file *file, struct vm_area_struct *vma)
 50 {
 51         int ret = -EINVAL;
 52         int size;
 53 
 54         if (vma->vm_pgoff != 0)
 55                 goto out;
 56 
 57         size = vma->vm_end - vma->vm_start;
 58         if (size > mmapper_size)
 59                 return -EFAULT;
 60 
 61         /*
 62          * XXX A comment above remap_pfn_range says it should only be
 63          * called when the mm semaphore is held
 64          */
 65         if (remap_pfn_range(vma, vma->vm_start, p_buf >> PAGE_SHIFT, size,
 66                             vma->vm_page_prot))
 67                 goto out;
 68         ret = 0;
 69 out:
 70         return ret;
 71 }
 72 
 73 static int mmapper_open(struct inode *inode, struct file *file)
 74 {
 75         return 0;
 76 }
 77 
 78 static int mmapper_release(struct inode *inode, struct file *file)
 79 {
 80         return 0;
 81 }
 82 
 83 static const struct file_operations mmapper_fops = {
 84         .owner          = THIS_MODULE,
 85         .read           = mmapper_read,
 86         .write          = mmapper_write,
 87         .unlocked_ioctl = mmapper_ioctl,
 88         .mmap           = mmapper_mmap,
 89         .open           = mmapper_open,
 90         .release        = mmapper_release,
 91         .llseek         = default_llseek,
 92 };
 93 
 94 /*
 95  * No locking needed - only used (and modified) by below initcall and exitcall.
 96  */
 97 static struct miscdevice mmapper_dev = {
 98         .minor          = MISC_DYNAMIC_MINOR,
 99         .name           = "mmapper",
100         .fops           = &mmapper_fops
101 };
102 
103 static int __init mmapper_init(void)
104 {
105         int err;
106 
107         printk(KERN_INFO "Mapper v0.1\n");
108 
109         v_buf = (char *) find_iomem("mmapper", &mmapper_size);
110         if (mmapper_size == 0) {
111                 printk(KERN_ERR "mmapper_init - find_iomem failed\n");
112                 return -ENODEV;
113         }
114         p_buf = __pa(v_buf);
115 
116         err = misc_register(&mmapper_dev);
117         if (err) {
118                 printk(KERN_ERR "mmapper - misc_register failed, err = %d\n",
119                        err);
120                 return err;
121         }
122         return 0;
123 }
124 
125 static void __exit mmapper_exit(void)
126 {
127         misc_deregister(&mmapper_dev);
128 }
129 
130 module_init(mmapper_init);
131 module_exit(mmapper_exit);
132 
133 MODULE_AUTHOR("Greg Lonnon <glonnon@ridgerun.com>");
134 MODULE_DESCRIPTION("DSPLinux simulator mmapper driver");
135 MODULE_LICENSE("GPL");
136 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php