diff options
Diffstat (limited to 'include/linux/device.h')
-rw-r--r-- | include/linux/device.h | 71 |
1 files changed, 40 insertions, 31 deletions
diff --git a/include/linux/device.h b/include/linux/device.h index de2d6fe349de..06e5d42f2c7b 100644 --- a/include/linux/device.h +++ b/include/linux/device.h | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/config.h> | 14 | #include <linux/config.h> |
15 | #include <linux/ioport.h> | 15 | #include <linux/ioport.h> |
16 | #include <linux/kobject.h> | 16 | #include <linux/kobject.h> |
17 | #include <linux/klist.h> | ||
17 | #include <linux/list.h> | 18 | #include <linux/list.h> |
18 | #include <linux/types.h> | 19 | #include <linux/types.h> |
19 | #include <linux/module.h> | 20 | #include <linux/module.h> |
@@ -44,14 +45,15 @@ struct device; | |||
44 | struct device_driver; | 45 | struct device_driver; |
45 | struct class; | 46 | struct class; |
46 | struct class_device; | 47 | struct class_device; |
47 | struct class_simple; | ||
48 | 48 | ||
49 | struct bus_type { | 49 | struct bus_type { |
50 | char * name; | 50 | const char * name; |
51 | 51 | ||
52 | struct subsystem subsys; | 52 | struct subsystem subsys; |
53 | struct kset drivers; | 53 | struct kset drivers; |
54 | struct kset devices; | 54 | struct kset devices; |
55 | struct klist klist_devices; | ||
56 | struct klist klist_drivers; | ||
55 | 57 | ||
56 | struct bus_attribute * bus_attrs; | 58 | struct bus_attribute * bus_attrs; |
57 | struct device_attribute * dev_attrs; | 59 | struct device_attribute * dev_attrs; |
@@ -67,7 +69,7 @@ struct bus_type { | |||
67 | extern int bus_register(struct bus_type * bus); | 69 | extern int bus_register(struct bus_type * bus); |
68 | extern void bus_unregister(struct bus_type * bus); | 70 | extern void bus_unregister(struct bus_type * bus); |
69 | 71 | ||
70 | extern int bus_rescan_devices(struct bus_type * bus); | 72 | extern void bus_rescan_devices(struct bus_type * bus); |
71 | 73 | ||
72 | extern struct bus_type * get_bus(struct bus_type * bus); | 74 | extern struct bus_type * get_bus(struct bus_type * bus); |
73 | extern void put_bus(struct bus_type * bus); | 75 | extern void put_bus(struct bus_type * bus); |
@@ -78,6 +80,8 @@ extern struct bus_type * find_bus(char * name); | |||
78 | 80 | ||
79 | int bus_for_each_dev(struct bus_type * bus, struct device * start, void * data, | 81 | int bus_for_each_dev(struct bus_type * bus, struct device * start, void * data, |
80 | int (*fn)(struct device *, void *)); | 82 | int (*fn)(struct device *, void *)); |
83 | struct device * bus_find_device(struct bus_type *bus, struct device *start, | ||
84 | void *data, int (*match)(struct device *, void *)); | ||
81 | 85 | ||
82 | int bus_for_each_drv(struct bus_type * bus, struct device_driver * start, | 86 | int bus_for_each_drv(struct bus_type * bus, struct device_driver * start, |
83 | void * data, int (*fn)(struct device_driver *, void *)); | 87 | void * data, int (*fn)(struct device_driver *, void *)); |
@@ -98,17 +102,18 @@ extern int bus_create_file(struct bus_type *, struct bus_attribute *); | |||
98 | extern void bus_remove_file(struct bus_type *, struct bus_attribute *); | 102 | extern void bus_remove_file(struct bus_type *, struct bus_attribute *); |
99 | 103 | ||
100 | struct device_driver { | 104 | struct device_driver { |
101 | char * name; | 105 | const char * name; |
102 | struct bus_type * bus; | 106 | struct bus_type * bus; |
103 | 107 | ||
104 | struct completion unloaded; | 108 | struct completion unloaded; |
105 | struct kobject kobj; | 109 | struct kobject kobj; |
106 | struct list_head devices; | 110 | struct klist klist_devices; |
111 | struct klist_node knode_bus; | ||
107 | 112 | ||
108 | struct module * owner; | 113 | struct module * owner; |
109 | 114 | ||
110 | int (*probe) (struct device * dev); | 115 | int (*probe) (struct device * dev); |
111 | int (*remove) (struct device * dev); | 116 | int (*remove) (struct device * dev); |
112 | void (*shutdown) (struct device * dev); | 117 | void (*shutdown) (struct device * dev); |
113 | int (*suspend) (struct device * dev, pm_message_t state, u32 level); | 118 | int (*suspend) (struct device * dev, pm_message_t state, u32 level); |
114 | int (*resume) (struct device * dev, u32 level); | 119 | int (*resume) (struct device * dev, u32 level); |
@@ -137,12 +142,19 @@ struct driver_attribute driver_attr_##_name = __ATTR(_name,_mode,_show,_store) | |||
137 | extern int driver_create_file(struct device_driver *, struct driver_attribute *); | 142 | extern int driver_create_file(struct device_driver *, struct driver_attribute *); |
138 | extern void driver_remove_file(struct device_driver *, struct driver_attribute *); | 143 | extern void driver_remove_file(struct device_driver *, struct driver_attribute *); |
139 | 144 | ||
145 | extern int driver_for_each_device(struct device_driver * drv, struct device * start, | ||
146 | void * data, int (*fn)(struct device *, void *)); | ||
147 | struct device * driver_find_device(struct device_driver *drv, | ||
148 | struct device *start, void *data, | ||
149 | int (*match)(struct device *, void *)); | ||
150 | |||
140 | 151 | ||
141 | /* | 152 | /* |
142 | * device classes | 153 | * device classes |
143 | */ | 154 | */ |
144 | struct class { | 155 | struct class { |
145 | char * name; | 156 | const char * name; |
157 | struct module * owner; | ||
146 | 158 | ||
147 | struct subsystem subsys; | 159 | struct subsystem subsys; |
148 | struct list_head children; | 160 | struct list_head children; |
@@ -185,6 +197,7 @@ struct class_device { | |||
185 | struct kobject kobj; | 197 | struct kobject kobj; |
186 | struct class * class; /* required */ | 198 | struct class * class; /* required */ |
187 | dev_t devt; /* dev_t, creates the sysfs "dev" */ | 199 | dev_t devt; /* dev_t, creates the sysfs "dev" */ |
200 | struct class_device_attribute *devt_attr; | ||
188 | struct device * dev; /* not necessary, but nice to have */ | 201 | struct device * dev; /* not necessary, but nice to have */ |
189 | void * class_data; /* class-specific data */ | 202 | void * class_data; /* class-specific data */ |
190 | 203 | ||
@@ -245,26 +258,28 @@ struct class_interface { | |||
245 | extern int class_interface_register(struct class_interface *); | 258 | extern int class_interface_register(struct class_interface *); |
246 | extern void class_interface_unregister(struct class_interface *); | 259 | extern void class_interface_unregister(struct class_interface *); |
247 | 260 | ||
248 | /* interface for class simple stuff */ | 261 | extern struct class *class_create(struct module *owner, char *name); |
249 | extern struct class_simple *class_simple_create(struct module *owner, char *name); | 262 | extern void class_destroy(struct class *cls); |
250 | extern void class_simple_destroy(struct class_simple *cs); | 263 | extern struct class_device *class_device_create(struct class *cls, dev_t devt, |
251 | extern struct class_device *class_simple_device_add(struct class_simple *cs, dev_t dev, struct device *device, const char *fmt, ...) | 264 | struct device *device, char *fmt, ...) |
252 | __attribute__((format(printf,4,5))); | 265 | __attribute__((format(printf,4,5))); |
253 | extern int class_simple_set_hotplug(struct class_simple *, | 266 | extern void class_device_destroy(struct class *cls, dev_t devt); |
254 | int (*hotplug)(struct class_device *dev, char **envp, int num_envp, char *buffer, int buffer_size)); | ||
255 | extern void class_simple_device_remove(dev_t dev); | ||
256 | 267 | ||
257 | 268 | ||
258 | struct device { | 269 | struct device { |
259 | struct list_head node; /* node in sibling list */ | 270 | struct klist klist_children; |
260 | struct list_head bus_list; /* node in bus's list */ | 271 | struct klist_node knode_parent; /* node in sibling list */ |
261 | struct list_head driver_list; | 272 | struct klist_node knode_driver; |
262 | struct list_head children; | 273 | struct klist_node knode_bus; |
263 | struct device * parent; | 274 | struct device * parent; |
264 | 275 | ||
265 | struct kobject kobj; | 276 | struct kobject kobj; |
266 | char bus_id[BUS_ID_SIZE]; /* position on parent bus */ | 277 | char bus_id[BUS_ID_SIZE]; /* position on parent bus */ |
267 | 278 | ||
279 | struct semaphore sem; /* semaphore to synchronize calls to | ||
280 | * its driver. | ||
281 | */ | ||
282 | |||
268 | struct bus_type * bus; /* type of bus device is on */ | 283 | struct bus_type * bus; /* type of bus device is on */ |
269 | struct device_driver *driver; /* which driver has allocated this | 284 | struct device_driver *driver; /* which driver has allocated this |
270 | device */ | 285 | device */ |
@@ -290,12 +305,6 @@ struct device { | |||
290 | void (*release)(struct device * dev); | 305 | void (*release)(struct device * dev); |
291 | }; | 306 | }; |
292 | 307 | ||
293 | static inline struct device * | ||
294 | list_to_dev(struct list_head *node) | ||
295 | { | ||
296 | return list_entry(node, struct device, node); | ||
297 | } | ||
298 | |||
299 | static inline void * | 308 | static inline void * |
300 | dev_get_drvdata (struct device *dev) | 309 | dev_get_drvdata (struct device *dev) |
301 | { | 310 | { |
@@ -323,7 +332,6 @@ extern int device_for_each_child(struct device *, void *, | |||
323 | * Manual binding of a device to driver. See drivers/base/bus.c | 332 | * Manual binding of a device to driver. See drivers/base/bus.c |
324 | * for information on use. | 333 | * for information on use. |
325 | */ | 334 | */ |
326 | extern int driver_probe_device(struct device_driver * drv, struct device * dev); | ||
327 | extern void device_bind_driver(struct device * dev); | 335 | extern void device_bind_driver(struct device * dev); |
328 | extern void device_release_driver(struct device * dev); | 336 | extern void device_release_driver(struct device * dev); |
329 | extern int device_attach(struct device * dev); | 337 | extern int device_attach(struct device * dev); |
@@ -334,8 +342,10 @@ extern void driver_attach(struct device_driver * drv); | |||
334 | 342 | ||
335 | struct device_attribute { | 343 | struct device_attribute { |
336 | struct attribute attr; | 344 | struct attribute attr; |
337 | ssize_t (*show)(struct device * dev, char * buf); | 345 | ssize_t (*show)(struct device *dev, struct device_attribute *attr, |
338 | ssize_t (*store)(struct device * dev, const char * buf, size_t count); | 346 | char *buf); |
347 | ssize_t (*store)(struct device *dev, struct device_attribute *attr, | ||
348 | const char *buf, size_t count); | ||
339 | }; | 349 | }; |
340 | 350 | ||
341 | #define DEVICE_ATTR(_name,_mode,_show,_store) \ | 351 | #define DEVICE_ATTR(_name,_mode,_show,_store) \ |
@@ -362,13 +372,12 @@ extern int (*platform_notify_remove)(struct device * dev); | |||
362 | */ | 372 | */ |
363 | extern struct device * get_device(struct device * dev); | 373 | extern struct device * get_device(struct device * dev); |
364 | extern void put_device(struct device * dev); | 374 | extern void put_device(struct device * dev); |
365 | extern struct device *device_find(const char *name, struct bus_type *bus); | ||
366 | 375 | ||
367 | 376 | ||
368 | /* drivers/base/platform.c */ | 377 | /* drivers/base/platform.c */ |
369 | 378 | ||
370 | struct platform_device { | 379 | struct platform_device { |
371 | char * name; | 380 | const char * name; |
372 | u32 id; | 381 | u32 id; |
373 | struct device dev; | 382 | struct device dev; |
374 | u32 num_resources; | 383 | u32 num_resources; |