]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/DxeMain.h
MdeModulePkg/DxeCore: switch to MdePkg allocation granularity macros
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / DxeMain.h
index fefe5bec19d36f09e2cb49e9daae4e691022b689..1a0babba713aa06fc15fdfa40dc9a0852451c30d 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 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2017, 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
@@ -69,7 +69,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #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
@@ -110,8 +109,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 \r
 ///\r
-/// EFI_DEP_REPLACE_TRUE - Used to dynamically patch the dependecy expression\r
-///                        to save time.  A EFI_DEP_PUSH is evauated one an\r
+/// EFI_DEP_REPLACE_TRUE - Used to dynamically patch the dependency expression\r
+///                        to save time.  A EFI_DEP_PUSH is evaluated one an\r
 ///                        replaced with EFI_DEP_REPLACE_TRUE. If PI spec's Vol 2\r
 ///                        Driver Execution Environment Core Interface use 0xff\r
 ///                        as new DEPEX opcode. EFI_DEP_REPLACE_TRUE should be\r
@@ -124,31 +123,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 ///\r
 #define DEPEX_STACK_SIZE_INCREMENT  0x1000\r
 \r
-#if defined (MDE_CPU_IPF)\r
-///\r
-/// For Itanium machines make the default allocations 8K aligned\r
-///\r
-#define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT  (EFI_PAGE_SIZE * 2)\r
-#define DEFAULT_PAGE_ALLOCATION                     (EFI_PAGE_SIZE * 2)\r
-\r
-#elif defined (MDE_CPU_AARCH64)\r
-///\r
-/// 64-bit ARM systems allow the OS to execute with 64 KB page size,\r
-/// so for improved interoperability with the firmware, align the\r
-/// runtime regions to 64 KB as well\r
-///\r
-#define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT  (SIZE_64KB)\r
-#define DEFAULT_PAGE_ALLOCATION                     (EFI_PAGE_SIZE)\r
-\r
-#else\r
-///\r
-/// For genric EFI machines make the default allocations 4K aligned\r
-///\r
-#define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT  (EFI_PAGE_SIZE)\r
-#define DEFAULT_PAGE_ALLOCATION                     (EFI_PAGE_SIZE)\r
-\r
-#endif\r
-\r
 typedef struct {\r
   EFI_GUID                    *ProtocolGuid;\r
   VOID                        **Protocol;\r
@@ -247,9 +221,9 @@ typedef struct {
   UINTN                       ExitDataSize;   \r
   /// Pointer to exit data from started image\r
   VOID                        *ExitData;      \r
-  /// Pointer to pool allocation for context save/retore\r
+  /// Pointer to pool allocation for context save/restore\r
   VOID                        *JumpBuffer;    \r
-  /// Pointer to buffer for context save/retore\r
+  /// Pointer to buffer for context save/restore\r
   BASE_LIBRARY_JUMP_BUFFER    *JumpContext;  \r
   /// Machine type from PE image\r
   UINT16                      Machine;        \r
@@ -257,7 +231,7 @@ typedef struct {
   EFI_EBC_PROTOCOL            *Ebc;           \r
   /// Runtime image list\r
   EFI_RUNTIME_IMAGE_ENTRY     *RuntimeData;   \r
-  /// Pointer to Loaded Image Device Path Protocl\r
+  /// Pointer to Loaded Image Device Path Protocol\r
   EFI_DEVICE_PATH_PROTOCOL    *LoadedImageDevicePath;  \r
   /// PeCoffLoader ImageContext\r
   PE_COFF_LOADER_IMAGE_CONTEXT  ImageContext; \r
@@ -268,6 +242,26 @@ typedef struct {
 #define LOADED_IMAGE_PRIVATE_DATA_FROM_THIS(a) \\r
           CR(a, LOADED_IMAGE_PRIVATE_DATA, Info, LOADED_IMAGE_PRIVATE_DATA_SIGNATURE)\r
 \r
+#define IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGNATURE SIGNATURE_32 ('I','P','R','C')\r
+\r
+typedef struct {\r
+  UINT32                 Signature;\r
+  LIST_ENTRY             Link;\r
+  EFI_PHYSICAL_ADDRESS   CodeSegmentBase;\r
+  UINT64                 CodeSegmentSize;\r
+} IMAGE_PROPERTIES_RECORD_CODE_SECTION;\r
+\r
+#define IMAGE_PROPERTIES_RECORD_SIGNATURE SIGNATURE_32 ('I','P','R','D')\r
+\r
+typedef struct {\r
+  UINT32                 Signature;\r
+  LIST_ENTRY             Link;\r
+  EFI_PHYSICAL_ADDRESS   ImageBase;\r
+  UINT64                 ImageSize;\r
+  UINTN                  CodeSegmentCount;\r
+  LIST_ENTRY             CodeSegmentList;\r
+} IMAGE_PROPERTIES_RECORD;\r
+\r
 //\r
 // DXE Core Global Variables\r
 //\r
@@ -276,6 +270,8 @@ extern EFI_RUNTIME_SERVICES                     *gDxeCoreRT;
 extern EFI_DXE_SERVICES                         *gDxeCoreDS;\r
 extern EFI_HANDLE                               gDxeCoreImageHandle;\r
 \r
+extern BOOLEAN                                  gMemoryMapTerminated;\r
+\r
 extern EFI_DECOMPRESS_PROTOCOL                  gEfiDecompress;\r
 \r
 extern EFI_RUNTIME_ARCH_PROTOCOL                *gRuntime;\r
@@ -444,7 +440,7 @@ CoreNotifyOnProtocolInstallation (
 \r
 \r
 /**\r
-  Return TRUE if all AP services are availible.\r
+  Return TRUE if all AP services are available.\r
 \r
   @retval EFI_SUCCESS    All AP services are available\r
   @retval EFI_NOT_FOUND  At least one AP service is not available\r
@@ -472,7 +468,7 @@ CalculateEfiHdrCrc (
 /**\r
   Called by the platform code to process a tick.\r
 \r
-  @param  Duration               The number of 100ns elasped since the last call\r
+  @param  Duration               The number of 100ns elapsed since the last call\r
                                  to TimerTick\r
 \r
 **/\r
@@ -1096,7 +1092,7 @@ CoreLocateDevicePath (
   @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
+  @retval EFI_INVALID_PARAMETER  One or more parameters are not valid.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1269,33 +1265,6 @@ 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
 \r
@@ -1314,24 +1283,6 @@ 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
   memory descriptors, each of which describes a contiguous block of memory.\r
@@ -1435,6 +1386,7 @@ CoreFreePool (
   Frees pool.\r
 \r
   @param  Buffer                 The allocated pool entry to free\r
+  @param  PoolType               Pointer to pool type\r
 \r
   @retval EFI_INVALID_PARAMETER  Buffer is not a valid value.\r
   @retval EFI_SUCCESS            Pool successfully freed.\r
@@ -1443,7 +1395,8 @@ CoreFreePool (
 EFI_STATUS\r
 EFIAPI\r
 CoreInternalFreePool (\r
-  IN VOID        *Buffer\r
+  IN VOID               *Buffer,\r
+  OUT EFI_MEMORY_TYPE   *PoolType OPTIONAL\r
   );\r
 \r
 /**\r
@@ -1500,7 +1453,7 @@ CoreLoadImage (
                                   unloaded.\r
 \r
   @retval EFI_SUCCESS             The image has been unloaded.\r
-  @retval EFI_UNSUPPORTED         The image has been sarted, and does not support\r
+  @retval EFI_UNSUPPORTED         The image has been started, and does not support\r
                                   unload.\r
   @retval EFI_INVALID_PARAMPETER  ImageHandle is not a valid image handle.\r
 \r
@@ -2471,7 +2424,7 @@ OpenSectionStream (
                                 non-null on input, then the buffer is caller\r
                                 allocated.  If Buffer is NULL, then the buffer\r
                                 is callee allocated.  In either case, the\r
-                                requried buffer size is returned in *BufferSize.\r
+                                required buffer size is returned in *BufferSize.\r
   @param  BufferSize            On input, indicates the size of *Buffer if\r
                                 *Buffer is non-null on input.  On output,\r
                                 indicates the required size (allocated size if\r
@@ -2717,22 +2670,6 @@ CoreReleaseLock (
   IN EFI_LOCK  *Lock\r
   );\r
 \r
-\r
-/**\r
-  An empty function to pass error checking of CreateEventEx ().\r
-\r
-  @param  Event                 Event whose notification function is being invoked.\r
-  @param  Context               Pointer to the notification function's context,\r
-                                which is implementation-dependent.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-CoreEmptyCallbackFunction (\r
-  IN EFI_EVENT                Event,\r
-  IN VOID                     *Context\r
-  );\r
-\r
 /**\r
   Read data from Firmware Block by FVB protocol Read. \r
   The data may cross the multi block ranges.\r
@@ -2821,11 +2758,13 @@ MemoryProfileInstallProtocol (
   @param DriverEntry    Image info.\r
   @param FileType       Image file type.\r
 \r
-  @retval TRUE          Register success.\r
-  @retval FALSE         Register fail.\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
-BOOLEAN\r
+EFI_STATUS\r
 RegisterMemoryProfileImage (\r
   IN LOADED_IMAGE_PRIVATE_DATA  *DriverEntry,\r
   IN EFI_FV_FILETYPE            FileType\r
@@ -2836,11 +2775,13 @@ RegisterMemoryProfileImage (
 \r
   @param DriverEntry    Image info.\r
 \r
-  @retval TRUE          Unregister success.\r
-  @retval FALSE         Unregister fail.\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
-BOOLEAN\r
+EFI_STATUS\r
 UnregisterMemoryProfileImage (\r
   IN LOADED_IMAGE_PRIVATE_DATA  *DriverEntry\r
   );\r
@@ -2851,20 +2792,31 @@ UnregisterMemoryProfileImage (
   @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
-  @retval TRUE          Profile udpate success.\r
-  @retval FALSE         Profile update fail.\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
-BOOLEAN\r
+EFI_STATUS\r
+EFIAPI\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 EFI_MEMORY_TYPE        MemoryType,\r
   IN UINTN                  Size,       // Valid for AllocatePages/FreePages/AllocatePool\r
-  IN VOID                   *Buffer\r
+  IN VOID                   *Buffer,\r
+  IN CHAR8                  *ActionString OPTIONAL\r
   );\r
 \r
 /**\r
@@ -2901,6 +2853,25 @@ CoreInitializeMemoryAttributesTable (
   VOID\r
   );\r
 \r
+/**\r
+  Initialize Memory Protection support.\r
+**/\r
+VOID\r
+EFIAPI\r
+CoreInitializeMemoryProtection (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Install MemoryAttributesTable on memory allocation.\r
+\r
+  @param[in] MemoryType EFI memory type.\r
+**/\r
+VOID\r
+InstallMemoryAttributesTableOnMemoryAllocation (\r
+  IN EFI_MEMORY_TYPE    MemoryType\r
+  );\r
+\r
 /**\r
   Insert image record.\r
 \r
@@ -2921,4 +2892,60 @@ RemoveImageRecord (
   IN EFI_RUNTIME_IMAGE_ENTRY  *RuntimeImage\r
   );\r
 \r
+/**\r
+  Protect UEFI image.\r
+\r
+  @param[in]  LoadedImage              The loaded image protocol\r
+  @param[in]  LoadedImageDevicePath    The loaded image device path protocol\r
+**/\r
+VOID\r
+ProtectUefiImage (\r
+  IN EFI_LOADED_IMAGE_PROTOCOL   *LoadedImage,\r
+  IN EFI_DEVICE_PATH_PROTOCOL    *LoadedImageDevicePath\r
+  );\r
+\r
+/**\r
+  Unprotect UEFI image.\r
+\r
+  @param[in]  LoadedImage              The loaded image protocol\r
+  @param[in]  LoadedImageDevicePath    The loaded image device path protocol\r
+**/\r
+VOID\r
+UnprotectUefiImage (\r
+  IN EFI_LOADED_IMAGE_PROTOCOL   *LoadedImage,\r
+  IN EFI_DEVICE_PATH_PROTOCOL    *LoadedImageDevicePath\r
+  );\r
+\r
+/**\r
+  ExitBootServices Callback function for memory protection.\r
+**/\r
+VOID\r
+MemoryProtectionExitBootServicesCallback (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Manage memory permission attributes on a memory range, according to the\r
+  configured DXE memory protection policy.\r
+\r
+  @param  OldType           The old memory type of the range\r
+  @param  NewType           The new memory type of the range\r
+  @param  Memory            The base address of the range\r
+  @param  Length            The size of the range (in bytes)\r
+\r
+  @return EFI_SUCCESS       If the the CPU arch protocol is not installed yet\r
+  @return EFI_SUCCESS       If no DXE memory protection policy has been configured\r
+  @return EFI_SUCCESS       If OldType and NewType use the same permission attributes\r
+  @return other             Return value of gCpu->SetMemoryAttributes()\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ApplyMemoryProtectionPolicy (\r
+  IN  EFI_MEMORY_TYPE       OldType,\r
+  IN  EFI_MEMORY_TYPE       NewType,\r
+  IN  EFI_PHYSICAL_ADDRESS  Memory,\r
+  IN  UINT64                Length\r
+  );\r
+\r
 #endif\r