Commit | Line | Data |
---|---|---|
736759ef | 1 | // SPDX-License-Identifier: GPL-2.0+ |
1da177e4 LT |
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 | * | |
1da177e4 LT |
11 | * Send feedback to <greg@kroah.com> |
12 | * | |
13 | */ | |
14 | ||
1da177e4 LT |
15 | #include <linux/module.h> |
16 | #include <linux/kernel.h> | |
17 | #include <linux/types.h> | |
1da177e4 LT |
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 | ||
ff3ce480 | 24 | static ssize_t show_ctrl(struct device *dev, struct device_attribute *attr, char *buf) |
1da177e4 | 25 | { |
dbd7a788 | 26 | struct pci_dev *pdev; |
3c78bc61 | 27 | char *out = buf; |
dbd7a788 | 28 | int index, busnr; |
29 | struct resource *res; | |
30 | struct pci_bus *bus; | |
1da177e4 | 31 | |
f3d2f165 | 32 | pdev = to_pci_dev(dev); |
dbd7a788 | 33 | bus = pdev->subordinate; |
1da177e4 LT |
34 | |
35 | out += sprintf(buf, "Free resources: memory\n"); | |
89a74ecc | 36 | pci_bus_for_each_resource(bus, res, index) { |
dbd7a788 | 37 | if (res && (res->flags & IORESOURCE_MEM) && |
38 | !(res->flags & IORESOURCE_PREFETCH)) { | |
28f65c11 JP |
39 | out += sprintf(out, "start = %8.8llx, length = %8.8llx\n", |
40 | (unsigned long long)res->start, | |
41 | (unsigned long long)resource_size(res)); | |
dbd7a788 | 42 | } |
1da177e4 LT |
43 | } |
44 | out += sprintf(out, "Free resources: prefetchable memory\n"); | |
89a74ecc | 45 | pci_bus_for_each_resource(bus, res, index) { |
dbd7a788 | 46 | if (res && (res->flags & IORESOURCE_MEM) && |
47 | (res->flags & IORESOURCE_PREFETCH)) { | |
28f65c11 JP |
48 | out += sprintf(out, "start = %8.8llx, length = %8.8llx\n", |
49 | (unsigned long long)res->start, | |
50 | (unsigned long long)resource_size(res)); | |
dbd7a788 | 51 | } |
1da177e4 LT |
52 | } |
53 | out += sprintf(out, "Free resources: IO\n"); | |
89a74ecc | 54 | pci_bus_for_each_resource(bus, res, index) { |
dbd7a788 | 55 | if (res && (res->flags & IORESOURCE_IO)) { |
28f65c11 JP |
56 | out += sprintf(out, "start = %8.8llx, length = %8.8llx\n", |
57 | (unsigned long long)res->start, | |
58 | (unsigned long long)resource_size(res)); | |
dbd7a788 | 59 | } |
1da177e4 LT |
60 | } |
61 | out += sprintf(out, "Free resources: bus numbers\n"); | |
b918c62e | 62 | for (busnr = bus->busn_res.start; busnr <= bus->busn_res.end; busnr++) { |
dbd7a788 | 63 | if (!pci_find_bus(pci_domain_nr(bus), busnr)) |
64 | break; | |
1da177e4 | 65 | } |
b918c62e | 66 | if (busnr < bus->busn_res.end) |
dbd7a788 | 67 | out += sprintf(out, "start = %8.8x, length = %8.8x\n", |
b918c62e | 68 | busnr, (int)(bus->busn_res.end - busnr)); |
1da177e4 LT |
69 | |
70 | return out - buf; | |
71 | } | |
ff3ce480 | 72 | static DEVICE_ATTR(ctrl, S_IRUGO, show_ctrl, NULL); |
1da177e4 | 73 | |
ff3ce480 | 74 | int shpchp_create_ctrl_files(struct controller *ctrl) |
1da177e4 | 75 | { |
ff3ce480 | 76 | return device_create_file(&ctrl->pci_dev->dev, &dev_attr_ctrl); |
1da177e4 | 77 | } |
c2608a11 | 78 | |
79 | void shpchp_remove_ctrl_files(struct controller *ctrl) | |
80 | { | |
81 | device_remove_file(&ctrl->pci_dev->dev, &dev_attr_ctrl); | |
82 | } |