Skip to content

Commit 6d3751f

Browse files
authored
Merge pull request #694 from nicholasbishop/bishop-remove-more-boot-param
Remove some more protocol lifetime parameters
2 parents 905c176 + b930450 commit 6d3751f

File tree

4 files changed

+32
-21
lines changed

4 files changed

+32
-21
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
- `HandleBuffer` and `ProtocolsPerHandle` now implement `Deref`. The
2121
`HandleBuffer::handles` and `ProtocolsPerHandle::protocols` methods have been
2222
deprecated.
23-
- Removed `'boot` lifetime from the `Output` protocol.
23+
- Removed `'boot` lifetime from the `GraphicsOutput`, `Output`, `Pointer`, and
24+
`Serial` protocols.
2425
- The generic type `Data` of `uefi::Error<Data: Debug>` doesn't need to be
2526
`Display` to be compatible with `core::error::Error`. Note that the error
2627
Trait requires the `unstable` feature.

uefi/src/proto/console/gop.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ use core::ptr;
6363
/// and also allows the app to access the in-memory buffer.
6464
#[repr(C)]
6565
#[unsafe_protocol("9042a9de-23dc-4a38-96fb-7aded080516a")]
66-
pub struct GraphicsOutput<'boot> {
66+
pub struct GraphicsOutput {
6767
query_mode: extern "efiapi" fn(
6868
&GraphicsOutput,
6969
mode: u32,
@@ -84,10 +84,10 @@ pub struct GraphicsOutput<'boot> {
8484
height: usize,
8585
stride: usize,
8686
) -> Status,
87-
mode: &'boot ModeData<'boot>,
87+
mode: *const ModeData,
8888
}
8989

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

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

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

308308
FrameBuffer {
309309
base,
310310
size,
311311
_lifetime: PhantomData,
312312
}
313313
}
314+
315+
const fn mode(&self) -> &ModeData {
316+
unsafe { &*self.mode }
317+
}
314318
}
315319

316320
#[repr(C)]
317-
struct ModeData<'info> {
321+
struct ModeData {
318322
// Number of modes which the GOP supports.
319323
max_mode: u32,
320324
// Current mode.
321325
mode: u32,
322326
// Information about the current mode.
323-
info: &'info ModeInfo,
327+
info: *const ModeInfo,
324328
// Size of the above structure.
325329
info_sz: usize,
326330
// Physical address of the frame buffer.
@@ -329,6 +333,12 @@ struct ModeData<'info> {
329333
fb_size: usize,
330334
}
331335

336+
impl ModeData {
337+
const fn info(&self) -> &ModeInfo {
338+
unsafe { &*self.info }
339+
}
340+
}
341+
332342
/// Represents the format of the pixels in a frame buffer.
333343
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
334344
#[repr(u32)]
@@ -436,7 +446,7 @@ impl ModeInfo {
436446

437447
/// Iterator for [`Mode`]s of the [`GraphicsOutput`] protocol.
438448
pub struct ModeIter<'gop> {
439-
gop: &'gop GraphicsOutput<'gop>,
449+
gop: &'gop GraphicsOutput,
440450
current: u32,
441451
max: u32,
442452
}

uefi/src/proto/console/pointer/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ use core::mem::MaybeUninit;
77
/// Provides information about a pointer device.
88
#[repr(C)]
99
#[unsafe_protocol("31878c87-0b75-11d5-9a4f-0090273fc14d")]
10-
pub struct Pointer<'boot> {
10+
pub struct Pointer {
1111
reset: extern "efiapi" fn(this: &mut Pointer, ext_verif: bool) -> Status,
1212
get_state: extern "efiapi" fn(this: &Pointer, state: *mut PointerState) -> Status,
1313
wait_for_input: Event,
14-
mode: &'boot PointerMode,
14+
mode: *const PointerMode,
1515
}
1616

17-
impl<'boot> Pointer<'boot> {
17+
impl Pointer {
1818
/// Resets the pointer device hardware.
1919
///
2020
/// The `extended_verification` parameter is used to request that UEFI
@@ -54,7 +54,7 @@ impl<'boot> Pointer<'boot> {
5454
/// Returns a reference to the pointer device information.
5555
#[must_use]
5656
pub const fn mode(&self) -> &PointerMode {
57-
self.mode
57+
unsafe { &*self.mode }
5858
}
5959
}
6060

uefi/src/proto/console/serial.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use bitflags::bitflags;
1515
/// check for input/output, some data might be lost.
1616
#[repr(C)]
1717
#[unsafe_protocol("bb25cf6f-f1d4-11d2-9a0c-0090273fc1fd")]
18-
pub struct Serial<'boot> {
18+
pub struct Serial {
1919
// Revision of this protocol, only 1.0 is currently defined.
2020
// Future versions will be backwards compatible.
2121
revision: u32,
@@ -33,10 +33,10 @@ pub struct Serial<'boot> {
3333
get_control_bits: extern "efiapi" fn(&Serial, &mut ControlBits) -> Status,
3434
write: unsafe extern "efiapi" fn(&mut Serial, &mut usize, *const u8) -> Status,
3535
read: unsafe extern "efiapi" fn(&mut Serial, &mut usize, *mut u8) -> Status,
36-
io_mode: &'boot IoMode,
36+
io_mode: *const IoMode,
3737
}
3838

39-
impl<'boot> Serial<'boot> {
39+
impl Serial {
4040
/// Reset the device.
4141
pub fn reset(&mut self) -> Result {
4242
(self.reset)(self).into()
@@ -45,7 +45,7 @@ impl<'boot> Serial<'boot> {
4545
/// Returns the current I/O mode.
4646
#[must_use]
4747
pub const fn io_mode(&self) -> &IoMode {
48-
self.io_mode
48+
unsafe { &*self.io_mode }
4949
}
5050

5151
/// Sets the device's new attributes.
@@ -115,7 +115,7 @@ impl<'boot> Serial<'boot> {
115115
}
116116
}
117117

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

0 commit comments

Comments
 (0)