public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: edk2-devel@lists.01.org
Cc: "Anthony Perard" <anthony.perard@citrix.com>,
	"Ard Biesheuvel" <ard.biesheuvel@linaro.org>,
	"Drew Jones" <drjones@redhat.com>,
	"Igor Mammedov" <imammedo@redhat.com>,
	"Jordan Justen" <jordan.l.justen@intel.com>,
	"Julien Grall" <julien.grall@linaro.org>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: [PATCH 3/4] OvmfPkg/AcpiPlatformDxe: add [Un]RegisterAcpiTestSupport() skeletons
Date: Sun, 25 Nov 2018 11:01:51 +0100	[thread overview]
Message-ID: <20181125100152.25675-4-lersek@redhat.com> (raw)
In-Reply-To: <20181125100152.25675-1-lersek@redhat.com>

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 <anthony.perard@citrix.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Drew Jones <drjones@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Julien Grall <julien.grall@linaro.org>
Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 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




  parent reply	other threads:[~2018-11-25 10:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-25 10:01 [PATCH 0/4] OvmfPkg, ArmVirtPkg: add ACPI Test Support Laszlo Ersek
2018-11-25 10:01 ` [PATCH 1/4] OvmfPkg: introduce ACPI Test Support data structure and GUID Laszlo Ersek
2018-11-26 21:43   ` Philippe Mathieu-Daudé
2018-11-27 11:23     ` Laszlo Ersek
2018-12-03 17:09   ` Igor Mammedov
2018-12-04 17:09     ` Laszlo Ersek
2018-12-26 20:24       ` Laszlo Ersek
2018-12-27  5:11         ` Igor Mammedov
2018-11-25 10:01 ` [PATCH 2/4] OvmfPkg/AcpiPlatformDxe: list missing lib classes for QemuFwCfgAcpiPlatformDxe Laszlo Ersek
2018-11-25 10:01 ` Laszlo Ersek [this message]
2018-11-25 10:01 ` [PATCH 4/4] OvmfPkg/AcpiPlatformDxe: fill in ACPI_TEST_SUPPORT at first Ready-To-Boot Laszlo Ersek
2018-11-26 17:21 ` [PATCH 0/4] OvmfPkg, ArmVirtPkg: add ACPI Test Support Ard Biesheuvel
2018-11-27 11:02   ` Laszlo Ersek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181125100152.25675-4-lersek@redhat.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox