diff mbox

[edk2,3/4] OvmfPkg: AcpiPlatformDxe: remove current ACPI table loader

Message ID 1407550139-25313-4-git-send-email-lersek@redhat.com
State New
Headers show

Commit Message

Laszlo Ersek Aug. 9, 2014, 2:08 a.m. UTC
In the next patch we rewrite the client code for QEMU's fw_cfg ACPI table
loader interface. In order to avoid randomly intermixed hunks in that
patch, first remove the old code cleanly.

We remove the InstallQemuLinkedTables() function and empty the
InstallAllQemuLinkedTables() function. We keep CheckRsdp(), and the way we
call it ensures that

- compilers won't complain about it being a unused static function,

- InstallAllQemuLinkedTables() will return constant EFI_NOT_FOUND to
  AcpiPlatformEntryPoint(), causing the latter to proceed to OVMF's
  builtin tables.

This way the history remains bisectable and the new client gets a clean
start in the next patch.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h |   2 +-
 OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c |   2 +-
 OvmfPkg/AcpiPlatformDxe/Qemu.c         | 266 +--------------------------------
 3 files changed, 4 insertions(+), 266 deletions(-)
diff mbox

Patch

diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h
index e757233..3837134 100644
--- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h
+++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h
@@ -64,7 +64,7 @@  InstallXenTables (
 EFI_STATUS
 EFIAPI
 InstallAllQemuLinkedTables (
-  IN   EFI_ACPI_TABLE_PROTOCOL       *AcpiProtocol
+  VOID
   );
 #endif
 
diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c
index 11f0ca8..c254e14 100644
--- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c
+++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c
@@ -257,7 +257,7 @@  AcpiPlatformEntryPoint (
   if (XenDetected ()) {
     Status = InstallXenTables (AcpiTable);
   } else {
-    Status = InstallAllQemuLinkedTables (AcpiTable);
+    Status = InstallAllQemuLinkedTables ();
   }
 
   if (EFI_ERROR (Status)) {
diff --git a/OvmfPkg/AcpiPlatformDxe/Qemu.c b/OvmfPkg/AcpiPlatformDxe/Qemu.c
index 70f3ff6..333766e 100644
--- a/OvmfPkg/AcpiPlatformDxe/Qemu.c
+++ b/OvmfPkg/AcpiPlatformDxe/Qemu.c
@@ -591,198 +591,6 @@  CheckRsdp (
   return EFI_SUCCESS;
 }
 
-//
-// We'll be saving the keys of installed tables so that we can roll them back
-// in case of failure. 128 tables should be enough for anyone (TM).
-//
-#define INSTALLED_TABLES_MAX 128
-
-/**
-  Download one ACPI table data file from QEMU and interpret it.
-
-  @param[in] FwCfgFile         The NUL-terminated name of the fw_cfg file to
-                               download and interpret.
-
-  @param[in] AcpiProtocol      The ACPI table protocol used to install tables.
-
-  @param[in,out] InstalledKey  On input, an array of INSTALLED_TABLES_MAX UINTN
-                               elements, allocated by the caller. On output,
-                               the function will have stored (appended) the
-                               AcpiProtocol-internal keys of the ACPI tables
-                               that the function has installed from the fw_cfg
-                               file. The array reflects installed tables even
-                               if the function returns with an error.
-
-  @param[in,out] NumInstalled  On input, the number of entries already used in
-                               InstalledKey; it must be in [0,
-                               INSTALLED_TABLES_MAX] inclusive. On output, the
-                               parameter is updated to the new cumulative count
-                               of the keys stored in InstalledKey; the value
-                               reflects installed tables even if the function
-                               returns with an error.
-
-  @retval  EFI_INVALID_PARAMETER  NumInstalled is outside the allowed range on
-                                  input.
-
-  @retval  EFI_UNSUPPORTED        Firmware configuration is unavailable.
-
-  @retval  EFI_NOT_FOUND          The host doesn't export the requested fw_cfg
-                                  file.
-
-  @retval  EFI_OUT_OF_RESOURCES   Memory allocation failed, or no more room in
-                                  InstalledKey.
-
-  @retval  EFI_PROTOCOL_ERROR     Found truncated or invalid ACPI table header
-                                  in the fw_cfg contents.
-
-  @return                         Status codes returned by
-                                  AcpiProtocol->InstallAcpiTable().
-
-**/
-
-STATIC
-EFI_STATUS
-InstallQemuLinkedTables (
-  IN     CONST CHAR8             *FwCfgFile,
-  IN     EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol,
-  IN OUT UINTN                   InstalledKey[INSTALLED_TABLES_MAX],
-  IN OUT INT32                   *NumInstalled
-  )
-{
-  EFI_STATUS           Status;
-  FIRMWARE_CONFIG_ITEM TablesFile;
-  UINTN                TablesFileSize;
-  UINT8                *Tables;
-  UINTN                Processed;
-
-  if (*NumInstalled < 0 || *NumInstalled > INSTALLED_TABLES_MAX) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  Status = QemuFwCfgFindFile (FwCfgFile, &TablesFile, &TablesFileSize);
-  if (EFI_ERROR (Status)) {
-    DEBUG ((EFI_D_ERROR, "%a: \"%a\" unavailable: %r\n", __FUNCTION__,
-      FwCfgFile, Status));
-    return Status;
-  }
-
-  Tables = AllocatePool (TablesFileSize);
-  if (Tables == NULL) {
-    return EFI_OUT_OF_RESOURCES;
-  }
-
-  QemuFwCfgSelectItem (TablesFile);
-  QemuFwCfgReadBytes (TablesFileSize, Tables);
-
-  Processed = 0;
-  while (Processed < TablesFileSize) {
-    UINTN                       Remaining;
-    UINTN                       RsdpSize;
-    EFI_ACPI_DESCRIPTION_HEADER *Probe;
-
-    Remaining = TablesFileSize - Processed;
-
-    //
-    // See if we're looking at an RSD PTR structure.
-    //
-    RsdpSize = 0;
-    Status = CheckRsdp (Tables + Processed, Remaining, &RsdpSize);
-    if (Status == EFI_PROTOCOL_ERROR) {
-      //
-      // RSD PTR found but its size is inconsistent; abort processing. (Note
-      // that "RSD PTR found" excludes the NUL-padding case by definition.)
-      //
-      break;
-    }
-    if (!EFI_ERROR (Status)) {
-      //
-      // Consistent RSD PTR found, skip it.
-      //
-      DEBUG ((EFI_D_VERBOSE, "%a: \"%a\" offset 0x%016Lx: RSD PTR "
-        "Length=0x%08x\n", __FUNCTION__, FwCfgFile, (UINT64)Processed,
-        (UINT32)RsdpSize));
-      Processed += RsdpSize;
-      continue;
-    }
-    ASSERT (Status == EFI_NOT_FOUND);
-
-    //
-    // What we're looking at is not an RSD PTR structure; attempt to parse it
-    // as an ACPI table.
-    //
-    if (Remaining < sizeof *Probe) {
-      Status = EFI_PROTOCOL_ERROR;
-      break;
-    }
-
-    Probe = (EFI_ACPI_DESCRIPTION_HEADER *) (Tables + Processed);
-    if (Remaining < Probe->Length || Probe->Length < sizeof *Probe) {
-      Status = EFI_PROTOCOL_ERROR;
-      break;
-    }
-
-    DEBUG ((EFI_D_VERBOSE, "%a: \"%a\" offset 0x%016Lx:"
-      " Signature=\"%-4.4a\" Length=0x%08x\n",
-      __FUNCTION__, FwCfgFile, (UINT64) Processed,
-      (CONST CHAR8 *) &Probe->Signature, Probe->Length));
-
-    //
-    // skip automatically handled "root" tables: RSDT, XSDT
-    //
-    if (Probe->Signature !=
-                        EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE &&
-        Probe->Signature !=
-                    EFI_ACPI_2_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE) {
-      if (*NumInstalled == INSTALLED_TABLES_MAX) {
-        DEBUG ((EFI_D_ERROR, "%a: can't install more than %d tables\n",
-          __FUNCTION__, INSTALLED_TABLES_MAX));
-        Status = EFI_OUT_OF_RESOURCES;
-        break;
-      }
-
-      Status = AcpiProtocol->InstallAcpiTable (AcpiProtocol, Probe,
-                 Probe->Length, &InstalledKey[*NumInstalled]);
-      if (EFI_ERROR (Status)) {
-        DEBUG ((EFI_D_ERROR,
-          "%a: failed to install table \"%-4.4a\" at \"%a\" offset 0x%Lx: "
-          "%r\n", __FUNCTION__, (CONST CHAR8 *)&Probe->Signature, FwCfgFile,
-          (UINT64) Processed, Status));
-        break;
-      }
-
-      ++*NumInstalled;
-    }
-
-    Processed += Probe->Length;
-  }
-
-  //
-  // NUL-padding at the end is accepted
-  //
-  if (Status == EFI_PROTOCOL_ERROR) {
-    UINTN ErrorLocation;
-
-    ErrorLocation = Processed;
-    while (Processed < TablesFileSize && Tables[Processed] == '\0') {
-      ++Processed;
-    }
-    if (Processed < TablesFileSize) {
-      DEBUG ((EFI_D_ERROR, "%a: truncated or invalid ACPI table header at "
-        "\"%a\" offset 0x%Lx\n", __FUNCTION__, FwCfgFile,
-        (UINT64)ErrorLocation));
-    }
-  }
-
-  if (Processed == TablesFileSize) {
-    Status = EFI_SUCCESS;
-  } else {
-    ASSERT (EFI_ERROR (Status));
-  }
-
-  FreePool (Tables);
-  return Status;
-}
-
 /**
   Download all ACPI table data files from QEMU and interpret them.
 
@@ -806,78 +614,8 @@  InstallQemuLinkedTables (
 EFI_STATUS
 EFIAPI
 InstallAllQemuLinkedTables (
-  IN   EFI_ACPI_TABLE_PROTOCOL       *AcpiProtocol
+  VOID
   )
 {
-  UINTN                *InstalledKey;
-  INT32                Installed;
-  EFI_STATUS           Status;
-  FIRMWARE_CONFIG_ITEM LoaderItem;
-  UINTN                LoaderSize;
-  UINT8                *Loader;
-  QEMU_LOADER_ENTRY    *Entry, *End;
-
-  InstalledKey = AllocatePool (INSTALLED_TABLES_MAX * sizeof *InstalledKey);
-  if (InstalledKey == NULL) {
-    return EFI_OUT_OF_RESOURCES;
-  }
-  Installed = 0;
-
-  Status = QemuFwCfgFindFile ("etc/table-loader", &LoaderItem, &LoaderSize);
-  if (EFI_ERROR (Status)) {
-    goto FreeInstalledKey;
-  }
-  if (LoaderSize % sizeof *Entry != 0) {
-    Status = EFI_PROTOCOL_ERROR;
-    goto FreeInstalledKey;
-  }
-
-  Loader = AllocatePool (LoaderSize);
-  if (Loader == NULL) {
-    Status = EFI_OUT_OF_RESOURCES;
-    goto FreeInstalledKey;
-  }
-
-  QemuFwCfgSelectItem (LoaderItem);
-  QemuFwCfgReadBytes (LoaderSize, Loader);
-
-  Entry = (QEMU_LOADER_ENTRY *)Loader;
-  End   = (QEMU_LOADER_ENTRY *)(Loader + LoaderSize);
-  while (Entry < End) {
-    if (Entry->Type == QemuLoaderCmdAllocate) {
-      QEMU_LOADER_ALLOCATE *Allocate;
-
-      Allocate = &Entry->Command.Allocate;
-      if (Allocate->File[sizeof Allocate->File - 1] != '\0') {
-        Status = EFI_PROTOCOL_ERROR;
-        break;
-      }
-
-      Status = InstallQemuLinkedTables ((CHAR8 *)Allocate->File, AcpiProtocol,
-                 InstalledKey, &Installed);
-      if (EFI_ERROR (Status)) {
-        ASSERT (Status != EFI_INVALID_PARAMETER);
-        break;
-      }
-    }
-    ++Entry;
-  }
-
-  FreePool (Loader);
-
-  if (EFI_ERROR (Status)) {
-    //
-    // Roll back partial installation.
-    //
-    while (Installed > 0) {
-      --Installed;
-      AcpiProtocol->UninstallAcpiTable (AcpiProtocol, InstalledKey[Installed]);
-    }
-  } else {
-    DEBUG ((EFI_D_INFO, "%a: installed %d tables\n", __FUNCTION__, Installed));
-  }
-
-FreeInstalledKey:
-  FreePool (InstalledKey);
-  return Status;
+  return CheckRsdp (NULL, 0, NULL);
 }