TianoCore EDK2 master
Loading...
Searching...
No Matches
SmmStm.c File Reference

Go to the source code of this file.

Macros

#define TXT_EVTYPE_BASE   0x400
 
#define TXT_EVTYPE_STM_HASH   (TXT_EVTYPE_BASE + 14)
 
#define RDWR_ACCS   3
 
#define FULL_ACCS   7
 
#define CPUID1_EDX_XD_SUPPORT   0x100000
 

Functions

EFI_STATUS EFIAPI SmmCpuFeaturesLibStmConstructor (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
 
VOID FinishSmmCpuFeaturesInitializeProcessor (VOID)
 
UINTN EFIAPI SmmCpuFeaturesGetSmiHandlerSize (VOID)
 
VOID EFIAPI SmmCpuFeaturesInstallSmiHandler (IN UINTN CpuIndex, IN UINT32 SmBase, IN VOID *SmiStack, IN UINTN StackSize, IN UINTN GdtBase, IN UINTN GdtSize, IN UINTN IdtBase, IN UINTN IdtSize, IN UINT32 Cr3)
 
EFI_STATUS EFIAPI SmmEndOfDxeEventNotify (IN CONST EFI_GUID *Protocol, IN VOID *Interface, IN EFI_HANDLE Handle)
 
VOID StmSmmConfigurationTableInit (VOID)
 
EFI_SM_MONITOR_STATE EFIAPI GetMonitorState (VOID)
 
BOOLEAN HandleSingleResource (IN STM_RSC *Resource, IN STM_RSC *Record)
 
VOID AddSingleResource (IN STM_RSC *Resource)
 
VOID AddResource (IN STM_RSC *ResourceList, IN UINT32 NumEntries OPTIONAL)
 
BOOLEAN ValidateResource (IN STM_RSC *ResourceList, IN UINT32 NumEntries OPTIONAL)
 
UINTN GetResourceSize (IN STM_RSC *ResourceList, IN UINT32 NumEntries OPTIONAL)
 
EFI_STATUS EFIAPI AddPiResource (IN STM_RSC *ResourceList, IN UINT32 NumEntries OPTIONAL)
 
EFI_STATUS EFIAPI DeletePiResource (IN STM_RSC *ResourceList, IN UINT32 NumEntries OPTIONAL)
 
EFI_STATUS EFIAPI GetPiResource (OUT STM_RSC *ResourceList, IN OUT UINT32 *ResourceSize)
 
VOID EFIAPI EnableMsegMsr (IN VOID *Buffer)
 
UINT32 GetVmcsSize (VOID)
 
BOOLEAN StmCheckStmImage (IN EFI_PHYSICAL_ADDRESS StmImage, IN UINTN StmImageSize)
 
VOID StmLoadStmImage (IN EFI_PHYSICAL_ADDRESS StmImage, IN UINTN StmImageSize)
 
EFI_STATUS EFIAPI LoadMonitor (IN EFI_PHYSICAL_ADDRESS StmImage, IN UINTN StmImageSize)
 
VOID * GetStmResource (VOID)
 
VOID NotifyStmResourceChange (VOID *StmResource)
 
VOID EFIAPI SmmStmSetup (VOID)
 
VOID EFIAPI SmmStmTeardown (VOID)
 

Variables

EFI_HANDLE mStmSmmCpuHandle = NULL
 
BOOLEAN mLockLoadMonitor = FALSE
 
GLOBAL_REMOVE_IF_UNREFERENCED STM_RSC_END mRscEndNode
 
GLOBAL_REMOVE_IF_UNREFERENCED UINT8 * mStmResourcesPtr = NULL
 
GLOBAL_REMOVE_IF_UNREFERENCED UINTN mStmResourceTotalSize = 0x0
 
GLOBAL_REMOVE_IF_UNREFERENCED UINTN mStmResourceSizeUsed = 0x0
 
GLOBAL_REMOVE_IF_UNREFERENCED UINTN mStmResourceSizeAvailable = 0x0
 
GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mStmState = 0
 
GLOBAL_REMOVE_IF_UNREFERENCED EFI_SM_MONITOR_INIT_PROTOCOL mSmMonitorInitProtocol
 
CONST TXT_PROCESSOR_SMM_DESCRIPTOR gcStmPsd
 
UINT32 gStmSmbase
 
volatile UINT32 gStmSmiStack
 
UINT32 gStmSmiCr3
 
volatile UINT8 gcStmSmiHandlerTemplate []
 
CONST UINT16 gcStmSmiHandlerSize
 
UINT16 gcStmSmiHandlerOffset
 
BOOLEAN gStmXdSupported
 
IA32_DESCRIPTOR gStmSmiHandlerIdtr
 
EFI_MP_SERVICES_PROTOCOLmSmmCpuFeaturesLibMpService = NULL
 
UINTN mMsegBase = 0
 
UINTN mMsegSize = 0
 
BOOLEAN mStmConfigurationTableInitialized = FALSE
 

Detailed Description

SMM STM support functions

Copyright (c) 2015 - 2023, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file SmmStm.c.

Macro Definition Documentation

◆ CPUID1_EDX_XD_SUPPORT

#define CPUID1_EDX_XD_SUPPORT   0x100000

Definition at line 59 of file SmmStm.c.

◆ FULL_ACCS

#define FULL_ACCS   7

Definition at line 27 of file SmmStm.c.

◆ RDWR_ACCS

#define RDWR_ACCS   3

Definition at line 26 of file SmmStm.c.

◆ TXT_EVTYPE_BASE

#define TXT_EVTYPE_BASE   0x400

Definition at line 23 of file SmmStm.c.

◆ TXT_EVTYPE_STM_HASH

#define TXT_EVTYPE_STM_HASH   (TXT_EVTYPE_BASE + 14)

Definition at line 24 of file SmmStm.c.

Function Documentation

◆ AddPiResource()

EFI_STATUS EFIAPI AddPiResource ( IN STM_RSC ResourceList,
IN UINT32 NumEntries  OPTIONAL 
)

Add resources in list to database. Allocate new memory areas as needed.

Parameters
ResourceListA pointer to resource list to be added
NumEntriesOptional number of entries. If 0, list must be terminated by END_OF_RESOURCES.
Return values
EFI_SUCCESSIf resources are added
EFI_INVALID_PARAMETERIf nested procedure detected resource failer
EFI_OUT_OF_RESOURCESIf nested procedure returned it and we cannot allocate more areas.

Definition at line 880 of file SmmStm.c.

◆ AddResource()

VOID AddResource ( IN STM_RSC ResourceList,
IN UINT32 NumEntries  OPTIONAL 
)

Add resource list.

Parameters
ResourceListA pointer to resource list to be added
NumEntriesOptional number of entries. If 0, list must be terminated by END_OF_RESOURCES.

Definition at line 660 of file SmmStm.c.

◆ AddSingleResource()

VOID AddSingleResource ( IN STM_RSC Resource)

Add resource node.

Parameters
ResourceA pointer to resource node to be added

Definition at line 600 of file SmmStm.c.

◆ DeletePiResource()

EFI_STATUS EFIAPI DeletePiResource ( IN STM_RSC ResourceList,
IN UINT32 NumEntries  OPTIONAL 
)

Delete resources in list to database.

Parameters
ResourceListA pointer to resource list to be deleted NULL means delete all resources.
NumEntriesOptional number of entries. If 0, list must be terminated by END_OF_RESOURCES.
Return values
EFI_SUCCESSIf resources are deleted
EFI_INVALID_PARAMETERIf nested procedure detected resource failer

Definition at line 988 of file SmmStm.c.

◆ EnableMsegMsr()

VOID EFIAPI EnableMsegMsr ( IN VOID *  Buffer)

Set valid bit for MSEG MSR.

Parameters
BufferAp function buffer. (not used)

Definition at line 1047 of file SmmStm.c.

◆ FinishSmmCpuFeaturesInitializeProcessor()

VOID FinishSmmCpuFeaturesInitializeProcessor ( VOID  )

Internal worker function that is called to complete CPU initialization at the end of SmmCpuFeaturesInitializeProcessor().

Definition at line 173 of file SmmStm.c.

◆ GetMonitorState()

EFI_SM_MONITOR_STATE EFIAPI GetMonitorState ( VOID  )

Get STM state.

Returns
STM state

Definition at line 446 of file SmmStm.c.

◆ GetPiResource()

EFI_STATUS EFIAPI GetPiResource ( OUT STM_RSC ResourceList,
IN OUT UINT32 *  ResourceSize 
)

Get BIOS resources.

Parameters
ResourceListA pointer to resource list to be filled
ResourceSizeOn input it means size of resource list input. On output it means size of resource list filled, or the size of resource list to be filled if size of too small.
Return values
EFI_SUCCESSIf resources are returned.
EFI_BUFFER_TOO_SMALLIf resource list buffer is too small to hold the whole resources.

Definition at line 1023 of file SmmStm.c.

◆ GetResourceSize()

UINTN GetResourceSize ( IN STM_RSC ResourceList,
IN UINT32 NumEntries  OPTIONAL 
)

Get resource list. EndResource is excluded.

Parameters
ResourceListA pointer to resource list to be added
NumEntriesOptional number of entries. If 0, list must be terminated by END_OF_RESOURCES.
Return values
TRUEresource valid
FALSEresource invalid

Definition at line 828 of file SmmStm.c.

◆ GetStmResource()

VOID * GetStmResource ( VOID  )

This function return BIOS STM resource. Produced by SmmStm. Consumed by SmmMpService when Init.

Returns
BIOS STM resource

Definition at line 1250 of file SmmStm.c.

◆ GetVmcsSize()

UINT32 GetVmcsSize ( VOID  )

Get 4K page aligned VMCS size.

Returns
4K page aligned VMCS size

Definition at line 1066 of file SmmStm.c.

◆ HandleSingleResource()

BOOLEAN HandleSingleResource ( IN STM_RSC Resource,
IN STM_RSC Record 
)

Handle single Resource to see if it can be merged into Record.

Parameters
ResourceA pointer to resource node to be added
RecordA pointer to record node to be merged
Return values
TRUEresource handled
FALSEresource is not handled

Definition at line 465 of file SmmStm.c.

◆ LoadMonitor()

EFI_STATUS EFIAPI LoadMonitor ( IN EFI_PHYSICAL_ADDRESS  StmImage,
IN UINTN  StmImageSize 
)

Load STM image to MSEG.

Parameters
StmImageSTM image
StmImageSizeSTM image size
Return values
EFI_SUCCESSLoad STM to MSEG successfully
EFI_ALREADY_STARTEDSTM image is already loaded to MSEG
EFI_BUFFER_TOO_SMALLMSEG is smaller than minimal requirement of STM image
EFI_UNSUPPORTEDMSEG is not enabled

Definition at line 1204 of file SmmStm.c.

◆ NotifyStmResourceChange()

VOID NotifyStmResourceChange ( VOID *  StmResource)

This function notify STM resource change.

Parameters
StmResourceBIOS STM resource

Definition at line 1264 of file SmmStm.c.

◆ SmmCpuFeaturesGetSmiHandlerSize()

UINTN EFIAPI SmmCpuFeaturesGetSmiHandlerSize ( VOID  )

Return the size, in bytes, of a custom SMI Handler in bytes. If 0 is returned, then a custom SMI handler is not provided by this library, and the default SMI handler must be used.

Return values
0Use the default SMI handler.
>0 Use the SMI handler installed by SmmCpuFeaturesInstallSmiHandler() The caller is required to allocate enough SMRAM for each CPU to support the size of the custom SMI handler.

Definition at line 202 of file SmmStm.c.

◆ SmmCpuFeaturesInstallSmiHandler()

VOID EFIAPI SmmCpuFeaturesInstallSmiHandler ( IN UINTN  CpuIndex,
IN UINT32  SmBase,
IN VOID *  SmiStack,
IN UINTN  StackSize,
IN UINTN  GdtBase,
IN UINTN  GdtSize,
IN UINTN  IdtBase,
IN UINTN  IdtSize,
IN UINT32  Cr3 
)

Install a custom SMI handler for the CPU specified by CpuIndex. This function is only called if SmmCpuFeaturesGetSmiHandlerSize() returns a size is greater than zero and is called by the CPU that was elected as monarch during System Management Mode initialization.

Parameters
[in]CpuIndexThe index of the CPU to install the custom SMI handler. The value must be between 0 and the NumberOfCpus field in the System Management System Table (SMST).
[in]SmBaseThe SMBASE address for the CPU specified by CpuIndex.
[in]SmiStackThe stack to use when an SMI is processed by the the CPU specified by CpuIndex.
[in]StackSizeThe size, in bytes, if the stack used when an SMI is processed by the CPU specified by CpuIndex.
[in]GdtBaseThe base address of the GDT to use when an SMI is processed by the CPU specified by CpuIndex.
[in]GdtSizeThe size, in bytes, of the GDT used when an SMI is processed by the CPU specified by CpuIndex.
[in]IdtBaseThe base address of the IDT to use when an SMI is processed by the CPU specified by CpuIndex.
[in]IdtSizeThe size, in bytes, of the IDT used when an SMI is processed by the CPU specified by CpuIndex.
[in]Cr3The base address of the page tables to use when an SMI is processed by the CPU specified by CpuIndex.

Definition at line 236 of file SmmStm.c.

◆ SmmCpuFeaturesLibStmConstructor()

EFI_STATUS EFIAPI SmmCpuFeaturesLibStmConstructor ( IN EFI_HANDLE  ImageHandle,
IN EFI_SYSTEM_TABLE SystemTable 
)

The constructor function for the Traditional MM library instance with STM.

Parameters
[in]ImageHandleThe firmware allocated handle for the EFI image.
[in]SystemTableA pointer to the EFI System Table.
Return values
EFI_SUCCESSThe constructor always returns EFI_SUCCESS.

Definition at line 102 of file SmmStm.c.

◆ SmmEndOfDxeEventNotify()

EFI_STATUS EFIAPI SmmEndOfDxeEventNotify ( IN CONST EFI_GUID Protocol,
IN VOID *  Interface,
IN EFI_HANDLE  Handle 
)

SMM End Of Dxe event notification handler.

STM support need patch AcpiRsdp in TXT_PROCESSOR_SMM_DESCRIPTOR.

Parameters
[in]ProtocolPoints to the protocol's unique identifier.
[in]InterfacePoints to the interface instance.
[in]HandleThe handle on which the interface was installed.
Return values
EFI_SUCCESSNotification handler runs successfully.

Definition at line 357 of file SmmStm.c.

◆ SmmStmSetup()

VOID EFIAPI SmmStmSetup ( VOID  )

This is STM setup BIOS callback.

Definition at line 1284 of file SmmStm.c.

◆ SmmStmTeardown()

VOID EFIAPI SmmStmTeardown ( VOID  )

This is STM teardown BIOS callback.

Definition at line 1296 of file SmmStm.c.

◆ StmCheckStmImage()

BOOLEAN StmCheckStmImage ( IN EFI_PHYSICAL_ADDRESS  StmImage,
IN UINTN  StmImageSize 
)

Check STM image size.

Parameters
StmImageSTM image
StmImageSizeSTM image size
Return values
TRUEcheck pass
FALSEcheck fail

Definition at line 1090 of file SmmStm.c.

◆ StmLoadStmImage()

VOID StmLoadStmImage ( IN EFI_PHYSICAL_ADDRESS  StmImage,
IN UINTN  StmImageSize 
)

Load STM image to MSEG.

Parameters
StmImageSTM image
StmImageSizeSTM image size

Definition at line 1156 of file SmmStm.c.

◆ StmSmmConfigurationTableInit()

VOID StmSmmConfigurationTableInit ( VOID  )

This function initializes the STM configuration table.

Definition at line 410 of file SmmStm.c.

◆ ValidateResource()

BOOLEAN ValidateResource ( IN STM_RSC ResourceList,
IN UINT32 NumEntries  OPTIONAL 
)

Validate resource list.

Parameters
ResourceListA pointer to resource list to be added
NumEntriesOptional number of entries. If 0, list must be terminated by END_OF_RESOURCES.
Return values
TRUEresource valid
FALSEresource invalid

Definition at line 702 of file SmmStm.c.

Variable Documentation

◆ gStmSmiHandlerIdtr

IA32_DESCRIPTOR gStmSmiHandlerIdtr

Definition at line 76 of file SmmStm.c.

◆ mLockLoadMonitor

BOOLEAN mLockLoadMonitor = FALSE

Definition at line 31 of file SmmStm.c.

◆ mMsegBase

UINTN mMsegBase = 0

Definition at line 86 of file SmmStm.c.

◆ mMsegSize

UINTN mMsegSize = 0

Definition at line 87 of file SmmStm.c.

◆ mRscEndNode

Initial value:
= {
}
#define END_OF_RESOURCES

Definition at line 36 of file SmmStm.c.

◆ mSmmCpuFeaturesLibMpService

EFI_MP_SERVICES_PROTOCOL* mSmmCpuFeaturesLibMpService = NULL

Definition at line 81 of file SmmStm.c.

◆ mSmMonitorInitProtocol

Initial value:
= {
}
EFI_STATUS EFIAPI DeletePiResource(IN STM_RSC *ResourceList, IN UINT32 NumEntries OPTIONAL)
Definition: SmmStm.c:988
EFI_SM_MONITOR_STATE EFIAPI GetMonitorState(VOID)
Definition: SmmStm.c:446
EFI_STATUS EFIAPI GetPiResource(OUT STM_RSC *ResourceList, IN OUT UINT32 *ResourceSize)
Definition: SmmStm.c:1023
EFI_STATUS EFIAPI AddPiResource(IN STM_RSC *ResourceList, IN UINT32 NumEntries OPTIONAL)
Definition: SmmStm.c:880
EFI_STATUS EFIAPI LoadMonitor(IN EFI_PHYSICAL_ADDRESS StmImage, IN UINTN StmImageSize)
Definition: SmmStm.c:1204

Definition at line 51 of file SmmStm.c.

◆ mStmConfigurationTableInitialized

BOOLEAN mStmConfigurationTableInitialized = FALSE

Definition at line 89 of file SmmStm.c.

◆ mStmResourceSizeAvailable

GLOBAL_REMOVE_IF_UNREFERENCED UINTN mStmResourceSizeAvailable = 0x0

Definition at line 43 of file SmmStm.c.

◆ mStmResourceSizeUsed

GLOBAL_REMOVE_IF_UNREFERENCED UINTN mStmResourceSizeUsed = 0x0

Definition at line 42 of file SmmStm.c.

◆ mStmResourcesPtr

GLOBAL_REMOVE_IF_UNREFERENCED UINT8* mStmResourcesPtr = NULL

Definition at line 40 of file SmmStm.c.

◆ mStmResourceTotalSize

GLOBAL_REMOVE_IF_UNREFERENCED UINTN mStmResourceTotalSize = 0x0

Definition at line 41 of file SmmStm.c.

◆ mStmSmmCpuHandle

EFI_HANDLE mStmSmmCpuHandle = NULL

Definition at line 29 of file SmmStm.c.

◆ mStmState

GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mStmState = 0

Definition at line 45 of file SmmStm.c.