From 0637e4054ee5f08c8145cdf74478d7eda414e7d7 Mon Sep 17 00:00:00 2001 From: Yeoreum Yun Date: Tue, 14 Apr 2026 15:50:56 +0100 Subject: [PATCH] MdeModulePkg/Library: introduce VariableStorageRouterLib This patch set introduce VariableStorageLib which can redirect variable service request to other than classic variable storage using FVB in non-volatile storage according to platform implementation. If platform redirect to platform specific storage for variables, it can implement its own VariableStorage protocol or VariableStorageRouterLib to add additional behavior. For example, If a platform wants to keep to use FVB for variable, It can use VariableStorageRouterBaseLib with VariableStorageFvb SMM driver or If a platform want to do platform specific action before/after handling variable storage with FVB, it could implements its own VariableStorageLib with VariableStorage FVB protocol. Below is the example overviews: 1. Default FVB backend The default implementation uses VariableStorageRouterBaseLib, which forwards every storage request to the FVB-based VariableStorage Protocol implementation. This preserves the current VariableService behaviour without requiring platform changes: OS or UEFI (Normal world) | StandaloneMm (Secure world) --------------------------------------|-------------------------------- | | +----------------+ +------------------+ | | Flash | | SetVariable() | | | (FVB based) | | GetVariable() | | +----------------+ +------------------+ | | | | | | | +----------------------------+ | | | VariableStorageFvb Driver | | | | (VariableStorage Protocol) | | | +----------------------------+ | | | | | +------------------------------+ | | | VariableStorageRouterLib | +-----------------------+ | |(VariableStorageRouterBaseLib)| | VariableSmmRuntimeDxe | | +------------------------------+ +-----------------------+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +---------------------+ MmCommunication +------------------+ | MmCommunicationDxe | <------------------------->| VariableSmmDxe | +---------------------+ +------------------+ 2. Platform-specific storage backend Platforms may replace the FVB backend with a platform-defined VariableStorage Protocol implementation while using VariableStorageRouterBaseLib to forward storage requests to the platform-defined VariableStorage Protocol. The example below shows a platform accessing flash managed by a dedicated management controller through a platform-defined VariableStorage Protocol implementation that proxies storage requests to the management controller. OS or UEFI (Normal world) | StandaloneMm (Secure world) --------------------------------------|------------------------------------ | +--------------+ | | +---------+ | +------------------+ | | | Flash | | | SetVariable() | | --->| | (Proxy) | | | GetVariable() | | | | +---------+ | +------------------+ | | | MC | | | | +--------------+ | | +----------------------------+ | | | VariableStorageProxy | | | | (VariableStorage Protocol) | | | +----------------------------+ | | | | | +-------------------------------+ | | | VariableStorageRouterLib | +-----------------------+ | | (VariableStorageRouterBaseib) | | VariableSmmRuntimeDxe | | +-------------------------------+ +-----------------------+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +---------------------+ MmCommunication +------------------+ | MmCommunicationDxe | <------------------------->| VariableSmmDxe | +---------------------+ +------------------+ Signed-off-by: Yeoreum Yun --- .../Library/VariableStorageRouterLib.h | 394 ++++++++++++++ .../VariableStorageRouterBase.c | 497 ++++++++++++++++++ .../VariableStorageRouterBaseLib.uni | 12 + ...VariableStorageRouterBaseStandaloneMmLib.c | 37 ++ ...riableStorageRouterBaseStandaloneMmLib.inf | 45 ++ ...ariableStorageRouterBaseTraditionalMmLib.c | 37 ++ ...iableStorageRouterBaseTraditionalMmLib.inf | 45 ++ MdeModulePkg/MdeModulePkg.dec | 4 + MdeModulePkg/MdeModulePkg.dsc | 4 + .../Variable/RuntimeDxe/VariableSmm.c | 265 +++------- .../Variable/RuntimeDxe/VariableSmm.inf | 3 +- .../RuntimeDxe/VariableStandaloneMm.inf | 4 +- 12 files changed, 1140 insertions(+), 207 deletions(-) create mode 100644 MdeModulePkg/Include/Library/VariableStorageRouterLib.h create mode 100644 MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBase.c create mode 100644 MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBaseLib.uni create mode 100644 MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBaseStandaloneMmLib.c create mode 100644 MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBaseStandaloneMmLib.inf create mode 100644 MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBaseTraditionalMmLib.c create mode 100644 MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBaseTraditionalMmLib.inf diff --git a/MdeModulePkg/Include/Library/VariableStorageRouterLib.h b/MdeModulePkg/Include/Library/VariableStorageRouterLib.h new file mode 100644 index 0000000000..83f8bb6fce --- /dev/null +++ b/MdeModulePkg/Include/Library/VariableStorageRouterLib.h @@ -0,0 +1,394 @@ +/** @file + Variable Storage Lib for Smm. + +Copyright (c) 2026, Arm Ltd. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include + +/** + Check whether Variable Storage use Auth Formet. + + @return TRUE Use Auth format. + @return FALSE Not use Auth format. + +**/ +BOOLEAN +EFIAPI +VariableStorageRouterLibCheckAuthFormat ( + VOID + ); + +/** + Get maximum variable size, covering both non-volatile and volatile variables. + + @return Maximum variable size. + +**/ +UINTN +EFIAPI +VariableStorageRouterLibGetMaxVariableSize ( + VOID + ); + +/** + + This code finds variable in storage blocks (Volatile or Non-Volatile). + + Caution: This function may receive untrusted input. + This function may be invoked in SMM mode, and datasize is external input. + This function will do basic validation, before parse the data. + + @param VariableName Name of Variable to be found. + @param VendorGuid Variable vendor GUID. + @param Attributes Attribute value of the variable found. + @param DataSize Size of Data found. If size is less than the + data, this value contains the required size. + @param Data The buffer to return the contents of the variable. May be NULL + with a zero DataSize in order to determine the size buffer needed. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_FOUND The variable was not found. + @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the result. + @retval EFI_INVALID_PARAMETER VariableName is NULL. + @retval EFI_INVALID_PARAMETER VendorGuid is NULL. + @retval EFI_INVALID_PARAMETER DataSize is NULL. + @retval EFI_INVALID_PARAMETER The DataSize is not too small and Data is NULL. + @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error. + @retval EFI_SECURITY_VIOLATION The variable could not be retrieved due to an authentication failure. + @retval EFI_UNSUPPORTED After ExitBootServices() has been called, this return code may be returned + if no variable storage is supported. The platform should describe this + runtime service as unsupported at runtime via an EFI_RT_PROPERTIES_TABLE + configuration table. + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibGetVariable ( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid, + OUT UINT32 *Attributes OPTIONAL, + IN OUT UINTN *DataSize, + OUT VOID *Data OPTIONAL + ); + +/** + + This code Finds the Next available variable. + + Caution: This function may receive untrusted input. + This function may be invoked in SMM mode. This function will do basic validation, before parse the data. + + @param VariableNameSize The size of the VariableName buffer. The size must be large + enough to fit input string supplied in VariableName buffer. + @param VariableName Pointer to variable name. + @param VendorGuid Variable Vendor Guid. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_FOUND The next variable was not found. + @retval EFI_BUFFER_TOO_SMALL The VariableNameSize is too small for the result. + VariableNameSize has been updated with the size needed to complete the request. + @retval EFI_INVALID_PARAMETER VariableNameSize is NULL. + @retval EFI_INVALID_PARAMETER VariableName is NULL. + @retval EFI_INVALID_PARAMETER VendorGuid is NULL. + @retval EFI_INVALID_PARAMETER The input values of VariableName and VendorGuid are not a name and + GUID of an existing variable. + @retval EFI_INVALID_PARAMETER Null-terminator is not found in the first VariableNameSize bytes of + the input VariableName buffer. + @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error. + @retval EFI_UNSUPPORTED After ExitBootServices() has been called, this return code may be returned + if no variable storage is supported. The platform should describe this + runtime service as unsupported at runtime via an EFI_RT_PROPERTIES_TABLE + configuration table. + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibGetNextVariableName ( + IN OUT UINTN *VariableNameSize, + IN OUT CHAR16 *VariableName, + IN OUT EFI_GUID *VendorGuid + ); + +/** + + This code sets variable in storage blocks (Volatile or Non-Volatile). + + Caution: This function may receive untrusted input. + This function may be invoked in SMM mode, and datasize and data are external input. + This function will do basic validation, before parse the data. + This function will parse the authentication carefully to avoid security issues, like + buffer overflow, integer overflow. + This function will check attribute carefully to avoid authentication bypass. + + @param VariableName Name of Variable to be found. + @param VendorGuid Variable vendor GUID. + @param Attributes Attribute value of the variable found + @param DataSize Size of Data found. If size is less than the + data, this value contains the required size. + @param Data Data pointer. + @param FromTrusted Whether request comes from trusted. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_FOUND The variable was not found. + @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the result. + @retval EFI_INVALID_PARAMETER VariableName is NULL. + @retval EFI_INVALID_PARAMETER VendorGuid is NULL. + @retval EFI_INVALID_PARAMETER DataSize is NULL. + @retval EFI_INVALID_PARAMETER The DataSize is not too small and Data is NULL. + @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error. + @retval EFI_SECURITY_VIOLATION The variable could not be retrieved due to an authentication failure. + @retval EFI_UNSUPPORTED After ExitBootServices() has been called, this return code may be returned + if no variable storage is supported. The platform should describe this + runtime service as unsupported at runtime via an EFI_RT_PROPERTIES_TABLE + configuration table. + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibSetVariable ( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid, + IN UINT32 Attributes, + IN UINTN DataSize, + IN VOID *Data, + IN BOOLEAN FromTrusted + ); + +/** + This code returns information about the EFI variables. + + Caution: This function may receive untrusted input. + This function may be invoked in SMM mode. This function will do basic validation, before parse the data. + + @param Attributes Attributes bitmask to specify the type of variables + on which to return information. + @param MaximumVariableStorageSize Pointer to the maximum size of the storage space available + for the EFI variables associated with the attributes specified. + @param RemainingVariableStorageSize Pointer to the remaining size of the storage space available + for EFI variables associated with the attributes specified. + @param MaximumVariableSize Pointer to the maximum size of an individual EFI variables + associated with the attributes specified. + + @return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied. + @return EFI_SUCCESS Query successfully. + @return EFI_UNSUPPORTED The attribute is not supported on this platform. + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibQueryVariableInfo ( + IN UINT32 Attributes, + OUT UINT64 *MaximumVariableStorageSize, + OUT UINT64 *RemainingVariableStorageSize, + OUT UINT64 *MaximumVariableSize + ); + +/** + Callback function at End of DXE phase notification. + + @return EFI_SUCCESS + @return Others ERROR. + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibEndOfDxe ( + IN VOID + ); + +/** + Callback function at READY_TO_BOOT phase notification. + + @return EFI_SUCCESS + @return Others ERROR. + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibReadyToBoot ( + IN VOID + ); + +/** + Callback function for EXIT_BOOT phase notification. + + @return EFI_SUCCESS + @return Others ERROR. + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibExitBootService ( + IN VOID + ); + +/** + Get the variable statistics information from the information buffer pointed by gVariableInfo. + + Caution: This function may be invoked at SMM runtime. + InfoEntry and InfoSize are external input. Care must be taken to make sure not security issue at runtime. + + @param[in, out] InfoEntry A pointer to the buffer of variable information entry. + On input, point to the variable information returned last time. if + InfoEntry->VendorGuid is zero, return the first information. + On output, point to the next variable information. + @param[in, out] InfoSize On input, the size of the variable information buffer. + On output, the returned variable information size. + + @retval EFI_SUCCESS The variable information is found and returned successfully. + @retval EFI_UNSUPPORTED No variable inoformation exists in variable driver. + @retval EFI_BUFFER_TOO_SMALL The buffer is too small to hold the next variable information. + @retval EFI_INVALID_PARAMETER Input parameter is invalid. + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibGetStatics ( + IN OUT VARIABLE_INFO_ENTRY *InfoEntry, + IN OUT UINTN *InfoSize + ); + +/** + Mark a variable that will become read-only after leaving the DXE phase of execution. + + @param[in] VariableName A pointer to the variable name that will be made read-only subsequently. + @param[in] VendorGuid A pointer to the vendor GUID that will be made read-only subsequently. + + @retval EFI_SUCCESS The variable specified by the VariableName and the VendorGuid was marked + as pending to be read-only. + @retval EFI_INVALID_PARAMETER VariableName or VendorGuid is NULL. + Or VariableName is an empty string. + @retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has + already been signaled. + @retval EFI_OUT_OF_RESOURCES There is not enough resource to hold the lock request. +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibRequestToLock ( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid + ); + +/** + Variable property set. + + @param[in] Name Pointer to the variable name. + @param[in] Guid Pointer to the vendor GUID. + @param[in] VariableProperty Pointer to the input variable property. + + @retval EFI_SUCCESS The property of variable specified by the Name and Guid was set successfully. + @retval EFI_INVALID_PARAMETER Name, Guid or VariableProperty is NULL, or Name is an empty string, + or the fields of VariableProperty are not valid. + @retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has + already been signaled. + @retval EFI_OUT_OF_RESOURCES There is not enough resource for the variable property set request. + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibPropertySet ( + IN CHAR16 *Name, + IN EFI_GUID *Guid, + IN VAR_CHECK_VARIABLE_PROPERTY *VariableProperty + ); + +/** + Variable property get. + + @param[in] Name Pointer to the variable name. + @param[in] Guid Pointer to the vendor GUID. + @param[out] VariableProperty Pointer to the output variable property. + + @retval EFI_SUCCESS The property of variable specified by the Name and Guid was got successfully. + @retval EFI_INVALID_PARAMETER Name, Guid or VariableProperty is NULL, or Name is an empty string. + @retval EFI_NOT_FOUND The property of variable specified by the Name and Guid was not found. + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibPropertyGet ( + IN CHAR16 *Name, + IN EFI_GUID *Guid, + OUT VAR_CHECK_VARIABLE_PROPERTY *VariableProperty + ); + +/** + Initialise Variable Runtime Cache. + + @param[in] HobCache Address of cache for variables in HobList. + @param[in] VolatileCache Address of cache for variables in volatile memory. + @param[in] NvCache Address of cache for variables in in non-volatile memory. + @param[in] PendingUpdate Address to bool to check pending update. + @param[in] ReadLock Address to bool to check read operation is locked. + @param[in] HobFlushComplete Address to bool to check flush hob is completed. + + @return EFI_SUCCESS + @return EFI_UNSUPPORTED Runtime variable cache isn't supported + @return Others Errors + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibInitCache ( + IN VARIABLE_STORE_HEADER *HobCache, + IN VARIABLE_STORE_HEADER *VolatileCache, + IN VARIABLE_STORE_HEADER *NvCache, + IN BOOLEAN *PendingUpdate, + IN BOOLEAN *ReadLock, + IN BOOLEAN *HobFlushComplete + ); + +/** + Copies any pending updates to runtime variable caches. + + @retval EFI_SUCCESS The cache store was updated successfully. + @retval EFI_UNSUPPORTED The cache store to be updated is not initialized properly. + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibSyncCache ( + VOID + ); + +/** + Get runtime variable caches info. + + @param[out] HobCacheSize Cache size of variables in Hob list. + @param[out] VolatileCacheSize Cache size of variables in volatile memory. + @param[out] NvCacheSize Cache size of variables in non-volatile memory. + + @retval EFI_SUCCESS + @retval EFI_UNSUPPORTED + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibGetCacheInfo ( + OUT UINTN *HobCacheSize, + OUT UINTN *VolatileCacheSize, + OUT UINTN *NvCacheSize + ); + +/** + Initialise Variable Write Service. + This function should install gSmmVariableWriteGuid or register notifier to install + + @param[in] WriteReadyNotify Notifier to be called when varaibles are + writable. + + @return EFI_SUCCESS + @return Others Failed to initialise write service. + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibInitWriteService ( + IN WRITE_READY_NOTIFY_FN WriteReadyNotify + ); diff --git a/MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBase.c b/MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBase.c new file mode 100644 index 0000000000..9c59c089c4 --- /dev/null +++ b/MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBase.c @@ -0,0 +1,497 @@ +/** @file + Variable Storage Router Base Library + +Copyright (c) 2026, Arm Ltd. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include + +#include + +EDKII_VARIABLE_STORAGE_PROTOCOL *mVariableStorage; + +/** + Check whether Variable Storage use Auth Formet. + + @return TRUE Use Auth format. + @return FALSE Not use Auth format. + +**/ +BOOLEAN +EFIAPI +VariableStorageRouterLibCheckAuthFormat ( + VOID + ) +{ + return mVariableStorage->CheckAuthFormat (); +} + +/** + Get maximum variable size, covering both non-volatile and volatile variables. + + @return Maximum variable size. + +**/ +UINTN +EFIAPI +VariableStorageRouterLibGetMaxVariableSize ( + VOID + ) +{ + return mVariableStorage->GetMaxVariableSize (); +} + +/** + + This code finds variable in storage blocks (Volatile or Non-Volatile). + + Caution: This function may receive untrusted input. + This function may be invoked in SMM mode, and datasize is external input. + This function will do basic validation, before parse the data. + + @param VariableName Name of Variable to be found. + @param VendorGuid Variable vendor GUID. + @param Attributes Attribute value of the variable found. + @param DataSize Size of Data found. If size is less than the + data, this value contains the required size. + @param Data The buffer to return the contents of the variable. May be NULL + with a zero DataSize in order to determine the size buffer needed. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_FOUND The variable was not found. + @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the result. + @retval EFI_INVALID_PARAMETER VariableName is NULL. + @retval EFI_INVALID_PARAMETER VendorGuid is NULL. + @retval EFI_INVALID_PARAMETER DataSize is NULL. + @retval EFI_INVALID_PARAMETER The DataSize is not too small and Data is NULL. + @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error. + @retval EFI_SECURITY_VIOLATION The variable could not be retrieved due to an authentication failure. + @retval EFI_UNSUPPORTED After ExitBootServices() has been called, this return code may be returned + if no variable storage is supported. The platform should describe this + runtime service as unsupported at runtime via an EFI_RT_PROPERTIES_TABLE + configuration table. + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibGetVariable ( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid, + OUT UINT32 *Attributes OPTIONAL, + IN OUT UINTN *DataSize, + OUT VOID *Data OPTIONAL + ) +{ + return mVariableStorage->GetVariable ( + VariableName, + VendorGuid, + Attributes, + DataSize, + Data + ); +} + +/** + + This code Finds the Next available variable. + + Caution: This function may receive untrusted input. + This function may be invoked in SMM mode. This function will do basic validation, before parse the data. + + @param VariableNameSize The size of the VariableName buffer. The size must be large + enough to fit input string supplied in VariableName buffer. + @param VariableName Pointer to variable name. + @param VendorGuid Variable Vendor Guid. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_FOUND The next variable was not found. + @retval EFI_BUFFER_TOO_SMALL The VariableNameSize is too small for the result. + VariableNameSize has been updated with the size needed to complete the request. + @retval EFI_INVALID_PARAMETER VariableNameSize is NULL. + @retval EFI_INVALID_PARAMETER VariableName is NULL. + @retval EFI_INVALID_PARAMETER VendorGuid is NULL. + @retval EFI_INVALID_PARAMETER The input values of VariableName and VendorGuid are not a name and + GUID of an existing variable. + @retval EFI_INVALID_PARAMETER Null-terminator is not found in the first VariableNameSize bytes of + the input VariableName buffer. + @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error. + @retval EFI_UNSUPPORTED After ExitBootServices() has been called, this return code may be returned + if no variable storage is supported. The platform should describe this + runtime service as unsupported at runtime via an EFI_RT_PROPERTIES_TABLE + configuration table. + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibGetNextVariableName ( + IN OUT UINTN *VariableNameSize, + IN OUT CHAR16 *VariableName, + IN OUT EFI_GUID *VendorGuid + ) +{ + return mVariableStorage->GetNextVariableName ( + VariableNameSize, + VariableName, + VendorGuid + ); +} + +/** + + This code sets variable in storage blocks (Volatile or Non-Volatile). + + Caution: This function may receive untrusted input. + This function may be invoked in SMM mode, and datasize and data are external input. + This function will do basic validation, before parse the data. + This function will parse the authentication carefully to avoid security issues, like + buffer overflow, integer overflow. + This function will check attribute carefully to avoid authentication bypass. + + @param VariableName Name of Variable to be found. + @param VendorGuid Variable vendor GUID. + @param Attributes Attribute value of the variable found + @param DataSize Size of Data found. If size is less than the + data, this value contains the required size. + @param Data Data pointer. + @param FromTrusted Whether request comes from trusted. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_FOUND The variable was not found. + @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the result. + @retval EFI_INVALID_PARAMETER VariableName is NULL. + @retval EFI_INVALID_PARAMETER VendorGuid is NULL. + @retval EFI_INVALID_PARAMETER DataSize is NULL. + @retval EFI_INVALID_PARAMETER The DataSize is not too small and Data is NULL. + @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error. + @retval EFI_SECURITY_VIOLATION The variable could not be retrieved due to an authentication failure. + @retval EFI_UNSUPPORTED After ExitBootServices() has been called, this return code may be returned + if no variable storage is supported. The platform should describe this + runtime service as unsupported at runtime via an EFI_RT_PROPERTIES_TABLE + configuration table. + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibSetVariable ( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid, + IN UINT32 Attributes, + IN UINTN DataSize, + IN VOID *Data, + IN BOOLEAN FromTrusted + ) +{ + return mVariableStorage->SetVariable ( + VariableName, + VendorGuid, + Attributes, + DataSize, + Data, + FromTrusted + ); +} + +/** + This code returns information about the EFI variables. + + Caution: This function may receive untrusted input. + This function may be invoked in SMM mode. This function will do basic validation, before parse the data. + + @param Attributes Attributes bitmask to specify the type of variables + on which to return information. + @param MaximumVariableStorageSize Pointer to the maximum size of the storage space available + for the EFI variables associated with the attributes specified. + @param RemainingVariableStorageSize Pointer to the remaining size of the storage space available + for EFI variables associated with the attributes specified. + @param MaximumVariableSize Pointer to the maximum size of an individual EFI variables + associated with the attributes specified. + + @return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied. + @return EFI_SUCCESS Query successfully. + @return EFI_UNSUPPORTED The attribute is not supported on this platform. + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibQueryVariableInfo ( + IN UINT32 Attributes, + OUT UINT64 *MaximumVariableStorageSize, + OUT UINT64 *RemainingVariableStorageSize, + OUT UINT64 *MaximumVariableSize + ) +{ + return mVariableStorage->QueryVariableInfo ( + Attributes, + MaximumVariableStorageSize, + RemainingVariableStorageSize, + MaximumVariableSize + ); +} + +/** + Callback function at End of DXE phase notification. + + @return EFI_SUCCESS + @return Others ERROR. + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibEndOfDxe ( + IN VOID + ) +{ + return mVariableStorage->EndOfDxe (); +} + +/** + Callback function at READY_TO_BOOT phase notification. + + @return EFI_SUCCESS + @return Others ERROR. + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibReadyToBoot ( + IN VOID + ) +{ + return mVariableStorage->ReadyToBoot (); +} + +/** + Callback function for EXIT_BOOT phase notification. + + @return EFI_SUCCESS + @return Others ERROR. + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibExitBootService ( + IN VOID + ) +{ + return mVariableStorage->ExitBootService (); +} + +/** + Get the variable statistics information from the information buffer pointed by gVariableInfo. + + Caution: This function may be invoked at SMM runtime. + InfoEntry and InfoSize are external input. Care must be taken to make sure not security issue at runtime. + + @param[in, out] InfoEntry A pointer to the buffer of variable information entry. + On input, point to the variable information returned last time. if + InfoEntry->VendorGuid is zero, return the first information. + On output, point to the next variable information. + @param[in, out] InfoSize On input, the size of the variable information buffer. + On output, the returned variable information size. + + @retval EFI_SUCCESS The variable information is found and returned successfully. + @retval EFI_UNSUPPORTED No variable inoformation exists in variable driver. + @retval EFI_BUFFER_TOO_SMALL The buffer is too small to hold the next variable information. + @retval EFI_INVALID_PARAMETER Input parameter is invalid. + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibGetStatics ( + IN OUT VARIABLE_INFO_ENTRY *InfoEntry, + IN OUT UINTN *InfoSize + ) +{ + return mVariableStorage->GetStatics ( + InfoEntry, + InfoSize + ); +} + +/** + Mark a variable that will become read-only after leaving the DXE phase of execution. + + @param[in] VariableName A pointer to the variable name that will be made read-only subsequently. + @param[in] VendorGuid A pointer to the vendor GUID that will be made read-only subsequently. + + @retval EFI_SUCCESS The variable specified by the VariableName and the VendorGuid was marked + as pending to be read-only. + @retval EFI_INVALID_PARAMETER VariableName or VendorGuid is NULL. + Or VariableName is an empty string. + @retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has + already been signaled. + @retval EFI_OUT_OF_RESOURCES There is not enough resource to hold the lock request. +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibRequestToLock ( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid + ) +{ + return mVariableStorage->RequestToLock ( + VariableName, + VendorGuid + ); +} + +/** + Variable property set. + + @param[in] Name Pointer to the variable name. + @param[in] Guid Pointer to the vendor GUID. + @param[in] VariableProperty Pointer to the input variable property. + + @retval EFI_SUCCESS The property of variable specified by the Name and Guid was set successfully. + @retval EFI_INVALID_PARAMETER Name, Guid or VariableProperty is NULL, or Name is an empty string, + or the fields of VariableProperty are not valid. + @retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has + already been signaled. + @retval EFI_OUT_OF_RESOURCES There is not enough resource for the variable property set request. + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibPropertySet ( + IN CHAR16 *Name, + IN EFI_GUID *Guid, + IN VAR_CHECK_VARIABLE_PROPERTY *VariableProperty + ) +{ + return mVariableStorage->PropertySet ( + Name, + Guid, + VariableProperty + ); +} + +/** + Variable property get. + + @param[in] Name Pointer to the variable name. + @param[in] Guid Pointer to the vendor GUID. + @param[out] VariableProperty Pointer to the output variable property. + + @retval EFI_SUCCESS The property of variable specified by the Name and Guid was got successfully. + @retval EFI_INVALID_PARAMETER Name, Guid or VariableProperty is NULL, or Name is an empty string. + @retval EFI_NOT_FOUND The property of variable specified by the Name and Guid was not found. + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibPropertyGet ( + IN CHAR16 *Name, + IN EFI_GUID *Guid, + OUT VAR_CHECK_VARIABLE_PROPERTY *VariableProperty + ) +{ + return mVariableStorage->PropertyGet ( + Name, + Guid, + VariableProperty + ); +} + +/** + Initialise Variable Runtime Cache. + + @param[in] HobCache Address of cache for variables in HobList. + @param[in] VolatileCache Address of cache for variables in volatile memory. + @param[in] NvCache Address of cache for variables in in non-volatile memory. + @param[in] PendingUpdate Address to bool to check pending update. + @param[in] ReadLock Address to bool to check read operation is locked. + @param[in] HobFlushComplete Address to bool to check flush hob is completed. + + @return EFI_SUCCESS + @return EFI_UNSUPPORTED Runtime variable cache isn't supported + @return Others Errors + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibInitCache ( + IN VARIABLE_STORE_HEADER *HobCache, + IN VARIABLE_STORE_HEADER *VolatileCache, + IN VARIABLE_STORE_HEADER *NvCache, + IN BOOLEAN *PendingUpdate, + IN BOOLEAN *ReadLock, + IN BOOLEAN *HobFlushComplete + ) +{ + return mVariableStorage->InitCache ( + HobCache, + VolatileCache, + NvCache, + PendingUpdate, + ReadLock, + HobFlushComplete + ); +} + +/** + Copies any pending updates to runtime variable caches. + + @retval EFI_SUCCESS The cache store was updated successfully. + @retval EFI_UNSUPPORTED The cache store to be updated is not initialized properly. + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibSyncCache ( + VOID + ) +{ + return mVariableStorage->SyncCache (); +} + +/** + Get runtime variable caches info. + + @param[out] HobCacheSize Cache size of variables in Hob list. + @param[out] VolatileCacheSize Cache size of variables in volatile memory. + @param[out] NvCacheSize Cache size of variables in non-volatile memory. + + @retval EFI_SUCCESS + @retval EFI_UNSUPPORTED + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibGetCacheInfo ( + OUT UINTN *HobCacheSize, + OUT UINTN *VolatileCacheSize, + OUT UINTN *NvCacheSize + ) +{ + return mVariableStorage->GetCacheInfo ( + HobCacheSize, + VolatileCacheSize, + NvCacheSize + ); +} + +/** + Initialise Variable Write Service. + This function should install gSmmVariableWriteGuid or register notifier to install + + @param[in] WriteReadyNotify Notifier to be called when varaibles are + writable. + + @return EFI_SUCCESS + @return Others Failed to initialise write service. + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterLibInitWriteService ( + IN WRITE_READY_NOTIFY_FN WriteReadyNotify + ) +{ + return mVariableStorage->InitWriteService ( + WriteReadyNotify + ); +} diff --git a/MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBaseLib.uni b/MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBaseLib.uni new file mode 100644 index 0000000000..cd4b7daa4d --- /dev/null +++ b/MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBaseLib.uni @@ -0,0 +1,12 @@ +// /** @file +// Variable Storage Router Base Library. +// +// Copyright (c) 2026, Arm Ltd. All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Variable Storage Router Base Library." +#string STR_MODULE_DESCRIPTION #language en-US "Variable Storage Router Base Library." diff --git a/MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBaseStandaloneMmLib.c b/MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBaseStandaloneMmLib.c new file mode 100644 index 0000000000..2456d8be0b --- /dev/null +++ b/MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBaseStandaloneMmLib.c @@ -0,0 +1,37 @@ +/** @file + Variable Storage Router Base Library + +Copyright (c) 2026, Arm Ltd. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include + +#include + +extern EDKII_VARIABLE_STORAGE_PROTOCOL *mVariableStorage; + +/** + The constructor function for VariableStorageRouterLib. + + @param ImageHandle The firmware allocated handle for the EFI image. + @param MmSystemTable A pointer to the MM System Table. + + @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterBaseLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_MM_SYSTEM_TABLE *MmSystemTable + ) +{ + return gMmst->MmLocateProtocol ( + &gEdkiiVariableStorageProtocolGuid, + NULL, + (VOID **)&mVariableStorage + ); +} diff --git a/MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBaseStandaloneMmLib.inf b/MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBaseStandaloneMmLib.inf new file mode 100644 index 0000000000..cecca9491a --- /dev/null +++ b/MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBaseStandaloneMmLib.inf @@ -0,0 +1,45 @@ +## @file +# Variable Storage Base Library which uses FVB. +# +# Copyright (c) 2026, Arm Ltd. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = VariableStorageRouterBaseLib + MODULE_UNI_FILE = VariableStorageRouterBaseLib.uni + FILE_GUID = 5481529a-380d-11f1-8961-ab5d0e6d80c1 + MODULE_TYPE = MM_STANDALONE + VERSION_STRING = 1.0 + LIBRARY_CLASS = VariableStorageLib|MM_STANDALONE + PI_SPECIFICATION_VERSION = 0x00010032 + CONSTRUCTOR = VariableStorageRouterBaseLibConstructor + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 AARCH64 +# + +[Sources] + VariableStorageRouterBase.c + VariableStorageRouterBaseStandaloneMmLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MmServicesTableLib + +[Protocols] + gEdkiiVariableStorageProtocolGuid ## COUNSUMES + +[Depex] + gEdkiiVariableStorageProtocolGuid diff --git a/MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBaseTraditionalMmLib.c b/MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBaseTraditionalMmLib.c new file mode 100644 index 0000000000..927819dd56 --- /dev/null +++ b/MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBaseTraditionalMmLib.c @@ -0,0 +1,37 @@ +/** @file + Variable Storage Router Base Library + +Copyright (c) 2026, Arm Ltd. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include + +#include + +extern EDKII_VARIABLE_STORAGE_PROTOCOL *mVariableStorage; + +/** + The constructor function for VariableStorageRouterLib. + + @param ImageHandle The firmware allocated handle for the EFI image. + @param[in] SystemTable A pointer to the EFI system table + + @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. + +**/ +EFI_STATUS +EFIAPI +VariableStorageRouterBaseLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + return gMmst->MmLocateProtocol ( + &gEdkiiVariableStorageProtocolGuid, + NULL, + (VOID **)&mVariableStorage + ); +} diff --git a/MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBaseTraditionalMmLib.inf b/MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBaseTraditionalMmLib.inf new file mode 100644 index 0000000000..0f69ee97f9 --- /dev/null +++ b/MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBaseTraditionalMmLib.inf @@ -0,0 +1,45 @@ +## @file +# Variable Storage Base Library which uses FVB. +# +# Copyright (c) 2026, Arm Ltd. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = VariableStorageRouterBaseLib + MODULE_UNI_FILE = VariableStorageRouterBaseLib.uni + FILE_GUID = 20d30b70-85e5-11f1-b3c9-f3f75f24066e + MODULE_TYPE = DXE_SMM_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = VariableStorageLib|DXE_SMM_DRIVER + PI_SPECIFICATION_VERSION = 0x00010032 + CONSTRUCTOR = VariableStorageRouterBaseLibConstructor + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 +# + +[Sources] + VariableStorageRouterBase.c + VariableStorageRouterBaseTraditionalMmLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MmServicesTableLib + +[Protocols] + gEdkiiVariableStorageProtocolGuid ## COUNSUMES + +[Depex] + gEdkiiVariableStorageProtocolGuid diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 593f541c6d..2121d272e2 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -187,6 +187,10 @@ # HobPrintLib|Include/Library/HobPrintLib.h + ## @libraryclass Provides a services to communicate Variable Storage + # + VariableStorageRouterLib|Include/Library/VariableStorageRouterLib.h + [Guids] ## MdeModule package token space guid # Include/Guid/MdeModulePkgTokenSpace.h diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index 0acf1d8805..39d352dda1 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -160,6 +160,7 @@ SmmServicesTableLib|MdePkg/Library/SmmServicesTableLib/SmmServicesTableLib.inf LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf SmmMemLib|MdePkg/Library/SmmMemLib/SmmMemLib.inf + VariableStorageRouterLib|MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBaseTraditionalMmLib.inf [LibraryClasses.common.UEFI_DRIVER] HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf @@ -182,6 +183,7 @@ MemLib|StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf VarCheckHiiLibMmDependency|MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibMmDependency.inf VarCheckHiiLib|MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibStandaloneMm.inf + VariableStorageRouterLib|MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBaseStandaloneMmLib.inf [LibraryClasses.AARCH64] LockBoxLib|MdeModulePkg/Library/LockBoxNullLib/LockBoxNullLib.inf @@ -473,6 +475,7 @@ } !if $(TOOL_CHAIN_TAG) != "XCODE5" + MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBaseStandaloneMmLib.inf MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStorageFvbStandaloneMm.inf { DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibBase.inf @@ -488,6 +491,7 @@ MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.inf MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf MdeModulePkg/Core/PiSmmCore/PiSmmCore.inf + MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBaseTraditionalMmLib.inf MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStorageFvbTraditionalMm.inf { NULL|MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLib.inf diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c index aaeaee5f79..b9b3fb9bd9 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c @@ -21,11 +21,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include -#include #include #include #include +#include #include #include "PrivilegePolymorphic.h" @@ -37,8 +37,6 @@ STATIC BOOLEAN mEndOfDxe = FALSE; STATIC UINT8 *mVariableBufferPayload = NULL; STATIC UINTN mVariableBufferPayloadSize; -STATIC EDKII_VARIABLE_STORAGE_PROTOCOL *mVariableStorage; - /** This code gets the size of variable header. @@ -55,7 +53,7 @@ GetVariableHeaderSize ( UINTN Value; BOOLEAN AuthFormat; - AuthFormat = mVariableStorage->CheckAuthFormat (); + AuthFormat = VariableStorageRouterLibCheckAuthFormat (); if (AuthFormat) { Value = sizeof (AUTHENTICATED_VARIABLE_HEADER); @@ -87,7 +85,7 @@ GetVariableHeaderSize ( STATIC EFI_STATUS EFIAPI -VariableStorageFvbSetVariable ( +SmmVariableSetVariable ( IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, @@ -95,155 +93,21 @@ VariableStorageFvbSetVariable ( IN VOID *Data ) { - return mVariableStorage->SetVariable ( - VariableName, - VendorGuid, - Attributes, - DataSize, - Data, - TRUE - ); -} - -/** - Returns the value of a variable. - - @param[in] VariableName A Null-terminated string that is the name of the vendor's - variable. - @param[in] VendorGuid A unique identifier for the vendor. - @param[out] Attributes If not NULL, a pointer to the memory location to return the - attributes bitmask for the variable. - @param[in, out] DataSize On input, the size in bytes of the return Data buffer. - On output the size of data returned in Data. - @param[out] Data The buffer to return the contents of the variable. May be NULL - with a zero DataSize in order to determine the size buffer needed. - - @retval EFI_SUCCESS The function completed successfully. - @retval EFI_NOT_FOUND The variable was not found. - @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the result. - @retval EFI_INVALID_PARAMETER VariableName is NULL. - @retval EFI_INVALID_PARAMETER VendorGuid is NULL. - @retval EFI_INVALID_PARAMETER DataSize is NULL. - @retval EFI_INVALID_PARAMETER The DataSize is not too small and Data is NULL. - @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error. - @retval EFI_SECURITY_VIOLATION The variable could not be retrieved due to an authentication failure. - @retval EFI_UNSUPPORTED After ExitBootServices() has been called, this return code may be returned - if no variable storage is supported. The platform should describe this - runtime service as unsupported at runtime via an EFI_RT_PROPERTIES_TABLE - configuration table. - -**/ -STATIC -EFI_STATUS -EFIAPI -VariableStorageFvbGetVariable ( - IN CHAR16 *VariableName, - IN EFI_GUID *VendorGuid, - OUT UINT32 *Attributes OPTIONAL, - IN OUT UINTN *DataSize, - OUT VOID *Data OPTIONAL - ) -{ - return mVariableStorage->GetVariable ( - VariableName, - VendorGuid, - Attributes, - DataSize, - Data - ); -} - -/** - Enumerates the current variable names. - - @param[in, out] VariableNameSize The size of the VariableName buffer. The size must be large - enough to fit input string supplied in VariableName buffer. - @param[in, out] VariableName On input, supplies the last VariableName that was returned - by GetNextVariableName(). On output, returns the Nullterminated - string of the current variable. - @param[in, out] VendorGuid On input, supplies the last VendorGuid that was returned by - GetNextVariableName(). On output, returns the - VendorGuid of the current variable. - - @retval EFI_SUCCESS The function completed successfully. - @retval EFI_NOT_FOUND The next variable was not found. - @retval EFI_BUFFER_TOO_SMALL The VariableNameSize is too small for the result. - VariableNameSize has been updated with the size needed to complete the request. - @retval EFI_INVALID_PARAMETER VariableNameSize is NULL. - @retval EFI_INVALID_PARAMETER VariableName is NULL. - @retval EFI_INVALID_PARAMETER VendorGuid is NULL. - @retval EFI_INVALID_PARAMETER The input values of VariableName and VendorGuid are not a name and - GUID of an existing variable. - @retval EFI_INVALID_PARAMETER Null-terminator is not found in the first VariableNameSize bytes of - the input VariableName buffer. - @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error. - @retval EFI_UNSUPPORTED After ExitBootServices() has been called, this return code may be returned - if no variable storage is supported. The platform should describe this - runtime service as unsupported at runtime via an EFI_RT_PROPERTIES_TABLE - configuration table. - -**/ -STATIC -EFI_STATUS -EFIAPI -VariableStorageFvbGetNextVariableName ( - IN OUT UINTN *VariableNameSize, - IN OUT CHAR16 *VariableName, - IN OUT EFI_GUID *VendorGuid - ) -{ - return mVariableStorage->GetNextVariableName ( - VariableNameSize, - VariableName, - VendorGuid - ); -} - -/** - Returns information about the EFI variables. - - @param[in] Attributes Attributes bitmask to specify the type of variables on - which to return information. - @param[out] MaximumVariableStorageSize On output the maximum size of the storage space - available for the EFI variables associated with the - attributes specified. - @param[out] RemainingVariableStorageSize Returns the remaining size of the storage space - available for the EFI variables associated with the - attributes specified. - @param[out] MaximumVariableSize Returns the maximum size of the individual EFI - variables associated with the attributes specified. - - @retval EFI_SUCCESS Valid answer returned. - @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied - @retval EFI_UNSUPPORTED The attribute is not supported on this platform, and the - MaximumVariableStorageSize, - RemainingVariableStorageSize, MaximumVariableSize - are undefined. - -**/ -STATIC -EFI_STATUS -EFIAPI -VariableStorageFvbQueryVariableInfo ( - IN UINT32 Attributes, - OUT UINT64 *MaximumVariableStorageSize, - OUT UINT64 *RemainingVariableStorageSize, - OUT UINT64 *MaximumVariableSize - ) -{ - return mVariableStorage->QueryVariableInfo ( - Attributes, - MaximumVariableStorageSize, - RemainingVariableStorageSize, - MaximumVariableSize - ); + return VariableStorageRouterLibSetVariable ( + VariableName, + VendorGuid, + Attributes, + DataSize, + Data, + TRUE + ); } EFI_SMM_VARIABLE_PROTOCOL gSmmVariable = { - VariableStorageFvbGetVariable, - VariableStorageFvbGetNextVariableName, - VariableStorageFvbSetVariable, - VariableStorageFvbQueryVariableInfo + VariableStorageRouterLibGetVariable, + VariableStorageRouterLibGetNextVariableName, + SmmVariableSetVariable, + VariableStorageRouterLibQueryVariableInfo }; /** @@ -371,7 +235,7 @@ SmmVariableHandler ( goto EXIT; } - Status = VariableStorageFvbGetVariable ( + Status = VariableStorageRouterLibGetVariable ( SmmVariableHeader->Name, &SmmVariableHeader->Guid, &SmmVariableHeader->Attributes, @@ -420,7 +284,7 @@ SmmVariableHandler ( goto EXIT; } - Status = VariableStorageFvbGetNextVariableName ( + Status = VariableStorageRouterLibGetNextVariableName ( &GetNextVariableName->NameSize, GetNextVariableName->Name, &GetNextVariableName->Guid @@ -476,14 +340,14 @@ SmmVariableHandler ( goto EXIT; } - Status = mVariableStorage->SetVariable ( - SmmVariableHeader->Name, - &SmmVariableHeader->Guid, - SmmVariableHeader->Attributes, - SmmVariableHeader->DataSize, - (UINT8 *)SmmVariableHeader->Name + SmmVariableHeader->NameSize, - FALSE - ); + Status = VariableStorageRouterLibSetVariable ( + SmmVariableHeader->Name, + &SmmVariableHeader->Guid, + SmmVariableHeader->Attributes, + SmmVariableHeader->DataSize, + (UINT8 *)SmmVariableHeader->Name + SmmVariableHeader->NameSize, + FALSE + ); break; case SMM_VARIABLE_FUNCTION_QUERY_VARIABLE_INFO: @@ -494,7 +358,7 @@ SmmVariableHandler ( QueryVariableInfo = (SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO *)SmmVariableFunctionHeader->Data; - Status = VariableStorageFvbQueryVariableInfo ( + Status = VariableStorageRouterLibQueryVariableInfo ( QueryVariableInfo->Attributes, &QueryVariableInfo->MaximumVariableStorageSize, &QueryVariableInfo->RemainingVariableStorageSize, @@ -520,7 +384,7 @@ SmmVariableHandler ( } if (!mEndOfDxe) { - Status = mVariableStorage->ReadyToBoot (); + Status = VariableStorageRouterLibReadyToBoot (); } else { Status = EFI_SUCCESS; } @@ -529,7 +393,7 @@ SmmVariableHandler ( case SMM_VARIABLE_FUNCTION_EXIT_BOOT_SERVICE: mAtRuntime = TRUE; - Status = mVariableStorage->ExitBootService (); + Status = VariableStorageRouterLibExitBootService (); break; case SMM_VARIABLE_FUNCTION_GET_STATISTICS: @@ -546,7 +410,7 @@ SmmVariableHandler ( // that was used by SMM core to cache CommSize from SmmCommunication protocol. // - Status = mVariableStorage->GetStatics (VariableInfo, &InfoSize); + Status = VariableStorageRouterLibGetStatics (VariableInfo, &InfoSize); *CommBufferSize = InfoSize + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE; break; @@ -555,10 +419,10 @@ SmmVariableHandler ( Status = EFI_ACCESS_DENIED; } else { VariableToLock = (SMM_VARIABLE_COMMUNICATE_LOCK_VARIABLE *)SmmVariableFunctionHeader->Data; - Status = mVariableStorage->RequestToLock ( - VariableToLock->Name, - &VariableToLock->Guid - ); + Status = VariableStorageRouterLibRequestToLock ( + VariableToLock->Name, + &VariableToLock->Guid + ); } break; @@ -568,11 +432,11 @@ SmmVariableHandler ( Status = EFI_ACCESS_DENIED; } else { CommVariableProperty = (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *)SmmVariableFunctionHeader->Data; - Status = mVariableStorage->PropertySet ( - CommVariableProperty->Name, - &CommVariableProperty->Guid, - &CommVariableProperty->VariableProperty - ); + Status = VariableStorageRouterLibPropertySet ( + CommVariableProperty->Name, + &CommVariableProperty->Guid, + &CommVariableProperty->VariableProperty + ); } break; @@ -621,11 +485,11 @@ SmmVariableHandler ( goto EXIT; } - Status = mVariableStorage->PropertyGet ( - CommVariableProperty->Name, - &CommVariableProperty->Guid, - &CommVariableProperty->VariableProperty - ); + Status = VariableStorageRouterLibPropertyGet ( + CommVariableProperty->Name, + &CommVariableProperty->Guid, + &CommVariableProperty->VariableProperty + ); CopyMem (SmmVariableFunctionHeader->Data, mVariableBufferPayload, CommBufferPayloadSize); break; @@ -739,18 +603,18 @@ SmmVariableHandler ( goto EXIT; } - Status = mVariableStorage->InitCache ( - RuntimeVariableCacheContext->RuntimeHobCache, - RuntimeVariableCacheContext->RuntimeVolatileCache, - RuntimeVariableCacheContext->RuntimeNvCache, - RuntimeVariableCacheContext->PendingUpdate, - RuntimeVariableCacheContext->ReadLock, - RuntimeVariableCacheContext->HobFlushComplete - ); + Status = VariableStorageRouterLibInitCache ( + RuntimeVariableCacheContext->RuntimeHobCache, + RuntimeVariableCacheContext->RuntimeVolatileCache, + RuntimeVariableCacheContext->RuntimeNvCache, + RuntimeVariableCacheContext->PendingUpdate, + RuntimeVariableCacheContext->ReadLock, + RuntimeVariableCacheContext->HobFlushComplete + ); break; case SMM_VARIABLE_FUNCTION_SYNC_RUNTIME_CACHE: - Status = mVariableStorage->SyncCache (); + Status = VariableStorageRouterLibSyncCache (); break; case SMM_VARIABLE_FUNCTION_GET_RUNTIME_CACHE_INFO: @@ -761,13 +625,13 @@ SmmVariableHandler ( GetRuntimeCacheInfo = (SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO *)SmmVariableFunctionHeader->Data; - GetRuntimeCacheInfo->AuthenticatedVariableUsage = mVariableStorage->CheckAuthFormat (); + GetRuntimeCacheInfo->AuthenticatedVariableUsage = VariableStorageRouterLibCheckAuthFormat (); - Status = mVariableStorage->GetCacheInfo ( - &GetRuntimeCacheInfo->TotalHobStorageSize, - &GetRuntimeCacheInfo->TotalVolatileStorageSize, - &GetRuntimeCacheInfo->TotalNvStorageSize - ); + Status = VariableStorageRouterLibGetCacheInfo ( + &GetRuntimeCacheInfo->TotalHobStorageSize, + &GetRuntimeCacheInfo->TotalVolatileStorageSize, + &GetRuntimeCacheInfo->TotalNvStorageSize + ); break; default: @@ -803,7 +667,7 @@ SmmEndOfDxeCallback ( if (!mEndOfDxe) { mEndOfDxe = TRUE; - return mVariableStorage->EndOfDxe (); + return VariableStorageRouterLibEndOfDxe (); } return EFI_SUCCESS; @@ -828,13 +692,6 @@ MmVariableServiceInitialize ( EFI_HANDLE VariableHandle; VOID *SmmEndOfDxeRegistration; - Status = gMmst->MmLocateProtocol ( - &gEdkiiVariableStorageProtocolGuid, - NULL, - (VOID **)&mVariableStorage - ); - ASSERT_EFI_ERROR (Status); - // // Install the Smm Variable Protocol on a new handle. // @@ -847,7 +704,7 @@ MmVariableServiceInitialize ( ); ASSERT_EFI_ERROR (Status); - mVariableBufferPayloadSize = mVariableStorage->GetMaxVariableSize () + + mVariableBufferPayloadSize = VariableStorageRouterLibGetMaxVariableSize () + OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name) - GetVariableHeaderSize (); @@ -883,7 +740,7 @@ MmVariableServiceInitialize ( // // Notify the variable wrapper driver the variable service is ready // - Status = mVariableStorage->InitWriteService (VariableNotifySmmWriteReady); + Status = VariableStorageRouterLibInitWriteService (VariableNotifySmmWriteReady); ASSERT_EFI_ERROR (Status); return EFI_SUCCESS; diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf index 57557e0eaf..5e8ebef035 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf @@ -64,6 +64,7 @@ UefiLib SafeIntLib SmmMemLib + VariableStorageRouterLib [Protocols] ## PRODUCES @@ -76,7 +77,7 @@ gSmmVariableWriteGuid ## PRODUCES ## GUID # Install protocol [Depex] - gEdkiiVariableStorageProtocolGuid + TRUE [UserExtensions.TianoCore."ExtraFiles"] VariableSmmExtra.uni diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf index f0b5012e5c..25f7201553 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf @@ -56,16 +56,16 @@ SafeIntLib StandaloneMmDriverEntryPoint SynchronizationLib + VariableStorageRouterLib [Protocols] ## PRODUCES ## UNDEFINED # SmiHandlerRegister gEfiSmmVariableProtocolGuid gEfiMmEndOfDxeProtocolGuid ## NOTIFY - gEdkiiVariableStorageProtocolGuid ## COUNSUMES [Guids] gSmmVariableWriteGuid ## PRODUCES ## GUID # Install protocol [Depex] - gEdkiiVariableStorageProtocolGuid + TRUE