|
18 | 18 |
|
19 | 19 | use crate::{proto::Protocol, unsafe_guid}; |
20 | 20 |
|
| 21 | +/// Header that appears at the start of every [`DevicePath`] node. |
| 22 | +#[derive(Clone, Copy, Debug, Eq, PartialEq)] |
| 23 | +#[repr(C, packed)] |
| 24 | +pub struct DevicePathHeader { |
| 25 | + /// Type of device |
| 26 | + pub device_type: DeviceType, |
| 27 | + /// Sub type of device |
| 28 | + pub sub_type: DeviceSubType, |
| 29 | + /// Size (in bytes) of the full [`DevicePath`] instance, including this header. |
| 30 | + pub length: u16, |
| 31 | +} |
| 32 | + |
21 | 33 | /// Device path protocol. |
22 | 34 | /// |
23 | 35 | /// This can be opened on a `LoadedImage.device()` handle using the `HandleProtocol` boot service. |
24 | 36 | #[repr(C, packed)] |
25 | 37 | #[unsafe_guid("09576e91-6d3f-11d2-8e39-00a0c969723b")] |
26 | 38 | #[derive(Protocol)] |
27 | 39 | pub struct DevicePath { |
| 40 | + header: DevicePathHeader, |
| 41 | +} |
| 42 | + |
| 43 | +impl DevicePath { |
28 | 44 | /// Type of device |
29 | | - pub device_type: DeviceType, |
| 45 | + pub fn device_type(&self) -> DeviceType { |
| 46 | + self.header.device_type |
| 47 | + } |
| 48 | + |
30 | 49 | /// Sub type of device |
31 | | - pub sub_type: DeviceSubType, |
32 | | - /// Data related to device path |
33 | | - /// |
34 | | - /// The `device_type` and `sub_type` determine the kind of data, and its size. |
35 | | - pub length: u16, |
| 50 | + pub fn sub_type(&self) -> DeviceSubType { |
| 51 | + self.header.sub_type |
| 52 | + } |
| 53 | + |
| 54 | + /// Size (in bytes) of the full [`DevicePath`] instance, including the header. |
| 55 | + pub fn length(&self) -> u16 { |
| 56 | + self.header.length |
| 57 | + } |
36 | 58 | } |
37 | 59 |
|
38 | 60 | newtype_enum! { |
@@ -191,10 +213,8 @@ impl DeviceSubType { |
191 | 213 | /// ACPI Device Path |
192 | 214 | #[repr(C, packed)] |
193 | 215 | pub struct AcpiDevicePath { |
194 | | - /// Type of device, which is ACPI Device Path |
195 | | - pub device_type: DeviceType, |
196 | | - /// Sub type of the device, which is ACPI Device Path |
197 | | - pub sub_type: DeviceSubType, |
| 216 | + header: DevicePathHeader, |
| 217 | + |
198 | 218 | /// Device's PnP hardware ID stored in a numeric 32-bit compressed EISA-type ID. This value must match the |
199 | 219 | /// corresponding _HID in the ACPI name space. |
200 | 220 | pub hid: u32, |
|
0 commit comments