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