[PATCH v4 0/8] Add Variable Flash Info HOB


Michael Kubacki
 

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

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

The UEFI variable drivers such as VariableRuntimeDxe, VariableSmm,
VariableStandaloneMm, etc. (and their dependent protocol/library
stack), typically acquire UEFI variable store flash information
with PCDs declared in MdeModulePkg.

For example:
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize

These PCDs work as-is in the StandaloneMm driver if they are not
dynamic such as Dynamic or DynamicEx because PCD services are not
readily available in the Standalone MM environment. Platforms that
use Standalone MM today, must define these PCDs as FixedAtBuild in
their platform build. However, the PCDs do allow platforms to treat
the PCDs as Dynamic/DynamicEx and being able to support that is
currently a gap for Standalone MM.

This patch series introduces a HOB that can be produced by the
platform to provide the same information. The HOB list is
available to Standalone MM.

The PCD declarations are left as-is in MdeModulePkg for backward
compatibility. This means unless a platform wants to use the HOB,
their code will continue to work with no change (they do not need
to produce the HOB). Only if the HOB is found, is its value used
instead of the PCDs.

Due to the large number of consumers of this information, access
to the base address and size values is abstracted in a new library
class (as requested in the v1 series) called VariableFlashInfoLib.

The API of VariableFlashInfoLib does not bind the underlying data
structure to the information returned to library users to allow
flexibility in the library implementation in the future.

V4 changes:
1. Add a UINT32 "Reserved" field to VARIABLE_FLASH_INFO.
2. Add a descriptive comment to VariableFlashInfo.h to explain
HOB usage.

V3 changes:
1. To better clarify usage, renamed the members
"NvStorageBaseAddress" and "NvStorageLength" in
"VARIABLE_FLASH_INFO" to "NvVariableBaseAddress" and
"NvVariableLength".
2. Added description comments to the fields in "VARIABLE_FLASH_INFO".

V2 changes:
1. Abstracted flash info data access with VariableFlashInfoLib.
2. Updated package builds in the repo that build the variable and
FTW drivers to include VariableFlashInfoLib.
3. Removed a redundant variable assignment in VariableSmm.c.
4. Updated comments in FtwMisc.c and FaultTolerantWritePei.c to
indicate driver assumption is UINTN (not UINT32)
5. Added a version field to the VARIABLE_FLASH_INFO structure.

Cc: Abner Chang <abner.chang@...>
Cc: Andrew Fish <afish@...>
Cc: Anthony Perard <anthony.perard@...>
Cc: Ard Biesheuvel <ardb+tianocore@...>
Cc: Benjamin You <benjamin.you@...>
Cc: Brijesh Singh <brijesh.singh@...>
Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: Guo Dong <guo.dong@...>
Cc: Hao A Wu <hao.a.wu@...>
Cc: James Bottomley <jejb@...>
Cc: Jian J Wang <jian.j.wang@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Jordan Justen <jordan.l.justen@...>
Cc: Julien Grall <julien@...>
Cc: Leif Lindholm <quic_llindhol@...>
Cc: Liming Gao <gaoliming@...>
Cc: Maurice Ma <maurice.ma@...>
Cc: Min Xu <min.m.xu@...>
Cc: Nickle Wang <nickle.wang@...>
Cc: Peter Grehan <grehan@...>
Cc: Ray Ni <ray.ni@...>
Cc: Rebecca Cran <rebecca@...>
Cc: Sami Mujawar <sami.mujawar@...>
Cc: Sean Rhodes <sean@...>
Cc: Sebastien Boeuf <sebastien.boeuf@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Signed-off-by: Michael Kubacki <michael.kubacki@...>

Michael Kubacki (8):
MdeModulePkg: Add Variable Flash Info HOB
MdeModulePkg/VariableFlashInfoLib: Add initial library
MdeModulePkg/Variable: Consume Variable Flash Info
MdeModulePkg/FaultTolerantWrite: Consume Variable Flash Info
ArmVirtPkg/ArmVirt.dsc.inc: Add VariableFlashInfoLib
EmulatorPkg: Add VariableFlashInfoLib
OvmfPkg: Add VariableFlashInfoLib
UefiPayloadPkg: Add VariableFlashInfoLib

MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.c=
| 178 ++++++++++++++++++++
MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c =
| 41 +++--
MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c =
| 7 +-
MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.c =
| 28 +--
MdeModulePkg/Universal/Variable/Pei/Variable.c =
| 14 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c =
| 16 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c =
| 14 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c =
| 17 +-
ArmVirtPkg/ArmVirt.dsc.inc =
| 1 +
EmulatorPkg/EmulatorPkg.dsc =
| 1 +
MdeModulePkg/Include/Guid/VariableFlashInfo.h =
| 111 ++++++++++++
MdeModulePkg/Include/Library/VariableFlashInfoLib.h =
| 68 ++++++++
MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.i=
nf | 48 ++++++
MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.u=
ni | 12 ++
MdeModulePkg/MdeModulePkg.dec =
| 8 +
MdeModulePkg/MdeModulePkg.dsc =
| 2 +
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h =
| 7 +-
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf =
| 10 +-
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf =
| 10 +-
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandalon=
eMm.inf | 10 +-
MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.inf =
| 10 +-
MdeModulePkg/Universal/Variable/Pei/Variable.h =
| 2 +
MdeModulePkg/Universal/Variable/Pei/VariablePei.inf =
| 5 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h =
| 7 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf =
| 5 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf =
| 5 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf =
| 5 +-
OvmfPkg/AmdSev/AmdSevX64.dsc =
| 1 +
OvmfPkg/Bhyve/BhyveX64.dsc =
| 1 +
OvmfPkg/CloudHv/CloudHvX64.dsc =
| 1 +
OvmfPkg/IntelTdx/IntelTdxX64.dsc =
| 1 +
OvmfPkg/Microvm/MicrovmX64.dsc =
| 1 +
OvmfPkg/OvmfPkgIa32.dsc =
| 1 +
OvmfPkg/OvmfPkgIa32X64.dsc =
| 1 +
OvmfPkg/OvmfPkgX64.dsc =
| 1 +
OvmfPkg/OvmfXen.dsc =
| 1 +
UefiPayloadPkg/UefiPayloadPkg.dsc =
| 1 +
37 files changed, 558 insertions(+), 94 deletions(-)
create mode 100644 MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVar=
iableFlashInfoLib.c
create mode 100644 MdeModulePkg/Include/Guid/VariableFlashInfo.h
create mode 100644 MdeModulePkg/Include/Library/VariableFlashInfoLib.h
create mode 100644 MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVar=
iableFlashInfoLib.inf
create mode 100644 MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVar=
iableFlashInfoLib.uni

--=20
2.28.0.windows.1


Michael Kubacki
 

A friendly reminder to those on the CC line to help review your respective packages in this patch series.

Some of the patches are just minor changes to DSC files and others do not have a significant number of changes.

Thanks,
Michael

