MdePkg/Library/SmmPeriodicSmiLib/SmmPeriodicSmiLib.c File Reference


Defines

#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_REGISTER_CONTEXT(a)
#define PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_FROM_LINK(a)

Functions

PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT * GetActivePeriodicSmiLibraryHandler (VOID)
PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT * LookupPeriodicSmiLibraryHandler (IN EFI_HANDLE DispatchHandle)
PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT * SetActivePeriodicSmiLibraryHandler (IN CONST VOID *Context)
VOID ReclaimPeriodicSmiLibraryHandler (PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *PeriodicSmiLibraryHandler)
BOOLEAN EnlargeFreePeriodicSmiLibraryHandlerList (VOID)
PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT * FindFreePeriodicSmiLibraryHandler (VOID)
UINT64 *EFIAPI PeriodicSmiSupportedTickPeriod (VOID)
UINT64 EFIAPI PeriodicSmiExecutionTime (VOID)
VOID EFIAPI PeriodicSmiExit (VOID)
UINT64 EFIAPI PeriodicSmiYield (VOID)
VOID EFIAPI PeriodicSmiDispatchFunctionSwitchStack (IN VOID *Context1, IN VOID *Context2)
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, IN OUT VOID *CommBuffer, IN OUT UINTN *CommBufferSize)
EFI_STATUS EFIAPI PeriodicSmiEnable (IN OUT EFI_HANDLE *DispatchHandle, IN PERIODIC_SMI_LIBRARY_HANDLER DispatchFunction, IN CONST VOID *Context, IN UINT64 TickPeriod, IN UINTN Cpu, IN UINTN StackSize)
BOOLEAN EFIAPI PeriodicSmiDisable (IN EFI_HANDLE DispatchHandle)
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
UINT64gSmiTickPeriodTable = NULL
LIST_ENTRY gFreePeriodicSmiLibraryHandlers
LIST_ENTRY gPeriodicSmiLibraryHandlers
PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT * gActivePeriodicSmiLibraryHandler = NULL

Detailed Description

SMM Periodic SMI Library.

Copyright (c) 2011, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php.

THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.


Define Documentation

#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.

Referenced by EnlargeFreePeriodicSmiLibraryHandlerList().

#define PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_FROM_LINK (  ) 

Value:

CR (                                                                \
    a,                                                                \
    PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT,                             \
    Link,                                                             \
    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.

Referenced by FindFreePeriodicSmiLibraryHandler(), LookupPeriodicSmiLibraryHandler(), and SmmPeriodicSmiLibDestructor().

#define PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_FROM_REGISTER_CONTEXT (  ) 

Value:

CR (                                                                \
    a,                                                                \
    PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT,                             \
    RegisterContext,                                                  \
    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 RegisterContext field.

Referenced by SetActivePeriodicSmiLibraryHandler().

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

Signature for a PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT structure

Referenced by EnlargeFreePeriodicSmiLibraryHandlerList().


Function Documentation

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:
TRUE The additional entries were added.
FALSE There was no available resource for the additional entries.

References AllocatePool(), InsertHeadList(), NULL, PERIODIC_SMI_LIBRARY_ALLOCATE_SIZE, and PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_SIGNATURE.

Referenced by FindFreePeriodicSmiLibraryHandler(), and SmmPeriodicSmiLibConstructor().

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:
NULL There are not enough resources available to to allocate a free entry.
other Pointer to a free PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT structure.

References EnlargeFreePeriodicSmiLibraryHandlerList(), GetFirstNode(), InsertTailList(), IsListEmpty(), NULL, PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_FROM_LINK, and RemoveEntryList().

Referenced by PeriodicSmiEnable().

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:
NULL A periodic SMI handler is not currently being executed.
other Pointer to the PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT associated with the active periodic SMI handler.

References gActivePeriodicSmiLibraryHandler.

Referenced by LookupPeriodicSmiLibraryHandler(), PeriodicSmiDisable(), PeriodicSmiExecutionTime(), PeriodicSmiExit(), and PeriodicSmiYield().

PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT* LookupPeriodicSmiLibraryHandler ( IN EFI_HANDLE  DispatchHandle  ) 

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] DispatchHandle DispatchHandle 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:
NULL DispatchHandle is NULL and there is no active periodic SMI handler.
NULL DispatchHandle does not match any of the periodic SMI handlers that have been enabled with PeriodicSmiEnable().
other Pointer to the PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT associated with the DispatchHandle.

References GetActivePeriodicSmiLibraryHandler(), GetFirstNode(), GetNextNode(), IsNull(), NULL, and PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_FROM_LINK.

Referenced by PeriodicSmiDisable().

BOOLEAN EFIAPI PeriodicSmiDisable ( IN EFI_HANDLE  DispatchHandle  ) 

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

Parameters:
[in] DispatchHandle A 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:
FALSE DispatchHandle is NULL and there is no active periodic SMI handler.
FALSE The periodic SMI handler specified by DispatchHandle has not been enabled with PeriodicSmiEnable().
TRUE The periodic SMI handler specified by DispatchHandle has been disabled. If DispatchHandle is NULL, then the active periodic SMI handler has been disabled.

References EFI_ERROR, FALSE, GetActivePeriodicSmiLibraryHandler(), LookupPeriodicSmiLibraryHandler(), NULL, ReclaimPeriodicSmiLibraryHandler(), TRUE, and _EFI_SMM_PERIODIC_TIMER_DISPATCH2_PROTOCOL::UnRegister.

Referenced by SmmPeriodicSmiLibDestructor().

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

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

Parameters:
[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
[in] Context Points to an optional handler context which was specified when the handler was registered.
[in,out] CommBuffer A pointer to a collection of data in memory that will be conveyed from a non-SMM environment into an SMM environment.
[in,out] CommBufferSize The size of the CommBuffer.
Return values:
EFI_SUCCESS The interrupt was handled and quiesced. No other handlers should still be called.
EFI_WARN_INTERRUPT_SOURCE_QUIESCED The interrupt has been quiesced but other handlers should still be called.
EFI_WARN_INTERRUPT_SOURCE_PENDING The interrupt is still pending and other handlers should still be called.
EFI_INTERRUPT_PENDING The interrupt could not be quiesced.

References AcquireSpinLock(), AcquireSpinLockOrFail(), CpuPause(), _EFI_SMM_SYSTEM_TABLE2::CurrentlyExecutingCpu, EFI_ERROR, EFI_NOT_FOUND, EFI_SUCCESS, EFI_SMM_PERIODIC_TIMER_CONTEXT::ElapsedTime, gSmst, NULL, PERIODIC_SMI_LIBRARY_ANY_CPU, PeriodicSmiDispatchFunctionOnCpu(), PeriodicSmiDispatchFunctionWithLock(), ReclaimPeriodicSmiLibraryHandler(), ReleaseSpinLock(), SetActivePeriodicSmiLibraryHandler(), and _EFI_SMM_SYSTEM_TABLE2::SmmStartupThisAp.

Referenced by PeriodicSmiEnable().

VOID EFIAPI PeriodicSmiDispatchFunctionOnCpu ( PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *  PeriodicSmiLibraryHandler  ) 

Internal worker function that transfers control to an enabled periodic SMI handler on the specified logial 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] PeriodicSmiLibraryHandler A pointer to the context for the periodic SMI handler to execute.

References ASSERT, CpuDeadLoop(), FALSE, GetPerformanceCounter(), LongJump(), NULL, PeriodicSmiDispatchFunctionSwitchStack(), PeriodicSmiExit(), SetJump(), and SwitchStack().

Referenced by PeriodicSmiDispatchFunction(), and PeriodicSmiDispatchFunctionWithLock().

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

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] Context1 Context1 parameter passed into SwitchStack().
[in] Context2 Context2 parameter passed into SwitchStack().

References PeriodicSmiExit().

Referenced by PeriodicSmiDispatchFunctionOnCpu().

VOID EFIAPI PeriodicSmiDispatchFunctionWithLock ( IN OUT VOID *  Buffer  ) 

Internal worker function that transfers control to an enabled periodic SMI handler on the specified logial 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] Buffer A pointer to the context for the periodic SMI handler.

References PeriodicSmiDispatchFunctionOnCpu(), and ReleaseSpinLock().

Referenced by PeriodicSmiDispatchFunction().

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

This function enables a periodic SMI handler.

Parameters:
[in,out] DispatchHandle A 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] DispatchFunction A pointer to a periodic SMI handler function.
[in] Context Optional content to pass into DispatchFunction.
[in] TickPeriod The requested tick period in 100ns units that control should be givien to the periodic SMI handler. Must be one of the supported values returned by PeriodicSmiSupportedPickPeriod().
[in] Cpu Specifies 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] StackSize The 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_PARAMETER DispatchFunction is NULL.
EFI_UNSUPPORTED TickPeriod is not a supported tick period. The supported tick periods can be retrieved using PeriodicSmiSupportedTickPeriod().
EFI_INVALID_PARAMETER Cpu is not PERIODIC_SMI_LIBRARY_ANY_CPU or in the range 0 to SMST NumberOfCpus.
EFI_OUT_OF_RESOURCES There are not enough resources to enable the periodic SMI handler.
EFI_OUT_OF_RESOURCES There are not enough resources to allocate the stack speficied by StackSize.
EFI_SUCCESS The periodic SMI handler was enabled.

