blob: 888cb9f5c5fbf563354af0f89a75da6af8f0202c [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 Brownc2b6705b2007-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
Alexander Chiang27558202009-06-10 19:55:14 +0000145/**
146 * acpi_is_root_bridge - determine whether an ACPI CA node is a PCI root bridge
147 * @handle - the ACPI CA node in question.
148 *
149 * Note: we could make this API take a struct acpi_device * instead, but
150 * for now, it's more convenient to operate on an acpi_handle.
151 */
152int acpi_is_root_bridge(acpi_handle handle)
153{
154 int ret;
155 struct acpi_device *device;
156
157 ret = acpi_bus_get_device(handle, &device);
158 if (ret)
159 return 0;
160
161 ret = acpi_match_device_ids(device, root_device_ids);
162 if (ret)
163 return 0;
164 else
165 return 1;
166}
167EXPORT_SYMBOL_GPL(acpi_is_root_bridge);
168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400170get_root_bridge_busnr_callback(struct acpi_resource *resource, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200172 int *busnr = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 struct acpi_resource_address64 address;
174
Bob Moore50eca3e2005-09-30 19:03:00 -0400175 if (resource->type != ACPI_RESOURCE_TYPE_ADDRESS16 &&
176 resource->type != ACPI_RESOURCE_TYPE_ADDRESS32 &&
177 resource->type != ACPI_RESOURCE_TYPE_ADDRESS64)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 return AE_OK;
179
180 acpi_resource_to_address64(resource, &address);
Len Brown4be44fc2005-08-05 00:44:28 -0400181 if ((address.address_length > 0) &&
182 (address.resource_type == ACPI_BUS_NUMBER_RANGE))
Bob Moore50eca3e2005-09-30 19:03:00 -0400183 *busnr = address.minimum;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185 return AE_OK;
186}
187
Len Brown4be44fc2005-08-05 00:44:28 -0400188static acpi_status try_get_root_bridge_busnr(acpi_handle handle, int *busnum)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189{
190 acpi_status status;
191
192 *busnum = -1;
Len Brown4be44fc2005-08-05 00:44:28 -0400193 status =
194 acpi_walk_resources(handle, METHOD_NAME__CRS,
195 get_root_bridge_busnr_callback, busnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 if (ACPI_FAILURE(status))
197 return status;
198 /* Check if we really get a bus number from _CRS */
199 if (*busnum == -1)
200 return AE_ERROR;
201 return AE_OK;
202}
203
Rui Zhang2786f6e2006-12-21 02:21:13 -0500204static void acpi_pci_bridge_scan(struct acpi_device *device)
205{
206 int status;
207 struct acpi_device *child = NULL;
208
209 if (device->flags.bus_address)
210 if (device->parent && device->parent->ops.bind) {
211 status = device->parent->ops.bind(device);
212 if (!status) {
213 list_for_each_entry(child, &device->children, node)
214 acpi_pci_bridge_scan(child);
215 }
216 }
217}
218
Kenji Kaneshige63f10f02009-02-09 15:59:29 +0900219static u8 OSC_UUID[16] = {0x5B, 0x4D, 0xDB, 0x33, 0xF7, 0x1F, 0x1C, 0x40,
220 0x96, 0x57, 0x74, 0x41, 0xC0, 0x3D, 0xD7, 0x66};
221
222static acpi_status acpi_pci_run_osc(acpi_handle handle,
223 const u32 *capbuf, u32 *retval)
224{
225 acpi_status status;
226 struct acpi_object_list input;
227 union acpi_object in_params[4];
228 struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
229 union acpi_object *out_obj;
230 u32 errors;
231
232 /* Setting up input parameters */
233 input.count = 4;
234 input.pointer = in_params;
235 in_params[0].type = ACPI_TYPE_BUFFER;
236 in_params[0].buffer.length = 16;
237 in_params[0].buffer.pointer = OSC_UUID;
238 in_params[1].type = ACPI_TYPE_INTEGER;
239 in_params[1].integer.value = 1;
240 in_params[2].type = ACPI_TYPE_INTEGER;
241 in_params[2].integer.value = 3;
242 in_params[3].type = ACPI_TYPE_BUFFER;
243 in_params[3].buffer.length = 12;
244 in_params[3].buffer.pointer = (u8 *)capbuf;
245
246 status = acpi_evaluate_object(handle, "_OSC", &input, &output);
247 if (ACPI_FAILURE(status))
248 return status;
249
250 if (!output.length)
251 return AE_NULL_OBJECT;
252
253 out_obj = output.pointer;
254 if (out_obj->type != ACPI_TYPE_BUFFER) {
255 printk(KERN_DEBUG "_OSC evaluation returned wrong type\n");
256 status = AE_TYPE;
257 goto out_kfree;
258 }
259 /* Need to ignore the bit0 in result code */
260 errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0);
261 if (errors) {
262 if (errors & OSC_REQUEST_ERROR)
263 printk(KERN_DEBUG "_OSC request failed\n");
264 if (errors & OSC_INVALID_UUID_ERROR)
265 printk(KERN_DEBUG "_OSC invalid UUID\n");
266 if (errors & OSC_INVALID_REVISION_ERROR)
267 printk(KERN_DEBUG "_OSC invalid revision\n");
268 if (errors & OSC_CAPABILITIES_MASK_ERROR) {
269 if (capbuf[OSC_QUERY_TYPE] & OSC_QUERY_ENABLE)
270 goto out_success;
271 printk(KERN_DEBUG
272 "Firmware did not grant requested _OSC control\n");
273 status = AE_SUPPORT;
274 goto out_kfree;
275 }
276 status = AE_ERROR;
277 goto out_kfree;
278 }
279out_success:
280 *retval = *((u32 *)(out_obj->buffer.pointer + 8));
281 status = AE_OK;
282
283out_kfree:
284 kfree(output.pointer);
285 return status;
286}
287
288static acpi_status acpi_pci_query_osc(struct acpi_pci_root *root, u32 flags)
289{
290 acpi_status status;
291 u32 support_set, result, capbuf[3];
292
293 /* do _OSC query for all possible controls */
294 support_set = root->osc_support_set | (flags & OSC_SUPPORT_MASKS);
295 capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
296 capbuf[OSC_SUPPORT_TYPE] = support_set;
297 capbuf[OSC_CONTROL_TYPE] = OSC_CONTROL_MASKS;
298
299 status = acpi_pci_run_osc(root->device->handle, capbuf, &result);
300 if (ACPI_SUCCESS(status)) {
301 root->osc_support_set = support_set;
302 root->osc_control_qry = result;
303 root->osc_queried = 1;
304 }
305 return status;
306}
307
308static acpi_status acpi_pci_osc_support(struct acpi_pci_root *root, u32 flags)
309{
310 acpi_status status;
311 acpi_handle tmp;
312
313 status = acpi_get_handle(root->device->handle, "_OSC", &tmp);
314 if (ACPI_FAILURE(status))
315 return status;
316 mutex_lock(&osc_lock);
317 status = acpi_pci_query_osc(root, flags);
318 mutex_unlock(&osc_lock);
319 return status;
320}
321
322static struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle)
323{
324 struct acpi_pci_root *root;
325 list_for_each_entry(root, &acpi_pci_roots, node) {
326 if (root->device->handle == handle)
327 return root;
328 }
329 return NULL;
330}
331
332/**
Kenji Kaneshige9f5404d2009-02-09 16:00:04 +0900333 * acpi_pci_osc_control_set - commit requested control to Firmware
Kenji Kaneshige63f10f02009-02-09 15:59:29 +0900334 * @handle: acpi_handle for the target ACPI object
335 * @flags: driver's requested control bits
336 *
337 * Attempt to take control from Firmware on requested control bits.
338 **/
Kenji Kaneshige9f5404d2009-02-09 16:00:04 +0900339acpi_status acpi_pci_osc_control_set(acpi_handle handle, u32 flags)
Kenji Kaneshige63f10f02009-02-09 15:59:29 +0900340{
341 acpi_status status;
342 u32 control_req, result, capbuf[3];
343 acpi_handle tmp;
344 struct acpi_pci_root *root;
345
346 status = acpi_get_handle(handle, "_OSC", &tmp);
347 if (ACPI_FAILURE(status))
348 return status;
349
350 control_req = (flags & OSC_CONTROL_MASKS);
351 if (!control_req)
352 return AE_TYPE;
353
354 root = acpi_pci_find_root(handle);
355 if (!root)
356 return AE_NOT_EXIST;
357
358 mutex_lock(&osc_lock);
359 /* No need to evaluate _OSC if the control was already granted. */
360 if ((root->osc_control_set & control_req) == control_req)
361 goto out;
362
363 /* Need to query controls first before requesting them */
364 if (!root->osc_queried) {
365 status = acpi_pci_query_osc(root, root->osc_support_set);
366 if (ACPI_FAILURE(status))
367 goto out;
368 }
369 if ((root->osc_control_qry & control_req) != control_req) {
370 printk(KERN_DEBUG
371 "Firmware did not grant requested _OSC control\n");
372 status = AE_SUPPORT;
373 goto out;
374 }
375
376 capbuf[OSC_QUERY_TYPE] = 0;
377 capbuf[OSC_SUPPORT_TYPE] = root->osc_support_set;
378 capbuf[OSC_CONTROL_TYPE] = root->osc_control_set | control_req;
379 status = acpi_pci_run_osc(handle, capbuf, &result);
380 if (ACPI_SUCCESS(status))
381 root->osc_control_set = result;
382out:
383 mutex_unlock(&osc_lock);
384 return status;
385}
Kenji Kaneshige9f5404d2009-02-09 16:00:04 +0900386EXPORT_SYMBOL(acpi_pci_osc_control_set);
Kenji Kaneshige63f10f02009-02-09 15:59:29 +0900387
Sam Ravnborgb5678a32008-02-17 13:23:03 +0100388static int __devinit acpi_pci_root_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389{
Len Brown4be44fc2005-08-05 00:44:28 -0400390 int result = 0;
391 struct acpi_pci_root *root = NULL;
392 struct acpi_pci_root *tmp;
393 acpi_status status = AE_OK;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400394 unsigned long long value = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400395 acpi_handle handle = NULL;
Rui Zhang2786f6e2006-12-21 02:21:13 -0500396 struct acpi_device *child;
Andrew Patterson0ef5f8f2008-11-10 15:30:50 -0700397 u32 flags, base_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
400 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400401 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Burman Yan36bcbec2006-12-19 12:56:11 -0800403 root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 if (!root)
Patrick Mocheld550d982006-06-27 00:41:40 -0400405 return -ENOMEM;
Rajesh Shahc431ada2005-04-28 00:25:45 -0700406 INIT_LIST_HEAD(&root->node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Patrick Mochel32917e52006-05-19 16:54:39 -0400408 root->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME);
410 strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -0700411 device->driver_data = root;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
Andrew Patterson990a7ac2008-11-10 15:30:45 -0700413 /*
414 * All supported architectures that use ACPI have support for
415 * PCI domains, so we indicate this in _OSC support capabilities.
416 */
Andrew Patterson0ef5f8f2008-11-10 15:30:50 -0700417 flags = base_flags = OSC_PCI_SEGMENT_GROUPS_SUPPORT;
Kenji Kaneshige63f10f02009-02-09 15:59:29 +0900418 acpi_pci_osc_support(root, flags);
Andrew Patterson990a7ac2008-11-10 15:30:45 -0700419
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 /*
421 * Segment
422 * -------
423 * Obtained via _SEG, if exists, otherwise assumed to be zero (0).
424 */
Patrick Mochel2d1e0a02006-05-19 16:54:43 -0400425 status = acpi_evaluate_integer(device->handle, METHOD_NAME__SEG, NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400426 &value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 switch (status) {
428 case AE_OK:
429 root->id.segment = (u16) value;
430 break;
431 case AE_NOT_FOUND:
Len Brown4be44fc2005-08-05 00:44:28 -0400432 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
433 "Assuming segment 0 (no _SEG)\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 root->id.segment = 0;
435 break;
436 default:
Thomas Renningera6fc6722006-06-26 23:58:43 -0400437 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _SEG"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 result = -ENODEV;
439 goto end;
440 }
441
442 /*
443 * Bus
444 * ---
445 * Obtained via _BBN, if exists, otherwise assumed to be zero (0).
446 */
Patrick Mochel2d1e0a02006-05-19 16:54:43 -0400447 status = acpi_evaluate_integer(device->handle, METHOD_NAME__BBN, NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400448 &value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 switch (status) {
450 case AE_OK:
451 root->id.bus = (u16) value;
452 break;
453 case AE_NOT_FOUND:
454 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Assuming bus 0 (no _BBN)\n"));
455 root->id.bus = 0;
456 break;
457 default:
Thomas Renningera6fc6722006-06-26 23:58:43 -0400458 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BBN"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 result = -ENODEV;
460 goto end;
461 }
462
463 /* Some systems have wrong _BBN */
464 list_for_each_entry(tmp, &acpi_pci_roots, node) {
465 if ((tmp->id.segment == root->id.segment)
Len Brown4be44fc2005-08-05 00:44:28 -0400466 && (tmp->id.bus == root->id.bus)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 int bus = 0;
468 acpi_status status;
469
Len Brown64684632006-06-26 23:41:38 -0400470 printk(KERN_ERR PREFIX
Thomas Renningera6fc6722006-06-26 23:58:43 -0400471 "Wrong _BBN value, reboot"
Len Brown64684632006-06-26 23:41:38 -0400472 " and use option 'pci=noacpi'\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
Patrick Mochel2d1e0a02006-05-19 16:54:43 -0400474 status = try_get_root_bridge_busnr(device->handle, &bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 if (ACPI_FAILURE(status))
476 break;
477 if (bus != root->id.bus) {
Len Brown4be44fc2005-08-05 00:44:28 -0400478 printk(KERN_INFO PREFIX
479 "PCI _CRS %d overrides _BBN 0\n", bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 root->id.bus = bus;
481 }
482 break;
483 }
484 }
485 /*
486 * Device & Function
487 * -----------------
488 * Obtained from _ADR (which has already been evaluated for us).
489 */
490 root->id.device = device->pnp.bus_address >> 16;
491 root->id.function = device->pnp.bus_address & 0xFFFF;
492
493 /*
494 * TBD: Need PCI interface for enumeration/configuration of roots.
495 */
496
Len Brown4be44fc2005-08-05 00:44:28 -0400497 /* TBD: Locking */
498 list_add_tail(&root->node, &acpi_pci_roots);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
Len Brown4be44fc2005-08-05 00:44:28 -0400500 printk(KERN_INFO PREFIX "%s [%s] (%04x:%02x)\n",
501 acpi_device_name(device), acpi_device_bid(device),
502 root->id.segment, root->id.bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
504 /*
505 * Scan the Root Bridge
506 * --------------------
507 * Must do this prior to any attempt to bind the root device, as the
508 * PCI namespace does not get created until this call is made (and
509 * thus the root bridge's pci_dev does not exist).
510 */
511 root->bus = pci_acpi_scan_root(device, root->id.segment, root->id.bus);
512 if (!root->bus) {
Len Brown64684632006-06-26 23:41:38 -0400513 printk(KERN_ERR PREFIX
514 "Bus %04x:%02x not present in PCI namespace\n",
515 root->id.segment, root->id.bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 result = -ENODEV;
517 goto end;
518 }
519
520 /*
521 * Attach ACPI-PCI Context
522 * -----------------------
523 * Thus binding the ACPI and PCI devices.
524 */
525 result = acpi_pci_bind_root(device, &root->id, root->bus);
526 if (result)
527 goto end;
528
529 /*
530 * PCI Routing Table
531 * -----------------
532 * Evaluate and parse _PRT, if exists.
533 */
Patrick Mochel2d1e0a02006-05-19 16:54:43 -0400534 status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 if (ACPI_SUCCESS(status))
Patrick Mochel2d1e0a02006-05-19 16:54:43 -0400536 result = acpi_pci_irq_add_prt(device->handle, root->id.segment,
Len Brown4be44fc2005-08-05 00:44:28 -0400537 root->id.bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
Rui Zhang2786f6e2006-12-21 02:21:13 -0500539 /*
540 * Scan and bind all _ADR-Based Devices
541 */
542 list_for_each_entry(child, &device->children, node)
543 acpi_pci_bridge_scan(child);
544
Andrew Patterson0ef5f8f2008-11-10 15:30:50 -0700545 /* Indicate support for various _OSC capabilities. */
546 if (pci_ext_cfg_avail(root->bus->self))
547 flags |= OSC_EXT_PCI_CONFIG_SUPPORT;
Andrew Patterson3e1b1602008-11-10 15:30:55 -0700548 if (pcie_aspm_enabled())
549 flags |= OSC_ACTIVE_STATE_PWR_SUPPORT |
550 OSC_CLOCK_PWR_CAPABILITY_SUPPORT;
Andrew Patterson07ae95f2008-11-10 15:31:05 -0700551 if (pci_msi_enabled())
552 flags |= OSC_MSI_SUPPORT;
Andrew Patterson0ef5f8f2008-11-10 15:30:50 -0700553 if (flags != base_flags)
Kenji Kaneshige63f10f02009-02-09 15:59:29 +0900554 acpi_pci_osc_support(root, flags);
Andrew Patterson0ef5f8f2008-11-10 15:30:50 -0700555
Len Brown4be44fc2005-08-05 00:44:28 -0400556 end:
Rajesh Shahc431ada2005-04-28 00:25:45 -0700557 if (result) {
558 if (!list_empty(&root->node))
559 list_del(&root->node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 kfree(root);
Rajesh Shahc431ada2005-04-28 00:25:45 -0700561 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Patrick Mocheld550d982006-06-27 00:41:40 -0400563 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564}
565
Len Brown4be44fc2005-08-05 00:44:28 -0400566static int acpi_pci_root_start(struct acpi_device *device)
Rajesh Shahc431ada2005-04-28 00:25:45 -0700567{
Len Brown4be44fc2005-08-05 00:44:28 -0400568 struct acpi_pci_root *root;
Rajesh Shahc431ada2005-04-28 00:25:45 -0700569
Rajesh Shahc431ada2005-04-28 00:25:45 -0700570
571 list_for_each_entry(root, &acpi_pci_roots, node) {
Patrick Mochel432bfab2006-05-19 16:54:51 -0400572 if (root->device == device) {
Rajesh Shahc431ada2005-04-28 00:25:45 -0700573 pci_bus_add_devices(root->bus);
Patrick Mocheld550d982006-06-27 00:41:40 -0400574 return 0;
Rajesh Shahc431ada2005-04-28 00:25:45 -0700575 }
576 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400577 return -ENODEV;
Rajesh Shahc431ada2005-04-28 00:25:45 -0700578}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
Len Brown4be44fc2005-08-05 00:44:28 -0400580static int acpi_pci_root_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581{
Len Brown4be44fc2005-08-05 00:44:28 -0400582 struct acpi_pci_root *root = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
585 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400586 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200588 root = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
590 kfree(root);
591
Patrick Mocheld550d982006-06-27 00:41:40 -0400592 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593}
594
Len Brown4be44fc2005-08-05 00:44:28 -0400595static int __init acpi_pci_root_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 if (acpi_pci_disabled)
Patrick Mocheld550d982006-06-27 00:41:40 -0400598 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 if (acpi_bus_register_driver(&acpi_pci_root_driver) < 0)
Patrick Mocheld550d982006-06-27 00:41:40 -0400601 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Patrick Mocheld550d982006-06-27 00:41:40 -0400603 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604}
605
606subsys_initcall(acpi_pci_root_init);