Blame SOURCES/ovmf-ArmVirtPkg-FdtClientDxe-install-DT-as-sysconfig-tabl.patch

eb7fe6
From 8db5445541920509ba0416b480e4fc65c3c5fade Mon Sep 17 00:00:00 2001
eb7fe6
From: Laszlo Ersek <lersek@redhat.com>
eb7fe6
Date: Wed, 29 Mar 2017 12:26:21 +0200
eb7fe6
Subject: [PATCH 09/11] ArmVirtPkg/FdtClientDxe: install DT as sysconfig table
eb7fe6
 in protocol notify
eb7fe6
eb7fe6
Message-id: <20170329102623.11570-10-lersek@redhat.com>
eb7fe6
Patchwork-id: 74577
eb7fe6
O-Subject:  [RHEL-7.4 ovmf PATCH 09/11] ArmVirtPkg/FdtClientDxe: install DT as
eb7fe6
	sysconfig table in protocol notify
eb7fe6
Bugzilla: 1430262
eb7fe6
Acked-by: Andrew Jones <drjones@redhat.com>
eb7fe6
Acked-by: Al Stone <ahs3@redhat.com>
eb7fe6
Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
eb7fe6
eb7fe6
Replace the dependency on PcdPureAcpiBoot with a Platform Has Device Tree
eb7fe6
notification callback. Move the sysconfig table installation from the
eb7fe6
entry point function to the callback.
eb7fe6
eb7fe6
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
eb7fe6
Cc: Leif Lindholm <leif.lindholm@linaro.org>
eb7fe6
Contributed-under: TianoCore Contribution Agreement 1.0
eb7fe6
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
eb7fe6
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
eb7fe6
(cherry picked from commit 51b09a2c50c60eb5dd3996b97f375eb596c5cc1d)
eb7fe6
---
eb7fe6
 ArmVirtPkg/FdtClientDxe/FdtClientDxe.c   | 105 ++++++++++++++++++++++++++++---
eb7fe6
 ArmVirtPkg/FdtClientDxe/FdtClientDxe.inf |   4 +-
eb7fe6
 2 files changed, 97 insertions(+), 12 deletions(-)
eb7fe6
eb7fe6
diff --git a/ArmVirtPkg/FdtClientDxe/FdtClientDxe.c b/ArmVirtPkg/FdtClientDxe/FdtClientDxe.c
eb7fe6
index 547a29f..2d867b1 100644
eb7fe6
--- a/ArmVirtPkg/FdtClientDxe/FdtClientDxe.c
eb7fe6
+++ b/ArmVirtPkg/FdtClientDxe/FdtClientDxe.c
eb7fe6
@@ -22,6 +22,7 @@
eb7fe6
 
eb7fe6
 #include <Guid/Fdt.h>
eb7fe6
 #include <Guid/FdtHob.h>
eb7fe6
+#include <Guid/PlatformHasDeviceTree.h>
eb7fe6
 
eb7fe6
 #include <Protocol/FdtClient.h>
eb7fe6
 
eb7fe6
@@ -306,6 +307,40 @@ STATIC FDT_CLIENT_PROTOCOL mFdtClientProtocol = {
eb7fe6
   GetOrInsertChosenNode,
eb7fe6
 };
eb7fe6
 
eb7fe6
+STATIC
eb7fe6
+VOID
eb7fe6
+EFIAPI
eb7fe6
+OnPlatformHasDeviceTree (
eb7fe6
+  IN EFI_EVENT Event,
eb7fe6
+  IN VOID      *Context
eb7fe6
+  )
eb7fe6
+{
eb7fe6
+  EFI_STATUS Status;
eb7fe6
+  VOID       *Interface;
eb7fe6
+  VOID       *DeviceTreeBase;
eb7fe6
+
eb7fe6
+  Status = gBS->LocateProtocol (
eb7fe6
+                  &gEdkiiPlatformHasDeviceTreeGuid,
eb7fe6
+                  NULL,                             // Registration
eb7fe6
+                  &Interface
eb7fe6
+                  );
eb7fe6
+  if (EFI_ERROR (Status)) {
eb7fe6
+    return;
eb7fe6
+  }
eb7fe6
+
eb7fe6
+  DeviceTreeBase = Context;
eb7fe6
+  DEBUG ((
eb7fe6
+    DEBUG_INFO,
eb7fe6
+    "%a: exposing DTB @ 0x%p to OS\n",
eb7fe6
+    __FUNCTION__,
eb7fe6
+    DeviceTreeBase
eb7fe6
+    ));
eb7fe6
+  Status = gBS->InstallConfigurationTable (&gFdtTableGuid, DeviceTreeBase);
eb7fe6
+  ASSERT_EFI_ERROR (Status);
eb7fe6
+
eb7fe6
+  gBS->CloseEvent (Event);
eb7fe6
+}
eb7fe6
+
eb7fe6
 EFI_STATUS
eb7fe6
 EFIAPI
eb7fe6
 InitializeFdtClientDxe (
eb7fe6
@@ -316,6 +351,8 @@ InitializeFdtClientDxe (
eb7fe6
   VOID              *Hob;
eb7fe6
   VOID              *DeviceTreeBase;
eb7fe6
   EFI_STATUS        Status;
eb7fe6
+  EFI_EVENT         PlatformHasDeviceTreeEvent;
eb7fe6
+  VOID              *Registration;
eb7fe6
 
eb7fe6
   Hob = GetFirstGuidHob (&gFdtHobGuid);
eb7fe6
   if (Hob == NULL || GET_GUID_HOB_DATA_SIZE (Hob) != sizeof (UINT64)) {
eb7fe6
@@ -333,15 +370,65 @@ InitializeFdtClientDxe (
eb7fe6
 
eb7fe6
   DEBUG ((EFI_D_INFO, "%a: DTB @ 0x%p\n", __FUNCTION__, mDeviceTreeBase));
eb7fe6
 
eb7fe6
-  if (!FeaturePcdGet (PcdPureAcpiBoot)) {
eb7fe6
-    //
eb7fe6
-    // Only install the FDT as a configuration table if we want to leave it up
eb7fe6
-    // to the OS to decide whether it prefers ACPI over DT.
eb7fe6
-    //
eb7fe6
-    Status = gBS->InstallConfigurationTable (&gFdtTableGuid, DeviceTreeBase);
eb7fe6
-    ASSERT_EFI_ERROR (Status);
eb7fe6
+  //
eb7fe6
+  // Register a protocol notify for the EDKII Platform Has Device Tree
eb7fe6
+  // Protocol.
eb7fe6
+  //
eb7fe6
+  Status = gBS->CreateEvent (
eb7fe6
+                  EVT_NOTIFY_SIGNAL,
eb7fe6
+                  TPL_CALLBACK,
eb7fe6
+                  OnPlatformHasDeviceTree,
eb7fe6
+                  DeviceTreeBase,             // Context
eb7fe6
+                  &PlatformHasDeviceTreeEvent
eb7fe6
+                  );
eb7fe6
+  if (EFI_ERROR (Status)) {
eb7fe6
+    DEBUG ((DEBUG_ERROR, "%a: CreateEvent(): %r\n", __FUNCTION__, Status));
eb7fe6
+    return Status;
eb7fe6
+  }
eb7fe6
+
eb7fe6
+  Status = gBS->RegisterProtocolNotify (
eb7fe6
+                  &gEdkiiPlatformHasDeviceTreeGuid,
eb7fe6
+                  PlatformHasDeviceTreeEvent,
eb7fe6
+                  &Registration
eb7fe6
+                  );
eb7fe6
+  if (EFI_ERROR (Status)) {
eb7fe6
+    DEBUG ((
eb7fe6
+      DEBUG_ERROR,
eb7fe6
+      "%a: RegisterProtocolNotify(): %r\n",
eb7fe6
+      __FUNCTION__,
eb7fe6
+      Status
eb7fe6
+      ));
eb7fe6
+    goto CloseEvent;
eb7fe6
+  }
eb7fe6
+
eb7fe6
+  //
eb7fe6
+  // Kick the event; the protocol could be available already.
eb7fe6
+  //
eb7fe6
+  Status = gBS->SignalEvent (PlatformHasDeviceTreeEvent);
eb7fe6
+  if (EFI_ERROR (Status)) {
eb7fe6
+    DEBUG ((DEBUG_ERROR, "%a: SignalEvent(): %r\n", __FUNCTION__, Status));
eb7fe6
+    goto CloseEvent;
eb7fe6
   }
eb7fe6
 
eb7fe6
-  return gBS->InstallProtocolInterface (&ImageHandle, &gFdtClientProtocolGuid,
eb7fe6
-                EFI_NATIVE_INTERFACE, &mFdtClientProtocol);
eb7fe6
+  Status = gBS->InstallProtocolInterface (
eb7fe6
+                  &ImageHandle,
eb7fe6
+                  &gFdtClientProtocolGuid,
eb7fe6
+                  EFI_NATIVE_INTERFACE,
eb7fe6
+                  &mFdtClientProtocol
eb7fe6
+                  );
eb7fe6
+  if (EFI_ERROR (Status)) {
eb7fe6
+    DEBUG ((
eb7fe6
+      DEBUG_ERROR,
eb7fe6
+      "%a: InstallProtocolInterface(): %r\n",
eb7fe6
+      __FUNCTION__,
eb7fe6
+      Status
eb7fe6
+      ));
eb7fe6
+    goto CloseEvent;
eb7fe6
+  }
eb7fe6
+
eb7fe6
+  return Status;
eb7fe6
+
eb7fe6
+CloseEvent:
eb7fe6
+  gBS->CloseEvent (PlatformHasDeviceTreeEvent);
eb7fe6
+  return Status;
eb7fe6
 }
eb7fe6
diff --git a/ArmVirtPkg/FdtClientDxe/FdtClientDxe.inf b/ArmVirtPkg/FdtClientDxe/FdtClientDxe.inf
eb7fe6
index 3a0cd37..8a5182a 100644
eb7fe6
--- a/ArmVirtPkg/FdtClientDxe/FdtClientDxe.inf
eb7fe6
+++ b/ArmVirtPkg/FdtClientDxe/FdtClientDxe.inf
eb7fe6
@@ -42,11 +42,9 @@
eb7fe6
   gFdtClientProtocolGuid                  ## PRODUCES
eb7fe6
 
eb7fe6
 [Guids]
eb7fe6
+  gEdkiiPlatformHasDeviceTreeGuid ## CONSUMES ## PROTOCOL
eb7fe6
   gFdtHobGuid
eb7fe6
   gFdtTableGuid
eb7fe6
 
eb7fe6
-[FeaturePcd]
eb7fe6
-  gArmVirtTokenSpaceGuid.PcdPureAcpiBoot
eb7fe6
-
eb7fe6
 [Depex]
eb7fe6
   TRUE
eb7fe6
-- 
eb7fe6
1.8.3.1
eb7fe6