]>
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> | |
6188e10d | 23 | #include <linux/semaphore.h> |
1da177e4 | 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 | 37 | struct class; |
7c71448b | 38 | struct class_private; |
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 | |
1eede070 RW |
72 | struct pm_ext_ops *pm; |
73 | ||
c6f7e72a | 74 | struct bus_type_private *p; |
1da177e4 LT |
75 | }; |
76 | ||
d462943a GKH |
77 | extern int __must_check bus_register(struct bus_type *bus); |
78 | extern void bus_unregister(struct bus_type *bus); | |
1da177e4 | 79 | |
d462943a | 80 | extern int __must_check bus_rescan_devices(struct bus_type *bus); |
1da177e4 | 81 | |
1da177e4 LT |
82 | /* iterator helpers for buses */ |
83 | ||
d462943a GKH |
84 | int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, |
85 | int (*fn)(struct device *dev, void *data)); | |
86 | struct device *bus_find_device(struct bus_type *bus, struct device *start, | |
87 | void *data, | |
88 | int (*match)(struct device *dev, void *data)); | |
1f9ffc04 GKH |
89 | struct device *bus_find_device_by_name(struct bus_type *bus, |
90 | struct device *start, | |
91 | const char *name); | |
1da177e4 | 92 | |
4a7fb636 | 93 | int __must_check bus_for_each_drv(struct bus_type *bus, |
d462943a GKH |
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 | ||
0fed80f7 | 120 | extern struct kset *bus_get_kset(struct bus_type *bus); |
b249072e | 121 | extern struct klist *bus_get_device_klist(struct bus_type *bus); |
0fed80f7 | 122 | |
1da177e4 | 123 | struct device_driver { |
e5dd1278 GKH |
124 | const char *name; |
125 | struct bus_type *bus; | |
1da177e4 | 126 | |
e5dd1278 GKH |
127 | struct module *owner; |
128 | const char *mod_name; /* used for built-in modules */ | |
1da177e4 | 129 | |
d462943a GKH |
130 | int (*probe) (struct device *dev); |
131 | int (*remove) (struct device *dev); | |
132 | void (*shutdown) (struct device *dev); | |
133 | int (*suspend) (struct device *dev, pm_message_t state); | |
134 | int (*resume) (struct device *dev); | |
57c74534 | 135 | struct attribute_group **groups; |
e5dd1278 | 136 | |
1eede070 RW |
137 | struct pm_ops *pm; |
138 | ||
e5dd1278 | 139 | struct driver_private *p; |
1da177e4 LT |
140 | }; |
141 | ||
142 | ||
d462943a GKH |
143 | extern int __must_check driver_register(struct device_driver *drv); |
144 | extern void driver_unregister(struct device_driver *drv); | |
1da177e4 | 145 | |
d462943a GKH |
146 | extern struct device_driver *get_driver(struct device_driver *drv); |
147 | extern void put_driver(struct device_driver *drv); | |
148 | extern struct device_driver *driver_find(const char *name, | |
149 | struct bus_type *bus); | |
d779249e | 150 | extern int driver_probe_done(void); |
1da177e4 | 151 | |
405ae7d3 | 152 | /* sysfs interface for exporting driver attributes */ |
1da177e4 LT |
153 | |
154 | struct driver_attribute { | |
d462943a GKH |
155 | struct attribute attr; |
156 | ssize_t (*show)(struct device_driver *driver, char *buf); | |
157 | ssize_t (*store)(struct device_driver *driver, const char *buf, | |
158 | size_t count); | |
1da177e4 LT |
159 | }; |
160 | ||
d462943a GKH |
161 | #define DRIVER_ATTR(_name, _mode, _show, _store) \ |
162 | struct driver_attribute driver_attr_##_name = \ | |
163 | __ATTR(_name, _mode, _show, _store) | |
1da177e4 | 164 | |
d462943a GKH |
165 | extern int __must_check driver_create_file(struct device_driver *driver, |
166 | struct driver_attribute *attr); | |
167 | extern void driver_remove_file(struct device_driver *driver, | |
168 | struct driver_attribute *attr); | |
1da177e4 | 169 | |
cbe9c595 GKH |
170 | extern int __must_check driver_add_kobj(struct device_driver *drv, |
171 | struct kobject *kobj, | |
172 | const char *fmt, ...); | |
173 | ||
d462943a GKH |
174 | extern int __must_check driver_for_each_device(struct device_driver *drv, |
175 | struct device *start, | |
176 | void *data, | |
177 | int (*fn)(struct device *dev, | |
178 | void *)); | |
179 | struct device *driver_find_device(struct device_driver *drv, | |
180 | struct device *start, void *data, | |
181 | int (*match)(struct device *dev, void *data)); | |
fae3cd00 | 182 | |
1da177e4 LT |
183 | /* |
184 | * device classes | |
185 | */ | |
186 | struct class { | |
d462943a GKH |
187 | const char *name; |
188 | struct module *owner; | |
1da177e4 | 189 | |
d462943a | 190 | struct class_attribute *class_attrs; |
d462943a | 191 | struct device_attribute *dev_attrs; |
e105b8bf | 192 | struct kobject *dev_kobj; |
1da177e4 | 193 | |
d462943a | 194 | int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env); |
1da177e4 | 195 | |
d462943a GKH |
196 | void (*class_release)(struct class *class); |
197 | void (*dev_release)(struct device *dev); | |
7c8265f5 | 198 | |
d462943a GKH |
199 | int (*suspend)(struct device *dev, pm_message_t state); |
200 | int (*resume)(struct device *dev); | |
1eede070 RW |
201 | |
202 | struct pm_ops *pm; | |
7c71448b | 203 | struct class_private *p; |
1da177e4 LT |
204 | }; |
205 | ||
e105b8bf DW |
206 | extern struct kobject *sysfs_dev_block_kobj; |
207 | extern struct kobject *sysfs_dev_char_kobj; | |
d462943a GKH |
208 | extern int __must_check class_register(struct class *class); |
209 | extern void class_unregister(struct class *class); | |
93562b53 GKH |
210 | extern int class_for_each_device(struct class *class, struct device *start, |
211 | void *data, | |
fd04897b | 212 | int (*fn)(struct device *dev, void *data)); |
695794ae GKH |
213 | extern struct device *class_find_device(struct class *class, |
214 | struct device *start, void *data, | |
fd04897b | 215 | int (*match)(struct device *, void *)); |
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 | |
1da177e4 LT |
231 | struct class_interface { |
232 | struct list_head node; | |
233 | struct class *class; | |
234 | ||
c47ed219 GKH |
235 | int (*add_dev) (struct device *, struct class_interface *); |
236 | void (*remove_dev) (struct device *, struct class_interface *); | |
1da177e4 LT |
237 | }; |
238 | ||
4a7fb636 | 239 | extern int __must_check class_interface_register(struct class_interface *); |
1da177e4 LT |
240 | extern void class_interface_unregister(struct class_interface *); |
241 | ||
ab7d7371 | 242 | extern struct class *class_create(struct module *owner, const char *name); |
e9ba6365 | 243 | extern void class_destroy(struct class *cls); |
e9ba6365 | 244 | |
414264f9 KS |
245 | /* |
246 | * The type of device, "struct device" is embedded in. A class | |
247 | * or bus can contain devices of different types | |
248 | * like "partitions" and "disks", "mouse" and "event". | |
249 | * This identifies the device type and carries type-specific | |
250 | * information, equivalent to the kobj_type of a kobject. | |
251 | * If "name" is specified, the uevent will contain it in | |
252 | * the DEVTYPE variable. | |
253 | */ | |
f9f852df | 254 | struct device_type { |
414264f9 | 255 | const char *name; |
621a1672 | 256 | struct attribute_group **groups; |
7eff2e7a | 257 | int (*uevent)(struct device *dev, struct kobj_uevent_env *env); |
f9f852df | 258 | void (*release)(struct device *dev); |
1eede070 | 259 | |
d462943a GKH |
260 | int (*suspend)(struct device *dev, pm_message_t state); |
261 | int (*resume)(struct device *dev); | |
1eede070 RW |
262 | |
263 | struct pm_ops *pm; | |
f9f852df KS |
264 | }; |
265 | ||
a7fd6706 KS |
266 | /* interface for exporting device attributes */ |
267 | struct device_attribute { | |
268 | struct attribute attr; | |
269 | ssize_t (*show)(struct device *dev, struct device_attribute *attr, | |
270 | char *buf); | |
271 | ssize_t (*store)(struct device *dev, struct device_attribute *attr, | |
272 | const char *buf, size_t count); | |
273 | }; | |
274 | ||
d462943a GKH |
275 | #define DEVICE_ATTR(_name, _mode, _show, _store) \ |
276 | struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store) | |
a7fd6706 | 277 | |
4a7fb636 | 278 | extern int __must_check device_create_file(struct device *device, |
d462943a GKH |
279 | struct device_attribute *entry); |
280 | extern void device_remove_file(struct device *dev, | |
281 | struct device_attribute *attr); | |
2589f188 GKH |
282 | extern int __must_check device_create_bin_file(struct device *dev, |
283 | struct bin_attribute *attr); | |
284 | extern void device_remove_bin_file(struct device *dev, | |
285 | struct bin_attribute *attr); | |
523ded71 | 286 | extern int device_schedule_callback_owner(struct device *dev, |
d462943a | 287 | void (*func)(struct device *dev), struct module *owner); |
523ded71 AS |
288 | |
289 | /* This is a macro to avoid include problems with THIS_MODULE */ | |
290 | #define device_schedule_callback(dev, func) \ | |
291 | device_schedule_callback_owner(dev, func, THIS_MODULE) | |
9ac7849e TH |
292 | |
293 | /* device resource management */ | |
294 | typedef void (*dr_release_t)(struct device *dev, void *res); | |
295 | typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data); | |
296 | ||
297 | #ifdef CONFIG_DEBUG_DEVRES | |
d462943a | 298 | extern void *__devres_alloc(dr_release_t release, size_t size, gfp_t gfp, |
9ac7849e TH |
299 | const char *name); |
300 | #define devres_alloc(release, size, gfp) \ | |
301 | __devres_alloc(release, size, gfp, #release) | |
302 | #else | |
d462943a | 303 | extern void *devres_alloc(dr_release_t release, size_t size, gfp_t gfp); |
9ac7849e TH |
304 | #endif |
305 | extern void devres_free(void *res); | |
306 | extern void devres_add(struct device *dev, void *res); | |
d462943a | 307 | extern void *devres_find(struct device *dev, dr_release_t release, |
9ac7849e | 308 | dr_match_t match, void *match_data); |
d462943a GKH |
309 | extern void *devres_get(struct device *dev, void *new_res, |
310 | dr_match_t match, void *match_data); | |
311 | extern void *devres_remove(struct device *dev, dr_release_t release, | |
312 | dr_match_t match, void *match_data); | |
9ac7849e TH |
313 | extern int devres_destroy(struct device *dev, dr_release_t release, |
314 | dr_match_t match, void *match_data); | |
315 | ||
316 | /* devres group */ | |
317 | extern void * __must_check devres_open_group(struct device *dev, void *id, | |
318 | gfp_t gfp); | |
319 | extern void devres_close_group(struct device *dev, void *id); | |
320 | extern void devres_remove_group(struct device *dev, void *id); | |
321 | extern int devres_release_group(struct device *dev, void *id); | |
322 | ||
323 | /* managed kzalloc/kfree for device drivers, no kmalloc, always use kzalloc */ | |
324 | extern void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp); | |
325 | extern void devm_kfree(struct device *dev, void *p); | |
326 | ||
6b7b6510 FT |
327 | struct device_dma_parameters { |
328 | /* | |
329 | * a low level driver may set these to teach IOMMU code about | |
330 | * sg limitations. | |
331 | */ | |
332 | unsigned int max_segment_size; | |
333 | unsigned long segment_boundary_mask; | |
334 | }; | |
335 | ||
1da177e4 | 336 | struct device { |
36239577 | 337 | struct klist klist_children; |
d462943a | 338 | struct klist_node knode_parent; /* node in sibling list */ |
94e7b1c5 | 339 | struct klist_node knode_driver; |
465c7a3a | 340 | struct klist_node knode_bus; |
49a4ec18 | 341 | struct device *parent; |
1da177e4 LT |
342 | |
343 | struct kobject kobj; | |
344 | char bus_id[BUS_ID_SIZE]; /* position on parent bus */ | |
f9f852df | 345 | struct device_type *type; |
49a4ec18 | 346 | unsigned uevent_suppress:1; |
1da177e4 | 347 | |
af70316a PM |
348 | struct semaphore sem; /* semaphore to synchronize calls to |
349 | * its driver. | |
350 | */ | |
351 | ||
d462943a | 352 | struct bus_type *bus; /* type of bus device is on */ |
1da177e4 LT |
353 | struct device_driver *driver; /* which driver has allocated this |
354 | device */ | |
355 | void *driver_data; /* data private to the driver */ | |
4e10d12a DSL |
356 | void *platform_data; /* Platform specific data, device |
357 | core doesn't touch it */ | |
1da177e4 LT |
358 | struct dev_pm_info power; |
359 | ||
87348136 CH |
360 | #ifdef CONFIG_NUMA |
361 | int numa_node; /* NUMA node this device is close to */ | |
362 | #endif | |
1da177e4 LT |
363 | u64 *dma_mask; /* dma mask (if dma'able device) */ |
364 | u64 coherent_dma_mask;/* Like dma_mask, but for | |
365 | alloc_coherent mappings as | |
366 | not all hardware supports | |
367 | 64 bit addresses for consistent | |
368 | allocations such descriptors. */ | |
369 | ||
6b7b6510 FT |
370 | struct device_dma_parameters *dma_parms; |
371 | ||
1da177e4 LT |
372 | struct list_head dma_pools; /* dma pools (if dma'ble) */ |
373 | ||
374 | struct dma_coherent_mem *dma_mem; /* internal for coherent mem | |
375 | override */ | |
c6dbaef2 BH |
376 | /* arch specific additions */ |
377 | struct dev_archdata archdata; | |
1da177e4 | 378 | |
9ac7849e TH |
379 | spinlock_t devres_lock; |
380 | struct list_head devres_head; | |
381 | ||
23681e47 | 382 | struct list_head node; |
b7a3e813 | 383 | struct class *class; |
d462943a | 384 | dev_t devt; /* dev_t, creates the sysfs "dev" */ |
de0ff00d | 385 | struct attribute_group **groups; /* optional groups */ |
23681e47 | 386 | |
d462943a | 387 | void (*release)(struct device *dev); |
1da177e4 LT |
388 | }; |
389 | ||
9a3df1f7 AS |
390 | /* Get the wakeup routines, which depend on struct device */ |
391 | #include <linux/pm_wakeup.h> | |
392 | ||
06916639 KS |
393 | static inline const char *dev_name(struct device *dev) |
394 | { | |
395 | /* will be changed into kobject_name(&dev->kobj) in the near future */ | |
396 | return dev->bus_id; | |
397 | } | |
398 | ||
413c239f SR |
399 | extern int dev_set_name(struct device *dev, const char *name, ...) |
400 | __attribute__((format(printf, 2, 3))); | |
401 | ||
87348136 CH |
402 | #ifdef CONFIG_NUMA |
403 | static inline int dev_to_node(struct device *dev) | |
404 | { | |
405 | return dev->numa_node; | |
406 | } | |
407 | static inline void set_dev_node(struct device *dev, int node) | |
408 | { | |
409 | dev->numa_node = node; | |
410 | } | |
411 | #else | |
412 | static inline int dev_to_node(struct device *dev) | |
413 | { | |
414 | return -1; | |
415 | } | |
416 | static inline void set_dev_node(struct device *dev, int node) | |
417 | { | |
418 | } | |
419 | #endif | |
420 | ||
d462943a | 421 | static inline void *dev_get_drvdata(struct device *dev) |
1da177e4 LT |
422 | { |
423 | return dev->driver_data; | |
424 | } | |
425 | ||
d462943a | 426 | static inline void dev_set_drvdata(struct device *dev, void *data) |
1da177e4 LT |
427 | { |
428 | dev->driver_data = data; | |
429 | } | |
430 | ||
d305ef5d DR |
431 | static inline int device_is_registered(struct device *dev) |
432 | { | |
3f62e570 | 433 | return dev->kobj.state_in_sysfs; |
d305ef5d DR |
434 | } |
435 | ||
1f21782e AB |
436 | void driver_init(void); |
437 | ||
1da177e4 LT |
438 | /* |
439 | * High level routines for use by the bus drivers | |
440 | */ | |
d462943a GKH |
441 | extern int __must_check device_register(struct device *dev); |
442 | extern void device_unregister(struct device *dev); | |
443 | extern void device_initialize(struct device *dev); | |
444 | extern int __must_check device_add(struct device *dev); | |
445 | extern void device_del(struct device *dev); | |
446 | extern int device_for_each_child(struct device *dev, void *data, | |
447 | int (*fn)(struct device *dev, void *data)); | |
448 | extern struct device *device_find_child(struct device *dev, void *data, | |
449 | int (*match)(struct device *dev, void *data)); | |
a2de48ca | 450 | extern int device_rename(struct device *dev, char *new_name); |
8a82472f | 451 | extern int device_move(struct device *dev, struct device *new_parent); |
1da177e4 LT |
452 | |
453 | /* | |
454 | * Manual binding of a device to driver. See drivers/base/bus.c | |
455 | * for information on use. | |
456 | */ | |
f86db396 | 457 | extern int __must_check device_bind_driver(struct device *dev); |
d462943a GKH |
458 | extern void device_release_driver(struct device *dev); |
459 | extern int __must_check device_attach(struct device *dev); | |
f86db396 AM |
460 | extern int __must_check driver_attach(struct device_driver *drv); |
461 | extern int __must_check device_reprobe(struct device *dev); | |
1da177e4 | 462 | |
23681e47 GKH |
463 | /* |
464 | * Easy functions for dynamically creating devices on the fly | |
465 | */ | |
8882b394 GKH |
466 | extern struct device *device_create_vargs(struct class *cls, |
467 | struct device *parent, | |
468 | dev_t devt, | |
469 | void *drvdata, | |
470 | const char *fmt, | |
471 | va_list vargs); | |
4e106739 GKH |
472 | extern struct device *device_create(struct class *cls, struct device *parent, |
473 | dev_t devt, void *drvdata, | |
474 | const char *fmt, ...) | |
8882b394 | 475 | __attribute__((format(printf, 5, 6))); |
4e106739 | 476 | #define device_create_drvdata device_create |
23681e47 | 477 | extern void device_destroy(struct class *cls, dev_t devt); |
1da177e4 | 478 | |
1da177e4 LT |
479 | /* |
480 | * Platform "fixup" functions - allow the platform to have their say | |
481 | * about devices and actions that the general device layer doesn't | |
482 | * know about. | |
483 | */ | |
484 | /* Notify platform of device discovery */ | |
d462943a | 485 | extern int (*platform_notify)(struct device *dev); |
1da177e4 | 486 | |
d462943a | 487 | extern int (*platform_notify_remove)(struct device *dev); |
1da177e4 LT |
488 | |
489 | ||
490 | /** | |
491 | * get_device - atomically increment the reference count for the device. | |
492 | * | |
493 | */ | |
d462943a GKH |
494 | extern struct device *get_device(struct device *dev); |
495 | extern void put_device(struct device *dev); | |
1da177e4 LT |
496 | |
497 | ||
116f232b | 498 | /* drivers/base/power/shutdown.c */ |
1da177e4 LT |
499 | extern void device_shutdown(void); |
500 | ||
58b3b71d RW |
501 | /* drivers/base/sys.c */ |
502 | extern void sysdev_shutdown(void); | |
503 | ||
1da177e4 | 504 | /* debugging and troubleshooting/diagnostic helpers. */ |
3e95637a | 505 | extern const char *dev_driver_string(struct device *dev); |
1da177e4 | 506 | #define dev_printk(level, dev, format, arg...) \ |
d462943a | 507 | printk(level "%s %s: " format , dev_driver_string(dev) , \ |
06916639 | 508 | dev_name(dev) , ## arg) |
1da177e4 | 509 | |
7b8712e5 EM |
510 | #define dev_emerg(dev, format, arg...) \ |
511 | dev_printk(KERN_EMERG , dev , format , ## arg) | |
512 | #define dev_alert(dev, format, arg...) \ | |
513 | dev_printk(KERN_ALERT , dev , format , ## arg) | |
514 | #define dev_crit(dev, format, arg...) \ | |
515 | dev_printk(KERN_CRIT , dev , format , ## arg) | |
516 | #define dev_err(dev, format, arg...) \ | |
517 | dev_printk(KERN_ERR , dev , format , ## arg) | |
518 | #define dev_warn(dev, format, arg...) \ | |
519 | dev_printk(KERN_WARNING , dev , format , ## arg) | |
520 | #define dev_notice(dev, format, arg...) \ | |
521 | dev_printk(KERN_NOTICE , dev , format , ## arg) | |
522 | #define dev_info(dev, format, arg...) \ | |
523 | dev_printk(KERN_INFO , dev , format , ## arg) | |
524 | ||
1da177e4 LT |
525 | #ifdef DEBUG |
526 | #define dev_dbg(dev, format, arg...) \ | |
527 | dev_printk(KERN_DEBUG , dev , format , ## arg) | |
528 | #else | |
1429db83 JP |
529 | #define dev_dbg(dev, format, arg...) \ |
530 | ({ if (0) dev_printk(KERN_DEBUG, dev, format, ##arg); 0; }) | |
1da177e4 LT |
531 | #endif |
532 | ||
aebdc3b4 DB |
533 | #ifdef VERBOSE_DEBUG |
534 | #define dev_vdbg dev_dbg | |
535 | #else | |
1429db83 JP |
536 | |
537 | #define dev_vdbg(dev, format, arg...) \ | |
538 | ({ if (0) dev_printk(KERN_DEBUG, dev, format, ##arg); 0; }) | |
aebdc3b4 DB |
539 | #endif |
540 | ||
1da177e4 LT |
541 | /* Create alias, so I can be autoloaded. */ |
542 | #define MODULE_ALIAS_CHARDEV(major,minor) \ | |
543 | MODULE_ALIAS("char-major-" __stringify(major) "-" __stringify(minor)) | |
544 | #define MODULE_ALIAS_CHARDEV_MAJOR(major) \ | |
545 | MODULE_ALIAS("char-major-" __stringify(major) "-*") | |
546 | #endif /* _DEVICE_H_ */ |