1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
//! Protocol definitions.
//!
//! Protocols are sets of related functionality identified by a unique
//! ID. They can be implemented by a UEFI driver or occasionally by a
//! UEFI application.
//!
//! See the [`BootServices`] documentation for details of how to open a
//! protocol.
//!
//! [`BootServices`]: crate::table::boot::BootServices#accessing-protocols
use crate::Identify;
use core::ffi::c_void;
/// Common trait implemented by all standard UEFI protocols
///
/// According to the UEFI's specification, protocols are `!Send` (they expect to
/// be run on the bootstrap processor) and `!Sync` (they are not thread-safe).
/// You can derive the `Protocol` trait, add these bounds and specify the
/// protocol's GUID using the following syntax:
///
/// ```
/// #![feature(negative_impls)]
/// use uefi::{proto::Protocol, unsafe_guid};
/// #[unsafe_guid("12345678-9abc-def0-1234-56789abcdef0")]
/// #[derive(Protocol)]
/// struct DummyProtocol {}
/// ```
pub trait Protocol: Identify {}
/// Trait for creating a protocol pointer from a [`c_void`] pointer.
///
/// There is a blanket implementation for all [`Sized`] protocols that
/// simply casts the pointer to the appropriate type. Protocols that
/// are not sized must provide a custom implementation.
pub trait ProtocolPointer: Protocol {
/// Create a const pointer to a [`Protocol`] from a [`c_void`] pointer.
///
/// # Safety
///
/// The input pointer must point to valid data.
unsafe fn ptr_from_ffi(ptr: *const c_void) -> *const Self;
/// Create a mutable pointer to a [`Protocol`] from a [`c_void`] pointer.
///
/// # Safety
///
/// The input pointer must point to valid data.
unsafe fn mut_ptr_from_ffi(ptr: *mut c_void) -> *mut Self;
}
impl<P> ProtocolPointer for P
where
P: Protocol,
{
unsafe fn ptr_from_ffi(ptr: *const c_void) -> *const Self {
ptr.cast::<Self>()
}
unsafe fn mut_ptr_from_ffi(ptr: *mut c_void) -> *mut Self {
ptr.cast::<Self>()
}
}
pub use uefi_macros::Protocol;
pub mod console;
pub mod debug;
pub mod device_path;
pub mod loaded_image;
pub mod media;
pub mod network;
pub mod pi;
pub mod rng;
pub mod shim;