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