]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
MdeModulePkg/S3SmmInitDone.h: Fix copyright coding style error.
[mirror_edk2.git] / MdeModulePkg / Core / PiSmmCore / PiSmmCore.h
index 5cd123705600b0e5ad67add6a3c058ae7ec42f52..2d3447e338b1099d1d18c1795060fcb138594254 100644 (file)
@@ -2,14 +2,14 @@
   The internal header file includes the common header files, defines\r
   internal structure and functions used by SmmCore module.\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials are licensed and made available \r
-  under the terms and conditions of the BSD License which accompanies this \r
-  distribution.  The full text of the license may be found at        \r
-  http://opensource.org/licenses/bsd-license.php                                            \r
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available\r
+  under the terms and conditions of the BSD License which accompanies this\r
+  distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
 \r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 **/\r
 \r
 \r
 #include <Protocol/DxeSmmReadyToLock.h>\r
 #include <Protocol/SmmReadyToLock.h>\r
+#include <Protocol/SmmEndOfDxe.h>\r
 #include <Protocol/CpuIo2.h>\r
 #include <Protocol/SmmCommunication.h>\r
 #include <Protocol/SmmAccess2.h>\r
-#include <Protocol/FirmwareVolume2.h>   \r
-#include <Protocol/LoadedImage.h>       \r
-#include <Protocol/DevicePath.h>        \r
-#include <Protocol/Security.h>          \r
+#include <Protocol/FirmwareVolume2.h>\r
+#include <Protocol/LoadedImage.h>\r
+#include <Protocol/DevicePath.h>\r
+#include <Protocol/Security.h>\r
+#include <Protocol/Security2.h>\r
+#include <Protocol/SmmExitBootServices.h>\r
+#include <Protocol/SmmLegacyBoot.h>\r
+#include <Protocol/SmmReadyToBoot.h>\r
+#include <Protocol/SmmMemoryAttribute.h>\r
+#include <Protocol/SmmSxDispatch2.h>\r
 \r
 #include <Guid/Apriori.h>\r
 #include <Guid/EventGroup.h>\r
 #include <Guid/EventLegacyBios.h>\r
+#include <Guid/MemoryProfile.h>\r
+#include <Guid/LoadModuleAtFixedAddress.h>\r
+#include <Guid/SmiHandlerProfile.h>\r
+#include <Guid/EndOfS3Resume.h>\r
+#include <Guid/S3SmmInitDone.h>\r
 \r
 #include <Library/BaseLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/PeCoffLib.h>\r
+#include <Library/PeCoffGetEntryPointLib.h>\r
 #include <Library/CacheMaintenanceLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/ReportStatusCodeLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
-#include <Library/DevicePathLib.h>             \r
-#include <Library/UefiLib.h>                   \r
+#include <Library/DevicePathLib.h>\r
+#include <Library/UefiLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/PcdLib.h>\r
+#include <Library/SmmCorePlatformHookLib.h>\r
+#include <Library/PerformanceLib.h>\r
+#include <Library/TimerLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/SmmMemLib.h>\r
 \r
 #include "PiSmmCorePrivateData.h"\r
+#include "HeapGuard.h"\r
 \r
 //\r
 // Used to build a table of SMI Handlers that the SMM Core registers\r
@@ -56,6 +75,32 @@ typedef struct {
   BOOLEAN                       UnRegister;\r
 } SMM_CORE_SMI_HANDLERS;\r
 \r
