From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.41]) by mx.groups.io with SMTP id smtpd.web11.5889.1633137400538746496 for ; Fri, 01 Oct 2021 18:16:40 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@vmware.com header.s=selector2 header.b=x6WxmsAp; spf=pass (domain: vmware.com, ip: 40.107.236.41, mailfrom: awarkentin@vmware.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m8VSo2vmSctx5ehw9A8YJ0x9MtLjLvkXA29H5Jfzea9OmDqFXEStekmFRxINQW3KabDU+6O5S9PF+Ol/X/0pNuJ31pZike7ZfqX0a4nFe191mihENliZvOPnB75ZTRgiybm+hYfFhdKfHNoLfE11k906PNiky+CdqrdwSl6SKLm0S1bUmHOTE/HUSHZGIOD6e4LdRRwui1UYxTfZ0zUu9muBzLc7aafuvzCKDjFjLmuLWdT2e+DhL9oDFYa55fIKX6bGrcizE+NdsdqCDMCx99eW+WrczmrZy6CTwHu0P/AyvLZRTNi6a0TNaXmqElHzgCj5FoKmJFOd3xvi7bNYGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7wJYJ1RCaEfdqElFpJRQXJeqq7iZCZAkbkw2LacG+3c=; b=gdD2xJH/lP4+0JrQOr8cHEqvQ7RVpyZfUPJnJJ6viqW/tZ3lJu0ErXx2nktbMiqmHNSQ7OqrdcxYC4SLFGGP9Iv3KL0Gd3RMyGYFVui6R4at7IHKkpPAq1XdalLT1FXrhXPjGk/3lvtQCIxPYx6TIfo2KDFWtuB5Too2/0f0ndTfK9sVCGhHUn/RLKkZ93ICxUADZhQLvlwxtaMTpZePZXcbL41SMOuqlY6y+7vwm665UeGxiEtUD96tAs0sZrFiWu7iUIVPzQKSl9yoFTA5f1VI9OwbXQARoVSjbR1fW1N3q7vB2Q95vbcYefI+XChJRzujlMn0Bg3ydh4I4Gc4tQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vmware.com; dmarc=pass action=none header.from=vmware.com; dkim=pass header.d=vmware.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vmware.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7wJYJ1RCaEfdqElFpJRQXJeqq7iZCZAkbkw2LacG+3c=; b=x6WxmsApq4mZ2k7DUCYFPPLPbsakdPGCTyjpiFJC2ZrxFZVRT+PJpNYUPlBWgUpEvMRe+jSccC598aq70r8ECsp+T+oLAqI0FGk+pbsIIttxDFthmY2tScjTVPEfyQ8QIQRC28jYPtOE8UM1u27YdvviJSh2ZHrpivO300QeiK0= Received: from PH0PR05MB8702.namprd05.prod.outlook.com (2603:10b6:510:b2::21) by PH0PR05MB8800.namprd05.prod.outlook.com (2603:10b6:510:bb::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.7; Sat, 2 Oct 2021 01:16:38 +0000 Received: from PH0PR05MB8702.namprd05.prod.outlook.com ([fe80::c88e:73c1:db37:5b94]) by PH0PR05MB8702.namprd05.prod.outlook.com ([fe80::c88e:73c1:db37:5b94%7]) with mapi id 15.20.4587.009; Sat, 2 Oct 2021 01:16:38 +0000 From: "Andrei Warkentin" To: Jeremy Linton , "devel@edk2.groups.io" CC: "pete@akeo.ie" , "ardb+tianocore@kernel.org" , "leif@nuviainc.com" , "Sunny.Wang@arm.com" , "samer.el-haj-mahmoud@arm.com" Subject: Re: [PATCH 5/5] Platform/RaspberryPi: Disconnect/shutdown all drivers before reboot Thread-Topic: [PATCH 5/5] Platform/RaspberryPi: Disconnect/shutdown all drivers before reboot Thread-Index: AQHXtyfU4kO+c+WHZUew5Hs+535S5Ku+5+bA Date: Sat, 2 Oct 2021 01:16:38 +0000 Message-ID: References: <20211002005238.40280-1-jeremy.linton@arm.com> <20211002005238.40280-6-jeremy.linton@arm.com> In-Reply-To: <20211002005238.40280-6-jeremy.linton@arm.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: suggested_attachment_session_id: b93bf2bd-92d3-6678-f424-bd2e7f041e62 authentication-results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=vmware.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e90c949e-cec5-4974-c06b-08d9854248f6 x-ms-traffictypediagnostic: PH0PR05MB8800: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: pd9DYEy4hHchSj6xydT53RfngCtlr/LLgmR0JhoD2L/h2m/owJsDNRMz35KQBVq305VP4+QYWpzQ6+IDr/sXRvaX+l4uCH2UNRgSlUjezpqPdO4AdVnnCzyL2tUGCruxNLgTqqDhBMaWSlenu43B0W9J5zFhzh7ZQCvMK2tYkaGtjm7Fo9fT2B290yZ2wwxmiBRnfOjTDLDfVipXIV5Z7lsjDilvRNQfUbeZN7J30GiTBHvXwHjY7+pNCeUWc/JprZSMq6L+bTzB8DLZlVt3waQjIZAAGg6enjuD5bH5o5Q2YP5fstCZPm/FYdNnNFWoGIWYOAuYNJG2E+2xkvM3b0MqIWlJbzYy+xaTGuophh+B1Z7pIPRpoVDwDtwmeH8mCVAf+Uv7HshF34QVCtin0zdHssAyQ//dA7jESt/f33oiCjXvwLzhhFGuSLaSrUIorV1/osIG9c0pdhok8hha8F7WjjbZ9YeLpL4DpnggCcoEkl4Emof8ywmnMiaOE3CpIMQqervZMmnehuKU7KiHebAhbz1J0fR2+KQEzqO1Er6Cf3yZ9wy9bYf1SQVk3TRqMzKsQJ9svMTnToHc62gcdn/JCxdxpUpHRD8u1imhs5Udf8GDXV9/iFITlDoTwYJeF+OIvVnhSyIL7VEmhMqAU8iKHY3qkrR7FLy45ojS2sUgkUudyUNngy/bsBsDJ7O8mtgw8DXt98z6cN3OvVMpWg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR05MB8702.namprd05.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(55016002)(26005)(5660300002)(71200400001)(122000001)(52536014)(7696005)(9686003)(8936002)(6506007)(66446008)(83380400001)(33656002)(508600001)(8676002)(66556008)(66946007)(91956017)(2906002)(38070700005)(66476007)(64756008)(186003)(38100700002)(316002)(76116006)(4326008)(110136005)(19627405001)(86362001)(54906003)(53546011);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?xxYL0Hzl0uN+3w3YMooW5Vad9tM2qAvZNe2OwybCC2B4+ERaz2zhkD/Dtxvo?= =?us-ascii?Q?8zvM2Uy8n7mLL1yBRWlDfKn8mf0D8raCQ4vDnpD/mhYeLstc4DxswDuVAGNf?= =?us-ascii?Q?CgGca1uDzttQ8SI/m2qDsYVXz0xGqIY2NpqJgFqDqvfWiFxErP6nyEKmyN0V?= =?us-ascii?Q?0IWYZC/FOswRbNQT2UkrwBJAMB78TNAIHWmrxPuIgNdAJk/dH/w1wTYKlWVv?= =?us-ascii?Q?xXX2GJDPWNMFqIErU2t+B2LQNnX+CbcEAfZKo99dokM7On2JdGgGfB9pOQ5h?= =?us-ascii?Q?ukoWXmuHZpvrEtkvTyKXZ3yNKcIEygZ880y9B5xZ/FT57pFhgbIZArH6hion?= =?us-ascii?Q?ryeWRsrfQab5mGkS5pM2kcT+RuqtXt32ITnu7KnAez6nVPUIvYUYcaeDz7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fKmRgiSprUEeZ/SmUP/O46x1Gjl?= =?us-ascii?Q?Mj0=3D?= x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PH0PR05MB8702.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e90c949e-cec5-4974-c06b-08d9854248f6 X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Oct 2021 01:16:38.6588 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: g3IF1/ICf+mgZBCYaTZ2Nn5cT0uwdFitSlrowaFAbqP9RFH3omFqg98U9oF6AGdAECVuppyOEY2AE5pAIsk8aA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR05MB8800 Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_PH0PR05MB870271E7BBA4035FB57541F5B9AC9PH0PR05MB8702namp_" --_000_PH0PR05MB870271E7BBA4035FB57541F5B9AC9PH0PR05MB8702namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Seems smart to do. Reviewed-by: Andrei Warkentin ________________________________ From: Jeremy Linton Sent: Friday, October 1, 2021 7:52 PM To: devel@edk2.groups.io Cc: pete@akeo.ie ; ardb+tianocore@kernel.org ; leif@nuviainc.com ; Andrei Warkentin ; Sunny.Wang@arm.com ; samer.el-haj-ma= hmoud@arm.com ; Jeremy Linton Subject: [PATCH 5/5] Platform/RaspberryPi: Disconnect/shutdown all drivers = before reboot In theory we should be properly cleaning up all the device drivers before pulling the big switch. Particularly the partition mgr will issue flush commands to attached disks as it goes down. This assures that devices running in WB mode (that correctly handle flush/sync/etc) commands are persisted to physical media before we hit reset. Without this, there are definitly 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 persistance requests but we can start here. Signed-off-by: Jeremy Linton --- Platform/RaspberryPi/Library/ResetLib/ResetLib.c | 44 ++++++++++++++++++++= ++++ 1 file changed, 44 insertions(+) diff --git a/Platform/RaspberryPi/Library/ResetLib/ResetLib.c b/Platform/Ra= spberryPi/Library/ResetLib/ResetLib.c index a70eee485d..036f619cb5 100644 --- a/Platform/RaspberryPi/Library/ResetLib/ResetLib.c +++ b/Platform/RaspberryPi/Library/ResetLib/ResetLib.c @@ -19,11 +19,54 @@ #include #include #include +#include #include #include #include + +/** + Disconnect everything. + Modified from the UEFI 2.3 spec (May 2009 version) + + @retval EFI_SUCCESS The operation was successful. + +**/ +EFI_STATUS +DisconnectAll( + VOID + ) +{ + EFI_STATUS Status; + UINTN HandleCount; + EFI_HANDLE *HandleBuffer; + UINTN HandleIndex; + + // + // Retrieve the list of all handles from the handle database + // + Status =3D gBS->LocateHandleBuffer ( + AllHandles, + NULL, + NULL, + &HandleCount, + &HandleBuffer + ); + if (!EFI_ERROR (Status)) { + for (HandleIndex =3D 0; HandleIndex < HandleCount; HandleIndex++) { + Status =3D gBS->DisconnectController ( + HandleBuffer[HandleIndex], + NULL, + NULL + ); + } + gBS->FreePool(HandleBuffer); + } + return (EFI_SUCCESS); +} + + /** Resets the entire platform. @@ -57,6 +100,7 @@ LibResetSystem ( if (Delay !=3D 0) { DEBUG ((DEBUG_INFO, "Platform will be reset in %d.%d seconds...\n", Delay / 1000000, (Delay % 1000000) / 100000)); + DisconnectAll (); MicroSecondDelay (Delay); } } -- 2.13.7 --_000_PH0PR05MB870271E7BBA4035FB57541F5B9AC9PH0PR05MB8702namp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
Seems smart to do.

Reviewed-by: Andrei Warkentin <awarkentin@vmware.com>

From: Jeremy Linton <jer= emy.linton@arm.com>
Sent: Friday, October 1, 2021 7:52 PM
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: pete@akeo.ie <pete@akeo.ie>; ardb+tianocore@kernel.org <= ;ardb+tianocore@kernel.org>; leif@nuviainc.com <leif@nuviainc.com>= ; Andrei Warkentin <awarkentin@vmware.com>; Sunny.Wang@arm.com <Su= nny.Wang@arm.com>; samer.el-haj-mahmoud@arm.com <samer.el-haj-mahmoud= @arm.com>; Jeremy Linton <jeremy.linton@arm.com>
Subject: [PATCH 5/5] Platform/RaspberryPi: Disconnect/shutdown all d= rivers before reboot
 
In theory we should be properly cleaning up all th= e device drivers before
pulling the big switch. Particularly the partition mgr will issue
flush commands to attached disks as it goes down. This assures that
devices running in WB mode (that correctly handle flush/sync/etc) commands<= br> are persisted to physical media before we hit reset.

Without this, there are definitly 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 persistance requests but we can start here.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
---
 Platform/RaspberryPi/Library/ResetLib/ResetLib.c | 44 +++++++++++++++= +++++++++
 1 file changed, 44 insertions(+)

diff --git a/Platform/RaspberryPi/Library/ResetLib/ResetLib.c b/Platform/Ra= spberryPi/Library/ResetLib/ResetLib.c
index a70eee485d..036f619cb5 100644
--- a/Platform/RaspberryPi/Library/ResetLib/ResetLib.c
+++ b/Platform/RaspberryPi/Library/ResetLib/ResetLib.c
@@ -19,11 +19,54 @@
 #include <Library/TimerLib.h>
 #include <Library/EfiResetSystemLib.h>
 #include <Library/ArmSmcLib.h>
+#include <Library/UefiBootServicesTableLib.h>
 #include <Library/UefiLib.h>
 #include <Library/UefiRuntimeLib.h>
 
 #include <IndustryStandard/ArmStdSmc.h>
 
+
+/**
+  Disconnect everything.
+  Modified from the UEFI 2.3 spec (May 2009 version)
+
+  @retval EFI_SUCCESS     The operation was succe= ssful.
+
+**/
+EFI_STATUS
+DisconnectAll(
+  VOID
+  )
+{
+  EFI_STATUS Status;
+  UINTN HandleCount;
+  EFI_HANDLE *HandleBuffer;
+  UINTN HandleIndex;
+
+  //
+  // Retrieve the list of all handles from the handle database
+  //
+  Status =3D gBS->LocateHandleBuffer (
+    AllHandles,
+    NULL,
+    NULL,
+    &HandleCount,
+    &HandleBuffer
+   );
+  if (!EFI_ERROR (Status)) {
+    for (HandleIndex =3D 0; HandleIndex < HandleCount; H= andleIndex++) {
+      Status =3D gBS->DisconnectController ( +        HandleBuffer[HandleIndex],
+        NULL,
+        NULL
+       );
+    }
+    gBS->FreePool(HandleBuffer);
+  }
+  return (EFI_SUCCESS);
+}
+
+
 /**
   Resets the entire platform.
 
@@ -57,6 +100,7 @@ LibResetSystem (
     if (Delay !=3D 0) {
       DEBUG ((DEBUG_INFO, "Platform wil= l be reset in %d.%d seconds...\n",
            &nb= sp;  Delay / 1000000, (Delay % 1000000) / 100000));
+      DisconnectAll ();
       MicroSecondDelay (Delay);
     }
   }
--
2.13.7

--_000_PH0PR05MB870271E7BBA4035FB57541F5B9AC9PH0PR05MB8702namp_--