On Wed, Jun 19, 2024 at 05:34:07PM +0530, Viresh Kumar wrote: > On 19-06-24, 01:39, Danilo Krummrich wrote: > > - move base device ID abstractions to a separate source file (Greg) > > - remove `DeviceRemoval` trait in favor of using a `Devres` callback to > > unregister drivers > > - remove `device::Data`, we don't need this abstraction anymore now that we > > `Devres` to revoke resources and registrations > > Hi Danilo, > > I am working on writing bindings for CPUFreq drivers [1] and was > looking to rebase over staging/rust-device, and I am not sure how to > proceed after device::Data is dropped now. > > What I was doing at probe() was something like this: > > fn probe(dev: &mut platform::Device, id_info: Option<&Self::IdInfo>) -> Result<Self::Data> { > let data = Arc::<DeviceData>::from(kernel::new_device_data!( > cpufreq::Registration::new(), > (), > "CPUFreqDT::Registration" > )?); > > ... > > // Need a mutable object to be passed to register() here. > data.registrations() > .ok_or(ENXIO)? > .as_pinned_mut() > .register(c_str!("cpufreq-dt"), ...)?; > > Ok(data) > } > > The register() function of cpufreq core needs a mutable pointer to > `self` and it worked earlier as Data used a RevocableMutex. But with > Devres, we don't have a Mutex anymore and devres.try_access() doesn't > give a mutable object. If you want to split `cpufreq::Registration` in `new()` and `register()`, you probably want to pass the registration object to `Devres` in `register()` instead. However, I wouldn't recommend splitting it up (unless you absolutely have to), it's way cleaner (and probably less racy) if things are registered once the registration is created. > > I am a bit confused on how to get this going. I looked at how PCI bus > is implemented in the staging/dev but I couldn't find an end driver > using this work. The PCI abstraction did not need to change for that, since it uses the generalized `driver::Registration`, which is handled by the `Module` structure instead. However, staging/dev also contains the `drm::drv::Registration` type [1], which in principle does the same thing as `cpufreq::Registration` just for a DRM device. If you're looking for an example driver making use of this, please have a look at Nova [1]. [1] https://github.com/Rust-for-Linux/linux/blob/staging/dev/rust/kernel/drm/drv.rs [2] https://gitlab.freedesktop.org/drm/nova/-/blob/nova-next/drivers/gpu/drm/nova/driver.rs > > Maybe I am making an mistake and missing the obvious. > > Thanks. > > -- > viresh > > [1] https://lore.kernel.org/all/cover.1717750631.git.viresh.kumar@xxxxxxxxxx/ >