Skip to content
Open
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: 1 addition & 1 deletion drivers/gpu/drm/asahi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ aurora-$(CONFIG_DRM_ASAHI_UAT_ADOPTION) += g15/uat_glue.o

aurora-$(CONFIG_DRM_ASAHI_G16) += g16/glue.o

aurora-y += retain.o sleep_pd.o cpu_capacity.o g17/mesh_tvb_floor.o rtkit_dump.o
aurora-y += memcg_scope.o retain.o sleep_pd.o cpu_capacity.o g17/mesh_tvb_floor.o rtkit_dump.o
aurora-$(CONFIG_DRM_ASAHI_G18) += g18/sync_input.o
aurora-$(CONFIG_DRM_ASAHI_G18) += g18/demand.o
26 changes: 26 additions & 0 deletions drivers/gpu/drm/asahi/g17/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,24 @@ pub(crate) struct FirmwarePages {
_qos: Arc<QosLease>,
}

/// One compute command of an owner, from before its SUBMIT provisions the owner's compute backing
/// until the command is dropped. While any is held, what the owner was given back for its
/// publications is kept for them ([`Context::compute_claimed`]).
pub(crate) struct ComputeClaim(Arc<Context>);

impl ComputeClaim {
pub(crate) fn new(context: &Arc<Context>) -> Self {
context.compute_claims.fetch_add(1, Ordering::AcqRel);
Self(context.clone())
}
}

impl Drop for ComputeClaim {
fn drop(&mut self) {
self.0.compute_claims.fetch_sub(1, Ordering::AcqRel);
}
}

