Add linux-next specific files for 20110831
[linux-2.6/next.git] / include / linux / device.h
blob500dad174ff347e8b7c40f49e7e532cf9cbcbbc1
1 /*
2 * device.h - generic, centralized driver model
4 * Copyright (c) 2001-2003 Patrick Mochel <mochel@osdl.org>
5 * Copyright (c) 2004-2009 Greg Kroah-Hartman <gregkh@suse.de>
6 * Copyright (c) 2008-2009 Novell Inc.
8 * This file is released under the GPLv2
10 * See Documentation/driver-model/ for more information.
13 #ifndef _DEVICE_H_
14 #define _DEVICE_H_
16 #include <linux/ioport.h>
17 #include <linux/kobject.h>
18 #include <linux/klist.h>
19 #include <linux/list.h>
20 #include <linux/lockdep.h>
21 #include <linux/compiler.h>
22 #include <linux/types.h>
23 #include <linux/mutex.h>
24 #include <linux/pm.h>
25 #include <linux/atomic.h>
26 #include <asm/device.h>
28 struct device;
29 struct device_private;
30 struct device_driver;
31 struct driver_private;
32 struct module;
33 struct class;
34 struct subsys_private;
35 struct bus_type;
36 struct device_node;
38 struct bus_attribute {
39 struct attribute attr;
40 ssize_t (*show)(struct bus_type *bus, char *buf);
41 ssize_t (*store)(struct bus_type *bus, const char *buf, size_t count);
44 #define BUS_ATTR(_name, _mode, _show, _store) \
45 struct bus_attribute bus_attr_##_name = __ATTR(_name, _mode, _show, _store)
47 extern int __must_check bus_create_file(struct bus_type *,
48 struct bus_attribute *);
49 extern void bus_remove_file(struct bus_type *, struct bus_attribute *);
51 /**
52 * struct bus_type - The bus type of the device
54 * @name: The name of the bus.
55 * @bus_attrs: Default attributes of the bus.
56 * @dev_attrs: Default attributes of the devices on the bus.
57 * @drv_attrs: Default attributes of the device drivers on the bus.
58 * @match: Called, perhaps multiple times, whenever a new device or driver
59 * is added for this bus. It should return a nonzero value if the
60 * given device can be handled by the given driver.
61 * @uevent: Called when a device is added, removed, or a few other things
62 * that generate uevents to add the environment variables.
63 * @probe: Called when a new device or driver add to this bus, and callback
64 * the specific driver's probe to initial the matched device.
65 * @remove: Called when a device removed from this bus.
66 * @shutdown: Called at shut-down time to quiesce the device.
67 * @suspend: Called when a device on this bus wants to go to sleep mode.
68 * @resume: Called to bring a device on this bus out of sleep mode.
69 * @pm: Power management operations of this bus, callback the specific
70 * device driver's pm-ops.
71 * @p: The private data of the driver core, only the driver core can
72 * touch this.
74 * A bus is a channel between the processor and one or more devices. For the
75 * purposes of the device model, all devices are connected via a bus, even if
76 * it is an internal, virtual, "platform" bus. Buses can plug into each other.
77 * A USB controller is usually a PCI device, for example. The device model
78 * represents the actual connections between buses and the devices they control.
79 * A bus is represented by the bus_type structure. It contains the name, the
80 * default attributes, the bus' methods, PM operations, and the driver core's
81 * private data.
83 struct bus_type {
84 const char *name;
85 struct bus_attribute *bus_attrs;
86 struct device_attribute *dev_attrs;
87 struct driver_attribute *drv_attrs;
89 int (*match)(struct device *dev, struct device_driver *drv);
90 int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
91 int (*probe)(struct device *dev);
92 int (*remove)(struct device *dev);
93 void (*shutdown)(struct device *dev);
95 int (*suspend)(struct device *dev, pm_message_t state);
96 int (*resume)(struct device *dev);
98 const struct dev_pm_ops *pm;
100 struct subsys_private *p;
103 extern int __must_check bus_register(struct bus_type *bus);
104 extern void bus_unregister(struct bus_type *bus);
106 extern int __must_check bus_rescan_devices(struct bus_type *bus);
108 /* iterator helpers for buses */
110 int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
111 int (*fn)(struct device *dev, void *data));
112 struct device *bus_find_device(struct bus_type *bus, struct device *start,
113 void *data,
114 int (*match)(struct device *dev, void *data));
115 struct device *bus_find_device_by_name(struct bus_type *bus,
116 struct device *start,
117 const char *name);
119 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
120 void *data, int (*fn)(struct device_driver *, void *));
122 void bus_sort_breadthfirst(struct bus_type *bus,
123 int (*compare)(const struct device *a,
124 const struct device *b));
126 * Bus notifiers: Get notified of addition/removal of devices
127 * and binding/unbinding of drivers to devices.
128 * In the long run, it should be a replacement for the platform
129 * notify hooks.
131 struct notifier_block;
133 extern int bus_register_notifier(struct bus_type *bus,
134 struct notifier_block *nb);
135 extern int bus_unregister_notifier(struct bus_type *bus,
136 struct notifier_block *nb);
138 /* All 4 notifers below get called with the target struct device *
139 * as an argument. Note that those functions are likely to be called
140 * with the device lock held in the core, so be careful.
142 #define BUS_NOTIFY_ADD_DEVICE 0x00000001 /* device added */
143 #define BUS_NOTIFY_DEL_DEVICE 0x00000002 /* device removed */
144 #define BUS_NOTIFY_BIND_DRIVER 0x00000003 /* driver about to be
145 bound */
146 #define BUS_NOTIFY_BOUND_DRIVER 0x00000004 /* driver bound to device */
147 #define BUS_NOTIFY_UNBIND_DRIVER 0x00000005 /* driver about to be
148 unbound */
149 #define BUS_NOTIFY_UNBOUND_DRIVER 0x00000006 /* driver is unbound
150 from the device */
152 extern struct kset *bus_get_kset(struct bus_type *bus);
153 extern struct klist *bus_get_device_klist(struct bus_type *bus);
156 * struct device_driver - The basic device driver structure
157 * @name: Name of the device driver.
158 * @bus: The bus which the device of this driver belongs to.
159 * @owner: The module owner.
160 * @mod_name: Used for built-in modules.
161 * @suppress_bind_attrs: Disables bind/unbind via sysfs.
162 * @of_match_table: The open firmware table.
163 * @probe: Called to query the existence of a specific device,
164 * whether this driver can work with it, and bind the driver
165 * to a specific device.
166 * @remove: Called when the device is removed from the system to
167 * unbind a device from this driver.
168 * @shutdown: Called at shut-down time to quiesce the device.
169 * @suspend: Called to put the device to sleep mode. Usually to a
170 * low power state.
171 * @resume: Called to bring a device from sleep mode.
172 * @groups: Default attributes that get created by the driver core
173 * automatically.
174 * @pm: Power management operations of the device which matched
175 * this driver.
176 * @p: Driver core's private data, no one other than the driver
177 * core can touch this.
179 * The device driver-model tracks all of the drivers known to the system.
180 * The main reason for this tracking is to enable the driver core to match
181 * up drivers with new devices. Once drivers are known objects within the
182 * system, however, a number of other things become possible. Device drivers
183 * can export information and configuration variables that are independent
184 * of any specific device.
186 struct device_driver {
187 const char *name;
188 struct bus_type *bus;
190 struct module *owner;
191 const char *mod_name; /* used for built-in modules */
193 bool suppress_bind_attrs; /* disables bind/unbind via sysfs */
195 const struct of_device_id *of_match_table;
197 int (*probe) (struct device *dev);
198 int (*remove) (struct device *dev);
199 void (*shutdown) (struct device *dev);
200 int (*suspend) (struct device *dev, pm_message_t state);
201 int (*resume) (struct device *dev);
202 const struct attribute_group **groups;
204 const struct dev_pm_ops *pm;
206 struct driver_private *p;
210 extern int __must_check driver_register(struct device_driver *drv);
211 extern void driver_unregister(struct device_driver *drv);
213 extern struct device_driver *get_driver(struct device_driver *drv);
214 extern void put_driver(struct device_driver *drv);
215 extern struct device_driver *driver_find(const char *name,
216 struct bus_type *bus);
217 extern int driver_probe_done(void);
218 extern void wait_for_device_probe(void);
221 /* sysfs interface for exporting driver attributes */
223 struct driver_attribute {
224 struct attribute attr;
225 ssize_t (*show)(struct device_driver *driver, char *buf);
226 ssize_t (*store)(struct device_driver *driver, const char *buf,
227 size_t count);
230 #define DRIVER_ATTR(_name, _mode, _show, _store) \
231 struct driver_attribute driver_attr_##_name = \
232 __ATTR(_name, _mode, _show, _store)
234 extern int __must_check driver_create_file(struct device_driver *driver,
235 const struct driver_attribute *attr);
236 extern void driver_remove_file(struct device_driver *driver,
237 const struct driver_attribute *attr);
239 extern int __must_check driver_add_kobj(struct device_driver *drv,
240 struct kobject *kobj,
241 const char *fmt, ...);
243 extern int __must_check driver_for_each_device(struct device_driver *drv,
244 struct device *start,
245 void *data,
246 int (*fn)(struct device *dev,
247 void *));
248 struct device *driver_find_device(struct device_driver *drv,
249 struct device *start, void *data,
250 int (*match)(struct device *dev, void *data));
253 * struct class - device classes
254 * @name: Name of the class.
255 * @owner: The module owner.
256 * @class_attrs: Default attributes of this class.
257 * @dev_attrs: Default attributes of the devices belong to the class.
258 * @dev_bin_attrs: Default binary attributes of the devices belong to the class.
259 * @dev_kobj: The kobject that represents this class and links it into the hierarchy.
260 * @dev_uevent: Called when a device is added, removed from this class, or a
261 * few other things that generate uevents to add the environment
262 * variables.
263 * @devnode: Callback to provide the devtmpfs.
264 * @class_release: Called to release this class.
265 * @dev_release: Called to release the device.
266 * @suspend: Used to put the device to sleep mode, usually to a low power
267 * state.
268 * @resume: Used to bring the device from the sleep mode.
269 * @ns_type: Callbacks so sysfs can detemine namespaces.
270 * @namespace: Namespace of the device belongs to this class.
271 * @pm: The default device power management operations of this class.
272 * @p: The private data of the driver core, no one other than the
273 * driver core can touch this.
275 * A class is a higher-level view of a device that abstracts out low-level
276 * implementation details. Drivers may see a SCSI disk or an ATA disk, but,
277 * at the class level, they are all simply disks. Classes allow user space
278 * to work with devices based on what they do, rather than how they are
279 * connected or how they work.
281 struct class {
282 const char *name;
283 struct module *owner;
285 struct class_attribute *class_attrs;
286 struct device_attribute *dev_attrs;
287 struct bin_attribute *dev_bin_attrs;
288 struct kobject *dev_kobj;
290 int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env);
291 char *(*devnode)(struct device *dev, mode_t *mode);
293 void (*class_release)(struct class *class);
294 void (*dev_release)(struct device *dev);
296 int (*suspend)(struct device *dev, pm_message_t state);
297 int (*resume)(struct device *dev);
299 const struct kobj_ns_type_operations *ns_type;
300 const void *(*namespace)(struct device *dev);
302 const struct dev_pm_ops *pm;
304 struct subsys_private *p;
307 struct class_dev_iter {
308 struct klist_iter ki;
309 const struct device_type *type;
312 extern struct kobject *sysfs_dev_block_kobj;
313 extern struct kobject *sysfs_dev_char_kobj;
314 extern int __must_check __class_register(struct class *class,
315 struct lock_class_key *key);
316 extern void class_unregister(struct class *class);
318 /* This is a #define to keep the compiler from merging different
319 * instances of the __key variable */
320 #define class_register(class) \
321 ({ \
322 static struct lock_class_key __key; \
323 __class_register(class, &__key); \
326 struct class_compat;
327 struct class_compat *class_compat_register(const char *name);
328 void class_compat_unregister(struct class_compat *cls);
329 int class_compat_create_link(struct class_compat *cls, struct device *dev,
330 struct device *device_link);
331 void class_compat_remove_link(struct class_compat *cls, struct device *dev,
332 struct device *device_link);
334 extern void class_dev_iter_init(struct class_dev_iter *iter,
335 struct class *class,
336 struct device *start,
337 const struct device_type *type);
338 extern struct device *class_dev_iter_next(struct class_dev_iter *iter);
339 extern void class_dev_iter_exit(struct class_dev_iter *iter);
341 extern int class_for_each_device(struct class *class, struct device *start,
342 void *data,
343 int (*fn)(struct device *dev, void *data));
344 extern struct device *class_find_device(struct class *class,
345 struct device *start, void *data,
346 int (*match)(struct device *, void *));
348 struct class_attribute {
349 struct attribute attr;
350 ssize_t (*show)(struct class *class, struct class_attribute *attr,
351 char *buf);
352 ssize_t (*store)(struct class *class, struct class_attribute *attr,
353 const char *buf, size_t count);
356 #define CLASS_ATTR(_name, _mode, _show, _store) \
357 struct class_attribute class_attr_##_name = __ATTR(_name, _mode, _show, _store)
359 extern int __must_check class_create_file(struct class *class,
360 const struct class_attribute *attr);
361 extern void class_remove_file(struct class *class,
362 const struct class_attribute *attr);
364 /* Simple class attribute that is just a static string */
366 struct class_attribute_string {
367 struct class_attribute attr;
368 char *str;
371 /* Currently read-only only */
372 #define _CLASS_ATTR_STRING(_name, _mode, _str) \
373 { __ATTR(_name, _mode, show_class_attr_string, NULL), _str }
374 #define CLASS_ATTR_STRING(_name, _mode, _str) \
375 struct class_attribute_string class_attr_##_name = \
376 _CLASS_ATTR_STRING(_name, _mode, _str)
378 extern ssize_t show_class_attr_string(struct class *class, struct class_attribute *attr,
379 char *buf);
381 struct class_interface {
382 struct list_head node;
383 struct class *class;
385 int (*add_dev) (struct device *, struct class_interface *);
386 void (*remove_dev) (struct device *, struct class_interface *);
389 extern int __must_check class_interface_register(struct class_interface *);
390 extern void class_interface_unregister(struct class_interface *);
392 extern struct class * __must_check __class_create(struct module *owner,
393 const char *name,
394 struct lock_class_key *key);
395 extern void class_destroy(struct class *cls);
397 /* This is a #define to keep the compiler from merging different
398 * instances of the __key variable */
399 #define class_create(owner, name) \
400 ({ \
401 static struct lock_class_key __key; \
402 __class_create(owner, name, &__key); \
406 * The type of device, "struct device" is embedded in. A class
407 * or bus can contain devices of different types
408 * like "partitions" and "disks", "mouse" and "event".
409 * This identifies the device type and carries type-specific
410 * information, equivalent to the kobj_type of a kobject.
411 * If "name" is specified, the uevent will contain it in
412 * the DEVTYPE variable.
414 struct device_type {
415 const char *name;
416 const struct attribute_group **groups;
417 int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
418 char *(*devnode)(struct device *dev, mode_t *mode);
419 void (*release)(struct device *dev);
421 const struct dev_pm_ops *pm;
424 /* interface for exporting device attributes */
425 struct device_attribute {
426 struct attribute attr;
427 ssize_t (*show)(struct device *dev, struct device_attribute *attr,
428 char *buf);
429 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
430 const char *buf, size_t count);
433 #define DEVICE_ATTR(_name, _mode, _show, _store) \
434 struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)
436 extern int __must_check device_create_file(struct device *device,
437 const struct device_attribute *entry);
438 extern void device_remove_file(struct device *dev,
439 const struct device_attribute *attr);
440 extern int __must_check device_create_bin_file(struct device *dev,
441 const struct bin_attribute *attr);
442 extern void device_remove_bin_file(struct device *dev,
443 const struct bin_attribute *attr);
444 extern int device_schedule_callback_owner(struct device *dev,
445 void (*func)(struct device *dev), struct module *owner);
447 /* This is a macro to avoid include problems with THIS_MODULE */
448 #define device_schedule_callback(dev, func) \
449 device_schedule_callback_owner(dev, func, THIS_MODULE)
451 /* device resource management */
452 typedef void (*dr_release_t)(struct device *dev, void *res);
453 typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data);
455 #ifdef CONFIG_DEBUG_DEVRES
456 extern void *__devres_alloc(dr_release_t release, size_t size, gfp_t gfp,
457 const char *name);
458 #define devres_alloc(release, size, gfp) \
459 __devres_alloc(release, size, gfp, #release)
460 #else
461 extern void *devres_alloc(dr_release_t release, size_t size, gfp_t gfp);
462 #endif
463 extern void devres_free(void *res);
464 extern void devres_add(struct device *dev, void *res);
465 extern void *devres_find(struct device *dev, dr_release_t release,
466 dr_match_t match, void *match_data);
467 extern void *devres_get(struct device *dev, void *new_res,
468 dr_match_t match, void *match_data);
469 extern void *devres_remove(struct device *dev, dr_release_t release,
470 dr_match_t match, void *match_data);
471 extern int devres_destroy(struct device *dev, dr_release_t release,
472 dr_match_t match, void *match_data);
474 /* devres group */
475 extern void * __must_check devres_open_group(struct device *dev, void *id,
476 gfp_t gfp);
477 extern void devres_close_group(struct device *dev, void *id);
478 extern void devres_remove_group(struct device *dev, void *id);
479 extern int devres_release_group(struct device *dev, void *id);
481 /* managed kzalloc/kfree for device drivers, no kmalloc, always use kzalloc */
482 extern void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp);
483 extern void devm_kfree(struct device *dev, void *p);
485 struct device_dma_parameters {
487 * a low level driver may set these to teach IOMMU code about
488 * sg limitations.
490 unsigned int max_segment_size;
491 unsigned long segment_boundary_mask;
495 * struct device - The basic device structure
496 * @parent: The device's "parent" device, the device to which it is attached.
497 * In most cases, a parent device is some sort of bus or host
498 * controller. If parent is NULL, the device, is a top-level device,
499 * which is not usually what you want.
500 * @p: Holds the private data of the driver core portions of the device.
501 * See the comment of the struct device_private for detail.
502 * @kobj: A top-level, abstract class from which other classes are derived.
503 * @init_name: Initial name of the device.
504 * @type: The type of device.
505 * This identifies the device type and carries type-specific
506 * information.
507 * @mutex: Mutex to synchronize calls to its driver.
508 * @bus: Type of bus device is on.
509 * @driver: Which driver has allocated this
510 * @platform_data: Platform data specific to the device.
511 * Example: For devices on custom boards, as typical of embedded
512 * and SOC based hardware, Linux often uses platform_data to point
513 * to board-specific structures describing devices and how they
514 * are wired. That can include what ports are available, chip
515 * variants, which GPIO pins act in what additional roles, and so
516 * on. This shrinks the "Board Support Packages" (BSPs) and
517 * minimizes board-specific #ifdefs in drivers.
518 * @power: For device power management.
519 * See Documentation/power/devices.txt for details.
520 * @pm_domain: Provide callbacks that are executed during system suspend,
521 * hibernation, system resume and during runtime PM transitions
522 * along with subsystem-level and driver-level callbacks.
523 * @numa_node: NUMA node this device is close to.
524 * @dma_mask: Dma mask (if dma'ble device).
525 * @coherent_dma_mask: Like dma_mask, but for alloc_coherent mapping as not all
526 * hardware supports 64-bit addresses for consistent allocations
527 * such descriptors.
528 * @dma_parms: A low level driver may set these to teach IOMMU code about
529 * segment limitations.
530 * @dma_pools: Dma pools (if dma'ble device).
531 * @dma_mem: Internal for coherent mem override.
532 * @archdata: For arch-specific additions.
533 * @of_node: Associated device tree node.
534 * @devt: For creating the sysfs "dev".
535 * @devres_lock: Spinlock to protect the resource of the device.
536 * @devres_head: The resources list of the device.
537 * @knode_class: The node used to add the device to the class list.
538 * @class: The class of the device.
539 * @groups: Optional attribute groups.
540 * @release: Callback to free the device after all references have
541 * gone away. This should be set by the allocator of the
542 * device (i.e. the bus driver that discovered the device).
544 * At the lowest level, every device in a Linux system is represented by an
545 * instance of struct device. The device structure contains the information
546 * that the device model core needs to model the system. Most subsystems,
547 * however, track additional information about the devices they host. As a
548 * result, it is rare for devices to be represented by bare device structures;
549 * instead, that structure, like kobject structures, is usually embedded within
550 * a higher-level representation of the device.
552 struct device {
553 struct device *parent;
555 struct device_private *p;
557 struct kobject kobj;
558 const char *init_name; /* initial name of the device */
559 const struct device_type *type;
561 struct mutex mutex; /* mutex to synchronize calls to
562 * its driver.
565 struct bus_type *bus; /* type of bus device is on */
566 struct device_driver *driver; /* which driver has allocated this
567 device */
568 void *platform_data; /* Platform specific data, device
569 core doesn't touch it */
570 struct dev_pm_info power;
571 struct dev_pm_domain *pm_domain;
573 #ifdef CONFIG_NUMA
574 int numa_node; /* NUMA node this device is close to */
575 #endif
576 u64 *dma_mask; /* dma mask (if dma'able device) */
577 u64 coherent_dma_mask;/* Like dma_mask, but for
578 alloc_coherent mappings as
579 not all hardware supports
580 64 bit addresses for consistent
581 allocations such descriptors. */
583 struct device_dma_parameters *dma_parms;
585 struct list_head dma_pools; /* dma pools (if dma'ble) */
587 struct dma_coherent_mem *dma_mem; /* internal for coherent mem
588 override */
589 /* arch specific additions */
590 struct dev_archdata archdata;
592 struct device_node *of_node; /* associated device tree node */
594 dev_t devt; /* dev_t, creates the sysfs "dev" */
596 spinlock_t devres_lock;
597 struct list_head devres_head;
599 struct klist_node knode_class;
600 struct class *class;
601 const struct attribute_group **groups; /* optional groups */
603 void (*release)(struct device *dev);
606 /* Get the wakeup routines, which depend on struct device */
607 #include <linux/pm_wakeup.h>
609 static inline const char *dev_name(const struct device *dev)
611 /* Use the init name until the kobject becomes available */
612 if (dev->init_name)
613 return dev->init_name;
615 return kobject_name(&dev->kobj);
618 extern int dev_set_name(struct device *dev, const char *name, ...)
619 __attribute__((format(printf, 2, 3)));
621 #ifdef CONFIG_NUMA
622 static inline int dev_to_node(struct device *dev)
624 return dev->numa_node;
626 static inline void set_dev_node(struct device *dev, int node)
628 dev->numa_node = node;
630 #else
631 static inline int dev_to_node(struct device *dev)
633 return -1;
635 static inline void set_dev_node(struct device *dev, int node)
638 #endif
640 static inline struct pm_subsys_data *dev_to_psd(struct device *dev)
642 return dev ? dev->power.subsys_data : NULL;
645 static inline unsigned int dev_get_uevent_suppress(const struct device *dev)
647 return dev->kobj.uevent_suppress;
650 static inline void dev_set_uevent_suppress(struct device *dev, int val)
652 dev->kobj.uevent_suppress = val;
655 static inline int device_is_registered(struct device *dev)
657 return dev->kobj.state_in_sysfs;
660 static inline void device_enable_async_suspend(struct device *dev)
662 if (!dev->power.is_prepared)
663 dev->power.async_suspend = true;
666 static inline void device_disable_async_suspend(struct device *dev)
668 if (!dev->power.is_prepared)
669 dev->power.async_suspend = false;
672 static inline bool device_async_suspend_enabled(struct device *dev)
674 return !!dev->power.async_suspend;
677 static inline void device_lock(struct device *dev)
679 mutex_lock(&dev->mutex);
682 static inline int device_trylock(struct device *dev)
684 return mutex_trylock(&dev->mutex);
687 static inline void device_unlock(struct device *dev)
689 mutex_unlock(&dev->mutex);
692 void driver_init(void);
695 * High level routines for use by the bus drivers
697 extern int __must_check device_register(struct device *dev);
698 extern void device_unregister(struct device *dev);
699 extern void device_initialize(struct device *dev);
700 extern int __must_check device_add(struct device *dev);
701 extern void device_del(struct device *dev);
702 extern int device_for_each_child(struct device *dev, void *data,
703 int (*fn)(struct device *dev, void *data));
704 extern struct device *device_find_child(struct device *dev, void *data,
705 int (*match)(struct device *dev, void *data));
706 extern int device_rename(struct device *dev, const char *new_name);
707 extern int device_move(struct device *dev, struct device *new_parent,
708 enum dpm_order dpm_order);
709 extern const char *device_get_devnode(struct device *dev,
710 mode_t *mode, const char **tmp);
711 extern void *dev_get_drvdata(const struct device *dev);
712 extern int dev_set_drvdata(struct device *dev, void *data);
715 * Root device objects for grouping under /sys/devices
717 extern struct device *__root_device_register(const char *name,
718 struct module *owner);
721 * This is a macro to avoid include problems with THIS_MODULE,
722 * just as per what is done for device_schedule_callback() above.
724 #define root_device_register(name) \
725 __root_device_register(name, THIS_MODULE)
727 extern void root_device_unregister(struct device *root);
729 static inline void *dev_get_platdata(const struct device *dev)
731 return dev->platform_data;
735 * Manual binding of a device to driver. See drivers/base/bus.c
736 * for information on use.
738 extern int __must_check device_bind_driver(struct device *dev);
739 extern void device_release_driver(struct device *dev);
740 extern int __must_check device_attach(struct device *dev);
741 extern int __must_check driver_attach(struct device_driver *drv);
742 extern int __must_check device_reprobe(struct device *dev);
745 * Easy functions for dynamically creating devices on the fly
747 extern struct device *device_create_vargs(struct class *cls,
748 struct device *parent,
749 dev_t devt,
750 void *drvdata,
751 const char *fmt,
752 va_list vargs);
753 extern struct device *device_create(struct class *cls, struct device *parent,
754 dev_t devt, void *drvdata,
755 const char *fmt, ...)
756 __attribute__((format(printf, 5, 6)));
757 extern void device_destroy(struct class *cls, dev_t devt);
760 * Platform "fixup" functions - allow the platform to have their say
761 * about devices and actions that the general device layer doesn't
762 * know about.
764 /* Notify platform of device discovery */
765 extern int (*platform_notify)(struct device *dev);
767 extern int (*platform_notify_remove)(struct device *dev);
771 * get_device - atomically increment the reference count for the device.
774 extern struct device *get_device(struct device *dev);
775 extern void put_device(struct device *dev);
777 extern void wait_for_device_probe(void);
779 #ifdef CONFIG_DEVTMPFS
780 extern int devtmpfs_create_node(struct device *dev);
781 extern int devtmpfs_delete_node(struct device *dev);
782 extern int devtmpfs_mount(const char *mntdir);
783 #else
784 static inline int devtmpfs_create_node(struct device *dev) { return 0; }
785 static inline int devtmpfs_delete_node(struct device *dev) { return 0; }
786 static inline int devtmpfs_mount(const char *mountpoint) { return 0; }
787 #endif
789 /* drivers/base/power/shutdown.c */
790 extern void device_shutdown(void);
792 /* debugging and troubleshooting/diagnostic helpers. */
793 extern const char *dev_driver_string(const struct device *dev);
796 #ifdef CONFIG_PRINTK
798 extern int __dev_printk(const char *level, const struct device *dev,
799 struct va_format *vaf);
800 extern int dev_printk(const char *level, const struct device *dev,
801 const char *fmt, ...)
802 __attribute__ ((format (printf, 3, 4)));
803 extern int dev_emerg(const struct device *dev, const char *fmt, ...)
804 __attribute__ ((format (printf, 2, 3)));
805 extern int dev_alert(const struct device *dev, const char *fmt, ...)
806 __attribute__ ((format (printf, 2, 3)));
807 extern int dev_crit(const struct device *dev, const char *fmt, ...)
808 __attribute__ ((format (printf, 2, 3)));
809 extern int dev_err(const struct device *dev, const char *fmt, ...)
810 __attribute__ ((format (printf, 2, 3)));
811 extern int dev_warn(const struct device *dev, const char *fmt, ...)
812 __attribute__ ((format (printf, 2, 3)));
813 extern int dev_notice(const struct device *dev, const char *fmt, ...)
814 __attribute__ ((format (printf, 2, 3)));
815 extern int _dev_info(const struct device *dev, const char *fmt, ...)
816 __attribute__ ((format (printf, 2, 3)));
818 #else
820 static inline int __dev_printk(const char *level, const struct device *dev,
821 struct va_format *vaf)
822 { return 0; }
823 static inline int dev_printk(const char *level, const struct device *dev,
824 const char *fmt, ...)
825 __attribute__ ((format (printf, 3, 4)));
826 static inline int dev_printk(const char *level, const struct device *dev,
827 const char *fmt, ...)
828 { return 0; }
830 static inline int dev_emerg(const struct device *dev, const char *fmt, ...)
831 __attribute__ ((format (printf, 2, 3)));
832 static inline int dev_emerg(const struct device *dev, const char *fmt, ...)
833 { return 0; }
834 static inline int dev_crit(const struct device *dev, const char *fmt, ...)
835 __attribute__ ((format (printf, 2, 3)));
836 static inline int dev_crit(const struct device *dev, const char *fmt, ...)
837 { return 0; }
838 static inline int dev_alert(const struct device *dev, const char *fmt, ...)
839 __attribute__ ((format (printf, 2, 3)));
840 static inline int dev_alert(const struct device *dev, const char *fmt, ...)
841 { return 0; }
842 static inline int dev_err(const struct device *dev, const char *fmt, ...)
843 __attribute__ ((format (printf, 2, 3)));
844 static inline int dev_err(const struct device *dev, const char *fmt, ...)
845 { return 0; }
846 static inline int dev_warn(const struct device *dev, const char *fmt, ...)
847 __attribute__ ((format (printf, 2, 3)));
848 static inline int dev_warn(const struct device *dev, const char *fmt, ...)
849 { return 0; }
850 static inline int dev_notice(const struct device *dev, const char *fmt, ...)
851 __attribute__ ((format (printf, 2, 3)));
852 static inline int dev_notice(const struct device *dev, const char *fmt, ...)
853 { return 0; }
854 static inline int _dev_info(const struct device *dev, const char *fmt, ...)
855 __attribute__ ((format (printf, 2, 3)));
856 static inline int _dev_info(const struct device *dev, const char *fmt, ...)
857 { return 0; }
859 #endif
862 * Stupid hackaround for existing uses of non-printk uses dev_info
864 * Note that the definition of dev_info below is actually _dev_info
865 * and a macro is used to avoid redefining dev_info
868 #define dev_info(dev, fmt, arg...) _dev_info(dev, fmt, ##arg)
870 #if defined(DEBUG)
871 #define dev_dbg(dev, format, arg...) \
872 dev_printk(KERN_DEBUG, dev, format, ##arg)
873 #elif defined(CONFIG_DYNAMIC_DEBUG)
874 #define dev_dbg(dev, format, ...) \
875 do { \
876 dynamic_dev_dbg(dev, format, ##__VA_ARGS__); \
877 } while (0)
878 #else
879 #define dev_dbg(dev, format, arg...) \
880 ({ \
881 if (0) \
882 dev_printk(KERN_DEBUG, dev, format, ##arg); \
883 0; \
885 #endif
887 #ifdef VERBOSE_DEBUG
888 #define dev_vdbg dev_dbg
889 #else
890 #define dev_vdbg(dev, format, arg...) \
891 ({ \
892 if (0) \
893 dev_printk(KERN_DEBUG, dev, format, ##arg); \
894 0; \
896 #endif
899 * dev_WARN*() acts like dev_printk(), but with the key difference
900 * of using a WARN/WARN_ON to get the message out, including the
901 * file/line information and a backtrace.
903 #define dev_WARN(dev, format, arg...) \
904 WARN(1, "Device: %s\n" format, dev_driver_string(dev), ## arg);
906 #define dev_WARN_ONCE(dev, condition, format, arg...) \
907 WARN_ONCE(condition, "Device %s\n" format, \
908 dev_driver_string(dev), ## arg)
910 /* Create alias, so I can be autoloaded. */
911 #define MODULE_ALIAS_CHARDEV(major,minor) \
912 MODULE_ALIAS("char-major-" __stringify(major) "-" __stringify(minor))
913 #define MODULE_ALIAS_CHARDEV_MAJOR(major) \
914 MODULE_ALIAS("char-major-" __stringify(major) "-*")
916 #ifdef CONFIG_SYSFS_DEPRECATED
917 extern long sysfs_deprecated;
918 #else
919 #define sysfs_deprecated 0
920 #endif
922 #endif /* _DEVICE_H_ */