shpchp_sysfs.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 (greg@kroah.com)
  7. * Copyright (c) 2001 IBM Corp.
  8. *
  9. * All rights reserved.
  10. *
  11. * Send feedback to <greg@kroah.com>
  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. char *out = buf;
  24. int index, busnr;
  25. struct resource *res;
  26. struct pci_bus *bus;
  27. pdev = to_pci_dev(dev);
  28. bus = pdev->subordinate;
  29. out += sprintf(buf, "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. out += sprintf(out, "start = %8.8llx, length = %8.8llx\n",
  34. (unsigned long long)res->start,
  35. (unsigned long long)resource_size(res));
  36. }
  37. }
  38. out += sprintf(out, "Free resources: prefetchable memory\n");
  39. pci_bus_for_each_resource(bus, res, index) {
  40. if (res && (res->flags & IORESOURCE_MEM) &&
  41. (res->flags & IORESOURCE_PREFETCH)) {
  42. out += sprintf(out, "start = %8.8llx, length = %8.8llx\n",
  43. (unsigned long long)res->start,
  44. (unsigned long long)resource_size(res));
  45. }
  46. }
  47. out += sprintf(out, "Free resources: IO\n");
  48. pci_bus_for_each_resource(bus, res, index) {
  49. if (res && (res->flags & IORESOURCE_IO)) {
  50. out += sprintf(out, "start = %8.8llx, length = %8.8llx\n",
  51. (unsigned long long)res->start,
  52. (unsigned long long)resource_size(res));
  53. }
  54. }
  55. out += sprintf(out, "Free resources: bus numbers\n");
  56. for (busnr = bus->busn_res.start; busnr <= bus->busn_res.end; busnr++) {
  57. if (!pci_find_bus(pci_domain_nr(bus), busnr))
  58. break;
  59. }
  60. if (busnr < bus->busn_res.end)
  61. out += sprintf(out, "start = %8.8x, length = %8.8x\n",
  62. busnr, (int)(bus->busn_res.end - busnr));
  63. return out - buf;
  64. }
  65. static DEVICE_ATTR(ctrl, S_IRUGO, show_ctrl, NULL);
  66. int shpchp_create_ctrl_files(struct controller *ctrl)
  67. {
  68. return device_create_file(&ctrl->pci_dev->dev, &dev_attr_ctrl);
  69. }
  70. void shpchp_remove_ctrl_files(struct controller *ctrl)
  71. {
  72. device_remove_file(&ctrl->pci_dev->dev, &dev_attr_ctrl);
  73. }