summaryrefslogtreecommitdiffstats
path: root/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c
diff options
context:
space:
mode:
Diffstat (limited to 'OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c')
-rw-r--r--OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c1054
1 files changed, 598 insertions, 456 deletions
diff --git a/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c b/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c
index ceffb17fa6..b5768285d8 100644
--- a/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c
+++ b/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c
@@ -26,21 +26,20 @@
/**
OpenFirmware to UEFI device path translation output buffer size in CHAR16's.
**/
-#define TRANSLATION_OUTPUT_SIZE 0x100
+#define TRANSLATION_OUTPUT_SIZE 0x100
/**
Output buffer size for OpenFirmware to UEFI device path fragment translation,
in CHAR16's, for a sequence of PCI bridges.
**/
-#define BRIDGE_TRANSLATION_OUTPUT_SIZE 0x40
+#define BRIDGE_TRANSLATION_OUTPUT_SIZE 0x40
/**
Numbers of nodes in OpenFirmware device paths that are required and examined.
**/
-#define REQUIRED_PCI_OFW_NODES 2
-#define REQUIRED_MMIO_OFW_NODES 1
-#define EXAMINED_OFW_NODES 6
-
+#define REQUIRED_PCI_OFW_NODES 2
+#define REQUIRED_MMIO_OFW_NODES 1
+#define EXAMINED_OFW_NODES 6
/**
Simple character classification routines, corresponding to POSIX class names
@@ -49,7 +48,7 @@
STATIC
BOOLEAN
IsAlnum (
- IN CHAR8 Chr
+ IN CHAR8 Chr
)
{
return (('0' <= Chr && Chr <= '9') ||
@@ -58,11 +57,10 @@ IsAlnum (
);
}
-
STATIC
BOOLEAN
IsDriverNamePunct (
- IN CHAR8 Chr
+ IN CHAR8 Chr
)
{
return (Chr == ',' || Chr == '.' || Chr == '_' ||
@@ -70,27 +68,24 @@ IsDriverNamePunct (
);
}
-
STATIC
BOOLEAN
IsPrintNotDelim (
- IN CHAR8 Chr
+ IN CHAR8 Chr
)
{
return (32 <= Chr && Chr <= 126 &&
Chr != '/' && Chr != '@' && Chr != ':');
}
-
/**
Utility types and functions.
**/
typedef struct {
- CONST CHAR8 *Ptr; // not necessarily NUL-terminated
- UINTN Len; // number of non-NUL characters
+ CONST CHAR8 *Ptr; // not necessarily NUL-terminated
+ UINTN Len; // number of non-NUL characters
} SUBSTRING;
-
/**
Check if Substring and String have identical contents.
@@ -109,12 +104,12 @@ typedef struct {
STATIC
BOOLEAN
SubstringEq (
- IN SUBSTRING Substring,
- IN CONST CHAR8 *String
+ IN SUBSTRING Substring,
+ IN CONST CHAR8 *String
)
{
- UINTN Pos;
- CONST CHAR8 *Chr;
+ UINTN Pos;
+ CONST CHAR8 *Chr;
Pos = 0;
Chr = String;
@@ -127,7 +122,6 @@ SubstringEq (
return (BOOLEAN)(Pos == Substring.Len && *Chr == '\0');
}
-
/**
Parse a comma-separated list of hexadecimal integers into the elements of an
@@ -175,38 +169,41 @@ ParseUnitAddressHexList (
IN OUT UINTN *NumResults
)
{
- UINTN Entry; // number of entry currently being parsed
- UINT64 EntryVal; // value being constructed for current entry
- CHAR8 PrevChr; // UnitAddress character previously checked
- UINTN Pos; // current position within UnitAddress
- RETURN_STATUS Status;
+ UINTN Entry; // number of entry currently being parsed
+ UINT64 EntryVal; // value being constructed for current entry
+ CHAR8 PrevChr; // UnitAddress character previously checked
+ UINTN Pos; // current position within UnitAddress
+ RETURN_STATUS Status;
Entry = 0;
EntryVal = 0;
PrevChr = ',';
for (Pos = 0; Pos < UnitAddress.Len; ++Pos) {
- CHAR8 Chr;
- INT8 Val;
+ CHAR8 Chr;
+ INT8 Val;
Chr = UnitAddress.Ptr[Pos];
Val = ('a' <= Chr && Chr <= 'f') ? (Chr - 'a' + 10) :
('A' <= Chr && Chr <= 'F') ? (Chr - 'A' + 10) :
- ('0' <= Chr && Chr <= '9') ? (Chr - '0' ) :
+ ('0' <= Chr && Chr <= '9') ? (Chr - '0') :
-1;
if (Val >= 0) {
if (EntryVal > 0xFFFFFFFFFFFFFFFull) {
return RETURN_INVALID_PARAMETER;
}
+
EntryVal = LShiftU64 (EntryVal, 4) | Val;
} else if (Chr == ',') {
if (PrevChr == ',') {
return RETURN_INVALID_PARAMETER;
}
+
if (Entry < *NumResults) {
Result[Entry] = EntryVal;
}
+
++Entry;
EntryVal = 0;
} else {
@@ -219,41 +216,40 @@ ParseUnitAddressHexList (
if (PrevChr == ',') {
return RETURN_INVALID_PARAMETER;
}
+
if (Entry < *NumResults) {
Result[Entry] = EntryVal;
- Status = RETURN_SUCCESS;
+ Status = RETURN_SUCCESS;
} else {
Status = RETURN_BUFFER_TOO_SMALL;
}
+
++Entry;
*NumResults = Entry;
return Status;
}
-
/**
A simple array of Boot Option ID's.
**/
typedef struct {
- UINT16 *Data;
- UINTN Allocated;
- UINTN Produced;
+ UINT16 *Data;
+ UINTN Allocated;
+ UINTN Produced;
} BOOT_ORDER;
-
/**
Array element tracking an enumerated boot option that has the
LOAD_OPTION_ACTIVE attribute.
**/
typedef struct {
- CONST EFI_BOOT_MANAGER_LOAD_OPTION *BootOption; // reference only, no
- // ownership
- BOOLEAN Appended; // has been added to a
- // BOOT_ORDER?
+ CONST EFI_BOOT_MANAGER_LOAD_OPTION *BootOption; // reference only, no
+ // ownership
+ BOOLEAN Appended; // has been added to a
+ // BOOT_ORDER?
} ACTIVE_OPTION;
-
/**
Append an active boot option to BootOrder, reallocating the latter if needed.
@@ -273,35 +269,35 @@ typedef struct {
STATIC
RETURN_STATUS
BootOrderAppend (
- IN OUT BOOT_ORDER *BootOrder,
- IN OUT ACTIVE_OPTION *ActiveOption
+ IN OUT BOOT_ORDER *BootOrder,
+ IN OUT ACTIVE_OPTION *ActiveOption
)
{
if (BootOrder->Produced == BootOrder->Allocated) {
- UINTN AllocatedNew;
- UINT16 *DataNew;
+ UINTN AllocatedNew;
+ UINT16 *DataNew;
ASSERT (BootOrder->Allocated > 0);
AllocatedNew = BootOrder->Allocated * 2;
- DataNew = ReallocatePool (
- BootOrder->Allocated * sizeof (*BootOrder->Data),
- AllocatedNew * sizeof (*DataNew),
- BootOrder->Data
- );
+ DataNew = ReallocatePool (
+ BootOrder->Allocated * sizeof (*BootOrder->Data),
+ AllocatedNew * sizeof (*DataNew),
+ BootOrder->Data
+ );
if (DataNew == NULL) {
return RETURN_OUT_OF_RESOURCES;
}
+
BootOrder->Allocated = AllocatedNew;
BootOrder->Data = DataNew;
}
BootOrder->Data[BootOrder->Produced++] =
- (UINT16) ActiveOption->BootOption->OptionNumber;
+ (UINT16)ActiveOption->BootOption->OptionNumber;
ActiveOption->Appended = TRUE;
return RETURN_SUCCESS;
}
-
/**
Create an array of ACTIVE_OPTION elements for a boot option array.
@@ -330,14 +326,14 @@ BootOrderAppend (
STATIC
RETURN_STATUS
CollectActiveOptions (
- IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions,
- IN UINTN BootOptionCount,
- OUT ACTIVE_OPTION **ActiveOption,
- OUT UINTN *Count
+ IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions,
+ IN UINTN BootOptionCount,
+ OUT ACTIVE_OPTION **ActiveOption,
+ OUT UINTN *Count
)
{
- UINTN Index;
- UINTN ScanMode;
+ UINTN Index;
+ UINTN ScanMode;
*ActiveOption = NULL;
@@ -354,6 +350,7 @@ CollectActiveOptions (
(*ActiveOption)[*Count].BootOption = &BootOptions[Index];
(*ActiveOption)[*Count].Appended = FALSE;
}
+
++*Count;
}
}
@@ -362,26 +359,26 @@ CollectActiveOptions (
if (*Count == 0) {
return RETURN_NOT_FOUND;
}
+
*ActiveOption = AllocatePool (*Count * sizeof **ActiveOption);
if (*ActiveOption == NULL) {
return RETURN_OUT_OF_RESOURCES;
}
}
}
+
return RETURN_SUCCESS;
}
-
/**
OpenFirmware device path node
**/
typedef struct {
- SUBSTRING DriverName;
- SUBSTRING UnitAddress;
- SUBSTRING DeviceArguments;
+ SUBSTRING DriverName;
+ SUBSTRING UnitAddress;
+ SUBSTRING DeviceArguments;
} OFW_NODE;
-
/**
Parse an OpenFirmware device path node into the caller-allocated OFW_NODE
@@ -430,24 +427,24 @@ typedef struct {
STATIC
RETURN_STATUS
ParseOfwNode (
- IN OUT CONST CHAR8 **Ptr,
- OUT OFW_NODE *OfwNode,
- OUT BOOLEAN *IsFinal
+ IN OUT CONST CHAR8 **Ptr,
+ OUT OFW_NODE *OfwNode,
+ OUT BOOLEAN *IsFinal
)
{
//
// A leading slash is expected. End of string is tolerated.
//
switch (**Ptr) {
- case '\0':
- return RETURN_NOT_FOUND;
+ case '\0':
+ return RETURN_NOT_FOUND;
- case '/':
- ++*Ptr;
- break;
+ case '/':
+ ++*Ptr;
+ break;
- default:
- return RETURN_INVALID_PARAMETER;
+ default:
+ return RETURN_INVALID_PARAMETER;
}
//
@@ -457,22 +454,23 @@ ParseOfwNode (
OfwNode->DriverName.Len = 0;
while (OfwNode->DriverName.Len < 32 &&
(IsAlnum (**Ptr) || IsDriverNamePunct (**Ptr))
- ) {
+ )
+ {
++*Ptr;
++OfwNode->DriverName.Len;
}
- if (OfwNode->DriverName.Len == 0 || OfwNode->DriverName.Len == 32) {
+ if ((OfwNode->DriverName.Len == 0) || (OfwNode->DriverName.Len == 32)) {
return RETURN_INVALID_PARAMETER;
}
-
//
// unit-address
//
if (**Ptr != '@') {
return RETURN_INVALID_PARAMETER;
}
+
++*Ptr;
OfwNode->UnitAddress.Ptr = *Ptr;
@@ -486,7 +484,6 @@ ParseOfwNode (
return RETURN_INVALID_PARAMETER;
}
-
//
// device-arguments, may be omitted
//
@@ -503,43 +500,43 @@ ParseOfwNode (
if (OfwNode->DeviceArguments.Len == 0) {
return RETURN_INVALID_PARAMETER;
}
- }
- else {
+ } else {
OfwNode->DeviceArguments.Ptr = NULL;
}
switch (**Ptr) {
- case '\n':
- ++*Ptr;
+ case '\n':
+ ++*Ptr;
//
// fall through
//
- case '\0':
- *IsFinal = TRUE;
- break;
+ case '\0':
+ *IsFinal = TRUE;
+ break;
- case '/':
- *IsFinal = FALSE;
- break;
+ case '/':
+ *IsFinal = FALSE;
+ break;
- default:
- return RETURN_INVALID_PARAMETER;
+ default:
+ return RETURN_INVALID_PARAMETER;
}
DEBUG ((
DEBUG_VERBOSE,
"%a: DriverName=\"%.*a\" UnitAddress=\"%.*a\" DeviceArguments=\"%.*a\"\n",
__FUNCTION__,
- OfwNode->DriverName.Len, OfwNode->DriverName.Ptr,
- OfwNode->UnitAddress.Len, OfwNode->UnitAddress.Ptr,
+ OfwNode->DriverName.Len,
+ OfwNode->DriverName.Ptr,
+ OfwNode->UnitAddress.Len,
+ OfwNode->UnitAddress.Ptr,
OfwNode->DeviceArguments.Len,
OfwNode->DeviceArguments.Ptr == NULL ? "" : OfwNode->DeviceArguments.Ptr
));
return RETURN_SUCCESS;
}
-
/**
Translate a PCI-like array of OpenFirmware device nodes to a UEFI device path
@@ -584,21 +581,21 @@ ParseOfwNode (
STATIC
RETURN_STATUS
TranslatePciOfwNodes (
- IN CONST OFW_NODE *OfwNode,
- IN UINTN NumNodes,
- IN CONST EXTRA_ROOT_BUS_MAP *ExtraPciRoots,
- OUT CHAR16 *Translated,
- IN OUT UINTN *TranslatedSize
+ IN CONST OFW_NODE *OfwNode,
+ IN UINTN NumNodes,
+ IN CONST EXTRA_ROOT_BUS_MAP *ExtraPciRoots,
+ OUT CHAR16 *Translated,
+ IN OUT UINTN *TranslatedSize
)
{
- UINT32 PciRoot;
- CHAR8 *Comma;
- UINTN FirstNonBridge;
- CHAR16 Bridges[BRIDGE_TRANSLATION_OUTPUT_SIZE];
- UINTN BridgesLen;
- UINT64 PciDevFun[2];
- UINTN NumEntries;
- UINTN Written;
+ UINT32 PciRoot;
+ CHAR8 *Comma;
+ UINTN FirstNonBridge;
+ CHAR16 Bridges[BRIDGE_TRANSLATION_OUTPUT_SIZE];
+ UINTN BridgesLen;
+ UINT64 PciDevFun[2];
+ UINTN NumEntries;
+ UINTN Written;
//
// Resolve the PCI root bus number.
@@ -613,18 +610,22 @@ TranslatePciOfwNodes (
// ^
// root bus serial number (not PCI bus number)
//
- if (NumNodes < REQUIRED_PCI_OFW_NODES ||
+ if ((NumNodes < REQUIRED_PCI_OFW_NODES) ||
!SubstringEq (OfwNode[0].DriverName, "pci")
- ) {
+ )
+ {
return RETURN_UNSUPPORTED;
}
PciRoot = 0;
- Comma = ScanMem8 (OfwNode[0].UnitAddress.Ptr, OfwNode[0].UnitAddress.Len,
- ',');
+ Comma = ScanMem8 (
+ OfwNode[0].UnitAddress.Ptr,
+ OfwNode[0].UnitAddress.Len,
+ ','
+ );
if (Comma != NULL) {
- SUBSTRING PciRootSerialSubString;
- UINT64 PciRootSerial;
+ SUBSTRING PciRootSerialSubString;
+ UINT64 PciRootSerial;
//
// Parse the root bus serial number from the unit address after the comma.
@@ -634,16 +635,28 @@ TranslatePciOfwNodes (
(PciRootSerialSubString.Ptr -
OfwNode[0].UnitAddress.Ptr);
NumEntries = 1;
- if (RETURN_ERROR (ParseUnitAddressHexList (PciRootSerialSubString,
- &PciRootSerial, &NumEntries))) {
+ if (RETURN_ERROR (
+ ParseUnitAddressHexList (
+ PciRootSerialSubString,
+ &PciRootSerial,
+ &NumEntries
+ )
+ ))
+ {
return RETURN_UNSUPPORTED;
}
//
// Map the extra root bus's serial number to its actual bus number.
//
- if (EFI_ERROR (MapRootBusPosToBusNr (ExtraPciRoots, PciRootSerial,
- &PciRoot))) {
+ if (EFI_ERROR (
+ MapRootBusPosToBusNr (
+ ExtraPciRoots,
+ PciRootSerial,
+ &PciRoot
+ )
+ ))
+ {
return RETURN_PROTOCOL_ERROR;
}
}
@@ -660,26 +673,35 @@ TranslatePciOfwNodes (
// Pci(0x1E,0x0)
//
FirstNonBridge = 1;
- Bridges[0] = L'\0';
- BridgesLen = 0;
+ Bridges[0] = L'\0';
+ BridgesLen = 0;
do {
- UINT64 BridgeDevFun[2];
- UINTN BridgesFreeBytes;
+ UINT64 BridgeDevFun[2];
+ UINTN BridgesFreeBytes;
if (!SubstringEq (OfwNode[FirstNonBridge].DriverName, "pci-bridge")) {
break;
}
BridgeDevFun[1] = 0;
- NumEntries = sizeof BridgeDevFun / sizeof BridgeDevFun[0];
- if (ParseUnitAddressHexList (OfwNode[FirstNonBridge].UnitAddress,
- BridgeDevFun, &NumEntries) != RETURN_SUCCESS) {
+ NumEntries = sizeof BridgeDevFun / sizeof BridgeDevFun[0];
+ if (ParseUnitAddressHexList (
+ OfwNode[FirstNonBridge].UnitAddress,
+ BridgeDevFun,
+ &NumEntries
+ ) != RETURN_SUCCESS)
+ {
return RETURN_UNSUPPORTED;
}
BridgesFreeBytes = sizeof Bridges - BridgesLen * sizeof Bridges[0];
- Written = UnicodeSPrintAsciiFormat (Bridges + BridgesLen, BridgesFreeBytes,
- "/Pci(0x%Lx,0x%Lx)", BridgeDevFun[0], BridgeDevFun[1]);
+ Written = UnicodeSPrintAsciiFormat (
+ Bridges + BridgesLen,
+ BridgesFreeBytes,
+ "/Pci(0x%Lx,0x%Lx)",
+ BridgeDevFun[0],
+ BridgeDevFun[1]
+ );
BridgesLen += Written;
//
@@ -701,21 +723,23 @@ TranslatePciOfwNodes (
// Parse the OFW nodes starting with the first non-bridge node.
//
PciDevFun[1] = 0;
- NumEntries = ARRAY_SIZE (PciDevFun);
+ NumEntries = ARRAY_SIZE (PciDevFun);
if (ParseUnitAddressHexList (
OfwNode[FirstNonBridge].UnitAddress,
PciDevFun,
&NumEntries
) != RETURN_SUCCESS
- ) {
+ )
+ {
return RETURN_UNSUPPORTED;
}
- if (NumNodes >= FirstNonBridge + 3 &&
+ if ((NumNodes >= FirstNonBridge + 3) &&
SubstringEq (OfwNode[FirstNonBridge + 0].DriverName, "ide") &&
SubstringEq (OfwNode[FirstNonBridge + 1].DriverName, "drive") &&
SubstringEq (OfwNode[FirstNonBridge + 2].DriverName, "disk")
- ) {
+ )
+ {
//
// OpenFirmware device path (IDE disk, IDE CD-ROM):
//
@@ -732,42 +756,44 @@ TranslatePciOfwNodes (
// ^
// fixed LUN
//
- UINT64 Secondary;
- UINT64 Slave;
+ UINT64 Secondary;
+ UINT64 Slave;
NumEntries = 1;
- if (ParseUnitAddressHexList (
- OfwNode[FirstNonBridge + 1].UnitAddress,
- &Secondary,
- &NumEntries
- ) != RETURN_SUCCESS ||
- Secondary > 1 ||
- ParseUnitAddressHexList (
- OfwNode[FirstNonBridge + 2].UnitAddress,
- &Slave,
- &NumEntries // reuse after previous single-element call
- ) != RETURN_SUCCESS ||
- Slave > 1
- ) {
+ if ((ParseUnitAddressHexList (
+ OfwNode[FirstNonBridge + 1].UnitAddress,
+ &Secondary,
+ &NumEntries
+ ) != RETURN_SUCCESS) ||
+ (Secondary > 1) ||
+ (ParseUnitAddressHexList (
+ OfwNode[FirstNonBridge + 2].UnitAddress,
+ &Slave,
+ &NumEntries // reuse after previous single-element call
+ ) != RETURN_SUCCESS) ||
+ (Slave > 1)
+ )
+ {
return RETURN_UNSUPPORTED;
}
Written = UnicodeSPrintAsciiFormat (
- Translated,
- *TranslatedSize * sizeof (*Translated), // BufferSize in bytes
- "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)/Ata(%a,%a,0x0)",
- PciRoot,
- Bridges,
- PciDevFun[0],
- PciDevFun[1],
- Secondary ? "Secondary" : "Primary",
- Slave ? "Slave" : "Master"
- );
- } else if (NumNodes >= FirstNonBridge + 3 &&
- SubstringEq (OfwNode[FirstNonBridge + 0].DriverName, "pci8086,2922") &&
- SubstringEq (OfwNode[FirstNonBridge + 1].DriverName, "drive") &&
- SubstringEq (OfwNode[FirstNonBridge + 2].DriverName, "disk")
- ) {
+ Translated,
+ *TranslatedSize * sizeof (*Translated), // BufferSize in bytes
+ "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)/Ata(%a,%a,0x0)",
+ PciRoot,
+ Bridges,
+ PciDevFun[0],
+ PciDevFun[1],
+ Secondary ? "Secondary" : "Primary",
+ Slave ? "Slave" : "Master"
+ );
+ } else if ((NumNodes >= FirstNonBridge + 3) &&
+ SubstringEq (OfwNode[FirstNonBridge + 0].DriverName, "pci8086,2922") &&
+ SubstringEq (OfwNode[FirstNonBridge + 1].DriverName, "drive") &&
+ SubstringEq (OfwNode[FirstNonBridge + 2].DriverName, "disk")
+ )
+ {
//
// OpenFirmware device path (Q35 SATA disk and CD-ROM):
//
@@ -787,30 +813,36 @@ TranslatePciOfwNodes (
// | always 0xFFFF on Q35
// channel (port) number
//
- UINT64 Channel;
+ UINT64 Channel;
NumEntries = 1;
- if (RETURN_ERROR (ParseUnitAddressHexList (
- OfwNode[FirstNonBridge + 1].UnitAddress, &Channel,
- &NumEntries))) {
+ if (RETURN_ERROR (
+ ParseUnitAddressHexList (
+ OfwNode[FirstNonBridge + 1].UnitAddress,
+ &Channel,
+ &NumEntries
+ )
+ ))
+ {
return RETURN_UNSUPPORTED;
}
Written = UnicodeSPrintAsciiFormat (
- Translated,
- *TranslatedSize * sizeof (*Translated), // BufferSize in bytes
- "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)/Sata(0x%Lx,0xFFFF,0x0)",
- PciRoot,
- Bridges,
- PciDevFun[0],
- PciDevFun[1],
- Channel
- );
- } else if (NumNodes >= FirstNonBridge + 3 &&
+ Translated,
+ *TranslatedSize * sizeof (*Translated), // BufferSize in bytes
+ "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)/Sata(0x%Lx,0xFFFF,0x0)",
+ PciRoot,
+ Bridges,
+ PciDevFun[0],
+ PciDevFun[1],
+ Channel
+ );
+ } else if ((NumNodes >= FirstNonBridge + 3) &&
SubstringEq (OfwNode[FirstNonBridge + 0].DriverName, "isa") &&
SubstringEq (OfwNode[FirstNonBridge + 1].DriverName, "fdc") &&
SubstringEq (OfwNode[FirstNonBridge + 2].DriverName, "floppy")
- ) {
+ )
+ {
//
// OpenFirmware device path (floppy disk):
//
@@ -827,33 +859,35 @@ TranslatePciOfwNodes (
// ^
// ACPI UID
//
- UINT64 AcpiUid;
+ UINT64 AcpiUid;
NumEntries = 1;
- if (ParseUnitAddressHexList (
- OfwNode[FirstNonBridge + 2].UnitAddress,
- &AcpiUid,
- &NumEntries
- ) != RETURN_SUCCESS ||
- AcpiUid > 1
- ) {
+ if ((ParseUnitAddressHexList (
+ OfwNode[FirstNonBridge + 2].UnitAddress,
+ &AcpiUid,
+ &NumEntries
+ ) != RETURN_SUCCESS) ||
+ (AcpiUid > 1)
+ )
+ {
return RETURN_UNSUPPORTED;
}
Written = UnicodeSPrintAsciiFormat (
- Translated,
- *TranslatedSize * sizeof (*Translated), // BufferSize in bytes
- "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)/Floppy(0x%Lx)",
- PciRoot,
- Bridges,
- PciDevFun[0],
- PciDevFun[1],
- AcpiUid
- );
- } else if (NumNodes >= FirstNonBridge + 2 &&
+ Translated,
+ *TranslatedSize * sizeof (*Translated), // BufferSize in bytes
+ "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)/Floppy(0x%Lx)",
+ PciRoot,
+ Bridges,
+ PciDevFun[0],
+ PciDevFun[1],
+ AcpiUid
+ );
+ } else if ((NumNodes >= FirstNonBridge + 2) &&
SubstringEq (OfwNode[FirstNonBridge + 0].DriverName, "scsi") &&
SubstringEq (OfwNode[FirstNonBridge + 1].DriverName, "disk")
- ) {
+ )
+ {
//
// OpenFirmware device path (virtio-blk disk):
//
@@ -870,19 +904,20 @@ TranslatePciOfwNodes (
// PciRoot(0x0)/Pci(0x6,0x3) -- if PCI function is present and nonzero
//
Written = UnicodeSPrintAsciiFormat (
- Translated,
- *TranslatedSize * sizeof (*Translated), // BufferSize in bytes
- "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)",
- PciRoot,
- Bridges,
- PciDevFun[0],
- PciDevFun[1]
- );
- } else if (NumNodes >= FirstNonBridge + 3 &&
+ Translated,
+ *TranslatedSize * sizeof (*Translated), // BufferSize in bytes
+ "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)",
+ PciRoot,
+ Bridges,
+ PciDevFun[0],
+ PciDevFun[1]
+ );
+ } else if ((NumNodes >= FirstNonBridge + 3) &&
SubstringEq (OfwNode[FirstNonBridge + 0].DriverName, "scsi") &&
SubstringEq (OfwNode[FirstNonBridge + 1].DriverName, "channel") &&
SubstringEq (OfwNode[FirstNonBridge + 2].DriverName, "disk")
- ) {
+ )
+ {
//
// OpenFirmware device path (virtio-scsi disk):
//
@@ -901,34 +936,36 @@ TranslatePciOfwNodes (
// PciRoot(0x0)/Pci(0x7,0x3)/Scsi(0x2,0x3)
// -- if PCI function is present and nonzero
//
- UINT64 TargetLun[2];
+ UINT64 TargetLun[2];
TargetLun[1] = 0;
- NumEntries = ARRAY_SIZE (TargetLun);
+ NumEntries = ARRAY_SIZE (TargetLun);
if (ParseUnitAddressHexList (
OfwNode[FirstNonBridge + 2].UnitAddress,
TargetLun,
&NumEntries
) != RETURN_SUCCESS
- ) {
+ )
+ {
return RETURN_UNSUPPORTED;
}
Written = UnicodeSPrintAsciiFormat (
- Translated,
- *TranslatedSize * sizeof (*Translated), // BufferSize in bytes
- "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)/Scsi(0x%Lx,0x%Lx)",
- PciRoot,
- Bridges,
- PciDevFun[0],
- PciDevFun[1],
- TargetLun[0],
- TargetLun[1]
- );
- } else if (NumNodes >= FirstNonBridge + 2 &&
- SubstringEq (OfwNode[FirstNonBridge + 0].DriverName, "pci8086,5845") &&
- SubstringEq (OfwNode[FirstNonBridge + 1].DriverName, "namespace")
- ) {
+ Translated,
+ *TranslatedSize * sizeof (*Translated), // BufferSize in bytes
+ "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)/Scsi(0x%Lx,0x%Lx)",
+ PciRoot,
+ Bridges,
+ PciDevFun[0],
+ PciDevFun[1],
+ TargetLun[0],
+ TargetLun[1]
+ );
+ } else if ((NumNodes >= FirstNonBridge + 2) &&
+ SubstringEq (OfwNode[FirstNonBridge + 0].DriverName, "pci8086,5845") &&
+ SubstringEq (OfwNode[FirstNonBridge + 1].DriverName, "namespace")
+ )
+ {
//
// OpenFirmware device path (NVMe device):
//
@@ -948,41 +985,49 @@ TranslatePciOfwNodes (
// | in address order
// namespace ID
//
- UINT64 Namespace[2];
- UINTN RequiredEntries;
- UINT8 *Eui64;
+ UINT64 Namespace[2];
+ UINTN RequiredEntries;
+ UINT8 *Eui64;
RequiredEntries = ARRAY_SIZE (Namespace);
- NumEntries = RequiredEntries;
- if (ParseUnitAddressHexList (
- OfwNode[FirstNonBridge + 1].UnitAddress,
- Namespace,
- &NumEntries
- ) != RETURN_SUCCESS ||
- NumEntries != RequiredEntries ||
- Namespace[0] == 0 ||
- Namespace[0] >= MAX_UINT32
- ) {
+ NumEntries = RequiredEntries;
+ if ((ParseUnitAddressHexList (
+ OfwNode[FirstNonBridge + 1].UnitAddress,
+ Namespace,
+ &NumEntries
+ ) != RETURN_SUCCESS) ||
+ (NumEntries != RequiredEntries) ||
+ (Namespace[0] == 0) ||
+ (Namespace[0] >= MAX_UINT32)
+ )
+ {
return RETURN_UNSUPPORTED;
}
- Eui64 = (UINT8 *)&Namespace[1];
+ Eui64 = (UINT8 *)&Namespace[1];
Written = UnicodeSPrintAsciiFormat (
- Translated,
- *TranslatedSize * sizeof (*Translated), // BufferSize in bytes
- "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)/"
- "NVMe(0x%Lx,%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x)",
- PciRoot,
- Bridges,
- PciDevFun[0],
- PciDevFun[1],
- Namespace[0],
- Eui64[7], Eui64[6], Eui64[5], Eui64[4],
- Eui64[3], Eui64[2], Eui64[1], Eui64[0]
- );
- } else if (NumNodes >= FirstNonBridge + 2 &&
+ Translated,
+ *TranslatedSize * sizeof (*Translated), // BufferSize in bytes
+ "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)/"
+ "NVMe(0x%Lx,%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x)",
+ PciRoot,
+ Bridges,
+ PciDevFun[0],
+ PciDevFun[1],
+ Namespace[0],
+ Eui64[7],
+ Eui64[6],
+ Eui64[5],
+ Eui64[4],
+ Eui64[3],
+ Eui64[2],
+ Eui64[1],
+ Eui64[0]
+ );
+ } else if ((NumNodes >= FirstNonBridge + 2) &&
SubstringEq (OfwNode[FirstNonBridge + 0].DriverName, "usb") &&
- SubstringEq (OfwNode[FirstNonBridge + 1].DriverName, "storage")) {
+ SubstringEq (OfwNode[FirstNonBridge + 1].DriverName, "storage"))
+ {
//
// OpenFirmware device path (usb-storage device in XHCI port):
//
@@ -1001,16 +1046,16 @@ TranslatePciOfwNodes (
// | XHCI port number in 0-based notation
// 0x0 if PCI function is 0, or absent from OFW
//
- RETURN_STATUS ParseStatus;
- UINT64 OneBasedXhciPort;
+ RETURN_STATUS ParseStatus;
+ UINT64 OneBasedXhciPort;
- NumEntries = 1;
+ NumEntries = 1;
ParseStatus = ParseUnitAddressHexList (
OfwNode[FirstNonBridge + 1].UnitAddress,
&OneBasedXhciPort,
&NumEntries
);
- if (RETURN_ERROR (ParseStatus) || OneBasedXhciPort == 0) {
+ if (RETURN_ERROR (ParseStatus) || (OneBasedXhciPort == 0)) {
return RETURN_UNSUPPORTED;
}
@@ -1039,14 +1084,14 @@ TranslatePciOfwNodes (
// PciRoot(0x0)/Pci(0x3,0x2)
//
Written = UnicodeSPrintAsciiFormat (
- Translated,
- *TranslatedSize * sizeof (*Translated), // BufferSize in bytes
- "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)",
- PciRoot,
- Bridges,
- PciDevFun[0],
- PciDevFun[1]
- );
+ Translated,
+ *TranslatedSize * sizeof (*Translated), // BufferSize in bytes
+ "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)",
+ PciRoot,
+ Bridges,
+ PciDevFun[0],
+ PciDevFun[1]
+ );
}
//
@@ -1062,17 +1107,15 @@ TranslatePciOfwNodes (
return RETURN_BUFFER_TOO_SMALL;
}
-
//
// A type providing easy raw access to the base address of a virtio-mmio
// transport.
//
typedef union {
- UINT64 Uint64;
- UINT8 Raw[8];
+ UINT64 Uint64;
+ UINT8 Raw[8];
} VIRTIO_MMIO_BASE_ADDRESS;
-
/**
Translate an MMIO-like array of OpenFirmware device nodes to a UEFI device
@@ -1108,43 +1151,56 @@ typedef union {
STATIC
RETURN_STATUS
TranslateMmioOfwNodes (
- IN CONST OFW_NODE *OfwNode,
- IN UINTN NumNodes,
- OUT CHAR16 *Translated,
- IN OUT UINTN *TranslatedSize
+ IN CONST OFW_NODE *OfwNode,
+ IN UINTN NumNodes,
+ OUT CHAR16 *Translated,
+ IN OUT UINTN *TranslatedSize
)
{
- VIRTIO_MMIO_BASE_ADDRESS VirtioMmioBase;
- CHAR16 VenHwString[60 + 1];
- UINTN NumEntries;
- UINTN Written;
+ VIRTIO_MMIO_BASE_ADDRESS VirtioMmioBase;
+ CHAR16 VenHwString[60 + 1];
+ UINTN NumEntries;
+ UINTN Written;
//
// Get the base address of the virtio-mmio transport.
//
- if (NumNodes < REQUIRED_MMIO_OFW_NODES ||
+ if ((NumNodes < REQUIRED_MMIO_OFW_NODES) ||
!SubstringEq (OfwNode[0].DriverName, "virtio-mmio")
- ) {
+ )
+ {
return RETURN_UNSUPPORTED;
}
+
NumEntries = 1;
if (ParseUnitAddressHexList (
OfwNode[0].UnitAddress,
&VirtioMmioBase.Uint64,
&NumEntries
) != RETURN_SUCCESS
- ) {
+ )
+ {
return RETURN_UNSUPPORTED;
}
- UnicodeSPrintAsciiFormat (VenHwString, sizeof VenHwString,
- "VenHw(%g,%02X%02X%02X%02X%02X%02X%02X%02X)", &gVirtioMmioTransportGuid,
- VirtioMmioBase.Raw[0], VirtioMmioBase.Raw[1], VirtioMmioBase.Raw[2],
- VirtioMmioBase.Raw[3], VirtioMmioBase.Raw[4], VirtioMmioBase.Raw[5],
- VirtioMmioBase.Raw[6], VirtioMmioBase.Raw[7]);
-
- if (NumNodes >= 2 &&
- SubstringEq (OfwNode[1].DriverName, "disk")) {
+ UnicodeSPrintAsciiFormat (
+ VenHwString,
+ sizeof VenHwString,
+ "VenHw(%g,%02X%02X%02X%02X%02X%02X%02X%02X)",
+ &gVirtioMmioTransportGuid,
+ VirtioMmioBase.Raw[0],
+ VirtioMmioBase.Raw[1],
+ VirtioMmioBase.Raw[2],
+ VirtioMmioBase.Raw[3],
+ VirtioMmioBase.Raw[4],
+ VirtioMmioBase.Raw[5],
+ VirtioMmioBase.Raw[6],
+ VirtioMmioBase.Raw[7]
+ );
+
+ if ((NumNodes >= 2) &&
+ SubstringEq (OfwNode[1].DriverName, "disk"))
+ {
//
// OpenFirmware device path (virtio-blk disk):
//
@@ -1163,9 +1219,10 @@ TranslateMmioOfwNodes (
"%s",
VenHwString
);
- } else if (NumNodes >= 3 &&
+ } else if ((NumNodes >= 3) &&
SubstringEq (OfwNode[1].DriverName, "channel") &&
- SubstringEq (OfwNode[2].DriverName, "disk")) {
+ SubstringEq (OfwNode[2].DriverName, "disk"))
+ {
//
// OpenFirmware device path (virtio-scsi disk):
//
@@ -1180,16 +1237,17 @@ TranslateMmioOfwNodes (
//
// <VenHwString>/Scsi(0x2,0x3)
//
- UINT64 TargetLun[2];
+ UINT64 TargetLun[2];
TargetLun[1] = 0;
- NumEntries = ARRAY_SIZE (TargetLun);
+ NumEntries = ARRAY_SIZE (TargetLun);
if (ParseUnitAddressHexList (
OfwNode[2].UnitAddress,
TargetLun,
&NumEntries
) != RETURN_SUCCESS
- ) {
+ )
+ {
return RETURN_UNSUPPORTED;
}
@@ -1201,8 +1259,9 @@ TranslateMmioOfwNodes (
TargetLun[0],
TargetLun[1]
);
- } else if (NumNodes >= 2 &&
- SubstringEq (OfwNode[1].DriverName, "ethernet-phy")) {
+ } else if ((NumNodes >= 2) &&
+ SubstringEq (OfwNode[1].DriverName, "ethernet-phy"))
+ {
//
// OpenFirmware device path (virtio-net NIC):
//
@@ -1238,7 +1297,6 @@ TranslateMmioOfwNodes (
return RETURN_BUFFER_TOO_SMALL;
}
-
/**
Translate an array of OpenFirmware device nodes to a UEFI device path
@@ -1283,26 +1341,38 @@ TranslateMmioOfwNodes (
STATIC
RETURN_STATUS
TranslateOfwNodes (
- IN CONST OFW_NODE *OfwNode,
- IN UINTN NumNodes,
- IN CONST EXTRA_ROOT_BUS_MAP *ExtraPciRoots,
- OUT CHAR16 *Translated,
- IN OUT UINTN *TranslatedSize
+ IN CONST OFW_NODE *OfwNode,
+ IN UINTN NumNodes,
+ IN CONST EXTRA_ROOT_BUS_MAP *ExtraPciRoots,
+ OUT CHAR16 *Translated,
+ IN OUT UINTN *TranslatedSize
)
{
- RETURN_STATUS Status;
+ RETURN_STATUS Status;
Status = RETURN_UNSUPPORTED;
if (FeaturePcdGet (PcdQemuBootOrderPciTranslation)) {
- Status = TranslatePciOfwNodes (OfwNode, NumNodes, ExtraPciRoots,
- Translated, TranslatedSize);
+ Status = TranslatePciOfwNodes (
+ OfwNode,
+ NumNodes,
+ ExtraPciRoots,
+ Translated,
+ TranslatedSize
+ );
}
- if (Status == RETURN_UNSUPPORTED &&
- FeaturePcdGet (PcdQemuBootOrderMmioTranslation)) {
- Status = TranslateMmioOfwNodes (OfwNode, NumNodes, Translated,
- TranslatedSize);
+
+ if ((Status == RETURN_UNSUPPORTED) &&
+ FeaturePcdGet (PcdQemuBootOrderMmioTranslation))
+ {
+ Status = TranslateMmioOfwNodes (
+ OfwNode,
+ NumNodes,
+ Translated,
+ TranslatedSize
+ );
}
+
return Status;
}
@@ -1368,22 +1438,22 @@ TranslateOfwNodes (
STATIC
RETURN_STATUS
TranslateOfwPath (
- IN OUT CONST CHAR8 **Ptr,
- IN CONST EXTRA_ROOT_BUS_MAP *ExtraPciRoots,
- OUT CHAR16 *Translated,
- IN OUT UINTN *TranslatedSize
+ IN OUT CONST CHAR8 **Ptr,
+ IN CONST EXTRA_ROOT_BUS_MAP *ExtraPciRoots,
+ OUT CHAR16 *Translated,
+ IN OUT UINTN *TranslatedSize
)
{
- UINTN NumNodes;
- RETURN_STATUS Status;
- OFW_NODE Node[EXAMINED_OFW_NODES];
- BOOLEAN IsFinal;
- OFW_NODE Skip;
+ UINTN NumNodes;
+ RETURN_STATUS Status;
+ OFW_NODE Node[EXAMINED_OFW_NODES];
+ BOOLEAN IsFinal;
+ OFW_NODE Skip;
- IsFinal = FALSE;
+ IsFinal = FALSE;
NumNodes = 0;
if (AsciiStrCmp (*Ptr, "HALT") == 0) {
- *Ptr += 4;
+ *Ptr += 4;
Status = RETURN_NOT_FOUND;
} else {
Status = ParseOfwNode (Ptr, &Node[NumNodes], &IsFinal);
@@ -1404,16 +1474,16 @@ TranslateOfwPath (
}
switch (Status) {
- case RETURN_SUCCESS:
- ++NumNodes;
- break;
+ case RETURN_SUCCESS:
+ ++NumNodes;
+ break;
- case RETURN_INVALID_PARAMETER:
- DEBUG ((DEBUG_VERBOSE, "%a: parse error\n", __FUNCTION__));
- return RETURN_INVALID_PARAMETER;
+ case RETURN_INVALID_PARAMETER:
+ DEBUG ((DEBUG_VERBOSE, "%a: parse error\n", __FUNCTION__));
+ return RETURN_INVALID_PARAMETER;
- default:
- ASSERT (0);
+ default:
+ ASSERT (0);
}
Status = TranslateOfwNodes (
@@ -1421,32 +1491,36 @@ TranslateOfwPath (
NumNodes < EXAMINED_OFW_NODES ? NumNodes : EXAMINED_OFW_NODES,
ExtraPciRoots,
Translated,
- TranslatedSize);
+ TranslatedSize
+ );
switch (Status) {
- case RETURN_SUCCESS:
- DEBUG ((DEBUG_VERBOSE, "%a: success: \"%s\"\n", __FUNCTION__, Translated));
- break;
+ case RETURN_SUCCESS:
+ DEBUG ((DEBUG_VERBOSE, "%a: success: \"%s\"\n", __FUNCTION__, Translated));
+ break;
- case RETURN_BUFFER_TOO_SMALL:
- DEBUG ((DEBUG_VERBOSE, "%a: buffer too small\n", __FUNCTION__));
- break;
+ case RETURN_BUFFER_TOO_SMALL:
+ DEBUG ((DEBUG_VERBOSE, "%a: buffer too small\n", __FUNCTION__));
+ break;
- case RETURN_UNSUPPORTED:
- DEBUG ((DEBUG_VERBOSE, "%a: unsupported\n", __FUNCTION__));
- break;
+ case RETURN_UNSUPPORTED:
+ DEBUG ((DEBUG_VERBOSE, "%a: unsupported\n", __FUNCTION__));
+ break;
- case RETURN_PROTOCOL_ERROR:
- DEBUG ((DEBUG_VERBOSE, "%a: logic error / system state mismatch\n",
- __FUNCTION__));
- break;
+ case RETURN_PROTOCOL_ERROR:
+ DEBUG ((
+ DEBUG_VERBOSE,
+ "%a: logic error / system state mismatch\n",
+ __FUNCTION__
+ ));
+ break;
- default:
- ASSERT (0);
+ default:
+ ASSERT (0);
}
+
return Status;
}
-
/**
Connect devices based on the boot order retrieved from QEMU.
@@ -1481,16 +1555,16 @@ ConnectDevicesFromQemu (
VOID
)
{
- RETURN_STATUS Status;
- FIRMWARE_CONFIG_ITEM FwCfgItem;
- UINTN FwCfgSize;
- CHAR8 *FwCfg;
- EFI_STATUS EfiStatus;
- EXTRA_ROOT_BUS_MAP *ExtraPciRoots;
- CONST CHAR8 *FwCfgPtr;
- UINTN NumConnected;
- UINTN TranslatedSize;
- CHAR16 Translated[TRANSLATION_OUTPUT_SIZE];
+ RETURN_STATUS Status;
+ FIRMWARE_CONFIG_ITEM FwCfgItem;
+ UINTN FwCfgSize;
+ CHAR8 *FwCfg;
+ EFI_STATUS EfiStatus;
+ EXTRA_ROOT_BUS_MAP *ExtraPciRoots;
+ CONST CHAR8 *FwCfgPtr;
+ UINTN NumConnected;
+ UINTN TranslatedSize;
+ CHAR16 Translated[TRANSLATION_OUTPUT_SIZE];
Status = QemuFwCfgFindFile ("bootorder", &FwCfgItem, &FwCfgSize);
if (RETURN_ERROR (Status)) {
@@ -1512,6 +1586,7 @@ ConnectDevicesFromQemu (
Status = RETURN_INVALID_PARAMETER;
goto FreeFwCfg;
}
+
DEBUG ((DEBUG_VERBOSE, "%a: FwCfg:\n", __FUNCTION__));
DEBUG ((DEBUG_VERBOSE, "%a\n", FwCfg));
DEBUG ((DEBUG_VERBOSE, "%a: FwCfg: <end>\n", __FUNCTION__));
@@ -1529,14 +1604,18 @@ ConnectDevicesFromQemu (
//
// Translate each OpenFirmware path to a UEFI devpath prefix.
//
- FwCfgPtr = FwCfg;
- NumConnected = 0;
+ FwCfgPtr = FwCfg;
+ NumConnected = 0;
TranslatedSize = ARRAY_SIZE (Translated);
- Status = TranslateOfwPath (&FwCfgPtr, ExtraPciRoots, Translated,
- &TranslatedSize);
+ Status = TranslateOfwPath (
+ &FwCfgPtr,
+ ExtraPciRoots,
+ Translated,
+ &TranslatedSize
+ );
while (!RETURN_ERROR (Status)) {
- EFI_DEVICE_PATH_PROTOCOL *DevicePath;
- EFI_HANDLE Controller;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ EFI_HANDLE Controller;
//
// Convert the UEFI devpath prefix to binary representation.
@@ -1547,6 +1626,7 @@ ConnectDevicesFromQemu (
Status = RETURN_OUT_OF_RESOURCES;
goto FreeExtraPciRoots;
}
+
//
// Advance along DevicePath, connecting the nodes individually, and asking
// drivers not to produce sibling nodes. Retrieve the controller handle
@@ -1559,6 +1639,7 @@ ConnectDevicesFromQemu (
Status = (RETURN_STATUS)EfiStatus;
goto FreeExtraPciRoots;
}
+
//
// Because QEMU's OFW devpaths have lesser expressive power than UEFI
// devpaths (i.e., DevicePath is considered a prefix), connect the tree
@@ -1566,22 +1647,31 @@ ConnectDevicesFromQemu (
// (EFI_NOT_FOUND), that's OK.
//
EfiStatus = gBS->ConnectController (Controller, NULL, NULL, TRUE);
- if (EFI_ERROR (EfiStatus) && EfiStatus != EFI_NOT_FOUND) {
+ if (EFI_ERROR (EfiStatus) && (EfiStatus != EFI_NOT_FOUND)) {
Status = (RETURN_STATUS)EfiStatus;
goto FreeExtraPciRoots;
}
+
++NumConnected;
//
// Move to the next OFW devpath.
//
TranslatedSize = ARRAY_SIZE (Translated);
- Status = TranslateOfwPath (&FwCfgPtr, ExtraPciRoots, Translated,
- &TranslatedSize);
+ Status = TranslateOfwPath (
+ &FwCfgPtr,
+ ExtraPciRoots,
+ Translated,
+ &TranslatedSize
+ );
}
- if (Status == RETURN_NOT_FOUND && NumConnected > 0) {
- DEBUG ((DEBUG_INFO, "%a: %Lu OpenFirmware device path(s) connected\n",
- __FUNCTION__, (UINT64)NumConnected));
+ if ((Status == RETURN_NOT_FOUND) && (NumConnected > 0)) {
+ DEBUG ((
+ DEBUG_INFO,
+ "%a: %Lu OpenFirmware device path(s) connected\n",
+ __FUNCTION__,
+ (UINT64)NumConnected
+ ));
Status = RETURN_SUCCESS;
}
@@ -1596,7 +1686,6 @@ FreeFwCfg:
return Status;
}
-
/**
Convert the UEFI DevicePath to full text representation with DevPathToText,
@@ -1623,19 +1712,19 @@ FreeFwCfg:
STATIC
BOOLEAN
Match (
- IN CONST CHAR16 *Translated,
- IN UINTN TranslatedLength,
- IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
+ IN CONST CHAR16 *Translated,
+ IN UINTN TranslatedLength,
+ IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
- CHAR16 *Converted;
- BOOLEAN Result;
- VOID *FileBuffer;
- UINTN FileSize;
- EFI_DEVICE_PATH_PROTOCOL *AbsDevicePath;
- CHAR16 *AbsConverted;
- BOOLEAN Shortform;
- EFI_DEVICE_PATH_PROTOCOL *Node;
+ CHAR16 *Converted;
+ BOOLEAN Result;
+ VOID *FileBuffer;
+ UINTN FileSize;
+ EFI_DEVICE_PATH_PROTOCOL *AbsDevicePath;
+ CHAR16 *AbsConverted;
+ BOOLEAN Shortform;
+ EFI_DEVICE_PATH_PROTOCOL *Node;
Converted = ConvertDevicePathToText (
DevicePath,
@@ -1646,37 +1735,42 @@ Match (
return FALSE;
}
- Result = FALSE;
+ Result = FALSE;
Shortform = FALSE;
//
// Expand the short-form device path to full device path
//
if ((DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) &&
- (DevicePathSubType (DevicePath) == MEDIA_HARDDRIVE_DP)) {
+ (DevicePathSubType (DevicePath) == MEDIA_HARDDRIVE_DP))
+ {
//
// Harddrive shortform device path
//
Shortform = TRUE;
} else if ((DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) &&
- (DevicePathSubType (DevicePath) == MEDIA_FILEPATH_DP)) {
+ (DevicePathSubType (DevicePath) == MEDIA_FILEPATH_DP))
+ {
//
// File-path shortform device path
//
Shortform = TRUE;
} else if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) &&
- (DevicePathSubType (DevicePath) == MSG_URI_DP)) {
+ (DevicePathSubType (DevicePath) == MSG_URI_DP))
+ {
//
// URI shortform device path
//
Shortform = TRUE;
} else {
for ( Node = DevicePath
- ; !IsDevicePathEnd (Node)
- ; Node = NextDevicePathNode (Node)
- ) {
+ ; !IsDevicePathEnd (Node)
+ ; Node = NextDevicePathNode (Node)
+ )
+ {
if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) &&
((DevicePathSubType (Node) == MSG_USB_CLASS_DP) ||
- (DevicePathSubType (Node) == MSG_USB_WWID_DP))) {
+ (DevicePathSubType (Node) == MSG_USB_WWID_DP)))
+ {
Shortform = TRUE;
break;
}
@@ -1689,20 +1783,27 @@ Match (
//
if (Shortform) {
FileBuffer = EfiBootManagerGetLoadOptionBuffer (
- DevicePath, &AbsDevicePath, &FileSize
+ DevicePath,
+ &AbsDevicePath,
+ &FileSize
);
if (FileBuffer == NULL) {
goto Exit;
}
+
FreePool (FileBuffer);
AbsConverted = ConvertDevicePathToText (AbsDevicePath, FALSE, FALSE);
FreePool (AbsDevicePath);
if (AbsConverted == NULL) {
goto Exit;
}
- DEBUG ((DEBUG_VERBOSE,
+
+ DEBUG ((
+ DEBUG_VERBOSE,
"%a: expanded relative device path \"%s\" for prefix matching\n",
- __FUNCTION__, Converted));
+ __FUNCTION__,
+ Converted
+ ));
FreePool (Converted);
Converted = AbsConverted;
}
@@ -1723,7 +1824,6 @@ Exit:
return Result;
}
-
/**
Append some of the unselected active boot options to the boot order.
@@ -1753,27 +1853,27 @@ Exit:
STATIC
RETURN_STATUS
BootOrderComplete (
- IN OUT BOOT_ORDER *BootOrder,
- IN OUT ACTIVE_OPTION *ActiveOption,
- IN UINTN ActiveCount
+ IN OUT BOOT_ORDER *BootOrder,
+ IN OUT ACTIVE_OPTION *ActiveOption,
+ IN UINTN ActiveCount
)
{
- RETURN_STATUS Status;
- UINTN Idx;
+ RETURN_STATUS Status;
+ UINTN Idx;
Status = RETURN_SUCCESS;
- Idx = 0;
+ Idx = 0;
while (!RETURN_ERROR (Status) && Idx < ActiveCount) {
if (!ActiveOption[Idx].Appended) {
- CONST EFI_BOOT_MANAGER_LOAD_OPTION *Current;
- CONST EFI_DEVICE_PATH_PROTOCOL *FirstNode;
+ CONST EFI_BOOT_MANAGER_LOAD_OPTION *Current;
+ CONST EFI_DEVICE_PATH_PROTOCOL *FirstNode;
- Current = ActiveOption[Idx].BootOption;
+ Current = ActiveOption[Idx].BootOption;
FirstNode = Current->FilePath;
if (FirstNode != NULL) {
- CHAR16 *Converted;
- STATIC CHAR16 ConvFallBack[] = L"<unable to convert>";
- BOOLEAN Keep;
+ CHAR16 *Converted;
+ STATIC CHAR16 ConvFallBack[] = L"<unable to convert>";
+ BOOLEAN Keep;
Converted = ConvertDevicePathToText (FirstNode, FALSE, FALSE);
if (Converted == NULL) {
@@ -1781,19 +1881,22 @@ BootOrderComplete (
}
Keep = TRUE;
- if (DevicePathType(FirstNode) == MEDIA_DEVICE_PATH &&
- DevicePathSubType(FirstNode) == MEDIA_HARDDRIVE_DP) {
+ if ((DevicePathType (FirstNode) == MEDIA_DEVICE_PATH) &&
+ (DevicePathSubType (FirstNode) == MEDIA_HARDDRIVE_DP))
+ {
//
// drop HD()
//
Keep = FALSE;
- } else if (DevicePathType(FirstNode) == ACPI_DEVICE_PATH &&
- DevicePathSubType(FirstNode) == ACPI_DP) {
- ACPI_HID_DEVICE_PATH *Acpi;
-
- Acpi = (ACPI_HID_DEVICE_PATH *) FirstNode;
- if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST &&
- EISA_ID_TO_NUM (Acpi->HID) == 0x0a03) {
+ } else if ((DevicePathType (FirstNode) == ACPI_DEVICE_PATH) &&
+ (DevicePathSubType (FirstNode) == ACPI_DP))
+ {
+ ACPI_HID_DEVICE_PATH *Acpi;
+
+ Acpi = (ACPI_HID_DEVICE_PATH *)FirstNode;
+ if (((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) &&
+ (EISA_ID_TO_NUM (Acpi->HID) == 0x0a03))
+ {
//
// drop PciRoot() if we enabled the user to select PCI-like boot
// options, by providing translation for such OFW device path
@@ -1801,9 +1904,10 @@ BootOrderComplete (
//
Keep = !FeaturePcdGet (PcdQemuBootOrderPciTranslation);
}
- } else if (DevicePathType(FirstNode) == HARDWARE_DEVICE_PATH &&
- DevicePathSubType(FirstNode) == HW_VENDOR_DP) {
- VENDOR_DEVICE_PATH *VenHw;
+ } else if ((DevicePathType (FirstNode) == HARDWARE_DEVICE_PATH) &&
+ (DevicePathSubType (FirstNode) == HW_VENDOR_DP))
+ {
+ VENDOR_DEVICE_PATH *VenHw;
VenHw = (VENDOR_DEVICE_PATH *)FirstNode;
if (CompareGuid (&VenHw->Guid, &gVirtioMmioTransportGuid)) {
@@ -1818,12 +1922,20 @@ BootOrderComplete (
if (Keep) {
Status = BootOrderAppend (BootOrder, &ActiveOption[Idx]);
if (!RETURN_ERROR (Status)) {
- DEBUG ((DEBUG_VERBOSE, "%a: keeping \"%s\"\n", __FUNCTION__,
- Converted));
+ DEBUG ((
+ DEBUG_VERBOSE,
+ "%a: keeping \"%s\"\n",
+ __FUNCTION__,
+ Converted
+ ));
}
} else {
- DEBUG ((DEBUG_VERBOSE, "%a: dropping \"%s\"\n", __FUNCTION__,
- Converted));
+ DEBUG ((
+ DEBUG_VERBOSE,
+ "%a: dropping \"%s\"\n",
+ __FUNCTION__,
+ Converted
+ ));
}
if (Converted != ConvFallBack) {
@@ -1831,12 +1943,13 @@ BootOrderComplete (
}
}
}
+
++Idx;
}
+
return Status;
}
-
/**
Delete Boot#### variables that stand for such active boot options that have
been dropped (ie. have not been selected by either matching or "survival
@@ -1851,24 +1964,30 @@ BootOrderComplete (
STATIC
VOID
PruneBootVariables (
- IN CONST ACTIVE_OPTION *ActiveOption,
- IN UINTN ActiveCount
+ IN CONST ACTIVE_OPTION *ActiveOption,
+ IN UINTN ActiveCount
)
{
- UINTN Idx;
+ UINTN Idx;
for (Idx = 0; Idx < ActiveCount; ++Idx) {
if (!ActiveOption[Idx].Appended) {
- CHAR16 VariableName[9];
+ CHAR16 VariableName[9];
- UnicodeSPrintAsciiFormat (VariableName, sizeof VariableName, "Boot%04x",
- ActiveOption[Idx].BootOption->OptionNumber);
+ UnicodeSPrintAsciiFormat (
+ VariableName,
+ sizeof VariableName,
+ "Boot%04x",
+ ActiveOption[Idx].BootOption->OptionNumber
+ );
//
// "The space consumed by the deleted variable may not be available until
// the next power cycle", but that's good enough.
//
- gRT->SetVariable (VariableName, &gEfiGlobalVariableGuid,
+ gRT->SetVariable (
+ VariableName,
+ &gEfiGlobalVariableGuid,
0, // Attributes, 0 means deletion
0, // DataSize, 0 means deletion
NULL // Data
@@ -1877,7 +1996,6 @@ PruneBootVariables (
}
}
-
/**
Set the boot order based on configuration retrieved from QEMU.
@@ -1912,22 +2030,22 @@ SetBootOrderFromQemu (
VOID
)
{
- RETURN_STATUS Status;
- FIRMWARE_CONFIG_ITEM FwCfgItem;
- UINTN FwCfgSize;
- CHAR8 *FwCfg;
- CONST CHAR8 *FwCfgPtr;
+ RETURN_STATUS Status;
+ FIRMWARE_CONFIG_ITEM FwCfgItem;
+ UINTN FwCfgSize;
+ CHAR8 *FwCfg;
+ CONST CHAR8 *FwCfgPtr;
- BOOT_ORDER BootOrder;
- ACTIVE_OPTION *ActiveOption;
- UINTN ActiveCount;
+ BOOT_ORDER BootOrder;
+ ACTIVE_OPTION *ActiveOption;
+ UINTN ActiveCount;
- EXTRA_ROOT_BUS_MAP *ExtraPciRoots;
+ EXTRA_ROOT_BUS_MAP *ExtraPciRoots;
- UINTN TranslatedSize;
- CHAR16 Translated[TRANSLATION_OUTPUT_SIZE];
- EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;
- UINTN BootOptionCount;
+ UINTN TranslatedSize;
+ CHAR16 Translated[TRANSLATION_OUTPUT_SIZE];
+ EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;
+ UINTN BootOptionCount;
Status = QemuFwCfgFindFile ("bootorder", &FwCfgItem, &FwCfgSize);
if (Status != RETURN_SUCCESS) {
@@ -1957,16 +2075,17 @@ SetBootOrderFromQemu (
BootOrder.Produced = 0;
BootOrder.Allocated = 1;
- BootOrder.Data = AllocatePool (
- BootOrder.Allocated * sizeof (*BootOrder.Data)
- );
+ BootOrder.Data = AllocatePool (
+ BootOrder.Allocated * sizeof (*BootOrder.Data)
+ );
if (BootOrder.Data == NULL) {
Status = RETURN_OUT_OF_RESOURCES;
goto ErrorFreeFwCfg;
}
BootOptions = EfiBootManagerGetLoadOptions (
- &BootOptionCount, LoadOptionTypeBoot
+ &BootOptionCount,
+ LoadOptionTypeBoot
);
if (BootOptions == NULL) {
Status = RETURN_NOT_FOUND;
@@ -1974,7 +2093,10 @@ SetBootOrderFromQemu (
}
Status = CollectActiveOptions (
- BootOptions, BootOptionCount, &ActiveOption, &ActiveCount
+ BootOptions,
+ BootOptionCount,
+ &ActiveOption,
+ &ActiveCount
);
if (RETURN_ERROR (Status)) {
goto ErrorFreeBootOptions;
@@ -1993,14 +2115,19 @@ SetBootOrderFromQemu (
// translate each OpenFirmware path
//
TranslatedSize = ARRAY_SIZE (Translated);
- Status = TranslateOfwPath (&FwCfgPtr, ExtraPciRoots, Translated,
- &TranslatedSize);
+ Status = TranslateOfwPath (
+ &FwCfgPtr,
+ ExtraPciRoots,
+ Translated,
+ &TranslatedSize
+ );
while (Status == RETURN_SUCCESS ||
Status == RETURN_UNSUPPORTED ||
Status == RETURN_PROTOCOL_ERROR ||
- Status == RETURN_BUFFER_TOO_SMALL) {
+ Status == RETURN_BUFFER_TOO_SMALL)
+ {
if (Status == RETURN_SUCCESS) {
- UINTN Idx;
+ UINTN Idx;
//
// match translated OpenFirmware path against all active boot options
@@ -2012,7 +2139,8 @@ SetBootOrderFromQemu (
TranslatedSize, // contains length, not size, in CHAR16's here
ActiveOption[Idx].BootOption->FilePath
)
- ) {
+ )
+ {
//
// match found, store ID and continue with next OpenFirmware path
//
@@ -2025,11 +2153,15 @@ SetBootOrderFromQemu (
} // translation successful
TranslatedSize = ARRAY_SIZE (Translated);
- Status = TranslateOfwPath (&FwCfgPtr, ExtraPciRoots, Translated,
- &TranslatedSize);
+ Status = TranslateOfwPath (
+ &FwCfgPtr,
+ ExtraPciRoots,
+ Translated,
+ &TranslatedSize
+ );
} // scanning of OpenFirmware paths done
- if (Status == RETURN_NOT_FOUND && BootOrder.Produced > 0) {
+ if ((Status == RETURN_NOT_FOUND) && (BootOrder.Produced > 0)) {
//
// No more OpenFirmware paths, some matches found: rewrite BootOrder NvVar.
// Some of the active boot options that have not been selected over fw_cfg
@@ -2048,14 +2180,18 @@ SetBootOrderFromQemu (
L"BootOrder",
&gEfiGlobalVariableGuid,
EFI_VARIABLE_NON_VOLATILE |
- EFI_VARIABLE_BOOTSERVICE_ACCESS |
- EFI_VARIABLE_RUNTIME_ACCESS,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_RUNTIME_ACCESS,
BootOrder.Produced * sizeof (*BootOrder.Data),
BootOrder.Data
);
if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a: setting BootOrder: %r\n", __FUNCTION__,
- Status));
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: setting BootOrder: %r\n",
+ __FUNCTION__,
+ Status
+ ));
goto ErrorFreeExtraPciRoots;
}
@@ -2083,7 +2219,6 @@ ErrorFreeFwCfg:
return Status;
}
-
/**
Calculate the number of seconds we should be showing the FrontPage progress
bar for.
@@ -2096,8 +2231,8 @@ GetFrontPageTimeoutFromQemu (
VOID
)
{
- FIRMWARE_CONFIG_ITEM BootMenuWaitItem;
- UINTN BootMenuWaitSize;
+ FIRMWARE_CONFIG_ITEM BootMenuWaitItem;
+ UINTN BootMenuWaitSize;
QemuFwCfgSelectItem (QemuFwCfgItemBootMenu);
if (QemuFwCfgRead16 () == 0) {
@@ -2108,20 +2243,27 @@ GetFrontPageTimeoutFromQemu (
return PcdGet16 (PcdPlatformBootTimeOut);
}
- if (RETURN_ERROR (QemuFwCfgFindFile ("etc/boot-menu-wait", &BootMenuWaitItem,
- &BootMenuWaitSize)) ||
- BootMenuWaitSize != sizeof (UINT16)) {
+ if (RETURN_ERROR (
+ QemuFwCfgFindFile (
+ "etc/boot-menu-wait",
+ &BootMenuWaitItem,
+ &BootMenuWaitSize
+ )
+ ) ||
+ (BootMenuWaitSize != sizeof (UINT16)))
+ {
//
// "-boot menu=on" was specified without "splash-time=N". In this case,
// return three seconds if the platform default would cause us to skip the
// front page, and return the platform default otherwise.
//
- UINT16 Timeout;
+ UINT16 Timeout;
Timeout = PcdGet16 (PcdPlatformBootTimeOut);
if (Timeout == 0) {
Timeout = 3;
}
+
return Timeout;
}