pcics/capabilities/
vital_product_data.rs

1/*!
2# Vital Product Data
3
4Vital Product Data (VPD) is the information that uniquely defines items such as the hardware,
5software, and microcode elements of a system.
6
7## Struct diagram
8[VitalProductData]
9
10## Examples
11
12```rust
13# use pcics::capabilities::vital_product_data::*;
14let data = [0x03, 0x58, 0x8c, 0x81, 0x00, 0x00, 0x00, 0x78,];
15let result = data[2..].try_into().unwrap();
16let sample = VitalProductData {
17    vpd_address: 0x018c,
18    transfer_completed: true,
19    vpd_data: 0x78000000,
20};
21assert_eq!(sample, result);
22```
23*/
24
25use heterob::{bit_numbering::Lsb, endianness::Le, Seq, P2};
26
27use super::CapabilityDataError;
28
29/// Vital Product Data
30#[derive(Debug, Clone, PartialEq, Eq)]
31pub struct VitalProductData {
32    /// DWORD-aligned byte address of the VPD to be accessed
33    pub vpd_address: u16,
34    /// Indicate when the transfer of data between the VPD Data register and the storage component
35    /// is completed
36    pub transfer_completed: bool,
37    /// VPD Data
38    pub vpd_data: u32,
39}
40impl TryFrom<&[u8]> for VitalProductData {
41    type Error = CapabilityDataError;
42
43    fn try_from(slice: &[u8]) -> Result<Self, Self::Error> {
44        let Seq {
45            head: Le((word, vpd_data)),
46            ..
47        } = P2(slice).try_into().map_err(|_| CapabilityDataError {
48            name: "Vital Product Data",
49            size: 6,
50        })?;
51        let Lsb((vpd_address, transfer_completed)) = P2::<u16, 15, 1>(word).into();
52        Ok(Self {
53            vpd_address,
54            transfer_completed,
55            vpd_data,
56        })
57    }
58}