Skip to content

Move DeviceType and DeviceSubType enums to uefi-raw #1442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions uefi-raw/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# uefi-raw - [Unreleased]

## Added

- Added `DeviceType` and `DeviceSubType` enums.


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

Expand Down
162 changes: 160 additions & 2 deletions uefi-raw/src/protocol/device_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::{guid, Char16, Guid};
#[derive(Debug)]
#[repr(C)]
pub struct DevicePathProtocol {
pub major_type: u8,
pub sub_type: u8,
pub major_type: DeviceType,
pub sub_type: DeviceSubType,
pub length: [u8; 2],
// followed by payload (dynamically sized)
}
Expand All @@ -20,6 +20,164 @@ impl DevicePathProtocol {
pub const GUID: Guid = guid!("09576e91-6d3f-11d2-8e39-00a0c969723b");
}

newtype_enum! {
/// Type identifier for a device path node.
pub enum DeviceType: u8 => {
/// Hardware Device Path.
///
/// This Device Path defines how a device is attached to the resource domain of a system, where resource domain is
/// simply the shared memory, memory mapped I/ O, and I/O space of the system.
HARDWARE = 0x01,
/// ACPI Device Path.
///
/// This Device Path is used to describe devices whose enumeration is not described in an industry-standard fashion.
/// These devices must be described using ACPI AML in the ACPI namespace; this Device Path is a linkage to the ACPI
/// namespace.
ACPI = 0x02,
/// Messaging Device Path.
///
/// This Device Path is used to describe the connection of devices outside the resource domain of the system. This
/// Device Path can describe physical messaging information such as a SCSI ID, or abstract information such as
/// networking protocol IP addresses.
MESSAGING = 0x03,
/// Media Device Path.
///
/// This Device Path is used to describe the portion of a medium that is being abstracted by a boot service.
/// For example, a Media Device Path could define which partition on a hard drive was being used.
MEDIA = 0x04,
/// BIOS Boot Specification Device Path.
///
/// This Device Path is used to point to boot legacy operating systems; it is based on the BIOS Boot Specification
/// Version 1.01.
BIOS_BOOT_SPEC = 0x05,
/// End of Hardware Device Path.
///
/// Depending on the Sub-Type, this Device Path node is used to indicate the end of the Device Path instance or
/// Device Path structure.
END = 0x7F,
}}

/// Sub-type identifier for a device path node.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(transparent)]
pub struct DeviceSubType(pub u8);

