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
16 changes: 10 additions & 6 deletions drivers/gpu/drm/asahi/g16/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use super::channel::Channel;
use super::command::{Command, ComputeCommand, RenderCommand};
use super::encode::{self, ComputeRefs, ComputeRt, Geometry, RenderRefs, StageRt};
use super::fw::channels::{SubmitRecord, RING_SLOTS};
use super::fw::graph::{notifier_page, qstate};
use super::fw::graph::{notifier_page, qstate, sched_ctx};
use super::fw::work::{self, BarrierType};
use super::hw::{engine as engine_ids, sizes};
use super::job::{Completions, Job};
Expand Down Expand Up @@ -838,6 +838,7 @@ impl Firmware {
bytes[12..20].copy_from_slice(&zero.to_le_bytes());
bytes[0x20..0x24].copy_from_slice(&0x80u32.to_le_bytes());
barrier.write(0, &bytes)?;
r.sched_ctx.sync_for_cpu(0, sched_ctx::SIZE)?;
if r.qstate[0].r32(qstate::READ)? != 0
|| r.qstate[0].r32(qstate::WRITE)? != 0
|| r.sched_ctx.r32(0)? & 0xffffff != 0x00ffff
Expand Down Expand Up @@ -870,6 +871,7 @@ impl Firmware {
if now >= deadline {
return Err(ETIMEDOUT);
}
self.graph.render.sched_ctx.sync_for_cpu(0, sched_ctx::SIZE)?;
let context = self.graph.render.sched_ctx.r32(0)?;
let registered = context & 0xff != 0xff
&& (context >> 8) & 0xff != 0xff
Expand Down Expand Up @@ -909,7 +911,7 @@ impl Firmware {
pub(crate) fn recovery_snapshot(&self) -> Result<[u32; 2 + sizes::COMPUTE_PIPES]> {
let mut stage = [0u32; 2 + sizes::COMPUTE_PIPES];
stage[0] = self.graph.render.fw_stamp[0].r32(0)?;
stage[1] = self.graph.render.fw_stamp[1].r32(0)?;
stage[1] = self.graph.render.notifier.r32(notifier_page::FS_STAMP)?;
for (p, compute) in self.graph.compute.iter().enumerate() {
stage[2 + p] = compute.fw_stamp.r32(0)?;
}
Expand Down Expand Up @@ -2491,7 +2493,7 @@ impl Firmware {
if engine_behind {
return Err(EAGAIN);
}
let e = job.resources.take_pb()?;
let e = job.resources.take_pb_for(heap_blocks)?;
if let Err(err) = e.prepare_with_scs_for(
self.init.abi.pb_manager(),
alloc_slot,
Expand All @@ -2507,7 +2509,7 @@ impl Firmware {
}
};
let binding = self.pools.bind(alloc_slot, reused);
a.pb_mgr = epoch.manager.va;
a.pb_mgr = epoch.manager_va()?;
a.mgr_misc = epoch.misc.va;
let r = &self.graph.render;
let stage = draw.checked_mul(2).ok_or(EOVERFLOW)?;
Expand Down Expand Up @@ -2568,7 +2570,7 @@ impl Firmware {
uma_mgr: a.uma_mgr,
uma_aux: a.uma_aux,
uma_gpu: a.uma_gpu,
pb_mgr: epoch.manager.va,
pb_mgr: epoch.manager_va()?,
scene_list: 0,
mgr_misc: epoch.misc.va,
pb_init_blocks: epoch.heap_blocks(),
Expand Down Expand Up @@ -3318,7 +3320,9 @@ impl Firmware {
let publication = (|| -> Result {
if render {
let a = f.pb_slot as usize;
f.pb.as_ref().ok_or(EINVAL)?.expose();
let pb = f.pb.as_ref().ok_or(EINVAL)?;
pb.expose();
pb.publish_flight();
job.resources.commit_render(f.count as u32);
for j2 in f.group.iter() {
j2.resources.commit_render(j2.progress.count());
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/asahi/g16/fw/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ pub(crate) mod pb_manager {
}
pub(crate) mod uma_manager {
pub(crate) const SIZE: usize = 0xa0;
#[allow(dead_code)]
pub(crate) const COMPLETED: usize = 0x54;
pub(crate) const SEEDS: u32 = 8192;
/// Freelist records of a base pool (+0x1c), its 0x20000-byte freelist.
Expand Down
73 changes: 45 additions & 28 deletions drivers/gpu/drm/asahi/g16/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,33 @@ struct QueueSession {
qinfo: Arc<FwObject>,
qstate: Arc<FwObject>,
user_stamp: Arc<FwObject>,
fw_stamp: Arc<FwObject>,
fw_stamp: Option<Arc<FwObject>>,
}
impl QueueSession {
fn new(o: &mut Objects) -> Result<Self> {
Self::new_with(o, Some(Class::Shared))
}
fn new_with(o: &mut Objects, fw_stamp_class: Option<Class>) -> Result<Self> {
Ok(Self {
qinfo: alloc(o, qinfo::SIZE, graph_fw(), None, 0, false)?,
qstate: alloc(o, qstate::SIZE, Class::Fw, None, 0, false)?,
user_stamp: alloc(o, 8, Class::Shared, None, 0, false)?,
fw_stamp: alloc(o, 8, Class::Shared, None, 0, false)?,
fw_stamp: match fw_stamp_class {
Some(class) => Some(alloc(o, 8, class, None, 0, false)?),
None => None,
},
})
}
/// Completes the queue with its firmware-cached work ring from a device-lifetime
/// [`Factory::persistent_objects`] allocator. The host only writes 64-bit work/barrier VAs
/// into the ring before advancing the uncached `qstate::WRITE` producer and never reads
/// back firmware writes, matching macOS 26B123's `0x443` command-ring mapping.
/// Completes the queue with its firmware-cached work ring (and, when deferred from
/// [`Self::new_with`], its firmware-cached `fw_stamp`) from a device-lifetime
/// [`Factory::persistent_objects`] allocator. The host writes 64-bit work/barrier VAs into
/// the ring before advancing the uncached `qstate::WRITE` producer and never reads back
/// firmware writes to the ring, matching macOS 26B123's `0x443` command-ring mapping.
fn finish(self, rings: &mut Objects) -> Result<QueueObjects> {
let fw_stamp = match self.fw_stamp {
Some(stamp) => stamp,
None => alloc(rings, 8, Class::FwCoherent, None, 0, false)?,
};
Ok(QueueObjects {
qinfo: self.qinfo,
qstate: self.qstate,
Expand All @@ -162,7 +173,7 @@ impl QueueSession {
false,
)?,
user_stamp: self.user_stamp,
fw_stamp: self.fw_stamp,
fw_stamp,
})
}
}
Expand Down Expand Up @@ -211,26 +222,24 @@ fn init_notifier(page: &FwObject, threshold: &FwObject) -> Result {
}

struct ComputeGraphSession {
sched_ctx: Arc<FwObject>,
notifier: Arc<FwObject>,
threshold: Arc<FwObject>,
job_list: Arc<FwObject>,
q: QueueSession,
}
impl ComputeGraphSession {
fn new(o: &mut Objects, sched_ctx: Arc<FwObject>) -> Result<Self> {
fn new(o: &mut Objects) -> Result<Self> {
Ok(Self {
sched_ctx,
notifier: alloc(o, 0x1000, Class::FwCached, None, 0, false)?,
threshold: alloc(o, 24, Class::Fw, None, 0, false)?,
job_list: alloc(o, job_list::SIZE, graph_fw(), None, 0, false)?,
q: QueueSession::new(o)?,
})
}
fn finish(self, rings: &mut Objects) -> Result<ComputeGraph> {
fn finish(self, rings: &mut Objects, sched_ctx: Arc<FwObject>) -> Result<ComputeGraph> {
let q = self.q.finish(rings)?;
Ok(ComputeGraph {
sched_ctx: self.sched_ctx,
sched_ctx,
notifier: self.notifier,
threshold: self.threshold,
job_list: self.job_list,
Expand All @@ -247,7 +256,7 @@ impl ComputeGraphSession {
impl ComputeGraph {
#[allow(dead_code)]
fn new(o: &mut Objects, rings: &mut Objects, sched_ctx: Arc<FwObject>) -> Result<Self> {
ComputeGraphSession::new(o, sched_ctx)?.finish(rings)
ComputeGraphSession::new(o)?.finish(rings, sched_ctx)
}
fn init(&self, abi: FwAbi, init_ctx: bool) -> Result {
if init_ctx {
Expand Down Expand Up @@ -289,19 +298,17 @@ pub(crate) struct RenderGraph {
struct RenderGraphSession {
ta: QueueSession,
fs: QueueSession,
sched_ctx: Arc<FwObject>,
notifier: Arc<FwObject>,
threshold: Arc<FwObject>,
job_list: [Arc<FwObject>; 2],
legacy_empty: Arc<FwObject>,
registration_barrier: Arc<FwObject>,
}
impl RenderGraphSession {
fn new(o: &mut Objects, context: Arc<FwObject>) -> Result<Self> {
fn new(o: &mut Objects) -> Result<Self> {
Ok(Self {
ta: QueueSession::new(o)?,
fs: QueueSession::new(o)?,
sched_ctx: context,
fs: QueueSession::new_with(o, None)?,
notifier: alloc(o, 0x1000, Class::Fw, None, 0, false)?,
threshold: alloc(o, 24, Class::Fw, None, 0, false)?,
job_list: [
Expand All @@ -319,7 +326,7 @@ impl RenderGraphSession {
)?,
})
}
fn finish(self, rings: &mut Objects) -> Result<RenderGraph> {
fn finish(self, rings: &mut Objects, sched_ctx: Arc<FwObject>) -> Result<RenderGraph> {
let [ta, fs] = [self.ta.finish(rings)?, self.fs.finish(rings)?];
Ok(RenderGraph {
qscratch: [ta.qinfo.clone(), fs.qinfo.clone()],
Expand All @@ -328,7 +335,7 @@ impl RenderGraphSession {
ring: [ta.ring, fs.ring],
user_stamp: [ta.user_stamp, fs.user_stamp],
fw_stamp: [ta.fw_stamp, fs.fw_stamp],
sched_ctx: self.sched_ctx,
sched_ctx,
notifier: self.notifier,
threshold: self.threshold,
job_list: self.job_list,
Expand All @@ -341,7 +348,7 @@ impl RenderGraphSession {
impl RenderGraph {
#[allow(dead_code)]
fn new(o: &mut Objects, rings: &mut Objects, context: Arc<FwObject>) -> Result<Self> {
RenderGraphSession::new(o, context)?.finish(rings)
RenderGraphSession::new(o)?.finish(rings, context)
}
fn init(&self, abi: FwAbi) -> Result {
init_notifier(&self.notifier, &self.threshold)?;
Expand Down Expand Up @@ -373,20 +380,18 @@ pub(crate) struct Graphs {
pub(crate) dev: ARef<device::Device>,
pub(crate) compute: KVec<ComputeGraph>,
pub(crate) render: RenderGraph,
/// Owns the firmware-cached work rings for the device lifetime (never dropped).
/// Owns the firmware-cached work rings and shared scheduling context for the device lifetime
/// (never dropped).
_ring_objects: core::mem::ManuallyDrop<Objects>,
}
impl Graphs {
#[inline(never)]
pub(crate) fn prepare(o: &mut Objects) -> Result<GraphSession> {
// Host polls sched_ctx from WC during register_context(); keep uncached and share one
// scheduling context across all compute pipes and the render graph.
let sched_ctx = alloc(o, sched_ctx::SIZE, Class::Fw, None, 0, false)?;
let mut compute = KVec::with_capacity(sizes::COMPUTE_PIPES, GFP_KERNEL)?;
for _ in 0..sizes::COMPUTE_PIPES {
compute.push(ComputeGraphSession::new(o, sched_ctx.clone())?, GFP_KERNEL)?;
compute.push(ComputeGraphSession::new(o)?, GFP_KERNEL)?;
}
let render = RenderGraphSession::new(o, sched_ctx)?;
let render = RenderGraphSession::new(o)?;
Ok(GraphSession { compute, render })
}

Expand All @@ -398,11 +403,23 @@ impl Graphs {
) -> Result<Self> {
// Never dropped even on partial failure: ASC-cached mappings have no qualified teardown.
let mut ring_objects = core::mem::ManuallyDrop::new(factory.persistent_objects_probe());
// Share one ASC-cached scheduling context across all compute pipes and the render graph,
// matching macOS 26B123 (`0x443`). `register_context()` syncs the cacheable host view
// before polling registration once at boot; firmware reads and writes it on every kick
// and completion.
let sched_ctx = alloc(
&mut ring_objects,
sched_ctx::SIZE,
Class::FwCoherent,
None,
0,
false,
)?;
let mut compute = KVec::with_capacity(sizes::COMPUTE_PIPES, GFP_KERNEL)?;
for c in session.compute {
compute.push(c.finish(&mut ring_objects)?, GFP_KERNEL)?;
compute.push(c.finish(&mut ring_objects, sched_ctx.clone())?, GFP_KERNEL)?;
}
let render = session.render.finish(&mut ring_objects)?;
let render = session.render.finish(&mut ring_objects, sched_ctx)?;
ring_objects.finish_private()?;
Ok(Self {
dev: dev.as_ref().as_ref().into(),
Expand Down
9 changes: 8 additions & 1 deletion drivers/gpu/drm/asahi/g16/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,14 @@ impl Firmware {
let recovery = recovery::Recovery::new()?;
let render_cmds = resources::RenderCmds::new()?;
let compute_cmds = resources::ComputeCmds::new()?;
let private_factory = booted.objects.private_factory(render_cmds, compute_cmds);
let render_uma_pool = resources::RenderUmaPool::new()?;
let pb_record_pool = resources::PbRecordPool::new()?;
let private_factory = booted.objects.private_factory(
render_cmds,
compute_cmds,
render_uma_pool,
pb_record_pool,
);
let graph = graph::Graphs::finish(dev, graph_session, &private_factory)?;
let slot = KBox::<Firmware>::new_uninit(GFP_KERNEL)?;
Ok((graph, private_factory, slots, pools, vms, engine, recovery, slot))
Expand Down
55 changes: 55 additions & 0 deletions drivers/gpu/drm/asahi/g16/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ pub(crate) struct Factory {
firmware: core::ops::Range<u64>,
render_cmds: Arc<super::resources::RenderCmds>,
compute_cmds: Arc<super::resources::ComputeCmds>,
render_uma_pool: Arc<super::resources::RenderUmaPool>,
pb_record_pool: Arc<super::resources::PbRecordPool>,
}

impl Factory {
Expand Down Expand Up @@ -492,6 +494,14 @@ impl Factory {
pub(crate) fn compute_cmds(&self, k: usize) -> Result<super::slots::UnitCmds> {
self.compute_cmds.get(self, k)
}

pub(crate) fn render_uma_pool(&self) -> &Arc<super::resources::RenderUmaPool> {
&self.render_uma_pool
}

pub(crate) fn pb_record_pool(&self) -> &Arc<super::resources::PbRecordPool> {
&self.pb_record_pool
}
}

/// The firmware object allocator and the set of retained objects.
Expand Down Expand Up @@ -553,6 +563,8 @@ impl Objects {
&mut self,
render_cmds: Arc<super::resources::RenderCmds>,
compute_cmds: Arc<super::resources::ComputeCmds>,
render_uma_pool: Arc<super::resources::RenderUmaPool>,
pb_record_pool: Arc<super::resources::PbRecordPool>,
) -> Factory {
self.sealed = true;
Factory {
Expand All @@ -562,6 +574,8 @@ impl Objects {
firmware: self.fw_next..hw::va::FW_ALLOC.end,
render_cmds,
compute_cmds,
render_uma_pool,
pb_record_pool,
}
}

Expand All @@ -573,6 +587,7 @@ impl Objects {
self.alloc_private_in(req, None)
}

#[allow(dead_code)]
pub(crate) fn alloc_dynamic_client(&mut self, size: usize) -> Result<Arc<FwObject>> {
self.alloc_private_in(
Request {
Expand All @@ -588,6 +603,46 @@ impl Objects {
)
}

/// Maps an existing uncached firmware object into this arena's user VM at fixed `gva` inside
/// [`hw::client::DYNAMIC`] with a trailing guard page.
///
/// Used by [`super::pools::PbEpoch`] to alias a persistent context-0 `Class::Shared` PB page
/// list at its record set's immutable `pages_gpu` address while the epoch owns the record set;
/// dropping this `Objects` unmaps the client alias before the record lease can be recycled.
pub(crate) fn map_client_at(&mut self, object: &Arc<FwObject>, gva: u64) -> Result {
if object.cached_cpu || object.offset != 0 {
return Err(EINVAL);
}
let bytes = object.bytes;
if bytes == 0 || bytes & (hw::PAGE as usize - 1) != 0 || gva & (hw::PAGE - 1) != 0 {
return Err(EINVAL);
}
let end = gva
.checked_add(bytes as u64)
.and_then(|end| end.checked_add(hw::PAGE))
.ok_or(EOVERFLOW)?;
if gva < hw::client::DYNAMIC.start || end > hw::client::DYNAMIC.end {
return Err(EINVAL);
}
let vm = self
.private
.as_ref()
.and_then(|private| private.vm.as_ref())
.ok_or(EINVAL)?
.clone();
self.mappings.reserve(1, GFP_KERNEL)?;
let mapping = vm.map_at(
gva,
bytes,
&object.gem(),
mmu::Prot::from_pte(pte::LEAF_NC),
true,
)?;
let _ = self.mappings.push_within_capacity(mapping);
wmb();
Ok(())
}

fn alloc_private_in(
&mut self,
req: Request,
Expand Down
Loading
Loading