Commit 75fb60f2 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki Committed by Jesse Barnes

ACPI/PCI: Negotiate _OSC control bits before requesting them

It is possible that the BIOS will not grant control of all _OSC
features requested via acpi_pci_osc_control_set(), so it is
recommended to negotiate the final set of _OSC features with the
query flag set before calling _OSC to request control of these
features.

To implement it, rework acpi_pci_osc_control_set() so that the caller
can specify the mask of _OSC control bits to negotiate and the mask
of _OSC control bits that are absolutely necessary to it.  Then,
acpi_pci_osc_control_set() will run _OSC queries in a loop until
the mask of _OSC control bits returned by the BIOS is equal to the
mask passed to it.  Also, before running the _OSC request
acpi_pci_osc_control_set() will check if the caller's required
control bits are present in the final mask.

Using this mechanism we will be able to avoid situations in which the
BIOS doesn't grant control of certain _OSC features, because they
depend on some other _OSC features that have not been requested.
Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
Signed-off-by: default avatarJesse Barnes <jbarnes@virtuousgeek.org>
parent 2b8fd918
...@@ -374,21 +374,32 @@ struct pci_dev *acpi_get_pci_dev(acpi_handle handle) ...@@ -374,21 +374,32 @@ struct pci_dev *acpi_get_pci_dev(acpi_handle handle)
EXPORT_SYMBOL_GPL(acpi_get_pci_dev); EXPORT_SYMBOL_GPL(acpi_get_pci_dev);
/** /**
* acpi_pci_osc_control_set - commit requested control to Firmware * acpi_pci_osc_control_set - Request control of PCI root _OSC features.
* @handle: acpi_handle for the target ACPI object * @handle: ACPI handle of a PCI root bridge (or PCIe Root Complex).
* @flags: driver's requested control bits * @mask: Mask of _OSC bits to request control of, place to store control mask.
* @req: Mask of _OSC bits the control of is essential to the caller.
* *
* Attempt to take control from Firmware on requested control bits. * Run _OSC query for @mask and if that is successful, compare the returned
* mask of control bits with @req. If all of the @req bits are set in the
* returned mask, run _OSC request for it.
*
* The variable at the @mask address may be modified regardless of whether or
* not the function returns success. On success it will contain the mask of
* _OSC bits the BIOS has granted control of, but its contents are meaningless
* on failure.
**/ **/
acpi_status acpi_pci_osc_control_set(acpi_handle handle, u32 flags) 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;
u32 control_req, result, capbuf[3]; u32 ctrl, capbuf[3];
acpi_handle tmp; acpi_handle tmp;
struct acpi_pci_root *root;
control_req = (flags & OSC_PCI_CONTROL_MASKS); if (!mask)
if (!control_req) return AE_BAD_PARAMETER;
ctrl = *mask & OSC_PCI_CONTROL_MASKS;
if ((ctrl & req) != req)
return AE_TYPE; return AE_TYPE;
root = acpi_pci_find_root(handle); root = acpi_pci_find_root(handle);
...@@ -400,27 +411,33 @@ acpi_status acpi_pci_osc_control_set(acpi_handle handle, u32 flags) ...@@ -400,27 +411,33 @@ acpi_status acpi_pci_osc_control_set(acpi_handle handle, u32 flags)
return status; return status;
mutex_lock(&osc_lock); mutex_lock(&osc_lock);
*mask = ctrl | root->osc_control_set;
/* No need to evaluate _OSC if the control was already granted. */ /* No need to evaluate _OSC if the control was already granted. */
if ((root->osc_control_set & control_req) == control_req) if ((root->osc_control_set & ctrl) == ctrl)
goto out; goto out;
/* Need to query controls first before requesting them */ /* Need to check the available controls bits before requesting them. */
flags = control_req; while (*mask) {
status = acpi_pci_query_osc(root, root->osc_support_set, &flags); status = acpi_pci_query_osc(root, root->osc_support_set, mask);
if (ACPI_FAILURE(status)) if (ACPI_FAILURE(status))
goto out; goto out;
if (ctrl == *mask)
break;
ctrl = *mask;
}
if (flags != control_req) { if ((ctrl & req) != req) {
status = AE_SUPPORT; status = AE_SUPPORT;
goto out; goto out;
} }
capbuf[OSC_QUERY_TYPE] = 0; capbuf[OSC_QUERY_TYPE] = 0;
capbuf[OSC_SUPPORT_TYPE] = root->osc_support_set; capbuf[OSC_SUPPORT_TYPE] = root->osc_support_set;
capbuf[OSC_CONTROL_TYPE] = root->osc_control_set | control_req; capbuf[OSC_CONTROL_TYPE] = ctrl;
status = acpi_pci_run_osc(handle, capbuf, &result); status = acpi_pci_run_osc(handle, capbuf, mask);
if (ACPI_SUCCESS(status)) if (ACPI_SUCCESS(status))
root->osc_control_set = result; root->osc_control_set = *mask;
out: out:
mutex_unlock(&osc_lock); mutex_unlock(&osc_lock);
return status; return status;
...@@ -551,8 +568,8 @@ static int __devinit acpi_pci_root_add(struct acpi_device *device) ...@@ -551,8 +568,8 @@ static int __devinit acpi_pci_root_add(struct acpi_device *device)
if (flags != base_flags) if (flags != base_flags)
acpi_pci_osc_support(root, flags); acpi_pci_osc_support(root, flags);
status = acpi_pci_osc_control_set(root->device->handle, flags = OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL;
OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL); status = acpi_pci_osc_control_set(root->device->handle, &flags, flags);
if (ACPI_FAILURE(status)) { if (ACPI_FAILURE(status)) {
printk(KERN_INFO "Unable to assume PCIe control: Disabling ASPM\n"); printk(KERN_INFO "Unable to assume PCIe control: Disabling ASPM\n");
......
...@@ -360,7 +360,7 @@ int acpi_get_hp_hw_control_from_firmware(struct pci_dev *pdev, u32 flags) ...@@ -360,7 +360,7 @@ int acpi_get_hp_hw_control_from_firmware(struct pci_dev *pdev, u32 flags)
acpi_get_name(handle, ACPI_FULL_PATHNAME, &string); acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
dbg("Trying to get hotplug control for %s\n", dbg("Trying to get hotplug control for %s\n",
(char *)string.pointer); (char *)string.pointer);
status = acpi_pci_osc_control_set(handle, flags); status = acpi_pci_osc_control_set(handle, &flags, flags);
if (ACPI_SUCCESS(status)) if (ACPI_SUCCESS(status))
goto got_one; goto got_one;
if (status == AE_SUPPORT) if (status == AE_SUPPORT)
......
...@@ -39,9 +39,9 @@ int aer_osc_setup(struct pcie_device *pciedev) ...@@ -39,9 +39,9 @@ int aer_osc_setup(struct pcie_device *pciedev)
handle = acpi_find_root_bridge_handle(pdev); handle = acpi_find_root_bridge_handle(pdev);
if (handle) { if (handle) {
status = acpi_pci_osc_control_set(handle, u32 flags = OSC_PCI_EXPRESS_AER_CONTROL |
OSC_PCI_EXPRESS_AER_CONTROL | OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL;
OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL); status = acpi_pci_osc_control_set(handle, &flags, flags);
} }
if (ACPI_FAILURE(status)) { if (ACPI_FAILURE(status)) {
......
...@@ -28,6 +28,7 @@ int pcie_pme_acpi_setup(struct pcie_device *srv) ...@@ -28,6 +28,7 @@ int pcie_pme_acpi_setup(struct pcie_device *srv)
acpi_status status = AE_NOT_FOUND; acpi_status status = AE_NOT_FOUND;
struct pci_dev *port = srv->port; struct pci_dev *port = srv->port;
acpi_handle handle; acpi_handle handle;
u32 flags;
int error = 0; int error = 0;
if (acpi_pci_disabled) if (acpi_pci_disabled)
...@@ -39,9 +40,10 @@ int pcie_pme_acpi_setup(struct pcie_device *srv) ...@@ -39,9 +40,10 @@ int pcie_pme_acpi_setup(struct pcie_device *srv)
if (!handle) if (!handle)
return -EINVAL; return -EINVAL;
status = acpi_pci_osc_control_set(handle, flags = OSC_PCI_EXPRESS_PME_CONTROL |
OSC_PCI_EXPRESS_PME_CONTROL | OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL;
OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL);
status = acpi_pci_osc_control_set(handle, &flags, flags);
if (ACPI_FAILURE(status)) { if (ACPI_FAILURE(status)) {
dev_info(&port->dev, dev_info(&port->dev,
"Failed to receive control of PCIe PME service: %s\n", "Failed to receive control of PCIe PME service: %s\n",
......
...@@ -304,8 +304,8 @@ acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context); ...@@ -304,8 +304,8 @@ acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context);
OSC_PCI_EXPRESS_PME_CONTROL | \ OSC_PCI_EXPRESS_PME_CONTROL | \
OSC_PCI_EXPRESS_AER_CONTROL | \ OSC_PCI_EXPRESS_AER_CONTROL | \
OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL) OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL)
extern acpi_status acpi_pci_osc_control_set(acpi_handle handle,
extern acpi_status acpi_pci_osc_control_set(acpi_handle handle, u32 flags); u32 *mask, u32 req);
extern void acpi_early_init(void); extern void acpi_early_init(void);
#else /* !CONFIG_ACPI */ #else /* !CONFIG_ACPI */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment