]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg BootScriptExecutorDxe: Fix S3 failure When PcdUse1GPageTable defined...
authorStar Zeng <star.zeng@intel.com>
Mon, 25 Nov 2013 06:20:18 +0000 (06:20 +0000)
committerlzeng14 <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 25 Nov 2013 06:20:18 +0000 (06:20 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14896 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf
MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.c
MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.h
MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/SetIdtEntry.c

index 04d4893a97c1c920de4937bf7d2d8cd9ed7959bd..4777f9d2ed91c863240b9fe5144f724c5c387940 100644 (file)
@@ -4,7 +4,7 @@
 # This is a standalone Boot Script Executor. Standalone means it does not\r
 # depends on any PEI or DXE service.\r
 #\r
-# Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
 #\r
 # This program and the accompanying materials are\r
 # licensed and made available under the terms and conditions of the BSD License\r
@@ -75,6 +75,9 @@
   gPerformanceProtocolGuid\r
   gEfiEventExitBootServicesGuid\r
 \r
+[Protocols]\r
+  gEfiDxeSmmReadyToLockProtocolGuid\r
+\r
 [FeaturePcd]\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode\r
 \r
index e34ead59fa1a820b96ea43dc93e90a993e0cba55..651a9dea546b861e6e6373c290c60cb52b074382 100644 (file)
@@ -1,10 +1,10 @@
 /** @file\r
   This is the code for Boot Script Executer module.\r
 \r
-  This driver is dispatched by Dxe core and the driver will reload itself to ACPI NVS memory\r
+  This driver is dispatched by Dxe core and the driver will reload itself to ACPI reserved memory\r
   in the entry point. The functionality is to interpret and restore the S3 boot script\r
 \r
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
 \r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
@@ -22,6 +22,8 @@ EFI_GUID              mBootScriptExecutorImageGuid = {
   0x9a8d3433, 0x9fe8, 0x42b6, { 0x87, 0xb, 0x1e, 0x31, 0xc8, 0x4e, 0xbe, 0x3b }\r
 };\r
 \r
+BOOLEAN               mPage1GSupport = FALSE;\r
+\r
 /**\r
   Entry function of Boot script exector. This function will be executed in\r
   S3 boot path.\r
@@ -205,6 +207,121 @@ S3BootScriptExecutorEntryFunction (
   CpuDeadLoop();\r
   return EFI_UNSUPPORTED;\r
 }\r
+\r
+/**\r
+  This is the Event notification function to reload BootScriptExecutor image\r
+  to RESERVED mem and save it to LockBox.\r
+  \r
+  @param    Event   Pointer to this event\r
+  @param    Context Event hanlder private data \r
+ **/\r
+VOID\r
+EFIAPI\r
+ReadyToLockEventNotify (\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
+  )\r
+{\r
+  EFI_STATUS                                    Status;\r
+  VOID                                          *Interface;\r
+  UINT8                                         *Buffer;\r
+  UINTN                                         BufferSize;\r
+  EFI_HANDLE                                    NewImageHandle;\r
+  UINTN                                         Pages;\r
+  EFI_PHYSICAL_ADDRESS                          FfsBuffer;\r
+  PE_COFF_LOADER_IMAGE_CONTEXT                  ImageContext;\r
+\r
+  Status = gBS->LocateProtocol (&gEfiDxeSmmReadyToLockProtocolGuid, NULL, &Interface);\r
+  if (EFI_ERROR (Status)) {\r
+    return;\r
+  }\r
+\r
+  //\r
+  // A workaround: Here we install a dummy handle\r
+  //\r
+  NewImageHandle = NULL;\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &NewImageHandle,\r
+                  &gEfiCallerIdGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Reload BootScriptExecutor image itself to RESERVED mem\r
+  //\r
+  Status = GetSectionFromAnyFv  (\r
+             &gEfiCallerIdGuid,\r
+             EFI_SECTION_PE32,\r
+             0,\r
+             (VOID **) &Buffer,\r
+             &BufferSize\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+  ImageContext.Handle    = Buffer;\r
+  ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;\r
+  //\r
+  // Get information about the image being loaded\r
+  //\r
+  Status = PeCoffLoaderGetImageInfo (&ImageContext);\r
+  ASSERT_EFI_ERROR (Status);\r
+  Pages = EFI_SIZE_TO_PAGES(BufferSize + ImageContext.SectionAlignment);\r
+  FfsBuffer = 0xFFFFFFFF;\r
+  Status = gBS->AllocatePages (\r
+                  AllocateMaxAddress,\r
+                  EfiReservedMemoryType,\r
+                  Pages,\r
+                  &FfsBuffer\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+  ImageContext.ImageAddress = (PHYSICAL_ADDRESS)(UINTN)FfsBuffer;\r
+  //\r
+  // Align buffer on section boundry\r
+  //\r
+  ImageContext.ImageAddress += ImageContext.SectionAlignment - 1;\r
+  ImageContext.ImageAddress &= ~(ImageContext.SectionAlignment - 1);\r
+  //\r
+  // Load the image to our new buffer\r
+  //\r
+  Status = PeCoffLoaderLoadImage (&ImageContext);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Relocate the image in our new buffer\r
+  //\r
+  Status = PeCoffLoaderRelocateImage (&ImageContext);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Free the buffer allocated by ReadSection since the image has been relocated in the new buffer\r
+  //\r
+  gBS->FreePool (Buffer);\r
+\r
+  //\r
+  // Flush the instruction cache so the image data is written before we execute it\r
+  //\r
+  InvalidateInstructionCacheRange ((VOID *)(UINTN)ImageContext.ImageAddress, (UINTN)ImageContext.ImageSize);\r
+  Status = ((EFI_IMAGE_ENTRY_POINT)(UINTN)(ImageContext.EntryPoint)) (NewImageHandle, gST);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Additional step for BootScript integrity\r
+  // Save BootScriptExecutor image\r
+  //\r
+  Status = SaveLockBox (\r
+             &mBootScriptExecutorImageGuid,\r
+             (VOID *)(UINTN)ImageContext.ImageAddress,\r
+             (UINTN)ImageContext.ImageSize\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = SetLockBoxAttributes (&mBootScriptExecutorImageGuid, LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  gBS->CloseEvent (Event);\r
+}\r
+\r
 /**\r
   Entrypoint of Boot script exector driver, this function will be executed in\r
   normal boot phase and invoked by DXE dispatch.\r
@@ -222,16 +339,16 @@ BootScriptExecutorEntryPoint (
   IN EFI_SYSTEM_TABLE     *SystemTable\r
   )\r
 {\r
-  UINT8                                         *Buffer;\r
   UINTN                                         BufferSize;\r
   UINTN                                         Pages;\r
-  EFI_PHYSICAL_ADDRESS                          FfsBuffer;\r
-  PE_COFF_LOADER_IMAGE_CONTEXT                  ImageContext;\r
   BOOT_SCRIPT_EXECUTOR_VARIABLE                 *EfiBootScriptExecutorVariable;\r
   EFI_PHYSICAL_ADDRESS                          BootScriptExecutorBuffer;\r
   EFI_STATUS                                    Status;\r
   VOID                                          *DevicePath;\r
-  EFI_HANDLE                                    NewImageHandle;\r
+  EFI_EVENT                                     ReadyToLockEvent;\r
+  VOID                                          *Registration;\r
+  UINT32                                        RegEax;\r
+  UINT32                                        RegEdx;\r
 \r
   //\r
   // Test if the gEfiCallerIdGuid of this image is already installed. if not, the entry\r
@@ -240,94 +357,32 @@ BootScriptExecutorEntryPoint (
   //\r
   Status = gBS->LocateProtocol (&gEfiCallerIdGuid, NULL, &DevicePath);\r
   if (EFI_ERROR (Status)) {\r
-\r
-      //\r
-      // This is the first-time loaded by DXE core. reload itself to RESERVED mem\r
-      //\r
-      //\r
-      // A workaround: Here we install a dummy handle\r
-      //\r
-      NewImageHandle = NULL;\r
-      Status = gBS->InstallProtocolInterface (\r
-                  &NewImageHandle,\r
-                  &gEfiCallerIdGuid,\r
-                  EFI_NATIVE_INTERFACE,\r
-                  NULL\r
-                  );\r
-      ASSERT_EFI_ERROR (Status);\r
-\r
-      Status = GetSectionFromAnyFv  (\r
-                 &gEfiCallerIdGuid,\r
-                 EFI_SECTION_PE32,\r
-                 0,\r
-                 (VOID **) &Buffer,\r
-                 &BufferSize\r
-                 );\r
-      ASSERT_EFI_ERROR (Status);\r
-      ImageContext.Handle    = Buffer;\r
-      ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;\r
-      //\r
-      // Get information about the image being loaded\r
-      //\r
-      Status = PeCoffLoaderGetImageInfo (&ImageContext);\r
-      ASSERT_EFI_ERROR (Status);\r
-      Pages = EFI_SIZE_TO_PAGES(BufferSize + ImageContext.SectionAlignment);\r
-      FfsBuffer = 0xFFFFFFFF;\r
-      Status = gBS->AllocatePages (\r
-                    AllocateMaxAddress,\r
-                    EfiReservedMemoryType,\r
-                    Pages,\r
-                    &FfsBuffer\r
-                    );\r
-      ASSERT_EFI_ERROR (Status);\r
-      ImageContext.ImageAddress = (PHYSICAL_ADDRESS)(UINTN)FfsBuffer;\r
-      //\r
-      // Align buffer on section boundry\r
       //\r
-      ImageContext.ImageAddress += ImageContext.SectionAlignment - 1;\r
-      ImageContext.ImageAddress &= ~(ImageContext.SectionAlignment - 1);\r
+      // Create ReadyToLock event to reload BootScriptExecutor image\r
+      // to RESERVED mem and save it to LockBox.\r
       //\r
-      // Load the image to our new buffer\r
-      //\r
-      Status = PeCoffLoaderLoadImage (&ImageContext);\r
-      ASSERT_EFI_ERROR (Status);\r
-\r
-      //\r
-      // Relocate the image in our new buffer\r
-      //\r
-      Status = PeCoffLoaderRelocateImage (&ImageContext);\r
-      ASSERT_EFI_ERROR (Status);\r
-\r
-      //\r
-      // Free the buffer allocated by ReadSection since the image has been relocated in the new buffer\r
-      //\r
-      gBS->FreePool (Buffer);\r
-\r
-      //\r
-      // Flush the instruction cache so the image data is written before we execute it\r
-      //\r
-      InvalidateInstructionCacheRange ((VOID *)(UINTN)ImageContext.ImageAddress, (UINTN)ImageContext.ImageSize);\r
-      Status = ((EFI_IMAGE_ENTRY_POINT)(UINTN)(ImageContext.EntryPoint)) (NewImageHandle, SystemTable);\r
-      ASSERT_EFI_ERROR (Status);\r
-\r
-      //\r
-      // Additional step for BootScript integrity\r
-      // Save BootScriptExecutor image\r
-      //\r
-      Status = SaveLockBox (\r
-                 &mBootScriptExecutorImageGuid,\r
-                 (VOID *)(UINTN)ImageContext.ImageAddress,\r
-                 (UINTN)ImageContext.ImageSize\r
-                 );\r
-      ASSERT_EFI_ERROR (Status);\r
-\r
-      Status = SetLockBoxAttributes (&mBootScriptExecutorImageGuid, LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE);\r
-      ASSERT_EFI_ERROR (Status);\r
-\r
+      ReadyToLockEvent = EfiCreateProtocolNotifyEvent  (\r
+                           &gEfiDxeSmmReadyToLockProtocolGuid,\r
+                           TPL_NOTIFY,\r
+                           ReadyToLockEventNotify,\r
+                           NULL,\r
+                           &Registration\r
+                           );\r
+      ASSERT (ReadyToLockEvent != NULL);\r
     } else {\r
       //\r
       // the entry point is invoked after reloading. following code only run in RESERVED mem\r
       //\r
+      if (PcdGetBool(PcdUse1GPageTable)) {\r
+        AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);\r
+        if (RegEax >= 0x80000001) {\r
+          AsmCpuid (0x80000001, NULL, NULL, NULL, &RegEdx);\r
+          if ((RegEdx & BIT26) != 0) {\r
+            mPage1GSupport = TRUE;\r
+          }\r
+        }\r
+      }\r
+\r
       BufferSize = sizeof (BOOT_SCRIPT_EXECUTOR_VARIABLE);\r
 \r
       BootScriptExecutorBuffer = 0xFFFFFFFF;\r
@@ -363,11 +418,8 @@ BootScriptExecutorEntryPoint (
 \r
       Status = SetLockBoxAttributes (&gEfiBootScriptExecutorContextGuid, LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE);\r
       ASSERT_EFI_ERROR (Status);\r
-\r
     }\r
 \r
     return EFI_SUCCESS;\r
 }\r
 \r
-\r
-\r
index 707ab8ca686bd933b6e7580000a652a33fd3e678..a3522905a84fb06c79659a9a3bce8c10cffe16f8 100644 (file)
@@ -1,10 +1,10 @@
 /** @file\r
   The header file for Boot Script Executer module.\r
   \r
-  This driver is dispatched by Dxe core and the driver will reload itself to ACPI NVS memory \r
+  This driver is dispatched by Dxe core and the driver will reload itself to ACPI reserved memory \r
   in the entry point. The functionality is to interpret and restore the S3 boot script \r
   \r
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
 \r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
@@ -39,7 +39,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include <Guid/AcpiS3Context.h>\r
 #include <Guid/BootScriptExecutorVariable.h>\r
-#include <Guid/EventGroup.h>\r
+#include <Protocol/DxeSmmReadyToLock.h>\r
 #include <IndustryStandard/Acpi.h>\r
 /**\r
   a ASM function to transfer control to OS.\r
@@ -83,5 +83,6 @@ SetIdtEntry (
 \r
 extern UINT32 AsmFixAddress16;\r
 extern UINT32 AsmJmpAddr32;\r
+extern BOOLEAN mPage1GSupport;\r
 \r
 #endif //_BOOT_SCRIPT_EXECUTOR_H_\r
index 2d15f5b5d122ab72dfa4e3f4b2cabd16ecbc7988..e42e6d4fe198eac45ef6d6c984a9eaba4e9ea6b5 100644 (file)
@@ -21,7 +21,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define IA32_PG_PS                  BIT7\r
 \r
 UINT64                             mPhyMask;\r
-BOOLEAN                            mPage1GSupport;\r
 VOID                               *mOriginalHandler;\r
 UINTN                              mS3NvsPageTableAddress;\r
 \r
@@ -47,23 +46,18 @@ HookPageFaultHandler (
   )\r
 {\r
   UINT32         RegEax;\r
-  UINT32         RegEdx;\r
+  UINT8          PhysicalAddressBits;\r
   UINTN          PageFaultHandlerHookAddress;\r
 \r
-  AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);\r
-  mPhyMask = LShiftU64 (1, (UINT8)RegEax) - 1;\r
-  mPhyMask &= (1ull << 48) - SIZE_4KB;\r
-\r
-  mPage1GSupport = FALSE;\r
-  if (PcdGetBool(PcdUse1GPageTable)) {\r
-    AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);\r
-    if (RegEax >= 0x80000001) {\r
-      AsmCpuid (0x80000001, NULL, NULL, NULL, &RegEdx);\r
-      if ((RegEdx & BIT26) != 0) {\r
-        mPage1GSupport = TRUE;\r
-      }\r
-    }\r
+  AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);\r
+  if (RegEax >= 0x80000008) {\r
+    AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);\r
+    PhysicalAddressBits = (UINT8) RegEax;\r
+  } else {\r
+    PhysicalAddressBits = 36;\r
   }\r
+  mPhyMask = LShiftU64 (1, PhysicalAddressBits) - 1;\r
+  mPhyMask &= (1ull << 48) - SIZE_4KB;\r
 \r
   //\r
   // Set Page Fault entry to catch >4G access\r