]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/IntelVTdPmrPei.c
IntelSiliconPkg/VTdPmrPei: Add EndOfPei callback for S3
[mirror_edk2.git] / IntelSiliconPkg / Feature / VTd / IntelVTdPmrPei / IntelVTdPmrPei.c
index e7682749a6b01106690d8af37256db9e104b9c8d..3fe6d654cd2026225d5a0606d6c5ed9e78b6cf14 100644 (file)
 #include <IndustryStandard/Vtd.h>\r
 #include <Ppi/IoMmu.h>\r
 #include <Ppi/VtdInfo.h>\r
+#include <Ppi/EndOfPeiPhase.h>\r
 \r
 #include "IntelVTdPmrPei.h"\r
 \r
 #define  TOTAL_DMA_BUFFER_SIZE    SIZE_4MB\r
+#define  TOTAL_DMA_BUFFER_SIZE_S3 SIZE_1MB\r
 \r
 EFI_ACPI_DMAR_HEADER              *mAcpiDmarTable;\r
 VTD_INFO                          *mVTdInfo;\r
 UINT64                            mEngineMask;\r
 UINTN                             mDmaBufferBase;\r
-UINTN                             mDmaBufferSize = TOTAL_DMA_BUFFER_SIZE;\r
+UINTN                             mDmaBufferSize;\r
 UINTN                             mDmaBufferCurrentTop;\r
 UINTN                             mDmaBufferCurrentBottom;\r
 \r
@@ -544,6 +546,7 @@ InitDmaProtection (
   }\r
   ASSERT (DmaBufferSize == ALIGN_VALUE(DmaBufferSize, MemoryAlignment));\r
   *DmaBufferBase = (UINTN)AllocateAlignedPages (EFI_SIZE_TO_PAGES(DmaBufferSize), MemoryAlignment);\r
+  ASSERT (*DmaBufferBase != 0);\r
   if (*DmaBufferBase == 0) {\r
     DEBUG ((DEBUG_INFO, " InitDmaProtection : OutOfResource\n"));\r
     return EFI_OUT_OF_RESOURCES;\r
@@ -1104,6 +1107,41 @@ ParseDmarAcpiTableRmrr (
   }\r
 }\r
 \r
+/**\r
+  This function handles S3 resume task at the end of PEI\r
+\r
+  @param[in] PeiServices    Pointer to PEI Services Table.\r
+  @param[in] NotifyDesc     Pointer to the descriptor for the Notification event that\r
+                            caused this function to execute.\r
+  @param[in] Ppi            Pointer to the PPI data associated with this function.\r
+\r
+  @retval EFI_STATUS        Always return EFI_SUCCESS\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+S3EndOfPeiNotify(\r
+  IN EFI_PEI_SERVICES          **PeiServices,\r
+  IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,\r
+  IN VOID                      *Ppi\r
+  )\r
+{\r
+  UINT64                      EngineMask;\r
+\r
+  DEBUG((DEBUG_INFO, "VTdPmr S3EndOfPeiNotify\n"));\r
+\r
+  if ((PcdGet8(PcdVTdPolicyPropertyMask) & BIT1) == 0) {\r
+    EngineMask = LShiftU64 (1, mVTdInfo->VTdEngineCount) - 1;\r
+    DisableDmaProtection (EngineMask);\r
+  }\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_PEI_NOTIFY_DESCRIPTOR mS3EndOfPeiNotifyDesc = {\r
+  (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+  &gEfiEndOfPeiSignalPpiGuid,\r
+  S3EndOfPeiNotify\r
+};\r
+\r
 /**\r
   Initializes the Intel VTd PMR PEIM.\r
 \r
@@ -1122,11 +1160,14 @@ IntelVTdPmrInitialize (
   )\r
 {\r
   EFI_STATUS                  Status;\r
+  EFI_BOOT_MODE               BootMode;\r
 \r
   if ((PcdGet8(PcdVTdPolicyPropertyMask) & BIT0) == 0) {\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
+  PeiServicesGetBootMode (&BootMode);\r
+\r
   Status = PeiServicesLocatePpi (\r
              &gEdkiiVTdInfoPpiGuid,\r
              0,\r
@@ -1150,6 +1191,13 @@ IntelVTdPmrInitialize (
   //\r
   ParseDmarAcpiTableRmrr ();\r
 \r
+  if (BootMode == BOOT_ON_S3_RESUME) {\r
+    mDmaBufferSize = TOTAL_DMA_BUFFER_SIZE_S3;\r
+  } else {\r
+    mDmaBufferSize = TOTAL_DMA_BUFFER_SIZE;\r
+  }\r
+  DEBUG ((DEBUG_INFO, " DmaBufferSize : 0x%x\n", mDmaBufferSize));\r
+\r
   //\r
   // Find a pre-memory in resource hob as DMA buffer\r
   // Mark PEI memory to be DMA protected.\r
@@ -1160,7 +1208,6 @@ IntelVTdPmrInitialize (
   }\r
 \r
   DEBUG ((DEBUG_INFO, " DmaBufferBase : 0x%x\n", mDmaBufferBase));\r
-  DEBUG ((DEBUG_INFO, " DmaBufferSize : 0x%x\n", mDmaBufferSize));\r
 \r
   mDmaBufferCurrentTop = mDmaBufferBase + mDmaBufferSize;\r
   mDmaBufferCurrentBottom = mDmaBufferBase;\r
@@ -1171,6 +1218,14 @@ IntelVTdPmrInitialize (
   Status = PeiServicesInstallPpi (&mIoMmuPpiList);\r
   ASSERT_EFI_ERROR(Status);\r
 \r
+  //\r
+  // Register EndOfPei Notify for S3 to run FSP NotifyPhase\r
+  //\r
+  if (BootMode == BOOT_ON_S3_RESUME) {\r
+    Status = PeiServicesNotifyPpi (&mS3EndOfPeiNotifyDesc);\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+\r
   return Status;\r
 }\r
 \r