Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions drivers/gpu/drm/asahi/g14_v27_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,8 @@ impl Runtime {
preempt,
timestamps: packet.timestamp_addresses(index),
helper: control.helper,
sampler_heap: control.sampler_heap,
sampler_count: control.sampler_count,
};
let command = state.pool.encode(slot, &state.queue, stamp.raw(), &job)?;
let submission = state.root.stage_compute(command)?;
Expand Down
52 changes: 52 additions & 0 deletions drivers/gpu/drm/asahi/g14_v27_2_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,34 @@ pub(crate) fn encode_compute_helper(cmd: &mut [u8], binary: u32, data: u64, conf
put32(cmd, COMPUTE_JOB_PARAMETERS1 + 0x50, config);
}

/// Where the 27.2 compute command keeps its sampler heap (u64), sampler count and sampler bound:
/// the 13.5 EncoderParams sampler words, 0x10 bytes further on as in the 27.2 fragment command
/// (13.5 0x8ac, 27.2 0x8bc). The firmware loads the same three words of every command type
/// into the data master's sampler state (TA 0x558/0x560/0x564, 3D 0x8bc/0x8c4/0x8c8, compute
/// here), the count and the bound as 11-bit fields.
pub(crate) const COMPUTE_SAMPLER_HEAP: usize = 0x284;
pub(crate) const COMPUTE_SAMPLER_COUNT: usize = 0x28c;
pub(crate) const COMPUTE_SAMPLER_MAX: usize = 0x290;

/// The sampler bound the 13.5 compute command stores next to the count: the count plus one,
/// or zero without samplers.
pub(crate) fn compute_sampler_max(count: u32) -> u32 {
if count == 0 {
0
} else {
count + 1
}
}

/// Writes the sampler heap of a zeroed 27.2 compute command. A command without samplers
/// (heap and count zero) keeps the words zero. The caller has validated the heap: at most
/// 1024 samplers, both fields set or both zero.
pub(crate) fn encode_compute_samplers(cmd: &mut [u8], heap: u64, count: u32) {
put64(cmd, COMPUTE_SAMPLER_HEAP, heap);
put32(cmd, COMPUTE_SAMPLER_COUNT, count);
put32(cmd, COMPUTE_SAMPLER_MAX, compute_sampler_max(count));
}

/// Writes the user timestamp pair of a zeroed 27.2 compute command at `cmd_va` and returns the
/// Timestamp operations' user word ([`user_timestamp_pointer`]).
pub(crate) fn encode_compute_timestamps(cmd: &mut [u8], cmd_va: u64, timestamps: [u64; 2]) -> u64 {
Expand Down Expand Up @@ -272,6 +300,30 @@ mod tests {
}
}

#[test]
fn the_compute_samplers_sit_between_the_encoder_mask_and_the_job_meta() {
let mut cmd = [0u8; COMPUTE_COMMAND_BYTES];
encode_compute_samplers(&mut cmd, 0x2d_fff4_4000, 1024);
let read64 = |at: usize| u64::from_le_bytes(cmd[at..at + 8].try_into().unwrap());
let read32 = |at: usize| u32::from_le_bytes(cmd[at..at + 4].try_into().unwrap());
assert_eq!(
(read64(0x284), read32(0x28c), read32(0x290)),
(0x2d_fff4_4000, 1024, 1025)
);
// After the encoder mask (+0x270) and before the JobMeta stamps (+0x298), in no other
// word the compute encoder writes.
for (at, len) in [(0x284, 8), (0x28c, 4), (0x290, 4)] {
assert!(free(at, len));
assert!(0x270 + 4 <= at && at + len <= 0x298);
}
// The firmware takes the count and the bound as 11-bit fields.
assert!(compute_sampler_max(1024) < 1 << 11);

let mut none = [0u8; COMPUTE_COMMAND_BYTES];
encode_compute_samplers(&mut none, 0, 0);
assert!(none.iter().all(|&b| b == 0));
}

