2 The internal header file includes the common header files, defines
3 internal structure and functions used by SmmCore module.
5 Copyright (c) 2009 - 2011, 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>
31 #include <Guid/Apriori.h>
32 #include <Guid/EventGroup.h>
33 #include <Guid/EventLegacyBios.h>
35 #include <Library/BaseLib.h>
36 #include <Library/BaseMemoryLib.h>
37 #include <Library/PeCoffLib.h>
38 #include <Library/CacheMaintenanceLib.h>
39 #include <Library/DebugLib.h>
40 #include <Library/ReportStatusCodeLib.h>
41 #include <Library/MemoryAllocationLib.h>
42 #include <Library/DevicePathLib.h>
43 #include <Library/UefiLib.h>
44 #include <Library/UefiBootServicesTableLib.h>
45 #include <Library/PcdLib.h>
46 #include <Library/SmmCorePlatformHookLib.h>
47 #include <Library/PerformanceLib.h>
49 #include "PiSmmCorePrivateData.h"
52 // Used to build a table of SMI Handlers that the SMM Core registers
55 EFI_SMM_HANDLER_ENTRY_POINT2 Handler
;
56 EFI_GUID
*HandlerType
;
57 EFI_HANDLE DispatchHandle
;
59 } SMM_CORE_SMI_HANDLERS
;
62 // Structure for recording the state of an SMM Driver
64 #define EFI_SMM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v')
68 LIST_ENTRY Link
; // mDriverList
70 LIST_ENTRY ScheduledLink
; // mScheduledQueue
74 EFI_DEVICE_PATH_PROTOCOL
*FvFileDevicePath
;
75 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
82 EFI_GUID BeforeAfterGuid
;
87 BOOLEAN DepexProtocolError
;
89 EFI_HANDLE ImageHandle
;
90 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
92 // Image EntryPoint in SMRAM
94 PHYSICAL_ADDRESS ImageEntryPoint
;
96 // Image Buffer in SMRAM
98 PHYSICAL_ADDRESS ImageBuffer
;
103 } EFI_SMM_DRIVER_ENTRY
;
105 #define EFI_HANDLE_SIGNATURE SIGNATURE_32('h','n','d','l')
108 /// IHANDLE - contains a list of protocol handles
112 /// All handles list of IHANDLE
113 LIST_ENTRY AllHandles
;
114 /// List of PROTOCOL_INTERFACE's for this handle
115 LIST_ENTRY Protocols
;
119 #define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature == EFI_HANDLE_SIGNATURE)
121 #define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('p','r','t','e')
124 /// PROTOCOL_ENTRY - each different protocol has 1 entry in the protocol
125 /// database. Each handler that supports this protocol is listed, along
126 /// with a list of registered notifies.
130 /// Link Entry inserted to mProtocolDatabase
131 LIST_ENTRY AllEntries
;
132 /// ID of the protocol
134 /// All protocol interfaces
135 LIST_ENTRY Protocols
;
136 /// Registerd notification handlers
140 #define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('p','i','f','c')
143 /// PROTOCOL_INTERFACE - each protocol installed on a handle is tracked
144 /// with a protocol interface structure
148 /// Link on IHANDLE.Protocols
152 /// Link on PROTOCOL_ENTRY.Protocols
153 LIST_ENTRY ByProtocol
;
155 PROTOCOL_ENTRY
*Protocol
;
156 /// The interface value
158 } PROTOCOL_INTERFACE
;
160 #define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('p','r','t','n')
163 /// PROTOCOL_NOTIFY - used for each register notification for a protocol
167 PROTOCOL_ENTRY
*Protocol
;
168 /// All notifications for this protocol
170 /// Notification function
171 EFI_SMM_NOTIFY_FN Function
;
172 /// Last position notified
173 LIST_ENTRY
*Position
;
177 // SMM Core Global Variables
179 extern SMM_CORE_PRIVATE_DATA
*gSmmCorePrivate
;
180 extern EFI_SMM_SYSTEM_TABLE2 gSmmCoreSmst
;
181 extern LIST_ENTRY gHandleList
;
182 extern EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddressSmramBase
;
185 Called to initialize the memory service.
187 @param SmramRangeCount Number of SMRAM Regions
188 @param SmramRanges Pointer to SMRAM Descriptors
192 SmmInitializeMemoryServices (
193 IN UINTN SmramRangeCount
,
194 IN EFI_SMRAM_DESCRIPTOR
*SmramRanges
198 The SmmInstallConfigurationTable() function is used to maintain the list
199 of configuration tables that are stored in the System Management System
200 Table. The list is stored as an array of (GUID, Pointer) pairs. The list
201 must be allocated from pool memory with PoolType set to EfiRuntimeServicesData.
203 @param SystemTable A pointer to the SMM System Table (SMST).
204 @param Guid A pointer to the GUID for the entry to add, update, or remove.
205 @param Table A pointer to the buffer of the table to add.
206 @param TableSize The size of the table to install.
208 @retval EFI_SUCCESS The (Guid, Table) pair was added, updated, or removed.
209 @retval EFI_INVALID_PARAMETER Guid is not valid.
210 @retval EFI_NOT_FOUND An attempt was made to delete a non-existent entry.
211 @retval EFI_OUT_OF_RESOURCES There is not enough memory available to complete the operation.
216 SmmInstallConfigurationTable (
217 IN CONST EFI_SMM_SYSTEM_TABLE2
*SystemTable
,
218 IN CONST EFI_GUID
*Guid
,
224 Wrapper function to SmmInstallProtocolInterfaceNotify. This is the public API which
225 Calls the private one which contains a BOOLEAN parameter for notifications
227 @param UserHandle The handle to install the protocol handler on,
228 or NULL if a new handle is to be allocated
229 @param Protocol The protocol to add to the handle
230 @param InterfaceType Indicates whether Interface is supplied in
232 @param Interface The interface for the protocol being added
239 SmmInstallProtocolInterface (
240 IN OUT EFI_HANDLE
*UserHandle
,
241 IN EFI_GUID
*Protocol
,
242 IN EFI_INTERFACE_TYPE InterfaceType
,
247 Allocates pages from the memory map.
249 @param Type The type of allocation to perform
250 @param MemoryType The type of memory to turn the allocated pages
252 @param NumberOfPages The number of pages to allocate
253 @param Memory A pointer to receive the base allocated memory
256 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.
257 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
258 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
259 @retval EFI_SUCCESS Pages successfully allocated.
265 IN EFI_ALLOCATE_TYPE Type
,
266 IN EFI_MEMORY_TYPE MemoryType
,
267 IN UINTN NumberOfPages
,
268 OUT EFI_PHYSICAL_ADDRESS
*Memory
272 Frees previous allocated pages.
274 @param Memory Base address of memory being freed
275 @param NumberOfPages The number of pages to free
277 @retval EFI_NOT_FOUND Could not find the entry that covers the range
278 @retval EFI_INVALID_PARAMETER Address not aligned
279 @return EFI_SUCCESS Pages successfully freed.
285 IN EFI_PHYSICAL_ADDRESS Memory
,
286 IN UINTN NumberOfPages
290 Allocate pool of a particular type.
292 @param PoolType Type of pool to allocate
293 @param Size The amount of pool to allocate
294 @param Buffer The address to return a pointer to the allocated
297 @retval EFI_INVALID_PARAMETER PoolType not valid
298 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
299 @retval EFI_SUCCESS Pool successfully allocated.
305 IN EFI_MEMORY_TYPE PoolType
,
313 @param Buffer The allocated pool entry to free
315 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.
316 @retval EFI_SUCCESS Pool successfully freed.
326 Installs a protocol interface into the boot services environment.
328 @param UserHandle The handle to install the protocol handler on,
329 or NULL if a new handle is to be allocated
330 @param Protocol The protocol to add to the handle
331 @param InterfaceType Indicates whether Interface is supplied in
333 @param Interface The interface for the protocol being added
334 @param Notify indicates whether notify the notification list
337 @retval EFI_INVALID_PARAMETER Invalid parameter
338 @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate
339 @retval EFI_SUCCESS Protocol interface successfully installed
343 SmmInstallProtocolInterfaceNotify (
344 IN OUT EFI_HANDLE
*UserHandle
,
345 IN EFI_GUID
*Protocol
,
346 IN EFI_INTERFACE_TYPE InterfaceType
,
352 Uninstalls all instances of a protocol:interfacer from a handle.
353 If the last protocol interface is remove from the handle, the
356 @param UserHandle The handle to remove the protocol handler from
357 @param Protocol The protocol, of protocol:interface, to remove
358 @param Interface The interface, of protocol:interface, to remove
360 @retval EFI_INVALID_PARAMETER Protocol is NULL.
361 @retval EFI_SUCCESS Protocol interface successfully uninstalled.
366 SmmUninstallProtocolInterface (
367 IN EFI_HANDLE UserHandle
,
368 IN EFI_GUID
*Protocol
,
373 Queries a handle to determine if it supports a specified protocol.
375 @param UserHandle The handle being queried.
376 @param Protocol The published unique identifier of the protocol.
377 @param Interface Supplies the address where a pointer to the
378 corresponding Protocol Interface is returned.
380 @return The requested protocol interface for the handle
386 IN EFI_HANDLE UserHandle
,
387 IN EFI_GUID
*Protocol
,
392 Add a new protocol notification record for the request protocol.
394 @param Protocol The requested protocol to add the notify
396 @param Function Points to the notification function
397 @param Registration Returns the registration record
399 @retval EFI_INVALID_PARAMETER Invalid parameter
400 @retval EFI_SUCCESS Successfully returned the registration record
406 SmmRegisterProtocolNotify (
407 IN CONST EFI_GUID
*Protocol
,
408 IN EFI_SMM_NOTIFY_FN Function
,
409 OUT VOID
**Registration
413 Locates the requested handle(s) and returns them in Buffer.
415 @param SearchType The type of search to perform to locate the
417 @param Protocol The protocol to search for
418 @param SearchKey Dependant on SearchType
419 @param BufferSize On input the size of Buffer. On output the
420 size of data returned.
421 @param Buffer The buffer to return the results in
423 @retval EFI_BUFFER_TOO_SMALL Buffer too small, required buffer size is
424 returned in BufferSize.
425 @retval EFI_INVALID_PARAMETER Invalid parameter
426 @retval EFI_SUCCESS Successfully found the requested handle(s) and
427 returns them in Buffer.
433 IN EFI_LOCATE_SEARCH_TYPE SearchType
,
434 IN EFI_GUID
*Protocol OPTIONAL
,
435 IN VOID
*SearchKey OPTIONAL
,
436 IN OUT UINTN
*BufferSize
,
437 OUT EFI_HANDLE
*Buffer
441 Return the first Protocol Interface that matches the Protocol GUID. If
442 Registration is pasased in return a Protocol Instance that was just add
443 to the system. If Retistration is NULL return the first Protocol Interface
446 @param Protocol The protocol to search for
447 @param Registration Optional Registration Key returned from
448 RegisterProtocolNotify()
449 @param Interface Return the Protocol interface (instance).
451 @retval EFI_SUCCESS If a valid Interface is returned
452 @retval EFI_INVALID_PARAMETER Invalid parameter
453 @retval EFI_NOT_FOUND Protocol interface not found
459 IN EFI_GUID
*Protocol
,
460 IN VOID
*Registration OPTIONAL
,
465 Manage SMI of a particular type.
467 @param HandlerType Points to the handler type or NULL for root SMI handlers.
468 @param Context Points to an optional context buffer.
469 @param CommBuffer Points to the optional communication buffer.
470 @param CommBufferSize Points to the size of the optional communication buffer.
472 @retval EFI_SUCCESS Interrupt source was processed successfully but not quiesced.
473 @retval EFI_INTERRUPT_PENDING One or more SMI sources could not be quiesced.
474 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING Interrupt source was not handled or quiesced.
475 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED Interrupt source was handled and quiesced.
481 IN CONST EFI_GUID
*HandlerType
,
482 IN CONST VOID
*Context OPTIONAL
,
483 IN OUT VOID
*CommBuffer OPTIONAL
,
484 IN OUT UINTN
*CommBufferSize OPTIONAL
488 Registers a handler to execute within SMM.
490 @param Handler Handler service funtion pointer.
491 @param HandlerType Points to the handler type or NULL for root SMI handlers.
492 @param DispatchHandle On return, contains a unique handle which can be used to later unregister the handler function.
494 @retval EFI_SUCCESS Handler register success.
495 @retval EFI_INVALID_PARAMETER Handler or DispatchHandle is NULL.
501 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler
,
502 IN CONST EFI_GUID
*HandlerType OPTIONAL
,
503 OUT EFI_HANDLE
*DispatchHandle
507 Unregister a handler in SMM.
509 @param DispatchHandle The handle that was specified when the handler was registered.
511 @retval EFI_SUCCESS Handler function was successfully unregistered.
512 @retval EFI_INVALID_PARAMETER DispatchHandle does not refer to a valid handle.
517 SmiHandlerUnRegister (
518 IN EFI_HANDLE DispatchHandle
522 This function is the main entry point for an SMM handler dispatch
523 or communicate-based callback.
525 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
526 @param Context Points to an optional handler context which was specified when the handler was registered.
527 @param CommBuffer A pointer to a collection of data in memory that will
528 be conveyed from a non-SMM environment into an SMM environment.
529 @param CommBufferSize The size of the CommBuffer.
536 SmmDriverDispatchHandler (
537 IN EFI_HANDLE DispatchHandle
,
538 IN CONST VOID
*Context
, OPTIONAL
539 IN OUT VOID
*CommBuffer
, OPTIONAL
540 IN OUT UINTN
*CommBufferSize OPTIONAL
544 This function is the main entry point for an SMM handler dispatch
545 or communicate-based callback.
547 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
548 @param Context Points to an optional handler context which was specified when the handler was registered.
549 @param CommBuffer A pointer to a collection of data in memory that will
550 be conveyed from a non-SMM environment into an SMM environment.
551 @param CommBufferSize The size of the CommBuffer.
558 SmmLegacyBootHandler (
559 IN EFI_HANDLE DispatchHandle
,
560 IN CONST VOID
*Context
, OPTIONAL
561 IN OUT VOID
*CommBuffer
, OPTIONAL
562 IN OUT UINTN
*CommBufferSize OPTIONAL
566 This function is the main entry point for an SMM handler dispatch
567 or communicate-based callback.
569 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
570 @param Context Points to an optional handler context which was specified when the handler was registered.
571 @param CommBuffer A pointer to a collection of data in memory that will
572 be conveyed from a non-SMM environment into an SMM environment.
573 @param CommBufferSize The size of the CommBuffer.
580 SmmReadyToLockHandler (
581 IN EFI_HANDLE DispatchHandle
,
582 IN CONST VOID
*Context
, OPTIONAL
583 IN OUT VOID
*CommBuffer
, OPTIONAL
584 IN OUT UINTN
*CommBufferSize OPTIONAL
588 Place holder function until all the SMM System Table Service are available.
590 @param Arg1 Undefined
591 @param Arg2 Undefined
592 @param Arg3 Undefined
593 @param Arg4 Undefined
594 @param Arg5 Undefined
596 @return EFI_NOT_AVAILABLE_YET
601 SmmEfiNotAvailableYetArg5 (
610 //Functions used during debug buils
614 Traverse the discovered list for any drivers that were discovered but not loaded
615 because the dependency experessions evaluated to false.
619 SmmDisplayDiscoveredNotDispatched (
624 Add free SMRAM region for use by memory service.
626 @param MemBase Base address of memory region.
627 @param MemLength Length of the memory region.
628 @param Type Memory type.
629 @param Attributes Memory region state.
634 IN EFI_PHYSICAL_ADDRESS MemBase
,
636 IN EFI_MEMORY_TYPE Type
,
641 Finds the protocol entry for the requested protocol.
643 @param Protocol The ID of the protocol
644 @param Create Create a new entry if not found
646 @return Protocol entry
650 SmmFindProtocolEntry (
651 IN EFI_GUID
*Protocol
,
656 Signal event for every protocol in protocol entry.
658 @param Prot Protocol interface
663 IN PROTOCOL_INTERFACE
*Prot
667 Finds the protocol instance for the requested handle and protocol.
668 Note: This function doesn't do parameters checking, it's caller's responsibility
669 to pass in valid parameters.
671 @param Handle The handle to search the protocol on
672 @param Protocol GUID of the protocol
673 @param Interface The interface for the protocol being searched
675 @return Protocol instance (NULL: Not found)
679 SmmFindProtocolInterface (
681 IN EFI_GUID
*Protocol
,
686 Removes Protocol from the protocol list (but not the handle list).
688 @param Handle The handle to remove protocol on.
689 @param Protocol GUID of the protocol to be moved
690 @param Interface The interface of the protocol
692 @return Protocol Entry
696 SmmRemoveInterfaceFromProtocol (
698 IN EFI_GUID
*Protocol
,
703 This is the POSTFIX version of the dependency evaluator. This code does
704 not need to handle Before or After, as it is not valid to call this
705 routine in this case. POSTFIX means all the math is done on top of the stack.
707 @param DriverEntry DriverEntry element to update.
709 @retval TRUE If driver is ready to run.
710 @retval FALSE If driver is not ready to run or some fatal error
716 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry