Skip to content

Commit 5d233a5

Browse files
Merge pull request #1612 from rust-osdev/doc-devicepath
doc/uefi: improve Protocol documentation
2 parents d61b05a + 4e03942 commit 5d233a5

File tree

34 files changed

+200
-59
lines changed

34 files changed

+200
-59
lines changed

book/src/how_to/protocols.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Using Protocols
22

3+
## About UEFI Protocols
4+
5+
UEFI protocols are a structured collection of functions and/or data. Please
6+
head to the module documentation in [uefi] for more technical information.
7+
8+
[uefi]: https://docs.rs/uefi/latest/uefi/proto/index.html
9+
10+
## Usage in uefi-rs
11+
312
To open a protocol, you must first get a handle, then open a protocol
413
on that handle. See [Handles and Protocols] for an overview of what
514
these terms mean.

uefi-raw/CHANGELOG.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
- Added `ConfigKeywordHandlerProtocol`.
77
- Added `HiiConfigAccessProtocol`.
88

9+
## Changed
10+
- The documentation for UEFI protocols has been streamlined and improved.
911

1012
# uefi-raw - 0.11.0 (2025-05-04)
1113

@@ -28,11 +30,6 @@
2830
## Changed
2931
- `DevicePathProtocol` now derives
3032
`Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash`
31-
- The documentation for UEFI device paths has been streamlined and improved.
32-
33-
## Changed
34-
35-
- **Breaking:** The MSRV is now 1.85.1 and the crate uses the Rust 2024 edition.
3633

3734

3835
# uefi-raw - 0.10.0 (2025-02-07)

uefi-raw/src/protocol/device_path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//!
88
//! # Terminology: Device Paths, Device Path Instances, and Device Path Nodes
99
//! An open UEFI device path [protocol], also called _device path_, is a
10-
//! flexible and structured sequence of binary nodes that describe a route from
10+
//! flexible and structured sequence of binary nodes that describes a route from
1111
//! the UEFI root to a particular device, controller, or file.
1212
//!
1313
//! An entire device path can be made up of multiple device path instances,

uefi-raw/src/protocol/mod.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,26 @@
22

33
//! Protocol definitions.
44
//!
5-
//! Protocols are sets of related functionality identified by a unique
6-
//! ID. They can be implemented by a UEFI driver or occasionally by a
7-
//! UEFI application.
5+
//! # TL;DR
6+
//! Technically, a protocol is a `C` struct holding functions and/or data, with
7+
//! an associated [`GUID`].
8+
//!
9+
//! # About
10+
//! UEFI protocols are a structured collection of functions and/or data,
11+
//! identified by a [`GUID`], which defines an interface between components in
12+
//! the UEFI environment, such as between drivers, applications, or firmware
13+
//! services.
14+
//!
15+
//! Protocols are central to UEFI’s handle-based object model, and they provide
16+
//! a clean, extensible way for components to discover and use services from one
17+
//! another.
18+
//!
19+
//! Implementation-wise, a protocol is a `C` struct holding function pointers
20+
//! and/or data. Please note that some protocols may use [`core::ptr::null`] as
21+
//! interface. For example, the device path protocol can be implemented but
22+
//! return `null`.
23+
//!
24+
//! [`GUID`]: crate::Guid
825
926
pub mod ata;
1027
pub mod block;

uefi/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
it in case you are also using the `logger` feature and if you run your UEFI
1818
image in QEMU or Cloud Hypervisor, when the debugcon/debug-console device is
1919
available.
20+
- The documentation for UEFI protocols has been streamlined and improved.
2021

2122
# uefi - 0.35.0 (2025-05-04)
2223

@@ -64,7 +65,6 @@
6465
bugs on some devices.
6566
- The UEFI `allocator::Allocator` has been optimized for page-aligned
6667
allocations.
67-
- The documentation for UEFI device paths has been streamlined and improved.
6868

6969

7070
# uefi - 0.34.1 (2025-02-07)

uefi/src/boot.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -853,12 +853,14 @@ pub fn protocols_per_handle(handle: Handle) -> Result<ProtocolsPerHandle> {
853853
})
854854
}
855855

