]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/DxeMain.h
MdeModulePkg DxeCore/PiSmmCore: Add UEFI memory and SMRAM profile support.
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / DxeMain.h
index dedb84047f8e7e65e3f7e76dc7b1dba86f06b283..bb2bfab370ff8ec32bb749336b9383684ad54d8d 100644 (file)
@@ -2,7 +2,7 @@
   The internal header file includes the common header files, defines\r
   internal structure and functions used by DxeCore module.\r
 \r
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -41,6 +41,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Protocol/Decompress.h>\r
 #include <Protocol/LoadPe32Image.h>\r
 #include <Protocol/Security.h>\r
+#include <Protocol/Security2.h>\r
 #include <Protocol/Ebc.h>\r
 #include <Protocol/Reset.h>\r
 #include <Protocol/Cpu.h>\r
@@ -63,8 +64,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Guid/MemoryAllocationHob.h>\r
 #include <Guid/EventLegacyBios.h>\r
 #include <Guid/EventGroup.h>\r
+#include <Guid/EventExitBootServiceFailed.h>\r
 #include <Guid/LoadModuleAtFixedAddress.h>\r
 #include <Guid/IdleLoopEvent.h>\r
+#include <Guid/VectorHandoffTable.h>\r
+#include <Ppi/VectorHandoffInfo.h>\r
+#include <Guid/ZeroGuid.h>\r
+#include <Guid/MemoryProfile.h>\r
 \r
 #include <Library/DxeCoreEntryPoint.h>\r
 #include <Library/DebugLib.h>\r
@@ -187,6 +193,56 @@ typedef struct {
   EFI_HANDLE            DeviceHandle;\r
 } EFI_GCD_MAP_ENTRY;\r
 \r
+\r
+#define LOADED_IMAGE_PRIVATE_DATA_SIGNATURE   SIGNATURE_32('l','d','r','i')\r
+\r
+typedef struct {\r
+  UINTN                       Signature;\r
+  /// Image handle\r
+  EFI_HANDLE                  Handle;   \r
+  /// Image type\r
+  UINTN                       Type;           \r
+  /// If entrypoint has been called\r
+  BOOLEAN                     Started;        \r
+  /// The image's entry point\r
+  EFI_IMAGE_ENTRY_POINT       EntryPoint;     \r
+  /// loaded image protocol\r
+  EFI_LOADED_IMAGE_PROTOCOL   Info;           \r
+  /// Location in memory\r
+  EFI_PHYSICAL_ADDRESS        ImageBasePage;  \r
+  /// Number of pages\r
+  UINTN                       NumberOfPages;  \r
+  /// Original fixup data\r
+  CHAR8                       *FixupData;     \r
+  /// Tpl of started image\r
+  EFI_TPL                     Tpl;            \r
+  /// Status returned by started image\r
+  EFI_STATUS                  Status;         \r
+  /// Size of ExitData from started image\r
+  UINTN                       ExitDataSize;   \r
+  /// Pointer to exit data from started image\r
+  VOID                        *ExitData;      \r
+  /// Pointer to pool allocation for context save/retore\r
+  VOID                        *JumpBuffer;    \r
+  /// Pointer to buffer for context save/retore\r
+  BASE_LIBRARY_JUMP_BUFFER    *JumpContext;  \r
+  /// Machine type from PE image\r
+  UINT16                      Machine;        \r
+  /// EBC Protocol pointer\r
+  EFI_EBC_PROTOCOL            *Ebc;           \r
+  /// Runtime image list\r
+  EFI_RUNTIME_IMAGE_ENTRY     *RuntimeData;   \r
+  /// Pointer to Loaded Image Device Path Protocl\r
+  EFI_DEVICE_PATH_PROTOCOL    *LoadedImageDevicePath;  \r
+  /// PeCoffLoader ImageContext\r
+  PE_COFF_LOADER_IMAGE_CONTEXT  ImageContext; \r
+  /// Status returned by LoadImage() service.\r
+  EFI_STATUS                  LoadImageStatus;\r
+} LOADED_IMAGE_PRIVATE_DATA;\r
+\r
+#define LOADED_IMAGE_PRIVATE_DATA_FROM_THIS(a) \\r
+          CR(a, LOADED_IMAGE_PRIVATE_DATA, Info, LOADED_IMAGE_PRIVATE_DATA_SIGNATURE)\r
+\r
 //\r
 // DXE Core Global Variables\r
 //\r
