From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from CH1PR05CU001.outbound.protection.outlook.com (mail-northcentralusazon11010043.outbound.protection.outlook.com [52.101.193.43]) (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 BC9A73D75DE; Sun, 27 Sep 2026 11:15:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.193.43 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790507718; cv=fail; b=NGtEIP8qGr2X4VnAzjPjjmw8Q4eQUdO5ZrM04o5SW/ks8xI2cijFMAMCsdDBCtzmj4OX4PIwRUawQ6HGbfLokOhA5FjTW5ITucAQD+jC6F355mgVG8zHykcfq7On34gKtULxqL8uxnpxT+X3XnrVrDLtlbNJGgLHQX0zMCDr+88= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790507718; c=relaxed/simple; bh=ICagNnqC6+jJJAUi6X9cxNJ+Dyj6UqatvEWg6HhV8jg=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=WuEd3ge41s59T8EfT6Tw1C8UHb0IXH6ThJQOsarcX4WuX8rPE49Bnelu8rxZoUtF2P9P6WFnJWUjJ1/JbupBjmemq9hl1rRqxnzA7faUQOkR8iik5AVzQ89EF8GTFe+ZEHqvaL26Sb0EA3uPVPZwLCDiMBj2PBC7d2foXIx4/Dk= 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=s07GPqd8; arc=fail smtp.client-ip=52.101.193.43 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="s07GPqd8" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=SrGG2LazteDT1ZRzj4wVZ+ZXgfjgkH+RROfsRPDFC4khoRSfFfLVAWGancVOWrmjpbPpy+LIfEIDiUW4D0RAu+24yu1a8FrHAqyiD8lwqDZ4aiIAHAChZNe4/FQxZD4/pa8+qPjCzGp3T30laOI252nyCygNKait2/zmC4y7oGjklEPy73GqfTTadybytEMiWr3C7cxZ6JsQbyHOqGhI4a8v7yKBMXKn+lLmTpkyo6y9jA6PeSEbJCIv+6xSg4vODxU7v5gIJ8tAhMCWAs9RjPpEFhLqqbCjpsT7467A1y1/mLiSiFnphmPWdxUzefeGiZYk8uurRue2gEyrggVTXw== 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=0rd2wrTncN4iYab2ghP93bX6ow/+czgZBbtXHT7hn0s=; b=Oty0jFIPEz3pPHZG7AC/lRc4m/oJOYNEnUgHhVUj4TKOgcCcq42hMbe0RlV00QWqVhBjucQE5aChT/XZ8MfOqSAGm29qpu4HHWu4/QC/aaAXziIZpq1D5FYjYbeLZ6cTLX8BzSZXx2w4wlyiQe33tWIJ9ezyefZXez7PKoQ82+41VaVoVGes4hdhyspN2cu2TJlXufl4/HjLq5nMZaECcCNYdPJkMaPNbk7AazQg6DKxPU/tf9Sw+GK1Iqsgsgd7qmy9UawefqXU/Bq6j5YlrBRJdw/VsduMWZsczUbd2qeRi8F0NaZw7rRd49fQvlZWH5pqUVLINGxWST7W0wMy4w== 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=0rd2wrTncN4iYab2ghP93bX6ow/+czgZBbtXHT7hn0s=; b=s07GPqd8Tc7QRexNNjEH1RcCK0Lz4iyHCTevMQlkazMGFvUasS7O/4o/s4HqP1YxJsRkooB+BIMMoayhLgXaQ6IzaKg+fBqpqTHO62BH1SSn8rOc336QWQfGq37cJ9Njxxn/jEbosRVCW3HWqvSxhHHBChFX8mzFifVV1dHcDdbk/YgiNUj/yTbddJBZ39upU3xz1mttTPI4VVmfBzh8HbMgIix7ZpfhDGdbHM0sPKmiZ4VDSgv1sw1T1U21D8xogvtGOBChGumebirdb6QVFOmCey2IgSDUzhYwRKAWm7Sb0S5xxzdz7JUmDoUBs4nQ7xJqSCcdZv6vDOBuRMO73A== 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 LV8PR12MB9154.namprd12.prod.outlook.com (2603:10b6:408:190::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.451.23; Sun, 27 Sep 2026 11:14:56 +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.0451.022; Sun, 27 Sep 2026 11:14:56 +0000 From: Alexandre Courbot Date: Sun, 27 Sep 2026 20:14:31 +0900 Subject: [PATCH 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: <20260927-cmdq-rpc-v1-9-822db5af910e@nvidia.com> References: <20260927-cmdq-rpc-v1-0-822db5af910e@nvidia.com> In-Reply-To: <20260927-cmdq-rpc-v1-0-822db5af910e@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: TY4PR01CA0051.jpnprd01.prod.outlook.com (2603:1096:405:372::19) 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_|LV8PR12MB9154:EE_ X-MS-Office365-Filtering-Correlation-Id: 9c3ee3be-52fd-45c3-7592-08df1c888f75 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|7416014|376014|10070799003|23010399003|6133799003|22082099003|18002099003|10067099003|3023799007|56012099006|11063799006; X-Microsoft-Antispam-Message-Info: ngCC70eG7AmtcZVCeHBRSaANceEnegrWA0N4jlTw2qwHhrhLFmPeZpYPX1c6SZ7mScXWl102ACpDK0dfoHDatltnlxwdWHwc62Q6RD1PGZk2cRVkan+xt7rS49CSJPaWb0BIKeoc8+uqHLwdGoKIgqG8cfAGltuVHXgJwu6rRZtPrhpVPpmFzbiyRcmZ/JjNF1aV7lGdcLbBz/nDgQKofRFrqYQxRTYf+eF/1vTzDfd64yz6ynGgEQjqHeR/94+sxgUzGuzJ6LzMhDBG2I+94kFzLYa3wGteY5IHtnThsoWz3xxGF2fHSQwwIVvBT5gGg81h5Yy7X99UbRhBKODl/Go+HHoixZoCBK9zozFFCRDJJZrERvJyiC9fLhCCZ4zQLDgvIVKtw0APHYMSnj0FQWcGK6N8T3pvYQ9LIqYDtbUkA6eiXajeS7GhVxzaoOWCkgLWMb7r0UL5kTybGiaWQKjoiXUqHjePvVzIygVJWAFnW15ps5b4QTKxWpLL2EdM01Spmht5P1+awMKWz7dIrt2ZB8f4eWgsesH2M3P8ZSmagQOJ+xt+PJMbBeBvIFnFWY4LWuweAv4ZMvdeh/A450CXCat3GDGPVTM7j67wrixHhiFrlWikcAr2HNkvfE8diG3DUhuDSiK8RxQdnrTZHU1OuGNz1WeZCercnenUeMI= 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)(366016)(1800799024)(7416014)(376014)(10070799003)(23010399003)(6133799003)(22082099003)(18002099003)(10067099003)(3023799007)(56012099006)(11063799006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?RTBkaTdkM01RQlJ0bFRZODdzV1FFdW1uMGpCb24yM3d4UHlUK040aThMeE1z?= =?utf-8?B?dWhlRDlNOW9DN0hkOUJrT1JjVldjRjZSS2s2elBjTmEwSFJKcHRocmJJK0hH?= =?utf-8?B?U3lkaDBGdVFYS0s3dWRKc3ZiYzJUd1FZSDRZU3lLUEtXSFk1dS9KSmFLeTg3?= =?utf-8?B?MFYrdDV2N3IyUzJGNFJ1Y2UvWFBFbkI3eUVpTGJOaFVvczQ0RzNjUTFsa3g5?= =?utf-8?B?ZUIrQWFqL2x2MFBxNU5ac2t3K3kreWErM1czcGJZcENXMXBuNWtGeGVMUGZV?= =?utf-8?B?dlZIQnZRRDFLcW1Gdml1bFp6ODlvZ3ZrMkRBSzBtTmZLM05TS1pqaEIzOEZj?= =?utf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HRZYVQ4UTNhT2E2dEl1bzdDNjgwNkplZ1du?= =?utf-8?B?ZXdKZUY0UWp6ZUJKK2lOa0xDd3FXazdyajh4Rmw1TFd3VGV2TW5IVVRyTWw1?= =?utf-8?B?UlFCd2F4TXBjaFBqV0dYQUVHNWZNM1hqVC9kMlpWc0dzZHJXMWIzcXRGUnp1?= =?utf-8?B?cUd4REEySjRsL1VLdEIzMkVSOGRlUHRCREZPdi8yUmZvaGE2WmNPL3JnZW5q?= =?utf-8?Q?/l6+nQieaczkfkLyZXFsnKLD5eMZ9ZIroRGmWpdbD2uJZ?= X-MS-Exchange-AntiSpam-MessageData-1: 6nL+haImJmuoKg== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9c3ee3be-52fd-45c3-7592-08df1c888f75 X-MS-Exchange-CrossTenant-AuthSource: MW4PR12MB6873.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Sep 2026 11:14:56.2590 (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: 8jTcUmquF6y+A8mjdW/fy96oHG1eR+L0sxfb+joYu1kxBfdN//hs7C7Ge3MlFw9r2pPWO/C4r1UjRHbgFMPQ+A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9154 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 --- 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 | 314 +---------------------------- drivers/gpu/nova-core/gsp/commands/rpc.rs | 316 ++++++++++++++++++++++++++++++ 5 files changed, 326 insertions(+), 322 deletions(-) diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs index 8f30186f10ba..b6c691361895 100644 --- a/drivers/gpu/nova-core/gpu.rs +++ b/drivers/gpu/nova-core/gpu.rs @@ -34,7 +34,7 @@ fsp::Fsp, gsp::{ self, - 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 81bd457a6eb6..5f1c944678be 100644 --- a/drivers/gpu/nova-core/gsp/commands.rs +++ b/drivers/gpu/nova-core/gsp/commands.rs @@ -1,316 +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 { - loop { - match cmdq.receive_msg::(Cmdq::RECEIVE_TIMEOUT) { - Ok(_) => break Ok(()), - Err(ERANGE) => continue, - Err(e) => break Err(e), - } - } -} - -/// 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(crate) struct GetGspStaticInfoReply { - gpu_name: [u8; 64], - /// 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(), - bar1_pde_base: msg.bar1_pde_base(), - usable_fb_regions, - total_fb_end, - }) - } -} - -/// Error type for [`GetGspStaticInfoReply::gpu_name`]. -#[derive(Debug)] -pub(crate) enum GpuNameError { - /// The GPU name string does not contain a null terminator. - NoNullTerminator(FromBytesUntilNulError), - - /// The GPU name string contains invalid UTF-8. - #[expect(dead_code)] - 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(crate) fn gpu_name(&self) -> core::result::Result<&str, GpuNameError> { - CStr::from_bytes_until_nul(&self.gpu_name) - .map_err(GpuNameError::NoNullTerminator)? - .to_str() - .map_err(GpuNameError::InvalidUtf8) - } -} - -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..a3262cc3e0e9 --- /dev/null +++ b/drivers/gpu/nova-core/gsp/commands/rpc.rs @@ -0,0 +1,316 @@ +// 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 { + loop { + match cmdq.receive_msg::(Cmdq::RECEIVE_TIMEOUT) { + Ok(_) => break Ok(()), + Err(ERANGE) => continue, + Err(e) => break Err(e), + } + } +} + +/// 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(crate) struct GetGspStaticInfoReply { + gpu_name: [u8; 64], + /// 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(), + bar1_pde_base: msg.bar1_pde_base(), + usable_fb_regions, + total_fb_end, + }) + } +} + +/// Error type for [`GetGspStaticInfoReply::gpu_name`]. +#[derive(Debug)] +pub(crate) enum GpuNameError { + /// The GPU name string does not contain a null terminator. + NoNullTerminator(FromBytesUntilNulError), + + /// The GPU name string contains invalid UTF-8. + #[expect(dead_code)] + 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(crate) fn gpu_name(&self) -> core::result::Result<&str, GpuNameError> { + CStr::from_bytes_until_nul(&self.gpu_name) + .map_err(GpuNameError::NoNullTerminator)? + .to_str() + .map_err(GpuNameError::InvalidUtf8) + } +} + +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.55.0