shpchp_sysfs.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 *pdev;
  40. char * out = buf;
  41. int index, busnr;
  42. struct resource *res;
  43. struct pci_bus *bus;
  44. pdev = container_of (dev, struct pci_dev, dev);
  45. bus = pdev->subordinate;
  46. out += sprintf(buf, "Free resources: memory\n");
  47. for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) {
  48. res = bus->resource[index];
  49. if (res && (res->flags & IORESOURCE_MEM) &&
  50. !(res->flags & IORESOURCE_PREFETCH)) {
  51. out += sprintf(out, "start = %8.8lx, length = %8.8lx\n",
  52. res->start, (res->end - res->start));
  53. }
  54. }
  55. out += sprintf(out, "Free resources: prefetchable memory\n");
  56. for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) {
  57. res = bus->resource[index];
  58. if (res && (res->flags & IORESOURCE_MEM) &&
  59. (res->flags & IORESOURCE_PREFETCH)) {
  60. out += sprintf(out, "start = %8.8lx, length = %8.8lx\n",
  61. res->start, (res->end - res->start));
  62. }
  63. }
  64. out += sprintf(out, "Free resources: IO\n");
  65. for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) {
  66. res = bus->resource[index];
  67. if (res && (res->flags & IORESOURCE_IO)) {
  68. out += sprintf(out, "start = %8.8lx, length = %8.8lx\n",
  69. res->start, (res->end - res->start));
  70. }
  71. }
  72. out += sprintf(out, "Free resources: bus numbers\n");
  73. for (busnr = bus->secondary; busnr <= bus->subordinate; busnr++) {
  74. if (!pci_find_bus(pci_domain_nr(bus), busnr))
  75. break;
  76. }
  77. if (busnr < bus->subordinate)
  78. out += sprintf(out, "start = %8.8x, length = %8.8x\n",
  79. busnr, (bus->subordinate - busnr));
  80. return out - buf;
  81. }
  82. static DEVICE_ATTR (ctrl, S_IRUGO, show_ctrl, NULL);
  83. static ssize_t show_dev (struct device *dev, struct device_attribute *attr, char *buf)
  84. {
  85. struct pci_dev *pdev, *fdev;
  86. struct controller *ctrl;
  87. char * out = buf;
  88. int index;
  89. struct resource *res;
  90. struct pci_func *new_slot;
  91. struct slot *slot;
  92. pdev = container_of (dev, struct pci_dev, dev);
  93. ctrl = pci_get_drvdata(pdev);
  94. slot=ctrl->slot;
  95. while (slot) {
  96. new_slot = shpchp_slot_find(slot->bus, slot->device, 0);
  97. if (!new_slot)
  98. break;
  99. fdev = new_slot->pci_dev;
  100. if (!fdev)
  101. break;
  102. out += sprintf(out, "assigned resources: memory\n");
  103. for (index=0; index <= PCI_NUM_RESOURCES; index++) {
  104. res = &(fdev->resource[index]);
  105. if (res && (res->flags & IORESOURCE_MEM) &&
  106. !(res->flags & IORESOURCE_PREFETCH)) {
  107. out += sprintf(out,
  108. "start = %8.8lx, length = %8.8lx\n",
  109. res->start, (res->end - res->start));
  110. }
  111. }
  112. out += sprintf(out, "assigned resources: prefetchable memory\n");
  113. for (index=0; index <= PCI_NUM_RESOURCES; index++) {
  114. res = &(fdev->resource[index]);
  115. if (res && (res->flags & (IORESOURCE_MEM |
  116. IORESOURCE_PREFETCH))) {
  117. out += sprintf(out,
  118. "start = %8.8lx, length = %8.8lx\n",
  119. res->start, (res->end - res->start));
  120. }
  121. }
  122. out += sprintf(out, "assigned resources: IO\n");
  123. for (index=0; index <= PCI_NUM_RESOURCES; index++) {
  124. res = &(fdev->resource[index]);
  125. if (res && (res->flags & IORESOURCE_IO)) {
  126. out += sprintf(out,
  127. "start = %8.8lx, length = %8.8lx\n",
  128. res->start, (res->end - res->start));
  129. }
  130. }
  131. out += sprintf(out, "assigned resources: bus numbers\n");
  132. if (fdev->subordinate)
  133. out += sprintf(out, "start = %8.8x, length = %8.8x\n",
  134. fdev->subordinate->secondary,
  135. (fdev->subordinate->subordinate -
  136. fdev->subordinate->secondary));
  137. else
  138. out += sprintf(out, "start = %8.8x, length = %8.8x\n",
  139. fdev->bus->number, 1);
  140. slot=slot->next;
  141. }
  142. return out - buf;
  143. }
  144. static DEVICE_ATTR (dev, S_IRUGO, show_dev, NULL);
  145. void shpchp_create_ctrl_files (struct controller *ctrl)
  146. {
  147. device_create_file (&ctrl->pci_dev->dev, &dev_attr_ctrl);
  148. device_create_file (&ctrl->pci_dev->dev, &dev_attr_dev);
  149. }