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 <linux/gfp.h>
30#include <asm/device.h>
31
32struct device;
33struct device_private;
34struct device_driver;
35struct driver_private;
36struct module;
37struct class;
38struct subsys_private;
39struct bus_type;
40struct device_node;
41struct fwnode_handle;
42struct iommu_ops;
43struct iommu_group;
44struct iommu_fwspec;
45
46struct bus_attribute {
47 struct attribute attr;
48 ssize_t (*show)(struct bus_type *bus, char *buf);
49 ssize_t (*store)(struct bus_type *bus, const char *buf, size_t count);
50};
51
52#define BUS_ATTR(_name, _mode, _show, _store) \
53 struct bus_attribute bus_attr_##_name = __ATTR(_name, _mode, _show, _store)
54#define BUS_ATTR_RW(_name) \
55 struct bus_attribute bus_attr_##_name = __ATTR_RW(_name)
56#define BUS_ATTR_RO(_name) \
57 struct bus_attribute bus_attr_##_name = __ATTR_RO(_name)
58
59extern int __must_check bus_create_file(struct bus_type *,
60 struct bus_attribute *);
61extern void bus_remove_file(struct bus_type *, struct bus_attribute *);
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109struct bus_type {
110 const char *name;
111 const char *dev_name;
112 struct device *dev_root;
113 struct device_attribute *dev_attrs;
114 const struct attribute_group **bus_groups;
115 const struct attribute_group **dev_groups;
116 const struct attribute_group **drv_groups;
117
118 int (*match)(struct device *dev, struct device_driver *drv);
119 int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
120 int (*probe)(struct device *dev);
121 int (*remove)(struct device *dev);
122 void (*shutdown)(struct device *dev);
123
124 int (*online)(struct device *dev);
125 int (*offline)(struct device *dev);
126
127 int (*suspend)(struct device *dev, pm_message_t state);
128 int (*resume)(struct device *dev);
129
130 const struct dev_pm_ops *pm;
131
132 const struct iommu_ops *iommu_ops;
133
134 struct subsys_private *p;
135 struct lock_class_key lock_key;
136};
137
138extern int __must_check bus_register(struct bus_type *bus);
139
140extern void bus_unregister(struct bus_type *bus);
141
142extern int __must_check bus_rescan_devices(struct bus_type *bus);
143
144
145struct subsys_dev_iter {
146 struct klist_iter ki;
147 const struct device_type *type;
148};
149void subsys_dev_iter_init(struct subsys_dev_iter *iter,
150 struct bus_type *subsys,
151 struct device *start,
152 const struct device_type *type);
153struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter);
154void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
155
156int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
157 int (*fn)(struct device *dev, void *data));
158struct device *bus_find_device(struct bus_type *bus, struct device *start,
159 void *data,
160 int (*match)(struct device *dev, void *data));
161struct device *bus_find_device_by_name(struct bus_type *bus,
162 struct device *start,
163 const char *name);
164struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
165 struct device *hint);
166int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
167 void *data, int (*fn)(struct device_driver *, void *));
168void bus_sort_breadthfirst(struct bus_type *bus,
169 int (*compare)(const struct device *a,
170 const struct device *b));
171
172
173
174
175
176
177struct notifier_block;
178
179extern int bus_register_notifier(struct bus_type *bus,
180 struct notifier_block *nb);
181extern int bus_unregister_notifier(struct bus_type *bus,
182 struct notifier_block *nb);
183
184
185
186
187
188#define BUS_NOTIFY_ADD_DEVICE 0x00000001
189#define BUS_NOTIFY_DEL_DEVICE 0x00000002
190#define BUS_NOTIFY_REMOVED_DEVICE 0x00000003
191#define BUS_NOTIFY_BIND_DRIVER 0x00000004
192
193#define BUS_NOTIFY_BOUND_DRIVER 0x00000005
194#define BUS_NOTIFY_UNBIND_DRIVER 0x00000006
195
196#define BUS_NOTIFY_UNBOUND_DRIVER 0x00000007
197
198#define BUS_NOTIFY_DRIVER_NOT_BOUND 0x00000008
199
200extern struct kset *bus_get_kset(struct bus_type *bus);
201extern struct klist *bus_get_device_klist(struct bus_type *bus);
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225enum probe_type {
226 PROBE_DEFAULT_STRATEGY,
227 PROBE_PREFER_ASYNCHRONOUS,
228 PROBE_FORCE_SYNCHRONOUS,
229};
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264struct device_driver {
265 const char *name;
266 struct bus_type *bus;
267
268 struct module *owner;
269 const char *mod_name;
270
271 bool suppress_bind_attrs;
272 enum probe_type probe_type;
273
274 const struct of_device_id *of_match_table;
275 const struct acpi_device_id *acpi_match_table;
276
277 int (*probe) (struct device *dev);
278 int (*remove) (struct device *dev);
279 void (*shutdown) (struct device *dev);
280 int (*suspend) (struct device *dev, pm_message_t state);
281 int (*resume) (struct device *dev);
282 const struct attribute_group **groups;
283
284 const struct dev_pm_ops *pm;
285
286 struct driver_private *p;
287};
288
289
290extern int __must_check driver_register(struct device_driver *drv);
291extern void driver_unregister(struct device_driver *drv);
292
293extern struct device_driver *driver_find(const char *name,
294 struct bus_type *bus);
295extern int driver_probe_done(void);
296extern void wait_for_device_probe(void);
297
298
299
300
301struct driver_attribute {
302 struct attribute attr;
303 ssize_t (*show)(struct device_driver *driver, char *buf);
304 ssize_t (*store)(struct device_driver *driver, const char *buf,
305 size_t count);
306};
307
308#define DRIVER_ATTR(_name, _mode, _show, _store) \
309 struct driver_attribute driver_attr_##_name = __ATTR(_name, _mode, _show, _store)
310#define DRIVER_ATTR_RW(_name) \
311 struct driver_attribute driver_attr_##_name = __ATTR_RW(_name)
312#define DRIVER_ATTR_RO(_name) \
313 struct driver_attribute driver_attr_##_name = __ATTR_RO(_name)
314#define DRIVER_ATTR_WO(_name) \
315 struct driver_attribute driver_attr_##_name = __ATTR_WO(_name)
316
317extern int __must_check driver_create_file(struct device_driver *driver,
318 const struct driver_attribute *attr);
319extern void driver_remove_file(struct device_driver *driver,
320 const struct driver_attribute *attr);
321
322extern int __must_check driver_for_each_device(struct device_driver *drv,
323 struct device *start,
324 void *data,
325 int (*fn)(struct device *dev,
326 void *));
327struct device *driver_find_device(struct device_driver *drv,
328 struct device *start, void *data,
329 int (*match)(struct device *dev, void *data));
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344struct subsys_interface {
345 const char *name;
346 struct bus_type *subsys;
347 struct list_head node;
348 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
349 void (*remove_dev)(struct device *dev, struct subsys_interface *sif);
350};
351
352int subsys_interface_register(struct subsys_interface *sif);
353void subsys_interface_unregister(struct subsys_interface *sif);
354
355int subsys_system_register(struct bus_type *subsys,
356 const struct attribute_group **groups);
357int subsys_virtual_register(struct bus_type *subsys,
358 const struct attribute_group **groups);
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388struct class {
389 const char *name;
390 struct module *owner;
391
392 struct class_attribute *class_attrs;
393 const struct attribute_group **dev_groups;
394 struct kobject *dev_kobj;
395
396 int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env);
397 char *(*devnode)(struct device *dev, umode_t *mode);
398
399 void (*class_release)(struct class *class);
400 void (*dev_release)(struct device *dev);
401
402 int (*suspend)(struct device *dev, pm_message_t state);
403 int (*resume)(struct device *dev);
404
405 const struct kobj_ns_type_operations *ns_type;
406 const void *(*namespace)(struct device *dev);
407
408 const struct dev_pm_ops *pm;
409
410 struct subsys_private *p;
411};
412
413struct class_dev_iter {
414 struct klist_iter ki;
415 const struct device_type *type;
416};
417
418extern struct kobject *sysfs_dev_block_kobj;
419extern struct kobject *sysfs_dev_char_kobj;
420extern int __must_check __class_register(struct class *class,
421 struct lock_class_key *key);
422extern void class_unregister(struct class *class);
423
424
425
426#define class_register(class) \
427({ \
428 static struct lock_class_key __key; \
429 __class_register(class, &__key); \
430})
431
432struct class_compat;
433struct class_compat *class_compat_register(const char *name);
434void class_compat_unregister(struct class_compat *cls);
435int class_compat_create_link(struct class_compat *cls, struct device *dev,
436 struct device *device_link);
437void class_compat_remove_link(struct class_compat *cls, struct device *dev,
438 struct device *device_link);
439
440extern void class_dev_iter_init(struct class_dev_iter *iter,
441 struct class *class,
442 struct device *start,
443 const struct device_type *type);
444extern struct device *class_dev_iter_next(struct class_dev_iter *iter);
445extern void class_dev_iter_exit(struct class_dev_iter *iter);
446
447extern int class_for_each_device(struct class *class, struct device *start,
448 void *data,
449 int (*fn)(struct device *dev, void *data));
450extern struct device *class_find_device(struct class *class,
451 struct device *start, const void *data,
452 int (*match)(struct device *, const void *));
453
454struct class_attribute {
455 struct attribute attr;
456 ssize_t (*show)(struct class *class, struct class_attribute *attr,
457 char *buf);
458 ssize_t (*store)(struct class *class, struct class_attribute *attr,
459 const char *buf, size_t count);
460};
461
462#define CLASS_ATTR(_name, _mode, _show, _store) \
463 struct class_attribute class_attr_##_name = __ATTR(_name, _mode, _show, _store)
464#define CLASS_ATTR_RW(_name) \
465 struct class_attribute class_attr_##_name = __ATTR_RW(_name)
466#define CLASS_ATTR_RO(_name) \
467 struct class_attribute class_attr_##_name = __ATTR_RO(_name)
468
469extern int __must_check class_create_file_ns(struct class *class,
470 const struct class_attribute *attr,
471 const void *ns);
472extern void class_remove_file_ns(struct class *class,
473 const struct class_attribute *attr,
474 const void *ns);
475
476static inline int __must_check class_create_file(struct class *class,
477 const struct class_attribute *attr)
478{
479 return class_create_file_ns(class, attr, NULL);
480}
481
482static inline void class_remove_file(struct class *class,
483 const struct class_attribute *attr)
484{
485 return class_remove_file_ns(class, attr, NULL);
486}
487
488
489struct class_attribute_string {
490 struct class_attribute attr;
491 char *str;
492};
493
494
495#define _CLASS_ATTR_STRING(_name, _mode, _str) \
496 { __ATTR(_name, _mode, show_class_attr_string, NULL), _str }
497#define CLASS_ATTR_STRING(_name, _mode, _str) \
498 struct class_attribute_string class_attr_##_name = \
499 _CLASS_ATTR_STRING(_name, _mode, _str)
500
501extern ssize_t show_class_attr_string(struct class *class, struct class_attribute *attr,
502 char *buf);
503
504struct class_interface {
505 struct list_head node;
506 struct class *class;
507
508 int (*add_dev) (struct device *, struct class_interface *);
509 void (*remove_dev) (struct device *, struct class_interface *);
510};
511
512extern int __must_check class_interface_register(struct class_interface *);
513extern void class_interface_unregister(struct class_interface *);
514
515extern struct class * __must_check __class_create(struct module *owner,
516 const char *name,
517 struct lock_class_key *key);
518extern void class_destroy(struct class *cls);
519
520
521
522#define class_create(owner, name) \
523({ \
524 static struct lock_class_key __key; \
525 __class_create(owner, name, &__key); \
526})
527
528
529
530
531
532
533
534
535
536
537struct device_type {
538 const char *name;
539 const struct attribute_group **groups;
540 int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
541 char *(*devnode)(struct device *dev, umode_t *mode,
542 kuid_t *uid, kgid_t *gid);
543 void (*release)(struct device *dev);
544
545 const struct dev_pm_ops *pm;
546};
547
548
549struct device_attribute {
550 struct attribute attr;
551 ssize_t (*show)(struct device *dev, struct device_attribute *attr,
552 char *buf);
553 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
554 const char *buf, size_t count);
555};
556
557struct dev_ext_attribute {
558 struct device_attribute attr;
559 void *var;
560};
561
562ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
563 char *buf);
564ssize_t device_store_ulong(struct device *dev, struct device_attribute *attr,
565 const char *buf, size_t count);
566ssize_t device_show_int(struct device *dev, struct device_attribute *attr,
567 char *buf);
568ssize_t device_store_int(struct device *dev, struct device_attribute *attr,
569 const char *buf, size_t count);
570ssize_t device_show_bool(struct device *dev, struct device_attribute *attr,
571 char *buf);
572ssize_t device_store_bool(struct device *dev, struct device_attribute *attr,
573 const char *buf, size_t count);
574
575#define DEVICE_ATTR(_name, _mode, _show, _store) \
576 struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)
577#define DEVICE_ATTR_RW(_name) \
578 struct device_attribute dev_attr_##_name = __ATTR_RW(_name)
579#define DEVICE_ATTR_RO(_name) \
580 struct device_attribute dev_attr_##_name = __ATTR_RO(_name)
581#define DEVICE_ATTR_WO(_name) \
582 struct device_attribute dev_attr_##_name = __ATTR_WO(_name)
583#define DEVICE_ULONG_ATTR(_name, _mode, _var) \
584 struct dev_ext_attribute dev_attr_##_name = \
585 { __ATTR(_name, _mode, device_show_ulong, device_store_ulong), &(_var) }
586#define DEVICE_INT_ATTR(_name, _mode, _var) \
587 struct dev_ext_attribute dev_attr_##_name = \
588 { __ATTR(_name, _mode, device_show_int, device_store_int), &(_var) }
589#define DEVICE_BOOL_ATTR(_name, _mode, _var) \
590 struct dev_ext_attribute dev_attr_##_name = \
591 { __ATTR(_name, _mode, device_show_bool, device_store_bool), &(_var) }
592#define DEVICE_ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) \
593 struct device_attribute dev_attr_##_name = \
594 __ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store)
595
596extern int device_create_file(struct device *device,
597 const struct device_attribute *entry);
598extern void device_remove_file(struct device *dev,
599 const struct device_attribute *attr);
600extern bool device_remove_file_self(struct device *dev,
601 const struct device_attribute *attr);
602extern int __must_check device_create_bin_file(struct device *dev,
603 const struct bin_attribute *attr);
604extern void device_remove_bin_file(struct device *dev,
605 const struct bin_attribute *attr);
606
607
608typedef void (*dr_release_t)(struct device *dev, void *res);
609typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data);
610
611#ifdef CONFIG_DEBUG_DEVRES
612extern void *__devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp,
613 int nid, const char *name) __malloc;
614#define devres_alloc(release, size, gfp) \
615 __devres_alloc_node(release, size, gfp, NUMA_NO_NODE, #release)
616#define devres_alloc_node(release, size, gfp, nid) \
617 __devres_alloc_node(release, size, gfp, nid, #release)
618#else
619extern void *devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp,
620 int nid) __malloc;
621static inline void *devres_alloc(dr_release_t release, size_t size, gfp_t gfp)
622{
623 return devres_alloc_node(release, size, gfp, NUMA_NO_NODE);
624}
625#endif
626
627extern void devres_for_each_res(struct device *dev, dr_release_t release,
628 dr_match_t match, void *match_data,
629 void (*fn)(struct device *, void *, void *),
630 void *data);
631extern void devres_free(void *res);
632extern void devres_add(struct device *dev, void *res);
633extern void *devres_find(struct device *dev, dr_release_t release,
634 dr_match_t match, void *match_data);
635extern void *devres_get(struct device *dev, void *new_res,
636 dr_match_t match, void *match_data);
637extern void *devres_remove(struct device *dev, dr_release_t release,
638 dr_match_t match, void *match_data);
639extern int devres_destroy(struct device *dev, dr_release_t release,
640 dr_match_t match, void *match_data);
641extern int devres_release(struct device *dev, dr_release_t release,
642 dr_match_t match, void *match_data);
643
644
645extern void * __must_check devres_open_group(struct device *dev, void *id,
646 gfp_t gfp);
647extern void devres_close_group(struct device *dev, void *id);
648extern void devres_remove_group(struct device *dev, void *id);
649extern int devres_release_group(struct device *dev, void *id);
650
651
652extern void *devm_kmalloc(struct device *dev, size_t size, gfp_t gfp) __malloc;
653extern __printf(3, 0)
654char *devm_kvasprintf(struct device *dev, gfp_t gfp, const char *fmt,
655 va_list ap) __malloc;
656extern __printf(3, 4)
657char *devm_kasprintf(struct device *dev, gfp_t gfp, const char *fmt, ...) __malloc;
658static inline void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp)
659{
660 return devm_kmalloc(dev, size, gfp | __GFP_ZERO);
661}
662static inline void *devm_kmalloc_array(struct device *dev,
663 size_t n, size_t size, gfp_t flags)
664{
665 if (size != 0 && n > SIZE_MAX / size)
666 return NULL;
667 return devm_kmalloc(dev, n * size, flags);
668}
669static inline void *devm_kcalloc(struct device *dev,
670 size_t n, size_t size, gfp_t flags)
671{
672 return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO);
673}
674extern void devm_kfree(struct device *dev, void *p);
675extern char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc;
676extern void *devm_kmemdup(struct device *dev, const void *src, size_t len,
677 gfp_t gfp);
678
679extern unsigned long devm_get_free_pages(struct device *dev,
680 gfp_t gfp_mask, unsigned int order);
681extern void devm_free_pages(struct device *dev, unsigned long addr);
682
683void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res);
684
685
686int devm_add_action(struct device *dev, void (*action)(void *), void *data);
687void devm_remove_action(struct device *dev, void (*action)(void *), void *data);
688
689static inline int devm_add_action_or_reset(struct device *dev,
690 void (*action)(void *), void *data)
691{
692 int ret;
693
694 ret = devm_add_action(dev, action, data);
695 if (ret)
696 action(data);
697
698 return ret;
699}
700
701struct device_dma_parameters {
702
703
704
705
706 unsigned int max_segment_size;
707 unsigned long segment_boundary_mask;
708};
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782struct device {
783 struct device *parent;
784
785 struct device_private *p;
786
787 struct kobject kobj;
788 const char *init_name;
789 const struct device_type *type;
790
791 struct mutex mutex;
792
793
794
795 struct bus_type *bus;
796 struct device_driver *driver;
797
798 void *platform_data;
799
800 void *driver_data;
801
802 struct dev_pm_info power;
803 struct dev_pm_domain *pm_domain;
804
805#ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN
806 struct irq_domain *msi_domain;
807#endif
808#ifdef CONFIG_PINCTRL
809 struct dev_pin_info *pins;
810#endif
811#ifdef CONFIG_GENERIC_MSI_IRQ
812 struct list_head msi_list;
813#endif
814
815#ifdef CONFIG_NUMA
816 int numa_node;
817#endif
818 u64 *dma_mask;
819 u64 coherent_dma_mask;
820
821
822
823
824 unsigned long dma_pfn_offset;
825
826 struct device_dma_parameters *dma_parms;
827
828 struct list_head dma_pools;
829
830 struct dma_coherent_mem *dma_mem;
831
832#ifdef CONFIG_DMA_CMA
833 struct cma *cma_area;
834
835#endif
836
837 struct dev_archdata archdata;
838
839 struct device_node *of_node;
840 struct fwnode_handle *fwnode;
841
842 dev_t devt;
843 u32 id;
844
845 spinlock_t devres_lock;
846 struct list_head devres_head;
847
848 struct klist_node knode_class;
849 struct class *class;
850 const struct attribute_group **groups;
851
852 void (*release)(struct device *dev);
853 struct iommu_group *iommu_group;
854 struct iommu_fwspec *iommu_fwspec;
855
856 bool offline_disabled:1;
857 bool offline:1;
858};
859
860static inline struct device *kobj_to_dev(struct kobject *kobj)
861{
862 return container_of(kobj, struct device, kobj);
863}
864
865
866#include <linux/pm_wakeup.h>
867
868static inline const char *dev_name(const struct device *dev)
869{
870
871 if (dev->init_name)
872 return dev->init_name;
873
874 return kobject_name(&dev->kobj);
875}
876
877extern __printf(2, 3)
878int dev_set_name(struct device *dev, const char *name, ...);
879
880#ifdef CONFIG_NUMA
881static inline int dev_to_node(struct device *dev)
882{
883 return dev->numa_node;
884}
885static inline void set_dev_node(struct device *dev, int node)
886{
887 dev->numa_node = node;
888}
889#else
890static inline int dev_to_node(struct device *dev)
891{
892 return -1;
893}
894static inline void set_dev_node(struct device *dev, int node)
895{
896}
897#endif
898
899static inline struct irq_domain *dev_get_msi_domain(const struct device *dev)
900{
901#ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN
902 return dev->msi_domain;
903#else
904 return NULL;
905#endif
906}
907
908static inline void dev_set_msi_domain(struct device *dev, struct irq_domain *d)
909{
910#ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN
911 dev->msi_domain = d;
912#endif
913}
914
915static inline void *dev_get_drvdata(const struct device *dev)
916{
917 return dev->driver_data;
918}
919
920static inline void dev_set_drvdata(struct device *dev, void *data)
921{
922 dev->driver_data = data;
923}
924
925static inline struct pm_subsys_data *dev_to_psd(struct device *dev)
926{
927 return dev ? dev->power.subsys_data : NULL;
928}
929
930static inline unsigned int dev_get_uevent_suppress(const struct device *dev)
931{
932 return dev->kobj.uevent_suppress;
933}
934
935static inline void dev_set_uevent_suppress(struct device *dev, int val)
936{
937 dev->kobj.uevent_suppress = val;
938}
939
940static inline int device_is_registered(struct device *dev)
941{
942 return dev->kobj.state_in_sysfs;
943}
944
945static inline void device_enable_async_suspend(struct device *dev)
946{
947 if (!dev->power.is_prepared)
948 dev->power.async_suspend = true;
949}
950
951static inline void device_disable_async_suspend(struct device *dev)
952{
953 if (!dev->power.is_prepared)
954 dev->power.async_suspend = false;
955}
956
957static inline bool device_async_suspend_enabled(struct device *dev)
958{
959 return !!dev->power.async_suspend;
960}
961
962static inline void dev_pm_syscore_device(struct device *dev, bool val)
963{
964#ifdef CONFIG_PM_SLEEP
965 dev->power.syscore = val;
966#endif
967}
968
969static inline void device_lock(struct device *dev)
970{
971 mutex_lock(&dev->mutex);
972}
973
974static inline int device_lock_interruptible(struct device *dev)
975{
976 return mutex_lock_interruptible(&dev->mutex);
977}
978
979static inline int device_trylock(struct device *dev)
980{
981 return mutex_trylock(&dev->mutex);
982}
983
984static inline void device_unlock(struct device *dev)
985{
986 mutex_unlock(&dev->mutex);
987}
988
989static inline void device_lock_assert(struct device *dev)
990{
991 lockdep_assert_held(&dev->mutex);
992}
993
994static inline struct device_node *dev_of_node(struct device *dev)
995{
996 if (!IS_ENABLED(CONFIG_OF))
997 return NULL;
998 return dev->of_node;
999}
1000
1001void driver_init(void);
1002
1003
1004
1005
1006extern int __must_check device_register(struct device *dev);
1007extern void device_unregister(struct device *dev);
1008extern void device_initialize(struct device *dev);
1009extern int __must_check device_add(struct device *dev);
1010extern void device_del(struct device *dev);
1011extern int device_for_each_child(struct device *dev, void *data,
1012 int (*fn)(struct device *dev, void *data));
1013extern int device_for_each_child_reverse(struct device *dev, void *data,
1014 int (*fn)(struct device *dev, void *data));
1015extern struct device *device_find_child(struct device *dev, void *data,
1016 int (*match)(struct device *dev, void *data));
1017extern int device_rename(struct device *dev, const char *new_name);
1018extern int device_move(struct device *dev, struct device *new_parent,
1019 enum dpm_order dpm_order);
1020extern const char *device_get_devnode(struct device *dev,
1021 umode_t *mode, kuid_t *uid, kgid_t *gid,
1022 const char **tmp);
1023
1024static inline bool device_supports_offline(struct device *dev)
1025{
1026 return dev->bus && dev->bus->offline && dev->bus->online;
1027}
1028
1029extern void lock_device_hotplug(void);
1030extern void unlock_device_hotplug(void);
1031extern int lock_device_hotplug_sysfs(void);
1032extern int device_offline(struct device *dev);
1033extern int device_online(struct device *dev);
1034extern void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode);
1035extern void set_secondary_fwnode(struct device *dev, struct fwnode_handle *fwnode);
1036
1037
1038
1039
1040extern struct device *__root_device_register(const char *name,
1041 struct module *owner);
1042
1043
1044#define root_device_register(name) \
1045 __root_device_register(name, THIS_MODULE)
1046
1047extern void root_device_unregister(struct device *root);
1048
1049static inline void *dev_get_platdata(const struct device *dev)
1050{
1051 return dev->platform_data;
1052}
1053
1054
1055
1056
1057
1058extern int __must_check device_bind_driver(struct device *dev);
1059extern void device_release_driver(struct device *dev);
1060extern int __must_check device_attach(struct device *dev);
1061extern int __must_check driver_attach(struct device_driver *drv);
1062extern void device_initial_probe(struct device *dev);
1063extern int __must_check device_reprobe(struct device *dev);
1064
1065extern bool device_is_bound(struct device *dev);
1066
1067
1068
1069
1070extern __printf(5, 0)
1071struct device *device_create_vargs(struct class *cls, struct device *parent,
1072 dev_t devt, void *drvdata,
1073 const char *fmt, va_list vargs);
1074extern __printf(5, 6)
1075struct device *device_create(struct class *cls, struct device *parent,
1076 dev_t devt, void *drvdata,
1077 const char *fmt, ...);
1078extern __printf(6, 7)
1079struct device *device_create_with_groups(struct class *cls,
1080 struct device *parent, dev_t devt, void *drvdata,
1081 const struct attribute_group **groups,
1082 const char *fmt, ...);
1083extern void device_destroy(struct class *cls, dev_t devt);
1084
1085
1086
1087
1088
1089
1090
1091extern int (*platform_notify)(struct device *dev);
1092
1093extern int (*platform_notify_remove)(struct device *dev);
1094
1095
1096
1097
1098
1099
1100extern struct device *get_device(struct device *dev);
1101extern void put_device(struct device *dev);
1102
1103#ifdef CONFIG_DEVTMPFS
1104extern int devtmpfs_create_node(struct device *dev);
1105extern int devtmpfs_delete_node(struct device *dev);
1106extern int devtmpfs_mount(const char *mntdir);
1107#else
1108static inline int devtmpfs_create_node(struct device *dev) { return 0; }
1109static inline int devtmpfs_delete_node(struct device *dev) { return 0; }
1110static inline int devtmpfs_mount(const char *mountpoint) { return 0; }
1111#endif
1112
1113
1114extern void device_shutdown(void);
1115
1116
1117extern const char *dev_driver_string(const struct device *dev);
1118
1119
1120#ifdef CONFIG_PRINTK
1121
1122extern __printf(3, 0)
1123int dev_vprintk_emit(int level, const struct device *dev,
1124 const char *fmt, va_list args);
1125extern __printf(3, 4)
1126int dev_printk_emit(int level, const struct device *dev, const char *fmt, ...);
1127
1128extern __printf(3, 4)
1129void dev_printk(const char *level, const struct device *dev,
1130 const char *fmt, ...);
1131extern __printf(2, 3)
1132void dev_emerg(const struct device *dev, const char *fmt, ...);
1133extern __printf(2, 3)
1134void dev_alert(const struct device *dev, const char *fmt, ...);
1135extern __printf(2, 3)
1136void dev_crit(const struct device *dev, const char *fmt, ...);
1137extern __printf(2, 3)
1138void dev_err(const struct device *dev, const char *fmt, ...);
1139extern __printf(2, 3)
1140void dev_warn(const struct device *dev, const char *fmt, ...);
1141extern __printf(2, 3)
1142void dev_notice(const struct device *dev, const char *fmt, ...);
1143extern __printf(2, 3)
1144void _dev_info(const struct device *dev, const char *fmt, ...);
1145
1146#else
1147
1148static inline __printf(3, 0)
1149int dev_vprintk_emit(int level, const struct device *dev,
1150 const char *fmt, va_list args)
1151{ return 0; }
1152static inline __printf(3, 4)
1153int dev_printk_emit(int level, const struct device *dev, const char *fmt, ...)
1154{ return 0; }
1155
1156static inline void __dev_printk(const char *level, const struct device *dev,
1157 struct va_format *vaf)
1158{}
1159static inline __printf(3, 4)
1160void dev_printk(const char *level, const struct device *dev,
1161 const char *fmt, ...)
1162{}
1163
1164static inline __printf(2, 3)
1165void dev_emerg(const struct device *dev, const char *fmt, ...)
1166{}
1167static inline __printf(2, 3)
1168void dev_crit(const struct device *dev, const char *fmt, ...)
1169{}
1170static inline __printf(2, 3)
1171void dev_alert(const struct device *dev, const char *fmt, ...)
1172{}
1173static inline __printf(2, 3)
1174void dev_err(const struct device *dev, const char *fmt, ...)
1175{}
1176static inline __printf(2, 3)
1177void dev_warn(const struct device *dev, const char *fmt, ...)
1178{}
1179static inline __printf(2, 3)
1180void dev_notice(const struct device *dev, const char *fmt, ...)
1181{}
1182static inline __printf(2, 3)
1183void _dev_info(const struct device *dev, const char *fmt, ...)
1184{}
1185
1186#endif
1187
1188
1189
1190
1191
1192
1193
1194
1195#define dev_info(dev, fmt, arg...) _dev_info(dev, fmt, ##arg)
1196
1197#if defined(CONFIG_DYNAMIC_DEBUG)
1198#define dev_dbg(dev, format, ...) \
1199do { \
1200 dynamic_dev_dbg(dev, format, ##__VA_ARGS__); \
1201} while (0)
1202#elif defined(DEBUG)
1203#define dev_dbg(dev, format, arg...) \
1204 dev_printk(KERN_DEBUG, dev, format, ##arg)
1205#else
1206#define dev_dbg(dev, format, arg...) \
1207({ \
1208 if (0) \
1209 dev_printk(KERN_DEBUG, dev, format, ##arg); \
1210})
1211#endif
1212
1213#ifdef CONFIG_PRINTK
1214#define dev_level_once(dev_level, dev, fmt, ...) \
1215do { \
1216 static bool __print_once __read_mostly; \
1217 \
1218 if (!__print_once) { \
1219 __print_once = true; \
1220 dev_level(dev, fmt, ##__VA_ARGS__); \
1221 } \
1222} while (0)
1223#else
1224#define dev_level_once(dev_level, dev, fmt, ...) \
1225do { \
1226 if (0) \
1227 dev_level(dev, fmt, ##__VA_ARGS__); \
1228} while (0)
1229#endif
1230
1231#define dev_emerg_once(dev, fmt, ...) \
1232 dev_level_once(dev_emerg, dev, fmt, ##__VA_ARGS__)
1233#define dev_alert_once(dev, fmt, ...) \
1234 dev_level_once(dev_alert, dev, fmt, ##__VA_ARGS__)
1235#define dev_crit_once(dev, fmt, ...) \
1236 dev_level_once(dev_crit, dev, fmt, ##__VA_ARGS__)
1237#define dev_err_once(dev, fmt, ...) \
1238 dev_level_once(dev_err, dev, fmt, ##__VA_ARGS__)
1239#define dev_warn_once(dev, fmt, ...) \
1240 dev_level_once(dev_warn, dev, fmt, ##__VA_ARGS__)
1241#define dev_notice_once(dev, fmt, ...) \
1242 dev_level_once(dev_notice, dev, fmt, ##__VA_ARGS__)
1243#define dev_info_once(dev, fmt, ...) \
1244 dev_level_once(dev_info, dev, fmt, ##__VA_ARGS__)
1245#define dev_dbg_once(dev, fmt, ...) \
1246 dev_level_once(dev_dbg, dev, fmt, ##__VA_ARGS__)
1247
1248#define dev_level_ratelimited(dev_level, dev, fmt, ...) \
1249do { \
1250 static DEFINE_RATELIMIT_STATE(_rs, \
1251 DEFAULT_RATELIMIT_INTERVAL, \
1252 DEFAULT_RATELIMIT_BURST); \
1253 if (__ratelimit(&_rs)) \
1254 dev_level(dev, fmt, ##__VA_ARGS__); \
1255} while (0)
1256
1257#define dev_emerg_ratelimited(dev, fmt, ...) \
1258 dev_level_ratelimited(dev_emerg, dev, fmt, ##__VA_ARGS__)
1259#define dev_alert_ratelimited(dev, fmt, ...) \
1260 dev_level_ratelimited(dev_alert, dev, fmt, ##__VA_ARGS__)
1261#define dev_crit_ratelimited(dev, fmt, ...) \
1262 dev_level_ratelimited(dev_crit, dev, fmt, ##__VA_ARGS__)
1263#define dev_err_ratelimited(dev, fmt, ...) \
1264 dev_level_ratelimited(dev_err, dev, fmt, ##__VA_ARGS__)
1265#define dev_warn_ratelimited(dev, fmt, ...) \
1266 dev_level_ratelimited(dev_warn, dev, fmt, ##__VA_ARGS__)
1267#define dev_notice_ratelimited(dev, fmt, ...) \
1268 dev_level_ratelimited(dev_notice, dev, fmt, ##__VA_ARGS__)
1269#define dev_info_ratelimited(dev, fmt, ...) \
1270 dev_level_ratelimited(dev_info, dev, fmt, ##__VA_ARGS__)
1271#if defined(CONFIG_DYNAMIC_DEBUG)
1272
1273#define dev_dbg_ratelimited(dev, fmt, ...) \
1274do { \
1275 static DEFINE_RATELIMIT_STATE(_rs, \
1276 DEFAULT_RATELIMIT_INTERVAL, \
1277 DEFAULT_RATELIMIT_BURST); \
1278 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
1279 if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
1280 __ratelimit(&_rs)) \
1281 __dynamic_dev_dbg(&descriptor, dev, fmt, \
1282 ##__VA_ARGS__); \
1283} while (0)
1284#elif defined(DEBUG)
1285#define dev_dbg_ratelimited(dev, fmt, ...) \
1286do { \
1287 static DEFINE_RATELIMIT_STATE(_rs, \
1288 DEFAULT_RATELIMIT_INTERVAL, \
1289 DEFAULT_RATELIMIT_BURST); \
1290 if (__ratelimit(&_rs)) \
1291 dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); \
1292} while (0)
1293#else
1294#define dev_dbg_ratelimited(dev, fmt, ...) \
1295do { \
1296 if (0) \
1297 dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); \
1298} while (0)
1299#endif
1300
1301#ifdef VERBOSE_DEBUG
1302#define dev_vdbg dev_dbg
1303#else
1304#define dev_vdbg(dev, format, arg...) \
1305({ \
1306 if (0) \
1307 dev_printk(KERN_DEBUG, dev, format, ##arg); \
1308})
1309#endif
1310
1311
1312
1313
1314
1315#define dev_WARN(dev, format, arg...) \
1316 WARN(1, "%s %s: " format, dev_driver_string(dev), dev_name(dev), ## arg);
1317
1318#define dev_WARN_ONCE(dev, condition, format, arg...) \
1319 WARN_ONCE(condition, "%s %s: " format, \
1320 dev_driver_string(dev), dev_name(dev), ## arg)
1321
1322
1323#define MODULE_ALIAS_CHARDEV(major,minor) \
1324 MODULE_ALIAS("char-major-" __stringify(major) "-" __stringify(minor))
1325#define MODULE_ALIAS_CHARDEV_MAJOR(major) \
1326 MODULE_ALIAS("char-major-" __stringify(major) "-*")
1327
1328#ifdef CONFIG_SYSFS_DEPRECATED
1329extern long sysfs_deprecated;
1330#else
1331#define sysfs_deprecated 0
1332#endif
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348#define module_driver(__driver, __register, __unregister, ...) \
1349static int __init __driver##_init(void) \
1350{ \
1351 return __register(&(__driver) , ##__VA_ARGS__); \
1352} \
1353module_init(__driver##_init); \
1354static void __exit __driver##_exit(void) \
1355{ \
1356 __unregister(&(__driver) , ##__VA_ARGS__); \
1357} \
1358module_exit(__driver##_exit);
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375#define builtin_driver(__driver, __register, ...) \
1376static int __init __driver##_init(void) \
1377{ \
1378 return __register(&(__driver) , ##__VA_ARGS__); \
1379} \
1380device_initcall(__driver##_init);
1381
1382#endif
1383