arc_hostlink.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #include <linux/fs.h> /* file_operations */
  13. #include <linux/miscdevice.h>
  14. #include <linux/mm.h> /* VM_IO */
  15. #include <linux/module.h>
  16. #include <linux/uaccess.h>
  17. static unsigned char __HOSTLINK__[4 * PAGE_SIZE] __aligned(PAGE_SIZE);
  18. static int arc_hl_mmap(struct file *fp, struct vm_area_struct *vma)
  19. {
  20. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  21. if (io_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
  22. vma->vm_end - vma->vm_start,
  23. vma->vm_page_prot)) {
  24. pr_warn("Hostlink buffer mmap ERROR\n");
  25. return -EAGAIN;
  26. }
  27. return 0;
  28. }
  29. static long arc_hl_ioctl(struct file *file, unsigned int cmd,
  30. unsigned long arg)
  31. {
  32. /* we only support, returning the physical addr to mmap in user space */
  33. put_user((unsigned int)__HOSTLINK__, (int __user *)arg);
  34. return 0;
  35. }
  36. static const struct file_operations arc_hl_fops = {
  37. .unlocked_ioctl = arc_hl_ioctl,
  38. .mmap = arc_hl_mmap,
  39. };
  40. static struct miscdevice arc_hl_dev = {
  41. .minor = MISC_DYNAMIC_MINOR,
  42. .name = "hostlink",
  43. .fops = &arc_hl_fops
  44. };
  45. static int __init arc_hl_init(void)
  46. {
  47. pr_info("ARC Hostlink driver mmap at 0x%p\n", __HOSTLINK__);
  48. return misc_register(&arc_hl_dev);
  49. }
  50. module_init(arc_hl_init);