]> Pileus Git - ~andy/linux/blobdiff - drivers/acpi/pci_root.c
Merge back earlier acpi-hotplug material.
[~andy/linux] / drivers / acpi / pci_root.c
index 3e06d4e179ecf7828ef2a1a37ef8afcac79776b4..20360e480bd8d81c0070cc25b5cd2cddd05d0447 100644 (file)
@@ -39,6 +39,8 @@
 #include <acpi/acpi_drivers.h>
 #include <acpi/apei.h>
 
+#include "internal.h"
+
 #define PREFIX "ACPI: "
 
 #define _COMPONENT             ACPI_PCI_COMPONENT
@@ -63,6 +65,9 @@ static struct acpi_scan_handler pci_root_handler = {
        .ids = root_device_ids,
        .attach = acpi_pci_root_add,
        .detach = acpi_pci_root_remove,
+       .hotplug = {
+               .ignore = true,
+       },
 };
 
 static DEFINE_MUTEX(osc_lock);
@@ -127,6 +132,55 @@ static acpi_status try_get_root_bridge_busnr(acpi_handle handle,
        return AE_OK;
 }
 
+struct pci_osc_bit_struct {
+       u32 bit;
+       char *desc;
+};
+
+static struct pci_osc_bit_struct pci_osc_support_bit[] = {
+       { OSC_PCI_EXT_CONFIG_SUPPORT, "ExtendedConfig" },
+       { OSC_PCI_ASPM_SUPPORT, "ASPM" },
+       { OSC_PCI_CLOCK_PM_SUPPORT, "ClockPM" },
+       { OSC_PCI_SEGMENT_GROUPS_SUPPORT, "Segments" },
+       { OSC_PCI_MSI_SUPPORT, "MSI" },
+};
+
+static struct pci_osc_bit_struct pci_osc_control_bit[] = {
+       { OSC_PCI_EXPRESS_NATIVE_HP_CONTROL, "PCIeHotplug" },
+       { OSC_PCI_SHPC_NATIVE_HP_CONTROL, "SHPCHotplug" },
+       { OSC_PCI_EXPRESS_PME_CONTROL, "PME" },
+       { OSC_PCI_EXPRESS_AER_CONTROL, "AER" },
+       { OSC_PCI_EXPRESS_CAPABILITY_CONTROL, "PCIeCapability" },
+};
+
+static void decode_osc_bits(struct acpi_pci_root *root, char *msg, u32 word,
+                           struct pci_osc_bit_struct *table, int size)
+{
+       char buf[80];
+       int i, len = 0;
+       struct pci_osc_bit_struct *entry;
+
+       buf[0] = '\0';
+       for (i = 0, entry = table; i < size; i++, entry++)
+               if (word & entry->bit)
+                       len += snprintf(buf + len, sizeof(buf) - len, "%s%s",
+                                       len ? " " : "", entry->desc);
+
+       dev_info(&root->device->dev, "_OSC: %s [%s]\n", msg, buf);
+}
+
+static void decode_osc_support(struct acpi_pci_root *root, char *msg, u32 word)
+{
+       decode_osc_bits(root, msg, word, pci_osc_support_bit,
+                       ARRAY_SIZE(pci_osc_support_bit));
+}
+
+static void decode_osc_control(struct acpi_pci_root *root, char *msg, u32 word)
+{
+       decode_osc_bits(root, msg, word, pci_osc_control_bit,
+                       ARRAY_SIZE(pci_osc_control_bit));
+}
+
 static u8 pci_osc_uuid_str[] = "33DB4D5B-1FF7-401C-9657-7441C03DD766";
 
 static acpi_status acpi_pci_run_osc(acpi_handle handle,
@@ -340,10 +394,14 @@ acpi_status acpi_pci_osc_control_set(acpi_handle handle, u32 *mask, u32 req)
                        goto out;
                if (ctrl == *mask)
                        break;
+               decode_osc_control(root, "platform does not support",
+                                  ctrl & ~(*mask));
                ctrl = *mask;
        }
 
        if ((ctrl & req) != req) {
+               decode_osc_control(root, "not requesting control; platform does not support",
+                                  req & ~(ctrl));
                status = AE_SUPPORT;
                goto out;
        }