impl DeviceSubType {
/// PCI Device Path.
pub const HARDWARE_PCI: Self = Self(1);
/// PCCARD Device Path.
pub const HARDWARE_PCCARD: Self = Self(2);
/// Memory-mapped Device Path.
pub const HARDWARE_MEMORY_MAPPED: Self = Self(3);
/// Vendor-Defined Device Path.
pub const HARDWARE_VENDOR: Self = Self(4);
/// Controller Device Path.
pub const HARDWARE_CONTROLLER: Self = Self(5);
/// BMC Device Path.
pub const HARDWARE_BMC: Self = Self(6);

/// ACPI Device Path.
pub const ACPI: Self = Self(1);
/// Expanded ACPI Device Path.
pub const ACPI_EXPANDED: Self = Self(2);
/// ACPI _ADR Device Path.
pub const ACPI_ADR: Self = Self(3);
/// NVDIMM Device Path.
pub const ACPI_NVDIMM: Self = Self(4);

/// ATAPI Device Path.
pub const MESSAGING_ATAPI: Self = Self(1);
/// SCSI Device Path.
pub const MESSAGING_SCSI: Self = Self(2);
/// Fibre Channel Device Path.
pub const MESSAGING_FIBRE_CHANNEL: Self = Self(3);
/// 1394 Device Path.
pub const MESSAGING_1394: Self = Self(4);
/// USB Device Path.
pub const MESSAGING_USB: Self = Self(5);
/// I2O Device Path.
pub const MESSAGING_I2O: Self = Self(6);
/// Infiniband Device Path.
pub const MESSAGING_INFINIBAND: Self = Self(9);
/// Vendor-Defined Device Path.
pub const MESSAGING_VENDOR: Self = Self(10);
/// MAC Address Device Path.
pub const MESSAGING_MAC_ADDRESS: Self = Self(11);
/// IPV4 Device Path.
pub const MESSAGING_IPV4: Self = Self(12);
/// IPV6 Device Path.
pub const MESSAGING_IPV6: Self = Self(13);
/// UART Device Path.
pub const MESSAGING_UART: Self = Self(14);
/// USB Class Device Path.
pub const MESSAGING_USB_CLASS: Self = Self(15);
/// USB WWID Device Path.
pub const MESSAGING_USB_WWID: Self = Self(16);
/// Device Logical Unit.
pub const MESSAGING_DEVICE_LOGICAL_UNIT: Self = Self(17);
/// SATA Device Path.
pub const MESSAGING_SATA: Self = Self(18);
/// iSCSI Device Path node (base information).
pub const MESSAGING_ISCSI: Self = Self(19);
/// VLAN Device Path node.
pub const MESSAGING_VLAN: Self = Self(20);
/// Fibre Channel Ex Device Path.
pub const MESSAGING_FIBRE_CHANNEL_EX: Self = Self(21);
/// Serial Attached SCSI (SAS) Ex Device Path.
pub const MESSAGING_SCSI_SAS_EX: Self = Self(22);
/// NVM Express Namespace Device Path.
pub const MESSAGING_NVME_NAMESPACE: Self = Self(23);
/// Uniform Resource Identifiers (URI) Device Path.
pub const MESSAGING_URI: Self = Self(24);
/// UFS Device Path.
pub const MESSAGING_UFS: Self = Self(25);
/// SD (Secure Digital) Device Path.
pub const MESSAGING_SD: Self = Self(26);
/// Bluetooth Device Path.
pub const MESSAGING_BLUETOOTH: Self = Self(27);
/// Wi-Fi Device Path.
pub const MESSAGING_WIFI: Self = Self(28);
/// eMMC (Embedded Multi-Media Card) Device Path.
pub const MESSAGING_EMMC: Self = Self(29);
/// BluetoothLE Device Path.
pub const MESSAGING_BLUETOOTH_LE: Self = Self(30);
/// DNS Device Path.
pub const MESSAGING_DNS: Self = Self(31);
/// NVDIMM Namespace Device Path.
pub const MESSAGING_NVDIMM_NAMESPACE: Self = Self(32);
/// REST Service Device Path.
pub const MESSAGING_REST_SERVICE: Self = Self(33);
/// NVME over Fabric (NVMe-oF) Namespace Device Path.
pub const MESSAGING_NVME_OF_NAMESPACE: Self = Self(34);

/// Hard Drive Media Device Path.
pub const MEDIA_HARD_DRIVE: Self = Self(1);
/// CD-ROM Media Device Path.
pub const MEDIA_CD_ROM: Self = Self(2);
/// Vendor-Defined Media Device Path.
pub const MEDIA_VENDOR: Self = Self(3);
/// File Path Media Device Path.
pub const MEDIA_FILE_PATH: Self = Self(4);
/// Media Protocol Device Path.
pub const MEDIA_PROTOCOL: Self = Self(5);
/// PIWG Firmware File.
pub const MEDIA_PIWG_FIRMWARE_FILE: Self = Self(6);
/// PIWG Firmware Volume.
pub const MEDIA_PIWG_FIRMWARE_VOLUME: Self = Self(7);
/// Relative Offset Range.
pub const MEDIA_RELATIVE_OFFSET_RANGE: Self = Self(8);
/// RAM Disk Device Path.
pub const MEDIA_RAM_DISK: Self = Self(9);

/// BIOS Boot Specification Device Path.
pub const BIOS_BOOT_SPECIFICATION: Self = Self(1);

/// End this instance of a Device Path and start a new one.
pub const END_INSTANCE: Self = Self(0x01);
/// End entire Device Path.
pub const END_ENTIRE: Self = Self(0xff);
}

#[derive(Debug)]
#[repr(C)]
pub struct DevicePathToTextProtocol {
Expand Down
158 changes: 1 addition & 157 deletions uefi/src/proto/device_path/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ mod device_path_gen;
pub use device_path_gen::{
acpi, bios_boot_spec, end, hardware, media, messaging, DevicePathNodeEnum,
};
pub use uefi_raw::protocol::device_path::{DeviceSubType, DeviceType};

use crate::proto::{unsafe_protocol, ProtocolPointer};
use core::ffi::c_void;
Expand Down Expand Up @@ -631,163 +632,6 @@ impl<'a> Iterator for DevicePathNodeIterator<'a> {
}
}

newtype_enum! {
/// Type identifier for a DevicePath
pub enum DeviceType: u8 => {
/// Hardware Device Path.
///
/// This Device Path defines how a device is attached to the resource domain of a system, where resource domain is
/// simply the shared memory, memory mapped I/ O, and I/O space of the system.
HARDWARE = 0x01,
/// ACPI Device Path.
///
/// This Device Path is used to describe devices whose enumeration is not described in an industry-standard fashion.
/// These devices must be described using ACPI AML in the ACPI namespace; this Device Path is a linkage to the ACPI
/// namespace.
ACPI = 0x02,
/// Messaging Device Path.
///
/// This Device Path is used to describe the connection of devices outside the resource domain of the system. This
/// Device Path can describe physical messaging information such as a SCSI ID, or abstract information such as
/// networking protocol IP addresses.
MESSAGING = 0x03,
/// Media Device Path.
///
/// This Device Path is used to describe the portion of a medium that is being abstracted by a boot service.
/// For example, a Media Device Path could define which partition on a hard drive was being used.
MEDIA = 0x04,
/// BIOS Boot Specification Device Path.
///
/// This Device Path is used to point to boot legacy operating systems; it is based on the BIOS Boot Specification
/// Version 1.01.
BIOS_BOOT_SPEC = 0x05,
/// End of Hardware Device Path.
///
/// Depending on the Sub-Type, this Device Path node is used to indicate the end of the Device Path instance or
/// Device Path structure.
END = 0x7F,
}}

/// Sub-type identifier for a DevicePath
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct DeviceSubType(pub u8);

