Skip to content

Add timestamp protocol #1109

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

Merged
merged 2 commits into from
Apr 2, 2024
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
3 changes: 3 additions & 0 deletions uefi-raw/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# uefi-raw - [Unreleased]

## Added
- Added `TimestampProtocol`.

# uefi-raw - 0.5.1 (2024-03-17)

## Added
Expand Down
24 changes: 24 additions & 0 deletions uefi-raw/src/protocol/misc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use crate::{guid, Guid, Status};

#[derive(Debug)]
#[repr(C)]
pub struct TimestampProtocol {
pub get_timestamp: unsafe extern "efiapi" fn() -> u64,
pub get_properties: unsafe extern "efiapi" fn(*mut TimestampProperties) -> Status,
}

impl TimestampProtocol {
pub const GUID: Guid = guid!("afbfde41-2e6e-4262-ba65-62b9236e5495");
}

/// Properties of the timestamp counter.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(C)]
pub struct TimestampProperties {
/// Timestamp counter frequency, in Hz.
pub frequency: u64,

/// The maximum value of the timestamp counter before it rolls over. For
/// example, a 24-bit counter would have an end value of `0xff_ffff`.
pub end_value: u64,
}
1 change: 1 addition & 0 deletions uefi-raw/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod file_system;
pub mod loaded_image;
pub mod media;
pub mod memory_protection;
pub mod misc;
pub mod network;
pub mod rng;
pub mod shell_params;
3 changes: 3 additions & 0 deletions uefi/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# uefi - [Unreleased]

## Added
- Added `Timestamp` protocol.

# uefi - 0.27.0 (2024-03-17)

## Added
Expand Down
25 changes: 25 additions & 0 deletions uefi/src/proto/misc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//! Miscellaneous protocols.

use crate::proto::unsafe_protocol;
use crate::{Result, StatusExt};
use uefi_raw::protocol::misc::{TimestampProperties, TimestampProtocol};

/// Protocol for retrieving a high-resolution timestamp counter.
#[derive(Debug)]
#[repr(transparent)]
#[unsafe_protocol(TimestampProtocol::GUID)]
pub struct Timestamp(TimestampProtocol);

impl Timestamp {
/// Get the current value of the timestamp counter.
#[must_use]
pub fn get_timestamp(&self) -> u64 {
unsafe { (self.0.get_timestamp)() }
}

/// Get the properties of the timestamp counter.
pub fn get_properties(&self) -> Result<TimestampProperties> {
let mut properties = TimestampProperties::default();
unsafe { (self.0.get_properties)(&mut properties) }.to_result_with_val(|| properties)
}
}
1 change: 1 addition & 0 deletions uefi/src/proto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub mod device_path;
pub mod driver;
pub mod loaded_image;
pub mod media;
pub mod misc;
pub mod network;
pub mod pi;
pub mod rng;
Expand Down