Date   

Re: [[edk2-devel] PATH v1 2/3] OvmfPkg: take PcdResizeXterm from the QEMU command line

Ard Biesheuvel
 

On Tue, 23 Aug 2022 at 03:03, Paweł Poławski <ppolawsk@...> wrote:

From: Laszlo Ersek <lersek@...>
<--- insert explanatory text here --->


Signed-off-by: Laszlo Ersek <lersek@...>

Pawel: Updated commit message for re-submission

Cc: Ard Biesheuvel <ardb+tianocore@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Jordan Justen <jordan.l.justen@...>
Cc: Gerd Hoffmann <kraxel@...>

Signed-off-by: Paweł Poławski <ppolawsk@...>
---
OvmfPkg/AmdSev/AmdSevX64.dsc | 1 +
OvmfPkg/CloudHv/CloudHvX64.dsc | 1 +
OvmfPkg/IntelTdx/IntelTdxX64.dsc | 1 +
OvmfPkg/Microvm/MicrovmX64.dsc | 2 +-
OvmfPkg/OvmfPkgIa32.dsc | 1 +
OvmfPkg/OvmfPkgIa32X64.dsc | 1 +
OvmfPkg/OvmfPkgX64.dsc | 1 +
OvmfPkg/PlatformPei/PlatformPei.inf | 1 +
OvmfPkg/PlatformPei/Platform.c | 13 +++++++++++++
9 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc
index 90e8a213ef77..20f9f0fd2424 100644
--- a/OvmfPkg/AmdSev/AmdSevX64.dsc
+++ b/OvmfPkg/AmdSev/AmdSevX64.dsc
@@ -475,6 +475,7 @@
[PcdsDynamicDefault]
gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved|0

+ gEfiMdeModulePkgTokenSpaceGuid.PcdResizeXterm|FALSE
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64|0
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64|0
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64|0
diff --git a/OvmfPkg/CloudHv/CloudHvX64.dsc b/OvmfPkg/CloudHv/CloudHvX64.dsc
index f0d700f14477..bac05b72f2da 100644
--- a/OvmfPkg/CloudHv/CloudHvX64.dsc
+++ b/OvmfPkg/CloudHv/CloudHvX64.dsc
@@ -573,6 +573,7 @@
# ($(SMM_REQUIRE) == FALSE)
gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved|0

+ gEfiMdeModulePkgTokenSpaceGuid.PcdResizeXterm|FALSE
!if $(SMM_REQUIRE) == FALSE
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64|0
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64|0
diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdxX64.dsc
index 71b1cf8e7090..f6945f6598b6 100644
--- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc
+++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc
@@ -464,6 +464,7 @@
# ($(SMM_REQUIRE) == FALSE)
gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved|0

+ gEfiMdeModulePkgTokenSpaceGuid.PcdResizeXterm|FALSE
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64|0
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64|0
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64|0
diff --git a/OvmfPkg/Microvm/MicrovmX64.dsc b/OvmfPkg/Microvm/MicrovmX64.dsc
index 52498bbe90a8..89c3dfce98ba 100644
--- a/OvmfPkg/Microvm/MicrovmX64.dsc
+++ b/OvmfPkg/Microvm/MicrovmX64.dsc
@@ -562,7 +562,7 @@
# only set when
# ($(SMM_REQUIRE) == FALSE)
gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved|0
-
+ gEfiMdeModulePkgTokenSpaceGuid.PcdResizeXterm|FALSE
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64|0
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64|0
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64|0
diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index 725a01ae9a20..22ea7e109c21 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -584,6 +584,7 @@
# ($(SMM_REQUIRE) == FALSE)
gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved|0

+ gEfiMdeModulePkgTokenSpaceGuid.PcdResizeXterm|FALSE
!if $(SMM_REQUIRE) == FALSE
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64|0
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64|0
diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index adc813ba2e1e..3d832080f3b9 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -592,6 +592,7 @@
# ($(SMM_REQUIRE) == FALSE)
gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved|0

+ gEfiMdeModulePkgTokenSpaceGuid.PcdResizeXterm|FALSE
!if $(SMM_REQUIRE) == FALSE
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64|0
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64|0
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index 6e68f60dc90f..16cfa4c362cb 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -611,6 +611,7 @@
# ($(SMM_REQUIRE) == FALSE)
gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved|0

+ gEfiMdeModulePkgTokenSpaceGuid.PcdResizeXterm|FALSE
!if $(SMM_REQUIRE) == FALSE
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64|0
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64|0
diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/PlatformPei.inf
index 3cd83e6ec3e5..47adfd0fbb90 100644
--- a/OvmfPkg/PlatformPei/PlatformPei.inf
+++ b/OvmfPkg/PlatformPei/PlatformPei.inf
@@ -99,6 +99,7 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved
+ gEfiMdeModulePkgTokenSpaceGuid.PcdResizeXterm
gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode
gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable
gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack
diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c
index 009db67ee60a..83d40b8a51f5 100644
--- a/OvmfPkg/PlatformPei/Platform.c
+++ b/OvmfPkg/PlatformPei/Platform.c
@@ -41,6 +41,18 @@

#include "Platform.h"

