[PATCH v4 1/8] MdeModulePkg: Add Variable Flash Info HOB


Michael Kubacki
 

From: Michael Kubacki <michael.kubacki@...>

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

Adds a new GUID that is used to identify a HOB that passes variable
flash information to UEFI variable drivers in HOB consumption phases
such as DXE, Traditional MM, and Standalone MM.

This information was previously passed directly with PCDs such
as EfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase
and gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize.

However, the Standalone MM variable driver instance does not have
direct access to the PCD database. Therefore, this HOB will first
be considered as the source for variable flash information and
if platforms do not produce the HOB, reading the information from
the PCDs directly will be a backup to provide backward
compatibility.

Cc: Jian J Wang <jian.j.wang@...>
Cc: Hao A Wu <hao.a.wu@...>
Cc: Liming Gao <gaoliming@...>
Signed-off-by: Michael Kubacki <michael.kubacki@...>
---
MdeModulePkg/Include/Guid/VariableFlashInfo.h | 111 ++++++++++++++++++++
MdeModulePkg/MdeModulePkg.dec | 4 +
2 files changed, 115 insertions(+)

diff --git a/MdeModulePkg/Include/Guid/VariableFlashInfo.h b/MdeModulePkg=
/Include/Guid/VariableFlashInfo.h
new file mode 100644
index 000000000000..992a0dcdd384
--- /dev/null
+++ b/MdeModulePkg/Include/Guid/VariableFlashInfo.h
@@ -0,0 +1,111 @@
+/** @file
+ This file defines the GUID and data structure used to pass information=
about
+ a variable store mapped on flash (i.e. a MMIO firmware volume) to the =
modules
+ that consume that information such as the DXE and MM UEFI variable dri=
vers.
+
+ The HOB described in this file is currently optional. It is primarily =
provided
+ to allow a platform to dynamically describe the flash information to e=
nvironments
+ such as Standalone MM that cannot access the prior method using dynami=
c PCDs.
+
+ Even for platforms that use Standalone MM, if the information is only =
stored
+ statically such as with FixedAtBuild PCDs, the HOB is not required.
+
+ Every point of consumption in this package that uses the PCDs will fir=
st check
+ for the HOB and use its value if present.
+
+ Early modules such as the PEI UEFI variable driver might also consume =
this
+ information. For modules such as these, that execute early in the boot=
flow,
+ at least two approaches are possible depending on platform design.
+
+ 1. If the information in the HOB exactly matches the information in th=
e PCDs,
+ (i.e. the HOB values are set using the PCD values), let the driver =
read
+ the information from the PCD and produce the HOB later in boot.
+
+ 2. Produce the HOB very early in boot. For example, the earliest point=
the HOB
+ is currently consumed is in FaultTolerantWritePei. Note that FaultT=
olerantWritePei
+ produces gEdkiiFaultTolerantWriteGuid which is a dependency for Var=
iablePei.
+
+ Therefore, attaching a NULL class library to FaultTolerantWritePei =
with a
+ constructor that produces the HOB will guarantee it is produced bef=
ore the first
+ point of consumption as the constructor is executed before the modu=
le entry point.
+
+ Copyright (c) Microsoft Corporation.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef VARIABLE_FLASH_INFO_H_
+#define VARIABLE_FLASH_INFO_H_
+
+#define VARIABLE_FLASH_INFO_HOB_GUID \
+ { 0x5d11c653, 0x8154, 0x4ac3, { 0xa8, 0xc2, 0xfb, 0xa2, 0x89, 0x20, 0x=
fc, 0x90 }}
+
+#define VARIABLE_FLASH_INFO_HOB_VERSION 1
+
+extern EFI_GUID gVariableFlashInfoHobGuid;
+
+#pragma pack (push, 1)
+
+///
+/// This structure can be used to describe UEFI variable
+/// flash information.
+///
+typedef struct {
+ ///
+ /// Version of this structure.
+ ///
+ /// Increment the value when the structure is modified.
+ ///
+ UINT32 Version;
+ ///
+ /// Reserved field.
+ ///
+ /// Currently reserved for natural alignment.
+ ///
+ UINT32 Reserved;
+ ///
+ /// Base address of the non-volatile variable range in the flash devic=
e.
+ ///
+ /// Note that this address should align with the block size requiremen=
ts of the flash device.
+ ///
+ EFI_PHYSICAL_ADDRESS NvVariableBaseAddress;
+ ///
+ /// Size of the non-volatile variable range in the flash device.
+ ///
+ /// Note that this value should be less than or equal to FtwSpareLengt=
h to support reclaim of
+ /// entire variable store area.
+ /// Note that this address should align with the block size requiremen=
ts of the flash device.
+ ///
+ UINT64 NvVariableLength;
+ ///
+ /// Base address of the FTW spare block range in the flash device.
+ ///
+ /// Note that this address should align with the block size requiremen=
ts of the flash device.
+ ///
+ EFI_PHYSICAL_ADDRESS FtwSpareBaseAddress;
+ ///
+ /// Size of the FTW spare block range in the flash device.
+ ///
+ /// Note that this value should be greater than or equal to NvVariable=
Length.
+ /// Note that this address should align with the block size requiremen=
ts of the flash device.
+ ///
+ UINT64 FtwSpareLength;
+ ///
+ /// Base address of the FTW working block range in the flash device.
+ ///
+ /// Note that if FtwWorkingLength is larger than on block size, this v=
alue should be block size aligned.
+ ///
+ EFI_PHYSICAL_ADDRESS FtwWorkingBaseAddress;
+ ///
+ /// Size of the FTW working block range in the flash device.
+ ///
+ /// Note that if the value is less than on block size, the range shoul=
d not span blocks.
+ /// Note that if the value is larger than one block size, this value s=
hould be block size aligned.
+ ///
+ UINT64 FtwWorkingLength;
+} VARIABLE_FLASH_INFO;
+
+#pragma pack (pop)
+
+#endif
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.de=
c
index cf79292ec877..4e82f5836096 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -226,6 +226,10 @@ [Guids]
# Include/Guid/SmmVariableCommon.h
gSmmVariableWriteGuid =3D { 0x93ba1826, 0xdffb, 0x45dd, { 0x82, 0xa7,=
0xe7, 0xdc, 0xaa, 0x3b, 0xbd, 0xf3 }}
=20
+ ## Guid of the variable flash information HOB.
+ # Include/Guid/VariableFlashInfo.h
+ gVariableFlashInfoHobGuid =3D { 0x5d11c653, 0x8154, 0x4ac3, { 0xa8, 0x=
c2, 0xfb, 0xa2, 0x89, 0x20, 0xfc, 0x90 }}
+
## Performance protocol guid that also acts as the performance HOB gui=
d and performance variable GUID
# Include/Guid/Performance.h
gPerformanceProtocolGuid =3D { 0x76B6BDFA, 0x2ACD, 0x4462, { 0x9=
E, 0x3F, 0xCB, 0x58, 0xC9, 0x69, 0xD9, 0x37 } }
--=20
2.28.0.windows.1


Sami Mujawar
 

Hi Michael,

Thank you for this patch.

These changes look good to me.

Reviewed-by: Sami Mujawar <sami.mujawar@...>

Regards,

Sami Mujawar

On 12/04/2022 05:29 pm, Michael Kubacki via groups.io wrote:
From: Michael Kubacki <michael.kubacki@...>

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

Adds a new GUID that is used to identify a HOB that passes variable
flash information to UEFI variable drivers in HOB consumption phases
such as DXE, Traditional MM, and Standalone MM.

This information was previously passed directly with PCDs such
as EfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase
and gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize.

However, the Standalone MM variable driver instance does not have
direct access to the PCD database. Therefore, this HOB will first
be considered as the source for variable flash information and
if platforms do not produce the HOB, reading the information from
the PCDs directly will be a backup to provide backward
compatibility.

Cc: Jian J Wang <jian.j.wang@...>
Cc: Hao A Wu <hao.a.wu@...>
Cc: Liming Gao <gaoliming@...>
Signed-off-by: Michael Kubacki <michael.kubacki@...>
---
MdeModulePkg/Include/Guid/VariableFlashInfo.h | 111 ++++++++++++++++++++
MdeModulePkg/MdeModulePkg.dec | 4 +
2 files changed, 115 insertions(+)

diff --git a/MdeModulePkg/Include/Guid/VariableFlashInfo.h b/MdeModulePkg/Include/Guid/VariableFlashInfo.h
new file mode 100644
index 000000000000..992a0dcdd384
--- /dev/null
+++ b/MdeModulePkg/Include/Guid/VariableFlashInfo.h
@@ -0,0 +1,111 @@
+/** @file
+ This file defines the GUID and data structure used to pass information about
+ a variable store mapped on flash (i.e. a MMIO firmware volume) to the modules
+ that consume that information such as the DXE and MM UEFI variable drivers.
+
+ The HOB described in this file is currently optional. It is primarily provided
+ to allow a platform to dynamically describe the flash information to environments
+ such as Standalone MM that cannot access the prior method using dynamic PCDs.
+
+ Even for platforms that use Standalone MM, if the information is only stored
+ statically such as with FixedAtBuild PCDs, the HOB is not required.
+
+ Every point of consumption in this package that uses the PCDs will first check
+ for the HOB and use its value if present.
+
+ Early modules such as the PEI UEFI variable driver might also consume this
+ information. For modules such as these, that execute early in the boot flow,
+ at least two approaches are possible depending on platform design.
+
+ 1. If the information in the HOB exactly matches the information in the PCDs,
+ (i.e. the HOB values are set using the PCD values), let the driver read
+ the information from the PCD and produce the HOB later in boot.
+
+ 2. Produce the HOB very early in boot. For example, the earliest point the HOB
+ is currently consumed is in FaultTolerantWritePei. Note that FaultTolerantWritePei
+ produces gEdkiiFaultTolerantWriteGuid which is a dependency for VariablePei.
+
+ Therefore, attaching a NULL class library to FaultTolerantWritePei with a
+ constructor that produces the HOB will guarantee it is produced before the first
+ point of consumption as the constructor is executed before the module entry point.
+
+ Copyright (c) Microsoft Corporation.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef VARIABLE_FLASH_INFO_H_
+#define VARIABLE_FLASH_INFO_H_
+
+#define VARIABLE_FLASH_INFO_HOB_GUID \
+ { 0x5d11c653, 0x8154, 0x4ac3, { 0xa8, 0xc2, 0xfb, 0xa2, 0x89, 0x20, 0xfc, 0x90 }}
+
+#define VARIABLE_FLASH_INFO_HOB_VERSION 1
+
+extern EFI_GUID gVariableFlashInfoHobGuid;
+
+#pragma pack (push, 1)
+
+///
+/// This structure can be used to describe UEFI variable
+/// flash information.
+///
+typedef struct {
+ ///
+ /// Version of this structure.
+ ///
+ /// Increment the value when the structure is modified.
+ ///
+ UINT32 Version;
+ ///
+ /// Reserved field.
+ ///
+ /// Currently reserved for natural alignment.
+ ///
+ UINT32 Reserved;
+ ///
+ /// Base address of the non-volatile variable range in the flash device.
+ ///
+ /// Note that this address should align with the block size requirements of the flash device.
+ ///
+ EFI_PHYSICAL_ADDRESS NvVariableBaseAddress;
+ ///
+ /// Size of the non-volatile variable range in the flash device.
+ ///
+ /// Note that this value should be less than or equal to FtwSpareLength to support reclaim of
+ /// entire variable store area.
+ /// Note that this address should align with the block size requirements of the flash device.
+ ///
+ UINT64 NvVariableLength;
+ ///
+ /// Base address of the FTW spare block range in the flash device.
+ ///
+ /// Note that this address should align with the block size requirements of the flash device.
+ ///
+ EFI_PHYSICAL_ADDRESS FtwSpareBaseAddress;
+ ///
+ /// Size of the FTW spare block range in the flash device.
+ ///
+ /// Note that this value should be greater than or equal to NvVariableLength.
+ /// Note that this address should align with the block size requirements of the flash device.
+ ///
+ UINT64 FtwSpareLength;
+ ///
+ /// Base address of the FTW working block range in the flash device.
+ ///
+ /// Note that if FtwWorkingLength is larger than on block size, this value should be block size aligned.
+ ///
+ EFI_PHYSICAL_ADDRESS FtwWorkingBaseAddress;
+ ///
+ /// Size of the FTW working block range in the flash device.
+ ///
+ /// Note that if the value is less than on block size, the range should not span blocks.
+ /// Note that if the value is larger than one block size, this value should be block size aligned.
+ ///
+ UINT64 FtwWorkingLength;
+} VARIABLE_FLASH_INFO;
+
+#pragma pack (pop)
+
+#endif
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index cf79292ec877..4e82f5836096 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -226,6 +226,10 @@ [Guids]
# Include/Guid/SmmVariableCommon.h
gSmmVariableWriteGuid = { 0x93ba1826, 0xdffb, 0x45dd, { 0x82, 0xa7, 0xe7, 0xdc, 0xaa, 0x3b, 0xbd, 0xf3 }}
+ ## Guid of the variable flash information HOB.
+ # Include/Guid/VariableFlashInfo.h
+ gVariableFlashInfoHobGuid = { 0x5d11c653, 0x8154, 0x4ac3, { 0xa8, 0xc2, 0xfb, 0xa2, 0x89, 0x20, 0xfc, 0x90 }}
+
## Performance protocol guid that also acts as the performance HOB guid and performance variable GUID
# Include/Guid/Performance.h
gPerformanceProtocolGuid = { 0x76B6BDFA, 0x2ACD, 0x4462, { 0x9E, 0x3F, 0xCB, 0x58, 0xC9, 0x69, 0xD9, 0x37 } }