Re: [edk2-devel] [PATCH v3 07/20] SecurityPkg: RngDxe: Remove incorrect limitation on GetRng

2024-05-23 Thread Yao, Jiewen
Acked-by: Jiewe Yao 

BTW: This patch is already got RB from below people. I suggest you can put them 
in commit directly.

Reviewed-by: Pierre Gondois 
Reviewed-by: Ard Biesheuvel 

Thank you
Yao, Jiewen

> -Original Message-
> From: Flickdm 
> Sent: Friday, May 24, 2024 1:45 PM
> To: devel@edk2.groups.io
> Cc: Yao, Jiewen 
> Subject: [PATCH v3 07/20] SecurityPkg: RngDxe: Remove incorrect limitation on
> GetRng
> 
> Removed from gEfiRngAlgorithmRaw an incorrect assumption that
> Raw cannot return less than 256 bits. The DRNG Algorithms
> should always use a 256 bit seed as per nist standards
> however a caller is free to request less than 256 bits.
> >
> > //
> >// When a DRBG is used on the output of a entropy source,
> >// its security level must be at least 256 bits according to UEFI
> Spec.
> >//
> >if (RNGValueLength < 32) {
> >  return EFI_INVALID_PARAMETER;
> >}
> >
> 
> AARCH64 platforms do not have this limitation and this brings both
> implementations into alignment with each other and the spec.
> 
> Cc: Jiewen Yao 
> 
> Signed-off-by: Doug Flick [MSFT] 
> Reviewed-by: Ard Biesheuvel 
> ---
>  SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c | 8 
>  1 file changed, 8 deletions(-)
> 
> diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c
> b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c
> index 7e06e16e4b..5723ed6957 100644
> --- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c
> +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c
> @@ -116,14 +116,6 @@ RngGetRNG (
>// The "raw" algorithm is intended to provide entropy directly
> 
>//
> 
>if (CompareGuid (RNGAlgorithm, )) {
> 
> -//
> 
> -// When a DRBG is used on the output of a entropy source,
> 
> -// its security level must be at least 256 bits according to UEFI Spec.
> 
> -//
> 
> -if (RNGValueLength < 32) {
> 
> -  return EFI_INVALID_PARAMETER;
> 
> -}
> 
> -
> 
>  Status = GenerateEntropy (RNGValueLength, RNGValue);
> 
>  return Status;
> 
>}
> 
> --
> 2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119246): https://edk2.groups.io/g/devel/message/119246
Mute This Topic: https://groups.io/mt/106276859/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 17/20] ArmVirtPkg/ArmVirtQemu: Permit the use of dynamic PCDs in PEI

2024-05-23 Thread Doug Flick via groups.io
From: Ard Biesheuvel 

Currently, only TPM2 builds enable the PCD PEIM, which is a prerequisite
for being able to use dynamic PCDs already at the PEI stage. This
facility will be used for other reasons too so move those pieces out of
code block that are conditional on TPM2_ENABLE

Cc: Ard Biesheuvel 
Cc: Leif Lindholm 
Cc: Sami Mujawar 
Cc: Gerd Hoffmann 

Committed-by: Ard Biesheuvel 
Signed-off-by: Doug Flick [MSFT] 
---
 ArmVirtPkg/ArmVirtQemu.dsc | 6 +-
 ArmVirtPkg/ArmVirtQemu.fdf | 2 +-
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
index 1d3315ad3e..4498ca58a8 100644
--- a/ArmVirtPkg/ArmVirtQemu.dsc
+++ b/ArmVirtPkg/ArmVirtQemu.dsc
@@ -318,11 +318,7 @@
   
gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|L"Timeout"|gEfiGlobalVariableGuid|0x0|5
 
 [LibraryClasses.common.PEI_CORE, LibraryClasses.common.PEIM]
-!if $(TPM2_ENABLE) == TRUE
   PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf
-!else
-  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
-!endif
 
 

 #
@@ -339,11 +335,11 @@
   ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf
   ArmPkg/Drivers/CpuPei/CpuPei.inf
 
-!if $(TPM2_ENABLE) == TRUE
   MdeModulePkg/Universal/PCD/Pei/Pcd.inf {
 
   PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
   }
+!if $(TPM2_ENABLE) == TRUE
   MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf {
 
   
ResetSystemLib|ArmVirtPkg/Library/ArmVirtPsciResetSystemPeiLib/ArmVirtPsciResetSystemPeiLib.inf
diff --git a/ArmVirtPkg/ArmVirtQemu.fdf b/ArmVirtPkg/ArmVirtQemu.fdf
index 764f652afd..6073a31970 100644
--- a/ArmVirtPkg/ArmVirtQemu.fdf
+++ b/ArmVirtPkg/ArmVirtQemu.fdf
@@ -111,8 +111,8 @@ READ_LOCK_STATUS   = TRUE
   INF ArmPkg/Drivers/CpuPei/CpuPei.inf
   INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
 
-!if $(TPM2_ENABLE) == TRUE
   INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf
+!if $(TPM2_ENABLE) == TRUE
   INF MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf
   INF OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf
   INF SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119244): https://edk2.groups.io/g/devel/message/119244
Mute This Topic: https://groups.io/mt/106276869/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 18/20] ArmVirtPkg: Use dynamic PCD to set the SMCCC conduit

2024-05-23 Thread Doug Flick via groups.io
From: Ard Biesheuvel 

On ARM systems, whether SMC or HVC instructions need to be used to issue
monitor calls is typically dependent on the exception level, but there
are also cases where EL1 might use SMC instructions, so there is no hard
and fast rule.

For ArmVirtQemu, this does depend strictly on the exception level, so
set the default to HVC (for EL1 execution) and override it to SMC when
booted at EL2.

Cc: Ard Biesheuvel 
Cc: Leif Lindholm 
Cc: Sami Mujawar 
Cc: Gerd Hoffmann 

Committed-by: Ard Biesheuvel 
Signed-off-by: Doug Flick [MSFT] 
---
 ArmVirtPkg/ArmVirtCloudHv.dsc|  3 +++
 ArmVirtPkg/ArmVirtQemu.dsc   |  4 
 ArmVirtPkg/ArmVirtQemuKernel.dsc |  2 ++
 ArmVirtPkg/ArmVirtXen.dsc|  2 ++
 ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf |  1 +
 ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c   | 14 ++
 6 files changed, 26 insertions(+)

diff --git a/ArmVirtPkg/ArmVirtCloudHv.dsc b/ArmVirtPkg/ArmVirtCloudHv.dsc
index 5cb2a609b1..d5055a0341 100644
--- a/ArmVirtPkg/ArmVirtCloudHv.dsc
+++ b/ArmVirtPkg/ArmVirtCloudHv.dsc
@@ -201,6 +201,9 @@
 [PcdsDynamicHii]
   
gUefiOvmfPkgTokenSpaceGuid.PcdForceNoAcpi|L"ForceNoAcpi"|gOvmfVariableGuid|0x0|FALSE|NV,BS
 
+[PcdsPatchableInModule.common]
+  gArmTokenSpaceGuid.PcdMonitorConduitHvc|TRUE
+
 

 #
 # Components Section - list of all EDK II Modules needed by this Platform
diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
index 4498ca58a8..80dd4fbb14 100644
--- a/ArmVirtPkg/ArmVirtQemu.dsc
+++ b/ArmVirtPkg/ArmVirtQemu.dsc
@@ -293,6 +293,10 @@
   gEfiNetworkPkgTokenSpaceGuid.PcdIPv4PXESupport|0x01
   gEfiNetworkPkgTokenSpaceGuid.PcdIPv6PXESupport|0x01
 
+  # whether to use HVC or SMC to issue monitor calls - this typically depends
+  # on the exception level at which the UEFI system firmware executes
+  gArmTokenSpaceGuid.PcdMonitorConduitHvc|TRUE
+
   #
   # TPM2 support
   #
diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKernel.dsc
index 94f48593c2..2700b97d09 100644
--- a/ArmVirtPkg/ArmVirtQemuKernel.dsc
+++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc
@@ -203,6 +203,8 @@
   gArmTokenSpaceGuid.PcdFdBaseAddress|0x0
   gArmTokenSpaceGuid.PcdFvBaseAddress|0x0
 
+  gArmTokenSpaceGuid.PcdMonitorConduitHvc|TRUE
+
 [PcdsDynamicDefault.common]
   gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|3
 
diff --git a/ArmVirtPkg/ArmVirtXen.dsc b/ArmVirtPkg/ArmVirtXen.dsc
index 5809832e66..ceb37f8a2d 100644
--- a/ArmVirtPkg/ArmVirtXen.dsc
+++ b/ArmVirtPkg/ArmVirtXen.dsc
@@ -120,6 +120,8 @@
   gArmTokenSpaceGuid.PcdFdBaseAddress|0x0
   gArmTokenSpaceGuid.PcdFvBaseAddress|0x0
 
+  gArmTokenSpaceGuid.PcdMonitorConduitHvc|TRUE
+
 [PcdsDynamicDefault.common]
 
   gArmTokenSpaceGuid.PcdArmArchTimerSecIntrNum|0x0
diff --git a/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf 
b/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf
index e9a34b6e2e..a38b89c103 100644
--- a/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf
+++ b/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf
@@ -45,6 +45,7 @@
 
 [Pcd]
   gArmTokenSpaceGuid.PcdFvBaseAddress
+  gArmTokenSpaceGuid.PcdMonitorConduitHvc
   gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress ## 
SOMETIMES_PRODUCES
   gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress
 
diff --git a/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c 
b/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c
index 7ab4aa2d6b..b8e9208301 100644
--- a/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c
+++ b/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c
@@ -18,6 +18,8 @@
 #include 
 #include 
 
+#include 
+
 #include 
 #include 
 
@@ -224,5 +226,17 @@ PlatformPeim (
 
   BuildFvHob (PcdGet64 (PcdFvBaseAddress), PcdGet32 (PcdFvSize));
 
+ #ifdef MDE_CPU_AARCH64
+  //
+  // Set the SMCCC conduit to SMC if executing at EL2, which is typically the
+  // exception level that services HVCs rather than the one that invokes them.
+  //
+  if (ArmReadCurrentEL () == AARCH64_EL2) {
+Status = PcdSetBoolS (PcdMonitorConduitHvc, FALSE);
+ASSERT_EFI_ERROR (Status);
+  }
+
+ #endif
+
   return EFI_SUCCESS;
 }
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119245): https://edk2.groups.io/g/devel/message/119245
Mute This Topic: https://groups.io/mt/106276870/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 16/20] MdePkg/BaseRngLib AARCH64: Remove overzealous ASSERT()

2024-05-23 Thread Doug Flick via groups.io
From: Ard Biesheuvel 

BaseRngLib on AARCH64 will discover whether or not RNDR instructions are
supported, by inspecting the ISAR0 identification register, and setting
a global boolean accordingly. This boolean is used in subsequent
execution to decide whether or not to issue the instruction.

The same discovery code also ASSERT()s that RNDR instructions are
implemented, which is unnecessary, and breaks execution on systems that
incorporate the library but don't implement the instruction (or fail to
expose it to the exception level that the firmware executes at).

So drop the ASSERT().

Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Zhiguang Liu 

Committed-by: Ard Biesheuvel 
Signed-off-by: Doug Flick [MSFT] 
---
 MdePkg/Library/BaseRngLib/AArch64/Rndr.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/MdePkg/Library/BaseRngLib/AArch64/Rndr.c 
b/MdePkg/Library/BaseRngLib/AArch64/Rndr.c
index d39db62153..3a556a2e3f 100644
--- a/MdePkg/Library/BaseRngLib/AArch64/Rndr.c
+++ b/MdePkg/Library/BaseRngLib/AArch64/Rndr.c
@@ -50,7 +50,6 @@ BaseRngLibConstructor (
   // MSR. A non-zero value indicates that the processor supports the RNDR 
instruction.
   //
   Isar0 = ArmReadIdIsar0 ();
-  ASSERT ((Isar0 & RNDR_MASK) != 0);
 
   mRndrSupported = ((Isar0 & RNDR_MASK) != 0);
 
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119243): https://edk2.groups.io/g/devel/message/119243
Mute This Topic: https://groups.io/mt/106276868/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 15/20] ArmVirtPkg: Move PcdMonitorConduitHvc

2024-05-23 Thread Doug Flick via groups.io
This moves the PcdMonitorConduitHvc from PcdsFeatureFlag.Common to
PcdsFixedAtBuild.Common

This is a follow on to the previous commit:
ArmPkg: Allow SMC/HVC monitor conduit to be specified at runtime

ArmVirtQemu may execute at EL2, in which case monitor calls are
generally made using SMC instructions instead of HVC instructions.

Whether or not this is the case can only be decided at runtime, and so
the associated PCD needs to be settable at runtime, if the platform
definition chooses so. This implies a boolean PCD, given that a feature
PCD is build-time configurable only.

Cc: Leif Lindholm 
Cc: Ard Biesheuvel 
Cc: Sami Mujawar 

Signed-off-by: Doug Flick [MSFT] 
---
 ArmVirtPkg/ArmVirtKvmTool.dsc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ArmVirtPkg/ArmVirtKvmTool.dsc b/ArmVirtPkg/ArmVirtKvmTool.dsc
index 20da331966..ae0dd1497f 100644
--- a/ArmVirtPkg/ArmVirtKvmTool.dsc
+++ b/ArmVirtPkg/ArmVirtKvmTool.dsc
@@ -126,8 +126,6 @@
   # Use MMIO for accessing RTC controller registers.
   gPcAtChipsetPkgTokenSpaceGuid.PcdRtcUseMmio|TRUE
 
-  gArmTokenSpaceGuid.PcdMonitorConduitHvc|TRUE
-
 [PcdsFixedAtBuild.common]
   gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x800F
 
@@ -167,6 +165,8 @@
   #
   gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize|16
 
+  gArmTokenSpaceGuid.PcdMonitorConduitHvc|TRUE
+
 [PcdsPatchableInModule.common]
   #
   # This will be overridden in the code
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119242): https://edk2.groups.io/g/devel/message/119242
Mute This Topic: https://groups.io/mt/106276867/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 12/20] MdePkg: Add MockHash2 Protocol for testing

2024-05-23 Thread Doug Flick via groups.io
From: Doug Flick 

This commit adds a new MockHash2 protocol to the MdePkg. This allows
the unit tests to pick up the new protocol and use it for testing.

Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Zhiguang Liu 

Signed-off-by: Doug Flick [MSFT] 
---
 MdePkg/Test/Mock/Include/GoogleTest/Protocol/MockHash2.h   | 67 

 MdePkg/Test/Mock/Library/GoogleTest/Protocol/MockHash2.cpp | 27 
 2 files changed, 94 insertions(+)

diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Protocol/MockHash2.h 
b/MdePkg/Test/Mock/Include/GoogleTest/Protocol/MockHash2.h
new file mode 100644
index 00..b44d341332
--- /dev/null
+++ b/MdePkg/Test/Mock/Include/GoogleTest/Protocol/MockHash2.h
@@ -0,0 +1,67 @@
+/** @file
+  This file declares a mock of Hash2 Protocol.
+
+  Copyright (c) Microsoft Corporation.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef MOCK_HASH2_H_
+#define MOCK_HASH2_H_
+
+#include 
+#include 
+
+extern "C" {
+  #include 
+  #include 
+}
+
+struct MockHash2 {
+  MOCK_INTERFACE_DECLARATION (MockHash2);
+
+  MOCK_FUNCTION_DECLARATION (
+EFI_STATUS,
+GetHashSize,
+(IN CONST EFI_HASH2_PROTOCOL  *This,
+ IN CONST EFI_GUID*HashAlgorithm,
+ OUT UINTN*HashSize)
+);
+
+  MOCK_FUNCTION_DECLARATION (
+EFI_STATUS,
+Hash,
+(IN CONST EFI_HASH2_PROTOCOL  *This,
+ IN CONST EFI_GUID*HashAlgorithm,
+ IN CONST UINT8   *Message,
+ IN UINTN MessageSize,
+ IN OUT EFI_HASH2_OUTPUT  *Hash)
+);
+
+  MOCK_FUNCTION_DECLARATION (
+EFI_STATUS,
+HashInit,
+(IN CONST EFI_HASH2_PROTOCOL  *This,
+ IN CONST EFI_GUID*HashAlgorithm)
+);
+
+  MOCK_FUNCTION_DECLARATION (
+EFI_STATUS,
+HashUpdate,
+(IN CONST EFI_HASH2_PROTOCOL  *This,
+ IN CONST UINT8   *Message,
+ IN UINTN MessageSize)
+);
+
+  MOCK_FUNCTION_DECLARATION (
+EFI_STATUS,
+HashFinal,
+(IN CONST EFI_HASH2_PROTOCOL  *This,
+ IN OUT EFI_HASH2_OUTPUT  *Hash)
+);
+};
+
+extern "C" {
+  extern EFI_HASH2_PROTOCOL  *gHash2Protocol;
+}
+
+#endif // MOCK_HASH2_H_
diff --git a/MdePkg/Test/Mock/Library/GoogleTest/Protocol/MockHash2.cpp 
b/MdePkg/Test/Mock/Library/GoogleTest/Protocol/MockHash2.cpp
new file mode 100644
index 00..5cf94c43b4
--- /dev/null
+++ b/MdePkg/Test/Mock/Library/GoogleTest/Protocol/MockHash2.cpp
@@ -0,0 +1,27 @@
+/** @file MockHash2.cpp
+  Google Test mock for Hash2 Protocol
+
+  Copyright (c) Microsoft Corporation.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include 
+
+MOCK_INTERFACE_DEFINITION (MockHash2);
+MOCK_FUNCTION_DEFINITION (MockHash2, GetHashSize, 3, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHash2, Hash, 5, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHash2, HashInit, 2, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHash2, HashUpdate, 3, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHash2, HashFinal, 2, EFIAPI);
+
+EFI_HASH2_PROTOCOL  HASH2_PROTOCOL_INSTANCE = {
+  GetHashSize, // EFI_HASH2_GET_HASH_SIZE
+  Hash,// EFI_HASH2_HASH
+  HashInit,// EFI_HASH2_HASH_INIT
+  HashUpdate,  // EFI_HASH2_HASH_UPDATE
+  HashFinal// EFI_HASH2_HASH_FINAL
+};
+
+extern "C" {
+  EFI_HASH2_PROTOCOL  *gHash2Protocol = _PROTOCOL_INSTANCE;
+}
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119239): https://edk2.groups.io/g/devel/message/119239
Mute This Topic: https://groups.io/mt/106276864/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 14/20] ArmPkg: Allow SMC/HVC monitor conduit to be specified at runtime

2024-05-23 Thread Doug Flick via groups.io
From: Ard Biesheuvel 

ArmVirtQemu may execute at EL2, in which case monitor calls are
generally made using SMC instructions instead of HVC instructions.

Whether or not this is the case can only be decided at runtime, and so
the associated PCD needs to be settable at runtime, if the platform
definition chooses so. This implies a boolean PCD, given that a feature
PCD is build-time configurable only.

Cc: Leif Lindholm 
Cc: Ard Biesheuvel 
Cc: Sami Mujawar 

Committed-by: Ard Biesheuvel 
Signed-off-by: Doug Flick [MSFT] 
---
 ArmPkg/ArmPkg.dec| 10 +-
 ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.c |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/ArmPkg/ArmPkg.dec b/ArmPkg/ArmPkg.dec
index 7fe2b9bca4..ac030e295b 100644
--- a/ArmPkg/ArmPkg.dec
+++ b/ArmPkg/ArmPkg.dec
@@ -139,11 +139,6 @@
   # Define if the GICv3 controller should use the GICv2 legacy
   gArmTokenSpaceGuid.PcdArmGicV3WithV2Legacy|FALSE|BOOLEAN|0x0042
 
-  ## Define the conduit to use for monitor calls.
-  # Default PcdMonitorConduitHvc = FALSE, conduit = SMC
-  # If PcdMonitorConduitHvc = TRUE, conduit = HVC
-  gArmTokenSpaceGuid.PcdMonitorConduitHvc|FALSE|BOOLEAN|0x0047
-
   # Whether to remap all unused memory NX before installing the CPU arch
   # protocol driver. This is needed on platforms that map all DRAM with RWX
   # attributes initially, and can be disabled otherwise.
@@ -317,6 +312,11 @@
   gArmTokenSpaceGuid.PcdSystemBiosRelease|0x|UINT16|0x3058
   
gArmTokenSpaceGuid.PcdEmbeddedControllerFirmwareRelease|0x|UINT16|0x3059
 
+  ## Define the conduit to use for monitor calls.
+  # Default PcdMonitorConduitHvc = FALSE, conduit = SMC
+  # If PcdMonitorConduitHvc = TRUE, conduit = HVC
+  gArmTokenSpaceGuid.PcdMonitorConduitHvc|FALSE|BOOLEAN|0x0047
+
 [PcdsFixedAtBuild.common, PcdsDynamic.common]
   #
   # ARM Architectural Timer
diff --git a/ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.c 
b/ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.c
index 741f5c6157..ec5b0b6619 100644
--- a/ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.c
+++ b/ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.c
@@ -26,7 +26,7 @@ ArmMonitorCall (
   IN OUT ARM_MONITOR_ARGS  *Args
   )
 {
-  if (FeaturePcdGet (PcdMonitorConduitHvc)) {
+  if (PcdGetBool (PcdMonitorConduitHvc)) {
 ArmCallHvc ((ARM_HVC_ARGS *)Args);
   } else {
 ArmCallSmc ((ARM_SMC_ARGS *)Args);
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119241): https://edk2.groups.io/g/devel/message/119241
Mute This Topic: https://groups.io/mt/106276866/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 13/20] NetworkPkg: Update the PxeBcDhcp6GoogleTest due to underlying changes

2024-05-23 Thread Doug Flick via groups.io
From: Doug Flick 

This patch updates the PxeBcDhcp6GoogleTest due to the changes in the
underlying code. The changes are as follows:
 - Random now comes from the RngLib Protocol
 - The TCP ISN is now generated by the hash function

Cc: Saloni Kasbekar 
Cc: Zachary Clark-williams 

Signed-off-by: Doug Flick [MSFT] 
---
 NetworkPkg/Test/NetworkPkgHostTest.dsc|   1 +
 NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf |   3 +-
 NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp   | 102 
+++-
 3 files changed, 100 insertions(+), 6 deletions(-)

diff --git a/NetworkPkg/Test/NetworkPkgHostTest.dsc 
b/NetworkPkg/Test/NetworkPkgHostTest.dsc
index fa301a7a52..1772afb058 100644
--- a/NetworkPkg/Test/NetworkPkgHostTest.dsc
+++ b/NetworkPkg/Test/NetworkPkgHostTest.dsc
@@ -30,6 +30,7 @@
   NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf {
 
   
UefiRuntimeServicesTableLib|MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib/MockUefiRuntimeServicesTableLib.inf
+  
UefiBootServicesTableLib|MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.inf
   }
 
 # Despite these library classes being listed in [LibraryClasses] below, they 
are not needed for the host-based unit tests.
diff --git a/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf 
b/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf
index 301dcdf611..8b092d9291 100644
--- a/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf
+++ b/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf
@@ -14,7 +14,7 @@ VERSION_STRING = 1.0
 #
 # The following information is for reference only and not required by the 
build tools.
 #
-#  VALID_ARCHITECTURES   = IA32 X64
+#  VALID_ARCHITECTURES   = IA32 X64 AARCH64
 #
 
 [Sources]
@@ -23,6 +23,7 @@ VERSION_STRING = 1.0
   PxeBcDhcp6GoogleTest.h
   ../PxeBcDhcp6.c
   ../PxeBcSupport.c
+  ../../../MdePkg/Test/Mock/Library/GoogleTest/Protocol/MockRng.cpp
 
 [Packages]
   MdePkg/MdePkg.dec
diff --git a/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp 
b/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp
index bd423ebadf..61736ff79e 100644
--- a/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp
+++ b/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp
@@ -7,6 +7,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 extern "C" {
   #include 
@@ -165,7 +167,7 @@ protected:
 // Note:
 // Testing PxeBcHandleDhcp6Offer() is difficult because it depends on a
 // properly setup Private structure. Attempting to properly test this function
-// without a signficant refactor is a fools errand. Instead, we will test
+// without a significant refactor is a fools errand. Instead, we will test
 // that we can prevent an overflow in the function.
 TEST_F (PxeBcHandleDhcp6OfferTest, BasicUsageTest) {
   PXEBC_DHCP6_PACKET_CACHE  *Cache6 = NULL;
@@ -238,6 +240,7 @@ TEST_F (PxeBcCacheDnsServerAddressesTest, BasicUsageTest) {
 FreePool (Option);
   }
 }
+
 // Test Description
 // Test that we can prevent an overflow in the function
 TEST_F (PxeBcCacheDnsServerAddressesTest, AttemptOverflowTest) {
@@ -470,10 +473,15 @@ TEST_F (PxeBcRequestBootServiceTest, 
AttemptRequestOverFlowExpectFailure) {
 class PxeBcDhcp6DiscoverTest : public ::testing::Test {
 public:
   PXEBC_PRIVATE_DATA Private = { 0 };
+  // create a mock md5 hash
+  UINT8 Md5Hash[16] = { 0 };
+
   EFI_UDP6_PROTOCOL Udp6Read;
 
 protected:
   MockUefiRuntimeServicesTableLib RtServicesMock;
+  MockUefiBootServicesTableLib BsMock;
+  MockRng RngMock;
 
   // Add any setup code if needed
   virtual void
@@ -527,8 +535,21 @@ TEST_F (PxeBcDhcp6DiscoverTest, BasicOverflowTest) {
 
   Private.Dhcp6Request->Length = (UINT16)(Cursor - (UINT8 
*)Private.Dhcp6Request);
 
-  EXPECT_CALL (RtServicesMock, gRT_GetTime)
-.WillOnce (::testing::Return (0));
+  EXPECT_CALL (BsMock, gBS_LocateProtocol)
+.WillOnce (
+   ::testing::DoAll (
+::testing::SetArgPointee<2> (::testing::ByRef 
(gRngProtocol)),
+::testing::Return (EFI_SUCCESS)
+)
+   );
+
+  EXPECT_CALL (RngMock, GetRng)
+.WillOnce (
+   ::testing::DoAll (
+::testing::SetArgPointee<3> (::testing::ByRef 
(Md5Hash[0])),
+::testing::Return (EFI_SUCCESS)
+)
+   );
 
   ASSERT_EQ (
 PxeBcDhcp6Discover (
@@ -558,8 +579,21 @@ TEST_F (PxeBcDhcp6DiscoverTest, BasicUsageTest) {
 
   Private.Dhcp6Request->Length = (UINT16)(Cursor - (UINT8 
*)Private.Dhcp6Request);
 
-  EXPECT_CALL (RtServicesMock, gRT_GetTime)
-.WillOnce (::testing::Return (0));
+  EXPECT_CALL (BsMock, gBS_LocateProtocol)
+.WillOnce (
+   ::testing::DoAll (
+::testing::SetArgPointee<2> (::testing::ByRef 
(gRngProtocol)),
+::testing::Return (EFI_SUCCESS)
+   

[edk2-devel] [PATCH v3 10/20] MdePkg: : Add MockUefiBootServicesTableLib

2024-05-23 Thread Doug Flick via groups.io
From: Doug Flick 

This commit adds a mock library for UefiBootServicesTableLib.

Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Zhiguang Liu 

Signed-off-by: Doug Flick [MSFT] 
---
 MdePkg/Test/MdePkgHostTest.dsc 
   |  1 +
 
MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.inf
 | 32 
 MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiBootServicesTableLib.h 
   | 78 
 
MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.cpp
 | 69 +
 4 files changed, 180 insertions(+)

diff --git a/MdePkg/Test/MdePkgHostTest.dsc b/MdePkg/Test/MdePkgHostTest.dsc
index e36b7c..6a85d02236 100644
--- a/MdePkg/Test/MdePkgHostTest.dsc
+++ b/MdePkg/Test/MdePkgHostTest.dsc
@@ -43,6 +43,7 @@
   MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf
   MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUefiLib.inf
   
MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib/MockUefiRuntimeServicesTableLib.inf
+  
MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.inf
   MdePkg/Test/Mock/Library/GoogleTest/MockPeiServicesLib/MockPeiServicesLib.inf
   MdePkg/Test/Mock/Library/GoogleTest/MockHobLib/MockHobLib.inf
   MdePkg/Test/Mock/Library/GoogleTest/MockFdtLib/MockFdtLib.inf
diff --git 
a/MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.inf
 
b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.inf
new file mode 100644
index 00..8b64fd195a
--- /dev/null
+++ 
b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.inf
@@ -0,0 +1,32 @@
+## @file
+#  Mock implementation of the UEFI Boot Services Table Library.
+#
+#  Copyright (c) Microsoft Corporation.
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION= 0x00010005
+  BASE_NAME  = MockUefiBootServicesTableLib
+  FILE_GUID  = 67EA4614-E276-49EC-9AE6-B97ACCEA676E
+  MODULE_TYPE= HOST_APPLICATION
+  VERSION_STRING = 1.0
+  LIBRARY_CLASS  = UefiBootServicesTableLib|HOST_APPLICATION
+
+#
+#  VALID_ARCHITECTURES   = IA32 X64 EBC
+#
+
+[Sources]
+  MockUefiBootServicesTableLib.cpp
+
+[LibraryClasses]
+  GoogleTestLib
+
+[Packages]
+  MdePkg/MdePkg.dec
+  UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
+
+[BuildOptions]
+  MSFT:*_*_*_CC_FLAGS = /EHsc
diff --git 
a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiBootServicesTableLib.h 
b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiBootServicesTableLib.h
new file mode 100644
index 00..d72b941323
--- /dev/null
+++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiBootServicesTableLib.h
@@ -0,0 +1,78 @@
+/** @file
+  Google Test mocks for UefiBootServicesTableLib
+
+  Copyright (c) Microsoft Corporation.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef MOCK_UEFI_BOOT_SERVICES_TABLE_LIB_H_
+#define MOCK_UEFI_BOOT_SERVICES_TABLE_LIB_H_
+
+#include 
+#include 
+extern "C" {
+  #include 
+  #include 
+}
+
+//
+// Declarations to handle usage of the UefiBootServiceTableLib by creating mock
+//
+struct MockUefiBootServicesTableLib {
+  MOCK_INTERFACE_DECLARATION (MockUefiBootServicesTableLib);
+
+  MOCK_FUNCTION_DECLARATION (
+EFI_STATUS,
+gBS_GetMemoryMap,
+(IN OUT UINTN *MemoryMapSize,
+ OUTEFI_MEMORY_DESCRIPTOR *MemoryMap,
+ OUTUINTN *MapKey,
+ OUTUINTN *DescriptorSize,
+ OUTUINT32*DescriptorVersion)
+);
+
+  MOCK_FUNCTION_DECLARATION (
+EFI_STATUS,
+gBS_CreateEvent,
+(IN  UINT32   Type,
+ IN  EFI_TPL  NotifyTpl,
+ IN  EFI_EVENT_NOTIFY NotifyFunction,
+ IN  VOID *NotifyContext,
+ OUT EFI_EVENT*Event)
+);
+
+  MOCK_FUNCTION_DECLARATION (
+EFI_STATUS,
+gBS_CloseEvent,
+(IN EFI_EVENT Event)
+);
+
+  MOCK_FUNCTION_DECLARATION (
+EFI_STATUS,
+gBS_HandleProtocol,
+(IN  EFI_HANDLE Handle,
+ IN  EFI_GUID   *Protocol,
+ OUT VOID   **Interface)
+);
+
+  MOCK_FUNCTION_DECLARATION (
+EFI_STATUS,
+gBS_LocateProtocol,
+(IN  EFI_GUID *Protocol,
+ IN  VOID  *Registration  OPTIONAL,
+ OUT VOID  **Interface)
+);
+
+  MOCK_FUNCTION_DECLARATION (
+EFI_STATUS,
+gBS_CreateEventEx,
+(IN UINT32Type,
+ IN EFI_TPL   NotifyTpl,
+ IN EFI_EVENT_NOTIFY  NotifyFunction OPTIONAL,
+ IN CONST VOID*NotifyContext OPTIONAL,
+ IN CONST EFI_GUID*EventGroup OPTIONAL,
+ OUT EFI_EVENT*Event)
+);
+};
+
+#endif // MOCK_UEFI_BOOT_SERVICES_TABLE_LIB_H_
diff --git 

[edk2-devel] [PATCH v3 09/20] NetworkPkg: TcpDxe: SECURITY PATCH CVE-2023-45236

2024-05-23 Thread Doug Flick via groups.io
From: Doug Flick 

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4541
REF: https://www.rfc-editor.org/rfc/rfc1948.txt
REF: https://www.rfc-editor.org/rfc/rfc6528.txt
REF: https://www.rfc-editor.org/rfc/rfc9293.txt

Bug Overview:
PixieFail Bug #8
CVE-2023-45236
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:L/I:N/A:N
CWE-200 Exposure of Sensitive Information to an Unauthorized Actor

Updates TCP ISN generation to use a cryptographic hash of the
connection's identifying parameters and a secret key.
This prevents an attacker from guessing the ISN used for some other
connection.

This is follows the guidance in RFC 1948, RFC 6528, and RFC 9293.

RFC: 9293 Section 3.4.1.  Initial Sequence Number Selection

   A TCP implementation MUST use the above type of "clock" for clock-
   driven selection of initial sequence numbers (MUST-8), and SHOULD
   generate its initial sequence numbers with the expression:

   ISN = M + F(localip, localport, remoteip, remoteport, secretkey)

   where M is the 4 microsecond timer, and F() is a pseudorandom
   function (PRF) of the connection's identifying parameters ("localip,
   localport, remoteip, remoteport") and a secret key ("secretkey")
   (SHLD-1).  F() MUST NOT be computable from the outside (MUST-9), or
   an attacker could still guess at sequence numbers from the ISN used
   for some other connection.  The PRF could be implemented as a
   cryptographic hash of the concatenation of the TCP connection
   parameters and some secret data.  For discussion of the selection of
   a specific hash algorithm and management of the secret key data,
   please see Section 3 of [42].

   For each connection there is a send sequence number and a receive
   sequence number.  The initial send sequence number (ISS) is chosen by
   the data sending TCP peer, and the initial receive sequence number
   (IRS) is learned during the connection-establishing procedure.

   For a connection to be established or initialized, the two TCP peers
   must synchronize on each other's initial sequence numbers.  This is
   done in an exchange of connection-establishing segments carrying a
   control bit called "SYN" (for synchronize) and the initial sequence
   numbers.  As a shorthand, segments carrying the SYN bit are also
   called "SYNs".  Hence, the solution requires a suitable mechanism for
   picking an initial sequence number and a slightly involved handshake
   to exchange the ISNs.

Cc: Saloni Kasbekar 
Cc: Zachary Clark-williams 

Signed-off-by: Doug Flick [MSFT] 
---
 NetworkPkg/TcpDxe/TcpDxe.inf  |   8 +-
 NetworkPkg/TcpDxe/TcpFunc.h   |  23 +-
 NetworkPkg/TcpDxe/TcpMain.h   |  59 -
 NetworkPkg/TcpDxe/TcpDriver.c |  92 +++-
 NetworkPkg/TcpDxe/TcpInput.c  |  13 +-
 NetworkPkg/TcpDxe/TcpMisc.c   | 244 ++--
 NetworkPkg/TcpDxe/TcpTimer.c  |   3 +-
 NetworkPkg/SecurityFixes.yaml |  22 ++
 8 files changed, 415 insertions(+), 49 deletions(-)

diff --git a/NetworkPkg/TcpDxe/TcpDxe.inf b/NetworkPkg/TcpDxe/TcpDxe.inf
index cf5423f4c5..76de4cf9ec 100644
--- a/NetworkPkg/TcpDxe/TcpDxe.inf
+++ b/NetworkPkg/TcpDxe/TcpDxe.inf
@@ -6,6 +6,7 @@
 #  stack has been loaded in system. This driver supports both IPv4 and IPv6 
network stack.
 #
 #  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
+#  Copyright (c) Microsoft Corporation
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -68,7 +69,6 @@
   NetLib
   IpIoLib
 
-
 [Protocols]
   ## SOMETIMES_CONSUMES
   ## SOMETIMES_PRODUCES
@@ -81,6 +81,12 @@
   gEfiIp6ServiceBindingProtocolGuid ## TO_START
   gEfiTcp6ProtocolGuid  ## BY_START
   gEfiTcp6ServiceBindingProtocolGuid## BY_START
+  gEfiHash2ProtocolGuid ## BY_START
+  gEfiHash2ServiceBindingProtocolGuid   ## BY_START
+
+[Guids]
+  gEfiHashAlgorithmMD5Guid  ## CONSUMES
+  gEfiHashAlgorithmSha256Guid   ## CONSUMES
 
 [Depex]
   gEfiHash2ServiceBindingProtocolGuid
diff --git a/NetworkPkg/TcpDxe/TcpFunc.h b/NetworkPkg/TcpDxe/TcpFunc.h
index a7af01fff2..c707bee3e5 100644
--- a/NetworkPkg/TcpDxe/TcpFunc.h
+++ b/NetworkPkg/TcpDxe/TcpFunc.h
@@ -2,7 +2,7 @@
   Declaration of external functions shared in TCP driver.
 
   Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
-
+  Copyright (c) Microsoft Corporation
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -36,8 +36,11 @@ VOID
 
   @param[in, out]  Tcb   Pointer to the TCP_CB of this TCP 
instance.
 
+  @retval EFI_SUCCESS The operation completed successfully
+  @retval others  The underlying functions failed and could 
not complete the operation
+
 **/
-VOID
+EFI_STATUS
 TcpInitTcbLocal (
   IN OUT TCP_CB  *Tcb
   );
@@ -128,17 +131,6 @@ TcpCloneTcb (
   IN TCP_CB  *Tcb
   );
 
-/**
-  Compute an ISS to be used by a new connection.
-
-  @return The result ISS.
-
-**/
-TCP_SEQNO
-TcpGetIss (
-  VOID
-  );
-
 /**
   Get the local mss.
 
@@ -202,8 

[edk2-devel] [PATCH v3 11/20] MdePkg: : Adds Protocol for MockRng

2024-05-23 Thread Doug Flick via groups.io
From: Doug Flick 

This patch adds a protocol for MockRng. This protocol is used to
mock the Rng protocol for testing purposes.

Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Zhiguang Liu 

Signed-off-by: Doug Flick [MSFT] 
---
 MdePkg/Test/Mock/Include/GoogleTest/Protocol/MockRng.h   | 48 

 MdePkg/Test/Mock/Library/GoogleTest/Protocol/MockRng.cpp | 21 +
 2 files changed, 69 insertions(+)

diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Protocol/MockRng.h 
b/MdePkg/Test/Mock/Include/GoogleTest/Protocol/MockRng.h
new file mode 100644
index 00..b54f8a234b
--- /dev/null
+++ b/MdePkg/Test/Mock/Include/GoogleTest/Protocol/MockRng.h
@@ -0,0 +1,48 @@
+/** @file
+  This file declares a mock of Rng Protocol.
+
+  Copyright (c) Microsoft Corporation.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef MOCK_RNG_H_
+#define MOCK_RNG_H_
+
+#include 
+#include 
+
+extern "C" {
+  #include 
+  #include 
+}
+
+struct MockRng {
+  MOCK_INTERFACE_DECLARATION (MockRng);
+
+  MOCK_FUNCTION_DECLARATION (
+EFI_STATUS,
+GetInfo,
+(
+ IN EFI_RNG_PROTOCOL *This,
+ IN OUT UINTN*RNGAlgorithmListSize,
+ OUT EFI_RNG_ALGORITHM   *RNGAlgorithmList
+)
+);
+
+  MOCK_FUNCTION_DECLARATION (
+EFI_STATUS,
+GetRng,
+(
+ IN EFI_RNG_PROTOCOL*This,
+ IN EFI_RNG_ALGORITHM   *RNGAlgorithm,
+ IN UINTN   RNGValueLength,
+ OUT UINT8  *RNGValue
+)
+);
+};
+
+extern "C" {
+  extern EFI_RNG_PROTOCOL  *gRngProtocol;
+}
+
+#endif // MOCK_RNG_H_
diff --git a/MdePkg/Test/Mock/Library/GoogleTest/Protocol/MockRng.cpp 
b/MdePkg/Test/Mock/Library/GoogleTest/Protocol/MockRng.cpp
new file mode 100644
index 00..7d8b69cc86
--- /dev/null
+++ b/MdePkg/Test/Mock/Library/GoogleTest/Protocol/MockRng.cpp
@@ -0,0 +1,21 @@
+/** @file MockRng.cpp
+  Google Test mock for Rng Protocol
+
+  Copyright (c) Microsoft Corporation.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include 
+
+MOCK_INTERFACE_DEFINITION (MockRng);
+MOCK_FUNCTION_DEFINITION (MockRng, GetInfo, 3, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockRng, GetRng, 4, EFIAPI);
+
+EFI_RNG_PROTOCOL  RNG_PROTOCOL_INSTANCE = {
+  GetInfo, // EFI_RNG_GET_INFO
+  GetRng   // EFI_RNG_GET_RNG
+};
+
+extern "C" {
+  EFI_RNG_PROTOCOL  *gRngProtocol = _PROTOCOL_INSTANCE;
+}
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119238): https://edk2.groups.io/g/devel/message/119238
Mute This Topic: https://groups.io/mt/106276863/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 08/20] NetworkPkg:: SECURITY PATCH CVE-2023-45237

2024-05-23 Thread Doug Flick via groups.io
From: Doug Flick 

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

Bug Overview:
PixieFail Bug #9
CVE-2023-45237
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N
CWE-338 Use of Cryptographically Weak Pseudo-Random Number Generator (PRNG)

Use of a Weak PseudoRandom Number Generator

Change Overview:

Updates all Instances of NET_RANDOM (NetRandomInitSeed ()) to either

>
> EFI_STATUS
> EFIAPI
> PseudoRandomU32 (
>  OUT UINT32  *Output
>  );
>

or (depending on the use case)

>
> EFI_STATUS
> EFIAPI
> PseudoRandom (
>  OUT  VOID   *Output,
>  IN   UINTN  OutputLength
>  );
>

This is because the use of

Example:

The following code snippet PseudoRandomU32 () function is used:

>
> UINT32 Random;
>
> Status = PseudoRandomU32 ();
> if (EFI_ERROR (Status)) {
>   DEBUG ((DEBUG_ERROR, "%a failed to generate random number: %r\n",
__func__, Status));
>   return Status;
> }
>

This also introduces a new PCD to enable/disable the use of the
secure implementation of algorithms for PseudoRandom () and
instead depend on the default implementation. This may be required for
some platforms where the UEFI Spec defined algorithms are not available.

>
> PcdEnforceSecureRngAlgorithms
>

If the platform does not have any one of the UEFI defined
secure RNG algorithms then the driver will assert.

Cc: Saloni Kasbekar 
Cc: Zachary Clark-williams 

Signed-off-by: Doug Flick [MSFT] 
---
 NetworkPkg/NetworkPkg.dec  |   7 ++
 NetworkPkg/Library/DxeNetLib/DxeNetLib.inf |  14 ++-
 NetworkPkg/TcpDxe/TcpDxe.inf   |   3 +
 NetworkPkg/IScsiDxe/IScsiMisc.h|   6 +-
 NetworkPkg/Include/Library/NetLib.h|  40 --
 NetworkPkg/Ip6Dxe/Ip6Nd.h  |   8 +-
 NetworkPkg/Dhcp4Dxe/Dhcp4Driver.c  |  10 +-
 NetworkPkg/Dhcp6Dxe/Dhcp6Driver.c  |  11 +-
 NetworkPkg/DnsDxe/DnsDhcp.c|  10 +-
 NetworkPkg/DnsDxe/DnsImpl.c|  11 +-
 NetworkPkg/HttpBootDxe/HttpBootDhcp6.c |  10 +-
 NetworkPkg/IScsiDxe/IScsiCHAP.c|  19 ++-
 NetworkPkg/IScsiDxe/IScsiMisc.c|  14 +--
 NetworkPkg/Ip4Dxe/Ip4Driver.c  |  10 +-
 NetworkPkg/Ip6Dxe/Ip6ConfigImpl.c  |   9 +-
 NetworkPkg/Ip6Dxe/Ip6Driver.c  |  17 ++-
 NetworkPkg/Ip6Dxe/Ip6If.c  |  12 +-
 NetworkPkg/Ip6Dxe/Ip6Mld.c |  12 +-
 NetworkPkg/Ip6Dxe/Ip6Nd.c  |  33 -
 NetworkPkg/Library/DxeNetLib/DxeNetLib.c   | 130 +---
 NetworkPkg/TcpDxe/TcpDriver.c  |  15 ++-
 NetworkPkg/Udp4Dxe/Udp4Driver.c|  10 +-
 NetworkPkg/Udp6Dxe/Udp6Driver.c|  11 +-
 NetworkPkg/UefiPxeBcDxe/PxeBcDhcp4.c   |   9 +-
 NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c   |  11 +-
 NetworkPkg/UefiPxeBcDxe/PxeBcDriver.c  |  12 +-
 NetworkPkg/SecurityFixes.yaml  |  39 ++
 27 files changed, 410 insertions(+), 83 deletions(-)

diff --git a/NetworkPkg/NetworkPkg.dec b/NetworkPkg/NetworkPkg.dec
index e06f35e774..7c4289b77b 100644
--- a/NetworkPkg/NetworkPkg.dec
+++ b/NetworkPkg/NetworkPkg.dec
@@ -5,6 +5,7 @@
 #
 # Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.
 # (C) Copyright 2015-2020 Hewlett Packard Enterprise Development LP
+# Copyright (c) Microsoft Corporation
 #
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -130,6 +131,12 @@
   # @Prompt Indicates whether SnpDxe creates event for ExitBootServices() call.
   
gEfiNetworkPkgTokenSpaceGuid.PcdSnpCreateExitBootServicesEvent|TRUE|BOOLEAN|0x100C
 
+  ## Enforces the use of Secure UEFI spec defined RNG algorithms for all 
network connections.
+  # TRUE  - Enforce the use of Secure UEFI spec defined RNG algorithms.
+  # FALSE - Do not enforce and depend on the default implementation of RNG 
algorithm from the provider.
+  # @Prompt Enforce the use of Secure UEFI spec defined RNG algorithms.
+  
gEfiNetworkPkgTokenSpaceGuid.PcdEnforceSecureRngAlgorithms|TRUE|BOOLEAN|0x100D
+
 [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx]
   ## IPv6 DHCP Unique Identifier (DUID) Type configuration (From RFCs 3315 and 
6355).
   # 01 = DUID Based on Link-layer Address Plus Time [DUID-LLT]
diff --git a/NetworkPkg/Library/DxeNetLib/DxeNetLib.inf 
b/NetworkPkg/Library/DxeNetLib/DxeNetLib.inf
index 8145d256ec..a8f534a293 100644
--- a/NetworkPkg/Library/DxeNetLib/DxeNetLib.inf
+++ b/NetworkPkg/Library/DxeNetLib/DxeNetLib.inf
@@ -3,6 +3,7 @@
 #
 #  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
 #  (C) Copyright 2015 Hewlett Packard Enterprise Development LP
+#  Copyright (c) Microsoft Corporation
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
@@ -49,7 +50,11 @@
   gEfiSmbiosTableGuid   ## SOMETIMES_CONSUMES  ## 
SystemTable
   gEfiSmbios3TableGuid  ## SOMETIMES_CONSUMES  ## 
SystemTable
   gEfiAdapterInfoMediaStateGuid ## SOMETIMES_CONSUMES
-
+  gEfiRngAlgorithmRaw   ## 

[edk2-devel] [PATCH v3 03/20] OvmfPkg:PlatformCI: Support virtio-rng-pci

2024-05-23 Thread Doug Flick via groups.io
This patch adds "virtio-rng-pci" to the PlatformBuildLib.py
This adds Rng services to the guest VM

Cc: Ard Biesheuvel 
Cc: Jiewen Yao 
Cc: Gerd Hoffmann 

Signed-off-by: Doug Flick [MSFT] 
---
 OvmfPkg/PlatformCI/PlatformBuildLib.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/OvmfPkg/PlatformCI/PlatformBuildLib.py 
b/OvmfPkg/PlatformCI/PlatformBuildLib.py
index 00d454954b..3fe80f5c1c 100644
--- a/OvmfPkg/PlatformCI/PlatformBuildLib.py
+++ b/OvmfPkg/PlatformCI/PlatformBuildLib.py
@@ -208,6 +208,8 @@ class PlatformBuilder( UefiBuilder, BuildSettingsManager):
 args += " -net none"# 
turn off network
 args += " -smp 4"
 args += f" -drive file=fat:rw:{VirtualDrive},format=raw,media=disk" # 
Mount disk with startup.nsh
+# Provides Rng services to the Guest VM
+args += " -device virtio-rng-pci"
 
 if (self.env.GetValue("QEMU_HEADLESS").upper() == "TRUE"):
 args += " -display none"  # no graphics
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119230): https://edk2.groups.io/g/devel/message/119230
Mute This Topic: https://groups.io/mt/106276855/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 07/20] SecurityPkg: RngDxe: Remove incorrect limitation on GetRng

2024-05-23 Thread Doug Flick via groups.io
Removed from gEfiRngAlgorithmRaw an incorrect assumption that
Raw cannot return less than 256 bits. The DRNG Algorithms
should always use a 256 bit seed as per nist standards
however a caller is free to request less than 256 bits.
>
> //
>// When a DRBG is used on the output of a entropy source,
>// its security level must be at least 256 bits according to UEFI
Spec.
>//
>if (RNGValueLength < 32) {
>  return EFI_INVALID_PARAMETER;
>}
>

AARCH64 platforms do not have this limitation and this brings both
implementations into alignment with each other and the spec.

Cc: Jiewen Yao 

Signed-off-by: Doug Flick [MSFT] 
Reviewed-by: Ard Biesheuvel 
---
 SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c | 8 
 1 file changed, 8 deletions(-)

diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c 
b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c
index 7e06e16e4b..5723ed6957 100644
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c
+++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c
@@ -116,14 +116,6 @@ RngGetRNG (
   // The "raw" algorithm is intended to provide entropy directly
   //
   if (CompareGuid (RNGAlgorithm, )) {
-//
-// When a DRBG is used on the output of a entropy source,
-// its security level must be at least 256 bits according to UEFI Spec.
-//
-if (RNGValueLength < 32) {
-  return EFI_INVALID_PARAMETER;
-}
-
 Status = GenerateEntropy (RNGValueLength, RNGValue);
 return Status;
   }
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119234): https://edk2.groups.io/g/devel/message/119234
Mute This Topic: https://groups.io/mt/106276859/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 05/20] ArmVirtPkg:PlatformCI: Support virtio-rng-pci

2024-05-23 Thread Doug Flick via groups.io
This patch adds "virtio-rng-pci" to the PlatformBuildLib.py
This adds Rng services to the guest VM

Cc: Ard Biesheuvel 
Cc: Leif Lindholm 
Cc: Sami Mujawar 
Cc: Gerd Hoffmann 

Signed-off-by: Doug Flick [MSFT] 
---
 ArmVirtPkg/PlatformCI/PlatformBuildLib.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/ArmVirtPkg/PlatformCI/PlatformBuildLib.py 
b/ArmVirtPkg/PlatformCI/PlatformBuildLib.py
index 0ddaccf9c2..3abab09141 100644
--- a/ArmVirtPkg/PlatformCI/PlatformBuildLib.py
+++ b/ArmVirtPkg/PlatformCI/PlatformBuildLib.py
@@ -240,6 +240,8 @@ class PlatformBuilder(UefiBuilder, BuildSettingsManager):
 args += " -serial stdio"
 # Mount disk with startup.nsh
 args += f" -drive file=fat:rw:{VirtualDrive},format=raw,media=disk"
+# Provides Rng services to the Guest VM
+args += " -device virtio-rng-pci"
 
 # Conditional Args
 if (self.env.GetValue("QEMU_HEADLESS").upper() == "TRUE"):
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119232): https://edk2.groups.io/g/devel/message/119232
Mute This Topic: https://groups.io/mt/106276857/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 06/20] ArmVirtPkg: : Add Hash2DxeCrypto to ArmVirtPkg

2024-05-23 Thread Doug Flick via groups.io
This patch adds Hash2DxeCrypto to ArmVirtPkg. The Hash2DxeCrypto is
used to provide the hashing protocol services.

Cc: Ard Biesheuvel 
Cc: Leif Lindholm 
Cc: Sami Mujawar 
Cc: Gerd Hoffmann 

Signed-off-by: Doug Flick [MSFT] 
---
 ArmVirtPkg/ArmVirtQemu.dsc   | 5 +
 ArmVirtPkg/ArmVirtQemuKernel.dsc | 5 +
 ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc | 5 +
 3 files changed, 15 insertions(+)

diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
index 7e2ff33ad1..1d3315ad3e 100644
--- a/ArmVirtPkg/ArmVirtQemu.dsc
+++ b/ArmVirtPkg/ArmVirtQemu.dsc
@@ -554,6 +554,11 @@
   MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf
   MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf
 
+  #
+  # Hash2 Protocol Support
+  #
+  SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
+
   #
   # TPM2 support
   #
diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKernel.dsc
index efe2df97bd..94f48593c2 100644
--- a/ArmVirtPkg/ArmVirtQemuKernel.dsc
+++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc
@@ -461,6 +461,11 @@
   MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf
   MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf
 
+  #
+  # Hash2 Protocol Support
+  #
+  SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
+
   #
   # ACPI Support
   #
diff --git a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc 
b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc
index c5d097ffb9..80d420023e 100644
--- a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc
+++ b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc
@@ -177,6 +177,11 @@ READ_LOCK_STATUS   = TRUE
   INF MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf
   INF MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf
 
+  #
+  # Hash2 Protocol producer
+  #
+  INF SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
+
   #
   # TPM2 support
   #
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119233): https://edk2.groups.io/g/devel/message/119233
Mute This Topic: https://groups.io/mt/106276858/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 04/20] OvmfPkg: : Add Hash2DxeCrypto to OvmfPkg

2024-05-23 Thread Doug Flick via groups.io
From: Doug Flick 

This patch adds Hash2DxeCrypto to OvmfPkg. The Hash2DxeCrypto is
used to provide the hashing protocol services.

Cc: Ard Biesheuvel 
Cc: Jiewen Yao 
Cc: Gerd Hoffmann 

Signed-off-by: Doug Flick [MSFT] 
---
 OvmfPkg/OvmfPkgIa32.dsc| 6 +-
 OvmfPkg/OvmfPkgIa32X64.dsc | 6 +-
 OvmfPkg/OvmfPkgX64.dsc | 6 +-
 OvmfPkg/OvmfXen.dsc| 5 +
 OvmfPkg/OvmfPkgIa32.fdf| 5 +
 OvmfPkg/OvmfPkgIa32X64.fdf | 5 +
 OvmfPkg/OvmfPkgX64.fdf | 5 +
 OvmfPkg/OvmfXen.fdf| 5 +
 8 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index 1be021be71..2ca005d768 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -229,7 +229,6 @@
   
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
   
VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
 
-
   #
   # Network libraries
   #
@@ -858,6 +857,11 @@
   MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf
   
MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf
 
+  #
+  # Hash2 Protocol producer
+  #
+  SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
+
   #
   # Network Support
   #
diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index d27a4c7278..a39070a626 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -234,7 +234,6 @@
   
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
   
VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
 
-
   #
   # Network libraries
   #
@@ -872,6 +871,11 @@
   MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf
   
MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf
 
+  #
+  # Hash2 Protocol producer
+  #
+  SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
+
   #
   # Network Support
   #
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index 8f5cd23b2e..1b90aa8f57 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -250,7 +250,6 @@
   
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
   
VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
 
-
   #
   # Network libraries
   #
@@ -940,6 +939,11 @@
   MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf
   
MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf
 
+  #
+  # Hash2 Protocol producer
+  #
+  SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
+
   #
   # Network Support
   #
diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index fa1a570e74..7fc340d1c1 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -667,6 +667,11 @@
   MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf
   
MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf
 
+  #
+  # Hash2 Protocol producer
+  #
+  SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
+
   #
   # Network Support
   #
diff --git a/OvmfPkg/OvmfPkgIa32.fdf b/OvmfPkg/OvmfPkgIa32.fdf
index 6eb26f7d46..0d4abb50a8 100644
--- a/OvmfPkg/OvmfPkgIa32.fdf
+++ b/OvmfPkg/OvmfPkgIa32.fdf
@@ -295,6 +295,11 @@ INF  OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf
 
 INF MdeModulePkg/Logo/LogoDxe.inf
 
+#
+# Hash2 Protocol producer
+#
+INF SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
+
 #
 # Network modules
 #
diff --git a/OvmfPkg/OvmfPkgIa32X64.fdf b/OvmfPkg/OvmfPkgIa32X64.fdf
index 080784f722..23a825a012 100644
--- a/OvmfPkg/OvmfPkgIa32X64.fdf
+++ b/OvmfPkg/OvmfPkgIa32X64.fdf
@@ -296,6 +296,11 @@ INF  OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf
 
 INF MdeModulePkg/Logo/LogoDxe.inf
 
+#
+# Hash2 Protocol producer
+#
+INF SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
+
 #
 # Network modules
 #
diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf
index b6e8f43566..4dcd6a033c 100644
--- a/OvmfPkg/OvmfPkgX64.fdf
+++ b/OvmfPkg/OvmfPkgX64.fdf
@@ -329,6 +329,11 @@ INF MdeModulePkg/Logo/LogoDxe.inf
 
 INF OvmfPkg/TdxDxe/TdxDxe.inf
 
+#
+# Hash2 Protocol producer
+#
+INF SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
+
 #
 # Network modules
 #
diff --git a/OvmfPkg/OvmfXen.fdf b/OvmfPkg/OvmfXen.fdf
index 5770b17316..41368f37e2 100644
--- a/OvmfPkg/OvmfXen.fdf
+++ b/OvmfPkg/OvmfXen.fdf
@@ -314,6 +314,11 @@ INF  ShellPkg/Application/Shell/Shell.inf
 
 INF MdeModulePkg/Logo/LogoDxe.inf
 
+#
+# Hash2 Protocol producer
+#
+INF SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
+
 #
 # Network modules
 #
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119231): https://edk2.groups.io/g/devel/message/119231
Mute This Topic: https://groups.io/mt/106276856/21656
Group Owner: devel+ow...@edk2.groups.io

[edk2-devel] [PATCH v3 01/20] EmulatorPkg: : Add RngDxe to EmulatorPkg

2024-05-23 Thread Doug Flick via groups.io
This patch adds RngDxe to EmulatorPkg. The RngDxe is used to provide
random number generation services to the UEFI firmware.

Cc: Andrew Fish 
Cc: Ray Ni 

Signed-off-by: Doug Flick [MSFT] 
Reviewed-by: Ray Ni 
---
 EmulatorPkg/EmulatorPkg.dsc | 7 ++-
 EmulatorPkg/EmulatorPkg.fdf | 6 +-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/EmulatorPkg/EmulatorPkg.dsc b/EmulatorPkg/EmulatorPkg.dsc
index 5fa1ed345a..0a66294cb7 100644
--- a/EmulatorPkg/EmulatorPkg.dsc
+++ b/EmulatorPkg/EmulatorPkg.dsc
@@ -127,9 +127,9 @@
   ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
   FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf
   
ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf
+  RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf
 
 !if $(SECURE_BOOT_ENABLE) == TRUE
-  RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf
   IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf
   OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf
   
PlatformSecureLib|SecurityPkg/Library/PlatformSecureLibNull/PlatformSecureLibNull.inf
@@ -398,6 +398,11 @@
   EmulatorPkg/PlatformSmbiosDxe/PlatformSmbiosDxe.inf
   EmulatorPkg/TimerDxe/Timer.inf
 
+  #
+  # Rng Protocol producer
+  #
+  SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
+
 !if $(SECURE_BOOT_ENABLE) == TRUE
   SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf
 !endif
diff --git a/EmulatorPkg/EmulatorPkg.fdf b/EmulatorPkg/EmulatorPkg.fdf
index 5420756eaa..d756c144d9 100644
--- a/EmulatorPkg/EmulatorPkg.fdf
+++ b/EmulatorPkg/EmulatorPkg.fdf
@@ -193,6 +193,11 @@ INF  RuleOverride = UI 
MdeModulePkg/Application/UiApp/UiApp.inf
 INF  MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenuApp.inf
 INF  MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf
 
+#
+# Rng Protocol producer
+#
+INF  SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
+
 #
 # Secure Boot Key Enroll
 #
@@ -320,4 +325,3 @@ INF  ShellPkg/Application/Shell/Shell.inf
 UISTRING="$(MODULE_NAME)" Optional
 VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
   }
-
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119228): https://edk2.groups.io/g/devel/message/119228
Mute This Topic: https://groups.io/mt/106276853/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 02/20] EmulatorPkg: : Add Hash2DxeCrypto to EmulatorPkg

2024-05-23 Thread Doug Flick via groups.io
From: Doug Flick 

This patch adds Hash2DxeCrypto to EmulatorPkg. The Hash2DxeCrypto is
used to provide the hashing protocol services.

Cc: Andrew Fish 
Cc: Ray Ni 

Signed-off-by: Doug Flick [MSFT] 
---
 EmulatorPkg/EmulatorPkg.dsc | 9 +++--
 EmulatorPkg/EmulatorPkg.fdf | 5 +
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/EmulatorPkg/EmulatorPkg.dsc b/EmulatorPkg/EmulatorPkg.dsc
index 0a66294cb7..1c356bc8c7 100644
--- a/EmulatorPkg/EmulatorPkg.dsc
+++ b/EmulatorPkg/EmulatorPkg.dsc
@@ -128,10 +128,11 @@
   FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf
   
ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf
   RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf
-
-!if $(SECURE_BOOT_ENABLE) == TRUE
   IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf
   OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf
+  BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
+
+!if $(SECURE_BOOT_ENABLE) == TRUE
   
PlatformSecureLib|SecurityPkg/Library/PlatformSecureLibNull/PlatformSecureLibNull.inf
   AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf
   
SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.inf
@@ -402,6 +403,10 @@
   # Rng Protocol producer
   #
   SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
+  #
+  # Hash2 Protocol producer
+  #
+  SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
 
 !if $(SECURE_BOOT_ENABLE) == TRUE
   SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf
diff --git a/EmulatorPkg/EmulatorPkg.fdf b/EmulatorPkg/EmulatorPkg.fdf
index d756c144d9..73d5b0068d 100644
--- a/EmulatorPkg/EmulatorPkg.fdf
+++ b/EmulatorPkg/EmulatorPkg.fdf
@@ -198,6 +198,11 @@ INF  
MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf
 #
 INF  SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
 
+#
+# Hash2 Protocol producer
+#
+INF  SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
+
 #
 # Secure Boot Key Enroll
 #
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119229): https://edk2.groups.io/g/devel/message/119229
Mute This Topic: https://groups.io/mt/106276854/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 00/20] NetworkPkg: CVE-2023-45236 and CVE-2023-45237

2024-05-23 Thread Doug Flick via groups.io


REF:https://blog.quarkslab.com/pixiefail-nine-vulnerabilities-in-tianocores-edk-ii-ipv6-network-stack.html

This patch series patches the following CVEs:
- CVE-2023-45236: Predictable TCP Initial Sequence Numbers
- CVE-2023-45237: Use of a Weak PseudoRandom Number Generator

In order to patch these CVEs, the following changes were made:
- NetworkPkg no longer performs it's own random number generation,
  instead it uses EFI_RNG_PROTOCOL provided by the plaform to
  generate random numbers.
  - This change was made such that any future random number
generation vulnerabilities will be a result of the platforms
implementation of the EFI_RNG_PROTOCOL and not the NetworkPkg

- NetworkPkg uses the TCP initial sequence number algorithm as described
  in RFC 6528 to generate the initial sequence number for TCP connections.
  - This change was made to ensure that the initial sequence number
is not predictable and therefore cannot be used in a TCP hijacking
attack.

In addition to the above changes, the following changes were made:
- EmulatorPkg OvmfPkg, and ArmVirtPkg were updated to include the
  Hash2DxeCrypto driver to support TCP ISN generation using
  EFI_HASH2_PROTOCOL

- EmulatorPkg was updated to include the
  RngDxe driver to support random number generation using the
  EFI_RNG_PROTOCOL

- OvmfPkg, and ArmVirtPkg were updated to include the
  virtio-rng-pci device to support random number generation using the
  EFI_RNG_PROTOCOL using the existing VirtioRngDxe driver

- SecurityPkg was updated to fix an incorrect limitation on the
  GetRng function in the RngDxe driver where the minimum amount of
  random data that could be requested was 32 bytes (256 bits) instead
  of what the caller requested

- MdePkg was updated to include MockUefiBootServicesTableLib,
  MockRng, and MockHash2 protocols for testing

- NetworkPkg was updated to include a test for the PxeBcDhcp6 driver
  due to underlying changes

- ArmPkg was updated to allow the SMC/HVC monitor conduit to be
  specified at runtime

- MdePkg was updated to remove an overzealous ASSERT in BaseRngLib

- ArmVirtPkg was updated to permit the use of dynamic PCDs in PEI

- ArmVirtPkg was updated to use dynamic PCDs to set the SMCCC conduit

- ArmVirtPkg was updated to add the RngDxe driver

Cc: Liming Gao 

Signed-off-by: Doug Flick [MSFT] 

Ard Biesheuvel (6):
  ArmPkg: Allow SMC/HVC monitor conduit to be specified at runtime
  MdePkg/BaseRngLib AARCH64: Remove overzealous ASSERT()
  ArmVirtPkg/ArmVirtQemu: Permit the use of dynamic PCDs in PEI
  ArmVirtPkg: Use dynamic PCD to set the SMCCC conduit
  ArmVirtPkg: Reverse inclusion order of MdeLibs.inc and ArmVirt.dsc.inc
  ArmVirtPkg/ArmVirtQemu: Add RngDxe driver

Doug Flick (8):
  EmulatorPkg: : Add Hash2DxeCrypto to EmulatorPkg
  OvmfPkg: : Add Hash2DxeCrypto to OvmfPkg
  NetworkPkg:: SECURITY PATCH CVE-2023-45237
  NetworkPkg: TcpDxe: SECURITY PATCH CVE-2023-45236
  MdePkg: : Add MockUefiBootServicesTableLib
  MdePkg: : Adds Protocol for MockRng
  MdePkg: Add MockHash2 Protocol for testing
  NetworkPkg: Update the PxeBcDhcp6GoogleTest due to underlying changes

Flickdm (6):
  EmulatorPkg: : Add RngDxe to EmulatorPkg
  OvmfPkg:PlatformCI: Support virtio-rng-pci
  ArmVirtPkg:PlatformCI: Support virtio-rng-pci
  ArmVirtPkg: : Add Hash2DxeCrypto to ArmVirtPkg
  SecurityPkg: RngDxe: Remove incorrect limitation on GetRng
  ArmVirtPkg: Move PcdMonitorConduitHvc

 ArmPkg/ArmPkg.dec  
   |  10 +-
 NetworkPkg/NetworkPkg.dec  
   |   7 +
 ArmVirtPkg/ArmVirt.dsc.inc 
   |   5 +-
 ArmVirtPkg/ArmVirtCloudHv.dsc  
   |   3 +
 ArmVirtPkg/ArmVirtKvmTool.dsc  
   |   4 +-
 ArmVirtPkg/ArmVirtQemu.dsc 
   |  20 +-
 ArmVirtPkg/ArmVirtQemuKernel.dsc   
   |  12 +-
 ArmVirtPkg/ArmVirtXen.dsc  
   |   6 +-
 EmulatorPkg/EmulatorPkg.dsc
   |  14 +-
 MdePkg/Test/MdePkgHostTest.dsc 
   |   1 +
 NetworkPkg/Test/NetworkPkgHostTest.dsc 
   |   1 +
 OvmfPkg/OvmfPkgIa32.dsc
   |   6 +-
 OvmfPkg/OvmfPkgIa32X64.dsc 
   |   6 +-
 OvmfPkg/OvmfPkgX64.dsc 
   |   6 +-
 OvmfPkg/OvmfXen.dsc

[edk2-devel] [PATCH v3 18/20] ArmVirtPkg: Use dynamic PCD to set the SMCCC conduit

2024-05-23 Thread Doug Flick via groups.io
From: Ard Biesheuvel 

On ARM systems, whether SMC or HVC instructions need to be used to issue
monitor calls is typically dependent on the exception level, but there
are also cases where EL1 might use SMC instructions, so there is no hard
and fast rule.

For ArmVirtQemu, this does depend strictly on the exception level, so
set the default to HVC (for EL1 execution) and override it to SMC when
booted at EL2.

Cc: Ard Biesheuvel 
Cc: Leif Lindholm 
Cc: Sami Mujawar 
Cc: Gerd Hoffmann 

Committed-by: Ard Biesheuvel 
Signed-off-by: Doug Flick [MSFT] 
---
 ArmVirtPkg/ArmVirtCloudHv.dsc|  3 +++
 ArmVirtPkg/ArmVirtQemu.dsc   |  4 
 ArmVirtPkg/ArmVirtQemuKernel.dsc |  2 ++
 ArmVirtPkg/ArmVirtXen.dsc|  2 ++
 ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf |  1 +
 ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c   | 14 ++
 6 files changed, 26 insertions(+)

diff --git a/ArmVirtPkg/ArmVirtCloudHv.dsc b/ArmVirtPkg/ArmVirtCloudHv.dsc
index 5cb2a609b1..d5055a0341 100644
--- a/ArmVirtPkg/ArmVirtCloudHv.dsc
+++ b/ArmVirtPkg/ArmVirtCloudHv.dsc
@@ -201,6 +201,9 @@
 [PcdsDynamicHii]
   
gUefiOvmfPkgTokenSpaceGuid.PcdForceNoAcpi|L"ForceNoAcpi"|gOvmfVariableGuid|0x0|FALSE|NV,BS
 
+[PcdsPatchableInModule.common]
+  gArmTokenSpaceGuid.PcdMonitorConduitHvc|TRUE
+
 

 #
 # Components Section - list of all EDK II Modules needed by this Platform
diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
index 4498ca58a8..80dd4fbb14 100644
--- a/ArmVirtPkg/ArmVirtQemu.dsc
+++ b/ArmVirtPkg/ArmVirtQemu.dsc
@@ -293,6 +293,10 @@
   gEfiNetworkPkgTokenSpaceGuid.PcdIPv4PXESupport|0x01
   gEfiNetworkPkgTokenSpaceGuid.PcdIPv6PXESupport|0x01
 
+  # whether to use HVC or SMC to issue monitor calls - this typically depends
+  # on the exception level at which the UEFI system firmware executes
+  gArmTokenSpaceGuid.PcdMonitorConduitHvc|TRUE
+
   #
   # TPM2 support
   #
diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKernel.dsc
index 94f48593c2..2700b97d09 100644
--- a/ArmVirtPkg/ArmVirtQemuKernel.dsc
+++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc
@@ -203,6 +203,8 @@
   gArmTokenSpaceGuid.PcdFdBaseAddress|0x0
   gArmTokenSpaceGuid.PcdFvBaseAddress|0x0
 
+  gArmTokenSpaceGuid.PcdMonitorConduitHvc|TRUE
+
 [PcdsDynamicDefault.common]
   gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|3
 
diff --git a/ArmVirtPkg/ArmVirtXen.dsc b/ArmVirtPkg/ArmVirtXen.dsc
index 5809832e66..ceb37f8a2d 100644
--- a/ArmVirtPkg/ArmVirtXen.dsc
+++ b/ArmVirtPkg/ArmVirtXen.dsc
@@ -120,6 +120,8 @@
   gArmTokenSpaceGuid.PcdFdBaseAddress|0x0
   gArmTokenSpaceGuid.PcdFvBaseAddress|0x0
 
+  gArmTokenSpaceGuid.PcdMonitorConduitHvc|TRUE
+
 [PcdsDynamicDefault.common]
 
   gArmTokenSpaceGuid.PcdArmArchTimerSecIntrNum|0x0
diff --git a/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf 
b/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf
index e9a34b6e2e..a38b89c103 100644
--- a/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf
+++ b/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf
@@ -45,6 +45,7 @@
 
 [Pcd]
   gArmTokenSpaceGuid.PcdFvBaseAddress
+  gArmTokenSpaceGuid.PcdMonitorConduitHvc
   gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress ## 
SOMETIMES_PRODUCES
   gUefiOvmfPkgTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress
 
diff --git a/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c 
b/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c
index 7ab4aa2d6b..b8e9208301 100644
--- a/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c
+++ b/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c
@@ -18,6 +18,8 @@
 #include 
 #include 
 
+#include 
+
 #include 
 #include 
 
@@ -224,5 +226,17 @@ PlatformPeim (
 
   BuildFvHob (PcdGet64 (PcdFvBaseAddress), PcdGet32 (PcdFvSize));
 
+ #ifdef MDE_CPU_AARCH64
+  //
+  // Set the SMCCC conduit to SMC if executing at EL2, which is typically the
+  // exception level that services HVCs rather than the one that invokes them.
+  //
+  if (ArmReadCurrentEL () == AARCH64_EL2) {
+Status = PcdSetBoolS (PcdMonitorConduitHvc, FALSE);
+ASSERT_EFI_ERROR (Status);
+  }
+
+ #endif
+
   return EFI_SUCCESS;
 }
-- 
2.34.1



[edk2-devel] [PATCH v3 20/20] ArmVirtPkg/ArmVirtQemu: Add RngDxe driver

2024-05-23 Thread Doug Flick via groups.io
From: Ard Biesheuvel 

Add the RngDxe driver to the build, backed by either RNDR or TRNG, one
of which is expected to be available in most cases:
- RNDR is implemented by the 'max' CPU that QEMU implements in TCG mode
- TRNG is implemented by the KVM hypervisor, which backs QEMU's 'host'
  CPU

Other TCG modes (e.g., the 'cortex-a*' CPUs) implement neither, which
should prevent the RngDxe driver from dispatching entirely, resulting
in the same situation as before.

Cc: Ard Biesheuvel 
Cc: Leif Lindholm 
Cc: Sami Mujawar 
Cc: Gerd Hoffmann 

Committed-by: Ard Biesheuvel 
Signed-off-by: Doug Flick [MSFT] 
---
 ArmVirtPkg/ArmVirt.dsc.inc   | 5 -
 ArmVirtPkg/ArmVirtQemu.dsc   | 1 +
 ArmVirtPkg/ArmVirtQemuKernel.dsc | 1 +
 ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc | 1 +
 4 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc
index 2bc6a29eb1..7044790a1e 100644
--- a/ArmVirtPkg/ArmVirt.dsc.inc
+++ b/ArmVirtPkg/ArmVirt.dsc.inc
@@ -156,7 +156,9 @@
   OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf
 !endif
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
-  RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf
+  RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf
+  ArmTrngLib|ArmPkg/Library/ArmTrngLib/ArmTrngLib.inf
+  ArmMonitorLib|ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.inf
 
   #
   # Secure Boot dependencies
@@ -266,6 +268,7 @@
 
 [LibraryClasses.ARM]
   ArmSoftFloatLib|ArmPkg/Library/ArmSoftFloatLib/ArmSoftFloatLib.inf
+  RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf
 
 [BuildOptions]
   GCC:RELEASE_*_*_CC_FLAGS  = -DMDEPKG_NDEBUG
diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
index e40ade230c..64aa4e96e5 100644
--- a/ArmVirtPkg/ArmVirtQemu.dsc
+++ b/ArmVirtPkg/ArmVirtQemu.dsc
@@ -432,6 +432,7 @@
   BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
   }
   MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
+  SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
 
   #
   # Status Code Routing
diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKernel.dsc
index 6f1b81427e..2cf96accbd 100644
--- a/ArmVirtPkg/ArmVirtQemuKernel.dsc
+++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc
@@ -341,6 +341,7 @@
   BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
   }
   MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
+  SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
 
   #
   # Status Code Routing
diff --git a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc 
b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc
index 80d420023e..38906004d7 100644
--- a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc
+++ b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc
@@ -75,6 +75,7 @@ READ_LOCK_STATUS   = TRUE
   INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf
   INF OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.inf
   INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
+  INF SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
 
   #
   # FAT filesystem + GPT/MBR partitioning + UDF filesystem + virtio-fs
-- 
2.34.1



[edk2-devel] [PATCH v3 19/20] ArmVirtPkg: Reverse inclusion order of MdeLibs.inc and ArmVirt.dsc.inc

2024-05-23 Thread Doug Flick via groups.io
From: Ard Biesheuvel 

MdeLibs.inc sets default library class resolutions which are much more
general than the ones that might be specified in ArmVirt.dsc.inc. So the
latter should be included *after* MdeLibs.inc to ensure that its
definitions take precedence.

Cc: Ard Biesheuvel 
Cc: Leif Lindholm 
Cc: Sami Mujawar 
Cc: Gerd Hoffmann 

Committed-by: Ard Biesheuvel 
Signed-off-by: Doug Flick [MSFT] 
---
 ArmVirtPkg/ArmVirtQemu.dsc   | 4 ++--
 ArmVirtPkg/ArmVirtQemuKernel.dsc | 4 ++--
 ArmVirtPkg/ArmVirtXen.dsc| 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
index 80dd4fbb14..e40ade230c 100644
--- a/ArmVirtPkg/ArmVirtQemu.dsc
+++ b/ArmVirtPkg/ArmVirtQemu.dsc
@@ -49,10 +49,10 @@
 
 !include NetworkPkg/NetworkDefines.dsc.inc
 
-!include ArmVirtPkg/ArmVirt.dsc.inc
-
 !include MdePkg/MdeLibs.dsc.inc
 
+!include ArmVirtPkg/ArmVirt.dsc.inc
+
 [LibraryClasses.common]
   ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf
   ArmMmuLib|ArmPkg/Library/ArmMmuLib/ArmMmuBaseLib.inf
diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKernel.dsc
index 2700b97d09..6f1b81427e 100644
--- a/ArmVirtPkg/ArmVirtQemuKernel.dsc
+++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc
@@ -46,10 +46,10 @@
 
 !include NetworkPkg/NetworkDefines.dsc.inc
 
-!include ArmVirtPkg/ArmVirt.dsc.inc
-
 !include MdePkg/MdeLibs.dsc.inc
 
+!include ArmVirtPkg/ArmVirt.dsc.inc
+
 [LibraryClasses.common]
   ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf
   ArmMmuLib|ArmPkg/Library/ArmMmuLib/ArmMmuBaseLib.inf
diff --git a/ArmVirtPkg/ArmVirtXen.dsc b/ArmVirtPkg/ArmVirtXen.dsc
index ceb37f8a2d..1505709a29 100644
--- a/ArmVirtPkg/ArmVirtXen.dsc
+++ b/ArmVirtPkg/ArmVirtXen.dsc
@@ -23,10 +23,10 @@
   SKUID_IDENTIFIER   = DEFAULT
   FLASH_DEFINITION   = ArmVirtPkg/ArmVirtXen.fdf
 
-!include ArmVirtPkg/ArmVirt.dsc.inc
-
 !include MdePkg/MdeLibs.dsc.inc
 
+!include ArmVirtPkg/ArmVirt.dsc.inc
+
 [LibraryClasses]
   
SerialPortLib|OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.inf
 !if $(TARGET) != RELEASE
-- 
2.34.1



[edk2-devel] [PATCH v3 08/20] NetworkPkg:: SECURITY PATCH CVE-2023-45237

2024-05-23 Thread Doug Flick via groups.io
From: Doug Flick 

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

Bug Overview:
PixieFail Bug #9
CVE-2023-45237
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N
CWE-338 Use of Cryptographically Weak Pseudo-Random Number Generator (PRNG)

Use of a Weak PseudoRandom Number Generator

Change Overview:

Updates all Instances of NET_RANDOM (NetRandomInitSeed ()) to either

>
> EFI_STATUS
> EFIAPI
> PseudoRandomU32 (
>  OUT UINT32  *Output
>  );
>

or (depending on the use case)

>
> EFI_STATUS
> EFIAPI
> PseudoRandom (
>  OUT  VOID   *Output,
>  IN   UINTN  OutputLength
>  );
>

This is because the use of

Example:

The following code snippet PseudoRandomU32 () function is used:

>
> UINT32 Random;
>
> Status = PseudoRandomU32 ();
> if (EFI_ERROR (Status)) {
>   DEBUG ((DEBUG_ERROR, "%a failed to generate random number: %r\n",
__func__, Status));
>   return Status;
> }
>

This also introduces a new PCD to enable/disable the use of the
secure implementation of algorithms for PseudoRandom () and
instead depend on the default implementation. This may be required for
some platforms where the UEFI Spec defined algorithms are not available.

>
> PcdEnforceSecureRngAlgorithms
>

If the platform does not have any one of the UEFI defined
secure RNG algorithms then the driver will assert.

Cc: Saloni Kasbekar 
Cc: Zachary Clark-williams 

Signed-off-by: Doug Flick [MSFT] 
---
 NetworkPkg/NetworkPkg.dec  |   7 ++
 NetworkPkg/Library/DxeNetLib/DxeNetLib.inf |  14 ++-
 NetworkPkg/TcpDxe/TcpDxe.inf   |   3 +
 NetworkPkg/IScsiDxe/IScsiMisc.h|   6 +-
 NetworkPkg/Include/Library/NetLib.h|  40 --
 NetworkPkg/Ip6Dxe/Ip6Nd.h  |   8 +-
 NetworkPkg/Dhcp4Dxe/Dhcp4Driver.c  |  10 +-
 NetworkPkg/Dhcp6Dxe/Dhcp6Driver.c  |  11 +-
 NetworkPkg/DnsDxe/DnsDhcp.c|  10 +-
 NetworkPkg/DnsDxe/DnsImpl.c|  11 +-
 NetworkPkg/HttpBootDxe/HttpBootDhcp6.c |  10 +-
 NetworkPkg/IScsiDxe/IScsiCHAP.c|  19 ++-
 NetworkPkg/IScsiDxe/IScsiMisc.c|  14 +--
 NetworkPkg/Ip4Dxe/Ip4Driver.c  |  10 +-
 NetworkPkg/Ip6Dxe/Ip6ConfigImpl.c  |   9 +-
 NetworkPkg/Ip6Dxe/Ip6Driver.c  |  17 ++-
 NetworkPkg/Ip6Dxe/Ip6If.c  |  12 +-
 NetworkPkg/Ip6Dxe/Ip6Mld.c |  12 +-
 NetworkPkg/Ip6Dxe/Ip6Nd.c  |  33 -
 NetworkPkg/Library/DxeNetLib/DxeNetLib.c   | 130 +---
 NetworkPkg/TcpDxe/TcpDriver.c  |  15 ++-
 NetworkPkg/Udp4Dxe/Udp4Driver.c|  10 +-
 NetworkPkg/Udp6Dxe/Udp6Driver.c|  11 +-
 NetworkPkg/UefiPxeBcDxe/PxeBcDhcp4.c   |   9 +-
 NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c   |  11 +-
 NetworkPkg/UefiPxeBcDxe/PxeBcDriver.c  |  12 +-
 NetworkPkg/SecurityFixes.yaml  |  39 ++
 27 files changed, 410 insertions(+), 83 deletions(-)

diff --git a/NetworkPkg/NetworkPkg.dec b/NetworkPkg/NetworkPkg.dec
index e06f35e774..7c4289b77b 100644
--- a/NetworkPkg/NetworkPkg.dec
+++ b/NetworkPkg/NetworkPkg.dec
@@ -5,6 +5,7 @@
 #
 # Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.
 # (C) Copyright 2015-2020 Hewlett Packard Enterprise Development LP
+# Copyright (c) Microsoft Corporation
 #
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -130,6 +131,12 @@
   # @Prompt Indicates whether SnpDxe creates event for ExitBootServices() call.
   
gEfiNetworkPkgTokenSpaceGuid.PcdSnpCreateExitBootServicesEvent|TRUE|BOOLEAN|0x100C
 
+  ## Enforces the use of Secure UEFI spec defined RNG algorithms for all 
network connections.
+  # TRUE  - Enforce the use of Secure UEFI spec defined RNG algorithms.
+  # FALSE - Do not enforce and depend on the default implementation of RNG 
algorithm from the provider.
+  # @Prompt Enforce the use of Secure UEFI spec defined RNG algorithms.
+  
gEfiNetworkPkgTokenSpaceGuid.PcdEnforceSecureRngAlgorithms|TRUE|BOOLEAN|0x100D
+
 [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx]
   ## IPv6 DHCP Unique Identifier (DUID) Type configuration (From RFCs 3315 and 
6355).
   # 01 = DUID Based on Link-layer Address Plus Time [DUID-LLT]
diff --git a/NetworkPkg/Library/DxeNetLib/DxeNetLib.inf 
b/NetworkPkg/Library/DxeNetLib/DxeNetLib.inf
index 8145d256ec..a8f534a293 100644
--- a/NetworkPkg/Library/DxeNetLib/DxeNetLib.inf
+++ b/NetworkPkg/Library/DxeNetLib/DxeNetLib.inf
@@ -3,6 +3,7 @@
 #
 #  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
 #  (C) Copyright 2015 Hewlett Packard Enterprise Development LP
+#  Copyright (c) Microsoft Corporation
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
@@ -49,7 +50,11 @@
   gEfiSmbiosTableGuid   ## SOMETIMES_CONSUMES  ## 
SystemTable
   gEfiSmbios3TableGuid  ## SOMETIMES_CONSUMES  ## 
SystemTable
   gEfiAdapterInfoMediaStateGuid ## SOMETIMES_CONSUMES
-
+  gEfiRngAlgorithmRaw   ## 

[edk2-devel] [PATCH v3 17/20] ArmVirtPkg/ArmVirtQemu: Permit the use of dynamic PCDs in PEI

2024-05-23 Thread Doug Flick via groups.io
From: Ard Biesheuvel 

Currently, only TPM2 builds enable the PCD PEIM, which is a prerequisite
for being able to use dynamic PCDs already at the PEI stage. This
facility will be used for other reasons too so move those pieces out of
code block that are conditional on TPM2_ENABLE

Cc: Ard Biesheuvel 
Cc: Leif Lindholm 
Cc: Sami Mujawar 
Cc: Gerd Hoffmann 

Committed-by: Ard Biesheuvel 
Signed-off-by: Doug Flick [MSFT] 
---
 ArmVirtPkg/ArmVirtQemu.dsc | 6 +-
 ArmVirtPkg/ArmVirtQemu.fdf | 2 +-
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
index 1d3315ad3e..4498ca58a8 100644
--- a/ArmVirtPkg/ArmVirtQemu.dsc
+++ b/ArmVirtPkg/ArmVirtQemu.dsc
@@ -318,11 +318,7 @@
   
gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|L"Timeout"|gEfiGlobalVariableGuid|0x0|5
 
 [LibraryClasses.common.PEI_CORE, LibraryClasses.common.PEIM]
-!if $(TPM2_ENABLE) == TRUE
   PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf
-!else
-  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
-!endif
 
 

 #
@@ -339,11 +335,11 @@
   ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf
   ArmPkg/Drivers/CpuPei/CpuPei.inf
 
-!if $(TPM2_ENABLE) == TRUE
   MdeModulePkg/Universal/PCD/Pei/Pcd.inf {
 
   PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
   }
+!if $(TPM2_ENABLE) == TRUE
   MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf {
 
   
ResetSystemLib|ArmVirtPkg/Library/ArmVirtPsciResetSystemPeiLib/ArmVirtPsciResetSystemPeiLib.inf
diff --git a/ArmVirtPkg/ArmVirtQemu.fdf b/ArmVirtPkg/ArmVirtQemu.fdf
index 764f652afd..6073a31970 100644
--- a/ArmVirtPkg/ArmVirtQemu.fdf
+++ b/ArmVirtPkg/ArmVirtQemu.fdf
@@ -111,8 +111,8 @@ READ_LOCK_STATUS   = TRUE
   INF ArmPkg/Drivers/CpuPei/CpuPei.inf
   INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
 
-!if $(TPM2_ENABLE) == TRUE
   INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf
+!if $(TPM2_ENABLE) == TRUE
   INF MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf
   INF OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf
   INF SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf
-- 
2.34.1



[edk2-devel] [PATCH v3 16/20] MdePkg/BaseRngLib AARCH64: Remove overzealous ASSERT()

2024-05-23 Thread Doug Flick via groups.io
From: Ard Biesheuvel 

BaseRngLib on AARCH64 will discover whether or not RNDR instructions are
supported, by inspecting the ISAR0 identification register, and setting
a global boolean accordingly. This boolean is used in subsequent
execution to decide whether or not to issue the instruction.

The same discovery code also ASSERT()s that RNDR instructions are
implemented, which is unnecessary, and breaks execution on systems that
incorporate the library but don't implement the instruction (or fail to
expose it to the exception level that the firmware executes at).

So drop the ASSERT().

Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Zhiguang Liu 

Committed-by: Ard Biesheuvel 
Signed-off-by: Doug Flick [MSFT] 
---
 MdePkg/Library/BaseRngLib/AArch64/Rndr.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/MdePkg/Library/BaseRngLib/AArch64/Rndr.c 
b/MdePkg/Library/BaseRngLib/AArch64/Rndr.c
index d39db62153..3a556a2e3f 100644
--- a/MdePkg/Library/BaseRngLib/AArch64/Rndr.c
+++ b/MdePkg/Library/BaseRngLib/AArch64/Rndr.c
@@ -50,7 +50,6 @@ BaseRngLibConstructor (
   // MSR. A non-zero value indicates that the processor supports the RNDR 
instruction.
   //
   Isar0 = ArmReadIdIsar0 ();
-  ASSERT ((Isar0 & RNDR_MASK) != 0);
 
   mRndrSupported = ((Isar0 & RNDR_MASK) != 0);
 
-- 
2.34.1



[edk2-devel] [PATCH v3 15/20] ArmVirtPkg: Move PcdMonitorConduitHvc

2024-05-23 Thread Doug Flick via groups.io
This moves the PcdMonitorConduitHvc from PcdsFeatureFlag.Common to
PcdsFixedAtBuild.Common

This is a follow on to the previous commit:
ArmPkg: Allow SMC/HVC monitor conduit to be specified at runtime

ArmVirtQemu may execute at EL2, in which case monitor calls are
generally made using SMC instructions instead of HVC instructions.

Whether or not this is the case can only be decided at runtime, and so
the associated PCD needs to be settable at runtime, if the platform
definition chooses so. This implies a boolean PCD, given that a feature
PCD is build-time configurable only.

Cc: Leif Lindholm 
Cc: Ard Biesheuvel 
Cc: Sami Mujawar 

Signed-off-by: Doug Flick [MSFT] 
---
 ArmVirtPkg/ArmVirtKvmTool.dsc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ArmVirtPkg/ArmVirtKvmTool.dsc b/ArmVirtPkg/ArmVirtKvmTool.dsc
index 20da331966..ae0dd1497f 100644
--- a/ArmVirtPkg/ArmVirtKvmTool.dsc
+++ b/ArmVirtPkg/ArmVirtKvmTool.dsc
@@ -126,8 +126,6 @@
   # Use MMIO for accessing RTC controller registers.
   gPcAtChipsetPkgTokenSpaceGuid.PcdRtcUseMmio|TRUE
 
-  gArmTokenSpaceGuid.PcdMonitorConduitHvc|TRUE
-
 [PcdsFixedAtBuild.common]
   gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x800F
 
@@ -167,6 +165,8 @@
   #
   gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize|16
 
+  gArmTokenSpaceGuid.PcdMonitorConduitHvc|TRUE
+
 [PcdsPatchableInModule.common]
   #
   # This will be overridden in the code
-- 
2.34.1



[edk2-devel] [PATCH v3 12/20] MdePkg: Add MockHash2 Protocol for testing

2024-05-23 Thread Doug Flick via groups.io
From: Doug Flick 

This commit adds a new MockHash2 protocol to the MdePkg. This allows
the unit tests to pick up the new protocol and use it for testing.

Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Zhiguang Liu 

Signed-off-by: Doug Flick [MSFT] 
---
 MdePkg/Test/Mock/Include/GoogleTest/Protocol/MockHash2.h   | 67 

 MdePkg/Test/Mock/Library/GoogleTest/Protocol/MockHash2.cpp | 27 
 2 files changed, 94 insertions(+)

diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Protocol/MockHash2.h 
b/MdePkg/Test/Mock/Include/GoogleTest/Protocol/MockHash2.h
new file mode 100644
index 00..b44d341332
--- /dev/null
+++ b/MdePkg/Test/Mock/Include/GoogleTest/Protocol/MockHash2.h
@@ -0,0 +1,67 @@
+/** @file
+  This file declares a mock of Hash2 Protocol.
+
+  Copyright (c) Microsoft Corporation.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef MOCK_HASH2_H_
+#define MOCK_HASH2_H_
+
+#include 
+#include 
+
+extern "C" {
+  #include 
+  #include 
+}
+
+struct MockHash2 {
+  MOCK_INTERFACE_DECLARATION (MockHash2);
+
+  MOCK_FUNCTION_DECLARATION (
+EFI_STATUS,
+GetHashSize,
+(IN CONST EFI_HASH2_PROTOCOL  *This,
+ IN CONST EFI_GUID*HashAlgorithm,
+ OUT UINTN*HashSize)
+);
+
+  MOCK_FUNCTION_DECLARATION (
+EFI_STATUS,
+Hash,
+(IN CONST EFI_HASH2_PROTOCOL  *This,
+ IN CONST EFI_GUID*HashAlgorithm,
+ IN CONST UINT8   *Message,
+ IN UINTN MessageSize,
+ IN OUT EFI_HASH2_OUTPUT  *Hash)
+);
+
+  MOCK_FUNCTION_DECLARATION (
+EFI_STATUS,
+HashInit,
+(IN CONST EFI_HASH2_PROTOCOL  *This,
+ IN CONST EFI_GUID*HashAlgorithm)
+);
+
+  MOCK_FUNCTION_DECLARATION (
+EFI_STATUS,
+HashUpdate,
+(IN CONST EFI_HASH2_PROTOCOL  *This,
+ IN CONST UINT8   *Message,
+ IN UINTN MessageSize)
+);
+
+  MOCK_FUNCTION_DECLARATION (
+EFI_STATUS,
+HashFinal,
+(IN CONST EFI_HASH2_PROTOCOL  *This,
+ IN OUT EFI_HASH2_OUTPUT  *Hash)
+);
+};
+
+extern "C" {
+  extern EFI_HASH2_PROTOCOL  *gHash2Protocol;
+}
+
+#endif // MOCK_HASH2_H_
diff --git a/MdePkg/Test/Mock/Library/GoogleTest/Protocol/MockHash2.cpp 
b/MdePkg/Test/Mock/Library/GoogleTest/Protocol/MockHash2.cpp
new file mode 100644
index 00..5cf94c43b4
--- /dev/null
+++ b/MdePkg/Test/Mock/Library/GoogleTest/Protocol/MockHash2.cpp
@@ -0,0 +1,27 @@
+/** @file MockHash2.cpp
+  Google Test mock for Hash2 Protocol
+
+  Copyright (c) Microsoft Corporation.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include 
+
+MOCK_INTERFACE_DEFINITION (MockHash2);
+MOCK_FUNCTION_DEFINITION (MockHash2, GetHashSize, 3, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHash2, Hash, 5, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHash2, HashInit, 2, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHash2, HashUpdate, 3, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockHash2, HashFinal, 2, EFIAPI);
+
+EFI_HASH2_PROTOCOL  HASH2_PROTOCOL_INSTANCE = {
+  GetHashSize, // EFI_HASH2_GET_HASH_SIZE
+  Hash,// EFI_HASH2_HASH
+  HashInit,// EFI_HASH2_HASH_INIT
+  HashUpdate,  // EFI_HASH2_HASH_UPDATE
+  HashFinal// EFI_HASH2_HASH_FINAL
+};
+
+extern "C" {
+  EFI_HASH2_PROTOCOL  *gHash2Protocol = _PROTOCOL_INSTANCE;
+}
-- 
2.34.1



[edk2-devel] [PATCH v3 13/20] NetworkPkg: Update the PxeBcDhcp6GoogleTest due to underlying changes

2024-05-23 Thread Doug Flick via groups.io
From: Doug Flick 

This patch updates the PxeBcDhcp6GoogleTest due to the changes in the
underlying code. The changes are as follows:
 - Random now comes from the RngLib Protocol
 - The TCP ISN is now generated by the hash function

Cc: Saloni Kasbekar 
Cc: Zachary Clark-williams 

Signed-off-by: Doug Flick [MSFT] 
---
 NetworkPkg/Test/NetworkPkgHostTest.dsc|   1 +
 NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf |   3 +-
 NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp   | 102 
+++-
 3 files changed, 100 insertions(+), 6 deletions(-)

diff --git a/NetworkPkg/Test/NetworkPkgHostTest.dsc 
b/NetworkPkg/Test/NetworkPkgHostTest.dsc
index fa301a7a52..1772afb058 100644
--- a/NetworkPkg/Test/NetworkPkgHostTest.dsc
+++ b/NetworkPkg/Test/NetworkPkgHostTest.dsc
@@ -30,6 +30,7 @@
   NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf {
 
   
UefiRuntimeServicesTableLib|MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib/MockUefiRuntimeServicesTableLib.inf
+  
UefiBootServicesTableLib|MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.inf
   }
 
 # Despite these library classes being listed in [LibraryClasses] below, they 
are not needed for the host-based unit tests.
diff --git a/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf 
b/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf
index 301dcdf611..8b092d9291 100644
--- a/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf
+++ b/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf
@@ -14,7 +14,7 @@ VERSION_STRING = 1.0
 #
 # The following information is for reference only and not required by the 
build tools.
 #
-#  VALID_ARCHITECTURES   = IA32 X64
+#  VALID_ARCHITECTURES   = IA32 X64 AARCH64
 #
 
 [Sources]
@@ -23,6 +23,7 @@ VERSION_STRING = 1.0
   PxeBcDhcp6GoogleTest.h
   ../PxeBcDhcp6.c
   ../PxeBcSupport.c
+  ../../../MdePkg/Test/Mock/Library/GoogleTest/Protocol/MockRng.cpp
 
 [Packages]
   MdePkg/MdePkg.dec
diff --git a/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp 
b/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp
index bd423ebadf..61736ff79e 100644
--- a/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp
+++ b/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp
@@ -7,6 +7,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 extern "C" {
   #include 
@@ -165,7 +167,7 @@ protected:
 // Note:
 // Testing PxeBcHandleDhcp6Offer() is difficult because it depends on a
 // properly setup Private structure. Attempting to properly test this function
-// without a signficant refactor is a fools errand. Instead, we will test
+// without a significant refactor is a fools errand. Instead, we will test
 // that we can prevent an overflow in the function.
 TEST_F (PxeBcHandleDhcp6OfferTest, BasicUsageTest) {
   PXEBC_DHCP6_PACKET_CACHE  *Cache6 = NULL;
@@ -238,6 +240,7 @@ TEST_F (PxeBcCacheDnsServerAddressesTest, BasicUsageTest) {
 FreePool (Option);
   }
 }
+
 // Test Description
 // Test that we can prevent an overflow in the function
 TEST_F (PxeBcCacheDnsServerAddressesTest, AttemptOverflowTest) {
@@ -470,10 +473,15 @@ TEST_F (PxeBcRequestBootServiceTest, 
AttemptRequestOverFlowExpectFailure) {
 class PxeBcDhcp6DiscoverTest : public ::testing::Test {
 public:
   PXEBC_PRIVATE_DATA Private = { 0 };
+  // create a mock md5 hash
+  UINT8 Md5Hash[16] = { 0 };
+
   EFI_UDP6_PROTOCOL Udp6Read;
 
 protected:
   MockUefiRuntimeServicesTableLib RtServicesMock;
+  MockUefiBootServicesTableLib BsMock;
+  MockRng RngMock;
 
   // Add any setup code if needed
   virtual void
@@ -527,8 +535,21 @@ TEST_F (PxeBcDhcp6DiscoverTest, BasicOverflowTest) {
 
   Private.Dhcp6Request->Length = (UINT16)(Cursor - (UINT8 
*)Private.Dhcp6Request);
 
-  EXPECT_CALL (RtServicesMock, gRT_GetTime)
-.WillOnce (::testing::Return (0));
+  EXPECT_CALL (BsMock, gBS_LocateProtocol)
+.WillOnce (
+   ::testing::DoAll (
+::testing::SetArgPointee<2> (::testing::ByRef 
(gRngProtocol)),
+::testing::Return (EFI_SUCCESS)
+)
+   );
+
+  EXPECT_CALL (RngMock, GetRng)
+.WillOnce (
+   ::testing::DoAll (
+::testing::SetArgPointee<3> (::testing::ByRef 
(Md5Hash[0])),
+::testing::Return (EFI_SUCCESS)
+)
+   );
 
   ASSERT_EQ (
 PxeBcDhcp6Discover (
@@ -558,8 +579,21 @@ TEST_F (PxeBcDhcp6DiscoverTest, BasicUsageTest) {
 
   Private.Dhcp6Request->Length = (UINT16)(Cursor - (UINT8 
*)Private.Dhcp6Request);
 
-  EXPECT_CALL (RtServicesMock, gRT_GetTime)
-.WillOnce (::testing::Return (0));
+  EXPECT_CALL (BsMock, gBS_LocateProtocol)
+.WillOnce (
+   ::testing::DoAll (
+::testing::SetArgPointee<2> (::testing::ByRef 
(gRngProtocol)),
+::testing::Return (EFI_SUCCESS)
+   

[edk2-devel] [PATCH v3 14/20] ArmPkg: Allow SMC/HVC monitor conduit to be specified at runtime

2024-05-23 Thread Doug Flick via groups.io
From: Ard Biesheuvel 

ArmVirtQemu may execute at EL2, in which case monitor calls are
generally made using SMC instructions instead of HVC instructions.

Whether or not this is the case can only be decided at runtime, and so
the associated PCD needs to be settable at runtime, if the platform
definition chooses so. This implies a boolean PCD, given that a feature
PCD is build-time configurable only.

Cc: Leif Lindholm 
Cc: Ard Biesheuvel 
Cc: Sami Mujawar 

Committed-by: Ard Biesheuvel 
Signed-off-by: Doug Flick [MSFT] 
---
 ArmPkg/ArmPkg.dec| 10 +-
 ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.c |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/ArmPkg/ArmPkg.dec b/ArmPkg/ArmPkg.dec
index 7fe2b9bca4..ac030e295b 100644
--- a/ArmPkg/ArmPkg.dec
+++ b/ArmPkg/ArmPkg.dec
@@ -139,11 +139,6 @@
   # Define if the GICv3 controller should use the GICv2 legacy
   gArmTokenSpaceGuid.PcdArmGicV3WithV2Legacy|FALSE|BOOLEAN|0x0042
 
-  ## Define the conduit to use for monitor calls.
-  # Default PcdMonitorConduitHvc = FALSE, conduit = SMC
-  # If PcdMonitorConduitHvc = TRUE, conduit = HVC
-  gArmTokenSpaceGuid.PcdMonitorConduitHvc|FALSE|BOOLEAN|0x0047
-
   # Whether to remap all unused memory NX before installing the CPU arch
   # protocol driver. This is needed on platforms that map all DRAM with RWX
   # attributes initially, and can be disabled otherwise.
@@ -317,6 +312,11 @@
   gArmTokenSpaceGuid.PcdSystemBiosRelease|0x|UINT16|0x3058
   
gArmTokenSpaceGuid.PcdEmbeddedControllerFirmwareRelease|0x|UINT16|0x3059
 
+  ## Define the conduit to use for monitor calls.
+  # Default PcdMonitorConduitHvc = FALSE, conduit = SMC
+  # If PcdMonitorConduitHvc = TRUE, conduit = HVC
+  gArmTokenSpaceGuid.PcdMonitorConduitHvc|FALSE|BOOLEAN|0x0047
+
 [PcdsFixedAtBuild.common, PcdsDynamic.common]
   #
   # ARM Architectural Timer
diff --git a/ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.c 
b/ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.c
index 741f5c6157..ec5b0b6619 100644
--- a/ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.c
+++ b/ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.c
@@ -26,7 +26,7 @@ ArmMonitorCall (
   IN OUT ARM_MONITOR_ARGS  *Args
   )
 {
-  if (FeaturePcdGet (PcdMonitorConduitHvc)) {
+  if (PcdGetBool (PcdMonitorConduitHvc)) {
 ArmCallHvc ((ARM_HVC_ARGS *)Args);
   } else {
 ArmCallSmc ((ARM_SMC_ARGS *)Args);
-- 
2.34.1



[edk2-devel] [PATCH v3 09/20] NetworkPkg: TcpDxe: SECURITY PATCH CVE-2023-45236

2024-05-23 Thread Doug Flick via groups.io
From: Doug Flick 

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4541
REF: https://www.rfc-editor.org/rfc/rfc1948.txt
REF: https://www.rfc-editor.org/rfc/rfc6528.txt
REF: https://www.rfc-editor.org/rfc/rfc9293.txt

Bug Overview:
PixieFail Bug #8
CVE-2023-45236
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:L/I:N/A:N
CWE-200 Exposure of Sensitive Information to an Unauthorized Actor

Updates TCP ISN generation to use a cryptographic hash of the
connection's identifying parameters and a secret key.
This prevents an attacker from guessing the ISN used for some other
connection.

This is follows the guidance in RFC 1948, RFC 6528, and RFC 9293.

RFC: 9293 Section 3.4.1.  Initial Sequence Number Selection

   A TCP implementation MUST use the above type of "clock" for clock-
   driven selection of initial sequence numbers (MUST-8), and SHOULD
   generate its initial sequence numbers with the expression:

   ISN = M + F(localip, localport, remoteip, remoteport, secretkey)

   where M is the 4 microsecond timer, and F() is a pseudorandom
   function (PRF) of the connection's identifying parameters ("localip,
   localport, remoteip, remoteport") and a secret key ("secretkey")
   (SHLD-1).  F() MUST NOT be computable from the outside (MUST-9), or
   an attacker could still guess at sequence numbers from the ISN used
   for some other connection.  The PRF could be implemented as a
   cryptographic hash of the concatenation of the TCP connection
   parameters and some secret data.  For discussion of the selection of
   a specific hash algorithm and management of the secret key data,
   please see Section 3 of [42].

   For each connection there is a send sequence number and a receive
   sequence number.  The initial send sequence number (ISS) is chosen by
   the data sending TCP peer, and the initial receive sequence number
   (IRS) is learned during the connection-establishing procedure.

   For a connection to be established or initialized, the two TCP peers
   must synchronize on each other's initial sequence numbers.  This is
   done in an exchange of connection-establishing segments carrying a
   control bit called "SYN" (for synchronize) and the initial sequence
   numbers.  As a shorthand, segments carrying the SYN bit are also
   called "SYNs".  Hence, the solution requires a suitable mechanism for
   picking an initial sequence number and a slightly involved handshake
   to exchange the ISNs.

Cc: Saloni Kasbekar 
Cc: Zachary Clark-williams 

Signed-off-by: Doug Flick [MSFT] 
---
 NetworkPkg/TcpDxe/TcpDxe.inf  |   8 +-
 NetworkPkg/TcpDxe/TcpFunc.h   |  23 +-
 NetworkPkg/TcpDxe/TcpMain.h   |  59 -
 NetworkPkg/TcpDxe/TcpDriver.c |  92 +++-
 NetworkPkg/TcpDxe/TcpInput.c  |  13 +-
 NetworkPkg/TcpDxe/TcpMisc.c   | 244 ++--
 NetworkPkg/TcpDxe/TcpTimer.c  |   3 +-
 NetworkPkg/SecurityFixes.yaml |  22 ++
 8 files changed, 415 insertions(+), 49 deletions(-)

diff --git a/NetworkPkg/TcpDxe/TcpDxe.inf b/NetworkPkg/TcpDxe/TcpDxe.inf
index cf5423f4c5..76de4cf9ec 100644
--- a/NetworkPkg/TcpDxe/TcpDxe.inf
+++ b/NetworkPkg/TcpDxe/TcpDxe.inf
@@ -6,6 +6,7 @@
 #  stack has been loaded in system. This driver supports both IPv4 and IPv6 
network stack.
 #
 #  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
+#  Copyright (c) Microsoft Corporation
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -68,7 +69,6 @@
   NetLib
   IpIoLib
 
-
 [Protocols]
   ## SOMETIMES_CONSUMES
   ## SOMETIMES_PRODUCES
@@ -81,6 +81,12 @@
   gEfiIp6ServiceBindingProtocolGuid ## TO_START
   gEfiTcp6ProtocolGuid  ## BY_START
   gEfiTcp6ServiceBindingProtocolGuid## BY_START
+  gEfiHash2ProtocolGuid ## BY_START
+  gEfiHash2ServiceBindingProtocolGuid   ## BY_START
+
+[Guids]
+  gEfiHashAlgorithmMD5Guid  ## CONSUMES
+  gEfiHashAlgorithmSha256Guid   ## CONSUMES
 
 [Depex]
   gEfiHash2ServiceBindingProtocolGuid
diff --git a/NetworkPkg/TcpDxe/TcpFunc.h b/NetworkPkg/TcpDxe/TcpFunc.h
index a7af01fff2..c707bee3e5 100644
--- a/NetworkPkg/TcpDxe/TcpFunc.h
+++ b/NetworkPkg/TcpDxe/TcpFunc.h
@@ -2,7 +2,7 @@
   Declaration of external functions shared in TCP driver.
 
   Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
-
+  Copyright (c) Microsoft Corporation
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -36,8 +36,11 @@ VOID
 
   @param[in, out]  Tcb   Pointer to the TCP_CB of this TCP 
instance.
 
+  @retval EFI_SUCCESS The operation completed successfully
+  @retval others  The underlying functions failed and could 
not complete the operation
+
 **/
-VOID
+EFI_STATUS
 TcpInitTcbLocal (
   IN OUT TCP_CB  *Tcb
   );
@@ -128,17 +131,6 @@ TcpCloneTcb (
   IN TCP_CB  *Tcb
   );
 
-/**
-  Compute an ISS to be used by a new connection.
-
-  @return The result ISS.
-
-**/
-TCP_SEQNO
-TcpGetIss (
-  VOID
-  );
-
 /**
   Get the local mss.
 
@@ -202,8 

[edk2-devel] [PATCH v3 11/20] MdePkg: : Adds Protocol for MockRng

2024-05-23 Thread Doug Flick via groups.io
From: Doug Flick 

This patch adds a protocol for MockRng. This protocol is used to
mock the Rng protocol for testing purposes.

Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Zhiguang Liu 

Signed-off-by: Doug Flick [MSFT] 
---
 MdePkg/Test/Mock/Include/GoogleTest/Protocol/MockRng.h   | 48 

 MdePkg/Test/Mock/Library/GoogleTest/Protocol/MockRng.cpp | 21 +
 2 files changed, 69 insertions(+)

diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Protocol/MockRng.h 
b/MdePkg/Test/Mock/Include/GoogleTest/Protocol/MockRng.h
new file mode 100644
index 00..b54f8a234b
--- /dev/null
+++ b/MdePkg/Test/Mock/Include/GoogleTest/Protocol/MockRng.h
@@ -0,0 +1,48 @@
+/** @file
+  This file declares a mock of Rng Protocol.
+
+  Copyright (c) Microsoft Corporation.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef MOCK_RNG_H_
+#define MOCK_RNG_H_
+
+#include 
+#include 
+
+extern "C" {
+  #include 
+  #include 
+}
+
+struct MockRng {
+  MOCK_INTERFACE_DECLARATION (MockRng);
+
+  MOCK_FUNCTION_DECLARATION (
+EFI_STATUS,
+GetInfo,
+(
+ IN EFI_RNG_PROTOCOL *This,
+ IN OUT UINTN*RNGAlgorithmListSize,
+ OUT EFI_RNG_ALGORITHM   *RNGAlgorithmList
+)
+);
+
+  MOCK_FUNCTION_DECLARATION (
+EFI_STATUS,
+GetRng,
+(
+ IN EFI_RNG_PROTOCOL*This,
+ IN EFI_RNG_ALGORITHM   *RNGAlgorithm,
+ IN UINTN   RNGValueLength,
+ OUT UINT8  *RNGValue
+)
+);
+};
+
+extern "C" {
+  extern EFI_RNG_PROTOCOL  *gRngProtocol;
+}
+
+#endif // MOCK_RNG_H_
diff --git a/MdePkg/Test/Mock/Library/GoogleTest/Protocol/MockRng.cpp 
b/MdePkg/Test/Mock/Library/GoogleTest/Protocol/MockRng.cpp
new file mode 100644
index 00..7d8b69cc86
--- /dev/null
+++ b/MdePkg/Test/Mock/Library/GoogleTest/Protocol/MockRng.cpp
@@ -0,0 +1,21 @@
+/** @file MockRng.cpp
+  Google Test mock for Rng Protocol
+
+  Copyright (c) Microsoft Corporation.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include 
+
+MOCK_INTERFACE_DEFINITION (MockRng);
+MOCK_FUNCTION_DEFINITION (MockRng, GetInfo, 3, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockRng, GetRng, 4, EFIAPI);
+
+EFI_RNG_PROTOCOL  RNG_PROTOCOL_INSTANCE = {
+  GetInfo, // EFI_RNG_GET_INFO
+  GetRng   // EFI_RNG_GET_RNG
+};
+
+extern "C" {
+  EFI_RNG_PROTOCOL  *gRngProtocol = _PROTOCOL_INSTANCE;
+}
-- 
2.34.1



[edk2-devel] [PATCH v3 10/20] MdePkg: : Add MockUefiBootServicesTableLib

2024-05-23 Thread Doug Flick via groups.io
From: Doug Flick 

This commit adds a mock library for UefiBootServicesTableLib.

Cc: Michael D Kinney 
Cc: Liming Gao 
Cc: Zhiguang Liu 

Signed-off-by: Doug Flick [MSFT] 
---
 MdePkg/Test/MdePkgHostTest.dsc 
   |  1 +
 
MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.inf
 | 32 
 MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiBootServicesTableLib.h 
   | 78 
 
MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.cpp
 | 69 +
 4 files changed, 180 insertions(+)

diff --git a/MdePkg/Test/MdePkgHostTest.dsc b/MdePkg/Test/MdePkgHostTest.dsc
index e36b7c..6a85d02236 100644
--- a/MdePkg/Test/MdePkgHostTest.dsc
+++ b/MdePkg/Test/MdePkgHostTest.dsc
@@ -43,6 +43,7 @@
   MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf
   MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUefiLib.inf
   
MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib/MockUefiRuntimeServicesTableLib.inf
+  
MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.inf
   MdePkg/Test/Mock/Library/GoogleTest/MockPeiServicesLib/MockPeiServicesLib.inf
   MdePkg/Test/Mock/Library/GoogleTest/MockHobLib/MockHobLib.inf
   MdePkg/Test/Mock/Library/GoogleTest/MockFdtLib/MockFdtLib.inf
diff --git 
a/MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.inf
 
b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.inf
new file mode 100644
index 00..8b64fd195a
--- /dev/null
+++ 
b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.inf
@@ -0,0 +1,32 @@
+## @file
+#  Mock implementation of the UEFI Boot Services Table Library.
+#
+#  Copyright (c) Microsoft Corporation.
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION= 0x00010005
+  BASE_NAME  = MockUefiBootServicesTableLib
+  FILE_GUID  = 67EA4614-E276-49EC-9AE6-B97ACCEA676E
+  MODULE_TYPE= HOST_APPLICATION
+  VERSION_STRING = 1.0
+  LIBRARY_CLASS  = UefiBootServicesTableLib|HOST_APPLICATION
+
+#
+#  VALID_ARCHITECTURES   = IA32 X64 EBC
+#
+
+[Sources]
+  MockUefiBootServicesTableLib.cpp
+
+[LibraryClasses]
+  GoogleTestLib
+
+[Packages]
+  MdePkg/MdePkg.dec
+  UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
+
+[BuildOptions]
+  MSFT:*_*_*_CC_FLAGS = /EHsc
diff --git 
a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiBootServicesTableLib.h 
b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiBootServicesTableLib.h
new file mode 100644
index 00..d72b941323
--- /dev/null
+++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiBootServicesTableLib.h
@@ -0,0 +1,78 @@
+/** @file
+  Google Test mocks for UefiBootServicesTableLib
+
+  Copyright (c) Microsoft Corporation.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef MOCK_UEFI_BOOT_SERVICES_TABLE_LIB_H_
+#define MOCK_UEFI_BOOT_SERVICES_TABLE_LIB_H_
+
+#include 
+#include 
+extern "C" {
+  #include 
+  #include 
+}
+
+//
+// Declarations to handle usage of the UefiBootServiceTableLib by creating mock
+//
+struct MockUefiBootServicesTableLib {
+  MOCK_INTERFACE_DECLARATION (MockUefiBootServicesTableLib);
+
+  MOCK_FUNCTION_DECLARATION (
+EFI_STATUS,
+gBS_GetMemoryMap,
+(IN OUT UINTN *MemoryMapSize,
+ OUTEFI_MEMORY_DESCRIPTOR *MemoryMap,
+ OUTUINTN *MapKey,
+ OUTUINTN *DescriptorSize,
+ OUTUINT32*DescriptorVersion)
+);
+
+  MOCK_FUNCTION_DECLARATION (
+EFI_STATUS,
+gBS_CreateEvent,
+(IN  UINT32   Type,
+ IN  EFI_TPL  NotifyTpl,
+ IN  EFI_EVENT_NOTIFY NotifyFunction,
+ IN  VOID *NotifyContext,
+ OUT EFI_EVENT*Event)
+);
+
+  MOCK_FUNCTION_DECLARATION (
+EFI_STATUS,
+gBS_CloseEvent,
+(IN EFI_EVENT Event)
+);
+
+  MOCK_FUNCTION_DECLARATION (
+EFI_STATUS,
+gBS_HandleProtocol,
+(IN  EFI_HANDLE Handle,
+ IN  EFI_GUID   *Protocol,
+ OUT VOID   **Interface)
+);
+
+  MOCK_FUNCTION_DECLARATION (
+EFI_STATUS,
+gBS_LocateProtocol,
+(IN  EFI_GUID *Protocol,
+ IN  VOID  *Registration  OPTIONAL,
+ OUT VOID  **Interface)
+);
+
+  MOCK_FUNCTION_DECLARATION (
+EFI_STATUS,
+gBS_CreateEventEx,
+(IN UINT32Type,
+ IN EFI_TPL   NotifyTpl,
+ IN EFI_EVENT_NOTIFY  NotifyFunction OPTIONAL,
+ IN CONST VOID*NotifyContext OPTIONAL,
+ IN CONST EFI_GUID*EventGroup OPTIONAL,
+ OUT EFI_EVENT*Event)
+);
+};
+
+#endif // MOCK_UEFI_BOOT_SERVICES_TABLE_LIB_H_
diff --git 

[edk2-devel] [PATCH v3 06/20] ArmVirtPkg: : Add Hash2DxeCrypto to ArmVirtPkg

2024-05-23 Thread Doug Flick via groups.io
This patch adds Hash2DxeCrypto to ArmVirtPkg. The Hash2DxeCrypto is
used to provide the hashing protocol services.

Cc: Ard Biesheuvel 
Cc: Leif Lindholm 
Cc: Sami Mujawar 
Cc: Gerd Hoffmann 

Signed-off-by: Doug Flick [MSFT] 
---
 ArmVirtPkg/ArmVirtQemu.dsc   | 5 +
 ArmVirtPkg/ArmVirtQemuKernel.dsc | 5 +
 ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc | 5 +
 3 files changed, 15 insertions(+)

diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
index 7e2ff33ad1..1d3315ad3e 100644
--- a/ArmVirtPkg/ArmVirtQemu.dsc
+++ b/ArmVirtPkg/ArmVirtQemu.dsc
@@ -554,6 +554,11 @@
   MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf
   MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf
 
+  #
+  # Hash2 Protocol Support
+  #
+  SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
+
   #
   # TPM2 support
   #
diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKernel.dsc
index efe2df97bd..94f48593c2 100644
--- a/ArmVirtPkg/ArmVirtQemuKernel.dsc
+++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc
@@ -461,6 +461,11 @@
   MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf
   MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf
 
+  #
+  # Hash2 Protocol Support
+  #
+  SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
+
   #
   # ACPI Support
   #
diff --git a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc 
b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc
index c5d097ffb9..80d420023e 100644
--- a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc
+++ b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc
@@ -177,6 +177,11 @@ READ_LOCK_STATUS   = TRUE
   INF MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf
   INF MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf
 
+  #
+  # Hash2 Protocol producer
+  #
+  INF SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
+
   #
   # TPM2 support
   #
-- 
2.34.1



[edk2-devel] [PATCH v3 07/20] SecurityPkg: RngDxe: Remove incorrect limitation on GetRng

2024-05-23 Thread Doug Flick via groups.io
Removed from gEfiRngAlgorithmRaw an incorrect assumption that
Raw cannot return less than 256 bits. The DRNG Algorithms
should always use a 256 bit seed as per nist standards
however a caller is free to request less than 256 bits.
>
> //
>// When a DRBG is used on the output of a entropy source,
>// its security level must be at least 256 bits according to UEFI
Spec.
>//
>if (RNGValueLength < 32) {
>  return EFI_INVALID_PARAMETER;
>}
>

AARCH64 platforms do not have this limitation and this brings both
implementations into alignment with each other and the spec.

Cc: Jiewen Yao 

Signed-off-by: Doug Flick [MSFT] 
Reviewed-by: Ard Biesheuvel 
---
 SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c | 8 
 1 file changed, 8 deletions(-)

diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c 
b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c
index 7e06e16e4b..5723ed6957 100644
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c
+++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c
@@ -116,14 +116,6 @@ RngGetRNG (
   // The "raw" algorithm is intended to provide entropy directly
   //
   if (CompareGuid (RNGAlgorithm, )) {
-//
-// When a DRBG is used on the output of a entropy source,
-// its security level must be at least 256 bits according to UEFI Spec.
-//
-if (RNGValueLength < 32) {
-  return EFI_INVALID_PARAMETER;
-}
-
 Status = GenerateEntropy (RNGValueLength, RNGValue);
 return Status;
   }
-- 
2.34.1



[edk2-devel] [PATCH v3 05/20] ArmVirtPkg:PlatformCI: Support virtio-rng-pci

2024-05-23 Thread Doug Flick via groups.io
This patch adds "virtio-rng-pci" to the PlatformBuildLib.py
This adds Rng services to the guest VM

Cc: Ard Biesheuvel 
Cc: Leif Lindholm 
Cc: Sami Mujawar 
Cc: Gerd Hoffmann 

Signed-off-by: Doug Flick [MSFT] 
---
 ArmVirtPkg/PlatformCI/PlatformBuildLib.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/ArmVirtPkg/PlatformCI/PlatformBuildLib.py 
b/ArmVirtPkg/PlatformCI/PlatformBuildLib.py
index 0ddaccf9c2..3abab09141 100644
--- a/ArmVirtPkg/PlatformCI/PlatformBuildLib.py
+++ b/ArmVirtPkg/PlatformCI/PlatformBuildLib.py
@@ -240,6 +240,8 @@ class PlatformBuilder(UefiBuilder, BuildSettingsManager):
 args += " -serial stdio"
 # Mount disk with startup.nsh
 args += f" -drive file=fat:rw:{VirtualDrive},format=raw,media=disk"
+# Provides Rng services to the Guest VM
+args += " -device virtio-rng-pci"
 
 # Conditional Args
 if (self.env.GetValue("QEMU_HEADLESS").upper() == "TRUE"):
-- 
2.34.1



[edk2-devel] [PATCH v3 04/20] OvmfPkg: : Add Hash2DxeCrypto to OvmfPkg

2024-05-23 Thread Doug Flick via groups.io
From: Doug Flick 

This patch adds Hash2DxeCrypto to OvmfPkg. The Hash2DxeCrypto is
used to provide the hashing protocol services.

Cc: Ard Biesheuvel 
Cc: Jiewen Yao 
Cc: Gerd Hoffmann 

Signed-off-by: Doug Flick [MSFT] 
---
 OvmfPkg/OvmfPkgIa32.dsc| 6 +-
 OvmfPkg/OvmfPkgIa32X64.dsc | 6 +-
 OvmfPkg/OvmfPkgX64.dsc | 6 +-
 OvmfPkg/OvmfXen.dsc| 5 +
 OvmfPkg/OvmfPkgIa32.fdf| 5 +
 OvmfPkg/OvmfPkgIa32X64.fdf | 5 +
 OvmfPkg/OvmfPkgX64.fdf | 5 +
 OvmfPkg/OvmfXen.fdf| 5 +
 8 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index 1be021be71..2ca005d768 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -229,7 +229,6 @@
   
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
   
VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
 
-
   #
   # Network libraries
   #
@@ -858,6 +857,11 @@
   MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf
   
MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf
 
+  #
+  # Hash2 Protocol producer
+  #
+  SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
+
   #
   # Network Support
   #
diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index d27a4c7278..a39070a626 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -234,7 +234,6 @@
   
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
   
VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
 
-
   #
   # Network libraries
   #
@@ -872,6 +871,11 @@
   MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf
   
MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf
 
+  #
+  # Hash2 Protocol producer
+  #
+  SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
+
   #
   # Network Support
   #
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index 8f5cd23b2e..1b90aa8f57 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -250,7 +250,6 @@
   
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
   
VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
 
-
   #
   # Network libraries
   #
@@ -940,6 +939,11 @@
   MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf
   
MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf
 
+  #
+  # Hash2 Protocol producer
+  #
+  SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
+
   #
   # Network Support
   #
diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index fa1a570e74..7fc340d1c1 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -667,6 +667,11 @@
   MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf
   
MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf
 
+  #
+  # Hash2 Protocol producer
+  #
+  SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
+
   #
   # Network Support
   #
diff --git a/OvmfPkg/OvmfPkgIa32.fdf b/OvmfPkg/OvmfPkgIa32.fdf
index 6eb26f7d46..0d4abb50a8 100644
--- a/OvmfPkg/OvmfPkgIa32.fdf
+++ b/OvmfPkg/OvmfPkgIa32.fdf
@@ -295,6 +295,11 @@ INF  OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf
 
 INF MdeModulePkg/Logo/LogoDxe.inf
 
+#
+# Hash2 Protocol producer
+#
+INF SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
+
 #
 # Network modules
 #
diff --git a/OvmfPkg/OvmfPkgIa32X64.fdf b/OvmfPkg/OvmfPkgIa32X64.fdf
index 080784f722..23a825a012 100644
--- a/OvmfPkg/OvmfPkgIa32X64.fdf
+++ b/OvmfPkg/OvmfPkgIa32X64.fdf
@@ -296,6 +296,11 @@ INF  OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf
 
 INF MdeModulePkg/Logo/LogoDxe.inf
 
+#
+# Hash2 Protocol producer
+#
+INF SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
+
 #
 # Network modules
 #
diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf
index b6e8f43566..4dcd6a033c 100644
--- a/OvmfPkg/OvmfPkgX64.fdf
+++ b/OvmfPkg/OvmfPkgX64.fdf
@@ -329,6 +329,11 @@ INF MdeModulePkg/Logo/LogoDxe.inf
 
 INF OvmfPkg/TdxDxe/TdxDxe.inf
 
+#
+# Hash2 Protocol producer
+#
+INF SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
+
 #
 # Network modules
 #
diff --git a/OvmfPkg/OvmfXen.fdf b/OvmfPkg/OvmfXen.fdf
index 5770b17316..41368f37e2 100644
--- a/OvmfPkg/OvmfXen.fdf
+++ b/OvmfPkg/OvmfXen.fdf
@@ -314,6 +314,11 @@ INF  ShellPkg/Application/Shell/Shell.inf
 
 INF MdeModulePkg/Logo/LogoDxe.inf
 
+#
+# Hash2 Protocol producer
+#
+INF SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
+
 #
 # Network modules
 #
-- 
2.34.1



[edk2-devel] [PATCH v3 03/20] OvmfPkg:PlatformCI: Support virtio-rng-pci

2024-05-23 Thread Doug Flick via groups.io
This patch adds "virtio-rng-pci" to the PlatformBuildLib.py
This adds Rng services to the guest VM

Cc: Ard Biesheuvel 
Cc: Jiewen Yao 
Cc: Gerd Hoffmann 

Signed-off-by: Doug Flick [MSFT] 
---
 OvmfPkg/PlatformCI/PlatformBuildLib.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/OvmfPkg/PlatformCI/PlatformBuildLib.py 
b/OvmfPkg/PlatformCI/PlatformBuildLib.py
index 00d454954b..3fe80f5c1c 100644
--- a/OvmfPkg/PlatformCI/PlatformBuildLib.py
+++ b/OvmfPkg/PlatformCI/PlatformBuildLib.py
@@ -208,6 +208,8 @@ class PlatformBuilder( UefiBuilder, BuildSettingsManager):
 args += " -net none"# 
turn off network
 args += " -smp 4"
 args += f" -drive file=fat:rw:{VirtualDrive},format=raw,media=disk" # 
Mount disk with startup.nsh
+# Provides Rng services to the Guest VM
+args += " -device virtio-rng-pci"
 
 if (self.env.GetValue("QEMU_HEADLESS").upper() == "TRUE"):
 args += " -display none"  # no graphics
-- 
2.34.1



[edk2-devel] [PATCH v3 01/20] EmulatorPkg: : Add RngDxe to EmulatorPkg

2024-05-23 Thread Doug Flick via groups.io
This patch adds RngDxe to EmulatorPkg. The RngDxe is used to provide
random number generation services to the UEFI firmware.

Cc: Andrew Fish 
Cc: Ray Ni 

Signed-off-by: Doug Flick [MSFT] 
Reviewed-by: Ray Ni 
---
 EmulatorPkg/EmulatorPkg.dsc | 7 ++-
 EmulatorPkg/EmulatorPkg.fdf | 6 +-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/EmulatorPkg/EmulatorPkg.dsc b/EmulatorPkg/EmulatorPkg.dsc
index 5fa1ed345a..0a66294cb7 100644
--- a/EmulatorPkg/EmulatorPkg.dsc
+++ b/EmulatorPkg/EmulatorPkg.dsc
@@ -127,9 +127,9 @@
   ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
   FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf
   
ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf
+  RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf
 
 !if $(SECURE_BOOT_ENABLE) == TRUE
-  RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf
   IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf
   OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf
   
PlatformSecureLib|SecurityPkg/Library/PlatformSecureLibNull/PlatformSecureLibNull.inf
@@ -398,6 +398,11 @@
   EmulatorPkg/PlatformSmbiosDxe/PlatformSmbiosDxe.inf
   EmulatorPkg/TimerDxe/Timer.inf
 
+  #
+  # Rng Protocol producer
+  #
+  SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
+
 !if $(SECURE_BOOT_ENABLE) == TRUE
   SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf
 !endif
diff --git a/EmulatorPkg/EmulatorPkg.fdf b/EmulatorPkg/EmulatorPkg.fdf
index 5420756eaa..d756c144d9 100644
--- a/EmulatorPkg/EmulatorPkg.fdf
+++ b/EmulatorPkg/EmulatorPkg.fdf
@@ -193,6 +193,11 @@ INF  RuleOverride = UI 
MdeModulePkg/Application/UiApp/UiApp.inf
 INF  MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenuApp.inf
 INF  MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf
 
+#
+# Rng Protocol producer
+#
+INF  SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
+
 #
 # Secure Boot Key Enroll
 #
@@ -320,4 +325,3 @@ INF  ShellPkg/Application/Shell/Shell.inf
 UISTRING="$(MODULE_NAME)" Optional
 VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
   }
-
-- 
2.34.1



[edk2-devel] [PATCH v3 00/20] NetworkPkg: CVE-2023-45236 and CVE-2023-45237

2024-05-23 Thread Doug Flick via groups.io

REF:https://blog.quarkslab.com/pixiefail-nine-vulnerabilities-in-tianocores-edk-ii-ipv6-network-stack.html

This patch series patches the following CVEs:
- CVE-2023-45236: Predictable TCP Initial Sequence Numbers
- CVE-2023-45237: Use of a Weak PseudoRandom Number Generator

In order to patch these CVEs, the following changes were made:
- NetworkPkg no longer performs it's own random number generation,
  instead it uses EFI_RNG_PROTOCOL provided by the plaform to
  generate random numbers.
  - This change was made such that any future random number
generation vulnerabilities will be a result of the platforms
implementation of the EFI_RNG_PROTOCOL and not the NetworkPkg

- NetworkPkg uses the TCP initial sequence number algorithm as described
  in RFC 6528 to generate the initial sequence number for TCP connections.
  - This change was made to ensure that the initial sequence number
is not predictable and therefore cannot be used in a TCP hijacking
attack.

In addition to the above changes, the following changes were made:
- EmulatorPkg OvmfPkg, and ArmVirtPkg were updated to include the
  Hash2DxeCrypto driver to support TCP ISN generation using
  EFI_HASH2_PROTOCOL

- EmulatorPkg was updated to include the
  RngDxe driver to support random number generation using the
  EFI_RNG_PROTOCOL

- OvmfPkg, and ArmVirtPkg were updated to include the
  virtio-rng-pci device to support random number generation using the
  EFI_RNG_PROTOCOL using the existing VirtioRngDxe driver

- SecurityPkg was updated to fix an incorrect limitation on the
  GetRng function in the RngDxe driver where the minimum amount of
  random data that could be requested was 32 bytes (256 bits) instead
  of what the caller requested

- MdePkg was updated to include MockUefiBootServicesTableLib,
  MockRng, and MockHash2 protocols for testing

- NetworkPkg was updated to include a test for the PxeBcDhcp6 driver
  due to underlying changes

- ArmPkg was updated to allow the SMC/HVC monitor conduit to be
  specified at runtime

- MdePkg was updated to remove an overzealous ASSERT in BaseRngLib

- ArmVirtPkg was updated to permit the use of dynamic PCDs in PEI

- ArmVirtPkg was updated to use dynamic PCDs to set the SMCCC conduit

- ArmVirtPkg was updated to add the RngDxe driver

Cc: Liming Gao 

Signed-off-by: Doug Flick [MSFT] 

Ard Biesheuvel (6):
  ArmPkg: Allow SMC/HVC monitor conduit to be specified at runtime
  MdePkg/BaseRngLib AARCH64: Remove overzealous ASSERT()
  ArmVirtPkg/ArmVirtQemu: Permit the use of dynamic PCDs in PEI
  ArmVirtPkg: Use dynamic PCD to set the SMCCC conduit
  ArmVirtPkg: Reverse inclusion order of MdeLibs.inc and ArmVirt.dsc.inc
  ArmVirtPkg/ArmVirtQemu: Add RngDxe driver

Doug Flick (8):
  EmulatorPkg: : Add Hash2DxeCrypto to EmulatorPkg
  OvmfPkg: : Add Hash2DxeCrypto to OvmfPkg
  NetworkPkg:: SECURITY PATCH CVE-2023-45237
  NetworkPkg: TcpDxe: SECURITY PATCH CVE-2023-45236
  MdePkg: : Add MockUefiBootServicesTableLib
  MdePkg: : Adds Protocol for MockRng
  MdePkg: Add MockHash2 Protocol for testing
  NetworkPkg: Update the PxeBcDhcp6GoogleTest due to underlying changes

Flickdm (6):
  EmulatorPkg: : Add RngDxe to EmulatorPkg
  OvmfPkg:PlatformCI: Support virtio-rng-pci
  ArmVirtPkg:PlatformCI: Support virtio-rng-pci
  ArmVirtPkg: : Add Hash2DxeCrypto to ArmVirtPkg
  SecurityPkg: RngDxe: Remove incorrect limitation on GetRng
  ArmVirtPkg: Move PcdMonitorConduitHvc

 ArmPkg/ArmPkg.dec  
   |  10 +-
 NetworkPkg/NetworkPkg.dec  
   |   7 +
 ArmVirtPkg/ArmVirt.dsc.inc 
   |   5 +-
 ArmVirtPkg/ArmVirtCloudHv.dsc  
   |   3 +
 ArmVirtPkg/ArmVirtKvmTool.dsc  
   |   4 +-
 ArmVirtPkg/ArmVirtQemu.dsc 
   |  20 +-
 ArmVirtPkg/ArmVirtQemuKernel.dsc   
   |  12 +-
 ArmVirtPkg/ArmVirtXen.dsc  
   |   6 +-
 EmulatorPkg/EmulatorPkg.dsc
   |  14 +-
 MdePkg/Test/MdePkgHostTest.dsc 
   |   1 +
 NetworkPkg/Test/NetworkPkgHostTest.dsc 
   |   1 +
 OvmfPkg/OvmfPkgIa32.dsc
   |   6 +-
 OvmfPkg/OvmfPkgIa32X64.dsc 
   |   6 +-
 OvmfPkg/OvmfPkgX64.dsc 
   |   6 +-
 OvmfPkg/OvmfXen.dsc 

[edk2-devel] [PATCH v3 02/20] EmulatorPkg: : Add Hash2DxeCrypto to EmulatorPkg

2024-05-23 Thread Doug Flick via groups.io
From: Doug Flick 

This patch adds Hash2DxeCrypto to EmulatorPkg. The Hash2DxeCrypto is
used to provide the hashing protocol services.

Cc: Andrew Fish 
Cc: Ray Ni 

Signed-off-by: Doug Flick [MSFT] 
---
 EmulatorPkg/EmulatorPkg.dsc | 9 +++--
 EmulatorPkg/EmulatorPkg.fdf | 5 +
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/EmulatorPkg/EmulatorPkg.dsc b/EmulatorPkg/EmulatorPkg.dsc
index 0a66294cb7..1c356bc8c7 100644
--- a/EmulatorPkg/EmulatorPkg.dsc
+++ b/EmulatorPkg/EmulatorPkg.dsc
@@ -128,10 +128,11 @@
   FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf
   
ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf
   RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf
-
-!if $(SECURE_BOOT_ENABLE) == TRUE
   IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf
   OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf
+  BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
+
+!if $(SECURE_BOOT_ENABLE) == TRUE
   
PlatformSecureLib|SecurityPkg/Library/PlatformSecureLibNull/PlatformSecureLibNull.inf
   AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf
   
SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.inf
@@ -402,6 +403,10 @@
   # Rng Protocol producer
   #
   SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
+  #
+  # Hash2 Protocol producer
+  #
+  SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
 
 !if $(SECURE_BOOT_ENABLE) == TRUE
   SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf
diff --git a/EmulatorPkg/EmulatorPkg.fdf b/EmulatorPkg/EmulatorPkg.fdf
index d756c144d9..73d5b0068d 100644
--- a/EmulatorPkg/EmulatorPkg.fdf
+++ b/EmulatorPkg/EmulatorPkg.fdf
@@ -198,6 +198,11 @@ INF  
MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf
 #
 INF  SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
 
+#
+# Hash2 Protocol producer
+#
+INF  SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
+
 #
 # Secure Boot Key Enroll
 #
-- 
2.34.1



Re: [edk2-devel] [edk2-platforms][PATCH 2/3] Platform/AMD: Update Readme.md

2024-05-23 Thread Abdul Lateef Attar via groups.io
Reviewed-by: Abdul Lateef Attar 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119205): https://edk2.groups.io/g/devel/message/119205
Mute This Topic: https://groups.io/mt/106257080/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [edk2-platforms][PATCH 1/3] Platform/AMD: Initial commit of cross platform/board interfaces

2024-05-23 Thread Abdul Lateef Attar via groups.io
Reviewed-by: Abdul Lateef Attar  ( 
abdullateef.at...@amd.com )


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119204): https://edk2.groups.io/g/devel/message/119204
Mute This Topic: https://groups.io/mt/106257082/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [edk2-platforms][PATCH 3/3] edk2-platform/Maintainer: Add entries for AMD packages

2024-05-23 Thread Paul via groups.io
[AMD Official Use Only - AMD Internal Distribution Only]


Reviewed-by: Paul Grimes mailto:paul.gri...@amd.com>>

From: devel@edk2.groups.io  on behalf of Abdul Lateef 
Attar via groups.io 
Sent: Thursday, May 23, 2024 7:00:03 PM
To: devel@edk2.groups.io ; michael.d.kin...@intel.com 
; Chang, Abner 
Cc: Leif Lindholm 
Subject: Re: [edk2-devel] [edk2-platforms][PATCH 3/3] edk2-platform/Maintainer: 
Add entries for AMD packages

Caution: This message originated from an External Source. Use proper caution 
when opening attachments, clicking links, or responding.


Reviewed-by: Abdul Lateef Attar 


On 23-05-2024 21:57, Michael D Kinney via groups.io wrote:

Caution: This message originated from an External Source. Use proper caution 
when opening attachments, clicking links, or responding.


Reviewed-by: Michael D Kinney 




-Original Message-
From: abner.ch...@amd.com 

Sent: Wednesday, May 22, 2024 9:12 PM
To: devel@edk2.groups.io
Cc: Leif Lindholm 
; Kinney, Michael D

Subject: [edk2-platforms][PATCH 3/3] edk2-platform/Maintainer: Add entries
for AMD packages

From: Abner Chang 

Signed-off-by: Abner Chang 
Cc: Leif Lindholm 
Cc: Michael D Kinney 

---
 Maintainers.txt | 14 +-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/Maintainers.txt b/Maintainers.txt
index 877620a1b0..af688c3813 100644
--- a/Maintainers.txt
+++ b/Maintainers.txt
@@ -86,8 +86,20 @@ M: Leif Lindholm 

 AMD
 F: Platform/AMD
 M: Abner Chang 
-M: Abdul Lateef Attar 
+M: Abdul Lateef Attar 

+M: Paul Grimes 
+
+F: Platform/AMD/AgesaModulePkg
+F: Platform/AMD/AgesaPkg
+F: Platform/AMD/AmdCbsPkg
+M: Paul Grimes 
+R: Abdul Lateef Attar 

+R: Abner Chang 
+
+F: Platform/AMD/AmdCpmPkg
+M: Abdul Lateef Attar 

 R: Paul Grimes 
+R: Abner Chang 

 AMD Seattle
 F: Platform/AMD/OverdriveBoard/
--
2.37.1.windows.1













-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119203): https://edk2.groups.io/g/devel/message/119203
Mute This Topic: https://groups.io/mt/106257081/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [edk2-platforms][PATCH 2/3] Platform/AMD: Update Readme.md

2024-05-23 Thread Paul via groups.io
[AMD Official Use Only - AMD Internal Distribution Only]

Thanks for the up-stream, Abner.

Looks good to me.

Reviewed-by: Paul Grimes 

From: Yao, Ken 
Sent: Thursday, May 23, 2024 1:30:48 AM
To: Zhai, MingXin (Duke) ; Chang, Abner 
; devel@edk2.groups.io 
Cc: Grimes, Paul ; Attar, AbdulLateef (Abdul Lateef) 
; Fu, Igniculus ; Xing, Eric 

Subject: RE: [edk2-platforms][PATCH 2/3] Platform/AMD: Update Readme.md

[AMD Official Use Only - AMD Internal Distribution Only]

[AMD Official Use Only - AMD Internal Distribution Only]

Thanks Abner for the up-stream.

Looks good to me.

Reviewed-by: Ken Yao 
-Original Message-
From: Zhai, MingXin (Duke) 
Sent: Thursday, May 23, 2024 3:47 PM
To: Chang, Abner ; devel@edk2.groups.io
Cc: Grimes, Paul ; Attar, AbdulLateef (Abdul Lateef) 
; Fu, Igniculus ; Yao, Ken 
; Xing, Eric 
Subject: RE: [edk2-platforms][PATCH 2/3] Platform/AMD: Update Readme.md

[AMD Official Use Only - AMD Internal Distribution Only]

Thanks Abner for the up-stream.

Looks good to me.

-Original Message-
From: Chang, Abner 
Sent: Thursday, May 23, 2024 12:12 PM
To: devel@edk2.groups.io
Cc: Grimes, Paul ; Attar, AbdulLateef (Abdul Lateef) 
; Fu, Igniculus ; Yao, Ken 
; Xing, Eric ; Zhai, MingXin (Duke) 

Subject: [edk2-platforms][PATCH 2/3] Platform/AMD: Update Readme.md

From: Abner Chang 

Cc: Paul Grimes 
Cc: Abdul Lateef Attar 
Cc: Igniculus Fu 
Cc: Ken Yao 
Cc: Eric Xing 
Cc: Duke Zhai 
Signed-off-by: Abner Chang 
---
 Platform/AMD/Readme.md | 64 --
 1 file changed, 49 insertions(+), 15 deletions(-)

diff --git a/Platform/AMD/Readme.md b/Platform/AMD/Readme.md index 
99d2b990c7..3297c6ba59 100644
--- a/Platform/AMD/Readme.md
+++ b/Platform/AMD/Readme.md
@@ -7,18 +7,25 @@ booting certain AMD platforms. The definition of sub-folders 
is described in bel

 ## Term and Definitions

+* **AGESA**
+
+  AMD Generic Encapsulated Software Architecture that are executed as
+ part of a  host platform BIOS.
+
 * **AMD Platform** (platform in short)

-  AMD platform refers to a platform that supports the particular AMD SoC 
(processor), such as AMD EPYC Milan and Genoa processors.
+  AMD platform refers to a platform that supports the particular AMD
+ SoC (processor), such as  AMD EPYC Milan and Genoa processors.

 * **AMD Board** (board in short)

   AMD board is a generic terminology refers to a board that is designed based 
on a
   specific AMD SoC architecture (also referred as AMD platform). More than one 
boards
-  are possibly designed to support an AMD platform with different 
configuration, such as 1-processor socket or 2-processor sockets board.
+  are possibly designed to support an AMD platform with different
+ configuration, such as  1-processor socket or 2-processor sockets board.

 * **AMD edk2 Platform Package** (platform package in short)
-
+
   The folder has the AMD edk2 platform common modules.

 * **AMD edk2 Board Package** (board package in short) @@ -28,29 +35,52 @@ 
booting certain AMD platforms. The definition of sub-folders is described in bel

 ## Package Definition

+* **AgesaModulePkg**
+
+  This package contains all of the private interfaces and build
+ configuration files for the  AGESA support.
+
+* **AgesaPkg**
+
+  This package contains all of the public interfaces and build
+ configuration files  for the AGESA support.
+
+* **AmdCbsPkg**
+
+  AMD Configurable BIOS Setting. Provides the edk2 formset following
+ the UEFI HII  spec to configure BIOS settings.
+
+* **AmdCpmPkg**
+
+  AMD Common Platform Module software is a BIOS procedure library
+ designed to aid  AMD customers to quickly implement AMD platform technology 
into their products.
+
 * **AmdPlatformPkg**

-  AMD platform edk2 package under this folder provides the common edk2 modules 
those
-  are leverage by platforms. Usually those modules have no dependencies with
-  particular platforms. The module under this scope can provides a common 
implementation
-  for all platforms, or it may just provide a framework but the differences of 
implementation could be configured through the PCDs declared in 
AmdPlatformPkg.dec, or
-  the board level library provided in the \Pkg.
+  AMD platform edk2 package under this folder provides the common edk2
+ modules that are leveraged by platforms. Usually those modules have no
+ dependencies with  particular platforms. Modules under this scope can
+ provide a common implementation  for all platforms, or may just
+ provide a framework but the differences of implementation  could be
+ configured through the PCDs declared in AmdPlatformPkg.dec, or the board 
level  library provided in the \Pkg.

 * **AmdMinBoardPkg**

-  This package provides the common edk2 modules those can be leverage across 
AMD boards those use MinPlatformPkg framework.
+  This package provides the common edk2 modules that can be leveraged
+ across AMD boards using  the MinPlatform framework.

 * **\Board**

-  This is 

Re: [edk2-devel] [PATCH v2 13/13] NetworkPkg: Update the PxeBcDhcp6GoogleTest due to underlying changes

2024-05-23 Thread Saloni Kasbekar
Reviewed-by: Saloni Kasbekar 

-Original Message-
From: Doug Flick  
Sent: Wednesday, May 8, 2024 10:57 PM
To: devel@edk2.groups.io
Cc: Kasbekar, Saloni ; Clark-williams, Zachary 

Subject: [PATCH v2 13/13] NetworkPkg: Update the PxeBcDhcp6GoogleTest due to 
underlying changes

From: Doug Flick 

This patch updates the PxeBcDhcp6GoogleTest due to the changes in the 
underlying code. The changes are as follows:
 - Random now comes from the RngLib Protocol
 - The TCP ISN is now generated by the hash function

Cc: Saloni Kasbekar 
Cc: Zachary Clark-williams 

Signed-off-by: Doug Flick [MSFT] 
---
 NetworkPkg/Test/NetworkPkgHostTest.dsc|   1 +
 NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf |   3 +-
 NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp   | 102 
+++-
 3 files changed, 100 insertions(+), 6 deletions(-)

diff --git a/NetworkPkg/Test/NetworkPkgHostTest.dsc 
b/NetworkPkg/Test/NetworkPkgHostTest.dsc
index fa301a7a52ab..1772afb05815 100644
--- a/NetworkPkg/Test/NetworkPkgHostTest.dsc
+++ b/NetworkPkg/Test/NetworkPkgHostTest.dsc
@@ -30,6 +30,7 @@ [Components]
   NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf { 
   
UefiRuntimeServicesTableLib|MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib/MockUefiRuntimeServicesTableLib.inf+
  
UefiBootServicesTableLib|MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.inf
   }  # Despite these library classes being listed in [LibraryClasses] below, 
they are not needed for the host-based unit tests.diff --git 
a/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf 
b/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf
index 301dcdf61109..8b092d9291d4 100644
--- a/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf
+++ b/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf
@@ -14,7 +14,7 @@ [Defines]
 # # The following information is for reference only and not required by the 
build tools. #-#  VALID_ARCHITECTURES   = IA32 X64+#  
VALID_ARCHITECTURES   = IA32 X64 AARCH64 #  [Sources]@@ -23,6 +23,7 @@ 
[Sources]
   PxeBcDhcp6GoogleTest.h   ../PxeBcDhcp6.c   ../PxeBcSupport.c+  
../../../MdePkg/Test/Mock/Library/GoogleTest/Protocol/MockRng.cpp  [Packages]   
MdePkg/MdePkg.decdiff --git 
a/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp 
b/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp
index bd423ebadfce..61736ff79e83 100644
--- a/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp
+++ b/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp
@@ -7,6 +7,8 @@
 #include  #include  
#include +#include 
+#include 
  extern "C" {   #include @@ -165,7 
+167,7 @@ protected:
 // Note: // Testing PxeBcHandleDhcp6Offer() is difficult because it depends on 
a // properly setup Private structure. Attempting to properly test this 
function-// without a signficant refactor is a fools errand. Instead, we will 
test+// without a significant refactor is a fools errand. Instead, we will test 
// that we can prevent an overflow in the function. TEST_F 
(PxeBcHandleDhcp6OfferTest, BasicUsageTest) {   PXEBC_DHCP6_PACKET_CACHE  
*Cache6 = NULL;@@ -238,6 +240,7 @@ TEST_F (PxeBcCacheDnsServerAddressesTest, 
BasicUsageTest) {
 FreePool (Option);   } }+ // Test Description // Test that we can prevent 
an overflow in the function TEST_F (PxeBcCacheDnsServerAddressesTest, 
AttemptOverflowTest) {@@ -470,10 +473,15 @@ TEST_F 
(PxeBcRequestBootServiceTest, AttemptRequestOverFlowExpectFailure) {
 class PxeBcDhcp6DiscoverTest : public ::testing::Test { public:   
PXEBC_PRIVATE_DATA Private = { 0 };+  // create a mock md5 hash+  UINT8 
Md5Hash[16] = { 0 };+   EFI_UDP6_PROTOCOL Udp6Read;  protected:   
MockUefiRuntimeServicesTableLib RtServicesMock;+  MockUefiBootServicesTableLib 
BsMock;+  MockRng RngMock;// Add any setup code if needed   virtual void@@ 
-527,8 +535,21 @@ TEST_F (PxeBcDhcp6DiscoverTest, BasicOverflowTest) {
Private.Dhcp6Request->Length = (UINT16)(Cursor - (UINT8 
*)Private.Dhcp6Request); -  EXPECT_CALL (RtServicesMock, gRT_GetTime)-
.WillOnce (::testing::Return (0));+  EXPECT_CALL (BsMock, gBS_LocateProtocol)+  
  .WillOnce (+   ::testing::DoAll (+
::testing::SetArgPointee<2> (::testing::ByRef (gRngProtocol)),+ 
   ::testing::Return (EFI_SUCCESS)+)+   );++  
EXPECT_CALL (RngMock, GetRng)+.WillOnce (+   ::testing::DoAll (+
::testing::SetArgPointee<3> (::testing::ByRef (Md5Hash[0])),+   
 ::testing::Return (EFI_SUCCESS)+)+   );
ASSERT_EQ ( PxeBcDhcp6Discover (@@ -558,8 +579,21 @@ TEST_F 
(PxeBcDhcp6DiscoverTest, BasicUsageTest) {
Private.Dhcp6Request->Length = (UINT16)(Cursor - (UINT8 
*)Private.Dhcp6Request); -  EXPECT_CALL (RtServicesMock, gRT_GetTime)-
.WillOnce 

Re: [edk2-devel] [PATCH v2 09/13] NetworkPkg: TcpDxe: SECURITY PATCH CVE-2023-45236

2024-05-23 Thread Saloni Kasbekar
No other concerns.

Reviewed-by: Saloni Kasbekar 


From: gaoliming 
Sent: Thursday, May 23, 2024 6:24 PM
To: devel@edk2.groups.io; dougfl...@microsoft.com; Kasbekar, Saloni 

Subject: 回复: [edk2-devel] [PATCH v2 09/13] NetworkPkg: TcpDxe: SECURITY PATCH 
CVE-2023-45236

Saloni:
  Have you any other comments for this patch?

Thanks
Liming
发件人: devel@edk2.groups.io 
mailto:devel@edk2.groups.io>> 代表 Doug Flick via groups.io
发送时间: 2024年5月22日 3:29
收件人: Saloni Kasbekar 
mailto:saloni.kasbe...@intel.com>>; 
devel@edk2.groups.io
主题: Re: [edk2-devel] [PATCH v2 09/13] NetworkPkg: TcpDxe: SECURITY PATCH 
CVE-2023-45236


This was more of a design decision. Both Hash2Protocol and HashLib serve 
similar purposes. The goal was to use Hash2Protocol to decouple and provide 
greater modularity and flexibility over HashLib.



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119199): https://edk2.groups.io/g/devel/message/119199
Mute This Topic: https://groups.io/mt/106276051/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 6/6] UefiPayloadPkg: Update UefiPayload driver for FDT support.

2024-05-23 Thread Linus Liu
Add FDT detection and comsume FDT when needed.
Move some x86 specific function in the x86 folder.
Create HandOffHob via FDT memory node.

Cc: Benny Lin 
Cc: Gua Guo 
Cc: Chasel Chiu 
Cc: James Lu 
Cc: Dhaval Sharma 

Signed-off-by: Linus Liu 
---
 UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.c   | 428 
+---
 UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFunc.c   |  12 
+
 UefiPayloadPkg/UefiPayloadEntry/Ia32/{DxeLoadFunc.c => DxeLoadFuncFit.c} |  32 
+-
 UefiPayloadPkg/UefiPayloadEntry/MemoryAllocation.c   |  50 
+++
 UefiPayloadPkg/UefiPayloadEntry/PrintHob.c   |   6 
+-
 UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c  |   6 
-
 UefiPayloadPkg/UefiPayloadEntry/X64/DxeLoadFunc.c|  12 
+
 UefiPayloadPkg/UefiPayloadEntry/X64/{DxeLoadFunc.c => DxeLoadFuncFit.c}  |  31 
+-
 UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.inf |  20 
+-
 UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h   |  68 

 UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf|  16 
+-
 UefiPayloadPkg/UefiPayloadPkg.dsc|  29 
+-
 12 files changed, 443 insertions(+), 267 deletions(-)

diff --git a/UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.c 
b/UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.c
index eb0b325369a0..813d656950d1 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.c
+++ b/UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.c
@@ -6,6 +6,8 @@
 #include "UefiPayloadEntry.h"
 #include 
 #include 
+#include 
+#include 
 
 #define MEMORY_ATTRIBUTE_MASK  (EFI_RESOURCE_ATTRIBUTE_PRESENT |   
 \
EFI_RESOURCE_ATTRIBUTE_INITIALIZED  
   | \
@@ -23,6 +25,15 @@
EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \
EFI_RESOURCE_ATTRIBUTE_TESTED  )
 
+EFI_MEMORY_TYPE_INFORMATION  mDefaultMemoryTypeInformation[] = {
+  { EfiACPIReclaimMemory,   FixedPcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory)  
 },
+  { EfiACPIMemoryNVS,   FixedPcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS)  
 },
+  { EfiReservedMemoryType,  FixedPcdGet32 (PcdMemoryTypeEfiReservedMemoryType) 
 },
+  { EfiRuntimeServicesData, FixedPcdGet32 
(PcdMemoryTypeEfiRuntimeServicesData) },
+  { EfiRuntimeServicesCode, FixedPcdGet32 
(PcdMemoryTypeEfiRuntimeServicesCode) },
+  { EfiMaxMemoryType,   0  
 }
+};
+
 extern VOID  *mHobList;
 
 CHAR8  *mLineBuffer = NULL;
@@ -36,6 +47,78 @@ PrintHob (
   IN CONST VOID  *HobStart
   );
 
+/**
+  Add HOB into HOB list
+  @param[in]  HobThe HOB to be added into the HOB list.
+**/
+VOID
+AddNewHob (
+  IN EFI_PEI_HOB_POINTERS  *Hob
+  );
+
+/**
+  Found the Resource Descriptor HOB that contains a range (Base, Top)
+  @param[in] HobListHob start address
+  @param[in] Base   Memory start address
+  @param[in] TopMemory end address.
+  @retval The pointer to the Resource Descriptor HOB.
+**/
+EFI_HOB_RESOURCE_DESCRIPTOR *
+FindResourceDescriptorByRange (
+  IN VOID  *HobList,
+  IN EFI_PHYSICAL_ADDRESS  Base,
+  IN EFI_PHYSICAL_ADDRESS  Top
+  );
+
+/**
+  Find the highest below 4G memory resource descriptor, except the input 
Resource Descriptor.
+  @param[in] HobList Hob start address
+  @param[in] MinimalNeededSize   Minimal needed size.
+  @param[in] ExceptResourceHob   Ignore this Resource Descriptor.
+  @retval The pointer to the Resource Descriptor HOB.
+**/
+EFI_HOB_RESOURCE_DESCRIPTOR *
+FindAnotherHighestBelow4GResourceDescriptor (
+  IN VOID *HobList,
+  IN UINTNMinimalNeededSize,
+  IN EFI_HOB_RESOURCE_DESCRIPTOR  *ExceptResourceHob
+  );
+
+/**
+  Check the HOB and decide if it is need inside Payload
+  Payload maintainer may make decision which HOB is need or needn't
+  Then add the check logic in the function.
+  @param[in] Hob The HOB to check
+  @retval TRUE  If HOB is need inside Payload
+  @retval FALSE If HOB is needn't inside Payload
+**/
+BOOLEAN
+FitIsHobNeed (
+  EFI_PEI_HOB_POINTERS  Hob
+  );
+
+/**
+  Check the HOB and decide if it is need inside Payload
+
+  Payload maintainer may make decision which HOB is need or needn't
+  Then add the check logic in the function.
+
+  @param[in] Hob The HOB to check
+
+  @retval TRUE  If HOB is need inside Payload
+  @retval FALSE If HOB is needn't inside Payload
+**/
+BOOLEAN
+IsHobNeed (
+  EFI_PEI_HOB_POINTERS  Hob
+  );
+
+VOID
+EFIAPI
+ProcessLibraryConstructorList (
+  VOID
+  );
+
 /**
   Find the first substring.
   @param  StringPoint to the string where to find the substring.
@@ -191,187 +274,6 @@ FixUpPcdDatabase (
   return EFI_SUCCESS;
 }
 
-/**
-  Add HOB into HOB list
- 

[edk2-devel] [PATCH v3 5/6] UefiPayloadPkg: Add FDT Paser relative LIBs.

2024-05-23 Thread Linus Liu
Add FDTParser and CustomFdtNodePaser
to retrive all FDT node and create the relate hobs.

Cc: Benny Lin 
Cc: Gua Guo 
Cc: Chasel Chiu 
Cc: James Lu 
Cc: Dhaval Sharma 

Signed-off-by: Linus Liu 
---
 UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.c 
  | 158 +
 UefiPayloadPkg/Library/CustomFdtNodeParserNullLib/CustomFdtNodeParserNullLib.c 
  |  51 ++
 UefiPayloadPkg/Library/FdtParserLib/FdtParserLib.c 
  | 622 
 UefiPayloadPkg/Library/HobParseLib/HobParseLib.c   
  | 408 +
 UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.inf   
  |  46 ++
 
UefiPayloadPkg/Library/CustomFdtNodeParserNullLib/CustomFdtNodeParserNullLib.inf
 |  33 ++
 UefiPayloadPkg/Library/FdtParserLib/FdtParseLib.inf
  |  63 ++
 UefiPayloadPkg/Library/HobParseLib/HobParseLib.inf 
  |  40 ++
 8 files changed, 1421 insertions(+)

diff --git 
a/UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.c 
b/UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.c
new file mode 100644
index ..d1376d21c5dd
--- /dev/null
+++ b/UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.c
@@ -0,0 +1,158 @@
+/** @file
+  Copyright (c) 2024, Intel Corporation. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+  Add a new HOB to the HOB List.
+
+  @param HobTypeType of the new HOB.
+  @param HobLength  Length of the new HOB to allocate.
+
+  @return  NULL if there is no space to create a hob.
+  @return  The address point to the new created hob.
+
+**/
+VOID *
+EFIAPI
+CreateHob (
+  IN  UINT16  HobType,
+  IN  UINT16  HobLength
+  );
+
+/**
+  Add HOB into HOB list
+  @param[in]  HobThe HOB to be added into the HOB list.
+**/
+VOID
+AddNewHob (
+  IN EFI_PEI_HOB_POINTERS  *Hob
+  );
+
+/**
+  Check the HOB and decide if it is need inside Payload
+  Payload maintainer may make decision which HOB is need or needn't
+  Then add the check logic in the function.
+  @param[in] Hob The HOB to check
+  @retval TRUE  If HOB is need inside Payload
+  @retval FALSE If HOB is needn't inside Payload
+**/
+BOOLEAN
+EFIAPI
+FitIsHobNeed (
+  EFI_PEI_HOB_POINTERS  Hob
+  )
+{
+  if (FixedPcdGetBool (PcdHandOffFdtEnable)) {
+if (Hob.Header->HobType == EFI_HOB_TYPE_HANDOFF) {
+  return FALSE;
+}
+
+if (Hob.Header->HobType == EFI_HOB_TYPE_MEMORY_ALLOCATION) {
+  if (CompareGuid (>AllocDescriptor.Name, 
)) {
+return FALSE;
+  }
+
+  if (CompareGuid 
(>MemoryAllocationHeader.Name, 
)) {
+return FALSE;
+  }
+
+  if ((Hob.MemoryAllocation->AllocDescriptor.MemoryType == 
EfiReservedMemoryType) ||
+  (Hob.MemoryAllocation->AllocDescriptor.MemoryType == 
EfiBootServicesCode) ||
+  (Hob.MemoryAllocation->AllocDescriptor.MemoryType == 
EfiBootServicesData) ||
+  (Hob.MemoryAllocation->AllocDescriptor.MemoryType == 
EfiRuntimeServicesCode) ||
+  (Hob.MemoryAllocation->AllocDescriptor.MemoryType == 
EfiRuntimeServicesData) ||
+  (Hob.MemoryAllocation->AllocDescriptor.MemoryType == 
EfiACPIReclaimMemory) ||
+  (Hob.MemoryAllocation->AllocDescriptor.MemoryType == 
EfiACPIMemoryNVS))
+  {
+return FALSE;
+  }
+}
+
+if (Hob.Header->HobType == EFI_HOB_TYPE_GUID_EXTENSION) {
+  if (CompareGuid (>Name, )) 
{
+return FALSE;
+  }
+
+  if (CompareGuid (>Name, )) {
+return FALSE;
+  }
+
+  if (CompareGuid (>Name, 
)) {
+return FALSE;
+  }
+}
+  }
+
+  // Arrive here mean the HOB is need
+  return TRUE;
+}
+
+/**
+  It will Parse FDT -custom node based on information from bootloaders.
+  @param[in]  FdtBase The starting memory address of FdtBase
+  @param[in]  HobList The starting memory address of New Hob list.
+
+**/
+UINTN
+EFIAPI
+CustomFdtNodeParser (
+  IN VOID  *FdtBase,
+  IN VOID  *HobList
+  )
+{
+  INT32 Node, CustomNode;
+  INT32 TempLen;
+  UINT64*Data64;
+  UINTN CHobList;
+  CONST FDT_PROPERTY*PropertyPtr;
+  EFI_PEI_HOB_POINTERS  Hob;
+
+  CHobList = (UINTN)HobList;
+
+  DEBUG ((DEBUG_INFO, "%a() #1 \n", __func__));
+
+  //
+  // Look for if exists hob list node
+  //
+  Node = FdtSubnodeOffsetNameLen (FdtBase, 0, "options", (INT32)AsciiStrLen 
("options"));
+  if (Node > 0) {
+DEBUG ((DEBUG_INFO, "  Found options node (%08X)", Node));
+CustomNode = FdtSubnodeOffsetNameLen (FdtBase, Node, "upl-custom", 
(INT32)AsciiStrLen ("upl-custom"));
+if (CustomNode > 0) {
+  DEBUG ((DEBUG_INFO, "  Found upl-custom node (%08X)", CustomNode));
+  PropertyPtr = FdtGetProperty (FdtBase, CustomNode, "hoblistptr", 
);

[edk2-devel] [PATCH v3 4/6] UefiPayloadPkg: Update PayloadLoader to suport FDT.

2024-05-23 Thread Linus Liu
Create FDT nodes (reserved-memory, serial, pci-rb, options) in
FdtPpiNotifyCallback function right after gEfiEndOfPeiSignalPpiGuid.

Cc: Benny Lin 
Cc: Gua Guo 
Cc: Chasel Chiu 
Cc: James Lu 
Cc: Dhaval Sharma 

Signed-off-by: Linus Liu 
---
 UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.c   | 1004 
+++-
 UefiPayloadPkg/PayloadLoaderPeim/PayloadLoaderPeim.c  |   71 +-
 UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.inf |   16 +-
 UefiPayloadPkg/PayloadLoaderPeim/PayloadLoaderPeim.inf|   12 +
 4 files changed, 1077 insertions(+), 26 deletions(-)

diff --git a/UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.c 
b/UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.c
index de33d49bd1c6..00016c7756c5 100644
--- a/UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.c
+++ b/UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.c
@@ -6,18 +6,74 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 
 #include 
 #include 
+#include 
 #include 
+#include 
 #include 
-
+#include 
 #include 
 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
-
+#include 
+#include 
+#include 
 #include "FitLib.h"
+#define STACK_SIZE  0x2
+#define N_NON_RELOCATABLE   BIT31
+#define P_NON_PREFETCHABLE  BIT30
+#define SS_CONFIGURATION_SPACE  0
+#define SS_IO_SPACE BIT24
+#define SS_32BIT_MEMORY_SPACE   BIT25
+#define SS_64BIT_MEMORY_SPACE   BIT24+BIT25
+
+CONST EFI_PEI_PPI_DESCRIPTOR  gReadyToPayloadSignalPpi = {
+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
+  ,
+  NULL
+};
+
+EFI_PEI_PPI_DESCRIPTOR  mEndOfPeiSignalPpi = {
+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
+  ,
+  NULL
+};
+
+#define MEMORY_ATTRIBUTE_DEFAULT  (EFI_RESOURCE_ATTRIBUTE_PRESENT  
 | \
+ EFI_RESOURCE_ATTRIBUTE_INITIALIZED
 | \
+ EFI_RESOURCE_ATTRIBUTE_TESTED 
 | \
+ EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
 | \
+ EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE  
 | \
+ 
EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE | \
+ 
EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE)
+
+CHAR8  *mMemoryAllocType[] = {
+  "Reserved",
+  "LoaderCode",
+  "LoaderData",
+  "boot-code",
+  "boot-data",
+  "runtime-code",
+  "runtime-data",
+  "ConventionalMemory",
+  "UnusableMemory",
+  "acpi",
+  "acpi-nvs",
+  "mmio",
+  "MemoryMappedIOPortSpace",
+  "PalCode",
+  "PersistentMemory",
+};
 
 /**
   The wrapper function of PeiLoadImageLoadImage().
@@ -50,6 +106,15 @@ PeiLoadFileLoadPayload (
   UINTN   Delta;
   UINTN   Index;
 
+ #if (FixedPcdGetBool (PcdHandOffFdtEnable))
+  VOID   *BaseOfStack;
+  VOID   *TopOfStack;
+  UNIVERSAL_PAYLOAD_DEVICE_TREE  *Fdt;
+  VOID   *Hob;
+
+  Fdt = NULL;
+ #endif
+
   Instance = 0;
   do {
 Status = PeiServicesFfsFindSectionData3 (EFI_SECTION_RAW, Instance++, 
FileHandle, , AuthenticationState);
@@ -66,13 +131,15 @@ PeiLoadFileLoadPayload (
 return Status;
   }
 
-  DEBUG ((
-DEBUG_INFO,
-"Before Rebase Payload File Base: 0x%08x, File Size: 0x%08X, EntryPoint: 
0x%08x\n",
-Context.PayloadBaseAddress,
-Context.PayloadSize,
-Context.PayloadEntryPoint
-));
+  DEBUG (
+(
+ DEBUG_INFO,
+ "Before Rebase Payload File Base: 0x%08x, File Size: 0x%08X, EntryPoint: 
0x%08x\n",
+ Context.PayloadBaseAddress,
+ Context.PayloadSize,
+ Context.PayloadEntryPoint
+)
+);
   Context.PayloadBaseAddress = (EFI_PHYSICAL_ADDRESS)AllocatePages 
(EFI_SIZE_TO_PAGES (Context.PayloadSize));
 
   RelocateTable = (FIT_RELOCATE_ITEM *)(UINTN)(Context.PayloadBaseAddress + 
Context.RelocateTableOffset);
@@ -96,13 +163,15 @@ PeiLoadFileLoadPayload (
 }
   }
 
-  DEBUG ((
-DEBUG_INFO,
-"After Rebase Payload File Base: 0x%08x, File Size: 0x%08X, EntryPoint: 
0x%08x\n",
-Context.PayloadBaseAddress,
-Context.PayloadSize,
-Context.PayloadEntryPoint
-));
+  DEBUG (
+(
+ DEBUG_INFO,
+ "After Rebase Payload File Base: 0x%08x, File Size: 0x%08X, EntryPoint: 
0x%08x\n",
+ Context.PayloadBaseAddress,
+ Context.PayloadSize,
+ Context.PayloadEntryPoint
+)
+);
 
   Length  = sizeof (UNIVERSAL_PAYLOAD_BASE);
   PayloadBase = BuildGuidHob (
@@ -115,6 +184,42 @@ PeiLoadFileLoadPayload (
   *ImageSizeArg= Context.PayloadSize;
   *EntryPoint  = Context.PayloadEntryPoint;
 
+  Status = PeiServicesInstallPpi ();
+  ASSERT_EFI_ERROR (Status);
+
+  Status = PeiServicesInstallPpi ();
+  ASSERT_EFI_ERROR (Status);
+
+ #if (FixedPcdGetBool (PcdHandOffFdtEnable))
+  Hob = GetFirstGuidHob ();
+  if 

[edk2-devel] [PATCH v3 3/6] UefiPayloadPkg: Support Debug function when Hob was not available.

2024-05-23 Thread Linus Liu
Initialize mUartInfo with PCD for debug message
when Hob was not available.

Cc: Benny Lin 
Cc: Gua Guo 
Cc: Chasel Chiu 
Cc: James Lu 
Cc: Dhaval Sharma 

Signed-off-by: Linus Liu 
---
 UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c 
| 69 
 UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c 
|  5 ++
 UefiPayloadPkg/Library/PayloadEntryHobLib/Hob.c
|  7 +-
 UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.c   
|  4 ++
 UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.inf   
| 10 +++
 UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.inf
| 13 ++--
 UefiPayloadPkg/Library/PayloadEntryHobLib/HobLib.inf   
|  1 +
 7 files changed, 104 insertions(+), 5 deletions(-)

diff --git a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c 
b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c
index 82d0dd585508..55e85dce8598 100644
--- a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c
+++ b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c
@@ -143,6 +143,75 @@ SerialPortInitialize (
 return RETURN_SUCCESS;
   }
 
+  if (GetHobList () == NULL) {
+mUartCount = 0;
+SerialRegisterBase = PcdGet64 (PcdSerialRegisterBase);
+MmioEnable = PcdGetBool (PcdSerialUseMmio);
+BaudRate   = PcdGet32 (PcdSerialBaudRate);
+RegisterStride = (UINT8)PcdGet32 (PcdSerialRegisterStride);
+
+mUartInfo[mUartCount].BaseAddress= SerialRegisterBase;
+mUartInfo[mUartCount].UseMmio= MmioEnable;
+mUartInfo[mUartCount].BaudRate   = BaudRate;
+mUartInfo[mUartCount].RegisterStride = RegisterStride;
+mUartCount++;
+
+Divisor = PcdGet32 (PcdSerialClockRate) / (BaudRate * 16);
+if ((PcdGet32 (PcdSerialClockRate) % (BaudRate * 16)) >= BaudRate * 8) {
+  Divisor++;
+}
+
+//
+// See if the serial port is already initialized
+//
+Initialized = TRUE;
+if ((SerialPortReadRegister (SerialRegisterBase, R_UART_LCR, MmioEnable, 
RegisterStride) & 0x3F) != (PcdGet8 (PcdSerialLineControl) & 0x3F)) {
+  Initialized = FALSE;
+}
+
+Value = (UINT8)(SerialPortReadRegister (SerialRegisterBase, R_UART_LCR, 
MmioEnable, RegisterStride) | B_UART_LCR_DLAB);
+SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, Value, 
MmioEnable, RegisterStride);
+CurrentDivisor  =  SerialPortReadRegister (SerialRegisterBase, 
R_UART_BAUD_HIGH, MmioEnable, RegisterStride) << 8;
+CurrentDivisor |= (UINT32)SerialPortReadRegister (SerialRegisterBase, 
R_UART_BAUD_LOW, MmioEnable, RegisterStride);
+Value   = (UINT8)(SerialPortReadRegister (SerialRegisterBase, 
R_UART_LCR, MmioEnable, RegisterStride) & ~B_UART_LCR_DLAB);
+SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, Value, 
MmioEnable, RegisterStride);
+if (CurrentDivisor != Divisor) {
+  Initialized = FALSE;
+}
+
+//
+// Configure baud rate
+//
+SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, B_UART_LCR_DLAB, 
MmioEnable, RegisterStride);
+SerialPortWriteRegister (SerialRegisterBase, R_UART_BAUD_HIGH, 
(UINT8)(Divisor >> 8), MmioEnable, RegisterStride);
+SerialPortWriteRegister (SerialRegisterBase, R_UART_BAUD_LOW, 
(UINT8)(Divisor & 0xff), MmioEnable, RegisterStride);
+
+//
+// Clear DLAB and configure Data Bits, Parity, and Stop Bits.
+// Strip reserved bits from PcdSerialLineControl
+//
+SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, (UINT8)(PcdGet8 
(PcdSerialLineControl) & 0x3F), MmioEnable, RegisterStride);
+
+//
+// Enable and reset FIFOs
+// Strip reserved bits from PcdSerialFifoControl
+//
+SerialPortWriteRegister (SerialRegisterBase, R_UART_FCR, 0x00, MmioEnable, 
RegisterStride);
+SerialPortWriteRegister (SerialRegisterBase, R_UART_FCR, (UINT8)(PcdGet8 
(PcdSerialFifoControl) & (B_UART_FCR_FIFOE | B_UART_FCR_FIFO64)), MmioEnable, 
RegisterStride);
+
+//
+// Set FIFO Polled Mode by clearing IER after setting FCR
+//
+SerialPortWriteRegister (SerialRegisterBase, R_UART_IER, 0x00, MmioEnable, 
RegisterStride);
+
+//
+// Put Modem Control Register(MCR) into its reset state of 0x00.
+//
+SerialPortWriteRegister (SerialRegisterBase, R_UART_MCR, 0x00, MmioEnable, 
RegisterStride);
+
+return RETURN_SUCCESS;
+  }
+
   GuidHob = GetFirstGuidHob ();
   while (GuidHob != NULL) {
 SerialPortInfo = (UNIVERSAL_PAYLOAD_SERIAL_PORT_INFO 
*)GET_GUID_HOB_DATA (GuidHob);
diff --git 
a/UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c
 
b/UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c
index 10bdbe2bbc1f..e9cce86bb853 100644
--- 
a/UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c

[edk2-devel] [PATCH v3 2/6] UefiPayloadPkg: Addd header files for FDT structure and function.

2024-05-23 Thread Linus Liu
Add Library header, DeviceTree hob header and PCD definitions.

Cc: Benny Lin 
Cc: Gua Guo 
Cc: Chasel Chiu 
Cc: James Lu 
Cc: Dhaval Sharma 

Signed-off-by: Linus Liu 
---
 UefiPayloadPkg/Include/Guid/UniversalPayloadBase.h   |  2 +
 UefiPayloadPkg/Include/Library/FdtParserLib.h| 64 
 UefiPayloadPkg/Include/UniversalPayload/DeviceTree.h | 30 +
 UefiPayloadPkg/UefiPayloadPkg.dec| 22 +++
 4 files changed, 118 insertions(+)

diff --git a/UefiPayloadPkg/Include/Guid/UniversalPayloadBase.h 
b/UefiPayloadPkg/Include/Guid/UniversalPayloadBase.h
index 60f2aa37dd3e..a2d4d491bdfb 100644
--- a/UefiPayloadPkg/Include/Guid/UniversalPayloadBase.h
+++ b/UefiPayloadPkg/Include/Guid/UniversalPayloadBase.h
@@ -16,4 +16,6 @@ typedef struct {
   EFI_PHYSICAL_ADDRESSEntry;
 } UNIVERSAL_PAYLOAD_BASE;
 
+#define UNIVERSAL_PAYLOAD_BASE_REVISION  1
+
 #endif // UNIVERSAL_PAYLOAD_BASE_H_
diff --git a/UefiPayloadPkg/Include/Library/FdtParserLib.h 
b/UefiPayloadPkg/Include/Library/FdtParserLib.h
new file mode 100644
index ..87109f1190bd
--- /dev/null
+++ b/UefiPayloadPkg/Include/Library/FdtParserLib.h
@@ -0,0 +1,64 @@
+/** @file
+  This library will parse the FDT (flat device tree) table information.
+
+  Copyright (c) 2024, Intel Corporation. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef FDT_PARSER_LIB_H_
+#define FDT_PARSER_LIB_H_
+
+/**
+  It will parse FDT based on DTB.
+
+  @param[in]  FdtBase   Address of the Fdt data.
+
+  @retval EFI_SUCCESS   If it completed successfully.
+  @retval OthersIf it failed to parse DTB.
+**/
+UINTN
+EFIAPI
+ParseDtb (
+  IN VOID  *FdtBase
+  );
+
+/**
+  It will Parse FDT -node based on information.
+  @param[in]  FdtBase   The starting memory address of FdtBase
+  @retval HobList   The base address of Hoblist.
+
+**/
+UINT64
+EFIAPI
+FdtNodeParser (
+  IN VOID  *FdtBase
+  );
+
+/**
+  It will Parse FDT -custom node based on information.
+  @param[in]  FdtBase The starting memory address of FdtBase
+  @param[in]  HostList The starting memory address of New Hob list.
+
+**/
+UINTN
+EFIAPI
+CustomFdtNodeParser (
+  IN VOID  *FdtBase,
+  IN VOID  *HostList
+  );
+
+/**
+  It will initialize HOBs for UPL.
+
+  @param[in]  FdtBaseAddress of the Fdt data.
+
+  @retval EFI_SUCCESSIf it completed successfully.
+  @retval Others If it failed to initialize HOBs.
+**/
+UINTN
+EFIAPI
+UplInitHob (
+  IN VOID  *FdtBase
+  );
+
+#endif
diff --git a/UefiPayloadPkg/Include/UniversalPayload/DeviceTree.h 
b/UefiPayloadPkg/Include/UniversalPayload/DeviceTree.h
new file mode 100644
index ..b7c2163e1e0d
--- /dev/null
+++ b/UefiPayloadPkg/Include/UniversalPayload/DeviceTree.h
@@ -0,0 +1,30 @@
+/** @file
+  This file defines the structure for the PCI Root Bridges.
+
+  Copyright (c) 2024, Intel Corporation. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Revision Reference:
+- Universal Payload Specification 0.8 
(https://universalpayload.github.io/spec/)
+**/
+
+#ifndef UNIVERSAL_PAYLOAD_DEVICE_TREE_H_
+#define UNIVERSAL_PAYLOAD_DEVICE_TREE_H_
+
+#include 
+#include 
+
+#pragma pack (1)
+
+typedef struct {
+  UNIVERSAL_PAYLOAD_GENERIC_HEADERHeader;
+  EFI_PHYSICAL_ADDRESSDeviceTreeAddress;
+} UNIVERSAL_PAYLOAD_DEVICE_TREE;
+
+#pragma pack()
+
+#define UNIVERSAL_PAYLOAD_DEVICE_TREE_REVISION  1
+
+extern GUID  gUniversalPayloadDeviceTreeGuid;
+
+#endif // UNIVERSAL_PAYLOAD_SMBIOS_TABLE_H_
diff --git a/UefiPayloadPkg/UefiPayloadPkg.dec 
b/UefiPayloadPkg/UefiPayloadPkg.dec
index 23dcdf9a0c9c..ca11a083ecdb 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.dec
+++ b/UefiPayloadPkg/UefiPayloadPkg.dec
@@ -27,6 +27,8 @@
   ## Include/Guid/UniversalPayloadBase.h
   gUniversalPayloadBaseGuid = { 0x03d4c61d, 0x2713, 0x4ec5, {0xa1, 0xcc, 0x88, 
0x3b, 0xe9, 0xdc, 0x18, 0xe5 } }
 
+  ## Include/UniversalPayload/DeviceTree.h
+  gUniversalPayloadDeviceTreeGuid = { 0x6784b889, 0xb13c, 0x4c3b, {0xae, 0x4b, 
0xf, 0xa, 0x2e, 0x32, 0xe, 0xa3 } }
   gEdkiiDebugPrintErrorLevelGuid = { 0xad82f436, 0x75c5, 0x4aa9, { 0x92, 0x93, 
0xc5, 0x55, 0x0a, 0x7f, 0xf9, 0x71 }}
   gUefiAcpiBoardInfoGuid   = {0xad3d31b, 0xb3d8, 0x4506, {0xae, 0x71, 0x2e, 
0xf1, 0x10, 0x6, 0xd9, 0xf}}
   gUefiSerialPortInfoGuid  = { 0x6c6872fe, 0x56a9, 0x4403, { 0xbb, 0x98, 0x95, 
0x8d, 0x62, 0xde, 0x87, 0xf1 } }
@@ -42,6 +44,13 @@
 [Ppis]
   gEfiPayLoadHobBasePpiGuid = { 0xdbe23aa1, 0xa342, 0x4b97, {0x85, 0xb6, 0xb2, 
0x26, 0xf1, 0x61, 0x73, 0x89} }
 
+  #
+  # This PPI is used to trigger Payload callback event in end of PEI.
+  #
+  gUplReadyToPayloadPpiGuid = { 0x67c8dfb1, 0x61f4, 0x439c, { 0x84, 0x4e, 
0x2b, 0xdf, 0xf1, 0x07, 0xad, 0x51 }}
+
+[Protocols]
+
 

 #
 # PCD Declarations section - list of all PCDs Declared by this Package

[edk2-devel] [PATCH v3 1/6] MdePkg: Fix build error after enable FDT support.

2024-05-23 Thread Linus Liu
Disable some compiling warnings caused by submodule code.
Those can be removed later once issues fixed by submodule owner.

Cc: Benny Lin 
Cc: Gua Guo 
Cc: Chasel Chiu 
Cc: James Lu 
Cc: Dhaval Sharma 
Signed-off-by: Linus Liu 
---
 MdePkg/Library/BaseFdtLib/BaseFdtLib.inf | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf 
b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
index 730e568ff605..b5815380c5ee 100644
--- a/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
+++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
@@ -57,6 +57,9 @@
   BaseMemoryLib
 
 [BuildOptions]
-  MSFT:*_*_IA32_CC_FLAGS = /wd4146 /wd4245
-  MSFT:*_*_X64_CC_FLAGS  = /wd4146 /wd4244 /wd4245 /wd4267
+# warning C4706: assignment within conditional expression
+# if ((err = fdt_splice_(fdt, p, oldlen, newlen)))
+# in BaseFdtLib\libfdt\libfdt\fdt_rw.c (wait for sub module update to remove 
this)
+  MSFT:*_*_IA32_CC_FLAGS = /wd4146 /wd4245 /wd4706
+  MSFT:*_*_X64_CC_FLAGS  = /wd4146 /wd4244 /wd4245 /wd4267 /wd4706
 
-- 
2.39.2.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119193): https://edk2.groups.io/g/devel/message/119193
Mute This Topic: https://groups.io/mt/106275981/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 0/6] *** FDT support in Universal Payload ***

2024-05-23 Thread Linus Liu
To align with ecosystem common interface, the FDT support is added to Universal 
Payload)

PR : https://github.com/tianocore/edk2/pull/5669
V2: Update typo [3/6] avalible ,[6/6] speciifc, HandOffhbo 
V3: Update cover letter content.

*** BLURB HERE ***

Linus Liu (6):
  MdePkg: Fix build error after enable FDT support.
  UefiPayloadPkg: Addd header files for FDT structure and function.
  UefiPayloadPkg: Support Debug function when Hob was not available.
  UefiPayloadPkg: Update PayloadLoader to suport FDT.
  UefiPayloadPkg: Add FDT Paser relative LIBs.
  UefiPayloadPkg: Update UefiPayload driver for FDT support.

 UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c 
|   69 ++
 UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.c 
|  158 +++
 UefiPayloadPkg/Library/CustomFdtNodeParserNullLib/CustomFdtNodeParserNullLib.c 
|   51 +
 UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c 
|5 +
 UefiPayloadPkg/Library/FdtParserLib/FdtParserLib.c 
|  622 
 UefiPayloadPkg/{UefiPayloadEntry/UniversalPayloadEntry.c => 
Library/HobParseLib/HobParseLib.c} |  255 ++---
 UefiPayloadPkg/Library/PayloadEntryHobLib/Hob.c
|7 +-
 UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.c   
|4 +
 UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.c
| 1004 +++-
 UefiPayloadPkg/PayloadLoaderPeim/PayloadLoaderPeim.c   
|   71 +-
 UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.c 
|  428 -
 UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFunc.c 
|   12 +
 UefiPayloadPkg/UefiPayloadEntry/Ia32/{DxeLoadFunc.c => DxeLoadFuncFit.c}   
|   32 +-
 UefiPayloadPkg/UefiPayloadEntry/MemoryAllocation.c 
|   50 +
 UefiPayloadPkg/UefiPayloadEntry/PrintHob.c 
|6 +-
 UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c
|6 -
 UefiPayloadPkg/UefiPayloadEntry/X64/DxeLoadFunc.c  
|   12 +
 UefiPayloadPkg/UefiPayloadEntry/X64/{DxeLoadFunc.c => DxeLoadFuncFit.c}
|   31 +-
 MdePkg/Library/BaseFdtLib/BaseFdtLib.inf   
|7 +-
 UefiPayloadPkg/Include/Guid/UniversalPayloadBase.h 
|2 +
 UefiPayloadPkg/Include/Library/FdtParserLib.h  
|   64 ++
 UefiPayloadPkg/Include/UniversalPayload/DeviceTree.h   
|   30 +
 UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.inf   
|   10 +
 UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.inf
|   13 +-
 UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.inf   
|   46 +
 
UefiPayloadPkg/Library/CustomFdtNodeParserNullLib/CustomFdtNodeParserNullLib.inf
   |   33 +
 UefiPayloadPkg/Library/FdtParserLib/FdtParseLib.inf
|   63 ++
 UefiPayloadPkg/Library/HobParseLib/HobParseLib.inf 
|   40 +
 UefiPayloadPkg/Library/PayloadEntryHobLib/HobLib.inf   
|1 +
 UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.inf  
|   16 +-
 UefiPayloadPkg/PayloadLoaderPeim/PayloadLoaderPeim.inf 
|   12 +
 UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.inf   
|   20 +-
 UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h 
|   68 ++
 UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf  
|   16 +-
 UefiPayloadPkg/UefiPayloadPkg.dec  
|   22 +
 UefiPayloadPkg/UefiPayloadPkg.dsc  
|   29 +-
 36 files changed, 2841 insertions(+), 474 deletions(-)
 create mode 100644 
UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.c
 create mode 100644 
UefiPayloadPkg/Library/CustomFdtNodeParserNullLib/CustomFdtNodeParserNullLib.c
 create mode 100644 UefiPayloadPkg/Library/FdtParserLib/FdtParserLib.c
 copy UefiPayloadPkg/{UefiPayloadEntry/UniversalPayloadEntry.c => 
Library/HobParseLib/HobParseLib.c} (61%)
 copy UefiPayloadPkg/UefiPayloadEntry/Ia32/{DxeLoadFunc.c => 

[edk2-devel] [PATCH v2 6/6] UefiPayloadPkg: Update UefiPayload driver for FDT support.

2024-05-23 Thread Linus Liu
Add FDT detection and comsume FDT when needed.
Move some x86 specific function in the x86 folder.
Create HandOffHob via FDT memory node.

Cc: Benny Lin 
Cc: Gua Guo 
Cc: Chasel Chiu 
Cc: James Lu 
Cc: Dhaval Sharma 

Signed-off-by: Linus Liu 
---
 UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.c   | 428 
+---
 UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFunc.c   |  12 
+
 UefiPayloadPkg/UefiPayloadEntry/Ia32/{DxeLoadFunc.c => DxeLoadFuncFit.c} |  32 
+-
 UefiPayloadPkg/UefiPayloadEntry/MemoryAllocation.c   |  50 
+++
 UefiPayloadPkg/UefiPayloadEntry/PrintHob.c   |   6 
+-
 UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c  |   6 
-
 UefiPayloadPkg/UefiPayloadEntry/X64/DxeLoadFunc.c|  12 
+
 UefiPayloadPkg/UefiPayloadEntry/X64/{DxeLoadFunc.c => DxeLoadFuncFit.c}  |  31 
+-
 UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.inf |  20 
+-
 UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h   |  68 

 UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf|  16 
+-
 UefiPayloadPkg/UefiPayloadPkg.dsc|  29 
+-
 12 files changed, 443 insertions(+), 267 deletions(-)

diff --git a/UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.c 
b/UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.c
index eb0b325369a0..813d656950d1 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.c
+++ b/UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.c
@@ -6,6 +6,8 @@
 #include "UefiPayloadEntry.h"
 #include 
 #include 
+#include 
+#include 
 
 #define MEMORY_ATTRIBUTE_MASK  (EFI_RESOURCE_ATTRIBUTE_PRESENT |   
 \
EFI_RESOURCE_ATTRIBUTE_INITIALIZED  
   | \
@@ -23,6 +25,15 @@
EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \
EFI_RESOURCE_ATTRIBUTE_TESTED  )
 
+EFI_MEMORY_TYPE_INFORMATION  mDefaultMemoryTypeInformation[] = {
+  { EfiACPIReclaimMemory,   FixedPcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory)  
 },
+  { EfiACPIMemoryNVS,   FixedPcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS)  
 },
+  { EfiReservedMemoryType,  FixedPcdGet32 (PcdMemoryTypeEfiReservedMemoryType) 
 },
+  { EfiRuntimeServicesData, FixedPcdGet32 
(PcdMemoryTypeEfiRuntimeServicesData) },
+  { EfiRuntimeServicesCode, FixedPcdGet32 
(PcdMemoryTypeEfiRuntimeServicesCode) },
+  { EfiMaxMemoryType,   0  
 }
+};
+
 extern VOID  *mHobList;
 
 CHAR8  *mLineBuffer = NULL;
@@ -36,6 +47,78 @@ PrintHob (
   IN CONST VOID  *HobStart
   );
 
+/**
+  Add HOB into HOB list
+  @param[in]  HobThe HOB to be added into the HOB list.
+**/
+VOID
+AddNewHob (
+  IN EFI_PEI_HOB_POINTERS  *Hob
+  );
+
+/**
+  Found the Resource Descriptor HOB that contains a range (Base, Top)
+  @param[in] HobListHob start address
+  @param[in] Base   Memory start address
+  @param[in] TopMemory end address.
+  @retval The pointer to the Resource Descriptor HOB.
+**/
+EFI_HOB_RESOURCE_DESCRIPTOR *
+FindResourceDescriptorByRange (
+  IN VOID  *HobList,
+  IN EFI_PHYSICAL_ADDRESS  Base,
+  IN EFI_PHYSICAL_ADDRESS  Top
+  );
+
+/**
+  Find the highest below 4G memory resource descriptor, except the input 
Resource Descriptor.
+  @param[in] HobList Hob start address
+  @param[in] MinimalNeededSize   Minimal needed size.
+  @param[in] ExceptResourceHob   Ignore this Resource Descriptor.
+  @retval The pointer to the Resource Descriptor HOB.
+**/
+EFI_HOB_RESOURCE_DESCRIPTOR *
+FindAnotherHighestBelow4GResourceDescriptor (
+  IN VOID *HobList,
+  IN UINTNMinimalNeededSize,
+  IN EFI_HOB_RESOURCE_DESCRIPTOR  *ExceptResourceHob
+  );
+
+/**
+  Check the HOB and decide if it is need inside Payload
+  Payload maintainer may make decision which HOB is need or needn't
+  Then add the check logic in the function.
+  @param[in] Hob The HOB to check
+  @retval TRUE  If HOB is need inside Payload
+  @retval FALSE If HOB is needn't inside Payload
+**/
+BOOLEAN
+FitIsHobNeed (
+  EFI_PEI_HOB_POINTERS  Hob
+  );
+
+/**
+  Check the HOB and decide if it is need inside Payload
+
+  Payload maintainer may make decision which HOB is need or needn't
+  Then add the check logic in the function.
+
+  @param[in] Hob The HOB to check
+
+  @retval TRUE  If HOB is need inside Payload
+  @retval FALSE If HOB is needn't inside Payload
+**/
+BOOLEAN
+IsHobNeed (
+  EFI_PEI_HOB_POINTERS  Hob
+  );
+
+VOID
+EFIAPI
+ProcessLibraryConstructorList (
+  VOID
+  );
+
 /**
   Find the first substring.
   @param  StringPoint to the string where to find the substring.
@@ -191,187 +274,6 @@ FixUpPcdDatabase (
   return EFI_SUCCESS;
 }
 
-/**
-  Add HOB into HOB list
- 

[edk2-devel] [PATCH v2 5/6] UefiPayloadPkg: Add FDT Paser relative LIBs.

2024-05-23 Thread Linus Liu
Add FDTParser and CustomFdtNodePaser
to retrive all FDT node and create the relate hobs.

Cc: Benny Lin 
Cc: Gua Guo 
Cc: Chasel Chiu 
Cc: James Lu 
Cc: Dhaval Sharma 

Signed-off-by: Linus Liu 
---
 UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.c 
  | 158 +
 UefiPayloadPkg/Library/CustomFdtNodeParserNullLib/CustomFdtNodeParserNullLib.c 
  |  51 ++
 UefiPayloadPkg/Library/FdtParserLib/FdtParserLib.c 
  | 622 
 UefiPayloadPkg/Library/HobParseLib/HobParseLib.c   
  | 408 +
 UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.inf   
  |  46 ++
 
UefiPayloadPkg/Library/CustomFdtNodeParserNullLib/CustomFdtNodeParserNullLib.inf
 |  33 ++
 UefiPayloadPkg/Library/FdtParserLib/FdtParseLib.inf
  |  63 ++
 UefiPayloadPkg/Library/HobParseLib/HobParseLib.inf 
  |  40 ++
 8 files changed, 1421 insertions(+)

diff --git 
a/UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.c 
b/UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.c
new file mode 100644
index ..d1376d21c5dd
--- /dev/null
+++ b/UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.c
@@ -0,0 +1,158 @@
+/** @file
+  Copyright (c) 2024, Intel Corporation. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+  Add a new HOB to the HOB List.
+
+  @param HobTypeType of the new HOB.
+  @param HobLength  Length of the new HOB to allocate.
+
+  @return  NULL if there is no space to create a hob.
+  @return  The address point to the new created hob.
+
+**/
+VOID *
+EFIAPI
+CreateHob (
+  IN  UINT16  HobType,
+  IN  UINT16  HobLength
+  );
+
+/**
+  Add HOB into HOB list
+  @param[in]  HobThe HOB to be added into the HOB list.
+**/
+VOID
+AddNewHob (
+  IN EFI_PEI_HOB_POINTERS  *Hob
+  );
+
+/**
+  Check the HOB and decide if it is need inside Payload
+  Payload maintainer may make decision which HOB is need or needn't
+  Then add the check logic in the function.
+  @param[in] Hob The HOB to check
+  @retval TRUE  If HOB is need inside Payload
+  @retval FALSE If HOB is needn't inside Payload
+**/
+BOOLEAN
+EFIAPI
+FitIsHobNeed (
+  EFI_PEI_HOB_POINTERS  Hob
+  )
+{
+  if (FixedPcdGetBool (PcdHandOffFdtEnable)) {
+if (Hob.Header->HobType == EFI_HOB_TYPE_HANDOFF) {
+  return FALSE;
+}
+
+if (Hob.Header->HobType == EFI_HOB_TYPE_MEMORY_ALLOCATION) {
+  if (CompareGuid (>AllocDescriptor.Name, 
)) {
+return FALSE;
+  }
+
+  if (CompareGuid 
(>MemoryAllocationHeader.Name, 
)) {
+return FALSE;
+  }
+
+  if ((Hob.MemoryAllocation->AllocDescriptor.MemoryType == 
EfiReservedMemoryType) ||
+  (Hob.MemoryAllocation->AllocDescriptor.MemoryType == 
EfiBootServicesCode) ||
+  (Hob.MemoryAllocation->AllocDescriptor.MemoryType == 
EfiBootServicesData) ||
+  (Hob.MemoryAllocation->AllocDescriptor.MemoryType == 
EfiRuntimeServicesCode) ||
+  (Hob.MemoryAllocation->AllocDescriptor.MemoryType == 
EfiRuntimeServicesData) ||
+  (Hob.MemoryAllocation->AllocDescriptor.MemoryType == 
EfiACPIReclaimMemory) ||
+  (Hob.MemoryAllocation->AllocDescriptor.MemoryType == 
EfiACPIMemoryNVS))
+  {
+return FALSE;
+  }
+}
+
+if (Hob.Header->HobType == EFI_HOB_TYPE_GUID_EXTENSION) {
+  if (CompareGuid (>Name, )) 
{
+return FALSE;
+  }
+
+  if (CompareGuid (>Name, )) {
+return FALSE;
+  }
+
+  if (CompareGuid (>Name, 
)) {
+return FALSE;
+  }
+}
+  }
+
+  // Arrive here mean the HOB is need
+  return TRUE;
+}
+
+/**
+  It will Parse FDT -custom node based on information from bootloaders.
+  @param[in]  FdtBase The starting memory address of FdtBase
+  @param[in]  HobList The starting memory address of New Hob list.
+
+**/
+UINTN
+EFIAPI
+CustomFdtNodeParser (
+  IN VOID  *FdtBase,
+  IN VOID  *HobList
+  )
+{
+  INT32 Node, CustomNode;
+  INT32 TempLen;
+  UINT64*Data64;
+  UINTN CHobList;
+  CONST FDT_PROPERTY*PropertyPtr;
+  EFI_PEI_HOB_POINTERS  Hob;
+
+  CHobList = (UINTN)HobList;
+
+  DEBUG ((DEBUG_INFO, "%a() #1 \n", __func__));
+
+  //
+  // Look for if exists hob list node
+  //
+  Node = FdtSubnodeOffsetNameLen (FdtBase, 0, "options", (INT32)AsciiStrLen 
("options"));
+  if (Node > 0) {
+DEBUG ((DEBUG_INFO, "  Found options node (%08X)", Node));
+CustomNode = FdtSubnodeOffsetNameLen (FdtBase, Node, "upl-custom", 
(INT32)AsciiStrLen ("upl-custom"));
+if (CustomNode > 0) {
+  DEBUG ((DEBUG_INFO, "  Found upl-custom node (%08X)", CustomNode));
+  PropertyPtr = FdtGetProperty (FdtBase, CustomNode, "hoblistptr", 
);

[edk2-devel] [PATCH v2 4/6] UefiPayloadPkg: Update PayloadLoader to suport FDT.

2024-05-23 Thread Linus Liu
Create FDT nodes (reserved-memory, serial, pci-rb, options) in
FdtPpiNotifyCallback function right after gEfiEndOfPeiSignalPpiGuid.

Cc: Benny Lin 
Cc: Gua Guo 
Cc: Chasel Chiu 
Cc: James Lu 
Cc: Dhaval Sharma 

Signed-off-by: Linus Liu 
---
 UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.c   | 1004 
+++-
 UefiPayloadPkg/PayloadLoaderPeim/PayloadLoaderPeim.c  |   71 +-
 UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.inf |   16 +-
 UefiPayloadPkg/PayloadLoaderPeim/PayloadLoaderPeim.inf|   12 +
 4 files changed, 1077 insertions(+), 26 deletions(-)

diff --git a/UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.c 
b/UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.c
index de33d49bd1c6..00016c7756c5 100644
--- a/UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.c
+++ b/UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.c
@@ -6,18 +6,74 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 
 #include 
 #include 
+#include 
 #include 
+#include 
 #include 
-
+#include 
 #include 
 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
-
+#include 
+#include 
+#include 
 #include "FitLib.h"
+#define STACK_SIZE  0x2
+#define N_NON_RELOCATABLE   BIT31
+#define P_NON_PREFETCHABLE  BIT30
+#define SS_CONFIGURATION_SPACE  0
+#define SS_IO_SPACE BIT24
+#define SS_32BIT_MEMORY_SPACE   BIT25
+#define SS_64BIT_MEMORY_SPACE   BIT24+BIT25
+
+CONST EFI_PEI_PPI_DESCRIPTOR  gReadyToPayloadSignalPpi = {
+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
+  ,
+  NULL
+};
+
+EFI_PEI_PPI_DESCRIPTOR  mEndOfPeiSignalPpi = {
+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
+  ,
+  NULL
+};
+
+#define MEMORY_ATTRIBUTE_DEFAULT  (EFI_RESOURCE_ATTRIBUTE_PRESENT  
 | \
+ EFI_RESOURCE_ATTRIBUTE_INITIALIZED
 | \
+ EFI_RESOURCE_ATTRIBUTE_TESTED 
 | \
+ EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
 | \
+ EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE  
 | \
+ 
EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE | \
+ 
EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE)
+
+CHAR8  *mMemoryAllocType[] = {
+  "Reserved",
+  "LoaderCode",
+  "LoaderData",
+  "boot-code",
+  "boot-data",
+  "runtime-code",
+  "runtime-data",
+  "ConventionalMemory",
+  "UnusableMemory",
+  "acpi",
+  "acpi-nvs",
+  "mmio",
+  "MemoryMappedIOPortSpace",
+  "PalCode",
+  "PersistentMemory",
+};
 
 /**
   The wrapper function of PeiLoadImageLoadImage().
@@ -50,6 +106,15 @@ PeiLoadFileLoadPayload (
   UINTN   Delta;
   UINTN   Index;
 
+ #if (FixedPcdGetBool (PcdHandOffFdtEnable))
+  VOID   *BaseOfStack;
+  VOID   *TopOfStack;
+  UNIVERSAL_PAYLOAD_DEVICE_TREE  *Fdt;
+  VOID   *Hob;
+
+  Fdt = NULL;
+ #endif
+
   Instance = 0;
   do {
 Status = PeiServicesFfsFindSectionData3 (EFI_SECTION_RAW, Instance++, 
FileHandle, , AuthenticationState);
@@ -66,13 +131,15 @@ PeiLoadFileLoadPayload (
 return Status;
   }
 
-  DEBUG ((
-DEBUG_INFO,
-"Before Rebase Payload File Base: 0x%08x, File Size: 0x%08X, EntryPoint: 
0x%08x\n",
-Context.PayloadBaseAddress,
-Context.PayloadSize,
-Context.PayloadEntryPoint
-));
+  DEBUG (
+(
+ DEBUG_INFO,
+ "Before Rebase Payload File Base: 0x%08x, File Size: 0x%08X, EntryPoint: 
0x%08x\n",
+ Context.PayloadBaseAddress,
+ Context.PayloadSize,
+ Context.PayloadEntryPoint
+)
+);
   Context.PayloadBaseAddress = (EFI_PHYSICAL_ADDRESS)AllocatePages 
(EFI_SIZE_TO_PAGES (Context.PayloadSize));
 
   RelocateTable = (FIT_RELOCATE_ITEM *)(UINTN)(Context.PayloadBaseAddress + 
Context.RelocateTableOffset);
@@ -96,13 +163,15 @@ PeiLoadFileLoadPayload (
 }
   }
 
-  DEBUG ((
-DEBUG_INFO,
-"After Rebase Payload File Base: 0x%08x, File Size: 0x%08X, EntryPoint: 
0x%08x\n",
-Context.PayloadBaseAddress,
-Context.PayloadSize,
-Context.PayloadEntryPoint
-));
+  DEBUG (
+(
+ DEBUG_INFO,
+ "After Rebase Payload File Base: 0x%08x, File Size: 0x%08X, EntryPoint: 
0x%08x\n",
+ Context.PayloadBaseAddress,
+ Context.PayloadSize,
+ Context.PayloadEntryPoint
+)
+);
 
   Length  = sizeof (UNIVERSAL_PAYLOAD_BASE);
   PayloadBase = BuildGuidHob (
@@ -115,6 +184,42 @@ PeiLoadFileLoadPayload (
   *ImageSizeArg= Context.PayloadSize;
   *EntryPoint  = Context.PayloadEntryPoint;
 
+  Status = PeiServicesInstallPpi ();
+  ASSERT_EFI_ERROR (Status);
+
+  Status = PeiServicesInstallPpi ();
+  ASSERT_EFI_ERROR (Status);
+
+ #if (FixedPcdGetBool (PcdHandOffFdtEnable))
+  Hob = GetFirstGuidHob ();
+  if 

[edk2-devel] [PATCH v2 3/6] UefiPayloadPkg: Support Debug function when Hob was not available.

2024-05-23 Thread Linus Liu
Initialize mUartInfo with PCD for debug message
when Hob was not available.

Cc: Benny Lin 
Cc: Gua Guo 
Cc: Chasel Chiu 
Cc: James Lu 
Cc: Dhaval Sharma 

Signed-off-by: Linus Liu 
---
 UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c 
| 69 
 UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c 
|  5 ++
 UefiPayloadPkg/Library/PayloadEntryHobLib/Hob.c
|  7 +-
 UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.c   
|  4 ++
 UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.inf   
| 10 +++
 UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.inf
| 13 ++--
 UefiPayloadPkg/Library/PayloadEntryHobLib/HobLib.inf   
|  1 +
 7 files changed, 104 insertions(+), 5 deletions(-)

diff --git a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c 
b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c
index 82d0dd585508..55e85dce8598 100644
--- a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c
+++ b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c
@@ -143,6 +143,75 @@ SerialPortInitialize (
 return RETURN_SUCCESS;
   }
 
+  if (GetHobList () == NULL) {
+mUartCount = 0;
+SerialRegisterBase = PcdGet64 (PcdSerialRegisterBase);
+MmioEnable = PcdGetBool (PcdSerialUseMmio);
+BaudRate   = PcdGet32 (PcdSerialBaudRate);
+RegisterStride = (UINT8)PcdGet32 (PcdSerialRegisterStride);
+
+mUartInfo[mUartCount].BaseAddress= SerialRegisterBase;
+mUartInfo[mUartCount].UseMmio= MmioEnable;
+mUartInfo[mUartCount].BaudRate   = BaudRate;
+mUartInfo[mUartCount].RegisterStride = RegisterStride;
+mUartCount++;
+
+Divisor = PcdGet32 (PcdSerialClockRate) / (BaudRate * 16);
+if ((PcdGet32 (PcdSerialClockRate) % (BaudRate * 16)) >= BaudRate * 8) {
+  Divisor++;
+}
+
+//
+// See if the serial port is already initialized
+//
+Initialized = TRUE;
+if ((SerialPortReadRegister (SerialRegisterBase, R_UART_LCR, MmioEnable, 
RegisterStride) & 0x3F) != (PcdGet8 (PcdSerialLineControl) & 0x3F)) {
+  Initialized = FALSE;
+}
+
+Value = (UINT8)(SerialPortReadRegister (SerialRegisterBase, R_UART_LCR, 
MmioEnable, RegisterStride) | B_UART_LCR_DLAB);
+SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, Value, 
MmioEnable, RegisterStride);
+CurrentDivisor  =  SerialPortReadRegister (SerialRegisterBase, 
R_UART_BAUD_HIGH, MmioEnable, RegisterStride) << 8;
+CurrentDivisor |= (UINT32)SerialPortReadRegister (SerialRegisterBase, 
R_UART_BAUD_LOW, MmioEnable, RegisterStride);
+Value   = (UINT8)(SerialPortReadRegister (SerialRegisterBase, 
R_UART_LCR, MmioEnable, RegisterStride) & ~B_UART_LCR_DLAB);
+SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, Value, 
MmioEnable, RegisterStride);
+if (CurrentDivisor != Divisor) {
+  Initialized = FALSE;
+}
+
+//
+// Configure baud rate
+//
+SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, B_UART_LCR_DLAB, 
MmioEnable, RegisterStride);
+SerialPortWriteRegister (SerialRegisterBase, R_UART_BAUD_HIGH, 
(UINT8)(Divisor >> 8), MmioEnable, RegisterStride);
+SerialPortWriteRegister (SerialRegisterBase, R_UART_BAUD_LOW, 
(UINT8)(Divisor & 0xff), MmioEnable, RegisterStride);
+
+//
+// Clear DLAB and configure Data Bits, Parity, and Stop Bits.
+// Strip reserved bits from PcdSerialLineControl
+//
+SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, (UINT8)(PcdGet8 
(PcdSerialLineControl) & 0x3F), MmioEnable, RegisterStride);
+
+//
+// Enable and reset FIFOs
+// Strip reserved bits from PcdSerialFifoControl
+//
+SerialPortWriteRegister (SerialRegisterBase, R_UART_FCR, 0x00, MmioEnable, 
RegisterStride);
+SerialPortWriteRegister (SerialRegisterBase, R_UART_FCR, (UINT8)(PcdGet8 
(PcdSerialFifoControl) & (B_UART_FCR_FIFOE | B_UART_FCR_FIFO64)), MmioEnable, 
RegisterStride);
+
+//
+// Set FIFO Polled Mode by clearing IER after setting FCR
+//
+SerialPortWriteRegister (SerialRegisterBase, R_UART_IER, 0x00, MmioEnable, 
RegisterStride);
+
+//
+// Put Modem Control Register(MCR) into its reset state of 0x00.
+//
+SerialPortWriteRegister (SerialRegisterBase, R_UART_MCR, 0x00, MmioEnable, 
RegisterStride);
+
+return RETURN_SUCCESS;
+  }
+
   GuidHob = GetFirstGuidHob ();
   while (GuidHob != NULL) {
 SerialPortInfo = (UNIVERSAL_PAYLOAD_SERIAL_PORT_INFO 
*)GET_GUID_HOB_DATA (GuidHob);
diff --git 
a/UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c
 
b/UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c
index 10bdbe2bbc1f..e9cce86bb853 100644
--- 
a/UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c

[edk2-devel] [PATCH v2 2/6] UefiPayloadPkg: Addd header files for FDT structure and function.

2024-05-23 Thread Linus Liu
Add Library header, DeviceTree hob header and PCD definitions.

Cc: Benny Lin 
Cc: Gua Guo 
Cc: Chasel Chiu 
Cc: James Lu 
Cc: Dhaval Sharma 

Signed-off-by: Linus Liu 
---
 UefiPayloadPkg/Include/Guid/UniversalPayloadBase.h   |  2 +
 UefiPayloadPkg/Include/Library/FdtParserLib.h| 64 
 UefiPayloadPkg/Include/UniversalPayload/DeviceTree.h | 30 +
 UefiPayloadPkg/UefiPayloadPkg.dec| 22 +++
 4 files changed, 118 insertions(+)

diff --git a/UefiPayloadPkg/Include/Guid/UniversalPayloadBase.h 
b/UefiPayloadPkg/Include/Guid/UniversalPayloadBase.h
index 60f2aa37dd3e..a2d4d491bdfb 100644
--- a/UefiPayloadPkg/Include/Guid/UniversalPayloadBase.h
+++ b/UefiPayloadPkg/Include/Guid/UniversalPayloadBase.h
@@ -16,4 +16,6 @@ typedef struct {
   EFI_PHYSICAL_ADDRESSEntry;
 } UNIVERSAL_PAYLOAD_BASE;
 
+#define UNIVERSAL_PAYLOAD_BASE_REVISION  1
+
 #endif // UNIVERSAL_PAYLOAD_BASE_H_
diff --git a/UefiPayloadPkg/Include/Library/FdtParserLib.h 
b/UefiPayloadPkg/Include/Library/FdtParserLib.h
new file mode 100644
index ..87109f1190bd
--- /dev/null
+++ b/UefiPayloadPkg/Include/Library/FdtParserLib.h
@@ -0,0 +1,64 @@
+/** @file
+  This library will parse the FDT (flat device tree) table information.
+
+  Copyright (c) 2024, Intel Corporation. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef FDT_PARSER_LIB_H_
+#define FDT_PARSER_LIB_H_
+
+/**
+  It will parse FDT based on DTB.
+
+  @param[in]  FdtBase   Address of the Fdt data.
+
+  @retval EFI_SUCCESS   If it completed successfully.
+  @retval OthersIf it failed to parse DTB.
+**/
+UINTN
+EFIAPI
+ParseDtb (
+  IN VOID  *FdtBase
+  );
+
+/**
+  It will Parse FDT -node based on information.
+  @param[in]  FdtBase   The starting memory address of FdtBase
+  @retval HobList   The base address of Hoblist.
+
+**/
+UINT64
+EFIAPI
+FdtNodeParser (
+  IN VOID  *FdtBase
+  );
+
+/**
+  It will Parse FDT -custom node based on information.
+  @param[in]  FdtBase The starting memory address of FdtBase
+  @param[in]  HostList The starting memory address of New Hob list.
+
+**/
+UINTN
+EFIAPI
+CustomFdtNodeParser (
+  IN VOID  *FdtBase,
+  IN VOID  *HostList
+  );
+
+/**
+  It will initialize HOBs for UPL.
+
+  @param[in]  FdtBaseAddress of the Fdt data.
+
+  @retval EFI_SUCCESSIf it completed successfully.
+  @retval Others If it failed to initialize HOBs.
+**/
+UINTN
+EFIAPI
+UplInitHob (
+  IN VOID  *FdtBase
+  );
+
+#endif
diff --git a/UefiPayloadPkg/Include/UniversalPayload/DeviceTree.h 
b/UefiPayloadPkg/Include/UniversalPayload/DeviceTree.h
new file mode 100644
index ..b7c2163e1e0d
--- /dev/null
+++ b/UefiPayloadPkg/Include/UniversalPayload/DeviceTree.h
@@ -0,0 +1,30 @@
+/** @file
+  This file defines the structure for the PCI Root Bridges.
+
+  Copyright (c) 2024, Intel Corporation. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Revision Reference:
+- Universal Payload Specification 0.8 
(https://universalpayload.github.io/spec/)
+**/
+
+#ifndef UNIVERSAL_PAYLOAD_DEVICE_TREE_H_
+#define UNIVERSAL_PAYLOAD_DEVICE_TREE_H_
+
+#include 
+#include 
+
+#pragma pack (1)
+
+typedef struct {
+  UNIVERSAL_PAYLOAD_GENERIC_HEADERHeader;
+  EFI_PHYSICAL_ADDRESSDeviceTreeAddress;
+} UNIVERSAL_PAYLOAD_DEVICE_TREE;
+
+#pragma pack()
+
+#define UNIVERSAL_PAYLOAD_DEVICE_TREE_REVISION  1
+
+extern GUID  gUniversalPayloadDeviceTreeGuid;
+
+#endif // UNIVERSAL_PAYLOAD_SMBIOS_TABLE_H_
diff --git a/UefiPayloadPkg/UefiPayloadPkg.dec 
b/UefiPayloadPkg/UefiPayloadPkg.dec
index 23dcdf9a0c9c..ca11a083ecdb 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.dec
+++ b/UefiPayloadPkg/UefiPayloadPkg.dec
@@ -27,6 +27,8 @@
   ## Include/Guid/UniversalPayloadBase.h
   gUniversalPayloadBaseGuid = { 0x03d4c61d, 0x2713, 0x4ec5, {0xa1, 0xcc, 0x88, 
0x3b, 0xe9, 0xdc, 0x18, 0xe5 } }
 
+  ## Include/UniversalPayload/DeviceTree.h
+  gUniversalPayloadDeviceTreeGuid = { 0x6784b889, 0xb13c, 0x4c3b, {0xae, 0x4b, 
0xf, 0xa, 0x2e, 0x32, 0xe, 0xa3 } }
   gEdkiiDebugPrintErrorLevelGuid = { 0xad82f436, 0x75c5, 0x4aa9, { 0x92, 0x93, 
0xc5, 0x55, 0x0a, 0x7f, 0xf9, 0x71 }}
   gUefiAcpiBoardInfoGuid   = {0xad3d31b, 0xb3d8, 0x4506, {0xae, 0x71, 0x2e, 
0xf1, 0x10, 0x6, 0xd9, 0xf}}
   gUefiSerialPortInfoGuid  = { 0x6c6872fe, 0x56a9, 0x4403, { 0xbb, 0x98, 0x95, 
0x8d, 0x62, 0xde, 0x87, 0xf1 } }
@@ -42,6 +44,13 @@
 [Ppis]
   gEfiPayLoadHobBasePpiGuid = { 0xdbe23aa1, 0xa342, 0x4b97, {0x85, 0xb6, 0xb2, 
0x26, 0xf1, 0x61, 0x73, 0x89} }
 
+  #
+  # This PPI is used to trigger Payload callback event in end of PEI.
+  #
+  gUplReadyToPayloadPpiGuid = { 0x67c8dfb1, 0x61f4, 0x439c, { 0x84, 0x4e, 
0x2b, 0xdf, 0xf1, 0x07, 0xad, 0x51 }}
+
+[Protocols]
+
 

 #
 # PCD Declarations section - list of all PCDs Declared by this Package

[edk2-devel] [PATCH v2 1/6] MdePkg: Fix build error after enable FDT support.

2024-05-23 Thread Linus Liu
Disable some compiling warnings caused by submodule code.
Those can be removed later once issues fixed by submodule owner.

Cc: Benny Lin 
Cc: Gua Guo 
Cc: Chasel Chiu 
Cc: James Lu 
Cc: Dhaval Sharma 
Signed-off-by: Linus Liu 
---
 MdePkg/Library/BaseFdtLib/BaseFdtLib.inf | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf 
b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
index 730e568ff605..b5815380c5ee 100644
--- a/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
+++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
@@ -57,6 +57,9 @@
   BaseMemoryLib
 
 [BuildOptions]
-  MSFT:*_*_IA32_CC_FLAGS = /wd4146 /wd4245
-  MSFT:*_*_X64_CC_FLAGS  = /wd4146 /wd4244 /wd4245 /wd4267
+# warning C4706: assignment within conditional expression
+# if ((err = fdt_splice_(fdt, p, oldlen, newlen)))
+# in BaseFdtLib\libfdt\libfdt\fdt_rw.c (wait for sub module update to remove 
this)
+  MSFT:*_*_IA32_CC_FLAGS = /wd4146 /wd4245 /wd4706
+  MSFT:*_*_X64_CC_FLAGS  = /wd4146 /wd4244 /wd4245 /wd4267 /wd4706
 
-- 
2.39.2.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119186): https://edk2.groups.io/g/devel/message/119186
Mute This Topic: https://groups.io/mt/106275533/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v2 0/6] *** SUBJECT HERE ***

2024-05-23 Thread Linus Liu
*** BLURB HERE ***

Linus Liu (6):
  MdePkg: Fix build error after enable FDT support.
  UefiPayloadPkg: Addd header files for FDT structure and function.
  UefiPayloadPkg: Support Debug function when Hob was not available.
  UefiPayloadPkg: Update PayloadLoader to suport FDT.
  UefiPayloadPkg: Add FDT Paser relative LIBs.
  UefiPayloadPkg: Update UefiPayload driver for FDT support.

 UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c 
|   69 ++
 UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.c 
|  158 +++
 UefiPayloadPkg/Library/CustomFdtNodeParserNullLib/CustomFdtNodeParserNullLib.c 
|   51 +
 UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c 
|5 +
 UefiPayloadPkg/Library/FdtParserLib/FdtParserLib.c 
|  622 
 UefiPayloadPkg/{UefiPayloadEntry/UniversalPayloadEntry.c => 
Library/HobParseLib/HobParseLib.c} |  255 ++---
 UefiPayloadPkg/Library/PayloadEntryHobLib/Hob.c
|7 +-
 UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.c   
|4 +
 UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.c
| 1004 +++-
 UefiPayloadPkg/PayloadLoaderPeim/PayloadLoaderPeim.c   
|   71 +-
 UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.c 
|  428 -
 UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFunc.c 
|   12 +
 UefiPayloadPkg/UefiPayloadEntry/Ia32/{DxeLoadFunc.c => DxeLoadFuncFit.c}   
|   32 +-
 UefiPayloadPkg/UefiPayloadEntry/MemoryAllocation.c 
|   50 +
 UefiPayloadPkg/UefiPayloadEntry/PrintHob.c 
|6 +-
 UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c
|6 -
 UefiPayloadPkg/UefiPayloadEntry/X64/DxeLoadFunc.c  
|   12 +
 UefiPayloadPkg/UefiPayloadEntry/X64/{DxeLoadFunc.c => DxeLoadFuncFit.c}
|   31 +-
 MdePkg/Library/BaseFdtLib/BaseFdtLib.inf   
|7 +-
 UefiPayloadPkg/Include/Guid/UniversalPayloadBase.h 
|2 +
 UefiPayloadPkg/Include/Library/FdtParserLib.h  
|   64 ++
 UefiPayloadPkg/Include/UniversalPayload/DeviceTree.h   
|   30 +
 UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.inf   
|   10 +
 UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.inf
|   13 +-
 UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.inf   
|   46 +
 
UefiPayloadPkg/Library/CustomFdtNodeParserNullLib/CustomFdtNodeParserNullLib.inf
   |   33 +
 UefiPayloadPkg/Library/FdtParserLib/FdtParseLib.inf
|   63 ++
 UefiPayloadPkg/Library/HobParseLib/HobParseLib.inf 
|   40 +
 UefiPayloadPkg/Library/PayloadEntryHobLib/HobLib.inf   
|1 +
 UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.inf  
|   16 +-
 UefiPayloadPkg/PayloadLoaderPeim/PayloadLoaderPeim.inf 
|   12 +
 UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.inf   
|   20 +-
 UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h 
|   68 ++
 UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf  
|   16 +-
 UefiPayloadPkg/UefiPayloadPkg.dec  
|   22 +
 UefiPayloadPkg/UefiPayloadPkg.dsc  
|   29 +-
 36 files changed, 2841 insertions(+), 474 deletions(-)
 create mode 100644 
UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.c
 create mode 100644 
UefiPayloadPkg/Library/CustomFdtNodeParserNullLib/CustomFdtNodeParserNullLib.c
 create mode 100644 UefiPayloadPkg/Library/FdtParserLib/FdtParserLib.c
 copy UefiPayloadPkg/{UefiPayloadEntry/UniversalPayloadEntry.c => 
Library/HobParseLib/HobParseLib.c} (61%)
 copy UefiPayloadPkg/UefiPayloadEntry/Ia32/{DxeLoadFunc.c => DxeLoadFuncFit.c} 
(90%)
 copy UefiPayloadPkg/UefiPayloadEntry/X64/{DxeLoadFunc.c => DxeLoadFuncFit.c} 
(74%)
 create mode 100644 UefiPayloadPkg/Include/Library/FdtParserLib.h
 create mode 100644 

Re: [edk2-devel] [Patch V2 00/18] Remove some S3 related code in CpuS3.c of smm cpu driver

2024-05-23 Thread duntan
Hi Liming,



Could you please help to review the following 2 patches in the patch series?

  [Patch V2 01/18] MdeModulePkg: Add gEdkiiS3MtrrSettingGuid

  [Patch V2 17/18] MdeModulePkg:Remove MpService2Ppi field in 
SMM_S3_RESUME_STATE



Thanks,

Dun

From: Ni, Ray 
Sent: Monday, May 20, 2024 3:05 PM
To: Tan, Dun ; devel@edk2.groups.io
Cc: Liming Gao ; Wu, Jiaxin ; 
Ard Biesheuvel ; Yao, Jiewen ; 
Gerd Hoffmann ; Kumar, Rahul R 
Subject: Re: [Patch V2 00/18] Remove some S3 related code in CpuS3.c of smm cpu 
driver

Following 3 patches still require the Reviewed-by from package maintainers of 
MdeModulePkg and OvmfPkg.
  MdeModulePkg: Add gEdkiiS3MtrrSettingGuid
  OvmfPkg: Save MTRR by lockbox in CpuS3DataDxe
  MdeModulePkg:Remove MpService2Ppi field in SMM_S3_RESUME_STATE

The patch set is a good move to simplify the X86 CPU SMM driver by removing 
most of S3 related logics.
I hope it can be merged next week when the stable tag freeze ends in the end of 
this week.

Thanks,
Ray

From: Tan, Dun mailto:dun@intel.com>>
Sent: Friday, May 17, 2024 17:45
To: devel@edk2.groups.io 
mailto:devel@edk2.groups.io>>
Cc: Liming Gao mailto:gaolim...@byosoft.com.cn>>; Wu, 
Jiaxin mailto:jiaxin...@intel.com>>; Ni, Ray 
mailto:ray...@intel.com>>; Ard Biesheuvel 
mailto:ardb+tianoc...@kernel.org>>; Yao, Jiewen 
mailto:jiewen@intel.com>>; Gerd Hoffmann 
mailto:kra...@redhat.com>>; Kumar, Rahul R 
mailto:rahul.r.ku...@intel.com>>
Subject: [Patch V2 00/18] Remove some S3 related code in CpuS3.c of smm cpu 
driver

Comparing to V1 patchs set, the V2 patch set only adjusts the commits ordering 
and modifies copy right year in some files.
This patch set is to remove some S3 related code in CpuS3.c of smm cpu driver. 
It contain commits to:
1) S3 MTRRs operation:
>   MdeModulePkg: Add gEdkiiS3MtrrSettingGuid
>   OvmfPkg: Save MTRR by lockbox in CpuS3DataDxe
>   UefiCpuPkg: Add locbox lib instance in DSC
>   UefiCpuPkg: Save MTRR by lockbox in CpuS3DataDxe
>   UefiCpuPkg: LoadMtrrData for all cpu in S3Resume
>   UefiCpuPkg: Remove code to load mtrr setting

2) AP page table unavailiable issue fix:
>   UefiCpuPkg: Disable PG in IA32 ApLoopCode

3) Register table cleanup:
>   UefiCpuPkg:Set PcdCpuFeaturesInitOnS3Resume to TRUE
>   UefiCpuPkg: Remove code to set register table

4)  S3 ApHltLoopCode Operation:
>   UefiCpuPkg:Abstract some DxeMpLib code to function
>   UefiCpuPkg:Move some code in DxeMpLib to common place
>   UefiCpuPkg: Install gEdkiiEndOfS3ResumeGuid in S3Resume
>   UefiCpuPkg:Relocate AP to new safe buffer in PeiMpLib
>   UefiCpuPkg:Remove code to handle APIC setting and Interrupt
>   UefiCpuPkg:Rremove code to wakeup AP and relocate ap
>   UefiCpuPkg: Remove the duplicated mpservice locate
>   MdeModulePkg: remove MpService2Ppi field in SMM_S3_RESUME_STATE

5)  Remove code to get AcpiCpuData:
>   UefiCpuPkg: Remove GetAcpiCpuData() in CpuS3.c

With this patch set, CpuS3.c in smm CPU driver can be simplified.
The whole patch set has been reviewed-by Ray.
PR for review: https://github.com/tianocore/edk2/pull/5606

Cc: Liming Gao mailto:gaolim...@byosoft.com.cn>>
Cc: Jiaxin Wu mailto:jiaxin...@intel.com>>
Cc: Ray Ni mailto:ray...@intel.com>>
Cc: Ard Biesheuvel mailto:ardb+tianoc...@kernel.org>>
Cc: Jiewen Yao mailto:jiewen@intel.com>>
Cc: Gerd Hoffmann mailto:kra...@redhat.com>>
Cc: Rahul Kumar mailto:rahul1.ku...@intel.com>>
Cc: Gerd Hoffmann mailto:kra...@redhat.com>>

Dun Tan (18):
  MdeModulePkg: Add gEdkiiS3MtrrSettingGuid
  OvmfPkg: Save MTRR by lockbox in CpuS3DataDxe
  UefiCpuPkg: Add locbox lib instance in DSC
  UefiCpuPkg: Save MTRR by lockbox in CpuS3DataDxe
  UefiCpuPkg: LoadMtrrData for all cpu in S3Resume
  UefiCpuPkg: Remove code to load mtrr setting
  UefiCpuPkg:Set PcdCpuFeaturesInitOnS3Resume to TRUE
  UefiCpuPkg: Remove code to set register table
  UefiCpuPkg: Disable PG in IA32 ApLoopCode
  UefiCpuPkg:Abstract some DxeMpLib code to function
  UefiCpuPkg:Move some code in DxeMpLib to common place
  UefiCpuPkg: Install gEdkiiEndOfS3ResumeGuid in S3Resume
  UefiCpuPkg:Relocate AP to new safe buffer in PeiMpLib
  UefiCpuPkg:Remove code to handle APIC setting and Interrupt
  UefiCpuPkg:Remove code to wakeup AP and relocate ap
  UefiCpuPkg: Remove unneeded MpService2Ppi assignment
  MdeModulePkg:Remove MpService2Ppi field in SMM_S3_RESUME_STATE
  UefiCpuPkg: Remove GetAcpiCpuData() in CpuS3.c

 MdeModulePkg/Include/Guid/AcpiS3Context.h   |   3 +--
 MdeModulePkg/MdeModulePkg.dec   |   5 -
 OvmfPkg/CpuS3DataDxe/CpuS3Data.c|  13 -
 OvmfPkg/CpuS3DataDxe/CpuS3DataDxe.inf   |   4 +++-
 UefiCpuPkg/CpuS3DataDxe/CpuS3Data.c |  13 -
 UefiCpuPkg/CpuS3DataDxe/CpuS3DataDxe.inf|   4 +++-
 UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 183 

Re: [edk2-devel] [PATCH] UefiCpuPkg:fix issue when splitting paging entry

2024-05-23 Thread Wu, Jiaxin
Reviewed-by: Jiaxin Wu 

> -Original Message-
> From: Tan, Dun 
> Sent: Friday, May 17, 2024 5:45 PM
> To: devel@edk2.groups.io
> Cc: Ni, Ray ; Kumar, Rahul R ;
> Gerd Hoffmann ; Wu, Jiaxin ;
> Zhou, Jianfeng 
> Subject: [PATCH] UefiCpuPkg:fix issue when splitting paging entry
> 
> This patch is to fix issue when splitting leaf paging
> entry in CpuPageTableLib code.
> 
> In previous code, before we assign the new child paging
> structure address to the content of splitted paging entry,
> PageTableLibSetPnle() is called to make sure the bit7 is
> set to 0, which indicate the previous leaf entry is
> changed to non-leaf entry now. There is a gap between
> we change the bit7 and we assign the new child paging
> structure address to the content of the splitted paging
> entry. If the address of code execution or data access
> happens to be in the range covered by the splitted paging
> entry, this gap may cause issue.
> 
> In this patch, we prepare the new paging entry content
> value in a local variable and assign the value to the
> splitted paging entry at once. The volatile keyword
> is used to ensure that no optimization will occur in
> compilation.
> 
> Signed-off-by: Dun Tan 
> Cc: Ray Ni 
> Cc: Rahul Kumar 
> Cc: Gerd Hoffmann 
> Cc: Jiaxin Wu 
> Cc: Zhou Jianfeng 
> ---
>  UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c | 9 +++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c
> b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c
> index b10a3008e4..bdc411338f 100644
> --- a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c
> +++ b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c
> @@ -342,6 +342,7 @@ PageTableLibMapInLevel (
>UINT64  PhysicalAddrInAttr;
>IA32_PAGING_ENTRY   OriginalParentPagingEntry;
>IA32_PAGING_ENTRY   OriginalCurrentPagingEntry;
> +  IA32_PAGING_ENTRY   TempPagingEntry;
> 
>ASSERT (Level != 0);
>ASSERT ((Attribute != NULL) && (Mask != NULL));
> @@ -359,6 +360,8 @@ PageTableLibMapInLevel (
> 
>OriginalParentPagingEntry.Uint64 = ParentPagingEntry->Uint64;
>OneOfPagingEntry.Uint64  = 0;
> +  TempPagingEntry.Uint64   = 0;
> +
>//
>// RegionLength: 256T (1 << 48) 512G (1 << 39), 1G (1 << 30), 2M (1 << 21)
> or 4K (1 << 12).
>//
> @@ -441,8 +444,10 @@ PageTableLibMapInLevel (
>// Non-leaf entry doesn't have PAT bit. So use
> ~IA32_PE_BASE_ADDRESS_MASK_40 is to make sure PAT bit
>// (bit12) in original big-leaf entry is not assigned to 
> PageTableBaseAddress
> field of non-leaf entry.
>//
> -  PageTableLibSetPnle (>Pnle, ,
> );
> -  ParentPagingEntry->Uint64 = ((UINTN)(VOID *)PagingEntry) |
> (ParentPagingEntry->Uint64 & (~IA32_PE_BASE_ADDRESS_MASK_40));
> +  TempPagingEntry.Uint64 = ParentPagingEntry->Uint64;
> +  PageTableLibSetPnle (, ,
> );
> +  TempPagingEntry.Uint64   = ((UINTN)(VOID 
> *)PagingEntry) |
> (TempPagingEntry.Uint64 & (~IA32_PE_BASE_ADDRESS_MASK_40));
> +  *(volatile UINT64 *)&(ParentPagingEntry->Uint64) =
> TempPagingEntry.Uint64;
>  }
>} else {
>  //
> --
> 2.31.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119183): https://edk2.groups.io/g/devel/message/119183
Mute This Topic: https://groups.io/mt/106150750/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [Patch V2 00/18] Remove some S3 related code in CpuS3.c of smm cpu driver

2024-05-23 Thread Wu, Jiaxin
Series Reviewed-by: Jiaxin Wu 

The series patches are good to me now. Thanks Dun.

Thanks,
Jiaxin

> -Original Message-
> From: Tan, Dun 
> Sent: Friday, May 17, 2024 5:46 PM
> To: devel@edk2.groups.io
> Cc: Liming Gao ; Wu, Jiaxin
> ; Ni, Ray ; Ard Biesheuvel
> ; Yao, Jiewen ; Gerd
> Hoffmann ; Kumar, Rahul R 
> Subject: [Patch V2 00/18] Remove some S3 related code in CpuS3.c of smm
> cpu driver
> 
> Comparing to V1 patchs set, the V2 patch set only adjusts the commits
> ordering and modifies copy right year in some files.
> This patch set is to remove some S3 related code in CpuS3.c of smm cpu
> driver. It contain commits to:
> 1) S3 MTRRs operation:
> >   MdeModulePkg: Add gEdkiiS3MtrrSettingGuid
> >   OvmfPkg: Save MTRR by lockbox in CpuS3DataDxe
> >   UefiCpuPkg: Add locbox lib instance in DSC
> >   UefiCpuPkg: Save MTRR by lockbox in CpuS3DataDxe
> >   UefiCpuPkg: LoadMtrrData for all cpu in S3Resume
> >   UefiCpuPkg: Remove code to load mtrr setting
> 
> 2) AP page table unavailiable issue fix:
> >   UefiCpuPkg: Disable PG in IA32 ApLoopCode
> 
> 3) Register table cleanup:
> >   UefiCpuPkg:Set PcdCpuFeaturesInitOnS3Resume to TRUE
> >   UefiCpuPkg: Remove code to set register table
> 
> 4)  S3 ApHltLoopCode Operation:
> >   UefiCpuPkg:Abstract some DxeMpLib code to function
> >   UefiCpuPkg:Move some code in DxeMpLib to common place
> >   UefiCpuPkg: Install gEdkiiEndOfS3ResumeGuid in S3Resume
> >   UefiCpuPkg:Relocate AP to new safe buffer in PeiMpLib
> >   UefiCpuPkg:Remove code to handle APIC setting and Interrupt
> >   UefiCpuPkg:Rremove code to wakeup AP and relocate ap
> >   UefiCpuPkg: Remove the duplicated mpservice locate
> >   MdeModulePkg: remove MpService2Ppi field in SMM_S3_RESUME_STATE
> 
> 5)  Remove code to get AcpiCpuData:
> >   UefiCpuPkg: Remove GetAcpiCpuData() in CpuS3.c
> 
> With this patch set, CpuS3.c in smm CPU driver can be simplified.
> The whole patch set has been reviewed-by Ray.
> PR for review: https://github.com/tianocore/edk2/pull/5606
> 
> Cc: Liming Gao 
> Cc: Jiaxin Wu 
> Cc: Ray Ni 
> Cc: Ard Biesheuvel 
> Cc: Jiewen Yao 
> Cc: Gerd Hoffmann 
> Cc: Rahul Kumar 
> Cc: Gerd Hoffmann 
> 
> Dun Tan (18):
>   MdeModulePkg: Add gEdkiiS3MtrrSettingGuid
>   OvmfPkg: Save MTRR by lockbox in CpuS3DataDxe
>   UefiCpuPkg: Add locbox lib instance in DSC
>   UefiCpuPkg: Save MTRR by lockbox in CpuS3DataDxe
>   UefiCpuPkg: LoadMtrrData for all cpu in S3Resume
>   UefiCpuPkg: Remove code to load mtrr setting
>   UefiCpuPkg:Set PcdCpuFeaturesInitOnS3Resume to TRUE
>   UefiCpuPkg: Remove code to set register table
>   UefiCpuPkg: Disable PG in IA32 ApLoopCode
>   UefiCpuPkg:Abstract some DxeMpLib code to function
>   UefiCpuPkg:Move some code in DxeMpLib to common place
>   UefiCpuPkg: Install gEdkiiEndOfS3ResumeGuid in S3Resume
>   UefiCpuPkg:Relocate AP to new safe buffer in PeiMpLib
>   UefiCpuPkg:Remove code to handle APIC setting and Interrupt
>   UefiCpuPkg:Remove code to wakeup AP and relocate ap
>   UefiCpuPkg: Remove unneeded MpService2Ppi assignment
>   MdeModulePkg:Remove MpService2Ppi field in SMM_S3_RESUME_STATE
>   UefiCpuPkg: Remove GetAcpiCpuData() in CpuS3.c
> 
>  MdeModulePkg/Include/Guid/AcpiS3Context.h   |   3 +--
>  MdeModulePkg/MdeModulePkg.dec   |   5 -
>  OvmfPkg/CpuS3DataDxe/CpuS3Data.c|  13 -
>  OvmfPkg/CpuS3DataDxe/CpuS3DataDxe.inf   |   4 +++-
>  UefiCpuPkg/CpuS3DataDxe/CpuS3Data.c |  13 -
>  UefiCpuPkg/CpuS3DataDxe/CpuS3DataDxe.inf|   4 +++-
>  UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 183
> -
> --
> --
>  UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm  |   6 +-
>  UefiCpuPkg/Library/MpInitLib/MpLib.c| 144
> ++
> ++
> +++-
>  UefiCpuPkg/Library/MpInitLib/MpLib.h|  56
> +++--
>  UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf   |   6 +-
>  UefiCpuPkg/Library/MpInitLib/PeiMpLib.c | 154
> ++
> ++
> +-
>  UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c   | 993 
> +---
> --
> -
>  UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/MpFuncs.nasm | 153 
> --
> 

Re: [edk2-devel] [PATCH] Pkg-Module:UefiCpuPkg/MpLib:Do not assume BSP is #0.

2024-05-23 Thread Ni, Ray
Ning,
I missed one minor issue with your patch.

Can you check if the following GetBspNumber() call can be removed?

  if (FirstMpHandOff == NULL) {
...
  } else {
...
CpuMpData->CpuCount  = MaxLogicalProcessorNumber;
CpuMpData->BspNumber = GetBspNumber (FirstMpHandOff);
CpuInfoInHob = (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob;


BTW, please remove "Pkg-Module:" from the subject.

Thanks,
Ray

From: Feng, Ning 
Sent: Friday, May 24, 2024 7:16
To: devel@edk2.groups.io 
Cc: Feng, Ning ; Ni, Ray 
Subject: [PATCH] Pkg-Module:UefiCpuPkg/MpLib:Do not assume BSP is #0.

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=4778
MPInitlib have wrong expectation that BSP index should always be 0 in
MpInitLibInitialize(), SwitchBsp(),ApWakeupFunction().
That will cause the data mismatch, if the initial BSP is not 0.
Cc: Ray Ni 
Signed-off-by: Ning Feng 
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 34 
 1 file changed, 24 insertions(+), 10 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index d724456502..ae279c6ceb 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -114,6 +114,10 @@ FutureBSPProc (
   SaveVolatileRegisters (>APInfo.VolatileRegisters);

   AsmExchangeRole (>APInfo, >BSPInfo);

   RestoreVolatileRegisters (>APInfo.VolatileRegisters, FALSE);

+  //

+  // Restore VolatileReg saved in CpuMpData->CpuData

+  //

+  CopyMem (>CpuData[DataInHob->BspNumber].VolatileRegisters, 
>APInfo.VolatileRegisters, sizeof (CPU_VOLATILE_REGISTERS));

 }



 /**

@@ -761,11 +765,11 @@ ApWakeupFunction (
   BistData = (UINT32)ApStackData->Bist;



   //

-  // CpuMpData->CpuData[0].VolatileRegisters is initialized based on BSP 
environment,

+  // CpuMpData->CpuData[BspNumber].VolatileRegisters is initialized based 
on BSP environment,

   //   to initialize AP in InitConfig path.

-  // NOTE: IDTR.BASE stored in CpuMpData->CpuData[0].VolatileRegisters 
points to a different IDT shared by all APs.

+  // NOTE: IDTR.BASE stored in 
CpuMpData->CpuData[BspNumber].VolatileRegisters points to a different IDT 
shared by all APs.

   //

-  RestoreVolatileRegisters (>CpuData[0].VolatileRegisters, 
FALSE);

+  RestoreVolatileRegisters 
(>CpuData[CpuMpData->BspNumber].VolatileRegisters, FALSE);

   InitializeApData (CpuMpData, ProcessorNumber, BistData, ApTopOfStack);

   ApStartupSignalBuffer = 
CpuMpData->CpuData[ProcessorNumber].StartupApSignal;

 } else {

@@ -798,10 +802,10 @@ ApWakeupFunction (
 // 1. AP is re-enabled after it's disabled, in either PEI or DXE phase.

 // 2. AP is initialized in DXE phase.

 // In either case, use the volatile registers value derived from BSP.

-// NOTE: IDTR.BASE stored in CpuMpData->CpuData[0].VolatileRegisters 
points to a

+// NOTE: IDTR.BASE stored in 
CpuMpData->CpuData[BspNumber].VolatileRegisters points to a

 //   different IDT shared by all APs.

 //

-RestoreVolatileRegisters (>CpuData[0].VolatileRegisters, 
FALSE);

+RestoreVolatileRegisters 
(>CpuData[CpuMpData->BspNumber].VolatileRegisters, FALSE);

   } else {

 if (CpuMpData->ApLoopMode == ApInHltLoop) {

   //

@@ -927,7 +931,7 @@ DxeApEntryPoint (
 AsmWriteMsr64 (MSR_IA32_EFER, EferMsr.Uint64);

   }



-  RestoreVolatileRegisters (>CpuData[0].VolatileRegisters, FALSE);

+  RestoreVolatileRegisters 
(>CpuData[CpuMpData->BspNumber].VolatileRegisters, FALSE);

   InterlockedIncrement ((UINT32 *)>FinishedCount);

   PlaceAPInMwaitLoopOrRunLoop (

 CpuMpData->ApLoopMode,

@@ -2151,7 +2155,12 @@ MpInitLibInitialize (
   CpuMpData->BackupBufferSize = ApResetVectorSizeBelow1Mb;

   CpuMpData->WakeupBuffer = (UINTN)-1;

   CpuMpData->CpuCount = 1;

-  CpuMpData->BspNumber= 0;

+  if (MpHandOff == NULL) {

+CpuMpData->BspNumber = 0;

+  } else {

+CpuMpData->BspNumber = GetBspNumber (MpHandOff);

+  }

+

   CpuMpData->WaitEvent= NULL;

   CpuMpData->SwitchBspFlag= FALSE;

   CpuMpData->CpuData  = (CPU_AP_DATA *)(CpuMpData + 1);

@@ -2186,11 +2195,11 @@ MpInitLibInitialize (
   // Don't pass BSP's TR to APs to avoid AP init failure.

   //

   VolatileRegisters.Tr = 0;

-  CopyMem (>CpuData[0].VolatileRegisters, , 
sizeof (VolatileRegisters));

+  CopyMem (>CpuData[CpuMpData->BspNumber].VolatileRegisters, 
, sizeof (VolatileRegisters));

   //

   // Set BSP basic information

   //

-  InitializeApData (CpuMpData, 0, 0, CpuMpData->Buffer + ApStackSize);

+  InitializeApData (CpuMpData, CpuMpData->BspNumber, 0, CpuMpData->Buffer + 
ApStackSize * (CpuMpData->BspNumber + 1));

   //

   // Save assembly code information

   //

@@ -2615,7 +2624,12 @@ SwitchBSPWorker (
   SaveVolatileRegisters (>BSPInfo.VolatileRegisters);

   AsmExchangeRole (>BSPInfo, 

回复: [edk2-devel] 回复: [edk2-devel] [PATCH v2 03/13] OvmfPkg:PlatformCI: Support virtio-rng-pci

2024-05-23 Thread gaoliming via groups.io
Doug:
  Have you any update for this patch set?

Thanks
Liming
> -邮件原件-
> 发件人: devel@edk2.groups.io  代表 Gerd Hoffmann
> 发送时间: 2024年5月17日 17:48
> 收件人: devel@edk2.groups.io; a...@kernel.org
> 抄送: Doug Flick ; Jiewen Yao
> ; Liming Gao (Byosoft address)
> 
> 主题: Re: [edk2-devel] 回复: [edk2-devel] [PATCH v2 03/13]
> OvmfPkg:PlatformCI: Support virtio-rng-pci
> 
> On Fri, May 17, 2024 at 09:27:53AM GMT, Ard Biesheuvel wrote:
> > On Fri, 17 May 2024 at 05:27, Doug Flick via groups.io
> >  wrote:
> > >
> > > On ARM, we can actually do better than this: I have taken Doug's v2
and
> applied some changes on top to make it work with ArmVirtQemu.
> > >
> > > https://github.com/ardbiesheuvel/edk2/tree/doug-v2
> > >
> > > Ard, would you be comfortable with this patch series if I take the
commits
> you're suggesting? I'm being asked to see what it would take to get these
commits
> in for this release.
> >
> > I won't object to that, but I'd like Gerd's take as well, given that a
> > similar concern appears to apply to OVMF/x86 IIUC.
> 
> I think including RngDxe in OvmfPkg is not an option.  That would
> be a silent regression on the random number quality delivered by
> EFI_RNG_PROTOCOL because OvmfPkg uses BaseRngLibTimerLib.
> 
> Switching to BaseRngLib is an easy way out for physical platforms
> with a sufficient recent processor.  OVMF can not assume the rdrand
> instruction is available, so that is not possible.
> 
> So short-term (i.e. 2024-05 stable tag) the only option I see is
> depending on virtio-rng.  Which is a regression too (network booting
> without '-device virtio-rng-pci' breaks), but it is an obvious failure
> with an easy fix.  Not an ideal solution, but much better than a
> regression which can easily go unnoticed.
> 
> Longer term it probably makes sense to have a EFI_RNG_PROTOCOL driver
> using the rdrand instruction and runtime detection whenever the
> instruction is available or not.  Either by adapting RngDxe accordingly,
> or by having an OVMF-specific driver handling the runtime detection.
> 
> take care,
>   Gerd
> 
> 
> 
> 
> 





-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119180): https://edk2.groups.io/g/devel/message/119180
Mute This Topic: https://groups.io/mt/106275345/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v1 6/6] UefiPayloadPkg: Update UefiPayload driver for FDT support.

2024-05-23 Thread Linus Liu
Add FDT detection and comsume FDT when needed.
Move some x86 speciifc function in the x86 folder.
Create HandOffHbo via FDT memory node.

Cc: Benny Lin 
Cc: Gua Guo 
Cc: Chasel Chiu 
Cc: James Lu 
Cc: Dhaval Sharma 

Signed-off-by: Linus Liu 
---
 UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.c   | 428 
+---
 UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFunc.c   |  12 
+
 UefiPayloadPkg/UefiPayloadEntry/Ia32/{DxeLoadFunc.c => DxeLoadFuncFit.c} |  32 
+-
 UefiPayloadPkg/UefiPayloadEntry/MemoryAllocation.c   |  50 
+++
 UefiPayloadPkg/UefiPayloadEntry/PrintHob.c   |   6 
+-
 UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c  |   6 
-
 UefiPayloadPkg/UefiPayloadEntry/X64/DxeLoadFunc.c|  12 
+
 UefiPayloadPkg/UefiPayloadEntry/X64/{DxeLoadFunc.c => DxeLoadFuncFit.c}  |  31 
+-
 UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.inf |  20 
+-
 UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h   |  68 

 UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf|  16 
+-
 UefiPayloadPkg/UefiPayloadPkg.dsc|  29 
+-
 12 files changed, 443 insertions(+), 267 deletions(-)

diff --git a/UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.c 
b/UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.c
index eb0b325369a0..813d656950d1 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.c
+++ b/UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.c
@@ -6,6 +6,8 @@
 #include "UefiPayloadEntry.h"
 #include 
 #include 
+#include 
+#include 
 
 #define MEMORY_ATTRIBUTE_MASK  (EFI_RESOURCE_ATTRIBUTE_PRESENT |   
 \
EFI_RESOURCE_ATTRIBUTE_INITIALIZED  
   | \
@@ -23,6 +25,15 @@
EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \
EFI_RESOURCE_ATTRIBUTE_TESTED  )
 
+EFI_MEMORY_TYPE_INFORMATION  mDefaultMemoryTypeInformation[] = {
+  { EfiACPIReclaimMemory,   FixedPcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory)  
 },
+  { EfiACPIMemoryNVS,   FixedPcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS)  
 },
+  { EfiReservedMemoryType,  FixedPcdGet32 (PcdMemoryTypeEfiReservedMemoryType) 
 },
+  { EfiRuntimeServicesData, FixedPcdGet32 
(PcdMemoryTypeEfiRuntimeServicesData) },
+  { EfiRuntimeServicesCode, FixedPcdGet32 
(PcdMemoryTypeEfiRuntimeServicesCode) },
+  { EfiMaxMemoryType,   0  
 }
+};
+
 extern VOID  *mHobList;
 
 CHAR8  *mLineBuffer = NULL;
@@ -36,6 +47,78 @@ PrintHob (
   IN CONST VOID  *HobStart
   );
 
+/**
+  Add HOB into HOB list
+  @param[in]  HobThe HOB to be added into the HOB list.
+**/
+VOID
+AddNewHob (
+  IN EFI_PEI_HOB_POINTERS  *Hob
+  );
+
+/**
+  Found the Resource Descriptor HOB that contains a range (Base, Top)
+  @param[in] HobListHob start address
+  @param[in] Base   Memory start address
+  @param[in] TopMemory end address.
+  @retval The pointer to the Resource Descriptor HOB.
+**/
+EFI_HOB_RESOURCE_DESCRIPTOR *
+FindResourceDescriptorByRange (
+  IN VOID  *HobList,
+  IN EFI_PHYSICAL_ADDRESS  Base,
+  IN EFI_PHYSICAL_ADDRESS  Top
+  );
+
+/**
+  Find the highest below 4G memory resource descriptor, except the input 
Resource Descriptor.
+  @param[in] HobList Hob start address
+  @param[in] MinimalNeededSize   Minimal needed size.
+  @param[in] ExceptResourceHob   Ignore this Resource Descriptor.
+  @retval The pointer to the Resource Descriptor HOB.
+**/
+EFI_HOB_RESOURCE_DESCRIPTOR *
+FindAnotherHighestBelow4GResourceDescriptor (
+  IN VOID *HobList,
+  IN UINTNMinimalNeededSize,
+  IN EFI_HOB_RESOURCE_DESCRIPTOR  *ExceptResourceHob
+  );
+
+/**
+  Check the HOB and decide if it is need inside Payload
+  Payload maintainer may make decision which HOB is need or needn't
+  Then add the check logic in the function.
+  @param[in] Hob The HOB to check
+  @retval TRUE  If HOB is need inside Payload
+  @retval FALSE If HOB is needn't inside Payload
+**/
+BOOLEAN
+FitIsHobNeed (
+  EFI_PEI_HOB_POINTERS  Hob
+  );
+
+/**
+  Check the HOB and decide if it is need inside Payload
+
+  Payload maintainer may make decision which HOB is need or needn't
+  Then add the check logic in the function.
+
+  @param[in] Hob The HOB to check
+
+  @retval TRUE  If HOB is need inside Payload
+  @retval FALSE If HOB is needn't inside Payload
+**/
+BOOLEAN
+IsHobNeed (
+  EFI_PEI_HOB_POINTERS  Hob
+  );
+
+VOID
+EFIAPI
+ProcessLibraryConstructorList (
+  VOID
+  );
+
 /**
   Find the first substring.
   @param  StringPoint to the string where to find the substring.
@@ -191,187 +274,6 @@ FixUpPcdDatabase (
   return EFI_SUCCESS;
 }
 
-/**
-  Add HOB into HOB list
- 

Re: [edk2-devel] libspdm Breaking Builds

2024-05-23 Thread Yao, Jiewen
Hello
Thanks for Michael Kubacki's effort. The cmocka for libspdm is switched to 
https://gitlab.com/cmocka/cmocka.git 
(https://github.com/DMTF/libspdm/pull/2710).

The next libspdm release is planned at the end of June.

Please let us know if the preference for libspdm submodule. (Below options)
1) Keep current libspdm official 3.3.0 release, and update to next release at 
the beginning of July.
2) Update libspdm immediately with the new cmocka submodule, which is NOT an 
official release.


Thank you
Yao, Jiewen

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Yao, Jiewen
> Sent: Thursday, May 23, 2024 10:17 AM
> To: Kinney, Michael D ; devel@edk2.groups.io;
> mikub...@linux.microsoft.com
> Subject: Re: [edk2-devel] libspdm Breaking Builds
> 
> Hello
> I am sorry to bring the inconvenience.
> I think the libspdm maintainers are aware of fact that the breaking of cmoka
> impacts the CI.
> 
> In history of libspdm, we did see this sometimes, but usually it was back 
> online
> after a while.
> That is the reason libspdm project is still using cmoka github, since it is 
> good at
> most of time.
> 
> I will discuss libspdm/cmoka issue in regular SPDM TF meeting, and update the
> issue https://github.com/DMTF/libspdm/issues/2707.
> 
> 
> It is similar to what I have observed in tianocore project. Tianocore CI 
> breaks
> sometimes, and works again after a while. But that is NOT a reason to disable 
> it.
> 
> Anyway, I think tianocore project has freedom to choose whatever options,
> independent with libspdm project. And I hope we have a consistent way to 
> handle
> all projects.
> 
> Thank you
> Yao, Jiewen
> 
> 
> > -Original Message-
> > From: Kinney, Michael D 
> > Sent: Thursday, May 23, 2024 9:52 AM
> > To: devel@edk2.groups.io; mikub...@linux.microsoft.com; Yao, Jiewen
> > 
> > Cc: Kinney, Michael D 
> > Subject: RE: [edk2-devel] libspdm Breaking Builds
> >
> > We have a mirror of cmocka in tianocore.
> >
> > https://github.com/tianocore/edk2-cmocka
> >
> > It is out of sync because GitHub keep disabling the workflow.
> >
> > And the workflow can not run until cmocka repo is back up.
> >
> > We updated UnitTestFrameworkPkg to use tianocore cmocka mirror long ago
> > for this exact failure case.
> >
> > Since we do not have control over libspdm submodule link to cmocka, what
> > we need is an override or a failover submodule link to tianocore mirror.
> >
> > Any ideas on how to implement that concept.  Does git have failover or
> > override URL for git submodules?
> >
> > Or do we need more stuart feature to have more fine grain control over
> > Submodules?
> >
> > Mike
> >
> > > -Original Message-
> > > From: devel@edk2.groups.io  On Behalf Of Michael
> > > Kubacki
> > > Sent: Wednesday, May 22, 2024 6:04 PM
> > > To: Kinney, Michael D ; devel@edk2.groups.io;
> > > Yao, Jiewen 
> > > Subject: Re: [edk2-devel] libspdm Breaking Builds
> > >
> > > We looked at Stuart and it can prevent a recursive submodule update at
> > > the first level but then it would prevent further updates. Here Repo A
> > > can prevent a recursive update in edk2 but it would then not be able to
> > > get libspdm.
> > >
> > >[Repo A] -[1]> [edk2] -[2]> [libspdm] -[3]> [cmocka]
> > >
> > > At its root, the issue is that this is broken, not wasteful. Therefore,
> > > it is disruptive and a regression for existing workflows.
> > >
> > > We, and I'm sure many other projects, recursively clone packages in edk2
> > > with submodules. For years, this has been fine except for a few brief
> > > exceptions. We pulled the change with the libspdm dependency into our
> > > codebase 8 days ago and this has been broken all day. The track record
> > > of cryptomilk.org in the past was also very poor and frequently caused
> > > problems. There is not an incident response team that I'm aware of at
> > > cryptomilk.org that provides status updates and proactively addresses
> > > services issues (i.e. https://www.githubstatus.com/).
> > >
> > > Also, libspdm is now a dependency and cloning cmocka there may fail.
> > > Users should expect that they can clone and work in that repo as part of
> > > their firmware development process without frequent service disruptions
> > > in the way.
> > >
> > > While I started this thread to raise the issue for users impacted here,
> > > I filed https://github.com/DMTF/libspdm/issues/2707 to track the request
> > > in the libspdm repo.
> > >
> > > Thanks,
> > > Michael
> > >
> > > On 5/22/2024 6:24 PM, Kinney, Michael D wrote:
> > > > Libspdm also depends on openssl.  We did not want to clone openssl 
> > > > twice.
> > > >
> > > > I though stuart config specifies which submodules to clone.  Can't we 
> > > > skip
> > > > all the submodules within libspdm to fix CI?
> > > >
> > > > Can't devs choose to not use --recursive?
> > > >
> > > > Mike
> > > >
> > > >> -Original Message-
> > > >> From: Michael Kubacki 
> > > >> Sent: Wednesday, May 22, 2024 3:16 PM
> 

[edk2-devel] [PATCH v1 6/6] UefiPayloadPkg: Update UefiPayload driver for FDT support.

2024-05-23 Thread Linus Liu
Add FDT detection and comsume FDT when needed.
Move some x86 speciifc function in the x86 folder.
Create HandOffHbo via FDT memory node.

Cc: Benny Lin 
Cc: Gua Guo 
Cc: Chasel Chiu 
Cc: James Lu 
Cc: Dhaval Sharma 

Signed-off-by: Linus Liu 
---
 UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.c   | 428 
+---
 UefiPayloadPkg/UefiPayloadEntry/Ia32/DxeLoadFunc.c   |  12 
+
 UefiPayloadPkg/UefiPayloadEntry/Ia32/{DxeLoadFunc.c => DxeLoadFuncFit.c} |  32 
+-
 UefiPayloadPkg/UefiPayloadEntry/MemoryAllocation.c   |  50 
+++
 UefiPayloadPkg/UefiPayloadEntry/PrintHob.c   |   6 
+-
 UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c  |   6 
-
 UefiPayloadPkg/UefiPayloadEntry/X64/DxeLoadFunc.c|  12 
+
 UefiPayloadPkg/UefiPayloadEntry/X64/{DxeLoadFunc.c => DxeLoadFuncFit.c}  |  31 
+-
 UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.inf |  20 
+-
 UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h   |  68 

 UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf|  16 
+-
 UefiPayloadPkg/UefiPayloadPkg.dsc|  29 
+-
 12 files changed, 443 insertions(+), 267 deletions(-)

diff --git a/UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.c 
b/UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.c
index eb0b325369a0..813d656950d1 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.c
+++ b/UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.c
@@ -6,6 +6,8 @@
 #include "UefiPayloadEntry.h"
 #include 
 #include 
+#include 
+#include 
 
 #define MEMORY_ATTRIBUTE_MASK  (EFI_RESOURCE_ATTRIBUTE_PRESENT |   
 \
EFI_RESOURCE_ATTRIBUTE_INITIALIZED  
   | \
@@ -23,6 +25,15 @@
EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \
EFI_RESOURCE_ATTRIBUTE_TESTED  )
 
+EFI_MEMORY_TYPE_INFORMATION  mDefaultMemoryTypeInformation[] = {
+  { EfiACPIReclaimMemory,   FixedPcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory)  
 },
+  { EfiACPIMemoryNVS,   FixedPcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS)  
 },
+  { EfiReservedMemoryType,  FixedPcdGet32 (PcdMemoryTypeEfiReservedMemoryType) 
 },
+  { EfiRuntimeServicesData, FixedPcdGet32 
(PcdMemoryTypeEfiRuntimeServicesData) },
+  { EfiRuntimeServicesCode, FixedPcdGet32 
(PcdMemoryTypeEfiRuntimeServicesCode) },
+  { EfiMaxMemoryType,   0  
 }
+};
+
 extern VOID  *mHobList;
 
 CHAR8  *mLineBuffer = NULL;
@@ -36,6 +47,78 @@ PrintHob (
   IN CONST VOID  *HobStart
   );
 
+/**
+  Add HOB into HOB list
+  @param[in]  HobThe HOB to be added into the HOB list.
+**/
+VOID
+AddNewHob (
+  IN EFI_PEI_HOB_POINTERS  *Hob
+  );
+
+/**
+  Found the Resource Descriptor HOB that contains a range (Base, Top)
+  @param[in] HobListHob start address
+  @param[in] Base   Memory start address
+  @param[in] TopMemory end address.
+  @retval The pointer to the Resource Descriptor HOB.
+**/
+EFI_HOB_RESOURCE_DESCRIPTOR *
+FindResourceDescriptorByRange (
+  IN VOID  *HobList,
+  IN EFI_PHYSICAL_ADDRESS  Base,
+  IN EFI_PHYSICAL_ADDRESS  Top
+  );
+
+/**
+  Find the highest below 4G memory resource descriptor, except the input 
Resource Descriptor.
+  @param[in] HobList Hob start address
+  @param[in] MinimalNeededSize   Minimal needed size.
+  @param[in] ExceptResourceHob   Ignore this Resource Descriptor.
+  @retval The pointer to the Resource Descriptor HOB.
+**/
+EFI_HOB_RESOURCE_DESCRIPTOR *
+FindAnotherHighestBelow4GResourceDescriptor (
+  IN VOID *HobList,
+  IN UINTNMinimalNeededSize,
+  IN EFI_HOB_RESOURCE_DESCRIPTOR  *ExceptResourceHob
+  );
+
+/**
+  Check the HOB and decide if it is need inside Payload
+  Payload maintainer may make decision which HOB is need or needn't
+  Then add the check logic in the function.
+  @param[in] Hob The HOB to check
+  @retval TRUE  If HOB is need inside Payload
+  @retval FALSE If HOB is needn't inside Payload
+**/
+BOOLEAN
+FitIsHobNeed (
+  EFI_PEI_HOB_POINTERS  Hob
+  );
+
+/**
+  Check the HOB and decide if it is need inside Payload
+
+  Payload maintainer may make decision which HOB is need or needn't
+  Then add the check logic in the function.
+
+  @param[in] Hob The HOB to check
+
+  @retval TRUE  If HOB is need inside Payload
+  @retval FALSE If HOB is needn't inside Payload
+**/
+BOOLEAN
+IsHobNeed (
+  EFI_PEI_HOB_POINTERS  Hob
+  );
+
+VOID
+EFIAPI
+ProcessLibraryConstructorList (
+  VOID
+  );
+
 /**
   Find the first substring.
   @param  StringPoint to the string where to find the substring.
@@ -191,187 +274,6 @@ FixUpPcdDatabase (
   return EFI_SUCCESS;
 }
 
-/**
-  Add HOB into HOB list
- 

[edk2-devel] [PATCH v1 5/6] UefiPayloadPkg: Add FDT Paser relative LIBs.

2024-05-23 Thread Linus Liu
Add FDTParser and CustomFdtNodePaser
to retrive all FDT node and create the relate hobs.

Cc: Benny Lin 
Cc: Gua Guo 
Cc: Chasel Chiu 
Cc: James Lu 
Cc: Dhaval Sharma 

Signed-off-by: Linus Liu 
---
 UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.c 
  | 158 +
 UefiPayloadPkg/Library/CustomFdtNodeParserNullLib/CustomFdtNodeParserNullLib.c 
  |  51 ++
 UefiPayloadPkg/Library/FdtParserLib/FdtParserLib.c 
  | 622 
 UefiPayloadPkg/Library/HobParseLib/HobParseLib.c   
  | 408 +
 UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.inf   
  |  46 ++
 
UefiPayloadPkg/Library/CustomFdtNodeParserNullLib/CustomFdtNodeParserNullLib.inf
 |  33 ++
 UefiPayloadPkg/Library/FdtParserLib/FdtParseLib.inf
  |  63 ++
 UefiPayloadPkg/Library/HobParseLib/HobParseLib.inf 
  |  40 ++
 8 files changed, 1421 insertions(+)

diff --git 
a/UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.c 
b/UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.c
new file mode 100644
index ..d1376d21c5dd
--- /dev/null
+++ b/UefiPayloadPkg/Library/CustomFdtNodeParserLib/CustomFdtNodeParserLib.c
@@ -0,0 +1,158 @@
+/** @file
+  Copyright (c) 2024, Intel Corporation. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+  Add a new HOB to the HOB List.
+
+  @param HobTypeType of the new HOB.
+  @param HobLength  Length of the new HOB to allocate.
+
+  @return  NULL if there is no space to create a hob.
+  @return  The address point to the new created hob.
+
+**/
+VOID *
+EFIAPI
+CreateHob (
+  IN  UINT16  HobType,
+  IN  UINT16  HobLength
+  );
+
+/**
+  Add HOB into HOB list
+  @param[in]  HobThe HOB to be added into the HOB list.
+**/
+VOID
+AddNewHob (
+  IN EFI_PEI_HOB_POINTERS  *Hob
+  );
+
+/**
+  Check the HOB and decide if it is need inside Payload
+  Payload maintainer may make decision which HOB is need or needn't
+  Then add the check logic in the function.
+  @param[in] Hob The HOB to check
+  @retval TRUE  If HOB is need inside Payload
+  @retval FALSE If HOB is needn't inside Payload
+**/
+BOOLEAN
+EFIAPI
+FitIsHobNeed (
+  EFI_PEI_HOB_POINTERS  Hob
+  )
+{
+  if (FixedPcdGetBool (PcdHandOffFdtEnable)) {
+if (Hob.Header->HobType == EFI_HOB_TYPE_HANDOFF) {
+  return FALSE;
+}
+
+if (Hob.Header->HobType == EFI_HOB_TYPE_MEMORY_ALLOCATION) {
+  if (CompareGuid (>AllocDescriptor.Name, 
)) {
+return FALSE;
+  }
+
+  if (CompareGuid 
(>MemoryAllocationHeader.Name, 
)) {
+return FALSE;
+  }
+
+  if ((Hob.MemoryAllocation->AllocDescriptor.MemoryType == 
EfiReservedMemoryType) ||
+  (Hob.MemoryAllocation->AllocDescriptor.MemoryType == 
EfiBootServicesCode) ||
+  (Hob.MemoryAllocation->AllocDescriptor.MemoryType == 
EfiBootServicesData) ||
+  (Hob.MemoryAllocation->AllocDescriptor.MemoryType == 
EfiRuntimeServicesCode) ||
+  (Hob.MemoryAllocation->AllocDescriptor.MemoryType == 
EfiRuntimeServicesData) ||
+  (Hob.MemoryAllocation->AllocDescriptor.MemoryType == 
EfiACPIReclaimMemory) ||
+  (Hob.MemoryAllocation->AllocDescriptor.MemoryType == 
EfiACPIMemoryNVS))
+  {
+return FALSE;
+  }
+}
+
+if (Hob.Header->HobType == EFI_HOB_TYPE_GUID_EXTENSION) {
+  if (CompareGuid (>Name, )) 
{
+return FALSE;
+  }
+
+  if (CompareGuid (>Name, )) {
+return FALSE;
+  }
+
+  if (CompareGuid (>Name, 
)) {
+return FALSE;
+  }
+}
+  }
+
+  // Arrive here mean the HOB is need
+  return TRUE;
+}
+
+/**
+  It will Parse FDT -custom node based on information from bootloaders.
+  @param[in]  FdtBase The starting memory address of FdtBase
+  @param[in]  HobList The starting memory address of New Hob list.
+
+**/
+UINTN
+EFIAPI
+CustomFdtNodeParser (
+  IN VOID  *FdtBase,
+  IN VOID  *HobList
+  )
+{
+  INT32 Node, CustomNode;
+  INT32 TempLen;
+  UINT64*Data64;
+  UINTN CHobList;
+  CONST FDT_PROPERTY*PropertyPtr;
+  EFI_PEI_HOB_POINTERS  Hob;
+
+  CHobList = (UINTN)HobList;
+
+  DEBUG ((DEBUG_INFO, "%a() #1 \n", __func__));
+
+  //
+  // Look for if exists hob list node
+  //
+  Node = FdtSubnodeOffsetNameLen (FdtBase, 0, "options", (INT32)AsciiStrLen 
("options"));
+  if (Node > 0) {
+DEBUG ((DEBUG_INFO, "  Found options node (%08X)", Node));
+CustomNode = FdtSubnodeOffsetNameLen (FdtBase, Node, "upl-custom", 
(INT32)AsciiStrLen ("upl-custom"));
+if (CustomNode > 0) {
+  DEBUG ((DEBUG_INFO, "  Found upl-custom node (%08X)", CustomNode));
+  PropertyPtr = FdtGetProperty (FdtBase, CustomNode, "hoblistptr", 
);

[edk2-devel] [PATCH v1 4/6] UefiPayloadPkg: Update PayloadLoader to suport FDT.

2024-05-23 Thread Linus Liu
Create FDT nodes (reserved-memory, serial, pci-rb, options) in
FdtPpiNotifyCallback function right after gEfiEndOfPeiSignalPpiGuid.

Cc: Benny Lin 
Cc: Gua Guo 
Cc: Chasel Chiu 
Cc: James Lu 
Cc: Dhaval Sharma 

Signed-off-by: Linus Liu 
---
 UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.c   | 1004 
+++-
 UefiPayloadPkg/PayloadLoaderPeim/PayloadLoaderPeim.c  |   71 +-
 UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.inf |   16 +-
 UefiPayloadPkg/PayloadLoaderPeim/PayloadLoaderPeim.inf|   12 +
 4 files changed, 1077 insertions(+), 26 deletions(-)

diff --git a/UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.c 
b/UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.c
index de33d49bd1c6..00016c7756c5 100644
--- a/UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.c
+++ b/UefiPayloadPkg/PayloadLoaderPeim/FitPayloadLoaderPeim.c
@@ -6,18 +6,74 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 
 #include 
 #include 
+#include 
 #include 
+#include 
 #include 
-
+#include 
 #include 
 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
-
+#include 
+#include 
+#include 
 #include "FitLib.h"
+#define STACK_SIZE  0x2
+#define N_NON_RELOCATABLE   BIT31
+#define P_NON_PREFETCHABLE  BIT30
+#define SS_CONFIGURATION_SPACE  0
+#define SS_IO_SPACE BIT24
+#define SS_32BIT_MEMORY_SPACE   BIT25
+#define SS_64BIT_MEMORY_SPACE   BIT24+BIT25
+
+CONST EFI_PEI_PPI_DESCRIPTOR  gReadyToPayloadSignalPpi = {
+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
+  ,
+  NULL
+};
+
+EFI_PEI_PPI_DESCRIPTOR  mEndOfPeiSignalPpi = {
+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
+  ,
+  NULL
+};
+
+#define MEMORY_ATTRIBUTE_DEFAULT  (EFI_RESOURCE_ATTRIBUTE_PRESENT  
 | \
+ EFI_RESOURCE_ATTRIBUTE_INITIALIZED
 | \
+ EFI_RESOURCE_ATTRIBUTE_TESTED 
 | \
+ EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
 | \
+ EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE  
 | \
+ 
EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE | \
+ 
EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE)
+
+CHAR8  *mMemoryAllocType[] = {
+  "Reserved",
+  "LoaderCode",
+  "LoaderData",
+  "boot-code",
+  "boot-data",
+  "runtime-code",
+  "runtime-data",
+  "ConventionalMemory",
+  "UnusableMemory",
+  "acpi",
+  "acpi-nvs",
+  "mmio",
+  "MemoryMappedIOPortSpace",
+  "PalCode",
+  "PersistentMemory",
+};
 
 /**
   The wrapper function of PeiLoadImageLoadImage().
@@ -50,6 +106,15 @@ PeiLoadFileLoadPayload (
   UINTN   Delta;
   UINTN   Index;
 
+ #if (FixedPcdGetBool (PcdHandOffFdtEnable))
+  VOID   *BaseOfStack;
+  VOID   *TopOfStack;
+  UNIVERSAL_PAYLOAD_DEVICE_TREE  *Fdt;
+  VOID   *Hob;
+
+  Fdt = NULL;
+ #endif
+
   Instance = 0;
   do {
 Status = PeiServicesFfsFindSectionData3 (EFI_SECTION_RAW, Instance++, 
FileHandle, , AuthenticationState);
@@ -66,13 +131,15 @@ PeiLoadFileLoadPayload (
 return Status;
   }
 
-  DEBUG ((
-DEBUG_INFO,
-"Before Rebase Payload File Base: 0x%08x, File Size: 0x%08X, EntryPoint: 
0x%08x\n",
-Context.PayloadBaseAddress,
-Context.PayloadSize,
-Context.PayloadEntryPoint
-));
+  DEBUG (
+(
+ DEBUG_INFO,
+ "Before Rebase Payload File Base: 0x%08x, File Size: 0x%08X, EntryPoint: 
0x%08x\n",
+ Context.PayloadBaseAddress,
+ Context.PayloadSize,
+ Context.PayloadEntryPoint
+)
+);
   Context.PayloadBaseAddress = (EFI_PHYSICAL_ADDRESS)AllocatePages 
(EFI_SIZE_TO_PAGES (Context.PayloadSize));
 
   RelocateTable = (FIT_RELOCATE_ITEM *)(UINTN)(Context.PayloadBaseAddress + 
Context.RelocateTableOffset);
@@ -96,13 +163,15 @@ PeiLoadFileLoadPayload (
 }
   }
 
-  DEBUG ((
-DEBUG_INFO,
-"After Rebase Payload File Base: 0x%08x, File Size: 0x%08X, EntryPoint: 
0x%08x\n",
-Context.PayloadBaseAddress,
-Context.PayloadSize,
-Context.PayloadEntryPoint
-));
+  DEBUG (
+(
+ DEBUG_INFO,
+ "After Rebase Payload File Base: 0x%08x, File Size: 0x%08X, EntryPoint: 
0x%08x\n",
+ Context.PayloadBaseAddress,
+ Context.PayloadSize,
+ Context.PayloadEntryPoint
+)
+);
 
   Length  = sizeof (UNIVERSAL_PAYLOAD_BASE);
   PayloadBase = BuildGuidHob (
@@ -115,6 +184,42 @@ PeiLoadFileLoadPayload (
   *ImageSizeArg= Context.PayloadSize;
   *EntryPoint  = Context.PayloadEntryPoint;
 
+  Status = PeiServicesInstallPpi ();
+  ASSERT_EFI_ERROR (Status);
+
+  Status = PeiServicesInstallPpi ();
+  ASSERT_EFI_ERROR (Status);
+
+ #if (FixedPcdGetBool (PcdHandOffFdtEnable))
+  Hob = GetFirstGuidHob ();
+  if 

[edk2-devel] [PATCH v1 3/6] UefiPayloadPkg: Support Debug function when Hob was not avalible.

2024-05-23 Thread Linus Liu
Initialize mUartInfo with PCD for debug message
when Hob was not avalible.

Cc: Benny Lin 
Cc: Gua Guo 
Cc: Chasel Chiu 
Cc: James Lu 
Cc: Dhaval Sharma 

Signed-off-by: Linus Liu 
---
 UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c 
| 69 
 UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c 
|  5 ++
 UefiPayloadPkg/Library/PayloadEntryHobLib/Hob.c
|  7 +-
 UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.c   
|  4 ++
 UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.inf   
| 10 +++
 UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.inf
| 13 ++--
 UefiPayloadPkg/Library/PayloadEntryHobLib/HobLib.inf   
|  1 +
 7 files changed, 104 insertions(+), 5 deletions(-)

diff --git a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c 
b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c
index 82d0dd585508..55e85dce8598 100644
--- a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c
+++ b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c
@@ -143,6 +143,75 @@ SerialPortInitialize (
 return RETURN_SUCCESS;
   }
 
+  if (GetHobList () == NULL) {
+mUartCount = 0;
+SerialRegisterBase = PcdGet64 (PcdSerialRegisterBase);
+MmioEnable = PcdGetBool (PcdSerialUseMmio);
+BaudRate   = PcdGet32 (PcdSerialBaudRate);
+RegisterStride = (UINT8)PcdGet32 (PcdSerialRegisterStride);
+
+mUartInfo[mUartCount].BaseAddress= SerialRegisterBase;
+mUartInfo[mUartCount].UseMmio= MmioEnable;
+mUartInfo[mUartCount].BaudRate   = BaudRate;
+mUartInfo[mUartCount].RegisterStride = RegisterStride;
+mUartCount++;
+
+Divisor = PcdGet32 (PcdSerialClockRate) / (BaudRate * 16);
+if ((PcdGet32 (PcdSerialClockRate) % (BaudRate * 16)) >= BaudRate * 8) {
+  Divisor++;
+}
+
+//
+// See if the serial port is already initialized
+//
+Initialized = TRUE;
+if ((SerialPortReadRegister (SerialRegisterBase, R_UART_LCR, MmioEnable, 
RegisterStride) & 0x3F) != (PcdGet8 (PcdSerialLineControl) & 0x3F)) {
+  Initialized = FALSE;
+}
+
+Value = (UINT8)(SerialPortReadRegister (SerialRegisterBase, R_UART_LCR, 
MmioEnable, RegisterStride) | B_UART_LCR_DLAB);
+SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, Value, 
MmioEnable, RegisterStride);
+CurrentDivisor  =  SerialPortReadRegister (SerialRegisterBase, 
R_UART_BAUD_HIGH, MmioEnable, RegisterStride) << 8;
+CurrentDivisor |= (UINT32)SerialPortReadRegister (SerialRegisterBase, 
R_UART_BAUD_LOW, MmioEnable, RegisterStride);
+Value   = (UINT8)(SerialPortReadRegister (SerialRegisterBase, 
R_UART_LCR, MmioEnable, RegisterStride) & ~B_UART_LCR_DLAB);
+SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, Value, 
MmioEnable, RegisterStride);
+if (CurrentDivisor != Divisor) {
+  Initialized = FALSE;
+}
+
+//
+// Configure baud rate
+//
+SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, B_UART_LCR_DLAB, 
MmioEnable, RegisterStride);
+SerialPortWriteRegister (SerialRegisterBase, R_UART_BAUD_HIGH, 
(UINT8)(Divisor >> 8), MmioEnable, RegisterStride);
+SerialPortWriteRegister (SerialRegisterBase, R_UART_BAUD_LOW, 
(UINT8)(Divisor & 0xff), MmioEnable, RegisterStride);
+
+//
+// Clear DLAB and configure Data Bits, Parity, and Stop Bits.
+// Strip reserved bits from PcdSerialLineControl
+//
+SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, (UINT8)(PcdGet8 
(PcdSerialLineControl) & 0x3F), MmioEnable, RegisterStride);
+
+//
+// Enable and reset FIFOs
+// Strip reserved bits from PcdSerialFifoControl
+//
+SerialPortWriteRegister (SerialRegisterBase, R_UART_FCR, 0x00, MmioEnable, 
RegisterStride);
+SerialPortWriteRegister (SerialRegisterBase, R_UART_FCR, (UINT8)(PcdGet8 
(PcdSerialFifoControl) & (B_UART_FCR_FIFOE | B_UART_FCR_FIFO64)), MmioEnable, 
RegisterStride);
+
+//
+// Set FIFO Polled Mode by clearing IER after setting FCR
+//
+SerialPortWriteRegister (SerialRegisterBase, R_UART_IER, 0x00, MmioEnable, 
RegisterStride);
+
+//
+// Put Modem Control Register(MCR) into its reset state of 0x00.
+//
+SerialPortWriteRegister (SerialRegisterBase, R_UART_MCR, 0x00, MmioEnable, 
RegisterStride);
+
+return RETURN_SUCCESS;
+  }
+
   GuidHob = GetFirstGuidHob ();
   while (GuidHob != NULL) {
 SerialPortInfo = (UNIVERSAL_PAYLOAD_SERIAL_PORT_INFO 
*)GET_GUID_HOB_DATA (GuidHob);
diff --git 
a/UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c
 
b/UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c
index 10bdbe2bbc1f..e9cce86bb853 100644
--- 
a/UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c

[edk2-devel] [PATCH v1 2/6] UefiPayloadPkg: Addd header files for FDT structure and function.

2024-05-23 Thread Linus Liu
Add Library header, DeviceTree hob header and PCD definitions.

Cc: Benny Lin 
Cc: Gua Guo 
Cc: Chasel Chiu 
Cc: James Lu 
Cc: Dhaval Sharma 

Signed-off-by: Linus Liu 
---
 UefiPayloadPkg/Include/Guid/UniversalPayloadBase.h   |  2 +
 UefiPayloadPkg/Include/Library/FdtParserLib.h| 64 
 UefiPayloadPkg/Include/UniversalPayload/DeviceTree.h | 30 +
 UefiPayloadPkg/UefiPayloadPkg.dec| 22 +++
 4 files changed, 118 insertions(+)

diff --git a/UefiPayloadPkg/Include/Guid/UniversalPayloadBase.h 
b/UefiPayloadPkg/Include/Guid/UniversalPayloadBase.h
index 60f2aa37dd3e..a2d4d491bdfb 100644
--- a/UefiPayloadPkg/Include/Guid/UniversalPayloadBase.h
+++ b/UefiPayloadPkg/Include/Guid/UniversalPayloadBase.h
@@ -16,4 +16,6 @@ typedef struct {
   EFI_PHYSICAL_ADDRESSEntry;
 } UNIVERSAL_PAYLOAD_BASE;
 
+#define UNIVERSAL_PAYLOAD_BASE_REVISION  1
+
 #endif // UNIVERSAL_PAYLOAD_BASE_H_
diff --git a/UefiPayloadPkg/Include/Library/FdtParserLib.h 
b/UefiPayloadPkg/Include/Library/FdtParserLib.h
new file mode 100644
index ..87109f1190bd
--- /dev/null
+++ b/UefiPayloadPkg/Include/Library/FdtParserLib.h
@@ -0,0 +1,64 @@
+/** @file
+  This library will parse the FDT (flat device tree) table information.
+
+  Copyright (c) 2024, Intel Corporation. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef FDT_PARSER_LIB_H_
+#define FDT_PARSER_LIB_H_
+
+/**
+  It will parse FDT based on DTB.
+
+  @param[in]  FdtBase   Address of the Fdt data.
+
+  @retval EFI_SUCCESS   If it completed successfully.
+  @retval OthersIf it failed to parse DTB.
+**/
+UINTN
+EFIAPI
+ParseDtb (
+  IN VOID  *FdtBase
+  );
+
+/**
+  It will Parse FDT -node based on information.
+  @param[in]  FdtBase   The starting memory address of FdtBase
+  @retval HobList   The base address of Hoblist.
+
+**/
+UINT64
+EFIAPI
+FdtNodeParser (
+  IN VOID  *FdtBase
+  );
+
+/**
+  It will Parse FDT -custom node based on information.
+  @param[in]  FdtBase The starting memory address of FdtBase
+  @param[in]  HostList The starting memory address of New Hob list.
+
+**/
+UINTN
+EFIAPI
+CustomFdtNodeParser (
+  IN VOID  *FdtBase,
+  IN VOID  *HostList
+  );
+
+/**
+  It will initialize HOBs for UPL.
+
+  @param[in]  FdtBaseAddress of the Fdt data.
+
+  @retval EFI_SUCCESSIf it completed successfully.
+  @retval Others If it failed to initialize HOBs.
+**/
+UINTN
+EFIAPI
+UplInitHob (
+  IN VOID  *FdtBase
+  );
+
+#endif
diff --git a/UefiPayloadPkg/Include/UniversalPayload/DeviceTree.h 
b/UefiPayloadPkg/Include/UniversalPayload/DeviceTree.h
new file mode 100644
index ..b7c2163e1e0d
--- /dev/null
+++ b/UefiPayloadPkg/Include/UniversalPayload/DeviceTree.h
@@ -0,0 +1,30 @@
+/** @file
+  This file defines the structure for the PCI Root Bridges.
+
+  Copyright (c) 2024, Intel Corporation. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Revision Reference:
+- Universal Payload Specification 0.8 
(https://universalpayload.github.io/spec/)
+**/
+
+#ifndef UNIVERSAL_PAYLOAD_DEVICE_TREE_H_
+#define UNIVERSAL_PAYLOAD_DEVICE_TREE_H_
+
+#include 
+#include 
+
+#pragma pack (1)
+
+typedef struct {
+  UNIVERSAL_PAYLOAD_GENERIC_HEADERHeader;
+  EFI_PHYSICAL_ADDRESSDeviceTreeAddress;
+} UNIVERSAL_PAYLOAD_DEVICE_TREE;
+
+#pragma pack()
+
+#define UNIVERSAL_PAYLOAD_DEVICE_TREE_REVISION  1
+
+extern GUID  gUniversalPayloadDeviceTreeGuid;
+
+#endif // UNIVERSAL_PAYLOAD_SMBIOS_TABLE_H_
diff --git a/UefiPayloadPkg/UefiPayloadPkg.dec 
b/UefiPayloadPkg/UefiPayloadPkg.dec
index 23dcdf9a0c9c..ca11a083ecdb 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.dec
+++ b/UefiPayloadPkg/UefiPayloadPkg.dec
@@ -27,6 +27,8 @@
   ## Include/Guid/UniversalPayloadBase.h
   gUniversalPayloadBaseGuid = { 0x03d4c61d, 0x2713, 0x4ec5, {0xa1, 0xcc, 0x88, 
0x3b, 0xe9, 0xdc, 0x18, 0xe5 } }
 
+  ## Include/UniversalPayload/DeviceTree.h
+  gUniversalPayloadDeviceTreeGuid = { 0x6784b889, 0xb13c, 0x4c3b, {0xae, 0x4b, 
0xf, 0xa, 0x2e, 0x32, 0xe, 0xa3 } }
   gEdkiiDebugPrintErrorLevelGuid = { 0xad82f436, 0x75c5, 0x4aa9, { 0x92, 0x93, 
0xc5, 0x55, 0x0a, 0x7f, 0xf9, 0x71 }}
   gUefiAcpiBoardInfoGuid   = {0xad3d31b, 0xb3d8, 0x4506, {0xae, 0x71, 0x2e, 
0xf1, 0x10, 0x6, 0xd9, 0xf}}
   gUefiSerialPortInfoGuid  = { 0x6c6872fe, 0x56a9, 0x4403, { 0xbb, 0x98, 0x95, 
0x8d, 0x62, 0xde, 0x87, 0xf1 } }
@@ -42,6 +44,13 @@
 [Ppis]
   gEfiPayLoadHobBasePpiGuid = { 0xdbe23aa1, 0xa342, 0x4b97, {0x85, 0xb6, 0xb2, 
0x26, 0xf1, 0x61, 0x73, 0x89} }
 
+  #
+  # This PPI is used to trigger Payload callback event in end of PEI.
+  #
+  gUplReadyToPayloadPpiGuid = { 0x67c8dfb1, 0x61f4, 0x439c, { 0x84, 0x4e, 
0x2b, 0xdf, 0xf1, 0x07, 0xad, 0x51 }}
+
+[Protocols]
+
 

 #
 # PCD Declarations section - list of all PCDs Declared by this Package

[edk2-devel] [PATCH v1 1/6] MdePkg: Fix build error after enable FDT support.

2024-05-23 Thread Linus Liu
Disable some compiling warnings caused by submodule code.
Those can be removed later once issues fixed by submodule owner.

Cc: Benny Lin 
Cc: Gua Guo 
Cc: Chasel Chiu 
Cc: James Lu 
Cc: Dhaval Sharma 
Signed-off-by: Linus Liu 
---
 MdePkg/Library/BaseFdtLib/BaseFdtLib.inf | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf 
b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
index 730e568ff605..b5815380c5ee 100644
--- a/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
+++ b/MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
@@ -57,6 +57,9 @@
   BaseMemoryLib
 
 [BuildOptions]
-  MSFT:*_*_IA32_CC_FLAGS = /wd4146 /wd4245
-  MSFT:*_*_X64_CC_FLAGS  = /wd4146 /wd4244 /wd4245 /wd4267
+# warning C4706: assignment within conditional expression
+# if ((err = fdt_splice_(fdt, p, oldlen, newlen)))
+# in BaseFdtLib\libfdt\libfdt\fdt_rw.c (wait for sub module update to remove 
this)
+  MSFT:*_*_IA32_CC_FLAGS = /wd4146 /wd4245 /wd4706
+  MSFT:*_*_X64_CC_FLAGS  = /wd4146 /wd4244 /wd4245 /wd4267 /wd4706
 
-- 
2.39.2.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119172): https://edk2.groups.io/g/devel/message/119172
Mute This Topic: https://groups.io/mt/106274745/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [edk2-platforms][PATCH 3/3] edk2-platform/Maintainer: Add entries for AMD packages

2024-05-23 Thread Abdul Lateef Attar via groups.io

Reviewed-by: Abdul Lateef Attar 

On 23-05-2024 21:57, Michael D Kinney via groups.io wrote:

Caution: This message originated from an External Source. Use proper caution 
when opening attachments, clicking links, or responding.


Reviewed-by: Michael D Kinney


-Original Message-
From:abner.ch...@amd.com  
Sent: Wednesday, May 22, 2024 9:12 PM
To:devel@edk2.groups.io
Cc: Leif Lindholm; Kinney, Michael D

Subject: [edk2-platforms][PATCH 3/3] edk2-platform/Maintainer: Add entries
for AMD packages

From: Abner Chang

Signed-off-by: Abner Chang
Cc: Leif Lindholm
Cc: Michael D Kinney
---
  Maintainers.txt | 14 +-
  1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/Maintainers.txt b/Maintainers.txt
index 877620a1b0..af688c3813 100644
--- a/Maintainers.txt
+++ b/Maintainers.txt
@@ -86,8 +86,20 @@ M: Leif Lindholm
  AMD
  F: Platform/AMD
  M: Abner Chang
-M: Abdul Lateef Attar
+M: Abdul Lateef Attar
+M: Paul Grimes
+
+F: Platform/AMD/AgesaModulePkg
+F: Platform/AMD/AgesaPkg
+F: Platform/AMD/AmdCbsPkg
+M: Paul Grimes
+R: Abdul Lateef Attar
+R: Abner Chang
+
+F: Platform/AMD/AmdCpmPkg
+M: Abdul Lateef Attar
  R: Paul Grimes
+R: Abner Chang

  AMD Seattle
  F: Platform/AMD/OverdriveBoard/
--
2.37.1.windows.1









-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119171): https://edk2.groups.io/g/devel/message/119171
Mute This Topic: https://groups.io/mt/106257081/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH] Pkg-Module:UefiCpuPkg/MpLib

2024-05-23 Thread Ning Feng
hi, ray looks like after only changed the title, there created another groups, 
please check below link. thanks
[PATCH] Pkg-Module:UefiCpuPkg/MpLib:Do not assume BSP is #0 (groups.io) ( 
https://edk2.groups.io/g/devel/message/119161 )


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119170): https://edk2.groups.io/g/devel/message/119170
Mute This Topic: https://groups.io/mt/106256300/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




回复: [edk2-devel] [PATCH v2 09/13] NetworkPkg: TcpDxe: SECURITY PATCH CVE-2023-45236

2024-05-23 Thread gaoliming via groups.io
Saloni:

  Have you any other comments for this patch?

 

Thanks

Liming

发件人: devel@edk2.groups.io  代表 Doug Flick via groups.io
发送时间: 2024年5月22日 3:29
收件人: Saloni Kasbekar ; devel@edk2.groups.io
主题: Re: [edk2-devel] [PATCH v2 09/13] NetworkPkg: TcpDxe: SECURITY PATCH 
CVE-2023-45236

 

This was more of a design decision. Both Hash2Protocol and HashLib serve 
similar purposes. The goal was to use Hash2Protocol to decouple and provide 
greater modularity and flexibility over HashLib.





-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119169): https://edk2.groups.io/g/devel/message/119169
Mute This Topic: https://groups.io/mt/106274103/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v3 1/1] MdeModulePkg: Add the EFI_RESOURCE_ATTRIBUTE_SPECIAL_PURPOSE attribute

2024-05-23 Thread Oliver Smith-Denny

On 5/23/2024 2:17 AM, Du Lin wrote:

Thanks for the quick response.

Agree that the PI and UEFI specs are vague on SP. That is also why I opted to 
minimize code changes to DXE core for SP support in patch 
https://edk2.groups.io/g/devel/message/118712.

Would it make more sense to let the caller determine if SP memory is available 
for UEFI via EFI resource types (e.g., EFI_RESOURCE_SYSTEM_MEMORY vs 
EFI_RESOURCE_MEMORY_RESERVED)?

CDAT can be read in PEI phase via DOE method and CDAT is important to support CXL 2.0. I 
believe CDAT spec is referencing EFI_MEMORY_TYPE and Memory Attributes defined in UEFI 
spec section 7.2. "EfiConventionalMemory Type with EFI_MEMORY_SP Attribute" may 
suggest that the memory type shall be EfiConventionalMemory and the attribute shall have 
SP set when reporting the memory to OS. And the concern is whether this combination can 
still be supported if we always mark resource HOBs with SP set as 
EfiGcdMemoryTypeReserved.


Thanks for the clarification. I agree that it makes sense to let the
resource HOB creator determine whether UEFI will put this in
system memory or reserved memory. DxeCore at that point could decide
to not allocate any memory with the EFI_MEMORY_SP attribute (or it
could decide it doesn't care).

We are meeting with some CXL stakeholders to make sure there is no
concern with changing this patch and then we will respin this.

Thanks,
Oliver


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119168): https://edk2.groups.io/g/devel/message/119168
Mute This Topic: https://groups.io/mt/106165072/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] PR Process Wiki Updates

2024-05-23 Thread Michael D Kinney
Hi Michael,

These updates look good.

Can you provide a brief overview/summary of the process changes 
in email to make sure there are no misunderstandings from the
details in the wiki page updates.

Thanks,

Mike

> -Original Message-
> From: Michael Kubacki 
> Sent: Monday, May 20, 2024 6:32 PM
> To: devel@edk2.groups.io; r...@edk2.groups.io
> Cc: Kinney, Michael D ;
> quic_llind...@quicinc.com; af...@apple.com
> Subject: PR Process Wiki Updates
> 
> In preparation for the transition to a pull request (PR) contribution
> process, I've updated the TianoCore wiki.
> 
> - Current official TianoCore wiki:
> https://github.com/tianocore/tianocore.github.io/wiki/
> 
> - My fork with proposed changes:
> https://github.com/makubacki/tianocore.github.io/wiki
> 
> - A PR that shows a diff of the changes:
> https://github.com/makubacki/tianocore.github.io/pull/2
> 
> This was presented in the TianoCore Tools & CI meeting today. I captured
> feedback from the meeting as PR comments. The actionable items currently
> there will be completed by Thursday, 5/23 this week.
> 
> Please feel free to let me know if you have any feedback.
> 
> Thanks,
> Michael


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119167): https://edk2.groups.io/g/devel/message/119167
Mute This Topic: https://groups.io/mt/106216419/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [edk2-platforms][PATCH 3/3] edk2-platform/Maintainer: Add entries for AMD packages

2024-05-23 Thread Michael D Kinney
Reviewed-by: Michael D Kinney 

> -Original Message-
> From: abner.ch...@amd.com 
> Sent: Wednesday, May 22, 2024 9:12 PM
> To: devel@edk2.groups.io
> Cc: Leif Lindholm ; Kinney, Michael D
> 
> Subject: [edk2-platforms][PATCH 3/3] edk2-platform/Maintainer: Add entries
> for AMD packages
> 
> From: Abner Chang 
> 
> Signed-off-by: Abner Chang 
> Cc: Leif Lindholm 
> Cc: Michael D Kinney 
> ---
>  Maintainers.txt | 14 +-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/Maintainers.txt b/Maintainers.txt
> index 877620a1b0..af688c3813 100644
> --- a/Maintainers.txt
> +++ b/Maintainers.txt
> @@ -86,8 +86,20 @@ M: Leif Lindholm 
>  AMD
>  F: Platform/AMD
>  M: Abner Chang 
> -M: Abdul Lateef Attar 
> +M: Abdul Lateef Attar 
> +M: Paul Grimes 
> +
> +F: Platform/AMD/AgesaModulePkg
> +F: Platform/AMD/AgesaPkg
> +F: Platform/AMD/AmdCbsPkg
> +M: Paul Grimes 
> +R: Abdul Lateef Attar 
> +R: Abner Chang 
> +
> +F: Platform/AMD/AmdCpmPkg
> +M: Abdul Lateef Attar 
>  R: Paul Grimes 
> +R: Abner Chang 
> 
>  AMD Seattle
>  F: Platform/AMD/OverdriveBoard/
> --
> 2.37.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119166): https://edk2.groups.io/g/devel/message/119166
Mute This Topic: https://groups.io/mt/106257081/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [edk2-platforms][PATCH V3 01/17] Platform/ARM/NorFlashDxe: Move DiskIo related functions out of NorFlash.c

2024-05-23 Thread Sami Mujawar
Hi Sahil,

I cannot apply your patches cleanly. Can you share a github branch with your 
patches, please?

Regards,

Sami Mujawar

On 23/05/2024, 11:56, "Sahil Kaushal" mailto:sahil.kaus...@arm.com>> wrote:


From: sahil mailto:sa...@arm.com>>


Moving these functions from NorFlash.c to NorFlashBlockIoDxe.c as
they are not dependent on any particular flash implementation.


Signed-off-by: sahil mailto:sa...@arm.com>>
---
Platform/ARM/Drivers/NorFlashDxe/NorFlash.c | 129 
Platform/ARM/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c | 129 
2 files changed, 129 insertions(+), 129 deletions(-)


diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c
index 1b431073ee93..60854ef2a7d0 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c
@@ -807,135 +807,6 @@ NorFlashWriteSingleBlock (
return EFI_SUCCESS;


}






-/*


- Although DiskIoDxe will automatically install the DiskIO protocol whenever


- we install the BlockIO protocol, its implementation is sub-optimal as it reads


- and writes entire blocks using the BlockIO protocol. In fact we can access


- NOR flash with a finer granularity than that, so we can improve performance


- by directly producing the DiskIO protocol.


-*/


-


-/**


- Read BufferSize bytes from Offset into Buffer.


-


- @param This Protocol instance pointer.


- @param MediaId Id of the media, changes every time the media is replaced.


- @param Offset The starting byte offset to read from


- @param BufferSize Size of Buffer


- @param Buffer Buffer containing read data


-


- @retval EFI_SUCCESS The data was read correctly from the device.


- @retval EFI_DEVICE_ERROR The device reported an error while performing the 
read.


- @retval EFI_NO_MEDIA There is no media in the device.


- @retval EFI_MEDIA_CHANGED The MediaId does not match the current device.


- @retval EFI_INVALID_PARAMETER The read request contains device addresses that 
are not


- valid for the device.


-


-**/


-EFI_STATUS


-EFIAPI


-NorFlashDiskIoReadDisk (


- IN EFI_DISK_IO_PROTOCOL *This,


- IN UINT32 MediaId,


- IN UINT64 DiskOffset,


- IN UINTN BufferSize,


- OUT VOID *Buffer


- )


-{


- NOR_FLASH_INSTANCE *Instance;


- UINT32 BlockSize;


- UINT32 BlockOffset;


- EFI_LBA Lba;


-


- Instance = INSTANCE_FROM_DISKIO_THIS (This);


-


- if (MediaId != Instance->Media.MediaId) {


- return EFI_MEDIA_CHANGED;


- }


-


- BlockSize = Instance->Media.BlockSize;


- Lba = (EFI_LBA)DivU64x32Remainder (DiskOffset, BlockSize, );


-


- return NorFlashRead (Instance, Lba, BlockOffset, BufferSize, Buffer);


-}


-


-/**


- Writes a specified number of bytes to a device.


-


- @param This Indicates a pointer to the calling context.


- @param MediaId ID of the medium to be written.


- @param Offset The starting byte offset on the logical block I/O device to 
write.


- @param BufferSize The size in bytes of Buffer. The number of bytes to write 
to the device.


- @param Buffer A pointer to the buffer containing the data to be written.


-


- @retval EFI_SUCCESS The data was written correctly to the device.


- @retval EFI_WRITE_PROTECTED The device can not be written to.


- @retval EFI_DEVICE_ERROR The device reported an error while performing the 
write.


- @retval EFI_NO_MEDIA There is no media in the device.


- @retval EFI_MEDIA_CHANGED The MediaId does not match the current device.


- @retval EFI_INVALID_PARAMETER The write request contains device addresses 
that are not


- valid for the device.


-


-**/


-EFI_STATUS


-EFIAPI


-NorFlashDiskIoWriteDisk (


- IN EFI_DISK_IO_PROTOCOL *This,


- IN UINT32 MediaId,


- IN UINT64 DiskOffset,


- IN UINTN BufferSize,


- IN VOID *Buffer


- )


-{


- NOR_FLASH_INSTANCE *Instance;


- UINT32 BlockSize;


- UINT32 BlockOffset;


- EFI_LBA Lba;


- UINTN RemainingBytes;


- UINTN WriteSize;


- EFI_STATUS Status;


-


- Instance = INSTANCE_FROM_DISKIO_THIS (This);


-


- if (MediaId != Instance->Media.MediaId) {


- return EFI_MEDIA_CHANGED;


- }


-


- BlockSize = Instance->Media.BlockSize;


- Lba = (EFI_LBA)DivU64x32Remainder (DiskOffset, BlockSize, );


-


- RemainingBytes = BufferSize;


-


- // Write either all the remaining bytes, or the number of bytes that bring


- // us up to a block boundary, whichever is less.


- // (DiskOffset | (BlockSize - 1)) + 1) rounds DiskOffset up to the next


- // block boundary (even if it is already on one).


- WriteSize = MIN (RemainingBytes, ((DiskOffset | (BlockSize - 1)) + 1) - 
DiskOffset);


-


- do {


- if (WriteSize == BlockSize) {


- // Write a full block


- Status = NorFlashWriteFullBlock (Instance, Lba, Buffer, BlockSize / sizeof 
(UINT32));


- } else {


- // Write a partial block


- Status = NorFlashWriteSingleBlock (Instance, Lba, BlockOffset, , 
Buffer);


- }


-


- if (EFI_ERROR (Status)) {


- return Status;


- }


-


- // 

Re: [edk2-devel] [edk2-platforms][PATCH V3 11/17] Platform/ARM/NorFlashDxe: Fix memory leak in NorFlashCreateInstance()

2024-05-23 Thread Sami Mujawar

Hi Sahil,

Thank you for this patch.

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

Otherwise this patch looks good to me.

Reviewed-by: Sami Mujawar 

Regards,

Sami Mujawar

On 23/05/2024 11:55 am, Sahil Kaushal wrote:

From: sahil

This patch adds error_handler1 and error_handler2 labels in
NorFlashCreateInstance() function to handle the cleanup.

error_handler1: Frees just the Instance structure as the
ShadowBuffer is not allocated yet.

error_handler2: Frees both Instance and Instance->ShadowBuffer.

Signed-off-by: sahil
---
  Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c  | 18 
+-
  Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c | 19 
++-
  2 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c
index e01b05d91978..fd47bd9e4c63 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c
@@ -135,7 +135,8 @@ NorFlashCreateInstance (
  


Instance->ShadowBuffer = AllocateRuntimePool (BlockSize);

if (Instance->ShadowBuffer == NULL) {

-return EFI_OUT_OF_RESOURCES;

+Status = EFI_OUT_OF_RESOURCES;

+goto error_handler1;

}

  


if (SupportFvb) {

@@ -152,8 +153,7 @@ NorFlashCreateInstance (
  NULL

  );

  if (EFI_ERROR (Status)) {

-  FreePool (Instance);

-  return Status;

+  goto error_handler2;

  }

} else {

  Status = gBS->InstallMultipleProtocolInterfaces (

@@ -167,12 +167,20 @@ NorFlashCreateInstance (
  NULL

  );

  if (EFI_ERROR (Status)) {

-  FreePool (Instance);

-  return Status;

+  goto error_handler2;

  }

}

  


*NorFlashInstance = Instance;

[SNIP]

+  return EFI_SUCCESS;

+
+error_handler1:

+  FreePool (Instance);

+  return Status;

+

+error_handler2:

+  FreePool (Instance->ShadowBuffer);

+  FreePool (Instance);

return Status;


[/SNIP]

[SAMI] I think the above code can be simplified as below:

---

+ return Status;
+

+error_handler2:

+  FreePool (Instance->ShadowBuffer);

+error_handler2:

+  FreePool (Instance);

   return Status;
---

A similar change is reuired later in this patch below.

If you agree, I will fix this up before merging the patch.

[/SAMI]



  }

  


diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c
index 16fe3762e125..17dfe26627dd 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c
@@ -129,7 +129,8 @@ NorFlashCreateInstance (
  


Instance->ShadowBuffer = AllocateRuntimePool (BlockSize);

if (Instance->ShadowBuffer == NULL) {

-return EFI_OUT_OF_RESOURCES;

+Status = EFI_OUT_OF_RESOURCES;

+goto error_handler1;

}

  


if (SupportFvb) {

@@ -142,16 +143,24 @@ NorFlashCreateInstance (
>FvbProtocol

);

  if (EFI_ERROR (Status)) {

-  FreePool (Instance);

-  return Status;

+  goto error_handler2;

  }

} else {

  DEBUG ((DEBUG_ERROR, "standalone MM NOR Flash driver only support 
FVB.\n"));

-FreePool (Instance);

-return EFI_UNSUPPORTED;

+Status = EFI_UNSUPPORTED;

+goto error_handler2;

}

  


*NorFlashInstance = Instance;

+  return EFI_SUCCESS;

+

+error_handler1:

+  FreePool (Instance);

+  return Status;

+

+error_handler2:

+  FreePool (Instance->ShadowBuffer);

+  FreePool (Instance);

return Status;

  }

  




-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119164): https://edk2.groups.io/g/devel/message/119164
Mute This Topic: https://groups.io/mt/106260149/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [edk2-platforms][PATCH 2/3] Platform/AMD: Update Readme.md

2024-05-23 Thread Yao, Ken via groups.io
[AMD Official Use Only - AMD Internal Distribution Only]

[AMD Official Use Only - AMD Internal Distribution Only]

Thanks Abner for the up-stream.

Looks good to me.

Reviewed-by: Ken Yao 
-Original Message-
From: Zhai, MingXin (Duke) 
Sent: Thursday, May 23, 2024 3:47 PM
To: Chang, Abner ; devel@edk2.groups.io
Cc: Grimes, Paul ; Attar, AbdulLateef (Abdul Lateef) 
; Fu, Igniculus ; Yao, Ken 
; Xing, Eric 
Subject: RE: [edk2-platforms][PATCH 2/3] Platform/AMD: Update Readme.md

[AMD Official Use Only - AMD Internal Distribution Only]

Thanks Abner for the up-stream.

Looks good to me.

-Original Message-
From: Chang, Abner 
Sent: Thursday, May 23, 2024 12:12 PM
To: devel@edk2.groups.io
Cc: Grimes, Paul ; Attar, AbdulLateef (Abdul Lateef) 
; Fu, Igniculus ; Yao, Ken 
; Xing, Eric ; Zhai, MingXin (Duke) 

Subject: [edk2-platforms][PATCH 2/3] Platform/AMD: Update Readme.md

From: Abner Chang 

Cc: Paul Grimes 
Cc: Abdul Lateef Attar 
Cc: Igniculus Fu 
Cc: Ken Yao 
Cc: Eric Xing 
Cc: Duke Zhai 
Signed-off-by: Abner Chang 
---
 Platform/AMD/Readme.md | 64 --
 1 file changed, 49 insertions(+), 15 deletions(-)

diff --git a/Platform/AMD/Readme.md b/Platform/AMD/Readme.md index 
99d2b990c7..3297c6ba59 100644
--- a/Platform/AMD/Readme.md
+++ b/Platform/AMD/Readme.md
@@ -7,18 +7,25 @@ booting certain AMD platforms. The definition of sub-folders 
is described in bel

 ## Term and Definitions

+* **AGESA**
+
+  AMD Generic Encapsulated Software Architecture that are executed as
+ part of a  host platform BIOS.
+
 * **AMD Platform** (platform in short)

-  AMD platform refers to a platform that supports the particular AMD SoC 
(processor), such as AMD EPYC Milan and Genoa processors.
+  AMD platform refers to a platform that supports the particular AMD
+ SoC (processor), such as  AMD EPYC Milan and Genoa processors.

 * **AMD Board** (board in short)

   AMD board is a generic terminology refers to a board that is designed based 
on a
   specific AMD SoC architecture (also referred as AMD platform). More than one 
boards
-  are possibly designed to support an AMD platform with different 
configuration, such as 1-processor socket or 2-processor sockets board.
+  are possibly designed to support an AMD platform with different
+ configuration, such as  1-processor socket or 2-processor sockets board.

 * **AMD edk2 Platform Package** (platform package in short)
-
+
   The folder has the AMD edk2 platform common modules.

 * **AMD edk2 Board Package** (board package in short) @@ -28,29 +35,52 @@ 
booting certain AMD platforms. The definition of sub-folders is described in bel

 ## Package Definition

+* **AgesaModulePkg**
+
+  This package contains all of the private interfaces and build
+ configuration files for the  AGESA support.
+
+* **AgesaPkg**
+
+  This package contains all of the public interfaces and build
+ configuration files  for the AGESA support.
+
+* **AmdCbsPkg**
+
+  AMD Configurable BIOS Setting. Provides the edk2 formset following
+ the UEFI HII  spec to configure BIOS settings.
+
+* **AmdCpmPkg**
+
+  AMD Common Platform Module software is a BIOS procedure library
+ designed to aid  AMD customers to quickly implement AMD platform technology 
into their products.
+
 * **AmdPlatformPkg**

-  AMD platform edk2 package under this folder provides the common edk2 modules 
those
-  are leverage by platforms. Usually those modules have no dependencies with
-  particular platforms. The module under this scope can provides a common 
implementation
-  for all platforms, or it may just provide a framework but the differences of 
implementation could be configured through the PCDs declared in 
AmdPlatformPkg.dec, or
-  the board level library provided in the \Pkg.
+  AMD platform edk2 package under this folder provides the common edk2
+ modules that are leveraged by platforms. Usually those modules have no
+ dependencies with  particular platforms. Modules under this scope can
+ provide a common implementation  for all platforms, or may just
+ provide a framework but the differences of implementation  could be
+ configured through the PCDs declared in AmdPlatformPkg.dec, or the board 
level  library provided in the \Pkg.

 * **AmdMinBoardPkg**

-  This package provides the common edk2 modules those can be leverage across 
AMD boards those use MinPlatformPkg framework.
+  This package provides the common edk2 modules that can be leveraged
+ across AMD boards using  the MinPlatform framework.

 * **\Board**

-  This is the folder named by SoC and accommodate one or multiple board 
packages those
-  are designed base on the same SoC platform. Board folder may 
contain edk2
-  package meta files directly or the sub-folders named by \Pkg 
for a
-  variety configurations of a platform.
+  This is the folder named by SoC and accommodates one or multiple
+ board packages  that are designed based on the same SoC platform. Board folder may  contain edk2 package meta 

[edk2-devel] [PATCH] Pkg-Module:UefiCpuPkg/MpLib:Do not assume BSP is #0.

2024-05-23 Thread Ning Feng
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=4778
MPInitlib have wrong expectation that BSP index should always be 0 in
MpInitLibInitialize(), SwitchBsp(),ApWakeupFunction().
That will cause the data mismatch, if the initial BSP is not 0.
Cc: Ray Ni 
Signed-off-by: Ning Feng 
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 34 
 1 file changed, 24 insertions(+), 10 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index d724456502..ae279c6ceb 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -114,6 +114,10 @@ FutureBSPProc (
   SaveVolatileRegisters (>APInfo.VolatileRegisters);
   AsmExchangeRole (>APInfo, >BSPInfo);
   RestoreVolatileRegisters (>APInfo.VolatileRegisters, FALSE);
+  //
+  // Restore VolatileReg saved in CpuMpData->CpuData
+  //
+  CopyMem (>CpuData[DataInHob->BspNumber].VolatileRegisters, 
>APInfo.VolatileRegisters, sizeof (CPU_VOLATILE_REGISTERS));
 }
 
 /**
@@ -761,11 +765,11 @@ ApWakeupFunction (
   BistData = (UINT32)ApStackData->Bist;
 
   //
-  // CpuMpData->CpuData[0].VolatileRegisters is initialized based on BSP 
environment,
+  // CpuMpData->CpuData[BspNumber].VolatileRegisters is initialized based 
on BSP environment,
   //   to initialize AP in InitConfig path.
-  // NOTE: IDTR.BASE stored in CpuMpData->CpuData[0].VolatileRegisters 
points to a different IDT shared by all APs.
+  // NOTE: IDTR.BASE stored in 
CpuMpData->CpuData[BspNumber].VolatileRegisters points to a different IDT 
shared by all APs.
   //
-  RestoreVolatileRegisters (>CpuData[0].VolatileRegisters, 
FALSE);
+  RestoreVolatileRegisters 
(>CpuData[CpuMpData->BspNumber].VolatileRegisters, FALSE);
   InitializeApData (CpuMpData, ProcessorNumber, BistData, ApTopOfStack);
   ApStartupSignalBuffer = 
CpuMpData->CpuData[ProcessorNumber].StartupApSignal;
 } else {
@@ -798,10 +802,10 @@ ApWakeupFunction (
 // 1. AP is re-enabled after it's disabled, in either PEI or DXE phase.
 // 2. AP is initialized in DXE phase.
 // In either case, use the volatile registers value derived from BSP.
-// NOTE: IDTR.BASE stored in CpuMpData->CpuData[0].VolatileRegisters 
points to a
+// NOTE: IDTR.BASE stored in 
CpuMpData->CpuData[BspNumber].VolatileRegisters points to a
 //   different IDT shared by all APs.
 //
-RestoreVolatileRegisters (>CpuData[0].VolatileRegisters, 
FALSE);
+RestoreVolatileRegisters 
(>CpuData[CpuMpData->BspNumber].VolatileRegisters, FALSE);
   } else {
 if (CpuMpData->ApLoopMode == ApInHltLoop) {
   //
@@ -927,7 +931,7 @@ DxeApEntryPoint (
 AsmWriteMsr64 (MSR_IA32_EFER, EferMsr.Uint64);
   }
 
-  RestoreVolatileRegisters (>CpuData[0].VolatileRegisters, FALSE);
+  RestoreVolatileRegisters 
(>CpuData[CpuMpData->BspNumber].VolatileRegisters, FALSE);
   InterlockedIncrement ((UINT32 *)>FinishedCount);
   PlaceAPInMwaitLoopOrRunLoop (
 CpuMpData->ApLoopMode,
@@ -2151,7 +2155,12 @@ MpInitLibInitialize (
   CpuMpData->BackupBufferSize = ApResetVectorSizeBelow1Mb;
   CpuMpData->WakeupBuffer = (UINTN)-1;
   CpuMpData->CpuCount = 1;
-  CpuMpData->BspNumber= 0;
+  if (MpHandOff == NULL) {
+CpuMpData->BspNumber = 0;
+  } else {
+CpuMpData->BspNumber = GetBspNumber (MpHandOff);
+  }
+
   CpuMpData->WaitEvent= NULL;
   CpuMpData->SwitchBspFlag= FALSE;
   CpuMpData->CpuData  = (CPU_AP_DATA *)(CpuMpData + 1);
@@ -2186,11 +2195,11 @@ MpInitLibInitialize (
   // Don't pass BSP's TR to APs to avoid AP init failure.
   //
   VolatileRegisters.Tr = 0;
-  CopyMem (>CpuData[0].VolatileRegisters, , 
sizeof (VolatileRegisters));
+  CopyMem (>CpuData[CpuMpData->BspNumber].VolatileRegisters, 
, sizeof (VolatileRegisters));
   //
   // Set BSP basic information
   //
-  InitializeApData (CpuMpData, 0, 0, CpuMpData->Buffer + ApStackSize);
+  InitializeApData (CpuMpData, CpuMpData->BspNumber, 0, CpuMpData->Buffer + 
ApStackSize * (CpuMpData->BspNumber + 1));
   //
   // Save assembly code information
   //
@@ -2615,7 +2624,12 @@ SwitchBSPWorker (
   SaveVolatileRegisters (>BSPInfo.VolatileRegisters);
   AsmExchangeRole (>BSPInfo, >APInfo);
   RestoreVolatileRegisters (>BSPInfo.VolatileRegisters, FALSE);
-
+  //
+  // Restore VolatileRegs saved in CpuMpData->CpuData
+  // Don't pass BSP's TR to APs to avoid AP init failure.
+  //
+  CopyMem (>CpuData[CpuMpData->NewBspNumber].VolatileRegisters, 
>BSPInfo.VolatileRegisters, sizeof (CPU_VOLATILE_REGISTERS));
+  CpuMpData->CpuData[CpuMpData->NewBspNumber].VolatileRegisters.Tr = 0;
   //
   // Set the BSP bit of MSR_IA32_APIC_BASE on new BSP
   //
-- 
2.25.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119161): https://edk2.groups.io/g/devel/message/119161
Mute This Topic: https://groups.io/mt/106263733/21656

Re: [edk2-devel] [PATCH] Pkg-Module:UefiCpuPkg/MpLib

2024-05-23 Thread Ni, Ray
Ning,
The patch looks good to me.
But it seems you did not change the patch title to a more specific message.

[Ray.1] The subject should be more specific. E.g.: UefiCpuPkg/MpInitLib: Do not 
assume BSP is #0.




Thanks,
Ray

From: Feng, Ning 
Sent: Friday, May 24, 2024 2:02
To: devel@edk2.groups.io 
Cc: Feng, Ning ; Ni, Ray 
Subject: [PATCH] Pkg-Module:UefiCpuPkg/MpLib

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=4778
MPInitlib have wrong expectation that BSP index should always be 0 in
MpInitLibInitialize(), SwitchBsp(),ApWakeupFunction().
That will cause the data mismatch, if the initial BSP is not 0.
Cc: Ray Ni 
Signed-off-by: Ning Feng 
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 34 
 1 file changed, 24 insertions(+), 10 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index d724456502..ae279c6ceb 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -114,6 +114,10 @@ FutureBSPProc (
   SaveVolatileRegisters (>APInfo.VolatileRegisters);

   AsmExchangeRole (>APInfo, >BSPInfo);

   RestoreVolatileRegisters (>APInfo.VolatileRegisters, FALSE);

+  //

+  // Restore VolatileReg saved in CpuMpData->CpuData

+  //

+  CopyMem (>CpuData[DataInHob->BspNumber].VolatileRegisters, 
>APInfo.VolatileRegisters, sizeof (CPU_VOLATILE_REGISTERS));

 }



 /**

@@ -761,11 +765,11 @@ ApWakeupFunction (
   BistData = (UINT32)ApStackData->Bist;



   //

-  // CpuMpData->CpuData[0].VolatileRegisters is initialized based on BSP 
environment,

+  // CpuMpData->CpuData[BspNumber].VolatileRegisters is initialized based 
on BSP environment,

   //   to initialize AP in InitConfig path.

-  // NOTE: IDTR.BASE stored in CpuMpData->CpuData[0].VolatileRegisters 
points to a different IDT shared by all APs.

+  // NOTE: IDTR.BASE stored in 
CpuMpData->CpuData[BspNumber].VolatileRegisters points to a different IDT 
shared by all APs.

   //

-  RestoreVolatileRegisters (>CpuData[0].VolatileRegisters, 
FALSE);

+  RestoreVolatileRegisters 
(>CpuData[CpuMpData->BspNumber].VolatileRegisters, FALSE);

   InitializeApData (CpuMpData, ProcessorNumber, BistData, ApTopOfStack);

   ApStartupSignalBuffer = 
CpuMpData->CpuData[ProcessorNumber].StartupApSignal;

 } else {

@@ -798,10 +802,10 @@ ApWakeupFunction (
 // 1. AP is re-enabled after it's disabled, in either PEI or DXE phase.

 // 2. AP is initialized in DXE phase.

 // In either case, use the volatile registers value derived from BSP.

-// NOTE: IDTR.BASE stored in CpuMpData->CpuData[0].VolatileRegisters 
points to a

+// NOTE: IDTR.BASE stored in 
CpuMpData->CpuData[BspNumber].VolatileRegisters points to a

 //   different IDT shared by all APs.

 //

-RestoreVolatileRegisters (>CpuData[0].VolatileRegisters, 
FALSE);

+RestoreVolatileRegisters 
(>CpuData[CpuMpData->BspNumber].VolatileRegisters, FALSE);

   } else {

 if (CpuMpData->ApLoopMode == ApInHltLoop) {

   //

@@ -927,7 +931,7 @@ DxeApEntryPoint (
 AsmWriteMsr64 (MSR_IA32_EFER, EferMsr.Uint64);

   }



-  RestoreVolatileRegisters (>CpuData[0].VolatileRegisters, FALSE);

+  RestoreVolatileRegisters 
(>CpuData[CpuMpData->BspNumber].VolatileRegisters, FALSE);

   InterlockedIncrement ((UINT32 *)>FinishedCount);

   PlaceAPInMwaitLoopOrRunLoop (

 CpuMpData->ApLoopMode,

@@ -2151,7 +2155,12 @@ MpInitLibInitialize (
   CpuMpData->BackupBufferSize = ApResetVectorSizeBelow1Mb;

   CpuMpData->WakeupBuffer = (UINTN)-1;

   CpuMpData->CpuCount = 1;

-  CpuMpData->BspNumber= 0;

+  if (MpHandOff == NULL) {

+CpuMpData->BspNumber = 0;

+  } else {

+CpuMpData->BspNumber = GetBspNumber (MpHandOff);

+  }

+

   CpuMpData->WaitEvent= NULL;

   CpuMpData->SwitchBspFlag= FALSE;

   CpuMpData->CpuData  = (CPU_AP_DATA *)(CpuMpData + 1);

@@ -2186,11 +2195,11 @@ MpInitLibInitialize (
   // Don't pass BSP's TR to APs to avoid AP init failure.

   //

   VolatileRegisters.Tr = 0;

-  CopyMem (>CpuData[0].VolatileRegisters, , 
sizeof (VolatileRegisters));

+  CopyMem (>CpuData[CpuMpData->BspNumber].VolatileRegisters, 
, sizeof (VolatileRegisters));

   //

   // Set BSP basic information

   //

-  InitializeApData (CpuMpData, 0, 0, CpuMpData->Buffer + ApStackSize);

+  InitializeApData (CpuMpData, CpuMpData->BspNumber, 0, CpuMpData->Buffer + 
ApStackSize * (CpuMpData->BspNumber + 1));

   //

   // Save assembly code information

   //

@@ -2615,7 +2624,12 @@ SwitchBSPWorker (
   SaveVolatileRegisters (>BSPInfo.VolatileRegisters);

   AsmExchangeRole (>BSPInfo, >APInfo);

   RestoreVolatileRegisters (>BSPInfo.VolatileRegisters, FALSE);

-

+  //

+  // Restore VolatileRegs saved in CpuMpData->CpuData

+  // Don't pass BSP's TR to APs to avoid AP init failure.

+  //

+  CopyMem 

[edk2-devel] [edk2-platforms][PATCH V3 17/17] Platform/ARM/N1Sdp: Enable FaultTolerantWrite Dxe driver for N1Sdp

2024-05-23 Thread Sahil Kaushal
From: sahil 

This driver enables Fault Tolerant Write protocol, which provides
fault tolerant write capability for block devices.

Signed-off-by: sahil 
---
 Platform/ARM/N1Sdp/N1SdpPlatform.dsc | 5 +
 Platform/ARM/N1Sdp/N1SdpPlatform.fdf | 1 +
 2 files changed, 6 insertions(+)

diff --git a/Platform/ARM/N1Sdp/N1SdpPlatform.dsc 
b/Platform/ARM/N1Sdp/N1SdpPlatform.dsc
index fd630fa08c35..743c2e647b76 100644
--- a/Platform/ARM/N1Sdp/N1SdpPlatform.dsc
+++ b/Platform/ARM/N1Sdp/N1SdpPlatform.dsc
@@ -162,6 +162,10 @@
   gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiExposedTableVersions|0x20
 
   # NOR flash support
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0x18F4
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize|0x0002
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0x18F2
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize|0x0002
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0x18F0
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x0002
 
@@ -228,6 +232,7 @@
   
NULL|EmbeddedPkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.inf
   BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
   }
+  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
 
   # ACPI Support
   MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
diff --git a/Platform/ARM/N1Sdp/N1SdpPlatform.fdf 
b/Platform/ARM/N1Sdp/N1SdpPlatform.fdf
index 07118725f168..7b7eda51c70c 100644
--- a/Platform/ARM/N1Sdp/N1SdpPlatform.fdf
+++ b/Platform/ARM/N1Sdp/N1SdpPlatform.fdf
@@ -90,6 +90,7 @@ READ_LOCK_STATUS   = TRUE
   INF MdeModulePkg/Universal/Metronome/Metronome.inf
   INF MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf
   INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
+  INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
   INF 
MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf
   INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
   INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
-- 
2.25.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119159): https://edk2.groups.io/g/devel/message/119159
Mute This Topic: https://groups.io/mt/106260158/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [edk2-platforms][PATCH V3 16/17] Platform/ARM/N1Sdp: Persistent storage for N1Sdp

2024-05-23 Thread Sahil Kaushal
From: sahil 

Enable persistent storage on QSPI flash device.

Signed-off-by: sahil 
---
 Platform/ARM/N1Sdp/N1SdpPlatform.dsc | 19 ++-
 Platform/ARM/N1Sdp/N1SdpPlatform.fdf |  2 ++
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/Platform/ARM/N1Sdp/N1SdpPlatform.dsc 
b/Platform/ARM/N1Sdp/N1SdpPlatform.dsc
index 46412bff7d78..fd630fa08c35 100644
--- a/Platform/ARM/N1Sdp/N1SdpPlatform.dsc
+++ b/Platform/ARM/N1Sdp/N1SdpPlatform.dsc
@@ -161,11 +161,9 @@
   # ACPI Table Version
   gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiExposedTableVersions|0x20
 
-  # Runtime Variable storage
-  gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved|0
-  gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvModeEnable|TRUE
-  gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000
-  gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x2800
+  # NOR flash support
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0x18F0
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x0002
 
 

 #
@@ -197,6 +195,16 @@
   gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x800F
   }
 
+  # NOR flash support
+  Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.inf {
+
+  
NorFlashDeviceLib|Platform/ARM/Library/CadenceQspiNorFlashDeviceLib/CadenceQspiNorFlashDeviceLib.inf
+  
NorFlashPlatformLib|Silicon/ARM/NeoverseN1Soc/Library/NorFlashLib/NorFlashLib.inf
+  NorFlashInfoLib|EmbeddedPkg/Library/NorFlashInfoLib/NorFlashInfoLib.inf
+
+  gPlatformArmTokenSpaceGuid.PcdNorFlashRegBaseAddress|0x1C0C
+  }
+
   # Architectural Protocols
   ArmPkg/Drivers/CpuDxe/CpuDxe.inf
   ArmPkg/Drivers/ArmGic/ArmGicDxe.inf
@@ -217,6 +225,7 @@
   MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf {
 
   NULL|MdeModulePkg/Library/VarCheckUefiLib/VarCheckUefiLib.inf
+  
NULL|EmbeddedPkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedLib.inf
   BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
   }
 
diff --git a/Platform/ARM/N1Sdp/N1SdpPlatform.fdf 
b/Platform/ARM/N1Sdp/N1SdpPlatform.fdf
index 7aae8e6a753b..07118725f168 100644
--- a/Platform/ARM/N1Sdp/N1SdpPlatform.fdf
+++ b/Platform/ARM/N1Sdp/N1SdpPlatform.fdf
@@ -140,6 +140,8 @@ READ_LOCK_STATUS   = TRUE
   INF ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.inf
   INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf
 
+  INF Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.inf
+
   INF Platform/ARM/Drivers/BootMonFs/BootMonFs.inf
   INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf
 
-- 
2.25.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119158): https://edk2.groups.io/g/devel/message/119158
Mute This Topic: https://groups.io/mt/106260157/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [edk2-platforms][PATCH V3 15/17] Platform/ARM: Add CadenceQspiNorFlashDeviceLib for NorFlashDxe

2024-05-23 Thread Sahil Kaushal
From: sahil 

In N1Sdp platform, the SoC is connected to IOFPGA which has a
Cadence Quad SPI (QSPI) controller. This QSPI controller manages
the flash chip device via QSPI bus.

This patch adds CadenceQspiNorFlashDeviceLib which is used to
manage and access the above configuration.

Signed-off-by: sahil 
---
 
Platform/ARM/Library/CadenceQspiNorFlashDeviceLib/CadenceQspiNorFlashDeviceLib.inf
 |   32 +
 
Platform/ARM/Library/CadenceQspiNorFlashDeviceLib/CadenceQspiNorFlashDeviceLib.h
   |   46 +
 
Platform/ARM/Library/CadenceQspiNorFlashDeviceLib/CadenceQspiNorFlashDeviceLib.c
   | 1034 
 3 files changed, 1112 insertions(+)

diff --git 
a/Platform/ARM/Library/CadenceQspiNorFlashDeviceLib/CadenceQspiNorFlashDeviceLib.inf
 
b/Platform/ARM/Library/CadenceQspiNorFlashDeviceLib/CadenceQspiNorFlashDeviceLib.inf
new file mode 100644
index ..506876b62285
--- /dev/null
+++ 
b/Platform/ARM/Library/CadenceQspiNorFlashDeviceLib/CadenceQspiNorFlashDeviceLib.inf
@@ -0,0 +1,32 @@
+#/** @file
+#
+#  Component description file for CadenceQspiNorFlashDeviceLib Library
+#
+#  Copyright (c) 2024, Arm Limited. All rights reserved.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#**/
+
+[Defines]
+  INF_VERSION= 0x00010005
+  BASE_NAME  = CadenceQspiNorFlashDeviceLib
+  FILE_GUID  = ed172366-066b-4998-9b5e-ca7f385a170b
+  MODULE_TYPE= DXE_RUNTIME_DRIVER
+  VERSION_STRING = 1.0
+  LIBRARY_CLASS  = NorFlashDeviceLib
+
+[Sources.common]
+  CadenceQspiNorFlashDeviceLib.c
+  CadenceQspiNorFlashDeviceLib.h
+
+[Packages]
+  MdePkg/MdePkg.dec
+  Platform/ARM/ARM.dec
+
+[LibraryClasses]
+  BaseLib
+  BaseMemoryLib
+  DebugLib
+  IoLib
+  TimerLib
diff --git 
a/Platform/ARM/Library/CadenceQspiNorFlashDeviceLib/CadenceQspiNorFlashDeviceLib.h
 
b/Platform/ARM/Library/CadenceQspiNorFlashDeviceLib/CadenceQspiNorFlashDeviceLib.h
new file mode 100644
index ..951a93481dd1
--- /dev/null
+++ 
b/Platform/ARM/Library/CadenceQspiNorFlashDeviceLib/CadenceQspiNorFlashDeviceLib.h
@@ -0,0 +1,46 @@
+/** @file
+
+  Copyright (c) 2024, ARM Limited. All rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef CADENCE_QSPI_NOR_FLASH_DEVICE_LIB_H_
+#define CADENCE_QSPI_NOR_FLASH_DEVICE_LIB_H_
+
+#define NOR_FLASH_ERASE_RETRY  10
+
+// QSPI Controller defines
+#define CDNS_QSPI_FLASH_CMD_CTRL_REG_OFFSET 0x90
+#define CDNS_QSPI_FLASH_CMD_CTRL_REG_EXECUTE0x01
+#define CDNS_QSPI_FLASH_CMD_CTRL_REG_ADDR_ENABLE0x01
+#define CDNS_QSPI_FLASH_CMD_CTRL_REG_ADDR_BIT_POS   19
+#define CDNS_QSPI_FLASH_CMD_CTRL_REG_ADDR_BYTE_BIT_POS  16
+#define CDNS_QSPI_FLASH_CMD_CTRL_REG_STATUS_BIT 0x02
+#define CDNS_QSPI_FLASH_CMD_CTRL_REG_OPCODE_BIT_POS 24
+#define CDNS_QSPI_FLASH_CMD_CTRL_REG_READ_ENABLE0x01
+#define CDNS_QSPI_FLASH_CMD_CTRL_REG_READ_BYTE_3B   0x02
+#define CDNS_QSPI_FLASH_CMD_CTRL_REG_READEN_BIT_POS 23
+#define CDNS_QSPI_FLASH_CMD_CTRL_REG_READBYTE_BIT_POS   20
+#define CDNS_QSPI_FLASH_CMD_CTRL_REG_DUMMY_8C   0x8
+#define CDNS_QSPI_FLASH_CMD_CTRL_REG_DUMMY_BIT_POS  7
+#define CDNS_QSPI_FLASH_CMD_CTRL_REG_NUM_DATA_BYTES(x)  ((x - 1) << 
CDNS_QSPI_FLASH_CMD_CTRL_REG_READBYTE_BIT_POS)
+#define CDNS_QSPI_FLASH_CMD_CTRL_REG_NUM_ADDR_BYTES(x)  ((x - 1) << 
CDNS_QSPI_FLASH_CMD_CTRL_REG_ADDR_BYTE_BIT_POS)
+
+#define CDNS_QSPI_FLASH_CMD_READ_DATA_REG_OFFSET  0xA0
+
+#define CDNS_QSPI_FLASH_CMD_ADDR_REG_OFFSET  0x94
+
+#define CDNS_QSPI_FLASH_CMD_STATUS_POLL_TIMEOUT_MS  1000u // Command Status 
Register read timeout
+
+#define SPINOR_SR_WIP  BIT0   // Write in progress
+
+#define SPINOR_OP_WREN   0x06 // Write enable
+#define SPINOR_OP_BE_4K  0x20 // Erase 4KiB block
+#define SPINOR_OP_RDID   0x9f // Read JEDEC ID
+#define SPINOR_OP_RDSR   0x05 // Read status 
register
+
+#define SPINOR_SR_WIP_POLL_TIMEOUT_MS  1000u  // Status Register 
read timeout
+
+#endif /* CADENCE_QSPI_NOR_FLASH_DEVICE_LIB_H_ */
diff --git 
a/Platform/ARM/Library/CadenceQspiNorFlashDeviceLib/CadenceQspiNorFlashDeviceLib.c
 
b/Platform/ARM/Library/CadenceQspiNorFlashDeviceLib/CadenceQspiNorFlashDeviceLib.c
new file mode 100644
index ..f97c8d51fd48
--- /dev/null
+++ 
b/Platform/ARM/Library/CadenceQspiNorFlashDeviceLib/CadenceQspiNorFlashDeviceLib.c
@@ -0,0 +1,1034 @@
+/** @file
+
+  Copyright (c) 2024 ARM Limited. All rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "CadenceQspiNorFlashDeviceLib.h"
+
+/**
+  Converts milliseconds into number of ticks of the performance counter.
+
+  @param[in] Milliseconds  Milliseconds to convert into ticks.
+
+  @retval Milliseconds expressed as number of 

[edk2-devel] [edk2-platforms][PATCH V3 14/17] Silicon/ARM/NeoverseN1Soc: NOR flash library for N1Sdp

2024-05-23 Thread Sahil Kaushal
From: sahil 

Add NOR flash library, this library provides APIs for getting the list
of NOR flash devices on the platform.

This flash is shared between AP core and System Control Processor. The
lower addresses are used to store SCP and AP boot images and higher
addresses will be used for variable storage.

Signed-off-by: sahil 
---
 Silicon/ARM/NeoverseN1Soc/Library/NorFlashLib/NorFlashLib.inf | 35 +
 Silicon/ARM/NeoverseN1Soc/Include/NeoverseN1Soc.h |  1 +
 Silicon/ARM/NeoverseN1Soc/Library/NorFlashLib/NorFlashLib.c   | 80 

 3 files changed, 116 insertions(+)

diff --git a/Silicon/ARM/NeoverseN1Soc/Library/NorFlashLib/NorFlashLib.inf 
b/Silicon/ARM/NeoverseN1Soc/Library/NorFlashLib/NorFlashLib.inf
new file mode 100644
index ..a9495cf667d5
--- /dev/null
+++ b/Silicon/ARM/NeoverseN1Soc/Library/NorFlashLib/NorFlashLib.inf
@@ -0,0 +1,35 @@
+## @file
+#  NOR flash lib for ARM Neoverse N1 platform.
+#
+#  Copyright (c) 2024, ARM Limited. All rights reserved.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION= 0x0001001B
+  BASE_NAME  = NorFlashNeoverseN1SocLib
+  FILE_GUID  = 7006fcf1-a585-4272-92e3-b286b1dff5bb
+  MODULE_TYPE= DXE_DRIVER
+  VERSION_STRING = 1.0
+  LIBRARY_CLASS  = NorFlashPlatformLib
+
+[Sources.common]
+  NorFlashLib.c
+
+[Packages]
+  MdeModulePkg/MdeModulePkg.dec
+  MdePkg/MdePkg.dec
+  Platform/ARM/ARM.dec
+  Silicon/ARM/NeoverseN1Soc/NeoverseN1Soc.dec
+
+[LibraryClasses]
+  BaseLib
+  DebugLib
+
+[FixedPcd]
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
diff --git a/Silicon/ARM/NeoverseN1Soc/Include/NeoverseN1Soc.h 
b/Silicon/ARM/NeoverseN1Soc/Include/NeoverseN1Soc.h
index 2dae57a0f01a..2a592e5adc2f 100644
--- a/Silicon/ARM/NeoverseN1Soc/Include/NeoverseN1Soc.h
+++ b/Silicon/ARM/NeoverseN1Soc/Include/NeoverseN1Soc.h
@@ -47,6 +47,7 @@
 // SCP QSPI flash device
 #define NEOVERSEN1SOC_SCP_QSPI_AHB_BASE  0x1800
 #define NEOVERSEN1SOC_SCP_QSPI_AHB_SZ0x200
+#define NEOVERSEN1SOC_FIRMWARE_IAMGES_SZ 0x80
 
 /*
  * Platform information structure stored in Non-secure SRAM. Platform
diff --git a/Silicon/ARM/NeoverseN1Soc/Library/NorFlashLib/NorFlashLib.c 
b/Silicon/ARM/NeoverseN1Soc/Library/NorFlashLib/NorFlashLib.c
new file mode 100644
index ..a354ffb5ac6d
--- /dev/null
+++ b/Silicon/ARM/NeoverseN1Soc/Library/NorFlashLib/NorFlashLib.c
@@ -0,0 +1,80 @@
+/** @file
+*  NOR flash lib for ARM Neoverse N1 platform
+*
+*  Copyright (c) 2024, ARM Limited. All rights reserved.
+*
+*  SPDX-License-Identifier: BSD-2-Clause-Patent
+*
+**/
+
+#include 
+#include 
+#include 
+#include 
+
+#define FW_ENV_REGION_BASE  FixedPcdGet32 (PcdFlashNvStorageVariableBase)
+#define FW_ENV_REGION_SIZE  (FixedPcdGet32 (PcdFlashNvStorageVariableSize) + \
+FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) + \
+FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize))
+
+STATIC NOR_FLASH_DESCRIPTION  mNorFlashDevices[] = {
+  {
+/// Environment variable region
+NEOVERSEN1SOC_SCP_QSPI_AHB_BASE,///< device base
+FW_ENV_REGION_BASE, ///< region base
+FW_ENV_REGION_SIZE, ///< region size
+SIZE_4KB,   ///< block size
+  },
+};
+
+/**
+  Dummy implementation of NorFlashPlatformInitialization to
+  comply with NorFlashPlatformLib structure.
+
+  @retvalEFI_SUCCESSSuccess.
+**/
+EFI_STATUS
+NorFlashPlatformInitialization (
+  VOID
+  )
+{
+  return EFI_SUCCESS;
+}
+
+/**
+  Get NOR flash region info
+
+  @param[out]NorFlashDevicesNOR flash regions info.
+  @param[out]Count  number of flash instance.
+
+  @retvalEFI_SUCCESSSuccess.
+  @retvalEFI_INVALID_PARAMETER  The parameters specified are not valid.
+  @retvalEFI_ACCESS_DENIED  Invalid variable region address.
+**/
+EFI_STATUS
+NorFlashPlatformGetDevices (
+  OUT NOR_FLASH_DESCRIPTION  **NorFlashDevices,
+  OUT UINT32 *Count
+  )
+{
+  if ((NorFlashDevices == NULL) || (Count == NULL)) {
+return EFI_INVALID_PARAMETER;
+  }
+
+  if ((NEOVERSEN1SOC_SCP_QSPI_AHB_BASE +
+   NEOVERSEN1SOC_FIRMWARE_IAMGES_SZ) >=
+  FW_ENV_REGION_BASE)
+  {
+DEBUG ((
+  DEBUG_ERROR,
+  "NorFlashPlatformInitialization: Variable region overlapping with "
+  "firmware region.\n"
+  ));
+
+return EFI_ACCESS_DENIED;
+  }
+
+  *NorFlashDevices = mNorFlashDevices;
+  *Count   = ARRAY_SIZE (mNorFlashDevices);
+  return 

[edk2-devel] [edk2-platforms][PATCH V3 13/17] Silicon/ARM/NeoverseN1Soc: Enable SCP QSPI flash region

2024-05-23 Thread Sahil Kaushal
From: sahil 

Enable SCP QSPI flash region access by adding it in the PlatformLibMem.
This flash is shared between AP core and System Control Processor. The
lower addresses are used to store SCP and AP boot images and higher
addresses will be used for variable storage.

Signed-off-by: sahil 
---
 Silicon/ARM/NeoverseN1Soc/Include/NeoverseN1Soc.h  | 7 +++
 Silicon/ARM/NeoverseN1Soc/Library/PlatformLib/PlatformLibMem.c | 8 +++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/Silicon/ARM/NeoverseN1Soc/Include/NeoverseN1Soc.h 
b/Silicon/ARM/NeoverseN1Soc/Include/NeoverseN1Soc.h
index 5483e7bc5f68..2dae57a0f01a 100644
--- a/Silicon/ARM/NeoverseN1Soc/Include/NeoverseN1Soc.h
+++ b/Silicon/ARM/NeoverseN1Soc/Include/NeoverseN1Soc.h
@@ -4,6 +4,9 @@
 *
 * SPDX-License-Identifier: BSD-2-Clause-Patent
 *
+* Arm Neoverse N1 System Development Platform Technical Reference Manual
+* https://developer.arm.com/documentation/101489//?lang=en
+*
 **/
 
 #ifndef NEOVERSEN1SOC_PLATFORM_H_
@@ -41,6 +44,10 @@
 #define NEOVERSEN1SOC_EXP_PERIPH_BASE0   0x1C00
 #define NEOVERSEN1SOC_EXP_PERIPH_BASE0_SZ0x130
 
+// SCP QSPI flash device
+#define NEOVERSEN1SOC_SCP_QSPI_AHB_BASE  0x1800
+#define NEOVERSEN1SOC_SCP_QSPI_AHB_SZ0x200
+
 /*
  * Platform information structure stored in Non-secure SRAM. Platform
  * information are passed from the trusted firmware with the below structure
diff --git a/Silicon/ARM/NeoverseN1Soc/Library/PlatformLib/PlatformLibMem.c 
b/Silicon/ARM/NeoverseN1Soc/Library/PlatformLib/PlatformLibMem.c
index 80daedb33416..282bfbc81736 100644
--- a/Silicon/ARM/NeoverseN1Soc/Library/PlatformLib/PlatformLibMem.c
+++ b/Silicon/ARM/NeoverseN1Soc/Library/PlatformLib/PlatformLibMem.c
@@ -14,7 +14,7 @@
 #include 
 
 // The total number of descriptors, including the final "end-of-table" 
descriptor.
-#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 19
+#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 20
 
 /**
   Returns the Virtual Memory Map of the platform.
@@ -203,6 +203,12 @@ ArmPlatformGetVirtualMemoryMap (
   VirtualMemoryTable[Index].Length  = 
NEOVERSEN1SOC_EXP_PERIPH_BASE0_SZ;
   VirtualMemoryTable[Index].Attributes  = 
ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
 
+  // SCP QSPI flash device
+  VirtualMemoryTable[++Index].PhysicalBase  = NEOVERSEN1SOC_SCP_QSPI_AHB_BASE;
+  VirtualMemoryTable[Index].VirtualBase = NEOVERSEN1SOC_SCP_QSPI_AHB_BASE;
+  VirtualMemoryTable[Index].Length  = NEOVERSEN1SOC_SCP_QSPI_AHB_SZ;
+  VirtualMemoryTable[Index].Attributes  = 
ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
+
   if (PlatInfo->MultichipMode == 1) {
 //Remote DDR (2GB)
 VirtualMemoryTable[++Index].PhysicalBase  = PcdGet64 (PcdExtMemorySpace) +
-- 
2.25.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119155): https://edk2.groups.io/g/devel/message/119155
Mute This Topic: https://groups.io/mt/106260153/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [edk2-platforms][PATCH V3 12/17] Platform/ARM: Add optional provision to fetch and print NOR Flash info

2024-05-23 Thread Sahil Kaushal
From: sahil 

This patch adds an optional functionality in NorFlashDxe to fetch and
print NOR Flash information from NorFlashInfoLib using its JEDEC ID.

NOR Flash libraries will implement a function "NorFlashReadID" which
will fetch and return JEDEC ID. This JEDEC ID can be then printed
along with the NOR Flash info by NorFlashInfoLib. If this functionality
is not needed then the function can just return EFI_UNSUPPORTED.

Signed-off-by: sahil 
---
 Platform/ARM/SgiPkg/SgiPlatform.dsc.inc  |  2 ++
 Platform/ARM/SgiPkg/SgiPlatformMm.dsc.inc|  2 ++
 Platform/ARM/VExpressPkg/ArmVExpress.dsc.inc |  2 ++
 Platform/ARM/JunoPkg/ArmJuno.dsc |  2 ++
 Platform/ARM/VExpressPkg/PlatformStandaloneMm.dsc|  2 ++
 Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.inf |  1 +
 Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.inf|  1 +
 Platform/ARM/Include/Library/NorFlashDeviceLib.h | 17 
+
 Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c   | 18 
++
 Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c  | 18 
++
 Platform/ARM/Library/P30NorFlashDeviceLib/P30NorFlashDeviceLib.c | 18 
++
 11 files changed, 83 insertions(+)

diff --git a/Platform/ARM/SgiPkg/SgiPlatform.dsc.inc 
b/Platform/ARM/SgiPkg/SgiPlatform.dsc.inc
index 3dcf422eab4b..107a5311b666 100644
--- a/Platform/ARM/SgiPkg/SgiPlatform.dsc.inc
+++ b/Platform/ARM/SgiPkg/SgiPlatform.dsc.inc
@@ -36,6 +36,8 @@
   LcdPlatformLib|Platform/ARM/SgiPkg/Library/HdLcdArmSgiLib/HdLcdArmSgiLib.inf
   
NorFlashDeviceLib|Platform/ARM/Library/P30NorFlashDeviceLib/P30NorFlashDeviceLib.inf
   NorFlashPlatformLib|Platform/ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.inf
+  # NOR flash identification support
+  NorFlashInfoLib|EmbeddedPkg/Library/NorFlashInfoLib/NorFlashInfoLib.inf
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
   
ResetSystemLib|ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.inf
   TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf
diff --git a/Platform/ARM/SgiPkg/SgiPlatformMm.dsc.inc 
b/Platform/ARM/SgiPkg/SgiPlatformMm.dsc.inc
index ab0e2a957a1b..19fd08dd7817 100644
--- a/Platform/ARM/SgiPkg/SgiPlatformMm.dsc.inc
+++ b/Platform/ARM/SgiPkg/SgiPlatformMm.dsc.inc
@@ -65,6 +65,8 @@
   IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf
   
NorFlashDeviceLib|Platform/ARM/Library/P30NorFlashDeviceLib/P30NorFlashDeviceLib.inf
   
NorFlashPlatformLib|Platform/ARM/SgiPkg/Library/NorFlashLib/StandaloneMmNorFlashLib.inf
+  # NOR flash identification support
+  NorFlashInfoLib|EmbeddedPkg/Library/NorFlashInfoLib/NorFlashInfoLib.inf
   OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf
   RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf
   
PlatformSecureLib|SecurityPkg/Library/PlatformSecureLibNull/PlatformSecureLibNull.inf
diff --git a/Platform/ARM/VExpressPkg/ArmVExpress.dsc.inc 
b/Platform/ARM/VExpressPkg/ArmVExpress.dsc.inc
index 70ff049d3248..f7f7b39bbf58 100644
--- a/Platform/ARM/VExpressPkg/ArmVExpress.dsc.inc
+++ b/Platform/ARM/VExpressPkg/ArmVExpress.dsc.inc
@@ -95,6 +95,8 @@
   
ArmPlatformSysConfigLib|Platform/ARM/VExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfigLib.inf
   
NorFlashDeviceLib|Platform/ARM/Library/P30NorFlashDeviceLib/P30NorFlashDeviceLib.inf
   
NorFlashPlatformLib|Platform/ARM/VExpressPkg/Library/NorFlashArmVExpressLib/NorFlashArmVExpressLib.inf
+  # NOR flash identification support
+  NorFlashInfoLib|EmbeddedPkg/Library/NorFlashInfoLib/NorFlashInfoLib.inf
   
ResetSystemLib|ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.inf
 
   # ARM PL031 RTC Driver
diff --git a/Platform/ARM/JunoPkg/ArmJuno.dsc b/Platform/ARM/JunoPkg/ArmJuno.dsc
index 81d2cbe4359f..1ca43b9e7dba 100644
--- a/Platform/ARM/JunoPkg/ArmJuno.dsc
+++ b/Platform/ARM/JunoPkg/ArmJuno.dsc
@@ -42,6 +42,8 @@
 
   
NorFlashDeviceLib|Platform/ARM/Library/P30NorFlashDeviceLib/P30NorFlashDeviceLib.inf
   
NorFlashPlatformLib|Platform/ARM/JunoPkg/Library/NorFlashJunoLib/NorFlashJunoLib.inf
+  # NOR flash identification support
+  NorFlashInfoLib|EmbeddedPkg/Library/NorFlashInfoLib/NorFlashInfoLib.inf
 
   CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
   
CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf
diff --git a/Platform/ARM/VExpressPkg/PlatformStandaloneMm.dsc 
b/Platform/ARM/VExpressPkg/PlatformStandaloneMm.dsc
index a5805da49c92..a0a9d9a21a1b 100644
--- a/Platform/ARM/VExpressPkg/PlatformStandaloneMm.dsc
+++ b/Platform/ARM/VExpressPkg/PlatformStandaloneMm.dsc
@@ -102,6 +102,8 @@
 !if $(ENABLE_UEFI_SECURE_VARIABLE) == TRUE
   
NorFlashDeviceLib|Platform/ARM/Library/P30NorFlashDeviceLib/P30NorFlashDeviceLib.inf
   

[edk2-devel] [edk2-platforms][PATCH V3 11/17] Platform/ARM/NorFlashDxe: Fix memory leak in NorFlashCreateInstance()

2024-05-23 Thread Sahil Kaushal
From: sahil 

This patch adds error_handler1 and error_handler2 labels in
NorFlashCreateInstance() function to handle the cleanup.

error_handler1: Frees just the Instance structure as the
ShadowBuffer is not allocated yet.

error_handler2: Frees both Instance and Instance->ShadowBuffer.

Signed-off-by: sahil 
---
 Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c  | 18 +-
 Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c | 19 
++-
 2 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c
index e01b05d91978..fd47bd9e4c63 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c
@@ -135,7 +135,8 @@ NorFlashCreateInstance (
 
   Instance->ShadowBuffer = AllocateRuntimePool (BlockSize);
   if (Instance->ShadowBuffer == NULL) {
-return EFI_OUT_OF_RESOURCES;
+Status = EFI_OUT_OF_RESOURCES;
+goto error_handler1;
   }
 
   if (SupportFvb) {
@@ -152,8 +153,7 @@ NorFlashCreateInstance (
 NULL
 );
 if (EFI_ERROR (Status)) {
-  FreePool (Instance);
-  return Status;
+  goto error_handler2;
 }
   } else {
 Status = gBS->InstallMultipleProtocolInterfaces (
@@ -167,12 +167,20 @@ NorFlashCreateInstance (
 NULL
 );
 if (EFI_ERROR (Status)) {
-  FreePool (Instance);
-  return Status;
+  goto error_handler2;
 }
   }
 
   *NorFlashInstance = Instance;
+  return EFI_SUCCESS;
+
+error_handler1:
+  FreePool (Instance);
+  return Status;
+
+error_handler2:
+  FreePool (Instance->ShadowBuffer);
+  FreePool (Instance);
   return Status;
 }
 
diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c
index 16fe3762e125..17dfe26627dd 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c
@@ -129,7 +129,8 @@ NorFlashCreateInstance (
 
   Instance->ShadowBuffer = AllocateRuntimePool (BlockSize);
   if (Instance->ShadowBuffer == NULL) {
-return EFI_OUT_OF_RESOURCES;
+Status = EFI_OUT_OF_RESOURCES;
+goto error_handler1;
   }
 
   if (SupportFvb) {
@@ -142,16 +143,24 @@ NorFlashCreateInstance (
   >FvbProtocol
   );
 if (EFI_ERROR (Status)) {
-  FreePool (Instance);
-  return Status;
+  goto error_handler2;
 }
   } else {
 DEBUG ((DEBUG_ERROR, "standalone MM NOR Flash driver only support 
FVB.\n"));
-FreePool (Instance);
-return EFI_UNSUPPORTED;
+Status = EFI_UNSUPPORTED;
+goto error_handler2;
   }
 
   *NorFlashInstance = Instance;
+  return EFI_SUCCESS;
+
+error_handler1:
+  FreePool (Instance);
+  return Status;
+
+error_handler2:
+  FreePool (Instance->ShadowBuffer);
+  FreePool (Instance);
   return Status;
 }
 
-- 
2.25.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119153): https://edk2.groups.io/g/devel/message/119153
Mute This Topic: https://groups.io/mt/106260149/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [edk2-platforms][PATCH V3 10/17] Platform/ARM: Add HostControllerBaseAddress variable

2024-05-23 Thread Sahil Kaushal
From: sahil 

This variable holds the QSPI controller's base address.
It is defined in ARM.dec as well with the default value of 0x0.
In case a platform is not using it, they can just ignore this
variable and the default value of 0x0 will be propogated and
the variable will not be used.

Signed-off-by: sahil 
---
 Platform/ARM/ARM.dec  |  3 ++
 Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.inf  |  3 ++
 Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.inf |  2 ++
 Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h |  1 +
 Platform/ARM/Include/Library/NorFlashDeviceLib.h  | 11 ---
 Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c| 34 
+---
 Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c   | 12 ---
 7 files changed, 54 insertions(+), 12 deletions(-)

diff --git a/Platform/ARM/ARM.dec b/Platform/ARM/ARM.dec
index 86d1fcb4878e..a5e28c372903 100644
--- a/Platform/ARM/ARM.dec
+++ b/Platform/ARM/ARM.dec
@@ -26,3 +26,6 @@
 
 [PcdsFeatureFlag.common]
   
gPlatformArmTokenSpaceGuid.PcdNorFlashCheckBlockLocked|FALSE|BOOLEAN|0x001
+
+[PcdsFixedAtBuild.common]
+  gPlatformArmTokenSpaceGuid.PcdNorFlashRegBaseAddress|0x0|UINT32|0x0002
diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.inf 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.inf
index de160025b632..6522968d6c5a 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.inf
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.inf
@@ -65,5 +65,8 @@
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
 
+[FixedPcd]
+  gPlatformArmTokenSpaceGuid.PcdNorFlashRegBaseAddress
+
 [Depex]
   gEfiCpuArchProtocolGuid
diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.inf 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.inf
index d9e7de07165c..eb86d423f106 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.inf
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.inf
@@ -59,5 +59,7 @@
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
 
+  gPlatformArmTokenSpaceGuid.PcdNorFlashRegBaseAddress
+
 [Depex]
   TRUE
diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h
index 7fcb949843e8..98464e4868b1 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h
@@ -34,6 +34,7 @@
 //
 EFI_STATUS
 NorFlashCreateInstance (
+  IN UINTNHostRegisterBase,
   IN UINTNNorFlashDeviceBase,
   IN UINTNNorFlashRegionBase,
   IN UINTNNorFlashSize,
diff --git a/Platform/ARM/Include/Library/NorFlashDeviceLib.h 
b/Platform/ARM/Include/Library/NorFlashDeviceLib.h
index 6833c1ddc456..348136630e78 100644
--- a/Platform/ARM/Include/Library/NorFlashDeviceLib.h
+++ b/Platform/ARM/Include/Library/NorFlashDeviceLib.h
@@ -36,10 +36,13 @@ struct _NOR_FLASH_INSTANCE {
   UINT32 Signature; ///< NOR Flash instance 
signature.
   EFI_HANDLE Handle;///< NOR Flash instance 
handle.
 
-  UINTN  DeviceBaseAddress; ///< NOR Flash 
device base address.
-  UINTN  RegionBaseAddress; ///< NOR Flash 
region base address.
-  UINTN  Size;  ///< NOR Flash 
region size.
-  EFI_LBAStartLba;  ///< Region start 
LBA.
+  UINTN  HostControllerBaseAddress; ///< NOR 
Flash host controller base address.
+///< This 
field is optional if no host
+///< 
controller is present.
+  UINTN  DeviceBaseAddress; ///< NOR 
Flash device base address.
+  UINTN  RegionBaseAddress; ///< NOR 
Flash region base address.
+  UINTN  Size;  ///< NOR 
Flash region size.
+  EFI_LBAStartLba;  ///< 
Region start LBA.
 
   EFI_BLOCK_IO_PROTOCOL  BlockIoProtocol; ///< Instance's 
Block IO protocol handle.
   EFI_BLOCK_IO_MEDIA Media;   ///< Instance's  
Media information.
diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c
index 1c12572ab663..e01b05d91978 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c
@@ -1,6 +1,6 @@
 /** @file  NorFlashDxe.c
 
-  Copyright (c) 2011 - 2021, Arm Limited. All rights reserved.
+  Copyright (c) 2011 - 2024, Arm Limited. All 

[edk2-devel] [edk2-platforms][PATCH V3 09/17] Platform/ARM/NorFlashDxe: Switch from NorFlash.c to NorFlashDeviceLib

2024-05-23 Thread Sahil Kaushal
From: sahil 

NorFlashDeviceLib can be used to provide implementations of different
NOR Flash to NorFlashDxe, i.e. NorFlashDxe links with NorFlashDeviceLib
and the platforms can specify their respective NorFlashDeviceLib
instances.

This patch adds the following major changes:

1. Adds changes in NorFlashDxe to look for NorFlashDeviceLib instead of
NorFlash.c for flash specific implementation

2. Remove NorFlash.c and NorFlash.h as they are no longer required.

3. Add changes to platform description files to provide
P30NorFlashDeviceLib as NorFlashDeviceLib

Signed-off-by: sahil 
---
 Platform/ARM/SgiPkg/SgiPlatform.dsc.inc   |   1 +
 Platform/ARM/SgiPkg/SgiPlatformMm.dsc.inc |   1 +
 Platform/ARM/VExpressPkg/ArmVExpress.dsc.inc  |   1 +
 Platform/ARM/JunoPkg/ArmJuno.dsc  |   1 +
 Platform/ARM/VExpressPkg/PlatformStandaloneMm.dsc |   1 +
 Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.inf  |   5 +-
 Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.inf |   6 +-
 Platform/ARM/Drivers/NorFlashDxe/NorFlash.h   | 108 ---
 Platform/ARM/Drivers/NorFlashDxe/NorFlash.c   | 956 

 Platform/ARM/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c |   1 -
 Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c|   1 -
 Platform/ARM/Drivers/NorFlashDxe/NorFlashFvb.c|   1 -
 Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c   |   1 -
 13 files changed, 7 insertions(+), 1077 deletions(-)

diff --git a/Platform/ARM/SgiPkg/SgiPlatform.dsc.inc 
b/Platform/ARM/SgiPkg/SgiPlatform.dsc.inc
index 1bf489ffeb39..3dcf422eab4b 100644
--- a/Platform/ARM/SgiPkg/SgiPlatform.dsc.inc
+++ b/Platform/ARM/SgiPkg/SgiPlatform.dsc.inc
@@ -34,6 +34,7 @@
   BasePathLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
   LcdHwLib|ArmPlatformPkg/Library/HdLcd/HdLcd.inf
   LcdPlatformLib|Platform/ARM/SgiPkg/Library/HdLcdArmSgiLib/HdLcdArmSgiLib.inf
+  
NorFlashDeviceLib|Platform/ARM/Library/P30NorFlashDeviceLib/P30NorFlashDeviceLib.inf
   NorFlashPlatformLib|Platform/ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.inf
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
   
ResetSystemLib|ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.inf
diff --git a/Platform/ARM/SgiPkg/SgiPlatformMm.dsc.inc 
b/Platform/ARM/SgiPkg/SgiPlatformMm.dsc.inc
index 0dd9ebbfc16c..ab0e2a957a1b 100644
--- a/Platform/ARM/SgiPkg/SgiPlatformMm.dsc.inc
+++ b/Platform/ARM/SgiPkg/SgiPlatformMm.dsc.inc
@@ -63,6 +63,7 @@
   AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
   IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf
+  
NorFlashDeviceLib|Platform/ARM/Library/P30NorFlashDeviceLib/P30NorFlashDeviceLib.inf
   
NorFlashPlatformLib|Platform/ARM/SgiPkg/Library/NorFlashLib/StandaloneMmNorFlashLib.inf
   OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf
   RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf
diff --git a/Platform/ARM/VExpressPkg/ArmVExpress.dsc.inc 
b/Platform/ARM/VExpressPkg/ArmVExpress.dsc.inc
index 9f51e05af561..70ff049d3248 100644
--- a/Platform/ARM/VExpressPkg/ArmVExpress.dsc.inc
+++ b/Platform/ARM/VExpressPkg/ArmVExpress.dsc.inc
@@ -93,6 +93,7 @@
   # Versatile Express Specific Libraries
   PlatformPeiLib|ArmPlatformPkg/PlatformPei/PlatformPeiLib.inf
   
ArmPlatformSysConfigLib|Platform/ARM/VExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfigLib.inf
+  
NorFlashDeviceLib|Platform/ARM/Library/P30NorFlashDeviceLib/P30NorFlashDeviceLib.inf
   
NorFlashPlatformLib|Platform/ARM/VExpressPkg/Library/NorFlashArmVExpressLib/NorFlashArmVExpressLib.inf
   
ResetSystemLib|ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.inf
 
diff --git a/Platform/ARM/JunoPkg/ArmJuno.dsc b/Platform/ARM/JunoPkg/ArmJuno.dsc
index 7fe796a53433..81d2cbe4359f 100644
--- a/Platform/ARM/JunoPkg/ArmJuno.dsc
+++ b/Platform/ARM/JunoPkg/ArmJuno.dsc
@@ -40,6 +40,7 @@
   ArmPlatformLib|Platform/ARM/JunoPkg/Library/ArmJunoLib/ArmJunoLib.inf
   ArmSmcLib|ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf
 
+  
NorFlashDeviceLib|Platform/ARM/Library/P30NorFlashDeviceLib/P30NorFlashDeviceLib.inf
   
NorFlashPlatformLib|Platform/ARM/JunoPkg/Library/NorFlashJunoLib/NorFlashJunoLib.inf
 
   CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
diff --git a/Platform/ARM/VExpressPkg/PlatformStandaloneMm.dsc 
b/Platform/ARM/VExpressPkg/PlatformStandaloneMm.dsc
index 0e77b76cae69..a5805da49c92 100644
--- a/Platform/ARM/VExpressPkg/PlatformStandaloneMm.dsc
+++ b/Platform/ARM/VExpressPkg/PlatformStandaloneMm.dsc
@@ -100,6 +100,7 @@
 
   # STMM for Variable runtime service.
 !if $(ENABLE_UEFI_SECURE_VARIABLE) == TRUE
+  
NorFlashDeviceLib|Platform/ARM/Library/P30NorFlashDeviceLib/P30NorFlashDeviceLib.inf
   
NorFlashPlatformLib|Platform/ARM/VExpressPkg/Library/NorFlashArmVExpressLib/NorFlashStMmLib.inf
   

[edk2-devel] [edk2-platforms][PATCH V3 08/17] Platform/ARM: Add P30NorFlashDeviceLib Library

2024-05-23 Thread Sahil Kaushal
From: sahil 

This patch implements functions to interact with P30 NOR Flash.
The code is taken from Platform/ARM/Drivers/NorFlashDxe/NorFlash.c
file.

Signed-off-by: sahil 
---
 Platform/ARM/Library/P30NorFlashDeviceLib/P30NorFlashDeviceLib.inf |  35 +
 Platform/ARM/Library/P30NorFlashDeviceLib/P30NorFlashDeviceLib.h   |  98 ++
 Platform/ARM/Library/P30NorFlashDeviceLib/P30NorFlashDeviceLib.c   | 953 

 3 files changed, 1086 insertions(+)

diff --git a/Platform/ARM/Library/P30NorFlashDeviceLib/P30NorFlashDeviceLib.inf 
b/Platform/ARM/Library/P30NorFlashDeviceLib/P30NorFlashDeviceLib.inf
new file mode 100644
index ..0707edb54442
--- /dev/null
+++ b/Platform/ARM/Library/P30NorFlashDeviceLib/P30NorFlashDeviceLib.inf
@@ -0,0 +1,35 @@
+#/** @file
+#
+#  Component description file for P30NorFlashDeviceLib library
+#
+#  Copyright (c) 2011 - 2024, Arm Limited. All rights reserved.
+#  Copyright (c) 2020, Linaro, Ltd. All rights reserved.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#**/
+
+[Defines]
+  INF_VERSION= 0x00010005
+  BASE_NAME  = P30NorFlashDeviceLib
+  FILE_GUID  = ed172366-066b-4998-9b5e-ca7f385a1709
+  MODULE_TYPE= DXE_DRIVER
+  VERSION_STRING = 1.0
+  LIBRARY_CLASS  = NorFlashDeviceLib
+
+[Sources.common]
+  P30NorFlashDeviceLib.c
+  P30NorFlashDeviceLib.h
+
+[Packages]
+  MdePkg/MdePkg.dec
+  Platform/ARM/ARM.dec
+
+[LibraryClasses]
+  BaseLib
+  BaseMemoryLib
+  DebugLib
+  IoLib
+
+[Pcd.common]
+  gPlatformArmTokenSpaceGuid.PcdNorFlashCheckBlockLocked
diff --git a/Platform/ARM/Library/P30NorFlashDeviceLib/P30NorFlashDeviceLib.h 
b/Platform/ARM/Library/P30NorFlashDeviceLib/P30NorFlashDeviceLib.h
new file mode 100644
index ..c310b2310d62
--- /dev/null
+++ b/Platform/ARM/Library/P30NorFlashDeviceLib/P30NorFlashDeviceLib.h
@@ -0,0 +1,98 @@
+/** @file  P30NorFlashDeviceLib.h
+
+  Copyright (c) 2011 - 2024, Arm Limited. All rights reserved.
+  Copyright (c) 2020, Linaro, Ltd. All rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef P30_NOR_FLASH_DEVICE_LIB_H_
+#define P30_NOR_FLASH_DEVICE_LIB_H_
+
+#define NOR_FLASH_ERASE_RETRY  10
+
+// Device access macros
+// These are necessary because we use 2 x 16bit parts to make up 32bit data
+
+#define HIGH_16_BITS  0x
+#define LOW_16_BITS   0x
+#define LOW_8_BITS0x00FF
+
+#define FOLD_32BIT_INTO_16BIT(value)  ( ( value >> 16 ) | ( value & 
LOW_16_BITS ) )
+
+#define GET_LOW_BYTE(value)   ( value & LOW_8_BITS )
+#define GET_HIGH_BYTE(value)  ( GET_LOW_BYTE( value >> 16 ) )
+
+// Each command must be sent simultaneously to both chips,
+// i.e. at the lower 16 bits AND at the higher 16 bits
+#define CREATE_NOR_ADDRESS(BaseAddr, OffsetAddr)  ((BaseAddr) + ((OffsetAddr) 
<< 2))
+#define CREATE_DUAL_CMD(Cmd)  ( ( Cmd << 16) | ( Cmd & 
LOW_16_BITS) )
+#define SEND_NOR_COMMAND(BaseAddr, Offset, Cmd)   MmioWrite32 
(CREATE_NOR_ADDRESS(BaseAddr,Offset), CREATE_DUAL_CMD(Cmd))
+
+#define BOTH_ALIGNED(a, b, align)  UINTN)(a) | (UINTN)(b)) & ((align) - 
1)) == 0)
+
+// Status Register Bits
+#define P30_SR_BIT_WRITE(BIT7 << 16 | BIT7)
+#define P30_SR_BIT_ERASE_SUSPEND(BIT6 << 16 | BIT6)
+#define P30_SR_BIT_ERASE(BIT5 << 16 | BIT5)
+#define P30_SR_BIT_PROGRAM  (BIT4 << 16 | BIT4)
+#define P30_SR_BIT_VPP  (BIT3 << 16 | BIT3)
+#define P30_SR_BIT_PROGRAM_SUSPEND  (BIT2 << 16 | BIT2)
+#define P30_SR_BIT_BLOCK_LOCKED (BIT1 << 16 | BIT1)
+#define P30_SR_BIT_BEFP (BIT0 << 16 | BIT0)
+
+// Device Commands for Intel StrataFlash(R) Embedded Memory (P30) Family
+
+// On chip buffer size for buffered programming operations
+// There are 2 chips, each chip can buffer up to 32 (16-bit)words, and each 
word is 2 bytes.
+// Therefore the total size of the buffer is 2 x 32 x 2 = 128 bytes
+#define P30_MAX_BUFFER_SIZE_IN_BYTES  ((UINTN)128)
+#define P30_MAX_BUFFER_SIZE_IN_WORDS  (P30_MAX_BUFFER_SIZE_IN_BYTES/((UINTN)4))
+#define MAX_BUFFERED_PROG_ITERATIONS  1000
+#define BOUNDARY_OF_32_WORDS  0x7F
+
+// CFI Addresses
+#define P30_CFI_ADDR_QUERY_UNIQUE_QRY  0x10
+#define P30_CFI_ADDR_VENDOR_ID 0x13
+
+// CFI Data
+#define CFI_QRY  0x00595251
+
+// READ Commands
+#define P30_CMD_READ_DEVICE_ID 0x0090
+#define P30_CMD_READ_STATUS_REGISTER   0x0070
+#define P30_CMD_CLEAR_STATUS_REGISTER  0x0050
+#define P30_CMD_READ_ARRAY 0x00FF
+#define P30_CMD_READ_CFI_QUERY 0x0098
+
+// WRITE Commands
+#define P30_CMD_WORD_PROGRAM_SETUP0x0040
+#define P30_CMD_ALTERNATE_WORD_PROGRAM_SETUP  0x0010
+#define P30_CMD_BUFFERED_PROGRAM_SETUP0x00E8
+#define P30_CMD_BUFFERED_PROGRAM_CONFIRM  0x00D0
+#define P30_CMD_BEFP_SETUP0x0080
+#define P30_CMD_BEFP_CONFIRM  0x00D0
+
+// ERASE Commands
+#define P30_CMD_BLOCK_ERASE_SETUP

[edk2-devel] [edk2-platforms][PATCH V3 07/17] Platform/ARM: Create NorFlashDeviceLib library interface for flash specific functions

2024-05-23 Thread Sahil Kaushal
From: sahil 

NorFlashDeviceLib can be used to provide implementations of different
NOR Flash to NorFlashDxe, i.e. NorFlashDxe links with NorFlashDeviceLib
and the platforms can specify their respective NorFlashDeviceLib
instances.

This patch splits NorFlash.h and moves out the function prototypes and
macros that are expected by NorFlashDxe to be implemented by any
Nor Flash implementation to NorFlashDeviceLib.h file.

Signed-off-by: sahil 
---
 Platform/ARM/ARM.dec  |   1 +
 Platform/ARM/Drivers/NorFlashDxe/NorFlash.h   | 105 +
 Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h |   1 +
 Platform/ARM/Include/Library/NorFlashDeviceLib.h  | 236 
 4 files changed, 239 insertions(+), 104 deletions(-)

diff --git a/Platform/ARM/ARM.dec b/Platform/ARM/ARM.dec
index be7e6dc83fde..86d1fcb4878e 100644
--- a/Platform/ARM/ARM.dec
+++ b/Platform/ARM/ARM.dec
@@ -17,6 +17,7 @@
 
 [LibraryClasses]
   BdsLib|Include/Library/BdsLib.h
+  NorFlashDeviceLib|Include/Library/NorFlashDeviceLib.h
   NorFlashPlatformLib|Include/Library/NorFlashPlatformLib.h
 
 [Guids]
diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h
index f30d499042ed..6cb1f64b9875 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h
@@ -20,6 +20,7 @@
 
 #include 
 #include 
+#include 
 
 #define NOR_FLASH_ERASE_RETRY  10
 
@@ -40,7 +41,6 @@
 #define CREATE_NOR_ADDRESS(BaseAddr, OffsetAddr)   ((BaseAddr) + 
((OffsetAddr) << 2))
 #define CREATE_DUAL_CMD(Cmd)   ( ( Cmd << 16) | ( Cmd 
& LOW_16_BITS) )
 #define SEND_NOR_COMMAND(BaseAddr, Offset, Cmd)MmioWrite32 
(CREATE_NOR_ADDRESS(BaseAddr,Offset), CREATE_DUAL_CMD(Cmd))
-#define GET_NOR_BLOCK_ADDRESS(BaseAddr, Lba, LbaSize)  ( BaseAddr + 
(UINTN)((Lba) * LbaSize) )
 
 // Status Register Bits
 #define P30_SR_BIT_WRITE(BIT7 << 16 | BIT7)
@@ -105,107 +105,4 @@
 #define P30_CMD_READ_CONFIGURATION_REGISTER_SETUP  0x0060
 #define P30_CMD_READ_CONFIGURATION_REGISTER0x0003
 
-typedef struct _NOR_FLASH_INSTANCE NOR_FLASH_INSTANCE;
-
-#pragma pack (1)
-typedef struct {
-  VENDOR_DEVICE_PATH  Vendor;
-  UINT8   Index;
-  EFI_DEVICE_PATH_PROTOCOLEnd;
-} NOR_FLASH_DEVICE_PATH;
-#pragma pack ()
-
-struct _NOR_FLASH_INSTANCE {
-  UINT32 Signature;
-  EFI_HANDLE Handle;
-
-  UINTN  DeviceBaseAddress;
-  UINTN  RegionBaseAddress;
-  UINTN  Size;
-  EFI_LBAStartLba;
-
-  EFI_BLOCK_IO_PROTOCOL  BlockIoProtocol;
-  EFI_BLOCK_IO_MEDIA Media;
-  EFI_DISK_IO_PROTOCOL   DiskIoProtocol;
-
-  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOLFvbProtocol;
-  VOID   *ShadowBuffer;
-
-  NOR_FLASH_DEVICE_PATH  DevicePath;
-};
-
-//
-// NorFlash.c
-//
-EFI_STATUS
-NorFlashWriteSingleBlock (
-  INNOR_FLASH_INSTANCE  *Instance,
-  INEFI_LBA Lba,
-  INUINTN   Offset,
-  IN OUTUINTN   *NumBytes,
-  INUINT8   *Buffer
-  );
-
-EFI_STATUS
-NorFlashWriteBlocks (
-  IN  NOR_FLASH_INSTANCE  *Instance,
-  IN  EFI_LBA Lba,
-  IN  UINTN   BufferSizeInBytes,
-  IN  VOID*Buffer
-  );
-
-EFI_STATUS
-NorFlashReadBlocks (
-  IN NOR_FLASH_INSTANCE  *Instance,
-  IN EFI_LBA Lba,
-  IN UINTN   BufferSizeInBytes,
-  OUT VOID   *Buffer
-  );
-
-EFI_STATUS
-NorFlashRead (
-  IN NOR_FLASH_INSTANCE  *Instance,
-  IN EFI_LBA Lba,
-  IN UINTN   Offset,
-  IN UINTN   BufferSizeInBytes,
-  OUT VOID   *Buffer
-  );
-
-EFI_STATUS
-NorFlashReset (
-  IN  NOR_FLASH_INSTANCE  *Instance
-  );
-
-EFI_STATUS
-NorFlashEraseSingleBlock (
-  IN NOR_FLASH_INSTANCE  *Instance,
-  IN UINTN   BlockAddress
-  );
-
-EFI_STATUS
-NorFlashWriteFullBlock (
-  IN NOR_FLASH_INSTANCE  *Instance,
-  IN EFI_LBA Lba,
-  IN UINT32  *DataBuffer,
-  IN UINT32  BlockSizeInWords
-  );
-
-EFI_STATUS
-NorFlashUnlockAndEraseSingleBlock (
-  IN NOR_FLASH_INSTANCE  *Instance,
-  IN UINTN   BlockAddress
-  );
-
-VOID
-EFIAPI
-NorFlashLock (
-  IN EFI_TPL  *OriginalTPL
-  );
-
-VOID
-EFIAPI
-NorFlashUnlock (
-  IN EFI_TPL OriginalTPL
-  );
-
 #endif /* __NOR_FLASH_H__ */
diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h
index c0a3b5861532..7fcb949843e8 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h
@@ -19,6 +19,7 @@
 #include 
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff 

[edk2-devel] [edk2-platforms][PATCH V3 06/17] Platform/ARM/NorFlashDxe: Make local functions STATIC

2024-05-23 Thread Sahil Kaushal
From: sahil 

This patch makes local functions not being used outside
NorFlash.c STATIC.
Also, NorFlashWriteBuffer() is specific to a particular
flash implementation and need not be implemented by
other NOR flash device IPs.

Signed-off-by: sahil 
---
 Platform/ARM/Drivers/NorFlashDxe/NorFlash.h | 21 
 Platform/ARM/Drivers/NorFlashDxe/NorFlash.c |  3 +++
 2 files changed, 3 insertions(+), 21 deletions(-)

diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h
index 3102c5e13bad..f30d499042ed 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h
@@ -134,14 +134,6 @@ struct _NOR_FLASH_INSTANCE {
   NOR_FLASH_DEVICE_PATH  DevicePath;
 };
 
-EFI_STATUS
-NorFlashWriteBuffer (
-  IN NOR_FLASH_INSTANCE  *Instance,
-  IN UINTN   TargetAddress,
-  IN UINTN   BufferSizeInBytes,
-  IN UINT32  *Buffer
-  );
-
 //
 // NorFlash.c
 //
@@ -190,19 +182,6 @@ NorFlashEraseSingleBlock (
   IN UINTN   BlockAddress
   );
 
-EFI_STATUS
-NorFlashUnlockSingleBlockIfNecessary (
-  IN NOR_FLASH_INSTANCE  *Instance,
-  IN UINTN   BlockAddress
-  );
-
-EFI_STATUS
-NorFlashWriteSingleWord (
-  IN NOR_FLASH_INSTANCE  *Instance,
-  IN UINTN   WordAddress,
-  IN UINT32  WriteData
-  );
-
 EFI_STATUS
 NorFlashWriteFullBlock (
   IN NOR_FLASH_INSTANCE  *Instance,
diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c
index 15000a692b02..254b8937e210 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c
@@ -103,6 +103,7 @@ NorFlashUnlockSingleBlock (
   return EFI_SUCCESS;
 }
 
+STATIC
 EFI_STATUS
 NorFlashUnlockSingleBlockIfNecessary (
   IN NOR_FLASH_INSTANCE  *Instance,
@@ -175,6 +176,7 @@ NorFlashEraseSingleBlock (
   return Status;
 }
 
+STATIC
 EFI_STATUS
 NorFlashWriteSingleWord (
   IN NOR_FLASH_INSTANCE  *Instance,
@@ -245,6 +247,7 @@ NorFlashWriteSingleWord (
  * Therefore, it is a requirement to align buffer writes to 32-bit word 
boundaries.
  * i.e. the last 4 bits of the target start address must be zero: 0x..00
  */
+STATIC
 EFI_STATUS
 NorFlashWriteBuffer (
   IN NOR_FLASH_INSTANCE  *Instance,
-- 
2.25.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119148): https://edk2.groups.io/g/devel/message/119148
Mute This Topic: https://groups.io/mt/106260144/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [edk2-platforms][PATCH V3 05/17] Platform/ARM/NorFlashDxe: Remove unimplemented functions from NorFlash.h

2024-05-23 Thread Sahil Kaushal
From: sahil 

This patch removes NorFlashReadCfiData() and NorFlashWrite()
prototypes from NorFlash.h as these are not implemented or
used anywhere in NorFlashDxe driver.

Signed-off-by: sahil 
---
 Platform/ARM/Drivers/NorFlashDxe/NorFlash.h | 17 -
 1 file changed, 17 deletions(-)

diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h
index bd5c6a949cf0..3102c5e13bad 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h
@@ -134,14 +134,6 @@ struct _NOR_FLASH_INSTANCE {
   NOR_FLASH_DEVICE_PATH  DevicePath;
 };
 
-EFI_STATUS
-NorFlashReadCfiData (
-  IN  UINTN   DeviceBaseAddress,
-  IN  UINTN   CFI_Offset,
-  IN  UINT32  NumberOfBytes,
-  OUT UINT32  *Data
-  );
-
 EFI_STATUS
 NorFlashWriteBuffer (
   IN NOR_FLASH_INSTANCE  *Instance,
@@ -187,15 +179,6 @@ NorFlashRead (
   OUT VOID   *Buffer
   );
 
-EFI_STATUS
-NorFlashWrite (
-  INNOR_FLASH_INSTANCE  *Instance,
-  INEFI_LBA Lba,
-  INUINTN   Offset,
-  IN OUTUINTN   *NumBytes,
-  INUINT8   *Buffer
-  );
-
 EFI_STATUS
 NorFlashReset (
   IN  NOR_FLASH_INSTANCE  *Instance
-- 
2.25.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119147): https://edk2.groups.io/g/devel/message/119147
Mute This Topic: https://groups.io/mt/106260143/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [edk2-platforms][PATCH V3 04/17] Platform/ARM/NorFlashDxe: Move flash specific functions to NorFlash.c

2024-05-23 Thread Sahil Kaushal
From: sahil 

Refactoring done in this patch has two major parts:

1. Moving out NorFlashUnlockAndEraseSingleBlock and
NorFlashWriteFullBlock functions from NorFlashDxe.c and
NorFlashStandaloneMm.c to NorFlash.c files.

2. At the same time, we are adding NorFlashLock and NorFlashUnlock
functions which will take care of TPL related operations needed by
functions mentioned in point 1. These functions are implemented
in NorFlashDxe.c but are just dummy placeholder functions in
NorFlashStandaloneMm.c file.

Signed-off-by: sahil 
---
 Platform/ARM/Drivers/NorFlashDxe/NorFlash.h |  26 +++
 Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h   |  14 --
 Platform/ARM/Drivers/NorFlashDxe/NorFlash.c | 136 +-
 Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c  | 193 

 Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c | 151 +++
 5 files changed, 225 insertions(+), 295 deletions(-)

diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h
index e0ebb1e2fd35..bd5c6a949cf0 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h
@@ -220,4 +220,30 @@ NorFlashWriteSingleWord (
   IN UINT32  WriteData
   );
 
+EFI_STATUS
+NorFlashWriteFullBlock (
+  IN NOR_FLASH_INSTANCE  *Instance,
+  IN EFI_LBA Lba,
+  IN UINT32  *DataBuffer,
+  IN UINT32  BlockSizeInWords
+  );
+
+EFI_STATUS
+NorFlashUnlockAndEraseSingleBlock (
+  IN NOR_FLASH_INSTANCE  *Instance,
+  IN UINTN   BlockAddress
+  );
+
+VOID
+EFIAPI
+NorFlashLock (
+  IN EFI_TPL  *OriginalTPL
+  );
+
+VOID
+EFIAPI
+NorFlashUnlock (
+  IN EFI_TPL OriginalTPL
+  );
+
 #endif /* __NOR_FLASH_H__ */
diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h
index e329e0727617..c0a3b5861532 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h
@@ -31,20 +31,6 @@
 //
 // NorFlashDxe.c
 //
-EFI_STATUS
-NorFlashWriteFullBlock (
-  IN NOR_FLASH_INSTANCE  *Instance,
-  IN EFI_LBA Lba,
-  IN UINT32  *DataBuffer,
-  IN UINT32  BlockSizeInWords
-  );
-
-EFI_STATUS
-NorFlashUnlockAndEraseSingleBlock (
-  IN NOR_FLASH_INSTANCE  *Instance,
-  IN UINTN   BlockAddress
-  );
-
 EFI_STATUS
 NorFlashCreateInstance (
   IN UINTNNorFlashDeviceBase,
diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c
index 4e5a97c83c7b..15000a692b02 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c
@@ -10,7 +10,6 @@
 #include 
 
 #include "NorFlash.h"
-#include "NorFlashCommon.h"
 
 //
 // Global variable declarations
@@ -817,3 +816,138 @@ NorFlashReset (
   SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);
   return EFI_SUCCESS;
 }
+
+/**
+ * This function unlock and erase an entire NOR Flash block.
+**/
+EFI_STATUS
+NorFlashUnlockAndEraseSingleBlock (
+  IN NOR_FLASH_INSTANCE  *Instance,
+  IN UINTN   BlockAddress
+  )
+{
+  EFI_STATUS  Status;
+  UINTN   Index;
+  EFI_TPL OriginalTPL;
+
+  NorFlashLock ();
+
+  Index = 0;
+  // The block erase might fail a first time (SW bug ?). Retry it ...
+  do {
+// Unlock the block if we have to
+Status = NorFlashUnlockSingleBlockIfNecessary (Instance, BlockAddress);
+if (EFI_ERROR (Status)) {
+  break;
+}
+
+Status = NorFlashEraseSingleBlock (Instance, BlockAddress);
+Index++;
+  } while ((Index < NOR_FLASH_ERASE_RETRY) && (Status == EFI_WRITE_PROTECTED));
+
+  if (Index == NOR_FLASH_ERASE_RETRY) {
+DEBUG ((DEBUG_ERROR, "EraseSingleBlock(BlockAddress=0x%08x: Block Locked 
Error (try to erase %d times)\n", BlockAddress, Index));
+  }
+
+  NorFlashUnlock (OriginalTPL);
+
+  return Status;
+}
+
+EFI_STATUS
+NorFlashWriteFullBlock (
+  IN NOR_FLASH_INSTANCE  *Instance,
+  IN EFI_LBA Lba,
+  IN UINT32  *DataBuffer,
+  IN UINT32  BlockSizeInWords
+  )
+{
+  EFI_STATUS  Status;
+  UINTN   WordAddress;
+  UINT32  WordIndex;
+  UINTN   BufferIndex;
+  UINTN   BlockAddress;
+  UINTN   BuffersInBlock;
+  UINTN   RemainingWords;
+  EFI_TPL OriginalTPL;
+  UINTN   Cnt;
+
+  Status = EFI_SUCCESS;
+
+  // Get the physical address of the block
+  BlockAddress = GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress, Lba, 
BlockSizeInWords * 4);
+
+  // Start writing from the first address at the start of the block
+  WordAddress = BlockAddress;
+
+  NorFlashLock ();
+
+  Status = NorFlashUnlockAndEraseSingleBlock (Instance, BlockAddress);
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "WriteSingleBlock: ERROR - Failed to Unlock and Erase 
the single block at 0x%X\n", BlockAddress));
+goto EXIT;
+  }
+
+  // To speed up 

[edk2-devel] [edk2-platforms][PATCH V3 03/17] Platform/ARM/NorFlashDxe: Add NorFlashCommon.h header file

2024-05-23 Thread Sahil Kaushal
From: sahil 

This patch splits NorFlash.h and adds NorFlashCommon.h which
will have all the flash independent functions and macros.
Whereas all the flash specific functions will be in NorFlash.h
header file.

Signed-off-by: sahil 
---
 Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.inf  |   1 +
 Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.inf |   1 +
 Platform/ARM/Drivers/NorFlashDxe/NorFlash.h   | 199 
--
 Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h | 221 

 Platform/ARM/Drivers/NorFlashDxe/NorFlash.c   |   1 +
 Platform/ARM/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c |   1 +
 Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c|   1 +
 Platform/ARM/Drivers/NorFlashDxe/NorFlashFvb.c|   1 +
 Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c   |   1 +
 9 files changed, 228 insertions(+), 199 deletions(-)

diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.inf 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.inf
index cdf1f5c27f35..18e99bac 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.inf
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.inf
@@ -21,6 +21,7 @@
   NorFlash.h
   NorFlashBlockIoDxe.c
   NorFlashDxe.c
+  NorFlashCommon.h
   NorFlashFvb.c
 
 [Packages]
diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.inf 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.inf
index 001f281220f2..69c40ccf9c27 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.inf
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.inf
@@ -22,6 +22,7 @@
   NorFlash.c
   NorFlash.h
   NorFlashFvb.c
+  NorFlashCommon.h
   NorFlashStandaloneMm.c
 
 [Packages]
diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h 
b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h
index d4d97bd22cc5..e0ebb1e2fd35 100644
--- a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h
+++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h
@@ -20,9 +20,6 @@
 
 #include 
 #include 
-#include 
-#include 
-#include 
 
 #define NOR_FLASH_ERASE_RETRY  10
 
@@ -108,11 +105,6 @@
 #define P30_CMD_READ_CONFIGURATION_REGISTER_SETUP  0x0060
 #define P30_CMD_READ_CONFIGURATION_REGISTER0x0003
 
-#define NOR_FLASH_SIGNATURE  SIGNATURE_32('n', 'o', 'r', '0')
-#define INSTANCE_FROM_FVB_THIS(a) CR(a, NOR_FLASH_INSTANCE, FvbProtocol, 
NOR_FLASH_SIGNATURE)
-#define INSTANCE_FROM_BLKIO_THIS(a)   CR(a, NOR_FLASH_INSTANCE, 
BlockIoProtocol, NOR_FLASH_SIGNATURE)
-#define INSTANCE_FROM_DISKIO_THIS(a)  CR(a, NOR_FLASH_INSTANCE, 
DiskIoProtocol, NOR_FLASH_SIGNATURE)
-
 typedef struct _NOR_FLASH_INSTANCE NOR_FLASH_INSTANCE;
 
 #pragma pack (1)
@@ -158,197 +150,6 @@ NorFlashWriteBuffer (
   IN UINT32  *Buffer
   );
 
-//
-// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.Reset
-//
-EFI_STATUS
-EFIAPI
-NorFlashBlockIoReset (
-  IN EFI_BLOCK_IO_PROTOCOL  *This,
-  IN BOOLEANExtendedVerification
-  );
-
-//
-// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.ReadBlocks
-//
-EFI_STATUS
-EFIAPI
-NorFlashBlockIoReadBlocks (
-  IN  EFI_BLOCK_IO_PROTOCOL  *This,
-  IN  UINT32 MediaId,
-  IN  EFI_LBALba,
-  IN  UINTN  BufferSizeInBytes,
-  OUT VOID   *Buffer
-  );
-
-//
-// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks
-//
-EFI_STATUS
-EFIAPI
-NorFlashBlockIoWriteBlocks (
-  IN  EFI_BLOCK_IO_PROTOCOL  *This,
-  IN  UINT32 MediaId,
-  IN  EFI_LBALba,
-  IN  UINTN  BufferSizeInBytes,
-  IN  VOID   *Buffer
-  );
-
-//
-// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks
-//
-EFI_STATUS
-EFIAPI
-NorFlashBlockIoFlushBlocks (
-  IN EFI_BLOCK_IO_PROTOCOL  *This
-  );
-
-//
-// DiskIO Protocol function EFI_DISK_IO_PROTOCOL.ReadDisk
-//
-EFI_STATUS
-EFIAPI
-NorFlashDiskIoReadDisk (
-  IN EFI_DISK_IO_PROTOCOL  *This,
-  IN UINT32MediaId,
-  IN UINT64Offset,
-  IN UINTN BufferSize,
-  OUT VOID *Buffer
-  );
-
-//
-// DiskIO Protocol function EFI_DISK_IO_PROTOCOL.WriteDisk
-//
-EFI_STATUS
-EFIAPI
-NorFlashDiskIoWriteDisk (
-  IN EFI_DISK_IO_PROTOCOL  *This,
-  IN UINT32MediaId,
-  IN UINT64Offset,
-  IN UINTN BufferSize,
-  IN VOID  *Buffer
-  );
-
-//
-// NorFlashFvbDxe.c
-//
-
-EFI_STATUS
-EFIAPI
-FvbGetAttributes (
-  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL  *This,
-  OUT   EFI_FVB_ATTRIBUTES_2 *Attributes
-  );
-
-EFI_STATUS
-EFIAPI
-FvbSetAttributes (
-  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL  *This,
-  IN OUTEFI_FVB_ATTRIBUTES_2 *Attributes
-  );
-
-EFI_STATUS
-EFIAPI
-FvbGetPhysicalAddress (
-  IN CONST  EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL  *This,
-  OUT   EFI_PHYSICAL_ADDRESS *Address
-  );
-
-EFI_STATUS
-EFIAPI
-FvbGetBlockSize (
-  IN CONST  

  1   2   >