Skip to content

Commit 1ed45ba

Browse files
hoshinolinajannau
authored andcommitted
drm/asahi: fw, queue: Plumb through UserTimestamps -> TimestampPointers
Signed-off-by: Asahi Lina <lina@asahilina.net>
1 parent e9e1239 commit 1ed45ba

4 files changed

Lines changed: 52 additions & 19 deletions

File tree

drivers/gpu/drm/asahi/fw/job.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
use super::types::*;
66
use crate::{default_zeroed, mmu, trivial_gpustruct};
7+
use kernel::prelude::Result;
78
use kernel::sync::Arc;
89

910
pub(crate) mod raw {
@@ -132,3 +133,24 @@ pub(crate) struct UserTimestamps {
132133
pub(crate) start: Option<UserTimestamp>,
133134
pub(crate) end: Option<UserTimestamp>,
134135
}
136+
137+
impl UserTimestamps {
138+
pub(crate) fn any(&self) -> bool {
139+
self.start.is_some() || self.end.is_some()
140+
}
141+
142+
pub(crate) fn pointers(&self) -> Result<raw::TimestampPointers<'_>> {
143+
Ok(raw::TimestampPointers {
144+
start_addr: self
145+
.start
146+
.as_ref()
147+
.map(|a| GpuPointer::from_mapping(&a.mapping, a.offset))
148+
.transpose()?,
149+
end_addr: self
150+
.end
151+
.as_ref()
152+
.map(|a| GpuPointer::from_mapping(&a.mapping, a.offset))
153+
.transpose()?,
154+
})
155+
}
156+
}

drivers/gpu/drm/asahi/object.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
//
4444
// Further discussion: https://github.com/rust-lang/unsafe-code-guidelines/issues/152
4545

46-
use kernel::{error::code::*, prelude::*};
46+
use kernel::{error::code::*, prelude::*, sync::Arc};
4747

4848
use core::fmt;
4949
use core::fmt::Debug;
@@ -57,6 +57,7 @@ use core::{mem, ptr, slice};
5757
use crate::alloc::Allocation;
5858
use crate::debug::*;
5959
use crate::fw::types::Zeroable;
60+
use crate::mmu;
6061

6162
const DEBUG_CLASS: DebugFlags = DebugFlags::Object;
6263

@@ -94,6 +95,25 @@ impl<'a, T: ?Sized> GpuPointer<'a, T> {
9495
}
9596
}
9697

98+
impl<'a, T> GpuPointer<'a, T> {
99+
/// Create a GPU pointer from a KernelMapping and an offset.
100+
/// TODO: Change all GPU pointers to point to the raw types so size_of here is GPU-sound.
101+
pub(crate) fn from_mapping(
102+
mapping: &'a Arc<mmu::KernelMapping>,
103+
offset: usize,
104+
) -> Result<GpuPointer<'a, T>> {
105+
let addr = mapping.iova().checked_add(offset as u64).ok_or(EINVAL)?;
106+
let end = offset
107+
.checked_add(core::mem::size_of::<T>())
108+
.ok_or(EINVAL)?;
109+
if end > mapping.size() {
110+
Err(ERANGE)
111+
} else {
112+
Ok(Self(addr.try_into().unwrap(), PhantomData))
113+
}
114+
}
115+
}
116+
97117
impl<'a, T: ?Sized> Debug for GpuPointer<'a, T> {
98118
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
99119
let val = self.0;

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl super::QueueInner::ver {
177177
notifier_buf: inner_weak_ptr!(notifier.weak_pointer(), state.unk_buf),
178178
})?;
179179

