Skip to content

Commit 75ae859

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

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

@@ -91,6 +92,25 @@ impl<'a, T: ?Sized> GpuPointer<'a, T> {
9192
}
9293
}
9394

95+
impl<'a, T> GpuPointer<'a, T> {
96+
/// Create a GPU pointer from a KernelMapping and an offset.
97+
/// TODO: Change all GPU pointers to point to the raw types so size_of here is GPU-sound.
98+
pub(crate) fn from_mapping(
99+
mapping: &'a Arc<mmu::KernelMapping>,
100+
offset: usize,
101+
) -> Result<GpuPointer<'a, T>> {
102+
let addr = mapping.iova().checked_add(offset as u64).ok_or(EINVAL)?;
103+
let end = offset
104+
.checked_add(core::mem::size_of::<T>())
105+
.ok_or(EINVAL)?;
106+
if end > mapping.size() {
107+
Err(ERANGE)
108+
} else {
109+
Ok(Self(addr.try_into().unwrap(), PhantomData))
110+
}
111+
}
112+
}
113+
94114
impl<'a, T: ?Sized> Debug for GpuPointer<'a, T> {
95115
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
96116
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
@@ -186,7 +186,7 @@ impl super::QueueInner::ver {
186186
notifier_buf: inner_weak_ptr!(notifier.weak_pointer(), state.unk_buf),
187187
})?;
188188

189-
if has_result {
189+
if has_result || user_timestamps.any() {
190190
builder.add(microseq::Timestamp::ver {
191191
header: microseq::op::Timestamp::new(true),
192192
command_time: inner_weak_ptr!(ptr, command_time),
@@ -210,7 +210,7 @@ impl super::QueueInner::ver {
210210
header: microseq::op::WaitForIdle2::HEADER,
211211
})?;
212212

213-
if has_result {
213+
if has_result || user_timestamps.any() {
214214
builder.add(microseq::Timestamp::ver {
215215
header: microseq::op::Timestamp::new(false),
216216
command_time: inner_weak_ptr!(ptr, command_time),
@@ -376,10 +376,7 @@ impl super::QueueInner::ver {
376376
start_addr: Some(inner_ptr!(inner.timestamps.gpu_pointer(), start)),
377377
end_addr: Some(inner_ptr!(inner.timestamps.gpu_pointer(), end)),
378378
}),
379-
user_timestamp_pointers <- try_init!(fw::job::raw::TimestampPointers {
380-
start_addr: None,
381-
end_addr: None,
382-
}),
379+
user_timestamp_pointers: inner.user_timestamps.pointers()?,
383380
client_sequence: slot_client_seq,
384381
pad_2d1: Default::default(),
385382
unk_2d4: 0,

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

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

696-
if has_result {
696+
if has_result || frg_user_timestamps.any() {
697697
builder.add(microseq::Timestamp::ver {
698698
header: microseq::op::Timestamp::new(true),
699699
command_time: inner_weak_ptr!(ptr, command_time),
@@ -717,7 +717,7 @@ impl super::QueueInner::ver {
717717
header: microseq::op::WaitForIdle2::HEADER,
718718
})?;
719719

720-
if has_result {
720+
if has_result || frg_user_timestamps.any() {
721721
builder.add(microseq::Timestamp::ver {
722722
header: microseq::op::Timestamp::new(false),
723723
command_time: inner_weak_ptr!(ptr, command_time),
@@ -1097,10 +1097,7 @@ impl super::QueueInner::ver {
10971097
start_addr: Some(inner_ptr!(inner.timestamps.gpu_pointer(), frag.start)),
10981098
end_addr: Some(inner_ptr!(inner.timestamps.gpu_pointer(), frag.end)),
10991099
}),
1100-
user_timestamp_pointers <- try_init!(fw::job::raw::TimestampPointers {
1101-
start_addr: None,
1102-
end_addr: None,
1103-
}),
1100+
user_timestamp_pointers: inner.user_timestamps.pointers()?,
11041101
client_sequence: slot_client_seq,
11051102
pad_925: Default::default(),
11061103
unk_928: 0,
@@ -1224,7 +1221,7 @@ impl super::QueueInner::ver {
12241221
unk_178: (!clustering) as u32,
12251222
})?;
12261223

1227-
if has_result {
1224+
if has_result || vtx_user_timestamps.any() {
12281225
builder.add(microseq::Timestamp::ver {
12291226
header: microseq::op::Timestamp::new(true),
12301227
command_time: inner_weak_ptr!(ptr, command_time),
@@ -1248,7 +1245,7 @@ impl super::QueueInner::ver {
12481245
header: microseq::op::WaitForIdle2::HEADER,
12491246
})?;
12501247

1251-
if has_result {
1248+
if has_result || vtx_user_timestamps.any() {
12521249
builder.add(microseq::Timestamp::ver {
12531250
header: microseq::op::Timestamp::new(false),
12541251
command_time: inner_weak_ptr!(ptr, command_time),
@@ -1555,10 +1552,7 @@ impl super::QueueInner::ver {
15551552
start_addr: Some(inner_ptr!(inner.timestamps.gpu_pointer(), vtx.start)),
15561553
end_addr: Some(inner_ptr!(inner.timestamps.gpu_pointer(), vtx.end)),
15571554
}),
1558-
user_timestamp_pointers <- try_init!(fw::job::raw::TimestampPointers {
1559-
start_addr: None,
1560-
end_addr: None,
1561-
}),
1555+
user_timestamp_pointers: inner.user_timestamps.pointers()?,
15621556
client_sequence: slot_client_seq,
15631557
pad_5d5: Default::default(),
15641558
unk_5d8: 0,

0 commit comments

Comments
 (0)