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