Skip to content

Commit c417fbc

Browse files
Merge pull request #1877 from rust-osdev/improve-handles-doc
uefi: boot: improve documentation for handles
2 parents 2f10a86 + 8b84011 commit c417fbc

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

uefi/src/boot.rs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
//!
55
//! These functions will panic if called after exiting boot services.
66
//!
7-
//! # Accessing protocols
7+
//! # Accessing Protocols
88
//!
9-
//! Protocols can be opened using several functions in this module. Most
10-
//! commonly, [`open_protocol_exclusive`] should be used. This ensures that
11-
//! nothing else can use the protocol until it is closed, and returns a
12-
//! [`ScopedProtocol`] that takes care of closing the protocol when it is
13-
//! dropped.
9+
//! Protocols in this module can be opened through multiple functions. In most
10+
//! cases, [`open_protocol_exclusive`] is the recommended choice. It opens the
11+
//! protocol with exclusive access, preventing concurrent use until it is
12+
//! closed, and returns a [`ScopedProtocol`] that automatically releases the
13+
//! protocol when dropped. Note that this approach has certain caveats; refer to
14+
//! the documentation of the respective function for details.
1415
//!
1516
//! Other methods for opening protocols:
1617
//!
@@ -19,6 +20,11 @@
1920
//!
2021
//! For protocol definitions, see the [`proto`] module.
2122
//!
23+
//! # Accessing Handles
24+
//!
25+
//! To access handles supporting a certain protocol, we recommend using
26+
//! [`find_handles`], [`locate_handle`], and [`locate_handle_buffer`].
27+
//!
2228
//! [`proto`]: crate::proto
2329
2430
pub use uefi_raw::table::boot::{
@@ -893,7 +899,12 @@ pub fn locate_device_path<P: ProtocolPointer + ?Sized>(
893899
}
894900
}
895901

896-
/// Enumerates all handles installed on the system which match a certain query.
902+
/// Enumerates all [`Handle`]s installed on the system which match a certain
903+
/// query.
904+
///
905+
/// If you use the `alloc` feature, it might be more convenient to use
906+
/// [`find_handles`] instead. Another alternative might be
907+
/// [`locate_handle_buffer`].
897908
///
898909
/// # Errors
899910
///
@@ -939,6 +950,10 @@ pub fn locate_handle<'buf>(
939950
///
940951
/// See [`SearchType`] for details of the available search operations.
941952
///
953+
/// Unlike [`find_handles`], this doesn't need the `alloc` feature and operates
954+
/// on the UEFI heap directly. Further, it allows a more fine-grained search
955+
/// via the provided [`SearchType`].
956+
///
942957
/// # Errors
943958
///
944959
/// * [`Status::NOT_FOUND`]: no matching handles.
@@ -1112,6 +1127,11 @@ pub unsafe fn open_protocol<P: ProtocolPointer + ?Sized>(
11121127
/// If successful, a [`ScopedProtocol`] is returned that will automatically
11131128
/// close the protocol interface when dropped.
11141129
///
1130+
/// Note that if any other drivers currently have the protocol interface opened
1131+
/// with the [`OpenProtocolAttributes::ByDriver`] attribute, they will be
1132+
/// disconnected via [`disconnect_controller`]. For example, opening the
1133+
/// SERIAL_IO_PROTOCOL exclusively will disconnect the console driver from it.
1134+
///
11151135
/// # Errors
11161136
///
11171137
/// * [`Status::UNSUPPORTED`]: the handle does not support the protocol.
@@ -1548,8 +1568,8 @@ impl Deref for ProtocolsPerHandle {
15481568
}
15491569
}
15501570

1551-
/// A buffer returned by [`locate_handle_buffer`] that contains an array of
1552-
/// [`Handle`]s that support the requested [`Protocol`].
1571+
/// A buffer on the UEFI heap returned by [`locate_handle_buffer`] that contains
1572+
/// an array of [`Handle`]s that support the requested [`Protocol`].
15531573
#[derive(Debug, Eq, PartialEq)]
15541574
pub struct HandleBuffer {
15551575
count: usize,

0 commit comments

Comments
 (0)