Date   

[PATCH v2 3/5] OvmfPkg/QemuVideoDxe: drop QEMU_VIDEO_BOCHS_MODES->ColorDepth

Gerd Hoffmann
 

All video modes in the list are 32-bit,
so drop the useless ColorDepth field.

Signed-off-by: Gerd Hoffmann <kraxel@...>
---
OvmfPkg/QemuVideoDxe/Qemu.h | 1 -
OvmfPkg/QemuVideoDxe/Initialize.c | 80 +++++++++++++++----------------
2 files changed, 39 insertions(+), 42 deletions(-)

diff --git a/OvmfPkg/QemuVideoDxe/Qemu.h b/OvmfPkg/QemuVideoDxe/Qemu.h
index fef648c967b2..1e6507f44caa 100644
--- a/OvmfPkg/QemuVideoDxe/Qemu.h
+++ b/OvmfPkg/QemuVideoDxe/Qemu.h
@@ -132,7 +132,6 @@ typedef struct {
typedef struct {
UINT32 Width;
UINT32 Height;
- UINT32 ColorDepth;
} QEMU_VIDEO_BOCHS_MODES;

#define QEMU_VIDEO_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS(a) \
diff --git a/OvmfPkg/QemuVideoDxe/Initialize.c b/OvmfPkg/QemuVideoDxe/Initialize.c
index 8a70cf848483..2b174d13faf2 100644
--- a/OvmfPkg/QemuVideoDxe/Initialize.c
+++ b/OvmfPkg/QemuVideoDxe/Initialize.c
@@ -203,43 +203,43 @@ QemuVideoCirrusModeSetup (
/// Table of supported video modes
///
STATIC QEMU_VIDEO_BOCHS_MODES QemuVideoBochsModes[] = {
- { 640, 480, 32 },
- { 800, 480, 32 },
- { 800, 600, 32 },
- { 832, 624, 32 },
- { 960, 640, 32 },
- { 1024, 600, 32 },
- { 1024, 768, 32 },
- { 1152, 864, 32 },
- { 1152, 870, 32 },
- { 1280, 720, 32 },
- { 1280, 760, 32 },
- { 1280, 768, 32 },
- { 1280, 800, 32 },
- { 1280, 960, 32 },
- { 1280, 1024, 32 },
- { 1360, 768, 32 },
- { 1366, 768, 32 },
- { 1400, 1050, 32 },
- { 1440, 900, 32 },
- { 1600, 900, 32 },
- { 1600, 1200, 32 },
- { 1680, 1050, 32 },
- { 1920, 1080, 32 },
- { 1920, 1200, 32 },
- { 1920, 1440, 32 },
- { 2000, 2000, 32 },
- { 2048, 1536, 32 },
- { 2048, 2048, 32 },
- { 2560, 1440, 32 },
- { 2560, 1600, 32 },
- { 2560, 2048, 32 },
- { 2800, 2100, 32 },
- { 3200, 2400, 32 },
- { 3840, 2160, 32 },
- { 4096, 2160, 32 },
- { 7680, 4320, 32 },
- { 8192, 4320, 32 }
+ { 640, 480 },
+ { 800, 480 },
+ { 800, 600 },
+ { 832, 624 },
+ { 960, 640 },
+ { 1024, 600 },
+ { 1024, 768 },
+ { 1152, 864 },
+ { 1152, 870 },
+ { 1280, 720 },
+ { 1280, 760 },
+ { 1280, 768 },
+ { 1280, 800 },
+ { 1280, 960 },
+ { 1280, 1024 },
+ { 1360, 768 },
+ { 1366, 768 },
+ { 1400, 1050 },
+ { 1440, 900 },
+ { 1600, 900 },
+ { 1600, 1200 },
+ { 1680, 1050 },
+ { 1920, 1080 },
+ { 1920, 1200 },
+ { 1920, 1440 },
+ { 2000, 2000 },
+ { 2048, 1536 },
+ { 2048, 2048 },
+ { 2560, 1440 },
+ { 2560, 1600 },
+ { 2560, 2048 },
+ { 2800, 2100 },
+ { 3200, 2400 },
+ { 3840, 2160 },
+ { 4096, 2160 },
+ { 7680, 4320 },
+ { 8192, 4320 }
};

#define QEMU_VIDEO_BOCHS_MODE_COUNT \
@@ -348,14 +348,12 @@ QemuVideoBochsModeSetup (
for (Index = 0; Index < QEMU_VIDEO_BOCHS_MODE_COUNT; Index++) {
UINTN RequiredFbSize;

- ASSERT (VideoMode->ColorDepth % 8 == 0);
- RequiredFbSize = (UINTN)VideoMode->Width * VideoMode->Height *
- (VideoMode->ColorDepth / 8);
+ RequiredFbSize = (UINTN)VideoMode->Width * VideoMode->Height * 4;
if (RequiredFbSize <= AvailableFbSize) {
ModeData->InternalModeIndex = Index;
ModeData->HorizontalResolution = VideoMode->Width;
ModeData->VerticalResolution = VideoMode->Height;
- ModeData->ColorDepth = VideoMode->ColorDepth;
+ ModeData->ColorDepth = 32;
DEBUG ((
DEBUG_INFO,
"Adding Mode %d as Bochs Internal Mode %d: %dx%d, %d-bit\n",
--
2.34.1


[PATCH v2 5/5] OvmfPkg/QemuVideoDxe: parse edid blob, detect display resolution

Gerd Hoffmann
 

Check whenever an EDID blob is present. In case it is get the display
resolution from it. Unless PcdVideoResolutionSource indicates the
display resolution has been set already update
PcdVideoHorizontalResolution and PcdVideoVerticalResolution accordingly.
Also add the resolution to the mode list.

This will make OVMF boot up with the display resolution configured by
QEMU, which is 1024x768 by default. The resolution can be set using the
xres and yres properties. Here is an example for FullHD:

qemu-system-x86_64 -device VGA,xres=1920,yres=1080

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3778
Ref: https://bugzilla.redhat.com/show_bug.cgi?id=1749250
Signed-off-by: Gerd Hoffmann <kraxel@...>
---
OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf | 3 +
OvmfPkg/QemuVideoDxe/Qemu.h | 2 +
OvmfPkg/QemuVideoDxe/Initialize.c | 102 +++++++++++++++++++++++++-
3 files changed, 105 insertions(+), 2 deletions(-)

diff --git a/OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf b/OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf
index fe8befd51d3c..43a6e07faa88 100644
--- a/OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf
+++ b/OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf
@@ -63,4 +63,7 @@ [Protocols]

[Pcd]
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
+ gUefiOvmfPkgTokenSpaceGuid.PcdVideoResolutionSource
gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask
+ gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution
+ gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution
diff --git a/OvmfPkg/QemuVideoDxe/Qemu.h b/OvmfPkg/QemuVideoDxe/Qemu.h
index 1e6507f44caa..57341a0bbfc4 100644
--- a/OvmfPkg/QemuVideoDxe/Qemu.h
+++ b/OvmfPkg/QemuVideoDxe/Qemu.h
@@ -115,6 +115,8 @@ typedef struct {
FRAME_BUFFER_CONFIGURE *FrameBufferBltConfigure;
UINTN FrameBufferBltConfigureSize;
UINT8 FrameBufferVramBarIndex;
+
+ UINT8 Edid[128];
} QEMU_VIDEO_PRIVATE_DATA;

///
diff --git a/OvmfPkg/QemuVideoDxe/Initialize.c b/OvmfPkg/QemuVideoDxe/Initialize.c
index 8c5c9176ad21..2a3cbc65c32a 100644
--- a/OvmfPkg/QemuVideoDxe/Initialize.c
+++ b/OvmfPkg/QemuVideoDxe/Initialize.c
@@ -284,6 +284,88 @@ QemuVideoBochsAddMode (
Private->MaxMode++;
}

+STATIC
+VOID
+QemuVideoBochsEdid (
+ QEMU_VIDEO_PRIVATE_DATA *Private,
+ UINT32 *XRes,
+ UINT32 *YRes
+ )
+{
+ EFI_STATUS Status;
+
+ if (Private->Variant != QEMU_VIDEO_BOCHS_MMIO) {
+ return;
+ }
+
+ Status = Private->PciIo->Mem.Read (
+ Private->PciIo,
+ EfiPciIoWidthUint8,
+ PCI_BAR_IDX2,
+ 0,
+ sizeof (Private->Edid),
+ Private->Edid
+ );
+ if (Status != EFI_SUCCESS) {
+ DEBUG ((
+ DEBUG_INFO,
+ "%a: mmio read failed\n",
+ __FUNCTION__
+ ));
+ return;
+ }
+
+ if ((Private->Edid[0] != 0x00) ||
+ (Private->Edid[1] != 0xff))
+ {
+ DEBUG ((
+ DEBUG_INFO,
+ "%a: magic check failed\n",
+ __FUNCTION__
+ ));
+ return;
+ }
+
+ DEBUG ((
+ DEBUG_INFO,
+ "%a: blob found (extensions: %d)\n",
+ __FUNCTION__,
+ Private->Edid[126]
+ ));
+
+ if ((Private->Edid[54] == 0x00) &&
+ (Private->Edid[55] == 0x00))
+ {
+ DEBUG ((
+ DEBUG_INFO,
+ "%a: no detailed timing descriptor\n",
+ __FUNCTION__
+ ));
+ return;
+ }
+
+ *XRes = Private->Edid[56] | ((Private->Edid[58] & 0xf0) << 4);
+ *YRes = Private->Edid[59] | ((Private->Edid[61] & 0xf0) << 4);
+ DEBUG ((
+ DEBUG_INFO,
+ "%a: default resolution: %dx%d\n",
+ __FUNCTION__,
+ *XRes,
+ *YRes
+ ));
+
+ if (PcdGet8 (PcdVideoResolutionSource) == 0) {
+ Status = PcdSet32S (PcdVideoHorizontalResolution, *XRes);
+ ASSERT_RETURN_ERROR (Status);
+ Status = PcdSet32S (PcdVideoVerticalResolution, *YRes);
+ ASSERT_RETURN_ERROR (Status);
+ Status = PcdSet8S (PcdVideoResolutionSource, 2);
+ ASSERT_RETURN_ERROR (Status);
+ }
+
+ // TODO: register edid as gEfiEdidDiscoveredProtocolGuid ?
+}
+
EFI_STATUS
QemuVideoBochsModeSetup (
QEMU_VIDEO_PRIVATE_DATA *Private,
@@ -291,7 +373,7 @@ QemuVideoBochsModeSetup (
)
{
UINT32 AvailableFbSize;
- UINT32 Index;
+ UINT32 Index, XRes = 0, YRes = 0;

//
// Fetch the available framebuffer size.
@@ -374,13 +456,29 @@ QemuVideoBochsModeSetup (
// Setup Video Modes
//
Private->ModeData = AllocatePool (
- sizeof (Private->ModeData[0]) * QEMU_VIDEO_BOCHS_MODE_COUNT
+ sizeof (Private->ModeData[0]) * (QEMU_VIDEO_BOCHS_MODE_COUNT+1)
);
if (Private->ModeData == NULL) {
return EFI_OUT_OF_RESOURCES;
}

+ QemuVideoBochsEdid (Private, &XRes, &YRes);
+ if (XRes && YRes) {
+ QemuVideoBochsAddMode (
+ Private,
+ AvailableFbSize,
+ XRes,
+ YRes
+ );
+ }
+
for (Index = 0; Index < QEMU_VIDEO_BOCHS_MODE_COUNT; Index++) {
+ if ((QemuVideoBochsModes[Index].Width == XRes) &&
+ (QemuVideoBochsModes[Index].Height == YRes))
+ {
+ continue; // duplicate with edid resolution
+ }
+
QemuVideoBochsAddMode (
Private,
AvailableFbSize,
--
2.34.1


[PATCH v2 2/5] OvmfPkg/QemuVideoDxe: simplify InitializeBochsGraphicsMode

Gerd Hoffmann
 

struct QEMU_VIDEO_MODE_DATA has all the data needed to set the video
mode, there is no need to take the extra indirection and use
struct QEMU_VIDEO_BOCHS_MODES.

Signed-off-by: Gerd Hoffmann <kraxel@...>
---
OvmfPkg/QemuVideoDxe/Qemu.h | 3 +--
OvmfPkg/QemuVideoDxe/Driver.c | 14 +++++++-------
OvmfPkg/QemuVideoDxe/Gop.c | 2 +-
OvmfPkg/QemuVideoDxe/Initialize.c | 2 +-
4 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/OvmfPkg/QemuVideoDxe/Qemu.h b/OvmfPkg/QemuVideoDxe/Qemu.h
index 8f05898f862c..fef648c967b2 100644
--- a/OvmfPkg/QemuVideoDxe/Qemu.h
+++ b/OvmfPkg/QemuVideoDxe/Qemu.h
@@ -150,7 +150,6 @@ extern UINT16 Seq_800_600_256_60[];
extern UINT8 Crtc_1024_768_256_60[];
extern UINT16 Seq_1024_768_256_60[];
extern QEMU_VIDEO_CIRRUS_MODES QemuVideoCirrusModes[];
-extern QEMU_VIDEO_BOCHS_MODES QemuVideoBochsModes[];
extern EFI_DRIVER_BINDING_PROTOCOL gQemuVideoDriverBinding;
extern EFI_COMPONENT_NAME_PROTOCOL gQemuVideoComponentName;
extern EFI_COMPONENT_NAME2_PROTOCOL gQemuVideoComponentName2;
@@ -414,7 +413,7 @@ InitializeCirrusGraphicsMode (
VOID
InitializeBochsGraphicsMode (
QEMU_VIDEO_PRIVATE_DATA *Private,
- QEMU_VIDEO_BOCHS_MODES *ModeData
+ QEMU_VIDEO_MODE_DATA *ModeData
);

VOID
diff --git a/OvmfPkg/QemuVideoDxe/Driver.c b/OvmfPkg/QemuVideoDxe/Driver.c
index d9f0a2464aa3..b91909a14e59 100644
--- a/OvmfPkg/QemuVideoDxe/Driver.c
+++ b/OvmfPkg/QemuVideoDxe/Driver.c
@@ -987,14 +987,14 @@ VgaOutb (
VOID
InitializeBochsGraphicsMode (
QEMU_VIDEO_PRIVATE_DATA *Private,
- QEMU_VIDEO_BOCHS_MODES *ModeData
+ QEMU_VIDEO_MODE_DATA *ModeData
)
{
DEBUG ((
DEBUG_INFO,
"InitializeBochsGraphicsMode: %dx%d @ %d\n",
- ModeData->Width,
- ModeData->Height,
+ ModeData->HorizontalResolution,
+ ModeData->VerticalResolution,
ModeData->ColorDepth
));

@@ -1007,10 +1007,10 @@ InitializeBochsGraphicsMode (
BochsWrite (Private, VBE_DISPI_INDEX_Y_OFFSET, 0);

BochsWrite (Private, VBE_DISPI_INDEX_BPP, (UINT16)ModeData->ColorDepth);
- BochsWrite (Private, VBE_DISPI_INDEX_XRES, (UINT16)ModeData->Width);
- BochsWrite (Private, VBE_DISPI_INDEX_VIRT_WIDTH, (UINT16)ModeData->Width);
- BochsWrite (Private, VBE_DISPI_INDEX_YRES, (UINT16)ModeData->Height);
- BochsWrite (Private, VBE_DISPI_INDEX_VIRT_HEIGHT, (UINT16)ModeData->Height);
+ BochsWrite (Private, VBE_DISPI_INDEX_XRES, (UINT16)ModeData->HorizontalResolution);
+ BochsWrite (Private, VBE_DISPI_INDEX_VIRT_WIDTH, (UINT16)ModeData->HorizontalResolution);
+ BochsWrite (Private, VBE_DISPI_INDEX_YRES, (UINT16)ModeData->VerticalResolution);
+ BochsWrite (Private, VBE_DISPI_INDEX_VIRT_HEIGHT, (UINT16)ModeData->VerticalResolution);

BochsWrite (
Private,
diff --git a/OvmfPkg/QemuVideoDxe/Gop.c b/OvmfPkg/QemuVideoDxe/Gop.c
index 5ad0afe88378..0c4dea7fb6f2 100644
--- a/OvmfPkg/QemuVideoDxe/Gop.c
+++ b/OvmfPkg/QemuVideoDxe/Gop.c
@@ -177,7 +177,7 @@ Routine Description:
break;
case QEMU_VIDEO_BOCHS_MMIO:
case QEMU_VIDEO_BOCHS:
- InitializeBochsGraphicsMode (Private, &QemuVideoBochsModes[ModeData->InternalModeIndex]);
+ InitializeBochsGraphicsMode (Private, ModeData);
break;
default:
ASSERT (FALSE);
diff --git a/OvmfPkg/QemuVideoDxe/Initialize.c b/OvmfPkg/QemuVideoDxe/Initialize.c
index 533ec661d64f..8a70cf848483 100644
--- a/OvmfPkg/QemuVideoDxe/Initialize.c
+++ b/OvmfPkg/QemuVideoDxe/Initialize.c
@@ -202,7 +202,7 @@ QemuVideoCirrusModeSetup (
///
/// Table of supported video modes
///
-QEMU_VIDEO_BOCHS_MODES QemuVideoBochsModes[] = {
+STATIC QEMU_VIDEO_BOCHS_MODES QemuVideoBochsModes[] = {
{ 640, 480, 32 },
{ 800, 480, 32 },
{ 800, 600, 32 },
--
2.34.1


[PATCH v2 0/5] OvmfPkg/QemuVideoDxe: pick up display resolution settings from the host

Gerd Hoffmann
 

See last patch in the series for details.

v2:
- rebase to latest master
- more verbose commit message explaining the
motivation for the new PCD (see patch #1).

Gerd Hoffmann (5):
OvmfPkg: add PcdVideoResolutionSource
OvmfPkg/QemuVideoDxe: simplify InitializeBochsGraphicsMode
OvmfPkg/QemuVideoDxe: drop QEMU_VIDEO_BOCHS_MODES->ColorDepth
OvmfPkg/QemuVideoDxe: factor out QemuVideoBochsAddMode
OvmfPkg/QemuVideoDxe: parse edid blob, detect display resolution

OvmfPkg/OvmfPkg.dec | 7 +
OvmfPkg/AmdSev/AmdSevX64.dsc | 1 +
OvmfPkg/Microvm/MicrovmX64.dsc | 1 +
OvmfPkg/OvmfPkgIa32.dsc | 1 +
OvmfPkg/OvmfPkgIa32X64.dsc | 1 +
OvmfPkg/OvmfPkgX64.dsc | 1 +
OvmfPkg/OvmfXen.dsc | 1 +
OvmfPkg/PlatformDxe/Platform.inf | 1 +
OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf | 3 +
OvmfPkg/QemuVideoDxe/Qemu.h | 6 +-
OvmfPkg/PlatformDxe/Platform.c | 3 +
OvmfPkg/QemuVideoDxe/Driver.c | 14 +-
OvmfPkg/QemuVideoDxe/Gop.c | 2 +-
OvmfPkg/QemuVideoDxe/Initialize.c | 251 +++++++++++++++++++-------
14 files changed, 213 insertions(+), 80 deletions(-)

--
2.34.1


[PATCH v2 1/5] OvmfPkg: add PcdVideoResolutionSource

Gerd Hoffmann
 

It's a UINT8 (enum) PCD telling where the PcdVideoHorizontalResolution
and PcdVideoVerticalResolution values are coming from. It can be:

0 (unset aka default from dsc file), or
1 (from PlatformConfig), or
2 (set by Video Driver).

It will be used by video drivers to avoid overriding PlatformConfig
values, or override each others values in case multiple display devices
are present.

The underlying problem this tries to solve is that the GOP protocol has
no way to indicate the preferred video mode. On physical hardware this
isn't much of a problem because using the highest resolution available
works just fine as that is typically the native display resolution

But in a virtual machine you don't want come up with a huge 4k window by
default just because the virtual vga is able to handle that. Cutting
down the video mode list isn't a great solution either as that would
also remove the modes from the platform configuration so the user
wouldn't be able to pick a resolution higher than the default any more.

So with patch drivers can use use PcdVideoHorizontalResolution and
PcdVideoVerticalResolution to indicate what the preferred display
resolution is, without overwriting the user preferences from
PlatformConfig if present.

A possible alternative approach would be to extend the GOP protocol, but
I'm not sure this is a good plan given this is mostly a problem for
virtual machines and using PCDs allows to keep this local to OvmfPkg.

Signed-off-by: Gerd Hoffmann <kraxel@...>
---
OvmfPkg/OvmfPkg.dec | 7 +++++++
OvmfPkg/AmdSev/AmdSevX64.dsc | 1 +
OvmfPkg/Microvm/MicrovmX64.dsc | 1 +
OvmfPkg/OvmfPkgIa32.dsc | 1 +
OvmfPkg/OvmfPkgIa32X64.dsc | 1 +
OvmfPkg/OvmfPkgX64.dsc | 1 +
OvmfPkg/OvmfXen.dsc | 1 +
OvmfPkg/PlatformDxe/Platform.inf | 1 +
OvmfPkg/PlatformDxe/Platform.c | 3 +++
9 files changed, 17 insertions(+)

diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index 769bef0ffa12..7aa94ca02863 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -408,6 +408,13 @@ [PcdsDynamic, PcdsDynamicEx]
# instance in PiSmmCpuDxeSmm, and CpuHotplugSmm.
gUefiOvmfPkgTokenSpaceGuid.PcdCpuHotEjectDataAddress|0|UINT64|0x46

+ ## This PCD tracks where PcdVideo{Horizontal,Vertical}Resolution
+ # values are coming from.
+ # 0 - unset (defaults from platform dsc)
+ # 1 - set from PlatformConfig
+ # 2 - set by GOP Driver.
+ gUefiOvmfPkgTokenSpaceGuid.PcdVideoResolutionSource|0|UINT8|0x64
+
[PcdsFeatureFlag]
gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderPciTranslation|TRUE|BOOLEAN|0x1c
gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderMmioTranslation|FALSE|BOOLEAN|0x1d
diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc
index 04ae61cf69d8..343ac643f021 100644
--- a/OvmfPkg/AmdSev/AmdSevX64.dsc
+++ b/OvmfPkg/AmdSev/AmdSevX64.dsc
@@ -527,6 +527,7 @@ [PcdsDynamicDefault]
gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution|800
gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution|600
gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable|FALSE
+ gUefiOvmfPkgTokenSpaceGuid.PcdVideoResolutionSource|0
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId|0
gUefiOvmfPkgTokenSpaceGuid.PcdPciIoBase|0x0
gUefiOvmfPkgTokenSpaceGuid.PcdPciIoSize|0x0
diff --git a/OvmfPkg/Microvm/MicrovmX64.dsc b/OvmfPkg/Microvm/MicrovmX64.dsc
index 1c2e600febee..cb28bd8bba2c 100644
--- a/OvmfPkg/Microvm/MicrovmX64.dsc
+++ b/OvmfPkg/Microvm/MicrovmX64.dsc
@@ -560,6 +560,7 @@ [PcdsDynamicDefault]
gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution|800
gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution|600
gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable|FALSE
+ gUefiOvmfPkgTokenSpaceGuid.PcdVideoResolutionSource|0
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId|0
gUefiOvmfPkgTokenSpaceGuid.PcdPciIoBase|0x0
gUefiOvmfPkgTokenSpaceGuid.PcdPciIoSize|0x0
diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index 085cc7ece15d..2f05d93ed4af 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -590,6 +590,7 @@ [PcdsDynamicDefault]
gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution|800
gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution|600
gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable|FALSE
+ gUefiOvmfPkgTokenSpaceGuid.PcdVideoResolutionSource|0
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId|0
gUefiOvmfPkgTokenSpaceGuid.PcdPciIoBase|0x0
gUefiOvmfPkgTokenSpaceGuid.PcdPciIoSize|0x0
diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index 0ce122ddb50c..bcab54aaa02a 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -596,6 +596,7 @@ [PcdsDynamicDefault]
gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution|800
gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution|600
gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable|FALSE
+ gUefiOvmfPkgTokenSpaceGuid.PcdVideoResolutionSource|0
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId|0
gUefiOvmfPkgTokenSpaceGuid.PcdPciIoBase|0x0
gUefiOvmfPkgTokenSpaceGuid.PcdPciIoSize|0x0
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index 4589adff388d..ee0fdf492fd4 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -595,6 +595,7 @@ [PcdsDynamicDefault]
gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution|800
gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution|600
gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable|FALSE
+ gUefiOvmfPkgTokenSpaceGuid.PcdVideoResolutionSource|0
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId|0
gUefiOvmfPkgTokenSpaceGuid.PcdPciIoBase|0x0
gUefiOvmfPkgTokenSpaceGuid.PcdPciIoSize|0x0
diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index de0d30bfb807..1f6352195b75 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -468,6 +468,7 @@ [PcdsDynamicDefault]
gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution|800
gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution|600
gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable|FALSE
+ gUefiOvmfPkgTokenSpaceGuid.PcdVideoResolutionSource|0
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId|0
gUefiOvmfPkgTokenSpaceGuid.PcdPciIoBase|0x0
gUefiOvmfPkgTokenSpaceGuid.PcdPciIoSize|0x0
diff --git a/OvmfPkg/PlatformDxe/Platform.inf b/OvmfPkg/PlatformDxe/Platform.inf
index 14727c1220e8..d2f75d78b601 100644
--- a/OvmfPkg/PlatformDxe/Platform.inf
+++ b/OvmfPkg/PlatformDxe/Platform.inf
@@ -47,6 +47,7 @@ [LibraryClasses]
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution
gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution
+ gUefiOvmfPkgTokenSpaceGuid.PcdVideoResolutionSource

[Protocols]
gEfiDevicePathProtocolGuid ## PRODUCES
diff --git a/OvmfPkg/PlatformDxe/Platform.c b/OvmfPkg/PlatformDxe/Platform.c
index 69a7ecb83d03..4bf22712c78f 100644
--- a/OvmfPkg/PlatformDxe/Platform.c
+++ b/OvmfPkg/PlatformDxe/Platform.c
@@ -742,6 +742,9 @@ ExecutePlatformConfig (
PlatformConfig.VerticalResolution
);
ASSERT_RETURN_ERROR (PcdStatus);
+
+ PcdStatus = PcdSet8S (PcdVideoResolutionSource, 1);
+ ASSERT_RETURN_ERROR (PcdStatus);
}

return EFI_SUCCESS;
--
2.34.1


[Patch V2] UefiPayloadPkg: Change the user interface name of the Uiapp

Yuanhao Xie
 

Chanage the name "Uiapp" to "Enter Setup".

Cc: Guo Dong <guo.dong@...>
Cc: Ray Ni <ray.ni@...>
Cc: Maurice Ma <maurice.ma@...>
Cc: Benjamin You <benjamin.you@...>
Signed-off-by: Yuanhao Xie <yuanhao.xie@...>
---
UefiPayloadPkg/UefiPayloadPkg.fdf | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/UefiPayloadPkg/UefiPayloadPkg.fdf b/UefiPayloadPkg/UefiPayloadPkg.fdf
index f619a23139..c7b04978ad 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.fdf
+++ b/UefiPayloadPkg/UefiPayloadPkg.fdf
@@ -104,7 +104,7 @@ INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
!endif
INF UefiCpuPkg/CpuDxe/CpuDxe.inf
INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
-INF MdeModulePkg/Application/UiApp/UiApp.inf
+INF RuleOverride = UI MdeModulePkg/Application/UiApp/UiApp.inf
INF MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenuApp.inf
INF PcAtChipsetPkg/HpetTimerDxe/HpetTimerDxe.inf
INF MdeModulePkg/Universal/Metronome/Metronome.inf
@@ -357,3 +357,10 @@ INF ShellPkg/Application/Shell/Shell.inf
FILE RAW = $(NAMED_GUID) {
RAW RAW |.raw
}
+
+[Rule.Common.UEFI_APPLICATION.UI]
+ FILE APPLICATION = $(NAMED_GUID) {
+ PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi
+ UI STRING="Enter Setup"
+ VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
+ }
--
2.30.0.windows.1


[Wiki V2] Wiki: Add optional steps for developer to run CI test before sending

Zhiguang Liu
 

V2: Add the step to join in https://edk2.groups.io/g/devel and wait for
approval when first sending patch.

Cc: Liming Gao <gaoliming@...>
Signed-off-by: Zhiguang Liu <zhiguang.liu@...>
---
EDK-II-Development-Process.md | 69 +++++++++++++++++++++++++++++++++++++++=
+++++++++++++-----------------
1 file changed, 52 insertions(+), 17 deletions(-)

diff --git a/EDK-II-Development-Process.md b/EDK-II-Development-Process.md
index 469a979..d02baa7 100644
--- a/EDK-II-Development-Process.md
+++ b/EDK-II-Development-Process.md
@@ -59,20 +59,50 @@ The developer process for the EDK II project
=20
`$ git rebase origin/master`
=20
-9. Run the automated code formatting tool (Uncrustify) against your change=
s=0D
-=0D
- - [EDK-II-Code-Formatting](EDK-II-Code-Formatting "wikilink")=0D
-=0D
- - The changes must pass local CI which includes a code formatting check=
=0D
- in order to be merged into the code base.=0D
-=0D
- - It is strongly recommended that you format the code after each commit=
.=0D
- The code can then be easily amended with the formatted output. Some=0D
- developers might also prefer to format frequently while writing the=0D
- code using the plugin instructions described in the code formatting=0D
- wiki page.=0D
-=0D
-10. Create patch (serial) to the [[edk2-devel]] mailing list=0D
+9. Run the automated code formatting tool (Uncrustify) against your changes
+
+ - [EDK-II-Code-Formatting](EDK-II-Code-Formatting "wikilink")
+
+ - The changes must pass local CI which includes a code formatting check
+ in order to be merged into the code base.
+
+ - It is strongly recommended that you format the code after each commit.
+ The code can then be easily amended with the formatted output. Some
+ developers might also prefer to format frequently while writing the
+ code using the plugin instructions described in the code formatting
+ wiki page.
+
+10. (Optional) Push changes to the developer's fork of the EDK II project
+ repository.
+
+ - How to create a [GitHub fork](https://help.github.com/en/github/gett=
ing-started-with-github/fork-a-repo)
+ - **NOTE:** A GitHub fork can also be created using the command line
+ utility called [`hub`](https://github.com/github/hub/releases). T=
he
+ `hub` usage information can be found [here](https://hub.github.com=
/hub.1.html).
+
+ - Add remote to the developer's fork of the EDK II project
+
+ `$ git remote add <developer-id> https://github.com/<developer-id>/edk=
2.git`
+
+ - Push the integration branch.
+
+ `$ git push <developer-id> <new-integration-branch>`
+
+11. (Optional) Create a GitHub pull request from the developer's
+ <new-integration-branch> to edk2/master to run CI check.
+
+ - How to create a [GitHub pull request](https://help.github.com/en/git=
hub/collaborating-with-issues-and-pull-requests/creating-a-pull-request)
+ - **NOTE:** A GitHub pull request can also be created using the comm=
and
+ line utility called [`hub`](https://github.com/github/hub/releases=
).
+ The `hub` usage information can be found [here](https://hub.github=
.com/hub.1.html).
+
+ - Declare that it is for CI check test in the pull request title and
+ description.
+
+ - Resolve GitHub pull request issues if it fails. Please refrence step=
8
+ in the below **The maintainer process for the EDK II project**
+
+12. Create patch (serial) to the [[edk2-devel]] mailing list
=20
- Clean out any old patches: `$ rm *.patch`
=20
@@ -84,10 +114,15 @@ The developer process for the EDK II project
- Add the `--subject-prefix=3D"PATCH v2"` if you are sending out a
second version of the patch series.
=20
- - `$ git send-email *.patch`
+ - `$ git send-email *.patch --to devel@edk2.groups.io`
+
+ - If it is the first time to send mail to edk2 mail list, please join
+ https://edk2.groups.io/g/devel and expect there will be delay because
+ the mail needs manual approval from the admin (gaoliming@...=
.cn
+ or michael.d.kinney@...) of https://edk2.groups.io/g/devel
=20
-11. Modify local commits based on the review feedbacks and repeat steps=0D
- 3 to 9
+13. Modify local commits based on the review feedbacks and repeat steps
+ 3 to 11
=20
- For the latest commit, you can use `$ git commit --amend`
=20
--=20
2.32.0.windows.2


Re: [PATCH] MdeModulePkg/HiiDatabaseDxe: Add Support for authenticated variable

Dandan Bi
 

Sure. Thanks Liming.


Thanks,
Dandan

-----Original Message-----
From: gaoliming <gaoliming@...>
Sent: Monday, January 17, 2022 11:12 AM
To: devel@edk2.groups.io; Bi, Dandan <dandan.bi@...>; Huang,
Long1 <long1.huang@...>
Cc: Feng, Bob C <bob.c.feng@...>; Chen, Lin Z <lin.z.chen@...>;
Li, Zhuangzhi <zhuangzhi.li@...>
Subject: 回复: [edk2-devel] [PATCH] MdeModulePkg/HiiDatabaseDxe: Add
Support for authenticated variable

Dandan:
I will review this patch today. Please wait one day for me.

Thanks
Liming
-----邮件原件-----
发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Dandan Bi
发送时间: 2022年1月17日 9:13
收件人: Huang, Long1 <long1.huang@...>; devel@edk2.groups.io
抄送: Feng, Bob C <bob.c.feng@...>; Gao, Liming
<gaoliming@...>; Chen, Lin Z <lin.z.chen@...>; Li,
Zhuangzhi <zhuangzhi.li@...>
主题: Re: [edk2-devel] [PATCH] MdeModulePkg/HiiDatabaseDxe: Add
Support
for authenticated variable

I will push this patch today if no other comment.


Thanks,
Dandan

-----Original Message-----
From: Bi, Dandan
Sent: Thursday, January 13, 2022 1:35 PM
To: Huang, Long1 <long1.huang@...>; devel@edk2.groups.io
Cc: Feng, Bob C <bob.c.feng@...>; Gao, Liming
<gaoliming@...>; Chen, Lin Z <lin.z.chen@...>; Li,
Zhuangzhi <zhuangzhi.li@...>
Subject: RE: [PATCH] MdeModulePkg/HiiDatabaseDxe: Add Support for
authenticated variable

The change is ok to me. Reviewed-by: Dandan Bi <dandan.bi@...>

Hi Liming,

Could you also help review it?


Thanks,
Dandan
-----Original Message-----
From: Huang, Long1 <long1.huang@...>
Sent: Thursday, January 13, 2022 1:06 AM
To: devel@edk2.groups.io
Cc: Huang, Long1 <long1.huang@...>; Feng, Bob C
<bob.c.feng@...>; Gao, Liming <gaoliming@...>;
Bi, Dandan <dandan.bi@...>; Chen, Lin Z
<lin.z.chen@...>; Li, Zhuangzhi <zhuangzhi.li@...>
Subject: [PATCH] MdeModulePkg/HiiDatabaseDxe: Add Support for
authenticated variable

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

Database.c:
1. Replace PcdGetExPtr with PcdGetExPtr.
2. Add FindAuthVariableData function to parse authenticated
variable
type for getting a correct default value in
PcdNvStoreDefaultValueBuffer.

Signed-off-by: Huang Long <long1.huang@...>

Cc: Bob Feng <bob.c.feng@...>
Cc: Liming Gao <gaoliming@...>
Cc: Dandan Bi <dandan.bi@...>
Cc: Lin Z Chen <lin.z.chen@...>
Cc: Zhuangzhi Li <zhuangzhi.li@...>
---
.../Universal/HiiDatabaseDxe/Database.c | 130
++++++++++++++----
.../HiiDatabaseDxe/HiiDatabaseDxe.inf | 3 +
2 files changed, 105 insertions(+), 28 deletions(-)

diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
index 0b09c24d52..c7a92d6aed 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
@@ -603,6 +603,45 @@ FindVariableData (
return NULL;

}



+/**

+ Find the matched authenticated variable from the input variable
storage.

+

+ @param[in] VariableStorage Point to the variable storage header.

+ @param[in] VarGuid A unique identifier for the variable.

+ @param[in] VarAttribute The attributes bitmask for the variable.

+ @param[in] VarName A Null-terminated ascii string that is
the name
of
the variable.

+

+ @return Pointer to the matched variable header or NULL if not
found.

+**/

+AUTHENTICATED_VARIABLE_HEADER *

+FindAuthVariableData (

+ IN VARIABLE_STORE_HEADER *VariableStorage,

+ IN EFI_GUID *VarGuid,

+ IN UINT32 VarAttribute,

+ IN CHAR16 *VarName

+ )

+{

+ AUTHENTICATED_VARIABLE_HEADER *AuthVariableHeader;

+ AUTHENTICATED_VARIABLE_HEADER *AuthVariableEnd;

+

+ AuthVariableEnd = (AUTHENTICATED_VARIABLE_HEADER
*)((UINT8
*)VariableStorage + VariableStorage->Size);

+ AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER
*)(VariableStorage + 1);

+ AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER
*)HEADER_ALIGN (AuthVariableHeader);

+ while (AuthVariableHeader < AuthVariableEnd) {

+ if (CompareGuid (&AuthVariableHeader->VendorGuid, VarGuid) &&

+ (AuthVariableHeader->Attributes == VarAttribute) &&

+ (StrCmp (VarName, (CHAR16 *)(AuthVariableHeader + 1)) ==
0))

+ {

+ return AuthVariableHeader;

+ }

+

+ AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER
*)((UINT8
*)AuthVariableHeader + sizeof (AUTHENTICATED_VARIABLE_HEADER)
+
AuthVariableHeader->NameSize + AuthVariableHeader->DataSize);

+ AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER
*)HEADER_ALIGN (AuthVariableHeader);

+ }

+

+ return NULL;

+}

+

/**

Find question default value from PcdNvStoreDefaultValueBuffer



@@ -626,25 +665,29 @@ FindQuestionDefaultSetting (
IN BOOLEAN BitFieldQuestion

)

{

- VARIABLE_HEADER *VariableHeader;

- VARIABLE_STORE_HEADER *VariableStorage;

- LIST_ENTRY *Link;

- VARSTORAGE_DEFAULT_DATA *Entry;

- VARIABLE_STORE_HEADER *NvStoreBuffer;

- UINT8 *DataBuffer;

- UINT8 *BufferEnd;

- BOOLEAN IsFound;

- UINTN Index;

- UINT32 BufferValue;

- UINT32 BitFieldVal;

- UINTN BitOffset;

- UINTN ByteOffset;

- UINTN BitWidth;

- UINTN StartBit;

- UINTN EndBit;

- PCD_DEFAULT_DATA *DataHeader;

- PCD_DEFAULT_INFO *DefaultInfo;

- PCD_DATA_DELTA *DeltaData;

+ VARIABLE_HEADER *VariableHeader;

+ AUTHENTICATED_VARIABLE_HEADER *AuthVariableHeader;

+ VARIABLE_STORE_HEADER *VariableStorage;

+ LIST_ENTRY *Link;

+ VARSTORAGE_DEFAULT_DATA *Entry;

+ VARIABLE_STORE_HEADER *NvStoreBuffer;

+ VOID *ValueSource;

+ VOID *BitValueSource;

+ UINT8 *DataBuffer;

+ UINT8 *BufferEnd;

+ BOOLEAN AuthFormat;

+ BOOLEAN IsFound;

+ UINTN Index;

+ UINT32 BufferValue;

+ UINT32 BitFieldVal;

+ UINTN BitOffset;

+ UINTN ByteOffset;

+ UINTN BitWidth;

+ UINTN StartBit;

+ UINTN EndBit;

+ PCD_DEFAULT_DATA *DataHeader;

+ PCD_DEFAULT_INFO *DefaultInfo;

+ PCD_DATA_DELTA *DeltaData;



if (gSkuId == 0xFFFFFFFFFFFFFFFF) {

gSkuId = LibPcdGetSku ();

@@ -666,7 +709,7 @@ FindQuestionDefaultSetting (
}



if (Link == &gVarStorageList) {

- DataBuffer = (UINT8 *)PcdGetPtr
(PcdNvStoreDefaultValueBuffer);

+ DataBuffer = (UINT8 *)PcdGetExPtr
(&gEfiMdeModulePkgTokenSpaceGuid,
PcdNvStoreDefaultValueBuffer);

gNvDefaultStoreSize =
((PCD_NV_STORE_DEFAULT_BUFFER_HEADER
*)DataBuffer)->Length;

//

// The first section data includes NV storage default setting.

@@ -750,12 +793,27 @@ FindQuestionDefaultSetting (
return EFI_NOT_FOUND;

}



+ //

+ // Judge if the variable type is authenticated, default is
+ false

+ //

+ AuthFormat = FALSE;

+ if (CompareGuid (&VariableStorage->Signature,
&gEfiAuthenticatedVariableGuid)) {

+ AuthFormat = TRUE;

+ }

+

//

// Find the question default value from the variable storage

//

- VariableHeader = FindVariableData (VariableStorage,
&EfiVarStore->Guid,
EfiVarStore->Attributes, (CHAR16 *)EfiVarStore->Name);

- if (VariableHeader == NULL) {

- return EFI_NOT_FOUND;

+ if(AuthFormat) {

+ AuthVariableHeader = FindAuthVariableData (VariableStorage,
&EfiVarStore->Guid, EfiVarStore->Attributes, (CHAR16
*)EfiVarStore-
Name);
+ if (AuthVariableHeader == NULL) {

+ return EFI_NOT_FOUND;

+ }

+ } else {

+ VariableHeader = FindVariableData (VariableStorage,
+ &EfiVarStore->Guid,
EfiVarStore->Attributes, (CHAR16 *)EfiVarStore->Name);

+ if (VariableHeader == NULL) {

+ return EFI_NOT_FOUND;

+ }

}



StartBit = 0;

@@ -770,8 +828,24 @@ FindQuestionDefaultSetting (
Width = EndBit / 8 + 1;

}



- if (VariableHeader->DataSize < ByteOffset + Width) {

- return EFI_INVALID_PARAMETER;

+ if (AuthFormat) {

+ if (AuthVariableHeader->DataSize < ByteOffset + Width) {

+ return EFI_INVALID_PARAMETER;

+ }

+

+ ValueSource = (UINT8 *)AuthVariableHeader + sizeof
(AUTHENTICATED_VARIABLE_HEADER) + AuthVariableHeader-
NameSize
+
IfrQuestionHdr->VarStoreInfo.VarOffset;

+ if (BitFieldQuestion) {

+ BitValueSource = (UINT8 *)AuthVariableHeader + sizeof
(AUTHENTICATED_VARIABLE_HEADER) + AuthVariableHeader-
NameSize
+
ByteOffset;

+ }

+ } else {

+ if (VariableHeader->DataSize < ByteOffset + Width) {

+ return EFI_INVALID_PARAMETER;

+ }

+

+ ValueSource = (UINT8 *)VariableHeader + sizeof
(VARIABLE_HEADER)
+ +
VariableHeader->NameSize + IfrQuestionHdr->VarStoreInfo.VarOffset;

+ if (BitFieldQuestion) {

+ BitValueSource = (UINT8 *)VariableHeader + sizeof
+ (VARIABLE_HEADER)
+ VariableHeader->NameSize + ByteOffset;

+ }

}



//

@@ -779,11 +853,11 @@ FindQuestionDefaultSetting (
//

if (ValueBuffer != NULL) {

if (BitFieldQuestion) {

- CopyMem (&BufferValue, (UINT8 *)VariableHeader + sizeof
(VARIABLE_HEADER) + VariableHeader->NameSize + ByteOffset,
Width);

+ CopyMem (&BufferValue, BitValueSource, Width);

BitFieldVal = BitFieldRead32 (BufferValue, StartBit,
EndBit);

CopyMem (ValueBuffer, &BitFieldVal, Width);

} else {

- CopyMem (ValueBuffer, (UINT8 *)VariableHeader + sizeof
(VARIABLE_HEADER) + VariableHeader->NameSize + IfrQuestionHdr-
VarStoreInfo.VarOffset, Width);
+ CopyMem (ValueBuffer, ValueSource, Width);

}

}



@@ -832,7 +906,7 @@ UpdateDefaultSettingInFormPackage (
// If no default setting, do nothing

//

if (gNvDefaultStoreSize == 0) {

- gNvDefaultStoreSize = PcdGetSize (PcdNvStoreDefaultValueBuffer);

+ gNvDefaultStoreSize = PcdGetExSize
(&gEfiMdeModulePkgTokenSpaceGuid,
PcdNvStoreDefaultValueBuffer);

}



if (gNvDefaultStoreSize < sizeof
(PCD_NV_STORE_DEFAULT_BUFFER_HEADER)) {

diff --git
a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
index 0116fb6ecb..dac4d614a8 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
@@ -86,6 +86,9 @@
gEfiHiiImageDecoderNameJpegGuid
|gEfiMdeModulePkgTokenSpaceGuid.PcdSupportHiiImageProtocol ##
SOMETIMES_CONSUMES ## GUID

gEfiHiiImageDecoderNamePngGuid
|gEfiMdeModulePkgTokenSpaceGuid.PcdSupportHiiImageProtocol ##
SOMETIMES_CONSUMES ## GUID

gEdkiiIfrBitVarstoreGuid
##
SOMETIMES_CONSUMES ## GUID

+ gEfiAuthenticatedVariableGuid

+ gEfiVariableGuid

+ gEfiMdeModulePkgTokenSpaceGuid



[Depex]

TRUE

--
2.25.1




Re: [PATCH] BaseTools/GenFw: Enhance to add export table in PE-COFF

Huang, Li-Xia <lisa.huang@...>
 

Hi Bob,

 

Thanks for your comments.

 

1.  I will add the help information for "--PRM";

2.

@@ -750,7 +818,7 @@ ScanSections64 (

     if (shdr->sh_addralign <= mCoffAlignment) {

       continue;

     }

-    if (IsTextShdr(shdr) || IsDataShdr(shdr) || IsHiiRsrcShdr(shdr)) {

+    if (IsTextShdr(shdr) || IsDataShdr(shdr) || IsHiiRsrcShdr(shdr) || IsSymbolShdr(shdr)) {

       mCoffAlignment = (UINT32)shdr->sh_addralign;

     }

   }

 

1) Above change is to Set mCoffAlignment to the maximum alignment of the input sections including symbol section.

    The symbol section will only exist with below change, so it should have no effect to other drivers.

 

build_rule.template:

    <Command.GCC>

        $(CP) ${src} $(DEBUG_DIR)(+)$(MODULE_NAME).debug

        #$(OBJCOPY) --strip-unneeded -R .eh_frame ${src}

        $(OBJCOPY) $(OBJCOPY_STRIPFLAG) ${src}

 

tools_def.template:

*_*_*_OBJCOPY_STRIPFLAG            = --strip-unneeded -R .eh_frame

 

PrmAddrTransDsm.inf:

[BuildOptions.common]

...

  GCC: *_*_*_OBJCOPY_STRIPFLAG == -R .eh_frame

 

2) For PRM driver, sh_addralign of symbol section is 8, and less than other sections such as Text and Data (sh_addralign is 4096).

 

 

Regards,

Lisa

 

-----Original Message-----
From: Feng, Bob C <bob.c.feng@...>
Sent: 2022114 14:12
To: Huang, Li-Xia <lisa.huang@...>; devel@edk2.groups.io
Cc: Gao, Liming <gaoliming@...>; Chen, Christine <yuwei.chen@...>
Subject: RE: [edk2-devel][PATCH] BaseTools/GenFw: Enhance to add export table in PE-COFF

 

Hi Lixia,

 

This patch introduce a new command line option --PRM. Could you add the help information about --PRM?

 

Could you provide more information about the below change? Would there be side-effect?

 

@@ -750,7 +818,7 @@ ScanSections64 (

     if (shdr->sh_addralign <= mCoffAlignment) {

       continue;

     }

-    if (IsTextShdr(shdr) || IsDataShdr(shdr) || IsHiiRsrcShdr(shdr)) {

+    if (IsTextShdr(shdr) || IsDataShdr(shdr) || IsHiiRsrcShdr(shdr) || IsSymbolShdr(shdr)) {

       mCoffAlignment = (UINT32)shdr->sh_addralign;

     }

   }

 

 

 

Thanks,

Bob

 

-----Original Message-----

From: Huang, Li-Xia <lisa.huang@...>

Sent: Wednesday, January 12, 2022 3:44 PM

To: devel@edk2.groups.io

Cc: Huang, Li-Xia <lisa.huang@...>; Gao, Liming <gaoliming@...>; Feng, Bob C <bob.c.feng@...>; Chen, Christine <yuwei.chen@...>

Subject: [edk2-devel][PATCH] BaseTools/GenFw: Enhance to add export table in PE-COFF

 

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

Since PRM module needs to support export table in PE-COFF, we'll enhance GenFw tool to support this.

 

Add one export flag in GenFw tool. If export flag is set:

Step1: Scan ELF symbol table based on PRM module descriptor to get descriptor offset address;

Step2: Find PRM handlers number and name in COFF file based on the address from step1;

Step3: Write PRM info such as handler name and export RVA into COFF export table.

 

Cc: Liming Gao <gaoliming@...>

Cc: Bob Feng <bob.c.feng@...>

Cc: Yuwei Chen <yuwei.chen@...>

Signed-off-by: Lixia Huang <lisa.huang@...>

---

BaseTools/Source/C/GenFw/Elf64Convert.c       | 254 +++++++++++++++++-

BaseTools/Source/C/GenFw/ElfConvert.c         |  10 +

BaseTools/Source/C/GenFw/ElfConvert.h         |  42 ++-

BaseTools/Source/C/GenFw/GenFw.c              |  11 +-

.../C/Include/IndustryStandard/PeImage.h      |   7 +

5 files changed, 318 insertions(+), 6 deletions(-)

 

diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/GenFw/Elf64Convert.c

index 0bb3ead228..0079507356 100644

--- a/BaseTools/Source/C/GenFw/Elf64Convert.c

+++ b/BaseTools/Source/C/GenFw/Elf64Convert.c

@@ -56,6 +56,18 @@ WriteDebug64 (

   VOID   ); +STATIC+VOID+ScanSymbol64 (+  VOID+  );++STATIC+VOID+WriteExport64 (+  VOID+  );+ STATIC VOID SetImageSize64 (@@ -122,7 +134,7 @@ STATIC UINT32 mDataOffset;

STATIC UINT32 mHiiRsrcOffset; STATIC UINT32 mRelocOffset; STATIC UINT32 mDebugOffset;-+STATIC UINT32 mExportOffset; // // Used for RISC-V relocations. //@@ -132,6 +144,14 @@ STATIC Elf64_Half  mRiscVPass1SymSecIndex = 0;

STATIC INT32       mRiscVPass1Offset; STATIC INT32       mRiscVPass1GotFixup; +//+// Used for Export section.+//+STATIC UINT32      mExportSize;+STATIC UINT32      mExportRVA[PRM_MODULE_EXPORT_SYMBOL_NUM];+STATIC UINT32      mExportSymNum;+STATIC CHAR8       mExportSymName[PRM_MODULE_EXPORT_SYMBOL_NUM][PRM_HANDLER_NAME_MAXIMUM_LENGTH];+ // // Initialization Function //@@ -200,6 +220,10 @@ InitializeElf64 (

   ElfFunctions->SetImageSize = SetImageSize64;   ElfFunctions->CleanUp = CleanUp64; +  if (mExportFlag) {+    ElfFunctions->ScanSymbol = ScanSymbol64;+    ElfFunctions->WriteExport = WriteExport64;+  }   return TRUE; } @@ -263,6 +287,17 @@ IsHiiRsrcShdr (

   return (BOOLEAN) (strcmp((CHAR8*)mEhdr + Namedr->sh_offset + Shdr->sh_name, ELF_HII_SECTION_NAME) == 0); } +STATIC+BOOLEAN+IsSymbolShdr (+  Elf_Shdr *Shdr+  )+{+  Elf_Shdr *Namehdr = GetShdrByIndex(mEhdr->e_shstrndx);++  return (BOOLEAN) (strcmp((CHAR8*)mEhdr + Namehdr->sh_offset + Shdr->sh_name, ELF_SYMBOL_SECTION_NAME) == 0);+}+ STATIC BOOLEAN IsDataShdr (@@ -335,6 +370,38 @@ GetSymName (

   return StrtabContents + Sym->st_name; } +//+// Get Prm Handler number and name+//+STATIC+VOID+FindPrmHandler (+  UINT64 Offset+  )+{+  PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT_HEADER *PrmExport;+  UINT32   NameOffset;+  UINT32   HandlerNum;+  UINT32   Index;+  UINT8    SymName[PRM_HANDLER_NAME_MAXIMUM_LENGTH];++  PrmExport = (PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT_HEADER*)(mCoffFile + Offset);+  NameOffset = sizeof(PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT_HEADER) + sizeof(EFI_GUID);++  for (HandlerNum = 0; HandlerNum < PrmExport->NumberPrmHandlers; HandlerNum++) {+    for (Index = 0; Index < PRM_HANDLER_NAME_MAXIMUM_LENGTH; Index++) {+      SymName[Index] = *((UINT8 *)PrmExport + NameOffset + Index);+      if (SymName[Index] == 0) {+        break;+      }+    }++    strcpy(mExportSymName[mExportSymNum], (CHAR8*)SymName);+    NameOffset += PRM_HANDLER_NAME_MAXIMUM_LENGTH + sizeof(EFI_GUID);+    mExportSymNum ++;+  }+}+ // // Find the ELF section hosting the GOT from an ELF Rva //   of a single GOT entry.  Normally, GOT is placed in@@ -717,6 +784,7 @@ ScanSections64 (

   UINT32                          CoffEntry;   UINT32                          SectionCount;   BOOLEAN                         FoundSection;+  UINT32                          Offset;    CoffEntry = 0;   mCoffOffset = 0;@@ -750,7 +818,7 @@ ScanSections64 (

     if (shdr->sh_addralign <= mCoffAlignment) {       continue;     }-    if (IsTextShdr(shdr) || IsDataShdr(shdr) || IsHiiRsrcShdr(shdr)) {+    if (IsTextShdr(shdr) || IsDataShdr(shdr) || IsHiiRsrcShdr(shdr) || IsSymbolShdr(shdr)) {       mCoffAlignment = (UINT32)shdr->sh_addralign;     }   }@@ -880,6 +948,16 @@ ScanSections64 (

     Warning (NULL, 0, 0, NULL, "Multiple sections in %s are merged into 1 data section. Source level debug might not work correctly.", mInImageName);   } +  //+  //  The Symbol sections.+  //+  if (mExportFlag) {+    mExportOffset = mCoffOffset;+    mExportSize = sizeof(EFI_IMAGE_EXPORT_DIRECTORY) + strlen(mInImageName) + 1;+    mCoffOffset += mExportSize;+    mCoffOffset = CoffAlign(mCoffOffset);+  }+   //   //  The HII resource sections.   //@@ -962,7 +1040,11 @@ ScanSections64 (

     | EFI_IMAGE_FILE_LARGE_ADDRESS_AWARE;    NtHdr->Pe32Plus.OptionalHeader.SizeOfCode = mDataOffset - mTextOffset;-  NtHdr->Pe32Plus.OptionalHeader.SizeOfInitializedData = mRelocOffset - mDataOffset;+  if(mExportFlag) {+    NtHdr->Pe32Plus.OptionalHeader.SizeOfInitializedData = mRelocOffset - mExportOffset;+  } else {+    NtHdr->Pe32Plus.OptionalHeader.SizeOfInitializedData = mRelocOffset - mDataOffset;+  }   NtHdr->Pe32Plus.OptionalHeader.SizeOfUninitializedData = 0;   NtHdr->Pe32Plus.OptionalHeader.AddressOfEntryPoint = CoffEntry; @@ -989,8 +1071,17 @@ ScanSections64 (

     NtHdr->Pe32Plus.FileHeader.NumberOfSections--;   } +  //+  // If found symbol, add edata section between data and rsrc section+  //+  if(mExportFlag) {+    Offset = mExportOffset;+  } else {+    Offset = mHiiRsrcOffset;+  }+   if ((mHiiRsrcOffset - mDataOffset) > 0) {-    CreateSectionHeader (".data", mDataOffset, mHiiRsrcOffset - mDataOffset,+    CreateSectionHeader (".data", mDataOffset, Offset - mDataOffset,             EFI_IMAGE_SCN_CNT_INITIALIZED_DATA             | EFI_IMAGE_SCN_MEM_WRITE             | EFI_IMAGE_SCN_MEM_READ);@@ -999,6 +1090,20 @@ ScanSections64 (

     NtHdr->Pe32Plus.FileHeader.NumberOfSections--;   } +  if(mExportFlag) {+    if ((mHiiRsrcOffset - mExportOffset) > 0) {+      CreateSectionHeader (".edata", mExportOffset, mHiiRsrcOffset - mExportOffset,+              EFI_IMAGE_SCN_CNT_INITIALIZED_DATA+              | EFI_IMAGE_SCN_MEM_READ);+      NtHdr->Pe32Plus.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_EXPORT].Size = mHiiRsrcOffset - mExportOffset;+      NtHdr->Pe32Plus.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress = mExportOffset;+      NtHdr->Pe32Plus.FileHeader.NumberOfSections++;+    } else {+      // Don't make a section of size 0.+      NtHdr->Pe32Plus.FileHeader.NumberOfSections--;+    }+  }+   if ((mRelocOffset - mHiiRsrcOffset) > 0) {     CreateSectionHeader (".rsrc", mHiiRsrcOffset, mRelocOffset - mHiiRsrcOffset,             EFI_IMAGE_SCN_CNT_INITIALIZED_DATA@@ -1757,4 +1862,145 @@ CleanUp64 (

   } } +STATIC+VOID+ScanSymbol64 (+  VOID+  )+{+  UINT32      shIndex;+  UINT32      SymIndex;+  Elf_Sym     *Sym;+  UINT64      SymNum;+  const UINT8 *SymName;++  for (shIndex = 0; shIndex < mEhdr->e_shnum; shIndex++) {+    //+    // Determine if this is a symbol section.+    //+    Elf_Shdr *shdr = GetShdrByIndex(shIndex);+    if (!IsSymbolShdr(shdr)) {+      continue;+    }++    UINT8    *Symtab = (UINT8*)mEhdr + shdr->sh_offset;+    SymNum = (shdr->sh_size) / (shdr->sh_entsize);++    //+    // First Get PrmModuleExportDescriptor+    //+    for (SymIndex = 0; SymIndex < SymNum; SymIndex++) {+      Sym = (Elf_Sym *)(Symtab + SymIndex * shdr->sh_entsize);+      SymName = GetSymName(Sym);+      if (SymName == NULL) {+          continue;+      }++      if (strcmp((CHAR8*)SymName, PRM_MODULE_EXPORT_DESCRIPTOR_NAME) == 0) {+        //+        // Find PrmHandler Number and Name+        //+        FindPrmHandler(Sym->st_value);++        strcpy(mExportSymName[mExportSymNum], (CHAR8*)SymName);+        mExportRVA[mExportSymNum] = (UINT32)(Sym->st_value);+        mExportSize += 2 * EFI_IMAGE_EXPORT_ADDR_SIZE + EFI_IMAGE_EXPORT_ORDINAL_SIZE + strlen((CHAR8 *)SymName) + 1;+        mExportSymNum ++;+        break;+      }+    }++    //+    // Second Get PrmHandler+    //+    for (SymIndex = 0; SymIndex < SymNum; SymIndex++) {+      UINT32   ExpIndex;+      Sym = (Elf_Sym *)(Symtab + SymIndex * shdr->sh_entsize);+      SymName = GetSymName(Sym);+      if (SymName == NULL) {+          continue;+      }++      for (ExpIndex = 0; ExpIndex < (mExportSymNum -1); ExpIndex++) {+        if (strcmp((CHAR8*)SymName, mExportSymName[ExpIndex]) != 0) {+          continue;+        }+        mExportRVA[ExpIndex] = (UINT32)(Sym->st_value);+        mExportSize += 2 * EFI_IMAGE_EXPORT_ADDR_SIZE + EFI_IMAGE_EXPORT_ORDINAL_SIZE + strlen((CHAR8 *)SymName) + 1;+      }+    }++    break;+  }+}++STATIC+VOID+WriteExport64 (+  VOID+  )+{+  EFI_IMAGE_OPTIONAL_HEADER_UNION     *NtHdr;+  EFI_IMAGE_EXPORT_DIRECTORY          *ExportDir;+  EFI_IMAGE_DATA_DIRECTORY            *DataDir;+  UINT32                              FileNameOffset;+  UINT32                              FuncOffset;+  UINT16                              Index;+  UINT8                               *Tdata = NULL;++  ExportDir = (EFI_IMAGE_EXPORT_DIRECTORY*)(mCoffFile + mExportOffset);+  ExportDir->Characteristics = 0;+  ExportDir->TimeDateStamp = 0;+  ExportDir->MajorVersion = 0;+  ExportDir->MinorVersion =0;+  ExportDir->Name = 0;+  ExportDir->NumberOfFunctions = mExportSymNum;+  ExportDir->NumberOfNames = mExportSymNum;+  ExportDir->Base = EFI_IMAGE_EXPORT_ORDINAL_BASE;+  ExportDir->AddressOfFunctions = mExportOffset + sizeof(EFI_IMAGE_EXPORT_DIRECTORY);+  ExportDir->AddressOfNames = ExportDir->AddressOfFunctions + EFI_IMAGE_EXPORT_ADDR_SIZE * mExportSymNum;+  ExportDir->AddressOfNameOrdinals = ExportDir->AddressOfNames + EFI_IMAGE_EXPORT_ADDR_SIZE * mExportSymNum;++  FileNameOffset = ExportDir->AddressOfNameOrdinals + EFI_IMAGE_EXPORT_ORDINAL_SIZE * mExportSymNum;+  FuncOffset = FileNameOffset + strlen(mInImageName) + 1;++  // Write Input image Name RVA+  Tdata = mCoffFile + 12;+  *(UINT32 *)Tdata = FileNameOffset;++  // Write Input image Name+  strcpy((char *)(mCoffFile + FileNameOffset), mInImageName);++  for (Index = 0; Index < mExportSymNum; Index++) {+    //+    // Write Export Address Table+    //+    Tdata = mCoffFile + ExportDir->AddressOfFunctions + Index * EFI_IMAGE_EXPORT_ADDR_SIZE;+    *(UINT32 *)Tdata = mExportRVA[Index];++    //+    // Write Export Name Pointer Table+    //+    Tdata = mCoffFile + ExportDir->AddressOfNames + Index * EFI_IMAGE_EXPORT_ADDR_SIZE;+    *(UINT32 *)Tdata = FuncOffset;++    //+    // Write Export Ordinal table+    //+    Tdata = mCoffFile + ExportDir->AddressOfNameOrdinals + Index * EFI_IMAGE_EXPORT_ORDINAL_SIZE;+    *(UINT16 *)Tdata = Index;++    //+    // Write Export Name Table+    //+    strcpy((char *)(mCoffFile + FuncOffset), mExportSymName[Index]);+    FuncOffset += strlen(mExportSymName[Index]) + 1;+  }++  NtHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)(mCoffFile + mNtHdrOffset);+  DataDir = &NtHdr->Pe32Plus.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_EXPORT];+  DataDir->VirtualAddress = mExportOffset;+  DataDir->Size = mExportSize;++} diff --git a/BaseTools/Source/C/GenFw/ElfConvert.c b/BaseTools/Source/C/GenFw/ElfConvert.c

index 7db8721167..795cdbd743 100644

--- a/BaseTools/Source/C/GenFw/ElfConvert.c

+++ b/BaseTools/Source/C/GenFw/ElfConvert.c

@@ -223,6 +223,16 @@ ConvertElf (

   VerboseMsg ("Write debug info.");   ElfFunctions.WriteDebug (); +  //+  // For PRM Driver to Write export info.+  //+  if (mExportFlag) {+    VerboseMsg ("Scan symbol info.");+    ElfFunctions.ScanSymbol ();+    VerboseMsg ("Write export info.");+    ElfFunctions.WriteExport ();+  }+   //   // Make sure image size is correct before returning the new image.   //diff --git a/BaseTools/Source/C/GenFw/ElfConvert.h b/BaseTools/Source/C/GenFw/ElfConvert.h

index 801e8de4a2..7920765fbb 100644

--- a/BaseTools/Source/C/GenFw/ElfConvert.h

+++ b/BaseTools/Source/C/GenFw/ElfConvert.h

@@ -24,6 +24,7 @@ extern UINT8  *mCoffFile;  extern UINT32 mTableOffset; extern UINT32 mOutImageType; extern UINT32 mFileBufferSize;+extern BOOLEAN mExportFlag;  // // Common EFI specific data.@@ -31,6 +32,42 @@ extern UINT32 mFileBufferSize;

#define ELF_HII_SECTION_NAME ".hii" #define ELF_STRTAB_SECTION_NAME ".strtab" #define MAX_COFF_ALIGNMENT 0x10000+#define ELF_SYMBOL_SECTION_NAME ".symtab"++//+// Platform Runtime Mechanism (PRM) specific data.+//+#define PRM_MODULE_EXPORT_SYMBOL_NUM 10+#define PRM_HANDLER_NAME_MAXIMUM_LENGTH 128++#define PRM_MODULE_EXPORT_DESCRIPTOR_NAME         "PrmModuleExportDescriptor"+#define PRM_MODULE_EXPORT_DESCRIPTOR_SIGNATURE    SIGNATURE_64 ('P', 'R', 'M', '_', 'M', 'E', 'D', 'T')+#define PRM_MODULE_EXPORT_REVISION                0x0++//+// Platform Runtime Mechanism (PRM) Export Descriptor Structures+//+#pragma pack(push, 1)++typedef struct {+  EFI_GUID                              PrmHandlerGuid;+  CHAR8                                 PrmHandlerName[PRM_HANDLER_NAME_MAXIMUM_LENGTH];+} PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT;++typedef struct {+  UINT64                                Signature;+  UINT16                                Revision;+  UINT16                                NumberPrmHandlers;+  EFI_GUID                              PlatformGuid;+  EFI_GUID                              ModuleGuid;+} PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT_HEADER;++typedef struct {+  PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT_HEADER  Header;+  PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT        PrmHandlerExportDescriptors[1];+} PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT;++#pragma pack(pop)  // // Filter Types@@ -38,7 +75,8 @@ extern UINT32 mFileBufferSize;

typedef enum {   SECTION_TEXT,   SECTION_HII,-  SECTION_DATA+  SECTION_DATA,+  SECTION_SYMBOL  } SECTION_FILTER_TYPES; @@ -50,6 +88,8 @@ typedef struct {

   BOOLEAN (*WriteSections) (SECTION_FILTER_TYPES  FilterType);   VOID    (*WriteRelocations) ();   VOID    (*WriteDebug) ();+  VOID    (*ScanSymbol) ();+  VOID    (*WriteExport) ();   VOID    (*SetImageSize) ();   VOID    (*CleanUp) (); diff --git a/BaseTools/Source/C/GenFw/GenFw.c b/BaseTools/Source/C/GenFw/GenFw.c

index 8cab70ba4d..c7de5b89d8 100644

--- a/BaseTools/Source/C/GenFw/GenFw.c

+++ b/BaseTools/Source/C/GenFw/GenFw.c

@@ -87,7 +87,7 @@ UINT32 mImageTimeStamp = 0;

UINT32 mImageSize = 0; UINT32 mOutImageType = FW_DUMMY_IMAGE; BOOLEAN mIsConvertXip = FALSE;-+BOOLEAN mExportFlag = FALSE;  STATIC EFI_STATUS@@ -1436,6 +1436,15 @@ Returns:

       continue;     } +    if (stricmp (argv[0], "--PRM") == 0) {+      if (!mExportFlag) {+        mExportFlag = TRUE;+      }+      argc --;+      argv ++;+      continue;+    }+     if (argv[0][0] == '-') {       Error (NULL, 0, 1000, "Unknown option", argv[0]);       goto Finish;diff --git a/BaseTools/Source/C/Include/IndustryStandard/PeImage.h b/BaseTools/Source/C/Include/IndustryStandard/PeImage.h

index f17b8ee19b..21c968e650 100644

--- a/BaseTools/Source/C/Include/IndustryStandard/PeImage.h

+++ b/BaseTools/Source/C/Include/IndustryStandard/PeImage.h

@@ -571,6 +571,13 @@ typedef struct {

   UINT32  AddressOfNameOrdinals; } EFI_IMAGE_EXPORT_DIRECTORY; +//+// Based export types.+//+#define EFI_IMAGE_EXPORT_ORDINAL_BASE     1+#define EFI_IMAGE_EXPORT_ADDR_SIZE        4+#define EFI_IMAGE_EXPORT_ORDINAL_SIZE     2+ /// /// DLL support. /// Import Format--

2.26.2.windows.1

 


回复: [edk2-devel] [PATCH] MdeModulePkg/HiiDatabaseDxe: Add Support for authenticated variable

gaoliming
 

Dandan:
I will review this patch today. Please wait one day for me.

Thanks
Liming
-----邮件原件-----
发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Dandan Bi
发送时间: 2022年1月17日 9:13
收件人: Huang, Long1 <long1.huang@...>; devel@edk2.groups.io
抄送: Feng, Bob C <bob.c.feng@...>; Gao, Liming
<gaoliming@...>; Chen, Lin Z <lin.z.chen@...>; Li,
Zhuangzhi <zhuangzhi.li@...>
主题: Re: [edk2-devel] [PATCH] MdeModulePkg/HiiDatabaseDxe: Add
Support for authenticated variable

I will push this patch today if no other comment.


Thanks,
Dandan

-----Original Message-----
From: Bi, Dandan
Sent: Thursday, January 13, 2022 1:35 PM
To: Huang, Long1 <long1.huang@...>; devel@edk2.groups.io
Cc: Feng, Bob C <bob.c.feng@...>; Gao, Liming
<gaoliming@...>; Chen, Lin Z <lin.z.chen@...>; Li,
Zhuangzhi <zhuangzhi.li@...>
Subject: RE: [PATCH] MdeModulePkg/HiiDatabaseDxe: Add Support for
authenticated variable

The change is ok to me. Reviewed-by: Dandan Bi <dandan.bi@...>

Hi Liming,

Could you also help review it?


Thanks,
Dandan
-----Original Message-----
From: Huang, Long1 <long1.huang@...>
Sent: Thursday, January 13, 2022 1:06 AM
To: devel@edk2.groups.io
Cc: Huang, Long1 <long1.huang@...>; Feng, Bob C
<bob.c.feng@...>; Gao, Liming <gaoliming@...>; Bi,
Dandan <dandan.bi@...>; Chen, Lin Z <lin.z.chen@...>; Li,
Zhuangzhi <zhuangzhi.li@...>
Subject: [PATCH] MdeModulePkg/HiiDatabaseDxe: Add Support for
authenticated variable

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

Database.c:
1. Replace PcdGetExPtr with PcdGetExPtr.
2. Add FindAuthVariableData function to parse authenticated
variable
type for getting a correct default value in
PcdNvStoreDefaultValueBuffer.

Signed-off-by: Huang Long <long1.huang@...>

Cc: Bob Feng <bob.c.feng@...>
Cc: Liming Gao <gaoliming@...>
Cc: Dandan Bi <dandan.bi@...>
Cc: Lin Z Chen <lin.z.chen@...>
Cc: Zhuangzhi Li <zhuangzhi.li@...>
---
.../Universal/HiiDatabaseDxe/Database.c | 130
++++++++++++++----
.../HiiDatabaseDxe/HiiDatabaseDxe.inf | 3 +
2 files changed, 105 insertions(+), 28 deletions(-)

diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
index 0b09c24d52..c7a92d6aed 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
@@ -603,6 +603,45 @@ FindVariableData (
return NULL;

}



+/**

+ Find the matched authenticated variable from the input variable
storage.

+

+ @param[in] VariableStorage Point to the variable storage header.

+ @param[in] VarGuid A unique identifier for the variable.

+ @param[in] VarAttribute The attributes bitmask for the variable.

+ @param[in] VarName A Null-terminated ascii string that is
the name
of
the variable.

+

+ @return Pointer to the matched variable header or NULL if not
found.

+**/

+AUTHENTICATED_VARIABLE_HEADER *

+FindAuthVariableData (

+ IN VARIABLE_STORE_HEADER *VariableStorage,

+ IN EFI_GUID *VarGuid,

+ IN UINT32 VarAttribute,

+ IN CHAR16 *VarName

+ )

+{

+ AUTHENTICATED_VARIABLE_HEADER *AuthVariableHeader;

+ AUTHENTICATED_VARIABLE_HEADER *AuthVariableEnd;

+

+ AuthVariableEnd = (AUTHENTICATED_VARIABLE_HEADER
*)((UINT8
*)VariableStorage + VariableStorage->Size);

+ AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER
*)(VariableStorage + 1);

+ AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER
*)HEADER_ALIGN (AuthVariableHeader);

+ while (AuthVariableHeader < AuthVariableEnd) {

+ if (CompareGuid (&AuthVariableHeader->VendorGuid, VarGuid) &&

+ (AuthVariableHeader->Attributes == VarAttribute) &&

+ (StrCmp (VarName, (CHAR16 *)(AuthVariableHeader + 1)) ==
0))

+ {

+ return AuthVariableHeader;

+ }

+

+ AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER
*)((UINT8
*)AuthVariableHeader + sizeof (AUTHENTICATED_VARIABLE_HEADER) +
AuthVariableHeader->NameSize + AuthVariableHeader->DataSize);

+ AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER
*)HEADER_ALIGN (AuthVariableHeader);

+ }

+

+ return NULL;

+}

+

/**

Find question default value from PcdNvStoreDefaultValueBuffer



@@ -626,25 +665,29 @@ FindQuestionDefaultSetting (
IN BOOLEAN BitFieldQuestion

)

{

- VARIABLE_HEADER *VariableHeader;

- VARIABLE_STORE_HEADER *VariableStorage;

- LIST_ENTRY *Link;

- VARSTORAGE_DEFAULT_DATA *Entry;

- VARIABLE_STORE_HEADER *NvStoreBuffer;

- UINT8 *DataBuffer;

- UINT8 *BufferEnd;

- BOOLEAN IsFound;

- UINTN Index;

- UINT32 BufferValue;

- UINT32 BitFieldVal;

- UINTN BitOffset;

- UINTN ByteOffset;

- UINTN BitWidth;

- UINTN StartBit;

- UINTN EndBit;

- PCD_DEFAULT_DATA *DataHeader;

- PCD_DEFAULT_INFO *DefaultInfo;

- PCD_DATA_DELTA *DeltaData;

+ VARIABLE_HEADER *VariableHeader;

+ AUTHENTICATED_VARIABLE_HEADER *AuthVariableHeader;

+ VARIABLE_STORE_HEADER *VariableStorage;

+ LIST_ENTRY *Link;

+ VARSTORAGE_DEFAULT_DATA *Entry;

+ VARIABLE_STORE_HEADER *NvStoreBuffer;

+ VOID *ValueSource;

+ VOID *BitValueSource;

+ UINT8 *DataBuffer;

+ UINT8 *BufferEnd;

+ BOOLEAN AuthFormat;

+ BOOLEAN IsFound;

+ UINTN Index;

+ UINT32 BufferValue;

+ UINT32 BitFieldVal;

+ UINTN BitOffset;

+ UINTN ByteOffset;

+ UINTN BitWidth;

+ UINTN StartBit;

+ UINTN EndBit;

+ PCD_DEFAULT_DATA *DataHeader;

+ PCD_DEFAULT_INFO *DefaultInfo;

+ PCD_DATA_DELTA *DeltaData;



if (gSkuId == 0xFFFFFFFFFFFFFFFF) {

gSkuId = LibPcdGetSku ();

@@ -666,7 +709,7 @@ FindQuestionDefaultSetting (
}



if (Link == &gVarStorageList) {

- DataBuffer = (UINT8 *)PcdGetPtr
(PcdNvStoreDefaultValueBuffer);

+ DataBuffer = (UINT8 *)PcdGetExPtr
(&gEfiMdeModulePkgTokenSpaceGuid, PcdNvStoreDefaultValueBuffer);

gNvDefaultStoreSize =
((PCD_NV_STORE_DEFAULT_BUFFER_HEADER
*)DataBuffer)->Length;

//

// The first section data includes NV storage default setting.

@@ -750,12 +793,27 @@ FindQuestionDefaultSetting (
return EFI_NOT_FOUND;

}



+ //

+ // Judge if the variable type is authenticated, default is false

+ //

+ AuthFormat = FALSE;

+ if (CompareGuid (&VariableStorage->Signature,
&gEfiAuthenticatedVariableGuid)) {

+ AuthFormat = TRUE;

+ }

+

//

// Find the question default value from the variable storage

//

- VariableHeader = FindVariableData (VariableStorage,
&EfiVarStore->Guid,
EfiVarStore->Attributes, (CHAR16 *)EfiVarStore->Name);

- if (VariableHeader == NULL) {

- return EFI_NOT_FOUND;

+ if(AuthFormat) {

+ AuthVariableHeader = FindAuthVariableData (VariableStorage,
&EfiVarStore->Guid, EfiVarStore->Attributes, (CHAR16 *)EfiVarStore-
Name);
+ if (AuthVariableHeader == NULL) {

+ return EFI_NOT_FOUND;

+ }

+ } else {

+ VariableHeader = FindVariableData (VariableStorage,
+ &EfiVarStore->Guid,
EfiVarStore->Attributes, (CHAR16 *)EfiVarStore->Name);

+ if (VariableHeader == NULL) {

+ return EFI_NOT_FOUND;

+ }

}



StartBit = 0;

@@ -770,8 +828,24 @@ FindQuestionDefaultSetting (
Width = EndBit / 8 + 1;

}



- if (VariableHeader->DataSize < ByteOffset + Width) {

- return EFI_INVALID_PARAMETER;

+ if (AuthFormat) {

+ if (AuthVariableHeader->DataSize < ByteOffset + Width) {

+ return EFI_INVALID_PARAMETER;

+ }

+

+ ValueSource = (UINT8 *)AuthVariableHeader + sizeof
(AUTHENTICATED_VARIABLE_HEADER) + AuthVariableHeader->NameSize
+
IfrQuestionHdr->VarStoreInfo.VarOffset;

+ if (BitFieldQuestion) {

+ BitValueSource = (UINT8 *)AuthVariableHeader + sizeof
(AUTHENTICATED_VARIABLE_HEADER) + AuthVariableHeader->NameSize
+
ByteOffset;

+ }

+ } else {

+ if (VariableHeader->DataSize < ByteOffset + Width) {

+ return EFI_INVALID_PARAMETER;

+ }

+

+ ValueSource = (UINT8 *)VariableHeader + sizeof
(VARIABLE_HEADER)
+ +
VariableHeader->NameSize + IfrQuestionHdr->VarStoreInfo.VarOffset;

+ if (BitFieldQuestion) {

+ BitValueSource = (UINT8 *)VariableHeader + sizeof
+ (VARIABLE_HEADER)
+ VariableHeader->NameSize + ByteOffset;

+ }

}



//

@@ -779,11 +853,11 @@ FindQuestionDefaultSetting (
//

if (ValueBuffer != NULL) {

if (BitFieldQuestion) {

- CopyMem (&BufferValue, (UINT8 *)VariableHeader + sizeof
(VARIABLE_HEADER) + VariableHeader->NameSize + ByteOffset, Width);

+ CopyMem (&BufferValue, BitValueSource, Width);

BitFieldVal = BitFieldRead32 (BufferValue, StartBit, EndBit);

CopyMem (ValueBuffer, &BitFieldVal, Width);

} else {

- CopyMem (ValueBuffer, (UINT8 *)VariableHeader + sizeof
(VARIABLE_HEADER) + VariableHeader->NameSize + IfrQuestionHdr-
VarStoreInfo.VarOffset, Width);
+ CopyMem (ValueBuffer, ValueSource, Width);

}

}



@@ -832,7 +906,7 @@ UpdateDefaultSettingInFormPackage (
// If no default setting, do nothing

//

if (gNvDefaultStoreSize == 0) {

- gNvDefaultStoreSize = PcdGetSize (PcdNvStoreDefaultValueBuffer);

+ gNvDefaultStoreSize = PcdGetExSize
(&gEfiMdeModulePkgTokenSpaceGuid, PcdNvStoreDefaultValueBuffer);

}



if (gNvDefaultStoreSize < sizeof
(PCD_NV_STORE_DEFAULT_BUFFER_HEADER)) {

diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
index 0116fb6ecb..dac4d614a8 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
@@ -86,6 +86,9 @@
gEfiHiiImageDecoderNameJpegGuid
|gEfiMdeModulePkgTokenSpaceGuid.PcdSupportHiiImageProtocol ##
SOMETIMES_CONSUMES ## GUID

gEfiHiiImageDecoderNamePngGuid
|gEfiMdeModulePkgTokenSpaceGuid.PcdSupportHiiImageProtocol ##
SOMETIMES_CONSUMES ## GUID

gEdkiiIfrBitVarstoreGuid
##
SOMETIMES_CONSUMES ## GUID

+ gEfiAuthenticatedVariableGuid

+ gEfiVariableGuid

+ gEfiMdeModulePkgTokenSpaceGuid



[Depex]

TRUE

--
2.25.1




[PATCH] MdeModulePkg: Enabling OS boot from SD card through UEFI payload

Aiman Rosli
 

This changes is by adding 50ms delay during voltage swithcing from 3.3V to 1.8V,
plus adding a while loop for 3.3V checking and retrying.

Signed-off-by: Aiman Rosli <muhammad.aiman.rosli@...>
---
MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c | 273 ++++++++++--------
1 file changed, 146 insertions(+), 127 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c
index 662f9f483c..e91251d457 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c
@@ -1213,167 +1213,186 @@ SdCardIdentification (
UINT32 PresentState;
UINT8 HostCtrl2;
UINTN Retry;
+ BOOLEAN Force3p3v;
+
+ Force3p3v = FALSE;

PciIo = Private->PciIo;
PassThru = &Private->PassThru;
- //
- // 1. Send Cmd0 to the device
- //
- Status = SdCardReset (PassThru, Slot);
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_INFO, "SdCardIdentification: Executing Cmd0 fails with %r\n", Status));
- return Status;
- }
-
- //
- // 2. Send Cmd8 to the device
- //
- Status = SdCardVoltageCheck (PassThru, Slot, 0x1, 0xFF);
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_INFO, "SdCardIdentification: Executing Cmd8 fails with %r\n", Status));
- return Status;
- }
-
- //
- // 3. Send SDIO Cmd5 to the device to the SDIO device OCR register.
- //
- Status = SdioSendOpCond (PassThru, Slot, 0, FALSE);
- if (!EFI_ERROR (Status)) {
- DEBUG ((DEBUG_INFO, "SdCardIdentification: Found SDIO device, ignore it as we don't support\n"));
- return EFI_DEVICE_ERROR;
- }

- //
- // 4. Send Acmd41 with voltage window 0 to the device
- //
- Status = SdCardSendOpCond (PassThru, Slot, 0, 0, FALSE, FALSE, FALSE, &Ocr);
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_INFO, "SdCardIdentification: Executing SdCardSendOpCond fails with %r\n", Status));
- return EFI_DEVICE_ERROR;
- }
-
- if (Private->Capability[Slot].Voltage33 != 0) {
+ do {
//
- // Support 3.3V
+ // 1. Send Cmd0 to the device
//
- MaxCurrent = ((UINT32)Private->MaxCurrent[Slot] & 0xFF) * 4;
- } else if (Private->Capability[Slot].Voltage30 != 0) {
+ Status = SdCardReset (PassThru, Slot);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_INFO, "SdCardIdentification: Executing Cmd0 fails with %r\n", Status));
+ return Status;
+ }
+
//
- // Support 3.0V
+ // 2. Send Cmd8 to the device
//
- MaxCurrent = (((UINT32)Private->MaxCurrent[Slot] >> 8) & 0xFF) * 4;
- } else if (Private->Capability[Slot].Voltage18 != 0) {
+ Status = SdCardVoltageCheck (PassThru, Slot, 0x1, 0xFF);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_INFO, "SdCardIdentification: Executing Cmd8 fails with %r\n", Status));
+ return Status;
+ }
+
//
- // Support 1.8V
+ // 3. Send SDIO Cmd5 to the device to the SDIO device OCR register.
//
- MaxCurrent = (((UINT32)Private->MaxCurrent[Slot] >> 16) & 0xFF) * 4;
- } else {
- ASSERT (FALSE);
- return EFI_DEVICE_ERROR;
- }
-
- if (MaxCurrent >= 150) {
- Xpc = TRUE;
- } else {
- Xpc = FALSE;
- }
-
- Status = SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_CTRL_VER, TRUE, sizeof (ControllerVer), &ControllerVer);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- if (((ControllerVer & 0xFF) >= SD_MMC_HC_CTRL_VER_300) &&
- ((ControllerVer & 0xFF) <= SD_MMC_HC_CTRL_VER_420))
- {
- S18r = TRUE;
- } else if (((ControllerVer & 0xFF) == SD_MMC_HC_CTRL_VER_100) || ((ControllerVer & 0xFF) == SD_MMC_HC_CTRL_VER_200)) {
- S18r = FALSE;
- } else {
- ASSERT (FALSE);
- return EFI_UNSUPPORTED;
- }
+ Status = SdioSendOpCond (PassThru, Slot, 0, FALSE);
+ if (!EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_INFO, "SdCardIdentification: Found SDIO device, ignore it as we don't support\n"));
+ return EFI_DEVICE_ERROR;
+ }

- //
- // 5. Repeatly send Acmd41 with supply voltage window to the device.
- // Note here we only support the cards complied with SD physical
- // layer simplified spec version 2.0 and version 3.0 and above.
- //
- Ocr = 0;
- Retry = 0;
- do {
- Status = SdCardSendOpCond (PassThru, Slot, 0, Ocr, S18r, Xpc, TRUE, &Ocr);
+ //
+ // 4. Send Acmd41 with voltage window 0 to the device
+ //
+ Status = SdCardSendOpCond (PassThru, Slot, 0, 0, FALSE, FALSE, FALSE, &Ocr);
if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "SdCardIdentification: SdCardSendOpCond fails with %r Ocr %x, S18r %x, Xpc %x\n", Status, Ocr, S18r, Xpc));
+ DEBUG ((DEBUG_INFO, "SdCardIdentification: Executing SdCardSendOpCond fails with %r\n", Status));
return EFI_DEVICE_ERROR;
}

- if (Retry++ == 100) {
- DEBUG ((DEBUG_ERROR, "SdCardIdentification: SdCardSendOpCond fails too many times\n"));
+ if (Private->Capability[Slot].Voltage33 != 0) {
+ //
+ // Support 3.3V
+ //
+ MaxCurrent = ((UINT32)Private->MaxCurrent[Slot] & 0xFF) * 4;
+ } else if (Private->Capability[Slot].Voltage30 != 0) {
+ //
+ // Support 3.0V
+ //
+ MaxCurrent = (((UINT32)Private->MaxCurrent[Slot] >> 8) & 0xFF) * 4;
+ } else if (Private->Capability[Slot].Voltage18 != 0) {
+ //
+ // Support 1.8V
+ //
+ MaxCurrent = (((UINT32)Private->MaxCurrent[Slot] >> 16) & 0xFF) * 4;
+ } else {
+ ASSERT (FALSE);
return EFI_DEVICE_ERROR;
}

- gBS->Stall (10 * 1000);
- } while ((Ocr & BIT31) == 0);
+ if (MaxCurrent >= 150) {
+ Xpc = TRUE;
+ } else {
+ Xpc = FALSE;
+ }

- //
- // 6. If the S18A bit is set and the Host Controller supports 1.8V signaling
- // (One of support bits is set to 1: SDR50, SDR104 or DDR50 in the
- // Capabilities register), switch its voltage to 1.8V.
- //
- if (((Private->Capability[Slot].Sdr50 != 0) ||
- (Private->Capability[Slot].Sdr104 != 0) ||
- (Private->Capability[Slot].Ddr50 != 0)) &&
- ((Ocr & BIT24) != 0))
- {
- Status = SdCardVoltageSwitch (PassThru, Slot);
+ Status = SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_CTRL_VER, TRUE, sizeof (ControllerVer), &ControllerVer);
if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "SdCardIdentification: Executing SdCardVoltageSwitch fails with %r\n", Status));
- Status = EFI_DEVICE_ERROR;
- goto Error;
+ return Status;
+ }
+
+ if (((ControllerVer & 0xFF) >= SD_MMC_HC_CTRL_VER_300) &&
+ ((ControllerVer & 0xFF) <= SD_MMC_HC_CTRL_VER_420))
+ {
+ S18r = TRUE;
+ } else if (((ControllerVer & 0xFF) == SD_MMC_HC_CTRL_VER_100) || ((ControllerVer & 0xFF) == SD_MMC_HC_CTRL_VER_200)) {
+ S18r = FALSE;
} else {
- Status = SdMmcHcStopClock (PciIo, Slot);
+ ASSERT (FALSE);
+ return EFI_UNSUPPORTED;
+ }
+
+ //
+ // 1.8V had failed in the previous run, forcing a retry with 3.3V instead
+ //
+ if (Force3p3v == TRUE) {
+ S18r = FALSE;
+ Force3p3v = FALSE;
+ }
+
+ //
+ // 5. Repeatly send Acmd41 with supply voltage window to the device.
+ // Note here we only support the cards complied with SD physical
+ // layer simplified spec version 2.0 and version 3.0 and above.
+ //
+ Ocr = 0;
+ Retry = 0;
+ do {
+ Status = SdCardSendOpCond (PassThru, Slot, 0, Ocr, S18r, Xpc, TRUE, &Ocr);
if (EFI_ERROR (Status)) {
- Status = EFI_DEVICE_ERROR;
- goto Error;
+ DEBUG ((DEBUG_ERROR, "SdCardIdentification: SdCardSendOpCond fails with %r Ocr %x, S18r %x, Xpc %x\n", Status, Ocr, S18r, Xpc));
+ return EFI_DEVICE_ERROR;
}

- SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_PRESENT_STATE, TRUE, sizeof (PresentState), &PresentState);
- if (((PresentState >> 20) & 0xF) != 0) {
- DEBUG ((DEBUG_ERROR, "SdCardIdentification: SwitchVoltage fails with PresentState = 0x%x\n", PresentState));
- Status = EFI_DEVICE_ERROR;
- goto Error;
+ if (Retry++ == 100) {
+ DEBUG ((DEBUG_ERROR, "SdCardIdentification: SdCardSendOpCond fails too many times\n"));
+ return EFI_DEVICE_ERROR;
}

- HostCtrl2 = BIT3;
- SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);
-
- gBS->Stall (5000);
+ gBS->Stall (10 * 1000);
+ } while ((Ocr & BIT31) == 0);

- SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, TRUE, sizeof (HostCtrl2), &HostCtrl2);
- if ((HostCtrl2 & BIT3) == 0) {
- DEBUG ((DEBUG_ERROR, "SdCardIdentification: SwitchVoltage fails with HostCtrl2 = 0x%x\n", HostCtrl2));
+ //
+ // 6. If the S18A bit is set and the Host Controller supports 1.8V signaling
+ // (One of support bits is set to 1: SDR50, SDR104 or DDR50 in the
+ // Capabilities register), switch its voltage to 1.8V.
+ //
+ if (((Private->Capability[Slot].Sdr50 != 0) ||
+ (Private->Capability[Slot].Sdr104 != 0) ||
+ (Private->Capability[Slot].Ddr50 != 0)) &&
+ ((Ocr & BIT24) != 0))
+ {
+ Status = SdCardVoltageSwitch (PassThru, Slot);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "SdCardIdentification: Executing SdCardVoltageSwitch fails with %r\n", Status));
Status = EFI_DEVICE_ERROR;
goto Error;
- }
+ } else {
+ Status = SdMmcHcStopClock (PciIo, Slot);
+ if (EFI_ERROR (Status)) {
+ Status = EFI_DEVICE_ERROR;
+ goto Error;
+ }

- Status = SdMmcHcStartSdClock (PciIo, Slot);
- if (EFI_ERROR (Status)) {
- goto Error;
- }
+ SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_PRESENT_STATE, TRUE, sizeof (PresentState), &PresentState);
+ if (((PresentState >> 20) & 0xF) != 0) {
+ DEBUG ((DEBUG_ERROR, "SdCardIdentification: SwitchVoltage fails with PresentState = 0x%x\n", PresentState));
+ Status = EFI_DEVICE_ERROR;
+ goto Error;
+ }

- gBS->Stall (1000);
+ HostCtrl2 = BIT3;
+ SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);

- SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_PRESENT_STATE, TRUE, sizeof (PresentState), &PresentState);
- if (((PresentState >> 20) & 0xF) != 0xF) {
- DEBUG ((DEBUG_ERROR, "SdCardIdentification: SwitchVoltage fails with PresentState = 0x%x, It should be 0xF\n", PresentState));
- Status = EFI_DEVICE_ERROR;
- goto Error;
+ gBS->Stall (5000);
+
+ SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, TRUE, sizeof (HostCtrl2), &HostCtrl2);
+ if ((HostCtrl2 & BIT3) == 0) {
+ DEBUG ((DEBUG_ERROR, "SdCardIdentification: SwitchVoltage fails with HostCtrl2 = 0x%x\n", HostCtrl2));
+ Status = EFI_DEVICE_ERROR;
+ goto Error;
+ }
+
+ Status = SdMmcHcStartSdClock (PciIo, Slot);
+ if (EFI_ERROR (Status)) {
+ goto Error;
+ }
+
+ // Workaround to add a delay of 100ms in order for clock to stabilize before turning on the SD card again.
+ gBS->Stall (50000);
+
+ gBS->Stall (1000);
+
+ SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_PRESENT_STATE, TRUE, sizeof (PresentState), &PresentState);
+ if (((PresentState >> 20) & 0xF) != 0xF) {
+ DEBUG ((DEBUG_ERROR, "SdCardIdentification: SwitchVoltage fails with PresentState = 0x%x, It should be 0xF\n", PresentState));
+ Status = SdMmcHcReset (Private, Slot);
+ Status = SdMmcHcInitHost (Private, Slot);
+ Force3p3v = TRUE;
+ DEBUG ((DEBUG_ERROR, "SdCardIdentification: Switching to 1.8V had failed in the previous run, forcing a retry with 3.3V instead\n"));
+ }
}
- }

- DEBUG ((DEBUG_INFO, "SdCardIdentification: Switch to 1.8v signal voltage success\n"));
- }
+ DEBUG ((DEBUG_INFO, "SdCardIdentification: Switch to 1.8v signal voltage success\n"));
+ }
+ } while (Force3p3v);

Status = SdCardAllSendCid (PassThru, Slot);
if (EFI_ERROR (Status)) {
--
2.34.1.windows.1


Re: [PATCH] MdeModulePkg/HiiDatabaseDxe: Add Support for authenticated variable

Dandan Bi
 

I will push this patch today if no other comment.


Thanks,
Dandan

-----Original Message-----
From: Bi, Dandan
Sent: Thursday, January 13, 2022 1:35 PM
To: Huang, Long1 <long1.huang@...>; devel@edk2.groups.io
Cc: Feng, Bob C <bob.c.feng@...>; Gao, Liming
<gaoliming@...>; Chen, Lin Z <lin.z.chen@...>; Li,
Zhuangzhi <zhuangzhi.li@...>
Subject: RE: [PATCH] MdeModulePkg/HiiDatabaseDxe: Add Support for
authenticated variable

The change is ok to me. Reviewed-by: Dandan Bi <dandan.bi@...>

Hi Liming,

Could you also help review it?


Thanks,
Dandan
-----Original Message-----
From: Huang, Long1 <long1.huang@...>
Sent: Thursday, January 13, 2022 1:06 AM
To: devel@edk2.groups.io
Cc: Huang, Long1 <long1.huang@...>; Feng, Bob C
<bob.c.feng@...>; Gao, Liming <gaoliming@...>; Bi,
Dandan <dandan.bi@...>; Chen, Lin Z <lin.z.chen@...>; Li,
Zhuangzhi <zhuangzhi.li@...>
Subject: [PATCH] MdeModulePkg/HiiDatabaseDxe: Add Support for
authenticated variable

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

Database.c:
1. Replace PcdGetExPtr with PcdGetExPtr.
2. Add FindAuthVariableData function to parse authenticated
variable
type for getting a correct default value in
PcdNvStoreDefaultValueBuffer.

Signed-off-by: Huang Long <long1.huang@...>

Cc: Bob Feng <bob.c.feng@...>
Cc: Liming Gao <gaoliming@...>
Cc: Dandan Bi <dandan.bi@...>
Cc: Lin Z Chen <lin.z.chen@...>
Cc: Zhuangzhi Li <zhuangzhi.li@...>
---
.../Universal/HiiDatabaseDxe/Database.c | 130 ++++++++++++++----
.../HiiDatabaseDxe/HiiDatabaseDxe.inf | 3 +
2 files changed, 105 insertions(+), 28 deletions(-)

diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
index 0b09c24d52..c7a92d6aed 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
@@ -603,6 +603,45 @@ FindVariableData (
return NULL;

}



+/**

+ Find the matched authenticated variable from the input variable storage.

+

+ @param[in] VariableStorage Point to the variable storage header.

+ @param[in] VarGuid A unique identifier for the variable.

+ @param[in] VarAttribute The attributes bitmask for the variable.

+ @param[in] VarName A Null-terminated ascii string that is the name
of
the variable.

+

+ @return Pointer to the matched variable header or NULL if not found.

+**/

+AUTHENTICATED_VARIABLE_HEADER *

+FindAuthVariableData (

+ IN VARIABLE_STORE_HEADER *VariableStorage,

+ IN EFI_GUID *VarGuid,

+ IN UINT32 VarAttribute,

+ IN CHAR16 *VarName

+ )

+{

+ AUTHENTICATED_VARIABLE_HEADER *AuthVariableHeader;

+ AUTHENTICATED_VARIABLE_HEADER *AuthVariableEnd;

+

+ AuthVariableEnd = (AUTHENTICATED_VARIABLE_HEADER *)((UINT8
*)VariableStorage + VariableStorage->Size);

+ AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER
*)(VariableStorage + 1);

+ AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER
*)HEADER_ALIGN (AuthVariableHeader);

+ while (AuthVariableHeader < AuthVariableEnd) {

+ if (CompareGuid (&AuthVariableHeader->VendorGuid, VarGuid) &&

+ (AuthVariableHeader->Attributes == VarAttribute) &&

+ (StrCmp (VarName, (CHAR16 *)(AuthVariableHeader + 1)) == 0))

+ {

+ return AuthVariableHeader;

+ }

+

+ AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER *)((UINT8
*)AuthVariableHeader + sizeof (AUTHENTICATED_VARIABLE_HEADER) +
AuthVariableHeader->NameSize + AuthVariableHeader->DataSize);

+ AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER
*)HEADER_ALIGN (AuthVariableHeader);

+ }

+

+ return NULL;

+}

+

/**

Find question default value from PcdNvStoreDefaultValueBuffer



@@ -626,25 +665,29 @@ FindQuestionDefaultSetting (
IN BOOLEAN BitFieldQuestion

)

{

- VARIABLE_HEADER *VariableHeader;

- VARIABLE_STORE_HEADER *VariableStorage;

- LIST_ENTRY *Link;

- VARSTORAGE_DEFAULT_DATA *Entry;

- VARIABLE_STORE_HEADER *NvStoreBuffer;

- UINT8 *DataBuffer;

- UINT8 *BufferEnd;

- BOOLEAN IsFound;

- UINTN Index;

- UINT32 BufferValue;

- UINT32 BitFieldVal;

- UINTN BitOffset;

- UINTN ByteOffset;

- UINTN BitWidth;

- UINTN StartBit;

- UINTN EndBit;

- PCD_DEFAULT_DATA *DataHeader;

- PCD_DEFAULT_INFO *DefaultInfo;

- PCD_DATA_DELTA *DeltaData;

+ VARIABLE_HEADER *VariableHeader;

+ AUTHENTICATED_VARIABLE_HEADER *AuthVariableHeader;

+ VARIABLE_STORE_HEADER *VariableStorage;

+ LIST_ENTRY *Link;

+ VARSTORAGE_DEFAULT_DATA *Entry;

+ VARIABLE_STORE_HEADER *NvStoreBuffer;

+ VOID *ValueSource;

+ VOID *BitValueSource;

+ UINT8 *DataBuffer;

+ UINT8 *BufferEnd;

+ BOOLEAN AuthFormat;

+ BOOLEAN IsFound;

+ UINTN Index;

+ UINT32 BufferValue;

+ UINT32 BitFieldVal;

+ UINTN BitOffset;

+ UINTN ByteOffset;

+ UINTN BitWidth;

+ UINTN StartBit;

+ UINTN EndBit;

+ PCD_DEFAULT_DATA *DataHeader;

+ PCD_DEFAULT_INFO *DefaultInfo;

+ PCD_DATA_DELTA *DeltaData;



if (gSkuId == 0xFFFFFFFFFFFFFFFF) {

gSkuId = LibPcdGetSku ();

@@ -666,7 +709,7 @@ FindQuestionDefaultSetting (
}



if (Link == &gVarStorageList) {

- DataBuffer = (UINT8 *)PcdGetPtr (PcdNvStoreDefaultValueBuffer);

+ DataBuffer = (UINT8 *)PcdGetExPtr
(&gEfiMdeModulePkgTokenSpaceGuid, PcdNvStoreDefaultValueBuffer);

gNvDefaultStoreSize = ((PCD_NV_STORE_DEFAULT_BUFFER_HEADER
*)DataBuffer)->Length;

//

// The first section data includes NV storage default setting.

@@ -750,12 +793,27 @@ FindQuestionDefaultSetting (
return EFI_NOT_FOUND;

}



+ //

+ // Judge if the variable type is authenticated, default is false

+ //

+ AuthFormat = FALSE;

+ if (CompareGuid (&VariableStorage->Signature,
&gEfiAuthenticatedVariableGuid)) {

+ AuthFormat = TRUE;

+ }

+

//

// Find the question default value from the variable storage

//

- VariableHeader = FindVariableData (VariableStorage,
&EfiVarStore->Guid,
EfiVarStore->Attributes, (CHAR16 *)EfiVarStore->Name);

- if (VariableHeader == NULL) {

- return EFI_NOT_FOUND;

+ if(AuthFormat) {

+ AuthVariableHeader = FindAuthVariableData (VariableStorage,
&EfiVarStore->Guid, EfiVarStore->Attributes, (CHAR16 *)EfiVarStore-
Name);
+ if (AuthVariableHeader == NULL) {

+ return EFI_NOT_FOUND;

+ }

+ } else {

+ VariableHeader = FindVariableData (VariableStorage,
+ &EfiVarStore->Guid,
EfiVarStore->Attributes, (CHAR16 *)EfiVarStore->Name);

+ if (VariableHeader == NULL) {

+ return EFI_NOT_FOUND;

+ }

}



StartBit = 0;

@@ -770,8 +828,24 @@ FindQuestionDefaultSetting (
Width = EndBit / 8 + 1;

}



- if (VariableHeader->DataSize < ByteOffset + Width) {

- return EFI_INVALID_PARAMETER;

+ if (AuthFormat) {

+ if (AuthVariableHeader->DataSize < ByteOffset + Width) {

+ return EFI_INVALID_PARAMETER;

+ }

+

+ ValueSource = (UINT8 *)AuthVariableHeader + sizeof
(AUTHENTICATED_VARIABLE_HEADER) + AuthVariableHeader->NameSize
+
IfrQuestionHdr->VarStoreInfo.VarOffset;

+ if (BitFieldQuestion) {

+ BitValueSource = (UINT8 *)AuthVariableHeader + sizeof
(AUTHENTICATED_VARIABLE_HEADER) + AuthVariableHeader->NameSize
+
ByteOffset;

+ }

+ } else {

+ if (VariableHeader->DataSize < ByteOffset + Width) {

+ return EFI_INVALID_PARAMETER;

+ }

+

+ ValueSource = (UINT8 *)VariableHeader + sizeof (VARIABLE_HEADER)
+ +
VariableHeader->NameSize + IfrQuestionHdr->VarStoreInfo.VarOffset;

+ if (BitFieldQuestion) {

+ BitValueSource = (UINT8 *)VariableHeader + sizeof
+ (VARIABLE_HEADER)
+ VariableHeader->NameSize + ByteOffset;

+ }

}



//

@@ -779,11 +853,11 @@ FindQuestionDefaultSetting (
//

if (ValueBuffer != NULL) {

if (BitFieldQuestion) {

- CopyMem (&BufferValue, (UINT8 *)VariableHeader + sizeof
(VARIABLE_HEADER) + VariableHeader->NameSize + ByteOffset, Width);

+ CopyMem (&BufferValue, BitValueSource, Width);

BitFieldVal = BitFieldRead32 (BufferValue, StartBit, EndBit);

CopyMem (ValueBuffer, &BitFieldVal, Width);

} else {

- CopyMem (ValueBuffer, (UINT8 *)VariableHeader + sizeof
(VARIABLE_HEADER) + VariableHeader->NameSize + IfrQuestionHdr-
VarStoreInfo.VarOffset, Width);
+ CopyMem (ValueBuffer, ValueSource, Width);

}

}



@@ -832,7 +906,7 @@ UpdateDefaultSettingInFormPackage (
// If no default setting, do nothing

//

if (gNvDefaultStoreSize == 0) {

- gNvDefaultStoreSize = PcdGetSize (PcdNvStoreDefaultValueBuffer);

+ gNvDefaultStoreSize = PcdGetExSize
(&gEfiMdeModulePkgTokenSpaceGuid, PcdNvStoreDefaultValueBuffer);

}



if (gNvDefaultStoreSize < sizeof
(PCD_NV_STORE_DEFAULT_BUFFER_HEADER)) {

diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
index 0116fb6ecb..dac4d614a8 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
@@ -86,6 +86,9 @@
gEfiHiiImageDecoderNameJpegGuid
|gEfiMdeModulePkgTokenSpaceGuid.PcdSupportHiiImageProtocol ##
SOMETIMES_CONSUMES ## GUID

gEfiHiiImageDecoderNamePngGuid
|gEfiMdeModulePkgTokenSpaceGuid.PcdSupportHiiImageProtocol ##
SOMETIMES_CONSUMES ## GUID

gEdkiiIfrBitVarstoreGuid ##
SOMETIMES_CONSUMES ## GUID

+ gEfiAuthenticatedVariableGuid

+ gEfiVariableGuid

+ gEfiMdeModulePkgTokenSpaceGuid



[Depex]

TRUE

--
2.25.1


Re: [PATCH v2 6/6] BaseTools: Upgrade the version of NASM tool

Yuwei Chen
 

This patch looks good to me.

Reviewed-by: Yuwei Chen<yuwei.chen@...>

-----Original Message-----
From: Lou, Yun <yun.lou@...>
Sent: Monday, January 10, 2022 11:13 PM
To: devel@edk2.groups.io
Cc: Lou, Yun <yun.lou@...>; Feng, Bob C <bob.c.feng@...>;
Gao, Liming <gaoliming@...>; Chen, Christine
<yuwei.chen@...>
Subject: [PATCH v2 6/6] BaseTools: Upgrade the version of NASM tool

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

Upgrade the version of NASM tool to avoid compilation errors when
compiling NASM code change.

Signed-off-by: Jason Lou <yun.lou@...>
Cc: Bob Feng <bob.c.feng@...>
Cc: Liming Gao <gaoliming@...>
Cc: Yuwei Chen <yuwei.chen@...>
---
BaseTools/Conf/tools_def.template | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/BaseTools/Conf/tools_def.template
b/BaseTools/Conf/tools_def.template
index 2e6b382ab6..0133860fc3 100755
--- a/BaseTools/Conf/tools_def.template
+++ b/BaseTools/Conf/tools_def.template
@@ -1,5 +1,5 @@
#-# Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>+#
Copyright (c) 2006 - 2022, Intel Corporation. All rights reserved.<BR> #
Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> #
Portions copyright (c) 2011 - 2019, ARM Ltd. All rights reserved.<BR> #
Copyright (c) 2015, Hewlett-Packard Development Company, L.P.<BR>@@ -
368,8 +368,8 @@ DEFINE DTC_BIN = ENV(DTC_PREFIX)dtc
# Other Supported Tools # ===================== # NASM --
http://www.nasm.us/-# - NASM 2.10 or later for use with the GCC toolchain
family-# - NASM 2.12.01 or later for use with all other toolchain families+#
- NASM 2.15.05 or later for use with the GCC toolchain family+# - NASM
2.15.05 or later for use with all other toolchain families #
################################################################
####################
################################################################
####################--
2.28.0.windows.1


CdePkgBlog 2022-01-16 -- Introduction of the ACPICA port to UEFI

Kilian Kegel
 

Hi Andrew, hi Jordan, hi Maciej, hi all,

 

this task was suggested by @ajfish and @jljusten at tianocore / tianocore.github.io:

https://github.com/tianocore/tianocore.github.io/wiki/Tasks#port-acpi-ca-to-a-shell-application.

 

All in all it could be solved within a really small amount of time, with a small amount of changes and extensions  some months ago

 

 

My concept here was to choose the existing Microsoft VisualStudio package and

adjust it to run in the UEFI environment, by reimplementing missing Win32-API functions (amount of 8).

This could be done using the Microsoft-C-Library compatible toro-C-Library

 

Maybe that concept is also useable for porting “openSSH” to UEFI Shell: https://github.com/tianocore/tianocore.github.io/wiki/Tasks#port-openssh-as-a-shell-application

 

@Maciej Rabeda

The toro-C-Library source code is included in the project.

You can check what is inside, how it works internally and how I do believe a

C-Library for UEFI Shell/SMM/DXE/PEI should be constructed that guarantees

compatibility/portability+testability for POST drivers and UEFI/Windows Shell applications by design.

 

The “toro-C-Library” build engine is VisualStudio/msbuild.exe only. It takes 20 Seconds to get it done.

The older “torito-C-Library” build engine is EDK2Build. It takes 120 seconds to get it done, for the same result,

on the same build machine.

 

If you want to build the samples, please get the entire CdePkg from edk2-staging that also includes the blog,

https://github.com/tianocore/edk2-staging/tree/CdePkg

 

If you just want to read the new blog:

https://github.com/tianocore/edk2-staging/blob/CdePkg/blogs/2022-01-16/README.md#cdepkgblog-2022-01-16

 

Enjoy the breathtaking speed and elegance of VisualStudio

 

Have fun,

Kilian

 

 


Event: TianoCore Design Meeting - APAC/NAMO - 01/21/2022 #cal-reminder

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

Reminder: TianoCore Design Meeting - APAC/NAMO

When:
01/21/2022
9:30am to 10:30am
(UTC+08:00) Asia/Shanghai

Where:
Microsoft Teams

Organizer: Ray Ni ray.ni@...

View Event

Description:

TOPIC

  1. NA

For more info, see here: https://www.tianocore.org/design-meeting/


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 715 416 0

Alternate VTC dialing instructions

Learn More | Meeting options


Re: [PATCH 08/10] OvmfPkg: Update Sec to support Tdvf Config-B

Min Xu
 

On January 14, 2022 4:32 PM, Gerd Hoffmann wrote:
I don't see that PEI-less boot is required for that. Sure, when
stripping down the build and removing all the features which require
PEIMs there isn't much left to do for the PEI phase. So it makes
sense to look into dropping PEI altogether. But it's more a "nice to have"
than a hard requirement, no?
No. I have to say PEI-less boot in Config-B is a hard requirement.
I'm still wondering why though. I have not yet seen a reason why config-b
can't use the PEI-based boot flow.
Hi, Gerd, I think Jiewen has discussed this (PEI-less boot in Config-B) in another mail thread. We can continue the discussion there. Let's first focus on the PlatformInitLib here. Thanks for your understanding.

4. But a basic version of PlatformInitLib is a good start.
Yes. Having initially only the functions needed by config-b in
PlatformInitLib is perfectly fine, but this should be a code *move* not a
copy.

During the development and community review, we can understand
better what functions should be wrapped into PlatformInitLib.
After that PlatformInitLib can be evolved for OvmfPkg/PlatformPei,
Bhyve/PlatformPei, XenPlatformPei.
Yes, most likely there are a number of opportunities to reduce code
duplication in the three PlatformPei variants we have by moving code
to the
(shared) PlatformInitLib.

That can be looked at later.
So let me summarize the discussion about PlatformInitLib.
1. PlatformInitLib wraps the common functions in OvmfPkg/PlatformPei.
These common functions covers the memory detection via fw_cfg, pci
init, cmos, (MemDetect.c/Platform.c/Cmos.c).
Yes. Everything needed for PEI-less / config-b boot moves to PlatformInitLib.

PlatformInitLib is added as dependency to OvmfPkg/PlatformPei, so
PlatformPei can call those functions when booting with PEI.

PEI-less boot will add PlatformInitLib to SEC (and DXE) instead so the same
code can be used then.

Not sure how to handle cmos best. Not needed for memory detection on
qemu, but cloudhw depends on it so it is back for now. Will cloudhw support
tdx too btw?
Yes, Cloudhw support TDX too. Actually we have some PoC and plan to upstream it later.
BTW, cmos is needed in GetSystemMemorySizeBelow4gb which call CmosRead for 0x34/0x35.

And PlatformInitLib will
not handle the S3/SMM variants.
At least not initially. Maybe later when we move more code to the lib to
reduce code duplication in xen/bhyve/qemu PlatformPei variants.

2. OvmfPkg/PlatformPei will be refactored with PlatformInitLib. The
functions not needed by config-b stay in PlatformPei.
3. Config-B support PEI-less boot for both legacy guest and td guest.
Yes.
Thanks
Min


Re: 回复: [edk2-devel] [PATCH] MdeModulePkg\CoreDxe: Allow DXE Drivers to use untested memory

Howell, Stacy <stacy.howell@...>
 

Hi Sean,
Setting all memory as tested in PEI is a workaround for the issue that this patch addresses. However, promoting all memory in PEI is not a workable solution for BIOSes that incorporate full memory testing functionality, as this relies on the tested flag to determine which memory regions to test.

This patch addresses a discrepancy in EDK2 core regarding how untested memory is treated for allocation by DXE drivers. In the case where a DXE driver does not request a specific memory region DXE Core will promote untested memory if necessary to provide memory to the driver. In the case where a DXE driver requests a specific memory range of untested memory, DXE Core will currently return an error instead of promoting untested memory to make the region available for the driver.

Thanks,
Stacy

-----Original Message-----
From: Kinney, Michael D <michael.d.kinney@...>
Sent: Tuesday, January 11, 2022 10:57 AM
To: devel@edk2.groups.io; spbrogan@...; Gao, Liming <gaoliming@...>; Howell, Stacy <stacy.howell@...>; Kinney, Michael D <michael.d.kinney@...>
Cc: Bi, Dandan <dandan.bi@...>
Subject: RE: 回复: [edk2-devel] [PATCH] MdeModulePkg\CoreDxe: Allow DXE Drivers to use untested memory

Hi Sean,

The auto promotion of memory was only intended as a dev/debug feature to maximize platform boot without having to tune what memory is tested in PEI phase.

In my opinion, a production platform should never trigger any auto promotions of untested to tested memory, and part of production validation should make sure this event never occurs in any production boot scenarios.

The specific bug being fix here is that auto promotion was not symmetric across all memory allocation types. It simply aligns this dev/debug feature.

Mike

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Sean
Sent: Monday, January 10, 2022 6:47 PM
To: devel@edk2.groups.io; Gao, Liming <gaoliming@...>;
Howell, Stacy <stacy.howell@...>
Cc: Bi, Dandan <dandan.bi@...>
Subject: Re: 回复: [edk2-devel] [PATCH] MdeModulePkg\CoreDxe: Allow DXE
Drivers to use untested memory

if this is auto promotion is happening in the core then what is the
value of memory testing and tracking that state. Is memory testing
state a necessary feature of the Dxe Core?


I think it makes more sense that if you platform wants to use a given
range your platform should either test it and/or mark it as tested.

OR

The dxe core should do away with the memory testing tracking.


On most platforms i have seen in the past few years all memory is
marked as tested without doing any testing. The only value in the
flag is keep the initial memory allocations in a given low range (below 4gb).




On 1/10/2022 5:59 PM, gaoliming wrote:
Stacy:
This fix covers the case with AllocateAddress allocation type. I
agree this fix. Reviewed-by: Liming Gao <gaoliming@...>

Thanks
Liming
-----邮件原件-----
发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Stacy Howell
发送时间: 2022年1月8日 3:36
收件人: devel@edk2.groups.io
抄送: Stacy Howell <stacy.howell@...>; Dandan Bi
<dandan.bi@...>; Liming Gao <gaoliming@...>
主题: [edk2-devel] [PATCH] MdeModulePkg\CoreDxe: Allow DXE Drivers to
use untested memory

REF: https://https://bugzilla.tianocore.org/show_bug.cgi?id=3795
CC: Dandan Bi <dandan.bi@...>
CC: Liming Gao <gaoliming@...>

Updated CoreInternalAllocatePages() to call PromoteMemoryResource()
and re-attempt the allocation if unable to convert the specified
memory range

Signed-off-by: Stacy Howell <stacy.howell@...>
---
MdeModulePkg/Core/Dxe/Mem/Page.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)

diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c
b/MdeModulePkg/Core/Dxe/Mem/Page.c
index 47d4c5d92e..cc0b90ac0d 100644
--- a/MdeModulePkg/Core/Dxe/Mem/Page.c
+++ b/MdeModulePkg/Core/Dxe/Mem/Page.c
@@ -1417,6 +1417,20 @@ CoreInternalAllocatePages (
Status = CoreConvertPages (Start, NumberOfPages, MemoryType);
}

+ if (EFI_ERROR (Status)) {
+ //
+ // If requested memory region is unavailable it may be
+ untested
memory
+ // Attempt to promote memory resources, then re-attempt the
allocation
+ //
+ if (PromoteMemoryResource ()) {
+ if (NeedGuard) {
+ Status = CoreConvertPagesWithGuard (Start, NumberOfPages,
MemoryType);
+ } else {
+ Status = CoreConvertPages (Start, NumberOfPages, MemoryType);
+ }
+ }
+ }
+
Done:
CoreReleaseMemoryLock ();

--
2.32.0.windows.2













Re: [PATCH 01/79] ProcessorPkg/Include: Add header files of RISC-V processor package

Michael D Kinney
 

Hi Abner,

We already have a package for common platform content in the edk2 repo.
This is the MdeModulePkg.

However, the number of common platform features added to the MdeModulePkg over
time has made this a very large package, and this can be measured by how complex the
Maintainer.txt rules are for this package.

The revised approach is to create feature packages that platforms can add
if their platform requires that specific feature category. Examples are
NetworkPkg, SecurityPkg, FmpDevicePkg, FatPkg, RedfishPkg, SourceLevelDebugPkg.

Instead of adding another generic package such as CommonPlatformPkg, I
would prefer to see the libs/modules either added to existing packages
that match the feature category, or create new feature packages if
there is a new feature category.

We also try to limit the edk2 repo to components that are directly related
the UEFI/PI specifications and are not Si/Platform specific. Si/Platform
specific features go into the edk2-platforms repo. An example of a generic
feature in the edk2-platforms repo is Features/Ext4. The UEFI spec only
specifies FAT for UEFI boot from file system.

There are a number of other feature packages in edk2-platforms in the
Features directory, so you should review those as well to see if there
is natural landing zone for any of your components.

Mike

-----Original Message-----
From: Chang, Abner (HPS SW/FW Technologist) <abner.chang@...>
Sent: Friday, January 14, 2022 3:15 AM
To: Kinney, Michael D <michael.d.kinney@...>; Leif Lindholm <leif@...>; devel@edk2.groups.io; Ni, Ray
<ray.ni@...>
Cc: Andrew Fish <afish@...>; Sami Mujawar <Sami.Mujawar@...>
Subject: RE: [edk2-devel] [PATCH 01/79] ProcessorPkg/Include: Add header files of RISC-V processor package



-----Original Message-----
From: Kinney, Michael D <michael.d.kinney@...>
Sent: Friday, January 14, 2022 12:38 AM
To: Chang, Abner (HPS SW/FW Technologist) <abner.chang@...>; Leif
Lindholm <leif@...>; devel@edk2.groups.io; Ni, Ray
<ray.ni@...>; Kinney, Michael D <michael.d.kinney@...>
Cc: Andrew Fish <afish@...>; Sami Mujawar
<Sami.Mujawar@...>
Subject: RE: [edk2-devel] [PATCH 01/79] ProcessorPkg/Include: Add header
files of RISC-V processor package

Hi Abner,

General recommendations included below. Of course each
lib/modules/include needs to be reviewed and the
best location selected. I am aware that there are components in edk2 that
do not follow these general
recommendations. This is due to content that was added before these
recommendations were established
and we have work to do to get everything aligned.

Mike

-----Original Message-----
From: Chang, Abner (HPS SW/FW Technologist) <abner.chang@...>
Sent: Wednesday, January 12, 2022 9:34 PM
To: Kinney, Michael D <michael.d.kinney@...>; Leif Lindholm
<leif@...>; devel@edk2.groups.io; Ni, Ray
<ray.ni@...>
Cc: Andrew Fish <afish@...>; Sami Mujawar
<Sami.Mujawar@...>
Subject: RE: [edk2-devel] [PATCH 01/79] ProcessorPkg/Include: Add
header files of RISC-V processor package

HI Mike,
It is no problem to meet there. However, I am not available to join the
design meeting in the next two weeks. Before we can get
together to discuss the best locations, do you have information regarding
the rationale of driver/library location?

What is the best location for,
- Processor ARCH dependent modules
MdePkg for libs
UefiCpuPkg for modules

- Common modules for all processor ARCHs
Feature Packages based on the common feature. Add to existing if it fits.
Create new for completely new feature area.

- Platform module that is specific to processor ARCH?
edk2-platform repository
How about Leif's suggestion? The CommonPlatformPkg on edk2?

Abner


The only exception so far are platform modules used to support
OvmfPkg/QEMU to support CI.
In this case the modules are added to OvmfPkg.

- Platform module that is common to processor ARCHs?
edk2-platform repository

The only exception so far are platform modules used to support
OvmfPkg/QEMU to support CI.
In this case the modules are added to OvmfPkg.


Thanks
Abner

-----Original Message-----
From: Kinney, Michael D <michael.d.kinney@...>
Sent: Monday, January 10, 2022 11:58 PM
To: Leif Lindholm <leif@...>; devel@edk2.groups.io; Chang,
Abner
(HPS SW/FW Technologist) <abner.chang@...>; Kinney, Michael D
<michael.d.kinney@...>; Ni, Ray <ray.ni@...>
Cc: Andrew Fish <afish@...>; Sami Mujawar
<Sami.Mujawar@...>
Subject: RE: [edk2-devel] [PATCH 01/79] ProcessorPkg/Include: Add
header
files of RISC-V processor package

Hi Abner,

I see comments from Leif as well.

Do you think a discussion in the design meeting Ray Ni runs would be
valuable
to review all the modules/libs/includes and discuss options for the best
location for them to reside in the edk2 repos?

Thanks,

Mike

-----Original Message-----
From: Kinney, Michael D <michael.d.kinney@...>
Sent: Monday, January 10, 2022 7:55 AM
To: Leif Lindholm <leif@...>; devel@edk2.groups.io; Chang,
Abner <abner.chang@...>; Kinney, Michael D
<michael.d.kinney@...>
Cc: Andrew Fish <afish@...>; Sami Mujawar
<Sami.Mujawar@...>
Subject: RE: [edk2-devel] [PATCH 01/79] ProcessorPkg/Include: Add
header files of RISC-V processor package

Hi Abner,

I would also like to see some proposals on adding the RiscV CPU scoped
content
to the existing MdePkg/UefiCpuPkg instead of adding a new top level
CPU
package.

There is already some work started to move some of the ARM specific
content
from ARM CPU packages into MdePkg.

Thanks,

Mike

-----Original Message-----
From: Leif Lindholm <leif@...>
Sent: Monday, January 10, 2022 5:11 AM
To: devel@edk2.groups.io; Chang, Abner <abner.chang@...>
Cc: Andrew Fish <afish@...>; Kinney, Michael D
<michael.d.kinney@...>; Sami Mujawar
<Sami.Mujawar@...>
Subject: Re: [edk2-devel] [PATCH 01/79] ProcessorPkg/Include: Add
header files of RISC-V processor package

On Sat, Jan 08, 2022 at 12:07:53 +0800, Abner Chang wrote:
(This is migrated from edk2-platforms:Silicon/RISC-V)

RISC-V processor package library definitions.

IndustryStandard/RiscV.h
-Add RiscV.h which conform with RISC-V Privilege Spec v1.10.

RiscVImpl.h
-Definition of EDK2 RISC-V implementation.

Signed-off-by: Abner Chang <abner.chang@...>
Co-authored-by: Daniel Schaefer <daniel.schaefer@...>
Co-authored-by: Gilbert Chen <gilbert.chen@...>
Reviewed-by: Leif Lindholm <leif.lindholm@...>
Hmm, no.
I gave a reviewed-by for that patch to be merged into edk2-platforms
once upon a time. This is not relevant for migration to edk2.

My proposal for migrating this code would be as follows:
- Announce a hold on merging new code to RiscV portions of
edk2-platforms.
- Apply any and all bugfixes and CI/uncrustify fixes in place in
edk2-platforms.
- Get some level of agreement for what to do instead of
RiscVPlatformPkg - i.e. slot into MdeModulePkg instead.
- If that cannot be reached within a few days, create a new
top-level directory called "CommonPlatformPkg" or something,
with you, Daniel(/Gilbert?), Sami, me as maintainers.
- Move all of the RiscVPlatformPkg code under there instead.
- I'll follow with ArmPlatformPkg.
- PC/AT code should move across too over time.
- Move the rest of the code across unmodified as massive single
patches per package (potentially more patches than that for
RiscVPlatformPkg).
- Drop all existing Reviewed-by/Acked-by.
- After each "move" patch, insert a "fixup" patch to address the
things that need fixing due to path/name changes.

/
Leif

Cc: Leif Lindholm <leif.lindholm@...>
Cc: Gilbert Chen <gilbert.chen@...>
---
.../Include/IndustryStandard/RiscV.h | 156
++++++++++++++++++
.../RISC-V/ProcessorPkg/Include/RiscVImpl.h | 87 ++++++++++
2 files changed, 243 insertions(+)
create mode 100644 Silicon/RISC-
V/ProcessorPkg/Include/IndustryStandard/RiscV.h
create mode 100644 Silicon/RISC-
V/ProcessorPkg/Include/RiscVImpl.h

diff --git a/Silicon/RISC-
V/ProcessorPkg/Include/IndustryStandard/RiscV.h b/Silicon/RISC-
V/ProcessorPkg/Include/IndustryStandard/RiscV.h
new file mode 100644
index 0000000000..2a992394ed
--- /dev/null
+++ b/Silicon/RISC-
V/ProcessorPkg/Include/IndustryStandard/RiscV.h
@@ -0,0 +1,156 @@
+/** @file
+ RISC-V package definitions.
+
+ Copyright (c) 2019, Hewlett Packard Enterprise Development LP.
All
rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef RISCV_INDUSTRY_STANDARD_H_
+#define RISCV_INDUSTRY_STANDARD_H_
+
+#if defined (MDE_CPU_RISCV64)
+#define RISC_V_XLEN_BITS 64
+#else
+#endif
+
+#define RISC_V_ISA_ATOMIC_EXTENSION (0x00000001 <<
0)
+#define RISC_V_ISA_BIT_OPERATION_EXTENSION
(0x00000001
<< 1)
+#define RISC_V_ISA_COMPRESSED_EXTENSION (0x00000001
<<
2)
+#define RISC_V_ISA_DOUBLE_PRECISION_FP_EXTENSION
(0x00000001 << 3)
+#define RISC_V_ISA_RV32E_ISA (0x00000001 << 4)
+#define RISC_V_ISA_SINGLE_PRECISION_FP_EXTENSION
(0x00000001 << 5)
+#define RISC_V_ISA_ADDITIONAL_STANDARD_EXTENSION
(0x00000001 << 6)
+#define RISC_V_ISA_RESERVED_1 (0x00000001 << 7)
+#define RISC_V_ISA_INTEGER_ISA_EXTENSION (0x00000001
<<
8)
+#define
RISC_V_ISA_DYNAMICALLY_TRANSLATED_LANGUAGE_EXTENSION
(0x00000001 << 9)
+#define RISC_V_ISA_RESERVED_2 (0x00000001 << 10)
+#define RISC_V_ISA_DECIMAL_FP_EXTENSION (0x00000001
<<
11)
+#define RISC_V_ISA_INTEGER_MUL_DIV_EXTENSION
(0x00000001
<< 12)
+#define RISC_V_ISA_USER_LEVEL_INTERRUPT_SUPPORTED
(0x00000001 << 13)
+#define RISC_V_ISA_RESERVED_3 (0x00000001 << 14)
+#define RISC_V_ISA_PACKED_SIMD_EXTENSION
(0x00000001 <<
15)
+#define RISC_V_ISA_QUAD_PRECISION_FP_EXTENSION
(0x00000001 << 16)
+#define RISC_V_ISA_RESERVED_4 (0x00000001 << 17)
+#define RISC_V_ISA_SUPERVISOR_MODE_IMPLEMENTED
(0x00000001 << 18)
+#define RISC_V_ISA_TRANSATIONAL_MEMORY_EXTENSION
(0x00000001 << 19)
+#define RISC_V_ISA_USER_MODE_IMPLEMENTED
(0x00000001
<< 20)
+#define RISC_V_ISA_VECTOR_EXTENSION (0x00000001 <<
21)
+#define RISC_V_ISA_RESERVED_5 (0x00000001 << 22)
+#define RISC_V_ISA_NON_STANDARD_EXTENSION
(0x00000001
<< 23)
+#define RISC_V_ISA_RESERVED_6 (0x00000001 << 24)
+#define RISC_V_ISA_RESERVED_7 (0x00000001 << 25)
+
+//
+// RISC-V CSR definitions.
+//
+//
+// Machine information
+//
+#define RISCV_CSR_MACHINE_MVENDORID 0xF11
+#define RISCV_CSR_MACHINE_MARCHID 0xF12
+#define RISCV_CSR_MACHINE_MIMPID 0xF13
+#define RISCV_CSR_MACHINE_HARRID 0xF14
+//
+// Machine Trap Setup.
+//
+#define RISCV_CSR_MACHINE_MSTATUS 0x300
+#define RISCV_CSR_MACHINE_MISA 0x301
+#define RISCV_CSR_MACHINE_MEDELEG 0x302
+#define RISCV_CSR_MACHINE_MIDELEG 0x303
+#define RISCV_CSR_MACHINE_MIE 0x304
+#define RISCV_CSR_MACHINE_MTVEC 0x305
+
+#define RISCV_TIMER_COMPARE_BITS 32
+//
+// Machine Timer and Counter.
+//
+//#define RISCV_CSR_MACHINE_MTIME 0x701
+//#define RISCV_CSR_MACHINE_MTIMEH 0x741
+//
+// Machine Trap Handling.
+//
+#define RISCV_CSR_MACHINE_MSCRATCH 0x340
+#define RISCV_CSR_MACHINE_MEPC 0x341
+#define RISCV_CSR_MACHINE_MCAUSE 0x342
+ #define MACHINE_MCAUSE_EXCEPTION_ MASK 0x0f
+ #define MACHINE_MCAUSE_INTERRUPT (RISC_V_XLEN_BITS -
1)
+#define RISCV_CSR_MACHINE_MBADADDR 0x343
+#define RISCV_CSR_MACHINE_MIP 0x344
+
+//
+// Machine Protection and Translation.
+//
+#define RISCV_CSR_MACHINE_MBASE 0x380
+#define RISCV_CSR_MACHINE_MBOUND 0x381
+#define RISCV_CSR_MACHINE_MIBASE 0x382
+#define RISCV_CSR_MACHINE_MIBOUND 0x383
+#define RISCV_CSR_MACHINE_MDBASE 0x384
+#define RISCV_CSR_MACHINE_MDBOUND 0x385
+
+//
+// Supervisor mode CSR.
+//
+#define RISCV_CSR_SUPERVISOR_SSTATUS 0x100
+ #define SSTATUS_SIE_BIT_POSITION 1
+ #define SSTATUS_SPP_BIT_POSITION 8
+#define RISCV_CSR_SUPERVISOR_SIE 0x104
+#define RISCV_CSR_SUPERVISOR_SSCRATCH 0x140
+#define RISCV_CSR_SUPERVISOR_SEPC 0x141
+#define RISCV_CSR_SUPERVISOR_SCAUSE 0x142
+ #define SCAUSE_USER_SOFTWARE_INT 0
+ #define SCAUSE_SUPERVISOR_SOFTWARE_INT 1
+ #define SCAUSE_USER_TIMER_INT 4
+ #define SCAUSE_SUPERVISOR_TIMER_INT 5
+ #define SCAUSE_USER_EXTERNAL_INT 8
+ #define SCAUSE_SUPERVISOR_EXTERNAL_INT 9
+#define RISCV_CSR_SUPERVISOR_STVAL 0x143
+#define RISCV_CSR_SUPERVISOR_SIP 0x144
+#define RISCV_CSR_SUPERVISOR_SATP 0x180
+
+#if defined (MDE_CPU_RISCV64)
+ #define RISCV_SATP_MODE_MASK 0xF000000000000000
+ #define RISCV_SATP_MODE_BIT_POSITION 60
+#endif
+ #define RISCV_SATP_MODE_OFF 0
+ #define RISCV_SATP_MODE_SV32 1
+ #define RISCV_SATP_MODE_SV39 8
+ #define RISCV_SATP_MODE_SV48 9
+ #define RISCV_SATP_MODE_SV57 10
+ #define RISCV_SATP_MODE_SV64 11
+
+ #define SATP64_ASID_MASK 0x0FFFF00000000000
+ #define SATP64_PPN_MASK 0x00000FFFFFFFFFFF
+
+#define RISCV_CAUSE_MISALIGNED_FETCH 0x0
+#define RISCV_CAUSE_FETCH_ACCESS 0x1
+#define RISCV_CAUSE_ILLEGAL_INSTRUCTION 0x2
+#define RISCV_CAUSE_BREAKPOINT 0x3
+#define RISCV_CAUSE_MISALIGNED_LOAD 0x4
+#define RISCV_CAUSE_LOAD_ACCESS 0x5
+#define RISCV_CAUSE_MISALIGNED_STORE 0x6
+#define RISCV_CAUSE_STORE_ACCESS 0x7
+#define RISCV_CAUSE_USER_ECALL 0x8
+#define RISCV_CAUSE_HYPERVISOR_ECALL 0x9
+#define RISCV_CAUSE_SUPERVISOR_ECALL 0xa
+#define RISCV_CAUSE_MACHINE_ECALL 0xb
+#define RISCV_CAUSE_FETCH_PAGE_FAULT 0xc
+#define RISCV_CAUSE_LOAD_PAGE_FAULT 0xd
+#define RISCV_CAUSE_STORE_PAGE_FAULT 0xf
+#define RISCV_CAUSE_FETCH_GUEST_PAGE_FAULT 0x14
+#define RISCV_CAUSE_LOAD_GUEST_PAGE_FAULT 0x15
+#define RISCV_CAUSE_STORE_GUEST_PAGE_FAULT 0x17
+
+//
+// Machine Read-Write Shadow of Hypervisor Read-Only Registers
+//
+#define RISCV_CSR_HTIMEW 0xB01
+#define RISCV_CSR_HTIMEHW 0xB81
+//
+// Machine Host-Target Interface (Non-Standard Berkeley
Extension)
+//
+#define RISCV_CSR_MTOHOST 0x780
+#define RISCV_CSR_MFROMHOST 0x781
+
+#endif
diff --git a/Silicon/RISC-V/ProcessorPkg/Include/RiscVImpl.h
b/Silicon/RISC-V/ProcessorPkg/Include/RiscVImpl.h
new file mode 100644
index 0000000000..14092df174
--- /dev/null
+++ b/Silicon/RISC-V/ProcessorPkg/Include/RiscVImpl.h
@@ -0,0 +1,87 @@
+/** @file
+ RISC-V package definitions.
+
+ Copyright (c) 2016 - 2019, Hewlett Packard Enterprise
Development
LP. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef RISCV_H_
+#define RISCV_H_
+
+#include <Uefi.h>
+#include <IndustryStandard/RiscV.h>
+
+#define _ASM_FUNC(Name, Section) \
+ .global Name ; \
+ .section #Section, "ax" ; \
+ .type Name, %function ; \
+ .p2align 2 ; \
+ Name:
+
+#define ASM_FUNC(Name) _ASM_FUNC(ASM_PFX(Name), .text.
##
Name)
+
+#if defined (MDE_CPU_RISCV64)
+typedef UINT64 RISC_V_REGS_PROTOTYPE;
+#else
+#endif
+
+//
+// Structure for 128-bit value
+//
+typedef struct {
+ UINT64 Value64_L;
+ UINT64 Value64_H;
+} RISCV_UINT128;
+
+#define RISCV_MACHINE_CONTEXT_SIZE 0x1000
+typedef struct _RISCV_MACHINE_MODE_CONTEXT
RISCV_MACHINE_MODE_CONTEXT;
+
+///
+/// Exception handlers in context.
+///
+typedef struct _EXCEPTION_HANDLER_CONTEXT {
+ EFI_PHYSICAL_ADDRESS InstAddressMisalignedHander;
+ EFI_PHYSICAL_ADDRESS InstAccessFaultHander;
+ EFI_PHYSICAL_ADDRESS IllegalInstHander;
+ EFI_PHYSICAL_ADDRESS BreakpointHander;
+ EFI_PHYSICAL_ADDRESS LoadAddrMisalignedHander;
+ EFI_PHYSICAL_ADDRESS LoadAccessFaultHander;
+ EFI_PHYSICAL_ADDRESS StoreAmoAddrMisalignedHander;
+ EFI_PHYSICAL_ADDRESS StoreAmoAccessFaultHander;
+ EFI_PHYSICAL_ADDRESS EnvCallFromUModeHander;
+ EFI_PHYSICAL_ADDRESS EnvCallFromSModeHander;
+ EFI_PHYSICAL_ADDRESS EnvCallFromHModeHander;
+ EFI_PHYSICAL_ADDRESS EnvCallFromMModeHander;
+} EXCEPTION_HANDLER_CONTEXT;
+
+///
+/// Exception handlers in context.
+///
+typedef struct _INTERRUPT_HANDLER_CONTEXT {
+ EFI_PHYSICAL_ADDRESS SoftwareIntHandler;
+ EFI_PHYSICAL_ADDRESS TimerIntHandler;
+} INTERRUPT_HANDLER_CONTEXT;
+
+///
+/// Interrupt handlers in context.
+///
+typedef struct _TRAP_HANDLER_CONTEXT {
+ EXCEPTION_HANDLER_CONTEXT ExceptionHandlerContext;
+ INTERRUPT_HANDLER_CONTEXT IntHandlerContext;
+} TRAP_HANDLER_CONTEXT;
+
+///
+/// Machine mode context used for saveing hart-local context.
+///
+typedef struct _RISCV_MACHINE_MODE_CONTEXT {
+ EFI_PHYSICAL_ADDRESS PeiService; /// PEI service.
+ EFI_PHYSICAL_ADDRESS MachineModeTrapHandler; ///
Machine
mode trap handler.
+ EFI_PHYSICAL_ADDRESS HypervisorModeTrapHandler; ///
Hypervisor
mode trap handler.
+ EFI_PHYSICAL_ADDRESS SupervisorModeTrapHandler; ///
Supervisor
mode trap handler.
+ EFI_PHYSICAL_ADDRESS UserModeTrapHandler; /// USer
mode
trap handler.
+ TRAP_HANDLER_CONTEXT MModeHandler; /// Handler for
machine mode.
+} RISCV_MACHINE_MODE_CONTEXT;
+
+#endif
--
2.31.1






Re: [PATCH] UefiPayloadPkg: Not use BaseCpuTimerLib by default.

Ma, Maurice <maurice.ma@...>
 

Reviewed-by: Maurice Ma <maurice.ma@...>

-----Original Message-----
From: Liu, Zhiguang <zhiguang.liu@...>
Sent: Thursday, January 13, 2022 22:15
To: devel@edk2.groups.io
Cc: Dong, Guo <guo.dong@...>; Ni, Ray <ray.ni@...>; Ma,
Maurice <maurice.ma@...>; You, Benjamin
<benjamin.you@...>
Subject: [PATCH] UefiPayloadPkg: Not use BaseCpuTimerLib by default.

For recent X86 CPU, 0x15 CPUID instruction will return Time Stamp Counter.
This is recommended way to get the time, and also how BaseCpuTimerLib
works However, some CPU doesn't support this feature, so disable it by
default.

Cc: Guo Dong <guo.dong@...>
Cc: Ray Ni <ray.ni@...>
Cc: Maurice Ma <maurice.ma@...>
Cc: Benjamin You <benjamin.you@...>
Signed-off-by: Zhiguang Liu <zhiguang.liu@...>
---
UefiPayloadPkg/UefiPayloadPkg.dsc | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc
b/UefiPayloadPkg/UefiPayloadPkg.dsc
index 3d08edfe31..65c1bd610e 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.dsc
+++ b/UefiPayloadPkg/UefiPayloadPkg.dsc
@@ -111,6 +111,11 @@
DEFINE SERIAL_DRIVER_ENABLE = TRUE DEFINE
PERFORMANCE_MEASUREMENT_ENABLE = FALSE + # For recent X86 CPU,
0x15 CPUID instruction will return Time Stamp Counter.+ # This is
recommended way to get the time, and also how BaseCpuTimerLib works.+
# However, some CPU doesn't support this feature, so disable it by default.+
DEFINE CPU_TIMER_LIB_ENABLE = FALSE+ [BuildOptions]
*_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES
GCC:*_UNIXGCC_*_CC_FLAGS = -DMDEPKG_NDEBUG@@ -217,7 +222,7
@@
# # Platform #-!if $(UNIVERSAL_PAYLOAD) == TRUE+!if
$(CPU_TIMER_LIB_ENABLE) == TRUE
TimerLib|UefiCpuPkg/Library/CpuTimerLib/BaseCpuTimerLib.inf !else
TimerLib|UefiPayloadPkg/Library/AcpiTimerLib/AcpiTimerLib.inf--
2.32.0.windows.2


Re: [PATCH 01/79] ProcessorPkg/Include: Add header files of RISC-V processor package

Abner Chang
 

-----Original Message-----
From: Kinney, Michael D <michael.d.kinney@...>
Sent: Friday, January 14, 2022 12:38 AM
To: Chang, Abner (HPS SW/FW Technologist) <abner.chang@...>; Leif
Lindholm <leif@...>; devel@edk2.groups.io; Ni, Ray
<ray.ni@...>; Kinney, Michael D <michael.d.kinney@...>
Cc: Andrew Fish <afish@...>; Sami Mujawar
<Sami.Mujawar@...>
Subject: RE: [edk2-devel] [PATCH 01/79] ProcessorPkg/Include: Add header
files of RISC-V processor package

Hi Abner,

General recommendations included below. Of course each
lib/modules/include needs to be reviewed and the
best location selected. I am aware that there are components in edk2 that
do not follow these general
recommendations. This is due to content that was added before these
recommendations were established
and we have work to do to get everything aligned.

Mike

-----Original Message-----
From: Chang, Abner (HPS SW/FW Technologist) <abner.chang@...>
Sent: Wednesday, January 12, 2022 9:34 PM
To: Kinney, Michael D <michael.d.kinney@...>; Leif Lindholm
<leif@...>; devel@edk2.groups.io; Ni, Ray
<ray.ni@...>
Cc: Andrew Fish <afish@...>; Sami Mujawar
<Sami.Mujawar@...>
Subject: RE: [edk2-devel] [PATCH 01/79] ProcessorPkg/Include: Add
header files of RISC-V processor package

HI Mike,
It is no problem to meet there. However, I am not available to join the
design meeting in the next two weeks. Before we can get
together to discuss the best locations, do you have information regarding
the rationale of driver/library location?

What is the best location for,
- Processor ARCH dependent modules
MdePkg for libs
UefiCpuPkg for modules

- Common modules for all processor ARCHs
Feature Packages based on the common feature. Add to existing if it fits.
Create new for completely new feature area.

- Platform module that is specific to processor ARCH?
edk2-platform repository
How about Leif's suggestion? The CommonPlatformPkg on edk2?

Abner


The only exception so far are platform modules used to support
OvmfPkg/QEMU to support CI.
In this case the modules are added to OvmfPkg.

- Platform module that is common to processor ARCHs?
edk2-platform repository

The only exception so far are platform modules used to support
OvmfPkg/QEMU to support CI.
In this case the modules are added to OvmfPkg.


Thanks
Abner

-----Original Message-----
From: Kinney, Michael D <michael.d.kinney@...>
Sent: Monday, January 10, 2022 11:58 PM
To: Leif Lindholm <leif@...>; devel@edk2.groups.io; Chang,
Abner
(HPS SW/FW Technologist) <abner.chang@...>; Kinney, Michael D
<michael.d.kinney@...>; Ni, Ray <ray.ni@...>
Cc: Andrew Fish <afish@...>; Sami Mujawar
<Sami.Mujawar@...>
Subject: RE: [edk2-devel] [PATCH 01/79] ProcessorPkg/Include: Add
header
files of RISC-V processor package

Hi Abner,

I see comments from Leif as well.

Do you think a discussion in the design meeting Ray Ni runs would be
valuable
to review all the modules/libs/includes and discuss options for the best
location for them to reside in the edk2 repos?

Thanks,

Mike

-----Original Message-----
From: Kinney, Michael D <michael.d.kinney@...>
Sent: Monday, January 10, 2022 7:55 AM
To: Leif Lindholm <leif@...>; devel@edk2.groups.io; Chang,
Abner <abner.chang@...>; Kinney, Michael D
<michael.d.kinney@...>
Cc: Andrew Fish <afish@...>; Sami Mujawar
<Sami.Mujawar@...>
Subject: RE: [edk2-devel] [PATCH 01/79] ProcessorPkg/Include: Add
header files of RISC-V processor package

Hi Abner,

I would also like to see some proposals on adding the RiscV CPU scoped
content
to the existing MdePkg/UefiCpuPkg instead of adding a new top level
CPU
package.

There is already some work started to move some of the ARM specific
content
from ARM CPU packages into MdePkg.

Thanks,

Mike

-----Original Message-----
From: Leif Lindholm <leif@...>
Sent: Monday, January 10, 2022 5:11 AM
To: devel@edk2.groups.io; Chang, Abner <abner.chang@...>
Cc: Andrew Fish <afish@...>; Kinney, Michael D
<michael.d.kinney@...>; Sami Mujawar
<Sami.Mujawar@...>
Subject: Re: [edk2-devel] [PATCH 01/79] ProcessorPkg/Include: Add
header files of RISC-V processor package

On Sat, Jan 08, 2022 at 12:07:53 +0800, Abner Chang wrote:
(This is migrated from edk2-platforms:Silicon/RISC-V)

RISC-V processor package library definitions.

IndustryStandard/RiscV.h
-Add RiscV.h which conform with RISC-V Privilege Spec v1.10.

RiscVImpl.h
-Definition of EDK2 RISC-V implementation.

Signed-off-by: Abner Chang <abner.chang@...>
Co-authored-by: Daniel Schaefer <daniel.schaefer@...>
Co-authored-by: Gilbert Chen <gilbert.chen@...>
Reviewed-by: Leif Lindholm <leif.lindholm@...>
Hmm, no.
I gave a reviewed-by for that patch to be merged into edk2-platforms
once upon a time. This is not relevant for migration to edk2.

My proposal for migrating this code would be as follows:
- Announce a hold on merging new code to RiscV portions of
edk2-platforms.
- Apply any and all bugfixes and CI/uncrustify fixes in place in
edk2-platforms.
- Get some level of agreement for what to do instead of
RiscVPlatformPkg - i.e. slot into MdeModulePkg instead.
- If that cannot be reached within a few days, create a new
top-level directory called "CommonPlatformPkg" or something,
with you, Daniel(/Gilbert?), Sami, me as maintainers.
- Move all of the RiscVPlatformPkg code under there instead.
- I'll follow with ArmPlatformPkg.
- PC/AT code should move across too over time.
- Move the rest of the code across unmodified as massive single
patches per package (potentially more patches than that for
RiscVPlatformPkg).
- Drop all existing Reviewed-by/Acked-by.
- After each "move" patch, insert a "fixup" patch to address the
things that need fixing due to path/name changes.

/
Leif

Cc: Leif Lindholm <leif.lindholm@...>
Cc: Gilbert Chen <gilbert.chen@...>
---
.../Include/IndustryStandard/RiscV.h | 156
++++++++++++++++++
.../RISC-V/ProcessorPkg/Include/RiscVImpl.h | 87 ++++++++++
2 files changed, 243 insertions(+)
create mode 100644 Silicon/RISC-
V/ProcessorPkg/Include/IndustryStandard/RiscV.h
create mode 100644 Silicon/RISC-
V/ProcessorPkg/Include/RiscVImpl.h

diff --git a/Silicon/RISC-
V/ProcessorPkg/Include/IndustryStandard/RiscV.h b/Silicon/RISC-
V/ProcessorPkg/Include/IndustryStandard/RiscV.h
new file mode 100644
index 0000000000..2a992394ed
--- /dev/null
+++ b/Silicon/RISC-
V/ProcessorPkg/Include/IndustryStandard/RiscV.h
@@ -0,0 +1,156 @@
+/** @file
+ RISC-V package definitions.
+
+ Copyright (c) 2019, Hewlett Packard Enterprise Development LP.
All
rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef RISCV_INDUSTRY_STANDARD_H_
+#define RISCV_INDUSTRY_STANDARD_H_
+
+#if defined (MDE_CPU_RISCV64)
+#define RISC_V_XLEN_BITS 64
+#else
+#endif
+
+#define RISC_V_ISA_ATOMIC_EXTENSION (0x00000001 <<
0)
+#define RISC_V_ISA_BIT_OPERATION_EXTENSION
(0x00000001
<< 1)
+#define RISC_V_ISA_COMPRESSED_EXTENSION (0x00000001
<<
2)
+#define RISC_V_ISA_DOUBLE_PRECISION_FP_EXTENSION
(0x00000001 << 3)
+#define RISC_V_ISA_RV32E_ISA (0x00000001 << 4)
+#define RISC_V_ISA_SINGLE_PRECISION_FP_EXTENSION
(0x00000001 << 5)
+#define RISC_V_ISA_ADDITIONAL_STANDARD_EXTENSION
(0x00000001 << 6)
+#define RISC_V_ISA_RESERVED_1 (0x00000001 << 7)
+#define RISC_V_ISA_INTEGER_ISA_EXTENSION (0x00000001
<<
8)
+#define
RISC_V_ISA_DYNAMICALLY_TRANSLATED_LANGUAGE_EXTENSION
(0x00000001 << 9)
+#define RISC_V_ISA_RESERVED_2 (0x00000001 << 10)
+#define RISC_V_ISA_DECIMAL_FP_EXTENSION (0x00000001
<<
11)
+#define RISC_V_ISA_INTEGER_MUL_DIV_EXTENSION
(0x00000001
<< 12)
+#define RISC_V_ISA_USER_LEVEL_INTERRUPT_SUPPORTED
(0x00000001 << 13)
+#define RISC_V_ISA_RESERVED_3 (0x00000001 << 14)
+#define RISC_V_ISA_PACKED_SIMD_EXTENSION
(0x00000001 <<
15)
+#define RISC_V_ISA_QUAD_PRECISION_FP_EXTENSION
(0x00000001 << 16)
+#define RISC_V_ISA_RESERVED_4 (0x00000001 << 17)
+#define RISC_V_ISA_SUPERVISOR_MODE_IMPLEMENTED
(0x00000001 << 18)
+#define RISC_V_ISA_TRANSATIONAL_MEMORY_EXTENSION
(0x00000001 << 19)
+#define RISC_V_ISA_USER_MODE_IMPLEMENTED
(0x00000001
<< 20)
+#define RISC_V_ISA_VECTOR_EXTENSION (0x00000001 <<
21)
+#define RISC_V_ISA_RESERVED_5 (0x00000001 << 22)
+#define RISC_V_ISA_NON_STANDARD_EXTENSION
(0x00000001
<< 23)
+#define RISC_V_ISA_RESERVED_6 (0x00000001 << 24)
+#define RISC_V_ISA_RESERVED_7 (0x00000001 << 25)
+
+//
+// RISC-V CSR definitions.
+//
+//
+// Machine information
+//
+#define RISCV_CSR_MACHINE_MVENDORID 0xF11
+#define RISCV_CSR_MACHINE_MARCHID 0xF12
+#define RISCV_CSR_MACHINE_MIMPID 0xF13
+#define RISCV_CSR_MACHINE_HARRID 0xF14
+//
+// Machine Trap Setup.
+//
+#define RISCV_CSR_MACHINE_MSTATUS 0x300
+#define RISCV_CSR_MACHINE_MISA 0x301
+#define RISCV_CSR_MACHINE_MEDELEG 0x302
+#define RISCV_CSR_MACHINE_MIDELEG 0x303
+#define RISCV_CSR_MACHINE_MIE 0x304
+#define RISCV_CSR_MACHINE_MTVEC 0x305
+
+#define RISCV_TIMER_COMPARE_BITS 32
+//
+// Machine Timer and Counter.
+//
+//#define RISCV_CSR_MACHINE_MTIME 0x701
+//#define RISCV_CSR_MACHINE_MTIMEH 0x741
+//
+// Machine Trap Handling.
+//
+#define RISCV_CSR_MACHINE_MSCRATCH 0x340
+#define RISCV_CSR_MACHINE_MEPC 0x341
+#define RISCV_CSR_MACHINE_MCAUSE 0x342
+ #define MACHINE_MCAUSE_EXCEPTION_ MASK 0x0f
+ #define MACHINE_MCAUSE_INTERRUPT (RISC_V_XLEN_BITS -
1)
+#define RISCV_CSR_MACHINE_MBADADDR 0x343
+#define RISCV_CSR_MACHINE_MIP 0x344
+
+//
+// Machine Protection and Translation.
+//
+#define RISCV_CSR_MACHINE_MBASE 0x380
+#define RISCV_CSR_MACHINE_MBOUND 0x381
+#define RISCV_CSR_MACHINE_MIBASE 0x382
+#define RISCV_CSR_MACHINE_MIBOUND 0x383
+#define RISCV_CSR_MACHINE_MDBASE 0x384
+#define RISCV_CSR_MACHINE_MDBOUND 0x385
+
+//
+// Supervisor mode CSR.
+//
+#define RISCV_CSR_SUPERVISOR_SSTATUS 0x100
+ #define SSTATUS_SIE_BIT_POSITION 1
+ #define SSTATUS_SPP_BIT_POSITION 8
+#define RISCV_CSR_SUPERVISOR_SIE 0x104
+#define RISCV_CSR_SUPERVISOR_SSCRATCH 0x140
+#define RISCV_CSR_SUPERVISOR_SEPC 0x141
+#define RISCV_CSR_SUPERVISOR_SCAUSE 0x142
+ #define SCAUSE_USER_SOFTWARE_INT 0
+ #define SCAUSE_SUPERVISOR_SOFTWARE_INT 1
+ #define SCAUSE_USER_TIMER_INT 4
+ #define SCAUSE_SUPERVISOR_TIMER_INT 5
+ #define SCAUSE_USER_EXTERNAL_INT 8
+ #define SCAUSE_SUPERVISOR_EXTERNAL_INT 9
+#define RISCV_CSR_SUPERVISOR_STVAL 0x143
+#define RISCV_CSR_SUPERVISOR_SIP 0x144
+#define RISCV_CSR_SUPERVISOR_SATP 0x180
+
+#if defined (MDE_CPU_RISCV64)
+ #define RISCV_SATP_MODE_MASK 0xF000000000000000
+ #define RISCV_SATP_MODE_BIT_POSITION 60
+#endif
+ #define RISCV_SATP_MODE_OFF 0
+ #define RISCV_SATP_MODE_SV32 1
+ #define RISCV_SATP_MODE_SV39 8
+ #define RISCV_SATP_MODE_SV48 9
+ #define RISCV_SATP_MODE_SV57 10
+ #define RISCV_SATP_MODE_SV64 11
+
+ #define SATP64_ASID_MASK 0x0FFFF00000000000
+ #define SATP64_PPN_MASK 0x00000FFFFFFFFFFF
+
+#define RISCV_CAUSE_MISALIGNED_FETCH 0x0
+#define RISCV_CAUSE_FETCH_ACCESS 0x1
+#define RISCV_CAUSE_ILLEGAL_INSTRUCTION 0x2
+#define RISCV_CAUSE_BREAKPOINT 0x3
+#define RISCV_CAUSE_MISALIGNED_LOAD 0x4
+#define RISCV_CAUSE_LOAD_ACCESS 0x5
+#define RISCV_CAUSE_MISALIGNED_STORE 0x6
+#define RISCV_CAUSE_STORE_ACCESS 0x7
+#define RISCV_CAUSE_USER_ECALL 0x8
+#define RISCV_CAUSE_HYPERVISOR_ECALL 0x9
+#define RISCV_CAUSE_SUPERVISOR_ECALL 0xa
+#define RISCV_CAUSE_MACHINE_ECALL 0xb
+#define RISCV_CAUSE_FETCH_PAGE_FAULT 0xc
+#define RISCV_CAUSE_LOAD_PAGE_FAULT 0xd
+#define RISCV_CAUSE_STORE_PAGE_FAULT 0xf
+#define RISCV_CAUSE_FETCH_GUEST_PAGE_FAULT 0x14
+#define RISCV_CAUSE_LOAD_GUEST_PAGE_FAULT 0x15
+#define RISCV_CAUSE_STORE_GUEST_PAGE_FAULT 0x17
+
+//
+// Machine Read-Write Shadow of Hypervisor Read-Only Registers
+//
+#define RISCV_CSR_HTIMEW 0xB01
+#define RISCV_CSR_HTIMEHW 0xB81
+//
+// Machine Host-Target Interface (Non-Standard Berkeley
Extension)
+//
+#define RISCV_CSR_MTOHOST 0x780
+#define RISCV_CSR_MFROMHOST 0x781
+
+#endif
diff --git a/Silicon/RISC-V/ProcessorPkg/Include/RiscVImpl.h
b/Silicon/RISC-V/ProcessorPkg/Include/RiscVImpl.h
new file mode 100644
index 0000000000..14092df174
--- /dev/null
+++ b/Silicon/RISC-V/ProcessorPkg/Include/RiscVImpl.h
@@ -0,0 +1,87 @@
+/** @file
+ RISC-V package definitions.
+
+ Copyright (c) 2016 - 2019, Hewlett Packard Enterprise
Development
LP. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef RISCV_H_
+#define RISCV_H_
+
+#include <Uefi.h>
+#include <IndustryStandard/RiscV.h>
+
+#define _ASM_FUNC(Name, Section) \
+ .global Name ; \
+ .section #Section, "ax" ; \
+ .type Name, %function ; \
+ .p2align 2 ; \
+ Name:
+
+#define ASM_FUNC(Name) _ASM_FUNC(ASM_PFX(Name), .text.
##
Name)
+
+#if defined (MDE_CPU_RISCV64)
+typedef UINT64 RISC_V_REGS_PROTOTYPE;
+#else
+#endif
+
+//
+// Structure for 128-bit value
+//
+typedef struct {
+ UINT64 Value64_L;
+ UINT64 Value64_H;
+} RISCV_UINT128;
+
+#define RISCV_MACHINE_CONTEXT_SIZE 0x1000
+typedef struct _RISCV_MACHINE_MODE_CONTEXT
RISCV_MACHINE_MODE_CONTEXT;
+
+///
+/// Exception handlers in context.
+///
+typedef struct _EXCEPTION_HANDLER_CONTEXT {
+ EFI_PHYSICAL_ADDRESS InstAddressMisalignedHander;
+ EFI_PHYSICAL_ADDRESS InstAccessFaultHander;
+ EFI_PHYSICAL_ADDRESS IllegalInstHander;
+ EFI_PHYSICAL_ADDRESS BreakpointHander;
+ EFI_PHYSICAL_ADDRESS LoadAddrMisalignedHander;
+ EFI_PHYSICAL_ADDRESS LoadAccessFaultHander;
+ EFI_PHYSICAL_ADDRESS StoreAmoAddrMisalignedHander;
+ EFI_PHYSICAL_ADDRESS StoreAmoAccessFaultHander;
+ EFI_PHYSICAL_ADDRESS EnvCallFromUModeHander;
+ EFI_PHYSICAL_ADDRESS EnvCallFromSModeHander;
+ EFI_PHYSICAL_ADDRESS EnvCallFromHModeHander;
+ EFI_PHYSICAL_ADDRESS EnvCallFromMModeHander;
+} EXCEPTION_HANDLER_CONTEXT;
+
+///
+/// Exception handlers in context.
+///
+typedef struct _INTERRUPT_HANDLER_CONTEXT {
+ EFI_PHYSICAL_ADDRESS SoftwareIntHandler;
+ EFI_PHYSICAL_ADDRESS TimerIntHandler;
+} INTERRUPT_HANDLER_CONTEXT;
+
+///
+/// Interrupt handlers in context.
+///
+typedef struct _TRAP_HANDLER_CONTEXT {
+ EXCEPTION_HANDLER_CONTEXT ExceptionHandlerContext;
+ INTERRUPT_HANDLER_CONTEXT IntHandlerContext;
+} TRAP_HANDLER_CONTEXT;
+
+///
+/// Machine mode context used for saveing hart-local context.
+///
+typedef struct _RISCV_MACHINE_MODE_CONTEXT {
+ EFI_PHYSICAL_ADDRESS PeiService; /// PEI service.
+ EFI_PHYSICAL_ADDRESS MachineModeTrapHandler; ///
Machine
mode trap handler.
+ EFI_PHYSICAL_ADDRESS HypervisorModeTrapHandler; ///
Hypervisor
mode trap handler.
+ EFI_PHYSICAL_ADDRESS SupervisorModeTrapHandler; ///
Supervisor
mode trap handler.
+ EFI_PHYSICAL_ADDRESS UserModeTrapHandler; /// USer
mode
trap handler.
+ TRAP_HANDLER_CONTEXT MModeHandler; /// Handler for
machine mode.
+} RISCV_MACHINE_MODE_CONTEXT;
+
+#endif
--
2.31.1





5201 - 5220 of 90847