Skip to content

Commit d8567b9

Browse files
authored
Merge pull request #1524 from nicholasbishop/bishop-rewrite-set-timer
relicensing: Rewrite set_timer PR
2 parents 5fa380f + 83bc8fc commit d8567b9

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

uefi-raw/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
- Added `HiiDatabaseProtocol`.
1111
- Added `ScsiIoProtocol`.
1212
- Added `Default` and other common impls for HTTP types.
13+
- Added `boot::TimerDelay`.
14+
15+
## Changed
16+
- The definition of `BootServices::set_timer` now uses `TimerDelay` rather than
17+
a plain integer.
1318

1419

1520
# uefi-raw - 0.9.0 (2024-10-23)

uefi-raw/src/table/boot.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ pub struct BootServices {
4747
notify_ctx: *mut c_void,
4848
out_event: *mut Event,
4949
) -> Status,
50-
pub set_timer: unsafe extern "efiapi" fn(event: Event, ty: u32, trigger_time: u64) -> Status,
50+
pub set_timer:
51+
unsafe extern "efiapi" fn(event: Event, ty: TimerDelay, trigger_time: u64) -> Status,
5152
pub wait_for_event: unsafe extern "efiapi" fn(
5253
number_of_events: usize,
5354
events: *mut Event,
@@ -484,3 +485,11 @@ pub enum Tpl: usize => {
484485
/// Note that this is not necessarily the processor's page size. The UEFI page
485486
/// size is always 4 KiB.
486487
pub const PAGE_SIZE: usize = 4096;
488+
489+
newtype_enum! {
490+
pub enum TimerDelay: i32 => {
491+
CANCEL = 0,
492+
PERIODIC = 1,
493+
RELATIVE = 2,
494+
}
495+
}

uefi/src/boot.rs

+24-14
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use core::ops::{Deref, DerefMut};
4242
use core::ptr::{self, NonNull};
4343
use core::sync::atomic::{AtomicPtr, Ordering};
4444
use core::{mem, slice};
45-
use uefi_raw::table::boot::InterfaceType;
45+
use uefi_raw::table::boot::{InterfaceType, TimerDelay};
4646
#[cfg(feature = "alloc")]
4747
use {alloc::vec::Vec, uefi::ResultExt};
4848

@@ -472,9 +472,9 @@ pub fn set_timer(event: &Event, trigger_time: TimerTrigger) -> Result {
472472
let bt = unsafe { bt.as_ref() };
473473

474474
let (ty, time) = match trigger_time {
475-
TimerTrigger::Cancel => (0, 0),
476-
TimerTrigger::Periodic(hundreds_ns) => (1, hundreds_ns),
477-
TimerTrigger::Relative(hundreds_ns) => (2, hundreds_ns),
475+
TimerTrigger::Cancel => (TimerDelay::CANCEL, 0),
476+
TimerTrigger::Periodic(period) => (TimerDelay::PERIODIC, period),
477+
TimerTrigger::Relative(delay) => (TimerDelay::RELATIVE, delay),
478478
};
479479
unsafe { (bt.set_timer)(event.as_ptr(), ty, time) }.to_result()
480480
}
@@ -1688,19 +1688,29 @@ impl SearchType<'_> {
16881688
/// Event notification callback type.
16891689
pub type EventNotifyFn = unsafe extern "efiapi" fn(event: Event, context: Option<NonNull<c_void>>);
16901690

1691-
/// Timer events manipulation.
1691+
/// Trigger type for events of type [`TIMER`].
1692+
///
1693+
/// See [`set_timer`].
1694+
///
1695+
/// [`TIMER`]: EventType::TIMER
16921696
#[derive(Debug)]
16931697
pub enum TimerTrigger {
1694-
/// Cancel event's timer
1698+
/// Remove the event's timer setting.
16951699
Cancel,
1696-
/// The event is to be signaled periodically.
1697-
/// Parameter is the period in 100ns units.
1698-
/// Delay of 0 will be signalled on every timer tick.
1699-
Periodic(u64),
1700-
/// The event is to be signaled once in 100ns units.
1701-
/// Parameter is the delay in 100ns units.
1702-
/// Delay of 0 will be signalled on next timer tick.
1703-
Relative(u64),
1700+
1701+
/// Trigger the event periodically.
1702+
Periodic(
1703+
/// Duration between event signaling in units of 100ns. If set to zero,
1704+
/// the event will be signaled on every timer tick.
1705+
u64,
1706+
),
1707+
1708+
/// Trigger the event one time.
1709+
Relative(
1710+
/// Duration to wait before signaling the event in units of 100ns. If
1711+
/// set to zero, the event will be signaled on the next timer tick.
1712+
u64,
1713+
),
17041714
}
17051715

17061716
/// Opaque pointer returned by [`register_protocol_notify`] to be used

0 commit comments

Comments
 (0)