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>
41 #include <Library/BaseLib.h>
42 #include <Library/BaseMemoryLib.h>
43 #include <Library/PeCoffLib.h>
44 #include <Library/PeCoffGetEntryPointLib.h>
45 #include <Library/CacheMaintenanceLib.h>
46 #include <Library/DebugLib.h>
47 #include <Library/ReportStatusCodeLib.h>
48 #include <Library/MemoryAllocationLib.h>
49 #include <Library/DevicePathLib.h>
50 #include <Library/UefiLib.h>
51 #include <Library/UefiBootServicesTableLib.h>
52 #include <Library/PcdLib.h>
53 #include <Library/SmmCorePlatformHookLib.h>
54 #include <Library/PerformanceLib.h>
55 #include <Library/TimerLib.h>
56 #include <Library/HobLib.h>
57 #include <Library/SmmMemLib.h>
59 #include "PiSmmCorePrivateData.h"
62 // Used to build a table of SMI Handlers that the SMM Core registers
65 EFI_SMM_HANDLER_ENTRY_POINT2 Handler
;
66 EFI_GUID
*HandlerType
;
67 EFI_HANDLE DispatchHandle
;
69 } SMM_CORE_SMI_HANDLERS
;
72 // Structure for recording the state of an SMM Driver
74 #define EFI_SMM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v')
78 LIST_ENTRY Link
; // mDriverList
80 LIST_ENTRY ScheduledLink
; // mScheduledQueue
84 EFI_DEVICE_PATH_PROTOCOL
*FvFileDevicePath
;
85 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
92 EFI_GUID BeforeAfterGuid
;
97 BOOLEAN DepexProtocolError
;
99 EFI_HANDLE ImageHandle
;
100 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
102 // Image EntryPoint in SMRAM
104 PHYSICAL_ADDRESS ImageEntryPoint
;
106 // Image Buffer in SMRAM
108 PHYSICAL_ADDRESS ImageBuffer
;
113 EFI_HANDLE SmmImageHandle
;
114 EFI_LOADED_IMAGE_PROTOCOL SmmLoadedImage
;
115 } EFI_SMM_DRIVER_ENTRY
;
117 #define EFI_HANDLE_SIGNATURE SIGNATURE_32('h','n','d','l')
120 /// IHANDLE - contains a list of protocol handles
124 /// All handles list of IHANDLE
125 LIST_ENTRY AllHandles
;
126 /// List of PROTOCOL_INTERFACE's for this handle
127 LIST_ENTRY Protocols
;
131 #define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature == EFI_HANDLE_SIGNATURE)
133 #define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('p','r','t','e')
136 /// PROTOCOL_ENTRY - each different protocol has 1 entry in the protocol
137 /// database. Each handler that supports this protocol is listed, along
138 /// with a list of registered notifies.
142 /// Link Entry inserted to mProtocolDatabase
143 LIST_ENTRY AllEntries
;
144 /// ID of the protocol
146 /// All protocol interfaces
147 LIST_ENTRY Protocols
;
148 /// Registerd notification handlers
152 #define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('p','i','f','c')
155 /// PROTOCOL_INTERFACE - each protocol installed on a handle is tracked
156 /// with a protocol interface structure
160 /// Link on IHANDLE.Protocols
164 /// Link on PROTOCOL_ENTRY.Protocols
165 LIST_ENTRY ByProtocol
;
167 PROTOCOL_ENTRY
*Protocol
;
168 /// The interface value
170 } PROTOCOL_INTERFACE
;
172 #define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('p','r','t','n')
175 /// PROTOCOL_NOTIFY - used for each register notification for a protocol
179 PROTOCOL_ENTRY
*Protocol
;
180 /// All notifications for this protocol
182 /// Notification function
183 EFI_SMM_NOTIFY_FN Function
;
184 /// Last position notified
185 LIST_ENTRY
*Position
;
189 // SMM Core Global Variables
191 extern SMM_CORE_PRIVATE_DATA
*gSmmCorePrivate
;
192 extern EFI_SMM_SYSTEM_TABLE2 gSmmCoreSmst
;
193 extern LIST_ENTRY gHandleList
;
194 extern EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddressSmramBase
;
197 Called to initialize the memory service.
199 @param SmramRangeCount Number of SMRAM Regions
200 @param SmramRanges Pointer to SMRAM Descriptors
204 SmmInitializeMemoryServices (
205 IN UINTN SmramRangeCount
,
206 IN EFI_SMRAM_DESCRIPTOR
*SmramRanges
210 The SmmInstallConfigurationTable() function is used to maintain the list
211 of configuration tables that are stored in the System Management System
212 Table. The list is stored as an array of (GUID, Pointer) pairs. The list
213 must be allocated from pool memory with PoolType set to EfiRuntimeServicesData.
215 @param SystemTable A pointer to the SMM System Table (SMST).
216 @param Guid A pointer to the GUID for the entry to add, update, or remove.
217 @param Table A pointer to the buffer of the table to add.
218 @param TableSize The size of the table to install.
220 @retval EFI_SUCCESS The (Guid, Table) pair was added, updated, or removed.
221 @retval EFI_INVALID_PARAMETER Guid is not valid.
222 @retval EFI_NOT_FOUND An attempt was made to delete a non-existent entry.
223 @retval EFI_OUT_OF_RESOURCES There is not enough memory available to complete the operation.
228 SmmInstallConfigurationTable (
229 IN CONST EFI_SMM_SYSTEM_TABLE2
*SystemTable
,
230 IN CONST EFI_GUID
*Guid
,
236 Wrapper function to SmmInstallProtocolInterfaceNotify. This is the public API which
237 Calls the private one which contains a BOOLEAN parameter for notifications
239 @param UserHandle The handle to install the protocol handler on,
240 or NULL if a new handle is to be allocated
241 @param Protocol The protocol to add to the handle
242 @param InterfaceType Indicates whether Interface is supplied in
244 @param Interface The interface for the protocol being added
251 SmmInstallProtocolInterface (
252 IN OUT EFI_HANDLE
*UserHandle
,
253 IN EFI_GUID
*Protocol
,
254 IN EFI_INTERFACE_TYPE InterfaceType
,
259 Allocates pages from the memory map.
261 @param Type The type of allocation to perform
262 @param MemoryType The type of memory to turn the allocated pages
264 @param NumberOfPages The number of pages to allocate
265 @param Memory A pointer to receive the base allocated memory
268 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.
269 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
270 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
271 @retval EFI_SUCCESS Pages successfully allocated.
277 IN EFI_ALLOCATE_TYPE Type
,
278 IN EFI_MEMORY_TYPE MemoryType
,
279 IN UINTN NumberOfPages
,
280 OUT EFI_PHYSICAL_ADDRESS
*Memory
284 Allocates pages from the memory map.
286 @param Type The type of allocation to perform
287 @param MemoryType The type of memory to turn the allocated pages
289 @param NumberOfPages The number of pages to allocate
290 @param Memory A pointer to receive the base allocated memory
293 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.
294 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
295 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
296 @retval EFI_SUCCESS Pages successfully allocated.
301 SmmInternalAllocatePages (
302 IN EFI_ALLOCATE_TYPE Type
,
303 IN EFI_MEMORY_TYPE MemoryType
,
304 IN UINTN NumberOfPages
,
305 OUT EFI_PHYSICAL_ADDRESS
*Memory
309 Frees previous allocated pages.
311 @param Memory Base address of memory being freed
312 @param NumberOfPages The number of pages to free
314 @retval EFI_NOT_FOUND Could not find the entry that covers the range
315 @retval EFI_INVALID_PARAMETER Address not aligned
316 @return EFI_SUCCESS Pages successfully freed.
322 IN EFI_PHYSICAL_ADDRESS Memory
,
323 IN UINTN NumberOfPages
327 Frees previous allocated pages.
329 @param Memory Base address of memory being freed
330 @param NumberOfPages The number of pages to free
332 @retval EFI_NOT_FOUND Could not find the entry that covers the range
333 @retval EFI_INVALID_PARAMETER Address not aligned
334 @return EFI_SUCCESS Pages successfully freed.
339 SmmInternalFreePages (
340 IN EFI_PHYSICAL_ADDRESS Memory
,
341 IN UINTN NumberOfPages
345 Allocate pool of a particular type.
347 @param PoolType Type of pool to allocate
348 @param Size The amount of pool to allocate
349 @param Buffer The address to return a pointer to the allocated
352 @retval EFI_INVALID_PARAMETER PoolType not valid
353 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
354 @retval EFI_SUCCESS Pool successfully allocated.
360 IN EFI_MEMORY_TYPE PoolType
,
366 Allocate pool of a particular type.
368 @param PoolType Type of pool to allocate
369 @param Size The amount of pool to allocate
370 @param Buffer The address to return a pointer to the allocated
373 @retval EFI_INVALID_PARAMETER PoolType not valid
374 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
375 @retval EFI_SUCCESS Pool successfully allocated.
380 SmmInternalAllocatePool (
381 IN EFI_MEMORY_TYPE PoolType
,
389 @param Buffer The allocated pool entry to free
391 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.
392 @retval EFI_SUCCESS Pool successfully freed.
404 @param Buffer The allocated pool entry to free
406 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.
407 @retval EFI_SUCCESS Pool successfully freed.
412 SmmInternalFreePool (
417 Installs a protocol interface into the boot services environment.
419 @param UserHandle The handle to install the protocol handler on,
420 or NULL if a new handle is to be allocated
421 @param Protocol The protocol to add to the handle
422 @param InterfaceType Indicates whether Interface is supplied in
424 @param Interface The interface for the protocol being added
425 @param Notify indicates whether notify the notification list
428 @retval EFI_INVALID_PARAMETER Invalid parameter
429 @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate
430 @retval EFI_SUCCESS Protocol interface successfully installed
434 SmmInstallProtocolInterfaceNotify (
435 IN OUT EFI_HANDLE
*UserHandle
,
436 IN EFI_GUID
*Protocol
,
437 IN EFI_INTERFACE_TYPE InterfaceType
,
443 Uninstalls all instances of a protocol:interfacer from a handle.
444 If the last protocol interface is remove from the handle, the
447 @param UserHandle The handle to remove the protocol handler from
448 @param Protocol The protocol, of protocol:interface, to remove
449 @param Interface The interface, of protocol:interface, to remove
451 @retval EFI_INVALID_PARAMETER Protocol is NULL.
452 @retval EFI_SUCCESS Protocol interface successfully uninstalled.
457 SmmUninstallProtocolInterface (
458 IN EFI_HANDLE UserHandle
,
459 IN EFI_GUID
*Protocol
,
464 Queries a handle to determine if it supports a specified protocol.
466 @param UserHandle The handle being queried.
467 @param Protocol The published unique identifier of the protocol.
468 @param Interface Supplies the address where a pointer to the
469 corresponding Protocol Interface is returned.
471 @return The requested protocol interface for the handle
477 IN EFI_HANDLE UserHandle
,
478 IN EFI_GUID
*Protocol
,
483 Add a new protocol notification record for the request protocol.
485 @param Protocol The requested protocol to add the notify
487 @param Function Points to the notification function
488 @param Registration Returns the registration record
490 @retval EFI_INVALID_PARAMETER Invalid parameter
491 @retval EFI_SUCCESS Successfully returned the registration record
497 SmmRegisterProtocolNotify (
498 IN CONST EFI_GUID
*Protocol
,
499 IN EFI_SMM_NOTIFY_FN Function
,
500 OUT VOID
**Registration
504 Locates the requested handle(s) and returns them in Buffer.
506 @param SearchType The type of search to perform to locate the
508 @param Protocol The protocol to search for
509 @param SearchKey Dependant on SearchType
510 @param BufferSize On input the size of Buffer. On output the
511 size of data returned.
512 @param Buffer The buffer to return the results in
514 @retval EFI_BUFFER_TOO_SMALL Buffer too small, required buffer size is
515 returned in BufferSize.
516 @retval EFI_INVALID_PARAMETER Invalid parameter
517 @retval EFI_SUCCESS Successfully found the requested handle(s) and
518 returns them in Buffer.
524 IN EFI_LOCATE_SEARCH_TYPE SearchType
,
525 IN EFI_GUID
*Protocol OPTIONAL
,
526 IN VOID
*SearchKey OPTIONAL
,
527 IN OUT UINTN
*BufferSize
,
528 OUT EFI_HANDLE
*Buffer
532 Return the first Protocol Interface that matches the Protocol GUID. If
533 Registration is pasased in return a Protocol Instance that was just add
534 to the system. If Retistration is NULL return the first Protocol Interface
537 @param Protocol The protocol to search for
538 @param Registration Optional Registration Key returned from
539 RegisterProtocolNotify()
540 @param Interface Return the Protocol interface (instance).
542 @retval EFI_SUCCESS If a valid Interface is returned
543 @retval EFI_INVALID_PARAMETER Invalid parameter
544 @retval EFI_NOT_FOUND Protocol interface not found
550 IN EFI_GUID
*Protocol
,
551 IN VOID
*Registration OPTIONAL
,
556 Function returns an array of handles that support the requested protocol
557 in a buffer allocated from pool. This is a version of SmmLocateHandle()
558 that allocates a buffer for the caller.
560 @param SearchType Specifies which handle(s) are to be returned.
561 @param Protocol Provides the protocol to search by. This
562 parameter is only valid for SearchType
564 @param SearchKey Supplies the search key depending on the
566 @param NumberHandles The number of handles returned in Buffer.
567 @param Buffer A pointer to the buffer to return the requested
568 array of handles that support Protocol.
570 @retval EFI_SUCCESS The result array of handles was returned.
571 @retval EFI_NOT_FOUND No handles match the search.
572 @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the
574 @retval EFI_INVALID_PARAMETER One or more paramters are not valid.
579 SmmLocateHandleBuffer (
580 IN EFI_LOCATE_SEARCH_TYPE SearchType
,
581 IN EFI_GUID
*Protocol OPTIONAL
,
582 IN VOID
*SearchKey OPTIONAL
,
583 IN OUT UINTN
*NumberHandles
,
584 OUT EFI_HANDLE
**Buffer
588 Manage SMI of a particular type.
590 @param HandlerType Points to the handler type or NULL for root SMI handlers.
591 @param Context Points to an optional context buffer.
592 @param CommBuffer Points to the optional communication buffer.
593 @param CommBufferSize Points to the size of the optional communication buffer.
595 @retval EFI_SUCCESS Interrupt source was processed successfully but not quiesced.
596 @retval EFI_INTERRUPT_PENDING One or more SMI sources could not be quiesced.
597 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING Interrupt source was not handled or quiesced.
598 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED Interrupt source was handled and quiesced.
604 IN CONST EFI_GUID
*HandlerType
,
605 IN CONST VOID
*Context OPTIONAL
,
606 IN OUT VOID
*CommBuffer OPTIONAL
,
607 IN OUT UINTN
*CommBufferSize OPTIONAL
611 Registers a handler to execute within SMM.
613 @param Handler Handler service funtion pointer.
614 @param HandlerType Points to the handler type or NULL for root SMI handlers.
615 @param DispatchHandle On return, contains a unique handle which can be used to later unregister the handler function.
617 @retval EFI_SUCCESS Handler register success.
618 @retval EFI_INVALID_PARAMETER Handler or DispatchHandle is NULL.
624 IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler
,
625 IN CONST EFI_GUID
*HandlerType OPTIONAL
,
626 OUT EFI_HANDLE
*DispatchHandle
630 Unregister a handler in SMM.
632 @param DispatchHandle The handle that was specified when the handler was registered.
634 @retval EFI_SUCCESS Handler function was successfully unregistered.
635 @retval EFI_INVALID_PARAMETER DispatchHandle does not refer to a valid handle.
640 SmiHandlerUnRegister (
641 IN EFI_HANDLE DispatchHandle
645 This function is the main entry point for an SMM handler dispatch
646 or communicate-based callback.
648 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
649 @param Context Points to an optional handler context which was specified when the handler was registered.
650 @param CommBuffer A pointer to a collection of data in memory that will
651 be conveyed from a non-SMM environment into an SMM environment.
652 @param CommBufferSize The size of the CommBuffer.
659 SmmDriverDispatchHandler (
660 IN EFI_HANDLE DispatchHandle
,
661 IN CONST VOID
*Context
, OPTIONAL
662 IN OUT VOID
*CommBuffer
, OPTIONAL
663 IN OUT UINTN
*CommBufferSize OPTIONAL
667 This function is the main entry point for an SMM handler dispatch
668 or communicate-based callback.
670 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
671 @param Context Points to an optional handler context which was specified when the handler was registered.
672 @param CommBuffer A pointer to a collection of data in memory that will
673 be conveyed from a non-SMM environment into an SMM environment.
674 @param CommBufferSize The size of the CommBuffer.
681 SmmLegacyBootHandler (
682 IN EFI_HANDLE DispatchHandle
,
683 IN CONST VOID
*Context
, OPTIONAL
684 IN OUT VOID
*CommBuffer
, OPTIONAL
685 IN OUT UINTN
*CommBufferSize OPTIONAL
689 This function is the main entry point for an SMM handler dispatch
690 or communicate-based callback.
692 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
693 @param Context Points to an optional handler context which was specified when the handler was registered.
694 @param CommBuffer A pointer to a collection of data in memory that will
695 be conveyed from a non-SMM environment into an SMM environment.
696 @param CommBufferSize The size of the CommBuffer.
703 SmmReadyToLockHandler (
704 IN EFI_HANDLE DispatchHandle
,
705 IN CONST VOID
*Context
, OPTIONAL
706 IN OUT VOID
*CommBuffer
, OPTIONAL
707 IN OUT UINTN
*CommBufferSize OPTIONAL
711 This function is the main entry point for an SMM handler dispatch
712 or communicate-based callback.
714 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
715 @param Context Points to an optional handler context which was specified when the handler was registered.
716 @param CommBuffer A pointer to a collection of data in memory that will
717 be conveyed from a non-SMM environment into an SMM environment.
718 @param CommBufferSize The size of the CommBuffer.
726 IN EFI_HANDLE DispatchHandle
,
727 IN CONST VOID
*Context
, OPTIONAL
728 IN OUT VOID
*CommBuffer
, OPTIONAL
729 IN OUT UINTN
*CommBufferSize OPTIONAL
733 This function is the main entry point for an SMM handler dispatch
734 or communicate-based callback.
736 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
737 @param Context Points to an optional handler context which was specified when the handler was registered.
738 @param CommBuffer A pointer to a collection of data in memory that will
739 be conveyed from a non-SMM environment into an SMM environment.
740 @param CommBufferSize The size of the CommBuffer.
747 SmmExitBootServicesHandler (
748 IN EFI_HANDLE DispatchHandle
,
749 IN CONST VOID
*Context
, OPTIONAL
750 IN OUT VOID
*CommBuffer
, OPTIONAL
751 IN OUT UINTN
*CommBufferSize OPTIONAL
755 This function is the main entry point for an SMM handler dispatch
756 or communicate-based callback.
758 @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
759 @param Context Points to an optional handler context which was specified when the handler was registered.
760 @param CommBuffer A pointer to a collection of data in memory that will
761 be conveyed from a non-SMM environment into an SMM environment.
762 @param CommBufferSize The size of the CommBuffer.
769 SmmReadyToBootHandler (
770 IN EFI_HANDLE DispatchHandle
,
771 IN CONST VOID
*Context
, OPTIONAL
772 IN OUT VOID
*CommBuffer
, OPTIONAL
773 IN OUT UINTN
*CommBufferSize OPTIONAL
777 Place holder function until all the SMM System Table Service are available.
779 @param Arg1 Undefined
780 @param Arg2 Undefined
781 @param Arg3 Undefined
782 @param Arg4 Undefined
783 @param Arg5 Undefined
785 @return EFI_NOT_AVAILABLE_YET
790 SmmEfiNotAvailableYetArg5 (
799 //Functions used during debug buils
803 Traverse the discovered list for any drivers that were discovered but not loaded
804 because the dependency experessions evaluated to false.
808 SmmDisplayDiscoveredNotDispatched (
813 Add free SMRAM region for use by memory service.
815 @param MemBase Base address of memory region.
816 @param MemLength Length of the memory region.
817 @param Type Memory type.
818 @param Attributes Memory region state.
823 IN EFI_PHYSICAL_ADDRESS MemBase
,
825 IN EFI_MEMORY_TYPE Type
,
830 Finds the protocol entry for the requested protocol.
832 @param Protocol The ID of the protocol
833 @param Create Create a new entry if not found
835 @return Protocol entry
839 SmmFindProtocolEntry (
840 IN EFI_GUID
*Protocol
,
845 Signal event for every protocol in protocol entry.
847 @param Prot Protocol interface
852 IN PROTOCOL_INTERFACE
*Prot
856 Finds the protocol instance for the requested handle and protocol.
857 Note: This function doesn't do parameters checking, it's caller's responsibility
858 to pass in valid parameters.
860 @param Handle The handle to search the protocol on
861 @param Protocol GUID of the protocol
862 @param Interface The interface for the protocol being searched
864 @return Protocol instance (NULL: Not found)
868 SmmFindProtocolInterface (
870 IN EFI_GUID
*Protocol
,
875 Removes Protocol from the protocol list (but not the handle list).
877 @param Handle The handle to remove protocol on.
878 @param Protocol GUID of the protocol to be moved
879 @param Interface The interface of the protocol
881 @return Protocol Entry
885 SmmRemoveInterfaceFromProtocol (
887 IN EFI_GUID
*Protocol
,
892 This is the POSTFIX version of the dependency evaluator. This code does
893 not need to handle Before or After, as it is not valid to call this
894 routine in this case. POSTFIX means all the math is done on top of the stack.
896 @param DriverEntry DriverEntry element to update.
898 @retval TRUE If driver is ready to run.
899 @retval FALSE If driver is not ready to run or some fatal error
905 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
913 Initialize SMRAM profile.
922 Install SMRAM profile protocol.
926 SmramProfileInstallProtocol (
931 Register SMM image to SMRAM profile.
933 @param DriverEntry SMM image info.
934 @param RegisterToDxe Register image to DXE.
936 @return EFI_SUCCESS Register successfully.
937 @return EFI_UNSUPPORTED Memory profile unsupported,
938 or memory profile for the image is not required.
939 @return EFI_OUT_OF_RESOURCES No enough resource for this register.
943 RegisterSmramProfileImage (
944 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
,
945 IN BOOLEAN RegisterToDxe
949 Unregister image from SMRAM profile.
951 @param DriverEntry SMM image info.
952 @param UnregisterToDxe Unregister image from DXE.
954 @return EFI_SUCCESS Unregister successfully.
955 @return EFI_UNSUPPORTED Memory profile unsupported,
956 or memory profile for the image is not required.
957 @return EFI_NOT_FOUND The image is not found.
961 UnregisterSmramProfileImage (
962 IN EFI_SMM_DRIVER_ENTRY
*DriverEntry
,
963 IN BOOLEAN UnregisterToDxe
967 Update SMRAM profile information.
969 @param CallerAddress Address of caller who call Allocate or Free.
970 @param Action This Allocate or Free action.
971 @param MemoryType Memory type.
972 EfiMaxMemoryType means the MemoryType is unknown.
973 @param Size Buffer size.
974 @param Buffer Buffer address.
975 @param ActionString String for memory profile action.
976 Only needed for user defined allocate action.
978 @return EFI_SUCCESS Memory profile is updated.
979 @return EFI_UNSUPPORTED Memory profile is unsupported,
980 or memory profile for the image is not required,
981 or memory profile for the memory type is not required.
982 @return EFI_ACCESS_DENIED It is during memory profile data getting.
983 @return EFI_ABORTED Memory profile recording is not enabled.
984 @return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.
985 @return EFI_NOT_FOUND No matched allocate info found for free action.
990 SmmCoreUpdateProfile (
991 IN PHYSICAL_ADDRESS CallerAddress
,
992 IN MEMORY_PROFILE_ACTION Action
,
993 IN EFI_MEMORY_TYPE MemoryType
, // Valid for AllocatePages/AllocatePool
994 IN UINTN Size
, // Valid for AllocatePages/FreePages/AllocatePool
996 IN CHAR8
*ActionString OPTIONAL
1000 Register SMRAM profile handler.
1004 RegisterSmramProfileHandler (
1009 SMRAM profile ready to lock callback function.
1013 SmramProfileReadyToLock (
1018 Initialize MemoryAttributes support.
1022 SmmCoreInitializeMemoryAttributesTable (
1027 This function returns a copy of the current memory map. The map is an array of
1028 memory descriptors, each of which describes a contiguous block of memory.
1030 @param[in, out] MemoryMapSize A pointer to the size, in bytes, of the
1031 MemoryMap buffer. On input, this is the size of
1032 the buffer allocated by the caller. On output,
1033 it is the size of the buffer returned by the
1034 firmware if the buffer was large enough, or the
1035 size of the buffer needed to contain the map if
1036 the buffer was too small.
1037 @param[in, out] MemoryMap A pointer to the buffer in which firmware places
1038 the current memory map.
1039 @param[out] MapKey A pointer to the location in which firmware
1040 returns the key for the current memory map.
1041 @param[out] DescriptorSize A pointer to the location in which firmware
1042 returns the size, in bytes, of an individual
1043 EFI_MEMORY_DESCRIPTOR.
1044 @param[out] DescriptorVersion A pointer to the location in which firmware
1045 returns the version number associated with the
1046 EFI_MEMORY_DESCRIPTOR.
1048 @retval EFI_SUCCESS The memory map was returned in the MemoryMap
1050 @retval EFI_BUFFER_TOO_SMALL The MemoryMap buffer was too small. The current
1051 buffer size needed to hold the memory map is
1052 returned in MemoryMapSize.
1053 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
1058 SmmCoreGetMemoryMap (
1059 IN OUT UINTN
*MemoryMapSize
,
1060 IN OUT EFI_MEMORY_DESCRIPTOR
*MemoryMap
,
1062 OUT UINTN
*DescriptorSize
,
1063 OUT UINT32
*DescriptorVersion
1067 /// For generic EFI machines make the default allocations 4K aligned
1069 #define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT (EFI_PAGE_SIZE)
1070 #define DEFAULT_PAGE_ALLOCATION (EFI_PAGE_SIZE)
1072 extern UINTN mFullSmramRangeCount
;
1073 extern EFI_SMRAM_DESCRIPTOR
*mFullSmramRanges
;
1075 extern EFI_SMM_DRIVER_ENTRY
*mSmmCoreDriverEntry
;
1077 extern EFI_LOADED_IMAGE_PROTOCOL
*mSmmCoreLoadedImage
;
1085 UINTN NumberOfPages
;
1088 extern LIST_ENTRY mSmmMemoryMap
;
1095 // MIN_POOL_SHIFT must not be less than 5
1097 #define MIN_POOL_SHIFT 6
1098 #define MIN_POOL_SIZE (1 << MIN_POOL_SHIFT)
1101 // MAX_POOL_SHIFT must not be less than EFI_PAGE_SHIFT - 1
1103 #define MAX_POOL_SHIFT (EFI_PAGE_SHIFT - 1)
1104 #define MAX_POOL_SIZE (1 << MAX_POOL_SHIFT)
1107 // MAX_POOL_INDEX are calculated by maximum and minimum pool sizes
1109 #define MAX_POOL_INDEX (MAX_POOL_SHIFT - MIN_POOL_SHIFT + 1)
1121 extern LIST_ENTRY mSmmPoolLists
[MAX_POOL_INDEX
];