1 /** @file
2   The internal header file includes the common header files, defines
3   internal structure and functions used by MmCore module.
4 
5   Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
6   Copyright (c) 2016 - 2021, Arm Limited. All rights reserved.<BR>
7 
8   SPDX-License-Identifier: BSD-2-Clause-Patent
9 
10 **/
11 
12 #ifndef _MM_CORE_H_
13 #define _MM_CORE_H_
14 
15 #include <PiMm.h>
16 #include <StandaloneMm.h>
17 
18 #include <Protocol/DxeMmReadyToLock.h>
19 #include <Protocol/MmReadyToLock.h>
20 #include <Protocol/MmEndOfDxe.h>
21 #include <Protocol/MmCommunication2.h>
22 #include <Protocol/LoadedImage.h>
23 #include <Protocol/MmConfiguration.h>
24 
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>
33 
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>
43 
44 #include <Library/StandaloneMmMemLib.h>
45 #include <Library/HobLib.h>
46 
47 #include "StandaloneMmCorePrivateData.h"
48 
49 //
50 // Used to build a table of MMI Handlers that the MM Core registers
51 //
52 typedef struct {
53   EFI_MM_HANDLER_ENTRY_POINT    Handler;
54   EFI_GUID                      *HandlerType;
55   EFI_HANDLE                    DispatchHandle;
56   BOOLEAN                       UnRegister;
57 } MM_CORE_MMI_HANDLERS;
58 
59 //
60 // Structure for recording the state of an MM Driver
61 //
62 #define EFI_MM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v')
63 
64 typedef struct {
65   UINTN                           Signature;
66   LIST_ENTRY                      Link;             // mDriverList
67 
68   LIST_ENTRY                      ScheduledLink;    // mScheduledQueue
69 
70   EFI_FIRMWARE_VOLUME_HEADER      *FwVolHeader;
71   EFI_GUID                        FileName;
72   VOID                            *Pe32Data;
73   UINTN                           Pe32DataSize;
74 
75   VOID                            *Depex;
76   UINTN                           DepexSize;
77 
78   BOOLEAN                         Before;
79   BOOLEAN                         After;
80   EFI_GUID                        BeforeAfterGuid;
81 
82   BOOLEAN                         Dependent;
83   BOOLEAN                         Scheduled;
84   BOOLEAN                         Initialized;
85   BOOLEAN                         DepexProtocolError;
86 
87   EFI_HANDLE                      ImageHandle;
88   EFI_LOADED_IMAGE_PROTOCOL       *LoadedImage;
89   //
90   // Image EntryPoint in MMRAM
91   //
92   PHYSICAL_ADDRESS                ImageEntryPoint;
93   //
94   // Image Buffer in MMRAM
95   //
96   PHYSICAL_ADDRESS                ImageBuffer;
97   //
98   // Image Page Number
99   //
100   UINTN                           NumberOfPage;
101 } EFI_MM_DRIVER_ENTRY;
102 
103 #define EFI_HANDLE_SIGNATURE            SIGNATURE_32('h','n','d','l')
104 
105 ///
106 /// IHANDLE - contains a list of protocol handles
107 ///
108 typedef struct {
109   UINTN               Signature;
110   /// All handles list of IHANDLE
111   LIST_ENTRY          AllHandles;
112   /// List of PROTOCOL_INTERFACE's for this handle
113   LIST_ENTRY          Protocols;
114   UINTN               LocateRequest;
115 } IHANDLE;
116 
117 #define ASSERT_IS_HANDLE(a)  ASSERT((a)->Signature == EFI_HANDLE_SIGNATURE)
118 
119 #define PROTOCOL_ENTRY_SIGNATURE        SIGNATURE_32('p','r','t','e')
120 
121 ///
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.
125 ///
126 typedef struct {
127   UINTN               Signature;
128   /// Link Entry inserted to mProtocolDatabase
129   LIST_ENTRY          AllEntries;
130   /// ID of the protocol
131   EFI_GUID            ProtocolID;
132   /// All protocol interfaces
133   LIST_ENTRY          Protocols;
134   /// Registered notification handlers
135   LIST_ENTRY          Notify;
136 } PROTOCOL_ENTRY;
137 
138 #define PROTOCOL_INTERFACE_SIGNATURE  SIGNATURE_32('p','i','f','c')
139 
140 ///
141 /// PROTOCOL_INTERFACE - each protocol installed on a handle is tracked
142 /// with a protocol interface structure
143 ///
144 typedef struct {
145   UINTN                       Signature;
146   /// Link on IHANDLE.Protocols
147   LIST_ENTRY                  Link;
148   /// Back pointer
149   IHANDLE                     *Handle;
150   /// Link on PROTOCOL_ENTRY.Protocols
151   LIST_ENTRY                  ByProtocol;
152   /// The protocol ID
153   PROTOCOL_ENTRY              *Protocol;
154   /// The interface value
155   VOID                        *Interface;
156 } PROTOCOL_INTERFACE;
157 
158 #define PROTOCOL_NOTIFY_SIGNATURE       SIGNATURE_32('p','r','t','n')
159 
160 ///
161 /// PROTOCOL_NOTIFY - used for each register notification for a protocol
162 ///
163 typedef struct {
164   UINTN               Signature;
165   PROTOCOL_ENTRY      *Protocol;
166   /// All notifications for this protocol
167   LIST_ENTRY          Link;
168   /// Notification function
169   EFI_MM_NOTIFY_FN   Function;
170   /// Last position notified
171   LIST_ENTRY          *Position;
172 } PROTOCOL_NOTIFY;
173 
174 //
175 // MM Core Global Variables
176 //
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;
181 
182 /**
183   Called to initialize the memory service.
184 
185   @param   MmramRangeCount       Number of MMRAM Regions
186   @param   MmramRanges           Pointer to MMRAM Descriptors
187 
188 **/
189 VOID
190 MmInitializeMemoryServices (
191   IN UINTN                 MmramRangeCount,
192   IN EFI_MMRAM_DESCRIPTOR  *MmramRanges
193   );
194 
195 /**
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.
200 
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.
205 
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.
210 
211 **/
212 EFI_STATUS
213 EFIAPI
214 MmInstallConfigurationTable (
215   IN  CONST EFI_MM_SYSTEM_TABLE  *SystemTable,
216   IN  CONST EFI_GUID              *Guid,
217   IN  VOID                        *Table,
218   IN  UINTN                       TableSize
219   );
220 
221 /**
222   Wrapper function to MmInstallProtocolInterfaceNotify.  This is the public API which
223   Calls the private one which contains a BOOLEAN parameter for notifications
224 
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
229                                  native form.
230   @param  Interface              The interface for the protocol being added
231 
232   @return Status code
233 
234 **/
235 EFI_STATUS
236 EFIAPI
237 MmInstallProtocolInterface (
238   IN OUT EFI_HANDLE     *UserHandle,
239   IN EFI_GUID           *Protocol,
240   IN EFI_INTERFACE_TYPE InterfaceType,
241   IN VOID               *Interface
242   );
243 
244 /**
245   Allocates pages from the memory map.
246 
247   @param  Type                   The type of allocation to perform
248   @param  MemoryType             The type of memory to turn the allocated pages
249                                  into
250   @param  NumberOfPages          The number of pages to allocate
251   @param  Memory                 A pointer to receive the base allocated memory
252                                  address
253 
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.
258 
259 **/
260 EFI_STATUS
261 EFIAPI
262 MmAllocatePages (
263   IN      EFI_ALLOCATE_TYPE         Type,
264   IN      EFI_MEMORY_TYPE           MemoryType,
265   IN      UINTN                     NumberOfPages,
266   OUT     EFI_PHYSICAL_ADDRESS      *Memory
267   );
268 
269 /**
270   Allocates pages from the memory map.
271 
272   @param  Type                   The type of allocation to perform
273   @param  MemoryType             The type of memory to turn the allocated pages
274                                  into
275   @param  NumberOfPages          The number of pages to allocate
276   @param  Memory                 A pointer to receive the base allocated memory
277                                  address
278 
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.
283 
284 **/
285 EFI_STATUS
286 EFIAPI
287 MmInternalAllocatePages (
288   IN      EFI_ALLOCATE_TYPE         Type,
289   IN      EFI_MEMORY_TYPE           MemoryType,
290   IN      UINTN                     NumberOfPages,
291   OUT     EFI_PHYSICAL_ADDRESS      *Memory
292   );
293 
294 /**
295   Frees previous allocated pages.
296 
297   @param  Memory                 Base address of memory being freed
298   @param  NumberOfPages          The number of pages to free
299 
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.
303 
304 **/
305 EFI_STATUS
306 EFIAPI
307 MmFreePages (
308   IN      EFI_PHYSICAL_ADDRESS      Memory,
309   IN      UINTN                     NumberOfPages
310   );
311 
312 /**
313   Frees previous allocated pages.
314 
315   @param  Memory                 Base address of memory being freed
316   @param  NumberOfPages          The number of pages to free
317 
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.
321 
322 **/
323 EFI_STATUS
324 EFIAPI
325 MmInternalFreePages (
326   IN      EFI_PHYSICAL_ADDRESS      Memory,
327   IN      UINTN                     NumberOfPages
328   );
329 
330 /**
331   Allocate pool of a particular type.
332 
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
336                                  pool
337 
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.
341 
342 **/
343 EFI_STATUS
344 EFIAPI
345 MmAllocatePool (
346   IN      EFI_MEMORY_TYPE           PoolType,
347   IN      UINTN                     Size,
348   OUT     VOID                      **Buffer
349   );
350 
351 /**
352   Allocate pool of a particular type.
353 
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
357                                  pool
358 
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.
362 
363 **/
364 EFI_STATUS
365 EFIAPI
366 MmInternalAllocatePool (
367   IN      EFI_MEMORY_TYPE           PoolType,
368   IN      UINTN                     Size,
369   OUT     VOID                      **Buffer
370   );
371 
372 /**
373   Frees pool.
374 
375   @param  Buffer                 The allocated pool entry to free
376 
377   @retval EFI_INVALID_PARAMETER  Buffer is not a valid value.
378   @retval EFI_SUCCESS            Pool successfully freed.
379 
380 **/
381 EFI_STATUS
382 EFIAPI
383 MmFreePool (
384   IN      VOID                      *Buffer
385   );
386 
387 /**
388   Frees pool.
389 
390   @param  Buffer                 The allocated pool entry to free
391 
392   @retval EFI_INVALID_PARAMETER  Buffer is not a valid value.
393   @retval EFI_SUCCESS            Pool successfully freed.
394 
395 **/
396 EFI_STATUS
397 EFIAPI
398 MmInternalFreePool (
399   IN      VOID                      *Buffer
400   );
401 
402 /**
403   Installs a protocol interface into the boot services environment.
404 
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
409                                  native form.
410   @param  Interface              The interface for the protocol being added
411   @param  Notify                 indicates whether notify the notification list
412                                  for this protocol
413 
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
417 
418 **/
419 EFI_STATUS
420 MmInstallProtocolInterfaceNotify (
421   IN OUT EFI_HANDLE     *UserHandle,
422   IN EFI_GUID           *Protocol,
423   IN EFI_INTERFACE_TYPE InterfaceType,
424   IN VOID               *Interface,
425   IN BOOLEAN            Notify
426   );
427 
428 /**
429   Uninstalls all instances of a protocol:interfacer from a handle.
430   If the last protocol interface is remove from the handle, the
431   handle is freed.
432 
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
436 
437   @retval EFI_INVALID_PARAMETER  Protocol is NULL.
438   @retval EFI_SUCCESS            Protocol interface successfully uninstalled.
439 
440 **/
441 EFI_STATUS
442 EFIAPI
443 MmUninstallProtocolInterface (
444   IN EFI_HANDLE       UserHandle,
445   IN EFI_GUID         *Protocol,
446   IN VOID             *Interface
447   );
448 
449 /**
450   Queries a handle to determine if it supports a specified protocol.
451 
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.
456 
457   @return The requested protocol interface for the handle
458 
459 **/
460 EFI_STATUS
461 EFIAPI
462 MmHandleProtocol (
463   IN EFI_HANDLE       UserHandle,
464   IN EFI_GUID         *Protocol,
465   OUT VOID            **Interface
466   );
467 
468 /**
469   Add a new protocol notification record for the request protocol.
470 
471   @param  Protocol               The requested protocol to add the notify
472                                  registration
473   @param  Function               Points to the notification function
474   @param  Registration           Returns the registration record
475 
476   @retval EFI_INVALID_PARAMETER  Invalid parameter
477   @retval EFI_SUCCESS            Successfully returned the registration record
478                                  that has been added
479 
480 **/
481 EFI_STATUS
482 EFIAPI
483 MmRegisterProtocolNotify (
484   IN  CONST EFI_GUID              *Protocol,
485   IN  EFI_MM_NOTIFY_FN           Function,
486   OUT VOID                        **Registration
487   );
488 
489 /**
490   Locates the requested handle(s) and returns them in Buffer.
491 
492   @param  SearchType             The type of search to perform to locate the
493                                  handles
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
499 
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.
505 
506 **/
507 EFI_STATUS
508 EFIAPI
509 MmLocateHandle (
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
515   );
516 
517 /**
518   Return the first Protocol Interface that matches the Protocol GUID. If
519   Registration is passed in return a Protocol Instance that was just add
520   to the system. If Registration is NULL return the first Protocol Interface
521   you find.
522 
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).
527 
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
531 
532 **/
533 EFI_STATUS
534 EFIAPI
535 MmLocateProtocol (
536   IN  EFI_GUID  *Protocol,
537   IN  VOID      *Registration OPTIONAL,
538   OUT VOID      **Interface
539   );
540 
541 /**
542   Manage MMI of a particular type.
543 
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.
548 
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.
553 
554 **/
555 EFI_STATUS
556 EFIAPI
557 MmiManage (
558   IN     CONST EFI_GUID           *HandlerType,
559   IN     CONST VOID               *Context         OPTIONAL,
560   IN OUT VOID                     *CommBuffer      OPTIONAL,
561   IN OUT UINTN                    *CommBufferSize  OPTIONAL
562   );
563 
564 /**
565   Registers a handler to execute within MM.
566 
567   @param  Handler        Handler service function 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.
570 
571   @retval EFI_SUCCESS           Handler register success.
572   @retval EFI_INVALID_PARAMETER Handler or DispatchHandle is NULL.
573 
574 **/
575 EFI_STATUS
576 EFIAPI
577 MmiHandlerRegister (
578   IN   EFI_MM_HANDLER_ENTRY_POINT     Handler,
579   IN   CONST EFI_GUID                 *HandlerType  OPTIONAL,
580   OUT  EFI_HANDLE                     *DispatchHandle
581   );
582 
583 /**
584   Unregister a handler in MM.
585 
586   @param  DispatchHandle  The handle that was specified when the handler was registered.
587 
588   @retval EFI_SUCCESS           Handler function was successfully unregistered.
589   @retval EFI_INVALID_PARAMETER DispatchHandle does not refer to a valid handle.
590 
591 **/
592 EFI_STATUS
593 EFIAPI
594 MmiHandlerUnRegister (
595   IN  EFI_HANDLE                      DispatchHandle
596   );
597 
598 /**
599   This function is the main entry point for an MM handler dispatch
600   or communicate-based callback.
601 
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.
607 
608   @return Status Code
609 
610 **/
611 EFI_STATUS
612 EFIAPI
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
618   );
619 
620 /**
621   This function is the main entry point for an MM handler dispatch
622   or communicate-based callback.
623 
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.
629 
630   @return Status Code
631 
632 **/
633 EFI_STATUS
634 EFIAPI
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
640   );
641 
642 /**
643   This function is the main entry point for an MM handler dispatch
644   or communicate-based callback.
645 
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.
651 
652   @return Status Code
653 
654 **/
655 EFI_STATUS
656 EFIAPI
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
662   );
663 
664 /**
665   This function is the main entry point for an MM handler dispatch
666   or communicate-based callback.
667 
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.
673 
674   @return Status Code
675 
676 **/
677 EFI_STATUS
678 EFIAPI
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
684   );
685 
686 /**
687   This function is the main entry point for an MM handler dispatch
688   or communicate-based callback.
689 
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.
695 
696   @return Status Code
697 
698 **/
699 EFI_STATUS
700 EFIAPI
701 MmEndOfDxeHandler (
702   IN     EFI_HANDLE               DispatchHandle,
703   IN     CONST VOID               *Context,        OPTIONAL
704   IN OUT VOID                     *CommBuffer,     OPTIONAL
705   IN OUT UINTN                    *CommBufferSize  OPTIONAL
706   );
707 
708 /**
709   Place holder function until all the MM System Table Service are available.
710 
711   @param  Arg1                   Undefined
712   @param  Arg2                   Undefined
713   @param  Arg3                   Undefined
714   @param  Arg4                   Undefined
715   @param  Arg5                   Undefined
716 
717   @return EFI_NOT_AVAILABLE_YET
718 
719 **/
720 EFI_STATUS
721 EFIAPI
722 MmEfiNotAvailableYetArg5 (
723   UINTN Arg1,
724   UINTN Arg2,
725   UINTN Arg3,
726   UINTN Arg4,
727   UINTN Arg5
728   );
729 
730 //
731 //Functions used during debug builds
732 //
733 
734 /**
735   Traverse the discovered list for any drivers that were discovered but not loaded
736   because the dependency expressions evaluated to false.
737 
738 **/
739 VOID
740 MmDisplayDiscoveredNotDispatched (
741   VOID
742   );
743 
744 /**
745   Add free MMRAM region for use by memory service.
746 
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.
751 
752 **/
753 VOID
754 MmAddMemoryRegion (
755   IN      EFI_PHYSICAL_ADDRESS      MemBase,
756   IN      UINT64                    MemLength,
757   IN      EFI_MEMORY_TYPE           Type,
758   IN      UINT64                    Attributes
759   );
760 
761 /**
762   Finds the protocol entry for the requested protocol.
763 
764   @param  Protocol               The ID of the protocol
765   @param  Create                 Create a new entry if not found
766 
767   @return Protocol entry
768 
769 **/
770 PROTOCOL_ENTRY  *
771 MmFindProtocolEntry (
772   IN EFI_GUID   *Protocol,
773   IN BOOLEAN    Create
774   );
775 
776 /**
777   Signal event for every protocol in protocol entry.
778 
779   @param  Prot                   Protocol interface
780 
781 **/
782 VOID
783 MmNotifyProtocol (
784   IN PROTOCOL_INTERFACE   *Prot
785   );
786 
787 /**
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.
791 
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
795 
796   @return Protocol instance (NULL: Not found)
797 
798 **/
799 PROTOCOL_INTERFACE *
800 MmFindProtocolInterface (
801   IN IHANDLE        *Handle,
802   IN EFI_GUID       *Protocol,
803   IN VOID           *Interface
804   );
805 
806 /**
807   Removes Protocol from the protocol list (but not the handle list).
808 
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
812 
813   @return Protocol Entry
814 
815 **/
816 PROTOCOL_INTERFACE *
817 MmRemoveInterfaceFromProtocol (
818   IN IHANDLE        *Handle,
819   IN EFI_GUID       *Protocol,
820   IN VOID           *Interface
821   );
822 
823 /**
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.
827 
828   @param  DriverEntry           DriverEntry element to update.
829 
830   @retval TRUE                  If driver is ready to run.
831   @retval FALSE                 If driver is not ready to run or some fatal error
832                                 was found.
833 
834 **/
835 BOOLEAN
836 MmIsSchedulable (
837   IN  EFI_MM_DRIVER_ENTRY   *DriverEntry
838   );
839 
840 /**
841   Dump MMRAM information.
842 
843 **/
844 VOID
845 DumpMmramInfo (
846   VOID
847   );
848 
849 extern UINTN                    mMmramRangeCount;
850 extern EFI_MMRAM_DESCRIPTOR     *mMmramRanges;
851 extern EFI_SYSTEM_TABLE         *mEfiSystemTable;
852 
853 #endif
854