Skip to content

Commit c730020

Browse files
authored
Merge pull request #1442 from nicholasbishop/bishop-move-node-types
Move DeviceType and DeviceSubType enums to uefi-raw
2 parents 3dfc5a8 + d2bf0bb commit c730020

File tree

3 files changed

+165
-159
lines changed

3 files changed

+165
-159
lines changed

uefi-raw/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# uefi-raw - [Unreleased]
22

3+
## Added
4+
5+
- Added `DeviceType` and `DeviceSubType` enums.
6+
37

48
# uefi-raw - 0.8.0 (2024-09-09)
59

uefi-raw/src/protocol/device_path.rs

Lines changed: 160 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use crate::{guid, Char16, Guid};
1010
#[derive(Debug)]
1111
#[repr(C)]
1212
pub struct DevicePathProtocol {
13-
pub major_type: u8,
14-
pub sub_type: u8,
13+
pub major_type: DeviceType,
14+
pub sub_type: DeviceSubType,
1515
pub length: [u8; 2],
1616
// followed by payload (dynamically sized)
1717
}
@@ -20,6 +20,164 @@ impl DevicePathProtocol {
2020
pub const GUID: Guid = guid!("09576e91-6d3f-11d2-8e39-00a0c969723b");
2121
}
2222

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

uefi/src/proto/device_path/mod.rs

Lines changed: 1 addition & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ mod device_path_gen;
8080
pub use device_path_gen::{
8181
acpi, bios_boot_spec, end, hardware, media, messaging, DevicePathNodeEnum,
8282
};
83+
pub use uefi_raw::protocol::device_path::{DeviceSubType, DeviceType};
8384

8485
use crate::proto::{unsafe_protocol, ProtocolPointer};
8586
use core::ffi::c_void;
@@ -631,163 +632,6 @@ impl<'a> Iterator for DevicePathNodeIterator<'a> {
631632
}
632633
}
633634

