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
1 change: 0 additions & 1 deletion drivers/gpu/drm/asahi/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,6 @@ impl File {
if op.offset.checked_add(accessed).ok_or(EINVAL)? > u64::try_from(object.size())? {
return Err(EINVAL);
}
vm.validate_context_binding(op.addr, op.range, single_page)?;
batch.push_map(vm.prepare_bind_object(
&object,
op.addr,
Expand Down
4 changes: 1 addition & 3 deletions drivers/gpu/drm/asahi/g17/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3127,9 +3127,7 @@ impl gpu::Gpu for Gpu {
/// with no fault reported (measured on the M4 Pro, firmware 25G83). The driver gives every
/// queue of the family the same fault setting, 1 in `QueueConfig::unk_66`, the word the M5
/// firmware names soft_fault_enabled, so this is not a per-SoC property. Advertise it unless
/// fault_control asks for anything else. The first 0x74000 bytes of a client VM are mapped,
/// not unmapped memory: they hold the execution context's views (`CONTEXT_VIEWS`, the null
/// view at address 0).
/// fault_control asks for anything else.
fn supports_soft_faults(&self) -> bool {
crate::module_parameters::fault_control.value() == 0xb
}
Expand Down
1 change: 0 additions & 1 deletion drivers/gpu/drm/asahi/g17/queue/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ impl Graph {
return Err(EFAULT);
}
let vm = context.vm();
if !self.m5 { vm.install_job_context_aliases()?; }
let descriptors = self.descriptor_alias(vm)?;
let prot = if self.m5 { mmu::PROT_GPU_SHARED_RW } else { mmu::PROT_GPU_FW_SHARED_RW };
let page = mmu::UAT_PGSZ as u64;
Expand Down
28 changes: 0 additions & 28 deletions drivers/gpu/drm/asahi/hw/t8140.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,34 +406,6 @@ pub(crate) mod resources {
}
}

/// Canonical userspace resource and its presentation in an execution context.
#[derive(Clone, Copy)]
pub(crate) struct ContextView {
pub(crate) source: u64,
pub(crate) low: u64,
pub(crate) size: usize,
pub(crate) write: bool,
}

const fn context_view(low: u64, size: usize, write: bool) -> ContextView {
ContextView {
source: 0x10_0000_0000 + low,
low,
size,
write,
}
}

pub(crate) const CONTEXT_VIEWS: [ContextView; 7] = [
context_view(0, 0x10000, false),
context_view(0x18000, 0x8000, false),
context_view(0x28000, 0x8000, false),
context_view(0x38000, 0x8000, false),
context_view(0x48000, 0x8000, false),
context_view(0x58000, 0x8000, true),
context_view(0x68000, 0xc000, true),
];

/// Scheduler accounting policy and its firmware clock domain.
pub(crate) mod qos {
pub(crate) const CLASS: u8 = 0x0f;
Expand Down
58 changes: 49 additions & 9 deletions drivers/gpu/drm/asahi/mmu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ pub(crate) use pgtable::{
const DEBUG_CLASS: DebugFlags = DebugFlags::Mmu;

mod bind;
mod context;
mod layout;

mod lifetime;
Expand Down Expand Up @@ -1346,7 +1345,6 @@ pub(crate) struct Vm {
bind_sequence: Arc<AtomicU64>,
lifetime: Option<Arc<lifetime::VmLifetime>>,
residency: Option<Arc<residency::Gate>>,
context_bindings: Option<Arc<context::ContextBindings>>,
shared_bindings: Option<Arc<shared::SharedBindings>>,
status: Option<Arc<crate::g17::status::VmStatus>>,
/// The memory accounting of the client that created this VM, which kernel memory sized
Expand Down Expand Up @@ -2692,7 +2690,6 @@ impl Vm {
bind_sequence,
lifetime: None,
residency: None,
context_bindings: None,
shared_bindings: None,
status: None,
memory: None,
Expand Down Expand Up @@ -2723,13 +2720,12 @@ impl Vm {
)?);
self.lifetime = Some(lifetime::VmLifetime::new()?);
self.residency = Some(residency::Gate::new()?);
self.context_bindings = Some(context::ContextBindings::new()?);
self.shared_bindings = Some(shared::SharedBindings::new()?);
Ok(self)
}

/// Attach a status and job lifetime tracking before sharing a newly created user VM with
/// queues, without the G17 canonical context views, shared-object footprints and idle
/// queues, without the G17 shared-object footprints and idle
/// residency reclaim of [`Self::with_status`]. Used by G15, whose user objects stay pinned.
#[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))]
pub(crate) fn with_tracked_status(mut self) -> Result<Self> {
Expand Down Expand Up @@ -3448,7 +3444,6 @@ impl Vm {
if result.is_ok() {
// The close callback or deferred object list retains this GEM,
// so clearing its candidate cannot release its final reference.
self.untrack_context_object(gem);
self.untrack_shared_object(gem);
}
mod_dev_dbg!(self.dev, "MMU: bo_unmap done\n");
Expand Down Expand Up @@ -3493,7 +3488,6 @@ impl Vm {
mod_dev_dbg!(self.dev, "MMU: deferred bo_unmap\n");
let result = vm_exec.unique_gpuvm.bo_unmap(&mut ctx, &bo);
if result.is_ok() {
self.untrack_context_object_before(gem, sequence);
self.untrack_shared_object_before(gem, sequence);
}
drop(vm_exec);
Expand All @@ -3514,7 +3508,6 @@ impl Vm {
VmInner::unmap_gpuva,
);
if result.is_ok() {
self.untrack_context_object_before(gem, sequence);
self.untrack_shared_object_before(gem, sequence);
}
drop(inner);
Expand All @@ -3528,14 +3521,61 @@ impl Vm {
let mut inner = self.gpuvm.lock_inner();
let result = inner.unmap_object(gem, VmInner::unmap_gpuva);
if result.is_ok() {
self.untrack_context_object(gem);
self.untrack_shared_object(gem);
}
drop(inner);
self.bo_deferred_cleanup();
result
}

pub(crate) fn translate_iova(&self, address: u64) -> Result<u64> {
// SAFETY: See `lock_vm()`. A page-table read needs only the VM's own reservation, not
// every external object's: G18 translates each page of a job's mappings on every
// submission, and locking all external objects made each translation cost O(external
// objects).
let mut vm_exec = unsafe { self.gpuvm.exec_lock_vm(None, false)? };
vm_exec.unique_gpuvm.data().page_table.translate_iova(address)
}

/// [`Self::translate_iova`] of `address + k * UAT_PGSZ` for each `k` below
/// `bytes.div_ceil(UAT_PGSZ)`, under one lock and one page-table walk.
pub(crate) fn translate_pages(&self, address: u64, bytes: usize) -> Result<KVec<u64>> {
let offset = address & UAT_PGMSK as u64;
let start = address - offset;
let pages = bytes.div_ceil(UAT_PGSZ);
let end = start.checked_add((pages as u64) << UAT_PGBIT).ok_or(EINVAL)?;
let mut physical = KVec::from_elem(0u64, pages, GFP_KERNEL)?;
if pages == 0 {
return Ok(physical);
}
{
// SAFETY: See `lock_vm()`, and `translate_iova()` for why the VM's reservation
// suffices.
let mut vm_exec = unsafe { self.gpuvm.exec_lock_vm(None, false)? };
vm_exec
.unique_gpuvm
.data()
.page_table
.translate_pages(start..end, &mut physical)?;
}
for frame in physical.iter_mut() {
*frame |= offset;
}
Ok(physical)
}

/// [`Self::translate_iova`] for each of `addresses`, under one lock.
pub(crate) fn translate_each(&self, addresses: &[u64]) -> Result<KVec<u64>> {
let mut physical = KVec::with_capacity(addresses.len(), GFP_KERNEL)?;
// SAFETY: As in `translate_pages()`.
let mut vm_exec = unsafe { self.gpuvm.exec_lock_vm(None, false)? };
let page_table = &mut vm_exec.unique_gpuvm.data().page_table;
for &address in addresses {
physical.push(page_table.translate_iova(address)?, GFP_KERNEL)?;
}
Ok(physical)
}

/// Returns the dummy GEM object used to hold the shared DMA reservation locks
pub(crate) fn get_resv_obj(&self) -> ARef<gem::Object> {
self.dummy_obj.clone()
Expand Down
23 changes: 4 additions & 19 deletions drivers/gpu/drm/asahi/mmu/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub(crate) struct PreparedUserMap {
offset: u64,
single_page: bool,
sparse_tile: bool,
context: context::PreparedBinding,
_residency: Option<residency::Lease>,
_sg_lease: kernel::drm::gem::shmem::SGLease<gem::AsahiObject>,
}
Expand Down Expand Up @@ -91,7 +90,6 @@ impl Vm {
}
gem::validate_vm_binding(gem, self)?;
let residency = self.enter_residency_metadata()?;
let context = self.prepare_context_binding(addr, size, offset)?;
let resources = VmOpResources::with_gpuvas(self.memory_client())?;
// SAFETY: As in `Vm::bind_object()`, the device is bound while its file can issue binds.
let dev = unsafe { self.dev.as_bound() };
Expand Down Expand Up @@ -119,7 +117,6 @@ impl Vm {
offset,
single_page,
sparse_tile,
context,
})
}

Expand Down Expand Up @@ -176,12 +173,7 @@ impl Vm {
context: &mut ctx,
flags,
});
let retired = result.is_ok().then(|| {
let retired = self.commit_context_binding(
&map.gem,
&map.context,
ctx.bind_sequence,
);
if result.is_ok() {
self.track_shared_binding(
&map.gem,
map.addr,
Expand All @@ -190,11 +182,9 @@ impl Vm {
map.single_page,
ctx.bind_sequence,
);
retired
});
}
drop(inner);
drop(commit);
drop(retired);
Some(result)
}
Err(error) if error == EIO => {
Expand All @@ -215,16 +205,11 @@ impl Vm {
inner
.unique_gpuvm
.sm_unmap(unmap.iova, unmap.size, &mut ctx);
let retired = result.is_ok().then(|| {
let retired = self.untrack_context_ranges(core::iter::once(
unmap.iova..unmap.iova + unmap.size,
));
if result.is_ok() {
self.untrack_shared_range(unmap.iova, unmap.size);
retired
});
}
drop(inner);
drop(commit);
drop(retired);
Some(result)
}
Err(error) if error == EIO => {
Expand Down
Loading
Loading