From: Danilo Krummrich <dakr@kernel.org>
To: Daniel Almeida <daniel.almeida@collabora.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Mika Westerberg" <mika.westerberg@linux.intel.com>,
"Ying Huang" <huang.ying.caritas@gmail.com>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v8 3/3] rust: platform: allow ioremap of platform resources
Date: Wed, 28 May 2025 20:06:16 +0200 [thread overview]
Message-ID: <aDdQmJ-pen_MQNDB@cassiopeiae> (raw)
In-Reply-To: <5B875DFB-D655-4BAC-A475-43AE309520E2@collabora.com>
On Wed, May 28, 2025 at 02:29:44PM -0300, Daniel Almeida wrote:
> Hi Danilo,
>
> […]
>
> >
> >> + /// let offset = 0; // Some offset.
> >> + ///
> >> + /// // If the size is known at compile time, use `ioremap_resource_sized`.
> >> + /// // No runtime checks will apply when reading and writing.
> >> + /// let resource = pdev.resource(0).ok_or(ENODEV)?;
> >> + /// let iomem = pdev.ioremap_resource_sized::<42>(&resource)?;
> >> + ///
> >> + /// // Read and write a 32-bit value at `offset`. Calling `try_access()` on
> >> + /// // the `Devres` makes sure that the resource is still valid.
> >> + /// let data = iomem.try_access().ok_or(ENODEV)?.read32_relaxed(offset);
> >> + ///
> >> + /// iomem.try_access().ok_or(ENODEV)?.write32_relaxed(data, offset);
> >
> > Since this won't land for v6.16, can you please use Devres::access() [1]
> > instead? I.e.
> >
> > let iomem = pdev.ioremap_resource_sized::<42>(&resource)?;
> > let io = Devres::access(pdev.as_ref())?;
> >
> > let data = io.read32_relaxed(offset);
> > io.write32_relaxed(data, offset);
> >
> > Devres::access() is in nova-next and lands in v6.16.
> >
> > [1] https://gitlab.freedesktop.org/drm/nova/-/commit/f301cb978c068faa8fcd630be2cb317a2d0ec063
>
> Devres:access takes &Device<Bound>, but the argument in probe() is
> &Device<Core>.
>
> Are these two types supposed to convert between them? I see no explicit
> function to do so.
Yes, it comes from impl_device_context_deref!() [1], which, as the name implies,
implements the corresponding Deref traits.
Device dereference in the following way:
&Device<Core> -> &Device<Bound> -> &Device (i.e. &Device<Normal>)
You can just pass in the &Device<Core>, it will work.
[1] https://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git/tree/rust/kernel/device.rs?h=driver-core-next#n284
next prev parent reply other threads:[~2025-05-28 18:06 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-09 20:29 [PATCH v8 0/3] rust: platform: add Io support Daniel Almeida
2025-05-09 20:29 ` [PATCH v8 1/3] rust: io: add resource abstraction Daniel Almeida
2025-05-15 15:53 ` Danilo Krummrich
2025-05-09 20:29 ` [PATCH v8 2/3] rust: io: mem: add a generic iomem abstraction Daniel Almeida
2025-05-15 16:01 ` Danilo Krummrich
2025-05-09 20:29 ` [PATCH v8 3/3] rust: platform: allow ioremap of platform resources Daniel Almeida
2025-05-15 16:23 ` Danilo Krummrich
2025-05-28 17:29 ` Daniel Almeida
2025-05-28 18:06 ` Danilo Krummrich [this message]
2025-05-16 8:39 ` Danilo Krummrich
2025-05-15 15:49 ` [PATCH v8 0/3] rust: platform: add Io support Danilo Krummrich
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=aDdQmJ-pen_MQNDB@cassiopeiae \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=benno.lossin@proton.me \
--cc=bhelgaas@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=huang.ying.caritas@gmail.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mika.westerberg@linux.intel.com \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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;
as well as URLs for NNTP newsgroup(s).