2 The internal header file includes the common header files, defines
3 internal structure and functions used by SmmCore module.
5 Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
15 #include <Protocol/DxeSmmReadyToLock.h>
16 #include <Protocol/SmmReadyToLock.h>
17 #include <Protocol/SmmEndOfDxe.h>
18 #include <Protocol/CpuIo2.h>
19 #include <Protocol/SmmCommunication.h>
20 #include <Protocol/SmmAccess2.h>
21 #include <Protocol/FirmwareVolume2.h>
22 #include <Protocol/LoadedImage.h>
23 #include <Protocol/DevicePath.h>
24 #include <Protocol/Security.h>
25 #include <Protocol/Security2.h>
26 #include <Protocol/SmmExitBootServices.h>
27 #include <Protocol/SmmLegacyBoot.h>
28 #include <Protocol/SmmReadyToBoot.h>
29 #include <Protocol/SmmMemoryAttribute.h>
30 #include <Protocol/SmmSxDispatch2.h>
32 #include <Guid/Apriori.h>
33 #include <Guid/EventGroup.h>
34 #include <Guid/EventLegacyBios.h>
35 #include <Guid/MemoryProfile.h>
36 #include <Guid/LoadModuleAtFixedAddress.h>
37 #include <Guid/SmiHandlerProfile.h>
38 #include <Guid/EndOfS3Resume.h>
39 #include <Guid/S3SmmInitDone.h>
41 #include <Library/BaseLib.h>
42 #include <Library/BaseMemoryLib.h>
43 #include <Library/PeCoffLib.h>
44 #include <Library/PeCoffGetEntryPointLib.h>
45 #include <Library/CacheMaintenanceLib.h>
46 #include <Library/DebugLib.h>
47 #include <Library/ReportStatusCodeLib.h>
48 #include <Library/MemoryAllocationLib.h>
49 #include <Library/DevicePathLib.h>
50 #include <Library/UefiLib.h>
51 #include <Library/UefiBootServicesTableLib.h>
52 #include <Library/PcdLib.h>
53 #include <Library/SmmCorePlatformHookLib.h>
54 #include <Library/PerformanceLib.h>
55 #include <Library/HobLib.h>
56 #include <Library/SmmMemLib.h>
57 #include <Library/SafeIntLib.h>
59 #include "PiSmmCorePrivateData.h"
60 #include "HeapGuard.h"
63 // Used to build a table of SMI Handlers that the SMM Core registers
66 EFI_SMM_HANDLER_ENTRY_POINT2 Handler
;
67 EFI_GUID
*HandlerType
;
68 EFI_HANDLE DispatchHandle
;
70 } SMM_CORE_SMI_HANDLERS
;
73 // SMM_HANDLER - used for each SMM handler
76 #define SMI_ENTRY_SIGNATURE SIGNATURE_32('s','m','i','e')
80 LIST_ENTRY AllEntries
; // All entries
82 EFI_GUID HandlerType
; // Type of interrupt
83 LIST_ENTRY SmiHandlers
; // All handlers
86 #define SMI_HANDLER_SIGNATURE SIGNATURE_32('s','m','i','h')
90 LIST_ENTRY Link
; // Link on SMI_ENTRY.SmiHandlers
91 EFI_SMM_HANDLER_ENTRY_POINT2 Handler
; // The smm handler's entry point
92 UINTN CallerAddr
; // The address of caller who register the SMI handler.
94 VOID
*Context
; // for profile
95 UINTN ContextSize
; // for profile
99 // Structure for recording the state of an SMM Driver
101 #define EFI_SMM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v')
105 LIST_ENTRY Link
; // mDriverList
107 LIST_ENTRY ScheduledLink
; // mScheduledQueue
111 EFI_DEVICE_PATH_PROTOCOL
*FvFileDevicePath
;
112 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
119 EFI_GUID BeforeAfterGuid
;
124 BOOLEAN DepexProtocolError
;
126 EFI_HANDLE ImageHandle
;
127 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
129 // Image EntryPoint in SMRAM
131 PHYSICAL_ADDRESS ImageEntryPoint
;
133 // Image Buffer in SMRAM
135 PHYSICAL_ADDRESS ImageBuffer
;
140 EFI_HANDLE SmmImageHandle
;
141 EFI_LOADED_IMAGE_PROTOCOL SmmLoadedImage
;
142 } EFI_SMM_DRIVER_ENTRY
;
144 #define EFI_HANDLE_SIGNATURE SIGNATURE_32('s','h','d','l')
147 /// IHANDLE - contains a list of protocol handles
151 /// All handles list of IHANDLE
152 LIST_ENTRY AllHandles
;
153 /// List of PROTOCOL_INTERFACE's for this handle
154 LIST_ENTRY Protocols
;
158 #define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature == EFI_HANDLE_SIGNATURE)
160 #define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('s','p','t','e')
163 /// PROTOCOL_ENTRY - each different protocol has 1 entry in the protocol
164 /// database. Each handler that supports this protocol is listed, along
165 /// with a list of registered notifies.
169 /// Link Entry inserted to mProtocolDatabase
170 LIST_ENTRY AllEntries
;
171 /// ID of the protocol
173 /// All protocol interfaces
174 LIST_ENTRY Protocols
;
175 /// Registered notification handlers
179 #define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('s','p','i','f')
182 /// PROTOCOL_INTERFACE - each protocol installed on a handle is tracked
183 /// with a protocol interface structure
187 /// Link on IHANDLE.Protocols
191 /// Link on PROTOCOL_ENTRY.Protocols
192 LIST_ENTRY ByProtocol
;
194 PROTOCOL_ENTRY
*Protocol
;
195 /// The interface value
197 } PROTOCOL_INTERFACE
;
199 #define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('s','p','t','n')
202 /// PROTOCOL_NOTIFY - used for each register notification for a protocol
206 PROTOCOL_ENTRY
*Protocol
;
207 /// All notifications for this protocol
209 /// Notification function
210 EFI_SMM_NOTIFY_FN Function
;
211 /// Last position notified
212 LIST_ENTRY
*Position
;
216 // SMM Core Global Variables
218 extern SMM_CORE_PRIVATE_DATA
*gSmmCorePrivate
;
219 extern EFI_SMM_SYSTEM_TABLE2 gSmmCoreSmst
;
220 extern LIST_ENTRY gHandleList
;
221 extern EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddressSmramBase
;
224 Called to initialize the memory service.
226 @param SmramRangeCount Number of SMRAM Regions
227 @param SmramRanges Pointer to SMRAM Descriptors
231 SmmInitializeMemoryServices (
232 IN UINTN SmramRangeCount
,
233 IN EFI_SMRAM_DESCRIPTOR
*SmramRanges
237 The SmmInstallConfigurationTable() function is used to maintain the list
238 of configuration tables that are stored in the System Management System
239 Table. The list is stored as an array of (GUID, Pointer) pairs. The list
240 must be allocated from pool memory with PoolType set to EfiRuntimeServicesData.
242 @param SystemTable A pointer to the SMM System Table (SMST).
243 @param Guid A pointer to the GUID for the entry to add, update, or remove.
244 @param Table A pointer to the buffer of the table to add.
245 @param TableSize The size of the table to install.
247 @retval EFI_SUCCESS The (Guid, Table) pair was added, updated, or removed.
248 @retval EFI_INVALID_PARAMETER Guid is not valid.
249 @retval EFI_NOT_FOUND An attempt was made to delete a non-existent entry.
250 @retval EFI_OUT_OF_RESOURCES There is not enough memory available to complete the operation.
255 SmmInstallConfigurationTable (
256 IN CONST EFI_SMM_SYSTEM_TABLE2
*SystemTable
,
257 IN CONST EFI_GUID
*Guid
,
263 Wrapper function to SmmInstallProtocolInterfaceNotify. This is the public API which
264 Calls the private one which contains a BOOLEAN parameter for notifications
266 @param UserHandle The handle to install the protocol handler on,
267 or NULL if a new handle is to be allocated
268 @param Protocol The protocol to add to the handle
269 @param InterfaceType Indicates whether Interface is supplied in
271 @param Interface The interface for the protocol being added
278 SmmInstallProtocolInterface (
279 IN OUT EFI_HANDLE
*UserHandle
,
280 IN EFI_GUID
*Protocol
,
281 IN EFI_INTERFACE_TYPE InterfaceType
,
286 Allocates pages from the memory map.
288 @param Type The type of allocation to perform
289 @param MemoryType The type of memory to turn the allocated pages
291 @param NumberOfPages The number of pages to allocate
292 @param Memory A pointer to receive the base allocated memory
295 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.
296 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
297 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
298 @retval EFI_SUCCESS Pages successfully allocated.
304 IN EFI_ALLOCATE_TYPE Type
,
305 IN EFI_MEMORY_TYPE MemoryType
,
306 IN UINTN NumberOfPages
,
307 OUT EFI_PHYSICAL_ADDRESS
*Memory
311 Allocates pages from the memory map.
313 @param Type The type of allocation to perform
314 @param MemoryType The type of memory to turn the allocated pages
316 @param NumberOfPages The number of pages to allocate
317 @param Memory A pointer to receive the base allocated memory
319 @param NeedGuard Flag to indicate Guard page is needed or not
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
,
338 Frees previous allocated pages.
340 @param Memory Base address of memory being freed
341 @param NumberOfPages The number of pages to free
343 @retval EFI_NOT_FOUND Could not find the entry that covers the range
344 @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.
345 @return EFI_SUCCESS Pages successfully freed.
351 IN EFI_PHYSICAL_ADDRESS Memory
,
352 IN UINTN NumberOfPages
356 Frees previous allocated pages.
358 @param Memory Base address of memory being freed
359 @param NumberOfPages The number of pages to free
360 @param IsGuarded Flag to indicate if the memory is guarded
363 @retval EFI_NOT_FOUND Could not find the entry that covers the range
364 @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.
365 @return EFI_SUCCESS Pages successfully freed.
370 SmmInternalFreePages (
371 IN EFI_PHYSICAL_ADDRESS Memory
,
372 IN UINTN NumberOfPages
,
377 Allocate pool of a particular type.
379 @param PoolType Type of pool to allocate
380 @param Size The amount of pool to allocate
381 @param Buffer The address to return a pointer to the allocated
384 @retval EFI_INVALID_PARAMETER PoolType not valid
385 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
386 @retval EFI_SUCCESS Pool successfully allocated.
392 IN EFI_MEMORY_TYPE PoolType
,
398 Allocate pool of a particular type.
400 @param PoolType Type of pool to allocate
401 @param Size The amount of pool to allocate
402 @param Buffer The address to return a pointer to the allocated
405 @retval EFI_INVALID_PARAMETER PoolType not valid
406 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
407 @retval EFI_SUCCESS Pool successfully allocated.
412 SmmInternalAllocatePool (
413 IN EFI_MEMORY_TYPE PoolType
,
421 @param Buffer The allocated pool entry to free
423 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.
424 @retval EFI_SUCCESS Pool successfully freed.
436 @param Buffer The allocated pool entry to free
438 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.
439 @retval EFI_SUCCESS Pool successfully freed.
444 SmmInternalFreePool (
449 Installs a protocol interface into the boot services environment.
451 @param UserHandle The handle to install the protocol handler on,
452 or NULL if a new handle is to be allocated
453 @param Protocol The protocol to add to the handle
454 @param InterfaceType Indicates whether Interface is supplied in
456 @param Interface The interface for the protocol being added
457 @param Notify indicates whether notify the notification list
460 @retval EFI_INVALID_PARAMETER Invalid parameter
461 @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate
462 @retval EFI_SUCCESS Protocol interface successfully installed
466 SmmInstallProtocolInterfaceNotify (
467 IN OUT EFI_HANDLE
*UserHandle
,
468 IN EFI_GUID
*Protocol
,
469 IN EFI_INTERFACE_TYPE InterfaceType
,
475 Uninstalls all instances of a protocol:interfacer from a handle.
476 If the last protocol interface is remove from the handle, the
479 @param UserHandle The handle to remove the protocol handler from
480 @param Protocol The protocol, of protocol:interface, to remove
481 @param Interface The interface, of protocol:interface, to remove
483 @retval EFI_INVALID_PARAMETER Protocol is NULL.
484 @retval EFI_SUCCESS Protocol interface successfully uninstalled.
489 SmmUninstallProtocolInterface (
490 IN EFI_HANDLE UserHandle
,
491 IN EFI_GUID
*Protocol
,
496 Queries a handle to determine if it supports a specified protocol.
498 @param UserHandle The handle being queried.
499 @param Protocol The published unique identifier of the protocol.
500 @param Interface Supplies the address where a pointer to the
501 corresponding Protocol Interface is returned.
503 @return The requested protocol interface for the handle
509 IN EFI_HANDLE UserHandle
,
510 IN EFI_GUID
*Protocol
,
515 Add a new protocol notification record for the request protocol.
517 @param Protocol The requested protocol to add the notify
519 @param Function Points to the notification function
520 @param Registration Returns the registration record
522 @retval EFI_INVALID_PARAMETER Invalid parameter
523 @retval EFI_SUCCESS Successfully returned the registration record
529 SmmRegisterProtocolNotify (
530 IN CONST EFI_GUID
*Protocol
,
531 IN EFI_SMM_NOTIFY_FN Function
,
532 OUT VOID
**Registration
536 Locates the requested handle(s) and returns them in Buffer.
538 @param SearchType The type of search to perform to locate the
540 @param Protocol The protocol to search for
541 @param SearchKey Dependant on SearchType
542 @param BufferSize On input the size of Buffer. On output the
543 size of data returned.
544 @param Buffer The buffer to return the results in
546 @retval EFI_BUFFER_TOO_SMALL Buffer too small, required buffer size is
547 returned in BufferSize.
548 @retval EFI_INVALID_PARAMETER Invalid parameter
549 @retval EFI_SUCCESS Successfully found the requested handle(s) and
550 returns them in Buffer.
556 IN EFI_LOCATE_SEARCH_TYPE SearchType
,
557 IN EFI_GUID
*Protocol OPTIONAL
,
558 IN VOID
*SearchKey OPTIONAL
,
559 IN OUT UINTN
*BufferSize
,
560 OUT EFI_HANDLE
*Buffer
564 Return the first Protocol Interface that matches the Protocol GUID. If
565 Registration is pasased in return a Protocol Instance that was just add
566 to the system. If Registration is NULL return the first Protocol Interface
569 @param Protocol The protocol to search for
570 @param Registration Optional Registration Key returned from
571 RegisterProtocolNotify()
572 @param Interface Return the Protocol interface (instance).
574 @retval EFI_SUCCESS If a valid Interface is returned
575 @retval EFI_INVALID_PARAMETER Invalid parameter
576 @retval EFI_NOT_FOUND Protocol interface not found
582 IN EFI_GUID
*Protocol
,
583 IN VOID
*Registration OPTIONAL
,
588 Function returns an array of handles that support the requested protocol
589 in a buffer allocated from pool. This is a version of SmmLocateHandle()
590 that allocates a buffer for the caller.
592 @param SearchType Specifies which handle(s) are to be returned.
593 @param Protocol Provides the protocol to search by. This
594 parameter is only valid for SearchType
596 @param SearchKey Supplies the search key depending on the
598 @param NumberHandles The number of handles returned in Buffer.
599 @param Buffer A pointer to the buffer to return the requested
600 array of handles that support Protocol.
602 @retval EFI_SUCCESS The result array of handles was returned.
603 @retval EFI_NOT_FOUND No handles match the search.
604 @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the
606 @retval EFI_INVALID_PARAMETER One or more parameters are not valid.
611 SmmLocateHandleBuffer (
612 IN EFI_LOCATE_SEARCH_TYPE SearchType
,
613 IN EFI_GUID
*Protocol OPTIONAL
,
614 IN VOID
*SearchKey OPTIONAL
,
615 IN OUT UINTN
*NumberHandles
,
616 OUT EFI_HANDLE
**Buffer
620 Manage SMI of a particular type.
622 @param HandlerType Points to the handler type or NULL for root SMI handlers.
623 @param Context Points to an optional context buffer.
624 @param CommBuffer Points to the optional communication buffer.
625 @param CommBufferSize Points to the size of the optional communication buffer.
627 @retval EFI_SUCCESS Interrupt source was processed successfully but not quiesced.
628 @retval EFI_INTERRUPT_PENDING One or more SMI sources could not be quiesced.
629 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING Interrupt source was not handled or quiesced.
630 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED Interrupt source was handled and quiesced.
636 IN CONST EFI_GUID
*HandlerType
,
637 IN CONST VOID
*Context OPTIONAL
,
638 IN OUT VOID
*CommBuffer OPTIONAL
,
639 IN OUT UINTN
*CommBufferSize OPTIONAL
643 Registers a handler to execute within SMM.
645 @param Handler Handler service function pointer.
646 @param HandlerType Points to the handler type or NULL for root SMI handlers.
647 @param DispatchHandle On return, contains a unique handle which can be used to later unregister the handler function.
649 @retval EFI_SUCCESS Handler register success.
650 @retval EFI_INVALID_PARAMETER Handler or DispatchHandle is NULL.
656 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler
,
657 IN CONST EFI_GUID
*HandlerType OPTIONAL
,
658 OUT EFI_HANDLE
*DispatchHandle
662 Unregister a handler in SMM.
664 @param DispatchHandle The handle that was specified when the handler was registered.
666 @retval EFI_SUCCESS Handler function was successfully unregistered.
667 @retval EFI_INVALID_PARAMETER DispatchHandle does not refer to a valid handle.
672 SmiHandlerUnRegister (
673 IN EFI_HANDLE DispatchHandle
677 This function is the main entry point for an SMM handler dispatch
678 or communicate-based callback.
680 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
681 @param Context Points to an optional handler context which was specified when the handler was registered.
682 @param CommBuffer A pointer to a collection of data in memory that will
683 be conveyed from a non-SMM environment into an SMM environment.
684 @param CommBufferSize The size of the CommBuffer.
691 SmmDriverDispatchHandler (
692 IN EFI_HANDLE DispatchHandle
,
693 IN CONST VOID
*Context OPTIONAL
,
694 IN OUT VOID
*CommBuffer OPTIONAL
,
695 IN OUT UINTN
*CommBufferSize OPTIONAL
699 This function is the main entry point for an SMM handler dispatch
700 or communicate-based callback.
702 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
703 @param Context Points to an optional handler context which was specified when the handler was registered.
704 @param CommBuffer A pointer to a collection of data in memory that will
705 be conveyed from a non-SMM environment into an SMM environment.
706 @param CommBufferSize The size of the CommBuffer.
713 SmmLegacyBootHandler (
714 IN EFI_HANDLE DispatchHandle
,
715 IN CONST VOID
*Context OPTIONAL
,
716 IN OUT VOID
*CommBuffer OPTIONAL
,
717 IN OUT UINTN
*CommBufferSize OPTIONAL
721 This function is the main entry point for an SMM handler dispatch
722 or communicate-based callback.
724 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
725 @param Context Points to an optional handler context which was specified when the handler was registered.
726 @param CommBuffer A pointer to a collection of data in memory that will
727 be conveyed from a non-SMM environment into an SMM environment.
728 @param CommBufferSize The size of the CommBuffer.
735 SmmReadyToLockHandler (
736 IN EFI_HANDLE DispatchHandle
,
737 IN CONST VOID
*Context OPTIONAL
,
738 IN OUT VOID
*CommBuffer OPTIONAL
,
739 IN OUT UINTN
*CommBufferSize OPTIONAL
743 This function is the main entry point for an SMM handler dispatch
744 or communicate-based callback.
746 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
747 @param Context Points to an optional handler context which was specified when the handler was registered.
748 @param CommBuffer A pointer to a collection of data in memory that will
749 be conveyed from a non-SMM environment into an SMM environment.
750 @param CommBufferSize The size of the CommBuffer.
758 IN EFI_HANDLE DispatchHandle
,
759 IN CONST VOID
*Context OPTIONAL
,
760 IN OUT VOID
*CommBuffer OPTIONAL
,
761 IN OUT UINTN
*CommBufferSize OPTIONAL
765 This function is the main entry point for an SMM handler dispatch
766 or communicate-based callback.
768 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
769 @param Context Points to an optional handler context which was specified when the handler was registered.
770 @param CommBuffer A pointer to a collection of data in memory that will
771 be conveyed from a non-SMM environment into an SMM environment.
772 @param CommBufferSize The size of the CommBuffer.
779 SmmExitBootServicesHandler (
780 IN EFI_HANDLE DispatchHandle
,
781 IN CONST VOID
*Context OPTIONAL
,
782 IN OUT VOID
*CommBuffer OPTIONAL
,
783 IN OUT UINTN
*CommBufferSize OPTIONAL
787 This function is the main entry point for an SMM handler dispatch
788 or communicate-based callback.
790 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
791 @param Context Points to an optional handler context which was specified when the handler was registered.
792 @param CommBuffer A pointer to a collection of data in memory that will
793 be conveyed from a non-SMM environment into an SMM environment.
794 @param CommBufferSize The size of the CommBuffer.
801 SmmReadyToBootHandler (
802 IN EFI_HANDLE DispatchHandle
,
803 IN CONST VOID
*Context OPTIONAL
,
804 IN OUT VOID
*CommBuffer OPTIONAL
,
805 IN OUT UINTN
*CommBufferSize OPTIONAL
809 Software SMI handler that is called when the S3SmmInitDone signal is triggered.
810 This function installs the SMM S3SmmInitDone Protocol so SMM Drivers are informed that
811 S3 SMM initialization has been done.
813 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
814 @param Context Points to an optional handler context which was specified when the handler was registered.
815 @param CommBuffer A pointer to a collection of data in memory that will
816 be conveyed from a non-SMM environment into an SMM environment.
817 @param CommBufferSize The size of the CommBuffer.
824 SmmS3SmmInitDoneHandler (
825 IN EFI_HANDLE DispatchHandle
,
826 IN CONST VOID
*Context OPTIONAL
,
827 IN OUT VOID
*CommBuffer OPTIONAL
,
828 IN OUT UINTN
*CommBufferSize OPTIONAL
832 Software SMI handler that is called when the EndOfS3Resume event is trigged.
833 This function installs the SMM EndOfS3Resume Protocol so SMM Drivers are informed that
834 S3 resume has finished.
836 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
837 @param Context Points to an optional handler context which was specified when the handler was registered.
838 @param CommBuffer A pointer to a collection of data in memory that will
839 be conveyed from a non-SMM environment into an SMM environment.
840 @param CommBufferSize The size of the CommBuffer.
847 SmmEndOfS3ResumeHandler (
848 IN EFI_HANDLE DispatchHandle
,
849 IN CONST VOID
*Context OPTIONAL
,
850 IN OUT VOID
*CommBuffer OPTIONAL
,
851 IN OUT UINTN
*CommBufferSize OPTIONAL
855 Place holder function until all the SMM System Table Service are available.
857 @param Arg1 Undefined
858 @param Arg2 Undefined
859 @param Arg3 Undefined
860 @param Arg4 Undefined
861 @param Arg5 Undefined
863 @return EFI_NOT_AVAILABLE_YET
868 SmmEfiNotAvailableYetArg5 (
877 // Functions used during debug builds
881 Traverse the discovered list for any drivers that were discovered but not loaded
882 because the dependency expressions evaluated to false.
886 SmmDisplayDiscoveredNotDispatched (
891 Add free SMRAM region for use by memory service.
893 @param MemBase Base address of memory region.
894 @param MemLength Length of the memory region.
895 @param Type Memory type.
896 @param Attributes Memory region state.
901 IN EFI_PHYSICAL_ADDRESS MemBase
,
903 IN EFI_MEMORY_TYPE Type
,
908 Finds the protocol entry for the requested protocol.
910 @param Protocol The ID of the protocol
911 @param Create Create a new entry if not found
913 @return Protocol entry
917 SmmFindProtocolEntry (
918 IN EFI_GUID
*Protocol
,
923 Signal event for every protocol in protocol entry.
925 @param Prot Protocol interface
930 IN PROTOCOL_INTERFACE
*Prot
934 Finds the protocol instance for the requested handle and protocol.
935 Note: This function doesn't do parameters checking, it's caller's responsibility
936 to pass in valid parameters.
938 @param Handle The handle to search the protocol on
939 @param Protocol GUID of the protocol
940 @param Interface The interface for the protocol being searched
942 @return Protocol instance (NULL: Not found)
946 SmmFindProtocolInterface (
948 IN EFI_GUID
*Protocol
,
953 Removes Protocol from the protocol list (but not the handle list).
955 @param Handle The handle to remove protocol on.
956 @param Protocol GUID of the protocol to be moved
957 @param Interface The interface of the protocol
959 @return Protocol Entry
963 SmmRemoveInterfaceFromProtocol (
965 IN EFI_GUID
*Protocol
,
970 This is the POSTFIX version of the dependency evaluator. This code does
971 not need to handle Before or After, as it is not valid to call this
972 routine in this case. POSTFIX means all the math is done on top of the stack.
974 @param DriverEntry DriverEntry element to update.
976 @retval TRUE If driver is ready to run.
977 @retval FALSE If driver is not ready to run or some fatal error
983 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
991 Initialize SMRAM profile.
1000 Install SMRAM profile protocol.
1004 SmramProfileInstallProtocol (
1009 Register SMM image to SMRAM profile.
1011 @param DriverEntry SMM image info.
1012 @param RegisterToDxe Register image to DXE.
1014 @return EFI_SUCCESS Register successfully.
1015 @return EFI_UNSUPPORTED Memory profile unsupported,
1016 or memory profile for the image is not required.
1017 @return EFI_OUT_OF_RESOURCES No enough resource for this register.
1021 RegisterSmramProfileImage (
1022 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
,
1023 IN BOOLEAN RegisterToDxe
1027 Unregister image from SMRAM profile.
1029 @param DriverEntry SMM image info.
1030 @param UnregisterToDxe Unregister image from DXE.
1032 @return EFI_SUCCESS Unregister successfully.
1033 @return EFI_UNSUPPORTED Memory profile unsupported,
1034 or memory profile for the image is not required.
1035 @return EFI_NOT_FOUND The image is not found.
1039 UnregisterSmramProfileImage (
1040 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
,
1041 IN BOOLEAN UnregisterToDxe
1045 Update SMRAM profile information.
1047 @param CallerAddress Address of caller who call Allocate or Free.
1048 @param Action This Allocate or Free action.
1049 @param MemoryType Memory type.
1050 EfiMaxMemoryType means the MemoryType is unknown.
1051 @param Size Buffer size.
1052 @param Buffer Buffer address.
1053 @param ActionString String for memory profile action.
1054 Only needed for user defined allocate action.
1056 @return EFI_SUCCESS Memory profile is updated.
1057 @return EFI_UNSUPPORTED Memory profile is unsupported,
1058 or memory profile for the image is not required,
1059 or memory profile for the memory type is not required.
1060 @return EFI_ACCESS_DENIED It is during memory profile data getting.
1061 @return EFI_ABORTED Memory profile recording is not enabled.
1062 @return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.
1063 @return EFI_NOT_FOUND No matched allocate info found for free action.
1068 SmmCoreUpdateProfile (
1069 IN PHYSICAL_ADDRESS CallerAddress
,
1070 IN MEMORY_PROFILE_ACTION Action
,
1071 IN EFI_MEMORY_TYPE MemoryType
, // Valid for AllocatePages/AllocatePool
1072 IN UINTN Size
, // Valid for AllocatePages/FreePages/AllocatePool
1074 IN CHAR8
*ActionString OPTIONAL
1078 Register SMRAM profile handler.
1082 RegisterSmramProfileHandler (
1087 SMRAM profile ready to lock callback function.
1091 SmramProfileReadyToLock (
1096 Initialize MemoryAttributes support.
1100 SmmCoreInitializeMemoryAttributesTable (
1105 This function returns a copy of the current memory map. The map is an array of
1106 memory descriptors, each of which describes a contiguous block of memory.
1108 @param[in, out] MemoryMapSize A pointer to the size, in bytes, of the
1109 MemoryMap buffer. On input, this is the size of
1110 the buffer allocated by the caller. On output,
1111 it is the size of the buffer returned by the
1112 firmware if the buffer was large enough, or the
1113 size of the buffer needed to contain the map if
1114 the buffer was too small.
1115 @param[in, out] MemoryMap A pointer to the buffer in which firmware places
1116 the current memory map.
1117 @param[out] MapKey A pointer to the location in which firmware
1118 returns the key for the current memory map.
1119 @param[out] DescriptorSize A pointer to the location in which firmware
1120 returns the size, in bytes, of an individual
1121 EFI_MEMORY_DESCRIPTOR.
1122 @param[out] DescriptorVersion A pointer to the location in which firmware
1123 returns the version number associated with the
1124 EFI_MEMORY_DESCRIPTOR.
1126 @retval EFI_SUCCESS The memory map was returned in the MemoryMap
1128 @retval EFI_BUFFER_TOO_SMALL The MemoryMap buffer was too small. The current
1129 buffer size needed to hold the memory map is
1130 returned in MemoryMapSize.
1131 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
1136 SmmCoreGetMemoryMap (
1137 IN OUT UINTN
*MemoryMapSize
,
1138 IN OUT EFI_MEMORY_DESCRIPTOR
*MemoryMap
,
1140 OUT UINTN
*DescriptorSize
,
1141 OUT UINT32
*DescriptorVersion
1145 Initialize SmiHandler profile feature.
1148 SmmCoreInitializeSmiHandlerProfile (
1153 This function is called by SmmChildDispatcher module to report
1154 a new SMI handler is registered, to SmmCore.
1156 @param This The protocol instance
1157 @param HandlerGuid The GUID to identify the type of the handler.
1158 For the SmmChildDispatch protocol, the HandlerGuid
1159 must be the GUID of SmmChildDispatch protocol.
1160 @param Handler The SMI handler.
1161 @param CallerAddress The address of the module who registers the SMI handler.
1162 @param Context The context of the SMI handler.
1163 For the SmmChildDispatch protocol, the Context
1164 must match the one defined for SmmChildDispatch protocol.
1165 @param ContextSize The size of the context in bytes.
1166 For the SmmChildDispatch protocol, the Context
1167 must match the one defined for SmmChildDispatch protocol.
1169 @retval EFI_SUCCESS The information is recorded.
1170 @retval EFI_OUT_OF_RESOURCES There is no enough resource to record the information.
1174 SmiHandlerProfileRegisterHandler (
1175 IN SMI_HANDLER_PROFILE_PROTOCOL
*This
,
1176 IN EFI_GUID
*HandlerGuid
,
1177 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler
,
1178 IN PHYSICAL_ADDRESS CallerAddress
,
1179 IN VOID
*Context OPTIONAL
,
1180 IN UINTN ContextSize OPTIONAL
1184 This function is called by SmmChildDispatcher module to report
1185 an existing SMI handler is unregistered, to SmmCore.
1187 @param This The protocol instance
1188 @param HandlerGuid The GUID to identify the type of the handler.
1189 For the SmmChildDispatch protocol, the HandlerGuid
1190 must be the GUID of SmmChildDispatch protocol.
1191 @param Handler The SMI handler.
1192 @param Context The context of the SMI handler.
1193 If it is NOT NULL, it will be used to check what is registered.
1194 @param ContextSize The size of the context in bytes.
1195 If Context is NOT NULL, it will be used to check what is registered.
1197 @retval EFI_SUCCESS The original record is removed.
1198 @retval EFI_NOT_FOUND There is no record for the HandlerGuid and handler.
1202 SmiHandlerProfileUnregisterHandler (
1203 IN SMI_HANDLER_PROFILE_PROTOCOL
*This
,
1204 IN EFI_GUID
*HandlerGuid
,
1205 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler
,
1206 IN VOID
*Context OPTIONAL
,
1207 IN UINTN ContextSize OPTIONAL
1210 extern UINTN mFullSmramRangeCount
;
1211 extern EFI_SMRAM_DESCRIPTOR
*mFullSmramRanges
;
1213 extern EFI_SMM_DRIVER_ENTRY
*mSmmCoreDriverEntry
;
1215 extern EFI_LOADED_IMAGE_PROTOCOL
*mSmmCoreLoadedImage
;
1223 UINTN NumberOfPages
;
1226 extern LIST_ENTRY mSmmMemoryMap
;
1233 // MIN_POOL_SHIFT must not be less than 5
1235 #define MIN_POOL_SHIFT 6
1236 #define MIN_POOL_SIZE (1 << MIN_POOL_SHIFT)
1239 // MAX_POOL_SHIFT must not be less than EFI_PAGE_SHIFT - 1
1241 #define MAX_POOL_SHIFT (EFI_PAGE_SHIFT - 1)
1242 #define MAX_POOL_SIZE (1 << MAX_POOL_SHIFT)
1245 // MAX_POOL_INDEX are calculated by maximum and minimum pool sizes
1247 #define MAX_POOL_INDEX (MAX_POOL_SHIFT - MIN_POOL_SHIFT + 1)
1249 #define POOL_HEAD_SIGNATURE SIGNATURE_32('s','p','h','d')
1254 EFI_MEMORY_TYPE Type
;
1258 #define POOL_TAIL_SIGNATURE SIGNATURE_32('s','p','t','l')
1266 #define POOL_OVERHEAD (sizeof(POOL_HEADER) + sizeof(POOL_TAIL))
1268 #define HEAD_TO_TAIL(a) \
1269 ((POOL_TAIL *) (((CHAR8 *) (a)) + (a)->Size - sizeof(POOL_TAIL)));
1282 extern LIST_ENTRY mSmmPoolLists
[SmmPoolTypeMax
][MAX_POOL_INDEX
];
1285 Internal Function. Allocate n pages from given free page node.
1287 @param Pages The free page node.
1288 @param NumberOfPages Number of pages to be allocated.
1289 @param MaxAddress Request to allocate memory below this address.
1291 @return Memory address of allocated pages.
1295 InternalAllocPagesOnOneNode (
1296 IN OUT FREE_PAGE_LIST
*Pages
,
1297 IN UINTN NumberOfPages
,
1302 Update SMM memory map entry.
1304 @param[in] Type The type of allocation to perform.
1305 @param[in] Memory The base of memory address.
1306 @param[in] NumberOfPages The number of pages to allocate.
1307 @param[in] AddRegion If this memory is new added region.
1310 ConvertSmmMemoryMapEntry (
1311 IN EFI_MEMORY_TYPE Type
,
1312 IN EFI_PHYSICAL_ADDRESS Memory
,
1313 IN UINTN NumberOfPages
,
1314 IN BOOLEAN AddRegion
1318 Internal function. Moves any memory descriptors that are on the
1319 temporary descriptor stack to heap.
1323 CoreFreeMemoryMapStack (
1328 Frees previous allocated pages.
1330 @param[in] Memory Base address of memory being freed.
1331 @param[in] NumberOfPages The number of pages to free.
1332 @param[in] AddRegion If this memory is new added region.
1334 @retval EFI_NOT_FOUND Could not find the entry that covers the range.
1335 @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.
1336 @return EFI_SUCCESS Pages successfully freed.
1340 SmmInternalFreePagesEx (
1341 IN EFI_PHYSICAL_ADDRESS Memory
,
1342 IN UINTN NumberOfPages
,
1343 IN BOOLEAN AddRegion
1347 Hook function used to set all Guard pages after entering SMM mode.
1350 SmmEntryPointMemoryManagementHook (