856-
/// Locates the handle of a device on the device path that supports the specified protocol.
856+
/// Locates the handle of a device on the [`DevicePath`] that supports the
857+
/// specified [`Protocol`].
857858
///
858-
/// The `device_path` is updated to point at the remaining part of the [`DevicePath`] after
859-
/// the part that matched the protocol. For example, it can be used with a device path
860-
/// that contains a file path to strip off the file system portion of the device path,
861-
/// leaving the file path and handle to the file system driver needed to access the file.
859+
/// The `device_path` is updated to point at the remaining part that matched the
860+
/// protocol. For example, this function can be used with a device path that
861+
/// contains a file path to strip off the file system portion of the device
862+
/// path, leaving the file path and handle to the file system driver needed to
863+
/// access the file.
862864
///
863865
/// If the first node of `device_path` matches the protocol, the `device_path`
864866
/// is advanced to the device path terminator node. If `device_path` is a
@@ -959,7 +961,7 @@ pub fn locate_handle_buffer(search_ty: SearchType) -> Result<HandleBuffer> {
959961
})
960962
}
961963

962-
/// Returns all the handles implementing a certain protocol.
964+
/// Returns all the handles implementing a certain [`Protocol`].
963965
///
964966
/// # Errors
965967
///
@@ -1038,7 +1040,7 @@ pub fn get_handle_for_protocol<P: ProtocolPointer + ?Sized>() -> Result<Handle>
10381040
.ok_or_else(|| Status::NOT_FOUND.into())
10391041
}
10401042

1041-
/// Opens a protocol interface for a handle.
1043+
/// Opens a [`Protocol`] interface for a handle.
10421044
///
10431045
/// See also [`open_protocol_exclusive`], which provides a safe subset of this
10441046
/// functionality.
@@ -1101,7 +1103,7 @@ pub unsafe fn open_protocol<P: ProtocolPointer + ?Sized>(
11011103
})
11021104
}
11031105

1104-
/// Opens a protocol interface for a handle in exclusive mode.
1106+
/// Opens a [`Protocol`] interface for a handle in exclusive mode.
11051107
///
11061108
/// If successful, a [`ScopedProtocol`] is returned that will automatically
11071109
/// close the protocol interface when dropped.
@@ -1129,7 +1131,7 @@ pub fn open_protocol_exclusive<P: ProtocolPointer + ?Sized>(
11291131
}
11301132
}
11311133

1132-
/// Tests whether a handle supports a protocol.
1134+
/// Tests whether a handle supports a [`Protocol`].
11331135
///
11341136
/// Returns `Ok(true)` if the handle supports the protocol, `Ok(false)` if not.
11351137
///
@@ -1543,7 +1545,7 @@ impl Deref for ProtocolsPerHandle {
15431545
}
15441546

15451547
/// A buffer returned by [`locate_handle_buffer`] that contains an array of
1546-
/// [`Handle`]s that support the requested protocol.
1548+
/// [`Handle`]s that support the requested [`Protocol`].
15471549
#[derive(Debug, Eq, PartialEq)]
15481550
pub struct HandleBuffer {
15491551
count: usize,
@@ -1564,7 +1566,7 @@ impl Deref for HandleBuffer {
15641566
}
15651567
}
15661568

1567-
/// An open protocol interface. Automatically closes the protocol
1569+
/// An open [`Protocol`] interface. Automatically closes the protocol
15681570
/// interface on drop.
15691571
///
15701572
/// Most protocols have interface data associated with them. `ScopedProtocol`

