kdebugfs.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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/stat.h>
  12. #include <linux/init.h>
  13. #include <linux/io.h>
  14. #include <linux/mm.h>
  15. #include <linux/module.h>
  16. #include <asm/setup.h>
  17. struct dentry *arch_debugfs_dir;
  18. EXPORT_SYMBOL(arch_debugfs_dir);
  19. #ifdef CONFIG_DEBUG_BOOT_PARAMS
  20. struct setup_data_node {
  21. u64 paddr;
  22. u32 type;
  23. u32 len;
  24. };
  25. static ssize_t
  26. setup_data_read(struct file *file, char __user *user_buf, size_t count,
  27. 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. }
  50. remain = copy_to_user(user_buf, p, count);
  51. if (PageHighMem(pg))
  52. iounmap(p);
  53. if (remain)
  54. return -EFAULT;
  55. *ppos = pos + count;
  56. return count;
  57. }
  58. static int setup_data_open(struct inode *inode, struct file *file)
  59. {
  60. file->private_data = inode->i_private;
  61. return 0;
  62. }
  63. static const struct file_operations fops_setup_data = {
  64. .read = setup_data_read,
  65. .open = setup_data_open,
  66. };
  67. static int __init
  68. create_setup_data_node(struct dentry *parent, int no,
  69. struct setup_data_node *node)
  70. {
  71. struct dentry *d, *type, *data;
  72. char buf[16];
  73. int error;
  74. sprintf(buf, "%d", no);
  75. d = debugfs_create_dir(buf, parent);
  76. if (!d) {
  77. error = -ENOMEM;
  78. goto err_return;
  79. }
  80. type = debugfs_create_x32("type", S_IRUGO, d, &node->type);
  81. if (!type) {
  82. error = -ENOMEM;
  83. goto err_dir;
  84. }
  85. data = debugfs_create_file("data", S_IRUGO, d, node, &fops_setup_data);
  86. if (!data) {
  87. error = -ENOMEM;
  88. goto err_type;
  89. }
  90. return 0;
  91. err_type:
  92. debugfs_remove(type);
  93. err_dir:
  94. debugfs_remove(d);
  95. err_return:
  96. return error;
  97. }
  98. static int __init create_setup_data_nodes(struct dentry *parent)
  99. {
  100. struct setup_data_node *node;
  101. struct setup_data *data;
  102. int error, no = 0;
  103. struct dentry *d;
  104. struct page *pg;
  105. u64 pa_data;
  106. d = debugfs_create_dir("setup_data", parent);
  107. if (!d) {
  108. error = -ENOMEM;
  109. goto err_return;
  110. }
  111. pa_data = boot_params.hdr.setup_data;
  112. while (pa_data) {
  113. node = kmalloc(sizeof(*node), GFP_KERNEL);
  114. if (!node) {
  115. error = -ENOMEM;
  116. goto err_dir;
  117. }
  118. pg = pfn_to_page((pa_data+sizeof(*data)-1) >> PAGE_SHIFT);
  119. if (PageHighMem(pg)) {
  120. data = ioremap_cache(pa_data, sizeof(*data));
  121. if (!data) {
  122. kfree(node);
  123. error = -ENXIO;
  124. goto err_dir;
  125. }
  126. } else {
  127. data = __va(pa_data);
  128. }
  129. node->paddr = pa_data;
  130. node->type = data->type;
  131. node->len = data->len;
  132. error = create_setup_data_node(d, no, node);
  133. pa_data = data->next;
  134. if (PageHighMem(pg))
  135. iounmap(data);
  136. if (error)
  137. goto err_dir;
  138. no++;
  139. }
  140. return 0;
  141. err_dir:
  142. debugfs_remove(d);
  143. err_return:
  144. return error;
  145. }
  146. static struct debugfs_blob_wrapper boot_params_blob = {
  147. .data = &boot_params,
  148. .size = sizeof(boot_params),
  149. };
  150. static int __init boot_params_kdebugfs_init(void)
  151. {
  152. struct dentry *dbp, *version, *data;
  153. int error;
  154. dbp = debugfs_create_dir("boot_params", NULL);
  155. if (!dbp) {
  156. error = -ENOMEM;
  157. goto err_return;
  158. }
  159. version = debugfs_create_x16("version", S_IRUGO, dbp,
  160. &boot_params.hdr.version);
  161. if (!version) {
  162. error = -ENOMEM;
  163. goto err_dir;
  164. }
  165. data = debugfs_create_blob("data", S_IRUGO, dbp,
  166. &boot_params_blob);
  167. if (!data) {
  168. error = -ENOMEM;
  169. goto err_version;
  170. }
  171. error = create_setup_data_nodes(dbp);
  172. if (error)
  173. goto err_data;
  174. return 0;
  175. err_data:
  176. debugfs_remove(data);
  177. err_version:
  178. debugfs_remove(version);
  179. err_dir:
  180. debugfs_remove(dbp);
  181. err_return:
  182. return error;
  183. }
  184. #endif
  185. static int __init arch_kdebugfs_init(void)
  186. {
  187. int error = 0;
  188. arch_debugfs_dir = debugfs_create_dir("x86", NULL);
  189. if (!arch_debugfs_dir)
  190. return -ENOMEM;
  191. #ifdef CONFIG_DEBUG_BOOT_PARAMS
  192. error = boot_params_kdebugfs_init();
  193. #endif
  194. return error;
  195. }
  196. arch_initcall(arch_kdebugfs_init);