1 mod device_path_gen;
2 
3 use crate::{guid, Char16, Guid};
4 
5 pub use device_path_gen::{acpi, bios_boot_spec, end, hardware, media, messaging};
6 
7 /// Device path protocol.
8 ///
9 /// A device path contains one or more device path instances made of up
10 /// variable-length nodes.
11 ///
12 /// Note that the fields in this struct define the header at the start of each
13 /// node; a device path is typically larger than these four bytes.
14 #[derive(Debug)]
15 #[repr(C)]
16 pub struct DevicePathProtocol {
17     pub major_type: DeviceType,
18     pub sub_type: DeviceSubType,
19     pub length: [u8; 2],
20     // followed by payload (dynamically sized)
21 }
22 
23 impl DevicePathProtocol {
24     pub const GUID: Guid = guid!("09576e91-6d3f-11d2-8e39-00a0c969723b");
25 }
26 
27 newtype_enum! {
28 /// Type identifier for a device path node.
29 pub enum DeviceType: u8 => {
30     /// Hardware Device Path.
31     ///
32     /// This Device Path defines how a device is attached to the resource domain of a system, where resource domain is
33     /// simply the shared memory, memory mapped I/ O, and I/O space of the system.
34     HARDWARE = 0x01,
35     /// ACPI Device Path.
36     ///
37     /// This Device Path is used to describe devices whose enumeration is not described in an industry-standard fashion.
38     /// These devices must be described using ACPI AML in the ACPI namespace; this Device Path is a linkage to the ACPI
39     /// namespace.
40     ACPI = 0x02,
41     /// Messaging Device Path.
42     ///
43     /// This Device Path is used to describe the connection of devices outside the resource domain of the system. This
44     /// Device Path can describe physical messaging information such as a SCSI ID, or abstract information such as
45     /// networking protocol IP addresses.
46     MESSAGING = 0x03,
47     /// Media Device Path.
48     ///
49     /// This Device Path is used to describe the portion of a medium that is being abstracted by a boot service.
50     /// For example, a Media Device Path could define which partition on a hard drive was being used.
51     MEDIA = 0x04,
52     /// BIOS Boot Specification Device Path.
53     ///
54     /// This Device Path is used to point to boot legacy operating systems; it is based on the BIOS Boot Specification
55     /// Version 1.01.
56     BIOS_BOOT_SPEC = 0x05,
57     /// End of Hardware Device Path.
58     ///
59     /// Depending on the Sub-Type, this Device Path node is used to indicate the end of the Device Path instance or
60     /// Device Path structure.
61     END = 0x7F,
62 }}
63 
64 /// Sub-type identifier for a device path node.
65 #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
66 #[repr(transparent)]
67 pub struct DeviceSubType(pub u8);
68 
69 impl DeviceSubType {
70     /// PCI Device Path.
71     pub const HARDWARE_PCI: Self = Self(1);
72     /// PCCARD Device Path.
73     pub const HARDWARE_PCCARD: Self = Self(2);
74     /// Memory-mapped Device Path.
75     pub const HARDWARE_MEMORY_MAPPED: Self = Self(3);
76     /// Vendor-Defined Device Path.
77     pub const HARDWARE_VENDOR: Self = Self(4);
78     /// Controller Device Path.
79     pub const HARDWARE_CONTROLLER: Self = Self(5);
80     /// BMC Device Path.
81     pub const HARDWARE_BMC: Self = Self(6);
82 
83     /// ACPI Device Path.
84     pub const ACPI: Self = Self(1);
85     /// Expanded ACPI Device Path.
86     pub const ACPI_EXPANDED: Self = Self(2);
87     /// ACPI _ADR Device Path.
88     pub const ACPI_ADR: Self = Self(3);
89     /// NVDIMM Device Path.
90     pub const ACPI_NVDIMM: Self = Self(4);
91 
92     /// ATAPI Device Path.
93     pub const MESSAGING_ATAPI: Self = Self(1);
94     /// SCSI Device Path.
95     pub const MESSAGING_SCSI: Self = Self(2);
96     /// Fibre Channel Device Path.
97     pub const MESSAGING_FIBRE_CHANNEL: Self = Self(3);
98     /// 1394 Device Path.
99     pub const MESSAGING_1394: Self = Self(4);
100     /// USB Device Path.
101     pub const MESSAGING_USB: Self = Self(5);
102     /// I2O Device Path.
103     pub const MESSAGING_I2O: Self = Self(6);
104     /// Infiniband Device Path.
105     pub const MESSAGING_INFINIBAND: Self = Self(9);
106     /// Vendor-Defined Device Path.
107     pub const MESSAGING_VENDOR: Self = Self(10);
108     /// MAC Address Device Path.
109     pub const MESSAGING_MAC_ADDRESS: Self = Self(11);
110     /// IPV4 Device Path.
111     pub const MESSAGING_IPV4: Self = Self(12);
112     /// IPV6 Device Path.
113     pub const MESSAGING_IPV6: Self = Self(13);
114     /// UART Device Path.
115     pub const MESSAGING_UART: Self = Self(14);
116     /// USB Class Device Path.
117     pub const MESSAGING_USB_CLASS: Self = Self(15);
118     /// USB WWID Device Path.
119     pub const MESSAGING_USB_WWID: Self = Self(16);
120     /// Device Logical Unit.
121     pub const MESSAGING_DEVICE_LOGICAL_UNIT: Self = Self(17);
122     /// SATA Device Path.
123     pub const MESSAGING_SATA: Self = Self(18);
124     /// iSCSI Device Path node (base information).
125     pub const MESSAGING_ISCSI: Self = Self(19);
126     /// VLAN Device Path node.
127     pub const MESSAGING_VLAN: Self = Self(20);
128     /// Fibre Channel Ex Device Path.
129     pub const MESSAGING_FIBRE_CHANNEL_EX: Self = Self(21);
130     /// Serial Attached SCSI (SAS) Ex Device Path.
131     pub const MESSAGING_SCSI_SAS_EX: Self = Self(22);
132     /// NVM Express Namespace Device Path.
133     pub const MESSAGING_NVME_NAMESPACE: Self = Self(23);
134     /// Uniform Resource Identifiers (URI) Device Path.
135     pub const MESSAGING_URI: Self = Self(24);
136     /// UFS Device Path.
137     pub const MESSAGING_UFS: Self = Self(25);
138     /// SD (Secure Digital) Device Path.
139     pub const MESSAGING_SD: Self = Self(26);
140     /// Bluetooth Device Path.
141     pub const MESSAGING_BLUETOOTH: Self = Self(27);
142     /// Wi-Fi Device Path.
143     pub const MESSAGING_WIFI: Self = Self(28);
144     /// eMMC (Embedded Multi-Media Card) Device Path.
145     pub const MESSAGING_EMMC: Self = Self(29);
146     /// BluetoothLE Device Path.
147     pub const MESSAGING_BLUETOOTH_LE: Self = Self(30);
148     /// DNS Device Path.
149     pub const MESSAGING_DNS: Self = Self(31);
150     /// NVDIMM Namespace Device Path.
151     pub const MESSAGING_NVDIMM_NAMESPACE: Self = Self(32);
152     /// REST Service Device Path.
153     pub const MESSAGING_REST_SERVICE: Self = Self(33);
154     /// NVME over Fabric (NVMe-oF) Namespace Device Path.
155     pub const MESSAGING_NVME_OF_NAMESPACE: Self = Self(34);
156 
157     /// Hard Drive Media Device Path.
158     pub const MEDIA_HARD_DRIVE: Self = Self(1);
159     /// CD-ROM Media Device Path.
160     pub const MEDIA_CD_ROM: Self = Self(2);
161     /// Vendor-Defined Media Device Path.
162     pub const MEDIA_VENDOR: Self = Self(3);
163     /// File Path Media Device Path.
164     pub const MEDIA_FILE_PATH: Self = Self(4);
165     /// Media Protocol Device Path.
166     pub const MEDIA_PROTOCOL: Self = Self(5);
167     /// PIWG Firmware File.
168     pub const MEDIA_PIWG_FIRMWARE_FILE: Self = Self(6);
169     /// PIWG Firmware Volume.
170     pub const MEDIA_PIWG_FIRMWARE_VOLUME: Self = Self(7);
171     /// Relative Offset Range.
172     pub const MEDIA_RELATIVE_OFFSET_RANGE: Self = Self(8);
173     /// RAM Disk Device Path.
174     pub const MEDIA_RAM_DISK: Self = Self(9);
175 
176     /// BIOS Boot Specification Device Path.
177     pub const BIOS_BOOT_SPECIFICATION: Self = Self(1);
178 
179     /// End this instance of a Device Path and start a new one.
180     pub const END_INSTANCE: Self = Self(0x01);
181     /// End entire Device Path.
182     pub const END_ENTIRE: Self = Self(0xff);
183 }
184 
185 #[derive(Debug)]
186 #[repr(C)]
187 pub struct DevicePathToTextProtocol {
188     pub convert_device_node_to_text: unsafe extern "efiapi" fn(
189         device_node: *const DevicePathProtocol,
190         display_only: bool,
191         allow_shortcuts: bool,
192     ) -> *const Char16,
193     pub convert_device_path_to_text: unsafe extern "efiapi" fn(
194         device_path: *const DevicePathProtocol,
195         display_only: bool,
196         allow_shortcuts: bool,
197     ) -> *const Char16,
198 }
199 
200 impl DevicePathToTextProtocol {
201     pub const GUID: Guid = guid!("8b843e20-8132-4852-90cc-551a4e4a7f1c");
202 }
203 
204 #[derive(Debug)]
205 #[repr(C)]
206 pub struct DevicePathFromTextProtocol {
207     pub convert_text_to_device_node:
208         unsafe extern "efiapi" fn(text_device_node: *const Char16) -> *const DevicePathProtocol,
209     pub convert_text_to_device_path:
210         unsafe extern "efiapi" fn(text_device_path: *const Char16) -> *const DevicePathProtocol,
211 }
212 
213 impl DevicePathFromTextProtocol {
214     pub const GUID: Guid = guid!("05c99a21-c70f-4ad2-8a5f-35df3343f51e");
215 }
216