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

Go to the source code of this file.

Data Structures

struct  PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT
 

Macros

#define PERIODIC_SMI_LIBRARY_ALLOCATE_SIZE   0x08
 
#define PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_SIGNATURE   SIGNATURE_32 ('P', 'S', 'M', 'I')
 
#define PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_FROM_LINK(a)
 

Functions

PERIODIC_SMI_LIBRARY_HANDLER_CONTEXTGetActivePeriodicSmiLibraryHandler (VOID)
 
PERIODIC_SMI_LIBRARY_HANDLER_CONTEXTLookupPeriodicSmiLibraryHandler (IN EFI_HANDLE DispatchHandle OPTIONAL)
 
PERIODIC_SMI_LIBRARY_HANDLER_CONTEXTSetActivePeriodicSmiLibraryHandler (IN EFI_HANDLE DispatchHandle OPTIONAL)
 
VOID ReclaimPeriodicSmiLibraryHandler (PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *PeriodicSmiLibraryHandler)
 
BOOLEAN EnlargeFreePeriodicSmiLibraryHandlerList (VOID)
 
PERIODIC_SMI_LIBRARY_HANDLER_CONTEXTFindFreePeriodicSmiLibraryHandler (VOID)
 
UINT64 *EFIAPI PeriodicSmiSupportedTickPeriod (VOID)
 
UINT64 EFIAPI PeriodicSmiExecutionTime (VOID)
 
VOID EFIAPI PeriodicSmiExit (VOID)
 
UINT64 EFIAPI PeriodicSmiYield (VOID)
 
VOID EFIAPI PeriodicSmiDispatchFunctionSwitchStack (IN VOID *Context1 OPTIONAL, IN VOID *Context2 OPTIONAL)
 
VOID EFIAPI PeriodicSmiDispatchFunctionOnCpu (PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *PeriodicSmiLibraryHandler)
 
VOID EFIAPI PeriodicSmiDispatchFunctionWithLock (IN OUT VOID *Buffer)
 
EFI_STATUS EFIAPI PeriodicSmiDispatchFunction (IN EFI_HANDLE DispatchHandle, IN CONST VOID *Context OPTIONAL, IN OUT VOID *CommBuffer OPTIONAL, IN OUT UINTN *CommBufferSize OPTIONAL)
 
EFI_STATUS EFIAPI PeriodicSmiEnable (IN OUT EFI_HANDLE *DispatchHandle OPTIONAL, IN PERIODIC_SMI_LIBRARY_HANDLER DispatchFunction, IN CONST VOID *Context OPTIONAL, IN UINT64 TickPeriod, IN UINTN Cpu, IN UINTN StackSize)
 
BOOLEAN EFIAPI PeriodicSmiDisable (IN EFI_HANDLE DispatchHandle OPTIONAL)
 
