Device drivers infrastructure
The Basic Device Driver-Model Structures
-
struct
-
The bus type of the device
bus_type
Definition
struct bus_type {
const char * name;
const char * dev_name;
struct device * dev_root;
struct device_attribute * dev_attrs;
const struct attribute_group ** bus_groups;
const struct attribute_group ** dev_groups;
const struct attribute_group ** drv_groups;
int (* match) (struct device *dev, struct device_driver *drv);
int (* uevent) (struct device *dev, struct kobj_uevent_env *env);
int (* probe) (struct device *dev);
int (* remove) (struct device *dev);
void (* shutdown) (struct device *dev);
int (* online) (struct device *dev);
int (* offline) (struct device *dev);
int (* suspend) (struct device *dev, pm_message_t state);
int (* resume) (struct device *dev);
const struct dev_pm_ops * pm;
const struct iommu_ops * iommu_ops;
struct subsys_private * p;
struct lock_class_key lock_key;
};
Members
- The name of the bus.
- Used for subsystems to enumerate devices like (“foo``u``”, dev->id).
- Default device to use as the parent.
- Default attributes of the devices on the bus.
- Default attributes of the bus.
- Default attributes of the devices on the bus.
- Default attributes of the device drivers on the bus.
- 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.
- Called when a device is added, removed, or a few other things that generate uevents to add the environment variables.
- Called when a new device or driver add to this bus, and callback the specific driver’s probe to initial the matched device.
- Called when a device removed from this bus.
- Called at shut-down time to quiesce the device.
- Called to put the device back online (after offlining it).
- Called to put the device offline for hot-removal. May fail.
- Called when a device on this bus wants to go to sleep mode.
- Called to bring a device on this bus out of sleep mode.
- Power management operations of this bus, callback the specific device driver’s pm-ops.
- IOMMU specific operations for this bus, used to attach IOMMU driver implementations to a bus and allow the driver to do bus-specific setup
- The private data of the driver core, only the driver core can touch this.
- Lock class key for use by the lock validator
name
dev_name
dev_root
dev_attrs
bus_groups
dev_groups
drv_groups
match
uevent
probe
remove
shutdown
online
offline
suspend
resume
pm
iommu_ops
p
lock_key
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
-
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.
probe_type
Constants
- Used by drivers that work equally well whether probed synchronously or asynchronously.
- Drivers for “slow” devices which probing order is not essential for booting the system may opt into executing their probes asynchronously.
- 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).
PROBE_DEFAULT_STRATEGY
PROBE_PREFER_ASYNCHRONOUS
PROBE_FORCE_SYNCHRONOUS
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
-
The basic device driver structure
device_driver
Definition
struct device_driver {
const char * name;
struct bus_type * bus;
struct module * owner;
const char * mod_name;
bool suppress_bind_attrs;
enum probe_type probe_type;
const struct of_device_id * of_match_table;
const struct acpi_device_id * acpi_match_table;
int (* probe) (struct device *dev);
int (* remove) (struct device *dev);
void (* shutdown) (struct device *dev);
int (* suspend) (struct device *dev, pm_message_t state);
int (* resume) (struct device *dev);
const struct attribute_group ** groups;
const struct dev_pm_ops * pm;
struct driver_private * p;
};
Members
- Name of the device driver.
- The bus which the device of this driver belongs to.
- The module owner.
- Used for built-in modules.
- Disables bind/unbind via sysfs.
- Type of the probe (synchronous or asynchronous) to use.
- The open firmware table.
- The ACPI match table.
- Called to query the existence of a specific device, whether this driver can work with it, and bind the driver to a specific device.
- Called when the device is removed from the system to unbind a device from this driver.
- Called at shut-down time to quiesce the device.
- Called to put the device to sleep mode. Usually to a low power state.
- Called to bring a device from sleep mode.
- Default attributes that get created by the driver core automatically.
- Power management operations of the device which matched this driver.
- Driver core’s private data, no one other than the driver core can touch this.
name
bus
owner
mod_name
suppress_bind_attrs
probe_type
of_match_table
acpi_match_table
probe
remove
shutdown
suspend
resume
groups
pm
p
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.
-
struct
-
interfaces to device functions
subsys_interface
Definition
struct subsys_interface {
const char * name;
struct bus_type * subsys;
struct list_head node;
int (* add_dev) (struct device *dev, struct subsys_interface *sif);
void (* remove_dev) (struct device *dev, struct subsys_interface *sif);
};
Members
- name of the device function
- subsytem of the devices to attach to
- the list of functions registered at the subsystem
- device hookup to device function handler
- device hookup to device function handler
name
subsys
node
add_dev
remove_dev
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 classes
class
Definition
struct class {
const char * name;
struct module * owner;
struct class_attribute * class_attrs;
const struct attribute_group ** class_groups;
const struct attribute_group ** dev_groups;
struct kobject * dev_kobj;
int (* dev_uevent) (struct device *dev, struct kobj_uevent_env *env);
char *(* devnode) (struct device *dev, umode_t *mode);
void (* class_release) (struct class *class);
void (* dev_release) (struct device *dev);
int (* suspend) (struct device *dev, pm_message_t state);
int (* resume) (struct device *dev);
const struct kobj_ns_type_operations * ns_type;
const void *(* namespace) (struct device *dev);
const struct dev_pm_ops * pm;
struct subsys_private * p;
};
Members
- Name of the class.
- The module owner.
- Default attributes of this class.
- Default attributes of this class.
- Default attributes of the devices that belong to the class.
- The kobject that represents this class and links it into the hierarchy.
- Called when a device is added, removed from this class, or a few other things that generate uevents to add the environment variables.
- Callback to provide the devtmpfs.
- Called to release this class.
- Called to release the device.
- Used to put the device to sleep mode, usually to a low power state.
- Used to bring the device from the sleep mode.
- Callbacks so sysfs can detemine namespaces.
- Namespace of the device belongs to this class.
- The default device power management operations of this class.
- The private data of the driver core, no one other than the driver core can touch this.
name
owner
class_attrs
class_groups
dev_groups
dev_kobj
dev_uevent
devnode
class_release
dev_release
suspend
resume
ns_type
namespace
pm
p
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.
-
Resource-managed alloc_percpu
devm_alloc_percpu
(
dev,
type
)
Parameters
- Device to allocate per-cpu memory for
- Type to allocate per-cpu memory for
dev
type
Description
Managed alloc_percpu. Per-cpu memory allocated with this function is automatically freed on driver detach.
Return
Pointer to allocated memory on success, NULL on failure.
-
enum
-
Device link states.
device_link_state
Constants
- The presence of the drivers is not being tracked.
- None of the supplier/consumer drivers is present.
- The supplier driver is present, but the consumer is not.
- The consumer is probing (supplier driver present).
- Both the supplier and consumer drivers are present.
- The supplier driver is unbinding.
DL_STATE_NONE
DL_STATE_DORMANT
DL_STATE_AVAILABLE
DL_STATE_CONSUMER_PROBE
DL_STATE_ACTIVE
DL_STATE_SUPPLIER_UNBIND
-
struct
-
Device link representation.
device_link
Definition
struct device_link {
struct device * supplier;
struct list_head s_node;
struct device * consumer;
struct list_head c_node;
enum device_link_state status;
u32 flags;
bool rpm_active;
#ifdef CONFIG_SRCU
struct rcu_head rcu_head;
#endif
};
Members
- The device on the supplier end of the link.
- Hook to the supplier device’s list of links to consumers.
- The device on the consumer end of the link.
- Hook to the consumer device’s list of links to suppliers.
- The state of the link (with respect to the presence of drivers).
- Link flags.
- Whether or not the consumer device is runtime-PM-active.
- An RCU head to use for deferred execution of SRCU callbacks.
supplier
s_node
consumer
c_node
status
flags
rpm_active
rcu_head
-
enum
-
Device driver presence tracking information.
dl_dev_state
Constants
- There is no driver attached to the device.
- A driver is probing.
- The driver has been bound to the device.
- The driver is unbinding from the device.
DL_DEV_NO_DRIVER
DL_DEV_PROBING
DL_DEV_DRIVER_BOUND
DL_DEV_UNBINDING
-
struct
-
Device data related to device links.
dev_links_info
Definition
struct dev_links_info {
struct list_head suppliers;
struct list_head consumers;
enum dl_dev_state status;
};
Members
- List of links to supplier devices.
- List of links to consumer devices.
- Driver status information.
suppliers
consumers
status
-
struct
-
The basic device structure
device
Definition
struct device {
struct device * parent;
struct device_private * p;
struct kobject kobj;
const char * init_name;
const struct device_type * type;
struct mutex mutex;
struct bus_type * bus;
struct device_driver * driver;
void * platform_data;
void * driver_data;
struct dev_links_info links;
struct dev_pm_info power;
struct dev_pm_domain * pm_domain;
#ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN
struct irq_domain * msi_domain;
#endif
#ifdef CONFIG_PINCTRL
struct dev_pin_info * pins;
#endif
#ifdef CONFIG_GENERIC_MSI_IRQ
struct list_head msi_list;
#endif
#ifdef CONFIG_NUMA
int numa_node;
#endif
u64 * dma_mask;
u64 coherent_dma_mask;
unsigned long dma_pfn_offset;
struct device_dma_parameters * dma_parms;
struct list_head dma_pools;
struct dma_coherent_mem * dma_mem;
#ifdef CONFIG_DMA_CMA
struct cma * cma_area;
#endif
struct dev_archdata archdata;
struct device_node * of_node;
struct fwnode_handle * fwnode;
dev_t devt;
u32 id;
spinlock_t devres_lock;
struct list_head devres_head;
struct klist_node knode_class;
struct class * class;
const struct attribute_group ** groups;
void (* release) (struct device *dev);
struct iommu_group * iommu_group;
struct iommu_fwspec * iommu_fwspec;
bool offline_disabled:1;
bool offline:1;
};
Members
- 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.
- Holds the private data of the driver core portions of the device. See the comment of the struct device_private for detail.
- A top-level, abstract class from which other classes are derived.
- Initial name of the device.
- The type of device. This identifies the device type and carries type-specific information.
- Mutex to synchronize calls to its driver.
- Type of bus device is on.
- Which driver has allocated this
- Platform data specific to the device.
- Private pointer for driver specific info.
- Links to suppliers and consumers of this device.
- For device power management. See Documentation/power/admin-guide/devices.rst for details.
- Provide callbacks that are executed during system suspend, hibernation, system resume and during runtime PM transitions along with subsystem-level and driver-level callbacks.
- The generic MSI domain this device is using.
- For device pin management. See Documentation/pinctrl.txt for details.
- Hosts MSI descriptors
- NUMA node this device is close to.
- Dma mask (if dma’ble device).
- Like dma_mask, but for alloc_coherent mapping as not all hardware supports 64-bit addresses for consistent allocations such descriptors.
- offset of DMA memory range relatively of RAM
- A low level driver may set these to teach IOMMU code about segment limitations.
- Dma pools (if dma’ble device).
- Internal for coherent mem override.
- Contiguous memory area for dma allocations
- For arch-specific additions.
- Associated device tree node.
- Associated device node supplied by platform firmware.
- For creating the sysfs “dev”.
- device instance
- Spinlock to protect the resource of the device.
- The resources list of the device.
- The node used to add the device to the class list.
- The class of the device.
- Optional attribute groups.
- 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 the device belongs to.
- IOMMU-specific properties supplied by firmware.
- If set, the device is permanently online.
- Set after successful invocation of bus type’s .:c:func: offline().
parent
p
kobj
init_name
type
mutex
bus
driver
platform_data
driver_data
links
power
pm_domain
msi_domain
pins
msi_list
numa_node
dma_mask
coherent_dma_mask
dma_pfn_offset
dma_parms
dma_pools
dma_mem
cma_area
archdata
of_node
fwnode
devt
id
devres_lock
devres_head
knode_class
class
groups
release
iommu_group
iommu_fwspec
offline_disabled
offline
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.
-
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()
andmodule_exit()
.
module_driver
(
__driver,
__register,
__unregister,
...
)
Parameters
- driver name
- register function for this driver type
- unregister function for this driver type
- Additional arguments to be passed to __register and __unregister.
__driver
__register
__unregister
...
Description
Use this macro to construct bus specific macros for registering drivers, and do not use it on its own.
-
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.
builtin_driver
(
__driver,
__register,
...
)
Parameters
- driver name
- register function for this driver type
- Additional arguments to be passed to __register
__driver
__register
...
Description
Use this macro to construct bus specific macros for registering drivers, and do not use it on its own.
Device Drivers Base
-
void
-
initialize driver model.
driver_init
(void
)
Parameters
- no arguments
void
Description
Call the driver model init functions to initialize their subsystems. Called early from init/main.c.
-
int
-
Iterator for devices bound to a driver.
driver_for_each_device
(struct
device_driver
*
drv, struct
device
*
start, void *
data, int (*fn) (struct
device
*, void
*
)
Parameters
- Driver we’re iterating.
- Device to begin with
- Data to pass to the callback.
- Function to call for each device.
struct device_driver * drv
struct device * start
void * data
int (*)(struct device *, void *) fn
Description
Iterate over the drv‘s list of devices calling fn for each one.
-
struct
device
*
-
device iterator for locating a particular device.
driver_find_device
(struct
device_driver
*
drv, struct
device
*
start, void *
data, int (*match) (struct
device
*dev, void
*data
)
Parameters
- The device’s driver
- Device to begin with
- Data to pass to match function
- Callback function to check device
struct device_driver * drv
struct device * start
void * data
int (*)(struct device *dev, void *data) match
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.
-
int
-
create sysfs file for driver.
driver_create_file
(struct
device_driver
*
drv, const struct driver_attribute *
attr
)
Parameters
- driver.
- driver attribute descriptor.
struct device_driver * drv
const struct driver_attribute * attr
-
void
-
remove sysfs file for driver.
driver_remove_file
(struct
device_driver
*
drv, const struct driver_attribute *
attr
)
Parameters
- driver.
- driver attribute descriptor.
struct device_driver * drv
const struct driver_attribute * attr
-
int
-
register driver with bus
driver_register
(struct
device_driver
*
drv
)
Parameters
- driver to register
struct device_driver * drv
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.
-
void
-
remove driver from system.
driver_unregister
(struct
device_driver
*
drv
)
Parameters
- driver.
struct device_driver * drv
Description
Again, we pass off most of the work to the bus-level call.
-
struct
device_driver
*
-
locate driver on a bus by its name.
driver_find
(const char *
name, struct
bus_type
*
bus
)
Parameters
- name of the driver.
- bus to scan for the driver.
const char * name
struct bus_type * bus
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.
-
struct
device_link
*
-
Create a link between two devices.
device_link_add
(struct
device
*
consumer, struct
device
*
supplier, u32
flags
)
Parameters
- Consumer end of the link.
- Supplier end of the link.
- Link flags.
struct device * consumer
struct device * supplier
u32 flags
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 metastate 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 the DL_FLAG_AUTOREMOVE is set, the link will be removed automatically when the consumer device driver unbinds from it. The combination of both DL_FLAG_AUTOREMOVE and DL_FLAG_STATELESS set is invalid and will cause NULL to be returned.
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.
-
void
-
Delete a link between two devices.
device_link_del
(struct
device_link
*
link
)
Parameters
- Device link to delete.
struct device_link * link
Description
The caller must ensure proper synchronization of this function with runtime PM.
-
const char *
-
Return a device’s driver name, if at all possible
dev_driver_string
(const struct
device
*
dev
)
Parameters
- struct device to get the name of
const struct device * dev
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.
-
int
-
create sysfs attribute file for device.
device_create_file
(struct
device
*
dev, const struct device_attribute *
attr
)
Parameters
- device.
- device attribute descriptor.
struct device * dev
const struct device_attribute * attr
-
void
-
remove sysfs attribute file.
device_remove_file
(struct
device
*
dev, const struct device_attribute *
attr
)
Parameters
- device.
- device attribute descriptor.
struct device * dev
const struct device_attribute * attr
-
bool
-
remove sysfs attribute file from its own method.
device_remove_file_self
(struct
device
*
dev, const struct device_attribute *
attr
)
Parameters
- device.
- device attribute descriptor.
struct device * dev
const struct device_attribute * attr
Description
See kernfs_remove_self()
for details.
-
int
-
create sysfs binary attribute file for device.
device_create_bin_file
(struct
device
*
dev, const struct bin_attribute *
attr
)
Parameters
- device.
- device binary attribute descriptor.
struct device * dev
const struct bin_attribute * attr
-
void
-
remove sysfs binary attribute file
device_remove_bin_file
(struct
device
*
dev, const struct bin_attribute *
attr
)
Parameters
- device.
- device binary attribute descriptor.
struct device * dev
const struct bin_attribute * attr
-
void
-
init device structure.
device_initialize
(struct
device
*
dev
)
Parameters
- device.
struct device * dev
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.
-
int
-
set a device name
dev_set_name
(struct
device
*
dev, const char *
fmt, ...
)
Parameters
- device
- format string for the device’s name
- variable arguments
struct device * dev
const char * fmt
...
-
int
-
add device to device hierarchy.
device_add
(struct
device
*
dev
)
Parameters
- device.
struct device * dev
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.
-
int
-
register a device with the system.
device_register
(struct
device
*
dev
)
Parameters
- pointer to the device structure
struct device * dev
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.
Parameters
- device.
struct device * dev
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.
-
void
-
decrement reference count.
put_device
(struct
device
*
dev
)
Parameters
- device in question.
struct device * dev
-
void
-
delete device from system.
device_del
(struct
device
*
dev
)
Parameters
- device.
struct device * dev
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.
-
void
-
unregister device from system.
device_unregister
(struct
device
*
dev
)
Parameters
- device going away.
struct device * dev
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.
-
int
-
device child iterator.
device_for_each_child
(struct
device
*
parent, void *
data, int (*fn) (struct
device
*dev, void
*data
)
Parameters
- parent struct device.
- data for the callback.
- function to be called for each device.
struct device * parent
void * data
int (*)(struct device *dev, void *data) fn
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.
-
int
-
device child iterator in reversed order.
device_for_each_child_reverse
(struct
device
*
parent, void *
data, int (*fn) (struct
device
*dev, void
*data
)
Parameters
- parent struct device.
- data for the callback.
- function to be called for each device.
struct device * parent
void * data
int (*)(struct device *dev, void *data) fn
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.
-
struct
device
*
-
device iterator for locating a particular device.
device_find_child
(struct
device
*
parent, void *
data, int (*match) (struct
device
*dev, void
*data
)
Parameters
- parent struct device
- Data to pass to match function
- Callback function to check device
struct device * parent
void * data
int (*)(struct device *dev, void *data) match
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.
-
struct
device
*
-
allocate and register a root device
__root_device_register
(const char *
name, struct module *
owner
)
Parameters
- root device name
- owner module of the root device, usually THIS_MODULE
const char * name
struct module * owner
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()
.
-
void
-
unregister and free a root device
root_device_unregister
(struct
device
*
dev
)
Parameters
- device going away
struct device * dev
Description
This function unregisters and cleans up a device that was created by root_device_register()
.
-
struct
device
*
-
creates a device and registers it with sysfs
device_create_vargs
(struct
class
*
class, struct
device
*
parent, dev_t
devt, void *
drvdata, const char *
fmt, va_list
args
)
Parameters
- pointer to the struct class that this device should be registered to
- pointer to the parent struct device of this new device, if any
- the dev_t for the char device to be added
- the data to be added to the device for callbacks
- string for the device’s name
- va_list for the device’s name
struct class * class
struct device * parent
dev_t devt
void * drvdata
const char * fmt
va_list args
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.
Note
the struct class passed to this function must have previously been created with a call to class_create()
.
-
struct
device
*
-
creates a device and registers it with sysfs
device_create
(struct
class
*
class, struct
device
*
parent, dev_t
devt, void *
drvdata, const char *
fmt, ...
)
Parameters
- pointer to the struct class that this device should be registered to
- pointer to the parent struct device of this new device, if any
- the dev_t for the char device to be added
- the data to be added to the device for callbacks
- string for the device’s name
- variable arguments
struct class * class
struct device * parent
dev_t devt
void * drvdata
const char * fmt
...
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.
Note
the struct class passed to this function must have previously been created with a call to class_create()
.
-
struct
device
*
-
creates a device and registers it with sysfs
device_create_with_groups
(struct
class
*
class, struct
device
*
parent, dev_t
devt, void *
drvdata, const struct attribute_group **
groups, const char *
fmt, ...
)
Parameters
- pointer to the struct class that this device should be registered to
- pointer to the parent struct device of this new device, if any
- the dev_t for the char device to be added
- the data to be added to the device for callbacks
- NULL-terminated list of attribute groups to be created
- string for the device’s name
- variable arguments
struct class * class
struct device * parent
dev_t devt
void * drvdata
const struct attribute_group ** groups
const char * fmt
...
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.
Note
the struct class passed to this function must have previously been created with a call to class_create()
.
-
void
-
removes a device that was created with
device_create()
device_destroy
(struct
class
*
class, dev_t
devt
)
Parameters
- pointer to the struct class that this device was registered with
- the dev_t of the device that was previously registered
struct class * class
dev_t devt
Description
This call unregisters and cleans up a device that was created with a call to device_create()
.
-
int
-
renames a device
device_rename
(struct
device
*
dev, const char *
new_name
)
Parameters
- the pointer to the struct device to be renamed
- the new name of the device
struct device * dev
const char * new_name
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
Don’t call this function. Currently, the networking layer calls this function, but that will change. 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.
We are currently about to change network renaming in udev to completely disallow renaming of devices in the same namespace as the kernel uses, because we can’t solve the problems properly, that arise with swapping names of multiple interfaces without races. Means, renaming of eth[0-9]* will only be allowed to some other name than eth[0-9]*, for the aforementioned reasons.
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. :)
-
int
-
moves a device to a new parent
device_move
(struct
device
*
dev, struct
device
*
new_parent, enum dpm_order
dpm_order
)
Parameters
- the pointer to the struct device to be moved
- the new parent of the device (can by NULL)
- how to reorder the dpm_list
struct device * dev
struct device * new_parent
enum dpm_order dpm_order
-
void
-
Change the primary firmware node of a given device.
set_primary_fwnode
(struct
device
*
dev, struct fwnode_handle *
fwnode
)
Parameters
- Device to handle.
- New primary firmware node of the device.
struct device * dev
struct fwnode_handle * fwnode
Description
Set the device’s firmware node pointer to fwnode, but if a secondary firmware node of the device is present, preserve it.
-
void
-
Register a set of system core operations.
register_syscore_ops
(struct syscore_ops *
ops
)
Parameters
- System core operations to register.
struct syscore_ops * ops
-
void
-
Unregister a set of system core operations.
unregister_syscore_ops
(struct syscore_ops *
ops
)
Parameters
- System core operations to unregister.
struct syscore_ops * ops
-
int
-
Execute all the registered system core suspend callbacks.
syscore_suspend
(void
)
Parameters
- no arguments
void
Description
This function is executed with one CPU on-line and disabled interrupts.
-
void
-
Execute all the registered system core resume callbacks.
syscore_resume
(void
)
Parameters
- no arguments
void
Description
This function is executed with one CPU on-line and disabled interrupts.
-
struct
class
*
-
create a struct class structure
__class_create
(struct module *
owner, const char *
name, struct lock_class_key *
key
)
Parameters
- pointer to the module that is to “own” this struct class
- pointer to a string for the name of this class.
- the lock_class_key for this class; used by mutex lock debugging
struct module * owner
const char * name
struct lock_class_key * key
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()
.
-
void
-
destroys a struct class structure
class_destroy
(struct
class
*
cls
)
Parameters
- pointer to the struct class that is to be destroyed
struct class * cls
Description
Note, the pointer to be destroyed must have been created with a call to class_create()
.
-
void
-
initialize class device iterator
class_dev_iter_init
(struct class_dev_iter *
iter, struct
class
*
class, struct
device
*
start, const struct device_type *
type
)
Parameters
- class iterator to initialize
- the class we wanna iterate over
- the device to start iterating from, if any
- device_type of the devices to iterate over, NULL for all
struct class_dev_iter * iter
struct class * class
struct device * start
const struct device_type * type
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.
-
struct
device
*
-
iterate to the next device
class_dev_iter_next
(struct class_dev_iter *
iter
)
Parameters
- class iterator to proceed
struct class_dev_iter * iter
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.
-
void
-
finish iteration
class_dev_iter_exit
(struct class_dev_iter *
iter
)
Parameters
- class iterator to finish
struct class_dev_iter * iter
Description
Finish an iteration. Always call this function after iteration is complete whether the iteration ran till the end or not.
-
int
-
device iterator
class_for_each_device
(struct
class
*
class, struct
device
*
start, void *
data, int (*fn) (struct
device
*, void
*
)
Parameters
- the class we’re iterating
- the device to start with in the list, if any.
- data for the callback
- function to be called for each device
struct class * class
struct device * start
void * data
int (*)(struct device *, void *) fn
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.
-
struct
device
*
-
device iterator for locating a particular device
class_find_device
(struct
class
*
class, struct
device
*
start, const void *
data, int (*match) (struct
device
*, const void
*
)
Parameters
- the class we’re iterating
- Device to begin with
- data for the match function
- function to check device
struct class * class
struct device * start
const void * data
int (*)(struct device *, const void *) match
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 thematch 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.
-
struct class_compat *
-
register a compatibility class
class_compat_register
(const char *
name
)
Parameters
- the name of the class
const char * name
Description
Compatibility class are meant as a temporary user-space compatibility workaround when converting a family of class devices to a bus devices.
-
void
-
unregister a compatibility class
class_compat_unregister
(struct class_compat *
cls
)
Parameters
- the class to unregister
struct class_compat * cls
-
int
-
create a compatibility class device link to a bus device
class_compat_create_link
(struct class_compat *
cls, struct
device
*
dev, struct
device
*
device_link
)
Parameters
- the compatibility class
- the target bus device
- an optional device to which a “device” link should be created
struct class_compat * cls
struct device * dev
struct device * device_link
-
void
-
remove a compatibility class device link to a bus device
class_compat_remove_link
(struct class_compat *
cls, struct
device
*
dev, struct
device
*
device_link
)
Parameters
- the compatibility class
- the target bus device
- an optional device to which a “device” link was previously created
struct class_compat * cls
struct device * dev
struct device * device_link
-
void
-
unregister a node device
unregister_node
(struct node *
node
)
Parameters
- node going away
struct node * node
Description
Unregisters a node device node. All the devices on the node must be unregistered before calling this function.
-
int
-
send firmware request and wait for it
request_firmware
(const struct firmware **
firmware_p, const char *
name, struct
device
*
device
)
Parameters
- pointer to firmware image
- name of firmware file
- device for which firmware is being loaded
const struct firmware ** firmware_p
const char * name
struct device * device
Description
firmware_p will be used to return a firmware image by the name of name for device device.
Should be called from user context where sleeping is allowed.
name will be used as $FIRMWARE in the uevent environment and should be distinctive enough not to be confused with any other firmware image for this or any other device.
Caller must hold the reference count of device.
The function can be called safely inside device’s suspend and resume callback.
-
int
-
load firmware directly without usermode helper
request_firmware_direct
(const struct firmware **
firmware_p, const char *
name, struct
device
*
device
)
Parameters
- pointer to firmware image
- name of firmware file
- device for which firmware is being loaded
const struct firmware ** firmware_p
const char * name
struct device * device
Description
This function works pretty much like request_firmware()
, but this doesn’t fall back to usermode helper even if the firmware couldn’t be loaded directly from fs. Hence it’s useful for loading optional firmwares, which aren’t always present, without extra long timeouts of udev.
-
int
-
load firmware into a previously allocated buffer
request_firmware_into_buf
(const struct firmware **
firmware_p, const char *
name, struct
device
*
device, void *
buf, size_t
size
)
Parameters
- pointer to firmware image
- name of firmware file
- device for which firmware is being loaded and DMA region allocated
- address of buffer to load firmware into
- size of buffer
const struct firmware ** firmware_p
const char * name
struct device * device
void * buf
size_t size
Description
This function works pretty much like request_firmware()
, but it doesn’t allocate a buffer to hold the firmware data. Instead, the firmware is loaded directly into the buffer pointed to by buf and the firmware_p data member is pointed at buf.
This function doesn’t cache firmware either.
-
void
-
release the resource associated with a firmware image
release_firmware
(const struct firmware *
fw
)
Parameters
- firmware resource to release
const struct firmware * fw
-
int
-
asynchronous version of request_firmware
request_firmware_nowait
(struct module *
module, bool
uevent, const char *
name, struct
device
*
device, gfp_t
gfp, void *
context, void (*cont) (const struct firmware
*fw, void
*context
)
Parameters
- module requesting the firmware
- sends uevent to copy the firmware image if this flag is non-zero else the firmware copy must be done manually.
- name of firmware file
- device for which firmware is being loaded
- allocation flags
-
will be passed over to
cont, and
fw
may be
NULL
if firmware request fails. - function will be called asynchronously when the firmware request is over.
struct module * module
bool uevent
const char * name
struct device * device
gfp_t gfp
void * context
void (*)(const struct firmware *fw, void *context) cont
Description
Caller must hold the reference count of device.
Asynchronous variant of
request_firmware()
for user contexts:
- sleep for as small periods as possible since it may increase kernel boot time of built-in device drivers requesting firmware in their ->:c:func:probe() methods, if gfp is GFP_KERNEL.
- can’t sleep at all if gfp is GFP_ATOMIC.
-
int
-
register an initial transport class
transport_class_register
(struct transport_class *
tclass
)
Parameters
- a pointer to the transport class structure to be initialised
struct transport_class * tclass
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.
-
void
-
unregister a previously registered class
transport_class_unregister
(struct transport_class *
tclass
)
Parameters
- The transport class to unregister
struct transport_class * tclass
Description
Must be called prior to deallocating the memory for the transport class.
-
int
-
register an anonymous class
anon_transport_class_register
(struct anon_transport_class *
atc
)
Parameters
- The anon transport class to register
struct anon_transport_class * atc
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 useDECLARE_ANON_TRANSPORT_CLASS()
to initialise the anon transport class storage.
-
void
-
unregister an anon class
anon_transport_class_unregister
(struct anon_transport_class *
atc
)
Parameters
- Pointer to the anon transport class to unregister
struct anon_transport_class * atc
Description
Must be called prior to deallocating the memory for the anon transport class.
-
void
-
declare a new dev for transport class association but don’t make it visible yet.
transport_setup_device
(struct
device
*
dev
)
Parameters
- the generic device representing the entity being added
struct device * dev
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).
-
void
-
declare a new dev for transport class association
transport_add_device
(struct
device
*
dev
)
Parameters
- the generic device representing the entity being added
struct device * dev
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.
-
void
-
configure an already set up device
transport_configure_device
(struct
device
*
dev
)
Parameters
- generic device representing device to be configured
struct device * dev
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.
-
void
-
remove the visibility of a device
transport_remove_device
(struct
device
*
dev
)
Parameters
- generic device to remove
struct device * dev
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.
-
void
-
destroy a removed device
transport_destroy_device
(struct
device
*
dev
)
Parameters
- device to eliminate from the transport class.
struct device * dev
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.
-
int
-
bind a driver to one device.
device_bind_driver
(struct
device
*
dev
)
Parameters
- device.
struct device * dev
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 nor take the bus’s rwsem. Please verify those are 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.
-
void
-
wait_for_device_probe
(void
)
Parameters
- no arguments
void
Description
Wait for device probing to be completed.
-
int
-
try to attach device to a driver.
device_attach
(struct
device
*
dev
)
Parameters
- device.
struct device * dev
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.
-
int
-
try to bind driver to devices.
driver_attach
(struct
device_driver
*
drv
)
Parameters
- driver.
struct device_driver * drv
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.
-
void
-
manually detach device from driver.
device_release_driver
(struct
device
*
dev
)
Parameters
- device.
struct device * dev
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.
-
struct platform_device *
-
add a platform-level device with resources and platform-specific data
platform_device_register_resndata
(struct
device
*
parent, const char *
name, int
id, const struct resource *
res, unsigned int
num, const void *
data, size_t
size
)
Parameters
- parent device for the device we’re adding
- base name of the device we’re adding
- instance id
- set of resources that needs to be allocated for the device
- number of resources
- platform specific data for this platform device
- size of platform specific data
struct device * parent
const char * name
int id
const struct resource * res
unsigned int num
const void * data
size_t size
Description
Returns struct platform_device
pointer on success, or ERR_PTR()
on error.
-
struct platform_device *
-
add a platform-level device and its resources
platform_device_register_simple
(const char *
name, int
id, const struct resource *
res, unsigned int
num
)
Parameters
- base name of the device we’re adding
- instance id
- set of resources that needs to be allocated for the device
- number of resources
const char * name
int id
const struct resource * res
unsigned int num
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.
-
struct platform_device *
-
add a platform-level device with platform-specific data
platform_device_register_data
(struct
device
*
parent, const char *
name, int
id, const void *
data, size_t
size
)
Parameters
- parent device for the device we’re adding
- base name of the device we’re adding
- instance id
- platform specific data for this platform device
- size of platform specific data
struct device * parent
const char * name
int id
const void * data
size_t size
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.
-
struct resource *
-
get a resource for a device
platform_get_resource
(struct platform_device *
dev, unsigned int
type, unsigned int
num
)
Parameters
- platform device
- resource type
- resource index
struct platform_device * dev
unsigned int type
unsigned int num
-
int
-
get an IRQ for a device
platform_get_irq
(struct platform_device *
dev, unsigned int
num
)
Parameters
- platform device
- IRQ number index
struct platform_device * dev
unsigned int num
-
int
-
Count the number of IRQs a platform device uses
platform_irq_count
(struct platform_device *
dev
)
Parameters
- platform device
struct platform_device * dev
Return
Number of IRQs a platform device uses or EPROBE_DEFER
-
struct resource *
-
get a resource for a device by name
platform_get_resource_byname
(struct platform_device *
dev, unsigned int
type, const char *
name
)
Parameters
- platform device
- resource type
- resource name
struct platform_device * dev
unsigned int type
const char * name
-
int
-
get an IRQ for a device by name
platform_get_irq_byname
(struct platform_device *
dev, const char *
name
)
Parameters
- platform device
- IRQ name
struct platform_device * dev
const char * name
-
int
-
add a numbers of platform devices
platform_add_devices
(struct platform_device **
devs, int
num
)
Parameters
- array of platform devices to add
- number of platform devices in array
struct platform_device ** devs
int num
-
void
-
destroy a platform device
platform_device_put
(struct platform_device *
pdev
)
Parameters
- platform device to free
struct platform_device * pdev
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.
-
struct platform_device *
-
create a platform device
platform_device_alloc
(const char *
name, int
id
)
Parameters
- base name of the device we’re adding
- instance id
const char * name
int 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.
-
int
-
add resources to a platform device
platform_device_add_resources
(struct platform_device *
pdev, const struct resource *
res, unsigned int
num
)
Parameters
- platform device allocated by platform_device_alloc to add resources to
- set of resources that needs to be allocated for the device
- number of resources
struct platform_device * pdev
const struct resource * res
unsigned int num
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.
-
int
-
add platform-specific data to a platform device
platform_device_add_data
(struct platform_device *
pdev, const void *
data, size_t
size
)
Parameters
- platform device allocated by platform_device_alloc to add resources to
- platform specific data for this platform device
- size of platform specific data
struct platform_device * pdev
const void * data
size_t size
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.
-
int
-
add built-in properties to a platform device
platform_device_add_properties
(struct platform_device *
pdev, struct property_entry *
properties
)
Parameters
- platform device to add properties to
- null terminated array of properties to add
struct platform_device * pdev
struct property_entry * properties
Description
The function will take deep copy of properties and attach the copy to the platform device. The memory associated with properties will be freed when the platform device is released.
-
int
-
add a platform device to device hierarchy
platform_device_add
(struct platform_device *
pdev
)
Parameters
- platform device we’re adding
struct platform_device * pdev
Description
This is part 2 of platform_device_register()
, though may be called separately _iff_ pdev was allocated by platform_device_alloc()
.
-
void
-
remove a platform-level device
platform_device_del
(struct platform_device *
pdev
)
Parameters
- platform device we’re removing
struct platform_device * pdev
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.
-
int
-
add a platform-level device
platform_device_register
(struct platform_device *
pdev
)
Parameters
- platform device we’re adding
struct platform_device * pdev
-
void
-
unregister a platform-level device
platform_device_unregister
(struct platform_device *
pdev
)
Parameters
- platform device we’re unregistering
struct platform_device * pdev
Description
Unregistration is done in 2 steps. First we release all resources and remove it from the subsystem, then we drop reference count by callingplatform_device_put()
.
-
struct platform_device *
-
add a platform-level device with resources and platform-specific data
platform_device_register_full
(const struct platform_device_info *
pdevinfo
)
Parameters
- data used to create device
const struct platform_device_info * pdevinfo
Description
Returns struct platform_device
pointer on success, or ERR_PTR()
on error.
-
int
-
register a driver for platform-level devices
__platform_driver_register
(struct platform_driver *
drv, struct module *
owner
)
Parameters
- platform driver structure
- owning module/driver
struct platform_driver * drv
struct module * owner
-
void
-
unregister a driver for platform-level devices
platform_driver_unregister
(struct platform_driver *
drv
)
Parameters
- platform driver structure
struct platform_driver * drv
-
int
-
register driver for non-hotpluggable device
__platform_driver_probe
(struct platform_driver *
drv, int (*probe) (struct platform_device
*, struct module *
module
)
Parameters
- platform driver structure
- the driver probe routine, probably from an __init section
- module which will be the owner of the driver
struct platform_driver * drv
int (*)(struct platform_device *) probe
struct module * module
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.
-
struct platform_device *
-
register driver and create corresponding device
__platform_create_bundle
(struct platform_driver *
driver, int (*probe) (struct platform_device
*, struct resource *
res, unsigned int
n_res, const void *
data, size_t
size, struct module *
module
)
Parameters
- platform driver structure
- the driver probe routine, probably from an __init section
- set of resources that needs to be allocated for the device
- number of resources
- platform specific data for this platform device
- size of platform specific data
- module which will be the owner of the driver
struct platform_driver * driver
int (*)(struct platform_device *) probe
struct resource * res
unsigned int n_res
const void * data
size_t size
struct module * module
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.
-
int
-
register an array of platform drivers
__platform_register_drivers
(struct platform_driver *const *
drivers, unsigned int
count, struct module *
owner
)
Parameters
- an array of drivers to register
- the number of drivers to register
- module owning the drivers
struct platform_driver *const * drivers
unsigned int count
struct module * owner
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.
-
void
-
unregister an array of platform drivers
platform_unregister_drivers
(struct platform_driver *const *
drivers, unsigned int
count
)
Parameters
- an array of drivers to unregister
- the number of drivers to unregister
struct platform_driver *const * drivers
unsigned int count
Description
Unegisters 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.
-
int
-
device iterator.
bus_for_each_dev
(struct
bus_type
*
bus, struct
device
*
start, void *
data, int (*fn) (struct
device
*, void
*
)
Parameters
- bus type.
- device to start iterating from.
- data for the callback.
- function to be called for each device.
struct bus_type * bus
struct device * start
void * data
int (*)(struct device *, void *) fn
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.
-
struct
device
*
-
device iterator for locating a particular device.
bus_find_device
(struct
bus_type
*
bus, struct
device
*
start, void *
data, int (*match) (struct
device
*dev, void
*data
)
Parameters
- bus type
- Device to begin with
- Data to pass to match function
- Callback function to check device
struct bus_type * bus
struct device * start
void * data
int (*)(struct device *dev, void *data) match
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 thematch 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.
-
struct
device
*
-
device iterator for locating a particular device of a specific name
bus_find_device_by_name
(struct
bus_type
*
bus, struct
device
*
start, const char *
name
)
Parameters
- bus type
- Device to begin with
- name of the device to match
struct bus_type * bus
struct device * start
const char * name
Description
This is similar to the bus_find_device()
function above, but it handles searching by a name automatically, no need to write another strcmp matching function.
-
struct
device
*
-
find a device with a specific enumeration number
subsys_find_device_by_id
(struct
bus_type
*
subsys, unsigned int
id, struct
device
*
hint
)
Parameters
- subsystem
- index ‘id’ in struct device
- device to check first
struct bus_type * subsys
unsigned int id
struct device * hint
Description
Check the hint’s next object and if it is a match return it directly, otherwise, fall back to a full list search. Either way a reference for the returned object is taken.
-
int
-
driver iterator
bus_for_each_drv
(struct
bus_type
*
bus, struct
device_driver
*
start, void *
data, int (*fn) (struct
device_driver
*, void
*
)
Parameters
- bus we’re dealing with.
- driver to start iterating on.
- data to pass to the callback.
- function to call for each driver.
struct bus_type * bus
struct device_driver * start
void * data
int (*)(struct device_driver *, void *) fn
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.
-
int
-
rescan devices on the bus for possible drivers
bus_rescan_devices
(struct
bus_type
*
bus
)
Parameters
- the bus to scan.
struct bus_type * bus
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 callingdevice_attach()
for the unbound devices.
-
int
-
remove driver for a device and probe for a new driver
device_reprobe
(struct
device
*
dev
)
Parameters
- the device to reprobe
struct device * dev
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.
-
int
-
register a driver-core subsystem
bus_register
(struct
bus_type
*
bus
)
Parameters
- bus to register
struct bus_type * bus
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.
-
void
-
remove a bus from the system
bus_unregister
(struct
bus_type
*
bus
)
Parameters
- bus.
struct bus_type * bus
Description
Unregister the child subsystems and the bus itself. Finally, we call bus_put()
to release the refcount
-
void
-
initialize subsys device iterator
subsys_dev_iter_init
(struct subsys_dev_iter *
iter, struct
bus_type
*
subsys, struct
device
*
start, const struct device_type *
type
)
Parameters
- subsys iterator to initialize
- the subsys we wanna iterate over
- the device to start iterating from, if any
- device_type of the devices to iterate over, NULL for all
struct subsys_dev_iter * iter
struct bus_type * subsys
struct device * start
const struct device_type * type
Description
Initialize subsys iterator iter such that it iterates over devices of subsys. If start is set, the list iteration will start there, otherwise if it is NULL, the iteration starts at the beginning of the list.
-
struct
device
*
-
iterate to the next device
subsys_dev_iter_next
(struct subsys_dev_iter *
iter
)
Parameters
- subsys iterator to proceed
struct subsys_dev_iter * iter
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 subsys code.
-
void
-
finish iteration
subsys_dev_iter_exit
(struct subsys_dev_iter *
iter
)
Parameters
- subsys iterator to finish
struct subsys_dev_iter * iter
Description
Finish an iteration. Always call this function after iteration is complete whether the iteration ran till the end or not.
-
int
-
register a subsystem at /sys/devices/system/
subsys_system_register
(struct
bus_type
*
subsys, const struct attribute_group **
groups
)
Parameters
- system subsystem
- default attributes for the root device
struct bus_type * subsys
const struct attribute_group ** groups
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>.
-
int
-
register a subsystem at /sys/devices/virtual/
subsys_virtual_register
(struct
bus_type
*
subsys, const struct attribute_group **
groups
)
Parameters
- virtual subsystem
- default attributes for the root device
struct bus_type * subsys
const struct attribute_group ** groups
Description
All ‘virtual’ subsystems have a /sys/devices/system/<name> root device with the name of the subystem. 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.
Device Drivers DMA Management
-
int
-
try to allocate memory from the per-device coherent area
dma_alloc_from_coherent
(struct
device
*
dev, ssize_t
size, dma_addr_t *
dma_handle, void **
ret
)
Parameters
- device from which we allocate memory
- size of requested memory area
- This will be filled with the correct dma handle
- This pointer will be filled with the virtual address to allocated area.
struct device * dev
ssize_t size
dma_addr_t * dma_handle
void ** ret
Description
This function should be only called from per-arch dma_alloc_coherent()
to support allocation from per-device coherent memory pools.
Returns 0 if dma_alloc_coherent should continue with allocating from generic memory areas, or !0 if dma_alloc_coherent should return ret.
-
int
-
try to free the memory allocated from per-device coherent memory pool
dma_release_from_coherent
(struct
device
*
dev, int
order, void *
vaddr
)
Parameters
- device from which the memory was allocated
- the order of pages allocated
- virtual address of allocated pages
struct device * dev
int order
void * vaddr
Description
This checks whether the memory was allocated from the per-device coherent memory pool and if so, releases that memory.
Returns 1 if we correctly released the memory, or 0 if dma_release_coherent()
should proceed with releasing memory from generic pools.
-
int
-
try to mmap the memory allocated from per-device coherent memory pool to userspace
dma_mmap_from_coherent
(struct
device
*
dev, struct vm_area_struct *
vma, void *
vaddr, size_t
size, int *
ret
)
Parameters
- device from which the memory was allocated
- vm_area for the userspace memory
- cpu address returned by dma_alloc_from_coherent
- size of the memory buffer allocated by dma_alloc_from_coherent
-
result from
remap_pfn_range()
struct device * dev
struct vm_area_struct * vma
void * vaddr
size_t size
int * ret
Description
This checks whether the memory was allocated from the per-device coherent memory pool and if so, maps that memory to the provided vma.
Returns 1 if we correctly mapped the memory, or 0 if the caller should proceed with mapping memory from generic pools.
-
void *
-
Managed
dma_alloc_coherent()
dmam_alloc_coherent
(struct
device
*
dev, size_t
size, dma_addr_t *
dma_handle, gfp_t
gfp
)
Parameters
- Device to allocate coherent memory for
- Size of allocation
- Out argument for allocated DMA handle
- Allocation flags
struct device * dev
size_t size
dma_addr_t * dma_handle
gfp_t gfp
Description
Managed dma_alloc_coherent()
. Memory allocated using this function will be automatically released on driver detach.
Return
Pointer to allocated memory on success, NULL on failure.
-
void
-
Managed
dma_free_coherent()
dmam_free_coherent
(struct
device
*
dev, size_t
size, void *
vaddr, dma_addr_t
dma_handle
)
Parameters
- Device to free coherent memory for
- Size of allocation
- Virtual address of the memory to free
- DMA handle of the memory to free
struct device * dev
size_t size
void * vaddr
dma_addr_t dma_handle
Description
Managed dma_free_coherent()
.
-
void *
-
Managed
dma_alloc_noncoherent()
dmam_alloc_noncoherent
(struct
device
*
dev, size_t
size, dma_addr_t *
dma_handle, gfp_t
gfp
)
Parameters
- Device to allocate non_coherent memory for
- Size of allocation
- Out argument for allocated DMA handle
- Allocation flags
struct device * dev
size_t size
dma_addr_t * dma_handle
gfp_t gfp
Description
Managed dma_alloc_noncoherent()
. Memory allocated using this function will be automatically released on driver detach.
Return
Pointer to allocated memory on success, NULL on failure.
-
void
-
Managed
dma_free_noncoherent()
dmam_free_noncoherent
(struct
device
*
dev, size_t
size, void *
vaddr, dma_addr_t
dma_handle
)
Parameters
- Device to free noncoherent memory for
- Size of allocation
- Virtual address of the memory to free
- DMA handle of the memory to free
struct device * dev
size_t size
void * vaddr
dma_addr_t dma_handle
Description
Managed dma_free_noncoherent()
.
-
int
-
Managed
dma_declare_coherent_memory()
dmam_declare_coherent_memory
(struct
device
*
dev, phys_addr_t
phys_addr, dma_addr_t
device_addr, size_t
size, int
flags
)
Parameters
- Device to declare coherent memory for
- Physical address of coherent memory to be declared
- Device address of coherent memory to be declared
- Size of coherent memory to be declared
- Flags
struct device * dev
phys_addr_t phys_addr
dma_addr_t device_addr
size_t size
int flags
Description
Managed dma_declare_coherent_memory()
.
Return
0 on success, -errno on failure.
-
void
-
Managed
dma_release_declared_memory()
.
dmam_release_declared_memory
(struct
device
*
dev
)
Parameters
- Device to release declared coherent memory for
struct device * dev
Description
Managed dmam_release_declared_memory()
.
Device Drivers Power Management
-
void
-
Execute “noirq” and “early” device callbacks.
dpm_resume_start
(pm_message_t
state
)
Parameters
- PM transition of the system being carried out.
pm_message_t state
-
void
-
Execute “resume” callbacks and complete system transition.
dpm_resume_end
(pm_message_t
state
)
Parameters
- PM transition of the system being carried out.
pm_message_t state
Description
Execute “resume” callbacks for all devices and complete the PM transition of the system.
-
int
-
Execute “late” and “noirq” device suspend callbacks.
dpm_suspend_end
(pm_message_t
state
)
Parameters
- PM transition of the system being carried out.
pm_message_t state
-
int
-
Prepare devices for PM transition and suspend them.
dpm_suspend_start
(pm_message_t
state
)
Parameters
- PM transition of the system being carried out.
pm_message_t state
Description
Prepare all non-sysdev devices for system PM transition and execute “suspend” callbacks for them.
-
int
-
Wait for suspend/resume of a device to complete.
device_pm_wait_for_dev
(struct
device
*
subordinate, struct
device
*
dev
)
Parameters
- Device that needs to wait for dev.
- Device to wait for.
struct device * subordinate
struct device * dev
-
void
-
device iterator.
dpm_for_each_dev
(void *
data, void (*fn) (struct
device
*, void
*
)
Parameters
- data for the callback.
- function to be called for each device.
void * data
void (*)(struct device *, void *) fn
Description
Iterate over devices in dpm_list, and call fn for each device, passing it data.
Device Drivers ACPI Support
-
void
-
Set-up DMA configuration for the device.
acpi_dma_configure
(struct
device
*
dev, enum dev_dma_attr
attr
)
Parameters
- The pointer to the device
- device dma attributes
struct device * dev
enum dev_dma_attr attr
-
void
-
Tear-down DMA configuration for the device.
acpi_dma_deconfigure
(struct
device
*
dev
)
Parameters
- The pointer to the device
struct device * dev
-
int
-
Add ACPI device node objects in a given namespace scope.
acpi_bus_scan
(acpi_handle
handle
)
Parameters
- Root of the namespace scope to scan.
acpi_handle handle
Description
Scan a given ACPI tree (probably recently hot-plugged) and create and add found devices.
If no devices were found, -ENODEV is returned, but it does not mean that there has been a real error. There just have been no suitable ACPI objects in the table trunk from which the kernel could create a device and add an appropriate driver.
Must be called under acpi_scan_lock.
-
void
-
Detach scan handlers and drivers from ACPI device objects.
acpi_bus_trim
(struct acpi_device *
adev
)
Parameters
- Root of the ACPI namespace scope to walk.
struct acpi_device * adev
Description
Must be called under acpi_scan_lock.
-
void
-
Drop an ACPI device object.
acpi_scan_drop_device
(acpi_handle
handle, void *
context
)
Parameters
- Handle of an ACPI namespace node, not used.
- Address of the ACPI device object to drop.
acpi_handle handle
void * context
Description
This is invoked by acpi_ns_delete_node()
during the removal of the ACPI namespace node the device object pointed to by context is attached to.
The unregistration is carried out asynchronously to avoid running acpi_device_del()
under the ACPICA’s namespace mutex and the list is used to ensure the correct ordering (the device objects must be unregistered in the same order in which the corresponding namespace nodes are deleted).
-
bool
-
Check DMA support for the specified device.
acpi_dma_supported
(struct acpi_device *
adev
)
Parameters
- The pointer to acpi device
struct acpi_device * adev
Description
Return false if DMA is not supported. Otherwise, return true
-
enum dev_dma_attr
-
Check the supported DMA attr for the specified device.
acpi_get_dma_attr
(struct acpi_device *
adev
)
Parameters
- The pointer to acpi device
struct acpi_device * adev
Description
Return enum dev_dma_attr.
Device drivers PnP support
-
int
-
adds a pnp protocol to the pnp layer
pnp_register_protocol
(struct pnp_protocol *
protocol
)
Parameters
- pointer to the corresponding pnp_protocol structure
struct pnp_protocol * protocol
Description
Ex protocols: ISAPNP, PNPBIOS, etc
-
void
-
removes a pnp protocol from the pnp layer
pnp_unregister_protocol
(struct pnp_protocol *
protocol
)
Parameters
- pointer to the corresponding pnp_protocol structure
struct pnp_protocol * protocol
-
struct pnp_dev *
-
Searches for a PnP device under the specified card
pnp_request_card_device
(struct pnp_card_link *
clink, const char *
id, struct pnp_dev *
from
)
Parameters
- pointer to the card link, cannot be NULL
- pointer to a PnP ID structure that explains the rules for finding the device
- Starting place to search from. If NULL it will start from the beginning.
struct pnp_card_link * clink
const char * id
struct pnp_dev * from
-
void
-
call this when the driver no longer needs the device
pnp_release_card_device
(struct pnp_dev *
dev
)
Parameters
- pointer to the PnP device structure
struct pnp_dev * dev
-
int
-
registers a PnP card driver with the PnP Layer
pnp_register_card_driver
(struct pnp_card_driver *
drv
)
Parameters
- pointer to the driver to register
struct pnp_card_driver * drv
-
void
-
unregisters a PnP card driver from the PnP Layer
pnp_unregister_card_driver
(struct pnp_card_driver *
drv
)
Parameters
- pointer to the driver to unregister
struct pnp_card_driver * drv
-
struct pnp_id *
-
adds an EISA id to the specified device
pnp_add_id
(struct pnp_dev *
dev, const char *
id
)
Parameters
- pointer to the desired device
- pointer to an EISA id string
struct pnp_dev * dev
const char * id
-
int
-
low-level start of the PnP device
pnp_start_dev
(struct pnp_dev *
dev
)
Parameters
- pointer to the desired device
struct pnp_dev * dev
Description
assumes that resources have already been allocated
-
int
-
low-level disable of the PnP device
pnp_stop_dev
(struct pnp_dev *
dev
)
Parameters
- pointer to the desired device
struct pnp_dev * dev
Description
does not free resources
-
int
-
activates a PnP device for use
pnp_activate_dev
(struct pnp_dev *
dev
)
Parameters
- pointer to the desired device
struct pnp_dev * dev
Description
does not validate or set resources so be careful.
-
int
-
disables device
pnp_disable_dev
(struct pnp_dev *
dev
)
Parameters
- pointer to the desired device
struct pnp_dev * dev
Description
inform the correct pnp protocol so that resources can be used by other devices
-
int
-
Determines if a device is active based on its current resources
pnp_is_active
(struct pnp_dev *
dev
)
Parameters
- pointer to the desired PnP device
struct pnp_dev * dev
Userspace IO devices
-
void
-
trigger an interrupt event
uio_event_notify
(struct
uio_info
*
info
)
Parameters
- UIO device capabilities
struct uio_info * info
-
int
-
register a new userspace IO device
__uio_register_device
(struct module *
owner, struct
device
*
parent, struct
uio_info
*
info
)
Parameters
- module that creates the new device
- parent device
- UIO device capabilities
struct module * owner
struct device * parent
struct uio_info * info
Description
returns zero on success or a negative error code.
-
void
-
unregister a industrial IO device
uio_unregister_device
(struct
uio_info
*
info
)
Parameters
- UIO device capabilities
struct uio_info * info
-
struct
-
description of a UIO memory region
uio_mem
Definition
struct uio_mem {
const char * name;
phys_addr_t addr;
resource_size_t size;
int memtype;
void __iomem * internal_addr;
struct uio_map * map;
};
Members
- name of the memory region for identification
- address of the device’s memory (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)
- size of IO
- type of memory addr points to
- ioremap-ped version of addr, for driver internal use
- for use by the UIO core only.
name
addr
size
memtype
internal_addr
map
-
struct
-
description of a UIO port region
uio_port
Definition
struct uio_port {
const char * name;
unsigned long start;
unsigned long size;
int porttype;
struct uio_portio * portio;
};
Members
- name of the port region for identification
- start of port region
- size of port region
- type of port (see UIO_PORT_* below)
- for use by the UIO core only.
name
start
size
porttype
portio
-
struct
-
UIO device capabilities
uio_info
Definition
struct uio_info {
struct uio_device * uio_dev;
const char * name;
const char * version;
struct uio_mem mem[MAX_UIO_MAPS];
struct uio_port port[MAX_UIO_PORT_REGIONS];
long irq;
unsigned long irq_flags;
void * priv;
irqreturn_t (* handler) (int irq, struct uio_info *dev_info);
int (* mmap) (struct uio_info *info, struct vm_area_struct *vma);
int (* open) (struct uio_info *info, struct inode *inode);
int (* release) (struct uio_info *info, struct inode *inode);
int (* irqcontrol) (struct uio_info *info, s32 irq_on);
};
Members
- the UIO device this info belongs to
- device name
- device driver version
- list of mappable memory regions, size==0 for end of list
- list of port regions, size==0 for end of list
- interrupt number or UIO_IRQ_CUSTOM
-
flags for
request_irq()
- optional private data
- the device’s irq handler
- mmap operation for this uio device
- open operation for this uio device
- release operation for this uio device
- disable/enable irqs when 0/1 is written to /dev/uioX
uio_dev
name
version
mem[MAX_UIO_MAPS]
port[MAX_UIO_PORT_REGIONS]
irq
irq_flags
priv
handler
mmap
open
release
irqcontrol