]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/Variable: Consume Variable Flash Info
authorMichael Kubacki <michael.kubacki@microsoft.com>
Wed, 6 Apr 2022 01:34:51 +0000 (21:34 -0400)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 19 May 2022 06:11:20 +0000 (06:11 +0000)
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3479

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

Note: This introduces a dependency on VariableFlashInfoLib in these
modules. Therefore, a platform building the variable modules must
specify an instance of VariableFlashInfoLib in their platform build.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
MdeModulePkg/Universal/Variable/Pei/Variable.c
MdeModulePkg/Universal/Variable/Pei/Variable.h
MdeModulePkg/Universal/Variable/Pei/VariablePei.inf
MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf

index b36dd0de67b294a4abf88c7f620886ca5cb74b0d..26a4c73b45a5995dc233e593a83d034e67ffee82 100644 (file)
@@ -567,11 +567,13 @@ GetVariableStore (
   OUT VARIABLE_STORE_INFO  *StoreInfo\r
   )\r
 {\r
+  EFI_STATUS                            Status;\r
   EFI_HOB_GUID_TYPE                     *GuidHob;\r
   EFI_FIRMWARE_VOLUME_HEADER            *FvHeader;\r
   VARIABLE_STORE_HEADER                 *VariableStoreHeader;\r
   EFI_PHYSICAL_ADDRESS                  NvStorageBase;\r
   UINT32                                NvStorageSize;\r
+  UINT64                                NvStorageSize64;\r
   FAULT_TOLERANT_WRITE_LAST_WRITE_DATA  *FtwLastWriteData;\r
   UINT32                                BackUpOffset;\r
 \r
@@ -591,11 +593,13 @@ GetVariableStore (
         // Emulated non-volatile variable mode is not enabled.\r
         //\r
 \r
-        NvStorageSize = PcdGet32 (PcdFlashNvStorageVariableSize);\r
-        NvStorageBase = (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvStorageVariableBase64) != 0 ?\r
-                                               PcdGet64 (PcdFlashNvStorageVariableBase64) :\r
-                                               PcdGet32 (PcdFlashNvStorageVariableBase)\r
-                                               );\r
+        Status = GetVariableFlashNvStorageInfo (&NvStorageBase, &NvStorageSize64);\r
+        ASSERT_EFI_ERROR (Status);\r
+\r
+        Status = SafeUint64ToUint32 (NvStorageSize64, &NvStorageSize);\r
+        // This driver currently assumes the size will be UINT32 so assert the value is safe for now.\r
+        ASSERT_EFI_ERROR (Status);\r
+\r
         ASSERT (NvStorageBase != 0);\r
 \r
         //\r
index 7f9ad5bfc357d61147a50f5cba516d59aa11a483..51effbf7998791c16a9cf5d0894c66f09402d132 100644 (file)
@@ -20,6 +20,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/PeiServicesTablePointerLib.h>\r
 #include <Library/PeiServicesLib.h>\r
+#include <Library/SafeIntLib.h>\r
+#include <Library/VariableFlashInfoLib.h>\r
 \r
 #include <Guid/VariableFormat.h>\r
 #include <Guid/VariableIndexTable.h>\r
index 7cbdd2385e8f6450e3423bb79da2e0f00a6c121d..7264a24bdf718ad87bf198d019ad4c5fdb6b875c 100644 (file)
@@ -39,6 +39,8 @@
   DebugLib\r
   PeiServicesTablePointerLib\r
   PeiServicesLib\r
+  SafeIntLib\r
+  VariableFlashInfoLib\r
 \r
 [Guids]\r
   ## CONSUMES             ## GUID # Variable store header\r
@@ -59,9 +61,6 @@
   gEfiPeiReadOnlyVariable2PpiGuid   ## PRODUCES\r
 \r
 [Pcd]\r
-  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase      ## SOMETIMES_CONSUMES\r
-  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64    ## CONSUMES\r
-  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize      ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvModeEnable         ## SOMETIMES_CONSUMES\r
 \r
 [Depex]\r
index 31e408976a3502a38dfabe4451d0f41479dfbbca..a668abb82b1556c5a3bdef77b18c82d3eb86ce6d 100644 (file)
@@ -31,6 +31,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/AuthVariableLib.h>\r
 #include <Library/VarCheckLib.h>\r
+#include <Library/VariableFlashInfoLib.h>\r
+#include <Library/SafeIntLib.h>\r
 #include <Guid/GlobalVariable.h>\r
 #include <Guid/EventGroup.h>\r
 #include <Guid/VariableFormat.h>\r
@@ -40,11 +42,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 \r
 #include "PrivilegePolymorphic.h"\r
 \r
-#define NV_STORAGE_VARIABLE_BASE  (EFI_PHYSICAL_ADDRESS)\\r
-                                   (PcdGet64 (PcdFlashNvStorageVariableBase64) != 0 ? \\r
-                                    PcdGet64 (PcdFlashNvStorageVariableBase64) : \\r
-                                    PcdGet32 (PcdFlashNvStorageVariableBase))\r
-\r
 #define EFI_VARIABLE_ATTRIBUTES_MASK  (EFI_VARIABLE_NON_VOLATILE |\\r
                                       EFI_VARIABLE_BOOTSERVICE_ACCESS | \\r
                                       EFI_VARIABLE_RUNTIME_ACCESS | \\r
index 03fec3048dc46c60ff1d03a96bdf33223d24a88f..d5c409c914d151442b03edcb0f6141a5552b4f08 100644 (file)
@@ -423,6 +423,8 @@ FtwNotificationEvent (
   EFI_PHYSICAL_ADDRESS                VariableStoreBase;\r
   UINT64                              VariableStoreLength;\r
   UINTN                               FtwMaxBlockSize;\r
+  UINT32                              NvStorageVariableSize;\r
+  UINT64                              NvStorageVariableSize64;\r
 \r
   //\r
   // Ensure FTW protocol is installed.\r
@@ -432,14 +434,20 @@ FtwNotificationEvent (
     return;\r
   }\r
 \r
+  Status = GetVariableFlashNvStorageInfo (&NvStorageVariableBase, &NvStorageVariableSize64);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = SafeUint64ToUint32 (NvStorageVariableSize64, &NvStorageVariableSize);\r
+  // This driver currently assumes the size will be UINT32 so assert the value is safe for now.\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength;\r
+\r
   Status = FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize);\r
   if (!EFI_ERROR (Status)) {\r
-    ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <= FtwMaxBlockSize);\r
+    ASSERT (NvStorageVariableSize <= FtwMaxBlockSize);\r
   }\r
 \r
-  NvStorageVariableBase = NV_STORAGE_VARIABLE_BASE;\r
-  VariableStoreBase     = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength;\r
-\r
   //\r
   // Let NonVolatileVariableBase point to flash variable store base directly after FTW ready.\r
   //\r
index 5e9d40b67ac29f364c9927bda2efbecf38c4a728..9e2d8fe0fe0cc1ccd2608775c6bbadaf1abf484d 100644 (file)
@@ -142,6 +142,7 @@ InitRealNonVolatileVariableStore (
   EFI_PHYSICAL_ADDRESS                  NvStorageBase;\r
   UINT8                                 *NvStorageData;\r
   UINT32                                NvStorageSize;\r
+  UINT64                                NvStorageSize64;\r
   FAULT_TOLERANT_WRITE_LAST_WRITE_DATA  *FtwLastWriteData;\r
   UINT32                                BackUpOffset;\r
   UINT32                                BackUpSize;\r
@@ -153,19 +154,24 @@ InitRealNonVolatileVariableStore (
 \r
   mVariableModuleGlobal->FvbInstance = NULL;\r
 \r
+  Status = GetVariableFlashNvStorageInfo (&NvStorageBase, &NvStorageSize64);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = SafeUint64ToUint32 (NvStorageSize64, &NvStorageSize);\r
+  // This driver currently assumes the size will be UINT32 so assert the value is safe for now.\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  ASSERT (NvStorageBase != 0);\r
+\r
   //\r
   // Allocate runtime memory used for a memory copy of the FLASH region.\r
   // Keep the memory and the FLASH in sync as updates occur.\r
   //\r
-  NvStorageSize = PcdGet32 (PcdFlashNvStorageVariableSize);\r
   NvStorageData = AllocateRuntimeZeroPool (NvStorageSize);\r
   if (NvStorageData == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  NvStorageBase = NV_STORAGE_VARIABLE_BASE;\r
-  ASSERT (NvStorageBase != 0);\r
-\r
   //\r
   // Copy NV storage data to the memory buffer.\r
   //\r
index c9434df631ee8b0e6a93a6583fb8cbbd7dfd8198..3858adf6739d3aba37f94da5090a3f0c04894bf7 100644 (file)
   TpmMeasurementLib\r
   AuthVariableLib\r
   VarCheckLib\r
+  VariableFlashInfoLib\r
   VariablePolicyLib\r
   VariablePolicyHelperLib\r
+  SafeIntLib\r
 \r
 [Protocols]\r
   gEfiFirmwareVolumeBlockProtocolGuid           ## CONSUMES\r
   gEfiImageSecurityDatabaseGuid\r
 \r
 [Pcd]\r
-  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize      ## CONSUMES\r
-  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase      ## SOMETIMES_CONSUMES\r
-  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64    ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize                 ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize             ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize         ## CONSUMES\r
index 517cae7b00f8e256adcbc80a5e37e10acab254f7..5253c328dcd9214ddac4b017f318be2c1be6c038 100644 (file)
@@ -1084,6 +1084,8 @@ SmmFtwNotificationEvent (
   EFI_SMM_FAULT_TOLERANT_WRITE_PROTOCOL   *FtwProtocol;\r
   EFI_PHYSICAL_ADDRESS                    NvStorageVariableBase;\r
   UINTN                                   FtwMaxBlockSize;\r
+  UINT32                                  NvStorageVariableSize;\r
+  UINT64                                  NvStorageVariableSize64;\r
 \r
   if (mVariableModuleGlobal->FvbInstance != NULL) {\r
     return EFI_SUCCESS;\r
@@ -1097,14 +1099,21 @@ SmmFtwNotificationEvent (
     return Status;\r
   }\r
 \r
+  Status = GetVariableFlashNvStorageInfo (&NvStorageVariableBase, &NvStorageVariableSize64);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = SafeUint64ToUint32 (NvStorageVariableSize64, &NvStorageVariableSize);\r
+  // This driver currently assumes the size will be UINT32 so assert the value is safe for now.\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  ASSERT (NvStorageVariableBase != 0);\r
+  VariableStoreBase = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength;\r
+\r
   Status = FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize);\r
   if (!EFI_ERROR (Status)) {\r
-    ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <= FtwMaxBlockSize);\r
+    ASSERT (NvStorageVariableSize <= FtwMaxBlockSize);\r
   }\r
 \r
-  NvStorageVariableBase = NV_STORAGE_VARIABLE_BASE;\r
-  VariableStoreBase     = NvStorageVariableBase + mNvFvHeaderCache->HeaderLength;\r
-\r
   //\r
   // Let NonVolatileVariableBase point to flash variable store base directly after FTW ready.\r
   //\r
index eaa97a01c6e5c5b7922c50d886e56375cbd65ec7..8c552b87e080604ecc98b6a28ca7458921d09259 100644 (file)
   AuthVariableLib\r
   VarCheckLib\r
   UefiBootServicesTableLib\r
+  VariableFlashInfoLib\r
   VariablePolicyLib\r
   VariablePolicyHelperLib\r
+  SafeIntLib\r
 \r
 [Protocols]\r
   gEfiSmmFirmwareVolumeBlockProtocolGuid        ## CONSUMES\r
   gEdkiiVarErrorFlagGuid\r
 \r
 [Pcd]\r
-  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize       ## CONSUMES\r
-  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase       ## SOMETIMES_CONSUMES\r
-  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64     ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize                  ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize              ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize          ## CONSUMES\r
index d8c4f77e7f1fdf5c235bf8b6abec496c25d95881..f09bed40cf517d2f95829ddd03693224775b4780 100644 (file)
   HobLib\r
   MemoryAllocationLib\r
   MmServicesTableLib\r
+  SafeIntLib\r
   StandaloneMmDriverEntryPoint\r
   SynchronizationLib\r
   VarCheckLib\r
+  VariableFlashInfoLib\r
   VariablePolicyLib\r
   VariablePolicyHelperLib\r
 \r
   gEdkiiVarErrorFlagGuid\r
 \r
 [Pcd]\r
-  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase       ## SOMETIMES_CONSUMES\r
-  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64     ## CONSUMES\r
-  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize       ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize                  ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize              ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize          ## CONSUMES\r