From: Ayush Singh <ayush@beagleboard.org>
To: "Jason Kridner" <jkridner@beagleboard.org>,
"Deepak Khatri" <lorforlinux@beagleboard.org>,
"Robert Nelson" <robertcnelson@beagleboard.org>,
"Miguel Ojeda" <ojeda@kernel.org>, "Dhruva Gole" <d-gole@ti.com>,
"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>,
"Danilo Krummrich" <dakr@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Saravana Kannan" <saravanak@google.com>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, Ayush Singh <ayush@beagleboard.org>
Subject: [PATCH 2/2] rust: kernel: of: Add overlay id abstraction
Date: Tue, 22 Apr 2025 18:02:10 +0530 [thread overview]
Message-ID: <20250422-rust-overlay-abs-v1-2-85779c1b853d@beagleboard.org> (raw)
In-Reply-To: <20250422-rust-overlay-abs-v1-0-85779c1b853d@beagleboard.org>
Allow applying devicetree overlays from Rust.
The overlay is removed on Drop.
Signed-off-by: Ayush Singh <ayush@beagleboard.org>
---
rust/kernel/of.rs | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/rust/kernel/of.rs b/rust/kernel/of.rs
index db4ec26ff7de024f5e513a2223cfd841f57b1434..76dbb118d2dc21d1174e0a1ca8f8610d1d176119 100644
--- a/rust/kernel/of.rs
+++ b/rust/kernel/of.rs
@@ -80,3 +80,32 @@ pub fn as_raw(&self) -> *mut bindings::device_node {
self.0.get()
}
}
+
+/// Devicetree overlay present in livetree.
+///
+/// The overlay is removed on Drop
+pub struct OvcsId(kernel::ffi::c_int);
+
+impl OvcsId {
+ /// Create and apply an overlay changeset to the live tree.
+ pub fn of_overlay_fdt_apply(overlay: &[u8], base: &DeviceNode) -> Result<Self> {
+ let mut ovcs_id: kernel::ffi::c_int = 0;
+
+ crate::error::to_result(unsafe {
+ bindings::of_overlay_fdt_apply(
+ overlay.as_ptr().cast(),
+ overlay.len().try_into().unwrap(),
+ &mut ovcs_id,
+ base.as_raw(),
+ )
+ })?;
+
+ Ok(Self(ovcs_id))
+ }
+}
+
+impl Drop for OvcsId {
+ fn drop(&mut self) {
+ unsafe { bindings::of_overlay_remove(&mut self.0) };
+ }
+}
--
2.49.0
prev parent reply other threads:[~2025-04-22 12:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-22 12:32 [PATCH 0/2] rust: Add abstractions for applying devicetree overlays Ayush Singh
2025-04-22 12:32 ` [PATCH 1/2] rust: kernel: of: Add DeviceNode abstraction Ayush Singh
2025-04-22 12:32 ` Ayush Singh [this message]
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=20250422-rust-overlay-abs-v1-2-85779c1b853d@beagleboard.org \
--to=ayush@beagleboard.org \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=d-gole@ti.com \
--cc=dakr@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=jkridner@beagleboard.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lorforlinux@beagleboard.org \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=robertcnelson@beagleboard.org \
--cc=robh@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=saravanak@google.com \
--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).