diff options
Diffstat (limited to 'include/linux/device.h')
| -rw-r--r-- | include/linux/device.h | 99 |
1 files changed, 64 insertions, 35 deletions
diff --git a/include/linux/device.h b/include/linux/device.h index 1e5f30da98bc..662e6a10144e 100644 --- a/include/linux/device.h +++ b/include/linux/device.h | |||
| @@ -15,6 +15,7 @@ | |||
| 15 | #include <linux/kobject.h> | 15 | #include <linux/kobject.h> |
| 16 | #include <linux/klist.h> | 16 | #include <linux/klist.h> |
| 17 | #include <linux/list.h> | 17 | #include <linux/list.h> |
| 18 | #include <linux/compiler.h> | ||
| 18 | #include <linux/types.h> | 19 | #include <linux/types.h> |
| 19 | #include <linux/module.h> | 20 | #include <linux/module.h> |
| 20 | #include <linux/pm.h> | 21 | #include <linux/pm.h> |
| @@ -51,14 +52,17 @@ struct bus_type { | |||
| 51 | int (*probe)(struct device * dev); | 52 | int (*probe)(struct device * dev); |
| 52 | int (*remove)(struct device * dev); | 53 | int (*remove)(struct device * dev); |
| 53 | void (*shutdown)(struct device * dev); | 54 | void (*shutdown)(struct device * dev); |
| 54 | int (*suspend)(struct device * dev, pm_message_t state); | 55 | |
| 55 | int (*resume)(struct device * dev); | 56 | int (*suspend)(struct device * dev, pm_message_t state); |
| 57 | int (*suspend_late)(struct device * dev, pm_message_t state); | ||
| 58 | int (*resume_early)(struct device * dev); | ||
| 59 | int (*resume)(struct device * dev); | ||
| 56 | }; | 60 | }; |
| 57 | 61 | ||
| 58 | extern int bus_register(struct bus_type * bus); | 62 | extern int __must_check bus_register(struct bus_type * bus); |
| 59 | extern void bus_unregister(struct bus_type * bus); | 63 | extern void bus_unregister(struct bus_type * bus); |
| 60 | 64 | ||
| 61 | extern void bus_rescan_devices(struct bus_type * bus); | 65 | extern int __must_check bus_rescan_devices(struct bus_type * bus); |
| 62 | 66 | ||
| 63 | /* iterator helpers for buses */ | 67 | /* iterator helpers for buses */ |
| 64 | 68 | ||
| @@ -67,9 +71,9 @@ int bus_for_each_dev(struct bus_type * bus, struct device * start, void * data, | |||
| 67 | struct device * bus_find_device(struct bus_type *bus, struct device *start, | 71 | struct device * bus_find_device(struct bus_type *bus, struct device *start, |
| 68 | void *data, int (*match)(struct device *, void *)); | 72 | void *data, int (*match)(struct device *, void *)); |
| 69 | 73 | ||
| 70 | int bus_for_each_drv(struct bus_type * bus, struct device_driver * start, | 74 | int __must_check bus_for_each_drv(struct bus_type *bus, |
| 71 | void * data, int (*fn)(struct device_driver *, void *)); | 75 | struct device_driver *start, void *data, |
| 72 | 76 | int (*fn)(struct device_driver *, void *)); | |
| 73 | 77 | ||
| 74 | /* driverfs interface for exporting bus attributes */ | 78 | /* driverfs interface for exporting bus attributes */ |
| 75 | 79 | ||
| @@ -82,7 +86,8 @@ struct bus_attribute { | |||
| 82 | #define BUS_ATTR(_name,_mode,_show,_store) \ | 86 | #define BUS_ATTR(_name,_mode,_show,_store) \ |
| 83 | struct bus_attribute bus_attr_##_name = __ATTR(_name,_mode,_show,_store) | 87 | struct bus_attribute bus_attr_##_name = __ATTR(_name,_mode,_show,_store) |
| 84 | 88 | ||
| 85 | extern int bus_create_file(struct bus_type *, struct bus_attribute *); | 89 | extern int __must_check bus_create_file(struct bus_type *, |
| 90 | struct bus_attribute *); | ||
| 86 | extern void bus_remove_file(struct bus_type *, struct bus_attribute *); | 91 | extern void bus_remove_file(struct bus_type *, struct bus_attribute *); |
| 87 | 92 | ||
| 88 | struct device_driver { | 93 | struct device_driver { |
| @@ -101,16 +106,18 @@ struct device_driver { | |||
| 101 | void (*shutdown) (struct device * dev); | 106 | void (*shutdown) (struct device * dev); |
| 102 | int (*suspend) (struct device * dev, pm_message_t state); | 107 | int (*suspend) (struct device * dev, pm_message_t state); |
| 103 | int (*resume) (struct device * dev); | 108 | int (*resume) (struct device * dev); |
| 109 | |||
| 110 | unsigned int multithread_probe:1; | ||
| 104 | }; | 111 | }; |
| 105 | 112 | ||
| 106 | 113 | ||
| 107 | extern int driver_register(struct device_driver * drv); | 114 | extern int __must_check driver_register(struct device_driver * drv); |
| 108 | extern void driver_unregister(struct device_driver * drv); | 115 | extern void driver_unregister(struct device_driver * drv); |
| 109 | 116 | ||
| 110 | extern struct device_driver * get_driver(struct device_driver * drv); | 117 | extern struct device_driver * get_driver(struct device_driver * drv); |
| 111 | extern void put_driver(struct device_driver * drv); | 118 | extern void put_driver(struct device_driver * drv); |
| 112 | extern struct device_driver *driver_find(const char *name, struct bus_type *bus); | 119 | extern struct device_driver *driver_find(const char *name, struct bus_type *bus); |
| 113 | 120 | extern int driver_probe_done(void); | |
| 114 | 121 | ||
| 115 | /* driverfs interface for exporting driver attributes */ | 122 | /* driverfs interface for exporting driver attributes */ |
| 116 | 123 | ||
| @@ -123,16 +130,17 @@ struct driver_attribute { | |||
| 123 | #define DRIVER_ATTR(_name,_mode,_show,_store) \ | 130 | #define DRIVER_ATTR(_name,_mode,_show,_store) \ |
| 124 | struct driver_attribute driver_attr_##_name = __ATTR(_name,_mode,_show,_store) | 131 | struct driver_attribute driver_attr_##_name = __ATTR(_name,_mode,_show,_store) |
| 125 | 132 | ||
| 126 | extern int driver_create_file(struct device_driver *, struct driver_attribute *); | 133 | extern int __must_check driver_create_file(struct device_driver *, |
| 134 | struct driver_attribute *); | ||
| 127 | extern void driver_remove_file(struct device_driver *, struct driver_attribute *); | 135 | extern void driver_remove_file(struct device_driver *, struct driver_attribute *); |
| 128 | 136 | ||
| 129 | extern int driver_for_each_device(struct device_driver * drv, struct device * start, | 137 | extern int __must_check driver_for_each_device(struct device_driver * drv, |
| 130 | void * data, int (*fn)(struct device *, void *)); | 138 | struct device *start, void *data, |
| 139 | int (*fn)(struct device *, void *)); | ||
| 131 | struct device * driver_find_device(struct device_driver *drv, | 140 | struct device * driver_find_device(struct device_driver *drv, |
| 132 | struct device *start, void *data, | 141 | struct device *start, void *data, |
| 133 | int (*match)(struct device *, void *)); | 142 | int (*match)(struct device *, void *)); |
| 134 | 143 | ||
| 135 | |||
| 136 | /* | 144 | /* |
| 137 | * device classes | 145 | * device classes |
| 138 | */ | 146 | */ |
| @@ -146,17 +154,26 @@ struct class { | |||
| 146 | struct list_head interfaces; | 154 | struct list_head interfaces; |
| 147 | struct semaphore sem; /* locks both the children and interfaces lists */ | 155 | struct semaphore sem; /* locks both the children and interfaces lists */ |
| 148 | 156 | ||
| 157 | struct kobject *virtual_dir; | ||
| 158 | |||
| 149 | struct class_attribute * class_attrs; | 159 | struct class_attribute * class_attrs; |
| 150 | struct class_device_attribute * class_dev_attrs; | 160 | struct class_device_attribute * class_dev_attrs; |
| 161 | struct device_attribute * dev_attrs; | ||
| 151 | 162 | ||
| 152 | int (*uevent)(struct class_device *dev, char **envp, | 163 | int (*uevent)(struct class_device *dev, char **envp, |
| 153 | int num_envp, char *buffer, int buffer_size); | 164 | int num_envp, char *buffer, int buffer_size); |
| 165 | int (*dev_uevent)(struct device *dev, char **envp, int num_envp, | ||
| 166 | char *buffer, int buffer_size); | ||
| 154 | 167 | ||
| 155 | void (*release)(struct class_device *dev); | 168 | void (*release)(struct class_device *dev); |
| 156 | void (*class_release)(struct class *class); | 169 | void (*class_release)(struct class *class); |
| 170 | void (*dev_release)(struct device *dev); | ||
| 171 | |||
| 172 | int (*suspend)(struct device *, pm_message_t state); | ||
| 173 | int (*resume)(struct device *); | ||
| 157 | }; | 174 | }; |
| 158 | 175 | ||
| 159 | extern int class_register(struct class *); | 176 | extern int __must_check class_register(struct class *); |
| 160 | extern void class_unregister(struct class *); | 177 | extern void class_unregister(struct class *); |
| 161 | 178 | ||
| 162 | 179 | ||
| @@ -169,7 +186,8 @@ struct class_attribute { | |||
| 169 | #define CLASS_ATTR(_name,_mode,_show,_store) \ | 186 | #define CLASS_ATTR(_name,_mode,_show,_store) \ |
| 170 | struct class_attribute class_attr_##_name = __ATTR(_name,_mode,_show,_store) | 187 | struct class_attribute class_attr_##_name = __ATTR(_name,_mode,_show,_store) |
| 171 | 188 | ||
| 172 | extern int class_create_file(struct class *, const struct class_attribute *); | 189 | extern int __must_check class_create_file(struct class *, |
| 190 | const struct class_attribute *); | ||
| 173 | extern void class_remove_file(struct class *, const struct class_attribute *); | 191 | extern void class_remove_file(struct class *, const struct class_attribute *); |
| 174 | 192 | ||
| 175 | struct class_device_attribute { | 193 | struct class_device_attribute { |
| @@ -182,7 +200,7 @@ struct class_device_attribute { | |||
| 182 | struct class_device_attribute class_device_attr_##_name = \ | 200 | struct class_device_attribute class_device_attr_##_name = \ |
| 183 | __ATTR(_name,_mode,_show,_store) | 201 | __ATTR(_name,_mode,_show,_store) |
| 184 | 202 | ||
| 185 | extern int class_device_create_file(struct class_device *, | 203 | extern int __must_check class_device_create_file(struct class_device *, |
| 186 | const struct class_device_attribute *); | 204 | const struct class_device_attribute *); |
| 187 | 205 | ||
| 188 | /** | 206 | /** |
| @@ -242,10 +260,10 @@ class_set_devdata (struct class_device *dev, void *data) | |||
| 242 | } | 260 | } |
| 243 | 261 | ||
| 244 | 262 | ||
| 245 | extern int class_device_register(struct class_device *); | 263 | extern int __must_check class_device_register(struct class_device *); |
| 246 | extern void class_device_unregister(struct class_device *); | 264 | extern void class_device_unregister(struct class_device *); |
| 247 | extern void class_device_initialize(struct class_device *); | 265 | extern void class_device_initialize(struct class_device *); |
| 248 | extern int class_device_add(struct class_device *); | 266 | extern int __must_check class_device_add(struct class_device *); |
| 249 | extern void class_device_del(struct class_device *); | 267 | extern void class_device_del(struct class_device *); |
| 250 | 268 | ||
| 251 | extern int class_device_rename(struct class_device *, char *); | 269 | extern int class_device_rename(struct class_device *, char *); |
| @@ -255,7 +273,7 @@ extern void class_device_put(struct class_device *); | |||
| 255 | 273 | ||
| 256 | extern void class_device_remove_file(struct class_device *, | 274 | extern void class_device_remove_file(struct class_device *, |
| 257 | const struct class_device_attribute *); | 275 | const struct class_device_attribute *); |
| 258 | extern int class_device_create_bin_file(struct class_device *, | 276 | extern int __must_check class_device_create_bin_file(struct class_device *, |
| 259 | struct bin_attribute *); | 277 | struct bin_attribute *); |
| 260 | extern void class_device_remove_bin_file(struct class_device *, | 278 | extern void class_device_remove_bin_file(struct class_device *, |
| 261 | struct bin_attribute *); | 279 | struct bin_attribute *); |
| @@ -266,22 +284,23 @@ struct class_interface { | |||
| 266 | 284 | ||
| 267 | int (*add) (struct class_device *, struct class_interface *); | 285 | int (*add) (struct class_device *, struct class_interface *); |
| 268 | void (*remove) (struct class_device *, struct class_interface *); | 286 | void (*remove) (struct class_device *, struct class_interface *); |
| 287 | int (*add_dev) (struct device *, struct class_interface *); | ||
| 288 | void (*remove_dev) (struct device *, struct class_interface *); | ||
| 269 | }; | 289 | }; |
| 270 | 290 | ||
| 271 | extern int class_interface_register(struct class_interface *); | 291 | extern int __must_check class_interface_register(struct class_interface *); |
| 272 | extern void class_interface_unregister(struct class_interface *); | 292 | extern void class_interface_unregister(struct class_interface *); |
| 273 | 293 | ||
| 274 | extern struct class *class_create(struct module *owner, char *name); | 294 | extern struct class *class_create(struct module *owner, const char *name); |
| 275 | extern void class_destroy(struct class *cls); | 295 | extern void class_destroy(struct class *cls); |
| 276 | extern struct class_device *class_device_create(struct class *cls, | 296 | extern struct class_device *class_device_create(struct class *cls, |
| 277 | struct class_device *parent, | 297 | struct class_device *parent, |
| 278 | dev_t devt, | 298 | dev_t devt, |
| 279 | struct device *device, | 299 | struct device *device, |
| 280 | char *fmt, ...) | 300 | const char *fmt, ...) |
| 281 | __attribute__((format(printf,5,6))); | 301 | __attribute__((format(printf,5,6))); |
| 282 | extern void class_device_destroy(struct class *cls, dev_t devt); | 302 | extern void class_device_destroy(struct class *cls, dev_t devt); |
| 283 | 303 | ||
| 284 | |||
| 285 | /* interface for exporting device attributes */ | 304 | /* interface for exporting device attributes */ |
| 286 | struct device_attribute { | 305 | struct device_attribute { |
| 287 | struct attribute attr; | 306 | struct attribute attr; |
| @@ -294,8 +313,13 @@ struct device_attribute { | |||
| 294 | #define DEVICE_ATTR(_name,_mode,_show,_store) \ | 313 | #define DEVICE_ATTR(_name,_mode,_show,_store) \ |
| 295 | struct device_attribute dev_attr_##_name = __ATTR(_name,_mode,_show,_store) | 314 | struct device_attribute dev_attr_##_name = __ATTR(_name,_mode,_show,_store) |
| 296 | 315 | ||
| 297 | extern int device_create_file(struct device *device, struct device_attribute * entry); | 316 | extern int __must_check device_create_file(struct device *device, |
| 317 | struct device_attribute * entry); | ||
| 298 | extern void device_remove_file(struct device * dev, struct device_attribute * attr); | 318 | extern void device_remove_file(struct device * dev, struct device_attribute * attr); |
| 319 | extern int __must_check device_create_bin_file(struct device *dev, | ||
| 320 | struct bin_attribute *attr); | ||
| 321 | extern void device_remove_bin_file(struct device *dev, | ||
| 322 | struct bin_attribute *attr); | ||
| 299 | struct device { | 323 | struct device { |
| 300 | struct klist klist_children; | 324 | struct klist klist_children; |
| 301 | struct klist_node knode_parent; /* node in sibling list */ | 325 | struct klist_node knode_parent; /* node in sibling list */ |
| @@ -305,6 +329,7 @@ struct device { | |||
| 305 | 329 | ||
| 306 | struct kobject kobj; | 330 | struct kobject kobj; |
| 307 | char bus_id[BUS_ID_SIZE]; /* position on parent bus */ | 331 | char bus_id[BUS_ID_SIZE]; /* position on parent bus */ |
| 332 | unsigned is_registered:1; | ||
| 308 | struct device_attribute uevent_attr; | 333 | struct device_attribute uevent_attr; |
| 309 | struct device_attribute *devt_attr; | 334 | struct device_attribute *devt_attr; |
| 310 | 335 | ||
| @@ -338,6 +363,7 @@ struct device { | |||
| 338 | struct list_head node; | 363 | struct list_head node; |
| 339 | struct class *class; /* optional*/ | 364 | struct class *class; /* optional*/ |
| 340 | dev_t devt; /* dev_t, creates the sysfs "dev" */ | 365 | dev_t devt; /* dev_t, creates the sysfs "dev" */ |
| 366 | struct attribute_group **groups; /* optional groups */ | ||
| 341 | 367 | ||
| 342 | void (*release)(struct device * dev); | 368 | void (*release)(struct device * dev); |
| 343 | }; | 369 | }; |
| @@ -356,38 +382,41 @@ dev_set_drvdata (struct device *dev, void *data) | |||
| 356 | 382 | ||
| 357 | static inline int device_is_registered(struct device *dev) | 383 | static inline int device_is_registered(struct device *dev) |
| 358 | { | 384 | { |
| 359 | return klist_node_attached(&dev->knode_bus); | 385 | return dev->is_registered; |
| 360 | } | 386 | } |
| 361 | 387 | ||
| 362 | /* | 388 | /* |
| 363 | * High level routines for use by the bus drivers | 389 | * High level routines for use by the bus drivers |
| 364 | */ | 390 | */ |
| 365 | extern int device_register(struct device * dev); | 391 | extern int __must_check device_register(struct device * dev); |
| 366 | extern void device_unregister(struct device * dev); | 392 | extern void device_unregister(struct device * dev); |
| 367 | extern void device_initialize(struct device * dev); | 393 | extern void device_initialize(struct device * dev); |
| 368 | extern int device_add(struct device * dev); | 394 | extern int __must_check device_add(struct device * dev); |
| 369 | extern void device_del(struct device * dev); | 395 | extern void device_del(struct device * dev); |
| 370 | extern int device_for_each_child(struct device *, void *, | 396 | extern int __must_check device_for_each_child(struct device *, void *, |
| 371 | int (*fn)(struct device *, void *)); | 397 | int (*fn)(struct device *, void *)); |
| 398 | extern int device_rename(struct device *dev, char *new_name); | ||
| 372 | 399 | ||
| 373 | /* | 400 | /* |
| 374 | * Manual binding of a device to driver. See drivers/base/bus.c | 401 | * Manual binding of a device to driver. See drivers/base/bus.c |
| 375 | * for information on use. | 402 | * for information on use. |
| 376 | */ | 403 | */ |
| 377 | extern void device_bind_driver(struct device * dev); | 404 | extern int __must_check device_bind_driver(struct device *dev); |
| 378 | extern void device_release_driver(struct device * dev); | 405 | extern void device_release_driver(struct device * dev); |
| 379 | extern int device_attach(struct device * dev); | 406 | extern int __must_check device_attach(struct device * dev); |
| 380 | extern void driver_attach(struct device_driver * drv); | 407 | extern int __must_check driver_attach(struct device_driver *drv); |
| 381 | extern void device_reprobe(struct device *dev); | 408 | extern int __must_check device_reprobe(struct device *dev); |
| 382 | 409 | ||
| 383 | /* | 410 | /* |
| 384 | * Easy functions for dynamically creating devices on the fly | 411 | * Easy functions for dynamically creating devices on the fly |
| 385 | */ | 412 | */ |
| 386 | extern struct device *device_create(struct class *cls, struct device *parent, | 413 | extern struct device *device_create(struct class *cls, struct device *parent, |
| 387 | dev_t devt, char *fmt, ...) | 414 | dev_t devt, const char *fmt, ...) |
| 388 | __attribute__((format(printf,4,5))); | 415 | __attribute__((format(printf,4,5))); |
| 389 | extern void device_destroy(struct class *cls, dev_t devt); | 416 | extern void device_destroy(struct class *cls, dev_t devt); |
| 390 | 417 | ||
| 418 | extern int virtual_device_parent(struct device *dev); | ||
| 419 | |||
| 391 | /* | 420 | /* |
| 392 | * Platform "fixup" functions - allow the platform to have their say | 421 | * Platform "fixup" functions - allow the platform to have their say |
| 393 | * about devices and actions that the general device layer doesn't | 422 | * about devices and actions that the general device layer doesn't |
| @@ -412,7 +441,7 @@ extern void device_shutdown(void); | |||
| 412 | 441 | ||
| 413 | 442 | ||
| 414 | /* drivers/base/firmware.c */ | 443 | /* drivers/base/firmware.c */ |
| 415 | extern int firmware_register(struct subsystem *); | 444 | extern int __must_check firmware_register(struct subsystem *); |
| 416 | extern void firmware_unregister(struct subsystem *); | 445 | extern void firmware_unregister(struct subsystem *); |
| 417 | 446 | ||
| 418 | /* debugging and troubleshooting/diagnostic helpers. */ | 447 | /* debugging and troubleshooting/diagnostic helpers. */ |
