UefiPayloadPkg: Add support for Firmware Volume Block Protocol
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>
This commit is contained in:
committed by
Tim Crawford
parent
d3b38ea28a
commit
0bef9ccd43
@@ -236,6 +236,19 @@ struct cb_cbmem_tab {
|
||||
UINT64 cbmem_tab;
|
||||
};
|
||||
|
||||
#define CB_TAG_SMMSTOREV2 0x0039
|
||||
struct cb_smmstorev2 {
|
||||
UINT32 tag;
|
||||
UINT32 size;
|
||||
UINT32 num_blocks; /* Number of writeable blocks in SMM */
|
||||
UINT32 block_size; /* Size of a block in byte. Default: 64 KiB */
|
||||
UINT32 mmap_addr; /* MMIO address of the store for read only access */
|
||||
UINT32 com_buffer; /* Physical address of the communication buffer */
|
||||
UINT32 com_buffer_size; /* Size of the communication buffer in byte */
|
||||
UINT8 apm_cmd; /* The command byte to write to the APM I/O port */
|
||||
UINT8 unused[3]; /* Set to zero */
|
||||
};
|
||||
|
||||
/* Helpful macros */
|
||||
|
||||
#define MEM_RANGE_COUNT(_rec) \
|
||||
|
27
UefiPayloadPkg/Include/Guid/SMMSTOREInfoGuid.h
Normal file
27
UefiPayloadPkg/Include/Guid/SMMSTOREInfoGuid.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/** @file
|
||||
This file defines the hob structure for system tables like ACPI, SMBIOS tables.
|
||||
|
||||
Copyright (c) 2020, 9elements Agency GmbH<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#ifndef __SMMSTORE_GUID_H__
|
||||
#define __SMMSTORE_GUID_H__
|
||||
|
||||
///
|
||||
/// System Table Information GUID
|
||||
///
|
||||
extern EFI_GUID gEfiSMMSTOREInfoHobGuid;
|
||||
|
||||
typedef struct {
|
||||
UINT64 ComBuffer;
|
||||
UINT32 ComBufferSize;
|
||||
UINT32 NumBlocks;
|
||||
UINT32 BlockSize;
|
||||
UINT64 MmioAddress;
|
||||
UINT8 ApmCmd;
|
||||
UINT8 Reserved0[3];
|
||||
} SMMSTORE_INFO;
|
||||
|
||||
#endif
|
@@ -12,6 +12,7 @@
|
||||
#include <Guid/SerialPortInfoGuid.h>
|
||||
#include <Guid/SystemTableInfoGuid.h>
|
||||
#include <Guid/AcpiBoardInfoGuid.h>
|
||||
#include <Guid/SMMSTOREInfoGuid.h>
|
||||
|
||||
#ifndef __BOOTLOADER_PARSE_LIB__
|
||||
#define __BOOTLOADER_PARSE_LIB__
|
||||
@@ -117,4 +118,19 @@ ParseGfxDeviceInfo (
|
||||
OUT EFI_PEI_GRAPHICS_DEVICE_INFO_HOB *GfxDeviceInfo
|
||||
);
|
||||
|
||||
/**
|
||||
Find the video frame buffer device information
|
||||
|
||||
@param SMMSTOREInfo Pointer to the SMMSTORE_INFO structure
|
||||
|
||||
@retval RETURN_SUCCESS Successfully find the SMM store buffer information.
|
||||
@retval RETURN_NOT_FOUND Failed to find the SMM store buffer information .
|
||||
|
||||
**/
|
||||
RETURN_STATUS
|
||||
EFIAPI
|
||||
ParseSMMSTOREInfo (
|
||||
OUT SMMSTORE_INFO *SMMSTOREInfo
|
||||
);
|
||||
|
||||
#endif
|
||||
|
98
UefiPayloadPkg/Include/Library/SMMStoreLib.h
Normal file
98
UefiPayloadPkg/Include/Library/SMMStoreLib.h
Normal file
@@ -0,0 +1,98 @@
|
||||
/** @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__ */
|
Reference in New Issue
Block a user