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 4/4] OvmfPkg/AcpiPlatformDxe: fill in ACPI_TEST_SUPPORT at first Ready-To-Boot
Date: Sun, 25 Nov 2018 11:01:52 +0100	[thread overview]
Message-ID: <20181125100152.25675-5-lersek@redhat.com> (raw)
In-Reply-To: <20181125100152.25675-1-lersek@redhat.com>

If the PcdAcpiTestSupport Feature PCD is set, allocate and fill the
ACPI_TEST_SUPPORT structure at a 1MB boundary.

This feature is a best-effort development / unit test helper, so even if
it is enabled at build time, and fails at boot time, it will not prevent
AcpiPlatformDxe from doing its job. For the same reason, error messages
are only logged at the DEBUG_WARN level.

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/AcpiPlatformDxe/AcpiPlatformDxe.inf          |  4 +
 OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf |  4 +
 OvmfPkg/AcpiPlatformDxe/AcpiTestSupport.c            | 89 ++++++++++++++++++++
 3 files changed, 97 insertions(+)

diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf b/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
index 9c5bfe767981..11ae3e2a1ac1 100644
--- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
+++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
@@ -66,6 +66,10 @@ [Protocols]
   gEfiPciIoProtocolGuid                         # PROTOCOL SOMETIMES_CONSUMED
 
 [Guids]
+  gAcpiTestSupportGuid
+  gEfiAcpi10TableGuid
+  gEfiAcpi20TableGuid
+  gEfiEventReadyToBootGuid
   gEfiXenInfoGuid
   gRootBridgesConnectedEventGroupGuid
 
diff --git a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf b/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf
index b2501fea9ca4..062f4d2fc50c 100644
--- a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf
+++ b/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf
@@ -58,6 +58,10 @@ [Protocols]
   gEfiPciIoProtocolGuid                         # PROTOCOL SOMETIMES_CONSUMED
 
 [Guids]
+  gAcpiTestSupportGuid
+  gEfiAcpi10TableGuid
+  gEfiAcpi20TableGuid
+  gEfiEventReadyToBootGuid
   gRootBridgesConnectedEventGroupGuid
 
 [Pcd]
diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiTestSupport.c b/OvmfPkg/AcpiPlatformDxe/AcpiTestSupport.c
index 462c8e64a4fd..26dd26cdc439 100644
--- a/OvmfPkg/AcpiPlatformDxe/AcpiTestSupport.c
+++ b/OvmfPkg/AcpiPlatformDxe/AcpiTestSupport.c
@@ -15,16 +15,105 @@
 
 #include "AcpiPlatform.h"
 
+#include <Guid/Acpi.h>
+#include <Guid/AcpiTestSupport.h>
+#include <Guid/EventGroup.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+
+STATIC volatile ACPI_TEST_SUPPORT *mAcpiTestSupport;
+STATIC EFI_EVENT                  mAcpiTestSupportEvent;
+
+STATIC
+VOID
+EFIAPI
+AcpiTestSupportOnReadyToBoot (
+  IN EFI_EVENT Event,
+  IN VOID      *Context
+  )
+{
+  VOID                          *Pages;
+  CONST VOID                    *Rsdp10;
+  CONST VOID                    *Rsdp20;
+  CONST EFI_CONFIGURATION_TABLE *ConfigTable;
+  CONST EFI_CONFIGURATION_TABLE *ConfigTablesEnd;
+  volatile EFI_GUID             *InverseSignature;
+  UINTN                         Idx;
+
+  Pages = AllocateAlignedPages (EFI_SIZE_TO_PAGES (sizeof *mAcpiTestSupport),
+            SIZE_1MB);
+  if (Pages == NULL) {
+    DEBUG ((DEBUG_WARN, "%a: AllocateAlignedPages() failed\n", __FUNCTION__));
+    UnregisterAcpiTestSupport ();
+    return;
+  }
+
+  //
+  // Locate both gEfiAcpi10TableGuid and gEfiAcpi20TableGuid config tables in
+  // one go.
+  //
+  Rsdp10 = NULL;
+  Rsdp20 = NULL;
+  ConfigTable = gST->ConfigurationTable;
+  ConfigTablesEnd = gST->ConfigurationTable + gST->NumberOfTableEntries;
+  while ((Rsdp10 == NULL || Rsdp20 == NULL) && ConfigTable < ConfigTablesEnd) {
+    if (CompareGuid (&ConfigTable->VendorGuid, &gEfiAcpi10TableGuid)) {
+      Rsdp10 = ConfigTable->VendorTable;
+    } else if (CompareGuid (&ConfigTable->VendorGuid, &gEfiAcpi20TableGuid)) {
+      Rsdp20 = ConfigTable->VendorTable;
+    }
+    ++ConfigTable;
+  }
+
+  DEBUG ((DEBUG_VERBOSE, "%a: AcpiTestSupport=%p Rsdp10=%p Rsdp20=%p\n",
+    __FUNCTION__, Pages, Rsdp10, Rsdp20));
+
+  //
+  // Store the RSD PTR address(es) first, then the signature second.
+  //
+  mAcpiTestSupport = Pages;
+  mAcpiTestSupport->Rsdp10 = (UINTN)Rsdp10;
+  mAcpiTestSupport->Rsdp20 = (UINTN)Rsdp20;
+
+  MemoryFence();
+
+  InverseSignature = &mAcpiTestSupport->InverseSignatureGuid;
+  InverseSignature->Data1  = gAcpiTestSupportGuid.Data1;
+  InverseSignature->Data1 ^= MAX_UINT32;
+  InverseSignature->Data2  = gAcpiTestSupportGuid.Data2;
+  InverseSignature->Data2 ^= MAX_UINT16;
+  InverseSignature->Data3  = gAcpiTestSupportGuid.Data3;
+  InverseSignature->Data3 ^= MAX_UINT16;
+  for (Idx = 0; Idx < sizeof InverseSignature->Data4; ++Idx) {
+    InverseSignature->Data4[Idx]  = gAcpiTestSupportGuid.Data4[Idx];
+    InverseSignature->Data4[Idx] ^= MAX_UINT8;
+  }
+
+  UnregisterAcpiTestSupport ();
+}
+
 VOID
 RegisterAcpiTestSupport (
   VOID
   )
 {
+  EFI_STATUS Status;
+
+  Status = gBS->CreateEventEx (EVT_NOTIFY_SIGNAL, TPL_CALLBACK,
+                  AcpiTestSupportOnReadyToBoot, NULL /* Context */,
+                  &gEfiEventReadyToBootGuid, &mAcpiTestSupportEvent);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_WARN, "%a: CreateEventEx(): %r\n", __FUNCTION__, Status));
+  }
 }
 
 VOID
 UnregisterAcpiTestSupport (
   VOID
   )
 {
+  if (mAcpiTestSupportEvent != NULL) {
+    gBS->CloseEvent (mAcpiTestSupportEvent);
+    mAcpiTestSupportEvent = NULL;
+  }
 }
-- 
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 ` [PATCH 3/4] OvmfPkg/AcpiPlatformDxe: add [Un]RegisterAcpiTestSupport() skeletons Laszlo Ersek
2018-11-25 10:01 ` Laszlo Ersek [this message]
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-5-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