1 // SPDX-License-Identifier: GPL-2.0-only
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>
16 #include <linux/init.h>
17 #include <linux/miscdevice.h>
18 #include <linux/module.h>
21 #include <linux/uaccess.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
;
29 static ssize_t
mmapper_read(struct file
*file
, char __user
*buf
, size_t count
,
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
)
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
)
49 static int mmapper_mmap(struct file
*file
, struct vm_area_struct
*vma
)
54 if (vma
->vm_pgoff
!= 0)
57 size
= vma
->vm_end
- vma
->vm_start
;
58 if (size
> mmapper_size
)
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
,
73 static int mmapper_open(struct inode
*inode
, struct file
*file
)
78 static int mmapper_release(struct inode
*inode
, struct file
*file
)
83 static const struct file_operations mmapper_fops
= {
86 .write
= mmapper_write
,
87 .unlocked_ioctl
= mmapper_ioctl
,
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
,
100 .fops
= &mmapper_fops
103 static int __init
mmapper_init(void)
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");
116 err
= misc_register(&mmapper_dev
);
118 printk(KERN_ERR
"mmapper - misc_register failed, err = %d\n",
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");