Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpu: nova-core: impl From for u32 for enums used from register!

Implement From for u32 for all enum types used within the register!()
macro.

This avoids a conflict with [1] as reported in [2].

Cc: Alexandre Courbot <acourbot@nvidia.com>
Cc: Miguel Ojeda <ojeda@kernel.org>
Link: https://lore.kernel.org/r/20250615-ptr-as-ptr-v12-5-f43b024581e8@gmail.com [1]
Link: https://lore.kernel.org/all/20250624173114.3be38990@canb.auug.org.au/ [2]
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Tested-by: Alexandre Courbot <acourbot@nvidia.com>
Link: https://lore.kernel.org/r/20250624132337.2242-1-dakr@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

+19
+19
drivers/gpu/nova-core/falcon.rs
··· 20 20 mod hal; 21 21 pub(crate) mod sec2; 22 22 23 + // TODO[FPRI]: Replace with `ToPrimitive`. 24 + macro_rules! impl_from_enum_to_u32 { 25 + ($enum_type:ty) => { 26 + impl From<$enum_type> for u32 { 27 + fn from(value: $enum_type) -> Self { 28 + value as u32 29 + } 30 + } 31 + }; 32 + } 33 + 23 34 /// Revision number of a falcon core, used in the [`crate::regs::NV_PFALCON_FALCON_HWCFG1`] 24 35 /// register. 25 36 #[repr(u8)] ··· 45 34 Rev6 = 6, 46 35 Rev7 = 7, 47 36 } 37 + impl_from_enum_to_u32!(FalconCoreRev); 48 38 49 39 // TODO[FPRI]: replace with `FromPrimitive`. 50 40 impl TryFrom<u8> for FalconCoreRev { ··· 80 68 Subversion2 = 2, 81 69 Subversion3 = 3, 82 70 } 71 + impl_from_enum_to_u32!(FalconCoreRevSubversion); 83 72 84 73 // TODO[FPRI]: replace with `FromPrimitive`. 85 74 impl TryFrom<u8> for FalconCoreRevSubversion { ··· 115 102 /// High-Secure: runs signed code with full privileges. Signature is validated by boot ROM. 116 103 Heavy = 3, 117 104 } 105 + impl_from_enum_to_u32!(FalconSecurityModel); 118 106 119 107 // TODO[FPRI]: replace with `FromPrimitive`. 120 108 impl TryFrom<u8> for FalconSecurityModel { ··· 144 130 #[default] 145 131 Rsa3k = 1, 146 132 } 133 + impl_from_enum_to_u32!(FalconModSelAlgo); 147 134 148 135 // TODO[FPRI]: replace with `FromPrimitive`. 149 136 impl TryFrom<u8> for FalconModSelAlgo { ··· 166 151 #[default] 167 152 Size256B = 0x6, 168 153 } 154 + impl_from_enum_to_u32!(DmaTrfCmdSize); 169 155 170 156 // TODO[FPRI]: replace with `FromPrimitive`. 171 157 impl TryFrom<u8> for DmaTrfCmdSize { ··· 189 173 /// RISC-V core is active. 190 174 Riscv = 1, 191 175 } 176 + impl_from_enum_to_u32!(PeregrineCoreSelect); 192 177 193 178 impl From<bool> for PeregrineCoreSelect { 194 179 fn from(value: bool) -> Self { ··· 220 203 /// Non-coherent system memory. 221 204 NoncoherentSysmem = 2, 222 205 } 206 + impl_from_enum_to_u32!(FalconFbifTarget); 223 207 224 208 // TODO[FPRI]: replace with `FromPrimitive`. 225 209 impl TryFrom<u8> for FalconFbifTarget { ··· 247 229 /// Physical memory addresses. 248 230 Physical = 1, 249 231 } 232 + impl_from_enum_to_u32!(FalconFbifMemType); 250 233 251 234 /// Conversion from a single-bit register field. 252 235 impl From<bool> for FalconFbifMemType {