All of lore.kernel.org
 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 03/10] gpu: nova-core: configure DMA through dma::Setup
Date: Sun, 29 Nov 2026 23:24:22 +0100	[thread overview]
Message-ID: <20261129222429.2380652-4-kernel@matt3o12.de> (raw)
In-Reply-To: <20261129222429.2380652-1-kernel@matt3o12.de>

Gpu::new() sets the DMA mask and the maximum segment size with the
unsafe dma::Device setters, and relies on a comment to rule out
concurrent DMA allocations.

Take the dma::Setup token from the PCI InitTokens and configure DMA
through it instead, with the same mask and the same unlimited segment
size. Store the returned dma::Handle in Gpu, so that the fields
initialized after it can use it, and keep a copy in GspResources for
the GSP unload path.

Pass the handle instead of the device to everything that allocates or
maps DMA memory. The DMA APIs still take a device, so hand them
dma.device() for now. They are converted to take the handle once all
drivers have one.

No functional change intended.

Suggested-by: Danilo Krummrich <dakr@kernel.org>
Signed-off-by: Matteo Kloiber <kernel@matt3o12.de>
---
 drivers/gpu/nova-core/driver.rs               |  5 +-
 drivers/gpu/nova-core/falcon.rs               | 13 +++--
 drivers/gpu/nova-core/fb.rs                   | 11 +++--
 .../nova-core/firmware/fwsec/bootloader.rs    | 13 +++--
 drivers/gpu/nova-core/firmware/gsp.rs         | 19 ++++----
 drivers/gpu/nova-core/firmware/gsp_fmc.rs     | 10 ++--
 drivers/gpu/nova-core/firmware/radix3.rs      | 12 ++---
 drivers/gpu/nova-core/firmware/riscv.rs       | 11 +++--
 drivers/gpu/nova-core/fsp.rs                  | 20 ++++----
 drivers/gpu/nova-core/gpu.rs                  | 47 ++++++++++++-------
 drivers/gpu/nova-core/gsp.rs                  | 19 ++++----
 drivers/gpu/nova-core/gsp/boot.rs             |  2 +-
 drivers/gpu/nova-core/gsp/cmdq.rs             | 14 +++---
 drivers/gpu/nova-core/gsp/hal/gh100.rs        |  9 ++--
 drivers/gpu/nova-core/gsp/hal/tu102.rs        | 24 ++++++----
 drivers/gpu/nova-core/gsp/logbuffer.rs        | 23 +++++----
 16 files changed, 145 insertions(+), 107 deletions(-)