634-
newtype_enum! {
635-
/// Type identifier for a DevicePath
636-
pub enum DeviceType: u8 => {
637-
/// Hardware Device Path.
638-
///
639-
/// This Device Path defines how a device is attached to the resource domain of a system, where resource domain is
640-
/// simply the shared memory, memory mapped I/ O, and I/O space of the system.
641-
HARDWARE = 0x01,
642-
/// ACPI Device Path.
643-
///
644-
/// This Device Path is used to describe devices whose enumeration is not described in an industry-standard fashion.
645-
/// These devices must be described using ACPI AML in the ACPI namespace; this Device Path is a linkage to the ACPI
646-
/// namespace.
647-
ACPI = 0x02,
648-
/// Messaging Device Path.
649-
///
650-
/// This Device Path is used to describe the connection of devices outside the resource domain of the system. This
651-
/// Device Path can describe physical messaging information such as a SCSI ID, or abstract information such as
652-
/// networking protocol IP addresses.
653-
MESSAGING = 0x03,
654-
/// Media Device Path.
655-
///
656-
/// This Device Path is used to describe the portion of a medium that is being abstracted by a boot service.
657-
/// For example, a Media Device Path could define which partition on a hard drive was being used.
658-
MEDIA = 0x04,
659-
/// BIOS Boot Specification Device Path.
660-
///
661-
/// This Device Path is used to point to boot legacy operating systems; it is based on the BIOS Boot Specification
662-
/// Version 1.01.
663-
BIOS_BOOT_SPEC = 0x05,
664-
/// End of Hardware Device Path.
665-
///
666-
/// Depending on the Sub-Type, this Device Path node is used to indicate the end of the Device Path instance or
667-
/// Device Path structure.
668-
END = 0x7F,
669-
}}
670-
671-
/// Sub-type identifier for a DevicePath
672-
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
673-
pub struct DeviceSubType(pub u8);
674-
675-
impl DeviceSubType {
676-
/// PCI Device Path.
677-
pub const HARDWARE_PCI: Self = Self(1);
678-
/// PCCARD Device Path.
679-
pub const HARDWARE_PCCARD: Self = Self(2);
680-
/// Memory-mapped Device Path.
681-
pub const HARDWARE_MEMORY_MAPPED: Self = Self(3);
682-
/// Vendor-Defined Device Path.
683-
pub const HARDWARE_VENDOR: Self = Self(4);
684-
/// Controller Device Path.
685-
pub const HARDWARE_CONTROLLER: Self = Self(5);
686-
/// BMC Device Path.
687-
pub const HARDWARE_BMC: Self = Self(6);
688-
689-
/// ACPI Device Path.
690-
pub const ACPI: Self = Self(1);
691-
/// Expanded ACPI Device Path.
692-
pub const ACPI_EXPANDED: Self = Self(2);
693-
/// ACPI _ADR Device Path.
694-
pub const ACPI_ADR: Self = Self(3);
695-
/// NVDIMM Device Path.
696-
pub const ACPI_NVDIMM: Self = Self(4);
697-
698-
/// ATAPI Device Path.
699-
pub const MESSAGING_ATAPI: Self = Self(1);
700-
/// SCSI Device Path.
701-
pub const MESSAGING_SCSI: Self = Self(2);
702-
/// Fibre Channel Device Path.
703-
pub const MESSAGING_FIBRE_CHANNEL: Self = Self(3);
704-
/// 1394 Device Path.
705-
pub const MESSAGING_1394: Self = Self(4);
706-
/// USB Device Path.
707-
pub const MESSAGING_USB: Self = Self(5);
708-
/// I2O Device Path.
709-
pub const MESSAGING_I2O: Self = Self(6);
710-
/// Infiniband Device Path.
711-
pub const MESSAGING_INFINIBAND: Self = Self(9);
712-
/// Vendor-Defined Device Path.
713-
pub const MESSAGING_VENDOR: Self = Self(10);
714-
/// MAC Address Device Path.
715-
pub const MESSAGING_MAC_ADDRESS: Self = Self(11);
716-
/// IPV4 Device Path.
717-
pub const MESSAGING_IPV4: Self = Self(12);
718-
/// IPV6 Device Path.
719-
pub const MESSAGING_IPV6: Self = Self(13);
720-
/// UART Device Path.
721-
pub const MESSAGING_UART: Self = Self(14);
722-
/// USB Class Device Path.
723-
pub const MESSAGING_USB_CLASS: Self = Self(15);
724-
/// USB WWID Device Path.
725-
pub const MESSAGING_USB_WWID: Self = Self(16);
726-
/// Device Logical Unit.
727-
pub const MESSAGING_DEVICE_LOGICAL_UNIT: Self = Self(17);
728-
/// SATA Device Path.
729-
pub const MESSAGING_SATA: Self = Self(18);
730-
/// iSCSI Device Path node (base information).
731-
pub const MESSAGING_ISCSI: Self = Self(19);
732-
/// VLAN Device Path node.
733-
pub const MESSAGING_VLAN: Self = Self(20);
734-
/// Fibre Channel Ex Device Path.
735-
pub const MESSAGING_FIBRE_CHANNEL_EX: Self = Self(21);
736-
/// Serial Attached SCSI (SAS) Ex Device Path.
737-
pub const MESSAGING_SCSI_SAS_EX: Self = Self(22);
738-
/// NVM Express Namespace Device Path.
739-
pub const MESSAGING_NVME_NAMESPACE: Self = Self(23);
740-
/// Uniform Resource Identifiers (URI) Device Path.
741-
pub const MESSAGING_URI: Self = Self(24);
742-
/// UFS Device Path.
743-
pub const MESSAGING_UFS: Self = Self(25);
744-
/// SD (Secure Digital) Device Path.
745-
pub const MESSAGING_SD: Self = Self(26);
746-
/// Bluetooth Device Path.
747-
pub const MESSAGING_BLUETOOTH: Self = Self(27);
748-
/// Wi-Fi Device Path.
749-
pub const MESSAGING_WIFI: Self = Self(28);
750-
/// eMMC (Embedded Multi-Media Card) Device Path.
751-
pub const MESSAGING_EMMC: Self = Self(29);
752-
/// BluetoothLE Device Path.
753-
pub const MESSAGING_BLUETOOTH_LE: Self = Self(30);
754-
/// DNS Device Path.
755-
pub const MESSAGING_DNS: Self = Self(31);
756-
/// NVDIMM Namespace Device Path.
757-
pub const MESSAGING_NVDIMM_NAMESPACE: Self = Self(32);
758-
/// REST Service Device Path.
759-
pub const MESSAGING_REST_SERVICE: Self = Self(33);
760-
/// NVME over Fabric (NVMe-oF) Namespace Device Path.
761-
pub const MESSAGING_NVME_OF_NAMESPACE: Self = Self(34);
762-
763-
/// Hard Drive Media Device Path.
764-
pub const MEDIA_HARD_DRIVE: Self = Self(1);
765-
/// CD-ROM Media Device Path.
766-
pub const MEDIA_CD_ROM: Self = Self(2);
767-
/// Vendor-Defined Media Device Path.
768-
pub const MEDIA_VENDOR: Self = Self(3);
769-
/// File Path Media Device Path.
770-
pub const MEDIA_FILE_PATH: Self = Self(4);
771-
/// Media Protocol Device Path.
772-
pub const MEDIA_PROTOCOL: Self = Self(5);
773-
/// PIWG Firmware File.
774-
pub const MEDIA_PIWG_FIRMWARE_FILE: Self = Self(6);
775-
/// PIWG Firmware Volume.
776-
pub const MEDIA_PIWG_FIRMWARE_VOLUME: Self = Self(7);
777-
/// Relative Offset Range.
778-
pub const MEDIA_RELATIVE_OFFSET_RANGE: Self = Self(8);
779-
/// RAM Disk Device Path.
780-
pub const MEDIA_RAM_DISK: Self = Self(9);
781-
782-
/// BIOS Boot Specification Device Path.
783-
pub const BIOS_BOOT_SPECIFICATION: Self = Self(1);
784-
785-
/// End this instance of a Device Path and start a new one.
786-
pub const END_INSTANCE: Self = Self(0x01);
787-
/// End entire Device Path.
788-
pub const END_ENTIRE: Self = Self(0xff);
789-
}
790-
791635
/// Error returned when attempting to convert from a `&[u8]` to a
792636
/// [`DevicePath`] type.
793637
#[derive(Clone, Copy, Debug, Eq, PartialEq)]

0 commit comments

Comments
 (0)