pub struct Device(/* private fields */);Expand description
A reference-counted device.
This structure represents the Rust abstraction for a C struct device. This implementation
abstracts the usage of an already existing C struct device within Rust code that we get
passed from the C side.
An instance of this abstraction can be obtained temporarily or permanent.
A temporary one is bound to the lifetime of the C struct device pointer used for creation.
A permanent instance is always reference-counted and hence not restricted by any lifetime
boundaries.
For subsystems it is recommended to create a permanent instance to wrap into a subsystem
specific device structure (e.g. pci::Device). This is useful for passing it to drivers in
T::probe(), such that a driver can store the ARef<Device> (equivalent to storing a
struct device pointer in a C driver) for arbitrary purposes, e.g. allocating DMA coherent
memory.
§Invariants
A Device instance represents a valid struct device created by the C portion of the kernel.
Instances of this type are always reference-counted, that is, a call to get_device ensures
that the allocation remains valid at least until the matching call to put_device.
bindings::device::release is valid to be called from any thread, hence ARef<Device> can be
dropped from any thread.
Implementations§
Source§impl Device
impl Device
Sourcepub unsafe fn get_device(ptr: *mut device) -> ARef<Self>
pub unsafe fn get_device(ptr: *mut device) -> ARef<Self>
Creates a new reference-counted abstraction instance of an existing struct device pointer.
§Safety
Callers must ensure that ptr is valid, non-null, and has a non-zero reference count,
i.e. it must be ensured that the reference count of the C struct device ptr points to
can’t drop to zero, for the duration of this function call.
It must also be ensured that bindings::device::release can be called from any thread.
While not officially documented, this should be the case for any struct device.
Sourcepub unsafe fn as_ref<'a>(ptr: *mut device) -> &'a Self
pub unsafe fn as_ref<'a>(ptr: *mut device) -> &'a Self
Convert a raw C struct device pointer to a &'a Device.
§Safety
Callers must ensure that ptr is valid, non-null, and has a non-zero reference count,
i.e. it must be ensured that the reference count of the C struct device ptr points to
can’t drop to zero, for the duration of this function call and the entire duration when the
returned reference exists.
Sourcepub fn pr_emerg(&self, args: Arguments<'_>)
pub fn pr_emerg(&self, args: Arguments<'_>)
Prints an emergency-level message (level 0) prefixed with device information.
More details are available from dev_emerg.
Sourcepub fn pr_alert(&self, args: Arguments<'_>)
pub fn pr_alert(&self, args: Arguments<'_>)
Prints an alert-level message (level 1) prefixed with device information.
More details are available from dev_alert.
Sourcepub fn pr_crit(&self, args: Arguments<'_>)
pub fn pr_crit(&self, args: Arguments<'_>)
Prints a critical-level message (level 2) prefixed with device information.
More details are available from dev_crit.
Sourcepub fn pr_err(&self, args: Arguments<'_>)
pub fn pr_err(&self, args: Arguments<'_>)
Prints an error-level message (level 3) prefixed with device information.
More details are available from dev_err.
Sourcepub fn pr_warn(&self, args: Arguments<'_>)
pub fn pr_warn(&self, args: Arguments<'_>)
Prints a warning-level message (level 4) prefixed with device information.
More details are available from dev_warn.
Sourcepub fn pr_notice(&self, args: Arguments<'_>)
pub fn pr_notice(&self, args: Arguments<'_>)
Prints a notice-level message (level 5) prefixed with device information.
More details are available from dev_notice.
Sourcepub fn pr_info(&self, args: Arguments<'_>)
pub fn pr_info(&self, args: Arguments<'_>)
Prints an info-level message (level 6) prefixed with device information.
More details are available from dev_info.
Sourcepub fn pr_dbg(&self, args: Arguments<'_>)
pub fn pr_dbg(&self, args: Arguments<'_>)
Prints a debug-level message (level 7) prefixed with device information.
More details are available from dev_dbg.
Sourcepub fn property_present(&self, name: &CStr) -> bool
pub fn property_present(&self, name: &CStr) -> bool
Checks if property is present or not.