impl DeviceSubType {
/// PCI Device Path.
pub const HARDWARE_PCI: Self = Self(1);
/// PCCARD Device Path.
pub const HARDWARE_PCCARD: Self = Self(2);
/// Memory-mapped Device Path.
pub const HARDWARE_MEMORY_MAPPED: Self = Self(3);
/// Vendor-Defined Device Path.
pub const HARDWARE_VENDOR: Self = Self(4);
/// Controller Device Path.
pub const HARDWARE_CONTROLLER: Self = Self(5);
/// BMC Device Path.
pub const HARDWARE_BMC: Self = Self(6);

/// ACPI Device Path.
pub const ACPI: Self = Self(1);
/// Expanded ACPI Device Path.
pub const ACPI_EXPANDED: Self = Self(2);
/// ACPI _ADR Device Path.
pub const ACPI_ADR: Self = Self(3);
/// NVDIMM Device Path.
pub const ACPI_NVDIMM: Self = Self(4);

/// ATAPI Device Path.
pub const MESSAGING_ATAPI: Self = Self(1);
/// SCSI Device Path.
pub const MESSAGING_SCSI: Self = Self(2);
/// Fibre Channel Device Path.
pub const MESSAGING_FIBRE_CHANNEL: Self = Self(3);
/// 1394 Device Path.
pub const MESSAGING_1394: Self = Self(4);
/// USB Device Path.
pub const MESSAGING_USB: Self = Self(5);
/// I2O Device Path.
pub const MESSAGING_I2O: Self = Self(6);
/// Infiniband Device Path.
pub const MESSAGING_INFINIBAND: Self = Self(9);
/// Vendor-Defined Device Path.
pub const MESSAGING_VENDOR: Self = Self(10);
/// MAC Address Device Path.
pub const MESSAGING_MAC_ADDRESS: Self = Self(11);
/// IPV4 Device Path.
pub const MESSAGING_IPV4: Self = Self(12);
/// IPV6 Device Path.
pub const MESSAGING_IPV6: Self = Self(13);
/// UART Device Path.
pub const MESSAGING_UART: Self = Self(14);
/// USB Class Device Path.
pub const MESSAGING_USB_CLASS: Self = Self(15);
/// USB WWID Device Path.
pub const MESSAGING_USB_WWID: Self = Self(16);
/// Device Logical Unit.
pub const MESSAGING_DEVICE_LOGICAL_UNIT: Self = Self(17);
/// SATA Device Path.
pub const MESSAGING_SATA: Self = Self(18);
/// iSCSI Device Path node (base information).
pub const MESSAGING_ISCSI: Self = Self(19);
/// VLAN Device Path node.
pub const MESSAGING_VLAN: Self = Self(20);
/// Fibre Channel Ex Device Path.
pub const MESSAGING_FIBRE_CHANNEL_EX: Self = Self(21);
/// Serial Attached SCSI (SAS) Ex Device Path.
pub const MESSAGING_SCSI_SAS_EX: Self = Self(22);
/// NVM Express Namespace Device Path.
pub const MESSAGING_NVME_NAMESPACE: Self = Self(23);
/// Uniform Resource Identifiers (URI) Device Path.
pub const MESSAGING_URI: Self = Self(24);
/// UFS Device Path.
pub const MESSAGING_UFS: Self = Self(25);
/// SD (Secure Digital) Device Path.
pub const MESSAGING_SD: Self = Self(26);
/// Bluetooth Device Path.
pub const MESSAGING_BLUETOOTH: Self = Self(27);
/// Wi-Fi Device Path.
pub const MESSAGING_WIFI: Self = Self(28);
/// eMMC (Embedded Multi-Media Card) Device Path.
pub const MESSAGING_EMMC: Self = Self(29);
/// BluetoothLE Device Path.
pub const MESSAGING_BLUETOOTH_LE: Self = Self(30);
/// DNS Device Path.
pub const MESSAGING_DNS: Self = Self(31);
/// NVDIMM Namespace Device Path.
pub const MESSAGING_NVDIMM_NAMESPACE: Self = Self(32);
/// REST Service Device Path.
pub const MESSAGING_REST_SERVICE: Self = Self(33);
/// NVME over Fabric (NVMe-oF) Namespace Device Path.
pub const MESSAGING_NVME_OF_NAMESPACE: Self = Self(34);

/// Hard Drive Media Device Path.
pub const MEDIA_HARD_DRIVE: Self = Self(1);
/// CD-ROM Media Device Path.
pub const MEDIA_CD_ROM: Self = Self(2);
/// Vendor-Defined Media Device Path.
pub const MEDIA_VENDOR: Self = Self(3);
/// File Path Media Device Path.
pub const MEDIA_FILE_PATH: Self = Self(4);
/// Media Protocol Device Path.
pub const MEDIA_PROTOCOL: Self = Self(5);
/// PIWG Firmware File.
pub const MEDIA_PIWG_FIRMWARE_FILE: Self = Self(6);
/// PIWG Firmware Volume.
pub const MEDIA_PIWG_FIRMWARE_VOLUME: Self = Self(7);
/// Relative Offset Range.
pub const MEDIA_RELATIVE_OFFSET_RANGE: Self = Self(8);
/// RAM Disk Device Path.
pub const MEDIA_RAM_DISK: Self = Self(9);

/// BIOS Boot Specification Device Path.
pub const BIOS_BOOT_SPECIFICATION: Self = Self(1);

/// End this instance of a Device Path and start a new one.
pub const END_INSTANCE: Self = Self(0x01);
/// End entire Device Path.
pub const END_ENTIRE: Self = Self(0xff);
}

/// Error returned when attempting to convert from a `&[u8]` to a
/// [`DevicePath`] type.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
Expand Down