diff options
author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2025-05-21 23:49:34 +0300 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2025-05-21 23:49:34 +0300 |
commit | 0c905cadf38b49d53deee25819f0eaa46091c83a (patch) | |
tree | 8871f62899430825973d393e070912a4719c4e14 /rust/kernel/platform.rs | |
parent | 922607a2b462b813c4b461feca04aed0c97d4cfe (diff) | |
parent | 6c9bb86922728c7a4cceb99f131e00dd87514f20 (diff) | |
download | linux-0c905cadf38b49d53deee25819f0eaa46091c83a.tar.xz |
Merge tag 'cpufreq-arm-updates-6.16' of git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/pm
Merge ARM CPUFreq updates for 6.16 from Viresh Kumar:
"- Rust abstractions for CPUFreq framework (Viresh Kumar).
- Rust abstractions for OPP framework (Viresh Kumar).
- Basic Rust abstractions for Clk and Cpumask frameworks (Viresh Kumar).
- Minor cleanup to the SCMI cpufreq driver (Mike Tipton)."
* tag 'cpufreq-arm-updates-6.16' of git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/pm: (24 commits)
cpufreq: scmi: Skip SCMI devices that aren't used by the CPUs
cpufreq: Add Rust-based cpufreq-dt driver
rust: opp: Extend OPP abstractions with cpufreq support
rust: cpufreq: Extend abstractions for driver registration
rust: cpufreq: Extend abstractions for policy and driver ops
rust: cpufreq: Add initial abstractions for cpufreq framework
rust: opp: Add abstractions for the configuration options
rust: opp: Add abstractions for the OPP table
rust: opp: Add initial abstractions for OPP framework
rust: cpu: Add from_cpu()
rust: macros: enable use of hyphens in module names
rust: clk: Add initial abstractions
rust: clk: Add helpers for Rust code
MAINTAINERS: Add entry for Rust cpumask API
rust: cpumask: Add initial abstractions
rust: cpumask: Add few more helpers
rust: devres: require a bound device
rust: pci: move iomap_region() to impl Device<Bound>
rust: device: implement Bound device context
rust: pci: preserve device context in AsRef
...
Diffstat (limited to 'rust/kernel/platform.rs')
-rw-r--r-- | rust/kernel/platform.rs | 32 |
1 files changed, 8 insertions, 24 deletions
diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs index 4917cb34e2fe..b1c48cd95cd6 100644 --- a/rust/kernel/platform.rs +++ b/rust/kernel/platform.rs @@ -10,13 +10,12 @@ use crate::{ of, prelude::*, str::CStr, - types::{ARef, ForeignOwnable, Opaque}, + types::{ForeignOwnable, Opaque}, ThisModule, }; use core::{ marker::PhantomData, - ops::Deref, ptr::{addr_of_mut, NonNull}, }; @@ -184,31 +183,16 @@ pub struct Device<Ctx: device::DeviceContext = device::Normal>( PhantomData<Ctx>, ); -impl Device { +impl<Ctx: device::DeviceContext> Device<Ctx> { fn as_raw(&self) -> *mut bindings::platform_device { self.0.get() } } -impl Deref for Device<device::Core> { - type Target = Device; - - fn deref(&self) -> &Self::Target { - let ptr: *const Self = self; - - // CAST: `Device<Ctx>` is a transparent wrapper of `Opaque<bindings::platform_device>`. - let ptr = ptr.cast::<Device>(); - - // SAFETY: `ptr` was derived from `&self`. - unsafe { &*ptr } - } -} - -impl From<&Device<device::Core>> for ARef<Device> { - fn from(dev: &Device<device::Core>) -> Self { - (&**dev).into() - } -} +// SAFETY: `Device` is a transparent wrapper of a type that doesn't depend on `Device`'s generic +// argument. +kernel::impl_device_context_deref!(unsafe { Device }); +kernel::impl_device_context_into_aref!(Device); // SAFETY: Instances of `Device` are always reference-counted. unsafe impl crate::types::AlwaysRefCounted for Device { @@ -223,8 +207,8 @@ unsafe impl crate::types::AlwaysRefCounted for Device { } } -impl AsRef<device::Device> for Device { - fn as_ref(&self) -> &device::Device { +impl<Ctx: device::DeviceContext> AsRef<device::Device<Ctx>> for Device<Ctx> { + fn as_ref(&self) -> &device::Device<Ctx> { // SAFETY: By the type invariant of `Self`, `self.as_raw()` is a pointer to a valid // `struct platform_device`. let dev = unsafe { addr_of_mut!((*self.as_raw()).dev) }; |