pcics/capabilities/slot_identification.rs
1/*!
2# Slot Identification
3
4This Capability structure identifies a bridge that provides external expansion capabilities
5
6## Struct diagram
7[SlotIdentification]
8- [ExpansionSlot]
9
10## Examples
11
12> Slot ID: 2 slots, First+, chassis 0x02
13
14```rust
15# use pcics::capabilities::slot_identification::*;
16let data = [0x04, 0x00, 0x22, 0x02];
17let result = data[2..].try_into().unwrap();
18let sample = SlotIdentification {
19 expansion_slot: ExpansionSlot {
20 expansion_slots_provided: 2,
21 first_in_chassis: true,
22 },
23 chassis_number: 2,
24};
25assert_eq!(sample, result);
26```
27*/
28
29use heterob::{bit_numbering::Lsb, endianness::Le, Seq, P2, P3};
30
31use super::CapabilityDataError;
32
33/// Slot Identification
34#[derive(Debug, Clone, PartialEq, Eq)]
35pub struct SlotIdentification {
36 pub expansion_slot: ExpansionSlot,
37 /// Contains the physical chassis number for the slots on this bridge’s secondary interface
38 pub chassis_number: u8,
39}
40impl<'a> TryFrom<&'a [u8]> for SlotIdentification {
41 type Error = CapabilityDataError;
42
43 fn try_from(slice: &'a [u8]) -> Result<Self, Self::Error> {
44 let Seq {
45 head: Le((expansion_slot, chassis_number)),
46 ..
47 } = P2(slice).try_into().map_err(|_| CapabilityDataError {
48 name: "Slot Identification",
49 size: 2,
50 })?;
51 let Lsb((expansion_slots_provided, first_in_chassis, ())) =
52 P3::<u8, 5, 1, 2>(expansion_slot).into();
53 let expansion_slot = ExpansionSlot {
54 expansion_slots_provided,
55 first_in_chassis,
56 };
57 Ok(Self {
58 expansion_slot,
59 chassis_number,
60 })
61 }
62}
63
64/// Provides information used by system software in calculating the slot number of a device plugged
65/// into a PCI slot in an expansion chassis
66#[derive(Debug, Clone, PartialEq, Eq)]
67pub struct ExpansionSlot {
68 /// Number of PCI expansion slots located directly on the secondary interface of this bridge
69 pub expansion_slots_provided: u8,
70 /// Indicates that this bridge is the first in an expansion chassis
71 pub first_in_chassis: bool,
72}