summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ArmPkg/ArmPkg.dec3
-rw-r--r--ArmPkg/Include/Guid/TransferListHob.h23
-rw-r--r--ArmPkg/Include/IndustryStandard/ArmTransferList.h12
-rw-r--r--ArmPkg/Include/Library/ArmTransferListLib.h58
-rw-r--r--ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.c156
-rw-r--r--ArmPlatformPkg/ArmPlatformPkg.dsc1
-rw-r--r--ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.c8
-rw-r--r--ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.inf2
-rw-r--r--ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c2
-rw-r--r--ArmPlatformPkg/PeilessSec/AArch64/ModuleEntryPoint.S20
-rw-r--r--ArmPlatformPkg/PeilessSec/PeilessSec.c31
-rw-r--r--ArmPlatformPkg/PeilessSec/PeilessSec.h2
-rw-r--r--ArmPlatformPkg/PeilessSec/PeilessSec.inf2
-rw-r--r--ArmPlatformPkg/PlatformPei/PlatformPeim.c21
-rw-r--r--ArmPlatformPkg/PlatformPei/PlatformPeim.inf4
-rw-r--r--ArmPlatformPkg/Sec/AArch64/ModuleEntryPoint.S16
-rw-r--r--ArmPlatformPkg/Sec/Sec.c48
-rw-r--r--ArmPlatformPkg/Sec/Sec.h1
-rw-r--r--ArmPlatformPkg/Sec/Sec.inf2
-rw-r--r--ArmVirtPkg/ArmVirtCloudHv.dsc1
-rw-r--r--ArmVirtPkg/ArmVirtQemu.dsc1
-rwxr-xr-xBaseTools/Conf/tools_def.template48
-rw-r--r--BaseTools/Source/Python/FMMT/core/FvHandler.py26
-rw-r--r--DynamicTablesPkg/DynamicTables.dsc.inc2
-rw-r--r--DynamicTablesPkg/DynamicTablesPkg.ci.yaml3
-rw-r--r--DynamicTablesPkg/DynamicTablesPkg.dec6
-rw-r--r--DynamicTablesPkg/DynamicTablesPkg.dsc1
-rw-r--r--DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h13
-rw-r--r--DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h117
-rw-r--r--DynamicTablesPkg/Include/Library/Tpm2DeviceTableLib.h50
-rw-r--r--DynamicTablesPkg/Library/Acpi/Common/AcpiTpm2Lib/AcpiTpm2Lib.inf5
-rw-r--r--DynamicTablesPkg/Library/Acpi/Common/AcpiTpm2Lib/Tpm2Generator.c251
-rw-r--r--DynamicTablesPkg/Library/Acpi/X64/SsdtSerialPortFixupLib/SsdtSerialPortFixupLib.c533
-rw-r--r--DynamicTablesPkg/Library/Acpi/X64/SsdtSerialPortFixupLib/SsdtSerialPortFixupLib.inf32
-rw-r--r--DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c460
-rw-r--r--DynamicTablesPkg/Library/Common/Tpm2DeviceTableLib/Tpm2DeviceTableLib.c329
-rw-r--r--DynamicTablesPkg/Library/Common/Tpm2DeviceTableLib/Tpm2DeviceTableLib.inf33
-rw-r--r--DynamicTablesPkg/Library/Common/Tpm2DeviceTableLib/Tpm2DeviceTableTemplate.asl44
-rw-r--r--EmbeddedPkg/Include/Protocol/HardwareInterrupt2.h4
-rw-r--r--MdeModulePkg/Core/Dxe/Image/Image.c11
-rw-r--r--MdeModulePkg/Core/Pei/Image/Image.c12
-rw-r--r--MdeModulePkg/Core/PiSmmCore/Dispatcher.c11
-rw-r--r--MdeModulePkg/MdeModulePkg.dec9
-rw-r--r--MdePkg/Include/IndustryStandard/Acpi50.h34
-rw-r--r--MdePkg/Include/IndustryStandard/Acpi66.h184
-rw-r--r--OvmfPkg/CloudHv/CloudHvX64.dsc2
-rw-r--r--OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf4
-rw-r--r--OvmfPkg/CpuHotplugSmm/FirstSmiHandler.nasm26
-rw-r--r--OvmfPkg/CpuHotplugSmm/FirstSmiHandlerContext.h8
-rw-r--r--OvmfPkg/CpuHotplugSmm/Smbase.c24
-rw-r--r--OvmfPkg/Include/Library/PlatformInitLib.h1
-rw-r--r--OvmfPkg/PlatformPei/FeatureControl.c1
-rw-r--r--OvmfPkg/RiscVVirt/Library/PlatformSecLib/SecEntry.S3
-rw-r--r--OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc6
-rw-r--r--OvmfPkg/Tcg/TdTcg2Dxe/TdTcg2Dxe.c33
-rw-r--r--SecurityPkg/FvReportPei/FvReportPei.c25
-rw-r--r--SecurityPkg/HddPassword/HddPasswordDxe.c26
-rw-r--r--SecurityPkg/Library/AuthVariableLib/AuthService.c6
-rw-r--r--SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c13
-rw-r--r--SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.c111
-rw-r--r--SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c2
-rw-r--r--SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.c14
-rw-r--r--SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.c5
-rw-r--r--SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.c5
-rw-r--r--SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c17
-rw-r--r--SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c22
-rw-r--r--SecurityPkg/Library/SecureBootVariableProvisionLib/SecureBootVariableProvisionLib.c9
-rw-r--r--SecurityPkg/Library/TcgEventLogRecordLib/TcgEventLogRecordLib.c2
-rw-r--r--SecurityPkg/Library/Tpm12DeviceLibDTpm/Tpm12Tis.c2
-rw-r--r--SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmDump.c10
-rw-r--r--SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfa.h50
-rw-r--r--SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfa.inf1
-rw-r--r--SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfaBase.c19
-rw-r--r--SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceSecLibFfa.inf51
-rw-r--r--SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2InfoFfa.c87
-rw-r--r--SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2InfoSecFfa.c62
-rw-r--r--SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2InstanceLibFfa.inf1
-rw-r--r--SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2ServiceFfaRaw.c48
-rw-r--r--SecurityPkg/RandomNumberGenerator/RngDxe/Rand/AesCore.c7
-rw-r--r--SecurityPkg/SecurityPkg.dsc5
-rw-r--r--SecurityPkg/Tcg/Opal/OpalPassword/OpalDriver.c2
-rw-r--r--SecurityPkg/Tcg/Opal/OpalPassword/OpalHii.c25
-rw-r--r--SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDriver.c6
-rw-r--r--SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigFfaPei.inf53
-rw-r--r--SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigFfaPeim.c198
-rw-r--r--SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c39
-rw-r--r--SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c16
-rw-r--r--SecurityPkg/Tcg/TcgDxe/TcgDxe.c5
-rw-r--r--SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c6
-rw-r--r--SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c46
-rw-r--r--ShellPkg/Application/Shell/Shell.c8
-rw-r--r--ShellPkg/Application/Shell/ShellEnvVar.c30
-rw-r--r--ShellPkg/Application/Shell/ShellProtocol.c6
-rw-r--r--ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c54
-rw-r--r--ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c5
-rw-r--r--ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c2
-rw-r--r--ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf2
-rw-r--r--ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c4
-rw-r--r--ShellPkg/ShellPkg.ci.yaml1
-rw-r--r--StandaloneMmPkg/Core/Dispatcher.c10
-rw-r--r--UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandlerLib.inf42
-rw-r--r--UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandlerLib.uni13
-rw-r--r--UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf13
-rw-r--r--UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/Backtrace.c175
-rw-r--r--UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/Backtrace.h57
-rw-r--r--UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/BacktraceHelper.c71
-rw-r--r--UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/BacktraceHelperSec.c42
-rw-r--r--UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/ExceptionHandler.h (renamed from UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandlerLib.h)8
-rw-r--r--UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/ExceptionHandlerAsm.S (renamed from UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/SupervisorTrapHandler.S)2
-rw-r--r--UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/ExceptionLib.c (renamed from UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandlerLib.c)18
-rw-r--r--UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf9
-rw-r--r--UefiCpuPkg/Library/MpInitLib/AmdSev.c4
-rw-r--r--UefiCpuPkg/Library/MpInitLib/MpLib.c12
-rw-r--r--UefiCpuPkg/Library/MpInitLib/MpLib.h2
-rw-r--r--UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm7
-rw-r--r--UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c12
-rw-r--r--UefiCpuPkg/UefiCpuPkg.ci.yaml1
-rw-r--r--UefiCpuPkg/UefiCpuPkg.dsc1
-rw-r--r--UefiPayloadPkg/PchSmiDispatchSmm/PchSmiDispatchSmm.c1
119 files changed, 3933 insertions, 415 deletions
diff --git a/ArmPkg/ArmPkg.dec b/ArmPkg/ArmPkg.dec
index ab3c3b3..a2b7c17 100644
--- a/ArmPkg/ArmPkg.dec
+++ b/ArmPkg/ArmPkg.dec
@@ -87,6 +87,8 @@
# Include/Guid/ArmMpCoreInfo.h
gArmMpCoreInfoGuid = { 0xa4ee0728, 0xe5d7, 0x4ac5, {0xb2, 0x1e, 0x65, 0x8e, 0xd8, 0x57, 0xe8, 0x34} }
+ gArmTransferListHobGuid = { 0xebe7bae8, 0xfe18, 0x43c5, { 0xbf, 0x3f, 0xf2, 0xb1, 0xaf, 0xb2, 0xdf, 0xb8 } }
+
[Protocols.common]
## Arm System Control and Management Interface(SCMI) Base protocol
## ArmPkg/Include/Protocol/ArmScmiBaseProtocol.h
@@ -106,6 +108,7 @@
[Ppis]
## Include/Ppi/ArmMpCoreInfo.h
gArmMpCoreInfoPpiGuid = { 0x6847cc74, 0xe9ec, 0x4f8f, {0xa2, 0x9d, 0xab, 0x44, 0xe7, 0x54, 0xa8, 0xfc} }
+ gArmTransferListPpiGuid = { 0x6d2e9da1, 0x9414, 0x41c3, {0x86, 0xbe, 0xf9, 0x16, 0x9f, 0xb4, 0x76, 0x38} }
[PcdsFeatureFlag.common]
gArmTokenSpaceGuid.PcdCpuDxeProduceDebugSupport|FALSE|BOOLEAN|0x00000001
diff --git a/ArmPkg/Include/Guid/TransferListHob.h b/ArmPkg/Include/Guid/TransferListHob.h
new file mode 100644
index 0000000..b8f9cc0
--- /dev/null
+++ b/ArmPkg/Include/Guid/TransferListHob.h
@@ -0,0 +1,23 @@
+/** @file
+ GUID for the HOB that contains the copy of the Transfer List
+
+ Copyright (C) 2024, Arm Limited. All rights reserved.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - https://github.com/FirmwareHandoff/firmware_handoff
+
+**/
+
+#ifndef ARM_TRANSFER_LIST_HOB_H__
+#define ARM_TRANSFER_LIST_HOB_H__
+
+#define ARM_TRANSFER_LIST_HOB_GUID {\
+ 0xebe7bae8, 0xfe18, 0x43c5, \
+ { 0xbf, 0x3f, 0xf2, 0xb1, 0xaf, 0xb2, 0xdf, 0xb8 } \
+ }
+
+extern EFI_GUID gArmTransferListHobGuid;
+
+#endif
diff --git a/ArmPkg/Include/IndustryStandard/ArmTransferList.h b/ArmPkg/Include/IndustryStandard/ArmTransferList.h
index 455c7d8..3033846 100644
--- a/ArmPkg/Include/IndustryStandard/ArmTransferList.h
+++ b/ArmPkg/Include/IndustryStandard/ArmTransferList.h
@@ -2,7 +2,7 @@
Header file defining a Transfer List and Transfer Entry as specified by the
A-profile Firmware Handoff Protocol specification.
- Copyright (c) 2024, Arm Limited. All rights reserved.<BR>
+ Copyright (c) 2025, Arm Limited. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
@par Reference(s):
@@ -74,6 +74,16 @@
#define TRANSFER_LIST_FL_HAS_CHECKSUM BIT0
/*
+ * Operation codes indicating the validity of the Transfer List.
+ */
+typedef enum {
+ TRANSFER_LIST_OPS_INVALID, /* invalid for any operation */
+ TRANSFER_LIST_OPS_ALL, /* valid for all operations */
+ TRANSFER_LIST_OPS_RO, /* valid for read only */
+ TRANSFER_LIST_OPS_CUSTOM, /* abort or switch to special code to interpret */
+} TRANSFER_LIST_OPS;
+
+/*
* Transfer list starts with the following header.
* Transfer entries followed after the following header.
*/
diff --git a/ArmPkg/Include/Library/ArmTransferListLib.h b/ArmPkg/Include/Library/ArmTransferListLib.h
index 96a1227..fb0c699 100644
--- a/ArmPkg/Include/Library/ArmTransferListLib.h
+++ b/ArmPkg/Include/Library/ArmTransferListLib.h
@@ -2,7 +2,7 @@
Library that implements the helper functions to parse and pack a Transfer
List as specified by the A-profile Firmware Handoff Specification.
- Copyright (c) 2022, Arm Limited. All rights reserved.<BR>
+ Copyright (c) 2022 - 2025, Arm Limited. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
@par Reference(s):
@@ -21,7 +21,7 @@
/**
Return the first Transfer Entry Node in the Transfer List.
- @param [in] TransferListHeader TransferListHeader
+ @param [in] TransferListHeader Pointer to the Transfer List Header.
@return Pointer to the Transfer Entry Node if successful otherwise NULL
@@ -103,4 +103,58 @@ TransferListGetEntryData (
IN TRANSFER_ENTRY_HEADER *TransferEntry
);
+/**
+ Dump the transfer list to the debug output.
+
+ @param [in] TransferListHeader Pointer to the Transfer List Header
+
+**/
+VOID
+EFIAPI
+TransferListDump (
+ IN TRANSFER_LIST_HEADER *TransferListHeader
+ );
+
+/**
+ Verify the checksum of the transfer list.
+
+ @param [in] TransferListHeader Pointer to the Transfer List Header
+
+ @retval FALSE Invalid Checksum
+ @retval TRUE Valid Checksum
+**/
+BOOLEAN
+EFIAPI
+TransferListVerifyChecksum (
+ IN TRANSFER_LIST_HEADER *TransferListHeader
+ );
+
+/**
+ Check the header of the Transfer List.
+
+ @param [in] TransferListHeader Pointer to the Transfer List Header
+
+ @return TRANSFER_LIST_OPS code indicating the validity of the Transfer List
+**/
+TRANSFER_LIST_OPS
+EFIAPI
+TransferListCheckHeader (
+ IN TRANSFER_LIST_HEADER *TransferListHeader
+ );
+
+/**
+ Find a Transfer Entry Node in the Transfer List matched with the given tag-id.
+
+ @param [in] TransferListHeader Pointer to the Transfer List Header
+ @param [in] TagId Tag id
+
+ @return Pointer to the Transfer Entry Node if successful otherwise NULL
+**/
+TRANSFER_ENTRY_HEADER *
+EFIAPI
+TransferListFindEntry (
+ IN TRANSFER_LIST_HEADER *TransferListHeader,
+ IN UINT16 TagId
+ );
+
#endif // ARM_TRANSFER_LIST_LIB_
diff --git a/ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.c b/ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.c
index 7cd203e..af8170e 100644
--- a/ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.c
+++ b/ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.c
@@ -2,7 +2,7 @@
Library that implements the helper functions to parse and pack a Transfer
List as specified by the A-profile Firmware Handoff Specification.
- Copyright (c) 2022, Arm Limited. All rights reserved.<BR>
+ Copyright (c) 2022 - 2025, Arm Limited. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
@par Reference(s):
@@ -15,6 +15,90 @@
#include <Library/DebugLib.h>
/**
+ This function verifies the checksum of the Transfer List.
+
+ @param [in] TransferListHeader Pointer to the Transfer List Header
+
+ @retval FALSE Invalid Checksum
+ @retval TRUE Valid Checksum
+
+**/
+BOOLEAN
+EFIAPI
+TransferListVerifyChecksum (
+ IN TRANSFER_LIST_HEADER *TransferListHeader
+ )
+{
+ if (TransferListHeader == NULL) {
+ return FALSE;
+ }
+
+ if ((TransferListHeader->Flags & TRANSFER_LIST_FL_HAS_CHECKSUM) == 0) {
+ return TRUE;
+ }
+
+ return (CalculateSum8 ((UINT8 *)TransferListHeader, TransferListHeader->UsedSize) == 0);
+}
+
+/**
+ This function checks the header of the Transfer List.
+
+ @param [in] TransferListHeader Pointer to the Transfer List Header
+
+ @return TRANSFER_LIST_OPS code indicating the validity of the Transfer List
+
+**/
+TRANSFER_LIST_OPS
+EFIAPI
+TransferListCheckHeader (
+ IN TRANSFER_LIST_HEADER *TransferListHeader
+ )
+{
+ if (TransferListHeader == NULL) {
+ return TRANSFER_LIST_OPS_INVALID;
+ }
+
+ if (TransferListHeader->Signature != TRANSFER_LIST_SIGNATURE_64) {
+ DEBUG ((DEBUG_ERROR, "Bad transfer list signature 0x%x\n", TransferListHeader->Signature));
+ return TRANSFER_LIST_OPS_INVALID;
+ }
+
+ if (TransferListHeader->TotalSize == 0) {
+ DEBUG ((DEBUG_ERROR, "Bad transfer list total size 0x%x\n", TransferListHeader->TotalSize));
+ return TRANSFER_LIST_OPS_INVALID;
+ }
+
+ if (TransferListHeader->UsedSize > TransferListHeader->TotalSize) {
+ DEBUG ((DEBUG_ERROR, "Bad transfer list used size 0x%x\n", TransferListHeader->UsedSize));
+ return TRANSFER_LIST_OPS_INVALID;
+ }
+
+ if (TransferListHeader->HeaderSize != sizeof (TRANSFER_LIST_HEADER)) {
+ DEBUG ((DEBUG_ERROR, "Bad transfer list header size 0x%x\n", TransferListHeader->HeaderSize));
+ return TRANSFER_LIST_OPS_INVALID;
+ }
+
+ if (TransferListVerifyChecksum (TransferListHeader) == FALSE) {
+ DEBUG ((DEBUG_ERROR, "Bad transfer list checksum 0x%x\n", TransferListHeader->Checksum));
+ return TRANSFER_LIST_OPS_INVALID;
+ }
+
+ if (TransferListHeader->Version == 0) {
+ DEBUG ((DEBUG_ERROR, "Transfer list version is invalid\n"));
+ return TRANSFER_LIST_OPS_INVALID;
+ } else if (TransferListHeader->Version == ARM_FW_HANDOFF_PROTOCOL_VERSION) {
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Transfer list version is valid for all operations\n"));
+ return TRANSFER_LIST_OPS_ALL;
+ } else if (TransferListHeader->Version > ARM_FW_HANDOFF_PROTOCOL_VERSION) {
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Transfer list version is valid for read-only\n"));
+ return TRANSFER_LIST_OPS_RO;
+ }
+
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Old or custom transfer list version is detected\n"));
+ return TRANSFER_LIST_OPS_CUSTOM;
+}
+
+/**
Return the first Transfer Entry Node in the Transfer List.
@param [in] TransferListHeader TransferListHeader
@@ -165,3 +249,73 @@ TransferListGetEntryData (
return (VOID *)((UINTN)TransferEntry + TransferEntry->HeaderSize);
}
+
+/**
+ Find a Transfer Entry Node in the Transfer List matched with the given tag-id.
+
+ @param [in] TransferListHeader Pointer to the Transfer List Header
+ @param [in] TagId Tag id
+
+ @return Pointer to the Transfer Entry Node if successful otherwise NULL
+**/
+TRANSFER_ENTRY_HEADER *
+EFIAPI
+TransferListFindEntry (
+ IN TRANSFER_LIST_HEADER *TransferListHeader,
+ IN UINT16 TagId
+ )
+{
+ TRANSFER_ENTRY_HEADER *Entry = NULL;
+
+ do {
+ Entry = TransferListGetNextEntry (TransferListHeader, Entry);
+ } while ((Entry != NULL) && (Entry->TagId != TagId));
+
+ return Entry;
+}
+
+/**
+ Dump the transfer list to the debug output.
+
+ @param [in] TransferListHeader Pointer to the Transfer List Header
+
+**/
+VOID
+EFIAPI
+TransferListDump (
+ IN TRANSFER_LIST_HEADER *TransferListHeader
+ )
+{
+ TRANSFER_ENTRY_HEADER *Entry;
+ UINTN Idx;
+
+ Entry = NULL;
+ Idx = 0;
+
+ if (TransferListHeader == NULL) {
+ return;
+ }
+
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Dump transfer list:\n"));
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "signature 0x%x\n", TransferListHeader->Signature));
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "checksum 0x%x\n", TransferListHeader->Checksum));
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "version 0x%x\n", TransferListHeader->Version));
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "hdr_size 0x%x\n", TransferListHeader->HeaderSize));
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "alignment 0x%x\n", TransferListHeader->Alignment));
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "used_size 0x%x\n", TransferListHeader->UsedSize));
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "total_size 0x%x\n", TransferListHeader->TotalSize));
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "flags 0x%x\n", TransferListHeader->Flags));
+
+ while (TRUE) {
+ Entry = TransferListGetNextEntry (TransferListHeader, Entry);
+ if (Entry == NULL) {
+ break;
+ }
+
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Entry %d:\n", Idx++));
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "tag_id 0x%x\n", Entry->TagId));
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "hdr_size 0x%x\n", Entry->HeaderSize));
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "data_size 0x%x\n", Entry->DataSize));
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "data_addr 0x%lx\n", (UINTN)TransferListGetEntryData (Entry)));
+ }
+}
diff --git a/ArmPlatformPkg/ArmPlatformPkg.dsc b/ArmPlatformPkg/ArmPlatformPkg.dsc
index 062246d..278d3cf 100644
--- a/ArmPlatformPkg/ArmPlatformPkg.dsc
+++ b/ArmPlatformPkg/ArmPlatformPkg.dsc
@@ -70,6 +70,7 @@
UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
+ ArmTransferListLib|ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.inf
[LibraryClasses.common.PEIM]
HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf
diff --git a/ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.c b/ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.c
index bf437af..afa3fc4 100644
--- a/ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.c
+++ b/ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.c
@@ -37,11 +37,11 @@ SerialPortInitialize (
EFI_STATUS Status;
UINT8 Scratch;
- BaudRate = FixedPcdGet64 (PcdUartDefaultBaudRate);
+ BaudRate = PcdGet64 (PcdUartDefaultBaudRate);
ReceiveFifoDepth = 0; // Use default FIFO depth
- Parity = (EFI_PARITY_TYPE)FixedPcdGet8 (PcdUartDefaultParity);
- DataBits = FixedPcdGet8 (PcdUartDefaultDataBits);
- StopBits = (EFI_STOP_BITS_TYPE)FixedPcdGet8 (PcdUartDefaultStopBits);
+ Parity = (EFI_PARITY_TYPE)PcdGet8 (PcdUartDefaultParity);
+ DataBits = PcdGet8 (PcdUartDefaultDataBits);
+ StopBits = (EFI_STOP_BITS_TYPE)PcdGet8 (PcdUartDefaultStopBits);
Status = PL011UartInitializePort (
(UINTN)PcdGet64 (PcdSerialRegisterBase),
diff --git a/ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.inf b/ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.inf
index b6b87f3..07424cc 100644
--- a/ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.inf
+++ b/ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.inf
@@ -33,7 +33,7 @@
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase
-[FixedPcd]
+[Pcd]
gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate
gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits
gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity
diff --git a/ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c b/ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c
index 60f9bc5..e8e2e1d 100644
--- a/ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c
+++ b/ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c
@@ -193,7 +193,7 @@ PL011UartInitializePort (
return RETURN_INVALID_PARAMETER;
}
- Divisor = (UartClkInHz * 4) / *BaudRate;
+ Divisor = (UINT32)((UartClkInHz * 4) / *BaudRate);
Integer = Divisor >> FRACTION_PART_SIZE_IN_BITS;
Fractional = Divisor & FRACTION_PART_MASK;
}
diff --git a/ArmPlatformPkg/PeilessSec/AArch64/ModuleEntryPoint.S b/ArmPlatformPkg/PeilessSec/AArch64/ModuleEntryPoint.S
index 5f285f3..94635ef 100644
--- a/ArmPlatformPkg/PeilessSec/AArch64/ModuleEntryPoint.S
+++ b/ArmPlatformPkg/PeilessSec/AArch64/ModuleEntryPoint.S
@@ -1,13 +1,29 @@
//
-// Copyright (c) 2011 - 2020, Arm Limited. All rights reserved.<BR>
+// Copyright (c) 2011 - 2025, Arm Limited. All rights reserved.<BR>
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
+// @Par Reference(s):
+// - Firmware Handoff specification [https://firmwarehandoff.github.io/firmware_handoff/main]
//
#include <AsmMacroLib.h>
ASM_FUNC(_ModuleEntryPoint)
+
+ // Check if register assignment at handoff matches spec
+ MOV64 (x4, 0x14a0fb10b)
+ cmp x1, x4
+ // Skip TransferList init if x1 is not equal to the TransferList signature
+ b.ne _SkipTransferList
+
+ // Skip TransferList init if x2 is not equal to 0
+ cbnz x2, _SkipTransferList
+
+ // Set the TransferList Base Address from register x3
+ mov x6, x3
+
+_SkipTransferList:
// Do early platform specific actions
bl ASM_PFX(ArmPlatformPeiBootAction)
@@ -76,6 +92,8 @@ _GetStackBase:
MOV32 (x2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
sub x1, x1, x2
+ // Pass Transfer List Base Address
+ mov x2, x6
// Move sec startup address into a data register
// Ensure we're jumping to FV version of the code (not boot remapped alias)
ldr x4, =ASM_PFX(CEntryPoint)
diff --git a/ArmPlatformPkg/PeilessSec/PeilessSec.c b/ArmPlatformPkg/PeilessSec/PeilessSec.c
index 639c374..b9b7196 100644
--- a/ArmPlatformPkg/PeilessSec/PeilessSec.c
+++ b/ArmPlatformPkg/PeilessSec/PeilessSec.c
@@ -53,13 +53,15 @@ GetPlatformPpi (
@param[in] UefiMemoryBase Start of the PI/UEFI memory region
@param[in] StackBase Start of the stack
@param[in] StartTimeStamp Timer value at start of execution
+ @param[in] TransferListBaseAddr Base address of the Transfer List
**/
STATIC
VOID
SecMain (
IN UINTN UefiMemoryBase,
IN UINTN StackBase,
- IN UINT64 StartTimeStamp
+ IN UINT64 StartTimeStamp,
+ IN UINTN TransferListBaseAddr
)
{
EFI_HOB_HANDOFF_INFO_TABLE *HobList;
@@ -71,6 +73,8 @@ SecMain (
UINTN CharCount;
UINTN StacksSize;
FIRMWARE_SEC_PERFORMANCE Performance;
+ VOID *TransferListBase;
+ UINTN *TransferListHobData;
// If ensure the FD is either part of the System Memory or totally outside of the System Memory (XIP)
ASSERT (
@@ -134,6 +138,25 @@ SecMain (
}
}
+ // Dump the Transfer List
+ TransferListBase = (VOID *)TransferListBaseAddr;
+ if (TransferListBase != NULL) {
+ if (TransferListCheckHeader (TransferListBase) != TRANSFER_LIST_OPS_INVALID) {
+ DEBUG_CODE_BEGIN ();
+ TransferListDump (TransferListBase);
+ DEBUG_CODE_END ();
+
+ TransferListHobData = BuildGuidHob (&gArmTransferListHobGuid, sizeof (*TransferListHobData));
+ ASSERT (TransferListHobData != NULL);
+
+ *TransferListHobData = (UINTN)TransferListBase;
+ } else {
+ DEBUG ((DEBUG_ERROR, "%a: No valid operations possible on TransferList found @ 0x%p\n", __func__, TransferListBase));
+ }
+ } else {
+ DEBUG ((DEBUG_INFO, "%a: No TransferList found, continuing boot\n", __func__));
+ }
+
// Store timer value logged at the beginning of firmware image execution
Performance.ResetEnd = GetTimeInNanoSecond (StartTimeStamp);
@@ -167,11 +190,13 @@ SecMain (
@param[in] UefiMemoryBase Start of the PI/UEFI memory region
@param[in] StackBase Start of the stack
+ @param[in] TransferListBaseAddr Base address of the Transfer List
**/
VOID
CEntryPoint (
IN UINTN UefiMemoryBase,
- IN UINTN StackBase
+ IN UINTN StackBase,
+ IN UINTN TransferListBaseAddr
)
{
UINT64 StartTimeStamp;
@@ -198,7 +223,7 @@ CEntryPoint (
FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)
);
- SecMain (UefiMemoryBase, StackBase, StartTimeStamp);
+ SecMain (UefiMemoryBase, StackBase, StartTimeStamp, TransferListBaseAddr);
// DXE Core should always load and never return
ASSERT (FALSE);
diff --git a/ArmPlatformPkg/PeilessSec/PeilessSec.h b/ArmPlatformPkg/PeilessSec/PeilessSec.h
index 70d78ca..73b6b25 100644
--- a/ArmPlatformPkg/PeilessSec/PeilessSec.h
+++ b/ArmPlatformPkg/PeilessSec/PeilessSec.h
@@ -24,6 +24,8 @@
#include <Library/PrintLib.h>
#include <Library/SerialPortLib.h>
#include <Library/TimerLib.h>
+#include <Library/ArmTransferListLib.h>
+#include <Guid/TransferListHob.h>
#include <Ppi/ArmMpCoreInfo.h>
#include <Ppi/GuidedSectionExtraction.h>
diff --git a/ArmPlatformPkg/PeilessSec/PeilessSec.inf b/ArmPlatformPkg/PeilessSec/PeilessSec.inf
index e210d01..db7449f 100644
--- a/ArmPlatformPkg/PeilessSec/PeilessSec.inf
+++ b/ArmPlatformPkg/PeilessSec/PeilessSec.inf
@@ -52,6 +52,7 @@
SerialPortLib
TimerLib
StackCheckLib
+ ArmTransferListLib
[Ppis]
gArmMpCoreInfoPpiGuid
@@ -59,6 +60,7 @@
[Guids]
gArmMpCoreInfoGuid
gEfiFirmwarePerformanceGuid
+ gArmTransferListHobGuid
[FeaturePcd]
gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob
diff --git a/ArmPlatformPkg/PlatformPei/PlatformPeim.c b/ArmPlatformPkg/PlatformPei/PlatformPeim.c
index 62d1faf..921371a 100644
--- a/ArmPlatformPkg/PlatformPei/PlatformPeim.c
+++ b/ArmPlatformPkg/PlatformPei/PlatformPeim.c
@@ -24,6 +24,7 @@
#include <Library/PeimEntryPoint.h>
#include <Library/PeiServicesLib.h>
#include <Library/PcdLib.h>
+#include <Guid/TransferListHob.h>
EFI_STATUS
EFIAPI
@@ -76,14 +77,30 @@ InitializePlatformPeim (
IN CONST EFI_PEI_SERVICES **PeiServices
)
{
- EFI_STATUS Status;
- EFI_BOOT_MODE BootMode;
+ EFI_STATUS Status;
+ EFI_BOOT_MODE BootMode;
+ VOID *TransferListBase;
+ UINTN *TransferListHobData;
+ EFI_HOB_GUID_TYPE *GuidHob;
DEBUG ((DEBUG_LOAD | DEBUG_INFO, "Platform PEIM Loaded\n"));
Status = PeiServicesSetBootMode (ArmPlatformGetBootMode ());
ASSERT_EFI_ERROR (Status);
+ // If TransferList PPI is present and TransferListHobGuid is not present,
+ // then create a TransferListHob with the TransferListBase address.
+ Status = PeiServicesLocatePpi (&gArmTransferListPpiGuid, 0, NULL, &TransferListBase);
+ if (!EFI_ERROR (Status)) {
+ GuidHob = GetFirstGuidHob (&gArmTransferListHobGuid);
+ if ((GuidHob == NULL) && (TransferListBase != NULL)) {
+ TransferListHobData = BuildGuidHob (&gArmTransferListHobGuid, sizeof (*TransferListHobData));
+ ASSERT (TransferListHobData != NULL);
+
+ *TransferListHobData = (UINTN)TransferListBase;
+ }
+ }
+
PlatformPeim ();
Status = PeiServicesGetBootMode (&BootMode);
diff --git a/ArmPlatformPkg/PlatformPei/PlatformPeim.inf b/ArmPlatformPkg/PlatformPei/PlatformPeim.inf
index f2b0e0f..d9e8f32 100644
--- a/ArmPlatformPkg/PlatformPei/PlatformPeim.inf
+++ b/ArmPlatformPkg/PlatformPei/PlatformPeim.inf
@@ -43,6 +43,7 @@
[Ppis]
gEfiPeiMasterBootModePpiGuid # PPI ALWAYS_PRODUCED
gEfiPeiBootInRecoveryModePpiGuid # PPI SOMETIMES_PRODUCED
+ gArmTransferListPpiGuid # PPI SOMETIMES_CONSUMED
[FixedPcd]
gArmTokenSpaceGuid.PcdFdBaseAddress
@@ -51,6 +52,9 @@
gArmTokenSpaceGuid.PcdFvBaseAddress
gArmTokenSpaceGuid.PcdFvSize
+[Guids]
+ gArmTransferListHobGuid
+
[Depex]
TRUE
diff --git a/ArmPlatformPkg/Sec/AArch64/ModuleEntryPoint.S b/ArmPlatformPkg/Sec/AArch64/ModuleEntryPoint.S
index 154be11..28cd015 100644
--- a/ArmPlatformPkg/Sec/AArch64/ModuleEntryPoint.S
+++ b/ArmPlatformPkg/Sec/AArch64/ModuleEntryPoint.S
@@ -8,6 +8,19 @@
#include <AsmMacroLib.h>
ASM_FUNC(_ModuleEntryPoint)
+ // Check if register assignment at handoff matches spec
+ MOV64 (x4, 0x14a0fb10b)
+ // Check if x1 holds TransferList signature
+ cmp x1, x4
+ b.ne _SkipTransferList
+
+ // Skip TransferList init if x2 is not equal to 0
+ cbnz x2, _SkipTransferList
+
+ // Set the TransferList Base Address from register x3
+ mov x10, x3
+
+_SkipTransferList:
// Do early platform specific actions
bl ASM_PFX(ArmPlatformPeiBootAction)
@@ -47,7 +60,8 @@ ASM_PFX(MainEntryPoint):
// The PEI Core Entry Point has been computed by GenFV and stored in the second entry of the Reset Vector
MOV64 (x2, FixedPcdGet64(PcdFvBaseAddress))
ldr x0, [x2, #8]
-
+ // Pass the TransferList Base Address
+ mov x1, x10
// Move sec startup address into a data register
// Ensure we're jumping to FV version of the code (not boot remapped alias)
ldr x3, =ASM_PFX(CEntryPoint)
diff --git a/ArmPlatformPkg/Sec/Sec.c b/ArmPlatformPkg/Sec/Sec.c
index 4535ae7..ec8bec2 100644
--- a/ArmPlatformPkg/Sec/Sec.c
+++ b/ArmPlatformPkg/Sec/Sec.c
@@ -86,12 +86,14 @@ STATIC CONST EFI_PEI_PPI_DESCRIPTOR gCommonPpiTable[] = {
@param[out] PpiListSize Size of the PPI list in bytes
@param[out] PpiList Pointer to the constructed PPI list
+ @param[in] TransferListBase Pointer to the Transfer List base
**/
STATIC
VOID
CreatePpiList (
OUT UINTN *PpiListSize,
- OUT EFI_PEI_PPI_DESCRIPTOR **PpiList
+ OUT EFI_PEI_PPI_DESCRIPTOR **PpiList,
+ IN VOID *TransferListBase
)
{
EFI_PEI_PPI_DESCRIPTOR *PlatformPpiList;
@@ -111,10 +113,20 @@ CreatePpiList (
// Set the Terminate flag on the last PPI entry
LastPpi = (EFI_PEI_PPI_DESCRIPTOR *)ListBase +
((sizeof (gCommonPpiTable) + PlatformPpiListSize) / sizeof (EFI_PEI_PPI_DESCRIPTOR)) - 1;
+ *PpiListSize = sizeof (gCommonPpiTable) + PlatformPpiListSize;
+
+ // Add the Transfer List PPI after the Common and Platform PPIs
+ if (TransferListBase != NULL) {
+ LastPpi++;
+ LastPpi->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI;
+ LastPpi->Guid = &gArmTransferListPpiGuid;
+ LastPpi->Ppi = TransferListBase;
+ *PpiListSize += sizeof (EFI_PEI_PPI_DESCRIPTOR);
+ }
+
LastPpi->Flags |= EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
- *PpiList = (EFI_PEI_PPI_DESCRIPTOR *)ListBase;
- *PpiListSize = sizeof (gCommonPpiTable) + PlatformPpiListSize;
+ *PpiList = (EFI_PEI_PPI_DESCRIPTOR *)ListBase;
}
/**
@@ -151,12 +163,15 @@ PrintFirmwareVersion (
@param[in] PeiCoreEntryPoint Address in ram of the entrypoint of the PEI
core
+ @param[in] TransferListBaseAddr Address of the Transfer List base address
+
**/
STATIC
VOID
EFIAPI
SecMain (
- IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
+ IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint,
+ IN UINTN TransferListBaseAddr
)
{
EFI_SEC_PEI_HAND_OFF SecCoreData;
@@ -164,8 +179,24 @@ SecMain (
EFI_PEI_PPI_DESCRIPTOR *PpiList;
UINTN TemporaryRamBase;
UINTN TemporaryRamSize;
+ VOID *TransferListBase;
+
+ // Dump the Transfer List
+ TransferListBase = (VOID *)TransferListBaseAddr;
+ if (TransferListBase != NULL) {
+ if (TransferListCheckHeader (TransferListBase) != TRANSFER_LIST_OPS_INVALID) {
+ DEBUG_CODE_BEGIN ();
+ TransferListDump (TransferListBase);
+ DEBUG_CODE_END ();
+ } else {
+ TransferListBase = NULL;
+ DEBUG ((DEBUG_ERROR, "%a: No valid operations possible on TransferList found @ 0x%p\n", __func__, TransferListBase));
+ }
+ } else {
+ DEBUG ((DEBUG_INFO, "%a: No TransferList found, continuing boot\n", __func__));
+ }
- CreatePpiList (&PpiListSize, &PpiList);
+ CreatePpiList (&PpiListSize, &PpiList, TransferListBase);
// Adjust the Temporary Ram as the new Ppi List (Common + Platform Ppi Lists) is created at
// the base of the primary core stack
@@ -197,10 +228,13 @@ SecMain (
@param[in] PeiCoreEntryPoint Address in ram of the entrypoint of the PEI
core
+ @param[in] TransferListBaseAddr Address of the Transfer List base address
+
**/
VOID
CEntryPoint (
- IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
+ IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint,
+ IN UINTN TransferListBaseAddr
)
{
if (!ArmMmuEnabled ()) {
@@ -237,7 +271,7 @@ CEntryPoint (
ArmPlatformInitialize (ArmReadMpidr ());
// Goto primary Main.
- SecMain (PeiCoreEntryPoint);
+ SecMain (PeiCoreEntryPoint, TransferListBaseAddr);
// PEI Core should always load and never return
ASSERT (FALSE);
diff --git a/ArmPlatformPkg/Sec/Sec.h b/ArmPlatformPkg/Sec/Sec.h
index 56d9f35..c1cd10d 100644
--- a/ArmPlatformPkg/Sec/Sec.h
+++ b/ArmPlatformPkg/Sec/Sec.h
@@ -23,6 +23,7 @@
#include <Library/SerialPortLib.h>
#include <Ppi/TemporaryRamSupport.h>
+#include <Library/ArmTransferListLib.h>
/**
Helper function to switch to a different stack. Implemented in assembler as
diff --git a/ArmPlatformPkg/Sec/Sec.inf b/ArmPlatformPkg/Sec/Sec.inf
index a75ce8d..6206707 100644
--- a/ArmPlatformPkg/Sec/Sec.inf
+++ b/ArmPlatformPkg/Sec/Sec.inf
@@ -48,9 +48,11 @@
PrintLib
SerialPortLib
StackCheckLib
+ ArmTransferListLib
[Ppis]
gEfiTemporaryRamSupportPpiGuid
+ gArmTransferListPpiGuid
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString
diff --git a/ArmVirtPkg/ArmVirtCloudHv.dsc b/ArmVirtPkg/ArmVirtCloudHv.dsc
index 541e7c9..94a4ff1 100644
--- a/ArmVirtPkg/ArmVirtCloudHv.dsc
+++ b/ArmVirtPkg/ArmVirtCloudHv.dsc
@@ -61,6 +61,7 @@
TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf
TpmPlatformHierarchyLib|SecurityPkg/Library/PeiDxeTpmPlatformHierarchyLibNull/PeiDxeTpmPlatformHierarchyLib.inf
+ ArmTransferListLib|ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.inf
!include MdePkg/MdeLibs.dsc.inc
diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
index fadd15f..1e239bb 100644
--- a/ArmVirtPkg/ArmVirtQemu.dsc
+++ b/ArmVirtPkg/ArmVirtQemu.dsc
@@ -63,6 +63,7 @@
[LibraryClasses.common]
ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf
ArmMmuLib|UefiCpuPkg/Library/ArmMmuLib/ArmMmuBaseLib.inf
+ ArmTransferListLib|ArmPkg/Library/ArmTransferListLib/ArmTransferListLib.inf
# Virtio Support
VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf
diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template
index 2108948..0caa1c9 100755
--- a/BaseTools/Conf/tools_def.template
+++ b/BaseTools/Conf/tools_def.template
@@ -929,18 +929,15 @@ DEFINE GCC_AARCH64_CC_FLAGS = DEF(GCC_ALL_CC_FLAGS) -mlittle-endian -fno-
DEFINE GCC_AARCH64_CC_XIPFLAGS = -mstrict-align -mgeneral-regs-only
DEFINE GCC_RISCV64_CC_XIPFLAGS = -mstrict-align -mgeneral-regs-only
DEFINE GCC_DLINK2_FLAGS_COMMON = -Wl,--script=$(EDK_TOOLS_PATH)/Scripts/GccBase.lds
-DEFINE GCC_IA32_X64_DLINK_COMMON = -nostdlib --pie --fatal-warnings -z,noexecstack --gc-sections
-DEFINE GCC_ARM_AARCH64_DLINK_COMMON= -Wl,--emit-relocs -nostdlib -Wl,--gc-sections -u $(IMAGE_ENTRY_POINT) -Wl,-e,$(IMAGE_ENTRY_POINT),-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map -Wl,--fatal-warnings -Wl,-z,noexecstack
+DEFINE GCC_ARM_AARCH64_DLINK_COMMON= -Wl,--emit-relocs -nostdlib -Wl,--gc-sections -u $(IMAGE_ENTRY_POINT) -Wl,-e,$(IMAGE_ENTRY_POINT),-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map
DEFINE GCC_LOONGARCH64_DLINK_COMMON= -Wl,--emit-relocs -nostdlib -Wl,--gc-sections -u $(IMAGE_ENTRY_POINT) -Wl,-e,$(IMAGE_ENTRY_POINT),-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map
DEFINE GCC_ARM_DLINK_FLAGS = DEF(GCC_ARM_AARCH64_DLINK_COMMON) -z common-page-size=0x20 -Wl,--pic-veneer
DEFINE GCC_AARCH64_DLINK_FLAGS = DEF(GCC_ARM_AARCH64_DLINK_COMMON) -z common-page-size=0x20
DEFINE GCC_LOONGARCH64_DLINK_FLAGS = DEF(GCC_LOONGARCH64_DLINK_COMMON) -z common-page-size=0x20
DEFINE GCC_ARM_AARCH64_ASLDLINK_FLAGS = -Wl,--defsym=PECOFF_HEADER_SIZE=0 DEF(GCC_DLINK2_FLAGS_COMMON) -z common-page-size=0x20
-DEFINE GCC_IA32_X64_ASLDLINK_FLAGS = DEF(GCC_IA32_X64_DLINK_COMMON) --entry _ReferenceAcpiTable -u $(IMAGE_ENTRY_POINT)
DEFINE GCC_ARM_ASLDLINK_FLAGS = DEF(GCC_ARM_DLINK_FLAGS) -Wl,--entry,ReferenceAcpiTable -u $(IMAGE_ENTRY_POINT) DEF(GCC_ARM_AARCH64_ASLDLINK_FLAGS)
DEFINE GCC_AARCH64_ASLDLINK_FLAGS = DEF(GCC_AARCH64_DLINK_FLAGS) -Wl,--entry,ReferenceAcpiTable -u $(IMAGE_ENTRY_POINT) DEF(GCC_ARM_AARCH64_ASLDLINK_FLAGS)
DEFINE GCC_LOONGARCH64_ASLDLINK_FLAGS = DEF(GCC_LOONGARCH64_DLINK_FLAGS) -Wl,--entry,ReferenceAcpiTable -u $(IMAGE_ENTRY_POINT)
-DEFINE GCC_IA32_X64_DLINK_FLAGS = DEF(GCC_IA32_X64_DLINK_COMMON) --entry _$(IMAGE_ENTRY_POINT) --file-alignment 0x20 --section-alignment 0x20 -Map $(DEST_DIR_DEBUG)/$(BASE_NAME).map
DEFINE GCC_ASM_FLAGS = -c -x assembler -imacros AutoGen.h
DEFINE GCC_PP_FLAGS = -E -x assembler-with-cpp -include AutoGen.h
DEFINE GCC_VFRPP_FLAGS = -x c -E -DVFRCOMPILE --include $(MODULE_NAME)StrDefs.h
@@ -1006,13 +1003,13 @@ DEFINE GCC49_ARM_ASLDLINK_FLAGS = DEF(GCC48_ARM_ASLDLINK_FLAGS)
DEFINE GCC49_AARCH64_ASLDLINK_FLAGS = DEF(GCC48_AARCH64_ASLDLINK_FLAGS)
DEFINE GCC49_ASLCC_FLAGS = DEF(GCC48_ASLCC_FLAGS)
+DEFINE GCC5_DLINK_WARNING_FLAGS = -Wl,--fatal-warnings -Wl,-z,noexecstack -Wl,-z,notext
DEFINE GCC5_IA32_CC_FLAGS = DEF(GCC49_IA32_CC_FLAGS)
DEFINE GCC5_X64_CC_FLAGS = DEF(GCC49_X64_CC_FLAGS)
-DEFINE GCC5_IA32_X64_DLINK_COMMON = DEF(GCC49_IA32_X64_DLINK_COMMON)
-DEFINE GCC5_IA32_X64_ASLDLINK_FLAGS = DEF(GCC49_IA32_X64_ASLDLINK_FLAGS)
-DEFINE GCC5_IA32_X64_DLINK_FLAGS = DEF(GCC49_IA32_X64_DLINK_FLAGS)
+DEFINE GCC5_IA32_X64_ASLDLINK_FLAGS = DEF(GCC49_IA32_X64_ASLDLINK_FLAGS) DEF(GCC5_DLINK_WARNING_FLAGS)
+DEFINE GCC5_IA32_X64_DLINK_FLAGS = DEF(GCC49_IA32_X64_DLINK_FLAGS) DEF(GCC5_DLINK_WARNING_FLAGS)
DEFINE GCC5_IA32_DLINK2_FLAGS = DEF(GCC49_IA32_DLINK2_FLAGS) -Wno-error
-DEFINE GCC5_X64_DLINK_FLAGS = DEF(GCC49_X64_DLINK_FLAGS)
+DEFINE GCC5_X64_DLINK_FLAGS = DEF(GCC49_X64_DLINK_FLAGS) DEF(GCC5_DLINK_WARNING_FLAGS)
DEFINE GCC5_X64_DLINK2_FLAGS = DEF(GCC49_X64_DLINK2_FLAGS) -Wno-error
DEFINE GCC5_ASM_FLAGS = DEF(GCC49_ASM_FLAGS)
DEFINE GCC5_ARM_ASM_FLAGS = DEF(GCC49_ARM_ASM_FLAGS)
@@ -1021,16 +1018,16 @@ DEFINE GCC5_ARM_CC_FLAGS = DEF(GCC49_ARM_CC_FLAGS)
DEFINE GCC5_ARM_CC_XIPFLAGS = DEF(GCC49_ARM_CC_XIPFLAGS)
DEFINE GCC5_AARCH64_CC_FLAGS = DEF(GCC49_AARCH64_CC_FLAGS)
DEFINE GCC5_AARCH64_CC_XIPFLAGS = DEF(GCC49_AARCH64_CC_XIPFLAGS)
-DEFINE GCC5_ARM_DLINK_FLAGS = DEF(GCC49_ARM_DLINK_FLAGS)
+DEFINE GCC5_ARM_DLINK_FLAGS = DEF(GCC49_ARM_DLINK_FLAGS) DEF(GCC5_DLINK_WARNING_FLAGS)
DEFINE GCC5_ARM_DLINK2_FLAGS = DEF(GCC49_ARM_DLINK2_FLAGS) -Wno-error
-DEFINE GCC5_AARCH64_DLINK_FLAGS = DEF(GCC49_AARCH64_DLINK_FLAGS)
+DEFINE GCC5_AARCH64_DLINK_FLAGS = DEF(GCC49_AARCH64_DLINK_FLAGS) DEF(GCC5_DLINK_WARNING_FLAGS)
DEFINE GCC5_AARCH64_DLINK2_FLAGS = DEF(GCC49_AARCH64_DLINK2_FLAGS) -Wno-error
-DEFINE GCC5_ARM_ASLDLINK_FLAGS = DEF(GCC49_ARM_ASLDLINK_FLAGS)
-DEFINE GCC5_AARCH64_ASLDLINK_FLAGS = DEF(GCC49_AARCH64_ASLDLINK_FLAGS)
+DEFINE GCC5_ARM_ASLDLINK_FLAGS = DEF(GCC49_ARM_ASLDLINK_FLAGS) DEF(GCC5_DLINK_WARNING_FLAGS)
+DEFINE GCC5_AARCH64_ASLDLINK_FLAGS = DEF(GCC49_AARCH64_ASLDLINK_FLAGS) DEF(GCC5_DLINK_WARNING_FLAGS)
DEFINE GCC5_ASLCC_FLAGS = DEF(GCC49_ASLCC_FLAGS) -fno-lto
-DEFINE GCC5_RISCV_ALL_CC_FLAGS = -g -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -ffunction-sections -fdata-sections -include AutoGen.h -fno-common -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings -msmall-data-limit=0
-DEFINE GCC5_RISCV_ALL_DLINK_COMMON = -nostdlib -Wl,-n,-q,--gc-sections -z common-page-size=0x40
+DEFINE GCC5_RISCV_ALL_CC_FLAGS = -g -fshort-wchar -fno-omit-frame-pointer -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -ffunction-sections -fdata-sections -include AutoGen.h -fno-common -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings -msmall-data-limit=0
+DEFINE GCC5_RISCV_ALL_DLINK_COMMON = -nostdlib -Wl,-n,-q,--gc-sections -z common-page-size=0x40 DEF(GCC5_DLINK_WARNING_FLAGS)
DEFINE GCC5_RISCV_ALL_DLINK_FLAGS = DEF(GCC5_RISCV_ALL_DLINK_COMMON) -Wl,--entry,$(IMAGE_ENTRY_POINT) -u $(IMAGE_ENTRY_POINT) -Wl,-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map
DEFINE GCC5_RISCV_ALL_DLINK2_FLAGS = -Wl,--defsym=PECOFF_HEADER_SIZE=0x220,--script=$(EDK_TOOLS_PATH)/Scripts/GccBase.lds
DEFINE GCC5_RISCV_ALL_ASM_FLAGS = -c -x assembler -imacros $(DEST_DIR_DEBUG)/AutoGen.h
@@ -1046,9 +1043,9 @@ DEFINE GCC5_RISCV64_DLINK2_FLAGS = DEF(GCC5_RISCV_ALL_DLINK2_FLAGS)
DEFINE GCC5_RISCV64_ASM_FLAGS = DEF(GCC5_RISCV_ALL_ASM_FLAGS) -march=DEF(GCC5_RISCV64_ARCH) -mcmodel=medany -mabi=lp64
DEFINE GCC5_LOONGARCH64_CC_FLAGS = DEF(GCC_LOONGARCH64_CC_FLAGS) -march=loongarch64 -mno-memcpy -Werror -Wno-maybe-uninitialized -Wno-stringop-overflow -Wno-pointer-to-int-cast -no-pie -fno-stack-protector -mno-explicit-relocs
-DEFINE GCC5_LOONGARCH64_DLINK_FLAGS = DEF(GCC_LOONGARCH64_DLINK_FLAGS)
+DEFINE GCC5_LOONGARCH64_DLINK_FLAGS = DEF(GCC_LOONGARCH64_DLINK_FLAGS) DEF(GCC5_DLINK_WARNING_FLAGS)
DEFINE GCC5_LOONGARCH64_DLINK2_FLAGS = DEF(GCC_DLINK2_FLAGS_COMMON) -Wl,--defsym=PECOFF_HEADER_SIZE=0x228
-DEFINE GCC5_LOONGARCH64_ASLDLINK_FLAGS = DEF(GCC_LOONGARCH64_ASLDLINK_FLAGS) DEF(GCC5_LOONGARCH64_DLINK2_FLAGS)
+DEFINE GCC5_LOONGARCH64_ASLDLINK_FLAGS = DEF(GCC_LOONGARCH64_ASLDLINK_FLAGS) DEF(GCC5_LOONGARCH64_DLINK2_FLAGS) DEF(GCC5_DLINK_WARNING_FLAGS)
DEFINE GCC5_LOONGARCH64_ASM_FLAGS = -x assembler-with-cpp -mabi=lp64d -march=loongarch64 -fno-builtin -c -Wall -mno-explicit-relocs
DEFINE GCC5_LOONGARCH64_PP_FLAGS = -mabi=lp64d -march=loongarch64 DEF(GCC_PP_FLAGS)
@@ -2031,10 +2028,11 @@ DEFINE CLANGDWARF_X64_PREFIX = ENV(CLANG_BIN)
# LLVM/CLANG doesn't support -n link option. So, it can't share the same IA32_X64_DLINK_COMMON flag.
# LLVM/CLANG doesn't support common page size. So, it can't share the same GccBase.lds script.
-DEFINE CLANGDWARF_IA32_X64_DLINK_COMMON = -nostdlib -Wl,-q,--gc-sections -z common-page-size=0x40
+DEFINE CLANGDWARF_DLINK_WARNING_FLAGS = -Wl,-z,notext
+DEFINE CLANGDWARF_IA32_X64_DLINK_COMMON = -nostdlib -Wl,-q,--gc-sections -z common-page-size=0x40 DEF(CLANGDWARF_DLINK_WARNING_FLAGS)
DEFINE CLANGDWARF_DLINK2_FLAGS_COMMON = -Wl,--script=$(EDK_TOOLS_PATH)/Scripts/GccBase.lds
DEFINE CLANGDWARF_IA32_X64_ASLDLINK_FLAGS = DEF(CLANGDWARF_IA32_X64_DLINK_COMMON) -Wl,--defsym=PECOFF_HEADER_SIZE=0 DEF(CLANGDWARF_DLINK2_FLAGS_COMMON) -Wl,--entry,ReferenceAcpiTable -u ReferenceAcpiTable
-DEFINE CLANGDWARF_IA32_X64_DLINK_FLAGS = DEF(CLANGDWARF_IA32_X64_DLINK_COMMON) -Wl,--entry,$(IMAGE_ENTRY_POINT) -u $(IMAGE_ENTRY_POINT) -Wl,-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map,--whole-archive -Wl,-z,notext
+DEFINE CLANGDWARF_IA32_X64_DLINK_FLAGS = DEF(CLANGDWARF_IA32_X64_DLINK_COMMON) -Wl,--entry,$(IMAGE_ENTRY_POINT) -u $(IMAGE_ENTRY_POINT) -Wl,-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map,--whole-archive
DEFINE CLANGDWARF_IA32_DLINK2_FLAGS = -Wl,--defsym=PECOFF_HEADER_SIZE=0x220 DEF(CLANGDWARF_DLINK2_FLAGS_COMMON)
DEFINE CLANGDWARF_X64_DLINK2_FLAGS = -Wl,--defsym=PECOFF_HEADER_SIZE=0x228 DEF(CLANGDWARF_DLINK2_FLAGS_COMMON)
@@ -2121,7 +2119,7 @@ NOOPT_CLANGDWARF_X64_DLINK2_FLAGS = DEF(CLANGDWARF_X64_DLINK2_FLAGS) -O0 -fu
##################
DEFINE CLANGDWARF_ARM_TARGET = -target arm-linux-gnueabi
DEFINE CLANGDWARF_ARM_CC_FLAGS = DEF(GCC_ARM_CC_FLAGS) DEF(CLANGDWARF_ARM_TARGET) DEF(CLANGDWARF_WARNING_OVERRIDES) -mno-movt -fno-stack-protector
-DEFINE CLANGDWARF_ARM_DLINK_FLAGS = DEF(CLANGDWARF_ARM_TARGET) DEF(GCC_ARM_DLINK_FLAGS)
+DEFINE CLANGDWARF_ARM_DLINK_FLAGS = DEF(CLANGDWARF_ARM_TARGET) DEF(GCC_ARM_DLINK_FLAGS) DEF(CLANGDWARF_DLINK_WARNING_FLAGS)
*_CLANGDWARF_ARM_PP_FLAGS = DEF(GCC_PP_FLAGS)
*_CLANGDWARF_ARM_ASLCC_FLAGS = DEF(GCC_ASLCC_FLAGS)
@@ -2165,7 +2163,7 @@ RELEASE_CLANGDWARF_ARM_DLINK_FLAGS = DEF(CLANGDWARF_ARM_DLINK_FLAGS) -flto -Wl,
##################
DEFINE CLANGDWARF_AARCH64_TARGET = -target aarch64-linux-gnu
DEFINE CLANGDWARF_AARCH64_CC_FLAGS = DEF(GCC_AARCH64_CC_FLAGS) DEF(CLANGDWARF_AARCH64_TARGET) -mcmodel=small DEF(CLANGDWARF_WARNING_OVERRIDES)
-DEFINE CLANGDWARF_AARCH64_DLINK_FLAGS = DEF(CLANGDWARF_AARCH64_TARGET) DEF(GCC_AARCH64_DLINK_FLAGS) -z common-page-size=0x1000
+DEFINE CLANGDWARF_AARCH64_DLINK_FLAGS = DEF(CLANGDWARF_AARCH64_TARGET) DEF(GCC_AARCH64_DLINK_FLAGS) -z common-page-size=0x1000 DEF(CLANGDWARF_DLINK_WARNING_FLAGS)
*_CLANGDWARF_AARCH64_PP_FLAGS = DEF(GCC_PP_FLAGS)
*_CLANGDWARF_AARCH64_ASLCC_FLAGS = DEF(GCC_ASLCC_FLAGS)
@@ -2187,9 +2185,9 @@ DEFINE CLANGDWARF_AARCH64_DLINK_FLAGS = DEF(CLANGDWARF_AARCH64_TARGET) DEF(GCC_
*_CLANGDWARF_AARCH64_RC_PATH = ENV(CLANGDWARF_BIN)llvm-objcopy
*_CLANGDWARF_AARCH64_ASLCC_FLAGS = DEF(GCC_ASLCC_FLAGS) -fno-lto
-*_CLANGDWARF_AARCH64_ASLDLINK_FLAGS = DEF(CLANGDWARF_AARCH64_TARGET) DEF(GCC_AARCH64_ASLDLINK_FLAGS)
+*_CLANGDWARF_AARCH64_ASLDLINK_FLAGS = DEF(CLANGDWARF_AARCH64_TARGET) DEF(GCC_AARCH64_ASLDLINK_FLAGS) DEF(CLANGDWARF_DLINK_WARNING_FLAGS)
*_CLANGDWARF_AARCH64_ASM_FLAGS = DEF(GCC_ASM_FLAGS) DEF(CLANGDWARF_AARCH64_TARGET) $(PLATFORM_FLAGS) -Qunused-arguments
-*_CLANGDWARF_AARCH64_DLINK_FLAGS = DEF(CLANGDWARF_AARCH64_TARGET) DEF(GCC_AARCH64_DLINK_FLAGS) -z common-page-size=0x1000
+*_CLANGDWARF_AARCH64_DLINK_FLAGS = DEF(CLANGDWARF_AARCH64_TARGET) DEF(GCC_AARCH64_DLINK_FLAGS) -z common-page-size=0x1000 DEF(CLANGDWARF_DLINK_WARNING_FLAGS)
*_CLANGDWARF_AARCH64_DLINK_XIPFLAGS = -z common-page-size=0x20
*_CLANGDWARF_AARCH64_DLINK2_FLAGS = DEF(GCC_DLINK2_FLAGS_COMMON) -Wl,--defsym=PECOFF_HEADER_SIZE=0x228
*_CLANGDWARF_AARCH64_PLATFORM_FLAGS =
@@ -2214,7 +2212,7 @@ DEFINE CLANGDWARF_RISCV64_CC_COMMON = DEF(GCC5_RISCV_ALL_CC_FLAGS) DEF(GCC5_RISC
DEFINE CLANGDWARF_RISCV64_CC_FLAGS = DEF(CLANGDWARF_RISCV64_CC_COMMON) DEF(CLANGDWARF_RISCV64_TARGET) DEF(CLANGDWARF_WARNING_OVERRIDES)
# This is similar to GCC flags but without -n
-DEFINE CLANGDWARF_RISCV64_ALL_DLINK_COMMON = -nostdlib -Wl,-q,--gc-sections -z common-page-size=0x40
+DEFINE CLANGDWARF_RISCV64_ALL_DLINK_COMMON = -nostdlib -Wl,-q,--gc-sections -z common-page-size=0x40 DEF(CLANGDWARF_DLINK_WARNING_FLAGS)
DEFINE CLANGDWARF_RISCV64_ALL_DLINK_FLAGS = DEF(CLANGDWARF_RISCV64_ALL_DLINK_COMMON) -Wl,--entry,$(IMAGE_ENTRY_POINT) -u $(IMAGE_ENTRY_POINT) -Wl,-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map
DEFINE CLANGDWARF_RISCV64_DLINK_FLAGS = DEF(CLANGDWARF_RISCV64_TARGET) DEF(CLANGDWARF_RISCV64_ALL_DLINK_FLAGS) -Wl,-melf64lriscv,--oformat=elf64-littleriscv,--no-relax
@@ -2239,9 +2237,9 @@ DEFINE CLANGDWARF_RISCV64_DLINK_FLAGS = DEF(CLANGDWARF_RISCV64_TARGET) DEF
*_CLANGDWARF_RISCV64_RC_PATH = ENV(CLANGDWARF_BIN)llvm-objcopy
*_CLANGDWARF_RISCV64_ASLCC_FLAGS = DEF(GCC_ASLCC_FLAGS) -fno-lto
-*_CLANGDWARF_RISCV64_ASLDLINK_FLAGS = DEF(CLANGDWARF_RISCV64_TARGET) DEF(GCC5_RISCV32_RISCV64_ASLDLINK_FLAGS)
+*_CLANGDWARF_RISCV64_ASLDLINK_FLAGS = DEF(CLANGDWARF_RISCV64_TARGET) DEF(GCC5_RISCV32_RISCV64_ASLDLINK_FLAGS) DEF(CLANGDWARF_DLINK_WARNING_FLAGS)
*_CLANGDWARF_RISCV64_ASM_FLAGS = DEF(GCC_ASM_FLAGS) DEF(CLANGDWARF_RISCV64_TARGET) $(PLATFORM_FLAGS) -Qunused-arguments -mabi=lp64 -mno-relax
-*_CLANGDWARF_RISCV64_DLINK_FLAGS = DEF(CLANGDWARF_RISCV64_TARGET) DEF(GCC5_RISCV64_DLINK_FLAGS)
+*_CLANGDWARF_RISCV64_DLINK_FLAGS = DEF(CLANGDWARF_RISCV64_TARGET) DEF(GCC5_RISCV64_DLINK_FLAGS) DEF(CLANGDWARF_DLINK_WARNING_FLAGS)
*_CLANGDWARF_RISCV64_DLINK_XIPFLAGS = -z common-page-size=0x20
*_CLANGDWARF_RISCV64_DLINK2_FLAGS = DEF(CLANGDWARF_DLINK2_FLAGS_COMMON) -Wl,--defsym=PECOFF_HEADER_SIZE=0x240
*_CLANGDWARF_RISCV64_PLATFORM_FLAGS =
diff --git a/BaseTools/Source/Python/FMMT/core/FvHandler.py b/BaseTools/Source/Python/FMMT/core/FvHandler.py
index 6d6a9c2..12d52c1 100644
--- a/BaseTools/Source/Python/FMMT/core/FvHandler.py
+++ b/BaseTools/Source/Python/FMMT/core/FvHandler.py
@@ -237,11 +237,20 @@ class FvHandler:
Size_delta = len(CompressedData) - len(TargetTree.Data.OriData)
ChangeSize(TargetTree, -Size_delta)
if TargetTree.NextRel:
+ Original_Pad_Size = len(TargetTree.Data.PadData)
TargetTree.Data.PadData = b'\x00' * New_Pad_Size
- self.Remain_New_Free_Space = len(TargetTree.Data.OriData) + len(TargetTree.Data.PadData) - len(CompressedData) - New_Pad_Size
+ self.Remain_New_Free_Space = (
+ len(TargetTree.Data.OriData) +
+ Original_Pad_Size -
+ len(CompressedData) -
+ New_Pad_Size
+ )
else:
TargetTree.Data.PadData = b''
- self.Remain_New_Free_Space = len(TargetTree.Data.OriData) - len(CompressedData)
+ self.Remain_New_Free_Space = (
+ len(TargetTree.Data.OriData) -
+ len(CompressedData)
+ )
TargetTree.Data.OriData = CompressedData
elif len(CompressedData) == len(TargetTree.Data.OriData):
TargetTree.Data.OriData = CompressedData
@@ -347,15 +356,24 @@ class FvHandler:
ModifySectionType(ParTree)
Needed_Space += ParTree.Data.HeaderLength - OriHeaderLen
# Update needed space with Delta_Pad_Size
+ Original_Pad_Size = len(ParTree.Data.PadData)
if ParTree.NextRel:
New_Pad_Size = GetPadSize(ParTree.Data.Size, SECTION_COMMON_ALIGNMENT)
- Delta_Pad_Size = New_Pad_Size - len(ParTree.Data.PadData)
+ Delta_Pad_Size = New_Pad_Size - Original_Pad_Size
ParTree.Data.PadData = b'\x00' * New_Pad_Size
Needed_Space += Delta_Pad_Size
else:
ParTree.Data.PadData = b''
if Needed_Space < 0:
- self.Remain_New_Free_Space = len(ParTree.Data.OriData) - len(CompressedData)
+ if ParTree.NextRel:
+ self.Remain_New_Free_Space = (
+ len(ParTree.Data.OriData) + Original_Pad_Size -
+ len(CompressedData) - New_Pad_Size
+ )
+ else:
+ self.Remain_New_Free_Space = (
+ len(ParTree.Data.OriData) - len(CompressedData)
+ )
# If current section is not guided section
elif Needed_Space:
ChangeSize(ParTree, -Needed_Space)
diff --git a/DynamicTablesPkg/DynamicTables.dsc.inc b/DynamicTablesPkg/DynamicTables.dsc.inc
index 371efe9..d8c92de 100644
--- a/DynamicTablesPkg/DynamicTables.dsc.inc
+++ b/DynamicTablesPkg/DynamicTables.dsc.inc
@@ -25,6 +25,7 @@
SmbiosStringTableLib|DynamicTablesPkg/Library/Common/SmbiosStringTableLib/SmbiosStringTableLib.inf
MetadataObjLib|DynamicTablesPkg/Library/Common/MetadataObjLib/MetadataObjLib.inf
MetadataHandlerLib|DynamicTablesPkg/Library/Common/MetadataHandlerLib/MetadataHandlerLib.inf
+ Tpm2DeviceTableLib|DynamicTablesPkg/Library/Common/Tpm2DeviceTableLib/Tpm2DeviceTableLib.inf
[LibraryClasses.AARCH64]
DynamicTablesScmiInfoLib|DynamicTablesPkg/Library/DynamicTablesScmiInfoLib/DynamicTablesScmiInfoLib.inf
@@ -67,6 +68,7 @@
DynamicTablesPkg/Library/Acpi/X64/AcpiMadtLib/AcpiMadtLib.inf
DynamicTablesPkg/Library/Acpi/X64/AcpiSsdtHpetLib/AcpiSsdtHpetLib.inf
DynamicTablesPkg/Library/Acpi/X64/AcpiWsmtLib/AcpiWsmtLib.inf
+ DynamicTablesPkg/Library/Acpi/X64/SsdtSerialPortFixupLib/SsdtSerialPortFixupLib.inf
#
# Dynamic Table Factory Dxe
diff --git a/DynamicTablesPkg/DynamicTablesPkg.ci.yaml b/DynamicTablesPkg/DynamicTablesPkg.ci.yaml
index 5c4efb4..56069e2 100644
--- a/DynamicTablesPkg/DynamicTablesPkg.ci.yaml
+++ b/DynamicTablesPkg/DynamicTablesPkg.ci.yaml
@@ -54,7 +54,8 @@
"EmbeddedPkg/EmbeddedPkg.dec",
"DynamicTablesPkg/DynamicTablesPkg.dec",
"MdeModulePkg/MdeModulePkg.dec",
- "MdePkg/MdePkg.dec"
+ "MdePkg/MdePkg.dec",
+ "SecurityPkg/SecurityPkg.dec"
],
# For host based unit tests
"AcceptableDependencies-HOST_APPLICATION":[
diff --git a/DynamicTablesPkg/DynamicTablesPkg.dec b/DynamicTablesPkg/DynamicTablesPkg.dec
index 87934c5..71e76e6 100644
--- a/DynamicTablesPkg/DynamicTablesPkg.dec
+++ b/DynamicTablesPkg/DynamicTablesPkg.dec
@@ -52,6 +52,9 @@
## @libraryclass Defines a set of APIs to a handle Metadata generation/validation.
MetadataHandlerLib|Include/Library/MetadataHandlerLib.h
+ ## @libraryclass Defines a set of methods for generating Tpm2 Device Table method.
+ Tpm2DeviceTableLib|Include/Library/Tpm2DeviceTableLib.h
+
[LibraryClasses.AARCH64]
## @libraryclass Defines a set of APIs to populate CmObj using SCMI.
DynamicTablesScmiInfoLib|Include/Library/DynamicTablesScmiInfoLib.h
@@ -84,5 +87,8 @@
# BIT0: Allow the absence of some registers in the _CPC object.
gEdkiiDynamicTablesPkgTokenSpaceGuid.PcdDevelopmentPlatformRelaxations|0|UINT64|0x4000000A
+ # Generate Tpm2 device table when generate TPM2 acpi table together.
+ gEdkiiDynamicTablesPkgTokenSpaceGuid.PcdGenTpm2DeviceTable|FALSE|BOOLEAN|0x4000000B
+
[Guids]
gEdkiiDynamicTablesPkgTokenSpaceGuid = { 0xab226e66, 0x31d8, 0x4613, { 0x87, 0x9d, 0xd2, 0xfa, 0xb6, 0x10, 0x26, 0x3c } }
diff --git a/DynamicTablesPkg/DynamicTablesPkg.dsc b/DynamicTablesPkg/DynamicTablesPkg.dsc
index 823b3fe..d8c0477 100644
--- a/DynamicTablesPkg/DynamicTablesPkg.dsc
+++ b/DynamicTablesPkg/DynamicTablesPkg.dsc
@@ -51,6 +51,7 @@
DynamicTablesPkg/Library/Common/SmbiosStringTableLib/SmbiosStringTableLib.inf
DynamicTablesPkg/Library/Common/MetadataObjLib/MetadataObjLib.inf
DynamicTablesPkg/Library/Common/MetadataHandlerLib/MetadataHandlerLib.inf
+ DynamicTablesPkg/Library/Common/Tpm2DeviceTableLib/Tpm2DeviceTableLib.inf
[Components.ARM, Components.AARCH64]
DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParserLib.inf
diff --git a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h
index a642aec..33e976c 100644
--- a/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h
+++ b/DynamicTablesPkg/Include/ArchCommonNameSpaceObjects.h
@@ -71,6 +71,7 @@ typedef enum ArchCommonObjectID {
EArchCommonObjMemoryLatBwInfo, ///< 43 - Memory Latency Bandwidth Info
EArchCommonObjMemoryCacheInfo, ///< 44 - Memory Cache Info
EArchCommonObjSpcrInfo, ///< 45 - Serial Terminal and Interrupt Info
+ EArchCommonObjTpm2DeviceInfo, ///< 46 - TPM2 Device Info
EArchCommonObjMax
} EARCH_COMMON_OBJECT_ID;
@@ -724,6 +725,18 @@ typedef struct CmArchCommonTpm2InterfaceInfo {
UINT64 Lasa;
} CM_ARCH_COMMON_TPM2_INTERFACE_INFO;
+/** A structure that describes TPM2 device.
+
+ ID: EArchCommonObjTpm2DeviceInfo
+*/
+typedef struct CmArchCommonTpm2DeviceInfo {
+ /** TPM2 Device's Base Address */
+ UINT64 Tpm2DeviceBaseAddress;
+
+ /** TPM2 Device' Size */
+ UINT64 Tpm2DeviceSize;
+} CM_ARCH_COMMON_TPM2_DEVICE_INFO;
+
/** A structure that describes the
SPMI (Service Processor Management Interface) Info.
diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h
index 9e294ac..a966148 100644
--- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h
+++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h
@@ -2107,4 +2107,121 @@ AmlCreatePssNode (
OUT AML_OBJECT_NODE_HANDLE *NewPssNode OPTIONAL
);
+/** Code generation for the IRQ Descriptor.
+
+ The Resource Data effectively created is an IRQ Resource
+ Data. Cf ACPI 6.5 specification:
+ - s6.4.2.1 "IRQ Descriptor"
+ - s19.6.66 "IRQ (Interrupt Resource Descriptor Macro)"
+
+
+ The created resource data node can be:
+ - appended to the list of resource data elements of the NameOpNode.
+ In such case NameOpNode must be defined by a the "Name ()" ASL statement
+ and initially contain a "ResourceTemplate ()".
+ - returned through the NewRdNode parameter.
+
+ @param [in] IsEdgeTriggered The interrupt is edge triggered or
+ level triggered.
+ @param [in] IsActiveLow The interrupt is active-high or active-low.
+ @param [in] IsShared The interrupt can be shared with other
+ devices or not (Exclusive).
+ @param [in] IrqList List of IRQ numbers. Must be non-NULL.
+ @param [in] IrqCount Number of IRQs in IrqList. Must be > 0 and <= 16.
+ @param [in] NameOpNode NameOp object node defining a named object.
+ If provided, append the new resource data node
+ to the list of resource data elements of this node.
+ @param [out] NewRdNode If provided and success, contain the created node.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval various Other errors as indicated.
+**/
+EFI_STATUS
+EFIAPI
+AmlCodeGenRdIrq (
+ IN BOOLEAN IsEdgeTriggered,
+ IN BOOLEAN IsActiveLow,
+ IN BOOLEAN IsShared,
+ IN UINT8 *IrqList,
+ IN UINT8 IrqCount,
+ IN AML_OBJECT_NODE_HANDLE NameOpNode OPTIONAL,
+ OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL
+ );
+
+/** Code generation for the UARTSerialBusV2() ASL macro.
+
+ The Resource Data effectively created is a UART Serial Bus Connection
+ Resource Descriptor Resource Data.
+ Cf ACPI 6.5:
+ - s19.6.143 UARTSerialBusV2
+ (UART Serial Bus Connection Resource Descriptor Version 2 Macro)
+ - s6.4.3.8.2.3 UART Serial Bus Connection Resource Descriptor
+
+ The created resource data node can be:
+ - appended to the list of resource data elements of the NameOpNode.
+ In such case NameOpNode must be defined by a the "Name ()" ASL statement
+ and initially contain a "ResourceTemplate ()".
+ - returned through the NewRdNode parameter.
+
+ @param [in] InitialBaudRate Initial baud rate.
+ @param [in] BitsPerByte Number of bits per byte.
+ Optional, default is 8.
+ @param [in] StopBits Number of stop bits.
+ Optional, default is 1.
+ @param [in] LinesInUse Number of lines in use.
+ @param [in] IsBigEndian Indicates whether the bit transfer is big-endian.
+ Optional, default is FALSE (little-endian).
+ @param [in] Parity Parity format used.
+ Optional, default is no parity.
+ @param [in] FlowControl Flow control protocol used.
+ Optional, default is no flow control.
+ @param [in] ReceiveBufferSize Size of the receive buffer.
+ @param [in] TransmitBufferSize Size of the transmit buffer.
+ @param [in] ResourceSource Name of source resource used.
+ @param [in] ResourceSourceLength Length of the Resource Source.
+ @param [in] ResourceSourceIndex Resource Source index.
+ Optional, default is 0.
+ @param [in] ResourceUsage Resource usage, TRUE for consumer,
+ FALSE for producer.
+ Optional, default is TRUE (consumer).
+ @param [in] IsShared Indicates whether the resource is shared.
+ Optional, default is FALSE (exclusive).
+ @param [in] VendorDefinedData Vendor defined data.
+ Optional, can be NULL.
+ @param [in] VendorDefinedDataLength Length of the vendor defined data.
+ @param [in] NameOpNode NameOp object node defining a named object.
+ If provided, append the new resource data
+ node to the list of resource data elements
+ of this node.
+ @param [out] NewRdNode If provided and success,
+ contain the created node.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval various Various failure values of called functions.
+**/
+EFI_STATUS
+EFIAPI
+AmlCodeGenRdUartSerialBusV2 (
+ IN UINT32 InitialBaudRate,
+ IN UINT8 *BitsPerByte OPTIONAL,
+ IN UINT8 *StopBits OPTIONAL,
+ IN UINT8 LinesInUse,
+ IN BOOLEAN *IsBigEndian OPTIONAL,
+ IN UINT8 *Parity OPTIONAL,
+ IN UINT8 *FlowControl OPTIONAL,
+ IN UINT16 ReceiveBufferSize,
+ IN UINT16 TransmitBufferSize,
+ IN CHAR8 *ResourceSource,
+ IN UINT16 ResourceSourceLength,
+ IN UINT8 *ResourceSourceIndex OPTIONAL,
+ IN BOOLEAN *ResourceUsage OPTIONAL,
+ IN BOOLEAN *IsShared OPTIONAL,
+ IN UINT8 *VendorDefinedData OPTIONAL,
+ IN UINT16 VendorDefinedDataLength,
+ IN AML_OBJECT_NODE_HANDLE NameOpNode OPTIONAL,
+ OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL
+ );
+
#endif // AML_LIB_H_
diff --git a/DynamicTablesPkg/Include/Library/Tpm2DeviceTableLib.h b/DynamicTablesPkg/Include/Library/Tpm2DeviceTableLib.h
new file mode 100644
index 0000000..5da8117
--- /dev/null
+++ b/DynamicTablesPkg/Include/Library/Tpm2DeviceTableLib.h
@@ -0,0 +1,50 @@
+/** @file
+ Tpm2 device table generating Library
+
+ Copyright (c) 2025, Arm Limited. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef TPM2_DEVICE_TABLE_LIB_H_
+#define TPM2_DEVICE_TABLE_LIB_H_
+
+/** Build a SSDT table describing the TPM2 device.
+
+ The table created by this function must be freed by FreeTpm2DeviceTable.
+
+ @param [in] TpmDevInfo TPM2 Device info to describe in the SSDT table.
+ @param [in] Name The Name to give to the Device.
+ Must be a NULL-terminated ASL NameString
+ e.g.: "DEV0", "DV15.DEV0", etc.
+ @param [in] Uid UID for the TPM@ device.
+ @param [out] Table If success, pointer to the created SSDT table.
+
+ @retval EFI_SUCCESS Table generated successfully.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+ @retval EFI_NOT_FOUND Could not find information.
+ @retval EFI_OUT_OF_RESOURCES Could not allocate memory.
+**/
+EFI_STATUS
+EFIAPI
+BuildTpm2DeviceTable (
+ IN CONST CM_ARCH_COMMON_TPM2_DEVICE_INFO *TpmDevInfo,
+ IN CONST CHAR8 *Name,
+ IN CONST UINT64 Uid,
+ OUT EFI_ACPI_DESCRIPTION_HEADER **Table
+ );
+
+/** Free an Tpm2 device table previously created by
+ the BuildTpm2DeviceTable function.
+
+ @param [in] Table Pointer to a Tpm2 Device table allocated by
+ the BuildTpm2DeviceTable function.
+
+**/
+VOID
+EFIAPI
+FreeTpm2DeviceTable (
+ IN EFI_ACPI_DESCRIPTION_HEADER *Table
+ );
+
+#endif // TPM2_DEVICE_TABLE_LIB_H_
diff --git a/DynamicTablesPkg/Library/Acpi/Common/AcpiTpm2Lib/AcpiTpm2Lib.inf b/DynamicTablesPkg/Library/Acpi/Common/AcpiTpm2Lib/AcpiTpm2Lib.inf
index ee50fc6..1623e4d 100644
--- a/DynamicTablesPkg/Library/Acpi/Common/AcpiTpm2Lib/AcpiTpm2Lib.inf
+++ b/DynamicTablesPkg/Library/Acpi/Common/AcpiTpm2Lib/AcpiTpm2Lib.inf
@@ -26,4 +26,9 @@
MdePkg/MdePkg.dec
[LibraryClasses]
+ AcpiHelperLib
BaseLib
+ Tpm2DeviceTableLib
+
+[FixedPcd]
+ gEdkiiDynamicTablesPkgTokenSpaceGuid.PcdGenTpm2DeviceTable
diff --git a/DynamicTablesPkg/Library/Acpi/Common/AcpiTpm2Lib/Tpm2Generator.c b/DynamicTablesPkg/Library/Acpi/Common/AcpiTpm2Lib/Tpm2Generator.c
index c743e20..9e39eb5 100644
--- a/DynamicTablesPkg/Library/Acpi/Common/AcpiTpm2Lib/Tpm2Generator.c
+++ b/DynamicTablesPkg/Library/Acpi/Common/AcpiTpm2Lib/Tpm2Generator.c
@@ -20,13 +20,16 @@
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
#include <Protocol/AcpiTable.h>
// Module specific include files.
#include <AcpiTableGenerator.h>
#include <ConfigurationManagerObject.h>
#include <ConfigurationManagerHelper.h>
+#include <Library/AcpiHelperLib.h>
#include <Library/TableHelperLib.h>
+#include <Library/Tpm2DeviceTableLib.h>
#include <Protocol/ConfigurationManagerProtocol.h>
#include <IndustryStandard/Tpm2Acpi.h>
@@ -35,6 +38,9 @@
#define START_METHOD_CRB_WITH_SMC_PARAM_SIZE 12
#define START_METHOD_CRB_WITH_FFA_PARM_SIZE 12
+#define TPM2_DEVICE_UID 0
+#define MAX_TABLE_COUNT 2
+
/**
ARM standard TPM2 Generator
@@ -53,6 +59,12 @@ GET_OBJECT_LIST (
CM_ARCH_COMMON_TPM2_INTERFACE_INFO
);
+GET_OBJECT_LIST (
+ EObjNameSpaceArchCommon,
+ EArchCommonObjTpm2DeviceInfo,
+ CM_ARCH_COMMON_TPM2_DEVICE_INFO
+ );
+
/**
Sanity check Start Method Specific Parameters field
@@ -122,6 +134,73 @@ AcpiTpm2CheckStartMethodParameters (
return EFI_SUCCESS;
}
+/** Build a TPM2 ACPI table.
+
+ @param [in] This Pointer to the table generator.
+ @param [in] AcpiTableInfo Pointer to the ACPI Table Info.
+ @param [in] CfgMgrProtocol Pointer to the Configuration Manager
+ Protocol Interface.
+ @param [in] TpmInfo TpmInfo to describe TPM2 device.
+ @param [in, out] Tpm2AcpiTable Tpm2AcpiTable.
+ @param [in] TableSize Size of Tpm2AcpiTable.
+
+ @retval EFI_SUCCESS Table generated successfully.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+ @retval EFI_NOT_FOUND Could not find information.
+ @retval EFI_OUT_OF_RESOURCES Could not allocate memory.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+BuildTpm2AcpiTable (
+ IN CONST ACPI_TABLE_GENERATOR *CONST This,
+ IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *CONST AcpiTableInfo,
+ IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol,
+ IN CONST CM_ARCH_COMMON_TPM2_INTERFACE_INFO *TpmInfo,
+ IN OUT EFI_TPM2_ACPI_TABLE *Tpm2AcpiTable,
+ IN UINT32 TableSize
+ )
+{
+ EFI_STATUS Status;
+ UINT32 *Laml;
+ UINT64 *Lasa;
+
+ Status = AddAcpiHeader (
+ CfgMgrProtocol,
+ This,
+ &Tpm2AcpiTable->Header,
+ AcpiTableInfo,
+ TableSize
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: TPM2: Failed to add ACPI header. Status = %r\n",
+ Status
+ ));
+ return Status;
+ }
+
+ Tpm2AcpiTable->Flags = TpmInfo->PlatformClass;
+ Tpm2AcpiTable->AddressOfControlArea = TpmInfo->AddressOfControlArea;
+ Tpm2AcpiTable->StartMethod = TpmInfo->StartMethod;
+
+ CopyMem (
+ Tpm2AcpiTable + 1,
+ TpmInfo->StartMethodParameters,
+ TpmInfo->StartMethodParametersSize
+ );
+
+ if (TpmInfo->Laml > 0) {
+ Lasa = (UINT64 *)((UINT8 *)Tpm2AcpiTable + TableSize - sizeof (TpmInfo->Lasa));
+ Laml = (UINT32 *)((UINT8 *)Lasa - sizeof (TpmInfo->Laml));
+ *Laml = TpmInfo->Laml;
+ *Lasa = TpmInfo->Lasa;
+ }
+
+ return EFI_SUCCESS;
+}
+
/** Construct the TPM2 ACPI table.
Called by the Dynamic Table Manager, this function invokes the
@@ -135,7 +214,8 @@ AcpiTpm2CheckStartMethodParameters (
@param [in] AcpiTableInfo Pointer to the ACPI Table Info.
@param [in] CfgMgrProtocol Pointer to the Configuration Manager
Protocol Interface.
- @param [out] Table Pointer to the constructed ACPI Table.
+ @param [out] Table Pointer to a list of generated ACPI table(s).
+ @param [out] TableCount Number of generated ACPI table(s).
@retval EFI_SUCCESS Table generated successfully.
@retval EFI_INVALID_PARAMETER A parameter is invalid.
@@ -148,22 +228,24 @@ AcpiTpm2CheckStartMethodParameters (
STATIC
EFI_STATUS
EFIAPI
-BuildTpm2Table (
+BuildTpm2TableEx (
IN CONST ACPI_TABLE_GENERATOR *CONST This,
IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *CONST AcpiTableInfo,
IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol,
- OUT EFI_ACPI_DESCRIPTION_HEADER **CONST Table
+ OUT EFI_ACPI_DESCRIPTION_HEADER ***Table,
+ OUT UINTN *CONST TableCount
)
{
EFI_STATUS Status;
- UINT32 TableSize;
CM_ARCH_COMMON_TPM2_INTERFACE_INFO *TpmInfo;
- EFI_TPM2_ACPI_TABLE *Tpm2;
- UINT32 *Laml;
- UINT64 *Lasa;
+ CM_ARCH_COMMON_TPM2_DEVICE_INFO *TpmDevInfo;
+ UINT32 TableSize;
UINT32 MaxParameterSize;
+ EFI_ACPI_DESCRIPTION_HEADER **TableList;
+ CHAR8 NewName[AML_NAME_SEG_SIZE + 1];
- *Table = NULL;
+ *Table = NULL;
+ *TableCount = 0;
ASSERT (
(This != NULL) &&
@@ -233,9 +315,24 @@ BuildTpm2Table (
TableSize += sizeof (TpmInfo->Laml) + sizeof (TpmInfo->Lasa);
}
+ // Allocate a table to store pointers to the TPM2 table and
+ // Ssdt table.for Tpm2 device description.
+ TableList = (EFI_ACPI_DESCRIPTION_HEADER **)
+ AllocateZeroPool (
+ (sizeof (EFI_ACPI_DESCRIPTION_HEADER *) * MAX_TABLE_COUNT)
+ );
+ if (TableList == NULL) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: TPM2: Failed to allocate memory for TableList.\n"
+ ));
+ return EFI_OUT_OF_RESOURCES;
+ }
+
// Allocate the Buffer for TPM2 table
- *Table = (EFI_ACPI_DESCRIPTION_HEADER *)AllocateZeroPool (TableSize);
- if (*Table == NULL) {
+ TableList[0] = (EFI_ACPI_DESCRIPTION_HEADER *)AllocateZeroPool (TableSize);
+ if (TableList[0] == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
DEBUG ((
DEBUG_ERROR,
"ERROR: TPM2: Failed to allocate memory for TPM2 Table, Size = %d," \
@@ -243,51 +340,85 @@ BuildTpm2Table (
TableSize,
Status
));
- return EFI_OUT_OF_RESOURCES;
+ goto ErrorHandler;
}
- Tpm2 = (EFI_TPM2_ACPI_TABLE *)*Table;
-
- Status = AddAcpiHeader (
- CfgMgrProtocol,
+ Status = BuildTpm2AcpiTable (
This,
- &Tpm2->Header,
AcpiTableInfo,
+ CfgMgrProtocol,
+ TpmInfo,
+ (EFI_TPM2_ACPI_TABLE *)TableList[0],
TableSize
);
if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_ERROR,
- "ERROR: TPM2: Failed to add ACPI header. Status = %r\n",
+ "ERROR: TPM2: Failed to Build TPM2 ACPI Table, " \
+ " Status = %r\n",
Status
));
- goto error_handler;
+ goto ErrorHandler;
}
- Tpm2->Flags = TpmInfo->PlatformClass;
- Tpm2->AddressOfControlArea = TpmInfo->AddressOfControlArea;
- Tpm2->StartMethod = TpmInfo->StartMethod;
-
- CopyMem (
- Tpm2 + 1,
- TpmInfo->StartMethodParameters,
- TpmInfo->StartMethodParametersSize
- );
-
- if (TpmInfo->Laml > 0) {
- Laml = (UINT32 *)((UINT8 *)Tpm2 + sizeof (EFI_TPM2_ACPI_TABLE) + MaxParameterSize);
- Lasa = (UINT64 *)((UINT8 *)Laml + sizeof (TpmInfo->Laml));
- *Laml = TpmInfo->Laml;
- *Lasa = TpmInfo->Lasa;
+ *TableCount += 1;
+
+ // Generate TPM2 device SSDT table.
+ if (FixedPcdGetBool (PcdGenTpm2DeviceTable)) {
+ Status = GetEArchCommonObjTpm2DeviceInfo (
+ CfgMgrProtocol,
+ CM_NULL_TOKEN,
+ &TpmDevInfo,
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: Failed to get TPM2 Device CM Object %r\n",
+ __func__,
+ Status
+ ));
+ goto ErrorHandler;
+ }
+
+ NewName[0] = 'T';
+ NewName[1] = 'P';
+ NewName[2] = 'M';
+ NewName[3] = AsciiFromHex ((UINT8)(TPM2_DEVICE_UID));
+ NewName[4] = '\0';
+
+ Status = BuildTpm2DeviceTable (
+ TpmDevInfo,
+ NewName,
+ TPM2_DEVICE_UID,
+ &TableList[1]
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: TPM2: Failed to Build SSDT table for TPM2 device," \
+ " Status = %r\n",
+ Status
+ ));
+ goto ErrorHandler;
+ }
+
+ *TableCount += 1;
}
+ *Table = TableList;
+
return EFI_SUCCESS;
-error_handler:
+ErrorHandler:
+ *TableCount = 0;
+
+ if (TableList != NULL) {
+ if (TableList[0] != NULL) {
+ FreePool (TableList[0]);
+ }
- if (*Table != NULL) {
- FreePool (*Table);
- *Table = NULL;
+ FreePool (TableList);
}
return Status;
@@ -299,7 +430,10 @@ error_handler:
@param [in] AcpiTableInfo Pointer to the ACPI Table Info.
@param [in] CfgMgrProtocol Pointer to the Configuration Manager
Protocol Interface.
- @param [in, out] Table Pointer to the ACPI Table.
+ @param [in, out] Table Pointer to an array of pointers
+ to ACPI Table(s).
+ @param [in] TableCount Number of ACPI table(s).
+
@retval EFI_SUCCESS The resources were freed successfully.
@retval EFI_INVALID_PARAMETER The table pointer is NULL or invalid.
@@ -307,13 +441,17 @@ error_handler:
STATIC
EFI_STATUS
EFIAPI
-FreeTpm2TableResources (
- IN CONST ACPI_TABLE_GENERATOR *CONST This,
- IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *CONST AcpiTableInfo,
- IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol,
- IN OUT EFI_ACPI_DESCRIPTION_HEADER **CONST Table
+FreeTpm2TableResourcesEx (
+ IN CONST ACPI_TABLE_GENERATOR *CONST This,
+ IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *CONST AcpiTableInfo,
+ IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol,
+ IN OUT EFI_ACPI_DESCRIPTION_HEADER ***CONST Table,
+ IN CONST UINTN TableCount
)
{
+ UINTN Idx;
+ EFI_ACPI_DESCRIPTION_HEADER **TableList;
+
ASSERT (
(This != NULL) &&
(AcpiTableInfo != NULL) &&
@@ -322,12 +460,27 @@ FreeTpm2TableResources (
(AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature)
);
- if ((Table == NULL) || (*Table == NULL)) {
+ if ((Table == NULL) || (*Table == NULL) || (TableCount == 0)) {
DEBUG ((DEBUG_ERROR, "ERROR: TPM2: Invalid Table Pointer\n"));
return EFI_INVALID_PARAMETER;
}
- FreePool (*Table);
+ TableList = *Table;
+
+ for (Idx = 0; Idx < TableCount; Idx++) {
+ switch (TableList[Idx]->Signature) {
+ case EFI_ACPI_6_5_TRUSTED_COMPUTING_PLATFORM_2_TABLE_SIGNATURE:
+ FreePool (TableList[Idx]);
+ break;
+ case EFI_ACPI_6_5_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE:
+ FreeTpm2DeviceTable (TableList[Idx]);
+ break;
+ default:
+ ASSERT (0);
+ }
+ }
+
+ FreePool (TableList);
*Table = NULL;
return EFI_SUCCESS;
@@ -357,14 +510,14 @@ ACPI_TABLE_GENERATOR Tpm2Generator = {
// Creator Revision
TPM2_GENERATOR_REVISION,
// Build Table function
- BuildTpm2Table,
+ NULL,
// Free Resource function
- FreeTpm2TableResources,
- // Extended build function not needed
NULL,
+ // Extended build function not needed
+ BuildTpm2TableEx,
// Extended build function not implemented by the generator.
// Hence extended free resource function is not required.
- NULL
+ FreeTpm2TableResourcesEx
};
/** Register the Generator with the ACPI Table Factory.
diff --git a/DynamicTablesPkg/Library/Acpi/X64/SsdtSerialPortFixupLib/SsdtSerialPortFixupLib.c b/DynamicTablesPkg/Library/Acpi/X64/SsdtSerialPortFixupLib/SsdtSerialPortFixupLib.c
new file mode 100644
index 0000000..b6e7c46
--- /dev/null
+++ b/DynamicTablesPkg/Library/Acpi/X64/SsdtSerialPortFixupLib/SsdtSerialPortFixupLib.c
@@ -0,0 +1,533 @@
+/** @file
+ SSDT Serial Port Fixup Library for X64.
+
+
+ Copyright (c) 2019 - 2024, Arm Limited. All rights reserved.<BR>
+ Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - Arm Server Base Boot Requirements (SBBR), s4.2.1.8 "SPCR".
+ - Microsoft Debug Port Table 2 (DBG2) Specification - December 10, 2015.
+ - ACPI for Arm Components 1.0 - 2020
+ - Arm Generic Interrupt Controller Architecture Specification,
+ Issue H, January 2022.
+ (https://developer.arm.com/documentation/ihi0069/)
+**/
+
+#include <IndustryStandard/DebugPort2Table.h>
+#include <Library/AcpiLib.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Protocol/AcpiTable.h>
+
+// Module specific include files.
+#include <AcpiTableGenerator.h>
+#include <ConfigurationManagerObject.h>
+#include <ConfigurationManagerHelper.h>
+#include <Library/AcpiHelperLib.h>
+#include <Library/AmlLib/AmlLib.h>
+#include <Protocol/ConfigurationManagerProtocol.h>
+
+/** UART address range length.
+*/
+#define MIN_UART_ADDRESS_LENGTH 0x1000U
+
+/** Validate the Serial Port Information.
+
+ @param [in] SerialPortInfoTable Table of CM_ARCH_COMMON_SERIAL_PORT_INFO.
+ @param [in] SerialPortCount Count of SerialPort in the table.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+**/
+EFI_STATUS
+EFIAPI
+ValidateSerialPortInfo (
+ IN CONST CM_ARCH_COMMON_SERIAL_PORT_INFO *SerialPortInfoTable,
+ IN UINT32 SerialPortCount
+ )
+{
+ UINT32 Index;
+ CONST CM_ARCH_COMMON_SERIAL_PORT_INFO *SerialPortInfo;
+
+ if ((SerialPortInfoTable == NULL) ||
+ (SerialPortCount == 0))
+ {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ for (Index = 0; Index < SerialPortCount; Index++) {
+ SerialPortInfo = &SerialPortInfoTable[Index];
+ ASSERT (SerialPortInfo != NULL);
+
+ if ((SerialPortInfo == NULL) ||
+ (SerialPortInfo->BaseAddress == 0))
+ {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: UART port base address is invalid. BaseAddress = 0x%llx\n",
+ SerialPortInfo->BaseAddress
+ ));
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if ((SerialPortInfo->PortSubtype !=
+ EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_ARM_PL011_UART) &&
+ (SerialPortInfo->PortSubtype !=
+ EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_ARM_SBSA_GENERIC_UART_2X) &&
+ (SerialPortInfo->PortSubtype !=
+ EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_ARM_SBSA_GENERIC_UART) &&
+ (SerialPortInfo->PortSubtype !=
+ EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_DCC) &&
+ (SerialPortInfo->PortSubtype !=
+ EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_FULL_16550) &&
+ (SerialPortInfo->PortSubtype !=
+ EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_16550_WITH_GAS))
+ {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: UART port subtype is invalid."
+ " UART Base = 0x%llx, PortSubtype = 0x%x\n",
+ SerialPortInfo->BaseAddress,
+ SerialPortInfo->PortSubtype
+ ));
+ return EFI_INVALID_PARAMETER;
+ }
+
+ DEBUG ((DEBUG_INFO, "UART Configuration:\n"));
+ DEBUG ((
+ DEBUG_INFO,
+ " UART Base = 0x%llx\n",
+ SerialPortInfo->BaseAddress
+ ));
+ DEBUG ((
+ DEBUG_INFO,
+ " Length = 0x%llx\n",
+ SerialPortInfo->BaseAddressLength
+ ));
+ DEBUG ((DEBUG_INFO, " Clock = %lu\n", SerialPortInfo->Clock));
+ DEBUG ((DEBUG_INFO, " BaudRate = %llu\n", SerialPortInfo->BaudRate));
+ DEBUG ((DEBUG_INFO, " Interrupt = %lu\n", SerialPortInfo->Interrupt));
+ } // for
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Create the _CRS (Current Resource Settings) AML node for a serial port device.
+
+ @param [in] SerialPortInfo Pointer to the serial port information structure.
+ @param [in] Name The Name to give to the Device.
+ Must be a NULL-terminated ASL NameString
+ e.g.: "DEV0", "DV15.DEV0", etc.
+ @param [in] DeviceNode AML device node handle.
+
+ @retval EFI_SUCCESS The CRS node was created successfully.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+ @retval Others Failed to create CRS node.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+CreateSerialPortCrs (
+ IN CONST CM_ARCH_COMMON_SERIAL_PORT_INFO *SerialPortInfo,
+ IN CONST CHAR8 *Name,
+ IN AML_OBJECT_NODE_HANDLE DeviceNode
+ )
+{
+ AML_OBJECT_NODE_HANDLE CrsNode;
+ EFI_STATUS Status;
+ UINT8 IrqList[1];
+
+ Status = AmlCodeGenNameResourceTemplate ("_CRS", DeviceNode, &CrsNode);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: SSDT-SERIAL-PORT-FIXUP: Failed to create AML _CRS Node."
+ " Status = %r\n",
+ Status
+ ));
+ return Status;
+ }
+
+ IrqList[0] = SerialPortInfo->Interrupt & MAX_UINT8;
+
+ if (SerialPortInfo->PortSubtype == EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_FULL_16550) {
+ Status = AmlCodeGenRdIo (
+ TRUE,
+ SerialPortInfo->BaseAddress & MAX_UINT16,
+ SerialPortInfo->BaseAddress & MAX_UINT16,
+ 1,
+ 0x8,
+ CrsNode,
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: SSDT-SERIAL-PORT-FIXUP: Failed to generate IO RD node."
+ " Status = %r\n",
+ Status
+ ));
+ return Status;
+ }
+
+ //
+ // Generate the IRQ() ASL macro.
+ // This is used for legacy X86/X64/PC-AT compatible systems.
+ //
+ Status = AmlCodeGenRdIrq (
+ TRUE,
+ TRUE,
+ TRUE,
+ IrqList,
+ ARRAY_SIZE (IrqList),
+ CrsNode,
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: SSDT-SERIAL-PORT-FIXUP: Failed to generate IRQ RD node."
+ " Status = %r\n",
+ Status
+ ));
+ return Status;
+ }
+
+ //
+ // Generate the UARTSerialBusV2() ASL macro.
+ // This describes legacy COM port resources for X86/X64/PC-AT compatible systems.
+ //
+ Status = AmlCodeGenRdUartSerialBusV2 (
+ SerialPortInfo->BaudRate & MAX_UINT32, // BaudRate
+ NULL, // Default 8 Bits Per Byte
+ NULL, // Default 1 Stop Bit
+ 0, // Lines in Use
+ NULL, // Default is little endian
+ NULL, // Default is no parity
+ NULL, // Default is no flow control
+ 0x1, // ReceiveBufferSize
+ 0x1, // TransmitBufferSize
+ (CHAR8 *)Name, // Serial Port Name
+ (AsciiStrLen (Name) + 1) & MAX_UINT16, // Serial Port Name Length
+ NULL, // Default resource index is zero
+ NULL, // Default is consumer
+ NULL, // Default is exclusive
+ NULL, // vendor defined data
+ 0, // VendorDefinedDataLength
+ CrsNode,
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: SSDT-SERIAL-PORT-FIXUP: Failed to generate UartSerialBus RD node."
+ " Status = %r\n",
+ Status
+ ));
+ return Status;
+ }
+ }
+
+ if (SerialPortInfo->PortSubtype == EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_16550_WITH_GAS) {
+ Status = AmlCodeGenRdMemory32Fixed (
+ TRUE,
+ SerialPortInfo->BaseAddress & MAX_UINT32,
+ ((SerialPortInfo->BaseAddressLength > MIN_UART_ADDRESS_LENGTH)
+ ? SerialPortInfo->BaseAddressLength
+ : MIN_UART_ADDRESS_LENGTH) & MAX_UINT32,
+ CrsNode,
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: SSDT-SERIAL-PORT-FIXUP: Failed to generate MMIO RD node."
+ " Status = %r\n",
+ Status
+ ));
+ return Status;
+ }
+
+ Status = AmlCodeGenRdIrq (
+ TRUE,
+ TRUE,
+ TRUE,
+ IrqList,
+ 1,
+ CrsNode,
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: SSDT-SERIAL-PORT-FIXUP: Failed to generate IRQ RD node."
+ " Status = %r\n",
+ Status
+ ));
+ return Status;
+ }
+ }
+
+ return EFI_SUCCESS;
+}
+
+/** Build a SSDT table describing the input serial port.
+
+ The table created by this function must be freed by FreeSsdtSerialTable.
+
+ @param [in] AcpiTableInfo Pointer to the ACPI table information.
+ @param [in] SerialPortInfo Serial port to describe in the SSDT table.
+ @param [in] Name The Name to give to the Device.
+ Must be a NULL-terminated ASL NameString
+ e.g.: "DEV0", "DV15.DEV0", etc.
+ @param [in] Uid UID for the Serial Port.
+ @param [out] Table If success, pointer to the created SSDT table.
+
+ @retval EFI_SUCCESS Table generated successfully.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+ @retval EFI_NOT_FOUND Could not find information.
+ @retval EFI_OUT_OF_RESOURCES Could not allocate memory.
+**/
+EFI_STATUS
+EFIAPI
+BuildSsdtSerialPortTable (
+ IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *AcpiTableInfo,
+ IN CONST CM_ARCH_COMMON_SERIAL_PORT_INFO *SerialPortInfo,
+ IN CONST CHAR8 *Name,
+ IN CONST UINT64 Uid,
+ OUT EFI_ACPI_DESCRIPTION_HEADER **Table
+ )
+{
+ AML_OBJECT_NODE_HANDLE DeviceNode;
+ AML_OBJECT_NODE_HANDLE ScopeNode;
+ AML_ROOT_NODE_HANDLE RootNode;
+ CONST CHAR8 *NonBsaHid;
+ EFI_STATUS Status;
+ EFI_STATUS Status1;
+ UINT32 EisaId;
+
+ ASSERT (AcpiTableInfo != NULL);
+ ASSERT (SerialPortInfo != NULL);
+ ASSERT (Name != NULL);
+ ASSERT (Table != NULL);
+
+ // Validate the Serial Port Info.
+ Status = ValidateSerialPortInfo (SerialPortInfo, 1);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Status = AmlCodeGenDefinitionBlock (
+ "SSDT",
+ "AMDINC",
+ "SERIAL",
+ 0x01,
+ &RootNode
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: SSDT-SERIAL-PORT-FIXUP: Failed to create AML Definition Block."
+ " Status = %r\n",
+ Status
+ ));
+ ASSERT_EFI_ERROR (Status);
+ return Status;
+ }
+
+ Status = AmlCodeGenScope ("\\_SB_", RootNode, &ScopeNode);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: SSDT-SERIAL-PORT-FIXUP: Failed to create AML Scope Node."
+ " Status = %r\n",
+ Status
+ ));
+ goto exit_handler;
+ }
+
+ // Create the Device Node, COMx, where x is the Uid.
+ Status = AmlCodeGenDevice (Name, ScopeNode, &DeviceNode);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: SSDT-SERIAL-PORT-FIXUP: Failed to create AML Device Node."
+ " Status = %r\n",
+ Status
+ ));
+ goto exit_handler;
+ }
+
+ NonBsaHid = (CONST CHAR8 *)PcdGetPtr (PcdNonBsaCompliant16550SerialHid);
+ if (SerialPortInfo->PortSubtype == EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_16550_WITH_GAS) {
+ if ((NonBsaHid != NULL) && (AsciiStrLen (NonBsaHid) != 0)) {
+ if (!(IsValidPnpId (NonBsaHid) || IsValidAcpiId (NonBsaHid))) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: SSDT-SERIAL-PORT-FIXUP: Invalid Supplied HID %a.\n",
+ NonBsaHid
+ ));
+ goto exit_handler;
+ }
+
+ Status = AmlCodeGenNameString (
+ "_HID",
+ NonBsaHid,
+ DeviceNode,
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: SSDT-SERIAL-PORT-FIXUP: Failed to create AML _HID Node."
+ " Status = %r\n",
+ Status
+ ));
+ goto exit_handler;
+ }
+ }
+ }
+
+ if ((SerialPortInfo->PortSubtype == EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_FULL_16550) ||
+ ((SerialPortInfo->PortSubtype == EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_16550_WITH_GAS) &&
+ ((NonBsaHid == NULL) || (AsciiStrLen (NonBsaHid) == 0))))
+ {
+ Status = AmlGetEisaIdFromString ("PNP0501", &EisaId);
+ if (EFI_ERROR (Status)) {
+ goto exit_handler;
+ }
+
+ Status = AmlCodeGenNameInteger ("_HID", EisaId, DeviceNode, NULL);
+ if (EFI_ERROR (Status)) {
+ goto exit_handler;
+ }
+
+ Status = AmlGetEisaIdFromString ("PNP0500", &EisaId);
+ if (EFI_ERROR (Status)) {
+ goto exit_handler;
+ }
+
+ Status = AmlCodeGenNameInteger ("_CID", EisaId, DeviceNode, NULL);
+ if (EFI_ERROR (Status)) {
+ goto exit_handler;
+ }
+ }
+
+ // _UID
+ Status = AmlCodeGenNameInteger ("_UID", Uid, DeviceNode, NULL);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: SSDT-SERIAL-PORT-FIXUP: Failed to create AML _UID Node."
+ " Status = %r\n",
+ Status
+ ));
+ goto exit_handler;
+ }
+
+ // _DDN
+ Status = AmlCodeGenNameString ("_DDN", Name, DeviceNode, NULL);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: SSDT-SERIAL-PORT-FIXUP: Failed to create AML _DDN Node."
+ " Status = %r\n",
+ Status
+ ));
+ goto exit_handler;
+ }
+
+ // _STA
+ Status = AmlCodeGenMethodRetInteger (
+ "_STA",
+ 0x0F,
+ 0,
+ FALSE,
+ 0,
+ DeviceNode,
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: SSDT-SERIAL-PORT-FIXUP: Failed to create AML _STA Node."
+ " Status = %r\n",
+ Status
+ ));
+ goto exit_handler;
+ }
+
+ Status = CreateSerialPortCrs (SerialPortInfo, Name, DeviceNode);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: SSDT-SERIAL-PORT-FIXUP: Failed to create _CRS for Serial Port."
+ " Status = %r\n",
+ Status
+ ));
+ goto exit_handler;
+ }
+
+ // Serialize the tree.
+ Status = AmlSerializeDefinitionBlock (
+ RootNode,
+ Table
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: SSDT-SERIAL-PORT-FIXUP: Failed to Serialize SSDT Table Data."
+ " Status = %r\n",
+ Status
+ ));
+ }
+
+ return EFI_SUCCESS;
+
+exit_handler:
+ // Cleanup
+ if (RootNode != NULL) {
+ Status1 = AmlDeleteTree (RootNode);
+ if (EFI_ERROR (Status1)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: SSDT-SERIAL-PORT-FIXUP: Failed to cleanup AML tree."
+ " Status = %r\n",
+ Status1
+ ));
+ // If Status was success but we failed to delete the AML Tree
+ // return Status1 else return the original error code, i.e. Status.
+ if (!EFI_ERROR (Status)) {
+ return Status1;
+ }
+ }
+ }
+
+ return Status;
+}
+
+/** Free an SSDT table previously created by
+ the BuildSsdtSerialTable function.
+
+ @param [in] Table Pointer to a SSDT table allocated by
+ the BuildSsdtSerialTable function.
+
+ @retval EFI_SUCCESS Success.
+**/
+EFI_STATUS
+EFIAPI
+FreeSsdtSerialPortTable (
+ IN EFI_ACPI_DESCRIPTION_HEADER *Table
+ )
+{
+ ASSERT (Table != NULL);
+ FreePool (Table);
+ return EFI_SUCCESS;
+}
diff --git a/DynamicTablesPkg/Library/Acpi/X64/SsdtSerialPortFixupLib/SsdtSerialPortFixupLib.inf b/DynamicTablesPkg/Library/Acpi/X64/SsdtSerialPortFixupLib/SsdtSerialPortFixupLib.inf
new file mode 100644
index 0000000..73ae99b
--- /dev/null
+++ b/DynamicTablesPkg/Library/Acpi/X64/SsdtSerialPortFixupLib/SsdtSerialPortFixupLib.inf
@@ -0,0 +1,32 @@
+## @file
+# SSDT Serial Port fixup Library
+#
+# Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 1.30
+ BASE_NAME = DynamicSsdtSerialPortFixupLib
+ FILE_GUID = 83F367CE-9EA3-4A5B-B61F-60E06CA7D9FF
+ VERSION_STRING = 1.0
+ MODULE_TYPE = DXE_DRIVER
+ LIBRARY_CLASS = SsdtSerialPortFixupLib
+
+[Sources]
+ SsdtSerialPortFixupLib.c
+
+[Packages.common]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ EmbeddedPkg/EmbeddedPkg.dec
+ DynamicTablesPkg/DynamicTablesPkg.dec
+
+[LibraryClasses]
+ AcpiHelperLib
+ AmlLib
+ BaseLib
+
+[Pcd]
+ gEdkiiDynamicTablesPkgTokenSpaceGuid.PcdNonBsaCompliant16550SerialHid
diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c
index bf0d7b0..8be5eab 100644
--- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c
+++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c
@@ -2,7 +2,7 @@
AML Resource Data Code Generation.
Copyright (c) 2020 - 2021, Arm Limited. All rights reserved.<BR>
- Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR>
+ Copyright (C) 2023 - 2025 Advanced Micro Devices, Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -1670,3 +1670,461 @@ error_handler:
return Status;
}
+
+/** Code generation for the IRQ Descriptor.
+
+ The Resource Data effectively created is an IRQ Resource
+ Data. Cf ACPI 6.5 specification:
+ - s6.4.2.1 "IRQ Descriptor"
+ - s19.6.66 "IRQ (Interrupt Resource Descriptor Macro)"
+
+
+ The created resource data node can be:
+ - appended to the list of resource data elements of the NameOpNode.
+ In such case NameOpNode must be defined by a the "Name ()" ASL statement
+ and initially contain a "ResourceTemplate ()".
+ - returned through the NewRdNode parameter.
+
+ @param [in] IsEdgeTriggered The interrupt is edge triggered or
+ level triggered.
+ @param [in] IsActiveLow The interrupt is active-high or active-low.
+ @param [in] IsShared The interrupt can be shared with other
+ devices or not (Exclusive).
+ @param [in] IrqList List of IRQ numbers. Must be non-NULL.
+ @param [in] IrqCount Number of IRQs in IrqList. Must be > 0 and <= 16.
+ @param [in] NameOpNode NameOp object node defining a named object.
+ If provided, append the new resource data node
+ to the list of resource data elements of this node.
+ @param [out] NewRdNode If provided and success, contain the created node.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval various Other errors as indicated.
+**/
+EFI_STATUS
+EFIAPI
+AmlCodeGenRdIrq (
+ IN BOOLEAN IsEdgeTriggered,
+ IN BOOLEAN IsActiveLow,
+ IN BOOLEAN IsShared,
+ IN UINT8 *IrqList,
+ IN UINT8 IrqCount,
+ IN AML_OBJECT_NODE_HANDLE NameOpNode OPTIONAL,
+ OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL
+ )
+{
+ AML_DATA_NODE *RdNode;
+ EFI_ACPI_IRQ_DESCRIPTOR IrqDesc;
+ EFI_STATUS Status;
+ UINT8 Index;
+ UINT16 Mask;
+
+ if ((NameOpNode == NULL) && (NewRdNode == NULL)) {
+ ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if ((IsEdgeTriggered && !IsActiveLow) ||
+ (!IsEdgeTriggered && IsActiveLow))
+ {
+ ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if ((IrqList == NULL) || (IrqCount == 0) || (IrqCount > 16)) {
+ ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Mask = 0;
+ for (Index = 0; Index < IrqCount; Index++) {
+ if (IrqList[Index] > 16) {
+ ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if ((Mask & (1 << IrqList[Index])) != 0) {
+ ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Mask |= (1 << IrqList[Index]);
+ }
+
+ if (Mask == 0) {
+ ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ IrqDesc.Header.Bits.Type = ACPI_SMALL_ITEM_FLAG;
+ IrqDesc.Header.Bits.Name = ACPI_SMALL_IRQ_DESCRIPTOR_NAME;
+ IrqDesc.Header.Bits.Length = sizeof (EFI_ACPI_IRQ_DESCRIPTOR) -
+ sizeof (ACPI_SMALL_RESOURCE_HEADER);
+ IrqDesc.Mask = Mask;
+ IrqDesc.Information = (IsEdgeTriggered ? BIT0 : 0) |
+ (IsActiveLow ? BIT3 : 0) |
+ (IsShared ? BIT4 : 0);
+
+ Status = AmlCreateDataNode (
+ EAmlNodeDataTypeResourceData,
+ (UINT8 *)&IrqDesc,
+ sizeof (EFI_ACPI_IRQ_DESCRIPTOR),
+ &RdNode
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT_EFI_ERROR (Status);
+ return Status;
+ }
+
+ return LinkRdNode (RdNode, NameOpNode, NewRdNode);
+}
+
+/** Code generation for the UART Serial Bus Connection Resource Descriptor.
+
+ The Resource Data effectively created is a UART Serial Bus Connection
+ Resource Descriptor Resource Data.
+ Cf ACPI 6.5:
+ - s19.6.143 UARTSerialBusV2
+ (UART Serial Bus Connection Resource Descriptor Version 2 Macro)
+ - s6.4.3.8.2.3 UART Serial Bus Connection Resource Descriptor
+
+ The created resource data node can be:
+ - appended to the list of resource data elements of the NameOpNode.
+ In such case NameOpNode must be defined by a the "Name ()" ASL statement
+ and initially contain a "ResourceTemplate ()".
+ - returned through the NewRdNode parameter.
+
+ @param [in] IsResourceConsumer ResourceUsage parameter.
+ @param [in] IsSlaveMode Indicates whether the uart operates in slave mode.
+ @param [in] IsBigEndian Indicates whether the bit transfer is big-endian.
+ @param [in] BitsPerByte Indicates the number of bits per byte.
+ @param [in] StopBits Specifies the stop bits format used.
+ @param [in] FlowControl Specifies the flow control protocol used.
+ @param [in] BaudRate Specifies the baud rate.
+ @param [in] RxFifo Number of bytes in the receiver FIFO.
+ @param [in] TxFifo Number of bytes in the transmitter FIFO.
+ @param [in] Parity Specifies the parity format used.
+ @param [in] SerialLinesEnabled Specifies which serial lines are enabled.
+ @param [in] VendorDefinedData VendorDefinedData parameter.
+ @param [in] VendorDefinedDataLength VendorDefinedDataLength parameter.
+ @param [in] ResourceSource Name of source resource used.
+ @param [in] ResourceSourceLength Resource Source Length.
+ @param [in] NameOpNode NameOpNode object node defining a named object.
+ If provided, append the new resource data
+ node to the list of resource data elements
+ of this node.
+ @param [out] NewRdNode If provided and success,
+ contain the created node.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_OUT_OF_RESOURCES Could not allocate memory.
+ @retval various Other errors as indicated.
+
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+AmlCodeGenRdUartSerialBus (
+ IN BOOLEAN IsResourceConsumer,
+ IN BOOLEAN IsSlaveMode,
+ IN BOOLEAN IsBigEndian,
+ IN UINT8 BitsPerByte,
+ IN UINT8 StopBits,
+ IN UINT8 FlowControl,
+ IN UINT32 BaudRate,
+ IN UINT16 RxFifo,
+ IN UINT16 TxFifo,
+ IN UINT8 Parity,
+ IN UINT8 SerialLinesEnabled,
+ IN UINT8 *VendorDefinedData OPTIONAL,
+ IN UINT16 VendorDefinedDataLength,
+ IN CHAR8 *ResourceSource,
+ IN UINT16 ResourceSourceLength,
+ IN AML_OBJECT_NODE_HANDLE NameOpNode OPTIONAL,
+ OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL
+ )
+{
+ AML_DATA_NODE *RdNode;
+ EFI_STATUS Status;
+ UINT16 UartDescBuffLength;
+ UINT8 *UartDescBuff;
+ UINT8 BitsPerByteMask;
+
+ EFI_ACPI_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR UartDesc;
+
+ if ((NameOpNode == NULL) && (NewRdNode == NULL)) {
+ ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (((VendorDefinedData == NULL) && (VendorDefinedDataLength > 0)) ||
+ ((VendorDefinedData != NULL) && (VendorDefinedDataLength == 0)))
+ {
+ ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if ((ResourceSource == NULL) || (ResourceSourceLength <= 0)) {
+ ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (StopBits > EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_TSF_STOP_BIT_2) {
+ ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (FlowControl > EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_TSF_FC_XON_XOFF) {
+ ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (Parity > EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_PARITY_SPACE) {
+ ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ switch (BitsPerByte) {
+ case 5:
+ BitsPerByteMask = EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_TSF_5_BITS_PER_BYTE;
+ break;
+ case 6:
+ BitsPerByteMask = EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_TSF_6_BITS_PER_BYTE;
+ break;
+ case 7:
+ BitsPerByteMask = EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_TSF_7_BITS_PER_BYTE;
+ break;
+ case 8:
+ BitsPerByteMask = EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_TSF_8_BITS_PER_BYTE;
+ break;
+ case 9:
+ BitsPerByteMask = EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_TSF_9_BITS_PER_BYTE;
+ break;
+ default:
+ ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ /// as per spec last two bits are reserved and must be 0.
+ if ((SerialLinesEnabled &
+ ~(EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_LIN_RTS |
+ EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_LIN_CTS |
+ EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_LIN_DTR |
+ EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_LIN_DSR |
+ EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_LIN_RI |
+ EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_LIN_DTD)) != 0)
+ {
+ ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ UartDesc.Header.Header.Bits.Type = ACPI_LARGE_ITEM_FLAG;
+ UartDesc.Header.Header.Bits.Name = ACPI_LARGE_GENERIC_SERIAL_BUS_CONNECTION_DESCRIPTOR_NAME;
+ UartDesc.RevisionId = EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_REVISION_ID;
+ UartDesc.ResourceSourceIndex = 0;
+ UartDesc.SerialBusType = EFI_ACPI_SERIAL_BUS_RESOURCE_TYPE_UART;
+ UartDesc.GeneralFlags = (IsResourceConsumer ? BIT1 : 0) |
+ (IsSlaveMode ? BIT0 : 0);
+ UartDesc.TypeSpecificFlags = (IsBigEndian ? BIT7 : 0) |
+ (BitsPerByteMask << 4) |
+ (StopBits << 2) |
+ (FlowControl);
+ UartDesc.TypeSpecificRevisionId = EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_REVISION_ID;
+ /// TypeDataLength is the length of the data following the TypeDataLength,
+ /// up to the Additional vendor supplied data (not included).
+ UartDesc.TypeDataLength = sizeof (UartDesc.DefaultBaudRate) +
+ sizeof (UartDesc.RxFIFO) +
+ sizeof (UartDesc.TxFIFO) +
+ sizeof (UartDesc.Parity) +
+ sizeof (UartDesc.SerialLinesEnabled) +
+ VendorDefinedDataLength;
+ UartDesc.DefaultBaudRate = BaudRate;
+ UartDesc.RxFIFO = RxFifo;
+ UartDesc.TxFIFO = TxFifo;
+ UartDesc.Parity = Parity;
+ UartDesc.SerialLinesEnabled = SerialLinesEnabled;
+
+ UartDescBuffLength = sizeof (EFI_ACPI_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR) +
+ VendorDefinedDataLength +
+ ResourceSourceLength;
+
+ UartDesc.Header.Length = UartDescBuffLength - sizeof (ACPI_LARGE_RESOURCE_HEADER);
+
+ UartDescBuff = AllocateZeroPool (UartDescBuffLength);
+ if (UartDescBuff == NULL) {
+ ASSERT_EFI_ERROR (EFI_OUT_OF_RESOURCES);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ CopyMem (
+ UartDescBuff,
+ &UartDesc,
+ sizeof (EFI_ACPI_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR)
+ );
+
+ if (VendorDefinedData != NULL) {
+ CopyMem (
+ UartDescBuff + sizeof (EFI_ACPI_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR),
+ VendorDefinedData,
+ VendorDefinedDataLength
+ );
+ }
+
+ CopyMem (
+ UartDescBuff +
+ sizeof (EFI_ACPI_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR) +
+ VendorDefinedDataLength,
+ ResourceSource,
+ ResourceSourceLength
+ );
+
+ Status = AmlCreateDataNode (
+ EAmlNodeDataTypeResourceData,
+ UartDescBuff,
+ UartDescBuffLength,
+ &RdNode
+ );
+ FreePool (UartDescBuff);
+ if (EFI_ERROR (Status)) {
+ ASSERT_EFI_ERROR (Status);
+ return Status;
+ }
+
+ return LinkRdNode (RdNode, NameOpNode, NewRdNode);
+}
+
+/** Code generation for the UARTSerialBusV2() ASL macro.
+
+ The Resource Data effectively created is a UART Serial Bus Connection
+ Resource Descriptor Resource Data.
+ Cf ACPI 6.5:
+ - s19.6.143 UARTSerialBusV2
+ (UART Serial Bus Connection Resource Descriptor Version 2 Macro)
+ - s6.4.3.8.2.3 UART Serial Bus Connection Resource Descriptor
+
+ The created resource data node can be:
+ - appended to the list of resource data elements of the NameOpNode.
+ In such case NameOpNode must be defined by a the "Name ()" ASL statement
+ and initially contain a "ResourceTemplate ()".
+ - returned through the NewRdNode parameter.
+
+ @param [in] InitialBaudRate Initial baud rate.
+ @param [in] BitsPerByte Number of bits per byte.
+ Optional, default is 8.
+ @param [in] StopBits Number of stop bits.
+ Optional, default is 1.
+ @param [in] LinesInUse Number of lines in use.
+ @param [in] IsBigEndian Indicates whether the bit transfer is big-endian.
+ Optional, default is FALSE (little-endian).
+ @param [in] Parity Parity format used.
+ Optional, default is no parity.
+ @param [in] FlowControl Flow control protocol used.
+ Optional, default is no flow control.
+ @param [in] ReceiveBufferSize Size of the receive buffer.
+ @param [in] TransmitBufferSize Size of the transmit buffer.
+ @param [in] ResourceSource Name of source resource used.
+ @param [in] ResourceSourceLength Length of the Resource Source.
+ @param [in] ResourceSourceIndex Resource Source index.
+ Optional, default is 0.
+ @param [in] ResourceUsage Resource usage, TRUE for consumer,
+ FALSE for producer.
+ Optional, default is TRUE (consumer).
+ @param [in] IsShared Indicates whether the resource is shared.
+ Optional, default is FALSE (exclusive).
+ @param [in] VendorDefinedData Vendor defined data.
+ Optional, can be NULL.
+ @param [in] VendorDefinedDataLength Length of the vendor defined data.
+ @param [in] NameOpNode NameOp object node defining a named object.
+ If provided, append the new resource data
+ node to the list of resource data elements
+ of this node.
+ @param [out] NewRdNode If provided and success,
+ contain the created node.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval various Various failure values of called functions.
+**/
+EFI_STATUS
+EFIAPI
+AmlCodeGenRdUartSerialBusV2 (
+ IN UINT32 InitialBaudRate,
+ IN UINT8 *BitsPerByte OPTIONAL,
+ IN UINT8 *StopBits OPTIONAL,
+ IN UINT8 LinesInUse,
+ IN BOOLEAN *IsBigEndian OPTIONAL,
+ IN UINT8 *Parity OPTIONAL,
+ IN UINT8 *FlowControl OPTIONAL,
+ IN UINT16 ReceiveBufferSize,
+ IN UINT16 TransmitBufferSize,
+ IN CHAR8 *ResourceSource,
+ IN UINT16 ResourceSourceLength,
+ IN UINT8 *ResourceSourceIndex OPTIONAL,
+ IN BOOLEAN *ResourceUsage OPTIONAL,
+ IN BOOLEAN *IsShared OPTIONAL,
+ IN UINT8 *VendorDefinedData OPTIONAL,
+ IN UINT16 VendorDefinedDataLength,
+ IN AML_OBJECT_NODE_HANDLE NameOpNode OPTIONAL,
+ OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL
+ )
+{
+ EFI_STATUS Status;
+
+ if ((NameOpNode == NULL) && (NewRdNode == NULL)) {
+ ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (((VendorDefinedData == NULL) && (VendorDefinedDataLength > 0)) ||
+ ((VendorDefinedData != NULL) && (VendorDefinedDataLength == 0)))
+ {
+ ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if ((ResourceSource == NULL) || (ResourceSourceLength <= 0)) {
+ ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (ResourceSourceIndex != NULL) {
+ if (*ResourceSourceIndex != 0) {
+ ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
+ return EFI_INVALID_PARAMETER;
+ }
+ }
+
+ Status = AmlCodeGenRdUartSerialBus (
+ /// default is resource consumer
+ (ResourceUsage != NULL) ? *ResourceUsage : TRUE,
+ /// slave mode
+ TRUE,
+ /// default is little-endian
+ (IsBigEndian != NULL) ? *IsBigEndian : FALSE,
+ /// default is 8 bits per byte
+ (BitsPerByte != NULL) ? *BitsPerByte : 8,
+ /// default is 1 stop bit
+ (StopBits != NULL) ? *StopBits : EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_TSF_STOP_BIT_1,
+ /// default is no flow control
+ (FlowControl != NULL) ? *FlowControl : EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_TSF_FC_NONE,
+ InitialBaudRate,
+ ReceiveBufferSize,
+ TransmitBufferSize,
+ /// default is no parity
+ (Parity != NULL) ? *Parity : EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_PARITY_NONE,
+ LinesInUse,
+ VendorDefinedData,
+ VendorDefinedDataLength,
+ ResourceSource,
+ ResourceSourceLength,
+ NameOpNode,
+ NewRdNode
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT_EFI_ERROR (Status);
+ return Status;
+ }
+
+ return Status;
+}
diff --git a/DynamicTablesPkg/Library/Common/Tpm2DeviceTableLib/Tpm2DeviceTableLib.c b/DynamicTablesPkg/Library/Common/Tpm2DeviceTableLib/Tpm2DeviceTableLib.c
new file mode 100644
index 0000000..22bd001
--- /dev/null
+++ b/DynamicTablesPkg/Library/Common/Tpm2DeviceTableLib/Tpm2DeviceTableLib.c
@@ -0,0 +1,329 @@
+/** @file
+ Tpm2 device table generating Library
+
+ Copyright (c) 2025, Arm Limited. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - TCG ACPI specification.
+ (https://trustedcomputinggroup.org/resource/tcg-acpi-specification/)
+**/
+#include <IndustryStandard/DebugPort2Table.h>
+#include <Library/AcpiLib.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
+
+#include <Protocol/AcpiTable.h>
+
+// Module specific include files.
+#include <AcpiTableGenerator.h>
+#include <ConfigurationManagerObject.h>
+#include <ConfigurationManagerHelper.h>
+#include <Library/AcpiHelperLib.h>
+#include <Library/AmlLib/AmlLib.h>
+#include <Protocol/ConfigurationManagerProtocol.h>
+
+/** C array containing the compiled AML template.
+ This symbol is defined in the auto generated C file
+ containing the AML bytecode array.
+*/
+extern CHAR8 tpm2devicetabletemplate_aml_code[];
+
+/** Fixup the TPM2 device UID (_UID).
+
+ @param [in] RootNodeHandle Pointer to the root of an AML tree.
+ @param [in] Uid UID for the TPM2 device.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Could not find information.
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+FixupTpm2DeviceUid (
+ IN AML_ROOT_NODE_HANDLE RootNodeHandle,
+ IN CONST UINT64 Uid
+ )
+{
+ EFI_STATUS Status;
+ AML_OBJECT_NODE_HANDLE NameOpIdNode;
+
+ // Get the _UID NameOp object defined by the "Name ()" statement,
+ // and update its value.
+ Status = AmlFindNode (
+ RootNodeHandle,
+ "\\_SB_.TPM0._UID",
+ &NameOpIdNode
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ return AmlNameOpUpdateInteger (NameOpIdNode, (UINT64)Uid);
+}
+
+/** Fixup the Tpm2 device name.
+
+ @param [in] RootNodeHandle Pointer to the root of an AML tree.
+ @param [in] Name The Name to give to the Device.
+ Must be a NULL-terminated ASL NameString
+ e.g.: "DEV0", "DV15.DEV0", etc.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Could not find information.
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+FixupTpm2DeviceName (
+ IN AML_ROOT_NODE_HANDLE RootNodeHandle,
+ IN CONST CHAR8 *Name
+ )
+{
+ EFI_STATUS Status;
+ AML_OBJECT_NODE_HANDLE DeviceNode;
+
+ // Get the COM0 variable defined by the "Device ()" statement.
+ Status = AmlFindNode (RootNodeHandle, "\\_SB_.TPM0", &DeviceNode);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ // Update the Device's name.
+ return AmlDeviceOpUpdateName (DeviceNode, Name);
+}
+
+/** Fixup the Tpm2 device _CRS values (BaseAddress, ...).
+
+ @param [in] RootNodeHandle Pointer to the root of an AML tree.
+ @param [in] TpmDevInfo Pointer to a TPM2 device Information
+ structure.
+ Get the device size Information from there.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Could not find information.
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+FixupTpm2DeviceCrs (
+ IN AML_ROOT_NODE_HANDLE RootNodeHandle,
+ IN CONST CM_ARCH_COMMON_TPM2_DEVICE_INFO *TpmDevInfo
+ )
+{
+ EFI_STATUS Status;
+ AML_OBJECT_NODE_HANDLE NameOpCrsNode;
+ AML_DATA_NODE_HANDLE QWordRdNode;
+
+ // Get the "_CRS" object defined by the "Name ()" statement.
+ Status = AmlFindNode (
+ RootNodeHandle,
+ "\\_SB_.TPM0._CRS",
+ &NameOpCrsNode
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ // Get the first Rd node in the "_CRS" object.
+ Status = AmlNameOpGetFirstRdNode (NameOpCrsNode, &QWordRdNode);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ if (QWordRdNode == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ // Update the TPM2 device's base address and length.
+ Status = AmlUpdateRdQWord (
+ QWordRdNode,
+ TpmDevInfo->Tpm2DeviceBaseAddress,
+ TpmDevInfo->Tpm2DeviceSize
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ return Status;
+}
+
+/** Fixup the Tpm2 Device in the AML tree.
+
+ For each template value:
+ - find the node to update;
+ - update the value.
+
+ @param [in] RootNodeHandle Pointer to the root of the AML tree.
+ @param [in] TpmDevInfo Pointer to a TPM2 device Information
+ structure.
+ @param [in] Name The Name to give to the Device.
+ Must be a NULL-terminated ASL NameString
+ e.g.: "DEV0", "DV15.DEV0", etc.
+ @param [in] Uid UID for the TPM2 device.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Could not find information.
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+FixupTpm2DeviceInfo (
+ IN AML_ROOT_NODE_HANDLE RootNodeHandle,
+ IN CONST CM_ARCH_COMMON_TPM2_DEVICE_INFO *TpmDevInfo,
+ IN CONST CHAR8 *Name,
+ IN CONST UINT64 Uid
+ )
+{
+ EFI_STATUS Status;
+
+ ASSERT (RootNodeHandle != NULL);
+ ASSERT (TpmDevInfo != NULL);
+ ASSERT (Name != NULL);
+
+ // Fixup the _UID value.
+ Status = FixupTpm2DeviceUid (RootNodeHandle, Uid);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ // Fixup the _CRS values.
+ Status = FixupTpm2DeviceCrs (RootNodeHandle, TpmDevInfo);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ // Fixup the Tpm2 device name.
+ // This MUST be done at the end, otherwise AML paths won't be valid anymore.
+ return FixupTpm2DeviceName (RootNodeHandle, Name);
+}
+
+/** Build a SSDT table describing the TPM2 device.
+
+ The table created by this function must be freed by FreeSImpleTpm2DeviceTable.
+
+ @param [in] TpmDevInfo TPM2 device info to describe in the SSDT table.
+ @param [in] Name The Name to give to the Device.
+ Must be a NULL-terminated ASL NameString
+ e.g.: "DEV0", "DV15.DEV0", etc.
+ @param [in] Uid UID for the TPM2 device
+ @param [out] Table If success, pointer to the created SSDT table.
+
+ @retval EFI_SUCCESS Table generated successfully.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+ @retval EFI_NOT_FOUND Could not find information.
+ @retval EFI_OUT_OF_RESOURCES Could not allocate memory.
+**/
+EFI_STATUS
+EFIAPI
+BuildTpm2DeviceTable (
+ IN CONST CM_ARCH_COMMON_TPM2_DEVICE_INFO *TpmDevInfo,
+ IN CONST CHAR8 *Name,
+ IN CONST UINT64 Uid,
+ OUT EFI_ACPI_DESCRIPTION_HEADER **Table
+ )
+{
+ EFI_STATUS Status;
+ EFI_STATUS Status1;
+ AML_ROOT_NODE_HANDLE RootNodeHandle;
+
+ ASSERT (TpmDevInfo != NULL);
+ ASSERT (Name != NULL);
+ ASSERT (Table != NULL);
+
+ // Parse the Tpm2 Device Table Template.
+ Status = AmlParseDefinitionBlock (
+ (EFI_ACPI_DESCRIPTION_HEADER *)tpm2devicetabletemplate_aml_code,
+ &RootNodeHandle
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: TPM2-DEVICE-FIXUP:"
+ " Failed to parse SSDT TPM2 device Template. Status = %r\n",
+ Status
+ ));
+ return Status;
+ }
+
+ // Fixup the template values.
+ Status = FixupTpm2DeviceInfo (
+ RootNodeHandle,
+ TpmDevInfo,
+ Name,
+ Uid
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: TPM2-DEVICE-FIXUP: Failed to fixup SSDT TPM2 Device Table."
+ " Status = %r\n",
+ Status
+ ));
+ goto ExitHandler;
+ }
+
+ // Serialize the tree.
+ Status = AmlSerializeDefinitionBlock (
+ RootNodeHandle,
+ Table
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: TPM2-DEVICE-FIXUP: Failed to Serialize SSDT Table Data."
+ " Status = %r\n",
+ Status
+ ));
+ }
+
+ExitHandler:
+ // Cleanup
+ if (RootNodeHandle != NULL) {
+ Status1 = AmlDeleteTree (RootNodeHandle);
+ if (EFI_ERROR (Status1)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: TPM2-DEVICE-FIXUP: Failed to cleanup AML tree."
+ " Status = %r\n",
+ Status1
+ ));
+ // If Status was success but we failed to delete the AML Tree
+ // return Status1 else return the original error code, i.e. Status.
+ if (!EFI_ERROR (Status)) {
+ return Status1;
+ }
+ }
+ }
+
+ return Status;
+}
+
+/** Free an Tpm2 device table previously created by
+ the BuildTpm2DeviceTable function.
+
+ @param [in] Table Pointer to a Tpm2 Device table allocated by
+ the BuildTpm2DeviceTable function.
+
+**/
+VOID
+EFIAPI
+FreeTpm2DeviceTable (
+ IN EFI_ACPI_DESCRIPTION_HEADER *Table
+ )
+{
+ ASSERT (Table != NULL);
+ FreePool (Table);
+}
diff --git a/DynamicTablesPkg/Library/Common/Tpm2DeviceTableLib/Tpm2DeviceTableLib.inf b/DynamicTablesPkg/Library/Common/Tpm2DeviceTableLib/Tpm2DeviceTableLib.inf
new file mode 100644
index 0000000..6c69a9c
--- /dev/null
+++ b/DynamicTablesPkg/Library/Common/Tpm2DeviceTableLib/Tpm2DeviceTableLib.inf
@@ -0,0 +1,33 @@
+## @file
+# Tpm2 Device table generating library
+#
+# Copyright (c) 2025, Arm Limited. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x0001001B
+ BASE_NAME = DynamicTpm2DeviceTableLib
+ FILE_GUID = b09d0390-0400-11f0-a447-cfc17b482322
+ VERSION_STRING = 1.0
+ MODULE_TYPE = DXE_DRIVER
+ LIBRARY_CLASS = Tpm2DeviceTableLib
+
+[Sources]
+ Tpm2DeviceTableLib.c
+ Tpm2DeviceTableTemplate.asl
+
+[Packages.common]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ EmbeddedPkg/EmbeddedPkg.dec
+ DynamicTablesPkg/DynamicTablesPkg.dec
+
+[Packages.ARM, Packages.AARCH64]
+ ArmPkg/ArmPkg.dec
+
+[LibraryClasses]
+ AcpiHelperLib
+ AmlLib
+ BaseLib
diff --git a/DynamicTablesPkg/Library/Common/Tpm2DeviceTableLib/Tpm2DeviceTableTemplate.asl b/DynamicTablesPkg/Library/Common/Tpm2DeviceTableLib/Tpm2DeviceTableTemplate.asl
new file mode 100644
index 0000000..9b99767
--- /dev/null
+++ b/DynamicTablesPkg/Library/Common/Tpm2DeviceTableLib/Tpm2DeviceTableTemplate.asl
@@ -0,0 +1,44 @@
+/** @file
+ TPM2 Device Table Template
+
+ Copyright (c) 2025, ARM Ltd. All rights reserved.<BR>
+ All rights reserved.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s)
+ - TCG ACPI Specification
+ - TCG PC Client Platform Firmware Profile Specification
+
+ @par Glossary:
+ - {template} - Data fixed up using AML Fixup APIs.
+**/
+
+DefinitionBlock("Tpm2DeviceTableTemplate.aml", "SSDT", 2, "ARMLTD", "TPM2CRB", 1) {
+ Scope(_SB) {
+ Device (TPM0) { // {template}
+ Name (_HID, "MSFT0101")
+ Name (_UID, 0) // {template}
+ Name (_CRS, ResourceTemplate () {
+ QWordMemory (
+ ResourceProducer,
+ PosDecode,
+ MinFixed,
+ MaxFixed,
+ NonCacheable,
+ ReadWrite,
+ 0x0000000000000000, // Granularity
+ 0x00000000FFDFB000, // Range Minimum // {template}
+ 0x00000000FFDFFFFF, // Range Maximum // {template}
+ 0x0000000000000000, // Translation Offset
+ 0x0000000000005000, // Length // {template}
+ ,
+ ,
+ ,
+ AddressRangeReserved,
+ TypeStatic
+ ) // QWordMemory
+ }) // Name
+ } // Device
+ } // Scope(_SB)
+}
diff --git a/EmbeddedPkg/Include/Protocol/HardwareInterrupt2.h b/EmbeddedPkg/Include/Protocol/HardwareInterrupt2.h
index d017a9e..d5b2f15 100644
--- a/EmbeddedPkg/Include/Protocol/HardwareInterrupt2.h
+++ b/EmbeddedPkg/Include/Protocol/HardwareInterrupt2.h
@@ -11,10 +11,10 @@
#include <Protocol/HardwareInterrupt.h>
-// 22838932-1a2d-4a47-aaba-f3f7cf569470
+// 32898322-2da1-474a-baaa-f3f7cf569470
#define EFI_HARDWARE_INTERRUPT2_PROTOCOL_GUID \
- { 0x32898322, 0x2d1a, 0x474a, \
+ { 0x32898322, 0x2da1, 0x474a, \
{ 0xba, 0xaa, 0xf3, 0xf7, 0xcf, 0x56, 0x94, 0x70 } }
typedef enum {
diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c
index 8d12f93..71d267b 100644
--- a/MdeModulePkg/Core/Dxe/Image/Image.c
+++ b/MdeModulePkg/Core/Dxe/Image/Image.c
@@ -584,6 +584,9 @@ CoreLoadPeImage (
EFI_STATUS Status;
BOOLEAN DstBufAlocated;
UINTN Size;
+ UINTN Index;
+ UINTN StartIndex;
+ CHAR8 EfiFileName[512];
ZeroMem (&Image->ImageContext, sizeof (Image->ImageContext));
@@ -823,12 +826,6 @@ CoreLoadPeImage (
// Print the load address and the PDB file name if it is available
//
- DEBUG_CODE_BEGIN ();
-
- UINTN Index;
- UINTN StartIndex;
- CHAR8 EfiFileName[256];
-
DEBUG ((
DEBUG_INFO | DEBUG_LOAD,
"Loading driver at 0x%11p EntryPoint=0x%11p ",
@@ -877,8 +874,6 @@ CoreLoadPeImage (
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "\n"));
- DEBUG_CODE_END ();
-
return EFI_SUCCESS;
Done:
diff --git a/MdeModulePkg/Core/Pei/Image/Image.c b/MdeModulePkg/Core/Pei/Image/Image.c
index cee9f09..f74406f 100644
--- a/MdeModulePkg/Core/Pei/Image/Image.c
+++ b/MdeModulePkg/Core/Pei/Image/Image.c
@@ -623,6 +623,10 @@ PeiLoadImageLoadImage (
UINT16 Machine;
EFI_SECTION_TYPE SearchType1;
EFI_SECTION_TYPE SearchType2;
+ CHAR8 *AsciiString;
+ CHAR8 EfiFileName[512];
+ UINTN Index;
+ UINTN StartIndex;
*EntryPoint = 0;
ImageSize = 0;
@@ -706,12 +710,6 @@ PeiLoadImageLoadImage (
*ImageSizeArg = ImageSize;
}
- DEBUG_CODE_BEGIN ();
- CHAR8 *AsciiString;
- CHAR8 EfiFileName[512];
- INT32 Index;
- INT32 StartIndex;
-
//
// Print debug message: Loading PEIM at 0x12345678 EntryPoint=0x12345688 Driver.efi
//
@@ -764,8 +762,6 @@ PeiLoadImageLoadImage (
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "%a", EfiFileName));
}
- DEBUG_CODE_END ();
-
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "\n"));
return EFI_SUCCESS;
diff --git a/MdeModulePkg/Core/PiSmmCore/Dispatcher.c b/MdeModulePkg/Core/PiSmmCore/Dispatcher.c
index bb789e5..2011db1 100644
--- a/MdeModulePkg/Core/PiSmmCore/Dispatcher.c
+++ b/MdeModulePkg/Core/PiSmmCore/Dispatcher.c
@@ -325,6 +325,9 @@ SmmLoadImage (
EFI_DEVICE_PATH_PROTOCOL *HandleFilePath;
EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
+ UINTN Index;
+ UINTN StartIndex;
+ CHAR8 EfiFileName[512];
PERF_LOAD_IMAGE_BEGIN (DriverEntry->ImageHandle);
@@ -664,12 +667,6 @@ SmmLoadImage (
// Print the load address and the PDB file name if it is available
//
- DEBUG_CODE_BEGIN ();
-
- UINTN Index;
- UINTN StartIndex;
- CHAR8 EfiFileName[256];
-
DEBUG ((
DEBUG_INFO | DEBUG_LOAD,
"Loading SMM driver at 0x%11p EntryPoint=0x%11p ",
@@ -718,8 +715,6 @@ SmmLoadImage (
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "\n"));
- DEBUG_CODE_END ();
-
//
// Free buffer allocated by Fv->ReadSection.
//
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index ed0b17e..0c0b1c6 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -1352,10 +1352,6 @@
# @Prompt Enable serial port cable detetion.
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialDetectCable|FALSE|BOOLEAN|0x00020006
- ## Base address of 16550 serial port registers in MMIO or I/O space. Default is 0x3F8.
- # @Prompt Base address of serial port registers.
- gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x03F8|UINT64|0x00020002
-
## Baud rate for the 16550 serial port. Default is 115200 baud.
# @Prompt Baud rate for serial port.
# @ValidList 0x80000001 | 921600, 460800, 230400, 115200, 57600, 38400, 19200, 9600, 7200, 4800, 3600, 2400, 2000, 1800, 1200, 600, 300, 150, 134, 110, 75, 50
@@ -1790,6 +1786,11 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiExposedTableVersions|0x20|UINT32|0x0001004c
[PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx]
+
+ ## Base address of 16550 serial port registers in MMIO or I/O space. Default is 0x3F8.
+ # @Prompt Base address of serial port registers.
+ gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x03F8|UINT64|0x00020002
+
## UART clock frequency is for the baud rate configuration.
# @Prompt Serial Port Clock Rate.
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate|1843200|UINT32|0x00010066
diff --git a/MdePkg/Include/IndustryStandard/Acpi50.h b/MdePkg/Include/IndustryStandard/Acpi50.h
index c98c35f..dd96ab5 100644
--- a/MdePkg/Include/IndustryStandard/Acpi50.h
+++ b/MdePkg/Include/IndustryStandard/Acpi50.h
@@ -132,6 +132,40 @@ typedef PACKED struct {
UINT16 DeviceSelection;
} EFI_ACPI_SERIAL_BUS_RESOURCE_SPI_DESCRIPTOR;
+/// Revision ID of serial bus uart descriptor
+#define EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_REVISION_ID 0x1
+
+/// Type specific flags
+#define EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_TSF_LITTLE_ENDIAN 0x0
+#define EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_TSF_BIG_ENDIAN 0x1
+#define EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_TSF_5_BITS_PER_BYTE 0x0
+#define EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_TSF_6_BITS_PER_BYTE 0x1
+#define EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_TSF_7_BITS_PER_BYTE 0x2
+#define EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_TSF_8_BITS_PER_BYTE 0x3
+#define EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_TSF_9_BITS_PER_BYTE 0x4
+#define EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_TSF_STOP_BIT_NONE 0x0
+#define EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_TSF_STOP_BIT_1 0x1
+#define EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_TSF_STOP_BIT_1_5 0x2
+#define EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_TSF_STOP_BIT_2 0x3
+#define EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_TSF_FC_NONE 0x0
+#define EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_TSF_FC_HW 0x1
+#define EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_TSF_FC_XON_XOFF 0x2
+
+/// Parity definitions
+#define EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_PARITY_NONE 0x0
+#define EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_PARITY_EVEN 0x1
+#define EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_PARITY_ODD 0x2
+#define EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_PARITY_MARK 0x3
+#define EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_PARITY_SPACE 0x4
+
+/// Serial lines in use bits
+#define EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_LIN_RTS BIT7
+#define EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_LIN_CTS BIT6
+#define EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_LIN_DTR BIT5
+#define EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_LIN_DSR BIT4
+#define EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_LIN_RI BIT3
+#define EFI_ACPI_5_0_SERIAL_BUS_RESOURCE_UART_DESCRIPTOR_LIN_DTD BIT2
+
///
/// Serial Bus Resource Descriptor (UART)
///
diff --git a/MdePkg/Include/IndustryStandard/Acpi66.h b/MdePkg/Include/IndustryStandard/Acpi66.h
index b951668..b7bc8ea 100644
--- a/MdePkg/Include/IndustryStandard/Acpi66.h
+++ b/MdePkg/Include/IndustryStandard/Acpi66.h
@@ -206,7 +206,7 @@ typedef struct {
/// FADT Version (as defined in ACPI 6.6 spec.)
///
#define EFI_ACPI_6_6_FIXED_ACPI_DESCRIPTION_TABLE_REVISION 0x06
-#define EFI_ACPI_6_6_FIXED_ACPI_DESCRIPTION_TABLE_MINOR_REVISION 0x05
+#define EFI_ACPI_6_6_FIXED_ACPI_DESCRIPTION_TABLE_MINOR_REVISION 0x06
//
// Fixed ACPI Description Table Preferred Power Management Profile
@@ -324,7 +324,7 @@ typedef struct {
///
/// MADT Revision (as defined in ACPI 6.6 spec.)
///
-#define EFI_ACPI_6_6_MULTIPLE_APIC_DESCRIPTION_TABLE_REVISION 0x06
+#define EFI_ACPI_6_6_MULTIPLE_APIC_DESCRIPTION_TABLE_REVISION 0x07
///
/// Multiple APIC Flags
@@ -361,6 +361,10 @@ typedef struct {
#define EFI_ACPI_6_6_MSI_PIC 0x15
#define EFI_ACPI_6_6_BIO_PIC 0x16
#define EFI_ACPI_6_6_LPC_PIC 0x17
+#define EFI_ACPI_6_6_RINTC 0x18
+#define EFI_ACPI_6_6_IMSIC 0x19
+#define EFI_ACPI_6_6_APLIC 0x1A
+#define EFI_ACPI_6_6_PLIC 0x1B
//
// APIC Structure Definitions
@@ -746,6 +750,83 @@ typedef struct {
} EFI_ACPI_6_6_LPC_PIC_STRUCTURE;
///
+/// RISC-V INTC (RINTC)
+///
+typedef struct {
+ UINT8 Type;
+ UINT8 Length;
+ UINT8 Version;
+ UINT8 Reserved;
+ UINT32 Flags;
+ UINT64 HartId;
+ UINT32 Uid;
+ UINT32 ExtIntcId;
+ UINT64 ImsicAddr;
+ UINT32 ImsicSize;
+} EFI_ACPI_6_6_RINTC_STRUCTURE;
+
+#define EFI_ACPI_6_6_RINTC_STRUCTURE_VERSION 1
+
+#define EFI_ACPI_6_6_RINTC_FLAG_ENABLE 1
+
+///
+/// RISC-V Incoming MSI Controller (IMSIC)
+///
+typedef struct {
+ UINT8 Type;
+ UINT8 Length;
+ UINT8 Version;
+ UINT8 Reserved;
+ UINT32 Flags;
+ UINT16 NumIds;
+ UINT16 NumGuestIds;
+ UINT8 GuestIndexBits;
+ UINT8 HartIndexBits;
+ UINT8 GroupIndexBits;
+ UINT8 GroupIndexShift;
+} EFI_ACPI_6_6_IMSIC_STRUCTURE;
+
+#define EFI_ACPI_6_6_IMSIC_STRUCTURE_VERSION 1
+
+///
+/// RISC-V APLIC
+///
+typedef struct {
+ UINT8 Type;
+ UINT8 Length;
+ UINT8 Version;
+ UINT8 Id;
+ UINT32 Flags;
+ UINT8 HwId[8];
+ UINT16 NumIdcs;
+ UINT16 NumSources;
+ UINT32 GsiBase;
+ UINT64 BaseAddr;
+ UINT32 Size;
+} EFI_ACPI_6_6_APLIC_STRUCTURE;
+
+#define EFI_ACPI_6_6_APLIC_STRUCTURE_VERSION 1
+
+///
+/// RISC-V PLIC
+///
+typedef struct {
+ UINT8 Type;
+ UINT8 Length;
+ UINT8 Version;
+ UINT8 Id;
+ UINT8 HwId[8];
+ UINT16 NumIrqs;
+ UINT16 MaxPrio;
+ UINT32 Flags;
+ UINT32 Size;
+ UINT64 BaseAddr;
+ UINT32 GsiBase;
+} EFI_ACPI_6_6_PLIC_STRUCTURE;
+
+#define EFI_ACPI_6_6_PLIC_STRUCTURE_VERSION 1
+
+///
/// Smart Battery Description Table (SBST)
///
typedef struct {
@@ -804,6 +885,8 @@ typedef struct {
#define EFI_ACPI_6_6_GICC_AFFINITY 0x03
#define EFI_ACPI_6_6_GIC_ITS_AFFINITY 0x04
#define EFI_ACPI_6_6_GENERIC_INITIATOR_AFFINITY 0x05
+#define EFI_ACPI_6_6_GENERIC_PORT_AFFINITY 0x06
+#define EFI_ACPI_6_6_RINTC_AFFINITY 0x07
///
/// Processor Local APIC/SAPIC Affinity Structure Definition
@@ -890,6 +973,19 @@ typedef struct {
UINT32 ItsId;
} EFI_ACPI_6_6_GIC_ITS_AFFINITY_STRUCTURE;
+///
+/// RINTC Affinity Structure Definition
+///
+typedef struct {
+ UINT8 Type;
+ UINT8 Length;
+ UINT16 Reserved;
+ UINT32 ProximityDomain;
+ UINT32 AcpiProcessorUid;
+ UINT32 Flags;
+ UINT32 ClockDomain;
+} EFI_ACPI_6_6_RINTC_AFFINITY_STRUCTURE;
+
//
// Generic Initiator Affinity Structure Device Handle Types
// All other values between 0x02 an 0xFF are reserved and
@@ -3024,6 +3120,86 @@ typedef struct {
#define EFI_ACPI_6_6_PHAT_RESET_REASON_REASON_POWER_LOSS 0x24
#define EFI_ACPI_6_6_PHAT_RESET_REASON_REASON_POWER_BUTTON 0x25
+typedef struct {
+ EFI_ACPI_DESCRIPTION_HEADER Header;
+ UINT32 Flags;
+ UINT64 TimeBaseFreq;
+ UINT32 NodeCount;
+ UINT32 NodeOffset;
+} EFI_ACPI_6_6_RISCV_HART_CAPABILITIES_TABLE;
+
+#define EFI_ACPI_6_6_RHCT_TABLE_REVISION 1
+//
+// RHCT Flags
+//
+#define EFI_ACPI_6_6_RHCT_FLAG_TIMER_CANNOT_WAKEUP_CPU 1
+
+//
+// RHCT subtables
+//
+typedef struct {
+ UINT16 Type;
+ UINT16 Length;
+ UINT16 Revision;
+} EFI_ACPI_6_6_RHCT_NODE_HEADER;
+
+/* Values for RHCT subtable Type above */
+#define EFI_ACPI_6_6_RHCT_NODE_TYPE_ISA_STRING 0x0000
+#define EFI_ACPI_6_6_RHCT_NODE_TYPE_CMO 0x0001
+#define EFI_ACPI_6_6_RHCT_NODE_TYPE_MMU 0x0002
+#define EFI_ACPI_6_6_RHCT_NODE_TYPE_HART_INFO 0xFFFF
+
+//
+// ISA string node structure
+//
+typedef struct {
+ EFI_ACPI_6_6_RHCT_NODE_HEADER Node;
+ UINT16 IsaLength;
+ char Isa[];
+} EFI_ACPI_6_6_RHCT_ISA_STRING_NODE;
+
+#define EFI_ACPI_6_6_RHCT_ISA_NODE_STRUCTURE_VERSION 1
+
+//
+// CMO node structure
+//
+typedef struct {
+ EFI_ACPI_6_6_RHCT_NODE_HEADER Node;
+ UINT8 Reserved;
+ UINT8 CbomBlockSize;
+ UINT8 CbopBlockSize;
+ UINT8 CbozBlockSize;
+} EFI_ACPI_6_6_RHCT_CMO_NODE;
+
+#define EFI_ACPI_6_6_RHCT_CMO_NODE_STRUCTURE_VERSION 1
+
+//
+// MMU node structure
+//
+typedef struct {
+ EFI_ACPI_6_6_RHCT_NODE_HEADER Node;
+ UINT8 Reserved;
+ UINT8 MmuType;
+} EFI_ACPI_6_6_RHCT_MMU_NODE;
+
+#define EFI_ACPI_6_6_RHCT_MMU_NODE_STRUCTURE_VERSION 1
+
+#define EFI_ACPI_6_6_RHCT_MMU_TYPE_SV39 0
+#define EFI_ACPI_6_6_RHCT_MMU_TYPE_SV48 1
+#define EFI_ACPI_6_6_RHCT_MMU_TYPE_SV57 2
+
+//
+// Hart Info node structure
+//
+typedef struct {
+ EFI_ACPI_6_6_RHCT_NODE_HEADER Node;
+ UINT16 NumOffsets;
+ UINT32 Uid;
+ UINT32 Offsets[];
+} EFI_ACPI_6_6_RHCT_HART_INFO_NODE;
+
+#define EFI_ACPI_6_6_RHCT_HART_INFO_NODE_STRUCTURE_VERSION 1
+
//
// Known table signatures
//
@@ -3284,6 +3460,10 @@ typedef struct {
#define EFI_ACPI_6_6_PLATFORM_HEALTH_ASSESSMENT_TABLE_SIGNATURE SIGNATURE_32('P', 'H', 'A', 'T')
///
+/// "RHCT" RISC-V Hart Capabilities Table (RHCT)
+///
+#define EFI_ACPI_6_6_RISCV_HART_CAPABILITIES_TABLE_SIGNATURE SIGNATURE_32('R', 'H', 'C', 'T')
+///
/// "SDEI" Software Delegated Exceptions Interface Table
///
#define EFI_ACPI_6_6_SOFTWARE_DELEGATED_EXCEPTIONS_INTERFACE_TABLE_SIGNATURE SIGNATURE_32('S', 'D', 'E', 'I')
diff --git a/OvmfPkg/CloudHv/CloudHvX64.dsc b/OvmfPkg/CloudHv/CloudHvX64.dsc
index d941d6d..157aa8e 100644
--- a/OvmfPkg/CloudHv/CloudHvX64.dsc
+++ b/OvmfPkg/CloudHv/CloudHvX64.dsc
@@ -628,7 +628,7 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack|FALSE
# UefiCpuPkg PCDs related to initial AP bringup and general AP management.
- gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber|64
+ gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber|254
gUefiCpuPkgTokenSpaceGuid.PcdCpuBootLogicalProcessorNumber|0
# Set memory encryption mask
diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf b/OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf
index ebcc7e2..0996968 100644
--- a/OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf
+++ b/OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf
@@ -42,6 +42,7 @@
BaseMemoryLib
CpuLib
DebugLib
+ HobLib
LocalApicLib
MmServicesTableLib
PcdLib
@@ -53,6 +54,9 @@
gEfiMmCpuIoProtocolGuid ## CONSUMES
gEfiSmmCpuServiceProtocolGuid ## CONSUMES
+[Guids]
+ gUefiOvmfPkgPlatformInfoGuid ## CONSUMES
+
[Pcd]
gUefiCpuPkgTokenSpaceGuid.PcdCpuHotPlugDataAddress ## CONSUMES
gUefiOvmfPkgTokenSpaceGuid.PcdCpuHotEjectDataAddress ## CONSUMES
diff --git a/OvmfPkg/CpuHotplugSmm/FirstSmiHandler.nasm b/OvmfPkg/CpuHotplugSmm/FirstSmiHandler.nasm
index 5399b5f..b38f94c 100644
--- a/OvmfPkg/CpuHotplugSmm/FirstSmiHandler.nasm
+++ b/OvmfPkg/CpuHotplugSmm/FirstSmiHandler.nasm
@@ -41,9 +41,12 @@ SMM_DEFAULT_SMBASE: equ 0x3_0000
; Field offsets in FIRST_SMI_HANDLER_CONTEXT, which resides at
; SMM_DEFAULT_SMBASE.
;
-ApicIdGate: equ 0 ; UINT64
-NewSmbase: equ 8 ; UINT32
-AboutToLeaveSmm: equ 12 ; UINT8
+ApicIdGate: equ 0 ; UINT64
+NewSmbase: equ 8 ; UINT32
+FeatureControlHighValue: equ 12 ; UINT32
+FeatureControlLowValue: equ 16 ; UINT32
+FeatureControl: equ 20 ; UINT8
+AboutToLeaveSmm: equ 21 ; UINT8
;
; SMRAM Save State Map field offsets, per the AMD (not Intel) layout that QEMU
@@ -60,6 +63,11 @@ CPUID_SIGNATURE: equ 0x00
CPUID_EXTENDED_TOPOLOGY: equ 0x0B
CPUID_VERSION_INFO: equ 0x01
+;
+; MSR constants, from "MdePkg/Include/Register/Intel/ArchitecturalMsr.h".
+;
+MSR_IA32_FEATURE_CONTROL: equ 0x0000003A
+
GLOBAL ASM_PFX (mFirstSmiHandler) ; UINT8[]
GLOBAL ASM_PFX (mFirstSmiHandlerSize) ; UINT16
@@ -141,6 +149,18 @@ UpdateSmbase:
; Save it to the SMBASE field whose address we calculated in EBX.
;
mov dword [ds : dword ebx], eax
+
+ ;
+ ; Set MSR_IA32_FEATURE_CONTROL if requested.
+ ;
+ cmp byte [ds : dword (SMM_DEFAULT_SMBASE + FeatureControl)], 0
+ je NoFeatureControl
+ mov ecx, MSR_IA32_FEATURE_CONTROL
+ mov edx, dword [ds : dword (SMM_DEFAULT_SMBASE + FeatureControlHighValue)]
+ mov eax, dword [ds : dword (SMM_DEFAULT_SMBASE + FeatureControlLowValue)]
+ wrmsr
+
+NoFeatureControl:
;
; Set AboutToLeaveSmm.
;
diff --git a/OvmfPkg/CpuHotplugSmm/FirstSmiHandlerContext.h b/OvmfPkg/CpuHotplugSmm/FirstSmiHandlerContext.h
index 6039532..0c6deed 100644
--- a/OvmfPkg/CpuHotplugSmm/FirstSmiHandlerContext.h
+++ b/OvmfPkg/CpuHotplugSmm/FirstSmiHandlerContext.h
@@ -36,6 +36,14 @@ typedef struct {
//
UINT32 NewSmbase;
//
+ // The High:Low value for the hot-added CPU to store in
+ // MSR_IA32_FEATURE_CONTROL, assuming MSR_IA32_FEATURE_CONTROL setting is
+ // enabled (i.e., if "FeatureControl" is nonzero).
+ //
+ UINT32 FeatureControlHighValue;
+ UINT32 FeatureControlLowValue;
+ UINT8 FeatureControl;
+ //
// The hot-added CPU sets this field to 1 right before executing the RSM
// instruction. This tells the SMM Monarch to proceed to polling the last
// byte of the normal RAM reserved page (Post-SMM Pen).
diff --git a/OvmfPkg/CpuHotplugSmm/Smbase.c b/OvmfPkg/CpuHotplugSmm/Smbase.c
index dc6f4f4..433633d 100644
--- a/OvmfPkg/CpuHotplugSmm/Smbase.c
+++ b/OvmfPkg/CpuHotplugSmm/Smbase.c
@@ -10,7 +10,9 @@
#include <Library/BaseLib.h> // CpuPause()
#include <Library/BaseMemoryLib.h> // CopyMem()
#include <Library/DebugLib.h> // DEBUG()
+#include <Library/HobLib.h> // GetFirstGuidHob()
#include <Library/LocalApicLib.h> // SendInitSipiSipi()
+#include <Library/PlatformInitLib.h> // EFI_HOB_PLATFORM_INFO
#include <Library/SynchronizationLib.h> // InterlockedCompareExchange64()
#include <Register/Intel/SmramSaveStateMap.h> // SMM_DEFAULT_SMBASE
@@ -132,7 +134,10 @@ SmbaseReleasePostSmmPen (
Note that this effects an "SMRAM to SMRAM" copy.
- Additionally, shut the APIC ID gate in FIRST_SMI_HANDLER_CONTEXT.
+ Additionally, shut the APIC ID gate in FIRST_SMI_HANDLER_CONTEXT, and prepare
+ for configuring MSR_IA32_FEATURE_CONTROL. (The latter depends on a GUID HOB,
+ which does not live in SMRAM; however, if we can't trust the HOB list at this
+ stage, we're doomed anyway.)
This function may only be called from the entry point function of the driver,
and only after PcdQ35SmramAtDefaultSmbase has been determined to be TRUE.
@@ -143,6 +148,7 @@ SmbaseInstallFirstSmiHandler (
)
{
FIRST_SMI_HANDLER_CONTEXT *Context;
+ EFI_HOB_GUID_TYPE *GuidHob;
CopyMem (
(VOID *)(UINTN)(SMM_DEFAULT_SMBASE + SMM_HANDLER_OFFSET),
@@ -152,6 +158,22 @@ SmbaseInstallFirstSmiHandler (
Context = (VOID *)(UINTN)SMM_DEFAULT_SMBASE;
Context->ApicIdGate = MAX_UINT64;
+
+ Context->FeatureControl = 0;
+ GuidHob = GetFirstGuidHob (&gUefiOvmfPkgPlatformInfoGuid);
+ if (GuidHob != NULL) {
+ EFI_HOB_PLATFORM_INFO *Info;
+
+ Info = GET_GUID_HOB_DATA (GuidHob);
+ if (Info->FeatureControl) {
+ Context->FeatureControlHighValue = (UINT32)RShiftU64 (
+ Info->FeatureControlValue,
+ 32
+ );
+ Context->FeatureControlLowValue = (UINT32)Info->FeatureControlValue;
+ Context->FeatureControl = 1;
+ }
+ }
}
/**
diff --git a/OvmfPkg/Include/Library/PlatformInitLib.h b/OvmfPkg/Include/Library/PlatformInitLib.h
index 2d9c662..dc0c280 100644
--- a/OvmfPkg/Include/Library/PlatformInitLib.h
+++ b/OvmfPkg/Include/Library/PlatformInitLib.h
@@ -64,6 +64,7 @@ typedef struct {
UINT32 S3AcpiReservedMemoryBase;
UINT32 S3AcpiReservedMemorySize;
+ BOOLEAN FeatureControl;
UINT64 FeatureControlValue;
BOOLEAN QemuFwCfgChecked;
diff --git a/OvmfPkg/PlatformPei/FeatureControl.c b/OvmfPkg/PlatformPei/FeatureControl.c
index d2ec496..749a07c 100644
--- a/OvmfPkg/PlatformPei/FeatureControl.c
+++ b/OvmfPkg/PlatformPei/FeatureControl.c
@@ -143,6 +143,7 @@ InstallFeatureControlCallback (
return;
}
+ PlatformInfoHob->FeatureControl = TRUE;
QemuFwCfgSelectItem (FwCfgItem);
QemuFwCfgReadBytes (
sizeof (PlatformInfoHob->FeatureControlValue),
diff --git a/OvmfPkg/RiscVVirt/Library/PlatformSecLib/SecEntry.S b/OvmfPkg/RiscVVirt/Library/PlatformSecLib/SecEntry.S
index de42a90..b52becd 100644
--- a/OvmfPkg/RiscVVirt/Library/PlatformSecLib/SecEntry.S
+++ b/OvmfPkg/RiscVVirt/Library/PlatformSecLib/SecEntry.S
@@ -8,6 +8,9 @@
#include "PlatformSecLib.h"
ASM_FUNC (_ModuleEntryPoint)
+/* Prevent stack unwinding from going further */
+li s0, 0
+
/* Use Temp memory as the stack for calling to C code */
li a2, FixedPcdGet32 (PcdOvmfSecPeiTempRamBase)
li a3, FixedPcdGet32 (PcdOvmfSecPeiTempRamSize)
diff --git a/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc b/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc
index 4c3eff7..47248f2 100644
--- a/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc
+++ b/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc
@@ -79,7 +79,6 @@
!endif
# RISC-V Architectural Libraries
- CpuExceptionHandlerLib|UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandlerLib.inf
RiscVSbiLib|MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.inf
RiscVMmuLib|UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.inf
PlatformBootManagerLib|OvmfPkg/RiscVVirt/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
@@ -153,6 +152,7 @@
PrePiHobListPointerLib|OvmfPkg/RiscVVirt/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf
PrePiLib|EmbeddedPkg/Library/PrePiLib/PrePiLib.inf
MemoryAllocationLib|EmbeddedPkg/Library/PrePiMemoryAllocationLib/PrePiMemoryAllocationLib.inf
+ CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
[LibraryClasses.common.PEI_CORE]
HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf
@@ -163,6 +163,7 @@
ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf
PeiResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf
ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf
+ CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
[LibraryClasses.common.PEIM]
HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf
@@ -174,16 +175,19 @@
ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf
PeiResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf
ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf
+ CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
[LibraryClasses.common.DXE_CORE]
PerformanceLib|MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.inf
HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf
MemoryAllocationLib|MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.inf
DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf
+ CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
[LibraryClasses.common.DXE_DRIVER]
SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
+ CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
[LibraryClasses.common.UEFI_APPLICATION]
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
diff --git a/OvmfPkg/Tcg/TdTcg2Dxe/TdTcg2Dxe.c b/OvmfPkg/Tcg/TdTcg2Dxe/TdTcg2Dxe.c
index 5287cda..8547c76 100644
--- a/OvmfPkg/Tcg/TdTcg2Dxe/TdTcg2Dxe.c
+++ b/OvmfPkg/Tcg/TdTcg2Dxe/TdTcg2Dxe.c
@@ -806,6 +806,7 @@ TdGetEventLog (
@retval FALSE This is NOT a Tcg800155PlatformIdEvent.
**/
+STATIC
BOOLEAN
Is800155Event (
IN VOID *NewEventHdr,
@@ -814,18 +815,26 @@ Is800155Event (
IN UINT32 NewEventSize
)
{
- if ((((TCG_PCR_EVENT2_HDR *)NewEventHdr)->EventType == EV_NO_ACTION) &&
- (NewEventSize >= sizeof (TCG_Sp800_155_PlatformId_Event2)) &&
- ((CompareMem (
- NewEventData,
- TCG_Sp800_155_PlatformId_Event2_SIGNATURE,
- sizeof (TCG_Sp800_155_PlatformId_Event2_SIGNATURE) - 1
- ) == 0) ||
- (CompareMem (
- NewEventData,
- TCG_Sp800_155_PlatformId_Event3_SIGNATURE,
- sizeof (TCG_Sp800_155_PlatformId_Event3_SIGNATURE) - 1
- ) == 0)))
+ if (((TCG_PCR_EVENT2_HDR *)NewEventHdr)->EventType != EV_NO_ACTION) {
+ return FALSE;
+ }
+
+ if ((NewEventSize >= sizeof (TCG_Sp800_155_PlatformId_Event2)) &&
+ (CompareMem (
+ NewEventData,
+ TCG_Sp800_155_PlatformId_Event2_SIGNATURE,
+ sizeof (TCG_Sp800_155_PlatformId_Event2_SIGNATURE) - 1
+ ) == 0))
+ {
+ return TRUE;
+ }
+
+ if ((NewEventSize >= sizeof (TCG_Sp800_155_PlatformId_Event3)) &&
+ (CompareMem (
+ NewEventData,
+ TCG_Sp800_155_PlatformId_Event3_SIGNATURE,
+ sizeof (TCG_Sp800_155_PlatformId_Event3_SIGNATURE) - 1
+ ) == 0))
{
return TRUE;
}
diff --git a/SecurityPkg/FvReportPei/FvReportPei.c b/SecurityPkg/FvReportPei/FvReportPei.c
index 50773db..4376f52 100644
--- a/SecurityPkg/FvReportPei/FvReportPei.c
+++ b/SecurityPkg/FvReportPei/FvReportPei.c
@@ -71,7 +71,10 @@ InstallPreHashFvPpi (
+ HashSize;
PreHashedFvPpi = AllocatePool (PpiSize);
- ASSERT (PreHashedFvPpi != NULL);
+ if (PreHashedFvPpi == NULL) {
+ ASSERT (PreHashedFvPpi != NULL);
+ return;
+ }
PreHashedFvPpi->FvBase = (UINT32)(UINTN)FvBuffer;
PreHashedFvPpi->FvLength = (UINT32)FvLength;
@@ -83,7 +86,11 @@ InstallPreHashFvPpi (
CopyMem (HASH_VALUE_PTR (HashInfo), HashValue, HashSize);
FvInfoPpiDescriptor = AllocatePool (sizeof (EFI_PEI_PPI_DESCRIPTOR));
- ASSERT (FvInfoPpiDescriptor != NULL);
+ if (FvInfoPpiDescriptor == NULL) {
+ ASSERT (FvInfoPpiDescriptor != NULL);
+ FreePool (PreHashedFvPpi);
+ return;
+ }
FvInfoPpiDescriptor->Guid = &gEdkiiPeiFirmwareVolumeInfoPrehashedFvPpiGuid;
FvInfoPpiDescriptor->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
@@ -202,8 +209,11 @@ VerifyHashedFv (
// Copy FV to permanent memory to avoid potential TOC/TOU.
//
FvBuffer = AllocatePages (EFI_SIZE_TO_PAGES ((UINTN)FvInfo[FvIndex].Length));
-
- ASSERT (FvBuffer != NULL);
+ if (FvBuffer == NULL) {
+ ASSERT (FvBuffer != NULL);
+ Status = EFI_OUT_OF_RESOURCES;
+ goto Done;
+ }
if (FvShadowPpi != NULL) {
Status = FvShadowPpi->FirmwareVolumeShadow (
@@ -379,12 +389,17 @@ CheckStoredHashFv (
);
if (!EFI_ERROR (Status) && (StoredHashFvPpi != NULL) && (StoredHashFvPpi->FvNumber > 0)) {
HashInfo = GetHashInfo (StoredHashFvPpi, BootMode);
- Status = VerifyHashedFv (
+ if (HashInfo != NULL) {
+ Status = VerifyHashedFv (
HashInfo,
StoredHashFvPpi->FvInfo,
StoredHashFvPpi->FvNumber,
BootMode
);
+ } else {
+ Status = EFI_NOT_FOUND;
+ }
+
if (!EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "OBB verification passed (%r)\r\n", Status));
diff --git a/SecurityPkg/HddPassword/HddPasswordDxe.c b/SecurityPkg/HddPassword/HddPasswordDxe.c
index 6f36b5a..228a9f4 100644
--- a/SecurityPkg/HddPassword/HddPasswordDxe.c
+++ b/SecurityPkg/HddPassword/HddPasswordDxe.c
@@ -149,7 +149,10 @@ BuildHddPasswordDeviceInfo (
S3InitDevicesExist = FALSE;
} else if (Status == EFI_BUFFER_TOO_SMALL) {
S3InitDevices = AllocatePool (S3InitDevicesLength);
- ASSERT (S3InitDevices != NULL);
+ if (S3InitDevices == NULL) {
+ ASSERT (S3InitDevices != NULL);
+ return;
+ }
Status = RestoreLockBox (
&gS3StorageDeviceInitListGuid,
@@ -184,7 +187,10 @@ BuildHddPasswordDeviceInfo (
FreePool (S3InitDevicesBak);
}
- ASSERT (S3InitDevices != NULL);
+ if (S3InitDevices == NULL) {
+ ASSERT (S3InitDevices != NULL);
+ return;
+ }
TempDevInfo = (HDD_PASSWORD_DEVICE_INFO *)((UINTN)TempDevInfo +
sizeof (HDD_PASSWORD_DEVICE_INFO) +
@@ -2195,8 +2201,14 @@ HddPasswordFormExtractConfig (
// followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
//
ConfigRequestHdr = HiiConstructConfigHdr (&mHddPasswordVendorGuid, mHddPasswordVendorStorageName, Private->DriverHandle);
- Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
- ConfigRequest = AllocateZeroPool (Size);
+ if (ConfigRequestHdr == NULL) {
+ ASSERT (ConfigRequestHdr != NULL);
+ FreePool (IfrData);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
+ ConfigRequest = AllocateZeroPool (Size);
ASSERT (ConfigRequest != NULL);
AllocatedRequest = TRUE;
UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);
@@ -2386,7 +2398,11 @@ HddPasswordFormCallback (
// In case goto the device configuration form, update the device form title.
//
ConfigFormEntry = HddPasswordGetConfigFormEntryByIndex ((UINT32)(QuestionId - KEY_HDD_DEVICE_ENTRY_BASE));
- ASSERT (ConfigFormEntry != NULL);
+ if (ConfigFormEntry == NULL) {
+ ASSERT (ConfigFormEntry != NULL);
+ FreePool (IfrData);
+ return EFI_NOT_FOUND;
+ }
DeviceFormTitleToken = (EFI_STRING_ID)STR_HDD_SECURITY_HD;
HiiSetString (Private->HiiHandle, DeviceFormTitleToken, ConfigFormEntry->HddString, NULL);
diff --git a/SecurityPkg/Library/AuthVariableLib/AuthService.c b/SecurityPkg/Library/AuthVariableLib/AuthService.c
index 706cb67..2d79cc1 100644
--- a/SecurityPkg/Library/AuthVariableLib/AuthService.c
+++ b/SecurityPkg/Library/AuthVariableLib/AuthService.c
@@ -553,7 +553,7 @@ CheckSignatureListFormat (
// Walk through the input signature list and check the data format.
// If any signature is incorrectly formed, the whole check will fail.
//
- while ((SigDataSize > 0) && (SigDataSize >= SigList->SignatureListSize)) {
+ while ((SigDataSize > 0) && (SigDataSize >= (UINTN)SigList->SignatureListSize)) {
for (Index = 0; Index < (sizeof (mSupportSigItem) / sizeof (EFI_SIGNATURE_ITEM)); Index++ ) {
if (CompareGuid (&SigList->SignatureType, &mSupportSigItem[Index].SigType)) {
//
@@ -1088,7 +1088,7 @@ FilterSignatureList (
Tail = TempData;
NewCertList = (EFI_SIGNATURE_LIST *)NewData;
- while ((*NewDataSize > 0) && (*NewDataSize >= NewCertList->SignatureListSize)) {
+ while ((*NewDataSize > 0) && (*NewDataSize >= (UINTN)NewCertList->SignatureListSize)) {
NewCert = (EFI_SIGNATURE_DATA *)((UINT8 *)NewCertList + sizeof (EFI_SIGNATURE_LIST) + NewCertList->SignatureHeaderSize);
NewCertCount = (NewCertList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - NewCertList->SignatureHeaderSize) / NewCertList->SignatureSize;
@@ -1098,7 +1098,7 @@ FilterSignatureList (
Size = DataSize;
CertList = (EFI_SIGNATURE_LIST *)Data;
- while ((Size > 0) && (Size >= CertList->SignatureListSize)) {
+ while ((Size > 0) && (Size >= (UINTN)CertList->SignatureListSize)) {
if (CompareGuid (&CertList->SignatureType, &NewCertList->SignatureType) &&
(CertList->SignatureSize == NewCertList->SignatureSize))
{
diff --git a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c
index 2eca39d..23e25a4 100644
--- a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c
+++ b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c
@@ -883,7 +883,7 @@ IsCertHashFoundInDbx (
return Status;
}
- while ((DbxSize > 0) && (SignatureListSize >= DbxList->SignatureListSize)) {
+ while ((DbxSize > 0) && (SignatureListSize >= (UINTN)DbxList->SignatureListSize)) {
//
// Determine Hash Algorithm of Certificate in the forbidden database.
//
@@ -1028,7 +1028,7 @@ IsSignatureFoundInDatabase (
// Enumerate all signature data in SigDB to check if signature exists for executable.
//
CertList = (EFI_SIGNATURE_LIST *)Data;
- while ((DataSize > 0) && (DataSize >= CertList->SignatureListSize)) {
+ while ((DataSize > 0) && (DataSize >= (UINTN)CertList->SignatureListSize)) {
CertCount = (CertList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - CertList->SignatureHeaderSize) / CertList->SignatureSize;
Cert = (EFI_SIGNATURE_DATA *)((UINT8 *)CertList + sizeof (EFI_SIGNATURE_LIST) + CertList->SignatureHeaderSize);
if ((CertList->SignatureSize == sizeof (EFI_SIGNATURE_DATA) - 1 + SignatureSize) && (CompareGuid (&CertList->SignatureType, CertType))) {
@@ -1193,7 +1193,7 @@ PassTimestampCheck (
}
CertList = (EFI_SIGNATURE_LIST *)DbtData;
- while ((DbtDataSize > 0) && (DbtDataSize >= CertList->SignatureListSize)) {
+ while ((DbtDataSize > 0) && (DbtDataSize >= (UINTN)CertList->SignatureListSize)) {
if (CompareGuid (&CertList->SignatureType, &gEfiCertX509Guid)) {
Cert = (EFI_SIGNATURE_DATA *)((UINT8 *)CertList + sizeof (EFI_SIGNATURE_LIST) + CertList->SignatureHeaderSize);
CertCount = (CertList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - CertList->SignatureHeaderSize) / CertList->SignatureSize;
@@ -1319,7 +1319,7 @@ IsForbiddenByDbx (
//
CertList = (EFI_SIGNATURE_LIST *)Data;
CertListSize = DataSize;
- while ((CertListSize > 0) && (CertListSize >= CertList->SignatureListSize)) {
+ while ((CertListSize > 0) && (CertListSize >= (UINTN)CertList->SignatureListSize)) {
if (CompareGuid (&CertList->SignatureType, &gEfiCertX509Guid)) {
CertData = (EFI_SIGNATURE_DATA *)((UINT8 *)CertList + sizeof (EFI_SIGNATURE_LIST) + CertList->SignatureHeaderSize);
CertCount = (CertList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - CertList->SignatureHeaderSize) / CertList->SignatureSize;
@@ -1524,7 +1524,7 @@ IsAllowedByDb (
// Find X509 certificate in Signature List to verify the signature in pkcs7 signed data.
//
CertList = (EFI_SIGNATURE_LIST *)Data;
- while ((DataSize > 0) && (DataSize >= CertList->SignatureListSize)) {
+ while ((DataSize > 0) && (DataSize >= (UINTN)CertList->SignatureListSize)) {
if (CompareGuid (&CertList->SignatureType, &gEfiCertX509Guid)) {
CertData = (EFI_SIGNATURE_DATA *)((UINT8 *)CertList + sizeof (EFI_SIGNATURE_LIST) + CertList->SignatureHeaderSize);
CertCount = (CertList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - CertList->SignatureHeaderSize) / CertList->SignatureSize;
@@ -2050,8 +2050,9 @@ Failed:
// executable information table in either case.
//
NameStr = ConvertDevicePathToText (File, FALSE, TRUE);
- AddImageExeInfo (Action, NameStr, File, SignatureList, SignatureListSize);
+
if (NameStr != NULL) {
+ AddImageExeInfo (Action, NameStr, File, SignatureList, SignatureListSize);
DEBUG ((DEBUG_INFO, "The image doesn't pass verification: %s\n", NameStr));
FreePool (NameStr);
}
diff --git a/SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.c b/SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.c
index de4f5e5..f81519d 100644
--- a/SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.c
+++ b/SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.c
@@ -387,7 +387,10 @@ Tcg2UserConfirm (
NoPpiInfo = FALSE;
BufSize = CONFIRM_BUFFER_SIZE;
ConfirmText = AllocateZeroPool (BufSize);
- ASSERT (ConfirmText != NULL);
+ if (ConfirmText == NULL) {
+ ASSERT (ConfirmText != NULL);
+ return FALSE;
+ }
mTcg2PpStringPackHandle = HiiAddPackages (&gEfiTcg2PhysicalPresenceGuid, gImageHandle, DxeTcg2PhysicalPresenceLibStrings, NULL);
ASSERT (mTcg2PpStringPackHandle != NULL);
@@ -401,10 +404,20 @@ Tcg2UserConfirm (
TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CLEAR));
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR));
+ if ((TmpStr1 == NULL) || (TmpStr2 == NULL)) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
FreePool (TmpStr1);
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR));
+ if (TmpStr1 == NULL) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), L" \n\n", (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
@@ -417,14 +430,29 @@ Tcg2UserConfirm (
TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CLEAR));
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_PPI_HEAD_STR));
+ if ((TmpStr1 == NULL) || (TmpStr2 == NULL)) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
FreePool (TmpStr1);
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_CLEAR));
+ if (TmpStr1 == NULL) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR));
+ if (TmpStr1 == NULL) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), L" \n\n", (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
@@ -452,14 +480,29 @@ Tcg2UserConfirm (
TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_SET_PCR_BANKS));
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR));
+ if ((TmpStr1 == NULL) || (TmpStr2 == NULL)) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
FreePool (TmpStr1);
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_SET_PCR_BANKS_1));
+ if (TmpStr1 == NULL) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_SET_PCR_BANKS_2));
+ if (TmpStr1 == NULL) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
@@ -467,7 +510,11 @@ Tcg2UserConfirm (
Tcg2FillBufferWithBootHashAlg (TempBuffer2, sizeof (TempBuffer2), CurrentPCRBanks);
TmpStr1 = AllocateZeroPool (BufSize);
- ASSERT (TmpStr1 != NULL);
+ if (TmpStr1 == NULL) {
+ ASSERT (TmpStr1 != NULL);
+ return FALSE;
+ }
+
UnicodeSPrint (TmpStr1, BufSize, L"Current PCRBanks is 0x%x. (%s)\nNew PCRBanks is 0x%x. (%s)\n", CurrentPCRBanks, TempBuffer2, TpmPpCommandParameter, TempBuffer);
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
@@ -481,14 +528,29 @@ Tcg2UserConfirm (
TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CHANGE_EPS));
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_STR));
+ if ((TmpStr1 == NULL) || (TmpStr2 == NULL)) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
FreePool (TmpStr1);
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CHANGE_EPS_1));
+ if (TmpStr1 == NULL) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CHANGE_EPS_2));
+ if (TmpStr1 == NULL) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
@@ -498,6 +560,11 @@ Tcg2UserConfirm (
TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_ENABLE_BLOCK_SID));
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_HEAD_STR));
+ if ((TmpStr1 == NULL) || (TmpStr2 == NULL)) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
FreePool (TmpStr1);
break;
@@ -506,6 +573,11 @@ Tcg2UserConfirm (
TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_DISABLE_BLOCK_SID));
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_HEAD_STR));
+ if ((TmpStr1 == NULL) || (TmpStr2 == NULL)) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
FreePool (TmpStr1);
break;
@@ -515,6 +587,11 @@ Tcg2UserConfirm (
TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_PP_ENABLE_BLOCK_SID));
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_PPI_HEAD_STR));
+ if ((TmpStr1 == NULL) || (TmpStr2 == NULL)) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
FreePool (TmpStr1);
break;
@@ -524,6 +601,11 @@ Tcg2UserConfirm (
TmpStr2 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_PP_DISABLE_BLOCK_SID));
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_PPI_HEAD_STR));
+ if ((TmpStr1 == NULL) || (TmpStr2 == NULL)) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);
FreePool (TmpStr1);
break;
@@ -544,11 +626,21 @@ Tcg2UserConfirm (
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY));
}
+ if (TmpStr1 == NULL) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
if (NoPpiInfo) {
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NO_PPI_INFO));
+ if (TmpStr1 == NULL) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
}
@@ -561,11 +653,21 @@ Tcg2UserConfirm (
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_ACCEPT_KEY));
}
+ if (TmpStr1 == NULL) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
if (NoPpiInfo) {
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_NO_PPI_INFO));
+ if (TmpStr1 == NULL) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);
FreePool (TmpStr1);
}
@@ -573,6 +675,11 @@ Tcg2UserConfirm (
TmpStr1 = Tcg2PhysicalPresenceGetStringById (STRING_TOKEN (TCG_STORAGE_REJECT_KEY));
}
+ if (TmpStr1 == NULL) {
+ FreePool (ConfirmText);
+ return FALSE;
+ }
+
BufSize -= StrSize (ConfirmText);
UnicodeSPrint (ConfirmText + StrLen (ConfirmText), BufSize, TmpStr1, TmpStr2);
diff --git a/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c b/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c
index 597ce77..d38a607 100644
--- a/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c
+++ b/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c
@@ -540,7 +540,7 @@ UserConfirm (
CHAR16 *TmpStr2;
UINTN BufSize;
BOOLEAN CautionKey;
- UINT16 Index;
+ UINTN Index;
CHAR16 DstStr[81];
TmpStr2 = NULL;
diff --git a/SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.c b/SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.c
index acba11d..b8eb5d6 100644
--- a/SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.c
+++ b/SecurityPkg/Library/DxeTpm2MeasureBootLib/DxeTpm2MeasureBootLib.c
@@ -615,6 +615,9 @@ GetMeasureBootProtocols (
@retval EFI_SUCCESS The file specified by DevicePath and non-NULL
FileBuffer did authenticate, and the platform policy dictates
that the DXE Foundation may use the file.
+
+ @retval EFI_OUT_OF_RESOURCES A necessary memory buffer could not be allocated.
+
@retval other error value
**/
EFI_STATUS
@@ -708,9 +711,16 @@ DxeTpm2MeasureBootHandler (
}
}
- FreePool (OrigDevicePathNode);
+ if (OrigDevicePathNode != NULL) {
+ FreePool (OrigDevicePathNode);
+ }
+
OrigDevicePathNode = DuplicateDevicePath (File);
- ASSERT (OrigDevicePathNode != NULL);
+ if (OrigDevicePathNode == NULL) {
+ ASSERT (OrigDevicePathNode != NULL);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
break;
}
}
diff --git a/SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.c b/SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.c
index c786c21..7b00833 100644
--- a/SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.c
+++ b/SecurityPkg/Library/HashInstanceLibSha1/HashInstanceLibSha1.c
@@ -56,7 +56,10 @@ Sha1HashInit (
CtxSize = Sha1GetContextSize ();
Sha1Ctx = AllocatePool (CtxSize);
- ASSERT (Sha1Ctx != NULL);
+ if (Sha1Ctx == NULL) {
+ ASSERT (Sha1Ctx != NULL);
+ return EFI_OUT_OF_RESOURCES;
+ }
Sha1Init (Sha1Ctx);
diff --git a/SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.c b/SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.c
index 4387740..4fdc5a8 100644
--- a/SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.c
+++ b/SecurityPkg/Library/HashInstanceLibSha256/HashInstanceLibSha256.c
@@ -56,7 +56,10 @@ Sha256HashInit (
CtxSize = Sha256GetContextSize ();
Sha256Ctx = AllocatePool (CtxSize);
- ASSERT (Sha256Ctx != NULL);
+ if (Sha256Ctx == NULL) {
+ ASSERT (Sha256Ctx != NULL);
+ return EFI_OUT_OF_RESOURCES;
+ }
Sha256Init (Sha256Ctx);
diff --git a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c
index 2169c5e..5e0bbe5 100644
--- a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c
+++ b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c
@@ -80,6 +80,11 @@ HashStart (
for (Index = 0; Index < mHashInterfaceCount; Index++) {
HashMask = Tpm2GetHashMaskFromAlgo (&mHashInterface[Index].HashGuid);
+ if (HashCtx == NULL) {
+ // If we fail to get the hash mask we don't have resources.
+ return EFI_OUT_OF_RESOURCES;
+ }
+
if ((HashMask & PcdGet32 (PcdTpm2HashMask)) != 0) {
mHashInterface[Index].HashInit (&HashCtx[Index]);
}
@@ -278,8 +283,16 @@ HashAndExtend (
CheckSupportedHashMaskMismatch ();
- HashStart (&HashHandle);
- HashUpdate (HashHandle, DataToHash, DataToHashLen);
+ Status = HashStart (&HashHandle);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Status = HashUpdate (HashHandle, DataToHash, DataToHashLen);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
Status = HashCompleteAndExtend (HashHandle, PcrIndex, NULL, 0, DigestList);
return Status;
diff --git a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c
index eeb424b..156dc04 100644
--- a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c
+++ b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c
@@ -106,7 +106,10 @@ CheckSupportedHashMaskMismatch (
HASH_INTERFACE_HOB *HashInterfaceHobLast;
HashInterfaceHobLast = InternalGetHashInterfaceHob (&gZeroGuid);
- ASSERT (HashInterfaceHobLast != NULL);
+ if (HashInterfaceHobLast == NULL) {
+ ASSERT (HashInterfaceHobLast != NULL);
+ return;
+ }
if ((HashInterfaceHobLast->SupportedHashMask != 0) &&
(HashInterfaceHobCurrent->SupportedHashMask != HashInterfaceHobLast->SupportedHashMask))
@@ -152,7 +155,10 @@ HashStart (
CheckSupportedHashMaskMismatch (HashInterfaceHob);
HashCtx = AllocatePool (sizeof (*HashCtx) * HashInterfaceHob->HashInterfaceCount);
- ASSERT (HashCtx != NULL);
+ if (HashCtx == NULL) {
+ ASSERT (HashCtx != NULL);
+ return EFI_OUT_OF_RESOURCES;
+ }
for (Index = 0; Index < HashInterfaceHob->HashInterfaceCount; Index++) {
HashMask = Tpm2GetHashMaskFromAlgo (&HashInterfaceHob->HashInterface[Index].HashGuid);
@@ -305,8 +311,16 @@ HashAndExtend (
CheckSupportedHashMaskMismatch (HashInterfaceHob);
- HashStart (&HashHandle);
- HashUpdate (HashHandle, DataToHash, DataToHashLen);
+ Status = HashStart (&HashHandle);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Status = HashUpdate (HashHandle, DataToHash, DataToHashLen);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
Status = HashCompleteAndExtend (HashHandle, PcrIndex, NULL, 0, DigestList);
return Status;
diff --git a/SecurityPkg/Library/SecureBootVariableProvisionLib/SecureBootVariableProvisionLib.c b/SecurityPkg/Library/SecureBootVariableProvisionLib/SecureBootVariableProvisionLib.c
index 7f9fdd2..e45e975 100644
--- a/SecurityPkg/Library/SecureBootVariableProvisionLib/SecureBootVariableProvisionLib.c
+++ b/SecurityPkg/Library/SecureBootVariableProvisionLib/SecureBootVariableProvisionLib.c
@@ -59,7 +59,11 @@ SecureBootFetchData (
*SigListOut = NULL;
*SigListsSize = 0;
CertInfo = AllocatePool (sizeof (SECURE_BOOT_CERTIFICATE_INFO));
- NewCertInfo = CertInfo;
+ if (CertInfo == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ NewCertInfo = CertInfo;
while (1) {
if (NewCertInfo == NULL) {
Status = EFI_OUT_OF_RESOURCES;
@@ -93,6 +97,9 @@ SecureBootFetchData (
sizeof (SECURE_BOOT_CERTIFICATE_INFO) * (KeyIndex + 1),
CertInfo
);
+ if (NewCertInfo == NULL) {
+ goto Cleanup;
+ }
}
if (Status == EFI_NOT_FOUND) {
diff --git a/SecurityPkg/Library/TcgEventLogRecordLib/TcgEventLogRecordLib.c b/SecurityPkg/Library/TcgEventLogRecordLib/TcgEventLogRecordLib.c
index e1e0f99..cbe1da3 100644
--- a/SecurityPkg/Library/TcgEventLogRecordLib/TcgEventLogRecordLib.c
+++ b/SecurityPkg/Library/TcgEventLogRecordLib/TcgEventLogRecordLib.c
@@ -106,7 +106,7 @@ MeasureFirmwareBlob (
{
if (Description != NULL) {
AsciiSPrint ((CHAR8 *)FvBlob2.BlobDescription, sizeof (FvBlob2.BlobDescription), "%a", Description);
- } else {
+ } else if (FvName != NULL) {
AsciiSPrint ((CHAR8 *)FvBlob2.BlobDescription, sizeof (FvBlob2.BlobDescription), "Fv(%g)", FvName);
}
diff --git a/SecurityPkg/Library/Tpm12DeviceLibDTpm/Tpm12Tis.c b/SecurityPkg/Library/Tpm12DeviceLibDTpm/Tpm12Tis.c
index 64bea73..5eb1a0b 100644
--- a/SecurityPkg/Library/Tpm12DeviceLibDTpm/Tpm12Tis.c
+++ b/SecurityPkg/Library/Tpm12DeviceLibDTpm/Tpm12Tis.c
@@ -270,7 +270,7 @@ Tpm12TisTpmCommand (
{
EFI_STATUS Status;
UINT16 BurstCount;
- UINT32 Index;
+ UINTN Index;
UINT32 TpmOutSize;
UINT16 Data16;
UINT32 Data32;
diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmDump.c b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmDump.c
index c83838f..7b2e449 100644
--- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmDump.c
+++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmDump.c
@@ -421,7 +421,7 @@ DumpTpmPcrCommand (
// If this is an unrecognized command, we can't go much further.
if ((Command != TPM_CC_PCR_Extend) && (Command != TPM_CC_PCR_Event)) {
- DEBUG ((DEBUG_WARN, "%a - Unrecognized command! 0x%X\n", __func__, Command));
+ DEBUG ((DEBUG_SECURITY, "%a - Unrecognized command! 0x%X\n", __func__, Command));
return;
}
@@ -461,7 +461,7 @@ DumpTpmPcrCommand (
default:
// This algorithm hasn't been programmed yet. We need to bail.
- DEBUG ((DEBUG_WARN, "%a - Unknown hash algorithm! 0x%04X\n", __func__, SwapBytes16 (CurrentDigest->hashAlg)));
+ DEBUG ((DEBUG_SECURITY, "%a - Unknown hash algorithm! 0x%04X\n", __func__, SwapBytes16 (CurrentDigest->hashAlg)));
// Zero the count so we can get out of here.
DigestCount = 0;
break;
@@ -635,11 +635,11 @@ DumpTpmInputBlock (
TPM_CC NativeCode;
DEBUG ((DEBUG_SECURITY, "\n=== BEGIN TPM COMMAND ===\n"));
- DEBUG ((DEBUG_VERBOSE, "Size: %d (0x%X), Address: 0x%X\n", InputBlockSize, InputBlockSize, InputBlock));
+ DEBUG ((DEBUG_SECURITY, "Size: %d (0x%X), Address: 0x%X\n", InputBlockSize, InputBlockSize, InputBlock));
// Make sure we've got at least enough data for a valid header.
if (InputBlockSize < sizeof (*CommHeader)) {
- DEBUG ((DEBUG_WARN, "%a - Invalid buffer size!\n", __func__));
+ DEBUG ((DEBUG_SECURITY, "%a - Invalid buffer size!\n", __func__));
return;
}
@@ -704,7 +704,7 @@ DumpTpmOutputBlock (
UINT32 NativeSize;
TPM_CC NativeCode;
- DEBUG ((DEBUG_VERBOSE, "Size: %d (0x%X), Address: 0x%X\n", OutputBlockSize, OutputBlockSize, OutputBlock));
+ DEBUG ((DEBUG_SECURITY, "Size: %d (0x%X), Address: 0x%X\n", OutputBlockSize, OutputBlockSize, OutputBlock));
// Start the debugging by mapping some stuff.
RespHeader = (TPM2_RESPONSE_HEADER *)OutputBlock;
diff --git a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfa.h b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfa.h
index 665b594..97a558a 100644
--- a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfa.h
+++ b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfa.h
@@ -34,6 +34,9 @@
#ifndef TPM2_DEVICE_LIB_FFA_H_
#define TPM2_DEVICE_LIB_FFA_H_
+#define TPM2_FFA_INTERFACE_TYPE_UNKNOWN 0xFF
+#define TPM2_FFA_PARTITION_ID_INVALID 0x0000
+
/**
This function is used to get the TPM interface version.
@@ -188,6 +191,22 @@ FfaTpm2RequestUseTpm (
);
/**
+ This function is used to get the TPM service partition id via FF-A
+
+ @param[out] PartitionId - Supplies the pointer to the TPM service partition id.
+
+ @retval EFI_SUCCESS The TPM command was successfully sent to the TPM
+ and the response was copied to the Output buffer.
+ @retval EFI_INVALID_PARAMETER The TPM command buffer is NULL or the TPM command
+ buffer size is 0.
+ @retval EFI_DEVICE_ERROR An error occurred in communication with the TPM.
+**/
+EFI_STATUS
+FfaTpm2GetServicePartitionId (
+ OUT UINT16 *PartitionId
+ );
+
+/**
Dump PTP register information.
@param[in] Register Pointer to PTP register.
@@ -210,4 +229,35 @@ InternalTpm2DeviceLibFfaConstructor (
VOID
);
+/**
+ This function validate TPM interface type for TPM service over FF-A.
+
+ @retval EFI_SUCCESS TPM interface type is valid.
+
+ @retval EFI_UNSUPPORTED TPM interface type is invalid.
+
+**/
+EFI_STATUS
+EFIAPI
+ValidateTpmInterfaceType (
+ VOID
+ );
+
+/**
+ This function is used to get the TPM service partition id.
+
+ @param[out] PartitionId - Supplies the pointer to the TPM service partition id.
+
+ @retval EFI_SUCCESS The TPM command was successfully sent to the TPM
+ and the response was copied to the Output buffer.
+ @retval EFI_INVALID_PARAMETER The TPM command buffer is NULL or the TPM command
+ buffer size is 0.
+ @retval EFI_DEVICE_ERROR An error occurred in communication with the TPM.
+**/
+EFI_STATUS
+EFIAPI
+GetTpmServicePartitionId (
+ OUT UINT16 *PartitionId
+ );
+
#endif /* _TPM2_DEVICE_LIB_SMC_H_ */
diff --git a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfa.inf b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfa.inf
index 68a0094..198a9e5 100644
--- a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfa.inf
+++ b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfa.inf
@@ -29,6 +29,7 @@
Tpm2DeviceLibFfaBase.c
Tpm2Ptp.c
Tpm2DeviceLibFfa.h
+ Tpm2InfoFfa.c
[Packages]
MdePkg/MdePkg.dec
diff --git a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfaBase.c b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfaBase.c
index 85815a0..058d131 100644
--- a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfaBase.c
+++ b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfaBase.c
@@ -21,8 +21,7 @@
#include "Tpm2DeviceLibFfa.h"
-TPM2_PTP_INTERFACE_TYPE mActiveTpmInterfaceType;
-UINT8 mCRBIdleByPass;
+UINT8 mCRBIdleByPass;
/**
Return cached PTP CRB interface IdleByPass state.
@@ -52,28 +51,18 @@ InternalTpm2DeviceLibFfaConstructor (
{
EFI_STATUS Status;
- mActiveTpmInterfaceType = PcdGet8 (PcdActiveTpmInterfaceType);
- mCRBIdleByPass = 0xFF;
+ mCRBIdleByPass = 0xFF;
if (PcdGet64 (PcdTpmBaseAddress) == 0) {
Status = EFI_NO_MAPPING;
goto Exit;
}
- //
- // Start by checking the PCD out of the gate and read from the CRB if it is invalid
- //
- if (mActiveTpmInterfaceType == 0xFF) {
- mActiveTpmInterfaceType = Tpm2GetPtpInterface ((VOID *)(UINTN)PcdGet64 (PcdTpmBaseAddress));
- PcdSet8S (PcdActiveTpmInterfaceType, mActiveTpmInterfaceType);
- }
-
- if (mActiveTpmInterfaceType != Tpm2PtpInterfaceCrb) {
- Status = EFI_UNSUPPORTED;
+ Status = ValidateTpmInterfaceType ();
+ if (EFI_ERROR (Status)) {
goto Exit;
}
- DEBUG ((DEBUG_INFO, "Setting Tpm Active Interface Type %d\n", mActiveTpmInterfaceType));
mCRBIdleByPass = Tpm2GetIdleByPass ((VOID *)(UINTN)PcdGet64 (PcdTpmBaseAddress));
Status = EFI_SUCCESS;
diff --git a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceSecLibFfa.inf b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceSecLibFfa.inf
new file mode 100644
index 0000000..2f4ae52
--- /dev/null
+++ b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceSecLibFfa.inf
@@ -0,0 +1,51 @@
+## @file
+# Provides function interfaces to communicate with TPM 2.0 device
+#
+# This library helps to use TPM 2.0 device in library function API
+# based on FF-A using Command Response Buffer (CRB).
+#
+# Copyright (c), Microsoft Corporation.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = Tpm2DeviceSecLibFfa
+ FILE_GUID = d66e7482-615c-11f0-91d0-47f6d24396e9
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = Tpm2DeviceLib|SEC
+ CONSTRUCTOR = Tpm2DeviceLibFfaConstructor
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = AARCH64
+#
+
+[Sources.common]
+ Tpm2DeviceLibFfa.c
+ Tpm2ServiceFfaRaw.c
+ Tpm2DeviceLibFfaBase.c
+ Tpm2Ptp.c
+ Tpm2DeviceLibFfa.h
+ Tpm2InfoSecFfa.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ SecurityPkg/SecurityPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ DebugLib
+ TimerLib
+ BaseMemoryLib
+ IoLib
+ ArmFfaLib
+
+[Guids]
+ gTpm2ServiceFfaGuid
+
+[Pcd.common]
+ gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress ## CONSUMES
diff --git a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2InfoFfa.c b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2InfoFfa.c
new file mode 100644
index 0000000..602fe34
--- /dev/null
+++ b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2InfoFfa.c
@@ -0,0 +1,87 @@
+/** @file
+ This library provides an interfaces to access DynamicPcds used
+ in Tpm2DeviceLibFfa.
+
+ Copyright (c) 2025, Arm Ltd. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/PcdLib.h>
+#include <Library/Tpm2DeviceLib.h>
+#include <Uefi/UefiBaseType.h>
+
+#include "Tpm2DeviceLibFfa.h"
+
+TPM2_PTP_INTERFACE_TYPE mActiveTpmInterfaceType;
+
+/**
+ This function validate TPM interface type for TPM service over FF-A.
+
+ @retval EFI_SUCCESS TPM interface type is valid.
+
+ @retval EFI_UNSUPPORTED TPM interface type is invalid.
+
+**/
+EFI_STATUS
+ValidateTpmInterfaceType (
+ VOID
+ )
+{
+ mActiveTpmInterfaceType = PcdGet8 (PcdActiveTpmInterfaceType);
+
+ //
+ // Start by checking the PCD out of the gate and read from the CRB if it is invalid
+ //
+ if (mActiveTpmInterfaceType == TPM2_FFA_INTERFACE_TYPE_UNKNOWN) {
+ mActiveTpmInterfaceType = Tpm2GetPtpInterface ((VOID *)(UINTN)PcdGet64 (PcdTpmBaseAddress));
+ PcdSet8S (PcdActiveTpmInterfaceType, mActiveTpmInterfaceType);
+ }
+
+ if (mActiveTpmInterfaceType != Tpm2PtpInterfaceCrb) {
+ return EFI_UNSUPPORTED;
+ }
+
+ DEBUG ((DEBUG_INFO, "Setting Tpm Active Interface Type %d\n", mActiveTpmInterfaceType));
+
+ return EFI_SUCCESS;
+}
+
+/**
+ This function is used to get the TPM service partition id.
+
+ @param[out] PartitionId - Supplies the pointer to the TPM service partition id.
+
+ @retval EFI_SUCCESS The TPM command was successfully sent to the TPM
+ and the response was copied to the Output buffer.
+ @retval EFI_INVALID_PARAMETER The TPM command buffer is NULL or the TPM command
+ buffer size is 0.
+ @retval EFI_DEVICE_ERROR An error occurred in communication with the TPM.
+**/
+EFI_STATUS
+EFIAPI
+GetTpmServicePartitionId (
+ OUT UINT16 *PartitionId
+ )
+{
+ EFI_STATUS Status;
+
+ if (PartitionId == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (PcdGet16 (PcdTpmServiceFfaPartitionId) != TPM2_FFA_PARTITION_ID_INVALID) {
+ *PartitionId = PcdGet16 (PcdTpmServiceFfaPartitionId);
+ return EFI_SUCCESS;
+ }
+
+ Status = FfaTpm2GetServicePartitionId (PartitionId);
+ if (!EFI_ERROR (Status)) {
+ PcdSet16S (PcdTpmServiceFfaPartitionId, *PartitionId);
+ }
+
+ return Status;
+}
diff --git a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2InfoSecFfa.c b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2InfoSecFfa.c
new file mode 100644
index 0000000..2f264eb
--- /dev/null
+++ b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2InfoSecFfa.c
@@ -0,0 +1,62 @@
+/** @file
+ This library provides an interfaces to access DynamicPcds used
+ in Tpm2DeviceLibFfa.
+
+ Copyright (c) 2025, Arm Ltd. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/Tpm2DeviceLib.h>
+#include <Uefi/UefiBaseType.h>
+
+#include "Tpm2DeviceLibFfa.h"
+
+/**
+ This function validate TPM interface type for TPM service over FF-A.
+
+ @retval EFI_SUCCESS TPM interface type is valid.
+
+ @retval EFI_UNSUPPORTED TPM interface type is invalid.
+
+**/
+EFI_STATUS
+EFIAPI
+ValidateTpmInterfaceType (
+ VOID
+ )
+{
+ TPM2_PTP_INTERFACE_TYPE TpmInterfaceType;
+
+ TpmInterfaceType = Tpm2GetPtpInterface ((VOID *)(UINTN)PcdGet64 (PcdTpmBaseAddress));
+ if (TpmInterfaceType != Tpm2PtpInterfaceCrb) {
+ return EFI_UNSUPPORTED;
+ }
+
+ DEBUG ((DEBUG_INFO, "Setting Tpm Active Interface Type %d\n", TpmInterfaceType));
+
+ return EFI_SUCCESS;
+}
+
+/**
+ This function is used to get the TPM service partition id.
+
+ @param[out] PartitionId - Supplies the pointer to the TPM service partition id.
+
+ @retval EFI_SUCCESS The TPM command was successfully sent to the TPM
+ and the response was copied to the Output buffer.
+ @retval EFI_INVALID_PARAMETER The TPM command buffer is NULL or the TPM command
+ buffer size is 0.
+ @retval EFI_DEVICE_ERROR An error occurred in communication with the TPM.
+**/
+EFI_STATUS
+EFIAPI
+GetTpmServicePartitionId (
+ OUT UINT16 *PartitionId
+ )
+{
+ return FfaTpm2GetServicePartitionId (PartitionId);
+}
diff --git a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2InstanceLibFfa.inf b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2InstanceLibFfa.inf
index 0f5d3fa..ecf9a36 100644
--- a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2InstanceLibFfa.inf
+++ b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2InstanceLibFfa.inf
@@ -29,6 +29,7 @@
Tpm2DeviceLibFfaBase.c
Tpm2Ptp.c
Tpm2DeviceLibFfa.h
+ Tpm2InfoFfa.c
[Packages]
MdePkg/MdePkg.dec
diff --git a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2ServiceFfaRaw.c b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2ServiceFfaRaw.c
index 3e36bcf..44159c9 100644
--- a/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2ServiceFfaRaw.c
+++ b/SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2ServiceFfaRaw.c
@@ -26,7 +26,7 @@
#include "Tpm2DeviceLibFfa.h"
-UINT32 mFfaTpm2PartitionId = MAX_UINT32;
+UINT16 mFfaTpm2PartitionId = TPM2_FFA_PARTITION_ID_INVALID;
/**
Check the return status from the FF-A call and returns EFI_STATUS
@@ -84,7 +84,7 @@ TranslateTpmReturnStatus (
}
/**
- This function is used to get the TPM service partition id.
+ This function is used to get the TPM service partition id via FF-A.
@param[out] PartitionId - Supplies the pointer to the TPM service partition id.
@@ -92,11 +92,12 @@ TranslateTpmReturnStatus (
and the response was copied to the Output buffer.
@retval EFI_INVALID_PARAMETER The TPM command buffer is NULL or the TPM command
buffer size is 0.
+ @retval EFI_DEVICE_ERROR The TPM partition information is wrong.
@retval EFI_DEVICE_ERROR An error occurred in communication with the TPM.
**/
EFI_STATUS
-GetTpmServicePartitionId (
- OUT UINT32 *PartitionId
+FfaTpm2GetServicePartitionId (
+ OUT UINT16 *PartitionId
)
{
EFI_STATUS Status;
@@ -114,20 +115,6 @@ GetTpmServicePartitionId (
goto Exit;
}
- if (mFfaTpm2PartitionId != MAX_UINT32) {
- *PartitionId = mFfaTpm2PartitionId;
- Status = EFI_SUCCESS;
- goto Exit;
- }
-
- if (PcdGet16 (PcdTpmServiceFfaPartitionId) != 0) {
- mFfaTpm2PartitionId = PcdGet16 (PcdTpmServiceFfaPartitionId);
- *PartitionId = mFfaTpm2PartitionId;
- Status = EFI_SUCCESS;
-
- goto Exit;
- }
-
Status = ArmFfaLibPartitionIdGet (&PartId);
if (EFI_ERROR (Status)) {
DEBUG ((
@@ -164,11 +151,14 @@ GetTpmServicePartitionId (
Status = EFI_INVALID_PARAMETER;
DEBUG ((DEBUG_ERROR, "Invalid partition Info(%g). Count: %d, Size: %d\n", &gTpm2ServiceFfaGuid, Count, Size));
} else {
- TpmPartInfo = (EFI_FFA_PART_INFO_DESC *)RxBuffer;
- mFfaTpm2PartitionId = TpmPartInfo->PartitionId;
- *PartitionId = mFfaTpm2PartitionId;
-
- Status = PcdSet16S (PcdTpmServiceFfaPartitionId, mFfaTpm2PartitionId);
+ TpmPartInfo = (EFI_FFA_PART_INFO_DESC *)RxBuffer;
+ *PartitionId = TpmPartInfo->PartitionId;
+ if (TpmPartInfo->PartitionId == TPM2_FFA_PARTITION_ID_INVALID) {
+ /*
+ * Tpm partition id never be TPM2_FFA_PARTITION_ID_INVALID.
+ */
+ Status = EFI_DEVICE_ERROR;
+ }
}
RxRelease:
@@ -202,7 +192,7 @@ Tpm2GetInterfaceVersion (
goto Exit;
}
- if (mFfaTpm2PartitionId == MAX_UINT32) {
+ if (mFfaTpm2PartitionId == TPM2_FFA_PARTITION_ID_INVALID) {
GetTpmServicePartitionId (&mFfaTpm2PartitionId);
}
@@ -253,7 +243,7 @@ Tpm2GetFeatureInfo (
goto Exit;
}
- if (mFfaTpm2PartitionId == MAX_UINT32) {
+ if (mFfaTpm2PartitionId == TPM2_FFA_PARTITION_ID_INVALID) {
GetTpmServicePartitionId (&mFfaTpm2PartitionId);
}
@@ -296,7 +286,7 @@ Tpm2ServiceStart (
EFI_STATUS Status;
DIRECT_MSG_ARGS FfaDirectReq2Args;
- if (mFfaTpm2PartitionId == MAX_UINT32) {
+ if (mFfaTpm2PartitionId == TPM2_FFA_PARTITION_ID_INVALID) {
GetTpmServicePartitionId (&mFfaTpm2PartitionId);
}
@@ -341,7 +331,7 @@ Tpm2RegisterNotification (
EFI_STATUS Status;
DIRECT_MSG_ARGS FfaDirectReq2Args;
- if (mFfaTpm2PartitionId == MAX_UINT32) {
+ if (mFfaTpm2PartitionId == TPM2_FFA_PARTITION_ID_INVALID) {
GetTpmServicePartitionId (&mFfaTpm2PartitionId);
}
@@ -380,7 +370,7 @@ Tpm2UnregisterNotification (
EFI_STATUS Status;
DIRECT_MSG_ARGS FfaDirectReq2Args;
- if (mFfaTpm2PartitionId == MAX_UINT32) {
+ if (mFfaTpm2PartitionId == TPM2_FFA_PARTITION_ID_INVALID) {
GetTpmServicePartitionId (&mFfaTpm2PartitionId);
}
@@ -417,7 +407,7 @@ Tpm2FinishNotified (
EFI_STATUS Status;
DIRECT_MSG_ARGS FfaDirectReq2Args;
- if (mFfaTpm2PartitionId == MAX_UINT32) {
+ if (mFfaTpm2PartitionId == TPM2_FFA_PARTITION_ID_INVALID) {
GetTpmServicePartitionId (&mFfaTpm2PartitionId);
}
diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/AesCore.c b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/AesCore.c
index 3ac20e8..1b2cddf 100644
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/AesCore.c
+++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/AesCore.c
@@ -230,6 +230,8 @@ AesEncrypt (
UINTN NbIndex;
UINTN Round;
+ EFI_STATUS Status;
+
if ((Key == NULL) || (InData == NULL) || (OutData == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -237,7 +239,10 @@ AesEncrypt (
//
// Expands AES Key for encryption.
//
- AesExpandKey (Key, 128, &AesKey);
+ Status = AesExpandKey (Key, 128, &AesKey);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
Nr = AesKey.Nk + 6;
Ek = AesKey.EncKey;
diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc
index 430b42c..ea6fdc2 100644
--- a/SecurityPkg/SecurityPkg.dsc
+++ b/SecurityPkg/SecurityPkg.dsc
@@ -91,6 +91,9 @@
[LibraryClasses.ARM, LibraryClasses.AARCH64]
ArmTrngLib|MdePkg/Library/BaseArmTrngLibNull/BaseArmTrngLibNull.inf
+ ArmSmcLib|MdePkg/Library/ArmSmcLib/ArmSmcLib.inf
+ ArmSvcLib|MdePkg/Library/ArmSvcLib/ArmSvcLib.inf
+ ArmFfaLib|MdeModulePkg/Library/ArmFfaLib/ArmFfaPeiLib.inf
[LibraryClasses.ARM]
RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf
@@ -425,7 +428,9 @@
[Components.AARCH64]
SecurityPkg/Tcg/Tcg2StandaloneMmArm/Tcg2StandaloneMmArm.inf
SecurityPkg/Tcg/Tcg2AcpiFfa/Tcg2AcpiFfa.inf
+ SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigFfaPei.inf
SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceLibFfa.inf
+ SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2DeviceSecLibFfa.inf
SecurityPkg/Library/Tpm2DeviceLibFfa/Tpm2InstanceLibFfa.inf
[BuildOptions]
diff --git a/SecurityPkg/Tcg/Opal/OpalPassword/OpalDriver.c b/SecurityPkg/Tcg/Opal/OpalPassword/OpalDriver.c
index 0167afd..068c3c7 100644
--- a/SecurityPkg/Tcg/Opal/OpalPassword/OpalDriver.c
+++ b/SecurityPkg/Tcg/Opal/OpalPassword/OpalDriver.c
@@ -2224,7 +2224,7 @@ ProcessOpalRequest (
//
TempVariable = Variable;
while ((VariableSize > sizeof (OPAL_REQUEST_VARIABLE)) &&
- (VariableSize >= TempVariable->Length) &&
+ (VariableSize >= (UINTN)TempVariable->Length) &&
(TempVariable->Length > sizeof (OPAL_REQUEST_VARIABLE)))
{
DevicePathInVariable = (EFI_DEVICE_PATH_PROTOCOL *)((UINTN)TempVariable + sizeof (OPAL_REQUEST_VARIABLE));
diff --git a/SecurityPkg/Tcg/Opal/OpalPassword/OpalHii.c b/SecurityPkg/Tcg/Opal/OpalPassword/OpalHii.c
index 1e0b00b..c5f1121 100644
--- a/SecurityPkg/Tcg/Opal/OpalPassword/OpalHii.c
+++ b/SecurityPkg/Tcg/Opal/OpalPassword/OpalHii.c
@@ -113,7 +113,7 @@ GetSavedOpalRequest (
TempVariable = Variable;
while ((VariableSize > sizeof (OPAL_REQUEST_VARIABLE)) &&
- (VariableSize >= TempVariable->Length) &&
+ (VariableSize >= (UINTN)TempVariable->Length) &&
(TempVariable->Length > sizeof (OPAL_REQUEST_VARIABLE)))
{
DevicePathInVariable = (EFI_DEVICE_PATH_PROTOCOL *)((UINTN)TempVariable + sizeof (OPAL_REQUEST_VARIABLE));
@@ -193,7 +193,7 @@ SaveOpalRequest (
TempVariable = Variable;
TempVariableSize = VariableSize;
while ((TempVariableSize > sizeof (OPAL_REQUEST_VARIABLE)) &&
- (TempVariableSize >= TempVariable->Length) &&
+ (TempVariableSize >= (UINTN)TempVariable->Length) &&
(TempVariable->Length > sizeof (OPAL_REQUEST_VARIABLE)))
{
DevicePathInVariable = (EFI_DEVICE_PATH_PROTOCOL *)((UINTN)TempVariable + sizeof (OPAL_REQUEST_VARIABLE));
@@ -226,7 +226,11 @@ SaveOpalRequest (
DevicePathSize = GetDevicePathSize (DevicePath);
NewVariableSize = VariableSize + sizeof (OPAL_REQUEST_VARIABLE) + DevicePathSize;
NewVariable = AllocatePool (NewVariableSize);
- ASSERT (NewVariable != NULL);
+ if (NewVariable == NULL) {
+ ASSERT (NewVariable != NULL);
+ return;
+ }
+
CopyMem (NewVariable, Variable, VariableSize);
TempVariable = (OPAL_REQUEST_VARIABLE *)((UINTN)NewVariable + VariableSize);
TempVariable->Length = (UINT32)(sizeof (OPAL_REQUEST_VARIABLE) + DevicePathSize);
@@ -239,7 +243,11 @@ SaveOpalRequest (
DevicePathSize = GetDevicePathSize (DevicePath);
NewVariableSize = sizeof (OPAL_REQUEST_VARIABLE) + DevicePathSize;
NewVariable = AllocatePool (NewVariableSize);
- ASSERT (NewVariable != NULL);
+ if (NewVariable == NULL) {
+ ASSERT (NewVariable != NULL);
+ return;
+ }
+
NewVariable->Length = (UINT32)(sizeof (OPAL_REQUEST_VARIABLE) + DevicePathSize);
CopyMem (&NewVariable->OpalRequest, &OpalRequest, sizeof (OPAL_REQUEST));
DevicePathInVariable = (EFI_DEVICE_PATH_PROTOCOL *)((UINTN)NewVariable + sizeof (OPAL_REQUEST_VARIABLE));
@@ -1111,8 +1119,13 @@ ExtractConfig (
//
DriverHandle = HiiGetDriverImageHandleCB ();
ConfigRequestHdr = HiiConstructConfigHdr (&gHiiSetupVariableGuid, OpalPasswordStorageName, DriverHandle);
- Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
- ConfigRequest = AllocateZeroPool (Size);
+ if (ConfigRequestHdr == NULL) {
+ ASSERT (ConfigRequestHdr != NULL);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
+ ConfigRequest = AllocateZeroPool (Size);
if (ConfigRequest == NULL) {
return EFI_OUT_OF_RESOURCES;
}
diff --git a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDriver.c b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDriver.c
index edf5f0f..2b93733 100644
--- a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDriver.c
+++ b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDriver.c
@@ -103,7 +103,11 @@ InitializeTcg2VersionInfo (
TCG2_VERSION_NAME,
PrivateData->DriverHandle
);
- ASSERT (ConfigRequestHdr != NULL);
+ if (ConfigRequestHdr == NULL) {
+ ASSERT (ConfigRequestHdr != NULL);
+ return;
+ }
+
DataSize = sizeof (Tcg2Version);
Status = gRT->GetVariable (
TCG2_VERSION_NAME,
diff --git a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigFfaPei.inf b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigFfaPei.inf
new file mode 100644
index 0000000..e20a1f8
--- /dev/null
+++ b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigFfaPei.inf
@@ -0,0 +1,53 @@
+## @file
+# Set TPM device type
+#
+# This module initializes TPM device type based on CRB over FF-A interface
+#
+# Copyright (c) 2025, Arm Ltd. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x0001001B
+ BASE_NAME = Tcg2ConfigFfaPei
+ FILE_GUID = ae8c4c50-2cd7-11f0-9e39-a7fbc471b972
+ MODULE_TYPE = PEIM
+ VERSION_STRING = 1.0
+ ENTRY_POINT = Tcg2ConfigFfaPeimEntryPoint
+
+#
+# VALID_ARCHITECTURES = AARCH64
+#
+
+[Sources]
+ Tcg2ConfigFfaPeim.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ SecurityPkg/SecurityPkg.dec
+
+[LibraryClasses]
+ ArmFfaLib
+ BaseLib
+ BaseMemoryLib
+ PeiServicesLib
+ PeimEntryPoint
+ DebugLib
+ PcdLib
+ HobLib
+
+[Guids]
+ gTpm2ServiceFfaGuid ## SOMETIMES_CONSUMES
+ gEfiTpmDeviceInstanceNoneGuid ## SOMETIMES_CONSUMES
+ gEfiTpmDeviceSelectedGuid ## SOMETIMES_PRODUCES
+
+[Ppis]
+ gPeiTpmInitializationDonePpiGuid ## SOMETIMES_PRODUCES
+
+[Pcd]
+ gEfiSecurityPkgTokenSpaceGuid.PcdTpmInstanceGuid
+
+[Depex]
+ gEfiPeiMasterBootModePpiGuid
diff --git a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigFfaPeim.c b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigFfaPeim.c
new file mode 100644
index 0000000..ea01c9b
--- /dev/null
+++ b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigFfaPeim.c
@@ -0,0 +1,198 @@
+/** @file
+ Set TPM device type
+
+ This module initializes the TPM device type based on a CRB over FF-A
+ interface
+
+ Copyright (C) 2025, Arm Ltd.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - https://developer.arm.com/documentation/den0138/latest/
+**/
+
+#include <PiPei.h>
+
+#include <Guid/TpmInstance.h>
+#include <Guid/Tpm2ServiceFfa.h>
+
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/PeiServicesLib.h>
+#include <Library/ArmFfaLib.h>
+
+#define TPM2_FFA_SERVICE_MAJOR_VERSION (1)
+#define TPM2_FFA_SERVICE_MINOR_VERSION (0)
+
+STATIC CONST EFI_PEI_PPI_DESCRIPTOR mTpmSelectedPpi = {
+ (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
+ &gEfiTpmDeviceSelectedGuid,
+ NULL
+};
+
+STATIC CONST EFI_PEI_PPI_DESCRIPTOR mTpmInitializationDonePpiList = {
+ EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
+ &gPeiTpmInitializationDonePpiGuid,
+ NULL
+};
+
+/**
+ Check the Tpm Service Interface version.
+
+ See the CRB over FF-A spec 6.1.
+ all of arguments' value based on the specification.
+
+ @param [in] TpmPartId TPM service partition id.
+
+ @retval EFI_SUCCESS
+ @retval EFI_DEVICE_ERROR Failed to communicate TPM SP.
+ @retval EFI_UNSUPPORTED Unsupported version of TPM service
+
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+Tpm2FfaCheckInterfaceVersion (
+ IN UINT16 TpmPartId
+ )
+{
+ EFI_STATUS Status;
+ DIRECT_MSG_ARGS TpmArgs;
+ UINT16 MajorVer;
+ UINT16 MinorVer;
+
+ ZeroMem (&TpmArgs, sizeof (DIRECT_MSG_ARGS));
+ TpmArgs.Arg0 = TPM2_FFA_GET_INTERFACE_VERSION;
+
+ Status = ArmFfaLibMsgSendDirectReq2 (TpmPartId, &gTpm2ServiceFfaGuid, &TpmArgs);
+ while (Status == EFI_INTERRUPT_PENDING) {
+ // We are assuming vCPU0 of the TPM SP since it is UP.
+ Status = ArmFfaLibRun (TpmPartId, 0x00);
+ }
+
+ if (EFI_ERROR (Status) || (TpmArgs.Arg0 != TPM2_FFA_SUCCESS_OK_RESULTS_RETURNED)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: Failed to get interface version... Status: %r, TpmArgs.Arg0: 0x%x\n",
+ __func__,
+ Status,
+ TpmArgs.Arg0
+ ));
+
+ return EFI_DEVICE_ERROR;
+ }
+
+ MajorVer = (TpmArgs.Arg1 & TPM2_FFA_SERVICE_MAJOR_VER_MASK) >> TPM2_FFA_SERVICE_MAJOR_VER_SHIFT;
+ MinorVer = (TpmArgs.Arg1 & TPM2_FFA_SERVICE_MINOR_VER_MASK) >> TPM2_FFA_SERVICE_MINOR_VER_SHIFT;
+ if ((MajorVer != TPM2_FFA_SERVICE_MAJOR_VERSION) || (MinorVer < TPM2_FFA_SERVICE_MINOR_VERSION)) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "%a: Wrong Tpm Ffa Interface Version...: v%d.%d\n",
+ __func__,
+ MajorVer,
+ MinorVer
+ ));
+ return EFI_UNSUPPORTED;
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ The entry point for Tcg2 configuration driver.
+
+ @param FileHandle Handle of the file being invoked.
+ @param PeiServices Describes the list of possible PEI Services.
+**/
+EFI_STATUS
+EFIAPI
+Tcg2ConfigFfaPeimEntryPoint (
+ IN EFI_PEI_FILE_HANDLE FileHandle,
+ IN CONST EFI_PEI_SERVICES **PeiServices
+ )
+{
+ EFI_STATUS Status;
+ UINTN Size;
+ UINT16 PartId;
+ UINT16 TpmPartId;
+ EFI_FFA_PART_INFO_DESC *TpmPartInfo;
+ VOID *TxBuffer;
+ UINT64 TxBufferSize;
+ VOID *RxBuffer;
+ UINT64 RxBufferSize;
+ UINT32 Count;
+ CONST EFI_PEI_PPI_DESCRIPTOR *PpiList;
+ GUID *TpmInstanceGuid;
+
+ DEBUG ((DEBUG_INFO, "%a\n", __func__));
+
+ TpmInstanceGuid = &gEfiTpmDeviceInstanceNoneGuid;
+ PpiList = &mTpmInitializationDonePpiList;
+
+ Status = ArmFfaLibPartitionIdGet (&PartId);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Failed to get partition-id. Status: %r\n", Status));
+ goto Cleanup;
+ }
+
+ Status = ArmFfaLibGetRxTxBuffers (
+ &TxBuffer,
+ &TxBufferSize,
+ &RxBuffer,
+ &RxBufferSize
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Failed to get Rx/Tx Buffer. Status: %r\n", Status));
+ goto Cleanup;
+ }
+
+ Status = ArmFfaLibPartitionInfoGet (
+ &gTpm2ServiceFfaGuid,
+ FFA_PART_INFO_FLAG_TYPE_DESC,
+ &Count,
+ (UINT32 *)&Size
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Failed to get Tpm2 partition info. Status: %r\n", Status));
+ goto Cleanup;
+ }
+
+ if ((Count != 1) || (Size < sizeof (EFI_FFA_PART_INFO_DESC))) {
+ Status = EFI_INVALID_PARAMETER;
+ DEBUG ((DEBUG_ERROR, "Invalid partition Info(%g). Count: %d, Size: %d\n", &gTpm2ServiceFfaGuid, Count, Size));
+ ArmFfaLibRxRelease (PartId);
+ goto Cleanup;
+ }
+
+ TpmPartInfo = (EFI_FFA_PART_INFO_DESC *)RxBuffer;
+ TpmPartId = TpmPartInfo->PartitionId;
+ ArmFfaLibRxRelease (PartId);
+
+ Status = Tpm2FfaCheckInterfaceVersion (TpmPartId);
+ if (EFI_ERROR (Status)) {
+ goto Cleanup;
+ }
+
+ /*
+ * Set the PcdTpmInstanceGuid to TPM using CRB over FF-A
+ * So that Tpm2DeviceLibRouterPei/Dxe can communicate with
+ * TPM secure partition.
+ */
+ TpmInstanceGuid = &gTpm2ServiceFfaGuid;
+ PpiList = &mTpmSelectedPpi;
+
+Cleanup:
+ Size = sizeof (GUID);
+ Status = PcdSetPtrS (
+ PcdTpmInstanceGuid,
+ &Size,
+ TpmInstanceGuid
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ Status = PeiServicesInstallPpi (PpiList);
+
+ return Status;
+}
diff --git a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
index 24a27cd..2a0307c 100644
--- a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
+++ b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
@@ -626,7 +626,7 @@ DumpEventLog (
TCG_PCR_EVENT_HDR *EventHdr;
TCG_PCR_EVENT2 *TcgPcrEvent2;
TCG_EfiSpecIDEventStruct *TcgEfiSpecIdEventStruct;
- UINTN NumberOfEvents;
+ UINT64 NumberOfEvents;
if (!DebugPrintLevelEnabled (DEBUG_SECURITY)) {
return;
@@ -637,7 +637,7 @@ DumpEventLog (
switch (EventLogFormat) {
case EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2:
EventHdr = (TCG_PCR_EVENT_HDR *)(UINTN)EventLogLocation;
- while ((UINTN)EventHdr <= EventLogLastEntry) {
+ while ((EFI_PHYSICAL_ADDRESS)(UINTN)EventHdr <= EventLogLastEntry) {
DumpEvent (EventHdr);
EventHdr = (TCG_PCR_EVENT_HDR *)((UINTN)EventHdr + sizeof (TCG_PCR_EVENT_HDR) + EventHdr->EventSize);
}
@@ -668,7 +668,7 @@ DumpEventLog (
DumpTcgEfiSpecIdEventStruct (TcgEfiSpecIdEventStruct);
TcgPcrEvent2 = (TCG_PCR_EVENT2 *)((UINTN)TcgEfiSpecIdEventStruct + GetTcgEfiSpecIdEventStructSize (TcgEfiSpecIdEventStruct));
- while ((UINTN)TcgPcrEvent2 <= EventLogLastEntry) {
+ while ((EFI_PHYSICAL_ADDRESS)(UINTN)TcgPcrEvent2 <= EventLogLastEntry) {
DumpEvent2 (TcgPcrEvent2);
TcgPcrEvent2 = (TCG_PCR_EVENT2 *)((UINTN)TcgPcrEvent2 + GetPcrEvent2Size (TcgPcrEvent2));
}
@@ -798,6 +798,7 @@ Tcg2GetEventLog (
@retval FALSE This is NOT a Tcg800155PlatformIdEvent.
**/
+STATIC
BOOLEAN
Is800155Event (
IN VOID *NewEventHdr,
@@ -806,18 +807,26 @@ Is800155Event (
IN UINT32 NewEventSize
)
{
- if ((((TCG_PCR_EVENT2_HDR *)NewEventHdr)->EventType == EV_NO_ACTION) &&
- (NewEventSize >= sizeof (TCG_Sp800_155_PlatformId_Event2)) &&
- ((CompareMem (
- NewEventData,
- TCG_Sp800_155_PlatformId_Event2_SIGNATURE,
- sizeof (TCG_Sp800_155_PlatformId_Event2_SIGNATURE) - 1
- ) == 0) ||
- (CompareMem (
- NewEventData,
- TCG_Sp800_155_PlatformId_Event3_SIGNATURE,
- sizeof (TCG_Sp800_155_PlatformId_Event3_SIGNATURE) - 1
- ) == 0)))
+ if (((TCG_PCR_EVENT2_HDR *)NewEventHdr)->EventType != EV_NO_ACTION) {
+ return FALSE;
+ }
+
+ if ((NewEventSize >= sizeof (TCG_Sp800_155_PlatformId_Event2)) &&
+ (CompareMem (
+ NewEventData,
+ TCG_Sp800_155_PlatformId_Event2_SIGNATURE,
+ sizeof (TCG_Sp800_155_PlatformId_Event2_SIGNATURE) - 1
+ ) == 0))
+ {
+ return TRUE;
+ }
+
+ if ((NewEventSize >= sizeof (TCG_Sp800_155_PlatformId_Event3)) &&
+ (CompareMem (
+ NewEventData,
+ TCG_Sp800_155_PlatformId_Event3_SIGNATURE,
+ sizeof (TCG_Sp800_155_PlatformId_Event3_SIGNATURE) - 1
+ ) == 0))
{
return TRUE;
}
diff --git a/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c b/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c
index 52ea1ac..2b4164c 100644
--- a/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c
+++ b/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c
@@ -193,9 +193,19 @@ TcgExtractConfig (
// followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
//
ConfigRequestHdr = HiiConstructConfigHdr (&gTcgConfigFormSetGuid, mTcgStorageName, PrivateData->DriverHandle);
- Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
- ConfigRequest = AllocateZeroPool (Size);
- ASSERT (ConfigRequest != NULL);
+ if (ConfigRequestHdr == NULL) {
+ ASSERT (ConfigRequestHdr != NULL);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
+ ConfigRequest = AllocateZeroPool (Size);
+ if (ConfigRequest == NULL) {
+ ASSERT (ConfigRequest != NULL);
+ FreePool (ConfigRequestHdr);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
AllocatedRequest = TRUE;
UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, sizeof (TCG_CONFIGURATION));
FreePool (ConfigRequestHdr);
diff --git a/SecurityPkg/Tcg/TcgDxe/TcgDxe.c b/SecurityPkg/Tcg/TcgDxe/TcgDxe.c
index ee6c627..ea4516a 100644
--- a/SecurityPkg/Tcg/TcgDxe/TcgDxe.c
+++ b/SecurityPkg/Tcg/TcgDxe/TcgDxe.c
@@ -286,7 +286,10 @@ TpmCommHashAll (
CtxSize = Sha1GetContextSize ();
Sha1Ctx = AllocatePool (CtxSize);
- ASSERT (Sha1Ctx != NULL);
+ if (Sha1Ctx == NULL) {
+ ASSERT (Sha1Ctx != NULL);
+ return EFI_OUT_OF_RESOURCES;
+ }
Sha1Init (Sha1Ctx);
Sha1Update (Sha1Ctx, Data, DataLen);
diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c
index 5a23dc5..65b3f81 100644
--- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c
+++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFileExplorer.c
@@ -98,7 +98,11 @@ ExtractFileNameFromDevicePath (
ASSERT (DevicePath != NULL);
- String = DevicePathToStr (DevicePath);
+ String = DevicePathToStr (DevicePath);
+ if (String == NULL) {
+ return NULL;
+ }
+
MatchString = String;
LastMatch = String;
FileName = NULL;
diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c
index d262904..e79932d 100644
--- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c
+++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c
@@ -1095,7 +1095,7 @@ IsSignatureFoundInDatabase (
// Enumerate all signature data in SigDB to check if signature exists for executable.
//
CertList = (EFI_SIGNATURE_LIST *)Data;
- while ((DataSize > 0) && (DataSize >= CertList->SignatureListSize)) {
+ while ((DataSize > 0) && (DataSize >= (UINTN)CertList->SignatureListSize)) {
CertCount = (CertList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - CertList->SignatureHeaderSize) / CertList->SignatureSize;
Cert = (EFI_SIGNATURE_DATA *)((UINT8 *)CertList + sizeof (EFI_SIGNATURE_LIST) + CertList->SignatureHeaderSize);
if ((CertList->SignatureSize == sizeof (EFI_SIGNATURE_DATA) - 1 + SignatureSize) && (CompareGuid (&CertList->SignatureType, &gEfiCertX509Guid))) {
@@ -1173,7 +1173,10 @@ CalculateCertHash (
//
CtxSize = mHash[HashAlg].GetContextSize ();
HashCtx = AllocatePool (CtxSize);
- ASSERT (HashCtx != NULL);
+ if (HashCtx == NULL) {
+ ASSERT (HashCtx != NULL);
+ return FALSE;
+ }
//
// 2. Initialize a hash context.
@@ -1261,7 +1264,7 @@ IsCertHashFoundInDbx (
// Check whether the certificate hash exists in the forbidden database.
//
DbxList = (EFI_SIGNATURE_LIST *)Data;
- while ((DataSize > 0) && (DataSize >= DbxList->SignatureListSize)) {
+ while ((DataSize > 0) && (DataSize >= (UINTN)DbxList->SignatureListSize)) {
//
// Determine Hash Algorithm of Certificate in the forbidden database.
//
@@ -1348,7 +1351,7 @@ GetSignaturelistOffset (
SigList = Database;
SiglistSize = DatabaseSize;
- while ((SiglistSize > 0) && (SiglistSize >= SigList->SignatureListSize)) {
+ while ((SiglistSize > 0) && (SiglistSize >= (UINTN)SigList->SignatureListSize)) {
if (CompareGuid (&SigList->SignatureType, SignatureType)) {
*Offset = DatabaseSize - SiglistSize;
return TRUE;
@@ -1888,7 +1891,10 @@ HashPeImage (
CtxSize = mHash[HashAlg].GetContextSize ();
HashCtx = AllocatePool (CtxSize);
- ASSERT (HashCtx != NULL);
+ if (HashCtx == NULL) {
+ ASSERT (HashCtx != NULL);
+ goto Done;
+ }
// 1. Load the image header into memory.
@@ -2540,7 +2546,7 @@ UpdateDeletePage (
)
{
EFI_STATUS Status;
- UINT32 Index;
+ UINTN Index;
UINTN CertCount;
UINTN GuidIndex;
VOID *StartOpCodeHandle;
@@ -2724,7 +2730,7 @@ DeleteKeyExchangeKey (
UINT8 *Data;
UINT8 *OldData;
UINT32 Attr;
- UINT32 Index;
+ UINTN Index;
EFI_SIGNATURE_LIST *CertList;
EFI_SIGNATURE_LIST *NewCertList;
EFI_SIGNATURE_DATA *Cert;
@@ -2928,7 +2934,7 @@ DeleteSignature (
UINT8 *Data;
UINT8 *OldData;
UINT32 Attr;
- UINT32 Index;
+ UINTN Index;
EFI_SIGNATURE_LIST *CertList;
EFI_SIGNATURE_LIST *NewCertList;
EFI_SIGNATURE_DATA *Cert;
@@ -3206,7 +3212,7 @@ DeleteSignatureEx (
//
// Traverse to target EFI_SIGNATURE_LIST but others will be skipped.
//
- while ((RemainingSize > 0) && (RemainingSize >= ListWalker->SignatureListSize) && ListIndex < PrivateData->ListIndex) {
+ while ((RemainingSize > 0) && (RemainingSize >= (UINTN)ListWalker->SignatureListSize) && ListIndex < PrivateData->ListIndex) {
CopyMem ((UINT8 *)NewVariableData + Offset, ListWalker, ListWalker->SignatureListSize);
Offset += ListWalker->SignatureListSize;
@@ -3513,9 +3519,19 @@ SecureBootExtractConfig (
// followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
//
ConfigRequestHdr = HiiConstructConfigHdr (&gSecureBootConfigFormSetGuid, mSecureBootStorageName, PrivateData->DriverHandle);
- Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
- ConfigRequest = AllocateZeroPool (Size);
- ASSERT (ConfigRequest != NULL);
+ if (ConfigRequestHdr == NULL) {
+ ASSERT (ConfigRequestHdr != NULL);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
+ ConfigRequest = AllocateZeroPool (Size);
+ if (ConfigRequest == NULL) {
+ ASSERT (ConfigRequest != NULL);
+ FreePool (ConfigRequestHdr);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
AllocatedRequest = TRUE;
UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);
FreePool (ConfigRequestHdr);
@@ -3794,7 +3810,7 @@ LoadSignatureList (
RemainingSize = DataSize;
ListWalker = (EFI_SIGNATURE_LIST *)VariableData;
- while ((RemainingSize > 0) && (RemainingSize >= ListWalker->SignatureListSize)) {
+ while ((RemainingSize > 0) && (RemainingSize >= (UINTN)ListWalker->SignatureListSize)) {
if (CompareGuid (&ListWalker->SignatureType, &gEfiCertRsa2048Guid)) {
ListType = STRING_TOKEN (STR_LIST_TYPE_RSA2048_SHA256);
} else if (CompareGuid (&ListWalker->SignatureType, &gEfiCertX509Guid)) {
@@ -4210,7 +4226,7 @@ LoadSignatureData (
VOID *EndOpCodeHandle;
UINTN DataSize;
UINTN RemainingSize;
- UINT16 Index;
+ UINT64 Index;
UINT8 *VariableData;
CHAR16 VariableName[BUFFER_MAX_SIZE];
CHAR16 NameBuffer[BUFFER_MAX_SIZE];
@@ -4294,7 +4310,7 @@ LoadSignatureData (
//
// Skip signature list.
//
- while ((RemainingSize > 0) && (RemainingSize >= ListWalker->SignatureListSize) && ListIndex-- > 0) {
+ while ((RemainingSize > 0) && (RemainingSize >= (UINTN)ListWalker->SignatureListSize) && ListIndex-- > 0) {
RemainingSize -= ListWalker->SignatureListSize;
ListWalker = (EFI_SIGNATURE_LIST *)((UINT8 *)ListWalker + ListWalker->SignatureListSize);
}
diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c
index 483fe4d..ae3e943 100644
--- a/ShellPkg/Application/Shell/Shell.c
+++ b/ShellPkg/Application/Shell/Shell.c
@@ -1262,9 +1262,11 @@ LocateStartupScript (
InternalEfiShellSetEnv (L"homefilesystem", StartupScriptPath, TRUE);
- StartupScriptPath = StrnCatGrow (&StartupScriptPath, &Size, ((FILEPATH_DEVICE_PATH *)FileDevicePath)->PathName, 0);
- PathRemoveLastItem (StartupScriptPath);
- StartupScriptPath = StrnCatGrow (&StartupScriptPath, &Size, mStartupScript, 0);
+ if ((DevicePathType (FileDevicePath) == MEDIA_DEVICE_PATH) && (DevicePathSubType (FileDevicePath) == MEDIA_FILEPATH_DP)) {
+ StartupScriptPath = StrnCatGrow (&StartupScriptPath, &Size, ((FILEPATH_DEVICE_PATH *)FileDevicePath)->PathName, 0);
+ PathRemoveLastItem (StartupScriptPath);
+ StartupScriptPath = StrnCatGrow (&StartupScriptPath, &Size, mStartupScript, 0);
+ }
}
//
diff --git a/ShellPkg/Application/Shell/ShellEnvVar.c b/ShellPkg/Application/Shell/ShellEnvVar.c
index b97cfe9..9e84d7f 100644
--- a/ShellPkg/Application/Shell/ShellEnvVar.c
+++ b/ShellPkg/Application/Shell/ShellEnvVar.c
@@ -285,19 +285,23 @@ SetEnvironmentVariableList (
//
// set all the variables from the list
//
- for ( Node = (ENV_VAR_LIST *)GetFirstNode (ListHead)
- ; !IsNull (ListHead, &Node->Link)
- ; Node = (ENV_VAR_LIST *)GetNextNode (ListHead, &Node->Link)
- )
- {
- Size = StrSize (Node->Val) - sizeof (CHAR16);
- if (Node->Atts & EFI_VARIABLE_NON_VOLATILE) {
- Status = SHELL_SET_ENVIRONMENT_VARIABLE_NV (Node->Key, Size, Node->Val);
- } else {
- Status = SHELL_SET_ENVIRONMENT_VARIABLE_V (Node->Key, Size, Node->Val);
- }
+ if ((ListHead != NULL) && !IsListEmpty (ListHead)) {
+ for ( Node = (ENV_VAR_LIST *)GetFirstNode (ListHead)
+ ; !IsNull (ListHead, &Node->Link)
+ ; Node = (ENV_VAR_LIST *)GetNextNode (ListHead, &Node->Link)
+ )
+ {
+ if ((Node->Key != NULL) && (Node->Val != NULL)) {
+ Size = StrSize (Node->Val) - sizeof (CHAR16);
+ if (Node->Atts & EFI_VARIABLE_NON_VOLATILE) {
+ Status = SHELL_SET_ENVIRONMENT_VARIABLE_NV (Node->Key, Size, Node->Val);
+ } else {
+ Status = SHELL_SET_ENVIRONMENT_VARIABLE_V (Node->Key, Size, Node->Val);
+ }
- ASSERT_EFI_ERROR (Status);
+ ASSERT_EFI_ERROR (Status);
+ }
+ }
}
FreeEnvironmentVariableList (ListHead);
@@ -441,7 +445,7 @@ ShellFindEnvVarInList (
; Node = (ENV_VAR_LIST *)GetNextNode (&gShellEnvVarList.Link, &Node->Link)
)
{
- if ((Node->Key != NULL) && (StrCmp (Key, Node->Key) == 0)) {
+ if ((Node->Key != NULL) && (StrCmp (Key, Node->Key) == 0) && (Node->Val != NULL)) {
*Value = AllocateCopyPool (StrSize (Node->Val), Node->Val);
*ValueSize = StrSize (Node->Val);
if (Atts != NULL) {
diff --git a/ShellPkg/Application/Shell/ShellProtocol.c b/ShellPkg/Application/Shell/ShellProtocol.c
index 3bc6239..646294d 100644
--- a/ShellPkg/Application/Shell/ShellProtocol.c
+++ b/ShellPkg/Application/Shell/ShellProtocol.c
@@ -2853,7 +2853,11 @@ EfiShellGetEnvEx (
; Node = (ENV_VAR_LIST *)GetNextNode (&gShellEnvVarList.Link, &Node->Link)
)
{
- ASSERT (Node->Key != NULL);
+ if (Node->Key == NULL) {
+ ASSERT (FALSE);
+ continue;
+ }
+
Size += StrSize (Node->Key);
}
diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
index b0c77e4..44c2ed9 100644
--- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
+++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
@@ -398,7 +398,11 @@ ShellCommandIsCommandOnInternalList (
; Node = (SHELL_COMMAND_INTERNAL_LIST_ENTRY *)GetNextNode (&mCommandList.Link, &Node->Link)
)
{
- ASSERT (Node->CommandString != NULL);
+ if (Node->CommandString == NULL) {
+ ASSERT (FALSE);
+ continue;
+ }
+
if (gUnicodeCollation->StriColl (
gUnicodeCollation,
(CHAR16 *)CommandString,
@@ -485,7 +489,11 @@ ShellCommandGetInternalCommandHelp (
; Node = (SHELL_COMMAND_INTERNAL_LIST_ENTRY *)GetNextNode (&mCommandList.Link, &Node->Link)
)
{
- ASSERT (Node->CommandString != NULL);
+ if (Node->CommandString == NULL) {
+ ASSERT (FALSE);
+ continue;
+ }
+
if (gUnicodeCollation->StriColl (
gUnicodeCollation,
(CHAR16 *)CommandString,
@@ -672,23 +680,25 @@ ShellCommandRegisterCommandName (
//
// Get Lexical Comparison Value between PrevCommand and Command list entry
//
- LexicalMatchValue = gUnicodeCollation->StriColl (
- gUnicodeCollation,
- PrevCommand->CommandString,
- Command->CommandString
- );
+ if ((PrevCommand->CommandString != NULL) && (Command->CommandString != NULL)) {
+ LexicalMatchValue = gUnicodeCollation->StriColl (
+ gUnicodeCollation,
+ PrevCommand->CommandString,
+ Command->CommandString
+ );
- //
- // Swap PrevCommand and Command list entry if PrevCommand list entry
- // is alphabetically greater than Command list entry
- //
- if (LexicalMatchValue > 0) {
- Command = (SHELL_COMMAND_INTERNAL_LIST_ENTRY *)SwapListEntries (&PrevCommand->Link, &Command->Link);
- } else if (LexicalMatchValue < 0) {
//
- // PrevCommand entry is lexically lower than Command entry
+ // Swap PrevCommand and Command list entry if PrevCommand list entry
+ // is alphabetically greater than Command list entry
//
- break;
+ if (LexicalMatchValue > 0) {
+ Command = (SHELL_COMMAND_INTERNAL_LIST_ENTRY *)SwapListEntries (&PrevCommand->Link, &Command->Link);
+ } else if (LexicalMatchValue < 0) {
+ //
+ // PrevCommand entry is lexically lower than Command entry
+ //
+ break;
+ }
}
}
@@ -758,7 +768,11 @@ ShellCommandRunCommandHandler (
; Node = (SHELL_COMMAND_INTERNAL_LIST_ENTRY *)GetNextNode (&mCommandList.Link, &Node->Link)
)
{
- ASSERT (Node->CommandString != NULL);
+ if (Node->CommandString == NULL) {
+ ASSERT (FALSE);
+ continue;
+ }
+
if (gUnicodeCollation->StriColl (
gUnicodeCollation,
(CHAR16 *)CommandString,
@@ -831,7 +845,11 @@ ShellCommandGetManFileNameHandler (
; Node = (SHELL_COMMAND_INTERNAL_LIST_ENTRY *)GetNextNode (&mCommandList.Link, &Node->Link)
)
{
- ASSERT (Node->CommandString != NULL);
+ if (Node->CommandString == NULL) {
+ ASSERT (FALSE);
+ continue;
+ }
+
if (gUnicodeCollation->StriColl (
gUnicodeCollation,
(CHAR16 *)CommandString,
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c
index dd3d7a7..37bccea 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c
@@ -491,6 +491,11 @@ ShellCommandRunDmem (
continue;
}
+ if (CompareGuid (&gST->ConfigurationTable[TableWalker].VendorGuid, &gFdtTableGuid)) {
+ DtbTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;
+ continue;
+ }
+
if (CompareGuid (&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiMemoryAttributesTableGuid)) {
MemoryAttributesTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;
continue;
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c
index 42d766e..bf68eb1 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c
@@ -3011,7 +3011,7 @@ DisplayMmBankConnections (
//
// Divide it to high and low
//
- High = (UINT8)(BankConnections & 0xF0);
+ High = (UINT8)((BankConnections & 0xF0)>>4);
Low = (UINT8)(BankConnections & 0x0F);
if (High != 0xF) {
if (Low != 0xF) {
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf
index 91b48e8..0f4068d 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf
@@ -96,6 +96,7 @@
MdePkg/MdePkg.dec
ShellPkg/ShellPkg.dec
MdeModulePkg/MdeModulePkg.dec
+ EmbeddedPkg/EmbeddedPkg.dec
[LibraryClasses]
MemoryAllocationLib
@@ -144,3 +145,4 @@
gEfiConfProfilesUefiSpecGuid ## SOMETIMES_CONSUMES ## GUID
gEfiConfProfilesEbbrSpec21Guid ## SOMETIMES_CONSUMES ## GUID
gEfiConfProfilesEbbrSpec22Guid ## SOMETIMES_CONSUMES ## GUID
+ gFdtTableGuid ## SOMETIMES_CONSUMES ## SystemTable
diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c b/ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c
index 4f39863..3bec32b 100644
--- a/ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c
+++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c
@@ -520,10 +520,6 @@ ShellCommandRunConnect (
}
Handle1 = ConvertHandleIndexToHandle ((UINTN)Intermediate);
- if (EFI_ERROR (Status)) {
- ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"connect", Param1);
- ShellStatus = SHELL_INVALID_PARAMETER;
- }
} else {
Handle1 = NULL;
}
diff --git a/ShellPkg/ShellPkg.ci.yaml b/ShellPkg/ShellPkg.ci.yaml
index 2c3a70d..4f5c69d 100644
--- a/ShellPkg/ShellPkg.ci.yaml
+++ b/ShellPkg/ShellPkg.ci.yaml
@@ -35,6 +35,7 @@
"MdePkg/MdePkg.dec",
"MdeModulePkg/MdeModulePkg.dec",
"ShellPkg/ShellPkg.dec",
+ "EmbeddedPkg/EmbeddedPkg.dec",
"NetworkPkg/NetworkPkg.dec"
],
# For host based unit tests
diff --git a/StandaloneMmPkg/Core/Dispatcher.c b/StandaloneMmPkg/Core/Dispatcher.c
index 821d9d6..086532e 100644
--- a/StandaloneMmPkg/Core/Dispatcher.c
+++ b/StandaloneMmPkg/Core/Dispatcher.c
@@ -143,6 +143,9 @@ MmLoadImage (
UINTN PageCount;
EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS DstBuffer;
+ UINTN Index;
+ UINTN StartIndex;
+ CHAR8 EfiFileName[512];
DEBUG ((DEBUG_INFO, "MmLoadImage - %g\n", &DriverEntry->FileName));
@@ -254,11 +257,6 @@ MmLoadImage (
//
// Print the load address and the PDB file name if it is available
//
- DEBUG_CODE_BEGIN ();
-
- UINTN Index;
- UINTN StartIndex;
- CHAR8 EfiFileName[256];
DEBUG ((
DEBUG_INFO | DEBUG_LOAD,
@@ -308,8 +306,6 @@ MmLoadImage (
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "\n"));
- DEBUG_CODE_END ();
-
return Status;
}
diff --git a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandlerLib.inf b/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandlerLib.inf
deleted file mode 100644
index d804629..0000000
--- a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandlerLib.inf
+++ /dev/null
@@ -1,42 +0,0 @@
-## @file
-# RISC-V CPU Exception Handler Library
-#
-# Copyright (c) 2022-2023, Ventana Micro Systems Inc. All rights reserved.<BR>
-#
-# SPDX-License-Identifier: BSD-2-Clause-Patent
-#
-##
-
-[Defines]
- INF_VERSION = 0x0001001B
- BASE_NAME = BaseRiscV64CpuExceptionHandlerLib
- MODULE_UNI_FILE = BaseRiscV64CpuExceptionHandlerLib.uni
- FILE_GUID = 6AB0D5FD-E615-45A3-9374-E284FB061FC9
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = CpuExceptionHandlerLib
-
-#
-# The following information is for reference only and not required by the build tools.
-#
-# VALID_ARCHITECTURES = RISCV64
-#
-
-[Sources]
- SupervisorTrapHandler.S
- CpuExceptionHandlerLib.c
- CpuExceptionHandlerLib.h
-
-[Packages]
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
- UefiCpuPkg/UefiCpuPkg.dec
-
-[LibraryClasses]
- BaseLib
- SerialPortLib
- PrintLib
- SynchronizationLib
- PeCoffGetEntryPointLib
- MemoryAllocationLib
- DebugLib
diff --git a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandlerLib.uni b/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandlerLib.uni
deleted file mode 100644
index 00cca22..0000000
--- a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandlerLib.uni
+++ /dev/null
@@ -1,13 +0,0 @@
-// /** @file
-//
-// Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
-//
-// SPDX-License-Identifier: BSD-2-Clause-Patent
-//
-// **/
-
-
-#string STR_MODULE_ABSTRACT #language en-US "RISC-V CPU Exception Handler Librarys."
-
-#string STR_MODULE_DESCRIPTION #language en-US "RISC-V CPU Exception Handler Librarys."
-
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
index 9fcba00..9e0b54e 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
@@ -19,7 +19,7 @@
#
# The following information is for reference only and not required by the build tools.
#
-# VALID_ARCHITECTURES = IA32 X64 LOONGARCH64
+# VALID_ARCHITECTURES = IA32 X64 LOONGARCH64 RISCV64
#
[Sources.Ia32]
@@ -46,6 +46,14 @@
LoongArch/LoongArch64/ArchExceptionHandler.c
LoongArch/LoongArch64/ExceptionHandlerAsm.S | GCC
+[Sources.RISCV64]
+ RiscV/Backtrace.h
+ RiscV/Backtrace.c
+ RiscV/BacktraceHelper.c
+ RiscV/ExceptionLib.c
+ RiscV/ExceptionHandler.h
+ RiscV/ExceptionHandlerAsm.S | GCC
+
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard
gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList
@@ -75,5 +83,8 @@
[LibraryClasses.LoongArch64]
CpuLib
+[Guids.RISCV64]
+ gEfiDebugImageInfoTableGuid
+
[BuildOptions]
XCODE:*_*_X64_NASM_FLAGS = -D NO_ABSOLUTE_RELOCS_IN_TEXT
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/Backtrace.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/Backtrace.c
new file mode 100644
index 0000000..9765d72
--- /dev/null
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/Backtrace.c
@@ -0,0 +1,175 @@
+/** @file
+ RISC-V backtrace implementation.
+
+ Copyright (c) 2016 - 2022, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+ Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>
+ Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2025, Ventana Micro Systems Inc. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "Backtrace.h"
+
+#define MAX_STACK_FRAME_SIZE SIZE_16KB
+
+STATIC
+INTN
+CheckFpValid (
+ IN UINTN Fp,
+ IN UINTN Sp
+ )
+{
+ UINTN Low, High;
+
+ Low = Sp + 2 * sizeof (UINTN);
+ High = ALIGN_VALUE (Sp, MAX_STACK_FRAME_SIZE);
+
+ return !(Fp < Low || Fp > High || Fp & 0x07);
+}
+
+STATIC
+CONST CHAR8 *
+BaseName (
+ IN CONST CHAR8 *FullName
+ )
+{
+ CONST CHAR8 *Str;
+
+ Str = FullName + AsciiStrLen (FullName);
+
+ while (--Str > FullName) {
+ if ((*Str == '/') || (*Str == '\\')) {
+ return Str + 1;
+ }
+ }
+
+ return Str;
+}
+
+/**
+ Helper for displaying a backtrace.
+
+ @param Regs Pointer to SMODE_TRAP_REGISTERS.
+ @param FirstPdb Pointer to the first symbol file used.
+ @param ListImage If true, only show the full path to symbol file, else
+ show the PC value and its decoded components.
+**/
+STATIC
+VOID
+DumpCpuBacktraceHelper (
+ IN SMODE_TRAP_REGISTERS *Regs,
+ IN CHAR8 *FirstPdb,
+ IN BOOLEAN ListImage
+ )
+{
+ UINTN ImageBase;
+ UINTN PeCoffSizeOfHeader;
+ BOOLEAN IsLeaf;
+ UINTN RootFp;
+ UINTN RootRa;
+ UINTN Sp;
+ UINTN Fp;
+ UINTN Ra;
+ UINTN Idx;
+ CHAR8 *Pdb;
+ CHAR8 *PrevPdb;
+
+ RootRa = Regs->ra;
+ RootFp = Regs->s0;
+
+ Idx = 0;
+ IsLeaf = TRUE;
+ Fp = RootFp;
+ Ra = RootRa;
+ PrevPdb = FirstPdb;
+ while (Fp != 0) {
+ Pdb = GetImageName (Ra, &ImageBase, &PeCoffSizeOfHeader);
+ if (Pdb != NULL) {
+ if (Pdb != PrevPdb) {
+ Idx++;
+ if (ListImage) {
+ DEBUG ((DEBUG_ERROR, "[% 2d] %a\n", Idx, Pdb));
+ }
+
+ PrevPdb = Pdb;
+ }
+
+ if (!ListImage) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "PC 0x%012lx (0x%012lx+0x%08x) [% 2d] %a\n",
+ Ra,
+ ImageBase,
+ Ra - ImageBase,
+ Idx,
+ BaseName (Pdb)
+ ));
+ }
+ } else if (!ListImage) {
+ DEBUG ((DEBUG_ERROR, "PC 0x%012lx\n", Ra));
+ }
+
+ /*
+ * After the prologue, the frame pointer register s0 will point
+ * to the Canonical Frame Address or CFA, which is the stack
+ * pointer value on entry to the current procedure. The previous
+ * frame pointer and return address pair will reside just prior
+ * to the current stack address held in s0. This puts the return
+ * address at s0 - XLEN/8, and the previous frame pointer at
+ * s0 - 2 * XLEN/8.
+ */
+ Sp = Fp;
+ Fp -= sizeof (UINTN) * 2;
+ Ra = *(UINTN *)(Fp + sizeof (UINTN));
+ Fp = *(UINTN *)(Fp);
+ if (IsLeaf && CheckFpValid (Ra, Sp)) {
+ /* We hit function where ra is not saved on the stack */
+ Fp = Ra;
+ Ra = RootRa;
+ }
+
+ IsLeaf = FALSE;
+ }
+}
+
+/**
+ Display a backtrace.
+
+ @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
+**/
+VOID
+EFIAPI
+DumpCpuBacktrace (
+ IN EFI_SYSTEM_CONTEXT SystemContext
+ )
+{
+ SMODE_TRAP_REGISTERS *Regs;
+ CHAR8 *Pdb;
+ UINTN ImageBase;
+ UINTN PeCoffSizeOfHeader;
+
+ Regs = (SMODE_TRAP_REGISTERS *)SystemContext.SystemContextRiscV64;
+ Pdb = GetImageName (Regs->sepc, &ImageBase, &PeCoffSizeOfHeader);
+ if (Pdb != NULL) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "PC 0x%012lx (0x%012lx+0x%08x) [ 0] %a\n",
+ Regs->sepc,
+ ImageBase,
+ Regs->sepc - ImageBase,
+ BaseName (Pdb)
+ ));
+ } else {
+ DEBUG ((DEBUG_ERROR, "PC 0x%012lx\n", Regs->sepc));
+ }
+
+ DumpCpuBacktraceHelper (Regs, Pdb, FALSE);
+
+ if (Pdb != NULL) {
+ DEBUG ((DEBUG_ERROR, "\n[ 0] %a\n", Pdb));
+ }
+
+ DumpCpuBacktraceHelper (Regs, Pdb, TRUE);
+}
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/Backtrace.h b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/Backtrace.h
new file mode 100644
index 0000000..6e29b90
--- /dev/null
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/Backtrace.h
@@ -0,0 +1,57 @@
+/** @file
+
+ RISC-V backtrace definition file.
+
+ Copyright (c) 2025, Ventana Micro Systems Inc. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef BACKTRACE_H_
+#define BACKTRACE_H_
+
+#include <PiPei.h>
+#include <Uefi.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseLib.h>
+#include <Library/PeCoffExtraActionLib.h>
+#include <Library/PeCoffGetEntryPointLib.h>
+#include <Library/UefiLib.h>
+#include <Guid/DebugImageInfoTable.h>
+#include "ExceptionHandler.h"
+
+/**
+ Use the EFI Debug Image Table to lookup the FaultAddress and find which PE/COFF image
+ it came from. As long as the PE/COFF image contains a debug directory entry a
+ string can be returned. For ELF and Mach-O images the string points to the Mach-O or ELF
+ image. Microsoft tools contain a pointer to the PDB file that contains the debug information.
+
+ @param FaultAddress Address to find PE/COFF image for.
+ @param ImageBase Return load address of found image
+ @param PeCoffSizeOfHeaders Return the size of the PE/COFF header for the image that was found
+
+ @retval NULL FaultAddress not in a loaded PE/COFF image.
+ @retval Path and file name of PE/COFF image.
+
+**/
+CHAR8 *
+EFIAPI
+GetImageName (
+ IN UINTN FaultAddress,
+ OUT UINTN *ImageBase,
+ OUT UINTN *PeCoffSizeOfHeaders
+ );
+
+/**
+ Display a backtrace.
+
+ @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
+**/
+VOID
+EFIAPI
+DumpCpuBacktrace (
+ IN EFI_SYSTEM_CONTEXT SystemContext
+ );
+
+#endif // BACKTRACE_H_
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/BacktraceHelper.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/BacktraceHelper.c
new file mode 100644
index 0000000..fdc5666
--- /dev/null
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/BacktraceHelper.c
@@ -0,0 +1,71 @@
+/** @file
+ RISC-V backtrace helper functions.
+
+ Copyright (c) 2016 - 2022, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+ Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>
+ Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2025, Ventana Micro Systems Inc. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "Backtrace.h"
+
+/**
+ Use the EFI Debug Image Table to lookup the FaultAddress and find which PE/COFF image
+ it came from. As long as the PE/COFF image contains a debug directory entry a
+ string can be returned. For ELF and Mach-O images the string points to the Mach-O or ELF
+ image. Microsoft tools contain a pointer to the PDB file that contains the debug information.
+
+ @param FaultAddress Address to find PE/COFF image for.
+ @param ImageBase Return load address of found image
+ @param PeCoffSizeOfHeaders Return the size of the PE/COFF header for the image that was found
+
+ @retval NULL FaultAddress not in a loaded PE/COFF image.
+ @retval Path and file name of PE/COFF image.
+
+**/
+CHAR8 *
+EFIAPI
+GetImageName (
+ IN UINTN FaultAddress,
+ OUT UINTN *ImageBase,
+ OUT UINTN *PeCoffSizeOfHeaders
+ )
+{
+ EFI_STATUS Status;
+ EFI_DEBUG_IMAGE_INFO_TABLE_HEADER *DebugTableHeader;
+ EFI_DEBUG_IMAGE_INFO *DebugTable;
+ UINTN Entry;
+ CHAR8 *Address;
+
+ Status = EfiGetSystemConfigurationTable (&gEfiDebugImageInfoTableGuid, (VOID **)&DebugTableHeader);
+ if (EFI_ERROR (Status)) {
+ return NULL;
+ }
+
+ DebugTable = DebugTableHeader->EfiDebugImageInfoTable;
+ if (DebugTable == NULL) {
+ return NULL;
+ }
+
+ Address = (CHAR8 *)(UINTN)FaultAddress;
+ for (Entry = 0; Entry < DebugTableHeader->TableSize; Entry++, DebugTable++) {
+ if (DebugTable->NormalImage != NULL) {
+ if ((DebugTable->NormalImage->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) &&
+ (DebugTable->NormalImage->LoadedImageProtocolInstance != NULL))
+ {
+ if ((Address >= (CHAR8 *)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase) &&
+ (Address <= ((CHAR8 *)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase + DebugTable->NormalImage->LoadedImageProtocolInstance->ImageSize)))
+ {
+ *ImageBase = (UINTN)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase;
+ *PeCoffSizeOfHeaders = PeCoffGetSizeOfHeaders ((VOID *)(UINTN)*ImageBase);
+ return PeCoffLoaderGetPdbPointer (DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase);
+ }
+ }
+ }
+ }
+
+ return NULL;
+}
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/BacktraceHelperSec.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/BacktraceHelperSec.c
new file mode 100644
index 0000000..10e3497
--- /dev/null
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/BacktraceHelperSec.c
@@ -0,0 +1,42 @@
+/** @file
+ RISC-V backtrace helper functions for SEC.
+
+ Copyright (c) 2025, Ventana Micro Systems Inc. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "Backtrace.h"
+
+/**
+ Use the EFI Debug Image Table to lookup the FaultAddress and find which PE/COFF image
+ it came from. As long as the PE/COFF image contains a debug directory entry a
+ string can be returned. For ELF and Mach-O images the string points to the Mach-O or ELF
+ image. Microsoft tools contain a pointer to the PDB file that contains the debug information.
+
+ @param FaultAddress Address to find PE/COFF image for.
+ @param ImageBase Return load address of found image
+ @param PeCoffSizeOfHeaders Return the size of the PE/COFF header for the image that was found
+
+ @retval NULL FaultAddress not in a loaded PE/COFF image.
+ @retval Path and file name of PE/COFF image.
+
+**/
+CHAR8 *
+EFIAPI
+GetImageName (
+ IN UINTN FaultAddress,
+ OUT UINTN *ImageBase,
+ OUT UINTN *PeCoffSizeOfHeaders
+ )
+{
+ //
+ // This function is not implemented in SEC phase.
+ // It should be implemented in DXE phase.
+ //
+ *ImageBase = 0;
+ *PeCoffSizeOfHeaders = 0;
+
+ return NULL;
+}
diff --git a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandlerLib.h b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/ExceptionHandler.h
index 9b7e130..0cf8221 100644
--- a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandlerLib.h
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/ExceptionHandler.h
@@ -8,16 +8,16 @@
**/
-#ifndef RISCV_CPU_EXECPTION_HANDLER_LIB_H_
-#define RISCV_CPU_EXECPTION_HANDLER_LIB_H_
+#ifndef EXCEPTION_HANDLER_H_
+#define EXCEPTION_HANDLER_H_
#include <Register/RiscV64/RiscVImpl.h>
/**
Trap Handler for S-mode
-
**/
VOID
+EFIAPI
SupervisorModeTrap (
VOID
);
@@ -108,4 +108,4 @@ typedef struct {
} SMODE_TRAP_REGISTERS;
#pragma pack()
-#endif
+#endif /* EXCEPTION_HANDLER_H_ */
diff --git a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/SupervisorTrapHandler.S b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/ExceptionHandlerAsm.S
index 45070b5..815e28b 100644
--- a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/SupervisorTrapHandler.S
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/ExceptionHandlerAsm.S
@@ -8,7 +8,7 @@
**/
#include <Base.h>
-#include "CpuExceptionHandlerLib.h"
+#include "ExceptionHandler.h"
.align 3
.section .entry, "ax", %progbits
diff --git a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandlerLib.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/ExceptionLib.c
index 73a9dd5..d19c992 100644
--- a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandlerLib.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/ExceptionLib.c
@@ -2,6 +2,9 @@
RISC-V Exception Handler library implementation.
Copyright (c) 2016 - 2022, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+ Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>
+ Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2025, Ventana Micro Systems Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -14,7 +17,8 @@
#include <Library/SerialPortLib.h>
#include <Library/PrintLib.h>
#include <Register/RiscV64/RiscVEncoding.h>
-#include "CpuExceptionHandlerLib.h"
+#include "Backtrace.h"
+#include "ExceptionHandler.h"
//
// Define the maximum message length
@@ -136,11 +140,21 @@ DumpCpuContext (
)
{
UINTN Printed;
+ UINTN RecursiveException;
SMODE_TRAP_REGISTERS *Regs;
Printed = 0;
Regs = (SMODE_TRAP_REGISTERS *)SystemContext.SystemContextRiscV64;
+ RecursiveException = RiscVGetSupervisorScratch ();
+ if (RecursiveException == 0xdeaddead) {
+ InternalPrintMessage ("\nRecursive exception occurred while dumping the CPU state\n");
+
+ CpuDeadLoop ();
+ }
+
+ RiscVSetSupervisorScratch ((UINTN)0xdeaddead);
+
InternalPrintMessage (
"!!!! RISCV64 Exception Type - %016x(%a) !!!!\n",
ExceptionType,
@@ -171,6 +185,8 @@ DumpCpuContext (
#undef REG
#undef REGS
+ DumpCpuBacktrace (SystemContext);
+
DEBUG_CODE_END ();
}
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
index 64de252..00a5b49 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
@@ -20,7 +20,7 @@
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64
-# VALID_ARCHITECTURES = IA32 X64 LOONGARCH64
+# VALID_ARCHITECTURES = IA32 X64 LOONGARCH64 RISCV64
#
[Sources.Ia32]
@@ -46,6 +46,13 @@
LoongArch/LoongArch64/ArchExceptionHandler.c
LoongArch/LoongArch64/ExceptionHandlerAsm.S | GCC
+[Sources.RISCV64]
+ RiscV/Backtrace.h
+ RiscV/Backtrace.c
+ RiscV/BacktraceHelperSec.c
+ RiscV/ExceptionLib.c
+ RiscV/ExceptionHandler.h
+ RiscV/ExceptionHandlerAsm.S | GCC
[Packages]
MdePkg/MdePkg.dec
diff --git a/UefiCpuPkg/Library/MpInitLib/AmdSev.c b/UefiCpuPkg/Library/MpInitLib/AmdSev.c
index 5108873..8ffb1b5 100644
--- a/UefiCpuPkg/Library/MpInitLib/AmdSev.c
+++ b/UefiCpuPkg/Library/MpInitLib/AmdSev.c
@@ -273,7 +273,7 @@ SevEsPlaceApHlt (
@param[in] ExchangeInfo The pointer to CPU Exchange Data structure
**/
VOID
-FillExchangeInfoDataSevEs (
+FillExchangeInfoDataSevSnp (
IN volatile MP_CPU_EXCHANGE_INFO *ExchangeInfo
)
{
@@ -293,8 +293,6 @@ FillExchangeInfoDataSevEs (
);
ExchangeInfo->ExtTopoAvail = !!ExtTopoEbx.Bits.LogicalProcessors;
}
-
- ExchangeInfo->SevSnpKnownInitApicId = FALSE;
}
/**
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 96c0980..63b8464 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -1018,15 +1018,17 @@ FillExchangeInfoData (
ExchangeInfo->Enable5LevelPaging = (BOOLEAN)(Cr4.Bits.LA57 == 1);
DEBUG ((DEBUG_INFO, "%a: 5-Level Paging = %d\n", gEfiCallerBaseName, ExchangeInfo->Enable5LevelPaging));
- ExchangeInfo->SevEsIsEnabled = CpuMpData->SevEsIsEnabled;
- ExchangeInfo->SevSnpIsEnabled = CpuMpData->SevSnpIsEnabled;
- ExchangeInfo->GhcbBase = (UINTN)CpuMpData->GhcbBase;
+ ExchangeInfo->SevEsIsEnabled = CpuMpData->SevEsIsEnabled;
+ ExchangeInfo->SevSnpIsEnabled = CpuMpData->SevSnpIsEnabled;
+ ExchangeInfo->GhcbBase = (UINTN)CpuMpData->GhcbBase;
+ ExchangeInfo->ExtTopoAvail = FALSE;
+ ExchangeInfo->SevSnpKnownInitApicId = FALSE;
//
- // Populate SEV-ES specific exchange data.
+ // Populate SEV-SNP specific exchange data.
//
if (ExchangeInfo->SevSnpIsEnabled) {
- FillExchangeInfoDataSevEs (ExchangeInfo);
+ FillExchangeInfoDataSevSnp (ExchangeInfo);
}
//
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index 60cae3b..5d10516 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -901,7 +901,7 @@ ConfidentialComputingGuestHas (
@param[in] ExchangeInfo The pointer to CPU Exchange Data structure
**/
VOID
-FillExchangeInfoDataSevEs (
+FillExchangeInfoDataSevSnp (
IN volatile MP_CPU_EXCHANGE_INFO *ExchangeInfo
);
diff --git a/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm b/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm
index 66d63a2..64358e5 100644
--- a/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm
+++ b/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm
@@ -24,13 +24,6 @@
;
SevSnpGetInitCpuNumber:
;
- ; If not an SNP guest, leave EBX (CpuNumber) as is
- ;
- lea edi, [esi + MP_CPU_EXCHANGE_INFO_FIELD (SevSnpIsEnabled)]
- cmp byte [edi], 1 ; SevSnpIsEnabled
- jne SevSnpGetCpuNumberDone
-
- ;
; If not starting the AP with a specific ApicId, leave EBX (CpuNumber) as is
;
lea edi, [esi + MP_CPU_EXCHANGE_INFO_FIELD (SevSnpKnownInitApicId)]
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
index 47ae9fd..1d53b78 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
@@ -236,12 +236,14 @@ SmmWaitForApArrival (
UINTN Index;
UINT32 DelayedCount;
UINT32 BlockedCount;
+ UINT32 DisabledCount;
BOOLEAN SyncNeeded;
PERF_FUNCTION_BEGIN ();
- DelayedCount = 0;
- BlockedCount = 0;
+ DelayedCount = 0;
+ BlockedCount = 0;
+ DisabledCount = 0;
ASSERT (SmmCpuSyncGetArrivedCpuCount (mSmmMpSyncData->SyncContext) <= mNumberOfCpus);
@@ -321,10 +323,10 @@ SmmWaitForApArrival (
mSmmMpSyncData->AllApArrivedWithException = AllCpusInSmmExceptBlockedDisabled ();
if (!mSmmMpSyncData->AllApArrivedWithException) {
//
- // Check for the Blocked & Delayed Case.
+ // Check for the Disabled & Blocked & Delayed Case.
//
- GetSmmDelayedBlockedDisabledCount (&DelayedCount, &BlockedCount, NULL);
- DEBUG ((DEBUG_INFO, "SmmWaitForApArrival: Delayed AP Count = %d, Blocked AP Count = %d\n", DelayedCount, BlockedCount));
+ GetSmmDelayedBlockedDisabledCount (&DelayedCount, &BlockedCount, &DisabledCount);
+ DEBUG ((DEBUG_ERROR, "SmmWaitForApArrival: Failed to wait all APs enter SMI. Delayed AP Count = %d, Blocked AP Count = %d, Disabled AP Count = %d\n", DelayedCount, BlockedCount, DisabledCount));
}
PERF_FUNCTION_END ();
diff --git a/UefiCpuPkg/UefiCpuPkg.ci.yaml b/UefiCpuPkg/UefiCpuPkg.ci.yaml
index a6fd147..57867dd 100644
--- a/UefiCpuPkg/UefiCpuPkg.ci.yaml
+++ b/UefiCpuPkg/UefiCpuPkg.ci.yaml
@@ -30,7 +30,6 @@
],
## Both file path and directory path are accepted.
"IgnoreFiles": [
- "Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandlerLib.h"
]
},
"CompilerPlugin": {
diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc
index aac4668..e011b18 100644
--- a/UefiCpuPkg/UefiCpuPkg.dsc
+++ b/UefiCpuPkg/UefiCpuPkg.dsc
@@ -218,7 +218,6 @@
UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerLibUnitTest.inf
[Components.RISCV64]
- UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandlerLib.inf
UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.inf
UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.inf
UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf
diff --git a/UefiPayloadPkg/PchSmiDispatchSmm/PchSmiDispatchSmm.c b/UefiPayloadPkg/PchSmiDispatchSmm/PchSmiDispatchSmm.c
index 8a076e1..155ab79 100644
--- a/UefiPayloadPkg/PchSmiDispatchSmm/PchSmiDispatchSmm.c
+++ b/UefiPayloadPkg/PchSmiDispatchSmm/PchSmiDispatchSmm.c
@@ -87,6 +87,7 @@ FindContextByDispatchHandle (
**/
EFI_STATUS
+EFIAPI
SmmSwDispatcher (
IN EFI_HANDLE DispatchHandle,
IN CONST VOID *RegisterContext,