From nobody Sun Feb 8 13:39:36 2026 Received: from PH0PR06CU001.outbound.protection.outlook.com (mail-westus3azon11011032.outbound.protection.outlook.com [40.107.208.32]) (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 40B75262FF3; Thu, 30 Oct 2025 16:03:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.208.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761840240; cv=fail; b=sRQ1fbwqUQ+5zGTgrwqEjrhRtgDMJKPHagw0xXQOBvUQm3/aIg1Inz4Ve6SgUGzn9LoaHTxiEFZxnaIJ9TBBdGNy+NHmYAwvIp+2vc5qE+AQXqFIIXSFHcEMa3Zof35xhJ2AMVdAbS1PFqYQWyaPx1qshbfLnI0UPK72lJ4hTf0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761840240; c=relaxed/simple; bh=wz30yFN/O1wc/bSqf+LifY2Ynownmx7x/8ij46Fuipg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RD/SP2+SMgZnasKf/ONRvwMAgZX/RzgjAyoDRusg5ajJ5JZcwF3R0Uiq15Rc3p4/w0NbJ+mWn+8badfF8+JcTIl+Loffx4cvD/5/Q0CWAHYhGsX1CJEQcP7NGD+c+ZwvJZ3/X42SFUG5OUOlDAI8hcOs7FP9tTDbwtMc3/uIB4E= 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=JV32dgmv; arc=fail smtp.client-ip=40.107.208.32 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="JV32dgmv" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=CdiHxztCRCiHsKkjIXX40sws7+mrak2IS99iYeghDo9l7luLBHvQ4vVQJz881kIxS7XKvLfdbAzdH6nFz9nw8JOdMIOIJTYu3I7woKG7DFGmHyiF/vrir0zzF4NqkU+S3V+HBEpKL1ThUc5qXOSmBnpPzGfiPYErHfC2nnx3Rvimfi40ZgqVV9BCsJjVpNfuajwxxEga9zhKE1xnO1xmasz9LCFM7D0SYN63Vpoa228jlS5QAj/1Fz8LesD5bWMrUiObpG+Y8X90qO2hKXSLV+IjiIjiC3IG0CQRksj7BM7wt4cXc9cIWwf4r6E5M7bfPyDETD3HEfgNpJ7o2RYluw== 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=xmhTs6V8cwNkeNgS/NWISqqWm7c5Oo/ye30LM2WwOMw=; b=h2gWo6akc8NJlpYdU4Nwk6Ce4rC7sz+tqr5/2tMIK2ZWS5umtAl8zDPlC797FJJbdTcxmJKhYeYXXF/PCV9Nx+oMwdDqDA91MZ8vIFNH75qlWWzMCCtwAarBYZvOkNIxZA2R9tG7qEecvMa9xpQZYB3D1y1p1dJ5fgPTg495q3wo/v+6hYC58a+4/h7hu97LSjmnHkipOa7VeZpJdS01NiczXAf+2nQXkSxNvkup+++Ri7hREn9e9Z5TQ6C8VzOpdIfviOq5JgcCuz9OeraK0tIA1JjGospJKgdda8GyWI6vozxlkpKubdBWCGqxIWYkpV53ciSB13dOa9B/uUfO+w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=vger.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=xmhTs6V8cwNkeNgS/NWISqqWm7c5Oo/ye30LM2WwOMw=; b=JV32dgmvp6yxY/YWJ6TxgXaDBw5a+LRouRYQQ56BejiHTOx1zr/5L8CHqbKDuYVC5Avk8AmLutrpksMna1F98pPLx8OnpEipS1xN87NOy2eui6hNIFiUk0lx4g8/SBZoaCfqPlxOJiSsVcW1KOwMEEz52qGtp/DaHM/qL9Efpv3ir5H3/n16hgRCZ8WkMQ3cmvZxFnpD1yU2IG8KZkrLMa2LcXaoemf4Ym7xnx7YDFmhI7NmeRJ0F5oYF97z+Ljjdst0iA16R9Scoa2ScdafeiHkxaLbDa97Rf2EJJuSRkZXcyZo1/aAP1ffnfN6iglmVYMTXmmIPMA5M2D6dFETaQ== Received: from BN1PR14CA0026.namprd14.prod.outlook.com (2603:10b6:408:e3::31) by SN7PR12MB7910.namprd12.prod.outlook.com (2603:10b6:806:34b::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9275.13; Thu, 30 Oct 2025 16:03:49 +0000 Received: from BN1PEPF00005FFF.namprd05.prod.outlook.com (2603:10b6:408:e3:cafe::8a) by BN1PR14CA0026.outlook.office365.com (2603:10b6:408:e3::31) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9275.13 via Frontend Transport; Thu, 30 Oct 2025 16:03:49 +0000 X-MS-Exchange-Authentication-Results: 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 BN1PEPF00005FFF.mail.protection.outlook.com (10.167.243.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9275.10 via Frontend Transport; Thu, 30 Oct 2025 16:03:49 +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.20; Thu, 30 Oct 2025 09:03:28 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) 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.20; Thu, 30 Oct 2025 09:03:28 -0700 Received: from ipp2-2168.ipp2a1.colossus.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Thu, 30 Oct 2025 09:03:27 -0700 From: Zhi Wang To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC 1/2] rust: introduce abstractions for fwctl Date: Thu, 30 Oct 2025 16:03:12 +0000 Message-ID: <20251030160315.451841-2-zhiw@nvidia.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251030160315.451841-1-zhiw@nvidia.com> References: <20251030160315.451841-1-zhiw@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF00005FFF:EE_|SN7PR12MB7910:EE_ X-MS-Office365-Filtering-Correlation-Id: 5c10accd-23ab-4dfe-ae93-08de17cdea37 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|82310400026|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?NfhwFOczKLYhe7upc50HGLJkTdBKKyroD0gYjezFNVw2gnisUHVYP6EGRrfq?= =?us-ascii?Q?NTEu/jsAdndQdAn3a+92KUtOus8pZ+wRl0vAVebB+PHiJj+Lvn/hHzuPwcwC?= =?us-ascii?Q?jCafFxpj0/8XkjsyZQlt3yNQctAqeHhinGVRXBF1Tizw4iw4IyjwKFwxDZz9?= =?us-ascii?Q?/O57gzfWjKooeVrkgsT7Rd7s4Wbr2crttC5dsqbAmYkVqzhiqZy89nj2pPYC?= =?us-ascii?Q?rt89SVrt5O0PK677VEqmrvkybfimCNcpmoho0QrXtSMIYC6GBZfqrC4/TC5v?= =?us-ascii?Q?9GhcR6SlXbFu+PYbWq2n/jWPSt7xie2UU6zxSD8EDcccytDr9d3xkj+zy0UW?= =?us-ascii?Q?dNcumUCjdf5bdXoVh4DdgMtTXErv4uvxW9WHqIQeiiXb/xfRar3t7WqK9wOG?= =?us-ascii?Q?yiaeDtKjgo3kbo8zwzXWqSgvAF/ARyrwrOQxIb7XgBV3SF86CTPTLLY+b0BD?= =?us-ascii?Q?3VEeaamWS2IsKZbyq9Fd/yk6WJjHjVsbRL2sp01BpuTmMzktYcXPiISzEH0p?= =?us-ascii?Q?2bEYR92YuLlrElIDWTH4TwHo2oWEiSlKMpVmrZa2HO/7y2s7bmsI0dd9IjL2?= =?us-ascii?Q?iG6cWuRDDaYOA4Fs8trnCKbDL0qjdTCe/QUix/1WgRUQKOyi+tWIoK5OG3Gq?= =?us-ascii?Q?VhDCe4/x2uUNmd88KnvN7mlhFG0jOVnRLsbAazUkMqYoE9qyC7GYX3iaESpQ?= =?us-ascii?Q?xVix8hU5Zn+jZS1xfvzwHho1z2kmAJnKt0S+FSTpjs4nkILnaoa1fzkPAILd?= =?us-ascii?Q?J44KGUOVeonq3Y5vGAj+y6xVSeOz5aLbgccd82d6gF+PYzMb6BFqDr2CE0b7?= =?us-ascii?Q?cB5FMh3Z3Jvfc9R/VxZn7jmoYT8AVDDZBDqmOCE5Jc0aCe5GAEiV0USjPluX?= =?us-ascii?Q?qLYdRrMDraeEfvvwixKBkNLbnDERrSnciePL0h95LwwUl1ZW4eW1ULV9k+AD?= =?us-ascii?Q?97mW3q0ikyGWW8qrk9FlOB9PNyG5R7QTuxHOWFHidLGyxCOhAylQ/8RA8xLJ?= =?us-ascii?Q?Y57cyES8CA4mdaH5twU0WvthAZq/hBO/dLnCd0Nay/XnBRkhi3VTi9eTP4ab?= =?us-ascii?Q?bCmUsLVzkbujgw5QCwsJmw3g67QOtndrmrcm6QSnITabzftcbEYVsVOGl+2E?= =?us-ascii?Q?yBiWXNMGa1OtNIpl6L4uTUGf6pR+0MdYW44EsGi5SF4ZrOpNUR1T2OvLLttx?= =?us-ascii?Q?/LycAjzUYPkIqTCHCOdaHHj/MYv7QipSPfndZXEAbe8+kpsNLPm/8wofihId?= =?us-ascii?Q?JKeeIuKmrs/V7FljkFS+doR0YFwzypX0j9ttB2AhLy6cF499RoZD08We9DGo?= =?us-ascii?Q?kVe/LgAx3RlSSqECE9l8aR2gLAL7TltJEGbXv5OtFbd2ygoYmehbabuqmLmR?= =?us-ascii?Q?3x3dPVIxmozfEDJZa7kh6+r9Gpe5DgZXjWtQaNT6hHqJkRNqZuwAfjSAGIgO?= =?us-ascii?Q?S9r/PL+JL1k6s+0d1qtet0knt9VMCEFYPOB48LtTwsw2atiLPmg0+05DPsmy?= =?us-ascii?Q?ERqcbnwfaYrDc7Mv9OTvDB9AzhwclDTWjS9rRD6RZQ1CVai5+hZXAFWPcOX0?= =?us-ascii?Q?Y6qsOZlqqGJl9qHevGY=3D?= 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)(376014)(7416014)(82310400026)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2025 16:03:49.6589 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5c10accd-23ab-4dfe-ae93-08de17cdea37 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: BN1PEPF00005FFF.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7910 Content-Type: text/plain; charset="utf-8" Introduce safe wrappers around `struct fwctl_device` and `struct fwctl_uctx`, allowing rust drivers to register fwctl devices and implement their control and RPC logic in safe rust. The core of the abstraction is the `FwCtlOps` trait, which defines the driver callbacks (`open_uctx`, `close_uctx`, `info`, and `fw_rpc`). `FwCtlVTable` bridges these trait methods to the C fwctl core through a static vtable. `rust/kernel/lib.rs` is updated to conditionally build this module when `CONFIG_FWCTL` is enabled. Signed-off-by: Zhi Wang --- rust/bindings/bindings_helper.h | 1 + rust/kernel/fwctl.rs | 254 ++++++++++++++++++++++++++++++++ rust/kernel/lib.rs | 2 + 3 files changed, 257 insertions(+) create mode 100644 rust/kernel/fwctl.rs diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helpe= r.h index 2e43c66635a2..5c374965f0f1 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -56,6 +56,7 @@ #include #include #include +#include #include #include #include diff --git a/rust/kernel/fwctl.rs b/rust/kernel/fwctl.rs new file mode 100644 index 000000000000..21f8f7d11d6f --- /dev/null +++ b/rust/kernel/fwctl.rs @@ -0,0 +1,254 @@ +// SPDX-License-Identifier: GPL-2.0-only + +//! Abstractions for the fwctl. +//! +//! This module provides bindings for working with fwctl devices in kernel= modules. +//! +//! C header: [`include/linux/fwctl.h`] + +use crate::device::Device; +use crate::types::ARef; +use crate::{bindings, container_of, device, error::code::*, prelude::*}; + +use core::marker::PhantomData; +use core::ptr::NonNull; +use core::slice; + +/// The registration of a fwctl device. +/// +/// This type represents the registration of a [`struct fwctl_device`]. Wh= en an instance of this +/// type is dropped, its respective fwctl device will be unregistered and = freed. +/// +/// [`struct fwctl_device`]: srctree/include/linux/device/fwctl.h +pub struct Registration { + fwctl_dev: NonNull, + _marker: PhantomData, +} + +impl Registration { + /// Allocate and register a new fwctl device under the given parent de= vice. + pub fn new(parent: &device::Device) -> Result { + let ops =3D &FwCtlVTable::::VTABLE as *const _ as *mut _; + + // SAFETY: `_fwctl_alloc_device()` allocates a new `fwctl_device` + // and initializes its embedded `struct device`. + let dev =3D unsafe { + bindings::_fwctl_alloc_device( + parent.as_raw(), + ops, + core::mem::size_of::(), + ) + }; + + let dev =3D NonNull::new(dev).ok_or(ENOMEM)?; + + // SAFETY: `fwctl_register()` expects a valid device from `_fwctl_= alloc_device()`. + let ret =3D unsafe { bindings::fwctl_register(dev.as_ptr()) }; + if ret !=3D 0 { + // SAFETY: If registration fails, release the allocated fwctl_= device(). + unsafe { + bindings::put_device(core::ptr::addr_of_mut!((*dev.as_ptr(= )).dev)); + } + return Err(Error::from_errno(ret)); + } + + Ok(Self { + fwctl_dev: dev, + _marker: PhantomData, + }) + } + + fn as_raw(&self) -> *mut bindings::fwctl_device { + self.fwctl_dev.as_ptr() + } +} + +impl Drop for Registration { + fn drop(&mut self) { + // SAFETY: `fwctl_unregister()` expects a valid device from `_fwct= l_alloc_device()`. + unsafe { + bindings::fwctl_unregister(self.as_raw()); + bindings::put_device(core::ptr::addr_of_mut!((*self.as_raw()).= dev)); + } + } +} + +// SAFETY: The only action allowed in a `Registration` instance is droppin= g it, which is safe to do +// from any thread because `fwctl_unregister()/put_device()` can be called= from any sleepible +// context. +unsafe impl Send for Registration {} + +/// Trait implemented by each Rust driver that integrates with the fwctl s= ubsystem. +/// +/// Each implementation corresponds to a specific device type and provides +/// the vtable used by the core `fwctl` layer to manage per-FD user contex= ts +/// and handle RPC requests. +pub trait FwCtlOps: Sized { + /// Driver UCtx type. + type UCtx; + + /// fwctl device type, matching the C enum `fwctl_device_type`. + const DEVICE_TYPE: u32; + + /// Called when a new user context is opened by userspace. + fn open_uctx(uctx: &mut FwCtlUCtx) -> Result<(), Error>; + + /// Called when the user context is being closed. + fn close_uctx(uctx: &mut FwCtlUCtx); + + /// Return device or context information to userspace. + fn info(uctx: &mut FwCtlUCtx) -> Result, Error>; + + /// Called when a userspace RPC request is received. + fn fw_rpc( + uctx: &mut FwCtlUCtx, + scope: u32, + rpc_in: &mut [u8], + out_len: *mut usize, + ) -> Result>, Error>; +} + +/// Represents a per-FD user context (`struct fwctl_uctx`). +/// +/// Each driver embeds `struct fwctl_uctx` as the first field of its own +/// context type and uses this wrapper to access driver-specific data. +#[repr(C)] +#[pin_data] +pub struct FwCtlUCtx { + /// The core fwctl user context shared with the C implementation. + #[pin] + pub fwctl_uctx: bindings::fwctl_uctx, + /// Driver-specific data associated with this user context. + pub uctx: T, +} + +impl FwCtlUCtx { + /// Converts a raw C pointer to `struct fwctl_uctx` into a reference t= o the + /// enclosing `FwCtlUCtx`. + /// + /// # Safety + /// * `ptr` must be a valid pointer to a `fwctl_uctx` that is embedded + /// inside an existing `FwCtlUCtx` instance. + /// * The caller must ensure that the lifetime of the returned referen= ce + /// does not outlive the underlying object managed on the C side. + pub unsafe fn from_raw<'a>(ptr: *mut bindings::fwctl_uctx) -> &'a mut = Self { + // SAFETY: `ptr` was originally created from a valid `FwCtlUCtx= `. + unsafe { &mut *container_of!(ptr, FwCtlUCtx, fwctl_uctx) } + } + + /// Returns the parent device of this user context. + /// + /// # Safety + /// The `fwctl_device` pointer inside `fwctl_uctx` must be valid. + pub fn get_parent_device(&self) -> ARef { + // SAFETY: `self.fwctl_uctx.fwctl` is initialized by the fwctl sub= system and guaranteed + // to remain valid for the lifetime of this `FwCtlUCtx`. + let raw_dev =3D + unsafe { (*(self.fwctl_uctx.fwctl)).dev.parent as *mut kernel:= :bindings::device }; + // SAFETY: `raw_dev` points to a live device object. + unsafe { Device::get_device(raw_dev) } + } + + /// Returns a mutable reference to the driver-specific context. + pub fn to_driver_uctx_mut(&mut self) -> &mut T { + &mut self.uctx + } +} + +/// Static vtable mapping Rust trait methods to C callbacks. +pub struct FwCtlVTable(PhantomData); + +impl FwCtlVTable { + /// Static instance of `fwctl_ops` used by the C core to call into Rus= t. + pub const VTABLE: bindings::fwctl_ops =3D bindings::fwctl_ops { + device_type: T::DEVICE_TYPE, + uctx_size: core::mem::size_of::>(), + open_uctx: Some(Self::open_uctx_callback), + close_uctx: Some(Self::close_uctx_callback), + info: Some(Self::info_callback), + fw_rpc: Some(Self::fw_rpc_callback), + }; + + /// Called when a new user context is opened by userspace. + unsafe extern "C" fn open_uctx_callback(uctx: *mut bindings::fwctl_uct= x) -> ffi::c_int { + // SAFETY: `uctx` is guaranteed by the fwctl subsystem to be a val= id pointer. + let ctx =3D unsafe { FwCtlUCtx::::from_raw(uctx) }; + match T::open_uctx(ctx) { + Ok(()) =3D> 0, + Err(e) =3D> e.to_errno(), + } + } + + /// Called when the user context is being closed. + unsafe extern "C" fn close_uctx_callback(uctx: *mut bindings::fwctl_uc= tx) { + // SAFETY: `uctx` is guaranteed by the fwctl subsystem to be a val= id pointer. + let ctx =3D unsafe { FwCtlUCtx::::from_raw(uctx) }; + T::close_uctx(ctx); + } + + /// Returns device or context information. + unsafe extern "C" fn info_callback( + uctx: *mut bindings::fwctl_uctx, + length: *mut usize, + ) -> *mut ffi::c_void { + // SAFETY: `uctx` is guaranteed by the fwctl subsystem to be a val= id pointer. + let ctx =3D unsafe { FwCtlUCtx::::from_raw(uctx) }; + + match T::info(ctx) { + Ok(kvec) =3D> { + // The ownership of the buffer is now transferred to the f= oreign + // caller. It must eventually be released by fwctl framewo= rk. + let (ptr, len, _cap) =3D kvec.into_raw_parts(); + + // SAFETY: `length` is a valid out-parameter provided by t= he C + // caller. Write the number of bytes in the returned buffe= r. + unsafe { + *length =3D len; + } + + ptr.cast::() + } + + Err(e) =3D> Error::to_ptr(e), + } + } + + /// Called when a user-space RPC request is received. + unsafe extern "C" fn fw_rpc_callback( + uctx: *mut bindings::fwctl_uctx, + scope: u32, + rpc_in: *mut ffi::c_void, + in_len: usize, + out_len: *mut usize, + ) -> *mut ffi::c_void { + // SAFETY: `uctx` is guaranteed by the fwctl framework to be a val= id pointer. + let ctx =3D unsafe { FwCtlUCtx::::from_raw(uctx) }; + + // SAFETY: `rpc_in` points to a valid input buffer of size `in_len` + // provided by fwctl subsystem. + let rpc_in_slice: &mut [u8] =3D + unsafe { slice::from_raw_parts_mut(rpc_in as *mut u8, in_len) = }; + + match T::fw_rpc(ctx, scope, rpc_in_slice, out_len) { + // Driver allocates a new output buffer. + Ok(Some(kvec)) =3D> { + // The ownership of the buffer is now transferred to the f= oreign + // caller. It must eventually be released by fwctl subsyst= em. + let (ptr, len, _cap) =3D kvec.into_raw_parts(); + + // SAFETY: `out_len` is a valid writable pointer provided = by the C caller. + unsafe { + *out_len =3D len; + } + + ptr.cast::() + } + + // Driver re-uses the existing input buffer and writes the out= _len. + Ok(None) =3D> rpc_in, + + // Return an ERR_PTR-style encoded error pointer. + Err(e) =3D> Error::to_ptr(e), + } + } +} diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index 3dd7bebe7888..8ddad8ae211a 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -94,6 +94,8 @@ pub mod firmware; pub mod fmt; pub mod fs; +#[cfg(CONFIG_FWCTL)] +pub mod fwctl; pub mod id_pool; pub mod init; pub mod io; --=20 2.47.3 From nobody Sun Feb 8 13:39:36 2026 Received: from BN1PR04CU002.outbound.protection.outlook.com (mail-eastus2azon11010062.outbound.protection.outlook.com [52.101.56.62]) (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 CEFCFB640; Thu, 30 Oct 2025 16:03:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.56.62 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761840241; cv=fail; b=oT9dnfSWdEmOVpD+A0FDji9wxMgRXpsC0HhZ779w5H8WC4XrU817wj/watll/jnXWURydVw93/ssiwZ9sG2yVI79ZXNEib+bXgRGPLEQLW1uFii5eB3mEU3oh/7yKFbw0VBgckAFS0sS92LXAK4c9cAfVNFIB5O9Dk1/Zwkqh7c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761840241; c=relaxed/simple; bh=NNI/ap9A6vABeifh/IiNznYL0lmDe+k6G2d20L3JU6I=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CI+tK1k6npX+pN273wv/K8SNHNlM4SrKEH1EwALjIo3TH1xotdFmanCJhlw2vFKx4AvGEASr/H4ABpUPIzw0aAuyYZzQxyevuLDa3CRC8J8cJKCkn8ijz7+nZjEjU3X3UeAse8lwgRPIUYtfNDymfje8PFDMM9wCyVGPs5lML98= 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=ltUgrmeT; arc=fail smtp.client-ip=52.101.56.62 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="ltUgrmeT" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TKn1UySLJhFiSKONo7eBfWF4S9dOE9RG55nZfm1dudqamMMA0sXZJTbuiF/susjouK6nCEOi+Ogo7GOpZhQl0gEwGkzZPllz2f+KU48CnoRuw5yLELd7HAYnW36KIvVpcXz95wkUJ58OP7zzUgbrt77E3P7E4nDjnvvlvSaa592Ej0T2dNneo6L6fTajiR16KdDLyjvsKHcLtz6bc3D7s0l7fq9HZ4HvFN2dJhUmXoCUuzNw8tGGK90rtg6pH0av1+fiR1jfIB+kD9HM4aflAGjcR8fECvYGnZn3fTcIXYuZG2fe2kW2cPhtBvmB6YhdQW6jzSBFnrVvJkaSwKgxIg== 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=vYzVjS7OYsZmH4Fazo2IatsShR7L2ECN0Msqmzt133E=; b=IRfER8LVE8OqvutLp5pMpxcrFH3zeOUEu5yT0oFbkgfPaKwQZE/NDZq8+4NpSCMDsc/gUfMXvYRyptbvasRzSf/wVMzU4FT1hK7dYCwyWGUzAaRqH6RzXWzv9lOLcOtD+/48r+ZsFFz4t8k7++MYBExBgkAU85bbkOaTyhyW6MgVXhRIuc0b/6K/LzNEJPIKyadBfWXP7Yrgpj+OrooLo0QYFjc0QAytD3eg+ZVWIYSLBNCo0agtOMShd2vE1PtKhUYwSWSCKLV1o/U4Ur/qZ/PV55Uum6oZ41xb/Xi/nN8B48xu1+VgalaHwRmDzekPefz+KTEUGDv5CyhIDmi+QQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=vger.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=vYzVjS7OYsZmH4Fazo2IatsShR7L2ECN0Msqmzt133E=; b=ltUgrmeTeW2vPmuiBxXfELLELpbBg3MuFPgh9F5FfsE1Vacy7sj+F0z4Qo/008zkeU63NxHPk8KPgjYpsBgG09sDzgLnLOD2OU7fclnToRYEuEbi+srbEnFecgF8JqIa1lAdZtIJ0dh9AQZCw6YFcx9Gnq+36WQO8eeQskr4j5ll/+LSutbRqwksgSR5vqahM1dDxquysBHpaKE6Ukmz0MxMmHyyFUULe4xCh7VtHb9brQEBetoVd8XIfr1OYNS1/R49r+EIAzVoymbDaNZD5uQb6ar3Tsb8aZHMfbIMRlgLU3A9YP8ePuvdbiogCp+Fu36rB2kFxQSfp1+ij7U9Dg== Received: from BLAPR03CA0112.namprd03.prod.outlook.com (2603:10b6:208:32a::27) by SA3PR12MB7949.namprd12.prod.outlook.com (2603:10b6:806:31a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9275.14; Thu, 30 Oct 2025 16:03:54 +0000 Received: from BL02EPF0001A106.namprd05.prod.outlook.com (2603:10b6:208:32a:cafe::c0) by BLAPR03CA0112.outlook.office365.com (2603:10b6:208:32a::27) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9253.19 via Frontend Transport; Thu, 30 Oct 2025 16:03:53 +0000 X-MS-Exchange-Authentication-Results: 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 BL02EPF0001A106.mail.protection.outlook.com (10.167.241.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9275.10 via Frontend Transport; Thu, 30 Oct 2025 16:03:53 +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.1544.14; Thu, 30 Oct 2025 09:03:29 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) 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.20; Thu, 30 Oct 2025 09:03:28 -0700 Received: from ipp2-2168.ipp2a1.colossus.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Thu, 30 Oct 2025 09:03:28 -0700 From: Zhi Wang To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC 2/2] samples: rust: fwctl: add sample code for FwCtl Date: Thu, 30 Oct 2025 16:03:13 +0000 Message-ID: <20251030160315.451841-3-zhiw@nvidia.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251030160315.451841-1-zhiw@nvidia.com> References: <20251030160315.451841-1-zhiw@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A106:EE_|SA3PR12MB7949:EE_ X-MS-Office365-Filtering-Correlation-Id: a59677cc-1010-4c63-ffab-08de17cdeca6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|82310400026|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?9ADc/JYwQmrJSVcCv2X8zAyTz9f+DjWFbozm+JleRHd/utgH/HluM4kmU5Va?= =?us-ascii?Q?EI1+/fbdhkI8fsCDKGjaaLCwgob6mbUwSSPzvB14BAU89yEIgScoc8CNOBTF?= =?us-ascii?Q?/l7//nvFE/dDVYehc1+OgatNiq/tzW9qi13tBhBwcCGvAljwK/cfFLwjPbeq?= =?us-ascii?Q?K8KEUKKhnDu49DgU7VxWABd0fJe+o6fRg6lz0WSesG5pWUmC0brOR37yd9YQ?= =?us-ascii?Q?kkPqKiJ3q2WRyShaSa7u6OjbAswV52O7k+rUONzKLGwgEPNjIiW6bSRfgE4T?= =?us-ascii?Q?Ve0833T3p8MG7ZBCLQDTjSJ6kI82ikAC1aNqNuPM4Tf/mYmNgcqoDH9ruB2w?= =?us-ascii?Q?dAQursO/dZ5jGQeIeDe7CLlkRz3Tnxv7PhyazLSiR6DyXW0VfFoEb6rw+A/1?= =?us-ascii?Q?SgTTJWHOQ82jzRgUfWlAEPxBL0Sgz965wIDZLQpFX+iQLtdCSosonrGhtywT?= =?us-ascii?Q?Fz0TvL4a0/Y62Qbdmv4LLDNuQ24McKZWRImoxxs8b/ZahXUGEIvlLp6g/b/F?= =?us-ascii?Q?7TtZPcpex+M5C5QswdPuYT3pYFTLHNQex/p5rRPXnnxfxvRcO3baBT7215d3?= =?us-ascii?Q?+YFK5OiPQxd7UrLWgmVoYxOmT+wUj8ME047358mvogXdHCNm5bcroact2La/?= =?us-ascii?Q?G/PekX05cbnxPYPoPOvj44WdpOJDpN1ITYAOyiK7hTeDOvmZEZ2Rw079FRJR?= =?us-ascii?Q?NsDds9nMxL0eukA23HJl4IJgCvP9BL/FasWUu98jgFDAlSdBXpLmZlOjp8+n?= =?us-ascii?Q?ZfyD+LkGJZ7hSqoAZu7SyABttv9rR2VI5ppsjYroKOvzvcW+zlN2HXsnYHtI?= =?us-ascii?Q?tZ1g+A4NeEcl+ROfTqh400B6HbYUmDwIdv08hY/EfZhQZtBa1uPt//XMDmo1?= =?us-ascii?Q?18UY7Vd4wAu5keVjddbYkztXQhftb8yvDeHjE32r/9Pltoc3UiI2VbHQcAbK?= =?us-ascii?Q?3L6Vo4TMGcbRqw69wfAwGv8Cuxfb9aKXITE2WfzLtfLhqxcsim0SrS0rNwO0?= =?us-ascii?Q?J4XUKwscAKRWFzBdTdTow2ROfNSm8DiAL0KR4uaq9iDbx0eMsWjUEjMLLB2s?= =?us-ascii?Q?UteGzBnUMz2qFXW9mw7uqpJ2kmhfIkQ4FiG9gzJ29qS/tF879foR4rMyz+BD?= =?us-ascii?Q?RCc8CtPEsm1zMavrWmsiasxO+rCpj+uXTdeyxtMCu8566RC8ekfJw3tVvFGn?= =?us-ascii?Q?mHxxggW85jTP2WHqVNfZw/gkK3cl8tCmAFdM/i+l7fXzbUhbDP/mkdHdUZt7?= =?us-ascii?Q?N9XBXyImLAScz5vpInsc9yH8+0qKTNuD9WPBuNsfna7oSBEvSYka+a4QdBVo?= =?us-ascii?Q?q5q7SFxR+FrTXuTXQEkvI+dvrSrxdTKkPjDVB7Wxd+/61ClzsaaTdOI9Dp3p?= =?us-ascii?Q?KR3k/S2t8Zc92G7d0CFrDZ5sGiwWh3BjaDIentwk7O+ibjf6dGZ5I924EAKq?= =?us-ascii?Q?gcwuHHqQ6CqarSoL9blxx6NrpeBPGqWO7k5nfh1My4XEECetlU2V/DwJcIvt?= =?us-ascii?Q?xkq7+Lz4n6YilJriOlchUpCmF6+3Zqih2M4SXF/00+t7ijyH0LF0q84zc0av?= =?us-ascii?Q?Ze8sW4REHomOi/K8FOQ=3D?= 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)(376014)(7416014)(82310400026)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2025 16:03:53.7554 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a59677cc-1010-4c63-ffab-08de17cdeca6 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: BL02EPF0001A106.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7949 Content-Type: text/plain; charset="utf-8" Add sample code for creating a FwCtl device, getting device info and issuing an RPC. Signed-off-by: Zhi Wang --- include/uapi/fwctl/fwctl.h | 1 + samples/rust/Kconfig | 11 +++ samples/rust/Makefile | 1 + samples/rust/rust_driver_fwctl.rs | 123 ++++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+) create mode 100644 samples/rust/rust_driver_fwctl.rs diff --git a/include/uapi/fwctl/fwctl.h b/include/uapi/fwctl/fwctl.h index 716ac0eee42d..eea1020ad180 100644 --- a/include/uapi/fwctl/fwctl.h +++ b/include/uapi/fwctl/fwctl.h @@ -45,6 +45,7 @@ enum fwctl_device_type { FWCTL_DEVICE_TYPE_MLX5 =3D 1, FWCTL_DEVICE_TYPE_CXL =3D 2, FWCTL_DEVICE_TYPE_PDS =3D 4, + FWCTL_DEVICE_TYPE_RUST_FWCTL_TEST =3D 8, }; =20 /** diff --git a/samples/rust/Kconfig b/samples/rust/Kconfig index c376eb899b7a..54ed2b0b86e2 100644 --- a/samples/rust/Kconfig +++ b/samples/rust/Kconfig @@ -138,6 +138,17 @@ config SAMPLE_RUST_DRIVER_AUXILIARY =20 If unsure, say N. =20 +config SAMPLE_RUST_DRIVER_FWCTL + tristate "Fwctl Driver" + depends on FWCTL + help + This option builds the Rust Fwctl driver sample. + + To compile this as a module, choose M here: + the module will be called rust_driver_fwctl. + + If unsure, say N. + config SAMPLE_RUST_HOSTPROGS bool "Host programs" help diff --git a/samples/rust/Makefile b/samples/rust/Makefile index cf8422f8f219..643208c2380e 100644 --- a/samples/rust/Makefile +++ b/samples/rust/Makefile @@ -12,6 +12,7 @@ obj-$(CONFIG_SAMPLE_RUST_DRIVER_PLATFORM) +=3D rust_drive= r_platform.o obj-$(CONFIG_SAMPLE_RUST_DRIVER_USB) +=3D rust_driver_usb.o obj-$(CONFIG_SAMPLE_RUST_DRIVER_FAUX) +=3D rust_driver_faux.o obj-$(CONFIG_SAMPLE_RUST_DRIVER_AUXILIARY) +=3D rust_driver_auxiliary.o +obj-$(CONFIG_SAMPLE_RUST_DRIVER_FWCTL) +=3D rust_driver_fwctl.o obj-$(CONFIG_SAMPLE_RUST_CONFIGFS) +=3D rust_configfs.o =20 rust_print-y :=3D rust_print_main.o rust_print_events.o diff --git a/samples/rust/rust_driver_fwctl.rs b/samples/rust/rust_driver_f= wctl.rs new file mode 100644 index 000000000000..386299eaf82c --- /dev/null +++ b/samples/rust/rust_driver_fwctl.rs @@ -0,0 +1,123 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Rust fwctl API test (based on QEMU's `pci-testdev`). +//! +//! To make this driver probe, QEMU must be run with `-device pci-testdev`. + +use kernel::{ + bindings, device::Core, fwctl, fwctl::FwCtlOps, fwctl::FwCtlUCtx, pci,= prelude::*, + sync::aref::ARef, +}; + +struct FwCtlSampleUCtx { + _drvdata: u32, +} + +struct FwCtlSampleOps; + +impl FwCtlOps for FwCtlSampleOps { + type UCtx =3D FwCtlSampleUCtx; + + const DEVICE_TYPE: u32 =3D bindings::fwctl_device_type_FWCTL_DEVICE_TY= PE_RUST_FWCTL_TEST as u32; + + fn open_uctx(uctx: &mut FwCtlUCtx) -> Result<(), Erro= r> { + let dev =3D uctx.get_parent_device(); + + dev_info!(dev, "fwctl test driver: open_uctx().\n"); + Ok(()) + } + + fn close_uctx(uctx: &mut FwCtlUCtx) { + let dev =3D uctx.get_parent_device(); + + dev_info!(dev, "fwctl test driver: close_uctx().\n"); + } + + fn info(uctx: &mut FwCtlUCtx) -> Result, Err= or> { + let dev =3D uctx.get_parent_device(); + + dev_info!(dev, "fwctl test driver: info().\n"); + + let mut infobuf =3D KVec::::new(); + infobuf.push(0xef, GFP_KERNEL)?; + infobuf.push(0xbe, GFP_KERNEL)?; + infobuf.push(0xad, GFP_KERNEL)?; + infobuf.push(0xde, GFP_KERNEL)?; + + Ok(infobuf) + } + + fn fw_rpc( + uctx: &mut FwCtlUCtx, + scope: u32, + rpc_in: &mut [u8], + _out_len: *mut usize, + ) -> Result>, Error> { + let dev =3D uctx.get_parent_device(); + + dev_info!(dev, "fwctl test driver: fw_rpc() scope {}.\n", scope); + + if rpc_in.len() !=3D 4 { + return Err(EINVAL); + } + + dev_info!( + dev, + "fwctl test driver: inbuf len{} bytes[0-3] {:x} {:x} {:x} {:x}= .\n", + rpc_in.len(), + rpc_in[0], + rpc_in[1], + rpc_in[2], + rpc_in[3] + ); + + let mut outbuf =3D KVec::::new(); + outbuf.push(0xef, GFP_KERNEL)?; + outbuf.push(0xbe, GFP_KERNEL)?; + outbuf.push(0xad, GFP_KERNEL)?; + outbuf.push(0xde, GFP_KERNEL)?; + + Ok(Some(outbuf)) + } +} + +#[pin_data] +struct FwCtlSampleDriver { + pdev: ARef, + #[pin] + fwctl: fwctl::Registration, +} + +kernel::pci_device_table!( + PCI_TABLE, + MODULE_PCI_TABLE, + ::IdInfo, + [(pci::DeviceId::from_id(pci::Vendor::REDHAT, 0x5), ())] +); + +impl pci::Driver for FwCtlSampleDriver { + type IdInfo =3D (); + const ID_TABLE: pci::IdTable =3D &PCI_TABLE; + + fn probe(pdev: &pci::Device, _info: &Self::IdInfo) -> Result>> { + dev_info!(pdev.as_ref(), "Probe fwctl test driver.\n"); + + let drvdata =3D KBox::pin_init( + try_pin_init!(Self { + pdev: pdev.into(), + fwctl <- fwctl::Registration::::new(pdev.a= s_ref())?, + }), + GFP_KERNEL, + )?; + + Ok(drvdata) + } +} + +kernel::module_pci_driver! { + type: FwCtlSampleDriver, + name: "rust_driver_fwctl", + authors: ["Zhi Wang"], + description: "Rust fwctl test", + license: "GPL v2", +} --=20 2.47.3