interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / vendor / uefi / src / proto / mod.rs

130 lines · 3736 bytes Raw Blame History
1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3//! High-level wrappers for [UEFI protocols].
4//!
5//! # TL;DR
6//! Technically, a protocol is a `C` struct holding functions and/or data, with
7//! an associated [`GUID`].
8//!
9//! # Overview
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
25//!
26//! # More Info
27//! - See the [`boot`] documentation for details of how to open a protocol.
28//! - Please find additional low-level information in the
29//! [protocol section of `uefi-raw`][[UEFI protocols]].
30//!
31//! [`boot`]: crate::boot#accessing-protocols
32//! [UEFI protocols]: uefi_raw::protocol
33
34pub mod acpi;
35#[cfg(feature = "alloc")]
36pub mod ata;
37pub mod console;
38pub mod debug;
39pub mod device_path;
40pub mod dma;
41pub mod driver;
42pub mod hii;
43pub mod loaded_image;
44pub mod media;
45pub mod misc;
46pub mod network;
47#[cfg(feature = "alloc")]
48pub mod nvme;
49pub mod pci;
50pub mod pi;
51pub mod rng;
52#[cfg(feature = "alloc")]
53pub mod scsi;
54pub mod security;
55pub mod shell;
56pub mod shell_params;
57pub mod shim;
58pub mod string;
59pub mod tcg;
60pub mod usb;
61
62mod boot_policy;
63
64pub use boot_policy::BootPolicy;
65pub use uefi_macros::unsafe_protocol;
66
67use crate::Identify;
68use core::ffi::c_void;
69
70#[cfg(doc)]
71use crate::boot;
72
73/// Marker trait for structures that represent [UEFI protocols].
74///
75/// Implementing this trait allows a protocol to be opened with
76/// [`boot::open_protocol`] or [`boot::open_protocol_exclusive`]. Note that
77/// implementing this trait does not automatically install a protocol. To
78/// install a protocol, call [`boot::install_protocol_interface`].
79///
80/// As a convenience, you can derive the `Protocol` trait and specify the
81/// protocol's GUID using the [`unsafe_protocol`] macro.
82///
83/// # Example
84///
85/// ```
86/// use uefi::{Identify, guid};
87/// use uefi::proto::unsafe_protocol;
88///
89/// #[unsafe_protocol("12345678-9abc-def0-1234-56789abcdef0")]
90/// struct ExampleProtocol {}
91///
92/// assert_eq!(ExampleProtocol::GUID, guid!("12345678-9abc-def0-1234-56789abcdef0"));
93/// ```
94///
95/// [UEFI protocols]: uefi_raw::protocol
96pub trait Protocol: Identify {}
97
98/// Trait for creating a [`Protocol`] pointer from a [`c_void`] pointer.
99///
100/// There is a blanket implementation for all [`Sized`] protocols that
101/// simply casts the pointer to the appropriate type. Protocols that
102/// are not sized must provide a custom implementation.
103pub trait ProtocolPointer: Protocol {
104 /// Create a const pointer to a [`Protocol`] from a [`c_void`] pointer.
105 ///
106 /// # Safety
107 ///
108 /// The input pointer must point to valid data.
109 unsafe fn ptr_from_ffi(ptr: *const c_void) -> *const Self;
110
111 /// Create a mutable pointer to a [`Protocol`] from a [`c_void`] pointer.
112 ///
113 /// # Safety
114 ///
115 /// The input pointer must point to valid data.
116 unsafe fn mut_ptr_from_ffi(ptr: *mut c_void) -> *mut Self;
117}
118
119impl<P> ProtocolPointer for P
120where
121 P: Protocol,
122{
123 unsafe fn ptr_from_ffi(ptr: *const c_void) -> *const Self {
124 ptr.cast::<Self>()
125 }
126
127 unsafe fn mut_ptr_from_ffi(ptr: *mut c_void) -> *mut Self {
128 ptr.cast::<Self>()
129 }
130}