From patchwork Thu Nov 27 23:19:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 415739 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C208F1401EB for ; Fri, 28 Nov 2014 10:25:52 +1100 (AEDT) Received: from localhost ([::1]:41888 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xu8Ra-0004xw-Us for incoming@patchwork.ozlabs.org; Thu, 27 Nov 2014 18:25:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43473) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xu8QL-00030L-Dx for qemu-devel@nongnu.org; Thu, 27 Nov 2014 18:24:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xu8QE-0000UV-T2 for qemu-devel@nongnu.org; Thu, 27 Nov 2014 18:24:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38488) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xu8QE-0000UC-LY for qemu-devel@nongnu.org; Thu, 27 Nov 2014 18:24:26 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sARNJxVg001786 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 27 Nov 2014 18:19:59 -0500 Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-24.ams2.redhat.com [10.36.116.24]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sARNJUAI030338; Thu, 27 Nov 2014 18:19:56 -0500 From: Laszlo Ersek To: qemu-devel@nongnu.org, edk2-devel@lists.sourceforge.net, drjones@redhat.com, ard.biesheuvel@linaro.org, peter.maydell@linaro.org, imammedo@redhat.com, mst@redhat.com Date: Fri, 28 Nov 2014 00:19:21 +0100 Message-Id: <1417130367-17777-7-git-send-email-lersek@redhat.com> In-Reply-To: <1417130367-17777-1-git-send-email-lersek@redhat.com> References: <5477B0FD.9040806@redhat.com> <1417130367-17777-1-git-send-email-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [edk2 PATCH 06/12] OvmfPkg: QemuBootOrderLib: featurize PCI-like device path translation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org In preparation for adding OpenFirmware-to-UEFI translation for "MMIO-like" OFW device path fragments, let's turn the currently exclusive "PCI-like" translation into "just one" of the possible translations. - Rename TranslateOfwNodes() to TranslatePciOfwNodes(), because it is tightly coupled to "PCI-like" translations. - Rename REQUIRED_OFW_NODES to REQUIRED_PCI_OFW_NODES, because this macro is specific to TranslatePciOfwNodes(). - Introduce a new wrapper function under the original TranslateOfwNodes() name. This function is supposed to try translations in some order until a specific translation returns a status different from RETURN_UNSUPPORTED. - Introduce a new Feature PCD that controls whether PCI translation is attempted at all. - The boot option "survival policy" in BootOrderComplete() must take into account if the user was able to select PCI-like boot options. If the user had no such possibility (because the Feature PCD was off for PCI-like translation), then we ought to keep any such unselected boot options. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek --- OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf | 3 +++ OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- OvmfPkg/OvmfPkg.dec | 1 + 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf b/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf index 12419cd..5aa4e6e 100644 --- a/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf +++ b/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf @@ -51,3 +51,6 @@ [Guids] gEfiGlobalVariableGuid + +[FeaturePcd] + gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderPciTranslation diff --git a/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c b/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c index 2ff6854..174fd1f 100644 --- a/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c +++ b/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c @@ -35,8 +35,8 @@ /** Numbers of nodes in OpenFirmware device paths that are required and examined. **/ -#define REQUIRED_OFW_NODES 2 -#define EXAMINED_OFW_NODES 4 +#define REQUIRED_PCI_OFW_NODES 2 +#define EXAMINED_OFW_NODES 4 /** @@ -539,7 +539,7 @@ ParseOfwNode ( /** - Translate an array of OpenFirmware device nodes to a UEFI device path + Translate a PCI-like array of OpenFirmware device nodes to a UEFI device path fragment. @param[in] OfwNode Array of OpenFirmware device nodes to @@ -571,7 +571,7 @@ ParseOfwNode ( **/ STATIC RETURN_STATUS -TranslateOfwNodes ( +TranslatePciOfwNodes ( IN CONST OFW_NODE *OfwNode, IN UINTN NumNodes, OUT CHAR16 *Translated, @@ -585,7 +585,7 @@ TranslateOfwNodes ( // // Get PCI device and optional PCI function. Assume a single PCI root. // - if (NumNodes < REQUIRED_OFW_NODES || + if (NumNodes < REQUIRED_PCI_OFW_NODES || !SubstringEq (OfwNode[0].DriverName, "pci") ) { return RETURN_UNSUPPORTED; @@ -803,6 +803,58 @@ TranslateOfwNodes ( /** + Translate an array of OpenFirmware device nodes to a UEFI device path + fragment. + + @param[in] OfwNode Array of OpenFirmware device nodes to + translate, constituting the beginning of an + OpenFirmware device path. + + @param[in] NumNodes Number of elements in OfwNode. + + @param[out] Translated Destination array receiving the UEFI path + fragment, allocated by the caller. If the + return value differs from RETURN_SUCCESS, its + contents is indeterminate. + + @param[in out] TranslatedSize On input, the number of CHAR16's in + Translated. On RETURN_SUCCESS this parameter + is assigned the number of non-NUL CHAR16's + written to Translated. In case of other return + values, TranslatedSize is indeterminate. + + + @retval RETURN_SUCCESS Translation successful. + + @retval RETURN_BUFFER_TOO_SMALL The translation does not fit into the number + of bytes provided. + + @retval RETURN_UNSUPPORTED The array of OpenFirmware device nodes can't + be translated in the current implementation. + +**/ +STATIC +RETURN_STATUS +TranslateOfwNodes ( + IN CONST OFW_NODE *OfwNode, + IN UINTN NumNodes, + OUT CHAR16 *Translated, + IN OUT UINTN *TranslatedSize + ) +{ + RETURN_STATUS Status; + + Status = RETURN_UNSUPPORTED; + + if (FeaturePcdGet (PcdQemuBootOrderPciTranslation)) { + Status = TranslatePciOfwNodes (OfwNode, NumNodes, Translated, + TranslatedSize); + } + return Status; +} + +/** + Translate an OpenFirmware device path fragment to a UEFI device path fragment, and advance in the input string. @@ -1083,9 +1135,11 @@ BootOrderComplete ( if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST && EISA_ID_TO_NUM (Acpi->HID) == 0x0a03) { // - // drop PciRoot() + // drop PciRoot() if we enabled the user to select PCI-like boot + // options, by providing translation for such OFW device path + // fragments // - Keep = FALSE; + Keep = !FeaturePcdGet (PcdQemuBootOrderPciTranslation); } } diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 0eeda6d..8802392 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -107,3 +107,4 @@ [PcdsFeatureFlag] gUefiOvmfPkgTokenSpaceGuid.PcdSecureBootEnable|FALSE|BOOLEAN|3 + gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderPciTranslation|TRUE|BOOLEAN|0x1c