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 This program and the accompanying materials are licensed and made available
9 under the terms and conditions of the BSD License which accompanies this
10 distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 #include <StandaloneMm.h>
24 #include <Protocol/DxeMmReadyToLock.h>
25 #include <Protocol/MmReadyToLock.h>
26 #include <Protocol/MmEndOfDxe.h>
27 #include <Protocol/MmCommunication.h>
28 #include <Protocol/LoadedImage.h>
29 #include <Protocol/MmConfiguration.h>
31 #include <Guid/Apriori.h>
32 #include <Guid/EventGroup.h>
33 #include <Guid/EventLegacyBios.h>
34 #include <Guid/ZeroGuid.h>
35 #include <Guid/MemoryProfile.h>
36 #include <Guid/HobList.h>
37 #include <Guid/MmFvDispatch.h>
38 #include <Guid/MmramMemoryReserve.h>
40 #include <Library/StandaloneMmCoreEntryPoint.h>
41 #include <Library/BaseLib.h>
42 #include <Library/BaseMemoryLib.h>
43 #include <Library/PeCoffLib.h>
44 #include <Library/CacheMaintenanceLib.h>
45 #include <Library/DebugLib.h>
46 #include <Library/ReportStatusCodeLib.h>
47 #include <Library/MemoryAllocationLib.h>
48 #include <Library/PcdLib.h>
50 #include <Library/StandaloneMmMemLib.h>
51 #include <Library/HobLib.h>
53 #include "StandaloneMmCorePrivateData.h"
56 // Used to build a table of MMI Handlers that the MM Core registers
59 EFI_MM_HANDLER_ENTRY_POINT Handler
;
60 EFI_GUID
*HandlerType
;
61 EFI_HANDLE DispatchHandle
;
63 } MM_CORE_MMI_HANDLERS
;
66 // Structure for recording the state of an MM Driver
68 #define EFI_MM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v')
72 LIST_ENTRY Link
; // mDriverList
74 LIST_ENTRY ScheduledLink
; // mScheduledQueue
86 EFI_GUID BeforeAfterGuid
;
91 BOOLEAN DepexProtocolError
;
93 EFI_HANDLE ImageHandle
;
94 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
96 // Image EntryPoint in MMRAM
98 PHYSICAL_ADDRESS ImageEntryPoint
;
100 // Image Buffer in MMRAM
102 PHYSICAL_ADDRESS ImageBuffer
;
107 } EFI_MM_DRIVER_ENTRY
;
109 #define EFI_HANDLE_SIGNATURE SIGNATURE_32('h','n','d','l')
112 /// IHANDLE - contains a list of protocol handles
116 /// All handles list of IHANDLE
117 LIST_ENTRY AllHandles
;
118 /// List of PROTOCOL_INTERFACE's for this handle
119 LIST_ENTRY Protocols
;
123 #define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature == EFI_HANDLE_SIGNATURE)
125 #define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('p','r','t','e')
128 /// PROTOCOL_ENTRY - each different protocol has 1 entry in the protocol
129 /// database. Each handler that supports this protocol is listed, along
130 /// with a list of registered notifies.
134 /// Link Entry inserted to mProtocolDatabase
135 LIST_ENTRY AllEntries
;
136 /// ID of the protocol
138 /// All protocol interfaces
139 LIST_ENTRY Protocols
;
140 /// Registerd notification handlers
144 #define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('p','i','f','c')
147 /// PROTOCOL_INTERFACE - each protocol installed on a handle is tracked
148 /// with a protocol interface structure
152 /// Link on IHANDLE.Protocols
156 /// Link on PROTOCOL_ENTRY.Protocols
157 LIST_ENTRY ByProtocol
;
159 PROTOCOL_ENTRY
*Protocol
;
160 /// The interface value
162 } PROTOCOL_INTERFACE
;
164 #define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('p','r','t','n')
167 /// PROTOCOL_NOTIFY - used for each register notification for a protocol
171 PROTOCOL_ENTRY
*Protocol
;
172 /// All notifications for this protocol
174 /// Notification function
175 EFI_MM_NOTIFY_FN Function
;
176 /// Last position notified
177 LIST_ENTRY
*Position
;
181 // MM Core Global Variables
183 extern MM_CORE_PRIVATE_DATA
*gMmCorePrivate
;
184 extern EFI_MM_SYSTEM_TABLE gMmCoreMmst
;
185 extern LIST_ENTRY gHandleList
;
186 extern EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddressMmramBase
;
189 Called to initialize the memory service.
191 @param MmramRangeCount Number of MMRAM Regions
192 @param MmramRanges Pointer to MMRAM Descriptors
196 MmInitializeMemoryServices (
197 IN UINTN MmramRangeCount
,
198 IN EFI_MMRAM_DESCRIPTOR
*MmramRanges
202 The MmInstallConfigurationTable() function is used to maintain the list
203 of configuration tables that are stored in the System Management System
204 Table. The list is stored as an array of (GUID, Pointer) pairs. The list
205 must be allocated from pool memory with PoolType set to EfiRuntimeServicesData.
207 @param SystemTable A pointer to the MM System Table (SMST).
208 @param Guid A pointer to the GUID for the entry to add, update, or remove.
209 @param Table A pointer to the buffer of the table to add.
210 @param TableSize The size of the table to install.
212 @retval EFI_SUCCESS The (Guid, Table) pair was added, updated, or removed.
213 @retval EFI_INVALID_PARAMETER Guid is not valid.
214 @retval EFI_NOT_FOUND An attempt was made to delete a non-existent entry.
215 @retval EFI_OUT_OF_RESOURCES There is not enough memory available to complete the operation.
220 MmInstallConfigurationTable (
221 IN CONST EFI_MM_SYSTEM_TABLE
*SystemTable
,
222 IN CONST EFI_GUID
*Guid
,
228 Wrapper function to MmInstallProtocolInterfaceNotify. This is the public API which
229 Calls the private one which contains a BOOLEAN parameter for notifications
231 @param UserHandle The handle to install the protocol handler on,
232 or NULL if a new handle is to be allocated
233 @param Protocol The protocol to add to the handle
234 @param InterfaceType Indicates whether Interface is supplied in
236 @param Interface The interface for the protocol being added
243 MmInstallProtocolInterface (
244 IN OUT EFI_HANDLE
*UserHandle
,
245 IN EFI_GUID
*Protocol
,
246 IN EFI_INTERFACE_TYPE InterfaceType
,
251 Allocates pages from the memory map.
253 @param Type The type of allocation to perform
254 @param MemoryType The type of memory to turn the allocated pages
256 @param NumberOfPages The number of pages to allocate
257 @param Memory A pointer to receive the base allocated memory
260 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.
261 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
262 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
263 @retval EFI_SUCCESS Pages successfully allocated.
269 IN EFI_ALLOCATE_TYPE Type
,
270 IN EFI_MEMORY_TYPE MemoryType
,
271 IN UINTN NumberOfPages
,
272 OUT EFI_PHYSICAL_ADDRESS
*Memory
276 Allocates pages from the memory map.
278 @param Type The type of allocation to perform
279 @param MemoryType The type of memory to turn the allocated pages
281 @param NumberOfPages The number of pages to allocate
282 @param Memory A pointer to receive the base allocated memory
285 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec.
286 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
287 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
288 @retval EFI_SUCCESS Pages successfully allocated.
293 MmInternalAllocatePages (
294 IN EFI_ALLOCATE_TYPE Type
,
295 IN EFI_MEMORY_TYPE MemoryType
,
296 IN UINTN NumberOfPages
,
297 OUT EFI_PHYSICAL_ADDRESS
*Memory
301 Frees previous allocated pages.
303 @param Memory Base address of memory being freed
304 @param NumberOfPages The number of pages to free
306 @retval EFI_NOT_FOUND Could not find the entry that covers the range
307 @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.
308 @return EFI_SUCCESS Pages successfully freed.
314 IN EFI_PHYSICAL_ADDRESS Memory
,
315 IN UINTN NumberOfPages
319 Frees previous allocated pages.
321 @param Memory Base address of memory being freed
322 @param NumberOfPages The number of pages to free
324 @retval EFI_NOT_FOUND Could not find the entry that covers the range
325 @retval EFI_INVALID_PARAMETER Address not aligned, Address is zero or NumberOfPages is zero.
326 @return EFI_SUCCESS Pages successfully freed.
331 MmInternalFreePages (
332 IN EFI_PHYSICAL_ADDRESS Memory
,
333 IN UINTN NumberOfPages
337 Allocate pool of a particular type.
339 @param PoolType Type of pool to allocate
340 @param Size The amount of pool to allocate
341 @param Buffer The address to return a pointer to the allocated
344 @retval EFI_INVALID_PARAMETER PoolType not valid
345 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
346 @retval EFI_SUCCESS Pool successfully allocated.
352 IN EFI_MEMORY_TYPE PoolType
,
358 Allocate pool of a particular type.
360 @param PoolType Type of pool to allocate
361 @param Size The amount of pool to allocate
362 @param Buffer The address to return a pointer to the allocated
365 @retval EFI_INVALID_PARAMETER PoolType not valid
366 @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
367 @retval EFI_SUCCESS Pool successfully allocated.
372 MmInternalAllocatePool (
373 IN EFI_MEMORY_TYPE PoolType
,
381 @param Buffer The allocated pool entry to free
383 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.
384 @retval EFI_SUCCESS Pool successfully freed.
396 @param Buffer The allocated pool entry to free
398 @retval EFI_INVALID_PARAMETER Buffer is not a valid value.
399 @retval EFI_SUCCESS Pool successfully freed.
409 Installs a protocol interface into the boot services environment.
411 @param UserHandle The handle to install the protocol handler on,
412 or NULL if a new handle is to be allocated
413 @param Protocol The protocol to add to the handle
414 @param InterfaceType Indicates whether Interface is supplied in
416 @param Interface The interface for the protocol being added
417 @param Notify indicates whether notify the notification list
420 @retval EFI_INVALID_PARAMETER Invalid parameter
421 @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate
422 @retval EFI_SUCCESS Protocol interface successfully installed
426 MmInstallProtocolInterfaceNotify (
427 IN OUT EFI_HANDLE
*UserHandle
,
428 IN EFI_GUID
*Protocol
,
429 IN EFI_INTERFACE_TYPE InterfaceType
,
435 Uninstalls all instances of a protocol:interfacer from a handle.
436 If the last protocol interface is remove from the handle, the
439 @param UserHandle The handle to remove the protocol handler from
440 @param Protocol The protocol, of protocol:interface, to remove
441 @param Interface The interface, of protocol:interface, to remove
443 @retval EFI_INVALID_PARAMETER Protocol is NULL.
444 @retval EFI_SUCCESS Protocol interface successfully uninstalled.
449 MmUninstallProtocolInterface (
450 IN EFI_HANDLE UserHandle
,
451 IN EFI_GUID
*Protocol
,
456 Queries a handle to determine if it supports a specified protocol.
458 @param UserHandle The handle being queried.
459 @param Protocol The published unique identifier of the protocol.
460 @param Interface Supplies the address where a pointer to the
461 corresponding Protocol Interface is returned.
463 @return The requested protocol interface for the handle
469 IN EFI_HANDLE UserHandle
,
470 IN EFI_GUID
*Protocol
,
475 Add a new protocol notification record for the request protocol.
477 @param Protocol The requested protocol to add the notify
479 @param Function Points to the notification function
480 @param Registration Returns the registration record
482 @retval EFI_INVALID_PARAMETER Invalid parameter
483 @retval EFI_SUCCESS Successfully returned the registration record
489 MmRegisterProtocolNotify (
490 IN CONST EFI_GUID
*Protocol
,
491 IN EFI_MM_NOTIFY_FN Function
,
492 OUT VOID
**Registration
496 Locates the requested handle(s) and returns them in Buffer.
498 @param SearchType The type of search to perform to locate the
500 @param Protocol The protocol to search for
501 @param SearchKey Dependant on SearchType
502 @param BufferSize On input the size of Buffer. On output the
503 size of data returned.
504 @param Buffer The buffer to return the results in
506 @retval EFI_BUFFER_TOO_SMALL Buffer too small, required buffer size is
507 returned in BufferSize.
508 @retval EFI_INVALID_PARAMETER Invalid parameter
509 @retval EFI_SUCCESS Successfully found the requested handle(s) and
510 returns them in Buffer.
516 IN EFI_LOCATE_SEARCH_TYPE SearchType
,
517 IN EFI_GUID
*Protocol OPTIONAL
,
518 IN VOID
*SearchKey OPTIONAL
,
519 IN OUT UINTN
*BufferSize
,
520 OUT EFI_HANDLE
*Buffer
524 Return the first Protocol Interface that matches the Protocol GUID. If
525 Registration is pasased in return a Protocol Instance that was just add
526 to the system. If Retistration is NULL return the first Protocol Interface
529 @param Protocol The protocol to search for
530 @param Registration Optional Registration Key returned from
531 RegisterProtocolNotify()
532 @param Interface Return the Protocol interface (instance).
534 @retval EFI_SUCCESS If a valid Interface is returned
535 @retval EFI_INVALID_PARAMETER Invalid parameter
536 @retval EFI_NOT_FOUND Protocol interface not found
542 IN EFI_GUID
*Protocol
,
543 IN VOID
*Registration OPTIONAL
,
548 Manage MMI of a particular type.
550 @param HandlerType Points to the handler type or NULL for root MMI handlers.
551 @param Context Points to an optional context buffer.
552 @param CommBuffer Points to the optional communication buffer.
553 @param CommBufferSize Points to the size of the optional communication buffer.
555 @retval EFI_SUCCESS Interrupt source was processed successfully but not quiesced.
556 @retval EFI_INTERRUPT_PENDING One or more MMI sources could not be quiesced.
557 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING Interrupt source was not handled or quiesced.
558 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED Interrupt source was handled and quiesced.
564 IN CONST EFI_GUID
*HandlerType
,
565 IN CONST VOID
*Context OPTIONAL
,
566 IN OUT VOID
*CommBuffer OPTIONAL
,
567 IN OUT UINTN
*CommBufferSize OPTIONAL
571 Registers a handler to execute within MM.
573 @param Handler Handler service funtion pointer.
574 @param HandlerType Points to the handler type or NULL for root MMI handlers.
575 @param DispatchHandle On return, contains a unique handle which can be used to later unregister the handler function.
577 @retval EFI_SUCCESS Handler register success.
578 @retval EFI_INVALID_PARAMETER Handler or DispatchHandle is NULL.
584 IN EFI_MM_HANDLER_ENTRY_POINT Handler
,
585 IN CONST EFI_GUID
*HandlerType OPTIONAL
,
586 OUT EFI_HANDLE
*DispatchHandle
590 Unregister a handler in MM.
592 @param DispatchHandle The handle that was specified when the handler was registered.
594 @retval EFI_SUCCESS Handler function was successfully unregistered.
595 @retval EFI_INVALID_PARAMETER DispatchHandle does not refer to a valid handle.
600 MmiHandlerUnRegister (
601 IN EFI_HANDLE DispatchHandle
605 This function is the main entry point for an MM handler dispatch
606 or communicate-based callback.
608 @param DispatchHandle The unique handle assigned to this handler by MmiHandlerRegister().
609 @param Context Points to an optional handler context which was specified when the handler was registered.
610 @param CommBuffer A pointer to a collection of data in memory that will
611 be conveyed from a non-MM environment into an MM environment.
612 @param CommBufferSize The size of the CommBuffer.
619 MmDriverDispatchHandler (
620 IN EFI_HANDLE DispatchHandle
,
621 IN CONST VOID
*Context
, OPTIONAL
622 IN OUT VOID
*CommBuffer
, OPTIONAL
623 IN OUT UINTN
*CommBufferSize OPTIONAL
627 This function is the main entry point for an MM handler dispatch
628 or communicate-based callback.
630 @param DispatchHandle The unique handle assigned to this handler by MmiHandlerRegister().
631 @param Context Points to an optional handler context which was specified when the handler was registered.
632 @param CommBuffer A pointer to a collection of data in memory that will
633 be conveyed from a non-MM environment into an MM environment.
634 @param CommBufferSize The size of the CommBuffer.
641 MmFvDispatchHandler (
642 IN EFI_HANDLE DispatchHandle
,
643 IN CONST VOID
*Context
, OPTIONAL
644 IN OUT VOID
*CommBuffer
, OPTIONAL
645 IN OUT UINTN
*CommBufferSize OPTIONAL
649 This function is the main entry point for an MM handler dispatch
650 or communicate-based callback.
652 @param DispatchHandle The unique handle assigned to this handler by MmiHandlerRegister().
653 @param Context Points to an optional handler context which was specified when the handler was registered.
654 @param CommBuffer A pointer to a collection of data in memory that will
655 be conveyed from a non-MM environment into an MM environment.
656 @param CommBufferSize The size of the CommBuffer.
663 MmLegacyBootHandler (
664 IN EFI_HANDLE DispatchHandle
,
665 IN CONST VOID
*Context
, OPTIONAL
666 IN OUT VOID
*CommBuffer
, OPTIONAL
667 IN OUT UINTN
*CommBufferSize OPTIONAL
671 This function is the main entry point for an MM handler dispatch
672 or communicate-based callback.
674 @param DispatchHandle The unique handle assigned to this handler by MmiHandlerRegister().
675 @param Context Points to an optional handler context which was specified when the handler was registered.
676 @param CommBuffer A pointer to a collection of data in memory that will
677 be conveyed from a non-MM environment into an MM environment.
678 @param CommBufferSize The size of the CommBuffer.
685 MmExitBootServiceHandler (
686 IN EFI_HANDLE DispatchHandle
,
687 IN CONST VOID
*Context
, OPTIONAL
688 IN OUT VOID
*CommBuffer
, OPTIONAL
689 IN OUT UINTN
*CommBufferSize OPTIONAL
693 This function is the main entry point for an MM handler dispatch
694 or communicate-based callback.
696 @param DispatchHandle The unique handle assigned to this handler by MmiHandlerRegister().
697 @param Context Points to an optional handler context which was specified when the handler was registered.
698 @param CommBuffer A pointer to a collection of data in memory that will
699 be conveyed from a non-MM environment into an MM environment.
700 @param CommBufferSize The size of the CommBuffer.
707 MmReadyToBootHandler (
708 IN EFI_HANDLE DispatchHandle
,
709 IN CONST VOID
*Context
, OPTIONAL
710 IN OUT VOID
*CommBuffer
, OPTIONAL
711 IN OUT UINTN
*CommBufferSize OPTIONAL
715 This function is the main entry point for an MM handler dispatch
716 or communicate-based callback.
718 @param DispatchHandle The unique handle assigned to this handler by MmiHandlerRegister().
719 @param Context Points to an optional handler context which was specified when the handler was registered.
720 @param CommBuffer A pointer to a collection of data in memory that will
721 be conveyed from a non-MM environment into an MM environment.
722 @param CommBufferSize The size of the CommBuffer.
729 MmReadyToLockHandler (
730 IN EFI_HANDLE DispatchHandle
,
731 IN CONST VOID
*Context
, OPTIONAL
732 IN OUT VOID
*CommBuffer
, OPTIONAL
733 IN OUT UINTN
*CommBufferSize OPTIONAL
737 This function is the main entry point for an MM handler dispatch
738 or communicate-based callback.
740 @param DispatchHandle The unique handle assigned to this handler by MmiHandlerRegister().
741 @param Context Points to an optional handler context which was specified when the handler was registered.
742 @param CommBuffer A pointer to a collection of data in memory that will
743 be conveyed from a non-MM environment into an MM environment.
744 @param CommBufferSize The size of the CommBuffer.
752 IN EFI_HANDLE DispatchHandle
,
753 IN CONST VOID
*Context
, OPTIONAL
754 IN OUT VOID
*CommBuffer
, OPTIONAL
755 IN OUT UINTN
*CommBufferSize OPTIONAL
759 Place holder function until all the MM System Table Service are available.
761 @param Arg1 Undefined
762 @param Arg2 Undefined
763 @param Arg3 Undefined
764 @param Arg4 Undefined
765 @param Arg5 Undefined
767 @return EFI_NOT_AVAILABLE_YET
772 MmEfiNotAvailableYetArg5 (
781 //Functions used during debug buils
785 Traverse the discovered list for any drivers that were discovered but not loaded
786 because the dependency expressions evaluated to false.
790 MmDisplayDiscoveredNotDispatched (
795 Add free MMRAM region for use by memory service.
797 @param MemBase Base address of memory region.
798 @param MemLength Length of the memory region.
799 @param Type Memory type.
800 @param Attributes Memory region state.
805 IN EFI_PHYSICAL_ADDRESS MemBase
,
807 IN EFI_MEMORY_TYPE Type
,
812 Finds the protocol entry for the requested protocol.
814 @param Protocol The ID of the protocol
815 @param Create Create a new entry if not found
817 @return Protocol entry
821 MmFindProtocolEntry (
822 IN EFI_GUID
*Protocol
,
827 Signal event for every protocol in protocol entry.
829 @param Prot Protocol interface
834 IN PROTOCOL_INTERFACE
*Prot
838 Finds the protocol instance for the requested handle and protocol.
839 Note: This function doesn't do parameters checking, it's caller's responsibility
840 to pass in valid parameters.
842 @param Handle The handle to search the protocol on
843 @param Protocol GUID of the protocol
844 @param Interface The interface for the protocol being searched
846 @return Protocol instance (NULL: Not found)
850 MmFindProtocolInterface (
852 IN EFI_GUID
*Protocol
,
857 Removes Protocol from the protocol list (but not the handle list).
859 @param Handle The handle to remove protocol on.
860 @param Protocol GUID of the protocol to be moved
861 @param Interface The interface of the protocol
863 @return Protocol Entry
867 MmRemoveInterfaceFromProtocol (
869 IN EFI_GUID
*Protocol
,
874 This is the POSTFIX version of the dependency evaluator. This code does
875 not need to handle Before or After, as it is not valid to call this
876 routine in this case. POSTFIX means all the math is done on top of the stack.
878 @param DriverEntry DriverEntry element to update.
880 @retval TRUE If driver is ready to run.
881 @retval FALSE If driver is not ready to run or some fatal error
887 IN EFI_MM_DRIVER_ENTRY
*DriverEntry
891 Dump MMRAM information.
899 extern UINTN mMmramRangeCount
;
900 extern EFI_MMRAM_DESCRIPTOR
*mMmramRanges
;
901 extern EFI_SYSTEM_TABLE
*mEfiSystemTable
;