Introduce the PcdAcpiTestSupport Feature PCD to OvmfPkg. This PCD will
decide whether AcpiPlatformDxe populates the ACPI_TEST_SUPPORT structure
at the first Ready-To-Boot event.

(The Ready-To-Boot event is chosen because (a) it is bound to occur after
AcpiPlatformDxe installs the ACPI tables, and (b) it is guaranteed to
occur, namely when the boot manager launches the built-in UEFI shell.)

Introduce the RegisterAcpiTestSupport() and UnregisterAcpiTestSupport()
functions as skeletons, and call them dependent on the PCD, from the
driver's entry point function. Refactor the entry point function so the
registration can be rolled back on the failure path.

Cc: Anthony Perard <[email protected]>
Cc: Ard Biesheuvel <[email protected]>
Cc: Drew Jones <[email protected]>
Cc: Igor Mammedov <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek <[email protected]>
---
 OvmfPkg/OvmfPkg.dec                                  |  5 ++++
 OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf          |  4 +++
 OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf |  4 +++
 OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h               | 10 +++++++
 OvmfPkg/AcpiPlatformDxe/AcpiTestSupport.c            | 30 ++++++++++++++++++++
 OvmfPkg/AcpiPlatformDxe/EntryPoint.c                 | 24 ++++++++++++----
 6 files changed, 72 insertions(+), 5 deletions(-)

diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index e8c7d9423f43..00765a7995fa 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -155,13 +155,18 @@ [PcdsDynamic, PcdsDynamicEx]
 [PcdsFeatureFlag]
   gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderPciTranslation|TRUE|BOOLEAN|0x1c
   gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderMmioTranslation|FALSE|BOOLEAN|0x1d
 
   ## This feature flag enables SMM/SMRAM support. Note that it also requires
   #  such support from the underlying QEMU instance; if that support is not
   #  present, the firmware will reject continuing after a certain point.
   #
   #  The flag also acts as a general "security switch"; when TRUE, many
   #  components will change behavior, with the goal of preventing a malicious
   #  runtime OS from tampering with firmware structures (special memory ranges
   #  used by OVMF, the varstore pflash chip, LockBox etc).
   gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire|FALSE|BOOLEAN|0x1e
+
+  ## Instruct AcpiPlatformDxe to expose the RSD PTR address(es) in the
+  #  MB-aligned ACPI_TEST_SUPPORT structure to the hypervisor. This is a
+  #  development / unit test aid; do not enable in production builds.
+  gUefiOvmfPkgTokenSpaceGuid.PcdAcpiTestSupport|FALSE|BOOLEAN|3
diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf 
b/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
index 8440e7b343d8..9c5bfe767981 100644
--- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
+++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
@@ -29,10 +29,11 @@ [Defines]
 [Sources]
   AcpiPlatform.c
   AcpiPlatform.h
+  AcpiTestSupport.c
   BootScript.c
   EntryPoint.c
   PciDecoding.c
   Qemu.c
   QemuFwCfgAcpi.c
   QemuLoader.h
   Xen.c
@@ -75,5 +76,8 @@ [Pcd]
   gPcAtChipsetPkgTokenSpaceGuid.Pcd8259LegacyModeEdgeLevel
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress
 
+[FeaturePcd]
+  gUefiOvmfPkgTokenSpaceGuid.PcdAcpiTestSupport
+
 [Depex]
   gEfiAcpiTableProtocolGuid
diff --git a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf 
b/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf
index f0fb3496e700..b2501fea9ca4 100644
--- a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf
+++ b/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf
@@ -28,9 +28,10 @@ [Defines]
 
 [Sources]
   AcpiPlatform.h
+  AcpiTestSupport.c
   BootScript.c
   EntryPoint.c
   PciDecoding.c
   QemuFwCfgAcpi.c
   QemuFwCfgAcpiPlatform.c
   QemuLoader.h
