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=ot1/OSZUypNL0tmiVR4nwE4+J/4Iu3EsKA65GiOPpt9nJfU1fCTXHGzwm093FoIlj+BE HBKP2seQZKSkCgPPYxbQdUPPMtSuuJQERhf4VmEMwbsSOqkTPJ47PyUoF4ESxSD1f+JyO H2hQzP22ffWEzcsO9F3I+dP/eeyeKdJZrBNzeOnvt254eX3exdNHLIH5SS7DYQT1ZIXhR 8+K9LkN3gRTSD4jJg0ntNmQ9GJ1BpDThsJNxT/rIA6dm1hbiWqCoiMntdMrtDnfJTYi+3 skzBSYPTecGmTg8JVwaYy1hRC6N9s437kgfmEtKZdmOFilfMLCp2txcA0wFRi5jWsyw== 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=lyGI+8wB7pX70ceAmeF6B8D0Qsov0W8qwZuMmNaCGHtVd4/d1JqfSWEwjdN/LvqQKr9D Q5IcH0cHS3UEeDhSmOpOat7lUK4h09+dwF3g67XdT/WkYCF18hYi4iAjAiepv2FiyvQb+ 9FwNxLnetr86n+0w5VTK43Djf2KNZQUdR34KS4/bKPxhaV5B+zqML6zIbnM50/+XxArfs QLPhdTgDjAd4Wo95WC1Ai30e9Lx7YPdTmIIRQNzP1swmwPW5HSTp8TXSGHFmun90m9H2E u1gT0cp+XxDexLXBPK9xY+bLoMcLKVrH+dPQjhmRqfpfp4F4HvXfY/+SFot65GxWVxw== 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 4808F606A697; Sun, 29 Nov 2026 22:25:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4808F606A697 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: driver-core@lists.linux.dev 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