Merge back earlier acpi-hotplug material.
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 22 Nov 2013 20:48:00 +0000 (21:48 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 22 Nov 2013 20:48:00 +0000 (21:48 +0100)
1  2 
drivers/acpi/pci_root.c
drivers/acpi/scan.c
include/acpi/acpi_bus.h

diff --combined drivers/acpi/pci_root.c
@@@ -51,10 -51,10 +51,10 @@@ static int acpi_pci_root_add(struct acp
                             const struct acpi_device_id *not_used);
  static void acpi_pci_root_remove(struct acpi_device *device);
  
 -#define ACPI_PCIE_REQ_SUPPORT (OSC_EXT_PCI_CONFIG_SUPPORT \
 -                              | OSC_ACTIVE_STATE_PWR_SUPPORT \
 -                              | OSC_CLOCK_PWR_CAPABILITY_SUPPORT \
 -                              | OSC_MSI_SUPPORT)
 +#define ACPI_PCIE_REQ_SUPPORT (OSC_PCI_EXT_CONFIG_SUPPORT \
 +                              | OSC_PCI_ASPM_SUPPORT \
 +                              | OSC_PCI_CLOCK_PM_SUPPORT \
 +                              | OSC_PCI_MSI_SUPPORT)
  
  static const struct acpi_device_id root_device_ids[] = {
        {"PNP0A03", 0},
@@@ -65,6 -65,9 +65,9 @@@ static struct acpi_scan_handler pci_roo
        .ids = root_device_ids,
        .attach = acpi_pci_root_add,
        .detach = acpi_pci_root_remove,
+       .hotplug = {
+               .ignore = true,
+       },
  };
  
  static DEFINE_MUTEX(osc_lock);
@@@ -129,55 -132,6 +132,55 @@@ static acpi_status try_get_root_bridge_
        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,