On 4/12/2022 12:29 PM, Michael Kubacki wrote:
From: Michael Kubacki <michael.kubacki@...>
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3479
The UEFI variable drivers such as VariableRuntimeDxe, VariableSmm,
VariableStandaloneMm, etc. (and their dependent protocol/library
stack), typically acquire UEFI variable store flash information
with PCDs declared in MdeModulePkg.
For example:
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
These PCDs work as-is in the StandaloneMm driver if they are not
dynamic such as Dynamic or DynamicEx because PCD services are not
readily available in the Standalone MM environment. Platforms that
use Standalone MM today, must define these PCDs as FixedAtBuild in
their platform build. However, the PCDs do allow platforms to treat
the PCDs as Dynamic/DynamicEx and being able to support that is
currently a gap for Standalone MM.
This patch series introduces a HOB that can be produced by the
platform to provide the same information. The HOB list is
available to Standalone MM.
The PCD declarations are left as-is in MdeModulePkg for backward
compatibility. This means unless a platform wants to use the HOB,
their code will continue to work with no change (they do not need
to produce the HOB). Only if the HOB is found, is its value used
instead of the PCDs.
Due to the large number of consumers of this information, access
to the base address and size values is abstracted in a new library
class (as requested in the v1 series) called VariableFlashInfoLib.
The API of VariableFlashInfoLib does not bind the underlying data
structure to the information returned to library users to allow
flexibility in the library implementation in the future.
V4 changes:
1. Add a UINT32 "Reserved" field to VARIABLE_FLASH_INFO.
2. Add a descriptive comment to VariableFlashInfo.h to explain
HOB usage.
V3 changes:
1. To better clarify usage, renamed the members
"NvStorageBaseAddress" and "NvStorageLength" in
"VARIABLE_FLASH_INFO" to "NvVariableBaseAddress" and
"NvVariableLength".
2. Added description comments to the fields in "VARIABLE_FLASH_INFO".
V2 changes:
1. Abstracted flash info data access with VariableFlashInfoLib.
2. Updated package builds in the repo that build the variable and
FTW drivers to include VariableFlashInfoLib.
3. Removed a redundant variable assignment in VariableSmm.c.
4. Updated comments in FtwMisc.c and FaultTolerantWritePei.c to
indicate driver assumption is UINTN (not UINT32)
5. Added a version field to the VARIABLE_FLASH_INFO structure.
Cc: Abner Chang <abner.chang@...>
Cc: Andrew Fish <afish@...>
Cc: Anthony Perard <anthony.perard@...>
Cc: Ard Biesheuvel <ardb+tianocore@...>
Cc: Benjamin You <benjamin.you@...>
Cc: Brijesh Singh <brijesh.singh@...>
Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: Guo Dong <guo.dong@...>
Cc: Hao A Wu <hao.a.wu@...>
Cc: James Bottomley <jejb@...>
Cc: Jian J Wang <jian.j.wang@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Jordan Justen <jordan.l.justen@...>
Cc: Julien Grall <julien@...>
Cc: Leif Lindholm <quic_llindhol@...>
Cc: Liming Gao <gaoliming@...>
Cc: Maurice Ma <maurice.ma@...>
Cc: Min Xu <min.m.xu@...>
Cc: Nickle Wang <nickle.wang@...>
Cc: Peter Grehan <grehan@...>
Cc: Ray Ni <ray.ni@...>
Cc: Rebecca Cran <rebecca@...>
Cc: Sami Mujawar <sami.mujawar@...>
Cc: Sean Rhodes <sean@...>
Cc: Sebastien Boeuf <sebastien.boeuf@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Signed-off-by: Michael Kubacki <michael.kubacki@...>
Michael Kubacki (8):
MdeModulePkg: Add Variable Flash Info HOB
MdeModulePkg/VariableFlashInfoLib: Add initial library
MdeModulePkg/Variable: Consume Variable Flash Info
MdeModulePkg/FaultTolerantWrite: Consume Variable Flash Info
ArmVirtPkg/ArmVirt.dsc.inc: Add VariableFlashInfoLib
EmulatorPkg: Add VariableFlashInfoLib
OvmfPkg: Add VariableFlashInfoLib
UefiPayloadPkg: Add VariableFlashInfoLib
MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.c | 178 ++++++++++++++++++++
MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c | 41 +++--
MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c | 7 +-
MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.c | 28 +--
MdeModulePkg/Universal/Variable/Pei/Variable.c | 14 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c | 16 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c | 14 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c | 17 +-
ArmVirtPkg/ArmVirt.dsc.inc | 1 +
EmulatorPkg/EmulatorPkg.dsc | 1 +
MdeModulePkg/Include/Guid/VariableFlashInfo.h | 111 ++++++++++++
MdeModulePkg/Include/Library/VariableFlashInfoLib.h | 68 ++++++++
MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf | 48 ++++++
MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.uni | 12 ++
MdeModulePkg/MdeModulePkg.dec | 8 +
MdeModulePkg/MdeModulePkg.dsc | 2 +
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h | 7 +-
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf | 10 +-
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf | 10 +-
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandaloneMm.inf | 10 +-
MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.inf | 10 +-
MdeModulePkg/Universal/Variable/Pei/Variable.h | 2 +
MdeModulePkg/Universal/Variable/Pei/VariablePei.inf | 5 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h | 7 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf | 5 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf | 5 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf | 5 +-
OvmfPkg/AmdSev/AmdSevX64.dsc | 1 +
OvmfPkg/Bhyve/BhyveX64.dsc | 1 +
OvmfPkg/CloudHv/CloudHvX64.dsc | 1 +
OvmfPkg/IntelTdx/IntelTdxX64.dsc | 1 +
OvmfPkg/Microvm/MicrovmX64.dsc | 1 +
OvmfPkg/OvmfPkgIa32.dsc | 1 +
OvmfPkg/OvmfPkgIa32X64.dsc | 1 +
OvmfPkg/OvmfPkgX64.dsc | 1 +
OvmfPkg/OvmfXen.dsc | 1 +
UefiPayloadPkg/UefiPayloadPkg.dsc | 1 +
37 files changed, 558 insertions(+), 94 deletions(-)
create mode 100644 MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.c
create mode 100644 MdeModulePkg/Include/Guid/VariableFlashInfo.h
create mode 100644 MdeModulePkg/Include/Library/VariableFlashInfoLib.h
create mode 100644 MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
create mode 100644 MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.uni


