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
-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
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
#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
#include <Guid/FaultTolerantWrite.h>\r
#include <Guid/VarErrorFlag.h>\r
\r
-#define EFI_VARIABLE_ATTRIBUTES_MASK (EFI_VARIABLE_NON_VOLATILE | \\r
+#include "PrivilegePolymorphic.h"\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
///\r
/// The size of a 3 character ISO639 language code.\r
///\r
-#define ISO_639_2_ENTRY_SIZE 3\r
+#define ISO_639_2_ENTRY_SIZE 3\r
\r
typedef enum {\r
VariableStoreTypeVolatile,\r
} VARIABLE_STORE_TYPE;\r
\r
typedef struct {\r
- VARIABLE_HEADER *CurrPtr;\r
+ UINT32 PendingUpdateOffset;\r
+ UINT32 PendingUpdateLength;\r
+ VARIABLE_STORE_HEADER *Store;\r
+} VARIABLE_RUNTIME_CACHE;\r
+\r
+typedef struct {\r
+ BOOLEAN *ReadLock;\r
+ BOOLEAN *PendingUpdate;\r
+ BOOLEAN *HobFlushComplete;\r
+ VARIABLE_RUNTIME_CACHE VariableRuntimeHobCache;\r
+ VARIABLE_RUNTIME_CACHE VariableRuntimeNvCache;\r
+ VARIABLE_RUNTIME_CACHE VariableRuntimeVolatileCache;\r
+} VARIABLE_RUNTIME_CACHE_CONTEXT;\r
+\r
+typedef struct {\r
+ VARIABLE_HEADER *CurrPtr;\r
//\r
// If both ADDED and IN_DELETED_TRANSITION variable are present,\r
// InDeletedTransitionPtr will point to the IN_DELETED_TRANSITION one.\r
// Otherwise, CurrPtr will point to the ADDED or IN_DELETED_TRANSITION one,\r
// and InDeletedTransitionPtr will be NULL at the same time.\r
//\r
- VARIABLE_HEADER *InDeletedTransitionPtr;\r
- VARIABLE_HEADER *EndPtr;\r
- VARIABLE_HEADER *StartPtr;\r
- BOOLEAN Volatile;\r
+ VARIABLE_HEADER *InDeletedTransitionPtr;\r
+ VARIABLE_HEADER *EndPtr;\r
+ VARIABLE_HEADER *StartPtr;\r
+ BOOLEAN Volatile;\r
} VARIABLE_POINTER_TRACK;\r
\r
typedef struct {\r
- EFI_PHYSICAL_ADDRESS HobVariableBase;\r
- EFI_PHYSICAL_ADDRESS VolatileVariableBase;\r
- EFI_PHYSICAL_ADDRESS NonVolatileVariableBase;\r
- EFI_LOCK VariableServicesLock;\r
- UINT32 ReentrantState;\r
- BOOLEAN AuthFormat;\r
- BOOLEAN AuthSupport;\r
+ EFI_PHYSICAL_ADDRESS HobVariableBase;\r
+ EFI_PHYSICAL_ADDRESS VolatileVariableBase;\r
+ EFI_PHYSICAL_ADDRESS NonVolatileVariableBase;\r
+ VARIABLE_RUNTIME_CACHE_CONTEXT VariableRuntimeCacheContext;\r
+ EFI_LOCK VariableServicesLock;\r
+ UINT32 ReentrantState;\r
+ BOOLEAN AuthFormat;\r
+ BOOLEAN AuthSupport;\r
+ BOOLEAN EmuNvMode;\r
} VARIABLE_GLOBAL;\r
\r
typedef struct {\r
- VARIABLE_GLOBAL VariableGlobal;\r
- UINTN VolatileLastVariableOffset;\r
- UINTN NonVolatileLastVariableOffset;\r
- UINTN CommonVariableSpace;\r
- UINTN CommonMaxUserVariableSpace;\r
- UINTN CommonRuntimeVariableSpace;\r
- UINTN CommonVariableTotalSize;\r
- UINTN CommonUserVariableTotalSize;\r
- UINTN HwErrVariableTotalSize;\r
- UINTN MaxVariableSize;\r
- UINTN MaxAuthVariableSize;\r
- UINTN ScratchBufferSize;\r
- CHAR8 *PlatformLangCodes;\r
- CHAR8 *LangCodes;\r
- CHAR8 *PlatformLang;\r
- CHAR8 Lang[ISO_639_2_ENTRY_SIZE + 1];\r
- EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbInstance;\r
+ VARIABLE_GLOBAL VariableGlobal;\r
+ UINTN VolatileLastVariableOffset;\r
+ UINTN NonVolatileLastVariableOffset;\r
+ UINTN CommonVariableSpace;\r
+ UINTN CommonMaxUserVariableSpace;\r
+ UINTN CommonRuntimeVariableSpace;\r
+ UINTN CommonVariableTotalSize;\r
+ UINTN CommonUserVariableTotalSize;\r
+ UINTN HwErrVariableTotalSize;\r
+ UINTN MaxVariableSize;\r
+ UINTN MaxAuthVariableSize;\r
+ UINTN MaxVolatileVariableSize;\r
+ UINTN ScratchBufferSize;\r
+ CHAR8 *PlatformLangCodes;\r
+ CHAR8 *LangCodes;\r
+ CHAR8 *PlatformLang;\r
+ CHAR8 Lang[ISO_639_2_ENTRY_SIZE + 1];\r
+ EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbInstance;\r
} VARIABLE_MODULE_GLOBAL;\r
\r
/**\r
**/\r
VOID\r
FlushHobVariableToFlash (\r
- IN CHAR16 *VariableName,\r
- IN EFI_GUID *VendorGuid\r
+ IN CHAR16 *VariableName,\r
+ IN EFI_GUID *VendorGuid\r
);\r
\r
/**\r
IN BOOLEAN IgnoreRtCheck\r
);\r
\r
-/**\r
-\r
- Gets the pointer to the end of the variable storage area.\r
-\r
- This function gets pointer to the end of the variable storage\r
- area, according to the input variable store header.\r
-\r
- @param VarStoreHeader Pointer to the Variable Store Header.\r
-\r
- @return Pointer to the end of the variable storage area.\r
-\r
-**/\r
-VARIABLE_HEADER *\r
-GetEndPointer (\r
- IN VARIABLE_STORE_HEADER *VarStoreHeader\r
- );\r
-\r
-/**\r
- This code gets the size of variable header.\r
-\r
- @return Size of variable header in bytes in type UINTN.\r
-\r
-**/\r
-UINTN\r
-GetVariableHeaderSize (\r
- VOID\r
- );\r
-\r
-/**\r
-\r
- This code gets the pointer to the variable name.\r
-\r
- @param Variable Pointer to the Variable Header.\r
-\r
- @return Pointer to Variable Name which is Unicode encoding.\r
-\r
-**/\r
-CHAR16 *\r
-GetVariableNamePtr (\r
- IN VARIABLE_HEADER *Variable\r
- );\r
-\r
-/**\r
- This code gets the pointer to the variable guid.\r
-\r
- @param Variable Pointer to the Variable Header.\r
-\r
- @return A EFI_GUID* pointer to Vendor Guid.\r
-\r
-**/\r
-EFI_GUID *\r
-GetVendorGuidPtr (\r
- IN VARIABLE_HEADER *Variable\r
- );\r
-\r
-/**\r
-\r
- This code gets the pointer to the variable data.\r
-\r
- @param Variable Pointer to the Variable Header.\r
-\r
- @return Pointer to Variable Data.\r
-\r
-**/\r
-UINT8 *\r
-GetVariableDataPtr (\r
- IN VARIABLE_HEADER *Variable\r
- );\r
-\r
-/**\r
-\r
- This code gets the size of variable data.\r
-\r
- @param Variable Pointer to the Variable Header.\r
-\r
- @return Size of variable in bytes.\r
-\r
-**/\r
-UINTN\r
-DataSizeOfVariable (\r
- IN VARIABLE_HEADER *Variable\r
- );\r
-\r
/**\r
This function is to check if the remaining variable space is enough to set\r
all Variables from argument list successfully. The purpose of the check\r
BOOLEAN\r
EFIAPI\r
CheckRemainingSpaceForConsistencyInternal (\r
- IN UINT32 Attributes,\r
- IN VA_LIST Marker\r
+ IN UINT32 Attributes,\r
+ IN VA_LIST Marker\r
);\r
\r
/**\r
**/\r
EFI_STATUS\r
UpdateVariable (\r
- IN CHAR16 *VariableName,\r
- IN EFI_GUID *VendorGuid,\r
- IN VOID *Data,\r
- IN UINTN DataSize,\r
- IN UINT32 Attributes OPTIONAL,\r
- IN UINT32 KeyIndex OPTIONAL,\r
- IN UINT64 MonotonicCount OPTIONAL,\r
- IN OUT VARIABLE_POINTER_TRACK *Variable,\r
- IN EFI_TIME *TimeStamp OPTIONAL\r
+ IN CHAR16 *VariableName,\r
+ IN EFI_GUID *VendorGuid,\r
+ IN VOID *Data,\r
+ IN UINTN DataSize,\r
+ IN UINT32 Attributes OPTIONAL,\r
+ IN UINT32 KeyIndex OPTIONAL,\r
+ IN UINT64 MonotonicCount OPTIONAL,\r
+ IN OUT VARIABLE_POINTER_TRACK *Variable,\r
+ IN EFI_TIME *TimeStamp OPTIONAL\r
);\r
\r
-\r
/**\r
Return TRUE if ExitBootServices () has been called.\r
\r
EFI_LOCK *\r
InitializeLock (\r
IN OUT EFI_LOCK *Lock,\r
- IN EFI_TPL Priority\r
+ IN EFI_TPL Priority\r
);\r
\r
-\r
/**\r
Acquires lock only at boot time. Simply returns at runtime.\r
\r
IN EFI_LOCK *Lock\r
);\r
\r
-\r
/**\r
Releases lock only at boot time. Simply returns at runtime.\r
\r
);\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
**/\r
EFI_STATUS\r
GetFvbCountAndBuffer (\r
- OUT UINTN *NumberHandles,\r
- OUT EFI_HANDLE **Buffer\r
+ OUT UINTN *NumberHandles,\r
+ OUT EFI_HANDLE **Buffer\r
);\r
\r
/**\r
\r
**/\r
VOID\r
-ReclaimForOS(\r
+ReclaimForOS (\r
VOID\r
);\r
\r
/**\r
- Get non-volatile maximum variable size.\r
+ Get maximum variable size, covering both non-volatile and volatile variables.\r
\r
- @return Non-volatile maximum variable size.\r
+ @return Maximum variable size.\r
\r
**/\r
UINTN\r
-GetNonVolatileMaxVariableSize (\r
+GetMaxVariableSize (\r
VOID\r
);\r
\r
/**\r
- Initializes variable write service after FVB was ready.\r
+ Initializes variable write service.\r
\r
@retval EFI_SUCCESS Function successfully executed.\r
@retval Others Fail to initialize the variable service.\r
);\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
**/\r
EFI_STATUS\r
GetFtwProtocol (\r
- OUT VOID **FtwProtocol\r
+ OUT VOID **FtwProtocol\r
);\r
\r
/**\r
@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
EFI_STATUS\r
EFIAPI\r
VariableServiceGetVariable (\r
- IN CHAR16 *VariableName,\r
- IN EFI_GUID *VendorGuid,\r
- OUT UINT32 *Attributes OPTIONAL,\r
- IN OUT UINTN *DataSize,\r
- OUT VOID *Data\r
- );\r
-\r
-/**\r
- This code Finds the Next available variable.\r
-\r
- 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[in] VariableName Pointer to variable name.\r
- @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
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-VariableServiceGetNextVariableInternal (\r
- IN CHAR16 *VariableName,\r
- IN EFI_GUID *VendorGuid,\r
- OUT VARIABLE_HEADER **VariablePtr\r
+ IN CHAR16 *VariableName,\r
+ IN EFI_GUID *VendorGuid,\r
+ OUT UINT32 *Attributes OPTIONAL,\r
+ IN OUT UINTN *DataSize,\r
+ OUT VOID *Data OPTIONAL\r
);\r
\r
/**\r
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
EFIAPI\r
VariableServiceGetNextVariableName (\r
- IN OUT UINTN *VariableNameSize,\r
- IN OUT CHAR16 *VariableName,\r
- IN OUT EFI_GUID *VendorGuid\r
+ IN OUT UINTN *VariableNameSize,\r
+ IN OUT CHAR16 *VariableName,\r
+ IN OUT EFI_GUID *VendorGuid\r
);\r
\r
/**\r
EFI_STATUS\r
EFIAPI\r
VariableServiceSetVariable (\r
- IN CHAR16 *VariableName,\r
- IN EFI_GUID *VendorGuid,\r
- IN UINT32 Attributes,\r
- IN UINTN DataSize,\r
- IN VOID *Data\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
EFI_STATUS\r
EFIAPI\r
VariableServiceQueryVariableInfoInternal (\r
- IN UINT32 Attributes,\r
- OUT UINT64 *MaximumVariableStorageSize,\r
- OUT UINT64 *RemainingVariableStorageSize,\r
- OUT UINT64 *MaximumVariableSize\r
+ IN UINT32 Attributes,\r
+ OUT UINT64 *MaximumVariableStorageSize,\r
+ OUT UINT64 *RemainingVariableStorageSize,\r
+ OUT UINT64 *MaximumVariableSize\r
);\r
\r
/**\r
EFI_STATUS\r
EFIAPI\r
VariableServiceQueryVariableInfo (\r
- IN UINT32 Attributes,\r
- OUT UINT64 *MaximumVariableStorageSize,\r
- OUT UINT64 *RemainingVariableStorageSize,\r
- OUT UINT64 *MaximumVariableSize\r
+ IN UINT32 Attributes,\r
+ OUT UINT64 *MaximumVariableStorageSize,\r
+ OUT UINT64 *RemainingVariableStorageSize,\r
+ OUT UINT64 *MaximumVariableSize\r
);\r
\r
/**\r
EFI_STATUS\r
EFIAPI\r
VariableLockRequestToLock (\r
- IN CONST EDKII_VARIABLE_LOCK_PROTOCOL *This,\r
- IN CHAR16 *VariableName,\r
- IN EFI_GUID *VendorGuid\r
+ IN CONST EDKII_VARIABLE_LOCK_PROTOCOL *This,\r
+ IN CHAR16 *VariableName,\r
+ IN EFI_GUID *VendorGuid\r
);\r
\r
/**\r
EFI_STATUS\r
EFIAPI\r
VarCheckRegisterSetVariableCheckHandler (\r
- IN VAR_CHECK_SET_VARIABLE_CHECK_HANDLER Handler\r
+ IN VAR_CHECK_SET_VARIABLE_CHECK_HANDLER Handler\r
);\r
\r
/**\r
EFI_STATUS\r
EFIAPI\r
VarCheckVariablePropertySet (\r
- IN CHAR16 *Name,\r
- IN EFI_GUID *Guid,\r
- IN VAR_CHECK_VARIABLE_PROPERTY *VariableProperty\r
+ IN CHAR16 *Name,\r
+ IN EFI_GUID *Guid,\r
+ IN VAR_CHECK_VARIABLE_PROPERTY *VariableProperty\r
);\r
\r
/**\r
EFI_STATUS\r
EFIAPI\r
VarCheckVariablePropertyGet (\r
- IN CHAR16 *Name,\r
- IN EFI_GUID *Guid,\r
- OUT VAR_CHECK_VARIABLE_PROPERTY *VariableProperty\r
+ IN CHAR16 *Name,\r
+ IN EFI_GUID *Guid,\r
+ OUT VAR_CHECK_VARIABLE_PROPERTY *VariableProperty\r
);\r
\r
/**\r
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 mAuthContextOut;\r
+extern AUTH_VAR_LIB_CONTEXT_OUT mAuthContextOut;\r
\r
/**\r
Finds variable in storage blocks of volatile and non-volatile storage areas.\r
EFI_STATUS\r
EFIAPI\r
VariableExLibFindVariable (\r
- IN CHAR16 *VariableName,\r
- IN EFI_GUID *VendorGuid,\r
- OUT AUTH_VARIABLE_INFO *AuthVariableInfo\r
+ IN CHAR16 *VariableName,\r
+ IN EFI_GUID *VendorGuid,\r
+ OUT AUTH_VARIABLE_INFO *AuthVariableInfo\r
);\r
\r
/**\r
EFI_STATUS\r
EFIAPI\r
VariableExLibFindNextVariable (\r
- IN CHAR16 *VariableName,\r
- IN EFI_GUID *VendorGuid,\r
- OUT AUTH_VARIABLE_INFO *AuthVariableInfo\r
+ IN CHAR16 *VariableName,\r
+ IN EFI_GUID *VendorGuid,\r
+ OUT AUTH_VARIABLE_INFO *AuthVariableInfo\r
);\r
\r
/**\r
EFI_STATUS\r
EFIAPI\r
VariableExLibUpdateVariable (\r
- IN AUTH_VARIABLE_INFO *AuthVariableInfo\r
+ IN AUTH_VARIABLE_INFO *AuthVariableInfo\r
);\r
\r
/**\r
EFI_STATUS\r
EFIAPI\r
VariableExLibGetScratchBuffer (\r
- IN OUT UINTN *ScratchBufferSize,\r
- OUT VOID **ScratchBuffer\r
+ IN OUT UINTN *ScratchBufferSize,\r
+ OUT VOID **ScratchBuffer\r
);\r
\r
/**\r
BOOLEAN\r
EFIAPI\r
VariableExLibCheckRemainingSpaceForConsistency (\r
- IN UINT32 Attributes,\r
+ IN UINT32 Attributes,\r
...\r
);\r
\r