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 | |
| 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 Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 41 | 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] | 42 | { |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame^] | 43 | struct pci_dev *pdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | char * out = buf; |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame^] | 45 | int index, busnr; |
| 46 | struct resource *res; |
| 47 | struct pci_bus *bus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame^] | 49 | pdev = container_of (dev, struct pci_dev, dev); |
| 50 | bus = pdev->subordinate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | out += sprintf(buf, "Free resources: memory\n"); |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame^] | 53 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | } |
| 61 | out += sprintf(out, "Free resources: prefetchable memory\n"); |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame^] | 62 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | } |
| 70 | out += sprintf(out, "Free resources: IO\n"); |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame^] | 71 | 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 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 | |
Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 91 | static ssize_t show_dev (struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | { |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame^] | 93 | struct pci_dev *pdev, *fdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | struct controller *ctrl; |
| 95 | char * out = buf; |
| 96 | int index; |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame^] | 97 | struct resource *res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | struct pci_func *new_slot; |
| 99 | struct slot *slot; |
| 100 | |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame^] | 101 | pdev = container_of (dev, struct pci_dev, dev); |
| 102 | ctrl = pci_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
| 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.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame^] | 110 | fdev = new_slot->pci_dev; |
| 111 | if (!fdev) |
| 112 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | out += sprintf(out, "assigned resources: memory\n"); |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame^] | 114 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | } |
| 123 | out += sprintf(out, "assigned resources: prefetchable memory\n"); |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame^] | 124 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | } |
| 133 | out += sprintf(out, "assigned resources: IO\n"); |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame^] | 134 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | } |
| 142 | out += sprintf(out, "assigned resources: bus numbers\n"); |
rajesh.shah@intel.com | dbd7a78 | 2005-10-13 12:05:36 -0700 | [diff] [blame^] | 143 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | slot=slot->next; |
| 152 | } |
| 153 | |
| 154 | return out - buf; |
| 155 | } |
| 156 | static DEVICE_ATTR (dev, S_IRUGO, show_dev, NULL); |
| 157 | |
| 158 | void 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 | } |