From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.182.11 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1793405151; b=m+VUc4arVH7m1CUPDd2oKwr++Fu3hn/6pZYPcQ7PaiTaO6zORqfv2iroknyBHfMMCFBg xuI156M75cFKRL3bmVg3+yXioU6b9pNKT0DeBnVOzl1DvE34jnHzkAd+r/Wr3yuaNLSse EDWbxXnAL7S8AOOqQU6Bb/g1fhMD2DLfnc7mZl5VHInovC8DTsdMG6oJkyK6eAPYrCaeF SXega+oOwtfRYshs1euAaprw7998Z4bMoObRfNe99r2jYx8F5MWieR8BsBaA/lC4zrS5n tNdcUrRNpZqezVfq6/GhzIsYv1CVAaeZGiqNHXuwlLq+MRdAiUBu6OF3xNBxfw5p/aw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793405151; h=DMARC-Filter:DKIM-Signature:Received:Date:From:To:Cc:Subject: Message-ID:References:MIME-Version:Content-Type:Content-Disposition: In-Reply-To:X-Zoho-Virus-Status:X-Zoho-AV-Stamp; bh=f9yLN0RkK2Stc/zltKXQAqZKvxbRR8oE2ZWmMs+DjYY=; b=YuWP0qLTjz0khMVEtMqiOK5wKHAFvTRsVrbrqWUVb1vuNTIJQi5cecZACoD1ePw5qEx0 +ZLdVHqUnMjUeBxC1jf+VBIZxPRfr9EKJeb5qvEGWb5K3kfBBFAp+1NIB0L0+25uI4wWZ Q+RRS3qVLbm81TAHlHVmaCz/lnRsbyeC8dljdNzyqDVbx3bl1THX60nFWGVfXBEgX9ukl rUrwLrZLjquawKiAGW728w86Ih2sdHOvlVBck16EYzQ486t8q4o6SSFocRPlE917Fauil ox60DpJDtagYrLgwV+cwtb0vCmsZRvOC1cl4Xn8J4zkzPGe/kLK+xtXXfJrVZMJkV1g== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=zohomail header.b="hr/cVHWZ"; arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.182.11 Received: from sender5-op-o11.zoho.com (sender5-op-o11.zoho.com [165.173.182.11]) (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 528BB606A31A for ; Sat, 31 Oct 2026 00:05:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 528BB606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=zohomail header.b=hr/cVHWZ ARC-Seal: i=1; a=rsa-sha256; t=1793405100; cv=none; d=zohomail.com; s=zohoarc; b=bZnuB2JRIAo5BQbq0eqVFPpyTHolRV6/OKsdm6eLSklINLhpeygWJ2q8RytLnTllVesDo4eYdbNcLLZ8Shu6ArppdRZhqfVYkOe89TNDG8OkvjEstUGdSG3A/MnQC4gblemQSwO9pEveQWCPVElYqIShEgdSLG2l9yr+hLSi7/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793405100; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=f9yLN0RkK2Stc/zltKXQAqZKvxbRR8oE2ZWmMs+DjYY=; b=UV6+97th1ByaATcIIiz8w3uuQ649atGFFaH19Othp5jTvHQeoUxSGZKORBUWJTHKAm5VeOCa3z3z5wRgISMDBMVprkvhQK605ZiJnCCdTb/IEEyggR1Hu0riXlZSXInz4zZ5XA6zyIgSfvwIS2e9lJZJAk29d59ct6N6OJXEL/0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=deborah.brouwer@collabora.com; dmarc=pass header.from= DKIM-Signature: a=rsa-sha256; b=hr/cVHWZ3xZpO9zKcwmtmOY1N5jRHw8tunxASI99mON3or5AjFWCRzzQoktxiMN2d9GhzB4BggAqsFTCfnJCtTYPDK5ft/ZflZMtmj1bKJVcoMrCVhuv8HVJ7IIGj532XDY6iXMuXRszWn1E93s0jkjRejGkCsAry+hq1O2x1wE=; c=relaxed/relaxed; s=zohomail; d=collabora.com; v=1; bh=f9yLN0RkK2Stc/zltKXQAqZKvxbRR8oE2ZWmMs+DjYY=; h=Content-Description:Content-ID:Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Resent-Sender:Resent-Cc:Resent-Date:Resent-To:Reply-To:Resent-Message-ID:Resent-From:Sender:Subject:To:Date:From:Message-Id:Reply-To:Subject:To:Cc; Received: by smtp.zohomail.com with SMTPS id 1793405097674331.3192838468908; Fri, 30 Oct 2026 17:04:57 -0700 (PDT) Date: Fri, 30 Oct 2026 17:04:56 -0700 From: Deborah Brouwer To: Ke Sun Cc: Miguel Ojeda , Boqun Feng , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , Onur =?iso-8859-1?Q?=D6zkan?= , Lorenzo Stoakes , Lyude Paul , David Airlie , Simona Vetter , Greg Kroah-Hartman , "Rafael J. Wysocki" , Sami Tolvanen , rust-for-linux@vger.kernel.org, dri-devel@lists.freedesktop.org, driver-core@lists.linux.dev, Alvin Sun Subject: Re: [PATCH v5 09/11] rust: device: expose the device DMA attribute Message-ID: References: <20261027-tyr-ioctls-v5-0-59dfe98cb003@kylinos.cn> <20261027-tyr-ioctls-v5-9-59dfe98cb003@kylinos.cn> X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261027-tyr-ioctls-v5-9-59dfe98cb003@kylinos.cn> X-Zoho-Virus-Status: 1 X-Zoho-AV-Stamp: zmail-av-0.2.13.1.5.4/293.393.56 On Tue, Oct 27, 2026 at 12:41:02AM +0800, Ke Sun wrote: > From: Sami Tolvanen > > 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 > [ Replace dma_coherent() with a DmaAttr wrapper covering all three > attribute values. - Alvin ] > Co-developed-by: Alvin Sun > Signed-off-by: Alvin Sun > --- > 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(&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 { > + /// 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 Device { > /// Obtain the raw `struct device *`. > pub(crate) fn as_raw(&self) -> *mut bindings::device { > > -- > 2.43.0 >