xhci/extended_capabilities/
xhci_extended_message_interrupt.rs

1//! xHCI Extended Message Interrupt Capability.
2
3use super::ExtendedCapability;
4use accessor::single;
5use accessor::Mapper;
6use bit_field::BitField;
7use core::convert::TryInto;
8
9/// xHCI Extended Message Interrupt Capability.
10#[repr(C)]
11#[derive(Copy, Clone, Debug)]
12pub struct XhciExtendedMessageInterrupt {
13    _id: u8,
14    _next: u8,
15    /// Message Control.
16    pub control: MessageControl,
17    /// Message Upper Address.
18    pub upper_address: u32,
19    /// Table Offset and BIR.
20    pub table_offset: TableOffset,
21}
22impl<M> From<single::ReadWrite<XhciExtendedMessageInterrupt, M>> for ExtendedCapability<M>
23where
24    M: Mapper + Clone,
25{
26    fn from(x: single::ReadWrite<XhciExtendedMessageInterrupt, M>) -> Self {
27        ExtendedCapability::XhciExtendedMessageInterrupt(x)
28    }
29}
30
31/// Message Control.
32#[repr(transparent)]
33#[derive(Copy, Clone)]
34pub struct MessageControl(u16);
35impl MessageControl {
36    rw_bit!(15, msi_x_enable, "MSI-X Enable");
37
38    /// Returns the value of the Table Size field.
39    #[must_use]
40    pub fn table_size(self) -> u16 {
41        self.0.get_bits(0..=10)
42    }
43}
44impl_debug_from_methods! {
45    MessageControl {
46        msi_x_enable,
47        table_size,
48    }
49}
50
51/// Table Offset and BIR.
52#[repr(transparent)]
53#[derive(Copy, Clone)]
54pub struct TableOffset(u32);
55impl TableOffset {
56    /// Returns the 8-byte aligned offset.
57    #[must_use]
58    pub fn offset(self) -> u32 {
59        self.0 & !0b111
60    }
61
62    /// Returns the BIR value.
63    #[must_use]
64    pub fn bir(self) -> u8 {
65        self.0.get_bits(0..=2).try_into().unwrap()
66    }
67}
68impl_debug_from_methods! {
69    TableOffset {
70        offset,
71        bir,
72    }
73}