+#define UPDATE_BOOLEAN_PCD_FROM_FW_CFG(TokenName) \
+ do { \
+ BOOLEAN Setting; \
+ RETURN_STATUS PcdStatus; \
+ \
+ if (!RETURN_ERROR (QemuFwCfgParseBool ( \
+ "opt/ovmf/" #TokenName, &Setting))) { \
+ PcdStatus = PcdSetBoolS (TokenName, Setting); \
+ ASSERT_RETURN_ERROR (PcdStatus); \
+ } \
+ } while (0)
+
EFI_HOB_PLATFORM_INFO mPlatformInfoHob = { 0 };

EFI_PEI_PPI_DESCRIPTOR mPpiBootMode[] = {
@@ -387,6 +399,7 @@ InitializePlatform (
MemTypeInfoInitialization ();
MemMapInitialization (&mPlatformInfoHob);
NoexecDxeInitialization ();
+ UPDATE_BOOLEAN_PCD_FROM_FW_CFG (PcdResizeXterm);
}

InstallClearCacheCallback ();
--
2.37.2


Re: [PATCH v2 0/6] ArmPkg/SMBIOS fixes and improvements

Ard Biesheuvel
 

On Wed, 24 Aug 2022 at 18:51, Nhi Pham <nhi@...> wrote:

This patchset is to update the ArmPkg/SMBIOS for fixes and improvements.

Changes since v1:
+ Change PartNumber to ProcessorVersion [Sami]

Minh Nguyen (5):
ArmPkg/ProcessorSubClassDxe: Get processor version from OemMiscLib
ArmPkg: Correct return value of "SMCCC_ARCH_SOC_ID" Function ID call
ArmPkg/SmbiosMiscDxe: Fix typo of "AssetTagType02"
ArmPkg/SmbiosMiscDxe: Remove redundant updates in SMBIOS Type 2
ArmPkg/SmbiosMiscDxe: Get SMBIOS information from OemMiscLib

Nhi Pham (1):
ArmPkg/SmbiosMiscDxe: Support fetching System UUID
As Sami appears to be happy with this series,

Acked-by: Ard Biesheuvel <ardb@...>

ArmPkg/Include/Library/OemMiscLib.h | 37 +++++++++++++++-
ArmPkg/Universal/Smbios/OemMiscLibNull/OemMiscLib.c | 46 ++++++++++++++++++++
ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClass.c | 8 +++-
ArmPkg/Universal/Smbios/ProcessorSubClassDxe/SmbiosProcessorArmCommon.c | 6 +--
ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendorFunction.c | 32 +++++++++-----
ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type01/MiscSystemManufacturerFunction.c | 3 +-
ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type02/MiscBaseBoardManufacturerFunction.c | 13 +-----
7 files changed, 117 insertions(+), 28 deletions(-)

--
2.25.1


Re: [PATCH V4 1/8] EmbeddedPkg: Add AllocateRuntimePages in PrePiMemoryAllocationLib

Ard Biesheuvel
 

On Fri, 1 Jul 2022 at 01:29, Min Xu <min.m.xu@...> wrote:

From: Min M Xu <min.m.xu@...>

AllocateRuntimePages is used to allocate one or more 4KB pages of
type EfiRuntimeServicesData.

Cc: Leif Lindholm <quic_llindhol@...>
Cc: Ard Biesheuvel <ardb+tianocore@...>
Cc: Abner Chang <abner.chang@...>
Cc: Daniel Schaefer <daniel.schaefer@...>
Cc: Gerd Hoffmann <kraxel@...>
Signed-off-by: Min Xu <min.m.xu@...>
With one comment below addressed:

Reviewed-by: Ard Biesheuvel <ardb@...>

---
EmbeddedPkg/Include/Library/PrePiLib.h | 19 ++++++
.../MemoryAllocationLib.c | 64 ++++++++++++++-----
2 files changed, 67 insertions(+), 16 deletions(-)

diff --git a/EmbeddedPkg/Include/Library/PrePiLib.h b/EmbeddedPkg/Include/Library/PrePiLib.h
index 7b2cea296f1c..3741b08c4478 100644
--- a/EmbeddedPkg/Include/Library/PrePiLib.h
+++ b/EmbeddedPkg/Include/Library/PrePiLib.h
@@ -665,6 +665,25 @@ AllocatePages (
IN UINTN Pages
);

+/**
+ Allocates one or more 4KB pages of type EfiRuntimeServicesData.
+
+ Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
+ allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
+ is returned. If there is not enough memory remaining to satisfy the request, then NULL is
+ returned.
+
+ @param Pages The number of 4 KB pages to allocate.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+AllocateRuntimePages (
+ IN UINTN Pages
+ );
+
/**
Allocates a buffer of type EfiBootServicesData.

diff --git a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c
index 78f8da5e9527..9d7b34ad28fa 100644
--- a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c
+++ b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c
@@ -14,23 +14,11 @@
#include <Library/PrePiLib.h>
#include <Library/DebugLib.h>

-/**
- Allocates one or more 4KB pages of type EfiBootServicesData.
-
- Allocates the number of 4KB pages of MemoryType and returns a pointer to the
- allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
- is returned. If there is not enough memory remaining to satisfy the request, then NULL is
- returned.
-
- @param Pages The number of 4 KB pages to allocate.
-
- @return A pointer to the allocated buffer or NULL if allocation fails.
-
-**/
VOID *
EFIAPI
-AllocatePages (
- IN UINTN Pages
+InternalAllocatePages (
Please make this STATIC

+ IN UINTN Pages,
+ IN EFI_MEMORY_TYPE MemoryType
)
{
EFI_PEI_HOB_POINTERS Hob;
@@ -65,12 +53,56 @@ AllocatePages (
BuildMemoryAllocationHob (
Hob.HandoffInformationTable->EfiFreeMemoryTop,
Pages * EFI_PAGE_SIZE,
- EfiBootServicesData
+ MemoryType
);
return (VOID *)(UINTN)Hob.HandoffInformationTable->EfiFreeMemoryTop;
}
}

+/**
+ Allocates one or more 4KB pages of type EfiBootServicesData.
+
+ Allocates the number of 4KB pages of MemoryType and returns a pointer to the
+ allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
+ is returned. If there is not enough memory remaining to satisfy the request, then NULL is
+ returned.
+
+ @param Pages The number of 4 KB pages to allocate.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+AllocatePages (
+ IN UINTN Pages
+ )
+{
+ return InternalAllocatePages (Pages, EfiBootServicesData);
+}
+
+/**
+ Allocates one or more 4KB pages of type EfiRuntimeServicesData.
+
+ Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
+ allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
+ is returned. If there is not enough memory remaining to satisfy the request, then NULL is
+ returned.
+
+ @param Pages The number of 4 KB pages to allocate.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+AllocateRuntimePages (
+ IN UINTN Pages
+ )
+{
+ return InternalAllocatePages (Pages, EfiRuntimeServicesData);
+}
+
/**
Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.

--
2.29.2.windows.2






Re: [PATCH 0/2] Add support EFI_MP_SERVICES_PROTOCOL on AARCH64

Ard Biesheuvel
 

On Mon, 29 Aug 2022 at 18:00, Rebecca Cran <quic_rcran@...> wrote:

This is the rework of the patches I sent out in late 2021,
building on fixes done by Ard at
https://github.com/ardbiesheuvel/edk2/tree/armpkg-mpservicesdxe-refactor.

The most significant changes are the addition of code to enable
the MMU and caches on the APs, and changing MpServicesTest to
use commandline parameters to control its operation.
IIRC, there were some issues with this code on bare metal. Which
hardware did you use to test it? Any chance you could try it on a
RPi4?

Rebecca Cran (2):
ArmPkg: implement EFI_MP_SERVICES_PROTOCOL based on PSCI calls
MdeModulePkg: Add new Application/MpServicesTest application

ArmPkg/ArmPkg.dsc | 1 +
MdeModulePkg/MdeModulePkg.dsc | 9 +
ArmPkg/Drivers/ArmPsciMpServicesDxe/ArmPsciMpServicesDxe.inf | 55 +
MdeModulePkg/Application/MpServicesTest/MpServicesTest.inf | 41 +
ArmPkg/Drivers/ArmPsciMpServicesDxe/MpServicesInternal.h | 351 ++++
MdeModulePkg/Application/MpServicesTest/Options.h | 39 +
ArmPkg/Drivers/ArmPsciMpServicesDxe/ArmPsciMpServicesDxe.c | 1774 ++++++++++++++++++++
MdeModulePkg/Application/MpServicesTest/MpServicesTest.c | 558 ++++++
MdeModulePkg/Application/MpServicesTest/Options.c | 215 +++
ArmPkg/Drivers/ArmPsciMpServicesDxe/MpFuncs.S | 57 +
10 files changed, 3100 insertions(+)
create mode 100644 ArmPkg/Drivers/ArmPsciMpServicesDxe/ArmPsciMpServicesDxe.inf
create mode 100644 MdeModulePkg/Application/MpServicesTest/MpServicesTest.inf
create mode 100644 ArmPkg/Drivers/ArmPsciMpServicesDxe/MpServicesInternal.h
create mode 100644 MdeModulePkg/Application/MpServicesTest/Options.h
create mode 100644 ArmPkg/Drivers/ArmPsciMpServicesDxe/ArmPsciMpServicesDxe.c
create mode 100644 MdeModulePkg/Application/MpServicesTest/MpServicesTest.c
create mode 100644 MdeModulePkg/Application/MpServicesTest/Options.c
create mode 100644 ArmPkg/Drivers/ArmPsciMpServicesDxe/MpFuncs.S

--
2.30.2






Re: [PATCH V3 06/12] ShellPkg: Update shell command memmap to show unaccepted memory

Gao, Zhichao
 

Reviewed-by: Zhichao Gao <zhichao.gao@...>

Thanks,
Zhichao

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Min Xu
Sent: Monday, September 5, 2022 4:35 PM
To: devel@edk2.groups.io
Cc: Xu, Min M <min.m.xu@...>; Ni, Ray <ray.ni@...>; Gao,
Zhichao <zhichao.gao@...>; Aktas, Erdem
<erdemaktas@...>; Gerd Hoffmann <kraxel@...>; James
Bottomley <jejb@...>; Yao, Jiewen <jiewen.yao@...>;
Tom Lendacky <thomas.lendacky@...>
Subject: [edk2-devel] [PATCH V3 06/12] ShellPkg: Update shell command
memmap to show unaccepted memory

From: Min M Xu <min.m.xu@...>

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

ShellCommandRunMemMap() is updated to handle the case of unaccepted
memory type.

Cc: Ray Ni <ray.ni@...>
Cc: Zhichao Gao <zhichao.gao@...>
Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Acked-by: Gerd Hoffmann <kraxel@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
.../Library/UefiShellDebug1CommandsLib/MemMap.c | 13
+++++++++++++
.../UefiShellDebug1CommandsLib.uni | 3 ++-
2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c
b/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c
index 72f3c58b0970..a089953b286f 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c
@@ -26,6 +26,7 @@ STATIC CONST CHAR16 NameEfiACPIMemoryNVS[]
= L"ACPIMemoryNVS";
STATIC CONST CHAR16 NameEfiMemoryMappedIO[] =
L"MemoryMappedIO";
STATIC CONST CHAR16 NameEfiMemoryMappedIOPortSpace[] =
L"MemoryMappedIOPortSpace";
STATIC CONST CHAR16 NameEfiPalCode[] = L"PalCode";
+STATIC CONST CHAR16 NameEfiUnacceptedMemoryType[] =
L"Unaccepted";

//
// Need short names for some memory types @@ -151,6 +152,8 @@
ShellCommandRunMemMap (
UINT64 UnusableMemoryPagesSize;
UINT64 PalCodePages;
UINT64 PalCodePagesSize;
+ UINT64 UnacceptedPages;
+ UINT64 UnacceptedPagesSize;
UINT64 PersistentPages;
UINT64 PersistentPagesSize;
BOOLEAN Sfo;
@@ -175,6 +178,7 @@ ShellCommandRunMemMap (
PalCodePages = 0;
PersistentPages = 0;
Size = 0;
+ UnacceptedPages = 0;
Descriptors = NULL;
ShellStatus = SHELL_SUCCESS;
Status = EFI_SUCCESS;
@@ -303,6 +307,11 @@ ShellCommandRunMemMap (
TotalPages += Walker->NumberOfPages;
PalCodePages += Walker->NumberOfPages;
break;
+ case EfiUnacceptedMemoryType:
+ ShellPrintHiiEx (-1, -1, NULL, (EFI_STRING_ID)(!Sfo ? STRING_TOKEN
(STR_MEMMAP_LIST_ITEM) : STRING_TOKEN
(STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle,
NameEfiUnacceptedMemoryType, Walker->PhysicalStart, Walker-
PhysicalStart+MultU64x64 (SIZE_4KB, Walker->NumberOfPages)-1, Walker-
NumberOfPages, Walker->Attribute);
+ TotalPages += Walker->NumberOfPages;
+ UnacceptedPages += Walker->NumberOfPages;
+ break;
default:
//
// Shell Spec defines the SFO format.
@@ -335,6 +344,7 @@ ShellCommandRunMemMap (
MmioSpacePagesSize = MultU64x64 (SIZE_4KB, MmioSpacePages);
MmioPortPagesSize = MultU64x64 (SIZE_4KB, MmioPortPages);
PalCodePagesSize = MultU64x64 (SIZE_4KB, PalCodePages);
+ UnacceptedPagesSize = MultU64x64 (SIZE_4KB, UnacceptedPages);
PersistentPagesSize = MultU64x64 (SIZE_4KB, PersistentPages);
UnusableMemoryPagesSize = MultU64x64 (SIZE_4KB,
UnusableMemoryPages);
if (!Sfo) {
@@ -368,6 +378,8 @@ ShellCommandRunMemMap (
MmioPortPagesSize,
PalCodePages,
PalCodePagesSize,
+ UnacceptedPages,
+ UnacceptedPagesSize,
AvailPages,
AvailPagesSize,
PersistentPages,
@@ -422,6 +434,7 @@ ShellCommandRunMemMap (
AcpiReclaimPagesSize,
AcpiNvsPagesSize,
PalCodePagesSize,
+ UnacceptedPagesSize,
PersistentPagesSize
);
}
diff --git
a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
dsLib.uni
b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
dsLib.uni
index 6693be26e699..b1d239ed37ea 100644
---
a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
dsLib.uni
+++
b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
d
+++ sLib.uni
@@ -88,13 +88,14 @@
" MMIO : %,14ld Pages (%,ld Bytes)\r\n"
" MMIO_Port : %,14ld Pages (%,ld Bytes)\r\n"
" PalCode : %,14ld Pages (%,ld Bytes)\r\n"
+ " Unaccepted: %,14ld Pages (%,ld Bytes)\r\n"
" Available : %,14ld Pages (%,ld Bytes)\r\n"
" Persistent: %,14ld Pages (%,ld Bytes)\r\n"
#string STR_MEMMAP_LIST_SUMM_OTHER #language en-US
" %08x : %,14ld Pages (%,ld Bytes)\r\n"
#string STR_MEMMAP_LIST_SUMM2 #language en-US " -------------
- \r\n"
"Total Memory: %,14ld MB (%,ld Bytes)\r\n"
#string STR_MEMMAP_LIST_ITEM_SFO #language en-US
"MemoryMap,"%s","%LX","%LX","%LX","%LX"\r\n"
-#string STR_MEMMAP_LIST_SUMM_SFO #language en-US
"MemoryMapSummary,"%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld
","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld"\r\n"
+#string STR_MEMMAP_LIST_SUMM_SFO #language en-US
"MemoryMapSummary,"%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld
","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld", "%Ld"\r\n"

#string STR_EFI_COMPRESS_FAIL #language en-US "Unable to
compress: %r.\r\n"
#string STR_EFI_DECOMPRESS_FAIL #language en-US "Unable to
decompress: %r.\r\n"
--
2.29.2.windows.2





[PATCH] BaseTools: Correct BPDG tool error prints

Konstantin Aladyshev
 

Popen communication returns bytestrings. It is necessary to perform
decode on these strings before passing them to the EdkLogger that
works with ordinary strings.

Signed-off-by: Konstantin Aladyshev <aladyshev22@...>
---
BaseTools/Source/Python/Common/VpdInfoFile.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/BaseTools/Source/Python/Common/VpdInfoFile.py b/BaseTools/Sour=
ce/Python/Common/VpdInfoFile.py
index 4249b9f899..1e0c3dfe76 100644
--- a/BaseTools/Source/Python/Common/VpdInfoFile.py
+++ b/BaseTools/Source/Python/Common/VpdInfoFile.py
@@ -248,8 +248,8 @@ def CallExtenalBPDGTool(ToolPath, VpdFileName):
PopenObject.wait()=0D
=0D
if PopenObject.returncode !=3D 0:=0D
- EdkLogger.debug(EdkLogger.DEBUG_1, "Fail to call BPDG tool", str(e=
rror))=0D
+ EdkLogger.debug(EdkLogger.DEBUG_1, "Fail to call BPDG tool", str(e=
rror.decode()))=0D
EdkLogger.error("BPDG", BuildToolError.COMMAND_FAILURE, "Fail to e=
xecute BPDG tool with exit code: %d, the error message is: \n %s" % \=0D
- (PopenObject.returncode, str(error)))=0D
+ (PopenObject.returncode, str(error.decode())))=
=0D
=0D
return PopenObject.returncode=0D
--=20
2.25.1


[PATCH] IntelSiliconPkg/VTd: Enable ADM when change TTM

Sheng Wei
 

In Abort DMA Mode(ADM), hardware will abort all DMA operations without
the need to set up a roottable. Enable Abort DMA Mode, when change
Translation Table Mode(TTM)

Change-Id: I74207fe96ef7a57d89a355d40dfbdd36186f06c3
Signed-off-by: Sheng Wei <w.sheng@...>
Cc: Jenny Huang <jenny.huang@...>
Cc: Ray Ni <ray.ni@...>
Cc: Rangasai V Chaganty <rangasai.v.chaganty@...>=0D
Cc: Robert Kowalewski <robert.kowalewski@...>
---
.../VTd/IntelVTdDmarPei/IntelVTdDmar.c | 157 +++++++++++-----
.../Feature/VTd/IntelVTdDxe/IntelVTdDxe.inf | 1 +
.../Feature/VTd/IntelVTdDxe/VtdReg.c | 169 +++++++++++++-----
.../Intel/IntelSiliconPkg/IntelSiliconPkg.dec | 12 +-
4 files changed, 245 insertions(+), 94 deletions(-)

diff --git a/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDmarPei/Inte=
lVTdDmar.c b/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDmarPei/Inte=
lVTdDmar.c
index b5b78f779..24beccd26 100644
--- a/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDmarPei/IntelVTdDma=
r.c
+++ b/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDmarPei/IntelVTdDma=
r.c
@@ -361,6 +361,68 @@ InvalidateIOTLB (
return EFI_SUCCESS;=0D
}=0D
=0D
+/**=0D
+ Clear Global Command Register Bits=0D
+=0D
+ @param[in] VtdUnitBaseAddress The base address of the VTd engine.=0D
+ @param[in] BitMask Bit mask.=0D
+**/=0D
+VOID=0D
+ClearGlobalCommandRegisterBits (=0D
+ IN UINTN VtdUnitBaseAddress,=0D
+ IN UINT32 BitMask=0D
+ )=0D
+{=0D
+ UINT32 Reg32;=0D
+ UINT32 Status;=0D
+ UINT32 Command;=0D
+=0D
+ Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG);=0D
+ Status =3D (Reg32 & 0x96FFFFFF); // Reset the one-shot bits=0D
+ Command =3D (Status & (~BitMask));=0D
+ MmioWrite32 (VtdUnitBaseAddress + R_GCMD_REG, Command);=0D
+=0D
+ DEBUG((DEBUG_INFO, "Clear GCMD_REG bits 0x%x.\n", BitMask));=0D
+=0D
+ //=0D
+ // Poll on Status bit of Global status register to become zero=0D
+ //=0D
+ do {=0D
+ Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG);=0D
+ } while ((Reg32 & BitMask) =3D=3D BitMask);=0D
+}=0D
+=0D
+/**=0D
+ Set Global Command Register Bits=0D
+=0D
+ @param[in] VtdUnitBaseAddress The base address of the VTd engine.=0D
+ @param[in] BitMask Bit mask.=0D
+**/=0D
+VOID=0D
+SetGlobalCommandRegisterBits (=0D
+ IN UINTN VtdUnitBaseAddress,=0D
+ IN UINT32 BitMask=0D
+ )=0D
+{=0D
+ UINT32 Reg32;=0D
+ UINT32 Status;=0D
+ UINT32 Command;=0D
+=0D
+ Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG);=0D
+ Status =3D (Reg32 & 0x96FFFFFF); // Reset the one-shot bits=0D
+ Command =3D (Status | BitMask);=0D
+ MmioWrite32 (VtdUnitBaseAddress + R_GCMD_REG, Command);=0D
+=0D
+ DEBUG((DEBUG_INFO, "Set GCMD_REG bits 0x%x.\n", BitMask));=0D
+=0D
+ //=0D
+ // Poll on Status bit of Global status register to become not zero=0D
+ //=0D
+ do {=0D
+ Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG);=0D
+ } while ((Reg32 & BitMask) =3D=3D 0);=0D
+}=0D
+=0D
/**=0D
Enable DMAR translation in pre-mem phase.=0D
=0D
@@ -383,13 +445,10 @@ EnableDmarPreMem (
DEBUG ((DEBUG_INFO, "RTADDR_REG : 0x%016lx \n", RtaddrRegValue));=0D
MmioWrite64 (VtdUnitBaseAddress + R_RTADDR_REG, RtaddrRegValue);=0D
=0D
- Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG);=0D
- MmioWrite32 (VtdUnitBaseAddress + R_GCMD_REG, Reg32 | B_GMCD_REG_SRTP);=
=0D
-=0D
DEBUG ((DEBUG_INFO, "EnableDmarPreMem: waiting for RTPS bit to be set...=
\n"));=0D
- do {=0D
- Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG);=0D
- } while((Reg32 & B_GSTS_REG_RTPS) =3D=3D 0);=0D
+ SetGlobalCommandRegisterBits (VtdUnitBaseAddress, B_GMCD_REG_SRTP);=0D
+=0D
+ Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG);=0D
DEBUG ((DEBUG_INFO, "EnableDmarPreMem: R_GSTS_REG =3D 0x%x \n", Reg32));=
=0D
=0D
//=0D
@@ -405,12 +464,7 @@ EnableDmarPreMem (
//=0D
// Enable VTd=0D
//=0D
- Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG);=0D
- MmioWrite32 (VtdUnitBaseAddress + R_GCMD_REG, Reg32 | B_GMCD_REG_TE);=0D
- DEBUG ((DEBUG_INFO, "EnableDmarPreMem: Waiting B_GSTS_REG_TE ...\n"));=0D
- do {=0D
- Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG);=0D
- } while ((Reg32 & B_GSTS_REG_TE) =3D=3D 0);=0D
+ SetGlobalCommandRegisterBits (VtdUnitBaseAddress, B_GMCD_REG_TE);=0D
=0D
DEBUG ((DEBUG_INFO, "VTD () enabled!<<<<<<\n"));=0D
=0D
@@ -434,22 +488,43 @@ EnableDmar (
{=0D
UINT32 Reg32;=0D
UINTN VtdUnitBaseAddress;=0D
+ BOOLEAN TEWasEnabled;=0D
=0D
VtdUnitBaseAddress =3D VTdUnitInfo->VtdUnitBaseAddress;=0D
=0D
DEBUG ((DEBUG_INFO, ">>>>>>EnableDmar() for engine [%x] \n", VtdUnitBase=
Address));=0D
=0D
- DEBUG ((DEBUG_INFO, "RootEntryTable 0x%x \n", RootEntryTable));=0D
- MmioWrite64 (VtdUnitBaseAddress + R_RTADDR_REG, (UINT64) RootEntryTable)=
;=0D
+ //=0D
+ // Check TE was enabled or not.=0D
+ //=0D
+ TEWasEnabled =3D ((MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG) & B_GSTS=
_REG_TE) =3D=3D B_GSTS_REG_TE);=0D
=0D
- Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG);=0D
- MmioWrite32 (VtdUnitBaseAddress + R_GCMD_REG, Reg32 | B_GMCD_REG_SRTP);=
=0D
+ if (TEWasEnabled && (VTdUnitInfo->ECapReg.Bits.ADMS =3D=3D 1) && PcdGetB=
ool (PcdVTdSupportAbortDmaMode)) {=0D
+ //=0D
+ // For implementations reporting Enhanced SRTP Support (ESRTPS) field =
as=0D
+ // Clear in the Capability register, software must not modify this fie=
ld while=0D
+ // DMA remapping is active (TES=3D1 in Global Status register).=0D
+ //=0D
+ if (VTdUnitInfo->CapReg.Bits.ESRTPS =3D=3D 0) {=0D
+ ClearGlobalCommandRegisterBits (VtdUnitBaseAddress, B_GMCD_REG_TE);=
=0D
+ }=0D
+=0D
+ //=0D
+ // Enable ADM=0D
+ //=0D
+ MmioWrite64 (VtdUnitBaseAddress + R_RTADDR_REG, (UINT64) (RootEntryTab=
le | V_RTADDR_REG_TTM_ADM));=0D
+=0D
+ DEBUG((DEBUG_INFO, "Enable Abort DMA Mode...\n"));=0D
+ SetGlobalCommandRegisterBits (VtdUnitBaseAddress, B_GMCD_REG_TE);=0D
+=0D
+ } else {=0D
+ DEBUG ((DEBUG_INFO, "RootEntryTable 0x%x \n", RootEntryTable));=0D
+ MmioWrite64 (VtdUnitBaseAddress + R_RTADDR_REG, (UINT64) RootEntryTabl=
e);=0D
+=0D
+ }=0D
=0D
DEBUG ((DEBUG_INFO, "EnableDmar: waiting for RTPS bit to be set... \n"))=
;=0D
- do {=0D
- Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG);=0D
- } while((Reg32 & B_GSTS_REG_RTPS) =3D=3D 0);=0D
- DEBUG ((DEBUG_INFO, "EnableDmar: R_GSTS_REG =3D 0x%x \n", Reg32));=0D
+ SetGlobalCommandRegisterBits (VtdUnitBaseAddress, B_GMCD_REG_SRTP);=0D
=0D
//=0D
// Init DMAr Fault Event and Data registers=0D
@@ -471,15 +546,19 @@ EnableDmar (
//=0D
InvalidateIOTLB (VTdUnitInfo);=0D
=0D
+ if (TEWasEnabled && (VTdUnitInfo->ECapReg.Bits.ADMS =3D=3D 1) && PcdGetB=
ool (PcdVTdSupportAbortDmaMode)) {=0D
+ if (VTdUnitInfo->CapReg.Bits.ESRTPS =3D=3D 0) {=0D
+ ClearGlobalCommandRegisterBits (VtdUnitBaseAddress, B_GMCD_REG_TE);=
=0D
+ }=0D
+=0D
+ DEBUG ((DEBUG_INFO, "RootEntryTable 0x%x \n", RootEntryTable));=0D
+ MmioWrite64 (VtdUnitBaseAddress + R_RTADDR_REG, (UINT64) RootEntryTabl=
e);=0D
+ }=0D
+=0D
//=0D
// Enable VTd=0D
//=0D
- Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG);=0D
- MmioWrite32 (VtdUnitBaseAddress + R_GCMD_REG, Reg32 | B_GMCD_REG_TE);=0D
- DEBUG ((DEBUG_INFO, "EnableDmar: Waiting B_GSTS_REG_TE ...\n"));=0D
- do {=0D
- Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG);=0D
- } while ((Reg32 & B_GSTS_REG_TE) =3D=3D 0);=0D
+ SetGlobalCommandRegisterBits (VtdUnitBaseAddress, B_GMCD_REG_TE);=0D
=0D
DEBUG ((DEBUG_INFO, "VTD () enabled!<<<<<<\n"));=0D
=0D
@@ -500,8 +579,6 @@ DisableDmar (
)=0D
{=0D
UINT32 Reg32;=0D
- UINT32 Status;=0D
- UINT32 Command;=0D
=0D
DEBUG ((DEBUG_INFO, ">>>>>>DisableDmar() for engine [%x] \n", VtdUnitBas=
eAddress));=0D
=0D
@@ -516,28 +593,12 @@ DisableDmar (
//=0D
// Set TE (Translation Enable: BIT31) of Global command register to zero=
=0D
//=0D
- Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG);=0D
- Status =3D (Reg32 & 0x96FFFFFF); // Reset the one-shot bits=0D
- Command =3D (Status & ~B_GMCD_REG_TE);=0D
- MmioWrite32 (VtdUnitBaseAddress + R_GCMD_REG, Command);=0D
-=0D
- //=0D
- // Poll on TE Status bit of Global status register to become zero=0D
- //=0D
- do {=0D
- Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG);=0D
- } while ((Reg32 & B_GSTS_REG_TE) =3D=3D B_GSTS_REG_TE);=0D
+ ClearGlobalCommandRegisterBits (VtdUnitBaseAddress, B_GMCD_REG_TE);=0D
=0D
//=0D
// Set SRTP (Set Root Table Pointer: BIT30) of Global command register i=
n order to update the root table pointerDisable VTd=0D
//=0D
- Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG);=0D
- Status =3D (Reg32 & 0x96FFFFFF); // Reset the one-shot bits=0D
- Command =3D (Status | B_GMCD_REG_SRTP);=0D
- MmioWrite32 (VtdUnitBaseAddress + R_GCMD_REG, Command);=0D
- do {=0D
- Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG);=0D
- } while((Reg32 & B_GSTS_REG_RTPS) =3D=3D 0);=0D
+ SetGlobalCommandRegisterBits (VtdUnitBaseAddress, B_GMCD_REG_SRTP);=0D
=0D
Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG);=0D
DEBUG((DEBUG_INFO, "DisableDmar: GSTS_REG - 0x%08x\n", Reg32));=0D
@@ -568,12 +629,12 @@ EnableVTdTranslationProtectionBlockDma (
=0D
DEBUG ((DEBUG_INFO, "EnableVTdTranslationProtectionBlockDma - 0x%08x\n",=
VtdUnitBaseAddress));=0D
=0D
- DEBUG ((DEBUG_INFO, "PcdVTdSupportAbortDmaMode : %d\n", FixedPcdGetBool =
(PcdVTdSupportAbortDmaMode)));=0D
+ DEBUG ((DEBUG_INFO, "PcdVTdSupportAbortDmaMode : %d\n", PcdGetBool (PcdV=
TdSupportAbortDmaMode)));=0D
=0D
ECapReg.Uint64 =3D MmioRead64 (VtdUnitBaseAddress + R_ECAP_REG);=0D
DEBUG ((DEBUG_INFO, "ECapReg.ADMS : %d\n", ECapReg.Bits.ADMS));=0D
=0D
- if ((ECapReg.Bits.ADMS =3D=3D 1) && FixedPcdGetBool (PcdVTdSupportAbortD=
maMode)) {=0D
+ if ((ECapReg.Bits.ADMS =3D=3D 1) && PcdGetBool (PcdVTdSupportAbortDmaMod=
e)) {=0D
//=0D
// Use Abort DMA Mode=0D
//=0D
diff --git a/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/IntelVTd=
Dxe.inf b/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/IntelVTdDxe=
.inf
index 387f90e37..b152831c0 100644
--- a/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/IntelVTdDxe.inf
+++ b/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/IntelVTdDxe.inf
@@ -75,6 +75,7 @@
[Pcd]=0D
gIntelSiliconPkgTokenSpaceGuid.PcdVTdPolicyPropertyMask ## CONSUMES=0D
gIntelSiliconPkgTokenSpaceGuid.PcdErrorCodeVTdError ## CONSUMES=0D
+ gIntelSiliconPkgTokenSpaceGuid.PcdVTdSupportAbortDmaMode ## CONSUMES=0D
=0D
[Depex]=0D
gEfiPciRootBridgeIoProtocolGuid=0D
diff --git a/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/VtdReg.c=
b/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/VtdReg.c
index c7a56cf57..396aa4a70 100644
--- a/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/VtdReg.c
+++ b/Silicon/Intel/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/VtdReg.c
@@ -475,6 +475,92 @@ DisablePmr (
return ;=0D
}=0D
=0D
+/**=0D
+ Clear Global Command Register Bits=0D
+=0D
+ @param[in] VtdUnitBaseAddress The base address of the VTd engine.=0D
+ @param[in] BitMask Bit mask.=0D
+**/=0D
+VOID=0D
+ClearGlobalCommandRegisterBits (=0D
+ IN UINTN VtdUnitBaseAddress,=0D
+ IN UINT32 BitMask=0D
+ )=0D
+{=0D
+ UINT32 Reg32;=0D
+ UINT32 Status;=0D
+ UINT32 Command;=0D
+=0D
+ Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG);=0D
+ Status =3D (Reg32 & 0x96FFFFFF); // Reset the one-shot bits=0D
+ Command =3D (Status & (~BitMask));=0D
+ MmioWrite32 (VtdUnitBaseAddress + R_GCMD_REG, Command);=0D
+=0D
+ DEBUG((DEBUG_INFO, "Clear GCMD_REG bits 0x%x.\n", BitMask));=0D
+=0D
+ //=0D
+ // Poll on Status bit of Global status register to become zero=0D
+ //=0D
+ do {=0D
+ Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG);=0D
+ } while ((Reg32 & BitMask) =3D=3D BitMask);=0D
+}=0D
+=0D
+/**=0D
+ Set Global Command Register Bits=0D
+=0D
+ @param[in] VtdUnitBaseAddress The base address of the VTd engine.=0D
+ @param[in] BitMask Bit mask.=0D
+**/=0D
+VOID=0D
+SetGlobalCommandRegisterBits (=0D
+ IN UINTN VtdUnitBaseAddress,=0D
+ IN UINT32 BitMask=0D
+ )=0D
+{=0D
+ UINT32 Reg32;=0D
+ UINT32 Status;=0D
+ UINT32 Command;=0D
+=0D
+ Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG);=0D
+ Status =3D (Reg32 & 0x96FFFFFF); // Reset the one-shot bits=0D
+ Command =3D (Status | BitMask);=0D
+ MmioWrite32 (VtdUnitBaseAddress + R_GCMD_REG, Command);=0D
+=0D
+ DEBUG((DEBUG_INFO, "Set GCMD_REG bits 0x%x.\n", BitMask));=0D
+=0D
+ //=0D
+ // Poll on Status bit of Global status register to become not zero=0D
+ //=0D
+ do {=0D
+ Reg32 =3D MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG);=0D
+ } while ((Reg32 & BitMask) =3D=3D 0);=0D
+}=0D
+=0D
+/**=0D
+ Update Root Table Address Register=0D
+=0D
+ @param[in] VtdIndex The index used to identify a VTd engine.=0D
+ @param[in] EnableADM TRUE - Enable ADM in TTM bits=0D
+**/=0D
+VOID=0D
+UpdateRootTableAddressRegister (=0D
+ IN UINTN VtdIndex,=0D
+ IN BOOLEAN EnableADM=0D
+ )=0D
+{=0D
+ UINT64 Reg64;=0D
+=0D
+ if (mVtdUnitInformation[VtdIndex].ExtRootEntryTable !=3D NULL) {=0D
+ DEBUG((DEBUG_INFO, "ExtRootEntryTable 0x%x \n", mVtdUnitInformation[Vt=
dIndex].ExtRootEntryTable));=0D
+ Reg64 =3D (UINT64)(UINTN)mVtdUnitInformation[VtdIndex].ExtRootEntryTab=
le | (EnableADM ? V_RTADDR_REG_TTM_ADM : BIT11);=0D
+ } else {=0D
+ DEBUG((DEBUG_INFO, "RootEntryTable 0x%x \n", mVtdUnitInformation[VtdIn=
dex].RootEntryTable));=0D
+ Reg64 =3D (UINT64)(UINTN)mVtdUnitInformation[VtdIndex].RootEntryTable =
| (EnableADM ? V_RTADDR_REG_TTM_ADM : 0);=0D
+ }=0D
+ MmioWrite64 (mVtdUnitInformation[VtdIndex].VtdUnitBaseAddress + R_RTADDR=
_REG, Reg64);=0D
+}=0D
+=0D
/**=0D
Enable DMAR translation.=0D
=0D
@@ -488,25 +574,43 @@ EnableDmar (
{=0D
UINTN Index;=0D
UINT32 Reg32;=0D
+ UINTN VtdUnitBaseAddress;=0D
+ BOOLEAN TEWasEnabled;=0D
=0D
for (Index =3D 0; Index < mVtdUnitNumber; Index++) {=0D
- DEBUG((DEBUG_INFO, ">>>>>>EnableDmar() for engine [%d] \n", Index));=0D
+ VtdUnitBaseAddress =3D mVtdUnitInformation[Index].VtdUnitBaseAddress;=
=0D
+ DEBUG((DEBUG_INFO, ">>>>>>EnableDmar() for engine [%d] BAR [0x%x]\n", =
Index, VtdUnitBaseAddress));=0D
+=0D
+ //=0D
+ // Check TE was enabled or not.=0D
+ //=0D
+ TEWasEnabled =3D ((MmioRead32 (VtdUnitBaseAddress + R_GSTS_REG) & B_GS=
TS_REG_TE) =3D=3D B_GSTS_REG_TE);=0D
+=0D
+ if (TEWasEnabled && (mVtdUnitInformation[Index].ECapReg.Bits.ADMS =3D=
=3D 1) && PcdGetBool (PcdVTdSupportAbortDmaMode)) {=0D
+ //=0D
+ // For implementations reporting Enhanced SRTP Support (ESRTPS) fiel=
d as=0D
+ // Clear in the Capability register, software must not modify this f=
ield while=0D
+ // DMA remapping is active (TES=3D1 in Global Status register).=0D
+ //=0D
+ if (mVtdUnitInformation[Index].CapReg.Bits.ESRTPS =3D=3D 0) {=0D
+ ClearGlobalCommandRegisterBits (VtdUnitBaseAddress, B_GMCD_REG_TE)=
;=0D
+ }=0D
+=0D
+ //=0D
+ // Enable ADM=0D
+ //=0D
+ UpdateRootTableAddressRegister (Index, TRUE);=0D
+=0D
+ DEBUG((DEBUG_INFO, "Enable Abort DMA Mode...\n"));=0D
+ SetGlobalCommandRegisterBits (VtdUnitBaseAddress, B_GMCD_REG_TE);=0D
=0D
- if (mVtdUnitInformation[Index].ExtRootEntryTable !=3D NULL) {=0D
- DEBUG((DEBUG_INFO, "ExtRootEntryTable 0x%x \n", mVtdUnitInformation[=
Index].ExtRootEntryTable));=0D
- MmioWrite64 (mVtdUnitInformation[Index].VtdUnitBaseAddress + R_RTADD=
R_REG, (UINT64)(UINTN)mVtdUnitInformation[Index].ExtRootEntryTable | BIT11)=
;=0D
} else {=0D
- DEBUG((DEBUG_INFO, "RootEntryTable 0x%x \n", mVtdUnitInformation[Ind=
ex].RootEntryTable));=0D
- MmioWrite64 (mVtdUnitInformation[Index].VtdUnitBaseAddress + R_RTADD=
R_REG, (UINT64)(UINTN)mVtdUnitInformation[Index].RootEntryTable);=0D
- }=0D
+ UpdateRootTableAddressRegister (Index, FALSE);=0D
=0D
- Reg32 =3D MmioRead32 (mVtdUnitInformation[Index].VtdUnitBaseAddress + =
R_GSTS_REG);=0D
- MmioWrite32 (mVtdUnitInformation[Index].VtdUnitBaseAddress + R_GCMD_RE=
G, Reg32 | B_GMCD_REG_SRTP);=0D
+ }=0D
=0D
DEBUG((DEBUG_INFO, "EnableDmar: waiting for RTPS bit to be set... \n")=
);=0D
- do {=0D
- Reg32 =3D MmioRead32 (mVtdUnitInformation[Index].VtdUnitBaseAddress =
+ R_GSTS_REG);=0D
- } while((Reg32 & B_GSTS_REG_RTPS) =3D=3D 0);=0D
+ SetGlobalCommandRegisterBits (VtdUnitBaseAddress, B_GMCD_REG_SRTP);=0D
=0D
//=0D
// Init DMAr Fault Event and Data registers=0D
@@ -528,15 +632,19 @@ EnableDmar (
//=0D
InvalidateIOTLB (Index);=0D
=0D
+ if (TEWasEnabled && (mVtdUnitInformation[Index].ECapReg.Bits.ADMS =3D=
=3D 1) && PcdGetBool (PcdVTdSupportAbortDmaMode)) {=0D
+ if (mVtdUnitInformation[Index].CapReg.Bits.ESRTPS =3D=3D 0) {=0D
+ ClearGlobalCommandRegisterBits (VtdUnitBaseAddress, B_GMCD_REG_TE)=
;=0D
+ }=0D
+=0D
+ UpdateRootTableAddressRegister (Index, FALSE);=0D
+ }=0D
+=0D
//=0D
// Enable VTd=0D
//=0D
- Reg32 =3D MmioRead32 (mVtdUnitInformation[Index].VtdUnitBaseAddress + =
R_GSTS_REG);=0D
- MmioWrite32 (mVtdUnitInformation[Index].VtdUnitBaseAddress + R_GCMD_RE=
G, Reg32 | B_GMCD_REG_TE);=0D
- DEBUG((DEBUG_INFO, "EnableDmar: Waiting B_GSTS_REG_TE ...\n"));=0D
- do {=0D
- Reg32 =3D MmioRead32 (mVtdUnitInformation[Index].VtdUnitBaseAddress =
+ R_GSTS_REG);=0D
- } while ((Reg32 & B_GSTS_REG_TE) =3D=3D 0);=0D
+ DEBUG ((DEBUG_INFO, "EnableDmar: Waiting B_GSTS_REG_TE ...\n"));=0D
+ SetGlobalCommandRegisterBits (VtdUnitBaseAddress, B_GMCD_REG_TE);=0D
=0D
DEBUG ((DEBUG_INFO,"VTD (%d) enabled!<<<<<<\n",Index));=0D
}=0D
@@ -565,8 +673,6 @@ DisableDmar (
UINTN Index;=0D
UINTN SubIndex;=0D
UINT32 Reg32;=0D
- UINT32 Status;=0D
- UINT32 Command;=0D
=0D
for (Index =3D 0; Index < mVtdUnitNumber; Index++) {=0D
DEBUG((DEBUG_INFO, ">>>>>>DisableDmar() for engine [%d] \n", Index));=
=0D
@@ -582,32 +688,15 @@ DisableDmar (
//=0D
// Set TE (Translation Enable: BIT31) of Global command register to ze=
ro=0D
//=0D
- Reg32 =3D MmioRead32 (mVtdUnitInformation[Index].VtdUnitBaseAddress + =
R_GSTS_REG);=0D
- Status =3D (Reg32 & 0x96FFFFFF); // Reset the one-shot bits=0D
- Command =3D (Status & ~B_GMCD_REG_TE);=0D
- MmioWrite32 (mVtdUnitInformation[Index].VtdUnitBaseAddress + R_GCMD_RE=
G, Command);=0D
-=0D
- //=0D
- // Poll on TE Status bit of Global status register to become zero=0D
- //=0D
- do {=0D
- Reg32 =3D MmioRead32 (mVtdUnitInformation[Index].VtdUnitBaseAddress =
+ R_GSTS_REG);=0D
- } while ((Reg32 & B_GSTS_REG_TE) =3D=3D B_GSTS_REG_TE);=0D
+ ClearGlobalCommandRegisterBits (mVtdUnitInformation[Index].VtdUnitBase=
Address, B_GMCD_REG_TE);=0D
=0D
//=0D
// Set SRTP (Set Root Table Pointer: BIT30) of Global command register=
in order to update the root table pointerDisable VTd=0D
//=0D
- Reg32 =3D MmioRead32 (mVtdUnitInformation[Index].VtdUnitBaseAddress + =
R_GSTS_REG);=0D
- Status =3D (Reg32 & 0x96FFFFFF); // Reset the one-shot bits=0D
- Command =3D (Status | B_GMCD_REG_SRTP);=0D
- MmioWrite32 (mVtdUnitInformation[Index].VtdUnitBaseAddress + R_GCMD_RE=
G, Command);=0D
-=0D
- do {=0D
- Reg32 =3D MmioRead32 (mVtdUnitInformation[Index].VtdUnitBaseAddress =
+ R_GSTS_REG);=0D
- } while((Reg32 & B_GSTS_REG_RTPS) =3D=3D 0);=0D
+ SetGlobalCommandRegisterBits (mVtdUnitInformation[Index].VtdUnitBaseAd=
dress, B_GSTS_REG_RTPS);=0D
=0D
Reg32 =3D MmioRead32 (mVtdUnitInformation[Index].VtdUnitBaseAddress + =
R_GSTS_REG);=0D
- DEBUG((DEBUG_INFO, "DisableDmar: GSTS_REG - 0x%08x\n", Reg32));=0D
+ DEBUG ((DEBUG_INFO, "DisableDmar: GSTS_REG - 0x%08x\n", Reg32));=0D
=0D
DEBUG ((DEBUG_INFO,"VTD (%d) Disabled!<<<<<<\n",Index));=0D
=0D
diff --git a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec b/Silicon/In=
tel/IntelSiliconPkg/IntelSiliconPkg.dec
index c36d130a0..9166e599a 100644
--- a/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
+++ b/Silicon/Intel/IntelSiliconPkg/IntelSiliconPkg.dec
@@ -135,12 +135,6 @@
gIntelSiliconPkgTokenSpaceGuid.PcdFlashMicrocodeFvSize|0x000A0000|UINT32=
|0x0000000A=0D
gIntelSiliconPkgTokenSpaceGuid.PcdFlashMicrocodeFvOffset|0x00660000|UINT=
32|0x0000000B=0D
=0D
- ## Indicates if VTd Abort DMA Mode is supported.<BR><BR>=0D
- # TRUE - Support VTd abort DMA mode.=0D
- # FALSE - Not support VTd abort DMA mode.=0D
- # @Prompt VTd abort DMA mode support.=0D
- gIntelSiliconPkgTokenSpaceGuid.PcdVTdSupportAbortDmaMode|FALSE|BOOLEAN|0=
x0000000C=0D
-=0D
[PcdsFixedAtBuild, PcdsPatchableInModule]=0D
## Error code for VTd error.<BR><BR>=0D
# EDKII_ERROR_CODE_VTD_ERROR =3D (EFI_IO_BUS_UNSPECIFIED | (EFI_OEM_SPE=
CIFIC | 0x00000000)) =3D 0x02008000<BR>=0D
@@ -178,3 +172,9 @@
# @Prompt The VTd PEI DMA buffer size for S3.=0D
gIntelSiliconPkgTokenSpaceGuid.PcdVTdPeiDmaBufferSizeS3|0x00200000|UINT3=
2|0x00000004=0D
=0D
+ ## Indicates if VTd Abort DMA Mode is supported.<BR><BR>=0D
+ # TRUE - Support VTd abort DMA mode.=0D
+ # FALSE - Not support VTd abort DMA mode.=0D
+ # @Prompt VTd abort DMA mode support.=0D
+ gIntelSiliconPkgTokenSpaceGuid.PcdVTdSupportAbortDmaMode|FALSE|BOOLEAN|0=
x0000000C=0D
+=0D
--=20
2.26.2.windows.1


[PATCH V3 12/12] OvmfPkg: Call gEdkiiMemoryAcceptProtocolGuid to accept pages

Min Xu
 

From: Min M Xu <min.m.xu@...>

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

After EdkiiMemoryAcceptProtocol is implemented in TdxDxe driver, we can
call it to accept pages in DXE phase.

Cc: Erdem Aktas <erdemaktas@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Acked-by: Gerd Hoffmann <kraxel@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
.../BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf | 3 +++
.../Library/BaseMemEncryptTdxLib/MemoryEncryption.c | 12 +++++++++---
2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf b/OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf
index a8abfec12fa3..11768825f8ca 100644
--- a/OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf
+++ b/OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf
@@ -42,3 +42,6 @@

[Pcd]
gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr
+
+[Protocols]
+ gEdkiiMemoryAcceptProtocolGuid
diff --git a/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c b/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c
index 9d11c6e4df72..503f626d75c6 100644
--- a/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c
+++ b/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c
@@ -27,6 +27,8 @@
#include "VirtualMemory.h"
#include <IndustryStandard/Tdx.h>
#include <Library/TdxLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Protocol/MemoryAccept.h>
#include <ConfidentialComputingGuestAttr.h>

typedef enum {
@@ -517,8 +519,9 @@ SetOrClearSharedBit (
IN UINT64 Length
)
{
- UINT64 AddressEncMask;
- UINT64 Status;
+ UINT64 AddressEncMask;
+ UINT64 Status;
+ EDKII_MEMORY_ACCEPT_PROTOCOL *MemoryAcceptProtocol;

AddressEncMask = GetMemEncryptionAddressMask ();

@@ -539,7 +542,10 @@ SetOrClearSharedBit (
// If changing shared to private, must accept-page again
//
if (Mode == ClearSharedBit) {
- TdAcceptPages (PhysicalAddress, Length / EFI_PAGE_SIZE, EFI_PAGE_SIZE);
+ Status = gBS->LocateProtocol (&gEdkiiMemoryAcceptProtocolGuid, NULL, (VOID **)&MemoryAcceptProtocol);
+ ASSERT (!EFI_ERROR (Status));
+ Status = MemoryAcceptProtocol->AcceptMemory (MemoryAcceptProtocol, PhysicalAddress, Length);
+ ASSERT (!EFI_ERROR (Status));
}

DEBUG ((
--
2.29.2.windows.2


[PATCH V3 11/12] OvmfPkg: Realize EdkiiMemoryAcceptProtocol in TdxDxe

Min Xu
 

From: Min M Xu <min.m.xu@...>

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

Memory usage may exceed the amount accepted at the begining (SEC), TDVF
needs to accept memory dynamically when OUT_OF_RESOURCE occurs.

Another usage is in SetOrClearSharedBit. If a memory region is changed from
shared to private, it must be accepted again.

EdkiiMemoryAcceptProtocol is defined in MdePkg and is implementated /
installed in TdxDxe for Intel TDX memory acceptance.

Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Acked-by: Gerd Hoffmann <kraxel@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
OvmfPkg/TdxDxe/TdxDxe.c | 103 ++++++++++++++++++++++++++++++++++++++
OvmfPkg/TdxDxe/TdxDxe.inf | 2 +
2 files changed, 105 insertions(+)

diff --git a/OvmfPkg/TdxDxe/TdxDxe.c b/OvmfPkg/TdxDxe/TdxDxe.c
index 2318db989792..ca948522a42c 100644
--- a/OvmfPkg/TdxDxe/TdxDxe.c
+++ b/OvmfPkg/TdxDxe/TdxDxe.c
@@ -24,6 +24,7 @@
#include <Library/HobLib.h>
#include <Protocol/Cpu.h>
#include <Protocol/MpInitLibDepProtocols.h>
+#include <Protocol/MemoryAccept.h>
#include <Library/UefiBootServicesTableLib.h>
#include <ConfidentialComputingGuestAttr.h>
#include <IndustryStandard/Tdx.h>
@@ -32,6 +33,95 @@
#include <TdxAcpiTable.h>
#include <Library/MemEncryptTdxLib.h>

+#define ALIGNED_2MB_MASK 0x1fffff
+EFI_HANDLE mTdxDxeHandle = NULL;
+
+EFI_STATUS
+EFIAPI
+TdxMemoryAccept (
+ IN EDKII_MEMORY_ACCEPT_PROTOCOL *This,
+ IN EFI_PHYSICAL_ADDRESS StartAddress,
+ IN UINTN Size
+ )
+{
+ EFI_STATUS Status;
+ UINT32 AcceptPageSize;
+ UINT64 StartAddress1;
+ UINT64 StartAddress2;
+ UINT64 StartAddress3;
+ UINT64 Length1;
+ UINT64 Length2;
+ UINT64 Length3;
+ UINT64 Pages;
+
+ AcceptPageSize = FixedPcdGet32 (PcdTdxAcceptPageSize);
+ StartAddress1 = 0;
+ StartAddress2 = 0;
+ StartAddress3 = 0;
+ Length1 = 0;
+ Length2 = 0;
+ Length3 = 0;
+
+ if (Size == 0) {
+ return EFI_SUCCESS;
+ }
+
+ if (ALIGN_VALUE (StartAddress, SIZE_2MB) != StartAddress) {
+ StartAddress1 = StartAddress;
+ Length1 = ALIGN_VALUE (StartAddress, SIZE_2MB) - StartAddress;
+ if (Length1 >= Size) {
+ Length1 = Size;
+ }
+
+ StartAddress += Length1;
+ Size -= Length1;
+ }
+
+ if (Size > SIZE_2MB) {
+ StartAddress2 = StartAddress;
+ Length2 = Size & ~(UINT64)ALIGNED_2MB_MASK;
+ StartAddress += Length2;
+ Size -= Length2;
+ }
+
+ if (Size) {
+ StartAddress3 = StartAddress;
+ Length3 = Size;
+ }
+
+ Status = EFI_SUCCESS;
+ if (Length1 > 0) {
+ Pages = Length1 / SIZE_4KB;
+ Status = TdAcceptPages (StartAddress1, Pages, SIZE_4KB);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ }
+
+ if (Length2 > 0) {
+ Pages = Length2 / AcceptPageSize;
+ Status = TdAcceptPages (StartAddress2, Pages, AcceptPageSize);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ }
+
+ if (Length3 > 0) {
+ Pages = Length3 / SIZE_4KB;
+ Status = TdAcceptPages (StartAddress3, Pages, SIZE_4KB);
+ ASSERT (!EFI_ERROR (Status));
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ }
+
+ return Status;
+}
+
+EDKII_MEMORY_ACCEPT_PROTOCOL mMemoryAcceptProtocol = {
+ TdxMemoryAccept
+};
+
VOID
SetPcdSettings (
EFI_HOB_PLATFORM_INFO *PlatformInfoHob
@@ -277,6 +367,19 @@ TdxDxeEntryPoint (
NULL
);

+ //
+ // Install MemoryAccept protocol for TDX
+ //
+ Status = gBS->InstallProtocolInterface (
+ &mTdxDxeHandle,
+ &gEdkiiMemoryAcceptProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &mMemoryAcceptProtocol
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Install EdkiiMemoryAcceptProtocol failed.\n"));
+ }
+
//
// Call TDINFO to get actual number of cpus in domain
//
diff --git a/OvmfPkg/TdxDxe/TdxDxe.inf b/OvmfPkg/TdxDxe/TdxDxe.inf
index a7e0abda1522..9be021f28648 100644
--- a/OvmfPkg/TdxDxe/TdxDxe.inf
+++ b/OvmfPkg/TdxDxe/TdxDxe.inf
@@ -52,6 +52,7 @@
gEfiAcpiTableProtocolGuid ## CONSUMES
gEfiMpInitLibMpDepProtocolGuid
gEfiMpInitLibUpDepProtocolGuid
+ gEdkiiMemoryAcceptProtocolGuid

[Pcd]
gUefiOvmfPkgTokenSpaceGuid.PcdPciIoBase
@@ -68,3 +69,4 @@
gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr
gEfiMdeModulePkgTokenSpaceGuid.PcdTdxSharedBitMask
gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack
+ gUefiOvmfPkgTokenSpaceGuid.PcdTdxAcceptPageSize
--
2.29.2.windows.2


[PATCH V3 10/12] MdePkg: The prototype definition of EdkiiMemoryAcceptProtocol

Min Xu
 

From: Jiaqi Gao <jiaqi.gao@...>

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

EdkiiMemoryAcceptProtocol is defined in MdePkg, the method AcceptMemory()
can be called when memory needs to be accepted.

EdkiiMemoryAcceptProtocol can be installed by architecture-specific
drivers such as TdxDxe. This allows different isolation architectures
to realize their own low-level methods to accept memory.

Cc: Michael D Kinney <michael.d.kinney@...>
Cc: Liming Gao <gaoliming@...>
Cc: Zhiguang Liu <zhiguang.liu@...>
Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Acked-by: Gerd Hoffmann <kraxel@...>
Signed-off-by: Jiaqi Gao <jiaqi.gao@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
MdePkg/Include/Protocol/MemoryAccept.h | 37 ++++++++++++++++++++++++++
MdePkg/MdePkg.dec | 3 +++
2 files changed, 40 insertions(+)
create mode 100644 MdePkg/Include/Protocol/MemoryAccept.h

diff --git a/MdePkg/Include/Protocol/MemoryAccept.h b/MdePkg/Include/Protocol/MemoryAccept.h
new file mode 100644
index 000000000000..f7646e04d8a1
--- /dev/null
+++ b/MdePkg/Include/Protocol/MemoryAccept.h
@@ -0,0 +1,37 @@
+/** @file
+ The file provides the protocol to provide interface to accept memory.
+
+ Copyright (c) 2021 - 2022, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef MEMORY_ACCEPT_H_
+#define MEMORY_ACCEPT_H_
+
+#define EDKII_MEMORY_ACCEPT_PROTOCOL_GUID \
+ { 0x38c74800, 0x5590, 0x4db4, { 0xa0, 0xf3, 0x67, 0x5d, 0x9b, 0x8e, 0x80, 0x26 } };
+
+typedef struct _EDKII_MEMORY_ACCEPT_PROTOCOL EDKII_MEMORY_ACCEPT_PROTOCOL;
+
+/**
+ @param This A pointer to a EDKII_MEMORY_ACCEPT_PROTOCOL.
+**/
+typedef
+EFI_STATUS
+(EFIAPI *EDKII_ACCEPT_MEMORY)(
+ IN EDKII_MEMORY_ACCEPT_PROTOCOL *This,
+ IN EFI_PHYSICAL_ADDRESS StartAddress,
+ IN UINTN Size
+ );
+
+///
+/// The EDKII_MEMORY_ACCEPT_PROTOCOL provides the ability for memory services
+/// to accept memory.
+///
+struct _EDKII_MEMORY_ACCEPT_PROTOCOL {
+ EDKII_ACCEPT_MEMORY AcceptMemory;
+};
+
+extern EFI_GUID gEdkiiMemoryAcceptProtocolGuid;
+
+#endif
diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index f1ebf9e251c1..6b6bfbec29b3 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -1019,6 +1019,9 @@
gEfiPeiDelayedDispatchPpiGuid = { 0x869c711d, 0x649c, 0x44fe, { 0x8b, 0x9e, 0x2c, 0xbb, 0x29, 0x11, 0xc3, 0xe6 }}

