[PATCH v3 07/10] gpu: nova-core: falcon: introduce `bounded_enum` macro

Alexandre Courbot acourbot at nvidia.com
Mon Mar 23 07:22:53 PDT 2026


On Mon Mar 23, 2026 at 9:43 PM JST, Gary Guo wrote:
> On Mon Mar 23, 2026 at 11:07 AM GMT, Alexandre Courbot wrote:
>> Introduce a powered-up version of our ad-hoc `impl_from_enum_to_u8`
>> macro that allows the definition of an enum type associated to a
>> `Bounded` of a given width, and provides the `From` and `TryFrom`
>> implementations required to use that enum as a register field member.
>>
>> The next patch will make use of it to convert all falcon registers to
>> the kernel register macro.
>>
>> The macro is unused in this patch: it is introduced ahead-of-time to
>> avoid diff mingling in the next patch that would make it difficult to
>> review.
>>
>> Reviewed-by: Gary Guo <gary at garyguo.net>
>> Signed-off-by: Alexandre Courbot <acourbot at nvidia.com>
>> ---
>>  drivers/gpu/nova-core/falcon.rs | 82 +++++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 82 insertions(+)
>>
>> diff --git a/drivers/gpu/nova-core/falcon.rs b/drivers/gpu/nova-core/falcon.rs
>> index 5a4f7fc85160..5221e4476f90 100644
>> --- a/drivers/gpu/nova-core/falcon.rs
>> +++ b/drivers/gpu/nova-core/falcon.rs
>> @@ -54,6 +54,88 @@ fn from(value: $enum_type) -> Self {
>>      };
>>  }
>>  
>> +/// Creates an enum type associated to a `Bounded`, with a `From` conversion to the associated
>> +/// `Bounded` and either a `TryFrom` or `From` converting from the associated `Bounded`.
>> +// TODO[FPRI]: This is a temporary solution to be replaced with the corresponding derive macros
>> +// once they land.
>> +#[expect(unused)]
>> +macro_rules! bounded_enum {
>> +    (
>> +        $(#[doc = $enum_doc:expr])*
>> +        enum $enum_type:ident with $from_impl:ident<Bounded<$width:ty, $length:literal>> {
>> +            $( $(#[doc = $variant_doc:expr])* $variant:ident = $value:expr),* $(,)*
>> +        }
>> +    ) => {
>> +        $(#[doc = $enum_doc])*
>> +        #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
>> +        pub(crate) enum $enum_type {
>> +            $(
>> +                $(#[doc = $variant_doc])*
>> +                $variant = $value
>> +            ),*
>> +        }
>> +
>> +        impl From<$enum_type> for Bounded<$width, $length> {
>> +            fn from(value: $enum_type) -> Self {
>> +                match value {
>> +                    $($enum_type::$variant => Bounded::<$width, _>::new::<$value>()),*
>
> Hi Alex,
>
> This looks exactly the same as the last version, without out the {} and MAX..
> change made (which you mentioned in the cover letter).

I'm so sorry. I mistakenly squashed the fixup commit into the next
commit instead of this one. I will resend after hearing back from Danilo
about where the macro should reside.




More information about the linux-riscv mailing list