public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: "Danilo Krummrich" <dakr@kernel.org>
To: "Daniel Almeida" <daniel.almeida@collabora.com>
Cc: "Dirk Behme" <Dirk.Behme@de.bosch.com>,
	"Dirk Behme" <dirk.behme@gmail.com>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Steven Price" <steven.price@arm.com>,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	rust-for-linux@vger.kernel.org,
	"Alexandre Courbot" <acourbot@nvidia.com>
Subject: Re: [PATCH] rust/drm: tyr: Convert to the register!() macro
Date: Fri, 16 Jan 2026 15:56:44 +0100	[thread overview]
Message-ID: <DFQ3NOFEAIRC.3V5QZUXJJ7CMA@kernel.org> (raw)
In-Reply-To: <1EF6A3B7-216F-47C3-8631-25C38994BAC1@collabora.com>

On Fri Jan 16, 2026 at 1:26 PM CET, Daniel Almeida wrote:
> +cc Alex,
>
>
>>>> +    31:0    l2_pwractive_hi as u32, "Bitmap of L2 caches active (higher 32 bits)";
>>>> +});
>>>> +
>>>>  pub(crate) const MCU_CONTROL_ENABLE: u32 = 1;
>>>>  pub(crate) const MCU_CONTROL_AUTO: u32 = 2;
>>>>  pub(crate) const MCU_CONTROL_DISABLE: u32 = 0;
>>>>  -pub(crate) const MCU_STATUS: Register<0x704> = Register;
>>>> +register!(McuControl @ 0x700, "Controls the execution state of the MCU subsystem" {
>>>> +    1:0     req as u32, "Request state change";
>>>> +});
>>> Any reason why req is a u32 and not a u8? Same for some other places.
>>> And would it be an option to move the const MCU_CONTROL* to an ìmpl
>>> McuControl Same for STATUS below.
>> 
>> Just fyi something like [1] builds for me.
>> 
>> This is inspired by
>> 
>> https://lore.kernel.org/rust-for-linux/20251003154748.1687160-6-joelagnelf@nvidia.com/
>> 
>> Best regards
>> 
>> Dirk
>> 
>> [1]
>> 
>> #[repr(u32)]
>> #[derive(Debug, Default, Clone, Copy, PartialEq)]
>> enum McuControl {
>>    #[default]
>>    Disable = 0,
>>    Enable = 1,
>>    Auto = 2,
>> }
>> 
>> impl From<McuControl> for u8 {
>>    fn from(ctrl: McuControl) -> Self {
>>        ctrl as u8
>>    }
>> }
>> 
>> impl From<u8> for McuControl {
>>    fn from(req: u8) -> Self {
>>        match req & 0x3 {
>>            0 => McuControl::Disable,
>>            1 => McuControl::Enable,
>>            2 => McuControl::Auto,
>>            _ => McuControl::Disable,
>>        }
>>    }
>> }
>> 
>> register!(MCUCONTROL @ 0x700, "Controls the execution state of the MCU subsystem" {
>>    1:0     req as u8 => McuControl, "Request state change";
>> });
>
> Alex, looking at the above, I wonder if a “as Foo” would be a good
> addition to the macro? That would then invoke a TryFrom implementation, i.e.:
>
>
> register!(MCUCONTROL @ 0x700, "Controls the execution state of the MCU subsystem" {
>    1:0     req as McuControl => McuControl, "Request state change";
> });

This would imply the assumption that req is treated as u8 by register!()
automatically before calling the TryFrom impl.

One could argue that this is reasonable, since the value is only two bits wide,
but it might not always be desired. I think keeping this explict is better.

  reply	other threads:[~2026-01-16 14:56 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-14 22:53 [PATCH] rust/drm: tyr: Convert to the register!() macro Daniel Almeida
2026-01-15 10:35 ` Steven Price
2026-01-16 12:12   ` Daniel Almeida
2026-01-15 17:05 ` Dirk Behme
2026-01-16  7:10   ` Dirk Behme
2026-01-16 12:26     ` Daniel Almeida
2026-01-16 14:56       ` Danilo Krummrich [this message]
2026-01-16 15:19       ` Alexandre Courbot
2026-01-16 15:25         ` Danilo Krummrich
2026-01-16 12:23   ` Daniel Almeida
2026-01-16 13:00     ` Gary Guo
2026-01-16 13:38       ` Daniel Almeida
2026-01-16 13:53         ` Gary Guo
2026-01-16 13:58           ` Danilo Krummrich
2026-01-16 13:00     ` Dirk Behme
2026-01-16 13:59       ` Daniel Almeida

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DFQ3NOFEAIRC.3V5QZUXJJ7CMA@kernel.org \
    --to=dakr@kernel.org \
    --cc=Dirk.Behme@de.bosch.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=daniel.almeida@collabora.com \
    --cc=dirk.behme@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=steven.price@arm.com \
    --cc=tmgross@umich.edu \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox