From: Matteo Kloiber <kernel@matt3o12.de>
To: Danilo Krummrich <dakr@kernel.org>,
Alexandre Courbot <acourbot@nvidia.com>,
Alice Ryhl <aliceryhl@google.com>,
Abdiel Janulgue <abdiel.janulgue@gmail.com>,
Robin Murphy <robin.murphy@arm.com>,
Andreas Hindborg <a.hindborg@kernel.org>,
Gary Guo <gary@garyguo.net>
Cc: "Daniel Almeida" <daniel.almeida@collabora.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
rust-for-linux@vger.kernel.org, driver-core@lists.linux.dev,
dri-devel@lists.freedesktop.org, nova-gpu@lists.linux.dev,
linux-kernel@vger.kernel.org,
"Matteo Kloiber" <kernel@matt3o12.de>
Subject: [RFC PATCH v2 04/10] drm/tyr: configure DMA through dma::Setup
Date: Sun, 29 Nov 2026 23:24:23 +0100 [thread overview]
Message-ID: <20261129222429.2380652-5-kernel@matt3o12.de> (raw)
In-Reply-To: <20261129222429.2380652-1-kernel@matt3o12.de>
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@matt3o12.de>
---
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
next prev parent reply other threads:[~2026-11-29 22:25 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 22:24 [RFC PATCH v2 00/10] rust: dma: require device configuration before DMA Matteo Kloiber
2026-11-29 22:24 ` [RFC PATCH v2 01/10] rust: pci, platform: pass InitTokens to probe() Matteo Kloiber
2026-11-29 22:24 ` [RFC PATCH v2 02/10] rust: dma: add Setup, Params and Handle Matteo Kloiber
2026-11-29 22:24 ` [RFC PATCH v2 03/10] gpu: nova-core: configure DMA through dma::Setup Matteo Kloiber
2026-11-29 22:24 ` Matteo Kloiber [this message]
2026-11-29 22:24 ` [RFC PATCH v2 05/10] samples: rust: dma: " Matteo Kloiber
2026-11-29 22:24 ` [RFC PATCH v2 06/10] rust: dma: require a Handle for coherent allocations Matteo Kloiber
2026-11-29 22:24 ` [RFC PATCH v2 07/10] rust: scatterlist: require a dma::Handle for SGTable::new() Matteo Kloiber
2026-11-29 22:24 ` [RFC PATCH v2 08/10] rust: iommu: require a dma::Handle for IoPageTable::new() Matteo Kloiber
2026-11-29 22:24 ` [RFC PATCH v2 09/10] rust: drm: require a dma::Handle for shmem sg_table() Matteo Kloiber
2026-11-29 22:24 ` [RFC PATCH v2 10/10] rust: dma: remove the Device trait and its setters Matteo Kloiber
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261129222429.2380652-5-kernel@matt3o12.de \
--to=kernel@matt3o12.de \
--cc=a.hindborg@kernel.org \
--cc=abdiel.janulgue@gmail.com \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=bhelgaas@google.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=driver-core@lists.linux.dev \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nova-gpu@lists.linux.dev \
--cc=ojeda@kernel.org \
--cc=robin.murphy@arm.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®