From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from BN1PR04CU002.outbound.protection.outlook.com (mail-eastus2azon11010057.outbound.protection.outlook.com [52.101.56.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41CF03CF1F6 for ; Mon, 29 Jun 2026 14:10:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.56.57 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782742211; cv=fail; b=cbmQin6tU3Di6QPM1a6G3lTalFDFKUXV9VUR98MTnra7mUq8zvgTpVn5C0fPztISiwHU0ieSHQzr5OsMNaA6TmTHtI1sUPQJwkWQYy6/+ajoCUdNJQMA3gXaBsitP2Y7guH4qGG+UN1u/DiDqpnuvuCBYkoalOeLpPneq7PP5WY= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782742211; c=relaxed/simple; bh=S0xrfxAg2fYi0/QuVCLWG78e7Cm2SX5TpPRwL7hJn9s=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=DPRl6nJGQrLjOQ15hcAhsWcnEQy1C04NZMB4rE0UZwthmN7kI57ptJcCR1hx/5PjNnHdcUHzarjBR4IxSrThpjsTf+cZREhZBzJD4/4mNIOaoZGkM4xFs+YTxu83ol/TqZf8WuBMQ/6wigYM68/kxjr4E0/Ylql02L3uJewBuXg= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=nNRu96LO; arc=fail smtp.client-ip=52.101.56.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="nNRu96LO" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fcewaDyyqstWANuoy+QJcDZ+jsVhQHqKmoJmgSjcwKLvV+/i+/6t3/dHwnYcl9AGrZtvbAcQVj4TOCzbtFwp3z8OeyXXhnUTilVbOhCTHjTy8A+laxjqInVPFixr2vXrZSzCyf0VLYmWScEEvQNKWRLHGaaWjJtdKdRZhqgsgYZv+M1+bj1CfpQoSxRcwm/Dvni4OdaZJRSsxiAfYgElF0ae7AME1pHF6em8h/8f6meILxJkRls9Kkuh3hRKRm4NDjKmDQEzWdb5OFMRaoucT4DIEt9C3PuadXBWOaKasrnAH1POBihgkl/LuvzKczL7Uhm5QHeTY2HyNuRmIzToPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=xCh5RDIG9kpjgUae5SMGYsTzUYlkSUM3g8Vxk01IuP0=; b=iMIXsIQ0yDsOiU9zb8OUsZjhnz2O99eCAK7H7ibHycDYnwSHl/Rx+RdzqakkOrp7hWhek1a0P5tm4JGC2j0ay6jUQVjNh+Z+O2gIp0/kbpmC8BSziKFC6jVItB7b9irk+C72/wcYMjlfLP59rJeqOm4VhV9I9T3hfj05686QqjJpZPDcLpIURn1Tbqjw/+gqz/ZUdMWmzWZqcElG8Kr3IbnDPANAgTH1mQ2lGhJ1njlMAE7hLkFGl9m9Xuc1n3RryK2NSkRdVrAbfKpfIG7ueB374JXG8llTC5bKfd4c5y5jDEa8i6jUonX1Udg7MoNxwUHiLweb0NQLZhJLRhjIPQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xCh5RDIG9kpjgUae5SMGYsTzUYlkSUM3g8Vxk01IuP0=; b=nNRu96LO1Y95T+qBXZ/1dVnxBXCIZBthjdD5ZbPFjFKt24ke/rZbRUWD4u7idhBCVKwss1oji/8C6AMy0gSSADOk7X1R9wazbcxN+vKiWFL1FaJDhsivnTrG8mjPTnV26Elyx9BXj3lZ21OXJ2IYffSuPdnxkEMYpW2bKUNwjd3j+/kNidlIUtpUrG1TmBBpTw+Gd9Mim7tcIJJSNjrRcejLrK6Q4jCOIRzapFZxyAaqOB5oz+FBPGBzi6Gy/3+rQtYKOkcS7MFTBPLxcrkVKbH68SWzOSmZjeoQYKB0LSgVQEt5ptyGjBHwXqc4zxwMvNboR3f1JjdmZjJzgmseAQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH2PR12MB3990.namprd12.prod.outlook.com (2603:10b6:610:28::18) by CYYPR12MB8654.namprd12.prod.outlook.com (2603:10b6:930:c9::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.159.19; Mon, 29 Jun 2026 14:09:57 +0000 Received: from CH2PR12MB3990.namprd12.prod.outlook.com ([fe80::7de1:4fe5:8ead:5989]) by CH2PR12MB3990.namprd12.prod.outlook.com ([fe80::7de1:4fe5:8ead:5989%4]) with mapi id 15.21.0159.018; Mon, 29 Jun 2026 14:09:57 +0000 From: Alexandre Courbot Date: Mon, 29 Jun 2026 23:09:35 +0900 Subject: [PATCH v4 03/13] gpu: nova-core: gsp: replace BootUnloadGuard with local handlers Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260629-nova-bootcontext-v4-3-5539d8469590@nvidia.com> References: <20260629-nova-bootcontext-v4-0-5539d8469590@nvidia.com> In-Reply-To: <20260629-nova-bootcontext-v4-0-5539d8469590@nvidia.com> To: Danilo Krummrich , Alice Ryhl , David Airlie , Simona Vetter , Gary Guo , John Hubbard , Alistair Popple , Timur Tabi , Eliot Courtney , Zhi Wang Cc: nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Alexandre Courbot X-Mailer: b4 0.15.2 X-ClientProxiedBy: OS7PR01CA0254.jpnprd01.prod.outlook.com (2603:1096:604:24b::20) To CH2PR12MB3990.namprd12.prod.outlook.com (2603:10b6:610:28::18) Precedence: bulk X-Mailing-List: nova-gpu@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PR12MB3990:EE_|CYYPR12MB8654:EE_ X-MS-Office365-Filtering-Correlation-Id: 0b3d5ce2-7c0f-4f49-c4dd-08ded5e819c3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|10070799003|1800799024|23010399003|6133799003|56012099006|11063799006|22082099003|18002099003|921020; X-Microsoft-Antispam-Message-Info: E/fczZCMRYhM5Ql+dlRgTdcnFCZrVrllqeVQvhH129BHLMbRPksbeFGewnLKYTeDpKGFIpN1XC/UY6e0Jq+oROAW3O/qoMmkJmtryjcG0B3pysHNBRub8hIM1dhFkx2DQNcAjFOVTuZwG2/pt2Mm5vyZC+2Ywb98jm0z70s2loTXi24PSryDaObHFgBAh/0gi1O9qLRxvYdL32SVumrQnJzeMkislZXr7JVBvHEJWR6YwzyaP/AgusnRQzWYQ+OpVk6wB+zujvSB8QGjow0wxQPQBb7c7bWo7kvICoRjKfotFeub7LKg2berSe7km3RGb38SDJ5DD3YJfSLNoPwAVgXS4qWl9dCp0zUHI/Wioydcw2LUm1IWDMF6+X09n92bEPtZdZ0Yfnc/cbyCCsynFZCjMmvHkSMl3E22nMCw92ZnkCS0KoItKX2yzJ2sbIQj5pE8ZwXCDhZJh6PhVZnJ4JAZARNBSRD4IrTbEsdFaWSRshoDoXhBXHBO1JAiZ/MD8Sxn3Y+svDDXG+6QiSuI/tQVcrQh7/4O/19RPalUdjXgtseXYwVW85Z6JwXhLUZ6LFoVhywl51s7JyYlTW7JO2Xyy2g2C3B3teLZ5ILVi7wgQ9CMqaPDnpMdC+hGoEElvV6shvLVbbzE/qrHRlZPnh/OqoavY1sO7HsYJltJhDpQtJdo8fGKOKFvkp5UXaRnJs+21cWe4DYC9n1ciclQHw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR12MB3990.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(10070799003)(1800799024)(23010399003)(6133799003)(56012099006)(11063799006)(22082099003)(18002099003)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?WjRJSnp4NE9YbFo2T0hFemxDZFg0VEpvcit0eWc2eFRKMXhjcE1OeDhpTzgr?= =?utf-8?B?TzV1SmtqYjM2WEhlb0QwRlQrNDBVNjJuSzRJS0VmdXBIMW93YkN1TkdKZUJh?= =?utf-8?B?d294VGc5WHZtVWVwcWhPVE85RUN3eWNSSnR0R3VaSXpIUzY4KytpcFlRS0dl?= =?utf-8?B?d0RPUlNNWWIwMVM0dndvdTFKczlrNTRrU2dwL2U5a1EvMVM3bnF5ckNjMEVa?= =?utf-8?B?RWt5V0Z5c0h1bUJhSnlLUVVneFY2UDhQbG9CRGNXWGNwUDE3LzdRS0t3K241?= =?utf-8?B?YTRDdGxXckN6VkRkL2dvMXNTMVFteGJEUW41bVFs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?d1Fob3psS1UyQ2hweDFQZ1Y1RUtleU9LUm1ZM0M4azRFeDA5cXlqVG11Yko2?= =?utf-8?B?YldzZ0dtOGJlS2h0UFU5eFdGTTFzQTdwVXBlVUdwMlg4WmJxMDBpTmZyK0hi?= =?utf-8?B?dStkcW00ZHY4V1VZRzNEaTlxZnRvVGdIcGpnRElLdkVheXBZMUFzS1RJVzNN?= =?utf-8?B?cW5KZW9ic1o5TmxMemc4UFN1VUZWTGlsRG90L1M4Tmp5Q05KNitqNUFzVEk1?= =?utf-8?Q?Ag1OyrSi3wHcnDycqGm2RkUoH/88/l5KO2LCWGzxZ+1Ba?= X-MS-Exchange-AntiSpam-MessageData-1: 9acspyjkgUtNcA== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0b3d5ce2-7c0f-4f49-c4dd-08ded5e819c3 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB3990.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2026 14:09:57.6811 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: kyx21oAs5ZY3LwF7HmQdblRuBni2sFFFize9nMDVbZzv45GHP0vj9JcoFuLutLgTXZitAh1syrTaqG7wbJ7RGg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8654 When adding the GSP unload capability, we introduced `BootUnloadGuard` to automatically call `Gsp::unload` whenever an error occurred during the boot process, in order to try to reset the GSP to a valid state. This approach is not well-suited to the errors that may occur in HALs: by definition, an error occurring in the HAL means that the GSP is not booted; yet the first thing that `Gsp::unload` does is queue a shutdown message to the GSP, which will inevitably result in a timeout when done from a HAL. Furthermore, `BootUnloadGuard` is problematic because it holds additional references to the boot context, notably the `Falcon`s. These extra references stand in the way of making some of the `Falcon`'s methods mutable, since those methods would require exclusive access. As this behavior is only needed in one place, introducing dedicated types for it is distracting and unnecessary. Thus, remove `BootUnloadGuard` and adopt a two-level error handling strategy: - HALs are free to handle their errors as they see fit (most likely, by running their unload bundle if it is ready by the time of the error), - `Gsp::boot` uses a `ScopeGuard` that runs `Gsp::unload`, since the GSP should be up and running by the time `GspHal::boot` has returned. Signed-off-by: Alexandre Courbot --- drivers/gpu/nova-core/gsp/boot.rs | 67 +++------------------------------- drivers/gpu/nova-core/gsp/hal.rs | 13 +++---- drivers/gpu/nova-core/gsp/hal/gh100.rs | 20 ++++------ drivers/gpu/nova-core/gsp/hal/tu102.rs | 23 +++++++----- 4 files changed, 33 insertions(+), 90 deletions(-) diff --git a/drivers/gpu/nova-core/gsp/boot.rs b/drivers/gpu/nova-core/gsp/boot.rs index ab0491b57944..536f2e341c01 100644 --- a/drivers/gpu/nova-core/gsp/boot.rs +++ b/drivers/gpu/nova-core/gsp/boot.rs @@ -30,66 +30,6 @@ }, }; -/// Arguments required to call [`Gsp::unload`](super::Gsp::unload). -/// -/// Stored as their own type to avoid repeating a long and tedious list in [`BootUnloadGuard`]. -pub(super) struct BootUnloadArgs<'a> { - gsp: &'a super::Gsp, - dev: &'a device::Device, - bar: Bar0<'a>, - gsp_falcon: &'a Falcon<'a, Gsp>, - sec2_falcon: &'a Falcon<'a, Sec2>, - unload_bundle: Option, -} - -/// Guard that calls [`Gsp::unload`](super::Gsp::unload) with a -/// [`UnloadBundle`](super::UnloadBundle) when dropped. -/// -/// Used to ensure the `UnloadBundle` is run during failure paths. -pub(super) struct BootUnloadGuard<'a> { - guard: ScopeGuard, fn(BootUnloadArgs<'a>)>, -} - -impl<'a> BootUnloadGuard<'a> { - /// Wraps `unload_bundle` into a guard that executes it when dropped. - pub(super) fn new( - gsp: &'a super::Gsp, - dev: &'a device::Device, - bar: Bar0<'a>, - gsp_falcon: &'a Falcon<'a, Gsp>, - sec2_falcon: &'a Falcon<'a, Sec2>, - unload_bundle: Option, - ) -> Self { - Self { - guard: ScopeGuard::new_with_data( - BootUnloadArgs { - gsp, - dev, - bar, - gsp_falcon, - sec2_falcon, - unload_bundle, - }, - |args| { - let _ = super::Gsp::unload( - args.gsp, - args.dev, - args.bar, - args.gsp_falcon, - args.sec2_falcon, - args.unload_bundle, - ); - }, - ), - } - } - - /// Disarms the guard and returns the [`UnloadBundle`](super::UnloadBundle) it contains. - pub(super) fn dismiss(self) -> Option { - self.guard.dismiss().unload_bundle - } -} - impl super::Gsp { /// Attempt to boot the GSP. /// @@ -107,6 +47,7 @@ pub(crate) fn boot( let bar = ctx.bar; let chipset = ctx.chipset; let gsp_falcon = ctx.gsp_falcon; + let sec2_falcon = ctx.sec2_falcon; let dev = pdev.as_ref(); let hal = super::hal::gsp_hal(chipset); @@ -118,7 +59,11 @@ pub(crate) fn boot( let wpr_meta = Coherent::init(dev, GFP_KERNEL, GspFwWprMeta::new(&gsp_fw, &fb_layout))?; // Perform the chipset-specific boot sequence, and retrieve the unload bundle. - let unload_guard = hal.boot(&self, &ctx, &fb_layout, &wpr_meta)?; + let unload_bundle = hal.boot(&self, &ctx, &fb_layout, &wpr_meta)?; + + let unload_guard = ScopeGuard::new_with_data(unload_bundle, |unload_bundle| { + let _ = self.unload(dev, bar, gsp_falcon, sec2_falcon, unload_bundle); + }); gsp_falcon.write_os_version(gsp_fw.bootloader.app_version); diff --git a/drivers/gpu/nova-core/gsp/hal.rs b/drivers/gpu/nova-core/gsp/hal.rs index d3e47ef206de..851d1f24c137 100644 --- a/drivers/gpu/nova-core/gsp/hal.rs +++ b/drivers/gpu/nova-core/gsp/hal.rs @@ -24,7 +24,6 @@ Chipset, // }, gsp::{ - boot::BootUnloadGuard, Gsp, GspBootContext, GspFwWprMeta, // @@ -51,15 +50,15 @@ fn run( pub(super) trait GspHal: Send { /// Performs the GSP boot process, loading and running the required firmwares as needed. /// - /// Upon success, returns a guard that runs the GSP unload sequence if GSP boot does not - /// complete. - fn boot<'a>( + /// Upon success, returns the [`crate::gsp::UnloadBundle`] to use with [`Gsp::unload`], if one + /// could be created. + fn boot( &self, - gsp: &'a Gsp, - ctx: &GspBootContext<'a>, + gsp: &Gsp, + ctx: &GspBootContext<'_>, fb_layout: &FbLayout, wpr_meta: &Coherent, - ) -> Result>; + ) -> Result>; /// Performs HAL-specific post-GSP boot tasks. /// diff --git a/drivers/gpu/nova-core/gsp/hal/gh100.rs b/drivers/gpu/nova-core/gsp/hal/gh100.rs index 1d06405a32f6..5fe445d73599 100644 --- a/drivers/gpu/nova-core/gsp/hal/gh100.rs +++ b/drivers/gpu/nova-core/gsp/hal/gh100.rs @@ -23,7 +23,6 @@ Fsp, // }, gsp::{ - boot::BootUnloadGuard, hal::{ GspHal, UnloadBundle, // @@ -143,27 +142,22 @@ impl GspHal for Gh100 { /// /// This path uses FSP to establish a chain of trust and boot GSP-FMC. FSP handles /// the GSP boot internally - no manual GSP reset/boot is needed. - fn boot<'a>( + fn boot( &self, - gsp: &'a Gsp, - ctx: &GspBootContext<'a>, + gsp: &Gsp, + ctx: &GspBootContext<'_>, fb_layout: &FbLayout, wpr_meta: &Coherent, - ) -> Result> { + ) -> Result> { let dev = ctx.dev(); let bar = ctx.bar; let chipset = ctx.chipset; let gsp_falcon = ctx.gsp_falcon; - let sec2_falcon = ctx.sec2_falcon; let unload_bundle = crate::gsp::UnloadBundle( KBox::new(FspUnloadBundle, GFP_KERNEL)? as KBox ); - // Wrap the unload bundle into a drop guard so it is automatically run upon failure. - let unload_guard = - BootUnloadGuard::new(gsp, dev, bar, gsp_falcon, sec2_falcon, Some(unload_bundle)); - let mut fsp = Fsp::wait_secure_boot(dev, bar, chipset)?; let args = FmcBootArgs::new( @@ -174,11 +168,13 @@ fn boot<'a>( false, )?; - fsp.boot_fmc(dev, fb_layout, &args)?; + // Keep the result as we want to wait for lockdown release even in case of error, to make + // sure `args` is not accessed by the GSP anymore. + let res = fsp.boot_fmc(dev, fb_layout, &args); wait_for_gsp_lockdown_release(dev, gsp_falcon, args.boot_params_dma_handle())?; - Ok(unload_guard) + res.map(|()| Some(unload_bundle)) } } diff --git a/drivers/gpu/nova-core/gsp/hal/tu102.rs b/drivers/gpu/nova-core/gsp/hal/tu102.rs index 87ceb8878f01..f78e2489f5a6 100644 --- a/drivers/gpu/nova-core/gsp/hal/tu102.rs +++ b/drivers/gpu/nova-core/gsp/hal/tu102.rs @@ -6,7 +6,8 @@ use kernel::{ device, dma::Coherent, - io::Io, // + io::Io, + types::ScopeGuard, // }; use crate::{ @@ -32,7 +33,6 @@ }, gpu::Chipset, gsp::{ - boot::BootUnloadGuard, hal::{ GspHal, UnloadBundle, // @@ -259,13 +259,13 @@ fn run_fwsec_frts( struct Tu102; impl GspHal for Tu102 { - fn boot<'a>( + fn boot( &self, - gsp: &'a Gsp, - ctx: &GspBootContext<'a>, + gsp: &Gsp, + ctx: &GspBootContext<'_>, fb_layout: &FbLayout, wpr_meta: &Coherent, - ) -> Result> { + ) -> Result> { let dev = ctx.dev(); let bar = ctx.bar; let chipset = ctx.chipset; @@ -290,9 +290,12 @@ fn boot<'a>( .ok() .map(crate::gsp::UnloadBundle); - // Wrap the unload bundle into a drop guard so it is automatically run upon failure. - let unload_guard = - BootUnloadGuard::new(gsp, dev, bar, gsp_falcon, sec2_falcon, unload_bundle); + // Run the unload bundle to try and recover the GSP if an error occurs. + let unload_guard = ScopeGuard::new_with_data(unload_bundle, |unload_bundle| { + if let Some(unload_bundle) = unload_bundle { + let _ = unload_bundle.0.run(dev, bar, gsp_falcon, sec2_falcon); + } + }); // FWSEC-FRTS is not executed on chips where the FRTS region size is 0 (e.g. GA100). if !fb_layout.frts.is_empty() { @@ -319,7 +322,7 @@ fn boot<'a>( )? .run(dev, sec2_falcon, wpr_meta)?; - Ok(unload_guard) + Ok(unload_guard.dismiss()) } fn post_boot(&self, gsp: &Gsp, ctx: &GspBootContext<'_>, gsp_fw: &GspFirmware) -> Result { -- 2.54.0