diff --git a/drivers/gpu/drm/asahi/hw/t6050.rs b/drivers/gpu/drm/asahi/hw/t6050.rs index 57382e9622126..b53b3dec3123a 100644 --- a/drivers/gpu/drm/asahi/hw/t6050.rs +++ b/drivers/gpu/drm/asahi/hw/t6050.rs @@ -33,8 +33,14 @@ pub(crate) const CONFIG: Config = Config { reserved_slots: &[], perf: None, opps: 0, - // The M5 Max and Ultra's UAT policy, for the same firmware family. - uat_quirks: CONFIG_ULTRA.uat_quirks, + // The M5 Max and Ultra's UAT policy, for the same firmware family, with ranges invalidated + // by range TLBI operations (`tlbi rvae1os`, ARMv8.4) instead of one `tlbi vae1os` per page + // and a whole-ASID flush past 2048 pages. Table writes are still cleaned to the point of + // coherency: no M4 or M5 SoC has run with a walker assumed to snoop the CPU caches. + uat_quirks: crate::mmu::UatQuirks { + page_tlbi: false, + ..CONFIG_ULTRA.uat_quirks + }, region_c: None, chip: None, m5: Some(&crate::g17::fw::m5::initdata::J714), diff --git a/drivers/gpu/drm/asahi/mem.rs b/drivers/gpu/drm/asahi/mem.rs index 1f4518be0bf29..59f3722bbf286 100644 --- a/drivers/gpu/drm/asahi/mem.rs +++ b/drivers/gpu/drm/asahi/mem.rs @@ -34,13 +34,27 @@ pub(crate) fn set_page_tlbi(enabled: bool) { PAGE_TLBI.store(enabled, Ordering::Relaxed); } -/// Invalidates `len` bytes at `va` one 16 KiB page at a time, or the whole ASID above -/// [`PAGE_TLBI_MAX_PAGES`]. +/// Upper half of the GPU VA space. It holds the kernel mappings, the only ones whose leaves are +/// global (nG clear), and `tlbi aside1os` leaves global entries cached. A range here is +/// invalidated by VA, which matches global entries whatever the ASID, or with `tlbi vmalle1os`. +const UAT_UPPER_HALF: usize = 1 << 63; + +/// Whether `va` lies in the upper half, where leaves may be global. +fn may_be_global(va: usize) -> bool { + va & UAT_UPPER_HALF != 0 +} + +/// Invalidates `len` bytes at `va` one 16 KiB page at a time. Above [`PAGE_TLBI_MAX_PAGES`], it +/// invalidates the whole ASID instead, or every entry for an upper-half range. fn tlbi_pages(asid: Asid, va: usize, len: usize) { let start = va >> mmu::UAT_PGBIT; let end = (va + len + mmu::UAT_PGMSK) >> mmu::UAT_PGBIT; if end - start > PAGE_TLBI_MAX_PAGES { - tlbi_asid(asid); + if may_be_global(va) { + tlbi_all(); + } else { + tlbi_asid(asid); + } return; } for page in start..end { @@ -112,7 +126,12 @@ pub(crate) fn tlbi_range(asid: Asid, va: usize, len: usize) { tlbi_pages(asid, va, len); return; } + tlbi_range_ops(asid, va, len); +} +/// Invalidates `len` bytes at `va` with as many range operations as the range needs. +#[inline(always)] +fn tlbi_range_ops(asid: Asid, va: usize, len: usize) { let start_pg = va >> mmu::UAT_PGBIT; let end_pg = (va + len + mmu::UAT_PGMSK) >> mmu::UAT_PGBIT; @@ -183,8 +202,9 @@ const TLBI_RANGE_BADDR_MASK: u64 = (1 << 37) - 1; /// Invalidate a range of pages for a given ASID with a single range operation. /// /// Unlike [`tlbi_range`], which issues as many range operations as needed, this invalidates -/// ranges that do not fit one operation (and ranges starting at VA 0) by ASID. Single pages use a -/// page operation, at the CPU page size. +/// ranges that do not fit one operation (and ranges starting at VA 0) by ASID. Upper-half ranges +/// that do not fit one operation still take range operations, as their leaves may be global. +/// Single pages use a page operation, at the CPU page size. #[inline(always)] pub(crate) fn tlbi_range_or_asid(asid: Asid, va: usize, len: usize) { if debug_enabled(DebugFlags::ConservativeTlbi) { @@ -202,7 +222,11 @@ pub(crate) fn tlbi_range_or_asid(asid: Asid, va: usize, len: usize) { } if va == 0 || len >= TLBI_RANGE_MAX { - tlbi_asid(asid); + if may_be_global(va) { + tlbi_range_ops(asid, va, len); + } else { + tlbi_asid(asid); + } return; } if len <= PAGE_SIZE {