8000 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
improve macros
  • Loading branch information
paulsohn committed Dec 6, 2023
commit da807014eb74e48df71c0397340844f65cae8d4a
73 changes: 39 additions & 34 deletions src/extended_capabilities/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ where
pub struct Id(u32);
impl Id {
ro_field!(
pub,
16..=20,
pub, self,
self.0; 16..=20,
debug_capability_event_ring_segment_table_max,
"Debug Capability Event Ring Segment Table Max",
u8
Expand All @@ -104,15 +104,20 @@ impl_debug_from_methods! {
#[derive(Copy, Clone, Debug)]
pub struct Doorbell(u32);
impl Doorbell {
field_setter!(pub, 8..=15, "Doorbell Target", u8);
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 {
rw_field!(pub, 0..=15, "Event Ring Segment Table Size", u16);
rw_field!(pub, self, self.0; 0..=15, "Event Ring Segment Table Size", u16);
}
impl_debug_from_methods! {
EventRingSegmentTableSize {
Expand All @@ -125,9 +130,9 @@ impl_debug_from_methods! {
#[derive(Copy, Clone)]
pub struct EventRingSegmentTableBaseAddress(u64);
impl EventRingSegmentTableBaseAddress {
rw_field!(
pub,
[]{4, "64-byte aligned"},
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
);
Expand All @@ -144,15 +149,15 @@ impl_debug_from_methods! {
pub struct EventRingDequeuePointer(u64);
impl EventRingDequeuePointer {
rw_field!(
pub,
0..=2,
pub, self,
self.0; 0..=2,
dequeue_erst_segment_index,
"Dequeue ERST Segment Index",
u8
);
rw_field!(
pub,
[]{4, "16-byte aligned"},
rw_zero_trailing!(
pub, self,
self.0; 4~; "16-byte aligned",
dequeue_pointer,
"Event Ring Dequeue Pointer",
u64
Expand All @@ -170,11 +175,11 @@ impl_debug_from_methods! {
#[derive(Copy, Clone)]
pub struct Control(u32);
impl Control {
ro_bit!(pub, 0, dbc_run, "DbC Run");
rw_bit!(pub, 1, link_status_event_enable, "Link Status Event Enable");
rw1s_bit!(pub, 2, halt_out_tr, "Halt OUT TR");
rw1s_bit!(pub, 3, halt_in_tr, "Halt IN TR");
rw1c_bit!(pub, 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 @@ -188,7 +193,7 @@ impl Control {
self.0.get_bits(24..=30).try_into().unwrap()
}

rw_bit!(pub, 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 @@ -208,8 +213,8 @@ impl_debug_from_methods! {
#[derive(Copy, Clone)]
pub struct Status(u32);
impl Status {
ro_bit!(pub, 0, event_ring_not_empty, "Event Ring Not Empty");
ro_bit!(pub, 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 @@ -230,9 +235,9 @@ impl_debug_from_methods! {
#[derive(Copy, Clone)]
pub struct PortStatusAndControl(u32);
impl PortStatusAndControl {
ro_bit!(pub, 0, current_connect_status, "Current Connect Status");
rw_bit!(pub, 1, port_enabled_disabled, "Port Enabled/Disabled");
ro_bit!(pub, 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 @@ -246,10 +251,10 @@ impl PortStatusAndControl {
self.0.get_bits(10..=13).try_into().unwrap()
}

rw1c_bit!(pub, 17, connect_status_change, "Connect Status Change");
rw1c_bit!(pub, 21, port_reset_change, "Port Reset Change");
rw1c_bit!(pub, 22, port_link_status_change, "Port Link Status Change");
rw1c_bit!(pub, 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 @@ -270,9 +275,9 @@ impl_debug_from_methods! {
#[derive(Copy, Clone, Debug)]
pub struct ContextPointer(u64);
impl ContextPointer {
rw_field!(
pub,
[]{4, "16-byte aligned"},
rw_zero_trailing!(
pub, self,
self.0; 4~; "16-byte aligned",
"Debug Capability Context Base Pointer",
u64
);
Expand All @@ -283,8 +288,8 @@ impl ContextPointer {
#[derive(Copy, Clone)]
pub struct DeviceDescriptorInfo1(u32);
impl DeviceDescriptorInfo1 {
rw_field!(pub, 0..=7, dbc_protocol, "DbC Protocol", u8);
rw_field!(pub, 16..=31, vendor_id, "Vendor ID", u16);
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 @@ -298,8 +303,8 @@ impl_debug_from_methods! {
#[derive(Copy, Clone)]
pub struct DeviceDescriptorInfo2(u32);
impl DeviceDescriptorInfo2 {
rw_field!(pub, 0..=15, product_id, "Product ID", u16);
rw_field!(pub, 16..=31, device_revision, "Device Revision", u16);
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!(pub, 11..=15, pme_support, "PME_Support", u8);
ro_bit!(pub, 10, d2_support, "D2_Support");
ro_bit!(pub, 9, d1_support, "D1_Support");
ro_field!(pub, 6..=8, aux_current, "Aux_Current", u8);
ro_bit!(pub, 5, dsi, "DSI");
ro_bit!(pub, 3, pme_clock, "PME Clock");
ro_field!(pub, 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!(pub, 15, pme_status, "PME_Status");
ro_field!(pub, 13..=14, data_scale, "Data_Scale", u8);
rw_field!(pub, 9..=12, data_select, "Data_Select", u8);
rw_bit!(pub, 8, pme_en, "PME_En");
rw_field!(pub, 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!(pub, 7, bpcc_en, "BPCC_En");
ro_bit!(pub, 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
27 changes: 14 additions & 13 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!(pub, 16, hc_bios_owned_semaphore, "HC BIOS Owned Semaphore");
rw_bit!(pub, 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!(pub, 0, usb_smi_enable, "USB SMI Enable");
rw_bit!(pub,
4,
rw_bit!(pub, self, self.0; 0, usb_smi_enable, "USB SMI Enable");
rw_bit!(
pub, self,
self.0; 4,
smi_on_host_system_error_enable,
"SMI on Host System Error Enable"
);
rw_bit!(pub, 13, smi_on_os_ownership_enable, "SMI on OS Ownership Enable");
rw_bit!(pub, 14, smi_on_pci_command_enable, "SMI on PCI Command Enable");
rw_bit!(pub, 15, smi_on_bar_enable, "SMI on BAR Enable");
ro_bit!(pub, 16, smi_on_event_interrupt, "SMI on Event Interrupt");
ro_bit!(pub, 20, smi_on_host_system_error, "SMI on Host System Error");
rw1c_bit!(pub, 29, smi_on_os_ownership_change, "SMI on OS Ownership Change");
rw1c_bit!(pub, 30, smi_on_pci_command, "SMI on PCI Command");
rw1c_bit!(pub, 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!(pub, 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
4 changes: 2 additions & 2 deletions src/extended_capabilities/xhci_local_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ where
pub struct Header([u32; 2]);
impl Header {
rw_bit!(
pub,
[0](16),
pub, self,
self.0[0]; 16,
local_memory_enable,
"Local Memory Enable"
);
Expand Down
16 changes: 8 additions & 8 deletions src/extended_capabilities/xhci_message_interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use super::ExtendedCapability;
use accessor::single;
use accessor::Mapper;
use bit_field::BitField;
// use bit_field::BitField;
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
// use bit_field::BitField;

use core::convert::TryFrom;
use core::convert::TryInto;

Expand Down Expand Up @@ -113,23 +113,23 @@ impl MessageAddress for u64 {}
#[derive(Copy, Clone)]
pub struct MessageControl(u16);
impl MessageControl {
rw_bit!(pub, 0, msi_enable, "MSI Enable");
rw_bit!(pub, self, self.0; 0, msi_enable, "MSI Enable");
ro_field!(
pub,
1..=3,
pub, self,
self.0; 1..=3,
multiple_message_capable,
"Multiple Message Capable",
u8
);
rw_field!(
pub,
4..=6,
pub, self,
self.0; 4..=6,
multiple_message_enable,
"Multiple Message Enable",
u8
);
ro_bit!(pub, 7, bit64_address_capable, "64 bit address capable");
ro_bit!(pub, 8, per_vector_masking_capable, "Per-vector masking capable");
ro_bit!(pub, self, self.0; 7, bit64_address_capable, "64 bit address capable");
ro_bit!(pub, self, self.0; 8, per_vector_masking_capable, "Per-vector masking capable");
}
impl_debug_from_methods! {
MessageControl {
Expand Down
Loading
0