Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2a89253

Browse files
authored
BootServices::set_timer wrapper (#124)
1 parent 055cc9d commit 2a89253

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

‎src/table/boot.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ pub struct BootServices {
4848
notify_ctx: *mut c_void,
4949
event: *mut Event,
5050
) -> Status,
51-
set_timer: usize,
51+
set_timer: unsafe extern "efiapi" fn(
52+
event: Event,
53+
ty: u32,
54+
trigger_time: u64
55+
) -> Status,
5256
wait_for_event: unsafe extern "efiapi" fn(
5357
number_of_events: usize,
5458
events: *mut Event,
@@ -346,6 +350,16 @@ impl BootServices {
346350
)
347351
}
348352

353+
/// Sets the trigger for `EventType::TIMER` event.
354+
pub fn set_timer(&self, event: Event, trigger_time: TimerTrigger) -> Result {
355+
let (ty, time) = match trigger_time {
356+
TimerTrigger::Cancel => (0, 0),
357+
TimerTrigger::Periodic(hundreds_ns) => (1, hundreds_ns),
358+
TimerTrigger::Relative(hundreds_ns) => (2, hundreds_ns),
359+
};
360+
unsafe { (self.set_timer)(event, ty, time) }.into()
361+
}
362+
349363
/// Query a handle for a certain protocol.
350364
///
351365
/// This function attempts to get the protocol implementation of a handle,
@@ -805,3 +819,17 @@ bitflags! {
805819

806820
/// Raw event notification function
807821
type EventNotifyFn = unsafe extern "efiapi" fn(event: Event, context: *mut c_void);
822+
823+
/// Timer events manipulation
824+
pub enum TimerTrigger {
825+
/// Cancel event's timer
826+
Cancel,
827+
/// The event is to be signaled periodically.
828+
/// Parameter is the period in 100ns units.
829+
/// Delay of 0 will be signalled on every timer tick.
830+
Periodic(u64),
831+
/// The event is to be signaled once in 100ns units.
832+
/// Parameter is the delay in 100ns units.
833+
/// Delay of 0 will be signalled on next timer tick.
834+
Relative(u64),
835+
}

‎uefi-test-runner/src/boot/misc.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use uefi::prelude::*;
2-
use uefi::table::boot::BootServices;
2+
use uefi::table::boot::{BootServices,EventType,Tpl,TimerTrigger};
33

44
pub fn test(bt: &BootServices) {
5+
info!("Testing timer...");
6+
test_timer(bt);
7+
info!("Testing watchdog...");
58
test_watchdog(bt);
69
}
710

@@ -10,3 +13,13 @@ fn test_watchdog(bt: &BootServices) {
1013
bt.set_watchdog_timer(0, 0x10000, None)
1114
.expect_success("Could not set watchdog timer");
1215
}
16+
17+
fn test_timer(bt: &BootServices) {
18+
let timer_event = unsafe { bt.create_event(EventType::TIMER, Tpl::APPLICATION, None) }
19+
.expect_success("Failed to create TIMER event");
20+
let mut events = [timer_event];
21+
bt.set_timer(timer_event, TimerTrigger::Relative(5_0/*00 ns */))
22+
.expect_success("Failed to set timer");
23+
bt.wait_for_event(&mut events)
24+
.expect_success("Wait for event failed");
25+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /