From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.52.39 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796213277; b=G3hK5lD2odb8FHYWByBTDcllAi7/LyyAcTtMzSiIE6FWuwgnY0LAehfp3Cru8oplOfBI yNYLkWembidjIyqaVTs6vVlbWSIvije76+g2W6LeTxssN88C1T5RQIL9pu0Utmz+6YZs0 mktehcsSkGpsr+eKjLWnLV2/hfl2o7w2wsfpMCxCdNuSW0+JoK0zljxjQpAmk+Kr0pLSg xggaScH1DD6bpWiAjHlEra5lpKFsDeFsTTFUSINEVDL/rbbavmhCIqZS+Ozl/mpSyg5rh QE4oLEeKrIwk5Ub0JOZ/ZpucmYovX9o7K9gcjRVKWWaKIlEL4+7WlUhUTuRA8DSjZsw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796213277; h=DMARC-Filter:DKIM-Signature:Received:Received:From:Date:Subject: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer:X-ClientProxiedBy:MIME-Version: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0: X-MS-Exchange-AntiSpam-MessageData-1:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=SRcT8i9FmX0IUZP1IPWPY+8BqB3i23jlM2ynaXSWXfI=; b=XDt1o/kteQBdUnMch1ITz+WUERbVE2gOE3lxcPppYtnNACStEY6NVWYLgbRJ1rKIOP8H t+QLWFyrAksJs1qrQmG9CF7V8MQiWJD5xu58G3IbPOd/lTskUyAlOvy9L6a6g5N/W6Cfn tmgdjqdQrQ0C6pXxG2JguN8PfIJtM9+pPmt01kkvfp/HOnJD9Rh2jUua7dRlpVerSxY+H w3t+AgnskLtIufPhlDEj1H2/bfPIkwmH2iUd6a8AZNd/l0u4Wp9Sj0NY4y1UrGpM5OTxc 023bKcXf1/liOVb6avvX2P6Dt55ejp8yOFqlA1CQb6JNPC+4RAzCJNjo7q4Hxo5qQww== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=jJ6M452M; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.52.39 Received: from BL2PR02CU003.outbound.protection.outlook.com (mail-eastusazon11011039.outbound.protection.outlook.com [52.101.52.39]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 26F3F606A322 for ; Wed, 2 Dec 2026 12:07:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 26F3F606A322 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, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=jJ6M452M ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=OvXSYLtSSClSwCCir8lcP0jaHTGXm3xU3cnHQ/g1cLbvrgnwnzjhA8CQ3PbBZbqSipUT1RC4JtvP7Gd48CgvtOv//Wh1/jS71ZCldmB8ktZMXqLKOnYXG+mY0HGh0B0IpJJxoC1SgE/yoNUZ6yfxIpcDlgAByRsP6eibWCIABZkZ2a0Bc+osilf1392hvOgPyRKQEDmeojud/WXxgbO0ksrWxrFDpJHgS2JD+IM9b9ZrVdXvuWromJabROiJ6ezdOucwmf3RraCT5YAJSXpMllljRPSqODuro08X6dvF8gqhiERC5zPBPC/C5GJ33d6Tw27KmNmrOVMX18FdCA8cOQ== 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=SRcT8i9FmX0IUZP1IPWPY+8BqB3i23jlM2ynaXSWXfI=; b=h/HxiP7KAUqIZqTMerG51mx55FD6WVrHbKfpyInfI8eJXeBfd3vRxJhA85s+CCvKvWWB+f9gF7xE4txMHae4zDXQK4v96/dMwNlSM0WqFdX1XhF+VGQzzFpEuig7uuEvkgA1vwljyZatr7BaVm7Vv7Fj+M50yy7uRZDjOS/aT9auXznIB6NIqKx7ZEFHDbOsZxrDiCJBvs+bQzIRcE9u1iuoJ4DxRMlf7GYDcLW+v0I86O7pn0O0pQIP0sfLGXlLr6fad+l0YtE7PtXxp4KVnv7L13UUo/ZPCEqW2G8GzUBN46cL5rsDW6VZeB56gArS8D8znqFak2mj7bkQWONvMw== 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=SRcT8i9FmX0IUZP1IPWPY+8BqB3i23jlM2ynaXSWXfI=; b=jJ6M452MBSJUrNf9XAu8IbtuSgzEANO6IjM5B0TG2s0MOZY4IdMxx5W+fMA2TqWT6SoYGQ8onWCIM3eBl9xyhRu7DLdz7C/CIfTOlunJqz3Lu5gSdrmKOwSJeWmvqyUS27El/V7EFiNhgr6GJ/Etz0snQRzhkLwQzix7G2dauOimVT1QK3Te9vDOp7xO+tic+vAOIz5xO9PDCTcYnc9NmlOKm8OZw963ZmbteoLBonBswp+ysqWwrT8A+XcUaSmFi06QKUtptJfKBUfS+UTDuAGcQVH6FJQpzL8UfLR/HnpIPhbHSnmJXc1sIg7nfvT2xOb0wN3+w6fM95hNON0TWw== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DS0PR12MB6413.namprd12.prod.outlook.com (2603:10b6:8:ce::10) by SAEPR12MB181460.namprd12.prod.outlook.com (2603:10b6:802:200::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Wed, 2 Dec 2026 12:07:51 +0000 Received: from DS0PR12MB6413.namprd12.prod.outlook.com ([fe80::e82a:6673:4142:37fa]) by DS0PR12MB6413.namprd12.prod.outlook.com ([fe80::e82a:6673:4142:37fa%5]) with mapi id 15.21.0688.009; Wed, 2 Dec 2026 12:07:51 +0000 From: Eliot Courtney Date: Wed, 02 Dec 2026 21:06:37 +0900 Subject: [PATCH v2 5/7] gpu: nova-core: gsp: add the r000 load-and-execute HS binary handler Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261202-falcon-v2-5-33ed73a20796@nvidia.com> References: <20261202-falcon-v2-0-33ed73a20796@nvidia.com> In-Reply-To: <20261202-falcon-v2-0-33ed73a20796@nvidia.com> To: Danilo Krummrich , Alice Ryhl , Alexandre Courbot , David Airlie , Simona Vetter Cc: John Hubbard , Alistair Popple , Timur Tabi , Zhi Wang , nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Eliot Courtney X-Mailer: b4 0.15.2 X-ClientProxiedBy: TYCP286CA0029.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:263::19) To DS0PR12MB6413.namprd12.prod.outlook.com (2603:10b6:8:ce::10) X-Mailing-List: nova-gpu@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB6413:EE_|SAEPR12MB181460:EE_ X-MS-Office365-Filtering-Correlation-Id: 8443ed40-7535-48be-fe24-08df506ce359 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|376014|366016|23010399003|1800799024|261102123227099003|10067099003|56012099006|11063799006|261021121427099003|261009223027099003|261022105027099003|261022075727099003|261022113327099003|261022115727099003|261026121527099003|261028144727099003|261021123027099003|261026140227099003|18002099003|22082099003|6133799003|3023799007; X-Microsoft-Antispam-Message-Info: qJmYjbcG7gCcJYWI8IMvdDCQ1vAUwN+lzi9xiitV9Iv+J1jJCjV6JvZlCzlIDfqR9wibtZIgNE9AVn3oUgcPt1m0hG71belLNdWOes/sEdaJl2YWZD2taWqPQsDC8SjBheSd1q9iN+IRE0r5O7+mk0J55haOK7jF8DCHgWRy1EqcoCXPIPUGUOf0sdVb7d1hYlWga+vBScUnG/xUvJruf97ssX1qYCWO1CH1f15kz41YazSFyu6tzxDIfm5EuHAoCV82FuCOx5ec/jfNM8MW/tsEAHZGiZudz8jeCQjVfQ/XhWfHmAth3wLSUtMZq2vm9S3z38uCZhQuxhOUm9MLoI3jsQzvKejKGZUhznsCayP6DFmZ6K7UuyxE/dxy5XkYCzzI4HXZgNJDtuA2+dL1inEFOpc+lqdjGSOjtqNs/34XwzUka5mWX4Kn9x5/gbFmQha13x6IHXvI3d+7uv7FVPIrgHYMicky2ZsT3lcgAzwhGpORpS4LpPwAMfXldMpD4AKKXPXs6TYwsleL4r2HoXMPXhTCes544lPlfgBBq9M8reyMzl1pZ8Ybuw7IaLV4EP07HESNaEwrAhUrh7tq4UUNY7F+JR7QKo4W3IyQ2qGoQJo8QrbXFPubirSExDB3lRyZL3OPRUwYd8h1BlDwUOcTmdThYkVkKEqq+QR1Erc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS0PR12MB6413.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(10070799003)(376014)(366016)(23010399003)(1800799024)(261102123227099003)(10067099003)(56012099006)(11063799006)(261021121427099003)(261009223027099003)(261022105027099003)(261022075727099003)(261022113327099003)(261022115727099003)(261026121527099003)(261028144727099003)(261021123027099003)(261026140227099003)(18002099003)(22082099003)(6133799003)(3023799007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?clR4eTQ2VFFuclY3bXhQMlRrbTlHSitocGZHd242dnkzNzRqTHpNbmlWcyto?= =?utf-8?B?VDlLeDFWeW1tS21iRlc5MG1xNzB4ek1YRGFmMWJKVDRydThRT2lPTnhYaElG?= =?utf-8?B?dmNwR0VoSE1WeXk5SmtaVWJHRFYvS21JSktoNlJIaGxiUEgxVlVSbjJVeHlp?= =?utf-8?B?K2hiYmZkbmgxek4ydjVqazc1THJoOGdQc201aisxMTgvYUQ1b1JEazhvM0d1?= =?utf-8?B?emNYNnJTOFFXSFpLSTg3bXRTeHJ5MTgwUGUrYlRFK3pIUWV4aEVPZnl4WjBv?= =?utf-8?B?bnpt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xCNUNhVHFHM3Uw?= =?utf-8?B?UFhWTHJxM3VPbkkxaSs0Tzh5Rm1wSnY0K05FK2IxOE9Xak52UmNqcnBBYXg5?= =?utf-8?B?SHRPeFFtMFRBVG95N3ZSaGpRWk91WE91Q3p2bXo0N0RPMU1tc0Z6N2dYMkx6?= =?utf-8?B?cHYyeWo5Y2FsSFFUMysxRkpqUFRTMGZVTDZ3bStoTWxDUlRtVzlhRHgyODBa?= =?utf-8?B?dy9NTjcxYjFXL3ZWOUVxVFVDOGM4MWZNRUdYcS9HK3VDWHZhQTdjYWU3cTdr?= =?utf-8?Q?hqqz4ooGXN3vsP7y3kgA5r8Y4GhF8MzyUIq3ULqjJ6Gaq?= X-MS-Exchange-AntiSpam-MessageData-1: LcQJs2ye8+6rjA== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8443ed40-7535-48be-fe24-08df506ce359 X-MS-Exchange-CrossTenant-AuthSource: DS0PR12MB6413.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2026 12:07:51.4928 (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: T3OURAwB6rP/BUr+tfseWZZuDhdZY0BVEivYu8518GK35oq2KEnCWOcePob9SxH3UMCEtn8RtQQmsSkKetN9XA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SAEPR12MB181460 From: John Hubbard The GSP falcon is a microcontroller with two cores, a falcon core and a RISC-V core, and only one of the two is active at a time. GSP-RM runs on the RISC-V core. On GA102 and later, the r000 GSP-RM requires a Heavy-Secured (HS) binary to run on the falcon core during boot. GSP-RM is suspended while the binary runs. The driver runs the binary on behalf of GSP-RM, in the following steps: 1. GSP-RM places the binary in the framebuffer. 2. GSP-RM raises a load-and-execute event. 3. GSP-RM suspends the RISC-V core. 4. The driver waits until the RISC-V core is suspended. 5. The driver resets the GSP falcon, which selects the falcon core. 6. The driver loads the binary from the framebuffer into the GSP falcon. 7. The driver starts the binary and waits for the falcon core to halt. 8. The driver resumes GSP-RM on the RISC-V core. Nova-core has no handler for the load-and-execute event. Add the handler, which performs steps 4 through 8. Co-developed-by: Alexandre Courbot Signed-off-by: Alexandre Courbot Signed-off-by: John Hubbard [ecourtney: boot HS binary with `Falcon::boot()`, keeping `dma_wr()` private] [ecourtney: zerocopy derives for `HsBinaryParams`, no `unsafe impl`] [ecourtney: move MAILBOX0 check and resume to `handle_load_exec_event()`] [ecourtney: module doc's FBIF sentence moved here from the bootloader patch] [ecourtney: move some methods to be impls of `GspBootContext`] Reviewed-by: Alexandre Courbot Signed-off-by: Eliot Courtney --- drivers/gpu/nova-core/falcon.rs | 1 - drivers/gpu/nova-core/gsp/load_exec.rs | 228 ++++++++++++++++++++++++++++++++- drivers/gpu/nova-core/sbuffer.rs | 1 - 3 files changed, 224 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/nova-core/falcon.rs b/drivers/gpu/nova-core/falcon.rs index bd0885be3ffe..760ff9c18055 100644 --- a/drivers/gpu/nova-core/falcon.rs +++ b/drivers/gpu/nova-core/falcon.rs @@ -211,7 +211,6 @@ pub(crate) enum FalconSegmentSource<'a> { /// Bytes in system memory. Sysmem(&'a [u8]), /// Bytes in the framebuffer. - #[expect(dead_code)] Framebuffer { /// DMA base address in the framebuffer. The falcon adds the segment's /// virtual address to it, so the actual segment may not start directly diff --git a/drivers/gpu/nova-core/gsp/load_exec.rs b/drivers/gpu/nova-core/gsp/load_exec.rs index 5148ea1c199f..6d832cb9ec24 100644 --- a/drivers/gpu/nova-core/gsp/load_exec.rs +++ b/drivers/gpu/nova-core/gsp/load_exec.rs @@ -1,19 +1,54 @@ // SPDX-License-Identifier: GPL-2.0 // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +//! The load-and-execute events of the GSP boot. +//! +//! See `Documentation/gpu/nova/core/falcon.rst`: +//! +//! - "Falcon security levels" describes the Heavy-Secured (HS) mode of a falcon and the boot ROM +//! that verifies an HS binary. The note in "Root of trust establishment" says why the GSP falcon +//! stops running GSP-RM, runs an HS binary, and then resumes GSP-RM. +//! - "Falcon memory subsystem and DMA engine" describes the instruction memory (IMEM) and the data +//! memory (DMEM) of a falcon, and the DMA engine that loads a binary into them. The DMA engine +//! accesses the framebuffer or system memory through the FBIF (Framebuffer Interface). + +use core::array; + use kernel::{ device, dma::DmaAddress, prelude::*, time::Delta, // }; +use zerocopy::FromZeros; -use crate::falcon::{ - gsp::Gsp, - sec2::Sec2, - Falcon, // +use crate::{ + falcon::{ + gsp::Gsp, + sec2::Sec2, + Falcon, + FalconBromParams, + FalconDmemSegment, + FalconFirmware, + FalconImage, + FalconImemSegment, + FalconSegmentSource, // + }, + gsp::{ + cmdq::gmc::MessageFromGsp, + GspBootContext, // + }, + sbuffer::SBufferIter, // }; +/// DMEM virtual address value that means "no virtual address assigned". +const FLCN_DMEM_VA_INVALID: u32 = 0xffff_ffff; + +/// `MAILBOX0` value that means that a falcon binary has not started. +/// +/// A binary that reports its status through `MAILBOX0` replaces it. +const FLCN_ERR_BINARY_NOT_STARTED: u32 = 0xfe; + /// Resumes GSP-RM on the GSP falcon by starting the SEC2 falcon. /// /// Resets the GSP falcon and writes `libos_dma_address` to its mailboxes before the start, and @@ -71,3 +106,188 @@ pub(super) fn resume_gsp_rm( } Ok(()) } + +impl GspBootContext<'_, '_> { + /// Waits until GSP-RM has suspended the RISC-V core, and then resets the GSP + /// falcon. + fn reset_gsp_falcon_after_suspend(&self) -> Result { + let dev = self.dev(); + let gsp_falcon = self.gsp_falcon; + + gsp_falcon.wait_for_processor_suspend().inspect_err(|_| { + dev_err!( + dev, + "Timeout waiting for GSP-RM (RISC-V core) to suspend (mbox0={:#x})\n", + gsp_falcon.read_mailbox0() + ); + })?; + + gsp_falcon.reset() + } + + /// Runs the Heavy-Secured (HS) binary of a `GMCAPI_CMD_EXEC_HS_BINARY` event + /// on the falcon core of the GSP falcon, and returns `MAILBOX0` once the + /// binary has halted. + /// + /// `params` describes the binary. The handler: + /// + /// 1. Waits until GSP-RM has suspended the RISC-V core, for up to five + /// seconds. + /// 2. Resets the GSP falcon, which selects the falcon core. + /// 3. Loads the code segment into IMEM and the data segment into DMEM, by + /// DMA from the framebuffer. + /// 4. Programs the boot ROM parameters and the boot vector, and writes + /// [`FLCN_ERR_BINARY_NOT_STARTED`] to `MAILBOX0`. + /// 5. Starts the falcon core, and waits until the falcon core halts, for up + /// to two seconds. The binary halts the falcon core when it is done, so + /// the handler learns from the halt that the binary has finished. + /// + /// # Errors + /// + /// - `EINVAL` if the engine ID mask or the ucode ID of `params` does not fit + /// its [`FalconBromParams`] field. + /// - `ETIMEDOUT` if GSP-RM has not suspended the RISC-V core within five + /// seconds, or if the falcon core has not halted within two seconds of + /// its start. + /// + /// Errors from the reset of the GSP falcon and the DMA transfers are + /// propagated as-is. + #[expect(dead_code)] + fn handle_hs_binary(&self, params: &HsBinaryParams) -> Result { + let dev = self.dev(); + let gsp_falcon = self.gsp_falcon; + let hs_binary = HsBinary::try_from(params)?; + + self.reset_gsp_falcon_after_suspend()?; + + gsp_falcon + .boot(&hs_binary, Some(FLCN_ERR_BINARY_NOT_STARTED), None) + .map(|(mbox0, _)| mbox0) + .inspect_err(|e| { + dev_err!( + dev, + "Failed to run the HS binary: {:?} (mbox0={:#x})\n", + e, + gsp_falcon.read_mailbox0() + ); + }) + } +} + +/// Payload of a `GMCAPI_CMD_EXEC_HS_BINARY` event, which describes the HS binary to run. +#[repr(C)] +#[derive(FromBytes, IntoBytes)] +struct HsBinaryParams { + /// DMA base of the code segment, a physical address in the framebuffer. + /// + /// The code segment starts at `imem_dma_base + imem_va`. + imem_dma_base: u64, + /// DMA base of the data segment, a physical address in the framebuffer. + /// + /// The data segment starts at `dmem_dma_base + dmem_va`, or at `dmem_dma_base` + /// when the data segment has no virtual address. + dmem_dma_base: u64, + _reserved64: [u64; 2], + /// Virtual address of the code segment. + /// + /// The binary starts executing at this address. + imem_va: u32, + /// Physical address in IMEM at which the code segment is loaded. + imem_pa: u32, + /// Size in bytes of the code segment. + imem_size: u32, + /// Virtual address of the data segment, or [`FLCN_DMEM_VA_INVALID`] if the data + /// segment has no virtual address. + /// + /// The DMA transfer writes no tags in that case. + dmem_va: u32, + /// Physical address in DMEM at which the data segment is loaded. + dmem_pa: u32, + /// Size in bytes of the data segment. + dmem_size: u32, + /// Physical address in DMEM of the signature of the binary. + hs_sig_dmem_addr: u32, + /// Mask of the falcon engines on which the binary can run, with one bit per engine. + engine_id_mask: u32, + /// ID number of the binary. + /// + /// Each ID has a fuse register that holds a version number. The boot ROM uses + /// the ID and that version number as inputs of the signature verification. + ucode_id: u32, + _reserved32: [u32; 3], +} + +impl MessageFromGsp for HsBinaryParams { + type InitError = Error; + + fn read(payload: &mut SBufferIter>) -> Result { + let mut params = Self::new_zeroed(); + + payload.read_exact(params.as_mut_bytes())?; + + Ok(params) + } +} + +/// HS binary of a `GMCAPI_CMD_EXEC_HS_BINARY` event, as a [`FalconFirmware`] +/// loaded from the framebuffer. +struct HsBinary { + /// Code segment, loaded into IMEM as secure code. + imem: FalconImemSegment<'static>, + /// Data segment, loaded into DMEM. + dmem: FalconDmemSegment<'static>, + /// Parameters that the boot ROM uses to check the signature of the binary. + brom_params: FalconBromParams, +} + +impl TryFrom<&HsBinaryParams> for HsBinary { + type Error = Error; + + fn try_from(params: &HsBinaryParams) -> Result { + Ok(Self { + imem: FalconImemSegment { + source: FalconSegmentSource::Framebuffer { + base: params.imem_dma_base, + len: params.imem_size, + }, + dst_start: params.imem_pa, + va: params.imem_va, + }, + dmem: FalconDmemSegment { + source: FalconSegmentSource::Framebuffer { + base: params.dmem_dma_base, + len: params.dmem_size, + }, + dst_start: params.dmem_pa, + // A data segment with a virtual address is tagged with it. One without starts at + // the DMA base. + va: (params.dmem_va != FLCN_DMEM_VA_INVALID).then_some(params.dmem_va), + }, + brom_params: FalconBromParams { + pkc_data_offset: params.hs_sig_dmem_addr, + engine_id_mask: u16::try_from(params.engine_id_mask)?, + ucode_id: u8::try_from(params.ucode_id)?, + }, + }) + } +} + +impl FalconFirmware for HsBinary { + type Target = Gsp; + + fn image(&self) -> Result> { + Ok(FalconImage { + imem_ns: None, + imem_sec: Some(self.imem.clone()), + dmem: self.dmem.clone(), + }) + } + + fn brom_params(&self) -> FalconBromParams { + self.brom_params.clone() + } + + fn boot_addr(&self) -> u32 { + self.imem.va + } +} diff --git a/drivers/gpu/nova-core/sbuffer.rs b/drivers/gpu/nova-core/sbuffer.rs index 3a41d224c77a..b8c01104c255 100644 --- a/drivers/gpu/nova-core/sbuffer.rs +++ b/drivers/gpu/nova-core/sbuffer.rs @@ -146,7 +146,6 @@ fn get_slice(&mut self, len: usize) -> Option<&'a [u8]> { /// Ideally we would implement `Read`, but it is not available in `core`. /// So mimic `std::io::Read::read_exact`. - #[expect(unused)] pub(crate) fn read_exact(&mut self, mut dst: &mut [u8]) -> Result { while !dst.is_empty() { match self.get_slice(dst.len()) { -- 2.56.1