Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Compaq Hot Plug Controller Driver | |
3 | * | |
4 | * Copyright (c) 1995,2001 Compaq Computer Corporation | |
5 | * Copyright (c) 2001,2003 Greg Kroah-Hartman (greg@kroah.com) | |
6 | * Copyright (c) 2001 IBM Corp. | |
7 | * | |
8 | * All rights reserved. | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License as published by | |
12 | * the Free Software Foundation; either version 2 of the License, or (at | |
13 | * your option) any later version. | |
14 | * | |
15 | * This program is distributed in the hope that it will be useful, but | |
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or | |
18 | * NON INFRINGEMENT. See the GNU General Public License for more | |
19 | * details. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License | |
22 | * along with this program; if not, write to the Free Software | |
23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
24 | * | |
25 | * Send feedback to <greg@kroah.com> | |
26 | * | |
27 | */ | |
28 | ||
1da177e4 LT |
29 | #include <linux/module.h> |
30 | #include <linux/kernel.h> | |
31 | #include <linux/types.h> | |
1da177e4 LT |
32 | #include <linux/pci.h> |
33 | #include "shpchp.h" | |
34 | ||
35 | ||
36 | /* A few routines that create sysfs entries for the hot plug controller */ | |
37 | ||
e404e274 | 38 | static ssize_t show_ctrl (struct device *dev, struct device_attribute *attr, char *buf) |
1da177e4 | 39 | { |
dbd7a788 | 40 | struct pci_dev *pdev; |
1da177e4 | 41 | char * out = buf; |
dbd7a788 RS |
42 | int index, busnr; |
43 | struct resource *res; | |
44 | struct pci_bus *bus; | |
1da177e4 | 45 | |
dbd7a788 RS |
46 | pdev = container_of (dev, struct pci_dev, dev); |
47 | bus = pdev->subordinate; | |
1da177e4 LT |
48 | |
49 | out += sprintf(buf, "Free resources: memory\n"); | |
dbd7a788 RS |
50 | for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) { |
51 | res = bus->resource[index]; | |
52 | if (res && (res->flags & IORESOURCE_MEM) && | |
53 | !(res->flags & IORESOURCE_PREFETCH)) { | |
1396a8c3 GKH |
54 | out += sprintf(out, "start = %8.8llx, " |
55 | "length = %8.8llx\n", | |
56 | (unsigned long long)res->start, | |
57 | (unsigned long long)(res->end - res->start)); | |
dbd7a788 | 58 | } |
1da177e4 LT |
59 | } |
60 | out += sprintf(out, "Free resources: prefetchable memory\n"); | |
dbd7a788 RS |
61 | for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) { |
62 | res = bus->resource[index]; | |
63 | if (res && (res->flags & IORESOURCE_MEM) && | |
64 | (res->flags & IORESOURCE_PREFETCH)) { | |
1396a8c3 GKH |
65 | out += sprintf(out, "start = %8.8llx, " |
66 | "length = %8.8llx\n", | |
67 | (unsigned long long)res->start, | |
68 | (unsigned long long)(res->end - res->start)); | |
dbd7a788 | 69 | } |
1da177e4 LT |
70 | } |
71 | out += sprintf(out, "Free resources: IO\n"); | |
dbd7a788 RS |
72 | for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) { |
73 | res = bus->resource[index]; | |
74 | if (res && (res->flags & IORESOURCE_IO)) { | |
1396a8c3 GKH |
75 | out += sprintf(out, "start = %8.8llx, " |
76 | "length = %8.8llx\n", | |
77 | (unsigned long long)res->start, | |
78 | (unsigned long long)(res->end - res->start)); | |
dbd7a788 | 79 | } |
1da177e4 LT |
80 | } |
81 | out += sprintf(out, "Free resources: bus numbers\n"); | |
dbd7a788 RS |
82 | for (busnr = bus->secondary; busnr <= bus->subordinate; busnr++) { |
83 | if (!pci_find_bus(pci_domain_nr(bus), busnr)) | |
84 | break; | |
1da177e4 | 85 | } |
dbd7a788 RS |
86 | if (busnr < bus->subordinate) |
87 | out += sprintf(out, "start = %8.8x, length = %8.8x\n", | |
88 | busnr, (bus->subordinate - busnr)); | |
1da177e4 LT |
89 | |
90 | return out - buf; | |
91 | } | |
92 | static DEVICE_ATTR (ctrl, S_IRUGO, show_ctrl, NULL); | |
93 | ||
e1b95dc6 | 94 | int __must_check shpchp_create_ctrl_files (struct controller *ctrl) |
1da177e4 | 95 | { |
e1b95dc6 | 96 | return device_create_file (&ctrl->pci_dev->dev, &dev_attr_ctrl); |
1da177e4 | 97 | } |
c2608a11 RS |
98 | |
99 | void shpchp_remove_ctrl_files(struct controller *ctrl) | |
100 | { | |
101 | device_remove_file(&ctrl->pci_dev->dev, &dev_attr_ctrl); | |
102 | } |