Skip to content

Commit 1b8233b

Browse files
author
Danilo Krummrich
committed
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 <[email protected]> Cc: Miguel Ojeda <[email protected]> Link: https://lore.kernel.org/r/[email protected] [1] Link: https://lore.kernel.org/all/[email protected]/ [2] Reviewed-by: Alexandre Courbot <[email protected]> Tested-by: Alexandre Courbot <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Danilo Krummrich <[email protected]>
1 parent 3606620 commit 1b8233b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

drivers/gpu/nova-core/falcon.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ pub(crate) mod gsp;
2020
mod hal;
2121
pub(crate) mod sec2;
2222

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+
2334
/// Revision number of a falcon core, used in the [`crate::regs::NV_PFALCON_FALCON_HWCFG1`]
2435
/// register.
2536
#[repr(u8)]
@@ -34,6 +45,7 @@ pub(crate) enum FalconCoreRev {
3445
Rev6 = 6,
3546
Rev7 = 7,
3647
}
48+
impl_from_enum_to_u32!(FalconCoreRev);
3749

3850
// TODO[FPRI]: replace with `FromPrimitive`.
3951
impl TryFrom<u8> for FalconCoreRev {
@@ -68,6 +80,7 @@ pub(crate) enum FalconCoreRevSubversion {
6880
Subversion2 = 2,
6981
Subversion3 = 3,
7082
}
83+
impl_from_enum_to_u32!(FalconCoreRevSubversion);
7184

7285
// TODO[FPRI]: replace with `FromPrimitive`.
7386
impl TryFrom<u8> for FalconCoreRevSubversion {
@@ -102,6 +115,7 @@ pub(crate) enum FalconSecurityModel {
102115
/// High-Secure: runs signed code with full privileges. Signature is validated by boot ROM.
103116
Heavy = 3,
104117
}
118+
impl_from_enum_to_u32!(FalconSecurityModel);
105119

106120
// TODO[FPRI]: replace with `FromPrimitive`.
107121
impl TryFrom<u8> for FalconSecurityModel {
@@ -130,6 +144,7 @@ pub(crate) enum FalconModSelAlgo {
130144
#[default]
131145
Rsa3k = 1,
132146
}
147+
impl_from_enum_to_u32!(FalconModSelAlgo);
133148

134149
// TODO[FPRI]: replace with `FromPrimitive`.
135150
impl TryFrom<u8> for FalconModSelAlgo {
@@ -151,6 +166,7 @@ pub(crate) enum DmaTrfCmdSize {
151166
#[default]
152167
Size256B = 0x6,
153168
}
169+
impl_from_enum_to_u32!(DmaTrfCmdSize);
154170

155171
// TODO[FPRI]: replace with `FromPrimitive`.
156172
impl TryFrom<u8> for DmaTrfCmdSize {
@@ -173,6 +189,7 @@ pub(crate) enum PeregrineCoreSelect {
173189
/// RISC-V core is active.
174190
Riscv = 1,
175191
}
192+
impl_from_enum_to_u32!(PeregrineCoreSelect);
176193

177194
impl From<bool> for PeregrineCoreSelect {
178195
fn from(value: bool) -> Self {
@@ -203,6 +220,7 @@ pub(crate) enum FalconFbifTarget {
203220
/// Non-coherent system memory.
204221
NoncoherentSysmem = 2,
205222
}
223+
impl_from_enum_to_u32!(FalconFbifTarget);
206224

207225
// TODO[FPRI]: replace with `FromPrimitive`.
208226
impl TryFrom<u8> for FalconFbifTarget {
@@ -229,6 +247,7 @@ pub(crate) enum FalconFbifMemType {
229247
/// Physical memory addresses.
230248
Physical = 1,
231249
}
250+
impl_from_enum_to_u32!(FalconFbifMemType);
232251

233252
/// Conversion from a single-bit register field.
234253
impl From<bool> for FalconFbifMemType {

0 commit comments

Comments
 (0)