mmapper_kern.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * arch/um/drivers/mmapper_kern.c
  3. *
  4. * BRIEF MODULE DESCRIPTION
  5. *
  6. * Copyright (C) 2000 RidgeRun, Inc.
  7. * Author: RidgeRun, Inc.
  8. * Greg Lonnon glonnon@ridgerun.com or info@ridgerun.com
  9. *
  10. */
  11. #include <linux/stddef.h>
  12. #include <linux/types.h>
  13. #include <linux/fs.h>
  14. #include <linux/init.h>
  15. #include <linux/miscdevice.h>
  16. #include <linux/module.h>
  17. #include <linux/mm.h>
  18. #include <asm/uaccess.h>
  19. #include <mem_user.h>
  20. /* These are set in mmapper_init, which is called at boot time */
  21. static unsigned long mmapper_size;
  22. static unsigned long p_buf;
  23. static char *v_buf;
  24. static ssize_t mmapper_read(struct file *file, char __user *buf, size_t count,
  25. loff_t *ppos)
  26. {
  27. return simple_read_from_buffer(buf, count, ppos, v_buf, mmapper_size);
  28. }
  29. static ssize_t mmapper_write(struct file *file, const char __user *buf,
  30. size_t count, loff_t *ppos)
  31. {
  32. if (*ppos > mmapper_size)
  33. return -EINVAL;
  34. return simple_write_to_buffer(v_buf, mmapper_size, ppos, buf, count);
  35. }
  36. static long mmapper_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  37. {
  38. return -ENOIOCTLCMD;
  39. }
  40. static int mmapper_mmap(struct file *file, struct vm_area_struct *vma)
  41. {
  42. int ret = -EINVAL;
  43. int size;
  44. if (vma->vm_pgoff != 0)
  45. goto out;
  46. size = vma->vm_end - vma->vm_start;
  47. if (size > mmapper_size)
  48. return -EFAULT;
  49. /*
  50. * XXX A comment above remap_pfn_range says it should only be
  51. * called when the mm semaphore is held
  52. */
  53. if (remap_pfn_range(vma, vma->vm_start, p_buf >> PAGE_SHIFT, size,
  54. vma->vm_page_prot))
  55. goto out;
  56. ret = 0;
  57. out:
  58. return ret;
  59. }
  60. static int mmapper_open(struct inode *inode, struct file *file)
  61. {
  62. return 0;
  63. }
  64. static int mmapper_release(struct inode *inode, struct file *file)
  65. {
  66. return 0;
  67. }
  68. static const struct file_operations mmapper_fops = {
  69. .owner = THIS_MODULE,
  70. .read = mmapper_read,
  71. .write = mmapper_write,
  72. .unlocked_ioctl = mmapper_ioctl,
  73. .mmap = mmapper_mmap,
  74. .open = mmapper_open,
  75. .release = mmapper_release,
  76. .llseek = default_llseek,
  77. };
  78. /*
  79. * No locking needed - only used (and modified) by below initcall and exitcall.
  80. */
  81. static struct miscdevice mmapper_dev = {
  82. .minor = MISC_DYNAMIC_MINOR,
  83. .name = "mmapper",
  84. .fops = &mmapper_fops
  85. };
  86. static int __init mmapper_init(void)
  87. {
  88. int err;
  89. printk(KERN_INFO "Mapper v0.1\n");
  90. v_buf = (char *) find_iomem("mmapper", &mmapper_size);
  91. if (mmapper_size == 0) {
  92. printk(KERN_ERR "mmapper_init - find_iomem failed\n");
  93. return -ENODEV;
  94. }
  95. p_buf = __pa(v_buf);
  96. err = misc_register(&mmapper_dev);
  97. if (err) {
  98. printk(KERN_ERR "mmapper - misc_register failed, err = %d\n",
  99. err);
  100. return err;
  101. }
  102. return 0;
  103. }
  104. static void mmapper_exit(void)
  105. {
  106. misc_deregister(&mmapper_dev);
  107. }
  108. module_init(mmapper_init);
  109. module_exit(mmapper_exit);
  110. MODULE_AUTHOR("Greg Lonnon <glonnon@ridgerun.com>");
  111. MODULE_DESCRIPTION("DSPLinux simulator mmapper driver");
  112. MODULE_LICENSE("GPL");