1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*!
# Configuration Access Correlation (CAC)
The PCI Express Configuration Access Correlation (CAC) Capability is an optional Extended
Capability that must be implemented by any PCI Express device Function that provides a Trusted
Configuration Space.
## Struct diagram
<pre>
<a href="struct.ConfigurationAccessCorrelation.html">ConfigurationAccessCorrelation</a>
</pre>
## Examples
```rust
# use pcics::extended_capabilities::configuration_access_correlation::*;
let data = [
/* 00h */ 0x0c, 0x00, 0x01, 0x00, // Capability header
/* 04h */ 0x00, 0x11, 0x22, 0x33, // Device Correlation
];
let result: ConfigurationAccessCorrelation = data.as_slice().try_into().unwrap();
let sample = ConfigurationAccessCorrelation {
device_correlation: 0x33221100,
};
assert_eq!(sample, result);
```
*/
use heterob::{endianness::Le, Seq, P2};
use super::{ExtendedCapabilityDataError, ExtendedCapabilityHeaderPlaceholder};
/// Configuration Access Correlation
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ConfigurationAccessCorrelation {
/// Device Correlation
///
/// Contains a value written from within the TSE via the Configuration
/// Access Correlation Trusted Capability.
pub device_correlation: u32,
}
impl ConfigurationAccessCorrelation {
/// Size in bytes (with Extended Capability Header)
pub const SIZE: usize = 0x8;
}
impl From<[u8; Self::SIZE]> for ConfigurationAccessCorrelation {
fn from(bytes: [u8; Self::SIZE]) -> Self {
let Le((ExtendedCapabilityHeaderPlaceholder, device_correlation)) = P2(bytes).into();
Self { device_correlation }
}
}
impl TryFrom<&[u8]> for ConfigurationAccessCorrelation {
type Error = ExtendedCapabilityDataError;
fn try_from(slice: &[u8]) -> Result<Self, Self::Error> {
let Seq { head, .. } = slice.try_into().map_err(|_| ExtendedCapabilityDataError {
name: "Configuration Access Correlation",
size: Self::SIZE,
})?;
Ok(From::<[u8; Self::SIZE]>::from(head))
}
}