From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from BL0PR03CU003.outbound.protection.outlook.com (mail-eastusazon11012057.outbound.protection.outlook.com [52.101.53.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 B82524E66A5; Fri, 9 Oct 2026 11:55:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.53.57 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791546917; cv=fail; b=rLvvMH7wfzPJinnuRFMPtOvAxLOOwV5ZVHo/0LvJwC39Jqwk6JYBc8dPi/J2ZhTeUd6OYCBv18UrwyDOC7/wDVvZzhRrYvPsPg7/qr8q2hJYl45p4Zgsvqsc6qJKNkAPpvLg6cxy9lAfS28A/r5BU7svMKAg/33+UZcSm/8QFww= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791546917; c=relaxed/simple; bh=GcX13rKQlXb1lvW/NyjvSnuBA7SQlZ4MDcXXNMAXrz4=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=i6/eiUMtGEb13ohxBkJKGQ+rn9kF9eix5yFEIn+/zk+XgCsYLK66W2ldbrqdqRmyw+qmjJBD7xjUA0SlPChDDWMuzmLBcfZATBTvokQcdrPpqDwxV09Vc5b+sRwvy8feNJjH2cxFGns5J0VYkk2Nx9/TAoLG0EnywS57I+exZoo= 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=mcK1eafU; arc=fail smtp.client-ip=52.101.53.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="mcK1eafU" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=I1y6PjcRUgaEUSTuYYDHUdlq7Jk/My6SzX+Z97ByEdeIYpQDKC73rftsjxTjPXIHQfvhxhSuJQ2MYYfMw/ZCA0OJzSOQ05zYVb49icRZasmsiVtfyv8IpasqI5PLg0Kzy1a7ixMfr9JsBJ9tMgDjJ73PDJ3de19cYSmphNdJVjIiiiqz75RIK2MIJqE23sUjOMo2/ROSN8Gm0cpN3gluIDw7Mr5O9u0CXF05gYGMRLzYzq2M22alqkPTarCQksgp39giNPtQSS0DIEP0KX7/5nVDJVL45k2mRA3LL5DXb7ySeVy9wY4rzJ/dnuD0kwXuW4XkjXby44wcXJoKCTOPMw== 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=k5qnArfsYkEPr9Oc7MS4hkZaCEaeK4LjfRwj4bb3Yw4=; b=RriaHcJ31ept9kcafeGLGTLRI/IXj/ZfhDphgtZKcnjmZoW59gtn4dEWOOPLzuzpfRINDQOy1uQrrIAVdFXHvVOWk26RwUKYp28suQ/5sJFcNx5o2fwJCB8ArGXGvsl0IDAXNRpKTtZmpcvHL/1LX3PwyRQlF4t0lkba89SFIRJLaodBJLjoGxZyvU1GFRUkMyC88n28fGBYHCf2XffcmtGEnIBrYNKrp7n9h3y2LgV6ieYgLCdC3uyFsAXJhhqGOQ/SVJkarBuKBh1hOMAOpMgTkgc2b7hI9CAVVkWN0olFx7J7WJVoZSLdTViYoEss6Pr70LRhSh8w7vucHJJDuA== 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=k5qnArfsYkEPr9Oc7MS4hkZaCEaeK4LjfRwj4bb3Yw4=; b=mcK1eafUqhBAO8WdnD9h5IbvBZ4dYOP5ew8i4C+tAOtXZeAG4UMMHsLdj9I2v593ZAWtAf/+yb2dhX7j8EozKUMiKpUuDIBOr+3kwe0NkjPnx2ll4zRsuRZzvvdPL2rNV97ZQlDmESXOLA6vrWfRRYFCTtzxBzbP4pHenNvxcl2cR4QXqmO7kfkgu6aWEZ8hlVJ1El+hLLf8yts9T5xT4eWP17VCl5L8FRh8d/M683WvqXc8qrDL7SLzppGlufsmXTWH7LF8WW1K5yh5/lgklUHZJQQy6Mohrj9EPM4Xu6ld+Nk6LE233B2oPKB6tBW2UYzrKPPxXgtQB7KBEoePeQ== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MW4PR12MB6873.namprd12.prod.outlook.com (2603:10b6:303:20c::17) by DS2PR12MB473522.namprd12.prod.outlook.com (2603:10b6:8:400::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.496.17; Fri, 9 Oct 2026 11:54:47 +0000 Received: from MW4PR12MB6873.namprd12.prod.outlook.com ([fe80::a338:bd2c:3a38:ece1]) by MW4PR12MB6873.namprd12.prod.outlook.com ([fe80::a338:bd2c:3a38:ece1%5]) with mapi id 15.21.0472.016; Fri, 9 Oct 2026 11:54:47 +0000 From: Alexandre Courbot Date: Fri, 09 Oct 2026 20:54:05 +0900 Subject: [PATCH v4 09/10] gpu: nova-core: gsp: move the RPC commands into a sub-module Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261009-cmdq-rpc-v4-9-c9ab8de1d3f2@nvidia.com> References: <20261009-cmdq-rpc-v4-0-c9ab8de1d3f2@nvidia.com> In-Reply-To: <20261009-cmdq-rpc-v4-0-c9ab8de1d3f2@nvidia.com> To: John Hubbard , Danilo Krummrich , Alice Ryhl , David Airlie , Simona Vetter , Benno Lossin , Gary Guo Cc: Alistair Popple , Timur Tabi , Eliot Courtney , Zhi Wang , 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: OS3PR01CA0034.jpnprd01.prod.outlook.com (2603:1096:604:db::21) To MW4PR12MB6873.namprd12.prod.outlook.com (2603:10b6:303:20c::17) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW4PR12MB6873:EE_|DS2PR12MB473522:EE_ X-MS-Office365-Filtering-Correlation-Id: 10da9838-e05d-403d-0def-08df25fc1dcf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|10070799003|366016|376014|7416014|23010399003|56012099006|11063799006|10067099003|18002099003|22082099003|6133799003|3023799007; X-Microsoft-Antispam-Message-Info: sBPvTT3viPd5j2yK4PqS8+kYveXVqJaK7GRMAp62i3us9mmHMOQfggEcf9UG2BrvWfqbokhD2pw3HPSgvGbhjhrfXXD0T43nJZ6LjVigUTfgG9vQ8UuF0P6ww/8xWtVz4CF/qtjl9/TNz9ALXPbgILgEc8ZghrQBfcXEzZjsiOe5xj06ko3pufKQQN8XBGWvH5VOG38NnzrMk6eGSxgRXeOsDY6EBnoOJ0IruZBomyJLz49Nhn46BUgAfpICL2JBjV+zzIuyXDFUDTQDpPWbyE/ionhZmeSv3XRuXj8qONRr22ACiKPBrrlEEEFeO2RZJCEorVSDseYoJ99SOrAcOOCaNFIG2UsYFeNsXvP8G1FufK19mCB6HxCPowiKRdRdV+coPRfGypakb5hsXfkqVxdTjeawtDuQWtY0cwJWofyX6w92y53hFyIdVhOclw8HYPHLTdducIRQFIeDo+OoWODO/odxp6tcgj6ToOHKnaC2HA0nvLgq4P7JpWkVUkvwwZQH8GYB+Hwj4Pk1KCEwu0TTZvX7UiDU2YEERPiiDEH0fiMwlBFW7d4wEmFKw74XZCLUxqfIo4bP2jl3ymP5bvTZWkYWYt4+PTrYNwnaefoQYbm99J/xuUT21aErfToS0V7He+9FluW6WBHLF4kaW9oHiXvRQlbZlavJqRHREto= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW4PR12MB6873.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(10070799003)(366016)(376014)(7416014)(23010399003)(56012099006)(11063799006)(10067099003)(18002099003)(22082099003)(6133799003)(3023799007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?aTRGMWR1c2xld1FDOVJnbFRsZjhCdmliZ0ZyY0UvclVFUk9jazBzSy9WN1dk?= =?utf-8?B?SmJtNFUvMk5xRGNvQzYwSUpZQXcyTGxubHcxK3BEOThwYzgxczVGMkxsKzQ5?= =?utf-8?B?dFlpK21yVzVwQTZRSUlJTVFwQWhoa2FIcDlleml6UUNyZ1JEQUpZN0JYcHhq?= =?utf-8?B?SXhSYWRvajR6cHA3Q2M3NXBncTdqRWFSa08xQi8raEl5Z1NCZjRJUllNeTM5?= =?utf-8?B?OTg1SlRyVThuS09BaTRSbFN4YnFNSFAyVkpBUk4wZFVLM2R0Tm94Q1hZM3Vp?= =?utf-8?B?OXdvdktvVkUwVUdwazR2SHhrRWI5Uk9ZRHVrVGJ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RjR4bjIzZ2NwWDh4aDlxZHFkWUdvd1NVMFI5OCtYMStVajdNVXNSekhySUJC?= =?utf-8?B?YmM3Q2cxTlN6bzFwcXgxVyt6SWxCWnE5ck9EOVFFMmZ2bUtTdVo4SUpMblN0?= =?utf-8?B?aVZUVWduS09QUlcwZjNrQTVxUVZHU1o2YUdyODhqU2txQldjZmhGOGFLLzNP?= =?utf-8?B?ZDBiakhPTXhucUtVbldmMEpqSXhoR3lBV29KMHd3YWhDZ25RdUk3WU9NbHZS?= =?utf-8?Q?soB2Jv9IrEQp33gTMtr1N2loZfJc7Avn2dTuoW90t9WDt?= X-MS-Exchange-AntiSpam-MessageData-1: 0kREGVJyoeUafg== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 10da9838-e05d-403d-0def-08df25fc1dcf X-MS-Exchange-CrossTenant-AuthSource: MW4PR12MB6873.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2026 11:54:47.4560 (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: 9U0mb8KYlU7ifvofa+d7aa/cmu6DfOym6K4W4qfm3n2xw4V/FZwdDkFDBbPlTD/+Ts+vHjGIsJkhgtv7j5XSDQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS2PR12MB473522 Move the types and code related to RPC commands into the `rpc` sub-module, and update their users to reference them from their new location. This is a pure move commit, with no functional change intended. Signed-off-by: Alexandre Courbot Reviewed-by: Eliot Courtney --- drivers/gpu/nova-core/api.rs | 2 +- drivers/gpu/nova-core/gpu.rs | 2 +- drivers/gpu/nova-core/gsp.rs | 4 +- drivers/gpu/nova-core/gsp/boot.rs | 12 +- drivers/gpu/nova-core/gsp/commands.rs | 331 +---------------------------- drivers/gpu/nova-core/gsp/commands/rpc.rs | 333 ++++++++++++++++++++++++++++++ 6 files changed, 344 insertions(+), 340 deletions(-) diff --git a/drivers/gpu/nova-core/api.rs b/drivers/gpu/nova-core/api.rs index 29207c4bb743..eec69aace3b2 100644 --- a/drivers/gpu/nova-core/api.rs +++ b/drivers/gpu/nova-core/api.rs @@ -18,7 +18,7 @@ use crate::{ driver, gpu::Gpu, - gsp::commands::GetGspStaticInfoReply, // + gsp::commands::rpc::GetGspStaticInfoReply, // }; /// API handle for the auxiliary bus child drivers to interact with nova-core. diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs index 4e59072cab50..ac5305d7ff5e 100644 --- a/drivers/gpu/nova-core/gpu.rs +++ b/drivers/gpu/nova-core/gpu.rs @@ -35,7 +35,7 @@ gsp::{ self, cmdq::Cmdq, - commands::GetGspStaticInfoReply, + commands::rpc::GetGspStaticInfoReply, Gsp, GspBootContext, // }, diff --git a/drivers/gpu/nova-core/gsp.rs b/drivers/gpu/nova-core/gsp.rs index dda58095f40b..75a3ba7d50f4 100644 --- a/drivers/gpu/nova-core/gsp.rs +++ b/drivers/gpu/nova-core/gsp.rs @@ -220,8 +220,8 @@ pub(crate) fn new( } /// Query the GSP for the static GPU information. - pub(crate) fn get_static_info(&self) -> Result { - self.cmdq.send_command(commands::GetGspStaticInfo) + pub(crate) fn get_static_info(&self) -> Result { + self.cmdq.send_command(commands::rpc::GetGspStaticInfo) } } diff --git a/drivers/gpu/nova-core/gsp/boot.rs b/drivers/gpu/nova-core/gsp/boot.rs index 4fb1b69ac9d5..8e446ad1eac2 100644 --- a/drivers/gpu/nova-core/gsp/boot.rs +++ b/drivers/gpu/nova-core/gsp/boot.rs @@ -43,9 +43,9 @@ pub(crate) fn boot( let gsp_fw = KBox::pin_init(GspFirmware::new(dev, chipset), GFP_KERNEL)?; self.cmdq - .send_command_no_wait(commands::SetSystemInfo::new(pdev, chipset))?; + .send_command_no_wait(commands::rpc::SetSystemInfo::new(pdev, chipset))?; self.cmdq - .send_command_no_wait(commands::SetRegistry::new(ctx.vgpu.state())?)?; + .send_command_no_wait(commands::rpc::SetRegistry::new(ctx.vgpu.state())?)?; // Perform the chipset-specific boot sequence, and retrieve the unload bundle. let unload_bundle = hal.boot(&self, &mut ctx, &gsp_fw)?.or_else(|| { @@ -79,7 +79,7 @@ pub(crate) fn boot( hal.post_boot(&self, ctx, &gsp_fw)?; // Wait until GSP is fully initialized. - commands::wait_gsp_init_done(&self.cmdq)?; + commands::rpc::wait_gsp_init_done(&self.cmdq)?; Ok(unload_guard.dismiss().1) } @@ -88,10 +88,10 @@ pub(crate) fn boot( fn shutdown_gsp( cmdq: &Cmdq<'_>, gsp_falcon: &Falcon<'_, Gsp>, - mode: commands::PowerStateLevel, + mode: commands::rpc::PowerStateLevel, ) -> Result { // Command to shut the GSP down. - cmdq.send_command(commands::UnloadingGuestDriver::new(mode))?; + cmdq.send_command(commands::rpc::UnloadingGuestDriver::new(mode))?; // Wait until GSP signals it is suspended. const LIBOS_INTERRUPT_PROCESSOR_SUSPENDED: u32 = bits::bit_u32(31); @@ -118,7 +118,7 @@ pub(crate) fn unload( let mut res = Self::shutdown_gsp( &self.cmdq, ctx.gsp_falcon, - commands::PowerStateLevel::Level0, + commands::rpc::PowerStateLevel::Level0, ) .inspect_err(|e| dev_err!(dev, "GSP shutdown failed: {:?}\n", e)); diff --git a/drivers/gpu/nova-core/gsp/commands.rs b/drivers/gpu/nova-core/gsp/commands.rs index ceac0b0f9423..5f1c944678be 100644 --- a/drivers/gpu/nova-core/gsp/commands.rs +++ b/drivers/gpu/nova-core/gsp/commands.rs @@ -1,333 +1,4 @@ // SPDX-License-Identifier: GPL-2.0 // SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -use core::{ - array, - convert::Infallible, - ffi::FromBytesUntilNulError, - ops::Range, - str::Utf8Error, // -}; - -use kernel::{ - device, - pci, - prelude::*, - transmute::{ - AsBytes, - FromBytes, // - }, // -}; - -use crate::{ - gpu::Chipset, - gsp::{ - cmdq::{ - rpc::{ - CommandToGsp, - MessageFromGsp, // - }, - Cmdq, - NoReply, // - }, - fw::{ - self, - MsgFunction, // - }, - }, - sbuffer::SBufferIter, - vgpu::VgpuState, // -}; - -/// The `GspSetSystemInfo` command. -pub(crate) struct SetSystemInfo<'a> { - pdev: &'a pci::Device, - chipset: Chipset, -} - -impl<'a> SetSystemInfo<'a> { - /// Creates a new `GspSetSystemInfo` command using the parameters of `pdev`. - pub(crate) fn new(pdev: &'a pci::Device, chipset: Chipset) -> Self { - Self { pdev, chipset } - } -} - -impl<'a> CommandToGsp for SetSystemInfo<'a> { - const FUNCTION: MsgFunction = MsgFunction::GspSetSystemInfo; - type Command = fw::commands::GspSetSystemInfo; - type Reply = NoReply; - type InitError = Error; - - fn init(&self) -> impl Init { - Self::Command::init(self.pdev, self.chipset) - } -} - -struct RegistryEntry { - key: &'static str, - value: u32, -} - -/// The `SetRegistry` command. -pub(crate) struct SetRegistry { - entries: KVec, -} - -impl SetRegistry { - /// Creates a new `SetRegistry` command, using a set of hardcoded entries. - pub(crate) fn new(vgpu_state: VgpuState) -> Result { - let mut entries = KVec::new(); - - // RMSecBusResetEnable - enables PCI secondary bus reset - entries.push( - RegistryEntry { - key: "RMSecBusResetEnable", - value: 1, - }, - GFP_KERNEL, - )?; - - // RMForcePcieConfigSave - forces GSP-RM to preserve PCI configuration registers on - // any PCI reset. - entries.push( - RegistryEntry { - key: "RMForcePcieConfigSave", - value: 1, - }, - GFP_KERNEL, - )?; - - // RMDevidCheckIgnore - allows GSP-RM to boot even if the PCI dev ID is not found - // in the internal product name database. - entries.push( - RegistryEntry { - key: "RMDevidCheckIgnore", - value: 1, - }, - GFP_KERNEL, - )?; - - if matches!(vgpu_state, VgpuState::Enabled { .. }) { - // RMSetSriovMode - required when vGPU is enabled. - entries.push( - RegistryEntry { - key: "RMSetSriovMode", - value: 1, - }, - GFP_KERNEL, - )?; - } - - Ok(Self { entries }) - } -} - -impl CommandToGsp for SetRegistry { - const FUNCTION: MsgFunction = MsgFunction::SetRegistry; - type Command = fw::commands::PackedRegistryTable; - type Reply = NoReply; - type InitError = Infallible; - - fn init(&self) -> impl Init { - Self::Command::init(self.entries.len() as u32, self.size() as u32) - } - - fn variable_payload_len(&self) -> usize { - let mut key_size = 0; - for entry in self.entries.iter() { - key_size += entry.key.len() + 1; // +1 for NULL terminator - } - self.entries.len() * size_of::() + key_size - } - - fn init_variable_payload( - &self, - dst: &mut SBufferIter>, - ) -> Result { - let string_data_start_offset = size_of::() - + self.entries.len() * size_of::(); - - // Array for string data. - let mut string_data = KVec::new(); - - for entry in self.entries.iter() { - dst.write_all( - fw::commands::PackedRegistryEntry::new( - (string_data_start_offset + string_data.len()) as u32, - entry.value, - ) - .as_bytes(), - )?; - - let key_bytes = entry.key.as_bytes(); - string_data.extend_from_slice(key_bytes, GFP_KERNEL)?; - string_data.push(0, GFP_KERNEL)?; - } - - dst.write_all(string_data.as_slice()) - } -} - -/// Message type for GSP initialization done notification. -struct GspInitDone; - -// SAFETY: `GspInitDone` is a zero-sized type with no bytes, therefore it -// trivially has no uninitialized bytes. -unsafe impl FromBytes for GspInitDone {} - -impl MessageFromGsp for GspInitDone { - const FUNCTION: MsgFunction = MsgFunction::GspInitDone; - type InitError = Infallible; - type Message = (); - - fn read( - _msg: &Self::Message, - _sbuffer: &mut SBufferIter>, - ) -> Result { - Ok(GspInitDone) - } -} - -/// Waits for GSP initialization to complete. -pub(crate) fn wait_gsp_init_done(cmdq: &Cmdq<'_>) -> Result { - cmdq.await_msg::().map(|_| ()) -} - -/// The `GetGspStaticInfo` command. -pub(crate) struct GetGspStaticInfo; - -impl CommandToGsp for GetGspStaticInfo { - const FUNCTION: MsgFunction = MsgFunction::GetGspStaticInfo; - type Command = fw::commands::GspStaticConfigInfo; - type Reply = GetGspStaticInfoReply; - type InitError = Infallible; - - fn init(&self) -> impl Init { - Self::Command::init_zeroed() - } -} - -/// The reply from the GSP to the [`GetGspStaticInfo`] command. -pub struct GetGspStaticInfoReply { - gpu_name: [u8; 64], - gpu_short_name: [u8; 64], - /// The 16-byte SHA-1 based GPU identifier (GID) reported by GSP-RM. - pub gpu_gid: [u8; 16], - /// BAR1 Page Directory Entry base address. - pub(crate) bar1_pde_base: u64, - /// Usable FB (VRAM) regions for driver memory allocation. - pub(crate) usable_fb_regions: KVec>, - /// Exclusive end of the FB physical address space. - pub(crate) total_fb_end: u64, -} - -impl MessageFromGsp for GetGspStaticInfoReply { - const FUNCTION: MsgFunction = MsgFunction::GetGspStaticInfo; - type Message = fw::commands::GspStaticConfigInfo; - type InitError = Error; - - fn read( - msg: &Self::Message, - _sbuffer: &mut SBufferIter>, - ) -> Result { - let mut usable_fb_regions = KVec::new(); - for region in msg.usable_fb_regions() { - usable_fb_regions.push(region, GFP_KERNEL)?; - } - let total_fb_end = msg.total_fb_end().ok_or(EINVAL)?; - - Ok(GetGspStaticInfoReply { - gpu_name: msg.gpu_name_str(), - gpu_short_name: msg.gpu_short_name_str(), - gpu_gid: msg.gpu_gid(), - bar1_pde_base: msg.bar1_pde_base(), - usable_fb_regions, - total_fb_end, - }) - } -} - -/// Error type for [`GetGspStaticInfoReply::gpu_name`]. -#[derive(Debug)] -pub enum GpuNameError { - /// The GPU name string does not contain a null terminator. - NoNullTerminator(FromBytesUntilNulError), - - /// The GPU name string contains invalid UTF-8. - InvalidUtf8(Utf8Error), -} - -impl GetGspStaticInfoReply { - /// Returns the name of the GPU as a string. - /// - /// Returns an error if the string given by the GSP does not contain a null terminator or - /// contains invalid UTF-8. - pub fn gpu_name(&self) -> Result<&str, GpuNameError> { - CStr::from_bytes_until_nul(&self.gpu_name) - .map_err(GpuNameError::NoNullTerminator)? - .to_str() - .map_err(GpuNameError::InvalidUtf8) - } - - /// Returns the short name of the GPU as a string. - /// - /// Returns an error if the string given by the GSP does not contain a null terminator or - /// contains invalid UTF-8. - pub fn gpu_short_name(&self) -> core::result::Result<&str, GpuNameError> { - CStr::from_bytes_until_nul(&self.gpu_short_name) - .map_err(GpuNameError::NoNullTerminator)? - .to_str() - .map_err(GpuNameError::InvalidUtf8) - } - - /// Returns the total usable VRAM size in bytes, i.e. the summed lengths of all usable FB - /// regions. - pub fn vram_size(&self) -> u64 { - self.usable_fb_regions.iter().fold(0, |size, region| { - size.saturating_add(region.end - region.start) - }) - } -} - -pub(crate) use fw::commands::PowerStateLevel; - -/// The `UnloadingGuestDriver` command, used to shut down the GSP. -/// -/// Only used within the `gsp` module. -pub(super) struct UnloadingGuestDriver { - level: PowerStateLevel, -} - -impl UnloadingGuestDriver { - /// Creates a new `UnloadingGuestDriver` command for the given [`PowerStateLevel`]. - pub(super) fn new(level: PowerStateLevel) -> Self { - Self { level } - } -} - -impl CommandToGsp for UnloadingGuestDriver { - const FUNCTION: MsgFunction = MsgFunction::UnloadingGuestDriver; - type Command = fw::commands::UnloadingGuestDriver; - type Reply = UnloadingGuestDriverReply; - type InitError = Infallible; - - fn init(&self) -> impl Init { - fw::commands::UnloadingGuestDriver::new(self.level) - } -} - -/// The reply from the GSP to the [`UnloadingGuestDriver`] command. -pub(super) struct UnloadingGuestDriverReply; - -impl MessageFromGsp for UnloadingGuestDriverReply { - const FUNCTION: MsgFunction = MsgFunction::UnloadingGuestDriver; - type InitError = Infallible; - type Message = (); - - fn read( - _msg: &Self::Message, - _sbuffer: &mut SBufferIter>, - ) -> Result { - Ok(UnloadingGuestDriverReply) - } -} +pub(crate) mod rpc; diff --git a/drivers/gpu/nova-core/gsp/commands/rpc.rs b/drivers/gpu/nova-core/gsp/commands/rpc.rs new file mode 100644 index 000000000000..54c40f29e367 --- /dev/null +++ b/drivers/gpu/nova-core/gsp/commands/rpc.rs @@ -0,0 +1,333 @@ +// SPDX-License-Identifier: GPL-2.0 +// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + +use core::{ + array, + convert::Infallible, + ffi::FromBytesUntilNulError, + ops::Range, + str::Utf8Error, // +}; + +use kernel::{ + device, + pci, + prelude::*, + transmute::{ + AsBytes, + FromBytes, // + }, // +}; + +use crate::{ + gpu::Chipset, + gsp::{ + cmdq::{ + rpc::{ + CommandToGsp, + MessageFromGsp, // + }, + Cmdq, + NoReply, // + }, + fw::{ + self, + MsgFunction, // + }, + }, + sbuffer::SBufferIter, + vgpu::VgpuState, // +}; + +/// The `GspSetSystemInfo` command. +pub(crate) struct SetSystemInfo<'a> { + pdev: &'a pci::Device, + chipset: Chipset, +} + +impl<'a> SetSystemInfo<'a> { + /// Creates a new `GspSetSystemInfo` command using the parameters of `pdev`. + pub(crate) fn new(pdev: &'a pci::Device, chipset: Chipset) -> Self { + Self { pdev, chipset } + } +} + +impl<'a> CommandToGsp for SetSystemInfo<'a> { + const FUNCTION: MsgFunction = MsgFunction::GspSetSystemInfo; + type Command = fw::commands::GspSetSystemInfo; + type Reply = NoReply; + type InitError = Error; + + fn init(&self) -> impl Init { + Self::Command::init(self.pdev, self.chipset) + } +} + +struct RegistryEntry { + key: &'static str, + value: u32, +} + +/// The `SetRegistry` command. +pub(crate) struct SetRegistry { + entries: KVec, +} + +impl SetRegistry { + /// Creates a new `SetRegistry` command, using a set of hardcoded entries. + pub(crate) fn new(vgpu_state: VgpuState) -> Result { + let mut entries = KVec::new(); + + // RMSecBusResetEnable - enables PCI secondary bus reset + entries.push( + RegistryEntry { + key: "RMSecBusResetEnable", + value: 1, + }, + GFP_KERNEL, + )?; + + // RMForcePcieConfigSave - forces GSP-RM to preserve PCI configuration registers on + // any PCI reset. + entries.push( + RegistryEntry { + key: "RMForcePcieConfigSave", + value: 1, + }, + GFP_KERNEL, + )?; + + // RMDevidCheckIgnore - allows GSP-RM to boot even if the PCI dev ID is not found + // in the internal product name database. + entries.push( + RegistryEntry { + key: "RMDevidCheckIgnore", + value: 1, + }, + GFP_KERNEL, + )?; + + if matches!(vgpu_state, VgpuState::Enabled { .. }) { + // RMSetSriovMode - required when vGPU is enabled. + entries.push( + RegistryEntry { + key: "RMSetSriovMode", + value: 1, + }, + GFP_KERNEL, + )?; + } + + Ok(Self { entries }) + } +} + +impl CommandToGsp for SetRegistry { + const FUNCTION: MsgFunction = MsgFunction::SetRegistry; + type Command = fw::commands::PackedRegistryTable; + type Reply = NoReply; + type InitError = Infallible; + + fn init(&self) -> impl Init { + Self::Command::init(self.entries.len() as u32, self.size() as u32) + } + + fn variable_payload_len(&self) -> usize { + let mut key_size = 0; + for entry in self.entries.iter() { + key_size += entry.key.len() + 1; // +1 for NULL terminator + } + self.entries.len() * size_of::() + key_size + } + + fn init_variable_payload( + &self, + dst: &mut SBufferIter>, + ) -> Result { + let string_data_start_offset = size_of::() + + self.entries.len() * size_of::(); + + // Array for string data. + let mut string_data = KVec::new(); + + for entry in self.entries.iter() { + dst.write_all( + fw::commands::PackedRegistryEntry::new( + (string_data_start_offset + string_data.len()) as u32, + entry.value, + ) + .as_bytes(), + )?; + + let key_bytes = entry.key.as_bytes(); + string_data.extend_from_slice(key_bytes, GFP_KERNEL)?; + string_data.push(0, GFP_KERNEL)?; + } + + dst.write_all(string_data.as_slice()) + } +} + +/// Message type for GSP initialization done notification. +struct GspInitDone; + +// SAFETY: `GspInitDone` is a zero-sized type with no bytes, therefore it +// trivially has no uninitialized bytes. +unsafe impl FromBytes for GspInitDone {} + +impl MessageFromGsp for GspInitDone { + const FUNCTION: MsgFunction = MsgFunction::GspInitDone; + type InitError = Infallible; + type Message = (); + + fn read( + _msg: &Self::Message, + _sbuffer: &mut SBufferIter>, + ) -> Result { + Ok(GspInitDone) + } +} + +/// Waits for GSP initialization to complete. +pub(crate) fn wait_gsp_init_done(cmdq: &Cmdq<'_>) -> Result { + cmdq.await_msg::().map(|_| ()) +} + +/// The `GetGspStaticInfo` command. +pub(crate) struct GetGspStaticInfo; + +impl CommandToGsp for GetGspStaticInfo { + const FUNCTION: MsgFunction = MsgFunction::GetGspStaticInfo; + type Command = fw::commands::GspStaticConfigInfo; + type Reply = GetGspStaticInfoReply; + type InitError = Infallible; + + fn init(&self) -> impl Init { + Self::Command::init_zeroed() + } +} + +/// The reply from the GSP to the [`GetGspStaticInfo`] command. +pub struct GetGspStaticInfoReply { + gpu_name: [u8; 64], + gpu_short_name: [u8; 64], + /// The 16-byte SHA-1 based GPU identifier (GID) reported by GSP-RM. + pub gpu_gid: [u8; 16], + /// BAR1 Page Directory Entry base address. + pub(crate) bar1_pde_base: u64, + /// Usable FB (VRAM) regions for driver memory allocation. + pub(crate) usable_fb_regions: KVec>, + /// Exclusive end of the FB physical address space. + pub(crate) total_fb_end: u64, +} + +impl MessageFromGsp for GetGspStaticInfoReply { + const FUNCTION: MsgFunction = MsgFunction::GetGspStaticInfo; + type Message = fw::commands::GspStaticConfigInfo; + type InitError = Error; + + fn read( + msg: &Self::Message, + _sbuffer: &mut SBufferIter>, + ) -> Result { + let mut usable_fb_regions = KVec::new(); + for region in msg.usable_fb_regions() { + usable_fb_regions.push(region, GFP_KERNEL)?; + } + let total_fb_end = msg.total_fb_end().ok_or(EINVAL)?; + + Ok(GetGspStaticInfoReply { + gpu_name: msg.gpu_name_str(), + gpu_short_name: msg.gpu_short_name_str(), + gpu_gid: msg.gpu_gid(), + bar1_pde_base: msg.bar1_pde_base(), + usable_fb_regions, + total_fb_end, + }) + } +} + +/// Error type for [`GetGspStaticInfoReply::gpu_name`]. +#[derive(Debug)] +pub enum GpuNameError { + /// The GPU name string does not contain a null terminator. + NoNullTerminator(FromBytesUntilNulError), + + /// The GPU name string contains invalid UTF-8. + InvalidUtf8(Utf8Error), +} + +impl GetGspStaticInfoReply { + /// Returns the name of the GPU as a string. + /// + /// Returns an error if the string given by the GSP does not contain a null terminator or + /// contains invalid UTF-8. + pub fn gpu_name(&self) -> Result<&str, GpuNameError> { + CStr::from_bytes_until_nul(&self.gpu_name) + .map_err(GpuNameError::NoNullTerminator)? + .to_str() + .map_err(GpuNameError::InvalidUtf8) + } + + /// Returns the short name of the GPU as a string. + /// + /// Returns an error if the string given by the GSP does not contain a null terminator or + /// contains invalid UTF-8. + pub fn gpu_short_name(&self) -> core::result::Result<&str, GpuNameError> { + CStr::from_bytes_until_nul(&self.gpu_short_name) + .map_err(GpuNameError::NoNullTerminator)? + .to_str() + .map_err(GpuNameError::InvalidUtf8) + } + + /// Returns the total usable VRAM size in bytes, i.e. the summed lengths of all usable FB + /// regions. + pub fn vram_size(&self) -> u64 { + self.usable_fb_regions.iter().fold(0, |size, region| { + size.saturating_add(region.end - region.start) + }) + } +} + +pub(crate) use fw::commands::PowerStateLevel; + +/// The `UnloadingGuestDriver` command, used to shut down the GSP. +/// +/// Only used within the `gsp` module. +pub(crate) struct UnloadingGuestDriver { + level: PowerStateLevel, +} + +impl UnloadingGuestDriver { + /// Creates a new `UnloadingGuestDriver` command for the given [`PowerStateLevel`]. + pub(crate) fn new(level: PowerStateLevel) -> Self { + Self { level } + } +} + +impl CommandToGsp for UnloadingGuestDriver { + const FUNCTION: MsgFunction = MsgFunction::UnloadingGuestDriver; + type Command = fw::commands::UnloadingGuestDriver; + type Reply = UnloadingGuestDriverReply; + type InitError = Infallible; + + fn init(&self) -> impl Init { + fw::commands::UnloadingGuestDriver::new(self.level) + } +} + +/// The reply from the GSP to the [`UnloadingGuestDriver`] command. +pub(crate) struct UnloadingGuestDriverReply; + +impl MessageFromGsp for UnloadingGuestDriverReply { + const FUNCTION: MsgFunction = MsgFunction::UnloadingGuestDriver; + type InitError = Infallible; + type Message = (); + + fn read( + _msg: &Self::Message, + _sbuffer: &mut SBufferIter>, + ) -> Result { + Ok(UnloadingGuestDriverReply) + } +} -- 2.56.0