4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync SMM Periodic SMI Library.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync This program and the accompanying materials
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync are licensed and made available under the terms and conditions of the BSD License
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync which accompanies this distribution. The full text of the license may be found at
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/// Define the number of periodic SMI handler entries that should be allocated to the list
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/// of free periodic SMI handlers when the list of free periodic SMI handlers is empty.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/// Signature for a PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT structure
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync#define PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_SIGNATURE SIGNATURE_32 ('P', 'S', 'M', 'I')
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/// Structure that contains state information for an enabled periodic SMI handler
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsynctypedef struct {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// Signature value that must be set to PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_SIGNATURE
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// The link entry to be inserted to the list of periodic SMI handlers.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// The dispatch function to called to invoke an enabled periodic SMI handler.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// The context to pass into DispatchFunction
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// The tick period in 100 ns units that DispatchFunction should be called.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// The Cpu number that is required to execute DispatchFunction. If Cpu is
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// set to PERIODIC_SMI_LIBRARY_ANY_CPU, then DispatchFunction may be executed
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// on any CPU.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// The size, in bytes, of the stack allocated for a periodic SMI handler.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// This value must be a multiple of EFI_PAGE_SIZE.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// A pointer to the stack allocated using AllocatePages(). This field will
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// be NULL if StackSize is 0.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// Spin lock used to wait for an AP to complete the execution of a periodic SMI handler
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// The rate in Hz of the performance counter that is used to measure the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// amount of time that a periodic SMI handler executes.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// The start count value of the performance counter that is used to measure
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// the amount of time that a periodic SMI handler executes.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// The end count value of the performance counter that is used to measure
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// the amount of time that a periodic SMI handler executes.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// The context record passed into the Register() function of the SMM Periodic
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// Timer Dispatch Protocol when a periodic SMI handler is enabled.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync EFI_SMM_PERIODIC_TIMER_REGISTER_CONTEXT RegisterContext;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// The handle returned from the Register() function of the SMM Periodic
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// Timer Dispatch Protocol when a periodic SMI handler is enabled.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// The total number of performance counter ticks that the periodic SMI handler
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// has been executing in its current invocation.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// The performance counter value that was captured the last time that the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// periodic SMI handler called PeriodcSmiExecutionTime(). This allows the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// time value returned by PeriodcSmiExecutionTime() to be accurate even when
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// the performance counter rolls over.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// Buffer used to save the context when control is transfer from this library
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// to an enabled periodic SMI handler. This saved context is used when the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// periodic SMI handler exits or yields.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// Flag that is set to TRUE when a periodic SMI handler requests to yield
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// using PeriodicSmiYield(). When this flag IS TRUE, YieldJumpBuffer is
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// valid. When this flag is FALSE, YieldJumpBuffer is not valid.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// Buffer used to save the context when a periodic SMI handler requests to
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// yield using PeriodicSmiYield(). This context is used to resume the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// execution of a periodic SMI handler the next time control is transferd
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// to the periodic SMI handler that yielded.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// The amount of time, in 100 ns units, that have elapsed since the last
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /// time the periodic SMI handler was invoked.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Macro that returns a pointer to a PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync structure based on a pointer to a RegisterContext field.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync#define PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_FROM_REGISTER_CONTEXT(a) \
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Macro that returns a pointer to a PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync structure based on a pointer to a Link field.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync#define PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_FROM_LINK(a) \
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/// Pointer to the SMM Periodic Timer Disatch Protocol that was located in the constuctor.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsyncEFI_SMM_PERIODIC_TIMER_DISPATCH2_PROTOCOL *gSmmPeriodicTimerDispatch2 = NULL;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/// Pointer to a table of supported periodic SMI tick periods in 100 ns units
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/// sorted from largest to smallest terminated by a tick period value of 0.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/// This table is allocated using AllocatePool() in the constructor and filled
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/// in based on the values returned from the SMM Periodic Timer Dispatch 2 Protocol
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/// function GetNextShorterInterval().
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/// Linked list of free periodic SMI handlers that this library can use.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync INITIALIZE_LIST_HEAD_VARIABLE (gFreePeriodicSmiLibraryHandlers);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/// Linked list of periodic SMI handlers that this library is currently managing.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync INITIALIZE_LIST_HEAD_VARIABLE (gPeriodicSmiLibraryHandlers);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/// Pointer to the periodic SMI handler that is currently being executed.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/// Is set to NULL if no periodic SMI handler is currently being executed.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsyncPERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *gActivePeriodicSmiLibraryHandler = NULL;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Internal worker function that returns a pointer to the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT structure associated with the periodic
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync SMI handler that is currently being executed. If a periodic SMI handler is
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync not currently being executed, the NULL is returned.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval NULL A periodic SMI handler is not currently being executed.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval other Pointer to the PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync associated with the active periodic SMI handler.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Internal worker function that returns a pointer to the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT structure associated with the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync DispatchHandle that was returned when the periodic SMI handler was enabled
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync with PeriodicSmiEnable(). If DispatchHandle is NULL, then the active
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync periodic SMI handler is returned. If DispatchHandle is NULL and there is
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync no active periodic SMI handler, then NULL is returned.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] DispatchHandle DispatchHandle that was returned when the periodic
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync SMI handler was enabled with PeriodicSmiEnable().
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync This is an optional parameter that may be NULL.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync If this parameter is NULL, then the active periodic
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync SMI handler is returned.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval NULL DispatchHandle is NULL and there is no active periodic SMI
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval NULL DispatchHandle does not match any of the periodic SMI handlers
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync that have been enabled with PeriodicSmiEnable().
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval other Pointer to the PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync associated with the DispatchHandle.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *PeriodicSmiLibraryHandler;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // If DispatchHandle is NULL, then return the active periodic SMI handler
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Search the periodic SMI handler entries for a a matching DispatchHandle
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync for ( Link = GetFirstNode (&gPeriodicSmiLibraryHandlers)
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ; Link = GetNextNode (&gPeriodicSmiLibraryHandlers, Link)
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiLibraryHandler = PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_FROM_LINK (Link);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (PeriodicSmiLibraryHandler->DispatchHandle == DispatchHandle) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // No entries match DispatchHandle, so return NULL
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Internal worker function that sets that active periodic SMI handler based on
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync the Context used when the periodic SMI handler was registered with the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync SMM Periodic Timer Dispatch 2 Protocol. If Context is NULL, then the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync state is updated to show that there is not active periodic SMI handler.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync A pointer to the active PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT structure
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync is returned.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval NULL Context is NULL.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval other Pointer to the PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync associated with Context.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync gActivePeriodicSmiLibraryHandler = PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_FROM_REGISTER_CONTEXT (Context);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Internal worker function that moves the specified periodic SMI handler from the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync list of managed periodic SMI handlers to the list of free periodic SMI handlers.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] PeriodicSmiLibraryHandler Pointer to the periodic SMI handler to be reclaimed.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *PeriodicSmiLibraryHandler
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ASSERT (PeriodicSmiLibraryHandler->DispatchHandle == NULL);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync EFI_SIZE_TO_PAGES (PeriodicSmiLibraryHandler->StackSize)
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync RemoveEntryList (&PeriodicSmiLibraryHandler->Link);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync InsertHeadList (&gFreePeriodicSmiLibraryHandlers, &PeriodicSmiLibraryHandler->Link);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Add the additional entries to the list of free periodic SMI handlers.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync The function is assumed to be called only when the list of free periodic SMI
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync handlers is empty.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval TRUE The additional entries were added.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval FALSE There was no available resource for the additional entries.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *PeriodicSmiLibraryHandler;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Add the entries to the list
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync for (Index = 0; Index < PERIODIC_SMI_LIBRARY_ALLOCATE_SIZE; Index++) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiLibraryHandler = AllocatePool (sizeof (PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT));
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiLibraryHandler->Signature = PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_SIGNATURE;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync InsertHeadList (&gFreePeriodicSmiLibraryHandlers, &PeriodicSmiLibraryHandler->Link);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Internal worker function that returns a free entry for a new periodic
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync SMI handler. If no free entries are available, then additional
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync entries are allocated.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval NULL There are not enough resources available to to allocate a free entry.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval other Pointer to a free PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT structure.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *PeriodicSmiLibraryHandler;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (IsListEmpty (&gFreePeriodicSmiLibraryHandlers)) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (!EnlargeFreePeriodicSmiLibraryHandlerList ()) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Get one from the list of free periodic SMI handlers.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiLibraryHandler = PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_FROM_LINK (
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync RemoveEntryList (&PeriodicSmiLibraryHandler->Link);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync InsertTailList (&gPeriodicSmiLibraryHandlers, &PeriodicSmiLibraryHandler->Link);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync This function returns a pointer to a table of supported periodic
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync SMI tick periods in 100 ns units sorted from largest to smallest.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync The table contains a array of UINT64 values terminated by a tick
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync period value of 0. The returned table must be treated as read-only
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync data and must not be freed.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @return A pointer to a table of UINT64 tick period values in
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync 100ns units sorted from largest to smallest terminated
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync by a tick period of 0.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Return the table allocated and populated by SmmPeriodicSmiLibConstructor()
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync This function returns the time in 100ns units since the periodic SMI
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync handler function was called. If the periodic SMI handler was resumed
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync through PeriodicSmiYield(), then the time returned is the time in
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync 100ns units since PeriodicSmiYield() returned.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @return The actual time in 100ns units that the periodic SMI handler
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync has been executing. If this function is not called from within
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync an enabled periodic SMI handler, then 0 is returned.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *PeriodicSmiLibraryHandler;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // If there is no active periodic SMI handler, then return 0
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiLibraryHandler = GetActivePeriodicSmiLibraryHandler ();
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Get the current performance counter value
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Count the number of performance counter ticks since the periodic SMI handler
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // was dispatched or the last time this function was called.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (PeriodicSmiLibraryHandler->PerfomanceCounterEndValue > PeriodicSmiLibraryHandler->PerfomanceCounterStartValue) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // The performance counter counts up. Check for roll over condition.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (Current > PeriodicSmiLibraryHandler->DispatchCheckPointTime) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Count = Current - PeriodicSmiLibraryHandler->DispatchCheckPointTime;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Count = (Current - PeriodicSmiLibraryHandler->PerfomanceCounterStartValue) + (PeriodicSmiLibraryHandler->PerfomanceCounterEndValue - PeriodicSmiLibraryHandler->DispatchCheckPointTime);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // The performance counter counts down. Check for roll over condition.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (PeriodicSmiLibraryHandler->DispatchCheckPointTime > Current) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Count = PeriodicSmiLibraryHandler->DispatchCheckPointTime - Current;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Count = (PeriodicSmiLibraryHandler->DispatchCheckPointTime - PeriodicSmiLibraryHandler->PerfomanceCounterEndValue) + (PeriodicSmiLibraryHandler->PerfomanceCounterStartValue - Current);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Accumulate the total number of performance counter ticks since the periodic
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // SMI handler was dispatched or resumed.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiLibraryHandler->DispatchTotalTime += Count;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Update the checkpoint value to the current performance counter value
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiLibraryHandler->DispatchCheckPointTime = Current;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Convert the total number of performance counter ticks to 100 ns units
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync MultU64x32 (PeriodicSmiLibraryHandler->DispatchTotalTime, 10000000),
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync This function returns control back to the SMM Foundation. When the next
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync periodic SMI for the currently executing handler is triggered, the periodic
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync SMI handler will restarted from its registered DispatchFunction entry point.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync If this function is not called from within an enabled periodic SMI handler,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync then control is returned to the calling function.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *PeriodicSmiLibraryHandler;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // If there is no active periodic SMI handler, then return
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiLibraryHandler = GetActivePeriodicSmiLibraryHandler ();
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Perform a long jump back to the point when the currently executing dispatch
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // function was dispatched.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync LongJump (&PeriodicSmiLibraryHandler->DispatchJumpBuffer, 1);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Must never return
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync This function yields control back to the SMM Foundation. When the next
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync periodic SMI for the currently executing handler is triggered, the periodic
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync SMI handler will be resumed and this function will return. Use of this
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync function requires a seperate stack for the periodic SMI handler. A non zero
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync stack size must be specified in PeriodicSmiEnable() for this function to be
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync If the stack size passed into PeriodicSmiEnable() was zero, the 0 is returned.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync If this function is not called from within an enabled periodic SMI handler,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync then 0 is returned.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @return The actual time in 100ns units elasped since this function was
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync called. A value of 0 indicates an unknown amount of time.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *PeriodicSmiLibraryHandler;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // If there is no active periodic SMI handler, then return
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiLibraryHandler = GetActivePeriodicSmiLibraryHandler ();
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // If PeriodicSmiYield() is called without an allocated stack, then just return
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // immediately with an elapsed time of 0.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Set a flag so the next periodic SMI event will resume at where SetJump()
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // is called below.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Save context in YieldJumpBuffer
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync SetJumpFlag = SetJump (&PeriodicSmiLibraryHandler->YieldJumpBuffer);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // The intial call to SetJump() always returns 0.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // If this is the initial call, then exit the current periodic SMI handler
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // We get here when a LongJump is performed from PeriodicSmiDispatchFunctionOnCpu()
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // to resume a periodic SMI handler that called PeriodicSmiYield() on the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // previous time this periodic SMI handler was dispatched.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Clear the flag so the next periodic SMI dispatch will not resume.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Return the amount elapsed time that occured while yielded
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Internal worker function that transfers control to an enabled periodic SMI
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync handler. If the enabled periodic SMI handler was allocated its own stack,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync then this function is called on that allocated stack through the BaseLin
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync function SwitchStack().
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Context1 Context1 parameter passed into SwitchStack().
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Context2 Context2 parameter passed into SwitchStack().
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *PeriodicSmiLibraryHandler;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Convert Context1 to PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiLibraryHandler = (PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *)Context1;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Dispatch the registered handler passing in the context that was registered
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // and the amount of time that has elapsed since the previous time this
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // periodic SMI handler was dispacthed.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // If this DispatchFunction() returns, then unconditially call PeriodicSmiExit()
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // to perform a LongJump() back to PeriodicSmiDispatchFunctionOnCpu(). The
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // LongJump() will resume exection on the original stack.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Internal worker function that transfers control to an enabled periodic SMI
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync handler on the specified logial CPU. This function determines if the periodic
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync SMI handler yielded and needs to be resumed. It also and switches to an
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync allocated stack if one was allocated in PeriodicSmiEnable().
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] PeriodicSmiLibraryHandler A pointer to the context for the periodic
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync SMI handler to execute.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *PeriodicSmiLibraryHandler
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Save context in DispatchJumpBuffer. The intial call to SetJump() always
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // returns 0. If this is the initial call, then either resume from a prior
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // call to PeriodicSmiYield() or call the DispatchFunction registerd in
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // PeriodicSmiEnable() using an allocated stack if one was specified.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (SetJump (&PeriodicSmiLibraryHandler->DispatchJumpBuffer) != 0) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Capture the performance counter value just before the periodic SMI handler
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // is resumed so the amount of time the periodic SMI handler executes can be
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // calculated.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiLibraryHandler->DispatchCheckPointTime = GetPerformanceCounter();
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Perform a long jump back to the point where the previously dispatched
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // function called PeriodicSmiYield().
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync LongJump (&PeriodicSmiLibraryHandler->YieldJumpBuffer, 1);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync } else if (PeriodicSmiLibraryHandler->Stack == NULL) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // If Stack is NULL then call DispatchFunction using current stack passing
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // in the context that was registered and the amount of time that has
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // elapsed since the previous time this periodic SMI handler was dispacthed.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // If this DispatchFunction() returns, then unconditially call PeriodicSmiExit()
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // to perform a LongJump() back to this function.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // If Stack is not NULL then call DispatchFunction switching to the allocated stack
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync (UINT8 *)PeriodicSmiLibraryHandler->Stack + PeriodicSmiLibraryHandler->StackSize
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Must never return
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Internal worker function that transfers control to an enabled periodic SMI
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync handler on the specified logial CPU. This worker function is only called
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync using the SMM Services Table function SmmStartupThisAp() to execute the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync periodic SMI handler on a logical CPU that is different than the one that is
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync running the SMM Foundation. When the periodic SMI handler returns, a lock is
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync released to notify the CPU that is running the SMM Foundation that the periodic
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync SMI handler execution has finished its execution.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in, out] Buffer A pointer to the context for the periodic SMI handler.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *PeriodicSmiLibraryHandler;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Get context
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiLibraryHandler = (PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *)Buffer;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Execute dispatch function on the currently excuting logical CPU
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiDispatchFunctionOnCpu (PeriodicSmiLibraryHandler);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Release the dispatch spin lock
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ReleaseSpinLock (&PeriodicSmiLibraryHandler->DispatchLock);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Internal worker function that transfers control to a periodic SMI handler that
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync was enabled using PeriodicSmiEnable().
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] DispatchHandle The unique handle assigned to this handler by
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync SmiHandlerRegister().
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Context Points to an optional handler context which was
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync specified when the handler was registered.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in, out] CommBuffer A pointer to a collection of data in memory that
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync will be conveyed from a non-SMM environment into
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync an SMM environment.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in, out] CommBufferSize The size of the CommBuffer.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_SUCCESS The interrupt was handled and quiesced.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync No other handlers should still be called.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED The interrupt has been quiesced but other
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync handlers should still be called.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_WARN_INTERRUPT_SOURCE_PENDING The interrupt is still pending and other
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync handlers should still be called.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_INTERRUPT_PENDING The interrupt could not be quiesced.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *PeriodicSmiLibraryHandler;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Set the active periodic SMI handler
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiLibraryHandler = SetActivePeriodicSmiLibraryHandler (Context);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Retrieve the elapsed time since the last time this periodic SMI handler was called
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync TimerContext = (EFI_SMM_PERIODIC_TIMER_CONTEXT *)CommBuffer;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiLibraryHandler->ElapsedTime = TimerContext->ElapsedTime;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Dispatch the periodic SMI handler
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if ((PeriodicSmiLibraryHandler->Cpu == PERIODIC_SMI_LIBRARY_ANY_CPU) ||
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync (PeriodicSmiLibraryHandler->Cpu == gSmst->CurrentlyExecutingCpu) ) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Dispatch on the currently execution CPU if the CPU specified in PeriodicSmiEnable()
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // was PERIODIC_SMI_LIBARRY_ANY_CPU or the currently executing CPU matches the CPU
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // that was specified in PeriodicSmiEnable().
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiDispatchFunctionOnCpu (PeriodicSmiLibraryHandler);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Acquire spin lock for ths periodic SMI handler. The AP will release the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // spin lock when it is done executing the periodic SMI handler.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync AcquireSpinLock (&PeriodicSmiLibraryHandler->DispatchLock);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Execute the periodic SMI handler on the CPU that was specified in
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // PeriodicSmiEnable().
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Wait for the AP to release the spin lock.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync while (!AcquireSpinLockOrFail (&PeriodicSmiLibraryHandler->DispatchLock)) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Release the spin lock for the periodic SMI handler.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ReleaseSpinLock (&PeriodicSmiLibraryHandler->DispatchLock);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Reclaim the active periodic SMI handler if it was disabled during the current dispatch.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (PeriodicSmiLibraryHandler->DispatchHandle == NULL) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ReclaimPeriodicSmiLibraryHandler (PeriodicSmiLibraryHandler);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Update state to show that there is no active periodic SMI handler
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync This function enables a periodic SMI handler.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in, out] DispatchHandle A pointer to the handle associated with the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync enabled periodic SMI handler. This is an
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync optional parameter that may be NULL. If it is
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync NULL, then the handle will not be returned,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync which means that the periodic SMI handler can
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync never be disabled.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] DispatchFunction A pointer to a periodic SMI handler function.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Context Optional content to pass into DispatchFunction.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] TickPeriod The requested tick period in 100ns units that
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync control should be givien to the periodic SMI
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync handler. Must be one of the supported values
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync returned by PeriodicSmiSupportedPickPeriod().
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] Cpu Specifies the CPU that is required to execute
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync the periodic SMI handler. If Cpu is
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PERIODIC_SMI_LIBRARY_ANY_CPU, then the periodic
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync SMI handler will always be executed on the SMST
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync CurrentlyExecutingCpu, which may vary across
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync periodic SMIs. If Cpu is between 0 and the SMST
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync NumberOfCpus, then the periodic SMI will always
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync be executed on the requested CPU.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] StackSize The size, in bytes, of the stack to allocate for
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync use by the periodic SMI handler. If 0, then the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync default stack will be used.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_INVALID_PARAMETER DispatchFunction is NULL.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_UNSUPPORTED TickPeriod is not a supported tick period. The
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync supported tick periods can be retrieved using
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiSupportedTickPeriod().
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_INVALID_PARAMETER Cpu is not PERIODIC_SMI_LIBRARY_ANY_CPU or in
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync the range 0 to SMST NumberOfCpus.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_OUT_OF_RESOURCES There are not enough resources to enable the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync periodic SMI handler.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync stack speficied by StackSize.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_SUCCESS The periodic SMI handler was enabled.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *PeriodicSmiLibraryHandler;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Make sure all the input parameters are valid
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync for (Index = 0; gSmiTickPeriodTable[Index] != 0; Index++) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (Cpu != PERIODIC_SMI_LIBRARY_ANY_CPU && Cpu >= gSmst->NumberOfCpus) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Find a free periodic SMI handler entry
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiLibraryHandler = FindFreePeriodicSmiLibraryHandler();
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Initialize a new periodic SMI handler entry
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiLibraryHandler->DispatchFunction = DispatchFunction;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiLibraryHandler->Context = (VOID *)Context;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiLibraryHandler->StackSize = ALIGN_VALUE (StackSize, EFI_PAGE_SIZE);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiLibraryHandler->Stack = AllocatePages (EFI_SIZE_TO_PAGES (PeriodicSmiLibraryHandler->StackSize));
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ZeroMem (PeriodicSmiLibraryHandler->Stack, PeriodicSmiLibraryHandler->StackSize);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync InitializeSpinLock (&PeriodicSmiLibraryHandler->DispatchLock);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiLibraryHandler->PerfomanceCounterRate = GetPerformanceCounterProperties (
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync &PeriodicSmiLibraryHandler->PerfomanceCounterStartValue,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync &PeriodicSmiLibraryHandler->PerfomanceCounterEndValue
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiLibraryHandler->RegisterContext.Period = TickPeriod;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiLibraryHandler->RegisterContext.SmiTickInterval = TickPeriod;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ReclaimPeriodicSmiLibraryHandler (PeriodicSmiLibraryHandler);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Return the registered handle if the optional DispatchHandle parameter is not NULL
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync *DispatchHandle = PeriodicSmiLibraryHandler->DispatchHandle;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync This function disables a periodic SMI handler that has been previously
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync enabled with PeriodicSmiEnable().
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] DispatchHandle A handle associated with a previously enabled periodic
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync SMI handler. This is an optional parameter that may
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync be NULL. If it is NULL, then the active periodic SMI
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync handlers is disabled.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval FALSE DispatchHandle is NULL and there is no active periodic SMI handler.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval FALSE The periodic SMI handler specified by DispatchHandle has
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync not been enabled with PeriodicSmiEnable().
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval TRUE The periodic SMI handler specified by DispatchHandle has
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync been disabled. If DispatchHandle is NULL, then the active
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync periodic SMI handler has been disabled.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *PeriodicSmiLibraryHandler;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Lookup the periodic SMI handler specified by DispatchHandle
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiLibraryHandler = LookupPeriodicSmiLibraryHandler (DispatchHandle);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Unregister the periodic SMI handler from the SMM Periodic Timer Dispatch 2 Protocol
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Mark the entry for the disabled periodic SMI handler as free, and
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // call ReclaimPeriodicSmiLibraryHandler to move it to the list of free
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // periodic SMI handlers.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (PeriodicSmiLibraryHandler != GetActivePeriodicSmiLibraryHandler ()) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ReclaimPeriodicSmiLibraryHandler (PeriodicSmiLibraryHandler);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync This constructor function caches the pointer to the SMM Periodic Timer
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Dispatch 2 Protocol and collects the list SMI tick rates that the hardware
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] ImageHandle The firmware allocated handle for the EFI image.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] SystemTable A pointer to the EFI System Table.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Locate the SMM Periodic Timer Dispatch 2 Protocol
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Count the number of periodic SMI tick intervals that the SMM Periodic Timer
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Dipatch 2 Protocol supports.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Status = gSmmPeriodicTimerDispatch2->GetNextShorterInterval (
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Allocate a buffer for the table of supported periodic SMI tick periods.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync gSmiTickPeriodTable = AllocateZeroPool (Count * sizeof (UINT64));
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Fill in the table of supported periodic SMI tick periods.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Status = gSmmPeriodicTimerDispatch2->GetNextShorterInterval (
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Allocate buffer for initial set of periodic SMI handlers
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync The constructor function caches the pointer to the SMM Periodic Timer Dispatch 2
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Protocol and collects the list SMI tick rates that the hardware supports.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] ImageHandle The firmware allocated handle for the EFI image.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] SystemTable A pointer to the EFI System Table.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT *PeriodicSmiLibraryHandler;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Free the table of supported periodic SMI tick rates
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Disable all periodic SMI handlers
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync for (Link = GetFirstNode (&gPeriodicSmiLibraryHandlers); !IsNull (&gPeriodicSmiLibraryHandlers, Link);) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiLibraryHandler = PERIODIC_SMI_LIBRARY_HANDLER_CONTEXT_FROM_LINK (Link);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Link = GetNextNode (&gPeriodicSmiLibraryHandlers, Link);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync PeriodicSmiDisable (PeriodicSmiLibraryHandler->DispatchHandle);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Free all the periodic SMI handler entries
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync for (Link = GetFirstNode (&gFreePeriodicSmiLibraryHandlers); !IsNull (&gFreePeriodicSmiLibraryHandlers, Link);) {