References ALIGN_VALUE, AllocatePages(), EFI_ERROR, EFI_INVALID_PARAMETER, EFI_OUT_OF_RESOURCES, EFI_PAGE_SIZE, EFI_SIZE_TO_PAGES, EFI_SUCCESS, EFI_UNSUPPORTED, FALSE, FindFreePeriodicSmiLibraryHandler(), GetPerformanceCounterProperties(), gSmiTickPeriodTable, gSmst, InitializeSpinLock(), NULL, _EFI_SMM_SYSTEM_TABLE2::NumberOfCpus, PERIODIC_SMI_LIBRARY_ANY_CPU, PeriodicSmiDispatchFunction(), ReclaimPeriodicSmiLibraryHandler(), _EFI_SMM_PERIODIC_TIMER_DISPATCH2_PROTOCOL::Register, VOID, and ZeroMem().

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.

References DivU64x64Remainder(), GetActivePeriodicSmiLibraryHandler(), GetPerformanceCounter(), MultU64x32(), and NULL.

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.

References ASSERT, CpuDeadLoop(), FALSE, GetActivePeriodicSmiLibraryHandler(), LongJump(), and NULL.

Referenced by PeriodicSmiDispatchFunctionOnCpu(), PeriodicSmiDispatchFunctionSwitchStack(), and PeriodicSmiYield().

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.

References gSmiTickPeriodTable.

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 seperate 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 elasped since this function was called. A value of 0 indicates an unknown amount of time.

References FALSE, GetActivePeriodicSmiLibraryHandler(), NULL, PeriodicSmiExit(), SetJump(), and TRUE.

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] PeriodicSmiLibraryHandler Pointer to the periodic SMI handler to be reclaimed.

References ASSERT, EFI_SIZE_TO_PAGES, FreePages(), InsertHeadList(), NULL, and RemoveEntryList().

Referenced by PeriodicSmiDisable(), PeriodicSmiDispatchFunction(), and PeriodicSmiEnable().

PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT* SetActivePeriodicSmiLibraryHandler ( IN CONST VOID *  Context  ) 

Internal worker function that sets that active periodic SMI handler based on the Context used when the periodic SMI handler was registered with the SMM Periodic Timer Dispatch 2 Protocol. If Context 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.

Return values:
NULL Context is NULL.
other Pointer to the PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT associated with Context.

References gActivePeriodicSmiLibraryHandler, NULL, and PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_FROM_REGISTER_CONTEXT.

Referenced by PeriodicSmiDispatchFunction().

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] ImageHandle The firmware allocated handle for the EFI image.
[in] SystemTable A pointer to the EFI System Table.
Return values:
EFI_SUCCESS The constructor always returns EFI_SUCCESS.

References AllocateZeroPool(), ASSERT, ASSERT_EFI_ERROR, EFI_SUCCESS, EnlargeFreePeriodicSmiLibraryHandlerList(), gEfiSmmPeriodicTimerDispatch2ProtocolGuid, gSmiTickPeriodTable, gSmst, NULL, _EFI_SMM_SYSTEM_TABLE2::SmmLocateProtocol, and VOID.

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] ImageHandle The firmware allocated handle for the EFI image.
[in] SystemTable A pointer to the EFI System Table.
Return values:
EFI_SUCCESS The constructor always returns EFI_SUCCESS.

References EFI_SUCCESS, FreePool(), GetFirstNode(), GetNextNode(), gSmiTickPeriodTable, IsNull(), NULL, PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_FROM_LINK, PeriodicSmiDisable(), and RemoveEntryList().


Variable Documentation

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.

Referenced by GetActivePeriodicSmiLibraryHandler(), and SetActivePeriodicSmiLibraryHandler().

Initial value:

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

Initial value:

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

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().

Referenced by PeriodicSmiEnable(), PeriodicSmiSupportedTickPeriod(), SmmPeriodicSmiLibConstructor(), and SmmPeriodicSmiLibDestructor().

Pointer to the SMM Periodic Timer Disatch Protocol that was located in the constuctor.


Generated on Thu Sep 24 23:14:24 2015 for MdePkg[ALL] by  doxygen 1.5.7.1