shpchp_sysfs.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Compaq Hot Plug Controller Driver
  4. *
  5. * Copyright (c) 1995,2001 Compaq Computer Corporation
  6. * Copyright (c) 2001,2003 Greg Kroah-Hartman ([email protected])
  7. * Copyright (c) 2001 IBM Corp.
  8. *
  9. * All rights reserved.
  10. *
  11. * Send feedback to <[email protected]>
  12. *
  13. */
  14. #include <linux/module.h>
  15. #include <linux/kernel.h>
  16. #include <linux/types.h>
  17. #include <linux/pci.h>
  18. #include "shpchp.h"
  19. /* A few routines that create sysfs entries for the hot plug controller */
  20. static ssize_t show_ctrl(struct device *dev, struct device_attribute *attr, char *buf)
  21. {
  22. struct pci_dev *pdev;
  23. int index, busnr;
  24. struct resource *res;
  25. struct pci_bus *bus;
  26. size_t len = 0;
  27. pdev = to_pci_dev(dev);
  28. bus = pdev->subordinate;
  29. len += sysfs_emit_at(buf, len, "Free resources: memory\n");
  30. pci_bus_for_each_resource(bus, res, index) {
  31. if (res && (res->flags & IORESOURCE_MEM) &&
  32. !(res->flags & IORESOURCE_PREFETCH)) {
  33. len += sysfs_emit_at(buf, len,
  34. "start = %8.8llx, length = %8.8llx\n",
  35. (unsigned long long)res->start,
  36. (unsigned long long)resource_size(res));
  37. }
  38. }
  39. len += sysfs_emit_at(buf, len, "Free resources: prefetchable memory\n");
  40. pci_bus_for_each_resource(bus, res, index) {
  41. if (res && (res->flags & IORESOURCE_MEM) &&
  42. (res->flags & IORESOURCE_PREFETCH)) {
  43. len += sysfs_emit_at(buf, len,
  44. "start = %8.8llx, length = %8.8llx\n",
  45. (unsigned long long)res->start,
  46. (unsigned long long)resource_size(res));
  47. }
  48. }
  49. len += sysfs_emit_at(buf, len, "Free resources: IO\n");
  50. pci_bus_for_each_resource(bus, res, index) {
  51. if (res && (res->flags & IORESOURCE_IO)) {
  52. len += sysfs_emit_at(buf, len,
  53. "start = %8.8llx, length = %8.8llx\n",
  54. (unsigned long long)res->start,
  55. (unsigned long long)resource_size(res));
  56. }
  57. }
  58. len += sysfs_emit_at(buf, len, "Free resources: bus numbers\n");
  59. for (busnr = bus->busn_res.start; busnr <= bus->busn_res.end; busnr++) {
  60. if (!pci_find_bus(pci_domain_nr(bus), busnr))
  61. break;
  62. }
  63. if (busnr < bus->busn_res.end)
  64. len += sysfs_emit_at(buf, len,
  65. "start = %8.8x, length = %8.8x\n",
  66. busnr, (int)(bus->busn_res.end - busnr));
  67. return len;
  68. }
  69. static DEVICE_ATTR(ctrl, S_IRUGO, show_ctrl, NULL);
  70. int shpchp_create_ctrl_files(struct controller *ctrl)
  71. {
  72. return device_create_file(&ctrl->pci_dev->dev, &dev_attr_ctrl);
  73. }
  74. void shpchp_remove_ctrl_files(struct controller *ctrl)
  75. {
  76. device_remove_file(&ctrl->pci_dev->dev, &dev_attr_ctrl);
  77. }