2 The internal header file includes the common header files, defines
3 internal structure and functions used by MmCore module.
5 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
6 Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.<BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
16 #include <StandaloneMm.h>
18 #include <Protocol/DxeMmReadyToLock.h>
19 #include <Protocol/MmReadyToLock.h>
20 #include <Protocol/MmEndOfDxe.h>
21 #include <Protocol/MmCommunication.h>
22 #include <Protocol/LoadedImage.h>
23 #include <Protocol/MmConfiguration.h>
25 #include <Guid/Apriori.h>
26 #include <Guid/EventGroup.h>
27 #include <Guid/EventLegacyBios.h>
28 #include <Guid/ZeroGuid.h>
29 #include <Guid/MemoryProfile.h>
30 #include <Guid/HobList.h>
31 #include <Guid/MmFvDispatch.h>
32 #include <Guid/MmramMemoryReserve.h>
34 #include <Library/StandaloneMmCoreEntryPoint.h>
35 #include <Library/BaseLib.h>
36 #include <Library/BaseMemoryLib.h>
37 #include <Library/PeCoffLib.h>
38 #include <Library/CacheMaintenanceLib.h>
39 #include <Library/DebugLib.h>
40 #include <Library/ReportStatusCodeLib.h>
41 #include <Library/MemoryAllocationLib.h>
42 #include <Library/PcdLib.h>
44 #include <Library/StandaloneMmMemLib.h>
45 #include <Library/HobLib.h>
47 #include "StandaloneMmCorePrivateData.h"
50 // Used to build a table of MMI Handlers that the MM Core registers
53 EFI_MM_HANDLER_ENTRY_POINT Handler
;
54 EFI_GUID
*HandlerType
;
55 EFI_HANDLE DispatchHandle
;
57 } MM_CORE_MMI_HANDLERS
;
60 // Structure for recording the state of an MM Driver
62 #define EFI_MM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v')
66 LIST_ENTRY Link
; // mDriverList
68 LIST_ENTRY ScheduledLink
; // mScheduledQueue
80 EFI_GUID BeforeAfterGuid
;
85 BOOLEAN DepexProtocolError
;
87 EFI_HANDLE ImageHandle
;
88 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
90 // Image EntryPoint in MMRAM
92 PHYSICAL_ADDRESS ImageEntryPoint
;
94 // Image Buffer in MMRAM
96 PHYSICAL_ADDRESS ImageBuffer
;
101 } EFI_MM_DRIVER_ENTRY
;
103 #define EFI_HANDLE_SIGNATURE SIGNATURE_32('h','n','d','l')
106 /// IHANDLE - contains a list of protocol handles
110 /// All handles list of IHANDLE
111 LIST_ENTRY AllHandles
;
112 /// List of PROTOCOL_INTERFACE's for this handle
113 LIST_ENTRY Protocols
;
117 #define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature == EFI_HANDLE_SIGNATURE)
119 #define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('p','r','t','e')
122 /// PROTOCOL_ENTRY - each different protocol has 1 entry in the protocol
123 /// database. Each handler that supports this protocol is listed, along
124 /// with a list of registered notifies.
128 /// Link Entry inserted to mProtocolDatabase
129 LIST_ENTRY AllEntries
;
130 /// ID of the protocol
132 /// All protocol interfaces
133 LIST_ENTRY Protocols
;
134 /// Registerd notification handlers
138 #define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('p','i','f','c')
141 /// PROTOCOL_INTERFACE - each protocol installed on a handle is tracked
142 /// with a protocol interface structure
146 /// Link on IHANDLE.Protocols
150 /// Link on PROTOCOL_ENTRY.Protocols
151 LIST_ENTRY ByProtocol
;
153 PROTOCOL_ENTRY
*Protocol
;
154 /// The interface value
156 } PROTOCOL_INTERFACE
;
158 #define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('p','r','t','n')
161 /// PROTOCOL_NOTIFY - used for each register notification for a protocol
165 PROTOCOL_ENTRY
*Protocol
;
166 /// All notifications for this protocol
168 /// Notification function
169 EFI_MM_NOTIFY_FN Function
;
170 /// Last position notified
171 LIST_ENTRY
*Position
;
175 // MM Core Global Variables
177 extern MM_CORE_PRIVATE_DATA
*gMmCorePrivate
;
178 extern EFI_MM_SYSTEM_TABLE gMmCoreMmst
;
179 extern LIST_ENTRY gHandleList
;
180 extern EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddressMmramBase
;
183 Called to initialize the memory service.
185 @param MmramRangeCount Number of MMRAM Regions
186 @param MmramRanges Pointer to MMRAM Descriptors
190 MmInitializeMemoryServices (
191 IN UINTN MmramRangeCount
,
192 IN EFI_MMRAM_DESCRIPTOR
*MmramRanges
196 The MmInstallConfigurationTable() function is used to maintain the list
197 of configuration tables that are stored in the System Management System
198 Table. The list is stored as an array of (GUID, Pointer) pairs. The list
199 must be allocated from pool memory with PoolType set to EfiRuntimeServicesData.
201 @param SystemTable A pointer to the MM System Table (SMST).
202 @param Guid A pointer to the GUID for the entry to add, update, or remove.
203 @param Table A pointer to the buffer of the table to add.
204 @param TableSize The size of the table to install.
206 @retval EFI_SUCCESS The (Guid, Table) pair was added, updated, or removed.
207 @retval EFI_INVALID_PARAMETER Guid is not valid.
208 @retval EFI_NOT_FOUND An attempt was made to delete a non-existent entry.
209 @retval EFI_OUT_OF_RESOURCES There is not enough memory available to complete the operation.
214 MmInstallConfigurationTable (
215 IN CONST EFI_MM_SYSTEM_TABLE
*SystemTable
,
216 IN CONST EFI_GUID
*Guid
,
222 Wrapper function to MmInstallProtocolInterfaceNotify. This is the public API which
223 Calls the private one which contains a BOOLEAN parameter for notifications
225 @param UserHandle The handle to install the protocol handler on,
226 or NULL if a new handle is to be allocated
227 @param Protocol The protocol to add to the handle
228 @param InterfaceType Indicates whether Interface is supplied in
230 @param Interface The interface for the protocol being added
237 MmInstallProtocolInterface (
238 IN OUT EFI_HANDLE
*UserHandle
,
239 IN EFI_GUID
*Protocol
,
240 IN EFI_INTERFACE_TYPE InterfaceType
,
245 Allocates pages from the memory map.
247 @param Type The type of allocation to perform
248 @param MemoryType The type of memory to turn the allocated pages
250 @param NumberOfPages The number of pages to allocate
251 @param Memory A pointer to receive the base allocated memory
254 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.
255 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
256 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
257 @retval EFI_SUCCESS Pages successfully allocated.
263 IN EFI_ALLOCATE_TYPE Type
,
264 IN EFI_MEMORY_TYPE MemoryType
,
265 IN UINTN NumberOfPages
,
266 OUT EFI_PHYSICAL_ADDRESS
*Memory
270 Allocates pages from the memory map.
272 @param Type The type of allocation to perform
273 @param MemoryType The type of memory to turn the allocated pages
275 @param NumberOfPages The number of pages to allocate
276 @param Memory A pointer to receive the base allocated memory
279 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.
280 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
281 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
282 @retval EFI_SUCCESS Pages successfully allocated.
287 MmInternalAllocatePages (
288 IN EFI_ALLOCATE_TYPE Type
,
289 IN EFI_MEMORY_TYPE MemoryType
,
290 IN UINTN NumberOfPages
,
291 OUT EFI_PHYSICAL_ADDRESS
*Memory
295 Frees previous allocated pages.
297 @param Memory Base address of memory being freed
298 @param NumberOfPages The number of pages to free
300 @retval EFI_NOT_FOUND Could not find the entry that covers the range
301 @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.
302 @return EFI_SUCCESS Pages successfully freed.
308 IN EFI_PHYSICAL_ADDRESS Memory
,
309 IN UINTN NumberOfPages
313 Frees previous allocated pages.
315 @param Memory Base address of memory being freed
316 @param NumberOfPages The number of pages to free
318 @retval EFI_NOT_FOUND Could not find the entry that covers the range
319 @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.
320 @return EFI_SUCCESS Pages successfully freed.
325 MmInternalFreePages (
326 IN EFI_PHYSICAL_ADDRESS Memory
,
327 IN UINTN NumberOfPages
331 Allocate pool of a particular type.
333 @param PoolType Type of pool to allocate
334 @param Size The amount of pool to allocate
335 @param Buffer The address to return a pointer to the allocated
338 @retval EFI_INVALID_PARAMETER PoolType not valid
339 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
340 @retval EFI_SUCCESS Pool successfully allocated.
346 IN EFI_MEMORY_TYPE PoolType
,
352 Allocate pool of a particular type.
354 @param PoolType Type of pool to allocate
355 @param Size The amount of pool to allocate
356 @param Buffer The address to return a pointer to the allocated
359 @retval EFI_INVALID_PARAMETER PoolType not valid
360 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
361 @retval EFI_SUCCESS Pool successfully allocated.
366 MmInternalAllocatePool (
367 IN EFI_MEMORY_TYPE PoolType
,
375 @param Buffer The allocated pool entry to free
377 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.
378 @retval EFI_SUCCESS Pool successfully freed.
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.
403 Installs a protocol interface into the boot services environment.
405 @param UserHandle The handle to install the protocol handler on,
406 or NULL if a new handle is to be allocated
407 @param Protocol The protocol to add to the handle
408 @param InterfaceType Indicates whether Interface is supplied in
410 @param Interface The interface for the protocol being added
411 @param Notify indicates whether notify the notification list
414 @retval EFI_INVALID_PARAMETER Invalid parameter
415 @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate
416 @retval EFI_SUCCESS Protocol interface successfully installed
420 MmInstallProtocolInterfaceNotify (
421 IN OUT EFI_HANDLE
*UserHandle
,
422 IN EFI_GUID
*Protocol
,
423 IN EFI_INTERFACE_TYPE InterfaceType
,
429 Uninstalls all instances of a protocol:interfacer from a handle.
430 If the last protocol interface is remove from the handle, the
433 @param UserHandle The handle to remove the protocol handler from
434 @param Protocol The protocol, of protocol:interface, to remove
435 @param Interface The interface, of protocol:interface, to remove
437 @retval EFI_INVALID_PARAMETER Protocol is NULL.
438 @retval EFI_SUCCESS Protocol interface successfully uninstalled.
443 MmUninstallProtocolInterface (
444 IN EFI_HANDLE UserHandle
,
445 IN EFI_GUID
*Protocol
,
450 Queries a handle to determine if it supports a specified protocol.
452 @param UserHandle The handle being queried.
453 @param Protocol The published unique identifier of the protocol.
454 @param Interface Supplies the address where a pointer to the
455 corresponding Protocol Interface is returned.
457 @return The requested protocol interface for the handle
463 IN EFI_HANDLE UserHandle
,
464 IN EFI_GUID
*Protocol
,
469 Add a new protocol notification record for the request protocol.
471 @param Protocol The requested protocol to add the notify
473 @param Function Points to the notification function
474 @param Registration Returns the registration record
476 @retval EFI_INVALID_PARAMETER Invalid parameter
477 @retval EFI_SUCCESS Successfully returned the registration record
483 MmRegisterProtocolNotify (
484 IN CONST EFI_GUID
*Protocol
,
485 IN EFI_MM_NOTIFY_FN Function
,
486 OUT VOID
**Registration
490 Locates the requested handle(s) and returns them in Buffer.
492 @param SearchType The type of search to perform to locate the
494 @param Protocol The protocol to search for
495 @param SearchKey Dependant on SearchType
496 @param BufferSize On input the size of Buffer. On output the
497 size of data returned.
498 @param Buffer The buffer to return the results in
500 @retval EFI_BUFFER_TOO_SMALL Buffer too small, required buffer size is
501 returned in BufferSize.
502 @retval EFI_INVALID_PARAMETER Invalid parameter
503 @retval EFI_SUCCESS Successfully found the requested handle(s) and
504 returns them in Buffer.
510 IN EFI_LOCATE_SEARCH_TYPE SearchType
,
511 IN EFI_GUID
*Protocol OPTIONAL
,
512 IN VOID
*SearchKey OPTIONAL
,
513 IN OUT UINTN
*BufferSize
,
514 OUT EFI_HANDLE
*Buffer
518 Return the first Protocol Interface that matches the Protocol GUID. If
519 Registration is pasased in return a Protocol Instance that was just add
520 to the system. If Retistration is NULL return the first Protocol Interface
523 @param Protocol The protocol to search for
524 @param Registration Optional Registration Key returned from
525 RegisterProtocolNotify()
526 @param Interface Return the Protocol interface (instance).
528 @retval EFI_SUCCESS If a valid Interface is returned
529 @retval EFI_INVALID_PARAMETER Invalid parameter
530 @retval EFI_NOT_FOUND Protocol interface not found
536 IN EFI_GUID
*Protocol
,
537 IN VOID
*Registration OPTIONAL
,
542 Manage MMI of a particular type.
544 @param HandlerType Points to the handler type or NULL for root MMI handlers.
545 @param Context Points to an optional context buffer.
546 @param CommBuffer Points to the optional communication buffer.
547 @param CommBufferSize Points to the size of the optional communication buffer.
549 @retval EFI_SUCCESS Interrupt source was processed successfully but not quiesced.
550 @retval EFI_INTERRUPT_PENDING One or more MMI sources could not be quiesced.
551 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING Interrupt source was not handled or quiesced.
552 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED Interrupt source was handled and quiesced.
558 IN CONST EFI_GUID
*HandlerType
,
559 IN CONST VOID
*Context OPTIONAL
,
560 IN OUT VOID
*CommBuffer OPTIONAL
,
561 IN OUT UINTN
*CommBufferSize OPTIONAL
565 Registers a handler to execute within MM.
567 @param Handler Handler service funtion pointer.
568 @param HandlerType Points to the handler type or NULL for root MMI handlers.
569 @param DispatchHandle On return, contains a unique handle which can be used to later unregister the handler function.
571 @retval EFI_SUCCESS Handler register success.
572 @retval EFI_INVALID_PARAMETER Handler or DispatchHandle is NULL.
578 IN EFI_MM_HANDLER_ENTRY_POINT Handler
,
579 IN CONST EFI_GUID
*HandlerType OPTIONAL
,
580 OUT EFI_HANDLE
*DispatchHandle
584 Unregister a handler in MM.
586 @param DispatchHandle The handle that was specified when the handler was registered.
588 @retval EFI_SUCCESS Handler function was successfully unregistered.
589 @retval EFI_INVALID_PARAMETER DispatchHandle does not refer to a valid handle.
594 MmiHandlerUnRegister (
595 IN EFI_HANDLE DispatchHandle
599 This function is the main entry point for an MM handler dispatch
600 or communicate-based callback.
602 @param DispatchHandle The unique handle assigned to this handler by MmiHandlerRegister().
603 @param Context Points to an optional handler context which was specified when the handler was registered.
604 @param CommBuffer A pointer to a collection of data in memory that will
605 be conveyed from a non-MM environment into an MM environment.
606 @param CommBufferSize The size of the CommBuffer.
613 MmDriverDispatchHandler (
614 IN EFI_HANDLE DispatchHandle
,
615 IN CONST VOID
*Context
, OPTIONAL
616 IN OUT VOID
*CommBuffer
, OPTIONAL
617 IN OUT UINTN
*CommBufferSize OPTIONAL
621 This function is the main entry point for an MM handler dispatch
622 or communicate-based callback.
624 @param DispatchHandle The unique handle assigned to this handler by MmiHandlerRegister().
625 @param Context Points to an optional handler context which was specified when the handler was registered.
626 @param CommBuffer A pointer to a collection of data in memory that will
627 be conveyed from a non-MM environment into an MM environment.
628 @param CommBufferSize The size of the CommBuffer.
635 MmExitBootServiceHandler (
636 IN EFI_HANDLE DispatchHandle
,
637 IN CONST VOID
*Context
, OPTIONAL
638 IN OUT VOID
*CommBuffer
, OPTIONAL
639 IN OUT UINTN
*CommBufferSize OPTIONAL
643 This function is the main entry point for an MM handler dispatch
644 or communicate-based callback.
646 @param DispatchHandle The unique handle assigned to this handler by MmiHandlerRegister().
647 @param Context Points to an optional handler context which was specified when the handler was registered.
648 @param CommBuffer A pointer to a collection of data in memory that will
649 be conveyed from a non-MM environment into an MM environment.
650 @param CommBufferSize The size of the CommBuffer.
657 MmReadyToBootHandler (
658 IN EFI_HANDLE DispatchHandle
,
659 IN CONST VOID
*Context
, OPTIONAL
660 IN OUT VOID
*CommBuffer
, OPTIONAL
661 IN OUT UINTN
*CommBufferSize OPTIONAL
665 This function is the main entry point for an MM handler dispatch
666 or communicate-based callback.
668 @param DispatchHandle The unique handle assigned to this handler by MmiHandlerRegister().
669 @param Context Points to an optional handler context which was specified when the handler was registered.
670 @param CommBuffer A pointer to a collection of data in memory that will
671 be conveyed from a non-MM environment into an MM environment.
672 @param CommBufferSize The size of the CommBuffer.
679 MmReadyToLockHandler (
680 IN EFI_HANDLE DispatchHandle
,
681 IN CONST VOID
*Context
, OPTIONAL
682 IN OUT VOID
*CommBuffer
, OPTIONAL
683 IN OUT UINTN
*CommBufferSize OPTIONAL
687 This function is the main entry point for an MM handler dispatch
688 or communicate-based callback.
690 @param DispatchHandle The unique handle assigned to this handler by MmiHandlerRegister().
691 @param Context Points to an optional handler context which was specified when the handler was registered.
692 @param CommBuffer A pointer to a collection of data in memory that will
693 be conveyed from a non-MM environment into an MM environment.
694 @param CommBufferSize The size of the CommBuffer.
702 IN EFI_HANDLE DispatchHandle
,
703 IN CONST VOID
*Context
, OPTIONAL
704 IN OUT VOID
*CommBuffer
, OPTIONAL
705 IN OUT UINTN
*CommBufferSize OPTIONAL
709 Place holder function until all the MM System Table Service are available.
711 @param Arg1 Undefined
712 @param Arg2 Undefined
713 @param Arg3 Undefined
714 @param Arg4 Undefined
715 @param Arg5 Undefined
717 @return EFI_NOT_AVAILABLE_YET
722 MmEfiNotAvailableYetArg5 (
731 //Functions used during debug buils
735 Traverse the discovered list for any drivers that were discovered but not loaded
736 because the dependency expressions evaluated to false.
740 MmDisplayDiscoveredNotDispatched (
745 Add free MMRAM region for use by memory service.
747 @param MemBase Base address of memory region.
748 @param MemLength Length of the memory region.
749 @param Type Memory type.
750 @param Attributes Memory region state.
755 IN EFI_PHYSICAL_ADDRESS MemBase
,
757 IN EFI_MEMORY_TYPE Type
,
762 Finds the protocol entry for the requested protocol.
764 @param Protocol The ID of the protocol
765 @param Create Create a new entry if not found
767 @return Protocol entry
771 MmFindProtocolEntry (
772 IN EFI_GUID
*Protocol
,
777 Signal event for every protocol in protocol entry.
779 @param Prot Protocol interface
784 IN PROTOCOL_INTERFACE
*Prot
788 Finds the protocol instance for the requested handle and protocol.
789 Note: This function doesn't do parameters checking, it's caller's responsibility
790 to pass in valid parameters.
792 @param Handle The handle to search the protocol on
793 @param Protocol GUID of the protocol
794 @param Interface The interface for the protocol being searched
796 @return Protocol instance (NULL: Not found)
800 MmFindProtocolInterface (
802 IN EFI_GUID
*Protocol
,
807 Removes Protocol from the protocol list (but not the handle list).
809 @param Handle The handle to remove protocol on.
810 @param Protocol GUID of the protocol to be moved
811 @param Interface The interface of the protocol
813 @return Protocol Entry
817 MmRemoveInterfaceFromProtocol (
819 IN EFI_GUID
*Protocol
,
824 This is the POSTFIX version of the dependency evaluator. This code does
825 not need to handle Before or After, as it is not valid to call this
826 routine in this case. POSTFIX means all the math is done on top of the stack.
828 @param DriverEntry DriverEntry element to update.
830 @retval TRUE If driver is ready to run.
831 @retval FALSE If driver is not ready to run or some fatal error
837 IN EFI_MM_DRIVER_ENTRY
*DriverEntry
841 Dump MMRAM information.
849 extern UINTN mMmramRangeCount
;
850 extern EFI_MMRAM_DESCRIPTOR
*mMmramRanges
;
851 extern EFI_SYSTEM_TABLE
*mEfiSystemTable
;