[RFC PATCH v2 04/10] drm/tyr: configure DMA through dma::Setup
From: Matteo Kloiber
Date: Sun Nov 29 2026 - 17:25:10 EST
Tyr sets its DMA mask with the unsafe dma::Device setter.
Take the dma::Setup token from the platform InitTokens and configure
DMA through it instead, with the same mask. Pass None for the maximum
segment size to keep its current value. Panthor sets UINT_MAX for the
same hardware, so Tyr probably should too, but that is a behaviour
change for a separate patch.
Pass the returned dma::Handle to the firmware loader and the VM, which
create the IOMMU page table and map the GEM shmem SG tables. Both APIs
still take a device, so hand them dma.device() for now.
No functional change intended.
Signed-off-by: Matteo Kloiber <kernel@xxxxxxxxxxx>
---
drivers/gpu/drm/tyr/driver.rs | 19 ++++++++++------
drivers/gpu/drm/tyr/fw.rs | 11 +++++-----
drivers/gpu/drm/tyr/mmu/address_space.rs | 7 +++---
drivers/gpu/drm/tyr/vm.rs | 28 +++++++++++++++---------
4 files changed, 39 insertions(+), 26 deletions(-)
diff --git a/drivers/gpu/drm/tyr/driver.rs b/drivers/gpu/drm/tyr/driver.rs
index 7650ade4ad72..9b9c7bd0fc6a 100644
--- a/drivers/gpu/drm/tyr/driver.rs
+++ b/drivers/gpu/drm/tyr/driver.rs
@@ -12,7 +12,7 @@
DeviceContext, //
},
dma::{
- Device as DmaDevice,
+ self,
DmaMask, //
},
drm,
@@ -119,9 +119,10 @@ impl platform::Driver for TyrPlatformDriver {
fn probe<'bound>(
pdev: &'bound platform::Device<Core<'_>>,
- _tokens: platform::InitTokens<'bound>,
+ tokens: platform::InitTokens<'bound>,
_info: Option<&'bound Self::IdInfo>,
) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {
+ let platform::InitTokens { dma: setup, .. } = tokens;
pin_init::pin_init_scope(move || {
let core_clk = Clk::get(pdev.as_ref(), Some(c"core"))?;
let stacks_clk = OptionalClk::get(pdev.as_ref(), Some(c"stacks"))?;
@@ -147,17 +148,21 @@ fn probe<'bound>(
let pa_bits = MMU_FEATURES::from_raw(gpu_info.mmu_features)
.pa_bits()
.get();
- // SAFETY: No concurrent DMA allocations or mappings can be made because
- // the device is still being probed and therefore isn't being used by
- // other threads of execution.
- unsafe { pdev.dma_set_mask_and_coherent(DmaMask::try_new(pa_bits)?)? };
+ let mask = DmaMask::try_new(pa_bits)?;
+ let dma = setup.configure(dma::Params {
+ streaming_mask: Some(mask),
+ coherent_mask: Some(mask),
+ // TODO: Panthor calls `dma_set_max_seg_size(dev, UINT_MAX)`; Tyr probably wants
+ // `Some(NonZeroU32::MAX)` here as well.
+ max_seg_size: None,
+ })?;
let unreg_dev = drm::UnregisteredDevice::<TyrDrmDriver>::new(pdev)?;
let mmu = Mmu::new(pdev.as_ref(), iomem.as_arc_borrow(), &gpu_info)?;
let firmware = Firmware::new(
- pdev.as_ref(),
+ dma,
iomem.clone(),
&unreg_dev,
mmu.as_arc_borrow(),
diff --git a/drivers/gpu/drm/tyr/fw.rs b/drivers/gpu/drm/tyr/fw.rs
index aea151ff1f93..b4e9de26ead5 100644
--- a/drivers/gpu/drm/tyr/fw.rs
+++ b/drivers/gpu/drm/tyr/fw.rs
@@ -15,10 +15,8 @@
use kernel::{
bitfield,
- device::{
- Bound,
- Device, //
- },
+ device::Device,
+ dma,
drm::{
gem::BaseObject, //
},
@@ -213,13 +211,14 @@ fn load(
/// Load firmware and map sections into MCU VM.
pub(crate) fn new(
- dev: &'drm Device<Bound>,
+ dma: dma::Handle<'drm>,
iomem: Arc<IoMem<'drm>>,
ddev: &TyrDrmDevice,
mmu: ArcBorrow<'_, Mmu<'drm>>,
gpu_info: &GpuInfo,
) -> Result<Firmware<'drm>> {
- let vm = Vm::new(dev, ddev, mmu, gpu_info)?;
+ let dev = dma.device();
+ let vm = Vm::new(dma, ddev, mmu, gpu_info)?;
vm.activate()?;
let result = (|| {
diff --git a/drivers/gpu/drm/tyr/mmu/address_space.rs b/drivers/gpu/drm/tyr/mmu/address_space.rs
index 76e3d2df6afd..de7dce8e9ee6 100644
--- a/drivers/gpu/drm/tyr/mmu/address_space.rs
+++ b/drivers/gpu/drm/tyr/mmu/address_space.rs
@@ -12,7 +12,8 @@
device::{
Bound,
Device, //
- }, //
+ },
+ dma,
error::Result,
io::{
poll,
@@ -89,7 +90,7 @@ impl<'drm> VmAsData<'drm> {
/// Creates VM address space data by initializing all of its fields.
pub(crate) fn new<'a>(
mmu: &'a Mmu<'drm>,
- dev: &'drm Device<Bound>,
+ dma: dma::Handle<'drm>,
va_bits: u32,
pa_bits: u32,
) -> impl pin_init::PinInit<VmAsData<'drm>, Error> + 'a {
@@ -101,7 +102,7 @@ pub(crate) fn new<'a>(
coherent_walk: false,
};
- let page_table_init = IoPageTable::new(dev, pt_config);
+ let page_table_init = IoPageTable::new(dma.device(), pt_config);
try_pin_init!(Self {
as_seat: LockedBy::new(&mmu.as_manager, Seat::NoSeat),
diff --git a/drivers/gpu/drm/tyr/vm.rs b/drivers/gpu/drm/tyr/vm.rs
index 1dd11b2b1253..8465d065dceb 100644
--- a/drivers/gpu/drm/tyr/vm.rs
+++ b/drivers/gpu/drm/tyr/vm.rs
@@ -15,6 +15,7 @@
Bound,
Device, //
},
+ dma,
drm::{
gem::BaseObject,
gpuvm::{
@@ -219,8 +220,10 @@ enum PtOpType {
/// Memory Management Unit (MMU) state is properly managed and Translation
/// Lookaside Buffer (TLB) entries are flushed.
pub(crate) struct PtUpdateContext<'ctx, 'drm> {
- /// Device used for DMA-mapping GEM shmem SG tables.
+ /// Device used for log messages.
dev: &'ctx Device<Bound>,
+ /// DMA handle used to map GEM shmem SG tables.
+ dma: dma::Handle<'ctx>,
/// Page table.
pt: &'ctx IoPageTable<'drm, ARM64LPAES1>,
@@ -248,7 +251,7 @@ impl<'ctx, 'drm> PtUpdateContext<'ctx, 'drm> {
/// The context will automatically flush the TLB and
/// complete the update when dropped.
fn new(
- dev: &'ctx Device<Bound>,
+ dma: dma::Handle<'ctx>,
pt: &'ctx IoPageTable<'drm, ARM64LPAES1>,
mmu: &'ctx Mmu<'drm>,
as_data: &'ctx VmAsData<'drm>,
@@ -259,7 +262,8 @@ fn new(
mmu.start_vm_update(as_data, ®ion)?;
Ok(Self {
- dev,
+ dev: dma.device(),
+ dma,
pt,
mmu,
as_data,
@@ -321,8 +325,10 @@ pub(crate) struct Vm<'drm> {
as_data: Arc<VmAsData<'drm>>,
/// MMU manager.
mmu: Arc<Mmu<'drm>>,
- /// Parent device used for DMA mapping and page-table operations.
+ /// Parent device.
dev: &'drm Device<Bound>,
+ /// DMA handle used for mappings and page-table operations.
+ dma: dma::Handle<'drm>,
/// DRM GPUVM core for managing virtual address space.
#[pin]
gpuvm_unique: Mutex<UniqueRefGpuVm<GpuVmData<'drm>>>,
@@ -339,11 +345,12 @@ impl<'drm> Vm<'drm> {
/// The VM is initialized with a page table configured according to the GPU's
/// address translation capabilities and registered with the GPUVM framework.
pub(crate) fn new(
- dev: &'drm Device<Bound>,
+ dma: dma::Handle<'drm>,
ddev: &TyrDrmDevice,
mmu: ArcBorrow<'_, Mmu<'drm>>,
gpu_info: &GpuInfo,
) -> Result<Arc<Vm<'drm>>> {
+ let dev = dma.device();
let mmu_features = MMU_FEATURES::from_raw(gpu_info.mmu_features);
let va_bits = mmu_features.va_bits().get();
let pa_bits = mmu_features.pa_bits().get();
@@ -371,12 +378,13 @@ pub(crate) fn new(
})?;
let gpuvm = ARef::from(&*gpuvm_unique);
- let as_data = Arc::pin_init(VmAsData::new(&mmu, dev, va_bits, pa_bits), GFP_KERNEL)?;
+ let as_data = Arc::pin_init(VmAsData::new(&mmu, dma, va_bits, pa_bits), GFP_KERNEL)?;
let vm = Arc::pin_init(
pin_init!(Self{
as_data,
dev,
+ dma,
mmu: mmu.into(),
gpuvm,
gpuvm_unique <- new_mutex!(gpuvm_unique),
@@ -388,7 +396,7 @@ pub(crate) fn new(
Ok(vm)
}
- /// Returns the parent device used by this VM for DMA mapping and page-table operations.
+ /// Returns the parent device.
pub(crate) fn dev(&self) -> &'drm Device<Bound> {
self.dev
}
@@ -435,7 +443,7 @@ fn exec_op<'a>(
match req.op_type {
VmOpType::Map(args) => {
let mut pt_upd = PtUpdateContext::new(
- self.dev,
+ self.dma,
pt,
&self.mmu,
&self.as_data,
@@ -457,7 +465,7 @@ fn exec_op<'a>(
}
VmOpType::Unmap => {
let mut pt_upd = PtUpdateContext::new(
- self.dev,
+ self.dma,
pt,
&self.mmu,
&self.as_data,
@@ -630,7 +638,7 @@ fn sm_step_map<'op>(
return Err(EINVAL);
}
- let sgt = op.obj().sg_table(context.dev).inspect_err(|e| {
+ let sgt = op.obj().sg_table(context.dma.device()).inspect_err(|e| {
dev_err!(context.dev, "Failed to get sg_table: {:?}", e);
})?;
let prot = match &context.op_type {
--
2.51.2