All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: linux-pm@lists.linux-foundation.org
Cc: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>,
	linux-pci@vger.kernel.org,
	Jesse Barnes <jbarnes@virtuousgeek.org>,
	ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
	Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>,
	Matthew Garrett <mjg@redhat.com>
Subject: [Update][PATCH 6/10] ACPI / PCI: Negotiate _OSC control bits before requesting them (v2)
Date: Mon, 23 Aug 2010 23:53:11 +0200	[thread overview]
Message-ID: <201008232353.12007.rjw@sisk.pl> (raw)
In-Reply-To: <201008210155.31915.rjw@sisk.pl>

On Saturday, August 21, 2010, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rjw@sisk.pl>
> 
> 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: Rafael J. Wysocki <rjw@sisk.pl>

Unfortunately, there's a bug in this version of the patch that causes the
for() loop in acpi_pci_osc_control_set() to break after one iteration.

Fixed patch is appended.

Thanks,
Rafael

---
From: Rafael J. Wysocki <rjw@sisk.pl>
Subject: ACPI / PCI: Negotiate _OSC control bits before requesting them (v2)

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: Rafael J. Wysocki <rjw@sisk.pl>
---
 drivers/acpi/pci_root.c              |   59 ++++++++++++++++++++++-------------
 drivers/pci/hotplug/acpi_pcihp.c     |    2 -
 drivers/pci/pcie/aer/aerdrv_acpi.c   |    6 +--
 drivers/pci/pcie/pme/pcie_pme_acpi.c |    8 ++--
 include/linux/acpi.h                 |    4 +-
 5 files changed, 49 insertions(+), 30 deletions(-)

Index: linux-2.6/drivers/acpi/pci_root.c
===================================================================
--- linux-2.6.orig/drivers/acpi/pci_root.c
+++ linux-2.6/drivers/acpi/pci_root.c
@@ -374,21 +374,32 @@ out:
 EXPORT_SYMBOL_GPL(acpi_get_pci_dev);
 
 /**
- * acpi_pci_osc_control_set - commit requested control to Firmware
- * @handle: acpi_handle for the target ACPI object
- * @flags: driver's requested control bits
+ * acpi_pci_osc_control_set - Request control of PCI root _OSC features.
+ * @handle: ACPI handle of a PCI root bridge (or PCIe Root Complex).
+ * @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;
-	u32 control_req, result, capbuf[3];
+	u32 ctrl, capbuf[3];
 	acpi_handle tmp;
-	struct acpi_pci_root *root;
 
-	control_req = (flags & OSC_PCI_CONTROL_MASKS);
-	if (!control_req)
+	if (!mask)
+		return AE_BAD_PARAMETER;
+
+	ctrl = *mask & OSC_PCI_CONTROL_MASKS;
+	if ((ctrl & req) != req)
 		return AE_TYPE;
 
 	root = acpi_pci_find_root(handle);
@@ -400,27 +411,33 @@ acpi_status acpi_pci_osc_control_set(acp
 		return status;
 
 	mutex_lock(&osc_lock);
+
+	*mask = ctrl | root->osc_control_set;
 	/* 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;
 
-	/* Need to query controls first before requesting them */
-	flags = control_req;
-	status = acpi_pci_query_osc(root, root->osc_support_set, &flags);
-	if (ACPI_FAILURE(status))
-		goto out;
+	/* Need to check the available controls bits before requesting them. */
+	while (*mask) {
+		status = acpi_pci_query_osc(root, root->osc_support_set, mask);
+		if (ACPI_FAILURE(status))
+			goto out;
+		if (ctrl == *mask)
+			break;
+		ctrl = *mask;
+	}
 
-	if (flags != control_req) {
+	if ((ctrl & req) != req) {
 		status = AE_SUPPORT;
 		goto out;
 	}
 
 	capbuf[OSC_QUERY_TYPE] = 0;
 	capbuf[OSC_SUPPORT_TYPE] = root->osc_support_set;
-	capbuf[OSC_CONTROL_TYPE] = root->osc_control_set | control_req;
-	status = acpi_pci_run_osc(handle, capbuf, &result);
+	capbuf[OSC_CONTROL_TYPE] = ctrl;
+	status = acpi_pci_run_osc(handle, capbuf, mask);
 	if (ACPI_SUCCESS(status))
-		root->osc_control_set = result;
+		root->osc_control_set = *mask;
 out:
 	mutex_unlock(&osc_lock);
 	return status;
@@ -551,8 +568,8 @@ static int __devinit acpi_pci_root_add(s
 	if (flags != base_flags)
 		acpi_pci_osc_support(root, flags);
 
-	status = acpi_pci_osc_control_set(root->device->handle,
-					  OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL);
+	flags = OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL;
+	status = acpi_pci_osc_control_set(root->device->handle, &flags, flags);
 
 	if (ACPI_FAILURE(status)) {
 		printk(KERN_INFO "Unable to assume PCIe control: Disabling ASPM\n");
Index: linux-2.6/include/linux/acpi.h
===================================================================
--- linux-2.6.orig/include/linux/acpi.h
+++ linux-2.6/include/linux/acpi.h
@@ -304,8 +304,8 @@ acpi_status acpi_run_osc(acpi_handle han
 				OSC_PCI_EXPRESS_PME_CONTROL |		\
 				OSC_PCI_EXPRESS_AER_CONTROL |		\
 				OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL)
-
-extern acpi_status acpi_pci_osc_control_set(acpi_handle handle, u32 flags);
+extern acpi_status acpi_pci_osc_control_set(acpi_handle handle,
+					     u32 *mask, u32 req);
 extern void acpi_early_init(void);
 
 #else	/* !CONFIG_ACPI */
Index: linux-2.6/drivers/pci/pcie/aer/aerdrv_acpi.c
===================================================================
--- linux-2.6.orig/drivers/pci/pcie/aer/aerdrv_acpi.c
+++ linux-2.6/drivers/pci/pcie/aer/aerdrv_acpi.c
@@ -39,9 +39,9 @@ int aer_osc_setup(struct pcie_device *pc
 
 	handle = acpi_find_root_bridge_handle(pdev);
 	if (handle) {
-		status = acpi_pci_osc_control_set(handle,
-					OSC_PCI_EXPRESS_AER_CONTROL |
-					OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL);
+		u32 flags = OSC_PCI_EXPRESS_AER_CONTROL |
+				OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL;
+		status = acpi_pci_osc_control_set(handle, &flags, flags);
 	}
 
 	if (ACPI_FAILURE(status)) {
Index: linux-2.6/drivers/pci/pcie/pme/pcie_pme_acpi.c
===================================================================
--- linux-2.6.orig/drivers/pci/pcie/pme/pcie_pme_acpi.c
+++ linux-2.6/drivers/pci/pcie/pme/pcie_pme_acpi.c
@@ -28,6 +28,7 @@ int pcie_pme_acpi_setup(struct pcie_devi
 	acpi_status status = AE_NOT_FOUND;
 	struct pci_dev *port = srv->port;
 	acpi_handle handle;
+	u32 flags;
 	int error = 0;
 
 	if (acpi_pci_disabled)
@@ -39,9 +40,10 @@ int pcie_pme_acpi_setup(struct pcie_devi
 	if (!handle)
 		return -EINVAL;
 
-	status = acpi_pci_osc_control_set(handle,
-			OSC_PCI_EXPRESS_PME_CONTROL |
-			OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL);
+	flags = OSC_PCI_EXPRESS_PME_CONTROL |
+		OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL;
+
+	status = acpi_pci_osc_control_set(handle, &flags, flags);
 	if (ACPI_FAILURE(status)) {
 		dev_info(&port->dev,
 			"Failed to receive control of PCIe PME service: %s\n",
Index: linux-2.6/drivers/pci/hotplug/acpi_pcihp.c
===================================================================
--- linux-2.6.orig/drivers/pci/hotplug/acpi_pcihp.c
+++ linux-2.6/drivers/pci/hotplug/acpi_pcihp.c
@@ -360,7 +360,7 @@ int acpi_get_hp_hw_control_from_firmware
 		acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
 		dbg("Trying to get hotplug control for %s\n",
 				(char *)string.pointer);
-		status = acpi_pci_osc_control_set(handle, flags);
+		status = acpi_pci_osc_control_set(handle, &flags, flags);
 		if (ACPI_SUCCESS(status))
 			goto got_one;
 		if (status == AE_SUPPORT)

  parent reply	other threads:[~2010-08-23 21:54 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-06  1:03 [PATCH 0/10] ACPI / PCI / PCIe: Rework _OSC handling (v3) Rafael J. Wysocki
2010-08-06  1:05 ` [PATCH 1/10] ACPI / PCI: Introduce function for querying PCI root _OSC Rafael J. Wysocki
2010-08-06  1:05 ` Rafael J. Wysocki
2010-08-06  1:06 ` [PATCH 2/10] PCI / PCIe/ AER: Introduce pci_aer_available() Rafael J. Wysocki
2010-08-06  1:06 ` Rafael J. Wysocki
2010-08-06  1:07 ` [PATCH 3/10] PCI / PCIe: Introduce commad line switch for disabling port services Rafael J. Wysocki
2010-08-06  1:07 ` Rafael J. Wysocki
2010-08-06  1:08 ` [PATCH 4/10] PCI / PCIe: Ask BIOS for control of all native services at once (v6) Rafael J. Wysocki
2010-08-06  1:08 ` Rafael J. Wysocki
2010-08-06  1:09 ` [PATCH 5/10] PCI / PCIe: Disable PCIe port services during port initialization Rafael J. Wysocki
2010-08-06  1:09 ` Rafael J. Wysocki
2010-08-06  1:10 ` [PATCH 6/10] PCI / PCIe: Remove the port driver module exit routine Rafael J. Wysocki
2010-08-06  1:10 ` Rafael J. Wysocki
2010-08-06  1:11 ` [PATCH 7/10] PCI / Hot-plug: Query _OSC before requesting controls Rafael J. Wysocki
2010-08-06  2:20   ` Hidetoshi Seto
2010-08-06  2:20   ` Hidetoshi Seto
2010-08-06 10:34     ` Rafael J. Wysocki
2010-08-09  1:22       ` Kenji Kaneshige
2010-08-09  1:22       ` Kenji Kaneshige
2010-08-06 10:34     ` Rafael J. Wysocki
2010-08-06  1:11 ` Rafael J. Wysocki
2010-08-06  1:12 ` [PATCH 8/10] ACPI / PCI: Do not preserve _OSC control bits returned by a query (v2) Rafael J. Wysocki
2010-08-06  1:12 ` Rafael J. Wysocki
2010-08-06  1:13 ` [PATCH 9/10] ACPI / PCI: Reorder checks in acpi_pci_osc_control_set() Rafael J. Wysocki
2010-08-06  1:13 ` Rafael J. Wysocki
2010-08-06  1:15 ` [PATCH 10/10] ACPI / PCI: Merge acpi_pci_osc_control_{query|set}() Rafael J. Wysocki
2010-08-06  1:15 ` Rafael J. Wysocki
2010-08-06  3:25 ` [PATCH 0/10] ACPI / PCI / PCIe: Rework _OSC handling (v3) Hidetoshi Seto
2010-08-06 10:42   ` Rafael J. Wysocki
2010-08-06 10:42   ` Rafael J. Wysocki
2010-08-06  3:25 ` Hidetoshi Seto
2010-08-20 23:49 ` [PATCH 0/10] ACPI / PCI / PCIe: Rework _OSC handling (v4) Rafael J. Wysocki
2010-08-20 23:50   ` [PATCH 1/10] PCI / PCIe/ AER: Introduce pci_aer_available() Rafael J. Wysocki
2010-08-20 23:50   ` Rafael J. Wysocki
2010-08-24 20:49     ` Jesse Barnes
2010-08-24 20:49     ` Jesse Barnes
2010-08-20 23:51   ` [PATCH 2/10] PCI / PCIe: Introduce commad line switch for disabling port services Rafael J. Wysocki
2010-08-20 23:51   ` Rafael J. Wysocki
2010-08-20 23:52   ` [PATCH 3/10] ACPI / PCI: Reorder checks in acpi_pci_osc_control_set() Rafael J. Wysocki
2010-08-20 23:52   ` Rafael J. Wysocki
2010-08-20 23:53   ` [PATCH 4/10] ACPI / PCI: Make acpi_pci_query_osc() return control bits Rafael J. Wysocki
2010-08-20 23:53   ` Rafael J. Wysocki
2010-08-20 23:54   ` [PATCH 5/10] ACPI / PCI: Do not preserve _OSC control bits returned by a query (v4) Rafael J. Wysocki
2010-08-20 23:54   ` Rafael J. Wysocki
2010-08-23 21:55     ` [Updated changelog][PATCH " Rafael J. Wysocki
2010-08-23 21:55     ` Rafael J. Wysocki
2010-08-20 23:55   ` [PATCH 6/10] ACPI / PCI: Negotiate _OSC control bits before requesting them Rafael J. Wysocki
2010-08-20 23:55   ` Rafael J. Wysocki
2010-08-23 21:53     ` [Update][PATCH 6/10] ACPI / PCI: Negotiate _OSC control bits before requesting them (v2) Rafael J. Wysocki
2010-08-23 21:53     ` Rafael J. Wysocki [this message]
2010-08-20 23:56   ` [PATCH 7/10] PCI / PCIe: Ask BIOS for control of all native services at once (v7) Rafael J. Wysocki
2010-08-21 20:02     ` Rafael J. Wysocki
2010-08-21 20:02     ` [linux-pm] " Rafael J. Wysocki
2010-08-20 23:56   ` Rafael J. Wysocki
2010-08-20 23:57   ` [PATCH 8/10] PCI / PCIe: Disable PCIe port services during port initialization Rafael J. Wysocki
2010-08-20 23:57   ` Rafael J. Wysocki
2010-08-20 23:58   ` [PATCH 9/10] PCI / PCIe: Move PCIe PME code to the pcie directory Rafael J. Wysocki
2010-08-20 23:58   ` Rafael J. Wysocki
2010-08-20 23:59   ` [PATCH 10/10] PCI / PCIe: Remove the port driver module exit routine Rafael J. Wysocki
2010-08-20 23:59   ` Rafael J. Wysocki
2010-08-20 23:49 ` [PATCH 0/10] ACPI / PCI / PCIe: Rework _OSC handling (v4) Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201008232353.12007.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=jbarnes@virtuousgeek.org \
    --cc=kaneshige.kenji@jp.fujitsu.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=mjg@redhat.com \
    --cc=seto.hidetoshi@jp.fujitsu.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.