On Thu Mar 12, 2026 at 5:39 PM JST, Boris Brezillon wrote:
<snip>
>> +
>> + impl GPU_COMMAND {
>> + /// No operation. This is the default value.
>> + pub(crate) const NOP: u32 = 0;
>> + /// Reset the GPU.
>> + pub(crate) const RESET: u32 = 1;
>> + /// Flush caches.
>> + pub(crate) const FLUSH_CACHES: u32 = 4;
>> + /// Clear GPU faults.
>> + pub(crate) const CLEAR_FAULT: u32 = 7;
>> + }
>> +
>> + register! {
>> + /// GPU command register in reset mode.
>> + /// Set command to [`GPU_COMMAND::RESET`] to set reset_mode.
>> + pub(crate) GPU_COMMAND_RESET (u32) => GPU_COMMAND {
>> + 7:0 command;
>
> Alexandre, dunno how hard it would be to extend this alias syntax to
> provide auto-initialization/expected-value of certain fields, like:
>
> pub(crate) GPU_COMMAND_RESET (u32) => GPU_COMMAND {
> 7:0 command <- GPU_COMMAND::RESET;
> 11:8 reset_mode;
> }
>
> so that when you instantiate a GPU_COMMAND_RESET, all you have to set is
> reset_mode and the command gets set to GPU_COMMAND::RESET for you.
> (that's for the write path, for the read path, you'll need some sort of
> match to do the re-interpretation anyway).
You can do this by augmenting the methods if `GPU_COMMAND_RESET` using a
dedicated impl block - in this case you probably want to implement
`Default`:
impl Default for GPU_COMMAND_RESET {
fn default() -> Self {
Self::zeroed().with_command(GPU_COMMAND::RESET)
}
}
Then you can just do `GPU_COMMAND_RESET::default()` to create the
register with the expected value.
Maybe we could have a syntax to automatically generate a `Default`
implementation in the future.
I will have more comments to do on this series (notably the use of
constants), but it's great to see the register macro being used!