cpqphp_sysfs.c 5.6 KB

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