]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
MdeModulePkg DxeCore/PiSmmCore: Add UEFI memory and SMRAM profile support.
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / DxeMain / DxeMain.c
index acc675844a89d3bc41f8d3c236e14752d031f1d9..1ac5cc17212d590479723f9216e85e3f69852fe3 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   DXE Core Main Entry Point\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
-All rights reserved. This program and the accompanying materials\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
 http://opensource.org/licenses/bsd-license.php\r
@@ -23,6 +23,7 @@ EFI_HANDLE                                mDecompressHandle = NULL;
 // DXE Core globals for Architecture Protocols\r
 //\r
 EFI_SECURITY_ARCH_PROTOCOL        *gSecurity      = NULL;\r
+EFI_SECURITY2_ARCH_PROTOCOL       *gSecurity2     = NULL;\r
 EFI_CPU_ARCH_PROTOCOL             *gCpu           = NULL;\r
 EFI_METRONOME_ARCH_PROTOCOL       *gMetronome     = NULL;\r
 EFI_TIMER_ARCH_PROTOCOL           *gTimer         = NULL;\r
@@ -30,24 +31,19 @@ EFI_BDS_ARCH_PROTOCOL             *gBds           = NULL;
 EFI_WATCHDOG_TIMER_ARCH_PROTOCOL  *gWatchdogTimer = NULL;\r
 \r
 //\r
-// DXE Core Global used to update core loaded image protocol handle\r
+// DXE Core globals for optional protocol dependencies\r
 //\r
-EFI_GUID                           *gDxeCoreFileName;\r
-EFI_LOADED_IMAGE_PROTOCOL          *gDxeCoreLoadedImage;\r
+EFI_SMM_BASE2_PROTOCOL            *gSmmBase2      = NULL;\r
 \r
 //\r
-// BugBug: I'n not runtime, but is the PPI?\r
+// DXE Core Global used to update core loaded image protocol handle\r
 //\r
-EFI_STATUS_CODE_PROTOCOL     gStatusCodeInstance = {\r
-  NULL\r
-};\r
-\r
-EFI_STATUS_CODE_PROTOCOL     *gStatusCode    = &gStatusCodeInstance;\r
+EFI_GUID                           *gDxeCoreFileName;\r
+EFI_LOADED_IMAGE_PROTOCOL          *gDxeCoreLoadedImage;\r
 \r
 //\r
 // DXE Core Module Variables\r
 //\r
