Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/module.h> |
| 30 | #include <linux/kernel.h> |
| 31 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 38 | static ssize_t show_ctrl (struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | { |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 40 | struct pci_dev *pdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | char * out = buf; |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 42 | int index, busnr; |
| 43 | struct resource *res; |
| 44 | struct pci_bus *bus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 46 | pdev = container_of (dev, struct pci_dev, dev); |
| 47 | bus = pdev->subordinate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | out += sprintf(buf, "Free resources: memory\n"); |
Bjorn Helgaas | 89a74ec | 2010-02-23 10:24:31 -0700 | [diff] [blame^] | 50 | pci_bus_for_each_resource(bus, res, index) { |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 51 | if (res && (res->flags & IORESOURCE_MEM) && |
| 52 | !(res->flags & IORESOURCE_PREFETCH)) { |
Greg Kroah-Hartman | 1396a8c | 2006-06-12 15:14:29 -0700 | [diff] [blame] | 53 | out += sprintf(out, "start = %8.8llx, " |
| 54 | "length = %8.8llx\n", |
| 55 | (unsigned long long)res->start, |
| 56 | (unsigned long long)(res->end - res->start)); |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 57 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | } |
| 59 | out += sprintf(out, "Free resources: prefetchable memory\n"); |
Bjorn Helgaas | 89a74ec | 2010-02-23 10:24:31 -0700 | [diff] [blame^] | 60 | pci_bus_for_each_resource(bus, res, index) { |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 61 | if (res && (res->flags & IORESOURCE_MEM) && |
| 62 | (res->flags & IORESOURCE_PREFETCH)) { |
Greg Kroah-Hartman | 1396a8c | 2006-06-12 15:14:29 -0700 | [diff] [blame] | 63 | out += sprintf(out, "start = %8.8llx, " |
| 64 | "length = %8.8llx\n", |
| 65 | (unsigned long long)res->start, |
| 66 | (unsigned long long)(res->end - res->start)); |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 67 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | } |
| 69 | out += sprintf(out, "Free resources: IO\n"); |
Bjorn Helgaas | 89a74ec | 2010-02-23 10:24:31 -0700 | [diff] [blame^] | 70 | pci_bus_for_each_resource(bus, res, index) { |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 71 | if (res && (res->flags & IORESOURCE_IO)) { |
Greg Kroah-Hartman | 1396a8c | 2006-06-12 15:14:29 -0700 | [diff] [blame] | 72 | out += sprintf(out, "start = %8.8llx, " |
| 73 | "length = %8.8llx\n", |
| 74 | (unsigned long long)res->start, |
| 75 | (unsigned long long)(res->end - res->start)); |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 76 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | } |
| 78 | out += sprintf(out, "Free resources: bus numbers\n"); |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 79 | for (busnr = bus->secondary; busnr <= bus->subordinate; busnr++) { |
| 80 | if (!pci_find_bus(pci_domain_nr(bus), busnr)) |
| 81 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | } |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame] | 83 | if (busnr < bus->subordinate) |
| 84 | out += sprintf(out, "start = %8.8x, length = %8.8x\n", |
| 85 | busnr, (bus->subordinate - busnr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
| 87 | return out - buf; |
| 88 | } |
| 89 | static DEVICE_ATTR (ctrl, S_IRUGO, show_ctrl, NULL); |
| 90 | |
Greg Kroah-Hartman | e1b95dc | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 91 | int __must_check shpchp_create_ctrl_files (struct controller *ctrl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | { |
Greg Kroah-Hartman | e1b95dc | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 93 | return device_create_file (&ctrl->pci_dev->dev, &dev_attr_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | } |
rajesh.shah@intel.com | c2608a1 | 2005-10-13 12:05:44 -0700 | [diff] [blame] | 95 | |
| 96 | void shpchp_remove_ctrl_files(struct controller *ctrl) |
| 97 | { |
| 98 | device_remove_file(&ctrl->pci_dev->dev, &dev_attr_ctrl); |
| 99 | } |