proc_powerpc.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2001 Mike Corrigan & Dave Engebretsen IBM Corporation
  4. */
  5. #include <linux/init.h>
  6. #include <linux/mm.h>
  7. #include <linux/proc_fs.h>
  8. #include <linux/kernel.h>
  9. #include <asm/machdep.h>
  10. #include <asm/vdso_datapage.h>
  11. #include <asm/rtas.h>
  12. #include <linux/uaccess.h>
  13. #include <asm/prom.h>
  14. #ifdef CONFIG_PPC64
  15. static loff_t page_map_seek(struct file *file, loff_t off, int whence)
  16. {
  17. return fixed_size_llseek(file, off, whence, PAGE_SIZE);
  18. }
  19. static ssize_t page_map_read( struct file *file, char __user *buf, size_t nbytes,
  20. loff_t *ppos)
  21. {
  22. return simple_read_from_buffer(buf, nbytes, ppos,
  23. PDE_DATA(file_inode(file)), PAGE_SIZE);
  24. }
  25. static int page_map_mmap( struct file *file, struct vm_area_struct *vma )
  26. {
  27. if ((vma->vm_end - vma->vm_start) > PAGE_SIZE)
  28. return -EINVAL;
  29. remap_pfn_range(vma, vma->vm_start,
  30. __pa(PDE_DATA(file_inode(file))) >> PAGE_SHIFT,
  31. PAGE_SIZE, vma->vm_page_prot);
  32. return 0;
  33. }
  34. static const struct proc_ops page_map_proc_ops = {
  35. .proc_lseek = page_map_seek,
  36. .proc_read = page_map_read,
  37. .proc_mmap = page_map_mmap,
  38. };
  39. static int __init proc_ppc64_init(void)
  40. {
  41. struct proc_dir_entry *pde;
  42. pde = proc_create_data("powerpc/systemcfg", S_IFREG | 0444, NULL,
  43. &page_map_proc_ops, vdso_data);
  44. if (!pde)
  45. return 1;
  46. proc_set_size(pde, PAGE_SIZE);
  47. return 0;
  48. }
  49. __initcall(proc_ppc64_init);
  50. #endif /* CONFIG_PPC64 */
  51. /*
  52. * Create the ppc64 and ppc64/rtas directories early. This allows us to
  53. * assume that they have been previously created in drivers.
  54. */
  55. static int __init proc_ppc64_create(void)
  56. {
  57. struct proc_dir_entry *root;
  58. root = proc_mkdir("powerpc", NULL);
  59. if (!root)
  60. return 1;
  61. #ifdef CONFIG_PPC64
  62. if (!proc_symlink("ppc64", NULL, "powerpc"))
  63. pr_err("Failed to create link /proc/ppc64 -> /proc/powerpc\n");
  64. #endif
  65. if (!of_find_node_by_path("/rtas"))
  66. return 0;
  67. if (!proc_mkdir("rtas", root))
  68. return 1;
  69. if (!proc_symlink("rtas", NULL, "powerpc/rtas"))
  70. return 1;
  71. return 0;
  72. }
  73. core_initcall(proc_ppc64_create);