IntelSiliconPkg IntelVTdDxe: Use new EfiLocateFirstAcpiTable()
authorStar Zeng <star.zeng@intel.com>
Fri, 8 Jun 2018 08:38:46 +0000 (16:38 +0800)
committerStar Zeng <star.zeng@intel.com>
Thu, 27 Sep 2018 06:25:33 +0000 (14:25 +0800)
https://bugzilla.tianocore.org/show_bug.cgi?id=967
Request to add a library function for GetAcpiTable() in order
to get ACPI table using signature as input.

After evaluation, we found there are many duplicated code to
find ACPI table by signature in different modules.

This patch updates IntelVTdDxe to use new
EfiLocateFirstAcpiTable() and remove the duplicated code.

Cc: Younas khan <pmdyounaskhan786@gmail.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
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/IntelVTdDxe/DmarAcpiTable.c

index 24723fe..92b09f9 100644 (file)
@@ -867,116 +867,6 @@ ParseDmarAcpiTableRmrr (
   return EFI_SUCCESS ;\r
 }\r
 \r
-/**\r
-  This function scan ACPI table in RSDT.\r
-\r
-  @param[in]  Rsdt      ACPI RSDT\r
-  @param[in]  Signature ACPI table signature\r
-\r
-  @return ACPI table\r
-**/\r
-VOID *\r
-ScanTableInRSDT (\r
-  IN RSDT_TABLE                   *Rsdt,\r
-  IN UINT32                       Signature\r
-  )\r
-{\r
-  UINTN                         Index;\r
-  UINT32                        EntryCount;\r
-  UINT32                        *EntryPtr;\r
-  EFI_ACPI_DESCRIPTION_HEADER   *Table;\r
-\r
-  EntryCount = (Rsdt->Header.Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / sizeof(UINT32);\r
-\r
-  EntryPtr = &Rsdt->Entry;\r
-  for (Index = 0; Index < EntryCount; Index ++, EntryPtr ++) {\r
-    Table = (EFI_ACPI_DESCRIPTION_HEADER*)((UINTN)(*EntryPtr));\r
-    if ((Table != NULL) && (Table->Signature == Signature)) {\r
-      return Table;\r
-    }\r
-  }\r
-\r
-  return NULL;\r
-}\r
-\r
-/**\r
-  This function scan ACPI table in XSDT.\r
-\r
-  @param[in]  Xsdt      ACPI XSDT\r
-  @param[in]  Signature ACPI table signature\r
-\r
-  @return ACPI table\r
-**/\r
-VOID *\r
-ScanTableInXSDT (\r
-  IN XSDT_TABLE                   *Xsdt,\r
-  IN UINT32                       Signature\r
-  )\r
-{\r
-  UINTN                        Index;\r
-  UINT32                       EntryCount;\r
-  UINT64                       EntryPtr;\r
-  UINTN                        BasePtr;\r
-  EFI_ACPI_DESCRIPTION_HEADER  *Table;\r
-\r
-  EntryCount = (Xsdt->Header.Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / sizeof(UINT64);\r
-\r
-  BasePtr = (UINTN)(&(Xsdt->Entry));\r
-  for (Index = 0; Index < EntryCount; Index ++) {\r
-    CopyMem (&EntryPtr, (VOID *)(BasePtr + Index * sizeof(UINT64)), sizeof(UINT64));\r
-    Table = (EFI_ACPI_DESCRIPTION_HEADER*)((UINTN)(EntryPtr));\r
-    if ((Table != NULL) && (Table->Signature == Signature)) {\r
-      return Table;\r
-    }\r
-  }\r
-\r
-  return NULL;\r
-}\r
-\r
-/**\r
-  This function scan ACPI table in RSDP.\r
-\r
-  @param[in]  Rsdp      ACPI RSDP\r
-  @param[in]  Signature ACPI table signature\r
-\r
-  @return ACPI table\r
-**/\r
-VOID *\r
-FindAcpiPtr (\r
-  IN EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp,\r
-  IN UINT32                                       Signature\r
-  )\r
-{\r
-  EFI_ACPI_DESCRIPTION_HEADER                    *AcpiTable;\r
-  RSDT_TABLE                                     *Rsdt;\r
-  XSDT_TABLE                                     *Xsdt;\r
-\r
-  AcpiTable = NULL;\r
-\r
-  //\r
-  // Check ACPI2.0 table\r
-  //\r
-  Rsdt = (RSDT_TABLE *)(UINTN)Rsdp->RsdtAddress;\r
-  Xsdt = NULL;\r
-  if ((Rsdp->Revision >= 2) && (Rsdp->XsdtAddress < (UINT64)(UINTN)-1)) {\r
-    Xsdt = (XSDT_TABLE *)(UINTN)Rsdp->XsdtAddress;\r
-  }\r
-  //\r
-  // Check Xsdt\r
-  //\r
-  if (Xsdt != NULL) {\r
-    AcpiTable = ScanTableInXSDT (Xsdt, Signature);\r
-  }\r
-  //\r
-  // Check Rsdt\r
-  //\r
-  if ((AcpiTable == NULL) && (Rsdt != NULL)) {\r
-    AcpiTable = ScanTableInRSDT (Rsdt, Signature);\r
-  }\r
-\r
-  return AcpiTable;\r
-}\r
-\r
 /**\r
   Get the DMAR ACPI table.\r
 \r
@@ -989,33 +879,13 @@ GetDmarAcpiTable (
   VOID\r
   )\r
 {\r
-  VOID                              *AcpiTable;\r
-  EFI_STATUS                        Status;\r
-\r
   if (mAcpiDmarTable != NULL) {\r
     return EFI_ALREADY_STARTED;\r
   }\r
 \r
-  AcpiTable = NULL;\r
-  Status = EfiGetSystemConfigurationTable (\r
-             &gEfiAcpi20TableGuid,\r
-             &AcpiTable\r
-             );\r
-  if (EFI_ERROR (Status)) {\r
-    Status = EfiGetSystemConfigurationTable (\r
-               &gEfiAcpi10TableGuid,\r
-               &AcpiTable\r
-               );\r
-  }\r
-  if (EFI_ERROR (Status)) {\r
-    return EFI_NOT_FOUND;\r
-  }\r
-  ASSERT (AcpiTable != NULL);\r
-\r
-  mAcpiDmarTable = FindAcpiPtr (\r
-                      (EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *)AcpiTable,\r
-                      EFI_ACPI_4_0_DMA_REMAPPING_TABLE_SIGNATURE\r
-                      );\r
+  mAcpiDmarTable = (EFI_ACPI_DMAR_HEADER *) EfiLocateFirstAcpiTable (\r
+                                              EFI_ACPI_4_0_DMA_REMAPPING_TABLE_SIGNATURE\r
+                                              );\r
   if (mAcpiDmarTable == NULL) {\r
     return EFI_NOT_FOUND;\r
   }\r