Skip to content
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

Transparent 'Raw TRB type' #169

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
200 changes: 59 additions & 141 deletions src/extended_capabilities/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ where
#[derive(Copy, Clone)]
pub struct Id(u32);
impl Id {
/// Returns the value of the Debug Capability Event Ring Segment Table Max field.
#[must_use]
pub fn debug_capability_event_ring_segment_table_max(self) -> u8 {
self.0.get_bits(16..=20).try_into().unwrap()
}
ro_field!(
pub, self,
self.0; 16..=20,
debug_capability_event_ring_segment_table_max,
"Debug Capability Event Ring Segment Table Max",
u8
);
}
impl_debug_from_methods! {
Id {
Expand All @@ -102,27 +104,20 @@ impl_debug_from_methods! {
#[derive(Copy, Clone, Debug)]
pub struct Doorbell(u32);
impl Doorbell {
/// Sets the value of the Doorbell Target field.
pub fn set_doorbell_target(&mut self, target: u8) {
self.0.set_bits(8..=15, target.into());
}
rw_field!(
pub, self,
self.0; 8..=15,
"Doorbell Target",
u8
);
}

/// Debug Capability Event Ring Segment Table Size Register.
#[repr(transparent)]
#[derive(Copy, Clone)]
pub struct EventRingSegmentTableSize(u32);
impl EventRingSegmentTableSize {
/// Returns the value of the Event Ring Segment Table Size field.
#[must_use]
pub fn get(self) -> u16 {
self.0.get_bits(0..=15).try_into().unwrap()
}

/// Sets the value of the Event Ring Segment Table Size field.
pub fn set(&mut self, sz: u16) {
self.0.set_bits(0..=15, sz.into());
}
rw_field!(pub, self, self.0; 0..=15, "Event Ring Segment Table Size", u16);
}
impl_debug_from_methods! {
EventRingSegmentTableSize {
Expand All @@ -135,25 +130,12 @@ impl_debug_from_methods! {
#[derive(Copy, Clone)]
pub struct EventRingSegmentTableBaseAddress(u64);
impl EventRingSegmentTableBaseAddress {
/// Returns the value of the Event Ring Segment Table Base Address field.
#[must_use]
pub fn get(self) -> u64 {
self.0
}

/// Sets the value of the Event Ring Segment Table Base Address field.
///
/// # Panics
///
/// This method panics if the address is not 16-byte aligned.
pub fn set(&mut self, a: u64) {
assert!(
a.trailing_zeros() >= 4,
"The base address of the Event Ring Segment Table must be 16-byte aligned."
);

self.0 = a;
}
rw_zero_trailing!(
pub, self,
self.0; 4~; "64-byte aligned",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
self.0; 4~; "64-byte aligned",
self.0; 4~; "16-byte aligned",

"Event Ring Segment Table Base Address",
u64
);
}
impl_debug_from_methods! {
EventRingSegmentTableBaseAddress {
Expand All @@ -166,36 +148,20 @@ impl_debug_from_methods! {
#[derive(Copy, Clone)]
pub struct EventRingDequeuePointer(u64);
impl EventRingDequeuePointer {
/// Returns the value of the Dequeue ERST Segment Index field.
#[must_use]
pub fn dequeue_erst_segment_index(self) -> u8 {
self.0.get_bits(0..=2).try_into().unwrap()
}

/// Sets the value of the Dequeue ERST Segment Index field.
pub fn set_dequeue_erst_segment_index(&mut self, i: u8) {
self.0.set_bits(0..=2, i.into());
}

/// Returns the value of the Dequeue Pointer field.
#[must_use]
pub fn dequeue_pointer(self) -> u64 {
self.0 & !0b1111
}

/// Sets the value of the Dequeue Pointer field.
///
/// # Panics
///
/// This method panics if the address is not 16-byte aligned.
pub fn set_dequeue_pointer(&mut self, a: u64) {
assert!(
a.trailing_zeros() >= 4,
"The Event Ring Dequeue Pointer must be 16-byte aligned."
);

self.0.set_bits(4..=63, a.get_bits(4..=63));
}
rw_field!(
pub, self,
self.0; 0..=2,
dequeue_erst_segment_index,
"Dequeue ERST Segment Index",
u8
);
rw_zero_trailing!(
pub, self,
self.0; 4~; "16-byte aligned",
dequeue_pointer,
"Event Ring Dequeue Pointer",
u64
);
}
impl_debug_from_methods! {
EventRingDequeuePointer {
Expand All @@ -209,11 +175,11 @@ impl_debug_from_methods! {
#[derive(Copy, Clone)]
pub struct Control(u32);
impl Control {
ro_bit!(0, dbc_run, "DbC Run");
rw_bit!(1, link_status_event_enable, "Link Status Event Enable");
rw1s_bit!(2, halt_out_tr, "Halt OUT TR");
rw1s_bit!(3, halt_in_tr, "Halt IN TR");
rw1c_bit!(4, dbc_run_change, "DbC Run Change");
ro_bit!(pub, self, self.0; 0, dbc_run, "DbC Run");
rw_bit!(pub, self, self.0; 1, link_status_event_enable, "Link Status Event Enable");
rw1s_bit!(pub, self, self.0; 2, halt_out_tr, "Halt OUT TR");
rw1s_bit!(pub, self, self.0; 3, halt_in_tr, "Halt IN TR");
rw1c_bit!(pub, self, self.0; 4, dbc_run_change, "DbC Run Change");

/// Returns the value of the Debug Max Burst Size field.
#[must_use]
Expand All @@ -227,7 +193,7 @@ impl Control {
self.0.get_bits(24..=30).try_into().unwrap()
}

rw_bit!(31, debug_capability_enable, "Debug Capability Enable");
rw_bit!(pub, self, self.0; 31, debug_capability_enable, "Debug Capability Enable");
}
impl_debug_from_methods! {
Control {
Expand All @@ -247,8 +213,8 @@ impl_debug_from_methods! {
#[derive(Copy, Clone)]
pub struct Status(u32);
impl Status {
ro_bit!(0, event_ring_not_empty, "Event Ring Not Empty");
ro_bit!(1, dbc_system_bus_reset, "DbC System Bus Reset");
ro_bit!(pub, self, self.0; 0, event_ring_not_empty, "Event Ring Not Empty");
ro_bit!(pub, self, self.0; 1, dbc_system_bus_reset, "DbC System Bus Reset");

/// Returns the value of the Debug Port Number field.
#[must_use]
Expand All @@ -269,9 +235,9 @@ impl_debug_from_methods! {
#[derive(Copy, Clone)]
pub struct PortStatusAndControl(u32);
impl PortStatusAndControl {
ro_bit!(0, current_connect_status, "Current Connect Status");
rw_bit!(1, port_enabled_disabled, "Port Enabled/Disabled");
ro_bit!(4, port_reset, "Port Reset");
ro_bit!(pub, self, self.0; 0, current_connect_status, "Current Connect Status");
rw_bit!(pub, self, self.0; 1, port_enabled_disabled, "Port Enabled/Disabled");
ro_bit!(pub, self, self.0; 4, port_reset, "Port Reset");

/// Returns the value of the Port Link State field.
#[must_use]
Expand All @@ -285,10 +251,10 @@ impl PortStatusAndControl {
self.0.get_bits(10..=13).try_into().unwrap()
}

rw1c_bit!(17, connect_status_change, "Connect Status Change");
rw1c_bit!(21, port_reset_change, "Port Reset Change");
rw1c_bit!(22, port_link_status_change, "Port Link Status Change");
rw1c_bit!(23, port_config_error_change, "Port Config Error Change");
rw1c_bit!(pub, self, self.0; 17, connect_status_change, "Connect Status Change");
rw1c_bit!(pub, self, self.0; 21, port_reset_change, "Port Reset Change");
rw1c_bit!(pub, self, self.0; 22, port_link_status_change, "Port Link Status Change");
rw1c_bit!(pub, self, self.0; 23, port_config_error_change, "Port Config Error Change");
}
impl_debug_from_methods! {
PortStatusAndControl {
Expand All @@ -309,50 +275,21 @@ impl_debug_from_methods! {
#[derive(Copy, Clone, Debug)]
pub struct ContextPointer(u64);
impl ContextPointer {
/// Returns the start address of the Debug Capability Context data structure.
#[must_use]
pub fn get(self) -> u64 {
self.0
}

/// Sets the start address of the Debug Capability Context data structure.
///
/// # Panics
///
/// This method panics if the address is not 16-byte aligned.
pub fn set(&mut self, a: u64) {
assert!(a.trailing_zeros()>=4,"The start address of the Debug Capability Context data structure must be 16-byte aligned.");

self.0 = a;
}
rw_zero_trailing!(
pub, self,
self.0; 4~; "16-byte aligned",
"Debug Capability Context Base Pointer",
u64
);
}

/// Debug Capability Device Descriptor Info Register 1
#[repr(transparent)]
#[derive(Copy, Clone)]
pub struct DeviceDescriptorInfo1(u32);
impl DeviceDescriptorInfo1 {
/// Returns the value of the DbC Protocol field.
#[must_use]
pub fn dbc_protocol(self) -> u8 {
self.0.get_bits(0..=7).try_into().unwrap()
}

/// Sets the value of the DbC Protocol field.
pub fn set_dbc_protocol(&mut self, protocol: u8) {
self.0.set_bits(0..=7, protocol.into());
}

/// Returns the value of the Vendor ID field.
#[must_use]
pub fn vendor_id(self) -> u16 {
self.0.get_bits(16..=31).try_into().unwrap()
}

/// Sets the value of the Vendor ID field.
pub fn set_vendor_id(&mut self, id: u16) {
self.0.set_bits(16..=31, id.into());
}
rw_field!(pub, self, self.0; 0..=7, dbc_protocol, "DbC Protocol", u8);
rw_field!(pub, self, self.0; 16..=31, vendor_id, "Vendor ID", u16);
}
impl_debug_from_methods! {
DeviceDescriptorInfo1 {
Expand All @@ -366,27 +303,8 @@ impl_debug_from_methods! {
#[derive(Copy, Clone)]
pub struct DeviceDescriptorInfo2(u32);
impl DeviceDescriptorInfo2 {
/// Returns the value of the Product ID field.
#[must_use]
pub fn product_id(self) -> u16 {
self.0.get_bits(0..=15).try_into().unwrap()
}

/// Sets the value of the Product ID field.
pub fn set_product_id(&mut self, id: u16) {
self.0.set_bits(0..=15, id.into());
}

/// Returns the value of the Device Revision field.
#[must_use]
pub fn device_revision(self) -> u16 {
self.0.get_bits(16..=31).try_into().unwrap()
}

/// Sets the value of the Device Revision field.
pub fn set_device_revision(&mut self, revision: u16) {
self.0.set_bits(16..=31, revision.into());
}
rw_field!(pub, self, self.0; 0..=15, product_id, "Product ID", u16);
rw_field!(pub, self, self.0; 16..=31, device_revision, "Device Revision", u16);
}
impl_debug_from_methods! {
DeviceDescriptorInfo2 {
Expand Down
28 changes: 14 additions & 14 deletions src/extended_capabilities/hci_extended_power_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ where
#[derive(Copy, Clone)]
pub struct PowerManagementCapabilities(u16);
impl PowerManagementCapabilities {
ro_field!(11..=15, pme_support, "PME_Support", u8);
ro_bit!(10, d2_support, "D2_Support");
ro_bit!(9, d1_support, "D1_Support");
ro_field!(6..=8, aux_current, "Aux_Current", u8);
ro_bit!(5, dsi, "DSI");
ro_bit!(3, pme_clock, "PME Clock");
ro_field!(0..=2, version, "Version", u8);
ro_field!(pub, self, self.0; 11..=15, pme_support, "PME_Support", u8);
ro_bit!(pub, self, self.0; 10, d2_support, "D2_Support");
ro_bit!(pub, self, self.0; 9, d1_support, "D1_Support");
ro_field!(pub, self, self.0; 6..=8, aux_current, "Aux_Current", u8);
ro_bit!(pub, self, self.0; 5, dsi, "DSI");
ro_bit!(pub, self, self.0; 3, pme_clock, "PME Clock");
ro_field!(pub, self, self.0; 0..=2, version, "Version", u8);
}
impl_debug_from_methods! {
PowerManagementCapabilities {
Expand All @@ -57,11 +57,11 @@ impl_debug_from_methods! {
#[derive(Copy, Clone)]
pub struct PowerManagementControlStatusRegister(u16);
impl PowerManagementControlStatusRegister {
rw1c_bit!(15, pme_status, "PME_Status");
ro_field!(13..=14, data_scale, "Data_Scale", u8);
rw_field!(9..=12, data_select, "Data_Select", u8);
rw_bit!(8, pme_en, "PME_En");
rw_field!(0..=1, power_state, "PowerState", u8);
rw1c_bit!(pub, self, self.0; 15, pme_status, "PME_Status");
ro_field!(pub, self, self.0; 13..=14, data_scale, "Data_Scale", u8);
rw_field!(pub, self, self.0; 9..=12, data_select, "Data_Select", u8);
rw_bit!(pub, self, self.0; 8, pme_en, "PME_En");
rw_field!(pub, self, self.0; 0..=1, power_state, "PowerState", u8);
}
impl_debug_from_methods! {
PowerManagementControlStatusRegister {
Expand All @@ -78,8 +78,8 @@ impl_debug_from_methods! {
#[derive(Copy, Clone)]
pub struct PmesrBse(u8);
impl PmesrBse {
ro_bit!(7, bpcc_en, "BPCC_En");
ro_bit!(6, b2_b3, "B2_B3");
ro_bit!(pub, self, self.0; 7, bpcc_en, "BPCC_En");
ro_bit!(pub, self, self.0; 6, b2_b3, "B2_B3");
}
impl_debug_from_methods! {
PmesrBse {
Expand Down
25 changes: 13 additions & 12 deletions src/extended_capabilities/usb_legacy_support_capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ where
#[derive(Copy, Clone)]
pub struct LegSup(u32);
impl LegSup {
rw_bit!(16, hc_bios_owned_semaphore, "HC BIOS Owned Semaphore");
rw_bit!(24, hc_os_owned_semaphore, "HC OS Owned Semaphore");
rw_bit!(pub, self, self.0; 16, hc_bios_owned_semaphore, "HC BIOS Owned Semaphore");
rw_bit!(pub, self, self.0; 24, hc_os_owned_semaphore, "HC OS Owned Semaphore");
}
impl_debug_from_methods! {
LegSup {
Expand All @@ -68,20 +68,21 @@ impl_debug_from_methods! {
#[derive(Copy, Clone)]
pub struct UsbLegacySupportControlStatus(u32);
impl UsbLegacySupportControlStatus {
rw_bit!(0, usb_smi_enable, "USB SMI Enable");
rw_bit!(pub, self, self.0; 0, usb_smi_enable, "USB SMI Enable");
rw_bit!(
4,
pub, self,
self.0; 4,
smi_on_host_system_error_enable,
"SMI on Host System Error Enable"
);
rw_bit!(13, smi_on_os_ownership_enable, "SMI on OS Ownership Enable");
rw_bit!(14, smi_on_pci_command_enable, "SMI on PCI Command Enable");
rw_bit!(15, smi_on_bar_enable, "SMI on BAR Enable");
ro_bit!(16, smi_on_event_interrupt, "SMI on Event Interrupt");
ro_bit!(20, smi_on_host_system_error, "SMI on Host System Error");
rw1c_bit!(29, smi_on_os_ownership_change, "SMI on OS Ownership Change");
rw1c_bit!(30, smi_on_pci_command, "SMI on PCI Command");
rw1c_bit!(31, smi_on_bar, "SMI on BAR");
rw_bit!(pub, self, self.0; 13, smi_on_os_ownership_enable, "SMI on OS Ownership Enable");
rw_bit!(pub, self, self.0; 14, smi_on_pci_command_enable, "SMI on PCI Command Enable");
rw_bit!(pub, self, self.0; 15, smi_on_bar_enable, "SMI on BAR Enable");
ro_bit!(pub, self, self.0; 16, smi_on_event_interrupt, "SMI on Event Interrupt");
ro_bit!(pub, self, self.0; 20, smi_on_host_system_error, "SMI on Host System Error");
rw1c_bit!(pub, self, self.0; 29, smi_on_os_ownership_change, "SMI on OS Ownership Change");
rw1c_bit!(pub, self, self.0; 30, smi_on_pci_command, "SMI on PCI Command");
rw1c_bit!(pub, self, self.0; 31, smi_on_bar, "SMI on BAR");
}
impl_debug_from_methods! {
UsbLegacySupportControlStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ where
#[derive(Copy, Clone)]
pub struct MessageControl(u16);
impl MessageControl {
rw_bit!(15, msi_x_enable, "MSI-X Enable");
rw_bit!(pub, self, self.0; 15, msi_x_enable, "MSI-X Enable");

/// Returns the value of the Table Size field.
#[must_use]
Expand Down
Loading
Loading