@@ -363,7 +421,7 @@ EXPORT_SYMBOL(acpi_pci_osc_control_set);
 static void negotiate_os_control(struct acpi_pci_root *root, int *no_aspm,
                                 int *clear_aspm)
 {
-       u32 support, base_support, control;
+       u32 support, control, requested;
        acpi_status status;
        struct acpi_device *device = root->device;
        acpi_handle handle = device->handle;
@@ -372,76 +430,72 @@ static void negotiate_os_control(struct acpi_pci_root *root, int *no_aspm,
         * All supported architectures that use ACPI have support for
         * PCI domains, so we indicate this in _OSC support capabilities.
         */
-       support = base_support = OSC_PCI_SEGMENT_GROUPS_SUPPORT;
-       acpi_pci_osc_support(root, support);
-
+       support = OSC_PCI_SEGMENT_GROUPS_SUPPORT;
        if (pci_ext_cfg_avail())
                support |= OSC_PCI_EXT_CONFIG_SUPPORT;
-       if (pcie_aspm_support_enabled()) {
+       if (pcie_aspm_support_enabled())
                support |= OSC_PCI_ASPM_SUPPORT | OSC_PCI_CLOCK_PM_SUPPORT;
-       }
        if (pci_msi_enabled())
                support |= OSC_PCI_MSI_SUPPORT;
-       if (support != base_support) {
-               status = acpi_pci_osc_support(root, support);
-               if (ACPI_FAILURE(status)) {
-                       dev_info(&device->dev, "ACPI _OSC support "
-                               "notification failed, disabling PCIe ASPM\n");
-                       *no_aspm = 1;
-                       support = base_support;
-               }
+
+       decode_osc_support(root, "OS supports", support);
+       status = acpi_pci_osc_support(root, support);
+       if (ACPI_FAILURE(status)) {
+               dev_info(&device->dev, "_OSC failed (%s); disabling ASPM\n",
+                        acpi_format_exception(status));
+               *no_aspm = 1;
+               return;
        }
 
-       if (!pcie_ports_disabled
-           && (support & ACPI_PCIE_REQ_SUPPORT) == ACPI_PCIE_REQ_SUPPORT) {
-               control = OSC_PCI_EXPRESS_CAPABILITY_CONTROL
-                       | OSC_PCI_EXPRESS_NATIVE_HP_CONTROL
-                       | OSC_PCI_EXPRESS_PME_CONTROL;
-
-               if (pci_aer_available()) {
-                       if (aer_acpi_firmware_first())
-                               dev_dbg(&device->dev,
-                                       "PCIe errors handled by BIOS.\n");
-                       else
-                               control |= OSC_PCI_EXPRESS_AER_CONTROL;
-               }
+       if (pcie_ports_disabled) {
+               dev_info(&device->dev, "PCIe port services disabled; not requesting _OSC control\n");
+               return;
+       }
+
+       if ((support & ACPI_PCIE_REQ_SUPPORT) != ACPI_PCIE_REQ_SUPPORT) {
+               decode_osc_support(root, "not requesting OS control; OS requires",
+                                  ACPI_PCIE_REQ_SUPPORT);
+               return;
+       }
 
-               dev_info(&device->dev,
-                       "Requesting ACPI _OSC control (0x%02x)\n", control);
+       control = OSC_PCI_EXPRESS_CAPABILITY_CONTROL
+               | OSC_PCI_EXPRESS_NATIVE_HP_CONTROL
+               | OSC_PCI_EXPRESS_PME_CONTROL;
 
-               status = acpi_pci_osc_control_set(handle, &control,
-                                      OSC_PCI_EXPRESS_CAPABILITY_CONTROL);
-               if (ACPI_SUCCESS(status)) {
-                       dev_info(&device->dev,
-                               "ACPI _OSC control (0x%02x) granted\n",
-                               control);
-                       if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_ASPM) {
-                               /*
-                                * We have ASPM control, but the FADT indicates
-                                * that it's unsupported. Clear it.
-                                */
-                               *clear_aspm = 1;
-                       }
-               } else {
+       if (pci_aer_available()) {
+               if (aer_acpi_firmware_first())
                        dev_info(&device->dev,
-                               "ACPI _OSC request failed (%s), "
-                               "returned control mask: 0x%02x\n",
-                               acpi_format_exception(status), control);
-                       dev_info(&device->dev,
-                                "ACPI _OSC control for PCIe not granted, disabling ASPM\n");
+                                "PCIe AER handled by firmware\n");
+               else
+                       control |= OSC_PCI_EXPRESS_AER_CONTROL;
+       }
+
+       requested = control;
+       status = acpi_pci_osc_control_set(handle, &control,
+                                         OSC_PCI_EXPRESS_CAPABILITY_CONTROL);
+       if (ACPI_SUCCESS(status)) {
+               decode_osc_control(root, "OS now controls", control);
+               if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_ASPM) {
                        /*
-                        * We want to disable ASPM here, but aspm_disabled
-                        * needs to remain in its state from boot so that we
-                        * properly handle PCIe 1.1 devices.  So we set this
-                        * flag here, to defer the action until after the ACPI
-                        * root scan.
+                        * We have ASPM control, but the FADT indicates
+                        * that it's unsupported. Clear it.
                         */
-                       *no_aspm = 1;
+                       *clear_aspm = 1;
                }
        } else {
-               dev_info(&device->dev,
-                        "Unable to request _OSC control "
-                        "(_OSC support mask: 0x%02x)\n", support);
+               decode_osc_control(root, "OS requested", requested);
+               decode_osc_control(root, "platform willing to grant", control);
+               dev_info(&device->dev, "_OSC failed (%s); disabling ASPM\n",
+                       acpi_format_exception(status));
+
+               /*
+                * We want to disable ASPM here, but aspm_disabled
+                * needs to remain in its state from boot so that we
+                * properly handle PCIe 1.1 devices.  So we set this
+                * flag here, to defer the action until after the ACPI
+                * root scan.
+                */
+               *no_aspm = 1;
        }
 }
 
@@ -524,6 +578,7 @@ static int acpi_pci_root_add(struct acpi_device *device,
                dev_err(&device->dev,
                        "Bus %04x:%02x not present in PCI namespace\n",
                        root->segment, (unsigned int)root->secondary.start);
+               device->driver_data = NULL;
                result = -ENODEV;
                goto end;
        }
@@ -591,39 +646,10 @@ static void handle_root_bridge_insertion(acpi_handle handle)
                acpi_handle_err(handle, "cannot add bridge to acpi list\n");
 }
 
