[PATCH] add sysfs attr to re-emit device hotplug event
[deliverable/linux.git] / include / linux / device.h
CommitLineData
1da177e4
LT
1/*
2 * device.h - generic, centralized driver model
3 *
4 * Copyright (c) 2001-2003 Patrick Mochel <mochel@osdl.org>
5 *
6 * This file is released under the GPLv2
7 *
8 * See Documentation/driver-model/ for more information.
9 */
10
11#ifndef _DEVICE_H_
12#define _DEVICE_H_
13
14#include <linux/config.h>
15#include <linux/ioport.h>
16#include <linux/kobject.h>
465c7a3a 17#include <linux/klist.h>
1da177e4
LT
18#include <linux/list.h>
19#include <linux/types.h>
20#include <linux/module.h>
21#include <linux/pm.h>
22#include <asm/semaphore.h>
23#include <asm/atomic.h>
24
25#define DEVICE_NAME_SIZE 50
26#define DEVICE_NAME_HALF __stringify(20) /* Less than half to accommodate slop */
27#define DEVICE_ID_SIZE 32
28#define BUS_ID_SIZE KOBJ_NAME_LEN
29
30
31enum {
32 SUSPEND_NOTIFY,
33 SUSPEND_SAVE_STATE,
34 SUSPEND_DISABLE,
35 SUSPEND_POWER_DOWN,
36};
37
38enum {
39 RESUME_POWER_ON,
40 RESUME_RESTORE_STATE,
41 RESUME_ENABLE,
42};
43
44struct device;
45struct device_driver;
46struct class;
47struct class_device;
1da177e4
LT
48
49struct bus_type {
8d790d74 50 const char * name;
1da177e4
LT
51
52 struct subsystem subsys;
53 struct kset drivers;
54 struct kset devices;
465c7a3a 55 struct klist klist_devices;
38fdac3c 56 struct klist klist_drivers;
1da177e4
LT
57
58 struct bus_attribute * bus_attrs;
59 struct device_attribute * dev_attrs;
60 struct driver_attribute * drv_attrs;
61
62 int (*match)(struct device * dev, struct device_driver * drv);
63 int (*hotplug) (struct device *dev, char **envp,
64 int num_envp, char *buffer, int buffer_size);
65 int (*suspend)(struct device * dev, pm_message_t state);
66 int (*resume)(struct device * dev);
67};
68
69extern int bus_register(struct bus_type * bus);
70extern void bus_unregister(struct bus_type * bus);
71
23d3d602 72extern void bus_rescan_devices(struct bus_type * bus);
1da177e4
LT
73
74extern struct bus_type * get_bus(struct bus_type * bus);
75extern void put_bus(struct bus_type * bus);
76
77extern struct bus_type * find_bus(char * name);
78
79/* iterator helpers for buses */
80
81int bus_for_each_dev(struct bus_type * bus, struct device * start, void * data,
82 int (*fn)(struct device *, void *));
0edb5860
CH
83struct device * bus_find_device(struct bus_type *bus, struct device *start,
84 void *data, int (*match)(struct device *, void *));
1da177e4
LT
85
86int bus_for_each_drv(struct bus_type * bus, struct device_driver * start,
87 void * data, int (*fn)(struct device_driver *, void *));
88
89
90/* driverfs interface for exporting bus attributes */
91
92struct bus_attribute {
93 struct attribute attr;
94 ssize_t (*show)(struct bus_type *, char * buf);
95 ssize_t (*store)(struct bus_type *, const char * buf, size_t count);
96};
97
98#define BUS_ATTR(_name,_mode,_show,_store) \
99struct bus_attribute bus_attr_##_name = __ATTR(_name,_mode,_show,_store)
100
101extern int bus_create_file(struct bus_type *, struct bus_attribute *);
102extern void bus_remove_file(struct bus_type *, struct bus_attribute *);
103
104struct device_driver {
8d790d74 105 const char * name;
1da177e4
LT
106 struct bus_type * bus;
107
108 struct completion unloaded;
109 struct kobject kobj;
94e7b1c5 110 struct klist klist_devices;
38fdac3c 111 struct klist_node knode_bus;
1da177e4 112
8d790d74 113 struct module * owner;
1da177e4
LT
114
115 int (*probe) (struct device * dev);
8d790d74 116 int (*remove) (struct device * dev);
1da177e4
LT
117 void (*shutdown) (struct device * dev);
118 int (*suspend) (struct device * dev, pm_message_t state, u32 level);
119 int (*resume) (struct device * dev, u32 level);
120};
121
122
123extern int driver_register(struct device_driver * drv);
124extern void driver_unregister(struct device_driver * drv);
125
126extern struct device_driver * get_driver(struct device_driver * drv);
127extern void put_driver(struct device_driver * drv);
128extern struct device_driver *driver_find(const char *name, struct bus_type *bus);
129
130
131/* driverfs interface for exporting driver attributes */
132
133struct driver_attribute {
134 struct attribute attr;
135 ssize_t (*show)(struct device_driver *, char * buf);
136 ssize_t (*store)(struct device_driver *, const char * buf, size_t count);
137};
138
139#define DRIVER_ATTR(_name,_mode,_show,_store) \
140struct driver_attribute driver_attr_##_name = __ATTR(_name,_mode,_show,_store)
141
142extern int driver_create_file(struct device_driver *, struct driver_attribute *);
143extern void driver_remove_file(struct device_driver *, struct driver_attribute *);
144
fae3cd00 145extern int driver_for_each_device(struct device_driver * drv, struct device * start,
146 void * data, int (*fn)(struct device *, void *));
0edb5860
CH
147struct device * driver_find_device(struct device_driver *drv,
148 struct device *start, void *data,
149 int (*match)(struct device *, void *));
fae3cd00 150
1da177e4
LT
151
152/*
153 * device classes
154 */
155struct class {
8d790d74 156 const char * name;
e9ba6365 157 struct module * owner;
1da177e4
LT
158
159 struct subsystem subsys;
160 struct list_head children;
161 struct list_head interfaces;
162 struct semaphore sem; /* locks both the children and interfaces lists */
163
164 struct class_attribute * class_attrs;
165 struct class_device_attribute * class_dev_attrs;
166
167 int (*hotplug)(struct class_device *dev, char **envp,
168 int num_envp, char *buffer, int buffer_size);
169
170 void (*release)(struct class_device *dev);
171 void (*class_release)(struct class *class);
172};
173
174extern int class_register(struct class *);
175extern void class_unregister(struct class *);
176
177extern struct class * class_get(struct class *);
178extern void class_put(struct class *);
179
180
181struct class_attribute {
182 struct attribute attr;
183 ssize_t (*show)(struct class *, char * buf);
184 ssize_t (*store)(struct class *, const char * buf, size_t count);
185};
186
187#define CLASS_ATTR(_name,_mode,_show,_store) \
188struct class_attribute class_attr_##_name = __ATTR(_name,_mode,_show,_store)
189
190extern int class_create_file(struct class *, const struct class_attribute *);
191extern void class_remove_file(struct class *, const struct class_attribute *);
192
a7fd6706
KS
193struct class_device_attribute {
194 struct attribute attr;
195 ssize_t (*show)(struct class_device *, char * buf);
196 ssize_t (*store)(struct class_device *, const char * buf, size_t count);
197};
198
199#define CLASS_DEVICE_ATTR(_name,_mode,_show,_store) \
200struct class_device_attribute class_device_attr_##_name = \
201 __ATTR(_name,_mode,_show,_store)
202
203extern int class_device_create_file(struct class_device *,
204 const struct class_device_attribute *);
1da177e4
LT
205
206struct class_device {
207 struct list_head node;
208
209 struct kobject kobj;
210 struct class * class; /* required */
211 dev_t devt; /* dev_t, creates the sysfs "dev" */
e9ba6365 212 struct class_device_attribute *devt_attr;
a7fd6706 213 struct class_device_attribute uevent_attr;
1da177e4
LT
214 struct device * dev; /* not necessary, but nice to have */
215 void * class_data; /* class-specific data */
216
217 char class_id[BUS_ID_SIZE]; /* unique to this class */
218};
219
220static inline void *
221class_get_devdata (struct class_device *dev)
222{
223 return dev->class_data;
224}
225
226static inline void
227class_set_devdata (struct class_device *dev, void *data)
228{
229 dev->class_data = data;
230}
231
232
233extern int class_device_register(struct class_device *);
234extern void class_device_unregister(struct class_device *);
235extern void class_device_initialize(struct class_device *);
236extern int class_device_add(struct class_device *);
237extern void class_device_del(struct class_device *);
238
239extern int class_device_rename(struct class_device *, char *);
240
241extern struct class_device * class_device_get(struct class_device *);
242extern void class_device_put(struct class_device *);
243
1da177e4
LT
244extern void class_device_remove_file(struct class_device *,
245 const struct class_device_attribute *);
246extern int class_device_create_bin_file(struct class_device *,
247 struct bin_attribute *);
248extern void class_device_remove_bin_file(struct class_device *,
249 struct bin_attribute *);
250
251struct class_interface {
252 struct list_head node;
253 struct class *class;
254
d8539d81
DT
255 int (*add) (struct class_device *, struct class_interface *);
256 void (*remove) (struct class_device *, struct class_interface *);
1da177e4
LT
257};
258
259extern int class_interface_register(struct class_interface *);
260extern void class_interface_unregister(struct class_interface *);
261
e9ba6365 262extern struct class *class_create(struct module *owner, char *name);
263extern void class_destroy(struct class *cls);
264extern struct class_device *class_device_create(struct class *cls, dev_t devt,
265 struct device *device, char *fmt, ...)
266 __attribute__((format(printf,4,5)));
267extern void class_device_destroy(struct class *cls, dev_t devt);
268
1da177e4 269
a7fd6706
KS
270/* interface for exporting device attributes */
271struct device_attribute {
272 struct attribute attr;
273 ssize_t (*show)(struct device *dev, struct device_attribute *attr,
274 char *buf);
275 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
276 const char *buf, size_t count);
277};
278
279#define DEVICE_ATTR(_name,_mode,_show,_store) \
280struct device_attribute dev_attr_##_name = __ATTR(_name,_mode,_show,_store)
281
282extern int device_create_file(struct device *device, struct device_attribute * entry);
283extern void device_remove_file(struct device * dev, struct device_attribute * attr);
1da177e4 284struct device {
36239577 285 struct klist klist_children;
286 struct klist_node knode_parent; /* node in sibling list */
94e7b1c5 287 struct klist_node knode_driver;
465c7a3a 288 struct klist_node knode_bus;
1da177e4
LT
289 struct device * parent;
290
291 struct kobject kobj;
292 char bus_id[BUS_ID_SIZE]; /* position on parent bus */
a7fd6706 293 struct device_attribute uevent_attr;
1da177e4 294
af70316a 295 struct semaphore sem; /* semaphore to synchronize calls to
296 * its driver.
297 */
298
1da177e4
LT
299 struct bus_type * bus; /* type of bus device is on */
300 struct device_driver *driver; /* which driver has allocated this
301 device */
302 void *driver_data; /* data private to the driver */
4e10d12a
DSL
303 void *platform_data; /* Platform specific data, device
304 core doesn't touch it */
305 void *firmware_data; /* Firmware specific data (e.g. ACPI,
306 BIOS data),reserved for device core*/
1da177e4
LT
307 struct dev_pm_info power;
308
1da177e4
LT
309 u64 *dma_mask; /* dma mask (if dma'able device) */
310 u64 coherent_dma_mask;/* Like dma_mask, but for
311 alloc_coherent mappings as
312 not all hardware supports
313 64 bit addresses for consistent
314 allocations such descriptors. */
315
316 struct list_head dma_pools; /* dma pools (if dma'ble) */
317
318 struct dma_coherent_mem *dma_mem; /* internal for coherent mem
319 override */
320
321 void (*release)(struct device * dev);
322};
323
1da177e4
LT
324static inline void *
325dev_get_drvdata (struct device *dev)
326{
327 return dev->driver_data;
328}
329
330static inline void
331dev_set_drvdata (struct device *dev, void *data)
332{
333 dev->driver_data = data;
334}
335
d305ef5d
DR
336static inline int device_is_registered(struct device *dev)
337{
338 return klist_node_attached(&dev->knode_bus);
339}
340
1da177e4
LT
341/*
342 * High level routines for use by the bus drivers
343 */
344extern int device_register(struct device * dev);
345extern void device_unregister(struct device * dev);
346extern void device_initialize(struct device * dev);
347extern int device_add(struct device * dev);
348extern void device_del(struct device * dev);
349extern int device_for_each_child(struct device *, void *,
350 int (*fn)(struct device *, void *));
351
352/*
353 * Manual binding of a device to driver. See drivers/base/bus.c
354 * for information on use.
355 */
1da177e4
LT
356extern void device_bind_driver(struct device * dev);
357extern void device_release_driver(struct device * dev);
358extern int device_attach(struct device * dev);
359extern void driver_attach(struct device_driver * drv);
360
361
1da177e4
LT
362/*
363 * Platform "fixup" functions - allow the platform to have their say
364 * about devices and actions that the general device layer doesn't
365 * know about.
366 */
367/* Notify platform of device discovery */
368extern int (*platform_notify)(struct device * dev);
369
370extern int (*platform_notify_remove)(struct device * dev);
371
372
373/**
374 * get_device - atomically increment the reference count for the device.
375 *
376 */
377extern struct device * get_device(struct device * dev);
378extern void put_device(struct device * dev);
1da177e4
LT
379
380
381/* drivers/base/platform.c */
382
383struct platform_device {
8d790d74 384 const char * name;
1da177e4
LT
385 u32 id;
386 struct device dev;
387 u32 num_resources;
388 struct resource * resource;
389};
390
391#define to_platform_device(x) container_of((x), struct platform_device, dev)
392
393extern int platform_device_register(struct platform_device *);
394extern void platform_device_unregister(struct platform_device *);
395
396extern struct bus_type platform_bus_type;
397extern struct device platform_bus;
398
399extern struct resource *platform_get_resource(struct platform_device *, unsigned int, unsigned int);
400extern int platform_get_irq(struct platform_device *, unsigned int);
401extern struct resource *platform_get_resource_byname(struct platform_device *, unsigned int, char *);
402extern int platform_get_irq_byname(struct platform_device *, char *);
403extern int platform_add_devices(struct platform_device **, int);
404
405extern struct platform_device *platform_device_register_simple(char *, unsigned int, struct resource *, unsigned int);
406
407/* drivers/base/power.c */
408extern void device_shutdown(void);
409
410
411/* drivers/base/firmware.c */
412extern int firmware_register(struct subsystem *);
413extern void firmware_unregister(struct subsystem *);
414
415/* debugging and troubleshooting/diagnostic helpers. */
416#define dev_printk(level, dev, format, arg...) \
417 printk(level "%s %s: " format , (dev)->driver ? (dev)->driver->name : "" , (dev)->bus_id , ## arg)
418
419#ifdef DEBUG
420#define dev_dbg(dev, format, arg...) \
421 dev_printk(KERN_DEBUG , dev , format , ## arg)
422#else
423#define dev_dbg(dev, format, arg...) do { (void)(dev); } while (0)
424#endif
425
426#define dev_err(dev, format, arg...) \
427 dev_printk(KERN_ERR , dev , format , ## arg)
428#define dev_info(dev, format, arg...) \
429 dev_printk(KERN_INFO , dev , format , ## arg)
430#define dev_warn(dev, format, arg...) \
431 dev_printk(KERN_WARNING , dev , format , ## arg)
432
433/* Create alias, so I can be autoloaded. */
434#define MODULE_ALIAS_CHARDEV(major,minor) \
435 MODULE_ALIAS("char-major-" __stringify(major) "-" __stringify(minor))
436#define MODULE_ALIAS_CHARDEV_MAJOR(major) \
437 MODULE_ALIAS("char-major-" __stringify(major) "-*")
438#endif /* _DEVICE_H_ */
This page took 0.155281 seconds and 5 git commands to generate.