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/CpuIo2.h>
24 #include <Protocol/SmmCommunication.h>
25 #include <Protocol/SmmAccess2.h>
26 #include <Protocol/FirmwareVolume2.h>
27 #include <Protocol/LoadedImage.h>
28 #include <Protocol/DevicePath.h>
29 #include <Protocol/Security.h>
30 #include <Protocol/Security2.h>
32 #include <Guid/Apriori.h>
33 #include <Guid/EventGroup.h>
34 #include <Guid/EventLegacyBios.h>
36 #include <Library/BaseLib.h>
37 #include <Library/BaseMemoryLib.h>
38 #include <Library/PeCoffLib.h>
39 #include <Library/CacheMaintenanceLib.h>
40 #include <Library/DebugLib.h>
41 #include <Library/ReportStatusCodeLib.h>
42 #include <Library/MemoryAllocationLib.h>
43 #include <Library/DevicePathLib.h>
44 #include <Library/UefiLib.h>
45 #include <Library/UefiBootServicesTableLib.h>
46 #include <Library/PcdLib.h>
47 #include <Library/SmmCorePlatformHookLib.h>
48 #include <Library/PerformanceLib.h>
49 #include <Library/TimerLib.h>
51 #include "PiSmmCorePrivateData.h"
54 // Used to build a table of SMI Handlers that the SMM Core registers
57 EFI_SMM_HANDLER_ENTRY_POINT2 Handler
;
58 EFI_GUID
*HandlerType
;
59 EFI_HANDLE DispatchHandle
;
61 } SMM_CORE_SMI_HANDLERS
;
64 // Structure for recording the state of an SMM Driver
66 #define EFI_SMM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v')
70 LIST_ENTRY Link
; // mDriverList
72 LIST_ENTRY ScheduledLink
; // mScheduledQueue
76 EFI_DEVICE_PATH_PROTOCOL
*FvFileDevicePath
;
77 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
84 EFI_GUID BeforeAfterGuid
;
89 BOOLEAN DepexProtocolError
;
91 EFI_HANDLE ImageHandle
;
92 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
94 // Image EntryPoint in SMRAM
96 PHYSICAL_ADDRESS ImageEntryPoint
;
98 // Image Buffer in SMRAM
100 PHYSICAL_ADDRESS ImageBuffer
;
105 } EFI_SMM_DRIVER_ENTRY
;
107 #define EFI_HANDLE_SIGNATURE SIGNATURE_32('h','n','d','l')
110 /// IHANDLE - contains a list of protocol handles
114 /// All handles list of IHANDLE
115 LIST_ENTRY AllHandles
;
116 /// List of PROTOCOL_INTERFACE's for this handle
117 LIST_ENTRY Protocols
;
121 #define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature == EFI_HANDLE_SIGNATURE)
123 #define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('p','r','t','e')
126 /// PROTOCOL_ENTRY - each different protocol has 1 entry in the protocol
127 /// database. Each handler that supports this protocol is listed, along
128 /// with a list of registered notifies.
132 /// Link Entry inserted to mProtocolDatabase
133 LIST_ENTRY AllEntries
;
134 /// ID of the protocol
136 /// All protocol interfaces
137 LIST_ENTRY Protocols
;
138 /// Registerd notification handlers
142 #define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('p','i','f','c')
145 /// PROTOCOL_INTERFACE - each protocol installed on a handle is tracked
146 /// with a protocol interface structure
150 /// Link on IHANDLE.Protocols
154 /// Link on PROTOCOL_ENTRY.Protocols
155 LIST_ENTRY ByProtocol
;
157 PROTOCOL_ENTRY
*Protocol
;
158 /// The interface value
160 } PROTOCOL_INTERFACE
;
162 #define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('p','r','t','n')
165 /// PROTOCOL_NOTIFY - used for each register notification for a protocol
169 PROTOCOL_ENTRY
*Protocol
;
170 /// All notifications for this protocol
172 /// Notification function
173 EFI_SMM_NOTIFY_FN Function
;
174 /// Last position notified
175 LIST_ENTRY
*Position
;
179 // SMM Core Global Variables
181 extern SMM_CORE_PRIVATE_DATA
*gSmmCorePrivate
;
182 extern EFI_SMM_SYSTEM_TABLE2 gSmmCoreSmst
;
183 extern LIST_ENTRY gHandleList
;
184 extern EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddressSmramBase
;
187 Called to initialize the memory service.
189 @param SmramRangeCount Number of SMRAM Regions
190 @param SmramRanges Pointer to SMRAM Descriptors
194 SmmInitializeMemoryServices (
195 IN UINTN SmramRangeCount
,
196 IN EFI_SMRAM_DESCRIPTOR
*SmramRanges
200 The SmmInstallConfigurationTable() function is used to maintain the list
201 of configuration tables that are stored in the System Management System
202 Table. The list is stored as an array of (GUID, Pointer) pairs. The list
203 must be allocated from pool memory with PoolType set to EfiRuntimeServicesData.
205 @param SystemTable A pointer to the SMM System Table (SMST).
206 @param Guid A pointer to the GUID for the entry to add, update, or remove.
207 @param Table A pointer to the buffer of the table to add.
208 @param TableSize The size of the table to install.
210 @retval EFI_SUCCESS The (Guid, Table) pair was added, updated, or removed.
211 @retval EFI_INVALID_PARAMETER Guid is not valid.
212 @retval EFI_NOT_FOUND An attempt was made to delete a non-existent entry.
213 @retval EFI_OUT_OF_RESOURCES There is not enough memory available to complete the operation.
218 SmmInstallConfigurationTable (
219 IN CONST EFI_SMM_SYSTEM_TABLE2
*SystemTable
,
220 IN CONST EFI_GUID
*Guid
,
226 Wrapper function to SmmInstallProtocolInterfaceNotify. This is the public API which
227 Calls the private one which contains a BOOLEAN parameter for notifications
229 @param UserHandle The handle to install the protocol handler on,
230 or NULL if a new handle is to be allocated
231 @param Protocol The protocol to add to the handle
232 @param InterfaceType Indicates whether Interface is supplied in
234 @param Interface The interface for the protocol being added
241 SmmInstallProtocolInterface (
242 IN OUT EFI_HANDLE
*UserHandle
,
243 IN EFI_GUID
*Protocol
,
244 IN EFI_INTERFACE_TYPE InterfaceType
,
249 Allocates pages from the memory map.
251 @param Type The type of allocation to perform
252 @param MemoryType The type of memory to turn the allocated pages
254 @param NumberOfPages The number of pages to allocate
255 @param Memory A pointer to receive the base allocated memory
258 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.
259 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
260 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
261 @retval EFI_SUCCESS Pages successfully allocated.
267 IN EFI_ALLOCATE_TYPE Type
,
268 IN EFI_MEMORY_TYPE MemoryType
,
269 IN UINTN NumberOfPages
,
270 OUT EFI_PHYSICAL_ADDRESS
*Memory
274 Frees previous allocated pages.
276 @param Memory Base address of memory being freed
277 @param NumberOfPages The number of pages to free
279 @retval EFI_NOT_FOUND Could not find the entry that covers the range
280 @retval EFI_INVALID_PARAMETER Address not aligned
281 @return EFI_SUCCESS Pages successfully freed.
287 IN EFI_PHYSICAL_ADDRESS Memory
,
288 IN UINTN NumberOfPages
292 Allocate pool of a particular type.
294 @param PoolType Type of pool to allocate
295 @param Size The amount of pool to allocate
296 @param Buffer The address to return a pointer to the allocated
299 @retval EFI_INVALID_PARAMETER PoolType not valid
300 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
301 @retval EFI_SUCCESS Pool successfully allocated.
307 IN EFI_MEMORY_TYPE PoolType
,
315 @param Buffer The allocated pool entry to free
317 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.
318 @retval EFI_SUCCESS Pool successfully freed.
328 Installs a protocol interface into the boot services environment.
330 @param UserHandle The handle to install the protocol handler on,
331 or NULL if a new handle is to be allocated
332 @param Protocol The protocol to add to the handle
333 @param InterfaceType Indicates whether Interface is supplied in
335 @param Interface The interface for the protocol being added
336 @param Notify indicates whether notify the notification list
339 @retval EFI_INVALID_PARAMETER Invalid parameter
340 @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate
341 @retval EFI_SUCCESS Protocol interface successfully installed
345 SmmInstallProtocolInterfaceNotify (
346 IN OUT EFI_HANDLE
*UserHandle
,
347 IN EFI_GUID
*Protocol
,
348 IN EFI_INTERFACE_TYPE InterfaceType
,
354 Uninstalls all instances of a protocol:interfacer from a handle.
355 If the last protocol interface is remove from the handle, the
358 @param UserHandle The handle to remove the protocol handler from
359 @param Protocol The protocol, of protocol:interface, to remove
360 @param Interface The interface, of protocol:interface, to remove
362 @retval EFI_INVALID_PARAMETER Protocol is NULL.
363 @retval EFI_SUCCESS Protocol interface successfully uninstalled.
368 SmmUninstallProtocolInterface (
369 IN EFI_HANDLE UserHandle
,
370 IN EFI_GUID
*Protocol
,
375 Queries a handle to determine if it supports a specified protocol.
377 @param UserHandle The handle being queried.
378 @param Protocol The published unique identifier of the protocol.
379 @param Interface Supplies the address where a pointer to the
380 corresponding Protocol Interface is returned.
382 @return The requested protocol interface for the handle
388 IN EFI_HANDLE UserHandle
,
389 IN EFI_GUID
*Protocol
,
394 Add a new protocol notification record for the request protocol.
396 @param Protocol The requested protocol to add the notify
398 @param Function Points to the notification function
399 @param Registration Returns the registration record
401 @retval EFI_INVALID_PARAMETER Invalid parameter
402 @retval EFI_SUCCESS Successfully returned the registration record
408 SmmRegisterProtocolNotify (
409 IN CONST EFI_GUID
*Protocol
,
410 IN EFI_SMM_NOTIFY_FN Function
,
411 OUT VOID
**Registration
415 Locates the requested handle(s) and returns them in Buffer.
417 @param SearchType The type of search to perform to locate the
419 @param Protocol The protocol to search for
420 @param SearchKey Dependant on SearchType
421 @param BufferSize On input the size of Buffer. On output the
422 size of data returned.
423 @param Buffer The buffer to return the results in
425 @retval EFI_BUFFER_TOO_SMALL Buffer too small, required buffer size is
426 returned in BufferSize.
427 @retval EFI_INVALID_PARAMETER Invalid parameter
428 @retval EFI_SUCCESS Successfully found the requested handle(s) and
429 returns them in Buffer.
435 IN EFI_LOCATE_SEARCH_TYPE SearchType
,
436 IN EFI_GUID
*Protocol OPTIONAL
,
437 IN VOID
*SearchKey OPTIONAL
,
438 IN OUT UINTN
*BufferSize
,
439 OUT EFI_HANDLE
*Buffer
443 Return the first Protocol Interface that matches the Protocol GUID. If
444 Registration is pasased in return a Protocol Instance that was just add
445 to the system. If Retistration is NULL return the first Protocol Interface
448 @param Protocol The protocol to search for
449 @param Registration Optional Registration Key returned from
450 RegisterProtocolNotify()
451 @param Interface Return the Protocol interface (instance).
453 @retval EFI_SUCCESS If a valid Interface is returned
454 @retval EFI_INVALID_PARAMETER Invalid parameter
455 @retval EFI_NOT_FOUND Protocol interface not found
461 IN EFI_GUID
*Protocol
,
462 IN VOID
*Registration OPTIONAL
,
467 Manage SMI of a particular type.
469 @param HandlerType Points to the handler type or NULL for root SMI handlers.
470 @param Context Points to an optional context buffer.
471 @param CommBuffer Points to the optional communication buffer.
472 @param CommBufferSize Points to the size of the optional communication buffer.
474 @retval EFI_SUCCESS Interrupt source was processed successfully but not quiesced.
475 @retval EFI_INTERRUPT_PENDING One or more SMI sources could not be quiesced.
476 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING Interrupt source was not handled or quiesced.
477 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED Interrupt source was handled and quiesced.
483 IN CONST EFI_GUID
*HandlerType
,
484 IN CONST VOID
*Context OPTIONAL
,
485 IN OUT VOID
*CommBuffer OPTIONAL
,
486 IN OUT UINTN
*CommBufferSize OPTIONAL
490 Registers a handler to execute within SMM.
492 @param Handler Handler service funtion pointer.
493 @param HandlerType Points to the handler type or NULL for root SMI handlers.
494 @param DispatchHandle On return, contains a unique handle which can be used to later unregister the handler function.
496 @retval EFI_SUCCESS Handler register success.
497 @retval EFI_INVALID_PARAMETER Handler or DispatchHandle is NULL.
503 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler
,
504 IN CONST EFI_GUID
*HandlerType OPTIONAL
,
505 OUT EFI_HANDLE
*DispatchHandle
509 Unregister a handler in SMM.
511 @param DispatchHandle The handle that was specified when the handler was registered.
513 @retval EFI_SUCCESS Handler function was successfully unregistered.
514 @retval EFI_INVALID_PARAMETER DispatchHandle does not refer to a valid handle.
519 SmiHandlerUnRegister (
520 IN EFI_HANDLE DispatchHandle
524 This function is the main entry point for an SMM handler dispatch
525 or communicate-based callback.
527 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
528 @param Context Points to an optional handler context which was specified when the handler was registered.
529 @param CommBuffer A pointer to a collection of data in memory that will
530 be conveyed from a non-SMM environment into an SMM environment.
531 @param CommBufferSize The size of the CommBuffer.
538 SmmDriverDispatchHandler (
539 IN EFI_HANDLE DispatchHandle
,
540 IN CONST VOID
*Context
, OPTIONAL
541 IN OUT VOID
*CommBuffer
, OPTIONAL
542 IN OUT UINTN
*CommBufferSize OPTIONAL
546 This function is the main entry point for an SMM handler dispatch
547 or communicate-based callback.
549 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
550 @param Context Points to an optional handler context which was specified when the handler was registered.
551 @param CommBuffer A pointer to a collection of data in memory that will
552 be conveyed from a non-SMM environment into an SMM environment.
553 @param CommBufferSize The size of the CommBuffer.
560 SmmLegacyBootHandler (
561 IN EFI_HANDLE DispatchHandle
,
562 IN CONST VOID
*Context
, OPTIONAL
563 IN OUT VOID
*CommBuffer
, OPTIONAL
564 IN OUT UINTN
*CommBufferSize OPTIONAL
568 This function is the main entry point for an SMM handler dispatch
569 or communicate-based callback.
571 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
572 @param Context Points to an optional handler context which was specified when the handler was registered.
573 @param CommBuffer A pointer to a collection of data in memory that will
574 be conveyed from a non-SMM environment into an SMM environment.
575 @param CommBufferSize The size of the CommBuffer.
582 SmmReadyToLockHandler (
583 IN EFI_HANDLE DispatchHandle
,
584 IN CONST VOID
*Context
, OPTIONAL
585 IN OUT VOID
*CommBuffer
, OPTIONAL
586 IN OUT UINTN
*CommBufferSize OPTIONAL
590 Place holder function until all the SMM System Table Service are available.
592 @param Arg1 Undefined
593 @param Arg2 Undefined
594 @param Arg3 Undefined
595 @param Arg4 Undefined
596 @param Arg5 Undefined
598 @return EFI_NOT_AVAILABLE_YET
603 SmmEfiNotAvailableYetArg5 (
612 //Functions used during debug buils
616 Traverse the discovered list for any drivers that were discovered but not loaded
617 because the dependency experessions evaluated to false.
621 SmmDisplayDiscoveredNotDispatched (
626 Add free SMRAM region for use by memory service.
628 @param MemBase Base address of memory region.
629 @param MemLength Length of the memory region.
630 @param Type Memory type.
631 @param Attributes Memory region state.
636 IN EFI_PHYSICAL_ADDRESS MemBase
,
638 IN EFI_MEMORY_TYPE Type
,
643 Finds the protocol entry for the requested protocol.
645 @param Protocol The ID of the protocol
646 @param Create Create a new entry if not found
648 @return Protocol entry
652 SmmFindProtocolEntry (
653 IN EFI_GUID
*Protocol
,
658 Signal event for every protocol in protocol entry.
660 @param Prot Protocol interface
665 IN PROTOCOL_INTERFACE
*Prot
669 Finds the protocol instance for the requested handle and protocol.
670 Note: This function doesn't do parameters checking, it's caller's responsibility
671 to pass in valid parameters.
673 @param Handle The handle to search the protocol on
674 @param Protocol GUID of the protocol
675 @param Interface The interface for the protocol being searched
677 @return Protocol instance (NULL: Not found)
681 SmmFindProtocolInterface (
683 IN EFI_GUID
*Protocol
,
688 Removes Protocol from the protocol list (but not the handle list).
690 @param Handle The handle to remove protocol on.
691 @param Protocol GUID of the protocol to be moved
692 @param Interface The interface of the protocol
694 @return Protocol Entry
698 SmmRemoveInterfaceFromProtocol (
700 IN EFI_GUID
*Protocol
,
705 This is the POSTFIX version of the dependency evaluator. This code does
706 not need to handle Before or After, as it is not valid to call this
707 routine in this case. POSTFIX means all the math is done on top of the stack.
709 @param DriverEntry DriverEntry element to update.
711 @retval TRUE If driver is ready to run.
712 @retval FALSE If driver is not ready to run or some fatal error
718 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry