Skip to content
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

relicensing: Rewrite set_timer PR #1524

Merged
merged 2 commits into from
Jan 23, 2025
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
5 changes: 5 additions & 0 deletions uefi-raw/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion uefi-raw/src/table/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
}
38 changes: 24 additions & 14 deletions uefi/src/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -1688,19 +1688,29 @@ impl SearchType<'_> {
/// Event notification callback type.
pub type EventNotifyFn = unsafe extern "efiapi" fn(event: Event, context: Option<NonNull<c_void>>);

/// 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
Expand Down
Loading