]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.c
MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe: Add support for PCD PcdPteMemoryEn...
[mirror_edk2.git] / MdeModulePkg / Universal / Acpi / BootScriptExecutorDxe / ScriptExecute.c
index ab185874c0e53b4d3398753e40cb8bc36a350698..22d434914befa9c96700791af381fda4276ee1d2 100644 (file)
@@ -4,7 +4,8 @@
   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 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2017, AMD Incorporated. 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
@@ -23,6 +24,7 @@ EFI_GUID              mBootScriptExecutorImageGuid = {
 };\r
 \r
 BOOLEAN               mPage1GSupport = FALSE;\r
+UINT64                mAddressEncMask = 0;\r
 \r
 /**\r
   Entry function of Boot script exector. This function will be executed in\r
@@ -208,6 +210,47 @@ S3BootScriptExecutorEntryFunction (
   return EFI_UNSUPPORTED;\r
 }\r
 \r
+/**\r
+  Register image to memory profile.\r
+\r
+  @param FileName       File name of the image.\r
+  @param ImageBase      Image base address.\r
+  @param ImageSize      Image size.\r
+  @param FileType       File type of the image.\r
+\r
+**/\r
+VOID\r
+RegisterMemoryProfileImage (\r
+  IN EFI_GUID                       *FileName,\r
+  IN PHYSICAL_ADDRESS               ImageBase,\r
+  IN UINT64                         ImageSize,\r
+  IN EFI_FV_FILETYPE                FileType\r
+  )\r
+{\r
+  EFI_STATUS                        Status;\r
+  EDKII_MEMORY_PROFILE_PROTOCOL     *ProfileProtocol;\r
+  MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FilePath;\r
+  UINT8                             TempBuffer[sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH) + sizeof (EFI_DEVICE_PATH_PROTOCOL)];\r
+\r
+  if ((PcdGet8 (PcdMemoryProfilePropertyMask) & BIT0) != 0) {\r
+\r
+    FilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)TempBuffer;\r
+    Status = gBS->LocateProtocol (&gEdkiiMemoryProfileGuid, NULL, (VOID **) &ProfileProtocol);\r
+    if (!EFI_ERROR (Status)) {\r
+      EfiInitializeFwVolDevicepathNode (FilePath, FileName);\r
+      SetDevicePathEndNode (FilePath + 1);\r
+\r
+      Status = ProfileProtocol->RegisterImage (\r
+                                  ProfileProtocol,\r
+                                  (EFI_DEVICE_PATH_PROTOCOL *) FilePath,\r
+                                  ImageBase,\r
+                                  ImageSize,\r
+                                  FileType\r
+                                  );\r
+    }\r
+  }\r
+}\r
+\r
 /**\r
   This is the Event notification function to reload BootScriptExecutor image\r
   to RESERVED mem and save it to LockBox.\r
@@ -266,7 +309,11 @@ ReadyToLockEventNotify (
   //\r
   Status = PeCoffLoaderGetImageInfo (&ImageContext);\r
   ASSERT_EFI_ERROR (Status);\r
-  Pages = EFI_SIZE_TO_PAGES(BufferSize + ImageContext.SectionAlignment);\r
+  if (ImageContext.SectionAlignment > EFI_PAGE_SIZE) {\r
+    Pages = EFI_SIZE_TO_PAGES ((UINTN) (ImageContext.ImageSize + ImageContext.SectionAlignment));\r
+  } else {\r
+    Pages = EFI_SIZE_TO_PAGES ((UINTN) ImageContext.ImageSize);\r
+  }\r
   FfsBuffer = 0xFFFFFFFF;\r
   Status = gBS->AllocatePages (\r
                   AllocateMaxAddress,\r
@@ -277,10 +324,10 @@ ReadyToLockEventNotify (
   ASSERT_EFI_ERROR (Status);\r
   ImageContext.ImageAddress = (PHYSICAL_ADDRESS)(UINTN)FfsBuffer;\r
   //\r
-  // Align buffer on section boundry\r
+  // Align buffer on section boundary\r
   //\r
   ImageContext.ImageAddress += ImageContext.SectionAlignment - 1;\r
-  ImageContext.ImageAddress &= ~(ImageContext.SectionAlignment - 1);\r
+  ImageContext.ImageAddress &= ~((EFI_PHYSICAL_ADDRESS)(ImageContext.SectionAlignment - 1));\r
   //\r
   // Load the image to our new buffer\r
   //\r
@@ -302,6 +349,14 @@ ReadyToLockEventNotify (
   // 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
+\r
+  RegisterMemoryProfileImage (\r
+    &gEfiCallerIdGuid,\r
+    ImageContext.ImageAddress,\r
+    ImageContext.ImageSize,\r
+    EFI_FV_FILETYPE_DRIVER\r
+    );\r
+\r
   Status = ((EFI_IMAGE_ENTRY_POINT)(UINTN)(ImageContext.EntryPoint)) (NewImageHandle, gST);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
@@ -350,6 +405,15 @@ BootScriptExecutorEntryPoint (
   UINT32                                        RegEax;\r
   UINT32                                        RegEdx;\r
 \r
+  if (!PcdGetBool (PcdAcpiS3Enable)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Make sure AddressEncMask is contained to smallest supported address field.\r
+  //\r
+  mAddressEncMask = PcdGet64 (PcdPteMemoryEncryptionAddressOrMask) & PAGING_1G_ADDRESS_MASK_64;\r
+\r
   //\r
   // Test if the gEfiCallerIdGuid of this image is already installed. if not, the entry\r
   // point is loaded by DXE code which is the first time loaded. or else, it is already\r