From: Alice Ryhl <aliceryhl@google.com>
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>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
"Fiona Behrens" <me@kloenk.dev>
Subject: Re: [PATCH v13 1/3] rust: io: add resource abstraction
Date: Tue, 15 Jul 2025 08:03:37 +0000 [thread overview]
Message-ID: <aHYLWc_KkMHj_jF-@google.com> (raw)
In-Reply-To: <20250711-topics-tyr-platform_iomem-v13-1-06328b514db3@collabora.com>
On Fri, Jul 11, 2025 at 07:32:27PM -0300, Daniel Almeida wrote:
> In preparation for ioremap support, add a Rust abstraction for struct
> resource.
>
> A future commit will introduce the Rust API to ioremap a resource from a
> platform device. The current abstraction, therefore, adds only the
> minimum API needed to get that done.
>
> Co-developed-by: Fiona Behrens <me@kloenk.dev>
> Signed-off-by: Fiona Behrens <me@kloenk.dev>
> Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
Some nits below, but overall LGTM. With those fixed:
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
> + /// Requests a resource region.
> + ///
> + /// Exclusive access will be given and the region will be marked as busy.
> + /// Further calls to [`Self::request_region`] will return [`None`] if
> + /// the region, or a part of it, is already in use.
> + pub fn request_region(
> + &self,
> + start: ResourceSize,
> + size: ResourceSize,
> + name: &'static CStr,
> + flags: Flags,
> + ) -> Option<Region> {
> + // SAFETY:
> + // - Safe as per the invariant of `Resource`.
> + // - `__request_region` will store a reference to the name, but that is
> + // safe as the name is 'static.
> + let region = unsafe {
> + bindings::__request_region(
> + self.0.get(),
> + start,
> + size,
> + name.as_char_ptr(),
> + flags.0 as c_int,
> + )
> + };
> +
> + Some(Region(NonNull::new(region)?))
> + }
> +
> + /// Returns the size of the resource.
> + pub fn size(&self) -> ResourceSize {
> + let inner = self.0.get();
> + // SAFETY: safe as per the invariants of `Resource`.
> + unsafe { bindings::resource_size(inner) }
> + }
> +
> + /// Returns the start address of the resource.
> + pub fn start(&self) -> u64 {
This should be a ResourceSize, right? You use the ResourceSize type for
the `start` when calling `request_region`.
Or ... should we have another PhysAddr typedef that we can use here?
> + let inner = self.0.get();
> + // SAFETY: safe as per the invariants of `Resource`.
> + unsafe { (*inner).start }
> + }
> +
> + /// Returns the name of the resource.
> + pub fn name(&self) -> &'static CStr {
> + let inner = self.0.get();
> + // SAFETY: safe as per the invariants of `Resource`
> + unsafe { CStr::from_char_ptr((*inner).name) }
This is 'static? I would like this safety comment to explicitly say that
the string always lives forever no matter what resource you call this
on.
Alice
next prev parent reply other threads:[~2025-07-15 8:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-11 22:32 [PATCH v13 0/3] rust: platform: add Io support Daniel Almeida
2025-07-11 22:32 ` [PATCH v13 1/3] rust: io: add resource abstraction Daniel Almeida
2025-07-15 8:03 ` Alice Ryhl [this message]
2025-07-16 16:52 ` Daniel Almeida
2025-07-16 17:04 ` Alice Ryhl
2025-07-16 17:10 ` Danilo Krummrich
2025-07-11 22:32 ` [PATCH v13 2/3] rust: io: mem: add a generic iomem abstraction Daniel Almeida
2025-07-13 7:57 ` kernel test robot
2025-07-15 8:12 ` Alice Ryhl
2025-07-15 8:20 ` Danilo Krummrich
2025-07-11 22:32 ` [PATCH v13 3/3] rust: platform: add resource accessors 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=aHYLWc_KkMHj_jF-@google.com \
--to=aliceryhl@google.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=me@kloenk.dev \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.