[Protocols]
+ ## Include/Protocol/MemoryAccept.h
+ gEdkiiMemoryAcceptProtocolGuid = { 0x38c74800, 0x5590, 0x4db4, { 0xa0, 0xf3, 0x67, 0x5d, 0x9b, 0x8e, 0x80, 0x26 }}
+
## Include/Protocol/Pcd.h
gPcdProtocolGuid = { 0x11B34006, 0xD85B, 0x4D0A, { 0xA2, 0x90, 0xD5, 0xA5, 0x71, 0x31, 0x0E, 0xF7 }}

--
2.29.2.windows.2


[PATCH V3 09/12] OvmfPkg: Update ConstructFwHobList for lazy accept

Min Xu
 

From: Min M Xu <min.m.xu@...>

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

In TDVF the hob list is constructed at the memory region which is the
largest one below 4GB. After lazy accept is introduced, the
MaxAcceptedMemoryAddress (which is tha max accpeted memory address in
lazy accept) should be considered.

Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
OvmfPkg/Library/PeilessStartupLib/Hob.c | 23 ++++++++++++++++++-
.../PeilessStartupLib/PeilessStartupLib.inf | 1 +
2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/Library/PeilessStartupLib/Hob.c b/OvmfPkg/Library/PeilessStartupLib/Hob.c
index a9b92b5fbaba..884490af68fd 100644
--- a/OvmfPkg/Library/PeilessStartupLib/Hob.c
+++ b/OvmfPkg/Library/PeilessStartupLib/Hob.c
@@ -21,6 +21,7 @@
#include <Library/PlatformInitLib.h>
#include <OvmfPlatforms.h>
#include <Pi/PrePiHob.h>
+#include <WorkArea.h>
#include "PeilessStartupInternal.h"

