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.26 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796200660; b=qtTFLFU7W79BUO+qkcMhP+SGNGYbne5FIApEfJUz+3ynDYyj7Q+I9fIeIWC2JJauwWT/ WgsqfAOC0p3MTkbsT1TswAUiO8c6mQ7FLvdWupyUVFmRbgE520q7pS0ZvjAff7j4aZ7vH gKBS9k4vG298aNzRb+oW8P+VBABLGIAlbHST/a0eKaDToesrllMmyKNUxYllT2WnIDBNr aT9TbDATcBVnj4UQdcs+2ivUoW2QkXDRgWZJrGm8w1i+7WrUTVjI6Kg+vfwCnPtKTblOk ArVK6wgLptIE+9irbf7U1sZYthWM3MdgNNTU4uVNfr65M7zlvk+UgFkBgZd2GIIFdYg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796200660; 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=nBygnJVqUN3kPPOk5wRVeAmOz3gCSl0VEnM4XLh4Wd0=; b=V1YYQD+2whFeMZYJkVF3OH7JlpcjvWmrXPNglcytrulNVXhvnQJDnU/r/oRExF8slTV5 F6IgYiL8TwAZ8GLZonbdeXednvtlQ8GGf+rTzn0lGtM6i+sFLMIBLrHMoi1rlKlP7Qwvg w96XmTnblRuHPtP1mlmclGe9qDSxMZ7NEI1l59BmoiPT5Zg5sDUDutr97R/PkF7imSZMI aZs4SJUFCmO4ht3hQNuskFA5QesWYInj0t1KpH5uGBTKMcNPRrokm4zvTSiaZM9zTWaVB 2PTxmOHIsRNmhj134z5H1TlpfDHOtbezLKOyLEPaOep2/Memh+/m5X78bgtpwU2/iaQ== 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=aWmPpcho; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.61.26 Received: from DM1PR04CU001.outbound.protection.outlook.com (mail-centralusazon11010026.outbound.protection.outlook.com [52.101.61.26]) (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 D2751606A31A; Wed, 2 Dec 2026 08:37:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D2751606A31A 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=aWmPpcho ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qLqkx1nTaq+oId44QaSvDIFFj5gD0O48VVh7PDIRhbpbl5pm5YINMIg+6a3bUqGWm9QFUP/sVgga70i+lUy1H/25/9FkbKmsdIIU3BByBskg4LSXFraDto3RLU0ycig84EdgNC1SSj9oqxUdEtYltzcy+XzN0vT55A1MzYQYOGaUl3SQIoSPbgU0e6jZVASA30rwShHH+GJzrY5oT+9rXNJJgHirmMKAaeRRmjNFRmFT9pxkitSMsS8/2/w8PXESw+6DP7uUYWIxcX+z2YsRkzt+PA1VSBp0vyvgE3WePn3KxSxAmyj4XDAujsD8hKKDvB90o/HMQO67eejSs4iAVw== 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=nBygnJVqUN3kPPOk5wRVeAmOz3gCSl0VEnM4XLh4Wd0=; b=CPegqf+iQmfqWdN5GPmhZbdHV0ryIXZUECelvn8ApAexRPPMajn2hnWazmaVUTb/TC6VF0TgvVM90OmSuR0NIqOvuno7NQL0NEOMv4CupjGNm7ifr7YDiTLht+djy20vyg1kmHp7RoucPXlqFBqZDHYpiSZdSsTLM/klcl/bMlYjc2NSvss9NE9obOzFDCWt2bX+7+FAUXA8d7zGnWZupbOQIDDaPqx7j3CD9fMY6jUeOvvePhBrKTJR96EGGWWIXY+8nL3W8XRPqVKD2zDsSWCZIj5SHaC9RsdU5KMjuzN8UdFH4wzcoxnA7bGXu4AI8ollgCXnolENeNQrsgyEOQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nBygnJVqUN3kPPOk5wRVeAmOz3gCSl0VEnM4XLh4Wd0=; b=aWmPpcho8tbWQjg+8QWHTUwEWTo6SGKzOdfJS4qtHkVmqYmGLCo/SMcJOz3sIO1PUhIUlnF20WJk7bvSctkxPmf67B+Q1+gy5NZChzQ+LzLddwu0KNFIvbBWNCjvo0Lm9c1Sfvz36dxCAnwodFFjBR/10DvxoVCXZuR8wN0hL4FDGIWFLTalpmrzsVlKQ/VCVdiBWs0sFut5HixjUIbJTX9hk3BIUQSROnURW9+HGp4zLVIVhFw+CKzBBMPaPOUNKhQLxQonJ9SItGs8qXo4h8Mrde9xeEfurvDM38SdKKV1aektDF0OO9i36UCRBY0LMtTsy+yERf4fDhAuBcqd0w== Received: from CH0PR03CA0238.namprd03.prod.outlook.com (2603:10b6:610:e7::33) by IA1PR12MB6137.namprd12.prod.outlook.com (2603:10b6:208:3eb::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Wed, 2 Dec 2026 08:37:32 +0000 Received: from LV8PEPF00000059.namprd02.prod.outlook.com (2603:10b6:610:e7:cafe::c) by CH0PR03CA0238.outlook.office365.com (2603:10b6:610:e7::33) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.662.13 via Frontend Transport; Wed, 2 Dec 2026 08:37:32 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by LV8PEPF00000059.mail.protection.outlook.com (10.167.245.133) 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 08:37:32 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Wed, 2 Dec 2026 00:37:10 -0800 Received: from kalok-SPC741D16QM3.nvidia.com (10.126.231.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 00:36:56 -0800 From: Alok Kumar To: , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v6 21/34] gpu: nova-core: vgpu: query VF assignments and properties Date: Wed, 2 Dec 2026 13:58:45 +0530 Message-ID: <3c007bb2a13cd7120a30a03e40007b1902b4e527.1796191007.git.alkumar@nvidia.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: X-Mailing-List: rust-for-linux@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: LV8PEPF00000059:EE_|IA1PR12MB6137:EE_ X-MS-Office365-Filtering-Correlation-Id: 0397a9cd-69d7-4de0-1b45-08df504f8216 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|82310400026|1800799024|7416014|376014|36860700016|11063799006|18002099003|6133799003|261009223027099003|3023799007|22082099003|10067099003|56012099006|261021135927099003|261021121427099003|261026121527099003|261021123027099003|261028144727099003|261102123227099003|261026140227099003|261022075727099003|261022113327099003|261022105027099003; X-Microsoft-Antispam-Message-Info: 4R0CvWuaFvCPUK/KhCF5J1VYCCQiit8e4RDgQirb+zjucYl+FgQmxtwjydCDVZcR63KLirGWaQrziYV5CyyGkI2xWVnfnmz8UCGIeZCgrYxBi6s+U9iKEPtbLP5cf1JZlYjFi7UYIxSnKC1CYErk0W+yN7Mb53wk7vwl3K0Y1/W701VegvY9qPGlZi2uMLIGwZLfyQt8v+s1ZI6kPa/43VZmebNzO6cCPXa7qBDlsfK5bIFNTVQrKaEOwpKWnMs5IEp41uQRdCPvmMK2bDYVn1QLH+5mXRgCBWo+mtCOA2AJW2c0J/RV8GdLjRQf/DkO+Zh4gWbcBohEUfNiFcqu7hIYNZ+rdECCu+DohGLDWop9tbZwOEaI//+yfY6NMD2trEydcqkx1jvZRyTelH7eeS7+J8tJqVhA+yU9PuRl96GmipQvnB+CY0qGZJ25R0H2y4cmH2SwhVlC2DD+Lwm8hnqb1exkHY7Q1wKMC6Z5KdIBgUFHjG5xqs4r+grwS5JxGK0RxgsfW8EWZJ5XFqiPvT8ahByyJdIbi3aY+sgKWVtSXiRJiMNYDgK/Od7EfwQ/aXIF/dlvuPb3tWNI+vIbk7ERvcOpqQHbBAA89y6Oyni4vtQEHhLXggoUQGs+l21oASUxDUJ4uGpq0Et5oaYIME94npoDrX2EFSOz7w+ynQVYc7Bg+YlVf2Rc8CWn0B0fTxHdDIyh+G/XQVBdJTtK4A== X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(23010399003)(82310400026)(1800799024)(7416014)(376014)(36860700016)(11063799006)(18002099003)(6133799003)(261009223027099003)(3023799007)(22082099003)(10067099003)(56012099006)(261021135927099003)(261021121427099003)(261026121527099003)(261021123027099003)(261028144727099003)(261102123227099003)(261026140227099003)(261022075727099003)(261022113327099003)(261022105027099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rt1i4EKVUMh7pNSgycqOyWGJoczTPrtB8tL8YkQRvmz/bMq1Qb27VV0OLStoOrolkVkznOqUO9NL8H0V6rAqvsaRqNHqu+ANfXWYsOrNsTvBLfxL08UIO4REZ6vahLuD/6VNKT9Wd/p5AJ7ODXp/pKLugfrmIMFVQ89uV8YdT8790t8y4DCdvfuFRf0QczDs3hrQuJOMBwhQyKQky8nhgenqlSMjjry7U2VpDynjX7oybCS8FVZ3sz+vMT8o6iXy8lv0BxwpE9jcPvjv0O0J2TJSHV9ih9pi373X739+JpTybOQMfPjOWfZfPucMlH5M12+Mjzpe0ZSkIqbKcLN9szjCzxnbviINq5enPg36VtuNJl4sW43Dv0vyIM7nyNec4D2m2YUwpQMmco5s7EZbU0zJU7N3PdNpVBhgjAoDKrER4a9xF/mZZ6XN7rVX6+du X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2026 08:37:32.3659 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0397a9cd-69d7-4de0-1b45-08df504f8216 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: LV8PEPF00000059.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6137 From: Zhi Wang Creating an instance requires its VF assignment and the corresponding vGPU properties before reserving resources. Decode the VF assignment and NVKV property replies at their query entry points. Validate the returned type ID and nonzero instance limit, and initialize the decoded properties on the heap. Co-developed-by: Eliot Courtney Signed-off-by: Eliot Courtney Co-developed-by: Alexandre Courbot Signed-off-by: Alexandre Courbot Signed-off-by: Zhi Wang Signed-off-by: Alok Kumar --- drivers/gpu/nova-core/gsp.rs | 1 + drivers/gpu/nova-core/gsp/fw.rs | 2 +- drivers/gpu/nova-core/sbuffer.rs | 7 ++ drivers/gpu/nova-core/vgpu.rs | 11 ++ drivers/gpu/nova-core/vgpu/commands.rs | 126 ++++++++++++++++++++++ drivers/gpu/nova-core/vgpu/fw.rs | 6 ++ drivers/gpu/nova-core/vgpu/fw/commands.rs | 75 +++++++++++++ 7 files changed, 227 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/nova-core/vgpu/commands.rs create mode 100644 drivers/gpu/nova-core/vgpu/fw/commands.rs diff --git a/drivers/gpu/nova-core/gsp.rs b/drivers/gpu/nova-core/gsp.rs index 84a76c1c39cd..66e08cbb75a8 100644 --- a/drivers/gpu/nova-core/gsp.rs +++ b/drivers/gpu/nova-core/gsp.rs @@ -29,6 +29,7 @@ pub(crate) use logbuffer::RetainedLogs; pub(crate) use fw::{ + GmcCommandId, GspFmcBootParams, GspFwWprMeta, LibosMemoryRegionInitArgument, diff --git a/drivers/gpu/nova-core/gsp/fw.rs b/drivers/gpu/nova-core/gsp/fw.rs index 7a2a45192c9a..0ea27cb547b4 100644 --- a/drivers/gpu/nova-core/gsp/fw.rs +++ b/drivers/gpu/nova-core/gsp/fw.rs @@ -2,7 +2,7 @@ // SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. pub(crate) mod commands; -mod r000_00; +pub(crate) mod r000_00; // Alias to avoid repeating the version number with every use. use r000_00 as bindings; diff --git a/drivers/gpu/nova-core/sbuffer.rs b/drivers/gpu/nova-core/sbuffer.rs index b8c01104c255..fd410aef2a1f 100644 --- a/drivers/gpu/nova-core/sbuffer.rs +++ b/drivers/gpu/nova-core/sbuffer.rs @@ -161,6 +161,13 @@ pub(crate) fn read_exact(&mut self, mut dst: &mut [u8]) -> Result { Ok(()) } + pub(crate) fn read(&mut self) -> Result { + let mut ret = T::new_zeroed(); + self.read_exact(ret.as_mut_bytes())?; + + Ok(ret) + } + /// Read all the remaining data into a [`KVec`]. /// /// `self` will be empty after this operation. diff --git a/drivers/gpu/nova-core/vgpu.rs b/drivers/gpu/nova-core/vgpu.rs index bf5d00a9e1cf..5688d6bf1e08 100644 --- a/drivers/gpu/nova-core/vgpu.rs +++ b/drivers/gpu/nova-core/vgpu.rs @@ -4,6 +4,7 @@ use core::num::NonZero; use kernel::{ + bitfield, device, pci, prelude::*, // @@ -21,10 +22,20 @@ gsp::commands::FifoEngineList, // }; +mod commands; mod fw; mod hal; mod vram; +bitfield! { + struct Dbdf(u32) { + 2:0 function; + 7:3 device; + 15:8 bus; + 31:16 domain; + } +} + /// vGPU state detected during GPU construction. #[derive(Debug, Clone, Copy)] pub(crate) enum VgpuState { diff --git a/drivers/gpu/nova-core/vgpu/commands.rs b/drivers/gpu/nova-core/vgpu/commands.rs new file mode 100644 index 000000000000..66669948230a --- /dev/null +++ b/drivers/gpu/nova-core/vgpu/commands.rs @@ -0,0 +1,126 @@ +// SPDX-License-Identifier: GPL-2.0 +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + +//! vGPU firmware command operations. +//! +//! Sends requests, checks responses and coordinates the firmware command +//! sequences used by instance lifecycle operations. + +use core::convert::Infallible; + +use kernel::{ + device, + prelude::*, // +}; + +use crate::{ + gsp::{ + cmdq::{ + gmc::{ + CommandToGsp, + MessageFromGsp, + MessagePayload, // + }, + Cmdq, + }, + nvkv::{ + nvkv_words, + Decoder, + Schema, + UnknownKeyPolicy, // + }, + GmcCommandId, + GSP_PAGE_SIZE, // + }, + vgpu::{ + fw::commands::{ + AssignedVfVgpuType, + VgpuProperties, + VgpuPropertiesSchema, // + }, + Dbdf, + }, +}; + +struct QueryAssignedVfVgpuType(Dbdf); + +impl CommandToGsp for QueryAssignedVfVgpuType { + const COMMAND: GmcCommandId = GmcCommandId::QueryAssignedVfVgpuType; + type Command = u64; + type Reply = AssignedVfVgpuType; + const MAX_REPLY_SIZE: u32 = cv!(size_of::()); + type InitError = Infallible; + + fn init(&self) -> impl Init { + u64::from(self.0.into_raw()).to_le() + } +} + +impl MessageFromGsp for AssignedVfVgpuType { + type InitError = Error; + + fn read(payload: &mut MessagePayload<'_>) -> Result { + payload.read() + } +} + +/// Query the vGPU type assigned to a VF by its DBDF. +#[expect(dead_code)] +pub(super) fn query_assigned_vf_type( + _dev: &device::Device, + cmdq: &Cmdq<'_>, + dbdf: Dbdf, +) -> Result { + let reply = cmdq + .send_gmc_command(QueryAssignedVfVgpuType(dbdf), |_| Ok(()))? + .map_err(|_| EIO)?; + + Ok(reply.vgpu_type_id) +} + +struct QueryVgpuProperties(u32); + +impl CommandToGsp for QueryVgpuProperties { + const COMMAND: GmcCommandId = GmcCommandId::QueryVgpuProperties; + type Command = u32; + type Reply = KBox; + /// The reply is NVKV-encoded and varies in length. + const MAX_REPLY_SIZE: u32 = cv!(GSP_PAGE_SIZE); + type InitError = Infallible; + + fn init(&self) -> impl Init { + self.0.to_le() + } +} + +impl MessageFromGsp for KBox { + type InitError = Error; + + fn read(payload: &mut MessagePayload<'_>) -> Result { + let bytes = payload.flush_into_kvec(GFP_KERNEL)?; + let words = nvkv_words(&bytes, &[])?; + let decoder = Decoder::new(&words, UnknownKeyPolicy::Ignore); + let mut schema = KBox::init(VgpuPropertiesSchema::init(), GFP_KERNEL)?; + let properties = KBox::try_init(decoder.decode(&mut *schema)?, GFP_KERNEL)?; + + Ok(properties) + } +} + +/// Query and decode the firmware properties of one vGPU type. +#[expect(dead_code)] +pub(super) fn query_vgpu_properties( + _dev: &device::Device, + cmdq: &Cmdq<'_>, + type_id: u32, +) -> Result> { + let properties = cmdq + .send_gmc_command(QueryVgpuProperties(type_id), |_| Ok(()))? + .map_err(|_| EIO)?; + + if properties.type_id != type_id || properties.max_instance == 0 { + Err(EINVAL) + } else { + Ok(properties) + } +} diff --git a/drivers/gpu/nova-core/vgpu/fw.rs b/drivers/gpu/nova-core/vgpu/fw.rs index e4571cfe11a3..2d32e196a771 100644 --- a/drivers/gpu/nova-core/vgpu/fw.rs +++ b/drivers/gpu/nova-core/vgpu/fw.rs @@ -1,4 +1,10 @@ // SPDX-License-Identifier: GPL-2.0 // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +//! vGPU firmware interface. +//! +//! Exposes command constants and communication buffer layout types from +//! raw firmware bindings. + +pub(super) mod commands; mod r000_00; diff --git a/drivers/gpu/nova-core/vgpu/fw/commands.rs b/drivers/gpu/nova-core/vgpu/fw/commands.rs new file mode 100644 index 000000000000..d1864d7ab530 --- /dev/null +++ b/drivers/gpu/nova-core/vgpu/fw/commands.rs @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: GPL-2.0 +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + +//! Wire types and codecs for vGPU commands. +//! +//! Defines request encoders and response schemas independently of command +//! submission and instance lifecycle operations. + +use kernel::{ + alloc::ArrayVec, + prelude::*, // +}; + +use crate::{ + gsp::nvkv::{ + nvkv_decode, + Array, + Key, + Required, // + }, // +}; + +nvkv_decode! { + pub(crate) struct VgpuPropertiesSchema => VgpuProperties { + // TODO: `name`/`class` required? + name: Array, + class: Array, + type_id: Required>, + bar1_length: Required>, + max_instance: Required>, + ecc: Key, + profile_size: Required>, + max_fps: Key, + num_heads: Key, + max_res_x: Key, + max_res_y: Key, + dev_id: Required>, + subsystem_id: Required>, + fb_length: Required>, + gsp_heap_size: Required>, + fb_reservation: Required>, + } +} + +pub(crate) struct VgpuProperties { + name: ArrayVec, + class: ArrayVec, + pub(crate) type_id: u32, + pub(crate) bar1_length: u64, + pub(crate) max_instance: u32, + ecc: u32, + profile_size: u64, + max_fps: u32, + num_heads: u32, + max_res_x: u32, + max_res_y: u32, + pub(crate) dev_id: u32, + pub(crate) subsystem_id: u32, + pub(crate) fb_length: u64, + pub(crate) gsp_heap_size: u64, + fb_reservation: u64, +} + +impl VgpuProperties { + const STRING_LEN: usize = 64; +} + +// TODO: extract from bindings +#[repr(C)] +#[derive(FromBytes, IntoBytes)] +pub(crate) struct AssignedVfVgpuType { + pub(crate) vgpu_type_id: u32, + _swizz_id: u32, + _placement_id: u32, +}