Date   

[PATCH V2 4/8] OvmfPkg/IntelTdx: Measure Td HobList and Configuration FV

Min Xu
 

RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3853

TdHobList and Configuration FV are external data provided by Host VMM.
These are not trusted in Td guest. So they should be validated , measured
and extended to Td RTMR registers. In the meantime 2 EFI_CC_EVENT_HOB are
created. These 2 GUIDed HOBs carry the hash value of TdHobList and
Configuration FV. In DXE phase EFI_CC_EVENT can be created based on these
2 GUIDed HOBs.

Cc: Ard Biesheuvel <ardb+tianocore@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Jordan Justen <jordan.l.justen@...>
Cc: Brijesh Singh <brijesh.singh@...>
Cc: Erdem Aktas <erdemaktas@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Cc: Gerd Hoffmann <kraxel@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
OvmfPkg/IntelTdx/IntelTdxX64.dsc | 3 +
OvmfPkg/Library/PeilessStartupLib/IntelTdx.c | 498 ++++++++++++++++++
.../PeilessStartupLib/PeilessStartup.c | 30 ++
.../PeilessStartupInternal.h | 57 ++
.../PeilessStartupLib/PeilessStartupLib.inf | 7 +-
5 files changed, 593 insertions(+), 2 deletions(-)
create mode 100644 OvmfPkg/Library/PeilessStartupLib/IntelTdx.c

diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdxX64.dsc
index 245155d41b30..caae49d524f9 100644
--- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc
+++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc
@@ -520,6 +520,9 @@
OvmfPkg/IntelTdx/Sec/SecMain.inf {
<LibraryClasses>
NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
+ BaseCryptLib|CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf
+ HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterTdx.inf
+ NULL|SecurityPkg/Library/HashInstanceLibSha384/HashInstanceLibSha384.inf
}

