]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
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> | |
d0020f65 | 30 | #include <linux/mutex.h> |
1da177e4 | 31 | #include <linux/pm.h> |
b67ea761 | 32 | #include <linux/pm_runtime.h> |
1da177e4 | 33 | #include <linux/pci.h> |
990a7ac5 | 34 | #include <linux/pci-acpi.h> |
eca67315 | 35 | #include <linux/pci-aspm.h> |
1da177e4 | 36 | #include <linux/acpi.h> |
5a0e3ad6 | 37 | #include <linux/slab.h> |
1da177e4 LT |
38 | #include <acpi/acpi_bus.h> |
39 | #include <acpi/acpi_drivers.h> | |
415e12b2 | 40 | #include <acpi/apei.h> |
1da177e4 | 41 | |
a192a958 LB |
42 | #define PREFIX "ACPI: " |
43 | ||
1da177e4 | 44 | #define _COMPONENT ACPI_PCI_COMPONENT |
f52fd66d | 45 | ACPI_MODULE_NAME("pci_root"); |
1da177e4 | 46 | #define ACPI_PCI_ROOT_CLASS "pci_bridge" |
1da177e4 | 47 | #define ACPI_PCI_ROOT_DEVICE_NAME "PCI Root Bridge" |
4be44fcd LB |
48 | static int acpi_pci_root_add(struct acpi_device *device); |
49 | static int acpi_pci_root_remove(struct acpi_device *device, int type); | |
1da177e4 | 50 | |
415e12b2 RW |
51 | #define ACPI_PCIE_REQ_SUPPORT (OSC_EXT_PCI_CONFIG_SUPPORT \ |
52 | | OSC_ACTIVE_STATE_PWR_SUPPORT \ | |
53 | | OSC_CLOCK_PWR_CAPABILITY_SUPPORT \ | |
54 | | OSC_MSI_SUPPORT) | |
55 | ||
c97adf9e | 56 | static const struct acpi_device_id root_device_ids[] = { |
1ba90e3a TR |
57 | {"PNP0A03", 0}, |
58 | {"", 0}, | |
59 | }; | |
60 | MODULE_DEVICE_TABLE(acpi, root_device_ids); | |
61 | ||
1da177e4 | 62 | static struct acpi_driver acpi_pci_root_driver = { |
c2b6705b | 63 | .name = "pci_root", |
4be44fcd | 64 | .class = ACPI_PCI_ROOT_CLASS, |
1ba90e3a | 65 | .ids = root_device_ids, |
4be44fcd LB |
66 | .ops = { |
67 | .add = acpi_pci_root_add, | |
68 | .remove = acpi_pci_root_remove, | |
4be44fcd | 69 | }, |
1da177e4 LT |
70 | }; |
71 | ||
d0020f65 TI |
72 | /* Lock to protect both acpi_pci_roots and acpi_pci_drivers lists */ |
73 | static DEFINE_MUTEX(acpi_pci_root_lock); | |
1da177e4 | 74 | static LIST_HEAD(acpi_pci_roots); |
8ee5bdf3 | 75 | static LIST_HEAD(acpi_pci_drivers); |
1da177e4 | 76 | |
63f10f0f | 77 | static DEFINE_MUTEX(osc_lock); |
1da177e4 LT |
78 | |
79 | int acpi_pci_register_driver(struct acpi_pci_driver *driver) | |
80 | { | |
81 | int n = 0; | |
c1aec834 | 82 | struct acpi_pci_root *root; |
1da177e4 | 83 | |
d0020f65 | 84 | mutex_lock(&acpi_pci_root_lock); |
8ee5bdf3 | 85 | list_add_tail(&driver->node, &acpi_pci_drivers); |
d0020f65 TI |
86 | if (driver->add) |
87 | list_for_each_entry(root, &acpi_pci_roots, node) { | |
55bfe3c0 | 88 | driver->add(root); |
d0020f65 TI |
89 | n++; |
90 | } | |
91 | mutex_unlock(&acpi_pci_root_lock); | |
1da177e4 LT |
92 | |
93 | return n; | |
94 | } | |
95 | EXPORT_SYMBOL(acpi_pci_register_driver); | |
96 | ||
97 | void acpi_pci_unregister_driver(struct acpi_pci_driver *driver) | |
98 | { | |
c1aec834 | 99 | struct acpi_pci_root *root; |
1da177e4 | 100 | |
d0020f65 | 101 | mutex_lock(&acpi_pci_root_lock); |
8ee5bdf3 | 102 | list_del(&driver->node); |
d0020f65 TI |
103 | if (driver->remove) |
104 | list_for_each_entry(root, &acpi_pci_roots, node) | |
55bfe3c0 | 105 | driver->remove(root); |
d0020f65 | 106 | mutex_unlock(&acpi_pci_root_lock); |
1da177e4 LT |
107 | } |
108 | EXPORT_SYMBOL(acpi_pci_unregister_driver); | |
109 | ||
d91a0078 JC |
110 | acpi_handle acpi_get_pci_rootbridge_handle(unsigned int seg, unsigned int bus) |
111 | { | |
c1aec834 | 112 | struct acpi_pci_root *root; |
6507e6eb | 113 | acpi_handle handle = NULL; |
d91a0078 | 114 | |
6507e6eb | 115 | mutex_lock(&acpi_pci_root_lock); |
c1aec834 | 116 | list_for_each_entry(root, &acpi_pci_roots, node) |
6ad95513 | 117 | if ((root->segment == (u16) seg) && |
6507e6eb TI |
118 | (root->secondary.start == (u16) bus)) { |
119 | handle = root->device->handle; | |
120 | break; | |
121 | } | |
122 | mutex_unlock(&acpi_pci_root_lock); | |
123 | return handle; | |
d91a0078 JC |
124 | } |
125 | ||
126 | EXPORT_SYMBOL_GPL(acpi_get_pci_rootbridge_handle); | |
127 | ||
27558203 AC |
128 | /** |
129 | * acpi_is_root_bridge - determine whether an ACPI CA node is a PCI root bridge | |
130 | * @handle - the ACPI CA node in question. | |
131 | * | |
132 | * Note: we could make this API take a struct acpi_device * instead, but | |
133 | * for now, it's more convenient to operate on an acpi_handle. | |
134 | */ | |
135 | int acpi_is_root_bridge(acpi_handle handle) | |
136 | { | |
137 | int ret; | |
138 | struct acpi_device *device; | |
139 | ||
140 | ret = acpi_bus_get_device(handle, &device); | |
141 | if (ret) | |
142 | return 0; | |
143 | ||
144 | ret = acpi_match_device_ids(device, root_device_ids); | |
145 | if (ret) | |
146 | return 0; | |
147 | else | |
148 | return 1; | |
149 | } | |
150 | EXPORT_SYMBOL_GPL(acpi_is_root_bridge); | |
151 | ||
1da177e4 | 152 | static acpi_status |
4be44fcd | 153 | get_root_bridge_busnr_callback(struct acpi_resource *resource, void *data) |
1da177e4 | 154 | { |
6ad95513 | 155 | struct resource *res = data; |
1da177e4 LT |
156 | struct acpi_resource_address64 address; |
157 | ||
50eca3eb BM |
158 | if (resource->type != ACPI_RESOURCE_TYPE_ADDRESS16 && |
159 | resource->type != ACPI_RESOURCE_TYPE_ADDRESS32 && | |
160 | resource->type != ACPI_RESOURCE_TYPE_ADDRESS64) | |
1da177e4 LT |
161 | return AE_OK; |
162 | ||
163 | acpi_resource_to_address64(resource, &address); | |
4be44fcd | 164 | if ((address.address_length > 0) && |
6ad95513 BH |
165 | (address.resource_type == ACPI_BUS_NUMBER_RANGE)) { |
166 | res->start = address.minimum; | |
167 | res->end = address.minimum + address.address_length - 1; | |
168 | } | |
1da177e4 LT |
169 | |
170 | return AE_OK; | |
171 | } | |
172 | ||
f5eebbe1 | 173 | static acpi_status try_get_root_bridge_busnr(acpi_handle handle, |
6ad95513 | 174 | struct resource *res) |
1da177e4 LT |
175 | { |
176 | acpi_status status; | |
177 | ||
6ad95513 | 178 | res->start = -1; |
4be44fcd LB |
179 | status = |
180 | acpi_walk_resources(handle, METHOD_NAME__CRS, | |
6ad95513 | 181 | get_root_bridge_busnr_callback, res); |
1da177e4 LT |
182 | if (ACPI_FAILURE(status)) |
183 | return status; | |
6ad95513 | 184 | if (res->start == -1) |
1da177e4 LT |
185 | return AE_ERROR; |
186 | return AE_OK; | |
187 | } | |
188 | ||
2786f6e3 RZ |
189 | static void acpi_pci_bridge_scan(struct acpi_device *device) |
190 | { | |
191 | int status; | |
192 | struct acpi_device *child = NULL; | |
193 | ||
194 | if (device->flags.bus_address) | |
195 | if (device->parent && device->parent->ops.bind) { | |
196 | status = device->parent->ops.bind(device); | |
197 | if (!status) { | |
198 | list_for_each_entry(child, &device->children, node) | |
199 | acpi_pci_bridge_scan(child); | |
200 | } | |
201 | } | |
202 | } | |
203 | ||
3a9622dc | 204 | static u8 pci_osc_uuid_str[] = "33DB4D5B-1FF7-401C-9657-7441C03DD766"; |
63f10f0f KK |
205 | |
206 | static acpi_status acpi_pci_run_osc(acpi_handle handle, | |
207 | const u32 *capbuf, u32 *retval) | |
208 | { | |
3a9622dc SL |
209 | struct acpi_osc_context context = { |
210 | .uuid_str = pci_osc_uuid_str, | |
211 | .rev = 1, | |
212 | .cap.length = 12, | |
213 | .cap.pointer = (void *)capbuf, | |
214 | }; | |
63f10f0f | 215 | acpi_status status; |
63f10f0f | 216 | |
3a9622dc SL |
217 | status = acpi_run_osc(handle, &context); |
218 | if (ACPI_SUCCESS(status)) { | |
219 | *retval = *((u32 *)(context.ret.pointer + 8)); | |
220 | kfree(context.ret.pointer); | |
63f10f0f | 221 | } |
63f10f0f KK |
222 | return status; |
223 | } | |
224 | ||
ab8e8957 RW |
225 | static acpi_status acpi_pci_query_osc(struct acpi_pci_root *root, |
226 | u32 support, | |
227 | u32 *control) | |
63f10f0f KK |
228 | { |
229 | acpi_status status; | |
ab8e8957 RW |
230 | u32 result, capbuf[3]; |
231 | ||
232 | support &= OSC_PCI_SUPPORT_MASKS; | |
233 | support |= root->osc_support_set; | |
63f10f0f | 234 | |
63f10f0f | 235 | capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE; |
ab8e8957 RW |
236 | capbuf[OSC_SUPPORT_TYPE] = support; |
237 | if (control) { | |
238 | *control &= OSC_PCI_CONTROL_MASKS; | |
239 | capbuf[OSC_CONTROL_TYPE] = *control | root->osc_control_set; | |
240 | } else { | |
241 | /* Run _OSC query for all possible controls. */ | |
242 | capbuf[OSC_CONTROL_TYPE] = OSC_PCI_CONTROL_MASKS; | |
243 | } | |
63f10f0f KK |
244 | |
245 | status = acpi_pci_run_osc(root->device->handle, capbuf, &result); | |
246 | if (ACPI_SUCCESS(status)) { | |
ab8e8957 | 247 | root->osc_support_set = support; |
2b8fd918 | 248 | if (control) |
ab8e8957 | 249 | *control = result; |
63f10f0f KK |
250 | } |
251 | return status; | |
252 | } | |
253 | ||
254 | static acpi_status acpi_pci_osc_support(struct acpi_pci_root *root, u32 flags) | |
255 | { | |
256 | acpi_status status; | |
257 | acpi_handle tmp; | |
258 | ||
259 | status = acpi_get_handle(root->device->handle, "_OSC", &tmp); | |
260 | if (ACPI_FAILURE(status)) | |
261 | return status; | |
262 | mutex_lock(&osc_lock); | |
ab8e8957 | 263 | status = acpi_pci_query_osc(root, flags, NULL); |
63f10f0f KK |
264 | mutex_unlock(&osc_lock); |
265 | return status; | |
266 | } | |
267 | ||
76d56de5 | 268 | struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle) |
63f10f0f KK |
269 | { |
270 | struct acpi_pci_root *root; | |
cd4faf9c | 271 | struct acpi_device *device; |
c1aec834 | 272 | |
cd4faf9c TI |
273 | if (acpi_bus_get_device(handle, &device) || |
274 | acpi_match_device_ids(device, root_device_ids)) | |
275 | return NULL; | |
276 | ||
277 | root = acpi_driver_data(device); | |
278 | ||
279 | return root; | |
63f10f0f | 280 | } |
76d56de5 | 281 | EXPORT_SYMBOL_GPL(acpi_pci_find_root); |
63f10f0f | 282 | |
2f7bbceb AC |
283 | struct acpi_handle_node { |
284 | struct list_head node; | |
285 | acpi_handle handle; | |
286 | }; | |
287 | ||
288 | /** | |
289 | * acpi_get_pci_dev - convert ACPI CA handle to struct pci_dev | |
290 | * @handle: the handle in question | |
291 | * | |
292 | * Given an ACPI CA handle, the desired PCI device is located in the | |
293 | * list of PCI devices. | |
294 | * | |
295 | * If the device is found, its reference count is increased and this | |
296 | * function returns a pointer to its data structure. The caller must | |
297 | * decrement the reference count by calling pci_dev_put(). | |
298 | * If no device is found, %NULL is returned. | |
299 | */ | |
300 | struct pci_dev *acpi_get_pci_dev(acpi_handle handle) | |
301 | { | |
302 | int dev, fn; | |
303 | unsigned long long adr; | |
304 | acpi_status status; | |
305 | acpi_handle phandle; | |
306 | struct pci_bus *pbus; | |
307 | struct pci_dev *pdev = NULL; | |
308 | struct acpi_handle_node *node, *tmp; | |
309 | struct acpi_pci_root *root; | |
310 | LIST_HEAD(device_list); | |
311 | ||
312 | /* | |
313 | * Walk up the ACPI CA namespace until we reach a PCI root bridge. | |
314 | */ | |
315 | phandle = handle; | |
316 | while (!acpi_is_root_bridge(phandle)) { | |
317 | node = kzalloc(sizeof(struct acpi_handle_node), GFP_KERNEL); | |
318 | if (!node) | |
319 | goto out; | |
320 | ||
321 | INIT_LIST_HEAD(&node->node); | |
322 | node->handle = phandle; | |
323 | list_add(&node->node, &device_list); | |
324 | ||
325 | status = acpi_get_parent(phandle, &phandle); | |
326 | if (ACPI_FAILURE(status)) | |
327 | goto out; | |
328 | } | |
329 | ||
330 | root = acpi_pci_find_root(phandle); | |
331 | if (!root) | |
332 | goto out; | |
333 | ||
334 | pbus = root->bus; | |
335 | ||
336 | /* | |
337 | * Now, walk back down the PCI device tree until we return to our | |
338 | * original handle. Assumes that everything between the PCI root | |
339 | * bridge and the device we're looking for must be a P2P bridge. | |
340 | */ | |
341 | list_for_each_entry(node, &device_list, node) { | |
342 | acpi_handle hnd = node->handle; | |
343 | status = acpi_evaluate_integer(hnd, "_ADR", NULL, &adr); | |
344 | if (ACPI_FAILURE(status)) | |
345 | goto out; | |
346 | dev = (adr >> 16) & 0xffff; | |
347 | fn = adr & 0xffff; | |
348 | ||
349 | pdev = pci_get_slot(pbus, PCI_DEVFN(dev, fn)); | |
412af978 | 350 | if (!pdev || hnd == handle) |
2f7bbceb AC |
351 | break; |
352 | ||
353 | pbus = pdev->subordinate; | |
354 | pci_dev_put(pdev); | |
497fb54f RW |
355 | |
356 | /* | |
357 | * This function may be called for a non-PCI device that has a | |
358 | * PCI parent (eg. a disk under a PCI SATA controller). In that | |
359 | * case pdev->subordinate will be NULL for the parent. | |
360 | */ | |
361 | if (!pbus) { | |
362 | dev_dbg(&pdev->dev, "Not a PCI-to-PCI bridge\n"); | |
363 | pdev = NULL; | |
364 | break; | |
365 | } | |
2f7bbceb AC |
366 | } |
367 | out: | |
368 | list_for_each_entry_safe(node, tmp, &device_list, node) | |
369 | kfree(node); | |
370 | ||
371 | return pdev; | |
372 | } | |
373 | EXPORT_SYMBOL_GPL(acpi_get_pci_dev); | |
374 | ||
63f10f0f | 375 | /** |
75fb60f2 RW |
376 | * acpi_pci_osc_control_set - Request control of PCI root _OSC features. |
377 | * @handle: ACPI handle of a PCI root bridge (or PCIe Root Complex). | |
378 | * @mask: Mask of _OSC bits to request control of, place to store control mask. | |
379 | * @req: Mask of _OSC bits the control of is essential to the caller. | |
63f10f0f | 380 | * |
75fb60f2 RW |
381 | * Run _OSC query for @mask and if that is successful, compare the returned |
382 | * mask of control bits with @req. If all of the @req bits are set in the | |
383 | * returned mask, run _OSC request for it. | |
384 | * | |
385 | * The variable at the @mask address may be modified regardless of whether or | |
386 | * not the function returns success. On success it will contain the mask of | |
387 | * _OSC bits the BIOS has granted control of, but its contents are meaningless | |
388 | * on failure. | |
63f10f0f | 389 | **/ |
75fb60f2 | 390 | acpi_status acpi_pci_osc_control_set(acpi_handle handle, u32 *mask, u32 req) |
63f10f0f | 391 | { |
75fb60f2 | 392 | struct acpi_pci_root *root; |
63f10f0f | 393 | acpi_status status; |
75fb60f2 | 394 | u32 ctrl, capbuf[3]; |
63f10f0f | 395 | acpi_handle tmp; |
63f10f0f | 396 | |
75fb60f2 RW |
397 | if (!mask) |
398 | return AE_BAD_PARAMETER; | |
399 | ||
400 | ctrl = *mask & OSC_PCI_CONTROL_MASKS; | |
401 | if ((ctrl & req) != req) | |
63f10f0f KK |
402 | return AE_TYPE; |
403 | ||
404 | root = acpi_pci_find_root(handle); | |
405 | if (!root) | |
406 | return AE_NOT_EXIST; | |
407 | ||
b879dc4b RW |
408 | status = acpi_get_handle(handle, "_OSC", &tmp); |
409 | if (ACPI_FAILURE(status)) | |
410 | return status; | |
411 | ||
63f10f0f | 412 | mutex_lock(&osc_lock); |
75fb60f2 RW |
413 | |
414 | *mask = ctrl | root->osc_control_set; | |
63f10f0f | 415 | /* No need to evaluate _OSC if the control was already granted. */ |
75fb60f2 | 416 | if ((root->osc_control_set & ctrl) == ctrl) |
63f10f0f KK |
417 | goto out; |
418 | ||
75fb60f2 RW |
419 | /* Need to check the available controls bits before requesting them. */ |
420 | while (*mask) { | |
421 | status = acpi_pci_query_osc(root, root->osc_support_set, mask); | |
422 | if (ACPI_FAILURE(status)) | |
423 | goto out; | |
424 | if (ctrl == *mask) | |
425 | break; | |
426 | ctrl = *mask; | |
427 | } | |
2b8fd918 | 428 | |
75fb60f2 | 429 | if ((ctrl & req) != req) { |
63f10f0f KK |
430 | status = AE_SUPPORT; |
431 | goto out; | |
432 | } | |
433 | ||
434 | capbuf[OSC_QUERY_TYPE] = 0; | |
435 | capbuf[OSC_SUPPORT_TYPE] = root->osc_support_set; | |
75fb60f2 RW |
436 | capbuf[OSC_CONTROL_TYPE] = ctrl; |
437 | status = acpi_pci_run_osc(handle, capbuf, mask); | |
63f10f0f | 438 | if (ACPI_SUCCESS(status)) |
75fb60f2 | 439 | root->osc_control_set = *mask; |
63f10f0f KK |
440 | out: |
441 | mutex_unlock(&osc_lock); | |
442 | return status; | |
443 | } | |
9f5404d8 | 444 | EXPORT_SYMBOL(acpi_pci_osc_control_set); |
63f10f0f | 445 | |
da095fd3 | 446 | static int acpi_pci_root_add(struct acpi_device *device) |
1da177e4 | 447 | { |
f5eebbe1 BH |
448 | unsigned long long segment, bus; |
449 | acpi_status status; | |
450 | int result; | |
451 | struct acpi_pci_root *root; | |
452 | acpi_handle handle; | |
2786f6e3 | 453 | struct acpi_device *child; |
47525cda | 454 | struct acpi_pci_driver *driver; |
0ef5f8f6 | 455 | u32 flags, base_flags; |
8c33f51d | 456 | bool is_osc_granted = false; |
1da177e4 | 457 | |
6ad95513 BH |
458 | root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL); |
459 | if (!root) | |
460 | return -ENOMEM; | |
461 | ||
f5eebbe1 BH |
462 | segment = 0; |
463 | status = acpi_evaluate_integer(device->handle, METHOD_NAME__SEG, NULL, | |
464 | &segment); | |
465 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { | |
466 | printk(KERN_ERR PREFIX "can't evaluate _SEG\n"); | |
6ad95513 BH |
467 | result = -ENODEV; |
468 | goto end; | |
f5eebbe1 | 469 | } |
1da177e4 | 470 | |
f5eebbe1 | 471 | /* Check _CRS first, then _BBN. If no _BBN, default to zero. */ |
6ad95513 BH |
472 | root->secondary.flags = IORESOURCE_BUS; |
473 | status = try_get_root_bridge_busnr(device->handle, &root->secondary); | |
f5eebbe1 | 474 | if (ACPI_FAILURE(status)) { |
6ad95513 BH |
475 | /* |
476 | * We need both the start and end of the downstream bus range | |
477 | * to interpret _CBA (MMCONFIG base address), so it really is | |
478 | * supposed to be in _CRS. If we don't find it there, all we | |
479 | * can do is assume [_BBN-0xFF] or [0-0xFF]. | |
480 | */ | |
481 | root->secondary.end = 0xFF; | |
482 | printk(KERN_WARNING FW_BUG PREFIX | |
483 | "no secondary bus range in _CRS\n"); | |
e545b55a JM |
484 | status = acpi_evaluate_integer(device->handle, METHOD_NAME__BBN, |
485 | NULL, &bus); | |
6ad95513 BH |
486 | if (ACPI_SUCCESS(status)) |
487 | root->secondary.start = bus; | |
488 | else if (status == AE_NOT_FOUND) | |
489 | root->secondary.start = 0; | |
490 | else { | |
491 | printk(KERN_ERR PREFIX "can't evaluate _BBN\n"); | |
492 | result = -ENODEV; | |
493 | goto end; | |
f5eebbe1 BH |
494 | } |
495 | } | |
1da177e4 | 496 | |
f5eebbe1 | 497 | INIT_LIST_HEAD(&root->node); |
32917e5b | 498 | root->device = device; |
0705495d | 499 | root->segment = segment & 0xFFFF; |
1da177e4 LT |
500 | strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME); |
501 | strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS); | |
db89b4f0 | 502 | device->driver_data = root; |
1da177e4 | 503 | |
6ad95513 | 504 | printk(KERN_INFO PREFIX "%s [%s] (domain %04x %pR)\n", |
4be44fcd | 505 | acpi_device_name(device), acpi_device_bid(device), |
6ad95513 | 506 | root->segment, &root->secondary); |
1da177e4 | 507 | |
1da177e4 LT |
508 | /* |
509 | * PCI Routing Table | |
510 | * ----------------- | |
511 | * Evaluate and parse _PRT, if exists. | |
512 | */ | |
2d1e0a02 | 513 | status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle); |
1da177e4 | 514 | if (ACPI_SUCCESS(status)) |
d4761ba2 BH |
515 | result = acpi_pci_irq_add_prt(device->handle, root->segment, |
516 | root->secondary.start); | |
517 | ||
f4b57a3b | 518 | root->mcfg_addr = acpi_pci_root_get_mcfg_addr(device->handle); |
1da177e4 | 519 | |
2786f6e3 | 520 | /* |
990a7ac5 AP |
521 | * All supported architectures that use ACPI have support for |
522 | * PCI domains, so we indicate this in _OSC support capabilities. | |
2786f6e3 | 523 | */ |
0ef5f8f6 | 524 | flags = base_flags = OSC_PCI_SEGMENT_GROUPS_SUPPORT; |
63f10f0f | 525 | acpi_pci_osc_support(root, flags); |
2786f6e3 | 526 | |
0ef5f8f6 | 527 | /* Indicate support for various _OSC capabilities. */ |
8c33f51d | 528 | if (pci_ext_cfg_avail()) |
0ef5f8f6 | 529 | flags |= OSC_EXT_PCI_CONFIG_SUPPORT; |
8c33f51d | 530 | if (pcie_aspm_support_enabled()) { |
3e1b1600 | 531 | flags |= OSC_ACTIVE_STATE_PWR_SUPPORT | |
8c33f51d TI |
532 | OSC_CLOCK_PWR_CAPABILITY_SUPPORT; |
533 | } | |
07ae95f9 AP |
534 | if (pci_msi_enabled()) |
535 | flags |= OSC_MSI_SUPPORT; | |
2d9c8677 RW |
536 | if (flags != base_flags) { |
537 | status = acpi_pci_osc_support(root, flags); | |
538 | if (ACPI_FAILURE(status)) { | |
8c33f51d | 539 | dev_info(&device->dev, "ACPI _OSC support " |
2d9c8677 RW |
540 | "notification failed, disabling PCIe ASPM\n"); |
541 | pcie_no_aspm(); | |
542 | flags = base_flags; | |
543 | } | |
544 | } | |
415e12b2 RW |
545 | if (!pcie_ports_disabled |
546 | && (flags & ACPI_PCIE_REQ_SUPPORT) == ACPI_PCIE_REQ_SUPPORT) { | |
547 | flags = OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL | |
548 | | OSC_PCI_EXPRESS_NATIVE_HP_CONTROL | |
549 | | OSC_PCI_EXPRESS_PME_CONTROL; | |
550 | ||
551 | if (pci_aer_available()) { | |
552 | if (aer_acpi_firmware_first()) | |
8c33f51d | 553 | dev_dbg(&device->dev, |
415e12b2 RW |
554 | "PCIe errors handled by BIOS.\n"); |
555 | else | |
556 | flags |= OSC_PCI_EXPRESS_AER_CONTROL; | |
557 | } | |
558 | ||
8c33f51d | 559 | dev_info(&device->dev, |
415e12b2 RW |
560 | "Requesting ACPI _OSC control (0x%02x)\n", flags); |
561 | ||
562 | status = acpi_pci_osc_control_set(device->handle, &flags, | |
8c33f51d | 563 | OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL); |
eca67315 | 564 | if (ACPI_SUCCESS(status)) { |
8c33f51d TI |
565 | is_osc_granted = true; |
566 | dev_info(&device->dev, | |
415e12b2 | 567 | "ACPI _OSC control (0x%02x) granted\n", flags); |
eca67315 | 568 | } else { |
8c33f51d TI |
569 | is_osc_granted = false; |
570 | dev_info(&device->dev, | |
a246670d RW |
571 | "ACPI _OSC request failed (%s), " |
572 | "returned control mask: 0x%02x\n", | |
573 | acpi_format_exception(status), flags); | |
eca67315 | 574 | } |
a246670d | 575 | } else { |
8c33f51d TI |
576 | dev_info(&device->dev, |
577 | "Unable to request _OSC control " | |
578 | "(_OSC support mask: 0x%02x)\n", flags); | |
579 | } | |
580 | ||
1da177e4 LT |
581 | /* |
582 | * TBD: Need PCI interface for enumeration/configuration of roots. | |
583 | */ | |
584 | ||
6507e6eb | 585 | mutex_lock(&acpi_pci_root_lock); |
4be44fcd | 586 | list_add_tail(&root->node, &acpi_pci_roots); |
6507e6eb | 587 | mutex_unlock(&acpi_pci_root_lock); |
1da177e4 | 588 | |
1da177e4 LT |
589 | /* |
590 | * Scan the Root Bridge | |
591 | * -------------------- | |
592 | * Must do this prior to any attempt to bind the root device, as the | |
593 | * PCI namespace does not get created until this call is made (and | |
594 | * thus the root bridge's pci_dev does not exist). | |
595 | */ | |
57283776 | 596 | root->bus = pci_acpi_scan_root(root); |
1da177e4 | 597 | if (!root->bus) { |
6468463a LB |
598 | printk(KERN_ERR PREFIX |
599 | "Bus %04x:%02x not present in PCI namespace\n", | |
6ad95513 | 600 | root->segment, (unsigned int)root->secondary.start); |
1da177e4 | 601 | result = -ENODEV; |
6507e6eb | 602 | goto out_del_root; |
1da177e4 LT |
603 | } |
604 | ||
605 | /* | |
606 | * Attach ACPI-PCI Context | |
607 | * ----------------------- | |
608 | * Thus binding the ACPI and PCI devices. | |
609 | */ | |
499650de | 610 | result = acpi_pci_bind_root(device); |
1da177e4 | 611 | if (result) |
6507e6eb | 612 | goto out_del_root; |
1da177e4 | 613 | |
2786f6e3 RZ |
614 | /* |
615 | * Scan and bind all _ADR-Based Devices | |
616 | */ | |
617 | list_for_each_entry(child, &device->children, node) | |
618 | acpi_pci_bridge_scan(child); | |
619 | ||
8c33f51d TI |
620 | /* ASPM setting */ |
621 | if (is_osc_granted) { | |
622 | if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_ASPM) | |
623 | pcie_clear_aspm(root->bus); | |
a246670d | 624 | } else { |
8c33f51d TI |
625 | pr_info("ACPI _OSC control for PCIe not granted, " |
626 | "disabling ASPM\n"); | |
627 | pcie_no_aspm(); | |
415e12b2 RW |
628 | } |
629 | ||
b67ea761 RW |
630 | pci_acpi_add_bus_pm_notifier(device, root->bus); |
631 | if (device->wakeup.flags.run_wake) | |
632 | device_set_run_wake(root->bus->bridge, true); | |
633 | ||
62a08c5a YL |
634 | if (system_state != SYSTEM_BOOTING) |
635 | pci_assign_unassigned_bus_resources(root->bus); | |
636 | ||
d0020f65 | 637 | mutex_lock(&acpi_pci_root_lock); |
c8e9afb1 JL |
638 | list_for_each_entry(driver, &acpi_pci_drivers, node) |
639 | if (driver->add) | |
55bfe3c0 | 640 | driver->add(root); |
d0020f65 | 641 | mutex_unlock(&acpi_pci_root_lock); |
c431ada4 | 642 | |
62a08c5a YL |
643 | /* need to after hot-added ioapic is registered */ |
644 | if (system_state != SYSTEM_BOOTING) | |
645 | pci_enable_bridges(root->bus); | |
646 | ||
caf420c6 BH |
647 | pci_bus_add_devices(root->bus); |
648 | return 0; | |
47525cda RW |
649 | |
650 | out_del_root: | |
651 | mutex_lock(&acpi_pci_root_lock); | |
652 | list_del(&root->node); | |
653 | mutex_unlock(&acpi_pci_root_lock); | |
654 | ||
655 | acpi_pci_irq_del_prt(root->segment, root->secondary.start); | |
656 | end: | |
657 | kfree(root); | |
658 | return result; | |
c431ada4 | 659 | } |
1da177e4 | 660 | |
4be44fcd | 661 | static int acpi_pci_root_remove(struct acpi_device *device, int type) |
1da177e4 | 662 | { |
13b6a916 YL |
663 | acpi_status status; |
664 | acpi_handle handle; | |
caf420c6 | 665 | struct acpi_pci_root *root = acpi_driver_data(device); |
c8e9afb1 JL |
666 | struct acpi_pci_driver *driver; |
667 | ||
9738a1fd YL |
668 | pci_stop_root_bus(root->bus); |
669 | ||
d0020f65 | 670 | mutex_lock(&acpi_pci_root_lock); |
f426cef3 | 671 | list_for_each_entry_reverse(driver, &acpi_pci_drivers, node) |
c8e9afb1 | 672 | if (driver->remove) |
55bfe3c0 | 673 | driver->remove(root); |
9738a1fd | 674 | mutex_unlock(&acpi_pci_root_lock); |
1da177e4 | 675 | |
b67ea761 RW |
676 | device_set_run_wake(root->bus->bridge, false); |
677 | pci_acpi_remove_bus_pm_notifier(device); | |
678 | ||
13b6a916 YL |
679 | status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle); |
680 | if (ACPI_SUCCESS(status)) | |
79c44122 | 681 | acpi_pci_irq_del_prt(root->segment, root->secondary.start); |
13b6a916 | 682 | |
9738a1fd YL |
683 | pci_remove_root_bus(root->bus); |
684 | ||
685 | mutex_lock(&acpi_pci_root_lock); | |
6507e6eb TI |
686 | list_del(&root->node); |
687 | mutex_unlock(&acpi_pci_root_lock); | |
1da177e4 | 688 | kfree(root); |
d550d98d | 689 | return 0; |
1da177e4 LT |
690 | } |
691 | ||
92ef2a25 | 692 | int __init acpi_pci_root_init(void) |
1da177e4 | 693 | { |
d3072e6a RW |
694 | acpi_hest_init(); |
695 | ||
1da177e4 | 696 | if (acpi_pci_disabled) |
d550d98d | 697 | return 0; |
1da177e4 | 698 | |
7bc5e3f2 | 699 | pci_acpi_crs_quirks(); |
1da177e4 | 700 | if (acpi_bus_register_driver(&acpi_pci_root_driver) < 0) |
d550d98d | 701 | return -ENODEV; |
1da177e4 | 702 | |
d550d98d | 703 | return 0; |
1da177e4 | 704 | } |