uefi/src/proto/console/gop.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,13 @@ use uefi_raw::protocol::console::{
6565

6666
pub use uefi_raw::protocol::console::PixelBitmask;
6767

68-
/// Provides access to the video hardware's frame buffer.
68+
/// Graphics Output [`Protocol`] (GOP). Provides access to the video hardware's
69+
/// frame buffer.
6970
///
70-
/// The GOP can be used to set the properties of the frame buffer,
71-
/// and also allows the app to access the in-memory buffer.
71+
/// The GOP can be used to set the properties of the framebuffer, and also
72+
/// allows the app to access the in-memory buffer.
73+
///
74+
/// [`Protocol`]: uefi::proto::Protocol
7275
#[derive(Debug)]
7376
#[repr(transparent)]
7477
#[unsafe_protocol(GraphicsOutputProtocol::GUID)]

uefi/src/proto/console/pointer/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ use crate::proto::unsafe_protocol;
66
use crate::{Event, Result, Status, StatusExt};
77
use uefi_raw::protocol::console::SimplePointerProtocol;
88

9-
/// Provides information about a pointer device.
9+
/// Simple Pointer [`Protocol`]. Provides information about a pointer device.
10+
///
11+
/// Pointer devices are mouses, touchpads, and touchscreens.
12+
///
13+
/// [`Protocol`]: uefi::proto::Protocol
1014
#[derive(Debug)]
1115
#[repr(transparent)]
1216
#[unsafe_protocol(SimplePointerProtocol::GUID)]

uefi/src/proto/console/serial.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ pub use uefi_raw::protocol::console::serial::{
1111
ControlBits, Parity, SerialIoMode as IoMode, StopBits,
1212
};
1313

14-
/// Provides access to a serial I/O device.
14+
/// Serial IO [`Protocol`]. Provides access to a serial I/O device.
1515
///
1616
/// This can include standard UART devices, serial ports over a USB interface,
1717
/// or any other character-based communication device.
1818
///
1919
/// Since UEFI drivers are implemented through polling, if you fail to regularly
2020
/// check for input/output, some data might be lost.
21+
///
22+
/// [`Protocol`]: uefi::proto::Protocol
2123
#[derive(Debug)]
2224
#[repr(transparent)]
2325
#[unsafe_protocol(SerialIoProtocol::GUID)]

uefi/src/proto/console/text/input.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use crate::{Char16, Event, Result, Status, StatusExt};
55
use core::mem::MaybeUninit;
66
use uefi_raw::protocol::console::{InputKey, SimpleTextInputProtocol};
77

8-
/// Interface for text-based input devices.
8+
/// Simple Text Input [`Protocol`]. Interface for text-based input devices.
9+
///
10+
/// [`Protocol`]: uefi::proto::Protocol
911
#[derive(Debug)]
1012
#[repr(transparent)]
1113
#[unsafe_protocol(SimpleTextInputProtocol::GUID)]

uefi/src/proto/console/text/output.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{CStr16, Result, ResultExt, Status, StatusExt};
55
use core::fmt;
66
use uefi_raw::protocol::console::{SimpleTextOutputMode, SimpleTextOutputProtocol};
77

8-
/// Interface for text-based output devices.
8+
/// Simple Text Output [`Protocol`]. Interface for text-based output devices.
99
///
1010
/// It implements the fmt::Write trait, so you can use it to print text with
1111
/// standard Rust constructs like the `write!()` and `writeln!()` macros.
@@ -22,6 +22,7 @@ use uefi_raw::protocol::console::{SimpleTextOutputMode, SimpleTextOutputProtocol
2222
/// [`system::stdout`]: crate::system::with_stdout
2323
/// [`system::stderr`]: crate::system::with_stderr
2424
/// [`boot`]: crate::boot#accessing-protocols
25+
/// [`Protocol`]: uefi::proto::Protocol
2526
#[derive(Debug)]
2627
#[repr(transparent)]
2728
#[unsafe_protocol(SimpleTextOutputProtocol::GUID)]

uefi/src/proto/debug/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ pub use exception::ExceptionType;
2323
mod context;
2424
mod exception;
2525

26+
/// Debug support [`Protocol`].
27+
///
2628
/// The debugging support protocol allows debuggers to connect to a UEFI machine.
2729
/// It is expected that there will typically be two instances of the EFI Debug Support protocol in the system.
2830
/// One associated with the native processor instruction set (IA-32, x64, ARM, RISC-V, or Itanium processor
@@ -31,6 +33,8 @@ mod exception;
3133
/// one for any given instruction set.
3234
///
3335
/// NOTE: OVMF only implements this protocol interface for the virtual EBC processor
36+
///
37+
/// [`Protocol`]: uefi::proto::Protocol
3438
#[derive(Debug)]
3539
#[repr(C)]
3640
#[unsafe_protocol("2755590c-6f3c-42fa-9ea4-a3ba543cda25")]
@@ -178,8 +182,12 @@ pub enum ProcessorArch: u32 => {
178182
RISCV_128 = 0x5128,
179183
}}
180184

185+
/// Debug Port [`Protocol`].
186+
///
181187
/// The debug port protocol abstracts the underlying debug port
182188
/// hardware, whether it is a regular Serial port or something else.
189+
///
190+
/// [`Protocol`]: uefi::proto::Protocol
183191
#[derive(Debug)]
184192
#[repr(C)]
185193
#[unsafe_protocol("eba4e8d2-3858-41ec-a281-2647ba9660d0")]

uefi/src/proto/device_path/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//!
99
//! # Terminology: Device Paths, Device Path Instances, and Device Path Nodes
1010
//! An open UEFI device path [`Protocol`], also called _device path_, is a
11-
//! flexible and structured sequence of binary nodes that describe a route from
11+
//! flexible and structured sequence of binary nodes that describes a route from
1212
//! the UEFI root to a particular device, controller, or file.
1313
//!
1414
//! An entire device path can be made up of multiple device path instances,
@@ -768,12 +768,15 @@ pub enum NodeConversionError {
768768
UnsupportedType,
769769
}
770770

771+
/// Loaded Image Device Path [`Protocol`].
772+
///
771773
/// Protocol for accessing the device path that was passed in to [`load_image`]
772774
/// when loading a PE/COFF image.
773775
///
774776
/// The layout of this type is the same as a [`DevicePath`].
775777
///
776778
/// [`load_image`]: crate::boot::load_image
779+
/// [`Protocol`]: uefi::proto::Protocol
777780
#[repr(transparent)]
778781
#[unsafe_protocol("bc62157e-3e33-4fec-9920-2d3b36d750df")]
779782
#[derive(Debug, Pointee)]

uefi/src/proto/device_path/text.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ pub struct DisplayOnly(pub bool);
4747
#[derive(Clone, Copy, Debug)]
4848
pub struct AllowShortcuts(pub bool);
4949

50+
/// Device Path to Text [`Protocol`].
51+
///
5052
/// Protocol for converting a [`DevicePath`] or `DevicePathNode`] to a string.
53+
///
54+
/// [`Protocol`]: uefi::proto::Protocol
5155
#[derive(Debug)]
5256
#[repr(transparent)]
5357
#[unsafe_protocol(DevicePathToTextProtocol::GUID)]
@@ -99,7 +103,11 @@ impl DevicePathToText {
99103
}
100104
}
101105

