blob: eeb23ceae4a890c807e9a0ed630bf2bca91c09f6 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/module.h>
30#include <linux/kernel.h>
31#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/pci.h>
33#include "shpchp.h"
34
35
36/* A few routines that create sysfs entries for the hot plug controller */
37
Yani Ioannoue404e272005-05-17 06:42:58 -040038static ssize_t show_ctrl (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070040 struct pci_dev *pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 char * out = buf;
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070042 int index, busnr;
43 struct resource *res;
44 struct pci_bus *bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070046 pdev = container_of (dev, struct pci_dev, dev);
47 bus = pdev->subordinate;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49 out += sprintf(buf, "Free resources: memory\n");
Bjorn Helgaas89a74ec2010-02-23 10:24:31 -070050 pci_bus_for_each_resource(bus, res, index) {
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070051 if (res && (res->flags & IORESOURCE_MEM) &&
52 !(res->flags & IORESOURCE_PREFETCH)) {
Joe Perches28f65c112011-06-09 09:13:32 -070053 out += sprintf(out, "start = %8.8llx, length = %8.8llx\n",
54 (unsigned long long)res->start,
55 (unsigned long long)resource_size(res));
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070056 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 }
58 out += sprintf(out, "Free resources: prefetchable memory\n");
Bjorn Helgaas89a74ec2010-02-23 10:24:31 -070059 pci_bus_for_each_resource(bus, res, index) {
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070060 if (res && (res->flags & IORESOURCE_MEM) &&
61 (res->flags & IORESOURCE_PREFETCH)) {
Joe Perches28f65c112011-06-09 09:13:32 -070062 out += sprintf(out, "start = %8.8llx, length = %8.8llx\n",
63 (unsigned long long)res->start,
64 (unsigned long long)resource_size(res));
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070065 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 }
67 out += sprintf(out, "Free resources: IO\n");
Bjorn Helgaas89a74ec2010-02-23 10:24:31 -070068 pci_bus_for_each_resource(bus, res, index) {
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070069 if (res && (res->flags & IORESOURCE_IO)) {
Joe Perches28f65c112011-06-09 09:13:32 -070070 out += sprintf(out, "start = %8.8llx, length = %8.8llx\n",
71 (unsigned long long)res->start,
72 (unsigned long long)resource_size(res));
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070073 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 }
75 out += sprintf(out, "Free resources: bus numbers\n");
Yinghai Lub918c622012-05-17 18:51:11 -070076 for (busnr = bus->busn_res.start; busnr <= bus->busn_res.end; busnr++) {
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070077 if (!pci_find_bus(pci_domain_nr(bus), busnr))
78 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 }
Yinghai Lub918c622012-05-17 18:51:11 -070080 if (busnr < bus->busn_res.end)
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -070081 out += sprintf(out, "start = %8.8x, length = %8.8x\n",
Yinghai Lub918c622012-05-17 18:51:11 -070082 busnr, (int)(bus->busn_res.end - busnr));
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84 return out - buf;
85}
86static DEVICE_ATTR (ctrl, S_IRUGO, show_ctrl, NULL);
87
Greg Kroah-Hartmane1b95dc2006-08-28 11:43:25 -070088int __must_check shpchp_create_ctrl_files (struct controller *ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
Greg Kroah-Hartmane1b95dc2006-08-28 11:43:25 -070090 return device_create_file (&ctrl->pci_dev->dev, &dev_attr_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091}
rajesh.shah@intel.comc2608a12005-10-13 12:05:44 -070092
93void shpchp_remove_ctrl_files(struct controller *ctrl)
94{
95 device_remove_file(&ctrl->pci_dev->dev, &dev_attr_ctrl);
96}