pub(crate) struct Context {
/// The GPU runs the M5 firmware's protocol.
m5: bool,
Expand All @@ -226,6 +244,9 @@ pub(crate) struct Context {
/// Advisory count of bound compute channels: publication still checks the physical binding
/// under the device mutex. Zero skips an inline attempt known to need admission.
compute_bindings: AtomicU32,
/// This owner's compute commands from before their SUBMIT provisioned them until they are
/// dropped ([`ComputeClaim`]): while there are any, the owner's spare compute backing stays.
compute_claims: AtomicU32,
/// Shared monotonic compute completion ordinal / submit sequence across an M5 multi-channel
/// context's physical compute queues.
compute_ordinal: AtomicU32,
Expand Down Expand Up @@ -386,6 +407,7 @@ impl Context {
closed_generation: AtomicU64::new(u64::MAX),
closed_for_open_client: AtomicBool::new(false),
compute_bindings: AtomicU32::new(0),
compute_claims: AtomicU32::new(0),
compute_ordinal: AtomicU32::new(0),
render_seen: AtomicBool::new(false),
render_active: AtomicU32::new(0),
Expand Down Expand Up @@ -431,6 +453,10 @@ impl Context {
self.render_seen.store(true, Ordering::Release);
}
}
/// Whether a compute command of this owner holds a [`ComputeClaim`].
pub(crate) fn compute_claimed(&self) -> bool {
self.compute_claims.load(Ordering::Acquire) != 0
}
/// Active (published and unretired) render count for this context.
pub(crate) fn render_active(&self) -> u32 {
self.render_active.load(Ordering::Acquire)
Expand Down
88 changes: 61 additions & 27 deletions drivers/gpu/drm/asahi/g17/freelist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,20 @@ impl Drop for Pages {
LOWER_FREED.fetch_add(1, Ordering::AcqRel);
}
}
impl super::queue::compute::reserve::Capacity for Pages {
fn fits(&self, required: ComputeCapacity) -> bool {
self.fits_capacity(required)
}
fn covers(&self, other: &Self) -> bool {
match (self.layout, other.layout) {
(PageLayout::Neo { blocks, .. }, PageLayout::Neo { blocks: other, .. }) => blocks >= other,
(PageLayout::M5(geometry), PageLayout::M5(other)) =>
geometry.block_bytes() == other.block_bytes() && geometry.blocks >= other.blocks,
_ => false,
}
}
}

impl Pages {
fn new(alloc: &Allocator<'_>, blocks: usize, runs: RunLayout) -> Result<Self> {
let size = TABLE_SIZE + blocks * FREE_LIST_BLOCK_SIZE;
Expand Down Expand Up @@ -394,8 +408,9 @@ impl Pages {
let (backing, charge) = match client {
Some(client) => {
let commit = crate::memacct::LEDGER.admit(client, size as u64)?;
let backing = alloc.lower_user_charged(size, mmu::UAT_PGSZ as u64,
mmu::PROT_GPU_SHARED_RW)?;
let backing = client.charging(|| alloc.lower_user_charged(
size, mmu::UAT_PGSZ as u64, mmu::PROT_GPU_SHARED_RW,
))?;
let charge = crate::memacct::Charge::user(commit, None);
charge.set_held(true);
(backing, Some(charge))
Expand Down Expand Up @@ -455,6 +470,19 @@ impl Pages {
_ => false,
}
}
/// Writes the tables of fresh backing again, for reuse by the owner that gave this backing
/// back. The caller has seen the firmware consume the pool's release.
pub(crate) fn reset(&mut self) -> Result {
match self.layout {
PageLayout::Neo { blocks, runs } => {
let base = self.backing.gpu_va();
self.backing.initialize::<PoolTables>(0, |tables| tables.init(base, blocks, runs))?;
}
PageLayout::M5(_) => self.populate_m5()?,
}
fence(Ordering::SeqCst);
Ok(())
}
fn is_m5(&self) -> bool { matches!(self.layout, PageLayout::M5(_)) }
pub(crate) fn page_list_va(&self) -> u64 { self.backing.gpu_va() }
fn run_list_va(&self) -> u64 {
Expand Down Expand Up @@ -1043,6 +1071,23 @@ impl Submitted<'_> {
/// that VM's work, so a view of it in another VM is refused
/// ([`Self::map_client`]). Another VM gets the queue only after the backing
/// was given back and fresh, zeroed backing installed ([`Self::rearm`]).
/// The control and state objects of a compute pool, allocated before a QID is reserved for it.
pub(crate) struct PoolObjects {
control: KernelObject,
state: KernelObject,
}
impl PoolObjects {
pub(crate) fn new(alloc: &Allocator<'_>) -> Result<Self> {
let object = || alloc.kernel(
CONTROL_SIZE,
mmu::UAT_PGSZ as u64,
mmu::PROT_GPU_FW_SHARED_RW,
CpuMap::WriteCombined,
);
Ok(Self { control: object()?, state: object()? })
}
}

pub(crate) struct ComputePool {
pages: Option<Pages>,
/// The VM (`mmu::Vm::id`) the backing serves, from its first client view
Expand All @@ -1059,33 +1104,22 @@ impl ComputePool {
self.pages.as_ref().is_some_and(|pages| pages.fits_capacity(required))
}

/// A pool at the admitted capacity, in the capacity's family format.
pub(crate) fn new(alloc: &Allocator<'_>, qid: u8, required: ComputeCapacity,
client: Option<&Arc<crate::memacct::Client>>) -> Result<Self> {
if qid > super::fw::kick::QID_MAX {
return Err(EINVAL);
}
let pages = Pages::for_compute(alloc, required, client)?;
/// Binds `objects` and `pages` to the pool slot of `qid`: stores only.
pub(crate) fn prepare(objects: &mut PoolObjects, qid: u8, pages: &Pages) -> Result {
if qid > super::fw::kick::QID_MAX { return Err(EINVAL); }
Self::initialize_control(&mut objects.control, pages, Self::slot(qid), objects.state.gpu_va(), [0; 8])?;
fence(Ordering::SeqCst);
Ok(())
}

pub(crate) fn bind(objects: PoolObjects, qid: u8, pages: Pages, client_vm: u64) -> Self {
let PoolObjects { control, state } = objects;
let m5 = pages.is_m5();
Self::with_pages(alloc, qid, m5, pages)
Self { pages: Some(pages), client_vm, control, state, id: Self::slot(qid), m5 }
}
fn with_pages(alloc: &Allocator<'_>, qid: u8, m5: bool, pages: Pages) -> Result<Self> {
let id = u16::from(qid) + 1;
let mut control = alloc.kernel(
CONTROL_SIZE,
mmu::UAT_PGSZ as u64,
mmu::PROT_GPU_FW_SHARED_RW,
CpuMap::WriteCombined,
)?;
let state = alloc.kernel(
CONTROL_SIZE,
mmu::UAT_PGSZ as u64,
mmu::PROT_GPU_FW_SHARED_RW,
CpuMap::WriteCombined,
)?;
Self::initialize_control(&mut control, &pages, id, state.gpu_va(), [0; 8])?;
fence(Ordering::SeqCst);
Ok(Self { pages: Some(pages), client_vm: 0, control, state, id, m5 })
/// The pool slot (buffer slot) of `qid`'s pool.
pub(crate) fn slot(qid: u8) -> u16 {
u16::from(qid) + 1
}
fn initialize_control(control: &mut KernelObject, pages: &Pages, id: u16,
submitted: u64, completed: [u8; 8]) -> Result {
Expand Down
6 changes: 6 additions & 0 deletions drivers/gpu/drm/asahi/g17/fw/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ pub(crate) enum ComputeProgram {
V25F84,
}

impl ComputeProgram {
pub(crate) fn needs_shared_aperture(self) -> bool {
matches!(self, Self::G17P)
}
}

const V25F84_REGISTERS: usize = 36;
const V25F84_REGISTERS_MAX: usize = V25F84_REGISTERS + 1;
const V25F84_CHECKPOINTS: [u16; 4] = [34, 35, 35, V25F84_REGISTERS as u16];
Expand Down
4 changes: 4 additions & 0 deletions drivers/gpu/drm/asahi/g17/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ pub(crate) struct Packet {
pub(crate) order: Order,
pub(crate) completion: Arc<Completion>,
pub(crate) footprint: Option<Arc<super::hazard::Footprint>>,
/// A compute command's hold on its owner's spare compute backing.
_claim: Option<super::context::ComputeClaim>,
/// Number of render passes in the submit ioctl that created this packet.
pub(crate) batch_renders: u16,
inputs: KVec<Fence>,
Expand Down Expand Up @@ -168,6 +170,7 @@ impl Packet {
batch_renders: u16,
inputs: KVec<Fence>,
producers: Option<Producers>,
claim: Option<super::context::ComputeClaim>,
) -> Result<Arc<Self>> {
let footprint = match &command {
Validated::Render { attachments, pass, .. } => {
Expand All @@ -185,6 +188,7 @@ impl Packet {
order,
completion,
footprint,
_claim: claim,
batch_renders,
inputs,
producers,
Expand Down
29 changes: 22 additions & 7 deletions drivers/gpu/drm/asahi/g17/kick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,11 +622,14 @@ impl PreparedKick<'_> {
}
}

impl Queue {
pub(crate) fn compute(alloc: &Allocator<'_>, id: Id) -> Result<Self> {
if id.engine != DataMaster::Compute {
return Err(EINVAL);
}
/// Storage of a compute queue's kick ring, allocated before a QID is reserved for it.
pub(crate) struct ComputeRing {
high: mmu::KernelMapping,
low: KernelObject,
}

impl ComputeRing {
pub(crate) fn new(alloc: &Allocator<'_>) -> Result<Self> {
let low = alloc.lower(
KICK_RING_SIZE,
mmu::UAT_PGSZ as u64,
Expand All @@ -641,12 +644,24 @@ impl Queue {
mmu::PROT_FW_SHARED_RW,
)?;
fence(Ordering::SeqCst);
Ok(Self {
Ok(Self { high, low })
}

pub(crate) fn map_client(&self, vm: &mmu::Vm) -> Result<mmu::KernelMapping> {
self.low.map_alias(vm, self.low.gpu_va(), CLIENT_KICK_PROT)
}
}

impl Queue {
/// Binds `ring` to the QID of `id`: stores only.
pub(crate) fn compute(ring: ComputeRing, id: Id) -> Self {
let ComputeRing { high, low } = ring;
Self {
backing: Backing::Compute { high, low },
id,
timestamp: KickTimestamp::FIRST,
previous: None,
})
}
}

/// Retired storage of a never-written ring is reused first. The returned view of the ring
Expand Down
46 changes: 4 additions & 42 deletions drivers/gpu/drm/asahi/g17/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,13 @@ use kernel::{
IoSysMap,
Region, //
},
new_condvar, new_delayed_work, new_mutex, new_work, platform,
new_delayed_work, new_mutex, new_work, platform,
prelude::*,
soc::apple::rtkit,
sync::{
aref::ARef,
Arc,
ArcBorrow,
CondVar,
Mutex, //
},
time::{
Expand Down Expand Up @@ -1309,39 +1308,6 @@ const GOVERNOR_WORK: u64 = 6;
/// `HOUSEKEEPING_NS`.
const HOUSEKEEPING_WORK: u64 = 7;

/// `CondVar` wrapper that tracks active waiters so `notify_all()` skips the waitqueue lock
/// in the common zero-waiter steady state.
#[pin_data]
struct TrackedCondVar {
#[pin]
condvar: CondVar,
waiters: AtomicU32,
}

impl TrackedCondVar {
fn wait_timeout<T: ?Sized>(
&self,
guard: &mut kernel::sync::MutexGuard<'_, T>,
timeout: kernel::time::Jiffies,
) -> kernel::sync::CondVarTimeoutResult {
struct Waiter<'a>(&'a AtomicU32);
impl Drop for Waiter<'_> {
fn drop(&mut self) {
self.0.fetch_sub(1, Ordering::Release);
}
}
self.waiters.fetch_add(1, Ordering::SeqCst);
let _waiter = Waiter(&self.waiters);
self.condvar.wait_timeout(guard, timeout)
}

fn notify_all(&self) {
if self.waiters.load(Ordering::SeqCst) != 0 {
self.condvar.notify_all();
}
}
}

/// Device state shared with the coprocessor callbacks and the event worker.
#[pin_data]
struct Shared {
Expand Down Expand Up @@ -1386,6 +1352,8 @@ struct Shared {
#[pin]
feed_work: Work<Shared, FEED_WORK>,
preparations: Arc<preparation::Gate>,
#[pin]
compute_provision: Mutex<()>,
/// Compute admission waiting for a physical channel: signalled when a channel becomes
/// reusable or shareable, a QID or slot is returned, or a pool vacancy is witnessed.
channels: Arc<availability::Availability>,
Expand Down Expand Up @@ -1475,8 +1443,6 @@ struct Shared {
/// fan boost. Never taken with `state` held.
#[pin]
actuators: Mutex<thermal::Actuators>,
#[pin]
changed: TrackedCondVar,
/// The port of the session in `state`; null before boot and once detachment begins.
port: core::sync::atomic::AtomicPtr<port::Port>,
}
Expand Down Expand Up @@ -1799,7 +1765,6 @@ impl Shared {

/// Wakes the waiters for a returned pair, binding or capacity change.
fn note_changed(&self) {
self.changed.notify_all();
self.renders.notify();
}

Expand Down Expand Up @@ -2325,11 +2290,8 @@ impl Gpu {
reclaim <- new_mutex!(reclaim, "g17::Shared::reclaim"),
stop <- new_mutex!((), "g17::Shared::stop"),
state <- new_mutex!(None, "g17::Shared::state"),
compute_provision <- new_mutex!((), "g17 compute provisioning"),
actuators <- new_mutex!(thermal::Actuators::new(), "g17::Shared::actuators"),
changed <- pin_init!(TrackedCondVar {
condvar <- new_condvar!("g17::Shared::changed"),
waiters: AtomicU32::new(0),
}),
port: core::sync::atomic::AtomicPtr::new(core::ptr::null_mut()),
}),
GFP_KERNEL,
Expand Down
Loading
Loading