]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * device.h - generic, centralized driver model | |
3 | * | |
4 | * Copyright (c) 2001-2003 Patrick Mochel <mochel@osdl.org> | |
89790fd7 | 5 | * Copyright (c) 2004-2007 Greg Kroah-Hartman <gregkh@suse.de> |
1da177e4 LT |
6 | * |
7 | * This file is released under the GPLv2 | |
8 | * | |
9 | * See Documentation/driver-model/ for more information. | |
10 | */ | |
11 | ||
12 | #ifndef _DEVICE_H_ | |
13 | #define _DEVICE_H_ | |
14 | ||
1da177e4 LT |
15 | #include <linux/ioport.h> |
16 | #include <linux/kobject.h> | |
465c7a3a | 17 | #include <linux/klist.h> |
1da177e4 | 18 | #include <linux/list.h> |
4a7fb636 | 19 | #include <linux/compiler.h> |
1da177e4 LT |
20 | #include <linux/types.h> |
21 | #include <linux/module.h> | |
22 | #include <linux/pm.h> | |
23 | #include <asm/semaphore.h> | |
24 | #include <asm/atomic.h> | |
c6dbaef2 | 25 | #include <asm/device.h> |
1da177e4 LT |
26 | |
27 | #define DEVICE_NAME_SIZE 50 | |
d462943a GKH |
28 | /* DEVICE_NAME_HALF is really less than half to accommodate slop */ |
29 | #define DEVICE_NAME_HALF __stringify(20) | |
1da177e4 LT |
30 | #define DEVICE_ID_SIZE 32 |
31 | #define BUS_ID_SIZE KOBJ_NAME_LEN | |
32 | ||
33 | ||
1da177e4 LT |
34 | struct device; |
35 | struct device_driver; | |
e5dd1278 | 36 | struct driver_private; |
1da177e4 LT |
37 | struct class; |
38 | struct class_device; | |
b8c5cec2 | 39 | struct bus_type; |
c6f7e72a | 40 | struct bus_type_private; |
b8c5cec2 KS |
41 | |
42 | struct bus_attribute { | |
43 | struct attribute attr; | |
d462943a GKH |
44 | ssize_t (*show)(struct bus_type *bus, char *buf); |
45 | ssize_t (*store)(struct bus_type *bus, const char *buf, size_t count); | |
b8c5cec2 KS |
46 | }; |
47 | ||
d462943a GKH |
48 | #define BUS_ATTR(_name, _mode, _show, _store) \ |
49 | struct bus_attribute bus_attr_##_name = __ATTR(_name, _mode, _show, _store) | |
b8c5cec2 KS |
50 | |
51 | extern int __must_check bus_create_file(struct bus_type *, | |
52 | struct bus_attribute *); | |
53 | extern void bus_remove_file(struct bus_type *, struct bus_attribute *); | |
1da177e4 LT |
54 | |
55 | struct bus_type { | |
d462943a GKH |
56 | const char *name; |
57 | struct bus_attribute *bus_attrs; | |
58 | struct device_attribute *dev_attrs; | |
59 | struct driver_attribute *drv_attrs; | |
60 | ||
61 | int (*match)(struct device *dev, struct device_driver *drv); | |
62 | int (*uevent)(struct device *dev, struct kobj_uevent_env *env); | |
63 | int (*probe)(struct device *dev); | |
64 | int (*remove)(struct device *dev); | |
65 | void (*shutdown)(struct device *dev); | |
66 | ||
67 | int (*suspend)(struct device *dev, pm_message_t state); | |
68 | int (*suspend_late)(struct device *dev, pm_message_t state); | |
69 | int (*resume_early)(struct device *dev); | |
70 | int (*resume)(struct device *dev); | |
b8c5cec2 | 71 | |
c6f7e72a | 72 | struct bus_type_private *p; |
1da177e4 LT |
73 | }; |
74 | ||
d462943a GKH |
75 | extern int __must_check bus_register(struct bus_type *bus); |
76 | extern void bus_unregister(struct bus_type *bus); | |
1da177e4 | 77 | |
d462943a | 78 | extern int __must_check bus_rescan_devices(struct bus_type *bus); |
1da177e4 | 79 | |
1da177e4 LT |
80 | /* iterator helpers for buses */ |
81 | ||
d462943a GKH |
82 | int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, |
83 | int (*fn)(struct device *dev, void *data)); | |
84 | struct device *bus_find_device(struct bus_type *bus, struct device *start, | |
85 | void *data, | |
86 | int (*match)(struct device *dev, void *data)); | |
1f9ffc04 GKH |
87 | struct device *bus_find_device_by_name(struct bus_type *bus, |
88 | struct device *start, | |
89 | const char *name); | |
1da177e4 | 90 | |
4a7fb636 | 91 | int __must_check bus_for_each_drv(struct bus_type *bus, |
d462943a GKH |
92 | struct device_driver *start, void *data, |
93 | int (*fn)(struct device_driver *, void *)); | |
1da177e4 | 94 | |
116af378 BH |
95 | /* |
96 | * Bus notifiers: Get notified of addition/removal of devices | |
97 | * and binding/unbinding of drivers to devices. | |
98 | * In the long run, it should be a replacement for the platform | |
99 | * notify hooks. | |
100 | */ | |
101 | struct notifier_block; | |
102 | ||
103 | extern int bus_register_notifier(struct bus_type *bus, | |
104 | struct notifier_block *nb); | |
105 | extern int bus_unregister_notifier(struct bus_type *bus, | |
106 | struct notifier_block *nb); | |
107 | ||
108 | /* All 4 notifers below get called with the target struct device * | |
109 | * as an argument. Note that those functions are likely to be called | |
110 | * with the device semaphore held in the core, so be careful. | |
111 | */ | |
112 | #define BUS_NOTIFY_ADD_DEVICE 0x00000001 /* device added */ | |
113 | #define BUS_NOTIFY_DEL_DEVICE 0x00000002 /* device removed */ | |
114 | #define BUS_NOTIFY_BOUND_DRIVER 0x00000003 /* driver bound to device */ | |
115 | #define BUS_NOTIFY_UNBIND_DRIVER 0x00000004 /* driver about to be | |
116 | unbound */ | |
117 | ||
0fed80f7 | 118 | extern struct kset *bus_get_kset(struct bus_type *bus); |
b249072e | 119 | extern struct klist *bus_get_device_klist(struct bus_type *bus); |
0fed80f7 | 120 | |
1da177e4 | 121 | struct device_driver { |
e5dd1278 GKH |
122 | const char *name; |
123 | struct bus_type *bus; | |
1da177e4 | 124 | |
e5dd1278 GKH |
125 | struct module *owner; |
126 | const char *mod_name; /* used for built-in modules */ | |
1da177e4 | 127 | |
d462943a GKH |
128 | int (*probe) (struct device *dev); |
129 | int (*remove) (struct device *dev); | |
130 | void (*shutdown) (struct device *dev); | |
131 | int (*suspend) (struct device *dev, pm_message_t state); | |
132 | int (*resume) (struct device *dev); | |
57c74534 | 133 | struct attribute_group **groups; |
e5dd1278 GKH |
134 | |
135 | struct driver_private *p; | |
1da177e4 LT |
136 | }; |
137 | ||
138 | ||
d462943a GKH |
139 | extern int __must_check driver_register(struct device_driver *drv); |
140 | extern void driver_unregister(struct device_driver *drv); | |
1da177e4 | 141 | |
d462943a GKH |
142 | extern struct device_driver *get_driver(struct device_driver *drv); |
143 | extern void put_driver(struct device_driver *drv); | |
144 | extern struct device_driver *driver_find(const char *name, | |
145 | struct bus_type *bus); | |
d779249e | 146 | extern int driver_probe_done(void); |
1da177e4 | 147 | |
405ae7d3 | 148 | /* sysfs interface for exporting driver attributes */ |
1da177e4 LT |
149 | |
150 | struct driver_attribute { | |
d462943a GKH |
151 | struct attribute attr; |
152 | ssize_t (*show)(struct device_driver *driver, char *buf); | |
153 | ssize_t (*store)(struct device_driver *driver, const char *buf, | |
154 | size_t count); | |
1da177e4 LT |
155 | }; |
156 | ||
d462943a GKH |
157 | #define DRIVER_ATTR(_name, _mode, _show, _store) \ |
158 | struct driver_attribute driver_attr_##_name = \ | |
159 | __ATTR(_name, _mode, _show, _store) | |
1da177e4 | 160 | |
d462943a GKH |
161 | extern int __must_check driver_create_file(struct device_driver *driver, |
162 | struct driver_attribute *attr); | |
163 | extern void driver_remove_file(struct device_driver *driver, | |
164 | struct driver_attribute *attr); | |
1da177e4 | 165 | |
cbe9c595 GKH |
166 | extern int __must_check driver_add_kobj(struct device_driver *drv, |
167 | struct kobject *kobj, | |
168 | const char *fmt, ...); | |
169 | ||
d462943a GKH |
170 | extern int __must_check driver_for_each_device(struct device_driver *drv, |
171 | struct device *start, | |
172 | void *data, | |
173 | int (*fn)(struct device *dev, | |
174 | void *)); | |
175 | struct device *driver_find_device(struct device_driver *drv, | |
176 | struct device *start, void *data, | |
177 | int (*match)(struct device *dev, void *data)); | |
fae3cd00 | 178 | |
1da177e4 LT |
179 | /* |
180 | * device classes | |
181 | */ | |
182 | struct class { | |
d462943a GKH |
183 | const char *name; |
184 | struct module *owner; | |
1da177e4 | 185 | |
823bccfc | 186 | struct kset subsys; |
1da177e4 | 187 | struct list_head children; |
23681e47 | 188 | struct list_head devices; |
1da177e4 | 189 | struct list_head interfaces; |
86406245 | 190 | struct kset class_dirs; |
fd04897b | 191 | struct semaphore sem; /* locks children, devices, interfaces */ |
d462943a GKH |
192 | struct class_attribute *class_attrs; |
193 | struct class_device_attribute *class_dev_attrs; | |
194 | struct device_attribute *dev_attrs; | |
1da177e4 | 195 | |
d462943a GKH |
196 | int (*uevent)(struct class_device *dev, struct kobj_uevent_env *env); |
197 | int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env); | |
1da177e4 | 198 | |
d462943a GKH |
199 | void (*release)(struct class_device *dev); |
200 | void (*class_release)(struct class *class); | |
201 | void (*dev_release)(struct device *dev); | |
7c8265f5 | 202 | |
d462943a GKH |
203 | int (*suspend)(struct device *dev, pm_message_t state); |
204 | int (*resume)(struct device *dev); | |
1da177e4 LT |
205 | }; |
206 | ||
d462943a GKH |
207 | extern int __must_check class_register(struct class *class); |
208 | extern void class_unregister(struct class *class); | |
fd04897b DY |
209 | extern int class_for_each_device(struct class *class, void *data, |
210 | int (*fn)(struct device *dev, void *data)); | |
211 | extern struct device *class_find_device(struct class *class, void *data, | |
212 | int (*match)(struct device *, void *)); | |
213 | extern struct class_device *class_find_child(struct class *class, void *data, | |
214 | int (*match)(struct class_device *, void *)); | |
1da177e4 | 215 | |
1da177e4 LT |
216 | |
217 | struct class_attribute { | |
d462943a GKH |
218 | struct attribute attr; |
219 | ssize_t (*show)(struct class *class, char *buf); | |
220 | ssize_t (*store)(struct class *class, const char *buf, size_t count); | |
1da177e4 LT |
221 | }; |
222 | ||
d462943a GKH |
223 | #define CLASS_ATTR(_name, _mode, _show, _store) \ |
224 | struct class_attribute class_attr_##_name = __ATTR(_name, _mode, _show, _store) | |
1da177e4 | 225 | |
d462943a GKH |
226 | extern int __must_check class_create_file(struct class *class, |
227 | const struct class_attribute *attr); | |
228 | extern void class_remove_file(struct class *class, | |
229 | const struct class_attribute *attr); | |
1da177e4 | 230 | |
a7fd6706 | 231 | struct class_device_attribute { |
d462943a GKH |
232 | struct attribute attr; |
233 | ssize_t (*show)(struct class_device *, char *buf); | |
234 | ssize_t (*store)(struct class_device *, const char *buf, size_t count); | |
a7fd6706 KS |
235 | }; |
236 | ||
d462943a | 237 | #define CLASS_DEVICE_ATTR(_name, _mode, _show, _store) \ |
a7fd6706 | 238 | struct class_device_attribute class_device_attr_##_name = \ |
d462943a | 239 | __ATTR(_name, _mode, _show, _store) |
a7fd6706 | 240 | |
4a7fb636 | 241 | extern int __must_check class_device_create_file(struct class_device *, |
a7fd6706 | 242 | const struct class_device_attribute *); |
1da177e4 | 243 | |
74be227f GKH |
244 | /** |
245 | * struct class_device - class devices | |
246 | * @class: pointer to the parent class for this class device. This is required. | |
247 | * @devt: for internal use by the driver core only. | |
248 | * @node: for internal use by the driver core only. | |
249 | * @kobj: for internal use by the driver core only. | |
1498221d | 250 | * @groups: optional additional groups to be created |
74be227f GKH |
251 | * @dev: if set, a symlink to the struct device is created in the sysfs |
252 | * directory for this struct class device. | |
253 | * @class_data: pointer to whatever you want to store here for this struct | |
254 | * class_device. Use class_get_devdata() and class_set_devdata() to get and | |
255 | * set this pointer. | |
256 | * @parent: pointer to a struct class_device that is the parent of this struct | |
257 | * class_device. If NULL, this class_device will show up at the root of the | |
258 | * struct class in sysfs (which is probably what you want to have happen.) | |
259 | * @release: pointer to a release function for this struct class_device. If | |
260 | * set, this will be called instead of the class specific release function. | |
261 | * Only use this if you want to override the default release function, like | |
262 | * when you are nesting class_device structures. | |
312c004d KS |
263 | * @uevent: pointer to a uevent function for this struct class_device. If |
264 | * set, this will be called instead of the class specific uevent function. | |
265 | * Only use this if you want to override the default uevent function, like | |
74be227f GKH |
266 | * when you are nesting class_device structures. |
267 | */ | |
1da177e4 LT |
268 | struct class_device { |
269 | struct list_head node; | |
270 | ||
271 | struct kobject kobj; | |
d462943a GKH |
272 | struct class *class; |
273 | dev_t devt; | |
274 | struct device *dev; | |
275 | void *class_data; | |
276 | struct class_device *parent; | |
277 | struct attribute_group **groups; | |
278 | ||
279 | void (*release)(struct class_device *dev); | |
280 | int (*uevent)(struct class_device *dev, struct kobj_uevent_env *env); | |
281 | char class_id[BUS_ID_SIZE]; | |
1da177e4 LT |
282 | }; |
283 | ||
d462943a | 284 | static inline void *class_get_devdata(struct class_device *dev) |
1da177e4 LT |
285 | { |
286 | return dev->class_data; | |
287 | } | |
288 | ||
d462943a | 289 | static inline void class_set_devdata(struct class_device *dev, void *data) |
1da177e4 LT |
290 | { |
291 | dev->class_data = data; | |
292 | } | |
293 | ||
294 | ||
4a7fb636 | 295 | extern int __must_check class_device_register(struct class_device *); |
1da177e4 LT |
296 | extern void class_device_unregister(struct class_device *); |
297 | extern void class_device_initialize(struct class_device *); | |
4a7fb636 | 298 | extern int __must_check class_device_add(struct class_device *); |
1da177e4 LT |
299 | extern void class_device_del(struct class_device *); |
300 | ||
d462943a | 301 | extern struct class_device *class_device_get(struct class_device *); |
1da177e4 LT |
302 | extern void class_device_put(struct class_device *); |
303 | ||
d462943a | 304 | extern void class_device_remove_file(struct class_device *, |
1da177e4 | 305 | const struct class_device_attribute *); |
d919fd43 GKH |
306 | extern int __must_check class_device_create_bin_file(struct class_device *, |
307 | struct bin_attribute *); | |
308 | extern void class_device_remove_bin_file(struct class_device *, | |
309 | struct bin_attribute *); | |
1da177e4 LT |
310 | |
311 | struct class_interface { | |
312 | struct list_head node; | |
313 | struct class *class; | |
314 | ||
d8539d81 DT |
315 | int (*add) (struct class_device *, struct class_interface *); |
316 | void (*remove) (struct class_device *, struct class_interface *); | |
c47ed219 GKH |
317 | int (*add_dev) (struct device *, struct class_interface *); |
318 | void (*remove_dev) (struct device *, struct class_interface *); | |
1da177e4 LT |
319 | }; |
320 | ||
4a7fb636 | 321 | extern int __must_check class_interface_register(struct class_interface *); |
1da177e4 LT |
322 | extern void class_interface_unregister(struct class_interface *); |
323 | ||
ab7d7371 | 324 | extern struct class *class_create(struct module *owner, const char *name); |
e9ba6365 | 325 | extern void class_destroy(struct class *cls); |
51d172d5 GKH |
326 | extern struct class_device *class_device_create(struct class *cls, |
327 | struct class_device *parent, | |
328 | dev_t devt, | |
329 | struct device *device, | |
ddd5d35a | 330 | const char *fmt, ...) |
d462943a | 331 | __attribute__((format(printf, 5, 6))); |
e9ba6365 GKH |
332 | extern void class_device_destroy(struct class *cls, dev_t devt); |
333 | ||
414264f9 KS |
334 | /* |
335 | * The type of device, "struct device" is embedded in. A class | |
336 | * or bus can contain devices of different types | |
337 | * like "partitions" and "disks", "mouse" and "event". | |
338 | * This identifies the device type and carries type-specific | |
339 | * information, equivalent to the kobj_type of a kobject. | |
340 | * If "name" is specified, the uevent will contain it in | |
341 | * the DEVTYPE variable. | |
342 | */ | |
f9f852df | 343 | struct device_type { |
414264f9 | 344 | const char *name; |
621a1672 | 345 | struct attribute_group **groups; |
7eff2e7a | 346 | int (*uevent)(struct device *dev, struct kobj_uevent_env *env); |
f9f852df | 347 | void (*release)(struct device *dev); |
d462943a GKH |
348 | int (*suspend)(struct device *dev, pm_message_t state); |
349 | int (*resume)(struct device *dev); | |
f9f852df KS |
350 | }; |
351 | ||
a7fd6706 KS |
352 | /* interface for exporting device attributes */ |
353 | struct device_attribute { | |
354 | struct attribute attr; | |
355 | ssize_t (*show)(struct device *dev, struct device_attribute *attr, | |
356 | char *buf); | |
357 | ssize_t (*store)(struct device *dev, struct device_attribute *attr, | |
358 | const char *buf, size_t count); | |
359 | }; | |
360 | ||
d462943a GKH |
361 | #define DEVICE_ATTR(_name, _mode, _show, _store) \ |
362 | struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store) | |
a7fd6706 | 363 | |
4a7fb636 | 364 | extern int __must_check device_create_file(struct device *device, |
d462943a GKH |
365 | struct device_attribute *entry); |
366 | extern void device_remove_file(struct device *dev, | |
367 | struct device_attribute *attr); | |
2589f188 GKH |
368 | extern int __must_check device_create_bin_file(struct device *dev, |
369 | struct bin_attribute *attr); | |
370 | extern void device_remove_bin_file(struct device *dev, | |
371 | struct bin_attribute *attr); | |
523ded71 | 372 | extern int device_schedule_callback_owner(struct device *dev, |
d462943a | 373 | void (*func)(struct device *dev), struct module *owner); |
523ded71 AS |
374 | |
375 | /* This is a macro to avoid include problems with THIS_MODULE */ | |
376 | #define device_schedule_callback(dev, func) \ | |
377 | device_schedule_callback_owner(dev, func, THIS_MODULE) | |
9ac7849e TH |
378 | |
379 | /* device resource management */ | |
380 | typedef void (*dr_release_t)(struct device *dev, void *res); | |
381 | typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data); | |
382 | ||
383 | #ifdef CONFIG_DEBUG_DEVRES | |
d462943a | 384 | extern void *__devres_alloc(dr_release_t release, size_t size, gfp_t gfp, |
9ac7849e TH |
385 | const char *name); |
386 | #define devres_alloc(release, size, gfp) \ | |
387 | __devres_alloc(release, size, gfp, #release) | |
388 | #else | |
d462943a | 389 | extern void *devres_alloc(dr_release_t release, size_t size, gfp_t gfp); |
9ac7849e TH |
390 | #endif |
391 | extern void devres_free(void *res); | |
392 | extern void devres_add(struct device *dev, void *res); | |
d462943a | 393 | extern void *devres_find(struct device *dev, dr_release_t release, |
9ac7849e | 394 | dr_match_t match, void *match_data); |
d462943a GKH |
395 | extern void *devres_get(struct device *dev, void *new_res, |
396 | dr_match_t match, void *match_data); | |
397 | extern void *devres_remove(struct device *dev, dr_release_t release, | |
398 | dr_match_t match, void *match_data); | |
9ac7849e TH |
399 | extern int devres_destroy(struct device *dev, dr_release_t release, |
400 | dr_match_t match, void *match_data); | |
401 | ||
402 | /* devres group */ | |
403 | extern void * __must_check devres_open_group(struct device *dev, void *id, | |
404 | gfp_t gfp); | |
405 | extern void devres_close_group(struct device *dev, void *id); | |
406 | extern void devres_remove_group(struct device *dev, void *id); | |
407 | extern int devres_release_group(struct device *dev, void *id); | |
408 | ||
409 | /* managed kzalloc/kfree for device drivers, no kmalloc, always use kzalloc */ | |
410 | extern void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp); | |
411 | extern void devm_kfree(struct device *dev, void *p); | |
412 | ||
1da177e4 | 413 | struct device { |
36239577 | 414 | struct klist klist_children; |
d462943a | 415 | struct klist_node knode_parent; /* node in sibling list */ |
94e7b1c5 | 416 | struct klist_node knode_driver; |
465c7a3a | 417 | struct klist_node knode_bus; |
49a4ec18 | 418 | struct device *parent; |
1da177e4 LT |
419 | |
420 | struct kobject kobj; | |
421 | char bus_id[BUS_ID_SIZE]; /* position on parent bus */ | |
f9f852df | 422 | struct device_type *type; |
f2eaae19 | 423 | unsigned is_registered:1; |
49a4ec18 | 424 | unsigned uevent_suppress:1; |
1da177e4 | 425 | |
af70316a PM |
426 | struct semaphore sem; /* semaphore to synchronize calls to |
427 | * its driver. | |
428 | */ | |
429 | ||
d462943a | 430 | struct bus_type *bus; /* type of bus device is on */ |
1da177e4 LT |
431 | struct device_driver *driver; /* which driver has allocated this |
432 | device */ | |
433 | void *driver_data; /* data private to the driver */ | |
4e10d12a DSL |
434 | void *platform_data; /* Platform specific data, device |
435 | core doesn't touch it */ | |
1da177e4 LT |
436 | struct dev_pm_info power; |
437 | ||
87348136 CH |
438 | #ifdef CONFIG_NUMA |
439 | int numa_node; /* NUMA node this device is close to */ | |
440 | #endif | |
1da177e4 LT |
441 | u64 *dma_mask; /* dma mask (if dma'able device) */ |
442 | u64 coherent_dma_mask;/* Like dma_mask, but for | |
443 | alloc_coherent mappings as | |
444 | not all hardware supports | |
445 | 64 bit addresses for consistent | |
446 | allocations such descriptors. */ | |
447 | ||
448 | struct list_head dma_pools; /* dma pools (if dma'ble) */ | |
449 | ||
450 | struct dma_coherent_mem *dma_mem; /* internal for coherent mem | |
451 | override */ | |
c6dbaef2 BH |
452 | /* arch specific additions */ |
453 | struct dev_archdata archdata; | |
1da177e4 | 454 | |
9ac7849e TH |
455 | spinlock_t devres_lock; |
456 | struct list_head devres_head; | |
457 | ||
23681e47 GKH |
458 | /* class_device migration path */ |
459 | struct list_head node; | |
b7a3e813 | 460 | struct class *class; |
d462943a | 461 | dev_t devt; /* dev_t, creates the sysfs "dev" */ |
de0ff00d | 462 | struct attribute_group **groups; /* optional groups */ |
23681e47 | 463 | |
d462943a | 464 | void (*release)(struct device *dev); |
1da177e4 LT |
465 | }; |
466 | ||
87348136 CH |
467 | #ifdef CONFIG_NUMA |
468 | static inline int dev_to_node(struct device *dev) | |
469 | { | |
470 | return dev->numa_node; | |
471 | } | |
472 | static inline void set_dev_node(struct device *dev, int node) | |
473 | { | |
474 | dev->numa_node = node; | |
475 | } | |
476 | #else | |
477 | static inline int dev_to_node(struct device *dev) | |
478 | { | |
479 | return -1; | |
480 | } | |
481 | static inline void set_dev_node(struct device *dev, int node) | |
482 | { | |
483 | } | |
484 | #endif | |
485 | ||
d462943a | 486 | static inline void *dev_get_drvdata(struct device *dev) |
1da177e4 LT |
487 | { |
488 | return dev->driver_data; | |
489 | } | |
490 | ||
d462943a | 491 | static inline void dev_set_drvdata(struct device *dev, void *data) |
1da177e4 LT |
492 | { |
493 | dev->driver_data = data; | |
494 | } | |
495 | ||
d305ef5d DR |
496 | static inline int device_is_registered(struct device *dev) |
497 | { | |
f2eaae19 | 498 | return dev->is_registered; |
d305ef5d DR |
499 | } |
500 | ||
1f21782e AB |
501 | void driver_init(void); |
502 | ||
1da177e4 LT |
503 | /* |
504 | * High level routines for use by the bus drivers | |
505 | */ | |
d462943a GKH |
506 | extern int __must_check device_register(struct device *dev); |
507 | extern void device_unregister(struct device *dev); | |
508 | extern void device_initialize(struct device *dev); | |
509 | extern int __must_check device_add(struct device *dev); | |
510 | extern void device_del(struct device *dev); | |
511 | extern int device_for_each_child(struct device *dev, void *data, | |
512 | int (*fn)(struct device *dev, void *data)); | |
513 | extern struct device *device_find_child(struct device *dev, void *data, | |
514 | int (*match)(struct device *dev, void *data)); | |
a2de48ca | 515 | extern int device_rename(struct device *dev, char *new_name); |
8a82472f | 516 | extern int device_move(struct device *dev, struct device *new_parent); |
1da177e4 LT |
517 | |
518 | /* | |
519 | * Manual binding of a device to driver. See drivers/base/bus.c | |
520 | * for information on use. | |
521 | */ | |
f86db396 | 522 | extern int __must_check device_bind_driver(struct device *dev); |
d462943a GKH |
523 | extern void device_release_driver(struct device *dev); |
524 | extern int __must_check device_attach(struct device *dev); | |
f86db396 AM |
525 | extern int __must_check driver_attach(struct device_driver *drv); |
526 | extern int __must_check device_reprobe(struct device *dev); | |
1da177e4 | 527 | |
23681e47 GKH |
528 | /* |
529 | * Easy functions for dynamically creating devices on the fly | |
530 | */ | |
531 | extern struct device *device_create(struct class *cls, struct device *parent, | |
5cbe5f8a | 532 | dev_t devt, const char *fmt, ...) |
d462943a | 533 | __attribute__((format(printf, 4, 5))); |
23681e47 | 534 | extern void device_destroy(struct class *cls, dev_t devt); |
775b64d2 RW |
535 | #ifdef CONFIG_PM_SLEEP |
536 | extern void destroy_suspended_device(struct class *cls, dev_t devt); | |
9617c3e4 | 537 | extern void device_pm_schedule_removal(struct device *); |
775b64d2 RW |
538 | #else /* !CONFIG_PM_SLEEP */ |
539 | static inline void destroy_suspended_device(struct class *cls, dev_t devt) | |
540 | { | |
541 | device_destroy(cls, devt); | |
542 | } | |
9617c3e4 RW |
543 | |
544 | static inline void device_pm_schedule_removal(struct device *dev) | |
545 | { | |
546 | device_unregister(dev); | |
547 | } | |
775b64d2 | 548 | #endif /* !CONFIG_PM_SLEEP */ |
1da177e4 | 549 | |
1da177e4 LT |
550 | /* |
551 | * Platform "fixup" functions - allow the platform to have their say | |
552 | * about devices and actions that the general device layer doesn't | |
553 | * know about. | |
554 | */ | |
555 | /* Notify platform of device discovery */ | |
d462943a | 556 | extern int (*platform_notify)(struct device *dev); |
1da177e4 | 557 | |
d462943a | 558 | extern int (*platform_notify_remove)(struct device *dev); |
1da177e4 LT |
559 | |
560 | ||
561 | /** | |
562 | * get_device - atomically increment the reference count for the device. | |
563 | * | |
564 | */ | |
d462943a GKH |
565 | extern struct device *get_device(struct device *dev); |
566 | extern void put_device(struct device *dev); | |
1da177e4 LT |
567 | |
568 | ||
116f232b | 569 | /* drivers/base/power/shutdown.c */ |
1da177e4 LT |
570 | extern void device_shutdown(void); |
571 | ||
58b3b71d RW |
572 | /* drivers/base/sys.c */ |
573 | extern void sysdev_shutdown(void); | |
574 | ||
1da177e4 | 575 | /* debugging and troubleshooting/diagnostic helpers. */ |
3e95637a | 576 | extern const char *dev_driver_string(struct device *dev); |
1da177e4 | 577 | #define dev_printk(level, dev, format, arg...) \ |
d462943a GKH |
578 | printk(level "%s %s: " format , dev_driver_string(dev) , \ |
579 | (dev)->bus_id , ## arg) | |
1da177e4 | 580 | |
7b8712e5 EM |
581 | #define dev_emerg(dev, format, arg...) \ |
582 | dev_printk(KERN_EMERG , dev , format , ## arg) | |
583 | #define dev_alert(dev, format, arg...) \ | |
584 | dev_printk(KERN_ALERT , dev , format , ## arg) | |
585 | #define dev_crit(dev, format, arg...) \ | |
586 | dev_printk(KERN_CRIT , dev , format , ## arg) | |
587 | #define dev_err(dev, format, arg...) \ | |
588 | dev_printk(KERN_ERR , dev , format , ## arg) | |
589 | #define dev_warn(dev, format, arg...) \ | |
590 | dev_printk(KERN_WARNING , dev , format , ## arg) | |
591 | #define dev_notice(dev, format, arg...) \ | |
592 | dev_printk(KERN_NOTICE , dev , format , ## arg) | |
593 | #define dev_info(dev, format, arg...) \ | |
594 | dev_printk(KERN_INFO , dev , format , ## arg) | |
595 | ||
1da177e4 LT |
596 | #ifdef DEBUG |
597 | #define dev_dbg(dev, format, arg...) \ | |
598 | dev_printk(KERN_DEBUG , dev , format , ## arg) | |
599 | #else | |
404d5b18 | 600 | static inline int __attribute__ ((format (printf, 2, 3))) |
d462943a | 601 | dev_dbg(struct device *dev, const char *fmt, ...) |
404d5b18 DW |
602 | { |
603 | return 0; | |
604 | } | |
1da177e4 LT |
605 | #endif |
606 | ||
aebdc3b4 DB |
607 | #ifdef VERBOSE_DEBUG |
608 | #define dev_vdbg dev_dbg | |
609 | #else | |
610 | static inline int __attribute__ ((format (printf, 2, 3))) | |
d462943a | 611 | dev_vdbg(struct device *dev, const char *fmt, ...) |
aebdc3b4 DB |
612 | { |
613 | return 0; | |
614 | } | |
615 | #endif | |
616 | ||
1da177e4 LT |
617 | /* Create alias, so I can be autoloaded. */ |
618 | #define MODULE_ALIAS_CHARDEV(major,minor) \ | |
619 | MODULE_ALIAS("char-major-" __stringify(major) "-" __stringify(minor)) | |
620 | #define MODULE_ALIAS_CHARDEV_MAJOR(major) \ | |
621 | MODULE_ALIAS("char-major-" __stringify(major) "-*") | |
622 | #endif /* _DEVICE_H_ */ |