diff options
Diffstat (limited to 'OvmfPkg/AcpiPlatformDxe')
-rw-r--r-- | OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h | 35 | ||||
-rw-r--r-- | OvmfPkg/AcpiPlatformDxe/BootScript.c | 115 | ||||
-rw-r--r-- | OvmfPkg/AcpiPlatformDxe/EntryPoint.c | 54 | ||||
-rw-r--r-- | OvmfPkg/AcpiPlatformDxe/PciDecoding.c | 110 | ||||
-rw-r--r-- | OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c | 717 | ||||
-rw-r--r-- | OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatform.c | 4 |
6 files changed, 623 insertions, 412 deletions
diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h index bd4c26f07f..1ccca0a368 100644 --- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h +++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h @@ -13,8 +13,8 @@ #include <Protocol/PciIo.h> // EFI_PCI_IO_PROTOCOL
typedef struct {
- EFI_PCI_IO_PROTOCOL *PciIo;
- UINT64 PciAttributes;
+ EFI_PCI_IO_PROTOCOL *PciIo;
+ UINT64 PciAttributes;
} ORIGINAL_ATTRIBUTES;
typedef struct S3_CONTEXT S3_CONTEXT;
@@ -22,51 +22,50 @@ typedef struct S3_CONTEXT S3_CONTEXT; EFI_STATUS
EFIAPI
InstallQemuFwCfgTables (
- IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol
+ IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol
);
EFI_STATUS
EFIAPI
InstallAcpiTables (
- IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable
+ IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable
);
VOID
EnablePciDecoding (
- OUT ORIGINAL_ATTRIBUTES **OriginalAttributes,
- OUT UINTN *Count
+ OUT ORIGINAL_ATTRIBUTES **OriginalAttributes,
+ OUT UINTN *Count
);
VOID
RestorePciDecoding (
- IN ORIGINAL_ATTRIBUTES *OriginalAttributes,
- IN UINTN Count
+ IN ORIGINAL_ATTRIBUTES *OriginalAttributes,
+ IN UINTN Count
);
EFI_STATUS
AllocateS3Context (
- OUT S3_CONTEXT **S3Context,
- IN UINTN WritePointerCount
+ OUT S3_CONTEXT **S3Context,
+ IN UINTN WritePointerCount
);
VOID
ReleaseS3Context (
- IN S3_CONTEXT *S3Context
+ IN S3_CONTEXT *S3Context
);
EFI_STATUS
SaveCondensedWritePointerToS3Context (
- IN OUT S3_CONTEXT *S3Context,
- IN UINT16 PointerItem,
- IN UINT8 PointerSize,
- IN UINT32 PointerOffset,
- IN UINT64 PointerValue
+ IN OUT S3_CONTEXT *S3Context,
+ IN UINT16 PointerItem,
+ IN UINT8 PointerSize,
+ IN UINT32 PointerOffset,
+ IN UINT64 PointerValue
);
EFI_STATUS
TransferS3ContextToBootScript (
- IN S3_CONTEXT *S3Context
+ IN S3_CONTEXT *S3Context
);
#endif
-
diff --git a/OvmfPkg/AcpiPlatformDxe/BootScript.c b/OvmfPkg/AcpiPlatformDxe/BootScript.c index efcf2e3ba5..08d0f41bda 100644 --- a/OvmfPkg/AcpiPlatformDxe/BootScript.c +++ b/OvmfPkg/AcpiPlatformDxe/BootScript.c @@ -14,20 +14,18 @@ #include "AcpiPlatform.h"
-
//
// Condensed structure for capturing the fw_cfg operations -- select, skip,
// write -- inherent in executing a QEMU_LOADER_WRITE_POINTER command.
//
typedef struct {
- UINT16 PointerItem; // resolved from QEMU_LOADER_WRITE_POINTER.PointerFile
- UINT8 PointerSize; // copied as-is from QEMU_LOADER_WRITE_POINTER
- UINT32 PointerOffset; // copied as-is from QEMU_LOADER_WRITE_POINTER
- UINT64 PointerValue; // resolved from QEMU_LOADER_WRITE_POINTER.PointeeFile
- // and QEMU_LOADER_WRITE_POINTER.PointeeOffset
+ UINT16 PointerItem; // resolved from QEMU_LOADER_WRITE_POINTER.PointerFile
+ UINT8 PointerSize; // copied as-is from QEMU_LOADER_WRITE_POINTER
+ UINT32 PointerOffset; // copied as-is from QEMU_LOADER_WRITE_POINTER
+ UINT64 PointerValue; // resolved from QEMU_LOADER_WRITE_POINTER.PointeeFile
+ // and QEMU_LOADER_WRITE_POINTER.PointeeOffset
} CONDENSED_WRITE_POINTER;
-
//
// Context structure to accumulate CONDENSED_WRITE_POINTER objects from
// QEMU_LOADER_WRITE_POINTER commands.
@@ -36,27 +34,25 @@ typedef struct { // context structure is released, all pointed-to objects must be released too.
//
struct S3_CONTEXT {
- CONDENSED_WRITE_POINTER *WritePointers; // one array element per processed
- // QEMU_LOADER_WRITE_POINTER
- // command
- UINTN Allocated; // number of elements allocated for
- // WritePointers
- UINTN Used; // number of elements populated in
- // WritePointers
+ CONDENSED_WRITE_POINTER *WritePointers; // one array element per processed
+ // QEMU_LOADER_WRITE_POINTER
+ // command
+ UINTN Allocated; // number of elements allocated for
+ // WritePointers
+ UINTN Used; // number of elements populated in
+ // WritePointers
};
-
//
// Scratch buffer, allocated in EfiReservedMemoryType type memory, for the ACPI
// S3 Boot Script opcodes to work on.
//
#pragma pack (1)
typedef union {
- UINT64 PointerValue; // filled in from CONDENSED_WRITE_POINTER.PointerValue
+ UINT64 PointerValue; // filled in from CONDENSED_WRITE_POINTER.PointerValue
} SCRATCH_BUFFER;
#pragma pack ()
-
/**
Allocate an S3_CONTEXT object.
@@ -75,12 +71,12 @@ typedef union { **/
EFI_STATUS
AllocateS3Context (
- OUT S3_CONTEXT **S3Context,
- IN UINTN WritePointerCount
+ OUT S3_CONTEXT **S3Context,
+ IN UINTN WritePointerCount
)
{
- EFI_STATUS Status;
- S3_CONTEXT *Context;
+ EFI_STATUS Status;
+ S3_CONTEXT *Context;
if (WritePointerCount == 0) {
return EFI_INVALID_PARAMETER;
@@ -91,15 +87,17 @@ AllocateS3Context ( return EFI_OUT_OF_RESOURCES;
}
- Context->WritePointers = AllocatePool (WritePointerCount *
- sizeof *Context->WritePointers);
+ Context->WritePointers = AllocatePool (
+ WritePointerCount *
+ sizeof *Context->WritePointers
+ );
if (Context->WritePointers == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto FreeContext;
}
Context->Allocated = WritePointerCount;
- *S3Context = Context;
+ *S3Context = Context;
return EFI_SUCCESS;
FreeContext:
@@ -108,7 +106,6 @@ FreeContext: return Status;
}
-
/**
Release an S3_CONTEXT object.
@@ -116,14 +113,13 @@ FreeContext: **/
VOID
ReleaseS3Context (
- IN S3_CONTEXT *S3Context
+ IN S3_CONTEXT *S3Context
)
{
FreePool (S3Context->WritePointers);
FreePool (S3Context);
}
-
/**
Save the information necessary to replicate a QEMU_LOADER_WRITE_POINTER
command during S3 resume, in condensed format.
@@ -158,31 +154,38 @@ ReleaseS3Context ( **/
EFI_STATUS
SaveCondensedWritePointerToS3Context (
- IN OUT S3_CONTEXT *S3Context,
- IN UINT16 PointerItem,
- IN UINT8 PointerSize,
- IN UINT32 PointerOffset,
- IN UINT64 PointerValue
+ IN OUT S3_CONTEXT *S3Context,
+ IN UINT16 PointerItem,
+ IN UINT8 PointerSize,
+ IN UINT32 PointerOffset,
+ IN UINT64 PointerValue
)
{
- CONDENSED_WRITE_POINTER *Condensed;
+ CONDENSED_WRITE_POINTER *Condensed;
if (S3Context->Used == S3Context->Allocated) {
return EFI_OUT_OF_RESOURCES;
}
- Condensed = S3Context->WritePointers + S3Context->Used;
+
+ Condensed = S3Context->WritePointers + S3Context->Used;
Condensed->PointerItem = PointerItem;
Condensed->PointerSize = PointerSize;
Condensed->PointerOffset = PointerOffset;
Condensed->PointerValue = PointerValue;
- DEBUG ((DEBUG_VERBOSE, "%a: 0x%04x/[0x%08x+%d] := 0x%Lx (%Lu)\n",
- __FUNCTION__, PointerItem, PointerOffset, PointerSize, PointerValue,
- (UINT64)S3Context->Used));
+ DEBUG ((
+ DEBUG_VERBOSE,
+ "%a: 0x%04x/[0x%08x+%d] := 0x%Lx (%Lu)\n",
+ __FUNCTION__,
+ PointerItem,
+ PointerOffset,
+ PointerSize,
+ PointerValue,
+ (UINT64)S3Context->Used
+ ));
++S3Context->Used;
return EFI_SUCCESS;
}
-
/**
FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION provided to QemuFwCfgS3Lib.
**/
@@ -190,31 +193,33 @@ STATIC VOID
EFIAPI
AppendFwCfgBootScript (
- IN OUT VOID *Context OPTIONAL,
- IN OUT VOID *ExternalScratchBuffer
+ IN OUT VOID *Context OPTIONAL,
+ IN OUT VOID *ExternalScratchBuffer
)
{
- S3_CONTEXT *S3Context;
- SCRATCH_BUFFER *ScratchBuffer;
- UINTN Index;
+ S3_CONTEXT *S3Context;
+ SCRATCH_BUFFER *ScratchBuffer;
+ UINTN Index;
- S3Context = Context;
+ S3Context = Context;
ScratchBuffer = ExternalScratchBuffer;
for (Index = 0; Index < S3Context->Used; ++Index) {
- CONST CONDENSED_WRITE_POINTER *Condensed;
- RETURN_STATUS Status;
+ CONST CONDENSED_WRITE_POINTER *Condensed;
+ RETURN_STATUS Status;
Condensed = &S3Context->WritePointers[Index];
- Status = QemuFwCfgS3ScriptSkipBytes (Condensed->PointerItem,
- Condensed->PointerOffset);
+ Status = QemuFwCfgS3ScriptSkipBytes (
+ Condensed->PointerItem,
+ Condensed->PointerOffset
+ );
if (RETURN_ERROR (Status)) {
goto FatalError;
}
ScratchBuffer->PointerValue = Condensed->PointerValue;
- Status = QemuFwCfgS3ScriptWriteBytes (-1, Condensed->PointerSize);
+ Status = QemuFwCfgS3ScriptWriteBytes (-1, Condensed->PointerSize);
if (RETURN_ERROR (Status)) {
goto FatalError;
}
@@ -230,7 +235,6 @@ FatalError: CpuDeadLoop ();
}
-
/**
Translate and append the information from an S3_CONTEXT object to the ACPI S3
Boot Script.
@@ -253,17 +257,20 @@ FatalError: **/
EFI_STATUS
TransferS3ContextToBootScript (
- IN S3_CONTEXT *S3Context
+ IN S3_CONTEXT *S3Context
)
{
- RETURN_STATUS Status;
+ RETURN_STATUS Status;
if (S3Context->Used == 0) {
ReleaseS3Context (S3Context);
return EFI_SUCCESS;
}
- Status = QemuFwCfgS3CallWhenBootScriptReady (AppendFwCfgBootScript,
- S3Context, sizeof (SCRATCH_BUFFER));
+ Status = QemuFwCfgS3CallWhenBootScriptReady (
+ AppendFwCfgBootScript,
+ S3Context,
+ sizeof (SCRATCH_BUFFER)
+ );
return (EFI_STATUS)Status;
}
diff --git a/OvmfPkg/AcpiPlatformDxe/EntryPoint.c b/OvmfPkg/AcpiPlatformDxe/EntryPoint.c index bb5fe82c18..143e860fe1 100644 --- a/OvmfPkg/AcpiPlatformDxe/EntryPoint.c +++ b/OvmfPkg/AcpiPlatformDxe/EntryPoint.c @@ -21,49 +21,50 @@ FindAcpiTableProtocol ( VOID
)
{
- EFI_STATUS Status;
- EFI_ACPI_TABLE_PROTOCOL *AcpiTable;
+ EFI_STATUS Status;
+ EFI_ACPI_TABLE_PROTOCOL *AcpiTable;
Status = gBS->LocateProtocol (
&gEfiAcpiTableProtocolGuid,
NULL,
- (VOID**)&AcpiTable
+ (VOID **)&AcpiTable
);
ASSERT_EFI_ERROR (Status);
return AcpiTable;
}
-
STATIC
VOID
EFIAPI
OnRootBridgesConnected (
- IN EFI_EVENT Event,
- IN VOID *Context
+ IN EFI_EVENT Event,
+ IN VOID *Context
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
- DEBUG ((DEBUG_INFO,
+ DEBUG ((
+ DEBUG_INFO,
"%a: root bridges have been connected, installing ACPI tables\n",
- __FUNCTION__));
+ __FUNCTION__
+ ));
Status = InstallAcpiTables (FindAcpiTableProtocol ());
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: InstallAcpiTables: %r\n", __FUNCTION__, Status));
}
+
gBS->CloseEvent (Event);
}
-
EFI_STATUS
EFIAPI
AcpiPlatformEntryPoint (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
)
{
- EFI_STATUS Status;
- EFI_EVENT RootBridgesConnected;
+ EFI_STATUS Status;
+ EFI_EVENT RootBridgesConnected;
//
// If the platform doesn't support PCI, or PCI enumeration has been disabled,
@@ -71,8 +72,12 @@ AcpiPlatformEntryPoint ( // the full functionality.
//
if (PcdGetBool (PcdPciDisableBusEnumeration)) {
- DEBUG ((DEBUG_INFO, "%a: PCI or its enumeration disabled, installing "
- "ACPI tables\n", __FUNCTION__));
+ DEBUG ((
+ DEBUG_INFO,
+ "%a: PCI or its enumeration disabled, installing "
+ "ACPI tables\n",
+ __FUNCTION__
+ ));
return InstallAcpiTables (FindAcpiTableProtocol ());
}
@@ -82,13 +87,20 @@ AcpiPlatformEntryPoint ( // setup. (Note that we're a DXE_DRIVER; our entry point function is invoked
// strictly before BDS is entered and can connect the root bridges.)
//
- Status = gBS->CreateEventEx (EVT_NOTIFY_SIGNAL, TPL_CALLBACK,
- OnRootBridgesConnected, NULL /* Context */,
- &gRootBridgesConnectedEventGroupGuid, &RootBridgesConnected);
+ Status = gBS->CreateEventEx (
+ EVT_NOTIFY_SIGNAL,
+ TPL_CALLBACK,
+ OnRootBridgesConnected,
+ NULL /* Context */,
+ &gRootBridgesConnectedEventGroupGuid,
+ &RootBridgesConnected
+ );
if (!EFI_ERROR (Status)) {
- DEBUG ((DEBUG_INFO,
+ DEBUG ((
+ DEBUG_INFO,
"%a: waiting for root bridges to be connected, registered callback\n",
- __FUNCTION__));
+ __FUNCTION__
+ ));
}
return Status;
diff --git a/OvmfPkg/AcpiPlatformDxe/PciDecoding.c b/OvmfPkg/AcpiPlatformDxe/PciDecoding.c index 6ba4c936ad..c178f857a2 100644 --- a/OvmfPkg/AcpiPlatformDxe/PciDecoding.c +++ b/OvmfPkg/AcpiPlatformDxe/PciDecoding.c @@ -13,7 +13,6 @@ #include "AcpiPlatform.h"
-
/**
Collect all PciIo protocol instances in the system. Save their original
attributes, and enable IO and MMIO decoding for each.
@@ -40,15 +39,15 @@ **/
VOID
EnablePciDecoding (
- OUT ORIGINAL_ATTRIBUTES **OriginalAttributes,
- OUT UINTN *Count
+ OUT ORIGINAL_ATTRIBUTES **OriginalAttributes,
+ OUT UINTN *Count
)
{
- EFI_STATUS Status;
- UINTN NoHandles;
- EFI_HANDLE *Handles;
- ORIGINAL_ATTRIBUTES *OrigAttrs;
- UINTN Idx;
+ EFI_STATUS Status;
+ UINTN NoHandles;
+ EFI_HANDLE *Handles;
+ ORIGINAL_ATTRIBUTES *OrigAttrs;
+ UINTN Idx;
*OriginalAttributes = NULL;
*Count = 0;
@@ -61,8 +60,13 @@ EnablePciDecoding ( return;
}
- Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiPciIoProtocolGuid,
- NULL /* SearchKey */, &NoHandles, &Handles);
+ Status = gBS->LocateHandleBuffer (
+ ByProtocol,
+ &gEfiPciIoProtocolGuid,
+ NULL /* SearchKey */,
+ &NoHandles,
+ &Handles
+ );
if (Status == EFI_NOT_FOUND) {
//
// No PCI devices were found on either of the root bridges. We're done.
@@ -71,49 +75,75 @@ EnablePciDecoding ( }
if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_WARN, "%a: LocateHandleBuffer(): %r\n", __FUNCTION__,
- Status));
+ DEBUG ((
+ DEBUG_WARN,
+ "%a: LocateHandleBuffer(): %r\n",
+ __FUNCTION__,
+ Status
+ ));
return;
}
OrigAttrs = AllocatePool (NoHandles * sizeof *OrigAttrs);
if (OrigAttrs == NULL) {
- DEBUG ((DEBUG_WARN, "%a: AllocatePool(): out of resources\n",
- __FUNCTION__));
+ DEBUG ((
+ DEBUG_WARN,
+ "%a: AllocatePool(): out of resources\n",
+ __FUNCTION__
+ ));
goto FreeHandles;
}
for (Idx = 0; Idx < NoHandles; ++Idx) {
- EFI_PCI_IO_PROTOCOL *PciIo;
- UINT64 Attributes;
+ EFI_PCI_IO_PROTOCOL *PciIo;
+ UINT64 Attributes;
//
// Look up PciIo on the handle and stash it
//
- Status = gBS->HandleProtocol (Handles[Idx], &gEfiPciIoProtocolGuid,
- (VOID**)&PciIo);
+ Status = gBS->HandleProtocol (
+ Handles[Idx],
+ &gEfiPciIoProtocolGuid,
+ (VOID **)&PciIo
+ );
ASSERT_EFI_ERROR (Status);
OrigAttrs[Idx].PciIo = PciIo;
//
// Stash the current attributes
//
- Status = PciIo->Attributes (PciIo, EfiPciIoAttributeOperationGet, 0,
- &OrigAttrs[Idx].PciAttributes);
+ Status = PciIo->Attributes (
+ PciIo,
+ EfiPciIoAttributeOperationGet,
+ 0,
+ &OrigAttrs[Idx].PciAttributes
+ );
if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_WARN, "%a: EfiPciIoAttributeOperationGet: %r\n",
- __FUNCTION__, Status));
+ DEBUG ((
+ DEBUG_WARN,
+ "%a: EfiPciIoAttributeOperationGet: %r\n",
+ __FUNCTION__,
+ Status
+ ));
goto RestoreAttributes;
}
//
// Retrieve supported attributes
//
- Status = PciIo->Attributes (PciIo, EfiPciIoAttributeOperationSupported, 0,
- &Attributes);
+ Status = PciIo->Attributes (
+ PciIo,
+ EfiPciIoAttributeOperationSupported,
+ 0,
+ &Attributes
+ );
if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_WARN, "%a: EfiPciIoAttributeOperationSupported: %r\n",
- __FUNCTION__, Status));
+ DEBUG ((
+ DEBUG_WARN,
+ "%a: EfiPciIoAttributeOperationSupported: %r\n",
+ __FUNCTION__,
+ Status
+ ));
goto RestoreAttributes;
}
@@ -121,11 +151,19 @@ EnablePciDecoding ( // Enable IO and MMIO decoding
//
Attributes &= EFI_PCI_IO_ATTRIBUTE_IO | EFI_PCI_IO_ATTRIBUTE_MEMORY;
- Status = PciIo->Attributes (PciIo, EfiPciIoAttributeOperationEnable,
- Attributes, NULL);
+ Status = PciIo->Attributes (
+ PciIo,
+ EfiPciIoAttributeOperationEnable,
+ Attributes,
+ NULL
+ );
if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_WARN, "%a: EfiPciIoAttributeOperationEnable: %r\n",
- __FUNCTION__, Status));
+ DEBUG ((
+ DEBUG_WARN,
+ "%a: EfiPciIoAttributeOperationEnable: %r\n",
+ __FUNCTION__,
+ Status
+ ));
goto RestoreAttributes;
}
}
@@ -141,19 +179,20 @@ EnablePciDecoding ( RestoreAttributes:
while (Idx > 0) {
--Idx;
- OrigAttrs[Idx].PciIo->Attributes (OrigAttrs[Idx].PciIo,
+ OrigAttrs[Idx].PciIo->Attributes (
+ OrigAttrs[Idx].PciIo,
EfiPciIoAttributeOperationSet,
OrigAttrs[Idx].PciAttributes,
NULL
);
}
+
FreePool (OrigAttrs);
FreeHandles:
FreePool (Handles);
}
-
/**
Restore the original PCI attributes saved with EnablePciDecoding().
@@ -171,11 +210,11 @@ FreeHandles: **/
VOID
RestorePciDecoding (
- IN ORIGINAL_ATTRIBUTES *OriginalAttributes,
- IN UINTN Count
+ IN ORIGINAL_ATTRIBUTES *OriginalAttributes,
+ IN UINTN Count
)
{
- UINTN Idx;
+ UINTN Idx;
ASSERT ((OriginalAttributes == NULL) == (Count == 0));
if (OriginalAttributes == NULL) {
@@ -190,5 +229,6 @@ RestorePciDecoding ( NULL
);
}
+
FreePool (OriginalAttributes);
}
diff --git a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c b/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c index df800b1492..b885965a60 100644 --- a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c +++ b/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c @@ -26,17 +26,16 @@ // blobs under processing.
//
typedef struct {
- UINT8 File[QEMU_LOADER_FNAME_SIZE]; // NUL-terminated name of the fw_cfg
- // blob. This is the ordering / search
- // key.
- UINTN Size; // The number of bytes in this blob.
- UINT8 *Base; // Pointer to the blob data.
- BOOLEAN HostsOnlyTableData; // TRUE iff the blob has been found to
- // only contain data that is directly
- // part of ACPI tables.
+ UINT8 File[QEMU_LOADER_FNAME_SIZE]; // NUL-terminated name of the fw_cfg
+ // blob. This is the ordering / search
+ // key.
+ UINTN Size; // The number of bytes in this blob.
+ UINT8 *Base; // Pointer to the blob data.
+ BOOLEAN HostsOnlyTableData; // TRUE iff the blob has been found to
+ // only contain data that is directly
+ // part of ACPI tables.
} BLOB;
-
/**
Compare a standalone key against a user structure containing an embedded key.
@@ -55,17 +54,16 @@ STATIC INTN
EFIAPI
BlobKeyCompare (
- IN CONST VOID *StandaloneKey,
- IN CONST VOID *UserStruct
+ IN CONST VOID *StandaloneKey,
+ IN CONST VOID *UserStruct
)
{
- CONST BLOB *Blob;
+ CONST BLOB *Blob;
Blob = UserStruct;
return AsciiStrCmp (StandaloneKey, (CONST CHAR8 *)Blob->File);
}
-
/**
Comparator function for two user structures.
@@ -83,17 +81,16 @@ STATIC INTN
EFIAPI
BlobCompare (
- IN CONST VOID *UserStruct1,
- IN CONST VOID *UserStruct2
+ IN CONST VOID *UserStruct1,
+ IN CONST VOID *UserStruct2
)
{
- CONST BLOB *Blob1;
+ CONST BLOB *Blob1;
Blob1 = UserStruct1;
return BlobKeyCompare (Blob1->File, UserStruct2);
}
-
/**
Comparator function for two opaque pointers, ordering on (unsigned) pointer
value itself.
@@ -113,20 +110,21 @@ STATIC INTN
EFIAPI
PointerCompare (
- IN CONST VOID *Pointer1,
- IN CONST VOID *Pointer2
+ IN CONST VOID *Pointer1,
+ IN CONST VOID *Pointer2
)
{
if (Pointer1 == Pointer2) {
return 0;
}
+
if ((UINTN)Pointer1 < (UINTN)Pointer2) {
return -1;
}
+
return 1;
}
-
/**
Comparator function for two ASCII strings. Can be used as both Key and
UserStruct comparator.
@@ -144,14 +142,13 @@ STATIC INTN
EFIAPI
AsciiStringCompare (
- IN CONST VOID *AsciiString1,
- IN CONST VOID *AsciiString2
+ IN CONST VOID *AsciiString1,
+ IN CONST VOID *AsciiString2
)
{
return AsciiStrCmp (AsciiString1, AsciiString2);
}
-
/**
Release the ORDERED_COLLECTION structure populated by
CollectAllocationsRestrictedTo32Bit() (below).
@@ -165,21 +162,22 @@ AsciiStringCompare ( STATIC
VOID
ReleaseAllocationsRestrictedTo32Bit (
- IN ORDERED_COLLECTION *AllocationsRestrictedTo32Bit
-)
+ IN ORDERED_COLLECTION *AllocationsRestrictedTo32Bit
+ )
{
- ORDERED_COLLECTION_ENTRY *Entry, *Entry2;
+ ORDERED_COLLECTION_ENTRY *Entry, *Entry2;
for (Entry = OrderedCollectionMin (AllocationsRestrictedTo32Bit);
Entry != NULL;
- Entry = Entry2) {
+ Entry = Entry2)
+ {
Entry2 = OrderedCollectionNext (Entry);
OrderedCollectionDelete (AllocationsRestrictedTo32Bit, Entry, NULL);
}
+
OrderedCollectionUninit (AllocationsRestrictedTo32Bit);
}
-
/**
Iterate over the linker/loader script, and collect the names of the fw_cfg
blobs that are referenced by QEMU_LOADER_ADD_POINTER.PointeeFile fields, such
@@ -210,14 +208,14 @@ ReleaseAllocationsRestrictedTo32Bit ( STATIC
EFI_STATUS
CollectAllocationsRestrictedTo32Bit (
- OUT ORDERED_COLLECTION **AllocationsRestrictedTo32Bit,
- IN CONST QEMU_LOADER_ENTRY *LoaderStart,
- IN CONST QEMU_LOADER_ENTRY *LoaderEnd
-)
+ OUT ORDERED_COLLECTION **AllocationsRestrictedTo32Bit,
+ IN CONST QEMU_LOADER_ENTRY *LoaderStart,
+ IN CONST QEMU_LOADER_ENTRY *LoaderEnd
+ )
{
- ORDERED_COLLECTION *Collection;
- CONST QEMU_LOADER_ENTRY *LoaderEntry;
- EFI_STATUS Status;
+ ORDERED_COLLECTION *Collection;
+ CONST QEMU_LOADER_ENTRY *LoaderEntry;
+ EFI_STATUS Status;
Collection = OrderedCollectionInit (AsciiStringCompare, AsciiStringCompare);
if (Collection == NULL) {
@@ -225,11 +223,12 @@ CollectAllocationsRestrictedTo32Bit ( }
for (LoaderEntry = LoaderStart; LoaderEntry < LoaderEnd; ++LoaderEntry) {
- CONST QEMU_LOADER_ADD_POINTER *AddPointer;
+ CONST QEMU_LOADER_ADD_POINTER *AddPointer;
if (LoaderEntry->Type != QemuLoaderCmdAddPointer) {
continue;
}
+
AddPointer = &LoaderEntry->Command.AddPointer;
if (AddPointer->PointerSize >= 8) {
@@ -248,23 +247,23 @@ CollectAllocationsRestrictedTo32Bit ( (VOID *)AddPointer->PointeeFile
);
switch (Status) {
- case EFI_SUCCESS:
- DEBUG ((
- DEBUG_VERBOSE,
- "%a: restricting blob \"%a\" from 64-bit allocation\n",
- __FUNCTION__,
- AddPointer->PointeeFile
- ));
- break;
- case EFI_ALREADY_STARTED:
- //
- // The restriction has been recorded already.
- //
- break;
- case EFI_OUT_OF_RESOURCES:
- goto RollBack;
- default:
- ASSERT (FALSE);
+ case EFI_SUCCESS:
+ DEBUG ((
+ DEBUG_VERBOSE,
+ "%a: restricting blob \"%a\" from 64-bit allocation\n",
+ __FUNCTION__,
+ AddPointer->PointeeFile
+ ));
+ break;
+ case EFI_ALREADY_STARTED:
+ //
+ // The restriction has been recorded already.
+ //
+ break;
+ case EFI_OUT_OF_RESOURCES:
+ goto RollBack;
+ default:
+ ASSERT (FALSE);
}
}
@@ -276,7 +275,6 @@ RollBack: return Status;
}
-
/**
Process a QEMU_LOADER_ALLOCATE command.
@@ -317,17 +315,17 @@ STATIC EFI_STATUS
EFIAPI
ProcessCmdAllocate (
- IN CONST QEMU_LOADER_ALLOCATE *Allocate,
- IN OUT ORDERED_COLLECTION *Tracker,
- IN ORDERED_COLLECTION *AllocationsRestrictedTo32Bit
+ IN CONST QEMU_LOADER_ALLOCATE *Allocate,
+ IN OUT ORDERED_COLLECTION *Tracker,
+ IN ORDERED_COLLECTION *AllocationsRestrictedTo32Bit
)
{
- FIRMWARE_CONFIG_ITEM FwCfgItem;
- UINTN FwCfgSize;
- EFI_STATUS Status;
- UINTN NumPages;
- EFI_PHYSICAL_ADDRESS Address;
- BLOB *Blob;
+ FIRMWARE_CONFIG_ITEM FwCfgItem;
+ UINTN FwCfgSize;
+ EFI_STATUS Status;
+ UINTN NumPages;
+ EFI_PHYSICAL_ADDRESS Address;
+ BLOB *Blob;
if (Allocate->File[QEMU_LOADER_FNAME_SIZE - 1] != '\0') {
DEBUG ((DEBUG_ERROR, "%a: malformed file name\n", __FUNCTION__));
@@ -335,28 +333,43 @@ ProcessCmdAllocate ( }
if (Allocate->Alignment > EFI_PAGE_SIZE) {
- DEBUG ((DEBUG_ERROR, "%a: unsupported alignment 0x%x\n", __FUNCTION__,
- Allocate->Alignment));
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: unsupported alignment 0x%x\n",
+ __FUNCTION__,
+ Allocate->Alignment
+ ));
return EFI_UNSUPPORTED;
}
Status = QemuFwCfgFindFile ((CHAR8 *)Allocate->File, &FwCfgItem, &FwCfgSize);
if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a: QemuFwCfgFindFile(\"%a\"): %r\n", __FUNCTION__,
- Allocate->File, Status));
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: QemuFwCfgFindFile(\"%a\"): %r\n",
+ __FUNCTION__,
+ Allocate->File,
+ Status
+ ));
return Status;
}
NumPages = EFI_SIZE_TO_PAGES (FwCfgSize);
- Address = MAX_UINT64;
+ Address = MAX_UINT64;
if (OrderedCollectionFind (
AllocationsRestrictedTo32Bit,
Allocate->File
- ) != NULL) {
+ ) != NULL)
+ {
Address = MAX_UINT32;
}
- Status = gBS->AllocatePages (AllocateMaxAddress, EfiACPIMemoryNVS, NumPages,
- &Address);
+
+ Status = gBS->AllocatePages (
+ AllocateMaxAddress,
+ EfiACPIMemoryNVS,
+ NumPages,
+ &Address
+ );
if (EFI_ERROR (Status)) {
return Status;
}
@@ -366,17 +379,23 @@ ProcessCmdAllocate ( Status = EFI_OUT_OF_RESOURCES;
goto FreePages;
}
+
CopyMem (Blob->File, Allocate->File, QEMU_LOADER_FNAME_SIZE);
- Blob->Size = FwCfgSize;
- Blob->Base = (VOID *)(UINTN)Address;
+ Blob->Size = FwCfgSize;
+ Blob->Base = (VOID *)(UINTN)Address;
Blob->HostsOnlyTableData = TRUE;
Status = OrderedCollectionInsert (Tracker, NULL, Blob);
if (Status == RETURN_ALREADY_STARTED) {
- DEBUG ((DEBUG_ERROR, "%a: duplicated file \"%a\"\n", __FUNCTION__,
- Allocate->File));
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: duplicated file \"%a\"\n",
+ __FUNCTION__,
+ Allocate->File
+ ));
Status = EFI_PROTOCOL_ERROR;
}
+
if (EFI_ERROR (Status)) {
goto FreeBlob;
}
@@ -385,9 +404,17 @@ ProcessCmdAllocate ( QemuFwCfgReadBytes (FwCfgSize, Blob->Base);
ZeroMem (Blob->Base + Blob->Size, EFI_PAGES_TO_SIZE (NumPages) - Blob->Size);
- DEBUG ((DEBUG_VERBOSE, "%a: File=\"%a\" Alignment=0x%x Zone=%d Size=0x%Lx "
- "Address=0x%Lx\n", __FUNCTION__, Allocate->File, Allocate->Alignment,
- Allocate->Zone, (UINT64)Blob->Size, (UINT64)(UINTN)Blob->Base));
+ DEBUG ((
+ DEBUG_VERBOSE,
+ "%a: File=\"%a\" Alignment=0x%x Zone=%d Size=0x%Lx "
+ "Address=0x%Lx\n",
+ __FUNCTION__,
+ Allocate->File,
+ Allocate->Alignment,
+ Allocate->Zone,
+ (UINT64)Blob->Size,
+ (UINT64)(UINTN)Blob->Base
+ ));
return EFI_SUCCESS;
FreeBlob:
@@ -399,7 +426,6 @@ FreePages: return Status;
}
-
/**
Process a QEMU_LOADER_ADD_POINTER command.
@@ -422,37 +448,48 @@ STATIC EFI_STATUS
EFIAPI
ProcessCmdAddPointer (
- IN CONST QEMU_LOADER_ADD_POINTER *AddPointer,
- IN CONST ORDERED_COLLECTION *Tracker
+ IN CONST QEMU_LOADER_ADD_POINTER *AddPointer,
+ IN CONST ORDERED_COLLECTION *Tracker
)
{
- ORDERED_COLLECTION_ENTRY *TrackerEntry, *TrackerEntry2;
- BLOB *Blob, *Blob2;
- UINT8 *PointerField;
- UINT64 PointerValue;
-
- if (AddPointer->PointerFile[QEMU_LOADER_FNAME_SIZE - 1] != '\0' ||
- AddPointer->PointeeFile[QEMU_LOADER_FNAME_SIZE - 1] != '\0') {
+ ORDERED_COLLECTION_ENTRY *TrackerEntry, *TrackerEntry2;
+ BLOB *Blob, *Blob2;
+ UINT8 *PointerField;
+ UINT64 PointerValue;
+
+ if ((AddPointer->PointerFile[QEMU_LOADER_FNAME_SIZE - 1] != '\0') ||
+ (AddPointer->PointeeFile[QEMU_LOADER_FNAME_SIZE - 1] != '\0'))
+ {
DEBUG ((DEBUG_ERROR, "%a: malformed file name\n", __FUNCTION__));
return EFI_PROTOCOL_ERROR;
}
- TrackerEntry = OrderedCollectionFind (Tracker, AddPointer->PointerFile);
+ TrackerEntry = OrderedCollectionFind (Tracker, AddPointer->PointerFile);
TrackerEntry2 = OrderedCollectionFind (Tracker, AddPointer->PointeeFile);
- if (TrackerEntry == NULL || TrackerEntry2 == NULL) {
- DEBUG ((DEBUG_ERROR, "%a: invalid blob reference(s) \"%a\" / \"%a\"\n",
- __FUNCTION__, AddPointer->PointerFile, AddPointer->PointeeFile));
+ if ((TrackerEntry == NULL) || (TrackerEntry2 == NULL)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: invalid blob reference(s) \"%a\" / \"%a\"\n",
+ __FUNCTION__,
+ AddPointer->PointerFile,
+ AddPointer->PointeeFile
+ ));
return EFI_PROTOCOL_ERROR;
}
- Blob = OrderedCollectionUserStruct (TrackerEntry);
+ Blob = OrderedCollectionUserStruct (TrackerEntry);
Blob2 = OrderedCollectionUserStruct (TrackerEntry2);
- if ((AddPointer->PointerSize != 1 && AddPointer->PointerSize != 2 &&
- AddPointer->PointerSize != 4 && AddPointer->PointerSize != 8) ||
- Blob->Size < AddPointer->PointerSize ||
- Blob->Size - AddPointer->PointerSize < AddPointer->PointerOffset) {
- DEBUG ((DEBUG_ERROR, "%a: invalid pointer location or size in \"%a\"\n",
- __FUNCTION__, AddPointer->PointerFile));
+ if (((AddPointer->PointerSize != 1) && (AddPointer->PointerSize != 2) &&
+ (AddPointer->PointerSize != 4) && (AddPointer->PointerSize != 8)) ||
+ (Blob->Size < AddPointer->PointerSize) ||
+ (Blob->Size - AddPointer->PointerSize < AddPointer->PointerOffset))
+ {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: invalid pointer location or size in \"%a\"\n",
+ __FUNCTION__,
+ AddPointer->PointerFile
+ ));
return EFI_PROTOCOL_ERROR;
}
@@ -460,8 +497,12 @@ ProcessCmdAddPointer ( PointerValue = 0;
CopyMem (&PointerValue, PointerField, AddPointer->PointerSize);
if (PointerValue >= Blob2->Size) {
- DEBUG ((DEBUG_ERROR, "%a: invalid pointer value in \"%a\"\n", __FUNCTION__,
- AddPointer->PointerFile));
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: invalid pointer value in \"%a\"\n",
+ __FUNCTION__,
+ AddPointer->PointerFile
+ ));
return EFI_PROTOCOL_ERROR;
}
@@ -472,23 +513,34 @@ ProcessCmdAddPointer ( ASSERT ((UINTN)Blob2->Base <= MAX_ADDRESS - Blob2->Size);
PointerValue += (UINT64)(UINTN)Blob2->Base;
- if (AddPointer->PointerSize < 8 &&
- RShiftU64 (PointerValue, AddPointer->PointerSize * 8) != 0) {
- DEBUG ((DEBUG_ERROR, "%a: relocated pointer value unrepresentable in "
- "\"%a\"\n", __FUNCTION__, AddPointer->PointerFile));
+ if ((AddPointer->PointerSize < 8) &&
+ (RShiftU64 (PointerValue, AddPointer->PointerSize * 8) != 0))
+ {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: relocated pointer value unrepresentable in "
+ "\"%a\"\n",
+ __FUNCTION__,
+ AddPointer->PointerFile
+ ));
return EFI_PROTOCOL_ERROR;
}
CopyMem (PointerField, &PointerValue, AddPointer->PointerSize);
- DEBUG ((DEBUG_VERBOSE, "%a: PointerFile=\"%a\" PointeeFile=\"%a\" "
- "PointerOffset=0x%x PointerSize=%d\n", __FUNCTION__,
- AddPointer->PointerFile, AddPointer->PointeeFile,
- AddPointer->PointerOffset, AddPointer->PointerSize));
+ DEBUG ((
+ DEBUG_VERBOSE,
+ "%a: PointerFile=\"%a\" PointeeFile=\"%a\" "
+ "PointerOffset=0x%x PointerSize=%d\n",
+ __FUNCTION__,
+ AddPointer->PointerFile,
+ AddPointer->PointeeFile,
+ AddPointer->PointerOffset,
+ AddPointer->PointerSize
+ ));
return EFI_SUCCESS;
}
-
/**
Process a QEMU_LOADER_ADD_CHECKSUM command.
@@ -508,12 +560,12 @@ STATIC EFI_STATUS
EFIAPI
ProcessCmdAddChecksum (
- IN CONST QEMU_LOADER_ADD_CHECKSUM *AddChecksum,
- IN CONST ORDERED_COLLECTION *Tracker
+ IN CONST QEMU_LOADER_ADD_CHECKSUM *AddChecksum,
+ IN CONST ORDERED_COLLECTION *Tracker
)
{
- ORDERED_COLLECTION_ENTRY *TrackerEntry;
- BLOB *Blob;
+ ORDERED_COLLECTION_ENTRY *TrackerEntry;
+ BLOB *Blob;
if (AddChecksum->File[QEMU_LOADER_FNAME_SIZE - 1] != '\0') {
DEBUG ((DEBUG_ERROR, "%a: malformed file name\n", __FUNCTION__));
@@ -522,31 +574,46 @@ ProcessCmdAddChecksum ( TrackerEntry = OrderedCollectionFind (Tracker, AddChecksum->File);
if (TrackerEntry == NULL) {
- DEBUG ((DEBUG_ERROR, "%a: invalid blob reference \"%a\"\n", __FUNCTION__,
- AddChecksum->File));
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: invalid blob reference \"%a\"\n",
+ __FUNCTION__,
+ AddChecksum->File
+ ));
return EFI_PROTOCOL_ERROR;
}
Blob = OrderedCollectionUserStruct (TrackerEntry);
- if (Blob->Size <= AddChecksum->ResultOffset ||
- Blob->Size < AddChecksum->Length ||
- Blob->Size - AddChecksum->Length < AddChecksum->Start) {
- DEBUG ((DEBUG_ERROR, "%a: invalid checksum range in \"%a\"\n",
- __FUNCTION__, AddChecksum->File));
+ if ((Blob->Size <= AddChecksum->ResultOffset) ||
+ (Blob->Size < AddChecksum->Length) ||
+ (Blob->Size - AddChecksum->Length < AddChecksum->Start))
+ {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: invalid checksum range in \"%a\"\n",
+ __FUNCTION__,
+ AddChecksum->File
+ ));
return EFI_PROTOCOL_ERROR;
}
Blob->Base[AddChecksum->ResultOffset] = CalculateCheckSum8 (
- Blob->Base + AddChecksum->Start,
- AddChecksum->Length
- );
- DEBUG ((DEBUG_VERBOSE, "%a: File=\"%a\" ResultOffset=0x%x Start=0x%x "
- "Length=0x%x\n", __FUNCTION__, AddChecksum->File,
- AddChecksum->ResultOffset, AddChecksum->Start, AddChecksum->Length));
+ Blob->Base + AddChecksum->Start,
+ AddChecksum->Length
+ );
+ DEBUG ((
+ DEBUG_VERBOSE,
+ "%a: File=\"%a\" ResultOffset=0x%x Start=0x%x "
+ "Length=0x%x\n",
+ __FUNCTION__,
+ AddChecksum->File,
+ AddChecksum->ResultOffset,
+ AddChecksum->Start,
+ AddChecksum->Length
+ ));
return EFI_SUCCESS;
}
-
/**
Process a QEMU_LOADER_WRITE_POINTER command.
@@ -581,45 +648,58 @@ ProcessCmdAddChecksum ( STATIC
EFI_STATUS
ProcessCmdWritePointer (
- IN CONST QEMU_LOADER_WRITE_POINTER *WritePointer,
- IN CONST ORDERED_COLLECTION *Tracker,
- IN OUT S3_CONTEXT *S3Context OPTIONAL
+ IN CONST QEMU_LOADER_WRITE_POINTER *WritePointer,
+ IN CONST ORDERED_COLLECTION *Tracker,
+ IN OUT S3_CONTEXT *S3Context OPTIONAL
)
{
- RETURN_STATUS Status;
- FIRMWARE_CONFIG_ITEM PointerItem;
- UINTN PointerItemSize;
- ORDERED_COLLECTION_ENTRY *PointeeEntry;
- BLOB *PointeeBlob;
- UINT64 PointerValue;
-
- if (WritePointer->PointerFile[QEMU_LOADER_FNAME_SIZE - 1] != '\0' ||
- WritePointer->PointeeFile[QEMU_LOADER_FNAME_SIZE - 1] != '\0') {
+ RETURN_STATUS Status;
+ FIRMWARE_CONFIG_ITEM PointerItem;
+ UINTN PointerItemSize;
+ ORDERED_COLLECTION_ENTRY *PointeeEntry;
+ BLOB *PointeeBlob;
+ UINT64 PointerValue;
+
+ if ((WritePointer->PointerFile[QEMU_LOADER_FNAME_SIZE - 1] != '\0') ||
+ (WritePointer->PointeeFile[QEMU_LOADER_FNAME_SIZE - 1] != '\0'))
+ {
DEBUG ((DEBUG_ERROR, "%a: malformed file name\n", __FUNCTION__));
return EFI_PROTOCOL_ERROR;
}
- Status = QemuFwCfgFindFile ((CONST CHAR8 *)WritePointer->PointerFile,
- &PointerItem, &PointerItemSize);
+ Status = QemuFwCfgFindFile (
+ (CONST CHAR8 *)WritePointer->PointerFile,
+ &PointerItem,
+ &PointerItemSize
+ );
PointeeEntry = OrderedCollectionFind (Tracker, WritePointer->PointeeFile);
- if (RETURN_ERROR (Status) || PointeeEntry == NULL) {
- DEBUG ((DEBUG_ERROR,
+ if (RETURN_ERROR (Status) || (PointeeEntry == NULL)) {
+ DEBUG ((
+ DEBUG_ERROR,
"%a: invalid fw_cfg file or blob reference \"%a\" / \"%a\"\n",
- __FUNCTION__, WritePointer->PointerFile, WritePointer->PointeeFile));
+ __FUNCTION__,
+ WritePointer->PointerFile,
+ WritePointer->PointeeFile
+ ));
return EFI_PROTOCOL_ERROR;
}
- if ((WritePointer->PointerSize != 1 && WritePointer->PointerSize != 2 &&
- WritePointer->PointerSize != 4 && WritePointer->PointerSize != 8) ||
+ if (((WritePointer->PointerSize != 1) && (WritePointer->PointerSize != 2) &&
+ (WritePointer->PointerSize != 4) && (WritePointer->PointerSize != 8)) ||
(PointerItemSize < WritePointer->PointerSize) ||
(PointerItemSize - WritePointer->PointerSize <
- WritePointer->PointerOffset)) {
- DEBUG ((DEBUG_ERROR, "%a: invalid pointer location or size in \"%a\"\n",
- __FUNCTION__, WritePointer->PointerFile));
+ WritePointer->PointerOffset))
+ {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: invalid pointer location or size in \"%a\"\n",
+ __FUNCTION__,
+ WritePointer->PointerFile
+ ));
return EFI_PROTOCOL_ERROR;
}
- PointeeBlob = OrderedCollectionUserStruct (PointeeEntry);
+ PointeeBlob = OrderedCollectionUserStruct (PointeeEntry);
PointerValue = WritePointer->PointeeOffset;
if (PointerValue >= PointeeBlob->Size) {
DEBUG ((DEBUG_ERROR, "%a: invalid PointeeOffset\n", __FUNCTION__));
@@ -633,10 +713,15 @@ ProcessCmdWritePointer ( ASSERT ((UINTN)PointeeBlob->Base <= MAX_ADDRESS - PointeeBlob->Size);
PointerValue += (UINT64)(UINTN)PointeeBlob->Base;
- if (WritePointer->PointerSize < 8 &&
- RShiftU64 (PointerValue, WritePointer->PointerSize * 8) != 0) {
- DEBUG ((DEBUG_ERROR, "%a: pointer value unrepresentable in \"%a\"\n",
- __FUNCTION__, WritePointer->PointerFile));
+ if ((WritePointer->PointerSize < 8) &&
+ (RShiftU64 (PointerValue, WritePointer->PointerSize * 8) != 0))
+ {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: pointer value unrepresentable in \"%a\"\n",
+ __FUNCTION__,
+ WritePointer->PointerFile
+ ));
return EFI_PROTOCOL_ERROR;
}
@@ -645,7 +730,7 @@ ProcessCmdWritePointer ( // form, to be replayed during S3 resume.
//
if (S3Context != NULL) {
- EFI_STATUS SaveStatus;
+ EFI_STATUS SaveStatus;
SaveStatus = SaveCondensedWritePointerToS3Context (
S3Context,
@@ -670,15 +755,20 @@ ProcessCmdWritePointer ( //
PointeeBlob->HostsOnlyTableData = FALSE;
- DEBUG ((DEBUG_VERBOSE, "%a: PointerFile=\"%a\" PointeeFile=\"%a\" "
- "PointerOffset=0x%x PointeeOffset=0x%x PointerSize=%d\n", __FUNCTION__,
- WritePointer->PointerFile, WritePointer->PointeeFile,
- WritePointer->PointerOffset, WritePointer->PointeeOffset,
- WritePointer->PointerSize));
+ DEBUG ((
+ DEBUG_VERBOSE,
+ "%a: PointerFile=\"%a\" PointeeFile=\"%a\" "
+ "PointerOffset=0x%x PointeeOffset=0x%x PointerSize=%d\n",
+ __FUNCTION__,
+ WritePointer->PointerFile,
+ WritePointer->PointeeFile,
+ WritePointer->PointerOffset,
+ WritePointer->PointeeOffset,
+ WritePointer->PointerSize
+ ));
return EFI_SUCCESS;
}
-
/**
Undo a QEMU_LOADER_WRITE_POINTER command.
@@ -692,16 +782,19 @@ ProcessCmdWritePointer ( STATIC
VOID
UndoCmdWritePointer (
- IN CONST QEMU_LOADER_WRITE_POINTER *WritePointer
+ IN CONST QEMU_LOADER_WRITE_POINTER *WritePointer
)
{
- RETURN_STATUS Status;
- FIRMWARE_CONFIG_ITEM PointerItem;
- UINTN PointerItemSize;
- UINT64 PointerValue;
-
- Status = QemuFwCfgFindFile ((CONST CHAR8 *)WritePointer->PointerFile,
- &PointerItem, &PointerItemSize);
+ RETURN_STATUS Status;
+ FIRMWARE_CONFIG_ITEM PointerItem;
+ UINTN PointerItemSize;
+ UINT64 PointerValue;
+
+ Status = QemuFwCfgFindFile (
+ (CONST CHAR8 *)WritePointer->PointerFile,
+ &PointerItem,
+ &PointerItemSize
+ );
ASSERT_RETURN_ERROR (Status);
PointerValue = 0;
@@ -709,18 +802,21 @@ UndoCmdWritePointer ( QemuFwCfgSkipBytes (WritePointer->PointerOffset);
QemuFwCfgWriteBytes (WritePointer->PointerSize, &PointerValue);
- DEBUG ((DEBUG_VERBOSE,
- "%a: PointerFile=\"%a\" PointerOffset=0x%x PointerSize=%d\n", __FUNCTION__,
- WritePointer->PointerFile, WritePointer->PointerOffset,
- WritePointer->PointerSize));
+ DEBUG ((
+ DEBUG_VERBOSE,
+ "%a: PointerFile=\"%a\" PointerOffset=0x%x PointerSize=%d\n",
+ __FUNCTION__,
+ WritePointer->PointerFile,
+ WritePointer->PointerOffset,
+ WritePointer->PointerSize
+ ));
}
-
//
// We'll be saving the keys of installed tables so that we can roll them back
// in case of failure. 128 tables should be enough for anyone (TM).
//
-#define INSTALLED_TABLES_MAX 128
+#define INSTALLED_TABLES_MAX 128
/**
Process a QEMU_LOADER_ADD_POINTER command in order to see if its target byte
@@ -785,37 +881,37 @@ STATIC EFI_STATUS
EFIAPI
Process2ndPassCmdAddPointer (
- IN CONST QEMU_LOADER_ADD_POINTER *AddPointer,
- IN CONST ORDERED_COLLECTION *Tracker,
- IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol,
- IN OUT UINTN InstalledKey[INSTALLED_TABLES_MAX],
- IN OUT INT32 *NumInstalled,
- IN OUT ORDERED_COLLECTION *SeenPointers
+ IN CONST QEMU_LOADER_ADD_POINTER *AddPointer,
+ IN CONST ORDERED_COLLECTION *Tracker,
+ IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol,
+ IN OUT UINTN InstalledKey[INSTALLED_TABLES_MAX],
+ IN OUT INT32 *NumInstalled,
+ IN OUT ORDERED_COLLECTION *SeenPointers
)
{
- CONST ORDERED_COLLECTION_ENTRY *TrackerEntry;
- CONST ORDERED_COLLECTION_ENTRY *TrackerEntry2;
- ORDERED_COLLECTION_ENTRY *SeenPointerEntry;
- CONST BLOB *Blob;
- BLOB *Blob2;
- CONST UINT8 *PointerField;
- UINT64 PointerValue;
- UINTN Blob2Remaining;
- UINTN TableSize;
- CONST EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *Facs;
- CONST EFI_ACPI_DESCRIPTION_HEADER *Header;
- EFI_STATUS Status;
-
- if (*NumInstalled < 0 || *NumInstalled > INSTALLED_TABLES_MAX) {
+ CONST ORDERED_COLLECTION_ENTRY *TrackerEntry;
+ CONST ORDERED_COLLECTION_ENTRY *TrackerEntry2;
+ ORDERED_COLLECTION_ENTRY *SeenPointerEntry;
+ CONST BLOB *Blob;
+ BLOB *Blob2;
+ CONST UINT8 *PointerField;
+ UINT64 PointerValue;
+ UINTN Blob2Remaining;
+ UINTN TableSize;
+ CONST EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *Facs;
+ CONST EFI_ACPI_DESCRIPTION_HEADER *Header;
+ EFI_STATUS Status;
+
+ if ((*NumInstalled < 0) || (*NumInstalled > INSTALLED_TABLES_MAX)) {
return EFI_INVALID_PARAMETER;
}
- TrackerEntry = OrderedCollectionFind (Tracker, AddPointer->PointerFile);
+ TrackerEntry = OrderedCollectionFind (Tracker, AddPointer->PointerFile);
TrackerEntry2 = OrderedCollectionFind (Tracker, AddPointer->PointeeFile);
- Blob = OrderedCollectionUserStruct (TrackerEntry);
- Blob2 = OrderedCollectionUserStruct (TrackerEntry2);
- PointerField = Blob->Base + AddPointer->PointerOffset;
- PointerValue = 0;
+ Blob = OrderedCollectionUserStruct (TrackerEntry);
+ Blob2 = OrderedCollectionUserStruct (TrackerEntry2);
+ PointerField = Blob->Base + AddPointer->PointerOffset;
+ PointerValue = 0;
CopyMem (&PointerValue, PointerField, AddPointer->PointerSize);
//
@@ -823,7 +919,7 @@ Process2ndPassCmdAddPointer ( // by the Blob2->Size check and later checks in ProcessCmdAddPointer().
//
Blob2Remaining = (UINTN)Blob2->Base;
- ASSERT(PointerValue >= Blob2Remaining);
+ ASSERT (PointerValue >= Blob2Remaining);
Blob2Remaining += Blob2->Size;
ASSERT (PointerValue < Blob2Remaining);
@@ -845,13 +941,20 @@ Process2ndPassCmdAddPointer ( ));
Status = EFI_SUCCESS;
}
+
return Status;
}
- Blob2Remaining -= (UINTN) PointerValue;
- DEBUG ((DEBUG_VERBOSE, "%a: checking for ACPI header in \"%a\" at 0x%Lx "
- "(remaining: 0x%Lx): ", __FUNCTION__, AddPointer->PointeeFile,
- PointerValue, (UINT64)Blob2Remaining));
+ Blob2Remaining -= (UINTN)PointerValue;
+ DEBUG ((
+ DEBUG_VERBOSE,
+ "%a: checking for ACPI header in \"%a\" at 0x%Lx "
+ "(remaining: 0x%Lx): ",
+ __FUNCTION__,
+ AddPointer->PointeeFile,
+ PointerValue,
+ (UINT64)Blob2Remaining
+ ));
TableSize = 0;
@@ -861,12 +964,17 @@ Process2ndPassCmdAddPointer ( if (sizeof *Facs <= Blob2Remaining) {
Facs = (EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UINTN)PointerValue;
- if (Facs->Length >= sizeof *Facs &&
- Facs->Length <= Blob2Remaining &&
- Facs->Signature ==
- EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE) {
- DEBUG ((DEBUG_VERBOSE, "found \"%-4.4a\" size 0x%x\n",
- (CONST CHAR8 *)&Facs->Signature, Facs->Length));
+ if ((Facs->Length >= sizeof *Facs) &&
+ (Facs->Length <= Blob2Remaining) &&
+ (Facs->Signature ==
+ EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE))
+ {
+ DEBUG ((
+ DEBUG_VERBOSE,
+ "found \"%-4.4a\" size 0x%x\n",
+ (CONST CHAR8 *)&Facs->Signature,
+ Facs->Length
+ ));
TableSize = Facs->Length;
}
}
@@ -874,28 +982,34 @@ Process2ndPassCmdAddPointer ( //
// check for the uniform tables
//
- if (TableSize == 0 && sizeof *Header <= Blob2Remaining) {
+ if ((TableSize == 0) && (sizeof *Header <= Blob2Remaining)) {
Header = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)PointerValue;
- if (Header->Length >= sizeof *Header &&
- Header->Length <= Blob2Remaining &&
- CalculateSum8 ((CONST UINT8 *)Header, Header->Length) == 0) {
+ if ((Header->Length >= sizeof *Header) &&
+ (Header->Length <= Blob2Remaining) &&
+ (CalculateSum8 ((CONST UINT8 *)Header, Header->Length) == 0))
+ {
//
// This looks very much like an ACPI table from QEMU:
// - Length field consistent with both ACPI and containing blob size
// - checksum is correct
//
- DEBUG ((DEBUG_VERBOSE, "found \"%-4.4a\" size 0x%x\n",
- (CONST CHAR8 *)&Header->Signature, Header->Length));
+ DEBUG ((
+ DEBUG_VERBOSE,
+ "found \"%-4.4a\" size 0x%x\n",
+ (CONST CHAR8 *)&Header->Signature,
+ Header->Length
+ ));
TableSize = Header->Length;
//
// Skip RSDT and XSDT because those are handled by
// EFI_ACPI_TABLE_PROTOCOL automatically.
- if (Header->Signature ==
- EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE ||
- Header->Signature ==
- EFI_ACPI_2_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE) {
+ if ((Header->Signature ==
+ EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE) ||
+ (Header->Signature ==
+ EFI_ACPI_2_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE))
+ {
return EFI_SUCCESS;
}
}
@@ -908,20 +1022,32 @@ Process2ndPassCmdAddPointer ( }
if (*NumInstalled == INSTALLED_TABLES_MAX) {
- DEBUG ((DEBUG_ERROR, "%a: can't install more than %d tables\n",
- __FUNCTION__, INSTALLED_TABLES_MAX));
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: can't install more than %d tables\n",
+ __FUNCTION__,
+ INSTALLED_TABLES_MAX
+ ));
Status = EFI_OUT_OF_RESOURCES;
goto RollbackSeenPointer;
}
- Status = AcpiProtocol->InstallAcpiTable (AcpiProtocol,
- (VOID *)(UINTN)PointerValue, TableSize,
- &InstalledKey[*NumInstalled]);
+ Status = AcpiProtocol->InstallAcpiTable (
+ AcpiProtocol,
+ (VOID *)(UINTN)PointerValue,
+ TableSize,
+ &InstalledKey[*NumInstalled]
+ );
if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a: InstallAcpiTable(): %r\n", __FUNCTION__,
- Status));
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: InstallAcpiTable(): %r\n",
+ __FUNCTION__,
+ Status
+ ));
goto RollbackSeenPointer;
}
+
++*NumInstalled;
return EFI_SUCCESS;
@@ -930,7 +1056,6 @@ RollbackSeenPointer: return Status;
}
-
/**
Download, process, and install ACPI table data from the QEMU loader
interface.
@@ -956,33 +1081,38 @@ RollbackSeenPointer: EFI_STATUS
EFIAPI
InstallQemuFwCfgTables (
- IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol
+ IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol
)
{
- EFI_STATUS Status;
- FIRMWARE_CONFIG_ITEM FwCfgItem;
- UINTN FwCfgSize;
- QEMU_LOADER_ENTRY *LoaderStart;
- CONST QEMU_LOADER_ENTRY *LoaderEntry, *LoaderEnd;
- CONST QEMU_LOADER_ENTRY *WritePointerSubsetEnd;
- ORIGINAL_ATTRIBUTES *OriginalPciAttributes;
- UINTN OriginalPciAttributesCount;
- ORDERED_COLLECTION *AllocationsRestrictedTo32Bit;
- S3_CONTEXT *S3Context;
- ORDERED_COLLECTION *Tracker;
- UINTN *InstalledKey;
- INT32 Installed;
- ORDERED_COLLECTION_ENTRY *TrackerEntry, *TrackerEntry2;
- ORDERED_COLLECTION *SeenPointers;
- ORDERED_COLLECTION_ENTRY *SeenPointerEntry, *SeenPointerEntry2;
+ EFI_STATUS Status;
+ FIRMWARE_CONFIG_ITEM FwCfgItem;
+ UINTN FwCfgSize;
+ QEMU_LOADER_ENTRY *LoaderStart;
+ CONST QEMU_LOADER_ENTRY *LoaderEntry, *LoaderEnd;
+ CONST QEMU_LOADER_ENTRY *WritePointerSubsetEnd;
+ ORIGINAL_ATTRIBUTES *OriginalPciAttributes;
+ UINTN OriginalPciAttributesCount;
+ ORDERED_COLLECTION *AllocationsRestrictedTo32Bit;
+ S3_CONTEXT *S3Context;
+ ORDERED_COLLECTION *Tracker;
+ UINTN *InstalledKey;
+ INT32 Installed;
+ ORDERED_COLLECTION_ENTRY *TrackerEntry, *TrackerEntry2;
+ ORDERED_COLLECTION *SeenPointers;
+ ORDERED_COLLECTION_ENTRY *SeenPointerEntry, *SeenPointerEntry2;
Status = QemuFwCfgFindFile ("etc/table-loader", &FwCfgItem, &FwCfgSize);
if (EFI_ERROR (Status)) {
return Status;
}
+
if (FwCfgSize % sizeof *LoaderEntry != 0) {
- DEBUG ((DEBUG_ERROR, "%a: \"etc/table-loader\" has invalid size 0x%Lx\n",
- __FUNCTION__, (UINT64)FwCfgSize));
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: \"etc/table-loader\" has invalid size 0x%Lx\n",
+ __FUNCTION__,
+ (UINT64)FwCfgSize
+ ));
return EFI_PROTOCOL_ERROR;
}
@@ -990,6 +1120,7 @@ InstallQemuFwCfgTables ( if (LoaderStart == NULL) {
return EFI_OUT_OF_RESOURCES;
}
+
EnablePciDecoding (&OriginalPciAttributes, &OriginalPciAttributesCount);
QemuFwCfgSelectItem (FwCfgItem);
QemuFwCfgReadBytes (FwCfgSize, LoaderStart);
@@ -997,11 +1128,11 @@ InstallQemuFwCfgTables ( LoaderEnd = LoaderStart + FwCfgSize / sizeof *LoaderEntry;
AllocationsRestrictedTo32Bit = NULL;
- Status = CollectAllocationsRestrictedTo32Bit (
- &AllocationsRestrictedTo32Bit,
- LoaderStart,
- LoaderEnd
- );
+ Status = CollectAllocationsRestrictedTo32Bit (
+ &AllocationsRestrictedTo32Bit,
+ LoaderStart,
+ LoaderEnd
+ );
if (EFI_ERROR (Status)) {
goto FreeLoader;
}
@@ -1034,36 +1165,48 @@ InstallQemuFwCfgTables ( WritePointerSubsetEnd = LoaderStart;
for (LoaderEntry = LoaderStart; LoaderEntry < LoaderEnd; ++LoaderEntry) {
switch (LoaderEntry->Type) {
- case QemuLoaderCmdAllocate:
- Status = ProcessCmdAllocate (
- &LoaderEntry->Command.Allocate,
- Tracker,
- AllocationsRestrictedTo32Bit
- );
- break;
+ case QemuLoaderCmdAllocate:
+ Status = ProcessCmdAllocate (
+ &LoaderEntry->Command.Allocate,
+ Tracker,
+ AllocationsRestrictedTo32Bit
+ );
+ break;
- case QemuLoaderCmdAddPointer:
- Status = ProcessCmdAddPointer (&LoaderEntry->Command.AddPointer,
- Tracker);
- break;
+ case QemuLoaderCmdAddPointer:
+ Status = ProcessCmdAddPointer (
+ &LoaderEntry->Command.AddPointer,
+ Tracker
+ );
+ break;
- case QemuLoaderCmdAddChecksum:
- Status = ProcessCmdAddChecksum (&LoaderEntry->Command.AddChecksum,
- Tracker);
- break;
+ case QemuLoaderCmdAddChecksum:
+ Status = ProcessCmdAddChecksum (
+ &LoaderEntry->Command.AddChecksum,
+ Tracker
+ );
+ break;
- case QemuLoaderCmdWritePointer:
- Status = ProcessCmdWritePointer (&LoaderEntry->Command.WritePointer,
- Tracker, S3Context);
+ case QemuLoaderCmdWritePointer:
+ Status = ProcessCmdWritePointer (
+ &LoaderEntry->Command.WritePointer,
+ Tracker,
+ S3Context
+ );
if (!EFI_ERROR (Status)) {
WritePointerSubsetEnd = LoaderEntry + 1;
}
+
break;
- default:
- DEBUG ((DEBUG_VERBOSE, "%a: unknown loader command: 0x%x\n",
- __FUNCTION__, LoaderEntry->Type));
- break;
+ default:
+ DEBUG ((
+ DEBUG_VERBOSE,
+ "%a: unknown loader command: 0x%x\n",
+ __FUNCTION__,
+ LoaderEntry->Type
+ ));
+ break;
}
if (EFI_ERROR (Status)) {
@@ -1113,6 +1256,7 @@ InstallQemuFwCfgTables ( if (EFI_ERROR (Status)) {
goto UninstallAcpiTables;
}
+
//
// Ownership of S3Context has been transferred.
//
@@ -1134,10 +1278,12 @@ UninstallAcpiTables: for (SeenPointerEntry = OrderedCollectionMin (SeenPointers);
SeenPointerEntry != NULL;
- SeenPointerEntry = SeenPointerEntry2) {
+ SeenPointerEntry = SeenPointerEntry2)
+ {
SeenPointerEntry2 = OrderedCollectionNext (SeenPointerEntry);
OrderedCollectionDelete (SeenPointers, SeenPointerEntry, NULL);
}
+
OrderedCollectionUninit (SeenPointers);
FreeKeys:
@@ -1164,21 +1310,28 @@ RollbackWritePointersAndFreeTracker: // not directly part of some ACPI table.
//
for (TrackerEntry = OrderedCollectionMin (Tracker); TrackerEntry != NULL;
- TrackerEntry = TrackerEntry2) {
- VOID *UserStruct;
- BLOB *Blob;
+ TrackerEntry = TrackerEntry2)
+ {
+ VOID *UserStruct;
+ BLOB *Blob;
TrackerEntry2 = OrderedCollectionNext (TrackerEntry);
OrderedCollectionDelete (Tracker, TrackerEntry, &UserStruct);
Blob = UserStruct;
if (EFI_ERROR (Status) || Blob->HostsOnlyTableData) {
- DEBUG ((DEBUG_VERBOSE, "%a: freeing \"%a\"\n", __FUNCTION__,
- Blob->File));
+ DEBUG ((
+ DEBUG_VERBOSE,
+ "%a: freeing \"%a\"\n",
+ __FUNCTION__,
+ Blob->File
+ ));
gBS->FreePages ((UINTN)Blob->Base, EFI_SIZE_TO_PAGES (Blob->Size));
}
+
FreePool (Blob);
}
+
OrderedCollectionUninit (Tracker);
FreeS3Context:
diff --git a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatform.c b/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatform.c index 057a450af9..aff1ad0c97 100644 --- a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatform.c +++ b/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatform.c @@ -23,10 +23,10 @@ EFI_STATUS
EFIAPI
InstallAcpiTables (
- IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable
+ IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
Status = InstallQemuFwCfgTables (AcpiTable);
return Status;
|