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=1795991109; b=eKtYSQOkux3hrO9//SFlPJEfdbYl3NTSyVjmvrOpoz3fTMZvIKWQVj8TptLw7ltH2KtO g/7EHRVi0Xq9eemvu4NH85WTJwgMkhqzo11qkI1UDf1djLcndqBM7lbknDhazN5tUhsCt EpbCaCq8UdvtCFGLrfXf4fOkLXqZipMn9+qaU/76Bx1Xcj0W1dgJ8A9I6mdqegRvC3YYl SwXC2HBy3JUjwS4GEeRwpjMNE76cSAfltxJ3f28/2X323vnkhscGcn/u84W4eWu9yHZu5 x4Si5nKBvIjC1udmvLHsi4HYJ09EVwmyiNLfjFUwS7iyekWOK2ntB7Hzw9NkYROXPsw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795991109; h=DMARC-Filter:From:DKIM-Signature:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=+9cV8VnipJON4KCxj/WNwqFNKaQypbMCRRqa8hgwEmA=; b=pnT2N/l+cde3lxzIjOaOn/E97qNlrF1W0VKlQEByxmTYtoHdjGgUkKG3kEm8x/l2Oysg 0FPomGQu0dXEIVLCZ4HNc857eYfnZRIGwqkmT5b2M78l2uCYn04d45MWJONimZLUIWCRd v/FjF2vb4/sMUS9zM29F9cnOAeATMXhU8uxAh20ys+5+4fzt/+Y/Efj1Pn1TbTKg7lGdW cFdoXvtr0guHliPq8G4MiBKsOfrM2G2RB1Ulf/VA2zQIk8KL/bkLfA1N6SG7AHkdjBE0R iO/lrgfPO2wUw5wOswa4EfTrkoo78/p0gKczgqDKjwNeYh6bb7OXKPrXMrwuSMk+1TQ== 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=jbHqD3MN; 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)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 48072606A687; Sun, 29 Nov 2026 22:25:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 48072606A687 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=jbHqD3MN From: Matteo Kloiber DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=matt3o12.de; s=securedbylima-20230709; t=1795991100; bh=aKZbUgIy8fafzMu3nYvUCyDVGjQ5NGc+El/5Zp4sUO8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jbHqD3MNnQCBdt6mpqIwp8XJJJhTJQRFdvqgPnb544hzn8Uv3odkNIyp6GJb0TQZg H3MVx0P3RoJHZfbUtpkMHmNBpuYrmH/UPTTWjL9Pu8W9hoY1sOFYy3p1lKRrQztqfy UACJFL30ZctzKuPivhajLKbN4skI24m6iA674bFLln2qUCs9s87BPswj5VJKF1swmv L/tBh+8diMlWMv16iNV8LRmyizSXwfTf0KA2VihhLY6yzhKR+OOaR6eAfvHyOJ8uZW uCxECTGrlJT8XWrW6XxWBSgFZomv5par5E9PBBREkefCVBBP44521RiI8GBHldnFMN C2ZHnTzf/+QLQ== 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 05/10] samples: rust: dma: configure DMA through dma::Setup Date: Sun, 29 Nov 2026 23:24:24 +0100 Message-ID: <20261129222429.2380652-6-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 Replace the unsafe dma::Device setter with dma::Setup::configure() and use the returned dma::Handle for the coherent allocation and the SG table. Both APIs still take a device, so hand them dma.device() for now. Set the maximum segment size to 64 KiB explicitly. This is the value the PCI core sets for every device, and the sample relied on it implicitly. Signed-off-by: Matteo Kloiber --- samples/rust/rust_dma.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/samples/rust/rust_dma.rs b/samples/rust/rust_dma.rs index b6a36d10bf74..c84107e5b2c3 100644 --- a/samples/rust/rust_dma.rs +++ b/samples/rust/rust_dma.rs @@ -4,15 +4,17 @@ //! //! To make this driver probe, QEMU must be run with `-device pci-testdev`. +use core::num::NonZeroU32; + use kernel::{ device::{ Bound, Core, // }, dma::{ + self, Coherent, DataDirection, - Device, DmaMask, // }, io::{ @@ -27,6 +29,7 @@ Owned, SGTable, // }, // + sizes::SizeConstants, }; struct DmaSampleDriver; @@ -77,19 +80,23 @@ impl pci::Driver for DmaSampleDriver { 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; pin_init::pin_init_scope(move || { dev_info!(pdev, "Probe DMA test driver.\n"); let mask = DmaMask::new::<64>(); - // SAFETY: There are no concurrent calls to DMA allocation and mapping primitives. - unsafe { pdev.dma_set_mask_and_coherent(mask)? }; + let dma = setup.configure(dma::Params { + streaming_mask: Some(mask), + coherent_mask: Some(mask), + max_seg_size: Some(const { NonZeroU32::new(u32::SZ_64K).unwrap() }), + })?; let ca: Coherent<'_, [MyStruct]> = - Coherent::zeroed_slice(pdev.as_ref(), TEST_VALUES.len(), GFP_KERNEL)?; + Coherent::zeroed_slice(dma.device(), TEST_VALUES.len(), GFP_KERNEL)?; for (i, value) in TEST_VALUES.into_iter().enumerate() { io_project!(ca, [panic: i]).copy_write(MyStruct::new(value.0, value.1)); @@ -98,7 +105,7 @@ fn probe<'bound>( let size = 4 * page::PAGE_SIZE; let pages = VVec::with_capacity(size, GFP_KERNEL)?; - let sgt = SGTable::new(pdev.as_ref(), pages, DataDirection::ToDevice, GFP_KERNEL); + let sgt = SGTable::new(dma.device(), pages, DataDirection::ToDevice, GFP_KERNEL); Ok(try_pin_init!(Self::Data { pdev, -- 2.51.2