]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/VariableFlashInfoLib: Add initial library
authorMichael Kubacki <michael.kubacki@microsoft.com>
Fri, 8 Apr 2022 15:53:29 +0000 (11:53 -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

Adds a new library class VariableFlashInfoLib that abstracts access
to variable flash information. The instance provided first attempts
to retrieve information from the Variable Flash Info HOB. If that
HOB is not present, it falls back to the PCDs defined in
MdeModulePkg.

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

Cc: Jian J Wang <jian.j.wang@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/Include/Library/VariableFlashInfoLib.h [new file with mode: 0644]
MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.c [new file with mode: 0644]
MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf [new file with mode: 0644]
MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.uni [new file with mode: 0644]
MdeModulePkg/MdeModulePkg.dec
MdeModulePkg/MdeModulePkg.dsc

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