-static void handle_root_bridge_removal(struct acpi_device *device)
-{
-       acpi_status status;
-       struct acpi_eject_event *ej_event;
-
-       ej_event = kmalloc(sizeof(*ej_event), GFP_KERNEL);
-       if (!ej_event) {
-               /* Inform firmware the hot-remove operation has error */
-               (void) acpi_evaluate_hotplug_ost(device->handle,
-                                       ACPI_NOTIFY_EJECT_REQUEST,
-                                       ACPI_OST_SC_NON_SPECIFIC_FAILURE,
-                                       NULL);
-               return;
-       }
-
-       ej_event->device = device;
-       ej_event->event = ACPI_NOTIFY_EJECT_REQUEST;
-
-       status = acpi_os_hotplug_execute(acpi_bus_hot_remove_device, ej_event);
-       if (ACPI_FAILURE(status))
-               kfree(ej_event);
-}
-
-static void _handle_hotplug_event_root(struct work_struct *work)
+static void hotplug_event_root(void *data, u32 type)
 {
+       acpi_handle handle = data;
        struct acpi_pci_root *root;
-       struct acpi_hp_work *hp_work;
-       acpi_handle handle;
-       u32 type;
-
-       hp_work = container_of(work, struct acpi_hp_work, work);
-       handle = hp_work->handle;
-       type = hp_work->type;
 
        acpi_scan_lock_acquire();
 
@@ -653,9 +679,15 @@ static void _handle_hotplug_event_root(struct work_struct *work)
                /* request device eject */
                acpi_handle_printk(KERN_DEBUG, handle,
                                   "Device eject notify on %s\n", __func__);
-               if (root)
-                       handle_root_bridge_removal(root->device);
-               break;
+               if (!root)
+                       break;
+
+               get_device(&root->device->dev);
+
+               acpi_scan_lock_release();
+
+               acpi_bus_device_eject(root->device, ACPI_NOTIFY_EJECT_REQUEST);
+               return;
        default:
                acpi_handle_warn(handle,
                                 "notify_handler: unknown event type 0x%x\n",
@@ -664,14 +696,12 @@ static void _handle_hotplug_event_root(struct work_struct *work)
        }
 
        acpi_scan_lock_release();
-       kfree(hp_work); /* allocated in handle_hotplug_event_bridge */
 }
 
 static void handle_hotplug_event_root(acpi_handle handle, u32 type,
                                        void *context)
 {
-       alloc_acpi_hp_work(handle, type, context,
-                               _handle_hotplug_event_root);
+       acpi_hotplug_execute(hotplug_event_root, handle, type);
 }
 
 static acpi_status __init