linux/arch/arc/kernel/arc_hostlink.c
<<
>>
Prefs
   1/*
   2 * arc_hostlink.c: Pseudo-driver for Metaware provided "hostlink" facility
   3 *
   4 * Allows Linux userland access to host in absence of any peripherals.
   5 *
   6 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
   7 *
   8 * This program is free software; you can redistribute it and/or modify
   9 * it under the terms of the GNU General Public License version 2 as
  10 * published by the Free Software Foundation.
  11 */
  12
  13#include <linux/fs.h>           /* file_operations */
  14#include <linux/miscdevice.h>
  15#include <linux/mm.h>           /* VM_IO */
  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        /* we only support, returning the physical addr to mmap in user space */
  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