[PATCH] shpchp: miscellaneous cleanups
[linux-2.6/x86.git] / drivers / pci / hotplug / shpchp_sysfs.c
blob807ef66899c74bbb7162c675e0fd58af30ea3e26
1 /*
2 * Compaq Hot Plug Controller Driver
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.
8 * All rights reserved.
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.
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.
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.
25 * Send feedback to <greg@kroah.com>
29 #include <linux/module.h>
30 #include <linux/kernel.h>
31 #include <linux/types.h>
32 #include <linux/pci.h>
33 #include "shpchp.h"
36 /* A few routines that create sysfs entries for the hot plug controller */
38 static ssize_t show_ctrl (struct device *dev, struct device_attribute *attr, char *buf)
40 struct pci_dev *pdev;
41 char * out = buf;
42 int index, busnr;
43 struct resource *res;
44 struct pci_bus *bus;
46 pdev = container_of (dev, struct pci_dev, dev);
47 bus = pdev->subordinate;
49 out += sprintf(buf, "Free resources: memory\n");
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)) {
54 out += sprintf(out, "start = %8.8lx, length = %8.8lx\n",
55 res->start, (res->end - res->start));
58 out += sprintf(out, "Free resources: prefetchable memory\n");
59 for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) {
60 res = bus->resource[index];
61 if (res && (res->flags & IORESOURCE_MEM) &&
62 (res->flags & IORESOURCE_PREFETCH)) {
63 out += sprintf(out, "start = %8.8lx, length = %8.8lx\n",
64 res->start, (res->end - res->start));
67 out += sprintf(out, "Free resources: IO\n");
68 for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) {
69 res = bus->resource[index];
70 if (res && (res->flags & IORESOURCE_IO)) {
71 out += sprintf(out, "start = %8.8lx, length = %8.8lx\n",
72 res->start, (res->end - res->start));
75 out += sprintf(out, "Free resources: bus numbers\n");
76 for (busnr = bus->secondary; busnr <= bus->subordinate; busnr++) {
77 if (!pci_find_bus(pci_domain_nr(bus), busnr))
78 break;
80 if (busnr < bus->subordinate)
81 out += sprintf(out, "start = %8.8x, length = %8.8x\n",
82 busnr, (bus->subordinate - busnr));
84 return out - buf;
86 static DEVICE_ATTR (ctrl, S_IRUGO, show_ctrl, NULL);
88 void shpchp_create_ctrl_files (struct controller *ctrl)
90 device_create_file (&ctrl->pci_dev->dev, &dev_attr_ctrl);