mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 07/10] rust: scatterlist: require a dma::Handle for SGTable::new()
Date: Sun, 29 Nov 2026 23:24:26 +0100	[thread overview]
Message-ID: <20261129222429.2380652-8-kernel@matt3o12.de> (raw)
In-Reply-To: <20261129222429.2380652-1-kernel@matt3o12.de>

SGTable::new() maps pages for a plain bound device. The mapping depends
on the device's DMA mask and maximum segment size, so it must not be
created before they are set.

Take a dma::Handle instead of the device. Convert nova-core and the DMA
sample, which already hold one.

Signed-off-by: Matteo Kloiber <kernel@matt3o12.de>
---
 drivers/gpu/nova-core/firmware/radix3.rs |  7 +++----
 rust/kernel/scatterlist.rs               | 22 +++++++++++-----------
 samples/rust/rust_dma.rs                 |  2 +-
 3 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/nova-core/firmware/radix3.rs b/drivers/gpu/nova-core/firmware/radix3.rs
index a00a583f7351..1dfe6b96ab45 100644
--- a/drivers/gpu/nova-core/firmware/radix3.rs
+++ b/drivers/gpu/nova-core/firmware/radix3.rs
@@ -52,19 +52,18 @@ pub(crate) struct Radix3<'a> {
 impl<'a> Radix3<'a> {
     /// Builds a radix3 page table over `data`, mapped for the device to read. May sleep.
     pub(crate) fn new(dma: dma::Handle<'a>, data: VVec<u8>) -> impl PinInit<Self, Error> + 'a {
-        let dev = dma.device();
         let size = data.len();
 
         pin_init::pin_init_scope(move || {
             Ok(try_pin_init!(Self {
-                data <- SGTable::new(dev, data, DataDirection::ToDevice, GFP_KERNEL),
+                data <- SGTable::new(dma, data, DataDirection::ToDevice, GFP_KERNEL),
                 level2 <- {
                     build_lvl(&data)
-                        .map(|l2| SGTable::new(dev, l2, DataDirection::ToDevice, GFP_KERNEL))?
+                        .map(|l2| SGTable::new(dma, l2, DataDirection::ToDevice, GFP_KERNEL))?
                 },
                 level1 <- {
                     build_lvl(&level2)
-                        .map(|l1| SGTable::new(dev, l1, DataDirection::ToDevice, GFP_KERNEL))?
+                        .map(|l1| SGTable::new(dma, l1, DataDirection::ToDevice, GFP_KERNEL))?
                 },
                 level0: {
                     // Allocate the level 0 page table as a device-visible DMA object, and map the
diff --git a/rust/kernel/scatterlist.rs b/rust/kernel/scatterlist.rs
index 3a5250f85000..9a9deb7ace2e 100644
--- a/rust/kernel/scatterlist.rs
+++ b/rust/kernel/scatterlist.rs
@@ -333,12 +333,13 @@ impl<P> Owned<P>
 where
     for<'a> P: page::AsPageIter<Iter<'a> = VmallocPageIter<'a>> + 'static,
 {
-    fn new(
-        dev: &Device<Bound>,
+    fn new<'a>(
+        dma: dma::Handle<'a>,
         mut pages: P,
         dir: dma::DataDirection,
         flags: alloc::Flags,
-    ) -> Result<impl PinInit<Self, Error> + '_> {
+    ) -> Result<impl PinInit<Self, Error> + 'a> {
+        let dev = dma.device();
         let page_iter = pages.page_iter();
         let size = page_iter.size();
 
@@ -406,7 +407,7 @@ impl<P> SGTable<Owned<P>>
     ///
     /// # Parameters
     ///
-    /// * `dev`: The [`Device`] that will be performing the DMA.
+    /// * `dma`: A handle for the device whose DMA parameters have been configured.
     /// * `pages`: The entity providing the backing pages. It must implement [`page::AsPageIter`].
     ///   The ownership of this entity is moved into the new [`SGTable<Owned>`].
     /// * `dir`: The [`dma::DataDirection`] of the DMA transfer.
@@ -416,18 +417,17 @@ impl<P> SGTable<Owned<P>>
     ///
     /// ```
     /// use kernel::{
-    ///     device::{Bound, Device},
     ///     dma, page,
     ///     prelude::*,
     ///     scatterlist::{SGTable, Owned},
     /// };
     ///
-    /// fn test(dev: &Device<Bound>) -> Result {
+    /// fn test(dma: dma::Handle<'_>) -> Result {
     ///     let size = 4 * page::PAGE_SIZE;
     ///     let pages = VVec::<u8>::with_capacity(size, GFP_KERNEL)?;
     ///
     ///     let sgt = KBox::pin_init(SGTable::new(
-    ///         dev,
+    ///         dma,
     ///         pages,
     ///         dma::DataDirection::ToDevice,
     ///         GFP_KERNEL,
@@ -436,14 +436,14 @@ impl<P> SGTable<Owned<P>>
     ///     Ok(())
     /// }
     /// ```
-    pub fn new(
-        dev: &Device<Bound>,
+    pub fn new<'a>(
+        dma: dma::Handle<'a>,
         pages: P,
         dir: dma::DataDirection,
         flags: alloc::Flags,
-    ) -> impl PinInit<Self, Error> + '_ {
+    ) -> impl PinInit<Self, Error> + 'a {
         try_pin_init!(Self {
-            inner <- Owned::new(dev, pages, dir, flags)?
+            inner <- Owned::new(dma, pages, dir, flags)?
         })
     }
 }
diff --git a/samples/rust/rust_dma.rs b/samples/rust/rust_dma.rs
index 1233aac8fe23..8fb5b90d7aaa 100644
--- a/samples/rust/rust_dma.rs
+++ b/samples/rust/rust_dma.rs
@@ -105,7 +105,7 @@ fn probe<'bound>(
             let size = 4 * page::PAGE_SIZE;
             let pages = VVec::with_capacity(size, GFP_KERNEL)?;
 
-            let sgt = SGTable::new(dma.device(), pages, DataDirection::ToDevice, GFP_KERNEL);
+            let sgt = SGTable::new(dma, pages, DataDirection::ToDevice, GFP_KERNEL);
 
             Ok(try_pin_init!(Self::Data {
                 pdev,
-- 
2.51.2


  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 ` [RFC PATCH v2 04/10] drm/tyr: " Matteo Kloiber
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 ` Matteo Kloiber [this message]
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-8-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®