1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef _DEVICE_BUS_H_
15#define _DEVICE_BUS_H_
16
17#include <linux/kobject.h>
18#include <linux/klist.h>
19#include <linux/pm.h>
20
21struct device_driver;
22struct fwnode_handle;
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
84struct bus_type {
85 const char *name;
86 const char *dev_name;
87 struct device *dev_root;
88 const struct attribute_group **bus_groups;
89 const struct attribute_group **dev_groups;
90 const struct attribute_group **drv_groups;
91
92 int (*match)(struct device *dev, struct device_driver *drv);
93 int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
94 int (*probe)(struct device *dev);
95 void (*sync_state)(struct device *dev);
96 void (*remove)(struct device *dev);
97 void (*shutdown)(struct device *dev);
98
99 int (*online)(struct device *dev);
100 int (*offline)(struct device *dev);
101
102 int (*suspend)(struct device *dev, pm_message_t state);
103 int (*resume)(struct device *dev);
104
105 int (*num_vf)(struct device *dev);
106
107 int (*dma_configure)(struct device *dev);
108 void (*dma_cleanup)(struct device *dev);
109
110 const struct dev_pm_ops *pm;
111
112 const struct iommu_ops *iommu_ops;
113
114 struct subsys_private *p;
115 struct lock_class_key lock_key;
116
117 bool need_parent_lock;
118};
119
120extern int __must_check bus_register(struct bus_type *bus);
121
122extern void bus_unregister(struct bus_type *bus);
123
124extern int __must_check bus_rescan_devices(struct bus_type *bus);
125
126struct bus_attribute {
127 struct attribute attr;
128 ssize_t (*show)(struct bus_type *bus, char *buf);
129 ssize_t (*store)(struct bus_type *bus, const char *buf, size_t count);
130};
131
132#define BUS_ATTR_RW(_name) \
133 struct bus_attribute bus_attr_##_name = __ATTR_RW(_name)
134#define BUS_ATTR_RO(_name) \
135 struct bus_attribute bus_attr_##_name = __ATTR_RO(_name)
136#define BUS_ATTR_WO(_name) \
137 struct bus_attribute bus_attr_##_name = __ATTR_WO(_name)
138
139extern int __must_check bus_create_file(struct bus_type *,
140 struct bus_attribute *);
141extern void bus_remove_file(struct bus_type *, struct bus_attribute *);
142
143
144int device_match_name(struct device *dev, const void *name);
145int device_match_of_node(struct device *dev, const void *np);
146int device_match_fwnode(struct device *dev, const void *fwnode);
147int device_match_devt(struct device *dev, const void *pdevt);
148int device_match_acpi_dev(struct device *dev, const void *adev);
149int device_match_acpi_handle(struct device *dev, const void *handle);
150int device_match_any(struct device *dev, const void *unused);
151
152
153struct subsys_dev_iter {
154 struct klist_iter ki;
155 const struct device_type *type;
156};
157void subsys_dev_iter_init(struct subsys_dev_iter *iter,
158 struct bus_type *subsys,
159 struct device *start,
160 const struct device_type *type);
161struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter);
162void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
163
164int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
165 int (*fn)(struct device *dev, void *data));
166struct device *bus_find_device(struct bus_type *bus, struct device *start,
167 const void *data,
168 int (*match)(struct device *dev, const void *data));
169
170
171
172
173
174
175
176static inline struct device *bus_find_device_by_name(struct bus_type *bus,
177 struct device *start,
178 const char *name)
179{
180 return bus_find_device(bus, start, name, device_match_name);
181}
182
183
184
185
186
187
188
189static inline struct device *
190bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np)
191{
192 return bus_find_device(bus, NULL, np, device_match_of_node);
193}
194
195
196
197
198
199
200
201static inline struct device *
202bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle *fwnode)
203{
204 return bus_find_device(bus, NULL, fwnode, device_match_fwnode);
205}
206
207
208
209
210
211
212
213static inline struct device *bus_find_device_by_devt(struct bus_type *bus,
214 dev_t devt)
215{
216 return bus_find_device(bus, NULL, &devt, device_match_devt);
217}
218
219
220
221
222
223
224
225static inline struct device *
226bus_find_next_device(struct bus_type *bus,struct device *cur)
227{
228 return bus_find_device(bus, cur, NULL, device_match_any);
229}
230
231#ifdef CONFIG_ACPI
232struct acpi_device;
233
234
235
236
237
238
239
240static inline struct device *
241bus_find_device_by_acpi_dev(struct bus_type *bus, const struct acpi_device *adev)
242{
243 return bus_find_device(bus, NULL, adev, device_match_acpi_dev);
244}
245#else
246static inline struct device *
247bus_find_device_by_acpi_dev(struct bus_type *bus, const void *adev)
248{
249 return NULL;
250}
251#endif
252
253struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
254 struct device *hint);
255int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
256 void *data, int (*fn)(struct device_driver *, void *));
257void bus_sort_breadthfirst(struct bus_type *bus,
258 int (*compare)(const struct device *a,
259 const struct device *b));
260
261
262
263
264
265
266struct notifier_block;
267
268extern int bus_register_notifier(struct bus_type *bus,
269 struct notifier_block *nb);
270extern int bus_unregister_notifier(struct bus_type *bus,
271 struct notifier_block *nb);
272
273
274
275
276
277#define BUS_NOTIFY_ADD_DEVICE 0x00000001
278#define BUS_NOTIFY_DEL_DEVICE 0x00000002
279#define BUS_NOTIFY_REMOVED_DEVICE 0x00000003
280#define BUS_NOTIFY_BIND_DRIVER 0x00000004
281
282#define BUS_NOTIFY_BOUND_DRIVER 0x00000005
283#define BUS_NOTIFY_UNBIND_DRIVER 0x00000006
284
285#define BUS_NOTIFY_UNBOUND_DRIVER 0x00000007
286
287#define BUS_NOTIFY_DRIVER_NOT_BOUND 0x00000008
288
289extern struct kset *bus_get_kset(struct bus_type *bus);
290extern struct klist *bus_get_device_klist(struct bus_type *bus);
291
292#endif
293