]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/IntelVTdPmrPei.c
IntelSiliconPkg/VtdPmrPei: Add premem support.
[mirror_edk2.git] / IntelSiliconPkg / Feature / VTd / IntelVTdPmrPei / IntelVTdPmrPei.c
index 3fe6d654cd2026225d5a0606d6c5ed9e78b6cf14..240a6d281737b84922276443c32c0bae88cc1665 100644 (file)
@@ -24,6 +24,7 @@
 #include <IndustryStandard/Vtd.h>\r
 #include <Ppi/IoMmu.h>\r
 #include <Ppi/VtdInfo.h>\r
+#include <Ppi/MemoryDiscovered.h>\r
 #include <Ppi/EndOfPeiPhase.h>\r
 \r
 #include "IntelVTdPmrPei.h"\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;\r
-UINTN                             mDmaBufferCurrentTop;\r
-UINTN                             mDmaBufferCurrentBottom;\r
+EFI_GUID mVTdInfoGuid = {\r
+  0x222f5e30, 0x5cd, 0x49c6, { 0x8a, 0xc, 0x36, 0xd6, 0x58, 0x41, 0xe0, 0x82 }\r
+};\r
+\r
+EFI_GUID mDmaBufferInfoGuid = {\r
+  0x7b624ec7, 0xfb67, 0x4f9c, { 0xb6, 0xb0, 0x4d, 0xfa, 0x9c, 0x88, 0x20, 0x39 }\r
+};\r
+\r
+typedef struct {\r
+  UINTN                             DmaBufferBase;\r
+  UINTN                             DmaBufferSize;\r
+  UINTN                             DmaBufferCurrentTop;\r
+  UINTN                             DmaBufferCurrentBottom;\r
+} DMA_BUFFER_INFO;\r
 \r
 #define MAP_INFO_SIGNATURE  SIGNATURE_32 ('D', 'M', 'A', 'P')\r
 typedef struct {\r
@@ -83,7 +91,6 @@ typedef struct {
               +------------------+ <=============== PLMR.Base (0)\r
 **/\r
 \r
-\r
 /**\r
   Set IOMMU attribute for a system memory.\r
 \r
@@ -149,8 +156,13 @@ PeiIoMmuMap (
   OUT    VOID                                       **Mapping\r
   )\r
 {\r
-  MAP_INFO   *MapInfo;\r
-  UINTN      Length;\r
+  MAP_INFO                    *MapInfo;\r
+  UINTN                       Length;\r
+  VOID                        *Hob;\r
+  DMA_BUFFER_INFO             *DmaBufferInfo;\r
+\r
+  Hob = GetFirstGuidHob (&mDmaBufferInfoGuid);\r
+  DmaBufferInfo = GET_GUID_HOB_DATA(Hob);\r
 \r
   if (Operation == EdkiiIoMmuOperationBusMasterCommonBuffer ||\r
       Operation == EdkiiIoMmuOperationBusMasterCommonBuffer64) {\r
@@ -160,18 +172,18 @@ PeiIoMmuMap (
   }\r
 \r
   DEBUG ((DEBUG_VERBOSE, "PeiIoMmuMap - HostAddress - 0x%x, NumberOfBytes - %x\n", HostAddress, *NumberOfBytes));\r
-  DEBUG ((DEBUG_VERBOSE, "  mDmaBufferCurrentTop - %x\n", mDmaBufferCurrentTop));\r
-  DEBUG ((DEBUG_VERBOSE, "  mDmaBufferCurrentBottom - %x\n", mDmaBufferCurrentBottom));\r
+  DEBUG ((DEBUG_VERBOSE, "  DmaBufferCurrentTop - %x\n", DmaBufferInfo->DmaBufferCurrentTop));\r
+  DEBUG ((DEBUG_VERBOSE, "  DmaBufferCurrentBottom - %x\n", DmaBufferInfo->DmaBufferCurrentBottom));\r
 \r
   Length = *NumberOfBytes + sizeof(MAP_INFO);\r
-  if (Length > mDmaBufferCurrentTop - mDmaBufferCurrentBottom) {\r
+  if (Length > DmaBufferInfo->DmaBufferCurrentTop - DmaBufferInfo->DmaBufferCurrentBottom) {\r
     DEBUG ((DEBUG_ERROR, "PeiIoMmuMap - OUT_OF_RESOURCE\n"));\r
     ASSERT (FALSE);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  *DeviceAddress = mDmaBufferCurrentBottom;\r
-  mDmaBufferCurrentBottom += Length;\r
+  *DeviceAddress = DmaBufferInfo->DmaBufferCurrentBottom;\r
+  DmaBufferInfo->DmaBufferCurrentBottom += Length;\r
 \r
   MapInfo = (VOID *)(UINTN)(*DeviceAddress + *NumberOfBytes);\r
   MapInfo->Signature     = MAP_INFO_SIGNATURE;\r
@@ -216,16 +228,21 @@ PeiIoMmuUnmap (
   IN  VOID                                     *Mapping\r
   )\r
 {\r
-  MAP_INFO   *MapInfo;\r
-  UINTN      Length;\r
+  MAP_INFO                    *MapInfo;\r
+  UINTN                       Length;\r
+  VOID                        *Hob;\r
+  DMA_BUFFER_INFO             *DmaBufferInfo;\r
+\r
+  Hob = GetFirstGuidHob (&mDmaBufferInfoGuid);\r
+  DmaBufferInfo = GET_GUID_HOB_DATA(Hob);\r
 \r
   if (Mapping == NULL) {\r
     return EFI_SUCCESS;\r
   }\r
 \r
   DEBUG ((DEBUG_VERBOSE, "PeiIoMmuUnmap - Mapping - %x\n", Mapping));\r
-  DEBUG ((DEBUG_VERBOSE, "  mDmaBufferCurrentTop - %x\n", mDmaBufferCurrentTop));\r
-  DEBUG ((DEBUG_VERBOSE, "  mDmaBufferCurrentBottom - %x\n", mDmaBufferCurrentBottom));\r
+  DEBUG ((DEBUG_VERBOSE, "  DmaBufferCurrentTop - %x\n", DmaBufferInfo->DmaBufferCurrentTop));\r
+  DEBUG ((DEBUG_VERBOSE, "  DmaBufferCurrentBottom - %x\n", DmaBufferInfo->DmaBufferCurrentBottom));\r
 \r
   MapInfo = Mapping;\r
   ASSERT (MapInfo->Signature == MAP_INFO_SIGNATURE);\r
@@ -246,8 +263,8 @@ PeiIoMmuUnmap (
   }\r
 \r
   Length = MapInfo->NumberOfBytes + sizeof(MAP_INFO);\r
-  if (mDmaBufferCurrentBottom == MapInfo->DeviceAddress + Length) {\r
-    mDmaBufferCurrentBottom -= Length;\r
+  if (DmaBufferInfo->DmaBufferCurrentBottom == MapInfo->DeviceAddress + Length) {\r
+    DmaBufferInfo->DmaBufferCurrentBottom -= Length;\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -282,20 +299,25 @@ PeiIoMmuAllocateBuffer (
   IN     UINT64                                   Attributes\r
   )\r
 {\r
-  UINTN  Length;\r
+  UINTN                       Length;\r
+  VOID                        *Hob;\r
+  DMA_BUFFER_INFO             *DmaBufferInfo;\r
+\r
+  Hob = GetFirstGuidHob (&mDmaBufferInfoGuid);\r
+  DmaBufferInfo = GET_GUID_HOB_DATA(Hob);\r
 \r
   DEBUG ((DEBUG_VERBOSE, "PeiIoMmuAllocateBuffer - page - %x\n", Pages));\r
-  DEBUG ((DEBUG_VERBOSE, "  mDmaBufferCurrentTop - %x\n", mDmaBufferCurrentTop));\r
-  DEBUG ((DEBUG_VERBOSE, "  mDmaBufferCurrentBottom - %x\n", mDmaBufferCurrentBottom));\r
+  DEBUG ((DEBUG_VERBOSE, "  DmaBufferCurrentTop - %x\n", DmaBufferInfo->DmaBufferCurrentTop));\r
+  DEBUG ((DEBUG_VERBOSE, "  DmaBufferCurrentBottom - %x\n", DmaBufferInfo->DmaBufferCurrentBottom));\r
 \r
   Length = EFI_PAGES_TO_SIZE(Pages);\r
-  if (Length > mDmaBufferCurrentTop - mDmaBufferCurrentBottom) {\r
+  if (Length > DmaBufferInfo->DmaBufferCurrentTop - DmaBufferInfo->DmaBufferCurrentBottom) {\r
     DEBUG ((DEBUG_ERROR, "PeiIoMmuAllocateBuffer - OUT_OF_RESOURCE\n"));\r
     ASSERT (FALSE);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  *HostAddress = (VOID *)(UINTN)(mDmaBufferCurrentTop - Length);\r
-  mDmaBufferCurrentTop -= Length;\r
+  *HostAddress = (VOID *)(UINTN)(DmaBufferInfo->DmaBufferCurrentTop - Length);\r
+  DmaBufferInfo->DmaBufferCurrentTop -= Length;\r
 \r
   DEBUG ((DEBUG_VERBOSE, "PeiIoMmuAllocateBuffer - allocate - %x\n", *HostAddress));\r
   return EFI_SUCCESS;\r
@@ -321,15 +343,20 @@ PeiIoMmuFreeBuffer (
   IN  VOID                                     *HostAddress\r
   )\r
 {\r
-  UINTN  Length;\r
+  UINTN                       Length;\r
+  VOID                        *Hob;\r
+  DMA_BUFFER_INFO             *DmaBufferInfo;\r
+\r
+  Hob = GetFirstGuidHob (&mDmaBufferInfoGuid);\r
+  DmaBufferInfo = GET_GUID_HOB_DATA(Hob);\r
 \r
   DEBUG ((DEBUG_VERBOSE, "PeiIoMmuFreeBuffer - page - %x, HostAddr - %x\n", Pages, HostAddress));\r
-  DEBUG ((DEBUG_VERBOSE, "  mDmaBufferCurrentTop - %x\n", mDmaBufferCurrentTop));\r
-  DEBUG ((DEBUG_VERBOSE, "  mDmaBufferCurrentBottom - %x\n", mDmaBufferCurrentBottom));\r
+  DEBUG ((DEBUG_VERBOSE, "  DmaBufferCurrentTop - %x\n", DmaBufferInfo->DmaBufferCurrentTop));\r
+  DEBUG ((DEBUG_VERBOSE, "  DmaBufferCurrentBottom - %x\n", DmaBufferInfo->DmaBufferCurrentBottom));\r
 \r
   Length = EFI_PAGES_TO_SIZE(Pages);\r
-  if ((UINTN)HostAddress == mDmaBufferCurrentTop) {\r
-    mDmaBufferCurrentTop += Length;\r
+  if ((UINTN)HostAddress == DmaBufferInfo->DmaBufferCurrentTop) {\r
+    DmaBufferInfo->DmaBufferCurrentTop += Length;\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -506,6 +533,7 @@ GetTopMemory (
 /**\r
   Initialize DMA protection.\r
 \r
+  @param VTdInfo        The VTd engine context information.\r
   @param DmaBufferSize  the DMA buffer size\r
   @param DmaBufferBase  the DMA buffer base\r
 \r
@@ -514,8 +542,9 @@ GetTopMemory (
 **/\r
 EFI_STATUS\r
 InitDmaProtection (\r
-  IN   UINTN  DmaBufferSize,\r
-  OUT  UINTN  *DmaBufferBase\r
+  IN   VTD_INFO                    *VTdInfo,\r
+  IN   UINTN                       DmaBufferSize,\r
+  OUT  UINTN                       *DmaBufferBase\r
   )\r
 {\r
   EFI_STATUS                  Status;\r
@@ -537,8 +566,8 @@ InitDmaProtection (
 \r
   ASSERT (PhitHob->EfiMemoryBottom < PhitHob->EfiMemoryTop);\r
 \r
-  LowMemoryAlignment = GetLowMemoryAlignment (mEngineMask);\r
-  HighMemoryAlignment = GetHighMemoryAlignment (mEngineMask);\r
+  LowMemoryAlignment = GetLowMemoryAlignment (VTdInfo, VTdInfo->EngineMask);\r
+  HighMemoryAlignment = GetHighMemoryAlignment (VTdInfo, VTdInfo->EngineMask);\r
   if (LowMemoryAlignment < HighMemoryAlignment) {\r
     MemoryAlignment = (UINTN)HighMemoryAlignment;\r
   } else {\r
@@ -558,12 +587,13 @@ InitDmaProtection (
   HighTop = GetTopMemory ();\r
 \r
   Status = SetDmaProtectedRange (\r
-               mEngineMask,\r
-               (UINT32)LowBottom,\r
-               (UINT32)(LowTop - LowBottom),\r
-               HighBottom,\r
-               HighTop - HighBottom\r
-               );\r
+             VTdInfo,\r
+             VTdInfo->EngineMask,\r
+             (UINT32)LowBottom,\r
+             (UINT32)(LowTop - LowBottom),\r
+             HighBottom,\r
+             HighTop - HighBottom\r
+             );\r
 \r
   if (EFI_ERROR(Status)) {\r
     FreePages ((VOID *)*DmaBufferBase, EFI_SIZE_TO_PAGES(DmaBufferSize));\r
@@ -573,542 +603,191 @@ InitDmaProtection (
 }\r
 \r
 /**\r
-  Dump DMAR DeviceScopeEntry.\r
+  Initializes the Intel VTd Info.\r
+\r
+  @retval EFI_SUCCESS            Usb bot driver is successfully initialized.\r
+  @retval EFI_OUT_OF_RESOURCES   Can't initialize the driver.\r
 \r
-  @param[in]  DmarDeviceScopeEntry  DMAR DeviceScopeEntry\r
 **/\r
-VOID\r
-DumpDmarDeviceScopeEntry (\r
-  IN EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER     *DmarDeviceScopeEntry\r
+EFI_STATUS\r
+InitVTdInfo (\r
+  VOID\r
   )\r
 {\r
-  UINTN   PciPathNumber;\r
-  UINTN   PciPathIndex;\r
-  EFI_ACPI_DMAR_PCI_PATH  *PciPath;\r
-\r
-  if (DmarDeviceScopeEntry == NULL) {\r
-    return;\r
-  }\r
-\r
-  DEBUG ((DEBUG_INFO,\r
-    "    *************************************************************************\n"\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    "    *       DMA-Remapping Device Scope Entry Structure                      *\n"\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    "    *************************************************************************\n"\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    (sizeof(UINTN) == sizeof(UINT64)) ?\r
-    "    DMAR Device Scope Entry address ...................... 0x%016lx\n" :\r
-    "    DMAR Device Scope Entry address ...................... 0x%08x\n",\r
-    DmarDeviceScopeEntry\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    "      Device Scope Entry Type ............................ 0x%02x\n",\r
-    DmarDeviceScopeEntry->Type\r
-    ));\r
-  switch (DmarDeviceScopeEntry->Type) {\r
-  case EFI_ACPI_DEVICE_SCOPE_ENTRY_TYPE_PCI_ENDPOINT:\r
-    DEBUG ((DEBUG_INFO,\r
-      "        PCI Endpoint Device\n"\r
-      ));\r
-    break;\r
-  case EFI_ACPI_DEVICE_SCOPE_ENTRY_TYPE_PCI_BRIDGE:\r
-    DEBUG ((DEBUG_INFO,\r
-      "        PCI Sub-hierachy\n"\r
-      ));\r
-    break;\r
-  default:\r
-    break;\r
-  }\r
-  DEBUG ((DEBUG_INFO,\r
-    "      Length ............................................. 0x%02x\n",\r
-    DmarDeviceScopeEntry->Length\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    "      Enumeration ID ..................................... 0x%02x\n",\r
-    DmarDeviceScopeEntry->EnumerationId\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    "      Starting Bus Number ................................ 0x%02x\n",\r
-    DmarDeviceScopeEntry->StartBusNumber\r
-    ));\r
-\r
-  PciPathNumber = (DmarDeviceScopeEntry->Length - sizeof(EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER)) / sizeof(EFI_ACPI_DMAR_PCI_PATH);\r
-  PciPath = (EFI_ACPI_DMAR_PCI_PATH *)(DmarDeviceScopeEntry + 1);\r
-  for (PciPathIndex = 0; PciPathIndex < PciPathNumber; PciPathIndex++) {\r
-    DEBUG ((DEBUG_INFO,\r
-      "      Device ............................................. 0x%02x\n",\r
-      PciPath[PciPathIndex].Device\r
-      ));\r
-    DEBUG ((DEBUG_INFO,\r
-      "      Function ........................................... 0x%02x\n",\r
-      PciPath[PciPathIndex].Function\r
-      ));\r
-  }\r
-\r
-  DEBUG ((DEBUG_INFO,\r
-    "    *************************************************************************\n\n"\r
-    ));\r
-\r
-  return;\r
-}\r
+  EFI_STATUS                  Status;\r
+  EFI_ACPI_DMAR_HEADER        *AcpiDmarTable;\r
+  VOID                        *Hob;\r
 \r
-/**\r
-  Dump DMAR RMRR table.\r
+  Status = PeiServicesLocatePpi (\r
+             &gEdkiiVTdInfoPpiGuid,\r
+             0,\r
+             NULL,\r
+             (VOID **)&AcpiDmarTable\r
+             );\r
+  ASSERT_EFI_ERROR(Status);\r
 \r
-  @param[in]  Rmrr  DMAR RMRR table\r
-**/\r
-VOID\r
-DumpDmarRmrr (\r
-  IN EFI_ACPI_DMAR_RMRR_HEADER *Rmrr\r
-  )\r
-{\r
-  EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER       *DmarDeviceScopeEntry;\r
-  INTN                                    RmrrLen;\r
+  DumpAcpiDMAR (AcpiDmarTable);\r
 \r
-  if (Rmrr == NULL) {\r
-    return;\r
+  //\r
+  // Clear old VTdInfo Hob.\r
+  //\r
+  Hob = GetFirstGuidHob (&mVTdInfoGuid);\r
+  if (Hob != NULL) {\r
+    ZeroMem (&((EFI_HOB_GUID_TYPE *)Hob)->Name, sizeof(EFI_GUID));\r
   }\r
 \r
-  DEBUG ((DEBUG_INFO,\r
-    "  ***************************************************************************\n"\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    "  *       Reserved Memory Region Reporting Structure                        *\n"\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    "  ***************************************************************************\n"\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    (sizeof(UINTN) == sizeof(UINT64)) ?\r
-    "  RMRR address ........................................... 0x%016lx\n" :\r
-    "  RMRR address ........................................... 0x%08x\n",\r
-    Rmrr\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    "    Type ................................................. 0x%04x\n",\r
-    Rmrr->Header.Type\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    "    Length ............................................... 0x%04x\n",\r
-    Rmrr->Header.Length\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    "    Segment Number ....................................... 0x%04x\n",\r
-    Rmrr->SegmentNumber\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    "    Reserved Memory Region Base Address .................. 0x%016lx\n",\r
-    Rmrr->ReservedMemoryRegionBaseAddress\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    "    Reserved Memory Region Limit Address ................. 0x%016lx\n",\r
-    Rmrr->ReservedMemoryRegionLimitAddress\r
-    ));\r
-\r
-  RmrrLen  = Rmrr->Header.Length - sizeof(EFI_ACPI_DMAR_RMRR_HEADER);\r
-  DmarDeviceScopeEntry = (EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER *)(Rmrr + 1);\r
-  while (RmrrLen > 0) {\r
-    DumpDmarDeviceScopeEntry (DmarDeviceScopeEntry);\r
-    RmrrLen -= DmarDeviceScopeEntry->Length;\r
-    DmarDeviceScopeEntry = (EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER *)((UINTN)DmarDeviceScopeEntry + DmarDeviceScopeEntry->Length);\r
+  //\r
+  // Get DMAR information to local VTdInfo\r
+  //\r
+  Status = ParseDmarAcpiTableDrhd (AcpiDmarTable);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
   }\r
 \r
-  DEBUG ((DEBUG_INFO,\r
-    "  ***************************************************************************\n\n"\r
-    ));\r
+  //\r
+  // NOTE: Do not parse RMRR here, because RMRR may cause PMR programming.\r
+  //\r
 \r
-  return;\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
-  Dump DMAR DRHD table.\r
+  Initializes the Intel VTd PMR for all memory.\r
+\r
+  @retval EFI_SUCCESS            Usb bot driver is successfully initialized.\r
+  @retval EFI_OUT_OF_RESOURCES   Can't initialize the driver.\r
 \r
-  @param[in]  Drhd  DMAR DRHD table\r
 **/\r
-VOID\r
-DumpDmarDrhd (\r
-  IN EFI_ACPI_DMAR_DRHD_HEADER *Drhd\r
+EFI_STATUS\r
+InitVTdPmrForAll (\r
+  VOID\r
   )\r
 {\r
-  EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER       *DmarDeviceScopeEntry;\r
-  INTN                                    DrhdLen;\r
+  EFI_STATUS                  Status;\r
+  VOID                        *Hob;\r
+  VTD_INFO                    *VTdInfo;\r
+  UINTN                       LowBottom;\r
+  UINTN                       LowTop;\r
+  UINTN                       HighBottom;\r
+  UINT64                      HighTop;\r
 \r
-  if (Drhd == NULL) {\r
-    return;\r
-  }\r
+  Hob = GetFirstGuidHob (&mVTdInfoGuid);\r
+  VTdInfo = GET_GUID_HOB_DATA(Hob);\r
 \r
-  DEBUG ((DEBUG_INFO,\r
-    "  ***************************************************************************\n"\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    "  *       DMA-Remapping Hardware Definition Structure                       *\n"\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    "  ***************************************************************************\n"\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    (sizeof(UINTN) == sizeof(UINT64)) ?\r
-    "  DRHD address ........................................... 0x%016lx\n" :\r
-    "  DRHD address ........................................... 0x%08x\n",\r
-    Drhd\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    "    Type ................................................. 0x%04x\n",\r
-    Drhd->Header.Type\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    "    Length ............................................... 0x%04x\n",\r
-    Drhd->Header.Length\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    "    Flags ................................................ 0x%02x\n",\r
-    Drhd->Flags\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    "      INCLUDE_PCI_ALL .................................... 0x%02x\n",\r
-    Drhd->Flags & EFI_ACPI_DMAR_DRHD_FLAGS_INCLUDE_PCI_ALL\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    "    Segment Number ....................................... 0x%04x\n",\r
-    Drhd->SegmentNumber\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    "    Register Base Address ................................ 0x%016lx\n",\r
-    Drhd->RegisterBaseAddress\r
-    ));\r
-\r
-  DrhdLen  = Drhd->Header.Length - sizeof(EFI_ACPI_DMAR_DRHD_HEADER);\r
-  DmarDeviceScopeEntry = (EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER *)(Drhd + 1);\r
-  while (DrhdLen > 0) {\r
-    DumpDmarDeviceScopeEntry (DmarDeviceScopeEntry);\r
-    DrhdLen -= DmarDeviceScopeEntry->Length;\r
-    DmarDeviceScopeEntry = (EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER *)((UINTN)DmarDeviceScopeEntry + DmarDeviceScopeEntry->Length);\r
-  }\r
+  LowBottom = 0;\r
+  LowTop = 0;\r
+  HighBottom = 0;\r
+  HighTop = LShiftU64 (1, VTdInfo->HostAddressWidth);\r
 \r
-  DEBUG ((DEBUG_INFO,\r
-    "  ***************************************************************************\n\n"\r
-    ));\r
+  Status = SetDmaProtectedRange (\r
+             VTdInfo,\r
+             VTdInfo->EngineMask,\r
+             (UINT32)LowBottom,\r
+             (UINT32)(LowTop - LowBottom),\r
+             HighBottom,\r
+             HighTop - HighBottom\r
+             );\r
 \r
-  return;\r
+  return Status;\r
 }\r
 \r
 /**\r
-  Dump DMAR ACPI table.\r
+  Initializes the Intel VTd PMR for DMA buffer.\r
+\r
+  @retval EFI_SUCCESS            Usb bot driver is successfully initialized.\r
+  @retval EFI_OUT_OF_RESOURCES   Can't initialize the driver.\r
 \r
-  @param[in]  Dmar  DMAR ACPI table\r
 **/\r
-VOID\r
-DumpAcpiDMAR (\r
-  IN EFI_ACPI_DMAR_HEADER  *Dmar\r
+EFI_STATUS\r
+InitVTdPmrForDma (\r
+  VOID\r
   )\r
 {\r
-  EFI_ACPI_DMAR_STRUCTURE_HEADER *DmarHeader;\r
-  INTN                  DmarLen;\r
+  EFI_STATUS                  Status;\r
+  VOID                        *Hob;\r
+  VTD_INFO                    *VTdInfo;\r
+  DMA_BUFFER_INFO             *DmaBufferInfo;\r
 \r
-  if (Dmar == NULL) {\r
-    return;\r
-  }\r
+  Hob = GetFirstGuidHob (&mVTdInfoGuid);\r
+  VTdInfo = GET_GUID_HOB_DATA(Hob);\r
 \r
   //\r
-  // Dump Dmar table\r
+  // If there is RMRR memory, parse it here.\r
   //\r
-  DEBUG ((DEBUG_INFO,\r
-    "*****************************************************************************\n"\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    "*         DMAR Table                                                        *\n"\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    "*****************************************************************************\n"\r
-    ));\r
-\r
-  DEBUG ((DEBUG_INFO,\r
-    (sizeof(UINTN) == sizeof(UINT64)) ?\r
-    "DMAR address ............................................. 0x%016lx\n" :\r
-    "DMAR address ............................................. 0x%08x\n",\r
-    Dmar\r
-    ));\r
-\r
-  DEBUG ((DEBUG_INFO,\r
-    "  Table Contents:\n"\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    "    Host Address Width ................................... 0x%02x\n",\r
-    Dmar->HostAddressWidth\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    "    Flags ................................................ 0x%02x\n",\r
-    Dmar->Flags\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    "      INTR_REMAP ......................................... 0x%02x\n",\r
-    Dmar->Flags & EFI_ACPI_DMAR_FLAGS_INTR_REMAP\r
-    ));\r
-  DEBUG ((DEBUG_INFO,\r
-    "      X2APIC_OPT_OUT_SET ................................. 0x%02x\n",\r
-    Dmar->Flags & EFI_ACPI_DMAR_FLAGS_X2APIC_OPT_OUT\r
-    ));\r
-\r
-  DmarLen  = Dmar->Header.Length - sizeof(EFI_ACPI_DMAR_HEADER);\r
-  DmarHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)(Dmar + 1);\r
-  while (DmarLen > 0) {\r
-    switch (DmarHeader->Type) {\r
-    case EFI_ACPI_DMAR_TYPE_DRHD:\r
-      DumpDmarDrhd ((EFI_ACPI_DMAR_DRHD_HEADER *)DmarHeader);\r
-      break;\r
-    case EFI_ACPI_DMAR_TYPE_RMRR:\r
-      DumpDmarRmrr ((EFI_ACPI_DMAR_RMRR_HEADER *)DmarHeader);\r
-      break;\r
-    default:\r
-      break;\r
-    }\r
-    DmarLen -= DmarHeader->Length;\r
-    DmarHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINTN)DmarHeader + DmarHeader->Length);\r
-  }\r
-\r
-  DEBUG ((DEBUG_INFO,\r
-    "*****************************************************************************\n\n"\r
-    ));\r
-\r
-  return;\r
-}\r
+  ParseDmarAcpiTableRmrr (VTdInfo);\r
 \r
-/**\r
-  Get VTd engine number.\r
+  Hob = GetFirstGuidHob (&mDmaBufferInfoGuid);\r
+  DmaBufferInfo = GET_GUID_HOB_DATA(Hob);\r
 \r
-  @return the VTd engine number.\r
-**/\r
-UINTN\r
-GetVtdEngineNumber (\r
-  VOID\r
-  )\r
-{\r
-  EFI_ACPI_DMAR_STRUCTURE_HEADER                    *DmarHeader;\r
-  UINTN                                             VtdIndex;\r
-\r
-  VtdIndex = 0;\r
-  DmarHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINTN)(mAcpiDmarTable + 1));\r
-  while ((UINTN)DmarHeader < (UINTN)mAcpiDmarTable + mAcpiDmarTable->Header.Length) {\r
-    switch (DmarHeader->Type) {\r
-    case EFI_ACPI_DMAR_TYPE_DRHD:\r
-      VtdIndex++;\r
-      break;\r
-    default:\r
-      break;\r
-    }\r
-    DmarHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINTN)DmarHeader + DmarHeader->Length);\r
+  DEBUG ((DEBUG_INFO, " DmaBufferSize : 0x%x\n", DmaBufferInfo->DmaBufferSize));\r
+  //\r
+  // Find a pre-memory in resource hob as DMA buffer\r
+  // Mark PEI memory to be DMA protected.\r
+  //\r
+  Status = InitDmaProtection (VTdInfo, DmaBufferInfo->DmaBufferSize, &DmaBufferInfo->DmaBufferBase);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
   }\r
-  return VtdIndex ;\r
-}\r
-\r
-/**\r
-  Process DMAR DHRD table.\r
-\r
-  @param[in]  VtdIndex  The index of VTd engine.\r
-  @param[in]  DmarDrhd  The DRHD table.\r
-**/\r
-VOID\r
-ProcessDhrd (\r
-  IN UINTN                      VtdIndex,\r
-  IN EFI_ACPI_DMAR_DRHD_HEADER  *DmarDrhd\r
-  )\r
-{\r
-  DEBUG ((DEBUG_INFO,"  VTD (%d) BaseAddress -  0x%016lx\n", VtdIndex, DmarDrhd->RegisterBaseAddress));\r
-  mVTdInfo->VTdEngineAddress[VtdIndex] = DmarDrhd->RegisterBaseAddress;\r
-}\r
 \r
-/**\r
-  Parse DMAR DRHD table.\r
-\r
-  @return EFI_SUCCESS  The DMAR DRHD table is parsed.\r
-**/\r
-EFI_STATUS\r
-ParseDmarAcpiTableDrhd (\r
-  VOID\r
-  )\r
-{\r
-  EFI_ACPI_DMAR_STRUCTURE_HEADER                    *DmarHeader;\r
-  UINTN                                             VtdUnitNumber;\r
-  UINTN                                             VtdIndex;\r
+  DEBUG ((DEBUG_INFO, " DmaBufferBase : 0x%x\n", DmaBufferInfo->DmaBufferBase));\r
 \r
-  VtdUnitNumber = GetVtdEngineNumber ();\r
-  if (VtdUnitNumber == 0) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
-  mVTdInfo = AllocateZeroPool (sizeof(VTD_INFO) + (VtdUnitNumber - 1) * sizeof(UINT64));\r
-  if (mVTdInfo == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-  mVTdInfo->HostAddressWidth = mAcpiDmarTable->HostAddressWidth;\r
-  mVTdInfo->VTdEngineCount   = VtdUnitNumber;\r
-\r
-  VtdIndex = 0;\r
-  DmarHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINTN)(mAcpiDmarTable + 1));\r
-  while ((UINTN)DmarHeader < (UINTN)mAcpiDmarTable + mAcpiDmarTable->Header.Length) {\r
-    switch (DmarHeader->Type) {\r
-    case EFI_ACPI_DMAR_TYPE_DRHD:\r
-      ASSERT (VtdIndex < VtdUnitNumber);\r
-      ProcessDhrd (VtdIndex, (EFI_ACPI_DMAR_DRHD_HEADER *)DmarHeader);\r
-      VtdIndex++;\r
-\r
-      break;\r
-\r
-    default:\r
-      break;\r
-    }\r
-    DmarHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINTN)DmarHeader + DmarHeader->Length);\r
-  }\r
-  ASSERT (VtdIndex == VtdUnitNumber);\r
+  DmaBufferInfo->DmaBufferCurrentTop = DmaBufferInfo->DmaBufferBase + DmaBufferInfo->DmaBufferSize;\r
+  DmaBufferInfo->DmaBufferCurrentBottom = DmaBufferInfo->DmaBufferBase;\r
 \r
   //\r
-  // Initialize the engine mask to all.\r
+  // Install PPI.\r
   //\r
-  mEngineMask = LShiftU64 (1, VtdUnitNumber) - 1;\r
+  Status = PeiServicesInstallPpi (&mIoMmuPpiList);\r
+  ASSERT_EFI_ERROR(Status);\r
 \r
-  return EFI_SUCCESS;\r
+  return Status;\r
 }\r
 \r
 /**\r
-  Return the VTd engine index according to the Segment and DevScopeEntry.\r
+  This function handles S3 resume task at the end of PEI\r
 \r
-  @param Segment         The segment of the VTd engine\r
-  @param DevScopeEntry   The DevScopeEntry of the VTd engine\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
-  @return The VTd engine index according to the Segment and DevScopeEntry.\r
-  @retval -1  The VTd engine is not found.\r
+  @retval EFI_STATUS        Always return EFI_SUCCESS\r
 **/\r
-UINTN\r
-GetVTdEngineFromDevScopeEntry (\r
-  IN  UINT16                                      Segment,\r
-  IN  EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER *DevScopeEntry\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
-  EFI_ACPI_DMAR_STRUCTURE_HEADER                    *DmarHeader;\r
-  UINTN                                             VtdIndex;\r
-  EFI_ACPI_DMAR_DRHD_HEADER                         *DmarDrhd;\r
-  EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER       *ThisDevScopeEntry;\r
-\r
-  VtdIndex = 0;\r
-  DmarHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINTN)(mAcpiDmarTable + 1));\r
-  while ((UINTN)DmarHeader < (UINTN)mAcpiDmarTable + mAcpiDmarTable->Header.Length) {\r
-    switch (DmarHeader->Type) {\r
-    case EFI_ACPI_DMAR_TYPE_DRHD:\r
-      DmarDrhd = (EFI_ACPI_DMAR_DRHD_HEADER *)DmarHeader;\r
-      if (DmarDrhd->SegmentNumber != Segment) {\r
-        // Mismatch\r
-        break;\r
-      }\r
-      if ((DmarDrhd->Header.Length == sizeof(EFI_ACPI_DMAR_DRHD_HEADER)) ||\r
-          ((DmarDrhd->Flags & EFI_ACPI_DMAR_DRHD_FLAGS_INCLUDE_PCI_ALL) != 0)) {\r
-        // No DevScopeEntry\r
-        // Do not handle PCI_ALL\r
-        break;\r
-      }\r
-      ThisDevScopeEntry = (EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER *)((UINTN)(DmarDrhd + 1));\r
-      while ((UINTN)ThisDevScopeEntry < (UINTN)DmarDrhd + DmarDrhd->Header.Length) {\r
-        if ((ThisDevScopeEntry->Length == DevScopeEntry->Length) &&\r
-            (CompareMem (ThisDevScopeEntry, DevScopeEntry, DevScopeEntry->Length) == 0)) {\r
-          return VtdIndex;\r
-        }\r
-        ThisDevScopeEntry = (EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER *)((UINTN)ThisDevScopeEntry + ThisDevScopeEntry->Length);\r
-      }\r
-      break;\r
-    default:\r
-      break;\r
-    }\r
-    DmarHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINTN)DmarHeader + DmarHeader->Length);\r
-  }\r
-  return (UINTN)-1;\r
-}\r
-\r
-/**\r
-  Process DMAR RMRR table.\r
+  VOID                        *Hob;\r
+  VTD_INFO                    *VTdInfo;\r
+  UINT64                      EngineMask;\r
 \r
-  @param[in]  DmarRmrr  The RMRR table.\r
-**/\r
-VOID\r
-ProcessRmrr (\r
-  IN EFI_ACPI_DMAR_RMRR_HEADER  *DmarRmrr\r
-  )\r
-{\r
-  EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER       *DmarDevScopeEntry;\r
-  UINTN                                             VTdIndex;\r
-  UINT64                                            RmrrMask;\r
-  UINTN                                             LowBottom;\r
-  UINTN                                             LowTop;\r
-  UINTN                                             HighBottom;\r
-  UINT64                                            HighTop;\r
-\r
-  DEBUG ((DEBUG_INFO,"  RMRR (Base 0x%016lx, Limit 0x%016lx)\n", DmarRmrr->ReservedMemoryRegionBaseAddress, DmarRmrr->ReservedMemoryRegionLimitAddress));\r
-\r
-  if ((DmarRmrr->ReservedMemoryRegionBaseAddress == 0) ||\r
-      (DmarRmrr->ReservedMemoryRegionLimitAddress == 0)) {\r
-    return ;\r
-  }\r
+  DEBUG((DEBUG_INFO, "VTdPmr S3EndOfPeiNotify\n"));\r
 \r
-  DmarDevScopeEntry = (EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER *)((UINTN)(DmarRmrr + 1));\r
-  while ((UINTN)DmarDevScopeEntry < (UINTN)DmarRmrr + DmarRmrr->Header.Length) {\r
-    ASSERT (DmarDevScopeEntry->Type == EFI_ACPI_DEVICE_SCOPE_ENTRY_TYPE_PCI_ENDPOINT);\r
-\r
-    VTdIndex = GetVTdEngineFromDevScopeEntry (DmarRmrr->SegmentNumber, DmarDevScopeEntry);\r
-    if (VTdIndex != (UINTN)-1) {\r
-      RmrrMask = LShiftU64 (1, VTdIndex);\r
-\r
-      LowBottom = 0;\r
-      LowTop = (UINTN)DmarRmrr->ReservedMemoryRegionBaseAddress;\r
-      HighBottom = (UINTN)DmarRmrr->ReservedMemoryRegionLimitAddress + 1;\r
-      HighTop = GetTopMemory ();\r
-\r
-      SetDmaProtectedRange (\r
-        RmrrMask,\r
-        0,\r
-        (UINT32)(LowTop - LowBottom),\r
-        HighBottom,\r
-        HighTop - HighBottom\r
-        );\r
-\r
-      //\r
-      // Remove the engine from the engine mask.\r
-      // The assumption is that any other PEI driver does not access\r
-      // the device covered by this engine.\r
-      //\r
-      mEngineMask = mEngineMask & (~RmrrMask);\r
+  if ((PcdGet8(PcdVTdPolicyPropertyMask) & BIT1) == 0) {\r
+    Hob = GetFirstGuidHob (&mVTdInfoGuid);\r
+    if (Hob == NULL) {\r
+      return EFI_SUCCESS;\r
     }\r
+    VTdInfo = GET_GUID_HOB_DATA(Hob);\r
 \r
-    DmarDevScopeEntry = (EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER *)((UINTN)DmarDevScopeEntry + DmarDevScopeEntry->Length);\r
+    EngineMask = LShiftU64 (1, VTdInfo->VTdEngineCount) - 1;\r
+    DisableDmaProtection (VTdInfo, EngineMask);\r
   }\r
+  return EFI_SUCCESS;\r
 }\r
 \r
-/**\r
-  Parse DMAR DRHD table.\r
-**/\r
-VOID\r
-ParseDmarAcpiTableRmrr (\r
-  VOID\r
-  )\r
-{\r
-  EFI_ACPI_DMAR_STRUCTURE_HEADER                    *DmarHeader;\r
-\r
-  DmarHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINTN)(mAcpiDmarTable + 1));\r
-  while ((UINTN)DmarHeader < (UINTN)mAcpiDmarTable + mAcpiDmarTable->Header.Length) {\r
-    switch (DmarHeader->Type) {\r
-    case EFI_ACPI_DMAR_TYPE_RMRR:\r
-      ProcessRmrr ((EFI_ACPI_DMAR_RMRR_HEADER *)DmarHeader);\r
-      break;\r
-    default:\r
-      break;\r
-    }\r
-    DmarHeader = (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINTN)DmarHeader + DmarHeader->Length);\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
-  This function handles S3 resume task at the end of PEI\r
+  This function handles VTd engine setup\r
 \r
   @param[in] PeiServices    Pointer to PEI Services Table.\r
   @param[in] NotifyDesc     Pointer to the descriptor for the Notification event that\r
@@ -1119,27 +798,80 @@ ParseDmarAcpiTableRmrr (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-S3EndOfPeiNotify(\r
+VTdInfoNotify (\r
   IN EFI_PEI_SERVICES          **PeiServices,\r
   IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,\r
   IN VOID                      *Ppi\r
   )\r
 {\r
-  UINT64                      EngineMask;\r
+  EFI_STATUS                  Status;\r
+  VOID                        *MemoryDiscovered;\r
+  UINT64                      EnabledEngineMask;\r
+  VOID                        *Hob;\r
+  VTD_INFO                    *VTdInfo;\r
+  BOOLEAN                     MemoryInitialized;\r
 \r
-  DEBUG((DEBUG_INFO, "VTdPmr S3EndOfPeiNotify\n"));\r
+  DEBUG ((DEBUG_INFO, "VTdInfoNotify\n"));\r
+\r
+  //\r
+  // Check if memory is initialized.\r
+  //\r
+  MemoryInitialized = FALSE;\r
+  Status = PeiServicesLocatePpi (\r
+             &gEfiPeiMemoryDiscoveredPpiGuid,\r
+             0,\r
+             NULL,\r
+             &MemoryDiscovered\r
+             );\r
+  if (!EFI_ERROR(Status)) {\r
+    MemoryInitialized = TRUE;\r
+  }\r
+\r
+  DEBUG ((DEBUG_INFO, "MemoryInitialized - %x\n", MemoryInitialized));\r
+\r
+  if (!MemoryInitialized) {\r
+    //\r
+    // If the memory is not initialized,\r
+    // Protect all system memory\r
+    //\r
+    InitVTdInfo ();\r
+    InitVTdPmrForAll ();\r
+  } else {\r
+    //\r
+    // If the memory is initialized,\r
+    // Allocate DMA buffer and protect rest system memory\r
+    //\r
+\r
+    //\r
+    // NOTE: We need reinit VTdInfo because previous information might be overriden.\r
+    //\r
+    InitVTdInfo ();\r
+\r
+    Hob = GetFirstGuidHob (&mVTdInfoGuid);\r
+    VTdInfo = GET_GUID_HOB_DATA(Hob);\r
+\r
+    //\r
+    // NOTE: We need check if PMR is enabled or not.\r
+    //\r
+    EnabledEngineMask = GetDmaProtectionEnabledEngineMask (VTdInfo, VTdInfo->EngineMask);\r
+    if (EnabledEngineMask != 0) {\r
+      EnableVTdTranslationProtection (VTdInfo, EnabledEngineMask);\r
+      DisableDmaProtection (VTdInfo, EnabledEngineMask);\r
+    }\r
+    InitVTdPmrForDma ();\r
+    if (EnabledEngineMask != 0) {\r
+      DisableVTdTranslationProtection (VTdInfo, EnabledEngineMask);\r
+    }\r
 \r
-  if ((PcdGet8(PcdVTdPolicyPropertyMask) & BIT1) == 0) {\r
-    EngineMask = LShiftU64 (1, mVTdInfo->VTdEngineCount) - 1;\r
-    DisableDmaProtection (EngineMask);\r
   }\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
-EFI_PEI_NOTIFY_DESCRIPTOR mS3EndOfPeiNotifyDesc = {\r
+EFI_PEI_NOTIFY_DESCRIPTOR mVTdInfoNotifyDesc = {\r
   (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
-  &gEfiEndOfPeiSignalPpiGuid,\r
-  S3EndOfPeiNotify\r
+  &gEdkiiVTdInfoPpiGuid,\r
+  VTdInfoNotify\r
 };\r
 \r
 /**\r
@@ -1161,71 +893,40 @@ IntelVTdPmrInitialize (
 {\r
   EFI_STATUS                  Status;\r
   EFI_BOOT_MODE               BootMode;\r
+  DMA_BUFFER_INFO             *DmaBufferInfo;\r
+\r
+  DEBUG ((DEBUG_INFO, "IntelVTdPmrInitialize\n"));\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
-             NULL,\r
-             (VOID **)&mAcpiDmarTable\r
-             );\r
-  ASSERT_EFI_ERROR(Status);\r
-\r
-  DumpAcpiDMAR (mAcpiDmarTable);\r
-\r
-  //\r
-  // Get DMAR information to local VTdInfo\r
-  //\r
-  Status = ParseDmarAcpiTableDrhd ();\r
-  if (EFI_ERROR(Status)) {\r
-    return Status;\r
+  DmaBufferInfo = BuildGuidHob (&mDmaBufferInfoGuid, sizeof(DMA_BUFFER_INFO));\r
+  ASSERT(DmaBufferInfo != NULL);\r
+  if (DmaBufferInfo == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
   }\r
+  ZeroMem (DmaBufferInfo, sizeof(DMA_BUFFER_INFO));\r
 \r
-  //\r
-  // If there is RMRR memory, parse it here.\r
-  //\r
-  ParseDmarAcpiTableRmrr ();\r
+  PeiServicesGetBootMode (&BootMode);\r
 \r
   if (BootMode == BOOT_ON_S3_RESUME) {\r
-    mDmaBufferSize = TOTAL_DMA_BUFFER_SIZE_S3;\r
+    DmaBufferInfo->DmaBufferSize = 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
-  //\r
-  Status = InitDmaProtection (mDmaBufferSize, &mDmaBufferBase);\r
-  if (EFI_ERROR(Status)) {\r
-    return Status;\r
+    DmaBufferInfo->DmaBufferSize = TOTAL_DMA_BUFFER_SIZE;\r
   }\r
 \r
-  DEBUG ((DEBUG_INFO, " DmaBufferBase : 0x%x\n", mDmaBufferBase));\r
-\r
-  mDmaBufferCurrentTop = mDmaBufferBase + mDmaBufferSize;\r
-  mDmaBufferCurrentBottom = mDmaBufferBase;\r
-\r
-  //\r
-  // Install PPI.\r
-  //\r
-  Status = PeiServicesInstallPpi (&mIoMmuPpiList);\r
-  ASSERT_EFI_ERROR(Status);\r
+  Status = PeiServicesNotifyPpi (&mVTdInfoNotifyDesc);\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
-  // Register EndOfPei Notify for S3 to run FSP NotifyPhase\r
+  // Register EndOfPei Notify for S3\r
   //\r
   if (BootMode == BOOT_ON_S3_RESUME) {\r
     Status = PeiServicesNotifyPpi (&mS3EndOfPeiNotifyDesc);\r
     ASSERT_EFI_ERROR (Status);\r
   }\r
 \r
-  return Status;\r
+  return EFI_SUCCESS;\r
 }\r
 \r