#
diff --git a/OvmfPkg/Library/PeilessStartupLib/IntelTdx.c b/OvmfPkg/Library/PeilessStartupLib/IntelTdx.c
new file mode 100644
index 000000000000..bb905cf5cd6a
--- /dev/null
+++ b/OvmfPkg/Library/PeilessStartupLib/IntelTdx.c
@@ -0,0 +1,498 @@
+/** @file
+ Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <PiPei.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+#include <IndustryStandard/UefiTcgPlatform.h>
+#include <IndustryStandard/Tpm20.h>
+#include <Library/HashLib.h>
+#include <Protocol/CcMeasurement.h>
+#include <Guid/VariableFormat.h>
+#include <Guid/SystemNvDataGuid.h>
+#include <Guid/CcEventHob.h>
+#include <Library/PrintLib.h>
+#include "PeilessStartupInternal.h"
+
+#pragma pack(1)
+
+typedef struct {
+ UINT32 count;
+ TPMI_ALG_HASH hashAlg;
+ BYTE sha384[SHA384_DIGEST_SIZE];
+} TDX_DIGEST_VALUE;
+
+#define HANDOFF_TABLE_DESC "TdxTable"
+typedef struct {
+ UINT8 TableDescriptionSize;
+ UINT8 TableDescription[sizeof (HANDOFF_TABLE_DESC)];
+ UINT64 NumberOfTables;
+ EFI_CONFIGURATION_TABLE TableEntry[1];
+} TDX_HANDOFF_TABLE_POINTERS2;
+
+#define FV_HANDOFF_TABLE_DESC "Fv(XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)"
+typedef struct {
+ UINT8 BlobDescriptionSize;
+ UINT8 BlobDescription[sizeof (FV_HANDOFF_TABLE_DESC)];
+ EFI_PHYSICAL_ADDRESS BlobBase;
+ UINT64 BlobLength;
+} FV_HANDOFF_TABLE_POINTERS2;
+
+#pragma pack()
+
+#define INVALID_PCR2MR_INDEX 0xFF
+
+/**
+ RTMR[0] => PCR[1,7]
+ RTMR[1] => PCR[2,3,4,5]
+ RTMR[2] => PCR[8~15]
+ RTMR[3] => NA
+ Note:
+ PCR[0] is mapped to MRTD and should not appear here.
+ PCR[6] is reserved for OEM. It is not used.
+**/
+UINT8
+GetMappedRtmrIndex (
+ UINT32 PCRIndex
+ )
+{
+ UINT8 RtmrIndex;
+
+ if ((PCRIndex == 6) || (PCRIndex == 0) || (PCRIndex > 15)) {
+ DEBUG ((DEBUG_ERROR, "Invalid PCRIndex(%d) map to MR Index.\n", PCRIndex));
+ ASSERT (FALSE);
+ return INVALID_PCR2MR_INDEX;
+ }
+
+ RtmrIndex = 0;
+ if ((PCRIndex == 1) || (PCRIndex == 7)) {
+ RtmrIndex = 0;
+ } else if ((PCRIndex >= 2) && (PCRIndex < 6)) {
+ RtmrIndex = 1;
+ } else if ((PCRIndex >= 8) && (PCRIndex <= 15)) {
+ RtmrIndex = 2;
+ }
+
+ return RtmrIndex;
+}
+
+/**
+ Tpm measure and log data, and extend the measurement result into a specific PCR.
+ @param[in] PcrIndex PCR Index.
+ @param[in] EventType Event type.
+ @param[in] EventLog Measurement event log.
+ @param[in] LogLen Event log length in bytes.
+ @param[in] HashData The start of the data buffer to be hashed, extended.
+ @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData
+ @retval EFI_SUCCESS Operation completed successfully.
+ @retval EFI_UNSUPPORTED TPM device not available.
+ @retval EFI_OUT_OF_RESOURCES Out of memory.
+ @retval EFI_DEVICE_ERROR The operation was unsuccessful.
+**/
+EFI_STATUS
+EFIAPI
+TdxMeasureAndLogData (
+ IN UINT32 PcrIndex,
+ IN UINT32 EventType,
+ IN VOID *EventLog,
+ IN UINT32 LogLen,
+ IN VOID *HashData,
+ IN UINT64 HashDataLen
+ )
+{
+ EFI_STATUS Status;
+ UINT32 RtmrIndex;
+ VOID *EventHobData;
+ TCG_PCR_EVENT2 *TcgPcrEvent2;
+ UINT8 *DigestBuffer;
+ TDX_DIGEST_VALUE *TdxDigest;
+ TPML_DIGEST_VALUES DigestList;
+ UINT8 *Ptr;
+
+ RtmrIndex = GetMappedRtmrIndex (PcrIndex);
+ if (RtmrIndex == INVALID_PCR2MR_INDEX) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ DEBUG ((DEBUG_INFO, "Creating TdTcg2PcrEvent PCR[%d]/RTMR[%d] EventType 0x%x\n", PcrIndex, RtmrIndex, EventType));
+
+ Status = HashAndExtend (
+ RtmrIndex,
+ (VOID *)HashData,
+ HashDataLen,
+ &DigestList
+ );
+
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_INFO, "Failed to HashAndExtend. %r\n", Status));
+ return Status;
+ }
+
+ //
+ // Use TDX_DIGEST_VALUE in the GUID HOB DataLength calculation
+ // to reserve enough buffer to hold TPML_DIGEST_VALUES compact binary
+ // which is limited to a SHA384 digest list
+ //
+ EventHobData = BuildGuidHob (
+ &gCcEventEntryHobGuid,
+ sizeof (TcgPcrEvent2->PCRIndex) + sizeof (TcgPcrEvent2->EventType) +
+ sizeof (TDX_DIGEST_VALUE) +
+ sizeof (TcgPcrEvent2->EventSize) + LogLen
+ );
+
+ if (EventHobData == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Ptr = (UINT8 *)EventHobData;
+ //
+ // Initialize PcrEvent data now
+ //
+ RtmrIndex++;
+ CopyMem (Ptr, &RtmrIndex, sizeof (UINT32));
+ Ptr += sizeof (UINT32);
+ CopyMem (Ptr, &EventType, sizeof (TCG_EVENTTYPE));
+ Ptr += sizeof (TCG_EVENTTYPE);
+
+ DigestBuffer = Ptr;
+
+ TdxDigest = (TDX_DIGEST_VALUE *)DigestBuffer;
+ TdxDigest->count = 1;
+ TdxDigest->hashAlg = TPM_ALG_SHA384;
+ CopyMem (
+ TdxDigest->sha384,
+ DigestList.digests[0].digest.sha384,
+ SHA384_DIGEST_SIZE
+ );
+
+ Ptr += sizeof (TDX_DIGEST_VALUE);
+
+ CopyMem (Ptr, &LogLen, sizeof (UINT32));
+ Ptr += sizeof (UINT32);
+ CopyMem (Ptr, EventLog, LogLen);
+ Ptr += LogLen;
+
+ Status = EFI_SUCCESS;
+ return Status;
+}
+
+/**
+ Measure the Hoblist passed from the VMM.
+
+ This function will create a unique GUID hob entry will be
+ found from the TCG driver building the event log.
+ This module will generate the measurement with the data in
+ this hob, and log the event.
+
+ @param[in] VmmHobList The Hoblist pass the firmware
+
+ @retval EFI_SUCCESS Fv image is measured successfully
+ or it has been already measured.
+ @retval Others Other errors as indicated
+**/
+EFI_STATUS
+EFIAPI
+MeasureHobList (
+ IN CONST VOID *VmmHobList
+ )
+{
+ EFI_PEI_HOB_POINTERS Hob;
+ TDX_HANDOFF_TABLE_POINTERS2 HandoffTables;
+ EFI_STATUS Status;
+
+ if (!TdIsEnabled ()) {
+ ASSERT (FALSE);
+ return EFI_UNSUPPORTED;
+ }
+
+ Hob.Raw = (UINT8 *)VmmHobList;
+
+ //
+ // Parse the HOB list until end of list.
+ //
+ while (!END_OF_HOB_LIST (Hob)) {
+ Hob.Raw = GET_NEXT_HOB (Hob);
+ }
+
+ //
+ // Init the log event for HOB measurement
+ //
+
+ HandoffTables.TableDescriptionSize = sizeof (HandoffTables.TableDescription);
+ CopyMem (HandoffTables.TableDescription, HANDOFF_TABLE_DESC, sizeof (HandoffTables.TableDescription));
+ HandoffTables.NumberOfTables = 1;
+ CopyGuid (&(HandoffTables.TableEntry[0].VendorGuid), &gUefiOvmfPkgTokenSpaceGuid);
+ HandoffTables.TableEntry[0].VendorTable = (VOID *)VmmHobList;
+
+ Status = TdxMeasureAndLogData (
+ 1, // PCRIndex
+ EV_EFI_HANDOFF_TABLES2, // EventType
+ (VOID *)&HandoffTables, // EventData
+ sizeof (HandoffTables), // EventSize
+ (UINT8 *)(UINTN)VmmHobList, // HashData
+ (UINTN)((UINT8 *)Hob.Raw - (UINT8 *)VmmHobList) // HashDataLen
+ );
+
+ if (EFI_ERROR (Status)) {
+ ASSERT (FALSE);
+ }
+
+ return Status;
+}
+
+/**
+ Check padding data all bit should be 1.
+
+ @param[in] Buffer - A pointer to buffer header
+ @param[in] BufferSize - Buffer size
+
+ @retval TRUE - The padding data is valid.
+ @retval TRUE - The padding data is invalid.
+
+**/
+BOOLEAN
+CheckPaddingData (
+ IN UINT8 *Buffer,
+ IN UINT32 BufferSize
+ )
+{
+ UINT32 index;
+
+ for (index = 0; index < BufferSize; index++) {
+ if (Buffer[index] != 0xFF) {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+/**
+ Check the integrity of CFV data.
+
+ @param[in] TdxCfvBase - A pointer to CFV header
+ @param[in] TdxCfvSize - CFV data size
+
+ @retval TRUE - The CFV data is valid.
+ @retval FALSE - The CFV data is invalid.
+
+**/
+BOOLEAN
+EFIAPI
+TdxValidateCfv (
+ IN UINT8 *TdxCfvBase,
+ IN UINT32 TdxCfvSize
+ )
+{
+ UINT16 Checksum;
+ UINTN VariableBase;
+ UINT32 VariableOffset;
+ UINT32 VariableOffsetBeforeAlign;
+ EFI_FIRMWARE_VOLUME_HEADER *CfvFvHeader;
+ VARIABLE_STORE_HEADER *CfvVariableStoreHeader;
+ AUTHENTICATED_VARIABLE_HEADER *VariableHeader;
+
+ static EFI_GUID FvHdrGUID = EFI_SYSTEM_NV_DATA_FV_GUID;
+ static EFI_GUID VarStoreHdrGUID = EFI_AUTHENTICATED_VARIABLE_GUID;
+
+ VariableOffset = 0;
+
+ if (TdxCfvBase == NULL) {
+ DEBUG ((DEBUG_ERROR, "TDX CFV: CFV pointer is NULL\n"));
+ return FALSE;
+ }
+
+ //
+ // Verify the header zerovetor, filesystemguid,
+ // revision, signature, attributes, fvlength, checksum
+ // HeaderLength cannot be an odd number
+ //
+ CfvFvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)TdxCfvBase;
+
+ if ((!IsZeroBuffer (CfvFvHeader->ZeroVector, 16)) ||
+ (!CompareGuid (&FvHdrGUID, &CfvFvHeader->FileSystemGuid)) ||
+ (CfvFvHeader->Signature != EFI_FVH_SIGNATURE) ||
+ (CfvFvHeader->Attributes != 0x4feff) ||
+ (CfvFvHeader->Revision != EFI_FVH_REVISION) ||
+ (CfvFvHeader->FvLength != TdxCfvSize)
+ )
+ {
+ DEBUG ((DEBUG_ERROR, "TDX CFV: Basic FV headers were invalid\n"));
+ return FALSE;
+ }
+
+ //
+ // Verify the header checksum
+ //
+ Checksum = CalculateSum16 ((VOID *)CfvFvHeader, CfvFvHeader->HeaderLength);
+
+ if (Checksum != 0) {
+ DEBUG ((DEBUG_ERROR, "TDX CFV: FV checksum was invalid\n"));
+ return FALSE;
+ }
+
+ //
+ // Verify the header signature, size, format, state
+ //
+ CfvVariableStoreHeader = (VARIABLE_STORE_HEADER *)(TdxCfvBase + CfvFvHeader->HeaderLength);
+ if ((!CompareGuid (&VarStoreHdrGUID, &CfvVariableStoreHeader->Signature)) ||
+ (CfvVariableStoreHeader->Format != VARIABLE_STORE_FORMATTED) ||
+ (CfvVariableStoreHeader->State != VARIABLE_STORE_HEALTHY) ||
+ (CfvVariableStoreHeader->Size > (CfvFvHeader->FvLength - CfvFvHeader->HeaderLength)) ||
+ (CfvVariableStoreHeader->Size < sizeof (VARIABLE_STORE_HEADER))
+ )
+ {
+ DEBUG ((DEBUG_ERROR, "TDX CFV: Variable Store header was invalid\n"));
+ return FALSE;
+ }
+
+ //
+ // Verify the header startId, state
+ // Verify data to the end
+ //
+ VariableBase = (UINTN)TdxCfvBase + CfvFvHeader->HeaderLength + sizeof (VARIABLE_STORE_HEADER);
+ while (VariableOffset < (CfvVariableStoreHeader->Size - sizeof (VARIABLE_STORE_HEADER))) {
+ VariableHeader = (AUTHENTICATED_VARIABLE_HEADER *)(VariableBase + VariableOffset);
+ if (VariableHeader->StartId != VARIABLE_DATA) {
+ if (!CheckPaddingData ((UINT8 *)VariableHeader, CfvVariableStoreHeader->Size - sizeof (VARIABLE_STORE_HEADER) - VariableOffset)) {
+ DEBUG ((DEBUG_ERROR, "TDX CFV: Variable header was invalid\n"));
+ return FALSE;
+ }
+
+ VariableOffset = CfvVariableStoreHeader->Size - sizeof (VARIABLE_STORE_HEADER);
+ } else {
+ if (!((VariableHeader->State == VAR_IN_DELETED_TRANSITION) ||
+ (VariableHeader->State == VAR_DELETED) ||
+ (VariableHeader->State == VAR_HEADER_VALID_ONLY) ||
+ (VariableHeader->State == VAR_ADDED)))
+ {
+ DEBUG ((DEBUG_ERROR, "TDX CFV: Variable header was invalid\n"));
+ return FALSE;
+ }
+
+ VariableOffset += sizeof (AUTHENTICATED_VARIABLE_HEADER) + VariableHeader->NameSize + VariableHeader->DataSize;
+ // Verify VariableOffset should be less than or equal CfvVariableStoreHeader->Size - sizeof(VARIABLE_STORE_HEADER)
+ if (VariableOffset > (CfvVariableStoreHeader->Size - sizeof (VARIABLE_STORE_HEADER))) {
+ DEBUG ((DEBUG_ERROR, "TDX CFV: Variable header was invalid\n"));
+ return FALSE;
+ }
+
+ VariableOffsetBeforeAlign = VariableOffset;
+ // 4 byte align
+ VariableOffset = (VariableOffset + 3) & (UINTN)(~3);
+
+ if (!CheckPaddingData ((UINT8 *)(VariableBase + VariableOffsetBeforeAlign), VariableOffset - VariableOffsetBeforeAlign)) {
+ DEBUG ((DEBUG_ERROR, "TDX CFV: Variable header was invalid\n"));
+ return FALSE;
+ }
+ }
+ }
+
+ return TRUE;
+}
+
+/**
+ Get the FvName from the FV header.
+
+ Causion: The FV is untrusted input.
+
+ @param[in] FvBase Base address of FV image.
+ @param[in] FvLength Length of FV image.
+
+ @return FvName pointer
+ @retval NULL FvName is NOT found
+**/
+VOID *
+GetFvName (
+ IN EFI_PHYSICAL_ADDRESS FvBase,
+ IN UINT64 FvLength
+ )
+{
+ EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
+ EFI_FIRMWARE_VOLUME_EXT_HEADER *FvExtHeader;
+
+ if (FvBase >= MAX_ADDRESS) {
+ return NULL;
+ }
+
+ if (FvLength >= MAX_ADDRESS - FvBase) {
+ return NULL;
+ }
+
+ if (FvLength < sizeof (EFI_FIRMWARE_VOLUME_HEADER)) {
+ return NULL;
+ }
+
+ FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FvBase;
+ if (FvHeader->ExtHeaderOffset < sizeof (EFI_FIRMWARE_VOLUME_HEADER)) {
+ return NULL;
+ }
+
+ if (FvHeader->ExtHeaderOffset + sizeof (EFI_FIRMWARE_VOLUME_EXT_HEADER) > FvLength) {
+ return NULL;
+ }
+
+ FvExtHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER *)(UINTN)(FvBase + FvHeader->ExtHeaderOffset);
+
+ return &FvExtHeader->FvName;
+}
+
+/**
+ Measure FV image.
+ Add it into the measured FV list after the FV is measured successfully.
+
+ @param[in] FvBase Base address of FV image.
+ @param[in] FvLength Length of FV image.
+ @param[in] PcrIndex Index of PCR
+
+ @retval EFI_SUCCESS Fv image is measured successfully
+ or it has been already measured.
+ @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
+ @retval EFI_DEVICE_ERROR The command was unsuccessful.
+
+**/
+EFI_STATUS
+EFIAPI
+TdxMeasureCfvImage (
+ IN EFI_PHYSICAL_ADDRESS FvBase,
+ IN UINT64 FvLength,
+ IN UINT8 PcrIndex
+ )
+{
+ EFI_STATUS Status;
+ FV_HANDOFF_TABLE_POINTERS2 FvBlob2;
+ VOID *FvName;
+
+ //
+ // Init the log event for FV measurement
+ //
+ FvBlob2.BlobDescriptionSize = sizeof (FvBlob2.BlobDescription);
+ CopyMem (FvBlob2.BlobDescription, FV_HANDOFF_TABLE_DESC, sizeof (FvBlob2.BlobDescription));
+ FvName = GetFvName (FvBase, FvLength);
+ if (FvName != NULL) {
+ AsciiSPrint ((CHAR8 *)FvBlob2.BlobDescription, sizeof (FvBlob2.BlobDescription), "Fv(%g)", FvName);
+ }
+
+ FvBlob2.BlobBase = FvBase;
+ FvBlob2.BlobLength = FvLength;
+
+ Status = TdxMeasureAndLogData (
+ 1, // PCRIndex
+ EV_EFI_PLATFORM_FIRMWARE_BLOB2, // EventType
+ (VOID *)&FvBlob2, // EventData
+ sizeof (FvBlob2), // EventSize
+ (UINT8 *)(UINTN)FvBase, // HashData
+ (UINTN)(FvLength) // HashDataLen
+ );
+
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "The FV which failed to be measured starts at: 0x%x\n", FvBase));
+ ASSERT (FALSE);
+ }
+
+ return Status;
+}
diff --git a/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c b/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c
index 126eb74048f4..aea7f98da92d 100644
--- a/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c
+++ b/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c
@@ -133,11 +133,13 @@ PeilessStartup (
UINT32 DxeCodeSize;
TD_RETURN_DATA TdReturnData;
VOID *VmmHobList;
+ UINT8 *CfvBase;

Status = EFI_SUCCESS;
BootFv = NULL;
VmmHobList = NULL;
SecCoreData = (EFI_SEC_PEI_HAND_OFF *)Context;
+ CfvBase = (UINT8 *)(UINTN)FixedPcdGet32 (PcdCfvBase);

ZeroMem (&PlatformInfoHob, sizeof (PlatformInfoHob));

@@ -167,6 +169,34 @@ PeilessStartup (

DEBUG ((DEBUG_INFO, "HobList: %p\n", GetHobList ()));

+ if (TdIsEnabled ()) {
+ //
+ // Measure HobList
+ //
+ Status = MeasureHobList (VmmHobList);
+ if (EFI_ERROR (Status)) {
+ ASSERT (FALSE);
+ CpuDeadLoop ();
+ }
+
+ //
+ // Validate Tdx CFV
+ //
+ if (!TdxValidateCfv (CfvBase, FixedPcdGet32 (PcdCfvRawDataSize))) {
+ ASSERT (FALSE);
+ CpuDeadLoop ();
+ }
+
+ //
+ // Measure Tdx CFV
+ //
+ Status = TdxMeasureCfvImage ((EFI_PHYSICAL_ADDRESS)(UINTN)CfvBase, FixedPcdGet32 (PcdCfvRawDataSize), 1);
+ if (EFI_ERROR (Status)) {
+ ASSERT (FALSE);
+ CpuDeadLoop ();
+ }
+ }
+
//
// Initialize the Platform
//
diff --git a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupInternal.h b/OvmfPkg/Library/PeilessStartupLib/PeilessStartupInternal.h
index 23e9e0be53f1..2a100270ff20 100644
--- a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupInternal.h
+++ b/OvmfPkg/Library/PeilessStartupLib/PeilessStartupInternal.h
@@ -52,4 +52,61 @@ EFIAPI
ConstructSecHobList (
);

+/**
+ Measure the Hoblist passed from the VMM.
+
+ This function will create a unique GUID hob entry will be
+ found from the TCG driver building the event log.
+ This module will generate the measurement with the data in
+ this hob, and log the event.
+
+ @param[in] VmmHobList The Hoblist pass the firmware
+
+ @retval EFI_SUCCESS Fv image is measured successfully
+ or it has been already measured.
+ @retval Others Other errors as indicated
+**/
+EFI_STATUS
+EFIAPI
+MeasureHobList (
+ IN CONST VOID *VmmHobList
+ );
+
+/**
+ Check the integrity of CFV data.
+
+ @param[in] TdxCfvBase - A pointer to CFV header
+ @param[in] TdxCfvSize - CFV data size
+
+ @retval TRUE - The CFV data is valid.
+ @retval FALSE - The CFV data is invalid.
+
+**/
+BOOLEAN
+EFIAPI
+TdxValidateCfv (
+ IN UINT8 *TdxCfvBase,
+ IN UINT32 TdxCfvSize
+ );
+
+/**
+ Measure FV image.
+ Add it into the measured FV list after the FV is measured successfully.
+
+ @param[in] FvBase Base address of FV image.
+ @param[in] FvLength Length of FV image.
+ @param[in] PcrIndex Index of PCR
+
+ @retval EFI_SUCCESS Fv image is measured successfully
+ or it has been already measured.
+ @retval Others Other errors as indicated
+**/
+EFI_STATUS
+EFIAPI
+TdxMeasureCfvImage (
+ IN EFI_PHYSICAL_ADDRESS FvBase,
+ IN UINT64 FvLength,
+ IN UINT8 PcrIndex
+ );
+
#endif
diff --git a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf b/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf
index 8791984586a4..178b4c35d472 100644
--- a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf
+++ b/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf
@@ -29,8 +29,7 @@
PeilessStartup.c
Hob.c
DxeLoad.c
-
-[Sources.X64]
+ IntelTdx.c
X64/VirtualMemory.c

[Packages]
@@ -39,6 +38,8 @@
UefiCpuPkg/UefiCpuPkg.dec
OvmfPkg/OvmfPkg.dec
EmbeddedPkg/EmbeddedPkg.dec
+ CryptoPkg/CryptoPkg.dec
+ SecurityPkg/SecurityPkg.dec

[LibraryClasses]
BaseLib
@@ -56,6 +57,7 @@
PrePiLib
QemuFwCfgLib
PlatformInitLib
+ HashLib

[Guids]
gEfiHobMemoryAllocModuleGuid
@@ -63,6 +65,7 @@
gUefiOvmfPkgPlatformInfoGuid
gEfiMemoryTypeInformationGuid
gPcdDataBaseHobGuid
+ gCcEventEntryHobGuid

[Pcd]
gUefiOvmfPkgTokenSpaceGuid.PcdCfvBase
--
2.29.2.windows.2


[PATCH V2 5/8] OvmfPkg: Add PCDs for LAML/LASA field in CC EVENTLOG ACPI table

Min Xu
 

RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3853

Add PCDs to records LAML/LASA field in CC EVENTLOG ACPI table.

Cc: Brijesh Singh <brijesh.singh@...>
Cc: Erdem Aktas <erdemaktas@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Cc: Ken Lu <ken.lu@...>
Cc: Sami Mujawar <sami.mujawar@...>
Cc: Gerd Hoffmann <kraxel@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
OvmfPkg/OvmfPkg.dec | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index b9ca44120289..f471f3bbeec2 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -436,6 +436,12 @@
# 2 - set by GOP Driver.
gUefiOvmfPkgTokenSpaceGuid.PcdVideoResolutionSource|0|UINT8|0x64

+ ## This PCD records LAML field in CC EVENTLOG ACPI table.
+ gUefiOvmfPkgTokenSpaceGuid.PcdCcEventlogAcpiTableLaml|0|UINT32|0x66
+
+ ## This PCD records LASA field in CC EVENTLOG ACPI table.
+ gUefiOvmfPkgTokenSpaceGuid.PcdCcEventlogAcpiTableLasa|0|UINT64|0x67
+
[PcdsFeatureFlag]
gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderPciTranslation|TRUE|BOOLEAN|0x1c
gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderMmioTranslation|FALSE|BOOLEAN|0x1d
--
2.29.2.windows.2


[PATCH V2 2/8] CryptoPkg: Add SecCryptLib

Min Xu
 

RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3853

This is the Cryptographic library instance for SEC. The motivation of
this library is to support SHA384 in SEC phase for Td guest. So only
Hash/CryptSha512.c is included which supports SHA384 and SHA512.

Cc: Jiewen Yao <jiewen.yao@...>
Cc: Jian J Wang <jian.j.wang@...>
Cc: Xiaoyu Lu <xiaoyu1.lu@...>
Cc: Guomin Jiang <guomin.jiang@...>
Cc: Gerd Hoffmann <kraxel@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
CryptoPkg/CryptoPkg.dsc | 4 ++
.../Library/BaseCryptLib/SecCryptLib.inf | 67 +++++++++++++++++++
2 files changed, 71 insertions(+)
create mode 100644 CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf

diff --git a/CryptoPkg/CryptoPkg.dsc b/CryptoPkg/CryptoPkg.dsc
index 0aa72ed87846..b814e9616454 100644
--- a/CryptoPkg/CryptoPkg.dsc
+++ b/CryptoPkg/CryptoPkg.dsc
@@ -109,6 +109,9 @@
[LibraryClasses.ARM]
ArmSoftFloatLib|ArmPkg/Library/ArmSoftFloatLib/ArmSoftFloatLib.inf

+[LibraryClasses.common.SEC]
+ BaseCryptLib|CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf
+
[LibraryClasses.common.PEIM]
PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf
ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf
@@ -236,6 +239,7 @@
!if $(CRYPTO_SERVICES) == PACKAGE
[Components]
CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
+ CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf
CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf
diff --git a/CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf b/CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf
new file mode 100644
index 000000000000..6ef2f67e35dd
--- /dev/null
+++ b/CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf
@@ -0,0 +1,67 @@
+## @file
+# Cryptographic Library Instance for SEC.
+#
+# Caution: This module requires additional review when modified.
+# This library will have external input - signature.
+# This external input must be validated carefully to avoid security issues such as
+# buffer overflow or integer overflow.
+#
+# Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = SecCryptLib
+ FILE_GUID = 3689D343-0D32-4284-8053-BF10537990E8
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = BaseCryptLib|SEC
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ InternalCryptLib.h
+ Hash/CryptSha512.c
+
+ SysCall/CrtWrapper.c
+ SysCall/ConstantTimeClock.c
+ SysCall/BaseMemAllocation.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ CryptoPkg/CryptoPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ BaseMemoryLib
+ MemoryAllocationLib
+ DebugLib
+ OpensslLib
+ IntrinsicLib
+
+#
+# Remove these [BuildOptions] after this library is cleaned up
+#
+[BuildOptions]
+ #
+ # suppress the following warnings so we do not break the build with warnings-as-errors:
+ # C4090: 'function' : different 'const' qualifiers
+ # C4718: 'function call' : recursive call has no side effects, deleting
+ #
+ MSFT:*_*_*_CC_FLAGS = /wd4090 /wd4718
+
+ # -JCryptoPkg/Include : To disable the use of the system includes provided by RVCT
+ # --diag_remark=1 : Reduce severity of "#1-D: last line of file ends without a newline"
+ RVCT:*_*_ARM_CC_FLAGS = -JCryptoPkg/Include --diag_remark=1
+
+ GCC:*_CLANG35_*_CC_FLAGS = -std=c99
+ GCC:*_CLANG38_*_CC_FLAGS = -std=c99
+ GCC:*_CLANGPDB_*_CC_FLAGS = -std=c99 -Wno-error=incompatible-pointer-types
+
+ XCODE:*_*_*_CC_FLAGS = -std=c99
--
2.29.2.windows.2


[PATCH V2 3/8] SecurityPkg: Add definition of EFI_CC_EVENT_HOB_GUID

Min Xu
 

RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3853

EFI_CC_EVENT_HOB_GUID is the global ID of a GUIDed HOB used to pass
TDX_DIGEST_VALUE from SEC to a DXE Driver ( This DXE driver will
be introduced in the following commit in this patch-sets ). In that
DXE driver this GUIDed HOB will be parsed and the TDX_DIGEST_VALUE
then will be extracted. After that a EFI_CC_EVENT will be created
based on it.

Cc: Gerd Hoffmann <kraxel@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Sami Mujawar <sami.mujawar@...>
Cc: Jian J Wang <jian.j.wang@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
SecurityPkg/Include/Guid/CcEventHob.h | 22 ++++++++++++++++++++++
SecurityPkg/SecurityPkg.dec | 4 ++++
2 files changed, 26 insertions(+)
create mode 100644 SecurityPkg/Include/Guid/CcEventHob.h

diff --git a/SecurityPkg/Include/Guid/CcEventHob.h b/SecurityPkg/Include/Guid/CcEventHob.h
new file mode 100644
index 000000000000..072999ce92de
--- /dev/null
+++ b/SecurityPkg/Include/Guid/CcEventHob.h
@@ -0,0 +1,22 @@
+/** @file
+ Defines the HOB GUID used to pass a CC_EVENT from SEC to
+ a CC DXE Driver. A GUIDed HOB is generated for each measurement
+ made in the SEC Phase.
+
+Copyright (c) 2021 - 2022, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef CC_EVENT_HOB_H_
+#define CC_EVENT_HOB_H_
+
+//
+// The Global ID of a GUIDed HOB used to pass a CC_EVENT from SEC to a CC DXE Driver.
+//
+#define EFI_CC_EVENT_HOB_GUID \
+ { 0x20f8fd36, 0x6d00, 0x40fb, { 0xb7, 0x04, 0xd1, 0x2c, 0x15, 0x3c, 0x62, 0xeb } }
+
+extern EFI_GUID gCcEventEntryHobGuid;
+
+#endif
diff --git a/SecurityPkg/SecurityPkg.dec b/SecurityPkg/SecurityPkg.dec
index 9f7a032d60d5..0ee75efc1a97 100644
--- a/SecurityPkg/SecurityPkg.dec
+++ b/SecurityPkg/SecurityPkg.dec
@@ -136,6 +136,10 @@
## Include/Guid/TcgEventHob.h
gTcgEvent2EntryHobGuid = { 0xd26c221e, 0x2430, 0x4c8a, { 0x91, 0x70, 0x3f, 0xcb, 0x45, 0x0, 0x41, 0x3f }}

+ ## Hob GUID used to pass a CC_EVENT from SEC to a CC DXE Driver.
+ ## Include/Guid/CcEventHob.h
+ gCcEventEntryHobGuid = { 0x20f8fd36, 0x6d00, 0x40fb, { 0xb7, 0x04, 0xd1, 0x2c, 0x15, 0x3c, 0x62, 0xeb }}
+
## HOB GUID used to record TPM device error.
# Include/Guid/TcgEventHob.h
gTpmErrorHobGuid = { 0xef598499, 0xb25e, 0x473a, { 0xbf, 0xaf, 0xe7, 0xe5, 0x7d, 0xce, 0x82, 0xc4 }}
--
2.29.2.windows.2


[PATCH V2 1/8] Security: Add HashLibBaseCryptoRouterTdx

Min Xu
 

RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3853

This library provides hash service by registered hash handler in Td
guest. It redirects hash request to each individual hash handler
(currently only SHA384 is supported). After that the hash value is
extended to Td RTMR registers which is similar to TPM PCRs.

Cc: Jiewen Yao <jiewen.yao@...>
Cc: Jian J Wang <jian.j.wang@...>
Cc: Gerd Hoffmann <kraxel@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
.../HashLibBaseCryptoRouterTdx.c | 214 ++++++++++++++++++
.../HashLibBaseCryptoRouterTdx.inf | 41 ++++
SecurityPkg/SecurityPkg.dsc | 10 +
3 files changed, 265 insertions(+)
create mode 100644 SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterTdx.c
create mode 100644 SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterTdx.inf

diff --git a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterTdx.c b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterTdx.c
new file mode 100644
index 000000000000..77e2a14c19be
--- /dev/null
+++ b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterTdx.c
@@ -0,0 +1,214 @@
+/** @file
+ This library is BaseCrypto router for Tdx.
+
+Copyright (c) 2021 - 2022, Intel Corporation. All rights reserved. <BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiPei.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/PcdLib.h>
+#include <Library/HashLib.h>
+#include <Library/TdxLib.h>
+#include <Protocol/CcMeasurement.h>
+#include "HashLibBaseCryptoRouterCommon.h"
+
+//
+// Currently TDX supports SHA384.
+//
+#define TDX_HASH_COUNT 1
+HASH_INTERFACE mHashInterface[TDX_HASH_COUNT] = {
+ {
+ { 0 }, NULL, NULL, NULL
+ }
+};
+
+UINTN mHashInterfaceCount = 0;
+HASH_HANDLE mHashCtx[TDX_HASH_COUNT] = { 0 };
+
+/**
+ Start hash sequence.
+
+ @param HashHandle Hash handle.
+
+ @retval EFI_SUCCESS Hash sequence start and HandleHandle returned.
+ @retval EFI_OUT_OF_RESOURCES No enough resource to start hash.
+**/
+EFI_STATUS
+EFIAPI
+HashStart (
+ OUT HASH_HANDLE *HashHandle
+ )
+{
+ HASH_HANDLE *HashCtx;
+
+ if (mHashInterfaceCount == 0) {
+ ASSERT (FALSE);
+ return EFI_UNSUPPORTED;
+ }
+
+ HashCtx = mHashCtx;
+ mHashInterface[0].HashInit (&HashCtx[0]);
+
+ *HashHandle = (HASH_HANDLE)HashCtx;
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Update hash sequence data.
+
+ @param HashHandle Hash handle.
+ @param DataToHash Data to be hashed.
+ @param DataToHashLen Data size.
+
+ @retval EFI_SUCCESS Hash sequence updated.
+**/
+EFI_STATUS
+EFIAPI
+HashUpdate (
+ IN HASH_HANDLE HashHandle,
+ IN VOID *DataToHash,
+ IN UINTN DataToHashLen
+ )
+{
+ HASH_HANDLE *HashCtx;
+
+ if (mHashInterfaceCount == 0) {
+ ASSERT (FALSE);
+ return EFI_UNSUPPORTED;
+ }
+
+ HashCtx = (HASH_HANDLE *)HashHandle;
+ mHashInterface[0].HashUpdate (HashCtx[0], DataToHash, DataToHashLen);
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Hash sequence complete and extend to PCR.
+
+ @param HashHandle Hash handle.
+ @param PcrIndex PCR to be extended.
+ @param DataToHash Data to be hashed.
+ @param DataToHashLen Data size.
+ @param DigestList Digest list.
+
+ @retval EFI_SUCCESS Hash sequence complete and DigestList is returned.
+**/
+EFI_STATUS
+EFIAPI
+HashCompleteAndExtend (
+ IN HASH_HANDLE HashHandle,
+ IN TPMI_DH_PCR PcrIndex,
+ IN VOID *DataToHash,
+ IN UINTN DataToHashLen,
+ OUT TPML_DIGEST_VALUES *DigestList
+ )
+{
+ TPML_DIGEST_VALUES Digest;
+ HASH_HANDLE *HashCtx;
+ EFI_STATUS Status;
+
+ if (mHashInterfaceCount == 0) {
+ ASSERT (FALSE);
+ return EFI_UNSUPPORTED;
+ }
+
+ HashCtx = (HASH_HANDLE *)HashHandle;
+ ZeroMem (DigestList, sizeof (*DigestList));
+
+ mHashInterface[0].HashUpdate (HashCtx[0], DataToHash, DataToHashLen);
+ mHashInterface[0].HashFinal (HashCtx[0], &Digest);
+ Tpm2SetHashToDigestList (DigestList, &Digest);
+
+ ASSERT (DigestList->count == 1 && DigestList->digests[0].hashAlg == TPM_ALG_SHA384);
+
+ Status = TdExtendRtmr (
+ (UINT32 *)DigestList->digests[0].digest.sha384,
+ SHA384_DIGEST_SIZE,
+ (UINT8)PcrIndex
+ );
+
+ ASSERT (!EFI_ERROR (Status));
+ return Status;
+}
+
+/**
+ Hash data and extend to RTMR.
+
+ @param PcrIndex PCR to be extended.
+ @param DataToHash Data to be hashed.
+ @param DataToHashLen Data size.
+ @param DigestList Digest list.
+
+ @retval EFI_SUCCESS Hash data and DigestList is returned.
+**/
+EFI_STATUS
+EFIAPI
+HashAndExtend (
+ IN TPMI_DH_PCR PcrIndex,
+ IN VOID *DataToHash,
+ IN UINTN DataToHashLen,
+ OUT TPML_DIGEST_VALUES *DigestList
+ )
+{
+ HASH_HANDLE HashHandle;
+ EFI_STATUS Status;
+
+ if (mHashInterfaceCount == 0) {
+ ASSERT (FALSE);
+ return EFI_UNSUPPORTED;
+ }
+
+ ASSERT (TdIsEnabled ());
+
+ HashStart (&HashHandle);
+ HashUpdate (HashHandle, DataToHash, DataToHashLen);
+ Status = HashCompleteAndExtend (HashHandle, PcrIndex, NULL, 0, DigestList);
+
+ return Status;
+}
+
+/**
+ This service register Hash.
+
+ @param HashInterface Hash interface
+
+ @retval EFI_SUCCESS This hash interface is registered successfully.
+ @retval EFI_UNSUPPORTED System does not support register this interface.
+ @retval EFI_ALREADY_STARTED System already register this interface.
+**/
+EFI_STATUS
+EFIAPI
+RegisterHashInterfaceLib (
+ IN HASH_INTERFACE *HashInterface
+ )
+{
+ UINT32 HashMask;
+
+ ASSERT (TdIsEnabled ());
+
+ //
+ // Check allow
+ //
+ HashMask = Tpm2GetHashMaskFromAlgo (&HashInterface->HashGuid);
+ ASSERT (HashMask == HASH_ALG_SHA384);
+
+ if (HashMask != HASH_ALG_SHA384) {
+ return EFI_UNSUPPORTED;
+ }
+
+ if (mHashInterfaceCount >= ARRAY_SIZE (mHashInterface)) {
+ ASSERT (FALSE);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ CopyMem (&mHashInterface[mHashInterfaceCount], HashInterface, sizeof (*HashInterface));
+ mHashInterfaceCount++;
+
+ return EFI_SUCCESS;
+}
diff --git a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterTdx.inf b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterTdx.inf
new file mode 100644
index 000000000000..f6b1353d0041
--- /dev/null
+++ b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterTdx.inf
@@ -0,0 +1,41 @@
+## @file
+# Provides hash service by registered hash handler in Tdx.
+#
+# This library is BaseCrypto router. It will redirect hash request to each individual
+# hash handler registered. Currently only SHA384 is supported in this router.
+#
+# Copyright (c) 2020 - 2021, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = HashLibBaseCryptoRouterTdx
+ MODULE_UNI_FILE = HashLibBaseCryptoRouter.uni
+ FILE_GUID = 77F6EA3E-1ABA-4467-A447-926E8CEB2D13
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = HashLib|SEC DXE_DRIVER
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = X64
+#
+
+[Sources]
+ HashLibBaseCryptoRouterCommon.h
+ HashLibBaseCryptoRouterCommon.c
+ HashLibBaseCryptoRouterTdx.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ SecurityPkg/SecurityPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ BaseMemoryLib
+ DebugLib
+ PcdLib
+ TdxLib
diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc
index 73a93c2285b1..b23701ad124e 100644
--- a/SecurityPkg/SecurityPkg.dsc
+++ b/SecurityPkg/SecurityPkg.dsc
@@ -72,6 +72,7 @@
MmUnblockMemoryLib|MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf
SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.inf
SecureBootVariableProvisionLib|SecurityPkg/Library/SecureBootVariableProvisionLib/SecureBootVariableProvisionLib.inf
+ TdxLib|MdePkg/Library/TdxLib/TdxLib.inf

[LibraryClasses.ARM, LibraryClasses.AARCH64]
#
@@ -92,6 +93,12 @@
[LibraryClasses.RISCV64]
RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf

+[LibraryClasses.X64.SEC]
+ HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterTdx.inf
+
+[LibraryClasses.X64.DXE_DRIVER]
+ HashLib|SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterTdx.inf
+
[LibraryClasses.common.PEIM]
PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf
PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf
@@ -283,6 +290,9 @@
#
SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf

+[Components.X64]
+ SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterTdx.inf
+
[Components.IA32, Components.X64]
SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf

--
2.29.2.windows.2


[PATCH V2 0/8] Enable RTMR based measurement and measure boot for Td guest

Min Xu
 

RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3853

Intel's Trust Domain Extensions (Intel TDX) refers to an Intel technology
that extends Virtual Machines Extensions (VMX) and Multi-Key Total Memory
Encryption (MKTME) with a new kind of virutal machines guest called a
Trust Domain (TD). A TD is desinged to run in a CPU mode that protects the
confidentiality of TD memory contents and the TD's CPU state from other
software, including the hosting Virtual-Machine Monitor (VMM), unless
explicitly shared by the TD itself.

There are 2 configurations for TDVF to upstream. See below link for
the definitions of the 2 configurations.
https://edk2.groups.io/g/devel/message/76367

This patch-set is to enable below features of Config-B in OvmfPkg.
- Enable RTMR based measurement and measured boot
- Install CC_MEASUREMENT_PROTOCOL instance in Td guest

The measurement for the other components, such as kernel image, initrd,
will be in the following patch-sets.

Patch 1:
HashLibBaseCryptoRouterTdx provides SHA384 service and extend to
RTMR registers.

Patch 2:
SecCryptLib is the cryptographic library instance for SEC.

Patch 3 - 7:
These 5 patches are related to RTMR based measurement and
CC Eventlog ACPI table.

Patch 8:
Update IntelTdxX64.dsc/IntelTdxX64.fdf to support RTMR based
measurement and measured boot.

Code at: https://github.com/mxu9/edk2/tree/tdvf_wave4.v2

v2 changes:
- Move the definition of EFI_CC_EVENT_HOB_GUID from MdePkg to
SecurityPkg.
- Update the definition of EFI_CC_EVENTLOG_ACPI_TABLE based
on below discussion:
https://edk2.groups.io/g/devel/message/87396
https://edk2.groups.io/g/devel/message/87402
- Update the code base to 94f905b3bf.

Cc: Jiewen Yao <jiewen.yao@...>
Cc: Jian J Wang <jian.j.wang@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: Xiaoyu Lu <xiaoyu1.lu@...>
Cc: Guomin Jiang <guomin.jiang@...>
Cc: Michael D Kinney <michael.d.kinney@...>
Cc: Liming Gao <gaoliming@...>
Cc: Zhiguang Liu <zhiguang.liu@...>
Cc: Sami Mujawar <sami.mujawar@...>
Cc: Ken Lu <ken.lu@...>
Cc: Ard Biesheuvel <ardb+tianocore@...>
Cc: Jordan Justen <jordan.l.justen@...>
Cc: Brijesh Singh <brijesh.singh@...>
Cc: Erdem Aktas <erdemaktas@...>
Cc: James Bottomley <jejb@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Signed-off-by: Min Xu <min.m.xu@...>

Min Xu (8):
Security: Add HashLibBaseCryptoRouterTdx
CryptoPkg: Add SecCryptLib
SecurityPkg: Add definition of EFI_CC_EVENT_HOB_GUID
OvmfPkg/IntelTdx: Measure Td HobList and Configuration FV
OvmfPkg: Add PCDs for LAML/LASA field in CC EVENTLOG ACPI table
MdePkg: Define CC Measure EventLog ACPI Table
OvmfPkg/IntelTdx: Add TdTcg2Dxe
OvmfPkg/IntelTdx: Enable RTMR based measurement and measure boot

CryptoPkg/CryptoPkg.dsc | 4 +
.../Library/BaseCryptLib/SecCryptLib.inf | 67 +
MdePkg/Include/Protocol/CcMeasurement.h | 21 +
OvmfPkg/IntelTdx/IntelTdxX64.dsc | 15 +-
OvmfPkg/IntelTdx/IntelTdxX64.fdf | 5 +
.../IntelTdx/TdTcg2Dxe/MeasureBootPeCoff.c | 407 +++
OvmfPkg/IntelTdx/TdTcg2Dxe/TdTcg2Dxe.c | 2489 +++++++++++++++++
OvmfPkg/IntelTdx/TdTcg2Dxe/TdTcg2Dxe.inf | 101 +
OvmfPkg/Library/PeilessStartupLib/IntelTdx.c | 498 ++++
.../PeilessStartupLib/PeilessStartup.c | 30 +
.../PeilessStartupInternal.h | 57 +
.../PeilessStartupLib/PeilessStartupLib.inf | 7 +-
OvmfPkg/OvmfPkg.dec | 6 +
SecurityPkg/Include/Guid/CcEventHob.h | 22 +
.../HashLibBaseCryptoRouterTdx.c | 214 ++
.../HashLibBaseCryptoRouterTdx.inf | 41 +
SecurityPkg/SecurityPkg.dec | 4 +
SecurityPkg/SecurityPkg.dsc | 10 +
18 files changed, 3995 insertions(+), 3 deletions(-)
create mode 100644 CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf
create mode 100644 OvmfPkg/IntelTdx/TdTcg2Dxe/MeasureBootPeCoff.c
create mode 100644 OvmfPkg/IntelTdx/TdTcg2Dxe/TdTcg2Dxe.c
create mode 100644 OvmfPkg/IntelTdx/TdTcg2Dxe/TdTcg2Dxe.inf
create mode 100644 OvmfPkg/Library/PeilessStartupLib/IntelTdx.c
create mode 100644 SecurityPkg/Include/Guid/CcEventHob.h
create mode 100644 SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterTdx.c
create mode 100644 SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterTdx.inf

--
2.29.2.windows.2


回复: [edk2-devel] [PATCH 1/1] UEFI-SCT: SctPkg: Updated the check for monotonic count after restart

Gao Jie
 

Hi Eday,

The patch looks good to me.

Reviewed-by: Barton Gao <gaojie@...>

Thanks
Barton

-----邮件原件-----
发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 G Edhaya Chandran
发送时间: 2022年3月3日 16:59
收件人: devel@edk2.groups.io
主题: [edk2-devel] [PATCH 1/1] UEFI-SCT: SctPkg: Updated the check for monotonic count after restart

Updated the check for montonic count in the case of after restart

From the UEFI Spec:
"The platform’s monotonic counter is comprised of two parts: the high 32 bits and the low 32 bits.
The low 32-bit value is volatile and is reset to zero on every system reset.
It is increased by 1 on every call to GetNextMonotonicCount().
The high 32-bit value is nonvolatile and is increased by one on
whenever the system resets or the low 32-bit counter overflows."

It was found in one case where the higher 32-bit increased by 2
presumably due to the overflow of lower 32-bit counter.
Update the logic to handle this case and to print a warning.

Please find more details in the ticket: https://bugzilla.tianocore.org/show_bug.cgi?id=2774

Cc: Barton Gao <gaojie@...>
Cc: Carolyn Gjertsen <Carolyn.Gjertsen@...>
Cc: Heinrich Schuchardt <heinrich.schuchardt@...>
Cc: Samer El-Haj-Mahmoud <samer.el-haj-mahmoud@...>

Signed-off-by: G Edhaya Chandran<edhaya.chandran@...>
---
.../MiscBootServicesBBTestFunction.c | 20 +++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/BootServices/MiscBootServices/BlackBoxTest/MiscBootServicesBBTestFunction.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/BootServices/MiscBootServices/BlackBoxTest/MiscBootServicesBBTestFunction.c
index 5d631c16d58b..12703d46f98c 100644
--- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/BootServices/MiscBootServices/BlackBoxTest/MiscBootServicesBBTestFunction.c
+++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/BootServices/MiscBootServices/BlackBoxTest/MiscBootServicesBBTestFunction.c
@@ -1707,12 +1707,20 @@ GetNextMonotonicCountStep2:
TplArray[Index]
);

- if (SctRShiftU64 (Count2, 32) == SctRShiftU64 (Count, 32) + 1) {
- AssertionType = EFI_TEST_ASSERTION_PASSED;
- } else {
- AssertionType = EFI_TEST_ASSERTION_FAILED;
- }
- StandardLib->RecordAssertion (
+ //The new count of upper 32 bits must be atleast 1 more than the old count.
+ //Pass case: new count is equal to old count + 1
+ if (SctRShiftU64 (Count2, 32) <= SctRShiftU64 (Count, 32)) {
+ AssertionType = EFI_TEST_ASSERTION_FAILED;
+ } else {
+ //If new count is more that old count + 1, then print warning.
+ if (SctRShiftU64 (Count2, 32) > SctRShiftU64 (Count, 32) + 1) {
+ AssertionType = EFI_TEST_ASSERTION_WARNING;
+ } else {
+ //new count == old count + 1
+ AssertionType = EFI_TEST_ASSERTION_PASSED;
+ }
+ }
+ StandardLib->RecordAssertion (
StandardLib,
AssertionType,
Index==0? \
--
2.17.1


Re: [staging/LoongArch RESEND PATCH v1 14/33] BaseTools: BaseTools changes for LoongArch platform.

Abner Chang
 

Acked-by: Abner Chang <abner.chang@...>

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Chao Li
Sent: Wednesday, February 9, 2022 2:55 PM
To: devel@edk2.groups.io
Cc: Bob Feng <bob.c.feng@...>; Liming Gao
<gaoliming@...>; Yuwei Chen <yuwei.chen@...>; Baoqi
Zhang <zhangbaoqi@...>
Subject: [edk2-devel] [staging/LoongArch RESEND PATCH v1 14/33]
BaseTools: BaseTools changes for LoongArch platform.

BaseTools define template files changes for building EDK2 LoongArch
platform.

Cc: Bob Feng <bob.c.feng@...>
Cc: Liming Gao <gaoliming@...>
Cc: Yuwei Chen <yuwei.chen@...>

Signed-off-by: Chao Li <lichao@...>
Co-authored-by: Baoqi Zhang <zhangbaoqi@...>
---
BaseTools/Conf/tools_def.template | 43
++++++++++++++++++++++++++++++-
1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/BaseTools/Conf/tools_def.template
b/BaseTools/Conf/tools_def.template
index 85b8afbb2d..67b6c69dcf 100755
--- a/BaseTools/Conf/tools_def.template
+++ b/BaseTools/Conf/tools_def.template
@@ -4,6 +4,7 @@
# Portions copyright (c) 2011 - 2019, ARM Ltd. All rights reserved.<BR>
# Copyright (c) 2015, Hewlett-Packard Development Company, L.P.<BR>
# (C) Copyright 2020, Hewlett Packard Enterprise Development LP<BR>
+# Copyright (c) 2022, Loongson Technology Corporation Limited. All rights
reserved.<BR>
# Copyright (c) Microsoft Corporation
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -267,7 +268,7 @@ DEFINE DTC_BIN = ENV(DTC_PREFIX)dtc
# Intel(r) ACPI Compiler from
# https://acpica.org/downloads
# GCC5 -Linux,Windows- Requires:
-# GCC 5 with LTO support, targeting x86_64-linux-gnu,
aarch64-linux-gnu, arm-linux-gnueabi or riscv64-linux-gnu
+# GCC 5 with LTO support, targeting x86_64-linux-gnu,
aarch64-linux-gnu, arm-linux-gnueabi, riscv64-linux-gnu ro loongarch64-linux-
gnu
# Optional:
# Required to build platforms or ACPI tables:
# Intel(r) ACPI Compiler from
@@ -1871,6 +1872,7 @@ DEFINE GCC_ALL_CC_FLAGS = -g -Os -fshort-
wchar -fno-builtin -fno-stri
DEFINE GCC_IA32_CC_FLAGS = DEF(GCC_ALL_CC_FLAGS) -m32 -
malign-double -freorder-blocks -freorder-blocks-and-partition -O2 -mno-
stack-arg-probe
DEFINE GCC_X64_CC_FLAGS = DEF(GCC_ALL_CC_FLAGS) -mno-red-
zone -Wno-address -mno-stack-arg-probe
DEFINE GCC_ARM_CC_FLAGS = DEF(GCC_ALL_CC_FLAGS) -mlittle-
endian -mabi=aapcs -fno-short-enums -funsigned-char -ffunction-sections -
fdata-sections -fomit-frame-pointer -Wno-address -mthumb -mfloat-
abi=soft -fno-pic -fno-pie
+DEFINE GCC_LOONGARCH64_CC_FLAGS = DEF(GCC_ALL_CC_FLAGS) -
march=loongarch64 -mabi=lp64d -Wa,-mla-global-with-abs -fno-plt -Wno-
address -fno-short-enums -fsigned-char -ffunction-sections -fdata-sections
DEFINE GCC_ARM_CC_XIPFLAGS = -mno-unaligned-access
DEFINE GCC_AARCH64_CC_FLAGS = DEF(GCC_ALL_CC_FLAGS) -mlittle-
endian -fno-short-enums -fverbose-asm -funsigned-char -ffunction-sections
-fdata-sections -Wno-address -fno-asynchronous-unwind-tables -fno-
unwind-tables -fno-pic -fno-pie -ffixed-x18
DEFINE GCC_AARCH64_CC_XIPFLAGS = -mstrict-align -mgeneral-regs-only
@@ -1878,12 +1880,15 @@ DEFINE GCC_DLINK_FLAGS_COMMON = -
nostdlib --pie
DEFINE GCC_DLINK2_FLAGS_COMMON = -Wl,--
script=$(EDK_TOOLS_PATH)/Scripts/GccBase.lds
DEFINE GCC_IA32_X64_DLINK_COMMON =
DEF(GCC_DLINK_FLAGS_COMMON) --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
+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) --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
@@ -1897,6 +1902,7 @@ DEFINE GCC_X64_RC_FLAGS = -I binary -O
elf64-x86-64 -B i386
DEFINE GCC_ARM_RC_FLAGS = -I binary -O elf32-littlearm -B arm --
rename-section .data=.hii
DEFINE GCC_AARCH64_RC_FLAGS = -I binary -O elf64-littleaarch64 -B
aarch64 --rename-section .data=.hii
DEFINE GCC_RISCV64_RC_FLAGS = -I binary -O elf64-littleriscv -B riscv -
-rename-section .data=.hii
+DEFINE GCC_LOONGARCH64_RC_FLAGS = -I binary -O elf64-loongarch -B
loongarch64 --alt-elf-eflags=0x3 --rename-section .data=.hii

# GCC Build Flag for included header file list generation
DEFINE GCC_DEPS_FLAGS = -MMD -MF $@.deps
@@ -1986,6 +1992,12 @@ DEFINE GCC5_RISCV64_CC_FLAGS =
DEF(GCC5_RISCV_ALL_CC_FLAGS) DEF(GC
DEFINE GCC5_RISCV64_DLINK_FLAGS =
DEF(GCC5_RISCV_ALL_DLINK_FLAGS) -Wl,-melf64lriscv,--oformat=elf64-
littleriscv,--no-relax
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) -mno-memcpy -Werror -Wno-maybe-
uninitialized -Wno-stringop-overflow -Wno-pointer-to-int-cast
+DEFINE GCC5_LOONGARCH64_DLINK_FLAGS =
DEF(GCC_LOONGARCH64_DLINK_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)
+DEFINE GCC5_LOONGARCH64_ASM_FLAGS = -x assembler-with-cpp -
mabi=lp64d -march=loongarch64 -Wa,-mla-global-with-abs -fno-builtin -c -
Wall
+DEFINE GCC5_LOONGARCH64_PP_FLAGS = -mabi=lp64d -
march=loongarch64 DEF(GCC_PP_FLAGS)
DEFINE GCC_PP_FLAGS = -E -x assembler-with-cpp -include
AutoGen.h DEF(GCC5_RISCV_OPENSBI_TYPES)


##########################################################
##########################
@@ -2464,6 +2476,35 @@ RELEASE_GCC5_AARCH64_DLINK_XIPFLAGS = -z
common-page-size=0x20
*_GCC5_RISCV64_OBJCOPY_FLAGS =
*_GCC5_RISCV64_DTCPP_FLAGS = DEF(GCC_DTCPP_FLAGS)

+##################
+# GCC5 LOONGARCH64 definitions
+##################
+*_GCC5_LOONGARCH64_OBJCOPY_PATH =
ENV(GCC5_LOONGARCH64_PREFIX)objcopy
+*_GCC5_LOONGARCH64_CC_PATH =
ENV(GCC5_LOONGARCH64_PREFIX)gcc
+*_GCC5_LOONGARCH64_SLINK_PATH =
ENV(GCC5_LOONGARCH64_PREFIX)gcc-ar
+*_GCC5_LOONGARCH64_DLINK_PATH =
ENV(GCC5_LOONGARCH64_PREFIX)gcc
+*_GCC5_LOONGARCH64_ASLDLINK_PATH =
ENV(GCC5_LOONGARCH64_PREFIX)gcc
+*_GCC5_LOONGARCH64_ASM_PATH =
ENV(GCC5_LOONGARCH64_PREFIX)gcc
+*_GCC5_LOONGARCH64_PP_PATH =
ENV(GCC5_LOONGARCH64_PREFIX)gcc
+*_GCC5_LOONGARCH64_VFRPP_PATH =
ENV(GCC5_LOONGARCH64_PREFIX)gcc
+*_GCC5_LOONGARCH64_ASLCC_PATH =
ENV(GCC5_LOONGARCH64_PREFIX)gcc
+*_GCC5_LOONGARCH64_ASLPP_PATH =
ENV(GCC5_LOONGARCH64_PREFIX)gcc
+*_GCC5_LOONGARCH64_RC_PATH =
ENV(GCC5_LOONGARCH64_PREFIX)objcopy
+
+*_GCC5_LOONGARCH64_ASLCC_FLAGS = DEF(GCC_ASLCC_FLAGS)
+*_GCC5_LOONGARCH64_ASLDLINK_FLAGS =
DEF(GCC5_LOONGARCH64_ASLDLINK_FLAGS)
+*_GCC5_LOONGARCH64_ASM_FLAGS =
DEF(GCC5_LOONGARCH64_ASM_FLAGS)
+*_GCC5_LOONGARCH64_CC_FLAGS =
DEF(GCC5_LOONGARCH64_CC_FLAGS)
+*_GCC5_LOONGARCH64_DLINK_FLAGS =
DEF(GCC5_LOONGARCH64_DLINK_FLAGS)
+*_GCC5_LOONGARCH64_DLINK2_FLAGS =
DEF(GCC5_LOONGARCH64_DLINK2_FLAGS)
+*_GCC5_LOONGARCH64_RC_FLAGS =
DEF(GCC_LOONGARCH64_RC_FLAGS)
+*_GCC5_LOONGARCH64_OBJCOPY_FLAGS =
+*_GCC5_LOONGARCH64_NASM_FLAGS = -f elf32
+*_GCC5_LOONGARCH64_PP_FLAGS =
DEF(GCC5_LOONGARCH64_PP_FLAGS)
+
+DEBUG_GCC5_LOONGARCH64_CC_FLAGS =
DEF(GCC5_LOONGARCH64_CC_FLAGS)
+RELEASE_GCC5_LOONGARCH64_CC_FLAGS =
DEF(GCC5_LOONGARCH64_CC_FLAGS) -Wno-unused-but-set-variable -
Wno-unused-variable
+

##########################################################
##########################
#
# CLANG35 - This configuration is used to compile under Linux to produce
--
2.27.0





Re: [staging/LoongArch RESEND PATCH v1 13/33] BaseTools: BaseTools changes for LoongArch platform.

Abner Chang
 

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Chao Li
Sent: Wednesday, February 9, 2022 2:55 PM
To: devel@edk2.groups.io
Cc: Bob Feng <bob.c.feng@...>; Liming Gao
<gaoliming@...>; Yuwei Chen <yuwei.chen@...>; Baoqi
Zhang <zhangbaoqi@...>
Subject: [edk2-devel] [staging/LoongArch RESEND PATCH v1 13/33]
BaseTools: BaseTools changes for LoongArch platform.

C code changes for building EDK2 LoongArch platform.

Cc: Bob Feng <bob.c.feng@...>
Cc: Liming Gao <gaoliming@...>
Cc: Yuwei Chen <yuwei.chen@...>

Signed-off-by: Chao Li <lichao@...>
Co-authored-by: Baoqi Zhang <zhangbaoqi@...>
---
BaseTools/Source/C/Common/BasePeCoff.c | 15 +-
BaseTools/Source/C/Common/PeCoffLoaderEx.c | 76 +++++++++
BaseTools/Source/C/GenFv/GenFvInternalLib.c | 128 ++++++++++++++-
BaseTools/Source/C/GenFw/Elf64Convert.c | 153 +++++++++++++++++-
BaseTools/Source/C/GenFw/elf_common.h | 58 +++++++
.../C/Include/IndustryStandard/PeImage.h | 57 ++++---
6 files changed, 454 insertions(+), 33 deletions(-)

diff --git a/BaseTools/Source/C/Common/BasePeCoff.c
b/BaseTools/Source/C/Common/BasePeCoff.c
index 62fbb2985c..30400d1341 100644
--- a/BaseTools/Source/C/Common/BasePeCoff.c
+++ b/BaseTools/Source/C/Common/BasePeCoff.c
@@ -5,6 +5,7 @@
Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
Portions Copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR>
Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All
rights reserved.<BR>
+Portions Copyright (c) 2022, Loongson Technology Corporation Limited. All
rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent

**/
@@ -68,6 +69,14 @@ PeCoffLoaderRelocateRiscVImage (
IN UINT64 Adjust
);

+RETURN_STATUS
+PeCoffLoaderRelocateLoongArch64Image (
+ IN UINT16 *Reloc,
+ IN OUT CHAR8 *Fixup,
+ IN OUT CHAR8 **FixupData,
+ IN UINT64 Adjust
+ );
+
STATIC
RETURN_STATUS
PeCoffLoaderGetPeHeader (
@@ -184,7 +193,8 @@ Returns:
ImageContext->Machine != EFI_IMAGE_MACHINE_ARMT && \
ImageContext->Machine != EFI_IMAGE_MACHINE_EBC && \
ImageContext->Machine != EFI_IMAGE_MACHINE_AARCH64 && \
- ImageContext->Machine != EFI_IMAGE_MACHINE_RISCV64) {
+ ImageContext->Machine != EFI_IMAGE_MACHINE_RISCV64 && \
+ ImageContext->Machine != EFI_IMAGE_MACHINE_LOONGARCH64) {
if (ImageContext->Machine == IMAGE_FILE_MACHINE_ARM) {
//
// There are two types of ARM images. Pure ARM and ARM/Thumb.
@@ -815,6 +825,9 @@ Returns:
case EFI_IMAGE_MACHINE_RISCV64:
Status = PeCoffLoaderRelocateRiscVImage (Reloc, Fixup, &FixupData,
Adjust);
break;
+ case EFI_IMAGE_MACHINE_LOONGARCH64:
+ Status = PeCoffLoaderRelocateLoongArch64Image (Reloc, Fixup,
&FixupData, Adjust);
+ break;
default:
Status = RETURN_UNSUPPORTED;
break;
diff --git a/BaseTools/Source/C/Common/PeCoffLoaderEx.c
b/BaseTools/Source/C/Common/PeCoffLoaderEx.c
index 799f282970..b50ce8bdef 100644
--- a/BaseTools/Source/C/Common/PeCoffLoaderEx.c
+++ b/BaseTools/Source/C/Common/PeCoffLoaderEx.c
@@ -4,6 +4,7 @@ IA32 and X64 Specific relocation fixups
Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
Portions Copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR>
Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights
reserved.<BR>
+Copyright (c) 2022, Loongson Technology Corporation Limited. All rights
reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent

--*/
@@ -332,3 +333,78 @@ PeCoffLoaderRelocateArmImage (

return RETURN_SUCCESS;
}
+
+/**
+ Performs a LoongArch specific relocation fixup.
+
+ @param Reloc Pointer to the relocation record.
+ @param Fixup Pointer to the address to fix up.
+ @param FixupData Pointer to a buffer to log the fixups.
+ @param Adjust The offset to adjust the fixup.
+
+ @return Status code.
+**/
+RETURN_STATUS
+PeCoffLoaderRelocateLoongArch64Image (
+ IN UINT16 *Reloc,
+ IN OUT CHAR8 *Fixup,
+ IN OUT CHAR8 **FixupData,
+ IN UINT64 Adjust
+ )
+{
+ UINT8 RelocType;
+ UINT64 Value = 0;
+ UINT64 Tmp1 = 0;
+ UINT64 Tmp2 = 0;
+
+ RelocType = ((*Reloc) >> 12);
+
+ switch (RelocType) {
+ case EFI_IMAGE_REL_BASED_LOONGARCH64_MARK_LA:
+ /* The next four instructions are used to load a 64 bit address, we
change it together*/
+ Value = (*(UINT32*)Fixup & 0x1ffffe0) << 7 | /* lu12i.w 20bits from
bit5 */
Please use double back slash for the comment in the function. So the comment in the entire file look consistent. This applied to the changes in this patch.

+ (*((UINT32*)Fixup + 1) & 0x3ffc00) >> 10; /* ori 12bits from bit10 */
+ Tmp1 = *((UINT32*)Fixup + 2) & 0x1ffffe0; /* lu32i.d 20bits from bit5
*/
+ Tmp2 = *((UINT32*)Fixup + 3) & 0x3ffc00; /* lu52i.d 12bits from
bit10 */
+ Value = Value | (Tmp1 << 27) | (Tmp2 << 42);
+
+ Value += Adjust;
+
+ *(UINT32*)Fixup = (*(UINT32*)Fixup & ~0x1ffffe0) | (((Value >> 12) &
0xfffff) << 5);
+ if (*FixupData != NULL) {
+ *FixupData = ALIGN_POINTER (*FixupData, sizeof (UINT32));
+ *(UINT32 *) (*FixupData) = *(UINT32*)Fixup;
+ *FixupData = *FixupData + sizeof (UINT32);
+ }
+
+ Fixup += sizeof(UINT32);
+ *(UINT32*)Fixup = (*(UINT32*)Fixup & ~0x3ffc00) | ((Value & 0xfff) <<
10);
+ if (*FixupData != NULL) {
+ *FixupData = ALIGN_POINTER (*FixupData, sizeof (UINT32));
+ *(UINT32 *) (*FixupData) = *(UINT32*)Fixup;
+ *FixupData = *FixupData + sizeof (UINT32);
+ }
+
+ Fixup += sizeof(UINT32);
+ *(UINT32*)Fixup = (*(UINT32*)Fixup & ~0x1ffffe0) | (((Value >> 32) &
0xfffff) << 5);
+ if (*FixupData != NULL) {
+ *FixupData = ALIGN_POINTER (*FixupData, sizeof (UINT32));
+ *(UINT32 *) (*FixupData) = *(UINT32*)Fixup;
+ *FixupData = *FixupData + sizeof (UINT32);
+ }
+
+ Fixup += sizeof(UINT32);
+ *(UINT32*)Fixup = (*(UINT32*)Fixup & ~0x3ffc00) | (((Value >> 52) &
0xfff) << 10);
+ if (*FixupData != NULL) {
+ *FixupData = ALIGN_POINTER (*FixupData, sizeof (UINT32));
+ *(UINT32 *) (*FixupData) = *(UINT32*)Fixup;
+ *FixupData = *FixupData + sizeof (UINT32);
+ }
+ break;
+ default:
+ Error (NULL, 0, 3000, "", "PeCoffLoaderRelocateLoongArch64Image:
Fixup[0x%x] Adjust[0x%llx] *Reloc[0x%x], type[0x%x].", *(UINT32*)Fixup,
Adjust, *Reloc, RelocType);
+ return RETURN_UNSUPPORTED;
+ }
+
+ return RETURN_SUCCESS;
+}
diff --git a/BaseTools/Source/C/GenFv/GenFvInternalLib.c
b/BaseTools/Source/C/GenFv/GenFvInternalLib.c
index d650a527a5..9c518b3609 100644
--- a/BaseTools/Source/C/GenFv/GenFvInternalLib.c
+++ b/BaseTools/Source/C/GenFv/GenFvInternalLib.c
@@ -5,6 +5,7 @@ Copyright (c) 2004 - 2018, Intel Corporation. All rights
reserved.<BR>
Portions Copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR>
Portions Copyright (c) 2016 HP Development Company, L.P.<BR>
Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All
rights reserved.<BR>
+Portions Copyright (c) 2022, Loongson Technology Corporation Limited. All
rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent

**/
@@ -57,6 +58,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent

BOOLEAN mArm = FALSE;
BOOLEAN mRiscV = FALSE;
+BOOLEAN mLoongArch = FALSE;
STATIC UINT32 MaxFfsAlignment = 0;
BOOLEAN VtfFileFlag = FALSE;

@@ -2416,6 +2418,102 @@ Returns:
return EFI_SUCCESS;
}

+EFI_STATUS
+UpdateLoongArchResetVectorIfNeeded (
+ IN MEMORY_FILE *FvImage,
+ IN FV_INFO *FvInfo
+ )
+/*++
+
+Routine Description:
+ This parses the FV looking for SEC and patches that address into the
+ beginning of the FV header.
+
+ For LoongArch ISA, the reset vector is at 0x1c000000.
+
+ We relocate it to SecCoreEntry and copy the ResetVector code to the
+ beginning of the FV.
+
+Arguments:
+ FvImage Memory file for the FV memory image
+ FvInfo Information read from INF file.
+
+Returns:
+
+ EFI_SUCCESS Function Completed successfully.
+ EFI_ABORTED Error encountered.
+ EFI_INVALID_PARAMETER A required parameter was NULL.
+ EFI_NOT_FOUND PEI Core file not found.
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_FILE_SECTION_POINTER SecPe32;
+ BOOLEAN UpdateVectorSec = FALSE;
+ UINT16 MachineType = 0;
+ EFI_PHYSICAL_ADDRESS SecCoreEntryAddress = 0;
+
+ //
+ // Verify input parameters
+ //
+ if (FvImage == NULL || FvInfo == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Locate an SEC Core instance and if found extract the machine type and
entry point address
+ //
+ Status = FindCorePeSection(FvImage->FileImage, FvInfo->Size,
EFI_FV_FILETYPE_SECURITY_CORE, &SecPe32);
+ if (!EFI_ERROR(Status)) {
+
+ Status = GetCoreMachineType(SecPe32, &MachineType);
+ if (EFI_ERROR(Status)) {
+ Error(NULL, 0, 3000, "Invalid", "Could not get the PE32 machine type for
SEC Core.");
+ return EFI_ABORTED;
+ }
+
+ Status = GetCoreEntryPointAddress(FvImage->FileImage, FvInfo,
SecPe32, &SecCoreEntryAddress);
+ if (EFI_ERROR(Status)) {
+ Error(NULL, 0, 3000, "Invalid", "Could not get the PE32 entry point
address for SEC Core.");
+ return EFI_ABORTED;
+ }
+
+ UpdateVectorSec = TRUE;
+ }
+
+ if (!UpdateVectorSec)
+ return EFI_SUCCESS;
+
+ if (MachineType == EFI_IMAGE_MACHINE_LOONGARCH64) {
+ UINT32 ResetVector[3];
+ UINT32 InstrStack;
+
+ memset(ResetVector, 0, sizeof (ResetVector));
+
+ /* if we found an SEC core entry point then generate a branch instruction
*/
+ if (UpdateVectorSec) {
+ VerboseMsg("UpdateLoongArchResetVectorIfNeeded updating
LOONGARCH64 SEC vector");
+
+ InstrStack = (SecCoreEntryAddress >> 12) & 0xfffff;
+ ResetVector[0] = 0x14000001 | (InstrStack << 5); /* lu12i.w ra si20 */
+
+ InstrStack = (SecCoreEntryAddress & 0x0fff);
+ ResetVector[1] = 0x03800021 | (InstrStack << 10); /* ori ra, ra, ui12 */
+ ResetVector[2] = 0x4c000021; /* jirl ra, ra, 0 */
+ }
+
+ //
+ // Copy to the beginning of the FV
+ //
+ memcpy(FvImage->FileImage, ResetVector, sizeof (ResetVector));
+ } else {
+ Error(NULL, 0, 3000, "Invalid", "Unknown machine type");
+ return EFI_ABORTED;
+ }
+
+ return EFI_SUCCESS;
+}
+
EFI_STATUS
GetPe32Info (
IN UINT8 *Pe32,
@@ -2509,7 +2607,7 @@ Returns:
//
if ((*MachineType != EFI_IMAGE_MACHINE_IA32) && (*MachineType !=
EFI_IMAGE_MACHINE_X64) && (*MachineType !=
EFI_IMAGE_MACHINE_EBC) &&
(*MachineType != EFI_IMAGE_MACHINE_ARMT) && (*MachineType !=
EFI_IMAGE_MACHINE_AARCH64) &&
- (*MachineType != EFI_IMAGE_MACHINE_RISCV64)) {
+ (*MachineType != EFI_IMAGE_MACHINE_RISCV64) &&
(*MachineType != EFI_IMAGE_MACHINE_LOONGARCH64)) {
Error (NULL, 0, 3000, "Invalid", "Unrecognized machine type in the PE32
file.");
return EFI_UNSUPPORTED;
}
@@ -2953,7 +3051,7 @@ Returns:
goto Finish;
}

- if (!mArm && !mRiscV) {
+ if (!mArm && !mRiscV && !mLoongArch) {
//
// Update reset vector (SALE_ENTRY for IPF)
// Now for IA32 and IA64 platform, the fv which has bsf file must have the
@@ -3004,6 +3102,19 @@ Returns:
FvHeader->Checksum = CalculateChecksum16 ((UINT16 *) FvHeader,
FvHeader->HeaderLength / sizeof (UINT16));
}

+ if (mLoongArch) {
+ Status = UpdateLoongArchResetVectorIfNeeded (&FvImageMemoryFile,
&mFvDataInfo);
+ if (EFI_ERROR (Status)) {
+ Error (NULL, 0, 3000, "Invalid", "Could not update the reset vector.");
+ goto Finish;
+ }
+ //
+ // Update Checksum for FvHeader
+ //
+ FvHeader->Checksum = 0;
+ FvHeader->Checksum = CalculateChecksum16 ((UINT16 *) FvHeader,
FvHeader->HeaderLength / sizeof (UINT16));
+ }
+
//
// Update FV Alignment attribute to the largest alignment of all the FFS files
in the FV
//
@@ -3450,6 +3561,11 @@ Returns:
VerboseMsg("Located ARM/AArch64 SEC/PEI core in child FV");
mArm = TRUE;
}
+ // machine type is LOONGARCH64, set a flag so LOONGARCH64 reset
vector procesing occurs
+ if ((MachineType == EFI_IMAGE_MACHINE_LOONGARCH64)) {
+ VerboseMsg("Located LOONGARCH64 SEC core in child FV");
+ mLoongArch = TRUE;
+ }
}

//
@@ -3608,6 +3724,10 @@ Returns:
mRiscV = TRUE;
}

+ if ( (ImageContext.Machine == EFI_IMAGE_MACHINE_LOONGARCH64) ) {
+ mLoongArch = TRUE;
+ }
+
//
// Keep Image Context for PE image in FV
//
@@ -3885,6 +4005,10 @@ Returns:
mArm = TRUE;
}

+ if ( (ImageContext.Machine == EFI_IMAGE_MACHINE_LOONGARCH64) ) {
+ mLoongArch = TRUE;
+ }
+
//
// Keep Image Context for TE image in FV
//
diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c
b/BaseTools/Source/C/GenFw/Elf64Convert.c
index 0bb3ead228..b66aadfd6c 100644
--- a/BaseTools/Source/C/GenFw/Elf64Convert.c
+++ b/BaseTools/Source/C/GenFw/Elf64Convert.c
@@ -4,6 +4,7 @@ Elf64 convert solution
Copyright (c) 2010 - 2021, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>
Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All
rights reserved.<BR>
+Portions Copyright (c) 2022, Loongson Technology Corporation Limited. All
rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent

@@ -163,7 +164,7 @@ InitializeElf64 (
Error (NULL, 0, 3000, "Unsupported", "ELF e_type not ET_EXEC or
ET_DYN");
return FALSE;
}
- if (!((mEhdr->e_machine == EM_X86_64) || (mEhdr->e_machine ==
EM_AARCH64) || (mEhdr->e_machine == EM_RISCV64))) {
+ if (!((mEhdr->e_machine == EM_X86_64) || (mEhdr->e_machine ==
EM_AARCH64) || (mEhdr->e_machine == EM_RISCV64) || (mEhdr-
e_machine == EM_LOONGARCH64))) {
Warning (NULL, 0, 3000, "Unsupported", "ELF e_machine is not Elf64
machine.");
}
if (mEhdr->e_version != EV_CURRENT) {
@@ -730,6 +731,7 @@ ScanSections64 (
case EM_X86_64:
case EM_AARCH64:
case EM_RISCV64:
+ case EM_LOONGARCH64:
mCoffOffset += sizeof (EFI_IMAGE_NT_HEADERS64);
break;
default:
@@ -943,6 +945,10 @@ ScanSections64 (
NtHdr->Pe32Plus.FileHeader.Machine = EFI_IMAGE_MACHINE_RISCV64;
NtHdr->Pe32Plus.OptionalHeader.Magic =
EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;
break;
+ case EM_LOONGARCH64:
+ NtHdr->Pe32Plus.FileHeader.Machine =
EFI_IMAGE_MACHINE_LOONGARCH64;
+ NtHdr->Pe32Plus.OptionalHeader.Magic =
EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;
+ break;

default:
VerboseMsg ("%s unknown e_machine type. Assume X64",
(UINTN)mEhdr->e_machine);
@@ -1149,10 +1155,10 @@ WriteSections64 (
}

//
- // Skip error on EM_RISCV64 becasue no symble name is built
- // from RISC-V toolchain.
+ // Skip error on EM_RISCV64 and EM_LOONGARCH64 becasue no
symble name is built
+ // from RISC-V and LoongArch toolchain.
//
- if (mEhdr->e_machine != EM_RISCV64) {
+ if ((mEhdr->e_machine != EM_RISCV64) && (mEhdr->e_machine !=
EM_LOONGARCH64)) {
Error (NULL, 0, 3000, "Invalid",
"%s: Bad definition for symbol '%s'@%#llx or unsupported symbol
type. "
"For example, absolute and undefined symbols are not
supported.",
@@ -1417,6 +1423,74 @@ WriteSections64 (
// Write section for RISC-V 64 architecture.
//
WriteSectionRiscV64 (Rel, Targ, SymShdr, Sym);
+ } else if (mEhdr->e_machine == EM_LOONGARCH64) {
+ switch (ELF_R_TYPE(Rel->r_info)) {
+
+ case R_LARCH_SOP_PUSH_ABSOLUTE:
+ //
+ // Absolute relocation.
+ //
+ *(UINT64 *)Targ = *(UINT64 *)Targ - SymShdr->sh_addr +
mCoffSectionsOffset[Sym->st_shndx];
+ break;
+
+ case R_LARCH_MARK_LA:
+ case R_LARCH_64:
+ case R_LARCH_NONE:
+ case R_LARCH_32:
+ case R_LARCH_RELATIVE:
+ case R_LARCH_COPY:
+ case R_LARCH_JUMP_SLOT:
+ case R_LARCH_TLS_DTPMOD32:
+ case R_LARCH_TLS_DTPMOD64:
+ case R_LARCH_TLS_DTPREL32:
+ case R_LARCH_TLS_DTPREL64:
+ case R_LARCH_TLS_TPREL32:
+ case R_LARCH_TLS_TPREL64:
+ case R_LARCH_IRELATIVE:
+ case R_LARCH_MARK_PCREL:
+ case R_LARCH_SOP_PUSH_PCREL:
+ case R_LARCH_SOP_PUSH_DUP:
+ case R_LARCH_SOP_PUSH_GPREL:
+ case R_LARCH_SOP_PUSH_TLS_TPREL:
+ case R_LARCH_SOP_PUSH_TLS_GOT:
+ case R_LARCH_SOP_PUSH_TLS_GD:
+ case R_LARCH_SOP_PUSH_PLT_PCREL:
+ case R_LARCH_SOP_ASSERT:
+ case R_LARCH_SOP_NOT:
+ case R_LARCH_SOP_SUB:
+ case R_LARCH_SOP_SL:
+ case R_LARCH_SOP_SR:
+ case R_LARCH_SOP_ADD:
+ case R_LARCH_SOP_AND:
+ case R_LARCH_SOP_IF_ELSE:
+ case R_LARCH_SOP_POP_32_S_10_5:
+ case R_LARCH_SOP_POP_32_U_10_12:
+ case R_LARCH_SOP_POP_32_S_10_12:
+ case R_LARCH_SOP_POP_32_S_10_16:
+ case R_LARCH_SOP_POP_32_S_10_16_S2:
+ case R_LARCH_SOP_POP_32_S_5_20:
+ case R_LARCH_SOP_POP_32_S_0_5_10_16_S2:
+ case R_LARCH_SOP_POP_32_S_0_10_10_16_S2:
+ case R_LARCH_SOP_POP_32_U:
+ case R_LARCH_ADD8:
+ case R_LARCH_ADD16:
+ case R_LARCH_ADD24:
+ case R_LARCH_ADD32:
+ case R_LARCH_ADD64:
+ case R_LARCH_SUB8:
+ case R_LARCH_SUB16:
+ case R_LARCH_SUB24:
+ case R_LARCH_SUB32:
+ case R_LARCH_SUB64:
+ case R_LARCH_GNU_VTINHERIT:
+ case R_LARCH_GNU_VTENTRY:
+ //
+ // These types are not used or do not need to fix the offsets.
+ //
+ break;
+ default:
+ Error (NULL, 0, 3000, "Invalid", "WriteSections64(): %s unsupported
ELF EM_LOONGARCH64 relocation 0x%x.", mInImageName, (unsigned)
ELF64_R_TYPE(Rel->r_info));
+ }
} else {
Error (NULL, 0, 3000, "Invalid", "Not a supported machine type");
}
@@ -1647,6 +1721,77 @@ WriteRelocations64 (
default:
Error (NULL, 0, 3000, "Invalid", "WriteRelocations64(): %s
unsupported ELF EM_RISCV64 relocation 0x%x.", mInImageName, (unsigned)
ELF_R_TYPE(Rel->r_info));
}
+ } else if (mEhdr->e_machine == EM_LOONGARCH64) {
+ switch (ELF_R_TYPE(Rel->r_info)) {
+ case R_LARCH_MARK_LA:
+ CoffAddFixup(
+ (UINT32) ((UINT64) mCoffSectionsOffset[RelShdr->sh_info]
+ + (Rel->r_offset - SecShdr->sh_addr)),
+ EFI_IMAGE_REL_BASED_LOONGARCH64_MARK_LA);
+ break;
+ case R_LARCH_64:
+ CoffAddFixup(
+ (UINT32) ((UINT64) mCoffSectionsOffset[RelShdr->sh_info]
+ + (Rel->r_offset - SecShdr->sh_addr)),
+ EFI_IMAGE_REL_BASED_DIR64);
+ break;
+ case R_LARCH_NONE:
+ case R_LARCH_32:
+ case R_LARCH_RELATIVE:
+ case R_LARCH_COPY:
+ case R_LARCH_JUMP_SLOT:
+ case R_LARCH_TLS_DTPMOD32:
+ case R_LARCH_TLS_DTPMOD64:
+ case R_LARCH_TLS_DTPREL32:
+ case R_LARCH_TLS_DTPREL64:
+ case R_LARCH_TLS_TPREL32:
+ case R_LARCH_TLS_TPREL64:
+ case R_LARCH_IRELATIVE:
+ case R_LARCH_MARK_PCREL:
+ case R_LARCH_SOP_PUSH_PCREL:
+ case R_LARCH_SOP_PUSH_ABSOLUTE:
+ case R_LARCH_SOP_PUSH_DUP:
+ case R_LARCH_SOP_PUSH_GPREL:
+ case R_LARCH_SOP_PUSH_TLS_TPREL:
+ case R_LARCH_SOP_PUSH_TLS_GOT:
+ case R_LARCH_SOP_PUSH_TLS_GD:
+ case R_LARCH_SOP_PUSH_PLT_PCREL:
+ case R_LARCH_SOP_ASSERT:
+ case R_LARCH_SOP_NOT:
+ case R_LARCH_SOP_SUB:
+ case R_LARCH_SOP_SL:
+ case R_LARCH_SOP_SR:
+ case R_LARCH_SOP_ADD:
+ case R_LARCH_SOP_AND:
+ case R_LARCH_SOP_IF_ELSE:
+ case R_LARCH_SOP_POP_32_S_10_5:
+ case R_LARCH_SOP_POP_32_U_10_12:
+ case R_LARCH_SOP_POP_32_S_10_12:
+ case R_LARCH_SOP_POP_32_S_10_16:
+ case R_LARCH_SOP_POP_32_S_10_16_S2:
+ case R_LARCH_SOP_POP_32_S_5_20:
+ case R_LARCH_SOP_POP_32_S_0_5_10_16_S2:
+ case R_LARCH_SOP_POP_32_S_0_10_10_16_S2:
+ case R_LARCH_SOP_POP_32_U:
+ case R_LARCH_ADD8:
+ case R_LARCH_ADD16:
+ case R_LARCH_ADD24:
+ case R_LARCH_ADD32:
+ case R_LARCH_ADD64:
+ case R_LARCH_SUB8:
+ case R_LARCH_SUB16:
+ case R_LARCH_SUB24:
+ case R_LARCH_SUB32:
+ case R_LARCH_SUB64:
+ case R_LARCH_GNU_VTINHERIT:
+ case R_LARCH_GNU_VTENTRY:
+ //
+ // These types are not used or do not require fixup in PE format
files.
+ //
+ break;
+ default:
+ Error (NULL, 0, 3000, "Invalid", "WriteRelocations64(): %s
unsupported ELF EM_LOONGARCH64 relocation 0x%x.", mInImageName,
(unsigned) ELF64_R_TYPE(Rel->r_info));
+ }
} else {
Error (NULL, 0, 3000, "Not Supported", "This tool does not support
relocations for ELF with e_machine %u (processor type).", (unsigned) mEhdr-
e_machine);
}
diff --git a/BaseTools/Source/C/GenFw/elf_common.h
b/BaseTools/Source/C/GenFw/elf_common.h
index b67f59e7a0..34c8748f39 100644
--- a/BaseTools/Source/C/GenFw/elf_common.h
+++ b/BaseTools/Source/C/GenFw/elf_common.h
@@ -4,6 +4,7 @@ Ported ELF include files from FreeBSD
Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.<BR>
Portions Copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR>
Portion Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All
rights reserved.<BR>
+Portions Copyright (c) 2022, Loongson Technology Corporation Limited. All
rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent


@@ -181,6 +182,7 @@ typedef struct {
#define EM_AARCH64 183 /* ARM 64bit Architecture */
#define EM_RISCV64 243 /* 64bit RISC-V Architecture */
#define EM_RISCV 244 /* 32bit RISC-V Architecture */
+#define EM_LOONGARCH64 258 /* LoongArch 64-bit Architecture */
Do you have 32-bit LOONGARCH that also requires a value in spec?

Abner

/* Non-standard or deprecated. */
#define EM_486 6 /* Intel i486. */
@@ -1042,4 +1044,60 @@ typedef struct {
#define R_RISCV_SET8 54
#define R_RISCV_SET16 55
#define R_RISCV_SET32 56
+
+/*
+ * LoongArch relocation types
+ */
+#define R_LARCH_NONE 0
+#define R_LARCH_32 1
+#define R_LARCH_64 2
+#define R_LARCH_RELATIVE 3
+#define R_LARCH_COPY 4
+#define R_LARCH_JUMP_SLOT 5
+#define R_LARCH_TLS_DTPMOD32 6
+#define R_LARCH_TLS_DTPMOD64 7
+#define R_LARCH_TLS_DTPREL32 8
+#define R_LARCH_TLS_DTPREL64 9
+#define R_LARCH_TLS_TPREL32 10
+#define R_LARCH_TLS_TPREL64 11
+#define R_LARCH_IRELATIVE 12
+#define R_LARCH_MARK_LA 20
+#define R_LARCH_MARK_PCREL 21
+#define R_LARCH_SOP_PUSH_PCREL 22
+#define R_LARCH_SOP_PUSH_ABSOLUTE 23
+#define R_LARCH_SOP_PUSH_DUP 24
+#define R_LARCH_SOP_PUSH_GPREL 25
+#define R_LARCH_SOP_PUSH_TLS_TPREL 26
+#define R_LARCH_SOP_PUSH_TLS_GOT 27
+#define R_LARCH_SOP_PUSH_TLS_GD 28
+#define R_LARCH_SOP_PUSH_PLT_PCREL 29
+#define R_LARCH_SOP_ASSERT 30
+#define R_LARCH_SOP_NOT 31
+#define R_LARCH_SOP_SUB 32
+#define R_LARCH_SOP_SL 33
+#define R_LARCH_SOP_SR 34
+#define R_LARCH_SOP_ADD 35
+#define R_LARCH_SOP_AND 36
+#define R_LARCH_SOP_IF_ELSE 37
+#define R_LARCH_SOP_POP_32_S_10_5 38
+#define R_LARCH_SOP_POP_32_U_10_12 39
+#define R_LARCH_SOP_POP_32_S_10_12 40
+#define R_LARCH_SOP_POP_32_S_10_16 41
+#define R_LARCH_SOP_POP_32_S_10_16_S2 42
+#define R_LARCH_SOP_POP_32_S_5_20 43
+#define R_LARCH_SOP_POP_32_S_0_5_10_16_S2 44
+#define R_LARCH_SOP_POP_32_S_0_10_10_16_S2 45
+#define R_LARCH_SOP_POP_32_U 46
+#define R_LARCH_ADD8 47
+#define R_LARCH_ADD16 48
+#define R_LARCH_ADD24 49
+#define R_LARCH_ADD32 50
+#define R_LARCH_ADD64 51
+#define R_LARCH_SUB8 52
+#define R_LARCH_SUB16 53
+#define R_LARCH_SUB24 54
+#define R_LARCH_SUB32 55
+#define R_LARCH_SUB64 56
+#define R_LARCH_GNU_VTINHERIT 57
+#define R_LARCH_GNU_VTENTRY 58
#endif /* !_SYS_ELF_COMMON_H_ */
diff --git a/BaseTools/Source/C/Include/IndustryStandard/PeImage.h
b/BaseTools/Source/C/Include/IndustryStandard/PeImage.h
index f17b8ee19b..80961e5576 100644
--- a/BaseTools/Source/C/Include/IndustryStandard/PeImage.h
+++ b/BaseTools/Source/C/Include/IndustryStandard/PeImage.h
@@ -7,6 +7,7 @@
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR>
Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights
reserved.<BR>
+ Copyright (c) 2022, Loongson Technology Corporation Limited. All rights
reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent

@@ -36,23 +37,25 @@
//
// PE32+ Machine type for EFI images
//
-#define IMAGE_FILE_MACHINE_I386 0x014c
-#define IMAGE_FILE_MACHINE_EBC 0x0EBC
-#define IMAGE_FILE_MACHINE_X64 0x8664
-#define IMAGE_FILE_MACHINE_ARM 0x01c0 // Thumb only
-#define IMAGE_FILE_MACHINE_ARMT 0x01c2 // 32bit Mixed ARM and
Thumb/Thumb 2 Little Endian
-#define IMAGE_FILE_MACHINE_ARM64 0xAA64 // 64bit ARM
Architecture, Little Endian
-#define IMAGE_FILE_MACHINE_RISCV64 0x5064 // 64bit RISC-V ISA
+#define IMAGE_FILE_MACHINE_I386 0x014c
+#define IMAGE_FILE_MACHINE_EBC 0x0EBC
+#define IMAGE_FILE_MACHINE_X64 0x8664
+#define IMAGE_FILE_MACHINE_ARM 0x01c0 // Thumb only
+#define IMAGE_FILE_MACHINE_ARMT 0x01c2 // 32bit Mixed ARM and
Thumb/Thumb 2 Little Endian
+#define IMAGE_FILE_MACHINE_ARM64 0xAA64 // 64bit ARM
Architecture, Little Endian
+#define IMAGE_FILE_MACHINE_RISCV64 0x5064 // 64bit RISC-V ISA
+#define IMAGE_FILE_MACHINE_LOONGARCH64 0x6264 // 64bit LoongArch
Architecture

//
// Support old names for backward compatible
//
-#define EFI_IMAGE_MACHINE_IA32 IMAGE_FILE_MACHINE_I386
-#define EFI_IMAGE_MACHINE_EBC IMAGE_FILE_MACHINE_EBC
-#define EFI_IMAGE_MACHINE_X64 IMAGE_FILE_MACHINE_X64
-#define EFI_IMAGE_MACHINE_ARMT IMAGE_FILE_MACHINE_ARMT
-#define EFI_IMAGE_MACHINE_AARCH64 IMAGE_FILE_MACHINE_ARM64
-#define EFI_IMAGE_MACHINE_RISCV64 IMAGE_FILE_MACHINE_RISCV64
+#define EFI_IMAGE_MACHINE_IA32 IMAGE_FILE_MACHINE_I386
+#define EFI_IMAGE_MACHINE_EBC IMAGE_FILE_MACHINE_EBC
+#define EFI_IMAGE_MACHINE_X64 IMAGE_FILE_MACHINE_X64
+#define EFI_IMAGE_MACHINE_ARMT IMAGE_FILE_MACHINE_ARMT
+#define EFI_IMAGE_MACHINE_AARCH64
IMAGE_FILE_MACHINE_ARM64
+#define EFI_IMAGE_MACHINE_RISCV64 IMAGE_FILE_MACHINE_RISCV64
+#define EFI_IMAGE_MACHINE_LOONGARCH64
IMAGE_FILE_MACHINE_LOONGARCH64

#define EFI_IMAGE_DOS_SIGNATURE 0x5A4D // MZ
#define EFI_IMAGE_OS2_SIGNATURE 0x454E // NE
@@ -500,19 +503,21 @@ typedef struct {
//
// Based relocation types.
//
-#define EFI_IMAGE_REL_BASED_ABSOLUTE 0
-#define EFI_IMAGE_REL_BASED_HIGH 1
-#define EFI_IMAGE_REL_BASED_LOW 2
-#define EFI_IMAGE_REL_BASED_HIGHLOW 3
-#define EFI_IMAGE_REL_BASED_HIGHADJ 4
-#define EFI_IMAGE_REL_BASED_MIPS_JMPADDR 5
-#define EFI_IMAGE_REL_BASED_ARM_MOV32A 5
-#define EFI_IMAGE_REL_BASED_RISCV_HI20 5
-#define EFI_IMAGE_REL_BASED_ARM_MOV32T 7
-#define EFI_IMAGE_REL_BASED_RISCV_LOW12I 7
-#define EFI_IMAGE_REL_BASED_RISCV_LOW12S 8
-#define EFI_IMAGE_REL_BASED_IA64_IMM64 9
-#define EFI_IMAGE_REL_BASED_DIR64 10
+#define EFI_IMAGE_REL_BASED_ABSOLUTE 0
+#define EFI_IMAGE_REL_BASED_HIGH 1
+#define EFI_IMAGE_REL_BASED_LOW 2
+#define EFI_IMAGE_REL_BASED_HIGHLOW 3
+#define EFI_IMAGE_REL_BASED_HIGHADJ 4
+#define EFI_IMAGE_REL_BASED_MIPS_JMPADDR 5
+#define EFI_IMAGE_REL_BASED_ARM_MOV32A 5
+#define EFI_IMAGE_REL_BASED_RISCV_HI20 5
+#define EFI_IMAGE_REL_BASED_ARM_MOV32T 7
+#define EFI_IMAGE_REL_BASED_RISCV_LOW12I 7
+#define EFI_IMAGE_REL_BASED_RISCV_LOW12S 8
+#define EFI_IMAGE_REL_BASED_LOONGARCH32_MARK_LA 8
+#define EFI_IMAGE_REL_BASED_LOONGARCH64_MARK_LA 8
+#define EFI_IMAGE_REL_BASED_IA64_IMM64 9
+#define EFI_IMAGE_REL_BASED_DIR64 10


///
--
2.27.0





Re: [PATCH v3] OvmfPkg/BhyveBhfPkg: add support for QemuFwCfg

Yao, Jiewen
 

Acked-by: Jiewen Yao <Jiewen.yao@...>

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Corvin
Köhne
Sent: Friday, April 8, 2022 1:53 PM
Cc: Corvin Köhne <CorvinK@...>; Köhne, Corvin
<c.koehne@...>; Ard Biesheuvel <ardb+tianocore@...>; Yao,
Jiewen <jiewen.yao@...>; Justen, Jordan L <jordan.l.justen@...>;
devel@edk2.groups.io; FreeBSD Virtualization <freebsd-
virtualization@...>; Gerd Hoffmann <kraxel@...>; Rebecca
Cran <rebecca@...>; Peter Grehan <grehan@...>
Subject: [edk2-devel] [PATCH v3] OvmfPkg/BhyveBhfPkg: add support for
QemuFwCfg

From: Corvin Köhne <CorvinK@...>

QemuFwCfg is much more powerful than BhyveFwCtl. Sadly, BhyveFwCtl
decided to use the same IO ports as QemuFwCfg. It's not possible to use
both interfaces simultaneously. So, prefer QemuFwCfg over BhyveFwCtl.

Signed-off-by: Corvin Köhne <c.koehne@...>
Acked-by: Gerd Hoffmann <kraxel@...>
Acked-by: Rebecca Cran <rebecca@...>
Acked-by: Peter Grehan <grehan@...>
CC: Ard Biesheuvel <ardb+tianocore@...>
CC: Jiewen Yao <jiewen.yao@...>
CC: Jordan Justen <jordan.l.justen@...>
CC: devel@edk2.groups.io
CC: FreeBSD Virtualization <freebsd-virtualization@...>
---
OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf | 1 +
OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c | 41 ++++++++++++++++++++-
--
OvmfPkg/Bhyve/BhyveX64.dsc | 4 +--
3 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf
b/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf
index 595fd055f9..94c65f32dc 100644
--- a/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf
+++ b/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf
@@ -43,6 +43,7 @@
MemoryAllocationLib
OrderedCollectionLib
PcdLib
+ QemuFwCfgLib
UefiBootServicesTableLib
UefiDriverEntryPoint
UefiLib
diff --git a/OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c
b/OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c
index 8e80aa33e1..e216a21bfa 100644
--- a/OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c
+++ b/OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c
@@ -11,6 +11,41 @@
#include <Library/BaseMemoryLib.h>
#include <Library/BhyveFwCtlLib.h>
#include <Library/MemoryAllocationLib.h>
+#include <Library/QemuFwCfgLib.h> // QemuFwCfgFindFile()
+
+STATIC
+EFI_STATUS
+EFIAPI
+BhyveGetCpuCount (
+ OUT UINT32 *CpuCount
+ )
+{
+ FIRMWARE_CONFIG_ITEM Item;
+ UINTN Size;
+
+ if (QemuFwCfgIsAvailable ()) {
+ if (EFI_ERROR (QemuFwCfgFindFile ("opt/bhyve/hw.ncpu", &Item, &Size))) {
+ return EFI_NOT_FOUND;
+ } else if (Size != sizeof (*CpuCount)) {
+ return EFI_BAD_BUFFER_SIZE;
+ }
+
+ QemuFwCfgSelectItem (Item);
+ QemuFwCfgReadBytes (Size, CpuCount);
+
+ return EFI_SUCCESS;
+ }
+
+ //
+ // QemuFwCfg not available, try BhyveFwCtl.
+ //
+ Size = sizeof (*CpuCount);
+ if (BhyveFwCtlGet ("hw.ncpu", CpuCount, &Size) == RETURN_SUCCESS) {
+ return EFI_SUCCESS;
+ }
+
+ return EFI_UNSUPPORTED;
+}

STATIC
EFI_STATUS
@@ -23,7 +58,6 @@ BhyveInstallAcpiMadtTable (
)
{
UINT32 CpuCount;
- UINTN cSize;
UINTN NewBufferSize;
EFI_ACPI_1_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER *Madt;
EFI_ACPI_1_0_PROCESSOR_LOCAL_APIC_STRUCTURE *LocalApic;
@@ -36,9 +70,8 @@ BhyveInstallAcpiMadtTable (
ASSERT (AcpiTableBufferSize >= sizeof (EFI_ACPI_DESCRIPTION_HEADER));

// Query the host for the number of vCPUs
- CpuCount = 0;
- cSize = sizeof (CpuCount);
- if (BhyveFwCtlGet ("hw.ncpu", &CpuCount, &cSize) == RETURN_SUCCESS) {
+ Status = BhyveGetCpuCount (&CpuCount);
+ if (!EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "Retrieved CpuCount %d\n", CpuCount));
ASSERT (CpuCount >= 1);
} else {
diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc
index 5fa08bebd7..14070fd6dd 100644
--- a/OvmfPkg/Bhyve/BhyveX64.dsc
+++ b/OvmfPkg/Bhyve/BhyveX64.dsc
@@ -163,8 +163,7 @@

SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/D
xeSecurityManagementLib.inf
UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf

SerializeVariablesLib|OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLi
b.inf
- QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibNull.inf
-
QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNu
ll.inf
+ QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgDxeLib.inf
BhyveFwCtlLib|OvmfPkg/Library/BhyveFwCtlLib/BhyveFwCtlLib.inf
VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf

MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptS
evLib.inf
@@ -355,6 +354,7 @@
!endif
PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
MpInitLib|UefiCpuPkg/Library/MpInitLibUp/MpInitLibUp.inf
+
QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwC
fg.inf

[LibraryClasses.common.UEFI_APPLICATION]
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
--
2.11.0

Beckhoff Automation GmbH & Co. KG | Managing Director: Dipl. Phys. Hans
Beckhoff
Registered office: Verl, Germany | Register court: Guetersloh HRA 7075







[PATCH] ShellPkg: Update smbiosview type 9 with SMBIOS 3.5 fields

Bo Chang Ke
 

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3896

update smbiosview type 9 related fileds.

Signed-off-by: Bo Chang Ke <bo-changx.ke@...>
Cc: Dandan Bi <dandan.bi@...>
Cc: Star Zeng <star.zeng@...>
---
MdePkg/Include/IndustryStandard/SmBios.h | 50 +++-
.../SmbiosView/PrintInfo.c | 11 +-
.../SmbiosView/QueryTable.c | 238 ++++++++++++++++++
.../SmbiosView/QueryTable.h | 36 +++
.../SmbiosView/SmbiosViewStrings.uni | 5 +-
5 files changed, 334 insertions(+), 6 deletions(-)

diff --git a/MdePkg/Include/IndustryStandard/SmBios.h b/MdePkg/Include/IndustryStandard/SmBios.h
index 2b1567b052..cb39470c92 100644
--- a/MdePkg/Include/IndustryStandard/SmBios.h
+++ b/MdePkg/Include/IndustryStandard/SmBios.h
@@ -1306,6 +1306,11 @@ typedef enum {
SlotTypePciExpressMini52pinWithBSKO = 0x21, ///< PCI Express Mini 52-pin (CEM spec. 2.0) with bottom-side keep-outs.
SlotTypePciExpressMini52pinWithoutBSKO = 0x22, ///< PCI Express Mini 52-pin (CEM spec. 2.0) without bottom-side keep-outs.
SlotTypePciExpressMini76pin = 0x23, ///< PCI Express Mini 76-pin (CEM spec. 2.0) Corresponds to Display-Mini card.
+ SlotTypePCIExpressGen4SFF_8639 = 0x24, ///< U.2
+ SlotTypePCIExpressGen5SFF_8639 = 0x25, ///< U.2
+ SlotTypeOCPNIC30SmallFormFactor = 0x26, ///< SFF
+ SlotTypeOCPNIC30LargeFormFactor = 0x27, ///< LFF
+ SlotTypeOCPNICPriorto30 = 0x28,
SlotTypeCXLFlexbus10 = 0x30,
SlotTypePC98C20 = 0xA0,
SlotTypePC98C24 = 0xA1,
@@ -1335,7 +1340,17 @@ typedef enum {
SlotTypePciExpressGen4X2 = 0xBA,
SlotTypePciExpressGen4X4 = 0xBB,
SlotTypePciExpressGen4X8 = 0xBC,
- SlotTypePciExpressGen4X16 = 0xBD
+ SlotTypePciExpressGen4X16 = 0xBD,
+ SlotTypePCIExpressGen5 = 0xBE,
+ SlotTypePCIExpressGen5X1 = 0xBF,
+ SlotTypePCIExpressGen5X2 = 0xC0,
+ SlotTypePCIExpressGen5X4 = 0xC1,
+ SlotTypePCIExpressGen5X8 = 0xC2,
+ SlotTypePCIExpressGen5X16 = 0xC3,
+ SlotTypePCIExpressGen6andBeyond = 0xC4,
+ SlotTypeEnterpriseandDatacenter1UE1FormFactorSlot = 0xC5,
+ SlotTypeEnterpriseandDatacenter3E3FormFactorSlot = 0xC6
+
} MISC_SLOT_TYPE;

///
@@ -1358,6 +1373,39 @@ typedef enum {
SlotDataBusWidth32X = 0x0E ///< Or X32
} MISC_SLOT_DATA_BUS_WIDTH;

+///
+/// System Slots - Slot Physical Width.
+///
+typedef enum {
+ SlotPhysicalWidthOther = 0x01,
+ SlotPhysicalWidthUnknown = 0x02,
+ SlotPhysicalWidth8Bit = 0x03,
+ SlotPhysicalWidth16Bit = 0x04,
+ SlotPhysicalWidth32Bit = 0x05,
+ SlotPhysicalWidth64Bit = 0x06,
+ SlotPhysicalWidth128Bit = 0x07,
+ SlotPhysicalWidth1X = 0x08, ///< Or X1
+ SlotPhysicalWidth2X = 0x09, ///< Or X2
+ SlotPhysicalWidth4X = 0x0A, ///< Or X4
+ SlotPhysicalWidth8X = 0x0B, ///< Or X8
+ SlotPhysicalWidth12X = 0x0C, ///< Or X12
+ SlotPhysicalWidth16X = 0x0D, ///< Or X16
+ SlotPhysicalWidth32X = 0x0E ///< Or X32
+} MISC_SLOT_PHYSICAL_WIDTH;
+
+///
+/// System Slots - Slot Information.
+///
+typedef enum{
+ others = 0x00,
+ Gen1 = 0x01,
+ Gen2 = 0x01,
+ Gen3 = 0x03,
+ Gen4 = 0x04,
+ Gen5 = 0x05,
+ Gen6 = 0x06
+}MISC_SLOT_INFORMATION;
+
///
/// System Slots - Current Usage.
///
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c
index b144600a25..0fa40dbe0c 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c
@@ -637,6 +637,13 @@ SmbiosPrintStructure (
}
}
}
+ if (AE_SMBIOS_VERSION (0x3, 0x2)) {
+ if (Struct->Hdr->Length > 0x12) {
+ DisplaySystemSlotHeight(Struct->Type9->SlotHeight, Option);
+ DisplaySystemSlotPhysicalWidth(Struct->Type9->SlotPhysicalWidth, Option);
+ DisplaySystemSlotInformation(Struct->Type9->SlotInformation, Option);
+ }
+ }

break;
}
@@ -2898,10 +2905,6 @@ DisplaySystemSlotId (
IN UINT8 Option
)
{
- //
- // Display slot type first
- //
- DisplaySystemSlotType (SlotType, Option);

ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_SLOT_ID), gShellDebug1HiiHandle);
//
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c
index c4a6acb167..96e0e4036a 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c
@@ -1447,6 +1447,27 @@ TABLE_ITEM SystemSlotTypeTable[] = {
0x23,
L"PCI Express Mini 76-pin (CEM spec. 2.0) Corresponds to Display-Mini card"
},
+ {
+ 0x24,
+ L"PCI Express Gen 4 SFF-8639 (U.2)"
+ },
+ {
+ 0x25,
+ L"PCI Express Gen 5 SFF-8639 (U.2)"
+ },
+ {
+ 0x26,
+ L"OCP NIC 3.0 Small Form Factor (SFF)"
+ },
+ {
+ 0x27,
+ L"OCP NIC 3.0 Large Form Factor (LFF)"
+ },
+ {
+ 0x28,
+ L"OCP NIC Prior to 3.0"
+ },
+
{
SlotTypeCXLFlexbus10,
L"CXL Flexbus 1.0"
@@ -1566,6 +1587,42 @@ TABLE_ITEM SystemSlotTypeTable[] = {
{
SlotTypePciExpressGen4X16,
L"PCI Express Gen 4 X16"
+ },
+ {
+ SlotTypePCIExpressGen5,
+ L"PCI Express Gen 5"
+ },
+ {
+ SlotTypePCIExpressGen5X1,
+ L"PCI Express Gen 5 x1"
+ },
+ {
+ SlotTypePCIExpressGen5X2,
+ L"PCI Express Gen 5 x2"
+ },
+ {
+ SlotTypePCIExpressGen5X4,
+ L"PCI Express Gen 5 x4"
+ },
+ {
+ SlotTypePCIExpressGen5X8,
+ L"PCI Express Gen 5 x8"
+ },
+ {
+ SlotTypePCIExpressGen5X16,
+ L"PCI Express Gen 5 x16"
+ },
+ {
+ SlotTypePCIExpressGen6andBeyond,
+ L"PCI Express Gen 6 and Beyond"
+ },
+ {
+ SlotTypeEnterpriseandDatacenter1UE1FormFactorSlot,
+ L"Enterprise and Datacenter 1U E1 Form Factor Slot"
+ },
+ {
+ SlotTypeEnterpriseandDatacenter3E3FormFactorSlot,
+ L"Enterprise and Datacenter 3'E3 Form Factor Slot"
}
};

@@ -1628,6 +1685,96 @@ TABLE_ITEM SystemSlotDataBusWidthTable[] = {
}
};

+TABLE_ITEM SystemSlotPhysicalWidthTable[] = {
+ {
+ 0x01,
+ L" Other"
+ },
+ {
+ 0x02,
+ L" Unknown"
+ },
+ {
+ 0x03,
+ L" 8 bit"
+ },
+ {
+ 0x04,
+ L" 16 bit"
+ },
+ {
+ 0x05,
+ L" 32 bit"
+ },
+ {
+ 0x06,
+ L" 64 bit"
+ },
+ {
+ 0x07,
+ L" 128 bit"
+ },
+ {
+ 0x08,
+ L" 1x or x1"
+ },
+ {
+ 0x09,
+ L" 2x or x2"
+ },
+ {
+ 0x0A,
+ L" 4x or x4"
+ },
+ {
+ 0x0B,
+ L" 8x or x8"
+ },
+ {
+ 0x0C,
+ L" 12x or x12"
+ },
+ {
+ 0x0D,
+ L" 16x or x16"
+ },
+ {
+ 0x0E,
+ L" 32x or x32"
+ }
+};
+
+TABLE_ITEM SystemSlotInformationTable[] = {
+ {
+ 0x00,
+ L" Others"
+ },
+ {
+ 0x01,
+ L" Gen 1"
+ },
+ {
+ 0x02,
+ L" Gen 2"
+ },
+ {
+ 0x03,
+ L" Gen 3"
+ },
+ {
+ 0x04,
+ L" Gen 4"
+ },
+ {
+ 0x05,
+ L" Gen 5"
+ },
+ {
+ 0x06,
+ L" Gen 6"
+ }
+};
+
TABLE_ITEM SystemSlotCurrentUsageTable[] = {
{
0x01,
@@ -1670,6 +1817,30 @@ TABLE_ITEM SystemSlotLengthTable[] = {
},
};

+TABLE_ITEM SystemSlotHeightTable[] = {
+ {
+ 0x00,
+ L" Not applicable"
+ },
+ {
+ 0x01,
+ L" Other"
+ },
+ {
+ 0x02,
+ L" Unkown"
+ },
+ {
+ 0x03,
+ L" Full height"
+ },
+ {
+ 0x04,
+ L" Low-Profile"
+ },
+
+};
+
TABLE_ITEM SlotCharacteristics1Table[] = {
{
0,
@@ -1722,6 +1893,22 @@ TABLE_ITEM SlotCharacteristics2Table[] = {
{
3,
L" PCIe slot supports bifurcation"
+ },
+ {
+ 4,
+ L" Slot supports async/surprise removal"
+ },
+ {
+ 5,
+ L" Flexbus slot, CXL 1.0 capable"
+ },
+ {
+ 6,
+ L" Flexbus slot, CXL 2.0 capable"
+ },
+ {
+ 7,
+ L" Reserved"
}
};

@@ -4208,6 +4395,57 @@ DisplaySlotCharacteristics2 (
PRINT_BITS_INFO (SlotCharacteristics2Table, Chara2);
}

+/**
+ Display System Slots (Type 9) Information.
+
+ @param[in] Width The key of the structure.
+ @param[in] Option The optional information.
+**/
+VOID
+DisplaySystemSlotInformation (
+ IN UINT8 Width,
+ IN UINT8 Option
+ )
+{
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SMBIOSVIEW_QUERYTABLE_SYSTEM_SLOT_INFORMATION), gShellDebug1HiiHandle);
+ PRINT_INFO_OPTION (Width, Option);
+ PRINT_TABLE_ITEM (SystemSlotInformationTable, Width);
+}
+
+/**
+ Display System Slots (Type 9) Physical Width.
+
+ @param[in] Width The key of the structure.
+ @param[in] Option The optional information.
+**/
+VOID
+DisplaySystemSlotPhysicalWidth (
+ IN UINT8 Width,
+ IN UINT8 Option
+ )
+{
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SMBIOSVIEW_QUERYTABLE_SYSTEM_SLOT_PHYSICAL_WIDTH), gShellDebug1HiiHandle);
+ PRINT_INFO_OPTION (Width, Option);
+ PRINT_TABLE_ITEM (SystemSlotPhysicalWidthTable, Width);
+}
+
+/**
+ Display System Slots (Type 9) slot height.
+
+ @param[in] Length The key of the structure.
+ @param[in] Option The optional information.
+**/
+VOID
+DisplaySystemSlotHeight (
+ IN UINT8 Length,
+ IN UINT8 Option
+ )
+{
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SMBIOSVIEW_QUERYTABLE_SYSTEM_SLOT_HEIGHT), gShellDebug1HiiHandle);
+ PRINT_INFO_OPTION (Length, Option);
+ PRINT_TABLE_ITEM (SystemSlotHeightTable, Length);
+}
+
/**
Display On Board Devices Information (Type 10) types.

diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.h b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.h
index 5111d35f63..5f062762b3 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.h
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.h
@@ -415,6 +415,42 @@ DisplaySlotCharacteristics2 (
IN UINT8 Option
);

+/**
+ Display System Slots (Type 9) Information.
+
+ @param[in] Width The key of the structure.
+ @param[in] Option The optional information.
+**/
+VOID
+DisplaySystemSlotInformation (
+ IN UINT8 Width,
+ IN UINT8 Option
+ );
+
+/**
+ Display System Slots (Type 9) Physical Width.
+
+ @param[in] Width The key of the structure.
+ @param[in] Option The optional information.
+**/
+VOID
+DisplaySystemSlotPhysicalWidth (
+ IN UINT8 Width,
+ IN UINT8 Option
+ );
+
+/**
+ Display System Slots (Type 9) slot height.
+
+ @param[in] Length The key of the structure.
+ @param[in] Option The optional information.
+**/
+VOID
+DisplaySystemSlotHeight (
+ IN UINT8 Length,
+ IN UINT8 Option
+ );
+
/**
Display On Board Devices Information (Type 10) types.

diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosViewStrings.uni b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosViewStrings.uni
index 9433e8a25f..a8728d6abc 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosViewStrings.uni
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosViewStrings.uni
@@ -294,7 +294,7 @@
#string STR_SMBIOSVIEW_PRINTINFO_MEM_SIZE #language en-US " Memory Size: %d MB\r\n"
#string STR_SMBIOSVIEW_PRINTINFO_MEM_MODULE_DOUBLE_BANK #language en-US "The memory module has a Double-bank connection\r\n"
#string STR_SMBIOSVIEW_PRINTINFO_MEM_MODULE_SINGLE_BANK #language en-US "The memory module has a Single-bank connection\r\n"
-#string STR_SMBIOSVIEW_PRINTINFO_SLOT_ID #language en-US " Slot Id:"
+#string STR_SMBIOSVIEW_PRINTINFO_SLOT_ID #language en-US "Slot Id:"
#string STR_SMBIOSVIEW_PRINTINFO_LOGICAL_MICRO_CHAN #language en-US " the logical Micro Channel slot number is:"
#string STR_SMBIOSVIEW_PRINTINFO_ONE_VAR_D #language en-US " %d\r\n"
#string STR_SMBIOSVIEW_PRINTINFO_ERROR_NOT_1_15 #language en-US " error, not 1-15.\r\n"
@@ -412,6 +412,9 @@
#string STR_SMBIOSVIEW_QUERYTABLE_SYSTEM_SLOT_LENGTH #language en-US "System Slot Length: "
#string STR_SMBIOSVIEW_QUERYTABLE_SLOT_CHARACTERISTICS #language en-US "Slot characteristics 1: "
#string STR_SMBIOSVIEW_QUERYTABLE_SLOT_CHARACTERISTICS_2 #language en-US "Slot characteristics 2: "
+#string STR_SMBIOSVIEW_QUERYTABLE_SYSTEM_SLOT_INFORMATION #language en-US "System Slot Information: "
+#string STR_SMBIOSVIEW_QUERYTABLE_SYSTEM_SLOT_HEIGHT #language en-US "System Slot Height: "
+#string STR_SMBIOSVIEW_QUERYTABLE_SYSTEM_SLOT_PHYSICAL_WIDTH #language en-US "System Slot Physical Width: "
#string STR_SMBIOSVIEW_QUERYTABLE_ONBOARD_DEVICE_TYPE #language en-US "Onboard Device Type: "
#string STR_SMBIOSVIEW_QUERYTABLE_SYSTEM_EVENT_LOG_TYPE #language en-US "System Event Log Type: "
#string STR_SMBIOSVIEW_QUERYTABLE_EVENT_LOG_VAR_DATA_FORMAT #language en-US "Event Log Variable Data Format Types: "
--
2.32.0.windows.1


Re: [PATCH v2] OvmfPkg/BhyveBhfPkg: add support for QemuFwCfg

Corvin Köhne <c.koehne@...>
 

Hi Rebecca and Peter,

thank you very much for your feedback.


Best regards
Corvin

Beckhoff Automation GmbH & Co. KG | Managing Director: Dipl. Phys. Hans Beckhoff
Registered office: Verl, Germany | Register court: Guetersloh HRA 7075


[PATCH v3] OvmfPkg/BhyveBhfPkg: add support for QemuFwCfg

Corvin Köhne <c.koehne@...>
 

From: Corvin Köhne <CorvinK@...>

QemuFwCfg is much more powerful than BhyveFwCtl. Sadly, BhyveFwCtl
decided to use the same IO ports as QemuFwCfg. It's not possible to use
both interfaces simultaneously. So, prefer QemuFwCfg over BhyveFwCtl.

Signed-off-by: Corvin Köhne <c.koehne@...>
Acked-by: Gerd Hoffmann <kraxel@...>
Acked-by: Rebecca Cran <rebecca@...>
Acked-by: Peter Grehan <grehan@...>
CC: Ard Biesheuvel <ardb+tianocore@...>
CC: Jiewen Yao <jiewen.yao@...>
CC: Jordan Justen <jordan.l.justen@...>
CC: devel@edk2.groups.io
CC: FreeBSD Virtualization <freebsd-virtualization@...>
---
OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf | 1 +
OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c | 41 ++++++++++++++++++++---
OvmfPkg/Bhyve/BhyveX64.dsc | 4 +--
3 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf b/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf
index 595fd055f9..94c65f32dc 100644
--- a/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf
+++ b/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf
@@ -43,6 +43,7 @@
MemoryAllocationLib
OrderedCollectionLib
PcdLib
+ QemuFwCfgLib
UefiBootServicesTableLib
UefiDriverEntryPoint
UefiLib
diff --git a/OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c b/OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c
index 8e80aa33e1..e216a21bfa 100644
--- a/OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c
+++ b/OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c
@@ -11,6 +11,41 @@
#include <Library/BaseMemoryLib.h>
#include <Library/BhyveFwCtlLib.h>
#include <Library/MemoryAllocationLib.h>
+#include <Library/QemuFwCfgLib.h> // QemuFwCfgFindFile()
+
+STATIC
+EFI_STATUS
+EFIAPI
+BhyveGetCpuCount (
+ OUT UINT32 *CpuCount
+ )
+{
+ FIRMWARE_CONFIG_ITEM Item;
+ UINTN Size;
+
+ if (QemuFwCfgIsAvailable ()) {
+ if (EFI_ERROR (QemuFwCfgFindFile ("opt/bhyve/hw.ncpu", &Item, &Size))) {
+ return EFI_NOT_FOUND;
+ } else if (Size != sizeof (*CpuCount)) {
+ return EFI_BAD_BUFFER_SIZE;
+ }
+
+ QemuFwCfgSelectItem (Item);
+ QemuFwCfgReadBytes (Size, CpuCount);
+
+ return EFI_SUCCESS;
+ }
+
+ //
+ // QemuFwCfg not available, try BhyveFwCtl.
+ //
+ Size = sizeof (*CpuCount);
+ if (BhyveFwCtlGet ("hw.ncpu", CpuCount, &Size) == RETURN_SUCCESS) {
+ return EFI_SUCCESS;
+ }
+
+ return EFI_UNSUPPORTED;
+}

STATIC
EFI_STATUS
@@ -23,7 +58,6 @@ BhyveInstallAcpiMadtTable (
)
{
UINT32 CpuCount;
- UINTN cSize;
UINTN NewBufferSize;
EFI_ACPI_1_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER *Madt;
EFI_ACPI_1_0_PROCESSOR_LOCAL_APIC_STRUCTURE *LocalApic;
@@ -36,9 +70,8 @@ BhyveInstallAcpiMadtTable (
ASSERT (AcpiTableBufferSize >= sizeof (EFI_ACPI_DESCRIPTION_HEADER));

// Query the host for the number of vCPUs
- CpuCount = 0;
- cSize = sizeof (CpuCount);
- if (BhyveFwCtlGet ("hw.ncpu", &CpuCount, &cSize) == RETURN_SUCCESS) {
+ Status = BhyveGetCpuCount (&CpuCount);
+ if (!EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "Retrieved CpuCount %d\n", CpuCount));
ASSERT (CpuCount >= 1);
} else {
diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc
index 5fa08bebd7..14070fd6dd 100644
--- a/OvmfPkg/Bhyve/BhyveX64.dsc
+++ b/OvmfPkg/Bhyve/BhyveX64.dsc
@@ -163,8 +163,7 @@
SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf
UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf
SerializeVariablesLib|OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.inf
- QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibNull.inf
- QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf
+ QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgDxeLib.inf
BhyveFwCtlLib|OvmfPkg/Library/BhyveFwCtlLib/BhyveFwCtlLib.inf
VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf
MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf
@@ -355,6 +354,7 @@
!endif
PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
MpInitLib|UefiCpuPkg/Library/MpInitLibUp/MpInitLibUp.inf
+ QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf

[LibraryClasses.common.UEFI_APPLICATION]
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
--
2.11.0

Beckhoff Automation GmbH & Co. KG | Managing Director: Dipl. Phys. Hans Beckhoff
Registered office: Verl, Germany | Register court: Guetersloh HRA 7075


[PATCH] ShellPkg: Update smbiosview type 9 with SMBIOS 3.5 fields

Bo Chang Ke
 

Signed-off-by: Bo Chang Ke <bo-changx.ke@...>
Cc: Dandan Bi <dandan.bi@...>
Cc: Star Zeng <star.zeng@...>
---
MdePkg/Include/IndustryStandard/SmBios.h | 50 +++-
.../SmbiosView/PrintInfo.c | 11 +-
.../SmbiosView/QueryTable.c | 238 ++++++++++++++++++
.../SmbiosView/QueryTable.h | 36 +++
.../SmbiosView/SmbiosViewStrings.uni | 5 +-
5 files changed, 334 insertions(+), 6 deletions(-)

diff --git a/MdePkg/Include/IndustryStandard/SmBios.h b/MdePkg/Include/IndustryStandard/SmBios.h
index 2b1567b052..cb39470c92 100644
--- a/MdePkg/Include/IndustryStandard/SmBios.h
+++ b/MdePkg/Include/IndustryStandard/SmBios.h
@@ -1306,6 +1306,11 @@ typedef enum {
SlotTypePciExpressMini52pinWithBSKO = 0x21, ///< PCI Express Mini 52-pin (CEM spec. 2.0) with bottom-side keep-outs.
SlotTypePciExpressMini52pinWithoutBSKO = 0x22, ///< PCI Express Mini 52-pin (CEM spec. 2.0) without bottom-side keep-outs.
SlotTypePciExpressMini76pin = 0x23, ///< PCI Express Mini 76-pin (CEM spec. 2.0) Corresponds to Display-Mini card.
+ SlotTypePCIExpressGen4SFF_8639 = 0x24, ///< U.2
+ SlotTypePCIExpressGen5SFF_8639 = 0x25, ///< U.2
+ SlotTypeOCPNIC30SmallFormFactor = 0x26, ///< SFF
+ SlotTypeOCPNIC30LargeFormFactor = 0x27, ///< LFF
+ SlotTypeOCPNICPriorto30 = 0x28,
SlotTypeCXLFlexbus10 = 0x30,
SlotTypePC98C20 = 0xA0,
SlotTypePC98C24 = 0xA1,
@@ -1335,7 +1340,17 @@ typedef enum {
SlotTypePciExpressGen4X2 = 0xBA,
SlotTypePciExpressGen4X4 = 0xBB,
SlotTypePciExpressGen4X8 = 0xBC,
- SlotTypePciExpressGen4X16 = 0xBD
+ SlotTypePciExpressGen4X16 = 0xBD,
+ SlotTypePCIExpressGen5 = 0xBE,
+ SlotTypePCIExpressGen5X1 = 0xBF,
+ SlotTypePCIExpressGen5X2 = 0xC0,
+ SlotTypePCIExpressGen5X4 = 0xC1,
+ SlotTypePCIExpressGen5X8 = 0xC2,
+ SlotTypePCIExpressGen5X16 = 0xC3,
+ SlotTypePCIExpressGen6andBeyond = 0xC4,
+ SlotTypeEnterpriseandDatacenter1UE1FormFactorSlot = 0xC5,
+ SlotTypeEnterpriseandDatacenter3E3FormFactorSlot = 0xC6
+
} MISC_SLOT_TYPE;

///
@@ -1358,6 +1373,39 @@ typedef enum {
SlotDataBusWidth32X = 0x0E ///< Or X32
} MISC_SLOT_DATA_BUS_WIDTH;

+///
+/// System Slots - Slot Physical Width.
+///
+typedef enum {
+ SlotPhysicalWidthOther = 0x01,
+ SlotPhysicalWidthUnknown = 0x02,
+ SlotPhysicalWidth8Bit = 0x03,
+ SlotPhysicalWidth16Bit = 0x04,
+ SlotPhysicalWidth32Bit = 0x05,
+ SlotPhysicalWidth64Bit = 0x06,
+ SlotPhysicalWidth128Bit = 0x07,
+ SlotPhysicalWidth1X = 0x08, ///< Or X1
+ SlotPhysicalWidth2X = 0x09, ///< Or X2
+ SlotPhysicalWidth4X = 0x0A, ///< Or X4
+ SlotPhysicalWidth8X = 0x0B, ///< Or X8
+ SlotPhysicalWidth12X = 0x0C, ///< Or X12
+ SlotPhysicalWidth16X = 0x0D, ///< Or X16
+ SlotPhysicalWidth32X = 0x0E ///< Or X32
+} MISC_SLOT_PHYSICAL_WIDTH;
+
+///
+/// System Slots - Slot Information.
+///
+typedef enum{
+ others = 0x00,
+ Gen1 = 0x01,
+ Gen2 = 0x01,
+ Gen3 = 0x03,
+ Gen4 = 0x04,
+ Gen5 = 0x05,
+ Gen6 = 0x06
+}MISC_SLOT_INFORMATION;
+
///
/// System Slots - Current Usage.
///
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c
index b144600a25..0fa40dbe0c 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c
@@ -637,6 +637,13 @@ SmbiosPrintStructure (
}
}
}
+ if (AE_SMBIOS_VERSION (0x3, 0x2)) {
+ if (Struct->Hdr->Length > 0x12) {
+ DisplaySystemSlotHeight(Struct->Type9->SlotHeight, Option);
+ DisplaySystemSlotPhysicalWidth(Struct->Type9->SlotPhysicalWidth, Option);
+ DisplaySystemSlotInformation(Struct->Type9->SlotInformation, Option);
+ }
+ }

break;
}
@@ -2898,10 +2905,6 @@ DisplaySystemSlotId (
IN UINT8 Option
)
{
- //
- // Display slot type first
- //
- DisplaySystemSlotType (SlotType, Option);

ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_SLOT_ID), gShellDebug1HiiHandle);
//
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c
index c4a6acb167..96e0e4036a 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c
@@ -1447,6 +1447,27 @@ TABLE_ITEM SystemSlotTypeTable[] = {
0x23,
L"PCI Express Mini 76-pin (CEM spec. 2.0) Corresponds to Display-Mini card"
},
+ {
+ 0x24,
+ L"PCI Express Gen 4 SFF-8639 (U.2)"
+ },
+ {
+ 0x25,
+ L"PCI Express Gen 5 SFF-8639 (U.2)"
+ },
+ {
+ 0x26,
+ L"OCP NIC 3.0 Small Form Factor (SFF)"
+ },
+ {
+ 0x27,
+ L"OCP NIC 3.0 Large Form Factor (LFF)"
+ },
+ {
+ 0x28,
+ L"OCP NIC Prior to 3.0"
+ },
+
{
SlotTypeCXLFlexbus10,
L"CXL Flexbus 1.0"
@@ -1566,6 +1587,42 @@ TABLE_ITEM SystemSlotTypeTable[] = {
{
SlotTypePciExpressGen4X16,
L"PCI Express Gen 4 X16"
+ },
+ {
+ SlotTypePCIExpressGen5,
+ L"PCI Express Gen 5"
+ },
+ {
+ SlotTypePCIExpressGen5X1,
+ L"PCI Express Gen 5 x1"
+ },
+ {
+ SlotTypePCIExpressGen5X2,
+ L"PCI Express Gen 5 x2"
+ },
+ {
+ SlotTypePCIExpressGen5X4,
+ L"PCI Express Gen 5 x4"
+ },
+ {
+ SlotTypePCIExpressGen5X8,
+ L"PCI Express Gen 5 x8"
+ },
+ {
+ SlotTypePCIExpressGen5X16,
+ L"PCI Express Gen 5 x16"
+ },
+ {
+ SlotTypePCIExpressGen6andBeyond,
+ L"PCI Express Gen 6 and Beyond"
+ },
+ {
+ SlotTypeEnterpriseandDatacenter1UE1FormFactorSlot,
+ L"Enterprise and Datacenter 1U E1 Form Factor Slot"
+ },
+ {
+ SlotTypeEnterpriseandDatacenter3E3FormFactorSlot,
+ L"Enterprise and Datacenter 3'E3 Form Factor Slot"
}
};

@@ -1628,6 +1685,96 @@ TABLE_ITEM SystemSlotDataBusWidthTable[] = {
}
};

+TABLE_ITEM SystemSlotPhysicalWidthTable[] = {
+ {
+ 0x01,
+ L" Other"
+ },
+ {
+ 0x02,
+ L" Unknown"
+ },
+ {
+ 0x03,
+ L" 8 bit"
+ },
+ {
+ 0x04,
+ L" 16 bit"
+ },
+ {
+ 0x05,
+ L" 32 bit"
+ },
+ {
+ 0x06,
+ L" 64 bit"
+ },
+ {
+ 0x07,
+ L" 128 bit"
+ },
+ {
+ 0x08,
+ L" 1x or x1"
+ },
+ {
+ 0x09,
+ L" 2x or x2"
+ },
+ {
+ 0x0A,
+ L" 4x or x4"
+ },
+ {
+ 0x0B,
+ L" 8x or x8"
+ },
+ {
+ 0x0C,
+ L" 12x or x12"
+ },
+ {
+ 0x0D,
+ L" 16x or x16"
+ },
+ {
+ 0x0E,
+ L" 32x or x32"
+ }
+};
+
+TABLE_ITEM SystemSlotInformationTable[] = {
+ {
+ 0x00,
+ L" Others"
+ },
+ {
+ 0x01,
+ L" Gen 1"
+ },
+ {
+ 0x02,
+ L" Gen 2"
+ },
+ {
+ 0x03,
+ L" Gen 3"
+ },
+ {
+ 0x04,
+ L" Gen 4"
+ },
+ {
+ 0x05,
+ L" Gen 5"
+ },
+ {
+ 0x06,
+ L" Gen 6"
+ }
+};
+
TABLE_ITEM SystemSlotCurrentUsageTable[] = {
{
0x01,
@@ -1670,6 +1817,30 @@ TABLE_ITEM SystemSlotLengthTable[] = {
},
};

+TABLE_ITEM SystemSlotHeightTable[] = {
+ {
+ 0x00,
+ L" Not applicable"
+ },
+ {
+ 0x01,
+ L" Other"
+ },
+ {
+ 0x02,
+ L" Unkown"
+ },
+ {
+ 0x03,
+ L" Full height"
+ },
+ {
+ 0x04,
+ L" Low-Profile"
+ },
+
+};
+
TABLE_ITEM SlotCharacteristics1Table[] = {
{
0,
@@ -1722,6 +1893,22 @@ TABLE_ITEM SlotCharacteristics2Table[] = {
{
3,
L" PCIe slot supports bifurcation"
+ },
+ {
+ 4,
+ L" Slot supports async/surprise removal"
+ },
+ {
+ 5,
+ L" Flexbus slot, CXL 1.0 capable"
+ },
+ {
+ 6,
+ L" Flexbus slot, CXL 2.0 capable"
+ },
+ {
+ 7,
+ L" Reserved"
}
};

@@ -4208,6 +4395,57 @@ DisplaySlotCharacteristics2 (
PRINT_BITS_INFO (SlotCharacteristics2Table, Chara2);
}

+/**
+ Display System Slots (Type 9) Information.
+
+ @param[in] Width The key of the structure.
+ @param[in] Option The optional information.
+**/
+VOID
+DisplaySystemSlotInformation (
+ IN UINT8 Width,
+ IN UINT8 Option
+ )
+{
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SMBIOSVIEW_QUERYTABLE_SYSTEM_SLOT_INFORMATION), gShellDebug1HiiHandle);
+ PRINT_INFO_OPTION (Width, Option);
+ PRINT_TABLE_ITEM (SystemSlotInformationTable, Width);
+}
+
+/**
+ Display System Slots (Type 9) Physical Width.
+
+ @param[in] Width The key of the structure.
+ @param[in] Option The optional information.
+**/
+VOID
+DisplaySystemSlotPhysicalWidth (
+ IN UINT8 Width,
+ IN UINT8 Option
+ )
+{
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SMBIOSVIEW_QUERYTABLE_SYSTEM_SLOT_PHYSICAL_WIDTH), gShellDebug1HiiHandle);
+ PRINT_INFO_OPTION (Width, Option);
+ PRINT_TABLE_ITEM (SystemSlotPhysicalWidthTable, Width);
+}
+
+/**
+ Display System Slots (Type 9) slot height.
+
+ @param[in] Length The key of the structure.
+ @param[in] Option The optional information.
+**/
+VOID
+DisplaySystemSlotHeight (
+ IN UINT8 Length,
+ IN UINT8 Option
+ )
+{
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SMBIOSVIEW_QUERYTABLE_SYSTEM_SLOT_HEIGHT), gShellDebug1HiiHandle);
+ PRINT_INFO_OPTION (Length, Option);
+ PRINT_TABLE_ITEM (SystemSlotHeightTable, Length);
+}
+
/**
Display On Board Devices Information (Type 10) types.

diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.h b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.h
index 5111d35f63..5f062762b3 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.h
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.h
@@ -415,6 +415,42 @@ DisplaySlotCharacteristics2 (
IN UINT8 Option
);

+/**
+ Display System Slots (Type 9) Information.
+
+ @param[in] Width The key of the structure.
+ @param[in] Option The optional information.
+**/
+VOID
+DisplaySystemSlotInformation (
+ IN UINT8 Width,
+ IN UINT8 Option
+ );
+
+/**
+ Display System Slots (Type 9) Physical Width.
+
+ @param[in] Width The key of the structure.
+ @param[in] Option The optional information.
+**/
+VOID
+DisplaySystemSlotPhysicalWidth (
+ IN UINT8 Width,
+ IN UINT8 Option
+ );
+
+/**
+ Display System Slots (Type 9) slot height.
+
+ @param[in] Length The key of the structure.
+ @param[in] Option The optional information.
+**/
+VOID
+DisplaySystemSlotHeight (
+ IN UINT8 Length,
+ IN UINT8 Option
+ );
+
/**
Display On Board Devices Information (Type 10) types.

diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosViewStrings.uni b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosViewStrings.uni
index 9433e8a25f..a8728d6abc 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosViewStrings.uni
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosViewStrings.uni
@@ -294,7 +294,7 @@
#string STR_SMBIOSVIEW_PRINTINFO_MEM_SIZE #language en-US " Memory Size: %d MB\r\n"
#string STR_SMBIOSVIEW_PRINTINFO_MEM_MODULE_DOUBLE_BANK #language en-US "The memory module has a Double-bank connection\r\n"
#string STR_SMBIOSVIEW_PRINTINFO_MEM_MODULE_SINGLE_BANK #language en-US "The memory module has a Single-bank connection\r\n"
-#string STR_SMBIOSVIEW_PRINTINFO_SLOT_ID #language en-US " Slot Id:"
+#string STR_SMBIOSVIEW_PRINTINFO_SLOT_ID #language en-US "Slot Id:"
#string STR_SMBIOSVIEW_PRINTINFO_LOGICAL_MICRO_CHAN #language en-US " the logical Micro Channel slot number is:"
#string STR_SMBIOSVIEW_PRINTINFO_ONE_VAR_D #language en-US " %d\r\n"
#string STR_SMBIOSVIEW_PRINTINFO_ERROR_NOT_1_15 #language en-US " error, not 1-15.\r\n"
@@ -412,6 +412,9 @@
#string STR_SMBIOSVIEW_QUERYTABLE_SYSTEM_SLOT_LENGTH #language en-US "System Slot Length: "
#string STR_SMBIOSVIEW_QUERYTABLE_SLOT_CHARACTERISTICS #language en-US "Slot characteristics 1: "
#string STR_SMBIOSVIEW_QUERYTABLE_SLOT_CHARACTERISTICS_2 #language en-US "Slot characteristics 2: "
+#string STR_SMBIOSVIEW_QUERYTABLE_SYSTEM_SLOT_INFORMATION #language en-US "System Slot Information: "
+#string STR_SMBIOSVIEW_QUERYTABLE_SYSTEM_SLOT_HEIGHT #language en-US "System Slot Height: "
+#string STR_SMBIOSVIEW_QUERYTABLE_SYSTEM_SLOT_PHYSICAL_WIDTH #language en-US "System Slot Physical Width: "
#string STR_SMBIOSVIEW_QUERYTABLE_ONBOARD_DEVICE_TYPE #language en-US "Onboard Device Type: "
#string STR_SMBIOSVIEW_QUERYTABLE_SYSTEM_EVENT_LOG_TYPE #language en-US "System Event Log Type: "
#string STR_SMBIOSVIEW_QUERYTABLE_EVENT_LOG_VAR_DATA_FORMAT #language en-US "Event Log Variable Data Format Types: "
--
2.32.0.windows.1


TianoCore Community Meeting 20220407 APAC/NAMO

Demeter, Miki
 

**Highlights:**

- GSOC Need Additional Mentors more is better

- Bugzilla Status update – Devs still need to update status (ongoing issue)

- UEFI Summit switched to Virtual only

- Question to the community Concerns about additional dependencies? See Comments in Stewards Download

 

# Meeting Minutes:

 

1) **Event Updates (_5 minutes]**

- **UEFI Summit switched to Virtual only**

 

2) [**Stable Tag Updates (_5 minutes_)**

- Soft Freeze - 2022-

- Hard freeze - 2022-

- 2022- Release 

 -** Stable Tag 20220225 released **

 

3) **Stewards Download (_20 minutes_)**

-**Coverity Status**

-- No Updates

- Raised topic number of dependencies on external services (git sub-modules, tools VS, iasm, nasm, Python, pip module)

-- CI tools (spell check has a dependency on node package manager) 

-- Stewards responsible to validate whether new dependencies are appropriate.

-- Developer helper tools (don’t affect CI builds)

-- Question to the community Concerns about additional dependencies

- **Comments** – We can’t afford to maintain our own set of tools. Dependencies allow us to leverage tools we don’t have time to build

 

 

-** Bugzilla Status**

- Still Need developers to update issues - Bug Scrubs working through issues

 

 

4) **Opens (_30 minutes_)**

- Brian Johnson concerned about the way build system has become too complex need to simplify, possibly a docker image to help

-- git submodules are complex and not well liked

- Rebecka helping Andrew to get the GDB scripts rebased and checked in waiting on a few more reviews.

- Rajnish – A way to run CI/CD Locally - https://github.com/tianocore/edk2/tree/master/.pytool#running-ci-locally

- Sean Brogan – Our RFC process needs to be reworked to be better involved. – Look at they way Rust utilizes github.

- Nate Desimone – 2 students want to add Rust support to edk2 not enough skilled Mentors

- Kevin Davis & Sean Brogan – PE file python module leverage the existing library - https://pypi.org/project/pefile/

- Sean Brogan suggests a larger community discussion on Rust

 

**AR: Miki reach out to Felix for update on (Coverity)**

**AR: Forward info on UEFI Summit-  brian.johnson@..., Rajnish.s.chauhan@... **

 

Next meeting will be back on the on the first Thursday of the month.

 

-- 

Miki Demeter (she/her)

Security Researcher

IPAS GO

Intel Corporation

 

Portland Women in Tech Best Speaker 2019

miki.demeter@...

 


Re: 回复: [PATCH-V2] Fix Setup numeric default value incorrect issue

Chen Lin Z
 

Thanks Dandan's update, I see patch got merged : )

Thanks,
Lin

-----Original Message-----
From: Bi, Dandan <dandan.bi@...>
Sent: Friday, April 8, 2022 10:12 AM
To: devel@edk2.groups.io; Gao, Liming <gaoliming@...>; Chen, Lin Z <lin.z.chen@...>; Wang, Jian J <jian.j.wang@...>; Dong, Eric <eric.dong@...>
Cc: Li, Zhuangzhi <zhuangzhi.li@...>; Zhang, Di <di.zhang@...>
Subject: RE: [edk2-devel] 回复: [PATCH-V2] Fix Setup numeric default value incorrect issue

The coding style issue is addressed and pushed via https://github.com/tianocore/edk2/pull/2753


Thanks,
Dandan

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
gaoliming
Sent: Friday, April 8, 2022 8:48 AM
To: devel@edk2.groups.io; Gao, Liming <gaoliming@...>;
Chen, Lin Z <lin.z.chen@...>; Wang, Jian J
<jian.j.wang@...>; Bi, Dandan <dandan.bi@...>; Dong, Eric
<eric.dong@...>
Cc: Li, Zhuangzhi <zhuangzhi.li@...>; Zhang, Di
<di.zhang@...>
Subject: 回复: [edk2-devel] 回复: [PATCH-V2] Fix Setup numeric default
value incorrect issue

Lin:
Here is PR https://github.com/tianocore/edk2/pull/2748. There is the
issue in the change. Please check it.

ERROR -
/home/vsts/work/1/s/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRou
ting.c
ERROR - --->Test Failed: Uncrustify Coding Standard Test NO-TARGET
returned
1

Thanks
Liming
-----邮件原件-----
发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 gaoliming
发送时间: 2022年4月7日 13:05
收件人: 'Chen Lin Z' <lin.z.chen@...>; jian.j.wang@...;
dandan.bi@...; eric.dong@...; devel@edk2.groups.io
抄送: zhuangzhi.li@...; di.zhang@...
主题: [edk2-devel] 回复: [PATCH-V2] Fix Setup numeric default value
incorrect issue

Reviewed-by: Liming Gao <gaoliming@...>

-----邮件原件-----
发件人: Chen Lin Z <lin.z.chen@...>
发送时间: 2022年4月1日 14:09
收件人: jian.j.wang@...; gaoliming@...;
dandan.bi@...; eric.dong@...; devel@edk2.groups.io
抄送: zhuangzhi.li@...; di.zhang@...; Chen Lin Z
<lin.z.chen@...>
主题: [PATCH-V2] Fix Setup numeric default value incorrect issue

When default/manufacturing flag get removed from numeric varid, it
can't get default value from StructurePcd in
'UpdateDefaultSettingInFormPackage'
function since there is no EFI_IFR_DEFAULT_OP opcode in IFR file.
Add a chance to get numeric default value from StructurePcd in the
case that numeric minimum value will be used as default value.

Signed-off-by: Chen Lin Z <lin.z.chen@...>
Signed-off-by: Dandan Bi <dandan.bi@...>
---
.../Universal/HiiDatabaseDxe/ConfigRouting.c | 22
++++++++++++++++++
.../Universal/HiiDatabaseDxe/HiiDatabase.h | 23
+++++++++++++++++++
2 files changed, 45 insertions(+)

diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
index 2f792d2965..1c6af853b3 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
@@ -2171,6 +2171,7 @@ ParseIfrData (
UINTN PackageOffset;

EFI_IFR_VARSTORE *IfrVarStore;

EFI_IFR_VARSTORE_EFI *IfrEfiVarStore;

+ EFI_IFR_VARSTORE_EFI *IfrEfiVarStoreTmp;

EFI_IFR_OP_HEADER *IfrOpHdr;

EFI_IFR_ONE_OF *IfrOneOf;

EFI_IFR_REF4 *IfrRef;

@@ -2187,6 +2188,7 @@ ParseIfrData (
IFR_BLOCK_DATA *BlockData;

CHAR16 *VarStoreName;

UINTN NameSize;

+ UINTN NvDefaultStoreSize;

UINT16 VarWidth;

UINT16 VarDefaultId;

BOOLEAN FirstOneOfOption;

@@ -2212,6 +2214,7 @@ ParseIfrData (
SmallestDefaultId = 0xFFFF;

FromOtherDefaultOpcode = FALSE;

QuestionReferBitField = FALSE;

+ IfrEfiVarStoreTmp = NULL;



//

// Go through the form package to parse OpCode one by one.

@@ -2303,6 +2306,17 @@ ParseIfrData (
}



AsciiStrToUnicodeStrS ((CHAR8 *)IfrEfiVarStore->Name,
VarStoreName, NameSize);

+ if (IfrEfiVarStoreTmp != NULL) {

+ FreePool (IfrEfiVarStoreTmp);

+ }

+ IfrEfiVarStoreTmp = AllocatePool
+ (IfrEfiVarStore->Header.Length
+
AsciiStrSize ((CHAR8 *)IfrEfiVarStore->Name));

+ if (IfrEfiVarStoreTmp == NULL) {

+ Status = EFI_OUT_OF_RESOURCES;

+ goto Done;

+ }

+

+ CopyMem (IfrEfiVarStoreTmp, IfrEfiVarStore,
IfrEfiVarStore->Header.Length);

+ AsciiStrToUnicodeStrS ((CHAR8 *)IfrEfiVarStore->Name,
+ (CHAR16
*)&(IfrEfiVarStoreTmp->Name[0]), AsciiStrSize ((CHAR8
*)IfrEfiVarStore->Name) * sizeof (CHAR16));



if (IsThisVarstore (&IfrEfiVarStore->Guid, VarStoreName,
ConfigHdr)) {

//

@@ -2502,9 +2516,13 @@ ParseIfrData (
//

// Set default value base on the DefaultId list get
from IFR
data.

//

+ NvDefaultStoreSize = PcdGetSize
(PcdNvStoreDefaultValueBuffer);

for (LinkData = DefaultIdArray->Entry.ForwardLink;
LinkData !=
&DefaultIdArray->Entry; LinkData = LinkData->ForwardLink) {

DefaultDataPtr = BASE_CR (LinkData,
IFR_DEFAULT_DATA, Entry);

DefaultData.DefaultId = DefaultDataPtr->DefaultId;

+ if (NvDefaultStoreSize > sizeof
(PCD_NV_STORE_DEFAULT_BUFFER_HEADER)) {

+ FindQuestionDefaultSetting (DefaultData.DefaultId,
IfrEfiVarStoreTmp, &(IfrOneOf->Question), &DefaultData.Value,
VarWidth, QuestionReferBitField);

+ }

InsertDefaultValue (BlockData, &DefaultData);

}

}

@@ -3192,6 +3210,10 @@ Done:
}

}



+ if (IfrEfiVarStoreTmp != NULL) {

+ FreePool (IfrEfiVarStoreTmp);

+ }

+

return Status;

}



diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabase.h
b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabase.h
index c4ca6ad6ee..421c293cfc 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabase.h
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabase.h
@@ -2308,6 +2308,29 @@ HiiGetConfigRespInfo (
IN CONST EFI_HII_DATABASE_PROTOCOL *This

);



+/**

+ Find question default value from PcdNvStoreDefaultValueBuffer

+

+ @param DefaultId Default store ID

+ @param EfiVarStore Point to EFI VarStore header

+ @param IfrQuestionHdr Point to Question header

+ @param ValueBuffer Point to Buffer includes the found default
setting

+ @param Width Width of the default value

+ @param BitFieldQuestion Whether the Question is stored in Bit
field.

+

+ @retval EFI_SUCCESS Question default value is found.

+ @retval EFI_NOT_FOUND Question default value is not found.

+**/

+EFI_STATUS

+FindQuestionDefaultSetting (

+ IN UINT16 DefaultId,

+ IN EFI_IFR_VARSTORE_EFI *EfiVarStore,

+ IN EFI_IFR_QUESTION_HEADER *IfrQuestionHdr,

+ OUT VOID *ValueBuffer,

+ IN UINTN Width,

+ IN BOOLEAN BitFieldQuestion

+ );

+

//

// Global variables

//

--
2.25.1











Event: TianoCore Community Meeting - APAC/NAMO - 04/07/2022 #cal-reminder

devel@edk2.groups.io Calendar <noreply@...>
 

Reminder: TianoCore Community Meeting - APAC/NAMO

When:
04/07/2022
7:30pm to 8:30pm
(UTC-07:00) America/Los Angeles

Where:
https://teams.microsoft.com/l/meetup-join/19%3ameeting_ZWNiZWM1MzgtNWEzMy00MTgwLTgwNjAtNWQ1ZWUwZmQzNjVh%40thread.v2/0?context=%7b%22Tid%22%3a%2246c98d88-e344-4ed4-8496-4ed7712e255d%22%2c%22Oid%22%3a%22b286b53a-1218-4db3-bfc9-3d4c5aa7669e%22%7d

Organizer: Miki Demeter

View Event

Description:

Microsoft Teams meeting

Join on your computer or mobile app

Click here to join the meeting

Join with a video conferencing device

teams@...

Video Conference ID: 119 132 712 6

Alternate VTC dialing instructions

Or call in (audio only)

+1 916-245-6934,,494156131#   United States, Sacramento

Phone Conference ID: 494 156 131#

Find a local number | Reset PIN

Learn More | Meeting options


Event: TianoCore Community Meeting - APAC/NAMO - 04/07/2022 #cal-reminder

devel@edk2.groups.io Calendar <noreply@...>
 

Reminder: TianoCore Community Meeting - APAC/NAMO

When:
04/07/2022
7:30pm to 8:30pm
(UTC-07:00) America/Los Angeles

Where:
https://teams.microsoft.com/l/meetup-join/19%3ameeting_ZWNiZWM1MzgtNWEzMy00MTgwLTgwNjAtNWQ1ZWUwZmQzNjVh%40thread.v2/0?context=%7b%22Tid%22%3a%2246c98d88-e344-4ed4-8496-4ed7712e255d%22%2c%22Oid%22%3a%22b286b53a-1218-4db3-bfc9-3d4c5aa7669e%22%7d

Organizer: Miki Demeter

View Event

Description:

Microsoft Teams meeting

Join on your computer or mobile app

Click here to join the meeting

Join with a video conferencing device

teams@...

Video Conference ID: 119 132 712 6

Alternate VTC dialing instructions

Or call in (audio only)

+1 916-245-6934,,494156131#   United States, Sacramento

Phone Conference ID: 494 156 131#

Find a local number | Reset PIN

Learn More | Meeting options


Re: 回复: [PATCH-V2] Fix Setup numeric default value incorrect issue

Dandan Bi
 

The coding style issue is addressed and pushed via https://github.com/tianocore/edk2/pull/2753


Thanks,
Dandan

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
gaoliming
Sent: Friday, April 8, 2022 8:48 AM
To: devel@edk2.groups.io; Gao, Liming <gaoliming@...>; Chen,
Lin Z <lin.z.chen@...>; Wang, Jian J <jian.j.wang@...>; Bi,
Dandan <dandan.bi@...>; Dong, Eric <eric.dong@...>
Cc: Li, Zhuangzhi <zhuangzhi.li@...>; Zhang, Di <di.zhang@...>
Subject: 回复: [edk2-devel] 回复: [PATCH-V2] Fix Setup numeric default value
incorrect issue

Lin:
Here is PR https://github.com/tianocore/edk2/pull/2748. There is the issue
in the change. Please check it.

ERROR -
/home/vsts/work/1/s/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRou
ting.c
ERROR - --->Test Failed: Uncrustify Coding Standard Test NO-TARGET
returned
1

Thanks
Liming
-----邮件原件-----
发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 gaoliming
发送时间: 2022年4月7日 13:05
收件人: 'Chen Lin Z' <lin.z.chen@...>; jian.j.wang@...;
dandan.bi@...; eric.dong@...; devel@edk2.groups.io
抄送: zhuangzhi.li@...; di.zhang@...
主题: [edk2-devel] 回复: [PATCH-V2] Fix Setup numeric default value
incorrect issue

Reviewed-by: Liming Gao <gaoliming@...>

-----邮件原件-----
发件人: Chen Lin Z <lin.z.chen@...>
发送时间: 2022年4月1日 14:09
收件人: jian.j.wang@...; gaoliming@...;
dandan.bi@...; eric.dong@...; devel@edk2.groups.io
抄送: zhuangzhi.li@...; di.zhang@...; Chen Lin Z
<lin.z.chen@...>
主题: [PATCH-V2] Fix Setup numeric default value incorrect issue

When default/manufacturing flag get removed from numeric varid, it
can't get default value from StructurePcd in
'UpdateDefaultSettingInFormPackage'
function since there is no EFI_IFR_DEFAULT_OP opcode in IFR file.
Add a chance to get numeric default value from StructurePcd in the
case that numeric minimum value will be used as default value.

Signed-off-by: Chen Lin Z <lin.z.chen@...>
Signed-off-by: Dandan Bi <dandan.bi@...>
---
.../Universal/HiiDatabaseDxe/ConfigRouting.c | 22
++++++++++++++++++
.../Universal/HiiDatabaseDxe/HiiDatabase.h | 23
+++++++++++++++++++
2 files changed, 45 insertions(+)

diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
index 2f792d2965..1c6af853b3 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
@@ -2171,6 +2171,7 @@ ParseIfrData (
UINTN PackageOffset;

EFI_IFR_VARSTORE *IfrVarStore;

EFI_IFR_VARSTORE_EFI *IfrEfiVarStore;

+ EFI_IFR_VARSTORE_EFI *IfrEfiVarStoreTmp;

EFI_IFR_OP_HEADER *IfrOpHdr;

EFI_IFR_ONE_OF *IfrOneOf;

EFI_IFR_REF4 *IfrRef;

@@ -2187,6 +2188,7 @@ ParseIfrData (
IFR_BLOCK_DATA *BlockData;

CHAR16 *VarStoreName;

UINTN NameSize;

+ UINTN NvDefaultStoreSize;

UINT16 VarWidth;

UINT16 VarDefaultId;

BOOLEAN FirstOneOfOption;

@@ -2212,6 +2214,7 @@ ParseIfrData (
SmallestDefaultId = 0xFFFF;

FromOtherDefaultOpcode = FALSE;

QuestionReferBitField = FALSE;

+ IfrEfiVarStoreTmp = NULL;



//

// Go through the form package to parse OpCode one by one.

@@ -2303,6 +2306,17 @@ ParseIfrData (
}



AsciiStrToUnicodeStrS ((CHAR8 *)IfrEfiVarStore->Name,
VarStoreName, NameSize);

+ if (IfrEfiVarStoreTmp != NULL) {

+ FreePool (IfrEfiVarStoreTmp);

+ }

+ IfrEfiVarStoreTmp = AllocatePool
+ (IfrEfiVarStore->Header.Length
+
AsciiStrSize ((CHAR8 *)IfrEfiVarStore->Name));

+ if (IfrEfiVarStoreTmp == NULL) {

+ Status = EFI_OUT_OF_RESOURCES;

+ goto Done;

+ }

+

+ CopyMem (IfrEfiVarStoreTmp, IfrEfiVarStore,
IfrEfiVarStore->Header.Length);

+ AsciiStrToUnicodeStrS ((CHAR8 *)IfrEfiVarStore->Name,
+ (CHAR16
*)&(IfrEfiVarStoreTmp->Name[0]), AsciiStrSize ((CHAR8
*)IfrEfiVarStore->Name) * sizeof (CHAR16));



if (IsThisVarstore (&IfrEfiVarStore->Guid, VarStoreName,
ConfigHdr)) {

//

@@ -2502,9 +2516,13 @@ ParseIfrData (
//

// Set default value base on the DefaultId list get from
IFR
data.

//

+ NvDefaultStoreSize = PcdGetSize
(PcdNvStoreDefaultValueBuffer);

for (LinkData = DefaultIdArray->Entry.ForwardLink;
LinkData !=
&DefaultIdArray->Entry; LinkData = LinkData->ForwardLink) {

DefaultDataPtr = BASE_CR (LinkData,
IFR_DEFAULT_DATA, Entry);

DefaultData.DefaultId = DefaultDataPtr->DefaultId;

+ if (NvDefaultStoreSize > sizeof
(PCD_NV_STORE_DEFAULT_BUFFER_HEADER)) {

+ FindQuestionDefaultSetting (DefaultData.DefaultId,
IfrEfiVarStoreTmp, &(IfrOneOf->Question), &DefaultData.Value,
VarWidth, QuestionReferBitField);

+ }

InsertDefaultValue (BlockData, &DefaultData);

}

}

@@ -3192,6 +3210,10 @@ Done:
}

}



+ if (IfrEfiVarStoreTmp != NULL) {

+ FreePool (IfrEfiVarStoreTmp);

+ }

+

return Status;

}



diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabase.h
b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabase.h
index c4ca6ad6ee..421c293cfc 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabase.h
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabase.h
@@ -2308,6 +2308,29 @@ HiiGetConfigRespInfo (
IN CONST EFI_HII_DATABASE_PROTOCOL *This

);



+/**

+ Find question default value from PcdNvStoreDefaultValueBuffer

+

+ @param DefaultId Default store ID

+ @param EfiVarStore Point to EFI VarStore header

+ @param IfrQuestionHdr Point to Question header

+ @param ValueBuffer Point to Buffer includes the found default
setting

+ @param Width Width of the default value

+ @param BitFieldQuestion Whether the Question is stored in Bit
field.

+

+ @retval EFI_SUCCESS Question default value is found.

+ @retval EFI_NOT_FOUND Question default value is not found.

+**/

+EFI_STATUS

+FindQuestionDefaultSetting (

+ IN UINT16 DefaultId,

+ IN EFI_IFR_VARSTORE_EFI *EfiVarStore,

+ IN EFI_IFR_QUESTION_HEADER *IfrQuestionHdr,

+ OUT VOID *ValueBuffer,

+ IN UINTN Width,

+ IN BOOLEAN BitFieldQuestion

+ );

+

//

// Global variables

//

--
2.25.1











回复: [edk2-devel] [PATCH] uefi-sct/SctPkg:Enhance BBTestReadKeyStrokeExFunctionAutoTestCheckpoint1()

Gao Jie
 

Hi Sunny,

Thanks for clarification. I will update the patch to make test fail when
KeyState is not touched.

Thanks
Barton

-----邮件原件-----
发件人: Sunny Wang <Sunny.Wang@...>
发送时间: 2022年4月7日 22:51
收件人: devel@edk2.groups.io; Sunny Wang <Sunny.Wang@...>;
gaojie@...
抄送: G Edhaya Chandran <Edhaya.Chandran@...>; Carolyn.Gjertsen@...;
Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@...>; eric.jin@...;
arvinx.chen@...; Supreeth.Venkatesh@...; Ruiyu Ni <ruiyu.ni@intel.
com>; Sunny Wang <Sunny.Wang@...>
主题: RE: [edk2-devel] [PATCH] uefi-sct/SctPkg:Enhance
BBTestReadKeyStrokeExFunctionAutoTestCheckpoint1()

Hi Barton,

As our discussion in today's edk2-test bug triage meeting, my second point "
UEFI spec implies that the ReadKeyStrokeEx should clear KeyState (set the
value to zero) if there is no key data" is not clear enough. Sorry about
that.

To be clear, UEFI spec says the following:
- UEFI drivers which implement the EFI_SIMPLE_TEXT_INPUT_EX protocol are
required to return KeyData.Key and KeyData.KeyState values. These drivers
must always return the most current state of KeyData.KeyState.KeyShiftState
and KeyData.KeyState.KeyToggleState.
However, when user doesn't press any key, there will be no most current
state to return. For solving thie problems, @Ruiyu Ni (In Cc) has patch
series https://edk2.groups.io/g/devel/message/20311 and commit message
below:
- Today's implementation only return key state when there is a key.But when
user doesn't press any key, the key state cannot be returned.The patch
changes the ReadKeyStrokeEx() to always return the key state even there is
no key pressed.

Therefore, this is just preferred implementation rather than a requirement
in spec.

Best Regards,
Sunny

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Sunny Wang
via groups.io
Sent: 03 March 2022 17:28
To: devel@edk2.groups.io; gaojie@...
Cc: G Edhaya Chandran <Edhaya.Chandran@...>; Carolyn.Gjertsen@...;
Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@...>; eric.jin@...;
arvinx.chen@...; Supreeth.Venkatesh@...; Sunny Wang
<Sunny.Wang@...>
Subject: Re: [edk2-devel] [PATCH] uefi-sct/SctPkg:Enhance
BBTestReadKeyStrokeExFunctionAutoTestCheckpoint1()

Sorry for the late review.

The change looks fine. However, I'm confused about the comment " Log the
error here and return key states are not supported when high order bit of
KeyToggleState is 0 or KeyState not touched". It looks like returning
EFI_UNSUPPORTED won't log any error/failure in the result log. Did I
overlook anything here?

Furthermore, it looks like UEFI spec implies that the ReadKeyStrokeEx should
clear KeyState (set the value to zero) if there is no key data. There is
also a code change for doing this in edk2.
https://edk2.groups.io/g/devel/message/20311
Therefore, if I didn't overlook anything here, we should separately deal
with the "(Key.KeyState.KeyShiftState == 0xFFFFFFFF) ||
(Key.KeyState.KeyToggleState == 0xFF)" as a failure rather than directly
returning EFI_UNSUPPORTED.

Barton and Edhaya, what do you guys think?

Best Regards,
Sunny
-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Gao Jie via
groups.io
Sent: 24 November 2021 03:16
To: devel@edk2.groups.io
Cc: G Edhaya Chandran <Edhaya.Chandran@...>; Carolyn.Gjertsen@...;
Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@...>; eric.jin@...;
arvinx.chen@...; Supreeth.Venkatesh@...
Subject: [edk2-devel] [PATCH] uefi-sct/SctPkg:Enhance
BBTestReadKeyStrokeExFunctionAutoTestCheckpoint1()

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2386

Enhance BBTestReadKeyStrokeExFunctionAutoTestCheckpoint1()
to handle ReadKeyStrokeEx implementation which returns EFI_NOT_READY
but without touching KeyToggleState.

Signed-off-by: Barton Gao <gaojie@...>
---
.../BlackBoxTest/SimpleTextInputExBBTestFunction.c | 11 ++++++++++-
.../BlackBoxTest/SimpleTextInputExBBTestFunction.c | 11 ++++++++++-
2 files changed, 20 insertions(+), 2 deletions(-)

diff --git
a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/SimpleTextInputEx/BlackBoxTest/
SimpleTextInputExBBTestFunction.c
b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/SimpleTextInputEx/BlackBoxTest/
SimpleTextInputExBBTestFunction.c
index 0398bc26..c1669959 100644
---
a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/SimpleTextInputEx/BlackBoxTest/
SimpleTextInputExBBTestFunction.c
+++
b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/SimpleTextInputEx/BlackBoxTest/
SimpleTextInputExBBTestFunction.c
@@ -1160,6 +1160,12 @@ BBTestReadKeyStrokeExFunctionAutoTestCheckpoint1 (
ValidState[5] = EFI_TOGGLE_STATE_VALID | EFI_KEY_STATE_EXPOSED |
EFI_NUM_LOCK_ACTIVE | EFI_CAPS_LOCK_ACTIVE;
ValidState[6] = EFI_TOGGLE_STATE_VALID | EFI_KEY_STATE_EXPOSED |
EFI_SCROLL_LOCK_ACTIVE |EFI_NUM_LOCK_ACTIVE | EFI_CAPS_LOCK_ACTIVE;

+ //
+ // Set all bits to one (invalid values) for both KeyShiftState and
KeyToggleState
+ //
+ Key.KeyState.KeyShiftState = 0xFFFFFFFF;
+ Key.KeyState.KeyToggleState = 0xFF;
+
//
//Read next keystroke from the input device
//
@@ -1171,7 +1177,10 @@ BBTestReadKeyStrokeExFunctionAutoTestCheckpoint1 (
return Status;
}

- if ((Key.KeyState.KeyToggleState & EFI_TOGGLE_STATE_VALID) == 0) {
+ if (((Key.KeyState.KeyToggleState & EFI_TOGGLE_STATE_VALID) == 0) ||
(Key.KeyState.KeyShiftState == 0xFFFFFFFF) || (Key.KeyState.KeyToggleState
== 0xFF)) {
+ //
+ // Log the error here and return key states are not supported when high
order bit of KeyToggleState is 0 or KeyState not touched
+ //
return EFI_UNSUPPORTED;
}

diff --git
a/uefi-sct/SctPkg/TestCase/UEFI/IHV/Protocol/SimpleTextInputEx/BlackBoxTest/
SimpleTextInputExBBTestFunction.c
b/uefi-sct/SctPkg/TestCase/UEFI/IHV/Protocol/SimpleTextInputEx/BlackBoxTest/
SimpleTextInputExBBTestFunction.c
index adbf3dcf..e20ed345 100644
---
a/uefi-sct/SctPkg/TestCase/UEFI/IHV/Protocol/SimpleTextInputEx/BlackBoxTest/
SimpleTextInputExBBTestFunction.c
+++
b/uefi-sct/SctPkg/TestCase/UEFI/IHV/Protocol/SimpleTextInputEx/BlackBoxTest/
SimpleTextInputExBBTestFunction.c
@@ -1160,6 +1160,12 @@ BBTestReadKeyStrokeExFunctionAutoTestCheckpoint1 (
ValidState[5] = EFI_TOGGLE_STATE_VALID | EFI_KEY_STATE_EXPOSED |
EFI_NUM_LOCK_ACTIVE | EFI_CAPS_LOCK_ACTIVE;
ValidState[6] = EFI_TOGGLE_STATE_VALID | EFI_KEY_STATE_EXPOSED |
EFI_SCROLL_LOCK_ACTIVE |EFI_NUM_LOCK_ACTIVE | EFI_CAPS_LOCK_ACTIVE;

+ //
+ // Set all bits to one (invalid values) for both KeyShiftState and
KeyToggleState
+ //
+ Key.KeyState.KeyShiftState = 0xFFFFFFFF;
+ Key.KeyState.KeyToggleState = 0xFF;
+
//
//Read next keystroke from the input device
//
@@ -1171,7 +1177,10 @@ BBTestReadKeyStrokeExFunctionAutoTestCheckpoint1 (
return Status;
}

- if ((Key.KeyState.KeyToggleState & EFI_TOGGLE_STATE_VALID) == 0) {
+ if (((Key.KeyState.KeyToggleState & EFI_TOGGLE_STATE_VALID) == 0) ||
(Key.KeyState.KeyShiftState == 0xFFFFFFFF) || (Key.KeyState.KeyToggleState
== 0xFF)) {
+ //
+ // Log the error here and return key states are not supported when high
order bit of KeyToggleState is 0 or KeyState not touched
+ //
return EFI_UNSUPPORTED;
}

--
2.31.0.windows.1







IMPORTANT NOTICE: The contents of this email and any attachments are
confidential and may also be privileged. If you are not the intended
recipient, please notify the sender immediately and do not disclose the
contents to any other person, use it for any purpose, or store or copy the
information in any medium. Thank you.





IMPORTANT NOTICE: The contents of this email and any attachments are
confidential and may also be privileged. If you are not the intended
recipient, please notify the sender immediately and do not disclose the
contents to any other person, use it for any purpose, or store or copy the
information in any medium. Thank you.

6081 - 6100 of 94575