Linux 5.8-rc4
[linux/fpc-iii.git] / arch / um / drivers / mmapper_kern.c
blob0bf78ff8901102f55c19369fce6f030932b0ef2d
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * arch/um/drivers/mmapper_kern.c
5 * BRIEF MODULE DESCRIPTION
7 * Copyright (C) 2000 RidgeRun, Inc.
8 * Author: RidgeRun, Inc.
9 * Greg Lonnon glonnon@ridgerun.com or info@ridgerun.com
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>
21 #include <linux/uaccess.h>
22 #include <mem_user.h>
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;
29 static ssize_t mmapper_read(struct file *file, char __user *buf, size_t count,
30 loff_t *ppos)
32 return simple_read_from_buffer(buf, count, ppos, v_buf, mmapper_size);
35 static ssize_t mmapper_write(struct file *file, const char __user *buf,
36 size_t count, loff_t *ppos)
38 if (*ppos > mmapper_size)
39 return -EINVAL;
41 return simple_write_to_buffer(v_buf, mmapper_size, ppos, buf, count);
44 static long mmapper_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
46 return -ENOIOCTLCMD;
49 static int mmapper_mmap(struct file *file, struct vm_area_struct *vma)
51 int ret = -EINVAL;
52 int size;
54 if (vma->vm_pgoff != 0)
55 goto out;
57 size = vma->vm_end - vma->vm_start;
58 if (size > mmapper_size)
59 return -EFAULT;
62 * XXX A comment above remap_pfn_range says it should only be
63 * called when the mm semaphore is held
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;
73 static int mmapper_open(struct inode *inode, struct file *file)
75 return 0;
78 static int mmapper_release(struct inode *inode, struct file *file)
80 return 0;
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,
95 * No locking needed - only used (and modified) by below initcall and exitcall.
97 static struct miscdevice mmapper_dev = {
98 .minor = MISC_DYNAMIC_MINOR,
99 .name = "mmapper",
100 .fops = &mmapper_fops
103 static int __init mmapper_init(void)
105 int err;
107 printk(KERN_INFO "Mapper v0.1\n");
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;
114 p_buf = __pa(v_buf);
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;
122 return 0;
125 static void mmapper_exit(void)
127 misc_deregister(&mmapper_dev);
130 module_init(mmapper_init);
131 module_exit(mmapper_exit);
133 MODULE_AUTHOR("Greg Lonnon <glonnon@ridgerun.com>");
134 MODULE_DESCRIPTION("DSPLinux simulator mmapper driver");
135 MODULE_LICENSE("GPL");