Skip to content

Commit

Permalink
drm/asahi: Implement ASAHI_GET_TIME
Browse files Browse the repository at this point in the history
Signed-off-by: Asahi Lina <[email protected]>
  • Loading branch information
asahilina committed Nov 3, 2024
1 parent 493ec37 commit 57a2096
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drivers/gpu/drm/asahi/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ impl drv::Driver for AsahiDriver {
ioctl::AUTH | ioctl::RENDER_ALLOW, crate::file::File::queue_destroy),
(ASAHI_SUBMIT, drm_asahi_submit,
ioctl::AUTH | ioctl::RENDER_ALLOW, crate::file::File::submit),
(ASAHI_GET_TIME, drm_asahi_get_time,
ioctl::AUTH | ioctl::RENDER_ALLOW, crate::file::File::get_time),
}
}

Expand Down
33 changes: 33 additions & 0 deletions drivers/gpu/drm/asahi/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,39 @@ impl File {
Ok(_) => Ok(0),
}
}

/// IOCTL: get_time: Get the current GPU timer value.
pub(crate) fn get_time(
device: &AsahiDevice,
data: &mut uapi::drm_asahi_get_time,
file: &DrmFile,
) -> Result<u32> {

if data.extensions != 0 || data.flags != 0 {
cls_pr_debug!(Errors, "get_time: Unexpected extensions or flags\n");
return Err(EINVAL);
}

let mut tp: kernel::bindings::timespec64 = Default::default();
let mut gputime: u64 = 0;

// TODO: bindings
// SAFETY: These functions are safe to call as long as the argument pointer is valid
unsafe {
core::arch::asm!(
"mrs {x}, CNTPCT_EL0",
x = out(reg) gputime
);
kernel::bindings::ktime_get_raw_ts64(&mut tp);
kernel::bindings::timens_add_monotonic(&mut tp);
}

data.gpu_timestamp = gputime;
data.tv_sec = tp.tv_sec;
data.tv_nsec = tp.tv_nsec;

Ok(0)
}
}

impl Drop for File {
Expand Down

0 comments on commit 57a2096

Please sign in to comment.