@@ -203,6 +259,7 @@ extern EFI_WATCHDOG_TIMER_ARCH_PROTOCOL         *gWatchdogTimer;
 extern EFI_METRONOME_ARCH_PROTOCOL              *gMetronome;\r
 extern EFI_TIMER_ARCH_PROTOCOL                  *gTimer;\r
 extern EFI_SECURITY_ARCH_PROTOCOL               *gSecurity;\r
+extern EFI_SECURITY2_ARCH_PROTOCOL              *gSecurity2;\r
 extern EFI_BDS_ARCH_PROTOCOL                    *gBds;\r
 extern EFI_SMM_BASE2_PROTOCOL                   *gSmmBase2;\r
 \r
@@ -670,8 +727,12 @@ CoreInstallProtocolInterfaceNotify (
                                  arguments to InstallProtocolInterface(). All the\r
                                  protocols are added to Handle.\r
 \r
+  @retval EFI_SUCCESS            All the protocol interface was installed.\r
+  @retval EFI_OUT_OF_RESOURCES   There was not enough memory in pool to install all the protocols.\r
+  @retval EFI_ALREADY_STARTED    A Device Path Protocol instance was passed in that is already present in\r
+                                 the handle database.\r
   @retval EFI_INVALID_PARAMETER  Handle is NULL.\r
-  @retval EFI_SUCCESS            Protocol interfaces successfully installed.\r
+  @retval EFI_INVALID_PARAMETER  Protocol is already installed on the handle specified by Handle.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1080,19 +1141,27 @@ CoreConnectHandlesByKey (
 /**\r
   Connects one or more drivers to a controller.\r
 \r
-  @param  ControllerHandle                      Handle of the controller to be\r
-                                                connected.\r
-  @param  DriverImageHandle                     DriverImageHandle A pointer to an\r
-                                                ordered list of driver image\r
-                                                handles.\r
-  @param  RemainingDevicePath                   RemainingDevicePath A pointer to\r
-                                                the device path that specifies a\r
-                                                child of the controller specified\r
-                                                by ControllerHandle.\r
-  @param  Recursive                             Whether the function would be\r
-                                                called recursively or not.\r
+  @param  ControllerHandle      The handle of the controller to which driver(s) are to be connected.\r
+  @param  DriverImageHandle     A pointer to an ordered list handles that support the\r
+                                EFI_DRIVER_BINDING_PROTOCOL.\r
+  @param  RemainingDevicePath   A pointer to the device path that specifies a child of the\r
+                                controller specified by ControllerHandle.\r
+  @param  Recursive             If TRUE, then ConnectController() is called recursively\r
+                                until the entire tree of controllers below the controller specified\r
+                                by ControllerHandle have been created. If FALSE, then\r
+                                the tree of controllers is only expanded one level.\r
 \r
-  @return Status code.\r
+  @retval EFI_SUCCESS           1) One or more drivers were connected to ControllerHandle.\r
+                                2) No drivers were connected to ControllerHandle, but\r
+                                RemainingDevicePath is not NULL, and it is an End Device\r
+                                Path Node.\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
+  @retval EFI_NOT_FOUND         1) There are no EFI_DRIVER_BINDING_PROTOCOL instances\r
+                                present in the system.\r
+                                2) No drivers were connected to ControllerHandle.\r
+  @retval EFI_SECURITY_VIOLATION \r
+                                The user has no permission to start UEFI device drivers on the device path \r
+                                associated with the ControllerHandle or specified by the RemainingDevicePath.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1175,7 +1244,32 @@ CoreAllocatePages (
   IN 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
+\r
+  @return Status. On success, Memory is filled in with the base address allocated\r
+  @retval EFI_INVALID_PARAMETER  Parameters violate checking rules defined in\r
+                                 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
+CoreInternalAllocatePages (\r
+  IN EFI_ALLOCATE_TYPE      Type,\r
+  IN EFI_MEMORY_TYPE        MemoryType,\r
+  IN UINTN                  NumberOfPages,\r
+  IN OUT EFI_PHYSICAL_ADDRESS  *Memory\r
+  );\r
 \r
 /**\r
   Frees previous allocated pages.\r
@@ -1195,7 +1289,23 @@ CoreFreePages (
   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
+\r
+  @retval EFI_NOT_FOUND          Could not find the entry that covers the range\r
+  @retval EFI_INVALID_PARAMETER  Address not aligned\r
+  @return EFI_SUCCESS         -Pages successfully freed.\r
 \r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CoreInternalFreePages (\r
+  IN EFI_PHYSICAL_ADDRESS   Memory,\r
+  IN UINTN                  NumberOfPages\r
+  );\r
 \r
 /**\r
   This function returns a copy of the current memory map. The map is an array of\r
@@ -1260,7 +1370,26 @@ CoreAllocatePool (
   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 or Buffer is NULL\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
+CoreInternalAllocatePool (\r
+  IN EFI_MEMORY_TYPE  PoolType,\r
+  IN UINTN            Size,\r
+  OUT VOID            **Buffer\r
+  );\r
 \r
 /**\r
   Frees pool.\r
@@ -1277,7 +1406,20 @@ CoreFreePool (
   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
+CoreInternalFreePool (\r
+  IN VOID        *Buffer\r
+  );\r
 \r
 /**\r
   Loads an EFI image into memory and returns a handle to the image.\r
@@ -1360,6 +1502,7 @@ CoreUnloadImage (
 \r
   @retval EFI_INVALID_PARAMETER   Invalid parameter\r
   @retval EFI_OUT_OF_RESOURCES    No enough buffer to allocate\r
+  @retval EFI_SECURITY_VIOLATION  The current platform policy specifies that the image should not be started.\r
   @retval EFI_SUCCESS             Successfully transfer control to the image's\r
                                   entry point.\r
 \r
@@ -2338,6 +2481,8 @@ GetSection (
   SEP member function.  Deletes an existing section stream\r
 \r
   @param  StreamHandleToClose    Indicates the stream to close\r
+  @param  FreeStreamBuffer       TRUE - Need to free stream buffer;\r
+                                 FALSE - No need to free stream buffer.\r
 \r
   @retval EFI_SUCCESS            The section stream is closed sucessfully.\r
   @retval EFI_OUT_OF_RESOURCES   Memory allocation failed.\r
@@ -2348,7 +2493,8 @@ GetSection (
 EFI_STATUS\r
 EFIAPI\r
 CloseSectionStream (\r
-  IN  UINTN                                     StreamHandleToClose\r
+  IN  UINTN                                     StreamHandleToClose,\r
+  IN  BOOLEAN                                   FreeStreamBuffer\r
   );\r
 \r
 /**\r
@@ -2574,6 +2720,8 @@ ReadFvbData (
   @retval EFI_OUT_OF_RESOURCES  No enough buffer could be allocated.\r
   @retval EFI_SUCCESS           Successfully read volume header to the allocated\r
                                 buffer.\r
+  @retval EFI_INVALID_PARAMETER The FV Header signature is not as expected or\r
+                                the file system could not be understood.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -2596,4 +2744,76 @@ VerifyFvHeaderChecksum (
   IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader\r
   );\r
 \r
+/**\r
+  Initialize memory profile.\r
+\r
+  @param HobStart   The start address of the HOB.\r
+\r
+**/\r
+VOID\r
+MemoryProfileInit (\r
+  IN VOID   *HobStart\r
+  );\r
+\r
+/**\r
+  Install memory profile protocol.\r
+\r
+**/\r
+VOID\r
+MemoryProfileInstallProtocol (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Register image to memory profile.\r
+\r
+  @param DriverEntry    Image info.\r
+  @param FileType       Image file type.\r
+\r
+  @retval TRUE          Register success.\r
+  @retval FALSE         Register fail.\r
+\r
+**/\r
+BOOLEAN\r
+RegisterMemoryProfileImage (\r
+  IN LOADED_IMAGE_PRIVATE_DATA  *DriverEntry,\r
+  IN EFI_FV_FILETYPE            FileType\r
+  );\r
+\r
+/**\r
+  Unregister image from memory profile.\r
+\r
+  @param DriverEntry    Image info.\r
+\r
+  @retval TRUE          Unregister success.\r
+  @retval FALSE         Unregister fail.\r
+\r
+**/\r
+BOOLEAN\r
+UnregisterMemoryProfileImage (\r
+  IN LOADED_IMAGE_PRIVATE_DATA  *DriverEntry\r
+  );\r
+\r
+/**\r
+  Update memory 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
+  @param Size           Buffer size.\r
+  @param Buffer         Buffer address.\r
+\r
+  @retval TRUE          Profile udpate success.\r
+  @retval FALSE         Profile update fail.\r
+\r
+**/\r
+BOOLEAN\r
+CoreUpdateProfile (\r
+  IN EFI_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
+  );\r
+\r
 #endif\r