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.h108
1 files changed, 101 insertions, 7 deletions
diff --git a/include/linux/device.h b/include/linux/device.h
index 3136ede5a1e1..96acef8dd916 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 */
87struct bus_type { 89struct 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
109extern 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})
120extern int __must_check __bus_register(struct bus_type *bus,
121 struct lock_class_key *key);
110extern void bus_unregister(struct bus_type *bus); 122extern void bus_unregister(struct bus_type *bus);
111 123
112extern int __must_check bus_rescan_devices(struct bus_type *bus); 124extern int __must_check bus_rescan_devices(struct bus_type *bus);
113 125
114/* iterator helpers for buses */ 126/* iterator helpers for buses */
127struct subsys_dev_iter {
128 struct klist_iter ki;
129 const struct device_type *type;
130};
131void subsys_dev_iter_init(struct subsys_dev_iter *iter,
132 struct bus_type *subsys,
133 struct device *start,
134 const struct device_type *type);
135struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter);
136void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
115 137
116int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, 138int 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,
121struct device *bus_find_device_by_name(struct bus_type *bus, 143struct 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 146struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
147 struct device *hint);
125int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, 148int 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
128void bus_sort_breadthfirst(struct bus_type *bus, 150void 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 */
293struct 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
301int subsys_interface_register(struct subsys_interface *sif);
302void subsys_interface_unregister(struct subsys_interface *sif);
303
304int 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,11 +487,31 @@ struct device_attribute {
438 const char *buf, size_t count); 487 const char *buf, size_t count);
439}; 488};
440 489
441#define DEVICE_ATTR(_name, _mode, _show, _store) \ 490struct dev_ext_attribute {
442struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store) 491 struct device_attribute attr;
492 void *var;
493};
494
495ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
496 char *buf);
497ssize_t device_store_ulong(struct device *dev, struct device_attribute *attr,
498 const char *buf, size_t count);
499ssize_t device_show_int(struct device *dev, struct device_attribute *attr,
500 char *buf);
501ssize_t device_store_int(struct device *dev, struct device_attribute *attr,
502 const char *buf, size_t count);
443 503
444extern int __must_check device_create_file(struct device *device, 504#define DEVICE_ATTR(_name, _mode, _show, _store) \
445 const struct device_attribute *entry); 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) }
512
513extern int device_create_file(struct device *device,
514 const struct device_attribute *entry);
446extern void device_remove_file(struct device *dev, 515extern void device_remove_file(struct device *dev,
447 const struct device_attribute *attr); 516 const struct device_attribute *attr);
448extern int __must_check device_create_bin_file(struct device *dev, 517extern int __must_check device_create_bin_file(struct device *dev,
@@ -490,6 +559,9 @@ extern int devres_release_group(struct device *dev, void *id);
490extern void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp); 559extern void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp);
491extern void devm_kfree(struct device *dev, void *p); 560extern void devm_kfree(struct device *dev, void *p);
492 561
562void __iomem *devm_request_and_ioremap(struct device *dev,
563 struct resource *res);
564
493struct device_dma_parameters { 565struct device_dma_parameters {
494 /* 566 /*
495 * a low level driver may set these to teach IOMMU code about 567 * a low level driver may set these to teach IOMMU code about
@@ -600,6 +672,7 @@ struct device {
600 struct device_node *of_node; /* associated device tree node */ 672 struct device_node *of_node; /* associated device tree node */
601 673
602 dev_t devt; /* dev_t, creates the sysfs "dev" */ 674 dev_t devt; /* dev_t, creates the sysfs "dev" */
675 u32 id; /* device instance */
603 676
604 spinlock_t devres_lock; 677 spinlock_t devres_lock;
605 struct list_head devres_head; 678 struct list_head devres_head;
@@ -924,4 +997,25 @@ extern long sysfs_deprecated;
924#define sysfs_deprecated 0 997#define sysfs_deprecated 0
925#endif 998#endif
926 999
1000/**
1001 * module_driver() - Helper macro for drivers that don't do anything
1002 * special in module init/exit. This eliminates a lot of boilerplate.
1003 * Each module may only use this macro once, and calling it replaces
1004 * module_init() and module_exit().
1005 *
1006 * Use this macro to construct bus specific macros for registering
1007 * drivers, and do not use it on its own.
1008 */
1009#define module_driver(__driver, __register, __unregister) \
1010static int __init __driver##_init(void) \
1011{ \
1012 return __register(&(__driver)); \
1013} \
1014module_init(__driver##_init); \
1015static void __exit __driver##_exit(void) \
1016{ \
1017 __unregister(&(__driver)); \
1018} \
1019module_exit(__driver##_exit);
1020
927#endif /* _DEVICE_H_ */ 1021#endif /* _DEVICE_H_ */