kdebugfs.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * Architecture specific debugfs files
  3. *
  4. * Copyright (C) 2007, Intel Corp.
  5. * Huang Ying <ying.huang@intel.com>
  6. *
  7. * This file is released under the GPLv2.
  8. */
  9. #include <linux/debugfs.h>
  10. #include <linux/uaccess.h>
  11. #include <linux/module.h>
  12. #include <linux/slab.h>
  13. #include <linux/init.h>
  14. #include <linux/stat.h>
  15. #include <linux/io.h>
  16. #include <linux/mm.h>
  17. #include <asm/setup.h>
  18. struct dentry *arch_debugfs_dir;
  19. EXPORT_SYMBOL(arch_debugfs_dir);
  20. #ifdef CONFIG_DEBUG_BOOT_PARAMS
  21. struct setup_data_node {
  22. u64 paddr;
  23. u32 type;
  24. u32 len;
  25. };
  26. static ssize_t setup_data_read(struct file *file, char __user *user_buf,
  27. size_t count, loff_t *ppos)
  28. {
  29. struct setup_data_node *node = file->private_data;
  30. unsigned long remain;
  31. loff_t pos = *ppos;
  32. struct page *pg;
  33. void *p;
  34. u64 pa;
  35. if (pos < 0)
  36. return -EINVAL;
  37. if (pos >= node->len)
  38. return 0;
  39. if (count > node->len - pos)
  40. count = node->len - pos;
  41. pa = node->paddr + sizeof(struct setup_data) + pos;
  42. pg = pfn_to_page((pa + count - 1) >> PAGE_SHIFT);
  43. if (PageHighMem(pg)) {
  44. p = ioremap_cache(pa, count);
  45. if (!p)
  46. return -ENXIO;
  47. } else
  48. p = __va(pa);
  49. remain = copy_to_user(user_buf, p, count);
  50. if (PageHighMem(pg))
  51. iounmap(p);
  52. if (remain)
  53. return -EFAULT;
  54. *ppos = pos + count;
  55. return count;
  56. }
  57. static const struct file_operations fops_setup_data = {
  58. .read = setup_data_read,
  59. .open = simple_open,
  60. .llseek = default_llseek,
  61. };
  62. static int __init
  63. create_setup_data_node(struct dentry *parent, int no,
  64. struct setup_data_node *node)
  65. {
  66. struct dentry *d, *type, *data;
  67. char buf[16];
  68. sprintf(buf, "%d", no);
  69. d = debugfs_create_dir(buf, parent);
  70. if (!d)
  71. return -ENOMEM;
  72. type = debugfs_create_x32("type", S_IRUGO, d, &node->type);
  73. if (!type)
  74. goto err_dir;
  75. data = debugfs_create_file("data", S_IRUGO, d, node, &fops_setup_data);
  76. if (!data)
  77. goto err_type;
  78. return 0;
  79. err_type:
  80. debugfs_remove(type);
  81. err_dir:
  82. debugfs_remove(d);
  83. return -ENOMEM;
  84. }
  85. static int __init create_setup_data_nodes(struct dentry *parent)
  86. {
  87. struct setup_data_node *node;
  88. struct setup_data *data;
  89. int error;
  90. struct dentry *d;
  91. struct page *pg;
  92. u64 pa_data;
  93. int no = 0;
  94. d = debugfs_create_dir("setup_data", parent);
  95. if (!d)
  96. return -ENOMEM;
  97. pa_data = boot_params.hdr.setup_data;
  98. while (pa_data) {
  99. node = kmalloc(sizeof(*node), GFP_KERNEL);
  100. if (!node) {
  101. error = -ENOMEM;
  102. goto err_dir;
  103. }
  104. pg = pfn_to_page((pa_data+sizeof(*data)-1) >> PAGE_SHIFT);
  105. if (PageHighMem(pg)) {
  106. data = ioremap_cache(pa_data, sizeof(*data));
  107. if (!data) {
  108. kfree(node);
  109. error = -ENXIO;
  110. goto err_dir;
  111. }
  112. } else
  113. data = __va(pa_data);
  114. node->paddr = pa_data;
  115. node->type = data->type;
  116. node->len = data->len;
  117. error = create_setup_data_node(d, no, node);
  118. pa_data = data->next;
  119. if (PageHighMem(pg))
  120. iounmap(data);
  121. if (error)
  122. goto err_dir;
  123. no++;
  124. }
  125. return 0;
  126. err_dir:
  127. debugfs_remove(d);
  128. return error;
  129. }
  130. static struct debugfs_blob_wrapper boot_params_blob = {
  131. .data = &boot_params,
  132. .size = sizeof(boot_params),
  133. };
  134. static int __init boot_params_kdebugfs_init(void)
  135. {
  136. struct dentry *dbp, *version, *data;
  137. int error = -ENOMEM;
  138. dbp = debugfs_create_dir("boot_params", NULL);
  139. if (!dbp)
  140. return -ENOMEM;
  141. version = debugfs_create_x16("version", S_IRUGO, dbp,
  142. &boot_params.hdr.version);
  143. if (!version)
  144. goto err_dir;
  145. data = debugfs_create_blob("data", S_IRUGO, dbp,
  146. &boot_params_blob);
  147. if (!data)
  148. goto err_version;
  149. error = create_setup_data_nodes(dbp);
  150. if (error)
  151. goto err_data;
  152. return 0;
  153. err_data:
  154. debugfs_remove(data);
  155. err_version:
  156. debugfs_remove(version);
  157. err_dir:
  158. debugfs_remove(dbp);
  159. return error;
  160. }
  161. #endif /* CONFIG_DEBUG_BOOT_PARAMS */
  162. static int __init arch_kdebugfs_init(void)
  163. {
  164. int error = 0;
  165. arch_debugfs_dir = debugfs_create_dir("x86", NULL);
  166. if (!arch_debugfs_dir)
  167. return -ENOMEM;
  168. #ifdef CONFIG_DEBUG_BOOT_PARAMS
  169. error = boot_params_kdebugfs_init();
  170. #endif
  171. return error;
  172. }
  173. arch_initcall(arch_kdebugfs_init);