Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * pci_root.c - ACPI PCI Root Bridge Driver ($Revision: 40 $) |
| 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> |
Andrew Patterson | 990a7ac | 2008-11-10 15:30:45 -0700 | [diff] [blame] | 34 | #include <linux/pci-acpi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/acpi.h> |
| 36 | #include <acpi/acpi_bus.h> |
| 37 | #include <acpi/acpi_drivers.h> |
| 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #define _COMPONENT ACPI_PCI_COMPONENT |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 40 | ACPI_MODULE_NAME("pci_root"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #define ACPI_PCI_ROOT_CLASS "pci_bridge" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #define ACPI_PCI_ROOT_DEVICE_NAME "PCI Root Bridge" |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 43 | static int acpi_pci_root_add(struct acpi_device *device); |
| 44 | static int acpi_pci_root_remove(struct acpi_device *device, int type); |
| 45 | static int acpi_pci_root_start(struct acpi_device *device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 47 | static struct acpi_device_id root_device_ids[] = { |
| 48 | {"PNP0A03", 0}, |
| 49 | {"", 0}, |
| 50 | }; |
| 51 | MODULE_DEVICE_TABLE(acpi, root_device_ids); |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | static struct acpi_driver acpi_pci_root_driver = { |
Len Brown | c2b6705 | 2007-02-12 23:33:40 -0500 | [diff] [blame] | 54 | .name = "pci_root", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 55 | .class = ACPI_PCI_ROOT_CLASS, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 56 | .ids = root_device_ids, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 57 | .ops = { |
| 58 | .add = acpi_pci_root_add, |
| 59 | .remove = acpi_pci_root_remove, |
| 60 | .start = acpi_pci_root_start, |
| 61 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | struct acpi_pci_root { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 65 | struct list_head node; |
Patrick Mochel | 32917e5 | 2006-05-19 16:54:39 -0400 | [diff] [blame] | 66 | struct acpi_device * device; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 67 | struct acpi_pci_id id; |
| 68 | struct pci_bus *bus; |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 69 | |
| 70 | u32 osc_support_set; /* _OSC state of support bits */ |
| 71 | u32 osc_control_set; /* _OSC state of control bits */ |
| 72 | u32 osc_control_qry; /* the latest _OSC query result */ |
| 73 | |
| 74 | u32 osc_queried:1; /* has _OSC control been queried? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | static LIST_HEAD(acpi_pci_roots); |
| 78 | |
| 79 | static struct acpi_pci_driver *sub_driver; |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 80 | static DEFINE_MUTEX(osc_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
| 82 | int acpi_pci_register_driver(struct acpi_pci_driver *driver) |
| 83 | { |
| 84 | int n = 0; |
| 85 | struct list_head *entry; |
| 86 | |
| 87 | struct acpi_pci_driver **pptr = &sub_driver; |
| 88 | while (*pptr) |
| 89 | pptr = &(*pptr)->next; |
| 90 | *pptr = driver; |
| 91 | |
| 92 | if (!driver->add) |
| 93 | return 0; |
| 94 | |
| 95 | list_for_each(entry, &acpi_pci_roots) { |
| 96 | struct acpi_pci_root *root; |
| 97 | root = list_entry(entry, struct acpi_pci_root, node); |
Patrick Mochel | 2d1e0a0 | 2006-05-19 16:54:43 -0400 | [diff] [blame] | 98 | driver->add(root->device->handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | n++; |
| 100 | } |
| 101 | |
| 102 | return n; |
| 103 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | EXPORT_SYMBOL(acpi_pci_register_driver); |
| 106 | |
| 107 | void acpi_pci_unregister_driver(struct acpi_pci_driver *driver) |
| 108 | { |
| 109 | struct list_head *entry; |
| 110 | |
| 111 | struct acpi_pci_driver **pptr = &sub_driver; |
| 112 | while (*pptr) { |
Akinobu Mita | f10bb25 | 2006-12-19 12:56:09 -0800 | [diff] [blame] | 113 | if (*pptr == driver) |
| 114 | break; |
| 115 | pptr = &(*pptr)->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } |
Akinobu Mita | f10bb25 | 2006-12-19 12:56:09 -0800 | [diff] [blame] | 117 | BUG_ON(!*pptr); |
| 118 | *pptr = (*pptr)->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
| 120 | if (!driver->remove) |
| 121 | return; |
| 122 | |
| 123 | list_for_each(entry, &acpi_pci_roots) { |
| 124 | struct acpi_pci_root *root; |
| 125 | root = list_entry(entry, struct acpi_pci_root, node); |
Patrick Mochel | 2d1e0a0 | 2006-05-19 16:54:43 -0400 | [diff] [blame] | 126 | driver->remove(root->device->handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | } |
| 128 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | EXPORT_SYMBOL(acpi_pci_unregister_driver); |
| 131 | |
Justin Chen | d91a007 | 2006-12-06 10:17:10 -0700 | [diff] [blame] | 132 | acpi_handle acpi_get_pci_rootbridge_handle(unsigned int seg, unsigned int bus) |
| 133 | { |
| 134 | struct acpi_pci_root *tmp; |
| 135 | |
| 136 | list_for_each_entry(tmp, &acpi_pci_roots, node) { |
| 137 | if ((tmp->id.segment == (u16) seg) && (tmp->id.bus == (u16) bus)) |
| 138 | return tmp->device->handle; |
| 139 | } |
| 140 | return NULL; |
| 141 | } |
| 142 | |
| 143 | EXPORT_SYMBOL_GPL(acpi_get_pci_rootbridge_handle); |
| 144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 146 | get_root_bridge_busnr_callback(struct acpi_resource *resource, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 148 | int *busnr = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | struct acpi_resource_address64 address; |
| 150 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 151 | if (resource->type != ACPI_RESOURCE_TYPE_ADDRESS16 && |
| 152 | resource->type != ACPI_RESOURCE_TYPE_ADDRESS32 && |
| 153 | resource->type != ACPI_RESOURCE_TYPE_ADDRESS64) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | return AE_OK; |
| 155 | |
| 156 | acpi_resource_to_address64(resource, &address); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 157 | if ((address.address_length > 0) && |
| 158 | (address.resource_type == ACPI_BUS_NUMBER_RANGE)) |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 159 | *busnr = address.minimum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
| 161 | return AE_OK; |
| 162 | } |
| 163 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 164 | static acpi_status try_get_root_bridge_busnr(acpi_handle handle, int *busnum) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | { |
| 166 | acpi_status status; |
| 167 | |
| 168 | *busnum = -1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 169 | status = |
| 170 | acpi_walk_resources(handle, METHOD_NAME__CRS, |
| 171 | get_root_bridge_busnr_callback, busnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | if (ACPI_FAILURE(status)) |
| 173 | return status; |
| 174 | /* Check if we really get a bus number from _CRS */ |
| 175 | if (*busnum == -1) |
| 176 | return AE_ERROR; |
| 177 | return AE_OK; |
| 178 | } |
| 179 | |
Rui Zhang | 2786f6e | 2006-12-21 02:21:13 -0500 | [diff] [blame] | 180 | static void acpi_pci_bridge_scan(struct acpi_device *device) |
| 181 | { |
| 182 | int status; |
| 183 | struct acpi_device *child = NULL; |
| 184 | |
| 185 | if (device->flags.bus_address) |
| 186 | if (device->parent && device->parent->ops.bind) { |
| 187 | status = device->parent->ops.bind(device); |
| 188 | if (!status) { |
| 189 | list_for_each_entry(child, &device->children, node) |
| 190 | acpi_pci_bridge_scan(child); |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 195 | static u8 OSC_UUID[16] = {0x5B, 0x4D, 0xDB, 0x33, 0xF7, 0x1F, 0x1C, 0x40, |
| 196 | 0x96, 0x57, 0x74, 0x41, 0xC0, 0x3D, 0xD7, 0x66}; |
| 197 | |
| 198 | static acpi_status acpi_pci_run_osc(acpi_handle handle, |
| 199 | const u32 *capbuf, u32 *retval) |
| 200 | { |
| 201 | acpi_status status; |
| 202 | struct acpi_object_list input; |
| 203 | union acpi_object in_params[4]; |
| 204 | struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL}; |
| 205 | union acpi_object *out_obj; |
| 206 | u32 errors; |
| 207 | |
| 208 | /* Setting up input parameters */ |
| 209 | input.count = 4; |
| 210 | input.pointer = in_params; |
| 211 | in_params[0].type = ACPI_TYPE_BUFFER; |
| 212 | in_params[0].buffer.length = 16; |
| 213 | in_params[0].buffer.pointer = OSC_UUID; |
| 214 | in_params[1].type = ACPI_TYPE_INTEGER; |
| 215 | in_params[1].integer.value = 1; |
| 216 | in_params[2].type = ACPI_TYPE_INTEGER; |
| 217 | in_params[2].integer.value = 3; |
| 218 | in_params[3].type = ACPI_TYPE_BUFFER; |
| 219 | in_params[3].buffer.length = 12; |
| 220 | in_params[3].buffer.pointer = (u8 *)capbuf; |
| 221 | |
| 222 | status = acpi_evaluate_object(handle, "_OSC", &input, &output); |
| 223 | if (ACPI_FAILURE(status)) |
| 224 | return status; |
| 225 | |
| 226 | if (!output.length) |
| 227 | return AE_NULL_OBJECT; |
| 228 | |
| 229 | out_obj = output.pointer; |
| 230 | if (out_obj->type != ACPI_TYPE_BUFFER) { |
| 231 | printk(KERN_DEBUG "_OSC evaluation returned wrong type\n"); |
| 232 | status = AE_TYPE; |
| 233 | goto out_kfree; |
| 234 | } |
| 235 | /* Need to ignore the bit0 in result code */ |
| 236 | errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0); |
| 237 | if (errors) { |
| 238 | if (errors & OSC_REQUEST_ERROR) |
| 239 | printk(KERN_DEBUG "_OSC request failed\n"); |
| 240 | if (errors & OSC_INVALID_UUID_ERROR) |
| 241 | printk(KERN_DEBUG "_OSC invalid UUID\n"); |
| 242 | if (errors & OSC_INVALID_REVISION_ERROR) |
| 243 | printk(KERN_DEBUG "_OSC invalid revision\n"); |
| 244 | if (errors & OSC_CAPABILITIES_MASK_ERROR) { |
| 245 | if (capbuf[OSC_QUERY_TYPE] & OSC_QUERY_ENABLE) |
| 246 | goto out_success; |
| 247 | printk(KERN_DEBUG |
| 248 | "Firmware did not grant requested _OSC control\n"); |
| 249 | status = AE_SUPPORT; |
| 250 | goto out_kfree; |
| 251 | } |
| 252 | status = AE_ERROR; |
| 253 | goto out_kfree; |
| 254 | } |
| 255 | out_success: |
| 256 | *retval = *((u32 *)(out_obj->buffer.pointer + 8)); |
| 257 | status = AE_OK; |
| 258 | |
| 259 | out_kfree: |
| 260 | kfree(output.pointer); |
| 261 | return status; |
| 262 | } |
| 263 | |
| 264 | static acpi_status acpi_pci_query_osc(struct acpi_pci_root *root, u32 flags) |
| 265 | { |
| 266 | acpi_status status; |
| 267 | u32 support_set, result, capbuf[3]; |
| 268 | |
| 269 | /* do _OSC query for all possible controls */ |
| 270 | support_set = root->osc_support_set | (flags & OSC_SUPPORT_MASKS); |
| 271 | capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE; |
| 272 | capbuf[OSC_SUPPORT_TYPE] = support_set; |
| 273 | capbuf[OSC_CONTROL_TYPE] = OSC_CONTROL_MASKS; |
| 274 | |
| 275 | status = acpi_pci_run_osc(root->device->handle, capbuf, &result); |
| 276 | if (ACPI_SUCCESS(status)) { |
| 277 | root->osc_support_set = support_set; |
| 278 | root->osc_control_qry = result; |
| 279 | root->osc_queried = 1; |
| 280 | } |
| 281 | return status; |
| 282 | } |
| 283 | |
| 284 | static acpi_status acpi_pci_osc_support(struct acpi_pci_root *root, u32 flags) |
| 285 | { |
| 286 | acpi_status status; |
| 287 | acpi_handle tmp; |
| 288 | |
| 289 | status = acpi_get_handle(root->device->handle, "_OSC", &tmp); |
| 290 | if (ACPI_FAILURE(status)) |
| 291 | return status; |
| 292 | mutex_lock(&osc_lock); |
| 293 | status = acpi_pci_query_osc(root, flags); |
| 294 | mutex_unlock(&osc_lock); |
| 295 | return status; |
| 296 | } |
| 297 | |
| 298 | static struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle) |
| 299 | { |
| 300 | struct acpi_pci_root *root; |
| 301 | list_for_each_entry(root, &acpi_pci_roots, node) { |
| 302 | if (root->device->handle == handle) |
| 303 | return root; |
| 304 | } |
| 305 | return NULL; |
| 306 | } |
| 307 | |
| 308 | /** |
Kenji Kaneshige | 9f5404d | 2009-02-09 16:00:04 +0900 | [diff] [blame] | 309 | * acpi_pci_osc_control_set - commit requested control to Firmware |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 310 | * @handle: acpi_handle for the target ACPI object |
| 311 | * @flags: driver's requested control bits |
| 312 | * |
| 313 | * Attempt to take control from Firmware on requested control bits. |
| 314 | **/ |
Kenji Kaneshige | 9f5404d | 2009-02-09 16:00:04 +0900 | [diff] [blame] | 315 | acpi_status acpi_pci_osc_control_set(acpi_handle handle, u32 flags) |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 316 | { |
| 317 | acpi_status status; |
| 318 | u32 control_req, result, capbuf[3]; |
| 319 | acpi_handle tmp; |
| 320 | struct acpi_pci_root *root; |
| 321 | |
| 322 | status = acpi_get_handle(handle, "_OSC", &tmp); |
| 323 | if (ACPI_FAILURE(status)) |
| 324 | return status; |
| 325 | |
| 326 | control_req = (flags & OSC_CONTROL_MASKS); |
| 327 | if (!control_req) |
| 328 | return AE_TYPE; |
| 329 | |
| 330 | root = acpi_pci_find_root(handle); |
| 331 | if (!root) |
| 332 | return AE_NOT_EXIST; |
| 333 | |
| 334 | mutex_lock(&osc_lock); |
| 335 | /* No need to evaluate _OSC if the control was already granted. */ |
| 336 | if ((root->osc_control_set & control_req) == control_req) |
| 337 | goto out; |
| 338 | |
| 339 | /* Need to query controls first before requesting them */ |
| 340 | if (!root->osc_queried) { |
| 341 | status = acpi_pci_query_osc(root, root->osc_support_set); |
| 342 | if (ACPI_FAILURE(status)) |
| 343 | goto out; |
| 344 | } |
| 345 | if ((root->osc_control_qry & control_req) != control_req) { |
| 346 | printk(KERN_DEBUG |
| 347 | "Firmware did not grant requested _OSC control\n"); |
| 348 | status = AE_SUPPORT; |
| 349 | goto out; |
| 350 | } |
| 351 | |
| 352 | capbuf[OSC_QUERY_TYPE] = 0; |
| 353 | capbuf[OSC_SUPPORT_TYPE] = root->osc_support_set; |
| 354 | capbuf[OSC_CONTROL_TYPE] = root->osc_control_set | control_req; |
| 355 | status = acpi_pci_run_osc(handle, capbuf, &result); |
| 356 | if (ACPI_SUCCESS(status)) |
| 357 | root->osc_control_set = result; |
| 358 | out: |
| 359 | mutex_unlock(&osc_lock); |
| 360 | return status; |
| 361 | } |
Kenji Kaneshige | 9f5404d | 2009-02-09 16:00:04 +0900 | [diff] [blame] | 362 | EXPORT_SYMBOL(acpi_pci_osc_control_set); |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 363 | |
Sam Ravnborg | b5678a3 | 2008-02-17 13:23:03 +0100 | [diff] [blame] | 364 | static int __devinit acpi_pci_root_add(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 366 | int result = 0; |
| 367 | struct acpi_pci_root *root = NULL; |
| 368 | struct acpi_pci_root *tmp; |
| 369 | acpi_status status = AE_OK; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 370 | unsigned long long value = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 371 | acpi_handle handle = NULL; |
Rui Zhang | 2786f6e | 2006-12-21 02:21:13 -0500 | [diff] [blame] | 372 | struct acpi_device *child; |
Andrew Patterson | 0ef5f8f | 2008-11-10 15:30:50 -0700 | [diff] [blame] | 373 | u32 flags, base_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | |
| 376 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 377 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
Burman Yan | 36bcbec | 2006-12-19 12:56:11 -0800 | [diff] [blame] | 379 | root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | if (!root) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 381 | return -ENOMEM; |
Rajesh Shah | c431ada | 2005-04-28 00:25:45 -0700 | [diff] [blame] | 382 | INIT_LIST_HEAD(&root->node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
Patrick Mochel | 32917e5 | 2006-05-19 16:54:39 -0400 | [diff] [blame] | 384 | root->device = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME); |
| 386 | strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS); |
Pavel Machek | db89b4f | 2008-09-22 14:37:34 -0700 | [diff] [blame] | 387 | device->driver_data = root; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | device->ops.bind = acpi_pci_bind; |
| 390 | |
Andrew Patterson | 990a7ac | 2008-11-10 15:30:45 -0700 | [diff] [blame] | 391 | /* |
| 392 | * All supported architectures that use ACPI have support for |
| 393 | * PCI domains, so we indicate this in _OSC support capabilities. |
| 394 | */ |
Andrew Patterson | 0ef5f8f | 2008-11-10 15:30:50 -0700 | [diff] [blame] | 395 | flags = base_flags = OSC_PCI_SEGMENT_GROUPS_SUPPORT; |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 396 | acpi_pci_osc_support(root, flags); |
Andrew Patterson | 990a7ac | 2008-11-10 15:30:45 -0700 | [diff] [blame] | 397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | /* |
| 399 | * Segment |
| 400 | * ------- |
| 401 | * Obtained via _SEG, if exists, otherwise assumed to be zero (0). |
| 402 | */ |
Patrick Mochel | 2d1e0a0 | 2006-05-19 16:54:43 -0400 | [diff] [blame] | 403 | status = acpi_evaluate_integer(device->handle, METHOD_NAME__SEG, NULL, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 404 | &value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | switch (status) { |
| 406 | case AE_OK: |
| 407 | root->id.segment = (u16) value; |
| 408 | break; |
| 409 | case AE_NOT_FOUND: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 410 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 411 | "Assuming segment 0 (no _SEG)\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | root->id.segment = 0; |
| 413 | break; |
| 414 | default: |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 415 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _SEG")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | result = -ENODEV; |
| 417 | goto end; |
| 418 | } |
| 419 | |
| 420 | /* |
| 421 | * Bus |
| 422 | * --- |
| 423 | * Obtained via _BBN, if exists, otherwise assumed to be zero (0). |
| 424 | */ |
Patrick Mochel | 2d1e0a0 | 2006-05-19 16:54:43 -0400 | [diff] [blame] | 425 | status = acpi_evaluate_integer(device->handle, METHOD_NAME__BBN, NULL, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 426 | &value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | switch (status) { |
| 428 | case AE_OK: |
| 429 | root->id.bus = (u16) value; |
| 430 | break; |
| 431 | case AE_NOT_FOUND: |
| 432 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Assuming bus 0 (no _BBN)\n")); |
| 433 | root->id.bus = 0; |
| 434 | break; |
| 435 | default: |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 436 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BBN")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | result = -ENODEV; |
| 438 | goto end; |
| 439 | } |
| 440 | |
| 441 | /* Some systems have wrong _BBN */ |
| 442 | list_for_each_entry(tmp, &acpi_pci_roots, node) { |
| 443 | if ((tmp->id.segment == root->id.segment) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 444 | && (tmp->id.bus == root->id.bus)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | int bus = 0; |
| 446 | acpi_status status; |
| 447 | |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 448 | printk(KERN_ERR PREFIX |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 449 | "Wrong _BBN value, reboot" |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 450 | " and use option 'pci=noacpi'\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
Patrick Mochel | 2d1e0a0 | 2006-05-19 16:54:43 -0400 | [diff] [blame] | 452 | status = try_get_root_bridge_busnr(device->handle, &bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | if (ACPI_FAILURE(status)) |
| 454 | break; |
| 455 | if (bus != root->id.bus) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 456 | printk(KERN_INFO PREFIX |
| 457 | "PCI _CRS %d overrides _BBN 0\n", bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | root->id.bus = bus; |
| 459 | } |
| 460 | break; |
| 461 | } |
| 462 | } |
| 463 | /* |
| 464 | * Device & Function |
| 465 | * ----------------- |
| 466 | * Obtained from _ADR (which has already been evaluated for us). |
| 467 | */ |
| 468 | root->id.device = device->pnp.bus_address >> 16; |
| 469 | root->id.function = device->pnp.bus_address & 0xFFFF; |
| 470 | |
| 471 | /* |
| 472 | * TBD: Need PCI interface for enumeration/configuration of roots. |
| 473 | */ |
| 474 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 475 | /* TBD: Locking */ |
| 476 | list_add_tail(&root->node, &acpi_pci_roots); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 478 | printk(KERN_INFO PREFIX "%s [%s] (%04x:%02x)\n", |
| 479 | acpi_device_name(device), acpi_device_bid(device), |
| 480 | root->id.segment, root->id.bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
| 482 | /* |
| 483 | * Scan the Root Bridge |
| 484 | * -------------------- |
| 485 | * Must do this prior to any attempt to bind the root device, as the |
| 486 | * PCI namespace does not get created until this call is made (and |
| 487 | * thus the root bridge's pci_dev does not exist). |
| 488 | */ |
| 489 | root->bus = pci_acpi_scan_root(device, root->id.segment, root->id.bus); |
| 490 | if (!root->bus) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 491 | printk(KERN_ERR PREFIX |
| 492 | "Bus %04x:%02x not present in PCI namespace\n", |
| 493 | root->id.segment, root->id.bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | result = -ENODEV; |
| 495 | goto end; |
| 496 | } |
| 497 | |
| 498 | /* |
| 499 | * Attach ACPI-PCI Context |
| 500 | * ----------------------- |
| 501 | * Thus binding the ACPI and PCI devices. |
| 502 | */ |
| 503 | result = acpi_pci_bind_root(device, &root->id, root->bus); |
| 504 | if (result) |
| 505 | goto end; |
| 506 | |
| 507 | /* |
| 508 | * PCI Routing Table |
| 509 | * ----------------- |
| 510 | * Evaluate and parse _PRT, if exists. |
| 511 | */ |
Patrick Mochel | 2d1e0a0 | 2006-05-19 16:54:43 -0400 | [diff] [blame] | 512 | status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | if (ACPI_SUCCESS(status)) |
Patrick Mochel | 2d1e0a0 | 2006-05-19 16:54:43 -0400 | [diff] [blame] | 514 | result = acpi_pci_irq_add_prt(device->handle, root->id.segment, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 515 | root->id.bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | |
Rui Zhang | 2786f6e | 2006-12-21 02:21:13 -0500 | [diff] [blame] | 517 | /* |
| 518 | * Scan and bind all _ADR-Based Devices |
| 519 | */ |
| 520 | list_for_each_entry(child, &device->children, node) |
| 521 | acpi_pci_bridge_scan(child); |
| 522 | |
Andrew Patterson | 0ef5f8f | 2008-11-10 15:30:50 -0700 | [diff] [blame] | 523 | /* Indicate support for various _OSC capabilities. */ |
| 524 | if (pci_ext_cfg_avail(root->bus->self)) |
| 525 | flags |= OSC_EXT_PCI_CONFIG_SUPPORT; |
Andrew Patterson | 3e1b160 | 2008-11-10 15:30:55 -0700 | [diff] [blame] | 526 | if (pcie_aspm_enabled()) |
| 527 | flags |= OSC_ACTIVE_STATE_PWR_SUPPORT | |
| 528 | OSC_CLOCK_PWR_CAPABILITY_SUPPORT; |
Andrew Patterson | 07ae95f | 2008-11-10 15:31:05 -0700 | [diff] [blame] | 529 | if (pci_msi_enabled()) |
| 530 | flags |= OSC_MSI_SUPPORT; |
Andrew Patterson | 0ef5f8f | 2008-11-10 15:30:50 -0700 | [diff] [blame] | 531 | if (flags != base_flags) |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 532 | acpi_pci_osc_support(root, flags); |
Andrew Patterson | 0ef5f8f | 2008-11-10 15:30:50 -0700 | [diff] [blame] | 533 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 534 | end: |
Rajesh Shah | c431ada | 2005-04-28 00:25:45 -0700 | [diff] [blame] | 535 | if (result) { |
| 536 | if (!list_empty(&root->node)) |
| 537 | list_del(&root->node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | kfree(root); |
Rajesh Shah | c431ada | 2005-04-28 00:25:45 -0700 | [diff] [blame] | 539 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 541 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 544 | static int acpi_pci_root_start(struct acpi_device *device) |
Rajesh Shah | c431ada | 2005-04-28 00:25:45 -0700 | [diff] [blame] | 545 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 546 | struct acpi_pci_root *root; |
Rajesh Shah | c431ada | 2005-04-28 00:25:45 -0700 | [diff] [blame] | 547 | |
Rajesh Shah | c431ada | 2005-04-28 00:25:45 -0700 | [diff] [blame] | 548 | |
| 549 | list_for_each_entry(root, &acpi_pci_roots, node) { |
Patrick Mochel | 432bfab | 2006-05-19 16:54:51 -0400 | [diff] [blame] | 550 | if (root->device == device) { |
Rajesh Shah | c431ada | 2005-04-28 00:25:45 -0700 | [diff] [blame] | 551 | pci_bus_add_devices(root->bus); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 552 | return 0; |
Rajesh Shah | c431ada | 2005-04-28 00:25:45 -0700 | [diff] [blame] | 553 | } |
| 554 | } |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 555 | return -ENODEV; |
Rajesh Shah | c431ada | 2005-04-28 00:25:45 -0700 | [diff] [blame] | 556 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 558 | static int acpi_pci_root_remove(struct acpi_device *device, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 560 | struct acpi_pci_root *root = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | |
| 563 | if (!device || !acpi_driver_data(device)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 564 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 566 | root = acpi_driver_data(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
| 568 | kfree(root); |
| 569 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 570 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 573 | static int __init acpi_pci_root_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | if (acpi_pci_disabled) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 576 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | if (acpi_bus_register_driver(&acpi_pci_root_driver) < 0) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 579 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 581 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | subsys_initcall(acpi_pci_root_init); |