[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250816-rust-overlay-abs-v2-2-48a2c8921df2@beagleboard.org>
Date: Sat, 16 Aug 2025 11:27:46 +0530
From: Ayush Singh <ayush@...gleboard.org>
To: Jason Kridner <jkridner@...gleboard.org>,
Deepak Khatri <lorforlinux@...gleboard.org>,
Robert Nelson <robertcnelson@...gleboard.org>,
Miguel Ojeda <ojeda@...nel.org>, Dhruva Gole <d-gole@...com>,
Alex Gaynor <alex.gaynor@...il.com>, Boqun Feng <boqun.feng@...il.com>,
Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Andreas Hindborg <a.hindborg@...nel.org>, Alice Ryhl <aliceryhl@...gle.com>,
Trevor Gross <tmgross@...ch.edu>, Danilo Krummrich <dakr@...nel.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"Rafael J. Wysocki" <rafael@...nel.org>, Rob Herring <robh@...nel.org>,
Saravana Kannan <saravanak@...gle.com>, Benno Lossin <lossin@...nel.org>,
Benno Lossin <lossin@...nel.org>
Cc: rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
devicetree@...r.kernel.org, Ayush Singh <ayush@...gleboard.org>
Subject: [PATCH v2 2/2] rust: kernel: of: Add overlay id abstraction
Allow applying devicetree overlays from Rust.
The overlay is removed on Drop.
Signed-off-by: Ayush Singh <ayush@...gleboard.org>
---
rust/kernel/of.rs | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/rust/kernel/of.rs b/rust/kernel/of.rs
index 74d42dce06f0e9f67a0e5bd1287117b4966d4af9..646148cc959fd5414271f9cf9023ef5d77a2ac2c 100644
--- a/rust/kernel/of.rs
+++ b/rust/kernel/of.rs
@@ -75,3 +75,37 @@ 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;
+
+ // Ensure that overlay length fits in u32
+ let Ok(overlay_len) = overlay.len().try_into() else {
+ return Err(crate::error::code::E2BIG);
+ };
+
+ crate::error::to_result(unsafe {
+ bindings::of_overlay_fdt_apply(
+ overlay.as_ptr().cast(),
+ overlay_len,
+ &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.50.1
Powered by blists - more mailing lists