Date   

Re: [Patch V3] UefiPayloadPkg: Use DynamicEx instead of Dynamic to pass PCD across binary

Guo Dong
 

This patch 1) changed PCD type from Dynamic to DynamicEX 2) added 3 PCDs.
It would be great if you could describe why 3 PCDs are added in the commit message.

With that:
Reviewed-by: Guo Dong <guo.dong@intel.com>

Thanks,
Guo

-----Original Message-----
From: Liu, Zhiguang <zhiguang.liu@intel.com>
Sent: Wednesday, June 9, 2021 6:38 PM
To: devel@edk2.groups.io
Cc: Ma, Maurice <maurice.ma@intel.com>; Dong, Guo
<guo.dong@intel.com>; You, Benjamin <benjamin.you@intel.com>
Subject: [Patch V3] UefiPayloadPkg: Use DynamicEx instead of Dynamic to
pass PCD across binary

V1:
When passing PCD database from Edk2 boot loader to Universal Payload, the
local
token number in boot loader PCD database can be different with that in
Payload
PCD database.
Dynamic PCD directly use local token number, while DynamicEx will search
token number
by Guid and ExTokenNumber, which are unique pair and can make sure
finding the correct
token number in boot loader's PCD database
V2:
Remove PCD PcdFlashNvStorageFtwWorkingBase and
PcdFlashNvStorageFtwSpareBase, because they
are not consumed by any modules.
Explicitly define some PCDs as DynamicEx, or their default type will be
Dynamic

V3:
Not remove some PCDs for they will be consumed soon

Cc: Maurice Ma <maurice.ma@intel.com>
Cc: Guo Dong <guo.dong@intel.com>
Cc: Benjamin You <benjamin.you@intel.com>

Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
---
UefiPayloadPkg/UefiPayloadPkg.dsc | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc
b/UefiPayloadPkg/UefiPayloadPkg.dsc
index 37ad5a0ae7..4b0ec3a059 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.dsc
+++ b/UefiPayloadPkg/UefiPayloadPkg.dsc
@@ -336,11 +336,11 @@



##########################################################
######################

#

-# Pcd Dynamic Section - list of all EDK II PCD Entries defined by this Platform

+# Pcd DynamicEx Section - list of all EDK II PCD Entries defined by this
Platform

#


##########################################################
######################



-[PcdsDynamicDefault]

+[PcdsDynamicExDefault]

gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved|0

gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64|0


gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0

@@ -363,6 +363,9 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdConOutColumn|100

gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0

gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseSize|0

+ gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase|0

+ gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed|FALSE

+ gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|0




##########################################################
######################

#

--
2.30.0.windows.2


Re: [Patch V4 9/9] UefiPayloadPkg: Creat gPldAcpiTableGuid Hob

Guo Dong
 

Reviewed-by: Guo Dong <guo.dong@intel.com>

-----Original Message-----
From: Liu, Zhiguang <zhiguang.liu@intel.com>
Sent: Wednesday, June 9, 2021 6:33 PM
To: devel@edk2.groups.io
Cc: Ma, Maurice <maurice.ma@intel.com>; Dong, Guo
<guo.dong@intel.com>; You, Benjamin <benjamin.you@intel.com>; Ni, Ray
<ray.ni@intel.com>
Subject: [Patch V4 9/9] UefiPayloadPkg: Creat gPldAcpiTableGuid Hob

From SysTableInfo Hob, get ACPI table address, and creat gPldAcpiTableGuid
Hob
to store it. Remove diretly adding ACPI table to ConfigurationTable.
Dxe ACPI driver will parse it and install ACPI table from Guid Hob.

Cc: Maurice Ma <maurice.ma@intel.com>
Cc: Guo Dong <guo.dong@intel.com>
Cc: Benjamin You <benjamin.you@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
---
UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c | 17 -----------------
UefiPayloadPkg/BlSupportDxe/BlSupportDxe.h | 5 +----
UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf | 1 -
UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c | 11 +++++++++++
UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h | 2 +-
UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf | 1 +
UefiPayloadPkg/UefiPayloadPkg.fdf | 4 ++++
7 files changed, 18 insertions(+), 23 deletions(-)

