Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * pci_bind.c - ACPI PCI Device Binding ($Revision: 2 $) |
| 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 | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 39 | ACPI_MODULE_NAME("pci_bind") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 41 | struct acpi_pci_data { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 42 | struct acpi_pci_id id; |
| 43 | struct pci_bus *bus; |
| 44 | struct pci_dev *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 47 | void acpi_pci_data_handler(acpi_handle handle, u32 function, void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | { |
| 49 | ACPI_FUNCTION_TRACE("acpi_pci_data_handler"); |
| 50 | |
| 51 | /* TBD: Anything we need to do here? */ |
| 52 | |
| 53 | return_VOID; |
| 54 | } |
| 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | /** |
Rajesh Shah | 4ce448e | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 57 | * acpi_get_pci_id |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | * ------------------ |
| 59 | * This function is used by the ACPI Interpreter (a.k.a. Core Subsystem) |
| 60 | * to resolve PCI information for ACPI-PCI devices defined in the namespace. |
| 61 | * This typically occurs when resolving PCI operation region information. |
| 62 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 63 | acpi_status acpi_get_pci_id(acpi_handle handle, struct acpi_pci_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 65 | int result = 0; |
| 66 | acpi_status status = AE_OK; |
| 67 | struct acpi_device *device = NULL; |
| 68 | struct acpi_pci_data *data = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Rajesh Shah | 4ce448e | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 70 | ACPI_FUNCTION_TRACE("acpi_get_pci_id"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
| 72 | if (!id) |
| 73 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 74 | |
| 75 | result = acpi_bus_get_device(handle, &device); |
| 76 | if (result) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 77 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 78 | "Invalid ACPI Bus context for device %s\n", |
| 79 | acpi_device_bid(device))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | return_ACPI_STATUS(AE_NOT_EXIST); |
| 81 | } |
| 82 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 83 | status = acpi_get_data(handle, acpi_pci_data_handler, (void **)&data); |
Rajesh Shah | 4ce448e | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 84 | if (ACPI_FAILURE(status) || !data) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 85 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 86 | "Invalid ACPI-PCI context for device %s\n", |
| 87 | acpi_device_bid(device))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | return_ACPI_STATUS(status); |
| 89 | } |
| 90 | |
| 91 | *id = data->id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 93 | /* |
| 94 | id->segment = data->id.segment; |
| 95 | id->bus = data->id.bus; |
| 96 | id->device = data->id.device; |
| 97 | id->function = data->id.function; |
| 98 | */ |
| 99 | |
| 100 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 101 | "Device %s has PCI address %02x:%02x:%02x.%02x\n", |
| 102 | acpi_device_bid(device), id->segment, id->bus, |
| 103 | id->device, id->function)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
| 105 | return_ACPI_STATUS(AE_OK); |
| 106 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 107 | |
Rajesh Shah | 4ce448e | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 108 | EXPORT_SYMBOL(acpi_get_pci_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 110 | int acpi_pci_bind(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 112 | int result = 0; |
| 113 | acpi_status status = AE_OK; |
| 114 | struct acpi_pci_data *data = NULL; |
| 115 | struct acpi_pci_data *pdata = NULL; |
| 116 | char *pathname = NULL; |
| 117 | struct acpi_buffer buffer = { 0, NULL }; |
| 118 | acpi_handle handle = NULL; |
| 119 | struct pci_dev *dev; |
| 120 | struct pci_bus *bus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
| 122 | ACPI_FUNCTION_TRACE("acpi_pci_bind"); |
| 123 | |
| 124 | if (!device || !device->parent) |
| 125 | return_VALUE(-EINVAL); |
| 126 | |
| 127 | pathname = kmalloc(ACPI_PATHNAME_MAX, GFP_KERNEL); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 128 | if (!pathname) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | return_VALUE(-ENOMEM); |
| 130 | memset(pathname, 0, ACPI_PATHNAME_MAX); |
| 131 | buffer.length = ACPI_PATHNAME_MAX; |
| 132 | buffer.pointer = pathname; |
| 133 | |
| 134 | data = kmalloc(sizeof(struct acpi_pci_data), GFP_KERNEL); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 135 | if (!data) { |
| 136 | kfree(pathname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | return_VALUE(-ENOMEM); |
| 138 | } |
| 139 | memset(data, 0, sizeof(struct acpi_pci_data)); |
| 140 | |
| 141 | acpi_get_name(device->handle, ACPI_FULL_PATHNAME, &buffer); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 142 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Binding PCI device [%s]...\n", |
| 143 | pathname)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
| 145 | /* |
| 146 | * Segment & Bus |
| 147 | * ------------- |
| 148 | * These are obtained via the parent device's ACPI-PCI context. |
| 149 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 150 | status = acpi_get_data(device->parent->handle, acpi_pci_data_handler, |
| 151 | (void **)&pdata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | if (ACPI_FAILURE(status) || !pdata || !pdata->bus) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 153 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 154 | "Invalid ACPI-PCI context for parent device %s\n", |
| 155 | acpi_device_bid(device->parent))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | result = -ENODEV; |
| 157 | goto end; |
| 158 | } |
| 159 | data->id.segment = pdata->id.segment; |
| 160 | data->id.bus = pdata->bus->number; |
| 161 | |
| 162 | /* |
| 163 | * Device & Function |
| 164 | * ----------------- |
| 165 | * These are simply obtained from the device's _ADR method. Note |
| 166 | * that a value of zero is valid. |
| 167 | */ |
| 168 | data->id.device = device->pnp.bus_address >> 16; |
| 169 | data->id.function = device->pnp.bus_address & 0xFFFF; |
| 170 | |
| 171 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "...to %02x:%02x:%02x.%02x\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 172 | data->id.segment, data->id.bus, data->id.device, |
| 173 | data->id.function)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
| 175 | /* |
| 176 | * TBD: Support slot devices (e.g. function=0xFFFF). |
| 177 | */ |
| 178 | |
| 179 | /* |
| 180 | * Locate PCI Device |
| 181 | * ----------------- |
| 182 | * Locate matching device in PCI namespace. If it doesn't exist |
| 183 | * this typically means that the device isn't currently inserted |
| 184 | * (e.g. docking station, port replicator, etc.). |
Rajesh Shah | c431ada | 2005-04-28 00:25:45 -0700 | [diff] [blame] | 185 | * We cannot simply search the global pci device list, since |
| 186 | * PCI devices are added to the global pci list when the root |
| 187 | * bridge start ops are run, which may not have happened yet. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | */ |
Rajesh Shah | c431ada | 2005-04-28 00:25:45 -0700 | [diff] [blame] | 189 | bus = pci_find_bus(data->id.segment, data->id.bus); |
| 190 | if (bus) { |
| 191 | list_for_each_entry(dev, &bus->devices, bus_list) { |
| 192 | if (dev->devfn == PCI_DEVFN(data->id.device, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 193 | data->id.function)) { |
Rajesh Shah | c431ada | 2005-04-28 00:25:45 -0700 | [diff] [blame] | 194 | data->dev = dev; |
| 195 | break; |
| 196 | } |
| 197 | } |
| 198 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | if (!data->dev) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 200 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 201 | "Device %02x:%02x:%02x.%02x not present in PCI namespace\n", |
| 202 | data->id.segment, data->id.bus, |
| 203 | data->id.device, data->id.function)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | result = -ENODEV; |
| 205 | goto end; |
| 206 | } |
| 207 | if (!data->dev->bus) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 208 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 209 | "Device %02x:%02x:%02x.%02x has invalid 'bus' field\n", |
| 210 | data->id.segment, data->id.bus, |
| 211 | data->id.device, data->id.function)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | result = -ENODEV; |
| 213 | goto end; |
| 214 | } |
| 215 | |
| 216 | /* |
| 217 | * PCI Bridge? |
| 218 | * ----------- |
| 219 | * If so, set the 'bus' field and install the 'bind' function to |
| 220 | * facilitate callbacks for all of its children. |
| 221 | */ |
| 222 | if (data->dev->subordinate) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 223 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 224 | "Device %02x:%02x:%02x.%02x is a PCI bridge\n", |
| 225 | data->id.segment, data->id.bus, |
| 226 | data->id.device, data->id.function)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | data->bus = data->dev->subordinate; |
| 228 | device->ops.bind = acpi_pci_bind; |
| 229 | device->ops.unbind = acpi_pci_unbind; |
| 230 | } |
| 231 | |
| 232 | /* |
| 233 | * Attach ACPI-PCI Context |
| 234 | * ----------------------- |
| 235 | * Thus binding the ACPI and PCI devices. |
| 236 | */ |
| 237 | status = acpi_attach_data(device->handle, acpi_pci_data_handler, data); |
| 238 | if (ACPI_FAILURE(status)) { |
| 239 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 240 | "Unable to attach ACPI-PCI context to device %s\n", |
| 241 | acpi_device_bid(device))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | result = -ENODEV; |
| 243 | goto end; |
| 244 | } |
| 245 | |
| 246 | /* |
| 247 | * PCI Routing Table |
| 248 | * ----------------- |
| 249 | * Evaluate and parse _PRT, if exists. This code is independent of |
| 250 | * PCI bridges (above) to allow parsing of _PRT objects within the |
| 251 | * scope of non-bridge devices. Note that _PRTs within the scope of |
| 252 | * a PCI bridge assume the bridge's subordinate bus number. |
| 253 | * |
| 254 | * TBD: Can _PRTs exist within the scope of non-bridge PCI devices? |
| 255 | */ |
| 256 | status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle); |
| 257 | if (ACPI_SUCCESS(status)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 258 | if (data->bus) /* PCI-PCI bridge */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | acpi_pci_irq_add_prt(device->handle, data->id.segment, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 260 | data->bus->number); |
| 261 | else /* non-bridge PCI device */ |
| 262 | acpi_pci_irq_add_prt(device->handle, data->id.segment, |
| 263 | data->id.bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 266 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | kfree(pathname); |
| 268 | if (result) |
| 269 | kfree(data); |
| 270 | |
| 271 | return_VALUE(result); |
| 272 | } |
| 273 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 274 | int acpi_pci_unbind(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 276 | int result = 0; |
| 277 | acpi_status status = AE_OK; |
| 278 | struct acpi_pci_data *data = NULL; |
| 279 | char *pathname = NULL; |
| 280 | struct acpi_buffer buffer = { 0, NULL }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
| 282 | ACPI_FUNCTION_TRACE("acpi_pci_unbind"); |
| 283 | |
| 284 | if (!device || !device->parent) |
| 285 | return_VALUE(-EINVAL); |
| 286 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 287 | pathname = (char *)kmalloc(ACPI_PATHNAME_MAX, GFP_KERNEL); |
| 288 | if (!pathname) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | return_VALUE(-ENOMEM); |
| 290 | memset(pathname, 0, ACPI_PATHNAME_MAX); |
| 291 | |
| 292 | buffer.length = ACPI_PATHNAME_MAX; |
| 293 | buffer.pointer = pathname; |
| 294 | acpi_get_name(device->handle, ACPI_FULL_PATHNAME, &buffer); |
| 295 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Unbinding PCI device [%s]...\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 296 | pathname)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | kfree(pathname); |
| 298 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 299 | status = |
| 300 | acpi_get_data(device->handle, acpi_pci_data_handler, |
| 301 | (void **)&data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | if (ACPI_FAILURE(status)) { |
| 303 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 304 | "Unable to get data from device %s\n", |
| 305 | acpi_device_bid(device))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | result = -ENODEV; |
| 307 | goto end; |
| 308 | } |
| 309 | |
| 310 | status = acpi_detach_data(device->handle, acpi_pci_data_handler); |
| 311 | if (ACPI_FAILURE(status)) { |
| 312 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 313 | "Unable to detach data from device %s\n", |
| 314 | acpi_device_bid(device))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | result = -ENODEV; |
| 316 | goto end; |
| 317 | } |
| 318 | if (data->dev->subordinate) { |
| 319 | acpi_pci_irq_del_prt(data->id.segment, data->bus->number); |
| 320 | } |
| 321 | kfree(data); |
| 322 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 323 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | return_VALUE(result); |
| 325 | } |
| 326 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 327 | int |
| 328 | acpi_pci_bind_root(struct acpi_device *device, |
| 329 | struct acpi_pci_id *id, struct pci_bus *bus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 331 | int result = 0; |
| 332 | acpi_status status = AE_OK; |
| 333 | struct acpi_pci_data *data = NULL; |
| 334 | char *pathname = NULL; |
| 335 | struct acpi_buffer buffer = { 0, NULL }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
| 337 | ACPI_FUNCTION_TRACE("acpi_pci_bind_root"); |
| 338 | |
| 339 | pathname = (char *)kmalloc(ACPI_PATHNAME_MAX, GFP_KERNEL); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 340 | if (!pathname) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | return_VALUE(-ENOMEM); |
| 342 | memset(pathname, 0, ACPI_PATHNAME_MAX); |
| 343 | |
| 344 | buffer.length = ACPI_PATHNAME_MAX; |
| 345 | buffer.pointer = pathname; |
| 346 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 347 | if (!device || !id || !bus) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | kfree(pathname); |
| 349 | return_VALUE(-EINVAL); |
| 350 | } |
| 351 | |
| 352 | data = kmalloc(sizeof(struct acpi_pci_data), GFP_KERNEL); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 353 | if (!data) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | kfree(pathname); |
| 355 | return_VALUE(-ENOMEM); |
| 356 | } |
| 357 | memset(data, 0, sizeof(struct acpi_pci_data)); |
| 358 | |
| 359 | data->id = *id; |
| 360 | data->bus = bus; |
| 361 | device->ops.bind = acpi_pci_bind; |
| 362 | device->ops.unbind = acpi_pci_unbind; |
| 363 | |
| 364 | acpi_get_name(device->handle, ACPI_FULL_PATHNAME, &buffer); |
| 365 | |
| 366 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Binding PCI root bridge [%s] to " |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 367 | "%02x:%02x\n", pathname, id->segment, id->bus)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
| 369 | status = acpi_attach_data(device->handle, acpi_pci_data_handler, data); |
| 370 | if (ACPI_FAILURE(status)) { |
| 371 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 372 | "Unable to attach ACPI-PCI context to device %s\n", |
| 373 | pathname)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | result = -ENODEV; |
| 375 | goto end; |
| 376 | } |
| 377 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 378 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | kfree(pathname); |
| 380 | if (result != 0) |
| 381 | kfree(data); |
| 382 | |
| 383 | return_VALUE(result); |
| 384 | } |