On 03/10/2025 17:47, Joel Fernandes wrote:
Out of broad need for the register and bitfield macros in Rust, move
them out of nova into the kernel crate. Several usecases need them (Nova
is already using these and Tyr developers said they need them).
bitfield moved into kernel crate - defines bitfields in Rust.
register moved into io module - defines hardware registers and accessors.
Reviewed-by: Alexandre Courbot <[email protected]>
Reviewed-by: Elle Rhumsaa <[email protected]>
Signed-off-by: Joel Fernandes <[email protected]>
---
drivers/gpu/nova-core/falcon.rs | 2 +-
drivers/gpu/nova-core/falcon/gsp.rs | 4 +-
drivers/gpu/nova-core/falcon/sec2.rs | 2 +-
drivers/gpu/nova-core/nova_core.rs | 3 -
drivers/gpu/nova-core/regs.rs | 6 +-
.../gpu/nova-core => rust/kernel}/bitfield.rs | 27 ++++-----
rust/kernel/io.rs | 1 +
.../macros.rs => rust/kernel/io/register.rs | 58 ++++++++++---------
rust/kernel/lib.rs | 1 +
9 files changed, 54 insertions(+), 50 deletions(-)
rename {drivers/gpu/nova-core => rust/kernel}/bitfield.rs (91%)
rename drivers/gpu/nova-core/regs/macros.rs => rust/kernel/io/register.rs
(93%)
...
index c0a5194e8d97..c24d956f122f 100644
--- a/drivers/gpu/nova-core/regs/macros.rs
+++ b/rust/kernel/io/register.rs
Assuming that register.rs is supposed to become the "generic" way to
access hardware registers I started to have a look to it. Some weeks
back testing interrupts I used some quite simple timer with 4 registers
[1]. Now, thinking about converting it to register!() I have three
understanding / usage questions:
* At the moment register!() is for 32-bit registers, only? So it can't
be used for my example having 8-bit and 16-bit registers as well?
* In my example I used io.try_write*() and io.try_read*() for the
register access. What is the relationship between these and the
register!() accessors (e.g. from the examples BOOT_0::read(&bar);)? Will
both stay? When to use which?
Note: Due to the file move obviously not the full content of the "new"
file register.rs is shown in this patch. Therefore, let me try it this
way, citing from register.rs:
-- cut --
...
/// This defines a `BOOT_0` type which can be read or written from
offset `0x100` of an `Io`
/// region
....
/// ```ignore
/// // Read from the register's defined offset (0x100).
/// let boot0 = BOOT_0::read(&bar);
-- cut --
* What is "&bar" in this example? Is it the `Io` region the explanation
talks about?
Thanks!
Dirk
[1]
https://lore.kernel.org/rust-for-linux/[email protected]/
The registers:
const TSTR: usize = 0x4; // 8 Bit register
const TCOR: usize = 0x8; // 32 Bit register
const TCNT: usize = 0xC; // 32 Bit register
const TCR: usize = 0x10; // 16 Bit register