blob: 7984e00540fa0ec23dd900f96da3170d7ed5498e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Patterson990a7ac2008-11-10 15:30:45 -070034#include <linux/pci-acpi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/acpi.h>
36#include <acpi/acpi_bus.h>
37#include <acpi/acpi_drivers.h>
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#define _COMPONENT ACPI_PCI_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050040ACPI_MODULE_NAME("pci_root");
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#define ACPI_PCI_ROOT_CLASS "pci_bridge"
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#define ACPI_PCI_ROOT_DEVICE_NAME "PCI Root Bridge"
Len Brown4be44fc2005-08-05 00:44:28 -040043static int acpi_pci_root_add(struct acpi_device *device);
44static int acpi_pci_root_remove(struct acpi_device *device, int type);
45static int acpi_pci_root_start(struct acpi_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Thomas Renninger1ba90e32007-07-23 14:44:41 +020047static struct acpi_device_id root_device_ids[] = {
48 {"PNP0A03", 0},
49 {"", 0},
50};
51MODULE_DEVICE_TABLE(acpi, root_device_ids);
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053static struct acpi_driver acpi_pci_root_driver = {
Len Brownc2b67052007-02-12 23:33:40 -050054 .name = "pci_root",
Len Brown4be44fc2005-08-05 00:44:28 -040055 .class = ACPI_PCI_ROOT_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +020056 .ids = root_device_ids,
Len Brown4be44fc2005-08-05 00:44:28 -040057 .ops = {
58 .add = acpi_pci_root_add,
59 .remove = acpi_pci_root_remove,
60 .start = acpi_pci_root_start,
61 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070062};
63
64struct acpi_pci_root {
Len Brown4be44fc2005-08-05 00:44:28 -040065 struct list_head node;
Patrick Mochel32917e52006-05-19 16:54:39 -040066 struct acpi_device * device;
Len Brown4be44fc2005-08-05 00:44:28 -040067 struct acpi_pci_id id;
68 struct pci_bus *bus;
Kenji Kaneshige63f10f02009-02-09 15:59:29 +090069
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 Torvalds1da177e2005-04-16 15:20:36 -070075};
76
77static LIST_HEAD(acpi_pci_roots);
78
79static struct acpi_pci_driver *sub_driver;
Kenji Kaneshige63f10f02009-02-09 15:59:29 +090080static DEFINE_MUTEX(osc_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82int 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 Mochel2d1e0a02006-05-19 16:54:43 -040098 driver->add(root->device->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 n++;
100 }
101
102 return n;
103}
Len Brown4be44fc2005-08-05 00:44:28 -0400104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105EXPORT_SYMBOL(acpi_pci_register_driver);
106
107void 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 Mitaf10bb252006-12-19 12:56:09 -0800113 if (*pptr == driver)
114 break;
115 pptr = &(*pptr)->next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 }
Akinobu Mitaf10bb252006-12-19 12:56:09 -0800117 BUG_ON(!*pptr);
118 *pptr = (*pptr)->next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
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 Mochel2d1e0a02006-05-19 16:54:43 -0400126 driver->remove(root->device->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 }
128}
Len Brown4be44fc2005-08-05 00:44:28 -0400129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130EXPORT_SYMBOL(acpi_pci_unregister_driver);
131
Justin Chend91a0072006-12-06 10:17:10 -0700132acpi_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
143EXPORT_SYMBOL_GPL(acpi_get_pci_rootbridge_handle);
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400146get_root_bridge_busnr_callback(struct acpi_resource *resource, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200148 int *busnr = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 struct acpi_resource_address64 address;
150
Bob Moore50eca3e2005-09-30 19:03:00 -0400151 if (resource->type != ACPI_RESOURCE_TYPE_ADDRESS16 &&
152 resource->type != ACPI_RESOURCE_TYPE_ADDRESS32 &&
153 resource->type != ACPI_RESOURCE_TYPE_ADDRESS64)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 return AE_OK;
155
156 acpi_resource_to_address64(resource, &address);
Len Brown4be44fc2005-08-05 00:44:28 -0400157 if ((address.address_length > 0) &&
158 (address.resource_type == ACPI_BUS_NUMBER_RANGE))
Bob Moore50eca3e2005-09-30 19:03:00 -0400159 *busnr = address.minimum;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
161 return AE_OK;
162}
163
Bjorn Helgaasf5eebbe2009-06-18 14:46:52 -0600164static acpi_status try_get_root_bridge_busnr(acpi_handle handle,
165 unsigned long long *bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166{
167 acpi_status status;
Bjorn Helgaasf5eebbe2009-06-18 14:46:52 -0600168 int busnum;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
Bjorn Helgaasf5eebbe2009-06-18 14:46:52 -0600170 busnum = -1;
Len Brown4be44fc2005-08-05 00:44:28 -0400171 status =
172 acpi_walk_resources(handle, METHOD_NAME__CRS,
Bjorn Helgaasf5eebbe2009-06-18 14:46:52 -0600173 get_root_bridge_busnr_callback, &busnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 if (ACPI_FAILURE(status))
175 return status;
176 /* Check if we really get a bus number from _CRS */
Bjorn Helgaasf5eebbe2009-06-18 14:46:52 -0600177 if (busnum == -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 return AE_ERROR;
Bjorn Helgaasf5eebbe2009-06-18 14:46:52 -0600179 *bus = busnum;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 return AE_OK;
181}
182
Rui Zhang2786f6e2006-12-21 02:21:13 -0500183static void acpi_pci_bridge_scan(struct acpi_device *device)
184{
185 int status;
186 struct acpi_device *child = NULL;
187
188 if (device->flags.bus_address)
189 if (device->parent && device->parent->ops.bind) {
190 status = device->parent->ops.bind(device);
191 if (!status) {
192 list_for_each_entry(child, &device->children, node)
193 acpi_pci_bridge_scan(child);
194 }
195 }
196}
197
Kenji Kaneshige63f10f02009-02-09 15:59:29 +0900198static u8 OSC_UUID[16] = {0x5B, 0x4D, 0xDB, 0x33, 0xF7, 0x1F, 0x1C, 0x40,
199 0x96, 0x57, 0x74, 0x41, 0xC0, 0x3D, 0xD7, 0x66};
200
201static acpi_status acpi_pci_run_osc(acpi_handle handle,
202 const u32 *capbuf, u32 *retval)
203{
204 acpi_status status;
205 struct acpi_object_list input;
206 union acpi_object in_params[4];
207 struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
208 union acpi_object *out_obj;
209 u32 errors;
210
211 /* Setting up input parameters */
212 input.count = 4;
213 input.pointer = in_params;
214 in_params[0].type = ACPI_TYPE_BUFFER;
215 in_params[0].buffer.length = 16;
216 in_params[0].buffer.pointer = OSC_UUID;
217 in_params[1].type = ACPI_TYPE_INTEGER;
218 in_params[1].integer.value = 1;
219 in_params[2].type = ACPI_TYPE_INTEGER;
220 in_params[2].integer.value = 3;
221 in_params[3].type = ACPI_TYPE_BUFFER;
222 in_params[3].buffer.length = 12;
223 in_params[3].buffer.pointer = (u8 *)capbuf;
224
225 status = acpi_evaluate_object(handle, "_OSC", &input, &output);
226 if (ACPI_FAILURE(status))
227 return status;
228
229 if (!output.length)
230 return AE_NULL_OBJECT;
231
232 out_obj = output.pointer;
233 if (out_obj->type != ACPI_TYPE_BUFFER) {
234 printk(KERN_DEBUG "_OSC evaluation returned wrong type\n");
235 status = AE_TYPE;
236 goto out_kfree;
237 }
238 /* Need to ignore the bit0 in result code */
239 errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0);
240 if (errors) {
241 if (errors & OSC_REQUEST_ERROR)
242 printk(KERN_DEBUG "_OSC request failed\n");
243 if (errors & OSC_INVALID_UUID_ERROR)
244 printk(KERN_DEBUG "_OSC invalid UUID\n");
245 if (errors & OSC_INVALID_REVISION_ERROR)
246 printk(KERN_DEBUG "_OSC invalid revision\n");
247 if (errors & OSC_CAPABILITIES_MASK_ERROR) {
248 if (capbuf[OSC_QUERY_TYPE] & OSC_QUERY_ENABLE)
249 goto out_success;
250 printk(KERN_DEBUG
251 "Firmware did not grant requested _OSC control\n");
252 status = AE_SUPPORT;
253 goto out_kfree;
254 }
255 status = AE_ERROR;
256 goto out_kfree;
257 }
258out_success:
259 *retval = *((u32 *)(out_obj->buffer.pointer + 8));
260 status = AE_OK;
261
262out_kfree:
263 kfree(output.pointer);
264 return status;
265}
266
267static acpi_status acpi_pci_query_osc(struct acpi_pci_root *root, u32 flags)
268{
269 acpi_status status;
270 u32 support_set, result, capbuf[3];
271
272 /* do _OSC query for all possible controls */
273 support_set = root->osc_support_set | (flags & OSC_SUPPORT_MASKS);
274 capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
275 capbuf[OSC_SUPPORT_TYPE] = support_set;
276 capbuf[OSC_CONTROL_TYPE] = OSC_CONTROL_MASKS;
277
278 status = acpi_pci_run_osc(root->device->handle, capbuf, &result);
279 if (ACPI_SUCCESS(status)) {
280 root->osc_support_set = support_set;
281 root->osc_control_qry = result;
282 root->osc_queried = 1;
283 }
284 return status;
285}
286
287static acpi_status acpi_pci_osc_support(struct acpi_pci_root *root, u32 flags)
288{
289 acpi_status status;
290 acpi_handle tmp;
291
292 status = acpi_get_handle(root->device->handle, "_OSC", &tmp);
293 if (ACPI_FAILURE(status))
294 return status;
295 mutex_lock(&osc_lock);
296 status = acpi_pci_query_osc(root, flags);
297 mutex_unlock(&osc_lock);
298 return status;
299}
300
301static struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle)
302{
303 struct acpi_pci_root *root;
304 list_for_each_entry(root, &acpi_pci_roots, node) {
305 if (root->device->handle == handle)
306 return root;
307 }
308 return NULL;
309}
310
311/**
Kenji Kaneshige9f5404d2009-02-09 16:00:04 +0900312 * acpi_pci_osc_control_set - commit requested control to Firmware
Kenji Kaneshige63f10f02009-02-09 15:59:29 +0900313 * @handle: acpi_handle for the target ACPI object
314 * @flags: driver's requested control bits
315 *
316 * Attempt to take control from Firmware on requested control bits.
317 **/
Kenji Kaneshige9f5404d2009-02-09 16:00:04 +0900318acpi_status acpi_pci_osc_control_set(acpi_handle handle, u32 flags)
Kenji Kaneshige63f10f02009-02-09 15:59:29 +0900319{
320 acpi_status status;
321 u32 control_req, result, capbuf[3];
322 acpi_handle tmp;
323 struct acpi_pci_root *root;
324
325 status = acpi_get_handle(handle, "_OSC", &tmp);
326 if (ACPI_FAILURE(status))
327 return status;
328
329 control_req = (flags & OSC_CONTROL_MASKS);
330 if (!control_req)
331 return AE_TYPE;
332
333 root = acpi_pci_find_root(handle);
334 if (!root)
335 return AE_NOT_EXIST;
336
337 mutex_lock(&osc_lock);
338 /* No need to evaluate _OSC if the control was already granted. */
339 if ((root->osc_control_set & control_req) == control_req)
340 goto out;
341
342 /* Need to query controls first before requesting them */
343 if (!root->osc_queried) {
344 status = acpi_pci_query_osc(root, root->osc_support_set);
345 if (ACPI_FAILURE(status))
346 goto out;
347 }
348 if ((root->osc_control_qry & control_req) != control_req) {
349 printk(KERN_DEBUG
350 "Firmware did not grant requested _OSC control\n");
351 status = AE_SUPPORT;
352 goto out;
353 }
354
355 capbuf[OSC_QUERY_TYPE] = 0;
356 capbuf[OSC_SUPPORT_TYPE] = root->osc_support_set;
357 capbuf[OSC_CONTROL_TYPE] = root->osc_control_set | control_req;
358 status = acpi_pci_run_osc(handle, capbuf, &result);
359 if (ACPI_SUCCESS(status))
360 root->osc_control_set = result;
361out:
362 mutex_unlock(&osc_lock);
363 return status;
364}
Kenji Kaneshige9f5404d2009-02-09 16:00:04 +0900365EXPORT_SYMBOL(acpi_pci_osc_control_set);
Kenji Kaneshige63f10f02009-02-09 15:59:29 +0900366
Sam Ravnborgb5678a32008-02-17 13:23:03 +0100367static int __devinit acpi_pci_root_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368{
Bjorn Helgaasf5eebbe2009-06-18 14:46:52 -0600369 unsigned long long segment, bus;
370 acpi_status status;
371 int result;
372 struct acpi_pci_root *root;
373 acpi_handle handle;
Rui Zhang2786f6e2006-12-21 02:21:13 -0500374 struct acpi_device *child;
Andrew Patterson0ef5f8f2008-11-10 15:30:50 -0700375 u32 flags, base_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Bjorn Helgaasf5eebbe2009-06-18 14:46:52 -0600377 segment = 0;
378 status = acpi_evaluate_integer(device->handle, METHOD_NAME__SEG, NULL,
379 &segment);
380 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
381 printk(KERN_ERR PREFIX "can't evaluate _SEG\n");
382 return -ENODEV;
383 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
Bjorn Helgaasf5eebbe2009-06-18 14:46:52 -0600385 /* Check _CRS first, then _BBN. If no _BBN, default to zero. */
386 bus = 0;
387 status = try_get_root_bridge_busnr(device->handle, &bus);
388 if (ACPI_FAILURE(status)) {
389 status = acpi_evaluate_integer(device->handle, METHOD_NAME__BBN, NULL, &bus);
390 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
391 printk(KERN_ERR PREFIX
392 "no bus number in _CRS and can't evaluate _BBN\n");
393 return -ENODEV;
394 }
395 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Burman Yan36bcbec2006-12-19 12:56:11 -0800397 root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 if (!root)
Patrick Mocheld550d982006-06-27 00:41:40 -0400399 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
Bjorn Helgaasf5eebbe2009-06-18 14:46:52 -0600401 INIT_LIST_HEAD(&root->node);
Patrick Mochel32917e52006-05-19 16:54:39 -0400402 root->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME);
404 strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -0700405 device->driver_data = root;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 device->ops.bind = acpi_pci_bind;
408
Andrew Patterson990a7ac2008-11-10 15:30:45 -0700409 /*
410 * All supported architectures that use ACPI have support for
411 * PCI domains, so we indicate this in _OSC support capabilities.
412 */
Andrew Patterson0ef5f8f2008-11-10 15:30:50 -0700413 flags = base_flags = OSC_PCI_SEGMENT_GROUPS_SUPPORT;
Kenji Kaneshige63f10f02009-02-09 15:59:29 +0900414 acpi_pci_osc_support(root, flags);
Andrew Patterson990a7ac2008-11-10 15:30:45 -0700415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 /*
417 * Device & Function
418 * -----------------
419 * Obtained from _ADR (which has already been evaluated for us).
420 */
Bjorn Helgaasf5eebbe2009-06-18 14:46:52 -0600421 root->id.segment = segment & 0xFFFF;
422 root->id.bus = bus & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 root->id.device = device->pnp.bus_address >> 16;
424 root->id.function = device->pnp.bus_address & 0xFFFF;
425
426 /*
427 * TBD: Need PCI interface for enumeration/configuration of roots.
428 */
429
Len Brown4be44fc2005-08-05 00:44:28 -0400430 /* TBD: Locking */
431 list_add_tail(&root->node, &acpi_pci_roots);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
Len Brown4be44fc2005-08-05 00:44:28 -0400433 printk(KERN_INFO PREFIX "%s [%s] (%04x:%02x)\n",
434 acpi_device_name(device), acpi_device_bid(device),
435 root->id.segment, root->id.bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
437 /*
438 * Scan the Root Bridge
439 * --------------------
440 * Must do this prior to any attempt to bind the root device, as the
441 * PCI namespace does not get created until this call is made (and
442 * thus the root bridge's pci_dev does not exist).
443 */
444 root->bus = pci_acpi_scan_root(device, root->id.segment, root->id.bus);
445 if (!root->bus) {
Len Brown64684632006-06-26 23:41:38 -0400446 printk(KERN_ERR PREFIX
447 "Bus %04x:%02x not present in PCI namespace\n",
448 root->id.segment, root->id.bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 result = -ENODEV;
450 goto end;
451 }
452
453 /*
454 * Attach ACPI-PCI Context
455 * -----------------------
456 * Thus binding the ACPI and PCI devices.
457 */
458 result = acpi_pci_bind_root(device, &root->id, root->bus);
459 if (result)
460 goto end;
461
462 /*
463 * PCI Routing Table
464 * -----------------
465 * Evaluate and parse _PRT, if exists.
466 */
Patrick Mochel2d1e0a02006-05-19 16:54:43 -0400467 status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 if (ACPI_SUCCESS(status))
Patrick Mochel2d1e0a02006-05-19 16:54:43 -0400469 result = acpi_pci_irq_add_prt(device->handle, root->id.segment,
Len Brown4be44fc2005-08-05 00:44:28 -0400470 root->id.bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471
Rui Zhang2786f6e2006-12-21 02:21:13 -0500472 /*
473 * Scan and bind all _ADR-Based Devices
474 */
475 list_for_each_entry(child, &device->children, node)
476 acpi_pci_bridge_scan(child);
477
Andrew Patterson0ef5f8f2008-11-10 15:30:50 -0700478 /* Indicate support for various _OSC capabilities. */
479 if (pci_ext_cfg_avail(root->bus->self))
480 flags |= OSC_EXT_PCI_CONFIG_SUPPORT;
Andrew Patterson3e1b1602008-11-10 15:30:55 -0700481 if (pcie_aspm_enabled())
482 flags |= OSC_ACTIVE_STATE_PWR_SUPPORT |
483 OSC_CLOCK_PWR_CAPABILITY_SUPPORT;
Andrew Patterson07ae95f2008-11-10 15:31:05 -0700484 if (pci_msi_enabled())
485 flags |= OSC_MSI_SUPPORT;
Andrew Patterson0ef5f8f2008-11-10 15:30:50 -0700486 if (flags != base_flags)
Kenji Kaneshige63f10f02009-02-09 15:59:29 +0900487 acpi_pci_osc_support(root, flags);
Andrew Patterson0ef5f8f2008-11-10 15:30:50 -0700488
Bjorn Helgaasf5eebbe2009-06-18 14:46:52 -0600489 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Bjorn Helgaasf5eebbe2009-06-18 14:46:52 -0600491end:
492 if (!list_empty(&root->node))
493 list_del(&root->node);
494 kfree(root);
Patrick Mocheld550d982006-06-27 00:41:40 -0400495 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496}
497
Len Brown4be44fc2005-08-05 00:44:28 -0400498static int acpi_pci_root_start(struct acpi_device *device)
Rajesh Shahc431ada2005-04-28 00:25:45 -0700499{
Bjorn Helgaascaf420c2009-06-18 14:46:57 -0600500 struct acpi_pci_root *root = acpi_driver_data(device);
Rajesh Shahc431ada2005-04-28 00:25:45 -0700501
Bjorn Helgaascaf420c2009-06-18 14:46:57 -0600502 pci_bus_add_devices(root->bus);
503 return 0;
Rajesh Shahc431ada2005-04-28 00:25:45 -0700504}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
Len Brown4be44fc2005-08-05 00:44:28 -0400506static int acpi_pci_root_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507{
Bjorn Helgaascaf420c2009-06-18 14:46:57 -0600508 struct acpi_pci_root *root = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
510 kfree(root);
Patrick Mocheld550d982006-06-27 00:41:40 -0400511 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512}
513
Len Brown4be44fc2005-08-05 00:44:28 -0400514static int __init acpi_pci_root_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 if (acpi_pci_disabled)
Patrick Mocheld550d982006-06-27 00:41:40 -0400517 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 if (acpi_bus_register_driver(&acpi_pci_root_driver) < 0)
Patrick Mocheld550d982006-06-27 00:41:40 -0400520 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
Patrick Mocheld550d982006-06-27 00:41:40 -0400522 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523}
524
525subsys_initcall(acpi_pci_root_init);