H A D | device.h | 2 * device.h - generic, centralized driver model 30 #include <asm/device.h> 32 struct device; 63 * struct bus_type - The bus type of the device 67 * @dev_root: Default device to use as the parent. 71 * @drv_groups: Default attributes of the device drivers on the bus. 72 * @match: Called, perhaps multiple times, whenever a new device or driver 74 * given device can be handled by the given driver. 75 * @uevent: Called when a device is added, removed, or a few other things 77 * @probe: Called when a new device or driver add to this bus, and callback 78 * the specific driver's probe to initial the matched device. 79 * @remove: Called when a device removed from this bus. 80 * @shutdown: Called at shut-down time to quiesce the device. 82 * @online: Called to put the device back online (after offlining it). 83 * @offline: Called to put the device offline for hot-removal. May fail. 85 * @suspend: Called when a device on this bus wants to go to sleep mode. 86 * @resume: Called to bring a device on this bus out of sleep mode. 88 * device driver's pm-ops. 97 * purposes of the device model, all devices are connected via a bus, even if 99 * A USB controller is usually a PCI device, for example. The device model 108 struct device *dev_root; 114 int (*match)(struct device *dev, struct device_driver *drv); 115 int (*uevent)(struct device *dev, struct kobj_uevent_env *env); 116 int (*probe)(struct device *dev); 117 int (*remove)(struct device *dev); 118 void (*shutdown)(struct device *dev); 120 int (*online)(struct device *dev); 121 int (*offline)(struct device *dev); 123 int (*suspend)(struct device *dev, pm_message_t state); 124 int (*resume)(struct device *dev); 147 struct device *start, 149 struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter); 152 int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, 153 int (*fn)(struct device *dev, void *data)); 154 struct device *bus_find_device(struct bus_type *bus, struct device *start, 156 int (*match)(struct device *dev, void *data)); 157 struct device *bus_find_device_by_name(struct bus_type *bus, 158 struct device *start, 160 struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id, 161 struct device *hint); 165 int (*compare)(const struct device *a, 166 const struct device *b)); 180 /* All 4 notifers below get called with the target struct device * 182 * with the device lock held in the core, so be careful. 184 #define BUS_NOTIFY_ADD_DEVICE 0x00000001 /* device added */ 185 #define BUS_NOTIFY_DEL_DEVICE 0x00000002 /* device to be removed */ 186 #define BUS_NOTIFY_REMOVED_DEVICE 0x00000003 /* device removed */ 189 #define BUS_NOTIFY_BOUND_DRIVER 0x00000005 /* driver bound to device */ 193 from the device */ 199 * struct device_driver - The basic device driver structure 200 * @name: Name of the device driver. 201 * @bus: The bus which the device of this driver belongs to. 207 * @probe: Called to query the existence of a specific device, 209 * to a specific device. 210 * @remove: Called when the device is removed from the system to 211 * unbind a device from this driver. 212 * @shutdown: Called at shut-down time to quiesce the device. 213 * @suspend: Called to put the device to sleep mode. Usually to a 215 * @resume: Called to bring a device from sleep mode. 218 * @pm: Power management operations of the device which matched 223 * The device driver-model tracks all of the drivers known to the system. 228 * of any specific device. 242 int (*probe) (struct device *dev); 243 int (*remove) (struct device *dev); 244 void (*shutdown) (struct device *dev); 245 int (*suspend) (struct device *dev, pm_message_t state); 246 int (*resume) (struct device *dev); 288 struct device *start, 290 int (*fn)(struct device *dev, 292 struct device *driver_find_device(struct device_driver *drv, 293 struct device *start, void *data, 294 int (*match)(struct device *dev, void *data)); 297 * struct subsys_interface - interfaces to device functions 298 * @name: name of the device function 301 * @add_dev: device hookup to device function handler 302 * @remove_dev: device hookup to device function handler 313 int (*add_dev)(struct device *dev, struct subsys_interface *sif); 314 int (*remove_dev)(struct device *dev, struct subsys_interface *sif); 326 * struct class - device classes 332 * @dev_uevent: Called when a device is added, removed from this class, or a 337 * @dev_release: Called to release the device. 338 * @suspend: Used to put the device to sleep mode, usually to a low power 340 * @resume: Used to bring the device from the sleep mode. 342 * @namespace: Namespace of the device belongs to this class. 343 * @pm: The default device power management operations of this class. 347 * A class is a higher-level view of a device that abstracts out low-level 361 int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env); 362 char *(*devnode)(struct device *dev, umode_t *mode); 365 void (*dev_release)(struct device *dev); 367 int (*suspend)(struct device *dev, pm_message_t state); 368 int (*resume)(struct device *dev); 371 const void *(*namespace)(struct device *dev); 400 int class_compat_create_link(struct class_compat *cls, struct device *dev, 401 struct device *device_link); 402 void class_compat_remove_link(struct class_compat *cls, struct device *dev, 403 struct device *device_link); 407 struct device *start, 409 extern struct device *class_dev_iter_next(struct class_dev_iter *iter); 412 extern int class_for_each_device(struct class *class, struct device *start, 414 int (*fn)(struct device *dev, void *data)); 415 extern struct device *class_find_device(struct class *class, 416 struct device *start, const void *data, 417 int (*match)(struct device *, const void *)); 473 int (*add_dev) (struct device *, struct class_interface *); 474 void (*remove_dev) (struct device *, struct class_interface *); 494 * The type of device, "struct device" is embedded in. A class 497 * This identifies the device type and carries type-specific 505 int (*uevent)(struct device *dev, struct kobj_uevent_env *env); 506 char *(*devnode)(struct device *dev, umode_t *mode, 508 void (*release)(struct device *dev); 513 /* interface for exporting device attributes */ 516 ssize_t (*show)(struct device *dev, struct device_attribute *attr, 518 ssize_t (*store)(struct device *dev, struct device_attribute *attr, 527 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr, 529 ssize_t device_store_ulong(struct device *dev, struct device_attribute *attr, 531 ssize_t device_show_int(struct device *dev, struct device_attribute *attr, 533 ssize_t device_store_int(struct device *dev, struct device_attribute *attr, 535 ssize_t device_show_bool(struct device *dev, struct device_attribute *attr, 537 ssize_t device_store_bool(struct device *dev, struct device_attribute *attr, 561 extern int device_create_file(struct device *device, 563 extern void device_remove_file(struct device *dev, 565 extern bool device_remove_file_self(struct device *dev, 567 extern int __must_check device_create_bin_file(struct device *dev, 569 extern void device_remove_bin_file(struct device *dev, 572 /* device resource management */ 573 typedef void (*dr_release_t)(struct device *dev, void *res); 574 typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data); 584 extern void devres_for_each_res(struct device *dev, dr_release_t release, 586 void (*fn)(struct device *, void *, void *), 589 extern void devres_add(struct device *dev, void *res); 590 extern void *devres_find(struct device *dev, dr_release_t release, 592 extern void *devres_get(struct device *dev, void *new_res, 594 extern void *devres_remove(struct device *dev, dr_release_t release, 596 extern int devres_destroy(struct device *dev, dr_release_t release, 598 extern int devres_release(struct device *dev, dr_release_t release, 602 extern void * __must_check devres_open_group(struct device *dev, void *id, 604 extern void devres_close_group(struct device *dev, void *id); 605 extern void devres_remove_group(struct device *dev, void *id); 606 extern int devres_release_group(struct device *dev, void *id); 608 /* managed devm_k.alloc/kfree for device drivers */ 609 extern void *devm_kmalloc(struct device *dev, size_t size, gfp_t gfp); 610 extern char *devm_kvasprintf(struct device *dev, gfp_t gfp, const char *fmt, 613 char *devm_kasprintf(struct device *dev, gfp_t gfp, const char *fmt, ...); devm_kzalloc() 614 static inline void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp) devm_kzalloc() 618 static inline void *devm_kmalloc_array(struct device *dev, devm_kmalloc_array() 625 static inline void *devm_kcalloc(struct device *dev, devm_kcalloc() 630 extern void devm_kfree(struct device *dev, void *p); 631 extern char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp); 632 extern void *devm_kmemdup(struct device *dev, const void *src, size_t len, 635 extern unsigned long devm_get_free_pages(struct device *dev, 637 extern void devm_free_pages(struct device *dev, unsigned long addr); 639 void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res); 642 int devm_add_action(struct device *dev, void (*action)(void *), void *data); 643 void devm_remove_action(struct device *dev, void (*action)(void *), void *data); 655 * struct device - The basic device structure 656 * @parent: The device's "parent" device, the device to which it is attached. 657 * In most cases, a parent device is some sort of bus or host 658 * controller. If parent is NULL, the device, is a top-level device, 660 * @p: Holds the private data of the driver core portions of the device. 663 * @init_name: Initial name of the device. 664 * @type: The type of device. 665 * This identifies the device type and carries type-specific 668 * @bus: Type of bus device is on. 670 * @platform_data: Platform data specific to the device. 679 * @power: For device power management. 684 * @pins: For device pin management. 686 * @numa_node: NUMA node this device is close to. 687 * @dma_mask: Dma mask (if dma'ble device). 694 * @dma_pools: Dma pools (if dma'ble device). 698 * @of_node: Associated device tree node. 699 * @fwnode: Associated device node supplied by platform firmware. 701 * @id: device instance 702 * @devres_lock: Spinlock to protect the resource of the device. 703 * @devres_head: The resources list of the device. 704 * @knode_class: The node used to add the device to the class list. 705 * @class: The class of the device. 707 * @release: Callback to free the device after all references have 709 * device (i.e. the bus driver that discovered the device). 710 * @iommu_group: IOMMU group the device belongs to. 712 * @offline_disabled: If set, the device is permanently online. 715 * At the lowest level, every device in a Linux system is represented by an 716 * instance of struct device. The device structure contains the information 717 * that the device model core needs to model the system. Most subsystems, 719 * result, it is rare for devices to be represented by bare device structures; 721 * a higher-level representation of the device. 723 struct device { struct 724 struct device *parent; 729 const char *init_name; /* initial name of the device */ 736 struct bus_type *bus; /* type of bus device is on */ 738 device */ 739 void *platform_data; /* Platform specific data, device 751 int numa_node; /* NUMA node this device is close to */ 753 u64 *dma_mask; /* dma mask (if dma'able device) */ 774 struct device_node *of_node; /* associated device tree node */ 775 struct fwnode_handle *fwnode; /* firmware device node */ 778 u32 id; /* device instance */ 787 void (*release)(struct device *dev); 794 static inline struct device *kobj_to_dev(struct kobject *kobj) kobj_to_dev() 796 return container_of(kobj, struct device, kobj); kobj_to_dev() 799 /* Get the wakeup routines, which depend on struct device */ 802 static inline const char *dev_name(const struct device *dev) dev_name() 812 int dev_set_name(struct device *dev, const char *name, ...); 815 static inline int dev_to_node(struct device *dev) dev_to_node() 819 static inline void set_dev_node(struct device *dev, int node) set_dev_node() 824 static inline int dev_to_node(struct device *dev) dev_to_node() 828 static inline void set_dev_node(struct device *dev, int node) set_dev_node() 833 static inline void *dev_get_drvdata(const struct device *dev) dev_get_drvdata() 838 static inline void dev_set_drvdata(struct device *dev, void *data) dev_set_drvdata() 843 static inline struct pm_subsys_data *dev_to_psd(struct device *dev) dev_to_psd() 848 static inline unsigned int dev_get_uevent_suppress(const struct device *dev) dev_get_uevent_suppress() 853 static inline void dev_set_uevent_suppress(struct device *dev, int val) dev_set_uevent_suppress() 858 static inline int device_is_registered(struct device *dev) device_is_registered() 863 static inline void device_enable_async_suspend(struct device *dev) device_enable_async_suspend() 869 static inline void device_disable_async_suspend(struct device *dev) device_disable_async_suspend() 875 static inline bool device_async_suspend_enabled(struct device *dev) device_async_suspend_enabled() 880 static inline void pm_suspend_ignore_children(struct device *dev, bool enable) pm_suspend_ignore_children() 885 static inline void dev_pm_syscore_device(struct device *dev, bool val) dev_pm_syscore_device() 892 static inline void device_lock(struct device *dev) device_lock() 897 static inline int device_trylock(struct device *dev) device_trylock() 902 static inline void device_unlock(struct device *dev) device_unlock() 907 static inline void device_lock_assert(struct device *dev) device_lock_assert() 912 static inline struct device_node *dev_of_node(struct device *dev) dev_of_node() 924 extern int __must_check device_register(struct device *dev); 925 extern void device_unregister(struct device *dev); 926 extern void device_initialize(struct device *dev); 927 extern int __must_check device_add(struct device *dev); 928 extern void device_del(struct device *dev); 929 extern int device_for_each_child(struct device *dev, void *data, 930 int (*fn)(struct device *dev, void *data)); 931 extern struct device *device_find_child(struct device *dev, void *data, 932 int (*match)(struct device *dev, void *data)); 933 extern int device_rename(struct device *dev, const char *new_name); 934 extern int device_move(struct device *dev, struct device *new_parent, 936 extern const char *device_get_devnode(struct device *dev, 940 static inline bool device_supports_offline(struct device *dev) device_supports_offline() 948 extern int device_offline(struct device *dev); 949 extern int device_online(struct device *dev); 950 extern void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode); 951 extern void set_secondary_fwnode(struct device *dev, struct fwnode_handle *fwnode); 954 * Root device objects for grouping under /sys/devices 956 extern struct device *__root_device_register(const char *name, 963 extern void root_device_unregister(struct device *root); 965 static inline void *dev_get_platdata(const struct device *dev) dev_get_platdata() 971 * Manual binding of a device to driver. See drivers/base/bus.c 974 extern int __must_check device_bind_driver(struct device *dev); 975 extern void device_release_driver(struct device *dev); 976 extern int __must_check device_attach(struct device *dev); 978 extern int __must_check device_reprobe(struct device *dev); 983 extern struct device *device_create_vargs(struct class *cls, 984 struct device *parent, 990 struct device *device_create(struct class *cls, struct device *parent, 994 struct device *device_create_with_groups(struct class *cls, 995 struct device *parent, dev_t devt, void *drvdata, 1002 * about devices and actions that the general device layer doesn't 1005 /* Notify platform of device discovery */ 1006 extern int (*platform_notify)(struct device *dev); 1008 extern int (*platform_notify_remove)(struct device *dev); 1012 * get_device - atomically increment the reference count for the device. 1015 extern struct device *get_device(struct device *dev); 1016 extern void put_device(struct device *dev); 1019 extern int devtmpfs_create_node(struct device *dev); 1020 extern int devtmpfs_delete_node(struct device *dev); 1023 static inline int devtmpfs_create_node(struct device *dev) { return 0; } devtmpfs_delete_node() 1024 static inline int devtmpfs_delete_node(struct device *dev) { return 0; } devtmpfs_mount() 1032 extern const char *dev_driver_string(const struct device *dev); devtmpfs_mount() 1038 int dev_vprintk_emit(int level, const struct device *dev, devtmpfs_mount() 1041 int dev_printk_emit(int level, const struct device *dev, const char *fmt, ...); devtmpfs_mount() 1044 void dev_printk(const char *level, const struct device *dev, devtmpfs_mount() 1047 void dev_emerg(const struct device *dev, const char *fmt, ...); devtmpfs_mount() 1049 void dev_alert(const struct device *dev, const char *fmt, ...); devtmpfs_mount() 1051 void dev_crit(const struct device *dev, const char *fmt, ...); devtmpfs_mount() 1053 void dev_err(const struct device *dev, const char *fmt, ...); devtmpfs_mount() 1055 void dev_warn(const struct device *dev, const char *fmt, ...); devtmpfs_mount() 1057 void dev_notice(const struct device *dev, const char *fmt, ...); devtmpfs_mount() 1059 void _dev_info(const struct device *dev, const char *fmt, ...); devtmpfs_mount() 1064 int dev_vprintk_emit(int level, const struct device *dev, dev_vprintk_emit() 1068 int dev_printk_emit(int level, const struct device *dev, const char *fmt, ...) dev_printk_emit() 1071 static inline void __dev_printk(const char *level, const struct device *dev, __dev_printk() 1075 void dev_printk(const char *level, const struct device *dev, dev_printk() 1080 void dev_emerg(const struct device *dev, const char *fmt, ...) dev_emerg() 1083 void dev_crit(const struct device *dev, const char *fmt, ...) dev_crit() 1086 void dev_alert(const struct device *dev, const char *fmt, ...) dev_alert() 1089 void dev_err(const struct device *dev, const char *fmt, ...) dev_err() 1092 void dev_warn(const struct device *dev, const char *fmt, ...) dev_warn() 1095 void dev_notice(const struct device *dev, const char *fmt, ...) dev_notice() 1098 void _dev_info(const struct device *dev, const char *fmt, ...) _dev_info()
|