Date   

[PATCH v5 3/5] Ovmf/HardwareInfoLib: Add Dxe lib to dynamically parse heterogenous data

Ojeda Leon, Nicolas
 

Following the Hardware Info library, create the DxeHardwareInfoLib
which implements the whole API capable of parsing heterogeneous hardware
information. The list-like API grants callers a flexible and common
pattern to retrieve the data. Moreover, the initial source is a BLOB
which generalizes the host-to-guest transmission mechanism.

The Hardware Info library main objective is to provide a way to
describe non-discoverable hardware so that the host can share the
available resources with the guest in Ovmf platforms. This change
features and embraces the main idea behind the library by providing
an API that parses a BLOB into a linked list to retrieve hardware
data from any source. Additionally, list-like APIs are provided so
that the hardware info list can be traversed conveniently.
Similarly, the capability is provided to filter results by specific
hardware types. However, heterogeneous elements can be added to the
list, increasing the flexibility. This way, a single source, for
example a fw-cfg file, can be used to describe several instances of
multiple types of hardware.

This part of the Hardware Info library makes use of dynamic memory
and is intended for stages in which memory services are available.
A motivation example is the PciHostBridgeLib. This library, part
of the PCI driver populates the list of PCI root bridges during DXE
stage for future steps to discover the resources under them. The
hardware info library can be used to obtain the detailed description
of available host bridges, for instance in the form of a fw-cfg file,
and parse that information into a dynmaic list that allows, first to
verify consistency of the data, and second discover the resources
availabe for each root bridge.

Cc: Alexander Graf <graf@...>
Cc: Gerd Hoffmann <kraxel@...>
Acked-by: Gerd Hoffmann <kraxel@...>
Signed-off-by: Nicolas Ojeda Leon <ncoleon@...>
---
.../HardwareInfoLib/DxeHardwareInfoLib.inf | 43 +++
.../Library/HardwareInfoLib/HardwareInfoDxe.c | 255 ++++++++++++++++++
OvmfPkg/OvmfPkgX64.dsc | 1 +
3 files changed, 299 insertions(+)
create mode 100644 OvmfPkg/Library/HardwareInfoLib/DxeHardwareInfoLib.inf
create mode 100644 OvmfPkg/Library/HardwareInfoLib/HardwareInfoDxe.c

