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
7 changes: 5 additions & 2 deletions drivers/gpu/drm/asahi/g18/address_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ pub(crate) const GRAPHICS_IDEAL_BLOCKS: u64 = 0x70_2000_0000;
pub(crate) const GRAPHICS_TARGET_OFFSET: u64 = 0x0100_0000;
pub(crate) const GRAPHICS_TARGET_BYTES: usize = 0x0100_0000;
pub(crate) const GRAPHICS_PB_OFFSET: u64 = 0x0200_0000;
pub(crate) const GRAPHICS_PB_COMPACT_BYTES: usize = 0x0100_0000;
// PB blocks grow to render_policy::PB_MAX_BLOCKS. The biased half stays
// inside the COMPACT_BIAS + [32 MiB, 2 GiB) that Mesa leaves to the kernel.
pub(crate) const GRAPHICS_PB_COMPACT_BYTES: usize = 0x3400_0000;
pub(crate) const PB_GRAPH: u64 = GRAPHICS_PB_HIGH + 0x4000;
pub(crate) const PB_PAGE_LIST_HIGH: u64 = GRAPHICS_PB_HIGH + 0x10000;
pub(crate) const PB_PAGE_LIST_LOW: u64 = GRAPHICS_PB_OFFSET;
Expand Down Expand Up @@ -194,7 +196,8 @@ pub(crate) const PB_REGIONS: &[Region] = &[
r("pb-metrics-high", PB_METRICS_HIGH, PAGE),
r("pb-page-list-low", PB_PAGE_LIST_LOW, PB_PAGE_LIST_BYTES as u64),
r("pb-metrics-low", PB_METRICS_LOW, PAGE), r("pb-scene-scratch", PB_SCENE_SCRATCH, PAGE),
r("pb-discard", PB_DISCARD, 0x8000), r("pb-blocks", PB_BLOCKS, 8 * 0x80000),
r("pb-discard", PB_DISCARD, 0x8000),
r("pb-blocks", PB_BLOCKS, crate::g18::uapi::render_policy::PB_MAX_BLOCKS as u64 * 0x80000),
];
const _: () = assert!(nonoverlapping(PB_REGIONS));

Expand Down
46 changes: 41 additions & 5 deletions drivers/gpu/drm/asahi/g18/boot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
use crate::{
driver::AsahiDrmDevice,
g18::probe::{G18Runtime, T8152Probe},
g18::initdata::G18FirmwareMemory,
g18::initdata::{G18FirmwareMemory, G18TvbGrowRequest},
g18::runtime::compute::G18PreparedComputeCommand,
g18::buffer::pool::G18UmaPoolBinding,
g18::queue::probe::{G18QueueProbe, QUEUE_ID},
Expand Down Expand Up @@ -198,6 +198,9 @@ const INITDATA_ACK: u64 = 0x0009_0000_0000_0000;
/// EP 0x21 device-control doorbell for the idle-policy wake (M5 value,
/// unchanged in the 26A428 EP 0x21 handler 0x254cc-0x25610).
const IDLE_POLICY_WAKE: u64 = 0x0084_0000_0000_0011;
/// The same doorbell after any other primary control record (g17
/// MSG_CONTROL_NOTIFY).
const CONTROL_NOTIFY: u64 = IDLE_POLICY_WAKE;

const ACK_POLLS: u32 = 200; // x 10 ms
const CONTROL_POLLS: u32 = 1000; // x 1 ms
Expand Down Expand Up @@ -1082,12 +1085,45 @@ impl G18Session {
}

/// Drain the report rings once the graph exists. Returns whether a
/// recovery (type 4) event was seen.
/// recovery (type 4) event was seen. Answers TVB grow requests.
fn drain(&mut self) -> Result<bool> {
match self.memory.as_mut() {
Some(memory) => memory.drain_reports(&self.dev),
None => Ok(false),
let Some(memory) = self.memory.as_mut() else { return Ok(false) };
let recovery = memory.drain_reports(&self.dev)?;
while let Some(request) = self.memory.as_mut().ok_or(EIO)?.take_tvb_grow() {
self.answer_tvb_grow(request)?;
}
Ok(recovery)
}

/// Grow the PB that a firmware TVB grow request names and reply, so the
/// waiting tiler continues; "not grown" when that fails or the PB is at
/// its limit. A request from before the current recovery epoch is
/// stale and gets no reply, as on M5.
fn answer_tvb_grow(&mut self, request: G18TvbGrowRequest) -> Result {
let epoch = self.memory.as_mut().ok_or(EIO)?.recovery_word()?.epoch;
if request.halt_count != epoch {
dev_warn!(self.device(), "G18_TVB_GROW stale {:?} epoch={}\n", request, epoch);
return Ok(());
}
let grown = match self.application_job.as_mut() {
Some(job) => job.grow_parameter_buffer(&self.dev, request.buffer_slot, request.vm_slot),
None => Err(ENOENT),
};
let grew = match grown {
Ok(0) => {
dev_warn!(self.device(), "G18_TVB_GROW {:?} not grown: PB at its limit\n", request);
false
}
Ok(_) => true,
Err(error) => {
dev_warn!(self.device(), "G18_TVB_GROW {:?} not grown: {:?}\n", request, error);
false
}
};
self.memory.as_mut().ok_or(EIO)?.reply_tvb_grow(request, grew)?;
Pin::new(&mut self.roles[G18Role::Gfx.index()].rtkit)
.send_message(EP_GFX_INTERRUPTS, CONTROL_NOTIFY)?;
Ok(())
}

/// Fault check used by every wait loop.
Expand Down
24 changes: 24 additions & 0 deletions drivers/gpu/drm/asahi/g18/buffer/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,30 @@ impl MappedObject {
})
}

