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