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.61.53 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796204627; b=MvlrMLEUG0Ije4BjhHlLuPRxPgRxXn2XevaK6eW3oz8z1cnsoD2cpfVPCOhnxAUBnosW FBGpbmu3gPtRMXEjGy3WtEFm/vabV7pN+/HbK0DAbUH2EV+NNU7hQGGZc6/UeF3s2+DTr 8FLML0nGuhXWq1Hd8eSIqFVzMMQJmhAcdtyEadaZnHRMGYps2qrHuIOgAlClsAa9DLcNn HHPGexbAlr+AlztkDZPNDH1aByW3Mojkc5xPtd3je0FhnkENWLtdearcDZpRhI0MbUDMd y/9pMKdGAs7HZ1pQyVh/xurgM0DtmomhYuu48vKFJ/lsN5/cNMK1bnjWI47kNnh0zHg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796204627; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: Received:From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:Content-Type: X-Originating-IP:X-ClientProxiedBy:X-EOPAttributedMessage: 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-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=txNXWmz6NB4sG6tSs2H+bQyZXTboq5/CHzI17OBnQu8=; b=EMY9rV5i9rl1DmMm4tOw76E1Z7FrA7M37cl2YzUz29fsRZYafoekArAi3TiFg6VAhwvv 7laNYo7Upt9svFqE0CN9Dczpqe21Jz2LhSfNR7XXE2LxjDw9ualri14xWhSEpPu/+vz/J Hb/kHJjJ6llVKKAhsShvN4ZTYcu2ywX7vHSUcHjhLF7qGAxe1lyEF7lcWbdWR2/oR6BN9 dM6BeTq6FrYgtaukCoXRkPGoGZv8Y6mQoqr0pd0/9cRfP8DFikU7lfbLhRgrFcqrBF0dl TGpuAv6r2x7eivGol2G1/W19xGjFUYYm0NQHOEijUW//M3EFNl8BcycKJJp4kTlBGLg== 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="KXx/3G1c"; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.61.53 Received: from DM1PR04CU001.outbound.protection.outlook.com (mail-centralusazon11010053.outbound.protection.outlook.com [52.101.61.53]) (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 6636C606A31A; Wed, 2 Dec 2026 09:43:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6636C606A31A 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=KXx/3G1c ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=seMF7JzafsfZ0GGhplees/6u6wZ43bL/dlFMFefmpUPjqZS8WlXP6CFhYCc0/Ruv+CBMjd+gTT04tJbJUryWwOCxuN8zcM+4DWXaAsBt5VcXnPCr78P0AGFzJnc7nra9sZBrptyC5hpX+D2F00MhcQTx3bE6sij23RXE+9RTBNtyYUrSUitNjFkD5nT9JiaYR+QSHEsM6xULWhmIK9PzixLsSqitlfDst5lhS/BDdGXup8TH+VIAgAiqRIN6ZnPoLCPGzdctomB+LKsJ+X7HG3+QgwUUdVdPs4L+VkUpLXoGJCG+Oi1dM2y57QkAroSITl9SHqWYJSWHkO+BM4aJiw== 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=txNXWmz6NB4sG6tSs2H+bQyZXTboq5/CHzI17OBnQu8=; b=J4jwsLU1Bp/xit83EPOYY/Pl8vTEtwNzZXVeni3CtPyMbbgrDps1T/0nVR0OdhvGiOe5leBJenmogv9qnAWGM8mnY+UOTzjdTBJtv/e20Iw8qne53M8KHwtRh4+op0qS/0LVthl5yW6i8SLjxa9IS9y3w6YEEfT71zSpnJo8C0uuJ0yRYxXpGloWDL7FZXr15yozHfCuBBl9dlDXpHLVEhpQJr8Rj5ItmVowOd7d/v1NM8ix5XKH+Xh7KR7y1JUUriYXDlsr97fGwVNry9HvvHYH/Eqlfe4wHYjcAQiti+K/rD7KjIgwjK+0Iz9p+YQSlHdRrpwVvkGqOyiRhAgCdg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) 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=txNXWmz6NB4sG6tSs2H+bQyZXTboq5/CHzI17OBnQu8=; b=KXx/3G1cg6D5wb0aXkoc/M/FO6FgwWGXznedP5WWC8LeIa2IhimQkndoiPUsSALMlKWos8saw/IO11WvqAjBr8xtkdgeqVCftUtR2xhTwBVbHGxDcA/dRU3LG7UWCnT3ffVffo2qUbscuBPMowU2X0BvcH66V7RXmGGTRB5pwZ5GxIy4nDy0tL9/JAqydfkK2UeRkfsPi9diKreBUC60pMm2Uifq+SpqzMVi/oSrvRfyT+QHBTemMUV4eEvX4XrDyMnlJUZYkEQ27UUst141VzGBZhCWJEnc7QAERcpfOmCw/KAgY5IiWJgwrbi2FxRAX0ZDmNuNmgMYOvUZUwjq6Q== Received: from CYXP220CA0012.NAMP220.PROD.OUTLOOK.COM (2603:10b6:930:ee::6) by AT6PR12MB496850.namprd12.prod.outlook.com (2603:10b6:170:116::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.11; Wed, 2 Dec 2026 09:43:39 +0000 Received: from MWH0EPF000DD30F.namprd05.prod.outlook.com (2603:10b6:930:ee:cafe::74) by CYXP220CA0012.outlook.office365.com (2603:10b6:930:ee::6) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.688.11 via Frontend Transport; Wed, 2 Dec 2026 09:43:38 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 216.228.117.160) 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.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by MWH0EPF000DD30F.mail.protection.outlook.com (10.167.249.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.5 via Frontend Transport; Wed, 2 Dec 2026 09:43:38 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Wed, 2 Dec 2026 01:43:20 -0800 Received: from kalok-SPC741D16QM3.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.57; Wed, 2 Dec 2026 01:43:07 -0800 From: Alok Kumar To: , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 1/1] gpu: nova-core: add fwctl driver for firmware control interface Date: Wed, 2 Dec 2026 15:12:19 +0530 Message-ID: <7c6ff97f631f11f29f76f1b2c30a6db55ca35b98.1796197508.git.alkumar@nvidia.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000DD30F:EE_|AT6PR12MB496850:EE_ X-MS-Office365-Filtering-Correlation-Id: 0dfa2370-8010-403e-e8c3-08df5058be2f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|7416014|36860700016|1800799024|23010399003|11063799006|6133799003|261009223027099003|3023799007|13003099007|22082099003|18002099003|260925022911599003|260925021311599003|260925021911599003|56012099006|10067099003|261102123227099003|261022075727099003|261022105027099003|261021121427099003|261022113327099003|261028144727099003|261026121527099003|261026140227099003; X-Microsoft-Antispam-Message-Info: R3rJ5y7HaVulPUmyNRQho+vJmuhvR7La5ttPQ1bXWUuFarDpOdhSRprpNqUr8yzLNyoFVc9rQAQXJQ4mOt7lwxl02Mk7jclM4q6/b7r5ggOqjY1djm/y+LQOxpqovpQQCT83gCN6x8uJqWvN8KdzGQ27rdVMMQypmmuHCTDf9xmlNTreBaoP26uxEsM4pyG0BhujnW+cAhDQ9ThMbyT9DR2+x73Jcgz6w05YOiIqRvGtY6MY9oYnjb4UQoext4eoT6MkoS0Dpl5S37M2vI2PouVsMUznrnp6jOyTa7+pOoMcCmJ1t+saTijpshdQHOxcryzDXpv9kcA9icfmJqvL4Kuzi1ijs09ZROx3bJjOEM0+5mEQ27ho1Pe0ikfGHEPg3zC72URULFeEhYofSIJFMifsAnHNiJnc7aXrZS/qyM9rXHHYe3CRgV5dSKUR5FxYmUKmf1TB2ZMySQelLYHcSZdKQEj/P5Qx0LG9NveMiNwzWrkPqffhPvgUpEPeK6R/JFv3VLUpEVDj5eLGMOu6JelHU8sI63aEr5WUuh7StliaNluP0tN5BneayP3ROkzrQOng0UK6wGXubbIdlN2/bAlYrrpTsARp5zm73CyjZqD9J9FpfGmWRyFoJ/dACkSjTm5iBX2T+eDBlQ5iUFIHq4hpRQf7rZ+NDBacihdRM0NC9VU8bdFwFqsfXXLlhsVRdTYgYQvpTJMZ2SmPSxUtqw== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(376014)(7416014)(36860700016)(1800799024)(23010399003)(11063799006)(6133799003)(261009223027099003)(3023799007)(13003099007)(22082099003)(18002099003)(260925022911599003)(260925021311599003)(260925021911599003)(56012099006)(10067099003)(261102123227099003)(261022075727099003)(261022105027099003)(261021121427099003)(261022113327099003)(261028144727099003)(261026121527099003)(261026140227099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /FtgIUZJBZODwLE3WPqmnv438mos8jTvDdW1AeBto/PS+Zb2DZYrr31zGqYF2ky0lOJZKpVpPHLVUY/bkYcpSsFh0KxcphHQu5AJvV9OnSpjh5DUZELGxa9olO6AGWHuyG9mEdpvbNrwMWf/kYQSQC9l/pisYIcb7v+bIiliWw59Ug3jS4i14U0/ZGoA9QaY0gw1k2nslf4nlarm6T7ojBwC2Gf8Q5AyxlEoOnLHyFWmwhWk2Y1Ii6QjmTUTQUe/ssMIotabYL/UQOLKcIS2GlKtVS+iewpcCSgM2rR/J6yYg1w4sw55BTEpAJQl1snW5aHhZwyGmhAtnO7AMWX3sWo6iTy7y51kPmUXHxOZh8rdCsopl5mYUfhY5luP69CzCAGPvPwSbDjAnSvhm8wvHl0R/EG0sPLmVNxv+Vy3Ebo3YkccvDcrDZ4iAAcTNQ85 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2026 09:43:38.7381 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0dfa2370-8010-403e-e8c3-08df5058be2f 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.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000DD30F.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AT6PR12MB496850 From: Zhi Wang Add a fwctl driver that provides an interface for userspace to issue GMC API commands to the GSP. Userspace supplies the command ID and payload while the transport headers remain internal to the kernel. Allow the seven vGPU management commands in the configuration scope. Reject all other commands and scopes. Signed-off-by: Zhi Wang Signed-off-by: Alok Kumar --- MAINTAINERS | 1 + drivers/gpu/nova-core/Kconfig | 2 + drivers/gpu/nova-core/driver.rs | 23 ++++ drivers/gpu/nova-core/fwctl.rs | 168 +++++++++++++++++++++++++++++ drivers/gpu/nova-core/gsp/fw.rs | 5 + drivers/gpu/nova-core/nova_core.rs | 2 + include/uapi/fwctl/fwctl.h | 1 + include/uapi/fwctl/nova-core.h | 34 ++++++ rust/kernel/fwctl.rs | 2 + rust/uapi/uapi_helper.h | 2 + 10 files changed, 240 insertions(+) create mode 100644 drivers/gpu/nova-core/fwctl.rs create mode 100644 include/uapi/fwctl/nova-core.h diff --git a/MAINTAINERS b/MAINTAINERS index 49b3d2d26e97..84bfc3ef2ae0 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8583,6 +8583,7 @@ C: irc://irc.oftc.net/nouveau T: git https://gitlab.freedesktop.org/drm/rust/kernel.git drm-rust-next F: Documentation/gpu/nova/ F: drivers/gpu/nova-core/ +F: include/uapi/fwctl/nova-core.h DRM DRIVER FOR NVIDIA GPUS [RUST] M: Danilo Krummrich diff --git a/drivers/gpu/nova-core/Kconfig b/drivers/gpu/nova-core/Kconfig index 2e11e46c99c7..3431cac7f3ba 100644 --- a/drivers/gpu/nova-core/Kconfig +++ b/drivers/gpu/nova-core/Kconfig @@ -4,8 +4,10 @@ config NOVA_CORE depends on PCI depends on RUST depends on !CPU_BIG_ENDIAN + depends on FWCTL=y select AUXILIARY_BUS select GPU_BUDDY + select RUST_FWCTL_ABSTRACTIONS select RUST_FW_LOADER_ABSTRACTIONS default n help diff --git a/drivers/gpu/nova-core/driver.rs b/drivers/gpu/nova-core/driver.rs index bea1b1b0844c..86f47016dcff 100644 --- a/drivers/gpu/nova-core/driver.rs +++ b/drivers/gpu/nova-core/driver.rs @@ -6,6 +6,7 @@ Bound, Core, // }, + fwctl, io::resource, pci, pci::{ @@ -24,6 +25,10 @@ use crate::{ api::NovaCoreApi, + fwctl::{ + NovaCoreFwCtl, + NovaCoreFwCtlData, // + }, gpu::Gpu, // }; @@ -35,6 +40,9 @@ pub(crate) struct NovaCore<'bound> { #[allow(clippy::type_complexity)] #[uses('gpu: invariant)] _reg: auxiliary::Registration<'gpu, ForLt!(NovaCoreApi<'_>)>, + /// Unregisters fwctl and drains its callbacks before GPU resources are dropped. + #[uses('gpu: invariant)] + _fwctl: fwctl::Registration<'gpu, NovaCoreFwCtl>, #[pin] #[uses('bar1)] pub(crate) gpu: Gpu<'bar>, @@ -152,6 +160,21 @@ fn probe<'bound>( NovaCoreApi::new(pdev, gpu), )? }, + + _fwctl: { + let fwctl_dev = fwctl::Device::::new(pdev.as_ref())?; + + // SAFETY: The device is newly allocated, unregistered, and parented to `pdev`. + // The self-referential borrow keeps `gpu` alive until fwctl is unregistered + // and its callbacks are drained. `NovaCore` is dropped before `pdev` unbinds. + unsafe { + fwctl::Registration::new( + pdev.as_ref(), + &fwctl_dev, + NovaCoreFwCtlData::new(gpu.get_ref().cmdq()), + )? + } + }, }) } } diff --git a/drivers/gpu/nova-core/fwctl.rs b/drivers/gpu/nova-core/fwctl.rs new file mode 100644 index 000000000000..76146f8fa60d --- /dev/null +++ b/drivers/gpu/nova-core/fwctl.rs @@ -0,0 +1,168 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! fwctl driver for nova-core GMC API pass-through. + +use core::convert::Infallible; + +use kernel::{ + fwctl::{ + self, + DeviceType, + FwRpcResponse, + RpcScope, // + }, + prelude::*, + transmute::{ + AsBytes, + FromBytes, // + }, + uapi, // +}; + +use crate::gsp::{ + cmdq::{ + gmc::{ + CommandPayload, + CommandToGsp, + MessageFromGsp, + MessagePayload, // + }, + Cmdq, + }, + GmcCommandId, +}; + +/// Resources used by fwctl callbacks while the GPU is bound. +#[pin_data] +pub(crate) struct NovaCoreFwCtlData<'a> { + cmdq: &'a Cmdq<'a>, +} + +impl<'a> NovaCoreFwCtlData<'a> { + pub(crate) fn new(cmdq: &'a Cmdq<'a>) -> impl PinInit { + try_pin_init!(Self { cmdq }) + } +} + +/// Per-file fwctl context for nova-core. +#[pin_data] +pub(crate) struct NovaCoreFwCtl {} + +impl fwctl::Operations for NovaCoreFwCtl { + type RegistrationData<'a> = NovaCoreFwCtlData<'a>; + + const DEVICE_TYPE: DeviceType = DeviceType::NovaCore; + + fn open<'a>( + _device: &fwctl::Device, + _reg_data: &Self::RegistrationData<'a>, + ) -> impl PinInit { + try_pin_init!(Self {}) + } + + fn fw_rpc<'a>( + _this: Pin<&Self>, + _device: &fwctl::Device, + reg_data: &Self::RegistrationData<'a>, + scope: RpcScope, + rpc_buf: &mut [u8], + _max_output_len: usize, + ) -> Result { + let (header, payload) = RpcHeader::from_bytes_copy_prefix(rpc_buf).ok_or(EINVAL)?; + let command_id = u32::from_le(header.0.command_id); + + if header.0.reserved != 0 { + return Err(EINVAL); + } + if !matches!(scope, RpcScope::Configuration) { + return Err(EPERM); + } + + let response = send_command(reg_data.cmdq, command_id, payload)?; + let response_len = size_of::() + .checked_add(response.len()) + .ok_or(EOVERFLOW)?; + let mut out = KVVec::with_capacity(response_len, GFP_KERNEL)?; + out.extend_from_slice(header.as_bytes(), GFP_KERNEL)?; + out.extend_from_slice(&response, GFP_KERNEL)?; + + Ok(FwRpcResponse::NewBuffer(out)) + } +} + +/// UAPI request/response header copied independently of the input buffer's alignment. +#[repr(transparent)] +struct RpcHeader(uapi::fwctl_rpc_nova_core); + +// SAFETY: The UAPI structure only contains two `u32` fields, so all bit patterns are valid +// and it has no interior mutability. +unsafe impl FromBytes for RpcHeader {} + +// SAFETY: The UAPI structure is `repr(C)` with two consecutive `u32` fields and no padding. +// The wrapper is transparent and contains no kernel pointers or interior mutability. +unsafe impl AsBytes for RpcHeader {} + +const GSP_GMC_MAX_RESPONSE_SIZE: u32 = 16_384; + +/// Firmware response bytes copied out before the message queue slot is consumed. +struct Response(KVec); + +impl MessageFromGsp for Response { + type InitError = Error; + + fn read(payload: &mut MessagePayload<'_>) -> Result { + payload.flush_into_kvec(GFP_KERNEL).map(Self) + } +} + +// Define typed requests and the exact command allowlist together. +macro_rules! fwctl_commands { + ($($command:ident),+ $(,)?) => { + $( + struct $command<'a>(&'a [u8]); + + impl CommandToGsp for $command<'_> { + const COMMAND: GmcCommandId = GmcCommandId::$command; + type Command = (); + type Reply = Response; + const MAX_REPLY_SIZE: u32 = GSP_GMC_MAX_RESPONSE_SIZE; + type InitError = Infallible; + + fn init(&self) -> impl Init { + pin_init::init_zeroed() + } + + fn variable_payload_len(&self) -> usize { + self.0.len() + } + + fn init_variable_payload(&self, dst: &mut CommandPayload<'_>) -> Result { + dst.write_all(self.0) + } + } + )+ + + fn send_command(cmdq: &Cmdq<'_>, command_id: u32, payload: &[u8]) -> Result> { + // CAST: `GmcCommandId` is `repr(u32)`, so these casts are lossless. + match command_id { + $( + id if id == GmcCommandId::$command as u32 => cmdq + .send_gmc_command($command(payload), |_| Ok(()))? + .map(|response| response.0) + .map_err(|_| EIO), + )+ + _ => Err(EPERM), + } + } + }; +} + +fwctl_commands! { + AddVgpuType, + QuerySupportedVgpuTypes, + QueryCreatableVgpuTypes, + AssignVgpuType, + DeassignVgpuType, + QueryVgpuProperties, + QueryAssignedVfVgpuType, +} diff --git a/drivers/gpu/nova-core/gsp/fw.rs b/drivers/gpu/nova-core/gsp/fw.rs index 0ea27cb547b4..764318eaca69 100644 --- a/drivers/gpu/nova-core/gsp/fw.rs +++ b/drivers/gpu/nova-core/gsp/fw.rs @@ -716,6 +716,11 @@ pub(crate) enum GmcCommandId with TryFrom> { ExecGenericBootloader = bindings::GMCAPI_COMMANDS_GMCAPI_CMD_EXEC_GENERIC_BOOTLOADER, ExecHsBinary = bindings::GMCAPI_COMMANDS_GMCAPI_CMD_EXEC_HS_BINARY, GspSuspend = bindings::GMCAPI_COMMANDS_GMCAPI_CMD_GSP_SUSPEND, + AddVgpuType = bindings::GMCAPI_COMMANDS_GMCAPI_CMD_ADD_VGPU_TYPE, + QuerySupportedVgpuTypes = bindings::GMCAPI_COMMANDS_GMCAPI_CMD_QUERY_SUPPORTED_VGPU_TYPES, + QueryCreatableVgpuTypes = bindings::GMCAPI_COMMANDS_GMCAPI_CMD_QUERY_CREATABLE_VGPU_TYPES, + AssignVgpuType = bindings::GMCAPI_COMMANDS_GMCAPI_CMD_ASSIGN_VGPU_TYPE, + DeassignVgpuType = bindings::GMCAPI_COMMANDS_GMCAPI_CMD_DEASSIGN_VGPU_TYPE, QueryVgpuProperties = bindings::GMCAPI_COMMANDS_GMCAPI_CMD_QUERY_VGPU_PROPERTIES, QueryAssignedVfVgpuType = bindings::GMCAPI_COMMANDS_GMCAPI_CMD_QUERY_ASSIGNED_VF_VGPU_TYPE, BootloadGspVgpuPluginTask = diff --git a/drivers/gpu/nova-core/nova_core.rs b/drivers/gpu/nova-core/nova_core.rs index 418571724543..b2cb11c0a4d2 100644 --- a/drivers/gpu/nova-core/nova_core.rs +++ b/drivers/gpu/nova-core/nova_core.rs @@ -17,6 +17,7 @@ mod fb; mod firmware; mod fsp; +mod fwctl; mod gpu; mod gsp; mod irq; @@ -98,6 +99,7 @@ fn init(module: &'static kernel::ThisModule) -> impl PinInit { description: "Nova Core GPU driver", license: "GPL v2", firmware: [], + imports_ns: ["FWCTL"], params: { gsp_keep_logs: bool { default: false, diff --git a/include/uapi/fwctl/fwctl.h b/include/uapi/fwctl/fwctl.h index 2d6d4049c205..0e336cbbeb6b 100644 --- a/include/uapi/fwctl/fwctl.h +++ b/include/uapi/fwctl/fwctl.h @@ -46,6 +46,7 @@ enum fwctl_device_type { FWCTL_DEVICE_TYPE_CXL = 2, FWCTL_DEVICE_TYPE_BNXT = 3, FWCTL_DEVICE_TYPE_PDS = 4, + FWCTL_DEVICE_TYPE_NOVA_CORE = 8, }; /** diff --git a/include/uapi/fwctl/nova-core.h b/include/uapi/fwctl/nova-core.h new file mode 100644 index 000000000000..c11619660058 --- /dev/null +++ b/include/uapi/fwctl/nova-core.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES + * + * NVIDIA nova-core fwctl interface. All fwctl traffic uses the GMC API + * transport. User-space supplies a command_id and optional payload; the + * kernel constructs the GMC transport headers, validates the command_id + * against the permitted set for the requested scope, and returns only the + * response payload. + * + * The device_type for this file is FWCTL_DEVICE_TYPE_NOVA_CORE. + */ +#ifndef _UAPI_FWCTL_NOVA_CORE_H +#define _UAPI_FWCTL_NOVA_CORE_H + +#include + +/** + * struct fwctl_rpc_nova_core - ioctl(FWCTL_RPC) in/out buffer format + * @command_id: GMC API command identifier (from GMCAPI_COMMANDS). + * @reserved: Must be zero. + * + * The request buffer passed to FWCTL_RPC begins with this header, + * followed by the command-specific payload bytes (if any). + * + * The response buffer returned by FWCTL_RPC begins with this same + * header (echoing the command_id), followed by the response payload. + */ +struct fwctl_rpc_nova_core { + __u32 command_id; + __u32 reserved; +}; + +#endif diff --git a/rust/kernel/fwctl.rs b/rust/kernel/fwctl.rs index b7778e4d5ee0..92e1cdf6da2d 100644 --- a/rust/kernel/fwctl.rs +++ b/rust/kernel/fwctl.rs @@ -44,6 +44,8 @@ pub enum DeviceType { Pds = bindings::fwctl_device_type_FWCTL_DEVICE_TYPE_PDS, /// Broadcom NetXtreme (bnxt) device. Bnxt = bindings::fwctl_device_type_FWCTL_DEVICE_TYPE_BNXT, + /// NVIDIA nova-core GPU device. + NovaCore = bindings::fwctl_device_type_FWCTL_DEVICE_TYPE_NOVA_CORE, } /// Scope of access for an RPC request. diff --git a/rust/uapi/uapi_helper.h b/rust/uapi/uapi_helper.h index 44fb6203c0ad..428a756a9b5c 100644 --- a/rust/uapi/uapi_helper.h +++ b/rust/uapi/uapi_helper.h @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include #include #include