EFI_STATUS EFIAPI SmmPeriodicSmiLibConstructor (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
 
EFI_STATUS EFIAPI SmmPeriodicSmiLibDestructor (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
 

Variables

EFI_SMM_PERIODIC_TIMER_DISPATCH2_PROTOCOLgSmmPeriodicTimerDispatch2 = NULL
 
UINT64 * gSmiTickPeriodTable = NULL
 
LIST_ENTRY gFreePeriodicSmiLibraryHandlers
 
LIST_ENTRY gPeriodicSmiLibraryHandlers
 
PERIODIC_SMI_LIBRARY_HANDLER_CONTEXTgActivePeriodicSmiLibraryHandler = NULL
 

Detailed Description

SMM Periodic SMI Library.

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

Definition in file SmmPeriodicSmiLib.c.

Macro Definition Documentation

◆ PERIODIC_SMI_LIBRARY_ALLOCATE_SIZE

#define PERIODIC_SMI_LIBRARY_ALLOCATE_SIZE   0x08

Define the number of periodic SMI handler entries that should be allocated to the list of free periodic SMI handlers when the list of free periodic SMI handlers is empty.

Definition at line 27 of file SmmPeriodicSmiLib.c.

◆ PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_FROM_LINK

#define PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_FROM_LINK (   a)
Value:
CR ( \
a, \
Link, \
)
#define CR(Record, TYPE, Field, TestSignature)
Definition: DebugLib.h:659
#define PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_SIGNATURE

Macro that returns a pointer to a PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT structure based on a pointer to a Link field.

Definition at line 146 of file SmmPeriodicSmiLib.c.

◆ PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_SIGNATURE

#define PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_SIGNATURE   SIGNATURE_32 ('P', 'S', 'M', 'I')

Signature for a PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT structure

Definition at line 32 of file SmmPeriodicSmiLib.c.

Function Documentation

◆ EnlargeFreePeriodicSmiLibraryHandlerList()

BOOLEAN EnlargeFreePeriodicSmiLibraryHandlerList ( VOID  )

Add the additional entries to the list of free periodic SMI handlers. The function is assumed to be called only when the list of free periodic SMI handlers is empty.

Return values
TRUEThe additional entries were added.
FALSEThere was no available resource for the additional entries.

Definition at line 328 of file SmmPeriodicSmiLib.c.

◆ FindFreePeriodicSmiLibraryHandler()

PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT * FindFreePeriodicSmiLibraryHandler ( VOID  )

Internal worker function that returns a free entry for a new periodic SMI handler. If no free entries are available, then additional entries are allocated.

Return values
NULLThere are not enough resources available to to allocate a free entry.
otherPointer to a free PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT structure.

Definition at line 361 of file SmmPeriodicSmiLib.c.

◆ GetActivePeriodicSmiLibraryHandler()

PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT * GetActivePeriodicSmiLibraryHandler ( VOID  )

Internal worker function that returns a pointer to the PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT structure associated with the periodic SMI handler that is currently being executed. If a periodic SMI handler is not currently being executed, the NULL is returned.

Return values
NULLA periodic SMI handler is not currently being executed.
otherPointer to the PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT associated with the active periodic SMI handler.

Definition at line 198 of file SmmPeriodicSmiLib.c.

◆ LookupPeriodicSmiLibraryHandler()

PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT * LookupPeriodicSmiLibraryHandler ( IN EFI_HANDLE DispatchHandle  OPTIONAL)

Internal worker function that returns a pointer to the PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT structure associated with the DispatchHandle that was returned when the periodic SMI handler was enabled with PeriodicSmiEnable(). If DispatchHandle is NULL, then the active periodic SMI handler is returned. If DispatchHandle is NULL and there is no active periodic SMI handler, then NULL is returned.

Parameters
[in]DispatchHandleDispatchHandle that was returned when the periodic SMI handler was enabled with PeriodicSmiEnable(). This is an optional parameter that may be NULL. If this parameter is NULL, then the active periodic SMI handler is returned.
Return values
NULLDispatchHandle is NULL and there is no active periodic SMI handler.
NULLDispatchHandle does not match any of the periodic SMI handlers that have been enabled with PeriodicSmiEnable().
otherPointer to the PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT associated with the DispatchHandle.

Definition at line 228 of file SmmPeriodicSmiLib.c.

◆ PeriodicSmiDisable()

BOOLEAN EFIAPI PeriodicSmiDisable ( IN EFI_HANDLE DispatchHandle  OPTIONAL)

This function disables a periodic SMI handler that has been previously enabled with PeriodicSmiEnable().

Parameters
[in]DispatchHandleA handle associated with a previously enabled periodic SMI handler. This is an optional parameter that may be NULL. If it is NULL, then the active periodic SMI handlers is disabled.
Return values
FALSEDispatchHandle is NULL and there is no active periodic SMI handler.
FALSEThe periodic SMI handler specified by DispatchHandle has not been enabled with PeriodicSmiEnable().
TRUEThe periodic SMI handler specified by DispatchHandle has been disabled. If DispatchHandle is NULL, then the active periodic SMI handler has been disabled.

Definition at line 1015 of file SmmPeriodicSmiLib.c.

◆ PeriodicSmiDispatchFunction()

EFI_STATUS EFIAPI PeriodicSmiDispatchFunction ( IN EFI_HANDLE  DispatchHandle,
IN CONST VOID *Context  OPTIONAL,
IN OUT VOID *CommBuffer  OPTIONAL,
IN OUT UINTN *CommBufferSize  OPTIONAL 
)

Internal worker function that transfers control to a periodic SMI handler that was enabled using PeriodicSmiEnable().

Parameters
[in]DispatchHandleThe unique handle assigned to this handler by SmiHandlerRegister().
[in]ContextPoints to an optional handler context which was specified when the handler was registered.
[in,out]CommBufferA pointer to a collection of data in memory that will be conveyed from a non-SMM environment into an SMM environment.
[in,out]CommBufferSizeThe size of the CommBuffer.
Return values
EFI_SUCCESSThe interrupt was handled and quiesced. No other handlers should still be called.
EFI_WARN_INTERRUPT_SOURCE_QUIESCEDThe interrupt has been quiesced but other handlers should still be called.
EFI_WARN_INTERRUPT_SOURCE_PENDINGThe interrupt is still pending and other handlers should still be called.
EFI_INTERRUPT_PENDINGThe interrupt could not be quiesced.

Definition at line 777 of file SmmPeriodicSmiLib.c.

◆ PeriodicSmiDispatchFunctionOnCpu()

VOID EFIAPI PeriodicSmiDispatchFunctionOnCpu ( PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT PeriodicSmiLibraryHandler)

Internal worker function that transfers control to an enabled periodic SMI handler on the specified logical CPU. This function determines if the periodic SMI handler yielded and needs to be resumed. It also and switches to an allocated stack if one was allocated in PeriodicSmiEnable().

Parameters
[in]PeriodicSmiLibraryHandlerA pointer to the context for the periodic SMI handler to execute.

Definition at line 654 of file SmmPeriodicSmiLib.c.

◆ PeriodicSmiDispatchFunctionSwitchStack()

VOID EFIAPI PeriodicSmiDispatchFunctionSwitchStack ( IN VOID *Context1  OPTIONAL,
IN VOID *Context2  OPTIONAL 
)

Internal worker function that transfers control to an enabled periodic SMI handler. If the enabled periodic SMI handler was allocated its own stack, then this function is called on that allocated stack through the BaseLin function SwitchStack().

Parameters
[in]Context1Context1 parameter passed into SwitchStack().
[in]Context2Context2 parameter passed into SwitchStack().

Definition at line 612 of file SmmPeriodicSmiLib.c.

◆ PeriodicSmiDispatchFunctionWithLock()

VOID EFIAPI PeriodicSmiDispatchFunctionWithLock ( IN OUT VOID *  Buffer)

Internal worker function that transfers control to an enabled periodic SMI handler on the specified logical CPU. This worker function is only called using the SMM Services Table function SmmStartupThisAp() to execute the periodic SMI handler on a logical CPU that is different than the one that is running the SMM Foundation. When the periodic SMI handler returns, a lock is released to notify the CPU that is running the SMM Foundation that the periodic SMI handler execution has finished its execution.

Parameters
[in,out]BufferA pointer to the context for the periodic SMI handler.

Definition at line 731 of file SmmPeriodicSmiLib.c.

◆ PeriodicSmiEnable()

EFI_STATUS EFIAPI PeriodicSmiEnable ( IN OUT EFI_HANDLE *DispatchHandle  OPTIONAL,
IN PERIODIC_SMI_LIBRARY_HANDLER  DispatchFunction,
IN CONST VOID *Context  OPTIONAL,
IN UINT64  TickPeriod,
IN UINTN  Cpu,
IN UINTN  StackSize 
)

This function enables a periodic SMI handler.

Parameters
[in,out]DispatchHandleA pointer to the handle associated with the enabled periodic SMI handler. This is an optional parameter that may be NULL. If it is NULL, then the handle will not be returned, which means that the periodic SMI handler can never be disabled.
[in]DispatchFunctionA pointer to a periodic SMI handler function.
[in]ContextOptional content to pass into DispatchFunction.
[in]TickPeriodThe requested tick period in 100ns units that control should be given to the periodic SMI handler. Must be one of the supported values returned by PeriodicSmiSupportedPickPeriod().
[in]CpuSpecifies the CPU that is required to execute the periodic SMI handler. If Cpu is PERIODIC_SMI_LIBRARY_ANY_CPU, then the periodic SMI handler will always be executed on the SMST CurrentlyExecutingCpu, which may vary across periodic SMIs. If Cpu is between 0 and the SMST NumberOfCpus, then the periodic SMI will always be executed on the requested CPU.
[in]StackSizeThe size, in bytes, of the stack to allocate for use by the periodic SMI handler. If 0, then the default stack will be used.
Return values
EFI_INVALID_PARAMETERDispatchFunction is NULL.
EFI_UNSUPPORTEDTickPeriod is not a supported tick period. The supported tick periods can be retrieved using PeriodicSmiSupportedTickPeriod().
EFI_INVALID_PARAMETERCpu is not PERIODIC_SMI_LIBRARY_ANY_CPU or in the range 0 to SMST NumberOfCpus.
EFI_OUT_OF_RESOURCESThere are not enough resources to enable the periodic SMI handler.
EFI_OUT_OF_RESOURCESThere are not enough resources to allocate the stack specified by StackSize.
EFI_SUCCESSThe periodic SMI handler was enabled.

Definition at line 905 of file SmmPeriodicSmiLib.c.

◆ PeriodicSmiExecutionTime()

UINT64 EFIAPI PeriodicSmiExecutionTime ( VOID  )

This function returns the time in 100ns units since the periodic SMI handler function was called. If the periodic SMI handler was resumed through PeriodicSmiYield(), then the time returned is the time in 100ns units since PeriodicSmiYield() returned.

Returns
The actual time in 100ns units that the periodic SMI handler has been executing. If this function is not called from within an enabled periodic SMI handler, then 0 is returned.

Definition at line 422 of file SmmPeriodicSmiLib.c.

◆ PeriodicSmiExit()

VOID EFIAPI PeriodicSmiExit ( VOID  )

This function returns control back to the SMM Foundation. When the next periodic SMI for the currently executing handler is triggered, the periodic SMI handler will restarted from its registered DispatchFunction entry point. If this function is not called from within an enabled periodic SMI handler, then control is returned to the calling function.

Definition at line 498 of file SmmPeriodicSmiLib.c.

◆ PeriodicSmiSupportedTickPeriod()

UINT64 *EFIAPI PeriodicSmiSupportedTickPeriod ( VOID  )

This function returns a pointer to a table of supported periodic SMI tick periods in 100 ns units sorted from largest to smallest. The table contains a array of UINT64 values terminated by a tick period value of 0. The returned table must be treated as read-only data and must not be freed.

Returns
A pointer to a table of UINT64 tick period values in 100ns units sorted from largest to smallest terminated by a tick period of 0.

Definition at line 399 of file SmmPeriodicSmiLib.c.

◆ PeriodicSmiYield()

UINT64 EFIAPI PeriodicSmiYield ( VOID  )

This function yields control back to the SMM Foundation. When the next periodic SMI for the currently executing handler is triggered, the periodic SMI handler will be resumed and this function will return. Use of this function requires a separate stack for the periodic SMI handler. A non zero stack size must be specified in PeriodicSmiEnable() for this function to be used.

If the stack size passed into PeriodicSmiEnable() was zero, the 0 is returned.

If this function is not called from within an enabled periodic SMI handler, then 0 is returned.

Returns
The actual time in 100ns units elapsed since this function was called. A value of 0 indicates an unknown amount of time.

Definition at line 544 of file SmmPeriodicSmiLib.c.

◆ ReclaimPeriodicSmiLibraryHandler()

VOID ReclaimPeriodicSmiLibraryHandler ( PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT PeriodicSmiLibraryHandler)

Internal worker function that moves the specified periodic SMI handler from the list of managed periodic SMI handlers to the list of free periodic SMI handlers.

Parameters
[in]PeriodicSmiLibraryHandlerPointer to the periodic SMI handler to be reclaimed.

Definition at line 302 of file SmmPeriodicSmiLib.c.

◆ SetActivePeriodicSmiLibraryHandler()

PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT * SetActivePeriodicSmiLibraryHandler ( IN EFI_HANDLE DispatchHandle  OPTIONAL)

Internal worker function that sets that active periodic SMI handler based on the DispatchHandle that was returned when the periodic SMI handler was enabled with PeriodicSmiEnable(). If DispatchHandle is NULL, then the state is updated to show that there is not active periodic SMI handler. A pointer to the active PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT structure is returned.

Parameters
[in]DispatchHandleDispatchHandle that was returned when the periodic SMI handler was enabled with PeriodicSmiEnable(). This is an optional parameter that may be NULL. If this parameter is NULL, then the state is updated to show that there is not active periodic SMI handler.
Return values
NULLDispatchHandle is NULL.
otherPointer to the PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT associated with DispatchHandle.

Definition at line 282 of file SmmPeriodicSmiLib.c.

◆ SmmPeriodicSmiLibConstructor()

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

This constructor function caches the pointer to the SMM Periodic Timer Dispatch 2 Protocol and collects the list SMI tick rates that the hardware supports.

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 1067 of file SmmPeriodicSmiLib.c.

◆ SmmPeriodicSmiLibDestructor()

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

The constructor function caches the pointer to the SMM Periodic Timer Dispatch 2 Protocol and collects the list SMI tick rates that the hardware supports.

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 1145 of file SmmPeriodicSmiLib.c.

Variable Documentation

◆ gActivePeriodicSmiLibraryHandler

PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT* gActivePeriodicSmiLibraryHandler = NULL

Pointer to the periodic SMI handler that is currently being executed. Is set to NULL if no periodic SMI handler is currently being executed.

Definition at line 184 of file SmmPeriodicSmiLib.c.

◆ gFreePeriodicSmiLibraryHandlers

LIST_ENTRY gFreePeriodicSmiLibraryHandlers
Initial value:
=
#define INITIALIZE_LIST_HEAD_VARIABLE(ListHead)
Definition: BaseLib.h:2904
LIST_ENTRY gFreePeriodicSmiLibraryHandlers

Linked list of free periodic SMI handlers that this library can use.

Definition at line 171 of file SmmPeriodicSmiLib.c.

◆ gPeriodicSmiLibraryHandlers

LIST_ENTRY gPeriodicSmiLibraryHandlers
Initial value:

Linked list of periodic SMI handlers that this library is currently managing.

Definition at line 177 of file SmmPeriodicSmiLib.c.

◆ gSmiTickPeriodTable

UINT64* gSmiTickPeriodTable = NULL

Pointer to a table of supported periodic SMI tick periods in 100 ns units sorted from largest to smallest terminated by a tick period value of 0. This table is allocated using AllocatePool() in the constructor and filled in based on the values returned from the SMM Periodic Timer Dispatch 2 Protocol function GetNextShorterInterval().

Definition at line 166 of file SmmPeriodicSmiLib.c.

◆ gSmmPeriodicTimerDispatch2

EFI_SMM_PERIODIC_TIMER_DISPATCH2_PROTOCOL* gSmmPeriodicTimerDispatch2 = NULL

Pointer to the SMM Periodic Timer Dispatch Protocol that was located in the constructor.

Definition at line 157 of file SmmPeriodicSmiLib.c.