1
2
3
4
5
6
7
8
9
10
11
12
13#include <linux/fs.h>
14#include <linux/miscdevice.h>
15#include <linux/mm.h>
16#include <linux/module.h>
17#include <linux/uaccess.h>
18
19static unsigned char __HOSTLINK__[4 * PAGE_SIZE] __aligned(PAGE_SIZE);
20
21static int arc_hl_mmap(struct file *fp, struct vm_area_struct *vma)
22{
23 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
24
25 if (io_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
26 vma->vm_end - vma->vm_start,
27 vma->vm_page_prot)) {
28 pr_warn("Hostlink buffer mmap ERROR\n");
29 return -EAGAIN;
30 }
31 return 0;
32}
33
34static long arc_hl_ioctl(struct file *file, unsigned int cmd,
35 unsigned long arg)
36{
37
38 put_user((unsigned int)__HOSTLINK__, (int __user *)arg);
39 return 0;
40}
41
42static const struct file_operations arc_hl_fops = {
43 .unlocked_ioctl = arc_hl_ioctl,
44 .mmap = arc_hl_mmap,
45};
46
47static struct miscdevice arc_hl_dev = {
48 .minor = MISC_DYNAMIC_MINOR,
49 .name = "hostlink",
50 .fops = &arc_hl_fops
51};
52
53static int __init arc_hl_init(void)
54{
55 pr_info("ARC Hostlink driver mmap at 0x%p\n", __HOSTLINK__);
56 return misc_register(&arc_hl_dev);
57}
58module_init(arc_hl_init);
59