/**
@@ -74,10 +75,13 @@ ConstructFwHobList (
)
{
EFI_PEI_HOB_POINTERS Hob;
+ EFI_PHYSICAL_ADDRESS PhysicalStart;
EFI_PHYSICAL_ADDRESS PhysicalEnd;
UINT64 ResourceLength;
EFI_PHYSICAL_ADDRESS LowMemoryStart;
UINT64 LowMemoryLength;
+ UINT64 MaxAcceptedMemoryAddress;
+ TDX_WORK_AREA *WorkArea;

ASSERT (VmmHobList != NULL);

@@ -86,14 +90,31 @@ ConstructFwHobList (
LowMemoryLength = 0;
LowMemoryStart = 0;

+ WorkArea = (TDX_WORK_AREA *)FixedPcdGet32 (PcdOvmfWorkAreaBase);
+ ASSERT (WorkArea != NULL);
+ ASSERT (WorkArea->Header.GuestType == CcGuestTypeIntelTdx);
+ MaxAcceptedMemoryAddress = WorkArea->SecTdxWorkArea.MaxAcceptedMemoryAddress;
+ if (MaxAcceptedMemoryAddress == 0) {
+ MaxAcceptedMemoryAddress = MAX_UINT64;
+ }
+
//
// Parse the HOB list until end of list or matching type is found.
//
while (!END_OF_HOB_LIST (Hob)) {
if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
- if (Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_MEMORY_UNACCEPTED) {
+ if ((Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_MEMORY_UNACCEPTED) && (Hob.ResourceDescriptor->PhysicalStart < MaxAcceptedMemoryAddress)) {
PhysicalEnd = Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength;
ResourceLength = Hob.ResourceDescriptor->ResourceLength;
+ PhysicalStart = Hob.ResourceDescriptor->PhysicalStart;
+
+ if ((PhysicalEnd >= MaxAcceptedMemoryAddress) && (PhysicalStart < MaxAcceptedMemoryAddress)) {
+ //
+ // This memory region is split into 2 parts. The left part is accepted.
+ //
+ PhysicalEnd = MaxAcceptedMemoryAddress;
+ ResourceLength = PhysicalEnd - PhysicalStart;
+ }

if (PhysicalEnd <= BASE_4GB) {
if (ResourceLength > LowMemoryLength) {
diff --git a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf b/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf
index def50b4b019e..eed9f27d3d01 100644
--- a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf
+++ b/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf
@@ -88,3 +88,4 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask ## CONSUMES
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvSize
+ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase
--
2.29.2.windows.2


[PATCH V3 08/12] OvmfPkg: Introduce lazy accept in PlatformInitLib and PlatformPei

Min Xu
 

From: Min M Xu <min.m.xu@...>

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

There are below major changes in PlatformInitLib/PlatformPei
1. ProcessHobList
The unaccepted memory is accepted if it is under 4G address.If an
EFI_RESOURCE_MEMORY_UNACCEPTED memory region is cross the 4G address,
it will be split into 2 parts and only the left one (<4G) is accepted.
The max accepted memory address is stored in Tdx workarea which will
be used in TransferTdxHobList.

Please be noted: in current stage, we only accept the memory under 4G.
We will re-visit here in the future when on-demand accept memory is
required.

2. TransferTdxHobList
Transfer the unaccepted memory hob to EFI_RESOURCE_SYSTEM_MEMORY hob
if it is accepted. As it is mentioned in 1), there may be a
EFI_RESOURCE_MEMORY_UNACCEPTED hob which only part of the memory
describes in the hob is accepted. We also handles this situation
in TransferTdxHobList.

Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
OvmfPkg/Library/PlatformInitLib/IntelTdx.c | 129 ++++++++++++++++++--
OvmfPkg/Library/PlatformInitLib/MemDetect.c | 2 +
2 files changed, 121 insertions(+), 10 deletions(-)

diff --git a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c b/OvmfPkg/Library/PlatformInitLib/IntelTdx.c
index 396b14d919d2..333c69d1a854 100644
--- a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c
+++ b/OvmfPkg/Library/PlatformInitLib/IntelTdx.c
@@ -7,6 +7,7 @@

**/

