proc_powerpc.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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/kernel.h>
  22. #include <asm/machdep.h>
  23. #include <asm/vdso_datapage.h>
  24. #include <asm/rtas.h>
  25. #include <asm/uaccess.h>
  26. #include <asm/prom.h>
  27. #ifdef CONFIG_PPC64
  28. static loff_t page_map_seek(struct file *file, loff_t off, int whence)
  29. {
  30. return fixed_size_llseek(file, off, whence, PAGE_SIZE);
  31. }
  32. static ssize_t page_map_read( struct file *file, char __user *buf, size_t nbytes,
  33. loff_t *ppos)
  34. {
  35. return simple_read_from_buffer(buf, nbytes, ppos,
  36. PDE_DATA(file_inode(file)), PAGE_SIZE);
  37. }
  38. static int page_map_mmap( struct file *file, struct vm_area_struct *vma )
  39. {
  40. if ((vma->vm_end - vma->vm_start) > PAGE_SIZE)
  41. return -EINVAL;
  42. remap_pfn_range(vma, vma->vm_start,
  43. __pa(PDE_DATA(file_inode(file))) >> PAGE_SHIFT,
  44. PAGE_SIZE, vma->vm_page_prot);
  45. return 0;
  46. }
  47. static const struct file_operations page_map_fops = {
  48. .llseek = page_map_seek,
  49. .read = page_map_read,
  50. .mmap = page_map_mmap
  51. };
  52. static int __init proc_ppc64_init(void)
  53. {
  54. struct proc_dir_entry *pde;
  55. pde = proc_create_data("powerpc/systemcfg", S_IFREG|S_IRUGO, NULL,
  56. &page_map_fops, vdso_data);
  57. if (!pde)
  58. return 1;
  59. proc_set_size(pde, PAGE_SIZE);
  60. return 0;
  61. }
  62. __initcall(proc_ppc64_init);
  63. #endif /* CONFIG_PPC64 */
  64. /*
  65. * Create the ppc64 and ppc64/rtas directories early. This allows us to
  66. * assume that they have been previously created in drivers.
  67. */
  68. static int __init proc_ppc64_create(void)
  69. {
  70. struct proc_dir_entry *root;
  71. root = proc_mkdir("powerpc", NULL);
  72. if (!root)
  73. return 1;
  74. #ifdef CONFIG_PPC64
  75. if (!proc_symlink("ppc64", NULL, "powerpc"))
  76. pr_err("Failed to create link /proc/ppc64 -> /proc/powerpc\n");
  77. #endif
  78. if (!of_find_node_by_path("/rtas"))
  79. return 0;
  80. if (!proc_mkdir("rtas", root))
  81. return 1;
  82. if (!proc_symlink("rtas", NULL, "powerpc/rtas"))
  83. return 1;
  84. return 0;
  85. }
  86. core_initcall(proc_ppc64_create);