Skip to content

Remove some more protocol lifetime parameters #694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
- `HandleBuffer` and `ProtocolsPerHandle` now implement `Deref`. The
`HandleBuffer::handles` and `ProtocolsPerHandle::protocols` methods have been
deprecated.
- Removed `'boot` lifetime from the `Output` protocol.
- Removed `'boot` lifetime from the `GraphicsOutput`, `Output`, `Pointer`, and
`Serial` protocols.
- The generic type `Data` of `uefi::Error<Data: Debug>` doesn't need to be
`Display` to be compatible with `core::error::Error`. Note that the error
Trait requires the `unstable` feature.
Expand Down
32 changes: 21 additions & 11 deletions uefi/src/proto/console/gop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ use core::ptr;
/// and also allows the app to access the in-memory buffer.
#[repr(C)]
#[unsafe_protocol("9042a9de-23dc-4a38-96fb-7aded080516a")]
pub struct GraphicsOutput<'boot> {
pub struct GraphicsOutput {
query_mode: extern "efiapi" fn(
&GraphicsOutput,
mode: u32,
Expand All @@ -84,10 +84,10 @@ pub struct GraphicsOutput<'boot> {
height: usize,
stride: usize,
) -> Status,
mode: &'boot ModeData<'boot>,
mode: *const ModeData,
}

impl<'boot> GraphicsOutput<'boot> {
impl GraphicsOutput {
/// Returns information for an available graphics mode that the graphics
/// device and the set of active video output devices supports.
pub fn query_mode(&self, index: u32) -> Result<Mode> {
Expand All @@ -110,7 +110,7 @@ impl<'boot> GraphicsOutput<'boot> {
ModeIter {
gop: self,
current: 0,
max: self.mode.max_mode,
max: self.mode().max_mode,
}
}

Expand Down Expand Up @@ -293,34 +293,38 @@ impl<'boot> GraphicsOutput<'boot> {
/// Returns the frame buffer information for the current mode.
#[must_use]
pub const fn current_mode_info(&self) -> ModeInfo {
*self.mode.info
*self.mode().info()
}

/// Access the frame buffer directly
pub fn frame_buffer(&mut self) -> FrameBuffer {
assert!(
self.mode.info.format != PixelFormat::BltOnly,
self.mode().info().format != PixelFormat::BltOnly,
"Cannot access the framebuffer in a Blt-only mode"
);
let base = self.mode.fb_address as *mut u8;
let size = self.mode.fb_size;
let base = self.mode().fb_address as *mut u8;
let size = self.mode().fb_size;

FrameBuffer {
base,
size,
_lifetime: PhantomData,
}
}

const fn mode(&self) -> &ModeData {
unsafe { &*self.mode }
}
}

#[repr(C)]
struct ModeData<'info> {
struct ModeData {
// Number of modes which the GOP supports.
max_mode: u32,
// Current mode.
mode: u32,
// Information about the current mode.
info: &'info ModeInfo,
info: *const ModeInfo,
// Size of the above structure.
info_sz: usize,
// Physical address of the frame buffer.
Expand All @@ -329,6 +333,12 @@ struct ModeData<'info> {
fb_size: usize,
}

impl ModeData {
const fn info(&self) -> &ModeInfo {
unsafe { &*self.info }
}
}

/// Represents the format of the pixels in a frame buffer.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[repr(u32)]
Expand Down Expand Up @@ -436,7 +446,7 @@ impl ModeInfo {

/// Iterator for [`Mode`]s of the [`GraphicsOutput`] protocol.
pub struct ModeIter<'gop> {
gop: &'gop GraphicsOutput<'gop>,
gop: &'gop GraphicsOutput,
current: u32,
max: u32,
}
Expand Down
8 changes: 4 additions & 4 deletions uefi/src/proto/console/pointer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use core::mem::MaybeUninit;
/// Provides information about a pointer device.
#[repr(C)]
#[unsafe_protocol("31878c87-0b75-11d5-9a4f-0090273fc14d")]
pub struct Pointer<'boot> {
pub struct Pointer {
reset: extern "efiapi" fn(this: &mut Pointer, ext_verif: bool) -> Status,
get_state: extern "efiapi" fn(this: &Pointer, state: *mut PointerState) -> Status,
wait_for_input: Event,
mode: &'boot PointerMode,
mode: *const PointerMode,
}

impl<'boot> Pointer<'boot> {
impl Pointer {
/// Resets the pointer device hardware.
///
/// The `extended_verification` parameter is used to request that UEFI
Expand Down Expand Up @@ -54,7 +54,7 @@ impl<'boot> Pointer<'boot> {
/// Returns a reference to the pointer device information.
#[must_use]
pub const fn mode(&self) -> &PointerMode {
self.mode
unsafe { &*self.mode }
}
}

Expand Down
10 changes: 5 additions & 5 deletions uefi/src/proto/console/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use bitflags::bitflags;
/// check for input/output, some data might be lost.
#[repr(C)]
#[unsafe_protocol("bb25cf6f-f1d4-11d2-9a0c-0090273fc1fd")]
pub struct Serial<'boot> {
pub struct Serial {
// Revision of this protocol, only 1.0 is currently defined.
// Future versions will be backwards compatible.
revision: u32,
Expand All @@ -33,10 +33,10 @@ pub struct Serial<'boot> {
get_control_bits: extern "efiapi" fn(&Serial, &mut ControlBits) -> Status,
write: unsafe extern "efiapi" fn(&mut Serial, &mut usize, *const u8) -> Status,
read: unsafe extern "efiapi" fn(&mut Serial, &mut usize, *mut u8) -> Status,
io_mode: &'boot IoMode,
io_mode: *const IoMode,
}

impl<'boot> Serial<'boot> {
impl Serial {
/// Reset the device.
pub fn reset(&mut self) -> Result {
(self.reset)(self).into()
Expand All @@ -45,7 +45,7 @@ impl<'boot> Serial<'boot> {
/// Returns the current I/O mode.
#[must_use]
pub const fn io_mode(&self) -> &IoMode {
self.io_mode
unsafe { &*self.io_mode }
}

/// Sets the device's new attributes.
Expand Down Expand Up @@ -115,7 +115,7 @@ impl<'boot> Serial<'boot> {
}
}

impl<'boot> Write for Serial<'boot> {
impl Write for Serial {
fn write_str(&mut self, s: &str) -> core::fmt::Result {
self.write(s.as_bytes()).map_err(|_| core::fmt::Error)
}
Expand Down