aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/device.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/device.h')
-rw-r--r--include/linux/device.h71
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;
44struct device_driver; 45struct device_driver;
45struct class; 46struct class;
46struct class_device; 47struct class_device;
47struct class_simple;
48 48
49struct bus_type { 49struct 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 {
67extern int bus_register(struct bus_type * bus); 69extern int bus_register(struct bus_type * bus);
68extern void bus_unregister(struct bus_type * bus); 70extern void bus_unregister(struct bus_type * bus);
69 71
70extern int bus_rescan_devices(struct bus_type * bus); 72extern void bus_rescan_devices(struct bus_type * bus);
71 73
72extern struct bus_type * get_bus(struct bus_type * bus); 74extern struct bus_type * get_bus(struct bus_type * bus);
73extern void put_bus(struct bus_type * bus); 75extern void put_bus(struct bus_type * bus);
@@ -78,6 +80,8 @@ extern struct bus_type * find_bus(char * name);
78 80
79int bus_for_each_dev(struct bus_type * bus, struct device * start, void * data, 81int 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 *));
83struct device * bus_find_device(struct bus_type *bus, struct device *start,
84 void *data, int (*match)(struct device *, void *));
81 85
82int bus_for_each_drv(struct bus_type * bus, struct device_driver * start, 86int 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 *);
98extern void bus_remove_file(struct bus_type *, struct bus_attribute *); 102extern void bus_remove_file(struct bus_type *, struct bus_attribute *);
99 103
100struct device_driver { 104struct 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)
137extern int driver_create_file(struct device_driver *, struct driver_attribute *); 142extern int driver_create_file(struct device_driver *, struct driver_attribute *);
138extern void driver_remove_file(struct device_driver *, struct driver_attribute *); 143extern void driver_remove_file(struct device_driver *, struct driver_attribute *);
139 144
145extern int driver_for_each_device(struct device_driver * drv, struct device * start,
146 void * data, int (*fn)(struct device *, void *));
147struct 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 */
144struct class { 155struct 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 {
245extern int class_interface_register(struct class_interface *); 258extern int class_interface_register(struct class_interface *);
246extern void class_interface_unregister(struct class_interface *); 259extern void class_interface_unregister(struct class_interface *);
247 260
248/* interface for class simple stuff */ 261extern struct class *class_create(struct module *owner, char *name);
249extern struct class_simple *class_simple_create(struct module *owner, char *name); 262extern void class_destroy(struct class *cls);
250extern void class_simple_destroy(struct class_simple *cs); 263extern struct class_device *class_device_create(struct class *cls, dev_t devt,
251extern 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)));
253extern int class_simple_set_hotplug(struct class_simple *, 266extern 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));
255extern void class_simple_device_remove(dev_t dev);
256 267
257 268
258struct device { 269struct 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
293static inline struct device *
294list_to_dev(struct list_head *node)
295{
296 return list_entry(node, struct device, node);
297}
298
299static inline void * 308static inline void *
300dev_get_drvdata (struct device *dev) 309dev_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 */
326extern int driver_probe_device(struct device_driver * drv, struct device * dev);
327extern void device_bind_driver(struct device * dev); 335extern void device_bind_driver(struct device * dev);
328extern void device_release_driver(struct device * dev); 336extern void device_release_driver(struct device * dev);
329extern int device_attach(struct device * dev); 337extern int device_attach(struct device * dev);
@@ -334,8 +342,10 @@ extern void driver_attach(struct device_driver * drv);
334 342
335struct device_attribute { 343struct 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 */
363extern struct device * get_device(struct device * dev); 373extern struct device * get_device(struct device * dev);
364extern void put_device(struct device * dev); 374extern void put_device(struct device * dev);
365extern 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
370struct platform_device { 379struct 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;