aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/device.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/device.h')
-rw-r--r--include/linux/device.h70
1 files changed, 56 insertions, 14 deletions
diff --git a/include/linux/device.h b/include/linux/device.h
index 9200cfd75f15..2a9d6ed59579 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -47,7 +47,11 @@ struct bus_attribute {
47}; 47};
48 48
49#define BUS_ATTR(_name, _mode, _show, _store) \ 49#define BUS_ATTR(_name, _mode, _show, _store) \
50struct bus_attribute bus_attr_##_name = __ATTR(_name, _mode, _show, _store) 50 struct bus_attribute bus_attr_##_name = __ATTR(_name, _mode, _show, _store)
51#define BUS_ATTR_RW(_name) \
52 struct bus_attribute bus_attr_##_name = __ATTR_RW(_name)
53#define BUS_ATTR_RO(_name) \
54 struct bus_attribute bus_attr_##_name = __ATTR_RO(_name)
51 55
52extern int __must_check bus_create_file(struct bus_type *, 56extern int __must_check bus_create_file(struct bus_type *,
53 struct bus_attribute *); 57 struct bus_attribute *);
@@ -62,6 +66,9 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *);
62 * @bus_attrs: Default attributes of the bus. 66 * @bus_attrs: Default attributes of the bus.
63 * @dev_attrs: Default attributes of the devices on the bus. 67 * @dev_attrs: Default attributes of the devices on the bus.
64 * @drv_attrs: Default attributes of the device drivers on the bus. 68 * @drv_attrs: Default attributes of the device drivers on the bus.
69 * @bus_groups: Default attributes of the bus.
70 * @dev_groups: Default attributes of the devices on the bus.
71 * @drv_groups: Default attributes of the device drivers on the bus.
65 * @match: Called, perhaps multiple times, whenever a new device or driver 72 * @match: Called, perhaps multiple times, whenever a new device or driver
66 * is added for this bus. It should return a nonzero value if the 73 * is added for this bus. It should return a nonzero value if the
67 * given device can be handled by the given driver. 74 * given device can be handled by the given driver.
@@ -99,9 +106,12 @@ struct bus_type {
99 const char *name; 106 const char *name;
100 const char *dev_name; 107 const char *dev_name;
101 struct device *dev_root; 108 struct device *dev_root;
102 struct bus_attribute *bus_attrs; 109 struct bus_attribute *bus_attrs; /* use bus_groups instead */
103 struct device_attribute *dev_attrs; 110 struct device_attribute *dev_attrs; /* use dev_groups instead */
104 struct driver_attribute *drv_attrs; 111 struct driver_attribute *drv_attrs; /* use drv_groups instead */
112 const struct attribute_group **bus_groups;
113 const struct attribute_group **dev_groups;
114 const struct attribute_group **drv_groups;
105 115
106 int (*match)(struct device *dev, struct device_driver *drv); 116 int (*match)(struct device *dev, struct device_driver *drv);
107 int (*uevent)(struct device *dev, struct kobj_uevent_env *env); 117 int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
@@ -261,9 +271,14 @@ struct driver_attribute {
261 size_t count); 271 size_t count);
262}; 272};
263 273
264#define DRIVER_ATTR(_name, _mode, _show, _store) \ 274#define DRIVER_ATTR(_name, _mode, _show, _store) \
265struct driver_attribute driver_attr_##_name = \ 275 struct driver_attribute driver_attr_##_name = __ATTR(_name, _mode, _show, _store)
266 __ATTR(_name, _mode, _show, _store) 276#define DRIVER_ATTR_RW(_name) \
277 struct driver_attribute driver_attr_##_name = __ATTR_RW(_name)
278#define DRIVER_ATTR_RO(_name) \
279 struct driver_attribute driver_attr_##_name = __ATTR_RO(_name)
280#define DRIVER_ATTR_WO(_name) \
281 struct driver_attribute driver_attr_##_name = __ATTR_WO(_name)
267 282
268extern int __must_check driver_create_file(struct device_driver *driver, 283extern int __must_check driver_create_file(struct device_driver *driver,
269 const struct driver_attribute *attr); 284 const struct driver_attribute *attr);
@@ -313,6 +328,7 @@ int subsys_virtual_register(struct bus_type *subsys,
313 * @name: Name of the class. 328 * @name: Name of the class.
314 * @owner: The module owner. 329 * @owner: The module owner.
315 * @class_attrs: Default attributes of this class. 330 * @class_attrs: Default attributes of this class.
331 * @dev_groups: Default attributes of the devices that belong to the class.
316 * @dev_attrs: Default attributes of the devices belong to the class. 332 * @dev_attrs: Default attributes of the devices belong to the class.
317 * @dev_bin_attrs: Default binary attributes of the devices belong to the class. 333 * @dev_bin_attrs: Default binary attributes of the devices belong to the class.
318 * @dev_kobj: The kobject that represents this class and links it into the hierarchy. 334 * @dev_kobj: The kobject that represents this class and links it into the hierarchy.
@@ -342,7 +358,8 @@ struct class {
342 struct module *owner; 358 struct module *owner;
343 359
344 struct class_attribute *class_attrs; 360 struct class_attribute *class_attrs;
345 struct device_attribute *dev_attrs; 361 struct device_attribute *dev_attrs; /* use dev_groups instead */
362 const struct attribute_group **dev_groups;
346 struct bin_attribute *dev_bin_attrs; 363 struct bin_attribute *dev_bin_attrs;
347 struct kobject *dev_kobj; 364 struct kobject *dev_kobj;
348 365
@@ -414,8 +431,12 @@ struct class_attribute {
414 const struct class_attribute *attr); 431 const struct class_attribute *attr);
415}; 432};
416 433
417#define CLASS_ATTR(_name, _mode, _show, _store) \ 434#define CLASS_ATTR(_name, _mode, _show, _store) \
418struct class_attribute class_attr_##_name = __ATTR(_name, _mode, _show, _store) 435 struct class_attribute class_attr_##_name = __ATTR(_name, _mode, _show, _store)
436#define CLASS_ATTR_RW(_name) \
437 struct class_attribute class_attr_##_name = __ATTR_RW(_name)
438#define CLASS_ATTR_RO(_name) \
439 struct class_attribute class_attr_##_name = __ATTR_RO(_name)
419 440
420extern int __must_check class_create_file(struct class *class, 441extern int __must_check class_create_file(struct class *class,
421 const struct class_attribute *attr); 442 const struct class_attribute *attr);
@@ -423,7 +444,6 @@ extern void class_remove_file(struct class *class,
423 const struct class_attribute *attr); 444 const struct class_attribute *attr);
424 445
425/* Simple class attribute that is just a static string */ 446/* Simple class attribute that is just a static string */
426
427struct class_attribute_string { 447struct class_attribute_string {
428 struct class_attribute attr; 448 struct class_attribute attr;
429 char *str; 449 char *str;
@@ -512,6 +532,12 @@ ssize_t device_store_bool(struct device *dev, struct device_attribute *attr,
512 532
513#define DEVICE_ATTR(_name, _mode, _show, _store) \ 533#define DEVICE_ATTR(_name, _mode, _show, _store) \
514 struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store) 534 struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)
535#define DEVICE_ATTR_RW(_name) \
536 struct device_attribute dev_attr_##_name = __ATTR_RW(_name)
537#define DEVICE_ATTR_RO(_name) \
538 struct device_attribute dev_attr_##_name = __ATTR_RO(_name)
539#define DEVICE_ATTR_WO(_name) \
540 struct device_attribute dev_attr_##_name = __ATTR_WO(_name)
515#define DEVICE_ULONG_ATTR(_name, _mode, _var) \ 541#define DEVICE_ULONG_ATTR(_name, _mode, _var) \
516 struct dev_ext_attribute dev_attr_##_name = \ 542 struct dev_ext_attribute dev_attr_##_name = \
517 { __ATTR(_name, _mode, device_show_ulong, device_store_ulong), &(_var) } 543 { __ATTR(_name, _mode, device_show_ulong, device_store_ulong), &(_var) }
@@ -879,6 +905,7 @@ static inline bool device_supports_offline(struct device *dev)
879 905
880extern void lock_device_hotplug(void); 906extern void lock_device_hotplug(void);
881extern void unlock_device_hotplug(void); 907extern void unlock_device_hotplug(void);
908extern int lock_device_hotplug_sysfs(void);
882extern int device_offline(struct device *dev); 909extern int device_offline(struct device *dev);
883extern int device_online(struct device *dev); 910extern int device_online(struct device *dev);
884/* 911/*
@@ -924,6 +951,11 @@ extern __printf(5, 6)
924struct device *device_create(struct class *cls, struct device *parent, 951struct device *device_create(struct class *cls, struct device *parent,
925 dev_t devt, void *drvdata, 952 dev_t devt, void *drvdata,
926 const char *fmt, ...); 953 const char *fmt, ...);
954extern __printf(6, 7)
955struct device *device_create_with_groups(struct class *cls,
956 struct device *parent, dev_t devt, void *drvdata,
957 const struct attribute_group **groups,
958 const char *fmt, ...);
927extern void device_destroy(struct class *cls, dev_t devt); 959extern void device_destroy(struct class *cls, dev_t devt);
928 960
929/* 961/*
@@ -1078,7 +1110,8 @@ do { \
1078 dev_level_ratelimited(dev_notice, dev, fmt, ##__VA_ARGS__) 1110 dev_level_ratelimited(dev_notice, dev, fmt, ##__VA_ARGS__)
1079#define dev_info_ratelimited(dev, fmt, ...) \ 1111#define dev_info_ratelimited(dev, fmt, ...) \
1080 dev_level_ratelimited(dev_info, dev, fmt, ##__VA_ARGS__) 1112 dev_level_ratelimited(dev_info, dev, fmt, ##__VA_ARGS__)
1081#if defined(CONFIG_DYNAMIC_DEBUG) || defined(DEBUG) 1113#if defined(CONFIG_DYNAMIC_DEBUG)
1114/* descriptor check is first to prevent flooding with "callbacks suppressed" */
1082#define dev_dbg_ratelimited(dev, fmt, ...) \ 1115#define dev_dbg_ratelimited(dev, fmt, ...) \
1083do { \ 1116do { \
1084 static DEFINE_RATELIMIT_STATE(_rs, \ 1117 static DEFINE_RATELIMIT_STATE(_rs, \
@@ -1087,8 +1120,17 @@ do { \
1087 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ 1120 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
1088 if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \ 1121 if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
1089 __ratelimit(&_rs)) \ 1122 __ratelimit(&_rs)) \
1090 __dynamic_pr_debug(&descriptor, pr_fmt(fmt), \ 1123 __dynamic_dev_dbg(&descriptor, dev, fmt, \
1091 ##__VA_ARGS__); \ 1124 ##__VA_ARGS__); \
1125} while (0)
1126#elif defined(DEBUG)
1127#define dev_dbg_ratelimited(dev, fmt, ...) \
1128do { \
1129 static DEFINE_RATELIMIT_STATE(_rs, \
1130 DEFAULT_RATELIMIT_INTERVAL, \
1131 DEFAULT_RATELIMIT_BURST); \
1132 if (__ratelimit(&_rs)) \
1133 dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); \
1092} while (0) 1134} while (0)
1093#else 1135#else
1094#define dev_dbg_ratelimited(dev, fmt, ...) \ 1136#define dev_dbg_ratelimited(dev, fmt, ...) \