pcics/extended_capabilities/
address_translation_services.rs1use heterob::{bit_numbering::Lsb, endianness::Le, Seq, P2, P3, P4};
36
37use super::ExtendedCapabilityDataError;
38
39#[derive(Debug, Clone, PartialEq, Eq)]
40pub struct AddressTranslationServices {
41 pub ats_capability: AtsCapability,
43 pub ats_control: AtsControl,
45}
46impl TryFrom<&[u8]> for AddressTranslationServices {
47 type Error = ExtendedCapabilityDataError;
48
49 fn try_from(slice: &[u8]) -> Result<Self, Self::Error> {
50 let Seq {
51 head: Le((ats_capability, ats_control)),
52 ..
53 } = P2(slice)
54 .try_into()
55 .map_err(|_| ExtendedCapabilityDataError {
56 name: "Address Translation Services",
57 size: 4,
58 })?;
59 Ok(Self {
60 ats_capability: From::<u16>::from(ats_capability),
61 ats_control: From::<u16>::from(ats_control),
62 })
63 }
64}
65
66#[derive(Debug, Clone, PartialEq, Eq)]
68pub struct AtsCapability {
69 pub invalidate_queue_depth: u8,
71 pub page_aligned_request: bool,
73 pub global_invalidate_supported: bool,
75}
76
77impl From<u16> for AtsCapability {
78 fn from(word: u16) -> Self {
79 let Lsb((invalidate_queue_depth, page_aligned_request, global_invalidate_supported, ())) =
80 P4::<_, 5, 1, 1, 9>(word).into();
81 Self {
82 invalidate_queue_depth,
83 page_aligned_request,
84 global_invalidate_supported,
85 }
86 }
87}
88
89#[derive(Debug, Clone, PartialEq, Eq)]
90pub struct AtsControl {
91 pub smallest_translation_unit: u8,
93 pub enable: bool,
95}
96
97impl From<u16> for AtsControl {
98 fn from(word: u16) -> Self {
99 let Lsb((smallest_translation_unit, (), enable)) = P3::<_, 5, 10, 1>(word).into();
100 Self {
101 smallest_translation_unit,
102 enable,
103 }
104 }
105}