This adds support for FVB in order to support a platform independent and non-volatile variable store on UefiPayloadPkg. It is required for non-volatile variable support, TPM support, Secureboot support and more. Since commit bc744f5893fc4d53275ed26dd8d968011c6a09c1 coreboot supports the SMMSTORE v2 feature. It implements a 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. Add a library for SMMStore to be used in DXE. The DXE component provides runtime services and takes care of virtual to physical mapping the communication buffers between SMM and OS. Make use of the APRIORI DXE to initialize an empty store on the first boot and set the PCDs to sane values before the variable driver is loaded. Tests on Intel(R) Xeon(R) E-2288G CPU @ 3.70G showed that the SMI isn't triggered with a probability of 1:40 of all cases when called in a tight loop. The CPU continues running and the SMI is triggeres asynchronously a few clock cycles later. coreboot only handels synchronous APM request and does nothing on asynchronous APM triggers. As there's no livesign from SMM it's impossible to tell if the handler has run. Just wait a bit and try again to trigger a synchronous SMI. Tests confirmed that out of 5 million tries the SMI is now always handled. Tested on Linux and Windows 10 on real hardware. Currently this cannot be tested on coreboot and qemu as it doesn't support the SMMSTORE on qemu. Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
99 lines
2.6 KiB
C
99 lines
2.6 KiB
C
/** @file SMMStoreLib.h
|
|
|
|
Copyright (c) 2020, 9elements Agency GmbH<BR>
|
|
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
|
|
|
**/
|
|
|
|
#ifndef __SMM_STORE_LIB_H__
|
|
#define __SMM_STORE_LIB_H__
|
|
|
|
#include <Base.h>
|
|
#include <Uefi/UefiBaseType.h>
|
|
#include <Guid/SMMSTOREInfoGuid.h>
|
|
|
|
#define SMMSTORE_COMBUF_SIZE 16
|
|
|
|
/**
|
|
Read from SMMStore
|
|
|
|
@param[in] Lba The starting logical block index to read from.
|
|
@param[in] Offset Offset into the block at which to begin reading.
|
|
@param[in] NumBytes On input, indicates the requested read size. On
|
|
output, indicates the actual number of bytes read
|
|
@param[in] Buffer Pointer to the buffer to read into.
|
|
|
|
**/
|
|
EFI_STATUS
|
|
SMMStoreRead (
|
|
IN EFI_LBA Lba,
|
|
IN UINTN Offset,
|
|
IN UINTN *NumBytes,
|
|
IN UINT8 *Buffer
|
|
);
|
|
|
|
|
|
/**
|
|
Write to SMMStore
|
|
|
|
@param[in] Lba The starting logical block index to write to.
|
|
@param[in] Offset Offset into the block at which to begin writing.
|
|
@param[in] NumBytes On input, indicates the requested write size. On
|
|
output, indicates the actual number of bytes written
|
|
@param[in] Buffer Pointer to the data to write.
|
|
|
|
**/
|
|
EFI_STATUS
|
|
SMMStoreWrite (
|
|
IN EFI_LBA Lba,
|
|
IN UINTN Offset,
|
|
IN UINTN *NumBytes,
|
|
IN UINT8 *Buffer
|
|
);
|
|
|
|
|
|
/**
|
|
Erase a block using the SMMStore
|
|
|
|
@param Lba The logical block index to erase.
|
|
|
|
**/
|
|
EFI_STATUS
|
|
SMMStoreEraseBlock (
|
|
IN EFI_LBA Lba
|
|
);
|
|
|
|
|
|
/**
|
|
Notify the SMMStore Library about a VirtualNotify
|
|
|
|
**/
|
|
|
|
VOID
|
|
EFIAPI
|
|
SMMStoreVirtualNotifyEvent (
|
|
IN EFI_EVENT Event,
|
|
IN VOID *Context
|
|
);
|
|
|
|
/**
|
|
Initializes SMMStore support
|
|
|
|
@param[in] Ptr A runtime buffer where arguments are stored
|
|
for SMM communication
|
|
@param[in] SmmStoreInfoHob A runtime buffer with a copy of the
|
|
SmmStore Info Hob
|
|
|
|
@retval EFI_WRITE_PROTECTED The SMMSTORE is not present.
|
|
@retval EFI_SUCCESS The SMMSTORE is supported.
|
|
|
|
**/
|
|
EFI_STATUS
|
|
SMMStoreInitialize (
|
|
IN VOID *Ptr,
|
|
IN SMMSTORE_INFO *SmmStoreInfoHob
|
|
);
|
|
|
|
#endif /* __SMM_STORE_LIB_H__ */
|