2 The internal header file includes the common header files, defines
3 internal structure and functions used by SmmCore module.
5 Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials are licensed and made available
7 under the terms and conditions of the BSD License which accompanies this
8 distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 #include <Protocol/DxeSmmReadyToLock.h>
22 #include <Protocol/SmmReadyToLock.h>
23 #include <Protocol/SmmEndOfDxe.h>
24 #include <Protocol/CpuIo2.h>
25 #include <Protocol/SmmCommunication.h>
26 #include <Protocol/SmmAccess2.h>
27 #include <Protocol/FirmwareVolume2.h>
28 #include <Protocol/LoadedImage.h>
29 #include <Protocol/DevicePath.h>
30 #include <Protocol/Security.h>
31 #include <Protocol/Security2.h>
32 #include <Protocol/SmmExitBootServices.h>
33 #include <Protocol/SmmLegacyBoot.h>
34 #include <Protocol/SmmReadyToBoot.h>
36 #include <Guid/Apriori.h>
37 #include <Guid/EventGroup.h>
38 #include <Guid/EventLegacyBios.h>
39 #include <Guid/MemoryProfile.h>
40 #include <Guid/LoadModuleAtFixedAddress.h>
42 #include <Library/BaseLib.h>
43 #include <Library/BaseMemoryLib.h>
44 #include <Library/PeCoffLib.h>
45 #include <Library/PeCoffGetEntryPointLib.h>
46 #include <Library/CacheMaintenanceLib.h>
47 #include <Library/DebugLib.h>
48 #include <Library/ReportStatusCodeLib.h>
49 #include <Library/MemoryAllocationLib.h>
50 #include <Library/DevicePathLib.h>
51 #include <Library/UefiLib.h>
52 #include <Library/UefiBootServicesTableLib.h>
53 #include <Library/PcdLib.h>
54 #include <Library/SmmCorePlatformHookLib.h>
55 #include <Library/PerformanceLib.h>
56 #include <Library/TimerLib.h>
57 #include <Library/HobLib.h>
58 #include <Library/SmmMemLib.h>
60 #include "PiSmmCorePrivateData.h"
63 // Used to build a table of SMI Handlers that the SMM Core registers
66 EFI_SMM_HANDLER_ENTRY_POINT2 Handler
;
67 EFI_GUID
*HandlerType
;
68 EFI_HANDLE DispatchHandle
;
70 } SMM_CORE_SMI_HANDLERS
;
73 // Structure for recording the state of an SMM Driver
75 #define EFI_SMM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v')
79 LIST_ENTRY Link
; // mDriverList
81 LIST_ENTRY ScheduledLink
; // mScheduledQueue
85 EFI_DEVICE_PATH_PROTOCOL
*FvFileDevicePath
;
86 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
93 EFI_GUID BeforeAfterGuid
;
98 BOOLEAN DepexProtocolError
;
100 EFI_HANDLE ImageHandle
;
101 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
103 // Image EntryPoint in SMRAM
105 PHYSICAL_ADDRESS ImageEntryPoint
;
107 // Image Buffer in SMRAM
109 PHYSICAL_ADDRESS ImageBuffer
;
114 EFI_HANDLE SmmImageHandle
;
115 EFI_LOADED_IMAGE_PROTOCOL SmmLoadedImage
;
116 } EFI_SMM_DRIVER_ENTRY
;
118 #define EFI_HANDLE_SIGNATURE SIGNATURE_32('h','n','d','l')
121 /// IHANDLE - contains a list of protocol handles
125 /// All handles list of IHANDLE
126 LIST_ENTRY AllHandles
;
127 /// List of PROTOCOL_INTERFACE's for this handle
128 LIST_ENTRY Protocols
;
132 #define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature == EFI_HANDLE_SIGNATURE)
134 #define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('p','r','t','e')
137 /// PROTOCOL_ENTRY - each different protocol has 1 entry in the protocol
138 /// database. Each handler that supports this protocol is listed, along
139 /// with a list of registered notifies.
143 /// Link Entry inserted to mProtocolDatabase
144 LIST_ENTRY AllEntries
;
145 /// ID of the protocol
147 /// All protocol interfaces
148 LIST_ENTRY Protocols
;
149 /// Registerd notification handlers
153 #define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('p','i','f','c')
156 /// PROTOCOL_INTERFACE - each protocol installed on a handle is tracked
157 /// with a protocol interface structure
161 /// Link on IHANDLE.Protocols
165 /// Link on PROTOCOL_ENTRY.Protocols
166 LIST_ENTRY ByProtocol
;
168 PROTOCOL_ENTRY
*Protocol
;
169 /// The interface value
171 } PROTOCOL_INTERFACE
;
173 #define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('p','r','t','n')
176 /// PROTOCOL_NOTIFY - used for each register notification for a protocol
180 PROTOCOL_ENTRY
*Protocol
;
181 /// All notifications for this protocol
183 /// Notification function
184 EFI_SMM_NOTIFY_FN Function
;
185 /// Last position notified
186 LIST_ENTRY
*Position
;
190 // SMM Core Global Variables
192 extern SMM_CORE_PRIVATE_DATA
*gSmmCorePrivate
;
193 extern EFI_SMM_SYSTEM_TABLE2 gSmmCoreSmst
;
194 extern LIST_ENTRY gHandleList
;
195 extern EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddressSmramBase
;
198 Called to initialize the memory service.
200 @param SmramRangeCount Number of SMRAM Regions
201 @param SmramRanges Pointer to SMRAM Descriptors
205 SmmInitializeMemoryServices (
206 IN UINTN SmramRangeCount
,
207 IN EFI_SMRAM_DESCRIPTOR
*SmramRanges
211 The SmmInstallConfigurationTable() function is used to maintain the list
212 of configuration tables that are stored in the System Management System
213 Table. The list is stored as an array of (GUID, Pointer) pairs. The list
214 must be allocated from pool memory with PoolType set to EfiRuntimeServicesData.
216 @param SystemTable A pointer to the SMM System Table (SMST).
217 @param Guid A pointer to the GUID for the entry to add, update, or remove.
218 @param Table A pointer to the buffer of the table to add.
219 @param TableSize The size of the table to install.
221 @retval EFI_SUCCESS The (Guid, Table) pair was added, updated, or removed.
222 @retval EFI_INVALID_PARAMETER Guid is not valid.
223 @retval EFI_NOT_FOUND An attempt was made to delete a non-existent entry.
224 @retval EFI_OUT_OF_RESOURCES There is not enough memory available to complete the operation.
229 SmmInstallConfigurationTable (
230 IN CONST EFI_SMM_SYSTEM_TABLE2
*SystemTable
,
231 IN CONST EFI_GUID
*Guid
,
237 Wrapper function to SmmInstallProtocolInterfaceNotify. This is the public API which
238 Calls the private one which contains a BOOLEAN parameter for notifications
240 @param UserHandle The handle to install the protocol handler on,
241 or NULL if a new handle is to be allocated
242 @param Protocol The protocol to add to the handle
243 @param InterfaceType Indicates whether Interface is supplied in
245 @param Interface The interface for the protocol being added
252 SmmInstallProtocolInterface (
253 IN OUT EFI_HANDLE
*UserHandle
,
254 IN EFI_GUID
*Protocol
,
255 IN EFI_INTERFACE_TYPE InterfaceType
,
260 Allocates pages from the memory map.
262 @param Type The type of allocation to perform
263 @param MemoryType The type of memory to turn the allocated pages
265 @param NumberOfPages The number of pages to allocate
266 @param Memory A pointer to receive the base allocated memory
269 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.
270 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
271 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
272 @retval EFI_SUCCESS Pages successfully allocated.
278 IN EFI_ALLOCATE_TYPE Type
,
279 IN EFI_MEMORY_TYPE MemoryType
,
280 IN UINTN NumberOfPages
,
281 OUT EFI_PHYSICAL_ADDRESS
*Memory
285 Allocates pages from the memory map.
287 @param Type The type of allocation to perform
288 @param MemoryType The type of memory to turn the allocated pages
290 @param NumberOfPages The number of pages to allocate
291 @param Memory A pointer to receive the base allocated memory
294 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.
295 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
296 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
297 @retval EFI_SUCCESS Pages successfully allocated.
302 SmmInternalAllocatePages (
303 IN EFI_ALLOCATE_TYPE Type
,
304 IN EFI_MEMORY_TYPE MemoryType
,
305 IN UINTN NumberOfPages
,
306 OUT EFI_PHYSICAL_ADDRESS
*Memory
310 Frees previous allocated pages.
312 @param Memory Base address of memory being freed
313 @param NumberOfPages The number of pages to free
315 @retval EFI_NOT_FOUND Could not find the entry that covers the range
316 @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.
317 @return EFI_SUCCESS Pages successfully freed.
323 IN EFI_PHYSICAL_ADDRESS Memory
,
324 IN UINTN NumberOfPages
328 Frees previous allocated pages.
330 @param Memory Base address of memory being freed
331 @param NumberOfPages The number of pages to free
333 @retval EFI_NOT_FOUND Could not find the entry that covers the range
334 @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.
335 @return EFI_SUCCESS Pages successfully freed.
340 SmmInternalFreePages (
341 IN EFI_PHYSICAL_ADDRESS Memory
,
342 IN UINTN NumberOfPages
346 Allocate pool of a particular type.
348 @param PoolType Type of pool to allocate
349 @param Size The amount of pool to allocate
350 @param Buffer The address to return a pointer to the allocated
353 @retval EFI_INVALID_PARAMETER PoolType not valid
354 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
355 @retval EFI_SUCCESS Pool successfully allocated.
361 IN EFI_MEMORY_TYPE PoolType
,
367 Allocate pool of a particular type.
369 @param PoolType Type of pool to allocate
370 @param Size The amount of pool to allocate
371 @param Buffer The address to return a pointer to the allocated
374 @retval EFI_INVALID_PARAMETER PoolType not valid
375 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
376 @retval EFI_SUCCESS Pool successfully allocated.
381 SmmInternalAllocatePool (
382 IN EFI_MEMORY_TYPE PoolType
,
390 @param Buffer The allocated pool entry to free
392 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.
393 @retval EFI_SUCCESS Pool successfully freed.
405 @param Buffer The allocated pool entry to free
407 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.
408 @retval EFI_SUCCESS Pool successfully freed.
413 SmmInternalFreePool (
418 Installs a protocol interface into the boot services environment.
420 @param UserHandle The handle to install the protocol handler on,
421 or NULL if a new handle is to be allocated
422 @param Protocol The protocol to add to the handle
423 @param InterfaceType Indicates whether Interface is supplied in
425 @param Interface The interface for the protocol being added
426 @param Notify indicates whether notify the notification list
429 @retval EFI_INVALID_PARAMETER Invalid parameter
430 @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate
431 @retval EFI_SUCCESS Protocol interface successfully installed
435 SmmInstallProtocolInterfaceNotify (
436 IN OUT EFI_HANDLE
*UserHandle
,
437 IN EFI_GUID
*Protocol
,
438 IN EFI_INTERFACE_TYPE InterfaceType
,
444 Uninstalls all instances of a protocol:interfacer from a handle.
445 If the last protocol interface is remove from the handle, the
448 @param UserHandle The handle to remove the protocol handler from
449 @param Protocol The protocol, of protocol:interface, to remove
450 @param Interface The interface, of protocol:interface, to remove
452 @retval EFI_INVALID_PARAMETER Protocol is NULL.
453 @retval EFI_SUCCESS Protocol interface successfully uninstalled.
458 SmmUninstallProtocolInterface (
459 IN EFI_HANDLE UserHandle
,
460 IN EFI_GUID
*Protocol
,
465 Queries a handle to determine if it supports a specified protocol.
467 @param UserHandle The handle being queried.
468 @param Protocol The published unique identifier of the protocol.
469 @param Interface Supplies the address where a pointer to the
470 corresponding Protocol Interface is returned.
472 @return The requested protocol interface for the handle
478 IN EFI_HANDLE UserHandle
,
479 IN EFI_GUID
*Protocol
,
484 Add a new protocol notification record for the request protocol.
486 @param Protocol The requested protocol to add the notify
488 @param Function Points to the notification function
489 @param Registration Returns the registration record
491 @retval EFI_INVALID_PARAMETER Invalid parameter
492 @retval EFI_SUCCESS Successfully returned the registration record
498 SmmRegisterProtocolNotify (
499 IN CONST EFI_GUID
*Protocol
,
500 IN EFI_SMM_NOTIFY_FN Function
,
501 OUT VOID
**Registration
505 Locates the requested handle(s) and returns them in Buffer.
507 @param SearchType The type of search to perform to locate the
509 @param Protocol The protocol to search for
510 @param SearchKey Dependant on SearchType
511 @param BufferSize On input the size of Buffer. On output the
512 size of data returned.
513 @param Buffer The buffer to return the results in
515 @retval EFI_BUFFER_TOO_SMALL Buffer too small, required buffer size is
516 returned in BufferSize.
517 @retval EFI_INVALID_PARAMETER Invalid parameter
518 @retval EFI_SUCCESS Successfully found the requested handle(s) and
519 returns them in Buffer.
525 IN EFI_LOCATE_SEARCH_TYPE SearchType
,
526 IN EFI_GUID
*Protocol OPTIONAL
,
527 IN VOID
*SearchKey OPTIONAL
,
528 IN OUT UINTN
*BufferSize
,
529 OUT EFI_HANDLE
*Buffer
533 Return the first Protocol Interface that matches the Protocol GUID. If
534 Registration is pasased in return a Protocol Instance that was just add
535 to the system. If Retistration is NULL return the first Protocol Interface
538 @param Protocol The protocol to search for
539 @param Registration Optional Registration Key returned from
540 RegisterProtocolNotify()
541 @param Interface Return the Protocol interface (instance).
543 @retval EFI_SUCCESS If a valid Interface is returned
544 @retval EFI_INVALID_PARAMETER Invalid parameter
545 @retval EFI_NOT_FOUND Protocol interface not found
551 IN EFI_GUID
*Protocol
,
552 IN VOID
*Registration OPTIONAL
,
557 Function returns an array of handles that support the requested protocol
558 in a buffer allocated from pool. This is a version of SmmLocateHandle()
559 that allocates a buffer for the caller.
561 @param SearchType Specifies which handle(s) are to be returned.
562 @param Protocol Provides the protocol to search by. This
563 parameter is only valid for SearchType
565 @param SearchKey Supplies the search key depending on the
567 @param NumberHandles The number of handles returned in Buffer.
568 @param Buffer A pointer to the buffer to return the requested
569 array of handles that support Protocol.
571 @retval EFI_SUCCESS The result array of handles was returned.
572 @retval EFI_NOT_FOUND No handles match the search.
573 @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the
575 @retval EFI_INVALID_PARAMETER One or more paramters are not valid.
580 SmmLocateHandleBuffer (
581 IN EFI_LOCATE_SEARCH_TYPE SearchType
,
582 IN EFI_GUID
*Protocol OPTIONAL
,
583 IN VOID
*SearchKey OPTIONAL
,
584 IN OUT UINTN
*NumberHandles
,
585 OUT EFI_HANDLE
**Buffer
589 Manage SMI of a particular type.
591 @param HandlerType Points to the handler type or NULL for root SMI handlers.
592 @param Context Points to an optional context buffer.
593 @param CommBuffer Points to the optional communication buffer.
594 @param CommBufferSize Points to the size of the optional communication buffer.
596 @retval EFI_SUCCESS Interrupt source was processed successfully but not quiesced.
597 @retval EFI_INTERRUPT_PENDING One or more SMI sources could not be quiesced.
598 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING Interrupt source was not handled or quiesced.
599 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED Interrupt source was handled and quiesced.
605 IN CONST EFI_GUID
*HandlerType
,
606 IN CONST VOID
*Context OPTIONAL
,
607 IN OUT VOID
*CommBuffer OPTIONAL
,
608 IN OUT UINTN
*CommBufferSize OPTIONAL
612 Registers a handler to execute within SMM.
614 @param Handler Handler service funtion pointer.
615 @param HandlerType Points to the handler type or NULL for root SMI handlers.
616 @param DispatchHandle On return, contains a unique handle which can be used to later unregister the handler function.
618 @retval EFI_SUCCESS Handler register success.
619 @retval EFI_INVALID_PARAMETER Handler or DispatchHandle is NULL.
625 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler
,
626 IN CONST EFI_GUID
*HandlerType OPTIONAL
,
627 OUT EFI_HANDLE
*DispatchHandle
631 Unregister a handler in SMM.
633 @param DispatchHandle The handle that was specified when the handler was registered.
635 @retval EFI_SUCCESS Handler function was successfully unregistered.
636 @retval EFI_INVALID_PARAMETER DispatchHandle does not refer to a valid handle.
641 SmiHandlerUnRegister (
642 IN EFI_HANDLE DispatchHandle
646 This function is the main entry point for an SMM handler dispatch
647 or communicate-based callback.
649 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
650 @param Context Points to an optional handler context which was specified when the handler was registered.
651 @param CommBuffer A pointer to a collection of data in memory that will
652 be conveyed from a non-SMM environment into an SMM environment.
653 @param CommBufferSize The size of the CommBuffer.
660 SmmDriverDispatchHandler (
661 IN EFI_HANDLE DispatchHandle
,
662 IN CONST VOID
*Context
, OPTIONAL
663 IN OUT VOID
*CommBuffer
, OPTIONAL
664 IN OUT UINTN
*CommBufferSize OPTIONAL
668 This function is the main entry point for an SMM handler dispatch
669 or communicate-based callback.
671 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
672 @param Context Points to an optional handler context which was specified when the handler was registered.
673 @param CommBuffer A pointer to a collection of data in memory that will
674 be conveyed from a non-SMM environment into an SMM environment.
675 @param CommBufferSize The size of the CommBuffer.
682 SmmLegacyBootHandler (
683 IN EFI_HANDLE DispatchHandle
,
684 IN CONST VOID
*Context
, OPTIONAL
685 IN OUT VOID
*CommBuffer
, OPTIONAL
686 IN OUT UINTN
*CommBufferSize OPTIONAL
690 This function is the main entry point for an SMM handler dispatch
691 or communicate-based callback.
693 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
694 @param Context Points to an optional handler context which was specified when the handler was registered.
695 @param CommBuffer A pointer to a collection of data in memory that will
696 be conveyed from a non-SMM environment into an SMM environment.
697 @param CommBufferSize The size of the CommBuffer.
704 SmmReadyToLockHandler (
705 IN EFI_HANDLE DispatchHandle
,
706 IN CONST VOID
*Context
, OPTIONAL
707 IN OUT VOID
*CommBuffer
, OPTIONAL
708 IN OUT UINTN
*CommBufferSize OPTIONAL
712 This function is the main entry point for an SMM handler dispatch
713 or communicate-based callback.
715 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
716 @param Context Points to an optional handler context which was specified when the handler was registered.
717 @param CommBuffer A pointer to a collection of data in memory that will
718 be conveyed from a non-SMM environment into an SMM environment.
719 @param CommBufferSize The size of the CommBuffer.
727 IN EFI_HANDLE DispatchHandle
,
728 IN CONST VOID
*Context
, OPTIONAL
729 IN OUT VOID
*CommBuffer
, OPTIONAL
730 IN OUT UINTN
*CommBufferSize OPTIONAL
734 This function is the main entry point for an SMM handler dispatch
735 or communicate-based callback.
737 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
738 @param Context Points to an optional handler context which was specified when the handler was registered.
739 @param CommBuffer A pointer to a collection of data in memory that will
740 be conveyed from a non-SMM environment into an SMM environment.
741 @param CommBufferSize The size of the CommBuffer.
748 SmmExitBootServicesHandler (
749 IN EFI_HANDLE DispatchHandle
,
750 IN CONST VOID
*Context
, OPTIONAL
751 IN OUT VOID
*CommBuffer
, OPTIONAL
752 IN OUT UINTN
*CommBufferSize OPTIONAL
756 This function is the main entry point for an SMM handler dispatch
757 or communicate-based callback.
759 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
760 @param Context Points to an optional handler context which was specified when the handler was registered.
761 @param CommBuffer A pointer to a collection of data in memory that will
762 be conveyed from a non-SMM environment into an SMM environment.
763 @param CommBufferSize The size of the CommBuffer.
770 SmmReadyToBootHandler (
771 IN EFI_HANDLE DispatchHandle
,
772 IN CONST VOID
*Context
, OPTIONAL
773 IN OUT VOID
*CommBuffer
, OPTIONAL
774 IN OUT UINTN
*CommBufferSize OPTIONAL
778 Place holder function until all the SMM System Table Service are available.
780 @param Arg1 Undefined
781 @param Arg2 Undefined
782 @param Arg3 Undefined
783 @param Arg4 Undefined
784 @param Arg5 Undefined
786 @return EFI_NOT_AVAILABLE_YET
791 SmmEfiNotAvailableYetArg5 (
800 //Functions used during debug buils
804 Traverse the discovered list for any drivers that were discovered but not loaded
805 because the dependency experessions evaluated to false.
809 SmmDisplayDiscoveredNotDispatched (
814 Add free SMRAM region for use by memory service.
816 @param MemBase Base address of memory region.
817 @param MemLength Length of the memory region.
818 @param Type Memory type.
819 @param Attributes Memory region state.
824 IN EFI_PHYSICAL_ADDRESS MemBase
,
826 IN EFI_MEMORY_TYPE Type
,
831 Finds the protocol entry for the requested protocol.
833 @param Protocol The ID of the protocol
834 @param Create Create a new entry if not found
836 @return Protocol entry
840 SmmFindProtocolEntry (
841 IN EFI_GUID
*Protocol
,
846 Signal event for every protocol in protocol entry.
848 @param Prot Protocol interface
853 IN PROTOCOL_INTERFACE
*Prot
857 Finds the protocol instance for the requested handle and protocol.
858 Note: This function doesn't do parameters checking, it's caller's responsibility
859 to pass in valid parameters.
861 @param Handle The handle to search the protocol on
862 @param Protocol GUID of the protocol
863 @param Interface The interface for the protocol being searched
865 @return Protocol instance (NULL: Not found)
869 SmmFindProtocolInterface (
871 IN EFI_GUID
*Protocol
,
876 Removes Protocol from the protocol list (but not the handle list).
878 @param Handle The handle to remove protocol on.
879 @param Protocol GUID of the protocol to be moved
880 @param Interface The interface of the protocol
882 @return Protocol Entry
886 SmmRemoveInterfaceFromProtocol (
888 IN EFI_GUID
*Protocol
,
893 This is the POSTFIX version of the dependency evaluator. This code does
894 not need to handle Before or After, as it is not valid to call this
895 routine in this case. POSTFIX means all the math is done on top of the stack.
897 @param DriverEntry DriverEntry element to update.
899 @retval TRUE If driver is ready to run.
900 @retval FALSE If driver is not ready to run or some fatal error
906 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
914 Initialize SMRAM profile.
923 Install SMRAM profile protocol.
927 SmramProfileInstallProtocol (
932 Register SMM image to SMRAM profile.
934 @param DriverEntry SMM image info.
935 @param RegisterToDxe Register image to DXE.
937 @return EFI_SUCCESS Register successfully.
938 @return EFI_UNSUPPORTED Memory profile unsupported,
939 or memory profile for the image is not required.
940 @return EFI_OUT_OF_RESOURCES No enough resource for this register.
944 RegisterSmramProfileImage (
945 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
,
946 IN BOOLEAN RegisterToDxe
950 Unregister image from SMRAM profile.
952 @param DriverEntry SMM image info.
953 @param UnregisterToDxe Unregister image from DXE.
955 @return EFI_SUCCESS Unregister successfully.
956 @return EFI_UNSUPPORTED Memory profile unsupported,
957 or memory profile for the image is not required.
958 @return EFI_NOT_FOUND The image is not found.
962 UnregisterSmramProfileImage (
963 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
,
964 IN BOOLEAN UnregisterToDxe
968 Update SMRAM profile information.
970 @param CallerAddress Address of caller who call Allocate or Free.
971 @param Action This Allocate or Free action.
972 @param MemoryType Memory type.
973 EfiMaxMemoryType means the MemoryType is unknown.
974 @param Size Buffer size.
975 @param Buffer Buffer address.
976 @param ActionString String for memory profile action.
977 Only needed for user defined allocate action.
979 @return EFI_SUCCESS Memory profile is updated.
980 @return EFI_UNSUPPORTED Memory profile is unsupported,
981 or memory profile for the image is not required,
982 or memory profile for the memory type is not required.
983 @return EFI_ACCESS_DENIED It is during memory profile data getting.
984 @return EFI_ABORTED Memory profile recording is not enabled.
985 @return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.
986 @return EFI_NOT_FOUND No matched allocate info found for free action.
991 SmmCoreUpdateProfile (
992 IN PHYSICAL_ADDRESS CallerAddress
,
993 IN MEMORY_PROFILE_ACTION Action
,
994 IN EFI_MEMORY_TYPE MemoryType
, // Valid for AllocatePages/AllocatePool
995 IN UINTN Size
, // Valid for AllocatePages/FreePages/AllocatePool
997 IN CHAR8
*ActionString OPTIONAL
1001 Register SMRAM profile handler.
1005 RegisterSmramProfileHandler (
1010 SMRAM profile ready to lock callback function.
1014 SmramProfileReadyToLock (
1019 Initialize MemoryAttributes support.
1023 SmmCoreInitializeMemoryAttributesTable (
1028 This function returns a copy of the current memory map. The map is an array of
1029 memory descriptors, each of which describes a contiguous block of memory.
1031 @param[in, out] MemoryMapSize A pointer to the size, in bytes, of the
1032 MemoryMap buffer. On input, this is the size of
1033 the buffer allocated by the caller. On output,
1034 it is the size of the buffer returned by the
1035 firmware if the buffer was large enough, or the
1036 size of the buffer needed to contain the map if
1037 the buffer was too small.
1038 @param[in, out] MemoryMap A pointer to the buffer in which firmware places
1039 the current memory map.
1040 @param[out] MapKey A pointer to the location in which firmware
1041 returns the key for the current memory map.
1042 @param[out] DescriptorSize A pointer to the location in which firmware
1043 returns the size, in bytes, of an individual
1044 EFI_MEMORY_DESCRIPTOR.
1045 @param[out] DescriptorVersion A pointer to the location in which firmware
1046 returns the version number associated with the
1047 EFI_MEMORY_DESCRIPTOR.
1049 @retval EFI_SUCCESS The memory map was returned in the MemoryMap
1051 @retval EFI_BUFFER_TOO_SMALL The MemoryMap buffer was too small. The current
1052 buffer size needed to hold the memory map is
1053 returned in MemoryMapSize.
1054 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
1059 SmmCoreGetMemoryMap (
1060 IN OUT UINTN
*MemoryMapSize
,
1061 IN OUT EFI_MEMORY_DESCRIPTOR
*MemoryMap
,
1063 OUT UINTN
*DescriptorSize
,
1064 OUT UINT32
*DescriptorVersion
1068 /// For generic EFI machines make the default allocations 4K aligned
1070 #define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT (EFI_PAGE_SIZE)
1071 #define DEFAULT_PAGE_ALLOCATION (EFI_PAGE_SIZE)
1073 extern UINTN mFullSmramRangeCount
;
1074 extern EFI_SMRAM_DESCRIPTOR
*mFullSmramRanges
;
1076 extern EFI_SMM_DRIVER_ENTRY
*mSmmCoreDriverEntry
;
1078 extern EFI_LOADED_IMAGE_PROTOCOL
*mSmmCoreLoadedImage
;
1086 UINTN NumberOfPages
;
1089 extern LIST_ENTRY mSmmMemoryMap
;
1096 // MIN_POOL_SHIFT must not be less than 5
1098 #define MIN_POOL_SHIFT 6
1099 #define MIN_POOL_SIZE (1 << MIN_POOL_SHIFT)
1102 // MAX_POOL_SHIFT must not be less than EFI_PAGE_SHIFT - 1
1104 #define MAX_POOL_SHIFT (EFI_PAGE_SHIFT - 1)
1105 #define MAX_POOL_SIZE (1 << MAX_POOL_SHIFT)
1108 // MAX_POOL_INDEX are calculated by maximum and minimum pool sizes
1110 #define MAX_POOL_INDEX (MAX_POOL_SHIFT - MIN_POOL_SHIFT + 1)
1115 EFI_MEMORY_TYPE Type
;
1129 extern LIST_ENTRY mSmmPoolLists
[SmmPoolTypeMax
][MAX_POOL_INDEX
];