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/TimerLib.h>
62 #include <Library/HobLib.h>
63 #include <Library/SmmMemLib.h>
65 #include "PiSmmCorePrivateData.h"
66 #include "HeapGuard.h"
69 // Used to build a table of SMI Handlers that the SMM Core registers
72 EFI_SMM_HANDLER_ENTRY_POINT2 Handler
;
73 EFI_GUID
*HandlerType
;
74 EFI_HANDLE DispatchHandle
;
76 } SMM_CORE_SMI_HANDLERS
;
79 // SMM_HANDLER - used for each SMM handler
82 #define SMI_ENTRY_SIGNATURE SIGNATURE_32('s','m','i','e')
86 LIST_ENTRY AllEntries
; // All entries
88 EFI_GUID HandlerType
; // Type of interrupt
89 LIST_ENTRY SmiHandlers
; // All handlers
92 #define SMI_HANDLER_SIGNATURE SIGNATURE_32('s','m','i','h')
96 LIST_ENTRY Link
; // Link on SMI_ENTRY.SmiHandlers
97 EFI_SMM_HANDLER_ENTRY_POINT2 Handler
; // The smm handler's entry point
98 UINTN CallerAddr
; // The address of caller who register the SMI handler.
100 VOID
*Context
; // for profile
101 UINTN ContextSize
; // for profile
105 // Structure for recording the state of an SMM Driver
107 #define EFI_SMM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v')
111 LIST_ENTRY Link
; // mDriverList
113 LIST_ENTRY ScheduledLink
; // mScheduledQueue
117 EFI_DEVICE_PATH_PROTOCOL
*FvFileDevicePath
;
118 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
125 EFI_GUID BeforeAfterGuid
;
130 BOOLEAN DepexProtocolError
;
132 EFI_HANDLE ImageHandle
;
133 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
135 // Image EntryPoint in SMRAM
137 PHYSICAL_ADDRESS ImageEntryPoint
;
139 // Image Buffer in SMRAM
141 PHYSICAL_ADDRESS ImageBuffer
;
146 EFI_HANDLE SmmImageHandle
;
147 EFI_LOADED_IMAGE_PROTOCOL SmmLoadedImage
;
148 } EFI_SMM_DRIVER_ENTRY
;
150 #define EFI_HANDLE_SIGNATURE SIGNATURE_32('h','n','d','l')
153 /// IHANDLE - contains a list of protocol handles
157 /// All handles list of IHANDLE
158 LIST_ENTRY AllHandles
;
159 /// List of PROTOCOL_INTERFACE's for this handle
160 LIST_ENTRY Protocols
;
164 #define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature == EFI_HANDLE_SIGNATURE)
166 #define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('p','r','t','e')
169 /// PROTOCOL_ENTRY - each different protocol has 1 entry in the protocol
170 /// database. Each handler that supports this protocol is listed, along
171 /// with a list of registered notifies.
175 /// Link Entry inserted to mProtocolDatabase
176 LIST_ENTRY AllEntries
;
177 /// ID of the protocol
179 /// All protocol interfaces
180 LIST_ENTRY Protocols
;
181 /// Registerd notification handlers
185 #define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('p','i','f','c')
188 /// PROTOCOL_INTERFACE - each protocol installed on a handle is tracked
189 /// with a protocol interface structure
193 /// Link on IHANDLE.Protocols
197 /// Link on PROTOCOL_ENTRY.Protocols
198 LIST_ENTRY ByProtocol
;
200 PROTOCOL_ENTRY
*Protocol
;
201 /// The interface value
203 } PROTOCOL_INTERFACE
;
205 #define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('p','r','t','n')
208 /// PROTOCOL_NOTIFY - used for each register notification for a protocol
212 PROTOCOL_ENTRY
*Protocol
;
213 /// All notifications for this protocol
215 /// Notification function
216 EFI_SMM_NOTIFY_FN Function
;
217 /// Last position notified
218 LIST_ENTRY
*Position
;
222 // SMM Core Global Variables
224 extern SMM_CORE_PRIVATE_DATA
*gSmmCorePrivate
;
225 extern EFI_SMM_SYSTEM_TABLE2 gSmmCoreSmst
;
226 extern LIST_ENTRY gHandleList
;
227 extern EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddressSmramBase
;
230 Called to initialize the memory service.
232 @param SmramRangeCount Number of SMRAM Regions
233 @param SmramRanges Pointer to SMRAM Descriptors
237 SmmInitializeMemoryServices (
238 IN UINTN SmramRangeCount
,
239 IN EFI_SMRAM_DESCRIPTOR
*SmramRanges
243 The SmmInstallConfigurationTable() function is used to maintain the list
244 of configuration tables that are stored in the System Management System
245 Table. The list is stored as an array of (GUID, Pointer) pairs. The list
246 must be allocated from pool memory with PoolType set to EfiRuntimeServicesData.
248 @param SystemTable A pointer to the SMM System Table (SMST).
249 @param Guid A pointer to the GUID for the entry to add, update, or remove.
250 @param Table A pointer to the buffer of the table to add.
251 @param TableSize The size of the table to install.
253 @retval EFI_SUCCESS The (Guid, Table) pair was added, updated, or removed.
254 @retval EFI_INVALID_PARAMETER Guid is not valid.
255 @retval EFI_NOT_FOUND An attempt was made to delete a non-existent entry.
256 @retval EFI_OUT_OF_RESOURCES There is not enough memory available to complete the operation.
261 SmmInstallConfigurationTable (
262 IN CONST EFI_SMM_SYSTEM_TABLE2
*SystemTable
,
263 IN CONST EFI_GUID
*Guid
,
269 Wrapper function to SmmInstallProtocolInterfaceNotify. This is the public API which
270 Calls the private one which contains a BOOLEAN parameter for notifications
272 @param UserHandle The handle to install the protocol handler on,
273 or NULL if a new handle is to be allocated
274 @param Protocol The protocol to add to the handle
275 @param InterfaceType Indicates whether Interface is supplied in
277 @param Interface The interface for the protocol being added
284 SmmInstallProtocolInterface (
285 IN OUT EFI_HANDLE
*UserHandle
,
286 IN EFI_GUID
*Protocol
,
287 IN EFI_INTERFACE_TYPE InterfaceType
,
292 Allocates pages from the memory map.
294 @param Type The type of allocation to perform
295 @param MemoryType The type of memory to turn the allocated pages
297 @param NumberOfPages The number of pages to allocate
298 @param Memory A pointer to receive the base allocated memory
301 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.
302 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
303 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
304 @retval EFI_SUCCESS Pages successfully allocated.
310 IN EFI_ALLOCATE_TYPE Type
,
311 IN EFI_MEMORY_TYPE MemoryType
,
312 IN UINTN NumberOfPages
,
313 OUT EFI_PHYSICAL_ADDRESS
*Memory
317 Allocates pages from the memory map.
319 @param Type The type of allocation to perform
320 @param MemoryType The type of memory to turn the allocated pages
322 @param NumberOfPages The number of pages to allocate
323 @param Memory A pointer to receive the base allocated memory
325 @param NeedGuard Flag to indicate Guard page is needed or not
327 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.
328 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
329 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
330 @retval EFI_SUCCESS Pages successfully allocated.
335 SmmInternalAllocatePages (
336 IN EFI_ALLOCATE_TYPE Type
,
337 IN EFI_MEMORY_TYPE MemoryType
,
338 IN UINTN NumberOfPages
,
339 OUT EFI_PHYSICAL_ADDRESS
*Memory
,
344 Frees previous allocated pages.
346 @param Memory Base address of memory being freed
347 @param NumberOfPages The number of pages to free
349 @retval EFI_NOT_FOUND Could not find the entry that covers the range
350 @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.
351 @return EFI_SUCCESS Pages successfully freed.
357 IN EFI_PHYSICAL_ADDRESS Memory
,
358 IN UINTN NumberOfPages
362 Frees previous allocated pages.
364 @param Memory Base address of memory being freed
365 @param NumberOfPages The number of pages to free
366 @param IsGuarded Flag to indicate if the memory is guarded
369 @retval EFI_NOT_FOUND Could not find the entry that covers the range
370 @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.
371 @return EFI_SUCCESS Pages successfully freed.
376 SmmInternalFreePages (
377 IN EFI_PHYSICAL_ADDRESS Memory
,
378 IN UINTN NumberOfPages
,
383 Allocate pool of a particular type.
385 @param PoolType Type of pool to allocate
386 @param Size The amount of pool to allocate
387 @param Buffer The address to return a pointer to the allocated
390 @retval EFI_INVALID_PARAMETER PoolType not valid
391 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
392 @retval EFI_SUCCESS Pool successfully allocated.
398 IN EFI_MEMORY_TYPE PoolType
,
404 Allocate pool of a particular type.
406 @param PoolType Type of pool to allocate
407 @param Size The amount of pool to allocate
408 @param Buffer The address to return a pointer to the allocated
411 @retval EFI_INVALID_PARAMETER PoolType not valid
412 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
413 @retval EFI_SUCCESS Pool successfully allocated.
418 SmmInternalAllocatePool (
419 IN EFI_MEMORY_TYPE PoolType
,
427 @param Buffer The allocated pool entry to free
429 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.
430 @retval EFI_SUCCESS Pool successfully freed.
442 @param Buffer The allocated pool entry to free
444 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.
445 @retval EFI_SUCCESS Pool successfully freed.
450 SmmInternalFreePool (
455 Installs a protocol interface into the boot services environment.
457 @param UserHandle The handle to install the protocol handler on,
458 or NULL if a new handle is to be allocated
459 @param Protocol The protocol to add to the handle
460 @param InterfaceType Indicates whether Interface is supplied in
462 @param Interface The interface for the protocol being added
463 @param Notify indicates whether notify the notification list
466 @retval EFI_INVALID_PARAMETER Invalid parameter
467 @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate
468 @retval EFI_SUCCESS Protocol interface successfully installed
472 SmmInstallProtocolInterfaceNotify (
473 IN OUT EFI_HANDLE
*UserHandle
,
474 IN EFI_GUID
*Protocol
,
475 IN EFI_INTERFACE_TYPE InterfaceType
,
481 Uninstalls all instances of a protocol:interfacer from a handle.
482 If the last protocol interface is remove from the handle, the
485 @param UserHandle The handle to remove the protocol handler from
486 @param Protocol The protocol, of protocol:interface, to remove
487 @param Interface The interface, of protocol:interface, to remove
489 @retval EFI_INVALID_PARAMETER Protocol is NULL.
490 @retval EFI_SUCCESS Protocol interface successfully uninstalled.
495 SmmUninstallProtocolInterface (
496 IN EFI_HANDLE UserHandle
,
497 IN EFI_GUID
*Protocol
,
502 Queries a handle to determine if it supports a specified protocol.
504 @param UserHandle The handle being queried.
505 @param Protocol The published unique identifier of the protocol.
506 @param Interface Supplies the address where a pointer to the
507 corresponding Protocol Interface is returned.
509 @return The requested protocol interface for the handle
515 IN EFI_HANDLE UserHandle
,
516 IN EFI_GUID
*Protocol
,
521 Add a new protocol notification record for the request protocol.
523 @param Protocol The requested protocol to add the notify
525 @param Function Points to the notification function
526 @param Registration Returns the registration record
528 @retval EFI_INVALID_PARAMETER Invalid parameter
529 @retval EFI_SUCCESS Successfully returned the registration record
535 SmmRegisterProtocolNotify (
536 IN CONST EFI_GUID
*Protocol
,
537 IN EFI_SMM_NOTIFY_FN Function
,
538 OUT VOID
**Registration
542 Locates the requested handle(s) and returns them in Buffer.
544 @param SearchType The type of search to perform to locate the
546 @param Protocol The protocol to search for
547 @param SearchKey Dependant on SearchType
548 @param BufferSize On input the size of Buffer. On output the
549 size of data returned.
550 @param Buffer The buffer to return the results in
552 @retval EFI_BUFFER_TOO_SMALL Buffer too small, required buffer size is
553 returned in BufferSize.
554 @retval EFI_INVALID_PARAMETER Invalid parameter
555 @retval EFI_SUCCESS Successfully found the requested handle(s) and
556 returns them in Buffer.
562 IN EFI_LOCATE_SEARCH_TYPE SearchType
,
563 IN EFI_GUID
*Protocol OPTIONAL
,
564 IN VOID
*SearchKey OPTIONAL
,
565 IN OUT UINTN
*BufferSize
,
566 OUT EFI_HANDLE
*Buffer
570 Return the first Protocol Interface that matches the Protocol GUID. If
571 Registration is pasased in return a Protocol Instance that was just add
572 to the system. If Retistration is NULL return the first Protocol Interface
575 @param Protocol The protocol to search for
576 @param Registration Optional Registration Key returned from
577 RegisterProtocolNotify()
578 @param Interface Return the Protocol interface (instance).
580 @retval EFI_SUCCESS If a valid Interface is returned
581 @retval EFI_INVALID_PARAMETER Invalid parameter
582 @retval EFI_NOT_FOUND Protocol interface not found
588 IN EFI_GUID
*Protocol
,
589 IN VOID
*Registration OPTIONAL
,
594 Function returns an array of handles that support the requested protocol
595 in a buffer allocated from pool. This is a version of SmmLocateHandle()
596 that allocates a buffer for the caller.
598 @param SearchType Specifies which handle(s) are to be returned.
599 @param Protocol Provides the protocol to search by. This
600 parameter is only valid for SearchType
602 @param SearchKey Supplies the search key depending on the
604 @param NumberHandles The number of handles returned in Buffer.
605 @param Buffer A pointer to the buffer to return the requested
606 array of handles that support Protocol.
608 @retval EFI_SUCCESS The result array of handles was returned.
609 @retval EFI_NOT_FOUND No handles match the search.
610 @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the
612 @retval EFI_INVALID_PARAMETER One or more paramters are not valid.
617 SmmLocateHandleBuffer (
618 IN EFI_LOCATE_SEARCH_TYPE SearchType
,
619 IN EFI_GUID
*Protocol OPTIONAL
,
620 IN VOID
*SearchKey OPTIONAL
,
621 IN OUT UINTN
*NumberHandles
,
622 OUT EFI_HANDLE
**Buffer
626 Manage SMI of a particular type.
628 @param HandlerType Points to the handler type or NULL for root SMI handlers.
629 @param Context Points to an optional context buffer.
630 @param CommBuffer Points to the optional communication buffer.
631 @param CommBufferSize Points to the size of the optional communication buffer.
633 @retval EFI_SUCCESS Interrupt source was processed successfully but not quiesced.
634 @retval EFI_INTERRUPT_PENDING One or more SMI sources could not be quiesced.
635 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING Interrupt source was not handled or quiesced.
636 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED Interrupt source was handled and quiesced.
642 IN CONST EFI_GUID
*HandlerType
,
643 IN CONST VOID
*Context OPTIONAL
,
644 IN OUT VOID
*CommBuffer OPTIONAL
,
645 IN OUT UINTN
*CommBufferSize OPTIONAL
649 Registers a handler to execute within SMM.
651 @param Handler Handler service funtion pointer.
652 @param HandlerType Points to the handler type or NULL for root SMI handlers.
653 @param DispatchHandle On return, contains a unique handle which can be used to later unregister the handler function.
655 @retval EFI_SUCCESS Handler register success.
656 @retval EFI_INVALID_PARAMETER Handler or DispatchHandle is NULL.
662 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler
,
663 IN CONST EFI_GUID
*HandlerType OPTIONAL
,
664 OUT EFI_HANDLE
*DispatchHandle
668 Unregister a handler in SMM.
670 @param DispatchHandle The handle that was specified when the handler was registered.
672 @retval EFI_SUCCESS Handler function was successfully unregistered.
673 @retval EFI_INVALID_PARAMETER DispatchHandle does not refer to a valid handle.
678 SmiHandlerUnRegister (
679 IN EFI_HANDLE DispatchHandle
683 This function is the main entry point for an SMM handler dispatch
684 or communicate-based callback.
686 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
687 @param Context Points to an optional handler context which was specified when the handler was registered.
688 @param CommBuffer A pointer to a collection of data in memory that will
689 be conveyed from a non-SMM environment into an SMM environment.
690 @param CommBufferSize The size of the CommBuffer.
697 SmmDriverDispatchHandler (
698 IN EFI_HANDLE DispatchHandle
,
699 IN CONST VOID
*Context
, OPTIONAL
700 IN OUT VOID
*CommBuffer
, OPTIONAL
701 IN OUT UINTN
*CommBufferSize OPTIONAL
705 This function is the main entry point for an SMM handler dispatch
706 or communicate-based callback.
708 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
709 @param Context Points to an optional handler context which was specified when the handler was registered.
710 @param CommBuffer A pointer to a collection of data in memory that will
711 be conveyed from a non-SMM environment into an SMM environment.
712 @param CommBufferSize The size of the CommBuffer.
719 SmmLegacyBootHandler (
720 IN EFI_HANDLE DispatchHandle
,
721 IN CONST VOID
*Context
, OPTIONAL
722 IN OUT VOID
*CommBuffer
, OPTIONAL
723 IN OUT UINTN
*CommBufferSize OPTIONAL
727 This function is the main entry point for an SMM handler dispatch
728 or communicate-based callback.
730 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
731 @param Context Points to an optional handler context which was specified when the handler was registered.
732 @param CommBuffer A pointer to a collection of data in memory that will
733 be conveyed from a non-SMM environment into an SMM environment.
734 @param CommBufferSize The size of the CommBuffer.
741 SmmReadyToLockHandler (
742 IN EFI_HANDLE DispatchHandle
,
743 IN CONST VOID
*Context
, OPTIONAL
744 IN OUT VOID
*CommBuffer
, OPTIONAL
745 IN OUT UINTN
*CommBufferSize OPTIONAL
749 This function is the main entry point for an SMM handler dispatch
750 or communicate-based callback.
752 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
753 @param Context Points to an optional handler context which was specified when the handler was registered.
754 @param CommBuffer A pointer to a collection of data in memory that will
755 be conveyed from a non-SMM environment into an SMM environment.
756 @param CommBufferSize The size of the CommBuffer.
764 IN EFI_HANDLE DispatchHandle
,
765 IN CONST VOID
*Context
, OPTIONAL
766 IN OUT VOID
*CommBuffer
, OPTIONAL
767 IN OUT UINTN
*CommBufferSize OPTIONAL
771 This function is the main entry point for an SMM handler dispatch
772 or communicate-based callback.
774 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
775 @param Context Points to an optional handler context which was specified when the handler was registered.
776 @param CommBuffer A pointer to a collection of data in memory that will
777 be conveyed from a non-SMM environment into an SMM environment.
778 @param CommBufferSize The size of the CommBuffer.
785 SmmExitBootServicesHandler (
786 IN EFI_HANDLE DispatchHandle
,
787 IN CONST VOID
*Context
, OPTIONAL
788 IN OUT VOID
*CommBuffer
, OPTIONAL
789 IN OUT UINTN
*CommBufferSize OPTIONAL
793 This function is the main entry point for an SMM handler dispatch
794 or communicate-based callback.
796 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
797 @param Context Points to an optional handler context which was specified when the handler was registered.
798 @param CommBuffer A pointer to a collection of data in memory that will
799 be conveyed from a non-SMM environment into an SMM environment.
800 @param CommBufferSize The size of the CommBuffer.
807 SmmReadyToBootHandler (
808 IN EFI_HANDLE DispatchHandle
,
809 IN CONST VOID
*Context
, OPTIONAL
810 IN OUT VOID
*CommBuffer
, OPTIONAL
811 IN OUT UINTN
*CommBufferSize OPTIONAL
815 Software SMI handler that is called when the S3SmmInitDone signal is triggered.
816 This function installs the SMM S3SmmInitDone Protocol so SMM Drivers are informed that
817 S3 SMM initialization has been done.
819 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
820 @param Context Points to an optional handler context which was specified when the handler was registered.
821 @param CommBuffer A pointer to a collection of data in memory that will
822 be conveyed from a non-SMM environment into an SMM environment.
823 @param CommBufferSize The size of the CommBuffer.
830 SmmS3SmmInitDoneHandler (
831 IN EFI_HANDLE DispatchHandle
,
832 IN CONST VOID
*Context
, OPTIONAL
833 IN OUT VOID
*CommBuffer
, OPTIONAL
834 IN OUT UINTN
*CommBufferSize OPTIONAL
838 Software SMI handler that is called when the EndOfS3Resume event is trigged.
839 This function installs the SMM EndOfS3Resume Protocol so SMM Drivers are informed that
840 S3 resume has finished.
842 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
843 @param Context Points to an optional handler context which was specified when the handler was registered.
844 @param CommBuffer A pointer to a collection of data in memory that will
845 be conveyed from a non-SMM environment into an SMM environment.
846 @param CommBufferSize The size of the CommBuffer.
853 SmmEndOfS3ResumeHandler (
854 IN EFI_HANDLE DispatchHandle
,
855 IN CONST VOID
*Context
, OPTIONAL
856 IN OUT VOID
*CommBuffer
, OPTIONAL
857 IN OUT UINTN
*CommBufferSize OPTIONAL
861 Place holder function until all the SMM System Table Service are available.
863 @param Arg1 Undefined
864 @param Arg2 Undefined
865 @param Arg3 Undefined
866 @param Arg4 Undefined
867 @param Arg5 Undefined
869 @return EFI_NOT_AVAILABLE_YET
874 SmmEfiNotAvailableYetArg5 (
883 //Functions used during debug buils
887 Traverse the discovered list for any drivers that were discovered but not loaded
888 because the dependency experessions evaluated to false.
892 SmmDisplayDiscoveredNotDispatched (
897 Add free SMRAM region for use by memory service.
899 @param MemBase Base address of memory region.
900 @param MemLength Length of the memory region.
901 @param Type Memory type.
902 @param Attributes Memory region state.
907 IN EFI_PHYSICAL_ADDRESS MemBase
,
909 IN EFI_MEMORY_TYPE Type
,
914 Finds the protocol entry for the requested protocol.
916 @param Protocol The ID of the protocol
917 @param Create Create a new entry if not found
919 @return Protocol entry
923 SmmFindProtocolEntry (
924 IN EFI_GUID
*Protocol
,
929 Signal event for every protocol in protocol entry.
931 @param Prot Protocol interface
936 IN PROTOCOL_INTERFACE
*Prot
940 Finds the protocol instance for the requested handle and protocol.
941 Note: This function doesn't do parameters checking, it's caller's responsibility
942 to pass in valid parameters.
944 @param Handle The handle to search the protocol on
945 @param Protocol GUID of the protocol
946 @param Interface The interface for the protocol being searched
948 @return Protocol instance (NULL: Not found)
952 SmmFindProtocolInterface (
954 IN EFI_GUID
*Protocol
,
959 Removes Protocol from the protocol list (but not the handle list).
961 @param Handle The handle to remove protocol on.
962 @param Protocol GUID of the protocol to be moved
963 @param Interface The interface of the protocol
965 @return Protocol Entry
969 SmmRemoveInterfaceFromProtocol (
971 IN EFI_GUID
*Protocol
,
976 This is the POSTFIX version of the dependency evaluator. This code does
977 not need to handle Before or After, as it is not valid to call this
978 routine in this case. POSTFIX means all the math is done on top of the stack.
980 @param DriverEntry DriverEntry element to update.
982 @retval TRUE If driver is ready to run.
983 @retval FALSE If driver is not ready to run or some fatal error
989 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
997 Initialize SMRAM profile.
1006 Install SMRAM profile protocol.
1010 SmramProfileInstallProtocol (
1015 Register SMM image to SMRAM profile.
1017 @param DriverEntry SMM image info.
1018 @param RegisterToDxe Register image to DXE.
1020 @return EFI_SUCCESS Register successfully.
1021 @return EFI_UNSUPPORTED Memory profile unsupported,
1022 or memory profile for the image is not required.
1023 @return EFI_OUT_OF_RESOURCES No enough resource for this register.
1027 RegisterSmramProfileImage (
1028 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
,
1029 IN BOOLEAN RegisterToDxe
1033 Unregister image from SMRAM profile.
1035 @param DriverEntry SMM image info.
1036 @param UnregisterToDxe Unregister image from DXE.
1038 @return EFI_SUCCESS Unregister successfully.
1039 @return EFI_UNSUPPORTED Memory profile unsupported,
1040 or memory profile for the image is not required.
1041 @return EFI_NOT_FOUND The image is not found.
1045 UnregisterSmramProfileImage (
1046 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
,
1047 IN BOOLEAN UnregisterToDxe
1051 Update SMRAM profile information.
1053 @param CallerAddress Address of caller who call Allocate or Free.
1054 @param Action This Allocate or Free action.
1055 @param MemoryType Memory type.
1056 EfiMaxMemoryType means the MemoryType is unknown.
1057 @param Size Buffer size.
1058 @param Buffer Buffer address.
1059 @param ActionString String for memory profile action.
1060 Only needed for user defined allocate action.
1062 @return EFI_SUCCESS Memory profile is updated.
1063 @return EFI_UNSUPPORTED Memory profile is unsupported,
1064 or memory profile for the image is not required,
1065 or memory profile for the memory type is not required.
1066 @return EFI_ACCESS_DENIED It is during memory profile data getting.
1067 @return EFI_ABORTED Memory profile recording is not enabled.
1068 @return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.
1069 @return EFI_NOT_FOUND No matched allocate info found for free action.
1074 SmmCoreUpdateProfile (
1075 IN PHYSICAL_ADDRESS CallerAddress
,
1076 IN MEMORY_PROFILE_ACTION Action
,
1077 IN EFI_MEMORY_TYPE MemoryType
, // Valid for AllocatePages/AllocatePool
1078 IN UINTN Size
, // Valid for AllocatePages/FreePages/AllocatePool
1080 IN CHAR8
*ActionString OPTIONAL
1084 Register SMRAM profile handler.
1088 RegisterSmramProfileHandler (
1093 SMRAM profile ready to lock callback function.
1097 SmramProfileReadyToLock (
1102 Initialize MemoryAttributes support.
1106 SmmCoreInitializeMemoryAttributesTable (
1111 This function returns a copy of the current memory map. The map is an array of
1112 memory descriptors, each of which describes a contiguous block of memory.
1114 @param[in, out] MemoryMapSize A pointer to the size, in bytes, of the
1115 MemoryMap buffer. On input, this is the size of
1116 the buffer allocated by the caller. On output,
1117 it is the size of the buffer returned by the
1118 firmware if the buffer was large enough, or the
1119 size of the buffer needed to contain the map if
1120 the buffer was too small.
1121 @param[in, out] MemoryMap A pointer to the buffer in which firmware places
1122 the current memory map.
1123 @param[out] MapKey A pointer to the location in which firmware
1124 returns the key for the current memory map.
1125 @param[out] DescriptorSize A pointer to the location in which firmware
1126 returns the size, in bytes, of an individual
1127 EFI_MEMORY_DESCRIPTOR.
1128 @param[out] DescriptorVersion A pointer to the location in which firmware
1129 returns the version number associated with the
1130 EFI_MEMORY_DESCRIPTOR.
1132 @retval EFI_SUCCESS The memory map was returned in the MemoryMap
1134 @retval EFI_BUFFER_TOO_SMALL The MemoryMap buffer was too small. The current
1135 buffer size needed to hold the memory map is
1136 returned in MemoryMapSize.
1137 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
1142 SmmCoreGetMemoryMap (
1143 IN OUT UINTN
*MemoryMapSize
,
1144 IN OUT EFI_MEMORY_DESCRIPTOR
*MemoryMap
,
1146 OUT UINTN
*DescriptorSize
,
1147 OUT UINT32
*DescriptorVersion
1151 Initialize SmiHandler profile feature.
1154 SmmCoreInitializeSmiHandlerProfile (
1159 This function is called by SmmChildDispatcher module to report
1160 a new SMI handler is registered, to SmmCore.
1162 @param This The protocol instance
1163 @param HandlerGuid The GUID to identify the type of the handler.
1164 For the SmmChildDispatch protocol, the HandlerGuid
1165 must be the GUID of SmmChildDispatch protocol.
1166 @param Handler The SMI handler.
1167 @param CallerAddress The address of the module who registers the SMI handler.
1168 @param Context The context of the SMI handler.
1169 For the SmmChildDispatch protocol, the Context
1170 must match the one defined for SmmChildDispatch protocol.
1171 @param ContextSize The size of the context in bytes.
1172 For the SmmChildDispatch protocol, the Context
1173 must match the one defined for SmmChildDispatch protocol.
1175 @retval EFI_SUCCESS The information is recorded.
1176 @retval EFI_OUT_OF_RESOURCES There is no enough resource to record the information.
1180 SmiHandlerProfileRegisterHandler (
1181 IN SMI_HANDLER_PROFILE_PROTOCOL
*This
,
1182 IN EFI_GUID
*HandlerGuid
,
1183 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler
,
1184 IN PHYSICAL_ADDRESS CallerAddress
,
1185 IN VOID
*Context
, OPTIONAL
1186 IN UINTN ContextSize OPTIONAL
1190 This function is called by SmmChildDispatcher module to report
1191 an existing SMI handler is unregistered, to SmmCore.
1193 @param This The protocol instance
1194 @param HandlerGuid The GUID to identify the type of the handler.
1195 For the SmmChildDispatch protocol, the HandlerGuid
1196 must be the GUID of SmmChildDispatch protocol.
1197 @param Handler The SMI handler.
1198 @param Context The context of the SMI handler.
1199 If it is NOT NULL, it will be used to check what is registered.
1200 @param ContextSize The size of the context in bytes.
1201 If Context is NOT NULL, it will be used to check what is registered.
1203 @retval EFI_SUCCESS The original record is removed.
1204 @retval EFI_NOT_FOUND There is no record for the HandlerGuid and handler.
1208 SmiHandlerProfileUnregisterHandler (
1209 IN SMI_HANDLER_PROFILE_PROTOCOL
*This
,
1210 IN EFI_GUID
*HandlerGuid
,
1211 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler
,
1212 IN VOID
*Context
, OPTIONAL
1213 IN UINTN ContextSize OPTIONAL
1216 extern UINTN mFullSmramRangeCount
;
1217 extern EFI_SMRAM_DESCRIPTOR
*mFullSmramRanges
;
1219 extern EFI_SMM_DRIVER_ENTRY
*mSmmCoreDriverEntry
;
1221 extern EFI_LOADED_IMAGE_PROTOCOL
*mSmmCoreLoadedImage
;
1229 UINTN NumberOfPages
;
1232 extern LIST_ENTRY mSmmMemoryMap
;
1239 // MIN_POOL_SHIFT must not be less than 5
1241 #define MIN_POOL_SHIFT 6
1242 #define MIN_POOL_SIZE (1 << MIN_POOL_SHIFT)
1245 // MAX_POOL_SHIFT must not be less than EFI_PAGE_SHIFT - 1
1247 #define MAX_POOL_SHIFT (EFI_PAGE_SHIFT - 1)
1248 #define MAX_POOL_SIZE (1 << MAX_POOL_SHIFT)
1251 // MAX_POOL_INDEX are calculated by maximum and minimum pool sizes
1253 #define MAX_POOL_INDEX (MAX_POOL_SHIFT - MIN_POOL_SHIFT + 1)
1255 #define POOL_HEAD_SIGNATURE SIGNATURE_32('p','h','d','0')
1260 EFI_MEMORY_TYPE Type
;
1264 #define POOL_TAIL_SIGNATURE SIGNATURE_32('p','t','a','l')
1272 #define POOL_OVERHEAD (sizeof(POOL_HEADER) + sizeof(POOL_TAIL))
1274 #define HEAD_TO_TAIL(a) \
1275 ((POOL_TAIL *) (((CHAR8 *) (a)) + (a)->Size - sizeof(POOL_TAIL)));
1288 extern LIST_ENTRY mSmmPoolLists
[SmmPoolTypeMax
][MAX_POOL_INDEX
];
1291 Internal Function. Allocate n pages from given free page node.
1293 @param Pages The free page node.
1294 @param NumberOfPages Number of pages to be allocated.
1295 @param MaxAddress Request to allocate memory below this address.
1297 @return Memory address of allocated pages.
1301 InternalAllocPagesOnOneNode (
1302 IN OUT FREE_PAGE_LIST
*Pages
,
1303 IN UINTN NumberOfPages
,
1308 Update SMM memory map entry.
1310 @param[in] Type The type of allocation to perform.
1311 @param[in] Memory The base of memory address.
1312 @param[in] NumberOfPages The number of pages to allocate.
1313 @param[in] AddRegion If this memory is new added region.
1316 ConvertSmmMemoryMapEntry (
1317 IN EFI_MEMORY_TYPE Type
,
1318 IN EFI_PHYSICAL_ADDRESS Memory
,
1319 IN UINTN NumberOfPages
,
1320 IN BOOLEAN AddRegion
1324 Internal function. Moves any memory descriptors that are on the
1325 temporary descriptor stack to heap.
1329 CoreFreeMemoryMapStack (
1334 Frees previous allocated pages.
1336 @param[in] Memory Base address of memory being freed.
1337 @param[in] NumberOfPages The number of pages to free.
1338 @param[in] AddRegion If this memory is new added region.
1340 @retval EFI_NOT_FOUND Could not find the entry that covers the range.
1341 @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.
1342 @return EFI_SUCCESS Pages successfully freed.
1346 SmmInternalFreePagesEx (
1347 IN EFI_PHYSICAL_ADDRESS Memory
,
1348 IN UINTN NumberOfPages
,
1349 IN BOOLEAN AddRegion
1353 Hook function used to set all Guard pages after entering SMM mode.
1356 SmmEntryPointMemoryManagementHook (