Skip to content

Commit e9e1239

Browse files
hoshinolinajannau
authored andcommitted
drm/asahi: queue: Plumb through objects XArray and add timestamp getter
Signed-off-by: Asahi Lina <lina@asahilina.net>
1 parent 46f4cf4 commit e9e1239

5 files changed

Lines changed: 42 additions & 4 deletions

File tree

drivers/gpu/drm/asahi/file.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,9 +1086,11 @@ impl File {
10861086
commands.push(unsafe { cmd.assume_init() }, GFP_KERNEL)?;
10871087
}
10881088

1089+
let objects = file.inner().objects();
1090+
10891091
let ret = queue
10901092
.lock()
1091-
.submit(id, in_syncs, out_syncs, result_buf, commands);
1093+
.submit(id, in_syncs, out_syncs, result_buf, commands, objects);
10921094

10931095
match ret {
10941096
Err(ERESTARTSYS) => Err(ERESTARTSYS),

drivers/gpu/drm/asahi/queue/common.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
//!
55
//! Shared helpers used by the submission logic for multiple command types.
66
7+
use crate::file;
8+
use crate::fw::job::UserTimestamp;
79
use crate::fw::microseq;
810
use crate::fw::types::*;
911

1012
use kernel::prelude::*;
1113
use kernel::uaccess::{UserPtr, UserSlice};
1214
use kernel::uapi;
15+
use kernel::xarray;
1316

1417
use core::mem::MaybeUninit;
1518

@@ -57,3 +60,28 @@ pub(super) fn build_attachments(pointer: u64, count: u32) -> Result<microseq::At
5760

5861
Ok(attachments)
5962
}
63+
64+
pub(super) fn get_timestamp_object(
65+
objects: Pin<&xarray::XArray<KBox<file::Object>>>,
66+
handle: u32,
67+
offset: u32,
68+
) -> Result<Option<UserTimestamp>> {
69+
if handle == 0 {
70+
return Ok(None);
71+
}
72+
73+
let object = objects.get(handle.try_into()?).ok_or(ENOENT)?;
74+
75+
#[allow(irrefutable_let_patterns)]
76+
if let file::Object::TimestampBuffer(mapping) = object.borrow() {
77+
if (offset.checked_add(8).ok_or(EINVAL)?) as usize > mapping.size() {
78+
return Err(ERANGE);
79+
}
80+
Ok(Some(UserTimestamp {
81+
mapping: mapping.clone(),
82+
offset: offset as usize,
83+
}))
84+
} else {
85+
Err(EINVAL)
86+
}
87+
}

drivers/gpu/drm/asahi/queue/compute.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::debug::*;
1313
use crate::driver::AsahiDriver;
1414
use crate::fw::types::*;
1515
use crate::gpu::GpuManager;
16-
use crate::{fw, gpu, microseq};
16+
use crate::{file, fw, gpu, microseq};
1717
use crate::{inner_ptr, inner_weak_ptr};
1818
use core::sync::atomic::Ordering;
1919
use kernel::dma_fence::RawDmaFence;
@@ -23,6 +23,7 @@ use kernel::sync::Arc;
2323
use kernel::types::ForeignOwnable;
2424
use kernel::uaccess::{UserPtr, UserSlice};
2525
use kernel::uapi;
26+
use kernel::xarray;
2627

2728
const DEBUG_CLASS: DebugFlags = DebugFlags::Compute;
2829

@@ -34,6 +35,7 @@ impl super::QueueInner::ver {
3435
job: &mut Job<super::QueueJob::ver>,
3536
cmd: &uapi::drm_asahi_command,
3637
result_writer: Option<super::ResultWriter>,
38+
objects: Pin<&xarray::XArray<KBox<file::Object>>>,
3739
id: u64,
3840
flush_stamps: bool,
3941
) -> Result {

drivers/gpu/drm/asahi/queue/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use kernel::{
1414
macros::versions,
1515
sync::{Arc, Mutex},
1616
types::ForeignOwnable,
17-
uapi,
17+
uapi, xarray,
1818
};
1919

2020
use crate::alloc::Allocator;
@@ -45,6 +45,7 @@ pub(crate) trait Queue: Send + Sync {
4545
out_syncs: KVec<file::SyncItem>,
4646
result_buf: Option<gem::ObjectRef>,
4747
commands: KVec<uapi::drm_asahi_command>,
48+
objects: Pin<&xarray::XArray<KBox<file::Object>>>,
4849
) -> Result;
4950
}
5051

@@ -546,6 +547,7 @@ impl Queue for Queue::ver {
546547
out_syncs: KVec<file::SyncItem>,
547548
result_buf: Option<gem::ObjectRef>,
548549
commands: KVec<uapi::drm_asahi_command>,
550+
objects: Pin<&xarray::XArray<KBox<file::Object>>>,
549551
) -> Result {
550552
let data = unsafe { &<KBox<AsahiDriver>>::borrow(self.dev.as_ref().get_drvdata()).data };
551553
let gpu = match data
@@ -758,6 +760,7 @@ impl Queue for Queue::ver {
758760
&mut job,
759761
&cmd,
760762
result_writer,
763+
objects,
761764
id,
762765
last_render.unwrap() == i,
763766
)?;
@@ -779,6 +782,7 @@ impl Queue for Queue::ver {
779782
&mut job,
780783
&cmd,
781784
result_writer,
785+
objects,
782786
id,
783787
last_compute.unwrap() == i,
784788
)?;

drivers/gpu/drm/asahi/queue/render.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::fw::types::*;
1515
use crate::gpu::GpuManager;
1616
use crate::util::*;
1717
use crate::workqueue::WorkError;
18-
use crate::{buffer, fw, gpu, microseq, workqueue};
18+
use crate::{buffer, file, fw, gpu, microseq, workqueue};
1919
use crate::{inner_ptr, inner_weak_ptr};
2020
use core::sync::atomic::Ordering;
2121
use kernel::dma_fence::RawDmaFence;
@@ -26,6 +26,7 @@ use kernel::sync::Arc;
2626
use kernel::types::ForeignOwnable;
2727
use kernel::uaccess::{UserPtr, UserSlice};
2828
use kernel::uapi;
29+
use kernel::xarray;
2930

3031
const DEBUG_CLASS: DebugFlags = DebugFlags::Render;
3132

@@ -219,6 +220,7 @@ impl super::QueueInner::ver {
219220
job: &mut Job<super::QueueJob::ver>,
220221
cmd: &uapi::drm_asahi_command,
221222
result_writer: Option<super::ResultWriter>,
223+
objects: Pin<&xarray::XArray<KBox<file::Object>>>,
222224
id: u64,
223225
flush_stamps: bool,
224226
) -> Result {

0 commit comments

Comments
 (0)