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