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