[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <c70935815ffc29ae5256b94c0e4880952abad79c.camel@ndufresne.ca>
Date: Thu, 07 Mar 2024 15:56:03 -0500
From: Nicolas Dufresne <nicolas@...fresne.ca>
To: Daniel Almeida <daniel.almeida@...labora.com>, wedsonaf@...il.com,
ojeda@...nel.org, mchehab@...nel.org, hverkuil@...all.nl
Cc: rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-media@...r.kernel.org, kernel@...labora.com
Subject: Re: [RFC PATCH v2 2/2] media: rkvdec: rewrite parts of the driver
in Rust
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
Powered by blists - more mailing lists