]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h
MdeModulePkg Variable: Add emulated variable NV mode support
[mirror_edk2.git] / MdeModulePkg / Universal / Variable / RuntimeDxe / Variable.h
index 9928837fd834523b47e83213a7069897925b1161..7a3a5f34deab49838121ba2d0d159c763c75325c 100644 (file)
@@ -2,7 +2,7 @@
   The internal header file includes the common header files, defines\r
   internal structure and functions used by Variable modules.\r
 \r
-Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -36,20 +36,25 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/SynchronizationLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/AuthVariableLib.h>\r
+#include <Library/VarCheckLib.h>\r
 #include <Guid/GlobalVariable.h>\r
 #include <Guid/EventGroup.h>\r
 #include <Guid/VariableFormat.h>\r
-#include <Guid/ImageAuthentication.h>\r
 #include <Guid/SystemNvDataGuid.h>\r
 #include <Guid/FaultTolerantWrite.h>\r
-#include <Guid/HardwareErrorVariable.h>\r
 #include <Guid/VarErrorFlag.h>\r
 \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
                                       EFI_VARIABLE_HARDWARE_ERROR_RECORD | \\r
-                                      EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \\r
                                       EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \\r
                                       EFI_VARIABLE_APPEND_WRITE)\r
 \r
@@ -87,6 +92,7 @@ typedef struct {
   UINT32                ReentrantState;\r
   BOOLEAN               AuthFormat;\r
   BOOLEAN               AuthSupport;\r
+  BOOLEAN               EmuNvMode;\r
 } VARIABLE_GLOBAL;\r
 \r
 typedef struct {\r
@@ -101,6 +107,7 @@ typedef struct {
   UINTN           HwErrVariableTotalSize;\r
   UINTN           MaxVariableSize;\r
   UINTN           MaxAuthVariableSize;\r
+  UINTN           MaxVolatileVariableSize;\r
   UINTN           ScratchBufferSize;\r
   CHAR8           *PlatformLangCodes;\r
   CHAR8           *LangCodes;\r
@@ -109,12 +116,6 @@ typedef struct {
   EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbInstance;\r
 } VARIABLE_MODULE_GLOBAL;\r
 \r
-typedef struct {\r
-  LIST_ENTRY  Link;\r
-  EFI_GUID    Guid;\r
-  //CHAR16      *Name;\r
-} VARIABLE_ENTRY;\r
-\r
 /**\r
   Flush the HOB variable to flash.\r
 \r
@@ -396,7 +397,7 @@ ReleaseLockOnlyAtBootTime (
   );\r
 \r
 /**\r
-  Retrive the FVB protocol interface by HANDLE.\r
+  Retrieve the FVB protocol interface by HANDLE.\r
 \r
   @param[in]  FvBlockHandle     The handle of FVB protocol that provides services for\r
                                 reading, writing, and erasing the target block.\r
@@ -467,7 +468,18 @@ GetNonVolatileMaxVariableSize (
   );\r
 \r
 /**\r
-  Initializes variable write service after FVB was ready.\r
+  Get maximum variable size, covering both non-volatile and volatile variables.\r
+\r
+  @return Maximum variable size.\r
+\r
+**/\r
+UINTN\r
+GetMaxVariableSize (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Initializes variable write service.\r
 \r
   @retval EFI_SUCCESS          Function successfully executed.\r
   @retval Others               Fail to initialize the variable service.\r
@@ -479,7 +491,7 @@ VariableWriteServiceInitialize (
   );\r
 \r
 /**\r
-  Retrive the SMM Fault Tolerent Write protocol interface.\r
+  Retrieve the SMM Fault Tolerent Write protocol interface.\r
 \r
   @param[out] FtwProtocol       The interface of SMM Ftw protocol\r
 \r
@@ -521,7 +533,8 @@ GetFvbInfoByAddress (
   @param Attributes                 Attribute value of the variable found.\r
   @param DataSize                   Size of Data found. If size is less than the\r
                                     data, this value contains the required size.\r
-  @param Data                       Data pointer.\r
+  @param Data                       The buffer to return the contents of the variable. May be NULL\r
+                                    with a zero DataSize in order to determine the size buffer needed.\r
 \r
   @return EFI_INVALID_PARAMETER     Invalid parameter.\r
   @return EFI_SUCCESS               Find the specified variable.\r
@@ -536,7 +549,7 @@ VariableServiceGetVariable (
   IN      EFI_GUID          *VendorGuid,\r
   OUT     UINT32            *Attributes OPTIONAL,\r
   IN OUT  UINTN             *DataSize,\r
-  OUT     VOID              *Data\r
+  OUT     VOID              *Data OPTIONAL\r
   );\r
 \r
 /**\r
@@ -549,8 +562,11 @@ VariableServiceGetVariable (
   @param[in] VendorGuid     Variable Vendor Guid.\r
   @param[out] VariablePtr   Pointer to variable header address.\r
 \r
-  @return EFI_SUCCESS       Find the specified variable.\r
-  @return EFI_NOT_FOUND     Not found.\r
+  @retval EFI_SUCCESS           The function completed successfully.\r
+  @retval EFI_NOT_FOUND         The next variable was not found.\r
+  @retval EFI_INVALID_PARAMETER If VariableName is not an empty string, while VendorGuid is NULL.\r
+  @retval EFI_INVALID_PARAMETER The input values of VariableName and VendorGuid are not a name and\r
+                                GUID of an existing variable.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -568,14 +584,22 @@ VariableServiceGetNextVariableInternal (
   Caution: This function may receive untrusted input.\r
   This function may be invoked in SMM mode. This function will do basic validation, before parse the data.\r
 \r
-  @param VariableNameSize           Size of the variable name.\r
+  @param VariableNameSize           The size of the VariableName buffer. The size must be large\r
+                                    enough to fit input string supplied in VariableName buffer.\r
   @param VariableName               Pointer to variable name.\r
   @param VendorGuid                 Variable Vendor Guid.\r
 \r
-  @return EFI_INVALID_PARAMETER     Invalid parameter.\r
-  @return EFI_SUCCESS               Find the specified variable.\r
-  @return EFI_NOT_FOUND             Not found.\r
-  @return EFI_BUFFER_TO_SMALL       DataSize is too small for the result.\r
+  @retval EFI_SUCCESS               The function completed successfully.\r
+  @retval EFI_NOT_FOUND             The next variable was not found.\r
+  @retval EFI_BUFFER_TOO_SMALL      The VariableNameSize is too small for the result.\r
+                                    VariableNameSize has been updated with the size needed to complete the request.\r
+  @retval EFI_INVALID_PARAMETER     VariableNameSize is NULL.\r
+  @retval EFI_INVALID_PARAMETER     VariableName is NULL.\r
+  @retval EFI_INVALID_PARAMETER     VendorGuid is NULL.\r
+  @retval EFI_INVALID_PARAMETER     The input values of VariableName and VendorGuid are not a name and\r
+                                    GUID of an existing variable.\r
+  @retval EFI_INVALID_PARAMETER     Null-terminator is not found in the first VariableNameSize bytes of\r
+                                    the input VariableName buffer.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -702,53 +726,6 @@ VariableLockRequestToLock (
   IN       EFI_GUID                     *VendorGuid\r
   );\r
 \r
-/**\r
-  Check if a Unicode character is a hexadecimal character.\r
-\r
-  This function checks if a Unicode character is a\r
-  hexadecimal character.  The valid hexadecimal character is\r
-  L'0' to L'9', L'a' to L'f', or L'A' to L'F'.\r
-\r
-\r
-  @param Char           The character to check against.\r
-\r
-  @retval TRUE          If the Char is a hexadecmial character.\r
-  @retval FALSE         If the Char is not a hexadecmial character.\r
-\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-IsHexaDecimalDigitCharacter (\r
-  IN CHAR16             Char\r
-  );\r
-\r
-/**\r
-  Internal SetVariable check.\r
-\r
-  @param[in] VariableName       Name of Variable to set.\r
-  @param[in] VendorGuid         Variable vendor GUID.\r
-  @param[in] Attributes         Attribute value of the variable.\r
-  @param[in] DataSize           Size of Data to set.\r
-  @param[in] Data               Data pointer.\r
-\r
-  @retval EFI_SUCCESS           The SetVariable check result was success.\r
-  @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits, name, and GUID were supplied,\r
-                                or the DataSize exceeds the minimum or maximum allowed,\r
-                                or the Data value is not following UEFI spec for UEFI defined variables.\r
-  @retval EFI_WRITE_PROTECTED   The variable in question is read-only.\r
-  @retval Others                The return status from check handler.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-InternalVarCheckSetVariableCheck (\r
-  IN CHAR16     *VariableName,\r
-  IN EFI_GUID   *VendorGuid,\r
-  IN UINT32     Attributes,\r
-  IN UINTN      DataSize,\r
-  IN VOID       *Data\r
-  );\r
-\r
 /**\r
   Register SetVariable check handler.\r
 \r
@@ -769,45 +746,6 @@ VarCheckRegisterSetVariableCheckHandler (
   IN VAR_CHECK_SET_VARIABLE_CHECK_HANDLER   Handler\r
   );\r
 \r
-/**\r
-  Internal variable property get.\r
-\r
-  @param[in]  Name              Pointer to the variable name.\r
-  @param[in]  Guid              Pointer to the vendor GUID.\r
-  @param[out] VariableProperty  Pointer to the output variable property.\r
-\r
-  @retval EFI_SUCCESS           The property of variable specified by the Name and Guid was got successfully.\r
-  @retval EFI_NOT_FOUND         The property of variable specified by the Name and Guid was not found.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-InternalVarCheckVariablePropertyGet (\r
-  IN CHAR16                         *Name,\r
-  IN EFI_GUID                       *Guid,\r
-  OUT VAR_CHECK_VARIABLE_PROPERTY   *VariableProperty\r
-  );\r
-\r
-/**\r
-  Internal variable property set.\r
-\r
-  @param[in] Name               Pointer to the variable name.\r
-  @param[in] Guid               Pointer to the vendor GUID.\r
-  @param[in] VariableProperty   Pointer to the input variable property.\r
-\r
-  @retval EFI_SUCCESS           The property of variable specified by the Name and Guid was set successfully.\r
-  @retval EFI_OUT_OF_RESOURCES  There is not enough resource for the variable property set request.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-InternalVarCheckVariablePropertySet (\r
-  IN CHAR16                         *Name,\r
-  IN EFI_GUID                       *Guid,\r
-  IN VAR_CHECK_VARIABLE_PROPERTY    *VariableProperty\r
-  );\r
-\r
-\r
 /**\r
   Variable property set.\r
 \r
@@ -860,9 +798,14 @@ InitializeVariableQuota (
   VOID\r
   );\r
 \r
-extern VARIABLE_MODULE_GLOBAL  *mVariableModuleGlobal;\r
+extern VARIABLE_MODULE_GLOBAL       *mVariableModuleGlobal;\r
+extern EFI_FIRMWARE_VOLUME_HEADER   *mNvFvHeaderCache;\r
+extern VARIABLE_STORE_HEADER        *mNvVariableCache;\r
+extern VARIABLE_INFO_ENTRY          *gVariableInfo;\r
+extern BOOLEAN                      mEndOfDxe;\r
+extern VAR_CHECK_REQUEST_SOURCE     mRequestSource;\r
 \r
-extern AUTH_VAR_LIB_CONTEXT_OUT mContextOut;\r
+extern AUTH_VAR_LIB_CONTEXT_OUT     mAuthContextOut;\r
 \r
 /**\r
   Finds variable in storage blocks of volatile and non-volatile storage areas.\r