From 55d62eddaa40c3836dcf838fc9db7e22f49e7465 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Wed, 22 Jan 2025 21:17:16 -0500 Subject: [PATCH 1/2] uefi-raw: Add TimerDelay and use it in BootServices::set_timer --- uefi-raw/CHANGELOG.md | 5 +++++ uefi-raw/src/table/boot.rs | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/uefi-raw/CHANGELOG.md b/uefi-raw/CHANGELOG.md index d256721af..5cd2242de 100644 --- a/uefi-raw/CHANGELOG.md +++ b/uefi-raw/CHANGELOG.md @@ -10,6 +10,11 @@ - Added `HiiDatabaseProtocol`. - Added `ScsiIoProtocol`. - Added `Default` and other common impls for HTTP types. +- Added `boot::TimerDelay`. + +## Changed +- The definition of `BootServices::set_timer` now uses `TimerDelay` rather than + a plain integer. # uefi-raw - 0.9.0 (2024-10-23) diff --git a/uefi-raw/src/table/boot.rs b/uefi-raw/src/table/boot.rs index 8559a4c28..1dc76b67c 100644 --- a/uefi-raw/src/table/boot.rs +++ b/uefi-raw/src/table/boot.rs @@ -47,7 +47,8 @@ pub struct BootServices { notify_ctx: *mut c_void, out_event: *mut Event, ) -> Status, - pub set_timer: unsafe extern "efiapi" fn(event: Event, ty: u32, trigger_time: u64) -> Status, + pub set_timer: + unsafe extern "efiapi" fn(event: Event, ty: TimerDelay, trigger_time: u64) -> Status, pub wait_for_event: unsafe extern "efiapi" fn( number_of_events: usize, events: *mut Event, @@ -484,3 +485,11 @@ pub enum Tpl: usize => { /// Note that this is not necessarily the processor's page size. The UEFI page /// size is always 4 KiB. pub const PAGE_SIZE: usize = 4096; + +newtype_enum! { + pub enum TimerDelay: i32 => { + CANCEL = 0, + PERIODIC = 1, + RELATIVE = 2, + } +} From 83bc8fcd508f32d057213487ed5a62f32d270e52 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Wed, 22 Jan 2025 21:21:53 -0500 Subject: [PATCH 2/2] relicensing: Rewrite PR "Added BootServices::set_timer()" This covers these commits: 2a892538bc9bd43f6041e06018ba43f674a8d975 --- uefi/src/boot.rs | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/uefi/src/boot.rs b/uefi/src/boot.rs index 48acb6aaf..4b5c880f5 100644 --- a/uefi/src/boot.rs +++ b/uefi/src/boot.rs @@ -42,7 +42,7 @@ use core::ops::{Deref, DerefMut}; use core::ptr::{self, NonNull}; use core::sync::atomic::{AtomicPtr, Ordering}; use core::{mem, slice}; -use uefi_raw::table::boot::InterfaceType; +use uefi_raw::table::boot::{InterfaceType, TimerDelay}; #[cfg(feature = "alloc")] use {alloc::vec::Vec, uefi::ResultExt}; @@ -472,9 +472,9 @@ pub fn set_timer(event: &Event, trigger_time: TimerTrigger) -> Result { let bt = unsafe { bt.as_ref() }; let (ty, time) = match trigger_time { - TimerTrigger::Cancel => (0, 0), - TimerTrigger::Periodic(hundreds_ns) => (1, hundreds_ns), - TimerTrigger::Relative(hundreds_ns) => (2, hundreds_ns), + TimerTrigger::Cancel => (TimerDelay::CANCEL, 0), + TimerTrigger::Periodic(period) => (TimerDelay::PERIODIC, period), + TimerTrigger::Relative(delay) => (TimerDelay::RELATIVE, delay), }; unsafe { (bt.set_timer)(event.as_ptr(), ty, time) }.to_result() } @@ -1688,19 +1688,29 @@ impl SearchType<'_> { /// Event notification callback type. pub type EventNotifyFn = unsafe extern "efiapi" fn(event: Event, context: Option>); -/// Timer events manipulation. +/// Trigger type for events of type [`TIMER`]. +/// +/// See [`set_timer`]. +/// +/// [`TIMER`]: EventType::TIMER #[derive(Debug)] pub enum TimerTrigger { - /// Cancel event's timer + /// Remove the event's timer setting. Cancel, - /// The event is to be signaled periodically. - /// Parameter is the period in 100ns units. - /// Delay of 0 will be signalled on every timer tick. - Periodic(u64), - /// The event is to be signaled once in 100ns units. - /// Parameter is the delay in 100ns units. - /// Delay of 0 will be signalled on next timer tick. - Relative(u64), + + /// Trigger the event periodically. + Periodic( + /// Duration between event signaling in units of 100ns. If set to zero, + /// the event will be signaled on every timer tick. + u64, + ), + + /// Trigger the event one time. + Relative( + /// Duration to wait before signaling the event in units of 100ns. If + /// set to zero, the event will be signaled on the next timer tick. + u64, + ), } /// Opaque pointer returned by [`register_protocol_notify`] to be used