From nobody Sat Feb 7 17:48:45 2026 Received: from CO1PR03CU002.outbound.protection.outlook.com (mail-westus2azon11010027.outbound.protection.outlook.com [52.101.46.27]) (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 43929343D93; Thu, 16 Oct 2025 15:02:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.46.27 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760626962; cv=fail; b=svEfrtPRIabt5+0CpC6XyLVdfsrLGSjXn2ABPXylz8Ts58mfWJWEMi8/ojdJd69UtnadH7klM3nFxpsFMhqGOK8U/a577v8hzrrJNb1lXtONdLQw4iSWLtgq+eXIpRt76M2LbhtrPAxl8Xj59GOanCiiJ+ESY7wa+cIiaGXBojM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760626962; c=relaxed/simple; bh=wovZ4vHRNdImhDIvGwObL5iQaBeZOWeQdFDEGHoX/o0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=aNjqPZ3ZvKCbnGbUZZ4dlUSV3f/c4ziE5bI5SOIb4Orx+0ykLaXcfBjJ420sLoXfkvlzFtHxiDRHtHQAj5FO4hEvCT02KWtFfcwzySg6inUoK3AxlbF+peeE6JJfME7Mfp6j/4Z+cpnsu0ENOrsiGZKI2dG3fyNSd1oOWUSsEy4= 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=KHGo8NYe; arc=fail smtp.client-ip=52.101.46.27 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="KHGo8NYe" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Re/gcK7+KedRJfvQ0y7N8CLJa5a1aQdkTGTuctn8qKUS37MRLsW6s57T8NEGyw06AUSOQXAkK5yZgRwaQJTYz34aQdPOtTV24tk5eUfJHSaLCcAeV35xuHQcvJ2+RVr2FkXvNIUrEKWmyOa9p4udT92+UOrGLWHNRXfHm/YE/DDeYQoLjvEwSoXpS5dsaoLkCEMx+mtY+g/O0zoewDpGnvgoGMya2HQjrBFdLL5ood0HaBOa8cZbJwfVK3ogniu0PtDRcgNvwO6P6RCI8HLUxKNyqOBfTDh0B8+MEmS3dBBkjAw/YcWW8ho5dfMwrYKfQyMB9vpOQmVgIsclyhnw2g== 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=cwe+dIK5Pcgh90I58kjFySD2eZyBAH3kwiso7QikAHI=; b=yE5w0oLw1/3celfPjzTdCdFIvm5GKloyT/Xlng+oAfjUDxOPoaBCicFTJ6S0ySgiJje+Il5HRfj+iik/OgMNzOZKH6CwSkGrC66YClGbztalUC1dlmZZ5nsr+2IL+U80oHk3Cyhl+S3gi2u54XGtpjp69z60HAgtdayZXvS6jsYDXx14kKHcfdKsLTLk3SfizjhWgX+8y6uHSFhHg3cehnZ5Ws2XCWgDNVgvCwWg5EVB+i768SSB366y8q3HAjpxOGD13RTio/9TkHt7cbDtC3TgQ0fwzO23lF3jG06vibN1V9hCZ9l4klB4YdbXwaF51RDKYKDP0wBUTdNAtaXSWw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cwe+dIK5Pcgh90I58kjFySD2eZyBAH3kwiso7QikAHI=; b=KHGo8NYe1wjbLKs9SXLWWQmPfzFVMon2gwNBiq+sX2iPx+qrbyVgmRMroR2hB9/UT9+rmljlFIRmgCJRHnK4v1cwUYXp8TuPrGI5nasG7nglGLMt7gtCs7qUquxYg0TCKtNTcL+F7nI6tTeQOuem5tDvf7gx7KpcQWog8YlxwYCZm32gFbyXez8j5Tka1jvtsxDBh6K1+E4aaloQ0Hzg0KzJzknbOlUS2rwcDX1sP2L5DJRxBX1r+sxyQ0Jprg3EznD1A362atW5ui2Tn/YYVnvuz7nQInt/cGmmwN/nUUh9hAEdek3JcTWsapn7aR8P3TPlwz+F4aaBhxy6WZULww== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from SN7PR12MB8059.namprd12.prod.outlook.com (2603:10b6:806:32b::7) by BL3PR12MB6380.namprd12.prod.outlook.com (2603:10b6:208:38d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9228.12; Thu, 16 Oct 2025 15:02:20 +0000 Received: from SN7PR12MB8059.namprd12.prod.outlook.com ([fe80::4ee2:654e:1fe8:4b91]) by SN7PR12MB8059.namprd12.prod.outlook.com ([fe80::4ee2:654e:1fe8:4b91%2]) with mapi id 15.20.9228.010; Thu, 16 Oct 2025 15:02:20 +0000 From: Joel Fernandes To: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, dri-devel@lists.freedesktop.org, dakr@kernel.org, acourbot@nvidia.com Cc: Alistair Popple , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , bjorn3_gh@protonmail.com, Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , David Airlie , Simona Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , John Hubbard , Joel Fernandes , Timur Tabi , joel@joelfernandes.org, Elle Rhumsaa , Yury Norov , Daniel Almeida , nouveau@lists.freedesktop.org Subject: [PATCH v7 1/4] gpu: nova-core: register: use field type for Into implementation Date: Thu, 16 Oct 2025 11:02:01 -0400 Message-Id: <20251016150204.1189641-2-joelagnelf@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251016150204.1189641-1-joelagnelf@nvidia.com> References: <20251016150204.1189641-1-joelagnelf@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BL1P223CA0017.NAMP223.PROD.OUTLOOK.COM (2603:10b6:208:2c4::22) To SN7PR12MB8059.namprd12.prod.outlook.com (2603:10b6:806:32b::7) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN7PR12MB8059:EE_|BL3PR12MB6380:EE_ X-MS-Office365-Filtering-Correlation-Id: 080ea939-cdfa-4970-fbe7-08de0cc50142 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?FSeAGnVzg/dLsw8L98r1J+6bLxb19ydCCnddFIlNwuHcbaAfjkVf12g37WPo?= =?us-ascii?Q?xGMMCgD2c2FphHfqf2xQ2cOJvzCZ6/oNejKXMh5Pzv1Z5McJulM1EjjncvsK?= =?us-ascii?Q?dw2//mz0vcpIBEvWMKc/ZGEGacaMYKKnilRtRscuVL1CeXzrN4pvkLCaUd08?= =?us-ascii?Q?0XJGM8LLV6EbaL2PEzUjsWU3M9BPYZ4bJheMrkvMYeFRtjxOait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E+9kt1xeJDuVRoIGW+8RSDepN5ZKupmvAbIKpUCx9E4aW?= =?us-ascii?Q?KDqv5WUvCmQPshqxtduDhPEYzTFfN02Q87/s5nIzSf68a3M/aYrsoEW1dsvN?= =?us-ascii?Q?mYaVZzprbbcOnQ8iqZ/1swefgB6pjRrtt0WlxMhyvmpz+xKvNYFV95D2tR8j?= =?us-ascii?Q?QFgZ+UbDWALrRT56mfOhg0k4CFTAa7LeKbjjIRifMh7s1d0y18z7421syiud?= =?us-ascii?Q?bH6ZwPh2TmdSAy/18l+xkSSIrCDM6kSUxDOC/OwAEcCatRmTO/UJSgUlpCAE?= =?us-ascii?Q?DHetFBuXhbyGPdpFf4DnDjrp+fbCriDt5CvcWa/+5ltqad1JR6EQGJa7HfFZ?= =?us-ascii?Q?NkBlY8gePn12HNM9bMLoW6BptVimBuTf?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN7PR12MB8059.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(7416014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?QCDIx0CbVte2hBCFcHNl1aMnM6htzJ5QCyIFEZ4Alw471Ml1fnGhVeoGT3ys?= =?us-ascii?Q?HnmneHE+EG+X6MlaPoq50cavwMrXKBA+4Ctbtzwm2NA4CglmcT8yuuRPspbu?= =?us-ascii?Q?jds4qBDhbU7uMlKmTSMG7RGlbQJWU4qJUIZoKwbb/7Pa2OrYBR2sGuie5x8G?= =?us-ascii?Q?qoUkwyZ/yO3e3N8C15lrSRqBCzvRDJGi/v5uweYVW2QqC+YX2UZb/v/zv0n6?= =?us-ascii?Q?BRG6M/9MU7rc2l1WJUi/A0YNT01XU7H7XKabMELsRvul2q6rddF9jdvpnMgA?= =?us-ascii?Q?gnPxX3+Wb0b21DCsEW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PFr8d2IEfBago4vnIGtOF5Ts6sK13iTXidbqxGLZwIy1N4HESXV2wd5C2?= =?us-ascii?Q?ttDi17StKMKGgwFBC9SVcICY2VUo0GSJqJmjIkgfZrEOG8Y9EWNLH2cHVZB5?= =?us-ascii?Q?pWqiVI58O55GWY3FsQfmOGrgBZUdAKJBA2aVZvsczCWHEjuvysSUyeL35yhB?= =?us-ascii?Q?SJ/R0LbTaduBNpgvkIcnTGvp6r2lJ89O2oYYs519n2JkfWnPkhy0U7MIRoXX?= =?us-ascii?Q?KHE+v/p4gEX2i8gFCArcWosuWgD+1mxdth2vrcqIlosShciIBuZXddrbLxAx?= =?us-ascii?Q?qMJwd9rHrd9RX3HMl9qOXEEh4Y20U6dlaRqOXyw9G+M1jUSpKAT1fHsTDHzL?= =?us-ascii?Q?KaBL41+rPQd2uyrlbJu9BgcJB2fvqMY88lUw18zJ?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 080ea939-cdfa-4970-fbe7-08de0cc50142 X-MS-Exchange-CrossTenant-AuthSource: SN7PR12MB8059.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2025 15:02:20.3834 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RWw4whjDuWLXBKiZygOvZfKM3GeF5WschcBOjBG6NciZp55MzSDyL5PHho6HA+Et0Ib1oyp7oDpxbG1IpUUFjw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6380 Content-Type: text/plain; charset="utf-8" From: Alexandre Courbot The getter method of a field works with the field type, but its setter expects the type of the register. This leads to an asymmetry in the From/Into implementations required for a field with a dedicated type. For instance, a field declared as pub struct ControlReg(u32) { 3:0 mode as u8 ?=3D> Mode; ... } currently requires the following implementations: impl TryFrom for Mode { ... } impl From for u32 { ... } Change this so the `From` now needs to be implemented for `u8`, i.e. the primitive type of the field. This is more consistent, and will become a requirement once we start using the TryFrom/Into derive macros to implement these automatically. Reviewed-by: Joel Fernandes Signed-off-by: Alexandre Courbot --- drivers/gpu/nova-core/falcon.rs | 38 ++++++++++++++++++++-------- drivers/gpu/nova-core/regs/macros.rs | 10 ++++---- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/nova-core/falcon.rs b/drivers/gpu/nova-core/falcon= .rs index 37e6298195e4..3f505b870601 100644 --- a/drivers/gpu/nova-core/falcon.rs +++ b/drivers/gpu/nova-core/falcon.rs @@ -22,11 +22,11 @@ pub(crate) mod sec2; =20 // TODO[FPRI]: Replace with `ToPrimitive`. -macro_rules! impl_from_enum_to_u32 { +macro_rules! impl_from_enum_to_u8 { ($enum_type:ty) =3D> { - impl From<$enum_type> for u32 { + impl From<$enum_type> for u8 { fn from(value: $enum_type) -> Self { - value as u32 + value as u8 } } }; @@ -46,7 +46,7 @@ pub(crate) enum FalconCoreRev { Rev6 =3D 6, Rev7 =3D 7, } -impl_from_enum_to_u32!(FalconCoreRev); +impl_from_enum_to_u8!(FalconCoreRev); =20 // TODO[FPRI]: replace with `FromPrimitive`. impl TryFrom for FalconCoreRev { @@ -81,7 +81,7 @@ pub(crate) enum FalconCoreRevSubversion { Subversion2 =3D 2, Subversion3 =3D 3, } -impl_from_enum_to_u32!(FalconCoreRevSubversion); +impl_from_enum_to_u8!(FalconCoreRevSubversion); =20 // TODO[FPRI]: replace with `FromPrimitive`. impl TryFrom for FalconCoreRevSubversion { @@ -125,7 +125,7 @@ pub(crate) enum FalconSecurityModel { /// Also known as High-Secure, Privilege Level 3 or PL3. Heavy =3D 3, } -impl_from_enum_to_u32!(FalconSecurityModel); +impl_from_enum_to_u8!(FalconSecurityModel); =20 // TODO[FPRI]: replace with `FromPrimitive`. impl TryFrom for FalconSecurityModel { @@ -157,7 +157,7 @@ pub(crate) enum FalconModSelAlgo { #[default] Rsa3k =3D 1, } -impl_from_enum_to_u32!(FalconModSelAlgo); +impl_from_enum_to_u8!(FalconModSelAlgo); =20 // TODO[FPRI]: replace with `FromPrimitive`. impl TryFrom for FalconModSelAlgo { @@ -179,7 +179,7 @@ pub(crate) enum DmaTrfCmdSize { #[default] Size256B =3D 0x6, } -impl_from_enum_to_u32!(DmaTrfCmdSize); +impl_from_enum_to_u8!(DmaTrfCmdSize); =20 // TODO[FPRI]: replace with `FromPrimitive`. impl TryFrom for DmaTrfCmdSize { @@ -202,7 +202,6 @@ pub(crate) enum PeregrineCoreSelect { /// RISC-V core is active. Riscv =3D 1, } -impl_from_enum_to_u32!(PeregrineCoreSelect); =20 impl From for PeregrineCoreSelect { fn from(value: bool) -> Self { @@ -213,6 +212,15 @@ fn from(value: bool) -> Self { } } =20 +impl From for bool { + fn from(value: PeregrineCoreSelect) -> Self { + match value { + PeregrineCoreSelect::Falcon =3D> false, + PeregrineCoreSelect::Riscv =3D> true, + } + } +} + /// Different types of memory present in a falcon core. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub(crate) enum FalconMem { @@ -236,7 +244,7 @@ pub(crate) enum FalconFbifTarget { /// Non-coherent system memory (System DRAM). NoncoherentSysmem =3D 2, } -impl_from_enum_to_u32!(FalconFbifTarget); +impl_from_enum_to_u8!(FalconFbifTarget); =20 // TODO[FPRI]: replace with `FromPrimitive`. impl TryFrom for FalconFbifTarget { @@ -263,7 +271,6 @@ pub(crate) enum FalconFbifMemType { /// Physical memory addresses. Physical =3D 1, } -impl_from_enum_to_u32!(FalconFbifMemType); =20 /// Conversion from a single-bit register field. impl From for FalconFbifMemType { @@ -275,6 +282,15 @@ fn from(value: bool) -> Self { } } =20 +impl From for bool { + fn from(value: FalconFbifMemType) -> Self { + match value { + FalconFbifMemType::Virtual =3D> false, + FalconFbifMemType::Physical =3D> true, + } + } +} + /// Type used to represent the `PFALCON` registers address base for a give= n falcon engine. pub(crate) struct PFalconBase(()); =20 diff --git a/drivers/gpu/nova-core/regs/macros.rs b/drivers/gpu/nova-core/r= egs/macros.rs index 8058e1696df9..1c54a4533822 100644 --- a/drivers/gpu/nova-core/regs/macros.rs +++ b/drivers/gpu/nova-core/regs/macros.rs @@ -482,7 +482,7 @@ impl $name { register!( @leaf_accessor $name $hi:$lo $field { |f| <$into_type>::from(if f !=3D 0 { true } else { false }) } - $into_type =3D> $into_type $(, $comment)?; + bool $into_type =3D> $into_type $(, $comment)?; ); }; =20 @@ -499,7 +499,7 @@ impl $name { $(, $comment:literal)?; ) =3D> { register!(@leaf_accessor $name $hi:$lo $field - { |f| <$try_into_type>::try_from(f as $type) } $try_into_type = =3D> + { |f| <$try_into_type>::try_from(f as $type) } $type $try_into= _type =3D> ::core::result::Result< $try_into_type, <$try_into_type as ::core::convert::TryFrom<$type>>::Error @@ -513,7 +513,7 @@ impl $name { $(, $comment:literal)?; ) =3D> { register!(@leaf_accessor $name $hi:$lo $field - { |f| <$into_type>::from(f as $type) } $into_type =3D> $into_t= ype $(, $comment)?;); + { |f| <$into_type>::from(f as $type) } $type $into_type =3D> $= into_type $(, $comment)?;); }; =20 // Shortcut for non-boolean fields defined without the `=3D>` or `?=3D= >` syntax. @@ -527,7 +527,7 @@ impl $name { // Generates the accessor methods for a single field. ( @leaf_accessor $name:ident $hi:tt:$lo:tt $field:ident - { $process:expr } $to_type:ty =3D> $res_type:ty $(, $comment:l= iteral)?; + { $process:expr } $prim_type:tt $to_type:ty =3D> $res_type:ty = $(, $comment:literal)?; ) =3D> { ::kernel::macros::paste!( const [<$field:upper _RANGE>]: ::core::ops::RangeInclusive =3D= $lo..=3D$hi; @@ -559,7 +559,7 @@ pub(crate) fn $field(self) -> $res_type { pub(crate) fn [](mut self, value: $to_type) -> Self { const MASK: u32 =3D $name::[<$field:upper _MASK>]; const SHIFT: u32 =3D $name::[<$field:upper _SHIFT>]; - let value =3D (u32::from(value) << SHIFT) & MASK; + let value =3D (u32::from($prim_type::from(value)) << SHIFT) & = MASK; self.0 =3D (self.0 & !MASK) | value; =20 self --=20 2.34.1 From nobody Sat Feb 7 17:48:45 2026 Received: from SJ2PR03CU001.outbound.protection.outlook.com (mail-westusazon11012063.outbound.protection.outlook.com [52.101.43.63]) (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 C694933439D; Thu, 16 Oct 2025 15:02:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.43.63 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760626957; cv=fail; b=rUWSV32L56EaAJ2H+CJzBKwu7Z4jkqMu4fxLgj+UB7XtZ7Q5t0MbHdTbUkjfdjFpIw94VQOKjnyaD9n5Cn184ff67Hm08BC4GTrnWCYRBIbubuqtYzpr+qv2GWDBUU7JhZceZ0q7q8yjnHwc79QVEZNE5DqAAO+UUsLcxCR2lcc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760626957; c=relaxed/simple; bh=BmbgfAhP3mVrFxTDdxn3NtvEKZh0si17FTYPxoEs1CA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=MPX306dHJ3f18cEa1G2crYjEVp0JJaRQwSOyeVaGmPAlYIvM6TFVlt0Gr83S3h7mLp02fvSneBtuJHl8EUmH2zYf/Y2xWOUQfZpi/zxEjTHErdmT2lPa8xFbw5pItkghKUmFCFXWxEhcXetrm8MgW/G+9pp5fgWmf7pI0hRRF9w= 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=f7OnKQIo; arc=fail smtp.client-ip=52.101.43.63 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="f7OnKQIo" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FI2kJy7K+MvGMbcmKwyNobYpVaLVrmcAOzUq9DEDYwU8sRCOtMZ9/zkI+XqIzMoYa4TnD+xelMRK/UWhX/xEGrk5L5WUo7V6wcescQUg8ZcIICsPs8kLC38YhLtWp86PxhEKZ3ftaZmkl00daB+mP2NzJYpsChDnmPiGod47WgLR0uoRj+RRf3At2U2ttSt79yWoPB9m1trsK4jFtNS7/K8dg6jt/yBFC6egF/jh1rioQIWVfqNdOTyBKwycyCBEdDjCP4EoGLYIy1OxpMEuTjVdcM1yfI/4haYMR487K1J9f4oMzhrcAVNosCmayXPigsdvlY386N0GfpKR/6deIA== 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=6meS+H2iiaBUmgHMHRC9IKBgy8PhGVTZ6C6trHfL+zg=; b=THeCr0uKj6ai9BnGYH5KvcvdaBvq4KxCMQ2JDaZBxs7kkYYCqnYHykH8vUvrBXWLeCLATSH/sJRBfT3vpAJ+m3sEmcOES+We5oks/oeXaTe+yPR0+Wqrx7DmC2YgfjU8KVqS0UgqyDtL2gbk6NdlkRaL8PBZvAAikZcnzWqLWi6mj5FcUbUTZt6KT/KloY4c8idSnCYobZL3mVUc1obfEJbhT0Sic8KR8IQeeQPDY8rlY7VWX+q2LVKvYSC9fogssnyiFrfNR0Z0+jE3/1Od7WSgpb8rBiEcKi4eWU1EftE6W+TnpqzjdvO719oZRR001IsEmHWIKgST0BYgbPL/OQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6meS+H2iiaBUmgHMHRC9IKBgy8PhGVTZ6C6trHfL+zg=; b=f7OnKQIoIzyKvE1rcAR1YKWRXcwIIQOxThRxGevF+zwiD8CJDL0i+K5u1SqhuaGbIoE6SBhbcRQITBlhLUOCzcY8bujbdvrGcfAabr4fyhAdSwDMQB3lVdQR60jRdeITuwi9JCvy8FawllCL2cuhs9Cc575mGkFyt477mnpJaMGiZGCOd8ICKsCFGSk87rfan5NKPWMu6taEtEyo3Hb5vzEUPUSQcHQpbZrbyQA1MARcgZ4MJbz9cnCy5+iSXT3R7o7FcCty/ZGvaBV3gdijdM99xjC3zvKATL6RiuhTPtkaLw5iIvz3Trkz5O0QTqQcf4zURWuRdEi1v4PSzmlHTw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from SN7PR12MB8059.namprd12.prod.outlook.com (2603:10b6:806:32b::7) by BL3PR12MB6380.namprd12.prod.outlook.com (2603:10b6:208:38d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9228.12; Thu, 16 Oct 2025 15:02:23 +0000 Received: from SN7PR12MB8059.namprd12.prod.outlook.com ([fe80::4ee2:654e:1fe8:4b91]) by SN7PR12MB8059.namprd12.prod.outlook.com ([fe80::4ee2:654e:1fe8:4b91%2]) with mapi id 15.20.9228.010; Thu, 16 Oct 2025 15:02:22 +0000 From: Joel Fernandes To: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, dri-devel@lists.freedesktop.org, dakr@kernel.org, acourbot@nvidia.com Cc: Alistair Popple , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , bjorn3_gh@protonmail.com, Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , David Airlie , Simona Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , John Hubbard , Joel Fernandes , Timur Tabi , joel@joelfernandes.org, Elle Rhumsaa , Yury Norov , Daniel Almeida , nouveau@lists.freedesktop.org, Edwin Peer Subject: [PATCH v7 2/4] gpu: nova-core: bitfield: Move bitfield-specific code from register! into new macro Date: Thu, 16 Oct 2025 11:02:02 -0400 Message-Id: <20251016150204.1189641-3-joelagnelf@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251016150204.1189641-1-joelagnelf@nvidia.com> References: <20251016150204.1189641-1-joelagnelf@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BN9PR03CA0593.namprd03.prod.outlook.com (2603:10b6:408:10d::28) To SN7PR12MB8059.namprd12.prod.outlook.com (2603:10b6:806:32b::7) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN7PR12MB8059:EE_|BL3PR12MB6380:EE_ X-MS-Office365-Filtering-Correlation-Id: 3083c798-cc53-4cca-15ce-08de0cc5026d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?dzudhJFNmubVqQtLeEPwzgp6/jG/tTNeSNRCeiH2SiTNhG3QXI0J9nWgL+ti?= =?us-ascii?Q?qNC/EQOX9hM8i/GhL5JK3VbVl1qOVvbeOe9QDkOAHjkWpkifUBeLtu9B903x?= =?us-ascii?Q?uEzosKApbuYUqTZh0yOUUTUfZehFss3CMujzFxPnT1AwUtdHlfj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8sV+pHPukQj9sxVdrbu4/b19fDqOP9m+BW8?= =?us-ascii?Q?Ph7qFlzUsHtkox4dVso5YU+U/Z044ZKt3dVFhflbjO3rTs1wIWZfy4/F+uPl?= =?us-ascii?Q?Sc7vpFq7Ot4M3C/IRPZU0EAw/MzvlP8nAbu/1xf6qKWYKKFB6Sp5gXwNZMux?= =?us-ascii?Q?RqJCcXnIBmIsOsT5CsDaVz8SUheiv1anhTD2FDFBSSdLewxAP2UzeGqpL0A0?= =?us-ascii?Q?ihxOMGXId1YoUMJNvl4Uljgtdp/9UZQmdmcrafrCztn7rOis96JOFN5zyZ78?= =?us-ascii?Q?Ml97QzA32JDVdEXbKmYbNsSFUoVmMiformsWdcv2YirW5jKT8LX8i/RNxTP3?= =?us-ascii?Q?F/eGHK7fTdv1mjnR/gzyzLLZgcLjiYoaQLynkEW/KR+b/Fl2mUf+T4hFeJQy?= =?us-ascii?Q?mLNdP3qbJJqdP2kpToAgY494jFVhN3wk?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN7PR12MB8059.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(7416014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?cuuwIX9FelBUlJfZT+LDiP1GmsxrxfIEguKAnXBlS/Y8kthZUJ91AltxVAvh?= =?us-ascii?Q?x1JNNgPiGDJxv2S/Nk/frAqhRJJkP1h1WYWfvbqdZ8Lq3/v4NEqUVwep82wL?= =?us-ascii?Q?lXEXCwbaKSSb/QdF16Lg9mfQROYRlfGG7y9P8+kIP1ZnzVa5P5CohXW9kqt3?= =?us-ascii?Q?524FpzlNkNp7ZYT7uiIGCjZfZitfB3MHCkB5tTpOHBn23hAr+Sv3ubbISi/E?= =?us-ascii?Q?bVceD9OoaX+G7kVQHo1J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q?ceODEk/+4W2DK1adcZ/OAYA6Rpdxl7cN78p4aOZjIKeHS3D66iXnk02Zs2DV?= =?us-ascii?Q?LSZEElkw+yh9bsuoOwjjPfrXhqay3ZZNKU0d86YV70qQea4cDDapNMEwRl9f?= =?us-ascii?Q?0dFdNGcttvVSaW3b48Z2C098+dFFQNPV2v8LMjCjjRDvtbJK050OIqlOPTqu?= =?us-ascii?Q?f0RNC/nQdiVM1LYRyeHkcXoQ0mbrbt7wt+FDY9epyRaewiuPIOB8eTjkTbkA?= =?us-ascii?Q?4WmxOzmeEORE3RGXcRHEHrCDTI3w+mNXHbiBEl+E41tpNJmA+V6SOASuja+p?= =?us-ascii?Q?7gJ3TJ3z+75sHoVw5xp8RFsYFgsyRRgP8eFj+nri4bF6lL2ljGWveAxlfWGu?= =?us-ascii?Q?8jh1LVZFJ/A/FwJFFXtsEkWTLYoYmdaDvgmO2cFW4L7lDxEgTTX351ThQjGF?= =?us-ascii?Q?g+oumxCuu3WBFMttXA5rJxn7LhEh/lHWTA3ZRD3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3083c798-cc53-4cca-15ce-08de0cc5026d X-MS-Exchange-CrossTenant-AuthSource: SN7PR12MB8059.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2025 15:02:22.3952 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 9YHCJpUTYBKDjxMVeC9kjQCHz86JNldyjORWPMkPqoYjbLQ8axiwA/MJ7RCc3Xe1Sofg/UkAmd37nz2pchJ0yg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6380 Content-Type: text/plain; charset="utf-8" The bitfield-specific into new macro. This will be used to define structs with bitfields, similar to C language. Reviewed-by: Elle Rhumsaa Reviewed-by: Alexandre Courbot Reviewed-by: Edwin Peer Signed-off-by: Joel Fernandes --- drivers/gpu/nova-core/bitfield.rs | 319 +++++++++++++++++++++++++++ drivers/gpu/nova-core/nova_core.rs | 3 + drivers/gpu/nova-core/regs/macros.rs | 259 +--------------------- 3 files changed, 332 insertions(+), 249 deletions(-) create mode 100644 drivers/gpu/nova-core/bitfield.rs diff --git a/drivers/gpu/nova-core/bitfield.rs b/drivers/gpu/nova-core/bitf= ield.rs new file mode 100644 index 000000000000..98ccb1bd3289 --- /dev/null +++ b/drivers/gpu/nova-core/bitfield.rs @@ -0,0 +1,319 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Bitfield library for Rust structures +//! +//! Support for defining bitfields in Rust structures. Also used by the [`= register!`] macro. + +/// Defines a struct with accessors to access bits within an inner unsigne= d integer. +/// +/// # Syntax +/// +/// ```rust +/// use nova_core::bitfield; +/// +/// #[derive(Debug, Clone, Copy, Default)] +/// enum Mode { +/// #[default] +/// Low =3D 0, +/// High =3D 1, +/// Auto =3D 2, +/// } +/// +/// impl TryFrom for Mode { +/// type Error =3D u8; +/// fn try_from(value: u8) -> Result { +/// match value { +/// 0 =3D> Ok(Mode::Low), +/// 1 =3D> Ok(Mode::High), +/// 2 =3D> Ok(Mode::Auto), +/// _ =3D> Err(value), +/// } +/// } +/// } +/// +/// impl From for u8 { +/// fn from(mode: Mode) -> u8 { +/// mode as u8 +/// } +/// } +/// +/// #[derive(Debug, Clone, Copy, Default)] +/// enum State { +/// #[default] +/// Inactive =3D 0, +/// Active =3D 1, +/// } +/// +/// impl From for State { +/// fn from(value: bool) -> Self { +/// if value { State::Active } else { State::Inactive } +/// } +/// } +/// +/// impl From for bool { +/// fn from(state: State) -> bool { +/// match state { +/// State::Inactive =3D> false, +/// State::Active =3D> true, +/// } +/// } +/// } +/// +/// bitfield! { +/// struct ControlReg { +/// 3:0 mode as u8 ?=3D> Mode; +/// 7:7 state as bool =3D> State; +/// } +/// } +/// ``` +/// +/// This generates a struct with: +/// - Field accessors: `mode()`, `state()`, etc. +/// - Field setters: `set_mode()`, `set_state()`, etc. (supports chaining = with builder pattern). +/// - Debug and Default implementations. +/// +/// Fields are defined as follows: +/// +/// - `as ` simply returns the field value casted to , typical= ly `u32`, `u16`, `u8` or +/// `bool`. Note that `bool` fields must have a range of 1 bit. +/// - `as =3D> ` calls ``'s `From::<>` = implementation and returns +/// the result. +/// - `as ?=3D> ` calls ``'s `TryFrom= ::<>` implementation +/// and returns the result. This is useful with fields for which not all= values are valid. +macro_rules! bitfield { + // Main entry point - defines the bitfield struct with fields + (struct $name:ident $(, $comment:literal)? { $($fields:tt)* }) =3D> { + bitfield!(@core $name $(, $comment)? { $($fields)* }); + }; + + // All rules below are helpers. + + // Defines the wrapper `$name` type, as well as its relevant implement= ations (`Debug`, + // `Default`, `BitOr`, and conversion to the value type) and field acc= essor methods. + (@core $name:ident $(, $comment:literal)? { $($fields:tt)* }) =3D> { + $( + #[doc=3D$comment] + )? + #[repr(transparent)] + #[derive(Clone, Copy)] + pub(crate) struct $name(u32); + + impl ::core::ops::BitOr for $name { + type Output =3D Self; + + fn bitor(self, rhs: Self) -> Self::Output { + Self(self.0 | rhs.0) + } + } + + impl ::core::convert::From<$name> for u32 { + fn from(val: $name) -> u32 { + val.0 + } + } + + bitfield!(@fields_dispatcher $name { $($fields)* }); + }; + + // Captures the fields and passes them to all the implementers that re= quire field information. + // + // Used to simplify the matching rules for implementers, so they don't= need to match the entire + // complex fields rule even though they only make use of part of it. + (@fields_dispatcher $name:ident { + $($hi:tt:$lo:tt $field:ident as $type:tt + $(?=3D> $try_into_type:ty)? + $(=3D> $into_type:ty)? + $(, $comment:literal)? + ; + )* + } + ) =3D> { + bitfield!(@field_accessors $name { + $( + $hi:$lo $field as $type + $(?=3D> $try_into_type)? + $(=3D> $into_type)? + $(, $comment)? + ; + )* + }); + bitfield!(@debug $name { $($field;)* }); + bitfield!(@default $name { $($field;)* }); + }; + + // Defines all the field getter/setter methods for `$name`. + ( + @field_accessors $name:ident { + $($hi:tt:$lo:tt $field:ident as $type:tt + $(?=3D> $try_into_type:ty)? + $(=3D> $into_type:ty)? + $(, $comment:literal)? + ; + )* + } + ) =3D> { + $( + bitfield!(@check_field_bounds $hi:$lo $field as $type); + )* + + #[allow(dead_code)] + impl $name { + $( + bitfield!(@field_accessor $name $hi:$lo $field as $type + $(?=3D> $try_into_type)? + $(=3D> $into_type)? + $(, $comment)? + ; + ); + )* + } + }; + + // Boolean fields must have `$hi =3D=3D $lo`. + (@check_field_bounds $hi:tt:$lo:tt $field:ident as bool) =3D> { + #[allow(clippy::eq_op)] + const _: () =3D { + ::kernel::build_assert!( + $hi =3D=3D $lo, + concat!("boolean field `", stringify!($field), "` covers m= ore than one bit") + ); + }; + }; + + // Non-boolean fields must have `$hi >=3D $lo`. + (@check_field_bounds $hi:tt:$lo:tt $field:ident as $type:tt) =3D> { + #[allow(clippy::eq_op)] + const _: () =3D { + ::kernel::build_assert!( + $hi >=3D $lo, + concat!("field `", stringify!($field), "`'s MSB is smaller= than its LSB") + ); + }; + }; + + // Catches fields defined as `bool` and convert them into a boolean va= lue. + ( + @field_accessor $name:ident $hi:tt:$lo:tt $field:ident as bool =3D= > $into_type:ty + $(, $comment:literal)?; + ) =3D> { + bitfield!( + @leaf_accessor $name $hi:$lo $field + { |f| <$into_type>::from(if f !=3D 0 { true } else { false }) } + bool $into_type =3D> $into_type $(, $comment)?; + ); + }; + + // Shortcut for fields defined as `bool` without the `=3D>` syntax. + ( + @field_accessor $name:ident $hi:tt:$lo:tt $field:ident as bool $(,= $comment:literal)?; + ) =3D> { + bitfield!(@field_accessor $name $hi:$lo $field as bool =3D> bool $= (, $comment)?;); + }; + + // Catches the `?=3D>` syntax for non-boolean fields. + ( + @field_accessor $name:ident $hi:tt:$lo:tt $field:ident as $type:tt= ?=3D> $try_into_type:ty + $(, $comment:literal)?; + ) =3D> { + bitfield!(@leaf_accessor $name $hi:$lo $field + { |f| <$try_into_type>::try_from(f as $type) } $type $try_into= _type =3D> + ::core::result::Result< + $try_into_type, + <$try_into_type as ::core::convert::TryFrom<$type>>::Error + > + $(, $comment)?;); + }; + + // Catches the `=3D>` syntax for non-boolean fields. + ( + @field_accessor $name:ident $hi:tt:$lo:tt $field:ident as $type:tt= =3D> $into_type:ty + $(, $comment:literal)?; + ) =3D> { + bitfield!(@leaf_accessor $name $hi:$lo $field + { |f| <$into_type>::from(f as $type) } $type $into_type =3D> $= into_type $(, $comment)?;); + }; + + // Shortcut for non-boolean fields defined without the `=3D>` or `?=3D= >` syntax. + ( + @field_accessor $name:ident $hi:tt:$lo:tt $field:ident as $type:tt + $(, $comment:literal)?; + ) =3D> { + bitfield!(@field_accessor $name $hi:$lo $field as $type =3D> $type= $(, $comment)?;); + }; + + // Generates the accessor methods for a single field. + ( + @leaf_accessor $name:ident $hi:tt:$lo:tt $field:ident + { $process:expr } $prim_type:tt $to_type:ty =3D> $res_type:ty = $(, $comment:literal)?; + ) =3D> { + ::kernel::macros::paste!( + const [<$field:upper _RANGE>]: ::core::ops::RangeInclusive =3D= $lo..=3D$hi; + const [<$field:upper _MASK>]: u32 =3D ((((1 << $hi) - 1) << 1) + 1= ) - ((1 << $lo) - 1); + const [<$field:upper _SHIFT>]: u32 =3D Self::[<$field:upper _MASK>= ].trailing_zeros(); + ); + + $( + #[doc=3D"Returns the value of this field:"] + #[doc=3D$comment] + )? + #[inline(always)] + pub(crate) fn $field(self) -> $res_type { + ::kernel::macros::paste!( + const MASK: u32 =3D $name::[<$field:upper _MASK>]; + const SHIFT: u32 =3D $name::[<$field:upper _SHIFT>]; + ); + let field =3D ((self.0 & MASK) >> SHIFT); + + $process(field) + } + + ::kernel::macros::paste!( + $( + #[doc=3D"Sets the value of this field:"] + #[doc=3D$comment] + )? + #[inline(always)] + pub(crate) fn [](mut self, value: $to_type) -> Self { + const MASK: u32 =3D $name::[<$field:upper _MASK>]; + const SHIFT: u32 =3D $name::[<$field:upper _SHIFT>]; + let value =3D (u32::from($prim_type::from(value)) << SHIFT) & = MASK; + self.0 =3D (self.0 & !MASK) | value; + + self + } + ); + }; + + // Generates the `Debug` implementation for `$name`. + (@debug $name:ident { $($field:ident;)* }) =3D> { + impl ::kernel::fmt::Debug for $name { + fn fmt(&self, f: &mut ::kernel::fmt::Formatter<'_>) -> ::kerne= l::fmt::Result { + f.debug_struct(stringify!($name)) + .field("", &::kernel::prelude::fmt!("{:#x}", &sel= f.0)) + $( + .field(stringify!($field), &self.$field()) + )* + .finish() + } + } + }; + + // Generates the `Default` implementation for `$name`. + (@default $name:ident { $($field:ident;)* }) =3D> { + /// Returns a value for the bitfield where all fields are set to t= heir default value. + impl ::core::default::Default for $name { + fn default() -> Self { + #[allow(unused_mut)] + let mut value =3D Self(Default::default()); + + ::kernel::macros::paste!( + $( + value.[](Default::default()); + )* + ); + + value + } + } + }; +} diff --git a/drivers/gpu/nova-core/nova_core.rs b/drivers/gpu/nova-core/nov= a_core.rs index fffcaee2249f..112277c7921e 100644 --- a/drivers/gpu/nova-core/nova_core.rs +++ b/drivers/gpu/nova-core/nova_core.rs @@ -2,6 +2,9 @@ =20 //! Nova Core GPU Driver =20 +#[macro_use] +mod bitfield; + mod dma; mod driver; mod falcon; diff --git a/drivers/gpu/nova-core/regs/macros.rs b/drivers/gpu/nova-core/r= egs/macros.rs index 1c54a4533822..945d15a2c529 100644 --- a/drivers/gpu/nova-core/regs/macros.rs +++ b/drivers/gpu/nova-core/regs/macros.rs @@ -8,7 +8,8 @@ //! //! The `register!` macro in this module provides an intuitive and readabl= e syntax for defining a //! dedicated type for each register. Each such type comes with its own fi= eld accessors that can -//! return an error if a field's value is invalid. +//! return an error if a field's value is invalid. Please look at the [`bi= tfield`] macro for the +//! complete syntax of fields definitions. =20 /// Trait providing a base address to be added to the offset of a relative= register to obtain /// its actual offset. @@ -54,15 +55,6 @@ pub(crate) trait RegisterBase { /// BOOT_0::alter(&bar, |r| r.set_major_revision(3).set_minor_revision(10)= ); /// ``` /// -/// Fields are defined as follows: -/// -/// - `as ` simply returns the field value casted to , typical= ly `u32`, `u16`, `u8` or -/// `bool`. Note that `bool` fields must have a range of 1 bit. -/// - `as =3D> ` calls ``'s `From::<>` = implementation and returns -/// the result. -/// - `as ?=3D> ` calls ``'s `TryFrom= ::<>` implementation -/// and returns the result. This is useful with fields for which not all= values are valid. -/// /// The documentation strings are optional. If present, they will be added= to the type's /// definition, or the field getter and setter methods they are attached t= o. /// @@ -284,25 +276,25 @@ pub(crate) trait RegisterBase { macro_rules! register { // Creates a register at a fixed offset of the MMIO space. ($name:ident @ $offset:literal $(, $comment:literal)? { $($fields:tt)*= } ) =3D> { - register!(@core $name $(, $comment)? { $($fields)* } ); + bitfield!(struct $name $(, $comment)? { $($fields)* } ); register!(@io_fixed $name @ $offset); }; =20 // Creates an alias register of fixed offset register `alias` with its= own fields. ($name:ident =3D> $alias:ident $(, $comment:literal)? { $($fields:tt)*= } ) =3D> { - register!(@core $name $(, $comment)? { $($fields)* } ); + bitfield!(struct $name $(, $comment)? { $($fields)* } ); register!(@io_fixed $name @ $alias::OFFSET); }; =20 // Creates a register at a relative offset from a base address provide= r. ($name:ident @ $base:ty [ $offset:literal ] $(, $comment:literal)? { $= ($fields:tt)* } ) =3D> { - register!(@core $name $(, $comment)? { $($fields)* } ); + bitfield!(struct $name $(, $comment)? { $($fields)* } ); register!(@io_relative $name @ $base [ $offset ]); }; =20 // Creates an alias register of relative offset register `alias` with = its own fields. ($name:ident =3D> $base:ty [ $alias:ident ] $(, $comment:literal)? { $= ($fields:tt)* }) =3D> { - register!(@core $name $(, $comment)? { $($fields)* } ); + bitfield!(struct $name $(, $comment)? { $($fields)* } ); register!(@io_relative $name @ $base [ $alias::OFFSET ]); }; =20 @@ -313,7 +305,7 @@ macro_rules! register { } ) =3D> { static_assert!(::core::mem::size_of::() <=3D $stride); - register!(@core $name $(, $comment)? { $($fields)* } ); + bitfield!(struct $name $(, $comment)? { $($fields)* } ); register!(@io_array $name @ $offset [ $size ; $stride ]); }; =20 @@ -334,7 +326,7 @@ macro_rules! register { $(, $comment:literal)? { $($fields:tt)* } ) =3D> { static_assert!(::core::mem::size_of::() <=3D $stride); - register!(@core $name $(, $comment)? { $($fields)* } ); + bitfield!(struct $name $(, $comment)? { $($fields)* } ); register!(@io_relative_array $name @ $base [ $offset [ $size ; $st= ride ] ]); }; =20 @@ -356,7 +348,7 @@ macro_rules! register { } ) =3D> { static_assert!($idx < $alias::SIZE); - register!(@core $name $(, $comment)? { $($fields)* } ); + bitfield!(struct $name $(, $comment)? { $($fields)* } ); register!(@io_relative $name @ $base [ $alias::OFFSET + $idx * $al= ias::STRIDE ] ); }; =20 @@ -365,241 +357,10 @@ macro_rules! register { // to avoid it being interpreted in place of the relative register arr= ay alias rule. ($name:ident =3D> $alias:ident [ $idx:expr ] $(, $comment:literal)? { = $($fields:tt)* }) =3D> { static_assert!($idx < $alias::SIZE); - register!(@core $name $(, $comment)? { $($fields)* } ); + bitfield!(struct $name $(, $comment)? { $($fields)* } ); register!(@io_fixed $name @ $alias::OFFSET + $idx * $alias::STRIDE= ); }; =20 - // All rules below are helpers. - - // Defines the wrapper `$name` type, as well as its relevant implement= ations (`Debug`, - // `Default`, `BitOr`, and conversion to the value type) and field acc= essor methods. - (@core $name:ident $(, $comment:literal)? { $($fields:tt)* }) =3D> { - $( - #[doc=3D$comment] - )? - #[repr(transparent)] - #[derive(Clone, Copy)] - pub(crate) struct $name(u32); - - impl ::core::ops::BitOr for $name { - type Output =3D Self; - - fn bitor(self, rhs: Self) -> Self::Output { - Self(self.0 | rhs.0) - } - } - - impl ::core::convert::From<$name> for u32 { - fn from(reg: $name) -> u32 { - reg.0 - } - } - - register!(@fields_dispatcher $name { $($fields)* }); - }; - - // Captures the fields and passes them to all the implementers that re= quire field information. - // - // Used to simplify the matching rules for implementers, so they don't= need to match the entire - // complex fields rule even though they only make use of part of it. - (@fields_dispatcher $name:ident { - $($hi:tt:$lo:tt $field:ident as $type:tt - $(?=3D> $try_into_type:ty)? - $(=3D> $into_type:ty)? - $(, $comment:literal)? - ; - )* - } - ) =3D> { - register!(@field_accessors $name { - $( - $hi:$lo $field as $type - $(?=3D> $try_into_type)? - $(=3D> $into_type)? - $(, $comment)? - ; - )* - }); - register!(@debug $name { $($field;)* }); - register!(@default $name { $($field;)* }); - }; - - // Defines all the field getter/methods methods for `$name`. - ( - @field_accessors $name:ident { - $($hi:tt:$lo:tt $field:ident as $type:tt - $(?=3D> $try_into_type:ty)? - $(=3D> $into_type:ty)? - $(, $comment:literal)? - ; - )* - } - ) =3D> { - $( - register!(@check_field_bounds $hi:$lo $field as $type); - )* - - #[allow(dead_code)] - impl $name { - $( - register!(@field_accessor $name $hi:$lo $field as $type - $(?=3D> $try_into_type)? - $(=3D> $into_type)? - $(, $comment)? - ; - ); - )* - } - }; - - // Boolean fields must have `$hi =3D=3D $lo`. - (@check_field_bounds $hi:tt:$lo:tt $field:ident as bool) =3D> { - #[allow(clippy::eq_op)] - const _: () =3D { - ::kernel::build_assert!( - $hi =3D=3D $lo, - concat!("boolean field `", stringify!($field), "` covers m= ore than one bit") - ); - }; - }; - - // Non-boolean fields must have `$hi >=3D $lo`. - (@check_field_bounds $hi:tt:$lo:tt $field:ident as $type:tt) =3D> { - #[allow(clippy::eq_op)] - const _: () =3D { - ::kernel::build_assert!( - $hi >=3D $lo, - concat!("field `", stringify!($field), "`'s MSB is smaller= than its LSB") - ); - }; - }; - - // Catches fields defined as `bool` and convert them into a boolean va= lue. - ( - @field_accessor $name:ident $hi:tt:$lo:tt $field:ident as bool =3D= > $into_type:ty - $(, $comment:literal)?; - ) =3D> { - register!( - @leaf_accessor $name $hi:$lo $field - { |f| <$into_type>::from(if f !=3D 0 { true } else { false }) } - bool $into_type =3D> $into_type $(, $comment)?; - ); - }; - - // Shortcut for fields defined as `bool` without the `=3D>` syntax. - ( - @field_accessor $name:ident $hi:tt:$lo:tt $field:ident as bool $(,= $comment:literal)?; - ) =3D> { - register!(@field_accessor $name $hi:$lo $field as bool =3D> bool $= (, $comment)?;); - }; - - // Catches the `?=3D>` syntax for non-boolean fields. - ( - @field_accessor $name:ident $hi:tt:$lo:tt $field:ident as $type:tt= ?=3D> $try_into_type:ty - $(, $comment:literal)?; - ) =3D> { - register!(@leaf_accessor $name $hi:$lo $field - { |f| <$try_into_type>::try_from(f as $type) } $type $try_into= _type =3D> - ::core::result::Result< - $try_into_type, - <$try_into_type as ::core::convert::TryFrom<$type>>::Error - > - $(, $comment)?;); - }; - - // Catches the `=3D>` syntax for non-boolean fields. - ( - @field_accessor $name:ident $hi:tt:$lo:tt $field:ident as $type:tt= =3D> $into_type:ty - $(, $comment:literal)?; - ) =3D> { - register!(@leaf_accessor $name $hi:$lo $field - { |f| <$into_type>::from(f as $type) } $type $into_type =3D> $= into_type $(, $comment)?;); - }; - - // Shortcut for non-boolean fields defined without the `=3D>` or `?=3D= >` syntax. - ( - @field_accessor $name:ident $hi:tt:$lo:tt $field:ident as $type:tt - $(, $comment:literal)?; - ) =3D> { - register!(@field_accessor $name $hi:$lo $field as $type =3D> $type= $(, $comment)?;); - }; - - // Generates the accessor methods for a single field. - ( - @leaf_accessor $name:ident $hi:tt:$lo:tt $field:ident - { $process:expr } $prim_type:tt $to_type:ty =3D> $res_type:ty = $(, $comment:literal)?; - ) =3D> { - ::kernel::macros::paste!( - const [<$field:upper _RANGE>]: ::core::ops::RangeInclusive =3D= $lo..=3D$hi; - const [<$field:upper _MASK>]: u32 =3D ((((1 << $hi) - 1) << 1) + 1= ) - ((1 << $lo) - 1); - const [<$field:upper _SHIFT>]: u32 =3D Self::[<$field:upper _MASK>= ].trailing_zeros(); - ); - - $( - #[doc=3D"Returns the value of this field:"] - #[doc=3D$comment] - )? - #[inline(always)] - pub(crate) fn $field(self) -> $res_type { - ::kernel::macros::paste!( - const MASK: u32 =3D $name::[<$field:upper _MASK>]; - const SHIFT: u32 =3D $name::[<$field:upper _SHIFT>]; - ); - let field =3D ((self.0 & MASK) >> SHIFT); - - $process(field) - } - - ::kernel::macros::paste!( - $( - #[doc=3D"Sets the value of this field:"] - #[doc=3D$comment] - )? - #[inline(always)] - pub(crate) fn [](mut self, value: $to_type) -> Self { - const MASK: u32 =3D $name::[<$field:upper _MASK>]; - const SHIFT: u32 =3D $name::[<$field:upper _SHIFT>]; - let value =3D (u32::from($prim_type::from(value)) << SHIFT) & = MASK; - self.0 =3D (self.0 & !MASK) | value; - - self - } - ); - }; - - // Generates the `Debug` implementation for `$name`. - (@debug $name:ident { $($field:ident;)* }) =3D> { - impl ::kernel::fmt::Debug for $name { - fn fmt(&self, f: &mut ::kernel::fmt::Formatter<'_>) -> ::kerne= l::fmt::Result { - f.debug_struct(stringify!($name)) - .field("", &::kernel::prelude::fmt!("{:#x}", &sel= f.0)) - $( - .field(stringify!($field), &self.$field()) - )* - .finish() - } - } - }; - - // Generates the `Default` implementation for `$name`. - (@default $name:ident { $($field:ident;)* }) =3D> { - /// Returns a value for the register where all fields are set to t= heir default value. - impl ::core::default::Default for $name { - fn default() -> Self { - #[allow(unused_mut)] - let mut value =3D Self(Default::default()); - - ::kernel::macros::paste!( - $( - value.[](Default::default()); - )* - ); - - value - } - } - }; - // Generates the IO accessors for a fixed offset register. (@io_fixed $name:ident @ $offset:expr) =3D> { #[allow(dead_code)] --=20 2.34.1 From nobody Sat Feb 7 17:48:45 2026 Received: from CO1PR03CU002.outbound.protection.outlook.com (mail-westus2azon11010027.outbound.protection.outlook.com [52.101.46.27]) (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 3A165345740; Thu, 16 Oct 2025 15:02:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.46.27 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760626964; cv=fail; b=TVUKFLrHrb8yYz9e99XY5v88jud6eO7Jr4OPUf4nxZZTZBIilUQtmbByO9kyp5T0N1IG0q3sfgz+wsAal6jgra3IqI2BCpuBnvD1p/xgx9wIKi1nnjyeUaLSF+Gb05vD1EjmlI9N222EskXOmRYnnBbkk14Eh9qHWYreOKECREk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760626964; c=relaxed/simple; bh=6hlbJswMk7j1m70PmNFdfDHNDABkRdQyWsqD3gY78VA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=O7iiKUnEXh6Gmu3NjJS32sILWPD3DTpcCB2uOeM9vA6/KkZjXrpW3ELinyfUtbKUiN5ksGmrym0PLNw9OAWXUrd/mThMcr6dO/EdSSms/6pZu1i8B5krdD/UTzy4aWZ0qELJ+hcG/a5JzPqMBw7zujCW78fonAs1bBFJip7Wpcc= 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=pUHD2G2o; arc=fail smtp.client-ip=52.101.46.27 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="pUHD2G2o" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=K53inIlQo6c4GrJJPdUqjb6oG4ipPeJ5nxFTLQsZE/lrAztj0X8x9QLWF+PZIy3YfvZqmC4qdbFxO6clYDrtzJwd0aMcHfysKDlpxmLyMXzx/MXk+YlwGYaoNmPEz+zhRQiianm2mktODE144P6haz4T+hBWqiAv6CEg3XPJqFIL4vnngmpG8nPu4GvCwSfcX88lCRZxoVvwkO2QEj+fWVHjKE5eTrTTE6imlEh2kFm2AJVpbGSn6qY+oJnkVunOqJzH19sLDnH0EtxU4GGW8Bs/WugCb3yFexWpYEZlGLGKCEGkMPoRJKfi24osOL1617fJ5MfyBXsNNLU3VjoidQ== 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=TazYopQhfj9fBNDwyQfsHCkjf/N0cmGySrdPC+y7YyY=; b=jBW6ohQC0uzISpil/P5CVJxW8I0s+DklyLAN7dMhIx2v6Xl0TihFE3fCdxxcZVVFv1m2Tb4AKlb1V4mTk/9GXmJRovHkNTKT+illuxTB+I7cxBHHLbqWBy+C7Z/dH6p/HzrApNaME87mH+Ygp/xi4ReMFh3vix8sqMiE7jl0l6KtUBwv2sSudmgQt0p9obUm8IafB/e106SdPCxBBJaJJSYkEog3WmOlENq/Iru7ZO+DXwsDLPT4k0OXFzAqNN77cK5TuW23fBZnCdLj6o9uhYrwOucORS1fXx+8mvy1fbkX5j25vJjyYkut8OF6HmYiOIxHHocNCwPzQBbd70xZnw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TazYopQhfj9fBNDwyQfsHCkjf/N0cmGySrdPC+y7YyY=; b=pUHD2G2oMzL71icmiXeHxkbALsdBcTyTyzZ3bYXpafrRRT//8/KqavvEDuZlVpg76WFo0NHRP7R+Rt6qy47pO2FtrBC4HdloazeURgtziaRB+OUNuMrJse/uhFn/WQ3wRaAp91wk44sUVcBMWa8/BMeYD2DjAOnaXa59N7bMot7wdMI3f+ZmNzGtMHHroSO3+a1nj7RY9HucqnhLjHASN+ovPTlCtFVv/n3o0slqZS03m7Nc81zJTHSUNqA2p9Ux4YneFB+WSwtKWQF6i2DJT3lJIuEP8qlRj6a9S/pVc9IpgpLJqXVWpNJtzvaVbnDNlOC+9vXInCXQxUVZtBLxQQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from SN7PR12MB8059.namprd12.prod.outlook.com (2603:10b6:806:32b::7) by BL3PR12MB6380.namprd12.prod.outlook.com (2603:10b6:208:38d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9228.12; Thu, 16 Oct 2025 15:02:30 +0000 Received: from SN7PR12MB8059.namprd12.prod.outlook.com ([fe80::4ee2:654e:1fe8:4b91]) by SN7PR12MB8059.namprd12.prod.outlook.com ([fe80::4ee2:654e:1fe8:4b91%2]) with mapi id 15.20.9228.010; Thu, 16 Oct 2025 15:02:30 +0000 From: Joel Fernandes To: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, dri-devel@lists.freedesktop.org, dakr@kernel.org, acourbot@nvidia.com Cc: Alistair Popple , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , bjorn3_gh@protonmail.com, Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , David Airlie , Simona Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , John Hubbard , Joel Fernandes , Timur Tabi , joel@joelfernandes.org, Elle Rhumsaa , Yury Norov , Daniel Almeida , nouveau@lists.freedesktop.org, Edwin Peer Subject: [PATCH v7 3/4] gpu: nova-core: bitfield: Add support for different storage widths Date: Thu, 16 Oct 2025 11:02:03 -0400 Message-Id: <20251016150204.1189641-4-joelagnelf@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251016150204.1189641-1-joelagnelf@nvidia.com> References: <20251016150204.1189641-1-joelagnelf@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BL1PR13CA0327.namprd13.prod.outlook.com (2603:10b6:208:2c1::32) To SN7PR12MB8059.namprd12.prod.outlook.com (2603:10b6:806:32b::7) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN7PR12MB8059:EE_|BL3PR12MB6380:EE_ X-MS-Office365-Filtering-Correlation-Id: 2e4436de-bc25-4ec7-c848-08de0cc5073c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?upUFFrefxbncbQEIkUInISJHPmYMfkKqSchyP4EpjQYVwT7M+ck7h/TFgmg8?= =?us-ascii?Q?bZP6+3qPlx0UBRPoyr6TdB6yt26Z4O5SnF37Eg8ZZ//rDzhX37rulbMZ1iF5?= =?us-ascii?Q?0C4Fxd7xB2R0gDqIxCNJb1QyRlUnUCNd3yvBUrtRinL8ynvzrf39a7SviKcs?= =?us-ascii?Q?zCEciUYEH4Pj8yoC9aB1U31MlHUJ3M/N34SLZNeUMAMeZZum4U2QBbE1ETmO?= =?us-ascii?Q?GUdm1XjaYQsPGFb50YedImm1x1KM6SYd1XfdZTCIukgNICfTFHxOv3ouYVhR?= =?us-ascii?Q?fSKmbPmD/75NTIGs6IZ+X9Fwb8/EzMUUNNF8zQgv2gWdKOWVdFsC0rXHVXTw?= =?us-ascii?Q?sIU6gIck+sbWaPkDTuM5L2YmZk21HzuUTtD+3g3eReMlApN+7nwJW4/laM/R?= =?us-ascii?Q?/hhsBu4pEfWyciout4gIP3Cd1yIPhmhlWopaMD72/v8Bt04rbl+TXPswrd6D?= =?us-ascii?Q?csW7o97LllwT+6IMiPFNLTHHtjtzODlJ19rdPltTdJ9KBHZK8hxNC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pubOyNp2jl+6zgQgBkrWbKhiTG+O?= =?us-ascii?Q?Pq9tuEP47VlC3aavNvXE8YAmijY+Ajx/?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN7PR12MB8059.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(7416014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?ktVVVBQ7ZZ8si/8d2vZKnXNNoXVtllBLms9VFnlve5TFM8UjzkWOPD/1lhRf?= =?us-ascii?Q?dxk1WiczeJjZK8KEwTeHlS3TZNlgq1Cg5W+zWrP3FePjAh0CSJvkHTYjbOlT?= =?us-ascii?Q?FO3K5PzkyQaiEIuZbvpjIVxKe3IeQ9TwNgHKxtGpD9RsY4L0C/MjiXYKZYn+?= =?us-ascii?Q?RpxRmMLGC/DAUemNJcClp/yyeArnBb9iP/xlKK76bFzw+TCL26biDOmH7kuM?= =?us-ascii?Q?Mh33jsFs1zDmgycAkmRdx7jw0FITWCVMemXNRRrspS1IEyBYMXDhDQUHzTHx?= =?us-ascii?Q?eOsiZN7FvEDK6sCH0SQ8DPI3gAdPgacSVQrChobr2zE7J302x1LGTsep4rAV?= =?us-ascii?Q?tW2JliBn4Pvqwj7sztQL2hUxFZBQaXPmXX5pjjVybVf5RXV/311eu14VcG3Z?= =?us-ascii?Q?yeVAiT5p5AV89B3nqjhKgizJa6FlSJOaBZjy9b4PChVvLmhj4u9RXm8p0V2l?= =?us-ascii?Q?CVH89SNsbZkl0qx3PmduZjcstaiy+whZsTYBReSnNSvMZ1Rtv9W+hzVL4d/A?= =?us-ascii?Q?5XmwT1oJackw5CNStAOdeMR74t7GLNVfFHu5pS7cdR7uIrZ+9267cxHlKA5A?= =?us-ascii?Q?TI3HViONa06yZHago3migdiymD1V3oOGE0BhkD/m57x0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h+i2ZJOST/VYSV6uqz/aL/0TMsvf/Kkp8MxkhauI?= =?us-ascii?Q?JdEyXm544jWP2i9UAUmHD6BGC8Fc8Ep/xh+ii2zS?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2e4436de-bc25-4ec7-c848-08de0cc5073c X-MS-Exchange-CrossTenant-AuthSource: SN7PR12MB8059.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2025 15:02:30.4899 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 4+vDj58j8ciCWXqv1KY8A5fDRI0wH75j5UBBr9qFMw2J+LIRKgE6peZsbsftTnMkJRZZH45MBODKiPN8DgjMzg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6380 Content-Type: text/plain; charset="utf-8" Previously, bitfields were hardcoded to use u32 as the underlying storage type. Add support for different storage types (u8, u16, u32, u64) to the bitfield macro. New syntax is: struct Name() { ... } Reviewed-by: Alexandre Courbot Reviewed-by: Elle Rhumsaa Reviewed-by: Edwin Peer Signed-off-by: Joel Fernandes --- drivers/gpu/nova-core/bitfield.rs | 65 ++++++++++++++++------------ drivers/gpu/nova-core/regs/macros.rs | 16 +++---- 2 files changed, 46 insertions(+), 35 deletions(-) diff --git a/drivers/gpu/nova-core/bitfield.rs b/drivers/gpu/nova-core/bitf= ield.rs index 98ccb1bd3289..998970ff0bbc 100644 --- a/drivers/gpu/nova-core/bitfield.rs +++ b/drivers/gpu/nova-core/bitfield.rs @@ -60,7 +60,7 @@ /// } /// /// bitfield! { -/// struct ControlReg { +/// struct ControlReg(u32) { /// 3:0 mode as u8 ?=3D> Mode; /// 7:7 state as bool =3D> State; /// } @@ -70,6 +70,8 @@ /// This generates a struct with: /// - Field accessors: `mode()`, `state()`, etc. /// - Field setters: `set_mode()`, `set_state()`, etc. (supports chaining = with builder pattern). +/// Note that the compiler will error out if the size of the setter's ar= g exceeds the +/// struct's storage size. /// - Debug and Default implementations. /// /// Fields are defined as follows: @@ -82,21 +84,21 @@ /// and returns the result. This is useful with fields for which not all= values are valid. macro_rules! bitfield { // Main entry point - defines the bitfield struct with fields - (struct $name:ident $(, $comment:literal)? { $($fields:tt)* }) =3D> { - bitfield!(@core $name $(, $comment)? { $($fields)* }); + (struct $name:ident($storage:ty) $(, $comment:literal)? { $($fields:tt= )* }) =3D> { + bitfield!(@core $name $storage $(, $comment)? { $($fields)* }); }; =20 // All rules below are helpers. =20 // Defines the wrapper `$name` type, as well as its relevant implement= ations (`Debug`, // `Default`, `BitOr`, and conversion to the value type) and field acc= essor methods. - (@core $name:ident $(, $comment:literal)? { $($fields:tt)* }) =3D> { + (@core $name:ident $storage:ty $(, $comment:literal)? { $($fields:tt)*= }) =3D> { $( #[doc=3D$comment] )? #[repr(transparent)] #[derive(Clone, Copy)] - pub(crate) struct $name(u32); + pub(crate) struct $name($storage); =20 impl ::core::ops::BitOr for $name { type Output =3D Self; @@ -106,20 +108,20 @@ fn bitor(self, rhs: Self) -> Self::Output { } } =20 - impl ::core::convert::From<$name> for u32 { - fn from(val: $name) -> u32 { + impl ::core::convert::From<$name> for $storage { + fn from(val: $name) -> $storage { val.0 } } =20 - bitfield!(@fields_dispatcher $name { $($fields)* }); + bitfield!(@fields_dispatcher $name $storage { $($fields)* }); }; =20 // Captures the fields and passes them to all the implementers that re= quire field information. // // Used to simplify the matching rules for implementers, so they don't= need to match the entire // complex fields rule even though they only make use of part of it. - (@fields_dispatcher $name:ident { + (@fields_dispatcher $name:ident $storage:ty { $($hi:tt:$lo:tt $field:ident as $type:tt $(?=3D> $try_into_type:ty)? $(=3D> $into_type:ty)? @@ -128,7 +130,7 @@ fn from(val: $name) -> u32 { )* } ) =3D> { - bitfield!(@field_accessors $name { + bitfield!(@field_accessors $name $storage { $( $hi:$lo $field as $type $(?=3D> $try_into_type)? @@ -143,7 +145,7 @@ fn from(val: $name) -> u32 { =20 // Defines all the field getter/setter methods for `$name`. ( - @field_accessors $name:ident { + @field_accessors $name:ident $storage:ty { $($hi:tt:$lo:tt $field:ident as $type:tt $(?=3D> $try_into_type:ty)? $(=3D> $into_type:ty)? @@ -159,7 +161,7 @@ fn from(val: $name) -> u32 { #[allow(dead_code)] impl $name { $( - bitfield!(@field_accessor $name $hi:$lo $field as $type + bitfield!(@field_accessor $name $storage, $hi:$lo $field as $t= ype $(?=3D> $try_into_type)? $(=3D> $into_type)? $(, $comment)? @@ -193,11 +195,11 @@ impl $name { =20 // Catches fields defined as `bool` and convert them into a boolean va= lue. ( - @field_accessor $name:ident $hi:tt:$lo:tt $field:ident as bool =3D= > $into_type:ty + @field_accessor $name:ident $storage:ty, $hi:tt:$lo:tt $field:iden= t as bool =3D> $into_type:ty $(, $comment:literal)?; ) =3D> { bitfield!( - @leaf_accessor $name $hi:$lo $field + @leaf_accessor $name $storage, $hi:$lo $field { |f| <$into_type>::from(if f !=3D 0 { true } else { false }) } bool $into_type =3D> $into_type $(, $comment)?; ); @@ -205,17 +207,17 @@ impl $name { =20 // Shortcut for fields defined as `bool` without the `=3D>` syntax. ( - @field_accessor $name:ident $hi:tt:$lo:tt $field:ident as bool $(,= $comment:literal)?; + @field_accessor $name:ident $storage:ty, $hi:tt:$lo:tt $field:iden= t as bool $(, $comment:literal)?; ) =3D> { - bitfield!(@field_accessor $name $hi:$lo $field as bool =3D> bool $= (, $comment)?;); + bitfield!(@field_accessor $name $storage, $hi:$lo $field as bool = =3D> bool $(, $comment)?;); }; =20 // Catches the `?=3D>` syntax for non-boolean fields. ( - @field_accessor $name:ident $hi:tt:$lo:tt $field:ident as $type:tt= ?=3D> $try_into_type:ty + @field_accessor $name:ident $storage:ty, $hi:tt:$lo:tt $field:iden= t as $type:tt ?=3D> $try_into_type:ty $(, $comment:literal)?; ) =3D> { - bitfield!(@leaf_accessor $name $hi:$lo $field + bitfield!(@leaf_accessor $name $storage, $hi:$lo $field { |f| <$try_into_type>::try_from(f as $type) } $type $try_into= _type =3D> ::core::result::Result< $try_into_type, @@ -226,29 +228,38 @@ impl $name { =20 // Catches the `=3D>` syntax for non-boolean fields. ( - @field_accessor $name:ident $hi:tt:$lo:tt $field:ident as $type:tt= =3D> $into_type:ty + @field_accessor $name:ident $storage:ty, $hi:tt:$lo:tt $field:iden= t as $type:tt =3D> $into_type:ty $(, $comment:literal)?; ) =3D> { - bitfield!(@leaf_accessor $name $hi:$lo $field + bitfield!(@leaf_accessor $name $storage, $hi:$lo $field { |f| <$into_type>::from(f as $type) } $type $into_type =3D> $= into_type $(, $comment)?;); }; =20 // Shortcut for non-boolean fields defined without the `=3D>` or `?=3D= >` syntax. ( - @field_accessor $name:ident $hi:tt:$lo:tt $field:ident as $type:tt + @field_accessor $name:ident $storage:ty, $hi:tt:$lo:tt $field:iden= t as $type:tt $(, $comment:literal)?; ) =3D> { - bitfield!(@field_accessor $name $hi:$lo $field as $type =3D> $type= $(, $comment)?;); + bitfield!(@field_accessor $name $storage, $hi:$lo $field as $type = =3D> $type $(, $comment)?;); }; =20 // Generates the accessor methods for a single field. ( - @leaf_accessor $name:ident $hi:tt:$lo:tt $field:ident + @leaf_accessor $name:ident $storage:ty, $hi:tt:$lo:tt $field:ident { $process:expr } $prim_type:tt $to_type:ty =3D> $res_type:ty = $(, $comment:literal)?; ) =3D> { ::kernel::macros::paste!( const [<$field:upper _RANGE>]: ::core::ops::RangeInclusive =3D= $lo..=3D$hi; - const [<$field:upper _MASK>]: u32 =3D ((((1 << $hi) - 1) << 1) + 1= ) - ((1 << $lo) - 1); + const [<$field:upper _MASK>]: $storage =3D { + // Generate mask for shifting + match ::core::mem::size_of::<$storage>() { + 1 =3D> ::kernel::bits::genmask_u8($lo..=3D$hi) as $storage, + 2 =3D> ::kernel::bits::genmask_u16($lo..=3D$hi) as $storag= e, + 4 =3D> ::kernel::bits::genmask_u32($lo..=3D$hi) as $storag= e, + 8 =3D> ::kernel::bits::genmask_u64($lo..=3D$hi) as $storag= e, + _ =3D> ::kernel::build_error!("Unsupported storage type si= ze") + } + }; const [<$field:upper _SHIFT>]: u32 =3D Self::[<$field:upper _MASK>= ].trailing_zeros(); ); =20 @@ -259,7 +270,7 @@ impl $name { #[inline(always)] pub(crate) fn $field(self) -> $res_type { ::kernel::macros::paste!( - const MASK: u32 =3D $name::[<$field:upper _MASK>]; + const MASK: $storage =3D $name::[<$field:upper _MASK>]; const SHIFT: u32 =3D $name::[<$field:upper _SHIFT>]; ); let field =3D ((self.0 & MASK) >> SHIFT); @@ -274,9 +285,9 @@ pub(crate) fn $field(self) -> $res_type { )? #[inline(always)] pub(crate) fn [](mut self, value: $to_type) -> Self { - const MASK: u32 =3D $name::[<$field:upper _MASK>]; + const MASK: $storage =3D $name::[<$field:upper _MASK>]; const SHIFT: u32 =3D $name::[<$field:upper _SHIFT>]; - let value =3D (u32::from($prim_type::from(value)) << SHIFT) & = MASK; + let value =3D ($storage::from($prim_type::from(value)) << SHIF= T) & MASK; self.0 =3D (self.0 & !MASK) | value; =20 self diff --git a/drivers/gpu/nova-core/regs/macros.rs b/drivers/gpu/nova-core/r= egs/macros.rs index 945d15a2c529..ffd7d5cb73bb 100644 --- a/drivers/gpu/nova-core/regs/macros.rs +++ b/drivers/gpu/nova-core/regs/macros.rs @@ -276,25 +276,25 @@ pub(crate) trait RegisterBase { macro_rules! register { // Creates a register at a fixed offset of the MMIO space. ($name:ident @ $offset:literal $(, $comment:literal)? { $($fields:tt)*= } ) =3D> { - bitfield!(struct $name $(, $comment)? { $($fields)* } ); + bitfield!(struct $name(u32) $(, $comment)? { $($fields)* } ); register!(@io_fixed $name @ $offset); }; =20 // Creates an alias register of fixed offset register `alias` with its= own fields. ($name:ident =3D> $alias:ident $(, $comment:literal)? { $($fields:tt)*= } ) =3D> { - bitfield!(struct $name $(, $comment)? { $($fields)* } ); + bitfield!(struct $name(u32) $(, $comment)? { $($fields)* } ); register!(@io_fixed $name @ $alias::OFFSET); }; =20 // Creates a register at a relative offset from a base address provide= r. ($name:ident @ $base:ty [ $offset:literal ] $(, $comment:literal)? { $= ($fields:tt)* } ) =3D> { - bitfield!(struct $name $(, $comment)? { $($fields)* } ); + bitfield!(struct $name(u32) $(, $comment)? { $($fields)* } ); register!(@io_relative $name @ $base [ $offset ]); }; =20 // Creates an alias register of relative offset register `alias` with = its own fields. ($name:ident =3D> $base:ty [ $alias:ident ] $(, $comment:literal)? { $= ($fields:tt)* }) =3D> { - bitfield!(struct $name $(, $comment)? { $($fields)* } ); + bitfield!(struct $name(u32) $(, $comment)? { $($fields)* } ); register!(@io_relative $name @ $base [ $alias::OFFSET ]); }; =20 @@ -305,7 +305,7 @@ macro_rules! register { } ) =3D> { static_assert!(::core::mem::size_of::() <=3D $stride); - bitfield!(struct $name $(, $comment)? { $($fields)* } ); + bitfield!(struct $name(u32) $(, $comment)? { $($fields)* } ); register!(@io_array $name @ $offset [ $size ; $stride ]); }; =20 @@ -326,7 +326,7 @@ macro_rules! register { $(, $comment:literal)? { $($fields:tt)* } ) =3D> { static_assert!(::core::mem::size_of::() <=3D $stride); - bitfield!(struct $name $(, $comment)? { $($fields)* } ); + bitfield!(struct $name(u32) $(, $comment)? { $($fields)* } ); register!(@io_relative_array $name @ $base [ $offset [ $size ; $st= ride ] ]); }; =20 @@ -348,7 +348,7 @@ macro_rules! register { } ) =3D> { static_assert!($idx < $alias::SIZE); - bitfield!(struct $name $(, $comment)? { $($fields)* } ); + bitfield!(struct $name(u32) $(, $comment)? { $($fields)* } ); register!(@io_relative $name @ $base [ $alias::OFFSET + $idx * $al= ias::STRIDE ] ); }; =20 @@ -357,7 +357,7 @@ macro_rules! register { // to avoid it being interpreted in place of the relative register arr= ay alias rule. ($name:ident =3D> $alias:ident [ $idx:expr ] $(, $comment:literal)? { = $($fields:tt)* }) =3D> { static_assert!($idx < $alias::SIZE); - bitfield!(struct $name $(, $comment)? { $($fields)* } ); + bitfield!(struct $name(u32) $(, $comment)? { $($fields)* } ); register!(@io_fixed $name @ $alias::OFFSET + $idx * $alias::STRIDE= ); }; =20 --=20 2.34.1 From nobody Sat Feb 7 17:48:45 2026 Received: from CO1PR03CU002.outbound.protection.outlook.com (mail-westus2azon11010027.outbound.protection.outlook.com [52.101.46.27]) (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 85F0134AB04; Thu, 16 Oct 2025 15:02:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.46.27 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760626966; cv=fail; b=TSooqvwhoEhtwFDU1ggWRhkdbxTl/CJVfRtPuCa3IbPiWBMwyMUmJD25eSHx5gPTnpIcT2xHdeoG0czkvDxQ9FzTnOVf6pvrWvOUIWTvGcytIj49fd0se96Ut0uIyjCz79hFftlVZ2zMkBeuPd121dqo2Rn/lY6OlNA8KsFMbxQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760626966; c=relaxed/simple; bh=NHxJ24aWDrKKiYtlx2EtRmC5GDOzOAGSN2oBnN7yWLI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=nOgnHG6dfQ/gpTx2kuJdkPzRWR6bLmZ4iLoAtKGWFlCTj5jnYKk1Sv2/VruWDvcl+mD+aiCueJUqsa6lV1phJ6jYAfADqjB4yBHRyU0aUlmiOZ+o+mXJ4HCrTyjdQ2ZLRiQ/vVwBQcQWT07iblSbrFJyn7+JY9Rf+d1BBhwFv60= 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=I7kmw/Lc; arc=fail smtp.client-ip=52.101.46.27 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="I7kmw/Lc" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RQ58bAp4JHK1U4hHTVhPcsgLkeflAnRURbZ4VOf+YujUs2mes8wWfKSmTH6jzJMqNb5RyEanWsTfO2Td+/cVREUu+lPK6Pj1+4rE3DJLWt+hJdJBtOGy9hjYY7oXZCDH5rvpt0svkRptoflLhhCB/Laoo9E0R33NnXjryjRsHwgNmK96XNQRX3/P4F2jvqlTWLXsShTHDHal+APCoVA3/ni5Z7AypYZVdPoi/v3iRtCgmU/L4rOcNAlcYZvAkMGfnCmyo9ORKoydEXaDWJINMWuYOuwBsD+BZRpDJuSfKCF6N7dPsVYcY5VvWV6U8eB2dmoI4ApmzYHJUCjaGofdyg== 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=veMMrum7Qc1DzPDXABeXBoo2pjJsL7P3kIjT4rK5xis=; b=LkzKYl6P4gxzXc+ccucFHEJvi+2s1YJKJox+iRlWdzxhT13TwptDrOaDz+AKUOFobjb0Gta8n1c07FXtlRtS+lS/AQTE1NuNAFwxOel7wKs40r2Zw4rYFlls6eQ8XRppjHIA9RmuazAHKCzl6ptl2EWvsOO75mhc1ESvK422zu/67O58H2G5tJKiI5LGruXHSX3YJmgGcwOgEP+4zM2YHS55lbqb64k4kmMjUWMc8iWgS4oCj6ddWfathsXms/5J8VyyGDO61gMHIGrXgfF0VGoQr2gH1vH1aKQ2jwuPTanf4wUWxmTkGESZLrd3rjbSDnzo5X90SLrFAeV3s8Rd4A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=veMMrum7Qc1DzPDXABeXBoo2pjJsL7P3kIjT4rK5xis=; b=I7kmw/LcXqJGz6q8zRvSz9nT4Rd2BEI6PkPfCkcMP/BkUCcm+i3Bdh8liP1cpxcpKBDMh+dT1hRfrm8SchGxSStzVOTjpFjtEBn4zcc6D1yFdLS7UR1HHFh26wEGIPFtNt9m6QIOpAjAaMaNtfchWcrnbEAOHoXAepuzHUS1vtXI73HJuxm7bM6Kga+Xsi48ps3KqM/XIPFPfvwcH6Bn2GQctPG3VXAZVBbj5xXCJf359eMkbvj0EstUme4fpgyAhNFV1K4TxOi7kARzney/uJrK8V0YH285tkfzbEO4qrH7ONImZG32voW9J+NKCfgG4eXGEvoS9BV6h2UUdt/u9w== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from SN7PR12MB8059.namprd12.prod.outlook.com (2603:10b6:806:32b::7) by BL3PR12MB6380.namprd12.prod.outlook.com (2603:10b6:208:38d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9228.12; Thu, 16 Oct 2025 15:02:32 +0000 Received: from SN7PR12MB8059.namprd12.prod.outlook.com ([fe80::4ee2:654e:1fe8:4b91]) by SN7PR12MB8059.namprd12.prod.outlook.com ([fe80::4ee2:654e:1fe8:4b91%2]) with mapi id 15.20.9228.010; Thu, 16 Oct 2025 15:02:32 +0000 From: Joel Fernandes To: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, dri-devel@lists.freedesktop.org, dakr@kernel.org, acourbot@nvidia.com Cc: Alistair Popple , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , bjorn3_gh@protonmail.com, Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , David Airlie , Simona Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , John Hubbard , Joel Fernandes , Timur Tabi , joel@joelfernandes.org, Elle Rhumsaa , Yury Norov , Daniel Almeida , nouveau@lists.freedesktop.org, Edwin Peer Subject: [PATCH v7 4/4] gpu: nova-core: bitfield: Add support for custom visiblity Date: Thu, 16 Oct 2025 11:02:04 -0400 Message-Id: <20251016150204.1189641-5-joelagnelf@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251016150204.1189641-1-joelagnelf@nvidia.com> References: <20251016150204.1189641-1-joelagnelf@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BN9PR03CA0810.namprd03.prod.outlook.com (2603:10b6:408:13f::35) To SN7PR12MB8059.namprd12.prod.outlook.com (2603:10b6:806:32b::7) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN7PR12MB8059:EE_|BL3PR12MB6380:EE_ X-MS-Office365-Filtering-Correlation-Id: 4ce2a731-002c-4e97-656a-08de0cc50889 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?fqfBEcEUlNAXGW6UwgA3Q6DoCHHVAc8NkblTe/wVPeyg4C0mc1XozkrnRCfj?= =?us-ascii?Q?RdBaiqnL/2GN311RIWuhZnLS7+VGPnF/uyQkDnigzCI6xDENcMW5i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JotCBivjWPW+zuk8hVEm8nO7Act7Ub3EsX?= =?us-ascii?Q?KqL4negks8ebUltm7zjpqGGoaD40xUDfuY+c72cj0VZ58+6DsyBn8dqK47ws?= =?us-ascii?Q?U2ARANcQx7wIy9fK8gwtngy8qeOy1WR/DaW6dMT9rNceKXKsVPgT0UN0y2ro?= =?us-ascii?Q?zOL8VOUiVHRY8e5Y3PhGfXnbzYb1t7m3mODHggSTRgdGD9O44bi97oYr7BrV?= =?us-ascii?Q?1IlRyCNYgklRfzxfnQfE1yyA8OuSbeUCYcAyAj1ZzHnTXi+qxsapTCr45vhI?= =?us-ascii?Q?YEECyoZLHtL64xssMFHsommrEk981+6ALeomaP1yoM9tDz4NGlUffAPfZ35Y?= =?us-ascii?Q?3wu+9JtJHu96bq9D+rSwCSgKyLmpYNHu7G3jfu48rHmdd9TNTp4n/RBDyW8B?= =?us-ascii?Q?q32iLAqQ18mNgEFls7ehJ/IX9tm/2Z6+/ACJJ6V2ChlCOLSDYcRvFZq47miS?= =?us-ascii?Q?1vQW8aAQdl24uShOMbcW9Cv+zi/nY/8i?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN7PR12MB8059.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(7416014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?JMw4xmQQ3nSePuqmdB/OoShFb104XH1k+cnygyMtnDwxiwkgyNRjcSOuvczn?= =?us-ascii?Q?lSu2c9iuzGoXgYrAkgZKEG20G0VJwl78jVYK2oeRn9WMmA2D1j9V7gAGdw1i?= =?us-ascii?Q?yugJSvivau+31RbVDJmMrhp8owKx8r4c9thMQcSV6KpADIfyVe42zlYNEvEv?= =?us-ascii?Q?rUCUCCNjdzquTh0cFDP2MwGyH0sfL+w7KQbxAk0G+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8HGcx1F3fgP3saUBk1GHicxfogVqfxRcwcptY2GPaGWqCqO?= =?us-ascii?Q?3aDls7TGSQbT5k4idlNFFY8Ulr5Md6KuDJG2ZPI8mP3puJCmgyktECT+eypm?= =?us-ascii?Q?EA37rlWGdTTiwSrHxlERBww3ayY+eQgEbrUCNZHuOOen9aa8/Svdcv7m/Yj6?= =?us-ascii?Q?LUYx2bvv9JAWvADAIGK6mKFQOs0M3nyIv6bSmVRl2V0G46X0GmyLhTe3v+7K?= =?us-ascii?Q?2V+I3Nu4cTyGMOxy9Tck6PeogI6BcUk1jKdiTKlqZ8wsImQ1aNy1C9ykEqNk?= =?us-ascii?Q?O7Km2bkJIJzix17mcMi2+lId3ldT7IHJ3bvMjobaG7DZN32nRkkvW/yOEl8m?= =?us-ascii?Q?ZljOW71vEbg+vaGnRJk3noep0eFkz0dLl68nb8G54wrKJZtuUbTSITwj7CJe?= =?us-ascii?Q?fT2J2vh7wo6WRy0iwcmEbf4Ud6O8kz96u6RZSfRx+shbWfvJ/p2deepxPove?= =?us-ascii?Q?sT1/50cQi5YZGAAApoKxSfPUjpUL4dRGFrmTQzkGXsS3oYuj4q17bljdhXGW?= =?us-ascii?Q?Lg=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4ce2a731-002c-4e97-656a-08de0cc50889 X-MS-Exchange-CrossTenant-AuthSource: SN7PR12MB8059.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2025 15:02:32.6675 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Pe1VSrsPKzWheS5tPKU3gHKplm1kMW6EErt3VYp6ZyOLIn66tNxJu0Cv41GeKeIuuIsK3Kn7zZHLSRAEXYjkBw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6380 Content-Type: text/plain; charset="utf-8" Add support for custom visiblity to allow for users to control visibility of the structure and helpers. Reviewed-by: Alexandre Courbot Reviewed-by: Elle Rhumsaa Reviewed-by: Edwin Peer Signed-off-by: Joel Fernandes --- drivers/gpu/nova-core/bitfield.rs | 49 +++++++++++++++------------- drivers/gpu/nova-core/regs/macros.rs | 16 ++++----- 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/drivers/gpu/nova-core/bitfield.rs b/drivers/gpu/nova-core/bitf= ield.rs index 998970ff0bbc..0994505393dd 100644 --- a/drivers/gpu/nova-core/bitfield.rs +++ b/drivers/gpu/nova-core/bitfield.rs @@ -60,7 +60,7 @@ /// } /// /// bitfield! { -/// struct ControlReg(u32) { +/// pub struct ControlReg(u32) { /// 3:0 mode as u8 ?=3D> Mode; /// 7:7 state as bool =3D> State; /// } @@ -74,6 +74,9 @@ /// struct's storage size. /// - Debug and Default implementations. /// +/// Note: Field accessors and setters inherit the same visibility as the s= truct itself. +/// In the example above, both `mode()` and `set_mode()` methods will be `= pub`. +/// /// Fields are defined as follows: /// /// - `as ` simply returns the field value casted to , typical= ly `u32`, `u16`, `u8` or @@ -84,21 +87,21 @@ /// and returns the result. This is useful with fields for which not all= values are valid. macro_rules! bitfield { // Main entry point - defines the bitfield struct with fields - (struct $name:ident($storage:ty) $(, $comment:literal)? { $($fields:tt= )* }) =3D> { - bitfield!(@core $name $storage $(, $comment)? { $($fields)* }); + ($vis:vis struct $name:ident($storage:ty) $(, $comment:literal)? { $($= fields:tt)* }) =3D> { + bitfield!(@core $vis $name $storage $(, $comment)? { $($fields)* }= ); }; =20 // All rules below are helpers. =20 // Defines the wrapper `$name` type, as well as its relevant implement= ations (`Debug`, // `Default`, `BitOr`, and conversion to the value type) and field acc= essor methods. - (@core $name:ident $storage:ty $(, $comment:literal)? { $($fields:tt)*= }) =3D> { + (@core $vis:vis $name:ident $storage:ty $(, $comment:literal)? { $($fi= elds:tt)* }) =3D> { $( #[doc=3D$comment] )? #[repr(transparent)] #[derive(Clone, Copy)] - pub(crate) struct $name($storage); + $vis struct $name($storage); =20 impl ::core::ops::BitOr for $name { type Output =3D Self; @@ -114,14 +117,14 @@ fn from(val: $name) -> $storage { } } =20 - bitfield!(@fields_dispatcher $name $storage { $($fields)* }); + bitfield!(@fields_dispatcher $vis $name $storage { $($fields)* }); }; =20 // Captures the fields and passes them to all the implementers that re= quire field information. // // Used to simplify the matching rules for implementers, so they don't= need to match the entire // complex fields rule even though they only make use of part of it. - (@fields_dispatcher $name:ident $storage:ty { + (@fields_dispatcher $vis:vis $name:ident $storage:ty { $($hi:tt:$lo:tt $field:ident as $type:tt $(?=3D> $try_into_type:ty)? $(=3D> $into_type:ty)? @@ -130,7 +133,7 @@ fn from(val: $name) -> $storage { )* } ) =3D> { - bitfield!(@field_accessors $name $storage { + bitfield!(@field_accessors $vis $name $storage { $( $hi:$lo $field as $type $(?=3D> $try_into_type)? @@ -145,7 +148,7 @@ fn from(val: $name) -> $storage { =20 // Defines all the field getter/setter methods for `$name`. ( - @field_accessors $name:ident $storage:ty { + @field_accessors $vis:vis $name:ident $storage:ty { $($hi:tt:$lo:tt $field:ident as $type:tt $(?=3D> $try_into_type:ty)? $(=3D> $into_type:ty)? @@ -161,7 +164,7 @@ fn from(val: $name) -> $storage { #[allow(dead_code)] impl $name { $( - bitfield!(@field_accessor $name $storage, $hi:$lo $field as $t= ype + bitfield!(@field_accessor $vis $name $storage, $hi:$lo $field = as $type $(?=3D> $try_into_type)? $(=3D> $into_type)? $(, $comment)? @@ -195,11 +198,11 @@ impl $name { =20 // Catches fields defined as `bool` and convert them into a boolean va= lue. ( - @field_accessor $name:ident $storage:ty, $hi:tt:$lo:tt $field:iden= t as bool =3D> $into_type:ty + @field_accessor $vis:vis $name:ident $storage:ty, $hi:tt:$lo:tt $f= ield:ident as bool =3D> $into_type:ty $(, $comment:literal)?; ) =3D> { bitfield!( - @leaf_accessor $name $storage, $hi:$lo $field + @leaf_accessor $vis $name $storage, $hi:$lo $field { |f| <$into_type>::from(if f !=3D 0 { true } else { false }) } bool $into_type =3D> $into_type $(, $comment)?; ); @@ -207,17 +210,17 @@ impl $name { =20 // Shortcut for fields defined as `bool` without the `=3D>` syntax. ( - @field_accessor $name:ident $storage:ty, $hi:tt:$lo:tt $field:iden= t as bool $(, $comment:literal)?; + @field_accessor $vis:vis $name:ident $storage:ty, $hi:tt:$lo:tt $f= ield:ident as bool $(, $comment:literal)?; ) =3D> { - bitfield!(@field_accessor $name $storage, $hi:$lo $field as bool = =3D> bool $(, $comment)?;); + bitfield!(@field_accessor $vis $name $storage, $hi:$lo $field as b= ool =3D> bool $(, $comment)?;); }; =20 // Catches the `?=3D>` syntax for non-boolean fields. ( - @field_accessor $name:ident $storage:ty, $hi:tt:$lo:tt $field:iden= t as $type:tt ?=3D> $try_into_type:ty + @field_accessor $vis:vis $name:ident $storage:ty, $hi:tt:$lo:tt $f= ield:ident as $type:tt ?=3D> $try_into_type:ty $(, $comment:literal)?; ) =3D> { - bitfield!(@leaf_accessor $name $storage, $hi:$lo $field + bitfield!(@leaf_accessor $vis $name $storage, $hi:$lo $field { |f| <$try_into_type>::try_from(f as $type) } $type $try_into= _type =3D> ::core::result::Result< $try_into_type, @@ -228,24 +231,24 @@ impl $name { =20 // Catches the `=3D>` syntax for non-boolean fields. ( - @field_accessor $name:ident $storage:ty, $hi:tt:$lo:tt $field:iden= t as $type:tt =3D> $into_type:ty + @field_accessor $vis:vis $name:ident $storage:ty, $hi:tt:$lo:tt $f= ield:ident as $type:tt =3D> $into_type:ty $(, $comment:literal)?; ) =3D> { - bitfield!(@leaf_accessor $name $storage, $hi:$lo $field + bitfield!(@leaf_accessor $vis $name $storage, $hi:$lo $field { |f| <$into_type>::from(f as $type) } $type $into_type =3D> $= into_type $(, $comment)?;); }; =20 // Shortcut for non-boolean fields defined without the `=3D>` or `?=3D= >` syntax. ( - @field_accessor $name:ident $storage:ty, $hi:tt:$lo:tt $field:iden= t as $type:tt + @field_accessor $vis:vis $name:ident $storage:ty, $hi:tt:$lo:tt $f= ield:ident as $type:tt $(, $comment:literal)?; ) =3D> { - bitfield!(@field_accessor $name $storage, $hi:$lo $field as $type = =3D> $type $(, $comment)?;); + bitfield!(@field_accessor $vis $name $storage, $hi:$lo $field as $= type =3D> $type $(, $comment)?;); }; =20 // Generates the accessor methods for a single field. ( - @leaf_accessor $name:ident $storage:ty, $hi:tt:$lo:tt $field:ident + @leaf_accessor $vis:vis $name:ident $storage:ty, $hi:tt:$lo:tt $fi= eld:ident { $process:expr } $prim_type:tt $to_type:ty =3D> $res_type:ty = $(, $comment:literal)?; ) =3D> { ::kernel::macros::paste!( @@ -268,7 +271,7 @@ impl $name { #[doc=3D$comment] )? #[inline(always)] - pub(crate) fn $field(self) -> $res_type { + $vis fn $field(self) -> $res_type { ::kernel::macros::paste!( const MASK: $storage =3D $name::[<$field:upper _MASK>]; const SHIFT: u32 =3D $name::[<$field:upper _SHIFT>]; @@ -284,7 +287,7 @@ pub(crate) fn $field(self) -> $res_type { #[doc=3D$comment] )? #[inline(always)] - pub(crate) fn [](mut self, value: $to_type) -> Self { + $vis fn [](mut self, value: $to_type) -> Self { const MASK: $storage =3D $name::[<$field:upper _MASK>]; const SHIFT: u32 =3D $name::[<$field:upper _SHIFT>]; let value =3D ($storage::from($prim_type::from(value)) << SHIF= T) & MASK; diff --git a/drivers/gpu/nova-core/regs/macros.rs b/drivers/gpu/nova-core/r= egs/macros.rs index ffd7d5cb73bb..c0a5194e8d97 100644 --- a/drivers/gpu/nova-core/regs/macros.rs +++ b/drivers/gpu/nova-core/regs/macros.rs @@ -276,25 +276,25 @@ pub(crate) trait RegisterBase { macro_rules! register { // Creates a register at a fixed offset of the MMIO space. ($name:ident @ $offset:literal $(, $comment:literal)? { $($fields:tt)*= } ) =3D> { - bitfield!(struct $name(u32) $(, $comment)? { $($fields)* } ); + bitfield!(pub(crate) struct $name(u32) $(, $comment)? { $($fields)= * } ); register!(@io_fixed $name @ $offset); }; =20 // Creates an alias register of fixed offset register `alias` with its= own fields. ($name:ident =3D> $alias:ident $(, $comment:literal)? { $($fields:tt)*= } ) =3D> { - bitfield!(struct $name(u32) $(, $comment)? { $($fields)* } ); + bitfield!(pub(crate) struct $name(u32) $(, $comment)? { $($fields)= * } ); register!(@io_fixed $name @ $alias::OFFSET); }; =20 // Creates a register at a relative offset from a base address provide= r. ($name:ident @ $base:ty [ $offset:literal ] $(, $comment:literal)? { $= ($fields:tt)* } ) =3D> { - bitfield!(struct $name(u32) $(, $comment)? { $($fields)* } ); + bitfield!(pub(crate) struct $name(u32) $(, $comment)? { $($fields)= * } ); register!(@io_relative $name @ $base [ $offset ]); }; =20 // Creates an alias register of relative offset register `alias` with = its own fields. ($name:ident =3D> $base:ty [ $alias:ident ] $(, $comment:literal)? { $= ($fields:tt)* }) =3D> { - bitfield!(struct $name(u32) $(, $comment)? { $($fields)* } ); + bitfield!(pub(crate) struct $name(u32) $(, $comment)? { $($fields)= * } ); register!(@io_relative $name @ $base [ $alias::OFFSET ]); }; =20 @@ -305,7 +305,7 @@ macro_rules! register { } ) =3D> { static_assert!(::core::mem::size_of::() <=3D $stride); - bitfield!(struct $name(u32) $(, $comment)? { $($fields)* } ); + bitfield!(pub(crate) struct $name(u32) $(, $comment)? { $($fields)= * } ); register!(@io_array $name @ $offset [ $size ; $stride ]); }; =20 @@ -326,7 +326,7 @@ macro_rules! register { $(, $comment:literal)? { $($fields:tt)* } ) =3D> { static_assert!(::core::mem::size_of::() <=3D $stride); - bitfield!(struct $name(u32) $(, $comment)? { $($fields)* } ); + bitfield!(pub(crate) struct $name(u32) $(, $comment)? { $($fields)= * } ); register!(@io_relative_array $name @ $base [ $offset [ $size ; $st= ride ] ]); }; =20 @@ -348,7 +348,7 @@ macro_rules! register { } ) =3D> { static_assert!($idx < $alias::SIZE); - bitfield!(struct $name(u32) $(, $comment)? { $($fields)* } ); + bitfield!(pub(crate) struct $name(u32) $(, $comment)? { $($fields)= * } ); register!(@io_relative $name @ $base [ $alias::OFFSET + $idx * $al= ias::STRIDE ] ); }; =20 @@ -357,7 +357,7 @@ macro_rules! register { // to avoid it being interpreted in place of the relative register arr= ay alias rule. ($name:ident =3D> $alias:ident [ $idx:expr ] $(, $comment:literal)? { = $($fields:tt)* }) =3D> { static_assert!($idx < $alias::SIZE); - bitfield!(struct $name(u32) $(, $comment)? { $($fields)* } ); + bitfield!(pub(crate) struct $name(u32) $(, $comment)? { $($fields)= * } ); register!(@io_fixed $name @ $alias::OFFSET + $idx * $alias::STRIDE= ); }; =20 --=20 2.34.1