Michael Kubacki
 

This patch series is still missing reviews from some package maintainers. Please review it when possible.

Thanks,
Michael

On 4/13/2022 10:21 PM, Michael Kubacki wrote:
A friendly reminder to those on the CC line to help review your respective packages in this patch series.
Some of the patches are just minor changes to DSC files and others do not have a significant number of changes.
Thanks,
Michael
On 4/12/2022 12:29 PM, Michael Kubacki wrote:
From: Michael Kubacki <michael.kubacki@...>

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

The UEFI variable drivers such as VariableRuntimeDxe, VariableSmm,
VariableStandaloneMm, etc. (and their dependent protocol/library
stack), typically acquire UEFI variable store flash information
with PCDs declared in MdeModulePkg.

For example:
[Pcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize

These PCDs work as-is in the StandaloneMm driver if they are not
dynamic such as Dynamic or DynamicEx because PCD services are not
readily available in the Standalone MM environment. Platforms that
use Standalone MM today, must define these PCDs as FixedAtBuild in
their platform build. However, the PCDs do allow platforms to treat
the PCDs as Dynamic/DynamicEx and being able to support that is
currently a gap for Standalone MM.

This patch series introduces a HOB that can be produced by the
platform to provide the same information. The HOB list is
available to Standalone MM.

The PCD declarations are left as-is in MdeModulePkg for backward
compatibility. This means unless a platform wants to use the HOB,
their code will continue to work with no change (they do not need
to produce the HOB). Only if the HOB is found, is its value used
instead of the PCDs.

Due to the large number of consumers of this information, access
to the base address and size values is abstracted in a new library
class (as requested in the v1 series) called VariableFlashInfoLib.

The API of VariableFlashInfoLib does not bind the underlying data
structure to the information returned to library users to allow
flexibility in the library implementation in the future.

V4 changes:
1. Add a UINT32 "Reserved" field to VARIABLE_FLASH_INFO.
2. Add a descriptive comment to VariableFlashInfo.h to explain
    HOB usage.

V3 changes:
1. To better clarify usage, renamed the members
    "NvStorageBaseAddress" and "NvStorageLength" in
    "VARIABLE_FLASH_INFO" to "NvVariableBaseAddress" and
    "NvVariableLength".
2. Added description comments to the fields in "VARIABLE_FLASH_INFO".

V2 changes:
1. Abstracted flash info data access with VariableFlashInfoLib.
2. Updated package builds in the repo that build the variable and
    FTW drivers to include VariableFlashInfoLib.
3. Removed a redundant variable assignment in VariableSmm.c.
4. Updated comments in FtwMisc.c and FaultTolerantWritePei.c to
    indicate driver assumption is UINTN (not UINT32)
5. Added a version field to the VARIABLE_FLASH_INFO structure.

Cc: Abner Chang <abner.chang@...>
Cc: Andrew Fish <afish@...>
Cc: Anthony Perard <anthony.perard@...>
Cc: Ard Biesheuvel <ardb+tianocore@...>
Cc: Benjamin You <benjamin.you@...>
Cc: Brijesh Singh <brijesh.singh@...>
Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: Guo Dong <guo.dong@...>
Cc: Hao A Wu <hao.a.wu@...>
Cc: James Bottomley <jejb@...>
Cc: Jian J Wang <jian.j.wang@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Jordan Justen <jordan.l.justen@...>
Cc: Julien Grall <julien@...>
Cc: Leif Lindholm <quic_llindhol@...>
Cc: Liming Gao <gaoliming@...>
Cc: Maurice Ma <maurice.ma@...>
Cc: Min Xu <min.m.xu@...>
Cc: Nickle Wang <nickle.wang@...>
Cc: Peter Grehan <grehan@...>
Cc: Ray Ni <ray.ni@...>
Cc: Rebecca Cran <rebecca@...>
Cc: Sami Mujawar <sami.mujawar@...>
Cc: Sean Rhodes <sean@...>
Cc: Sebastien Boeuf <sebastien.boeuf@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Signed-off-by: Michael Kubacki <michael.kubacki@...>

Michael Kubacki (8):
   MdeModulePkg: Add Variable Flash Info HOB
   MdeModulePkg/VariableFlashInfoLib: Add initial library
   MdeModulePkg/Variable: Consume Variable Flash Info
   MdeModulePkg/FaultTolerantWrite: Consume Variable Flash Info
   ArmVirtPkg/ArmVirt.dsc.inc: Add VariableFlashInfoLib
   EmulatorPkg: Add VariableFlashInfoLib
   OvmfPkg: Add VariableFlashInfoLib
   UefiPayloadPkg: Add VariableFlashInfoLib

MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.c | 178 ++++++++++++++++++++
MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c |  41 +++--
MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c |   7 +-
MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.c |  28 +--
MdeModulePkg/Universal/Variable/Pei/Variable.c |  14 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c |  16 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c |  14 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c |  17 +-
ArmVirtPkg/ArmVirt.dsc.inc |   1 +
EmulatorPkg/EmulatorPkg.dsc |   1 +
MdeModulePkg/Include/Guid/VariableFlashInfo.h | 111 ++++++++++++
MdeModulePkg/Include/Library/VariableFlashInfoLib.h |  68 ++++++++
MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf |  48 ++++++
MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.uni |  12 ++
MdeModulePkg/MdeModulePkg.dec |   8 +
MdeModulePkg/MdeModulePkg.dsc |   2 +
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h |   7 +-
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf |  10 +-
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf |  10 +-
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandaloneMm.inf |  10 +-
MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.inf |  10 +-
MdeModulePkg/Universal/Variable/Pei/Variable.h |   2 +
MdeModulePkg/Universal/Variable/Pei/VariablePei.inf |   5 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h |   7 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf |   5 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf |   5 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf |   5 +-
OvmfPkg/AmdSev/AmdSevX64.dsc |   1 +
OvmfPkg/Bhyve/BhyveX64.dsc |   1 +
OvmfPkg/CloudHv/CloudHvX64.dsc |   1 +
OvmfPkg/IntelTdx/IntelTdxX64.dsc |   1 +
OvmfPkg/Microvm/MicrovmX64.dsc |   1 +
OvmfPkg/OvmfPkgIa32.dsc |   1 +
OvmfPkg/OvmfPkgIa32X64.dsc |   1 +
OvmfPkg/OvmfPkgX64.dsc |   1 +
OvmfPkg/OvmfXen.dsc |   1 +
UefiPayloadPkg/UefiPayloadPkg.dsc |   1 +
  37 files changed, 558 insertions(+), 94 deletions(-)
  create mode 100644 MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.c
  create mode 100644 MdeModulePkg/Include/Guid/VariableFlashInfo.h
  create mode 100644 MdeModulePkg/Include/Library/VariableFlashInfoLib.h
  create mode 100644 MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
  create mode 100644 MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.uni


Ard Biesheuvel
 

On Tue, 12 Apr 2022 at 18:30, <mikuback@...> wrote:

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

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

The UEFI variable drivers such as VariableRuntimeDxe, VariableSmm,
VariableStandaloneMm, etc. (and their dependent protocol/library
stack), typically acquire UEFI variable store flash information
with PCDs declared in MdeModulePkg.

For example:
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize

These PCDs work as-is in the StandaloneMm driver if they are not
dynamic such as Dynamic or DynamicEx because PCD services are not
readily available in the Standalone MM environment. Platforms that
use Standalone MM today, must define these PCDs as FixedAtBuild in
their platform build. However, the PCDs do allow platforms to treat
the PCDs as Dynamic/DynamicEx and being able to support that is
currently a gap for Standalone MM.

This patch series introduces a HOB that can be produced by the
platform to provide the same information. The HOB list is
available to Standalone MM.

The PCD declarations are left as-is in MdeModulePkg for backward
compatibility. This means unless a platform wants to use the HOB,
their code will continue to work with no change (they do not need
to produce the HOB). Only if the HOB is found, is its value used
instead of the PCDs.

Due to the large number of consumers of this information, access
to the base address and size values is abstracted in a new library
class (as requested in the v1 series) called VariableFlashInfoLib.

The API of VariableFlashInfoLib does not bind the underlying data
structure to the information returned to library users to allow
flexibility in the library implementation in the future.

V4 changes:
1. Add a UINT32 "Reserved" field to VARIABLE_FLASH_INFO.
2. Add a descriptive comment to VariableFlashInfo.h to explain
HOB usage.

V3 changes:
1. To better clarify usage, renamed the members
"NvStorageBaseAddress" and "NvStorageLength" in
"VARIABLE_FLASH_INFO" to "NvVariableBaseAddress" and
"NvVariableLength".
2. Added description comments to the fields in "VARIABLE_FLASH_INFO".

V2 changes:
1. Abstracted flash info data access with VariableFlashInfoLib.
2. Updated package builds in the repo that build the variable and
FTW drivers to include VariableFlashInfoLib.
3. Removed a redundant variable assignment in VariableSmm.c.
4. Updated comments in FtwMisc.c and FaultTolerantWritePei.c to
indicate driver assumption is UINTN (not UINT32)
5. Added a version field to the VARIABLE_FLASH_INFO structure.

Cc: Abner Chang <abner.chang@...>
Cc: Andrew Fish <afish@...>
Cc: Anthony Perard <anthony.perard@...>
Cc: Ard Biesheuvel <ardb+tianocore@...>
Cc: Benjamin You <benjamin.you@...>
Cc: Brijesh Singh <brijesh.singh@...>
Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: Guo Dong <guo.dong@...>
Cc: Hao A Wu <hao.a.wu@...>
Cc: James Bottomley <jejb@...>
Cc: Jian J Wang <jian.j.wang@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Jordan Justen <jordan.l.justen@...>
Cc: Julien Grall <julien@...>
Cc: Leif Lindholm <quic_llindhol@...>
Cc: Liming Gao <gaoliming@...>
Cc: Maurice Ma <maurice.ma@...>
Cc: Min Xu <min.m.xu@...>
Cc: Nickle Wang <nickle.wang@...>
Cc: Peter Grehan <grehan@...>
Cc: Ray Ni <ray.ni@...>
Cc: Rebecca Cran <rebecca@...>
Cc: Sami Mujawar <sami.mujawar@...>
Cc: Sean Rhodes <sean@...>
Cc: Sebastien Boeuf <sebastien.boeuf@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Signed-off-by: Michael Kubacki <michael.kubacki@...>

Michael Kubacki (8):
MdeModulePkg: Add Variable Flash Info HOB
MdeModulePkg/VariableFlashInfoLib: Add initial library
MdeModulePkg/Variable: Consume Variable Flash Info
MdeModulePkg/FaultTolerantWrite: Consume Variable Flash Info
ArmVirtPkg/ArmVirt.dsc.inc: Add VariableFlashInfoLib
EmulatorPkg: Add VariableFlashInfoLib
OvmfPkg: Add VariableFlashInfoLib
UefiPayloadPkg: Add VariableFlashInfoLib
For the series,

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

MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.c | 178 ++++++++++++++++++++
MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c | 41 +++--
MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c | 7 +-
MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.c | 28 +--
MdeModulePkg/Universal/Variable/Pei/Variable.c | 14 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c | 16 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c | 14 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c | 17 +-
ArmVirtPkg/ArmVirt.dsc.inc | 1 +
EmulatorPkg/EmulatorPkg.dsc | 1 +
MdeModulePkg/Include/Guid/VariableFlashInfo.h | 111 ++++++++++++
MdeModulePkg/Include/Library/VariableFlashInfoLib.h | 68 ++++++++
MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf | 48 ++++++
MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.uni | 12 ++
MdeModulePkg/MdeModulePkg.dec | 8 +
MdeModulePkg/MdeModulePkg.dsc | 2 +
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h | 7 +-
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf | 10 +-
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf | 10 +-
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandaloneMm.inf | 10 +-
MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.inf | 10 +-
MdeModulePkg/Universal/Variable/Pei/Variable.h | 2 +
MdeModulePkg/Universal/Variable/Pei/VariablePei.inf | 5 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h | 7 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf | 5 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf | 5 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf | 5 +-
OvmfPkg/AmdSev/AmdSevX64.dsc | 1 +
OvmfPkg/Bhyve/BhyveX64.dsc | 1 +
OvmfPkg/CloudHv/CloudHvX64.dsc | 1 +
OvmfPkg/IntelTdx/IntelTdxX64.dsc | 1 +
OvmfPkg/Microvm/MicrovmX64.dsc | 1 +
OvmfPkg/OvmfPkgIa32.dsc | 1 +
OvmfPkg/OvmfPkgIa32X64.dsc | 1 +
OvmfPkg/OvmfPkgX64.dsc | 1 +
OvmfPkg/OvmfXen.dsc | 1 +
UefiPayloadPkg/UefiPayloadPkg.dsc | 1 +
37 files changed, 558 insertions(+), 94 deletions(-)
create mode 100644 MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.c
create mode 100644 MdeModulePkg/Include/Guid/VariableFlashInfo.h
create mode 100644 MdeModulePkg/Include/Library/VariableFlashInfoLib.h
create mode 100644 MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
create mode 100644 MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.uni

--
2.28.0.windows.1


Michael Kubacki
 

Hello MdeModulePkg maintainers,

This patch series has received reviews for all patches. I have placed a rebased branch with up-to-date review tags in the following PR:

https://github.com/tianocore/edk2/pull/2812

Please let me know if anything further is needed for you to merge the PR.

Thanks,
Michael

On 4/12/2022 12:29 PM, Michael Kubacki wrote:
From: Michael Kubacki <michael.kubacki@...>
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3479
The UEFI variable drivers such as VariableRuntimeDxe, VariableSmm,
VariableStandaloneMm, etc. (and their dependent protocol/library
stack), typically acquire UEFI variable store flash information
with PCDs declared in MdeModulePkg.
For example:
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
These PCDs work as-is in the StandaloneMm driver if they are not
dynamic such as Dynamic or DynamicEx because PCD services are not
readily available in the Standalone MM environment. Platforms that
use Standalone MM today, must define these PCDs as FixedAtBuild in
their platform build. However, the PCDs do allow platforms to treat
the PCDs as Dynamic/DynamicEx and being able to support that is
currently a gap for Standalone MM.
This patch series introduces a HOB that can be produced by the
platform to provide the same information. The HOB list is
available to Standalone MM.
The PCD declarations are left as-is in MdeModulePkg for backward
compatibility. This means unless a platform wants to use the HOB,
their code will continue to work with no change (they do not need
to produce the HOB). Only if the HOB is found, is its value used
instead of the PCDs.
Due to the large number of consumers of this information, access
to the base address and size values is abstracted in a new library
class (as requested in the v1 series) called VariableFlashInfoLib.
The API of VariableFlashInfoLib does not bind the underlying data
structure to the information returned to library users to allow
flexibility in the library implementation in the future.
V4 changes:
1. Add a UINT32 "Reserved" field to VARIABLE_FLASH_INFO.
2. Add a descriptive comment to VariableFlashInfo.h to explain
HOB usage.
V3 changes:
1. To better clarify usage, renamed the members
"NvStorageBaseAddress" and "NvStorageLength" in
"VARIABLE_FLASH_INFO" to "NvVariableBaseAddress" and
"NvVariableLength".
2. Added description comments to the fields in "VARIABLE_FLASH_INFO".
V2 changes:
1. Abstracted flash info data access with VariableFlashInfoLib.
2. Updated package builds in the repo that build the variable and
FTW drivers to include VariableFlashInfoLib.
3. Removed a redundant variable assignment in VariableSmm.c.
4. Updated comments in FtwMisc.c and FaultTolerantWritePei.c to
indicate driver assumption is UINTN (not UINT32)
5. Added a version field to the VARIABLE_FLASH_INFO structure.
Cc: Abner Chang <abner.chang@...>
Cc: Andrew Fish <afish@...>
Cc: Anthony Perard <anthony.perard@...>
Cc: Ard Biesheuvel <ardb+tianocore@...>
Cc: Benjamin You <benjamin.you@...>
Cc: Brijesh Singh <brijesh.singh@...>
Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: Guo Dong <guo.dong@...>
Cc: Hao A Wu <hao.a.wu@...>
Cc: James Bottomley <jejb@...>
Cc: Jian J Wang <jian.j.wang@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Jordan Justen <jordan.l.justen@...>
Cc: Julien Grall <julien@...>
Cc: Leif Lindholm <quic_llindhol@...>
Cc: Liming Gao <gaoliming@...>
Cc: Maurice Ma <maurice.ma@...>
Cc: Min Xu <min.m.xu@...>
Cc: Nickle Wang <nickle.wang@...>
Cc: Peter Grehan <grehan@...>
Cc: Ray Ni <ray.ni@...>
Cc: Rebecca Cran <rebecca@...>
Cc: Sami Mujawar <sami.mujawar@...>
Cc: Sean Rhodes <sean@...>
Cc: Sebastien Boeuf <sebastien.boeuf@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Signed-off-by: Michael Kubacki <michael.kubacki@...>
Michael Kubacki (8):
MdeModulePkg: Add Variable Flash Info HOB
MdeModulePkg/VariableFlashInfoLib: Add initial library
MdeModulePkg/Variable: Consume Variable Flash Info
MdeModulePkg/FaultTolerantWrite: Consume Variable Flash Info
ArmVirtPkg/ArmVirt.dsc.inc: Add VariableFlashInfoLib
EmulatorPkg: Add VariableFlashInfoLib
OvmfPkg: Add VariableFlashInfoLib
UefiPayloadPkg: Add VariableFlashInfoLib
MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.c | 178 ++++++++++++++++++++
MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c | 41 +++--
MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c | 7 +-
MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.c | 28 +--
MdeModulePkg/Universal/Variable/Pei/Variable.c | 14 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c | 16 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c | 14 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c | 17 +-
ArmVirtPkg/ArmVirt.dsc.inc | 1 +
EmulatorPkg/EmulatorPkg.dsc | 1 +
MdeModulePkg/Include/Guid/VariableFlashInfo.h | 111 ++++++++++++
MdeModulePkg/Include/Library/VariableFlashInfoLib.h | 68 ++++++++
MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf | 48 ++++++
MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.uni | 12 ++
MdeModulePkg/MdeModulePkg.dec | 8 +
MdeModulePkg/MdeModulePkg.dsc | 2 +
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h | 7 +-
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf | 10 +-
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf | 10 +-
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandaloneMm.inf | 10 +-
MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.inf | 10 +-
MdeModulePkg/Universal/Variable/Pei/Variable.h | 2 +
MdeModulePkg/Universal/Variable/Pei/VariablePei.inf | 5 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h | 7 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf | 5 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf | 5 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf | 5 +-
OvmfPkg/AmdSev/AmdSevX64.dsc | 1 +
OvmfPkg/Bhyve/BhyveX64.dsc | 1 +
OvmfPkg/CloudHv/CloudHvX64.dsc | 1 +
OvmfPkg/IntelTdx/IntelTdxX64.dsc | 1 +
OvmfPkg/Microvm/MicrovmX64.dsc | 1 +
OvmfPkg/OvmfPkgIa32.dsc | 1 +
OvmfPkg/OvmfPkgIa32X64.dsc | 1 +
OvmfPkg/OvmfPkgX64.dsc | 1 +
OvmfPkg/OvmfXen.dsc | 1 +
UefiPayloadPkg/UefiPayloadPkg.dsc | 1 +
37 files changed, 558 insertions(+), 94 deletions(-)
create mode 100644 MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.c
create mode 100644 MdeModulePkg/Include/Guid/VariableFlashInfo.h
create mode 100644 MdeModulePkg/Include/Library/VariableFlashInfoLib.h
create mode 100644 MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
create mode 100644 MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.uni