Skip to content

Commit 589884f

Browse files
uefi: Add Timestamp protocol
1 parent c37fb59 commit 589884f

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

uefi/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# uefi - [Unreleased]
22

3+
## Added
4+
- Added `Timestamp` protocol.
5+
36
# uefi - 0.27.0 (2024-03-17)
47

58
## Added

uefi/src/proto/misc.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//! Miscellaneous protocols.
2+
3+
use crate::proto::unsafe_protocol;
4+
use crate::{Result, StatusExt};
5+
use uefi_raw::protocol::misc::{TimestampProperties, TimestampProtocol};
6+
7+
/// Protocol for retrieving a high-resolution timestamp counter.
8+
#[derive(Debug)]
9+
#[repr(transparent)]
10+
#[unsafe_protocol(TimestampProtocol::GUID)]
11+
pub struct Timestamp(TimestampProtocol);
12+
13+
impl Timestamp {
14+
/// Get the current value of the timestamp counter.
15+
pub fn get_timestamp(&self) -> u64 {
16+
unsafe { (self.0.get_timestamp)() }
17+
}
18+
19+
/// Get the properties of the timestamp counter.
20+
pub fn get_properties(&self) -> Result<TimestampProperties> {
21+
let mut properties = TimestampProperties::default();
22+
unsafe { (self.0.get_properties)(&mut properties) }.to_result_with_val(|| properties)
23+
}
24+
}

uefi/src/proto/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ pub mod device_path;
7272
pub mod driver;
7373
pub mod loaded_image;
7474
pub mod media;
75+
pub mod misc;
7576
pub mod network;
7677
pub mod pi;
7778
pub mod rng;

0 commit comments

Comments
 (0)