edk2/MdeModulePkg/Library/VariableStorageRouterBaseLib/VariableStorageRouterBaseStandaloneMmLib.c
Yeoreum Yun 0637e4054e 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 <yeoreum.yun@arm.com>
2026-07-29 13:02:10 +01:00

37 lines
959 B
C

/** @file
Variable Storage Router Base Library
Copyright (c) 2026, Arm Ltd. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Library/BaseLib.h>
#include <Library/MmServicesTableLib.h>
#include <Protocol/VariableStorage.h>
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
);
}