@@ -121,8 +121,8 @@
io::IoLoc, //
};
-/// Trait implemented by all registers.
-pub trait Register: Sized {
+/// Trait implemented by registers with a fixed offset.
+pub trait FixedRegister: Sized {
/// Base type for this register.
type Base: ?Sized;
@@ -132,9 +132,6 @@ pub trait Register: Sized {
const OFFSET: usize;
}
-/// Trait implemented by registers with a fixed offset.
-pub trait FixedRegister: Register {}
-
/// Allows `()` to be used as the `location` parameter of [`Io::write`](super::Io::write) when
/// passing a [`FixedRegister`] value.
impl<Base: ?Sized, T> IoLoc<Base, T> for ()
@@ -201,7 +198,14 @@ fn offset(self) -> usize {
}
/// Trait implemented by arrays of registers.
-pub trait RegisterArray: Register {
+pub trait RegisterArray: Sized {
+ /// Base type for this register.
+ type Base: ?Sized;
+
+ /// Start offset of the register.
+ ///
+ /// The interpretation of this offset depends on the type of the register.
+ const OFFSET: usize;
/// Number of elements in the registers array.
const SIZE: usize;
/// Number of bytes between the start of elements in the registers array.
@@ -267,8 +271,8 @@ fn try_at(idx: usize) -> Option<RegisterArrayLoc<Self>>
///
/// Implementors can be used with [`Io::write_reg`](super::Io::write_reg).
pub trait LocatedRegister<Base: ?Sized> {
- /// Register value to write.
- type Value: Register;
+ /// Value to write.
+ type Value;
/// Full location information at which to write the value.
type Location: IoLoc<Base, Self::Value>;
@@ -295,7 +299,7 @@ fn into_io_op(self) -> (FixedRegisterLoc<T>, T) {
/// This is used to enforce base matching.
#[doc(hidden)]
#[inline(always)] // for const eval only
-pub const fn alias_offset<Base: ?Sized, Alias: Register<Base = Base>>() -> usize {
+pub const fn alias_offset<Base: ?Sized, Alias: FixedRegister<Base = Base>>() -> usize {
Alias::OFFSET
}
@@ -225,11 +225,6 @@ pub(crate) fn register(def: RegDef) -> Result<TokenStream> {
#[allow(non_camel_case_types)]
#(#attrs)* #vis struct #name(#storage) #args
);
-
- impl ::kernel::io::register::Register for #name {
- type Base = #base;
- const OFFSET: usize = #offset;
- }
));
}
@@ -245,7 +240,10 @@ impl ::kernel::io::register::Register for #name {
))?,
None => outputs.extend(quote_spanned!(span =>
- impl ::kernel::io::register::FixedRegister for #name {}
+ impl ::kernel::io::register::FixedRegister for #name {
+ type Base = #base;
+ const OFFSET: usize = #offset;
+ }
#(#attrs)* #vis const #name: ::kernel::io::register::FixedRegisterLoc<#name> =
::kernel::io::register::FixedRegisterLoc::<#name>::new();
@@ -268,6 +266,8 @@ impl ::kernel::io::register::FixedRegister for #name {}
impl ::kernel::io::register::Array for #name {}
impl ::kernel::io::register::RegisterArray for #name {
+ type Base = #base;
+ const OFFSET: usize = #offset;
const SIZE: usize = #size;
const STRIDE: usize = #stride;
}
With the removal of relative registers, there are only two type of registers left, fixed register and register arrays. There is not much benefit in having a common super trait for them anymore, thus remove it, and cleanup the macro rules associated with it. Signed-off-by: Gary Guo <gary@garyguo.net> --- rust/kernel/io/register.rs | 22 +++++++++++++--------- rust/macros/io/register.rs | 12 ++++++------ 2 files changed, 19 insertions(+), 15 deletions(-)