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.193.25 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796030985; b=smXxCtUhcRTGGZzgDKGVXCXfS4CYMFebkGiq/FC3FRifrArSABtJ9F/5d/zIUDo8v/bd N4LlVB+QcXUXp/P5oUFWqEP5BCluNRPiS9Znc3SoMsmvf9N/qgwWjYBqxG2aCbpeGetE0 ZovNxkwkgg3noyYbFTLhR3/ZXi87cNarX93WUediTC81F294Xy5lHWV7wJUS6zesI1Scf soJn5GR8uPkf/4tmNc6UyAtpJ2OV0+aEBgGtQy/F6T2usbY4Lrepd0ZL77Gm7O+MAGFB9 0kakFwvRm/0rWKTx4sMUXCfwyx+CH3oeuJbRkSNSdwbT60Mwgzdkw4I3ExWRjAB33mA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796030985; 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=wZEJD4HVN6zc4fw/NKKVkxeRZf1MzxPFeDaey/E8030=; b=x8LIOV66kRa7jjNEOVwOjsVbROgjlqRztJTYXNP9L+CCih/XF0GyMziUUQ2OHCN1knvx 5iwZX8rpPOJXAgrktg3F2Sa2RD2au5kY4rEXRzJDpzbVa+p9twkv/X5D+8bMRpDWAqLf/ v9A/AItnipepA6I40GsJv/AAwZknrYY8A29NSS5mCKkniS++l6FSAwNr1Z66DiaB53iNi +CVFlJmHQXRzuyCRhbtuO05lU6L0nHFU0rw1sYwrutaYpN9e8xG1gZEd26oYJn+E5OzC7 FMvv3kk+30NvSPUAR9W96Gq3+CSpims4IBWOeqzgZoCdiuCCBahMy8mUMwusvv/bjZw== 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=saTpTv9T; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.193.25 Received: from CH1PR05CU001.outbound.protection.outlook.com (mail-northcentralusazon11010025.outbound.protection.outlook.com [52.101.193.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 358AB606A339 for ; Mon, 30 Nov 2026 09:29:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 358AB606A339 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=saTpTv9T ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RzmUfUgWzlCumoEoFeZ2tJkMtf2rVT9qBplTFHrHx4w/fqBCRcp96qTDpU1Lw9S9BGbcpU6q42+pEnNc0rkMCMz7usIohad6MY9MrdZYLZPtpK4lSf1bn1HwkCGKsazYvAj6ZQ106E6Nny8KVUwVmpqFoK5C+q7aYjaY/g1bi4tpi5u2PF2MSBsok5/aEzSdUaFqOy0w2KFJkz0+n1QYixA+DDW3RnHxR9G/+MW8/4JK2+1tT6Z7NDqWp6ipeqZILc+aHm9jqxWPgaQjbQ+Dud8Fix9C/rE7oexhu3VGB5yufJVyn7Pyux/INc/YPWtavGCBHRQmeunWeZLbu1dn9Q== 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=wZEJD4HVN6zc4fw/NKKVkxeRZf1MzxPFeDaey/E8030=; b=UcCJBSnlW2kprhgJdwZethBwumGoxSREeWNqMimZBKWwrL+e9J9BKY8MDBlXkr501qGO0cOgYicJmmW/hQEtiOse2uAkpXcntVuzKuiOwV8inGfLTFQlEP2uZ6+fFSDUTVZCTBJmwUocgGXapx6/JgkdjM1TZAaXyczme12pENOGabK9qr9pSFZMUnolsitV5J29j86zIAE9aT2lxzj+14fKPwHaPxY+U0tWZjkCMM5T3VqEPcnFufyKjeyKZDm+EbyQuNuLtiiW8KA4T3W2pmYflxfr8DbNbF3BCcVwfACR9xzOtJ1mTAkAXmDA3znUrdr7R0mBE/xq7JztWNXKXQ== 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=wZEJD4HVN6zc4fw/NKKVkxeRZf1MzxPFeDaey/E8030=; b=saTpTv9TXPEZma3cX2kHdslmgw3MlowzsM1pU04ax2I4+kpRu1v2Gs5CVMZsHmPrqjTtgCzHdUN9ZLLKucLYOCDAVMyIH93HDkaYSy6g+H3SbL0RqVb2pGmb8qk8Ij2F3yaLjBtxfotrgdbeUGFe9GVKWvCLASVekLyrLpfsWkvlwnAzT0go5ajkkaPjczKMhVvxk74bxNFUm1yuMvnnl/5KQXs580vfuYMQHCxce7V+7KI7IJt47zGPSwdJjRClkoySDAK3QDG0yDrVFb0T1ANnhBKf9Rj6+0HQk1IufSaefVvROpAluL9Dq7fFV9H16Bu/6VNBSxB+POwdLmlJKA== 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 PH0PR12MB999113.namprd12.prod.outlook.com (2603:10b6:510:38f::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.12; Mon, 30 Nov 2026 09:29:26 +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.0662.007; Mon, 30 Nov 2026 09:29:26 +0000 From: Eliot Courtney Date: Mon, 30 Nov 2026 18:28:36 +0900 Subject: [PATCH 12/14] 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: <20261130-falcon-v1-12-cb94f87b5674@nvidia.com> References: <20261130-falcon-v1-0-cb94f87b5674@nvidia.com> In-Reply-To: <20261130-falcon-v1-0-cb94f87b5674@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: TYCP286CA0189.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:382::15) To DS0PR12MB6413.namprd12.prod.outlook.com (2603:10b6:8:ce::10) X-Mailing-List: linux-kernel@vger.kernel.org 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_|PH0PR12MB999113:EE_ X-MS-Office365-Filtering-Correlation-Id: 6768d339-01f8-4d02-5d2b-08df4ec46ceb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|23010399003|1800799024|10070799003|376014|10067099003|56012099006|261028144727099003|261026140227099003|261026121527099003|261022115727099003|261021123027099003|261021121427099003|261102123227099003|261022113327099003|261022105027099003|261022075727099003|261009223027099003|18002099003|22082099003|11063799006|6133799003|3023799007; X-Microsoft-Antispam-Message-Info: kHdPWmakzvR4REvEEeHS/+VlYkdXCfKE74JXqTIVyC3suAwK8SBQNjkcSd9VjLZWg8c/ntzrnfJofgPDXZu41PWDgz2+uC+L0gBw4eBgD6er4qYdIT8hVhZ1oJttYZnaPmC/iN0PhIX6zBgPXNyTSSESxwuZwwfTI4Mq4xvSjAZJR17JDMZNnGnBIkcBLnuzEzcO7GQzdfCyH+tPtyGurwiaI85WPzikD2JKnXvDzvtgS95lvAwIIeHpQgOEIA8m4GUbtSK3uc4N8Mwvl67Nqi6tubkjQONItgH3RIf8WDl+mX4HhqrIktt1VbulaIWqyzlDP5FcqBb+Y4KhCQU3tgFsmpN5pHVWgtnGfvKu/iNuupBjMLueLz/85dngLxpULIW4atCTj1IAGiOza0Mi9kyXwHmp4QLrIsVos2i1CJxfWcxDTGK5HqUsOpxmzzEFSfkloabSwXjaJQR2Izz+2kKZj3pgMO+rC84hy3EhODOSlMsPr3rw0ECBNeahcD+DBYdD81KiCXt6POF+Odwt3kUjQA01+71OlBmEsbwrAac9zJmivz+2mBFkPq858+niBCNPsCIGezIAAyhzqW29pjJWNuFHKV7aC0OLK8WYBeIUo3J5lZCcI14l7NN1s5/jwzGJwWu17x7ft7OpDOrel36PTbXbswa0icxnTF1lYkk= 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)(366016)(23010399003)(1800799024)(10070799003)(376014)(10067099003)(56012099006)(261028144727099003)(261026140227099003)(261026121527099003)(261022115727099003)(261021123027099003)(261021121427099003)(261102123227099003)(261022113327099003)(261022105027099003)(261022075727099003)(261009223027099003)(18002099003)(22082099003)(11063799006)(6133799003)(3023799007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?UUxOVmc3TTUvTVRTbHpZbE5iVmZCbGtvcUdmSjM0QzFBbno0SFBqaVVmL3dy?= =?utf-8?B?NDZwNnFQeDE4NjloMUFVcFRMYkRIYVFWSjRXdGhUNzJiK0JJelJ4QzVneGZu?= =?utf-8?B?S0c3UTczNmkvOTNyQzk5eUM5OU5FY0FkeWtYYUx3cnh2MFJTTnpjZHZMc3lC?= =?utf-8?B?QXgvRFdSRmEvdk9CdTgxZisxTHBnRjZwWEVDaHMxSktpYk1YcnZWSmlRZUdZ?= =?utf-8?B?L3dNU2V1UlR1cDVRYVozNmUyTHplRy95OGk3UWlOUm9oQU9ZTzB0NDV5OWZP?= =?utf-8?B?K1N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lVaXZ5L2lzSkJqKzVycUg2RmdNMk1N?= =?utf-8?B?aXpEOHRQZ2tTTUJLakpETGVYUzJkenRCaVNRTi9RSHlMVEtzOCsxbGpla2t0?= =?utf-8?B?MDJIL1RHUlYyQU5HUW9Helh1Z0t4NDNCSmJMZU8yVncyNklNbTVNRCtxcDlu?= =?utf-8?B?Q2QxUXhOMXl6TWZnU2NqNEpkVjhVVXlQTXNycTNwdm02S0wySVZZanF1MmRQ?= =?utf-8?B?RmZPQWVJaUhMdmZTeklrbzM3TnFGVDFOR1hEaGFhZGwyRDY3YXp2NlFDR3dL?= =?utf-8?Q?qB8xgnJmDFE5540GrIKDN1JabiNJMdCbJWyZUYjdIj+2y?= X-MS-Exchange-AntiSpam-MessageData-1: APrZM1CS/5U1Jw== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6768d339-01f8-4d02-5d2b-08df4ec46ceb X-MS-Exchange-CrossTenant-AuthSource: DS0PR12MB6413.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2026 09:29:26.0879 (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: y0bETMvuHF8IZv8O8tCApj0P20ADzDu6Rg6YcbAHtDX79VQG+0gkGBlScIfIuKI6MjRKIeH57vbcdLmosxOGXw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB999113 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`] 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, 223 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/nova-core/falcon.rs b/drivers/gpu/nova-core/falcon.rs index fe6a84509d09..0c10e225f1b0 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 ac5eb8b7edd7..6d832cb9ec24 100644 --- a/drivers/gpu/nova-core/gsp/load_exec.rs +++ b/drivers/gpu/nova-core/gsp/load_exec.rs @@ -1,7 +1,18 @@ // SPDX-License-Identifier: GPL-2.0 // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -//! The core resume of the GSP falcon. +//! 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, @@ -9,13 +20,35 @@ 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 @@ -73,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