IntelSiliconPkg IntelVTdPmrPei: Get high top by host address width
authorStar Zeng <star.zeng@intel.com>
Wed, 17 Jan 2018 03:10:57 +0000 (11:10 +0800)
committerStar Zeng <star.zeng@intel.com>
Wed, 17 Jan 2018 10:34:46 +0000 (18:34 +0800)
Get high top by host address width instead of resource HOB.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/DmarTable.c
IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/IntelVTdPmrPei.c
IntelSiliconPkg/Feature/VTd/IntelVTdPmrPei/IntelVTdPmrPei.h

index 891efa6..ea853bd 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-  Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2017 - 2018, 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
@@ -528,7 +528,7 @@ ProcessRmrr (
       LowBottom = 0;\r
       LowTop = (UINTN)DmarRmrr->ReservedMemoryRegionBaseAddress;\r
       HighBottom = (UINTN)DmarRmrr->ReservedMemoryRegionLimitAddress + 1;\r
-      HighTop = GetTopMemory ();\r
+      HighTop = LShiftU64 (1, VTdInfo->HostAddressWidth + 1);\r
 \r
       SetDmaProtectedRange (\r
         VTdInfo,\r
index bb7ace4..63ba94d 100644 (file)
@@ -60,7 +60,7 @@ typedef struct {
 \r
   PEI Memory Layout:\r
 \r
-              +------------------+ <=============== PHMR.Limit (+ alignment) (Top of memory)\r
+              +------------------+ <=============== PHMR.Limit (+ alignment) (1 << (HostAddressWidth + 1))\r
               |   Mem Resource   |\r
               |                  |\r
 \r
@@ -377,159 +377,6 @@ CONST EFI_PEI_PPI_DESCRIPTOR mIoMmuPpiList = {
   (VOID *) &mIoMmuPpi\r
 };\r
 \r
-#define MEMORY_ATTRIBUTE_MASK (EFI_RESOURCE_ATTRIBUTE_PRESENT | \\r
-                               EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \\r
-                               EFI_RESOURCE_ATTRIBUTE_TESTED | \\r
-                               EFI_RESOURCE_ATTRIBUTE_16_BIT_IO | \\r
-                               EFI_RESOURCE_ATTRIBUTE_32_BIT_IO | \\r
-                               EFI_RESOURCE_ATTRIBUTE_64_BIT_IO \\r
-                               )\r
-\r
-#define TESTED_MEMORY_ATTRIBUTES      (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_TESTED)\r
-\r
-#define INITIALIZED_MEMORY_ATTRIBUTES (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED)\r
-\r
-#define PRESENT_MEMORY_ATTRIBUTES     (EFI_RESOURCE_ATTRIBUTE_PRESENT)\r
-\r
-GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 *mResourceTypeShortName[] = {\r
-  "Mem",\r
-  "MMIO",\r
-  "I/O",\r
-  "FD",\r
-  "MM Port I/O",\r
-  "Reserved Mem",\r
-  "Reserved I/O",\r
-};\r
-\r
-/**\r
-  Return the short name of resource type.\r
-\r
-  @param Type  resource type.\r
-\r
-  @return the short name of resource type.\r
-**/\r
-CHAR8 *\r
-ShortNameOfResourceType (\r
-  IN UINT32 Type\r
-  )\r
-{\r
-  if (Type < sizeof(mResourceTypeShortName) / sizeof(mResourceTypeShortName[0])) {\r
-    return mResourceTypeShortName[Type];\r
-  } else {\r
-    return "Unknown";\r
-  }\r
-}\r
-\r
-/**\r
-  Dump resource hob.\r
-\r
-  @param HobList  the HOB list.\r
-**/\r
-VOID\r
-DumpResourceHob (\r
-  IN VOID                        *HobList\r
-  )\r
-{\r
-  EFI_PEI_HOB_POINTERS        Hob;\r
-  EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob;\r
-\r
-  DEBUG ((DEBUG_VERBOSE, "Resource Descriptor HOBs\n"));\r
-  for (Hob.Raw = HobList; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {\r
-    if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {\r
-      ResourceHob = Hob.ResourceDescriptor;\r
-      DEBUG ((DEBUG_VERBOSE,\r
-        "  BA=%016lx  L=%016lx  Attr=%08x  ",\r
-        ResourceHob->PhysicalStart,\r
-        ResourceHob->ResourceLength,\r
-        ResourceHob->ResourceAttribute\r
-        ));\r
-      DEBUG ((DEBUG_VERBOSE, ShortNameOfResourceType(ResourceHob->ResourceType)));\r
-      switch (ResourceHob->ResourceType) {\r
-      case EFI_RESOURCE_SYSTEM_MEMORY:\r
-        if ((ResourceHob->ResourceAttribute & EFI_RESOURCE_ATTRIBUTE_PERSISTENT) != 0) {\r
-          DEBUG ((DEBUG_VERBOSE, " (Persistent)"));\r
-        } else if ((ResourceHob->ResourceAttribute & EFI_RESOURCE_ATTRIBUTE_MORE_RELIABLE) != 0) {\r
-          DEBUG ((DEBUG_VERBOSE, " (MoreReliable)"));\r
-        } else if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) == TESTED_MEMORY_ATTRIBUTES) {\r
-          DEBUG ((DEBUG_VERBOSE, " (Tested)"));\r
-        } else if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) == INITIALIZED_MEMORY_ATTRIBUTES) {\r
-          DEBUG ((DEBUG_VERBOSE, " (Init)"));\r
-        } else if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) == PRESENT_MEMORY_ATTRIBUTES) {\r
-          DEBUG ((DEBUG_VERBOSE, " (Present)"));\r
-        } else {\r
-          DEBUG ((DEBUG_VERBOSE, " (Unknown)"));\r
-        }\r
-        break;\r
-      default:\r
-        break;\r
-      }\r
-      DEBUG ((DEBUG_VERBOSE, "\n"));\r
-    }\r
-  }\r
-}\r
-\r
-/**\r
-  Dump PHIT hob.\r
-\r
-  @param HobList  the HOB list.\r
-**/\r
-VOID\r
-DumpPhitHob (\r
-  IN VOID                        *HobList\r
-  )\r
-{\r
-  EFI_HOB_HANDOFF_INFO_TABLE  *PhitHob;\r
-\r
-  PhitHob = HobList;\r
-  ASSERT(GET_HOB_TYPE(HobList) == EFI_HOB_TYPE_HANDOFF);\r
-  DEBUG ((DEBUG_VERBOSE, "PHIT HOB\n"));\r
-  DEBUG ((DEBUG_VERBOSE, "  PhitHob             - 0x%x\n", PhitHob));\r
-  DEBUG ((DEBUG_VERBOSE, "  BootMode            - 0x%x\n", PhitHob->BootMode));\r
-  DEBUG ((DEBUG_VERBOSE, "  EfiMemoryTop        - 0x%016lx\n", PhitHob->EfiMemoryTop));\r
-  DEBUG ((DEBUG_VERBOSE, "  EfiMemoryBottom     - 0x%016lx\n", PhitHob->EfiMemoryBottom));\r
-  DEBUG ((DEBUG_VERBOSE, "  EfiFreeMemoryTop    - 0x%016lx\n", PhitHob->EfiFreeMemoryTop));\r
-  DEBUG ((DEBUG_VERBOSE, "  EfiFreeMemoryBottom - 0x%016lx\n", PhitHob->EfiFreeMemoryBottom));\r
-  DEBUG ((DEBUG_VERBOSE, "  EfiEndOfHobList     - 0x%lx\n", PhitHob->EfiEndOfHobList));\r
-}\r
-\r
-/**\r
-  Get the highest memory.\r
-\r
-  @return the highest memory.\r
-**/\r
-UINT64\r
-GetTopMemory (\r
-  VOID\r
-  )\r
-{\r
-  VOID                        *HobList;\r
-  EFI_PEI_HOB_POINTERS        Hob;\r
-  EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob;\r
-  UINT64                      TopMemory;\r
-  UINT64                      ResourceTop;\r
-\r
-  HobList = GetHobList ();\r
-\r
-  TopMemory = 0;\r
-  for (Hob.Raw = HobList; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {\r
-    if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {\r
-      ResourceHob = Hob.ResourceDescriptor;\r
-      switch (ResourceHob->ResourceType) {\r
-      case EFI_RESOURCE_SYSTEM_MEMORY:\r
-        ResourceTop = ResourceHob->PhysicalStart + ResourceHob->ResourceLength;\r
-        if (TopMemory < ResourceTop) {\r
-          TopMemory = ResourceTop;\r
-        }\r
-        break;\r
-      default:\r
-        break;\r
-      }\r
-      DEBUG ((DEBUG_VERBOSE, "\n"));\r
-    }\r
-  }\r
-  return TopMemory;\r
-}\r
-\r
 /**\r
   Initialize DMA protection.\r
 \r
@@ -548,8 +395,6 @@ InitDmaProtection (
   )\r
 {\r
   EFI_STATUS                  Status;\r
-  VOID                        *HobList;\r
-  EFI_HOB_HANDOFF_INFO_TABLE  *PhitHob;\r
   UINT32                      LowMemoryAlignment;\r
   UINT64                      HighMemoryAlignment;\r
   UINTN                       MemoryAlignment;\r
@@ -558,14 +403,6 @@ InitDmaProtection (
   UINTN                       HighBottom;\r
   UINT64                      HighTop;\r
 \r
-  HobList = GetHobList ();\r
-  DumpPhitHob (HobList);\r
-  DumpResourceHob (HobList);\r
-\r
-  PhitHob = HobList;\r
-\r
-  ASSERT (PhitHob->EfiMemoryBottom < PhitHob->EfiMemoryTop);\r
-\r
   LowMemoryAlignment = GetLowMemoryAlignment (VTdInfo, VTdInfo->EngineMask);\r
   HighMemoryAlignment = GetHighMemoryAlignment (VTdInfo, VTdInfo->EngineMask);\r
   if (LowMemoryAlignment < HighMemoryAlignment) {\r
@@ -584,7 +421,7 @@ InitDmaProtection (
   LowBottom = 0;\r
   LowTop = *DmaBufferBase;\r
   HighBottom = *DmaBufferBase + DmaBufferSize;\r
-  HighTop = GetTopMemory ();\r
+  HighTop = LShiftU64 (1, VTdInfo->HostAddressWidth + 1);\r
 \r
   Status = SetDmaProtectedRange (\r
              VTdInfo,\r
index 499119d..c53f69c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The definition for DMA access Library.\r
 \r
-  Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2017 - 2018, 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
@@ -159,16 +159,6 @@ DumpAcpiDMAR (
   IN EFI_ACPI_DMAR_HEADER  *Dmar\r
   );\r
 \r
-/**\r
-  Get the highest memory.\r
-\r
-  @return the highest memory.\r
-**/\r
-UINT64\r
-GetTopMemory (\r
-  VOID\r
-  );\r
-\r
 extern EFI_GUID mVTdInfoGuid;\r
 \r
 #endif\r