diff options
Diffstat (limited to 'include/linux/device.h')
-rw-r--r-- | include/linux/device.h | 78 |
1 files changed, 74 insertions, 4 deletions
diff --git a/include/linux/device.h b/include/linux/device.h index 341fb740d851..7f9fc1505e94 100644 --- a/include/linux/device.h +++ b/include/linux/device.h | |||
@@ -53,6 +53,8 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *); | |||
53 | * struct bus_type - The bus type of the device | 53 | * struct bus_type - The bus type of the device |
54 | * | 54 | * |
55 | * @name: The name of the bus. | 55 | * @name: The name of the bus. |
56 | * @dev_name: Used for subsystems to enumerate devices like ("foo%u", dev->id). | ||
57 | * @dev_root: Default device to use as the parent. | ||
56 | * @bus_attrs: Default attributes of the bus. | 58 | * @bus_attrs: Default attributes of the bus. |
57 | * @dev_attrs: Default attributes of the devices on the bus. | 59 | * @dev_attrs: Default attributes of the devices on the bus. |
58 | * @drv_attrs: Default attributes of the device drivers on the bus. | 60 | * @drv_attrs: Default attributes of the device drivers on the bus. |
@@ -86,6 +88,8 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *); | |||
86 | */ | 88 | */ |
87 | struct bus_type { | 89 | struct bus_type { |
88 | const char *name; | 90 | const char *name; |
91 | const char *dev_name; | ||
92 | struct device *dev_root; | ||
89 | struct bus_attribute *bus_attrs; | 93 | struct bus_attribute *bus_attrs; |
90 | struct device_attribute *dev_attrs; | 94 | struct device_attribute *dev_attrs; |
91 | struct driver_attribute *drv_attrs; | 95 | struct driver_attribute *drv_attrs; |
@@ -106,12 +110,30 @@ struct bus_type { | |||
106 | struct subsys_private *p; | 110 | struct subsys_private *p; |
107 | }; | 111 | }; |
108 | 112 | ||
109 | extern int __must_check bus_register(struct bus_type *bus); | 113 | /* This is a #define to keep the compiler from merging different |
114 | * instances of the __key variable */ | ||
115 | #define bus_register(subsys) \ | ||
116 | ({ \ | ||
117 | static struct lock_class_key __key; \ | ||
118 | __bus_register(subsys, &__key); \ | ||
119 | }) | ||
120 | extern int __must_check __bus_register(struct bus_type *bus, | ||
121 | struct lock_class_key *key); | ||
110 | extern void bus_unregister(struct bus_type *bus); | 122 | extern void bus_unregister(struct bus_type *bus); |
111 | 123 | ||
112 | extern int __must_check bus_rescan_devices(struct bus_type *bus); | 124 | extern int __must_check bus_rescan_devices(struct bus_type *bus); |
113 | 125 | ||
114 | /* iterator helpers for buses */ | 126 | /* iterator helpers for buses */ |
127 | struct subsys_dev_iter { | ||
128 | struct klist_iter ki; | ||
129 | const struct device_type *type; | ||
130 | }; | ||
131 | void subsys_dev_iter_init(struct subsys_dev_iter *iter, | ||
132 | struct bus_type *subsys, | ||
133 | struct device *start, | ||
134 | const struct device_type *type); | ||
135 | struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter); | ||
136 | void subsys_dev_iter_exit(struct subsys_dev_iter *iter); | ||
115 | 137 | ||
116 | int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, | 138 | int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, |
117 | int (*fn)(struct device *dev, void *data)); | 139 | int (*fn)(struct device *dev, void *data)); |
@@ -121,10 +143,10 @@ struct device *bus_find_device(struct bus_type *bus, struct device *start, | |||
121 | struct device *bus_find_device_by_name(struct bus_type *bus, | 143 | struct device *bus_find_device_by_name(struct bus_type *bus, |
122 | struct device *start, | 144 | struct device *start, |
123 | const char *name); | 145 | const char *name); |
124 | 146 | struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id, | |
147 | struct device *hint); | ||
125 | int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, | 148 | int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, |
126 | void *data, int (*fn)(struct device_driver *, void *)); | 149 | void *data, int (*fn)(struct device_driver *, void *)); |
127 | |||
128 | void bus_sort_breadthfirst(struct bus_type *bus, | 150 | void bus_sort_breadthfirst(struct bus_type *bus, |
129 | int (*compare)(const struct device *a, | 151 | int (*compare)(const struct device *a, |
130 | const struct device *b)); | 152 | const struct device *b)); |
@@ -256,6 +278,33 @@ struct device *driver_find_device(struct device_driver *drv, | |||
256 | int (*match)(struct device *dev, void *data)); | 278 | int (*match)(struct device *dev, void *data)); |
257 | 279 | ||
258 | /** | 280 | /** |
281 | * struct subsys_interface - interfaces to device functions | ||
282 | * @name name of the device function | ||
283 | * @subsystem subsytem of the devices to attach to | ||
284 | * @node the list of functions registered at the subsystem | ||
285 | * @add device hookup to device function handler | ||
286 | * @remove device hookup to device function handler | ||
287 | * | ||
288 | * Simple interfaces attached to a subsystem. Multiple interfaces can | ||
289 | * attach to a subsystem and its devices. Unlike drivers, they do not | ||
290 | * exclusively claim or control devices. Interfaces usually represent | ||
291 | * a specific functionality of a subsystem/class of devices. | ||
292 | */ | ||
293 | struct subsys_interface { | ||
294 | const char *name; | ||
295 | struct bus_type *subsys; | ||
296 | struct list_head node; | ||
297 | int (*add_dev)(struct device *dev, struct subsys_interface *sif); | ||
298 | int (*remove_dev)(struct device *dev, struct subsys_interface *sif); | ||
299 | }; | ||
300 | |||
301 | int subsys_interface_register(struct subsys_interface *sif); | ||
302 | void subsys_interface_unregister(struct subsys_interface *sif); | ||
303 | |||
304 | int subsys_system_register(struct bus_type *subsys, | ||
305 | const struct attribute_group **groups); | ||
306 | |||
307 | /** | ||
259 | * struct class - device classes | 308 | * struct class - device classes |
260 | * @name: Name of the class. | 309 | * @name: Name of the class. |
261 | * @owner: The module owner. | 310 | * @owner: The module owner. |
@@ -438,8 +487,28 @@ struct device_attribute { | |||
438 | const char *buf, size_t count); | 487 | const char *buf, size_t count); |
439 | }; | 488 | }; |
440 | 489 | ||
490 | struct dev_ext_attribute { | ||
491 | struct device_attribute attr; | ||
492 | void *var; | ||
493 | }; | ||
494 | |||
495 | ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr, | ||
496 | char *buf); | ||
497 | ssize_t device_store_ulong(struct device *dev, struct device_attribute *attr, | ||
498 | const char *buf, size_t count); | ||
499 | ssize_t device_show_int(struct device *dev, struct device_attribute *attr, | ||
500 | char *buf); | ||
501 | ssize_t device_store_int(struct device *dev, struct device_attribute *attr, | ||
502 | const char *buf, size_t count); | ||
503 | |||
441 | #define DEVICE_ATTR(_name, _mode, _show, _store) \ | 504 | #define DEVICE_ATTR(_name, _mode, _show, _store) \ |
442 | struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store) | 505 | struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store) |
506 | #define DEVICE_ULONG_ATTR(_name, _mode, _var) \ | ||
507 | struct dev_ext_attribute dev_attr_##_name = \ | ||
508 | { __ATTR(_name, _mode, device_show_ulong, device_store_ulong), &(_var) } | ||
509 | #define DEVICE_INT_ATTR(_name, _mode, _var) \ | ||
510 | struct dev_ext_attribute dev_attr_##_name = \ | ||
511 | { __ATTR(_name, _mode, device_show_ulong, device_store_ulong), &(_var) } | ||
443 | 512 | ||
444 | extern int __must_check device_create_file(struct device *device, | 513 | extern int __must_check device_create_file(struct device *device, |
445 | const struct device_attribute *entry); | 514 | const struct device_attribute *entry); |
@@ -603,6 +672,7 @@ struct device { | |||
603 | struct device_node *of_node; /* associated device tree node */ | 672 | struct device_node *of_node; /* associated device tree node */ |
604 | 673 | ||
605 | dev_t devt; /* dev_t, creates the sysfs "dev" */ | 674 | dev_t devt; /* dev_t, creates the sysfs "dev" */ |
675 | u32 id; /* device instance */ | ||
606 | 676 | ||
607 | spinlock_t devres_lock; | 677 | spinlock_t devres_lock; |
608 | struct list_head devres_head; | 678 | struct list_head devres_head; |