From: Deborah Brouwer <deborah.brouwer@collabora.com>
To: Ke Sun <sunke@kylinos.cn>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Lorenzo Stoakes" <ljs@kernel.org>,
"Lyude Paul" <lyude@redhat.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Sami Tolvanen" <samitolvanen@google.com>,
rust-for-linux@vger.kernel.org, dri-devel@lists.freedesktop.org,
driver-core@lists.linux.dev, "Alvin Sun" <alvin.sun@linux.dev>
Subject: Re: [PATCH v5 09/11] rust: device: expose the device DMA attribute
Date: Fri, 30 Oct 2026 17:04:56 -0700 [thread overview]
Message-ID: <auUwqGMOw_OtrWn3@um790> (raw)
In-Reply-To: <20261027-tyr-ioctls-v5-9-59dfe98cb003@kylinos.cn>
On Tue, Oct 27, 2026 at 12:41:02AM +0800, Ke Sun wrote:
> From: Sami Tolvanen <samitolvanen@google.com>
>
> A driver may need to know whether its device is DMA-coherent, but
> rust/kernel exposes no accessor for the attribute today.
>
> Add a transparent DmaAttr wrapper around device_get_dma_attr(), so all
> three attribute values (unset, non-coherent, coherent) are covered, and
> an is_coherent() accessor for the boolean case.
>
> Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
> [ Replace dma_coherent() with a DmaAttr wrapper covering all three
> attribute values. - Alvin ]
> Co-developed-by: Alvin Sun <alvin.sun@linux.dev>
> Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
> ---
> rust/kernel/device.rs | 24 ++++++++++++++++++++++++
> 1 file changed, 24 insertions(+)
>
> diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs
> index 2291d85b6849e..d5bbebdf620df 100644
> --- a/rust/kernel/device.rs
> +++ b/rust/kernel/device.rs
> @@ -260,6 +260,30 @@ pub unsafe fn drvdata_borrow<T>(&self) -> Pin<&T> {
> }
> }
>
> +/// The DMA attribute of a device, as reported by firmware. A transparent
> +/// wrapper around the kernel's `enum dev_dma_attr`, covering all its states.
> +#[repr(transparent)]
> +pub struct DmaAttr(bindings::dev_dma_attr);
> +
> +impl DmaAttr {
> + /// This wraps `device_get_dma_attr()` and only returns `true` for the
> + /// `DEV_DMA_COHERENT` attribute; no attribute or `DEV_DMA_NON_COHERENT` is non-coherent.
> + #[inline]
> + pub fn is_coherent(&self) -> bool {
> + self.0 == bindings::dev_dma_attr_DEV_DMA_COHERENT
> + }
I think Danilo was suggesting in the last version that all three enum
variants be exposed to the caller. You could remove this is_coherent() helper
and just provide something like this:
/// The device has no reported DMA attributes.
pub const NOT_SUPPORTED: Self = Self(bindings::dev_dma_attr_DEV_DMA_NOT_SUPPORTED);
/// The device is not DMA-coherent.
pub const NON_COHERENT: Self = Self(bindings::dev_dma_attr_DEV_DMA_NON_COHERENT);
/// The device is DMA-coherent.
pub const COHERENT: Self = Self(bindings::dev_dma_attr_DEV_DMA_COHERENT);
Then as long as you annotate struct DmaAttr with:
#[derive(Clone, Copy, PartialEq, Eq)]
Tyr can later do its own check like this:
let coherent = pdev.as_ref().dma_attr() == DmaAttr::COHERENT;
> +}
> +
> +impl Device<Bound> {
> + /// Returns the DMA attribute of the device as reported by firmware.
> + #[inline]
> + pub fn dma_attr(&self) -> DmaAttr {
> + // SAFETY: By the type invariants, `self.as_raw()` is a valid pointer
> + // to a `struct device`.
> + unsafe { DmaAttr(bindings::device_get_dma_attr(self.as_raw())) }
> + }
> +}
> +
> impl<Ctx: DeviceContext> Device<Ctx> {
> /// Obtain the raw `struct device *`.
> pub(crate) fn as_raw(&self) -> *mut bindings::device {
>
> --
> 2.43.0
>
next prev parent reply other threads:[~2026-10-31 0:05 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-26 16:40 [PATCH v5 00/11] drm/tyr: add VM and BO ioctl support Ke Sun via B4 Relay
2026-10-26 16:40 ` [PATCH v5 01/11] rust: sizes: add SZ_4G constant Ke Sun via B4 Relay
2026-10-26 16:40 ` [PATCH v5 02/11] rust: task: add task_size() Ke Sun via B4 Relay
2026-10-26 16:40 ` [PATCH v5 03/11] rust: sync: arc: relax `ForeignOwnable` for `Arc<T>` Ke Sun via B4 Relay
2026-10-26 16:40 ` [PATCH v5 04/11] drm/tyr: add per-file VM pool Ke Sun via B4 Relay
2026-10-26 16:40 ` [PATCH v5 05/11] drm/tyr: add user and MCU VM specifications Ke Sun via B4 Relay
2026-10-28 0:23 ` Deborah Brouwer
2026-10-26 16:40 ` [PATCH v5 06/11] drm/tyr: add BO creation and lookup helpers Ke Sun via B4 Relay
2026-10-26 16:41 ` [PATCH v5 07/11] drm/tyr: add VM-related ioctls Ke Sun via B4 Relay
2026-10-28 19:41 ` Deborah Brouwer
2026-10-26 16:41 ` [PATCH v5 08/11] drm/tyr: add BO-related ioctls Ke Sun via B4 Relay
2026-10-29 0:29 ` Deborah Brouwer
2026-10-31 0:10 ` Deborah Brouwer
2026-10-26 16:41 ` [PATCH v5 09/11] rust: device: expose the device DMA attribute Ke Sun via B4 Relay
2026-10-31 0:04 ` Deborah Brouwer [this message]
2026-10-26 16:41 ` [PATCH v5 10/11] drm/tyr: gem: flush write-combine BOs from probe-time coherence Ke Sun via B4 Relay
2026-10-31 0:15 ` Deborah Brouwer
2026-10-26 16:41 ` [PATCH v5 11/11] drm/tyr: gem: map cached BOs for DRM_PANTHOR_BO_WB_MMAP Ke Sun via B4 Relay
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=auUwqGMOw_OtrWn3@um790 \
--to=deborah.brouwer@collabora.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=alvin.sun@linux.dev \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--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=ljs@kernel.org \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=samitolvanen@google.com \
--cc=simona@ffwll.ch \
--cc=sunke@kylinos.cn \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox