Message ID | cover.1745218975.git.viresh.kumar@linaro.org |
---|---|
Headers | show |
Series | Rust abstractions for clk, cpumask, cpufreq, OPP | expand |
On 4/21/25 9:22 AM, Viresh Kumar wrote: > Extend the cpufreq abstractions to support driver registration from > Rust. > > Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> > --- > rust/kernel/cpufreq.rs | 490 ++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 488 insertions(+), 2 deletions(-) > > diff --git a/rust/kernel/cpufreq.rs b/rust/kernel/cpufreq.rs > index 5e0bfd03fd30..8628f0bada02 100644 > --- a/rust/kernel/cpufreq.rs > +++ b/rust/kernel/cpufreq.rs <snip> > + /// Registers a CPU frequency driver with the cpufreq core. > + pub fn new() -> Result<Self> { > + // We can't use `&Self::VTABLE` directly because the cpufreq core modifies some fields in > + // the C `struct cpufreq_driver`, which requires a mutable reference. > + let mut drv = KBox::new(UnsafeCell::new(Self::VTABLE), GFP_KERNEL)?; Maybe add a comment that it would be desired to make a struct cpufreq_driver capable of being declared as static const in the future. Either way, Reviewed-by: Danilo Krummrich <dakr@kernel.org>
On 4/21/25 9:22 AM, Viresh Kumar wrote: > > + /// Same as [`Registration::new`], but does not return a [`Registration`] instance. > + /// > + /// Instead the [`Registration`] is owned by [`Devres`] and will be revoked / dropped, once the > + /// device is detached. > + pub fn new_foreign_owned(dev: &Device) -> Result<()> { > + Devres::new_foreign_owned(dev, Self::new()?, GFP_KERNEL) > + } Btw. if you take it for v6.16-rc1, expect a conflict with [1]. [1] https://web.git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git/commit/?h=driver-core-next&id=f720efda2db5e609b32100c25d9cf383f082d945
On 23-04-25, 14:05, Danilo Krummrich wrote: > On 4/21/25 9:22 AM, Viresh Kumar wrote: > > + /// Registers a CPU frequency driver with the cpufreq core. > > + pub fn new() -> Result<Self> { > > + // We can't use `&Self::VTABLE` directly because the cpufreq core modifies some fields in > > + // the C `struct cpufreq_driver`, which requires a mutable reference. > > + let mut drv = KBox::new(UnsafeCell::new(Self::VTABLE), GFP_KERNEL)?; > > Maybe add a comment that it would be desired to make a struct cpufreq_driver > capable of being declared as static const in the future. Is it really the case ? I am not sure if that's how the C code sees these structures. Most of the driver structures (platform, etc) contain `struct device_driver`, which is mostly modified from the bus layer when the driver is registered, and so it can't be a `const`. Apart from that too, the drivers many sometimes carry flags. File operations (with just callbacks) can be `const` though. > Either way, > > Reviewed-by: Danilo Krummrich <dakr@kernel.org> Thanks a lot Danilo.
On 23-04-25, 14:08, Danilo Krummrich wrote: > On 4/21/25 9:22 AM, Viresh Kumar wrote: > > > > + /// Same as [`Registration::new`], but does not return a [`Registration`] instance. > > + /// > > + /// Instead the [`Registration`] is owned by [`Devres`] and will be revoked / dropped, once the > > + /// device is detached. > > + pub fn new_foreign_owned(dev: &Device) -> Result<()> { > > + Devres::new_foreign_owned(dev, Self::new()?, GFP_KERNEL) > > + } > > Btw. if you take it for v6.16-rc1, expect a conflict with [1]. > > [1] https://web.git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git/commit/?h=driver-core-next&id=f720efda2db5e609b32100c25d9cf383f082d945 Thanks for pointing this out. I believe this branch is immutable and so I can rebase over f720efda and send my pull request after yours is merged ?