Re: [PATCH v2 00/10] Device / Driver and PCI Rust abstractions

From: Viresh Kumar
Date: Wed Jun 19 2024 - 08:04:21 EST


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.

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.

Maybe I am making an mistake and missing the obvious.

Thanks.

--
viresh

[1] https://lore.kernel.org/all/cover.1717750631.git.viresh.kumar@xxxxxxxxxx/