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.56.35 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796299784; b=0ymCJA7kFnjUX3PwOOs/9vBiy8S2AaqS/36+UhDOa7mtJXEgGCvzSWnwzmRXc4SO1qar wGMwWG1jTrX3kglErKcwkp22cSS9r5dTUxf3VhrRAZ2ih4Bx5Sb1kILiZJlbGo/Wf7Avk bPAh1656Lm+s86sVbyi+6d+VZ8YsWN5T4aIbq98cUFI+hx0O7aKA+ARkIQFTEzCw4TX0X dymnWkBGf5zaDhYnHGCgvDqP0Xq2guqrOOoJqGn4OLyQhjdN2t53kDY+ZpbcxnZRRPli0 5IxGIJK7WvaVU+cR8tilxs6IpAZbouLEVq0cl/FWec4PisGZqWa0sT8JcHOEP5Xmeyw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796299784; 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=MaMk5hRknWqvrLS7dG5LwojDkaL5w0Am89p7y+29DH4=; b=d9JC3F/gbBf0gmAp0cKOoOtIkFHfmTzCvY7GRRBmiprpVpgI7dFSaZlRncpbs98TE59Q AXa/R/sYpH9LH3R5IBFMD9GTZ4suP+a75/NykSIK39EHKhvHMrKXUH+3RQvY30KOoF71u eGTCvPjtlrb+dWIi6HRW+Mj7TeqnphWXrjTpENcf5AKEfnoiPi9ZQ3vs8J8ysNr2b4HyB dz7BVZuPhI2wUTi6vGyfaFgcVqLt7s2uWuQ7zJvnvihU0zGznJU3XpnfAP4ZckKzMct3I cZBELEBJyiItdt+BUPXhqFi+1r6gabeB+X7xA0zQaJ4RjNq06+cHbu1MD4K/6nbIt/Q== 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=LWFaoMCy; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.56.35 Received: from BN1PR04CU002.outbound.protection.outlook.com (mail-eastus2azon11010035.outbound.protection.outlook.com [52.101.56.35]) (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 D66D5606AC3A; Thu, 3 Dec 2026 12:09:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D66D5606AC3A 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=LWFaoMCy ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DaXMg68iFqMq+cLgTZYNtQSnmxRgiuSLkIsN1jvKzv78p//oprKdQmPXpT79Utxak3ZjuTNWcKWBx+aV6sFXwnL0z9oKC+wlaIv0Nnf4+ZGl2lSNdtyJPT8FTJzAW0Trb1m/akaC1CgUIYMVvoh3DbHGsj1WBsDuDja7Df+GZUWw18qDixJbegCizxZ4dy7SCr73innaXPm4GIpHhvucaL38vYPvueq1ZKH04dD6JlP25iTiY+/XBNGJN+r8O/82n6ARbkh4COOG8XdYIPZagYyvsiSiOX5hARK+ZUZPUWIsk6uyA4qD06NdXkYJ9hEXLArFnKqotWF1+jLsItHV+A== 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=MaMk5hRknWqvrLS7dG5LwojDkaL5w0Am89p7y+29DH4=; b=NYL90EYn5FmkaGzuHLEsxHA2+nEKyOSKD2kPhoSW+0W5IZEJ17psgmtO+X8RKv68tv0IM+JFsoeLhW2WwHf2VNzigpOVdv7K/9R77L1xUowyxxF07MC4g02siLfYz9AztjDfUPhaHhF+SkjKGnk53LiYao0T1ox+wzZsw0k6xy5wyj3xufpnOHHSTt8+sfmVUYr2H4767UkpuMpPpm7xT1RlaOwwWyfeEeuI9Uulw34cXNNff0sW43keuplEfMAcs7IFy9bQ0wbxJc7vxGf3NKDX2MCKFnc9cAWxgrE4Bu4eZATiTW34qwyApEHEcg3fm7r/RIxRS5I1pZz8uPJLmg== 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=MaMk5hRknWqvrLS7dG5LwojDkaL5w0Am89p7y+29DH4=; b=LWFaoMCy+8dzfMmWs3aCVEnGBuOJWtJxdp2gI4JEApj0GeAEGzaGoq/ATkE6lMWELT6ZA8UMRW9HDBXbz3SSQHgXVmwWE3sG2698sWCkrK30YJPyT+YS2jjbvAWTHpIVg+I47tiYUGilQSkvOjPacoYUfrQ/XK7TGwDBFbve0NnHTeycvuAtfWPCB1H7BwwcJXIZ53nH5KLsobv5yc5MPIMVeujytbxvAcEjqEX/nd1zN/Yt3Q9acL893qO61wIq05m4k4fojIE5ST/8S5M7/93RLLp2Gj30wf3RdZzs3rJItw5SiuGxemzqHJmF4EsUEaX/AXdIC4m3kUB/qOe+QQ== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from PH7PR12MB6858.namprd12.prod.outlook.com (2603:10b6:510:1b4::20) by LV2PR12MB999073.namprd12.prod.outlook.com (2603:10b6:408:352::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Thu, 3 Dec 2026 12:09:41 +0000 Received: from PH7PR12MB6858.namprd12.prod.outlook.com ([fe80::a550:dbcf:2fcf:463d]) by PH7PR12MB6858.namprd12.prod.outlook.com ([fe80::a550:dbcf:2fcf:463d%6]) with mapi id 15.21.0688.009; Thu, 3 Dec 2026 12:09:41 +0000 From: Alexandre Courbot Date: Thu, 03 Dec 2026 21:09:19 +0900 Subject: [PATCH 02/15] gpu: nova-core: gsp: add the GSP_INIT command and its reply Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261203-b4-r000-switch-v1-2-b1463ec6dae2@nvidia.com> References: <20261203-b4-r000-switch-v1-0-b1463ec6dae2@nvidia.com> In-Reply-To: <20261203-b4-r000-switch-v1-0-b1463ec6dae2@nvidia.com> To: Danilo Krummrich , Alice Ryhl , David Airlie , Simona Vetter , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Daniel Almeida , Tamir Duberstein , =?utf-8?q?Onur_=C3=96zkan?= , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Jonathan Corbet , Shuah Khan , Randy Dunlap Cc: John Hubbard , Alistair Popple , Timur Tabi , Eliot Courtney , Zhi Wang , Alok Kumar , nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandre Courbot X-Mailer: b4 0.16.0 X-ClientProxiedBy: TY4P301CA0007.JPNP301.PROD.OUTLOOK.COM (2603:1096:405:26f::6) To PH7PR12MB6858.namprd12.prod.outlook.com (2603:10b6:510:1b4::20) 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: PH7PR12MB6858:EE_|LV2PR12MB999073:EE_ X-MS-Office365-Filtering-Correlation-Id: 8776988f-ba57-400d-0a21-08df51364f1a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|366016|1800799024|10070799003|7416014|376014|22082099003|18002099003|921020|56012099006|10067099003|261021123027099003|261021135927099003|261028144727099003|261022105027099003|261022113327099003|261102123227099003|261021121427099003|261026140227099003|261026121527099003|261022075727099003|261009223027099003|11063799006|6133799003|13003099007|3023799007; X-Microsoft-Antispam-Message-Info: qhJUYwJZQ9nBx0uctCMo4Onu2CpqdwT2oAPD4A4cV0xn6i/DXGlURdbjk0ywqEzGd0JmhIKhrRapGLadM13sZowVMQ0v5wvqfqJUg9tRhNnT+SmyI1ufBvo2kxudT4zNYl1qA4RGk0u87GIWxT01XHJQAnODw9i+b5KOF8jxA4s19puLvtzIqKpqB46yY97nylD+bAUzBzBmRMTucNwwtV0hrHVvY1IeEgwtMPh1FoDEzI+3f7Iyc7E/h53UjDzCYKJv+aU/9DIemDyW51asIdq12czXaEtFx+UR5cDb0CJpwv4lmw7JJVzSq5mmrLWX3d4CzEqjq3I0epaSJqThCKvVVdSwdjB2gFkpgykYuexit5umOTFZaIbyFfrT4II52UZOYMcXU9bvi88ngjjE1j9n/dpWbnagTSvVw/TAoyTqVGNxLRIxmiqEKAPkWMrUPPjjDxLcVje0u4u6nbLbtCXeIqxlFAefvCXqKcC3Cn+anKW6/OUWaUoZVSmrXSsMs526Oy45eMyYRQKp46ZxdwdoTJKNPkmyxJbJnyw2P2x2pIm5hVuNbSV/MnnFEX1F/0OiH8xGtn+db1tMPnfzOunUIB87QfGQnO7NMZDT6d8bbAYOwqsrDUHiQWz7nywEL1RSPEgMiw4uUFeBQSzQCYRKdiSkw/mlQsULpo/xjZWWbQxU5MjCFU1ZMe4pjlAyccEyg7eGxZ8D320BI2aTnw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH7PR12MB6858.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(366016)(1800799024)(10070799003)(7416014)(376014)(22082099003)(18002099003)(921020)(56012099006)(10067099003)(261021123027099003)(261021135927099003)(261028144727099003)(261022105027099003)(261022113327099003)(261102123227099003)(261021121427099003)(261026140227099003)(261026121527099003)(261022075727099003)(261009223027099003)(11063799006)(6133799003)(13003099007)(3023799007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?SVFxbVRjVGlxWUNzRGFSeUs1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?= =?utf-8?B?Q1VoQXhKclRvTnhtYTcxaitZZk1EQ1ZtN05jY1Q0UTVEZFZLcHNTNUhiS3pD?= =?utf-8?B?QlAweU5tSkxNTVRmcmM1c2MwcmRtMGR1and0NDU2LzNjRnpZVGxrb0w2eVZ4?= =?utf-8?B?MlJhWU8xa2ZMNENHYmNTSUNCWXRiTktOTzRJLzIwdlhibHhyTzIyV2ZFV2Rw?= =?utf-8?B?ckNyRFJaRERGaFlTcFFzakZXRUxkdi9Md0ZDVDFJdFRBcmdTT0FTTzhDWDlJ?= =?utf-8?B?M2V4c0hKT1N0RjcrcFNlTkt3aDJ3dTlpb3NRMEVFSGcwUklMQ2tKT3pncGlC?= =?utf-8?B?endRRjJmcko1RFpZZE5pbTJNcTFmTXNsRzh0TlBEY01YUUxNVnM0eE4xT1Ar?= =?utf-8?B?V20wMXlrWmhqZVkwNVJaUDFmd2FCcVdKeEk4dVhLdVJEQVRRcDRPeklxK2Q3?= =?utf-8?B?MGtFeGtlcW1KWWhEZkk1QTF3Y0t6ckxkR0U0VEtIdlpDN3VMakNiK1oxK05o?= =?utf-8?B?MDRoclBoai9FOWRRTnFRUXhPZTBhbUNTZTNWdFVYVGYvK2RscnQ5c242TnRx?= =?utf-8?Q?jnDWfaIZdbZYpiEH3JuPgWyxRTKNflMEmVflohiydRY+M?= X-MS-Exchange-AntiSpam-MessageData-1: Wto1wJDim5N0pg== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8776988f-ba57-400d-0a21-08df51364f1a X-MS-Exchange-CrossTenant-AuthSource: PH7PR12MB6858.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2026 12:09:40.8745 (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: fUmXfEZU1GoktC6Lo1WsDh3OAihlh76sejvgHAywovbEHujSPn9OBlmA+L3Fx9b9hFWSCfeVnlmBGzavAC34Fw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB999073 From: John Hubbard The r000 boot protocol replaces the system-info, registry and static-info RPC commands with one GMC command, GSP_INIT, whose payload is an NVKV stream of key-value pairs. GSP-RM answers it once it has finished starting, with the static GPU configuration. Nova-core has the NVKV codec and the GSP_INIT schemas. It has no code that fills the request schema in from the PCI device, and no code that decodes the reply into the static configuration type that the boot sequence returns. Add the GSP_INIT command, whose variable payload is the encoded request, and decode its reply into the static configuration type, so that the rest of the driver reads the same configuration whichever firmware reported it. The request carries the registry keys that the r570 registry command sends, and it reports the architecture that the kernel is built for. Signed-off-by: John Hubbard [acourbot: declare `REGISTRY_ENTRIES` as const `Key`s.] [acourbot: avoid double-copy in `read`.] [acourbot: use `CStr` in `RegKey::new`.] [acourbot: return fixed-size arrays from `GspInitResponse`.] Co-developed-by: Alexandre Courbot Signed-off-by: Alexandre Courbot --- drivers/gpu/nova-core/gsp/commands.rs | 3 + drivers/gpu/nova-core/gsp/commands/gmc.rs | 133 +++++++++++++++++++++++++ drivers/gpu/nova-core/gsp/fw/commands.rs | 155 +++++++++++++++++++++++++++--- 3 files changed, 279 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/nova-core/gsp/commands.rs b/drivers/gpu/nova-core/gsp/commands.rs index 91f63f704e55..b48cf30978cf 100644 --- a/drivers/gpu/nova-core/gsp/commands.rs +++ b/drivers/gpu/nova-core/gsp/commands.rs @@ -1,6 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 // SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// The r570 firmware does not use GMC. +#[expect(dead_code)] +pub(crate) mod gmc; pub(crate) mod rpc; use core::{ diff --git a/drivers/gpu/nova-core/gsp/commands/gmc.rs b/drivers/gpu/nova-core/gsp/commands/gmc.rs new file mode 100644 index 000000000000..f74ada78f7ac --- /dev/null +++ b/drivers/gpu/nova-core/gsp/commands/gmc.rs @@ -0,0 +1,133 @@ +// SPDX-License-Identifier: GPL-2.0 +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + +//! GMC (GPU Management Controller) API commands. + +use core::convert::Infallible; + +use kernel::{ + device, + pci, + prelude::*, + time::Delta, + transmute::AsBytes, // +}; + +use crate::{ + gpu::Chipset, + gsp::{ + cmdq::gmc::{ + CommandToGsp, + MessageFromGsp, // + }, + commands::GspStaticInfo, + fw::{ + commands::{ + GspInitRequest, + GspInitResponseSchema, // + }, + GmcCommandId, // + }, + nvkv::{ + Decoder, + Encodable, + Encoder, + Schema, + UnknownKeyPolicy, // + }, + }, + sbuffer::SBufferIter, +}; + +/// The `GSP_INIT` command, which carries the system information and registry keys to GSP-RM. +/// +/// GSP-RM answers it with the static GPU configuration once it has finished starting. +pub(crate) struct GspInit { + /// The NVKV-encoded request. + payload: KVVec, +} + +impl GspInit { + /// Builds the request for `pdev`. + /// + /// # Errors + /// + /// - `ENOMEM` if the request or the encoder buffer cannot be allocated. + pub(crate) fn new(pdev: &pci::Device, chipset: Chipset) -> Result { + let mut encoder = Encoder::new(); + GspInitRequest::new(pdev, chipset)?.encode(&mut encoder)?; + + Ok(Self { + payload: encoder.finish(), + }) + } + + /// Returns the request as the bytes that the GSP reads. + fn payload_bytes(&self) -> &[u8] { + AsBytes::as_bytes(self.payload.as_slice()) + } +} + +impl CommandToGsp for GspInit { + const COMMAND: GmcCommandId = GmcCommandId::GspInit; + /// Largest reply that the driver accepts, in bytes. + const MAX_REPLY_SIZE: u32 = 48 * 1024; + /// `GspInit` can take longer than 5 seconds to complete on some SKUs. + const COMPLETION_TIMEOUT: Delta = Delta::from_secs(15); + type Command = (); + type Reply = GspStaticInfo; + type InitError = Infallible; + + fn init(&self) -> impl Init { + pin_init::init_zeroed() + } + + fn variable_payload_len(&self) -> usize { + self.payload_bytes().len() + } + + fn init_variable_payload( + &self, + dst: &mut SBufferIter>, + ) -> Result { + dst.write_all(self.payload_bytes()) + } +} + +impl MessageFromGsp for GspStaticInfo { + type InitError = Error; + + /// Decodes the `GSP_INIT` reply, an NVKV stream, into the static configuration. + /// + /// # Errors + /// + /// - `EINVAL` if the payload is not a whole number of NVKV words, if the stream is malformed + /// or omits a required key, or if GSP-RM reported no framebuffer region. + /// - `ENOMEM` if the words or the decoded regions cannot be allocated. + fn read(payload: &mut SBufferIter>) -> Result { + let mut words = KVVec::new(); + while !payload.is_empty() { + let mut word = [0u8; size_of::()]; + payload.read_exact(&mut word)?; + words.push(u64::from_le_bytes(word), GFP_KERNEL)?; + } + + let decoder = Decoder::new(&words, UnknownKeyPolicy::Ignore); + let mut schema = KBox::init(GspInitResponseSchema::init(), GFP_KERNEL)?; + let reply = KBox::try_init(decoder.decode(&mut *schema)?, GFP_KERNEL)?; + + let mut usable_fb_regions = KVec::new(); + for region in reply.usable_fb_regions() { + usable_fb_regions.push(region, GFP_KERNEL)?; + } + + Ok(GspStaticInfo { + gpu_name: reply.gpu_name(), + gpu_short_name: reply.gpu_short_name(), + gpu_gid: reply.gpu_gid(), + bar1_pde_base: reply.bar1_pde_base(), + usable_fb_regions, + total_fb_end: reply.total_fb_end().ok_or(EINVAL)?, + }) + } +} diff --git a/drivers/gpu/nova-core/gsp/fw/commands.rs b/drivers/gpu/nova-core/gsp/fw/commands.rs index 76f8d4a75562..c7f544775ce9 100644 --- a/drivers/gpu/nova-core/gsp/fw/commands.rs +++ b/drivers/gpu/nova-core/gsp/fw/commands.rs @@ -331,6 +331,25 @@ fn from(value: HostArch) -> Self { } } +impl HostArch { + /// Returns the variant that names the architecture for which this kernel is built. + fn host() -> Self { + if cfg!(target_arch = "x86_64") { + Self::X86_64 + } else if cfg!(target_arch = "aarch64") { + Self::Aarch64 + } else if cfg!(all(target_arch = "powerpc64", target_endian = "little")) { + Self::Ppc64le + } else if cfg!(target_arch = "arm") { + Self::Arm + } else if cfg!(target_arch = "riscv64") { + Self::Riscv64 + } else { + Self::None + } + } +} + nvkv_encode! { /// A GSP registry entry. struct RegKey { @@ -339,6 +358,18 @@ struct RegKey { } } +impl RegKey { + /// Creates a registry entry. + /// + /// GSP-RM counts the NUL terminator in the encoded name length. + const fn new(key_name: &'static CStr, key_value: u32) -> Self { + Self { + key_name: Key::new(key_name.to_bytes_with_nul()), + key_value: Key::new(key_value), + } + } +} + impl Encodable for KVVec { fn encode(&self, encoder: &mut Encoder) -> Result { for regkey in self { @@ -362,10 +393,7 @@ struct VfInfo { nvkv_encode! { /// Payload of the `GSP_INIT` command. - // TODO: expect() doesn't work here before rustc 1.97.0 - // https://github.com/rust-lang/rust/pull/154377 - #[allow(dead_code)] - struct GspInitRequest { + pub(crate) struct GspInitRequest { pci_device_id: Key, pci_sub_device_id: Key, pci_revision_id: Key, @@ -406,15 +434,55 @@ fn new(dev: &pci::Device) -> Self { } } +/// Registry entries that the driver sends to GSP-RM on every boot. +const REGISTRY_ENTRIES: [RegKey; 3] = [ + // Enables PCI secondary bus reset. + RegKey::new(c"RMSecBusResetEnable", 1), + // Makes GSP-RM preserve PCI configuration registers across any PCI reset. + RegKey::new(c"RMForcePcieConfigSave", 1), + // Lets GSP-RM boot when the PCI device id is absent from its product name database. + RegKey::new(c"RMDevidCheckIgnore", 1), +]; + +impl GspInitRequest { + /// Creates the request for `dev`. + /// + /// The registry keys are [`REGISTRY_ENTRIES`]. + /// + /// # Errors + /// + /// - `ENOMEM` if the registry list cannot be allocated. + pub(crate) fn new(dev: &pci::Device, chipset: Chipset) -> Result { + let mut regkeys = KVVec::new(); + for entry in REGISTRY_ENTRIES { + regkeys.push(entry, GFP_KERNEL)?; + } + + let mirror = chipset.pci_config_mirror_range(); + let device_id = (u32::from(dev.device_id()) << 16) | u32::from(dev.vendor_id().as_raw()); + let sub_device_id = + (u32::from(dev.subsystem_device_id()) << 16) | u32::from(dev.subsystem_vendor_id()); + + Ok(Self { + pci_device_id: device_id.into(), + pci_sub_device_id: sub_device_id.into(), + pci_revision_id: u32::from(dev.revision_id()).into(), + pci_config_mirror_base: mirror.start.into(), + pci_config_mirror_size: (mirror.end - mirror.start).into(), + host_arch: HostArch::host().into(), + bus_device_func: u64::from(DomainBusDevice::new(dev)).into(), + regkeys, + vf_info: None, + }) + } +} + // Decode: // Should decode with UnknownKeyPolicy::Ignore. nvkv_decode! { /// Schema for the `GSP_INIT` response. - // TODO: expect() doesn't work here before rustc 1.97.0 - // https://github.com/rust-lang/rust/pull/154377 - #[allow(dead_code)] - struct GspInitResponseSchema => GspInitResponse { + pub(crate) struct GspInitResponseSchema => GspInitResponse { gpu_name: TruncatingArray, gpu_short_name: TruncatingArray, gpu_gid: TruncatingArray, @@ -425,10 +493,7 @@ struct GspInitResponseSchema => GspInitResponse { } /// Payload of the `GSP_INIT` response. -// TODO: expect() doesn't work here before rustc 1.97.0 -// https://github.com/rust-lang/rust/pull/154377 -#[allow(dead_code)] -struct GspInitResponse { +pub(crate) struct GspInitResponse { gpu_name: ArrayVec, gpu_short_name: ArrayVec, gpu_gid: ArrayVec, @@ -437,6 +502,72 @@ struct GspInitResponse { vmmu_segment_size: u64, } +/// Copies `src` to the start of a zero-initialized array. +fn zero_padded_array(src: &ArrayVec) -> [u8; N] { + let mut dst = [0u8; N]; + // PANIC: `src.len()` never exceeds `N` per the invariant of `ArrayVec`. + dst[..src.len()].copy_from_slice(src); + dst +} + +impl GspInitResponse { + /// Tag of a general-purpose region. Any other tag marks a region that GSP-RM reserves for the + /// use that the tag names. + const FB_REGION_TAG_NONE: u32 = 0; + + /// Returns the GPU name, zero-padded to [`GspStaticInfo::MAX_GPU_NAME_LEN`] bytes. + pub(crate) fn gpu_name(&self) -> [u8; GspStaticInfo::MAX_GPU_NAME_LEN] { + zero_padded_array(&self.gpu_name) + } + + /// Returns the short GPU name, zero-padded to [`GspStaticInfo::MAX_GPU_NAME_LEN`] bytes. + pub(crate) fn gpu_short_name(&self) -> [u8; GspStaticInfo::MAX_GPU_NAME_LEN] { + zero_padded_array(&self.gpu_short_name) + } + + /// Returns the SHA-1 based GPU identifier (GID), zero-padded to [`GspStaticInfo::GID_LEN`] + /// bytes. + pub(crate) fn gpu_gid(&self) -> [u8; GspStaticInfo::GID_LEN] { + zero_padded_array(&self.gpu_gid) + } + + /// Returns an iterator over the FB regions from which the driver may allocate: the + /// general-purpose regions that are not protected and that support both compression and + /// isochronous access. + pub(crate) fn usable_fb_regions(&self) -> impl Iterator> + '_ { + self.fb_regions.iter().filter_map(|region| { + if region.limit >= region.base + && region.tag == Self::FB_REGION_TAG_NONE + && !region.flags.protected() + && region.flags.support_compressed() + && region.flags.support_iso() + { + region.limit.checked_add(1).map(|end| region.base..end) + } else { + None + } + }) + } + + /// Returns the exclusive end of the FB physical address space, which spans every region + /// including the ones that [`Self::usable_fb_regions`] leaves out. + /// + /// Returns `None` if no region that GSP-RM reported has a limit at or above its base. + pub(crate) fn total_fb_end(&self) -> Option { + self.fb_regions + .iter() + .filter(|region| region.limit >= region.base) + .map(|region| region.limit) + .max()? + .checked_add(1) + } + + /// Returns the BAR1 page directory entry base address. + pub(crate) fn bar1_pde_base(&self) -> u64 { + self.bar1_pde_base + } +} + nvkv_decode! { /// Schema for one FB region of the `GSP_INIT` response. struct FbRegionSchema => FbRegion { -- 2.56.1