1 // SPDX-License-Identifier: GPL-2.0+
3 * Compaq Hot Plug Controller Driver
5 * Copyright (c) 1995,2001 Compaq Computer Corporation
7 * Copyright (c) 2001 IBM Corp.
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/types.h>
18 #include <linux/pci.h>
22 /* A few routines that create sysfs entries for the hot plug controller */
24 static ssize_t show_ctrl(struct device *dev, struct device_attribute *attr, char *buf)
32 pdev = to_pci_dev(dev);
33 bus = pdev->subordinate;
35 len += sysfs_emit_at(buf, len, "Free resources: memory\n");
36 pci_bus_for_each_resource(bus, res, index) {
37 if (res && (res->flags & IORESOURCE_MEM) &&
38 !(res->flags & IORESOURCE_PREFETCH)) {
39 len += sysfs_emit_at(buf, len,
40 "start = %8.8llx, length = %8.8llx\n",
41 (unsigned long long)res->start,
42 (unsigned long long)resource_size(res));
45 len += sysfs_emit_at(buf, len, "Free resources: prefetchable memory\n");
46 pci_bus_for_each_resource(bus, res, index) {
47 if (res && (res->flags & IORESOURCE_MEM) &&
48 (res->flags & IORESOURCE_PREFETCH)) {
49 len += sysfs_emit_at(buf, len,
50 "start = %8.8llx, length = %8.8llx\n",
51 (unsigned long long)res->start,
52 (unsigned long long)resource_size(res));
55 len += sysfs_emit_at(buf, len, "Free resources: IO\n");
56 pci_bus_for_each_resource(bus, res, index) {
57 if (res && (res->flags & IORESOURCE_IO)) {
58 len += sysfs_emit_at(buf, len,
59 "start = %8.8llx, length = %8.8llx\n",
60 (unsigned long long)res->start,
61 (unsigned long long)resource_size(res));
64 len += sysfs_emit_at(buf, len, "Free resources: bus numbers\n");
65 for (busnr = bus->busn_res.start; busnr <= bus->busn_res.end; busnr++) {
66 if (!pci_find_bus(pci_domain_nr(bus), busnr))
69 if (busnr < bus->busn_res.end)
70 len += sysfs_emit_at(buf, len,
71 "start = %8.8x, length = %8.8x\n",
72 busnr, (int)(bus->busn_res.end - busnr));
76 static DEVICE_ATTR(ctrl, S_IRUGO, show_ctrl, NULL);
78 int shpchp_create_ctrl_files(struct controller *ctrl)
80 return device_create_file(&ctrl->pci_dev->dev, &dev_attr_ctrl);
83 void shpchp_remove_ctrl_files(struct controller *ctrl)
85 device_remove_file(&ctrl->pci_dev->dev, &dev_attr_ctrl);