linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nicolas Dufresne <nicolas@ndufresne.ca>
To: Daniel Almeida <daniel.almeida@collabora.com>,
	wedsonaf@gmail.com,  ojeda@kernel.org, mchehab@kernel.org,
	hverkuil@xs4all.nl
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-media@vger.kernel.org, kernel@collabora.com
Subject: Re: [RFC PATCH v2 2/2] media: rkvdec: rewrite parts of the driver in Rust
Date: Thu, 07 Mar 2024 15:56:03 -0500	[thread overview]
Message-ID: <c70935815ffc29ae5256b94c0e4880952abad79c.camel@ndufresne.ca> (raw)
In-Reply-To: <20240307190841.10260-3-daniel.almeida@collabora.com>

Hi Daniel,

as I'm already sold to the idea, I decided to discuss other things ;-P see
below.

Le jeudi 07 mars 2024 à 16:08 -0300, Daniel Almeida a écrit :
> +++ b/drivers/staging/media/rkvdec/regs.rs
> @@ -0,0 +1,237 @@
> +#![allow(dead_code)]
> +#![allow(unused_macros)]
> +
> +pub(crate) const RKVDEC_REG_INTERRUPT: u32 = 0x004;
> +pub(crate) const RKVDEC_INTERRUPT_DEC_E: u32 = 1 << 0;
> +pub(crate) const RKVDEC_CONFIG_DEC_CLK_GATE_E: u32 = 1 << 1;
> +pub(crate) const RKVDEC_E_STRMD_CLKGATE_DIS: u32 = 1 << 2;

Regs file are a bit our coded reference information on how the registers are
layout in memory. So I believe the alignment, indent and readability of that
file would at least need polishing.

But to the light of your comment, being able to use more modern utility, isn't
there something in Rust we could use to better map the registers ? These
variables are just mask offset to help someone write specific bits within a list
of 32bit registers (Hantro and RKVDEC have that in common). In downstream mpp
userspace driver, they maps all the register with a C struct.

struct reg123 {
  val1 :3  // bit 31-29
  val2 :20 // bit 28-9
  val3 :9  // bit 8-0
};

I seriously think it looks nicer, and when the compiler does not screw it up
(the main reason we don't use that), it is also a lot safer and simpler to use.
Now, lets forget about C, my question is just if there is something in Rust that
could give us the safety to edit the right portion of a register, but also allow
expressing that map in a readable form.

Note that sometimes, we may want to read the register before editing it,
something MPP giant C struct does not help with.

Nicolas

  reply	other threads:[~2024-03-07 20:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-27 21:51 [RFC PATCH 0/1] Rewrite the VP9 codec library in Rust Daniel Almeida
2024-02-27 21:51 ` [RFC PATCH 1/1] v4l2-core: rewrite the VP9 " Daniel Almeida
2024-02-28 14:13   ` Alice Ryhl
2024-02-28 17:59     ` Daniel Almeida
2024-03-07 19:08 ` [RFC PATCH v2 0/2] Rewrite parts of rkvdec driver and the VP9 codec " Daniel Almeida
2024-03-07 19:08   ` [RFC PATCH v2 1/2] v4l2-core: rewrite the VP9 " Daniel Almeida
2024-03-07 19:08   ` [RFC PATCH v2 2/2] media: rkvdec: rewrite parts of the driver " Daniel Almeida
2024-03-07 20:56     ` Nicolas Dufresne [this message]
2024-03-07 21:45       ` Daniel Almeida
2024-03-07 20:04   ` [RFC PATCH v2 0/2] Rewrite parts of rkvdec driver and the VP9 codec library " Deborah Brouwer

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=c70935815ffc29ae5256b94c0e4880952abad79c.camel@ndufresne.ca \
    --to=nicolas@ndufresne.ca \
    --cc=daniel.almeida@collabora.com \
    --cc=hverkuil@xs4all.nl \
    --cc=kernel@collabora.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=wedsonaf@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).