proc_powerpc.c 3.0 KB

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