| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | *  pci_root.c - ACPI PCI Root Bridge Driver ($Revision: 40 $) | 
|  | 3 | * | 
|  | 4 | *  Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> | 
|  | 5 | *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> | 
|  | 6 | * | 
|  | 7 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|  | 8 | * | 
|  | 9 | *  This program is free software; you can redistribute it and/or modify | 
|  | 10 | *  it under the terms of the GNU General Public License as published by | 
|  | 11 | *  the Free Software Foundation; either version 2 of the License, or (at | 
|  | 12 | *  your option) any later version. | 
|  | 13 | * | 
|  | 14 | *  This program is distributed in the hope that it will be useful, but | 
|  | 15 | *  WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 16 | *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
|  | 17 | *  General Public License for more details. | 
|  | 18 | * | 
|  | 19 | *  You should have received a copy of the GNU General Public License along | 
|  | 20 | *  with this program; if not, write to the Free Software Foundation, Inc., | 
|  | 21 | *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | 
|  | 22 | * | 
|  | 23 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|  | 24 | */ | 
|  | 25 |  | 
|  | 26 | #include <linux/kernel.h> | 
|  | 27 | #include <linux/module.h> | 
|  | 28 | #include <linux/init.h> | 
|  | 29 | #include <linux/types.h> | 
|  | 30 | #include <linux/proc_fs.h> | 
|  | 31 | #include <linux/spinlock.h> | 
|  | 32 | #include <linux/pm.h> | 
|  | 33 | #include <linux/pci.h> | 
|  | 34 | #include <linux/acpi.h> | 
|  | 35 | #include <acpi/acpi_bus.h> | 
|  | 36 | #include <acpi/acpi_drivers.h> | 
|  | 37 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #define _COMPONENT		ACPI_PCI_COMPONENT | 
| Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 39 | ACPI_MODULE_NAME("pci_root"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #define ACPI_PCI_ROOT_CLASS		"pci_bridge" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #define ACPI_PCI_ROOT_DEVICE_NAME	"PCI Root Bridge" | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 42 | static int acpi_pci_root_add(struct acpi_device *device); | 
|  | 43 | static int acpi_pci_root_remove(struct acpi_device *device, int type); | 
|  | 44 | static int acpi_pci_root_start(struct acpi_device *device); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 |  | 
| Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 46 | static struct acpi_device_id root_device_ids[] = { | 
|  | 47 | {"PNP0A03", 0}, | 
|  | 48 | {"", 0}, | 
|  | 49 | }; | 
|  | 50 | MODULE_DEVICE_TABLE(acpi, root_device_ids); | 
|  | 51 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | static struct acpi_driver acpi_pci_root_driver = { | 
| Len Brown | c2b6705b | 2007-02-12 23:33:40 -0500 | [diff] [blame] | 53 | .name = "pci_root", | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 54 | .class = ACPI_PCI_ROOT_CLASS, | 
| Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 55 | .ids = root_device_ids, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 56 | .ops = { | 
|  | 57 | .add = acpi_pci_root_add, | 
|  | 58 | .remove = acpi_pci_root_remove, | 
|  | 59 | .start = acpi_pci_root_start, | 
|  | 60 | }, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | }; | 
|  | 62 |  | 
|  | 63 | struct acpi_pci_root { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 64 | struct list_head node; | 
| Patrick Mochel | 32917e5 | 2006-05-19 16:54:39 -0400 | [diff] [blame] | 65 | struct acpi_device * device; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 66 | struct acpi_pci_id id; | 
|  | 67 | struct pci_bus *bus; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | }; | 
|  | 69 |  | 
|  | 70 | static LIST_HEAD(acpi_pci_roots); | 
|  | 71 |  | 
|  | 72 | static struct acpi_pci_driver *sub_driver; | 
|  | 73 |  | 
|  | 74 | int acpi_pci_register_driver(struct acpi_pci_driver *driver) | 
|  | 75 | { | 
|  | 76 | int n = 0; | 
|  | 77 | struct list_head *entry; | 
|  | 78 |  | 
|  | 79 | struct acpi_pci_driver **pptr = &sub_driver; | 
|  | 80 | while (*pptr) | 
|  | 81 | pptr = &(*pptr)->next; | 
|  | 82 | *pptr = driver; | 
|  | 83 |  | 
|  | 84 | if (!driver->add) | 
|  | 85 | return 0; | 
|  | 86 |  | 
|  | 87 | list_for_each(entry, &acpi_pci_roots) { | 
|  | 88 | struct acpi_pci_root *root; | 
|  | 89 | root = list_entry(entry, struct acpi_pci_root, node); | 
| Patrick Mochel | 2d1e0a0 | 2006-05-19 16:54:43 -0400 | [diff] [blame] | 90 | driver->add(root->device->handle); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | n++; | 
|  | 92 | } | 
|  | 93 |  | 
|  | 94 | return n; | 
|  | 95 | } | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 96 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | EXPORT_SYMBOL(acpi_pci_register_driver); | 
|  | 98 |  | 
|  | 99 | void acpi_pci_unregister_driver(struct acpi_pci_driver *driver) | 
|  | 100 | { | 
|  | 101 | struct list_head *entry; | 
|  | 102 |  | 
|  | 103 | struct acpi_pci_driver **pptr = &sub_driver; | 
|  | 104 | while (*pptr) { | 
| Akinobu Mita | f10bb25 | 2006-12-19 12:56:09 -0800 | [diff] [blame] | 105 | if (*pptr == driver) | 
|  | 106 | break; | 
|  | 107 | pptr = &(*pptr)->next; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | } | 
| Akinobu Mita | f10bb25 | 2006-12-19 12:56:09 -0800 | [diff] [blame] | 109 | BUG_ON(!*pptr); | 
|  | 110 | *pptr = (*pptr)->next; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 |  | 
|  | 112 | if (!driver->remove) | 
|  | 113 | return; | 
|  | 114 |  | 
|  | 115 | list_for_each(entry, &acpi_pci_roots) { | 
|  | 116 | struct acpi_pci_root *root; | 
|  | 117 | root = list_entry(entry, struct acpi_pci_root, node); | 
| Patrick Mochel | 2d1e0a0 | 2006-05-19 16:54:43 -0400 | [diff] [blame] | 118 | driver->remove(root->device->handle); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } | 
|  | 120 | } | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 121 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | EXPORT_SYMBOL(acpi_pci_unregister_driver); | 
|  | 123 |  | 
| Justin Chen | d91a007 | 2006-12-06 10:17:10 -0700 | [diff] [blame] | 124 | acpi_handle acpi_get_pci_rootbridge_handle(unsigned int seg, unsigned int bus) | 
|  | 125 | { | 
|  | 126 | struct acpi_pci_root *tmp; | 
|  | 127 |  | 
|  | 128 | list_for_each_entry(tmp, &acpi_pci_roots, node) { | 
|  | 129 | if ((tmp->id.segment == (u16) seg) && (tmp->id.bus == (u16) bus)) | 
|  | 130 | return tmp->device->handle; | 
|  | 131 | } | 
|  | 132 | return NULL; | 
|  | 133 | } | 
|  | 134 |  | 
|  | 135 | EXPORT_SYMBOL_GPL(acpi_get_pci_rootbridge_handle); | 
|  | 136 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | static acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 138 | get_root_bridge_busnr_callback(struct acpi_resource *resource, void *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | { | 
| Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 140 | int *busnr = data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | struct acpi_resource_address64 address; | 
|  | 142 |  | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 143 | if (resource->type != ACPI_RESOURCE_TYPE_ADDRESS16 && | 
|  | 144 | resource->type != ACPI_RESOURCE_TYPE_ADDRESS32 && | 
|  | 145 | resource->type != ACPI_RESOURCE_TYPE_ADDRESS64) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | return AE_OK; | 
|  | 147 |  | 
|  | 148 | acpi_resource_to_address64(resource, &address); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 149 | if ((address.address_length > 0) && | 
|  | 150 | (address.resource_type == ACPI_BUS_NUMBER_RANGE)) | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 151 | *busnr = address.minimum; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 |  | 
|  | 153 | return AE_OK; | 
|  | 154 | } | 
|  | 155 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 156 | static acpi_status try_get_root_bridge_busnr(acpi_handle handle, int *busnum) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { | 
|  | 158 | acpi_status status; | 
|  | 159 |  | 
|  | 160 | *busnum = -1; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 161 | status = | 
|  | 162 | acpi_walk_resources(handle, METHOD_NAME__CRS, | 
|  | 163 | get_root_bridge_busnr_callback, busnum); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | if (ACPI_FAILURE(status)) | 
|  | 165 | return status; | 
|  | 166 | /* Check if we really get a bus number from _CRS */ | 
|  | 167 | if (*busnum == -1) | 
|  | 168 | return AE_ERROR; | 
|  | 169 | return AE_OK; | 
|  | 170 | } | 
|  | 171 |  | 
| Rui Zhang | 2786f6e | 2006-12-21 02:21:13 -0500 | [diff] [blame] | 172 | static void acpi_pci_bridge_scan(struct acpi_device *device) | 
|  | 173 | { | 
|  | 174 | int status; | 
|  | 175 | struct acpi_device *child = NULL; | 
|  | 176 |  | 
|  | 177 | if (device->flags.bus_address) | 
|  | 178 | if (device->parent && device->parent->ops.bind) { | 
|  | 179 | status = device->parent->ops.bind(device); | 
|  | 180 | if (!status) { | 
|  | 181 | list_for_each_entry(child, &device->children, node) | 
|  | 182 | acpi_pci_bridge_scan(child); | 
|  | 183 | } | 
|  | 184 | } | 
|  | 185 | } | 
|  | 186 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 187 | static int acpi_pci_root_add(struct acpi_device *device) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 189 | int result = 0; | 
|  | 190 | struct acpi_pci_root *root = NULL; | 
|  | 191 | struct acpi_pci_root *tmp; | 
|  | 192 | acpi_status status = AE_OK; | 
|  | 193 | unsigned long value = 0; | 
|  | 194 | acpi_handle handle = NULL; | 
| Rui Zhang | 2786f6e | 2006-12-21 02:21:13 -0500 | [diff] [blame] | 195 | struct acpi_device *child; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 |  | 
|  | 198 | if (!device) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 199 | return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 |  | 
| Burman Yan | 36bcbec | 2006-12-19 12:56:11 -0800 | [diff] [blame] | 201 | root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | if (!root) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 203 | return -ENOMEM; | 
| Rajesh Shah | c431ada | 2005-04-28 00:25:45 -0700 | [diff] [blame] | 204 | INIT_LIST_HEAD(&root->node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 |  | 
| Patrick Mochel | 32917e5 | 2006-05-19 16:54:39 -0400 | [diff] [blame] | 206 | root->device = device; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME); | 
|  | 208 | strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS); | 
|  | 209 | acpi_driver_data(device) = root; | 
|  | 210 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | device->ops.bind = acpi_pci_bind; | 
|  | 212 |  | 
|  | 213 | /* | 
|  | 214 | * Segment | 
|  | 215 | * ------- | 
|  | 216 | * Obtained via _SEG, if exists, otherwise assumed to be zero (0). | 
|  | 217 | */ | 
| Patrick Mochel | 2d1e0a0 | 2006-05-19 16:54:43 -0400 | [diff] [blame] | 218 | status = acpi_evaluate_integer(device->handle, METHOD_NAME__SEG, NULL, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 219 | &value); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | switch (status) { | 
|  | 221 | case AE_OK: | 
|  | 222 | root->id.segment = (u16) value; | 
|  | 223 | break; | 
|  | 224 | case AE_NOT_FOUND: | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 225 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
|  | 226 | "Assuming segment 0 (no _SEG)\n")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | root->id.segment = 0; | 
|  | 228 | break; | 
|  | 229 | default: | 
| Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 230 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _SEG")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | result = -ENODEV; | 
|  | 232 | goto end; | 
|  | 233 | } | 
|  | 234 |  | 
|  | 235 | /* | 
|  | 236 | * Bus | 
|  | 237 | * --- | 
|  | 238 | * Obtained via _BBN, if exists, otherwise assumed to be zero (0). | 
|  | 239 | */ | 
| Patrick Mochel | 2d1e0a0 | 2006-05-19 16:54:43 -0400 | [diff] [blame] | 240 | status = acpi_evaluate_integer(device->handle, METHOD_NAME__BBN, NULL, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 241 | &value); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | switch (status) { | 
|  | 243 | case AE_OK: | 
|  | 244 | root->id.bus = (u16) value; | 
|  | 245 | break; | 
|  | 246 | case AE_NOT_FOUND: | 
|  | 247 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Assuming bus 0 (no _BBN)\n")); | 
|  | 248 | root->id.bus = 0; | 
|  | 249 | break; | 
|  | 250 | default: | 
| Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 251 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BBN")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | result = -ENODEV; | 
|  | 253 | goto end; | 
|  | 254 | } | 
|  | 255 |  | 
|  | 256 | /* Some systems have wrong _BBN */ | 
|  | 257 | list_for_each_entry(tmp, &acpi_pci_roots, node) { | 
|  | 258 | if ((tmp->id.segment == root->id.segment) | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 259 | && (tmp->id.bus == root->id.bus)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | int bus = 0; | 
|  | 261 | acpi_status status; | 
|  | 262 |  | 
| Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 263 | printk(KERN_ERR PREFIX | 
| Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 264 | "Wrong _BBN value, reboot" | 
| Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 265 | " and use option 'pci=noacpi'\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 |  | 
| Patrick Mochel | 2d1e0a0 | 2006-05-19 16:54:43 -0400 | [diff] [blame] | 267 | status = try_get_root_bridge_busnr(device->handle, &bus); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | if (ACPI_FAILURE(status)) | 
|  | 269 | break; | 
|  | 270 | if (bus != root->id.bus) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 271 | printk(KERN_INFO PREFIX | 
|  | 272 | "PCI _CRS %d overrides _BBN 0\n", bus); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | root->id.bus = bus; | 
|  | 274 | } | 
|  | 275 | break; | 
|  | 276 | } | 
|  | 277 | } | 
|  | 278 | /* | 
|  | 279 | * Device & Function | 
|  | 280 | * ----------------- | 
|  | 281 | * Obtained from _ADR (which has already been evaluated for us). | 
|  | 282 | */ | 
|  | 283 | root->id.device = device->pnp.bus_address >> 16; | 
|  | 284 | root->id.function = device->pnp.bus_address & 0xFFFF; | 
|  | 285 |  | 
|  | 286 | /* | 
|  | 287 | * TBD: Need PCI interface for enumeration/configuration of roots. | 
|  | 288 | */ | 
|  | 289 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 290 | /* TBD: Locking */ | 
|  | 291 | list_add_tail(&root->node, &acpi_pci_roots); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 293 | printk(KERN_INFO PREFIX "%s [%s] (%04x:%02x)\n", | 
|  | 294 | acpi_device_name(device), acpi_device_bid(device), | 
|  | 295 | root->id.segment, root->id.bus); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 |  | 
|  | 297 | /* | 
|  | 298 | * Scan the Root Bridge | 
|  | 299 | * -------------------- | 
|  | 300 | * Must do this prior to any attempt to bind the root device, as the | 
|  | 301 | * PCI namespace does not get created until this call is made (and | 
|  | 302 | * thus the root bridge's pci_dev does not exist). | 
|  | 303 | */ | 
|  | 304 | root->bus = pci_acpi_scan_root(device, root->id.segment, root->id.bus); | 
|  | 305 | if (!root->bus) { | 
| Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 306 | printk(KERN_ERR PREFIX | 
|  | 307 | "Bus %04x:%02x not present in PCI namespace\n", | 
|  | 308 | root->id.segment, root->id.bus); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | result = -ENODEV; | 
|  | 310 | goto end; | 
|  | 311 | } | 
|  | 312 |  | 
|  | 313 | /* | 
|  | 314 | * Attach ACPI-PCI Context | 
|  | 315 | * ----------------------- | 
|  | 316 | * Thus binding the ACPI and PCI devices. | 
|  | 317 | */ | 
|  | 318 | result = acpi_pci_bind_root(device, &root->id, root->bus); | 
|  | 319 | if (result) | 
|  | 320 | goto end; | 
|  | 321 |  | 
|  | 322 | /* | 
|  | 323 | * PCI Routing Table | 
|  | 324 | * ----------------- | 
|  | 325 | * Evaluate and parse _PRT, if exists. | 
|  | 326 | */ | 
| Patrick Mochel | 2d1e0a0 | 2006-05-19 16:54:43 -0400 | [diff] [blame] | 327 | status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | if (ACPI_SUCCESS(status)) | 
| Patrick Mochel | 2d1e0a0 | 2006-05-19 16:54:43 -0400 | [diff] [blame] | 329 | result = acpi_pci_irq_add_prt(device->handle, root->id.segment, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 330 | root->id.bus); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 |  | 
| Rui Zhang | 2786f6e | 2006-12-21 02:21:13 -0500 | [diff] [blame] | 332 | /* | 
|  | 333 | * Scan and bind all _ADR-Based Devices | 
|  | 334 | */ | 
|  | 335 | list_for_each_entry(child, &device->children, node) | 
|  | 336 | acpi_pci_bridge_scan(child); | 
|  | 337 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 338 | end: | 
| Rajesh Shah | c431ada | 2005-04-28 00:25:45 -0700 | [diff] [blame] | 339 | if (result) { | 
|  | 340 | if (!list_empty(&root->node)) | 
|  | 341 | list_del(&root->node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | kfree(root); | 
| Rajesh Shah | c431ada | 2005-04-28 00:25:45 -0700 | [diff] [blame] | 343 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 345 | return result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | } | 
|  | 347 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 348 | static int acpi_pci_root_start(struct acpi_device *device) | 
| Rajesh Shah | c431ada | 2005-04-28 00:25:45 -0700 | [diff] [blame] | 349 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 350 | struct acpi_pci_root *root; | 
| Rajesh Shah | c431ada | 2005-04-28 00:25:45 -0700 | [diff] [blame] | 351 |  | 
| Rajesh Shah | c431ada | 2005-04-28 00:25:45 -0700 | [diff] [blame] | 352 |  | 
|  | 353 | list_for_each_entry(root, &acpi_pci_roots, node) { | 
| Patrick Mochel | 432bfab | 2006-05-19 16:54:51 -0400 | [diff] [blame] | 354 | if (root->device == device) { | 
| Rajesh Shah | c431ada | 2005-04-28 00:25:45 -0700 | [diff] [blame] | 355 | pci_bus_add_devices(root->bus); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 356 | return 0; | 
| Rajesh Shah | c431ada | 2005-04-28 00:25:45 -0700 | [diff] [blame] | 357 | } | 
|  | 358 | } | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 359 | return -ENODEV; | 
| Rajesh Shah | c431ada | 2005-04-28 00:25:45 -0700 | [diff] [blame] | 360 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 362 | static int acpi_pci_root_remove(struct acpi_device *device, int type) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 364 | struct acpi_pci_root *root = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 |  | 
|  | 367 | if (!device || !acpi_driver_data(device)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 368 | return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 |  | 
| Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 370 | root = acpi_driver_data(device); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 |  | 
|  | 372 | kfree(root); | 
|  | 373 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 374 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | } | 
|  | 376 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 377 | static int __init acpi_pci_root_init(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 |  | 
|  | 380 | if (acpi_pci_disabled) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 381 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 |  | 
|  | 383 | /* DEBUG: | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 384 | acpi_dbg_layer = ACPI_PCI_COMPONENT; | 
|  | 385 | acpi_dbg_level = 0xFFFFFFFF; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | */ | 
|  | 387 |  | 
|  | 388 | if (acpi_bus_register_driver(&acpi_pci_root_driver) < 0) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 389 | return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 391 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | } | 
|  | 393 |  | 
|  | 394 | subsys_initcall(acpi_pci_root_init); |