11// SPDX-License-Identifier: MIT OR Apache-2.0
22
3- //! Device Path protocol
4- //!
5- //! A UEFI device path is a very flexible structure for encoding a
6- //! programmatic path such as a hard drive or console.
7- //!
8- //! A device path is made up of a packed list of variable-length nodes of
9- //! various types. The entire device path is terminated with an
10- //! [`END_ENTIRE`] node. A device path _may_ contain multiple device-path
11- //! instances separated by [`END_INSTANCE`] nodes, but typical paths contain
12- //! only a single instance (in which case no `END_INSTANCE` node is needed).
13- //!
14- //! Example of what a device path containing two instances (each comprised of
15- //! three nodes) might look like:
16- //!
17- //! ```text
18- //! ┌──────┬─────┬──────────────╥───────┬──────────┬────────────┐
19- //! │ ACPI │ PCI │ END_INSTANCE ║ CDROM │ FILEPATH │ END_ENTIRE │
20- //! └──────┴─────┴──────────────╨───────┴──────────┴────────────┘
21- //! ↑ ↑ ↑
22- //! ├─── DevicePathInstance ────╨────── DevicePathInstance ─────┤
23- //! │ │
24- //! └─────────────────── Entire DevicePath ─────────────────────┘
25- //! ```
3+ //! High-level wrappers for the UEFI device path [`Protocol`], i.e.,
4+ //! [UEFI device paths].
265//!
276//! # Types
287//!
7453//! [`Protocol`]: crate::proto::Protocol
7554//! [`device_type`]: DevicePathNode::device_type
7655//! [`sub_type`]: DevicePathNode::sub_type
56+ //! [UEFI device paths]: uefi_raw::protocol::device_path
7757
7858pub mod build;
7959pub mod text;
@@ -92,7 +72,6 @@ use core::ffi::c_void;
9272use core:: fmt:: { self , Debug , Display , Formatter } ;
9373use core:: ops:: Deref ;
9474use ptr_meta:: Pointee ;
95-
9675use uefi_raw:: protocol:: device_path:: DevicePathProtocol ;
9776#[ cfg( feature = "alloc" ) ]
9877use {
@@ -400,21 +379,49 @@ impl ToOwned for DevicePathInstance {
400379 }
401380}
402381
403- /// Device path protocol.
382+ /// High-level representation of the UEFI [device path protocol] .
404383///
405- /// Can be used on any device handle to obtain generic path/location information
406- /// concerning the physical device or logical device. If the handle does not
407- /// logically map to a physical device, the handle may not necessarily support
408- /// the device path protocol. The device path describes the location of the
409- /// device the handle is for. The size of the Device Path can be determined from
410- /// the structures that make up the Device Path.
384+ /// This type represents an entire device path, possibly consisting of multiple
385+ /// [`DevicePathInstance`]s and [`DevicePathNode`]s.
411386///
412387/// See the [module-level documentation] for more details.
413388///
389+ /// # Usage
390+ /// This type implements [`Protocol`] and therefore can be used on any
391+ /// device handle to obtain generic path/location information concerning the
392+ /// physical device or logical device. If the handle does not logically map to a
393+ /// physical device, the handle may not necessarily support the device path
394+ /// protocol. The device path describes the location of the device the handle is
395+ /// for. The size of the Device Path can be determined from the structures that
396+ /// make up the Device Path.
397+ ///
398+ /// # Example
399+ /// ```rust,no_run
400+ /// use uefi::Handle;
401+ /// use uefi::boot::{open_protocol_exclusive, ScopedProtocol};
402+ /// use uefi::proto::device_path::DevicePath;
403+ /// use uefi::proto::device_path::text::{AllowShortcuts, DisplayOnly};
404+ /// use uefi::proto::loaded_image::LoadedImage;
405+ ///
406+ /// fn open_device_path(image_handle: Handle) {
407+ /// let loaded_image = open_protocol_exclusive::<LoadedImage>(image_handle).unwrap();
408+ /// let device_handle = loaded_image.device().unwrap();
409+ /// let device_path: ScopedProtocol<DevicePath>
410+ /// = open_protocol_exclusive::<DevicePath>(device_handle).unwrap();
411+ /// log::debug!(
412+ /// "Device path: {}",
413+ /// device_path.to_string(DisplayOnly(true), AllowShortcuts(true)).unwrap()
414+ /// );
415+ /// }
416+ /// ```
417+ ///
414418/// [module-level documentation]: crate::proto::device_path
415419/// [`END_ENTIRE`]: DeviceSubType::END_ENTIRE
420+ /// [`DevicePathProtocol`]: uefi_raw::protocol::device_path::DevicePathProtocol
421+ /// [`Protocol`]: uefi::proto::Protocol
422+ /// [device path protocol]: uefi_raw::protocol::device_path
416423#[ repr( C , packed) ]
417- #[ unsafe_protocol( uefi_raw :: protocol :: device_path :: DevicePathProtocol :: GUID ) ]
424+ #[ unsafe_protocol( DevicePathProtocol :: GUID ) ]
418425#[ derive( Eq , Pointee ) ]
419426pub struct DevicePath {
420427 data : [ u8 ] ,
0 commit comments