[PATCH v2 17/19] gpu: nova-core: register: add support for register arrays

Alexandre Courbot acourbot at nvidia.com
Mon Jul 28 05:12:01 UTC 2025


On Sat Jul 26, 2025 at 4:12 AM JST, Daniel Almeida wrote:
<snip>
>> macro_rules! register {
>>     // Creates a register at a fixed offset of the MMIO space.
>>     ($name:ident @ $offset:literal $(, $comment:literal)? { $($fields:tt)* } ) => {
>> @@ -187,6 +238,35 @@ macro_rules! register {
>>         register!(@io_relative $name @ $base [ $alias::OFFSET ]);
>>     };
>> 
>> +    // Creates an array of registers at a fixed offset of the MMIO space.
>> +    (
>> +        $name:ident @ $offset:literal [ $size:expr ; $stride:expr ] $(, $comment:literal)? {
>> +            $($fields:tt)*
>> +        }
>> +    ) => {
>> +        static_assert!(::core::mem::size_of::<u32>() <= $stride);
>
> Perhaps a TODO here would be nice, since you’ll want to change it when/if
> this macros get to support non-u32 types (which is apparently on the roadmap
> IIUC).

There are many `u32`s sprinkled across that code, it would be a bit
tedious to have a TODO for each of them. And when we start making them
generic the code won't compile unless they are all replaced anyway, so I
think we are safe. :)

>
>> +        register!(@core $name $(, $comment)? { $($fields)* } );
>> +        register!(@io_array $name @ $offset [ $size ; $stride ]);
>> +    };
>> +
>> +    // Shortcut for contiguous array of registers (stride == size of element).
>> +    (
>> +        $name:ident @ $offset:literal [ $size:expr ] $(, $comment:literal)? {
>> +            $($fields:tt)*
>> +        }
>> +    ) => {
>> +        register!($name @ $offset [ $size ; ::core::mem::size_of::<u32>() ] $(, $comment)? {
>
> Same here.
>
>> +            $($fields)*
>> +        } );
>> +    };
>> +
>> +    // Creates an alias of register `idx` of array of registers `alias` with its own fields.
>> +    ($name:ident => $alias:ident [ $idx:expr ] $(, $comment:literal)? { $($fields:tt)* }) => {
>> +        static_assert!($idx < $alias::SIZE);
>> +        register!(@core $name $(, $comment)? { $($fields)* } );
>> +        register!(@io_fixed $name @ $alias::OFFSET + $idx * $alias::STRIDE );
>
> Why is this @io_fixed?

Because once you index a register (which the alias does), you obtain
what is effectively a fixed-address register, so these are the correct
I/O accessors here.


More information about the Nouveau mailing list