+#include <Base.h>
#include <PiPei.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
@@ -24,7 +25,8 @@
#include <WorkArea.h>
#include <ConfidentialComputingGuestAttr.h>

-#define ALIGNED_2MB_MASK 0x1fffff
+#define ALIGNED_2MB_MASK 0x1fffff
+#define MEGABYTE_SHIFT 20

/**
This function will be called to accept pages. Only BSP accepts pages.
@@ -375,11 +377,18 @@ ProcessHobList (
EFI_STATUS Status;
EFI_PEI_HOB_POINTERS Hob;
EFI_PHYSICAL_ADDRESS PhysicalEnd;
+ TDX_WORK_AREA *WorkArea;
+ UINT64 ResourceLength;
+ UINT64 AccumulateAcceptedMemory;
+ UINT64 MaxAcceptedMemoryAddress;

Status = EFI_SUCCESS;
ASSERT (VmmHobList != NULL);
Hob.Raw = (UINT8 *)VmmHobList;

+ AccumulateAcceptedMemory = 0;
+ MaxAcceptedMemoryAddress = 0;
+
//
// Parse the HOB list until end of list or matching type is found.
//
@@ -393,7 +402,16 @@ ProcessHobList (
DEBUG ((DEBUG_INFO, "ResourceLength: 0x%llx\n", Hob.ResourceDescriptor->ResourceLength));
DEBUG ((DEBUG_INFO, "Owner: %g\n\n", &Hob.ResourceDescriptor->Owner));

- PhysicalEnd = Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength;
+ PhysicalEnd = Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength;
+ ResourceLength = Hob.ResourceDescriptor->ResourceLength;
+
+ if (PhysicalEnd > SIZE_4GB) {
+ //
+ // In current stage, we only accept the memory under 4G
+ //
+ ResourceLength -= (PhysicalEnd - SIZE_4GB);
+ PhysicalEnd = SIZE_4GB;
+ }

Status = BspAcceptMemoryResourceRange (
Hob.ResourceDescriptor->PhysicalStart,
@@ -402,12 +420,25 @@ ProcessHobList (
if (EFI_ERROR (Status)) {
break;
}
+
+ AccumulateAcceptedMemory += ResourceLength;
+ MaxAcceptedMemoryAddress = PhysicalEnd;
}
}

Hob.Raw = GET_NEXT_HOB (Hob);
}

+ //
+ // Record MaxAcceptedMemoryAddress in OvmfWorkArea.
+ // This information is useful later but in SEC phase we cannot use a global
+ // variable to pass this value. So it is stored in OvmfWorkarea.
+ //
+ WorkArea = (TDX_WORK_AREA *)FixedPcdGet32 (PcdOvmfWorkAreaBase);
+ ASSERT (WorkArea != NULL);
+ ASSERT (WorkArea->Header.GuestType == CcGuestTypeIntelTdx);
+ WorkArea->SecTdxWorkArea.MaxAcceptedMemoryAddress = MaxAcceptedMemoryAddress;
+
return Status;
}

@@ -460,6 +491,74 @@ ProcessTdxHobList (
return Status;
}

+/**
+ * Build ResourceDescriptorHob for the unaccepted memory region.
+ * This memory region may be splitted into 2 parts because of lazy accept.
+ *
+ * @param Hob Point to the EFI_HOB_RESOURCE_DESCRIPTOR
+ * @param MaxAcceptedMemoryAddress The max accepted memory address
+ * @return VOID
+ */
+VOID
+BuildResourceDescriptorHobForUnacceptedMemory (
+ IN EFI_HOB_RESOURCE_DESCRIPTOR *Hob,
+ IN UINT64 MaxAcceptedMemoryAddress
+ )
+{
+ EFI_PHYSICAL_ADDRESS PhysicalStart;
+ EFI_PHYSICAL_ADDRESS PhysicalEnd;
+ UINT64 ResourceLength;
+ EFI_RESOURCE_TYPE ResourceType;
+ EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute;
+ UINT64 AcceptedResourceLength;
+
+ ASSERT (Hob->ResourceType == EFI_RESOURCE_MEMORY_UNACCEPTED);
+
+ ResourceType = EFI_RESOURCE_MEMORY_UNACCEPTED;
+ ResourceAttribute = Hob->ResourceAttribute;
+ PhysicalStart = Hob->PhysicalStart;
+ ResourceLength = Hob->ResourceLength;
+ PhysicalEnd = PhysicalStart + ResourceLength;
+
+ if (PhysicalEnd <= MaxAcceptedMemoryAddress) {
+ //
+ // This memory region has been accepted.
+ //
+ ResourceType = EFI_RESOURCE_SYSTEM_MEMORY;
+ ResourceAttribute |= (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_TESTED);
+ } else if (PhysicalStart >= MaxAcceptedMemoryAddress) {
+ //
+ // This memory region hasn't been accepted.
+ // So keep the ResourceType and ResourceAttribute unchange.
+ //
+ } else {
+ //
+ // This memory region is splitted into 2 parts:
+ // the accepted and unaccepted.
+ //
+ AcceptedResourceLength = MaxAcceptedMemoryAddress - Hob->PhysicalStart;
+
+ // We build the ResourceDescriptorHob for the accepted part.
+ // The unaccepted part will be build out side the if-else block.
+ BuildResourceDescriptorHob (
+ EFI_RESOURCE_SYSTEM_MEMORY,
+ ResourceAttribute | (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_TESTED),
+ Hob->PhysicalStart,
+ AcceptedResourceLength
+ );
+
+ PhysicalStart = Hob->PhysicalStart + AcceptedResourceLength;
+ ResourceLength -= AcceptedResourceLength;
+ }
+
+ BuildResourceDescriptorHob (
+ ResourceType,
+ ResourceAttribute,
+ PhysicalStart,
+ ResourceLength
+ );
+}
+
/**
Transfer the incoming HobList for the TD to the final HobList for Dxe.
The Hobs transferred in this function are ResourceDescriptor hob and
@@ -477,6 +576,16 @@ TransferTdxHobList (
EFI_PEI_HOB_POINTERS Hob;
EFI_RESOURCE_TYPE ResourceType;
EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute;
+ UINT64 MaxAcceptedMemoryAddress;
+ TDX_WORK_AREA *WorkArea;
+
+ WorkArea = (TDX_WORK_AREA *)FixedPcdGet32 (PcdOvmfWorkAreaBase);
+ ASSERT (WorkArea != NULL);
+ ASSERT (WorkArea->Header.GuestType == CcGuestTypeIntelTdx);
+ MaxAcceptedMemoryAddress = WorkArea->SecTdxWorkArea.MaxAcceptedMemoryAddress;
+ if (MaxAcceptedMemoryAddress == 0) {
+ MaxAcceptedMemoryAddress = MAX_UINT64;
+ }

//
// PcdOvmfSecGhcbBase is used as the TD_HOB in Tdx guest.
@@ -489,16 +598,16 @@ TransferTdxHobList (
ResourceAttribute = Hob.ResourceDescriptor->ResourceAttribute;

if (ResourceType == EFI_RESOURCE_MEMORY_UNACCEPTED) {
- ResourceType = EFI_RESOURCE_SYSTEM_MEMORY;
- ResourceAttribute |= (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_TESTED);
+ BuildResourceDescriptorHobForUnacceptedMemory (Hob.ResourceDescriptor, MaxAcceptedMemoryAddress);
+ } else {
+ BuildResourceDescriptorHob (
+ ResourceType,
+ ResourceAttribute,
+ Hob.ResourceDescriptor->PhysicalStart,
+ Hob.ResourceDescriptor->ResourceLength
+ );
}

- BuildResourceDescriptorHob (
- ResourceType,
- ResourceAttribute,
- Hob.ResourceDescriptor->PhysicalStart,
- Hob.ResourceDescriptor->ResourceLength
- );
break;
case EFI_HOB_TYPE_MEMORY_ALLOCATION:
BuildMemoryAllocationHob (
diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/PlatformInitLib/MemDetect.c
index 942eaf89cfcf..62132f9cacfa 100644
--- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c
+++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c
@@ -42,6 +42,8 @@ Module Name:

#include <Library/PlatformInitLib.h>

+#define MEGABYTE_SHIFT 20
+
VOID
EFIAPI
PlatformQemuUc32BaseInitialization (
--
2.29.2.windows.2


[PATCH V3 07/12] OvmfPkg: Add MaxAcceptedMemoryAddress in TDX work area

Min Xu
 

From: Min M Xu <min.m.xu@...>

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

In lazy-accept the MaxAcceptedMemoryAddress is needed in
TransferTdxHobList and ContructFwHobList(at PeilessStartupLib). But in
SEC phase we cannot use a global variable to pass this value. So we add
a new field (MaxAcceptedMemoryAddress) in Tdx work area.

Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
OvmfPkg/Include/WorkArea.h | 1 +
1 file changed, 1 insertion(+)

diff --git a/OvmfPkg/Include/WorkArea.h b/OvmfPkg/Include/WorkArea.h
index bf56fc4a6f65..2c2a5816b0dc 100644
--- a/OvmfPkg/Include/WorkArea.h
+++ b/OvmfPkg/Include/WorkArea.h
@@ -71,6 +71,7 @@ typedef struct _SEC_TDX_WORK_AREA {
UINT32 PageTableReady;
UINT32 Gpaw;
UINT64 HobList;
+ UINT64 MaxAcceptedMemoryAddress;
} SEC_TDX_WORK_AREA;

typedef struct _TDX_WORK_AREA {
--
2.29.2.windows.2


[PATCH V3 06/12] ShellPkg: Update shell command memmap to show unaccepted memory

Min Xu
 

From: Min M Xu <min.m.xu@...>

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

ShellCommandRunMemMap() is updated to handle the case of unaccepted
memory type.

Cc: Ray Ni <ray.ni@...>
Cc: Zhichao Gao <zhichao.gao@...>
Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Acked-by: Gerd Hoffmann <kraxel@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
.../Library/UefiShellDebug1CommandsLib/MemMap.c | 13 +++++++++++++
.../UefiShellDebug1CommandsLib.uni | 3 ++-
2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c
index 72f3c58b0970..a089953b286f 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c
@@ -26,6 +26,7 @@ STATIC CONST CHAR16 NameEfiACPIMemoryNVS[] = L"ACPIMemoryNVS";
STATIC CONST CHAR16 NameEfiMemoryMappedIO[] = L"MemoryMappedIO";
STATIC CONST CHAR16 NameEfiMemoryMappedIOPortSpace[] = L"MemoryMappedIOPortSpace";
STATIC CONST CHAR16 NameEfiPalCode[] = L"PalCode";
+STATIC CONST CHAR16 NameEfiUnacceptedMemoryType[] = L"Unaccepted";

//
// Need short names for some memory types
@@ -151,6 +152,8 @@ ShellCommandRunMemMap (
UINT64 UnusableMemoryPagesSize;
UINT64 PalCodePages;
UINT64 PalCodePagesSize;
+ UINT64 UnacceptedPages;
+ UINT64 UnacceptedPagesSize;
UINT64 PersistentPages;
UINT64 PersistentPagesSize;
BOOLEAN Sfo;
@@ -175,6 +178,7 @@ ShellCommandRunMemMap (
PalCodePages = 0;
PersistentPages = 0;
Size = 0;
+ UnacceptedPages = 0;
Descriptors = NULL;
ShellStatus = SHELL_SUCCESS;
Status = EFI_SUCCESS;
@@ -303,6 +307,11 @@ ShellCommandRunMemMap (
TotalPages += Walker->NumberOfPages;
PalCodePages += Walker->NumberOfPages;
break;
+ case EfiUnacceptedMemoryType:
+ ShellPrintHiiEx (-1, -1, NULL, (EFI_STRING_ID)(!Sfo ? STRING_TOKEN (STR_MEMMAP_LIST_ITEM) : STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiUnacceptedMemoryType, Walker->PhysicalStart, Walker->PhysicalStart+MultU64x64 (SIZE_4KB, Walker->NumberOfPages)-1, Walker->NumberOfPages, Walker->Attribute);
+ TotalPages += Walker->NumberOfPages;
+ UnacceptedPages += Walker->NumberOfPages;
+ break;
default:
//
// Shell Spec defines the SFO format.
@@ -335,6 +344,7 @@ ShellCommandRunMemMap (
MmioSpacePagesSize = MultU64x64 (SIZE_4KB, MmioSpacePages);
MmioPortPagesSize = MultU64x64 (SIZE_4KB, MmioPortPages);
PalCodePagesSize = MultU64x64 (SIZE_4KB, PalCodePages);
+ UnacceptedPagesSize = MultU64x64 (SIZE_4KB, UnacceptedPages);
PersistentPagesSize = MultU64x64 (SIZE_4KB, PersistentPages);
UnusableMemoryPagesSize = MultU64x64 (SIZE_4KB, UnusableMemoryPages);
if (!Sfo) {
@@ -368,6 +378,8 @@ ShellCommandRunMemMap (
MmioPortPagesSize,
PalCodePages,
PalCodePagesSize,
+ UnacceptedPages,
+ UnacceptedPagesSize,
AvailPages,
AvailPagesSize,
PersistentPages,
@@ -422,6 +434,7 @@ ShellCommandRunMemMap (
AcpiReclaimPagesSize,
AcpiNvsPagesSize,
PalCodePagesSize,
+ UnacceptedPagesSize,
PersistentPagesSize
);
}
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni
index 6693be26e699..b1d239ed37ea 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni
@@ -88,13 +88,14 @@
" MMIO : %,14ld Pages (%,ld Bytes)\r\n"
" MMIO_Port : %,14ld Pages (%,ld Bytes)\r\n"
" PalCode : %,14ld Pages (%,ld Bytes)\r\n"
+ " Unaccepted: %,14ld Pages (%,ld Bytes)\r\n"
" Available : %,14ld Pages (%,ld Bytes)\r\n"
" Persistent: %,14ld Pages (%,ld Bytes)\r\n"
#string STR_MEMMAP_LIST_SUMM_OTHER #language en-US " %08x : %,14ld Pages (%,ld Bytes)\r\n"
#string STR_MEMMAP_LIST_SUMM2 #language en-US " -------------- \r\n"
"Total Memory: %,14ld MB (%,ld Bytes)\r\n"
#string STR_MEMMAP_LIST_ITEM_SFO #language en-US "MemoryMap,"%s","%LX","%LX","%LX","%LX"\r\n"
-#string STR_MEMMAP_LIST_SUMM_SFO #language en-US "MemoryMapSummary,"%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld"\r\n"
+#string STR_MEMMAP_LIST_SUMM_SFO #language en-US "MemoryMapSummary,"%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld", "%Ld"\r\n"

#string STR_EFI_COMPRESS_FAIL #language en-US "Unable to compress: %r.\r\n"
#string STR_EFI_DECOMPRESS_FAIL #language en-US "Unable to decompress: %r.\r\n"
--
2.29.2.windows.2


[PATCH V3 05/12] MdeModulePkg: Update Dxe to handle unaccepted memory type

Min Xu
 

From: Min M Xu <min.m.xu@...>

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

Unaccepted memory is a kind of new memory type,
CoreInitializeGcdServices() and CoreGetMemoryMap() are updated to handle
the unaccepted memory type.

Ref: microsoft/mu_basecore@97e9c31

Cc: Jian J Wang <jian.j.wang@...>
Cc: Liming Gao <gaoliming@...>
Cc: Ray Ni <ray.ni@...>
Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 6 +++
MdeModulePkg/Core/Dxe/Mem/Page.c | 63 +++++++++++++++++++++++---------
2 files changed, 52 insertions(+), 17 deletions(-)

diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c
index 3763467bdbc0..9ba73d148af3 100644
--- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c
+++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c
@@ -8,6 +8,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent

**/