diff --git a/drivers/gpu/nova-core/driver.rs b/drivers/gpu/nova-core/driver.rs
index 365e77ff0cc4..fbbb4f4fa55b 100644
--- a/drivers/gpu/nova-core/driver.rs
+++ b/drivers/gpu/nova-core/driver.rs
@@ -101,9 +101,10 @@ impl pci::Driver for NovaCoreDriver {
 
     fn probe<'bound>(
         pdev: &'bound pci::Device<Core<'_>>,
-        _tokens: pci::InitTokens<'bound>,
+        tokens: pci::InitTokens<'bound>,
         _info: Option<&'bound Self::IdInfo>,
     ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {
+        let pci::InitTokens { dma: setup, .. } = tokens;
         dev_dbg!(pdev, "Probe Nova Core GPU driver.\n");
 
         try_pin_init!(NovaCore {
@@ -133,7 +134,7 @@ fn probe<'bound>(
                 crate::irq::doorbell_test::run_selftest(pdev, bar, spec.chipset)?;
             },
 
-            gpu <- Gpu::new(pdev, bar, bar1).pin_chain(|_gpu| {
+            gpu <- Gpu::new(pdev, setup, bar, bar1).pin_chain(|_gpu| {
                 #[cfg(CONFIG_NOVA_CORE_SELFTESTS)]
                 _gpu.run_selftests(pdev);
                 Ok(())
diff --git a/drivers/gpu/nova-core/falcon.rs b/drivers/gpu/nova-core/falcon.rs
index 8bcc9240d1bd..c9ffda0208b0 100644
--- a/drivers/gpu/nova-core/falcon.rs
+++ b/drivers/gpu/nova-core/falcon.rs
@@ -7,6 +7,7 @@
 use kernel::{
     device,
     dma::{
+        self,
         Coherent,
         CoherentBox,
         DmaAddress, //
@@ -374,6 +375,7 @@ pub(crate) trait FalconFirmware {
 pub(crate) struct Falcon<'a, E: FalconEngine> {
     hal: KBox<dyn FalconHal<E>>,
     dev: &'a device::Device<device::Bound>,
+    dma: dma::Handle<'a>,
     bar: Bar0<'a>,
     pfalcon: Mmio<'a, PFalconRegisters>,
     pfalcon2: Mmio<'a, PFalcon2Registers>,
@@ -381,14 +383,11 @@ pub(crate) struct Falcon<'a, E: FalconEngine> {
 
 impl<'a, E: FalconEngine + 'static> Falcon<'a, E> {
     /// Create a new falcon instance.
-    pub(crate) fn new(
-        dev: &'a device::Device<device::Bound>,
-        chipset: Chipset,
-        bar: Bar0<'a>,
-    ) -> Result<Self> {
+    pub(crate) fn new(dma: dma::Handle<'a>, chipset: Chipset, bar: Bar0<'a>) -> Result<Self> {
         Ok(Self {
             hal: hal::falcon_hal(chipset)?,
-            dev,
+            dev: dma.device(),
+            dma,
             bar,
             pfalcon: E::pfalcon(bar),
             pfalcon2: E::pfalcon2(bar),
@@ -650,7 +649,7 @@ fn dma_load<F: FalconFirmware<Target = E> + FalconDmaLoadable>(&self, fw: &F) ->
             // DMA copies are done in chunks of `MEM_BLOCK_ALIGNMENT`, so pad the length
             // accordingly and fill with `0`.
             let mut dma_obj = CoherentBox::zeroed_slice(
-                self.dev,
+                self.dma.device(),
                 fw_slice.len().next_multiple_of(MEM_BLOCK_ALIGNMENT),
                 GFP_KERNEL,
             )?;
diff --git a/drivers/gpu/nova-core/fb.rs b/drivers/gpu/nova-core/fb.rs
index 5ceb7760c78e..a2505da09a79 100644
--- a/drivers/gpu/nova-core/fb.rs
+++ b/drivers/gpu/nova-core/fb.rs
@@ -7,7 +7,10 @@
 
 use kernel::{
     device,
-    dma::CoherentHandle,
+    dma::{
+        self,
+        CoherentHandle, //
+    },
     fmt,
     io::Io,
     prelude::*,
@@ -55,17 +58,17 @@ pub(crate) struct SysmemFlush<'sys> {
 impl<'sys> SysmemFlush<'sys> {
     /// Allocate a memory page and register it as the sysmem flush page.
     pub(crate) fn register(
-        dev: &'sys device::Device<device::Bound>,
+        dma: dma::Handle<'sys>,
         bar: Bar0<'sys>,
         chipset: Chipset,
     ) -> Result<Self> {
-        let page = CoherentHandle::alloc(dev, kernel::page::PAGE_SIZE, GFP_KERNEL)?;
+        let page = CoherentHandle::alloc(dma.device(), kernel::page::PAGE_SIZE, GFP_KERNEL)?;
 
         hal::fb_hal(chipset).write_sysmem_flush_page(bar, page.dma_address())?;
 
         Ok(Self {
             chipset,
-            device: dev,
+            device: dma.device(),
             bar,
             page,
         })
diff --git a/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs b/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs
index 461e5e6f7899..49651a404286 100644
--- a/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs
+++ b/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs
@@ -11,7 +11,10 @@
         self,
         Device, //
     },
-    dma::Coherent,
+    dma::{
+        self,
+        Coherent, //
+    },
     prelude::*, //
 };
 
@@ -45,14 +48,14 @@ pub(crate) struct FwsecFirmwareWithBl<'a> {
 }
 
 impl<'a> FwsecFirmwareWithBl<'a> {
-    /// Loads the bootloader firmware for `dev` and `chipset`, and wrap `firmware` so it can be
+    /// Loads the bootloader firmware for the device and `chipset`, and wrap `firmware` so it can be
     /// loaded using it.
     pub(crate) fn new(
         firmware: FwsecFirmware,
-        dev: &'a Device<device::Bound>,
+        dma: dma::Handle<'a>,
         chipset: Chipset,
     ) -> Result<Self> {
-        let bootloader = GenericBootloader::new(dev, chipset)?;
+        let bootloader = GenericBootloader::new(dma.device(), chipset)?;
 
         // `BootloaderDmemDescV2` expects the source to be a mirror image of the destination and
         // uses the same offset parameter for both.
@@ -77,7 +80,7 @@ pub(crate) fn new(
 
             (
                 align_padding,
-                Coherent::from_slice(dev, firmware_obj.as_slice(), GFP_KERNEL)?,
+                Coherent::from_slice(dma.device(), firmware_obj.as_slice(), GFP_KERNEL)?,
             )
         };
 
diff --git a/drivers/gpu/nova-core/firmware/gsp.rs b/drivers/gpu/nova-core/firmware/gsp.rs
index 341a8b19aa38..e5fce91337a8 100644
--- a/drivers/gpu/nova-core/firmware/gsp.rs
+++ b/drivers/gpu/nova-core/firmware/gsp.rs
@@ -1,8 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0
 
 use kernel::{
-    device,
     dma::{
+        self,
         Coherent,
         DmaAddress, //
     },
@@ -37,12 +37,10 @@ pub(crate) struct GspFirmware<'a> {
 }
 
 impl<'a> GspFirmware<'a> {
-    /// Loads the GSP firmware binaries, map them into `dev`'s address-space, and creates the page
-    /// tables expected by the GSP bootloader to load it.
-    pub(crate) fn new(
-        dev: &'a device::Device<device::Bound>,
-        chipset: Chipset,
-    ) -> impl PinInit<Self, Error> + 'a {
+    /// Loads the GSP firmware binaries, maps them into the device's address space, and creates
+    /// the page tables expected by the GSP bootloader to load it.
+    pub(crate) fn new(dma: dma::Handle<'a>, chipset: Chipset) -> impl PinInit<Self, Error> + 'a {
+        let dev = dma.device();
         pin_init::pin_init_scope(move || {
             let firmware = request_tlv(dev, chipset, "gsp")?;
             let tlv = Tlv::new(firmware.data())?;
@@ -56,15 +54,16 @@ pub(crate) fn new(
             let filename = CString::try_from_fmt(fmt!("nvidia/{chip_name}/gsp/{file}"))?;
             firmware::request_into_buf(&filename, dev, fw_vvec.as_mut_slice())?;
 
-            let signatures = Coherent::from_slice(dev, tlv.get_bytes(b"SIGN")?, GFP_KERNEL)?;
+            let signatures =
+                Coherent::from_slice(dma.device(), tlv.get_bytes(b"SIGN")?, GFP_KERNEL)?;
 
             Ok(try_pin_init!(Self {
-                radix3 <- Radix3::new(dev, fw_vvec),
+                radix3 <- Radix3::new(dma, fw_vvec),
                 signatures,
                 bootloader: {
                     let bl = request_tlv(dev, chipset, "gsp_bootloader")?;
 
-                    RiscvFirmware::new(dev, &bl)?
+                    RiscvFirmware::new(dma, &bl)?
                 },
             }))
         })
diff --git a/drivers/gpu/nova-core/firmware/gsp_fmc.rs b/drivers/gpu/nova-core/firmware/gsp_fmc.rs
index 94fcc86c7dff..230d631beaf4 100644
--- a/drivers/gpu/nova-core/firmware/gsp_fmc.rs
+++ b/drivers/gpu/nova-core/firmware/gsp_fmc.rs
@@ -6,7 +6,10 @@
 
 use kernel::{
     device,
-    dma::Coherent,
+    dma::{
+        self,
+        Coherent, //
+    },
     prelude::*, //
 };
 
@@ -48,7 +51,8 @@ pub(crate) struct GspFmcFirmware<'a> {
 }
 
 impl<'a> GspFmcFirmware<'a> {
-    pub(crate) fn new(dev: &'a device::Device<device::Bound>, chipset: Chipset) -> Result<Self> {
+    pub(crate) fn new(dma: dma::Handle<'a>, chipset: Chipset) -> Result<Self> {
+        let dev = dma.device();
         let fw = request_tlv(dev, chipset, "fmc")?;
         let tlv = Tlv::new(fw.data())?;
         dev_dbg!(
@@ -58,7 +62,7 @@ pub(crate) fn new(dev: &'a device::Device<device::Bound>, chipset: Chipset) -> R
         );
 
         let fmc_image_data = tlv.get_bytes(b"BLOB")?;
-        let fmc_image = Coherent::from_slice(dev, fmc_image_data, GFP_KERNEL)?;
+        let fmc_image = Coherent::from_slice(dma.device(), fmc_image_data, GFP_KERNEL)?;
 
         Ok(Self {
             fmc_image,
diff --git a/drivers/gpu/nova-core/firmware/radix3.rs b/drivers/gpu/nova-core/firmware/radix3.rs
index 94235bd1209d..5e10263e8313 100644
--- a/drivers/gpu/nova-core/firmware/radix3.rs
+++ b/drivers/gpu/nova-core/firmware/radix3.rs
@@ -12,8 +12,8 @@
 //! ```
 
 use kernel::{
-    device,
     dma::{
+        self,
         Coherent,
         CoherentBox,
         DataDirection,
@@ -50,11 +50,9 @@ pub(crate) struct Radix3<'a> {
 }
 
 impl<'a> Radix3<'a> {
-    /// Builds a radix3 page table over `data`, mapped for `dev` to read. May sleep.
-    pub(crate) fn new(
-        dev: &'a device::Device<device::Bound>,
-        data: VVec<u8>,
-    ) -> impl PinInit<Self, Error> + '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 || {
@@ -79,7 +77,7 @@ pub(crate) fn new(
                     // Create level 0 page table data and fill its first entry with the level 1
                     // table.
                     let mut level0 = CoherentBox::<'_, [u64]>::zeroed_slice(
-                        dev,
+                        dma.device(),
                         GSP_PAGE_SIZE / size_of::<u64>(),
                         GFP_KERNEL
                     )?;
diff --git a/drivers/gpu/nova-core/firmware/riscv.rs b/drivers/gpu/nova-core/firmware/riscv.rs
index f05cfb1c65da..ce0da2efe34e 100644
--- a/drivers/gpu/nova-core/firmware/riscv.rs
+++ b/drivers/gpu/nova-core/firmware/riscv.rs
@@ -4,8 +4,10 @@
 //! dedicated header.
 
 use kernel::{
-    device,
-    dma::Coherent,
+    dma::{
+        self,
+        Coherent, //
+    },
     firmware::Firmware,
     prelude::*, //
 };
@@ -28,7 +30,8 @@ pub(crate) struct RiscvFirmware<'a> {
 
 impl<'a> RiscvFirmware<'a> {
     /// Parses the RISC-V firmware image contained in `fw`.
-    pub(crate) fn new(dev: &'a device::Device<device::Bound>, fw: &Firmware) -> Result<Self> {
+    pub(crate) fn new(dma: dma::Handle<'a>, fw: &Firmware) -> Result<Self> {
+        let dev = dma.device();
         let tlv = Tlv::new(fw.data())?;
         dev_dbg!(
             dev,
@@ -41,7 +44,7 @@ pub(crate) fn new(dev: &'a device::Device<device::Bound>, fw: &Firmware) -> Resu
         let manifest_offset = tlv.get_u32(b"MFOF")?;
         let app_version = tlv.get_u32(b"APPV")?;
 
-        let ucode = Coherent::from_slice(dev, tlv.get_bytes(b"BLOB")?, GFP_KERNEL)?;
+        let ucode = Coherent::from_slice(dma.device(), tlv.get_bytes(b"BLOB")?, GFP_KERNEL)?;
 
         Ok(Self {
             ucode,
diff --git a/drivers/gpu/nova-core/fsp.rs b/drivers/gpu/nova-core/fsp.rs
index ea08cd58346f..17da2efbf0e0 100644
--- a/drivers/gpu/nova-core/fsp.rs
+++ b/drivers/gpu/nova-core/fsp.rs
@@ -12,7 +12,10 @@
 
 use kernel::{
     device,
-    dma::Coherent,
+    dma::{
+        self,
+        Coherent, //
+    },
     io::poll::read_poll_timeout,
     num::TryIntoBounded,
     prelude::*,
@@ -359,7 +362,7 @@ impl<'a> FmcBootArgs<'a> {
     /// Builds FMC boot arguments, allocating the DMA-coherent boot parameter
     /// structure that FSP will read.
     pub(crate) fn new(
-        dev: &'a device::Device<device::Bound>,
+        dma: dma::Handle<'a>,
         chipset: Chipset,
         wpr_meta: Coherent<'a, GspFwWprMeta>,
         libos: &'a Coherent<'a, [LibosMemoryRegionInitArgument]>,
@@ -369,7 +372,7 @@ pub(crate) fn new(
 
         Ok(Self {
             chipset,
-            fmc_boot_params: Coherent::init(dev, GFP_KERNEL, init)?,
+            fmc_boot_params: Coherent::init(dma.device(), GFP_KERNEL, init)?,
             resume,
             _wpr_meta: wpr_meta,
             _libos: libos,
@@ -401,13 +404,13 @@ impl<'a> Fsp<'a> {
     ///
     /// If `chipset` doesn't support FSP, `Ok(None)` is returned.
     pub(crate) fn try_new(
-        dev: &'a device::Device<device::Bound>,
+        dma: dma::Handle<'a>,
         bar: Bar0<'a>,
         chipset: Chipset,
     ) -> Result<Option<Self>> {
         match hal::fsp_hal(chipset) {
             None => Ok(None),
-            Some(hal) => Self::wait_secure_boot(dev, bar, chipset, hal).map(Option::Some),
+            Some(hal) => Self::wait_secure_boot(dma, bar, chipset, hal).map(Option::Some),
         }
     }
 
@@ -417,7 +420,7 @@ pub(crate) fn try_new(
     /// elapses. Returning an [`Fsp`] only on success guarantees, at the API level, that the
     /// interface is not used before secure boot has completed.
     fn wait_secure_boot(
-        dev: &'a device::Device<device::Bound>,
+        dma: dma::Handle<'a>,
         bar: Bar0<'a>,
         chipset: Chipset,
         hal: &'static dyn hal::FspHal,
@@ -425,8 +428,9 @@ fn wait_secure_boot(
         /// FSP secure boot completion timeout in milliseconds.
         const FSP_SECURE_BOOT_TIMEOUT_MS: i64 = 5000;
 
-        let falcon = Falcon::<FspEngine>::new(dev, chipset, bar)?;
-        let fmc_fw = GspFmcFirmware::new(dev, chipset)?;
+        let dev = dma.device();
+        let falcon = Falcon::<FspEngine>::new(dma, chipset, bar)?;
+        let fmc_fw = GspFmcFirmware::new(dma, chipset)?;
 
         read_poll_timeout(
             || Ok(hal.fsp_boot_status(bar)),
diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs
index 8ab1687847ff..2a59948169ef 100644
--- a/drivers/gpu/nova-core/gpu.rs
+++ b/drivers/gpu/nova-core/gpu.rs
@@ -1,10 +1,13 @@
 // SPDX-License-Identifier: GPL-2.0
 
-use core::ops::Range;
+use core::{
+    num::NonZeroU32,
+    ops::Range, //
+};
 
 use kernel::{
     device,
-    dma::Device,
+    dma,
     fmt,
     gpu::buddy::GpuBuddyParams,
     io::Io,
@@ -322,6 +325,8 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 struct GspResources<'gpu> {
     /// Device owning the GPU.
     device: &'gpu pci::Device<device::Bound>,
+    /// DMA handle used for the GPU's allocations.
+    dma: dma::Handle<'gpu>,
     /// Details about the chipset.
     spec: Spec,
     /// MMIO mapping of PCI BAR 0.
@@ -385,6 +390,8 @@ unsafe fn new(
 #[pin_data]
 pub(crate) struct Gpu<'gpu> {
     pub(crate) spec: Spec,
+    /// DMA handle of the configured device, kept as a field for the other field initializers.
+    dma: dma::Handle<'gpu>,
     /// GSP event interrupt registration, and the enable of its subtree.
     ///
     /// Must be kept declared *before* `gsp_resources`, so that the handler is unregistered, and
@@ -434,6 +441,7 @@ fn drop(self: Pin<&mut Self>) {
             .unload(
                 GspBootContext {
                     pdev: device,
+                    dma: *this.dma,
                     bar,
                     chipset: this.spec.chipset,
                     gsp_falcon: &*this.gsp_falcon,
@@ -450,6 +458,7 @@ fn drop(self: Pin<&mut Self>) {
 impl<'gpu> Gpu<'gpu> {
     pub(crate) fn new<'a>(
         pdev: &'gpu pci::Device<device::Core<'a>>,
+        setup: dma::Setup<'gpu>,
         bar: Bar0<'gpu>,
         bar1: Bar1<'gpu>,
     ) -> impl PinInit<Self, Error> + use<'gpu, 'a> {
@@ -462,51 +471,53 @@ pub(crate) fn new<'a>(
 
             tree: Tree::new(pdev, bar, spec.chipset, irq::gsp::GSP_SUBTREE.into())?,
 
-            _: {
+            dma: {
                 let dma_mask = hal::gpu_hal(spec.chipset).dma_mask();
 
-                // SAFETY: `Gpu` owns all DMA allocations for this device, and we are
-                // still constructing it, so no concurrent DMA allocations can exist.
-                unsafe { pdev.dma_set_mask_and_coherent(dma_mask)? };
-
-                // Nova walks SG segments to build page tables, so their length is
-                // irrelevant to the device.
-                //
-                // SAFETY: `Gpu` owns all DMA allocations for this device, and we are
-                // still constructing it, so no concurrent DMA allocations can exist.
-                unsafe { pdev.dma_set_max_seg_size(u32::MAX) };
+                setup.configure(dma::Params {
+                    streaming_mask: Some(dma_mask),
+                    coherent_mask: Some(dma_mask),
+                    // Nova walks SG segments to build page tables, so their length is
+                    // irrelevant to the device.
+                    max_seg_size: Some(NonZeroU32::MAX),
+                })?
+            },
 
+            _: {
                 // We must wait for GFW_BOOT completion before doing any significant setup on the GPU.
                 Self::wait_gfw_boot_completion(dev, bar, spec.chipset)?;
             },
 
             // Initialize this early because `gsp_resources` depends on it.
-            sysmem_flush: SysmemFlush::register(dev, bar, spec.chipset)?,
+            sysmem_flush: SysmemFlush::register(*dma, bar, spec.chipset)?,
 
             gsp_resources <- try_pin_init!(GspResources {
                 device: pdev,
 
+                dma: *dma,
+
                 spec: *spec,
 
                 bar,
 
-                gsp_falcon: Falcon::new(dev, spec.chipset, bar)?,
+                gsp_falcon: Falcon::new(*dma, spec.chipset, bar)?,
 
-                sec2_falcon: Falcon::new(dev, spec.chipset, bar)?,
+                sec2_falcon: Falcon::new(*dma, spec.chipset, bar)?,
 
-                fsp: Fsp::try_new(dev, bar, spec.chipset)?,
+                fsp: Fsp::try_new(*dma, bar, spec.chipset)?,
 
                 timer: Timer::setup(dev, bar, spec.chipset, fsp.as_ref())?,
 
                 vgpu: VgpuManager::new(pdev, spec.chipset, fsp.as_mut()),
 
-                gsp <- Gsp::new(pdev, bar),
+                gsp <- Gsp::new(*dma, bar),
 
                 // This member must be initialized last, so the `UnloadBundle` can never be dropped
                 // from outside of the constructed `GspResources`, ensuring that the unload sequence
                 // is properly run in case of failure.
                 unload_bundle: gsp.boot(GspBootContext {
                     pdev,
+                    dma: *dma,
                     bar,
                     chipset: spec.chipset,
                     gsp_falcon,
diff --git a/drivers/gpu/nova-core/gsp.rs b/drivers/gpu/nova-core/gsp.rs
index 2f1cdf8b7bec..908ecfbcd2aa 100644
--- a/drivers/gpu/nova-core/gsp.rs
+++ b/drivers/gpu/nova-core/gsp.rs
@@ -7,6 +7,7 @@
     debugfs,
     device,
     dma::{
+        self,
         Coherent,
         CoherentBox,
         CoherentView,
@@ -64,6 +65,7 @@
 /// - `'ctx` is a shorter lifetime during which this context borrows those subdevices.
 pub(crate) struct GspBootContext<'ctx, 'gpu> {
     pub(crate) pdev: &'gpu pci::Device<device::Bound>,
+    pub(crate) dma: dma::Handle<'gpu>,
     pub(crate) bar: Bar0<'gpu>,
     pub(crate) chipset: Chipset,
     pub(crate) gsp_falcon: &'ctx Falcon<'gpu, GspFalcon>,
@@ -114,25 +116,20 @@ pub(crate) struct Gsp<'gsp> {
 }
 
 impl<'gsp> Gsp<'gsp> {
-    // Creates an in-place initializer for a `Gsp` manager for `pdev`.
-    pub(crate) fn new(
-        pdev: &'gsp pci::Device<device::Bound>,
-        bar: Bar0<'gsp>,
-    ) -> impl PinInit<Self, Error> + 'gsp {
+    // Creates an in-place initializer for a `Gsp` manager for the device.
+    pub(crate) fn new(dma: dma::Handle<'gsp>, bar: Bar0<'gsp>) -> impl PinInit<Self, Error> + 'gsp {
         pin_init::pin_init_scope(move || {
-            let dev = pdev.as_ref();
-
-            let log_buffers = LogBuffers::new(dev)?;
+            let log_buffers = LogBuffers::new(dma)?;
 
             // Initialise the logging structures. The OpenRM equivalents are in:
             // _kgspInitLibosLoggingStructures (allocates memory for buffers)
             // kgspSetupLibosInitArgs_IMPL (creates pLibosInitArgs[] array)
             Ok(try_pin_init!(Self {
-                cmdq <- Cmdq::new(dev, bar),
-                rmargs: Coherent::init(dev, GFP_KERNEL, GspArgumentsPadded::new(&cmdq))?,
+                cmdq <- Cmdq::new(dma, bar),
+                rmargs: Coherent::init(dma.device(), GFP_KERNEL, GspArgumentsPadded::new(&cmdq))?,
                 libos: {
                     let mut libos = CoherentBox::zeroed_slice(
-                        dev,
+                        dma.device(),
                         GSP_PAGE_SIZE / size_of::<LibosMemoryRegionInitArgument>(),
                         GFP_KERNEL,
                     )?;
diff --git a/drivers/gpu/nova-core/gsp/boot.rs b/drivers/gpu/nova-core/gsp/boot.rs
index 9d5da5b165ac..fc24a779305f 100644
--- a/drivers/gpu/nova-core/gsp/boot.rs
+++ b/drivers/gpu/nova-core/gsp/boot.rs
@@ -39,7 +39,7 @@ pub(crate) fn boot(
         let dev = pdev.as_ref();
         let hal = super::hal::gsp_hal(chipset);
 
-        let gsp_fw = KBox::pin_init(GspFirmware::new(dev, chipset), GFP_KERNEL)?;
+        let gsp_fw = KBox::pin_init(GspFirmware::new(ctx.dma, chipset), GFP_KERNEL)?;
 
         self.cmdq
             .send_rpc_command_no_wait(commands::rpc::SetSystemInfo::new(
diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gsp/cmdq.rs
index e2b9a5383a66..d34174998f3d 100644
--- a/drivers/gpu/nova-core/gsp/cmdq.rs
+++ b/drivers/gpu/nova-core/gsp/cmdq.rs
@@ -12,6 +12,7 @@
 use kernel::{
     device,
     dma::{
+        self,
         Coherent,
         CoherentBox,
         DmaAddress, //
@@ -174,12 +175,12 @@ struct DmaGspMem<'a> {
 }
 
 impl<'a> DmaGspMem<'a> {
-    /// Allocate a new instance and map it for `dev`.
-    fn new(dev: &'a device::Device<device::Bound>, bar: Bar0<'a>) -> Result<Self> {
+    /// Allocate a new instance and map it for the device.
+    fn new(dma: dma::Handle<'a>, bar: Bar0<'a>) -> Result<Self> {
         const MSGQ_SIZE: u32 = cv!(size_of::<Msgq>());
         const RX_HDR_OFF: u32 = cv!(mem::offset_of!(Msgq, rx));
 
-        let mut gsp_mem = CoherentBox::<'_, GspMem>::zeroed(dev, GFP_KERNEL)?;
+        let mut gsp_mem = CoherentBox::<'_, GspMem>::zeroed(dma.device(), GFP_KERNEL)?;
         gsp_mem.cpuq.tx = MsgqTxHeader::new(MSGQ_SIZE, RX_HDR_OFF, MSGQ_NUM_PAGES);
         gsp_mem.cpuq.rx = MsgqRxHeader::new();
 
@@ -489,13 +490,14 @@ impl<'cmdq> Cmdq<'cmdq> {
     /// Default timeout for receiving a message from the GSP.
     pub(super) const RECEIVE_TIMEOUT: Delta = Delta::from_secs(5);
 
-    /// Creates a new command queue for `dev`.
+    /// Creates a new command queue for the device.
     pub(crate) fn new(
-        dev: &'cmdq device::Device<device::Bound>,
+        dma: dma::Handle<'cmdq>,
         bar: Bar0<'cmdq>,
     ) -> impl PinInit<Self, Error> + 'cmdq {
         pin_init_scope(move || {
-            let gsp_mem = DmaGspMem::new(dev, bar)?;
+            let dev = dma.device();
+            let gsp_mem = DmaGspMem::new(dma, bar)?;
 
             Ok(try_pin_init!(Self {
                 dma_addr: gsp_mem.mem.dma_address(),
diff --git a/drivers/gpu/nova-core/gsp/hal/gh100.rs b/drivers/gpu/nova-core/gsp/hal/gh100.rs
index 91201b51030e..f194df6656aa 100644
--- a/drivers/gpu/nova-core/gsp/hal/gh100.rs
+++ b/drivers/gpu/nova-core/gsp/hal/gh100.rs
@@ -154,9 +154,12 @@ fn boot<'gpu>(
         let fb_sizes = FbSizes::new(chipset, ctx.bar, ctx.vgpu.state())?;
         dev_dbg!(dev, "{:#x?}\n", fb_sizes);
 
-        let wpr_meta =
-            Coherent::init(dev, GFP_KERNEL, GspFwWprMeta::from_sizes(gsp_fw, &fb_sizes))?;
-        let args = FmcBootArgs::new(dev, chipset, wpr_meta, &gsp.libos, false)?;
+        let wpr_meta = Coherent::init(
+            ctx.dma.device(),
+            GFP_KERNEL,
+            GspFwWprMeta::from_sizes(gsp_fw, &fb_sizes),
+        )?;
+        let args = FmcBootArgs::new(ctx.dma, chipset, wpr_meta, &gsp.libos, false)?;
 
         let unload_bundle = crate::gsp::UnloadBundle(
             KBox::new(FspUnloadBundle, GFP_KERNEL)? as KBox<dyn UnloadBundle + 'gpu>
diff --git a/drivers/gpu/nova-core/gsp/hal/tu102.rs b/drivers/gpu/nova-core/gsp/hal/tu102.rs
index 2139279d40c4..44a758335118 100644
--- a/drivers/gpu/nova-core/gsp/hal/tu102.rs
+++ b/drivers/gpu/nova-core/gsp/hal/tu102.rs
@@ -5,7 +5,10 @@
 
 use kernel::{
     device,
-    dma::Coherent,
+    dma::{
+        self,
+        Coherent, //
+    },
     io::Io,
     types::ScopeGuard, //
 };
@@ -136,13 +139,15 @@ impl Tu102 {
     /// created the WPR2 region.
     fn run_fwsec_frts(
         &self,
-        dev: &device::Device<device::Bound>,
+        dma: dma::Handle<'_>,
         chipset: Chipset,
         falcon: &Falcon<'_, GspEngine>,
         bar: Bar0<'_>,
         bios: &Vbios,
         fb_ranges: &FbRanges,
     ) -> Result {
+        let dev = dma.device();
+
         // Check that the WPR2 region does not already exist - if it does, we cannot run
         // FWSEC-FRTS until the GPU is reset.
         if wpr2_range(bar).is_some() {
@@ -165,7 +170,7 @@ fn run_fwsec_frts(
         )?;
 
         if self.needs_fwsec_bootloader {
-            let fwsec_frts_bl = FwsecFirmwareWithBl::new(fwsec_frts, dev, chipset)?;
+            let fwsec_frts_bl = FwsecFirmwareWithBl::new(fwsec_frts, dma, chipset)?;
             // Load and run the bootloader, which will load FWSEC-FRTS and run it.
             fwsec_frts_bl.run(dev, falcon)?;
         } else {
@@ -214,16 +219,18 @@ fn run_fwsec_frts(
     /// Load and prepare the resources required to properly reset the GSP after it has been stopped.
     fn build_unload_bundle<'gpu>(
         &self,
-        dev: &'gpu device::Device<device::Bound>,
+        dma: dma::Handle<'gpu>,
         chipset: Chipset,
         bios: &Vbios,
         gsp_falcon: &Falcon<'_, GspEngine>,
         sec2_falcon: &Falcon<'_, Sec2>,
     ) -> Result<crate::gsp::UnloadBundle<'gpu>> {
+        let dev = dma.device();
+
         // Load the FWSEC SB firmware, as well as its bootloader if required.
         let fwsec_sb = FwsecFirmware::new(dev, gsp_falcon, bios, FwsecCommand::Sb)?;
         let fwsec_sb = if self.needs_fwsec_bootloader {
-            FwsecUnloadFirmware::WithBl(FwsecFirmwareWithBl::new(fwsec_sb, dev, chipset)?)
+            FwsecUnloadFirmware::WithBl(FwsecFirmwareWithBl::new(fwsec_sb, dma, chipset)?)
         } else {
             FwsecUnloadFirmware::WithoutBl(fwsec_sb)
         };
@@ -252,6 +259,7 @@ fn boot<'gpu>(
         ctx: &mut GspBootContext<'_, 'gpu>,
         gsp_fw: &GspFirmware<'gpu>,
     ) -> Result<Option<crate::gsp::UnloadBundle<'gpu>>> {
+        let dma = ctx.dma;
         let dev = ctx.dev();
         let bar = ctx.bar;
         let chipset = ctx.chipset;
@@ -264,7 +272,7 @@ fn boot<'gpu>(
         // Declared before the unload guard so that if Booter fails while running, SEC2 is reset
         // by the guard before this allocation is freed.
         let wpr_meta = Coherent::init(
-            dev,
+            dma.device(),
             GFP_KERNEL,
             GspFwWprMeta::from_ranges(gsp_fw, &fb_ranges),
         )?;
@@ -276,7 +284,7 @@ fn boot<'gpu>(
         // If the unload bundle creation fails, the GPU will need to be reset before the driver can
         // be probed again.
         let unload_bundle = self
-            .build_unload_bundle(dev, chipset, &bios, gsp_falcon, sec2_falcon)
+            .build_unload_bundle(dma, chipset, &bios, gsp_falcon, sec2_falcon)
             .inspect_err(|e| dev_warn!(dev, "Failed to prepare unload firmware: {:?}\n", e))
             .ok();
 
@@ -289,7 +297,7 @@ fn boot<'gpu>(
 
         // FWSEC-FRTS is not executed on chips where the FRTS region size is 0 (e.g. GA100).
         if !fb_ranges.frts.is_empty() {
-            self.run_fwsec_frts(dev, chipset, gsp_falcon, bar, &bios, &fb_ranges)?;
+            self.run_fwsec_frts(dma, chipset, gsp_falcon, bar, &bios, &fb_ranges)?;
         }
 
         gsp_falcon.reset()?;
diff --git a/drivers/gpu/nova-core/gsp/logbuffer.rs b/drivers/gpu/nova-core/gsp/logbuffer.rs
index 5455d990ffb4..57d063c15502 100644
--- a/drivers/gpu/nova-core/gsp/logbuffer.rs
+++ b/drivers/gpu/nova-core/gsp/logbuffer.rs
@@ -5,7 +5,10 @@
 use kernel::{
     debugfs,
     device,
-    dma::Coherent,
+    dma::{
+        self,
+        Coherent, //
+    },
     io::{
         io_project,
         Io, //
@@ -47,9 +50,9 @@
 pub(super) struct LogBuffer<'a>(pub(super) Coherent<'a, [u8; LOG_BUFFER_SIZE]>);
 
 impl<'a> LogBuffer<'a> {
-    /// Creates a new `LogBuffer` mapped on `dev`.
-    fn new(dev: &'a device::Device<device::Bound>) -> Result<Self> {
-        let obj = Self(Coherent::zeroed(dev, GFP_KERNEL)?);
+    /// Creates a new `LogBuffer` mapped on the device.
+    fn new(dma: dma::Handle<'a>) -> Result<Self> {
+        let obj = Self(Coherent::zeroed(dma.device(), GFP_KERNEL)?);
 
         let start_addr = obj.0.dma_address();
 
@@ -98,13 +101,13 @@ pub(super) struct LogBuffers<'a> {
 }
 
 impl<'a> LogBuffers<'a> {
-    /// Allocates the log buffers of `dev`.
-    pub(super) fn new(dev: &'a device::Device<device::Bound>) -> Result<Self> {
+    /// Allocates the log buffers of the device.
+    pub(super) fn new(dma: dma::Handle<'a>) -> Result<Self> {
         Ok(Self {
-            dev,
-            loginit: LogBuffer::new(dev)?,
-            logintr: LogBuffer::new(dev)?,
-            logrm: LogBuffer::new(dev)?,
+            dev: dma.device(),
+            loginit: LogBuffer::new(dma)?,
+            logintr: LogBuffer::new(dma)?,
+            logrm: LogBuffer::new(dma)?,
         })
     }
 
-- 
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 ` Matteo Kloiber [this message]
2026-11-29 22:24 ` [RFC PATCH v2 04/10] drm/tyr: configure DMA through dma::Setup 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 ` [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-4-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.