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" <lossin@kernel.org>,
"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>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v15 2/3] rust: io: mem: add a generic iomem abstraction
Date: Sat, 19 Jul 2025 15:51:59 +0200 [thread overview]
Message-ID: <DBG2XI0UZ3B5.I9KLFJUYQUMC@kernel.org> (raw)
In-Reply-To: <20250717-topics-tyr-platform_iomem-v15-2-beca780b77e3@collabora.com>
On Thu Jul 17, 2025 at 5:55 PM CEST, Daniel Almeida wrote:
> + /// Maps an [`IoRequest`] where the size is known at compile time.
> + ///
> + /// This uses the [`ioremap()`] C API.
> + ///
> + /// [`ioremap()`]: https://docs.kernel.org/driver-api/device-io.html#getting-access-to-the-device
> + ///
> + /// # Examples
> + ///
> + /// The following example uses a [`platform::Device`] for illustration
> + /// purposes.
> + ///
> + /// ```no_run
> + /// use kernel::{bindings, c_str, platform, of, device::Core};
> + /// struct SampleDriver;
> + ///
> + /// impl platform::Driver for SampleDriver {
> + /// # type IdInfo = ();
> + /// # const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = None;
> + ///
> + /// fn probe(
> + /// pdev: &platform::Device<Core>,
> + /// info: Option<&Self::IdInfo>,
> + /// ) -> Result<Pin<KBox<Self>>> {
> + /// let offset = 0; // Some offset.
> + ///
> + /// // If the size is known at compile time, use [`Self::iomap_sized`].
> + /// //
> + /// // No runtime checks will apply when reading and writing.
> + /// let request = pdev.io_request_by_index(0).ok_or(ENODEV)?;
> + /// let iomem = request.iomap_sized::<42>();
> + /// let iomem = KBox::pin_init(iomem, GFP_KERNEL)?;
> + ///
> + /// let io = iomem.access(pdev.as_ref())?;
> + ///
> + /// // Read and write a 32-bit value at `offset`.
> + /// let data = io.read32_relaxed(offset);
> + ///
> + /// io.write32_relaxed(data, offset);
> + ///
> + /// # Ok(KBox::new(SampleDriver, GFP_KERNEL)?.into())
> + /// }
> + /// }
> + /// ```
> + pub fn iomap_sized<const SIZE: usize>(self) -> impl PinInit<Devres<IoMem<SIZE>>, Error> + 'a {
> + IoMem::new(self)
> + }
This doc-test and the one below break the build, since the used platform device
infrastructure is introduced with the next patch.
I can set them to `ignore` and we turn them into `no_run` with a subsequent
patch.
> + /// Maps an [`IoRequest`] where the size is not known at compile time,
> + ///
> + /// This uses the [`ioremap()`] C API.
> + ///
> + /// [`ioremap()`]: https://docs.kernel.org/driver-api/device-io.html#getting-access-to-the-device
> + ///
> + /// # Examples
> + ///
> + /// The following example uses a [`platform::Device`] for illustration
> + /// purposes.
> + ///
> + /// ```no_run
> + /// use kernel::{bindings, c_str, platform, of, device::Core};
> + /// struct SampleDriver;
> + ///
> + /// impl platform::Driver for SampleDriver {
> + /// # type IdInfo = ();
> + /// # const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = None;
> + ///
> + /// fn probe(
> + /// pdev: &platform::Device<Core>,
> + /// info: Option<&Self::IdInfo>,
> + /// ) -> Result<Pin<KBox<Self>>> {
> + /// let offset = 0; // Some offset.
> + ///
> + /// // Unlike [`Self::iomap_sized`], here the size of the memory region
> + /// // is not known at compile time, so only the `try_read*` and `try_write*`
> + /// // family of functions should be used, leading to runtime checks on every
> + /// // access.
> + /// let request = pdev.io_request_by_index(0).ok_or(ENODEV)?;
> + /// let iomem = request.iomap();
> + /// let iomem = KBox::pin_init(iomem, GFP_KERNEL)?;
> + ///
> + /// let io = iomem.access(pdev.as_ref())?;
> + ///
> + /// let data = io.try_read32_relaxed(offset)?;
> + ///
> + /// io.try_write32_relaxed(data, offset)?;
> + ///
> + /// # Ok(KBox::new(SampleDriver, GFP_KERNEL)?.into())
> + /// }
> + /// }
> + /// ```
> + pub fn iomap(self) -> impl PinInit<Devres<IoMem<0>>, Error> + 'a {
> + Self::iomap_sized::<0>(self)
> + }
> +
> + /// Same as [`Self::iomap`] but with exclusive access to the underlying
> + /// region.
> + pub fn iomap_exclusive(self) -> impl PinInit<Devres<ExclusiveIoMem<0>>, Error> + 'a {
> + Self::iomap_exclusive_sized::<0>(self)
> + }
> +}
next prev parent reply other threads:[~2025-07-19 13:52 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-17 15:55 [PATCH v15 0/3] rust: platform: add Io support Daniel Almeida
2025-07-17 15:55 ` [PATCH v15 1/3] rust: io: add resource abstraction Daniel Almeida
2025-07-17 15:55 ` [PATCH v15 2/3] rust: io: mem: add a generic iomem abstraction Daniel Almeida
2025-07-17 19:45 ` Danilo Krummrich
2025-07-18 12:23 ` Daniel Almeida
2025-07-19 13:51 ` Danilo Krummrich [this message]
2025-07-19 14:08 ` [PATCH] rust: io: mem: enable IoRequest doc-tests Danilo Krummrich
2025-07-20 17:47 ` Danilo Krummrich
2025-07-17 15:55 ` [PATCH v15 3/3] rust: platform: add resource accessors Daniel Almeida
2025-07-19 13:15 ` Danilo Krummrich
2025-07-19 16:19 ` Miguel Ojeda
2025-07-19 16:29 ` Miguel Ojeda
2025-07-19 8:01 ` [PATCH v15 0/3] rust: platform: add Io support Greg Kroah-Hartman
2025-07-19 10:16 ` Danilo Krummrich
2025-07-20 0:34 ` Daniel Almeida
2025-07-20 17:46 ` Danilo Krummrich
2025-07-23 7:35 ` Dirk Behme
2025-07-23 13:33 ` Daniel Almeida
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=DBG2XI0UZ3B5.I9KLFJUYQUMC@kernel.org \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@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=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--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).