10000 Transparent 'Raw TRB type' by paulsohn · Pull Request #169 · rust-osdev/xhci · GitHub
[go: up one dir, main page]

Skip to content

Transparent 'Raw TRB type' #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cargo fmt
  • Loading branch information
paulsohn committed Dec 6, 2023
commit dfbeec505bcb491628b60447bb8b563d67a97d6b
6 changes: 3 additions & 3 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ macro_rules! double_field_getter {
$vis fn $method(&$self_) -> $ty {
let lo = $arr[$off_lo] as $ty;
let hi = $arr[$off_hi] as $ty;

(hi << $bits) | lo
}
};
Expand All @@ -244,7 +244,7 @@ macro_rules! double_zero_trailing_getter {
$vis fn $method(&$self_) -> $ty {
let lo = ($arr[$off_lo] as $ty) >> $start << $start;
let hi = $arr[$off_hi] as $ty;

(hi << $bits) | lo
}
};
Expand Down Expand Up @@ -326,4 +326,4 @@ macro_rules! rw_double_zero_trailing {
double_zero_trailing_setter!($vis, $self_, $arr; [$off_lo, $off_hi]; $start~; $expect, [<set_ $method>], $name, $bits, $ty);
}
};
}
}
4 changes: 2 additions & 2 deletions src/registers/operational.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ impl PortStatusAndControlRegister {
rw_bit!(pub, self, self.0; 9, port_power, "Port Power");
ro_field!(pub, self, self.0; 10..=13, port_speed, "Port Speed", u8);
rw_field!(
pub, self,
pub, self,
self.0; 14..=15,
port_indicator_control,
"Port Indicator Control",
Expand Down Expand Up @@ -483,7 +483,7 @@ impl_debug_from_methods! {
pub struct PortHardwareLpmControlRegister(u32);
impl PortHardwareLpmControlRegister {
rw_field!(
pub, self,
pub, self,
self.0; 0..=1,
host_initiated_resume_duration_mode,
"Host Initiated Resume Duration Mode",
Expand Down
2 changes: 1 addition & 1 deletion src/ring/mod.rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A trailing newline is preferred.

Original file 10000 line number Diff line number Diff line change
@@ -1,3 +1,3 @@
//! TRB Ring.

pub mod trb;
pub mod trb;
28 changes: 10 additions & 18 deletions src/ring/trb/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use num_traits::FromPrimitive;
macro_rules! impl_input_context_pointer {
() => {
param_align_16!(input_context_pointer, "Input Context Pointer");
}
};
}

macro_rules! impl_subtype {
Expand Down Expand Up @@ -93,9 +93,7 @@ impl_debug_from_methods!(NoOp {});
impl EnableSlot {
rw_field!(pub, self, self.0.0[3]; 16..=20, slot_type, "Slot Type", u8);
}
impl_debug_from_methods!(EnableSlot {
slot_type,
});
impl_debug_from_methods!(EnableSlot { slot_type });
rsvdz_checking_try_from!(EnableSlot {
[0];0..=31,
[1];0..=31,
Expand All @@ -107,9 +105,7 @@ rsvdz_checking_try_from!(EnableSlot {
impl DisableSlot {
impl_slot_id!();
}
impl_debug_from_methods!(DisableSlot {
slot_id,
});
impl_debug_from_methods!(DisableSlot { slot_id });
rsvdz_checking_try_from!(DisableSlot {
[0];0..=31,
[1];0..=31,
Expand Down Expand Up @@ -233,9 +229,7 @@ rsvdz_checking_try_from!(SetTrDequeuePointer {
impl ResetDevice {
impl_slot_id!();
}
impl_debug_from_methods!(ResetDevice {
slot_id,
});
impl_debug_from_methods!(ResetDevice { slot_id });
rsvdz_checking_try_from!(ResetDevice {
[0];0..=31,
[1];0..=31,
Expand Down Expand Up @@ -272,9 +266,7 @@ rsvdz_checking_try_from!(ForceEvent {
impl NegotiateBandwidth {
impl_slot_id!();
}
impl_debug_from_methods!(NegotiateBandwidth {
slot_id,
});
impl_debug_from_methods!(NegotiateBandwidth { slot_id });
rsvdz_checking_try_from!(NegotiateBandwidth {
[0];0..=31,
[1];0..=31,
Expand Down Expand Up @@ -338,16 +330,16 @@ impl ForceHeader {
"The lowest 5 bits of the Header Info Lo 6D4E w must be 0."
);

self.0.0[0].set_bits(5.., info[0].get_bits(5..));
self.0.0[1] = info[1];
self.0.0[2] = info[2];
self.0 .0[0].set_bits(5.., info[0].get_bits(5..));
self.0 .0[1] = info[1];
self.0 .0[2] = info[2];
self
}

/// Returns the value of the Header Info field.
#[must_use]
pub fn header_info(&self) -> [u32; 3] {
[self.0.0[0] >> 5 << 5, self.0.0[1], self.0.0[2]]
[self.0 .0[0] >> 5 << 5, self.0 .0[1], self.0 .0[2]]
}

rw_field!(
Expand Down Expand Up @@ -430,4 +422,4 @@ rsvdz_checking_try_from!(SetExtendedProperty {
[0];0..=3,
[2];16..=31,
[3];1..=9,
});
});
17 changes: 6 additions & 11 deletions src/ring/trb/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ macro_rules! impl_cc {
/// This method may return an [`Err`] variant with the Completion Code that is either reserved or
/// not implemented in this crate.
pub fn completion_code(&self) -> Result<CompletionCode, u8> {
let c: u8 = self.0.0[2].get_bits(24..=31).try_into().unwrap();
let c: u8 = self.0 .0[2].get_bits(24..=31).try_into().unwrap();
CompletionCode::from_u8(c).ok_or(c)
}
}
};
}

allowed_trb!("Transfer TRB", {
Expand Down Expand Up @@ -74,7 +74,7 @@ impl CommandCompletion {

ro_field!(
pub, self,
self.0.0[2]; 0..=23,
self.0.0[2]; 0..=23,
command_completion_parameter,
"Command Completion Parameter",
u32
Expand Down Expand Up @@ -154,9 +154,7 @@ rsvdz_checking_try_from!(Doorbell {
impl HostController {
impl_cc!(ro);
}
impl_debug_from_methods!(HostController {
completion_code,
});
impl_debug_from_methods!(HostController { completion_code });
rsvdz_checking_try_from!(HostController {
[0];0..=31,
[1];0..=31,
Expand Down Expand Up @@ -206,9 +204,7 @@ rsvdz_checking_try_from!(DeviceNotification {
impl MfindexWrap {
impl_cc!(ro);
}
impl_debug_from_methods!(MfindexWrap {
completion_code,
});
impl_debug_from_methods!(MfindexWrap { completion_code });
rsvdz_checking_try_from!(MfindexWrap {
[0];0..=31,
[1];0..=31,
Expand All @@ -217,7 +213,6 @@ rsvdz_checking_try_from!(MfindexWrap {
[3];16..=31,
});


/// The TRB Completion Codes.
///
/// The description of each error is quoted from eXtensible Host Controller Interface for Universal
Expand Down Expand Up @@ -313,4 +308,4 @@ pub enum CompletionCode {
SecondaryBandwidthError = 35,
/// Asserted if an error is detected on a USB2 protocol endpoint for a split transaction.
SplitTransactionError = 36,
}
}
11 changes: 5 additions & 6 deletions src/ring/trb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ macro_rules! param_align_16 {
macro_rules! impl_ring_segment_pointer {
() => {
param_align_16!(ring_segment_pointer, "Ring Segment Pointer");
}
};
}

macro_rules! impl_tc {
Expand Down Expand Up @@ -79,7 +79,7 @@ macro_rules! allowed_trb {
),+
}
);

// defining common block
paste::paste!(
#[doc = "A raw " $name " Block."]
Expand All @@ -104,12 +104,11 @@ macro_rules! allowed_trb {
rw_bit!(pub, self, self.0[3]; 0, cycle_bit, "Cycle");
}
);

// defining individual TRB types
// all TRB types require `Self::new()`. Derive by simple default or manually implement it.
$(
paste::paste! {
#[doc = "A "]
$(#[$docs])*
#[doc = "."]
#[repr(transparent)]
Expand Down Expand Up @@ -168,6 +167,6 @@ macro_rules! rsvdz_checking_try_from {
}
}

pub mod transfer;
pub mod command;
pub mod event;
pub mod command;
pub mod transfer;
10 changes: 5 additions & 5 deletions src/ring/trb/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ allowed_trb!("Transfer TRB", {

impl Normal {
impl_data_buffer_pointer!();

impl_trb_transfer_length!();
impl_td_size!();
impl_interrupter_target!();
Expand Down Expand Up @@ -162,7 +162,7 @@ impl SetupStage {

/// Sets the value of the Transfer Type field.
pub fn set_transfer_type(&mut self, t: TransferType) -> &mut Self {
self.0.0[3].set_bits(16..=17, t as _);
self.0 .0[3].set_bits(16..=17, t as _);
self
}

Expand All @@ -173,7 +173,7 @@ impl SetupStage {
/// This method panics if the Transfer Type field contains 1 which is reserved.
#[must_use]
pub fn transfer_type(&self) -> TransferType {
FromPrimitive::from_u32(self.0.0[3].get_bits(16..=17))
FromPrimitive::from_u32(self.0 .0[3].get_bits(16..=17))
.expect("Transfer Type 1 is reserved.")
}
}
Expand Down Expand Up @@ -301,7 +301,7 @@ impl Link {
impl_ring_segment_pointer!();

impl_interrupter_target!();

impl_tc!();
impl_ch!();
impl_ioc!();
Expand Down Expand Up @@ -381,4 +381,4 @@ pub enum TransferType {
Out = 2,
/// In Data Stage.
In = 3,
}
}
0