1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * pci_root.c - ACPI PCI Root Bridge Driver ($Revision: 40 $)
5 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
6 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/types.h>
13 #include <linux/mutex.h>
15 #include <linux/pm_runtime.h>
16 #include <linux/pci.h>
17 #include <linux/pci-acpi.h>
18 #include <linux/dmar.h>
19 #include <linux/acpi.h>
20 #include <linux/slab.h>
21 #include <linux/dmi.h>
22 #include <linux/platform_data/x86/apple.h>
23 #include <acpi/apei.h> /* for acpi_hest_init() */
27 #define ACPI_PCI_ROOT_CLASS "pci_bridge"
28 #define ACPI_PCI_ROOT_DEVICE_NAME "PCI Root Bridge"
29 static int acpi_pci_root_add(struct acpi_device *device,
30 const struct acpi_device_id *not_used);
31 static void acpi_pci_root_remove(struct acpi_device *device);
33 static int acpi_pci_root_scan_dependent(struct acpi_device *adev)
35 acpiphp_check_host_bridge(adev);
39 #define ACPI_PCIE_REQ_SUPPORT (OSC_PCI_EXT_CONFIG_SUPPORT \
40 | OSC_PCI_ASPM_SUPPORT \
41 | OSC_PCI_CLOCK_PM_SUPPORT \
42 | OSC_PCI_MSI_SUPPORT)
44 static const struct acpi_device_id root_device_ids[] = {
49 static struct acpi_scan_handler pci_root_handler = {
50 .ids = root_device_ids,
51 .attach = acpi_pci_root_add,
52 .detach = acpi_pci_root_remove,
55 .scan_dependent = acpi_pci_root_scan_dependent,
60 * acpi_is_root_bridge - determine whether an ACPI CA node is a PCI root bridge
61 * @handle: the ACPI CA node in question.
63 * Note: we could make this API take a struct acpi_device * instead, but
64 * for now, it's more convenient to operate on an acpi_handle.
66 int acpi_is_root_bridge(acpi_handle handle)
69 struct acpi_device *device;
71 ret = acpi_bus_get_device(handle, &device);
75 ret = acpi_match_device_ids(device, root_device_ids);
81 EXPORT_SYMBOL_GPL(acpi_is_root_bridge);
84 get_root_bridge_busnr_callback(struct acpi_resource *resource, void *data)
86 struct resource *res = data;
87 struct acpi_resource_address64 address;
90 status = acpi_resource_to_address64(resource, &address);
91 if (ACPI_FAILURE(status))
94 if ((address.address.address_length > 0) &&
95 (address.resource_type == ACPI_BUS_NUMBER_RANGE)) {
96 res->start = address.address.minimum;
97 res->end = address.address.minimum + address.address.address_length - 1;
103 static acpi_status try_get_root_bridge_busnr(acpi_handle handle,
104 struct resource *res)
110 acpi_walk_resources(handle, METHOD_NAME__CRS,
111 get_root_bridge_busnr_callback, res);
112 if (ACPI_FAILURE(status))
114 if (res->start == -1)
119 struct pci_osc_bit_struct {
124 static struct pci_osc_bit_struct pci_osc_support_bit[] = {
125 { OSC_PCI_EXT_CONFIG_SUPPORT, "ExtendedConfig" },
126 { OSC_PCI_ASPM_SUPPORT, "ASPM" },
127 { OSC_PCI_CLOCK_PM_SUPPORT, "ClockPM" },
128 { OSC_PCI_SEGMENT_GROUPS_SUPPORT, "Segments" },
129 { OSC_PCI_MSI_SUPPORT, "MSI" },
130 { OSC_PCI_EDR_SUPPORT, "EDR" },
131 { OSC_PCI_HPX_TYPE_3_SUPPORT, "HPX-Type3" },
134 static struct pci_osc_bit_struct pci_osc_control_bit[] = {
135 { OSC_PCI_EXPRESS_NATIVE_HP_CONTROL, "PCIeHotplug" },
136 { OSC_PCI_SHPC_NATIVE_HP_CONTROL, "SHPCHotplug" },
137 { OSC_PCI_EXPRESS_PME_CONTROL, "PME" },
138 { OSC_PCI_EXPRESS_AER_CONTROL, "AER" },
139 { OSC_PCI_EXPRESS_CAPABILITY_CONTROL, "PCIeCapability" },
140 { OSC_PCI_EXPRESS_LTR_CONTROL, "LTR" },
141 { OSC_PCI_EXPRESS_DPC_CONTROL, "DPC" },
144 static void decode_osc_bits(struct acpi_pci_root *root, char *msg, u32 word,
145 struct pci_osc_bit_struct *table, int size)
149 struct pci_osc_bit_struct *entry;
152 for (i = 0, entry = table; i < size; i++, entry++)
153 if (word & entry->bit)
154 len += scnprintf(buf + len, sizeof(buf) - len, "%s%s",
155 len ? " " : "", entry->desc);
157 dev_info(&root->device->dev, "_OSC: %s [%s]\n", msg, buf);
160 static void decode_osc_support(struct acpi_pci_root *root, char *msg, u32 word)
162 decode_osc_bits(root, msg, word, pci_osc_support_bit,
163 ARRAY_SIZE(pci_osc_support_bit));
166 static void decode_osc_control(struct acpi_pci_root *root, char *msg, u32 word)
168 decode_osc_bits(root, msg, word, pci_osc_control_bit,
169 ARRAY_SIZE(pci_osc_control_bit));
172 static u8 pci_osc_uuid_str[] = "33DB4D5B-1FF7-401C-9657-7441C03DD766";
174 static acpi_status acpi_pci_run_osc(acpi_handle handle,
175 const u32 *capbuf, u32 *retval)
177 struct acpi_osc_context context = {
178 .uuid_str = pci_osc_uuid_str,
181 .cap.pointer = (void *)capbuf,
185 status = acpi_run_osc(handle, &context);
186 if (ACPI_SUCCESS(status)) {
187 *retval = *((u32 *)(context.ret.pointer + 8));
188 kfree(context.ret.pointer);
193 static acpi_status acpi_pci_query_osc(struct acpi_pci_root *root,
198 u32 result, capbuf[3];
200 support &= OSC_PCI_SUPPORT_MASKS;
201 support |= root->osc_support_set;
203 capbuf[OSC_QUERY_DWORD] = OSC_QUERY_ENABLE;
204 capbuf[OSC_SUPPORT_DWORD] = support;
206 *control &= OSC_PCI_CONTROL_MASKS;
207 capbuf[OSC_CONTROL_DWORD] = *control | root->osc_control_set;
209 /* Run _OSC query only with existing controls. */
210 capbuf[OSC_CONTROL_DWORD] = root->osc_control_set;
213 status = acpi_pci_run_osc(root->device->handle, capbuf, &result);
214 if (ACPI_SUCCESS(status)) {
215 root->osc_support_set = support;
222 static acpi_status acpi_pci_osc_support(struct acpi_pci_root *root, u32 flags)
224 return acpi_pci_query_osc(root, flags, NULL);
227 struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle)
229 struct acpi_pci_root *root;
230 struct acpi_device *device;
232 if (acpi_bus_get_device(handle, &device) ||
233 acpi_match_device_ids(device, root_device_ids))
236 root = acpi_driver_data(device);
240 EXPORT_SYMBOL_GPL(acpi_pci_find_root);
242 struct acpi_handle_node {
243 struct list_head node;
248 * acpi_get_pci_dev - convert ACPI CA handle to struct pci_dev
249 * @handle: the handle in question
251 * Given an ACPI CA handle, the desired PCI device is located in the
252 * list of PCI devices.
254 * If the device is found, its reference count is increased and this
255 * function returns a pointer to its data structure. The caller must
256 * decrement the reference count by calling pci_dev_put().
257 * If no device is found, %NULL is returned.
259 struct pci_dev *acpi_get_pci_dev(acpi_handle handle)
262 unsigned long long adr;
265 struct pci_bus *pbus;
266 struct pci_dev *pdev = NULL;
267 struct acpi_handle_node *node, *tmp;
268 struct acpi_pci_root *root;
269 LIST_HEAD(device_list);
272 * Walk up the ACPI CA namespace until we reach a PCI root bridge.
275 while (!acpi_is_root_bridge(phandle)) {
276 node = kzalloc(sizeof(struct acpi_handle_node), GFP_KERNEL);
280 INIT_LIST_HEAD(&node->node);
281 node->handle = phandle;
282 list_add(&node->node, &device_list);
284 status = acpi_get_parent(phandle, &phandle);
285 if (ACPI_FAILURE(status))
289 root = acpi_pci_find_root(phandle);
296 * Now, walk back down the PCI device tree until we return to our
297 * original handle. Assumes that everything between the PCI root
298 * bridge and the device we're looking for must be a P2P bridge.
300 list_for_each_entry(node, &device_list, node) {
301 acpi_handle hnd = node->handle;
302 status = acpi_evaluate_integer(hnd, "_ADR", NULL, &adr);
303 if (ACPI_FAILURE(status))
305 dev = (adr >> 16) & 0xffff;
308 pdev = pci_get_slot(pbus, PCI_DEVFN(dev, fn));
309 if (!pdev || hnd == handle)
312 pbus = pdev->subordinate;
316 * This function may be called for a non-PCI device that has a
317 * PCI parent (eg. a disk under a PCI SATA controller). In that
318 * case pdev->subordinate will be NULL for the parent.
321 dev_dbg(&pdev->dev, "Not a PCI-to-PCI bridge\n");
327 list_for_each_entry_safe(node, tmp, &device_list, node)
332 EXPORT_SYMBOL_GPL(acpi_get_pci_dev);
335 * acpi_pci_osc_control_set - Request control of PCI root _OSC features.
336 * @handle: ACPI handle of a PCI root bridge (or PCIe Root Complex).
337 * @mask: Mask of _OSC bits to request control of, place to store control mask.
338 * @req: Mask of _OSC bits the control of is essential to the caller.
340 * Run _OSC query for @mask and if that is successful, compare the returned
341 * mask of control bits with @req. If all of the @req bits are set in the
342 * returned mask, run _OSC request for it.
344 * The variable at the @mask address may be modified regardless of whether or
345 * not the function returns success. On success it will contain the mask of
346 * _OSC bits the BIOS has granted control of, but its contents are meaningless
349 static acpi_status acpi_pci_osc_control_set(acpi_handle handle, u32 *mask, u32 req)
351 struct acpi_pci_root *root;
356 return AE_BAD_PARAMETER;
358 ctrl = *mask & OSC_PCI_CONTROL_MASKS;
359 if ((ctrl & req) != req)
362 root = acpi_pci_find_root(handle);
366 *mask = ctrl | root->osc_control_set;
367 /* No need to evaluate _OSC if the control was already granted. */
368 if ((root->osc_control_set & ctrl) == ctrl)
371 /* Need to check the available controls bits before requesting them. */
373 status = acpi_pci_query_osc(root, root->osc_support_set, mask);
374 if (ACPI_FAILURE(status))
378 decode_osc_control(root, "platform does not support",
383 if ((ctrl & req) != req) {
384 decode_osc_control(root, "not requesting control; platform does not support",
389 capbuf[OSC_QUERY_DWORD] = 0;
390 capbuf[OSC_SUPPORT_DWORD] = root->osc_support_set;
391 capbuf[OSC_CONTROL_DWORD] = ctrl;
392 status = acpi_pci_run_osc(handle, capbuf, mask);
393 if (ACPI_FAILURE(status))
396 root->osc_control_set = *mask;
400 static void negotiate_os_control(struct acpi_pci_root *root, int *no_aspm,
403 u32 support, control, requested;
405 struct acpi_device *device = root->device;
406 acpi_handle handle = device->handle;
409 * Apple always return failure on _OSC calls when _OSI("Darwin") has
410 * been called successfully. We know the feature set supported by the
411 * platform, so avoid calling _OSC at all
413 if (x86_apple_machine) {
414 root->osc_control_set = ~OSC_PCI_EXPRESS_PME_CONTROL;
415 decode_osc_control(root, "OS assumes control of",
416 root->osc_control_set);
421 * All supported architectures that use ACPI have support for
422 * PCI domains, so we indicate this in _OSC support capabilities.
424 support = OSC_PCI_SEGMENT_GROUPS_SUPPORT;
425 support |= OSC_PCI_HPX_TYPE_3_SUPPORT;
426 if (pci_ext_cfg_avail())
427 support |= OSC_PCI_EXT_CONFIG_SUPPORT;
428 if (pcie_aspm_support_enabled())
429 support |= OSC_PCI_ASPM_SUPPORT | OSC_PCI_CLOCK_PM_SUPPORT;
430 if (pci_msi_enabled())
431 support |= OSC_PCI_MSI_SUPPORT;
432 if (IS_ENABLED(CONFIG_PCIE_EDR))
433 support |= OSC_PCI_EDR_SUPPORT;
435 decode_osc_support(root, "OS supports", support);
436 status = acpi_pci_osc_support(root, support);
437 if (ACPI_FAILURE(status)) {
440 /* _OSC is optional for PCI host bridges */
441 if ((status == AE_NOT_FOUND) && !is_pcie)
444 dev_info(&device->dev, "_OSC: platform retains control of PCIe features (%s)\n",
445 acpi_format_exception(status));
449 if (pcie_ports_disabled) {
450 dev_info(&device->dev, "PCIe port services disabled; not requesting _OSC control\n");
454 if ((support & ACPI_PCIE_REQ_SUPPORT) != ACPI_PCIE_REQ_SUPPORT) {
455 decode_osc_support(root, "not requesting OS control; OS requires",
456 ACPI_PCIE_REQ_SUPPORT);
460 control = OSC_PCI_EXPRESS_CAPABILITY_CONTROL
461 | OSC_PCI_EXPRESS_PME_CONTROL;
463 if (IS_ENABLED(CONFIG_PCIEASPM))
464 control |= OSC_PCI_EXPRESS_LTR_CONTROL;
466 if (IS_ENABLED(CONFIG_HOTPLUG_PCI_PCIE))
467 control |= OSC_PCI_EXPRESS_NATIVE_HP_CONTROL;
469 if (IS_ENABLED(CONFIG_HOTPLUG_PCI_SHPC))
470 control |= OSC_PCI_SHPC_NATIVE_HP_CONTROL;
472 if (pci_aer_available())
473 control |= OSC_PCI_EXPRESS_AER_CONTROL;
476 * Per the Downstream Port Containment Related Enhancements ECN to
477 * the PCI Firmware Spec, r3.2, sec 4.5.1, table 4-5,
478 * OSC_PCI_EXPRESS_DPC_CONTROL indicates the OS supports both DPC
481 if (IS_ENABLED(CONFIG_PCIE_DPC) && IS_ENABLED(CONFIG_PCIE_EDR))
482 control |= OSC_PCI_EXPRESS_DPC_CONTROL;
485 status = acpi_pci_osc_control_set(handle, &control,
486 OSC_PCI_EXPRESS_CAPABILITY_CONTROL);
487 if (ACPI_SUCCESS(status)) {
488 decode_osc_control(root, "OS now controls", control);
489 if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_ASPM) {
491 * We have ASPM control, but the FADT indicates that
492 * it's unsupported. Leave existing configuration
493 * intact and prevent the OS from touching it.
495 dev_info(&device->dev, "FADT indicates ASPM is unsupported, using BIOS configuration\n");
499 decode_osc_control(root, "OS requested", requested);
500 decode_osc_control(root, "platform willing to grant", control);
501 dev_info(&device->dev, "_OSC: platform retains control of PCIe features (%s)\n",
502 acpi_format_exception(status));
505 * We want to disable ASPM here, but aspm_disabled
506 * needs to remain in its state from boot so that we
507 * properly handle PCIe 1.1 devices. So we set this
508 * flag here, to defer the action until after the ACPI
515 static int acpi_pci_root_add(struct acpi_device *device,
516 const struct acpi_device_id *not_used)
518 unsigned long long segment, bus;
521 struct acpi_pci_root *root;
522 acpi_handle handle = device->handle;
524 bool hotadd = system_state == SYSTEM_RUNNING;
527 root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL);
532 status = acpi_evaluate_integer(handle, METHOD_NAME__SEG, NULL,
534 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
535 dev_err(&device->dev, "can't evaluate _SEG\n");
540 /* Check _CRS first, then _BBN. If no _BBN, default to zero. */
541 root->secondary.flags = IORESOURCE_BUS;
542 status = try_get_root_bridge_busnr(handle, &root->secondary);
543 if (ACPI_FAILURE(status)) {
545 * We need both the start and end of the downstream bus range
546 * to interpret _CBA (MMCONFIG base address), so it really is
547 * supposed to be in _CRS. If we don't find it there, all we
548 * can do is assume [_BBN-0xFF] or [0-0xFF].
550 root->secondary.end = 0xFF;
551 dev_warn(&device->dev,
552 FW_BUG "no secondary bus range in _CRS\n");
553 status = acpi_evaluate_integer(handle, METHOD_NAME__BBN,
555 if (ACPI_SUCCESS(status))
556 root->secondary.start = bus;
557 else if (status == AE_NOT_FOUND)
558 root->secondary.start = 0;
560 dev_err(&device->dev, "can't evaluate _BBN\n");
566 root->device = device;
567 root->segment = segment & 0xFFFF;
568 strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME);
569 strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS);
570 device->driver_data = root;
572 if (hotadd && dmar_device_add(handle)) {
577 pr_info(PREFIX "%s [%s] (domain %04x %pR)\n",
578 acpi_device_name(device), acpi_device_bid(device),
579 root->segment, &root->secondary);
581 root->mcfg_addr = acpi_pci_root_get_mcfg_addr(handle);
583 is_pcie = strcmp(acpi_device_hid(device), "PNP0A08") == 0;
584 negotiate_os_control(root, &no_aspm, is_pcie);
587 * TBD: Need PCI interface for enumeration/configuration of roots.
591 * Scan the Root Bridge
592 * --------------------
593 * Must do this prior to any attempt to bind the root device, as the
594 * PCI namespace does not get created until this call is made (and
595 * thus the root bridge's pci_dev does not exist).
597 root->bus = pci_acpi_scan_root(root);
599 dev_err(&device->dev,
600 "Bus %04x:%02x not present in PCI namespace\n",
601 root->segment, (unsigned int)root->secondary.start);
602 device->driver_data = NULL;
610 pci_acpi_add_bus_pm_notifier(device);
611 device_set_wakeup_capable(root->bus->bridge, device->wakeup.flags.valid);
614 pcibios_resource_survey_bus(root->bus);
615 pci_assign_unassigned_root_bus_resources(root->bus);
617 * This is only called for the hotadd case. For the boot-time
618 * case, we need to wait until after PCI initialization in
619 * order to deal with IOAPICs mapped in on a PCI BAR.
621 * This is currently x86-specific, because acpi_ioapic_add()
622 * is an empty function without CONFIG_ACPI_HOTPLUG_IOAPIC.
623 * And CONFIG_ACPI_HOTPLUG_IOAPIC depends on CONFIG_X86_IO_APIC
624 * (see drivers/acpi/Kconfig).
626 acpi_ioapic_add(root->device->handle);
629 pci_lock_rescan_remove();
630 pci_bus_add_devices(root->bus);
631 pci_unlock_rescan_remove();
636 dmar_device_remove(handle);
642 static void acpi_pci_root_remove(struct acpi_device *device)
644 struct acpi_pci_root *root = acpi_driver_data(device);
646 pci_lock_rescan_remove();
648 pci_stop_root_bus(root->bus);
650 pci_ioapic_remove(root);
651 device_set_wakeup_capable(root->bus->bridge, false);
652 pci_acpi_remove_bus_pm_notifier(device);
654 pci_remove_root_bus(root->bus);
655 WARN_ON(acpi_ioapic_remove(root));
657 dmar_device_remove(device->handle);
659 pci_unlock_rescan_remove();
665 * Following code to support acpi_pci_root_create() is copied from
666 * arch/x86/pci/acpi.c and modified so it could be reused by x86, IA64
669 static void acpi_pci_root_validate_resources(struct device *dev,
670 struct list_head *resources,
674 struct resource *res1, *res2, *root = NULL;
675 struct resource_entry *tmp, *entry, *entry2;
677 BUG_ON((type & (IORESOURCE_MEM | IORESOURCE_IO)) == 0);
678 root = (type & IORESOURCE_MEM) ? &iomem_resource : &ioport_resource;
680 list_splice_init(resources, &list);
681 resource_list_for_each_entry_safe(entry, tmp, &list) {
686 if (!(res1->flags & type))
689 /* Exclude non-addressable range or non-addressable portion */
690 end = min(res1->end, root->end);
691 if (end <= res1->start) {
692 dev_info(dev, "host bridge window %pR (ignored, not CPU addressable)\n",
696 } else if (res1->end != end) {
697 dev_info(dev, "host bridge window %pR ([%#llx-%#llx] ignored, not CPU addressable)\n",
698 res1, (unsigned long long)end + 1,
699 (unsigned long long)res1->end);
703 resource_list_for_each_entry(entry2, resources) {
705 if (!(res2->flags & type))
709 * I don't like throwing away windows because then
710 * our resources no longer match the ACPI _CRS, but
711 * the kernel resource tree doesn't allow overlaps.
713 if (resource_union(res1, res2, res2)) {
714 dev_info(dev, "host bridge window expanded to %pR; %pR ignored\n",
722 resource_list_del(entry);
724 resource_list_free_entry(entry);
726 resource_list_add_tail(entry, resources);
730 static void acpi_pci_root_remap_iospace(struct fwnode_handle *fwnode,
731 struct resource_entry *entry)
734 struct resource *res = entry->res;
735 resource_size_t cpu_addr = res->start;
736 resource_size_t pci_addr = cpu_addr - entry->offset;
737 resource_size_t length = resource_size(res);
740 if (pci_register_io_range(fwnode, cpu_addr, length))
743 port = pci_address_to_pio(cpu_addr);
744 if (port == (unsigned long)-1)
748 res->end = port + length - 1;
749 entry->offset = port - pci_addr;
751 if (pci_remap_iospace(res, cpu_addr) < 0)
754 pr_info("Remapped I/O %pa to %pR\n", &cpu_addr, res);
757 res->flags |= IORESOURCE_DISABLED;
761 int acpi_pci_probe_root_resources(struct acpi_pci_root_info *info)
764 struct list_head *list = &info->resources;
765 struct acpi_device *device = info->bridge;
766 struct resource_entry *entry, *tmp;
769 flags = IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_MEM_8AND16BIT;
770 ret = acpi_dev_get_resources(device, list,
771 acpi_dev_filter_resource_type_cb,
774 dev_warn(&device->dev,
775 "failed to parse _CRS method, error code %d\n", ret);
777 dev_dbg(&device->dev,
778 "no IO and memory resources present in _CRS\n");
780 resource_list_for_each_entry_safe(entry, tmp, list) {
781 if (entry->res->flags & IORESOURCE_IO)
782 acpi_pci_root_remap_iospace(&device->fwnode,
785 if (entry->res->flags & IORESOURCE_DISABLED)
786 resource_list_destroy_entry(entry);
788 entry->res->name = info->name;
790 acpi_pci_root_validate_resources(&device->dev, list,
792 acpi_pci_root_validate_resources(&device->dev, list,
799 static void pci_acpi_root_add_resources(struct acpi_pci_root_info *info)
801 struct resource_entry *entry, *tmp;
802 struct resource *res, *conflict, *root = NULL;
804 resource_list_for_each_entry_safe(entry, tmp, &info->resources) {
806 if (res->flags & IORESOURCE_MEM)
807 root = &iomem_resource;
808 else if (res->flags & IORESOURCE_IO)
809 root = &ioport_resource;
814 * Some legacy x86 host bridge drivers use iomem_resource and
815 * ioport_resource as default resource pool, skip it.
820 conflict = insert_resource_conflict(root, res);
822 dev_info(&info->bridge->dev,
823 "ignoring host bridge window %pR (conflicts with %s %pR)\n",
824 res, conflict->name, conflict);
825 resource_list_destroy_entry(entry);
830 static void __acpi_pci_root_release_info(struct acpi_pci_root_info *info)
832 struct resource *res;
833 struct resource_entry *entry, *tmp;
838 resource_list_for_each_entry_safe(entry, tmp, &info->resources) {
841 (res->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
842 release_resource(res);
843 resource_list_destroy_entry(entry);
846 info->ops->release_info(info);
849 static void acpi_pci_root_release_info(struct pci_host_bridge *bridge)
851 struct resource *res;
852 struct resource_entry *entry;
854 resource_list_for_each_entry(entry, &bridge->windows) {
856 if (res->flags & IORESOURCE_IO)
857 pci_unmap_iospace(res);
859 (res->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
860 release_resource(res);
862 __acpi_pci_root_release_info(bridge->release_data);
865 struct pci_bus *acpi_pci_root_create(struct acpi_pci_root *root,
866 struct acpi_pci_root_ops *ops,
867 struct acpi_pci_root_info *info,
870 int ret, busnum = root->secondary.start;
871 struct acpi_device *device = root->device;
872 int node = acpi_get_node(device->handle);
874 struct pci_host_bridge *host_bridge;
875 union acpi_object *obj;
878 info->bridge = device;
880 INIT_LIST_HEAD(&info->resources);
881 snprintf(info->name, sizeof(info->name), "PCI Bus %04x:%02x",
882 root->segment, busnum);
884 if (ops->init_info && ops->init_info(info))
885 goto out_release_info;
886 if (ops->prepare_resources)
887 ret = ops->prepare_resources(info);
889 ret = acpi_pci_probe_root_resources(info);
891 goto out_release_info;
893 pci_acpi_root_add_resources(info);
894 pci_add_resource(&info->resources, &root->secondary);
895 bus = pci_create_root_bus(NULL, busnum, ops->pci_ops,
896 sysdata, &info->resources);
898 goto out_release_info;
900 host_bridge = to_pci_host_bridge(bus->bridge);
901 if (!(root->osc_control_set & OSC_PCI_EXPRESS_NATIVE_HP_CONTROL))
902 host_bridge->native_pcie_hotplug = 0;
903 if (!(root->osc_control_set & OSC_PCI_SHPC_NATIVE_HP_CONTROL))
904 host_bridge->native_shpc_hotplug = 0;
905 if (!(root->osc_control_set & OSC_PCI_EXPRESS_AER_CONTROL))
906 host_bridge->native_aer = 0;
907 if (!(root->osc_control_set & OSC_PCI_EXPRESS_PME_CONTROL))
908 host_bridge->native_pme = 0;
909 if (!(root->osc_control_set & OSC_PCI_EXPRESS_LTR_CONTROL))
910 host_bridge->native_ltr = 0;
911 if (!(root->osc_control_set & OSC_PCI_EXPRESS_DPC_CONTROL))
912 host_bridge->native_dpc = 0;
915 * Evaluate the "PCI Boot Configuration" _DSM Function. If it
916 * exists and returns 0, we must preserve any PCI resource
917 * assignments made by firmware for this host bridge.
919 obj = acpi_evaluate_dsm(ACPI_HANDLE(bus->bridge), &pci_acpi_dsm_guid, 1,
920 DSM_PCI_PRESERVE_BOOT_CONFIG, NULL);
921 if (obj && obj->type == ACPI_TYPE_INTEGER && obj->integer.value == 0)
922 host_bridge->preserve_config = 1;
925 pci_scan_child_bus(bus);
926 pci_set_host_bridge_release(host_bridge, acpi_pci_root_release_info,
928 if (node != NUMA_NO_NODE)
929 dev_printk(KERN_DEBUG, &bus->dev, "on NUMA node %d\n", node);
933 __acpi_pci_root_release_info(info);
937 void __init acpi_pci_root_init(void)
940 if (acpi_pci_disabled)
943 pci_acpi_crs_quirks();
944 acpi_scan_add_handler_with_hotplug(&pci_root_handler, "pci_root");