proc_ppc64.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright (C) 2001 Mike Corrigan & Dave Engebretsen IBM Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #include <linux/config.h>
  19. #include <linux/init.h>
  20. #include <linux/mm.h>
  21. #include <linux/proc_fs.h>
  22. #include <linux/slab.h>
  23. #include <linux/kernel.h>
  24. #include <asm/machdep.h>
  25. #include <asm/vdso_datapage.h>
  26. #include <asm/rtas.h>
  27. #include <asm/uaccess.h>
  28. #include <asm/prom.h>
  29. static loff_t page_map_seek( struct file *file, loff_t off, int whence);
  30. static ssize_t page_map_read( struct file *file, char __user *buf, size_t nbytes,
  31. loff_t *ppos);
  32. static int page_map_mmap( struct file *file, struct vm_area_struct *vma );
  33. static struct file_operations page_map_fops = {
  34. .llseek = page_map_seek,
  35. .read = page_map_read,
  36. .mmap = page_map_mmap
  37. };
  38. /*
  39. * Create the ppc64 and ppc64/rtas directories early. This allows us to
  40. * assume that they have been previously created in drivers.
  41. */
  42. static int __init proc_ppc64_create(void)
  43. {
  44. struct proc_dir_entry *root;
  45. root = proc_mkdir("ppc64", NULL);
  46. if (!root)
  47. return 1;
  48. if (!machine_is(pseries) && !machine_is(cell))
  49. return 0;
  50. if (!proc_mkdir("rtas", root))
  51. return 1;
  52. if (!proc_symlink("rtas", NULL, "ppc64/rtas"))
  53. return 1;
  54. return 0;
  55. }
  56. core_initcall(proc_ppc64_create);
  57. static int __init proc_ppc64_init(void)
  58. {
  59. struct proc_dir_entry *pde;
  60. pde = create_proc_entry("ppc64/systemcfg", S_IFREG|S_IRUGO, NULL);
  61. if (!pde)
  62. return 1;
  63. pde->nlink = 1;
  64. pde->data = vdso_data;
  65. pde->size = PAGE_SIZE;
  66. pde->proc_fops = &page_map_fops;
  67. return 0;
  68. }
  69. __initcall(proc_ppc64_init);
  70. static loff_t page_map_seek( struct file *file, loff_t off, int whence)
  71. {
  72. loff_t new;
  73. struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode);
  74. switch(whence) {
  75. case 0:
  76. new = off;
  77. break;
  78. case 1:
  79. new = file->f_pos + off;
  80. break;
  81. case 2:
  82. new = dp->size + off;
  83. break;
  84. default:
  85. return -EINVAL;
  86. }
  87. if ( new < 0 || new > dp->size )
  88. return -EINVAL;
  89. return (file->f_pos = new);
  90. }
  91. static ssize_t page_map_read( struct file *file, char __user *buf, size_t nbytes,
  92. loff_t *ppos)
  93. {
  94. struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode);
  95. return simple_read_from_buffer(buf, nbytes, ppos, dp->data, dp->size);
  96. }
  97. static int page_map_mmap( struct file *file, struct vm_area_struct *vma )
  98. {
  99. struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode);
  100. vma->vm_flags |= VM_SHM | VM_LOCKED;
  101. if ((vma->vm_end - vma->vm_start) > dp->size)
  102. return -EINVAL;
  103. remap_pfn_range(vma, vma->vm_start, __pa(dp->data) >> PAGE_SHIFT,
  104. dp->size, vma->vm_page_prot);
  105. return 0;
  106. }