From nobody Sun Feb 8 09:13:23 2026 Received: from PH0PR06CU001.outbound.protection.outlook.com (mail-westus3azon11011056.outbound.protection.outlook.com [40.107.208.56]) (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 3DD213451B0; Thu, 16 Oct 2025 15:13:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.208.56 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760627614; cv=fail; b=jlzJ1m4h6NU5wsMAv6gC7CYSwcTGh0kq2l+d7M+5qDVYdoFVbaoLMxCXM17fp+703qffZAi1GdlDRpq5GN3YDWIEH6IwY1CFxsZ4o4fH1LvuZG/TgzHzbUWngqLvLkvzmW2VRBmgBlP0XrVpmMOm7g/wGSr1aCUTOfp7ZGeKJBc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760627614; c=relaxed/simple; bh=TnE4y3RvU7fMmzuWnwmIKdsgCDUxhPqLl/Ln0iZEwUM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=fdyh+sSDJLFSumzgla2gG7DTwdBGPuX+EhkwBdjyTwjy9I40nW3pl9fPn9PZ9LzZxxbVm1RNZRWurOQ8AIOLHDGyUGamKh7DUuSFVTrkUsLd9mbzQ64NfXoMOSOsM3Piuw5EFUpQluLi2IncrgVYlaXESOOO/0wrXXZn6SNKSHg= 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=uOmvWllb; arc=fail smtp.client-ip=40.107.208.56 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="uOmvWllb" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=SwT/9esEm9WWXC+JluvpbR3o/FUtRYnM6doj4sltA8vZG03lFdUrAkKdYyzNP39mQy+xFAT7oKe+T18djRk4Xj9yXnHZgHDz7Fbu9yZHmk29C6Bi2aWnwAufVOSS88YPm7NUu5Qmh0jkVh5u9yC8gfTvrn+QyPHMPnt/4SOYe0Rhp8YjmpJGbcG8nZm3bV24vNtltIZ2iaWrU03l/F6ERy8egVxxDZNsPvsgPbbt+Kj7hihPHhbAak/aEtA+qN3gCWcSnxb1KI9BdY3SdnIQrADr8yOHEsMl89945nK2nSRvBk4/xImu1AeR5Pc4DdAcOcqIdGzjgOQ8umK0KIIB5g== 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=KAmpI8MkYGJzNWMUEeQJbkXicdfagVrV2YnN6fyAVUo=; b=fIgh7QDjRCCdacYBEop0ToUEDm3LuhgRlq1UUdNgxxZz6F9KCdiTjDljJoSjPkpZTvESA8DDFwI0kYIeuqx+1RtowD4Rl+D9jYBxGGhr1pUjY6y+g4TvVaYmAwNy/m7t/dXAlrWIm64EufpNq6sa4VytxpPlx3r8Rgaj1gsj9wpJ1sJ5DyILNeTO/BkP27K9BlkabU3SlgaZDWDTIJxlQ8Os+K4Y71WDUrcF2AyY8VHseKPOfjiefRogUzYEP2dkVa5zL7kyPWyH6b9WUahtiynXJah8k3DCVA1hWI+znobEX0pABEiaBS5csqorISVqOMK3veVNX1s9LN73DlXkBA== 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=KAmpI8MkYGJzNWMUEeQJbkXicdfagVrV2YnN6fyAVUo=; b=uOmvWllbK1OHMLPKv43HQXpLUC3wTv3mYkcEq4ziBQdHOuIKGuj26w3/qPAz0Ib8bQFn1vid+v6p2OqL8SARmyFcvU71TTLBvDOZcivNMoKGiXb+1zlYYLyjc0l0U8CIyHx4ER7Dtg08WbUouNKoG/i2isaTe28aWf+YR6ALBtElyGquGueFzLaH62houA85kdM1d6xWozAib8qsHRN9TeDY27EtZK2AjBv09COD71sG0tAOy31bd/4Cx8uwNXAFXHxi7tRna8L+mY3whOPkV0c2QCDzRbftMjVPNOZwE20J5dg04KzeCodgIpQBgVoaUiHS/OOoZmE4b5uB0aMQTg== 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 DS0PR12MB8574.namprd12.prod.outlook.com (2603:10b6:8:166::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9228.10; Thu, 16 Oct 2025 15:13:29 +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:13:29 +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 1/4] gpu: nova-core: register: use field type for Into implementation Date: Thu, 16 Oct 2025 11:13:20 -0400 Message-Id: <20251016151323.1201196-2-joelagnelf@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251016151323.1201196-1-joelagnelf@nvidia.com> References: <20251016151323.1201196-1-joelagnelf@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BN9PR03CA0929.namprd03.prod.outlook.com (2603:10b6:408:107::34) 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_|DS0PR12MB8574:EE_ X-MS-Office365-Filtering-Correlation-Id: e332dd23-d744-429e-7dc6-08de0cc6901f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?ak6gl9GZy002JCsOLhDXUPrgkCKrDg47qYLyN+c6WLjC/9JvImIsN/o8eFiU?= =?us-ascii?Q?aEDY4uSs9Y+OtRcvPKq9V98Iqoc37dHpZmiTzerJH3ES/4mKjtZhK3Y8rXC4?= =?us-ascii?Q?SZqUb1FgAwHjms6XjbhmH71M0I3Fy28RW2XbmXQ1iGQ5wjm4RfPV1EEIEzZa?= =?us-ascii?Q?l7geAOJcw8bTAbu3X7qyEdy+vVJVH/FAwLyHk9MDa75rT9UEz8YIf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yEic53mjz4yZECV72lrJ/WYbirOdyKrGkvV?= =?us-ascii?Q?PydfuTMDdt4O5Q19X+hLNfH+dJSt6pnuEZpoQ/xVqzNXOP38Fk2akbHTI5fP?= =?us-ascii?Q?6d2dwS+yf4A9029oBMm5OT5OXVZhFDslqCQK8oeN5+08002S/Epxjfc3/CYF?= =?us-ascii?Q?aDwuqj+HrRYkrFBODKoD4LaBfKlGyd/javHG5jMlEkClqkEkbWd35OpvDl1d?= =?us-ascii?Q?7cgTXuawzifTZJ4Sv+BONmxfdUS5JFfoty323W6T7Vx+aSLsuwYPEuhcOXN1?= =?us-ascii?Q?GC4VBQQ+5DEBX6KZErDIO8lz46TESEpSJS0bIZLfKpFVOFGFsBJBmN+j5PKW?= =?us-ascii?Q?B4UXogj31tcfSVScl6VolpTSo+Tm/mWF?= 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)(7416014)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?h89UA7zo9oJqs9JXZhn/dVQ+Zge6Y+meJRL6oaEHDqQtOyenjMU6cQZ6jMCq?= =?us-ascii?Q?s/TyPQKgeevV5IamdClvE8AoV0VxYUHdN5iBuIkMMYH0+905kKPHd1BaPq8g?= =?us-ascii?Q?gPQE3xZ58167mBGtiObeq/G3kVkMsBVVqtkpvRbCx22iYEGTSHqjK43Jbk8o?= =?us-ascii?Q?Blwx6/ZX+D+v2V3SvHwp9/e/GKriBfPPtMm6v9PrsrwxPMMzqGxhfwMe6XAo?= =?us-ascii?Q?WIP6EaMX1FwgMdiLAB9zD0iB5amfIYtz3P6onumLzcBH1AwsS31yoODqN5jL?= =?us-ascii?Q?jQNGxWFROAYROqCVNkkSkdnLJhsgMnxTHBja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1dhOgLkfOp+qgvENA8CbWX4DHAGAFMfltyPzKGLHXbWCZhXwZAOxE7K/?= =?us-ascii?Q?bFQXqw+dbqst6E0wgRWZ2cj5ladxpv55zLpxEJqx3QCkGXkS6R58mdpw3os5?= =?us-ascii?Q?G+DYJnLlsd9g1XH8nzZT+Mji7J3QlhvxkoiJ6PAM4s6oyRtxASPV2jjWWdZ2?= =?us-ascii?Q?HP0So5etST7qnmC0UHRFI+fVyrR8BspjOAe3Ebprj2+AnhV557FFdjZDVRZx?= =?us-ascii?Q?+n3btwT62ScKJzOogMvQx9tUPxY+8sRiUcDbA8cLR6643g+RNVzzVTHJ0E3f?= =?us-ascii?Q?E5VY35mr8T4eK4h9Nyd0yKQ8oHLgVwBKhreXnfzQ4znIwFU35c8gOHWeOnr0?= =?us-ascii?Q?DQQpXgguxm+H8U6ljIaunUc2SP/z2CUeNre/TYmx?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e332dd23-d744-429e-7dc6-08de0cc6901f 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:13:29.5487 (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: z0CVWeF3nJca65dDQxSg7WLlVcSV/oSTtFtNkUtzE02J5a4Z6Wt9rWMesFWuVUtabQIFyObZ11+QfzD0WmmrEQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8574 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 Signed-off-by: Joel Fernandes Acked-by: Danilo Krummrich --- 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 Sun Feb 8 09:13:23 2026 Received: from CO1PR03CU002.outbound.protection.outlook.com (mail-westus2azon11010015.outbound.protection.outlook.com [52.101.46.15]) (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 B179C3451CC; Thu, 16 Oct 2025 15:13:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.46.15 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760627621; cv=fail; b=jLZC4RAos9UffZSQmGfEFI45myGmnWHe8Kxxq/Il+tR0uh76dnnnvyHaTPGji77ZSx5CwR31EiKSisca68LWqg9pMc9DyrOLSebMCxNfhCNjIcnRnU0+1BtoZiyZDs/JA1UqivPFEqKcM3QrUC6gxE+ar7S38YihLIIy2MnEqUU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760627621; c=relaxed/simple; bh=izwy1wo5PNA+dM4laamG7+oyoxjlk0MEPeEVkRVsX5A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=ORCGj4RfERzA0Rv1Lw66QBc54M/iVAfyGxblow7vE8jI3nQvgRZ+b6Si5UG/oau3laxMbHT/z+3rDa7fFHIbrqglb32Ju/3J/5INJTllcFhtanOoBTGPH4mYwDoF7EG//tzMlHnaOYIQsvJehZzMBKxkpxNCxwA1nLgcMAt6EB0= 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=tRGhKJGV; arc=fail smtp.client-ip=52.101.46.15 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="tRGhKJGV" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TVlVEXe5vKuUlYvuawUbMs1IPljQ1pu6jKf/K1azr9SXQey7nfsnKUYI5L5g6bxA4zeBgq0PgsXy6g5QtAwrCSMUQeO++mPEz3oIKvJe34BYzVxkZbuAvYKU4tTSVqdJuhV7RwhKP++LPnLeVN3pPHyFZ0ITJfqgYjwNglmhDP2aOlwt1afHjKrBx9j2bVIvx031w+Pjuol16I/xrNa5Rz95fiijjr/xieHP70V6GoE3KFbl+o7LnkOVlEVpBCACRpBooG2t3AQBK+PzeaFRKit0A9MaLmQ3UcEhNFJCI6TmRrJPzrrm+Y9nSGiQ+DjdwM8ecpiF6tw4YbhPdqd8lA== 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=98hQqApuNbYCGknsmr/qe6ay65FjvLPUkzya0UdGw+o=; b=XCnYK+ISfKk9iJxaD0USi3DUnuZ0kH0lL7f0y2CpIxJteBViT9RaXMBmLGSMMhr7aeKHWFDr6It/BK3ub2m8ZkmtAchsoAA/lJKeg78PhZkvwXNvfzPXiNt7OxQLuJI7B6O2L6BAcUAbMHpxkdjPR7N8JUXiBsQSExULyw70ukdwGDklq8X2KZUsWjLUveDzQIMZ09TKEvxa9snOAIZzAg0tp5a+SKZTT0sZbmdOKxjoWwYFC0FSJbugaaWiPX7jNFViXCjpQM+GNjjUco6iiRiCKKyFl8wMVD9mKtow3UV8Wf/QmdEFk09nnec3p4qxdjIY87riQTBRywrhxRinVw== 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=98hQqApuNbYCGknsmr/qe6ay65FjvLPUkzya0UdGw+o=; b=tRGhKJGVQdAyasbfnR0xs8wr2KnlxSmahmpwLmPWvgRx1+Inm79PQWGO2X8yBGPoThuZrG+k1uLn6CSU1p4+cG+4aNtt54V4rfr0biq9d6xO6tby75ThbjB5iZ7egt9gUB6qaGKzFNZc1nkhQzse4XK5GLVcDMNcXc1dlgN6idWB7/hfIy6Y0ubxY9+7x4mfVQ5j6ODGo5ZVKy6Vb6uhuebzVWpIh6iFC1LJw0R2MU8MOPYxidmaj03axbVl6ILBLYltTUyZpLRbpl+xNpuUCi+BmUg3o4jzVjR3h6SoUGU8eDouPGhcK0lJa/bRQyyuJQArHbPsLVLJsCSpV5IYkw== 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 DS0PR12MB8574.namprd12.prod.outlook.com (2603:10b6:8:166::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9228.10; Thu, 16 Oct 2025 15:13:31 +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:13:31 +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.1 2/4] gpu: nova-core: bitfield: Move bitfield-specific code from register! into new macro Date: Thu, 16 Oct 2025 11:13:21 -0400 Message-Id: <20251016151323.1201196-3-joelagnelf@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251016151323.1201196-1-joelagnelf@nvidia.com> References: <20251016151323.1201196-1-joelagnelf@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BN9PR03CA0864.namprd03.prod.outlook.com (2603:10b6:408:13d::29) 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_|DS0PR12MB8574:EE_ X-MS-Office365-Filtering-Correlation-Id: 481ef0d7-b195-4930-4ce8-08de0cc6911b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?6OzItX7Ty0pVuJNnj/Hll9SD+wrsYdBKC1KP2sbtnhEG46iAEWCB/eSI/dy/?= =?us-ascii?Q?N98Kk5tIYV5EU6/IlBJPONYOu7LWaiQV/YBypUrfdo2aEQnG3ue9xuh5smQb?= =?us-ascii?Q?iXMh6W2lGngd63pOhfZ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ZTsh+B?= =?us-ascii?Q?Mrwqgcc1qdMJ6GwHbPgDB53A2AO4fOiEZrAR1fAQRX3D9zwDVqRiVzNX2hIO?= =?us-ascii?Q?c4IwEeYp3AE3RdlAAwDR+RYZnZCRDwM8a+K8jG44703ZCXqmrcODWBV7V7P+?= =?us-ascii?Q?kOh8cQyJh02QIGL3akMKgfBoEI0N5egXWLvYY78HKvYc8wGPZ4eReHSLg8rP?= =?us-ascii?Q?ECZEZknL+zXpbfwvCVl1ysJKd4nJ8r0Jl0WK7QIH42gyySG58Bo71sNQApjZ?= =?us-ascii?Q?tVVKMxpS8UogHGTX/uWmhhUf4tXPf6JFLFeCeaUMhVyJtTyoA3/QToNd4eiu?= =?us-ascii?Q?Hm4Feroj0oKEQN7xydvuRgiz3P4P84k8Gd27TNzNjzSU552KMBTdbmTWHgef?= =?us-ascii?Q?heAklmwTZAmu+5WWtQZPxf3l4FAm8QXavFP7g4iTEirLvCi1V4PLkrxeBHtq?= =?us-ascii?Q?rr+ku03VLpjlvLCpsWjaIF/7Htz+Xvkq?= 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)(7416014)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?TcFdjqGtB9kWSI8hf3y0qkESHMpAsy/1IgxeomFfBB+ipY4yax+TCh82MgWJ?= =?us-ascii?Q?QBtFGm/8PUoUs7mjLWmMABXvTz17Ah9PXK0D02pxlSojjXZL8lqJe6a2IjFu?= =?us-ascii?Q?azyifEtgrTGfL9caA3i/lipT+TNiFRwTiRLKSdK6TIah/lv3Q1+zlQsB6J6H?= =?us-ascii?Q?oF0dTKf2okSgaTIcd+tYwO8q2IMGK1c05F7D33h7JtIHE1HDGfgwCklnj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YSXQyxmndmqhRdKBB9TvJNcCX3I7Z6dgG?= =?us-ascii?Q?GgIviCgeRyS6oXyFhmBbk4HXLQmNG3YP9H3jbm+/1jfxsZ7yK3VdOn3FPdsq?= =?us-ascii?Q?MDq8o1stZQ8Mjwz96TQq0WWAd/5tyR4FD5kSzBOvVTOazQ4t4EyJsAI1vjds?= =?us-ascii?Q?FQI+/UjBUAGqQ546Is5i2YDmrV8clouIsUadYwumo4sLQ/YCtIGBXqDks8d6?= =?us-ascii?Q?H3EnhEZ0qsPIFoKbQ9buh7k5cQCB3LqTemC5/YwEP3YguqAFzY4z74wc/D57?= =?us-ascii?Q?707nqUlh+9XUHKRsoX3s1IAr4vqUv9Yre2k2fpNjOx6GjwKq+dN2DjlCThB0?= =?us-ascii?Q?Km6Txf2NkIIYCHqqe1itwxlYMfWlNvuXu/5UAuNjf+sSHgsSMQm7x+UKPtm2?= =?us-ascii?Q?HoGlPXBQc4U01lSScwjeQmwMxFaOMj/arbZCniiIrDK9+68YeIUFbEMaEA90?= =?us-ascii?Q?Sl3sK8A6qvI/7/MySItXkhrFy7m4ADLt62bnwl3b?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 481ef0d7-b195-4930-4ce8-08de0cc6911b 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:13:31.3960 (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: DNAQ5U0RaKdBUXdeAnlbCHHaA2/8aamviOGsUL29KlQrfDFOrpuN9X/Q2yqXuCAA0yJdwec4uM6Iw7jxhllBdg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8574 Content-Type: text/plain; charset="utf-8" Move the bitfield-specific code from the register macro into a new macro called bitfield. 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 Acked-by: Danilo Krummrich --- 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 Sun Feb 8 09:13:23 2026 Received: from CO1PR03CU002.outbound.protection.outlook.com (mail-westus2azon11010015.outbound.protection.outlook.com [52.101.46.15]) (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 9CE653469E9; Thu, 16 Oct 2025 15:13:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.46.15 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760627618; cv=fail; b=MVGHeOxFvymoApWhPLC+uTQuQlGyv2Zr8g5EU4gNbcwVaejpYhchh9lGNYHI6iZf8nd5CaRYBQoyk5Y5GK7o/2zIZVPt4fvsgulu7o/CQhuTRVffOgD2EjUssTvO4G6yX6q7TsA1PjopGMZtQWr6qkqTYIKhJlC0hEPPwrQ8C7I= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760627618; c=relaxed/simple; bh=6hlbJswMk7j1m70PmNFdfDHNDABkRdQyWsqD3gY78VA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=BVHxhXQs3wHPXszYO0WtPIea/iHRyuy2jc5p0MkX4tytLrmpHqDl15i09Q4K/rZXjYGy2cj5taPp9R3ufzqtW55hBGNtxawoNyMtzJtACnvltkHIgfqdHhXjntsFHmNSGI4zgpRjUked7fC0lI9CULUJkCNE9BmEgCfgHlCOq1c= 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=aqCQM8zJ; arc=fail smtp.client-ip=52.101.46.15 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="aqCQM8zJ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TB3MmFQSz5pyb28gCiw8bpmesMWt6AwzIkfRdb4ATReTiOwrEjoOVCmOUBn8pjNEkAZ1OzS+KT/ssoJoyDr/tjdWYKOdNajGYj7/HVbtzoegqcipKnnPHYOX/Mf1iFxgSfZfwKvBM3dYRQBdvEi6SGhRXUdbab+Bf7SkaBh2VEpPMRRH16L/HSXmhCWP1H+M0UWgEzzdEzd9u+iBno76Itqphl5TCXExbbeyrJiByNkWjHKoiQ0IMZI1InZXalYi+JRdVGwZZkxo5KMo7F9ez++4uUUizgVhQQfOKhUNOs6pOlKTmCELD8FZVTq7/A6NkvGQNfbteQ+/p2ipYBP/bQ== 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=WJJqS34d+O7sBZA+oqR4bzFlSn9o776Z+tIXXZ2wOdt5Vw6sZsMUvohd00Iq6yjTo1QQy2keszPgOExaBg/Ds2O9BUDPjc60UKTRn8hQq/gXyfKEf4J7jcTNul36pGnd/fm2KfNhEh2DYUICpTxNjVM/OclYYo2f55oqN4dX64xhnHZwzjGKp4w9fI0LMWu1PL3lqC4f+4lbJRyG9reByMedBdlRf0ZqwrqTMoaDUJuKweE0Ml1yzn5nHfY2CQXqIDjj4dUcSGdu2wYNKQ8f08THhxB107zskXXCRMUh54RbUQUD+NFTTIggdH3O7mCF4TVS9XbqRW5sSUBXOshURw== 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=aqCQM8zJ6BoTFg+/09TNdY3gJXDgdFcOeJHGOsm+Zk8zgWU3b4OiZjMneRl6o1EVFSUJUO6N4AuRwCT3X7OqE9XGwsfClRdMIRKwzJAtYE8uvs2m6975muBAdqv0z38AGZIwuN4z0vPnlK3IPs0AGtrT8/Q9lJsgQiXYll+JLzyJr8K4T3vgHBTO29MZR3jARiCxuN/MooH+AX6j2PKyCOaJL0BiK19w8J1VOEsE4m6tShcvvNcZ5mkMgCBsjEtKf2sXqwITLGumpqiwwyxCLtoDGhMydJQv/jyq22mtDil6XW5eGMsi+RcUKtsB31kjOBlas+8+XRxam0o6lcOq4w== 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 DS0PR12MB8574.namprd12.prod.outlook.com (2603:10b6:8:166::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9228.10; Thu, 16 Oct 2025 15:13:33 +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:13:33 +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.1 3/4] gpu: nova-core: bitfield: Add support for different storage widths Date: Thu, 16 Oct 2025 11:13:22 -0400 Message-Id: <20251016151323.1201196-4-joelagnelf@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251016151323.1201196-1-joelagnelf@nvidia.com> References: <20251016151323.1201196-1-joelagnelf@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BL1PR13CA0321.namprd13.prod.outlook.com (2603:10b6:208:2c1::26) 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_|DS0PR12MB8574:EE_ X-MS-Office365-Filtering-Correlation-Id: 21011d9b-9504-46ab-b5fe-08de0cc69271 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?E3pHersiJs6n1lFW8unyY43Zjb26iFrzMpJDmbiShSpRnBV3oQxccwLOJ7ro?= =?us-ascii?Q?0vHoLjaKSUtvfK2inxmKCZYaZBe8a1UZwyQX3+UCeD4rV7LwkQEQf3rT/q0+?= =?us-ascii?Q?E+q1EaoOVuUjGAoy0oqi2xlEADafTbn8GbbdWe8Lq0rT9jKi5faODCqbZjQd?= =?us-ascii?Q?lUAss5BEcoZSl1svJf0CnCq3tC7M/1lurOKkkgb5QY7t3AqQuunFoZTuZR6a?= =?us-ascii?Q?IvmQvDp2kit8As8/n40Y239FD1HDFBwURd2uCx+vIplOk20q9E4aKIsNlQfl?= =?us-ascii?Q?9QG7PpxraurSvF7Zzmn3FyjIZWDq4JefnPhTYL8KbqO6T/I2y/r9nU3pbZmy?= =?us-ascii?Q?OTO3ho3FsJt+TqgvJTz6rZDV0v06GzXMDoaycrxNVq+BmWEp/6gTR1tpgyN9?= =?us-ascii?Q?rG9cJoj//rAPeTHFhe5PYHlqSxi1o4BI6yo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E1Vq0195OkCGUANafeDXe2DjPramfC4M9zfhgtn/MJ9iUVp5ulE1d2440?= =?us-ascii?Q?Kdn5QCpi3Npz28lTKRPknNY7KEY3D1AnOicQyr/ln27Rxa0kOGT7wtU1RwJn?= =?us-ascii?Q?1jU3Nn0xNE/gLO1Z8PpcC0EWR6AvHmRq?= 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)(7416014)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?2RfIT6ZVL99CDnPNIe74gyGZBmZC2kKY8U8DISu+vcKkxuyebDMHTYJfDbfG?= =?us-ascii?Q?jfp9xd0UlPdc1Ez8vg+pTCmio936NSx1uS+zPf/58oS+W9vyVLzTDCxneSNP?= =?us-ascii?Q?2QNssQiZDTcbP5tBGvccYjpddhj61zA1WoPQr+sF1MZJRmGrl/Z00u4dDTw2?= =?us-ascii?Q?SKXN1vWOzEqACIvM7m8f6b8lX+wzjBZ0/guSQl5pZ2UJyUwI9pxISBffznST?= =?us-ascii?Q?dKm3xJd42tNA1LRX7wJRUAJuW+AbumHT6lRrft5hWJa7gOohJILrArIzIusK?= =?us-ascii?Q?Ward/Hu6Wz/NnEItBaP2tkNI9gXdGcY9UqgCFymWPX8VRSCBWF/VbU5lGnA4?= =?us-ascii?Q?J89tPGwjMwBLIw3SFO/gEwvUkignH2nNmVL8N48pJY3nAPLrvNhnl6Zaa006?= =?us-ascii?Q?HlWn1kDzyY+tIcgTZ4/WuGTbU1sXKj0ksiHK8R6l2e0A0jofpLHsb/5aSn8z?= =?us-ascii?Q?7I2I6/TqwuNdOpqzRnwMGrOQU3J+EfPFA3GKzTd8JVo+AiixTA0XbXHQ3U3R?= =?us-ascii?Q?PVE/QABl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VkH5/u?= =?us-ascii?Q?gMRvRE11pcm4uxZiEBQn+79JnKdJKNsyZ96JxzYw4JoWjiYEGxETPiDjO5zb?= =?us-ascii?Q?CfAwaX7sIm3taM+d6MYU0mgjwDvjyuqfcoUxgGjnpQcBCJGAwjQXmZ2rwsMB?= =?us-ascii?Q?qiwJIG0uG8tyWq+yHoRj27g7aXD1Bhkbkfx6iAqR?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 21011d9b-9504-46ab-b5fe-08de0cc69271 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:13:33.5084 (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: VL/Zqe53/nc5+C28Bez9FYYgggaVEGz1z3oetrSHwPI4P174iB6xjGk64gMVGiSWBIeUN/Z7Ej0ZdfMv6loFoQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8574 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 Acked-by: Danilo Krummrich --- 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 Sun Feb 8 09:13:23 2026 Received: from CO1PR03CU002.outbound.protection.outlook.com (mail-westus2azon11010015.outbound.protection.outlook.com [52.101.46.15]) (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 3823F34572A; Thu, 16 Oct 2025 15:13:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.46.15 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760627623; cv=fail; b=LJc0DxgHdS5TW+LhV3ksO7Ytj1rHTxgViYRFiT7HZkW1A6lbnmVw3doPG/EHqr0chkrJZqHfNhHwgIZV2fm0fu5DEhnOrAIWTUoo90yCCtsVvvklp+XUEyw3OWJ7fiV5ha2T4FK/I5txy6hlcjyD+SsND+q4Lyjtch+rrHHiXEM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760627623; c=relaxed/simple; bh=Zy6CeLa1IX+DLumKsCyO9borr12sd5dLcoQdkz29W14=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=nKVvylPegUYNcSLAWaiz55oMt+Um6BM8xME+xoo5nik6DplzPrwC8HNUR6NHUHk2jWXjzQxRr1BOtI9wgZh/YfOKgynZAYLd9hLdE0E1nHRSB+8PFF8VmQE2JPRkVDj4t0zT3/6HkX90Kdqve/AnmEWnMZZrsYwAkpxWvsq3Rlg= 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=BtlJYtMb; arc=fail smtp.client-ip=52.101.46.15 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="BtlJYtMb" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yg3RavisxMivMFZ4Xnf3sLry4BVJyllCMYrs7OHqj0C8AtUWDT//Y71CwbgZKvzmVr6Y7Ek7OwcOKS0HzukO6x1jfJRSm5PJNOxhjWK1eV3jb4j7+q6cPUdOmnUB19e9+DMhPG3B77JWorimL57lUKPEkbbD5AYMeMIOuFFryozpGcgOvSYSOpUrB3hlnDY1nZI86HrX1FLRFmsiOn8Vvud7BMjqt8ELzy7UjzIXRnCxYdQGQ8MEs7ucJ9F9oNmKo+ziOzbBVpeG2X04FHsXiULwP8kbgamEzyH+1iapUFxPpKmBNFLsqIy8O7zNs3B2LtU/8EjWJHI8Th2ZoHFmXQ== 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=Or4vegJ37dm6vFkg9XIyhJHgngzh+8yUExNw16FJvCk=; b=qkqZNY5WaGFMiRx97uK5WHIFmH+PDpHemm1p4xU/TW+5mf/SMIWEETpnOE8F2aPfJfesOwlHoTRoKqNGVF01hcvWDUWfazinariQkLJiKyLJ21F6/3f3Us+LlKkxFN7y0aYHaN8i5CFpXHAQGe7j50HM6iuMcCDTMIym1gD70cbcZu/tylWs8fQCT1n0BRRUm32V1D42hmivDZL87TkcRLM4StgoiLierR6YltVDSXx1iZWwLXSqBTZp15aODX5MOqf9aQF5CT+0LBhp6LyaR4R94ndNlxPlqjEI0p4umgVWNqgjxh1Knh721Jb9O1D7J8T7woKHL5NyZpEvWJerdQ== 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=Or4vegJ37dm6vFkg9XIyhJHgngzh+8yUExNw16FJvCk=; b=BtlJYtMby7O2XD+zGAut/9JAw1zC8DL0UfKqxgCZtBS0Vu2jlLD/Tod8Jaj5q4GnvJuGqZdf5mQ+Ru9YFiGqpVdpB/x12uZ+wczzVgmZaTsABAim9C9XVSD45/paoabj4yLbr++zjNbcRgIOLNK+OU7ZGLZNvsRfhK9ebUjsLqjRyRBcS+dxz3LzobDqbv8CtYDyjfH5PIcNoNcl3KU9ncK1RpYdYN0/slhUfaXA4E8yOXOo9mKDZw1CWjXatzHk/zpiXCBg8tbs4sPEAbC6vrq2pvzxaBBh1p61N88/9pWCTyoe0IN3n7iHtnBGLF/n0r72QeYgRSFqqAqGQb8wYg== 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 DS0PR12MB8574.namprd12.prod.outlook.com (2603:10b6:8:166::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9228.10; Thu, 16 Oct 2025 15:13:35 +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:13:35 +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.1 4/4] gpu: nova-core: bitfield: Add support for custom visiblity Date: Thu, 16 Oct 2025 11:13:23 -0400 Message-Id: <20251016151323.1201196-5-joelagnelf@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251016151323.1201196-1-joelagnelf@nvidia.com> References: <20251016151323.1201196-1-joelagnelf@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BN9P223CA0005.NAMP223.PROD.OUTLOOK.COM (2603:10b6:408:10b::10) 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_|DS0PR12MB8574:EE_ X-MS-Office365-Filtering-Correlation-Id: 1e121e24-191e-402d-b283-08de0cc693a2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?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g0pyVPKfQSLt?= =?us-ascii?Q?XqW/GC6YQ+1pmn/EUDqJbIVzNuYF8jPiAlbxai+Wbm9PNnV/sRFfiLKgXNEj?= =?us-ascii?Q?33+FdY6KUvMYl1i3lb3qUVdfYGffZHNa1PE86HnC3yQ+JJyv6OKHpe6QwUhF?= =?us-ascii?Q?/yqAGUJbTqmgRf+fjN/l9BYs/YGOoezSmA04PRi+NVlkJz5c/FW7bA0/31RA?= =?us-ascii?Q?YkCYWunjkrCqR23JZb4a++ngtibLA4gUjEsyzCqgO7CmstEUx89mgI2hee5V?= =?us-ascii?Q?6unTZmX3PeHw0nLh76qH6OM1BFkxPE+ZZj3jW4oJ5z39HdvUI2iS/OacYJXM?= =?us-ascii?Q?6jjeEev7UNXsiULX+578NFm5UZdVNG1MzZLoqauEqvlXB161Hek/KJytWU9V?= =?us-ascii?Q?XkjB5mqc1xIGqmlvvoz8z2ASzY6HGD9yfXKLuHK6DY2IjkNRMc4Z72rYhTd3?= =?us-ascii?Q?/FYBf+rH4oaFomKA3WKNU/7BzCUFDe2brNBNwdxlhTOnx4keiiWGWVY0I31m?= =?us-ascii?Q?sXoVvy+J9zg/U9SCuOfCM3uAgRdJatLi8UnKurrQ/bY4u4NigHznEpB8+1Bt?= =?us-ascii?Q?DOH1KTE/7xHykKvwErd5jeX+eBiR0XMA?= 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)(7416014)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?I1HzMzx+7Fxmb0lqkwiI/BDeb0ljo2rkH4WXOvrN1pVTTL6MyLAeD7Ki5PWw?= =?us-ascii?Q?RGLmi8yr85LicHDwInHKedSJGaxKFlgfck2F8PVLV6J8qoBCGi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c4o3iywjyXxvQXntEpANkXAi3RBcFSGfUr3rEh?= =?us-ascii?Q?utdbmau1SLaqVn9M1Rh8N0lPrB6wfZrII2nPeHYQmwAQgT6dPaV8IOWzVf8G?= =?us-ascii?Q?x7pCDpU46gbGPKknlp7xpja6X1ZdtYIFXYYTYa7y8JiZKz2bwBr5eGt+VysD?= =?us-ascii?Q?Bcv0AuUZN6AEoW7MCV+kvIDmt49S7gIYHUTWCIM6JYupdd2hNKEzD+RP1Et1?= =?us-ascii?Q?Q3saQaAqc+0CMplHtojrtQ4qV/4+gF8LQU/puaHv/XfWisF0BB9ddjtR4uW5?= =?us-ascii?Q?LoR+dWDaQdnwoR4cFs95tUehh8Yk195B3IkhbXM9JAExcjcs93Yy0kRCf2uo?= =?us-ascii?Q?CFddWqaQ2So6879PSmQry4nTkigW4+eWkbFZyp4XVt0mQyhTapdsZR2LsaA1?= =?us-ascii?Q?KXA4YFFl+3EGpolSwM5BRnOIQ+1SRlPlKE1QyYcYPMF7r43bUhgFPNyS8Sjs?= =?us-ascii?Q?1uFW4JHMA4+T7LllLsy1DTa8HzpV6JlJZTcjCTNIVmg20gYug+hE3sfCLqiB?= =?us-ascii?Q?iYpu5IyqivelofVaGD1S41Z2kCVIZ2Zyqx22yJCx3wQBEnlsuOAXVpa4kxD0?= =?us-ascii?Q?5nE/KNhXkwVCmDkn41+QkLb7yu28xloG2jYEsews?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1e121e24-191e-402d-b283-08de0cc693a2 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:13:35.4750 (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: jRUeB2sVVhsEU7r7qsFyO5MtCgI3iKYnq/C9G/GFkT/VaFTZ+SJzjdJPMRs0PoXQbxT6pqSu2oJdBhnZKfvA1A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8574 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 Acked-by: Danilo Krummrich --- 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