On 10/2/25 2:51 AM, Alexandre Courbot wrote:
On Thu Oct 2, 2025 at 11:16 AM JST, Elle Rhumsaa wrote:
On 10/2/25 1:41 AM, Alexandre Courbot wrote:
On Tue Sep 30, 2025 at 11:45 PM JST, Joel Fernandes wrote:
Add KUNIT tests to make sure the macro is working correctly.
Signed-off-by: Joel
On 10/2/25 1:41 AM, Alexandre Courbot wrote:
On Tue Sep 30, 2025 at 11:45 PM JST, Joel Fernandes wrote:
Add KUNIT tests to make sure the macro is working correctly.
Signed-off-by: Joel Fernandes
---
rust/kernel/bitfield.rs | 321
1 file changed, 321
On 9/24/2025 4:38 PM, Yury Norov wrote:
On Wed, Sep 24, 2025 at 12:52:41PM +0200, Greg KH wrote:
On Sun, Sep 21, 2025 at 03:47:55PM +0200, Danilo Krummrich wrote:
On Sun Sep 21, 2025 at 2:45 PM CEST, Greg KH wrote:
Again, regmap handles this all just fine, why not just make bindings to
tha
> ) => {
> static_assert!(::core::mem::size_of::() <= $stride);
> -bitstruct!(struct $name: u32 $(, $comment)? { $($fields)* } );
> +bitstruct!(pub(crate) struct $name: u32 $(, $comment)? { $($fields)*
> } );
> register!(@io_relative_array $name @ $base [ $offset [ $size ;
> $stride ] ]);
> };
>
> @@ -356,7 +356,7 @@ macro_rules! register {
> }
> ) => {
> static_assert!($idx < $alias::SIZE);
> -bitstruct!(struct $name: u32 $(, $comment)? { $($fields)* } );
> +bitstruct!(pub(crate) struct $name: u32 $(, $comment)? { $($fields)*
> } );
> register!(@io_relative $name @ $base [ $alias::OFFSET + $idx *
> $alias::STRIDE ] );
> };
>
> @@ -365,7 +365,7 @@ macro_rules! register {
> // to avoid it being interpreted in place of the relative register array
> alias rule.
> ($name:ident => $alias:ident [ $idx:expr ] $(, $comment:literal)? {
> $($fields:tt)* }) => {
> static_assert!($idx < $alias::SIZE);
> -bitstruct!(struct $name: u32 $(, $comment)? { $($fields)* } );
> +bitstruct!(pub(crate) struct $name: u32 $(, $comment)? { $($fields)*
> } );
> register!(@io_fixed $name @ $alias::OFFSET + $idx * $alias::STRIDE );
> };
>
> --
> 2.34.1
>
>
Reviewed-by: Elle Rhumsaa
fset [ $size ; $stride ]);
> };
>
> @@ -334,7 +334,7 @@ macro_rules! register {
> $(, $comment:literal)? { $($fields:tt)* }
> ) => {
> static_assert!(::core::mem::size_of::() <= $stride);
> -bitstruct!(struct $name $(, $comment)? { $($fields)* } );
> +bitstruct!(struct $name: u32 $(, $comment)? { $($fields)* } );
> register!(@io_relative_array $name @ $base [ $offset [ $size ;
> $stride ] ]);
> };
>
> @@ -356,7 +356,7 @@ macro_rules! register {
> }
> ) => {
> static_assert!($idx < $alias::SIZE);
> -bitstruct!(struct $name $(, $comment)? { $($fields)* } );
> +bitstruct!(struct $name: u32 $(, $comment)? { $($fields)* } );
> register!(@io_relative $name @ $base [ $alias::OFFSET + $idx *
> $alias::STRIDE ] );
> };
>
> @@ -365,7 +365,7 @@ macro_rules! register {
> // to avoid it being interpreted in place of the relative register array
> alias rule.
> ($name:ident => $alias:ident [ $idx:expr ] $(, $comment:literal)? {
> $($fields:tt)* }) => {
> static_assert!($idx < $alias::SIZE);
> -bitstruct!(struct $name $(, $comment)? { $($fields)* } );
> +bitstruct!(struct $name: u32 $(, $comment)? { $($fields)* } );
> register!(@io_fixed $name @ $alias::OFFSET + $idx * $alias::STRIDE );
> };
>
> --
> 2.34.1
>
>
Reviewed-by: Elle Rhumsaa
ult where
> -T: ::core::ops::Deref>,
> -B: crate::regs::macros::RegisterBase<$base>,
> + ) -> $crate::error::Result where
> +T: ::core::ops::Deref>,
> +B: $crate::register::RegisterBase<$base>,
> {
> if idx < Self::SIZE {
> Ok(Self::read(io, base, idx))
> } else {
> -Err(EINVAL)
> +Err($crate::error::code::EINVAL)
> }
> }
>
> @@ -690,14 +692,14 @@ pub(crate) fn try_write(
> io: &T,
> base: &B,
> idx: usize,
> -) -> ::kernel::error::Result where
> -T: ::core::ops::Deref>,
> -B: crate::regs::macros::RegisterBase<$base>,
> +) -> $crate::error::Result where
> +T: ::core::ops::Deref>,
> +B: $crate::register::RegisterBase<$base>,
> {
> if idx < Self::SIZE {
> Ok(self.write(io, base, idx))
> } else {
> -Err(EINVAL)
> +Err($crate::error::code::EINVAL)
> }
> }
>
> @@ -713,17 +715,19 @@ pub(crate) fn try_alter(
> base: &B,
> idx: usize,
> f: F,
> -) -> ::kernel::error::Result where
> -T: ::core::ops::Deref>,
> -B: crate::regs::macros::RegisterBase<$base>,
> +) -> $crate::error::Result where
> +T: ::core::ops::Deref>,
> +B: $crate::register::RegisterBase<$base>,
> F: ::core::ops::FnOnce(Self) -> Self,
> {
> if idx < Self::SIZE {
> Ok(Self::alter(io, base, idx, f))
> } else {
> -Err(EINVAL)
> +Err($crate::error::code::EINVAL)
> }
> }
> }
> };
> }
> +
> +pub use register;
> --
> 2.34.1
>
>
Reviewed-by: Elle Rhumsaa
> ) => {
> static_assert!(::core::mem::size_of::() <= $stride);
> -bitstruct!(struct $name: u32 $(, $comment)? { $($fields)* } );
> +bitstruct!(pub(crate) struct $name: u32 $(, $comment)? { $($fields)*
> } );
> register!(@io_relative_array $name @ $base [ $offset [ $size ;
> $stride ] ]);
> };
>
> @@ -356,7 +356,7 @@ macro_rules! register {
> }
> ) => {
> static_assert!($idx < $alias::SIZE);
> -bitstruct!(struct $name: u32 $(, $comment)? { $($fields)* } );
> +bitstruct!(pub(crate) struct $name: u32 $(, $comment)? { $($fields)*
> } );
> register!(@io_relative $name @ $base [ $alias::OFFSET + $idx *
> $alias::STRIDE ] );
> };
>
> @@ -365,7 +365,7 @@ macro_rules! register {
> // to avoid it being interpreted in place of the relative register array
> alias rule.
> ($name:ident => $alias:ident [ $idx:expr ] $(, $comment:literal)? {
> $($fields:tt)* }) => {
> static_assert!($idx < $alias::SIZE);
> -bitstruct!(struct $name: u32 $(, $comment)? { $($fields)* } );
> +bitstruct!(pub(crate) struct $name: u32 $(, $comment)? { $($fields)*
> } );
> register!(@io_fixed $name @ $alias::OFFSET + $idx * $alias::STRIDE );
> };
>
> --
> 2.34.1
>
>
Reviewed-by: Elle Rhumsaa
t; +}
> +
> +#[inline(always)]
> +#[allow(dead_code)]
> +$vis const fn [](mut self, val: $field_type)
> -> Self {
> +self.0 = bitstruct_write_bits!(self.0, $hi, $lo, val,
> $storage);
> + self
> +}
> +}
> +}
> +};
> +}
This is awesome. Is there a place for this to live outside of
`nova-core`? I would think this would be extremely useful as a general
helper for bitfield struct definitions.
> diff --git a/drivers/gpu/nova-core/nova_core.rs
> b/drivers/gpu/nova-core/nova_core.rs
> index cb2bbb30cba1..54505cad4a73 100644
> --- a/drivers/gpu/nova-core/nova_core.rs
> +++ b/drivers/gpu/nova-core/nova_core.rs
> @@ -2,6 +2,7 @@
>
> //! Nova Core GPU Driver
>
> +mod bitstruct;
> mod dma;
> mod driver;
> mod falcon;
> --
> 2.34.1
Reviewed-by: Elle Rhumsaa