]> rtime.felk.cvut.cz Git - can-eth-gw-linux.git/blobdiff - drivers/acpi/pci_root.c
Merge tag 'for-3.8' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci
[can-eth-gw-linux.git] / drivers / acpi / pci_root.c
index f70b9e5fc1b59098b530e58567bba2ae36ea99d3..7928d4dc705618a833ccce3172ed5113307d4cff 100644 (file)
@@ -454,6 +454,7 @@ static int acpi_pci_root_add(struct acpi_device *device)
        acpi_handle handle;
        struct acpi_device *child;
        u32 flags, base_flags;
+       bool is_osc_granted = false;
 
        root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL);
        if (!root)
@@ -501,52 +502,10 @@ static int acpi_pci_root_add(struct acpi_device *device)
        strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS);
        device->driver_data = root;
 
-       root->mcfg_addr = acpi_pci_root_get_mcfg_addr(device->handle);
-
-       /*
-        * All supported architectures that use ACPI have support for
-        * PCI domains, so we indicate this in _OSC support capabilities.
-        */
-       flags = base_flags = OSC_PCI_SEGMENT_GROUPS_SUPPORT;
-       acpi_pci_osc_support(root, flags);
-
-       /*
-        * TBD: Need PCI interface for enumeration/configuration of roots.
-        */
-
-       mutex_lock(&acpi_pci_root_lock);
-       list_add_tail(&root->node, &acpi_pci_roots);
-       mutex_unlock(&acpi_pci_root_lock);
-
        printk(KERN_INFO PREFIX "%s [%s] (domain %04x %pR)\n",
               acpi_device_name(device), acpi_device_bid(device),
               root->segment, &root->secondary);
 
-       /*
-        * Scan the Root Bridge
-        * --------------------
-        * Must do this prior to any attempt to bind the root device, as the
-        * PCI namespace does not get created until this call is made (and 
-        * thus the root bridge's pci_dev does not exist).
-        */
-       root->bus = pci_acpi_scan_root(root);
-       if (!root->bus) {
-               printk(KERN_ERR PREFIX
-                           "Bus %04x:%02x not present in PCI namespace\n",
-                           root->segment, (unsigned int)root->secondary.start);
-               result = -ENODEV;
-               goto out_del_root;
-       }
-
-       /*
-        * Attach ACPI-PCI Context
-        * -----------------------
-        * Thus binding the ACPI and PCI devices.
-        */
-       result = acpi_pci_bind_root(device);
-       if (result)
-               goto out_del_root;
-
        /*
         * PCI Routing Table
         * -----------------
@@ -554,32 +513,36 @@ static int acpi_pci_root_add(struct acpi_device *device)
         */
        status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
        if (ACPI_SUCCESS(status))
-               result = acpi_pci_irq_add_prt(device->handle, root->bus);
+               result = acpi_pci_irq_add_prt(device->handle, root->segment,
+                                             root->secondary.start);
+
+       root->mcfg_addr = acpi_pci_root_get_mcfg_addr(device->handle);
 
        /*
-        * Scan and bind all _ADR-Based Devices
+        * All supported architectures that use ACPI have support for
+        * PCI domains, so we indicate this in _OSC support capabilities.
         */
-       list_for_each_entry(child, &device->children, node)
-               acpi_pci_bridge_scan(child);
+       flags = base_flags = OSC_PCI_SEGMENT_GROUPS_SUPPORT;
+       acpi_pci_osc_support(root, flags);
 
        /* Indicate support for various _OSC capabilities. */
-       if (pci_ext_cfg_avail(root->bus->self))
+       if (pci_ext_cfg_avail())
                flags |= OSC_EXT_PCI_CONFIG_SUPPORT;
