1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef _DEVICE_H_
14#define _DEVICE_H_
15
16#include <linux/ioport.h>
17#include <linux/kobject.h>
18#include <linux/klist.h>
19#include <linux/list.h>
20#include <linux/lockdep.h>
21#include <linux/compiler.h>
22#include <linux/types.h>
23#include <linux/mutex.h>
24#include <linux/pinctrl/devinfo.h>
25#include <linux/pm.h>
26#include <linux/atomic.h>
27#include <linux/ratelimit.h>
28#include <linux/uidgid.h>
29#include <asm/device.h>
30
31struct device;
32struct device_private;
33struct device_driver;
34struct driver_private;
35struct module;
36struct class;
37struct subsys_private;
38struct bus_type;
39struct device_node;
40struct iommu_ops;
41struct iommu_group;
42
43struct bus_attribute {
44 struct attribute attr;
45 ssize_t (*show)(struct bus_type *bus, char *buf);
46 ssize_t (*store)(struct bus_type *bus, const char *buf, size_t count);
47};
48
49#define BUS_ATTR(_name, _mode, _show, _store) \
50struct bus_attribute bus_attr_##_name = __ATTR(_name, _mode, _show, _store)
51
52extern int __must_check bus_create_file(struct bus_type *,
53 struct bus_attribute *);
54extern void bus_remove_file(struct bus_type *, struct bus_attribute *);
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93struct bus_type {
94 const char *name;
95 const char *dev_name;
96 struct device *dev_root;
97 struct bus_attribute *bus_attrs;
98 struct device_attribute *dev_attrs;
99 struct driver_attribute *drv_attrs;
100
101 int (*match)(struct device *dev, struct device_driver *drv);
102 int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
103 int (*probe)(struct device *dev);
104 int (*remove)(struct device *dev);
105 void (*shutdown)(struct device *dev);
106
107 int (*suspend)(struct device *dev, pm_message_t state);
108 int (*resume)(struct device *dev);
109
110 const struct dev_pm_ops *pm;
111
112 struct iommu_ops *iommu_ops;
113
114 struct subsys_private *p;
115 struct lock_class_key lock_key;
116};
117
118extern int __must_check bus_register(struct bus_type *bus);
119
120extern void bus_unregister(struct bus_type *bus);
121
122extern int __must_check bus_rescan_devices(struct bus_type *bus);
123
124
125struct subsys_dev_iter {
126 struct klist_iter ki;
127 const struct device_type *type;
128};
129void subsys_dev_iter_init(struct subsys_dev_iter *iter,
130 struct bus_type *subsys,
131 struct device *start,
132 const struct device_type *type);
133struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter);
134void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
135
136int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
137 int (*fn)(struct device *dev, void *data));
138struct device *bus_find_device(struct bus_type *bus, struct device *start,
139 void *data,
140 int (*match)(struct device *dev, void *data));
141struct device *bus_find_device_by_name(struct bus_type *bus,
142 struct device *start,
143 const char *name);
144struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
145 struct device *hint);
146int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
147 void *data, int (*fn)(struct device_driver *, void *));
148void bus_sort_breadthfirst(struct bus_type *bus,
149 int (*compare)(const struct device *a,
150 const struct device *b));
151
152
153
154
155
156
157struct notifier_block;
158
159extern int bus_register_notifier(struct bus_type *bus,
160 struct notifier_block *nb);
161extern int bus_unregister_notifier(struct bus_type *bus,
162 struct notifier_block *nb);
163
164
165
166
167
168#define BUS_NOTIFY_ADD_DEVICE 0x00000001
169#define BUS_NOTIFY_DEL_DEVICE 0x00000002
170#define BUS_NOTIFY_BIND_DRIVER 0x00000003
171
172#define BUS_NOTIFY_BOUND_DRIVER 0x00000004
173#define BUS_NOTIFY_UNBIND_DRIVER 0x00000005
174
175#define BUS_NOTIFY_UNBOUND_DRIVER 0x00000006
176
177
178extern struct kset *bus_get_kset(struct bus_type *bus);
179extern struct klist *bus_get_device_klist(struct bus_type *bus);
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213struct device_driver {
214 const char *name;
215 struct bus_type *bus;
216
217 struct module *owner;
218 const char *mod_name;
219
220 bool suppress_bind_attrs;
221
222 const struct of_device_id *of_match_table;
223 const struct acpi_device_id *acpi_match_table;
224
225 int (*probe) (struct device *dev);
226 int (*remove) (struct device *dev);
227 void (*shutdown) (struct device *dev);
228 int (*suspend) (struct device *dev, pm_message_t state);
229 int (*resume) (struct device *dev);
230 const struct attribute_group **groups;
231
232 const struct dev_pm_ops *pm;
233
234 struct driver_private *p;
235};
236
237
238extern int __must_check driver_register(struct device_driver *drv);
239extern void driver_unregister(struct device_driver *drv);
240
241extern struct device_driver *driver_find(const char *name,
242 struct bus_type *bus);
243extern int driver_probe_done(void);
244extern void wait_for_device_probe(void);
245
246
247
248
249struct driver_attribute {
250 struct attribute attr;
251 ssize_t (*show)(struct device_driver *driver, char *buf);
252 ssize_t (*store)(struct device_driver *driver, const char *buf,
253 size_t count);
254};
255
256#define DRIVER_ATTR(_name, _mode, _show, _store) \
257struct driver_attribute driver_attr_##_name = \
258 __ATTR(_name, _mode, _show, _store)
259
260extern int __must_check driver_create_file(struct device_driver *driver,
261 const struct driver_attribute *attr);
262extern void driver_remove_file(struct device_driver *driver,
263 const struct driver_attribute *attr);
264
265extern int __must_check driver_for_each_device(struct device_driver *drv,
266 struct device *start,
267 void *data,
268 int (*fn)(struct device *dev,
269 void *));
270struct device *driver_find_device(struct device_driver *drv,
271 struct device *start, void *data,
272 int (*match)(struct device *dev, void *data));
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287struct subsys_interface {
288 const char *name;
289 struct bus_type *subsys;
290 struct list_head node;
291 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
292 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
293};
294
295int subsys_interface_register(struct subsys_interface *sif);
296void subsys_interface_unregister(struct subsys_interface *sif);
297
298int subsys_system_register(struct bus_type *subsys,
299 const struct attribute_group **groups);
300int subsys_virtual_register(struct bus_type *subsys,
301 const struct attribute_group **groups);
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332struct class {
333 const char *name;
334 struct module *owner;
335
336 struct class_attribute *class_attrs;
337 struct device_attribute *dev_attrs;
338 struct bin_attribute *dev_bin_attrs;
339 struct kobject *dev_kobj;
340
341 int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env);
342 char *(*devnode)(struct device *dev, umode_t *mode);
343
344 void (*class_release)(struct class *class);
345 void (*dev_release)(struct device *dev);
346
347 int (*suspend)(struct device *dev, pm_message_t state);
348 int (*resume)(struct device *dev);
349
350 const struct kobj_ns_type_operations *ns_type;
351 const void *(*namespace)(struct device *dev);
352
353 const struct dev_pm_ops *pm;
354
355 struct subsys_private *p;
356};
357
358struct class_dev_iter {
359 struct klist_iter ki;
360 const struct device_type *type;
361};
362
363extern struct kobject *sysfs_dev_block_kobj;
364extern struct kobject *sysfs_dev_char_kobj;
365extern int __must_check __class_register(struct class *class,
366 struct lock_class_key *key);
367extern void class_unregister(struct class *class);
368
369
370
371#define class_register(class) \
372({ \
373 static struct lock_class_key __key; \
374 __class_register(class, &__key); \
375})
376
377struct class_compat;
378struct class_compat *class_compat_register(const char *name);
379void class_compat_unregister(struct class_compat *cls);
380int class_compat_create_link(struct class_compat *cls, struct device *dev,
381 struct device *device_link);
382void class_compat_remove_link(struct class_compat *cls, struct device *dev,
383 struct device *device_link);
384
385extern void class_dev_iter_init(struct class_dev_iter *iter,
386 struct class *class,
387 struct device *start,
388 const struct device_type *type);
389extern struct device *class_dev_iter_next(struct class_dev_iter *iter);
390extern void class_dev_iter_exit(struct class_dev_iter *iter);
391
392extern int class_for_each_device(struct class *class, struct device *start,
393 void *data,
394 int (*fn)(struct device *dev, void *data));
395extern struct device *class_find_device(struct class *class,
396 struct device *start, const void *data,
397 int (*match)(struct device *, const void *));
398
399struct class_attribute {
400 struct attribute attr;
401 ssize_t (*show)(struct class *class, struct class_attribute *attr,
402 char *buf);
403 ssize_t (*store)(struct class *class, struct class_attribute *attr,
404 const char *buf, size_t count);
405 const void *(*namespace)(struct class *class,
406 const struct class_attribute *attr);
407};
408
409#define CLASS_ATTR(_name, _mode, _show, _store) \
410struct class_attribute class_attr_##_name = __ATTR(_name, _mode, _show, _store)
411
412extern int __must_check class_create_file(struct class *class,
413 const struct class_attribute *attr);
414extern void class_remove_file(struct class *class,
415 const struct class_attribute *attr);
416
417
418
419struct class_attribute_string {
420 struct class_attribute attr;
421 char *str;
422};
423
424
425#define _CLASS_ATTR_STRING(_name, _mode, _str) \
426 { __ATTR(_name, _mode, show_class_attr_string, NULL), _str }
427#define CLASS_ATTR_STRING(_name, _mode, _str) \
428 struct class_attribute_string class_attr_##_name = \
429 _CLASS_ATTR_STRING(_name, _mode, _str)
430
431extern ssize_t show_class_attr_string(struct class *class, struct class_attribute *attr,
432 char *buf);
433
434struct class_interface {
435 struct list_head node;
436 struct class *class;
437
438 int (*add_dev) (struct device *, struct class_interface *);
439 void (*remove_dev) (struct device *, struct class_interface *);
440};
441
442extern int __must_check class_interface_register(struct class_interface *);
443extern void class_interface_unregister(struct class_interface *);
444
445extern struct class * __must_check __class_create(struct module *owner,
446 const char *name,
447 struct lock_class_key *key);
448extern void class_destroy(struct class *cls);
449
450
451
452#define class_create(owner, name) \
453({ \
454 static struct lock_class_key __key; \
455 __class_create(owner, name, &__key); \
456})
457
458
459
460
461
462
463
464
465
466
467struct device_type {
468 const char *name;
469 const struct attribute_group **groups;
470 int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
471 char *(*devnode)(struct device *dev, umode_t *mode,
472 kuid_t *uid, kgid_t *gid);
473 void (*release)(struct device *dev);
474
475 const struct dev_pm_ops *pm;
476};
477
478
479struct device_attribute {
480 struct attribute attr;
481 ssize_t (*show)(struct device *dev, struct device_attribute *attr,
482 char *buf);
483 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
484 const char *buf, size_t count);
485};
486
487struct dev_ext_attribute {
488 struct device_attribute attr;
489 void *var;
490};
491
492ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
493 char *buf);
494ssize_t device_store_ulong(struct device *dev, struct device_attribute *attr,
495 const char *buf, size_t count);
496ssize_t device_show_int(struct device *dev, struct device_attribute *attr,
497 char *buf);
498ssize_t device_store_int(struct device *dev, struct device_attribute *attr,
499 const char *buf, size_t count);
500ssize_t device_show_bool(struct device *dev, struct device_attribute *attr,
501 char *buf);
502ssize_t device_store_bool(struct device *dev, struct device_attribute *attr,
503 const char *buf, size_t count);
504
505#define DEVICE_ATTR(_name, _mode, _show, _store) \
506 struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)
507#define DEVICE_ULONG_ATTR(_name, _mode, _var) \
508 struct dev_ext_attribute dev_attr_##_name = \
509 { __ATTR(_name, _mode, device_show_ulong, device_store_ulong), &(_var) }
510#define DEVICE_INT_ATTR(_name, _mode, _var) \
511 struct dev_ext_attribute dev_attr_##_name = \
512 { __ATTR(_name, _mode, device_show_int, device_store_int), &(_var) }
513#define DEVICE_BOOL_ATTR(_name, _mode, _var) \
514 struct dev_ext_attribute dev_attr_##_name = \
515 { __ATTR(_name, _mode, device_show_bool, device_store_bool), &(_var) }
516#define DEVICE_ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) \
517 struct device_attribute dev_attr_##_name = \
518 __ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store)
519
520extern int device_create_file(struct device *device,
521 const struct device_attribute *entry);
522extern void device_remove_file(struct device *dev,
523 const struct device_attribute *attr);
524extern int __must_check device_create_bin_file(struct device *dev,
525 const struct bin_attribute *attr);
526extern void device_remove_bin_file(struct device *dev,
527 const struct bin_attribute *attr);
528extern int device_schedule_callback_owner(struct device *dev,
529 void (*func)(struct device *dev), struct module *owner);
530
531
532#define device_schedule_callback(dev, func) \
533 device_schedule_callback_owner(dev, func, THIS_MODULE)
534
535
536typedef void (*dr_release_t)(struct device *dev, void *res);
537typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data);
538
539#ifdef CONFIG_DEBUG_DEVRES
540extern void *__devres_alloc(dr_release_t release, size_t size, gfp_t gfp,
541 const char *name);
542#define devres_alloc(release, size, gfp) \
543 __devres_alloc(release, size, gfp, #release)
544#else
545extern void *devres_alloc(dr_release_t release, size_t size, gfp_t gfp);
546#endif
547extern void devres_for_each_res(struct device *dev, dr_release_t release,
548 dr_match_t match, void *match_data,
549 void (*fn)(struct device *, void *, void *),
550 void *data);
551extern void devres_free(void *res);
552extern void devres_add(struct device *dev, void *res);
553extern void *devres_find(struct device *dev, dr_release_t release,
554 dr_match_t match, void *match_data);
555extern void *devres_get(struct device *dev, void *new_res,
556 dr_match_t match, void *match_data);
557extern void *devres_remove(struct device *dev, dr_release_t release,
558 dr_match_t match, void *match_data);
559extern int devres_destroy(struct device *dev, dr_release_t release,
560 dr_match_t match, void *match_data);
561extern int devres_release(struct device *dev, dr_release_t release,
562 dr_match_t match, void *match_data);
563
564
565extern void * __must_check devres_open_group(struct device *dev, void *id,
566 gfp_t gfp);
567extern void devres_close_group(struct device *dev, void *id);
568extern void devres_remove_group(struct device *dev, void *id);
569extern int devres_release_group(struct device *dev, void *id);
570
571
572extern void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp);
573extern void devm_kfree(struct device *dev, void *p);
574
575void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res);
576void __iomem *devm_request_and_ioremap(struct device *dev,
577 struct resource *res);
578
579
580int devm_add_action(struct device *dev, void (*action)(void *), void *data);
581void devm_remove_action(struct device *dev, void (*action)(void *), void *data);
582
583struct device_dma_parameters {
584
585
586
587
588 unsigned int max_segment_size;
589 unsigned long segment_boundary_mask;
590};
591
592struct acpi_dev_node {
593#ifdef CONFIG_ACPI
594 void *handle;
595#endif
596};
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660struct device {
661 struct device *parent;
662
663 struct device_private *p;
664
665 struct kobject kobj;
666 const char *init_name;
667 const struct device_type *type;
668
669 struct mutex mutex;
670
671
672
673 struct bus_type *bus;
674 struct device_driver *driver;
675
676 void *platform_data;
677
678 struct dev_pm_info power;
679 struct dev_pm_domain *pm_domain;
680
681#ifdef CONFIG_PINCTRL
682 struct dev_pin_info *pins;
683#endif
684
685#ifdef CONFIG_NUMA
686 int numa_node;
687#endif
688 u64 *dma_mask;
689 u64 coherent_dma_mask;
690
691
692
693
694
695 struct device_dma_parameters *dma_parms;
696
697 struct list_head dma_pools;
698
699 struct dma_coherent_mem *dma_mem;
700
701#ifdef CONFIG_CMA
702 struct cma *cma_area;
703
704#endif
705
706 struct dev_archdata archdata;
707
708 struct device_node *of_node;
709 struct acpi_dev_node acpi_node;
710
711 dev_t devt;
712 u32 id;
713
714 spinlock_t devres_lock;
715 struct list_head devres_head;
716
717 struct klist_node knode_class;
718 struct class *class;
719 const struct attribute_group **groups;
720
721 void (*release)(struct device *dev);
722 struct iommu_group *iommu_group;
723};
724
725static inline struct device *kobj_to_dev(struct kobject *kobj)
726{
727 return container_of(kobj, struct device, kobj);
728}
729
730#ifdef CONFIG_ACPI
731#define ACPI_HANDLE(dev) ((dev)->acpi_node.handle)
732#define ACPI_HANDLE_SET(dev, _handle_) (dev)->acpi_node.handle = (_handle_)
733#else
734#define ACPI_HANDLE(dev) (NULL)
735#define ACPI_HANDLE_SET(dev, _handle_) do { } while (0)
736#endif
737
738
739#include <linux/pm_wakeup.h>
740
741static inline const char *dev_name(const struct device *dev)
742{
743
744 if (dev->init_name)
745 return dev->init_name;
746
747 return kobject_name(&dev->kobj);
748}
749
750extern __printf(2, 3)
751int dev_set_name(struct device *dev, const char *name, ...);
752
753#ifdef CONFIG_NUMA
754static inline int dev_to_node(struct device *dev)
755{
756 return dev->numa_node;
757}
758static inline void set_dev_node(struct device *dev, int node)
759{
760 dev->numa_node = node;
761}
762#else
763static inline int dev_to_node(struct device *dev)
764{
765 return -1;
766}
767static inline void set_dev_node(struct device *dev, int node)
768{
769}
770#endif
771
772static inline struct pm_subsys_data *dev_to_psd(struct device *dev)
773{
774 return dev ? dev->power.subsys_data : NULL;
775}
776
777static inline unsigned int dev_get_uevent_suppress(const struct device *dev)
778{
779 return dev->kobj.uevent_suppress;
780}
781
782static inline void dev_set_uevent_suppress(struct device *dev, int val)
783{
784 dev->kobj.uevent_suppress = val;
785}
786
787static inline int device_is_registered(struct device *dev)
788{
789 return dev->kobj.state_in_sysfs;
790}
791
792static inline void device_enable_async_suspend(struct device *dev)
793{
794 if (!dev->power.is_prepared)
795 dev->power.async_suspend = true;
796}
797
798static inline void device_disable_async_suspend(struct device *dev)
799{
800 if (!dev->power.is_prepared)
801 dev->power.async_suspend = false;
802}
803
804static inline bool device_async_suspend_enabled(struct device *dev)
805{
806 return !!dev->power.async_suspend;
807}
808
809static inline void pm_suspend_ignore_children(struct device *dev, bool enable)
810{
811 dev->power.ignore_children = enable;
812}
813
814static inline void dev_pm_syscore_device(struct device *dev, bool val)
815{
816#ifdef CONFIG_PM_SLEEP
817 dev->power.syscore = val;
818#endif
819}
820
821static inline void device_lock(struct device *dev)
822{
823 mutex_lock(&dev->mutex);
824}
825
826static inline int device_trylock(struct device *dev)
827{
828 return mutex_trylock(&dev->mutex);
829}
830
831static inline void device_unlock(struct device *dev)
832{
833 mutex_unlock(&dev->mutex);
834}
835
836void driver_init(void);
837
838
839
840
841extern int __must_check device_register(struct device *dev);
842extern void device_unregister(struct device *dev);
843extern void device_initialize(struct device *dev);
844extern int __must_check device_add(struct device *dev);
845extern void device_del(struct device *dev);
846extern int device_for_each_child(struct device *dev, void *data,
847 int (*fn)(struct device *dev, void *data));
848extern struct device *device_find_child(struct device *dev, void *data,
849 int (*match)(struct device *dev, void *data));
850extern int device_rename(struct device *dev, const char *new_name);
851extern int device_move(struct device *dev, struct device *new_parent,
852 enum dpm_order dpm_order);
853extern const char *device_get_devnode(struct device *dev,
854 umode_t *mode, kuid_t *uid, kgid_t *gid,
855 const char **tmp);
856extern void *dev_get_drvdata(const struct device *dev);
857extern int dev_set_drvdata(struct device *dev, void *data);
858
859
860
861
862extern struct device *__root_device_register(const char *name,
863 struct module *owner);
864
865
866
867
868
869#define root_device_register(name) \
870 __root_device_register(name, THIS_MODULE)
871
872extern void root_device_unregister(struct device *root);
873
874static inline void *dev_get_platdata(const struct device *dev)
875{
876 return dev->platform_data;
877}
878
879
880
881
882
883extern int __must_check device_bind_driver(struct device *dev);
884extern void device_release_driver(struct device *dev);
885extern int __must_check device_attach(struct device *dev);
886extern int __must_check driver_attach(struct device_driver *drv);
887extern int __must_check device_reprobe(struct device *dev);
888
889
890
891
892extern struct device *device_create_vargs(struct class *cls,
893 struct device *parent,
894 dev_t devt,
895 void *drvdata,
896 const char *fmt,
897 va_list vargs);
898extern __printf(5, 6)
899struct device *device_create(struct class *cls, struct device *parent,
900 dev_t devt, void *drvdata,
901 const char *fmt, ...);
902extern void device_destroy(struct class *cls, dev_t devt);
903
904
905
906
907
908
909
910extern int (*platform_notify)(struct device *dev);
911
912extern int (*platform_notify_remove)(struct device *dev);
913
914
915
916
917
918
919extern struct device *get_device(struct device *dev);
920extern void put_device(struct device *dev);
921
922#ifdef CONFIG_DEVTMPFS
923extern int devtmpfs_create_node(struct device *dev);
924extern int devtmpfs_delete_node(struct device *dev);
925extern int devtmpfs_mount(const char *mntdir);
926#else
927static inline int devtmpfs_create_node(struct device *dev) { return 0; }
928static inline int devtmpfs_delete_node(struct device *dev) { return 0; }
929static inline int devtmpfs_mount(const char *mountpoint) { return 0; }
930#endif
931
932
933extern void device_shutdown(void);
934
935
936extern const char *dev_driver_string(const struct device *dev);
937
938
939#ifdef CONFIG_PRINTK
940
941extern __printf(3, 0)
942int dev_vprintk_emit(int level, const struct device *dev,
943 const char *fmt, va_list args);
944extern __printf(3, 4)
945int dev_printk_emit(int level, const struct device *dev, const char *fmt, ...);
946
947extern __printf(3, 4)
948int dev_printk(const char *level, const struct device *dev,
949 const char *fmt, ...);
950extern __printf(2, 3)
951int dev_emerg(const struct device *dev, const char *fmt, ...);
952extern __printf(2, 3)
953int dev_alert(const struct device *dev, const char *fmt, ...);
954extern __printf(2, 3)
955int dev_crit(const struct device *dev, const char *fmt, ...);
956extern __printf(2, 3)
957int dev_err(const struct device *dev, const char *fmt, ...);
958extern __printf(2, 3)
959int dev_warn(const struct device *dev, const char *fmt, ...);
960extern __printf(2, 3)
961int dev_notice(const struct device *dev, const char *fmt, ...);
962extern __printf(2, 3)
963int _dev_info(const struct device *dev, const char *fmt, ...);
964
965#else
966
967static inline __printf(3, 0)
968int dev_vprintk_emit(int level, const struct device *dev,
969 const char *fmt, va_list args)
970{ return 0; }
971static inline __printf(3, 4)
972int dev_printk_emit(int level, const struct device *dev, const char *fmt, ...)
973{ return 0; }
974
975static inline int __dev_printk(const char *level, const struct device *dev,
976 struct va_format *vaf)
977{ return 0; }
978static inline __printf(3, 4)
979int dev_printk(const char *level, const struct device *dev,
980 const char *fmt, ...)
981{ return 0; }
982
983static inline __printf(2, 3)
984int dev_emerg(const struct device *dev, const char *fmt, ...)
985{ return 0; }
986static inline __printf(2, 3)
987int dev_crit(const struct device *dev, const char *fmt, ...)
988{ return 0; }
989static inline __printf(2, 3)
990int dev_alert(const struct device *dev, const char *fmt, ...)
991{ return 0; }
992static inline __printf(2, 3)
993int dev_err(const struct device *dev, const char *fmt, ...)
994{ return 0; }
995static inline __printf(2, 3)
996int dev_warn(const struct device *dev, const char *fmt, ...)
997{ return 0; }
998static inline __printf(2, 3)
999int dev_notice(const struct device *dev, const char *fmt, ...)
1000{ return 0; }
1001static inline __printf(2, 3)
1002int _dev_info(const struct device *dev, const char *fmt, ...)
1003{ return 0; }
1004
1005#endif
1006
1007
1008
1009
1010
1011
1012
1013
1014#define dev_info(dev, fmt, arg...) _dev_info(dev, fmt, ##arg)
1015
1016#if defined(CONFIG_DYNAMIC_DEBUG)
1017#define dev_dbg(dev, format, ...) \
1018do { \
1019 dynamic_dev_dbg(dev, format, ##__VA_ARGS__); \
1020} while (0)
1021#elif defined(DEBUG)
1022#define dev_dbg(dev, format, arg...) \
1023 dev_printk(KERN_DEBUG, dev, format, ##arg)
1024#else
1025#define dev_dbg(dev, format, arg...) \
1026({ \
1027 if (0) \
1028 dev_printk(KERN_DEBUG, dev, format, ##arg); \
1029 0; \
1030})
1031#endif
1032
1033#define dev_level_ratelimited(dev_level, dev, fmt, ...) \
1034do { \
1035 static DEFINE_RATELIMIT_STATE(_rs, \
1036 DEFAULT_RATELIMIT_INTERVAL, \
1037 DEFAULT_RATELIMIT_BURST); \
1038 if (__ratelimit(&_rs)) \
1039 dev_level(dev, fmt, ##__VA_ARGS__); \
1040} while (0)
1041
1042#define dev_emerg_ratelimited(dev, fmt, ...) \
1043 dev_level_ratelimited(dev_emerg, dev, fmt, ##__VA_ARGS__)
1044#define dev_alert_ratelimited(dev, fmt, ...) \
1045 dev_level_ratelimited(dev_alert, dev, fmt, ##__VA_ARGS__)
1046#define dev_crit_ratelimited(dev, fmt, ...) \
1047 dev_level_ratelimited(dev_crit, dev, fmt, ##__VA_ARGS__)
1048#define dev_err_ratelimited(dev, fmt, ...) \
1049 dev_level_ratelimited(dev_err, dev, fmt, ##__VA_ARGS__)
1050#define dev_warn_ratelimited(dev, fmt, ...) \
1051 dev_level_ratelimited(dev_warn, dev, fmt, ##__VA_ARGS__)
1052#define dev_notice_ratelimited(dev, fmt, ...) \
1053 dev_level_ratelimited(dev_notice, dev, fmt, ##__VA_ARGS__)
1054#define dev_info_ratelimited(dev, fmt, ...) \
1055 dev_level_ratelimited(dev_info, dev, fmt, ##__VA_ARGS__)
1056#if defined(CONFIG_DYNAMIC_DEBUG) || defined(DEBUG)
1057#define dev_dbg_ratelimited(dev, fmt, ...) \
1058do { \
1059 static DEFINE_RATELIMIT_STATE(_rs, \
1060 DEFAULT_RATELIMIT_INTERVAL, \
1061 DEFAULT_RATELIMIT_BURST); \
1062 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
1063 if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
1064 __ratelimit(&_rs)) \
1065 __dynamic_pr_debug(&descriptor, pr_fmt(fmt), \
1066 ##__VA_ARGS__); \
1067} while (0)
1068#else
1069#define dev_dbg_ratelimited(dev, fmt, ...) \
1070 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
1071#endif
1072
1073#ifdef VERBOSE_DEBUG
1074#define dev_vdbg dev_dbg
1075#else
1076#define dev_vdbg(dev, format, arg...) \
1077({ \
1078 if (0) \
1079 dev_printk(KERN_DEBUG, dev, format, ##arg); \
1080 0; \
1081})
1082#endif
1083
1084
1085
1086
1087
1088
1089#define dev_WARN(dev, format, arg...) \
1090 WARN(1, "Device: %s\n" format, dev_driver_string(dev), ## arg);
1091
1092#define dev_WARN_ONCE(dev, condition, format, arg...) \
1093 WARN_ONCE(condition, "Device %s\n" format, \
1094 dev_driver_string(dev), ## arg)
1095
1096
1097#define MODULE_ALIAS_CHARDEV(major,minor) \
1098 MODULE_ALIAS("char-major-" __stringify(major) "-" __stringify(minor))
1099#define MODULE_ALIAS_CHARDEV_MAJOR(major) \
1100 MODULE_ALIAS("char-major-" __stringify(major) "-*")
1101
1102#ifdef CONFIG_SYSFS_DEPRECATED
1103extern long sysfs_deprecated;
1104#else
1105#define sysfs_deprecated 0
1106#endif
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122#define module_driver(__driver, __register, __unregister, ...) \
1123static int __init __driver##_init(void) \
1124{ \
1125 return __register(&(__driver) , ##__VA_ARGS__); \
1126} \
1127module_init(__driver##_init); \
1128static void __exit __driver##_exit(void) \
1129{ \
1130 __unregister(&(__driver) , ##__VA_ARGS__); \
1131} \
1132module_exit(__driver##_exit);
1133
1134#endif
1135