2 The internal header file includes the common header files, defines
3 internal structure and functions used by SmmCore module.
5 Copyright (c) 2009 - 2017, 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>
32 #include <Protocol/SmmExitBootServices.h>
33 #include <Protocol/SmmLegacyBoot.h>
34 #include <Protocol/SmmReadyToBoot.h>
36 #include <Guid/Apriori.h>
37 #include <Guid/EventGroup.h>
38 #include <Guid/EventLegacyBios.h>
39 #include <Guid/MemoryProfile.h>
40 #include <Guid/LoadModuleAtFixedAddress.h>
41 #include <Guid/SmiHandlerProfile.h>
43 #include <Library/BaseLib.h>
44 #include <Library/BaseMemoryLib.h>
45 #include <Library/PeCoffLib.h>
46 #include <Library/PeCoffGetEntryPointLib.h>
47 #include <Library/CacheMaintenanceLib.h>
48 #include <Library/DebugLib.h>
49 #include <Library/ReportStatusCodeLib.h>
50 #include <Library/MemoryAllocationLib.h>
51 #include <Library/DevicePathLib.h>
52 #include <Library/UefiLib.h>
53 #include <Library/UefiBootServicesTableLib.h>
54 #include <Library/PcdLib.h>
55 #include <Library/SmmCorePlatformHookLib.h>
56 #include <Library/PerformanceLib.h>
57 #include <Library/TimerLib.h>
58 #include <Library/HobLib.h>
59 #include <Library/SmmMemLib.h>
61 #include "PiSmmCorePrivateData.h"
64 // Used to build a table of SMI Handlers that the SMM Core registers
67 EFI_SMM_HANDLER_ENTRY_POINT2 Handler
;
68 EFI_GUID
*HandlerType
;
69 EFI_HANDLE DispatchHandle
;
71 } SMM_CORE_SMI_HANDLERS
;
74 // SMM_HANDLER - used for each SMM handler
77 #define SMI_ENTRY_SIGNATURE SIGNATURE_32('s','m','i','e')
81 LIST_ENTRY AllEntries
; // All entries
83 EFI_GUID HandlerType
; // Type of interrupt
84 LIST_ENTRY SmiHandlers
; // All handlers
87 #define SMI_HANDLER_SIGNATURE SIGNATURE_32('s','m','i','h')
91 LIST_ENTRY Link
; // Link on SMI_ENTRY.SmiHandlers
92 EFI_SMM_HANDLER_ENTRY_POINT2 Handler
; // The smm handler's entry point
93 UINTN CallerAddr
; // The address of caller who register the SMI handler.
95 VOID
*Context
; // for profile
96 UINTN ContextSize
; // for profile
100 // Structure for recording the state of an SMM Driver
102 #define EFI_SMM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v')
106 LIST_ENTRY Link
; // mDriverList
108 LIST_ENTRY ScheduledLink
; // mScheduledQueue
112 EFI_DEVICE_PATH_PROTOCOL
*FvFileDevicePath
;
113 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
120 EFI_GUID BeforeAfterGuid
;
125 BOOLEAN DepexProtocolError
;
127 EFI_HANDLE ImageHandle
;
128 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
130 // Image EntryPoint in SMRAM
132 PHYSICAL_ADDRESS ImageEntryPoint
;
134 // Image Buffer in SMRAM
136 PHYSICAL_ADDRESS ImageBuffer
;
141 EFI_HANDLE SmmImageHandle
;
142 EFI_LOADED_IMAGE_PROTOCOL SmmLoadedImage
;
143 } EFI_SMM_DRIVER_ENTRY
;
145 #define EFI_HANDLE_SIGNATURE SIGNATURE_32('h','n','d','l')
148 /// IHANDLE - contains a list of protocol handles
152 /// All handles list of IHANDLE
153 LIST_ENTRY AllHandles
;
154 /// List of PROTOCOL_INTERFACE's for this handle
155 LIST_ENTRY Protocols
;
159 #define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature == EFI_HANDLE_SIGNATURE)
161 #define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('p','r','t','e')
164 /// PROTOCOL_ENTRY - each different protocol has 1 entry in the protocol
165 /// database. Each handler that supports this protocol is listed, along
166 /// with a list of registered notifies.
170 /// Link Entry inserted to mProtocolDatabase
171 LIST_ENTRY AllEntries
;
172 /// ID of the protocol
174 /// All protocol interfaces
175 LIST_ENTRY Protocols
;
176 /// Registerd notification handlers
180 #define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('p','i','f','c')
183 /// PROTOCOL_INTERFACE - each protocol installed on a handle is tracked
184 /// with a protocol interface structure
188 /// Link on IHANDLE.Protocols
192 /// Link on PROTOCOL_ENTRY.Protocols
193 LIST_ENTRY ByProtocol
;
195 PROTOCOL_ENTRY
*Protocol
;
196 /// The interface value
198 } PROTOCOL_INTERFACE
;
200 #define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('p','r','t','n')
203 /// PROTOCOL_NOTIFY - used for each register notification for a protocol
207 PROTOCOL_ENTRY
*Protocol
;
208 /// All notifications for this protocol
210 /// Notification function
211 EFI_SMM_NOTIFY_FN Function
;
212 /// Last position notified
213 LIST_ENTRY
*Position
;
217 // SMM Core Global Variables
219 extern SMM_CORE_PRIVATE_DATA
*gSmmCorePrivate
;
220 extern EFI_SMM_SYSTEM_TABLE2 gSmmCoreSmst
;
221 extern LIST_ENTRY gHandleList
;
222 extern EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddressSmramBase
;
225 Called to initialize the memory service.
227 @param SmramRangeCount Number of SMRAM Regions
228 @param SmramRanges Pointer to SMRAM Descriptors
232 SmmInitializeMemoryServices (
233 IN UINTN SmramRangeCount
,
234 IN EFI_SMRAM_DESCRIPTOR
*SmramRanges
238 The SmmInstallConfigurationTable() function is used to maintain the list
239 of configuration tables that are stored in the System Management System
240 Table. The list is stored as an array of (GUID, Pointer) pairs. The list
241 must be allocated from pool memory with PoolType set to EfiRuntimeServicesData.
243 @param SystemTable A pointer to the SMM System Table (SMST).
244 @param Guid A pointer to the GUID for the entry to add, update, or remove.
245 @param Table A pointer to the buffer of the table to add.
246 @param TableSize The size of the table to install.
248 @retval EFI_SUCCESS The (Guid, Table) pair was added, updated, or removed.
249 @retval EFI_INVALID_PARAMETER Guid is not valid.
250 @retval EFI_NOT_FOUND An attempt was made to delete a non-existent entry.
251 @retval EFI_OUT_OF_RESOURCES There is not enough memory available to complete the operation.
256 SmmInstallConfigurationTable (
257 IN CONST EFI_SMM_SYSTEM_TABLE2
*SystemTable
,
258 IN CONST EFI_GUID
*Guid
,
264 Wrapper function to SmmInstallProtocolInterfaceNotify. This is the public API which
265 Calls the private one which contains a BOOLEAN parameter for notifications
267 @param UserHandle The handle to install the protocol handler on,
268 or NULL if a new handle is to be allocated
269 @param Protocol The protocol to add to the handle
270 @param InterfaceType Indicates whether Interface is supplied in
272 @param Interface The interface for the protocol being added
279 SmmInstallProtocolInterface (
280 IN OUT EFI_HANDLE
*UserHandle
,
281 IN EFI_GUID
*Protocol
,
282 IN EFI_INTERFACE_TYPE InterfaceType
,
287 Allocates pages from the memory map.
289 @param Type The type of allocation to perform
290 @param MemoryType The type of memory to turn the allocated pages
292 @param NumberOfPages The number of pages to allocate
293 @param Memory A pointer to receive the base allocated memory
296 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.
297 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
298 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
299 @retval EFI_SUCCESS Pages successfully allocated.
305 IN EFI_ALLOCATE_TYPE Type
,
306 IN EFI_MEMORY_TYPE MemoryType
,
307 IN UINTN NumberOfPages
,
308 OUT EFI_PHYSICAL_ADDRESS
*Memory
312 Allocates pages from the memory map.
314 @param Type The type of allocation to perform
315 @param MemoryType The type of memory to turn the allocated pages
317 @param NumberOfPages The number of pages to allocate
318 @param Memory A pointer to receive the base allocated memory
321 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.
322 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
323 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
324 @retval EFI_SUCCESS Pages successfully allocated.
329 SmmInternalAllocatePages (
330 IN EFI_ALLOCATE_TYPE Type
,
331 IN EFI_MEMORY_TYPE MemoryType
,
332 IN UINTN NumberOfPages
,
333 OUT EFI_PHYSICAL_ADDRESS
*Memory
337 Frees previous allocated pages.
339 @param Memory Base address of memory being freed
340 @param NumberOfPages The number of pages to free
342 @retval EFI_NOT_FOUND Could not find the entry that covers the range
343 @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.
344 @return EFI_SUCCESS Pages successfully freed.
350 IN EFI_PHYSICAL_ADDRESS Memory
,
351 IN UINTN NumberOfPages
355 Frees previous allocated pages.
357 @param Memory Base address of memory being freed
358 @param NumberOfPages The number of pages to free
360 @retval EFI_NOT_FOUND Could not find the entry that covers the range
361 @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.
362 @return EFI_SUCCESS Pages successfully freed.
367 SmmInternalFreePages (
368 IN EFI_PHYSICAL_ADDRESS Memory
,
369 IN UINTN NumberOfPages
373 Allocate pool of a particular type.
375 @param PoolType Type of pool to allocate
376 @param Size The amount of pool to allocate
377 @param Buffer The address to return a pointer to the allocated
380 @retval EFI_INVALID_PARAMETER PoolType not valid
381 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
382 @retval EFI_SUCCESS Pool successfully allocated.
388 IN EFI_MEMORY_TYPE PoolType
,
394 Allocate pool of a particular type.
396 @param PoolType Type of pool to allocate
397 @param Size The amount of pool to allocate
398 @param Buffer The address to return a pointer to the allocated
401 @retval EFI_INVALID_PARAMETER PoolType not valid
402 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
403 @retval EFI_SUCCESS Pool successfully allocated.
408 SmmInternalAllocatePool (
409 IN EFI_MEMORY_TYPE PoolType
,
417 @param Buffer The allocated pool entry to free
419 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.
420 @retval EFI_SUCCESS Pool successfully freed.
432 @param Buffer The allocated pool entry to free
434 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.
435 @retval EFI_SUCCESS Pool successfully freed.
440 SmmInternalFreePool (
445 Installs a protocol interface into the boot services environment.
447 @param UserHandle The handle to install the protocol handler on,
448 or NULL if a new handle is to be allocated
449 @param Protocol The protocol to add to the handle
450 @param InterfaceType Indicates whether Interface is supplied in
452 @param Interface The interface for the protocol being added
453 @param Notify indicates whether notify the notification list
456 @retval EFI_INVALID_PARAMETER Invalid parameter
457 @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate
458 @retval EFI_SUCCESS Protocol interface successfully installed
462 SmmInstallProtocolInterfaceNotify (
463 IN OUT EFI_HANDLE
*UserHandle
,
464 IN EFI_GUID
*Protocol
,
465 IN EFI_INTERFACE_TYPE InterfaceType
,
471 Uninstalls all instances of a protocol:interfacer from a handle.
472 If the last protocol interface is remove from the handle, the
475 @param UserHandle The handle to remove the protocol handler from
476 @param Protocol The protocol, of protocol:interface, to remove
477 @param Interface The interface, of protocol:interface, to remove
479 @retval EFI_INVALID_PARAMETER Protocol is NULL.
480 @retval EFI_SUCCESS Protocol interface successfully uninstalled.
485 SmmUninstallProtocolInterface (
486 IN EFI_HANDLE UserHandle
,
487 IN EFI_GUID
*Protocol
,
492 Queries a handle to determine if it supports a specified protocol.
494 @param UserHandle The handle being queried.
495 @param Protocol The published unique identifier of the protocol.
496 @param Interface Supplies the address where a pointer to the
497 corresponding Protocol Interface is returned.
499 @return The requested protocol interface for the handle
505 IN EFI_HANDLE UserHandle
,
506 IN EFI_GUID
*Protocol
,
511 Add a new protocol notification record for the request protocol.
513 @param Protocol The requested protocol to add the notify
515 @param Function Points to the notification function
516 @param Registration Returns the registration record
518 @retval EFI_INVALID_PARAMETER Invalid parameter
519 @retval EFI_SUCCESS Successfully returned the registration record
525 SmmRegisterProtocolNotify (
526 IN CONST EFI_GUID
*Protocol
,
527 IN EFI_SMM_NOTIFY_FN Function
,
528 OUT VOID
**Registration
532 Locates the requested handle(s) and returns them in Buffer.
534 @param SearchType The type of search to perform to locate the
536 @param Protocol The protocol to search for
537 @param SearchKey Dependant on SearchType
538 @param BufferSize On input the size of Buffer. On output the
539 size of data returned.
540 @param Buffer The buffer to return the results in
542 @retval EFI_BUFFER_TOO_SMALL Buffer too small, required buffer size is
543 returned in BufferSize.
544 @retval EFI_INVALID_PARAMETER Invalid parameter
545 @retval EFI_SUCCESS Successfully found the requested handle(s) and
546 returns them in Buffer.
552 IN EFI_LOCATE_SEARCH_TYPE SearchType
,
553 IN EFI_GUID
*Protocol OPTIONAL
,
554 IN VOID
*SearchKey OPTIONAL
,
555 IN OUT UINTN
*BufferSize
,
556 OUT EFI_HANDLE
*Buffer
560 Return the first Protocol Interface that matches the Protocol GUID. If
561 Registration is pasased in return a Protocol Instance that was just add
562 to the system. If Retistration is NULL return the first Protocol Interface
565 @param Protocol The protocol to search for
566 @param Registration Optional Registration Key returned from
567 RegisterProtocolNotify()
568 @param Interface Return the Protocol interface (instance).
570 @retval EFI_SUCCESS If a valid Interface is returned
571 @retval EFI_INVALID_PARAMETER Invalid parameter
572 @retval EFI_NOT_FOUND Protocol interface not found
578 IN EFI_GUID
*Protocol
,
579 IN VOID
*Registration OPTIONAL
,
584 Function returns an array of handles that support the requested protocol
585 in a buffer allocated from pool. This is a version of SmmLocateHandle()
586 that allocates a buffer for the caller.
588 @param SearchType Specifies which handle(s) are to be returned.
589 @param Protocol Provides the protocol to search by. This
590 parameter is only valid for SearchType
592 @param SearchKey Supplies the search key depending on the
594 @param NumberHandles The number of handles returned in Buffer.
595 @param Buffer A pointer to the buffer to return the requested
596 array of handles that support Protocol.
598 @retval EFI_SUCCESS The result array of handles was returned.
599 @retval EFI_NOT_FOUND No handles match the search.
600 @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the
602 @retval EFI_INVALID_PARAMETER One or more paramters are not valid.
607 SmmLocateHandleBuffer (
608 IN EFI_LOCATE_SEARCH_TYPE SearchType
,
609 IN EFI_GUID
*Protocol OPTIONAL
,
610 IN VOID
*SearchKey OPTIONAL
,
611 IN OUT UINTN
*NumberHandles
,
612 OUT EFI_HANDLE
**Buffer
616 Manage SMI of a particular type.
618 @param HandlerType Points to the handler type or NULL for root SMI handlers.
619 @param Context Points to an optional context buffer.
620 @param CommBuffer Points to the optional communication buffer.
621 @param CommBufferSize Points to the size of the optional communication buffer.
623 @retval EFI_SUCCESS Interrupt source was processed successfully but not quiesced.
624 @retval EFI_INTERRUPT_PENDING One or more SMI sources could not be quiesced.
625 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING Interrupt source was not handled or quiesced.
626 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED Interrupt source was handled and quiesced.
632 IN CONST EFI_GUID
*HandlerType
,
633 IN CONST VOID
*Context OPTIONAL
,
634 IN OUT VOID
*CommBuffer OPTIONAL
,
635 IN OUT UINTN
*CommBufferSize OPTIONAL
639 Registers a handler to execute within SMM.
641 @param Handler Handler service funtion pointer.
642 @param HandlerType Points to the handler type or NULL for root SMI handlers.
643 @param DispatchHandle On return, contains a unique handle which can be used to later unregister the handler function.
645 @retval EFI_SUCCESS Handler register success.
646 @retval EFI_INVALID_PARAMETER Handler or DispatchHandle is NULL.
652 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler
,
653 IN CONST EFI_GUID
*HandlerType OPTIONAL
,
654 OUT EFI_HANDLE
*DispatchHandle
658 Unregister a handler in SMM.
660 @param DispatchHandle The handle that was specified when the handler was registered.
662 @retval EFI_SUCCESS Handler function was successfully unregistered.
663 @retval EFI_INVALID_PARAMETER DispatchHandle does not refer to a valid handle.
668 SmiHandlerUnRegister (
669 IN EFI_HANDLE DispatchHandle
673 This function is the main entry point for an SMM handler dispatch
674 or communicate-based callback.
676 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
677 @param Context Points to an optional handler context which was specified when the handler was registered.
678 @param CommBuffer A pointer to a collection of data in memory that will
679 be conveyed from a non-SMM environment into an SMM environment.
680 @param CommBufferSize The size of the CommBuffer.
687 SmmDriverDispatchHandler (
688 IN EFI_HANDLE DispatchHandle
,
689 IN CONST VOID
*Context
, OPTIONAL
690 IN OUT VOID
*CommBuffer
, OPTIONAL
691 IN OUT UINTN
*CommBufferSize OPTIONAL
695 This function is the main entry point for an SMM handler dispatch
696 or communicate-based callback.
698 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
699 @param Context Points to an optional handler context which was specified when the handler was registered.
700 @param CommBuffer A pointer to a collection of data in memory that will
701 be conveyed from a non-SMM environment into an SMM environment.
702 @param CommBufferSize The size of the CommBuffer.
709 SmmLegacyBootHandler (
710 IN EFI_HANDLE DispatchHandle
,
711 IN CONST VOID
*Context
, OPTIONAL
712 IN OUT VOID
*CommBuffer
, OPTIONAL
713 IN OUT UINTN
*CommBufferSize OPTIONAL
717 This function is the main entry point for an SMM handler dispatch
718 or communicate-based callback.
720 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
721 @param Context Points to an optional handler context which was specified when the handler was registered.
722 @param CommBuffer A pointer to a collection of data in memory that will
723 be conveyed from a non-SMM environment into an SMM environment.
724 @param CommBufferSize The size of the CommBuffer.
731 SmmReadyToLockHandler (
732 IN EFI_HANDLE DispatchHandle
,
733 IN CONST VOID
*Context
, OPTIONAL
734 IN OUT VOID
*CommBuffer
, OPTIONAL
735 IN OUT UINTN
*CommBufferSize OPTIONAL
739 This function is the main entry point for an SMM handler dispatch
740 or communicate-based callback.
742 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
743 @param Context Points to an optional handler context which was specified when the handler was registered.
744 @param CommBuffer A pointer to a collection of data in memory that will
745 be conveyed from a non-SMM environment into an SMM environment.
746 @param CommBufferSize The size of the CommBuffer.
754 IN EFI_HANDLE DispatchHandle
,
755 IN CONST VOID
*Context
, OPTIONAL
756 IN OUT VOID
*CommBuffer
, OPTIONAL
757 IN OUT UINTN
*CommBufferSize OPTIONAL
761 This function is the main entry point for an SMM handler dispatch
762 or communicate-based callback.
764 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
765 @param Context Points to an optional handler context which was specified when the handler was registered.
766 @param CommBuffer A pointer to a collection of data in memory that will
767 be conveyed from a non-SMM environment into an SMM environment.
768 @param CommBufferSize The size of the CommBuffer.
775 SmmExitBootServicesHandler (
776 IN EFI_HANDLE DispatchHandle
,
777 IN CONST VOID
*Context
, OPTIONAL
778 IN OUT VOID
*CommBuffer
, OPTIONAL
779 IN OUT UINTN
*CommBufferSize OPTIONAL
783 This function is the main entry point for an SMM handler dispatch
784 or communicate-based callback.
786 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
787 @param Context Points to an optional handler context which was specified when the handler was registered.
788 @param CommBuffer A pointer to a collection of data in memory that will
789 be conveyed from a non-SMM environment into an SMM environment.
790 @param CommBufferSize The size of the CommBuffer.
797 SmmReadyToBootHandler (
798 IN EFI_HANDLE DispatchHandle
,
799 IN CONST VOID
*Context
, OPTIONAL
800 IN OUT VOID
*CommBuffer
, OPTIONAL
801 IN OUT UINTN
*CommBufferSize OPTIONAL
805 Place holder function until all the SMM System Table Service are available.
807 @param Arg1 Undefined
808 @param Arg2 Undefined
809 @param Arg3 Undefined
810 @param Arg4 Undefined
811 @param Arg5 Undefined
813 @return EFI_NOT_AVAILABLE_YET
818 SmmEfiNotAvailableYetArg5 (
827 //Functions used during debug buils
831 Traverse the discovered list for any drivers that were discovered but not loaded
832 because the dependency experessions evaluated to false.
836 SmmDisplayDiscoveredNotDispatched (
841 Add free SMRAM region for use by memory service.
843 @param MemBase Base address of memory region.
844 @param MemLength Length of the memory region.
845 @param Type Memory type.
846 @param Attributes Memory region state.
851 IN EFI_PHYSICAL_ADDRESS MemBase
,
853 IN EFI_MEMORY_TYPE Type
,
858 Finds the protocol entry for the requested protocol.
860 @param Protocol The ID of the protocol
861 @param Create Create a new entry if not found
863 @return Protocol entry
867 SmmFindProtocolEntry (
868 IN EFI_GUID
*Protocol
,
873 Signal event for every protocol in protocol entry.
875 @param Prot Protocol interface
880 IN PROTOCOL_INTERFACE
*Prot
884 Finds the protocol instance for the requested handle and protocol.
885 Note: This function doesn't do parameters checking, it's caller's responsibility
886 to pass in valid parameters.
888 @param Handle The handle to search the protocol on
889 @param Protocol GUID of the protocol
890 @param Interface The interface for the protocol being searched
892 @return Protocol instance (NULL: Not found)
896 SmmFindProtocolInterface (
898 IN EFI_GUID
*Protocol
,
903 Removes Protocol from the protocol list (but not the handle list).
905 @param Handle The handle to remove protocol on.
906 @param Protocol GUID of the protocol to be moved
907 @param Interface The interface of the protocol
909 @return Protocol Entry
913 SmmRemoveInterfaceFromProtocol (
915 IN EFI_GUID
*Protocol
,
920 This is the POSTFIX version of the dependency evaluator. This code does
921 not need to handle Before or After, as it is not valid to call this
922 routine in this case. POSTFIX means all the math is done on top of the stack.
924 @param DriverEntry DriverEntry element to update.
926 @retval TRUE If driver is ready to run.
927 @retval FALSE If driver is not ready to run or some fatal error
933 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
941 Initialize SMRAM profile.
950 Install SMRAM profile protocol.
954 SmramProfileInstallProtocol (
959 Register SMM image to SMRAM profile.
961 @param DriverEntry SMM image info.
962 @param RegisterToDxe Register image to DXE.
964 @return EFI_SUCCESS Register successfully.
965 @return EFI_UNSUPPORTED Memory profile unsupported,
966 or memory profile for the image is not required.
967 @return EFI_OUT_OF_RESOURCES No enough resource for this register.
971 RegisterSmramProfileImage (
972 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
,
973 IN BOOLEAN RegisterToDxe
977 Unregister image from SMRAM profile.
979 @param DriverEntry SMM image info.
980 @param UnregisterToDxe Unregister image from DXE.
982 @return EFI_SUCCESS Unregister successfully.
983 @return EFI_UNSUPPORTED Memory profile unsupported,
984 or memory profile for the image is not required.
985 @return EFI_NOT_FOUND The image is not found.
989 UnregisterSmramProfileImage (
990 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
,
991 IN BOOLEAN UnregisterToDxe
995 Update SMRAM profile information.
997 @param CallerAddress Address of caller who call Allocate or Free.
998 @param Action This Allocate or Free action.
999 @param MemoryType Memory type.
1000 EfiMaxMemoryType means the MemoryType is unknown.
1001 @param Size Buffer size.
1002 @param Buffer Buffer address.
1003 @param ActionString String for memory profile action.
1004 Only needed for user defined allocate action.
1006 @return EFI_SUCCESS Memory profile is updated.
1007 @return EFI_UNSUPPORTED Memory profile is unsupported,
1008 or memory profile for the image is not required,
1009 or memory profile for the memory type is not required.
1010 @return EFI_ACCESS_DENIED It is during memory profile data getting.
1011 @return EFI_ABORTED Memory profile recording is not enabled.
1012 @return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.
1013 @return EFI_NOT_FOUND No matched allocate info found for free action.
1018 SmmCoreUpdateProfile (
1019 IN PHYSICAL_ADDRESS CallerAddress
,
1020 IN MEMORY_PROFILE_ACTION Action
,
1021 IN EFI_MEMORY_TYPE MemoryType
, // Valid for AllocatePages/AllocatePool
1022 IN UINTN Size
, // Valid for AllocatePages/FreePages/AllocatePool
1024 IN CHAR8
*ActionString OPTIONAL
1028 Register SMRAM profile handler.
1032 RegisterSmramProfileHandler (
1037 SMRAM profile ready to lock callback function.
1041 SmramProfileReadyToLock (
1046 Initialize MemoryAttributes support.
1050 SmmCoreInitializeMemoryAttributesTable (
1055 This function returns a copy of the current memory map. The map is an array of
1056 memory descriptors, each of which describes a contiguous block of memory.
1058 @param[in, out] MemoryMapSize A pointer to the size, in bytes, of the
1059 MemoryMap buffer. On input, this is the size of
1060 the buffer allocated by the caller. On output,
1061 it is the size of the buffer returned by the
1062 firmware if the buffer was large enough, or the
1063 size of the buffer needed to contain the map if
1064 the buffer was too small.
1065 @param[in, out] MemoryMap A pointer to the buffer in which firmware places
1066 the current memory map.
1067 @param[out] MapKey A pointer to the location in which firmware
1068 returns the key for the current memory map.
1069 @param[out] DescriptorSize A pointer to the location in which firmware
1070 returns the size, in bytes, of an individual
1071 EFI_MEMORY_DESCRIPTOR.
1072 @param[out] DescriptorVersion A pointer to the location in which firmware
1073 returns the version number associated with the
1074 EFI_MEMORY_DESCRIPTOR.
1076 @retval EFI_SUCCESS The memory map was returned in the MemoryMap
1078 @retval EFI_BUFFER_TOO_SMALL The MemoryMap buffer was too small. The current
1079 buffer size needed to hold the memory map is
1080 returned in MemoryMapSize.
1081 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
1086 SmmCoreGetMemoryMap (
1087 IN OUT UINTN
*MemoryMapSize
,
1088 IN OUT EFI_MEMORY_DESCRIPTOR
*MemoryMap
,
1090 OUT UINTN
*DescriptorSize
,
1091 OUT UINT32
*DescriptorVersion
1095 Initialize SmiHandler profile feature.
1098 SmmCoreInitializeSmiHandlerProfile (
1103 This function is called by SmmChildDispatcher module to report
1104 a new SMI handler is registered, to SmmCore.
1106 @param This The protocol instance
1107 @param HandlerGuid The GUID to identify the type of the handler.
1108 For the SmmChildDispatch protocol, the HandlerGuid
1109 must be the GUID of SmmChildDispatch protocol.
1110 @param Handler The SMI handler.
1111 @param CallerAddress The address of the module who registers the SMI handler.
1112 @param Context The context of the SMI handler.
1113 For the SmmChildDispatch protocol, the Context
1114 must match the one defined for SmmChildDispatch protocol.
1115 @param ContextSize The size of the context in bytes.
1116 For the SmmChildDispatch protocol, the Context
1117 must match the one defined for SmmChildDispatch protocol.
1119 @retval EFI_SUCCESS The information is recorded.
1120 @retval EFI_OUT_OF_RESOURCES There is no enough resource to record the information.
1124 SmiHandlerProfileRegisterHandler (
1125 IN SMI_HANDLER_PROFILE_PROTOCOL
*This
,
1126 IN EFI_GUID
*HandlerGuid
,
1127 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler
,
1128 IN PHYSICAL_ADDRESS CallerAddress
,
1129 IN VOID
*Context
, OPTIONAL
1130 IN UINTN ContextSize OPTIONAL
1134 This function is called by SmmChildDispatcher module to report
1135 an existing SMI handler is unregistered, to SmmCore.
1137 @param This The protocol instance
1138 @param HandlerGuid The GUID to identify the type of the handler.
1139 For the SmmChildDispatch protocol, the HandlerGuid
1140 must be the GUID of SmmChildDispatch protocol.
1141 @param Handler The SMI handler.
1142 @param Context The context of the SMI handler.
1143 If it is NOT NULL, it will be used to check what is registered.
1144 @param ContextSize The size of the context in bytes.
1145 If Context is NOT NULL, it will be used to check what is registered.
1147 @retval EFI_SUCCESS The original record is removed.
1148 @retval EFI_NOT_FOUND There is no record for the HandlerGuid and handler.
1152 SmiHandlerProfileUnregisterHandler (
1153 IN SMI_HANDLER_PROFILE_PROTOCOL
*This
,
1154 IN EFI_GUID
*HandlerGuid
,
1155 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler
,
1156 IN VOID
*Context
, OPTIONAL
1157 IN UINTN ContextSize OPTIONAL
1160 extern UINTN mFullSmramRangeCount
;
1161 extern EFI_SMRAM_DESCRIPTOR
*mFullSmramRanges
;
1163 extern EFI_SMM_DRIVER_ENTRY
*mSmmCoreDriverEntry
;
1165 extern EFI_LOADED_IMAGE_PROTOCOL
*mSmmCoreLoadedImage
;
1173 UINTN NumberOfPages
;
1176 extern LIST_ENTRY mSmmMemoryMap
;
1183 // MIN_POOL_SHIFT must not be less than 5
1185 #define MIN_POOL_SHIFT 6
1186 #define MIN_POOL_SIZE (1 << MIN_POOL_SHIFT)
1189 // MAX_POOL_SHIFT must not be less than EFI_PAGE_SHIFT - 1
1191 #define MAX_POOL_SHIFT (EFI_PAGE_SHIFT - 1)
1192 #define MAX_POOL_SIZE (1 << MAX_POOL_SHIFT)
1195 // MAX_POOL_INDEX are calculated by maximum and minimum pool sizes
1197 #define MAX_POOL_INDEX (MAX_POOL_SHIFT - MIN_POOL_SHIFT + 1)
1202 EFI_MEMORY_TYPE Type
;
1216 extern LIST_ENTRY mSmmPoolLists
[SmmPoolTypeMax
][MAX_POOL_INDEX
];