Rewrite the BootOrder NvVar based on QEMU's "bootorder" fw_cfg file.\r
\r
Copyright (C) 2012 - 2014, Red Hat, Inc.\r
- Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR>\r
\r
This program and the accompanying materials are licensed and made available\r
under the terms and conditions of the BSD License which accompanies this\r
#include <Library/QemuFwCfgLib.h>\r
#include <Library/DebugLib.h>\r
#include <Library/MemoryAllocationLib.h>\r
-#include <Library/GenericBdsLib.h>\r
+#include <Library/UefiBootManagerLib.h>\r
#include <Library/UefiBootServicesTableLib.h>\r
#include <Library/UefiRuntimeServicesTableLib.h>\r
#include <Library/BaseLib.h>\r
#include <Guid/GlobalVariable.h>\r
#include <Guid/VirtioMmioTransport.h>\r
\r
+#include "ExtraRootBusMap.h"\r
\r
/**\r
OpenFirmware to UEFI device path translation output buffer size in CHAR16's.\r
**/\r
#define TRANSLATION_OUTPUT_SIZE 0x100\r
\r
+/**\r
+ Output buffer size for OpenFirmware to UEFI device path fragment translation,\r
+ in CHAR16's, for a sequence of PCI bridges.\r
+**/\r
+#define BRIDGE_TRANSLATION_OUTPUT_SIZE 0x40\r
\r
/**\r
Numbers of nodes in OpenFirmware device paths that are required and examined.\r
**/\r
#define REQUIRED_PCI_OFW_NODES 2\r
#define REQUIRED_MMIO_OFW_NODES 1\r
-#define EXAMINED_OFW_NODES 4\r
+#define EXAMINED_OFW_NODES 6\r
\r
\r
/**\r
LOAD_OPTION_ACTIVE attribute.\r
**/\r
typedef struct {\r
- CONST BDS_COMMON_OPTION *BootOption; // reference only, no ownership\r
- BOOLEAN Appended; // has been added to a BOOT_ORDER?\r
+ CONST EFI_BOOT_MANAGER_LOAD_OPTION *BootOption; // reference only, no\r
+ // ownership\r
+ BOOLEAN Appended; // has been added to a\r
+ // BOOT_ORDER?\r
} ACTIVE_OPTION;\r
\r
\r
}\r
\r
BootOrder->Data[BootOrder->Produced++] =\r
- ActiveOption->BootOption->BootCurrent;\r
+ (UINT16) ActiveOption->BootOption->OptionNumber;\r
ActiveOption->Appended = TRUE;\r
return RETURN_SUCCESS;\r
}\r
\r
/**\r
\r
- Create an array of ACTIVE_OPTION elements for a boot option list.\r
+ Create an array of ACTIVE_OPTION elements for a boot option array.\r
+\r
+ @param[in] BootOptions A boot option array, created with\r
+ EfiBootManagerRefreshAllBootOption () and\r
+ EfiBootManagerGetLoadOptions ().\r
\r
- @param[in] BootOptionList A boot option list, created with\r
- BdsLibEnumerateAllBootOption().\r
+ @param[in] BootOptionCount The number of elements in BootOptions.\r
\r
- @param[out] ActiveOption Pointer to the first element in the new array.\r
- The caller is responsible for freeing the array\r
- with FreePool() after use.\r
+ @param[out] ActiveOption Pointer to the first element in the new array.\r
+ The caller is responsible for freeing the array\r
+ with FreePool() after use.\r
\r
- @param[out] Count Number of elements in the new array.\r
+ @param[out] Count Number of elements in the new array.\r
\r
\r
@retval RETURN_SUCCESS The ActiveOption array has been created.\r
\r
@retval RETURN_NOT_FOUND No active entry has been found in\r
- BootOptionList.\r
+ BootOptions.\r
\r
@retval RETURN_OUT_OF_RESOURCES Memory allocation failed.\r
\r
STATIC\r
RETURN_STATUS\r
CollectActiveOptions (\r
- IN CONST LIST_ENTRY *BootOptionList,\r
- OUT ACTIVE_OPTION **ActiveOption,\r
- OUT UINTN *Count\r
+ IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions,\r
+ IN UINTN BootOptionCount,\r
+ OUT ACTIVE_OPTION **ActiveOption,\r
+ OUT UINTN *Count\r
)\r
{\r
+ UINTN Index;\r
UINTN ScanMode;\r
\r
*ActiveOption = NULL;\r
// - store links to active entries.\r
//\r
for (ScanMode = 0; ScanMode < 2; ++ScanMode) {\r
- CONST LIST_ENTRY *Link;\r
-\r
- Link = BootOptionList->ForwardLink;\r
*Count = 0;\r
- while (Link != BootOptionList) {\r
- CONST BDS_COMMON_OPTION *Current;\r
-\r
- Current = CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATURE);\r
- if (IS_LOAD_OPTION_TYPE (Current->Attribute, LOAD_OPTION_ACTIVE)) {\r
+ for (Index = 0; Index < BootOptionCount; Index++) {\r
+ if ((BootOptions[Index].Attributes & LOAD_OPTION_ACTIVE) != 0) {\r
if (ScanMode == 1) {\r
- (*ActiveOption)[*Count].BootOption = Current;\r
+ (*ActiveOption)[*Count].BootOption = &BootOptions[Index];\r
(*ActiveOption)[*Count].Appended = FALSE;\r
}\r
++*Count;\r
}\r
- Link = Link->ForwardLink;\r
}\r
\r
if (ScanMode == 0) {\r
\r
@param[in] NumNodes Number of elements in OfwNode.\r
\r
+ @param[in] ExtraPciRoots An EXTRA_ROOT_BUS_MAP object created with\r
+ CreateExtraRootBusMap(), to be used for\r
+ translating positions of extra root buses to\r
+ bus numbers.\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
@retval RETURN_UNSUPPORTED The array of OpenFirmware device nodes can't\r
be translated in the current implementation.\r
\r
+ @retval RETURN_PROTOCOL_ERROR The initial OpenFirmware node refers to an\r
+ extra PCI root bus (by serial number) that\r
+ is invalid according to ExtraPciRoots.\r
+\r
**/\r
STATIC\r
RETURN_STATUS\r
TranslatePciOfwNodes (\r
- IN CONST OFW_NODE *OfwNode,\r
- IN UINTN NumNodes,\r
- OUT CHAR16 *Translated,\r
- IN OUT UINTN *TranslatedSize\r
+ IN CONST OFW_NODE *OfwNode,\r
+ IN UINTN NumNodes,\r
+ IN CONST EXTRA_ROOT_BUS_MAP *ExtraPciRoots,\r
+ OUT CHAR16 *Translated,\r
+ IN OUT UINTN *TranslatedSize\r
)\r
{\r
+ UINT32 PciRoot;\r
+ CHAR8 *Comma;\r
+ UINTN FirstNonBridge;\r
+ CHAR16 Bridges[BRIDGE_TRANSLATION_OUTPUT_SIZE];\r
+ UINTN BridgesLen;\r
UINT64 PciDevFun[2];\r
UINTN NumEntries;\r
UINTN Written;\r
\r
//\r
- // Get PCI device and optional PCI function. Assume a single PCI root.\r
+ // Resolve the PCI root bus number.\r
+ //\r
+ // The initial OFW node for the main root bus (ie. bus number 0) is:\r
+ //\r
+ // /pci@i0cf8\r
+ //\r
+ // For extra root buses, the initial OFW node is\r
+ //\r
+ // /pci@i0cf8,4\r
+ // ^\r
+ // root bus serial number (not PCI bus number)\r
//\r
if (NumNodes < REQUIRED_PCI_OFW_NODES ||\r
!SubstringEq (OfwNode[0].DriverName, "pci")\r
) {\r
return RETURN_UNSUPPORTED;\r
}\r
+\r
+ PciRoot = 0;\r
+ Comma = ScanMem8 (OfwNode[0].UnitAddress.Ptr, OfwNode[0].UnitAddress.Len,\r
+ ',');\r
+ if (Comma != NULL) {\r
+ SUBSTRING PciRootSerialSubString;\r
+ UINT64 PciRootSerial;\r
+\r
+ //\r
+ // Parse the root bus serial number from the unit address after the comma.\r
+ //\r
+ PciRootSerialSubString.Ptr = Comma + 1;\r
+ PciRootSerialSubString.Len = OfwNode[0].UnitAddress.Len -\r
+ (PciRootSerialSubString.Ptr -\r
+ OfwNode[0].UnitAddress.Ptr);\r
+ NumEntries = 1;\r
+ if (RETURN_ERROR (ParseUnitAddressHexList (PciRootSerialSubString,\r
+ &PciRootSerial, &NumEntries))) {\r
+ return RETURN_UNSUPPORTED;\r
+ }\r
+\r
+ //\r
+ // Map the extra root bus's serial number to its actual bus number.\r
+ //\r
+ if (EFI_ERROR (MapRootBusPosToBusNr (ExtraPciRoots, PciRootSerial,\r
+ &PciRoot))) {\r
+ return RETURN_PROTOCOL_ERROR;\r
+ }\r
+ }\r
+\r
+ //\r
+ // Translate a sequence of PCI bridges. For each bridge, the OFW node is:\r
+ //\r
+ // pci-bridge@1e[,0]\r
+ // ^ ^\r
+ // PCI slot & function on the parent, holding the bridge\r
+ //\r
+ // and the UEFI device path node is:\r
+ //\r
+ // Pci(0x1E,0x0)\r
+ //\r
+ FirstNonBridge = 1;\r
+ Bridges[0] = L'\0';\r
+ BridgesLen = 0;\r
+ do {\r
+ UINT64 BridgeDevFun[2];\r
+ UINTN BridgesFreeBytes;\r
+\r
+ if (!SubstringEq (OfwNode[FirstNonBridge].DriverName, "pci-bridge")) {\r
+ break;\r
+ }\r
+\r
+ BridgeDevFun[1] = 0;\r
+ NumEntries = sizeof BridgeDevFun / sizeof BridgeDevFun[0];\r
+ if (ParseUnitAddressHexList (OfwNode[FirstNonBridge].UnitAddress,\r
+ BridgeDevFun, &NumEntries) != RETURN_SUCCESS) {\r
+ return RETURN_UNSUPPORTED;\r
+ }\r
+\r
+ BridgesFreeBytes = sizeof Bridges - BridgesLen * sizeof Bridges[0];\r
+ Written = UnicodeSPrintAsciiFormat (Bridges + BridgesLen, BridgesFreeBytes,\r
+ "/Pci(0x%Lx,0x%Lx)", BridgeDevFun[0], BridgeDevFun[1]);\r
+ BridgesLen += Written;\r
+\r
+ //\r
+ // There's no way to differentiate between "completely used up without\r
+ // truncation" and "truncated", so treat the former as the latter.\r
+ //\r
+ if (BridgesLen + 1 == BRIDGE_TRANSLATION_OUTPUT_SIZE) {\r
+ return RETURN_UNSUPPORTED;\r
+ }\r
+\r
+ ++FirstNonBridge;\r
+ } while (FirstNonBridge < NumNodes);\r
+\r
+ if (FirstNonBridge == NumNodes) {\r
+ return RETURN_UNSUPPORTED;\r
+ }\r
+\r
+ //\r
+ // Parse the OFW nodes starting with the first non-bridge node.\r
+ //\r
PciDevFun[1] = 0;\r
- NumEntries = sizeof (PciDevFun) / sizeof (PciDevFun[0]);\r
+ NumEntries = ARRAY_SIZE (PciDevFun);\r
if (ParseUnitAddressHexList (\r
- OfwNode[1].UnitAddress,\r
+ OfwNode[FirstNonBridge].UnitAddress,\r
PciDevFun,\r
&NumEntries\r
) != RETURN_SUCCESS\r
return RETURN_UNSUPPORTED;\r
}\r
\r
- if (NumNodes >= 4 &&\r
- SubstringEq (OfwNode[1].DriverName, "ide") &&\r
- SubstringEq (OfwNode[2].DriverName, "drive") &&\r
- SubstringEq (OfwNode[3].DriverName, "disk")\r
+ if (NumNodes >= FirstNonBridge + 3 &&\r
+ SubstringEq (OfwNode[FirstNonBridge + 0].DriverName, "ide") &&\r
+ SubstringEq (OfwNode[FirstNonBridge + 1].DriverName, "drive") &&\r
+ SubstringEq (OfwNode[FirstNonBridge + 2].DriverName, "disk")\r
) {\r
//\r
// OpenFirmware device path (IDE disk, IDE CD-ROM):\r
\r
NumEntries = 1;\r
if (ParseUnitAddressHexList (\r
- OfwNode[2].UnitAddress,\r
+ OfwNode[FirstNonBridge + 1].UnitAddress,\r
&Secondary,\r
&NumEntries\r
) != RETURN_SUCCESS ||\r
Secondary > 1 ||\r
ParseUnitAddressHexList (\r
- OfwNode[3].UnitAddress,\r
+ OfwNode[FirstNonBridge + 2].UnitAddress,\r
&Slave,\r
&NumEntries // reuse after previous single-element call\r
) != RETURN_SUCCESS ||\r
Written = UnicodeSPrintAsciiFormat (\r
Translated,\r
*TranslatedSize * sizeof (*Translated), // BufferSize in bytes\r
- "PciRoot(0x0)/Pci(0x%Lx,0x%Lx)/Ata(%a,%a,0x0)",\r
+ "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)/Ata(%a,%a,0x0)",\r
+ PciRoot,\r
+ Bridges,\r
PciDevFun[0],\r
PciDevFun[1],\r
Secondary ? "Secondary" : "Primary",\r
Slave ? "Slave" : "Master"\r
);\r
- } else if (NumNodes >= 4 &&\r
- SubstringEq (OfwNode[1].DriverName, "isa") &&\r
- SubstringEq (OfwNode[2].DriverName, "fdc") &&\r
- SubstringEq (OfwNode[3].DriverName, "floppy")\r
+ } else if (NumNodes >= FirstNonBridge + 3 &&\r
+ SubstringEq (OfwNode[FirstNonBridge + 0].DriverName, "pci8086,2922") &&\r
+ SubstringEq (OfwNode[FirstNonBridge + 1].DriverName, "drive") &&\r
+ SubstringEq (OfwNode[FirstNonBridge + 2].DriverName, "disk")\r
+ ) {\r
+ //\r
+ // OpenFirmware device path (Q35 SATA disk and CD-ROM):\r
+ //\r
+ // /pci@i0cf8/pci8086,2922@1f,2/drive@1/disk@0\r
+ // ^ ^ ^ ^ ^\r
+ // | | | | device number (fixed 0)\r
+ // | | | channel (port) number\r
+ // | PCI slot & function holding SATA HBA\r
+ // PCI root at system bus port, PIO\r
+ //\r
+ // UEFI device path:\r
+ //\r
+ // PciRoot(0x0)/Pci(0x1F,0x2)/Sata(0x1,0xFFFF,0x0)\r
+ // ^ ^ ^\r
+ // | | LUN (always 0 on Q35)\r
+ // | port multiplier port number,\r
+ // | always 0xFFFF on Q35\r
+ // channel (port) number\r
+ //\r
+ UINT64 Channel;\r
+\r
+ NumEntries = 1;\r
+ if (RETURN_ERROR (ParseUnitAddressHexList (\r
+ OfwNode[FirstNonBridge + 1].UnitAddress, &Channel,\r
+ &NumEntries))) {\r
+ return RETURN_UNSUPPORTED;\r
+ }\r
+\r
+ Written = UnicodeSPrintAsciiFormat (\r
+ Translated,\r
+ *TranslatedSize * sizeof (*Translated), // BufferSize in bytes\r
+ "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)/Sata(0x%Lx,0xFFFF,0x0)",\r
+ PciRoot,\r
+ Bridges,\r
+ PciDevFun[0],\r
+ PciDevFun[1],\r
+ Channel\r
+ );\r
+ } else if (NumNodes >= FirstNonBridge + 3 &&\r
+ SubstringEq (OfwNode[FirstNonBridge + 0].DriverName, "isa") &&\r
+ SubstringEq (OfwNode[FirstNonBridge + 1].DriverName, "fdc") &&\r
+ SubstringEq (OfwNode[FirstNonBridge + 2].DriverName, "floppy")\r
) {\r
//\r
// OpenFirmware device path (floppy disk):\r
\r
NumEntries = 1;\r
if (ParseUnitAddressHexList (\r
- OfwNode[3].UnitAddress,\r
+ OfwNode[FirstNonBridge + 2].UnitAddress,\r
&AcpiUid,\r
&NumEntries\r
) != RETURN_SUCCESS ||\r
Written = UnicodeSPrintAsciiFormat (\r
Translated,\r
*TranslatedSize * sizeof (*Translated), // BufferSize in bytes\r
- "PciRoot(0x0)/Pci(0x%Lx,0x%Lx)/Floppy(0x%Lx)",\r
+ "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)/Floppy(0x%Lx)",\r
+ PciRoot,\r
+ Bridges,\r
PciDevFun[0],\r
PciDevFun[1],\r
AcpiUid\r
);\r
- } else if (NumNodes >= 3 &&\r
- SubstringEq (OfwNode[1].DriverName, "scsi") &&\r
- SubstringEq (OfwNode[2].DriverName, "disk")\r
+ } else if (NumNodes >= FirstNonBridge + 2 &&\r
+ SubstringEq (OfwNode[FirstNonBridge + 0].DriverName, "scsi") &&\r
+ SubstringEq (OfwNode[FirstNonBridge + 1].DriverName, "disk")\r
) {\r
//\r
// OpenFirmware device path (virtio-blk disk):\r
//\r
// UEFI device path prefix:\r
//\r
- // PciRoot(0x0)/Pci(0x6,0x0)/HD( -- if PCI function is 0 or absent\r
- // PciRoot(0x0)/Pci(0x6,0x3)/HD( -- if PCI function is present and nonzero\r
+ // PciRoot(0x0)/Pci(0x6,0x0) -- if PCI function is 0 or absent\r
+ // PciRoot(0x0)/Pci(0x6,0x3) -- if PCI function is present and nonzero\r
//\r
Written = UnicodeSPrintAsciiFormat (\r
Translated,\r
*TranslatedSize * sizeof (*Translated), // BufferSize in bytes\r
- "PciRoot(0x0)/Pci(0x%Lx,0x%Lx)/HD(",\r
+ "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)",\r
+ PciRoot,\r
+ Bridges,\r
PciDevFun[0],\r
PciDevFun[1]\r
);\r
- } else if (NumNodes >= 4 &&\r
- SubstringEq (OfwNode[1].DriverName, "scsi") &&\r
- SubstringEq (OfwNode[2].DriverName, "channel") &&\r
- SubstringEq (OfwNode[3].DriverName, "disk")\r
+ } else if (NumNodes >= FirstNonBridge + 3 &&\r
+ SubstringEq (OfwNode[FirstNonBridge + 0].DriverName, "scsi") &&\r
+ SubstringEq (OfwNode[FirstNonBridge + 1].DriverName, "channel") &&\r
+ SubstringEq (OfwNode[FirstNonBridge + 2].DriverName, "disk")\r
) {\r
//\r
// OpenFirmware device path (virtio-scsi disk):\r
UINT64 TargetLun[2];\r
\r
TargetLun[1] = 0;\r
- NumEntries = sizeof (TargetLun) / sizeof (TargetLun[0]);\r
+ NumEntries = ARRAY_SIZE (TargetLun);\r
if (ParseUnitAddressHexList (\r
- OfwNode[3].UnitAddress,\r
+ OfwNode[FirstNonBridge + 2].UnitAddress,\r
TargetLun,\r
&NumEntries\r
) != RETURN_SUCCESS\r
Written = UnicodeSPrintAsciiFormat (\r
Translated,\r
*TranslatedSize * sizeof (*Translated), // BufferSize in bytes\r
- "PciRoot(0x0)/Pci(0x%Lx,0x%Lx)/Scsi(0x%Lx,0x%Lx)",\r
+ "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)/Scsi(0x%Lx,0x%Lx)",\r
+ PciRoot,\r
+ Bridges,\r
PciDevFun[0],\r
PciDevFun[1],\r
TargetLun[0],\r
TargetLun[1]\r
);\r
+ } else if (NumNodes >= FirstNonBridge + 2 &&\r
+ SubstringEq (OfwNode[FirstNonBridge + 0].DriverName, "pci8086,5845") &&\r
+ SubstringEq (OfwNode[FirstNonBridge + 1].DriverName, "namespace")\r
+ ) {\r
+ //\r
+ // OpenFirmware device path (NVMe device):\r
+ //\r
+ // /pci@i0cf8/pci8086,5845@6[,1]/namespace@1,0\r
+ // ^ ^ ^ ^ ^\r
+ // | | | | Extended Unique Identifier\r
+ // | | | | (EUI-64), big endian interp.\r
+ // | | | namespace ID\r
+ // | PCI slot & function holding NVMe controller\r
+ // PCI root at system bus port, PIO\r
+ //\r
+ // UEFI device path:\r
+ //\r
+ // PciRoot(0x0)/Pci(0x6,0x1)/NVMe(0x1,00-00-00-00-00-00-00-00)\r
+ // ^ ^\r
+ // | octets of the EUI-64\r
+ // | in address order\r
+ // namespace ID\r
+ //\r
+ UINT64 Namespace[2];\r
+ UINTN RequiredEntries;\r
+ UINT8 *Eui64;\r
+\r
+ RequiredEntries = ARRAY_SIZE (Namespace);\r
+ NumEntries = RequiredEntries;\r
+ if (ParseUnitAddressHexList (\r
+ OfwNode[FirstNonBridge + 1].UnitAddress,\r
+ Namespace,\r
+ &NumEntries\r
+ ) != RETURN_SUCCESS ||\r
+ NumEntries != RequiredEntries ||\r
+ Namespace[0] == 0 ||\r
+ Namespace[0] >= MAX_UINT32\r
+ ) {\r
+ return RETURN_UNSUPPORTED;\r
+ }\r
+\r
+ Eui64 = (UINT8 *)&Namespace[1];\r
+ Written = UnicodeSPrintAsciiFormat (\r
+ Translated,\r
+ *TranslatedSize * sizeof (*Translated), // BufferSize in bytes\r
+ "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)/"\r
+ "NVMe(0x%Lx,%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x)",\r
+ PciRoot,\r
+ Bridges,\r
+ PciDevFun[0],\r
+ PciDevFun[1],\r
+ Namespace[0],\r
+ Eui64[7], Eui64[6], Eui64[5], Eui64[4],\r
+ Eui64[3], Eui64[2], Eui64[1], Eui64[0]\r
+ );\r
} else {\r
//\r
// Generic OpenFirmware device path for PCI devices:\r
Written = UnicodeSPrintAsciiFormat (\r
Translated,\r
*TranslatedSize * sizeof (*Translated), // BufferSize in bytes\r
- "PciRoot(0x0)/Pci(0x%Lx,0x%Lx)",\r
+ "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)",\r
+ PciRoot,\r
+ Bridges,\r
PciDevFun[0],\r
PciDevFun[1]\r
);\r
//\r
// UEFI device path prefix:\r
//\r
- // <VenHwString>/HD(\r
+ // <VenHwString>\r
//\r
Written = UnicodeSPrintAsciiFormat (\r
Translated,\r
*TranslatedSize * sizeof (*Translated), // BufferSize in bytes\r
- "%s/HD(",\r
+ "%s",\r
VenHwString\r
);\r
} else if (NumNodes >= 3 &&\r
UINT64 TargetLun[2];\r
\r
TargetLun[1] = 0;\r
- NumEntries = sizeof (TargetLun) / sizeof (TargetLun[0]);\r
+ NumEntries = ARRAY_SIZE (TargetLun);\r
if (ParseUnitAddressHexList (\r
OfwNode[2].UnitAddress,\r
TargetLun,\r
\r
@param[in] NumNodes Number of elements in OfwNode.\r
\r
+ @param[in] ExtraPciRoots An EXTRA_ROOT_BUS_MAP object created with\r
+ CreateExtraRootBusMap(), to be used for\r
+ translating positions of extra root buses to\r
+ bus numbers.\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
@retval RETURN_UNSUPPORTED The array of OpenFirmware device nodes can't\r
be translated in the current implementation.\r
\r
+ @retval RETURN_PROTOCOL_ERROR The array of OpenFirmware device nodes has\r
+ been (partially) recognized, but it contains\r
+ a logic error / doesn't match system state.\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
+ IN CONST OFW_NODE *OfwNode,\r
+ IN UINTN NumNodes,\r
+ IN CONST EXTRA_ROOT_BUS_MAP *ExtraPciRoots,\r
+ OUT CHAR16 *Translated,\r
+ IN OUT UINTN *TranslatedSize\r
)\r
{\r
RETURN_STATUS Status;\r
Status = RETURN_UNSUPPORTED;\r
\r
if (FeaturePcdGet (PcdQemuBootOrderPciTranslation)) {\r
- Status = TranslatePciOfwNodes (OfwNode, NumNodes, Translated,\r
- TranslatedSize);\r
+ Status = TranslatePciOfwNodes (OfwNode, NumNodes, ExtraPciRoots,\r
+ Translated, TranslatedSize);\r
}\r
if (Status == RETURN_UNSUPPORTED &&\r
FeaturePcdGet (PcdQemuBootOrderMmioTranslation)) {\r
characters. In other error cases, it points to\r
the byte that caused the error.\r
\r
+ @param[in] ExtraPciRoots An EXTRA_ROOT_BUS_MAP object created with\r
+ CreateExtraRootBusMap(), to be used for\r
+ translating positions of extra root buses to\r
+ bus numbers.\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
the current implementation. Further calls\r
to this function are possible.\r
\r
+ @retval RETURN_PROTOCOL_ERROR The OpenFirmware device path has been\r
+ (partially) recognized, but it contains a\r
+ logic error / doesn't match system state.\r
+ Further calls to this function are\r
+ possible.\r
+\r
@retval RETURN_NOT_FOUND Translation terminated. On input, *Ptr was\r
pointing to the empty string or "HALT". On\r
output, *Ptr points to the empty string\r
STATIC\r
RETURN_STATUS\r
TranslateOfwPath (\r
- IN OUT CONST CHAR8 **Ptr,\r
- OUT CHAR16 *Translated,\r
- IN OUT UINTN *TranslatedSize\r
+ IN OUT CONST CHAR8 **Ptr,\r
+ IN CONST EXTRA_ROOT_BUS_MAP *ExtraPciRoots,\r
+ OUT CHAR16 *Translated,\r
+ IN OUT UINTN *TranslatedSize\r
)\r
{\r
UINTN NumNodes;\r
Status = TranslateOfwNodes (\r
Node,\r
NumNodes < EXAMINED_OFW_NODES ? NumNodes : EXAMINED_OFW_NODES,\r
+ ExtraPciRoots,\r
Translated,\r
TranslatedSize);\r
switch (Status) {\r
DEBUG ((DEBUG_VERBOSE, "%a: unsupported\n", __FUNCTION__));\r
break;\r
\r
+ case RETURN_PROTOCOL_ERROR:\r
+ DEBUG ((DEBUG_VERBOSE, "%a: logic error / system state mismatch\n",\r
+ __FUNCTION__));\r
+ break;\r
+\r
default:\r
ASSERT (0);\r
}\r
Match (\r
IN CONST CHAR16 *Translated,\r
IN UINTN TranslatedLength,\r
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
+ IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
)\r
{\r
- CHAR16 *Converted;\r
- BOOLEAN Result;\r
+ CHAR16 *Converted;\r
+ BOOLEAN Result;\r
+ VOID *FileBuffer;\r
+ UINTN FileSize;\r
+ EFI_DEVICE_PATH_PROTOCOL *AbsDevicePath;\r
+ CHAR16 *AbsConverted;\r
+ BOOLEAN Shortform;\r
+ EFI_DEVICE_PATH_PROTOCOL *Node;\r
\r
Converted = ConvertDevicePathToText (\r
DevicePath,\r
return FALSE;\r
}\r
\r
+ Result = FALSE;\r
+ Shortform = FALSE;\r
+ //\r
+ // Expand the short-form device path to full device path\r
+ //\r
+ if ((DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) &&\r
+ (DevicePathSubType (DevicePath) == MEDIA_HARDDRIVE_DP)) {\r
+ //\r
+ // Harddrive shortform device path\r
+ //\r
+ Shortform = TRUE;\r
+ } else if ((DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) &&\r
+ (DevicePathSubType (DevicePath) == MEDIA_FILEPATH_DP)) {\r
+ //\r
+ // File-path shortform device path\r
+ //\r
+ Shortform = TRUE;\r
+ } else if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) &&\r
+ (DevicePathSubType (DevicePath) == MSG_URI_DP)) {\r
+ //\r
+ // URI shortform device path\r
+ //\r
+ Shortform = TRUE;\r
+ } else {\r
+ for ( Node = DevicePath\r
+ ; !IsDevicePathEnd (Node)\r
+ ; Node = NextDevicePathNode (Node)\r
+ ) {\r
+ if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) &&\r
+ ((DevicePathSubType (Node) == MSG_USB_CLASS_DP) ||\r
+ (DevicePathSubType (Node) == MSG_USB_WWID_DP))) {\r
+ Shortform = TRUE;\r
+ break;\r
+ }\r
+ }\r
+ }\r
+\r
//\r
- // Attempt to expand any relative UEFI device path starting with HD() to an\r
- // absolute device path first. The logic imitates BdsLibBootViaBootOption().\r
- // We don't have to free the absolute device path,\r
- // BdsExpandPartitionPartialDevicePathToFull() has internal caching.\r
+ // Attempt to expand any relative UEFI device path to\r
+ // an absolute device path first.\r
//\r
- Result = FALSE;\r
- if (DevicePathType (DevicePath) == MEDIA_DEVICE_PATH &&\r
- DevicePathSubType (DevicePath) == MEDIA_HARDDRIVE_DP) {\r
- EFI_DEVICE_PATH_PROTOCOL *AbsDevicePath;\r
- CHAR16 *AbsConverted;\r
-\r
- AbsDevicePath = BdsExpandPartitionPartialDevicePathToFull (\r
- (HARDDRIVE_DEVICE_PATH *) DevicePath);\r
- if (AbsDevicePath == NULL) {\r
+ if (Shortform) {\r
+ FileBuffer = EfiBootManagerGetLoadOptionBuffer (\r
+ DevicePath, &AbsDevicePath, &FileSize\r
+ );\r
+ if (FileBuffer == NULL) {\r
goto Exit;\r
}\r
+ FreePool (FileBuffer);\r
AbsConverted = ConvertDevicePathToText (AbsDevicePath, FALSE, FALSE);\r
+ FreePool (AbsDevicePath);\r
if (AbsConverted == NULL) {\r
goto Exit;\r
}\r
Idx = 0;\r
while (!RETURN_ERROR (Status) && Idx < ActiveCount) {\r
if (!ActiveOption[Idx].Appended) {\r
- CONST BDS_COMMON_OPTION *Current;\r
- CONST EFI_DEVICE_PATH_PROTOCOL *FirstNode;\r
+ CONST EFI_BOOT_MANAGER_LOAD_OPTION *Current;\r
+ CONST EFI_DEVICE_PATH_PROTOCOL *FirstNode;\r
\r
Current = ActiveOption[Idx].BootOption;\r
- FirstNode = Current->DevicePath;\r
+ FirstNode = Current->FilePath;\r
if (FirstNode != NULL) {\r
CHAR16 *Converted;\r
STATIC CHAR16 ConvFallBack[] = L"<unable to convert>";\r
CHAR16 VariableName[9];\r
\r
UnicodeSPrintAsciiFormat (VariableName, sizeof VariableName, "Boot%04x",\r
- ActiveOption[Idx].BootOption->BootCurrent);\r
+ ActiveOption[Idx].BootOption->OptionNumber);\r
\r
//\r
// "The space consumed by the deleted variable may not be available until\r
\r
Attempt to retrieve the "bootorder" fw_cfg file from QEMU. Translate the\r
OpenFirmware device paths therein to UEFI device path fragments. Match the\r
- translated fragments against BootOptionList, and rewrite the BootOrder NvVar\r
- so that it corresponds to the order described in fw_cfg.\r
-\r
- @param[in] BootOptionList A boot option list, created with\r
- BdsLibEnumerateAllBootOption ().\r
+ translated fragments against the current list of boot options, and rewrite\r
+ the BootOrder NvVar so that it corresponds to the order described in fw_cfg.\r
\r
+ Platform BDS should call this function after EfiBootManagerConnectAll () and\r
+ EfiBootManagerRefreshAllBootOption () return.\r
\r
@retval RETURN_SUCCESS BootOrder NvVar rewritten.\r
\r
**/\r
RETURN_STATUS\r
SetBootOrderFromQemu (\r
- IN CONST LIST_ENTRY *BootOptionList\r
+ VOID\r
)\r
{\r
RETURN_STATUS Status;\r
ACTIVE_OPTION *ActiveOption;\r
UINTN ActiveCount;\r
\r
+ EXTRA_ROOT_BUS_MAP *ExtraPciRoots;\r
+\r
UINTN TranslatedSize;\r
CHAR16 Translated[TRANSLATION_OUTPUT_SIZE];\r
+ EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;\r
+ UINTN BootOptionCount;\r
\r
Status = QemuFwCfgFindFile ("bootorder", &FwCfgItem, &FwCfgSize);\r
if (Status != RETURN_SUCCESS) {\r
goto ErrorFreeFwCfg;\r
}\r
\r
- Status = CollectActiveOptions (BootOptionList, &ActiveOption, &ActiveCount);\r
- if (RETURN_ERROR (Status)) {\r
+ BootOptions = EfiBootManagerGetLoadOptions (\r
+ &BootOptionCount, LoadOptionTypeBoot\r
+ );\r
+ if (BootOptions == NULL) {\r
+ Status = RETURN_NOT_FOUND;\r
goto ErrorFreeBootOrder;\r
}\r
\r
+ Status = CollectActiveOptions (\r
+ BootOptions, BootOptionCount, &ActiveOption, &ActiveCount\r
+ );\r
+ if (RETURN_ERROR (Status)) {\r
+ goto ErrorFreeBootOptions;\r
+ }\r
+\r
+ if (FeaturePcdGet (PcdQemuBootOrderPciTranslation)) {\r
+ Status = CreateExtraRootBusMap (&ExtraPciRoots);\r
+ if (EFI_ERROR (Status)) {\r
+ goto ErrorFreeActiveOption;\r
+ }\r
+ } else {\r
+ ExtraPciRoots = NULL;\r
+ }\r
+\r
//\r
// translate each OpenFirmware path\r
//\r
- TranslatedSize = sizeof (Translated) / sizeof (Translated[0]);\r
- Status = TranslateOfwPath (&FwCfgPtr, Translated, &TranslatedSize);\r
+ TranslatedSize = ARRAY_SIZE (Translated);\r
+ Status = TranslateOfwPath (&FwCfgPtr, ExtraPciRoots, Translated,\r
+ &TranslatedSize);\r
while (Status == RETURN_SUCCESS ||\r
Status == RETURN_UNSUPPORTED ||\r
+ Status == RETURN_PROTOCOL_ERROR ||\r
Status == RETURN_BUFFER_TOO_SMALL) {\r
if (Status == RETURN_SUCCESS) {\r
UINTN Idx;\r
if (Match (\r
Translated,\r
TranslatedSize, // contains length, not size, in CHAR16's here\r
- ActiveOption[Idx].BootOption->DevicePath\r
+ ActiveOption[Idx].BootOption->FilePath\r
)\r
) {\r
//\r
//\r
Status = BootOrderAppend (&BootOrder, &ActiveOption[Idx]);\r
if (Status != RETURN_SUCCESS) {\r
- goto ErrorFreeActiveOption;\r
+ goto ErrorFreeExtraPciRoots;\r
}\r
break;\r
}\r
} // scanned all active boot options\r
} // translation successful\r
\r
- TranslatedSize = sizeof (Translated) / sizeof (Translated[0]);\r
- Status = TranslateOfwPath (&FwCfgPtr, Translated, &TranslatedSize);\r
+ TranslatedSize = ARRAY_SIZE (Translated);\r
+ Status = TranslateOfwPath (&FwCfgPtr, ExtraPciRoots, Translated,\r
+ &TranslatedSize);\r
} // scanning of OpenFirmware paths done\r
\r
if (Status == RETURN_NOT_FOUND && BootOrder.Produced > 0) {\r
//\r
Status = BootOrderComplete (&BootOrder, ActiveOption, ActiveCount);\r
if (RETURN_ERROR (Status)) {\r
- goto ErrorFreeActiveOption;\r
+ goto ErrorFreeExtraPciRoots;\r
}\r
\r
//\r
);\r
if (EFI_ERROR (Status)) {\r
DEBUG ((DEBUG_ERROR, "%a: setting BootOrder: %r\n", __FUNCTION__, Status));\r
- goto ErrorFreeActiveOption;\r
+ goto ErrorFreeExtraPciRoots;\r
}\r
\r
DEBUG ((DEBUG_INFO, "%a: setting BootOrder: success\n", __FUNCTION__));\r
PruneBootVariables (ActiveOption, ActiveCount);\r
}\r
\r
+ErrorFreeExtraPciRoots:\r
+ if (ExtraPciRoots != NULL) {\r
+ DestroyExtraRootBusMap (ExtraPciRoots);\r
+ }\r
+\r
ErrorFreeActiveOption:\r
FreePool (ActiveOption);\r
\r
+ErrorFreeBootOptions:\r
+ EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);\r
+\r
ErrorFreeBootOrder:\r
FreePool (BootOrder.Data);\r
\r