#[test]
fn flush_stamps_follows_the_compute_job_meta_and_misses_the_user_pair() {
// The JobMeta words the encoder writes end right before it: slot at +0x2b0.
Expand Down
5 changes: 5 additions & 0 deletions drivers/gpu/drm/asahi/gpu/v27_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ pub(crate) struct ComputeJob {
pub(crate) timestamps: [u64; 2],
/// The helper program (scratch and stack setup), or zero.
pub(crate) helper: crate::m3::agx_uapi::UapiHelperProgram,
/// The sampler heap and its sampler count, or zero.
pub(crate) sampler_heap: u64,
pub(crate) sampler_count: u32,
}

fn put32(b: &mut [u8], at: usize, v: u32) {
Expand Down Expand Up @@ -217,6 +220,7 @@ fn encode_compute(
put64(cmd, 0x334, timestamps + 0x20);
let user = g14_v27_2_abi::encode_compute_timestamps(cmd, cmd_va, job.timestamps);
g14_v27_2_abi::encode_compute_helper(cmd, job.helper.binary, job.helper.data, job.helper.config);
g14_v27_2_abi::encode_compute_samplers(cmd, job.sampler_heap, job.sampler_count);

put32(stream, 0, 11);
// 13.5 StartCompute.unk_28, at the same place in this layout (the 13.5 G14 path writes 1).
Expand Down Expand Up @@ -455,6 +459,7 @@ impl BootJob {
context: 0, sequence: 0, cdm_base: cdm, cdm_end: cdm + 8,
usc_base: 0x11_0000_0000, preempt: self.client_va, timestamps: [0; 2],
helper: crate::m3::agx_uapi::UapiHelperProgram { binary: 0, config: 0, data: 0 },
sampler_heap: 0, sampler_count: 0,
};
let (cmd_va, stream_va) = (self.command.gpu_va().get(), self.stream.gpu_va().get());
encode_compute(self.command.as_mut_slice(), cmd_va, self.stream.as_mut_slice(), stream_va,
Expand Down
6 changes: 6 additions & 0 deletions drivers/gpu/drm/asahi/m3/agx_compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ pub(crate) struct Control {
/// (`m3_submit::Queue::samplers_and_helpers`).
#[cfg_attr(not(CONFIG_DRM_ASAHI_G14_V27_2), allow(dead_code))]
pub helper: crate::m3::agx_uapi::UapiHelperProgram,
/// The sampler heap and its sampler count, both zero unless the queue's command builder
/// encodes them (`m3_submit::Queue::samplers_and_helpers`).
#[cfg_attr(not(CONFIG_DRM_ASAHI_G14_V27_2), allow(dead_code))]
pub sampler_heap: u64,
#[cfg_attr(not(CONFIG_DRM_ASAHI_G14_V27_2), allow(dead_code))]
pub sampler_count: u32,
}
20 changes: 12 additions & 8 deletions drivers/gpu/drm/asahi/m3/m3_submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,9 @@ pub(crate) struct Queue {
/// for every sample count and layer count. Otherwise only the single-sample,
/// single-layer compressed depth layout is admitted.
zls_compression_all_layouts:bool,
/// Whether this queue's command builders encode the render sampler heap and the render and
/// compute helper programs, in the 13.5 places. Otherwise they are refused: the M3 26.x
/// commands stream their sampler state and carry no helper.
/// Whether this queue's command builders encode the render and compute sampler heaps and
/// helper programs, in the 13.5 places. Otherwise they are refused: the M3 26.x commands
/// stream their sampler state and carry no helper.
samplers_and_helpers:bool,
urgency:u8,
}
Expand Down Expand Up @@ -356,8 +356,9 @@ impl Queue {
// compression words in every layout (g14_v27_2_render.rs).
zls_compression_all_layouts:true,
// Its render commands carry the sampler heap and both helper programs, and its
// compute command the 13.5 compute JobParameters1 with the helper
// (g14_v27_2_render.rs, gpu/v27_2.rs).
// compute command the 13.5 compute JobParameters1 with the helper and the sampler
// heap words the firmware loads for every command type (g14_v27_2_render.rs,
// g14_v27_2_abi.rs, gpu/v27_2.rs).
samplers_and_helpers:true,
urgency,preempt_alloc:Some((ualloc_priv,preempt_bytes)),
render_queue: Some(render_queue)})
Expand Down Expand Up @@ -391,7 +392,7 @@ impl queue::Queue for Queue {
// Other engines and helpers need their own M3 firmware translation.
let wide=kernel::uapi::drm_asahi_compute_flags_DRM_ASAHI_COMPUTE_WIDE_VISIBILITY as u32;
if payload.flags & !wide !=0 || (!self.wide_visibility && payload.flags & wide != 0)
|| payload.sampler_count!=0 || payload.sampler_heap!=0 {
|| (!self.samplers_and_helpers && (payload.sampler_count!=0 || payload.sampler_heap!=0)) {
pr_err!("M3 compute rejected: flags={:#x} samplers={} heap={:#x} attachments={} timestamps={}/{}\n",payload.flags,payload.sampler_count,payload.sampler_heap,attachments.as_slice().len(),payload.timestamps.start.handle,payload.timestamps.end.handle);
return Err(ENOTSUPP);
}
Expand All @@ -415,7 +416,7 @@ impl queue::Queue for Queue {
let c=agx_uapi::translate_compute_command(payload,attachments,
agx_uapi::QueueUscWindow{base:self.usc,user_start:0x4000,user_end:(1u64<<42)-0x8000},
&AddressSpace(&self.vm)).map_err(|e| {
pr_err!("M3 compute translation rejected {:?}: stream={:#x}..{:#x} helper={:?}\n",e,payload.control_stream_base,payload.control_stream_end,payload.helper);
pr_err!("M3 compute translation rejected {:?}: stream={:#x}..{:#x} helper={:?} samplers={} heap={:#x}\n",e,payload.control_stream_base,payload.control_stream_end,payload.helper,payload.sampler_count,payload.sampler_heap);
EINVAL
})?;
// The launch check decodes the 26.x G15 CDM launch format; G14 streams differ.
Expand All @@ -425,7 +426,10 @@ impl queue::Queue for Queue {
}
timestamps.push([Destination::resolve(objects,payload.timestamps.start)?,
Destination::resolve(objects,payload.timestamps.end)?,None,None],GFP_KERNEL)?;
commands.push(Command::Compute(crate::m3::agx_compute::Control{base:c.control_stream_base,end:c.control_stream_end,usc_base:self.usc,helper}),GFP_KERNEL)?;
// The translator checked the heap: at most 1024 samplers, both fields set or both zero,
// 8-byte aligned and readable in this VM. Only a queue that encodes it admits one.
commands.push(Command::Compute(crate::m3::agx_compute::Control{base:c.control_stream_base,end:c.control_stream_end,usc_base:self.usc,helper,
sampler_heap:c.sampler_heap,sampler_count:c.sampler_count}),GFP_KERNEL)?;
}
parser.finish().map_err(|_|EINVAL)?;
let preempt=match &self.preempt_alloc {
Expand Down
Loading