aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/device.h
diff options
context:
space:
mode:
authorMichal Marek <mmarek@suse.cz>2010-10-27 18:15:57 -0400
committerMichal Marek <mmarek@suse.cz>2010-10-27 18:15:57 -0400
commitb74b953b998bcc2db91b694446f3a2619ec32de6 (patch)
tree6ce24caabd730f6ae9287ed0676ec32e6ff31e9d /include/linux/device.h
parentabb438526201c6a79949ad45375c051b6681c253 (diff)
parentf6f94e2ab1b33f0082ac22d71f66385a60d8157f (diff)
Merge commit 'v2.6.36' into kbuild/misc
Update to be able to fix a recent change to scripts/basic/docproc.c (commit eda603f).
Diffstat (limited to 'include/linux/device.h')
-rw-r--r--include/linux/device.h202
1 files changed, 164 insertions, 38 deletions
diff --git a/include/linux/device.h b/include/linux/device.h
index a62799f2ab00..516fecacf27b 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -22,7 +22,6 @@
22#include <linux/types.h> 22#include <linux/types.h>
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/pm.h> 24#include <linux/pm.h>
25#include <linux/semaphore.h>
26#include <asm/atomic.h> 25#include <asm/atomic.h>
27#include <asm/device.h> 26#include <asm/device.h>
28 27
@@ -34,6 +33,7 @@ struct class;
34struct class_private; 33struct class_private;
35struct bus_type; 34struct bus_type;
36struct bus_type_private; 35struct bus_type_private;
36struct device_node;
37 37
38struct bus_attribute { 38struct bus_attribute {
39 struct attribute attr; 39 struct attribute attr;
@@ -84,9 +84,8 @@ struct device *bus_find_device_by_name(struct bus_type *bus,
84 struct device *start, 84 struct device *start,
85 const char *name); 85 const char *name);
86 86
87int __must_check bus_for_each_drv(struct bus_type *bus, 87int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
88 struct device_driver *start, void *data, 88 void *data, int (*fn)(struct device_driver *, void *));
89 int (*fn)(struct device_driver *, void *));
90 89
91void bus_sort_breadthfirst(struct bus_type *bus, 90void bus_sort_breadthfirst(struct bus_type *bus,
92 int (*compare)(const struct device *a, 91 int (*compare)(const struct device *a,
@@ -106,14 +105,16 @@ extern int bus_unregister_notifier(struct bus_type *bus,
106 105
107/* All 4 notifers below get called with the target struct device * 106/* All 4 notifers below get called with the target struct device *
108 * as an argument. Note that those functions are likely to be called 107 * as an argument. Note that those functions are likely to be called
109 * with the device semaphore held in the core, so be careful. 108 * with the device lock held in the core, so be careful.
110 */ 109 */
111#define BUS_NOTIFY_ADD_DEVICE 0x00000001 /* device added */ 110#define BUS_NOTIFY_ADD_DEVICE 0x00000001 /* device added */
112#define BUS_NOTIFY_DEL_DEVICE 0x00000002 /* device removed */ 111#define BUS_NOTIFY_DEL_DEVICE 0x00000002 /* device removed */
113#define BUS_NOTIFY_BOUND_DRIVER 0x00000003 /* driver bound to device */ 112#define BUS_NOTIFY_BIND_DRIVER 0x00000003 /* driver about to be
114#define BUS_NOTIFY_UNBIND_DRIVER 0x00000004 /* driver about to be 113 bound */
114#define BUS_NOTIFY_BOUND_DRIVER 0x00000004 /* driver bound to device */
115#define BUS_NOTIFY_UNBIND_DRIVER 0x00000005 /* driver about to be
115 unbound */ 116 unbound */
116#define BUS_NOTIFY_UNBOUND_DRIVER 0x00000005 /* driver is unbound 117#define BUS_NOTIFY_UNBOUND_DRIVER 0x00000006 /* driver is unbound
117 from the device */ 118 from the device */
118 119
119extern struct kset *bus_get_kset(struct bus_type *bus); 120extern struct kset *bus_get_kset(struct bus_type *bus);
@@ -128,6 +129,10 @@ struct device_driver {
128 129
129 bool suppress_bind_attrs; /* disables bind/unbind via sysfs */ 130 bool suppress_bind_attrs; /* disables bind/unbind via sysfs */
130 131
132#if defined(CONFIG_OF)
133 const struct of_device_id *of_match_table;
134#endif
135
131 int (*probe) (struct device *dev); 136 int (*probe) (struct device *dev);
132 int (*remove) (struct device *dev); 137 int (*remove) (struct device *dev);
133 void (*shutdown) (struct device *dev); 138 void (*shutdown) (struct device *dev);
@@ -203,6 +208,9 @@ struct class {
203 int (*suspend)(struct device *dev, pm_message_t state); 208 int (*suspend)(struct device *dev, pm_message_t state);
204 int (*resume)(struct device *dev); 209 int (*resume)(struct device *dev);
205 210
211 const struct kobj_ns_type_operations *ns_type;
212 const void *(*namespace)(struct device *dev);
213
206 const struct dev_pm_ops *pm; 214 const struct dev_pm_ops *pm;
207 215
208 struct class_private *p; 216 struct class_private *p;
@@ -251,8 +259,10 @@ extern struct device *class_find_device(struct class *class,
251 259
252struct class_attribute { 260struct class_attribute {
253 struct attribute attr; 261 struct attribute attr;
254 ssize_t (*show)(struct class *class, char *buf); 262 ssize_t (*show)(struct class *class, struct class_attribute *attr,
255 ssize_t (*store)(struct class *class, const char *buf, size_t count); 263 char *buf);
264 ssize_t (*store)(struct class *class, struct class_attribute *attr,
265 const char *buf, size_t count);
256}; 266};
257 267
258#define CLASS_ATTR(_name, _mode, _show, _store) \ 268#define CLASS_ATTR(_name, _mode, _show, _store) \
@@ -263,6 +273,23 @@ extern int __must_check class_create_file(struct class *class,
263extern void class_remove_file(struct class *class, 273extern void class_remove_file(struct class *class,
264 const struct class_attribute *attr); 274 const struct class_attribute *attr);
265 275
276/* Simple class attribute that is just a static string */
277
278struct class_attribute_string {
279 struct class_attribute attr;
280 char *str;
281};
282
283/* Currently read-only only */
284#define _CLASS_ATTR_STRING(_name, _mode, _str) \
285 { __ATTR(_name, _mode, show_class_attr_string, NULL), _str }
286#define CLASS_ATTR_STRING(_name, _mode, _str) \
287 struct class_attribute_string class_attr_##_name = \
288 _CLASS_ATTR_STRING(_name, _mode, _str)
289
290extern ssize_t show_class_attr_string(struct class *class, struct class_attribute *attr,
291 char *buf);
292
266struct class_interface { 293struct class_interface {
267 struct list_head node; 294 struct list_head node;
268 struct class *class; 295 struct class *class;
@@ -385,7 +412,7 @@ struct device {
385 const char *init_name; /* initial name of the device */ 412 const char *init_name; /* initial name of the device */
386 struct device_type *type; 413 struct device_type *type;
387 414
388 struct semaphore sem; /* semaphore to synchronize calls to 415 struct mutex mutex; /* mutex to synchronize calls to
389 * its driver. 416 * its driver.
390 */ 417 */
391 418
@@ -414,6 +441,9 @@ struct device {
414 override */ 441 override */
415 /* arch specific additions */ 442 /* arch specific additions */
416 struct dev_archdata archdata; 443 struct dev_archdata archdata;
444#ifdef CONFIG_OF
445 struct device_node *of_node;
446#endif
417 447
418 dev_t devt; /* dev_t, creates the sysfs "dev" */ 448 dev_t devt; /* dev_t, creates the sysfs "dev" */
419 449
@@ -432,6 +462,10 @@ struct device {
432 462
433static inline const char *dev_name(const struct device *dev) 463static inline const char *dev_name(const struct device *dev)
434{ 464{
465 /* Use the init name until the kobject becomes available */
466 if (dev->init_name)
467 return dev->init_name;
468
435 return kobject_name(&dev->kobj); 469 return kobject_name(&dev->kobj);
436} 470}
437 471
@@ -472,6 +506,38 @@ static inline int device_is_registered(struct device *dev)
472 return dev->kobj.state_in_sysfs; 506 return dev->kobj.state_in_sysfs;
473} 507}
474 508
509static inline void device_enable_async_suspend(struct device *dev)
510{
511 if (dev->power.status == DPM_ON)
512 dev->power.async_suspend = true;
513}
514
515static inline void device_disable_async_suspend(struct device *dev)
516{
517 if (dev->power.status == DPM_ON)
518 dev->power.async_suspend = false;
519}
520
521static inline bool device_async_suspend_enabled(struct device *dev)
522{
523 return !!dev->power.async_suspend;
524}
525
526static inline void device_lock(struct device *dev)
527{
528 mutex_lock(&dev->mutex);
529}
530
531static inline int device_trylock(struct device *dev)
532{
533 return mutex_trylock(&dev->mutex);
534}
535
536static inline void device_unlock(struct device *dev)
537{
538 mutex_unlock(&dev->mutex);
539}
540
475void driver_init(void); 541void driver_init(void);
476 542
477/* 543/*
@@ -486,7 +552,7 @@ extern int device_for_each_child(struct device *dev, void *data,
486 int (*fn)(struct device *dev, void *data)); 552 int (*fn)(struct device *dev, void *data));
487extern struct device *device_find_child(struct device *dev, void *data, 553extern struct device *device_find_child(struct device *dev, void *data,
488 int (*match)(struct device *dev, void *data)); 554 int (*match)(struct device *dev, void *data));
489extern int device_rename(struct device *dev, char *new_name); 555extern int device_rename(struct device *dev, const char *new_name);
490extern int device_move(struct device *dev, struct device *new_parent, 556extern int device_move(struct device *dev, struct device *new_parent,
491 enum dpm_order dpm_order); 557 enum dpm_order dpm_order);
492extern const char *device_get_devnode(struct device *dev, 558extern const char *device_get_devnode(struct device *dev,
@@ -573,43 +639,103 @@ extern void sysdev_shutdown(void);
573 639
574/* debugging and troubleshooting/diagnostic helpers. */ 640/* debugging and troubleshooting/diagnostic helpers. */
575extern const char *dev_driver_string(const struct device *dev); 641extern const char *dev_driver_string(const struct device *dev);
576#define dev_printk(level, dev, format, arg...) \ 642
577 printk(level "%s %s: " format , dev_driver_string(dev) , \ 643
578 dev_name(dev) , ## arg) 644#ifdef CONFIG_PRINTK
579 645
580#define dev_emerg(dev, format, arg...) \ 646extern int dev_printk(const char *level, const struct device *dev,
581 dev_printk(KERN_EMERG , dev , format , ## arg) 647 const char *fmt, ...)
582#define dev_alert(dev, format, arg...) \ 648 __attribute__ ((format (printf, 3, 4)));
583 dev_printk(KERN_ALERT , dev , format , ## arg) 649extern int dev_emerg(const struct device *dev, const char *fmt, ...)
584#define dev_crit(dev, format, arg...) \ 650 __attribute__ ((format (printf, 2, 3)));
585 dev_printk(KERN_CRIT , dev , format , ## arg) 651extern int dev_alert(const struct device *dev, const char *fmt, ...)
586#define dev_err(dev, format, arg...) \ 652 __attribute__ ((format (printf, 2, 3)));
587 dev_printk(KERN_ERR , dev , format , ## arg) 653extern int dev_crit(const struct device *dev, const char *fmt, ...)
588#define dev_warn(dev, format, arg...) \ 654 __attribute__ ((format (printf, 2, 3)));
589 dev_printk(KERN_WARNING , dev , format , ## arg) 655extern int dev_err(const struct device *dev, const char *fmt, ...)
590#define dev_notice(dev, format, arg...) \ 656 __attribute__ ((format (printf, 2, 3)));
591 dev_printk(KERN_NOTICE , dev , format , ## arg) 657extern int dev_warn(const struct device *dev, const char *fmt, ...)
592#define dev_info(dev, format, arg...) \ 658 __attribute__ ((format (printf, 2, 3)));
593 dev_printk(KERN_INFO , dev , format , ## arg) 659extern int dev_notice(const struct device *dev, const char *fmt, ...)
660 __attribute__ ((format (printf, 2, 3)));
661extern int _dev_info(const struct device *dev, const char *fmt, ...)
662 __attribute__ ((format (printf, 2, 3)));
663
664#else
665
666static inline int dev_printk(const char *level, const struct device *dev,
667 const char *fmt, ...)
668 __attribute__ ((format (printf, 3, 4)));
669static inline int dev_printk(const char *level, const struct device *dev,
670 const char *fmt, ...)
671 { return 0; }
672
673static inline int dev_emerg(const struct device *dev, const char *fmt, ...)
674 __attribute__ ((format (printf, 2, 3)));
675static inline int dev_emerg(const struct device *dev, const char *fmt, ...)
676 { return 0; }
677static inline int dev_crit(const struct device *dev, const char *fmt, ...)
678 __attribute__ ((format (printf, 2, 3)));
679static inline int dev_crit(const struct device *dev, const char *fmt, ...)
680 { return 0; }
681static inline int dev_alert(const struct device *dev, const char *fmt, ...)
682 __attribute__ ((format (printf, 2, 3)));
683static inline int dev_alert(const struct device *dev, const char *fmt, ...)
684 { return 0; }
685static inline int dev_err(const struct device *dev, const char *fmt, ...)
686 __attribute__ ((format (printf, 2, 3)));
687static inline int dev_err(const struct device *dev, const char *fmt, ...)
688 { return 0; }
689static inline int dev_warn(const struct device *dev, const char *fmt, ...)
690 __attribute__ ((format (printf, 2, 3)));
691static inline int dev_warn(const struct device *dev, const char *fmt, ...)
692 { return 0; }
693static inline int dev_notice(const struct device *dev, const char *fmt, ...)
694 __attribute__ ((format (printf, 2, 3)));
695static inline int dev_notice(const struct device *dev, const char *fmt, ...)
696 { return 0; }
697static inline int _dev_info(const struct device *dev, const char *fmt, ...)
698 __attribute__ ((format (printf, 2, 3)));
699static inline int _dev_info(const struct device *dev, const char *fmt, ...)
700 { return 0; }
701
702#endif
703
704/*
705 * Stupid hackaround for existing uses of non-printk uses dev_info
706 *
707 * Note that the definition of dev_info below is actually _dev_info
708 * and a macro is used to avoid redefining dev_info
709 */
710
711#define dev_info(dev, fmt, arg...) _dev_info(dev, fmt, ##arg)
594 712
595#if defined(DEBUG) 713#if defined(DEBUG)
596#define dev_dbg(dev, format, arg...) \ 714#define dev_dbg(dev, format, arg...) \
597 dev_printk(KERN_DEBUG , dev , format , ## arg) 715 dev_printk(KERN_DEBUG, dev, format, ##arg)
598#elif defined(CONFIG_DYNAMIC_DEBUG) 716#elif defined(CONFIG_DYNAMIC_DEBUG)
599#define dev_dbg(dev, format, ...) do { \ 717#define dev_dbg(dev, format, ...) \
718do { \
600 dynamic_dev_dbg(dev, format, ##__VA_ARGS__); \ 719 dynamic_dev_dbg(dev, format, ##__VA_ARGS__); \
601 } while (0) 720} while (0)
602#else 721#else
603#define dev_dbg(dev, format, arg...) \ 722#define dev_dbg(dev, format, arg...) \
604 ({ if (0) dev_printk(KERN_DEBUG, dev, format, ##arg); 0; }) 723({ \
724 if (0) \
725 dev_printk(KERN_DEBUG, dev, format, ##arg); \
726 0; \
727})
605#endif 728#endif
606 729
607#ifdef VERBOSE_DEBUG 730#ifdef VERBOSE_DEBUG
608#define dev_vdbg dev_dbg 731#define dev_vdbg dev_dbg
609#else 732#else
610 733#define dev_vdbg(dev, format, arg...) \
611#define dev_vdbg(dev, format, arg...) \ 734({ \
612 ({ if (0) dev_printk(KERN_DEBUG, dev, format, ##arg); 0; }) 735 if (0) \
736 dev_printk(KERN_DEBUG, dev, format, ##arg); \
737 0; \
738})
613#endif 739#endif
614 740
615/* 741/*