Skip to content

Commit 87ab019

Browse files
Merge pull request #1659 from fox0/main
uefi: use Duration for boot::stall
2 parents d24e96c + 6a77e28 commit 87ab019

File tree

9 files changed

+25
-12
lines changed

9 files changed

+25
-12
lines changed

uefi-test-runner/examples/hello_world.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// ANCHOR_END: features
88

99
// ANCHOR: use
10+
use core::time::Duration;
1011
use log::info;
1112
use uefi::prelude::*;
1213
// ANCHOR_END: use
@@ -20,7 +21,7 @@ fn main() -> Status {
2021
// ANCHOR_END: services
2122
// ANCHOR: log
2223
info!("Hello world!");
23-
boot::stall(10_000_000);
24+
boot::stall(Duration::from_secs(10));
2425
// ANCHOR_END: log
2526
// ANCHOR: return
2627
Status::SUCCESS

uefi-test-runner/examples/loaded_image.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![no_main]
55
#![no_std]
66

7+
use core::time::Duration;
78
use log::info;
89
use uefi::boot::{self, SearchType};
910
use uefi::prelude::*;
@@ -20,7 +21,7 @@ fn main() -> Status {
2021

2122
print_image_path().unwrap();
2223

23-
boot::stall(10_000_000);
24+
boot::stall(Duration::from_secs(10));
2425
Status::SUCCESS
2526
}
2627
// ANCHOR_END: main

uefi-test-runner/examples/timestamp.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88

99
extern crate alloc;
1010

11-
use log::{info, warn};
12-
1311
// ANCHOR: use
12+
use core::time::Duration;
13+
use log::{info, warn};
1414
use uefi::boot;
1515
use uefi::prelude::*;
1616
use uefi::proto::misc::Timestamp;
17-
1817
// ANCHOR_END: use
1918

2019
// ANCHOR: entry
@@ -30,7 +29,7 @@ fn main() -> Status {
3029
// ANCHOR_END: params
3130

3231
// ANCHOR: stall
33-
boot::stall(10_000_000);
32+
boot::stall(Duration::from_secs(10));
3433
// ANCHOR_END: stall
3534

3635
// ANCHOR: return

uefi-test-runner/src/proto/network/snp.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
22

3+
use core::time::Duration;
4+
35
use uefi::proto::network::snp::{InterruptStatus, ReceiveFlags, SimpleNetwork};
46
use uefi::proto::network::MacAddress;
57
use uefi::{boot, Status};
@@ -106,7 +108,7 @@ pub fn test() {
106108
if simple_network.receive(&mut buffer, None, None, None, None)
107109
== Err(Status::NOT_READY.into())
108110
{
109-
boot::stall(1_000_000);
111+
boot::stall(Duration::from_secs(1));
110112

111113
simple_network
112114
.receive(&mut buffer, None, None, None, None)

uefi-test-runner/src/proto/pi/mp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ extern "efiapi" fn proc_increment_atomic(arg: *mut c_void) {
7676
}
7777

7878
extern "efiapi" fn proc_wait_100ms(_: *mut c_void) {
79-
boot::stall(100_000);
79+
boot::stall(Duration::from_millis(100));
8080
}
8181

8282
fn test_startup_all_aps(mps: &MpServices) {

uefi/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# uefi - [Unreleased]
22

3+
## Changed
4+
- **Breaking:** `boot::stall` now take `Duration` instead of
5+
`usize`.
6+
37

48
# uefi - 0.35.0 (2025-05-04)
59

uefi/src/boot.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ use core::mem::MaybeUninit;
4343
use core::ops::{Deref, DerefMut};
4444
use core::ptr::{self, NonNull};
4545
use core::sync::atomic::{AtomicPtr, Ordering};
46+
use core::time::Duration;
4647
use core::{mem, slice};
4748
use uefi_raw::table::boot::{InterfaceType, TimerDelay};
4849
#[cfg(feature = "alloc")]
@@ -1423,11 +1424,13 @@ pub fn set_watchdog_timer(
14231424
.to_result()
14241425
}
14251426

1426-
/// Stalls execution for the given number of microseconds.
1427-
pub fn stall(microseconds: usize) {
1427+
/// Stalls execution for the given duration.
1428+
pub fn stall(duration: Duration) {
14281429
let bt = boot_services_raw_panicking();
14291430
let bt = unsafe { bt.as_ref() };
14301431

1432+
let microseconds = duration.as_micros() as usize;
1433+
14311434
unsafe {
14321435
// No error conditions are defined in the spec for this function, so
14331436
// ignore the status.

uefi/src/helpers/panic_handler.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
22

3+
use core::time::Duration;
4+
35
use crate::{boot, println};
46
use cfg_if::cfg_if;
57

@@ -9,7 +11,7 @@ fn panic_handler(info: &core::panic::PanicInfo) -> ! {
911

1012
// Give the user some time to read the message
1113
if boot::are_boot_services_active() {
12-
boot::stall(10_000_000);
14+
boot::stall(Duration::from_secs(10));
1315
} else {
1416
let mut dummy = 0u64;
1517
// FIXME: May need different counter values in debug & release builds

uefi/src/proto/network/ip4config2.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use alloc::vec;
88
use alloc::vec::Vec;
99
use core::ffi::c_void;
10+
use core::time::Duration;
1011

1112
use uefi::boot::ScopedProtocol;
1213
use uefi::prelude::*;
@@ -137,7 +138,7 @@ impl Ip4Config2 {
137138
if verbose {
138139
print!(".");
139140
}
140-
boot::stall(1_000_000);
141+
boot::stall(Duration::from_secs(1));
141142
let info = self.get_interface_info()?;
142143
if info.station_addr != no_address {
143144
if verbose {

0 commit comments

Comments
 (0)