From patchwork Wed Aug 4 23:37:14 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafael Wysocki X-Patchwork-Id: 117177 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o74Ndwu4023917 for ; Wed, 4 Aug 2010 23:39:58 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759510Ab0HDXjr (ORCPT ); Wed, 4 Aug 2010 19:39:47 -0400 Received: from ogre.sisk.pl ([217.79.144.158]:39089 "EHLO ogre.sisk.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933162Ab0HDXjo (ORCPT ); Wed, 4 Aug 2010 19:39:44 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by ogre.sisk.pl (Postfix) with ESMTP id 50F7418FA62; Thu, 5 Aug 2010 01:31:46 +0200 (CEST) Received: from ogre.sisk.pl ([127.0.0.1]) by localhost (ogre.sisk.pl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 22944-01; Thu, 5 Aug 2010 01:31:39 +0200 (CEST) Received: from ferrari.localnet (220-bem-13.acn.waw.pl [82.210.184.220]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ogre.sisk.pl (Postfix) with ESMTP id 0F21618FACC; Thu, 5 Aug 2010 01:31:39 +0200 (CEST) From: "Rafael J. Wysocki" To: Kenji Kaneshige Subject: Re: [linux-pm] [PATCH 1/8] ACPI / PCI: Introduce acpi_pci_osc_control_query() Date: Thu, 5 Aug 2010 01:37:14 +0200 User-Agent: KMail/1.13.5 (Linux/2.6.35-rjw+; KDE/4.4.4; x86_64; ; ) Cc: linux-pm@lists.linux-foundation.org, Hidetoshi Seto , linux-pci@vger.kernel.org, Jesse Barnes , ACPI Devel Maling List References: <201008022351.31406.rjw@sisk.pl> <201008032258.40838.rjw@sisk.pl> <4C58EC6D.4050902@jp.fujitsu.com> In-Reply-To: <4C58EC6D.4050902@jp.fujitsu.com> MIME-Version: 1.0 Message-Id: <201008050137.15082.rjw@sisk.pl> X-Virus-Scanned: amavisd-new at ogre.sisk.pl using MkS_Vir for Linux Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Wed, 04 Aug 2010 23:39:58 +0000 (UTC) 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 @@ -225,21 +225,32 @@ static acpi_status acpi_pci_run_osc(acpi return status; } -static acpi_status acpi_pci_query_osc(struct acpi_pci_root *root, u32 flags) +static acpi_status acpi_pci_query_osc(struct acpi_pci_root *root, + u32 support, + u32 *control) { acpi_status status; - u32 support_set, result, capbuf[3]; + u32 result, capbuf[3]; + + support &= OSC_PCI_SUPPORT_MASKS; + support |= root->osc_support_set; - /* do _OSC query for all possible controls */ - support_set = root->osc_support_set | (flags & OSC_PCI_SUPPORT_MASKS); capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE; - capbuf[OSC_SUPPORT_TYPE] = support_set; - capbuf[OSC_CONTROL_TYPE] = OSC_PCI_CONTROL_MASKS; + capbuf[OSC_SUPPORT_TYPE] = support; + if (control) { + *control &= OSC_PCI_CONTROL_MASKS; + capbuf[OSC_CONTROL_TYPE] = *control | root->osc_control_set; + } else { + /* Run _OSC query for all possible controls. */ + capbuf[OSC_CONTROL_TYPE] = OSC_PCI_CONTROL_MASKS; + } status = acpi_pci_run_osc(root->device->handle, capbuf, &result); if (ACPI_SUCCESS(status)) { - root->osc_support_set = support_set; + root->osc_support_set = support; root->osc_control_qry = result; + if (control) + *control = result; root->osc_queried = 1; } return status; @@ -254,7 +265,7 @@ static acpi_status acpi_pci_osc_support( if (ACPI_FAILURE(status)) return status; mutex_lock(&osc_lock); - status = acpi_pci_query_osc(root, flags); + status = acpi_pci_query_osc(root, flags, NULL); mutex_unlock(&osc_lock); return status; } @@ -363,6 +374,48 @@ out: } EXPORT_SYMBOL_GPL(acpi_get_pci_dev); + /** + * acpi_pci_osc_control_query - Get the _OSC bits the kernel can control. + * @handle: ACPI handle of a PCI root bridge (or PCIe Root Complex). + * @mask: Mask of _OSC bits to query and the place to put the result into. + **/ +acpi_status acpi_pci_osc_control_query(acpi_handle handle, u32 *mask) +{ + struct acpi_pci_root *root; + acpi_handle tmp; + acpi_status status = AE_OK; + u32 ctrl = *mask; + + if (!ctrl || !(ctrl & OSC_PCI_CONTROL_MASKS)) + return AE_BAD_PARAMETER; + + root = acpi_pci_find_root(handle); + if (!root) + return AE_NOT_EXIST; + + status = acpi_get_handle(handle, "_OSC", &tmp); + if (ACPI_FAILURE(status)) + return status; + + mutex_lock(&osc_lock); + + *mask |= root->osc_control_set; + if ((ctrl & root->osc_control_set) == ctrl) + goto out; + + while (*mask && *mask != ctrl) { + ctrl = *mask; + status = acpi_pci_query_osc(root, root->osc_support_set, mask); + if (ACPI_FAILURE(status)) + break; + } + + out: + mutex_unlock(&osc_lock); + + return status; +} + /** * acpi_pci_osc_control_set - commit requested control to Firmware * @handle: acpi_handle for the target ACPI object @@ -396,7 +449,7 @@ acpi_status acpi_pci_osc_control_set(acp /* Need to query controls first before requesting them */ if (!root->osc_queried) { - status = acpi_pci_query_osc(root, root->osc_support_set); + status = acpi_pci_query_osc(root, root->osc_support_set, NULL); if (ACPI_FAILURE(status)) goto out; } Index: linux-2.6/include/linux/acpi.h =================================================================== --- linux-2.6.orig/include/linux/acpi.h +++ linux-2.6/include/linux/acpi.h @@ -305,6 +305,7 @@ acpi_status acpi_run_osc(acpi_handle han OSC_PCI_EXPRESS_AER_CONTROL | \ OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL) +extern acpi_status acpi_pci_osc_control_query(acpi_handle handle, u32 *mask); extern acpi_status acpi_pci_osc_control_set(acpi_handle handle, u32 flags); extern void acpi_early_init(void);