180-
if has_result {
180+
if has_result || user_timestamps.any() {
181181
builder.add(microseq::Timestamp::ver {
182182
header: microseq::op::Timestamp::new(true),
183183
command_time: inner_weak_ptr!(ptr, command_time),
@@ -201,7 +201,7 @@ impl super::QueueInner::ver {
201201
header: microseq::op::WaitForIdle2::HEADER,
202202
})?;
203203

204-
if has_result {
204+
if has_result || user_timestamps.any() {
205205
builder.add(microseq::Timestamp::ver {
206206
header: microseq::op::Timestamp::new(false),
207207
command_time: inner_weak_ptr!(ptr, command_time),
@@ -367,10 +367,7 @@ impl super::QueueInner::ver {
367367
start_addr: Some(inner_ptr!(inner.timestamps.gpu_pointer(), start)),
368368
end_addr: Some(inner_ptr!(inner.timestamps.gpu_pointer(), end)),
369369
}),
370-
user_timestamp_pointers <- try_init!(fw::job::raw::TimestampPointers {
371-
start_addr: None,
372-
end_addr: None,
373-
}),
370+
user_timestamp_pointers: inner.user_timestamps.pointers()?,
374371
client_sequence: slot_client_seq,
375372
pad_2d1: Default::default(),
376373
unk_2d4: 0,

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ impl super::QueueInner::ver {
681681
notifier_buf: inner_weak_ptr!(notifier.weak_pointer(), state.unk_buf),
682682
})?;
683683

684-
if has_result {
684+
if has_result || frg_user_timestamps.any() {
685685
builder.add(microseq::Timestamp::ver {
686686
header: microseq::op::Timestamp::new(true),
687687
command_time: inner_weak_ptr!(ptr, command_time),
@@ -705,7 +705,7 @@ impl super::QueueInner::ver {
705705
header: microseq::op::WaitForIdle2::HEADER,
706706
})?;
707707

708-
if has_result {
708+
if has_result || frg_user_timestamps.any() {
709709
builder.add(microseq::Timestamp::ver {
710710
header: microseq::op::Timestamp::new(false),
711711
command_time: inner_weak_ptr!(ptr, command_time),
@@ -1085,10 +1085,7 @@ impl super::QueueInner::ver {
10851085
start_addr: Some(inner_ptr!(inner.timestamps.gpu_pointer(), frag.start)),
10861086
end_addr: Some(inner_ptr!(inner.timestamps.gpu_pointer(), frag.end)),
10871087
}),
1088-
user_timestamp_pointers <- try_init!(fw::job::raw::TimestampPointers {
1089-
start_addr: None,
1090-
end_addr: None,
1091-
}),
1088+
user_timestamp_pointers: inner.user_timestamps.pointers()?,
10921089
client_sequence: slot_client_seq,
10931090
pad_925: Default::default(),
10941091
unk_928: 0,
@@ -1212,7 +1209,7 @@ impl super::QueueInner::ver {
12121209
unk_178: (!clustering) as u32,
12131210
})?;
12141211

1215-
if has_result {
1212+
if has_result || vtx_user_timestamps.any() {
12161213
builder.add(microseq::Timestamp::ver {
12171214
header: microseq::op::Timestamp::new(true),
12181215
command_time: inner_weak_ptr!(ptr, command_time),
@@ -1236,7 +1233,7 @@ impl super::QueueInner::ver {
12361233
header: microseq::op::WaitForIdle2::HEADER,
12371234
})?;
12381235

1239-
if has_result {
1236+
if has_result || vtx_user_timestamps.any() {
12401237
builder.add(microseq::Timestamp::ver {
12411238
header: microseq::op::Timestamp::new(false),
12421239
command_time: inner_weak_ptr!(ptr, command_time),
@@ -1543,10 +1540,7 @@ impl super::QueueInner::ver {
15431540
start_addr: Some(inner_ptr!(inner.timestamps.gpu_pointer(), vtx.start)),
15441541
end_addr: Some(inner_ptr!(inner.timestamps.gpu_pointer(), vtx.end)),
15451542
}),
1546-
user_timestamp_pointers <- try_init!(fw::job::raw::TimestampPointers {
1547-
start_addr: None,
1548-
end_addr: None,
1549-
}),
1543+
user_timestamp_pointers: inner.user_timestamps.pointers()?,
15501544
client_sequence: slot_client_seq,
15511545
pad_5d5: Default::default(),
15521546
unk_5d8: 0,

0 commit comments

Comments
 (0)