From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.216.248.203 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795991106; b=P3k9YO91yYP8yojICUpxdJvFK2RZ3Y2AlpFbhJ08vuAkNJK85xc+Ui1lPPmYYJUpBfVu oWh7jXOcbxnb49A7qVlbhbz1eS0H/WAEE4IO8kOIoN97GBfC+jFIKbqU8uda27icA1IxT +lJwgqRWtl5oBSKGXY7FFBEMTVzvmHfI806ofcXIkbFPHXHdlyCAYnoLEDxfu0iFqk6LV q4sX85W3RJ/ODBss+W0kkDXuEyOn9qejFg4DMNnjrz2nViqTfZTldBkN6F2wUb8+ics8X 2pZZ1CMfGEl7kXfqCaPnta5tuGQWmPRsQb84AI0WQeLm2GnklLz/XconA729o1ifhPA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795991106; h=DMARC-Filter:From:DKIM-Signature:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=26rvoalo5kpExkptzw7mUWX07RqszcpNJjDMAmngExs=; b=i0NBc7QGVH8paIWQoiV7aIgbeRQLn+LhJKRD+QuicQw6lG0NleBnYHnBErBig20Z8MYx 7jIGDnqQMUc+VEY2QGHSelud4kwUYOl9UUzWc3eQAr74t0hJ17edmeG8FPdvYnvZ2LmR0 CNdbMmf1uBjafAm9ld4CkqSeU2O4UJN4ydFVh1poxrvNlpT3jLjCl2gjsj/Hr3HGbh8i+ /zWtfAC5DW8/sCyeia3l9QEyNBOBRx6AVUCH3ug7YVw1WeAgvRMrBmNHCrQmnDbDP9Pxx 4QhPaweIp32xxPHjmb/EB2GVakcHCDI3qPQfY1ktZz7zMgnPtWGvO7lDUAcmNFRmUMw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=matt3o12.de; spf=pass smtp.mailfrom=matt3o12.de; dkim=pass header.d=matt3o12.de header.i=@matt3o12.de header.a=rsa-sha256 header.s=securedbylima-20230709 header.b=bBbDuJoE; arc=none smtp.remote-ip=91.216.248.203 Received: from mx1.mail-out.lima-city.de (mx1.mail-out.lima-city.de [91.216.248.203]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B480606A33E; Sun, 29 Nov 2026 22:25:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6B480606A33E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=matt3o12.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=matt3o12.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=matt3o12.de header.i=@matt3o12.de header.a=rsa-sha256 header.s=securedbylima-20230709 header.b=bBbDuJoE From: Matteo Kloiber DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=matt3o12.de; s=securedbylima-20230709; t=1795991098; bh=aC4408tF+mJRIOo16ehQJE4ddqs0V59JTE6fB1hJb+Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bBbDuJoEGu8LghnkmKCyDxO9sumPGoFljPM04XyClJSLHSosYhgN++2bbg9AfA+dY xgir03OU8km1jb6fmQm649Pbqgml/S7h9hZF9pG6Ql5Di9cIHcKRikgCpjQMH2Mnv9 ZQl1IUrbeU6JiTn9hLtOfj90wnzT+nnVA7YiQTKwow4unJfd0XNpWtlXAHJvQqLD61 cKXoFi/0ri3Wi9fLduOHZyyAyX7K4162KpFELOjBBw7hon0FlGehas+q2pE+9ATIXO 2WFI7pzwIk1BqiMRlYXIAvhUu6fpyZdJsrP+UEoyQstCiASvYpQyfaqr/hJWMSQpOt vjnDUQK+4qdww== To: Danilo Krummrich , Alexandre Courbot , Alice Ryhl , Abdiel Janulgue , Robin Murphy , Andreas Hindborg , Gary Guo Cc: Daniel Almeida , Miguel Ojeda , David Airlie , Simona Vetter , Bjorn Helgaas , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Greg Kroah-Hartman , 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 Subject: [RFC PATCH v2 03/10] gpu: nova-core: configure DMA through dma::Setup Date: Sun, 29 Nov 2026 23:24:22 +0100 Message-ID: <20261129222429.2380652-4-kernel@matt3o12.de> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20261129222429.2380652-1-kernel@matt3o12.de> References: <20261129222429.2380652-1-kernel@matt3o12.de> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Matteo Kloiber --- 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>, - _tokens: pci::InitTokens<'bound>, + tokens: pci::InitTokens<'bound>, _info: Option<&'bound Self::IdInfo>, ) -> impl PinInit, 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>, dev: &'a device::Device, + 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, - chipset: Chipset, - bar: Bar0<'a>, - ) -> Result { + pub(crate) fn new(dma: dma::Handle<'a>, chipset: Chipset, bar: Bar0<'a>) -> Result { 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 + 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, + dma: dma::Handle<'sys>, bar: Bar0<'sys>, chipset: Chipset, ) -> Result { - 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, + dma: dma::Handle<'a>, chipset: Chipset, ) -> Result { - 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, - chipset: Chipset, - ) -> impl PinInit + '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 + '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, chipset: Chipset) -> Result { + pub(crate) fn new(dma: dma::Handle<'a>, chipset: Chipset) -> Result { + 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, 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, - data: VVec, - ) -> impl PinInit + '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) -> impl PinInit + '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::(), 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, fw: &Firmware) -> Result { + pub(crate) fn new(dma: dma::Handle<'a>, fw: &Firmware) -> Result { + 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, 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, + 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, + dma: dma::Handle<'a>, bar: Bar0<'a>, chipset: Chipset, ) -> Result> { 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, + 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::::new(dev, chipset, bar)?; - let fmc_fw = GspFmcFirmware::new(dev, chipset)?; + let dev = dma.device(); + let falcon = Falcon::::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, + /// 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>, + setup: dma::Setup<'gpu>, bar: Bar0<'gpu>, bar1: Bar1<'gpu>, ) -> impl PinInit + 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, + 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, - bar: Bar0<'gsp>, - ) -> impl PinInit + '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 + '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::(), 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, bar: Bar0<'a>) -> Result { + /// Allocate a new instance and map it for the device. + fn new(dma: dma::Handle<'a>, bar: Bar0<'a>) -> Result { const MSGQ_SIZE: u32 = cv!(size_of::()); 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, + dma: dma::Handle<'cmdq>, bar: Bar0<'cmdq>, ) -> impl PinInit + '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 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, + 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, + dma: dma::Handle<'gpu>, chipset: Chipset, bios: &Vbios, gsp_falcon: &Falcon<'_, GspEngine>, sec2_falcon: &Falcon<'_, Sec2>, ) -> Result> { + 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>> { + 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) -> Result { - let obj = Self(Coherent::zeroed(dev, GFP_KERNEL)?); + /// Creates a new `LogBuffer` mapped on the device. + fn new(dma: dma::Handle<'a>) -> Result { + 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) -> Result { + /// Allocates the log buffers of the device. + pub(super) fn new(dma: dma::Handle<'a>) -> Result { 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