Skip to content

Commit 8afbaf8

Browse files
authored
Merge pull request #1109 from nicholasbishop/bishop-timestamp
Add timestamp protocol
2 parents bcfc2b3 + 01308fa commit 8afbaf8

File tree

6 files changed

+57
-0
lines changed

6 files changed

+57
-0
lines changed

uefi-raw/CHANGELOG.md

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

3+
## Added
4+
- Added `TimestampProtocol`.
5+
36
# uefi-raw - 0.5.1 (2024-03-17)
47

58
## Added

uefi-raw/src/protocol/misc.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use crate::{guid, Guid, Status};
2+
3+
#[derive(Debug)]
4+
#[repr(C)]
5+
pub struct TimestampProtocol {
6+
pub get_timestamp: unsafe extern "efiapi" fn() -> u64,
7+
pub get_properties: unsafe extern "efiapi" fn(*mut TimestampProperties) -> Status,
8+
}
9+
10+
impl TimestampProtocol {
11+
pub const GUID: Guid = guid!("afbfde41-2e6e-4262-ba65-62b9236e5495");
12+
}
13+
14+
/// Properties of the timestamp counter.
15+
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
16+
#[repr(C)]
17+
pub struct TimestampProperties {
18+
/// Timestamp counter frequency, in Hz.
19+
pub frequency: u64,
20+
21+
/// The maximum value of the timestamp counter before it rolls over. For
22+
/// example, a 24-bit counter would have an end value of `0xff_ffff`.
23+
pub end_value: u64,
24+
}

uefi-raw/src/protocol/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub mod file_system;
1313
pub mod loaded_image;
1414
pub mod media;
1515
pub mod memory_protection;
16+
pub mod misc;
1617
pub mod network;
1718
pub mod rng;
1819
pub mod shell_params;

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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
#[must_use]
16+
pub fn get_timestamp(&self) -> u64 {
17+
unsafe { (self.0.get_timestamp)() }
18+
}
19+
20+
/// Get the properties of the timestamp counter.
21+
pub fn get_properties(&self) -> Result<TimestampProperties> {
22+
let mut properties = TimestampProperties::default();
23+
unsafe { (self.0.get_properties)(&mut properties) }.to_result_with_val(|| properties)
24+
}
25+
}

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)