Skip to content

Commit b884f84

Browse files
hoshinolinajannau
authored andcommitted
drm/asahi: Implement ASAHI_GET_TIME
Signed-off-by: Asahi Lina <lina@asahilina.net>
1 parent 582dfc3 commit b884f84

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

drivers/gpu/drm/asahi/driver.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ impl drv::Driver for AsahiDriver {
7676
ioctl::AUTH | ioctl::RENDER_ALLOW, crate::file::File::queue_destroy),
7777
(ASAHI_SUBMIT, drm_asahi_submit,
7878
ioctl::AUTH | ioctl::RENDER_ALLOW, crate::file::File::submit),
79+
(ASAHI_GET_TIME, drm_asahi_get_time,
80+
ioctl::AUTH | ioctl::RENDER_ALLOW, crate::file::File::get_time),
7981
}
8082
}
8183

drivers/gpu/drm/asahi/file.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,38 @@ impl File {
925925
Ok(_) => Ok(0),
926926
}
927927
}
928+
929+
/// IOCTL: get_time: Get the current GPU timer value.
930+
pub(crate) fn get_time(
931+
device: &AsahiDevice,
932+
data: &mut uapi::drm_asahi_get_time,
933+
file: &DrmFile,
934+
) -> Result<u32> {
935+
if data.extensions != 0 || data.flags != 0 {
936+
cls_pr_debug!(Errors, "get_time: Unexpected extensions or flags\n");
937+
return Err(EINVAL);
938+
}
939+
940+
let mut tp: kernel::bindings::timespec64 = Default::default();
941+
let mut gputime: u64 = 0;
942+
943+
// TODO: bindings
944+
// SAFETY: These functions are safe to call as long as the argument pointer is valid
945+
unsafe {
946+
core::arch::asm!(
947+
"mrs {x}, CNTPCT_EL0",
948+
x = out(reg) gputime
949+
);
950+
kernel::bindings::ktime_get_raw_ts64(&mut tp);
951+
kernel::bindings::timens_add_monotonic(&mut tp);
952+
}
953+
954+
data.gpu_timestamp = gputime;
955+
data.tv_sec = tp.tv_sec;
956+
data.tv_nsec = tp.tv_nsec;
957+
958+
Ok(0)
959+
}
928960
}
929961

930962
impl Drop for File {

0 commit comments

Comments
 (0)