shpchp_sysfs.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 "shpchp.h"
  36. /* A few routines that create sysfs entries for the hot plug controller */
  37. static ssize_t show_ctrl (struct device *dev, struct device_attribute *attr, char *buf)
  38. {
  39. struct pci_dev *pci_dev;
  40. struct controller *ctrl;
  41. char * out = buf;
  42. int index;
  43. struct pci_resource *res;
  44. pci_dev = container_of (dev, struct pci_dev, dev);
  45. ctrl = pci_get_drvdata(pci_dev);
  46. out += sprintf(buf, "Free resources: memory\n");
  47. index = 11;
  48. res = ctrl->mem_head;
  49. while (res && index--) {
  50. out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
  51. res = res->next;
  52. }
  53. out += sprintf(out, "Free resources: prefetchable memory\n");
  54. index = 11;
  55. res = ctrl->p_mem_head;
  56. while (res && index--) {
  57. out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
  58. res = res->next;
  59. }
  60. out += sprintf(out, "Free resources: IO\n");
  61. index = 11;
  62. res = ctrl->io_head;
  63. while (res && index--) {
  64. out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
  65. res = res->next;
  66. }
  67. out += sprintf(out, "Free resources: bus numbers\n");
  68. index = 11;
  69. res = ctrl->bus_head;
  70. while (res && index--) {
  71. out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
  72. res = res->next;
  73. }
  74. return out - buf;
  75. }
  76. static DEVICE_ATTR (ctrl, S_IRUGO, show_ctrl, NULL);
  77. static ssize_t show_dev (struct device *dev, struct device_attribute *attr, char *buf)
  78. {
  79. struct pci_dev *pci_dev;
  80. struct controller *ctrl;
  81. char * out = buf;
  82. int index;
  83. struct pci_resource *res;
  84. struct pci_func *new_slot;
  85. struct slot *slot;
  86. pci_dev = container_of (dev, struct pci_dev, dev);
  87. ctrl = pci_get_drvdata(pci_dev);
  88. slot=ctrl->slot;
  89. while (slot) {
  90. new_slot = shpchp_slot_find(slot->bus, slot->device, 0);
  91. if (!new_slot)
  92. break;
  93. out += sprintf(out, "assigned resources: memory\n");
  94. index = 11;
  95. res = new_slot->mem_head;
  96. while (res && index--) {
  97. out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
  98. res = res->next;
  99. }
  100. out += sprintf(out, "assigned resources: prefetchable memory\n");
  101. index = 11;
  102. res = new_slot->p_mem_head;
  103. while (res && index--) {
  104. out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
  105. res = res->next;
  106. }
  107. out += sprintf(out, "assigned resources: IO\n");
  108. index = 11;
  109. res = new_slot->io_head;
  110. while (res && index--) {
  111. out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
  112. res = res->next;
  113. }
  114. out += sprintf(out, "assigned resources: bus numbers\n");
  115. index = 11;
  116. res = new_slot->bus_head;
  117. while (res && index--) {
  118. out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
  119. res = res->next;
  120. }
  121. slot=slot->next;
  122. }
  123. return out - buf;
  124. }
  125. static DEVICE_ATTR (dev, S_IRUGO, show_dev, NULL);
  126. void shpchp_create_ctrl_files (struct controller *ctrl)
  127. {
  128. device_create_file (&ctrl->pci_dev->dev, &dev_attr_ctrl);
  129. device_create_file (&ctrl->pci_dev->dev, &dev_attr_dev);
  130. }