From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from SA9PR02CU001.outbound.protection.outlook.com (mail-southcentralusazon11013017.outbound.protection.outlook.com [40.93.196.17]) (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 C97AD346E7A for ; Wed, 10 Jun 2026 17:50:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.196.17 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781113821; cv=fail; b=F7OIkSAo+jSooS21yEMAGlgFvAhsadhzLGTPgGXrtCQZsrCtu0/1C7Su2V0TUd6QALfZ4uUa5iwsRz+H3FwBs2wB5U6hghCnsgOAKYSiQMUJC8CsHv586/xzq5sNwZfzj+qaEk4xbcGCINy34WhJ1Porc7Ln0aHjCXEQ9hqjt7Q= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781113821; c=relaxed/simple; bh=f7af/iafNa+vjrHMiLrgDXf4ZegsowLLvVYCqXu/U6k=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cbrMFYHyFShL0Ty6nkOwAFH0rb8Tk6GQW0MdBNIuix1g5/de5+kREwe9TSwC1GfGSxfUqI7g8lCLLKgzZSJOldu1lDUs3YP9x8D0k2uzL5A2HIyDUH6EXteOGR7yP2EYLbre8pmG/4mbSoAsFaMzGI54qHH5im1GAbX6dPoHkF0= 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=bVA9L6zL; arc=fail smtp.client-ip=40.93.196.17 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="bVA9L6zL" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Ibndac9ywWKrLtmuFU1trY7f8apTOer5Rz5LLR7ASMflq3lk8HxtrNxaYb1fRW0pAlzXl1gvK3EiM/xlUpXPPFf9shttoBMmisX5oW+lozwGAZo+9IcG/YnnLXqe321ReOb/tlSAkRPUiupihlU6Yrb9/6eopqdzCoDMds6SuGjUzytkH3INpIchpe7y2WnG8ZrcQofTwwU84+2BLFmLX0lZp8hViW1EBvGNvDKKYSN3SEx/gXoQPuWteM66yCw83p6ZMezgL73geFeX0q5PTSdQvjfzzQCnNdlGgLl6FAppxI3qnLKJStUQF/jS9FXOG0rEzfcgHLQsbEIN6iRvSQ== 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=YEXD9Y5fO0sVPJmRRT8YLL3hyRUBSBZ87SFUomBouTk=; b=fN8/6WOp+yRNfYWmQ6ShB+IFMD3SuWsAjmvHEZYDAIOLOHF3Fl0MwhVPCxTlSIfDn7M7hmzdK3bAWRm/5S71OcN5t206MKpYhWCcbATcOIAYVVDRCAc+S5LuiZExM4j2qLt96VLFovCTcgE4KZwfvyaCIPUuG5NYwyQ4gRNCvUxhpdW8Ajk7EiiJ90D3rVBQfEMe0FE1xPRYwjOKKLo9HAjw4ELPoXCFeUGsyc+M48LurMGTiiPyuMAadV4fEQTl0vljzBUeuz+c/Hzc1fTJsn6pym3rpUbdDcnI7wBl/IwUmb/NNu/WduvvLoDUl9UrGlAJQwM5PX1YpJG0sZ3JkQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) 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=YEXD9Y5fO0sVPJmRRT8YLL3hyRUBSBZ87SFUomBouTk=; b=bVA9L6zLlgyTxo34gSHadbDXsEmV13Xrj4YM+DQysikOnsP0cdl2VP2FONQ1WnwFpDcnE6HBku+qPN7v72uDxjd6bWN7zI1HiEWFWNnbjitaY8c9dP2R+eocx9gVWomua+GTGMLBqRVGtMoyMGEg9i2WzryhCpINxpIHQRUH9QCG1t75O2R4XFAOsU+LYSR5mqbnh9YuioX3doRc/yhl7BYKh3k1hbp8jtPTiLXgw99x/5uU2bw84cbeSpW3Tq1NC/2bpSDxzpjR7zEYIYcVvS/lKEgKh1nX27H3x7lTIkaTzWhnL3O9o0kgztWcQ953Mv5aAvmvZmMKrpLp95Fwkw== Received: from BLAPR05CA0020.namprd05.prod.outlook.com (2603:10b6:208:36e::23) by SJ2PR12MB8650.namprd12.prod.outlook.com (2603:10b6:a03:544::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.113.11; Wed, 10 Jun 2026 17:50:11 +0000 Received: from BL02EPF00021F6D.namprd02.prod.outlook.com (2603:10b6:208:36e:cafe::5e) by BLAPR05CA0020.outlook.office365.com (2603:10b6:208:36e::23) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.113.12 via Frontend Transport; Wed, 10 Jun 2026 17:50:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BL02EPF00021F6D.mail.protection.outlook.com (10.167.249.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.113.7 via Frontend Transport; Wed, 10 Jun 2026 17:50:08 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 10 Jun 2026 10:49:44 -0700 Received: from ttabi.nvidia.com (10.126.230.37) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 10 Jun 2026 10:49:43 -0700 From: Timur Tabi To: Danilo Krummrich , Gary Guo , "Alexandre Courbot" , , Eliot Courtney , John Hubbard , Subject: [PATCH 4/8] gpu: nova-core: transition booter_load to TLV images Date: Wed, 10 Jun 2026 12:49:25 -0500 Message-ID: <20260610174929.744477-5-ttabi@nvidia.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260610174929.744477-1-ttabi@nvidia.com> References: <20260610174929.744477-1-ttabi@nvidia.com> Precedence: bulk X-Mailing-List: nova-gpu@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NVConfidentiality: public Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF00021F6D:EE_|SJ2PR12MB8650:EE_ X-MS-Office365-Filtering-Correlation-Id: bc05c33d-3859-4f59-97ed-08dec718b62e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700016|1800799024|376014|23010399003|6133799003|3023799007|18002099003|22082099003|56012099006|11063799006; X-Microsoft-Antispam-Message-Info: O/NNrNU8KTmpCSCNg2snCP87RKOg4SKG+76CTvU1gFDRQdaEs3G9WQXiY9IKDTFEesMNRvNVqck2gGnNc8IRbzsPlnHuI6NskSl6Y2rhNsnoG5QD/3ZC8H6jNM56p5QPC+VtBdFmMl0QSRVHRtUVKZQyyqT7WRGxeazdxz2HHFgsljhGvgFAl/w4rH9t6d1QwbIVX3yY9foo4G0CNIk9V54PlkbidcmjUHp1PH7KO1XpE9L4sq1HUvBfrwdymCjy+hR+PjmlQMak3cYK+QYtzgrNXiZgmRqkSv05B6SP3vqsB4c0PLz4Bh98jGXtxxNLKCv5ifVItoybVjCKVflzohn7UZfyB51zW3VaXAhbhJMfvrUu+K1UJjD1MeQ6ZyGEs9p/kLZ1z0KpCp2GkPL/ITWIOPYzOTuoH9El77pa0I+qQO+Q8cucERTv7LiRWnqXf20A+BeNUTErft8Wkdx0+SIS5O7UGOHODDJI4/m9tROt7lTpYhwerAGV9lirwc/tlk64YxFDDog2XD7cpfqTRJRlRRsLratcnPpwUn6P8Q2UAEL4j6pmBs2OTnLPFrbwx1xRhR7MCcVM5faUPkQjnMxnpxlnBzPpL0Svw4wxFyETLJDkAFHHS2SK5KlDlmRvAbtDHysnnfTP3pls+TfBWnqmONQ5fnKMKNdwQ6J4fG3xrgH4ViEMtTjRCtn/Q5DNFCUxz81hHMSg5Bx/XFIZMUY105VK1KHERVmUVFvQtZU= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(36860700016)(1800799024)(376014)(23010399003)(6133799003)(3023799007)(18002099003)(22082099003)(56012099006)(11063799006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: heLOBRqeZDCmgEEy1XKhDNOkMfaDKkQ1g5aXWLZNvC1bjpaBQaEAcZE2ygm8LcHvDzS0pciDZe7EJXlihFPAgrJ9wT3v54Q8rbJCqv9hdrYh9ZmYpjMzf81bnGug3fqE3VL41XFKG/C1V+iTvVTOfva1md9QbehRCTqlynRUVoEh/NiIKURkwncWojMMO+0fAzT/yFjhP509zGZXN/hgAtbP6hDXBXuFEWtY48k7btSAq014es+hwySpYqZN1KyXJQbHXBwlV21IFlPNx4WIWleeW0CONuTXq2hAF9N+eVmEKbMItTTR1OMo9gbLjbVY8vMrS/hxLOX5iYw3RkmGQPSVlKxc9NzGhVewRa9F9O6F4ElzErEWhIEu7JQoqtOLBBAYWwmiuCHPVODoEwjFJGNOP/QsU8YdZDct5wDg5pQSsrQl/+gzBp1Qnfts02g2 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2026 17:50:08.0823 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bc05c33d-3859-4f59-97ed-08dec718b62e X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF00021F6D.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8650 Switch the booter firmware loader from the legacy binary format to the TLV format. This change requires the new TLV versions of the r570.144 firmware images. The new TLV format has all of the metadata needed by Nova encoded as separate tags, eliminating the need to parse legacy firmware headers such as HsHeaderV2 and HsSignatureParams. All of the structs and code for parsing those headers is therefore deleted. Signed-off-by: Timur Tabi --- drivers/gpu/nova-core/firmware.rs | 15 +- drivers/gpu/nova-core/firmware/booter.rs | 328 ++++------------------- drivers/gpu/nova-core/gsp/hal/tu102.rs | 15 +- 3 files changed, 63 insertions(+), 295 deletions(-) diff --git a/drivers/gpu/nova-core/firmware.rs b/drivers/gpu/nova-core/firmware.rs index 888a426b7b41..f632db8283f0 100644 --- a/drivers/gpu/nova-core/firmware.rs +++ b/drivers/gpu/nova-core/firmware.rs @@ -21,10 +21,7 @@ FalconFirmware, // }, gpu, - num::{ - FromSafeCast, - IntoSafeCast, // - }, + num::IntoSafeCast, }; pub(crate) mod booter; @@ -411,16 +408,6 @@ fn new(fw: &'a firmware::Firmware) -> Result { .map(|hdr| Self { hdr, fw }) .ok_or(EINVAL) } - - /// Returns the data payload of the firmware, or `None` if the data range is out of bounds of - /// the firmware image. - fn data(&self) -> Option<&[u8]> { - let fw_start = usize::from_safe_cast(self.hdr.data_offset); - let fw_size = usize::from_safe_cast(self.hdr.data_size); - let fw_end = fw_start.checked_add(fw_size)?; - - self.fw.get(fw_start..fw_end) - } } pub(crate) struct ModInfoBuilder(firmware::ModInfoBuilder); diff --git a/drivers/gpu/nova-core/firmware/booter.rs b/drivers/gpu/nova-core/firmware/booter.rs index d9313ac361af..c748aa94cd0e 100644 --- a/drivers/gpu/nova-core/firmware/booter.rs +++ b/drivers/gpu/nova-core/firmware/booter.rs @@ -10,8 +10,7 @@ use kernel::{ device, dma::Coherent, - prelude::*, - transmute::FromBytes, // + prelude::*, // }; use crate::{ @@ -25,224 +24,16 @@ FalconFirmware, // }, firmware::{ - BinFirmware, FirmwareObject, FirmwareSignature, Signed, + Tlv, Unsigned, // }, gpu::Chipset, - num::{ - FromSafeCast, - IntoSafeCast, // - }, + num::IntoSafeCast, }; -/// Local convenience function to return a copy of `S` by reinterpreting the bytes starting at -/// `offset` in `slice`. -fn frombytes_at(slice: &[u8], offset: usize) -> Result { - let end = offset.checked_add(size_of::()).ok_or(EINVAL)?; - slice - .get(offset..end) - .and_then(S::from_bytes_copy) - .ok_or(EINVAL) -} - -/// Heavy-Secured firmware header. -/// -/// Such firmwares have an application-specific payload that needs to be patched with a given -/// signature. -#[repr(C)] -#[derive(Debug, Clone)] -struct HsHeaderV2 { - /// Offset to the start of the signatures. - sig_prod_offset: u32, - /// Size in bytes of the signatures. - sig_prod_size: u32, - /// Offset to a `u32` containing the location at which to patch the signature in the microcode - /// image. - patch_loc_offset: u32, - /// Offset to a `u32` containing the index of the signature to patch. - patch_sig_offset: u32, - /// Start offset to the signature metadata. - meta_data_offset: u32, - /// Size in bytes of the signature metadata. - meta_data_size: u32, - /// Offset to a `u32` containing the number of signatures in the signatures section. - num_sig_offset: u32, - /// Offset of the application-specific header. - header_offset: u32, - /// Size in bytes of the application-specific header. - header_size: u32, -} - -// SAFETY: all bit patterns are valid for this type, and it doesn't use interior mutability. -unsafe impl FromBytes for HsHeaderV2 {} - -/// Heavy-Secured Firmware image container. -/// -/// This provides convenient access to the fields of [`HsHeaderV2`] that are actually indices to -/// read from in the firmware data. -struct HsFirmwareV2<'a> { - hdr: HsHeaderV2, - fw: &'a [u8], -} - -impl<'a> HsFirmwareV2<'a> { - /// Interprets the header of `bin_fw` as a [`HsHeaderV2`] and returns an instance of - /// `HsFirmwareV2` for further parsing. - /// - /// Fails if the header pointed at by `bin_fw` is not within the bounds of the firmware image. - fn new(bin_fw: &BinFirmware<'a>) -> Result { - frombytes_at::(bin_fw.fw, bin_fw.hdr.header_offset.into_safe_cast()) - .map(|hdr| Self { hdr, fw: bin_fw.fw }) - } - - /// Returns the location at which the signatures should be patched in the microcode image. - /// - /// Fails if the offset of the patch location is outside the bounds of the firmware - /// image. - fn patch_location(&self) -> Result { - frombytes_at::(self.fw, self.hdr.patch_loc_offset.into_safe_cast()) - } - - /// Returns an iterator to the signatures of the firmware. The iterator can be empty if the - /// firmware is unsigned. - /// - /// Fails if the pointed signatures are outside the bounds of the firmware image. - fn signatures_iter(&'a self) -> Result>> { - let num_sig = frombytes_at::(self.fw, self.hdr.num_sig_offset.into_safe_cast())?; - let iter = match self.hdr.sig_prod_size.checked_div(num_sig) { - // If there are no signatures, return an iterator that will yield zero elements. - None => (&[] as &[u8]).chunks_exact(1), - Some(sig_size) => { - let patch_sig = - frombytes_at::(self.fw, self.hdr.patch_sig_offset.into_safe_cast())?; - - let signatures_start = self - .hdr - .sig_prod_offset - .checked_add(patch_sig) - .map(usize::from_safe_cast) - .ok_or(EINVAL)?; - - let signatures_end = signatures_start - .checked_add(usize::from_safe_cast(self.hdr.sig_prod_size)) - .ok_or(EINVAL)?; - - self.fw - // Get signatures range. - .get(signatures_start..signatures_end) - .ok_or(EINVAL)? - .chunks_exact(sig_size.into_safe_cast()) - } - }; - - // Map the byte slices into signatures. - Ok(iter.map(BooterSignature)) - } -} - -/// Signature parameters, as defined in the firmware. -#[repr(C)] -struct HsSignatureParams { - /// Fuse version to use. - fuse_ver: u32, - /// Mask of engine IDs this firmware applies to. - engine_id_mask: u32, - /// ID of the microcode. - ucode_id: u32, -} - -// SAFETY: all bit patterns are valid for this type, and it doesn't use interior mutability. -unsafe impl FromBytes for HsSignatureParams {} - -impl HsSignatureParams { - /// Returns the signature parameters contained in `hs_fw`. - /// - /// Fails if the meta data parameter of `hs_fw` is outside the bounds of the firmware image, or - /// if its size doesn't match that of [`HsSignatureParams`]. - fn new(hs_fw: &HsFirmwareV2<'_>) -> Result { - let start = usize::from_safe_cast(hs_fw.hdr.meta_data_offset); - let end = start - .checked_add(hs_fw.hdr.meta_data_size.into_safe_cast()) - .ok_or(EINVAL)?; - - hs_fw - .fw - .get(start..end) - .and_then(Self::from_bytes_copy) - .ok_or(EINVAL) - } -} - -/// Header for code and data load offsets. -#[repr(C)] -#[derive(Debug, Clone)] -struct HsLoadHeaderV2 { - // Offset at which the code starts. - os_code_offset: u32, - // Total size of the code, for all apps. - os_code_size: u32, - // Offset at which the data starts. - os_data_offset: u32, - // Size of the data. - os_data_size: u32, - // Number of apps following this header. Each app is described by a [`HsLoadHeaderV2App`]. - num_apps: u32, -} - -// SAFETY: all bit patterns are valid for this type, and it doesn't use interior mutability. -unsafe impl FromBytes for HsLoadHeaderV2 {} - -impl HsLoadHeaderV2 { - /// Returns the load header contained in `hs_fw`. - /// - /// Fails if the header pointed at by `hs_fw` is not within the bounds of the firmware image. - fn new(hs_fw: &HsFirmwareV2<'_>) -> Result { - frombytes_at::(hs_fw.fw, hs_fw.hdr.header_offset.into_safe_cast()) - } -} - -/// Header for app code loader. -#[repr(C)] -#[derive(Debug, Clone)] -struct HsLoadHeaderV2App { - /// Offset at which to load the app code. - offset: u32, - /// Length in bytes of the app code. - len: u32, -} - -// SAFETY: all bit patterns are valid for this type, and it doesn't use interior mutability. -unsafe impl FromBytes for HsLoadHeaderV2App {} - -impl HsLoadHeaderV2App { - /// Returns the [`HsLoadHeaderV2App`] for app `idx` of `hs_fw`. - /// - /// Fails if `idx` is larger than the number of apps declared in `hs_fw`, or if the header is - /// not within the bounds of the firmware image. - fn new(hs_fw: &HsFirmwareV2<'_>, idx: u32) -> Result { - let load_hdr = HsLoadHeaderV2::new(hs_fw)?; - if idx >= load_hdr.num_apps { - Err(EINVAL) - } else { - frombytes_at::( - hs_fw.fw, - usize::from_safe_cast(hs_fw.hdr.header_offset) - // Skip the load header... - .checked_add(size_of::()) - // ... and jump to app header `idx`. - .and_then(|offset| { - offset - .checked_add(usize::from_safe_cast(idx).checked_mul(size_of::())?) - }) - .ok_or(EINVAL)?, - ) - } - } -} - /// Signature for Booter firmware. Their size is encoded into the header and not known a compile /// time, so we just wrap a byte slices on which we can implement [`FirmwareSignature`]. struct BooterSignature<'a>(&'a [u8]); @@ -292,7 +83,6 @@ pub(crate) fn new( dev: &device::Device, kind: BooterKind, chipset: Chipset, - ver: &str, falcon: &Falcon<::Target>, bar: Bar0<'_>, ) -> Result { @@ -300,68 +90,64 @@ pub(crate) fn new( BooterKind::Loader => "booter_load", BooterKind::Unloader => "booter_unload", }; - let fw = super::request_firmware(dev, chipset, fw_name, ver)?; - let bin_fw = BinFirmware::new(&fw)?; + let fw = super::request_tlv(dev, chipset, fw_name)?; + let tlv = Tlv::new(fw.data())?; + dev_info!(dev, "loaded booter firmware v{}\n", tlv.get_string("VERS")?); + + let os_data_offset = tlv.get_u32("DAOF")?; + let os_data_size = tlv.get_u32("DASZ")?; + let os_code_offset = tlv.get_u32("CDOF")?; + let os_code_size = tlv.get_u32("CDSZ")?; + let patch_loc = tlv.get_u32("PLOC")?; + let fuse_version = tlv.get_u32("FUSE")?; + let engine_id = tlv.get_u32("ENID")?; + let ucode_id = tlv.get_u32("UCID")?; + let app0_code_offset = tlv.get_u32("A0CO")?; + let app0_code_size = tlv.get_u32("A0CS")?; + let num_sigs = tlv.get_u32("NSIG")?; - // The binary firmware embeds a Heavy-Secured firmware. - let hs_fw = HsFirmwareV2::new(&bin_fw)?; - - // The Heavy-Secured firmware embeds a firmware load descriptor. - let load_hdr = HsLoadHeaderV2::new(&hs_fw)?; - - // Offset in `ucode` where to patch the signature. - let patch_loc = hs_fw.patch_location()?; - - let sig_params = HsSignatureParams::new(&hs_fw)?; let brom_params = FalconBromParams { - // `load_hdr.os_data_offset` is an absolute index, but `pkc_data_offset` is from the + // `os_data_offset` is an absolute index, but `pkc_data_offset` is from the // signature patch location. - pkc_data_offset: patch_loc - .checked_sub(load_hdr.os_data_offset) - .ok_or(EINVAL)?, - engine_id_mask: u16::try_from(sig_params.engine_id_mask).map_err(|_| EINVAL)?, - ucode_id: u8::try_from(sig_params.ucode_id).map_err(|_| EINVAL)?, + pkc_data_offset: patch_loc.checked_sub(os_data_offset).ok_or(EINVAL)?, + engine_id_mask: u16::try_from(engine_id).map_err(|_| EINVAL)?, + ucode_id: u8::try_from(ucode_id).map_err(|_| EINVAL)?, }; - let app0 = HsLoadHeaderV2App::new(&hs_fw, 0)?; - // Object containing the firmware microcode to be signature-patched. - let ucode = bin_fw - .data() - .ok_or(EINVAL) + let ucode = tlv + .get_bytes("BLOB") .and_then(FirmwareObject::::new_booter)?; - let ucode_signed = { - let mut signatures = hs_fw.signatures_iter()?.peekable(); - - if signatures.peek().is_none() { - // If there are no signatures, then the firmware is unsigned. - ucode.no_patch_signature() - } else { - // Obtain the version from the fuse register, and extract the corresponding - // signature. - let reg_fuse_version = falcon.signature_reg_fuse_version( - bar, - brom_params.engine_id_mask, - brom_params.ucode_id, - )?; + let ucode_signed = if num_sigs == 0 { + // If there are no signatures, then the firmware is unsigned. + ucode.no_patch_signature() + } else { + // Obtain the version from the fuse register, and extract the corresponding + // signature. + let reg_fuse_version = falcon.signature_reg_fuse_version( + bar, + brom_params.engine_id_mask, + brom_params.ucode_id, + )?; + + const FUSE_VERSION_USE_LAST_SIG: u32 = 0; + let index = match reg_fuse_version { // `0` means the last signature should be used. - const FUSE_VERSION_USE_LAST_SIG: u32 = 0; - let signature = match reg_fuse_version { - FUSE_VERSION_USE_LAST_SIG => signatures.last(), - // Otherwise hardware fuse version needs to be subtracted to obtain the index. - reg_fuse_version => { - let Some(idx) = sig_params.fuse_ver.checked_sub(reg_fuse_version) else { - dev_err!(dev, "invalid fuse version for Booter firmware\n"); - return Err(EINVAL); - }; - signatures.nth(idx.into_safe_cast()) - } - } + FUSE_VERSION_USE_LAST_SIG => num_sigs - 1, + // Otherwise, hardware fuse version needs to be subtracted to obtain the index. + _ => fuse_version.checked_sub(reg_fuse_version).ok_or(EINVAL)?, + }; + + // The size of one signature + let sig_size = tlv + .len("SIGS")? + .checked_div(num_sigs.into_safe_cast()) .ok_or(EINVAL)?; - ucode.patch_signature(&signature, patch_loc.into_safe_cast())? - } + let signature = BooterSignature(tlv.get_nth_chunk("SIGS", sig_size, index as usize)?); + + ucode.patch_signature(&signature, patch_loc.into_safe_cast())? }; // There are two versions of Booter, one for Turing/GA100, and another for @@ -370,11 +156,11 @@ pub(crate) fn new( // don't indicate the versions. The only way to differentiate is by the Chipset. let (imem_sec_dst_start, imem_ns_load_target) = if chipset <= Chipset::GA100 { ( - app0.offset, + app0_code_offset, Some(FalconDmaLoadTarget { src_start: 0, - dst_start: load_hdr.os_code_offset, - len: load_hdr.os_code_size, + dst_start: os_code_offset, + len: os_code_size, }), ) } else { @@ -383,15 +169,15 @@ pub(crate) fn new( Ok(Self { imem_sec_load_target: FalconDmaLoadTarget { - src_start: app0.offset, + src_start: app0_code_offset, dst_start: imem_sec_dst_start, - len: app0.len, + len: app0_code_size, }, imem_ns_load_target, dmem_load_target: FalconDmaLoadTarget { - src_start: load_hdr.os_data_offset, + src_start: os_data_offset, dst_start: 0, - len: load_hdr.os_data_size, + len: os_data_size, }, brom_params, ucode: ucode_signed, diff --git a/drivers/gpu/nova-core/gsp/hal/tu102.rs b/drivers/gpu/nova-core/gsp/hal/tu102.rs index eb7166148cc9..bd103cf99662 100644 --- a/drivers/gpu/nova-core/gsp/hal/tu102.rs +++ b/drivers/gpu/nova-core/gsp/hal/tu102.rs @@ -27,8 +27,7 @@ FwsecCommand, FwsecFirmware, // }, - gsp::GspFirmware, - FIRMWARE_VERSION, // + gsp::GspFirmware, // }, gpu::Chipset, gsp::{ @@ -113,7 +112,6 @@ fn build( dev, BooterKind::Unloader, chipset, - FIRMWARE_VERSION, sec2_falcon, bar, )?, @@ -319,15 +317,12 @@ fn boot<'a>( "Using SEC2 to load and run the booter_load firmware...\n" ); - BooterFirmware::new( + BooterFirmware::new(dev, BooterKind::Loader, chipset, sec2_falcon, bar)?.run( dev, - BooterKind::Loader, - chipset, - FIRMWARE_VERSION, - sec2_falcon, bar, - )? - .run(dev, bar, sec2_falcon, wpr_meta)?; + sec2_falcon, + wpr_meta, + )?; Ok(unload_guard) } -- 2.54.0