2 The internal header file includes the common header files, defines
3 internal structure and functions used by SmmCore module.
5 Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials are licensed and made available
7 under the terms and conditions of the BSD License which accompanies this
8 distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 #include <Protocol/DxeSmmReadyToLock.h>
22 #include <Protocol/SmmReadyToLock.h>
23 #include <Protocol/SmmEndOfDxe.h>
24 #include <Protocol/CpuIo2.h>
25 #include <Protocol/SmmCommunication.h>
26 #include <Protocol/SmmAccess2.h>
27 #include <Protocol/FirmwareVolume2.h>
28 #include <Protocol/LoadedImage.h>
29 #include <Protocol/DevicePath.h>
30 #include <Protocol/Security.h>
31 #include <Protocol/Security2.h>
32 #include <Protocol/SmmExitBootServices.h>
33 #include <Protocol/SmmLegacyBoot.h>
34 #include <Protocol/SmmReadyToBoot.h>
35 #include <Protocol/SmmEndOfS3Resume.h>
36 #include <Protocol/SmmMemoryAttribute.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>
45 #include <Library/BaseLib.h>
46 #include <Library/BaseMemoryLib.h>
47 #include <Library/PeCoffLib.h>
48 #include <Library/PeCoffGetEntryPointLib.h>
49 #include <Library/CacheMaintenanceLib.h>
50 #include <Library/DebugLib.h>
51 #include <Library/ReportStatusCodeLib.h>
52 #include <Library/MemoryAllocationLib.h>
53 #include <Library/DevicePathLib.h>
54 #include <Library/UefiLib.h>
55 #include <Library/UefiBootServicesTableLib.h>
56 #include <Library/PcdLib.h>
57 #include <Library/SmmCorePlatformHookLib.h>
58 #include <Library/PerformanceLib.h>
59 #include <Library/TimerLib.h>
60 #include <Library/HobLib.h>
61 #include <Library/SmmMemLib.h>
63 #include "PiSmmCorePrivateData.h"
64 #include "HeapGuard.h"
67 // Used to build a table of SMI Handlers that the SMM Core registers
70 EFI_SMM_HANDLER_ENTRY_POINT2 Handler
;
71 EFI_GUID
*HandlerType
;
72 EFI_HANDLE DispatchHandle
;
74 } SMM_CORE_SMI_HANDLERS
;
77 // SMM_HANDLER - used for each SMM handler
80 #define SMI_ENTRY_SIGNATURE SIGNATURE_32('s','m','i','e')
84 LIST_ENTRY AllEntries
; // All entries
86 EFI_GUID HandlerType
; // Type of interrupt
87 LIST_ENTRY SmiHandlers
; // All handlers
90 #define SMI_HANDLER_SIGNATURE SIGNATURE_32('s','m','i','h')
94 LIST_ENTRY Link
; // Link on SMI_ENTRY.SmiHandlers
95 EFI_SMM_HANDLER_ENTRY_POINT2 Handler
; // The smm handler's entry point
96 UINTN CallerAddr
; // The address of caller who register the SMI handler.
98 VOID
*Context
; // for profile
99 UINTN ContextSize
; // for profile
103 // Structure for recording the state of an SMM Driver
105 #define EFI_SMM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v')
109 LIST_ENTRY Link
; // mDriverList
111 LIST_ENTRY ScheduledLink
; // mScheduledQueue
115 EFI_DEVICE_PATH_PROTOCOL
*FvFileDevicePath
;
116 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
123 EFI_GUID BeforeAfterGuid
;
128 BOOLEAN DepexProtocolError
;
130 EFI_HANDLE ImageHandle
;
131 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
133 // Image EntryPoint in SMRAM
135 PHYSICAL_ADDRESS ImageEntryPoint
;
137 // Image Buffer in SMRAM
139 PHYSICAL_ADDRESS ImageBuffer
;
144 EFI_HANDLE SmmImageHandle
;
145 EFI_LOADED_IMAGE_PROTOCOL SmmLoadedImage
;
146 } EFI_SMM_DRIVER_ENTRY
;
148 #define EFI_HANDLE_SIGNATURE SIGNATURE_32('h','n','d','l')
151 /// IHANDLE - contains a list of protocol handles
155 /// All handles list of IHANDLE
156 LIST_ENTRY AllHandles
;
157 /// List of PROTOCOL_INTERFACE's for this handle
158 LIST_ENTRY Protocols
;
162 #define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature == EFI_HANDLE_SIGNATURE)
164 #define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('p','r','t','e')
167 /// PROTOCOL_ENTRY - each different protocol has 1 entry in the protocol
168 /// database. Each handler that supports this protocol is listed, along
169 /// with a list of registered notifies.
173 /// Link Entry inserted to mProtocolDatabase
174 LIST_ENTRY AllEntries
;
175 /// ID of the protocol
177 /// All protocol interfaces
178 LIST_ENTRY Protocols
;
179 /// Registerd notification handlers
183 #define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('p','i','f','c')
186 /// PROTOCOL_INTERFACE - each protocol installed on a handle is tracked
187 /// with a protocol interface structure
191 /// Link on IHANDLE.Protocols
195 /// Link on PROTOCOL_ENTRY.Protocols
196 LIST_ENTRY ByProtocol
;
198 PROTOCOL_ENTRY
*Protocol
;
199 /// The interface value
201 } PROTOCOL_INTERFACE
;
203 #define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('p','r','t','n')
206 /// PROTOCOL_NOTIFY - used for each register notification for a protocol
210 PROTOCOL_ENTRY
*Protocol
;
211 /// All notifications for this protocol
213 /// Notification function
214 EFI_SMM_NOTIFY_FN Function
;
215 /// Last position notified
216 LIST_ENTRY
*Position
;
220 // SMM Core Global Variables
222 extern SMM_CORE_PRIVATE_DATA
*gSmmCorePrivate
;
223 extern EFI_SMM_SYSTEM_TABLE2 gSmmCoreSmst
;
224 extern LIST_ENTRY gHandleList
;
225 extern EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddressSmramBase
;
228 Called to initialize the memory service.
230 @param SmramRangeCount Number of SMRAM Regions
231 @param SmramRanges Pointer to SMRAM Descriptors
235 SmmInitializeMemoryServices (
236 IN UINTN SmramRangeCount
,
237 IN EFI_SMRAM_DESCRIPTOR
*SmramRanges
241 The SmmInstallConfigurationTable() function is used to maintain the list
242 of configuration tables that are stored in the System Management System
243 Table. The list is stored as an array of (GUID, Pointer) pairs. The list
244 must be allocated from pool memory with PoolType set to EfiRuntimeServicesData.
246 @param SystemTable A pointer to the SMM System Table (SMST).
247 @param Guid A pointer to the GUID for the entry to add, update, or remove.
248 @param Table A pointer to the buffer of the table to add.
249 @param TableSize The size of the table to install.
251 @retval EFI_SUCCESS The (Guid, Table) pair was added, updated, or removed.
252 @retval EFI_INVALID_PARAMETER Guid is not valid.
253 @retval EFI_NOT_FOUND An attempt was made to delete a non-existent entry.
254 @retval EFI_OUT_OF_RESOURCES There is not enough memory available to complete the operation.
259 SmmInstallConfigurationTable (
260 IN CONST EFI_SMM_SYSTEM_TABLE2
*SystemTable
,
261 IN CONST EFI_GUID
*Guid
,
267 Wrapper function to SmmInstallProtocolInterfaceNotify. This is the public API which
268 Calls the private one which contains a BOOLEAN parameter for notifications
270 @param UserHandle The handle to install the protocol handler on,
271 or NULL if a new handle is to be allocated
272 @param Protocol The protocol to add to the handle
273 @param InterfaceType Indicates whether Interface is supplied in
275 @param Interface The interface for the protocol being added
282 SmmInstallProtocolInterface (
283 IN OUT EFI_HANDLE
*UserHandle
,
284 IN EFI_GUID
*Protocol
,
285 IN EFI_INTERFACE_TYPE InterfaceType
,
290 Allocates pages from the memory map.
292 @param Type The type of allocation to perform
293 @param MemoryType The type of memory to turn the allocated pages
295 @param NumberOfPages The number of pages to allocate
296 @param Memory A pointer to receive the base allocated memory
299 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.
300 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
301 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
302 @retval EFI_SUCCESS Pages successfully allocated.
308 IN EFI_ALLOCATE_TYPE Type
,
309 IN EFI_MEMORY_TYPE MemoryType
,
310 IN UINTN NumberOfPages
,
311 OUT EFI_PHYSICAL_ADDRESS
*Memory
315 Allocates pages from the memory map.
317 @param Type The type of allocation to perform
318 @param MemoryType The type of memory to turn the allocated pages
320 @param NumberOfPages The number of pages to allocate
321 @param Memory A pointer to receive the base allocated memory
323 @param NeedGuard Flag to indicate Guard page is needed or not
325 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.
326 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
327 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
328 @retval EFI_SUCCESS Pages successfully allocated.
333 SmmInternalAllocatePages (
334 IN EFI_ALLOCATE_TYPE Type
,
335 IN EFI_MEMORY_TYPE MemoryType
,
336 IN UINTN NumberOfPages
,
337 OUT EFI_PHYSICAL_ADDRESS
*Memory
,
342 Frees previous allocated pages.
344 @param Memory Base address of memory being freed
345 @param NumberOfPages The number of pages to free
347 @retval EFI_NOT_FOUND Could not find the entry that covers the range
348 @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.
349 @return EFI_SUCCESS Pages successfully freed.
355 IN EFI_PHYSICAL_ADDRESS Memory
,
356 IN UINTN NumberOfPages
360 Frees previous allocated pages.
362 @param Memory Base address of memory being freed
363 @param NumberOfPages The number of pages to free
364 @param IsGuarded Flag to indicate if the memory is guarded
367 @retval EFI_NOT_FOUND Could not find the entry that covers the range
368 @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.
369 @return EFI_SUCCESS Pages successfully freed.
374 SmmInternalFreePages (
375 IN EFI_PHYSICAL_ADDRESS Memory
,
376 IN UINTN NumberOfPages
,
381 Allocate pool of a particular type.
383 @param PoolType Type of pool to allocate
384 @param Size The amount of pool to allocate
385 @param Buffer The address to return a pointer to the allocated
388 @retval EFI_INVALID_PARAMETER PoolType not valid
389 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
390 @retval EFI_SUCCESS Pool successfully allocated.
396 IN EFI_MEMORY_TYPE PoolType
,
402 Allocate pool of a particular type.
404 @param PoolType Type of pool to allocate
405 @param Size The amount of pool to allocate
406 @param Buffer The address to return a pointer to the allocated
409 @retval EFI_INVALID_PARAMETER PoolType not valid
410 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
411 @retval EFI_SUCCESS Pool successfully allocated.
416 SmmInternalAllocatePool (
417 IN EFI_MEMORY_TYPE PoolType
,
425 @param Buffer The allocated pool entry to free
427 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.
428 @retval EFI_SUCCESS Pool successfully freed.
440 @param Buffer The allocated pool entry to free
442 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.
443 @retval EFI_SUCCESS Pool successfully freed.
448 SmmInternalFreePool (
453 Installs a protocol interface into the boot services environment.
455 @param UserHandle The handle to install the protocol handler on,
456 or NULL if a new handle is to be allocated
457 @param Protocol The protocol to add to the handle
458 @param InterfaceType Indicates whether Interface is supplied in
460 @param Interface The interface for the protocol being added
461 @param Notify indicates whether notify the notification list
464 @retval EFI_INVALID_PARAMETER Invalid parameter
465 @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate
466 @retval EFI_SUCCESS Protocol interface successfully installed
470 SmmInstallProtocolInterfaceNotify (
471 IN OUT EFI_HANDLE
*UserHandle
,
472 IN EFI_GUID
*Protocol
,
473 IN EFI_INTERFACE_TYPE InterfaceType
,
479 Uninstalls all instances of a protocol:interfacer from a handle.
480 If the last protocol interface is remove from the handle, the
483 @param UserHandle The handle to remove the protocol handler from
484 @param Protocol The protocol, of protocol:interface, to remove
485 @param Interface The interface, of protocol:interface, to remove
487 @retval EFI_INVALID_PARAMETER Protocol is NULL.
488 @retval EFI_SUCCESS Protocol interface successfully uninstalled.
493 SmmUninstallProtocolInterface (
494 IN EFI_HANDLE UserHandle
,
495 IN EFI_GUID
*Protocol
,
500 Queries a handle to determine if it supports a specified protocol.
502 @param UserHandle The handle being queried.
503 @param Protocol The published unique identifier of the protocol.
504 @param Interface Supplies the address where a pointer to the
505 corresponding Protocol Interface is returned.
507 @return The requested protocol interface for the handle
513 IN EFI_HANDLE UserHandle
,
514 IN EFI_GUID
*Protocol
,
519 Add a new protocol notification record for the request protocol.
521 @param Protocol The requested protocol to add the notify
523 @param Function Points to the notification function
524 @param Registration Returns the registration record
526 @retval EFI_INVALID_PARAMETER Invalid parameter
527 @retval EFI_SUCCESS Successfully returned the registration record
533 SmmRegisterProtocolNotify (
534 IN CONST EFI_GUID
*Protocol
,
535 IN EFI_SMM_NOTIFY_FN Function
,
536 OUT VOID
**Registration
540 Locates the requested handle(s) and returns them in Buffer.
542 @param SearchType The type of search to perform to locate the
544 @param Protocol The protocol to search for
545 @param SearchKey Dependant on SearchType
546 @param BufferSize On input the size of Buffer. On output the
547 size of data returned.
548 @param Buffer The buffer to return the results in
550 @retval EFI_BUFFER_TOO_SMALL Buffer too small, required buffer size is
551 returned in BufferSize.
552 @retval EFI_INVALID_PARAMETER Invalid parameter
553 @retval EFI_SUCCESS Successfully found the requested handle(s) and
554 returns them in Buffer.
560 IN EFI_LOCATE_SEARCH_TYPE SearchType
,
561 IN EFI_GUID
*Protocol OPTIONAL
,
562 IN VOID
*SearchKey OPTIONAL
,
563 IN OUT UINTN
*BufferSize
,
564 OUT EFI_HANDLE
*Buffer
568 Return the first Protocol Interface that matches the Protocol GUID. If
569 Registration is pasased in return a Protocol Instance that was just add
570 to the system. If Retistration is NULL return the first Protocol Interface
573 @param Protocol The protocol to search for
574 @param Registration Optional Registration Key returned from
575 RegisterProtocolNotify()
576 @param Interface Return the Protocol interface (instance).
578 @retval EFI_SUCCESS If a valid Interface is returned
579 @retval EFI_INVALID_PARAMETER Invalid parameter
580 @retval EFI_NOT_FOUND Protocol interface not found
586 IN EFI_GUID
*Protocol
,
587 IN VOID
*Registration OPTIONAL
,
592 Function returns an array of handles that support the requested protocol
593 in a buffer allocated from pool. This is a version of SmmLocateHandle()
594 that allocates a buffer for the caller.
596 @param SearchType Specifies which handle(s) are to be returned.
597 @param Protocol Provides the protocol to search by. This
598 parameter is only valid for SearchType
600 @param SearchKey Supplies the search key depending on the
602 @param NumberHandles The number of handles returned in Buffer.
603 @param Buffer A pointer to the buffer to return the requested
604 array of handles that support Protocol.
606 @retval EFI_SUCCESS The result array of handles was returned.
607 @retval EFI_NOT_FOUND No handles match the search.
608 @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the
610 @retval EFI_INVALID_PARAMETER One or more paramters are not valid.
615 SmmLocateHandleBuffer (
616 IN EFI_LOCATE_SEARCH_TYPE SearchType
,
617 IN EFI_GUID
*Protocol OPTIONAL
,
618 IN VOID
*SearchKey OPTIONAL
,
619 IN OUT UINTN
*NumberHandles
,
620 OUT EFI_HANDLE
**Buffer
624 Manage SMI of a particular type.
626 @param HandlerType Points to the handler type or NULL for root SMI handlers.
627 @param Context Points to an optional context buffer.
628 @param CommBuffer Points to the optional communication buffer.
629 @param CommBufferSize Points to the size of the optional communication buffer.
631 @retval EFI_SUCCESS Interrupt source was processed successfully but not quiesced.
632 @retval EFI_INTERRUPT_PENDING One or more SMI sources could not be quiesced.
633 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING Interrupt source was not handled or quiesced.
634 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED Interrupt source was handled and quiesced.
640 IN CONST EFI_GUID
*HandlerType
,
641 IN CONST VOID
*Context OPTIONAL
,
642 IN OUT VOID
*CommBuffer OPTIONAL
,
643 IN OUT UINTN
*CommBufferSize OPTIONAL
647 Registers a handler to execute within SMM.
649 @param Handler Handler service funtion pointer.
650 @param HandlerType Points to the handler type or NULL for root SMI handlers.
651 @param DispatchHandle On return, contains a unique handle which can be used to later unregister the handler function.
653 @retval EFI_SUCCESS Handler register success.
654 @retval EFI_INVALID_PARAMETER Handler or DispatchHandle is NULL.
660 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler
,
661 IN CONST EFI_GUID
*HandlerType OPTIONAL
,
662 OUT EFI_HANDLE
*DispatchHandle
666 Unregister a handler in SMM.
668 @param DispatchHandle The handle that was specified when the handler was registered.
670 @retval EFI_SUCCESS Handler function was successfully unregistered.
671 @retval EFI_INVALID_PARAMETER DispatchHandle does not refer to a valid handle.
676 SmiHandlerUnRegister (
677 IN EFI_HANDLE DispatchHandle
681 This function is the main entry point for an SMM handler dispatch
682 or communicate-based callback.
684 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
685 @param Context Points to an optional handler context which was specified when the handler was registered.
686 @param CommBuffer A pointer to a collection of data in memory that will
687 be conveyed from a non-SMM environment into an SMM environment.
688 @param CommBufferSize The size of the CommBuffer.
695 SmmDriverDispatchHandler (
696 IN EFI_HANDLE DispatchHandle
,
697 IN CONST VOID
*Context
, OPTIONAL
698 IN OUT VOID
*CommBuffer
, OPTIONAL
699 IN OUT UINTN
*CommBufferSize OPTIONAL
703 This function is the main entry point for an SMM handler dispatch
704 or communicate-based callback.
706 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
707 @param Context Points to an optional handler context which was specified when the handler was registered.
708 @param CommBuffer A pointer to a collection of data in memory that will
709 be conveyed from a non-SMM environment into an SMM environment.
710 @param CommBufferSize The size of the CommBuffer.
717 SmmLegacyBootHandler (
718 IN EFI_HANDLE DispatchHandle
,
719 IN CONST VOID
*Context
, OPTIONAL
720 IN OUT VOID
*CommBuffer
, OPTIONAL
721 IN OUT UINTN
*CommBufferSize OPTIONAL
725 This function is the main entry point for an SMM handler dispatch
726 or communicate-based callback.
728 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
729 @param Context Points to an optional handler context which was specified when the handler was registered.
730 @param CommBuffer A pointer to a collection of data in memory that will
731 be conveyed from a non-SMM environment into an SMM environment.
732 @param CommBufferSize The size of the CommBuffer.
739 SmmReadyToLockHandler (
740 IN EFI_HANDLE DispatchHandle
,
741 IN CONST VOID
*Context
, OPTIONAL
742 IN OUT VOID
*CommBuffer
, OPTIONAL
743 IN OUT UINTN
*CommBufferSize OPTIONAL
747 This function is the main entry point for an SMM handler dispatch
748 or communicate-based callback.
750 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
751 @param Context Points to an optional handler context which was specified when the handler was registered.
752 @param CommBuffer A pointer to a collection of data in memory that will
753 be conveyed from a non-SMM environment into an SMM environment.
754 @param CommBufferSize The size of the CommBuffer.
762 IN EFI_HANDLE DispatchHandle
,
763 IN CONST VOID
*Context
, OPTIONAL
764 IN OUT VOID
*CommBuffer
, OPTIONAL
765 IN OUT UINTN
*CommBufferSize OPTIONAL
769 This function is the main entry point for an SMM handler dispatch
770 or communicate-based callback.
772 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
773 @param Context Points to an optional handler context which was specified when the handler was registered.
774 @param CommBuffer A pointer to a collection of data in memory that will
775 be conveyed from a non-SMM environment into an SMM environment.
776 @param CommBufferSize The size of the CommBuffer.
783 SmmExitBootServicesHandler (
784 IN EFI_HANDLE DispatchHandle
,
785 IN CONST VOID
*Context
, OPTIONAL
786 IN OUT VOID
*CommBuffer
, OPTIONAL
787 IN OUT UINTN
*CommBufferSize OPTIONAL
791 This function is the main entry point for an SMM handler dispatch
792 or communicate-based callback.
794 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
795 @param Context Points to an optional handler context which was specified when the handler was registered.
796 @param CommBuffer A pointer to a collection of data in memory that will
797 be conveyed from a non-SMM environment into an SMM environment.
798 @param CommBufferSize The size of the CommBuffer.
805 SmmReadyToBootHandler (
806 IN EFI_HANDLE DispatchHandle
,
807 IN CONST VOID
*Context
, OPTIONAL
808 IN OUT VOID
*CommBuffer
, OPTIONAL
809 IN OUT UINTN
*CommBufferSize OPTIONAL
813 Software SMI handler that is called when the EndOfS3Resume event is trigged.
814 This function installs the SMM EndOfS3Resume Protocol so SMM Drivers are informed that
815 S3 resume has finished.
817 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
818 @param Context Points to an optional handler context which was specified when the handler was registered.
819 @param CommBuffer A pointer to a collection of data in memory that will
820 be conveyed from a non-SMM environment into an SMM environment.
821 @param CommBufferSize The size of the CommBuffer.
828 SmmEndOfS3ResumeHandler (
829 IN EFI_HANDLE DispatchHandle
,
830 IN CONST VOID
*Context
, OPTIONAL
831 IN OUT VOID
*CommBuffer
, OPTIONAL
832 IN OUT UINTN
*CommBufferSize OPTIONAL
836 Place holder function until all the SMM System Table Service are available.
838 @param Arg1 Undefined
839 @param Arg2 Undefined
840 @param Arg3 Undefined
841 @param Arg4 Undefined
842 @param Arg5 Undefined
844 @return EFI_NOT_AVAILABLE_YET
849 SmmEfiNotAvailableYetArg5 (
858 //Functions used during debug buils
862 Traverse the discovered list for any drivers that were discovered but not loaded
863 because the dependency experessions evaluated to false.
867 SmmDisplayDiscoveredNotDispatched (
872 Add free SMRAM region for use by memory service.
874 @param MemBase Base address of memory region.
875 @param MemLength Length of the memory region.
876 @param Type Memory type.
877 @param Attributes Memory region state.
882 IN EFI_PHYSICAL_ADDRESS MemBase
,
884 IN EFI_MEMORY_TYPE Type
,
889 Finds the protocol entry for the requested protocol.
891 @param Protocol The ID of the protocol
892 @param Create Create a new entry if not found
894 @return Protocol entry
898 SmmFindProtocolEntry (
899 IN EFI_GUID
*Protocol
,
904 Signal event for every protocol in protocol entry.
906 @param Prot Protocol interface
911 IN PROTOCOL_INTERFACE
*Prot
915 Finds the protocol instance for the requested handle and protocol.
916 Note: This function doesn't do parameters checking, it's caller's responsibility
917 to pass in valid parameters.
919 @param Handle The handle to search the protocol on
920 @param Protocol GUID of the protocol
921 @param Interface The interface for the protocol being searched
923 @return Protocol instance (NULL: Not found)
927 SmmFindProtocolInterface (
929 IN EFI_GUID
*Protocol
,
934 Removes Protocol from the protocol list (but not the handle list).
936 @param Handle The handle to remove protocol on.
937 @param Protocol GUID of the protocol to be moved
938 @param Interface The interface of the protocol
940 @return Protocol Entry
944 SmmRemoveInterfaceFromProtocol (
946 IN EFI_GUID
*Protocol
,
951 This is the POSTFIX version of the dependency evaluator. This code does
952 not need to handle Before or After, as it is not valid to call this
953 routine in this case. POSTFIX means all the math is done on top of the stack.
955 @param DriverEntry DriverEntry element to update.
957 @retval TRUE If driver is ready to run.
958 @retval FALSE If driver is not ready to run or some fatal error
964 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
972 Initialize SMRAM profile.
981 Install SMRAM profile protocol.
985 SmramProfileInstallProtocol (
990 Register SMM image to SMRAM profile.
992 @param DriverEntry SMM image info.
993 @param RegisterToDxe Register image to DXE.
995 @return EFI_SUCCESS Register successfully.
996 @return EFI_UNSUPPORTED Memory profile unsupported,
997 or memory profile for the image is not required.
998 @return EFI_OUT_OF_RESOURCES No enough resource for this register.
1002 RegisterSmramProfileImage (
1003 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
,
1004 IN BOOLEAN RegisterToDxe
1008 Unregister image from SMRAM profile.
1010 @param DriverEntry SMM image info.
1011 @param UnregisterToDxe Unregister image from DXE.
1013 @return EFI_SUCCESS Unregister successfully.
1014 @return EFI_UNSUPPORTED Memory profile unsupported,
1015 or memory profile for the image is not required.
1016 @return EFI_NOT_FOUND The image is not found.
1020 UnregisterSmramProfileImage (
1021 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
,
1022 IN BOOLEAN UnregisterToDxe
1026 Update SMRAM profile information.
1028 @param CallerAddress Address of caller who call Allocate or Free.
1029 @param Action This Allocate or Free action.
1030 @param MemoryType Memory type.
1031 EfiMaxMemoryType means the MemoryType is unknown.
1032 @param Size Buffer size.
1033 @param Buffer Buffer address.
1034 @param ActionString String for memory profile action.
1035 Only needed for user defined allocate action.
1037 @return EFI_SUCCESS Memory profile is updated.
1038 @return EFI_UNSUPPORTED Memory profile is unsupported,
1039 or memory profile for the image is not required,
1040 or memory profile for the memory type is not required.
1041 @return EFI_ACCESS_DENIED It is during memory profile data getting.
1042 @return EFI_ABORTED Memory profile recording is not enabled.
1043 @return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.
1044 @return EFI_NOT_FOUND No matched allocate info found for free action.
1049 SmmCoreUpdateProfile (
1050 IN PHYSICAL_ADDRESS CallerAddress
,
1051 IN MEMORY_PROFILE_ACTION Action
,
1052 IN EFI_MEMORY_TYPE MemoryType
, // Valid for AllocatePages/AllocatePool
1053 IN UINTN Size
, // Valid for AllocatePages/FreePages/AllocatePool
1055 IN CHAR8
*ActionString OPTIONAL
1059 Register SMRAM profile handler.
1063 RegisterSmramProfileHandler (
1068 SMRAM profile ready to lock callback function.
1072 SmramProfileReadyToLock (
1077 Initialize MemoryAttributes support.
1081 SmmCoreInitializeMemoryAttributesTable (
1086 This function returns a copy of the current memory map. The map is an array of
1087 memory descriptors, each of which describes a contiguous block of memory.
1089 @param[in, out] MemoryMapSize A pointer to the size, in bytes, of the
1090 MemoryMap buffer. On input, this is the size of
1091 the buffer allocated by the caller. On output,
1092 it is the size of the buffer returned by the
1093 firmware if the buffer was large enough, or the
1094 size of the buffer needed to contain the map if
1095 the buffer was too small.
1096 @param[in, out] MemoryMap A pointer to the buffer in which firmware places
1097 the current memory map.
1098 @param[out] MapKey A pointer to the location in which firmware
1099 returns the key for the current memory map.
1100 @param[out] DescriptorSize A pointer to the location in which firmware
1101 returns the size, in bytes, of an individual
1102 EFI_MEMORY_DESCRIPTOR.
1103 @param[out] DescriptorVersion A pointer to the location in which firmware
1104 returns the version number associated with the
1105 EFI_MEMORY_DESCRIPTOR.
1107 @retval EFI_SUCCESS The memory map was returned in the MemoryMap
1109 @retval EFI_BUFFER_TOO_SMALL The MemoryMap buffer was too small. The current
1110 buffer size needed to hold the memory map is
1111 returned in MemoryMapSize.
1112 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
1117 SmmCoreGetMemoryMap (
1118 IN OUT UINTN
*MemoryMapSize
,
1119 IN OUT EFI_MEMORY_DESCRIPTOR
*MemoryMap
,
1121 OUT UINTN
*DescriptorSize
,
1122 OUT UINT32
*DescriptorVersion
1126 Initialize SmiHandler profile feature.
1129 SmmCoreInitializeSmiHandlerProfile (
1134 This function is called by SmmChildDispatcher module to report
1135 a new SMI handler is registered, to SmmCore.
1137 @param This The protocol instance
1138 @param HandlerGuid The GUID to identify the type of the handler.
1139 For the SmmChildDispatch protocol, the HandlerGuid
1140 must be the GUID of SmmChildDispatch protocol.
1141 @param Handler The SMI handler.
1142 @param CallerAddress The address of the module who registers the SMI handler.
1143 @param Context The context of the SMI handler.
1144 For the SmmChildDispatch protocol, the Context
1145 must match the one defined for SmmChildDispatch protocol.
1146 @param ContextSize The size of the context in bytes.
1147 For the SmmChildDispatch protocol, the Context
1148 must match the one defined for SmmChildDispatch protocol.
1150 @retval EFI_SUCCESS The information is recorded.
1151 @retval EFI_OUT_OF_RESOURCES There is no enough resource to record the information.
1155 SmiHandlerProfileRegisterHandler (
1156 IN SMI_HANDLER_PROFILE_PROTOCOL
*This
,
1157 IN EFI_GUID
*HandlerGuid
,
1158 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler
,
1159 IN PHYSICAL_ADDRESS CallerAddress
,
1160 IN VOID
*Context
, OPTIONAL
1161 IN UINTN ContextSize OPTIONAL
1165 This function is called by SmmChildDispatcher module to report
1166 an existing SMI handler is unregistered, to SmmCore.
1168 @param This The protocol instance
1169 @param HandlerGuid The GUID to identify the type of the handler.
1170 For the SmmChildDispatch protocol, the HandlerGuid
1171 must be the GUID of SmmChildDispatch protocol.
1172 @param Handler The SMI handler.
1173 @param Context The context of the SMI handler.
1174 If it is NOT NULL, it will be used to check what is registered.
1175 @param ContextSize The size of the context in bytes.
1176 If Context is NOT NULL, it will be used to check what is registered.
1178 @retval EFI_SUCCESS The original record is removed.
1179 @retval EFI_NOT_FOUND There is no record for the HandlerGuid and handler.
1183 SmiHandlerProfileUnregisterHandler (
1184 IN SMI_HANDLER_PROFILE_PROTOCOL
*This
,
1185 IN EFI_GUID
*HandlerGuid
,
1186 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler
,
1187 IN VOID
*Context
, OPTIONAL
1188 IN UINTN ContextSize OPTIONAL
1191 extern UINTN mFullSmramRangeCount
;
1192 extern EFI_SMRAM_DESCRIPTOR
*mFullSmramRanges
;
1194 extern EFI_SMM_DRIVER_ENTRY
*mSmmCoreDriverEntry
;
1196 extern EFI_LOADED_IMAGE_PROTOCOL
*mSmmCoreLoadedImage
;
1204 UINTN NumberOfPages
;
1207 extern LIST_ENTRY mSmmMemoryMap
;
1214 // MIN_POOL_SHIFT must not be less than 5
1216 #define MIN_POOL_SHIFT 6
1217 #define MIN_POOL_SIZE (1 << MIN_POOL_SHIFT)
1220 // MAX_POOL_SHIFT must not be less than EFI_PAGE_SHIFT - 1
1222 #define MAX_POOL_SHIFT (EFI_PAGE_SHIFT - 1)
1223 #define MAX_POOL_SIZE (1 << MAX_POOL_SHIFT)
1226 // MAX_POOL_INDEX are calculated by maximum and minimum pool sizes
1228 #define MAX_POOL_INDEX (MAX_POOL_SHIFT - MIN_POOL_SHIFT + 1)
1230 #define POOL_HEAD_SIGNATURE SIGNATURE_32('p','h','d','0')
1235 EFI_MEMORY_TYPE Type
;
1239 #define POOL_TAIL_SIGNATURE SIGNATURE_32('p','t','a','l')
1247 #define POOL_OVERHEAD (sizeof(POOL_HEADER) + sizeof(POOL_TAIL))
1249 #define HEAD_TO_TAIL(a) \
1250 ((POOL_TAIL *) (((CHAR8 *) (a)) + (a)->Size - sizeof(POOL_TAIL)));
1263 extern LIST_ENTRY mSmmPoolLists
[SmmPoolTypeMax
][MAX_POOL_INDEX
];
1266 Internal Function. Allocate n pages from given free page node.
1268 @param Pages The free page node.
1269 @param NumberOfPages Number of pages to be allocated.
1270 @param MaxAddress Request to allocate memory below this address.
1272 @return Memory address of allocated pages.
1276 InternalAllocPagesOnOneNode (
1277 IN OUT FREE_PAGE_LIST
*Pages
,
1278 IN UINTN NumberOfPages
,
1283 Update SMM memory map entry.
1285 @param[in] Type The type of allocation to perform.
1286 @param[in] Memory The base of memory address.
1287 @param[in] NumberOfPages The number of pages to allocate.
1288 @param[in] AddRegion If this memory is new added region.
1291 ConvertSmmMemoryMapEntry (
1292 IN EFI_MEMORY_TYPE Type
,
1293 IN EFI_PHYSICAL_ADDRESS Memory
,
1294 IN UINTN NumberOfPages
,
1295 IN BOOLEAN AddRegion
1299 Internal function. Moves any memory descriptors that are on the
1300 temporary descriptor stack to heap.
1304 CoreFreeMemoryMapStack (
1309 Frees previous allocated pages.
1311 @param[in] Memory Base address of memory being freed.
1312 @param[in] NumberOfPages The number of pages to free.
1313 @param[in] AddRegion If this memory is new added region.
1315 @retval EFI_NOT_FOUND Could not find the entry that covers the range.
1316 @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.
1317 @return EFI_SUCCESS Pages successfully freed.
1321 SmmInternalFreePagesEx (
1322 IN EFI_PHYSICAL_ADDRESS Memory
,
1323 IN UINTN NumberOfPages
,
1324 IN BOOLEAN AddRegion
1328 Hook function used to set all Guard pages after entering SMM mode.
1331 SmmEntryPointMemoryManagementHook (