Branch data Line data Source code
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 : :
15 : : #include <linux/module.h>
16 : : #include <linux/kernel.h>
17 : : #include <linux/types.h>
18 : : #include <linux/pci.h>
19 : : #include "shpchp.h"
20 : :
21 : :
22 : : /* A few routines that create sysfs entries for the hot plug controller */
23 : :
24 : 0 : static ssize_t show_ctrl(struct device *dev, struct device_attribute *attr, char *buf)
25 : : {
26 : 0 : struct pci_dev *pdev;
27 : 0 : char *out = buf;
28 : 0 : int index, busnr;
29 : 0 : struct resource *res;
30 : 0 : struct pci_bus *bus;
31 : :
32 : 0 : pdev = to_pci_dev(dev);
33 : 0 : bus = pdev->subordinate;
34 : :
35 : 0 : out += sprintf(buf, "Free resources: memory\n");
36 [ # # # # ]: 0 : pci_bus_for_each_resource(bus, res, index) {
37 [ # # # # ]: 0 : if (res && (res->flags & IORESOURCE_MEM) &&
38 : : !(res->flags & IORESOURCE_PREFETCH)) {
39 : 0 : out += sprintf(out, "start = %8.8llx, length = %8.8llx\n",
40 : : (unsigned long long)res->start,
41 : 0 : (unsigned long long)resource_size(res));
42 : : }
43 : : }
44 : 0 : out += sprintf(out, "Free resources: prefetchable memory\n");
45 [ # # # # ]: 0 : pci_bus_for_each_resource(bus, res, index) {
46 [ # # # # ]: 0 : if (res && (res->flags & IORESOURCE_MEM) &&
47 : : (res->flags & IORESOURCE_PREFETCH)) {
48 : 0 : out += sprintf(out, "start = %8.8llx, length = %8.8llx\n",
49 : : (unsigned long long)res->start,
50 : 0 : (unsigned long long)resource_size(res));
51 : : }
52 : : }
53 : 0 : out += sprintf(out, "Free resources: IO\n");
54 [ # # # # ]: 0 : pci_bus_for_each_resource(bus, res, index) {
55 [ # # # # ]: 0 : if (res && (res->flags & IORESOURCE_IO)) {
56 : 0 : out += sprintf(out, "start = %8.8llx, length = %8.8llx\n",
57 : : (unsigned long long)res->start,
58 : 0 : (unsigned long long)resource_size(res));
59 : : }
60 : : }
61 : 0 : out += sprintf(out, "Free resources: bus numbers\n");
62 [ # # ]: 0 : for (busnr = bus->busn_res.start; busnr <= bus->busn_res.end; busnr++) {
63 [ # # ]: 0 : if (!pci_find_bus(pci_domain_nr(bus), busnr))
64 : : break;
65 : : }
66 [ # # ]: 0 : if (busnr < bus->busn_res.end)
67 : 0 : out += sprintf(out, "start = %8.8x, length = %8.8x\n",
68 : 0 : busnr, (int)(bus->busn_res.end - busnr));
69 : :
70 : 0 : return out - buf;
71 : : }
72 : : static DEVICE_ATTR(ctrl, S_IRUGO, show_ctrl, NULL);
73 : :
74 : 0 : int shpchp_create_ctrl_files(struct controller *ctrl)
75 : : {
76 : 0 : return device_create_file(&ctrl->pci_dev->dev, &dev_attr_ctrl);
77 : : }
78 : :
79 : 0 : void shpchp_remove_ctrl_files(struct controller *ctrl)
80 : : {
81 : 0 : device_remove_file(&ctrl->pci_dev->dev, &dev_attr_ctrl);
82 : 0 : }
|