Files
EDK2-fork/UefiPayloadPkg/SmmStoreFvb/SmmStoreFvbRuntime.h
Sean Rhodes d8531a1e1a UefiPayloadPkg: Add support for Firmware Volume Block Protocol
This adds support for FVB in order to support a platform-independent
non-volatile variable store on UefiPayloadPkg. The variable store makes
use of the SmmStoreLib to provide an unauthenticated variable store.

Since commit bc744f5893fc4d53275ed26dd8d968011c6a09c1 coreboot supports
the SMMSTORE v2 feature. It implements an SMI handler that is able to
write, read and erase pages in the boot media (SPI flash).
The communication is done using a fixed communication buffer that is
allocated in CBMEM. The existence of this optional feature is advertised
by a coreboot table. When the SMMSTORE feature is not available, the
variable emulation is used by setting PcdEmuVariableNvModeEnable to
TRUE.

The DXE component provides runtime services and takes care of virtual to
physical mapping the communication buffers between SMM and OS.

The contents of the variable store can be accessed and modified by any
privileged application. As authentication is done by runtime services
only the store shouldn't be used to store authenticated variables.

Tested on Linux and Windows on a variety of real hardware.
This can also be tested in QEMU starting with coreboot 24.12 using
qemu-q35 board.

Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
Signed-off-by: Sean Rhodes <sean@starlabs.systems>
Signed-off-by: Matt DeVillier <matt.devillier@gmail.com>
Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
2025-04-09 18:12:48 +00:00

112 lines
2.8 KiB
C

/** @file SmmStoreFvbRuntime.h
Copyright (c) 2022, 9elements GmbH<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef SMM_STORE_DXE_H_
#define SMM_STORE_DXE_H_
#include <Base.h>
#include <PiDxe.h>
#include <Guid/EventGroup.h>
#include <Protocol/FirmwareVolumeBlock.h>
#include <Library/DebugLib.h>
#include <Library/IoLib.h>
#include <Library/UefiLib.h>
#include <Library/UefiRuntimeLib.h>
#define SMMSTORE_SIGNATURE SIGNATURE_32('S', 'M', 'M', 'S')
#define INSTANCE_FROM_FVB_THIS(a) CR(a, SMMSTORE_INSTANCE, FvbProtocol, SMMSTORE_SIGNATURE)
typedef struct _SMMSTORE_INSTANCE SMMSTORE_INSTANCE;
typedef struct {
MEMMAP_DEVICE_PATH MemMapDevPath;
EFI_DEVICE_PATH_PROTOCOL EndDevPath;
} FV_MEMMAP_DEVICE_PATH;
struct _SMMSTORE_INSTANCE {
UINT32 Signature;
EFI_HANDLE Handle;
EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL FvbProtocol;
UINTN BlockSize;
UINTN LastBlock;
EFI_PHYSICAL_ADDRESS MmioAddress;
FV_MEMMAP_DEVICE_PATH DevicePath;
};
//
// SmmStoreFvbRuntimeDxe.c
//
EFI_STATUS
EFIAPI
FvbInitialize (
IN SMMSTORE_INSTANCE *Instance
);
EFI_STATUS
EFIAPI
FvbGetAttributes (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
OUT EFI_FVB_ATTRIBUTES_2 *Attributes
);
EFI_STATUS
EFIAPI
FvbSetAttributes (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes
);
EFI_STATUS
EFIAPI
FvbGetPhysicalAddress (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
OUT EFI_PHYSICAL_ADDRESS *Address
);
EFI_STATUS
EFIAPI
FvbGetBlockSize (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
IN EFI_LBA Lba,
OUT UINTN *BlockSize,
OUT UINTN *NumberOfBlocks
);
EFI_STATUS
EFIAPI
FvbRead (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
IN EFI_LBA Lba,
IN UINTN Offset,
IN OUT UINTN *NumBytes,
IN OUT UINT8 *Buffer
);
EFI_STATUS
EFIAPI
FvbWrite (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
IN EFI_LBA Lba,
IN UINTN Offset,
IN OUT UINTN *NumBytes,
IN UINT8 *Buffer
);
EFI_STATUS
EFIAPI
FvbEraseBlocks (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
...
);
#endif // SMM_STORE_DXE_H_