106+
/// Device Path from Text [`Protocol`].
107+
///
102108
/// Protocol for converting a string to a [`DevicePath`] or `DevicePathNode`].
109+
///
110+
/// [`Protocol`]: uefi::proto::Protocol
103111
#[derive(Debug)]
104112
#[repr(transparent)]
105113
#[unsafe_protocol("05c99a21-c70f-4ad2-8a5f-35df3343f51e")]

uefi/src/proto/driver/component_name.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use core::fmt::{self, Debug, Display, Formatter};
1313
use core::{ptr, slice};
1414
use uefi_raw::protocol::driver::ComponentName2Protocol;
1515

16+
/// Component Name1 [`Protocol`].
17+
///
1618
/// Protocol that provides human-readable names for a driver and for each of the
1719
/// controllers that the driver is managing.
1820
///
@@ -27,6 +29,7 @@ use uefi_raw::protocol::driver::ComponentName2Protocol;
2729
///
2830
/// [ISO 639-2]: https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes
2931
/// [RFC 4646]: https://www.rfc-editor.org/rfc/rfc4646
32+
/// [`Protocol`]: uefi::proto::Protocol
3033
#[deprecated = "deprecated in UEFI 2.1; use ComponentName2 where possible"]
3134
#[unsafe_protocol(ComponentName2Protocol::DEPRECATED_COMPONENT_NAME_GUID)]
3235
#[derive(Debug)]
@@ -87,6 +90,8 @@ impl ComponentName1 {
8790
}
8891
}
8992

93+
/// Component Name2 [`Protocol`].
94+
///
9095
/// Protocol that provides human-readable names for a driver and for each of the
9196
/// controllers that the driver is managing.
9297
///
@@ -101,6 +106,7 @@ impl ComponentName1 {
101106
///
102107
/// [ISO 639-2]: https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes
103108
/// [RFC 4646]: https://www.rfc-editor.org/rfc/rfc4646
109+
/// [`Protocol`]: uefi::proto::Protocol
104110
#[unsafe_protocol(ComponentName2Protocol::GUID)]
105111
#[derive(Debug)]
106112
#[repr(transparent)]

uefi/src/proto/loaded_image.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ use core::ffi::c_void;
1212
use core::{mem, slice};
1313
use uefi_raw::protocol::loaded_image::LoadedImageProtocol;
1414

15-
/// The LoadedImage protocol. This can be opened on any image handle using the `HandleProtocol` boot service.
15+
/// The Loaded Image [`Protocol`].
16+
///
17+
/// This can be opened on any image handle using [`boot::open_protocol`],
18+
/// for example.
19+
///
20+
/// [`Protocol`]: uefi::proto::Protocol
21+
/// [`boot::open_protocol`]: uefi::boot::open_protocol
1622
#[derive(Debug)]
1723
#[repr(transparent)]
1824
#[unsafe_protocol(LoadedImageProtocol::GUID)]

uefi/src/proto/media/block.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use crate::{Result, StatusExt};
77

88
pub use uefi_raw::protocol::block::{BlockIoProtocol, Lba};
99

10-
/// The Block I/O protocol.
10+
/// Block I/O [`Protocol`].
11+
///
12+
/// [`Protocol`]: uefi::proto::Protocol
1113
#[derive(Debug)]
1214
#[repr(transparent)]
1315
#[unsafe_protocol(BlockIoProtocol::GUID)]

0 commit comments

Comments
 (0)