@@ -62,5 +63,8 @@ [Guids]
 [Pcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration
 
+[FeaturePcd]
+  gUefiOvmfPkgTokenSpaceGuid.PcdAcpiTestSupport
+
 [Depex]
   gEfiAcpiTableProtocolGuid
diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h 
b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h
index 83b981ee005d..4769b92621b9 100644
--- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h
+++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h
@@ -117,6 +117,16 @@ EFI_STATUS
 TransferS3ContextToBootScript (
   IN S3_CONTEXT *S3Context
   );
 
+VOID
+RegisterAcpiTestSupport (
+  VOID
+  );
+
+VOID
+UnregisterAcpiTestSupport (
+  VOID
+  );
+
 #endif
 
diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiTestSupport.c 
b/OvmfPkg/AcpiPlatformDxe/AcpiTestSupport.c
new file mode 100644
index 000000000000..462c8e64a4fd
--- /dev/null
+++ b/OvmfPkg/AcpiPlatformDxe/AcpiTestSupport.c
@@ -0,0 +1,30 @@
+/** @file
+  Register a Ready-To-Boot callback for populating the ACPI_TEST_SUPPORT
+  structure.
+
+  Copyright (C) 2018, Red Hat, Inc.
+
+  This program and the accompanying materials are licensed and made available
+  under the terms and conditions of the BSD License which accompanies this
+  distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+  WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+
+#include "AcpiPlatform.h"
+
+VOID
+RegisterAcpiTestSupport (
+  VOID
+  )
+{
+}
+
+VOID
+UnregisterAcpiTestSupport (
+  VOID
+  )
+{
+}
diff --git a/OvmfPkg/AcpiPlatformDxe/EntryPoint.c 
b/OvmfPkg/AcpiPlatformDxe/EntryPoint.c
index 1bfd31a0371a..d32fba4f22f4 100644
--- a/OvmfPkg/AcpiPlatformDxe/EntryPoint.c
+++ b/OvmfPkg/AcpiPlatformDxe/EntryPoint.c
@@ -61,36 +61,50 @@ EFIAPI
 AcpiPlatformEntryPoint (
   IN EFI_HANDLE         ImageHandle,
   IN EFI_SYSTEM_TABLE   *SystemTable
   )
 {
   EFI_STATUS Status;
   EFI_EVENT  RootBridgesConnected;
 
+  if (FeaturePcdGet (PcdAcpiTestSupport)) {
+    RegisterAcpiTestSupport ();
+  }
+
   //
   // If the platform doesn't support PCI, or PCI enumeration has been disabled,
   // install the tables at once, and let the entry point's return code reflect
   // the full functionality.
   //
   if (PcdGetBool (PcdPciDisableBusEnumeration)) {
     DEBUG ((EFI_D_INFO, "%a: PCI or its enumeration disabled, installing "
       "ACPI tables\n", __FUNCTION__));
-    return InstallAcpiTables (FindAcpiTableProtocol ());
+    Status = InstallAcpiTables (FindAcpiTableProtocol ());
+    if (EFI_ERROR (Status)) {
+      goto RollbackAcpiTestSupport;
+    }
+    return EFI_SUCCESS;
   }
 
   //
   // Otherwise, delay installing the ACPI tables until root bridges are
   // connected. The entry point's return status will only reflect the callback
   // setup. (Note that we're a DXE_DRIVER; our entry point function is invoked
   // strictly before BDS is entered and can connect the root bridges.)
   //
   Status = gBS->CreateEventEx (EVT_NOTIFY_SIGNAL, TPL_CALLBACK,
                   OnRootBridgesConnected, NULL /* Context */,
                   &gRootBridgesConnectedEventGroupGuid, &RootBridgesConnected);
-  if (!EFI_ERROR (Status)) {
-    DEBUG ((EFI_D_INFO,
-      "%a: waiting for root bridges to be connected, registered callback\n",
-      __FUNCTION__));
+  if (EFI_ERROR (Status)) {
+    goto RollbackAcpiTestSupport;
   }
+  DEBUG ((DEBUG_INFO,
+    "%a: waiting for root bridges to be connected, registered callback\n",
+    __FUNCTION__));
+  return EFI_SUCCESS;
 
+RollbackAcpiTestSupport:
+  if (FeaturePcdGet (PcdAcpiTestSupport)) {
+    UnregisterAcpiTestSupport ();
+  }
   return Status;
 }
-- 
2.19.1.3.g30247aa5d201


_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to