From: Viresh Kumar <viresh.kumar@linaro.org>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
"Viresh Kumar" <vireshk@kernel.org>, "Nishanth Menon" <nm@ti.com>,
"Stephen Boyd" <sboyd@kernel.org>,
"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>
Cc: Viresh Kumar <viresh.kumar@linaro.org>,
linux-pm@vger.kernel.org,
Vincent Guittot <vincent.guittot@linaro.org>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH V7 14/16] rust: Extend OPP bindings with CPU frequency table
Date: Mon, 13 Jan 2025 16:53:09 +0530 [thread overview]
Message-ID: <47cfb24fd3c7429dc68a023a6b504e37bb13c141.1736766672.git.viresh.kumar@linaro.org> (raw)
In-Reply-To: <cover.1736766672.git.viresh.kumar@linaro.org>
This commit adds bindings for CPUFreq core related API.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
rust/kernel/opp.rs | 62 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+)
diff --git a/rust/kernel/opp.rs b/rust/kernel/opp.rs
index 22c4d543f456..147178410c60 100644
--- a/rust/kernel/opp.rs
+++ b/rust/kernel/opp.rs
@@ -16,6 +16,12 @@
types::{ARef, AlwaysRefCounted, Opaque},
};
+#[cfg(CONFIG_CPU_FREQ)]
+use crate::cpufreq;
+
+#[cfg(CONFIG_CPU_FREQ)]
+use core::ops::Deref;
+
use core::{marker::PhantomData, ptr};
use macros::vtable;
@@ -337,6 +343,56 @@ extern "C" fn config_regulators(
}
}
+/// CPU Frequency table created from OPP entries.
+#[cfg(CONFIG_CPU_FREQ)]
+pub struct FreqTable {
+ dev: ARef<Device>,
+ table: cpufreq::Table,
+}
+
+#[cfg(CONFIG_CPU_FREQ)]
+impl FreqTable {
+ /// Creates new instance of [`FreqTable`] from raw pointer.
+ fn new(table: &Table) -> Result<Self> {
+ let mut ptr: *mut bindings::cpufreq_frequency_table = ptr::null_mut();
+
+ // SAFETY: The requirements are satisfied by the existence of `Device` and its safety
+ // requirements.
+ to_result(unsafe {
+ bindings::dev_pm_opp_init_cpufreq_table(table.dev.as_raw(), &mut ptr)
+ })?;
+ Ok(Self {
+ dev: table.dev.clone(),
+ // SAFETY: The `ptr` is guaranteed by the C code to be valid.
+ table: unsafe { cpufreq::Table::from_raw(ptr) },
+ })
+ }
+
+ /// Returns reference to the underlying [`cpufreq::Table`].
+ pub fn table(&self) -> &cpufreq::Table {
+ &self.table
+ }
+}
+
+#[cfg(CONFIG_CPU_FREQ)]
+impl Deref for FreqTable {
+ type Target = cpufreq::Table;
+
+ #[inline]
+ fn deref(&self) -> &Self::Target {
+ &self.table
+ }
+}
+
+#[cfg(CONFIG_CPU_FREQ)]
+impl Drop for FreqTable {
+ fn drop(&mut self) {
+ // SAFETY: The requirements are satisfied by the existence of `Device` and its safety
+ // requirements.
+ unsafe { bindings::dev_pm_opp_free_cpufreq_table(self.dev.as_raw(), &mut self.as_raw()) };
+ }
+}
+
/// Operating performance point (OPP) table.
///
/// Wraps the kernel's `struct opp_table`.
@@ -541,6 +597,12 @@ pub fn adjust_voltage(
})
}
+ /// Create cpufreq table from OPP table.
+ #[cfg(CONFIG_CPU_FREQ)]
+ pub fn to_cpufreq_table(&mut self) -> Result<FreqTable> {
+ FreqTable::new(self)
+ }
+
/// Sets a matching OPP based on frequency.
pub fn set_rate(&self, freq: usize) -> Result<()> {
// SAFETY: The requirements are satisfied by the existence of `Device` and its safety
--
2.31.1.272.g89b43f80a514
next prev parent reply other threads:[~2025-01-13 11:24 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-13 11:22 [PATCH V7 00/16] Rust bindings for cpufreq and OPP core + sample driver Viresh Kumar
2025-01-13 11:22 ` [PATCH V7 01/16] cpufreq: Use enum for cpufreq flags that use BIT() Viresh Kumar
2025-01-13 11:22 ` [PATCH V7 02/16] PM / OPP: Add reference counting helpers for Rust implementation Viresh Kumar
2025-01-13 11:22 ` [PATCH V7 03/16] rust: cpu: Add from_cpu() Viresh Kumar
2025-01-14 18:44 ` Greg KH
2025-01-15 7:20 ` Viresh Kumar
2025-01-15 7:54 ` Greg KH
2025-01-15 7:58 ` Viresh Kumar
2025-01-15 8:09 ` Greg KH
2025-01-16 9:17 ` Viresh Kumar
2025-01-15 8:10 ` Alice Ryhl
2025-01-15 8:33 ` Viresh Kumar
2025-01-13 11:22 ` [PATCH V7 04/16] rust: device: Add property_present() Viresh Kumar
2025-01-14 18:42 ` Greg Kroah-Hartman
2025-01-14 18:42 ` Greg Kroah-Hartman
2025-01-15 7:15 ` Viresh Kumar
2025-01-15 7:35 ` Viresh Kumar
2025-01-15 17:21 ` Greg Kroah-Hartman
2025-01-13 11:23 ` [PATCH V7 05/16] rust: Add cpumask helpers Viresh Kumar
2025-01-13 11:23 ` [PATCH V7 06/16] rust: Add bindings for cpumask Viresh Kumar
2025-01-22 14:40 ` Miguel Ojeda
2025-01-23 3:43 ` Viresh Kumar
2025-01-13 11:23 ` [PATCH V7 07/16] rust: Add bare minimal bindings for clk framework Viresh Kumar
2025-01-13 11:23 ` [PATCH V7 08/16] rust: Add initial bindings for OPP framework Viresh Kumar
2025-01-13 11:23 ` [PATCH V7 09/16] rust: Extend OPP bindings for the OPP table Viresh Kumar
2025-01-13 11:23 ` [PATCH V7 10/16] rust: Extend OPP bindings for the configuration options Viresh Kumar
2025-01-13 11:23 ` [PATCH V7 11/16] rust: Add initial bindings for cpufreq framework Viresh Kumar
2025-01-13 11:23 ` [PATCH V7 12/16] rust: Extend cpufreq bindings for policy and driver ops Viresh Kumar
2025-01-13 11:23 ` [PATCH V7 13/16] rust: Extend cpufreq bindings for driver registration Viresh Kumar
2025-01-13 11:23 ` Viresh Kumar [this message]
2025-01-13 11:23 ` [PATCH V7 15/16] cpufreq: Add Rust based cpufreq-dt driver Viresh Kumar
2025-01-13 11:23 ` [PATCH V7 16/16] DO-NOT_MERGE: cpufreq: Rename cpufreq-dt platdev Viresh Kumar
2025-01-22 13:18 ` [PATCH] rust: macros: enable use of hyphens in module names Anisse Astier
2025-01-22 13:39 ` [PATCH v2] " Anisse Astier
2025-01-22 14:38 ` Viresh Kumar
2025-01-30 4:58 ` Viresh Kumar
2025-01-30 6:08 ` Anisse Astier
2025-01-30 11:51 ` Alice Ryhl
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=47cfb24fd3c7429dc68a023a6b504e37bb13c141.1736766672.git.viresh.kumar@linaro.org \
--to=viresh.kumar@linaro.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=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=nm@ti.com \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sboyd@kernel.org \
--cc=tmgross@umich.edu \
--cc=vincent.guittot@linaro.org \
--cc=vireshk@kernel.org \
/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