+//\r
+// SMM_HANDLER - used for each SMM handler\r
+//\r
+\r
+#define SMI_ENTRY_SIGNATURE  SIGNATURE_32('s','m','i','e')\r
+\r
+ typedef struct {\r
+  UINTN       Signature;\r
+  LIST_ENTRY  AllEntries;  // All entries\r
+\r
+  EFI_GUID    HandlerType; // Type of interrupt\r
+  LIST_ENTRY  SmiHandlers; // All handlers\r
+} SMI_ENTRY;\r
+\r
+#define SMI_HANDLER_SIGNATURE  SIGNATURE_32('s','m','i','h')\r
+\r
+ typedef struct {\r
+  UINTN                         Signature;\r
+  LIST_ENTRY                    Link;        // Link on SMI_ENTRY.SmiHandlers\r
+  EFI_SMM_HANDLER_ENTRY_POINT2  Handler;     // The smm handler's entry point\r
+  UINTN                         CallerAddr;  // The address of caller who register the SMI handler.\r
+  SMI_ENTRY                     *SmiEntry;\r
+  VOID                          *Context;    // for profile\r
+  UINTN                         ContextSize; // for profile\r
+} SMI_HANDLER;\r
+\r
 //\r
 // Structure for recording the state of an SMM Driver\r
 //\r
@@ -91,13 +136,15 @@ typedef struct {
   //\r
   PHYSICAL_ADDRESS                ImageEntryPoint;\r
   //\r
-  // Image Buffer in SMRAM  \r
+  // Image Buffer in SMRAM\r
   //\r
   PHYSICAL_ADDRESS                ImageBuffer;\r
   //\r
   // Image Page Number\r
   //\r
   UINTN                           NumberOfPage;\r
+  EFI_HANDLE                      SmmImageHandle;\r
+  EFI_LOADED_IMAGE_PROTOCOL       SmmLoadedImage;\r
 } EFI_SMM_DRIVER_ENTRY;\r
 \r
 #define EFI_HANDLE_SIGNATURE            SIGNATURE_32('h','n','d','l')\r
@@ -266,6 +313,33 @@ SmmAllocatePages (
   OUT     EFI_PHYSICAL_ADDRESS      *Memory\r
   );\r
 \r
+/**\r
+  Allocates pages from the memory map.\r
+\r
+  @param  Type                   The type of allocation to perform\r
+  @param  MemoryType             The type of memory to turn the allocated pages\r
+                                 into\r
+  @param  NumberOfPages          The number of pages to allocate\r
+  @param  Memory                 A pointer to receive the base allocated memory\r
+                                 address\r
+  @param  NeedGuard              Flag to indicate Guard page is needed or not\r
+\r
+  @retval EFI_INVALID_PARAMETER  Parameters violate checking rules defined in spec.\r
+  @retval EFI_NOT_FOUND          Could not allocate pages match the requirement.\r
+  @retval EFI_OUT_OF_RESOURCES   No enough pages to allocate.\r
+  @retval EFI_SUCCESS            Pages successfully allocated.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmInternalAllocatePages (\r
+  IN      EFI_ALLOCATE_TYPE         Type,\r
+  IN      EFI_MEMORY_TYPE           MemoryType,\r
+  IN      UINTN                     NumberOfPages,\r
+  OUT     EFI_PHYSICAL_ADDRESS      *Memory,\r
+  IN      BOOLEAN                   NeedGuard\r
+  );\r
+\r
 /**\r
   Frees previous allocated pages.\r
 \r
@@ -273,7 +347,7 @@ SmmAllocatePages (
   @param  NumberOfPages          The number of pages to free\r
 \r
   @retval EFI_NOT_FOUND          Could not find the entry that covers the range\r
-  @retval EFI_INVALID_PARAMETER  Address not aligned\r
+  @retval EFI_INVALID_PARAMETER  Address not aligned, Address is zero or NumberOfPages is zero.\r
   @return EFI_SUCCESS            Pages successfully freed.\r
 \r
 **/\r
@@ -284,6 +358,27 @@ SmmFreePages (
   IN      UINTN                     NumberOfPages\r
   );\r
 \r
