cpqphp_sysfs.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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/config.h>
  29. #include <linux/module.h>
  30. #include <linux/kernel.h>
  31. #include <linux/types.h>
  32. #include <linux/proc_fs.h>
  33. #include <linux/workqueue.h>
  34. #include <linux/pci.h>
  35. #include <linux/debugfs.h>
  36. #include "cpqphp.h"
  37. static int show_ctrl (struct controller *ctrl, char *buf)
  38. {
  39. char *out = buf;
  40. int index;
  41. struct pci_resource *res;
  42. out += sprintf(buf, "Free resources: memory\n");
  43. index = 11;
  44. res = ctrl->mem_head;
  45. while (res && index--) {
  46. out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
  47. res = res->next;
  48. }
  49. out += sprintf(out, "Free resources: prefetchable memory\n");
  50. index = 11;
  51. res = ctrl->p_mem_head;
  52. while (res && index--) {
  53. out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
  54. res = res->next;
  55. }
  56. out += sprintf(out, "Free resources: IO\n");
  57. index = 11;
  58. res = ctrl->io_head;
  59. while (res && index--) {
  60. out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
  61. res = res->next;
  62. }
  63. out += sprintf(out, "Free resources: bus numbers\n");
  64. index = 11;
  65. res = ctrl->bus_head;
  66. while (res && index--) {
  67. out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
  68. res = res->next;
  69. }
  70. return out - buf;
  71. }
  72. static int show_dev (struct controller *ctrl, char *buf)
  73. {
  74. char * out = buf;
  75. int index;
  76. struct pci_resource *res;
  77. struct pci_func *new_slot;
  78. struct slot *slot;
  79. slot = ctrl->slot;
  80. while (slot) {
  81. new_slot = cpqhp_slot_find(slot->bus, slot->device, 0);
  82. if (!new_slot)
  83. break;
  84. out += sprintf(out, "assigned resources: memory\n");
  85. index = 11;
  86. res = new_slot->mem_head;
  87. while (res && index--) {
  88. out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
  89. res = res->next;
  90. }
  91. out += sprintf(out, "assigned resources: prefetchable memory\n");
  92. index = 11;
  93. res = new_slot->p_mem_head;
  94. while (res && index--) {
  95. out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
  96. res = res->next;
  97. }
  98. out += sprintf(out, "assigned resources: IO\n");
  99. index = 11;
  100. res = new_slot->io_head;
  101. while (res && index--) {
  102. out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
  103. res = res->next;
  104. }
  105. out += sprintf(out, "assigned resources: bus numbers\n");
  106. index = 11;
  107. res = new_slot->bus_head;
  108. while (res && index--) {
  109. out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
  110. res = res->next;
  111. }
  112. slot=slot->next;
  113. }
  114. return out - buf;
  115. }
  116. static int spew_debug_info(struct controller *ctrl, char *data, int size)
  117. {
  118. int used;
  119. used = size - show_ctrl(ctrl, data);
  120. used = (size - used) - show_dev(ctrl, &data[used]);
  121. return used;
  122. }
  123. struct ctrl_dbg {
  124. int size;
  125. char *data;
  126. struct controller *ctrl;
  127. };
  128. #define MAX_OUTPUT (4*PAGE_SIZE)
  129. static int open(struct inode *inode, struct file *file)
  130. {
  131. struct controller *ctrl = inode->u.generic_ip;
  132. struct ctrl_dbg *dbg;
  133. int retval = -ENOMEM;
  134. lock_kernel();
  135. dbg = kmalloc(sizeof(*dbg), GFP_KERNEL);
  136. if (!dbg)
  137. goto exit;
  138. dbg->data = kmalloc(MAX_OUTPUT, GFP_KERNEL);
  139. if (!dbg->data) {
  140. kfree(dbg);
  141. goto exit;
  142. }
  143. dbg->size = spew_debug_info(ctrl, dbg->data, MAX_OUTPUT);
  144. file->private_data = dbg;
  145. retval = 0;
  146. exit:
  147. unlock_kernel();
  148. return retval;
  149. }
  150. static loff_t lseek(struct file *file, loff_t off, int whence)
  151. {
  152. struct ctrl_dbg *dbg;
  153. loff_t new = -1;
  154. lock_kernel();
  155. dbg = file->private_data;
  156. switch (whence) {
  157. case 0:
  158. new = off;
  159. break;
  160. case 1:
  161. new = file->f_pos + off;
  162. break;
  163. }
  164. if (new < 0 || new > dbg->size) {
  165. unlock_kernel();
  166. return -EINVAL;
  167. }
  168. unlock_kernel();
  169. return (file->f_pos = new);
  170. }
  171. static ssize_t read(struct file *file, char __user *buf,
  172. size_t nbytes, loff_t *ppos)
  173. {
  174. struct ctrl_dbg *dbg = file->private_data;
  175. return simple_read_from_buffer(buf, nbytes, ppos, dbg->data, dbg->size);
  176. }
  177. static int release(struct inode *inode, struct file *file)
  178. {
  179. struct ctrl_dbg *dbg = file->private_data;
  180. kfree(dbg->data);
  181. kfree(dbg);
  182. return 0;
  183. }
  184. static struct file_operations debug_ops = {
  185. .owner = THIS_MODULE,
  186. .open = open,
  187. .llseek = lseek,
  188. .read = read,
  189. .release = release,
  190. };
  191. static struct dentry *root;
  192. void cpqhp_initialize_debugfs(void)
  193. {
  194. if (!root)
  195. root = debugfs_create_dir("cpqhp", NULL);
  196. }
  197. void cpqhp_shutdown_debugfs(void)
  198. {
  199. debugfs_remove(root);
  200. }
  201. void cpqhp_create_debugfs_files(struct controller *ctrl)
  202. {
  203. ctrl->dentry = debugfs_create_file(ctrl->pci_dev->dev.bus_id, S_IRUGO, root, ctrl, &debug_ops);
  204. }
  205. void cpqhp_remove_debugfs_files(struct controller *ctrl)
  206. {
  207. if (ctrl->dentry)
  208. debugfs_remove(ctrl->dentry);
  209. ctrl->dentry = NULL;
  210. }