arc_hostlink.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * arc_hostlink.c: Pseudo-driver for Metaware provided "hostlink" facility
  4. *
  5. * Allows Linux userland access to host in absence of any peripherals.
  6. *
  7. * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  8. */
  9. #include <linux/fs.h> /* file_operations */
  10. #include <linux/miscdevice.h>
  11. #include <linux/mm.h> /* VM_IO */
  12. #include <linux/module.h>
  13. #include <linux/uaccess.h>
  14. static unsigned char __HOSTLINK__[4 * PAGE_SIZE] __aligned(PAGE_SIZE);
  15. static int arc_hl_mmap(struct file *fp, struct vm_area_struct *vma)
  16. {
  17. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  18. if (io_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
  19. vma->vm_end - vma->vm_start,
  20. vma->vm_page_prot)) {
  21. pr_warn("Hostlink buffer mmap ERROR\n");
  22. return -EAGAIN;
  23. }
  24. return 0;
  25. }
  26. static long arc_hl_ioctl(struct file *file, unsigned int cmd,
  27. unsigned long arg)
  28. {
  29. /* we only support, returning the physical addr to mmap in user space */
  30. put_user((unsigned int)__HOSTLINK__, (int __user *)arg);
  31. return 0;
  32. }
  33. static const struct file_operations arc_hl_fops = {
  34. .unlocked_ioctl = arc_hl_ioctl,
  35. .mmap = arc_hl_mmap,
  36. };
  37. static struct miscdevice arc_hl_dev = {
  38. .minor = MISC_DYNAMIC_MINOR,
  39. .name = "hostlink",
  40. .fops = &arc_hl_fops
  41. };
  42. static int __init arc_hl_init(void)
  43. {
  44. pr_info("ARC Hostlink driver mmap at 0x%p\n", __HOSTLINK__);
  45. return misc_register(&arc_hl_dev);
  46. }
  47. module_init(arc_hl_init);