From: Ard Biesheuvel <a...@kernel.org>

Duplicate the logic that is triggered on a system reset into the
platform boot manager driver, and hook it up to the EDK2 platform
specific reset notification driver. This is supported by generic EDK2
code in MdeModulePkg, allowing us to retire the platform-specific
EfiResetSystemLib implementation in a subsequent patch. This is needed
because this library class and its only user ResetRuntimeDxe in
EmbeddedPkg are deprecated and are going to be removed.

Signed-off-by: Ard Biesheuvel <a...@kernel.org>
Reviewed-by: Leif Lindholm <quic_llind...@quicinc.com>
---
 Platform/RaspberryPi/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf 
|  3 +
 Platform/RaspberryPi/Library/PlatformBootManagerLib/PlatformBm.c               
| 76 ++++++++++++++++++++
 2 files changed, 79 insertions(+)

diff --git 
a/Platform/RaspberryPi/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
 
b/Platform/RaspberryPi/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
index 5e55eff7bcf9..9c6bbb9dd102 100644
--- 
a/Platform/RaspberryPi/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
+++ 
b/Platform/RaspberryPi/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
@@ -46,6 +46,7 @@ [LibraryClasses]
   MemoryAllocationLib
   PcdLib
   PrintLib
+  TimerLib
   UefiBootManagerLib
   UefiBootServicesTableLib
   UefiLib
@@ -63,6 +64,7 @@ [FixedPcd]
 [Pcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdBootDiscoveryPolicy
   gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut
+  gRaspberryPiTokenSpaceGuid.PcdPlatformResetDelay
   gRaspberryPiTokenSpaceGuid.PcdSdIsArasan
 
 [Guids]
@@ -78,6 +80,7 @@ [Guids]
   gEfiBootManagerPolicyConnectAllGuid
 
 [Protocols]
+  gEdkiiPlatformSpecificResetHandlerProtocolGuid
   gEfiBootManagerPolicyProtocolGuid
   gEfiDevicePathProtocolGuid
   gEfiGraphicsOutputProtocolGuid
diff --git a/Platform/RaspberryPi/Library/PlatformBootManagerLib/PlatformBm.c 
b/Platform/RaspberryPi/Library/PlatformBootManagerLib/PlatformBm.c
index 1a0fcbf8f908..976e86043790 100644
--- a/Platform/RaspberryPi/Library/PlatformBootManagerLib/PlatformBm.c
+++ b/Platform/RaspberryPi/Library/PlatformBootManagerLib/PlatformBm.c
@@ -17,6 +17,7 @@
 #include <Library/DevicePathLib.h>
 #include <Library/HobLib.h>
 #include <Library/PcdLib.h>
+#include <Library/TimerLib.h>
 #include <Library/UefiBootManagerLib.h>
 #include <Library/UefiLib.h>
 #include <Library/PrintLib.h>
@@ -25,6 +26,7 @@
 #include <Protocol/EsrtManagement.h>
 #include <Protocol/GraphicsOutput.h>
 #include <Protocol/LoadedImage.h>
+#include <Protocol/PlatformSpecificResetHandler.h>
 #include <Guid/BootDiscoveryPolicy.h>
 #include <Guid/EventGroup.h>
 #include <Guid/TtyTerm.h>
@@ -527,6 +529,66 @@ SerialConPrint (
   }
 }
 
+/**
+  Disconnect everything.
+  Modified from the UEFI 2.3 spec (May 2009 version)
+
+**/
+STATIC
+VOID
+DisconnectAll (
+  VOID
+  )
+{
+  EFI_STATUS  Status;
+  UINTN       HandleCount;
+  EFI_HANDLE  *HandleBuffer;
+  UINTN       HandleIndex;
+
+  /*
+   * Retrieve the list of all handles from the handle database
+   */
+  Status = gBS->LocateHandleBuffer (
+                  AllHandles,
+                  NULL,
+                  NULL,
+                  &HandleCount,
+                  &HandleBuffer
+                  );
+  if (EFI_ERROR (Status)) {
+    return;
+  }
+
+  for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
+    gBS->DisconnectController (HandleBuffer[HandleIndex], NULL, NULL);
+  }
+
+  gBS->FreePool(HandleBuffer);
+}
+
+
+STATIC
+VOID
+EFIAPI
+OnResetNotify (
+  IN EFI_RESET_TYPE  ResetType,
+  IN EFI_STATUS      ResetStatus,
+  IN UINTN           DataSize,
+  IN VOID            *ResetData OPTIONAL
+  )
+{
+  UINT32 Delay;
+
+  DisconnectAll ();
+
+  Delay = PcdGet32 (PcdPlatformResetDelay);
+  if (Delay != 0) {
+    DEBUG ((DEBUG_INFO, "Platform will be reset in %d.%d seconds...\n",
+          Delay / 1000000, (Delay % 1000000) / 100000));
+    MicroSecondDelay (Delay);
+  }
+}
+
 //
 // BDS Platform Functions
 //
@@ -549,6 +611,7 @@ PlatformBootManagerBeforeConsole (
 {
   EFI_STATUS Status;
   ESRT_MANAGEMENT_PROTOCOL *EsrtManagement;
+  EDKII_PLATFORM_SPECIFIC_RESET_HANDLER_PROTOCOL *ResetNotify;
 
   if (GetBootModeHob () == BOOT_ON_FLASH_UPDATE) {
     DEBUG ((DEBUG_INFO, "ProcessCapsules Before EndOfDxe ......\n"));
@@ -582,6 +645,19 @@ PlatformBootManagerBeforeConsole (
   EfiBootManagerUpdateConsoleVariable (ConOut, 
(EFI_DEVICE_PATH_PROTOCOL*)&mSerialConsole, NULL);
   EfiBootManagerUpdateConsoleVariable (ErrOut, 
(EFI_DEVICE_PATH_PROTOCOL*)&mSerialConsole, NULL);
 
+  Status = gBS->LocateProtocol (
+                  &gEdkiiPlatformSpecificResetHandlerProtocolGuid,
+                  NULL,
+                  (VOID **)&ResetNotify
+                  );
+  if (!EFI_ERROR (Status)) {
+    Status = ResetNotify->RegisterResetNotify (
+                            ResetNotify,
+                            OnResetNotify
+                            );
+    ASSERT_EFI_ERROR (Status);
+  }
+
   //
   // Signal EndOfDxe PI Event
   //
-- 
2.46.0.rc1.232.g9752f9e123-goog



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#120106): https://edk2.groups.io/g/devel/message/120106
Mute This Topic: https://groups.io/mt/107628980/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to