From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail05.groups.io (mail05.groups.io [45.79.224.7]) by spool.mail.gandi.net (Postfix) with ESMTPS id 1F66BAC132D for ; Tue, 30 Jul 2024 15:08:24 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=VF4mWabdYOEc8XZXVrhlBrolZeqafezaLaUCJPUdU74=; c=relaxed/simple; d=groups.io; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From:To:Cc:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type; s=20240206; t=1722352104; v=1; b=S5O7d9sC65WZYGtw28UowWzCEA2QGBsREYlJAp4+hduorLzF+lMXJEBhlGly6NCxwTwhnqSi HaeFX63XEnwy0d6nwvIt9iJ2se8fE7pPiyzcwc3oaK8wFiI9AVi65bL/FTOW19Jfc5bAhj6Zz3M OuVlBMxA8Gl8VPJHxeliMjwSR52dnOYl4Fx6/jLrXI7zNuCP18gF+bbewMbVlveijuNqKR5il9K GGu6qBjyruhYMF0hHX8Gps7qJRO2hP1/nKjvE3tYgbt9rAyKsY0dQ7vmwKGeuAazX7gH/eKVQSH n6skOeqMg7CpBaBff3uEv4xsDZrLtcScAt5IpiKCMmH6A== X-Received: by 127.0.0.2 with SMTP id Jc8dYY7687511xwC986LjUh8; Tue, 30 Jul 2024 08:08:23 -0700 X-Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by mx.groups.io with SMTP id smtpd.web11.42531.1722199496130904792 for ; Sun, 28 Jul 2024 13:44:56 -0700 X-Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-4280fb8f919so13092865e9.2 for ; Sun, 28 Jul 2024 13:44:55 -0700 (PDT) X-Gm-Message-State: xU21MKjiancnxiBUF4b2OVDUx7686176AA= X-Google-Smtp-Source: AGHT+IFav06KChd8IOmu/7uWAE7AU82NjOzMdPBNtOla/iifKpKDNL6zNqbcmXd2k2jdiewiCq7JgjKg X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:600c:3b1e:b0:426:6dbd:f9d3 with SMTP id 5b1f17b1804b1-42811e0b580mr916125e9.6.1722199494519; Sun, 28 Jul 2024 13:44:54 -0700 (PDT) Date: Sun, 28 Jul 2024 22:44:33 +0200 In-Reply-To: <20240728204437.4064847-1-ardb+git@google.com> Mime-Version: 1.0 References: <20240728204437.4064847-1-ardb+git@google.com> Message-ID: <20240728204437.4064847-7-ardb+git@google.com> Subject: [edk2-devel] [PATCH edk2-platforms v2 6/8] Platform/RaspberryPi/PlatformBootManagerLib: Reimplement reset hook From: "Ard Biesheuvel via groups.io" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Leif Lindholm , Jeremy Linton Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Resent-Date: Tue, 30 Jul 2024 08:08:18 -0700 Resent-From: ardb+git@google.com Reply-To: devel@edk2.groups.io,ardb+git@google.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Type: text/plain; charset="UTF-8" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=S5O7d9sC; dmarc=pass (policy=none) header.from=groups.io; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io From: Ard Biesheuvel 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 Reviewed-by: Leif Lindholm --- 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 #include #include +#include #include #include #include @@ -25,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -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/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-