proc_ppc64.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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/init.h>
  19. #include <linux/mm.h>
  20. #include <linux/proc_fs.h>
  21. #include <linux/slab.h>
  22. #include <linux/kernel.h>
  23. #include <asm/machdep.h>
  24. #include <asm/vdso_datapage.h>
  25. #include <asm/rtas.h>
  26. #include <asm/uaccess.h>
  27. #include <asm/prom.h>
  28. static loff_t page_map_seek( struct file *file, loff_t off, int whence);
  29. static ssize_t page_map_read( struct file *file, char __user *buf, size_t nbytes,
  30. loff_t *ppos);
  31. static int page_map_mmap( struct file *file, struct vm_area_struct *vma );
  32. static const struct file_operations page_map_fops = {
  33. .llseek = page_map_seek,
  34. .read = page_map_read,
  35. .mmap = page_map_mmap
  36. };
  37. /*
  38. * Create the ppc64 and ppc64/rtas directories early. This allows us to
  39. * assume that they have been previously created in drivers.
  40. */
  41. static int __init proc_ppc64_create(void)
  42. {
  43. struct proc_dir_entry *root;
  44. root = proc_mkdir("ppc64", NULL);
  45. if (!root)
  46. return 1;
  47. if (!of_find_node_by_path("/rtas"))
  48. return 0;
  49. if (!proc_mkdir("rtas", root))
  50. return 1;
  51. if (!proc_symlink("rtas", NULL, "ppc64/rtas"))
  52. return 1;
  53. return 0;
  54. }
  55. core_initcall(proc_ppc64_create);
  56. static int __init proc_ppc64_init(void)
  57. {
  58. struct proc_dir_entry *pde;
  59. pde = proc_create_data("ppc64/systemcfg", S_IFREG|S_IRUGO, NULL,
  60. &page_map_fops, vdso_data);
  61. if (!pde)
  62. return 1;
  63. pde->size = PAGE_SIZE;
  64. return 0;
  65. }
  66. __initcall(proc_ppc64_init);
  67. static loff_t page_map_seek( struct file *file, loff_t off, int whence)
  68. {
  69. loff_t new;
  70. struct proc_dir_entry *dp = PDE(file->f_path.dentry->d_inode);
  71. switch(whence) {
  72. case 0:
  73. new = off;
  74. break;
  75. case 1:
  76. new = file->f_pos + off;
  77. break;
  78. case 2:
  79. new = dp->size + off;
  80. break;
  81. default:
  82. return -EINVAL;
  83. }
  84. if ( new < 0 || new > dp->size )
  85. return -EINVAL;
  86. return (file->f_pos = new);
  87. }
  88. static ssize_t page_map_read( struct file *file, char __user *buf, size_t nbytes,
  89. loff_t *ppos)
  90. {
  91. struct proc_dir_entry *dp = PDE(file->f_path.dentry->d_inode);
  92. return simple_read_from_buffer(buf, nbytes, ppos, dp->data, dp->size);
  93. }
  94. static int page_map_mmap( struct file *file, struct vm_area_struct *vma )
  95. {
  96. struct proc_dir_entry *dp = PDE(file->f_path.dentry->d_inode);
  97. if ((vma->vm_end - vma->vm_start) > dp->size)
  98. return -EINVAL;
  99. remap_pfn_range(vma, vma->vm_start, __pa(dp->data) >> PAGE_SHIFT,
  100. dp->size, vma->vm_page_prot);
  101. return 0;
  102. }