proc_ppc64.c 3.2 KB

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