-       if (pcie_aspm_support_enabled())
+       if (pcie_aspm_support_enabled()) {
                flags |= OSC_ACTIVE_STATE_PWR_SUPPORT |
-                       OSC_CLOCK_PWR_CAPABILITY_SUPPORT;
+               OSC_CLOCK_PWR_CAPABILITY_SUPPORT;
+       }
        if (pci_msi_enabled())
                flags |= OSC_MSI_SUPPORT;
        if (flags != base_flags) {
                status = acpi_pci_osc_support(root, flags);
                if (ACPI_FAILURE(status)) {
-                       dev_info(root->bus->bridge, "ACPI _OSC support "
+                       dev_info(&device->dev, "ACPI _OSC support "
                                "notification failed, disabling PCIe ASPM\n");
                        pcie_no_aspm();
                        flags = base_flags;
                }
        }
-
        if (!pcie_ports_disabled
            && (flags & ACPI_PCIE_REQ_SUPPORT) == ACPI_PCIE_REQ_SUPPORT) {
                flags = OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL
@@ -588,40 +551,81 @@ static int acpi_pci_root_add(struct acpi_device *device)
 
                if (pci_aer_available()) {
                        if (aer_acpi_firmware_first())
-                               dev_dbg(root->bus->bridge,
+                               dev_dbg(&device->dev,
                                        "PCIe errors handled by BIOS.\n");
                        else
                                flags |= OSC_PCI_EXPRESS_AER_CONTROL;
                }
 
-               dev_info(root->bus->bridge,
+               dev_info(&device->dev,
                        "Requesting ACPI _OSC control (0x%02x)\n", flags);
 
                status = acpi_pci_osc_control_set(device->handle, &flags,
-                                       OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL);
+                                      OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL);
                if (ACPI_SUCCESS(status)) {
-                       dev_info(root->bus->bridge,
+                       is_osc_granted = true;
+                       dev_info(&device->dev,
                                "ACPI _OSC control (0x%02x) granted\n", flags);
-                       if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_ASPM) {
-                               /*
-                                * We have ASPM control, but the FADT indicates
-                                * that it's unsupported. Clear it.
-                                */
-                               pcie_clear_aspm(root->bus);
-                       }
                } else {
-                       dev_info(root->bus->bridge,
+                       is_osc_granted = false;
+                       dev_info(&device->dev,
                                "ACPI _OSC request failed (%s), "
                                "returned control mask: 0x%02x\n",
                                acpi_format_exception(status), flags);
-                       pr_info("ACPI _OSC control for PCIe not granted, "
-                               "disabling ASPM\n");
-                       pcie_no_aspm();
                }
        } else {
-               dev_info(root->bus->bridge,
-                        "Unable to request _OSC control "
-                        "(_OSC support mask: 0x%02x)\n", flags);
+               dev_info(&device->dev,
+                       "Unable to request _OSC control "
+                       "(_OSC support mask: 0x%02x)\n", flags);
+       }
+
+       /*
+        * TBD: Need PCI interface for enumeration/configuration of roots.
+        */
+
+       mutex_lock(&acpi_pci_root_lock);
+       list_add_tail(&root->node, &acpi_pci_roots);
+       mutex_unlock(&acpi_pci_root_lock);
+
+       /*
+        * Scan the Root Bridge
+        * --------------------
+        * Must do this prior to any attempt to bind the root device, as the
+        * PCI namespace does not get created until this call is made (and 
+        * thus the root bridge's pci_dev does not exist).
+        */
+       root->bus = pci_acpi_scan_root(root);
+       if (!root->bus) {
+               printk(KERN_ERR PREFIX
+                           "Bus %04x:%02x not present in PCI namespace\n",
+                           root->segment, (unsigned int)root->secondary.start);
+               result = -ENODEV;
+               goto out_del_root;
+       }
+
+       /*
+        * Attach ACPI-PCI Context
+        * -----------------------
+        * Thus binding the ACPI and PCI devices.
+        */
+       result = acpi_pci_bind_root(device);
+       if (result)
+               goto out_del_root;
+
+       /*
+        * Scan and bind all _ADR-Based Devices
+        */
+       list_for_each_entry(child, &device->children, node)
+               acpi_pci_bridge_scan(child);
+
+       /* ASPM setting */
+       if (is_osc_granted) {
+               if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_ASPM)
+                       pcie_clear_aspm(root->bus);
+       } else {
+               pr_info("ACPI _OSC control for PCIe not granted, "
+                       "disabling ASPM\n");
+               pcie_no_aspm();
        }
 
        pci_acpi_add_bus_pm_notifier(device, root->bus);
@@ -634,6 +638,8 @@ out_del_root:
        mutex_lock(&acpi_pci_root_lock);
        list_del(&root->node);
        mutex_unlock(&acpi_pci_root_lock);
+
+       acpi_pci_irq_del_prt(root->segment, root->secondary.start);
 end:
        kfree(root);
        return result;
@@ -644,12 +650,19 @@ static int acpi_pci_root_start(struct acpi_device *device)
        struct acpi_pci_root *root = acpi_driver_data(device);
        struct acpi_pci_driver *driver;
 
+       if (system_state != SYSTEM_BOOTING)
+               pci_assign_unassigned_bus_resources(root->bus);
+
        mutex_lock(&acpi_pci_root_lock);
        list_for_each_entry(driver, &acpi_pci_drivers, node)
                if (driver->add)
                        driver->add(root);
        mutex_unlock(&acpi_pci_root_lock);
 
+       /* need to after hot-added ioapic is registered */
+       if (system_state != SYSTEM_BOOTING)
+               pci_enable_bridges(root->bus);
+
        pci_bus_add_devices(root->bus);
 
        return 0;
@@ -657,17 +670,29 @@ static int acpi_pci_root_start(struct acpi_device *device)
 
 static int acpi_pci_root_remove(struct acpi_device *device, int type)
 {
+       acpi_status status;
+       acpi_handle handle;
        struct acpi_pci_root *root = acpi_driver_data(device);
        struct acpi_pci_driver *driver;
 
+       pci_stop_root_bus(root->bus);
+
        mutex_lock(&acpi_pci_root_lock);
-       list_for_each_entry(driver, &acpi_pci_drivers, node)
+       list_for_each_entry_reverse(driver, &acpi_pci_drivers, node)
                if (driver->remove)
                        driver->remove(root);
+       mutex_unlock(&acpi_pci_root_lock);
 
        device_set_run_wake(root->bus->bridge, false);
        pci_acpi_remove_bus_pm_notifier(device);
 
+       status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
+       if (ACPI_SUCCESS(status))
+               acpi_pci_irq_del_prt(root->segment, root->secondary.start);
+
+       pci_remove_root_bus(root->bus);
+
+       mutex_lock(&acpi_pci_root_lock);
        list_del(&root->node);
        mutex_unlock(&acpi_pci_root_lock);
        kfree(root);