From 57a2096e69681a8d8cbfbbfa6158ab22c1e0535a Mon Sep 17 00:00:00 2001 From: Asahi Lina Date: Sun, 3 Nov 2024 21:18:08 +0900 Subject: [PATCH] drm/asahi: Implement ASAHI_GET_TIME Signed-off-by: Asahi Lina --- drivers/gpu/drm/asahi/driver.rs | 2 ++ drivers/gpu/drm/asahi/file.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/drivers/gpu/drm/asahi/driver.rs b/drivers/gpu/drm/asahi/driver.rs index f99494265234a7..80ea12df7810ed 100644 --- a/drivers/gpu/drm/asahi/driver.rs +++ b/drivers/gpu/drm/asahi/driver.rs @@ -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), } } diff --git a/drivers/gpu/drm/asahi/file.rs b/drivers/gpu/drm/asahi/file.rs index d2e28fd1d11a9b..5c50e2aa41c33c 100644 --- a/drivers/gpu/drm/asahi/file.rs +++ b/drivers/gpu/drm/asahi/file.rs @@ -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 { + + 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 {