1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29#include <linux/module.h>
30#include <linux/kernel.h>
31#include <linux/types.h>
32#include <linux/pci.h>
33#include "shpchp.h"
34
35
36
37
38static ssize_t show_ctrl(struct device *dev, struct device_attribute *attr, char *buf)
39{
40 struct pci_dev *pdev;
41 char *out = buf;
42 int index, busnr;
43 struct resource *res;
44 struct pci_bus *bus;
45
46 pdev = to_pci_dev(dev);
47 bus = pdev->subordinate;
48
49 out += sprintf(buf, "Free resources: memory\n");
50 pci_bus_for_each_resource(bus, res, index) {
51 if (res && (res->flags & IORESOURCE_MEM) &&
52 !(res->flags & IORESOURCE_PREFETCH)) {
53 out += sprintf(out, "start = %8.8llx, length = %8.8llx\n",
54 (unsigned long long)res->start,
55 (unsigned long long)resource_size(res));
56 }
57 }
58 out += sprintf(out, "Free resources: prefetchable memory\n");
59 pci_bus_for_each_resource(bus, res, index) {
60 if (res && (res->flags & IORESOURCE_MEM) &&
61 (res->flags & IORESOURCE_PREFETCH)) {
62 out += sprintf(out, "start = %8.8llx, length = %8.8llx\n",
63 (unsigned long long)res->start,
64 (unsigned long long)resource_size(res));
65 }
66 }
67 out += sprintf(out, "Free resources: IO\n");
68 pci_bus_for_each_resource(bus, res, index) {
69 if (res && (res->flags & IORESOURCE_IO)) {
70 out += sprintf(out, "start = %8.8llx, length = %8.8llx\n",
71 (unsigned long long)res->start,
72 (unsigned long long)resource_size(res));
73 }
74 }
75 out += sprintf(out, "Free resources: bus numbers\n");
76 for (busnr = bus->busn_res.start; busnr <= bus->busn_res.end; busnr++) {
77 if (!pci_find_bus(pci_domain_nr(bus), busnr))
78 break;
79 }
80 if (busnr < bus->busn_res.end)
81 out += sprintf(out, "start = %8.8x, length = %8.8x\n",
82 busnr, (int)(bus->busn_res.end - busnr));
83
84 return out - buf;
85}
86static DEVICE_ATTR(ctrl, S_IRUGO, show_ctrl, NULL);
87
88int shpchp_create_ctrl_files(struct controller *ctrl)
89{
90 return device_create_file(&ctrl->pci_dev->dev, &dev_attr_ctrl);
91}
92
93void shpchp_remove_ctrl_files(struct controller *ctrl)
94{
95 device_remove_file(&ctrl->pci_dev->dev, &dev_attr_ctrl);
96}
97