shpchp_sysfs.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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/pci.h>
  32. #include "shpchp.h"
  33. /* A few routines that create sysfs entries for the hot plug controller */
  34. static ssize_t show_ctrl (struct device *dev, struct device_attribute *attr, char *buf)
  35. {
  36. struct pci_dev *pdev;
  37. char * out = buf;
  38. int index, busnr;
  39. struct resource *res;
  40. struct pci_bus *bus;
  41. pdev = container_of (dev, struct pci_dev, dev);
  42. bus = pdev->subordinate;
  43. out += sprintf(buf, "Free resources: memory\n");
  44. for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) {
  45. res = bus->resource[index];
  46. if (res && (res->flags & IORESOURCE_MEM) &&
  47. !(res->flags & IORESOURCE_PREFETCH)) {
  48. out += sprintf(out, "start = %8.8llx, "
  49. "length = %8.8llx\n",
  50. (unsigned long long)res->start,
  51. (unsigned long long)(res->end - res->start));
  52. }
  53. }
  54. out += sprintf(out, "Free resources: prefetchable memory\n");
  55. for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) {
  56. res = bus->resource[index];
  57. if (res && (res->flags & IORESOURCE_MEM) &&
  58. (res->flags & IORESOURCE_PREFETCH)) {
  59. out += sprintf(out, "start = %8.8llx, "
  60. "length = %8.8llx\n",
  61. (unsigned long long)res->start,
  62. (unsigned long long)(res->end - res->start));
  63. }
  64. }
  65. out += sprintf(out, "Free resources: IO\n");
  66. for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) {
  67. res = bus->resource[index];
  68. if (res && (res->flags & IORESOURCE_IO)) {
  69. out += sprintf(out, "start = %8.8llx, "
  70. "length = %8.8llx\n",
  71. (unsigned long long)res->start,
  72. (unsigned long long)(res->end - res->start));
  73. }
  74. }
  75. out += sprintf(out, "Free resources: bus numbers\n");
  76. for (busnr = bus->secondary; busnr <= bus->subordinate; busnr++) {
  77. if (!pci_find_bus(pci_domain_nr(bus), busnr))
  78. break;
  79. }
  80. if (busnr < bus->subordinate)
  81. out += sprintf(out, "start = %8.8x, length = %8.8x\n",
  82. busnr, (bus->subordinate - busnr));
  83. return out - buf;
  84. }
  85. static DEVICE_ATTR (ctrl, S_IRUGO, show_ctrl, NULL);
  86. int __must_check shpchp_create_ctrl_files (struct controller *ctrl)
  87. {
  88. return device_create_file (&ctrl->pci_dev->dev, &dev_attr_ctrl);
  89. }
  90. void shpchp_remove_ctrl_files(struct controller *ctrl)
  91. {
  92. device_remove_file(&ctrl->pci_dev->dev, &dev_attr_ctrl);
  93. }