]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c
OvmfPkg: QemuBootOrderLib: featurize PCI-like device path translation
[mirror_edk2.git] / OvmfPkg / Library / QemuBootOrderLib / QemuBootOrderLib.c
index 2ff6854430ebef2e99fac333cd25b30042d02563..174fd1f5541191c294f5ac18e2d71003d841adcf 100644 (file)
@@ -35,8 +35,8 @@
 /**\r
   Numbers of nodes in OpenFirmware device paths that are required and examined.\r
 **/\r
-#define REQUIRED_OFW_NODES 2\r
-#define EXAMINED_OFW_NODES 4\r
+#define REQUIRED_PCI_OFW_NODES  2\r
+#define EXAMINED_OFW_NODES      4\r
 \r
 \r
 /**\r
@@ -539,7 +539,7 @@ ParseOfwNode (
 \r
 /**\r
 \r
-  Translate an array of OpenFirmware device nodes to a UEFI device path\r
+  Translate a PCI-like array of OpenFirmware device nodes to a UEFI device path\r
   fragment.\r
 \r
   @param[in]     OfwNode         Array of OpenFirmware device nodes to\r
@@ -571,7 +571,7 @@ ParseOfwNode (
 **/\r
 STATIC\r
 RETURN_STATUS\r
-TranslateOfwNodes (\r
+TranslatePciOfwNodes (\r
   IN      CONST OFW_NODE *OfwNode,\r
   IN      UINTN          NumNodes,\r
   OUT     CHAR16         *Translated,\r
@@ -585,7 +585,7 @@ TranslateOfwNodes (
   //\r
   // Get PCI device and optional PCI function. Assume a single PCI root.\r
   //\r
-  if (NumNodes < REQUIRED_OFW_NODES ||\r
+  if (NumNodes < REQUIRED_PCI_OFW_NODES ||\r
       !SubstringEq (OfwNode[0].DriverName, "pci")\r
       ) {\r
     return RETURN_UNSUPPORTED;\r
@@ -801,6 +801,58 @@ TranslateOfwNodes (
 }\r
 \r
 \r
+/**\r
+\r
+  Translate an array of OpenFirmware device nodes to a UEFI device path\r
+  fragment.\r
+\r
+  @param[in]     OfwNode         Array of OpenFirmware device nodes to\r
+                                 translate, constituting the beginning of an\r
+                                 OpenFirmware device path.\r
+\r
+  @param[in]     NumNodes        Number of elements in OfwNode.\r
+\r
+  @param[out]    Translated      Destination array receiving the UEFI path\r
+                                 fragment, allocated by the caller. If the\r
+                                 return value differs from RETURN_SUCCESS, its\r
+                                 contents is indeterminate.\r
+\r
+  @param[in out] TranslatedSize  On input, the number of CHAR16's in\r
+                                 Translated. On RETURN_SUCCESS this parameter\r
+                                 is assigned the number of non-NUL CHAR16's\r
+                                 written to Translated. In case of other return\r
+                                 values, TranslatedSize is indeterminate.\r
+\r
+\r
+  @retval RETURN_SUCCESS           Translation successful.\r
+\r
+  @retval RETURN_BUFFER_TOO_SMALL  The translation does not fit into the number\r
+                                   of bytes provided.\r
+\r
+  @retval RETURN_UNSUPPORTED       The array of OpenFirmware device nodes can't\r
+                                   be translated in the current implementation.\r
+\r
+**/\r
+STATIC\r
+RETURN_STATUS\r
+TranslateOfwNodes (\r
+  IN      CONST OFW_NODE *OfwNode,\r
+  IN      UINTN          NumNodes,\r
+  OUT     CHAR16         *Translated,\r
+  IN OUT  UINTN          *TranslatedSize\r
+  )\r
+{\r
+  RETURN_STATUS Status;\r
+\r
+  Status = RETURN_UNSUPPORTED;\r
+\r
+  if (FeaturePcdGet (PcdQemuBootOrderPciTranslation)) {\r
+    Status = TranslatePciOfwNodes (OfwNode, NumNodes, Translated,\r
+               TranslatedSize);\r
+  }\r
+  return Status;\r
+}\r
+\r
 /**\r
 \r
   Translate an OpenFirmware device path fragment to a UEFI device path\r
@@ -1083,9 +1135,11 @@ BootOrderComplete (
           if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST &&\r
               EISA_ID_TO_NUM (Acpi->HID) == 0x0a03) {\r
             //\r
-            // drop PciRoot()\r
+            // drop PciRoot() if we enabled the user to select PCI-like boot\r
+            // options, by providing translation for such OFW device path\r
+            // fragments\r
             //\r
-            Keep = FALSE;\r
+            Keep = !FeaturePcdGet (PcdQemuBootOrderPciTranslation);\r
           }\r
         }\r
 \r