26 #include <linux/kernel.h>
27 #include <linux/module.h>
29 #include <linux/types.h>
33 #include <linux/pci.h>
37 #include <linux/slab.h>
42 #define PREFIX "ACPI: "
44 #define _COMPONENT ACPI_PCI_COMPONENT
46 #define ACPI_PCI_ROOT_CLASS "pci_bridge"
47 #define ACPI_PCI_ROOT_DEVICE_NAME "PCI Root Bridge"
48 static int acpi_pci_root_add(
struct acpi_device *
device);
49 static int acpi_pci_root_remove(
struct acpi_device *
device,
int type);
50 static int acpi_pci_root_start(
struct acpi_device *
device);
52 #define ACPI_PCIE_REQ_SUPPORT (OSC_EXT_PCI_CONFIG_SUPPORT \
53 | OSC_ACTIVE_STATE_PWR_SUPPORT \
54 | OSC_CLOCK_PWR_CAPABILITY_SUPPORT \
63 static struct acpi_driver acpi_pci_root_driver = {
66 .ids = root_device_ids,
68 .add = acpi_pci_root_add,
69 .remove = acpi_pci_root_remove,
70 .start = acpi_pci_root_start,
84 struct acpi_pci_root *
root;
101 struct acpi_pci_root *
root;
107 driver->remove(root);
114 struct acpi_pci_root *
root;
119 if ((root->segment == (
u16) seg) &&
120 (root->secondary.start == (
u16) bus)) {
121 handle = root->device->handle;
140 struct acpi_device *
device;
166 if ((
address.address_length > 0) &&
176 struct resource *res)
183 get_root_bridge_busnr_callback, res);
186 if (res->
start == -1)
191 static void acpi_pci_bridge_scan(
struct acpi_device *
device)
196 if (device->flags.bus_address)
197 if (device->parent && device->parent->ops.bind) {
198 status = device->parent->ops.bind(device);
201 acpi_pci_bridge_scan(child);
206 static
u8 pci_osc_uuid_str[] = "33DB4D5B-1FF7-401
C-9657-7441C03DD766";
211 struct acpi_osc_context
context = {
212 .uuid_str = pci_osc_uuid_str,
215 .cap.pointer = (
void *)capbuf,
221 *retval = *((
u32 *)(context.ret.pointer + 8));
222 kfree(context.ret.pointer);
227 static acpi_status acpi_pci_query_osc(
struct acpi_pci_root *root,
234 support &= OSC_PCI_SUPPORT_MASKS;
235 support |= root->osc_support_set;
237 capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
238 capbuf[OSC_SUPPORT_TYPE] =
support;
240 *control &= OSC_PCI_CONTROL_MASKS;
241 capbuf[OSC_CONTROL_TYPE] = *control | root->osc_control_set;
244 capbuf[OSC_CONTROL_TYPE] = OSC_PCI_CONTROL_MASKS;
247 status = acpi_pci_run_osc(root->device->handle, capbuf, &result);
249 root->osc_support_set =
support;
265 status = acpi_pci_query_osc(root, flags,
NULL);
272 struct acpi_pci_root *root;
273 struct acpi_device *device;
279 root = acpi_driver_data(device);
305 unsigned long long adr;
311 struct acpi_pci_root *root;
323 INIT_LIST_HEAD(&node->
node);
348 dev = (adr >> 16) & 0xffff;
352 if (!pdev || hnd == handle)
364 dev_dbg(&pdev->
dev,
"Not a PCI-to-PCI bridge\n");
394 struct acpi_pci_root *root;
402 ctrl = *mask & OSC_PCI_CONTROL_MASKS;
403 if ((ctrl & req) != req)
416 *mask = ctrl | root->osc_control_set;
418 if ((root->osc_control_set & ctrl) == ctrl)
423 status = acpi_pci_query_osc(root, root->osc_support_set, mask);
431 if ((ctrl & req) != req) {
436 capbuf[OSC_QUERY_TYPE] = 0;
437 capbuf[OSC_SUPPORT_TYPE] = root->osc_support_set;
438 capbuf[OSC_CONTROL_TYPE] =
ctrl;
439 status = acpi_pci_run_osc(handle, capbuf, mask);
441 root->osc_control_set = *
mask;
448 static int __devinit acpi_pci_root_add(
struct acpi_device *device)
453 struct acpi_pci_root *root;
455 struct acpi_device *child;
458 root = kzalloc(
sizeof(
struct acpi_pci_root),
GFP_KERNEL);
473 status = try_get_root_bridge_busnr(device->handle, &root->secondary);
481 root->secondary.end = 0xFF;
483 "no secondary bus range in _CRS\n");
487 root->secondary.start =
bus;
489 root->secondary.start = 0;
497 INIT_LIST_HEAD(&root->node);
498 root->device = device;
499 root->segment = segment & 0xFFFF;
502 device->driver_data = root;
510 flags = base_flags = OSC_PCI_SEGMENT_GROUPS_SUPPORT;
511 acpi_pci_osc_support(root, flags);
522 acpi_device_name(device), acpi_device_bid(device),
523 root->segment, &root->secondary);
535 "Bus %04x:%02x not present in PCI namespace\n",
536 root->segment, (
unsigned int)root->secondary.start);
563 acpi_pci_bridge_scan(child);
567 flags |= OSC_EXT_PCI_CONFIG_SUPPORT;
569 flags |= OSC_ACTIVE_STATE_PWR_SUPPORT |
570 OSC_CLOCK_PWR_CAPABILITY_SUPPORT;
572 flags |= OSC_MSI_SUPPORT;
573 if (flags != base_flags) {
574 status = acpi_pci_osc_support(root, flags);
576 dev_info(root->bus->bridge,
"ACPI _OSC support "
577 "notification failed, disabling PCIe ASPM\n");
585 flags = OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL
586 | OSC_PCI_EXPRESS_NATIVE_HP_CONTROL
587 | OSC_PCI_EXPRESS_PME_CONTROL;
590 if (aer_acpi_firmware_first())
592 "PCIe errors handled by BIOS.\n");
594 flags |= OSC_PCI_EXPRESS_AER_CONTROL;
598 "Requesting ACPI _OSC control (0x%02x)\n", flags);
601 OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL);
604 "ACPI _OSC control (0x%02x) granted\n", flags);
614 "ACPI _OSC request failed (%s), "
615 "returned control mask: 0x%02x\n",
617 pr_info(
"ACPI _OSC control for PCIe not granted, "
623 "Unable to request _OSC control "
624 "(_OSC support mask: 0x%02x)\n", flags);
628 if (device->wakeup.flags.run_wake)
629 device_set_run_wake(root->bus->bridge,
true);
642 static int acpi_pci_root_start(
struct acpi_device *device)
644 struct acpi_pci_root *root = acpi_driver_data(device);
645 struct acpi_pci_driver *
driver;
658 static
int acpi_pci_root_remove(
struct acpi_device *device,
int type)
660 struct acpi_pci_root *root = acpi_driver_data(device);
661 struct acpi_pci_driver *
driver;
666 driver->remove(root);
668 device_set_run_wake(root->bus->bridge,
false);
677 static
int __init acpi_pci_root_init(
void)