Device drivers infrastructure
The Basic Device Driver-Model Structures #
struct subsys_interface #
interfaces to device functions
Definition
;
Members
name: name of the device functionsubsys: subsystem of the devices to attach tonode: the list of functions registered at the subsystemadd_dev: device hookup to device function handlerremove_dev: device hookup to device function handler
Description
Simple interfaces attached to a subsystem. Multiple interfaces can attach to a subsystem and its devices. Unlike drivers, they do not exclusively claim or control devices. Interfaces usually represent a specific functionality of a subsystem/class of devices.
struct device_attribute #
Interface for exporting device attributes.
Definition
;
Members
attr: sysfs attribute definition.show: Show handler.store: Store handler.
struct dev_ext_attribute #
Exported device attribute with extra context.
Definition
;
Members
attr: Exported device attribute.var: Pointer to context.
DEVICE_ATTR() #
Define a device attribute.
Parameters
_name: Attribute name._mode: File mode._show: Show handler. Optional, but mandatory if attribute is readable._store: Store handler. Optional, but mandatory if attribute is writable.
Description
Convenience macro for defining a struct device_attribute.
For example, DEVICE_ATTR(foo, 0644, foo_show, foo_store); expands to:
struct device_attribute dev_attr_foo = ;
DEVICE_ATTR_PREALLOC() #
Define a preallocated device attribute.
Parameters
_name: Attribute name._mode: File mode._show: Show handler. Optional, but mandatory if attribute is readable._store: Store handler. Optional, but mandatory if attribute is writable.
Description
Like DEVICE_ATTR(), but SYSFS_PREALLOC is set on _mode.
DEVICE_ATTR_RW() #
Define a read-write device attribute.
Parameters
_name: Attribute name.
Description
Like DEVICE_ATTR(), but _mode is 0644, _show is <_name>_show,
and _store is <_name>_store.
DEVICE_ATTR_ADMIN_RW() #
Define an admin-only read-write device attribute.
Parameters
_name: Attribute name.
Description
Like DEVICE_ATTR_RW(), but _mode is 0600.
DEVICE_ATTR_RO() #
Define a readable device attribute.
Parameters
_name: Attribute name.
Description
Like DEVICE_ATTR(), but _mode is 0444 and _show is <_name>_show.
DEVICE_ATTR_ADMIN_RO() #
Define an admin-only readable device attribute.
Parameters
_name: Attribute name.
Description
Like DEVICE_ATTR_RO(), but _mode is 0400.
DEVICE_ATTR_WO() #
Define an admin-only writable device attribute.
Parameters
_name: Attribute name.
Description
Like DEVICE_ATTR(), but _mode is 0200 and _store is <_name>_store.
DEVICE_ULONG_ATTR() #
Define a device attribute backed by an unsigned long.
Parameters
_name: Attribute name._mode: File mode._var: Identifier of unsigned long.
Description
Like DEVICE_ATTR(), but _show and _store are automatically provided
such that reads and writes to the attribute from userspace affect _var.
DEVICE_INT_ATTR() #
Define a device attribute backed by an int.
Parameters
_name: Attribute name._mode: File mode._var: Identifier of int.
Description
Like DEVICE_ULONG_ATTR(), but _var is an int.
DEVICE_BOOL_ATTR() #
Define a device attribute backed by a bool.
Parameters
_name: Attribute name._mode: File mode._var: Identifier of bool.
Description
Like DEVICE_ULONG_ATTR(), but _var is a bool.
DEVICE_STRING_ATTR_RO() #
Define a device attribute backed by a r/o string.
Parameters
_name: Attribute name._mode: File mode._var: Identifier of string.
Description
Like DEVICE_ULONG_ATTR(), but _var is a string. Because the length of the
string allocation is unknown, the attribute must be read-only.
enum dl_dev_state #
Device driver presence tracking information.
Constants
DL_DEV_NO_DRIVER: There is no driver attached to the device.DL_DEV_PROBING: A driver is probing.DL_DEV_DRIVER_BOUND: The driver has been bound to the device.DL_DEV_UNBINDING: The driver is unbinding from the device.
enum device_removable #
Whether the device is removable. The criteria for a device to be classified as removable is determined by its subsystem or bus.
Constants
DEVICE_REMOVABLE_NOT_SUPPORTED: This attribute is not supported for this device (default).DEVICE_REMOVABLE_UNKNOWN: Device location is Unknown.DEVICE_FIXED: Device is not removable by the user.DEVICE_REMOVABLE: Device is removable by the user.
struct dev_links_info #
Device data related to device links.
Definition
;
Members
suppliers: List of links to supplier devices.consumers: List of links to consumer devices.defer_sync: Hook to global list of devices that have deferred sync_state.status: Driver status information.
struct dev_msi_info #
Device data related to MSI
Definition
;
Members
domain: The MSI interrupt domain associated to the devicedata: Pointer to MSI device data
enum device_physical_location_panel #
Describes which panel surface of the system's housing the device connection point resides on.
Constants
DEVICE_PANEL_TOP: Device connection point is on the top panel.DEVICE_PANEL_BOTTOM: Device connection point is on the bottom panel.DEVICE_PANEL_LEFT: Device connection point is on the left panel.DEVICE_PANEL_RIGHT: Device connection point is on the right panel.DEVICE_PANEL_FRONT: Device connection point is on the front panel.DEVICE_PANEL_BACK: Device connection point is on the back panel.DEVICE_PANEL_UNKNOWN: The panel with device connection point is unknown.
enum device_physical_location_vertical_position #
Describes vertical position of the device connection point on the panel surface.
Constants
DEVICE_VERT_POS_UPPER: Device connection point is at upper part of panel.DEVICE_VERT_POS_CENTER: Device connection point is at center part of panel.DEVICE_VERT_POS_LOWER: Device connection point is at lower part of panel.
enum device_physical_location_horizontal_position #
Describes horizontal position of the device connection point on the panel surface.
Constants
DEVICE_HORI_POS_LEFT: Device connection point is at left part of panel.DEVICE_HORI_POS_CENTER: Device connection point is at center part of panel.DEVICE_HORI_POS_RIGHT: Device connection point is at right part of panel.
struct device_physical_location #
Device data related to physical location of the device connection point.
Definition
;
Members
panel: Panel surface of the system's housing that the device connection point resides on.vertical_position: Vertical position of the device connection point within the panel.horizontal_position: Horizontal position of the device connection point within the panel.dock: Set if the device connection point resides in a docking station or port replicator.lid: Set if this device connection point resides on the lid of laptop system.
enum struct_device_flags #
Flags in struct device
Constants
DEV_FLAG_READY_TO_PROBE: If set thendevice_add()has finished enough initialization that probe could be called.DEV_FLAG_COUNT: Number of defined struct_device_flags.
Description
Each flag should have a set of accessor functions created via
__create_dev_flag_accessors() for each access.
struct device #
The basic device structure
Definition
;
Members
kobj: A top-level, abstract class from which other classes are derived.parent: The device's "parent" device, the device to which it is attached. In most cases, a parent device is some sort of bus or host controller. If parent is NULL, the device, is a top-level device, which is not usually what you want.p: Holds the private data of the driver core portions of the device. See the comment of the struct device_private for detail.init_name: Initial name of the device.type: The type of device. This identifies the device type and carries type-specific information.bus: Type of bus device is on.driver: Which driver has allocated thisplatform_data: Platform data specific to the device.driver_data: Private pointer for driver specific info.driver_override: Driver name to force a match. Do not touch directly; usedevice_set_driver_override()instead.mutex: Mutex to synchronize calls to its driver.links: Links to suppliers and consumers of this device.power: For device power management. See Documentation/driver-api/pm/devices.rst for details.pm_domain: Provide callbacks that are executed during system suspend, hibernation, system resume and during runtime PM transitions along with subsystem-level and driver-level callbacks.em_pd: device's energy model performance domainpins: For device pin management. See Documentation/driver-api/pin-control.rst for details.msi: MSI related datadma_ops: DMA mapping operations for this device.dma_mask: Dma mask (if dma'ble device).coherent_dma_mask: Like dma_mask, but for alloc_coherent mapping as not all hardware supports 64-bit addresses for consistent allocations such descriptors.bus_dma_limit: Limit of an upstream bridge or bus which imposes a smaller DMA limit than the device itself supports.dma_range_map: map for DMA memory ranges relative to that of RAMdma_parms: A low level driver may set these to teach IOMMU code about segment limitations.dma_pools: Dma pools (if dma'ble device).dma_mem: Internal for coherent mem override.cma_area: Contiguous memory area for dma allocationsdma_io_tlb_mem: Software IO TLB allocator. Not for driver use.dma_io_tlb_pools: List of transient swiotlb memory pools.dma_io_tlb_lock: Protects changes to the list of active pools.dma_uses_io_tlb:trueif device has used the software IO TLB.archdata: For arch-specific additions.of_node: Associated device tree node.fwnode: Associated device node supplied by platform firmware.numa_node: NUMA node this device is close to.devt: For creating the sysfs "dev".id: device instancedevres_lock: Spinlock to protect the resource of the device.devres_head: The resources list of the device.class: The class of the device.groups: Optional attribute groups.release: Callback to free the device after all references have gone away. This should be set by the allocator of the device (i.e. the bus driver that discovered the device).iommu_group: IOMMU group the device belongs to.iommu: Per device generic IOMMU runtime dataphysical_location: Describes physical location of the device connection point in the system housing.removable: Whether the device can be removed from the system. This should be set by the subsystem / bus driver that discovered the device.offline_disabled: If set, the device is permanently online.offline: Set after successful invocation of bus type's .offline().of_node_reused: Set if the device-tree node is shared with an ancestor device.state_synced: The hardware state of this device has been synced to match the software state of this device by calling the driver/bussync_state()callback.can_match: The device has matched with a driver at least once or it is in a bus (like AMBA) which can't check for matching drivers until other devices probe successfully.dma_coherent: this particular device is dma coherent, even if the architecture supports non-coherent devices.dma_ops_bypass: If set totruethen the dma_ops are bypassed for the streaming DMA operations (->map_* / ->unmap_* / ->sync_*), and optionall (if the coherent mask is large enough) also for dma allocations. This flag is managed by the dma ops instance from ->dma_supported.dma_skip_sync: DMA sync operations can be skipped for coherent buffers.dma_iommu: Device is using default IOMMU implementation for DMA and doesn't rely on dma_ops structure.flags: DEV_FLAG_XXX flags. Use atomic bitfield operations to modify.
Example
-
For devices on custom boards, as typical of embedded
and SOC based hardware, Linux often uses platform_data to point to board-specific structures describing devices and how they are wired. That can include what ports are available, chip variants, which GPIO pins act in what additional roles, and so on. This shrinks the "Board Support Packages" (BSPs) and minimizes board-specific #ifdefs in drivers.
Description
At the lowest level, every device in a Linux system is represented by an instance of struct device. The device structure contains the information that the device model core needs to model the system. Most subsystems, however, track additional information about the devices they host. As a result, it is rare for devices to be represented by bare device structures; instead, that structure, like kobject structures, is usually embedded within a higher-level representation of the device.
struct device_link #
Device link representation.
Definition
;
Members
supplier: The device on the supplier end of the link.s_node: Hook to the supplier device's list of links to consumers.consumer: The device on the consumer end of the link.c_node: Hook to the consumer device's list of links to suppliers.link_dev: device used to expose link details in sysfsstatus: The state of the link (with respect to the presence of drivers).flags: Link flags.rpm_active: Whether or not the consumer device is runtime-PM-active.kref: Count repeated addition of the same link.rm_work: Work structure used for removing the link.supplier_preactivated: Supplier has been made active before consumer probe.
device_set_driver_override() #
int Helper to set or clear driver override.
Parameters
struct device *dev: Device to changeconst char *s: NUL-terminated string, new driver name to force a match, pass empty string to clear it ("" or "\n", where the latter is only for sysfs interface).
Description
Helper to set or clear driver override of a device.
Return
0 on success or a negative error code on failure.
device_has_driver_override() #
bool Check if a driver override has been set.
Parameters
struct device *dev: device to check
Description
Returns true if a driver override has been set for this device.
device_match_driver_override() #
int Match a driver against the device's driver_override.
Parameters
struct device *dev: device to checkconst struct device_driver *drv: driver to match against
Description
Returns > 0 if a driver override is set and matches the given driver, 0 if a driver override is set but does not match, or < 0 if a driver override is not set at all.
device_iommu_mapped() #
bool Returns true when the device DMA is translated by an IOMMU
Parameters
struct device *dev: Device to perform the check on
dev_name() #
const char * Return a device's name.
Parameters
const struct device *dev: Device with name to get.
Return
The kobject name of the device, or its initial name if unavailable.
dev_bus_name() #
const char * Return a device's bus/class name, if at all possible
Parameters
const struct device *dev: struct device to get the bus/class name of
Description
Will return the name of the bus/class the device is attached to. If it is not attached to a bus/class, an empty string will be returned.
device_find_child_by_name() #
struct device * device iterator for locating a child device.
Parameters
struct device *parent: parent struct deviceconst char *name: name of the child device
Description
This is similar to the device_find_child() function above, but it
returns a reference to a device that has the name name.
NOTE
you will need to drop the reference with put_device() after use.
device_find_any_child() #
struct device * device iterator for locating a child device, if any.
Parameters
struct device *parent: parent struct device
Description
This is similar to the device_find_child() function above, but it
returns a reference to a child device, if any.
NOTE
you will need to drop the reference with put_device() after use.
device_lock_set_class() #
Specify a temporary lock class while a device is attached to a driver
Parameters
dev: device to modifykey: lock class key data
Description
This must be called with the device_lock() already held, for example
from driver ->probe(). Take care to only override the default
lockdep_no_validate class.
device_lock_reset_class() #
Return a device to the default lockdep novalidate state
Parameters
dev: device to modify
Description
This must be called with the device_lock() already held, for example
from driver ->remove().
struct bus_type #
The bus type of the device
Definition
;
Members
name: The name of the bus.dev_name: Used for subsystems to enumerate devices like ("foou", dev->id).bus_groups: Default attributes of the bus.dev_groups: Default attributes of the devices on the bus.drv_groups: Default attributes of the device drivers on the bus.match: Called, perhaps multiple times, whenever a new device or driver is added for this bus. It should return a positive value if the given device can be handled by the given driver and zero otherwise. It may also return error code if determining that the driver supports the device is not possible. In case of -EPROBE_DEFER it will queue the device for deferred probing.uevent: Called when a device is added, removed, or a few other things that generate uevents to add the environment variables.probe: Called when a new device or driver add to this bus, and callback the specific driver's probe to initial the matched device.sync_state: Called to sync device state to software state after all the state tracking consumers linked to this device (present at the time of late_initcall) have successfully bound to a driver. If the device has no consumers, this function will be called at late_initcall_sync level. If the device has consumers that are never bound to a driver, this function will never get called until they do.remove: Called when a device removed from this bus.shutdown: Called at shut-down time to quiesce the device.irq_get_affinity: Get IRQ affinity mask for the device on this bus.online: Called to put the device back online (after offlining it).offline: Called to put the device offline for hot-removal. May fail.suspend: Called when a device on this bus wants to go to sleep mode.resume: Called to bring a device on this bus out of sleep mode.num_vf: Called to find out how many virtual functions a device on this bus supports.dma_configure: Called to setup DMA configuration on a device on this bus.dma_cleanup: Called to cleanup DMA configuration on a device on this bus.pm: Power management operations of this bus, callback the specific device driver's pm-ops.driver_override: Set to true if this bus supports the driver_override mechanism, which allows userspace to force a specific driver to bind to a device via a sysfs attribute.need_parent_lock: When probing or removing a device on this bus, the device core should lock the device's parent.
Note
-
This callback may be invoked with or without the device
lock held.
Description
A bus is a channel between the processor and one or more devices. For the purposes of the device model, all devices are connected via a bus, even if it is an internal, virtual, "platform" bus. Buses can plug into each other. A USB controller is usually a PCI device, for example. The device model represents the actual connections between buses and the devices they control. A bus is represented by the bus_type structure. It contains the name, the default attributes, the bus' methods, PM operations, and the driver core's private data.
enum bus_notifier_event #
Bus Notifier events that have happened
Constants
BUS_NOTIFY_ADD_DEVICE: device is added to this busBUS_NOTIFY_DEL_DEVICE: device is about to be removed from this busBUS_NOTIFY_REMOVED_DEVICE: device is successfully removed from this busBUS_NOTIFY_BIND_DRIVER: a driver is about to be bound to this device on this busBUS_NOTIFY_BOUND_DRIVER: a driver is successfully bound to this device on this busBUS_NOTIFY_UNBIND_DRIVER: a driver is about to be unbound from this device on this busBUS_NOTIFY_UNBOUND_DRIVER: a driver is successfully unbound from this device on this busBUS_NOTIFY_DRIVER_NOT_BOUND: a driver failed to be bound to this device on this bus
Description
These are the value passed to a bus notifier when a specific event happens.
Note that bus notifiers are likely to be called with the device lock already held by the driver core, so be careful in any notifier callback as to what you do with the device structure.
All bus notifiers are called with the target struct device * as an argument.
struct class #
device classes
Definition
;
Members
name: Name of the class.class_groups: Default attributes of this class.dev_groups: Default attributes of the devices that belong to the class.dev_uevent: Called when a device is added, removed from this class, or a few other things that generate uevents to add the environment variables.devnode: Callback to provide the devtmpfs.class_release: Called to release this class.dev_release: Called to release the device.shutdown_pre: Called at shut-down time before driver shutdown.ns_type: Callbacks so sysfs can detemine namespaces.namespace: Namespace of the device belongs to this class.get_ownership: Allows class to specify uid/gid of the sysfs directories for the devices belonging to the class. Usually tied to device's namespace.pm: The default device power management operations of this class.
Description
A class is a higher-level view of a device that abstracts out low-level implementation details. Drivers may see a SCSI disk or an ATA disk, but, at the class level, they are all simply disks. Classes allow user space to work with devices based on what they do, rather than how they are connected or how they work.
enum probe_type #
device driver probe type to try Device drivers may opt in for special handling of their respective probe routines. This tells the core what to expect and prefer.
Constants
PROBE_DEFAULT_STRATEGY: Used by drivers that work equally well whether probed synchronously or asynchronously.PROBE_PREFER_ASYNCHRONOUS: Drivers for "slow" devices which probing order is not essential for booting the system may opt into executing their probes asynchronously.PROBE_FORCE_SYNCHRONOUS: Use this to annotate drivers that need their probe routines to run synchronously with driver and device registration (with the exception of -EPROBE_DEFER handling - re-probing always ends up being done asynchronously).
Description
Note that the end goal is to switch the kernel to use asynchronous
probing by default, so annotating drivers with
PROBE_PREFER_ASYNCHRONOUS is a temporary measure that allows us
to speed up boot process while we are validating the rest of the
drivers.
struct device_driver #
The basic device driver structure
Definition
;
Members
name: Name of the device driver.bus: The bus which the device of this driver belongs to.owner: The module owner.mod_name: Used for built-in modules.suppress_bind_attrs: Disables bind/unbind via sysfs.probe_type: Type of the probe (synchronous or asynchronous) to use.of_match_table: The open firmware table.acpi_match_table: The ACPI match table.probe: Called to query the existence of a specific device, whether this driver can work with it, and bind the driver to a specific device.sync_state: Called to sync device state to software state after all the state tracking consumers linked to this device (present at the time of late_initcall) have successfully bound to a driver. If the device has no consumers, this function will be called at late_initcall_sync level. If the device has consumers that are never bound to a driver, this function will never get called until they do.remove: Called when the device is removed from the system to unbind a device from this driver.shutdown: Called at shut-down time to quiesce the device.suspend: Called to put the device to sleep mode. Usually to a low power state.resume: Called to bring a device from sleep mode.groups: Default attributes that get created by the driver core automatically.dev_groups: Additional attributes attached to device instance once it is bound to the driver.pm: Power management operations of the device which matched this driver.coredump: Called when sysfs entry is written to. The device driver is expected to call the dev_coredump API resulting in a uevent.p: Driver core's private data, no one other than the driver core can touch this.p_cb: Callbacks private to the driver core; no one other than the driver core is allowed to touch this.
Description
The device driver-model tracks all of the drivers known to the system. The main reason for this tracking is to enable the driver core to match up drivers with new devices. Once drivers are known objects within the system, however, a number of other things become possible. Device drivers can export information and configuration variables that are independent of any specific device.
Device Drivers Base #
driver_init() #
void initialize driver model.
Parameters
void: no arguments
Description
Call the driver model init functions to initialize their subsystems. Called early from init/main.c.
driver_find_device_by_name() #
struct device * device iterator for locating a particular device of a specific name.
Parameters
const struct device_driver *drv: the driver we're iteratingconst char *name: name of the device to match
driver_find_device_by_of_node() #
struct device * device iterator for locating a particular device by of_node pointer.
Parameters
const struct device_driver *drv: the driver we're iteratingconst struct device_node *np: of_node pointer to match.
driver_find_device_by_fwnode() #
struct device * device iterator for locating a particular device by fwnode pointer.
Parameters
struct device_driver *drv: the driver we're iteratingconst struct fwnode_handle *fwnode: fwnode pointer to match.
driver_find_device_by_devt() #
struct device * device iterator for locating a particular device by devt.
Parameters
const struct device_driver *drv: the driver we're iteratingdev_t devt: devt pointer to match.
driver_find_device_by_acpi_dev() #
struct device * device iterator for locating a particular device matching the ACPI_COMPANION device.
Parameters
const struct device_driver *drv: the driver we're iteratingconst struct acpi_device *adev: ACPI_COMPANION device to match.
module_driver() #
Helper macro for drivers that don't do anything special in module init/exit. This eliminates a lot of boilerplate. Each module may only use this macro once, and calling it replaces module_init() and module_exit().
Parameters
__driver: driver name__register: register function for this driver type__unregister: unregister function for this driver type...: Additional arguments to be passed to __register and __unregister.
Description
Use this macro to construct bus specific macros for registering drivers, and do not use it on its own.
builtin_driver() #
Helper macro for drivers that don't do anything special in init and have no exit. This eliminates some boilerplate. Each driver may only use this macro once, and calling it replaces device_initcall (or in some cases, the legacy __initcall). This is meant to be a direct parallel of module_driver() above but without the __exit stuff that is not used for builtin cases.
Parameters
__driver: driver name__register: register function for this driver type...: Additional arguments to be passed to __register
Description
Use this macro to construct bus specific macros for registering drivers, and do not use it on its own.
driver_set_override() #
int Helper to set or clear driver override.
Parameters
struct device *dev: Device to changeconst char **override: Address of string to change (e.g.device->driver_override); The contents will be freed and hold newly allocated override.const char *s: NUL-terminated string, new driver name to force a match, pass empty string to clear it ("" or "\n", where the latter is only for sysfs interface).size_t len: length of s
Description
Helper to set or clear driver override in a device, intended for the cases when the driver_override field is allocated by driver/bus code.
Return
0 on success or a negative error code on failure.
driver_for_each_device() #
int Iterator for devices bound to a driver.
Parameters
struct device_driver *drv: Driver we're iterating.struct device *start: Device to begin withvoid *data: Data to pass to the callback.device_iter_t fn: Function to call for each device.
Description
Iterate over the drv's list of devices calling fn for each one.
driver_find_device() #
struct device * device iterator for locating a particular device.
Parameters
const struct device_driver *drv: The device's driverstruct device *start: Device to begin withconst void *data: Data to pass to match functiondevice_match_t match: Callback function to check device
Description
This is similar to the driver_for_each_device() function above, but
it returns a reference to a device that is 'found' for later use, as
determined by the match callback.
The callback should return 0 if the device doesn't match and non-zero if it does. If the callback returns non-zero, this function will return to the caller and not iterate over any more devices.
driver_create_file() #
int create sysfs file for driver.
Parameters
const struct device_driver *drv: driver.const struct driver_attribute *attr: driver attribute descriptor.
driver_remove_file() #
void remove sysfs file for driver.
Parameters
const struct device_driver *drv: driver.const struct driver_attribute *attr: driver attribute descriptor.
driver_register() #
int register driver with bus
Parameters
struct device_driver *drv: driver to register
Description
We pass off most of the work to the bus_add_driver() call,
since most of the things we have to do deal with the bus
structures.
driver_unregister() #
void remove driver from system.
Parameters
struct device_driver *drv: driver.
Description
Again, we pass off most of the work to the bus-level call.
device_link_wait_removal() #
void Wait for ongoing devlink removal jobs to terminate
Parameters
void: no arguments
device_link_add() #
struct device_link * Create a link between two devices.
Parameters
struct device *consumer: Consumer end of the link.struct device *supplier: Supplier end of the link.u32 flags: Link flags.
Return
On success, a device_link struct will be returned. On error or invalid flag settings, NULL will be returned.
Description
The caller is responsible for the proper synchronization of the link creation with runtime PM. First, setting the DL_FLAG_PM_RUNTIME flag will cause the runtime PM framework to take the link into account. Second, if the DL_FLAG_RPM_ACTIVE flag is set in addition to it, the supplier devices will be forced into the active meta state and reference-counted upon the creation of the link. If DL_FLAG_PM_RUNTIME is not set, DL_FLAG_RPM_ACTIVE will be ignored.
If DL_FLAG_STATELESS is set in flags, the caller of this function is
expected to release the link returned by it directly with the help of either
device_link_del() or device_link_remove().
If that flag is not set, however, the caller of this function is handing the management of the link over to the driver core entirely and its return value can only be used to check whether or not the link is present. In that case, the DL_FLAG_AUTOREMOVE_CONSUMER and DL_FLAG_AUTOREMOVE_SUPPLIER device link flags can be used to indicate to the driver core when the link can be safely deleted. Namely, setting one of them in flags indicates to the driver core that the link is not going to be used (by the given caller of this function) after unbinding the consumer or supplier driver, respectively, from its device, so the link can be deleted at that point. If none of them is set, the link will be maintained until one of the devices pointed to by it (either the consumer or the supplier) is unregistered.
Also, if DL_FLAG_STATELESS, DL_FLAG_AUTOREMOVE_CONSUMER and DL_FLAG_AUTOREMOVE_SUPPLIER are not set in flags (that is, a persistent managed device link is being added), the DL_FLAG_AUTOPROBE_CONSUMER flag can be used to request the driver core to automatically probe for a consumer driver after successfully binding a driver to the supplier device.
The combination of DL_FLAG_STATELESS and one of DL_FLAG_AUTOREMOVE_CONSUMER, DL_FLAG_AUTOREMOVE_SUPPLIER, or DL_FLAG_AUTOPROBE_CONSUMER set in flags at the same time is invalid and will cause NULL to be returned upfront. However, if a device link between the given consumer and supplier pair exists already when this function is called for them, the existing link will be returned regardless of its current type and status (the link's flags may be modified then). The caller of this function is then expected to treat the link as though it has just been created, so (in particular) if DL_FLAG_STATELESS was passed in flags, the link needs to be released explicitly when not needed any more (as stated above).
A side effect of the link creation is re-ordering of dpm_list and the devices_kset list by moving the consumer device and all devices depending on it to the ends of these lists (that does not happen to devices that have not been registered when this function is called).
The supplier device is required to be registered when this function is called and NULL will be returned if that is not the case. The consumer device need not be registered, however.
device_link_del() #
void Delete a stateless link between two devices.
Parameters
struct device_link *link: Device link to delete.
Description
The caller must ensure proper synchronization of this function with runtime
PM. If the link was added multiple times, it needs to be deleted as often.
Care is required for hotplugged devices: Their links are purged on removal
and calling device_link_del() is then no longer allowed.
device_link_remove() #
void Delete a stateless link between two devices.
Parameters
void *consumer: Consumer end of the link.struct device *supplier: Supplier end of the link.
Description
The caller must ensure proper synchronization of this function with runtime PM.
dev_driver_string() #
const char * Return a device's driver name, if at all possible
Parameters
const struct device *dev: struct device to get the name of
Description
Will return the device's driver's name if it is bound to a device. If the device is not bound to a driver, it will return the name of the bus it is attached to. If it is not attached to a bus either, an empty string will be returned.
devm_device_add_group() #
int given a device, create a managed attribute group
Parameters
struct device *dev: The device to create the group forconst struct attribute_group *grp: The attribute group to create
Description
This function creates a group for the first time. It will explicitly warn and error if any of the attribute files being created already exist.
Returns 0 on success or error code on failure.
device_create_file() #
int create sysfs attribute file for device.
Parameters
struct device *dev: device.const struct device_attribute *attr: device attribute descriptor.
device_remove_file() #
void remove sysfs attribute file.
Parameters
struct device *dev: device.const struct device_attribute *attr: device attribute descriptor.
device_remove_file_self() #
bool remove sysfs attribute file from its own method.
Parameters
struct device *dev: device.const struct device_attribute *attr: device attribute descriptor.
Description
See kernfs_remove_self() for details.
device_create_bin_file() #
int create sysfs binary attribute file for device.
Parameters
struct device *dev: device.const struct bin_attribute *attr: device binary attribute descriptor.
device_remove_bin_file() #
void remove sysfs binary attribute file
Parameters
struct device *dev: device.const struct bin_attribute *attr: device binary attribute descriptor.
device_initialize() #
void init device structure.
Parameters
struct device *dev: device.
Description
This prepares the device for use by other layers by initializing
its fields.
It is the first half of device_register(), if called by
that function, though it can also be called separately, so one
may use dev's fields. In particular, get_device()/put_device()
may be used for reference counting of dev after calling this
function.
All fields in dev must be initialized by the caller to 0, except
for those explicitly set to some other value. The simplest
approach is to use kzalloc() to allocate the structure containing
dev.
NOTE
Use put_device() to give up your reference instead of freeing
dev directly once you have called this function.
dev_set_name() #
int set a device name
Parameters
struct device *dev: deviceconst char *fmt: format string for the device's name...: variable arguments
device_add() #
int add device to device hierarchy.
Parameters
struct device *dev: device.
Description
This is part 2 of device_register(), though may be called
separately iff device_initialize() has been called separately.
This adds dev to the kobject hierarchy via kobject_add(), adds it
to the global and sibling lists for the device, then
adds it to the other relevant subsystems of the driver model.
Do not call this routine or device_register() more than once for
any device structure. The driver model core is not designed to work
with devices that get unregistered and then spring back to life.
(Among other things, it's very hard to guarantee that all references
to the previous incarnation of dev have been dropped.) Allocate
and register a fresh new struct device instead.
NOTE
Never directly free dev after calling this function, even
if it returned an error! Always use put_device() to give up your
reference instead.
Rule of thumb is: if device_add() succeeds, you should call
device_del() when you want to get rid of it. If device_add() has
not succeeded, use only put_device() to drop the reference
count.
device_register() #
int register a device with the system.
Parameters
struct device *dev: pointer to the device structure
Description
This happens in two clean steps - initialize the device and add it to the system. The two steps can be called separately, but this is the easiest and most common. I.e. you should only call the two helpers separately if have a clearly defined need to use and refcount the device before it is added to the hierarchy.
For more information, see the kerneldoc for device_initialize()
and device_add().
NOTE
Never directly free dev after calling this function, even
if it returned an error! Always use put_device() to give up the
reference initialized in this function instead.
get_device() #
struct device * increment reference count for device.
Parameters
struct device *dev: device.
Description
This simply forwards the call to kobject_get(), though
we do take care to provide for the case that we get a NULL
pointer passed in.
put_device() #
void decrement reference count.
Parameters
struct device *dev: device in question.
device_del() #
void delete device from system.
Parameters
struct device *dev: device.
Description
This is the first part of the device unregistration
sequence. This removes the device from the lists we control
from here, has it removed from the other driver model
subsystems it was added to in device_add(), and removes it
from the kobject hierarchy.
NOTE
this should be called manually iff device_add() was
also called manually.
device_unregister() #
void unregister device from system.
Parameters
struct device *dev: device going away.
Description
We do this in two parts, like we do device_register(). First,
we remove it from all the subsystems with device_del(), then
we decrement the reference count via put_device(). If that
is the final reference count, the device will be cleaned up
via device_release() above. Otherwise, the structure will
stick around until the final reference to the device is dropped.
device_for_each_child() #
int device child iterator.
Parameters
struct device *parent: parent struct device.void *data: data for the callback.device_iter_t fn: function to be called for each device.
Description
Iterate over parent's child devices, and call fn for each, passing it data.
We check the return of fn each time. If it returns anything other than 0, we break out and return that value.
device_for_each_child_reverse() #
int device child iterator in reversed order.
Parameters
struct device *parent: parent struct device.void *data: data for the callback.device_iter_t fn: function to be called for each device.
Description
Iterate over parent's child devices, and call fn for each, passing it data.
We check the return of fn each time. If it returns anything other than 0, we break out and return that value.
device_for_each_child_reverse_from() #
int device child iterator in reversed order.
Parameters
struct device *parent: parent struct device.struct device *from: optional starting point in child listvoid *data: data for the callback.device_iter_t fn: function to be called for each device.
Description
Iterate over parent's child devices, starting at from, and call fn
for each, passing it data. This helper is identical to
device_for_each_child_reverse() when from is NULL.
fn is checked each iteration. If it returns anything other than 0,
iteration stop and that value is returned to the caller of
device_for_each_child_reverse_from();
device_find_child() #
struct device * device iterator for locating a particular device.
Parameters
struct device *parent: parent struct deviceconst void *data: Data to pass to match functiondevice_match_t match: Callback function to check device
Description
This is similar to the device_for_each_child() function above, but it
returns a reference to a device that is 'found' for later use, as
determined by the match callback.
The callback should return 0 if the device doesn't match and non-zero if it does. If the callback returns non-zero and a reference to the current device can be obtained, this function will return to the caller and not iterate over any more devices.
NOTE
you will need to drop the reference with put_device() after use.
__root_device_register() #
struct device * allocate and register a root device
Parameters
const char *name: root device namestruct module *owner: owner module of the root device, usually THIS_MODULE
Description
This function allocates a root device and registers it
using device_register(). In order to free the returned
device, use root_device_unregister().
Root devices are dummy devices which allow other devices to be grouped under /sys/devices. Use this function to allocate a root device and then use it as the parent of any device which should appear under /sys/devices/{name}
The /sys/devices/{name} directory will also contain a 'module' symlink which points to the owner directory in sysfs.
Returns struct device pointer on success, or ERR_PTR() on error.
Note
You probably want to use root_device_register().
root_device_unregister() #
void unregister and free a root device
Parameters
struct device *dev: device going away
Description
This function unregisters and cleans up a device that was created by
root_device_register().
device_create() #
struct device * creates a device and registers it with sysfs
Parameters
const struct class *class: pointer to the struct class that this device should be registered tostruct device *parent: pointer to the parent struct device of this new device, if anydev_t devt: the dev_t for the char device to be addedvoid *drvdata: the data to be added to the device for callbacksconst char *fmt: string for the device's name...: variable arguments
Description
This function can be used by char device classes. A struct device will be created in sysfs, registered to the specified class.
A "dev" file will be created, showing the dev_t for the device, if the dev_t is not 0,0. If a pointer to a parent struct device is passed in, the newly created struct device will be a child of that device in sysfs. The pointer to the struct device will be returned from the call. Any further sysfs files that might be required can be created using this pointer.
Returns struct device pointer on success, or ERR_PTR() on error.
device_create_with_groups() #
struct device * creates a device and registers it with sysfs
Parameters
const struct class *class: pointer to the struct class that this device should be registered tostruct device *parent: pointer to the parent struct device of this new device, if anydev_t devt: the dev_t for the char device to be addedvoid *drvdata: the data to be added to the device for callbacksconst struct attribute_group **groups: NULL-terminated list of attribute groups to be createdconst char *fmt: string for the device's name...: variable arguments
Description
This function can be used by char device classes. A struct device will be created in sysfs, registered to the specified class. Additional attributes specified in the groups parameter will also be created automatically.
A "dev" file will be created, showing the dev_t for the device, if the dev_t is not 0,0. If a pointer to a parent struct device is passed in, the newly created struct device will be a child of that device in sysfs. The pointer to the struct device will be returned from the call. Any further sysfs files that might be required can be created using this pointer.
Returns struct device pointer on success, or ERR_PTR() on error.
device_destroy() #
void removes a device that was created with device_create()
Parameters
const struct class *class: pointer to the struct class that this device was registered withdev_t devt: the dev_t of the device that was previously registered
Description
This call unregisters and cleans up a device that was created with a
call to device_create().
device_rename() #
int renames a device
Parameters
struct device *dev: the pointer to the struct device to be renamedconst char *new_name: the new name of the device
Description
It is the responsibility of the caller to provide mutual exclusion between two different calls of device_rename on the same device to ensure that new_name is valid and won't conflict with other devices.
Note
given that some subsystems (networking and infiniband) use this function, with no immediate plans for this to change, we cannot assume or require that this function not be called at all.
However, if you're writing new code, do not call this function. The following text from Kay Sievers offers some insight:
Renaming devices is racy at many levels, symlinks and other stuff are not replaced atomically, and you get a "move" uevent, but it's not easy to connect the event to the old and new device. Device nodes are not renamed at all, there isn't even support for that in the kernel now.
In the meantime, during renaming, your target name might be taken by another driver, creating conflicts. Or the old name is taken directly after you renamed it -- then you get events for the same DEVPATH, before you even see the "move" event. It's just a mess, and nothing new should ever rely on kernel device renaming. Besides that, it's not even implemented now for other things than (driver-core wise very simple) network devices.
Make up a "real" name in the driver before you register anything, or add some other attributes for userspace to find the device, or use udev to add symlinks -- but never rename kernel devices later, it's a complete mess. We don't even want to get into that and try to implement the missing pieces in the core. We really have other pieces to fix in the driver core mess. :)
device_move() #
int moves a device to a new parent
Parameters
struct device *dev: the pointer to the struct device to be movedstruct device *new_parent: the new parent of the device (can be NULL)enum dpm_order dpm_order: how to reorder the dpm_list
dev_err_probe() #
int probe error check and log helper
Parameters
const struct device *dev: the pointer to the struct deviceint err: error value to testconst char *fmt: printf-style format string...: arguments as specified in the format string
Description
This helper implements common pattern present in probe functions for error checking: print debug or error message depending if the error value is -EPROBE_DEFER and propagate error upwards. In case of -EPROBE_DEFER it sets also defer probe reason, which can be checked later by reading devices_deferred debugfs attribute. It replaces the following code sequence:
if (err != -EPROBE_DEFER)
dev_err(dev, ...);
else
dev_dbg(dev, ...);
return err;
with:
return dev_err_probe(dev, err, ...);
Using this helper in your probe function is totally fine even if err
is known to never be -EPROBE_DEFER.
The benefit compared to a normal dev_err() is the standardized format
of the error code, which is emitted symbolically (i.e. you get "EAGAIN"
instead of "-35"), and having the error code returned allows more
compact error paths.
Returns err.
dev_warn_probe() #
int probe error check and log helper
Parameters
const struct device *dev: the pointer to the struct deviceint err: error value to testconst char *fmt: printf-style format string...: arguments as specified in the format string
Description
This helper implements common pattern present in probe functions for error checking: print debug or warning message depending if the error value is -EPROBE_DEFER and propagate error upwards. In case of -EPROBE_DEFER it sets also defer probe reason, which can be checked later by reading devices_deferred debugfs attribute. It replaces the following code sequence:
if (err != -EPROBE_DEFER)
dev_warn(dev, ...);
else
dev_dbg(dev, ...);
return err;
with:
return dev_warn_probe(dev, err, ...);
Using this helper in your probe function is totally fine even if err
is known to never be -EPROBE_DEFER.
The benefit compared to a normal dev_warn() is the standardized format
of the error code, which is emitted symbolically (i.e. you get "EAGAIN"
instead of "-35"), and having the error code returned allows more
compact error paths.
Returns err.
set_primary_fwnode() #
void Change the primary firmware node of a given device.
Parameters
struct device *dev: Device to handle.struct fwnode_handle *fwnode: New primary firmware node of the device.
Description
Set the device's firmware node pointer to fwnode, but if a secondary firmware node of the device is present, preserve it.
- Valid fwnode cases are:
- primary --> secondary --> -ENODEV
- primary --> NULL
- secondary --> -ENODEV
- NULL
set_secondary_fwnode() #
void Change the secondary firmware node of a given device.
Parameters
struct device *dev: Device to handle.struct fwnode_handle *fwnode: New secondary firmware node of the device.
Description
If a primary firmware node of the device is present, set its secondary pointer to fwnode. Otherwise, set the device's firmware node pointer to fwnode.
device_remove_of_node() #
void Remove an of_node from a device
Parameters
struct device *dev: device whose device tree node is being removed
device_add_of_node() #
int Add an of_node to an existing device
Parameters
struct device *dev: device whose device tree node is being addedstruct device_node *of_node: of_node to add
Return
0 on success or error code on failure.
device_set_of_node_from_dev() #
void reuse device-tree node of another device
Parameters
struct device *dev: device whose device-tree node is being setconst struct device *dev2: device whose device-tree node is being reused
Description
Takes another reference to the new device-tree node after first dropping any reference held to the old node.
get_dev_from_fwnode() #
struct device * Obtain a reference count of the struct device the struct fwnode_handle is associated with.
Parameters
struct fwnode_handle *fwnode: The pointer to the struct fwnode_handle to obtain the struct device reference count of.
Description
This function obtains a reference count of the device the device pointer embedded in the struct fwnode_handle points to.
Note that the struct device pointer embedded in struct fwnode_handle does not have a reference count of the struct device itself.
Hence, it is a UAF (and thus a bug) to call this function if the caller can't guarantee that the last reference count of the corresponding struct device is not dropped concurrently.
This is possible since struct fwnode_handle has its own reference count and hence can out-live the struct device it is associated with.
register_syscore() #
void Register a set of system core operations.
Parameters
struct syscore *syscore: System core operations to register.
unregister_syscore() #
void Unregister a set of system core operations.
Parameters
struct syscore *syscore: System core operations to unregister.
syscore_suspend() #
int Execute all the registered system core suspend callbacks.
Parameters
void: no arguments
Description
This function is executed with one CPU on-line and disabled interrupts.
syscore_resume() #
void Execute all the registered system core resume callbacks.
Parameters
void: no arguments
Description
This function is executed with one CPU on-line and disabled interrupts.
class_find_device_by_name() #
struct device * device iterator for locating a particular device of a specific name.
Parameters
const struct class *class: class typeconst char *name: name of the device to match
class_find_device_by_of_node() #
struct device * device iterator for locating a particular device matching the of_node.
Parameters
const struct class *class: class typeconst struct device_node *np: of_node of the device to match.
class_find_device_by_fwnode() #
struct device * device iterator for locating a particular device matching the fwnode.
Parameters
const struct class *class: class typeconst struct fwnode_handle *fwnode: fwnode of the device to match.
class_find_device_by_devt() #
struct device * device iterator for locating a particular device matching the device type.
Parameters
const struct class *class: class typedev_t devt: device type of the device to match.
class_find_device_by_acpi_dev() #
struct device * device iterator for locating a particular device matching the ACPI_COMPANION device.
Parameters
const struct class *class: class typeconst struct acpi_device *adev: ACPI_COMPANION device to match.
class_create() #
struct class * create a struct class structure
Parameters
const char *name: pointer to a string for the name of this class.
Description
This is used to create a struct class pointer that can then be used
in calls to device_create().
Returns struct class pointer on success, or ERR_PTR() on error.
Note, the pointer created here is to be destroyed when finished by
making a call to class_destroy().
class_destroy() #
void destroys a struct class structure
Parameters
const struct class *cls: pointer to the struct class that is to be destroyed
Description
Note, the pointer to be destroyed must have been created with a call
to class_create().
class_dev_iter_init() #
void initialize class device iterator
Parameters
struct class_dev_iter *iter: class iterator to initializeconst struct class *class: the class we wanna iterate overconst struct device *start: the device to start iterating from, if anyconst struct device_type *type: device_type of the devices to iterate over, NULL for all
Description
Initialize class iterator iter such that it iterates over devices of class. If start is set, the list iteration will start there, otherwise if it is NULL, the iteration starts at the beginning of the list.
class_dev_iter_next() #
struct device * iterate to the next device
Parameters
struct class_dev_iter *iter: class iterator to proceed
Description
Proceed iter to the next device and return it. Returns NULL if iteration is complete.
The returned device is referenced and won't be released till iterator is proceed to the next device or exited. The caller is free to do whatever it wants to do with the device including calling back into class code.
class_dev_iter_exit() #
void finish iteration
Parameters
struct class_dev_iter *iter: class iterator to finish
Description
Finish an iteration. Always call this function after iteration is complete whether the iteration ran till the end or not.
class_for_each_device() #
int device iterator
Parameters
const struct class *class: the class we're iteratingconst struct device *start: the device to start with in the list, if any.void *data: data for the callbackdevice_iter_t fn: function to be called for each device
Description
Iterate over class's list of devices, and call fn for each, passing it data. If start is set, the list iteration will start there, otherwise if it is NULL, the iteration starts at the beginning of the list.
We check the return of fn each time. If it returns anything other than 0, we break out and return that value.
fn is allowed to do anything including calling back into class code. There's no locking restriction.
class_find_device() #
struct device * device iterator for locating a particular device
Parameters
const struct class *class: the class we're iteratingconst struct device *start: Device to begin withconst void *data: data for the match functiondevice_match_t match: function to check device
Description
This is similar to the class_for_each_dev() function above, but it
returns a reference to a device that is 'found' for later use, as
determined by the match callback.
The callback should return 0 if the device doesn't match and non-zero if it does. If the callback returns non-zero, this function will return to the caller and not iterate over any more devices.
Note, you will need to drop the reference with put_device() after use.
match is allowed to do anything including calling back into class code. There's no locking restriction.
class_compat_register() #
struct class_compat * register a compatibility class
Parameters
const char *name: the name of the class
Description
Compatibility class are meant as a temporary user-space compatibility workaround when converting a family of class devices to a bus devices.
class_compat_unregister() #
void unregister a compatibility class
Parameters
struct class_compat *cls: the class to unregister
class_compat_create_link() #
int create a compatibility class device link to a bus device
Parameters
struct class_compat *cls: the compatibility classstruct device *dev: the target bus device
class_compat_remove_link() #
void remove a compatibility class device link to a bus device
Parameters
struct class_compat *cls: the compatibility classstruct device *dev: the target bus device
class_is_registered() #
bool determine if at this moment in time, a class is registered in the driver core or not.
Parameters
const struct class *class: the class to check
Description
Returns a boolean to state if the class is registered in the driver core or not. Note that the value could switch right after this call is made, so only use this in places where you "know" it is safe to do so (usually to determine if the specific class has been registered yet or not).
Be careful in using this.
struct faux_device #
a "faux" device
Definition
;
Members
dev: internal struct device of the object
Description
A simple faux device that can be created/destroyed. To be used when a driver only needs to have a device to "hang" something off. This can be used for downloading firmware or other basic tasks. Use this instead of a struct platform_device if the device has no resources assigned to it at all.
struct faux_device_ops #
a set of callbacks for a struct faux_device
Definition
;
Members
probe: called when a faux device is probed by the driver core before the device is fully bound to the internal faux bus code. If probe succeeds, return 0, otherwise return a negative error number to stop the probe sequence from succeeding.remove: called when a faux device is removed from the system
Description
Both probe and remove are optional, if not needed, set to NULL.
faux_device_create_with_groups() #
struct faux_device * Create and register with the driver core a faux device and populate the device with an initial set of sysfs attributes.
Parameters
const char *name: The name of the device we are adding, must be unique for all faux devices.struct device *parent: Pointer to a potential parent struct device. If set to NULL, the device will be created in the "root" of the faux device tree in sysfs.const struct faux_device_ops *faux_ops: struct faux_device_ops that the new device will call back into, can be NULL.const struct attribute_group **groups: The set of sysfs attributes that will be created for this device when it is registered with the driver core.
Description
Create a new faux device and register it in the driver core properly. If present, callbacks in faux_ops will be called with the device that for the caller to do something with at the proper time given the device's lifecycle.
Note, when this function is called, the functions specified in struct faux_ops can be called before the function returns, so be prepared for everything to be properly initialized before that point in time. If the probe callback (if one is present) does NOT succeed, the creation of the device will fail and NULL will be returned.
Return
- NULL if an error happened with creating the device
- pointer to a valid struct faux_device that is registered with sysfs
faux_device_create() #
struct faux_device * create and register with the driver core a faux device
Parameters
const char *name: The name of the device we are adding, must be unique for all faux devices.struct device *parent: Pointer to a potential parent struct device. If set to NULL, the device will be created in the "root" of the faux device tree in sysfs.const struct faux_device_ops *faux_ops: struct faux_device_ops that the new device will call back into, can be NULL.
Description
Create a new faux device and register it in the driver core properly. If present, callbacks in faux_ops will be called with the device that for the caller to do something with at the proper time given the device's lifecycle.
Note, when this function is called, the functions specified in struct faux_ops can be called before the function returns, so be prepared for everything to be properly initialized before that point in time.
Return
- NULL if an error happened with creating the device
- pointer to a valid struct faux_device that is registered with sysfs
faux_device_destroy() #
void destroy a faux device
Parameters
struct faux_device *faux_dev: faux device to destroy
Description
Unregisters and cleans up a device that was created with a call to
faux_device_create()
struct node_access_nodes #
Access class device to hold user visible relationships to other nodes.
Definition
;
Members
dev: Device for this memory access classlist_node: List element in the node's access listaccess: The access class rankcoord: Heterogeneous memory performance coordinates
struct node_cache_info #
Internal tracking for memory node caches
Definition
;
Members
dev: Device represeting the cache levelnode: List element for tracking in the nodecache_attrs: Attributes for this cache level
node_add_cache() #
void add cache attribute to a memory node
Parameters
unsigned int nid: Node identifier that has new cache attributesstruct node_cache_attrs *cache_attrs: Attributes for the cache being added
register_memory_node_under_compute_node() #
int link memory node to its compute node for a given access class.
Parameters
unsigned int mem_nid: Memory node numberunsigned int cpu_nid: Cpu node numberenum access_coordinate_class access: Access class to register
Description
For use with platforms that may have separate memory and compute nodes. This function will export node relationships linking which memory initiator nodes can access memory targets at a given ranked access class.
register_node() #
int Initialize and register the node device.
Parameters
int nid: Node number to use when creating the device.
Return
0 on success, -errno otherwise
unregister_node() #
void unregister a node device
Parameters
int nid: nid of the node going away
Description
Unregisters the node device at node id nid. All the devices on the node must be unregistered before calling this function.
transport_class_register() #
int register an initial transport class
Parameters
struct transport_class *tclass: a pointer to the transport class structure to be initialised
Description
The transport class contains an embedded class which is used to
identify it. The caller should initialise this structure with
zeros and then generic class must have been initialised with the
actual transport class unique name. There's a macro
DECLARE_TRANSPORT_CLASS() to do this (declared classes still must
be registered).
Returns 0 on success or error on failure.
transport_class_unregister() #
void unregister a previously registered class
Parameters
struct transport_class *tclass: The transport class to unregister
Description
Must be called prior to deallocating the memory for the transport class.
anon_transport_class_register() #
void register an anonymous class
Parameters
struct anon_transport_class *atc: The anon transport class to register
Description
The anonymous transport class contains both a transport class and a
container. The idea of an anonymous class is that it never
actually has any device attributes associated with it (and thus
saves on container storage). So it can only be used for triggering
events. Use prezero and then use DECLARE_ANON_TRANSPORT_CLASS() to
initialise the anon transport class storage.
anon_transport_class_unregister() #
void unregister an anon class
Parameters
struct anon_transport_class *atc: Pointer to the anon transport class to unregister
Description
Must be called prior to deallocating the memory for the anon transport class.
transport_setup_device() #
void declare a new dev for transport class association but don't make it visible yet.
Parameters
struct device *dev: the generic device representing the entity being added
Description
Usually, dev represents some component in the HBA system (either the HBA itself or a device remote across the HBA bus). This routine is simply a trigger point to see if any set of transport classes wishes to associate with the added device. This allocates storage for the class device and initialises it, but does not yet add it to the system or add attributes to it (you do this with transport_add_device). If you have no need for a separate setup and add operations, use transport_register_device (see transport_class.h).
transport_add_device() #
int declare a new dev for transport class association
Parameters
struct device *dev: the generic device representing the entity being added
Description
Usually, dev represents some component in the HBA system (either the HBA itself or a device remote across the HBA bus). This routine is simply a trigger point used to add the device to the system and register attributes for it.
transport_configure_device() #
void configure an already set up device
Parameters
struct device *dev: generic device representing device to be configured
Description
The idea of configure is simply to provide a point within the setup process to allow the transport class to extract information from a device after it has been setup. This is used in SCSI because we have to have a setup device to begin using the HBA, but after we send the initial inquiry, we use configure to extract the device parameters. The device need not have been added to be configured.
transport_remove_device() #
void remove the visibility of a device
Parameters
struct device *dev: generic device to remove
Description
This call removes the visibility of the device (to the user from
sysfs), but does not destroy it. To eliminate a device entirely
you must also call transport_destroy_device. If you don't need to
do remove and destroy as separate operations, use
transport_unregister_device() (see transport_class.h) which will
perform both calls for you.
transport_destroy_device() #
void destroy a removed device
Parameters
struct device *dev: device to eliminate from the transport class.
Description
This call triggers the elimination of storage associated with the transport classdev. Note: all it really does is relinquish a reference to the classdev. The memory will not be freed until the last reference goes to zero. Note also that the classdev retains a reference count on dev, so dev too will remain for as long as the transport class device remains around.
driver_deferred_probe_check_state() #
int Check deferred probe state
Parameters
struct device *dev: device to check
Return
- -ENODEV if initcalls have completed and modules are disabled.
- -ETIMEDOUT if the deferred probe timeout was set and has expired and modules are enabled.
- -EPROBE_DEFER in other cases.
Description
Drivers or subsystems can opt-in to calling this function instead of directly returning -EPROBE_DEFER.
device_is_bound() #
bool Check if device is bound to a driver
Parameters
struct device *dev: device to check
Description
Returns true if passed device has already finished probing successfully against a driver.
This function must be called with the device lock held.
device_bind_driver() #
int bind a driver to one device.
Parameters
struct device *dev: device.
Description
Allow manual attachment of a driver to a device. Caller must have already set dev->driver.
Note that this does not modify the bus reference count.
Please verify that is accounted for before calling this.
(It is ok to call with no other effort from a driver's probe() method.)
This function must be called with the device lock held.
Callers should prefer to use device_driver_attach() instead.
wait_for_device_probe() #
void Parameters
void: no arguments
Description
Wait for device probing to be completed.
device_attach() #
int try to attach device to a driver.
Parameters
struct device *dev: device.
Description
Walk the list of drivers that the bus has and call
driver_probe_device() for each pair. If a compatible
pair is found, break out and return.
Returns 1 if the device was bound to a driver; 0 if no matching driver was found; -ENODEV if the device is not registered.
When called for a USB interface, dev->parent lock must be held.
device_driver_attach() #
int attach a specific driver to a specific device
Parameters
const struct device_driver *drv: Driver to attachstruct device *dev: Device to attach it to
Description
Manually attach driver to a device. Will acquire both dev lock and dev->parent lock if needed. Returns 0 on success, -ERR on failure.
driver_attach() #
int try to bind driver to devices.
Parameters
const struct device_driver *drv: driver.
Description
Walk the list of devices that the bus has on it and try to
match the driver with each one. If driver_probe_device()
returns 0 and the dev->driver is set, we've found a
compatible pair.
device_release_driver() #
void manually detach device from driver.
Parameters
struct device *dev: device.
Description
Manually detach device from driver. When called for a USB interface, dev->parent lock must be held.
If this function is to be called with dev->parent lock held, ensure that the device's consumers are unbound in advance or that their locks can be acquired under the dev->parent lock.
platform_device_register_resndata() #
struct platform_device * add a platform-level device with resources and platform-specific data
Parameters
struct device *parent: parent device for the device we're addingconst char *name: base name of the device we're addingint id: instance idconst struct resource *res: set of resources that needs to be allocated for the deviceunsigned int num: number of resourcesconst void *data: platform specific data for this platform devicesize_t size: size of platform specific data
Description
Returns struct platform_device pointer on success, or ERR_PTR() on error.
platform_device_register_simple() #
struct platform_device * add a platform-level device and its resources
Parameters
const char *name: base name of the device we're addingint id: instance idconst struct resource *res: set of resources that needs to be allocated for the deviceunsigned int num: number of resources
Description
This function creates a simple platform device that requires minimal resource and memory management. Canned release function freeing memory allocated for the device allows drivers using such devices to be unloaded without waiting for the last reference to the device to be dropped.
This interface is primarily intended for use with legacy drivers which probe hardware directly. Because such drivers create sysfs device nodes themselves, rather than letting system infrastructure handle such device enumeration tasks, they don't fully conform to the Linux driver model. In particular, when such drivers are built as modules, they can't be "hotplugged".
Returns struct platform_device pointer on success, or ERR_PTR() on error.
platform_device_register_data() #
struct platform_device * add a platform-level device with platform-specific data
Parameters
struct device *parent: parent device for the device we're addingconst char *name: base name of the device we're addingint id: instance idconst void *data: platform specific data for this platform devicesize_t size: size of platform specific data
Description
This function creates a simple platform device that requires minimal resource and memory management. Canned release function freeing memory allocated for the device allows drivers using such devices to be unloaded without waiting for the last reference to the device to be dropped.
Returns struct platform_device pointer on success, or ERR_PTR() on error.
platform_get_resource() #
struct resource * get a resource for a device
Parameters
struct platform_device *dev: platform deviceunsigned int type: resource typeunsigned int num: resource index
Return
a pointer to the resource or NULL on failure.
devm_platform_get_and_ioremap_resource() #
void __iomem * call devm_ioremap_resource() for a platform device and get resource
Parameters
struct platform_device *pdev: platform device to use both for memory resource lookup as well as resource managementunsigned int index: resource indexstruct resource **res: optional output parameter to store a pointer to the obtained resource.
Return
a pointer to the remapped memory or an ERR_PTR() encoded error code
on failure.
devm_platform_ioremap_resource() #
void __iomem * call devm_ioremap_resource() for a platform device
Parameters
struct platform_device *pdev: platform device to use both for memory resource lookup as well as resource managementunsigned int index: resource index
Return
a pointer to the remapped memory or an ERR_PTR() encoded error code
on failure.
devm_platform_ioremap_resource_byname() #
void __iomem * call devm_ioremap_resource for a platform device, retrieve the resource by name
Parameters
struct platform_device *pdev: platform device to use both for memory resource lookup as well as resource managementconst char *name: name of the resource
Return
a pointer to the remapped memory or an ERR_PTR() encoded error code
on failure.
platform_get_irq_affinity() #
int get an optional IRQ and its affinity for a device
Parameters
struct platform_device *dev: platform deviceunsigned int num: interrupt number indexconst struct cpumask **affinity: optional cpumask pointer to get the affinity of a per-cpu interrupt
Description
Gets an interupt for a platform device. Device drivers should check the
return value for errors so as to not pass a negative integer value to
the request_irq() APIs. Optional affinity information is provided in the
affinity pointer if available, and NULL otherwise.
Return
non-zero interrupt number on success, negative error number on failure.
platform_get_irq_optional() #
int get an optional interrupt for a device
Parameters
struct platform_device *dev: platform deviceunsigned int num: interrupt number index
Description
Gets an interrupt for a platform device. Device drivers should check the
return value for errors so as to not pass a negative integer value to
the request_irq() APIs. This is the same as platform_get_irq(), except
that it does not print an error message if an interrupt can not be
obtained.
For example:
int irq = platform_get_irq_optional(pdev, 0);
if (irq < 0)
return irq;
Return
non-zero interrupt number on success, negative error number on failure.
platform_get_irq() #
int get an IRQ for a device
Parameters
struct platform_device *dev: platform deviceunsigned int num: IRQ number index
Description
Gets an IRQ for a platform device and prints an error message if finding the
IRQ fails. Device drivers should check the return value for errors so as to
not pass a negative integer value to the request_irq() APIs.
For example:
int irq = platform_get_irq(pdev, 0);
if (irq < 0)
return irq;
Return
non-zero IRQ number on success, negative error number on failure.
platform_irq_count() #
int Count the number of IRQs a platform device uses
Parameters
struct platform_device *dev: platform device
Return
Number of IRQs a platform device uses or EPROBE_DEFER
devm_platform_get_irqs_affinity() #
int devm method to get a set of IRQs for a device using an interrupt affinity descriptor
Parameters
struct platform_device *dev: platform device pointerstruct irq_affinity *affd: affinity descriptorunsigned int minvec: minimum count of interrupt vectorsunsigned int maxvec: maximum count of interrupt vectorsint **irqs: pointer holder for IRQ numbers
Description
Gets a set of IRQs for a platform device, and updates IRQ afffinty according to the passed affinity descriptor
Return
Number of vectors on success, negative error number on failure.
platform_get_resource_byname() #
struct resource * get a resource for a device by name
Parameters
struct platform_device *dev: platform deviceunsigned int type: resource typeconst char *name: resource name
platform_get_irq_byname() #
int get an IRQ for a device by name
Parameters
struct platform_device *dev: platform deviceconst char *name: IRQ name
Description
Get an IRQ like platform_get_irq(), but then by name rather then by index.
Return
non-zero IRQ number on success, negative error number on failure.
platform_get_irq_byname_optional() #
int get an optional IRQ for a device by name
Parameters
struct platform_device *dev: platform deviceconst char *name: IRQ name
Description
Get an optional IRQ by name like platform_get_irq_byname(). Except that it
does not print an error message if an IRQ can not be obtained.
Return
non-zero IRQ number on success, negative error number on failure.
platform_add_devices() #
int add a numbers of platform devices
Parameters
struct platform_device **devs: array of platform devices to addint num: number of platform devices in array
Return
0 on success, negative error number on failure.
platform_device_put() #
void destroy a platform device
Parameters
struct platform_device *pdev: platform device to free
Description
Free all memory associated with a platform device. This function must only be externally called in error cases. All other usage is a bug.
platform_device_alloc() #
struct platform_device * create a platform device
Parameters
const char *name: base name of the device we're addingint id: instance id
Description
Create a platform device object which can have other objects attached to it, and which will have attached objects freed when it is released.
platform_device_add_resources() #
int add resources to a platform device
Parameters
struct platform_device *pdev: platform device allocated by platform_device_alloc to add resources toconst struct resource *res: set of resources that needs to be allocated for the deviceunsigned int num: number of resources
Description
Add a copy of the resources to the platform device. The memory associated with the resources will be freed when the platform device is released.
platform_device_add_data() #
int add platform-specific data to a platform device
Parameters
struct platform_device *pdev: platform device allocated by platform_device_alloc to add resources toconst void *data: platform specific data for this platform devicesize_t size: size of platform specific data
Description
Add a copy of platform specific data to the platform device's platform_data pointer. The memory associated with the platform data will be freed when the platform device is released.
platform_device_add() #
int add a platform device to device hierarchy
Parameters
struct platform_device *pdev: platform device we're adding
Description
This is part 2 of platform_device_register(), though may be called
separately iff pdev was allocated by platform_device_alloc().
platform_device_del() #
void remove a platform-level device
Parameters
struct platform_device *pdev: platform device we're removing
Description
Note that this function will also release all memory- and port-based resources owned by the device (dev->resource). This function must only be externally called in error cases. All other usage is a bug.
platform_device_register() #
int add a platform-level device
Parameters
struct platform_device *pdev: platform device we're adding
NOTE
Never directly free pdev after calling this function, even if it
returned an error! Always use platform_device_put() to give up the
reference initialised in this function instead.
platform_device_unregister() #
void unregister a platform-level device
Parameters
struct platform_device *pdev: platform device we're unregistering
Description
Unregistration is done in 2 steps. First we release all resources
and remove it from the subsystem, then we drop reference count by
calling platform_device_put().
platform_device_register_full() #
struct platform_device * add a platform-level device with resources and platform-specific data
Parameters
const struct platform_device_info *pdevinfo: data used to create device
Description
Returns struct platform_device pointer on success, or ERR_PTR() on error.
__platform_driver_register() #
int register a driver for platform-level devices
Parameters
struct platform_driver *drv: platform driver structurestruct module *owner: owning module/driver
platform_driver_unregister() #
void unregister a driver for platform-level devices
Parameters
struct platform_driver *drv: platform driver structure
__platform_driver_probe() #
int register driver for non-hotpluggable device
Parameters
struct platform_driver *drv: platform driver structureint (*probe)(struct platform_device *): the driver probe routine, probably from an __init sectionstruct module *module: module which will be the owner of the driver
Description
Use this instead of platform_driver_register() when you know the device
is not hotpluggable and has already been registered, and you want to
remove its run-once probe() infrastructure from memory after the driver
has bound to the device.
One typical use for this would be with drivers for controllers integrated into system-on-chip processors, where the controller devices have been configured as part of board setup.
Note that this is incompatible with deferred probing.
Returns zero if the driver registered and bound to a device, else returns a negative error code and with the driver not registered.
__platform_create_bundle() #
struct platform_device * register driver and create corresponding device
Parameters
struct platform_driver *driver: platform driver structureint (*probe)(struct platform_device *): the driver probe routine, probably from an __init sectionstruct resource *res: set of resources that needs to be allocated for the deviceunsigned int n_res: number of resourcesconst void *data: platform specific data for this platform devicesize_t size: size of platform specific datastruct module *module: module which will be the owner of the driver
Description
Use this in legacy-style modules that probe hardware directly and register a single platform device and corresponding platform driver.
Returns struct platform_device pointer on success, or ERR_PTR() on error.
__platform_register_drivers() #
int register an array of platform drivers
Parameters
struct platform_driver * const *drivers: an array of drivers to registerunsigned int count: the number of drivers to registerstruct module *owner: module owning the drivers
Description
Registers platform drivers specified by an array. On failure to register a
driver, all previously registered drivers will be unregistered. Callers of
this API should use platform_unregister_drivers() to unregister drivers in
the reverse order.
Return
0 on success or a negative error code on failure.
platform_unregister_drivers() #
void unregister an array of platform drivers
Parameters
struct platform_driver * const *drivers: an array of drivers to unregisterunsigned int count: the number of drivers to unregister
Description
Unregisters platform drivers specified by an array. This is typically used
to complement an earlier call to platform_register_drivers(). Drivers are
unregistered in the reverse order in which they were registered.
platform_find_device_by_driver() #
struct device * Find a platform device with a given driver.
Parameters
struct device *start: The device to start the search from.const struct device_driver *drv: The device driver to look for.
bus_find_device_by_name() #
struct device * device iterator for locating a particular device of a specific name.
Parameters
const struct bus_type *bus: bus typestruct device *start: Device to begin withconst char *name: name of the device to match
bus_find_device_by_of_node() #
struct device * device iterator for locating a particular device matching the of_node.
Parameters
const struct bus_type *bus: bus typeconst struct device_node *np: of_node of the device to match.
bus_find_device_by_fwnode() #
struct device * device iterator for locating a particular device matching the fwnode.
Parameters
const struct bus_type *bus: bus typeconst struct fwnode_handle *fwnode: fwnode of the device to match.
bus_find_device_by_devt() #
struct device * device iterator for locating a particular device matching the device type.
Parameters
const struct bus_type *bus: bus typedev_t devt: device type of the device to match.
bus_find_next_device() #
struct device * Find the next device after a given device in a given bus.
Parameters
const struct bus_type *bus: bus typestruct device *cur: device to begin the search with.
bus_find_device_by_acpi_dev() #
struct device * device iterator for locating a particular device matching the ACPI COMPANION device.
Parameters
const struct bus_type *bus: bus typeconst struct acpi_device *adev: ACPI COMPANION device to match.
bus_for_each_dev() #
int device iterator.
Parameters
const struct bus_type *bus: bus type.struct device *start: device to start iterating from.void *data: data for the callback.device_iter_t fn: function to be called for each device.
Description
Iterate over bus's list of devices, and call fn for each, passing it data. If start is not NULL, we use that device to begin iterating from.
We check the return of fn each time. If it returns anything other than 0, we break out and return that value.
NOTE
The device that returns a non-zero value is not retained in any way, nor is its refcount incremented. If the caller needs to retain this data, it should do so, and increment the reference count in the supplied callback.
bus_find_device() #
struct device * device iterator for locating a particular device.
Parameters
const struct bus_type *bus: bus typestruct device *start: Device to begin withconst void *data: Data to pass to match functiondevice_match_t match: Callback function to check device
Description
This is similar to the bus_for_each_dev() function above, but it
returns a reference to a device that is 'found' for later use, as
determined by the match callback.
The callback should return 0 if the device doesn't match and non-zero if it does. If the callback returns non-zero, this function will return to the caller and not iterate over any more devices.
bus_for_each_drv() #
int driver iterator
Parameters
const struct bus_type *bus: bus we're dealing with.struct device_driver *start: driver to start iterating on.void *data: data to pass to the callback.int (*fn)(struct device_driver *, void *): function to call for each driver.
Description
This is nearly identical to the device iterator above. We iterate over each driver that belongs to bus, and call fn for each. If fn returns anything but 0, we break out and return it. If start is not NULL, we use it as the head of the list.
NOTE
we don't return the driver that returns a non-zero value, nor do we leave the reference count incremented for that driver. If the caller needs to know that info, it must set it in the callback. It must also be sure to increment the refcount so it doesn't disappear before returning to the caller.
bus_rescan_devices() #
int rescan devices on the bus for possible drivers
Parameters
const struct bus_type *bus: the bus to scan.
Description
This function will look for devices on the bus with no driver
attached and rescan it against existing drivers to see if it matches
any by calling device_attach() for the unbound devices.
device_reprobe() #
int remove driver for a device and probe for a new driver
Parameters
struct device *dev: the device to reprobe
Description
This function detaches the attached driver (if any) for the given device and restarts the driver probing process. It is intended to use if probing criteria changed during a devices lifetime and driver attachment should change accordingly.
bus_register() #
int register a driver-core subsystem
Parameters
const struct bus_type *bus: bus to register
Description
Once we have that, we register the bus with the kobject infrastructure, then register the children subsystems it has: the devices and drivers that belong to the subsystem.
bus_unregister() #
void remove a bus from the system
Parameters
const struct bus_type *bus: bus.
Description
Unregister the child subsystems and the bus itself.
Finally, we call bus_put() to release the refcount
subsys_system_register() #
int register a subsystem at /sys/devices/system/
Parameters
const struct bus_type *subsys: system subsystemconst struct attribute_group **groups: default attributes for the root device
Description
All 'system' subsystems have a /sys/devices/system/<name> root device with the name of the subsystem. The root device can carry subsystem- wide attributes. All registered devices are below this single root device and are named after the subsystem with a simple enumeration number appended. The registered devices are not explicitly named; only 'id' in the device needs to be set.
Do not use this interface for anything new, it exists for compatibility with bad ideas only. New subsystems should use plain subsystems; and add the subsystem-wide attributes should be added to the subsystem directory itself and not some create fake root-device placed in /sys/devices/system/<name>.
subsys_virtual_register() #
int register a subsystem at /sys/devices/virtual/
Parameters
const struct bus_type *subsys: virtual subsystemconst struct attribute_group **groups: default attributes for the root device
Description
All 'virtual' subsystems have a /sys/devices/system/<name> root device with the name of the subsystem. The root device can carry subsystem-wide attributes. All registered devices are below this single root device. There's no restriction on device naming. This is for kernel software constructs which need sysfs interface.
driver_find() #
struct device_driver * locate driver on a bus by its name.
Parameters
const char *name: name of the driver.const struct bus_type *bus: bus to scan for the driver.
Description
Call kset_find_obj() to iterate over list of drivers on
a bus to find driver by name. Return driver if found.
This routine provides no locking to prevent the driver it returns from being unregistered or unloaded while the caller is using it. The caller is responsible for preventing this.
bus_get_dev_root() #
struct device * return a pointer to the "device root" of a bus
Parameters
const struct bus_type *bus: bus to return the device root of.
Description
If a bus has a "device root" structure, return it, WITH THE REFERENCE COUNT INCREMENTED.
Note, when finished with the device, a call to put_device() is required.
If the device root is not present (or bus is not a valid pointer), NULL will be returned.
Device Drivers DMA Management #
dmam_free_coherent() #
void Managed dma_free_coherent()
Parameters
struct device *dev: Device to free coherent memory forsize_t size: Size of allocationvoid *vaddr: Virtual address of the memory to freedma_addr_t dma_handle: DMA handle of the memory to free
Description
Managed dma_free_coherent().
dmam_alloc_attrs() #
void * Managed dma_alloc_attrs()
Parameters
struct device *dev: Device to allocate non_coherent memory forsize_t size: Size of allocationdma_addr_t *dma_handle: Out argument for allocated DMA handlegfp_t gfp: Allocation flagsunsigned long attrs: Flags in the DMA_ATTR_* namespace.
Description
Managed dma_alloc_attrs(). Memory allocated using this function will be
automatically released on driver detach.
Return
Pointer to allocated memory on success, NULL on failure.
dma_map_sg_attrs() #
unsigned int Map the given buffer for DMA
Parameters
struct device *dev: The device for which to perform the DMA operationstruct scatterlist *sg: The sg_table object describing the bufferint nents: Number of entries to mapenum dma_data_direction dir: DMA directionunsigned long attrs: Optional DMA attributes for the map operation
Description
Maps a buffer described by a scatterlist passed in the sg argument with nents segments for the dir DMA operation by the dev device.
Returns the number of mapped entries (which can be less than nents) on success. Zero is returned for any error.
dma_unmap_sg_attrs() should be used to unmap the buffer with the
original sg and original nents (not the value returned by this funciton).
dma_map_sgtable() #
int Map the given buffer for DMA
Parameters
struct device *dev: The device for which to perform the DMA operationstruct sg_table *sgt: The sg_table object describing the bufferenum dma_data_direction dir: DMA directionunsigned long attrs: Optional DMA attributes for the map operation
Description
Maps a buffer described by a scatterlist stored in the given sg_table
object for the dir DMA operation by the dev device. After success, the
ownership for the buffer is transferred to the DMA domain. One has to
call dma_sync_sgtable_for_cpu() or dma_unmap_sgtable() to move the
ownership of the buffer back to the CPU domain before touching the
buffer by the CPU.
Returns 0 on success or a negative error code on error. The following error codes are supported with the given meaning:
-
-EINVAL An invalid argument, unaligned access or other error
in usage. Will not succeed if retried.
-
-ENOMEM Insufficient resources (like memory or IOVA space) to
complete the mapping. Should succeed if retried later.
-
-EIO Legacy error code with an unknown meaning. eg. this is
returned if a lower level call returned DMA_MAPPING_ERROR.
-
-EREMOTEIO The DMA device cannot access P2PDMA memory specified
in the sg_table. This will not succeed if retried.
-
dma_need_unmap() #
bool does this device need dma_unmap_* operations
Parameters
struct device *dev: device to check
Description
If this function returns false, drivers can skip calling dma_unmap_* after
finishing an I/O. This function must be called after all mappings that might
need to be unmapped have been performed.
dma_can_mmap() #
bool check if a given device supports dma_mmap_*
Parameters
struct device *dev: device to check
Description
Returns true if dev supports dma_mmap_coherent() and dma_mmap_attrs() to
map DMA allocations to userspace.
dma_mmap_attrs() #
int map a coherent DMA allocation into user space
Parameters
struct device *dev: valid struct device pointer, or NULL for ISA and EISA-like devicesstruct vm_area_struct *vma: vm_area_struct describing requested user mappingvoid *cpu_addr: kernel CPU-view address returned from dma_alloc_attrsdma_addr_t dma_addr: device-view address returned from dma_alloc_attrssize_t size: size of memory originally requested in dma_alloc_attrsunsigned long attrs: attributes of mapping properties requested in dma_alloc_attrs
Description
Map a coherent DMA buffer previously allocated by dma_alloc_attrs into user space. The coherent DMA buffer must not be freed by the driver until the user space mapping has been released.
dma_addressing_limited() #
bool return if the device is addressing limited
Parameters
struct device *dev: device to check
Description
Return true if the devices DMA mask is too small to address all memory in
the system, else false. Lack of addressing bits is the prime reason for
bounce buffering, but might not be the only one.
Device drivers PnP support #
pnp_register_protocol() #
int adds a pnp protocol to the pnp layer
Parameters
struct pnp_protocol *protocol: pointer to the corresponding pnp_protocol structure
Description
Ex protocols: ISAPNP, PNPBIOS, etc
pnp_request_card_device() #
struct pnp_dev * Searches for a PnP device under the specified card
Parameters
struct pnp_card_link *clink: pointer to the card link, cannot be NULLconst char *id: pointer to a PnP ID structure that explains the rules for finding the devicestruct pnp_dev *from: Starting place to search from. If NULL it will start from the beginning.
pnp_release_card_device() #
void call this when the driver no longer needs the device
Parameters
struct pnp_dev *dev: pointer to the PnP device structure
pnp_register_card_driver() #
int registers a PnP card driver with the PnP Layer
Parameters
struct pnp_card_driver *drv: pointer to the driver to register
pnp_unregister_card_driver() #
void unregisters a PnP card driver from the PnP Layer
Parameters
struct pnp_card_driver *drv: pointer to the driver to unregister
pnp_add_id() #
struct pnp_id * adds an EISA id to the specified device
Parameters
struct pnp_dev *dev: pointer to the desired deviceconst char *id: pointer to an EISA id string
pnp_start_dev() #
int low-level start of the PnP device
Parameters
struct pnp_dev *dev: pointer to the desired device
Description
assumes that resources have already been allocated
pnp_stop_dev() #
int low-level disable of the PnP device
Parameters
struct pnp_dev *dev: pointer to the desired device
Description
does not free resources
pnp_activate_dev() #
int activates a PnP device for use
Parameters
struct pnp_dev *dev: pointer to the desired device
Description
does not validate or set resources so be careful.
pnp_disable_dev() #
int disables device
Parameters
struct pnp_dev *dev: pointer to the desired device
Description
inform the correct pnp protocol so that resources can be used by other devices
pnp_is_active() #
int Determines if a device is active based on its current resources
Parameters
struct pnp_dev *dev: pointer to the desired PnP device
Userspace IO devices #
uio_event_notify() #
void trigger an interrupt event
Parameters
struct uio_info *info: UIO device capabilities
__uio_register_device() #
int register a new userspace IO device
Parameters
struct module *owner: module that creates the new devicestruct device *parent: parent devicestruct uio_info *info: UIO device capabilities
Description
returns zero on success or a negative error code.
__devm_uio_register_device() #
int Resource managed uio_register_device()
Parameters
struct module *owner: module that creates the new devicestruct device *parent: parent devicestruct uio_info *info: UIO device capabilities
Description
returns zero on success or a negative error code.
uio_unregister_device() #
void unregister a industrial IO device
Parameters
struct uio_info *info: UIO device capabilities
struct uio_mem #
description of a UIO memory region
Definition
;
Members
name: name of the memory region for identificationaddr: address of the device's memory rounded to page size (phys_addr is used since addr can be logical, virtual, or physical & phys_addr_t should always be large enough to handle any of the address types)dma_addr: DMA handle set by dma_alloc_coherent, used with UIO_MEM_DMA_COHERENT only (addr should be the void * returned from the same dma_alloc_coherent call)offs: offset of device memory within the pagesize: size of IO (multiple of page size)memtype: type of memory addr points tointernal_addr: ioremap-ped version of addr, for driver internal usedma_device: device struct that was passed to dma_alloc_coherent, used with UIO_MEM_DMA_COHERENT onlymap: for use by the UIO core only.
struct uio_port #
description of a UIO port region
Definition
;
Members
name: name of the port region for identificationstart: start of port regionsize: size of port regionporttype: type of port (see UIO_PORT_* below)portio: for use by the UIO core only.
struct uio_info #
UIO device capabilities
Definition
;
Members
uio_dev: the UIO device this info belongs toname: device nameversion: device driver versionmem: list of mappable memory regions, size==0 for end of listport: list of port regions, size==0 for end of listirq: interrupt number or UIO_IRQ_CUSTOMirq_flags: flags forrequest_irq()priv: optional private datahandler: the device's irq handlermmap: mmap operation for this uio deviceopen: open operation for this uio devicerelease: release operation for this uio deviceirqcontrol: disable/enable irqs when 0/1 is written to /dev/uioX
uio_register_device() #
register a new userspace IO device
Parameters
parent: parent deviceinfo: UIO device capabilities
Description
returns zero on success or a negative error code.
devm_uio_register_device() #
Resource managed uio_register_device()
Parameters
parent: parent deviceinfo: UIO device capabilities
Description
returns zero on success or a negative error code.