/// As [`Self::new_wc_at`], for memory whose owner holds a user charge for
/// it ([`crate::memacct::Charge::user`]) instead of counting it as kernel
/// memory.
pub(crate) fn new_wc_at_user_charged(
dev: &AsahiDrmDevice,
vm: &mmu::Vm,
address: u64,
size: usize,
prot: mmu::Prot,
) -> Result<Self> {
let mut object = gem::new_kernel_object_wc_user_charged(dev, size)?;
zero_object(&mut object)?;
let mapping = object.map_at(vm, address, prot, false)?;
let iova = mapping.iova();
Ok(Self {
mapping: Some(mapping),
object,
iova,
object_offset: 0,
logical_size: size,
cpu_wc: true,
})
}

/// Replace this object's backing with a larger one at the SAME address.
///
/// The replacement is allocated and zeroed before the old aperture is
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/asahi/g18/initdata/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl G18FirmwareMemory {
/// Graphics and compute share this outer ring but have independent inner
/// sequences. Only publish from a fully retired observed outer position.
pub(crate) fn publish_application_records(&mut self, records: &[[u8;24]]) -> Result<u32> {
if records.is_empty() || records.len()>2 || self.control_counters()?!=[[2;3],[1;3]] {
if records.is_empty() || records.len()>2 || self.control_counters()?!=self.control_retired() {
return Err(EINVAL);
}
let counters=self.compute_outer_counters()?;let before=counters[0];
Expand Down
79 changes: 78 additions & 1 deletion drivers/gpu/drm/asahi/g18/initdata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ const TRACE_PRINT_BUDGET: [u32; 2] = [512, 16];
const TRACE_JOURNAL_CAPACITY: usize = 32768;
/// b000 0x7de8 constructs type4 with counter at +4 and stamp index at +12.
const EVENT_TYPE_RECOVERY: u32 = 4;
/// Parameter-buffer (TVB) grow request in the 25G76 TvbGrowEventRecord
/// layout (g17::fw::channels). The tiler waits for the reply.
const EVENT_TYPE_TVB_GROW: u32 = 6;
/// Device-control TvbGrowReply (g17 DeviceControlOp::TvbGrowReply).
const DEVICE_CONTROL_OPCODE_TVB_GROW_REPLY: u32 = 0x08;
/// Grow requests held between a drain and the session answering them.
const TVB_GROW_QUEUE: usize = 4;

/// `halLoadUMADesc` device words (accelerator+0x11af8..0x11b10) as native
/// `halInitSMAEnableMask` 0xfffffe0008c41bdc derives them on J873.
Expand Down Expand Up @@ -166,6 +173,10 @@ pub(crate) struct G18FirmwareMemory {
trace_printed: [u32; 2],
trace_journal: [KVVec<G18TraceRecord>; 2],
trace_dropped: [u32; 2],
/// TVB grow requests drained but not yet answered, oldest first.
tvb_grow: KVec<G18TvbGrowRequest>,
/// Primary device-control records published after the idle wake.
control_published: u32,
uat: Arc<mmu::Uat>,
/// InitData layouts of the firmware build the loader admitted.
layouts: &'static init::G18GLayouts,
Expand All @@ -183,6 +194,18 @@ pub(crate) struct G18StatusLinks {
pub(crate) status_config_pointer: u64,
}

/// A firmware TVB grow request (event 6): vm_slot +4, buffer_slot +8,
/// counter +0xc, subpipe +0x10, u64 halt count (the recovery epoch) +0x14.
/// The reply echoes every field.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub(crate) struct G18TvbGrowRequest {
pub(crate) vm_slot: u32,
pub(crate) buffer_slot: u32,
pub(crate) counter: u32,
pub(crate) subpipe: u32,
pub(crate) halt_count: u64,
}

/// The status-B recovery handshake words.
#[derive(Debug, Copy, Clone, Default)]
pub(crate) struct G18RecoveryWord {
Expand Down Expand Up @@ -238,6 +261,7 @@ impl G18FirmwareMemory {
KVVec::with_capacity(TRACE_JOURNAL_CAPACITY, GFP_KERNEL)?,
KVVec::with_capacity(TRACE_JOURNAL_CAPACITY, GFP_KERNEL)?,
];
let tvb_grow = KVec::with_capacity(TVB_GROW_QUEUE, GFP_KERNEL)?;
let mut registers = KVec::new();
for window in init::G18G_26A428_REGISTER_WINDOWS {
let (physical, virtual_address, span) = window.mapped_pages().map_err(|_| EINVAL)?;
Expand Down Expand Up @@ -418,7 +442,7 @@ impl G18FirmwareMemory {
application_compute: None,
completions, aliases, registers,
report_counts: [[0; 2]; 2], completion_masks: [0; 2], trace_printed: [0; 2], uat,
trace_journal, trace_dropped: [0; 2], layouts,
trace_journal, trace_dropped: [0; 2], tvb_grow, control_published: 0, layouts,
}), GFP_KERNEL)
}

Expand Down Expand Up @@ -886,6 +910,13 @@ impl G18FirmwareMemory {
crate::g18_event_info!(role == 0 && word(0) == 1, dev.as_ref(), "G18_EVENT role={} ordinal={} type={} payload={:x?}\n",
role, count, word(0), [qword(4), qword(12), qword(20), qword(28), qword(36)]);
recovery |= word(0) == EVENT_TYPE_RECOVERY;
if word(0) == EVENT_TYPE_TVB_GROW {
// The session grows the PB and replies after the drain.
self.tvb_grow.push_within_capacity(G18TvbGrowRequest {
vm_slot: word(4), buffer_slot: word(8), counter: word(0xc),
subpipe: word(0x10), halt_count: qword(0x14),
}).map_err(|_| EBUSY)?;
}
if role == 0 && word(0) == 1 {
// Original G18 b000 233a8..233d4 uses this exact
// type-1 prefix. Copy/validate before releasing the
Expand All @@ -911,6 +942,52 @@ impl G18FirmwareMemory {
Ok(recovery)
}

/// The oldest drained TVB grow request not yet answered.
pub(crate) fn take_tvb_grow(&mut self) -> Option<G18TvbGrowRequest> {
if self.tvb_grow.is_empty() { None } else { self.tvb_grow.remove(0).ok() }
}

/// Publish the TvbGrowReply for `request` on the primary device-control
/// ring (g17 TvbGrowReply: opcode, grew, buffer_slot, vm_slot, counter,
/// subpipe, halt_count). The caller rings the EP 0x21 control doorbell.
pub(crate) fn reply_tvb_grow(&mut self, request: G18TvbGrowRequest, grew: bool) -> Result {
let [consumer, _, producer] = self.control_counters()?[0];
if consumer > init::CONTROL_RING_INDEX_MASK || producer > init::CONTROL_RING_INDEX_MASK {
return Err(EIO);
}
let next = (producer + 1) & init::CONTROL_RING_INDEX_MASK;
if next == consumer {
return Err(EBUSY);
}
let record = self.layouts.shared.control_ring[0] + producer as usize * init::CONTROL_RECORD_SIZE;
self.shared.with_bytes_mut(|out| {
let record = out.get_mut(record..record + init::CONTROL_RECORD_SIZE).ok_or(EINVAL)?;
init::encode_device_control_record(DEVICE_CONTROL_OPCODE_TVB_GROW_REPLY, u32::from(grew), record)
.map_err(|_| EINVAL)?;
let r = request;
for (offset, value) in [(0x08, r.buffer_slot), (0x0c, r.vm_slot), (0x10, r.counter),
(0x14, r.subpipe), (0x18, r.halt_count as u32),
(0x1c, (r.halt_count >> 32) as u32)] {
record[offset..offset + 4].copy_from_slice(&value.to_le_bytes());
}
Ok(())
})?;
fence(Ordering::SeqCst);
let producer_offset = init::G18G_26A428_PRIVATE_STATE_GRIDS[0]
+ init::WORK_STATE_GRID_OFFSETS[init::CONTROL_CHANNEL_INDEX]
+ init::CHANNEL_STATE_PRODUCER * init::CHANNEL_STATE_SPACING;
self.private.write_u32(PRIVATE_BASE + producer_offset as u64, next)?;
fence(Ordering::SeqCst);
self.control_published = self.control_published.wrapping_add(1);
Ok(())
}

/// Device-control counters of both roles once every record published
/// after boot retired: the idle wake left the primary ring at 2.
pub(crate) fn control_retired(&self) -> [[u32; 3]; 2] {
[[(2 + self.control_published) & init::CONTROL_RING_INDEX_MASK; 3], [1; 3]]
}

/// Report-record totals per role and channel since construction.
pub(crate) fn report_counts(&self) -> [[u32; 2]; 2] {
self.report_counts
Expand Down
3 changes: 3 additions & 0 deletions drivers/gpu/drm/asahi/g18/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ impl platform::Driver for Driver {
info: Option<&'bound Self::IdInfo>,
) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {
let soc = *info.ok_or(ENODEV)?;
// The memory limits the parameter buffer's growth is admitted
// against (memacct), as the other generations' probe sets them.
crate::memacct::LEDGER.configure();
AsahiPlatformDriver::probe_g18(pdev, soc)
}

Expand Down
18 changes: 14 additions & 4 deletions drivers/gpu/drm/asahi/g18/queue/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,10 +625,17 @@ impl G18GraphicsQueues {
use crate::g18::fw::parameter_buffer::*;

const PM_GRAPH_BYTES: usize = 0x8000;
// The block table holds an entry for each of the PB_CAPACITY ring slots the
// firmware is given. It stays at the start of the graph (behind the scene
// records, at +0x8000 of a larger graph, the first frame faulted); the shared
// header, the counter and the scene records follow it.
const BLOCK_TABLE: usize = 0;
const SHARED: usize = 0x800;
const COUNTER: usize = 0x900;
const SCENES: usize = 0x1000;
const SHARED: usize = 0x3400;
const COUNTER: usize = 0x3500;
const SCENES: usize = 0x4000;
const _: () = assert!(
BLOCK_TABLE + crate::g18::uapi::render_policy::PB_CAPACITY as usize * 8 <= SHARED
);
const SCENE_BYTES: usize = 0x80;

fn pb_put32(out: &mut [u8], offset: usize, value: u32) {
Expand Down Expand Up @@ -723,6 +730,8 @@ pub(crate) struct G18ParameterBuffer {
metrics: MappedObject,
scene_scratch: MappedObject,
blocks: KVec<MappedObject>,
/// The user charges of the grown blocks ([`Self::grow`]).
charges: KVec<crate::memacct::Charge>,
discard: MappedObject,
addresses: G18PbAddresses,
policy: G18PbPolicy,
Expand Down Expand Up @@ -810,7 +819,8 @@ impl G18ParameterBuffer {
};
let mut owner = Self {
window_aliases: KVec::new(), low_aliases, state, graph, page_list, metrics,
scene_scratch, blocks, discard, addresses: a, policy, inputs, row: None,
scene_scratch, blocks, charges: KVec::new(), discard, addresses: a, policy,
inputs, row: None,
};
owner.encode()?;
dev_info!(dev.as_ref(),
Expand Down
Loading
Loading