-\r
 EFI_BOOT_SERVICES mBootServices = {\r
   {\r
     EFI_BOOT_SERVICES_SIGNATURE,                                                          // Signature\r
@@ -220,6 +216,11 @@ EFI_DECOMPRESS_PROTOCOL  gEfiDecompress = {
 };\r
 \r
 //\r
+// For Loading modules at fixed address feature, the configuration table is to cache the top address below which to load\r
+// Runtime code&boot time code\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE    gLoadModuleAtFixAddressConfigurationTable = {0, 0};\r
+\r
 // Main entry point to the DXE Core\r
 //\r
 \r
@@ -237,15 +238,38 @@ DxeMain (
   IN  VOID *HobStart\r
   )\r
 {\r
-  EFI_STATUS                         Status;\r
-  EFI_PHYSICAL_ADDRESS               MemoryBaseAddress;\r
-  UINT64                             MemoryLength;\r
+  EFI_STATUS                    Status;\r
+  EFI_PHYSICAL_ADDRESS          MemoryBaseAddress;\r
+  UINT64                        MemoryLength;\r
+  PE_COFF_LOADER_IMAGE_CONTEXT  ImageContext;\r
+  UINTN                         Index;\r
+  EFI_HOB_GUID_TYPE             *GuidHob;\r
+  EFI_VECTOR_HANDOFF_INFO       *VectorInfoList;\r
+  EFI_VECTOR_HANDOFF_INFO       *VectorInfo;\r
+\r
+  //\r
+  // Setup the default exception handlers\r
+  //\r
+  VectorInfoList = NULL;\r
+  GuidHob = GetNextGuidHob (&gEfiVectorHandoffInfoPpiGuid, HobStart);\r
+  if (GuidHob != NULL) {\r
+    VectorInfoList = (EFI_VECTOR_HANDOFF_INFO *) (GET_GUID_HOB_DATA(GuidHob));\r
+  }\r
+  Status = InitializeCpuExceptionHandlers (VectorInfoList);\r
+  ASSERT_EFI_ERROR (Status);\r
+  \r
+  //\r
+  // Initialize Debug Agent to support source level debug in DXE phase\r
+  //\r
+  InitializeDebugAgent (DEBUG_AGENT_INIT_DXE_CORE, HobStart, NULL);\r
 \r
   //\r
   // Initialize Memory Services\r
   //\r
   CoreInitializeMemoryServices (&HobStart, &MemoryBaseAddress, &MemoryLength);\r
 \r
+  MemoryProfileInit (HobStart);\r
+\r
   //\r
   // Allocate the EFI System Table and EFI Runtime Service Table from EfiRuntimeServicesData\r
   // Use the templates to initialize the contents of the EFI System Table and EFI Runtime Services Table\r
@@ -268,8 +292,16 @@ DxeMain (
   // Call constructor for all libraries\r
   //\r
   ProcessLibraryConstructorList (gDxeCoreImageHandle, gDxeCoreST);\r
-  PERF_END   (0,PEI_TOK, NULL, 0) ;\r
-  PERF_START (0,DXE_TOK, NULL, 0) ;\r
+  PERF_END   (NULL,"PEI", NULL, 0) ;\r
+  PERF_START (NULL,"DXE", NULL, 0) ;\r
+\r
+  //\r
+  // Report DXE Core image information to the PE/COFF Extra Action Library\r
+  //\r
+  ZeroMem (&ImageContext, sizeof (ImageContext));\r
+  ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)gDxeCoreLoadedImage->ImageBase;\r
+  ImageContext.PdbPointer   = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageContext.ImageAddress);\r
+  PeCoffLoaderRelocateImageExtraAction (&ImageContext);\r
 \r
   //\r
   // Initialize the Global Coherency Domain Services\r
@@ -296,14 +328,21 @@ DxeMain (
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
-  // Initialize the ReportStatusCode with PEI version, if available\r
+  // If Loading modules At fixed address feature is enabled, install Load moduels at fixed address\r
+  // Configuration Table so that user could easily to retrieve the top address to load Dxe and PEI\r
+  // Code and Tseg base to load SMM driver.\r
   //\r
-  CoreGetPeiProtocol (&gEfiStatusCodeRuntimeProtocolGuid, (VOID **) &gStatusCode->ReportStatusCode);\r
-\r
+  if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {\r
+    Status = CoreInstallConfigurationTable (&gLoadFixedAddressConfigurationTableGuid, &gLoadModuleAtFixAddressConfigurationTable);\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
   //\r
   // Report Status Code here for DXE_ENTRY_POINT once it is available\r
   //\r
-  CoreReportProgressCode (FixedPcdGet32(PcdStatusCodeValueDxeCoreEntry));\r
+  REPORT_STATUS_CODE (\r
+    EFI_PROGRESS_CODE,\r
+    (EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_ENTRY_POINT)\r
+    );\r
 \r
   //\r
   // Create the aligned system table pointer structure that is used by external\r
@@ -319,12 +358,52 @@ DxeMain (
 \r
   DEBUG ((DEBUG_INFO | DEBUG_LOAD, "HOBLIST address in DXE = 0x%p\n", HobStart));\r
 \r
+  DEBUG_CODE_BEGIN ();\r
+    EFI_PEI_HOB_POINTERS               Hob;\r
+\r
+    for (Hob.Raw = HobStart; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {\r
+      if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_MEMORY_ALLOCATION) {\r
+        DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Memory Allocation 0x%08x 0x%0lx - 0x%0lx\n", \\r
+          Hob.MemoryAllocation->AllocDescriptor.MemoryType,                      \\r
+          Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress,               \\r
+          Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress + Hob.MemoryAllocation->AllocDescriptor.MemoryLength - 1));\r
+      }\r
+    }\r
+    for (Hob.Raw = HobStart; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {\r
+      if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV2) {\r
+        DEBUG ((DEBUG_INFO | DEBUG_LOAD, "FV2 Hob           0x%0lx - 0x%0lx\n", Hob.FirmwareVolume2->BaseAddress, Hob.FirmwareVolume2->BaseAddress + Hob.FirmwareVolume2->Length - 1));\r
+      } else if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV) {\r
+        DEBUG ((DEBUG_INFO | DEBUG_LOAD, "FV Hob            0x%0lx - 0x%0lx\n", Hob.FirmwareVolume->BaseAddress, Hob.FirmwareVolume->BaseAddress + Hob.FirmwareVolume2->Length - 1));\r
+      }\r
+    }\r
+  DEBUG_CODE_END ();\r
+\r
   //\r
   // Initialize the Event Services\r
   //\r
   Status = CoreInitializeEventServices ();\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  MemoryProfileInstallProtocol ();\r
+\r
+  //\r
+  // Get persisted vector hand-off info from GUIDeed HOB again due to HobStart may be updated,\r
+  // and install configuration table\r
+  //\r
+  GuidHob = GetNextGuidHob (&gEfiVectorHandoffInfoPpiGuid, HobStart);\r
+  if (GuidHob != NULL) {\r
+    VectorInfoList = (EFI_VECTOR_HANDOFF_INFO *) (GET_GUID_HOB_DATA(GuidHob));\r
+    VectorInfo = VectorInfoList;\r
+    Index = 1;\r
+    while (VectorInfo->Attribute != EFI_VECTOR_HANDOFF_LAST_ENTRY) {\r
+      VectorInfo ++;\r
+      Index ++;\r
+    }\r
+    VectorInfo = AllocateCopyPool (sizeof (EFI_VECTOR_HANDOFF_INFO) * Index, (VOID *) VectorInfoList);\r
+    ASSERT (VectorInfo != NULL);\r
+    Status = CoreInstallConfigurationTable (&gEfiVectorHandoffTableGuid, (VOID *) VectorInfo);\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
 \r
   //\r
   // Get the Protocols that were passed in from PEI to DXE through GUIDed HOBs\r
@@ -351,8 +430,9 @@ DxeMain (
   //\r
   // Register for the GUIDs of the Architectural Protocols, so the rest of the\r
   // EFI Boot Services and EFI Runtime Services tables can be filled in.\r
+  // Also register for the GUIDs of optional protocols.\r
   //\r
-  CoreNotifyOnArchProtocolInstallation ();\r
+  CoreNotifyOnProtocolInstallation ();\r
 \r
   //\r
   // Produce Firmware Volume Protocols, one for each FV in the HOB list.\r
@@ -372,16 +452,16 @@ DxeMain (
   //\r
   // Initialize the DXE Dispatcher\r
   //\r
-  PERF_START (0,"CoreInitializeDispatcher", "DxeMain", 0) ;\r
+  PERF_START (NULL,"CoreInitializeDispatcher", "DxeMain", 0) ;\r
   CoreInitializeDispatcher ();\r
-  PERF_END (0,"CoreInitializeDispatcher", "DxeMain", 0) ;\r
+  PERF_END (NULL,"CoreInitializeDispatcher", "DxeMain", 0) ;\r
 \r
   //\r
   // Invoke the DXE Dispatcher\r
   //\r
-  PERF_START (0, "CoreDispatcher", "DxeMain", 0);\r
+  PERF_START (NULL, "CoreDispatcher", "DxeMain", 0);\r
   CoreDispatcher ();\r
-  PERF_END (0, "CoreDispatcher", "DxeMain", 0);\r
+  PERF_END (NULL, "CoreDispatcher", "DxeMain", 0);\r
 \r
   //\r
   // Display Architectural protocols that were not loaded if this is DEBUG build\r
@@ -391,22 +471,35 @@ DxeMain (
   DEBUG_CODE_END ();\r
 \r
   //\r
-  // Assert if the Architectural Protocols are not present.\r
+  // Display any drivers that were not dispatched because dependency expression\r
+  // evaluated to false if this is a debug build\r
   //\r
-  ASSERT_EFI_ERROR (CoreAllEfiServicesAvailable ());\r
+  DEBUG_CODE_BEGIN ();\r
+    CoreDisplayDiscoveredNotDispatched ();\r
+  DEBUG_CODE_END ();\r
 \r
   //\r
-  // Report Status code before transfer control to BDS\r
+  // Assert if the Architectural Protocols are not present.\r
   //\r
-  CoreReportProgressCode (FixedPcdGet32 (PcdStatusCodeValueDxeCoreHandoffToBds));\r
+  Status = CoreAllEfiServicesAvailable ();\r
+  if (EFI_ERROR(Status)) {\r
+    //\r
+    // Report Status code that some Architectural Protocols are not present.\r
+    //\r
+    REPORT_STATUS_CODE (\r
+      EFI_ERROR_CODE | EFI_ERROR_MAJOR,\r
+      (EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_EC_NO_ARCH)\r
+      );    \r
+  }\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
-  // Display any drivers that were not dispatched because dependency expression\r
-  // evaluated to false if this is a debug build\r
+  // Report Status code before transfer control to BDS\r
   //\r
-  DEBUG_CODE_BEGIN ();\r
-    CoreDisplayDiscoveredNotDispatched ();\r
-  DEBUG_CODE_END ();\r
+  REPORT_STATUS_CODE (\r
+    EFI_PROGRESS_CODE,\r
+    (EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_HANDOFF_TO_NEXT)\r
+    );\r
 \r
   //\r
   // Transfer control to the BDS Architectural Protocol\r
@@ -586,42 +679,6 @@ CoreEfiNotAvailableYetArg5 (
 }\r
 \r
 \r
-\r
-/**\r
-  Searches for a Protocol Interface passed from PEI through a HOB.\r
-\r
-  @param  ProtocolGuid           The Protocol GUID to search for in the HOB List\r
-  @param  Interface              A pointer to the interface for the Protocol GUID\r
-\r
-  @retval EFI_SUCCESS            The Protocol GUID was found and its interface is\r
-                                 returned in Interface\r
-  @retval EFI_NOT_FOUND          The Protocol GUID was not found in the HOB List\r
-\r
-**/\r
-EFI_STATUS\r
-CoreGetPeiProtocol (\r
-  IN EFI_GUID  *ProtocolGuid,\r
-  IN VOID      **Interface\r
-  )\r
-{\r
-  EFI_HOB_GUID_TYPE   *GuidHob;\r
-  VOID                *Buffer;\r
-\r
-  GuidHob = GetFirstGuidHob (ProtocolGuid);\r
-  if (GuidHob == NULL) {\r
-    return EFI_NOT_FOUND;\r
-  }\r
-\r
-  Buffer = GET_GUID_HOB_DATA (GuidHob);\r
-  ASSERT (Buffer != NULL);\r
-\r
-  *Interface = (VOID *)(*(UINTN *)(Buffer));\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
-\r
 /**\r
   Calcualte the 32-bit CRC in a EFI table using the service provided by the\r
   gRuntime service.\r
@@ -648,8 +705,6 @@ CalculateEfiHdrCrc (
 }\r
 \r
 \r
-\r
-\r
 /**\r
   Terminates all boot services.\r
 \r
@@ -668,23 +723,11 @@ CoreExitBootServices (
   )\r
 {\r
   EFI_STATUS                Status;\r
-  EFI_STATUS                StatusTemp;\r
-  EFI_TCG_PLATFORM_PROTOCOL *TcgPlatformProtocol;\r
 \r
   //\r
-  // Measure invocation of ExitBootServices,\r
-  // which is defined by TCG_EFI_Platform_1_20_Final Specification\r
+  // Disable Timer\r
   //\r
-  TcgPlatformProtocol = NULL;\r
-  Status = CoreLocateProtocol (\r
-             &gEfiTcgPlatformProtocolGuid,\r
-             NULL,\r
-             (VOID **) &TcgPlatformProtocol\r
-             );\r
-  if (!EFI_ERROR (Status)) {\r
-    Status = TcgPlatformProtocol->MeasureAction (EFI_EXIT_BOOT_SERVICES_INVOCATION);\r
-    ASSERT_EFI_ERROR (Status);\r
-  }\r
+  gTimer->SetTimerPeriod (gTimer, 0);\r
 \r
   //\r
   // Terminate memory services if the MapKey matches\r
@@ -692,13 +735,9 @@ CoreExitBootServices (
   Status = CoreTerminateMemoryMap (MapKey);\r
   if (EFI_ERROR (Status)) {\r
     //\r
-    // Measure failure of ExitBootServices\r
+    // Notify other drivers that ExitBootServices fail \r
     //\r
-    if (TcgPlatformProtocol != NULL) {\r
-      StatusTemp = TcgPlatformProtocol->MeasureAction (EFI_EXIT_BOOT_SERVICES_FAILED);\r
-      ASSERT_EFI_ERROR (StatusTemp);\r
-    }\r
-\r
+    CoreNotifySignalList (&gEventExitBootServicesFailedGuid);\r
     return Status;\r
   }\r
 \r
@@ -708,21 +747,22 @@ CoreExitBootServices (
   CoreNotifySignalList (&gEfiEventExitBootServicesGuid);\r
 \r
   //\r
-  // Disable Timer\r
+  // Report that ExitBootServices() has been called\r
   //\r
-  gTimer->SetTimerPeriod (gTimer, 0);\r
+  REPORT_STATUS_CODE (\r
+    EFI_PROGRESS_CODE,\r
+    (EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_BS_PC_EXIT_BOOT_SERVICES)\r
+    );\r
 \r
   //\r
-  // Disable CPU Interrupts\r
+  // Disable interrupt of Debug timer.\r
   //\r
-  gCpu->DisableInterrupt (gCpu);\r
+  SaveAndSetDebugTimerInterrupt (FALSE);\r
 \r
   //\r
-  // Report that ExitBootServices() has been called\r
-  //\r
-  // We are using gEfiCallerIdGuid as the caller ID for Dxe Core\r
+  // Disable CPU Interrupts\r
   //\r
-  CoreReportProgressCode (FixedPcdGet32 (PcdStatusCodeValueBootServiceExit));\r
+  gCpu->DisableInterrupt (gCpu);\r
 \r
   //\r
   // Clear the non-runtime values of the EFI System Table\r
@@ -751,14 +791,6 @@ CoreExitBootServices (
   //\r
   gRuntime->AtRuntime = TRUE;\r
 \r
-  //\r
-  // Measure success of ExitBootServices\r
-  //\r
-  if (TcgPlatformProtocol != NULL) {\r
-    StatusTemp = TcgPlatformProtocol->MeasureAction (EFI_EXIT_BOOT_SERVICES_SUCCEEDED);\r
-    ASSERT_EFI_ERROR (StatusTemp);\r
-  }\r
-\r
   return Status;\r
 }\r
 \r
@@ -829,7 +861,7 @@ DxeMainUefiDecompressGetInfo (
   implementation. It is the caller's responsibility to allocate and free the\r
   Destination and Scratch buffers.\r
   If the compressed source data specified by Source and SourceSize is\r
-  sucessfully decompressed into Destination, then EFI_SUCCESS is returned. If\r
+  successfully decompressed into Destination, then EFI_SUCCESS is returned. If\r
   the compressed source data specified by Source and SourceSize is not in a\r
   valid compressed data format, then EFI_INVALID_PARAMETER is returned.\r
 \r