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