public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ard Biesheuvel" <ard.biesheuvel@arm.com>
To: devel@edk2.groups.io
Cc: leif@nuviainc.com, Samer.El-Haj-Mahmoud@arm.com,
	Ard Biesheuvel <ard.biesheuvel@arm.com>
Subject: [PATCH edk2-platforms 1/2] Silicon/SynQuacer/PlatformDxe: defer device registration until EndOfDxe
Date: Wed,  8 Apr 2020 18:11:37 +0200	[thread overview]
Message-ID: <20200408161138.18289-2-ard.biesheuvel@arm.com> (raw)
In-Reply-To: <20200408161138.18289-1-ard.biesheuvel@arm.com>

EDK2 carries an interesting quirk which dates back to the EFI 1.02 days,
where each protocol that is installed onto a handle during the execution
of a DXE driver's entrypoint is connected immediately (in the UEFI driver
model sense) after the entry point returns.

This means that, depending on the order that these drivers happen to end
up being dispatched, we may enter the BDS phase with the device's driver
stack fully connected, even if the device in question is not being used
to boot the machine.

Given the substantial delays that this might incur, let's work around
this 'feature' by deferring the registration of the network and eMMC
controllers to an EndOfDxe event handler.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
---
 Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.c   | 37 ++++++++++++++------
 Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.inf |  1 +
 2 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.c b/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.c
index b6e2789cb9d2..09200a918009 100644
--- a/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.c
+++ b/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.c
@@ -301,6 +301,28 @@ InstallAcpiTables (
   }
 }
 
+STATIC
+VOID
+EFIAPI
+RegisterDevices (
+  EFI_EVENT           Event,
+  VOID                *Context
+  )
+{
+  EFI_HANDLE                      Handle;
+  EFI_STATUS                      Status;
+
+  Handle = NULL;
+  Status = RegisterDevice (&gNetsecNonDiscoverableDeviceGuid, mNetsecDesc,
+             &Handle);
+  ASSERT_EFI_ERROR (Status);
+
+  if (mHiiSettings->EnableEmmc == EMMC_ENABLED) {
+    Status = RegisterEmmc ();
+    ASSERT_EFI_ERROR (Status);
+  }
+}
+
 EFI_STATUS
 EFIAPI
 PlatformDxeEntryPoint (
@@ -315,6 +337,7 @@ PlatformDxeEntryPoint (
   EFI_ACPI_DESCRIPTION_HEADER     *Ssdt;
   UINTN                           SsdtSize;
   UINTN                           Index;
+  EFI_EVENT                       EndOfDxeEvent;
 
   mHiiSettingsVal = PcdGet64 (PcdPlatformSettings);
   mHiiSettings = (SYNQUACER_PLATFORM_VARSTORE_DATA *)&mHiiSettingsVal;
@@ -344,11 +367,6 @@ PlatformDxeEntryPoint (
     }
   }
 
-  Handle = NULL;
-  Status = RegisterDevice (&gNetsecNonDiscoverableDeviceGuid, mNetsecDesc,
-             &Handle);
-  ASSERT_EFI_ERROR (Status);
-
   Handle = NULL;
   Status = RegisterDevice (&gSynQuacerNonDiscoverableRuntimeI2cMasterGuid,
              mI2c0Desc, &Handle);
@@ -387,11 +405,6 @@ PlatformDxeEntryPoint (
   Status = EnableSettingsForm ();
   ASSERT_EFI_ERROR (Status);
 
-  if (mHiiSettings->EnableEmmc == EMMC_ENABLED) {
-    Status = RegisterEmmc ();
-    ASSERT_EFI_ERROR (Status);
-  }
-
   if (mHiiSettings->AcpiPref == ACPIPREF_ACPI) {
     //
     // Load the SSDT tables from a raw section in this FFS file.
@@ -431,5 +444,9 @@ PlatformDxeEntryPoint (
     }
   }
 
+  Status = gBS->CreateEventEx (EVT_NOTIFY_SIGNAL, TPL_NOTIFY, RegisterDevices,
+                  NULL, &gEfiEndOfDxeEventGroupGuid, &EndOfDxeEvent);
+  ASSERT_EFI_ERROR (Status);
+
   return EFI_SUCCESS;
 }
diff --git a/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.inf b/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.inf
index 57f2d071c14e..157f914ea85d 100644
--- a/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.inf
+++ b/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.inf
@@ -57,6 +57,7 @@ [LibraryClasses]
 [Guids]
   g96BoardsI2c0MasterGuid
   gEdkiiPlatformHasAcpiGuid
+  gEfiEndOfDxeEventGroupGuid
   gEfiHiiPlatformSetupFormsetGuid
   gFdtTableGuid
   gNetsecNonDiscoverableDeviceGuid
-- 
2.17.1


  reply	other threads:[~2020-04-08 16:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-08 16:11 [PATCH edk2-platforms 0/2] SynQuacer: fix driver model integration of NetSec Ard Biesheuvel
2020-04-08 16:11 ` Ard Biesheuvel [this message]
2020-04-08 16:11 ` [PATCH edk2-platforms 2/2] Silicon/SynQuacer/NetsecDxe: move device path to root device Ard Biesheuvel
2020-04-08 16:26 ` [PATCH edk2-platforms 0/2] SynQuacer: fix driver model integration of NetSec Leif Lindholm
2020-04-09  5:48   ` Ard Biesheuvel

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=20200408161138.18289-2-ard.biesheuvel@arm.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