Re: [PATCH v2 08/10] gpu: nova-core: convert falcon registers to kernel register macro

From: Alexandre Courbot

Date: Sat Mar 21 2026 - 02:17:07 EST


On Sat Mar 21, 2026 at 4:52 AM JST, John Hubbard wrote:
> On 3/20/26 10:38 AM, Joel Fernandes wrote:
>> Hi Alex,
>>
>> On 3/20/2026 8:19 AM, Alexandre Courbot wrote:
>>> /// Reset the controller, select the falcon core, and wait for memory scrubbing to complete.
>>> @@ -616,9 +462,10 @@ pub(crate) fn reset(&self, bar: &Bar0) -> Result {
>>> self.hal.select_core(self, bar)?;
>>> self.hal.reset_wait_mem_scrubbing(bar)?;
>>>
>>> - regs::NV_PFALCON_FALCON_RM::default()
>>> - .set_value(bar.read(regs::NV_PMC_BOOT_0).into())
>>> - .write(bar, &E::ID);
>>> + bar.write(
>>> + WithBase::of::<E>(),
>>> + regs::NV_PFALCON_FALCON_RM::from(bar.read(regs::NV_PMC_BOOT_0).into_raw()),
>>> + );
>>>
>>
>> Overall, I think the series is good improvement but I still feel this part is a
>> step back in readability, and we should come up with something better. I don't
>> think there's any chance anyone can memorize this syntax.
>
> I must reluctantly (because I know this conversation has gone very
> long, across so many versions) agree. That .write() statement is just
> brutal, and we will be relying on AI in order to even figure it out,
> I fear.
>
> I'd hoped that there were other, simpler forms to express this,
> is that not the case here?

Is the problem only about this particular `write()` statement? If so
there are other ways to write it, which we definitely should do if we
consider the nasty thing it is doing: read PMC_BOOT_0, extract its raw
value, forcibly store it into PFALCON_FALCON_RM, and write that value
back into the instance belonging to engine `E`.

It's quite a mouthful. Using a temporary value would help. Maybe we can
also implement a `From<NV_PMC_BOOT_0> on `PFALCON_FALCON_RM`, as it is
clearly used with that intent here.

Future features like projections the macro to initialize bitfields (once
they are extracted) should also improve readability. Meanwhile, it is of
course fine to use variables to smoothen complex statements a bit,
although I'd say this is beyond the scope of this series which tries to
translate the code 1:1.