Lines Matching full:device
3 * device.h - generic, centralized driver model
30 #include <linux/device/bus.h>
31 #include <linux/device/class.h>
32 #include <linux/device/driver.h>
34 #include <asm/device.h>
36 struct device;
51 * struct subsys_interface - interfaces to device functions
52 * @name: name of the device function
55 * @add_dev: device hookup to device function handler
56 * @remove_dev: device hookup to device function handler
67 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
68 void (*remove_dev)(struct device *dev, struct subsys_interface *sif);
80 * The type of device, "struct device" is embedded in. A class
83 * This identifies the device type and carries type-specific
91 int (*uevent)(const struct device *dev, struct kobj_uevent_env *env);
92 char *(*devnode)(const struct device *dev, umode_t *mode,
94 void (*release)(struct device *dev);
100 * struct device_attribute - Interface for exporting device attributes.
107 ssize_t (*show)(struct device *dev, struct device_attribute *attr,
109 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
114 * struct dev_ext_attribute - Exported device attribute with extra context.
115 * @attr: Exported device attribute.
123 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
125 ssize_t device_store_ulong(struct device *dev, struct device_attribute *attr,
127 ssize_t device_show_int(struct device *dev, struct device_attribute *attr,
129 ssize_t device_store_int(struct device *dev, struct device_attribute *attr,
131 ssize_t device_show_bool(struct device *dev, struct device_attribute *attr,
133 ssize_t device_store_bool(struct device *dev, struct device_attribute *attr,
137 * DEVICE_ATTR - Define a device attribute.
159 * DEVICE_ATTR_PREALLOC - Define a preallocated device attribute.
172 * DEVICE_ATTR_RW - Define a read-write device attribute.
182 * DEVICE_ATTR_ADMIN_RW - Define an admin-only read-write device attribute.
191 * DEVICE_ATTR_RO - Define a readable device attribute.
200 * DEVICE_ATTR_ADMIN_RO - Define an admin-only readable device attribute.
209 * DEVICE_ATTR_WO - Define an admin-only writable device attribute.
218 * DEVICE_ULONG_ATTR - Define a device attribute backed by an unsigned long.
231 * DEVICE_INT_ATTR - Define a device attribute backed by an int.
243 * DEVICE_BOOL_ATTR - Define a device attribute backed by a bool.
258 int device_create_file(struct device *device,
260 void device_remove_file(struct device *dev,
262 bool device_remove_file_self(struct device *dev,
264 int __must_check device_create_bin_file(struct device *dev,
266 void device_remove_bin_file(struct device *dev,
269 /* device resource management */
270 typedef void (*dr_release_t)(struct device *dev, void *res);
271 typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data);
280 void devres_for_each_res(struct device *dev, dr_release_t release,
282 void (*fn)(struct device *, void *, void *),
285 void devres_add(struct device *dev, void *res);
286 void *devres_find(struct device *dev, dr_release_t release,
288 void *devres_get(struct device *dev, void *new_res,
290 void *devres_remove(struct device *dev, dr_release_t release,
292 int devres_destroy(struct device *dev, dr_release_t release,
294 int devres_release(struct device *dev, dr_release_t release,
298 void * __must_check devres_open_group(struct device *dev, void *id, gfp_t gfp);
299 void devres_close_group(struct device *dev, void *id);
300 void devres_remove_group(struct device *dev, void *id);
301 int devres_release_group(struct device *dev, void *id);
303 /* managed devm_k.alloc/kfree for device drivers */
304 void *devm_kmalloc(struct device *dev, size_t size, gfp_t gfp) __alloc_size(2);
305 void *devm_krealloc(struct device *dev, void *ptr, size_t size,
307 __printf(3, 0) char *devm_kvasprintf(struct device *dev, gfp_t gfp,
309 __printf(3, 4) char *devm_kasprintf(struct device *dev, gfp_t gfp,
311 static inline void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp) in devm_kzalloc()
315 static inline void *devm_kmalloc_array(struct device *dev, in devm_kmalloc_array()
325 static inline void *devm_kcalloc(struct device *dev, in devm_kcalloc()
331 devm_krealloc_array(struct device *dev, void *p, size_t new_n, size_t new_size, gfp_t flags) in devm_krealloc_array()
341 void devm_kfree(struct device *dev, const void *p);
342 char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc;
343 const char *devm_kstrdup_const(struct device *dev, const char *s, gfp_t gfp);
344 void *devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp)
347 unsigned long devm_get_free_pages(struct device *dev,
349 void devm_free_pages(struct device *dev, unsigned long addr);
352 void __iomem *devm_ioremap_resource(struct device *dev,
354 void __iomem *devm_ioremap_resource_wc(struct device *dev,
357 void __iomem *devm_of_iomap(struct device *dev,
363 void __iomem *devm_ioremap_resource(struct device *dev, in devm_ioremap_resource()
370 void __iomem *devm_ioremap_resource_wc(struct device *dev, in devm_ioremap_resource_wc()
377 void __iomem *devm_of_iomap(struct device *dev, in devm_of_iomap()
387 void devm_remove_action(struct device *dev, void (*action)(void *), void *data);
388 void devm_release_action(struct device *dev, void (*action)(void *), void *data);
390 int __devm_add_action(struct device *dev, void (*action)(void *), void *data, const char *name);
394 static inline int __devm_add_action_or_reset(struct device *dev, void (*action)(void *), in __devm_add_action_or_reset()
410 * @dev: Device to allocate per-cpu memory for
423 void __percpu *__devm_alloc_percpu(struct device *dev, size_t size,
425 void devm_free_percpu(struct device *dev, void __percpu *pdata);
438 * enum device_link_state - Device link states.
456 * Device link flags.
480 * enum dl_dev_state - Device driver presence tracking information.
481 * @DL_DEV_NO_DRIVER: There is no driver attached to the device.
483 * @DL_DEV_DRIVER_BOUND: The driver has been bound to the device.
484 * @DL_DEV_UNBINDING: The driver is unbinding from the device.
494 * enum device_removable - Whether the device is removable. The criteria for a
495 * device to be classified as removable is determined by its subsystem or bus.
497 * device (default).
498 * @DEVICE_REMOVABLE_UNKNOWN: Device location is Unknown.
499 * @DEVICE_FIXED: Device is not removable by the user.
500 * @DEVICE_REMOVABLE: Device is removable by the user.
510 * struct dev_links_info - Device data related to device links.
524 * struct dev_msi_info - Device data related to MSI
525 * @domain: The MSI interrupt domain associated to the device
526 * @data: Pointer to MSI device data
537 * system's housing the device connection point resides on.
538 * @DEVICE_PANEL_TOP: Device connection point is on the top panel.
539 * @DEVICE_PANEL_BOTTOM: Device connection point is on the bottom panel.
540 * @DEVICE_PANEL_LEFT: Device connection point is on the left panel.
541 * @DEVICE_PANEL_RIGHT: Device connection point is on the right panel.
542 * @DEVICE_PANEL_FRONT: Device connection point is on the front panel.
543 * @DEVICE_PANEL_BACK: Device connection point is on the back panel.
544 * @DEVICE_PANEL_UNKNOWN: The panel with device connection point is unknown.
558 * position of the device connection point on the panel surface.
559 * @DEVICE_VERT_POS_UPPER: Device connection point is at upper part of panel.
560 * @DEVICE_VERT_POS_CENTER: Device connection point is at center part of panel.
561 * @DEVICE_VERT_POS_LOWER: Device connection point is at lower part of panel.
571 * position of the device connection point on the panel surface.
572 * @DEVICE_HORI_POS_LEFT: Device connection point is at left part of panel.
573 * @DEVICE_HORI_POS_CENTER: Device connection point is at center part of panel.
574 * @DEVICE_HORI_POS_RIGHT: Device connection point is at right part of panel.
583 * struct device_physical_location - Device data related to physical location
584 * of the device connection point.
585 * @panel: Panel surface of the system's housing that the device connection
587 * @vertical_position: Vertical position of the device connection point within
589 * @horizontal_position: Horizontal position of the device connection point
591 * @dock: Set if the device connection point resides in a docking station or
593 * @lid: Set if this device connection point resides on the lid of laptop
605 * struct device - The basic device structure
606 * @parent: The device's "parent" device, the device to which it is attached.
607 * In most cases, a parent device is some sort of bus or host
608 * controller. If parent is NULL, the device, is a top-level device,
610 * @p: Holds the private data of the driver core portions of the device.
613 * @init_name: Initial name of the device.
614 * @type: The type of device.
615 * This identifies the device type and carries type-specific
618 * @bus: Type of bus device is on.
620 * @platform_data: Platform data specific to the device.
629 * @links: Links to suppliers and consumers of this device.
630 * @power: For device power management.
635 * @em_pd: device's energy model performance domain
636 * @pins: For device pin management.
639 * @numa_node: NUMA node this device is close to.
640 * @dma_ops: DMA mapping operations for this device.
641 * @dma_mask: Dma mask (if dma'ble device).
646 * DMA limit than the device itself supports.
650 * @dma_pools: Dma pools (if dma'ble device).
656 * @dma_uses_io_tlb: %true if device has used the software IO TLB.
658 * @of_node: Associated device tree node.
659 * @fwnode: Associated device node supplied by platform firmware.
661 * @id: device instance
662 * @devres_lock: Spinlock to protect the resource of the device.
663 * @devres_head: The resources list of the device.
664 * @class: The class of the device.
666 * @release: Callback to free the device after all references have
668 * device (i.e. the bus driver that discovered the device).
669 * @iommu_group: IOMMU group the device belongs to.
670 * @iommu: Per device generic IOMMU runtime data
671 * @physical_location: Describes physical location of the device connection
673 * @removable: Whether the device can be removed from the system. This
675 * the device.
677 * @offline_disabled: If set, the device is permanently online.
679 * @of_node_reused: Set if the device-tree node is shared with an ancestor
680 * device.
681 * @state_synced: The hardware state of this device has been synced to match
682 * the software state of this device by calling the driver/bus
684 * @can_match: The device has matched with a driver at least once or it is in
687 * @dma_coherent: this particular device is dma coherent, even if the
695 * At the lowest level, every device in a Linux system is represented by an
696 * instance of struct device. The device structure contains the information
697 * that the device model core needs to model the system. Most subsystems,
699 * result, it is rare for devices to be represented by bare device structures;
701 * a higher-level representation of the device.
703 struct device { struct
705 struct device *parent; argument
709 const char *init_name; /* initial name of the device */ argument
712 const struct bus_type *bus; /* type of bus device is on */ argument
714 device */
715 void *platform_data; /* Platform specific data, device argument
738 u64 *dma_mask; /* dma mask (if dma'able device) */ argument
770 struct device_node *of_node; /* associated device tree node */ argument
771 struct fwnode_handle *fwnode; /* firmware device node */ argument
774 int numa_node; /* NUMA node this device is close to */ argument
777 u32 id; /* device instance */ argument
785 void (*release)(struct device *dev); argument
809 * struct device_link - Device link representation.
810 * @supplier: The device on the supplier end of the link. argument
811 * @s_node: Hook to the supplier device's list of links to consumers.
812 * @consumer: The device on the consumer end of the link.
813 * @c_node: Hook to the consumer device's list of links to suppliers.
814 * @link_dev: device used to expose link details in sysfs
817 * @rpm_active: Whether or not the consumer device is runtime-PM-active.
823 struct device *supplier;
825 struct device *consumer;
827 struct device link_dev;
836 #define kobj_to_dev(__kobj) container_of_const(__kobj, struct device, kobj)
839 * device_iommu_mapped - Returns true when the device DMA is translated
841 * @dev: Device to perform the check on
843 static inline bool device_iommu_mapped(struct device *dev) in device_iommu_mapped()
848 /* Get the wakeup routines, which depend on struct device */
852 * dev_name - Return a device's name.
853 * @dev: Device with name to get.
854 * Return: The kobject name of the device, or its initial name if unavailable.
856 static inline const char *dev_name(const struct device *dev) in dev_name()
866 * dev_bus_name - Return a device's bus/class name, if at all possible
867 * @dev: struct device to get the bus/class name of
869 * Will return the name of the bus/class the device is attached to. If it is
872 static inline const char *dev_bus_name(const struct device *dev) in dev_bus_name()
877 __printf(2, 3) int dev_set_name(struct device *dev, const char *name, ...);
880 static inline int dev_to_node(struct device *dev) in dev_to_node()
884 static inline void set_dev_node(struct device *dev, int node) in set_dev_node()
889 static inline int dev_to_node(struct device *dev) in dev_to_node()
893 static inline void set_dev_node(struct device *dev, int node) in set_dev_node()
898 static inline struct irq_domain *dev_get_msi_domain(const struct device *dev) in dev_get_msi_domain()
907 static inline void dev_set_msi_domain(struct device *dev, struct irq_domain *d) in dev_set_msi_domain()
914 static inline void *dev_get_drvdata(const struct device *dev) in dev_get_drvdata()
919 static inline void dev_set_drvdata(struct device *dev, void *data) in dev_set_drvdata()
924 static inline struct pm_subsys_data *dev_to_psd(struct device *dev) in dev_to_psd()
929 static inline unsigned int dev_get_uevent_suppress(const struct device *dev) in dev_get_uevent_suppress()
934 static inline void dev_set_uevent_suppress(struct device *dev, int val) in dev_set_uevent_suppress()
939 static inline int device_is_registered(struct device *dev) in device_is_registered()
944 static inline void device_enable_async_suspend(struct device *dev) in device_enable_async_suspend()
950 static inline void device_disable_async_suspend(struct device *dev) in device_disable_async_suspend()
956 static inline bool device_async_suspend_enabled(struct device *dev) in device_async_suspend_enabled()
961 static inline bool device_pm_not_required(struct device *dev) in device_pm_not_required()
966 static inline void device_set_pm_not_required(struct device *dev) in device_set_pm_not_required()
971 static inline void dev_pm_syscore_device(struct device *dev, bool val) in dev_pm_syscore_device()
978 static inline void dev_pm_set_driver_flags(struct device *dev, u32 flags) in dev_pm_set_driver_flags()
983 static inline bool dev_pm_test_driver_flags(struct device *dev, u32 flags) in dev_pm_test_driver_flags()
988 static inline void device_lock(struct device *dev) in device_lock()
993 static inline int device_lock_interruptible(struct device *dev) in device_lock_interruptible()
998 static inline int device_trylock(struct device *dev) in device_trylock()
1003 static inline void device_unlock(struct device *dev) in device_unlock()
1008 DEFINE_GUARD(device, struct device *, device_lock(_T), device_unlock(_T)) in DEFINE_GUARD() argument
1010 static inline void device_lock_assert(struct device *dev) in DEFINE_GUARD()
1015 static inline struct device_node *dev_of_node(struct device *dev) in dev_of_node()
1022 static inline bool dev_has_sync_state(struct device *dev) in dev_has_sync_state()
1033 static inline void dev_set_removable(struct device *dev, in dev_set_removable()
1039 static inline bool dev_is_removable(struct device *dev) in dev_is_removable()
1044 static inline bool dev_removable_is_valid(struct device *dev) in dev_removable_is_valid()
1052 int __must_check device_register(struct device *dev);
1053 void device_unregister(struct device *dev);
1054 void device_initialize(struct device *dev);
1055 int __must_check device_add(struct device *dev);
1056 void device_del(struct device *dev);
1058 DEFINE_FREE(device_del, struct device *, if (_T) device_del(_T))
1060 int device_for_each_child(struct device *dev, void *data,
1061 int (*fn)(struct device *dev, void *data));
1062 int device_for_each_child_reverse(struct device *dev, void *data,
1063 int (*fn)(struct device *dev, void *data));
1064 struct device *device_find_child(struct device *dev, void *data,
1065 int (*match)(struct device *dev, void *data));
1066 struct device *device_find_child_by_name(struct device *parent,
1068 struct device *device_find_any_child(struct device *parent);
1070 int device_rename(struct device *dev, const char *new_name);
1071 int device_move(struct device *dev, struct device *new_parent,
1073 int device_change_owner(struct device *dev, kuid_t kuid, kgid_t kgid);
1075 static inline bool device_supports_offline(struct device *dev) in device_supports_offline()
1082 struct device *__d2 __maybe_unused = dev; \
1087 * device_lock_set_class - Specify a temporary lock class while a device
1089 * @dev: device to modify
1099 struct device *__d = dev; \
1110 * device_lock_reset_class - Return a device to the default lockdep novalidate state
1111 * @dev: device to modify
1118 struct device *__d __maybe_unused = dev; \
1126 int device_offline(struct device *dev);
1127 int device_online(struct device *dev);
1128 void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode);
1129 void set_secondary_fwnode(struct device *dev, struct fwnode_handle *fwnode);
1130 void device_set_of_node_from_dev(struct device *dev, const struct device *dev2);
1131 void device_set_node(struct device *dev, struct fwnode_handle *fwnode);
1133 static inline int dev_num_vf(struct device *dev) in dev_num_vf()
1141 * Root device objects for grouping under /sys/devices
1143 struct device *__root_device_register(const char *name, struct module *owner);
1149 void root_device_unregister(struct device *root);
1151 static inline void *dev_get_platdata(const struct device *dev) in dev_get_platdata()
1157 * Manual binding of a device to driver. See drivers/base/bus.c
1161 struct device *dev);
1162 int __must_check device_bind_driver(struct device *dev);
1163 void device_release_driver(struct device *dev);
1164 int __must_check device_attach(struct device *dev);
1166 void device_initial_probe(struct device *dev);
1167 int __must_check device_reprobe(struct device *dev);
1169 bool device_is_bound(struct device *dev);
1174 __printf(5, 6) struct device *
1175 device_create(const struct class *cls, struct device *parent, dev_t devt,
1177 __printf(6, 7) struct device *
1178 device_create_with_groups(const struct class *cls, struct device *parent, dev_t devt,
1183 int __must_check device_add_groups(struct device *dev,
1185 void device_remove_groups(struct device *dev,
1188 static inline int __must_check device_add_group(struct device *dev, in device_add_group()
1196 static inline void device_remove_group(struct device *dev, in device_remove_group()
1204 int __must_check devm_device_add_groups(struct device *dev,
1206 int __must_check devm_device_add_group(struct device *dev,
1211 * about devices and actions that the general device layer doesn't
1214 /* Notify platform of device discovery */
1215 extern int (*platform_notify)(struct device *dev);
1217 extern int (*platform_notify_remove)(struct device *dev);
1221 * get_device - atomically increment the reference count for the device.
1224 struct device *get_device(struct device *dev);
1225 void put_device(struct device *dev);
1227 DEFINE_FREE(put_device, struct device *, if (_T) put_device(_T))
1229 bool kill_device(struct device *dev);
1241 const char *dev_driver_string(const struct device *dev);
1243 /* Device links interface. */
1244 struct device_link *device_link_add(struct device *consumer,
1245 struct device *supplier, u32 flags);
1247 void device_link_remove(void *consumer, struct device *supplier);