+#include <Pi/PrePiDxeCis.h>
+#include <Pi/PrePiHob.h>
#include "DxeMain.h"
#include "Gcd.h"
#include "Mem/HeapGuard.h"
@@ -103,6 +105,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdMemoryTypeNames[] = {
"MMIO ", // EfiGcdMemoryTypeMemoryMappedIo
"PersisMem", // EfiGcdMemoryTypePersistent
"MoreRelia", // EfiGcdMemoryTypeMoreReliable
+ "Unaccepte", // EFI_GCD_MEMORY_TYPE_UNACCEPTED
"Unknown " // EfiGcdMemoryTypeMaximum
};

@@ -2600,6 +2603,9 @@ CoreInitializeGcdServices (
case EFI_RESOURCE_MEMORY_RESERVED:
GcdMemoryType = EfiGcdMemoryTypeReserved;
break;
+ case EFI_RESOURCE_MEMORY_UNACCEPTED:
+ GcdMemoryType = EFI_GCD_MEMORY_TYPE_UNACCEPTED;
+ break;
case EFI_RESOURCE_IO:
GcdIoType = EfiGcdIoTypeIo;
break;
diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c
index cc0b90ac0df5..160289c1f9ec 100644
--- a/MdeModulePkg/Core/Dxe/Mem/Page.c
+++ b/MdeModulePkg/Core/Dxe/Mem/Page.c
@@ -9,6 +9,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "DxeMain.h"
#include "Imem.h"
#include "HeapGuard.h"
+#include <Pi/PrePiDxeCis.h>

//
// Entry for tracking the memory regions for each memory type to coalesce similar memory types
@@ -61,6 +62,7 @@ EFI_MEMORY_TYPE_STATISTICS mMemoryTypeStatistics[EfiMaxMemoryType + 1] = {
{ 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiMemoryMappedIOPortSpace
{ 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, TRUE }, // EfiPalCode
{ 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiPersistentMemory
+ { 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, FALSE }, // EfiUnacceptedMemoryType
{ 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE } // EfiMaxMemoryType
};

@@ -68,22 +70,23 @@ EFI_PHYSICAL_ADDRESS mDefaultMaximumAddress = MAX_ALLOC_ADDRESS;
EFI_PHYSICAL_ADDRESS mDefaultBaseAddress = MAX_ALLOC_ADDRESS;

EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1] = {
- { EfiReservedMemoryType, 0 },
- { EfiLoaderCode, 0 },
- { EfiLoaderData, 0 },
- { EfiBootServicesCode, 0 },
- { EfiBootServicesData, 0 },
- { EfiRuntimeServicesCode, 0 },
- { EfiRuntimeServicesData, 0 },
- { EfiConventionalMemory, 0 },
- { EfiUnusableMemory, 0 },
- { EfiACPIReclaimMemory, 0 },
- { EfiACPIMemoryNVS, 0 },
- { EfiMemoryMappedIO, 0 },
- { EfiMemoryMappedIOPortSpace, 0 },
- { EfiPalCode, 0 },
- { EfiPersistentMemory, 0 },
- { EfiMaxMemoryType, 0 }
+ { EfiReservedMemoryType, 0 },
+ { EfiLoaderCode, 0 },
+ { EfiLoaderData, 0 },
+ { EfiBootServicesCode, 0 },
+ { EfiBootServicesData, 0 },
+ { EfiRuntimeServicesCode, 0 },
+ { EfiRuntimeServicesData, 0 },
+ { EfiConventionalMemory, 0 },
+ { EfiUnusableMemory, 0 },
+ { EfiACPIReclaimMemory, 0 },
+ { EfiACPIMemoryNVS, 0 },
+ { EfiMemoryMappedIO, 0 },
+ { EfiMemoryMappedIOPortSpace, 0 },
+ { EfiPalCode, 0 },
+ { EfiPersistentMemory, 0 },
+ { EFI_GCD_MEMORY_TYPE_UNACCEPTED, 0 },
+ { EfiMaxMemoryType, 0 }
};
//
// Only used when load module at fixed address feature is enabled. True means the memory is alreay successfully allocated
@@ -1286,7 +1289,7 @@ CoreInternalAllocatePages (
}

if (((MemoryType >= EfiMaxMemoryType) && (MemoryType < MEMORY_TYPE_OEM_RESERVED_MIN)) ||
- (MemoryType == EfiConventionalMemory) || (MemoryType == EfiPersistentMemory))
+ (MemoryType == EfiConventionalMemory) || (MemoryType == EfiPersistentMemory) || (MemoryType == EfiUnacceptedMemoryType))
{
return EFI_INVALID_PARAMETER;
}
@@ -1961,6 +1964,32 @@ CoreGetMemoryMap (
MemoryMap = MergeMemoryMapDescriptor (MemoryMapStart, MemoryMap, Size);
}

+ if (MergeGcdMapEntry.GcdMemoryType == EFI_GCD_MEMORY_TYPE_UNACCEPTED) {
+ //
+ // Page Align GCD range is required. When it is converted to EFI_MEMORY_DESCRIPTOR,
+ // it will be recorded as page PhysicalStart and NumberOfPages.
+ //
+ ASSERT ((MergeGcdMapEntry.BaseAddress & EFI_PAGE_MASK) == 0);
+ ASSERT (((MergeGcdMapEntry.EndAddress - MergeGcdMapEntry.BaseAddress + 1) & EFI_PAGE_MASK) == 0);
+
+ //
+ // Create EFI_MEMORY_DESCRIPTOR for every Unaccepted GCD entries
+ //
+ MemoryMap->PhysicalStart = MergeGcdMapEntry.BaseAddress;
+ MemoryMap->VirtualStart = 0;
+ MemoryMap->NumberOfPages = RShiftU64 ((MergeGcdMapEntry.EndAddress - MergeGcdMapEntry.BaseAddress + 1), EFI_PAGE_SHIFT);
+ MemoryMap->Attribute = MergeGcdMapEntry.Attributes |
+ (MergeGcdMapEntry.Capabilities & (EFI_MEMORY_RP | EFI_MEMORY_WP | EFI_MEMORY_XP | EFI_MEMORY_RO |
+ EFI_MEMORY_UC | EFI_MEMORY_UCE | EFI_MEMORY_WC | EFI_MEMORY_WT | EFI_MEMORY_WB));
+ MemoryMap->Type = EfiUnacceptedMemoryType;
+
+ //
+ // Check to see if the new Memory Map Descriptor can be merged with an
+ // existing descriptor if they are adjacent and have the same attributes
+ //
+ MemoryMap = MergeMemoryMapDescriptor (MemoryMapStart, MemoryMap, Size);
+ }
+
if (Link == &mGcdMemorySpaceMap) {
//
// break loop when arrive at head.
--
2.29.2.windows.2


[PATCH V3 04/12] MdePkg: Add UEFI Unaccepted memory definition

Min Xu
 

From: Min M Xu <min.m.xu@...>

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

Plase refer to:
UEFI Spec v2.9 Table 7-5 Memory Type Usage before ExitBootServices()

Cc: Michael D Kinney <michael.d.kinney@...>
Cc: Liming Gao <gaoliming@...>
Cc: Zhiguang Liu <zhiguang.liu@...>
Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Reviewed-by: Jiewen Yao <jiewen.yao@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
MdeModulePkg/Include/Pi/PrePiDxeCis.h | 25 +++++++++++++++++++++++++
MdePkg/Include/Pi/PiDxeCis.h | 10 +++++++++-
MdePkg/Include/Uefi/UefiMultiPhase.h | 5 +++++
3 files changed, 39 insertions(+), 1 deletion(-)
create mode 100644 MdeModulePkg/Include/Pi/PrePiDxeCis.h

diff --git a/MdeModulePkg/Include/Pi/PrePiDxeCis.h b/MdeModulePkg/Include/Pi/PrePiDxeCis.h
new file mode 100644
index 000000000000..113ac37924cc
--- /dev/null
+++ b/MdeModulePkg/Include/Pi/PrePiDxeCis.h
@@ -0,0 +1,25 @@
+/** @file
+ Include file matches things in PI.
+
+Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef MDE_MODULEPKG_PRE_PI_DXE_CIS_H_
+#define MDE_MODULEPKG_PRE_PI_DXE_CIS_H_
+
+///
+/// A memory region that describes system memory that has not been accepted
+/// by a corresponding call to the underlying isolation architecture.
+///
+/// This memory region has not been defined in PI spec, so it is defined in
+/// PrePiDxeCis.h. And it is defined in the format of captial letters
+/// because only capital letters are allowed to be used for #define declarations.
+///
+/// After this memory region is defined in PI spec, it should be a value in
+/// EFI_GCD_MEMORY_TYPE in PiDxeCis.h.
+///
+#define EFI_GCD_MEMORY_TYPE_UNACCEPTED 7
+
+#endif
diff --git a/MdePkg/Include/Pi/PiDxeCis.h b/MdePkg/Include/Pi/PiDxeCis.h
index d0f2ed0e58df..27b219aa3ffa 100644
--- a/MdePkg/Include/Pi/PiDxeCis.h
+++ b/MdePkg/Include/Pi/PiDxeCis.h
@@ -56,7 +56,15 @@ typedef enum {
/// system. If all memory has the same reliability, then this bit is not used.
///
EfiGcdMemoryTypeMoreReliable,
- EfiGcdMemoryTypeMaximum
+ // ///
+ // /// A memory region that describes system memory that has not been accepted
+ // /// by a corresponding call to the underlying isolation architecture.
+ // ///
+ // /// Please be noted:
+ // /// EfiGcdMemoryTypeUnaccepted is defined in PrePiDxeCis.h because it has not been
+ // /// defined in PI spec.
+ // EfiGcdMemoryTypeUnaccepted,
+ EfiGcdMemoryTypeMaximum = 8
} EFI_GCD_MEMORY_TYPE;

///
diff --git a/MdePkg/Include/Uefi/UefiMultiPhase.h b/MdePkg/Include/Uefi/UefiMultiPhase.h
index 22bae43e36e8..7884913371a9 100644
--- a/MdePkg/Include/Uefi/UefiMultiPhase.h
+++ b/MdePkg/Include/Uefi/UefiMultiPhase.h
@@ -103,6 +103,11 @@ typedef enum {
/// however it happens to also support byte-addressable non-volatility.
///
EfiPersistentMemory,
+ ///
+ /// A memory region that describes system memory that has not been accepted
+ /// by a corresponding call to the underlying isolation architecture.
+ ///
+ EfiUnacceptedMemoryType,
EfiMaxMemoryType
} EFI_MEMORY_TYPE;

--
2.29.2.windows.2


[PATCH V3 03/12] OvmfPkg: Use EFI_RESOURCE_MEMORY_UNACCEPTED which defined in MdeModulePkg

Min Xu
 

From: Min M Xu <min.m.xu@...>

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

EFI_RESOURCE_MEMORY_UNACCEPTED is defined in MdeModulePkg. The files
which use the definition are updated as well.

Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
OvmfPkg/Library/PeilessStartupLib/Hob.c | 3 +--
OvmfPkg/Library/PlatformInitLib/IntelTdx.c | 2 +-
2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/OvmfPkg/Library/PeilessStartupLib/Hob.c b/OvmfPkg/Library/PeilessStartupLib/Hob.c
index 5fc84a809025..a9b92b5fbaba 100644
--- a/OvmfPkg/Library/PeilessStartupLib/Hob.c
+++ b/OvmfPkg/Library/PeilessStartupLib/Hob.c
@@ -20,10 +20,9 @@
#include <IndustryStandard/UefiTcgPlatform.h>
#include <Library/PlatformInitLib.h>
#include <OvmfPlatforms.h>
+#include <Pi/PrePiHob.h>
#include "PeilessStartupInternal.h"

-#define EFI_RESOURCE_MEMORY_UNACCEPTED 7
-
/**
* Construct the HobList in SEC phase.
*
diff --git a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c b/OvmfPkg/Library/PlatformInitLib/IntelTdx.c
index c6d7c8bb6e0e..396b14d919d2 100644
--- a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c
+++ b/OvmfPkg/Library/PlatformInitLib/IntelTdx.c
@@ -20,11 +20,11 @@
#include <Library/PeiServicesLib.h>
#include <Library/TdxLib.h>
#include <Library/SynchronizationLib.h>
+#include <Pi/PrePiHob.h>
#include <WorkArea.h>
#include <ConfidentialComputingGuestAttr.h>

#define ALIGNED_2MB_MASK 0x1fffff
-#define EFI_RESOURCE_MEMORY_UNACCEPTED 7

/**
This function will be called to accept pages. Only BSP accepts pages.
--
2.29.2.windows.2


[PATCH V3 02/12] MdePkg: Increase EFI_RESOURCE_MAX_MEMORY_TYPE

Min Xu
 

From: Min M Xu <min.m.xu@...>

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

EFI_RESOURCE_MEMORY_UNACCEPTED is defined for unaccepted memory.
But this defitinion has not been officially in the PI spec. Base
on the code-first we define EFI_RESOURCE_MEMORY_UNACCEPTED at
MdeModulePkg/Include/Pi/PrePiHob.h and update EFI_RESOURCE_MAX_MEMORY_TYPE
to 8. After EFI_RESOURCE_MEMORY_UNACCEPTED is officially published
in PI spec, we will re-visit here.

Cc: Michael D Kinney <michael.d.kinney@...>
Cc: Liming Gao <gaoliming@...>
Cc: Zhiguang Liu <zhiguang.liu@...>
Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Reviewed-by: Jiewen Yao <jiewen.yao@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
MdePkg/Include/Pi/PiHob.h | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/MdePkg/Include/Pi/PiHob.h b/MdePkg/Include/Pi/PiHob.h
index e9f0ab4309d1..9af2e957fee5 100644
--- a/MdePkg/Include/Pi/PiHob.h
+++ b/MdePkg/Include/Pi/PiHob.h
@@ -232,7 +232,16 @@ typedef UINT32 EFI_RESOURCE_TYPE;
#define EFI_RESOURCE_MEMORY_MAPPED_IO_PORT 0x00000004
#define EFI_RESOURCE_MEMORY_RESERVED 0x00000005
#define EFI_RESOURCE_IO_RESERVED 0x00000006
-#define EFI_RESOURCE_MAX_MEMORY_TYPE 0x00000007
+//
+// EFI_RESOURCE_MEMORY_UNACCEPTED is defined for unaccepted memory.
+// But this defitinion has not been officially in the PI spec. Base
+// on the code-first we define EFI_RESOURCE_MEMORY_UNACCEPTED at
+// MdeModulePkg/Include/Pi/PrePiHob.h and update EFI_RESOURCE_MAX_MEMORY_TYPE
+// to 8. After EFI_RESOURCE_MEMORY_UNACCEPTED is officially published
+// in PI spec, we will re-visit here.
+//
+// #define EFI_RESOURCE_MEMORY_UNACCEPTED 0x00000007
+#define EFI_RESOURCE_MAX_MEMORY_TYPE 0x00000008

///
/// A type of recount attribute type.
--
2.29.2.windows.2


[PATCH V3 01/12] MdeModulePkg: Add PrePiHob.h

Min Xu
 

From: Min M Xu <min.m.xu@...>

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

EFI_RESOURCE_MEMORY_UNACCEPTED is defined for unaccepted memory.
But this defitinion has not been officially in the PI spec. Base
on the code-first we define EFI_RESOURCE_MEMORY_UNACCEPTED at
MdeModulePkg/Include/Pi/PrePiHob.h.

Cc: Jian J Wang <jian.j.wang@...>
Cc: Liming Gao <gaoliming@...>
Cc: Ray Ni <ray.ni@...>
Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
MdeModulePkg/Include/Pi/PrePiHob.h | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
create mode 100644 MdeModulePkg/Include/Pi/PrePiHob.h

diff --git a/MdeModulePkg/Include/Pi/PrePiHob.h b/MdeModulePkg/Include/Pi/PrePiHob.h
new file mode 100644
index 000000000000..38a8f1be149d
--- /dev/null
+++ b/MdeModulePkg/Include/Pi/PrePiHob.h
@@ -0,0 +1,20 @@
+/** @file
+ HOB related definitions which has not been officially published in PI.
+
+Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef MDE_MODULEPKG_PRE_PI_HOB_H_
+#define MDE_MODULEPKG_PRE_PI_HOB_H_
+
+//
+// EFI_RESOURCE_MEMORY_UNACCEPTED is defined for unaccepted memory.
+// But this defitinion has not been officially in the PI spec. Base
+// on the code-first we define EFI_RESOURCE_MEMORY_UNACCEPTED at
+// MdeModulePkg/Include/Pi/PrePiHob.h.
+//
+#define EFI_RESOURCE_MEMORY_UNACCEPTED 0x00000007
+
+#endif
--
2.29.2.windows.2


[PATCH V3 00/12] Introduce Lazy-accept for Tdx guest

Min Xu
 

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

UnacceptedMemory is one of the four defined types of TD memory in Intel
TDX guest. TDVF must invoke TDCALL [TDG.MEM.PAGE.ACCEPT] the unaccepted
memory before use it. See [TDVF] Section 7.1.
TDVF: https://www.intel.com/content/dam/develop/external/us/en/
documents/tdx-virtual-firmware-design-guide-rev-1.01.pdf

It is a time-consuming task which impacts the boot performance badly.
One of the mitigation is the lazy-accept mechanism. That the whole system
memory is divided into 2 parts, one is accepted in bios phase, the other
is tagged as EfiGcdMemoryTypeUnaccepted and OS will handle these
"unaccepted" memories.
See "UEFI Spec v2.9 Table 7-5 Memory Type Usage before ExitBootServices()"

As the first stage we accept all the memory under 4G. Please see the
discussion in https://edk2.groups.io/g/devel/message/93086

Patch 1-4:
Introduce lazy-accept related definitions.

Patch 5-6:
Update Dxe and shell for unaccepted memory.

Patch 7 - 9:
Update OvmfPkg for unaccepted memory.

Patch 10 - 12:
Introduce EfiMemoryAcceptProtocol and realize it in TdxDxe.

Code: https://github.com/mxu9/edk2/tree/lazyaccept.v3

v3 changes:
- As the first stage we accept all the memory under 4G. See the
discussion in https://edk2.groups.io/g/devel/message/93086
- "Pool and page functions accept memory when OOM occurs" is dropped.
See the discussion in https://edk2.groups.io/g/devel/message/93086
- PlatformAdjustSystemMemorySizeBelow4gbForLazyAccep is deleted
because in current stage we accept all the memory under 4G.

v2 changes:
- Fix a typo that change EfiUnacceptedMemory to EfiUnacceptedMemoryType.
- Define EFI_GCD_MEMORY_TYPE_UNACCEPTED in PrePiDxeCis.h because it has
not been defined in PI spec.
- AllocatePages should return EFI_INVALID_PARAMETERS if input MemoryType
is EfiUnacceptedMemoryType.
- Use EDKII_ prefix instead of EFI_ prefix in the protocol name of
EDKII_MEMORY_ACCEPT_PROTOCOL_GUID. Because this protocol is not EFI
defined.
- Accept memory under 4G even if the PcdLazyAcceptPartialMemorySize is
bigger than 4G. So with this setting, even if the
PcdLazyAcceptPartialMemorySize is 0 (which means to accept all
memories), only the memory under 4G will be accepted. This is to
optimize the performance.

Cc: Zhichao Gao <zhichao.gao@...>
Cc: Michael D Kinney <michael.d.kinney@...>
Cc: Zhiguang Liu <zhiguang.liu@...>
Cc: Jian J Wang <jian.j.wang@...>
Cc: Liming Gao <gaoliming@...>
Cc: Ray Ni <ray.ni@...>
Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Signed-off-by: Jiaqi Gao <jiaqi.gao@...>
Signed-off-by: Min Xu <min.m.xu@...>

Jiaqi Gao (1):
MdePkg: The prototype definition of EdkiiMemoryAcceptProtocol

Min M Xu (11):
MdeModulePkg: Add PrePiHob.h
MdePkg: Increase EFI_RESOURCE_MAX_MEMORY_TYPE
OvmfPkg: Use EFI_RESOURCE_MEMORY_UNACCEPTED which defined in
MdeModulePkg
MdePkg: Add UEFI Unaccepted memory definition
MdeModulePkg: Update Dxe to handle unaccepted memory type
ShellPkg: Update shell command memmap to show unaccepted memory
OvmfPkg: Add MaxAcceptedMemoryAddress in TDX work area
OvmfPkg: Introduce lazy accept in PlatformInitLib and PlatformPei
OvmfPkg: Update ConstructFwHobList for lazy accept
OvmfPkg: Realize EdkiiMemoryAcceptProtocol in TdxDxe
OvmfPkg: Call gEdkiiMemoryAcceptProtocolGuid to accept pages

MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 6 +
MdeModulePkg/Core/Dxe/Mem/Page.c | 63 ++++++---
MdeModulePkg/Include/Pi/PrePiDxeCis.h | 25 ++++
MdeModulePkg/Include/Pi/PrePiHob.h | 20 +++
MdePkg/Include/Pi/PiDxeCis.h | 10 +-
MdePkg/Include/Pi/PiHob.h | 11 +-
MdePkg/Include/Protocol/MemoryAccept.h | 37 +++++
MdePkg/Include/Uefi/UefiMultiPhase.h | 5 +
MdePkg/MdePkg.dec | 3 +
OvmfPkg/Include/WorkArea.h | 1 +
.../BaseMemEncryptTdxLib.inf | 3 +
.../BaseMemEncryptTdxLib/MemoryEncryption.c | 12 +-
OvmfPkg/Library/PeilessStartupLib/Hob.c | 26 +++-
.../PeilessStartupLib/PeilessStartupLib.inf | 1 +
OvmfPkg/Library/PlatformInitLib/IntelTdx.c | 131 ++++++++++++++++--
OvmfPkg/Library/PlatformInitLib/MemDetect.c | 2 +
OvmfPkg/TdxDxe/TdxDxe.c | 103 ++++++++++++++
OvmfPkg/TdxDxe/TdxDxe.inf | 2 +
.../UefiShellDebug1CommandsLib/MemMap.c | 13 ++
.../UefiShellDebug1CommandsLib.uni | 3 +-
20 files changed, 440 insertions(+), 37 deletions(-)
create mode 100644 MdeModulePkg/Include/Pi/PrePiDxeCis.h
create mode 100644 MdeModulePkg/Include/Pi/PrePiHob.h
create mode 100644 MdePkg/Include/Protocol/MemoryAccept.h

--
2.29.2.windows.2