diff --git a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c
b/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c
index 56b85b8e6d..ffd3427fb3 100644
--- a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c
+++ b/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c
@@ -99,7 +99,6 @@ BlDxeEntryPoint (
{

EFI_STATUS Status;

EFI_HOB_GUID_TYPE *GuidHob;

- SYSTEM_TABLE_INFO *SystemTableInfo;

EFI_PEI_GRAPHICS_INFO_HOB *GfxInfo;

ACPI_BOARD_INFO *AcpiBoardInfo;



@@ -113,22 +112,6 @@ BlDxeEntryPoint (
Status = ReserveResourceInGcd (TRUE,
EfiGcdMemoryTypeMemoryMappedIo, 0xFED00000, SIZE_1KB, 0,
ImageHandle); // HPET

ASSERT_EFI_ERROR (Status);



- //

- // Find the system table information guid hob

- //

- GuidHob = GetFirstGuidHob (&gUefiSystemTableInfoGuid);

- ASSERT (GuidHob != NULL);

- SystemTableInfo = (SYSTEM_TABLE_INFO *)GET_GUID_HOB_DATA
(GuidHob);

-

- //

- // Install Acpi Table

- //

- if (SystemTableInfo->AcpiTableBase != 0 && SystemTableInfo-
AcpiTableSize != 0) {
- DEBUG ((DEBUG_ERROR, "Install Acpi Table at 0x%lx, length 0x%x\n",
SystemTableInfo->AcpiTableBase, SystemTableInfo->AcpiTableSize));

- Status = gBS->InstallConfigurationTable (&gEfiAcpiTableGuid, (VOID
*)(UINTN)SystemTableInfo->AcpiTableBase);

- ASSERT_EFI_ERROR (Status);

- }

-

//

// Find the frame buffer information and update PCDs

//

diff --git a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.h
b/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.h
index 512105fafd..3332a30eae 100644
--- a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.h
+++ b/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.h
@@ -1,7 +1,7 @@
/** @file

The header file of bootloader support DXE.



-Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>

+Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>

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



**/

@@ -19,12 +19,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/IoLib.h>

#include <Library/HobLib.h>



-#include <Guid/Acpi.h>

#include <Guid/SmBios.h>

#include <Guid/SystemTableInfoGuid.h>

#include <Guid/AcpiBoardInfoGuid.h>

#include <Guid/GraphicsInfoHob.h>



-#include <IndustryStandard/Acpi.h>

-

#endif

diff --git a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf
b/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf
index 30f41f8c39..1ccb250991 100644
--- a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf
+++ b/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf
@@ -42,7 +42,6 @@
HobLib



[Guids]

- gEfiAcpiTableGuid

gUefiSystemTableInfoGuid

gUefiAcpiBoardInfoGuid

gEfiGraphicsInfoHobGuid

diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c
b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c
index 80f66a3fd5..f44e0ea7f0 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c
+++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c
@@ -235,6 +235,7 @@ BuildHobFromBl (
EFI_PEI_GRAPHICS_DEVICE_INFO_HOB GfxDeviceInfo;

EFI_PEI_GRAPHICS_DEVICE_INFO_HOB *NewGfxDeviceInfo;

UNIVERSAL_PAYLOAD_SMBIOS_TABLE *SmBiosTableHob;

+ UNIVERSAL_PAYLOAD_ACPI_TABLE *AcpiTableHob;



//

// Parse memory info and build memory HOBs

@@ -287,6 +288,16 @@ BuildHobFromBl (
SmBiosTableHob->SmBiosEntryPoint = SysTableInfo.SmbiosTableBase;

DEBUG ((DEBUG_INFO, "Create smbios table
gUniversalPayloadSmbiosTableGuid guid hob\n"));



+ //

+ // Creat ACPI table Hob

+ //

+ AcpiTableHob = BuildGuidHob (&gUniversalPayloadAcpiTableGuid, sizeof
(UNIVERSAL_PAYLOAD_ACPI_TABLE));

+ ASSERT (AcpiTableHob != NULL);

+ AcpiTableHob->Header.Revision =
UNIVERSAL_PAYLOAD_ACPI_TABLE_REVISION;

+ AcpiTableHob->Header.Length = sizeof
(UNIVERSAL_PAYLOAD_ACPI_TABLE);

+ AcpiTableHob->Rsdp = SysTableInfo.AcpiTableBase;

+ DEBUG ((DEBUG_INFO, "Create smbios table
gUniversalPayloadAcpiTableGuid guid hob\n"));

+

//

// Create guid hob for acpi board information

//

diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h
b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h
index e7d0d15118..a4c9da128e 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h
+++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h
@@ -32,7 +32,7 @@
#include <Guid/AcpiBoardInfoGuid.h>

#include <Guid/GraphicsInfoHob.h>

#include <UniversalPayload/SmbiosTable.h>

-

+#include <UniversalPayload/AcpiTable.h>



#define LEGACY_8259_MASK_REGISTER_MASTER 0x21

#define LEGACY_8259_MASK_REGISTER_SLAVE 0xA1

diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
index fc5b5ce9d4..8d42925fcd 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
+++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
@@ -65,6 +65,7 @@
gEfiGraphicsDeviceInfoHobGuid

gUefiAcpiBoardInfoGuid

gUniversalPayloadSmbiosTableGuid

+ gUniversalPayloadAcpiTableGuid



[FeaturePcd.IA32]

gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode ##
CONSUMES

diff --git a/UefiPayloadPkg/UefiPayloadPkg.fdf
b/UefiPayloadPkg/UefiPayloadPkg.fdf
index 8fc509024b..ed7fbcaddb 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.fdf
+++ b/UefiPayloadPkg/UefiPayloadPkg.fdf
@@ -175,6 +175,10 @@ INF
MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe.inf
INF MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf

INF MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf



+#

+# ACPI Support

+#

+INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf



#

# Shell

--
2.30.0.windows.2


Re: [Patch V4 6/9] UefiPayloadPkg: Creat gPldSmbiosTableGuid Hob

Guo Dong
 

Reviewed-by: Guo Dong <guo.dong@intel.com>

-----Original Message-----
From: Liu, Zhiguang <zhiguang.liu@intel.com>
Sent: Wednesday, June 9, 2021 6:33 PM
To: devel@edk2.groups.io
Cc: Ma, Maurice <maurice.ma@intel.com>; Dong, Guo
<guo.dong@intel.com>; You, Benjamin <benjamin.you@intel.com>
Subject: [Patch V4 6/9] UefiPayloadPkg: Creat gPldSmbiosTableGuid Hob

From SysTableInfo Hob, get Smbios table address, and creat
gPldSmbiosTableGuid Hob
to store it. Remove diretly adding smbios table to ConfigurationTable.
Dxe module SmbiosDxe will parse it and install smbios table from it.

Cc: Maurice Ma <maurice.ma@intel.com>
Cc: Guo Dong <guo.dong@intel.com>
Cc: Benjamin You <benjamin.you@intel.com>
Reviewed-by: Guo Dong <guo.dong@intel.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
---
UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c | 11 +----------
UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf | 3 +--
UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c | 12 +++++++++++-
UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h | 3 ++-
UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf | 3 ++-
5 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c
b/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c
index a746d0581e..56b85b8e6d 100644
--- a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c
+++ b/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c
@@ -2,7 +2,7 @@
This driver will report some MMIO/IO resources to dxe core, extract smbios
and acpi

tables from bootloader.



- Copyright (c) 2014 - 2020, Intel Corporation. All rights reserved.<BR>

+ Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.<BR>

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



**/

@@ -129,15 +129,6 @@ BlDxeEntryPoint (
ASSERT_EFI_ERROR (Status);

}



- //

- // Install Smbios Table

- //

- if (SystemTableInfo->SmbiosTableBase != 0 && SystemTableInfo-
SmbiosTableSize != 0) {
- DEBUG ((DEBUG_ERROR, "Install Smbios Table at 0x%lx, length 0x%x\n",
SystemTableInfo->SmbiosTableBase, SystemTableInfo->SmbiosTableSize));

- Status = gBS->InstallConfigurationTable (&gEfiSmbiosTableGuid, (VOID
*)(UINTN)SystemTableInfo->SmbiosTableBase);

- ASSERT_EFI_ERROR (Status);

- }

-

//

// Find the frame buffer information and update PCDs

//

diff --git a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf
b/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf
index cebc811355..30f41f8c39 100644
--- a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf
+++ b/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf
@@ -3,7 +3,7 @@
#

# Report some MMIO/IO resources to dxe core, extract smbios and acpi
tables

#

-# Copyright (c) 2014 - 2020, Intel Corporation. All rights reserved.<BR>

+# Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.<BR>

#

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

#

@@ -43,7 +43,6 @@


[Guids]

gEfiAcpiTableGuid

- gEfiSmbiosTableGuid

gUefiSystemTableInfoGuid

gUefiAcpiBoardInfoGuid

gEfiGraphicsInfoHobGuid

diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c
b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c
index 805f5448d9..80f66a3fd5 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c
+++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c
@@ -1,6 +1,6 @@
/** @file



- Copyright (c) 2014 - 2020, Intel Corporation. All rights reserved.<BR>

+ Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.<BR>

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



**/

@@ -234,6 +234,7 @@ BuildHobFromBl (
EFI_PEI_GRAPHICS_INFO_HOB *NewGfxInfo;

EFI_PEI_GRAPHICS_DEVICE_INFO_HOB GfxDeviceInfo;

EFI_PEI_GRAPHICS_DEVICE_INFO_HOB *NewGfxDeviceInfo;

+ UNIVERSAL_PAYLOAD_SMBIOS_TABLE *SmBiosTableHob;



//

// Parse memory info and build memory HOBs

@@ -276,6 +277,15 @@ BuildHobFromBl (
DEBUG ((DEBUG_INFO, "Detected Acpi Table at 0x%lx, length 0x%x\n",
SysTableInfo.AcpiTableBase, SysTableInfo.AcpiTableSize));

DEBUG ((DEBUG_INFO, "Detected Smbios Table at 0x%lx, length 0x%x\n",
SysTableInfo.SmbiosTableBase, SysTableInfo.SmbiosTableSize));

}

+ //

+ // Creat SmBios table Hob

+ //

+ SmBiosTableHob = BuildGuidHob (&gUniversalPayloadSmbiosTableGuid,
sizeof (UNIVERSAL_PAYLOAD_SMBIOS_TABLE));

+ ASSERT (SmBiosTableHob != NULL);

+ SmBiosTableHob->Header.Revision =
UNIVERSAL_PAYLOAD_SMBIOS_TABLE_REVISION;

+ SmBiosTableHob->Header.Length = sizeof
(UNIVERSAL_PAYLOAD_SMBIOS_TABLE);

+ SmBiosTableHob->SmBiosEntryPoint = SysTableInfo.SmbiosTableBase;

+ DEBUG ((DEBUG_INFO, "Create smbios table
gUniversalPayloadSmbiosTableGuid guid hob\n"));



//

// Create guid hob for acpi board information

diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h
b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h
index 2c84d6ed53..e7d0d15118 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h
+++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h
@@ -1,6 +1,6 @@
/** @file

*

-* Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>

+* Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>

*

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

*

@@ -31,6 +31,7 @@
#include <Guid/MemoryMapInfoGuid.h>

#include <Guid/AcpiBoardInfoGuid.h>

#include <Guid/GraphicsInfoHob.h>

+#include <UniversalPayload/SmbiosTable.h>





#define LEGACY_8259_MASK_REGISTER_MASTER 0x21

diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
index cc59f1903b..fc5b5ce9d4 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
+++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
@@ -1,7 +1,7 @@
## @file

# This is the first module for UEFI payload.

#

-# Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.<BR>

+# Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>

# Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>

#

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

@@ -64,6 +64,7 @@
gEfiGraphicsInfoHobGuid

gEfiGraphicsDeviceInfoHobGuid

gUefiAcpiBoardInfoGuid

+ gUniversalPayloadSmbiosTableGuid



[FeaturePcd.IA32]

gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode ##
CONSUMES

--
2.30.0.windows.2


Re: [Patch V3 5/9] MdeModulePkg/Universal/SmbiosDxe: Scan for existing tables

Zhiguang Liu
 

Hi Patrick

Thanks for catching this issue.
I updated the code, and you can find the code below
https://github.com/LiuZhiguang001/edk2/tree/UniversalPayloadHeaders_v4
Please help confirm.

Thanks
Zhiguang

-----Original Message-----
From: Patrick Rudolph <patrick.rudolph@9elements.com>
Sent: Tuesday, June 8, 2021 5:21 PM
To: Liu, Zhiguang <zhiguang.liu@intel.com>
Cc: devel@edk2.groups.io; Wang, Jian J <jian.j.wang@intel.com>; Wu, Hao A
<hao.a.wu@intel.com>; Bi, Dandan <dandan.bi@intel.com>; Zeng, Star
<star.zeng@intel.com>; Gao, Zhichao <zhichao.gao@intel.com>
Subject: Re: [Patch V3 5/9] MdeModulePkg/Universal/SmbiosDxe: Scan for
existing tables

On Fri, Jun 4, 2021 at 11:42 AM Zhiguang Liu <zhiguang.liu@intel.com> wrote:

V1:
The default EfiSmbiosProtocol operates on an empty SMBIOS table.
The SMBIOS tables are provided by the bootloader on UefiPayloadPkg.
Scan for existing tables in SmbiosDxe and load them if they seem valid.

This fixes the settings menu not showing any hardware information,
instead only "0 MB RAM" was displayed.

Tests showed that the OS can still see the SMBIOS tables.

V2:
SmbiosDxe will get the SMBIOS from a guid Hob.
Aslo will keep the SmbiosHandle if it is available.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Zhichao Gao <zhichao.gao@intel.com>
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
---
MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c | 320
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++--
MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.h | 4 +++-
MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf | 5 ++++-
3 files changed, 325 insertions(+), 4 deletions(-)

diff --git a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c
b/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c
index 3cdb0b1ed7..3579c4d890 100644
--- a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c
+++ b/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c
@@ -2,7 +2,7 @@
This code produces the Smbios protocol. It also responsible for
constructing
SMBIOS table into system table.

-Copyright (c) 2009 - 2018, Intel Corporation. All rights
reserved.<BR>
+Copyright (c) 2009 - 2021, Intel Corporation. All rights
+reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent

**/
@@ -148,6 +148,31 @@ SMBIOS_TABLE_3_0_ENTRY_POINT
Smbios30EntryPointStructureData = {
//
0
};
+
+/**
+ Validates a SMBIOS table entry point.
+
+ @param TableEntry The SmBios table entry to validate.
+ @param TableAddress On exit, point to the smbios table addres.
+ @param TableMaximumSize On exit, point to the maximum size of the
table.
+
+ @retval TRUE SMBIOS table entry point is valid.
+ @retval FALSE SMBIOS table entry point is malformed.
+
+**/
+typedef
+BOOLEAN
+(* IS_SMBIOS_TABLE_VALID) (
+ IN VOID *TableEntry,
+ OUT VOID **TableAddress,
+ OUT UINTN *TableMaximumSize
+ );
+typedef struct {
+ EFI_GUID *Guid;
+ IS_SMBIOS_TABLE_VALID IsValid;
+} IS_SMBIOS_TABLE_VALID_ENTRY;
+
+
/**

Get the full size of SMBIOS structure including optional strings that follow
the formatted structure.
@@ -1408,6 +1433,296 @@ SmbiosTableConstruction (
}
}

+/**
+ Validates a SMBIOS 2.0 table entry point.
+
+ @param TableEntry The SmBios table entry to validate.
+ @param TableAddress On exit, point to the smbios table addres.
+ @param TableMaximumSize On exit, point to the maximum size of the
table.
+
+ @retval TRUE SMBIOS table entry point is valid.
+ @retval FALSE SMBIOS table entry point is malformed.
+
+**/
+STATIC
+BOOLEAN
+IsValidSmbios20Table (
+ IN VOID *TableEntry,
+ OUT VOID **TableAddress,
+ OUT UINTN *TableMaximumSize
+ )
+{
+ UINT8 Checksum;
+ SMBIOS_TABLE_ENTRY_POINT *SmbiosTable;
+ SmbiosTable = (SMBIOS_TABLE_ENTRY_POINT *) TableEntry;
+
+ if (CompareMem (SmbiosTable->AnchorString, "_SM_", 4) != 0) {
+ return FALSE;
+ }
+
+ if (CompareMem (SmbiosTable->IntermediateAnchorString, "_DMI_",
5) != 0) {
+ return FALSE;
+ }
+
+ //
+ // The actual value of the EntryPointLength should be 1Fh.
+ // However, it was incorrectly stated in version 2.1 of smbios
specification.
+ // Therefore, 0x1F and 0x1E are both accepted.
+ //
+ if (SmbiosTable->EntryPointLength != 0x1E && SmbiosTable-
EntryPointLength != sizeof (SMBIOS_TABLE_ENTRY_POINT)) {
+ return FALSE;
+ }
+
+ //
+ // MajorVersion should not be less than 2.
+ //
+ if (SmbiosTable->MajorVersion < 2) {
+ return FALSE;
+ }
+
+ //
+ // The whole struct check sum should be zero // Checksum =
+ CalculateSum8 (
+ (UINT8 *) SmbiosTable,
+ SmbiosTable->EntryPointLength
+ );
+ if (Checksum != 0) {
+ return FALSE;
+ }
+
+ //
+ // The Intermediate Entry Point Structure check sum should be zero.
+ //
+ Checksum = CalculateSum8 (
+ (UINT8 *) SmbiosTable + OFFSET_OF
(SMBIOS_TABLE_ENTRY_POINT, IntermediateAnchorString),
+ SmbiosTable->EntryPointLength - OFFSET_OF
(SMBIOS_TABLE_ENTRY_POINT, IntermediateAnchorString)
+ );
+ if (Checksum != 0) {
+ return FALSE;
+ }
+
+ *TableAddress = (VOID *) (UINTN) SmbiosTable->TableAddress;
+ *TableMaximumSize = SmbiosTable->TableLength;
+ return TRUE;
+}
+
+/**
+ Validates a SMBIOS 3.0 table entry point.
+
+ @param TableEntry The SmBios table entry to validate.
+ @param TableAddress On exit, point to the smbios table addres.
+ @param TableMaximumSize On exit, point to the maximum size of the
table.
+
+ @retval TRUE SMBIOS table entry point is valid.
+ @retval FALSE SMBIOS table entry point is malformed.
+
+**/
+STATIC
+BOOLEAN
+IsValidSmbios30Table (
+ IN VOID *TableEntry,
+ OUT VOID **TableAddress,
+ OUT UINTN *TableMaximumSize
+ )
+{
+ UINT8 Checksum;
+ SMBIOS_TABLE_3_0_ENTRY_POINT *SmbiosTable;
+ SmbiosTable = (SMBIOS_TABLE_3_0_ENTRY_POINT *) TableEntry;
+
+ if (CompareMem (SmbiosTable->AnchorString, "_SM3_", 5) != 0) {
+ return FALSE;
+ }
+ if (SmbiosTable->EntryPointLength < sizeof
(SMBIOS_TABLE_3_0_ENTRY_POINT)) {
+ return FALSE;
+ }
+ if (SmbiosTable->MajorVersion < 3) {
+ return FALSE;
+ }
+
+ //
+ // The whole struct check sum should be zero // Checksum =
+ CalculateSum8 (
+ (UINT8 *) SmbiosTable,
+ SmbiosTable->EntryPointLength
+ );
+ if (Checksum != 0) {
+ return FALSE;
+ }
+
+ *TableAddress = (VOID *) (UINTN) SmbiosTable->TableAddress;
+ *TableMaximumSize = SmbiosTable->TableMaximumSize;
+ return TRUE;
+}
+
+/**
+ Parse an existing SMBIOS table and insert it using SmbiosAdd.
+
+ @param ImageHandle The EFI_HANDLE to this driver.
+ @param Smbios The SMBIOS table to parse.
+ @param Length The length of the SMBIOS table.
+
+ @retval EFI_SUCCESS SMBIOS table was parsed and installed.
+ @retval EFI_OUT_OF_RESOURCES Record was not added due to lack of
system resources.
+ @retval EFI_INVALID_PARAMETER Smbios is not a correct smbios table
+
+**/
+STATIC
+EFI_STATUS
+ParseAndAddExistingSmbiosTable (
+ IN EFI_HANDLE ImageHandle,
+ IN SMBIOS_STRUCTURE_POINTER Smbios,
+ IN UINTN Length
+ )
+{
+ EFI_STATUS Status;
+ CHAR8 *String;
+ EFI_SMBIOS_HANDLE SmbiosHandle;
+ SMBIOS_STRUCTURE_POINTER SmbiosEnd;
+
+ SmbiosEnd.Raw = Smbios.Raw + Length;
+
+ if (Smbios.Raw >= SmbiosEnd.Raw || Smbios.Raw == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ do {
+ //
+ // Make sure not to access memory beyond SmbiosEnd
+ //
+ if (Smbios.Raw + sizeof (SMBIOS_STRUCTURE) > SmbiosEnd.Raw ||
+ Smbios.Raw + sizeof (SMBIOS_STRUCTURE) < Smbios.Raw) {
+ return EFI_INVALID_PARAMETER;
+ }
+ //
+ // Check for end marker
+ //
+ if (Smbios.Hdr->Type == SMBIOS_TYPE_END_OF_TABLE) {
+ break;
+ }
+ //
+ // Make sure not to access memory beyond SmbiosEnd
+ // Each structure shall be terminated by a double-null (0000h).
+ //
+ if (Smbios.Raw + Smbios.Hdr->Length + 2 * sizeof (UINT8) >
SmbiosEnd.Raw ||
+ Smbios.Raw + Smbios.Hdr->Length + 2 * sizeof (UINT8) < Smbios.Raw)
{
+ return EFI_INVALID_PARAMETER;
+ }
+ //
+ // Install the table
+ //
+ SmbiosHandle = Smbios.Hdr->Handle;
+ Status = SmbiosAdd (
+ &mPrivateData.Smbios,
+ ImageHandle,
+ &SmbiosHandle,
+ Smbios.Hdr
+ );
+
+ ASSERT_EFI_ERROR (Status);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ //
+ // Go to the next SMBIOS structure. Each SMBIOS structure may include
2 parts:
+ // 1. Formatted section; 2. Unformatted string section. So, 2 steps are
needed
+ // to skip one SMBIOS structure.
+ //
+
+ //
+ // Step 1: Skip over formatted section.
+ //
+ String = (CHAR8 *) (Smbios.Raw + Smbios.Hdr->Length);
+
+ //
+ // Step 2: Skip over unformatted string section.
+ //
+ do {
+ //
+ // Each string is terminated with a NULL(00h) BYTE and the sets of
strings
+ // is terminated with an additional NULL(00h) BYTE.
+ //
+ for ( ; *String != 0; String++) {
+ if ((UINTN) String >= (UINTN) SmbiosEnd.Raw - sizeof (UINT8)) {
+ return EFI_INVALID_PARAMETER;
+ }
+ }
+
+ if (*(UINT8 *) ++String == 0) {
+ //
+ // Pointer to the next SMBIOS structure.
+ //
+ Smbios.Raw = (UINT8 *) ++String;
+ break;
+ }
+ } while (TRUE);
+ } while (Smbios.Raw < SmbiosEnd.Raw);
+
+ return EFI_SUCCESS;
+}
+
+
+IS_SMBIOS_TABLE_VALID_ENTRY mIsSmbiosTableValid[] = {
+ {&gPldSmbios3TableGuid, IsValidSmbios30Table },
+ {&gPldSmbiosTableGuid, IsValidSmbios20Table } };
+
+/**
+ Retrieve SMBIOS from Hob.
+ @param ImageHandle Module's image handle
+
+ @retval EFI_SUCCESS Smbios from Hob is installed.
+ @return EFI_NOT_FOUND Not found Smbios from Hob.
+ @retval Other No Smbios from Hob is installed.
+
+**/
+EFI_STATUS
+RetrieveSmbiosFromHob (
+ IN EFI_HANDLE ImageHandle
+ )
+{
+ EFI_STATUS Status;
+ UINTN Index;
+ SMBIOS_STRUCTURE_POINTER Smbios;
+ EFI_HOB_GUID_TYPE *GuidHob;
+ PLD_SMBIOS_TABLE *SmBiosTableAdress;
+ PLD_GENERIC_HEADER *GenericHeader;
+ VOID *TableAddress;
+ UINTN TableMaximumSize;
+
+ Status = EFI_NOT_FOUND;
+
+ for (Index = 0; Index < ARRAY_SIZE (mIsSmbiosTableValid); Index++) {
+ GuidHob = GetFirstGuidHob (mIsSmbiosTableValid[Index].Guid);
+ if (GuidHob == NULL) {
+ continue;
+ }
+ GenericHeader = (PLD_GENERIC_HEADER *) GET_GUID_HOB_DATA
(GuidHob);
+ if ((sizeof (PLD_GENERIC_HEADER) <= GET_GUID_HOB_DATA_SIZE
(GuidHob)) && (GenericHeader->Length <= GET_GUID_HOB_DATA_SIZE
(GuidHob))) {
+ if (GenericHeader->Revision == PLD_SMBIOS_TABLE_REVISION) {
+ //
+ // PLD_SMBIOS_TABLE structure is used when Revision equals to
PLD_SMBIOS_TABLE_REVISION
+ //
+ SmBiosTableAdress = (PLD_SMBIOS_TABLE *) GET_GUID_HOB_DATA
(GuidHob);
+ if (GenericHeader->Length >= PLD_SIZEOF_THROUGH_FIELD
(PLD_SMBIOS_TABLE, SmBiosEntryPoint)) {
+ if (mIsSmbiosTableValid[Index].IsValid ((VOID *)
(UINTN )SmBiosTableAdress->SmBiosEntryPoint, &TableAddress,
&TableMaximumSize)) {
+ Smbios.Raw = TableAddress;
+ Status = ParseAndAddExistingSmbiosTable (ImageHandle, Smbios,
TableMaximumSize);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "RetrieveSmbiosFromHob: Failed to
parse preinstalled tables from gPldSmbios3TableGuid Guid Hob\n"));
+ Status = EFI_UNSUPPORTED;
+ } else {
+ return EFI_SUCCESS;
+ }
+ }
+ }
+ }
+ }
+ }
+ return Status;
+}
+
/**

Driver to produce Smbios protocol and pre-allocate 1 page for the final
SMBIOS table.
@@ -1451,5 +1766,6 @@ SmbiosDriverEntryPoint (
&mPrivateData.Smbios
);

- return Status;
That doesn't compile as Status is written, but never read.

+ RetrieveSmbiosFromHob (ImageHandle); return EFI_SUCCESS;
}
diff --git a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.h
b/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.h
index f97c85ae40..a260cf695e 100644
--- a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.h
+++ b/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.h
@@ -1,7 +1,7 @@
/** @file
This code supports the implementation of the Smbios protocol

-Copyright (c) 2009 - 2018, Intel Corporation. All rights
reserved.<BR>
+Copyright (c) 2009 - 2021, Intel Corporation. All rights
+reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent

**/
@@ -24,6 +24,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/MemoryAllocationLib.h> #include
<Library/UefiBootServicesTableLib.h>
#include <Library/PcdLib.h>
+#include <Library/HobLib.h>
+#include <UniversalPayload/SmbiosTable.h>

#define SMBIOS_INSTANCE_SIGNATURE SIGNATURE_32 ('S', 'B', 'i', 's')
typedef struct { diff --git
a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf
b/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf
index f6c036e1dc..63f468936d 100644
--- a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf
+++ b/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf
@@ -1,7 +1,7 @@
## @file
# This driver initializes and installs the SMBIOS protocol, constructs SMBIOS
table into system configuration table.
#
-# Copyright (c) 2009 - 2018, Intel Corporation. All rights
reserved.<BR>
+# Copyright (c) 2009 - 2021, Intel Corporation. All rights
+reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -41,6 +41,7 @@
UefiDriverEntryPoint
DebugLib
PcdLib
+ HobLib

[Protocols]
gEfiSmbiosProtocolGuid ## PRODUCES
@@ -48,6 +49,8 @@
[Guids]
gEfiSmbiosTableGuid ## SOMETIMES_PRODUCES ##
SystemTable
gEfiSmbios3TableGuid ## SOMETIMES_PRODUCES ##
SystemTable
+ gPldSmbios3TableGuid ## CONSUMES ## HOB
+ gPldSmbiosTableGuid ## SOMETIMES_CONSUMES ##
HOB

[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosVersion ## CONSUMES
--
2.30.0.windows.2


[Patch V3] UefiPayloadPkg: Get platform specific logic from protocol for BDS driver

Zhiguang Liu
 

V1:
Currently, BDS driver will link a PlatformBootManagerLib, which contains pl=
atform
sepcific logic. This patch get the platform specific logic from a protocol,=
so that
platform logic for Boot manager can be in another binary.

V2:
Add function comments in PlatformBootManagerOverride.h

V3:
Avoid using "PLD" term

Cc: Maurice Ma <maurice.ma@intel.com>
Cc: Guo Dong <guo.dong@intel.com>
Cc: Benjamin You <benjamin.you@intel.com>

Reviewed-by: Guo Dong <guo.dong@intel.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
---
UefiPayloadPkg/Include/Protocol/PlatformBootManagerOverride.h |=
85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
++++++++++++++
UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.c |=
25 ++++++++++++++++++++++++-
UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf |=
3 ++-
UefiPayloadPkg/UefiPayloadPkg.dec |=
4 +++-
4 files changed, 114 insertions(+), 3 deletions(-)

diff --git a/UefiPayloadPkg/Include/Protocol/PlatformBootManagerOverride.h =
b/UefiPayloadPkg/Include/Protocol/PlatformBootManagerOverride.h
new file mode 100644
index 0000000000..59544e417c
--- /dev/null
+++ b/UefiPayloadPkg/Include/Protocol/PlatformBootManagerOverride.h
@@ -0,0 +1,85 @@
+/** @file=0D
+ This file defines the Univeral Payload Platform BootManager Protocol.=0D
+=0D
+ Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>=0D
+ SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+**/=0D
+=0D
+#ifndef __PLATFORM_BOOT_MANAGER_OVERRIDE_H__=0D
+#define __PLATFORM_BOOT_MANAGER_OVERRIDE_H__=0D
+=0D
+=0D
+/**=0D
+ Do the platform specific action before the console is connected.=0D
+=0D
+ Such as:=0D
+ Update console variable;=0D
+ Register new Driver#### or Boot####;=0D
+ Signal ReadyToLock event.=0D
+=0D
+ This function will override the default behavior in PlatformBootManagerL=
ib=0D
+**/=0D
+typedef=0D
+VOID=0D
+(EFIAPI *UNIVERSAL_PAYLOAD_PLATFORM_BOOT_MANAGER_OVERRIDE_BEFORE_CONSOLE) =
(=0D
+ VOID=0D
+ );=0D
+=0D
+/**=0D
+ Do the platform specific action after the console is connected.=0D
+=0D
+ Such as:=0D
+ Dynamically switch output mode;=0D
+ Signal console ready platform customized event;=0D
+ Run diagnostics like memory testing;=0D
+ Connect certain devices;=0D
+ Dispatch aditional option roms.=0D
+=0D
+ This function will override the default behavior in PlatformBootManagerL=
ib=0D
+**/=0D
+typedef=0D
+VOID=0D
+(EFIAPI *UNIVERSAL_PAYLOAD_PLATFORM_BOOT_MANAGER_OVERRIDE_AFTER_CONSOLE) (=
=0D
+ VOID=0D
+ );=0D
+=0D
+/**=0D
+ This function is called each second during the boot manager waits the ti=
meout.=0D
+ This function will override the default behavior in PlatformBootManagerL=
ib=0D
+=0D
+ @param TimeoutRemain The remaining timeout.=0D
+**/=0D
+typedef=0D
+VOID=0D
+(EFIAPI *UNIVERSAL_PAYLOAD_PLATFORM_BOOT_MANAGER_OVERRIDE_WAIT_CALLBACK) (=
=0D
+ UINT16 TimeoutRemain=0D
+ );=0D
+=0D
+/**=0D
+ The function is called when no boot option could be launched,=0D
+ including platform recovery options and options pointing to applications=
=0D
+ built into firmware volumes.=0D
+=0D
+ If this function returns, BDS attempts to enter an infinite loop.=0D
+ This function will override the default behavior in PlatformBootManagerL=
ib=0D
+**/=0D
+typedef=0D
+VOID=0D
+(EFIAPI *UNIVERSAL_PAYLOAD_PLATFORM_BOOT_MANAGER_OVERRIDE_UNABLE_TO_BOOT) =
(=0D
+ VOID=0D
+ );=0D
+=0D
+///=0D
+/// Provides an interface to override the default behavior in PlatformBoot=
ManagerLib,=0D
+/// so platform can provide its own platform specific logic through this p=
rotocol=0D
+///=0D
+typedef struct {=0D
+ UNIVERSAL_PAYLOAD_PLATFORM_BOOT_MANAGER_OVERRIDE_BEFORE_CONSOLE B=
eforeConsole;=0D
+ UNIVERSAL_PAYLOAD_PLATFORM_BOOT_MANAGER_OVERRIDE_AFTER_CONSOLE A=
fterConsole;=0D
+ UNIVERSAL_PAYLOAD_PLATFORM_BOOT_MANAGER_OVERRIDE_WAIT_CALLBACK W=
aitCallback;=0D
+ UNIVERSAL_PAYLOAD_PLATFORM_BOOT_MANAGER_OVERRIDE_UNABLE_TO_BOOT U=
nableToBoot;=0D
+} UNIVERSAL_PAYLOAD_PLATFORM_BOOT_MANAGER_OVERRIDE_PROTOCOL;=0D
+=0D
+extern GUID gUniversalPayloadPlatformBootManagerOverrideProtocolGuid;=0D
+=0D
+#endif=0D
diff --git a/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootMana=
ger.c b/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.c
index 7fa3a048b7..fce48d26a1 100644
--- a/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.c
+++ b/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.c
@@ -2,13 +2,16 @@
This file include all platform action which can be customized=0D
by IBV/OEM.=0D
=0D
-Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>=0D
+Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.<BR>=0D
SPDX-License-Identifier: BSD-2-Clause-Patent=0D
=0D
**/=0D
=0D
#include "PlatformBootManager.h"=0D
#include "PlatformConsole.h"=0D
+#include <Protocol/PlatformBootManagerOverride.h>=0D
+=0D
+UNIVERSAL_PAYLOAD_PLATFORM_BOOT_MANAGER_OVERRIDE_PROTOCOL *mUniversalPayl=
oadPlatformBootManagerOverrideInstance =3D NULL;=0D
=0D
VOID=0D
InstallReadyToLock (=0D
@@ -156,6 +159,16 @@ PlatformBootManagerBeforeConsole (
EFI_INPUT_KEY F2;=0D
EFI_INPUT_KEY Down;=0D
EFI_BOOT_MANAGER_LOAD_OPTION BootOption;=0D
+ EFI_STATUS Status;=0D
+=0D
+ Status =3D gBS->LocateProtocol (&gUniversalPayloadPlatformBootManagerOve=
rrideProtocolGuid, NULL, (VOID **) &mUniversalPayloadPlatformBootManagerOve=
rrideInstance);=0D
+ if (EFI_ERROR (Status)) {=0D
+ mUniversalPayloadPlatformBootManagerOverrideInstance =3D NULL;=0D
+ }=0D
+ if (mUniversalPayloadPlatformBootManagerOverrideInstance !=3D NULL){=0D
+ mUniversalPayloadPlatformBootManagerOverrideInstance->BeforeConsole();=
=0D
+ return;=0D
+ }=0D
=0D
//=0D
// Register ENTER as CONTINUE key=0D
@@ -213,6 +226,10 @@ PlatformBootManagerAfterConsole (
EFI_GRAPHICS_OUTPUT_BLT_PIXEL Black;=0D
EFI_GRAPHICS_OUTPUT_BLT_PIXEL White;=0D
=0D
+ if (mUniversalPayloadPlatformBootManagerOverrideInstance !=3D NULL){=0D
+ mUniversalPayloadPlatformBootManagerOverrideInstance->AfterConsole();=
=0D
+ return;=0D
+ }=0D
Black.Blue =3D Black.Green =3D Black.Red =3D Black.Reserved =3D 0;=0D
White.Blue =3D White.Green =3D White.Red =3D White.Reserved =3D 0xFF;=0D
=0D
@@ -244,6 +261,9 @@ PlatformBootManagerWaitCallback (
UINT16 TimeoutRemain=0D
)=0D
{=0D
+ if (mUniversalPayloadPlatformBootManagerOverrideInstance !=3D NULL){=0D
+ mUniversalPayloadPlatformBootManagerOverrideInstance->WaitCallback (Ti=
meoutRemain);=0D
+ }=0D
return;=0D
}=0D
=0D
@@ -260,6 +280,9 @@ PlatformBootManagerUnableToBoot (
VOID=0D
)=0D
{=0D
+ if (mUniversalPayloadPlatformBootManagerOverrideInstance !=3D NULL){=0D
+ mUniversalPayloadPlatformBootManagerOverrideInstance->UnableToBoot();=
=0D
+ }=0D
return;=0D
}=0D
=0D
diff --git a/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootMana=
gerLib.inf b/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootMana=
gerLib.inf
index 1f5a0bcad0..600a535282 100644
--- a/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.=
inf
+++ b/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.=
inf
@@ -1,7 +1,7 @@
## @file=0D
# Include all platform action which can be customized by IBV/OEM.=0D
#=0D
-# Copyright (c) 2012 - 2016, Intel Corporation. All rights reserved.<BR>=
=0D
+# Copyright (c) 2012 - 2021, Intel Corporation. All rights reserved.<BR>=
=0D
# SPDX-License-Identifier: BSD-2-Clause-Patent=0D
#=0D
##=0D
@@ -57,6 +57,7 @@
gEfiBootLogoProtocolGuid ## CONSUMES=0D
gEfiDxeSmmReadyToLockProtocolGuid=0D
gEfiSmmAccess2ProtocolGuid=0D
+ gUniversalPayloadPlatformBootManagerOverrideProtocolGuid=0D
=0D
[Pcd]=0D
gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut=0D
diff --git a/UefiPayloadPkg/UefiPayloadPkg.dec b/UefiPayloadPkg/UefiPayload=
Pkg.dec
index 99cb3311a6..105e1f5a1c 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.dec
+++ b/UefiPayloadPkg/UefiPayloadPkg.dec
@@ -3,7 +3,7 @@
#=0D
# Provides drivers and definitions to create uefi payload for bootloaders.=
=0D
#=0D
-# Copyright (c) 2014 - 2020, Intel Corporation. All rights reserved.<BR>=0D
+# Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.<BR>=0D
# SPDX-License-Identifier: BSD-2-Clause-Patent=0D
#=0D
##=0D
@@ -43,6 +43,8 @@
#=0D
gPlatformGOPPolicyGuid =3D { 0xec2e931b, 0x3281, 0x48a5=
, { 0x81, 0x07, 0xdf, 0x8a, 0x8b, 0xed, 0x3c, 0x5d } }=0D
=0D
+ gUniversalPayloadPlatformBootManagerOverrideProtocolGuid =3D { 0xdb3fc2d=
f, 0x7376, 0x4a8d, { 0x82, 0xab, 0x91, 0x54, 0xa1, 0x36, 0xa6, 0x5a } }=0D
+=0D
##########################################################################=
######=0D
#=0D
# PCD Declarations section - list of all PCDs Declared by this Package=0D
--=20
2.30.0.windows.2


[PATCH v1 1/1] Pytool: SpellCheck: Fix incorrect file mask across package matrices

Kun Qin
 

From: Sean Brogan <spbrogan@live.com>

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

Existing implementation could modify class global data that causes
potential incorrect file mask to be used for execution of plugin.

This change switches class variable to be tuple so that it cannot be
accidently modified. Local usage of STANDARD_PLUGIN_DEFINED_PATHS is also
changed to copy to new list before modification.

Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>

Signed-off-by: Sean Brogan <sean.brogan@microsoft.com>
---
.pytool/Plugin/SpellCheck/SpellCheck.py | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/.pytool/Plugin/SpellCheck/SpellCheck.py b/.pytool/Plugin/SpellCheck/SpellCheck.py
index 43365441b91c..9ad57632a6e8 100644
--- a/.pytool/Plugin/SpellCheck/SpellCheck.py
+++ b/.pytool/Plugin/SpellCheck/SpellCheck.py
@@ -37,12 +37,12 @@ class SpellCheck(ICiBuildPlugin):
#
# A package can remove any of these using IgnoreStandardPaths
#
- STANDARD_PLUGIN_DEFINED_PATHS = ["*.c", "*.h",
+ STANDARD_PLUGIN_DEFINED_PATHS = ("*.c", "*.h",
"*.nasm", "*.asm", "*.masm", "*.s",
"*.asl",
"*.dsc", "*.dec", "*.fdf", "*.inf",
"*.md", "*.txt"
- ]
+ )

def GetTestName(self, packagename: str, environment: VarDict) -> tuple:
""" Provide the testcase name and classname for use in reporting
@@ -107,7 +107,8 @@ class SpellCheck(ICiBuildPlugin):
version_aggregator.GetVersionAggregator().ReportVersion(
"CSpell", cspell_version, version_aggregator.VersionTypes.INFO)

- package_relative_paths_to_spell_check = SpellCheck.STANDARD_PLUGIN_DEFINED_PATHS
+ # copy the default as a list
+ package_relative_paths_to_spell_check = list(SpellCheck.STANDARD_PLUGIN_DEFINED_PATHS)

#
# Allow the ci.yaml to remove any of the above standard paths
--
2.31.1.windows.1


[PATCH v1 0/1] Spell Check File Mask Leak into Sequential Package Checks

Kun Qin
 

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

Current spell check routine on CI build pipelines is ignoring some files
incorrectly.

The issue is class variable, STANDARD_PLUGIN_DEFINED_PATHS from
SpellCheck.py, is a list. In a local function the list is assigned to a
local variable, which is then modified based on the package config. But
the modification of this local variable will change the class variable
and then leaks to the next package.

The proposed solution in this patch series is to convert class member to
tuple so that is read-only. Then copy into list in the local function
before package specific modifications.

Patch v1 branch: https://github.com/kuqin12/edk2/tree/spell_check_v1

Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>

Sean Brogan (1):
Pytool: SpellCheck: Fix incorrect file mask across package matrices

.pytool/Plugin/SpellCheck/SpellCheck.py | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

--
2.31.1.windows.1


[PATCH v1 5/5] MdePkg: MmCommunication: Extend MessageLength field size to UINT64

Kun Qin
 

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

The MessageLength field of EFI_MM_COMMUNICATE_HEADER, as a generic
definition, could be used for both PEI and DXE MM communication. On a
system that supports PEI MM launch, but operates PEI in 32bit mode and MM
foundation in 64bit, the current EFI_MM_COMMUNICATE_HEADER definition
will cause structure parse error due to UINTN used.

This change removes the architecture dependent field by extending this
field definition as UINT64.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>

Signed-off-by: Kun Qin <kuqin12@gmail.com>
---
MdePkg/Include/Protocol/MmCommunication.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/MdePkg/Include/Protocol/MmCommunication.h b/MdePkg/Include/Protocol/MmCommunication.h
index 34c3e2b5a9e3..24d88d3e0b68 100644
--- a/MdePkg/Include/Protocol/MmCommunication.h
+++ b/MdePkg/Include/Protocol/MmCommunication.h
@@ -26,7 +26,8 @@ typedef struct {
///
/// Describes the size of Data (in bytes) and does not include the size of the header.
///
- UINTN MessageLength;
+ /// BZ3398: Make MessageLength the same size in EFI_MM_COMMUNICATE_HEADER for both IA32 and X64.
+ UINT64 MessageLength;
///
/// Designates an array of bytes that is MessageLength in size.
///
--
2.31.1.windows.1


[PATCH v1 4/5] MdeModulePkg: SmiHandlerProfileInfo: Updated MessageLength calculation

Kun Qin
 

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

This change replaced the calculation of communication buffer size from
explicitly adding the size of each member with the OFFSET macro function.
This will make the structure field defition change transparent to
consumers.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>

Signed-off-by: Kun Qin <kuqin12@gmail.com>
---
MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c b/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c
index 4153074b7a80..56d80d1a9ce1 100644
--- a/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c
+++ b/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c
@@ -116,7 +116,9 @@ GetSmiHandlerProfileDatabase(
CommGetInfo->Header.ReturnStatus = (UINT64)-1;
CommGetInfo->DataSize = 0;

- CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + CommHeader->MessageLength;
+ // BZ3398: Make MessageLength the same size in EFI_MM_COMMUNICATE_HEADER for both IA32 and X64.
+ // The CommHeader->MessageLength contains a definitive value, thus UINTN cast is safe here.
+ CommSize = OFFSET_OF(EFI_SMM_COMMUNICATE_HEADER, Data) + (UINTN)CommHeader->MessageLength;
Status = SmmCommunication->Communicate(SmmCommunication, CommBuffer, &CommSize);
if (EFI_ERROR(Status)) {
Print(L"SmiHandlerProfile: SmmCommunication - %r\n", Status);
@@ -149,7 +151,9 @@ GetSmiHandlerProfileDatabase(
CommGetData->Header.DataLength = sizeof(*CommGetData);
CommGetData->Header.ReturnStatus = (UINT64)-1;

- CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + CommHeader->MessageLength;
+ // BZ3398: Make MessageLength the same size in EFI_MM_COMMUNICATE_HEADER for both IA32 and X64.
+ // The CommHeader->MessageLength contains a definitive value, thus UINTN cast is safe here.
+ CommSize = OFFSET_OF(EFI_SMM_COMMUNICATE_HEADER, Data) + (UINTN)CommHeader->MessageLength;
Buffer = (UINT8 *)CommHeader + CommSize;
Size -= CommSize;

--
2.31.1.windows.1


[PATCH v1 3/5] MdeModulePkg: MemoryProfileInfo: Updated MessageLength calculation

Kun Qin
 

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

This change replaced the calculation of communication buffer size from
explicitly adding the size of each member with the OFFSET macro function.
This will make the structure field defition change transparent to
consumers.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>

Signed-off-by: Kun Qin <kuqin12@gmail.com>
---
MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c b/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c
index 191c31068545..39ed8b2e0484 100644
--- a/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c
+++ b/MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c
@@ -1190,7 +1190,9 @@ GetSmramProfileData (
CommRecordingState->Header.ReturnStatus = (UINT64)-1;
CommRecordingState->RecordingState = MEMORY_PROFILE_RECORDING_DISABLE;

- CommSize = sizeof (EFI_GUID) + sizeof (UINTN) + CommHeader->MessageLength;
+ // BZ3398: Make MessageLength the same size in EFI_MM_COMMUNICATE_HEADER for both IA32 and X64.
+ // The CommHeader->MessageLength contains a definitive value, thus UINTN cast is safe here.
+ CommSize = OFFSET_OF(EFI_SMM_COMMUNICATE_HEADER, Data) + (UINTN)CommHeader->MessageLength;
Status = SmmCommunication->Communicate (SmmCommunication, CommBuffer, &CommSize);
if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_ERROR, "SmramProfile: SmmCommunication - %r\n", Status));
@@ -1213,7 +1215,9 @@ GetSmramProfileData (
CommRecordingState->Header.ReturnStatus = (UINT64)-1;
CommRecordingState->RecordingState = MEMORY_PROFILE_RECORDING_DISABLE;

- CommSize = sizeof (EFI_GUID) + sizeof (UINTN) + CommHeader->MessageLength;
+ // BZ3398: Make MessageLength the same size in EFI_MM_COMMUNICATE_HEADER for both IA32 and X64.
+ // The CommHeader->MessageLength contains a definitive value, thus UINTN cast is safe here.
+ CommSize = OFFSET_OF(EFI_SMM_COMMUNICATE_HEADER, Data) + (UINTN)CommHeader->MessageLength;
SmmCommunication->Communicate (SmmCommunication, CommBuffer, &CommSize);
}

@@ -1230,7 +1234,9 @@ GetSmramProfileData (
CommGetProfileInfo->Header.ReturnStatus = (UINT64)-1;
CommGetProfileInfo->ProfileSize = 0;

- CommSize = sizeof (EFI_GUID) + sizeof (UINTN) + CommHeader->MessageLength;
+ // BZ3398: Make MessageLength the same size in EFI_MM_COMMUNICATE_HEADER for both IA32 and X64.
+ // The CommHeader->MessageLength contains a definitive value, thus UINTN cast is safe here.
+ CommSize = OFFSET_OF(EFI_SMM_COMMUNICATE_HEADER, Data) + (UINTN)CommHeader->MessageLength;
Status = SmmCommunication->Communicate (SmmCommunication, CommBuffer, &CommSize);
ASSERT_EFI_ERROR (Status);

@@ -1261,7 +1267,9 @@ GetSmramProfileData (
CommGetProfileData->Header.DataLength = sizeof (*CommGetProfileData);
CommGetProfileData->Header.ReturnStatus = (UINT64)-1;

- CommSize = sizeof (EFI_GUID) + sizeof (UINTN) + CommHeader->MessageLength;
+ // BZ3398: Make MessageLength the same size in EFI_MM_COMMUNICATE_HEADER for both IA32 and X64.
+ // The CommHeader->MessageLength contains a definitive value, thus UINTN cast is safe here.
+ CommSize = OFFSET_OF(EFI_SMM_COMMUNICATE_HEADER, Data) + (UINTN)CommHeader->MessageLength;
Buffer = (UINT8 *) CommHeader + CommSize;
Size -= CommSize;

@@ -1320,7 +1328,9 @@ GetSmramProfileData (
CommRecordingState->Header.ReturnStatus = (UINT64)-1;
CommRecordingState->RecordingState = MEMORY_PROFILE_RECORDING_ENABLE;

- CommSize = sizeof (EFI_GUID) + sizeof (UINTN) + CommHeader->MessageLength;
+ // BZ3398: Make MessageLength the same size in EFI_MM_COMMUNICATE_HEADER for both IA32 and X64.
+ // The CommHeader->MessageLength contains a definitive value, thus UINTN cast is safe here.
+ CommSize = OFFSET_OF(EFI_SMM_COMMUNICATE_HEADER, Data) + (UINTN)CommHeader->MessageLength;
SmmCommunication->Communicate (SmmCommunication, CommBuffer, &CommSize);
}

--
2.31.1.windows.1


[PATCH v1 2/5] MdeModulePkg: PiSmmIpl: Update MessageLength calculation for MmCommunicate

Kun Qin
 

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

This change updated calculation routine for MM communication in PiSmmIpl.
It removes ambiguity brought in by UINTN variables from this routine and
paves way for updating definition of field MessageLength in
EFI_MM_COMMUNICATE_HEADER to definitive size.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>

Signed-off-by: Kun Qin <kuqin12@gmail.com>
---
MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c | 13 ++++++++++++-
MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf | 1 +
2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c
index 599a0cd01d80..9508715fda24 100644
--- a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c
+++ b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c
@@ -34,6 +34,7 @@
#include <Library/UefiRuntimeLib.h>
#include <Library/PcdLib.h>
#include <Library/ReportStatusCodeLib.h>
+#include <Library/SafeIntLib.h> // BZ3398

#include "PiSmmCorePrivateData.h"

@@ -515,6 +516,7 @@ SmmCommunicationCommunicate (
EFI_STATUS Status;
EFI_SMM_COMMUNICATE_HEADER *CommunicateHeader;
BOOLEAN OldInSmm;
+ UINT64 BZ3398_LongCommSize;
UINTN TempCommSize;

//
@@ -527,7 +529,16 @@ SmmCommunicationCommunicate (
CommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *) CommBuffer;

if (CommSize == NULL) {
- TempCommSize = OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + CommunicateHeader->MessageLength;
+ // BZ3398 Starts: Make MessageLength the same size in EFI_MM_COMMUNICATE_HEADER for both IA32 and X64.
+ Status = SafeUint64Add (OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data), CommunicateHeader->MessageLength, &BZ3398_LongCommSize);
+ if (EFI_ERROR (Status)) {
+ return EFI_INVALID_PARAMETER;
+ }
+ Status = SafeUint64ToUintn (BZ3398_LongCommSize, &TempCommSize);
+ if (EFI_ERROR (Status)) {
+ return EFI_INVALID_PARAMETER;
+ }
+ // BZ3398 Ends
} else {
TempCommSize = *CommSize;
//
diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf
index 6109d6b5449c..87142e27fa47 100644
--- a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf
+++ b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf
@@ -46,6 +46,7 @@ [LibraryClasses]
DxeServicesLib
PcdLib
ReportStatusCodeLib
+ SafeIntLib #BZ3398

[Protocols]
gEfiSmmBase2ProtocolGuid ## PRODUCES
--
2.31.1.windows.1


[PATCH v1 1/5] EDK2 Code First: PI Specification: EFI_MM_COMMUNICATE_HEADER Update

Kun Qin
 

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

This change includes specification update markdown file that describes
the proposed PI Specification v1.7 Errata A in detail and potential
impact to the existing codebase.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Cc: Andrew Fish <afish@apple.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Leif Lindholm <leif@nuviainc.com>

Signed-off-by: Kun Qin <kuqin12@gmail.com>
---
BZ3430-SpecChange.md | 88 ++++++++++++++++++++
1 file changed, 88 insertions(+)

diff --git a/BZ3430-SpecChange.md b/BZ3430-SpecChange.md
new file mode 100644
index 000000000000..33a1ffda447b
--- /dev/null
+++ b/BZ3430-SpecChange.md
@@ -0,0 +1,88 @@
+# Title: Change MessageLength Field of EFI_MM_COMMUNICATE_HEADER to UINT64
+
+## Status: Draft
+
+## Document: UEFI Platform Initialization Specification Version 1.7 Errata A
+
+## License
+
+SPDX-License-Identifier: CC-BY-4.0
+
+## Submitter: [TianoCore Community](https://www.tianocore.org)
+
+## Summary of the change
+
+Change the `MessageLength` Field of `EFI_MM_COMMUNICATE_HEADER` from UINTN to UINT64 to remove architecture dependency:
+
+```c
+typedef struct {
+ EFI_GUID HeaderGuid;
+ UINT64 MessageLength;
+ UINT8 Data[ANYSIZE_ARRAY];
+} EFI_MM_COMMUNICATE_HEADER;
+```
+
+## Benefits of the change
+
+In PI Spec v1.7 Errata A, Vol.4, Sec 5.7 MM Communication Protocol, the MessageLength field of `EFI_MM_COMMUNICATE_HEADER` (also defined as `EFI_SMM_COMMUNICATE_HEADER`) is defined as type UINTN.
+
+But this structure, as a generic definition, could be used for both PEI and DXE MM communication. Thus for a system that supports PEI MM launch, but operates PEI in 32bit mode and MM foundation in 64bit, the current `EFI_MM_COMMUNICATE_HEADER` definition will cause structure parse error due to UINTN used.
+
+## Impact of the change
+
+This change will impact the known structure consumers including:
+
+```bash
+MdeModulePkg/Core/PiSmmCore/PiSmmIpl
+MdeModulePkg/Application/SmiHandlerProfileInfo
+MdeModulePkg/Application/MemoryProfileInfo
+```
+
+For consumers that are not using `OFFSET_OF(EFI_MM_COMMUNICATE_HEADER, Data)`, but performing explicit addition such as the existing MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c, one will need to change code implementation to match new structure definition. Otherwise, the code compiled on IA32 architecture will experience structure field dereference error.
+
+User who currently uses UINTN local variables as place holder of MessageLength will need to use caution to make cast from UINTN to UINT64 and vice versa. It is recommended to use `SafeUint64ToUintn` for such operations when the value is indeterministic.
+
+Note: MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxPeiLib is also consuming this structure, but it handled this size discrepancy internally. If this potential spec change is not applied, all applicable PEI MM communicate callers will need to use the same routine as that of SmmLockBoxPeiLib to invoke a properly populated EFI_MM_COMMUNICATE_HEADER to be used in X64 MM foundation.
+
+## Detailed description of the change [normative updates]
+
+### Specification Changes
+
+1. In PI Specification v1.7 Errata A: Vol. 4 Page-91, the definition of `EFI_MM_COMMUNICATE_HEADER` should be changed from current:
+
+```c
+typedef struct {
+ EFI_GUID HeaderGuid;
+ UINTN MessageLength;
+ UINT8 Data[ANYSIZE_ARRAY];
+} EFI_MM_COMMUNICATE_HEADER;
+```
+
+to:
+
+```c
+typedef struct {
+ EFI_GUID HeaderGuid;
+ UINT64 MessageLength;
+ UINT8 Data[ANYSIZE_ARRAY];
+} EFI_MM_COMMUNICATE_HEADER;
+```
+
+### Code Changes
+
+1. Remove the explicit calculation of the offset of `Data` in `EFI_MM_COMMUNICATE_HEADER`. Thus applicable calculations of `sizeof(EFI_GUID) + sizeof(UINTN)` should be replaced with `OFFSET_OF(EFI_MM_COMMUNICATE_HEADER, Data)` or similar alternatives. These calculations are identified in:
+
+```bash
+MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c
+MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c
+```
+
+1. Resolve potentially mismatched type between `UINTN` and `UINT64`. This would occur when `MessageLength` or its derivitive are used for local calculation with existing `UINTN` typed variables. Code change regarding this perspective is per case evaluation: if the variables involved are all deterministic values, and there is no overflow or underflow risk, a cast operation (from `UINTN` to `UINT64`) can be safely used. Otherwise, the calculation will be performed in `UINT64` bitwidth and then convert to `UINTN` using `SafeUint64*` and `SafeUint64ToUintn`, respectively. These operations are identified in:
+
+```bash
+MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c
+MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c
+MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c
+```
+
+1. After all above changes applied and specification updated, `MdePkg/Include/Protocol/MmCommunication.h` will need to be updated to match new definition that includes the field type update.
--
2.31.1.windows.1


[PATCH v1 0/5] EDK2 Code First: PI Specification: Update EFI_MM_COMMUNICATE_HEADER

Kun Qin
 

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

In PI Spec v1.7 Errata A, Vol.4, Sec 5.7 MM Communication Protocol, the
MessageLength field of EFI_MM_COMMUNICATE_HEADER (also derived as
EFI_SMM_COMMUNICATE_HEADER) is currently defined as type UINTN.

But this structure, as a generic definition, could be used for both PEI
and DXE MM communication. Thus for a system that supports PEI MM launch,
but operates PEI in 32bit mode and MM foundation in 64bit, the current
EFI_MM_COMMUNICATE_HEADER definition will cause structure parse error due
to UINTN being used.

The suggested change is to make the MessageLength field defined with
definitive size as below:
```
typedef struct {
EFI_GUID HeaderGuid;
UINT64 MessageLength;
UINT8 Data[ANYSIZE_ARRAY];
} EFI_MM_COMMUNICATE_HEADER;
```

Patch v1 branch: https://github.com/kuqin12/edk2/tree/BZ3398-MmCommunicate-Length

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Cc: Andrew Fish <afish@apple.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Leif Lindholm <leif@nuviainc.com>

Kun Qin (5):
EDK2 Code First: PI Specification: EFI_MM_COMMUNICATE_HEADER Update
MdeModulePkg: PiSmmIpl: Update MessageLength calculation for
MmCommunicate
MdeModulePkg: MemoryProfileInfo: Updated MessageLength calculation
MdeModulePkg: SmiHandlerProfileInfo: Updated MessageLength calculation
MdePkg: MmCommunication: Extend MessageLength field size to UINT64

MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c | 20 +++--
MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c | 8 +-
MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c | 13 ++-
BZ3430-SpecChange.md | 88 ++++++++++++++++++++
MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf | 1 +
MdePkg/Include/Protocol/MmCommunication.h | 3 +-
6 files changed, 124 insertions(+), 9 deletions(-)
create mode 100644 BZ3430-SpecChange.md

--
2.31.1.windows.1


[Patch V3] UefiPayloadPkg: Use DynamicEx instead of Dynamic to pass PCD across binary

Zhiguang Liu
 

V1:
When passing PCD database from Edk2 boot loader to Universal Payload, the l=
ocal
token number in boot loader PCD database can be different with that in Payl=
oad
PCD database.
Dynamic PCD directly use local token number, while DynamicEx will search to=
ken number
by Guid and ExTokenNumber, which are unique pair and can make sure finding =
the correct
token number in boot loader's PCD database
V2:
Remove PCD PcdFlashNvStorageFtwWorkingBase and PcdFlashNvStorageFtwSpareBas=
e, because they
are not consumed by any modules.
Explicitly define some PCDs as DynamicEx, or their default type will be Dyn=
amic

V3:
Not remove some PCDs for they will be consumed soon

Cc: Maurice Ma <maurice.ma@intel.com>
Cc: Guo Dong <guo.dong@intel.com>
Cc: Benjamin You <benjamin.you@intel.com>

Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
---
UefiPayloadPkg/UefiPayloadPkg.dsc | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayload=
Pkg.dsc
index 37ad5a0ae7..4b0ec3a059 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.dsc
+++ b/UefiPayloadPkg/UefiPayloadPkg.dsc
@@ -336,11 +336,11 @@
=0D
##########################################################################=
######=0D
#=0D
-# Pcd Dynamic Section - list of all EDK II PCD Entries defined by this Pla=
tform=0D
+# Pcd DynamicEx Section - list of all EDK II PCD Entries defined by this P=
latform=0D
#=0D
##########################################################################=
######=0D
=0D
-[PcdsDynamicDefault]=0D
+[PcdsDynamicExDefault]=0D
gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved|0=0D
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64|0=0D
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0=0D
@@ -363,6 +363,9 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdConOutColumn|100=0D
gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0=0D
gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseSize|0=0D
+ gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase|0=0D
+ gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed|FALSE=0D
+ gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|0=0D
=0D
##########################################################################=
######=0D
#=0D
--=20
2.30.0.windows.2


[Patch V4 9/9] UefiPayloadPkg: Creat gPldAcpiTableGuid Hob

Zhiguang Liu
 

From SysTableInfo Hob, get ACPI table address, and creat gPldAcpiTableGuid =
Hob
to store it. Remove diretly adding ACPI table to ConfigurationTable.
Dxe ACPI driver will parse it and install ACPI table from Guid Hob.

Cc: Maurice Ma <maurice.ma@intel.com>
Cc: Guo Dong <guo.dong@intel.com>
Cc: Benjamin You <benjamin.you@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
---
UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c | 17 -----------------
UefiPayloadPkg/BlSupportDxe/BlSupportDxe.h | 5 +----
UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf | 1 -
UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c | 11 +++++++++++
UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h | 2 +-
UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf | 1 +
UefiPayloadPkg/UefiPayloadPkg.fdf | 4 ++++
7 files changed, 18 insertions(+), 23 deletions(-)

diff --git a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c b/UefiPayloadPkg/Bl=
SupportDxe/BlSupportDxe.c
index 56b85b8e6d..ffd3427fb3 100644
--- a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c
+++ b/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c
@@ -99,7 +99,6 @@ BlDxeEntryPoint (
{=0D
EFI_STATUS Status;=0D
EFI_HOB_GUID_TYPE *GuidHob;=0D
- SYSTEM_TABLE_INFO *SystemTableInfo;=0D
EFI_PEI_GRAPHICS_INFO_HOB *GfxInfo;=0D
ACPI_BOARD_INFO *AcpiBoardInfo;=0D
=0D
@@ -113,22 +112,6 @@ BlDxeEntryPoint (
Status =3D ReserveResourceInGcd (TRUE, EfiGcdMemoryTypeMemoryMappedIo, 0=
xFED00000, SIZE_1KB, 0, ImageHandle); // HPET=0D
ASSERT_EFI_ERROR (Status);=0D
=0D
- //=0D
- // Find the system table information guid hob=0D
- //=0D
- GuidHob =3D GetFirstGuidHob (&gUefiSystemTableInfoGuid);=0D
- ASSERT (GuidHob !=3D NULL);=0D
- SystemTableInfo =3D (SYSTEM_TABLE_INFO *)GET_GUID_HOB_DATA (GuidHob);=0D
-=0D
- //=0D
- // Install Acpi Table=0D
- //=0D
- if (SystemTableInfo->AcpiTableBase !=3D 0 && SystemTableInfo->AcpiTableS=
ize !=3D 0) {=0D
- DEBUG ((DEBUG_ERROR, "Install Acpi Table at 0x%lx, length 0x%x\n", Sys=
temTableInfo->AcpiTableBase, SystemTableInfo->AcpiTableSize));=0D
- Status =3D gBS->InstallConfigurationTable (&gEfiAcpiTableGuid, (VOID *=
)(UINTN)SystemTableInfo->AcpiTableBase);=0D
- ASSERT_EFI_ERROR (Status);=0D
- }=0D
-=0D
//=0D
// Find the frame buffer information and update PCDs=0D
//=0D
diff --git a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.h b/UefiPayloadPkg/Bl=
SupportDxe/BlSupportDxe.h
index 512105fafd..3332a30eae 100644
--- a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.h
+++ b/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.h
@@ -1,7 +1,7 @@
/** @file=0D
The header file of bootloader support DXE.=0D
=0D
-Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>=0D
+Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>=0D
SPDX-License-Identifier: BSD-2-Clause-Patent=0D
=0D
**/=0D
@@ -19,12 +19,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/IoLib.h>=0D
#include <Library/HobLib.h>=0D
=0D
-#include <Guid/Acpi.h>=0D
#include <Guid/SmBios.h>=0D
#include <Guid/SystemTableInfoGuid.h>=0D
#include <Guid/AcpiBoardInfoGuid.h>=0D
#include <Guid/GraphicsInfoHob.h>=0D
=0D
-#include <IndustryStandard/Acpi.h>=0D
-=0D
#endif=0D
diff --git a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf b/UefiPayloadPkg/=
BlSupportDxe/BlSupportDxe.inf
index 30f41f8c39..1ccb250991 100644
--- a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf
+++ b/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf
@@ -42,7 +42,6 @@
HobLib=0D
=0D
[Guids]=0D
- gEfiAcpiTableGuid=0D
gUefiSystemTableInfoGuid=0D
gUefiAcpiBoardInfoGuid=0D
gEfiGraphicsInfoHobGuid=0D
diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c b/UefiPaylo=
adPkg/UefiPayloadEntry/UefiPayloadEntry.c
index 80f66a3fd5..f44e0ea7f0 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c
+++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c
@@ -235,6 +235,7 @@ BuildHobFromBl (
EFI_PEI_GRAPHICS_DEVICE_INFO_HOB GfxDeviceInfo;=0D
EFI_PEI_GRAPHICS_DEVICE_INFO_HOB *NewGfxDeviceInfo;=0D
UNIVERSAL_PAYLOAD_SMBIOS_TABLE *SmBiosTableHob;=0D
+ UNIVERSAL_PAYLOAD_ACPI_TABLE *AcpiTableHob;=0D
=0D
//=0D
// Parse memory info and build memory HOBs=0D
@@ -287,6 +288,16 @@ BuildHobFromBl (
SmBiosTableHob->SmBiosEntryPoint =3D SysTableInfo.SmbiosTableBase;=0D
DEBUG ((DEBUG_INFO, "Create smbios table gUniversalPayloadSmbiosTableGui=
d guid hob\n"));=0D
=0D
+ // =0D
+ // Creat ACPI table Hob=0D
+ //=0D
+ AcpiTableHob =3D BuildGuidHob (&gUniversalPayloadAcpiTableGuid, sizeof (=
UNIVERSAL_PAYLOAD_ACPI_TABLE));=0D
+ ASSERT (AcpiTableHob !=3D NULL);=0D
+ AcpiTableHob->Header.Revision =3D UNIVERSAL_PAYLOAD_ACPI_TABLE_REVISION;=
=0D
+ AcpiTableHob->Header.Length =3D sizeof (UNIVERSAL_PAYLOAD_ACPI_TABLE);=0D
+ AcpiTableHob->Rsdp =3D SysTableInfo.AcpiTableBase;=0D
+ DEBUG ((DEBUG_INFO, "Create smbios table gUniversalPayloadAcpiTableGuid =
guid hob\n"));=0D
+=0D
//=0D
// Create guid hob for acpi board information=0D
//=0D
diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h b/UefiPaylo=
adPkg/UefiPayloadEntry/UefiPayloadEntry.h
index e7d0d15118..a4c9da128e 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h
+++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h
@@ -32,7 +32,7 @@
#include <Guid/AcpiBoardInfoGuid.h>=0D
#include <Guid/GraphicsInfoHob.h>=0D
#include <UniversalPayload/SmbiosTable.h>=0D
-=0D
+#include <UniversalPayload/AcpiTable.h>=0D
=0D
#define LEGACY_8259_MASK_REGISTER_MASTER 0x21=0D
#define LEGACY_8259_MASK_REGISTER_SLAVE 0xA1=0D
diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf b/UefiPay=
loadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
index fc5b5ce9d4..8d42925fcd 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
+++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
@@ -65,6 +65,7 @@
gEfiGraphicsDeviceInfoHobGuid=0D
gUefiAcpiBoardInfoGuid=0D
gUniversalPayloadSmbiosTableGuid=0D
+ gUniversalPayloadAcpiTableGuid=0D
=0D
[FeaturePcd.IA32]=0D
gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode ## CONSUME=
S=0D
diff --git a/UefiPayloadPkg/UefiPayloadPkg.fdf b/UefiPayloadPkg/UefiPayload=
Pkg.fdf
index 8fc509024b..ed7fbcaddb 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.fdf
+++ b/UefiPayloadPkg/UefiPayloadPkg.fdf
@@ -175,6 +175,10 @@ INF MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe.inf
INF MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf=0D
INF MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf=0D
=0D
+#=0D
+# ACPI Support=0D
+#=0D
+INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf=0D
=0D
#=0D
# Shell=0D
--=20
2.30.0.windows.2


[Patch V4 8/9] MdeModulePkg/ACPI: Install ACPI table from HOB.

Zhiguang Liu
 

V1:
If HOB contains APCI table information, entry point of AcpiTableDxe.inf
should parse the APCI table from HOB, and install these tables.
We assume the whole ACPI table (starting with EFI_ACPI_2_0_ROOT_SYSTEM_DESC=
RIPTION_POINTER)
is contained by a single gEfiAcpiTableGuid HOB.

V2:
If error happens when installing ACPI table, stop installing and removing a=
ll the tables that
are already added.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Ray Ni <ray.ni@intel.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
---
MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.c | 92 +++++++=
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------=
----------
MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.h | 38 +++++++=
++++++++++++++++++++++++++++++-
MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf | 8 +++++---
MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c | 171 +++++++=
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
+++++++-------
4 files changed, 271 insertions(+), 38 deletions(-)

diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.c b/MdeModule=
Pkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.c
index 14ced68e64..d98573d613 100644
--- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.c
+++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.c
@@ -1,7 +1,7 @@
/** @file=0D
ACPI Sdt Protocol Driver=0D
=0D
- Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved. <BR>=
=0D
+ Copyright (c) 2010 - 2021, Intel Corporation. All rights reserved. <BR>=
=0D
SPDX-License-Identifier: BSD-2-Clause-Patent=0D
=0D
**/=0D
@@ -191,8 +191,7 @@ SdtNotifyAcpiList (
/**=0D
Returns a requested ACPI table.=0D
=0D
- The GetAcpiTable() function returns a pointer to a buffer containing the=
ACPI table associated=0D
- with the Index that was input. The following structures are not consider=
ed elements in the list of=0D
+ The following structures are not considered elements in the list of=0D
ACPI tables:=0D
- Root System Description Pointer (RSD_PTR)=0D
- Root System Description Table (RSDT)=0D
@@ -201,42 +200,32 @@ SdtNotifyAcpiList (
member. For tables installed via the EFI_ACPI_TABLE_PROTOCOL.InstallAcpi=
Table() interface,=0D
the function returns the value of EFI_ACPI_STD_PROTOCOL.AcpiVersion.=0D
=0D
- @param[in] Index The zero-based index of the table to retrieve.=
=0D
- @param[out] Table Pointer for returning the table buffer.=0D
- @param[out] Version On return, updated with the ACPI versions to w=
hich this table belongs. Type=0D
- EFI_ACPI_TABLE_VERSION is defined in "Related =
Definitions" in the=0D
- EFI_ACPI_SDT_PROTOCOL.=0D
- @param[out] TableKey On return, points to the table key for the spe=
cified ACPI system definition table.=0D
- This is identical to the table key used in the=
EFI_ACPI_TABLE_PROTOCOL.=0D
- The TableKey can be passed to EFI_ACPI_TABLE_P=
ROTOCOL.UninstallAcpiTable()=0D
- to uninstall the table.=0D
- @retval EFI_SUCCESS The function completed successfully.=0D
- @retval EFI_NOT_FOUND The requested index is too large and a table w=
as not found.=0D
+ @param[in] AcpiTableInstance ACPI table Instance.=0D
+ @param[in] Index The zero-based index of the table to re=
trieve.=0D
+ @param[out] Table Pointer for returning the table buffer.=
=0D
+ @param[out] Version On return, updated with the ACPI versio=
ns to which this table belongs. Type=0D
+ EFI_ACPI_TABLE_VERSION is defined in "R=
elated Definitions" in the=0D
+ EFI_ACPI_SDT_PROTOCOL.=0D
+ @param[out] TableKey On return, points to the table key for =
the specified ACPI system definition table.=0D
+ This is identical to the table key used=
in the EFI_ACPI_TABLE_PROTOCOL.=0D
+ The TableKey can be passed to EFI_ACPI_=
TABLE_PROTOCOL.UninstallAcpiTable()=0D
+ to uninstall the table.=0D
+ @retval EFI_SUCCESS The function completed successfully.=0D
+ @retval EFI_NOT_FOUND The requested index is too large and a =
table was not found.=0D
**/=0D
EFI_STATUS=0D
-EFIAPI=0D
-GetAcpiTable2 (=0D
+SdtGetAcpiTable (=0D
+ IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,=0D
IN UINTN Index,=0D
OUT EFI_ACPI_SDT_HEADER **Table,=0D
OUT EFI_ACPI_TABLE_VERSION *Version,=0D
OUT UINTN *TableKey=0D
)=0D
{=0D
- EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance;=0D
UINTN TableIndex;=0D
LIST_ENTRY *CurrentLink;=0D
LIST_ENTRY *StartLink;=0D
EFI_ACPI_TABLE_LIST *CurrentTable;=0D
-=0D
- ASSERT (Table !=3D NULL);=0D
- ASSERT (Version !=3D NULL);=0D
- ASSERT (TableKey !=3D NULL);=0D
-=0D
- //=0D
- // Get the instance of the ACPI Table=0D
- //=0D
- AcpiTableInstance =3D SdtGetAcpiTableInstance ();=0D
-=0D
//=0D
// Find the table=0D
//=0D
@@ -270,6 +259,55 @@ GetAcpiTable2 (
return EFI_SUCCESS;=0D
}=0D
=0D
+/**=0D
+ Returns a requested ACPI table.=0D
+=0D
+ The GetAcpiTable() function returns a pointer to a buffer containing the=
ACPI table associated=0D
+ with the Index that was input. The following structures are not consider=
ed elements in the list of=0D
+ ACPI tables:=0D
+ - Root System Description Pointer (RSD_PTR)=0D
+ - Root System Description Table (RSDT)=0D
+ - Extended System Description Table (XSDT)=0D
+ Version is updated with a bit map containing all the versions of ACPI of=
which the table is a=0D
+ member. For tables installed via the EFI_ACPI_TABLE_PROTOCOL.InstallAcpi=
Table() interface,=0D
+ the function returns the value of EFI_ACPI_STD_PROTOCOL.AcpiVersion.=0D
+=0D
+ @param[in] Index The zero-based index of the table to retrieve.=
=0D
+ @param[out] Table Pointer for returning the table buffer.=0D
+ @param[out] Version On return, updated with the ACPI versions to w=
hich this table belongs. Type=0D
+ EFI_ACPI_TABLE_VERSION is defined in "Related =
Definitions" in the=0D
+ EFI_ACPI_SDT_PROTOCOL.=0D
+ @param[out] TableKey On return, points to the table key for the spe=
cified ACPI system definition table.=0D
+ This is identical to the table key used in the=
EFI_ACPI_TABLE_PROTOCOL.=0D
+ The TableKey can be passed to EFI_ACPI_TABLE_P=
ROTOCOL.UninstallAcpiTable()=0D
+ to uninstall the table.=0D
+ @retval EFI_SUCCESS The function completed successfully.=0D
+ @retval EFI_NOT_FOUND The requested index is too large and a table w=
as not found.=0D
+**/=0D
+EFI_STATUS=0D
+EFIAPI=0D
+GetAcpiTable2 (=0D
+ IN UINTN Index,=0D
+ OUT EFI_ACPI_SDT_HEADER **Table,=0D
+ OUT EFI_ACPI_TABLE_VERSION *Version,=0D
+ OUT UINTN *TableKey=0D
+ )=0D
+{=0D
+ EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance;=0D
+=0D
+ ASSERT (Table !=3D NULL);=0D
+ ASSERT (Version !=3D NULL);=0D
+ ASSERT (TableKey !=3D NULL);=0D
+=0D
+ //=0D
+ // Get the instance of the ACPI Table=0D
+ //=0D
+ AcpiTableInstance =3D SdtGetAcpiTableInstance ();=0D
+=0D
+ return SdtGetAcpiTable (AcpiTableInstance, Index, Table, Version, TableK=
ey);=0D
+}=0D
+=0D
+=0D
/**=0D
Register a callback when an ACPI table is installed.=0D
=0D
diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.h b/MdeModu=
lePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.h
index 9d7cf7ccfc..0af2d11a1a 100644
--- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.h
+++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.h
@@ -1,7 +1,7 @@
/** @file=0D
ACPI Table Protocol Driver=0D
=0D
- Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>=0D
+ Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>=0D
SPDX-License-Identifier: BSD-2-Clause-Patent=0D
=0D
**/=0D
@@ -24,6 +24,8 @@
#include <Library/MemoryAllocationLib.h>=0D
#include <Library/UefiBootServicesTableLib.h>=0D
#include <Library/PcdLib.h>=0D
+#include <Library/HobLib.h>=0D
+#include <UniversalPayload/AcpiTable.h>=0D
=0D
//=0D
// Statements that include other files=0D
@@ -228,6 +230,40 @@ SdtAcpiTableAcpiSdtConstructor (
IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance=0D
);=0D
=0D
+/**=0D
+ Returns a requested ACPI table.=0D
+=0D
+ The following structures are not considered elements in the list of=0D
+ ACPI tables:=0D
+ - Root System Description Pointer (RSD_PTR)=0D
+ - Root System Description Table (RSDT)=0D
+ - Extended System Description Table (XSDT)=0D
+ Version is updated with a bit map containing all the versions of ACPI of=
which the table is a=0D
+ member. For tables installed via the EFI_ACPI_TABLE_PROTOCOL.InstallAcpi=
Table() interface,=0D
+ the function returns the value of EFI_ACPI_STD_PROTOCOL.AcpiVersion.=0D
+=0D
+ @param[in] AcpiTableInstance ACPI table Instance.=0D
+ @param[in] Index The zero-based index of the table to re=
trieve.=0D
+ @param[out] Table Pointer for returning the table buffer.=
=0D
+ @param[out] Version On return, updated with the ACPI versio=
ns to which this table belongs. Type=0D
+ EFI_ACPI_TABLE_VERSION is defined in "R=
elated Definitions" in the=0D
+ EFI_ACPI_SDT_PROTOCOL.=0D
+ @param[out] TableKey On return, points to the table key for =
the specified ACPI system definition table.=0D
+ This is identical to the table key used=
in the EFI_ACPI_TABLE_PROTOCOL.=0D
+ The TableKey can be passed to EFI_ACPI_=
TABLE_PROTOCOL.UninstallAcpiTable()=0D
+ to uninstall the table.=0D
+ @retval EFI_SUCCESS The function completed successfully.=0D
+ @retval EFI_NOT_FOUND The requested index is too large and a =
table was not found.=0D
+**/=0D
+EFI_STATUS=0D
+SdtGetAcpiTable (=0D
+ IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,=0D
+ IN UINTN Index,=0D
+ OUT EFI_ACPI_SDT_HEADER **Table,=0D
+ OUT EFI_ACPI_TABLE_VERSION *Version,=0D
+ OUT UINTN *TableKey=0D
+ );=0D
+=0D
//=0D
// export PrivateData symbol, because we need that in AcpiSdtProtol implem=
entation=0D
//=0D
diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf b/Md=
eModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
index d341df439e..86dea43e27 100644
--- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
+++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
@@ -4,7 +4,7 @@
# This driver initializes ACPI tables (Rsdp, Rsdt and Xsdt) and produces =
UEFI/PI=0D
# services to install/uninstall/manage ACPI tables.=0D
#=0D
-# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>=
=0D
+# Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>=
=0D
# Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>=0D
# SPDX-License-Identifier: BSD-2-Clause-Patent=0D
#=0D
@@ -51,10 +51,12 @@
DebugLib=0D
BaseLib=0D
PcdLib=0D
+ HobLib=0D
=0D
[Guids]=0D
- gEfiAcpi10TableGuid ## PRODUCES ## SystemTable=
=0D
- gEfiAcpiTableGuid ## PRODUCES ## SystemTable=
=0D
+ gEfiAcpi10TableGuid ## PRODUCES ## S=
ystemTable=0D
+ gEfiAcpiTableGuid ## PRODUCES ## S=
ystemTable=0D
+ gUniversalPayloadAcpiTableGuid ## SOMETIMES_CONSUMES ## H=
OB=0D
=0D
[FeaturePcd]=0D
gEfiMdeModulePkgTokenSpaceGuid.PcdInstallAcpiSdtProtocol ## CONSUMES=0D
diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c b=
/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c
index 5a2afdff27..34d4a1cec0 100644
--- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c
+++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c
@@ -1,7 +1,7 @@
/** @file=0D
ACPI Table Protocol Implementation=0D
=0D
- Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>=0D
+ Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>=0D
Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>=0D
SPDX-License-Identifier: BSD-2-Clause-Patent=0D
=0D
@@ -30,6 +30,7 @@ STATIC EFI_ALLOCATE_TYPE mAcpiTableAllocType;
@param Table Table to add.=0D
@param Checksum Does the table require checksumming.=0D
@param Version The version of the list to add the tab=
le to.=0D
+ @param IsFromHob True, if add Apci Table from Hob List.=
=0D
@param Handle Pointer for returning the handle.=0D
=0D
@return EFI_SUCCESS The function completed successfully.=0D
@@ -44,6 +45,7 @@ AddTableToList (
IN VOID *Table,=0D
IN BOOLEAN Checksum,=0D
IN EFI_ACPI_TABLE_VERSION Version,=0D
+ IN BOOLEAN IsFromHob,=0D
OUT UINTN *Handle=0D
);=0D
=0D
@@ -238,6 +240,7 @@ InstallAcpiTable (
AcpiTableBufferConst,=0D
TRUE,=0D
Version,=0D
+ FALSE,=0D
TableKey=0D
);=0D
if (!EFI_ERROR (Status)) {=0D
@@ -472,6 +475,7 @@ FreeTableMemory (
@param Table Table to add.=0D
@param Checksum Does the table require checksumming.=0D
@param Version The version of the list to add the tab=
le to.=0D
+ @param IsFromHob True, if add Apci Table from Hob List.=
=0D
@param Handle Pointer for returning the handle.=0D
=0D
@return EFI_SUCCESS The function completed successfully.=0D
@@ -487,6 +491,7 @@ AddTableToList (
IN VOID *Table,=0D
IN BOOLEAN Checksum,=0D
IN EFI_ACPI_TABLE_VERSION Version,=0D
+ IN BOOLEAN IsFromHob,=0D
OUT UINTN *Handle=0D
)=0D
{=0D
@@ -553,12 +558,17 @@ AddTableToList (
// SMM communication ACPI table.=0D
//=0D
ASSERT ((EFI_PAGE_SIZE % 64) =3D=3D 0);=0D
- Status =3D gBS->AllocatePages (=0D
- AllocateMaxAddress,=0D
- EfiACPIMemoryNVS,=0D
- EFI_SIZE_TO_PAGES (CurrentTableList->TableSize),=0D
- &AllocPhysAddress=0D
- );=0D
+ if (IsFromHob){=0D
+ AllocPhysAddress =3D (UINTN)Table;=0D
+ Status =3D EFI_SUCCESS;=0D
+ } else {=0D
+ Status =3D gBS->AllocatePages (=0D
+ AllocateMaxAddress,=0D
+ EfiACPIMemoryNVS,=0D
+ EFI_SIZE_TO_PAGES (CurrentTableList->TableSize),=0D
+ &AllocPhysAddress=0D
+ );=0D
+ }=0D
} else if (mAcpiTableAllocType =3D=3D AllocateAnyPages) {=0D
//=0D
// If there is no allocation limit, there is also no need to use page=
=0D
@@ -1689,6 +1699,151 @@ ChecksumCommonTables (
return EFI_SUCCESS;=0D
}=0D
=0D
+/**=0D
+ This function will find gUniversalPayloadAcpiTableGuid Guid Hob, and ins=
tall Acpi table from it.=0D
+=0D
+ @param AcpiTableInstance Protocol instance private data.=0D
+=0D
+ @return EFI_SUCCESS The function completed successfully.=0D
+ @return EFI_NOT_FOUND The function doesn't find the gEfiAcpiTableGu=
id Guid Hob.=0D
+ @return EFI_ABORTED The function could not complete successfully.=
=0D
+=0D
+**/=0D
+EFI_STATUS=0D
+InstallAcpiTableFromHob (=0D
+ EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance=0D
+ )=0D
+{=0D
+ EFI_HOB_GUID_TYPE *GuidHob;=0D
+ EFI_ACPI_TABLE_VERSION Version;=0D
+ EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp;=0D
+ EFI_ACPI_DESCRIPTION_HEADER *Rsdt;=0D
+ EFI_ACPI_DESCRIPTION_HEADER *ChildTable;=0D
+ UINT64 ChildTableAddress;=0D
+ UINTN Count;=0D
+ UINTN Index;=0D
+ UINTN TableKey;=0D
+ EFI_STATUS Status;=0D
+ UINTN EntrySize;=0D
+ UNIVERSAL_PAYLOAD_ACPI_TABLE *AcpiTableAdress;=0D
+ VOID *TableToInstall;=0D
+ EFI_ACPI_SDT_HEADER *Table;=0D
+ UNIVERSAL_PAYLOAD_GENERIC_HEADER *GenericHeader;=0D
+=0D
+ TableKey =3D 0;=0D
+ Version =3D PcdGet32 (PcdAcpiExposedTableVersions);=0D
+ Status =3D EFI_SUCCESS;=0D
+ //=0D
+ // HOB only contains the ACPI table in 2.0+ format.=0D
+ //=0D
+ GuidHob =3D GetFirstGuidHob (&gUniversalPayloadAcpiTableGuid);=0D
+ if (GuidHob =3D=3D NULL) {=0D
+ return EFI_NOT_FOUND;=0D
+ }=0D
+=0D
+ GenericHeader =3D (UNIVERSAL_PAYLOAD_GENERIC_HEADER *) GET_GUID_HOB_DATA=
(GuidHob);=0D
+ if ((sizeof (UNIVERSAL_PAYLOAD_GENERIC_HEADER) > GET_GUID_HOB_DATA_SIZE =
(GuidHob)) || (GenericHeader->Length > GET_GUID_HOB_DATA_SIZE (GuidHob))) {=
=0D
+ return EFI_NOT_FOUND;=0D
+ }=0D
+ if (GenericHeader->Revision =3D=3D UNIVERSAL_PAYLOAD_ACPI_TABLE_REVISION=
) {=0D
+ //=0D
+ // UNIVERSAL_PAYLOAD_ACPI_TABLE structure is used when Revision equals=
to UNIVERSAL_PAYLOAD_ACPI_TABLE_REVISION=0D
+ //=0D
+ AcpiTableAdress =3D (UNIVERSAL_PAYLOAD_ACPI_TABLE *) GET_GUID_HOB_DATA=
(GuidHob);=0D
+ if (AcpiTableAdress->Header.Length < UNIVERSAL_PAYLOAD_SIZEOF_THROUGH_=
FIELD (UNIVERSAL_PAYLOAD_ACPI_TABLE, Rsdp)) {=0D
+ //=0D
+ // Retrun if can't find the ACPI Info Hob with enough length=0D
+ //=0D
+ return EFI_NOT_FOUND;=0D
+ }=0D
+ Rsdp =3D (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *) (UINTN) (Acp=
iTableAdress->Rsdp);=0D
+=0D
+ //=0D
+ // An ACPI-compatible OS must use the XSDT if present.=0D
+ // It shouldn't happen that XsdtAddress points beyond 4G range in 32-b=
it environment.=0D
+ //=0D
+ ASSERT ((UINTN) Rsdp->XsdtAddress =3D=3D Rsdp->XsdtAddress);=0D
+=0D
+ EntrySize =3D sizeof (UINT64);=0D
+ Rsdt =3D (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) Rsdp->XsdtAddress;=0D
+ if (Rsdt =3D=3D NULL) {=0D
+ //=0D
+ // XsdtAddress is zero, then we use Rsdt which has 32 bit entry=0D
+ //=0D
+ Rsdt =3D (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) Rsdp->RsdtAddress;=
=0D
+ EntrySize =3D sizeof (UINT32);=0D
+ }=0D
+=0D
+ if (Rsdt->Length <=3D sizeof (EFI_ACPI_DESCRIPTION_HEADER)) {=0D
+ return EFI_ABORTED;=0D
+ }=0D
+=0D
+ Count =3D (Rsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / Entr=
ySize;=0D
+=0D
+ for (Index =3D 0; Index < Count; Index++){=0D
+ ChildTableAddress =3D 0;=0D
+ CopyMem (&ChildTableAddress, (UINT8 *) (Rsdt + 1) + EntrySize * Inde=
x, EntrySize);=0D
+ //=0D
+ // If the address is of UINT64 while this module runs at 32 bits,=0D
+ // make sure the upper bits are all-zeros.=0D
+ //=0D
+ ASSERT (ChildTableAddress =3D=3D (UINTN) ChildTableAddress);=0D
+ if (ChildTableAddress !=3D (UINTN) ChildTableAddress) {=0D
+ Status =3D EFI_ABORTED;=0D
+ break;=0D
+ }=0D
+=0D
+ ChildTable =3D (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) ChildTableAdd=
ress;=0D
+ Status =3D AddTableToList (AcpiTableInstance, ChildTable, TRUE, Vers=
ion, TRUE, &TableKey);=0D
+ if (EFI_ERROR (Status)) {=0D
+ DEBUG ((DEBUG_ERROR, "InstallAcpiTableFromHob: Fail to add ACPI ta=
ble at 0x%p\n", ChildTable));=0D
+ ASSERT_EFI_ERROR (Status);=0D
+ break;=0D
+ }=0D
+ if (ChildTable->Signature =3D=3D EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION=
_TABLE_SIGNATURE){=0D
+ //=0D
+ // Add the FACS and DSDT tables if it is not NULL.=0D
+ //=0D
+ if (((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *) ChildTable)->Fi=
rmwareCtrl !=3D 0) {=0D
+ TableToInstall =3D (VOID *) (UINTN) ((EFI_ACPI_3_0_FIXED_ACPI_DE=
SCRIPTION_TABLE *) ChildTable)->FirmwareCtrl;=0D
+ Status =3D AddTableToList (AcpiTableInstance, TableToInstall, TR=
UE, Version, TRUE, &TableKey);=0D
+ if (EFI_ERROR (Status)) {=0D
+ DEBUG ((DEBUG_ERROR, "InstallAcpiTableFromHob: Fail to add ACP=
I table FACS\n"));=0D
+ ASSERT_EFI_ERROR (Status);=0D
+ break;=0D
+ }=0D
+ }=0D
+=0D
+ if (((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *) ChildTable)->Ds=
dt !=3D 0) {=0D
+ TableToInstall =3D (VOID *) (UINTN) ((EFI_ACPI_3_0_FIXED_ACPI_DE=
SCRIPTION_TABLE *) ChildTable)->Dsdt;=0D
+ Status =3D AddTableToList (AcpiTableInstance, TableToInstall, TR=
UE, Version, TRUE, &TableKey);=0D
+ if (EFI_ERROR (Status)) {=0D
+ DEBUG ((DEBUG_ERROR, "InstallAcpiTableFromHob: Fail to add ACP=
I table DSDT\n"));=0D
+ ASSERT_EFI_ERROR (Status);=0D
+ break;=0D
+ }=0D
+ }=0D
+ }=0D
+ }=0D
+ } else {=0D
+ return EFI_NOT_FOUND;=0D
+ }=0D
+=0D
+ if (EFI_ERROR (Status)) {=0D
+ //=0D
+ // Error happens when trying to add ACPI table to the list.=0D
+ // Remove all of them from list because at this time, no other tables =
except from HOB are in the list=0D
+ //=0D
+ while (SdtGetAcpiTable (AcpiTableInstance, 0, &Table, &Version, &Table=
Key) =3D=3D EFI_SUCCESS) {=0D
+ RemoveTableFromList (AcpiTableInstance, Version, TableKey);=0D
+ }=0D
+ } else {=0D
+ Status =3D PublishTables (AcpiTableInstance, Version);=0D
+ }=0D
+=0D
+ ASSERT_EFI_ERROR (Status);=0D
+ return Status;=0D
+}=0D
=0D
/**=0D
Constructor for the ACPI table protocol. Initializes instance=0D
@@ -1918,6 +2073,8 @@ AcpiTableAcpiTableConstructor (
=0D
ChecksumCommonTables (AcpiTableInstance);=0D
=0D
+ InstallAcpiTableFromHob (AcpiTableInstance);=0D
+=0D
//=0D
// Completed successfully=0D
//=0D
--=20
2.30.0.windows.2


[Patch V4 7/9] MdeModulePkg: Add new structure for the Universal Payload ACPI Table Info Hob

Zhiguang Liu
 

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
---
MdeModulePkg/Include/UniversalPayload/AcpiTable.h | 30 +++++++++++++++++++=
+++++++++++
MdeModulePkg/MdeModulePkg.dec | 3 +++
2 files changed, 33 insertions(+)

diff --git a/MdeModulePkg/Include/UniversalPayload/AcpiTable.h b/MdeModuleP=
kg/Include/UniversalPayload/AcpiTable.h
new file mode 100644
index 0000000000..ff60c74d86
--- /dev/null
+++ b/MdeModulePkg/Include/UniversalPayload/AcpiTable.h
@@ -0,0 +1,30 @@
+/** @file=0D
+ Define the structure for the Universal Payload APCI table.=0D
+=0D
+Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>=0D
+SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+=0D
+ @par Revision Reference:=0D
+ - Universal Payload Specification 0.75 (https://universalpayload.githu=
b.io/documentation/)=0D
+**/=0D
+=0D
+#ifndef __UNIVERSAL_PAYLOAD_ACPI_TABLE_H_=0D
+#define __UNIVERSAL_PAYLOAD_ACPI_TABLE_H_=0D
+=0D
+#include <Uefi.h>=0D
+#include <UniversalPayload/UniversalPayload.h>=0D
+=0D
+#pragma pack(1)=0D
+=0D
+typedef struct {=0D
+ UNIVERSAL_PAYLOAD_GENERIC_HEADER Header;=0D
+ EFI_PHYSICAL_ADDRESS Rsdp;=0D
+} UNIVERSAL_PAYLOAD_ACPI_TABLE;=0D
+=0D
+#pragma pack()=0D
+=0D
+#define UNIVERSAL_PAYLOAD_ACPI_TABLE_REVISION 1=0D
+=0D
+extern GUID gUniversalPayloadAcpiTableGuid;=0D
+=0D
+#endif //__UNIVERSAL_PAYLOAD_ACPI_TABLE_H_=0D
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index 377e868e7c..8c0885955b 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -416,6 +416,9 @@
## Include/UniversalPayload/SmbiosTable.h=0D
gUniversalPayloadSmbiosTableGuid =3D { 0x590a0d26, 0x06e5, 0x4d20, { 0x8=
a, 0x82, 0x59, 0xea, 0x1b, 0x34, 0x98, 0x2d } }=0D
=0D
+ ## Include/UniversalPayload/AcpiTable.h=0D
+ gUniversalPayloadAcpiTableGuid =3D { 0x9f9a9506, 0x5597, 0x4515, { 0xba,=
0xb6, 0x8b, 0xcd, 0xe7, 0x84, 0xba, 0x87 } }=0D
+=0D
[Ppis]=0D
## Include/Ppi/AtaController.h=0D
gPeiAtaControllerPpiGuid =3D { 0xa45e60d1, 0xc719, 0x44aa, { 0xb0,=
0x7a, 0xaa, 0x77, 0x7f, 0x85, 0x90, 0x6d }}=0D
--=20
2.30.0.windows.2


[Patch V4 6/9] UefiPayloadPkg: Creat gPldSmbiosTableGuid Hob

Zhiguang Liu
 

From SysTableInfo Hob, get Smbios table address, and creat gPldSmbiosTableG=
uid Hob
to store it. Remove diretly adding smbios table to ConfigurationTable.
Dxe module SmbiosDxe will parse it and install smbios table from it.

Cc: Maurice Ma <maurice.ma@intel.com>
Cc: Guo Dong <guo.dong@intel.com>
Cc: Benjamin You <benjamin.you@intel.com>
Reviewed-by: Guo Dong <guo.dong@intel.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
---
UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c | 11 +----------
UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf | 3 +--
UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c | 12 +++++++++++-
UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h | 3 ++-
UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf | 3 ++-
5 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c b/UefiPayloadPkg/Bl=
SupportDxe/BlSupportDxe.c
index a746d0581e..56b85b8e6d 100644
--- a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c
+++ b/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c
@@ -2,7 +2,7 @@
This driver will report some MMIO/IO resources to dxe core, extract smbi=
os and acpi=0D
tables from bootloader.=0D
=0D
- Copyright (c) 2014 - 2020, Intel Corporation. All rights reserved.<BR>=0D
+ Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.<BR>=0D
SPDX-License-Identifier: BSD-2-Clause-Patent=0D
=0D
**/=0D
@@ -129,15 +129,6 @@ BlDxeEntryPoint (
ASSERT_EFI_ERROR (Status);=0D
}=0D
=0D
- //=0D
- // Install Smbios Table=0D
- //=0D
- if (SystemTableInfo->SmbiosTableBase !=3D 0 && SystemTableInfo->SmbiosTa=
bleSize !=3D 0) {=0D
- DEBUG ((DEBUG_ERROR, "Install Smbios Table at 0x%lx, length 0x%x\n", S=
ystemTableInfo->SmbiosTableBase, SystemTableInfo->SmbiosTableSize));=0D
- Status =3D gBS->InstallConfigurationTable (&gEfiSmbiosTableGuid, (VOID=
*)(UINTN)SystemTableInfo->SmbiosTableBase);=0D
- ASSERT_EFI_ERROR (Status);=0D
- }=0D
-=0D
//=0D
// Find the frame buffer information and update PCDs=0D
//=0D
diff --git a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf b/UefiPayloadPkg/=
BlSupportDxe/BlSupportDxe.inf
index cebc811355..30f41f8c39 100644
--- a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf
+++ b/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf
@@ -3,7 +3,7 @@
#=0D
# Report some MMIO/IO resources to dxe core, extract smbios and acpi table=
s=0D
#=0D
-# Copyright (c) 2014 - 2020, Intel Corporation. All rights reserved.<BR>=
=0D
+# Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.<BR>=
=0D
#=0D
# SPDX-License-Identifier: BSD-2-Clause-Patent=0D
#=0D
@@ -43,7 +43,6 @@
=0D
[Guids]=0D
gEfiAcpiTableGuid=0D
- gEfiSmbiosTableGuid=0D
gUefiSystemTableInfoGuid=0D
gUefiAcpiBoardInfoGuid=0D
gEfiGraphicsInfoHobGuid=0D
diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c b/UefiPaylo=
adPkg/UefiPayloadEntry/UefiPayloadEntry.c
index 805f5448d9..80f66a3fd5 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c
+++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c
@@ -1,6 +1,6 @@
/** @file=0D
=0D
- Copyright (c) 2014 - 2020, Intel Corporation. All rights reserved.<BR>=0D
+ Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.<BR>=0D
SPDX-License-Identifier: BSD-2-Clause-Patent=0D
=0D
**/=0D
@@ -234,6 +234,7 @@ BuildHobFromBl (
EFI_PEI_GRAPHICS_INFO_HOB *NewGfxInfo;=0D
EFI_PEI_GRAPHICS_DEVICE_INFO_HOB GfxDeviceInfo;=0D
EFI_PEI_GRAPHICS_DEVICE_INFO_HOB *NewGfxDeviceInfo;=0D
+ UNIVERSAL_PAYLOAD_SMBIOS_TABLE *SmBiosTableHob;=0D
=0D
//=0D
// Parse memory info and build memory HOBs=0D
@@ -276,6 +277,15 @@ BuildHobFromBl (
DEBUG ((DEBUG_INFO, "Detected Acpi Table at 0x%lx, length 0x%x\n", Sys=
TableInfo.AcpiTableBase, SysTableInfo.AcpiTableSize));=0D
DEBUG ((DEBUG_INFO, "Detected Smbios Table at 0x%lx, length 0x%x\n", S=
ysTableInfo.SmbiosTableBase, SysTableInfo.SmbiosTableSize));=0D
}=0D
+ //=0D
+ // Creat SmBios table Hob=0D
+ //=0D
+ SmBiosTableHob =3D BuildGuidHob (&gUniversalPayloadSmbiosTableGuid, size=
of (UNIVERSAL_PAYLOAD_SMBIOS_TABLE));=0D
+ ASSERT (SmBiosTableHob !=3D NULL);=0D
+ SmBiosTableHob->Header.Revision =3D UNIVERSAL_PAYLOAD_SMBIOS_TABLE_REVIS=
ION;=0D
+ SmBiosTableHob->Header.Length =3D sizeof (UNIVERSAL_PAYLOAD_SMBIOS_TABLE=
);=0D
+ SmBiosTableHob->SmBiosEntryPoint =3D SysTableInfo.SmbiosTableBase;=0D
+ DEBUG ((DEBUG_INFO, "Create smbios table gUniversalPayloadSmbiosTableGui=
d guid hob\n"));=0D
=0D
//=0D
// Create guid hob for acpi board information=0D
diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h b/UefiPaylo=
adPkg/UefiPayloadEntry/UefiPayloadEntry.h
index 2c84d6ed53..e7d0d15118 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h
+++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h
@@ -1,6 +1,6 @@
/** @file=0D
*=0D
-* Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>=0D
+* Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>=0D
*=0D
* SPDX-License-Identifier: BSD-2-Clause-Patent=0D
*=0D
@@ -31,6 +31,7 @@
#include <Guid/MemoryMapInfoGuid.h>=0D
#include <Guid/AcpiBoardInfoGuid.h>=0D
#include <Guid/GraphicsInfoHob.h>=0D
+#include <UniversalPayload/SmbiosTable.h>=0D
=0D
=0D
#define LEGACY_8259_MASK_REGISTER_MASTER 0x21=0D
diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf b/UefiPay=
loadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
index cc59f1903b..fc5b5ce9d4 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
+++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
@@ -1,7 +1,7 @@
## @file=0D
# This is the first module for UEFI payload.=0D
#=0D
-# Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.<BR>=
=0D
+# Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>=
=0D
# Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>=0D
#=0D
# SPDX-License-Identifier: BSD-2-Clause-Patent=0D
@@ -64,6 +64,7 @@
gEfiGraphicsInfoHobGuid=0D
gEfiGraphicsDeviceInfoHobGuid=0D
gUefiAcpiBoardInfoGuid=0D
+ gUniversalPayloadSmbiosTableGuid=0D
=0D
[FeaturePcd.IA32]=0D
gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode ## CONSUME=
S=0D
--=20
2.30.0.windows.2


[Patch V4 5/9] MdeModulePkg/Universal/SmbiosDxe: Scan for existing tables

Zhiguang Liu
 

V1:
The default EfiSmbiosProtocol operates on an empty SMBIOS table.
The SMBIOS tables are provided by the bootloader on UefiPayloadPkg.
Scan for existing tables in SmbiosDxe and load them if they seem valid.

This fixes the settings menu not showing any hardware information, instead
only "0 MB RAM" was displayed.

Tests showed that the OS can still see the SMBIOS tables.

V2:
SmbiosDxe will get the SMBIOS from a guid Hob.
Also will keep the SmbiosHandle if it is available.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Zhichao Gao <zhichao.gao@intel.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
---
MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c | 293 +++++++++++++++++++++=
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
++++++++++++++++++++++++++++++++++++++++++++++-
MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.h | 65 +++++++++++++++++++++=
+++++++++++++++++++++++++++++++++++++++++++-
MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf | 5 ++++-
3 files changed, 360 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c b/MdeModulePkg/Un=
iversal/SmbiosDxe/SmbiosDxe.c
index 3cdb0b1ed7..400b0fa578 100644
--- a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c
+++ b/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c
@@ -2,7 +2,7 @@
This code produces the Smbios protocol. It also responsible for construc=
ting=0D
SMBIOS table into system table.=0D
=0D
-Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>=0D
+Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.<BR>=0D
SPDX-License-Identifier: BSD-2-Clause-Patent=0D
=0D
**/=0D
@@ -148,6 +148,12 @@ SMBIOS_TABLE_3_0_ENTRY_POINT Smbios30EntryPointStructu=
reData =3D {
//=0D
0=0D
};=0D
+=0D
+IS_SMBIOS_TABLE_VALID_ENTRY mIsSmbiosTableValid[] =3D {=0D
+ {&gUniversalPayloadSmbios3TableGuid, IsValidSmbios30Table },=0D
+ {&gUniversalPayloadSmbiosTableGuid, IsValidSmbios20Table }=0D
+};=0D
+=0D
/**=0D
=0D
Get the full size of SMBIOS structure including optional strings that fo=
llow the formatted structure.=0D
@@ -1408,6 +1414,290 @@ SmbiosTableConstruction (
}=0D
}=0D
=0D
+/**=0D
+ Validates a SMBIOS 2.0 table entry point.=0D
+=0D
+ @param TableEntry The SmBios table entry to validate.=0D
+ @param TableAddress On exit, point to the smbios table addres.=0D
+ @param TableMaximumSize On exit, point to the maximum size of the table=
.=0D
+=0D
+ @retval TRUE SMBIOS table entry point is valid.=0D
+ @retval FALSE SMBIOS table entry point is malformed.=0D
+=0D
+**/=0D
+STATIC=0D
+BOOLEAN=0D
+IsValidSmbios20Table (=0D
+ IN VOID *TableEntry,=0D
+ OUT VOID **TableAddress,=0D
+ OUT UINTN *TableMaximumSize=0D
+ )=0D
+{=0D
+ UINT8 Checksum;=0D
+ SMBIOS_TABLE_ENTRY_POINT *SmbiosTable;=0D
+ SmbiosTable =3D (SMBIOS_TABLE_ENTRY_POINT *) TableEntry;=0D
+=0D
+ if (CompareMem (SmbiosTable->AnchorString, "_SM_", 4) !=3D 0) {=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ if (CompareMem (SmbiosTable->IntermediateAnchorString, "_DMI_", 5) !=3D =
0) {=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ //=0D
+ // The actual value of the EntryPointLength should be 1Fh.=0D
+ // However, it was incorrectly stated in version 2.1 of smbios specifica=
tion.=0D
+ // Therefore, 0x1F and 0x1E are both accepted.=0D
+ //=0D
+ if (SmbiosTable->EntryPointLength !=3D 0x1E && SmbiosTable->EntryPointLe=
ngth !=3D sizeof (SMBIOS_TABLE_ENTRY_POINT)) {=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ //=0D
+ // MajorVersion should not be less than 2.=0D
+ //=0D
+ if (SmbiosTable->MajorVersion < 2) {=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ //=0D
+ // The whole struct check sum should be zero=0D
+ //=0D
+ Checksum =3D CalculateSum8 (=0D
+ (UINT8 *) SmbiosTable,=0D
+ SmbiosTable->EntryPointLength=0D
+ );=0D
+ if (Checksum !=3D 0) {=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ //=0D
+ // The Intermediate Entry Point Structure check sum should be zero.=0D
+ //=0D
+ Checksum =3D CalculateSum8 (=0D
+ (UINT8 *) SmbiosTable + OFFSET_OF (SMBIOS_TABLE_ENTRY_POINT=
, IntermediateAnchorString),=0D
+ SmbiosTable->EntryPointLength - OFFSET_OF (SMBIOS_TABLE_ENT=
RY_POINT, IntermediateAnchorString)=0D
+ );=0D
+ if (Checksum !=3D 0) {=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ *TableAddress =3D (VOID *) (UINTN) SmbiosTable->TableAddress;=0D
+ *TableMaximumSize =3D SmbiosTable->TableLength;=0D
+ return TRUE;=0D
+}=0D
+=0D
+/**=0D
+ Validates a SMBIOS 3.0 table entry point.=0D
+=0D
+ @param TableEntry The SmBios table entry to validate.=0D
+ @param TableAddress On exit, point to the smbios table addres.=0D
+ @param TableMaximumSize On exit, point to the maximum size of the table=
.=0D
+=0D
+ @retval TRUE SMBIOS table entry point is valid.=0D
+ @retval FALSE SMBIOS table entry point is malformed.=0D
+=0D
+**/=0D
+STATIC=0D
+BOOLEAN=0D
+IsValidSmbios30Table (=0D
+ IN VOID *TableEntry,=0D
+ OUT VOID **TableAddress,=0D
+ OUT UINTN *TableMaximumSize=0D
+ )=0D
+{=0D
+ UINT8 Checksum;=0D
+ SMBIOS_TABLE_3_0_ENTRY_POINT *SmbiosTable;=0D
+ SmbiosTable =3D (SMBIOS_TABLE_3_0_ENTRY_POINT *) TableEntry;=0D
+=0D
+ if (CompareMem (SmbiosTable->AnchorString, "_SM3_", 5) !=3D 0) {=0D
+ return FALSE;=0D
+ }=0D
+ if (SmbiosTable->EntryPointLength < sizeof (SMBIOS_TABLE_3_0_ENTRY_POINT=
)) {=0D
+ return FALSE;=0D
+ }=0D
+ if (SmbiosTable->MajorVersion < 3) {=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ //=0D
+ // The whole struct check sum should be zero=0D
+ //=0D
+ Checksum =3D CalculateSum8 (=0D
+ (UINT8 *) SmbiosTable,=0D
+ SmbiosTable->EntryPointLength=0D
+ );=0D
+ if (Checksum !=3D 0) {=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ *TableAddress =3D (VOID *) (UINTN) SmbiosTable->TableAddress;=0D
+ *TableMaximumSize =3D SmbiosTable->TableMaximumSize;=0D
+ return TRUE;=0D
+}=0D
+=0D
+/**=0D
+ Parse an existing SMBIOS table and insert it using SmbiosAdd.=0D
+=0D
+ @param ImageHandle The EFI_HANDLE to this driver.=0D
+ @param Smbios The SMBIOS table to parse.=0D
+ @param Length The length of the SMBIOS table.=0D
+=0D
+ @retval EFI_SUCCESS SMBIOS table was parsed and installed.=0D
+ @retval EFI_OUT_OF_RESOURCES Record was not added due to lack of system=
resources.=0D
+ @retval EFI_INVALID_PARAMETER Smbios is not a correct smbios table=0D
+=0D
+**/=0D
+STATIC=0D
+EFI_STATUS=0D
+ParseAndAddExistingSmbiosTable (=0D
+ IN EFI_HANDLE ImageHandle,=0D
+ IN SMBIOS_STRUCTURE_POINTER Smbios,=0D
+ IN UINTN Length=0D
+ )=0D
+{=0D
+ EFI_STATUS Status;=0D
+ CHAR8 *String;=0D
+ EFI_SMBIOS_HANDLE SmbiosHandle;=0D
+ SMBIOS_STRUCTURE_POINTER SmbiosEnd;=0D
+=0D
+ SmbiosEnd.Raw =3D Smbios.Raw + Length;=0D
+=0D
+ if (Smbios.Raw >=3D SmbiosEnd.Raw || Smbios.Raw =3D=3D NULL) {=0D
+ return EFI_INVALID_PARAMETER;=0D
+ }=0D
+=0D
+ do {=0D
+ //=0D
+ // Make sure not to access memory beyond SmbiosEnd=0D
+ //=0D
+ if (Smbios.Raw + sizeof (SMBIOS_STRUCTURE) > SmbiosEnd.Raw ||=0D
+ Smbios.Raw + sizeof (SMBIOS_STRUCTURE) < Smbios.Raw) {=0D
+ return EFI_INVALID_PARAMETER;=0D
+ }=0D
+ //=0D
+ // Check for end marker=0D
+ //=0D
+ if (Smbios.Hdr->Type =3D=3D SMBIOS_TYPE_END_OF_TABLE) {=0D
+ break;=0D
+ }=0D
+ //=0D
+ // Make sure not to access memory beyond SmbiosEnd=0D
+ // Each structure shall be terminated by a double-null (0000h).=0D
+ //=0D
+ if (Smbios.Raw + Smbios.Hdr->Length + 2 * sizeof (UINT8) > SmbiosEnd.R=
aw ||=0D
+ Smbios.Raw + Smbios.Hdr->Length + 2 * sizeof (UINT8) < Smbios.Raw) {=
=0D
+ return EFI_INVALID_PARAMETER;=0D
+ }=0D
+ //=0D
+ // Install the table=0D
+ //=0D
+ SmbiosHandle =3D Smbios.Hdr->Handle;=0D
+ Status =3D SmbiosAdd (=0D
+ &mPrivateData.Smbios,=0D
+ ImageHandle,=0D
+ &SmbiosHandle,=0D
+ Smbios.Hdr=0D
+ );=0D
+=0D
+ ASSERT_EFI_ERROR (Status);=0D
+ if (EFI_ERROR (Status)) {=0D
+ return Status;=0D
+ }=0D
+ //=0D
+ // Go to the next SMBIOS structure. Each SMBIOS structure may include =
2 parts:=0D
+ // 1. Formatted section; 2. Unformatted string section. So, 2 steps ar=
e needed=0D
+ // to skip one SMBIOS structure.=0D
+ //=0D
+=0D
+ //=0D
+ // Step 1: Skip over formatted section.=0D
+ //=0D
+ String =3D (CHAR8 *) (Smbios.Raw + Smbios.Hdr->Length);=0D
+=0D
+ //=0D
+ // Step 2: Skip over unformatted string section.=0D
+ //=0D
+ do {=0D
+ //=0D
+ // Each string is terminated with a NULL(00h) BYTE and the sets of s=
trings=0D
+ // is terminated with an additional NULL(00h) BYTE.=0D
+ //=0D
+ for ( ; *String !=3D 0; String++) {=0D
+ if ((UINTN) String >=3D (UINTN) SmbiosEnd.Raw - sizeof (UINT8)) {=
=0D
+ return EFI_INVALID_PARAMETER;=0D
+ }=0D
+ }=0D
+=0D
+ if (*(UINT8 *) ++String =3D=3D 0) {=0D
+ //=0D
+ // Pointer to the next SMBIOS structure.=0D
+ //=0D
+ Smbios.Raw =3D (UINT8 *) ++String;=0D
+ break;=0D
+ }=0D
+ } while (TRUE);=0D
+ } while (Smbios.Raw < SmbiosEnd.Raw);=0D
+=0D
+ return EFI_SUCCESS;=0D
+}=0D
+=0D
+/**=0D
+ Retrieve SMBIOS from Hob.=0D
+ @param ImageHandle Module's image handle=0D
+=0D
+ @retval EFI_SUCCESS Smbios from Hob is installed.=0D
+ @return EFI_NOT_FOUND Not found Smbios from Hob.=0D
+ @retval Other No Smbios from Hob is installed.=0D
+=0D
+**/=0D
+EFI_STATUS=0D
+RetrieveSmbiosFromHob (=0D
+ IN EFI_HANDLE ImageHandle=0D
+ )=0D
+{=0D
+ EFI_STATUS Status;=0D
+ UINTN Index;=0D
+ SMBIOS_STRUCTURE_POINTER Smbios;=0D
+ EFI_HOB_GUID_TYPE *GuidHob;=0D
+ UNIVERSAL_PAYLOAD_SMBIOS_TABLE *SmBiosTableAdress;=0D
+ UNIVERSAL_PAYLOAD_GENERIC_HEADER *GenericHeader;=0D
+ VOID *TableAddress;=0D
+ UINTN TableMaximumSize;=0D
+=0D
+ Status =3D EFI_NOT_FOUND;=0D
+=0D
+ for (Index =3D 0; Index < ARRAY_SIZE (mIsSmbiosTableValid); Index++) {=0D
+ GuidHob =3D GetFirstGuidHob (mIsSmbiosTableValid[Index].Guid);=0D
+ if (GuidHob =3D=3D NULL) {=0D
+ continue;=0D
+ }=0D
+ GenericHeader =3D (UNIVERSAL_PAYLOAD_GENERIC_HEADER *) GET_GUID_HOB_DA=
TA (GuidHob);=0D
+ if ((sizeof (UNIVERSAL_PAYLOAD_GENERIC_HEADER) <=3D GET_GUID_HOB_DATA_=
SIZE (GuidHob)) && (GenericHeader->Length <=3D GET_GUID_HOB_DATA_SIZE (Guid=
Hob))) {=0D
+ if (GenericHeader->Revision =3D=3D UNIVERSAL_PAYLOAD_SMBIOS_TABLE_RE=
VISION) {=0D
+ //=0D
+ // UNIVERSAL_PAYLOAD_SMBIOS_TABLE structure is used when Revision =
equals to UNIVERSAL_PAYLOAD_SMBIOS_TABLE_REVISION=0D
+ //=0D
+ SmBiosTableAdress =3D (UNIVERSAL_PAYLOAD_SMBIOS_TABLE *) GET_GUID_=
HOB_DATA (GuidHob);=0D
+ if (GenericHeader->Length >=3D UNIVERSAL_PAYLOAD_SIZEOF_THROUGH_FI=
ELD (UNIVERSAL_PAYLOAD_SMBIOS_TABLE, SmBiosEntryPoint)) {=0D
+ if (mIsSmbiosTableValid[Index].IsValid ((VOID *) (UINTN )SmBiosT=
ableAdress->SmBiosEntryPoint, &TableAddress, &TableMaximumSize)) {=0D
+ Smbios.Raw =3D TableAddress;=0D
+ Status =3D ParseAndAddExistingSmbiosTable (ImageHandle, Smbios=
, TableMaximumSize);=0D
+ if (EFI_ERROR (Status)) {=0D
+ DEBUG ((DEBUG_ERROR, "RetrieveSmbiosFromHob: Failed to parse=
preinstalled tables from Guid Hob\n"));=0D
+ Status =3D EFI_UNSUPPORTED;=0D
+ } else {=0D
+ return EFI_SUCCESS;=0D
+ }=0D
+ }=0D
+ }=0D
+ }=0D
+ }=0D
+ }=0D
+ return Status;=0D
+}=0D
+=0D
/**=0D
=0D
Driver to produce Smbios protocol and pre-allocate 1 page for the final =
SMBIOS table.=0D
@@ -1451,5 +1741,6 @@ SmbiosDriverEntryPoint (
&mPrivateData.Smbios=0D
);=0D
=0D
+ RetrieveSmbiosFromHob (ImageHandle);=0D
return Status;=0D
}=0D
diff --git a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.h b/MdeModulePkg/Un=
iversal/SmbiosDxe/SmbiosDxe.h
index f97c85ae40..a131bdabec 100644
--- a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.h
+++ b/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.h
@@ -1,7 +1,7 @@
/** @file=0D
This code supports the implementation of the Smbios protocol=0D
=0D
-Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>=0D
+Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.<BR>=0D
SPDX-License-Identifier: BSD-2-Clause-Patent=0D
=0D
**/=0D
@@ -24,6 +24,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/MemoryAllocationLib.h>=0D
#include <Library/UefiBootServicesTableLib.h>=0D
#include <Library/PcdLib.h>=0D
+#include <Library/HobLib.h>=0D
+#include <UniversalPayload/SmbiosTable.h>=0D
=0D
#define SMBIOS_INSTANCE_SIGNATURE SIGNATURE_32 ('S', 'B', 'i', 's')=0D
typedef struct {=0D
@@ -121,4 +123,65 @@ SmbiosTableConstruction (
BOOLEAN Smbios64BitTable=0D
);=0D
=0D
+/**=0D
+ Validates a SMBIOS 3.0 table entry point.=0D
+=0D
+ @param TableEntry The SmBios table entry to validate.=0D
+ @param TableAddress On exit, point to the smbios table addres.=0D
+ @param TableMaximumSize On exit, point to the maximum size of the table=
.=0D
+=0D
+ @retval TRUE SMBIOS table entry point is valid.=0D
+ @retval FALSE SMBIOS table entry point is malformed.=0D
+=0D
+**/=0D
+STATIC=0D
+BOOLEAN=0D
+IsValidSmbios30Table (=0D
+ IN VOID *TableEntry,=0D
+ OUT VOID **TableAddress,=0D
+ OUT UINTN *TableMaximumSize=0D
+ );=0D
+=0D
+/**=0D
+ Validates a SMBIOS 2.0 table entry point.=0D
+=0D
+ @param TableEntry The SmBios table entry to validate.=0D
+ @param TableAddress On exit, point to the smbios table addres.=0D
+ @param TableMaximumSize On exit, point to the maximum size of the table=
.=0D
+=0D
+ @retval TRUE SMBIOS table entry point is valid.=0D
+ @retval FALSE SMBIOS table entry point is malformed.=0D
+=0D
+**/=0D
+STATIC=0D
+BOOLEAN=0D
+IsValidSmbios20Table (=0D
+ IN VOID *TableEntry,=0D
+ OUT VOID **TableAddress,=0D
+ OUT UINTN *TableMaximumSize=0D
+ );=0D
+=0D
+/**=0D
+ Validates a SMBIOS table entry point.=0D
+=0D
+ @param TableEntry The SmBios table entry to validate.=0D
+ @param TableAddress On exit, point to the smbios table addres.=0D
+ @param TableMaximumSize On exit, point to the maximum size of the table=
.=0D
+=0D
+ @retval TRUE SMBIOS table entry point is valid.=0D
+ @retval FALSE SMBIOS table entry point is malformed.=0D
+=0D
+**/=0D
+typedef=0D
+BOOLEAN=0D
+(* IS_SMBIOS_TABLE_VALID) (=0D
+ IN VOID *TableEntry,=0D
+ OUT VOID **TableAddress,=0D
+ OUT UINTN *TableMaximumSize=0D
+ );=0D
+typedef struct {=0D
+ EFI_GUID *Guid;=0D
+ IS_SMBIOS_TABLE_VALID IsValid;=0D
+} IS_SMBIOS_TABLE_VALID_ENTRY;=0D
+=0D
#endif=0D
diff --git a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf b/MdeModulePkg/=
Universal/SmbiosDxe/SmbiosDxe.inf
index f6c036e1dc..c03915a692 100644
--- a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf
+++ b/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf
@@ -1,7 +1,7 @@
## @file=0D
# This driver initializes and installs the SMBIOS protocol, constructs SMB=
IOS table into system configuration table.=0D
#=0D
-# Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>=0D
+# Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.<BR>=0D
#=0D
# SPDX-License-Identifier: BSD-2-Clause-Patent=0D
#=0D
@@ -41,6 +41,7 @@
UefiDriverEntryPoint=0D
DebugLib=0D
PcdLib=0D
+ HobLib=0D
=0D
[Protocols]=0D
gEfiSmbiosProtocolGuid ## PRODUCES=0D
@@ -48,6 +49,8 @@
[Guids]=0D
gEfiSmbiosTableGuid ## SOMETIMES_PRODUCES =
## SystemTable=0D
gEfiSmbios3TableGuid ## SOMETIMES_PRODUCES =
## SystemTable=0D
+ gUniversalPayloadSmbios3TableGuid ## CONSUMES =
## HOB=0D
+ gUniversalPayloadSmbiosTableGuid ## SOMETIMES_CONSUMES =
## HOB=0D
=0D
[Pcd]=0D
gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosVersion ## CONSUMES=0D
--=20
2.30.0.windows.2


[Patch V4 4/9] MdeModulePkg: Add new structure for the Universal Payload SMBios Table Info Hob

Zhiguang Liu
 

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
---
MdeModulePkg/Include/UniversalPayload/SmbiosTable.h | 30 +++++++++++++++++=
+++++++++++++
MdeModulePkg/MdeModulePkg.dec | 6 ++++++
2 files changed, 36 insertions(+)

diff --git a/MdeModulePkg/Include/UniversalPayload/SmbiosTable.h b/MdeModul=
ePkg/Include/UniversalPayload/SmbiosTable.h
new file mode 100644
index 0000000000..64afba6fe1
--- /dev/null
+++ b/MdeModulePkg/Include/UniversalPayload/SmbiosTable.h
@@ -0,0 +1,30 @@
+/** @file=0D
+ Define the structure for the Universal Payload SmBios.=0D
+=0D
+Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>=0D
+SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+=0D
+ @par Revision Reference:=0D
+ - Universal Payload Specification 0.75 (https://universalpayload.githu=
b.io/documentation/)=0D
+**/=0D
+=0D
+#ifndef __UNIVERSAL_PAYLOAD_SMBIOS_TABLE_H_=0D
+#define __UNIVERSAL_PAYLOAD_SMBIOS_TABLE_H_=0D
+=0D
+#include <Uefi.h>=0D
+#include <UniversalPayload/UniversalPayload.h>=0D
+=0D
+#pragma pack (1)=0D
+=0D
+typedef struct {=0D
+ UNIVERSAL_PAYLOAD_GENERIC_HEADER Header;=0D
+ EFI_PHYSICAL_ADDRESS SmBiosEntryPoint;=0D
+} UNIVERSAL_PAYLOAD_SMBIOS_TABLE;=0D
+=0D
+#pragma pack()=0D
+=0D
+#define UNIVERSAL_PAYLOAD_SMBIOS_TABLE_REVISION 1=0D
+=0D
+extern GUID gUniversalPayloadSmbios3TableGuid;=0D
+extern GUID gUniversalPayloadSmbiosTableGuid;=0D
+#endif //__UNIVERSAL_PAYLOAD_SMBIOS_TABLE_H_=0D
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index 5cee4e159a..377e868e7c 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -410,6 +410,12 @@
## Include/UniversalPayload/PciRootBridges.h=0D
gUniversalPayloadPciRootBridgeInfoGuid =3D { 0xec4ebacb, 0x2638, 0x416e,=
{ 0xbe, 0x80, 0xe5, 0xfa, 0x4b, 0x51, 0x19, 0x01 }}=0D
=0D
+ ## Include/UniversalPayload/SmbiosTable.h=0D
+ gUniversalPayloadSmbios3TableGuid =3D { 0x92b7896c, 0x3362, 0x46ce, { 0x=
99, 0xb3, 0x4f, 0x5e, 0x3c, 0x34, 0xeb, 0x42 } }=0D
+=0D
+ ## Include/UniversalPayload/SmbiosTable.h=0D
+ gUniversalPayloadSmbiosTableGuid =3D { 0x590a0d26, 0x06e5, 0x4d20, { 0x8=
a, 0x82, 0x59, 0xea, 0x1b, 0x34, 0x98, 0x2d } }=0D
+=0D
[Ppis]=0D
## Include/Ppi/AtaController.h=0D
gPeiAtaControllerPpiGuid =3D { 0xa45e60d1, 0xc719, 0x44aa, { 0xb0,=
0x7a, 0xaa, 0x77, 0x7f, 0x85, 0x90, 0x6d }}=0D
--=20
2.30.0.windows.2

6341 - 6360 of 82581