kdebugfs.c 3.9 KB

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