+/**\r
+  Frees previous allocated pages.\r
+\r
+  @param  Memory                 Base address of memory being freed\r
+  @param  NumberOfPages          The number of pages to free\r
+  @param  IsGuarded              Flag to indicate if the memory is guarded\r
+                                 or not\r
+\r
+  @retval EFI_NOT_FOUND          Could not find the entry that covers the range\r
+  @retval EFI_INVALID_PARAMETER  Address not aligned, Address is zero or NumberOfPages is zero.\r
+  @return EFI_SUCCESS            Pages successfully freed.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmInternalFreePages (\r
+  IN      EFI_PHYSICAL_ADDRESS      Memory,\r
+  IN      UINTN                     NumberOfPages,\r
+  IN      BOOLEAN                   IsGuarded\r
+  );\r
+\r
 /**\r
   Allocate pool of a particular type.\r
 \r
@@ -305,6 +400,27 @@ SmmAllocatePool (
   OUT     VOID                      **Buffer\r
   );\r
 \r
+/**\r
+  Allocate pool of a particular type.\r
+\r
+  @param  PoolType               Type of pool to allocate\r
+  @param  Size                   The amount of pool to allocate\r
+  @param  Buffer                 The address to return a pointer to the allocated\r
+                                 pool\r
+\r
+  @retval EFI_INVALID_PARAMETER  PoolType not valid\r
+  @retval EFI_OUT_OF_RESOURCES   Size exceeds max pool size or allocation failed.\r
+  @retval EFI_SUCCESS            Pool successfully allocated.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmInternalAllocatePool (\r
+  IN      EFI_MEMORY_TYPE           PoolType,\r
+  IN      UINTN                     Size,\r
+  OUT     VOID                      **Buffer\r
+  );\r
+\r
 /**\r
   Frees pool.\r
 \r
@@ -320,6 +436,21 @@ SmmFreePool (
   IN      VOID                      *Buffer\r
   );\r
 \r
+/**\r
+  Frees pool.\r
+\r
+  @param  Buffer                 The allocated pool entry to free\r
+\r
+  @retval EFI_INVALID_PARAMETER  Buffer is not a valid value.\r
+  @retval EFI_SUCCESS            Pool successfully freed.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmInternalFreePool (\r
+  IN      VOID                      *Buffer\r
+  );\r
+\r
 /**\r
   Installs a protocol interface into the boot services environment.\r
 \r
@@ -459,6 +590,38 @@ SmmLocateProtocol (
   OUT VOID      **Interface\r
   );\r
 \r
+/**\r
+  Function returns an array of handles that support the requested protocol\r
+  in a buffer allocated from pool. This is a version of SmmLocateHandle()\r
+  that allocates a buffer for the caller.\r
+\r
+  @param  SearchType             Specifies which handle(s) are to be returned.\r
+  @param  Protocol               Provides the protocol to search by.    This\r
+                                 parameter is only valid for SearchType\r
+                                 ByProtocol.\r
+  @param  SearchKey              Supplies the search key depending on the\r
+                                 SearchType.\r
+  @param  NumberHandles          The number of handles returned in Buffer.\r
+  @param  Buffer                 A pointer to the buffer to return the requested\r
+                                 array of  handles that support Protocol.\r
+\r
+  @retval EFI_SUCCESS            The result array of handles was returned.\r
+  @retval EFI_NOT_FOUND          No handles match the search.\r
+  @retval EFI_OUT_OF_RESOURCES   There is not enough pool memory to store the\r
+                                 matching results.\r
+  @retval EFI_INVALID_PARAMETER  One or more paramters are not valid.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmLocateHandleBuffer (\r
+  IN     EFI_LOCATE_SEARCH_TYPE  SearchType,\r
+  IN     EFI_GUID                *Protocol OPTIONAL,\r
+  IN     VOID                    *SearchKey OPTIONAL,\r
+  IN OUT UINTN                   *NumberHandles,\r
+  OUT    EFI_HANDLE              **Buffer\r
+  );\r
+\r
 /**\r
   Manage SMI of a particular type.\r
 \r
@@ -582,6 +745,118 @@ SmmReadyToLockHandler (
   IN OUT UINTN                    *CommBufferSize  OPTIONAL\r
   );\r
 \r
+/**\r
+  This function is the main entry point for an SMM handler dispatch\r
+  or communicate-based callback.\r
+\r
+  @param  DispatchHandle  The unique handle assigned to this handler by SmiHandlerRegister().\r
+  @param  Context         Points to an optional handler context which was specified when the handler was registered.\r
+  @param  CommBuffer      A pointer to a collection of data in memory that will\r
+                          be conveyed from a non-SMM environment into an SMM environment.\r
+  @param  CommBufferSize  The size of the CommBuffer.\r
+\r
+  @return Status Code\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmEndOfDxeHandler (\r
+  IN     EFI_HANDLE               DispatchHandle,\r
+  IN     CONST VOID               *Context,        OPTIONAL\r
+  IN OUT VOID                     *CommBuffer,     OPTIONAL\r
+  IN OUT UINTN                    *CommBufferSize  OPTIONAL\r
+  );\r
+\r
+/**\r
+  This function is the main entry point for an SMM handler dispatch\r
+  or communicate-based callback.\r
+\r
+  @param  DispatchHandle  The unique handle assigned to this handler by SmiHandlerRegister().\r
+  @param  Context         Points to an optional handler context which was specified when the handler was registered.\r
+  @param  CommBuffer      A pointer to a collection of data in memory that will\r
+                          be conveyed from a non-SMM environment into an SMM environment.\r
+  @param  CommBufferSize  The size of the CommBuffer.\r
+\r
+  @return Status Code\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmExitBootServicesHandler (\r
+  IN     EFI_HANDLE               DispatchHandle,\r
+  IN     CONST VOID               *Context,        OPTIONAL\r
+  IN OUT VOID                     *CommBuffer,     OPTIONAL\r
+  IN OUT UINTN                    *CommBufferSize  OPTIONAL\r
+  );\r
+\r
+/**\r
+  This function is the main entry point for an SMM handler dispatch\r
+  or communicate-based callback.\r
+\r
+  @param  DispatchHandle  The unique handle assigned to this handler by SmiHandlerRegister().\r
+  @param  Context         Points to an optional handler context which was specified when the handler was registered.\r
+  @param  CommBuffer      A pointer to a collection of data in memory that will\r
+                          be conveyed from a non-SMM environment into an SMM environment.\r
+  @param  CommBufferSize  The size of the CommBuffer.\r
+\r
+  @return Status Code\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmReadyToBootHandler (\r
+  IN     EFI_HANDLE               DispatchHandle,\r
+  IN     CONST VOID               *Context,        OPTIONAL\r
+  IN OUT VOID                     *CommBuffer,     OPTIONAL\r
+  IN OUT UINTN                    *CommBufferSize  OPTIONAL\r
+  );\r
+\r
+/**\r
+  Software SMI handler that is called when the S3SmmInitDone signal is triggered.\r
+  This function installs the SMM S3SmmInitDone Protocol so SMM Drivers are informed that\r
+  S3 SMM initialization has been done.\r
+\r
+  @param  DispatchHandle  The unique handle assigned to this handler by SmiHandlerRegister().\r
+  @param  Context         Points to an optional handler context which was specified when the handler was registered.\r
+  @param  CommBuffer      A pointer to a collection of data in memory that will\r
+                          be conveyed from a non-SMM environment into an SMM environment.\r
+  @param  CommBufferSize  The size of the CommBuffer.\r
+\r
+  @return Status Code\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmS3SmmInitDoneHandler (\r
+  IN     EFI_HANDLE  DispatchHandle,\r
+  IN     CONST VOID  *Context,        OPTIONAL\r
+  IN OUT VOID        *CommBuffer,     OPTIONAL\r
+  IN OUT UINTN       *CommBufferSize  OPTIONAL\r
+  );\r
+\r
+/**\r
+  Software SMI handler that is called when the EndOfS3Resume event is trigged.\r
+  This function installs the SMM EndOfS3Resume Protocol so SMM Drivers are informed that\r
+  S3 resume has finished.\r
+\r
+  @param  DispatchHandle  The unique handle assigned to this handler by SmiHandlerRegister().\r
+  @param  Context         Points to an optional handler context which was specified when the handler was registered.\r
+  @param  CommBuffer      A pointer to a collection of data in memory that will\r
+                          be conveyed from a non-SMM environment into an SMM environment.\r
+  @param  CommBufferSize  The size of the CommBuffer.\r
+\r
+  @return Status Code\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmEndOfS3ResumeHandler (\r
+  IN     EFI_HANDLE  DispatchHandle,\r
+  IN     CONST VOID  *Context,        OPTIONAL\r
+  IN OUT VOID        *CommBuffer,     OPTIONAL\r
+  IN OUT UINTN       *CommBufferSize  OPTIONAL\r
+  );\r
+\r
 /**\r
   Place holder function until all the SMM System Table Service are available.\r
 \r
@@ -714,4 +989,372 @@ SmmIsSchedulable (
   IN  EFI_SMM_DRIVER_ENTRY   *DriverEntry\r
   );\r
 \r
+//\r
+// SmramProfile\r
+//\r
+\r
+/**\r
+  Initialize SMRAM profile.\r
+\r
+**/\r
+VOID\r
+SmramProfileInit (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Install SMRAM profile protocol.\r
+\r
+**/\r
+VOID\r
+SmramProfileInstallProtocol (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Register SMM image to SMRAM profile.\r
+\r
+  @param DriverEntry    SMM image info.\r
+  @param RegisterToDxe  Register image to DXE.\r
+\r
+  @return EFI_SUCCESS           Register successfully.\r
+  @return EFI_UNSUPPORTED       Memory profile unsupported,\r
+                                or memory profile for the image is not required.\r
+  @return EFI_OUT_OF_RESOURCES  No enough resource for this register.\r
+\r
+**/\r
+EFI_STATUS\r
+RegisterSmramProfileImage (\r
+  IN EFI_SMM_DRIVER_ENTRY   *DriverEntry,\r
+  IN BOOLEAN                RegisterToDxe\r
+  );\r
+\r
+/**\r
+  Unregister image from SMRAM profile.\r
+\r
+  @param DriverEntry        SMM image info.\r
+  @param UnregisterToDxe    Unregister image from DXE.\r
+\r
+  @return EFI_SUCCESS           Unregister successfully.\r
+  @return EFI_UNSUPPORTED       Memory profile unsupported,\r
+                                or memory profile for the image is not required.\r
+  @return EFI_NOT_FOUND         The image is not found.\r
+\r
+**/\r
+EFI_STATUS\r
+UnregisterSmramProfileImage (\r
+  IN EFI_SMM_DRIVER_ENTRY   *DriverEntry,\r
+  IN BOOLEAN                UnregisterToDxe\r
+  );\r
+\r
+/**\r
+  Update SMRAM profile information.\r
+\r
+  @param CallerAddress  Address of caller who call Allocate or Free.\r
+  @param Action         This Allocate or Free action.\r
+  @param MemoryType     Memory type.\r
+                        EfiMaxMemoryType means the MemoryType is unknown.\r
+  @param Size           Buffer size.\r
+  @param Buffer         Buffer address.\r
+  @param ActionString   String for memory profile action.\r
+                        Only needed for user defined allocate action.\r
+\r
+  @return EFI_SUCCESS           Memory profile is updated.\r
+  @return EFI_UNSUPPORTED       Memory profile is unsupported,\r
+                                or memory profile for the image is not required,\r
+                                or memory profile for the memory type is not required.\r
+  @return EFI_ACCESS_DENIED     It is during memory profile data getting.\r
+  @return EFI_ABORTED           Memory profile recording is not enabled.\r
+  @return EFI_OUT_OF_RESOURCES  No enough resource to update memory profile for allocate action.\r
+  @return EFI_NOT_FOUND         No matched allocate info found for free action.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmCoreUpdateProfile (\r
+  IN PHYSICAL_ADDRESS       CallerAddress,\r
+  IN MEMORY_PROFILE_ACTION  Action,\r
+  IN EFI_MEMORY_TYPE        MemoryType, // Valid for AllocatePages/AllocatePool\r
+  IN UINTN                  Size,       // Valid for AllocatePages/FreePages/AllocatePool\r
+  IN VOID                   *Buffer,\r
+  IN CHAR8                  *ActionString OPTIONAL\r
+  );\r
+\r
+/**\r
+  Register SMRAM profile handler.\r
+\r
+**/\r
+VOID\r
+RegisterSmramProfileHandler (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  SMRAM profile ready to lock callback function.\r
+\r
+**/\r
+VOID\r
+SmramProfileReadyToLock (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Initialize MemoryAttributes support.\r
+**/\r
+VOID\r
+EFIAPI\r
+SmmCoreInitializeMemoryAttributesTable (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  This function returns a copy of the current memory map. The map is an array of\r
+  memory descriptors, each of which describes a contiguous block of memory.\r
+\r
+  @param[in, out]  MemoryMapSize          A pointer to the size, in bytes, of the\r
+                                          MemoryMap buffer. On input, this is the size of\r
+                                          the buffer allocated by the caller.  On output,\r
+                                          it is the size of the buffer returned by the\r
+                                          firmware  if the buffer was large enough, or the\r
+                                          size of the buffer needed  to contain the map if\r
+                                          the buffer was too small.\r
+  @param[in, out]  MemoryMap              A pointer to the buffer in which firmware places\r
+                                          the current memory map.\r
+  @param[out]      MapKey                 A pointer to the location in which firmware\r
+                                          returns the key for the current memory map.\r
+  @param[out]      DescriptorSize         A pointer to the location in which firmware\r
+                                          returns the size, in bytes, of an individual\r
+                                          EFI_MEMORY_DESCRIPTOR.\r
+  @param[out]      DescriptorVersion      A pointer to the location in which firmware\r
+                                          returns the version number associated with the\r
+                                          EFI_MEMORY_DESCRIPTOR.\r
+\r
+  @retval EFI_SUCCESS            The memory map was returned in the MemoryMap\r
+                                 buffer.\r
+  @retval EFI_BUFFER_TOO_SMALL   The MemoryMap buffer was too small. The current\r
+                                 buffer size needed to hold the memory map is\r
+                                 returned in MemoryMapSize.\r
+  @retval EFI_INVALID_PARAMETER  One of the parameters has an invalid value.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmCoreGetMemoryMap (\r
+  IN OUT UINTN                  *MemoryMapSize,\r
+  IN OUT EFI_MEMORY_DESCRIPTOR  *MemoryMap,\r
+  OUT UINTN                     *MapKey,\r
+  OUT UINTN                     *DescriptorSize,\r
+  OUT UINT32                    *DescriptorVersion\r
+  );\r
+\r
+/**\r
+  Initialize SmiHandler profile feature.\r
+**/\r
+VOID\r
+SmmCoreInitializeSmiHandlerProfile (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  This function is called by SmmChildDispatcher module to report\r
+  a new SMI handler is registered, to SmmCore.\r
+\r
+  @param This            The protocol instance\r
+  @param HandlerGuid     The GUID to identify the type of the handler.\r
+                         For the SmmChildDispatch protocol, the HandlerGuid\r
+                         must be the GUID of SmmChildDispatch protocol.\r
+  @param Handler         The SMI handler.\r
+  @param CallerAddress   The address of the module who registers the SMI handler.\r
+  @param Context         The context of the SMI handler.\r
+                         For the SmmChildDispatch protocol, the Context\r
+                         must match the one defined for SmmChildDispatch protocol.\r
+  @param ContextSize     The size of the context in bytes.\r
+                         For the SmmChildDispatch protocol, the Context\r
+                         must match the one defined for SmmChildDispatch protocol.\r
+\r
+  @retval EFI_SUCCESS           The information is recorded.\r
+  @retval EFI_OUT_OF_RESOURCES  There is no enough resource to record the information.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmiHandlerProfileRegisterHandler (\r
+  IN SMI_HANDLER_PROFILE_PROTOCOL   *This,\r
+  IN EFI_GUID                       *HandlerGuid,\r
+  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler,\r
+  IN PHYSICAL_ADDRESS               CallerAddress,\r
+  IN VOID                           *Context, OPTIONAL\r
+  IN UINTN                          ContextSize OPTIONAL\r
+  );\r
+\r
+/**\r
+  This function is called by SmmChildDispatcher module to report\r
+  an existing SMI handler is unregistered, to SmmCore.\r
+\r
+  @param This            The protocol instance\r
+  @param HandlerGuid     The GUID to identify the type of the handler.\r
+                         For the SmmChildDispatch protocol, the HandlerGuid\r
+                         must be the GUID of SmmChildDispatch protocol.\r
+  @param Handler         The SMI handler.\r
+  @param Context         The context of the SMI handler.\r
+                         If it is NOT NULL, it will be used to check what is registered.\r
+  @param ContextSize     The size of the context in bytes.\r
+                         If Context is NOT NULL, it will be used to check what is registered.\r
+\r
+  @retval EFI_SUCCESS           The original record is removed.\r
+  @retval EFI_NOT_FOUND         There is no record for the HandlerGuid and handler.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmiHandlerProfileUnregisterHandler (\r
+  IN SMI_HANDLER_PROFILE_PROTOCOL   *This,\r
+  IN EFI_GUID                       *HandlerGuid,\r
+  IN EFI_SMM_HANDLER_ENTRY_POINT2   Handler,\r
+  IN VOID                           *Context, OPTIONAL\r
+  IN UINTN                          ContextSize OPTIONAL\r
+  );\r
+\r
+extern UINTN                    mFullSmramRangeCount;\r
+extern EFI_SMRAM_DESCRIPTOR     *mFullSmramRanges;\r
+\r
+extern EFI_SMM_DRIVER_ENTRY       *mSmmCoreDriverEntry;\r
+\r
+extern EFI_LOADED_IMAGE_PROTOCOL  *mSmmCoreLoadedImage;\r
+\r
+//\r
+// Page management\r
+//\r
+\r
+typedef struct {\r
+  LIST_ENTRY  Link;\r
+  UINTN       NumberOfPages;\r
+} FREE_PAGE_LIST;\r
+\r
+extern LIST_ENTRY  mSmmMemoryMap;\r
+\r
+//\r
+// Pool management\r
+//\r
+\r
+//\r
+// MIN_POOL_SHIFT must not be less than 5\r
+//\r
+#define MIN_POOL_SHIFT  6\r
+#define MIN_POOL_SIZE   (1 << MIN_POOL_SHIFT)\r
+\r
+//\r
+// MAX_POOL_SHIFT must not be less than EFI_PAGE_SHIFT - 1\r
+//\r
+#define MAX_POOL_SHIFT  (EFI_PAGE_SHIFT - 1)\r
+#define MAX_POOL_SIZE   (1 << MAX_POOL_SHIFT)\r
+\r
+//\r
+// MAX_POOL_INDEX are calculated by maximum and minimum pool sizes\r
+//\r
+#define MAX_POOL_INDEX  (MAX_POOL_SHIFT - MIN_POOL_SHIFT + 1)\r
+\r
+#define POOL_HEAD_SIGNATURE   SIGNATURE_32('p','h','d','0')\r
+\r
+typedef struct {\r
+  UINT32            Signature;\r
+  BOOLEAN           Available;\r
+  EFI_MEMORY_TYPE   Type;\r
+  UINTN             Size;\r
+} POOL_HEADER;\r
+\r
+#define POOL_TAIL_SIGNATURE   SIGNATURE_32('p','t','a','l')\r
+\r
+typedef struct {\r
+  UINT32            Signature;\r
+  UINT32            Reserved;\r
+  UINTN             Size;\r
+} POOL_TAIL;\r
+\r
+#define POOL_OVERHEAD (sizeof(POOL_HEADER) + sizeof(POOL_TAIL))\r
+\r
+#define HEAD_TO_TAIL(a)   \\r
+  ((POOL_TAIL *) (((CHAR8 *) (a)) + (a)->Size - sizeof(POOL_TAIL)));\r
+\r
+typedef struct {\r
+  POOL_HEADER  Header;\r
+  LIST_ENTRY   Link;\r
+} FREE_POOL_HEADER;\r
+\r
+typedef enum {\r
+  SmmPoolTypeCode,\r
+  SmmPoolTypeData,\r
+  SmmPoolTypeMax,\r
+} SMM_POOL_TYPE;\r
+\r
+extern LIST_ENTRY  mSmmPoolLists[SmmPoolTypeMax][MAX_POOL_INDEX];\r
+\r
+/**\r
+  Internal Function. Allocate n pages from given free page node.\r
+\r
+  @param  Pages                  The free page node.\r
+  @param  NumberOfPages          Number of pages to be allocated.\r
+  @param  MaxAddress             Request to allocate memory below this address.\r
+\r
+  @return Memory address of allocated pages.\r
+\r
+**/\r
+UINTN\r
+InternalAllocPagesOnOneNode (\r
+  IN OUT FREE_PAGE_LIST   *Pages,\r
+  IN     UINTN            NumberOfPages,\r
+  IN     UINTN            MaxAddress\r
+  );\r
+\r
+/**\r
+  Update SMM memory map entry.\r
+\r
+  @param[in]  Type                   The type of allocation to perform.\r
+  @param[in]  Memory                 The base of memory address.\r
+  @param[in]  NumberOfPages          The number of pages to allocate.\r
+  @param[in]  AddRegion              If this memory is new added region.\r
+**/\r
+VOID\r
+ConvertSmmMemoryMapEntry (\r
+  IN EFI_MEMORY_TYPE       Type,\r
+  IN EFI_PHYSICAL_ADDRESS  Memory,\r
+  IN UINTN                 NumberOfPages,\r
+  IN BOOLEAN               AddRegion\r
+  );\r
+\r
+/**\r
+  Internal function.  Moves any memory descriptors that are on the\r
+  temporary descriptor stack to heap.\r
+\r
+**/\r
+VOID\r
+CoreFreeMemoryMapStack (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Frees previous allocated pages.\r
+\r
+  @param[in]  Memory                 Base address of memory being freed.\r
+  @param[in]  NumberOfPages          The number of pages to free.\r
+  @param[in]  AddRegion              If this memory is new added region.\r
+\r
+  @retval EFI_NOT_FOUND          Could not find the entry that covers the range.\r
+  @retval EFI_INVALID_PARAMETER  Address not aligned, Address is zero or NumberOfPages is zero.\r
+  @return EFI_SUCCESS            Pages successfully freed.\r
+\r
+**/\r
+EFI_STATUS\r
+SmmInternalFreePagesEx (\r
+  IN EFI_PHYSICAL_ADDRESS  Memory,\r
+  IN UINTN                 NumberOfPages,\r
+  IN BOOLEAN               AddRegion\r
+  );\r
+\r
+/**\r
+  Hook function used to set all Guard pages after entering SMM mode.\r
+**/\r
+VOID\r
+SmmEntryPointMemoryManagementHook (\r
+  VOID\r
+  );\r
+\r
 #endif\r