Skip to content

Commit 5b9228a

Browse files
hoshinolinajannau
authored andcommitted
drm/asahi: Implement ASAHI_BIND_SINGLE_PAGE (mmu/pgtbl)
Signed-off-by: Asahi Lina <[email protected]>
1 parent 20579c1 commit 5b9228a

2 files changed

Lines changed: 40 additions & 13 deletions

File tree

drivers/gpu/drm/asahi/mmu.rs

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ impl gpuvm::DriverGpuVm for VmInner {
195195

196196
let bo = ctx.vm_bo.as_ref().expect("step_map with no BO");
197197

198+
let one_page = op.flags().contains(gpuvm::GpuVaFlags::SINGLE_PAGE);
199+
198200
let guard = bo.inner().sgt.lock();
199201
for range in unsafe { guard.as_ref().expect("step_map with no SGT").iter_raw() } {
200202
// TODO: proper DMA address/length handling
@@ -218,18 +220,27 @@ impl gpuvm::DriverGpuVm for VmInner {
218220

219221
assert!(offset == 0);
220222

221-
len = len.min(left);
223+
if one_page {
224+
len = left;
225+
} else {
226+
len = len.min(left);
227+
}
222228

223229
mod_dev_dbg!(
224230
self.dev,
225-
"MMU: map: {:#x}:{:#x} -> {:#x}\n",
231+
"MMU: map: {:#x}:{:#x} -> {:#x} [OP={}]\n",
226232
addr,
227233
len,
228-
iova
234+
iova,
235+
one_page
229236
);
230237

231-
self.page_table
232-
.map_pages(iova..(iova + len as u64), addr as PhysicalAddr, ctx.prot)?;
238+
self.page_table.map_pages(
239+
iova..(iova + len as u64),
240+
addr as PhysicalAddr,
241+
ctx.prot,
242+
one_page,
243+
)?;
233244

234245
left -= len;
235246
iova += len as u64;
@@ -442,8 +453,12 @@ impl VmInner {
442453
iova
443454
);
444455

445-
self.page_table
446-
.map_pages(iova..(iova + len as u64), addr as PhysicalAddr, prot)?;
456+
self.page_table.map_pages(
457+
iova..(iova + len as u64),
458+
addr as PhysicalAddr,
459+
prot,
460+
false,
461+
)?;
447462

448463
iova += len as u64;
449464
left -= len;
@@ -1083,6 +1098,7 @@ impl Vm {
10831098
size: u64,
10841099
offset: u64,
10851100
prot: Prot,
1101+
single_page: bool,
10861102
) -> Result {
10871103
// Mapping needs a complete context
10881104
let mut ctx = StepContext {
@@ -1120,14 +1136,20 @@ impl Vm {
11201136
return Err(EINVAL);
11211137
}
11221138

1139+
let flags = if single_page {
1140+
gpuvm::GpuVaFlags::SINGLE_PAGE
1141+
} else {
1142+
gpuvm::GpuVaFlags::NONE
1143+
};
1144+
11231145
mod_dev_dbg!(
11241146
inner.dev,
11251147
"MMU: sm_map: {:#x} [{:#x}] -> {:#x}\n",
11261148
offset,
11271149
size,
11281150
addr
11291151
);
1130-
inner.sm_map(&mut ctx, addr, size, offset)
1152+
inner.sm_map(&mut ctx, addr, size, offset, flags)
11311153
}
11321154

11331155
/// Add a direct MMIO mapping to this Vm at a free address.
@@ -1175,10 +1197,12 @@ impl Vm {
11751197
0,
11761198
)?;
11771199

1178-
let ret =
1179-
inner
1180-
.page_table
1181-
.map_pages(iova..(iova + size as u64), phys as PhysicalAddr, prot);
1200+
let ret = inner.page_table.map_pages(
1201+
iova..(iova + size as u64),
1202+
phys as PhysicalAddr,
1203+
prot,
1204+
false,
1205+
);
11821206
// Drop the exec_lock first, so that if map_node failed the
11831207
// KernelMappingInner destructur does not deadlock.
11841208
core::mem::drop(inner);

drivers/gpu/drm/asahi/pgtable.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ impl UatPageTable {
396396
iova_range: Range<u64>,
397397
mut phys: PhysicalAddr,
398398
prot: Prot,
399+
one_page: bool,
399400
) -> Result {
400401
mod_pr_debug!(
401402
"UATPageTable::map_pages: {:#x?} {:#x?} {:?}\n",
@@ -421,7 +422,9 @@ impl UatPageTable {
421422
);
422423
}
423424
pte.store(phys | prot.as_pte() | pte_bits, Ordering::Relaxed);
424-
phys += UAT_PGSZ as PhysicalAddr;
425+
if !one_page {
426+
phys += UAT_PGSZ as PhysicalAddr;
427+
}
425428
}
426429
})
427430
}

0 commit comments

Comments
 (0)