blob: b0e781dbcffba84b45c991712684e57ead4e27c9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
29#include <linux/config.h>
30#include <linux/module.h>
31#include <linux/kernel.h>
32#include <linux/types.h>
33#include <linux/proc_fs.h>
34#include <linux/workqueue.h>
35#include <linux/pci.h>
36#include "shpchp.h"
37
38
39/* A few routines that create sysfs entries for the hot plug controller */
40
Yani Ioannoue404e272005-05-17 06:42:58 -040041static ssize_t show_ctrl (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042{
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070043 struct pci_dev *pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 char * out = buf;
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070045 int index, busnr;
46 struct resource *res;
47 struct pci_bus *bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070049 pdev = container_of (dev, struct pci_dev, dev);
50 bus = pdev->subordinate;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52 out += sprintf(buf, "Free resources: memory\n");
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070053 for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) {
54 res = bus->resource[index];
55 if (res && (res->flags & IORESOURCE_MEM) &&
56 !(res->flags & IORESOURCE_PREFETCH)) {
57 out += sprintf(out, "start = %8.8lx, length = %8.8lx\n",
58 res->start, (res->end - res->start));
59 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 }
61 out += sprintf(out, "Free resources: prefetchable memory\n");
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070062 for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) {
63 res = bus->resource[index];
64 if (res && (res->flags & IORESOURCE_MEM) &&
65 (res->flags & IORESOURCE_PREFETCH)) {
66 out += sprintf(out, "start = %8.8lx, length = %8.8lx\n",
67 res->start, (res->end - res->start));
68 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 }
70 out += sprintf(out, "Free resources: IO\n");
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070071 for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) {
72 res = bus->resource[index];
73 if (res && (res->flags & IORESOURCE_IO)) {
74 out += sprintf(out, "start = %8.8lx, length = %8.8lx\n",
75 res->start, (res->end - res->start));
76 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 }
78 out += sprintf(out, "Free resources: bus numbers\n");
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070079 for (busnr = bus->secondary; busnr <= bus->subordinate; busnr++) {
80 if (!pci_find_bus(pci_domain_nr(bus), busnr))
81 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 }
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070083 if (busnr < bus->subordinate)
84 out += sprintf(out, "start = %8.8x, length = %8.8x\n",
85 busnr, (bus->subordinate - busnr));
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87 return out - buf;
88}
89static DEVICE_ATTR (ctrl, S_IRUGO, show_ctrl, NULL);
90
Yani Ioannoue404e272005-05-17 06:42:58 -040091static ssize_t show_dev (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092{
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070093 struct pci_dev *pdev, *fdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 struct controller *ctrl;
95 char * out = buf;
96 int index;
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070097 struct resource *res;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 struct pci_func *new_slot;
99 struct slot *slot;
100
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -0700101 pdev = container_of (dev, struct pci_dev, dev);
102 ctrl = pci_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104 slot=ctrl->slot;
105
106 while (slot) {
107 new_slot = shpchp_slot_find(slot->bus, slot->device, 0);
108 if (!new_slot)
109 break;
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -0700110 fdev = new_slot->pci_dev;
111 if (!fdev)
112 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 out += sprintf(out, "assigned resources: memory\n");
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -0700114 for (index=0; index <= PCI_NUM_RESOURCES; index++) {
115 res = &(fdev->resource[index]);
116 if (res && (res->flags & IORESOURCE_MEM) &&
117 !(res->flags & IORESOURCE_PREFETCH)) {
118 out += sprintf(out,
119 "start = %8.8lx, length = %8.8lx\n",
120 res->start, (res->end - res->start));
121 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 }
123 out += sprintf(out, "assigned resources: prefetchable memory\n");
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -0700124 for (index=0; index <= PCI_NUM_RESOURCES; index++) {
125 res = &(fdev->resource[index]);
126 if (res && (res->flags & (IORESOURCE_MEM |
127 IORESOURCE_PREFETCH))) {
128 out += sprintf(out,
129 "start = %8.8lx, length = %8.8lx\n",
130 res->start, (res->end - res->start));
131 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 }
133 out += sprintf(out, "assigned resources: IO\n");
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -0700134 for (index=0; index <= PCI_NUM_RESOURCES; index++) {
135 res = &(fdev->resource[index]);
136 if (res && (res->flags & IORESOURCE_IO)) {
137 out += sprintf(out,
138 "start = %8.8lx, length = %8.8lx\n",
139 res->start, (res->end - res->start));
140 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 }
142 out += sprintf(out, "assigned resources: bus numbers\n");
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -0700143 if (fdev->subordinate)
144 out += sprintf(out, "start = %8.8x, length = %8.8x\n",
145 fdev->subordinate->secondary,
146 (fdev->subordinate->subordinate -
147 fdev->subordinate->secondary));
148 else
149 out += sprintf(out, "start = %8.8x, length = %8.8x\n",
150 fdev->bus->number, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 slot=slot->next;
152 }
153
154 return out - buf;
155}
156static DEVICE_ATTR (dev, S_IRUGO, show_dev, NULL);
157
158void shpchp_create_ctrl_files (struct controller *ctrl)
159{
160 device_create_file (&ctrl->pci_dev->dev, &dev_attr_ctrl);
161 device_create_file (&ctrl->pci_dev->dev, &dev_attr_dev);
162}