Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/uefi/src/proto/mod.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers 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 34 pub mod acpi; 35 #[cfg(feature = "alloc")] 36 pub mod ata; 37 pub mod console; 38 pub mod debug; 39 pub mod device_path; 40 pub mod dma; 41 pub mod driver; 42 pub mod hii; 43 pub mod loaded_image; 44 pub mod media; 45 pub mod misc; 46 pub mod network; 47 #[cfg(feature = "alloc")] 48 pub mod nvme; 49 pub mod pci; 50 pub mod pi; 51 pub mod rng; 52 #[cfg(feature = "alloc")] 53 pub mod scsi; 54 pub mod security; 55 pub mod shell; 56 pub mod shell_params; 57 pub mod shim; 58 pub mod string; 59 pub mod tcg; 60 pub mod usb; 61 62 mod boot_policy; 63 64 pub use boot_policy::BootPolicy; 65 pub use uefi_macros::unsafe_protocol; 66 67 use crate::Identify; 68 use core::ffi::c_void; 69 70 #[cfg(doc)] 71 use 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 96 pub 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. 103 pub 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 119 impl
ProtocolPointer for P
120 where
121 P: Protocol,
122 {
123 unsafe fn ptr_from_ffi(ptr: *const c_void) -> *const Self {
124 ptr.cast::