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