cpqphp_sysfs.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. * Compaq Hot Plug Controller Driver
  3. *
  4. * Copyright (C) 1995,2001 Compaq Computer Corporation
  5. * Copyright (C) 2001,2003 Greg Kroah-Hartman (greg@kroah.com)
  6. * Copyright (C) 2001 IBM Corp.
  7. *
  8. * All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or (at
  13. * your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  18. * NON INFRINGEMENT. See the GNU General Public License for more
  19. * details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. *
  25. * Send feedback to <greg@kroah.com>
  26. *
  27. */
  28. #include <linux/module.h>
  29. #include <linux/kernel.h>
  30. #include <linux/types.h>
  31. #include <linux/proc_fs.h>
  32. #include <linux/workqueue.h>
  33. #include <linux/pci.h>
  34. #include <linux/debugfs.h>
  35. #include "cpqphp.h"
  36. static int show_ctrl (struct controller *ctrl, char *buf)
  37. {
  38. char *out = buf;
  39. int index;
  40. struct pci_resource *res;
  41. out += sprintf(buf, "Free resources: memory\n");
  42. index = 11;
  43. res = ctrl->mem_head;
  44. while (res && index--) {
  45. out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
  46. res = res->next;
  47. }
  48. out += sprintf(out, "Free resources: prefetchable memory\n");
  49. index = 11;
  50. res = ctrl->p_mem_head;
  51. while (res && index--) {
  52. out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
  53. res = res->next;
  54. }
  55. out += sprintf(out, "Free resources: IO\n");
  56. index = 11;
  57. res = ctrl->io_head;
  58. while (res && index--) {
  59. out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
  60. res = res->next;
  61. }
  62. out += sprintf(out, "Free resources: bus numbers\n");
  63. index = 11;
  64. res = ctrl->bus_head;
  65. while (res && index--) {
  66. out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
  67. res = res->next;
  68. }
  69. return out - buf;
  70. }
  71. static int show_dev (struct controller *ctrl, char *buf)
  72. {
  73. char * out = buf;
  74. int index;
  75. struct pci_resource *res;
  76. struct pci_func *new_slot;
  77. struct slot *slot;
  78. slot = ctrl->slot;
  79. while (slot) {
  80. new_slot = cpqhp_slot_find(slot->bus, slot->device, 0);
  81. if (!new_slot)
  82. break;
  83. out += sprintf(out, "assigned resources: memory\n");
  84. index = 11;
  85. res = new_slot->mem_head;
  86. while (res && index--) {
  87. out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
  88. res = res->next;
  89. }
  90. out += sprintf(out, "assigned resources: prefetchable memory\n");
  91. index = 11;
  92. res = new_slot->p_mem_head;
  93. while (res && index--) {
  94. out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
  95. res = res->next;
  96. }
  97. out += sprintf(out, "assigned resources: IO\n");
  98. index = 11;
  99. res = new_slot->io_head;
  100. while (res && index--) {
  101. out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
  102. res = res->next;
  103. }
  104. out += sprintf(out, "assigned resources: bus numbers\n");
  105. index = 11;
  106. res = new_slot->bus_head;
  107. while (res && index--) {
  108. out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
  109. res = res->next;
  110. }
  111. slot=slot->next;
  112. }
  113. return out - buf;
  114. }
  115. static int spew_debug_info(struct controller *ctrl, char *data, int size)
  116. {
  117. int used;
  118. used = size - show_ctrl(ctrl, data);
  119. used = (size - used) - show_dev(ctrl, &data[used]);
  120. return used;
  121. }
  122. struct ctrl_dbg {
  123. int size;
  124. char *data;
  125. struct controller *ctrl;
  126. };
  127. #define MAX_OUTPUT (4*PAGE_SIZE)
  128. static int open(struct inode *inode, struct file *file)
  129. {
  130. struct controller *ctrl = inode->i_private;
  131. struct ctrl_dbg *dbg;
  132. int retval = -ENOMEM;
  133. lock_kernel();
  134. dbg = kmalloc(sizeof(*dbg), GFP_KERNEL);
  135. if (!dbg)
  136. goto exit;
  137. dbg->data = kmalloc(MAX_OUTPUT, GFP_KERNEL);
  138. if (!dbg->data) {
  139. kfree(dbg);
  140. goto exit;
  141. }
  142. dbg->size = spew_debug_info(ctrl, dbg->data, MAX_OUTPUT);
  143. file->private_data = dbg;
  144. retval = 0;
  145. exit:
  146. unlock_kernel();
  147. return retval;
  148. }
  149. static loff_t lseek(struct file *file, loff_t off, int whence)
  150. {
  151. struct ctrl_dbg *dbg;
  152. loff_t new = -1;
  153. lock_kernel();
  154. dbg = file->private_data;
  155. switch (whence) {
  156. case 0:
  157. new = off;
  158. break;
  159. case 1:
  160. new = file->f_pos + off;
  161. break;
  162. }
  163. if (new < 0 || new > dbg->size) {
  164. unlock_kernel();
  165. return -EINVAL;
  166. }
  167. unlock_kernel();
  168. return (file->f_pos = new);
  169. }
  170. static ssize_t read(struct file *file, char __user *buf,
  171. size_t nbytes, loff_t *ppos)
  172. {
  173. struct ctrl_dbg *dbg = file->private_data;
  174. return simple_read_from_buffer(buf, nbytes, ppos, dbg->data, dbg->size);
  175. }
  176. static int release(struct inode *inode, struct file *file)
  177. {
  178. struct ctrl_dbg *dbg = file->private_data;
  179. kfree(dbg->data);
  180. kfree(dbg);
  181. return 0;
  182. }
  183. static struct file_operations debug_ops = {
  184. .owner = THIS_MODULE,
  185. .open = open,
  186. .llseek = lseek,
  187. .read = read,
  188. .release = release,
  189. };
  190. static struct dentry *root;
  191. void cpqhp_initialize_debugfs(void)
  192. {
  193. if (!root)
  194. root = debugfs_create_dir("cpqhp", NULL);
  195. }
  196. void cpqhp_shutdown_debugfs(void)
  197. {
  198. debugfs_remove(root);
  199. }
  200. void cpqhp_create_debugfs_files(struct controller *ctrl)
  201. {
  202. ctrl->dentry = debugfs_create_file(ctrl->pci_dev->dev.bus_id, S_IRUGO, root, ctrl, &debug_ops);
  203. }
  204. void cpqhp_remove_debugfs_files(struct controller *ctrl)
  205. {
  206. if (ctrl->dentry)
  207. debugfs_remove(ctrl->dentry);
  208. ctrl->dentry = NULL;
  209. }