@@@ -209,14 -163,14 +212,14 @@@ static acpi_status acpi_pci_query_osc(s
        support &= OSC_PCI_SUPPORT_MASKS;
        support |= root->osc_support_set;
  
 -      capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
 -      capbuf[OSC_SUPPORT_TYPE] = support;
 +      capbuf[OSC_QUERY_DWORD] = OSC_QUERY_ENABLE;
 +      capbuf[OSC_SUPPORT_DWORD] = support;
        if (control) {
                *control &= OSC_PCI_CONTROL_MASKS;
 -              capbuf[OSC_CONTROL_TYPE] = *control | root->osc_control_set;
 +              capbuf[OSC_CONTROL_DWORD] = *control | root->osc_control_set;
        } else {
                /* Run _OSC query only with existing controls. */
 -              capbuf[OSC_CONTROL_TYPE] = root->osc_control_set;
 +              capbuf[OSC_CONTROL_DWORD] = root->osc_control_set;
        }
  
        status = acpi_pci_run_osc(root->device->handle, capbuf, &result);
  static acpi_status acpi_pci_osc_support(struct acpi_pci_root *root, u32 flags)
  {
        acpi_status status;
 -      acpi_handle tmp;
  
 -      status = acpi_get_handle(root->device->handle, "_OSC", &tmp);
 -      if (ACPI_FAILURE(status))
 -              return status;
        mutex_lock(&osc_lock);
        status = acpi_pci_query_osc(root, flags, NULL);
        mutex_unlock(&osc_lock);
@@@ -363,8 -321,9 +366,8 @@@ EXPORT_SYMBOL_GPL(acpi_get_pci_dev)
  acpi_status acpi_pci_osc_control_set(acpi_handle handle, u32 *mask, u32 req)
  {
        struct acpi_pci_root *root;
 -      acpi_status status;
 +      acpi_status status = AE_OK;
        u32 ctrl, capbuf[3];
 -      acpi_handle tmp;
  
        if (!mask)
                return AE_BAD_PARAMETER;
        if (!root)
                return AE_NOT_EXIST;
  
 -      status = acpi_get_handle(handle, "_OSC", &tmp);
 -      if (ACPI_FAILURE(status))
 -              return status;
 -
        mutex_lock(&osc_lock);
  
        *mask = ctrl | root->osc_control_set;
                        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;
        }
  
 -      capbuf[OSC_QUERY_TYPE] = 0;
 -      capbuf[OSC_SUPPORT_TYPE] = root->osc_support_set;
 -      capbuf[OSC_CONTROL_TYPE] = ctrl;
 +      capbuf[OSC_QUERY_DWORD] = 0;
 +      capbuf[OSC_SUPPORT_DWORD] = root->osc_support_set;
 +      capbuf[OSC_CONTROL_DWORD] = ctrl;
        status = acpi_pci_run_osc(handle, capbuf, mask);
        if (ACPI_SUCCESS(status))
                root->osc_control_set = *mask;
@@@ -415,87 -374,6 +418,87 @@@ out
  }
  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, control, requested;
 +      acpi_status status;
 +      struct acpi_device *device = root->device;
 +      acpi_handle handle = device->handle;
 +
 +      /*
 +       * All supported architectures that use ACPI have support for
 +       * PCI domains, so we indicate this in _OSC support capabilities.
 +       */
 +      support = OSC_PCI_SEGMENT_GROUPS_SUPPORT;
 +      if (pci_ext_cfg_avail())
 +              support |= OSC_PCI_EXT_CONFIG_SUPPORT;
 +      if (pcie_aspm_support_enabled())
 +              support |= OSC_PCI_ASPM_SUPPORT | OSC_PCI_CLOCK_PM_SUPPORT;
 +      if (pci_msi_enabled())
 +              support |= OSC_PCI_MSI_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) {
 +              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;
 +      }
 +
 +      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_info(&device->dev,
 +                               "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 have ASPM control, but the FADT indicates
 +                       * that it's unsupported. Clear it.
 +                       */
 +                      *clear_aspm = 1;
 +              }
 +      } else {
 +              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;
 +      }
 +}
 +
  static int acpi_pci_root_add(struct acpi_device *device,
                             const struct acpi_device_id *not_used)
  {
        acpi_status status;
        int result;
        struct acpi_pci_root *root;
 -      u32 flags, base_flags;
        acpi_handle handle = device->handle;
 -      bool no_aspm = false, clear_aspm = false;
 +      int no_aspm = 0, clear_aspm = 0;
  
        root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL);
        if (!root)
  
        root->mcfg_addr = acpi_pci_root_get_mcfg_addr(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);
 -
 -      if (pci_ext_cfg_avail())
 -              flags |= OSC_EXT_PCI_CONFIG_SUPPORT;
 -      if (pcie_aspm_support_enabled()) {
 -              flags |= OSC_ACTIVE_STATE_PWR_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(&device->dev, "ACPI _OSC support "
 -                              "notification failed, disabling PCIe ASPM\n");
 -                      no_aspm = true;
 -                      flags = base_flags;
 -              }
 -      }
 -
 -      if (!pcie_ports_disabled
 -          && (flags & ACPI_PCIE_REQ_SUPPORT) == ACPI_PCIE_REQ_SUPPORT) {
 -              flags = OSC_PCI_EXPRESS_CAP_STRUCTURE_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
 -                              flags |= OSC_PCI_EXPRESS_AER_CONTROL;
 -              }
 -
 -              dev_info(&device->dev,
 -                      "Requesting ACPI _OSC control (0x%02x)\n", flags);
 -
 -              status = acpi_pci_osc_control_set(handle, &flags,
 -                                     OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL);
 -              if (ACPI_SUCCESS(status)) {
 -                      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.
 -                               */
 -                              clear_aspm = true;
 -                      }
 -              } else {
 -                      dev_info(&device->dev,
 -                              "ACPI _OSC request failed (%s), "
 -                              "returned control mask: 0x%02x\n",
 -                              acpi_format_exception(status), flags);
 -                      dev_info(&device->dev,
 -                               "ACPI _OSC control for PCIe not granted, disabling ASPM\n");
 -                      /*
 -                       * 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 = true;
 -              }
 -      } else {
 -              dev_info(&device->dev,
 -                       "Unable to request _OSC control "
 -                       "(_OSC support mask: 0x%02x)\n", flags);
 -      }
 +      negotiate_os_control(root, &no_aspm, &clear_aspm);
  
        /*
         * TBD: Need PCI interface for enumeration/configuration of roots.
diff --combined drivers/acpi/scan.c
@@@ -927,7 -927,7 +927,7 @@@ int acpi_bus_get_device(acpi_handle han
        }
        return 0;
  }
 -EXPORT_SYMBOL_GPL(acpi_bus_get_device);
 +EXPORT_SYMBOL(acpi_bus_get_device);
  
  int acpi_device_add(struct acpi_device *device,
                    void (*release)(struct device *))
        INIT_LIST_HEAD(&device->wakeup_list);
        INIT_LIST_HEAD(&device->physical_node_list);
        mutex_init(&device->physical_node_lock);
 -      INIT_LIST_HEAD(&device->power_dependent);
  
        new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL);
        if (!new_bus_id) {
@@@ -1079,7 -1080,7 +1079,7 @@@ int acpi_bus_register_driver(struct acp
  EXPORT_SYMBOL(acpi_bus_register_driver);
  
  /**
 - * acpi_bus_unregister_driver - unregisters a driver with the APIC bus
 + * acpi_bus_unregister_driver - unregisters a driver with the ACPI bus
   * @driver: driver to unregister
   *
   * Unregisters a driver with the ACPI bus.  Searches the namespace for all
@@@ -1772,7 -1773,7 +1772,7 @@@ static void acpi_scan_init_hotplug(acpi
         */
        list_for_each_entry(hwid, &pnp.ids, list) {
                handler = acpi_scan_match_handler(hwid->id, NULL);
-               if (handler) {
+               if (handler && !handler->hotplug.ignore) {
                        acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
                                        acpi_hotplug_notify_cb, handler);
                        break;
diff --combined include/acpi/acpi_bus.h
@@@ -100,6 -100,7 +100,7 @@@ enum acpi_hotplug_mode 
  struct acpi_hotplug_profile {
        struct kobject kobj;
        bool enabled:1;
+       bool ignore:1;
        enum acpi_hotplug_mode mode;
  };
  
@@@ -222,8 -223,7 +223,8 @@@ struct acpi_device_power_flags 
        u32 power_resources:1;  /* Power resources */
        u32 inrush_current:1;   /* Serialize Dx->D0 */
        u32 power_removed:1;    /* Optimize Dx->D0 */
 -      u32 reserved:28;
 +      u32 ignore_parent:1;    /* Power is independent of parent power state */
 +      u32 reserved:27;
  };
  
  struct acpi_device_power_state {
@@@ -312,6 -312,7 +313,6 @@@ struct acpi_device 
        unsigned int physical_node_count;
        struct list_head physical_node_list;
        struct mutex physical_node_lock;
 -      struct list_head power_dependent;
        void (*remove)(struct acpi_device *);
  };
  
@@@ -431,9 -432,9 +432,9 @@@ static inline acpi_handle acpi_get_chil
  {
        return acpi_find_child(handle, addr, false);
  }
 +void acpi_preset_companion(struct device *dev, acpi_handle parent, u64 addr);
  int acpi_is_root_bridge(acpi_handle);
  struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle);
 -#define DEVICE_ACPI_HANDLE(dev) ((acpi_handle)ACPI_HANDLE(dev))
  
  int acpi_enable_wakeup_device_power(struct acpi_device *dev, int state);
  int acpi_disable_wakeup_device_power(struct acpi_device *dev);
@@@ -444,6 -445,8 +445,6 @@@ acpi_status acpi_add_pm_notifier(struc
  acpi_status acpi_remove_pm_notifier(struct acpi_device *adev,
                                    acpi_notify_handler handler);
  int acpi_pm_device_sleep_state(struct device *, int *, int);
 -void acpi_dev_pm_add_dependent(acpi_handle handle, struct device *depdev);
 -void acpi_dev_pm_remove_dependent(acpi_handle handle, struct device *depdev);
  #else
  static inline acpi_status acpi_add_pm_notifier(struct acpi_device *adev,
                                               acpi_notify_handler handler,
@@@ -464,6 -467,10 +465,6 @@@ static inline int acpi_pm_device_sleep_
        return (m >= ACPI_STATE_D0 && m <= ACPI_STATE_D3_COLD) ?
                m : ACPI_STATE_D0;
  }
 -static inline void acpi_dev_pm_add_dependent(acpi_handle handle,
 -                                           struct device *depdev) {}
 -static inline void acpi_dev_pm_remove_dependent(acpi_handle handle,
 -                                              struct device *depdev) {}
  #endif
  
  #ifdef CONFIG_PM_RUNTIME