2 The internal header file includes the common header files, defines
3 internal structure and functions used by SmmCore module.
5 Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials are licensed and made available
7 under the terms and conditions of the BSD License which accompanies this
8 distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 #include <Protocol/DxeSmmReadyToLock.h>
22 #include <Protocol/SmmReadyToLock.h>
23 #include <Protocol/SmmEndOfDxe.h>
24 #include <Protocol/CpuIo2.h>
25 #include <Protocol/SmmCommunication.h>
26 #include <Protocol/SmmAccess2.h>
27 #include <Protocol/FirmwareVolume2.h>
28 #include <Protocol/LoadedImage.h>
29 #include <Protocol/DevicePath.h>
30 #include <Protocol/Security.h>
31 #include <Protocol/Security2.h>
33 #include <Guid/Apriori.h>
34 #include <Guid/EventGroup.h>
35 #include <Guid/EventLegacyBios.h>
37 #include <Library/BaseLib.h>
38 #include <Library/BaseMemoryLib.h>
39 #include <Library/PeCoffLib.h>
40 #include <Library/CacheMaintenanceLib.h>
41 #include <Library/DebugLib.h>
42 #include <Library/ReportStatusCodeLib.h>
43 #include <Library/MemoryAllocationLib.h>
44 #include <Library/DevicePathLib.h>
45 #include <Library/UefiLib.h>
46 #include <Library/UefiBootServicesTableLib.h>
47 #include <Library/PcdLib.h>
48 #include <Library/SmmCorePlatformHookLib.h>
49 #include <Library/PerformanceLib.h>
50 #include <Library/TimerLib.h>
52 #include "PiSmmCorePrivateData.h"
55 // Used to build a table of SMI Handlers that the SMM Core registers
58 EFI_SMM_HANDLER_ENTRY_POINT2 Handler
;
59 EFI_GUID
*HandlerType
;
60 EFI_HANDLE DispatchHandle
;
62 } SMM_CORE_SMI_HANDLERS
;
65 // Structure for recording the state of an SMM Driver
67 #define EFI_SMM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v')
71 LIST_ENTRY Link
; // mDriverList
73 LIST_ENTRY ScheduledLink
; // mScheduledQueue
77 EFI_DEVICE_PATH_PROTOCOL
*FvFileDevicePath
;
78 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
85 EFI_GUID BeforeAfterGuid
;
90 BOOLEAN DepexProtocolError
;
92 EFI_HANDLE ImageHandle
;
93 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
95 // Image EntryPoint in SMRAM
97 PHYSICAL_ADDRESS ImageEntryPoint
;
99 // Image Buffer in SMRAM
101 PHYSICAL_ADDRESS ImageBuffer
;
106 } EFI_SMM_DRIVER_ENTRY
;
108 #define EFI_HANDLE_SIGNATURE SIGNATURE_32('h','n','d','l')
111 /// IHANDLE - contains a list of protocol handles
115 /// All handles list of IHANDLE
116 LIST_ENTRY AllHandles
;
117 /// List of PROTOCOL_INTERFACE's for this handle
118 LIST_ENTRY Protocols
;
122 #define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature == EFI_HANDLE_SIGNATURE)
124 #define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('p','r','t','e')
127 /// PROTOCOL_ENTRY - each different protocol has 1 entry in the protocol
128 /// database. Each handler that supports this protocol is listed, along
129 /// with a list of registered notifies.
133 /// Link Entry inserted to mProtocolDatabase
134 LIST_ENTRY AllEntries
;
135 /// ID of the protocol
137 /// All protocol interfaces
138 LIST_ENTRY Protocols
;
139 /// Registerd notification handlers
143 #define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('p','i','f','c')
146 /// PROTOCOL_INTERFACE - each protocol installed on a handle is tracked
147 /// with a protocol interface structure
151 /// Link on IHANDLE.Protocols
155 /// Link on PROTOCOL_ENTRY.Protocols
156 LIST_ENTRY ByProtocol
;
158 PROTOCOL_ENTRY
*Protocol
;
159 /// The interface value
161 } PROTOCOL_INTERFACE
;
163 #define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('p','r','t','n')
166 /// PROTOCOL_NOTIFY - used for each register notification for a protocol
170 PROTOCOL_ENTRY
*Protocol
;
171 /// All notifications for this protocol
173 /// Notification function
174 EFI_SMM_NOTIFY_FN Function
;
175 /// Last position notified
176 LIST_ENTRY
*Position
;
180 // SMM Core Global Variables
182 extern SMM_CORE_PRIVATE_DATA
*gSmmCorePrivate
;
183 extern EFI_SMM_SYSTEM_TABLE2 gSmmCoreSmst
;
184 extern LIST_ENTRY gHandleList
;
185 extern EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddressSmramBase
;
188 Called to initialize the memory service.
190 @param SmramRangeCount Number of SMRAM Regions
191 @param SmramRanges Pointer to SMRAM Descriptors
195 SmmInitializeMemoryServices (
196 IN UINTN SmramRangeCount
,
197 IN EFI_SMRAM_DESCRIPTOR
*SmramRanges
201 The SmmInstallConfigurationTable() function is used to maintain the list
202 of configuration tables that are stored in the System Management System
203 Table. The list is stored as an array of (GUID, Pointer) pairs. The list
204 must be allocated from pool memory with PoolType set to EfiRuntimeServicesData.
206 @param SystemTable A pointer to the SMM System Table (SMST).
207 @param Guid A pointer to the GUID for the entry to add, update, or remove.
208 @param Table A pointer to the buffer of the table to add.
209 @param TableSize The size of the table to install.
211 @retval EFI_SUCCESS The (Guid, Table) pair was added, updated, or removed.
212 @retval EFI_INVALID_PARAMETER Guid is not valid.
213 @retval EFI_NOT_FOUND An attempt was made to delete a non-existent entry.
214 @retval EFI_OUT_OF_RESOURCES There is not enough memory available to complete the operation.
219 SmmInstallConfigurationTable (
220 IN CONST EFI_SMM_SYSTEM_TABLE2
*SystemTable
,
221 IN CONST EFI_GUID
*Guid
,
227 Wrapper function to SmmInstallProtocolInterfaceNotify. This is the public API which
228 Calls the private one which contains a BOOLEAN parameter for notifications
230 @param UserHandle The handle to install the protocol handler on,
231 or NULL if a new handle is to be allocated
232 @param Protocol The protocol to add to the handle
233 @param InterfaceType Indicates whether Interface is supplied in
235 @param Interface The interface for the protocol being added
242 SmmInstallProtocolInterface (
243 IN OUT EFI_HANDLE
*UserHandle
,
244 IN EFI_GUID
*Protocol
,
245 IN EFI_INTERFACE_TYPE InterfaceType
,
250 Allocates pages from the memory map.
252 @param Type The type of allocation to perform
253 @param MemoryType The type of memory to turn the allocated pages
255 @param NumberOfPages The number of pages to allocate
256 @param Memory A pointer to receive the base allocated memory
259 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.
260 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
261 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
262 @retval EFI_SUCCESS Pages successfully allocated.
268 IN EFI_ALLOCATE_TYPE Type
,
269 IN EFI_MEMORY_TYPE MemoryType
,
270 IN UINTN NumberOfPages
,
271 OUT EFI_PHYSICAL_ADDRESS
*Memory
275 Frees previous allocated pages.
277 @param Memory Base address of memory being freed
278 @param NumberOfPages The number of pages to free
280 @retval EFI_NOT_FOUND Could not find the entry that covers the range
281 @retval EFI_INVALID_PARAMETER Address not aligned
282 @return EFI_SUCCESS Pages successfully freed.
288 IN EFI_PHYSICAL_ADDRESS Memory
,
289 IN UINTN NumberOfPages
293 Allocate pool of a particular type.
295 @param PoolType Type of pool to allocate
296 @param Size The amount of pool to allocate
297 @param Buffer The address to return a pointer to the allocated
300 @retval EFI_INVALID_PARAMETER PoolType not valid
301 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
302 @retval EFI_SUCCESS Pool successfully allocated.
308 IN EFI_MEMORY_TYPE PoolType
,
316 @param Buffer The allocated pool entry to free
318 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.
319 @retval EFI_SUCCESS Pool successfully freed.
329 Installs a protocol interface into the boot services environment.
331 @param UserHandle The handle to install the protocol handler on,
332 or NULL if a new handle is to be allocated
333 @param Protocol The protocol to add to the handle
334 @param InterfaceType Indicates whether Interface is supplied in
336 @param Interface The interface for the protocol being added
337 @param Notify indicates whether notify the notification list
340 @retval EFI_INVALID_PARAMETER Invalid parameter
341 @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate
342 @retval EFI_SUCCESS Protocol interface successfully installed
346 SmmInstallProtocolInterfaceNotify (
347 IN OUT EFI_HANDLE
*UserHandle
,
348 IN EFI_GUID
*Protocol
,
349 IN EFI_INTERFACE_TYPE InterfaceType
,
355 Uninstalls all instances of a protocol:interfacer from a handle.
356 If the last protocol interface is remove from the handle, the
359 @param UserHandle The handle to remove the protocol handler from
360 @param Protocol The protocol, of protocol:interface, to remove
361 @param Interface The interface, of protocol:interface, to remove
363 @retval EFI_INVALID_PARAMETER Protocol is NULL.
364 @retval EFI_SUCCESS Protocol interface successfully uninstalled.
369 SmmUninstallProtocolInterface (
370 IN EFI_HANDLE UserHandle
,
371 IN EFI_GUID
*Protocol
,
376 Queries a handle to determine if it supports a specified protocol.
378 @param UserHandle The handle being queried.
379 @param Protocol The published unique identifier of the protocol.
380 @param Interface Supplies the address where a pointer to the
381 corresponding Protocol Interface is returned.
383 @return The requested protocol interface for the handle
389 IN EFI_HANDLE UserHandle
,
390 IN EFI_GUID
*Protocol
,
395 Add a new protocol notification record for the request protocol.
397 @param Protocol The requested protocol to add the notify
399 @param Function Points to the notification function
400 @param Registration Returns the registration record
402 @retval EFI_INVALID_PARAMETER Invalid parameter
403 @retval EFI_SUCCESS Successfully returned the registration record
409 SmmRegisterProtocolNotify (
410 IN CONST EFI_GUID
*Protocol
,
411 IN EFI_SMM_NOTIFY_FN Function
,
412 OUT VOID
**Registration
416 Locates the requested handle(s) and returns them in Buffer.
418 @param SearchType The type of search to perform to locate the
420 @param Protocol The protocol to search for
421 @param SearchKey Dependant on SearchType
422 @param BufferSize On input the size of Buffer. On output the
423 size of data returned.
424 @param Buffer The buffer to return the results in
426 @retval EFI_BUFFER_TOO_SMALL Buffer too small, required buffer size is
427 returned in BufferSize.
428 @retval EFI_INVALID_PARAMETER Invalid parameter
429 @retval EFI_SUCCESS Successfully found the requested handle(s) and
430 returns them in Buffer.
436 IN EFI_LOCATE_SEARCH_TYPE SearchType
,
437 IN EFI_GUID
*Protocol OPTIONAL
,
438 IN VOID
*SearchKey OPTIONAL
,
439 IN OUT UINTN
*BufferSize
,
440 OUT EFI_HANDLE
*Buffer
444 Return the first Protocol Interface that matches the Protocol GUID. If
445 Registration is pasased in return a Protocol Instance that was just add
446 to the system. If Retistration is NULL return the first Protocol Interface
449 @param Protocol The protocol to search for
450 @param Registration Optional Registration Key returned from
451 RegisterProtocolNotify()
452 @param Interface Return the Protocol interface (instance).
454 @retval EFI_SUCCESS If a valid Interface is returned
455 @retval EFI_INVALID_PARAMETER Invalid parameter
456 @retval EFI_NOT_FOUND Protocol interface not found
462 IN EFI_GUID
*Protocol
,
463 IN VOID
*Registration OPTIONAL
,
468 Manage SMI of a particular type.
470 @param HandlerType Points to the handler type or NULL for root SMI handlers.
471 @param Context Points to an optional context buffer.
472 @param CommBuffer Points to the optional communication buffer.
473 @param CommBufferSize Points to the size of the optional communication buffer.
475 @retval EFI_SUCCESS Interrupt source was processed successfully but not quiesced.
476 @retval EFI_INTERRUPT_PENDING One or more SMI sources could not be quiesced.
477 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING Interrupt source was not handled or quiesced.
478 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED Interrupt source was handled and quiesced.
484 IN CONST EFI_GUID
*HandlerType
,
485 IN CONST VOID
*Context OPTIONAL
,
486 IN OUT VOID
*CommBuffer OPTIONAL
,
487 IN OUT UINTN
*CommBufferSize OPTIONAL
491 Registers a handler to execute within SMM.
493 @param Handler Handler service funtion pointer.
494 @param HandlerType Points to the handler type or NULL for root SMI handlers.
495 @param DispatchHandle On return, contains a unique handle which can be used to later unregister the handler function.
497 @retval EFI_SUCCESS Handler register success.
498 @retval EFI_INVALID_PARAMETER Handler or DispatchHandle is NULL.
504 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler
,
505 IN CONST EFI_GUID
*HandlerType OPTIONAL
,
506 OUT EFI_HANDLE
*DispatchHandle
510 Unregister a handler in SMM.
512 @param DispatchHandle The handle that was specified when the handler was registered.
514 @retval EFI_SUCCESS Handler function was successfully unregistered.
515 @retval EFI_INVALID_PARAMETER DispatchHandle does not refer to a valid handle.
520 SmiHandlerUnRegister (
521 IN EFI_HANDLE DispatchHandle
525 This function is the main entry point for an SMM handler dispatch
526 or communicate-based callback.
528 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
529 @param Context Points to an optional handler context which was specified when the handler was registered.
530 @param CommBuffer A pointer to a collection of data in memory that will
531 be conveyed from a non-SMM environment into an SMM environment.
532 @param CommBufferSize The size of the CommBuffer.
539 SmmDriverDispatchHandler (
540 IN EFI_HANDLE DispatchHandle
,
541 IN CONST VOID
*Context
, OPTIONAL
542 IN OUT VOID
*CommBuffer
, OPTIONAL
543 IN OUT UINTN
*CommBufferSize OPTIONAL
547 This function is the main entry point for an SMM handler dispatch
548 or communicate-based callback.
550 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
551 @param Context Points to an optional handler context which was specified when the handler was registered.
552 @param CommBuffer A pointer to a collection of data in memory that will
553 be conveyed from a non-SMM environment into an SMM environment.
554 @param CommBufferSize The size of the CommBuffer.
561 SmmLegacyBootHandler (
562 IN EFI_HANDLE DispatchHandle
,
563 IN CONST VOID
*Context
, OPTIONAL
564 IN OUT VOID
*CommBuffer
, OPTIONAL
565 IN OUT UINTN
*CommBufferSize OPTIONAL
569 This function is the main entry point for an SMM handler dispatch
570 or communicate-based callback.
572 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
573 @param Context Points to an optional handler context which was specified when the handler was registered.
574 @param CommBuffer A pointer to a collection of data in memory that will
575 be conveyed from a non-SMM environment into an SMM environment.
576 @param CommBufferSize The size of the CommBuffer.
583 SmmReadyToLockHandler (
584 IN EFI_HANDLE DispatchHandle
,
585 IN CONST VOID
*Context
, OPTIONAL
586 IN OUT VOID
*CommBuffer
, OPTIONAL
587 IN OUT UINTN
*CommBufferSize OPTIONAL
591 This function is the main entry point for an SMM handler dispatch
592 or communicate-based callback.
594 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
595 @param Context Points to an optional handler context which was specified when the handler was registered.
596 @param CommBuffer A pointer to a collection of data in memory that will
597 be conveyed from a non-SMM environment into an SMM environment.
598 @param CommBufferSize The size of the CommBuffer.
606 IN EFI_HANDLE DispatchHandle
,
607 IN CONST VOID
*Context
, OPTIONAL
608 IN OUT VOID
*CommBuffer
, OPTIONAL
609 IN OUT UINTN
*CommBufferSize OPTIONAL
613 Place holder function until all the SMM System Table Service are available.
615 @param Arg1 Undefined
616 @param Arg2 Undefined
617 @param Arg3 Undefined
618 @param Arg4 Undefined
619 @param Arg5 Undefined
621 @return EFI_NOT_AVAILABLE_YET
626 SmmEfiNotAvailableYetArg5 (
635 //Functions used during debug buils
639 Traverse the discovered list for any drivers that were discovered but not loaded
640 because the dependency experessions evaluated to false.
644 SmmDisplayDiscoveredNotDispatched (
649 Add free SMRAM region for use by memory service.
651 @param MemBase Base address of memory region.
652 @param MemLength Length of the memory region.
653 @param Type Memory type.
654 @param Attributes Memory region state.
659 IN EFI_PHYSICAL_ADDRESS MemBase
,
661 IN EFI_MEMORY_TYPE Type
,
666 Finds the protocol entry for the requested protocol.
668 @param Protocol The ID of the protocol
669 @param Create Create a new entry if not found
671 @return Protocol entry
675 SmmFindProtocolEntry (
676 IN EFI_GUID
*Protocol
,
681 Signal event for every protocol in protocol entry.
683 @param Prot Protocol interface
688 IN PROTOCOL_INTERFACE
*Prot
692 Finds the protocol instance for the requested handle and protocol.
693 Note: This function doesn't do parameters checking, it's caller's responsibility
694 to pass in valid parameters.
696 @param Handle The handle to search the protocol on
697 @param Protocol GUID of the protocol
698 @param Interface The interface for the protocol being searched
700 @return Protocol instance (NULL: Not found)
704 SmmFindProtocolInterface (
706 IN EFI_GUID
*Protocol
,
711 Removes Protocol from the protocol list (but not the handle list).
713 @param Handle The handle to remove protocol on.
714 @param Protocol GUID of the protocol to be moved
715 @param Interface The interface of the protocol
717 @return Protocol Entry
721 SmmRemoveInterfaceFromProtocol (
723 IN EFI_GUID
*Protocol
,
728 This is the POSTFIX version of the dependency evaluator. This code does
729 not need to handle Before or After, as it is not valid to call this
730 routine in this case. POSTFIX means all the math is done on top of the stack.
732 @param DriverEntry DriverEntry element to update.
734 @retval TRUE If driver is ready to run.
735 @retval FALSE If driver is not ready to run or some fatal error
741 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry