pub struct Data<T, U, V> { /* private fields */ }
Expand description
Device data.
When a device is removed (for whatever reason, for example, because the device was unplugged or because the user decided to unbind the driver), the driver is given a chance to clean its state up, and all io resources should ideally not be used anymore.
However, the device data is reference-counted because other subsystems hold pointers to it. So some device state must be freed and not used anymore, while others must remain accessible.
This struct separates the device data into three categories:
- Registrations: are destroyed when the device is removed, but before the io resources become inaccessible.
- Io resources: are available until the device is removed.
- General data: remain available as long as the ref count is nonzero.
This struct implements the DeviceRemoval
trait so that it can clean resources up even if not
explicitly called by the device drivers.
Implementations
sourceimpl<T, U, V> Data<T, U, V>
impl<T, U, V> Data<T, U, V>
sourcepub fn try_new(
registrations: T,
resources: U,
general: V,
name: &'static CStr,
key1: &'static LockClassKey,
key2: &'static LockClassKey
) -> Result<Pin<UniqueArc<Self>>>
pub fn try_new(
registrations: T,
resources: U,
general: V,
name: &'static CStr,
key1: &'static LockClassKey,
key2: &'static LockClassKey
) -> Result<Pin<UniqueArc<Self>>>
Creates a new instance of Data
.
It is recommended that the [new_device_data
] macro be used as it automatically creates
the lock classes.
sourcepub fn resources(&self) -> Option<RevocableGuard<'_, U>>
pub fn resources(&self) -> Option<RevocableGuard<'_, U>>
Returns the resources if they’re still available.
sourcepub fn registrations(&self) -> Option<RevocableMutexGuard<'_, T>>
pub fn registrations(&self) -> Option<RevocableMutexGuard<'_, T>>
Returns the locked registrations if they’re still available.