diff --git a/OvmfPkg/Library/HardwareInfoLib/DxeHardwareInfoLib.inf b/OvmfPkg/Library/HardwareInfoLib/DxeHardwareInfoLib.inf
new file mode 100644
index 0000000000..0a93d24b8a
--- /dev/null
+++ b/OvmfPkg/Library/HardwareInfoLib/DxeHardwareInfoLib.inf
@@ -0,0 +1,43 @@
+## @file
+# Hardware information library to describe non-discoverable hardware resources
+#
+# Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = DxeHardwareInfoLib
+ FILE_GUID = F60B206A-5C56-11EC-AEAC-67CB080BCFF2
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = DxeHardwareInfoLib
+
+#
+# The following information is for reference only and not required by the build
+# tools.
+#
+# VALID_ARCHITECTURES = X64
+#
+
+[Sources]
+ HardwareInfoDxe.c
+ HardwareInfoPciHostBridgeLib.c
+ QemuFwCfgHardwareInfoLib.c
+
+[Packages]
+ MdeModulePkg/MdeModulePkg.dec
+ MdePkg/MdePkg.dec
+ OvmfPkg/OvmfPkg.dec
+
+[LibraryClasses]
+ BaseMemoryLib
+ DebugLib
+ MemoryAllocationLib
diff --git a/OvmfPkg/Library/HardwareInfoLib/HardwareInfoDxe.c b/OvmfPkg/Library/HardwareInfoLib/HardwareInfoDxe.c
new file mode 100644
index 0000000000..4f0b51c942
--- /dev/null
+++ b/OvmfPkg/Library/HardwareInfoLib/HardwareInfoDxe.c
@@ -0,0 +1,255 @@
+/*/@file
+ Hardware info parsing functions.
+ Binary data is expected as a consecutive series of header - object pairs.
+ Complete library providing list-like interface to dynamically manipulate
+ hardware info objects and parsing from a generic blob.
+
+ Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+
+#include <string.h>
+#include <Uefi/UefiBaseType.h>
+#include <Uefi/UefiSpec.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/BaseLib.h>
+#include <Library/UefiLib.h>
+
+#include <Library/HardwareInfoLib.h>
+
+EFI_STATUS
+CreateHardwareInfoList (
+ IN UINT8 *Blob,
+ IN UINTN BlobSize,
+ IN HARDWARE_INFO_TYPE TypeFilter,
+ OUT LIST_ENTRY *ListHead
+ )
+{
+ UINT8 *Index;
+ HARDWARE_INFO *HwComponent;
+
+ if ((Blob == NULL) || (BlobSize <= 0) ||
+ (ListHead == NULL))
+ {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Index = Blob;
+ while (Index < (Blob + BlobSize)) {
+ HwComponent = AllocateZeroPool (sizeof (HARDWARE_INFO));
+
+ if (HwComponent == NULL) {
+ goto FailedAllocate;
+ }
+
+ HwComponent->Header.Type.Uint64 = *((UINT64 *)Index);
+ Index += sizeof (HwComponent->Header.Type);
+ HwComponent->Header.Size = *((UINT64 *)(Index));
+ Index += sizeof (HwComponent->Header.Size);
+
+ //
+ // Check if optional TypeFilter is set, skip if the current
+ // object is of a different type and release the partially
+ // allocated object
+ //
+ if ((TypeFilter != HardwareInfoTypeUndefined) &&
+ (HwComponent->Header.Type.Value != TypeFilter))
+ {
+ FreePool (HwComponent);
+ Index += HwComponent->Header.Size;
+ continue;
+ }
+
+ HwComponent->Data.Raw = AllocateZeroPool (HwComponent->Header.Size);
+ if (HwComponent->Data.Raw == NULL) {
+ goto FreeResources;
+ }
+
+ CopyMem (HwComponent->Data.Raw, Index, HwComponent->Header.Size);
+ Index += HwComponent->Header.Size;
+
+ InsertTailList (ListHead, &HwComponent->Link);
+ }
+
+ return EFI_SUCCESS;
+
+FreeResources:
+ //
+ // Clean the resources allocated in the incomplete cycle
+ //
+ FreePool (HwComponent);
+
+FailedAllocate:
+ DEBUG ((
+ EFI_D_ERROR,
+ "%a: Failed to allocate memory for hardware info\n",
+ __FUNCTION__
+ ));
+
+ return EFI_OUT_OF_RESOURCES;
+}
+
+VOID
+FreeHardwareInfoList (
+ IN OUT LIST_ENTRY *ListHead
+ )
+{
+ LIST_ENTRY *CurrentLink;
+ HARDWARE_INFO *HwComponent;
+
+ if (IsListEmpty (ListHead)) {
+ return;
+ }
+
+ CurrentLink = ListHead->ForwardLink;
+ while (CurrentLink != NULL && CurrentLink != ListHead) {
+ HwComponent = HARDWARE_INFO_FROM_LINK (CurrentLink);
+
+ //
+ // Remove item from list before invalidating the pointers
+ //
+ CurrentLink = RemoveEntryList (CurrentLink);
+
+ FreePool (HwComponent->Data.Raw);
+ FreePool (HwComponent);
+ }
+}
+
+/**
+ Validates if the specified Node has a valid data size and is of
+ specified type.
+ The data size can be less or equal to the provided type size to be
+ regarded as valid and thus accessible with the typed pointer.
+
+ For future compatibility the size is allowed to be smaller so that
+ different versions interpret fields differently and, particularly,
+ have smaller data structures. However, it cannot be larger than the
+ type size to avoid accessing memory out of bounds.
+
+ @param[in] Node Hardware Info node to be validated
+ @param[in] TypeSize Size (in bytes) of the data type intended to be
+ used to dereference the data.
+ @retval TRUE Node is valid and can be accessed
+ @retval FALSE Node is not valid
+/*/
+STATIC
+BOOLEAN
+IsHardwareInfoNodeValidByType (
+ IN LIST_ENTRY *ListHead,
+ IN LIST_ENTRY *Link,
+ IN HARDWARE_INFO_TYPE Type,
+ IN UINTN TypeSize
+ )
+{
+ HARDWARE_INFO *HwComponent;
+
+ if (IsNull (ListHead, Link)) {
+ return FALSE;
+ }
+
+ HwComponent = HARDWARE_INFO_FROM_LINK (Link);
+
+ //
+ // Verify if the node type is the specified one and the size of
+ // the data allocated to the node is greater than the size of
+ // the type intended to dereference it in order to avoid access
+ // to memory out of bondaries.
+ //
+ if ((HwComponent->Header.Type.Value == Type) &&
+ (HwComponent->Header.Size >= TypeSize))
+ {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+UINTN
+GetHardwareInfoCountByType (
+ IN LIST_ENTRY *ListHead,
+ IN HARDWARE_INFO_TYPE Type,
+ IN UINTN TypeSize
+ )
+{
+ UINTN Count;
+ LIST_ENTRY *Link;
+
+ Count = 0;
+ for (Link = GetFirstHardwareInfoByType (ListHead, Type, TypeSize);
+ !IsNull (ListHead, Link);
+ Link = GetNextHardwareInfoByType (ListHead, Link, Type, TypeSize))
+ {
+ if (IsHardwareInfoNodeValidByType (ListHead, Link, Type, TypeSize)) {
+ Count++;
+ }
+ }
+
+ return Count;
+}
+
+LIST_ENTRY *
+GetFirstHardwareInfoByType (
+ IN LIST_ENTRY *ListHead,
+ IN HARDWARE_INFO_TYPE Type,
+ IN UINTN TypeSize
+ )
+{
+ LIST_ENTRY *Link;
+
+ if (IsListEmpty (ListHead)) {
+ return ListHead;
+ }
+
+ Link = GetFirstNode (ListHead);
+
+ if (IsHardwareInfoNodeValidByType (ListHead, Link, Type, TypeSize)) {
+ return Link;
+ }
+
+ return GetNextHardwareInfoByType (ListHead, Link, Type, TypeSize);
+}
+
+LIST_ENTRY *
+GetNextHardwareInfoByType (
+ IN LIST_ENTRY *ListHead,
+ IN LIST_ENTRY *Node,
+ IN HARDWARE_INFO_TYPE Type,
+ IN UINTN TypeSize
+ )
+{
+ LIST_ENTRY *Link;
+
+ Link = GetNextNode (ListHead, Node);
+
+ while (!IsNull (ListHead, Link)) {
+ if (IsHardwareInfoNodeValidByType (ListHead, Link, Type, TypeSize)) {
+ //
+ // Found a node of specified type and with valid size. Break and
+ // return the found node.
+ //
+ break;
+ }
+
+ Link = GetNextNode (ListHead, Link);
+ }
+
+ return Link;
+}
+
+BOOLEAN
+EndOfHardwareInfoList (
+ IN LIST_ENTRY *ListHead,
+ IN LIST_ENTRY *Node
+ )
+{
+ return IsNull (ListHead, Node);
+}
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index 1904b1bc63..8d1203b6f5 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -190,6 +190,7 @@
MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf
MemEncryptTdxLib|OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf
PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf
+ DxeHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/DxeHardwareInfoLib.inf

!if $(SMM_REQUIRE) == FALSE
LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf
--
2.32.0




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


[PATCH v5 0/5] Handling of multiple PCI host bridges

Ojeda Leon, Nicolas
 

Increased control is provided in Ovmf platforms to define and configure
the specifications of multiple PCI host bridges in the hypervisor. The
host propagates this information to the guest, initially through fw-cfg
interface.

In some AWS EC2 platforms, we expose a PCI topology including several
root bridges portraying information about physical distribution that
enables the guest to optimize accesses. Current PCI driver for Ovmf
enables the explicit definition of multiple root bridges and contains
the logic to fix their resources based on platform-specific PCD
entries. However, we need a way to control, from the hypervisor, how
many and which resources each PCI root bridge can use. For this
reason, this patch series introduces a mechanism to provide PCI host
bridges information like bus number range, attributes, allocation
attributes, PIO aperture as well as 32 and 64- bit prefetchable and
non-prefetchable MMIO ranges through a fw-cfg item created by the
hypervisor and consumed by the guest firmware. In order to offer a
generic and extensible way to disclose non-discoverable hardware
information from the host to the guest, a new library called
HardwareInfoLib is created in the OvmfPkg. In essence, this library
offers the functionality to parse a generic BLOB into a list as well
as the methods to iterate over such list, including filtering options.
The library is conceived in a generic way so that further hardware
elements can also be described using it. For such purpose the length
of the BLOB is not restricted but instead regarded as a sequence of
header-info elements that allow the parsing during runtime.
Furthermore, specific functionality is provided wrapping
QemuFwCfgReadBytes to extract hardware descriptions, in the
aforementioned format, in a static way so that early in the Pei
stage the library can be used to identify address space requirements.
The core of the library offers enough flexibility to process as many
elements, even from different hardware types (heterogenous), as needed
in a single run. This library is extended for the particular use case
already exposed, PCI host bridges, and this same code offers an
example of how to tailor it for further hardware components.


---
Notes:
v5:
- Removed last 3 patches dealing with pre-populated resources to
encapsulate related changes in more manageable chunks and while
pre-populated changes are finalized.
- Added Acked-by to all commits
- Re-based on top of latest master and refactored changes in
MemDetect.c to adapt to recently created
PlatformInitLib/MemDetect.c

v4:
- Minor modification to use MAX_UINT64 as global invalid base address
when reading PCI host bridge information provided by the host
(Patch 1)
- Refactor PciHostBridgeUtilityGetRootBridges into a thin wrapper that
calls 2 new function: one (BusScan) that performs the legacy bus
scan population process and a new one (HostProvided) that populates
Root Bridges with host provided values. (Patch 5)
- Move code that sets value of PcdPciPreservePopulatedMappings token
based on host-provided fw-cfg file into the function that populates
root bridges with host provided data (Patch 6)
- Restructured base address retrieval to leave PCI Resource Allocation
protocol untouched and instead augment the existing services to
enable base address retrieval before allocation. (Patch 7)
- Use new method to retrieve Root Bridge base addresses before
allocation and use that to handle pre-populated BARs (Patch 8)


Nicolas Ojeda Leon (5):
OvmfPkg/Library: Create base HardwareInfoLib for PCI Host Bridges
Ovmf/HardwareInfoLib: Create Pei lib to parse directly from fw-cfg
Ovmf/HardwareInfoLib: Add Dxe lib to dynamically parse heterogenous
data
Ovmf/PlatformPei: Use host-provided GPA end if available
OvmfPkg/PciHostBridgeUtilityLib: Initialize RootBridges apertures with
spec

OvmfPkg/Include/Library/HardwareInfoLib.h | 165 ++++++
.../HardwareInfoLib/DxeHardwareInfoLib.inf | 43 ++
.../Library/HardwareInfoLib/HardwareInfoDxe.c | 255 +++++++++
.../HardwareInfoPciHostBridgeLib.c | 514 ++++++++++++++++++
.../HardwareInfoPciHostBridgeLib.h | 262 +++++++++
.../Library/HardwareInfoLib/HardwareInfoPei.c | 85 +++
.../HardwareInfoLib/HardwareInfoTypesLib.h | 64 +++
.../HardwareInfoLib/PeiHardwareInfoLib.inf | 43 ++
.../QemuFwCfgHardwareInfoLib.c | 89 +++
.../PciHostBridgeUtilityLib.c | 316 ++++++++++-
.../PciHostBridgeUtilityLib.inf | 1 +
OvmfPkg/Library/PlatformInitLib/MemDetect.c | 148 ++++-
OvmfPkg/OvmfPkgX64.dsc | 2 +
OvmfPkg/PlatformPei/PlatformPei.inf | 1 +
14 files changed, 1976 insertions(+), 12 deletions(-)
create mode 100644 OvmfPkg/Include/Library/HardwareInfoLib.h
create mode 100644 OvmfPkg/Library/HardwareInfoLib/DxeHardwareInfoLib.inf
create mode 100644 OvmfPkg/Library/HardwareInfoLib/HardwareInfoDxe.c
create mode 100644 OvmfPkg/Library/HardwareInfoLib/HardwareInfoPciHostBridgeLib.c
create mode 100644 OvmfPkg/Library/HardwareInfoLib/HardwareInfoPciHostBridgeLib.h
create mode 100644 OvmfPkg/Library/HardwareInfoLib/HardwareInfoPei.c
create mode 100644 OvmfPkg/Library/HardwareInfoLib/HardwareInfoTypesLib.h
create mode 100644 OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf
create mode 100644 OvmfPkg/Library/HardwareInfoLib/QemuFwCfgHardwareInfoLib.c

--
2.32.0




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


Re: [PATCH v5 1/6] MdeModulePkg/PciHostBridge: io range is not mandatory

Ard Biesheuvel
 

On Fri, 22 Apr 2022 at 09:37, Gerd Hoffmann <kraxel@...> wrote:

io range is not mandatory according to pcie spec,
so allow bridge configurations without io address
space assigned.

Signed-off-by: Gerd Hoffmann <kraxel@...>
Reviewed-by: Ard Biesheuvel <ardb@...>
Could one of the MdeModulePkg maintainers please get this reviewed? Thanks.

---
MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c
index b20bcd310ad5..712662707931 100644
--- a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c
+++ b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c
@@ -1085,6 +1085,9 @@ NotifyPhase (
RootBridge->ResAllocNode[Index].Base = BaseAddress;
RootBridge->ResAllocNode[Index].Status = ResAllocated;
DEBUG ((DEBUG_INFO, "Success\n"));
+ } else if ((Index == TypeIo) && (RootBridge->Io.Base == MAX_UINT64)) {
+ /* optional on PCIe */
+ DEBUG ((DEBUG_INFO, "PCI Root Bridge does not provide IO Resources.\n"));
} else {
ReturnStatus = EFI_OUT_OF_RESOURCES;
DEBUG ((DEBUG_ERROR, "Out Of Resource!\n"));
--
2.35.1






[PATCH] PcAtChipsetPkg: Change the flow of PcRtcInit()

Zhuoran Chao
 

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

The original flow of PcRtcInit() is like:
1. Guarantee atomic accesses to the RTC time registers and
read out the value.
2. Program RTC register B. (adopt 12h mode or 24h mode. Current
bios code sets RTC to 24h mode by default).
3. Then function ConvertRtcTimeToEfiTime converts the RTC time
value to their 24h mode by checking the hour format bit
(1:24h mode,0:12h mode).
And here lies the problem: Step3 will fail to adjust the value
if Step2 already sets RTC to 24h mode. The hour value in 12h mode
will not be converted to its 24h mode.

The solution is to program RTC register B a little later when all
the original RTC registers' value is retrieved, adjusted
and validated.

Cc: Ray Ni <ray.ni@...>

Signed-off-by: Zhuoran Chao <zhuoran.chao@...>
---
PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c
index 0fbfa4bcee..ea56a66267 100644
--- a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c
+++ b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c
@@ -269,13 +269,6 @@ PcRtcInit (
Time.Month = RtcRead (RTC_ADDRESS_MONTH);
Time.Year = RtcRead (RTC_ADDRESS_YEAR);

- //
- // Set RTC configuration after get original time
- // The value of bit AIE should be reserved.
- //
- RegisterB.Data = FixedPcdGet8 (PcdInitialValueRtcRegisterB) | (RegisterB.Data & BIT5);
- RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data);
-
//
// Release RTC Lock.
//
@@ -330,6 +323,13 @@ PcRtcInit (
Time.Daylight = 0;
}

+ //
+ // Set RTC configuration after get original time
+ // The value of bit AIE should be reserved.
+ //
+ RegisterB.Data = FixedPcdGet8 (PcdInitialValueRtcRegisterB) | (RegisterB.Data & BIT5);
+ RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data);
+
//
// Reset time value according to new RTC configuration
//
--
2.31.1.windows.1


Re: [PATCH edk2-platforms 0/3] Ext4Pkg: Add ext2/3 support and move crc16/32c to BaseLib

Pedro Falcato
 

Ping. If someone could take a look, it would be much appreciated.


On Thu, Apr 7, 2022 at 11:01 PM Pedro Falcato <pedro.falcato@...> wrote:
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3745
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3871

Hi all,

This patch-set attempts to address two open feature requests for Ext4Pkg
by adding ext2/3 support (id 3745) and moving crc16-ansi/crc32c to BaseLib (id 3871).

The previous patch-set regarding 3871 attempted to merge the different crc16 implementations
but failed because, contrary to what I thought, there are many, many different CRC16s which
are all slightly different. This one (plus the separate edk2 patch) attempts to just merge
CRC16-ANSI (confusingly, also known as CRC16) into BaseLib.

Since this patch set grew to be considerably different from the original, I didn't mark it
as v2 but rather a separate, new patch-set.

CC'ing the edk2-platforms stewards (as I cannot review my own code) and the CC's of the MdePkg
patch.

Cc: Leif Lindholm <leif@...>
Cc: Michael D Kinney <michael.d.kinney@...>
Cc: Liming Gao <gaoliming@...>
Cc: Zhiguang Liu <zhiguang.liu@...>

Pedro Falcato (3):
  Ext4Pkg: Replace the CRC implementations with BaseLib
  Ext4Pkg: Format using uncrustify
  Ext4Pkg: Add ext2/3 support

 Features/Ext4Pkg/Ext4Dxe/BlockGroup.c |  10 +-
 Features/Ext4Pkg/Ext4Dxe/BlockMap.c   | 279 +++++++++++++++++
 Features/Ext4Pkg/Ext4Dxe/Collation.c  |   4 +-
 Features/Ext4Pkg/Ext4Dxe/Crc16.c      |  75 -----
 Features/Ext4Pkg/Ext4Dxe/Crc32c.c     |  84 ------
 Features/Ext4Pkg/Ext4Dxe/Directory.c  |  13 +-
 Features/Ext4Pkg/Ext4Dxe/DiskUtil.c   |   6 +-
 Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h   |  30 +-
 Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.c    |  95 +++---
 Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h    | 417 ++++++++++++++------------
 Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.inf  |   3 +-
 Features/Ext4Pkg/Ext4Dxe/Extents.c    |  27 +-
 Features/Ext4Pkg/Ext4Dxe/File.c       |  19 +-
 Features/Ext4Pkg/Ext4Dxe/Inode.c      |  33 +-
 Features/Ext4Pkg/Ext4Dxe/Partition.c  |  12 +-
 Features/Ext4Pkg/Ext4Dxe/Superblock.c |  20 +-
 16 files changed, 640 insertions(+), 487 deletions(-)
 create mode 100644 Features/Ext4Pkg/Ext4Dxe/BlockMap.c
 delete mode 100644 Features/Ext4Pkg/Ext4Dxe/Crc16.c
 delete mode 100644 Features/Ext4Pkg/Ext4Dxe/Crc32c.c

--
2.35.1



--
Pedro Falcato


Re: [PATCH 1/1] MdePkg/BaseLib: Add CRC16-ANSI and CRC32c implementations

Pedro Falcato
 

Ping. If someone could take a look, it would be much appreciated.

On Thu, Apr 7, 2022 at 11:02 PM Pedro Falcato <pedro.falcato@...> wrote:
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3871

Add the CRC16-ANSI and CRC32C implementations previously found at
Features/Ext4Pkg/Ext4Dxe/Crc{16,32c}.c to BaseLib.

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

Signed-off-by: Pedro Falcato <pedro.falcato@...>
---
 MdePkg/Include/Library/BaseLib.h  |  35 +++++++-
 MdePkg/Library/BaseLib/CheckSum.c | 144 ++++++++++++++++++++++++++++++
 2 files changed, 178 insertions(+), 1 deletion(-)

diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h
index 6aa0d972186e..f365de9f74a0 100644
--- a/MdePkg/Include/Library/BaseLib.h
+++ b/MdePkg/Include/Library/BaseLib.h
@@ -4503,6 +4503,40 @@ CalculateCrc32 (
   IN  UINTN  Length
   );

+/**
+   Calculates the CRC16-ANSI checksum of the given buffer.
+
+   @param[in]      Buffer        Pointer to the buffer.
+   @param[in]      Length        Length of the buffer, in bytes.
+   @param[in]      InitialValue  Initial value of the CRC.
+
+   @return The CRC16-ANSI checksum.
+**/
+UINT16
+EFIAPI
+CalculateCrc16Ansi (
+  IN  CONST VOID  *Buffer,
+  IN  UINTN       Length,
+  IN  UINT16      InitialValue
+  );
+
+/**
+   Calculates the CRC32c checksum of the given buffer.
+
+   @param[in]      Buffer        Pointer to the buffer.
+   @param[in]      Length        Length of the buffer, in bytes.
+   @param[in]      InitialValue  Initial value of the CRC.
+
+   @return The CRC32c checksum.
+**/
+UINT32
+EFIAPI
+CalculateCrc32c (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length,
+  IN UINT32      InitialValue
+  );
+
 //
 // Base Library CPU Functions
 //
@@ -4512,7 +4546,6 @@ CalculateCrc32 (

   @param  Context1        Context1 parameter passed into SwitchStack().
   @param  Context2        Context2 parameter passed into SwitchStack().
-
 **/
 typedef
 VOID
diff --git a/MdePkg/Library/BaseLib/CheckSum.c b/MdePkg/Library/BaseLib/CheckSum.c
index 28dee5ac6a15..b6a076573191 100644
--- a/MdePkg/Library/BaseLib/CheckSum.c
+++ b/MdePkg/Library/BaseLib/CheckSum.c
@@ -3,6 +3,7 @@
   algorithm.

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

 **/
@@ -618,3 +619,146 @@ CalculateCrc32 (

   return Crc ^ 0xffffffff;
 }
+
+GLOBAL_REMOVE_IF_UNREFERENCED STATIC CONST UINT16  mCrc16LookupTable[256] =
+{
+  0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
+  0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
+  0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40,
+  0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841,
+  0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40,
+  0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41,
+  0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641,
+  0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040,
+  0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240,
+  0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441,
+  0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41,
+  0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840,
+  0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41,
+  0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40,
+  0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640,
+  0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041,
+  0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240,
+  0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441,
+  0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41,
+  0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840,
+  0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41,
+  0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40,
+  0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640,
+  0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041,
+  0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241,
+  0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440,
+  0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40,
+  0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841,
+  0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40,
+  0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41,
+  0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641,
+  0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040
+};
+
+/**
+   Calculates the CRC16-ANSI checksum of the given buffer.
+
+   @param[in]      Buffer        Pointer to the buffer.
+   @param[in]      Length        Length of the buffer, in bytes.
+   @param[in]      InitialValue  Initial value of the CRC.
+
+   @return The CRC16-ANSI checksum.
+**/
+UINT16
+EFIAPI
+CalculateCrc16Ansi (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length,
+  IN UINT16      InitialValue
+  )
+{
+  CONST UINT8  *Buf;
+  UINT16       Crc;
+
+  Buf = Buffer;
+
+  Crc = ~InitialValue;
+
+  while (Length-- != 0) {
+    Crc = mCrc16LookupTable[(Crc & 0xFF) ^ *(Buf++)] ^ (Crc >> 8);
+  }
+
+  return ~Crc;
+}
+
+GLOBAL_REMOVE_IF_UNREFERENCED STATIC CONST UINT32  mCrc32cLookupTable[256] = {
+  0x00000000, 0xf26b8303, 0xe13b70f7, 0x1350f3f4, 0xc79a971f, 0x35f1141c,
+  0x26a1e7e8, 0xd4ca64eb, 0x8ad958cf, 0x78b2dbcc, 0x6be22838, 0x9989ab3b,
+  0x4d43cfd0, 0xbf284cd3, 0xac78bf27, 0x5e133c24, 0x105ec76f, 0xe235446c,
+  0xf165b798, 0x030e349b, 0xd7c45070, 0x25afd373, 0x36ff2087, 0xc494a384,
+  0x9a879fa0, 0x68ec1ca3, 0x7bbcef57, 0x89d76c54, 0x5d1d08bf, 0xaf768bbc,
+  0xbc267848, 0x4e4dfb4b, 0x20bd8ede, 0xd2d60ddd, 0xc186fe29, 0x33ed7d2a,
+  0xe72719c1, 0x154c9ac2, 0x061c6936, 0xf477ea35, 0xaa64d611, 0x580f5512,
+  0x4b5fa6e6, 0xb93425e5, 0x6dfe410e, 0x9f95c20d, 0x8cc531f9, 0x7eaeb2fa,
+  0x30e349b1, 0xc288cab2, 0xd1d83946, 0x23b3ba45, 0xf779deae, 0x05125dad,
+  0x1642ae59, 0xe4292d5a, 0xba3a117e, 0x4851927d, 0x5b016189, 0xa96ae28a,
+  0x7da08661, 0x8fcb0562, 0x9c9bf696, 0x6ef07595, 0x417b1dbc, 0xb3109ebf,
+  0xa0406d4b, 0x522bee48, 0x86e18aa3, 0x748a09a0, 0x67dafa54, 0x95b17957,
+  0xcba24573, 0x39c9c670, 0x2a993584, 0xd8f2b687, 0x0c38d26c, 0xfe53516f,
+  0xed03a29b, 0x1f682198, 0x5125dad3, 0xa34e59d0, 0xb01eaa24, 0x42752927,
+  0x96bf4dcc, 0x64d4cecf, 0x77843d3b, 0x85efbe38, 0xdbfc821c, 0x2997011f,
+  0x3ac7f2eb, 0xc8ac71e8, 0x1c661503, 0xee0d9600, 0xfd5d65f4, 0x0f36e6f7,
+  0x61c69362, 0x93ad1061, 0x80fde395, 0x72966096, 0xa65c047d, 0x5437877e,
+  0x4767748a, 0xb50cf789, 0xeb1fcbad, 0x197448ae, 0x0a24bb5a, 0xf84f3859,
+  0x2c855cb2, 0xdeeedfb1, 0xcdbe2c45, 0x3fd5af46, 0x7198540d, 0x83f3d70e,
+  0x90a324fa, 0x62c8a7f9, 0xb602c312, 0x44694011, 0x5739b3e5, 0xa55230e6,
+  0xfb410cc2, 0x092a8fc1, 0x1a7a7c35, 0xe811ff36, 0x3cdb9bdd, 0xceb018de,
+  0xdde0eb2a, 0x2f8b6829, 0x82f63b78, 0x709db87b, 0x63cd4b8f, 0x91a6c88c,
+  0x456cac67, 0xb7072f64, 0xa457dc90, 0x563c5f93, 0x082f63b7, 0xfa44e0b4,
+  0xe9141340, 0x1b7f9043, 0xcfb5f4a8, 0x3dde77ab, 0x2e8e845f, 0xdce5075c,
+  0x92a8fc17, 0x60c37f14, 0x73938ce0, 0x81f80fe3, 0x55326b08, 0xa759e80b,
+  0xb4091bff, 0x466298fc, 0x1871a4d8, 0xea1a27db, 0xf94ad42f, 0x0b21572c,
+  0xdfeb33c7, 0x2d80b0c4, 0x3ed04330, 0xccbbc033, 0xa24bb5a6, 0x502036a5,
+  0x4370c551, 0xb11b4652, 0x65d122b9, 0x97baa1ba, 0x84ea524e, 0x7681d14d,
+  0x2892ed69, 0xdaf96e6a, 0xc9a99d9e, 0x3bc21e9d, 0xef087a76, 0x1d63f975,
+  0x0e330a81, 0xfc588982, 0xb21572c9, 0x407ef1ca, 0x532e023e, 0xa145813d,
+  0x758fe5d6, 0x87e466d5, 0x94b49521, 0x66df1622, 0x38cc2a06, 0xcaa7a905,
+  0xd9f75af1, 0x2b9cd9f2, 0xff56bd19, 0x0d3d3e1a, 0x1e6dcdee, 0xec064eed,
+  0xc38d26c4, 0x31e6a5c7, 0x22b65633, 0xd0ddd530, 0x0417b1db, 0xf67c32d8,
+  0xe52cc12c, 0x1747422f, 0x49547e0b, 0xbb3ffd08, 0xa86f0efc, 0x5a048dff,
+  0x8ecee914, 0x7ca56a17, 0x6ff599e3, 0x9d9e1ae0, 0xd3d3e1ab, 0x21b862a8,
+  0x32e8915c, 0xc083125f, 0x144976b4, 0xe622f5b7, 0xf5720643, 0x07198540,
+  0x590ab964, 0xab613a67, 0xb831c993, 0x4a5a4a90, 0x9e902e7b, 0x6cfbad78,
+  0x7fab5e8c, 0x8dc0dd8f, 0xe330a81a, 0x115b2b19, 0x020bd8ed, 0xf0605bee,
+  0x24aa3f05, 0xd6c1bc06, 0xc5914ff2, 0x37faccf1, 0x69e9f0d5, 0x9b8273d6,
+  0x88d28022, 0x7ab90321, 0xae7367ca, 0x5c18e4c9, 0x4f48173d, 0xbd23943e,
+  0xf36e6f75, 0x0105ec76, 0x12551f82, 0xe03e9c81, 0x34f4f86a, 0xc69f7b69,
+  0xd5cf889d, 0x27a40b9e, 0x79b737ba, 0x8bdcb4b9, 0x988c474d, 0x6ae7c44e,
+  0xbe2da0a5, 0x4c4623a6, 0x5f16d052, 0xad7d5351
+};
+
+/**
+   Calculates the CRC32c checksum of the given buffer.
+
+   @param[in]      Buffer        Pointer to the buffer.
+   @param[in]      Length        Length of the buffer, in bytes.
+   @param[in]      InitialValue  Initial value of the CRC.
+
+   @return The CRC32c checksum.
+**/
+UINT32
+EFIAPI
+CalculateCrc32c (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length,
+  IN UINT32      InitialValue
+  )
+{
+  CONST UINT8  *Buf;
+  UINT32       Crc;
+
+  Buf = Buffer;
+  Crc = ~InitialValue;
+
+  while (Length-- != 0) {
+    Crc = mCrc32cLookupTable[(Crc & 0xFF) ^ *(Buf++)] ^ (Crc >> 8);
+  }
+
+  return ~Crc;
+}
--
2.35.1



--
Pedro Falcato


Re: [edk2-platforms][PATCH v1 00/10] Add variableFlashInfoLib

Sami Mujawar
 

Hi Michael,

There are other platforms in edk2-platforms that would possibly require similar changes.

e.g. Platform\ARM\VExpressPkg\ArmVExpress-FVP-AArch64.dsc, Platform\ARM\JunoPkg\ArmJuno.dsc, etc.

Do you plan to submit patches to update these platforms as well?

Regards,

Sami Mujawar

On 20/04/2022 09:44 pm, mikuback@... wrote:
From: Michael Kubacki <michael.kubacki@...>

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

Adds an instance for the library class VariableFlashInfoLib that
was recently introduced in MdeModulePkg. This change is made to
allow the new variable driver to build that has a dependency on
this library class and does not require any further platform
changes.

Note that this series is for an upcoming change in MdeModulePkg
and requires that change to be present locally for testing.

https://edk2.groups.io/g/devel/message/88787

Cc: Abner Chang <abner.chang@...>
Cc: Ard Biesheuvel <ardb+tianocore@...>
Cc: Chasel Chiu <chasel.chiu@...>
Cc: Daniel Schaefer <daniel.schaefer@...>
Cc: Eric Dong <eric.dong@...>
Cc: Gilbert Chen <gilbert.chen@...>
Cc: Graeme Gregory <graeme@...>
Cc: Ilias Apalodimas <ilias.apalodimas@...>
Cc: Jeremy Linton <jeremy.linton@...>
Cc: Leif Lindholm <quic_llindhol@...>
Cc: Liming Gao <gaoliming@...>
Cc: Masami Hiramatsu <masami.hiramatsu@...>
Cc: Nate DeSimone <nathaniel.l.desimone@...>
Cc: Radoslaw Biernacki <rad@...>
Cc: Sami Mujawar <sami.mujawar@...>
Signed-off-by: Michael Kubacki <michael.kubacki@...>

Michael Kubacki (10):
OverdriveBoard: Add VariableFlashInfoLib
BeagleBoardPkg: Add VariableFlashInfoLib
MinPlatformPkg: Add VariableFlashInfoLib
CelloBoard: Add VariableFlashInfoLib
SbsaQemu: Add VariableFlashInfoLib
RaspberryPi: Add VariableFlashInfoLib
U5SeriesPkg: Add VariableFlashInfoLib
Socionext: Add VariableFlashInfoLib
Softiron: Add VariableFlashInfoLib
PlatformStandaloneMmPkg: Add VariableFlashInfoLib

Platform/AMD/OverdriveBoard/OverdriveBoard.dsc | 1 +
Platform/BeagleBoard/BeagleBoardPkg/BeagleBoardPkg.dsc | 1 +
Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc | 1 +
Platform/LeMaker/CelloBoard/CelloBoard.dsc | 1 +
Platform/Qemu/SbsaQemu/SbsaQemu.dsc | 1 +
Platform/RaspberryPi/RPi3/RPi3.dsc | 1 +
Platform/RaspberryPi/RPi4/RPi4.dsc | 1 +
Platform/SiFive/U5SeriesPkg/FreedomU500VC707Board/U500.dsc | 1 +
Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.dsc | 1 +
Platform/Socionext/SynQuacerEvalBoard/SynQuacerEvalBoard.dsc | 1 +
Platform/SoftIron/Overdrive1000Board/Overdrive1000Board.dsc | 1 +
Platform/StandaloneMm/PlatformStandaloneMmPkg/PlatformStandaloneMmRpmb.dsc | 1 +
12 files changed, 12 insertions(+)


Re: [edk2-platforms][PATCH v1 10/10] PlatformStandaloneMmPkg: Add VariableFlashInfoLib

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 20/04/2022 09:44 pm, mikuback@... wrote:
From: Michael Kubacki <michael.kubacki@...>

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

Adds an instance for the library class VariableFlashInfoLib that
was recently introduced in MdeModulePkg. This change is made to
allow the new variable driver to build that has a dependency on
this library class and does not require any further platform
changes.

Cc: Sami Mujawar <sami.mujawar@...>
Cc: Ilias Apalodimas <ilias.apalodimas@...>
Signed-off-by: Michael Kubacki <michael.kubacki@...>
---
Platform/StandaloneMm/PlatformStandaloneMmPkg/PlatformStandaloneMmRpmb.dsc | 1 +
1 file changed, 1 insertion(+)

diff --git a/Platform/StandaloneMm/PlatformStandaloneMmPkg/PlatformStandaloneMmRpmb.dsc b/Platform/StandaloneMm/PlatformStandaloneMmPkg/PlatformStandaloneMmRpmb.dsc
index 33364deb1ef0..653029c52fdb 100644
--- a/Platform/StandaloneMm/PlatformStandaloneMmPkg/PlatformStandaloneMmRpmb.dsc
+++ b/Platform/StandaloneMm/PlatformStandaloneMmPkg/PlatformStandaloneMmRpmb.dsc
@@ -34,6 +34,7 @@ [LibraryClasses]
ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf
BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
+ VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf


Re: [PATCH v4 5/8] ArmVirtPkg/ArmVirt.dsc.inc: Add VariableFlashInfoLib

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, mikuback@... wrote:
From: Michael Kubacki <michael.kubacki@...>

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

Adds an instance of VariableFlashInfoLib to the platform build as
it is a new library class introduced in MdeModulePkg.

Cc: Ard Biesheuvel <ardb+tianocore@...>
Cc: Leif Lindholm <quic_llindhol@...>
Cc: Sami Mujawar <sami.mujawar@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: Julien Grall <julien@...>
Signed-off-by: Michael Kubacki <michael.kubacki@...>
---
ArmVirtPkg/ArmVirt.dsc.inc | 1 +
1 file changed, 1 insertion(+)

diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc
index ba711deac025..988c1eb75529 100644
--- a/ArmVirtPkg/ArmVirt.dsc.inc
+++ b/ArmVirtPkg/ArmVirt.dsc.inc
@@ -177,6 +177,7 @@ [LibraryClasses.common]
AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLibNull.inf
!endif
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
+ VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf


Re: [PATCH v4 4/8] MdeModulePkg/FaultTolerantWrite: Consume Variable Flash Info

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 support to the UEFI variable fault tolerant write (FTW) drivers
to receive FTW base and size information dynamically via the Variable
Flash Information library.

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/Universal/FaultTolerantWriteDxe/FtwMisc.c | 41 +++++++++++++-------
MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c | 7 +++-
MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.c | 28 ++++++++-----
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 +----
8 files changed, 63 insertions(+), 60 deletions(-)

diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c
index 661e1487673b..f1335870e797 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c
@@ -987,22 +987,43 @@ InitFtwDevice (
OUT EFI_FTW_DEVICE **FtwData
)
{
- EFI_FTW_DEVICE *FtwDevice;
+ EFI_STATUS Status;
+ EFI_PHYSICAL_ADDRESS WorkSpaceAddress;
+ UINT64 Size;
+ UINTN FtwWorkingSize;
+ EFI_FTW_DEVICE *FtwDevice;
+
+ FtwWorkingSize = 0;
+
+ Status = GetVariableFlashFtwWorkingInfo (&WorkSpaceAddress, &Size);
+ ASSERT_EFI_ERROR (Status);
+
+ Status = SafeUint64ToUintn (Size, &FtwWorkingSize);
+ // This driver currently assumes the size will be UINTN so assert the value is safe for now.
+ ASSERT_EFI_ERROR (Status);
//
// Allocate private data of this driver,
// Including the FtwWorkSpace[FTW_WORK_SPACE_SIZE].
//
- FtwDevice = AllocateZeroPool (sizeof (EFI_FTW_DEVICE) + PcdGet32 (PcdFlashNvStorageFtwWorkingSize));
+ FtwDevice = AllocateZeroPool (sizeof (EFI_FTW_DEVICE) + FtwWorkingSize);
if (FtwDevice == NULL) {
return EFI_OUT_OF_RESOURCES;
}
+ FtwDevice->WorkSpaceAddress = WorkSpaceAddress;
+ FtwDevice->WorkSpaceLength = FtwWorkingSize;
+
+ Status = GetVariableFlashFtwSpareInfo (&FtwDevice->SpareAreaAddress, &Size);
+ ASSERT_EFI_ERROR (Status);
+
+ Status = SafeUint64ToUintn (Size, &FtwDevice->SpareAreaLength);
+ // This driver currently assumes the size will be UINTN so assert the value is safe for now.
+ ASSERT_EFI_ERROR (Status);
+
//
// Initialize other parameters, and set WorkSpace as FTW_ERASED_BYTE.
//
- FtwDevice->WorkSpaceLength = (UINTN)PcdGet32 (PcdFlashNvStorageFtwWorkingSize);
- FtwDevice->SpareAreaLength = (UINTN)PcdGet32 (PcdFlashNvStorageFtwSpareSize);
if ((FtwDevice->WorkSpaceLength == 0) || (FtwDevice->SpareAreaLength == 0)) {
DEBUG ((DEBUG_ERROR, "Ftw: Workspace or Spare block does not exist!\n"));
FreePool (FtwDevice);
@@ -1015,16 +1036,6 @@ InitFtwDevice (
FtwDevice->FtwWorkSpaceLba = (EFI_LBA)(-1);
FtwDevice->FtwSpareLba = (EFI_LBA)(-1);
- FtwDevice->WorkSpaceAddress = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFlashNvStorageFtwWorkingBase64);
- if (FtwDevice->WorkSpaceAddress == 0) {
- FtwDevice->WorkSpaceAddress = (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFlashNvStorageFtwWorkingBase);
- }
-
- FtwDevice->SpareAreaAddress = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFlashNvStorageFtwSpareBase64);
- if (FtwDevice->SpareAreaAddress == 0) {
- FtwDevice->SpareAreaAddress = (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFlashNvStorageFtwSpareBase);
- }
-
*FtwData = FtwDevice;
return EFI_SUCCESS;
}
@@ -1277,7 +1288,7 @@ InitFtwProtocol (
FtwDevice->FtwLastWriteHeader = NULL;
FtwDevice->FtwLastWriteRecord = NULL;
- InitializeLocalWorkSpaceHeader ();
+ InitializeLocalWorkSpaceHeader (FtwDevice->WorkSpaceLength);
//
// Refresh the working space data from working block
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c
index 61e7a92ccea1..fd563643eb63 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c
@@ -16,10 +16,13 @@ EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER mWorkingBlockHeader = { ZERO_GUID, 0, 0
Since Signature and WriteQueueSize have been known, Crc can be calculated out,
then the work space header will be fixed.
+
+ @param[in] WorkSpaceLength Length in bytes of the FTW workspace area.
+
**/
VOID
InitializeLocalWorkSpaceHeader (
- VOID
+ IN UINTN WorkSpaceLength
)
{
//
@@ -46,7 +49,7 @@ InitializeLocalWorkSpaceHeader (
&gEdkiiWorkingBlockSignatureGuid,
sizeof (EFI_GUID)
);
- mWorkingBlockHeader.WriteQueueSize = PcdGet32 (PcdFlashNvStorageFtwWorkingSize) - sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER);
+ mWorkingBlockHeader.WriteQueueSize = WorkSpaceLength - sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER);
//
// Crc is calculated with all the fields except Crc and STATE, so leave them as FTW_ERASED_BYTE.
diff --git a/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.c b/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.c
index 15543f12ed29..8c152dcbad98 100644
--- a/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.c
+++ b/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.c
@@ -16,6 +16,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/HobLib.h>
+#include <Library/SafeIntLib.h>
+#include <Library/VariableFlashInfoLib.h>
EFI_PEI_PPI_DESCRIPTOR mPpiListVariable = {
(EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
@@ -212,25 +214,31 @@ PeimFaultTolerantWriteInitialize (
EFI_PHYSICAL_ADDRESS SpareAreaAddress;
UINTN SpareAreaLength;
EFI_PHYSICAL_ADDRESS WorkSpaceInSpareArea;
+ UINT64 Size;
FAULT_TOLERANT_WRITE_LAST_WRITE_DATA FtwLastWrite;
FtwWorkingBlockHeader = NULL;
FtwLastWriteHeader = NULL;
FtwLastWriteRecord = NULL;
- WorkSpaceAddress = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFlashNvStorageFtwWorkingBase64);
- if (WorkSpaceAddress == 0) {
- WorkSpaceAddress = (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFlashNvStorageFtwWorkingBase);
- }
+ SpareAreaAddress = 0;
+ SpareAreaLength = 0;
+ WorkSpaceAddress = 0;
+ WorkSpaceLength = 0;
- WorkSpaceLength = (UINTN)PcdGet32 (PcdFlashNvStorageFtwWorkingSize);
+ Status = GetVariableFlashFtwWorkingInfo (&WorkSpaceAddress, &Size);
+ ASSERT_EFI_ERROR (Status);
- SpareAreaAddress = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFlashNvStorageFtwSpareBase64);
- if (SpareAreaAddress == 0) {
- SpareAreaAddress = (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFlashNvStorageFtwSpareBase);
- }
+ Status = SafeUint64ToUintn (Size, &WorkSpaceLength);
+ // This driver currently assumes the size will be UINTN so assert the value is safe for now.
+ ASSERT_EFI_ERROR (Status);
- SpareAreaLength = (UINTN)PcdGet32 (PcdFlashNvStorageFtwSpareSize);
+ Status = GetVariableFlashFtwSpareInfo (&SpareAreaAddress, &Size);
+ ASSERT_EFI_ERROR (Status);
+
+ Status = SafeUint64ToUintn (Size, &SpareAreaLength);
+ // This driver currently assumes the size will be UINTN so assert the value is safe for now.
+ ASSERT_EFI_ERROR (Status);
//
// The address of FTW working base and spare base must not be 0.
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h
index c14e47b5c7b2..5b84d062c294 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h
@@ -26,6 +26,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/ReportStatusCodeLib.h>
+#include <Library/SafeIntLib.h>
+#include <Library/VariableFlashInfoLib.h>
//
// Flash erase polarity is 1
@@ -708,10 +710,13 @@ InitFtwProtocol (
Since Signature and WriteQueueSize have been known, Crc can be calculated out,
then the work space header will be fixed.
+
+ @param[in] WorkSpaceLength Length in bytes of the FTW workspace area.
+
**/
VOID
InitializeLocalWorkSpaceHeader (
- VOID
+ IN UINTN WorkSpaceLength
);
/**
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
index 96165614d178..d524e1849a2e 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
@@ -46,6 +46,8 @@ [LibraryClasses]
UefiLib
PcdLib
ReportStatusCodeLib
+ SafeIntLib
+ VariableFlashInfoLib
[Guids]
#
@@ -65,14 +67,6 @@ [Protocols]
[FeaturePcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFullFtwServiceEnable ## CONSUMES
-[Pcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase ## SOMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 ## CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase ## SOMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## CONSUMES
-
#
# gBS->CalculateCrc32() is consumed in EntryPoint.
# PI spec said: When the DXE Foundation is notified that the EFI_RUNTIME_ARCH_PROTOCOL
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf
index 8cc6028470d8..8a4b9ad24657 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf
@@ -52,6 +52,8 @@ [LibraryClasses]
ReportStatusCodeLib
SmmMemLib
BaseLib
+ SafeIntLib
+ VariableFlashInfoLib
[Guids]
#
@@ -74,14 +76,6 @@ [Protocols]
[FeaturePcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFullFtwServiceEnable ## CONSUMES
-[Pcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase ## SOMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 ## CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase ## SOMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## CONSUMES
-
#
# gBS->CalculateCrc32() is consumed in EntryPoint.
# PI spec said: When the DXE Foundation is notified that the EFI_RUNTIME_ARCH_PROTOCOL
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandaloneMm.inf b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandaloneMm.inf
index d0fab7d9414f..0ac6edf771ab 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandaloneMm.inf
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandaloneMm.inf
@@ -50,7 +50,9 @@ [LibraryClasses]
MmServicesTableLib
PcdLib
ReportStatusCodeLib
+ SafeIntLib
StandaloneMmDriverEntryPoint
+ VariableFlashInfoLib
[Guids]
#
@@ -73,13 +75,5 @@ [Protocols]
[FeaturePcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFullFtwServiceEnable ## CONSUMES
-[Pcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase ## SOMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 ## CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase ## SOMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## CONSUMES
-
[Depex]
TRUE
diff --git a/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.inf b/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.inf
index f90892ad4493..230138272c3a 100644
--- a/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.inf
+++ b/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.inf
@@ -39,6 +39,8 @@ [LibraryClasses]
HobLib
BaseMemoryLib
PcdLib
+ SafeIntLib
+ VariableFlashInfoLib
[Guids]
## SOMETIMES_PRODUCES ## HOB
@@ -47,14 +49,6 @@ [Guids]
gEdkiiWorkingBlockSignatureGuid ## SOMETIMES_CONSUMES ## GUID
gEfiSystemNvDataFvGuid ## SOMETIMES_CONSUMES ## GUID
-[Pcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase ## SOMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 ## CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase ## SOMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## CONSUMES
-
[Depex]
TRUE


Re: [PATCH v4 3/8] MdeModulePkg/Variable: Consume Variable Flash Info

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

Updates VariableRuntimeDxe, VariableSmm, and VariableStandaloneMm
to acquire variable flash information from the Variable Flash
Information library.

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/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 +++++++++++++----
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 ++---
10 files changed, 56 insertions(+), 34 deletions(-)

diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.c b/MdeModulePkg/Universal/Variable/Pei/Variable.c
index b36dd0de67b2..26a4c73b45a5 100644
--- a/MdeModulePkg/Universal/Variable/Pei/Variable.c
+++ b/MdeModulePkg/Universal/Variable/Pei/Variable.c
@@ -567,11 +567,13 @@ GetVariableStore (
OUT VARIABLE_STORE_INFO *StoreInfo
)
{
+ EFI_STATUS Status;
EFI_HOB_GUID_TYPE *GuidHob;
EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
VARIABLE_STORE_HEADER *VariableStoreHeader;
EFI_PHYSICAL_ADDRESS NvStorageBase;
UINT32 NvStorageSize;
+ UINT64 NvStorageSize64;
FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *FtwLastWriteData;
UINT32 BackUpOffset;
@@ -591,11 +593,13 @@ GetVariableStore (
// Emulated non-volatile variable mode is not enabled.
//
- NvStorageSize = PcdGet32 (PcdFlashNvStorageVariableSize);
- NvStorageBase = (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvStorageVariableBase64) != 0 ?
- PcdGet64 (PcdFlashNvStorageVariableBase64) :
- PcdGet32 (PcdFlashNvStorageVariableBase)
- );
+ Status = GetVariableFlashNvStorageInfo (&NvStorageBase, &NvStorageSize64);
+ ASSERT_EFI_ERROR (Status);
+
+ Status = SafeUint64ToUint32 (NvStorageSize64, &NvStorageSize);
+ // This driver currently assumes the size will be UINT32 so assert the value is safe for now.
+ ASSERT_EFI_ERROR (Status);
+
ASSERT (NvStorageBase != 0);
//
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c
index 03fec3048dc4..d5c409c914d1 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c
@@ -423,6 +423,8 @@ FtwNotificationEvent (
EFI_PHYSICAL_ADDRESS VariableStoreBase;
UINT64 VariableStoreLength;
UINTN FtwMaxBlockSize;
+ UINT32 NvStorageVariableSize;
+ UINT64 NvStorageVariableSize64;
//
// Ensure FTW protocol is installed.
@@ -432,14 +434,20 @@ FtwNotificationEvent (
return;
}
+ Status = GetVariableFlashNvStorageInfo (&NvStorageVariableBase, &NvStorageVariableSize64);
+ ASSERT_EFI_ERROR (Status);
+
+ Status = SafeUint64ToUint32 (NvStorageVariableSize64, &NvStorageVariableSize);
+ // This driver currently assumes the size will be UINT32 so assert the value is safe for now.
+ ASSERT_EFI_ERROR (Status);
+
+ VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength;
+
Status = FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize);
if (!EFI_ERROR (Status)) {
- ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <= FtwMaxBlockSize);
+ ASSERT (NvStorageVariableSize <= FtwMaxBlockSize);
}
- NvStorageVariableBase = NV_STORAGE_VARIABLE_BASE;
- VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength;
-
//
// Let NonVolatileVariableBase point to flash variable store base directly after FTW ready.
//
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c
index 5e9d40b67ac2..9e2d8fe0fe0c 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c
@@ -142,6 +142,7 @@ InitRealNonVolatileVariableStore (
EFI_PHYSICAL_ADDRESS NvStorageBase;
UINT8 *NvStorageData;
UINT32 NvStorageSize;
+ UINT64 NvStorageSize64;
FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *FtwLastWriteData;
UINT32 BackUpOffset;
UINT32 BackUpSize;
@@ -153,19 +154,24 @@ InitRealNonVolatileVariableStore (
mVariableModuleGlobal->FvbInstance = NULL;
+ Status = GetVariableFlashNvStorageInfo (&NvStorageBase, &NvStorageSize64);
+ ASSERT_EFI_ERROR (Status);
+
+ Status = SafeUint64ToUint32 (NvStorageSize64, &NvStorageSize);
+ // This driver currently assumes the size will be UINT32 so assert the value is safe for now.
+ ASSERT_EFI_ERROR (Status);
+
+ ASSERT (NvStorageBase != 0);
+
//
// Allocate runtime memory used for a memory copy of the FLASH region.
// Keep the memory and the FLASH in sync as updates occur.
//
- NvStorageSize = PcdGet32 (PcdFlashNvStorageVariableSize);
NvStorageData = AllocateRuntimeZeroPool (NvStorageSize);
if (NvStorageData == NULL) {
return EFI_OUT_OF_RESOURCES;
}
- NvStorageBase = NV_STORAGE_VARIABLE_BASE;
- ASSERT (NvStorageBase != 0);
-
//
// Copy NV storage data to the memory buffer.
//
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c
index 517cae7b00f8..5253c328dcd9 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c
@@ -1084,6 +1084,8 @@ SmmFtwNotificationEvent (
EFI_SMM_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;
EFI_PHYSICAL_ADDRESS NvStorageVariableBase;
UINTN FtwMaxBlockSize;
+ UINT32 NvStorageVariableSize;
+ UINT64 NvStorageVariableSize64;
if (mVariableModuleGlobal->FvbInstance != NULL) {
return EFI_SUCCESS;
@@ -1097,14 +1099,21 @@ SmmFtwNotificationEvent (
return Status;
}
+ Status = GetVariableFlashNvStorageInfo (&NvStorageVariableBase, &NvStorageVariableSize64);
+ ASSERT_EFI_ERROR (Status);
+
+ Status = SafeUint64ToUint32 (NvStorageVariableSize64, &NvStorageVariableSize);
+ // This driver currently assumes the size will be UINT32 so assert the value is safe for now.
+ ASSERT_EFI_ERROR (Status);
+
+ ASSERT (NvStorageVariableBase != 0);
+ VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength;
+
Status = FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize);
if (!EFI_ERROR (Status)) {
- ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <= FtwMaxBlockSize);
+ ASSERT (NvStorageVariableSize <= FtwMaxBlockSize);
}
- NvStorageVariableBase = NV_STORAGE_VARIABLE_BASE;
- VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength;
-
//
// Let NonVolatileVariableBase point to flash variable store base directly after FTW ready.
//
diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.h b/MdeModulePkg/Universal/Variable/Pei/Variable.h
index 7f9ad5bfc357..51effbf79987 100644
--- a/MdeModulePkg/Universal/Variable/Pei/Variable.h
+++ b/MdeModulePkg/Universal/Variable/Pei/Variable.h
@@ -20,6 +20,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/BaseMemoryLib.h>
#include <Library/PeiServicesTablePointerLib.h>
#include <Library/PeiServicesLib.h>
+#include <Library/SafeIntLib.h>
+#include <Library/VariableFlashInfoLib.h>
#include <Guid/VariableFormat.h>
#include <Guid/VariableIndexTable.h>
diff --git a/MdeModulePkg/Universal/Variable/Pei/VariablePei.inf b/MdeModulePkg/Universal/Variable/Pei/VariablePei.inf
index 7cbdd2385e8f..7264a24bdf71 100644
--- a/MdeModulePkg/Universal/Variable/Pei/VariablePei.inf
+++ b/MdeModulePkg/Universal/Variable/Pei/VariablePei.inf
@@ -39,6 +39,8 @@ [LibraryClasses]
DebugLib
PeiServicesTablePointerLib
PeiServicesLib
+ SafeIntLib
+ VariableFlashInfoLib
[Guids]
## CONSUMES ## GUID # Variable store header
@@ -59,9 +61,6 @@ [Ppis]
gEfiPeiReadOnlyVariable2PpiGuid ## PRODUCES
[Pcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## SOMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvModeEnable ## SOMETIMES_CONSUMES
[Depex]
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h
index 31e408976a35..a668abb82b15 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h
@@ -31,6 +31,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/MemoryAllocationLib.h>
#include <Library/AuthVariableLib.h>
#include <Library/VarCheckLib.h>
+#include <Library/VariableFlashInfoLib.h>
+#include <Library/SafeIntLib.h>
#include <Guid/GlobalVariable.h>
#include <Guid/EventGroup.h>
#include <Guid/VariableFormat.h>
@@ -40,11 +42,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "PrivilegePolymorphic.h"
-#define NV_STORAGE_VARIABLE_BASE (EFI_PHYSICAL_ADDRESS)\
- (PcdGet64 (PcdFlashNvStorageVariableBase64) != 0 ? \
- PcdGet64 (PcdFlashNvStorageVariableBase64) : \
- PcdGet32 (PcdFlashNvStorageVariableBase))
-
#define EFI_VARIABLE_ATTRIBUTES_MASK (EFI_VARIABLE_NON_VOLATILE |\
EFI_VARIABLE_BOOTSERVICE_ACCESS | \
EFI_VARIABLE_RUNTIME_ACCESS | \
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
index c9434df631ee..3858adf6739d 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
@@ -71,8 +71,10 @@ [LibraryClasses]
TpmMeasurementLib
AuthVariableLib
VarCheckLib
+ VariableFlashInfoLib
VariablePolicyLib
VariablePolicyHelperLib
+ SafeIntLib
[Protocols]
gEfiFirmwareVolumeBlockProtocolGuid ## CONSUMES
@@ -125,9 +127,6 @@ [Guids]
gEfiImageSecurityDatabaseGuid
[Pcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## SOMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## CONSUMES
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf
index eaa97a01c6e5..8c552b87e080 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf
@@ -80,8 +80,10 @@ [LibraryClasses]
AuthVariableLib
VarCheckLib
UefiBootServicesTableLib
+ VariableFlashInfoLib
VariablePolicyLib
VariablePolicyHelperLib
+ SafeIntLib
[Protocols]
gEfiSmmFirmwareVolumeBlockProtocolGuid ## CONSUMES
@@ -127,9 +129,6 @@ [Guids]
gEdkiiVarErrorFlagGuid
[Pcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## SOMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## CONSUMES
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf
index d8c4f77e7f1f..f09bed40cf51 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf
@@ -73,9 +73,11 @@ [LibraryClasses]
HobLib
MemoryAllocationLib
MmServicesTableLib
+ SafeIntLib
StandaloneMmDriverEntryPoint
SynchronizationLib
VarCheckLib
+ VariableFlashInfoLib
VariablePolicyLib
VariablePolicyHelperLib
@@ -120,9 +122,6 @@ [Guids]
gEdkiiVarErrorFlagGuid
[Pcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## SOMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## CONSUMES


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

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 } }


Re: [PATCH v4 2/8] MdeModulePkg/VariableFlashInfoLib: Add initial library

Sami Mujawar
 

Hi Michael,

I have a minor suggestion marked inline as [SAMI].

Otherwise this patch looks 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 library class VariableFlashInfoLib that abstracts access
to variable flash information. The instance provided first attempts
to retrieve information from the Variable Flash Info HOB. If that
HOB is not present, it falls back to the PCDs defined in
MdeModulePkg.

This fall back behavior provides backward compatibility for platforms
that only provide PCDs but also allows platforms that need to
dynamically provide the information using the Variable Flash Info HOB
to do so at runtime.

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/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.c | 178 ++++++++++++++++++++
MdeModulePkg/Include/Library/VariableFlashInfoLib.h | 68 ++++++++
MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf | 48 ++++++
MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.uni | 12 ++
MdeModulePkg/MdeModulePkg.dec | 4 +
MdeModulePkg/MdeModulePkg.dsc | 2 +
6 files changed, 312 insertions(+)

diff --git a/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.c b/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.c
new file mode 100644
index 000000000000..a1db97bdf218
--- /dev/null
+++ b/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.c
@@ -0,0 +1,178 @@
+/** @file
+ Variable Flash Information Library
+
+ Copyright (c) Microsoft Corporation<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Uefi.h>
+#include <Pi/PiMultiPhase.h>
+#include <Guid/VariableFlashInfo.h>
+#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+#include <Library/VariableFlashInfoLib.h>
+
+/**
+ Get the HOB that contains variable flash information.
+
+ @param[out] VariableFlashInfo Pointer to a pointer to set to the variable flash information structure.
+
+ @retval EFI_SUCCESS Variable flash information was found successfully.
+ @retval EFI_INVALID_PARAMETER The VariableFlashInfo pointer given is NULL.
+ @retval EFI_NOT_FOUND Variable flash information could not be found.
+
+**/
+EFI_STATUS
+GetVariableFlashInfoFromHob (
+ OUT VARIABLE_FLASH_INFO **VariableFlashInfo
+ )
[SAMI] Can this function be made STATIC, please?
+{
+ EFI_HOB_GUID_TYPE *GuidHob;
+
+ if (VariableFlashInfo == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ GuidHob = GetFirstGuidHob (&gVariableFlashInfoHobGuid);
+ if (GuidHob == NULL) {
+ return EFI_NOT_FOUND;
+ }
+
+ *VariableFlashInfo = GET_GUID_HOB_DATA (GuidHob);
+
+ //
+ // Assert if more than one variable flash information HOB is present.
+ //
+ DEBUG_CODE (
+ if ((GetNextGuidHob (&gVariableFlashInfoHobGuid, GET_NEXT_HOB (GuidHob)) != NULL)) {
+ DEBUG ((DEBUG_ERROR, "ERROR: Found two variable flash information HOBs\n"));
+ ASSERT (FALSE);
+ }
+
+ );
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Get the base address and size for the NV storage area used for UEFI variable storage.
+
+ @param[out] BaseAddress The NV storage base address.
+ @param[out] Length The NV storage length in bytes.
+
+ @retval EFI_SUCCESS NV storage information was found successfully.
+ @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL.
+
+**/
+EFI_STATUS
+EFIAPI
+GetVariableFlashNvStorageInfo (
+ OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
+ OUT UINT64 *Length
+ )
+{
+ EFI_STATUS Status;
+ VARIABLE_FLASH_INFO *VariableFlashInfo;
+
+ if ((BaseAddress == NULL) || (Length == NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status = GetVariableFlashInfoFromHob (&VariableFlashInfo);
+ if (!EFI_ERROR (Status)) {
+ *BaseAddress = VariableFlashInfo->NvVariableBaseAddress;
+ *Length = VariableFlashInfo->NvVariableLength;
+ } else {
+ *BaseAddress = (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvStorageVariableBase64) != 0 ?
+ PcdGet64 (PcdFlashNvStorageVariableBase64) :
+ PcdGet32 (PcdFlashNvStorageVariableBase)
+ );
+ *Length = (UINT64)PcdGet32 (PcdFlashNvStorageVariableSize);
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Get the base address and size for the fault tolerant write (FTW) spare
+ area used for UEFI variable storage.
+
+ @param[out] BaseAddress The FTW spare base address.
+ @param[out] Length The FTW spare length in bytes.
+
+ @retval EFI_SUCCESS FTW spare information was found successfully.
+ @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL.
+ @retval EFI_NOT_FOUND FTW spare information could not be found.
+
+**/
+EFI_STATUS
+EFIAPI
+GetVariableFlashFtwSpareInfo (
+ OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
+ OUT UINT64 *Length
+ )
+{
+ EFI_STATUS Status;
+ VARIABLE_FLASH_INFO *VariableFlashInfo;
+
+ if ((BaseAddress == NULL) || (Length == NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status = GetVariableFlashInfoFromHob (&VariableFlashInfo);
+ if (!EFI_ERROR (Status)) {
+ *BaseAddress = VariableFlashInfo->FtwSpareBaseAddress;
+ *Length = VariableFlashInfo->FtwSpareLength;
+ } else {
+ *BaseAddress = (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvStorageFtwSpareBase64) != 0 ?
+ PcdGet64 (PcdFlashNvStorageFtwSpareBase64) :
+ PcdGet32 (PcdFlashNvStorageFtwSpareBase)
+ );
+ *Length = (UINT64)PcdGet32 (PcdFlashNvStorageFtwSpareSize);
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Get the base address and size for the fault tolerant write (FTW) working
+ area used for UEFI variable storage.
+
+ @param[out] BaseAddress The FTW working area base address.
+ @param[out] Length The FTW working area length in bytes.
+
+ @retval EFI_SUCCESS FTW working information was found successfully.
+ @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL.
+ @retval EFI_NOT_FOUND FTW working information could not be found.
+
+**/
+EFI_STATUS
+EFIAPI
+GetVariableFlashFtwWorkingInfo (
+ OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
+ OUT UINT64 *Length
+ )
+{
+ EFI_STATUS Status;
+ VARIABLE_FLASH_INFO *VariableFlashInfo;
+
+ if ((BaseAddress == NULL) || (Length == NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status = GetVariableFlashInfoFromHob (&VariableFlashInfo);
+ if (!EFI_ERROR (Status)) {
+ *BaseAddress = VariableFlashInfo->FtwWorkingBaseAddress;
+ *Length = VariableFlashInfo->FtwWorkingLength;
+ } else {
+ *BaseAddress = (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvStorageFtwWorkingBase64) != 0 ?
+ PcdGet64 (PcdFlashNvStorageFtwWorkingBase64) :
+ PcdGet32 (PcdFlashNvStorageFtwWorkingBase)
+ );
+ *Length = (UINT64)PcdGet32 (PcdFlashNvStorageFtwWorkingSize);
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/MdeModulePkg/Include/Library/VariableFlashInfoLib.h b/MdeModulePkg/Include/Library/VariableFlashInfoLib.h
new file mode 100644
index 000000000000..1367be9376ea
--- /dev/null
+++ b/MdeModulePkg/Include/Library/VariableFlashInfoLib.h
@@ -0,0 +1,68 @@
+/** @file
+ Variable Flash Information Library
+
+Copyright (c) Microsoft Corporation<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef VARIABLE_FLASH_INFO_LIB_H_
+#define VARIABLE_FLASH_INFO_LIB_H_
+
+/**
+ Get the base address and size for the NV storage area used for UEFI variable storage.
+
+ @param[out] BaseAddress The NV storage base address.
+ @param[out] Length The NV storage length in bytes.
+
+ @retval EFI_SUCCESS NV storage information was found successfully.
+ @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL.
+ @retval EFI_NOT_FOUND NV storage information could not be found.
+
+**/
+EFI_STATUS
+EFIAPI
+GetVariableFlashNvStorageInfo (
+ OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
+ OUT UINT64 *Length
+ );
+
+/**
+ Get the base address and size for the fault tolerant write (FTW) spare
+ area used for UEFI variable storage.
+
+ @param[out] BaseAddress The FTW spare base address.
+ @param[out] Length The FTW spare length in bytes.
+
+ @retval EFI_SUCCESS FTW spare information was found successfully.
+ @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL.
+ @retval EFI_NOT_FOUND FTW spare information could not be found.
+
+**/
+EFI_STATUS
+EFIAPI
+GetVariableFlashFtwSpareInfo (
+ OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
+ OUT UINT64 *Length
+ );
+
+/**
+ Get the base address and size for the fault tolerant write (FTW) working
+ area used for UEFI variable storage.
+
+ @param[out] BaseAddress The FTW working area base address.
+ @param[out] Length The FTW working area length in bytes.
+
+ @retval EFI_SUCCESS FTW working information was found successfully.
+ @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL.
+ @retval EFI_NOT_FOUND FTW working information could not be found.
+
+**/
+EFI_STATUS
+EFIAPI
+GetVariableFlashFtwWorkingInfo (
+ OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
+ OUT UINT64 *Length
+ );
+
+#endif
diff --git a/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf b/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
new file mode 100644
index 000000000000..70175e75f9b1
--- /dev/null
+++ b/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
@@ -0,0 +1,48 @@
+## @file
+# Variable Flash Information Library
+#
+# Provides services to access UEFI variable flash information.
+#
+# Copyright (c) Microsoft Corporation<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = BaseVariableFlashInfoLib
+ MODULE_UNI_FILE = BaseVariableFlashInfoLib.uni
+ FILE_GUID = DEC426C9-C92E-4BAD-8E93-3F61C261118B
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = VariableFlashInfoLib
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = ANY
+#
+
+[Sources]
+ BaseVariableFlashInfoLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+ DebugLib
+ HobLib
+
+[Guids]
+ gVariableFlashInfoHobGuid ## CONSUMES ## HOB
+
+[Pcd]
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## SOMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## SOMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## SOMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase ## SOMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## SOMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## SOMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase ## SOMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 ## SOMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## SOMETIMES_CONSUMES
diff --git a/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.uni b/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.uni
new file mode 100644
index 000000000000..9a5348fa02a0
--- /dev/null
+++ b/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.uni
@@ -0,0 +1,12 @@
+// /** @file
+// Variable Flash Information Library
+//
+// Copyright (c) Microsoft Corporation<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_MODULE_ABSTRACT #language en-US "UEFI variable flash information library"
+
+#string STR_MODULE_DESCRIPTION #language en-US "Provides services to access UEFI variable flash information."
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index 4e82f5836096..2bcb9f9453af 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -154,6 +154,10 @@ [LibraryClasses]
#
VariablePolicyHelperLib|Include/Library/VariablePolicyHelperLib.h
+ ## @libraryclass Provides services to access UEFI variable flash information.
+ #
+ VariableFlashInfoLib|Include/Library/VariableFlashInfoLib.h
+
[Guids]
## MdeModule package token space guid
# Include/Guid/MdeModulePkgTokenSpace.h
diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc
index b1d83461865e..90a0a7ec4a7c 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -103,6 +103,7 @@ [LibraryClasses]
DisplayUpdateProgressLib|MdeModulePkg/Library/DisplayUpdateProgressLibGraphics/DisplayUpdateProgressLibGraphics.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
MmUnblockMemoryLib|MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf
+ VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
[LibraryClasses.EBC.PEIM]
IoLib|MdePkg/Library/PeiIoLibCpuIo/PeiIoLibCpuIo.inf
@@ -440,6 +441,7 @@ [Components]
MdeModulePkg/Library/FmpAuthenticationLibNull/FmpAuthenticationLibNull.inf
MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf
MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf
+ MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
[Components.IA32, Components.X64, Components.AARCH64]
MdeModulePkg/Universal/EbcDxe/EbcDxe.inf


Re: [PATCH 3/4] CryptoPkg: Make EC source file config-able

PierreGondois
 

Hello Yi1, Jiewen, and Bob,

As you mentioned in the cover letter, this patch relies on the following patch
bf9230a9f3dd ("BaseTools: Add the FeatureFlagExpression usage to the Source Section")
https://github.com/tianocore/edk2/commit/bf9230a9f3dde065c3c8b4175ccd32e44e8f0362

I just wanted to signal that this patch is currently not in
https://github.com/tianocore/edk2-basetools
It is thus not in any edk2basetools python module: the latest version of the edk2-basetools python module won't support the new build feature (cf pip-requirements.txt).
Thus someone who:
-relies on the edk2basetools python module
-tries to build an edk2 module relying on OpenSSL
will have a build break.

For instance, I get the following error when building:
build -a AARCH64 -t GCC5 -p SecurityPkg/SecurityPkg.dsc
...
"[some_path]/edk2/BaseTools/Bin/gcc_aarch64_linux_extdep/bin/aarch64-none-linux-gnu-gcc" @[some_path]/Build/SbsaQemu/DEBUG_GCC5/AARCH64/CryptoPkg/Library/OpensslLib/OpensslLib/OUTPUT/cc_resp.txt -c -o [some_path]/Build/SbsaQemu/DEBUG_GCC5/AARCH64/CryptoPkg/Library/OpensslLib/OpensslLib/OUTPUT/openssl/crypto/ec/curve25519.obj [some_path]/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/ec/curve25519.c
In file included from [some_path]/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/ec/curve25519.c:11:
[some_path]/edk2/CryptoPkg/Library/OpensslLib/openssl/crypto/ec/ec_local.h:48:24: error: unknown type name ‘EC_GROUP’
48 | int (*group_init) (EC_GROUP *);

This is due to the build system trying to build a file in $(OPENSSL_PATH)/crypto/ec/* even though gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled is set to FALSE by default. The new Pcd feature to build files conditionally on a Pcd value is not handled yet.
The edk2 CI doesn't seem to build modules relying on OpenSSL due to the CONTINUOUS_INTEGRATION flag, explaining why the patch passed the CI I think.

I added Bob as I think he knows more about BaseTools.

Regards,
Pierre

On 4/18/22 15:03, yi1 li via groups.io wrote:
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3679
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3828
Use PCD gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled to config-able
source files list in OpensslLib.inf and OpensslLibCrypto.inf.
If PcdEcEnabled equals to FALSE, this file will not be compiled.
Signed-off-by: yi1 li <yi1.li@...>
---
CryptoPkg/CryptoPkg.dec | 4 +
.../Library/Include/openssl/opensslconf.h | 7 +-
CryptoPkg/Library/OpensslLib/OpensslLib.inf | 95 ++++++++++---------
.../Library/OpensslLib/OpensslLibCrypto.inf | 95 ++++++++++---------
4 files changed, 108 insertions(+), 93 deletions(-)
diff --git a/CryptoPkg/CryptoPkg.dec b/CryptoPkg/CryptoPkg.dec
index 5888941bab4c..ebec64050b71 100644
--- a/CryptoPkg/CryptoPkg.dec
+++ b/CryptoPkg/CryptoPkg.dec
@@ -81,5 +81,9 @@
# @ValidList 0x80000001 | 0x00000001, 0x00000002, 0x00000004, 0x00000008, 0x00000010
gEfiCryptoPkgTokenSpaceGuid.PcdHashApiLibPolicy|0x00000002|UINT32|0x00000001
+ ## Enable/Disable the ECC feature in openssl library. The default is disabled.
+ # If ECC feature is disabled, all related source files will not be compiled.
+ gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled|FALSE|BOOLEAN|0x0000003
+
[UserExtensions.TianoCore."ExtraFiles"]
CryptoPkgExtra.uni
diff --git a/CryptoPkg/Library/Include/openssl/opensslconf.h b/CryptoPkg/Library/Include/openssl/opensslconf.h
index 7ea976b2252e..1485b8c9f108 100644
--- a/CryptoPkg/Library/Include/openssl/opensslconf.h
+++ b/CryptoPkg/Library/Include/openssl/opensslconf.h
@@ -9,7 +9,7 @@
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
-
+#include <Library/PcdLib.h>
#include <openssl/opensslv.h>
#ifdef __cplusplus
@@ -55,6 +55,11 @@ extern "C" {
#ifndef OPENSSL_NO_DSA
#define OPENSSL_NO_DSA
#endif
+#if !FixedPcdGetBool (PcdEcEnabled)
+ #ifndef OPENSSL_NO_EC
+#define OPENSSL_NO_EC
+ #endif
+#endif
#ifndef OPENSSL_NO_IDEA
#define OPENSSL_NO_IDEA
#endif
diff --git a/CryptoPkg/Library/OpensslLib/OpensslLib.inf b/CryptoPkg/Library/OpensslLib/OpensslLib.inf
index 1d67ed55e1b1..459ac4864a4e 100644
--- a/CryptoPkg/Library/OpensslLib/OpensslLib.inf
+++ b/CryptoPkg/Library/OpensslLib/OpensslLib.inf
@@ -199,43 +199,43 @@
$(OPENSSL_PATH)/crypto/dso/dso_vms.c
$(OPENSSL_PATH)/crypto/dso/dso_win32.c
$(OPENSSL_PATH)/crypto/ebcdic.c
- $(OPENSSL_PATH)/crypto/ec/curve25519.c
- $(OPENSSL_PATH)/crypto/ec/curve448/arch_32/f_impl.c
- $(OPENSSL_PATH)/crypto/ec/curve448/curve448.c
- $(OPENSSL_PATH)/crypto/ec/curve448/curve448_tables.c
- $(OPENSSL_PATH)/crypto/ec/curve448/eddsa.c
- $(OPENSSL_PATH)/crypto/ec/curve448/f_generic.c
- $(OPENSSL_PATH)/crypto/ec/curve448/scalar.c
- $(OPENSSL_PATH)/crypto/ec/ec2_oct.c
- $(OPENSSL_PATH)/crypto/ec/ec2_smpl.c
- $(OPENSSL_PATH)/crypto/ec/ec_ameth.c
- $(OPENSSL_PATH)/crypto/ec/ec_asn1.c
- $(OPENSSL_PATH)/crypto/ec/ec_check.c
- $(OPENSSL_PATH)/crypto/ec/ec_curve.c
- $(OPENSSL_PATH)/crypto/ec/ec_cvt.c
- $(OPENSSL_PATH)/crypto/ec/ec_err.c
- $(OPENSSL_PATH)/crypto/ec/ec_key.c
- $(OPENSSL_PATH)/crypto/ec/ec_kmeth.c
- $(OPENSSL_PATH)/crypto/ec/ec_lib.c
- $(OPENSSL_PATH)/crypto/ec/ec_mult.c
- $(OPENSSL_PATH)/crypto/ec/ec_oct.c
- $(OPENSSL_PATH)/crypto/ec/ec_pmeth.c
- $(OPENSSL_PATH)/crypto/ec/ec_print.c
- $(OPENSSL_PATH)/crypto/ec/ecdh_kdf.c
- $(OPENSSL_PATH)/crypto/ec/ecdh_ossl.c
- $(OPENSSL_PATH)/crypto/ec/ecdsa_ossl.c
- $(OPENSSL_PATH)/crypto/ec/ecdsa_sign.c
- $(OPENSSL_PATH)/crypto/ec/ecdsa_vrf.c
- $(OPENSSL_PATH)/crypto/ec/eck_prn.c
- $(OPENSSL_PATH)/crypto/ec/ecp_mont.c
- $(OPENSSL_PATH)/crypto/ec/ecp_nist.c
- $(OPENSSL_PATH)/crypto/ec/ecp_nistp224.c
- $(OPENSSL_PATH)/crypto/ec/ecp_nistp256.c
- $(OPENSSL_PATH)/crypto/ec/ecp_nistp521.c
- $(OPENSSL_PATH)/crypto/ec/ecp_nistputil.c
- $(OPENSSL_PATH)/crypto/ec/ecp_oct.c
- $(OPENSSL_PATH)/crypto/ec/ecp_smpl.c
- $(OPENSSL_PATH)/crypto/ec/ecx_meth.c
+ $(OPENSSL_PATH)/crypto/ec/curve25519.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/arch_32/f_impl.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/curve448.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/curve448_tables.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/eddsa.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/f_generic.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/scalar.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec2_oct.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec2_smpl.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec_ameth.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec_asn1.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec_check.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec_curve.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec_cvt.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec_err.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec_key.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec_kmeth.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec_lib.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec_mult.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec_oct.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec_pmeth.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec_print.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecdh_kdf.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecdh_ossl.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecdsa_ossl.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecdsa_sign.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecdsa_vrf.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/eck_prn.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecp_mont.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecp_nist.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecp_nistp224.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecp_nistp256.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecp_nistp521.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecp_nistputil.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecp_oct.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecp_smpl.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecx_meth.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
$(OPENSSL_PATH)/crypto/err/err.c
$(OPENSSL_PATH)/crypto/err/err_prn.c
$(OPENSSL_PATH)/crypto/evp/bio_b64.c
@@ -533,15 +533,15 @@
$(OPENSSL_PATH)/crypto/conf/conf_local.h
$(OPENSSL_PATH)/crypto/dh/dh_local.h
$(OPENSSL_PATH)/crypto/dso/dso_local.h
- $(OPENSSL_PATH)/crypto/ec/ec_local.h
- $(OPENSSL_PATH)/crypto/ec/curve448/curve448_local.h
- $(OPENSSL_PATH)/crypto/ec/curve448/curve448utils.h
- $(OPENSSL_PATH)/crypto/ec/curve448/ed448.h
- $(OPENSSL_PATH)/crypto/ec/curve448/field.h
- $(OPENSSL_PATH)/crypto/ec/curve448/point_448.h
- $(OPENSSL_PATH)/crypto/ec/curve448/word.h
- $(OPENSSL_PATH)/crypto/ec/curve448/arch_32/arch_intrinsics.h
- $(OPENSSL_PATH)/crypto/ec/curve448/arch_32/f_impl.h
+ $(OPENSSL_PATH)/crypto/ec/ec_local.h |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/curve448_local.h |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/curve448utils.h |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/ed448.h |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/field.h |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/point_448.h |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/word.h |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/arch_32/arch_intrinsics.h |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/arch_32/f_impl.h |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
$(OPENSSL_PATH)/crypto/evp/evp_local.h
$(OPENSSL_PATH)/crypto/hmac/hmac_local.h
$(OPENSSL_PATH)/crypto/lhash/lhash_local.h
@@ -633,6 +633,9 @@
[LibraryClasses.ARM]
ArmSoftFloatLib
+[Pcd]
+ gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled ## CONSUMES
+
[BuildOptions]
#
# Disables the following Visual Studio compiler warnings brought by openssl source,
diff --git a/CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf b/CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf
index 66ca5b1250c1..c9d69a368e3c 100644
--- a/CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf
+++ b/CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf
@@ -199,43 +199,43 @@
$(OPENSSL_PATH)/crypto/dso/dso_vms.c
$(OPENSSL_PATH)/crypto/dso/dso_win32.c
$(OPENSSL_PATH)/crypto/ebcdic.c
- $(OPENSSL_PATH)/crypto/ec/curve25519.c
- $(OPENSSL_PATH)/crypto/ec/curve448/arch_32/f_impl.c
- $(OPENSSL_PATH)/crypto/ec/curve448/curve448.c
- $(OPENSSL_PATH)/crypto/ec/curve448/curve448_tables.c
- $(OPENSSL_PATH)/crypto/ec/curve448/eddsa.c
- $(OPENSSL_PATH)/crypto/ec/curve448/f_generic.c
- $(OPENSSL_PATH)/crypto/ec/curve448/scalar.c
- $(OPENSSL_PATH)/crypto/ec/ec2_oct.c
- $(OPENSSL_PATH)/crypto/ec/ec2_smpl.c
- $(OPENSSL_PATH)/crypto/ec/ec_ameth.c
- $(OPENSSL_PATH)/crypto/ec/ec_asn1.c
- $(OPENSSL_PATH)/crypto/ec/ec_check.c
- $(OPENSSL_PATH)/crypto/ec/ec_curve.c
- $(OPENSSL_PATH)/crypto/ec/ec_cvt.c
- $(OPENSSL_PATH)/crypto/ec/ec_err.c
- $(OPENSSL_PATH)/crypto/ec/ec_key.c
- $(OPENSSL_PATH)/crypto/ec/ec_kmeth.c
- $(OPENSSL_PATH)/crypto/ec/ec_lib.c
- $(OPENSSL_PATH)/crypto/ec/ec_mult.c
- $(OPENSSL_PATH)/crypto/ec/ec_oct.c
- $(OPENSSL_PATH)/crypto/ec/ec_pmeth.c
- $(OPENSSL_PATH)/crypto/ec/ec_print.c
- $(OPENSSL_PATH)/crypto/ec/ecdh_kdf.c
- $(OPENSSL_PATH)/crypto/ec/ecdh_ossl.c
- $(OPENSSL_PATH)/crypto/ec/ecdsa_ossl.c
- $(OPENSSL_PATH)/crypto/ec/ecdsa_sign.c
- $(OPENSSL_PATH)/crypto/ec/ecdsa_vrf.c
- $(OPENSSL_PATH)/crypto/ec/eck_prn.c
- $(OPENSSL_PATH)/crypto/ec/ecp_mont.c
- $(OPENSSL_PATH)/crypto/ec/ecp_nist.c
- $(OPENSSL_PATH)/crypto/ec/ecp_nistp224.c
- $(OPENSSL_PATH)/crypto/ec/ecp_nistp256.c
- $(OPENSSL_PATH)/crypto/ec/ecp_nistp521.c
- $(OPENSSL_PATH)/crypto/ec/ecp_nistputil.c
- $(OPENSSL_PATH)/crypto/ec/ecp_oct.c
- $(OPENSSL_PATH)/crypto/ec/ecp_smpl.c
- $(OPENSSL_PATH)/crypto/ec/ecx_meth.c
+ $(OPENSSL_PATH)/crypto/ec/curve25519.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/arch_32/f_impl.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/curve448.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/curve448_tables.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/eddsa.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/f_generic.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/scalar.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec2_oct.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec2_smpl.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec_ameth.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec_asn1.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec_check.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec_curve.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec_cvt.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec_err.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec_key.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec_kmeth.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec_lib.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec_mult.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec_oct.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec_pmeth.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ec_print.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecdh_kdf.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecdh_ossl.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecdsa_ossl.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecdsa_sign.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecdsa_vrf.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/eck_prn.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecp_mont.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecp_nist.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecp_nistp224.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecp_nistp256.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecp_nistp521.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecp_nistputil.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecp_oct.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecp_smpl.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/ecx_meth.c |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
$(OPENSSL_PATH)/crypto/err/err.c
$(OPENSSL_PATH)/crypto/err/err_prn.c
$(OPENSSL_PATH)/crypto/evp/bio_b64.c
@@ -533,15 +533,15 @@
$(OPENSSL_PATH)/crypto/conf/conf_local.h
$(OPENSSL_PATH)/crypto/dh/dh_local.h
$(OPENSSL_PATH)/crypto/dso/dso_local.h
- $(OPENSSL_PATH)/crypto/ec/ec_local.h
- $(OPENSSL_PATH)/crypto/ec/curve448/curve448_local.h
- $(OPENSSL_PATH)/crypto/ec/curve448/curve448utils.h
- $(OPENSSL_PATH)/crypto/ec/curve448/ed448.h
- $(OPENSSL_PATH)/crypto/ec/curve448/field.h
- $(OPENSSL_PATH)/crypto/ec/curve448/point_448.h
- $(OPENSSL_PATH)/crypto/ec/curve448/word.h
- $(OPENSSL_PATH)/crypto/ec/curve448/arch_32/arch_intrinsics.h
- $(OPENSSL_PATH)/crypto/ec/curve448/arch_32/f_impl.h
+ $(OPENSSL_PATH)/crypto/ec/ec_local.h |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/curve448_local.h |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/curve448utils.h |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/ed448.h |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/field.h |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/point_448.h |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/word.h |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/arch_32/arch_intrinsics.h |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
+ $(OPENSSL_PATH)/crypto/ec/curve448/arch_32/f_impl.h |*|*|*|gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled
$(OPENSSL_PATH)/crypto/evp/evp_local.h
$(OPENSSL_PATH)/crypto/hmac/hmac_local.h
$(OPENSSL_PATH)/crypto/lhash/lhash_local.h
@@ -582,6 +582,9 @@
[LibraryClasses.ARM]
ArmSoftFloatLib
+[Pcd]
+ gEfiCryptoPkgTokenSpaceGuid.PcdEcEnabled ## CONSUMES
+
[BuildOptions]
#
# Disables the following Visual Studio compiler warnings brought by openssl source,


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

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

Hi all,
Are there any other comments or concerns regarding this patch?

Thanks,
Stacy

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

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

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

Thanks,
Stacy

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

Hi Sean,

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

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

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

Mike

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

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


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

OR

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


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




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

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

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

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

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

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

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

--
2.32.0.windows.2













Re: [edk2-platforms PATCH v1 0/1] BoardModulePkg: Copy device path

Attar, AbdulLateef (Abdul Lateef) <AbdulLateef.Attar@...>
 

[Public]

Hi,
Please review the patch.
Thanks
AbduL

-----Original Message-----
From: Attar, AbdulLateef (Abdul Lateef) <AbdulLateef.Attar@...>
Sent: 05 April 2022 11:25
To: devel@edk2.groups.io; Attar, AbdulLateef (Abdul Lateef) <AbdulLateef.Attar@...>; Eric Dong <eric.dong@...>; Liming Gao <gaoliming@...>
Subject: RE: [edk2-devel] [edk2-platforms PATCH v1 0/1] BoardModulePkg: Copy device path

[Public]

Hi,
Could you please review the patch?
Thanks
AbduL

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Abdul Lateef Attar via groups.io
Sent: 15 March 2022 10:16
To: devel@edk2.groups.io
Cc: Eric Dong <eric.dong@...>; Liming Gao <gaoliming@...>
Subject: [edk2-devel] [edk2-platforms PATCH v1 0/1] BoardModulePkg: Copy device path

[CAUTION: External Email]

(Resending patch with [edk2-platforms] prefix with correct emailid).
GCC compiler puts the DevicePath PCDs to the read-only section. During boot if try to process the device path after PtrGetPtr it throws a page fault exception.

Hence making a local copy using DuplicateDevicePath() to avoid the page fault exception.

REF : https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fabdattar%2Fedk2-platforms%2Ftree%2FBoardModulePkg&;data=04%7C01%7CAbdulLateef.Attar%40amd.com%7Cdd04fc2187754979081008da063ebd5d%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637829164332474465%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=MX%2FlzKO2jVyPHaaURb7b8kMyNWFAlMPZ%2B0gK%2Ffrh5xo%3D&amp;reserved=0

Cc: Eric Dong <eric.dong@...>
Cc: Liming Gao <gaoliming@...>

Abdul Lateef Attar (1):
BoardModulePkg: Copy device path before processing

Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBdsHookLib.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)

--
2.25.1


[PATCH v2] MdeModulePkg/XhciDxe: Add access xHCI Extended Capabilities Pointer

ian.chiu@...
 

From: Ian Chiu <Ian.chiu@...>

Add support process Port Speed field value of PORTSC according to Supported=
Protocol Capability
(new design in xHCI spec 1.2 2019)

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

The value of Port Speed field in PORTSC bit[10:13] (xHCI spec 1.2 2019 sect=
ion 5.4.8)
should be change to use this value to query thru Protocol Speed ID (PSI)
(xHCI spec 1.2 2019 section 7.2.1) in xHCI Supported Protocol Capability and
return the value according the Protocol Speed ID (PSIV) Dword.

Cc: Jenny Huang <jenny.huang@...>
Cc: More Shih <more.shih@...>
Cc: Hao A Wu <hao.a.wu@...>
Cc: Ray Ni <ray.ni@...>
Signed-off-by: Ian Chiu <Ian.chiu@...>
---
MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 41 ++++--
MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h | 2 +
MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c | 147 ++++++++++++++++++++
MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.h | 87 ++++++++++++
4 files changed, 262 insertions(+), 15 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c b/MdeModulePkg/Bus/Pci/Xhc=
iDxe/Xhci.c
index b79499e225..f5b99210c9 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
@@ -398,25 +398,32 @@ XhcGetRootHubPortStatus (
State =3D XhcReadOpReg (Xhc, Offset);=0D
=0D
//=0D
- // According to XHCI 1.1 spec November 2017,=0D
- // bit 10~13 of the root port status register identifies the speed of th=
e attached device.=0D
+ // According to XHCI 1.2 spec November 2019,=0D
+ // Section 7.2 xHCI Support Protocol Capability=0D
//=0D
- switch ((State & XHC_PORTSC_PS) >> 10) {=0D
- case 2:=0D
- PortStatus->PortStatus |=3D USB_PORT_STAT_LOW_SPEED;=0D
- break;=0D
+ PortStatus->PortStatus =3D XhcCheckUsbPortSpeedUsedPsic (Xhc, ((State & =
XHC_PORTSC_PS) >> 10));=0D
+ if (PortStatus->PortStatus =3D=3D 0) {=0D
+ //=0D
+ // According to XHCI 1.1 spec November 2017,=0D
+ // bit 10~13 of the root port status register identifies the speed of =
the attached device.=0D
+ //=0D
+ switch ((State & XHC_PORTSC_PS) >> 10) {=0D
+ case 2:=0D
+ PortStatus->PortStatus |=3D USB_PORT_STAT_LOW_SPEED;=0D
+ break;=0D
=0D
- case 3:=0D
- PortStatus->PortStatus |=3D USB_PORT_STAT_HIGH_SPEED;=0D
- break;=0D
+ case 3:=0D
+ PortStatus->PortStatus |=3D USB_PORT_STAT_HIGH_SPEED;=0D
+ break;=0D
=0D
- case 4:=0D
- case 5:=0D
- PortStatus->PortStatus |=3D USB_PORT_STAT_SUPER_SPEED;=0D
- break;=0D
+ case 4:=0D
+ case 5:=0D
+ PortStatus->PortStatus |=3D USB_PORT_STAT_SUPER_SPEED;=0D
+ break;=0D
=0D
- default:=0D
- break;=0D
+ default:=0D
+ break;=0D
+ }=0D
}=0D
=0D
//=0D
@@ -1820,6 +1827,8 @@ XhcCreateUsbHc (
Xhc->ExtCapRegBase =3D ExtCapReg << 2;=0D
Xhc->UsbLegSupOffset =3D XhcGetCapabilityAddr (Xhc, XHC_CAP_USB_LEGACY=
);=0D
Xhc->DebugCapSupOffset =3D XhcGetCapabilityAddr (Xhc, XHC_CAP_USB_DEBUG)=
;=0D
+ Xhc->Usb2SupOffset =3D XhcGetUsbSupportedCapabilityAddr (Xhc, USB_SUPPOR=
T_PROTOCOL_USB2_MAJOR_VER);=0D
+ Xhc->UsbSsSupOffset =3D XhcGetUsbSupportedCapabilityAddr (Xhc, USB_SUPPO=
RT_PROTOCOL_USB3_MAJOR_VER);=0D
=0D
DEBUG ((DEBUG_INFO, "XhcCreateUsb3Hc: Capability length 0x%x\n", Xhc->Ca=
pLength));=0D
DEBUG ((DEBUG_INFO, "XhcCreateUsb3Hc: HcSParams1 0x%x\n", Xhc->HcSParams=
1));=0D
@@ -1829,6 +1838,8 @@ XhcCreateUsbHc (
DEBUG ((DEBUG_INFO, "XhcCreateUsb3Hc: RTSOff 0x%x\n", Xhc->RTSOff));=0D
DEBUG ((DEBUG_INFO, "XhcCreateUsb3Hc: UsbLegSupOffset 0x%x\n", Xhc->UsbL=
egSupOffset));=0D
DEBUG ((DEBUG_INFO, "XhcCreateUsb3Hc: DebugCapSupOffset 0x%x\n", Xhc->De=
bugCapSupOffset));=0D
+ DEBUG ((DEBUG_INFO, "XhcCreateUsb3Hc: Usb2SupOffset 0x%x\n", Xhc->Usb2Su=
pOffset));=0D
+ DEBUG ((DEBUG_INFO, "XhcCreateUsb3Hc: UsbSsSupOffset 0x%x\n", Xhc->UsbSs=
SupOffset));=0D
=0D
//=0D
// Create AsyncRequest Polling Timer=0D
diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h b/MdeModulePkg/Bus/Pci/Xhc=
iDxe/Xhci.h
index 5054d796b1..7eed7bd15e 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h
@@ -227,6 +227,8 @@ struct _USB_XHCI_INSTANCE {
UINT32 ExtCapRegBase;=0D
UINT32 UsbLegSupOffset;=0D
UINT32 DebugCapSupOffset;=0D
+ UINT32 Usb2SupOffset;=0D
+ UINT32 UsbSsSupOffset;=0D
UINT64 *DCBAA;=0D
VOID *DCBAAMap;=0D
UINT32 MaxSlotsEn;=0D
diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c b/MdeModulePkg/Bus/Pci/=
XhciDxe/XhciReg.c
index 80be3311d4..5bff698edb 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c
@@ -564,7 +564,57 @@ XhcGetCapabilityAddr (
if ((Data & 0xFF) =3D=3D CapId) {=0D
return ExtCapOffset;=0D
}=0D
+ //=0D
+ // If not, then traverse all of the ext capability registers till find=
ing out it.=0D
+ //=0D
+ NextExtCapReg =3D (UINT8)((Data >> 8) & 0xFF);=0D
+ ExtCapOffset +=3D (NextExtCapReg << 2);=0D
+ } while (NextExtCapReg !=3D 0);=0D
+=0D
+ return 0xFFFFFFFF;=0D
+}=0D
=0D
+/**=0D
+ Calculate the offset of the xHCI Supported Protocol Capability.=0D
+=0D
+ @param Xhc The XHCI Instance.=0D
+ @param MajorVersion The USB Major Version in xHCI Support Protocol Cap=
ability Field=0D
+=0D
+ @return The offset of xHCI Supported Protocol capability register.=0D
+=0D
+**/=0D
+UINT32=0D
+XhcGetUsbSupportedCapabilityAddr (=0D
+ IN USB_XHCI_INSTANCE *Xhc,=0D
+ IN UINT8 MajorVersion=0D
+ )=0D
+{=0D
+ UINT32 ExtCapOffset;=0D
+ UINT8 NextExtCapReg;=0D
+ UINT32 Data;=0D
+ UINT32 NameString;=0D
+ XHC_SUPPORTED_PROTOCOL_DW0 UsbSupportDw0;=0D
+=0D
+ if (Xhc =3D=3D NULL) {=0D
+ return 0;=0D
+ }=0D
+=0D
+ ExtCapOffset =3D 0;=0D
+=0D
+ do {=0D
+ //=0D
+ // Check if the extended capability register's capability id is USB Le=
gacy Support.=0D
+ //=0D
+ Data =3D XhcReadExtCapReg (Xhc, ExtCapOffset);=0D
+ UsbSupportDw0.Dword =3D Data;=0D
+ if ((Data & 0xFF) =3D=3D XHC_CAP_USB_SUPPORTED) {=0D
+ if (UsbSupportDw0.Data.RevMajor =3D=3D MajorVersion) {=0D
+ NameString =3D XhcReadExtCapReg (Xhc, ExtCapOffset + USB_SUPPORTED=
_NAME_STRING_OFFSET);=0D
+ if (NameString =3D=3D USB_SUPPORTED_PROTOCOL_NAME_STRING) {=0D
+ return ExtCapOffset;=0D
+ }=0D
+ }=0D
+ }=0D
//=0D
// If not, then traverse all of the ext capability registers till find=
ing out it.=0D
//=0D
@@ -575,6 +625,103 @@ XhcGetCapabilityAddr (
return 0xFFFFFFFF;=0D
}=0D
=0D
+/**=0D
+ Find SpeedField value match with Port Speed ID value.=0D
+=0D
+ @param Xhc The XHCI Instance.=0D
+ @param ExtCapOffset The USB Major Version in xHCI Support Protocol Cap=
ability Field=0D
+ @param SpeedField The Port Speed filed in USB PortSc register=0D
+=0D
+ @return The Protocol Speed ID xHCI Supported Protocol capability registe=
r.=0D
+=0D
+**/=0D
+UINT32=0D
+XhciPsivGetPsid (=0D
+ IN USB_XHCI_INSTANCE *Xhc,=0D
+ IN UINT32 ExtCapOffset,=0D
+ IN UINT8 SpeedField=0D
+ )=0D
+{=0D
+ XHC_SUPPORTED_PROTOCOL_DW2 PortId;=0D
+ XHC_SUPPORTED_PROTOCOL_FIELD Reg;=0D
+ UINT32 Count;=0D
+=0D
+ if ((Xhc =3D=3D NULL) || (ExtCapOffset =3D=3D 0xFFFFFFFF)) {=0D
+ return 0;=0D
+ }=0D
+=0D
+ //=0D
+ // According to XHCI 1.2 spec November 2019,=0D
+ // Section 7.2 xHCI Supported Protocol Capability=0D
+ // 1. Get the PSIC(Protocol Speed ID Count) Value.=0D
+ // 2. The PSID register boundary should be Base address + PSIC * 0x04=0D
+ //=0D
+ PortId.Dword =3D XhcReadExtCapReg (Xhc, ExtCapOffset + USB_SUPPORTED_PO=
RT_ID_OFFSET);=0D
+=0D
+ for (Count =3D 0; Count < PortId.Data.Psic; Count++) {=0D
+ Reg.Dword =3D XhcReadExtCapReg (Xhc, ExtCapOffset + USB_SUPPORT_SPEED_=
ID_OFFSET + (Count << 2));=0D
+ if (Reg.Data.Psiv =3D=3D SpeedField) {=0D
+ return Reg.Dword;=0D
+ }=0D
+ }=0D
+ return 0;=0D
+}=0D
+=0D
+/**=0D
+ Find SpeedField value match with Port Speed ID value.=0D
+=0D
+ @param Xhc The XHCI Instance.=0D
+ @param Speed The Port Speed filed in USB PortSc register=0D
+=0D
+ @return The USB Port Speed.=0D
+=0D
+**/=0D
+UINT16=0D
+XhcCheckUsbPortSpeedUsedPsic (=0D
+ IN USB_XHCI_INSTANCE *Xhc,=0D
+ IN UINT8 Speed=0D
+ )=0D
+{=0D
+ XHC_SUPPORTED_PROTOCOL_FIELD SpField;=0D
+ UINT16 ReturnSpeed;=0D
+=0D
+ if (Xhc =3D=3D NULL) {=0D
+ return 0;=0D
+ }=0D
+=0D
+ SpField.Dword =3D 0;=0D
+ ReturnSpeed =3D 0;=0D
+ //=0D
+ // Check USB3 Protocol Speed ID if ReturnSpeed didn't get match speed.=0D
+ //=0D
+ if ((ReturnSpeed =3D=3D 0) && (Xhc->UsbSsSupOffset !=3D 0xFFFFFFFF)) {=0D
+ SpField.Dword =3D XhciPsivGetPsid (Xhc, Xhc->UsbSsSupOffset, Speed);=0D
+ if (SpField.Dword !=3D 0) {=0D
+ // Super Speed=0D
+ ReturnSpeed =3D USB_PORT_STAT_SUPER_SPEED;=0D
+ }=0D
+ }=0D
+=0D
+ //=0D
+ // Check USB2 Protocol Speed ID if ReturnSpeed didn't get match speed.=0D
+ //=0D
+ if ((ReturnSpeed =3D=3D 0) && (Xhc->Usb2SupOffset !=3D 0xFFFFFFFF)) {=0D
+ SpField.Dword =3D XhciPsivGetPsid (Xhc, Xhc->Usb2SupOffset, Speed);=0D
+ if (SpField.Dword !=3D 0) {=0D
+ if (SpField.Data.Psie =3D=3D 2) {=0D
+ if (SpField.Data.Mantissa =3D=3D USB_SUPPORT_PROTOCOL_USB2_HIGH_SP=
EED_PSIM) {=0D
+ // High Speed=0D
+ ReturnSpeed =3D USB_PORT_STAT_HIGH_SPEED;=0D
+ }=0D
+ } else if (SpField.Data.Psie =3D=3D 1) {=0D
+ // Low speed=0D
+ ReturnSpeed =3D USB_PORT_STAT_LOW_SPEED;=0D
+ }=0D
+ }=0D
+ }=0D
+ return ReturnSpeed;=0D
+}=0D
+=0D
/**=0D
Whether the XHCI host controller is halted.=0D
=0D
diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.h b/MdeModulePkg/Bus/Pci/=
XhciDxe/XhciReg.h
index 4950eed272..4f83b49027 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.h
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.h
@@ -27,6 +27,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
=0D
#define XHC_CAP_USB_LEGACY 0x01=0D
#define XHC_CAP_USB_DEBUG 0x0A=0D
+#define XHC_CAP_USB_SUPPORTED 0x02=0D
=0D
// =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D//=0D
// XHCI register offset //=0D
@@ -74,6 +75,17 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#define USBLEGSP_BIOS_SEMAPHORE BIT16 // HC BIOS Owned Semaphor=
e=0D
#define USBLEGSP_OS_SEMAPHORE BIT24 // HC OS Owned Semaphore=
=0D
=0D
+//=0D
+// xHCI Supported Protocol Capability=0D
+//=0D
+#define USB_SUPPORTED_PROTOCOL_NAME_STRING 0x20425355=0D
+#define USB_SUPPORTED_NAME_STRING_OFFSET 0x04=0D
+#define USB_SUPPORTED_PORT_ID_OFFSET 0x08=0D
+#define USB_SUPPORT_SPEED_ID_OFFSET 0x10=0D
+#define USB_SUPPORT_PROTOCOL_USB2_MAJOR_VER 0x02=0D
+#define USB_SUPPORT_PROTOCOL_USB3_MAJOR_VER 0x03=0D
+#define USB_SUPPORT_PROTOCOL_USB2_HIGH_SPEED_PSIM 480=0D
+=0D
#pragma pack (1)=0D
typedef struct {=0D
UINT8 MaxSlots; // Number of Device Slots=0D
@@ -130,6 +142,52 @@ typedef union {
HCCPARAMS Data;=0D
} XHC_HCCPARAMS;=0D
=0D
+//=0D
+// xHCI Supported Protocol Cabability=0D
+//=0D
+typedef struct {=0D
+ UINT8 CapId;=0D
+ UINT8 NextExtCapReg;=0D
+ UINT8 RevMinor;=0D
+ UINT8 RevMajor;=0D
+} SUPP_PROTOCOL_DW0;=0D
+=0D
+typedef union {=0D
+ UINT32 Dword;=0D
+ SUPP_PROTOCOL_DW0 Data;=0D
+} XHC_SUPPORTED_PROTOCOL_DW0;=0D
+=0D
+typedef struct {=0D
+ UINT32 NameString;=0D
+} XHC_SUPPORTED_PROTOCOL_DW1;=0D
+=0D
+typedef struct {=0D
+ UINT8 CompPortOffset : 8;=0D
+ UINT8 CompPortCount : 8;=0D
+ UINT16 ProtocolDef :12;=0D
+ UINT16 Psic : 4;=0D
+} SUPP_PROTOCOL_DW2;=0D
+=0D
+typedef union {=0D
+ UINT32 Dword;=0D
+ SUPP_PROTOCOL_DW2 Data;=0D
+} XHC_SUPPORTED_PROTOCOL_DW2;=0D
+=0D
+typedef struct {=0D
+ UINT16 Psiv : 4;=0D
+ UINT16 Psie : 2;=0D
+ UINT16 Plt : 2;=0D
+ UINT16 Pfd : 1;=0D
+ UINT16 RsvdP : 5;=0D
+ UINT16 Lp : 2;=0D
+ UINT16 Mantissa :16;=0D
+} XHCI_PROTOCOL_FIELD;=0D
+=0D
+typedef union {=0D
+ UINT32 Dword;=0D
+ XHCI_PROTOCOL_FIELD Data;=0D
+} XHC_SUPPORTED_PROTOCOL_FIELD;=0D
+=0D
#pragma pack ()=0D
=0D
//=0D
@@ -546,4 +604,33 @@ XhcGetCapabilityAddr (
IN UINT8 CapId=0D
);=0D
=0D
+/**=0D
+ Calculate the offset of the xHCI Supported Protocol Capability.=0D
+=0D
+ @param Xhc The XHCI Instance.=0D
+ @param MajorVersion The USB Major Version in xHCI Support Protocol Cap=
ability Field=0D
+=0D
+ @return The offset of xHCI Supported Protocol capability register.=0D
+=0D
+**/=0D
+UINT32=0D
+XhcGetUsbSupportedCapabilityAddr (=0D
+ IN USB_XHCI_INSTANCE *Xhc,=0D
+ IN UINT8 MajorVersion=0D
+ );=0D
+=0D
+/**=0D
+ Find SpeedField value match with Port Speed ID value.=0D
+=0D
+ @param Xhc The XHCI Instance.=0D
+ @param Speed The Port Speed filed in USB PortSc register=0D
+=0D
+ @return The USB Port Speed.=0D
+=0D
+**/=0D
+UINT16=0D
+XhcCheckUsbPortSpeedUsedPsic (=0D
+ IN USB_XHCI_INSTANCE *Xhc,=0D
+ IN UINT8 Speed=0D
+ );=0D
#endif=0D
--=20
2.26.2.windows.1


Re: [PATCH] BaseTools: Fix dependency issue in PcdValueInit

Jake Garver
 

Hello maintainers,

Any interest in accepting this and the "BaseTools/Conf: Fix Dynamic-Library-File template" patch?

Thanks,
Jake


Re: [PATCH v4] OvmfPkg/BhyveBhfPkg: add support for QemuFwCfg

Corvin Köhne <c.koehne@...>
 

Hi,

does it require more review to get merged?


Best regards
Corvin

Beckhoff Automation GmbH & Co. KG | Managing Director: Dipl. Phys. Hans Beckhoff
Registered office: Verl, Germany | Register court: Guetersloh HRA 7075

-----Original Message-----
From: Corvin Köhne <C.Koehne@...>
Sent: Friday, April 8, 2022 10:15 AM
Cc: Corvin Köhne <C.Koehne@...>; Corvin Köhne <C.Koehne@...>; Ard Biesheuvel <ardb+tianocore@...>; Jordan Justen <jordan.l.justen@...>; devel@edk2.groups.io; FreeBSD Virtualization <freebsd-virtualization@...>; Jiewen Yao <jiewen.yao@...>; Gerd Hoffmann <kraxel@...>; Rebecca Cran <rebecca@...>; Peter Grehan <grehan@...>
Subject: [PATCH v4] OvmfPkg/BhyveBhfPkg: add support for QemuFwCfg

From: Corvin Köhne <CorvinK@...>

QemuFwCfg is much more powerful than BhyveFwCtl. Sadly, BhyveFwCtl
decided to use the same IO ports as QemuFwCfg. It's not possible to use
both interfaces simultaneously. So, prefer QemuFwCfg over BhyveFwCtl.

Signed-off-by: Corvin Köhne <c.koehne@...>
Acked-by: Gerd Hoffmann <kraxel@...>
Acked-by: Rebecca Cran <rebecca@...>
Acked-by: Peter Grehan <grehan@...>
Acked-by: Jiewen Yao <jiewen.yao@...>
CC: Ard Biesheuvel <ardb+tianocore@...>
CC: Jordan Justen <jordan.l.justen@...>
CC: devel@edk2.groups.io
CC: FreeBSD Virtualization <freebsd-virtualization@...>
---
OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf | 1 +
OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c | 41 ++++++++++++++++++++---
OvmfPkg/Bhyve/BhyveX64.dsc | 4 +--
3 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf b/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf
index 595fd055f9..94c65f32dc 100644
--- a/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf
+++ b/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf
@@ -43,6 +43,7 @@
MemoryAllocationLib
OrderedCollectionLib
PcdLib
+ QemuFwCfgLib
UefiBootServicesTableLib
UefiDriverEntryPoint
UefiLib
diff --git a/OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c b/OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c
index 8e80aa33e1..e216a21bfa 100644
--- a/OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c
+++ b/OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c
@@ -11,6 +11,41 @@
#include <Library/BaseMemoryLib.h>
#include <Library/BhyveFwCtlLib.h>
#include <Library/MemoryAllocationLib.h>
+#include <Library/QemuFwCfgLib.h> // QemuFwCfgFindFile()
+
+STATIC
+EFI_STATUS
+EFIAPI
+BhyveGetCpuCount (
+ OUT UINT32 *CpuCount
+ )
+{
+ FIRMWARE_CONFIG_ITEM Item;
+ UINTN Size;
+
+ if (QemuFwCfgIsAvailable ()) {
+ if (EFI_ERROR (QemuFwCfgFindFile ("opt/bhyve/hw.ncpu", &Item, &Size))) {
+ return EFI_NOT_FOUND;
+ } else if (Size != sizeof (*CpuCount)) {
+ return EFI_BAD_BUFFER_SIZE;
+ }
+
+ QemuFwCfgSelectItem (Item);
+ QemuFwCfgReadBytes (Size, CpuCount);
+
+ return EFI_SUCCESS;
+ }
+
+ //
+ // QemuFwCfg not available, try BhyveFwCtl.
+ //
+ Size = sizeof (*CpuCount);
+ if (BhyveFwCtlGet ("hw.ncpu", CpuCount, &Size) == RETURN_SUCCESS) {
+ return EFI_SUCCESS;
+ }
+
+ return EFI_UNSUPPORTED;
+}

STATIC
EFI_STATUS
@@ -23,7 +58,6 @@ BhyveInstallAcpiMadtTable (
)
{
UINT32 CpuCount;
- UINTN cSize;
UINTN NewBufferSize;
EFI_ACPI_1_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER *Madt;
EFI_ACPI_1_0_PROCESSOR_LOCAL_APIC_STRUCTURE *LocalApic;
@@ -36,9 +70,8 @@ BhyveInstallAcpiMadtTable (
ASSERT (AcpiTableBufferSize >= sizeof (EFI_ACPI_DESCRIPTION_HEADER));

// Query the host for the number of vCPUs
- CpuCount = 0;
- cSize = sizeof (CpuCount);
- if (BhyveFwCtlGet ("hw.ncpu", &CpuCount, &cSize) == RETURN_SUCCESS) {
+ Status = BhyveGetCpuCount (&CpuCount);
+ if (!EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "Retrieved CpuCount %d\n", CpuCount));
ASSERT (CpuCount >= 1);
} else {
diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc
index 5fa08bebd7..14070fd6dd 100644
--- a/OvmfPkg/Bhyve/BhyveX64.dsc
+++ b/OvmfPkg/Bhyve/BhyveX64.dsc
@@ -163,8 +163,7 @@
SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf
UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf
SerializeVariablesLib|OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.inf
- QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibNull.inf
- QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf
+ QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgDxeLib.inf
BhyveFwCtlLib|OvmfPkg/Library/BhyveFwCtlLib/BhyveFwCtlLib.inf
VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf
MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf
@@ -355,6 +354,7 @@
!endif
PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
MpInitLib|UefiCpuPkg/Library/MpInitLibUp/MpInitLibUp.inf
+ QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf

[LibraryClasses.common.UEFI_APPLICATION]
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
--
2.11.0

Beckhoff Automation GmbH & Co. KG | Managing Director: Dipl. Phys. Hans Beckhoff
Registered office: Verl, Germany | Register court: Guetersloh HRA 7075


Re: [PATCH v6 2/6] OvmfPkg/FdtPciHostBridgeLib: io range is not mandatory

Abner Chang
 

Thanks.

Reviewed-by: Abner Chang <abner.chang@...>

-----Original Message-----
From: Gerd Hoffmann <kraxel@...>
Sent: Monday, April 25, 2022 6:35 PM
To: devel@edk2.groups.io
Cc: Jiewen Yao <jiewen.yao@...>; Oliver Steffen
<osteffen@...>; Leif Lindholm <quic_llindhol@...>; Pawel
Polawski <ppolawsk@...>; Hao A Wu <hao.a.wu@...>;
Chang, Abner (HPS SW/FW Technologist) <abner.chang@...>; Liming
Gao <gaoliming@...>; Ray Ni <ray.ni@...>; Jordan Justen
<jordan.l.justen@...>; Jian J Wang <jian.j.wang@...>; Ard
Biesheuvel <ardb+tianocore@...>; Gerd Hoffmann
<kraxel@...>
Subject: [PATCH v6 2/6] OvmfPkg/FdtPciHostBridgeLib: io range is not
mandatory

io range is not mandatory according to pcie spec,
so allow host bridges without io address space.

Signed-off-by: Gerd Hoffmann <kraxel@...>
---
.../FdtPciHostBridgeLib/FdtPciHostBridgeLib.c | 45 ++++++++++---------
1 file changed, 23 insertions(+), 22 deletions(-)

diff --git a/OvmfPkg/Fdt/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
b/OvmfPkg/Fdt/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
index 98828e0b262b..14b41a533e96 100644
--- a/OvmfPkg/Fdt/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
+++ b/OvmfPkg/Fdt/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
@@ -292,13 +292,8 @@ ProcessPciHost (
}
}

- if ((*IoSize == 0) || (*Mmio32Size == 0)) {
- DEBUG ((
- DEBUG_ERROR,
- "%a: %a space empty\n",
- __FUNCTION__,
- (*IoSize == 0) ? "IO" : "MMIO32"
- ));
+ if (*Mmio32Size == 0) {
+ DEBUG ((DEBUG_ERROR, "%a: MMIO32 space empty\n",
__FUNCTION__));
return EFI_PROTOCOL_ERROR;
}

@@ -333,13 +328,15 @@ ProcessPciHost (
return Status;
}

- //
- // Map the MMIO window that provides I/O access - the PCI host bridge
code
- // is not aware of this translation and so it will only map the I/O view
- // in the GCD I/O map.
- //
- Status = MapGcdMmioSpace (*IoBase + IoTranslation, *IoSize);
- ASSERT_EFI_ERROR (Status);
+ if (*IoSize != 0) {
+ //
+ // Map the MMIO window that provides I/O access - the PCI host bridge
code
+ // is not aware of this translation and so it will only map the I/O view
+ // in the GCD I/O map.
+ //
+ Status = MapGcdMmioSpace (*IoBase + IoTranslation, *IoSize);
+ ASSERT_EFI_ERROR (Status);
+ }

return Status;
}
@@ -413,17 +410,21 @@ PciHostBridgeGetRootBridges (

AllocationAttributes = EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM;

- Io.Base = IoBase;
- Io.Limit = IoBase + IoSize - 1;
+ if (IoSize != 0) {
+ Io.Base = IoBase;
+ Io.Limit = IoBase + IoSize - 1;
+ } else {
+ Io.Base = MAX_UINT64;
+ Io.Limit = 0;
+ }
+
Mem.Base = Mmio32Base;
Mem.Limit = Mmio32Base + Mmio32Size - 1;

- if (sizeof (UINTN) == sizeof (UINT64)) {
- MemAbove4G.Base = Mmio64Base;
- MemAbove4G.Limit = Mmio64Base + Mmio64Size - 1;
- if (Mmio64Size > 0) {
- AllocationAttributes |= EFI_PCI_HOST_BRIDGE_MEM64_DECODE;
- }
+ if ((sizeof (UINTN) == sizeof (UINT64)) && (Mmio64Size != 0)) {
+ MemAbove4G.Base = Mmio64Base;
+ MemAbove4G.Limit = Mmio64Base + Mmio64Size - 1;
+ AllocationAttributes |= EFI_PCI_HOST_BRIDGE_MEM64_DECODE;
} else {
//
// UEFI mandates a 1:1 virtual-to-physical mapping, so on a 32-bit
--
2.35.1

5381 - 5400 of 94575