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 7DFB8941AE4 for ; Tue, 30 Jul 2024 15:08:15 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=y9zhPy3D12jYbT4bHyOjMWGkPyqv1DBOqa7BNO8fjnQ=; 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=1722352095; v=1; b=E0iOf0BrRCfXw9TkzKI0rFNGGJSZPihfOC3w3mdSEWP0OGbF71bMZnZusg5l1y949LpRrLNa KEatOhGxI1njUlQzAYsAx9wRQlvzo+1Hg3XgTXeWjEvWEg3TBsE/VFo0caWNgW1BjPvgqt4rTcn +euYp5ffIipgXEfzD1Ylx6BXFNhHIfz0hpm511nel9hvWvkpIJkO/wBKlq2uqyKISxxaR03mnLI q6ulDvofmq0I5+RTuMKRFXCPaoLo5Zx/z4pz7XNXwJ4lRzztFVF1C73xuzzrrr6UmSgKe2WD55P LfhS7CzbPNKPtf32bkdamkaXdUUa1JvtJmDt00Wq+sing== X-Received: by 127.0.0.2 with SMTP id MgTrYY7687511xOXaximumxX; Tue, 30 Jul 2024 08:08:14 -0700 X-Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by mx.groups.io with SMTP id smtpd.web11.33580.1721904226075394459 for ; Thu, 25 Jul 2024 03:43:46 -0700 X-Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e0b39c429a1so24124276.0 for ; Thu, 25 Jul 2024 03:43:45 -0700 (PDT) X-Gm-Message-State: aiyoArUIsazz1ztGEMXsC1zXx7686176AA= X-Google-Smtp-Source: AGHT+IEtrJ35xjZnWz2Oy5c345gW0gRncUV0lIA1dVgFjfrlXZulsHPgvH+Ir1K6xguC7dLcu43ahJA2 X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:6902:1021:b0:e02:c619:73d with SMTP id 3f1490d57ef6-e0b2ca8e1bcmr7146276.5.1721904225056; Thu, 25 Jul 2024 03:43:45 -0700 (PDT) Date: Thu, 25 Jul 2024 12:43:28 +0200 In-Reply-To: <20240725104332.1675625-1-ardb+git@google.com> Mime-Version: 1.0 References: <20240725104332.1675625-1-ardb+git@google.com> Message-ID: <20240725104332.1675625-4-ardb+git@google.com> Subject: [edk2-devel] [PATCH edk2-platforms 3/5] 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:07:57 -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=E0iOf0Br; 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 --- 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 (#120097): https://edk2.groups.io/g/devel/message/120097 Mute This Topic: https://groups.io/mt/107628961/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-