bootinfo_proc.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Based on arch/arm/kernel/atags_proc.c
  3. */
  4. #include <linux/fs.h>
  5. #include <linux/init.h>
  6. #include <linux/printk.h>
  7. #include <linux/proc_fs.h>
  8. #include <linux/slab.h>
  9. #include <linux/string.h>
  10. #include <asm/bootinfo.h>
  11. #include <asm/byteorder.h>
  12. static char bootinfo_tmp[1536] __initdata;
  13. static void *bootinfo_copy;
  14. static size_t bootinfo_size;
  15. static ssize_t bootinfo_read(struct file *file, char __user *buf,
  16. size_t count, loff_t *ppos)
  17. {
  18. return simple_read_from_buffer(buf, count, ppos, bootinfo_copy,
  19. bootinfo_size);
  20. }
  21. static const struct file_operations bootinfo_fops = {
  22. .read = bootinfo_read,
  23. .llseek = default_llseek,
  24. };
  25. void __init save_bootinfo(const struct bi_record *bi)
  26. {
  27. const void *start = bi;
  28. size_t size = sizeof(bi->tag);
  29. while (be16_to_cpu(bi->tag) != BI_LAST) {
  30. uint16_t n = be16_to_cpu(bi->size);
  31. size += n;
  32. bi = (struct bi_record *)((unsigned long)bi + n);
  33. }
  34. if (size > sizeof(bootinfo_tmp)) {
  35. pr_err("Cannot save %zu bytes of bootinfo\n", size);
  36. return;
  37. }
  38. pr_info("Saving %zu bytes of bootinfo\n", size);
  39. memcpy(bootinfo_tmp, start, size);
  40. bootinfo_size = size;
  41. }
  42. static int __init init_bootinfo_procfs(void)
  43. {
  44. /*
  45. * This cannot go into save_bootinfo() because kmalloc and proc don't
  46. * work yet when it is called.
  47. */
  48. struct proc_dir_entry *pde;
  49. if (!bootinfo_size)
  50. return -EINVAL;
  51. bootinfo_copy = kmemdup(bootinfo_tmp, bootinfo_size, GFP_KERNEL);
  52. if (!bootinfo_copy)
  53. return -ENOMEM;
  54. pde = proc_create_data("bootinfo", 0400, NULL, &bootinfo_fops, NULL);
  55. if (!pde) {
  56. kfree(bootinfo_copy);
  57. return -ENOMEM;
  58. }
  59. return 0;
  60. }
  61. arch_initcall(init_bootinfo_procfs);