Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * arc_hostlink.c: Pseudo-driver for Metaware provided "hostlink" facility
0004  *
0005  * Allows Linux userland access to host in absence of any peripherals.
0006  *
0007  * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
0008  */
0009 
0010 #include <linux/fs.h>       /* file_operations */
0011 #include <linux/miscdevice.h>
0012 #include <linux/mm.h>       /* VM_IO */
0013 #include <linux/module.h>
0014 #include <linux/uaccess.h>
0015 
0016 static unsigned char __HOSTLINK__[4 * PAGE_SIZE] __aligned(PAGE_SIZE);
0017 
0018 static int arc_hl_mmap(struct file *fp, struct vm_area_struct *vma)
0019 {
0020     vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
0021 
0022     if (io_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
0023                    vma->vm_end - vma->vm_start,
0024                    vma->vm_page_prot)) {
0025         pr_warn("Hostlink buffer mmap ERROR\n");
0026         return -EAGAIN;
0027     }
0028     return 0;
0029 }
0030 
0031 static long arc_hl_ioctl(struct file *file, unsigned int cmd,
0032             unsigned long arg)
0033 {
0034     /* we only support, returning the physical addr to mmap in user space */
0035     put_user((unsigned int)__HOSTLINK__, (int __user *)arg);
0036     return 0;
0037 }
0038 
0039 static const struct file_operations arc_hl_fops = {
0040     .unlocked_ioctl = arc_hl_ioctl,
0041     .mmap       = arc_hl_mmap,
0042 };
0043 
0044 static struct miscdevice arc_hl_dev = {
0045     .minor  = MISC_DYNAMIC_MINOR,
0046     .name   = "hostlink",
0047     .fops   = &arc_hl_fops
0048 };
0049 
0050 static int __init arc_hl_init(void)
0051 {
0052     pr_info("ARC Hostlink driver mmap at 0x%p\n", __HOSTLINK__);
0053     return misc_register(&arc_hl_dev);
0054 }
0055 module_init(arc_hl_init);