From 2f9c55cc1d00c075c20dc196699eb8f0d6029069 Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Fri, 2 Jan 2015 12:08:02 +0000 Subject: OvmfPkg: QemuBootOrderLib: featurize PCI-like device path translation 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 Acked-by: Jordan Justen git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16571 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Library/QemuBootOrderLib/QemuBootOrderLib.c | 68 +++++++++++++++++++--- .../Library/QemuBootOrderLib/QemuBootOrderLib.inf | 3 + 2 files changed, 64 insertions(+), 7 deletions(-) (limited to 'OvmfPkg/Library/QemuBootOrderLib') diff --git a/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c b/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c index 2ff6854430..174fd1f554 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; @@ -801,6 +801,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 @@ -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/Library/QemuBootOrderLib/QemuBootOrderLib.inf b/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf index 12419cda09..5aa4e6eff0 100644 --- a/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf +++ b/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf @@ -51,3 +51,6 @@ [Guids] gEfiGlobalVariableGuid + +[FeaturePcd] + gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderPciTranslation -- cgit v1.2.3