From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.216.248.212 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795991107; b=O7cz7yXFHJEX5OmqvUrhCkck7o7+Vn/P1PDVmwXhAofZo2zm2JtyepfuegUVonMlQc+4 4fzEsUcs3Nl0qKroBWYVU8zX+KPK0BjyNa+NbS1/hAh17RNkrMu/vBU2wI+KZtwY3Du+k H8ljnXBz8DewjFYt1CNnBvKOxs5BDvmTL5J+UnxzazyWmf2Des+8H3rlqci8qzdZvTmZ9 2iNoHrIRSju0owXmR8KoZnaUaQ9bZFaAa3ZEiw4TJ5Kz3ukMmYwg2eeXlGvvkI2Tt64VM XjNoH4dTiyHEGCDJptd1VHbgKx0WWFwD/gLzSKFUSWhzdgI0BXO+570wnnf/eZWNvVg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795991107; h=DMARC-Filter:From:DKIM-Signature:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=UBk8WqonRfO2YHecyoosWIEOASojcR6JikwwKhrGskg=; b=0uFyY96yyA5yXM517vCEvoloLmgjc0l2TMht3qUeLJRmH3LO1KwcFvAL2oZXepoCIlrw yYbzZ7dXzptth5NFvN4cq1hPk9Zq3ydRygVsq3KrqUC7TrdxnrqpsWP1qDhye/lvP9gCu UZ2354UMVKN8AzppSN+puBv9CTkhO0kWw/he4Kp7+J7wOSBg4GwasVNJ6aE4TZmGKdmaW lQDV4uaDeYv7zhXv7NFhvBxrEGplhsiK3GXjtzffa8zta344ywjf8H4zMOOVecKIZ+OrF SZBx5oUnsZqFTYkJYeVpai9UJzEU2rKmhk3RSx945HAqQczH3yII+EyOEKVhaLDpx5Q== 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=RZXN9eRC; arc=none smtp.remote-ip=91.216.248.212 Received: from bulk0.mail-out.lima-city.de (bulk0.mail-out.lima-city.de [91.216.248.212]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A329606A33B; Sun, 29 Nov 2026 22:25:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9A329606A33B 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=RZXN9eRC From: Matteo Kloiber DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=matt3o12.de; s=securedbylima-20230709; t=1795991099; bh=Tpwyf/tsT0BK3/PmJ4nKjVl4u6ZOdGOTRacvJdYNsKE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RZXN9eRCKWmG2TnoAhjfpElNhMvwutulzazhlVrIowWOKGektPkVCeRMIMMuWTZAG YAPi4p7xt/nJgRkdOoZVIUwYkjvYACFKBuG7OAYpiwB84rxjnM01a4URhVJ4W04RrI C7uOu8Q7AFZ22ufWEQWLF/sroB32WS9fryM2o6gdcJIC1pfX9FjbOa9Ug/1PbR7iTK +Qf8ce7ghAbtNE9fnDic6NPQKx5kU5lYVHZUlD+KMmuPhPP7sYOu0k/4UzhrafwbzT x/tbmPs/Ic33z9CsW0KWbAzChjy1W8Zt2ENJX7dwEmSujKEql8ej84AEpRm1Z2fms3 zAGPppc8EXtdw== 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 04/10] drm/tyr: configure DMA through dma::Setup Date: Sun, 29 Nov 2026 23:24:23 +0100 Message-ID: <20261129222429.2380652-5-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 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 --- 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>, - _tokens: platform::InitTokens<'bound>, + tokens: platform::InitTokens<'bound>, _info: Option<&'bound Self::IdInfo>, ) -> impl PinInit, 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::::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, + dma: dma::Handle<'drm>, iomem: Arc>, ddev: &TyrDrmDevice, mmu: ArcBorrow<'_, Mmu<'drm>>, gpu_info: &GpuInfo, ) -> Result> { - 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, + dma: dma::Handle<'drm>, va_bits: u32, pa_bits: u32, ) -> impl pin_init::PinInit, 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, + /// 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, + 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>, /// MMU manager. mmu: Arc>, - /// Parent device used for DMA mapping and page-table operations. + /// Parent device. dev: &'drm Device, + /// 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>>, @@ -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, + dma: dma::Handle<'drm>, ddev: &TyrDrmDevice, mmu: ArcBorrow<'_, Mmu<'drm>>, gpu_info: &GpuInfo, ) -> Result>> { + 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 { 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