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.85.8 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796200701; b=YfeF/tsl0OvFcKasMaEHCtXaW7S8Qced0ch7I3yG5TWRFwporwnyuOy4ObEDBEUuPF1T N+dYaxNS9fxM+tOeAtVikgxgU/d3TYzscbh63fuw9vub/A9O/34Xm5KsfdSfq4bNy/Ynj 51/H60ZNgl0A/Hog1yRYf3wAuHZnXDqH4FGmfVrBdfMRrLM5Dj/PAVvoRniBbWGwGh5SO WQfiqeM7VcOTGoH2qrD9Jfi+NIa1vBMTxbJI/944fGd3mk2IqyIGfWbhdvd9c6i9v589s LQ2ctm+idLfHO5OwR9xQEyhF+V0+K6xErx/hgXtSxvh6khPM1vSgQA3KiE6nbZt1TTw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796200701; 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=8sCLiPj3JcDsUpTJj+jYiHl9WZQb0shOBJ6k1ioWKvA=; b=B51QeCZ9E0IBbpVrtAjChsfT7znzwQDaeOvwErCOuPs9qRMkca68wZicaS6CStNAnBnE I+HlMiVR1rnU3BIf7Fg62tj+uim12HgHJaka3kOCpkQwzEhhCzo/BzL8BQ5BiINf2Kob0 upedR/0jwzSu1ZTpFmYneXn1mSiaocQasz86paHQtkb+JjWHil3Whzlf1WLqMaEOozMhQ pEVCEMjllRgxE2VOLppDnIN/wqc0Y/fEu2U/qZSpMknHJHCc8WMWJMRfH/b/gDbnrs8FM d4YRwufNxmIGlUZan0LgCAfXUvLMNfNYyYBeB/J7O6h120KeZKhzucN4ZJU+sBaNFRw== 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=WzyKqit+; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.85.8 Received: from BYAPR05CU005.outbound.protection.outlook.com (mail-westusazon11010008.outbound.protection.outlook.com [52.101.85.8]) (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 EC8CF606A327; Wed, 2 Dec 2026 08:38:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EC8CF606A327 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=WzyKqit+ ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ErZQ8gOLbX+1bFE/Zw93Nmz+EKvBYxe7a1h113+tZN5/1NLM5ajuqTwfFT0c0ZWqp8324fewhFEUmsDJ7x0BPkZLYpJteaWyogXX2fdVbt33ooCaU00de0nIJoacr+ONL+kU28fPHimP1nnW7iPPuoAtDYntlwSAoDkUnKU1OaUWzq/GhrR6N80+9NK9F4Nh7+0HHToop16ogZKdxOSdCb8smdDmqWH/A+1isxjcsOOrXzCPDZ/GJqIy50aLS/1dJb8n8lY+Olmx4wONqodzlWHmnBg5jsU11p1e2epsLCV6NmroTsjbEquLR0S9KvZ7kp4GwaZdFH/MDVsOr+sFsQ== 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=8sCLiPj3JcDsUpTJj+jYiHl9WZQb0shOBJ6k1ioWKvA=; b=agu6sm27vkIapGqXPpQVf/81Z8sczYiK6IsyMY/LdETtDCVV13j81PH0CVKbeXt1PL3lesdfSBWY3BltnLzHR1278ecveT7SEPzseWO0WJ7NSwDd1Eu+t04zYF7zBs9XOUuf72oDKJviAPgLD0ib/AtNAFBvi4dr+Ncmja9Fme7QnI3OaYSDmc0ugXonBiAHc/ESVcOIyIpzFwlEFH1LdR+0GirAi6ZvdFEE9c4/bX3eUETuCe97/Xt1kM57eLs+KVUBq732aF+IAul0zy+RXnaSFB3Ur2W6VH2Dj1HDXF7A5V7Qq4qPkmT+ffW+JWxcqb0tUhd6Ds3BHl43TM9T8g== 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=8sCLiPj3JcDsUpTJj+jYiHl9WZQb0shOBJ6k1ioWKvA=; b=WzyKqit+ACub1UsvxnRolo+Eo4zomhuhF0nGbF0WYyQdOCUR8hgnYyZ9flchhGu1hmYsxTGF+TjgSTJM6g5/xC/mKEUu10ilhzgM2b8lUhziWPXXAqGyYNxxFZFuJTY4ImqNnhBY6RSmv+shr/uoWpZo50Ctj4JmZ5w3J9VcEYbOr+OhXNtvYu9fO+gdCTHzkSUwC0DYsP7hRhf5i1DrZVL1GGl9ZV4SW+PyYrHTotxL0fH3+IJ9riOYQeg6CnVknhfPGPGyDjo+6F1xGXp52qw+xTCaViNIBhm9f/EwaqFK32HtG1FeU4KSX/KpMW4JIboH94M40a46AWlxLCQ14A== Received: from CH2PR03CA0024.namprd03.prod.outlook.com (2603:10b6:610:59::34) by SJ2PR12MB8184.namprd12.prod.outlook.com (2603:10b6:a03:4f2::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.13; Wed, 2 Dec 2026 08:38:13 +0000 Received: from LV8PEPF00000060.namprd02.prod.outlook.com (2603:10b6:610:59:cafe::43) by CH2PR03CA0024.outlook.office365.com (2603:10b6:610:59::34) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.688.10 via Frontend Transport; Wed, 2 Dec 2026 08:38:13 +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 LV8PEPF00000060.mail.protection.outlook.com (10.167.245.139) 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:38:13 +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:52 -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:37:38 -0800 From: Alok Kumar To: , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v6 24/34] gpu: nova-core: vgpu: add GSP plugin communication buffer Date: Wed, 2 Dec 2026 13:58:48 +0530 Message-ID: <2168da4c8a73f34b2c10b1cffb1d0e3d591f8827.1796191008.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: LV8PEPF00000060:EE_|SJ2PR12MB8184:EE_ X-MS-Office365-Filtering-Correlation-Id: 039b2441-0a2b-48be-72d5-08df504f9a57 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|7416014|30052699003|1800799024|36860700016|23010399003|11063799006|261009223027099003|18002099003|22082099003|3023799007|261026140227099003|10067099003|56012099006|261022113327099003|261028144727099003|261026121527099003|261021135927099003|261022105027099003|261021121427099003|261021123027099003|261102123227099003; X-Microsoft-Antispam-Message-Info: iFvCL1XtmwR5m1ynertVL85Vx9VHeFeHeRY127XcnaVch60Xmy/kkz2H7C688SqKdnM79OGK1LR+af3SYuHiSPF3jpT6zt/Vou2fKXEIWpiGIt9tAJ9zlhdkE/hlbWZ1FaLfX6pKxxnrwotohj9zE1nh6FNtAYlGyRimA9BOe9rp4Ho0hhPtbgoZX22HsdFzEuXNBR4Uo1XRWaYiVE8M6fn+nVok2ie+r/hugWJyQm0OJPy68B2YVbldYkAUrCr80ALY5WcYIEReIgj909u8ll6YizaRLqw66q4P0cB/CmXuBbOsTd5X11gAMeE04SrADlL9U47B4nR7Vn/suM8oT1r1ajbB0jRg7mZ8YPWPu2Y252qRCQ/S9TfwsOYOP53v9U+JWRGiyMlew+ew9pCGVfoNAu67so0D0tfhZRJ7/uVaDgRGF4YnxcVCMkgBK+jhyFtXYpB6ctHkwLhDOXRtFe+kLJmN3PkkPPLr417qKLv2HQEv/VZa2949XW+xZ0WB/61oqkO20yRn6mlin37uhxIcIsExOXokul41ko7WNYcDUakiIOfnX6FCN2Y6I8E7rJnmZzPzZjMahhD2T/hV4kcv1ORsM9UI12ypIux8gBhUwbFxkwCN7ERV2H8HyJzXicQHAVb8/GcLTRpckEuzOn47CIbIhruGYWp79xN2Qp4vpAr/X4E0NywXMt7YPUylqSIAuMiAxpMb4HBG3Cra2Q== 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)(82310400026)(376014)(7416014)(30052699003)(1800799024)(36860700016)(23010399003)(11063799006)(261009223027099003)(18002099003)(22082099003)(3023799007)(261026140227099003)(10067099003)(56012099006)(261022113327099003)(261028144727099003)(261026121527099003)(261021135927099003)(261022105027099003)(261021121427099003)(261021123027099003)(261102123227099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gHqTKTya1bC90XwlgL7wqhvtajbJMgUz7afIQbbqfFZazBUrCWn94iwcsaUeRFlQihWQ8khjvJMYrhIaqakoQErkd0AXtcK63/9p9QaeY6Ia/qOQu9109OfaaRAN2USAGcq9qMB1Q/tGccX+eGIVR3RPbTdVBOa2IiRwncN+i72yg0QcfGO6Hsa1OziGJkD6RUZv0Fne+iBOEydH9V8rztjbvqCRL5azbz7Xwt5+CqcY2R8Z3xr5zByvHos5kRA3Nn5XwUu6GW8i5SMEEv8FJoNDh4JIBp4Y+tIw87dN+1kB+sRKXb28GToeRzvBF6iCtYs6It2PIlrXCwNvmM1qFzBiRsQXWxL3TcfSLtP4jJu2uiOvUzfCrOhzEcZSd98sAhh4RKGHKOZbMsSwxrwvtJlkkzkBOPpUUyE+oxtCqkCYq3vul8fRzftmZORCp1aI X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2026 08:38:13.0294 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 039b2441-0a2b-48be-72d5-08df504f9a57 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: LV8PEPF00000060.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8184 From: Zhi Wang Each vGPU instance shares a communication buffer with its GSP plugin, located at the start of the instance's management heap. It contains the control and response regions used for plugin RPCs, the message and migration buffers, and the plugin logs. Describe its layout with a `CommBuffer` type, and add `CommBufferRegion` which maps the buffer through BAR1 and provides the operations needed before the first RPC: checking the plugin's boot-ready marker, obtaining the VRAM regions of the logs, and initializing the control and response regions. The ready marker is stored in the control region's sequence number field, so the regions must only be initialized after the plugin has reported itself ready. Signed-off-by: Zhi Wang Co-developed-by: Alexandre Courbot Signed-off-by: Alexandre Courbot Signed-off-by: Alok Kumar --- drivers/gpu/nova-core/mm.rs | 1 - drivers/gpu/nova-core/mm/vram.rs | 1 + drivers/gpu/nova-core/vgpu.rs | 1 + drivers/gpu/nova-core/vgpu/fw.rs | 20 ++ drivers/gpu/nova-core/vgpu/gsp_plugin_comm.rs | 201 ++++++++++++++++++ 5 files changed, 223 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/nova-core/vgpu/gsp_plugin_comm.rs diff --git a/drivers/gpu/nova-core/mm.rs b/drivers/gpu/nova-core/mm.rs index f1f86931928c..9489502d3362 100644 --- a/drivers/gpu/nova-core/mm.rs +++ b/drivers/gpu/nova-core/mm.rs @@ -69,7 +69,6 @@ macro_rules! impl_pfn_bounded { mod regs; pub(super) mod tlb; pub(super) mod vmm; -#[expect(dead_code)] pub(crate) mod vram; /// GPU Memory Manager - owns all core MM components. diff --git a/drivers/gpu/nova-core/mm/vram.rs b/drivers/gpu/nova-core/mm/vram.rs index be3076d065c6..265d8269733e 100644 --- a/drivers/gpu/nova-core/mm/vram.rs +++ b/drivers/gpu/nova-core/mm/vram.rs @@ -75,6 +75,7 @@ pub(crate) struct VramRegion<'pool> { range: Range, } +#[expect(dead_code)] impl VramRegion<'_> { /// Returns the range covered by this region. pub(crate) const fn range(&self) -> &Range { diff --git a/drivers/gpu/nova-core/vgpu.rs b/drivers/gpu/nova-core/vgpu.rs index e7b4f1f3a614..f0aee87456aa 100644 --- a/drivers/gpu/nova-core/vgpu.rs +++ b/drivers/gpu/nova-core/vgpu.rs @@ -29,6 +29,7 @@ mod commands; mod fw; +mod gsp_plugin_comm; mod hal; mod instance; mod vram; diff --git a/drivers/gpu/nova-core/vgpu/fw.rs b/drivers/gpu/nova-core/vgpu/fw.rs index 2d32e196a771..84a89c32a77b 100644 --- a/drivers/gpu/nova-core/vgpu/fw.rs +++ b/drivers/gpu/nova-core/vgpu/fw.rs @@ -8,3 +8,23 @@ pub(super) mod commands; mod r000_00; + +// Alias to avoid repeating the version number with every use. +use r000_00 as bindings; + +pub(super) use bindings::{ + GSP_PLUGIN_BOOTLOADED, + VGPU_CPU_GSP_COMMUNICATION_BUFF_TOTAL_SIZE, + VGPU_CPU_GSP_CTRL_BUFF_REGION as RawControlRegion, + VGPU_CPU_GSP_CTRL_BUFF_REGION_SIZE, + VGPU_CPU_GSP_CTRL_BUFF_VERSION, + VGPU_CPU_GSP_ERROR_BUFF_REGION_SIZE, + VGPU_CPU_GSP_GUEST_RPC_TRACE_BUFF_REGION_SIZE, + VGPU_CPU_GSP_INIT_TASK_LOG_BUFF_REGION_SIZE, + VGPU_CPU_GSP_KERNEL_TASK_LOG_BUFF_REGION_SIZE, + VGPU_CPU_GSP_MESSAGE_BUFF_REGION_SIZE, + VGPU_CPU_GSP_MIGRATION_BUFF_REGION_SIZE, + VGPU_CPU_GSP_RESPONSE_BUFF_REGION as RawResponseRegion, + VGPU_CPU_GSP_RESPONSE_BUFF_REGION_SIZE, + VGPU_CPU_GSP_VGPU_TASK_LOG_BUFF_REGION_SIZE, // +}; diff --git a/drivers/gpu/nova-core/vgpu/gsp_plugin_comm.rs b/drivers/gpu/nova-core/vgpu/gsp_plugin_comm.rs new file mode 100644 index 000000000000..e543555a0e94 --- /dev/null +++ b/drivers/gpu/nova-core/vgpu/gsp_plugin_comm.rs @@ -0,0 +1,201 @@ +// SPDX-License-Identifier: GPL-2.0 +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + +//! GSP plugin communication buffer mappings and access. + +use core::mem::offset_of; + +use kernel::{ + io::{ + io_project, + io_read, + io_write, + Mmio, // + }, + num::casts::FromSafeCast, + prelude::*, // +}; + +use crate::mm::{ + bar_user::{ + BarMapping, + BarUser, // + }, + vram::VramRegion, + SharedGpuMm, // +}; + +use super::fw::{ + self, + RawControlRegion, + RawResponseRegion, // +}; + +/// Layout of the plugin communication region, located at the start of the management heap. +/// +/// This type is never instantiated; it only describes the layout of the region for I/O +/// projections. +/// +/// r000 layout, with byte offsets from the management heap (not to scale): +/// +/// ```text +/// 0x000000 +----------------------------------------+ +/// | Control (boot-ready marker) 4 KiB | +/// 0x001000 +----------------------------------------+ +/// | Response 4 KiB | +/// 0x002000 +----------------------------------------+ +/// | Message 4 KiB | +/// 0x003000 +----------------------------------------+ +/// | Migration 2 MiB | +/// 0x203000 +----------------------------------------+ +/// | Error 4 KiB | +/// 0x204000 +----------------------------------------+ +/// | Init task log 128 KiB | +/// 0x224000 +----------------------------------------+ +/// | vGPU task log 256 KiB | +/// 0x264000 +----------------------------------------+ +/// | Kernel task log 64 KiB | +/// 0x274000 +----------------------------------------+ +/// | Guest RPC trace 64 KiB | +/// 0x284000 +----------------------------------------+ +/// ``` +#[repr(C)] +struct CommBuffer { + control: RawControlRegion, + response: RawResponseRegion, + message: [u8; cv!(fw::VGPU_CPU_GSP_MESSAGE_BUFF_REGION_SIZE)], + migration: [u8; cv!(fw::VGPU_CPU_GSP_MIGRATION_BUFF_REGION_SIZE)], + error: [u8; cv!(fw::VGPU_CPU_GSP_ERROR_BUFF_REGION_SIZE)], + init_log: [u8; cv!(fw::VGPU_CPU_GSP_INIT_TASK_LOG_BUFF_REGION_SIZE)], + vgpu_log: [u8; cv!(fw::VGPU_CPU_GSP_VGPU_TASK_LOG_BUFF_REGION_SIZE)], + kernel_log: [u8; cv!(fw::VGPU_CPU_GSP_KERNEL_TASK_LOG_BUFF_REGION_SIZE)], + guest_trace: [u8; cv!(fw::VGPU_CPU_GSP_GUEST_RPC_TRACE_BUFF_REGION_SIZE)], +} + +static_assert!(size_of::() == cv!(fw::VGPU_CPU_GSP_COMMUNICATION_BUFF_TOTAL_SIZE)); +static_assert!(size_of::() == cv!(fw::VGPU_CPU_GSP_CTRL_BUFF_REGION_SIZE)); +static_assert!(size_of::() == cv!(fw::VGPU_CPU_GSP_RESPONSE_BUFF_REGION_SIZE)); + +/// Physical VRAM regions containing the vGPU plugin logs. +#[expect(dead_code)] +pub(super) struct PluginLogRegions<'pool> { + pub(super) init: VramRegion<'pool>, + pub(super) vgpu: VramRegion<'pool>, + pub(super) kernel: VramRegion<'pool>, +} + +/// BAR1 mapping of the plugin communication region in its management heap. +/// +/// See [`CommBuffer`] for the layout of the region. +pub(super) struct CommBufferRegion<'pool, 'map, 'gpu> { + map: BarMapping<'pool, 'map, 'gpu>, +} + +#[expect(dead_code)] +impl<'pool, 'map, 'gpu> CommBufferRegion<'pool, 'map, 'gpu> { + /// Map the communication portion of a plugin management heap. + pub(super) fn new( + bar_user: &'map BarUser<'gpu>, + mm: &'map SharedGpuMm<'gpu>, + management_heap: &VramRegion<'pool>, + ) -> Result { + let region = management_heap.subregion(0..u64::from_safe_cast(size_of::()))?; + + Ok(Self { + map: BarMapping::new(bar_user, mm, region, true)?, + }) + } + + /// Returns the MMIO view of the communication region. + /// + /// Fails if the region has been unmapped. + fn view(&self) -> Result> { + self.map.view() + } + + /// Return the physical regions occupied by the three plugin logs. + pub(super) fn plugin_logs(&self) -> Result> { + let log_region = |offset, size| { + let start = u64::from_safe_cast(offset); + + self.map.region().subregion(start..start + u64::from(size)) + }; + + Ok(PluginLogRegions { + init: log_region( + offset_of!(CommBuffer, init_log), + fw::VGPU_CPU_GSP_INIT_TASK_LOG_BUFF_REGION_SIZE, + )?, + vgpu: log_region( + offset_of!(CommBuffer, vgpu_log), + fw::VGPU_CPU_GSP_VGPU_TASK_LOG_BUFF_REGION_SIZE, + )?, + kernel: log_region( + offset_of!(CommBuffer, kernel_log), + fw::VGPU_CPU_GSP_KERNEL_TASK_LOG_BUFF_REGION_SIZE, + )?, + }) + } + + /// Return whether firmware has published the plugin boot marker. + pub(super) fn is_plugin_ready(&self) -> Result { + let value = io_read!(self.view()?, .control.__bindgen_anon_1.message_seq_num); + + Ok(value == fw::GSP_PLUGIN_BOOTLOADED) + } + + /// Initialize the shared control and response buffers for plugin RPC. + #[expect(dead_code)] + pub(super) fn initialize(&self) -> Result { + let comm = self.view()?; + let control = io_project!(comm, .control.__bindgen_anon_1); + let response = io_project!(comm, .response.__bindgen_anon_1); + + io_write!( + control, + .response_buff_offset, + u64::from_safe_cast(offset_of!(CommBuffer, response)) + ); + io_write!( + control, + .message_buff_offset, + u64::from_safe_cast(offset_of!(CommBuffer, message)) + ); + io_write!( + control, + .migration_buff_offset, + u64::from_safe_cast(offset_of!(CommBuffer, migration)) + ); + io_write!( + control, + .error_buff_offset, + u64::from_safe_cast(offset_of!(CommBuffer, error)) + ); + io_write!( + control, + .guest_rpc_trace_buff_offset, + u64::from_safe_cast(offset_of!(CommBuffer, guest_trace)) + ); + io_write!(control, .migration_buf_cpu_access_offset, 0); + io_write!(control, .is_migration_in_progress, 0); + io_write!(control, .error_buff_cpu_get_idx, 0); + io_write!(control, .guest_rpc_trace_buff_cpu_get_idx, 0); + io_write!(control, .attached_vgpu_count, 1); + io_write!(control, .is_gr_init_done, 0); + + io_write!(control, .message_type, 0); + // Replace the boot-ready marker with the initial RPC sequence. + io_write!(control, .message_seq_num, 0); + io_write!(response, .message_seq_num_processed, 0); + io_write!(response, .result_code, 0); + io_write!(control, .version, fw::VGPU_CPU_GSP_CTRL_BUFF_VERSION); + + Ok(()) + } + + /// Invalidate the PTEs and release the communication mapping. + #[expect(dead_code)] + pub(super) fn unmap(&mut self) -> Result { + self.map.unmap() + } +}