2 The internal header file includes the common header files, defines
3 internal structure and functions used by SmmCore module.
5 Copyright (c) 2009 - 2018, 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>
35 #include <Protocol/SmmMemoryAttribute.h>
36 #include <Protocol/SmmSxDispatch2.h>
38 #include <Guid/Apriori.h>
39 #include <Guid/EventGroup.h>
40 #include <Guid/EventLegacyBios.h>
41 #include <Guid/MemoryProfile.h>
42 #include <Guid/LoadModuleAtFixedAddress.h>
43 #include <Guid/SmiHandlerProfile.h>
44 #include <Guid/EndOfS3Resume.h>
45 #include <Guid/S3SmmInitDone.h>
47 #include <Library/BaseLib.h>
48 #include <Library/BaseMemoryLib.h>
49 #include <Library/PeCoffLib.h>
50 #include <Library/PeCoffGetEntryPointLib.h>
51 #include <Library/CacheMaintenanceLib.h>
52 #include <Library/DebugLib.h>
53 #include <Library/ReportStatusCodeLib.h>
54 #include <Library/MemoryAllocationLib.h>
55 #include <Library/DevicePathLib.h>
56 #include <Library/UefiLib.h>
57 #include <Library/UefiBootServicesTableLib.h>
58 #include <Library/PcdLib.h>
59 #include <Library/SmmCorePlatformHookLib.h>
60 #include <Library/PerformanceLib.h>
61 #include <Library/HobLib.h>
62 #include <Library/SmmMemLib.h>
64 #include "PiSmmCorePrivateData.h"
65 #include "HeapGuard.h"
68 // Used to build a table of SMI Handlers that the SMM Core registers
71 EFI_SMM_HANDLER_ENTRY_POINT2 Handler
;
72 EFI_GUID
*HandlerType
;
73 EFI_HANDLE DispatchHandle
;
75 } SMM_CORE_SMI_HANDLERS
;
78 // SMM_HANDLER - used for each SMM handler
81 #define SMI_ENTRY_SIGNATURE SIGNATURE_32('s','m','i','e')
85 LIST_ENTRY AllEntries
; // All entries
87 EFI_GUID HandlerType
; // Type of interrupt
88 LIST_ENTRY SmiHandlers
; // All handlers
91 #define SMI_HANDLER_SIGNATURE SIGNATURE_32('s','m','i','h')
95 LIST_ENTRY Link
; // Link on SMI_ENTRY.SmiHandlers
96 EFI_SMM_HANDLER_ENTRY_POINT2 Handler
; // The smm handler's entry point
97 UINTN CallerAddr
; // The address of caller who register the SMI handler.
99 VOID
*Context
; // for profile
100 UINTN ContextSize
; // for profile
104 // Structure for recording the state of an SMM Driver
106 #define EFI_SMM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v')
110 LIST_ENTRY Link
; // mDriverList
112 LIST_ENTRY ScheduledLink
; // mScheduledQueue
116 EFI_DEVICE_PATH_PROTOCOL
*FvFileDevicePath
;
117 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
124 EFI_GUID BeforeAfterGuid
;
129 BOOLEAN DepexProtocolError
;
131 EFI_HANDLE ImageHandle
;
132 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
134 // Image EntryPoint in SMRAM
136 PHYSICAL_ADDRESS ImageEntryPoint
;
138 // Image Buffer in SMRAM
140 PHYSICAL_ADDRESS ImageBuffer
;
145 EFI_HANDLE SmmImageHandle
;
146 EFI_LOADED_IMAGE_PROTOCOL SmmLoadedImage
;
147 } EFI_SMM_DRIVER_ENTRY
;
149 #define EFI_HANDLE_SIGNATURE SIGNATURE_32('h','n','d','l')
152 /// IHANDLE - contains a list of protocol handles
156 /// All handles list of IHANDLE
157 LIST_ENTRY AllHandles
;
158 /// List of PROTOCOL_INTERFACE's for this handle
159 LIST_ENTRY Protocols
;
163 #define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature == EFI_HANDLE_SIGNATURE)
165 #define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('p','r','t','e')
168 /// PROTOCOL_ENTRY - each different protocol has 1 entry in the protocol
169 /// database. Each handler that supports this protocol is listed, along
170 /// with a list of registered notifies.
174 /// Link Entry inserted to mProtocolDatabase
175 LIST_ENTRY AllEntries
;
176 /// ID of the protocol
178 /// All protocol interfaces
179 LIST_ENTRY Protocols
;
180 /// Registerd notification handlers
184 #define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('p','i','f','c')
187 /// PROTOCOL_INTERFACE - each protocol installed on a handle is tracked
188 /// with a protocol interface structure
192 /// Link on IHANDLE.Protocols
196 /// Link on PROTOCOL_ENTRY.Protocols
197 LIST_ENTRY ByProtocol
;
199 PROTOCOL_ENTRY
*Protocol
;
200 /// The interface value
202 } PROTOCOL_INTERFACE
;
204 #define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('p','r','t','n')
207 /// PROTOCOL_NOTIFY - used for each register notification for a protocol
211 PROTOCOL_ENTRY
*Protocol
;
212 /// All notifications for this protocol
214 /// Notification function
215 EFI_SMM_NOTIFY_FN Function
;
216 /// Last position notified
217 LIST_ENTRY
*Position
;
221 // SMM Core Global Variables
223 extern SMM_CORE_PRIVATE_DATA
*gSmmCorePrivate
;
224 extern EFI_SMM_SYSTEM_TABLE2 gSmmCoreSmst
;
225 extern LIST_ENTRY gHandleList
;
226 extern EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddressSmramBase
;
229 Called to initialize the memory service.
231 @param SmramRangeCount Number of SMRAM Regions
232 @param SmramRanges Pointer to SMRAM Descriptors
236 SmmInitializeMemoryServices (
237 IN UINTN SmramRangeCount
,
238 IN EFI_SMRAM_DESCRIPTOR
*SmramRanges
242 The SmmInstallConfigurationTable() function is used to maintain the list
243 of configuration tables that are stored in the System Management System
244 Table. The list is stored as an array of (GUID, Pointer) pairs. The list
245 must be allocated from pool memory with PoolType set to EfiRuntimeServicesData.
247 @param SystemTable A pointer to the SMM System Table (SMST).
248 @param Guid A pointer to the GUID for the entry to add, update, or remove.
249 @param Table A pointer to the buffer of the table to add.
250 @param TableSize The size of the table to install.
252 @retval EFI_SUCCESS The (Guid, Table) pair was added, updated, or removed.
253 @retval EFI_INVALID_PARAMETER Guid is not valid.
254 @retval EFI_NOT_FOUND An attempt was made to delete a non-existent entry.
255 @retval EFI_OUT_OF_RESOURCES There is not enough memory available to complete the operation.
260 SmmInstallConfigurationTable (
261 IN CONST EFI_SMM_SYSTEM_TABLE2
*SystemTable
,
262 IN CONST EFI_GUID
*Guid
,
268 Wrapper function to SmmInstallProtocolInterfaceNotify. This is the public API which
269 Calls the private one which contains a BOOLEAN parameter for notifications
271 @param UserHandle The handle to install the protocol handler on,
272 or NULL if a new handle is to be allocated
273 @param Protocol The protocol to add to the handle
274 @param InterfaceType Indicates whether Interface is supplied in
276 @param Interface The interface for the protocol being added
283 SmmInstallProtocolInterface (
284 IN OUT EFI_HANDLE
*UserHandle
,
285 IN EFI_GUID
*Protocol
,
286 IN EFI_INTERFACE_TYPE InterfaceType
,
291 Allocates pages from the memory map.
293 @param Type The type of allocation to perform
294 @param MemoryType The type of memory to turn the allocated pages
296 @param NumberOfPages The number of pages to allocate
297 @param Memory A pointer to receive the base allocated memory
300 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.
301 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
302 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
303 @retval EFI_SUCCESS Pages successfully allocated.
309 IN EFI_ALLOCATE_TYPE Type
,
310 IN EFI_MEMORY_TYPE MemoryType
,
311 IN UINTN NumberOfPages
,
312 OUT EFI_PHYSICAL_ADDRESS
*Memory
316 Allocates pages from the memory map.
318 @param Type The type of allocation to perform
319 @param MemoryType The type of memory to turn the allocated pages
321 @param NumberOfPages The number of pages to allocate
322 @param Memory A pointer to receive the base allocated memory
324 @param NeedGuard Flag to indicate Guard page is needed or not
326 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.
327 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
328 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
329 @retval EFI_SUCCESS Pages successfully allocated.
334 SmmInternalAllocatePages (
335 IN EFI_ALLOCATE_TYPE Type
,
336 IN EFI_MEMORY_TYPE MemoryType
,
337 IN UINTN NumberOfPages
,
338 OUT EFI_PHYSICAL_ADDRESS
*Memory
,
343 Frees previous allocated pages.
345 @param Memory Base address of memory being freed
346 @param NumberOfPages The number of pages to free
348 @retval EFI_NOT_FOUND Could not find the entry that covers the range
349 @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.
350 @return EFI_SUCCESS Pages successfully freed.
356 IN EFI_PHYSICAL_ADDRESS Memory
,
357 IN UINTN NumberOfPages
361 Frees previous allocated pages.
363 @param Memory Base address of memory being freed
364 @param NumberOfPages The number of pages to free
365 @param IsGuarded Flag to indicate if the memory is guarded
368 @retval EFI_NOT_FOUND Could not find the entry that covers the range
369 @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.
370 @return EFI_SUCCESS Pages successfully freed.
375 SmmInternalFreePages (
376 IN EFI_PHYSICAL_ADDRESS Memory
,
377 IN UINTN NumberOfPages
,
382 Allocate pool of a particular type.
384 @param PoolType Type of pool to allocate
385 @param Size The amount of pool to allocate
386 @param Buffer The address to return a pointer to the allocated
389 @retval EFI_INVALID_PARAMETER PoolType not valid
390 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
391 @retval EFI_SUCCESS Pool successfully allocated.
397 IN EFI_MEMORY_TYPE PoolType
,
403 Allocate pool of a particular type.
405 @param PoolType Type of pool to allocate
406 @param Size The amount of pool to allocate
407 @param Buffer The address to return a pointer to the allocated
410 @retval EFI_INVALID_PARAMETER PoolType not valid
411 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
412 @retval EFI_SUCCESS Pool successfully allocated.
417 SmmInternalAllocatePool (
418 IN EFI_MEMORY_TYPE PoolType
,
426 @param Buffer The allocated pool entry to free
428 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.
429 @retval EFI_SUCCESS Pool successfully freed.
441 @param Buffer The allocated pool entry to free
443 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.
444 @retval EFI_SUCCESS Pool successfully freed.
449 SmmInternalFreePool (
454 Installs a protocol interface into the boot services environment.
456 @param UserHandle The handle to install the protocol handler on,
457 or NULL if a new handle is to be allocated
458 @param Protocol The protocol to add to the handle
459 @param InterfaceType Indicates whether Interface is supplied in
461 @param Interface The interface for the protocol being added
462 @param Notify indicates whether notify the notification list
465 @retval EFI_INVALID_PARAMETER Invalid parameter
466 @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate
467 @retval EFI_SUCCESS Protocol interface successfully installed
471 SmmInstallProtocolInterfaceNotify (
472 IN OUT EFI_HANDLE
*UserHandle
,
473 IN EFI_GUID
*Protocol
,
474 IN EFI_INTERFACE_TYPE InterfaceType
,
480 Uninstalls all instances of a protocol:interfacer from a handle.
481 If the last protocol interface is remove from the handle, the
484 @param UserHandle The handle to remove the protocol handler from
485 @param Protocol The protocol, of protocol:interface, to remove
486 @param Interface The interface, of protocol:interface, to remove
488 @retval EFI_INVALID_PARAMETER Protocol is NULL.
489 @retval EFI_SUCCESS Protocol interface successfully uninstalled.
494 SmmUninstallProtocolInterface (
495 IN EFI_HANDLE UserHandle
,
496 IN EFI_GUID
*Protocol
,
501 Queries a handle to determine if it supports a specified protocol.
503 @param UserHandle The handle being queried.
504 @param Protocol The published unique identifier of the protocol.
505 @param Interface Supplies the address where a pointer to the
506 corresponding Protocol Interface is returned.
508 @return The requested protocol interface for the handle
514 IN EFI_HANDLE UserHandle
,
515 IN EFI_GUID
*Protocol
,
520 Add a new protocol notification record for the request protocol.
522 @param Protocol The requested protocol to add the notify
524 @param Function Points to the notification function
525 @param Registration Returns the registration record
527 @retval EFI_INVALID_PARAMETER Invalid parameter
528 @retval EFI_SUCCESS Successfully returned the registration record
534 SmmRegisterProtocolNotify (
535 IN CONST EFI_GUID
*Protocol
,
536 IN EFI_SMM_NOTIFY_FN Function
,
537 OUT VOID
**Registration
541 Locates the requested handle(s) and returns them in Buffer.
543 @param SearchType The type of search to perform to locate the
545 @param Protocol The protocol to search for
546 @param SearchKey Dependant on SearchType
547 @param BufferSize On input the size of Buffer. On output the
548 size of data returned.
549 @param Buffer The buffer to return the results in
551 @retval EFI_BUFFER_TOO_SMALL Buffer too small, required buffer size is
552 returned in BufferSize.
553 @retval EFI_INVALID_PARAMETER Invalid parameter
554 @retval EFI_SUCCESS Successfully found the requested handle(s) and
555 returns them in Buffer.
561 IN EFI_LOCATE_SEARCH_TYPE SearchType
,
562 IN EFI_GUID
*Protocol OPTIONAL
,
563 IN VOID
*SearchKey OPTIONAL
,
564 IN OUT UINTN
*BufferSize
,
565 OUT EFI_HANDLE
*Buffer
569 Return the first Protocol Interface that matches the Protocol GUID. If
570 Registration is pasased in return a Protocol Instance that was just add
571 to the system. If Retistration is NULL return the first Protocol Interface
574 @param Protocol The protocol to search for
575 @param Registration Optional Registration Key returned from
576 RegisterProtocolNotify()
577 @param Interface Return the Protocol interface (instance).
579 @retval EFI_SUCCESS If a valid Interface is returned
580 @retval EFI_INVALID_PARAMETER Invalid parameter
581 @retval EFI_NOT_FOUND Protocol interface not found
587 IN EFI_GUID
*Protocol
,
588 IN VOID
*Registration OPTIONAL
,
593 Function returns an array of handles that support the requested protocol
594 in a buffer allocated from pool. This is a version of SmmLocateHandle()
595 that allocates a buffer for the caller.
597 @param SearchType Specifies which handle(s) are to be returned.
598 @param Protocol Provides the protocol to search by. This
599 parameter is only valid for SearchType
601 @param SearchKey Supplies the search key depending on the
603 @param NumberHandles The number of handles returned in Buffer.
604 @param Buffer A pointer to the buffer to return the requested
605 array of handles that support Protocol.
607 @retval EFI_SUCCESS The result array of handles was returned.
608 @retval EFI_NOT_FOUND No handles match the search.
609 @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the
611 @retval EFI_INVALID_PARAMETER One or more paramters are not valid.
616 SmmLocateHandleBuffer (
617 IN EFI_LOCATE_SEARCH_TYPE SearchType
,
618 IN EFI_GUID
*Protocol OPTIONAL
,
619 IN VOID
*SearchKey OPTIONAL
,
620 IN OUT UINTN
*NumberHandles
,
621 OUT EFI_HANDLE
**Buffer
625 Manage SMI of a particular type.
627 @param HandlerType Points to the handler type or NULL for root SMI handlers.
628 @param Context Points to an optional context buffer.
629 @param CommBuffer Points to the optional communication buffer.
630 @param CommBufferSize Points to the size of the optional communication buffer.
632 @retval EFI_SUCCESS Interrupt source was processed successfully but not quiesced.
633 @retval EFI_INTERRUPT_PENDING One or more SMI sources could not be quiesced.
634 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING Interrupt source was not handled or quiesced.
635 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED Interrupt source was handled and quiesced.
641 IN CONST EFI_GUID
*HandlerType
,
642 IN CONST VOID
*Context OPTIONAL
,
643 IN OUT VOID
*CommBuffer OPTIONAL
,
644 IN OUT UINTN
*CommBufferSize OPTIONAL
648 Registers a handler to execute within SMM.
650 @param Handler Handler service funtion pointer.
651 @param HandlerType Points to the handler type or NULL for root SMI handlers.
652 @param DispatchHandle On return, contains a unique handle which can be used to later unregister the handler function.
654 @retval EFI_SUCCESS Handler register success.
655 @retval EFI_INVALID_PARAMETER Handler or DispatchHandle is NULL.
661 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler
,
662 IN CONST EFI_GUID
*HandlerType OPTIONAL
,
663 OUT EFI_HANDLE
*DispatchHandle
667 Unregister a handler in SMM.
669 @param DispatchHandle The handle that was specified when the handler was registered.
671 @retval EFI_SUCCESS Handler function was successfully unregistered.
672 @retval EFI_INVALID_PARAMETER DispatchHandle does not refer to a valid handle.
677 SmiHandlerUnRegister (
678 IN EFI_HANDLE DispatchHandle
682 This function is the main entry point for an SMM handler dispatch
683 or communicate-based callback.
685 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
686 @param Context Points to an optional handler context which was specified when the handler was registered.
687 @param CommBuffer A pointer to a collection of data in memory that will
688 be conveyed from a non-SMM environment into an SMM environment.
689 @param CommBufferSize The size of the CommBuffer.
696 SmmDriverDispatchHandler (
697 IN EFI_HANDLE DispatchHandle
,
698 IN CONST VOID
*Context
, OPTIONAL
699 IN OUT VOID
*CommBuffer
, OPTIONAL
700 IN OUT UINTN
*CommBufferSize OPTIONAL
704 This function is the main entry point for an SMM handler dispatch
705 or communicate-based callback.
707 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
708 @param Context Points to an optional handler context which was specified when the handler was registered.
709 @param CommBuffer A pointer to a collection of data in memory that will
710 be conveyed from a non-SMM environment into an SMM environment.
711 @param CommBufferSize The size of the CommBuffer.
718 SmmLegacyBootHandler (
719 IN EFI_HANDLE DispatchHandle
,
720 IN CONST VOID
*Context
, OPTIONAL
721 IN OUT VOID
*CommBuffer
, OPTIONAL
722 IN OUT UINTN
*CommBufferSize OPTIONAL
726 This function is the main entry point for an SMM handler dispatch
727 or communicate-based callback.
729 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
730 @param Context Points to an optional handler context which was specified when the handler was registered.
731 @param CommBuffer A pointer to a collection of data in memory that will
732 be conveyed from a non-SMM environment into an SMM environment.
733 @param CommBufferSize The size of the CommBuffer.
740 SmmReadyToLockHandler (
741 IN EFI_HANDLE DispatchHandle
,
742 IN CONST VOID
*Context
, OPTIONAL
743 IN OUT VOID
*CommBuffer
, OPTIONAL
744 IN OUT UINTN
*CommBufferSize OPTIONAL
748 This function is the main entry point for an SMM handler dispatch
749 or communicate-based callback.
751 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
752 @param Context Points to an optional handler context which was specified when the handler was registered.
753 @param CommBuffer A pointer to a collection of data in memory that will
754 be conveyed from a non-SMM environment into an SMM environment.
755 @param CommBufferSize The size of the CommBuffer.
763 IN EFI_HANDLE DispatchHandle
,
764 IN CONST VOID
*Context
, OPTIONAL
765 IN OUT VOID
*CommBuffer
, OPTIONAL
766 IN OUT UINTN
*CommBufferSize OPTIONAL
770 This function is the main entry point for an SMM handler dispatch
771 or communicate-based callback.
773 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
774 @param Context Points to an optional handler context which was specified when the handler was registered.
775 @param CommBuffer A pointer to a collection of data in memory that will
776 be conveyed from a non-SMM environment into an SMM environment.
777 @param CommBufferSize The size of the CommBuffer.
784 SmmExitBootServicesHandler (
785 IN EFI_HANDLE DispatchHandle
,
786 IN CONST VOID
*Context
, OPTIONAL
787 IN OUT VOID
*CommBuffer
, OPTIONAL
788 IN OUT UINTN
*CommBufferSize OPTIONAL
792 This function is the main entry point for an SMM handler dispatch
793 or communicate-based callback.
795 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
796 @param Context Points to an optional handler context which was specified when the handler was registered.
797 @param CommBuffer A pointer to a collection of data in memory that will
798 be conveyed from a non-SMM environment into an SMM environment.
799 @param CommBufferSize The size of the CommBuffer.
806 SmmReadyToBootHandler (
807 IN EFI_HANDLE DispatchHandle
,
808 IN CONST VOID
*Context
, OPTIONAL
809 IN OUT VOID
*CommBuffer
, OPTIONAL
810 IN OUT UINTN
*CommBufferSize OPTIONAL
814 Software SMI handler that is called when the S3SmmInitDone signal is triggered.
815 This function installs the SMM S3SmmInitDone Protocol so SMM Drivers are informed that
816 S3 SMM initialization has been done.
818 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
819 @param Context Points to an optional handler context which was specified when the handler was registered.
820 @param CommBuffer A pointer to a collection of data in memory that will
821 be conveyed from a non-SMM environment into an SMM environment.
822 @param CommBufferSize The size of the CommBuffer.
829 SmmS3SmmInitDoneHandler (
830 IN EFI_HANDLE DispatchHandle
,
831 IN CONST VOID
*Context
, OPTIONAL
832 IN OUT VOID
*CommBuffer
, OPTIONAL
833 IN OUT UINTN
*CommBufferSize OPTIONAL
837 Software SMI handler that is called when the EndOfS3Resume event is trigged.
838 This function installs the SMM EndOfS3Resume Protocol so SMM Drivers are informed that
839 S3 resume has finished.
841 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
842 @param Context Points to an optional handler context which was specified when the handler was registered.
843 @param CommBuffer A pointer to a collection of data in memory that will
844 be conveyed from a non-SMM environment into an SMM environment.
845 @param CommBufferSize The size of the CommBuffer.
852 SmmEndOfS3ResumeHandler (
853 IN EFI_HANDLE DispatchHandle
,
854 IN CONST VOID
*Context
, OPTIONAL
855 IN OUT VOID
*CommBuffer
, OPTIONAL
856 IN OUT UINTN
*CommBufferSize OPTIONAL
860 Place holder function until all the SMM System Table Service are available.
862 @param Arg1 Undefined
863 @param Arg2 Undefined
864 @param Arg3 Undefined
865 @param Arg4 Undefined
866 @param Arg5 Undefined
868 @return EFI_NOT_AVAILABLE_YET
873 SmmEfiNotAvailableYetArg5 (
882 //Functions used during debug buils
886 Traverse the discovered list for any drivers that were discovered but not loaded
887 because the dependency experessions evaluated to false.
891 SmmDisplayDiscoveredNotDispatched (
896 Add free SMRAM region for use by memory service.
898 @param MemBase Base address of memory region.
899 @param MemLength Length of the memory region.
900 @param Type Memory type.
901 @param Attributes Memory region state.
906 IN EFI_PHYSICAL_ADDRESS MemBase
,
908 IN EFI_MEMORY_TYPE Type
,
913 Finds the protocol entry for the requested protocol.
915 @param Protocol The ID of the protocol
916 @param Create Create a new entry if not found
918 @return Protocol entry
922 SmmFindProtocolEntry (
923 IN EFI_GUID
*Protocol
,
928 Signal event for every protocol in protocol entry.
930 @param Prot Protocol interface
935 IN PROTOCOL_INTERFACE
*Prot
939 Finds the protocol instance for the requested handle and protocol.
940 Note: This function doesn't do parameters checking, it's caller's responsibility
941 to pass in valid parameters.
943 @param Handle The handle to search the protocol on
944 @param Protocol GUID of the protocol
945 @param Interface The interface for the protocol being searched
947 @return Protocol instance (NULL: Not found)
951 SmmFindProtocolInterface (
953 IN EFI_GUID
*Protocol
,
958 Removes Protocol from the protocol list (but not the handle list).
960 @param Handle The handle to remove protocol on.
961 @param Protocol GUID of the protocol to be moved
962 @param Interface The interface of the protocol
964 @return Protocol Entry
968 SmmRemoveInterfaceFromProtocol (
970 IN EFI_GUID
*Protocol
,
975 This is the POSTFIX version of the dependency evaluator. This code does
976 not need to handle Before or After, as it is not valid to call this
977 routine in this case. POSTFIX means all the math is done on top of the stack.
979 @param DriverEntry DriverEntry element to update.
981 @retval TRUE If driver is ready to run.
982 @retval FALSE If driver is not ready to run or some fatal error
988 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
996 Initialize SMRAM profile.
1005 Install SMRAM profile protocol.
1009 SmramProfileInstallProtocol (
1014 Register SMM image to SMRAM profile.
1016 @param DriverEntry SMM image info.
1017 @param RegisterToDxe Register image to DXE.
1019 @return EFI_SUCCESS Register successfully.
1020 @return EFI_UNSUPPORTED Memory profile unsupported,
1021 or memory profile for the image is not required.
1022 @return EFI_OUT_OF_RESOURCES No enough resource for this register.
1026 RegisterSmramProfileImage (
1027 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
,
1028 IN BOOLEAN RegisterToDxe
1032 Unregister image from SMRAM profile.
1034 @param DriverEntry SMM image info.
1035 @param UnregisterToDxe Unregister image from DXE.
1037 @return EFI_SUCCESS Unregister successfully.
1038 @return EFI_UNSUPPORTED Memory profile unsupported,
1039 or memory profile for the image is not required.
1040 @return EFI_NOT_FOUND The image is not found.
1044 UnregisterSmramProfileImage (
1045 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
,
1046 IN BOOLEAN UnregisterToDxe
1050 Update SMRAM profile information.
1052 @param CallerAddress Address of caller who call Allocate or Free.
1053 @param Action This Allocate or Free action.
1054 @param MemoryType Memory type.
1055 EfiMaxMemoryType means the MemoryType is unknown.
1056 @param Size Buffer size.
1057 @param Buffer Buffer address.
1058 @param ActionString String for memory profile action.
1059 Only needed for user defined allocate action.
1061 @return EFI_SUCCESS Memory profile is updated.
1062 @return EFI_UNSUPPORTED Memory profile is unsupported,
1063 or memory profile for the image is not required,
1064 or memory profile for the memory type is not required.
1065 @return EFI_ACCESS_DENIED It is during memory profile data getting.
1066 @return EFI_ABORTED Memory profile recording is not enabled.
1067 @return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.
1068 @return EFI_NOT_FOUND No matched allocate info found for free action.
1073 SmmCoreUpdateProfile (
1074 IN PHYSICAL_ADDRESS CallerAddress
,
1075 IN MEMORY_PROFILE_ACTION Action
,
1076 IN EFI_MEMORY_TYPE MemoryType
, // Valid for AllocatePages/AllocatePool
1077 IN UINTN Size
, // Valid for AllocatePages/FreePages/AllocatePool
1079 IN CHAR8
*ActionString OPTIONAL
1083 Register SMRAM profile handler.
1087 RegisterSmramProfileHandler (
1092 SMRAM profile ready to lock callback function.
1096 SmramProfileReadyToLock (
1101 Initialize MemoryAttributes support.
1105 SmmCoreInitializeMemoryAttributesTable (
1110 This function returns a copy of the current memory map. The map is an array of
1111 memory descriptors, each of which describes a contiguous block of memory.
1113 @param[in, out] MemoryMapSize A pointer to the size, in bytes, of the
1114 MemoryMap buffer. On input, this is the size of
1115 the buffer allocated by the caller. On output,
1116 it is the size of the buffer returned by the
1117 firmware if the buffer was large enough, or the
1118 size of the buffer needed to contain the map if
1119 the buffer was too small.
1120 @param[in, out] MemoryMap A pointer to the buffer in which firmware places
1121 the current memory map.
1122 @param[out] MapKey A pointer to the location in which firmware
1123 returns the key for the current memory map.
1124 @param[out] DescriptorSize A pointer to the location in which firmware
1125 returns the size, in bytes, of an individual
1126 EFI_MEMORY_DESCRIPTOR.
1127 @param[out] DescriptorVersion A pointer to the location in which firmware
1128 returns the version number associated with the
1129 EFI_MEMORY_DESCRIPTOR.
1131 @retval EFI_SUCCESS The memory map was returned in the MemoryMap
1133 @retval EFI_BUFFER_TOO_SMALL The MemoryMap buffer was too small. The current
1134 buffer size needed to hold the memory map is
1135 returned in MemoryMapSize.
1136 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
1141 SmmCoreGetMemoryMap (
1142 IN OUT UINTN
*MemoryMapSize
,
1143 IN OUT EFI_MEMORY_DESCRIPTOR
*MemoryMap
,
1145 OUT UINTN
*DescriptorSize
,
1146 OUT UINT32
*DescriptorVersion
1150 Initialize SmiHandler profile feature.
1153 SmmCoreInitializeSmiHandlerProfile (
1158 This function is called by SmmChildDispatcher module to report
1159 a new SMI handler is registered, to SmmCore.
1161 @param This The protocol instance
1162 @param HandlerGuid The GUID to identify the type of the handler.
1163 For the SmmChildDispatch protocol, the HandlerGuid
1164 must be the GUID of SmmChildDispatch protocol.
1165 @param Handler The SMI handler.
1166 @param CallerAddress The address of the module who registers the SMI handler.
1167 @param Context The context of the SMI handler.
1168 For the SmmChildDispatch protocol, the Context
1169 must match the one defined for SmmChildDispatch protocol.
1170 @param ContextSize The size of the context in bytes.
1171 For the SmmChildDispatch protocol, the Context
1172 must match the one defined for SmmChildDispatch protocol.
1174 @retval EFI_SUCCESS The information is recorded.
1175 @retval EFI_OUT_OF_RESOURCES There is no enough resource to record the information.
1179 SmiHandlerProfileRegisterHandler (
1180 IN SMI_HANDLER_PROFILE_PROTOCOL
*This
,
1181 IN EFI_GUID
*HandlerGuid
,
1182 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler
,
1183 IN PHYSICAL_ADDRESS CallerAddress
,
1184 IN VOID
*Context
, OPTIONAL
1185 IN UINTN ContextSize OPTIONAL
1189 This function is called by SmmChildDispatcher module to report
1190 an existing SMI handler is unregistered, to SmmCore.
1192 @param This The protocol instance
1193 @param HandlerGuid The GUID to identify the type of the handler.
1194 For the SmmChildDispatch protocol, the HandlerGuid
1195 must be the GUID of SmmChildDispatch protocol.
1196 @param Handler The SMI handler.
1197 @param Context The context of the SMI handler.
1198 If it is NOT NULL, it will be used to check what is registered.
1199 @param ContextSize The size of the context in bytes.
1200 If Context is NOT NULL, it will be used to check what is registered.
1202 @retval EFI_SUCCESS The original record is removed.
1203 @retval EFI_NOT_FOUND There is no record for the HandlerGuid and handler.
1207 SmiHandlerProfileUnregisterHandler (
1208 IN SMI_HANDLER_PROFILE_PROTOCOL
*This
,
1209 IN EFI_GUID
*HandlerGuid
,
1210 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler
,
1211 IN VOID
*Context
, OPTIONAL
1212 IN UINTN ContextSize OPTIONAL
1215 extern UINTN mFullSmramRangeCount
;
1216 extern EFI_SMRAM_DESCRIPTOR
*mFullSmramRanges
;
1218 extern EFI_SMM_DRIVER_ENTRY
*mSmmCoreDriverEntry
;
1220 extern EFI_LOADED_IMAGE_PROTOCOL
*mSmmCoreLoadedImage
;
1228 UINTN NumberOfPages
;
1231 extern LIST_ENTRY mSmmMemoryMap
;
1238 // MIN_POOL_SHIFT must not be less than 5
1240 #define MIN_POOL_SHIFT 6
1241 #define MIN_POOL_SIZE (1 << MIN_POOL_SHIFT)
1244 // MAX_POOL_SHIFT must not be less than EFI_PAGE_SHIFT - 1
1246 #define MAX_POOL_SHIFT (EFI_PAGE_SHIFT - 1)
1247 #define MAX_POOL_SIZE (1 << MAX_POOL_SHIFT)
1250 // MAX_POOL_INDEX are calculated by maximum and minimum pool sizes
1252 #define MAX_POOL_INDEX (MAX_POOL_SHIFT - MIN_POOL_SHIFT + 1)
1254 #define POOL_HEAD_SIGNATURE SIGNATURE_32('p','h','d','0')
1259 EFI_MEMORY_TYPE Type
;
1263 #define POOL_TAIL_SIGNATURE SIGNATURE_32('p','t','a','l')
1271 #define POOL_OVERHEAD (sizeof(POOL_HEADER) + sizeof(POOL_TAIL))
1273 #define HEAD_TO_TAIL(a) \
1274 ((POOL_TAIL *) (((CHAR8 *) (a)) + (a)->Size - sizeof(POOL_TAIL)));
1287 extern LIST_ENTRY mSmmPoolLists
[SmmPoolTypeMax
][MAX_POOL_INDEX
];
1290 Internal Function. Allocate n pages from given free page node.
1292 @param Pages The free page node.
1293 @param NumberOfPages Number of pages to be allocated.
1294 @param MaxAddress Request to allocate memory below this address.
1296 @return Memory address of allocated pages.
1300 InternalAllocPagesOnOneNode (
1301 IN OUT FREE_PAGE_LIST
*Pages
,
1302 IN UINTN NumberOfPages
,
1307 Update SMM memory map entry.
1309 @param[in] Type The type of allocation to perform.
1310 @param[in] Memory The base of memory address.
1311 @param[in] NumberOfPages The number of pages to allocate.
1312 @param[in] AddRegion If this memory is new added region.
1315 ConvertSmmMemoryMapEntry (
1316 IN EFI_MEMORY_TYPE Type
,
1317 IN EFI_PHYSICAL_ADDRESS Memory
,
1318 IN UINTN NumberOfPages
,
1319 IN BOOLEAN AddRegion
1323 Internal function. Moves any memory descriptors that are on the
1324 temporary descriptor stack to heap.
1328 CoreFreeMemoryMapStack (
1333 Frees previous allocated pages.
1335 @param[in] Memory Base address of memory being freed.
1336 @param[in] NumberOfPages The number of pages to free.
1337 @param[in] AddRegion If this memory is new added region.
1339 @retval EFI_NOT_FOUND Could not find the entry that covers the range.
1340 @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.
1341 @return EFI_SUCCESS Pages successfully freed.
1345 SmmInternalFreePagesEx (
1346 IN EFI_PHYSICAL_ADDRESS Memory
,
1347 IN UINTN NumberOfPages
,
1348 IN BOOLEAN AddRegion
1352 Hook function used to set all Guard pages after entering SMM mode.
1355 SmmEntryPointMemoryManagementHook (