From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.155.1634590295534584673 for ; Mon, 18 Oct 2021 13:51:35 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: jeremy.linton@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 364B6D6E; Mon, 18 Oct 2021 13:51:35 -0700 (PDT) Received: from u200856.usa.arm.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D20293F73D; Mon, 18 Oct 2021 13:51:34 -0700 (PDT) From: "Jeremy Linton" To: devel@edk2.groups.io Cc: pete@akeo.ie, ardb+tianocore@kernel.org, leif@nuviainc.com, awarkentin@vmware.com, Sunny.Wang@arm.com, samer.el-haj-mahmoud@arm.com, kettenis@openbsd.org, Jeremy Linton Subject: [PATCH v2 5/5] Platform/RaspberryPi: Disconnect/shutdown all drivers before reboot Date: Mon, 18 Oct 2021 15:51:27 -0500 Message-Id: <20211018205127.7099-6-jeremy.linton@arm.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20211018205127.7099-1-jeremy.linton@arm.com> References: <20211018205127.7099-1-jeremy.linton@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7bit In theory we should be properly cleaning up all the device drivers before hitting the big reset. The partition manager will issue flush commands to attached disks as it goes down. This assures that devices running in WB mode, which correctly handle flush/sync/etc commands, are persisted to physical media before reset. Without this, there are definitely cases where the relevant specifications don't guarantee persistence of data in their buffers in the face of reset conditions. We can't really do anything about the many devices that don't honor persistence requests, but we can start here. Signed-off-by: Jeremy Linton --- Platform/RaspberryPi/Library/ResetLib/ResetLib.c | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/Platform/RaspberryPi/Library/ResetLib/ResetLib.c b/Platform/RaspberryPi/Library/ResetLib/ResetLib.c index a70eee485d..2bcef8d4db 100644 --- a/Platform/RaspberryPi/Library/ResetLib/ResetLib.c +++ b/Platform/RaspberryPi/Library/ResetLib/ResetLib.c @@ -19,11 +19,51 @@ #include #include #include +#include #include #include #include + +/** + 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); +} + + /** Resets the entire platform. @@ -53,6 +93,8 @@ LibResetSystem ( */ EfiEventGroupSignal (&gRaspberryPiEventResetGuid); + DisconnectAll (); + Delay = PcdGet32 (PcdPlatformResetDelay); if (Delay != 0) { DEBUG ((DEBUG_INFO, "Platform will be reset in %d.%d seconds...\n", -- 2.13.7