ia64/linux-2.6.18-xen.hg

view include/linux/device.h @ 881:e9f508296fc7

pcie io space multiplex: backport of bus event notification patch

back port of 116af378201ef793424cd10508ccf18b06d8a021 and
ec0676ee28528dc8dda13a93ee4b1f215a0c2f9d.

commit 116af378201ef793424cd10508ccf18b06d8a021
Author: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Date: Wed Oct 25 13:44:59 2006 +1000

Driver core: add notification of bus events

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


commit ec0676ee28528dc8dda13a93ee4b1f215a0c2f9d
Author: Alan Stern <stern@rowland.harvard.edu>
Date: Fri Dec 5 14:10:31 2008 -0500

Driver core: move the bus notifier call points

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Cc: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
author Keir Fraser <keir.fraser@citrix.com>
date Thu May 28 09:56:11 2009 +0100 (2009-05-28)
parents 831230e53067
children
line source
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 */
11 #ifndef _DEVICE_H_
12 #define _DEVICE_H_
14 #include <linux/ioport.h>
15 #include <linux/kobject.h>
16 #include <linux/klist.h>
17 #include <linux/list.h>
18 #include <linux/types.h>
19 #include <linux/module.h>
20 #include <linux/pm.h>
21 #include <asm/semaphore.h>
22 #include <asm/atomic.h>
24 #define DEVICE_NAME_SIZE 50
25 #define DEVICE_NAME_HALF __stringify(20) /* Less than half to accommodate slop */
26 #define DEVICE_ID_SIZE 32
27 #define BUS_ID_SIZE KOBJ_NAME_LEN
30 struct device;
31 struct device_driver;
32 struct class;
33 struct class_device;
35 struct bus_type {
36 const char * name;
38 struct subsystem subsys;
39 struct kset drivers;
40 struct kset devices;
41 struct klist klist_devices;
42 struct klist klist_drivers;
44 struct blocking_notifier_head bus_notifier;
46 struct bus_attribute * bus_attrs;
47 struct device_attribute * dev_attrs;
48 struct driver_attribute * drv_attrs;
50 int (*match)(struct device * dev, struct device_driver * drv);
51 int (*uevent)(struct device *dev, char **envp,
52 int num_envp, char *buffer, int buffer_size);
53 int (*probe)(struct device * dev);
54 int (*remove)(struct device * dev);
55 void (*shutdown)(struct device * dev);
56 int (*suspend)(struct device * dev, pm_message_t state);
57 int (*resume)(struct device * dev);
58 };
60 extern int bus_register(struct bus_type * bus);
61 extern void bus_unregister(struct bus_type * bus);
63 extern void bus_rescan_devices(struct bus_type * bus);
65 /* iterator helpers for buses */
67 int bus_for_each_dev(struct bus_type * bus, struct device * start, void * data,
68 int (*fn)(struct device *, void *));
69 struct device * bus_find_device(struct bus_type *bus, struct device *start,
70 void *data, int (*match)(struct device *, void *));
72 int bus_for_each_drv(struct bus_type * bus, struct device_driver * start,
73 void * data, int (*fn)(struct device_driver *, void *));
76 /*
77 * Bus notifiers: Get notified of addition/removal of devices
78 * and binding/unbinding of drivers to devices.
79 * In the long run, it should be a replacement for the platform
80 * notify hooks.
81 */
82 struct notifier_block;
84 extern int bus_register_notifier(struct bus_type *bus,
85 struct notifier_block *nb);
86 extern int bus_unregister_notifier(struct bus_type *bus,
87 struct notifier_block *nb);
89 /* All 4 notifers below get called with the target struct device *
90 * as an argument. Note that those functions are likely to be called
91 * with the device semaphore held in the core, so be careful.
92 */
93 #define BUS_NOTIFY_ADD_DEVICE 0x00000001 /* device added */
94 #define BUS_NOTIFY_DEL_DEVICE 0x00000002 /* device removed */
95 #define BUS_NOTIFY_BOUND_DRIVER 0x00000003 /* driver bound to device */
96 #define BUS_NOTIFY_UNBIND_DRIVER 0x00000004 /* driver about to be
97 unbound */
99 /* driverfs interface for exporting bus attributes */
101 struct bus_attribute {
102 struct attribute attr;
103 ssize_t (*show)(struct bus_type *, char * buf);
104 ssize_t (*store)(struct bus_type *, const char * buf, size_t count);
105 };
107 #define BUS_ATTR(_name,_mode,_show,_store) \
108 struct bus_attribute bus_attr_##_name = __ATTR(_name,_mode,_show,_store)
110 extern int bus_create_file(struct bus_type *, struct bus_attribute *);
111 extern void bus_remove_file(struct bus_type *, struct bus_attribute *);
113 struct device_driver {
114 const char * name;
115 struct bus_type * bus;
117 struct completion unloaded;
118 struct kobject kobj;
119 struct klist klist_devices;
120 struct klist_node knode_bus;
122 struct module * owner;
124 int (*probe) (struct device * dev);
125 int (*remove) (struct device * dev);
126 void (*shutdown) (struct device * dev);
127 int (*suspend) (struct device * dev, pm_message_t state);
128 int (*resume) (struct device * dev);
129 };
132 extern int driver_register(struct device_driver * drv);
133 extern void driver_unregister(struct device_driver * drv);
135 extern struct device_driver * get_driver(struct device_driver * drv);
136 extern void put_driver(struct device_driver * drv);
137 extern struct device_driver *driver_find(const char *name, struct bus_type *bus);
140 /* driverfs interface for exporting driver attributes */
142 struct driver_attribute {
143 struct attribute attr;
144 ssize_t (*show)(struct device_driver *, char * buf);
145 ssize_t (*store)(struct device_driver *, const char * buf, size_t count);
146 };
148 #define DRIVER_ATTR(_name,_mode,_show,_store) \
149 struct driver_attribute driver_attr_##_name = __ATTR(_name,_mode,_show,_store)
151 extern int driver_create_file(struct device_driver *, struct driver_attribute *);
152 extern void driver_remove_file(struct device_driver *, struct driver_attribute *);
154 extern int driver_for_each_device(struct device_driver * drv, struct device * start,
155 void * data, int (*fn)(struct device *, void *));
156 struct device * driver_find_device(struct device_driver *drv,
157 struct device *start, void *data,
158 int (*match)(struct device *, void *));
161 /*
162 * device classes
163 */
164 struct class {
165 const char * name;
166 struct module * owner;
168 struct subsystem subsys;
169 struct list_head children;
170 struct list_head devices;
171 struct list_head interfaces;
172 struct semaphore sem; /* locks both the children and interfaces lists */
174 struct class_attribute * class_attrs;
175 struct class_device_attribute * class_dev_attrs;
177 int (*uevent)(struct class_device *dev, char **envp,
178 int num_envp, char *buffer, int buffer_size);
180 void (*release)(struct class_device *dev);
181 void (*class_release)(struct class *class);
182 };
184 extern int class_register(struct class *);
185 extern void class_unregister(struct class *);
188 struct class_attribute {
189 struct attribute attr;
190 ssize_t (*show)(struct class *, char * buf);
191 ssize_t (*store)(struct class *, const char * buf, size_t count);
192 };
194 #define CLASS_ATTR(_name,_mode,_show,_store) \
195 struct class_attribute class_attr_##_name = __ATTR(_name,_mode,_show,_store)
197 extern int class_create_file(struct class *, const struct class_attribute *);
198 extern void class_remove_file(struct class *, const struct class_attribute *);
200 struct class_device_attribute {
201 struct attribute attr;
202 ssize_t (*show)(struct class_device *, char * buf);
203 ssize_t (*store)(struct class_device *, const char * buf, size_t count);
204 };
206 #define CLASS_DEVICE_ATTR(_name,_mode,_show,_store) \
207 struct class_device_attribute class_device_attr_##_name = \
208 __ATTR(_name,_mode,_show,_store)
210 extern int class_device_create_file(struct class_device *,
211 const struct class_device_attribute *);
213 /**
214 * struct class_device - class devices
215 * @class: pointer to the parent class for this class device. This is required.
216 * @devt: for internal use by the driver core only.
217 * @node: for internal use by the driver core only.
218 * @kobj: for internal use by the driver core only.
219 * @devt_attr: for internal use by the driver core only.
220 * @groups: optional additional groups to be created
221 * @dev: if set, a symlink to the struct device is created in the sysfs
222 * directory for this struct class device.
223 * @class_data: pointer to whatever you want to store here for this struct
224 * class_device. Use class_get_devdata() and class_set_devdata() to get and
225 * set this pointer.
226 * @parent: pointer to a struct class_device that is the parent of this struct
227 * class_device. If NULL, this class_device will show up at the root of the
228 * struct class in sysfs (which is probably what you want to have happen.)
229 * @release: pointer to a release function for this struct class_device. If
230 * set, this will be called instead of the class specific release function.
231 * Only use this if you want to override the default release function, like
232 * when you are nesting class_device structures.
233 * @uevent: pointer to a uevent function for this struct class_device. If
234 * set, this will be called instead of the class specific uevent function.
235 * Only use this if you want to override the default uevent function, like
236 * when you are nesting class_device structures.
237 */
238 struct class_device {
239 struct list_head node;
241 struct kobject kobj;
242 struct class * class; /* required */
243 dev_t devt; /* dev_t, creates the sysfs "dev" */
244 struct class_device_attribute *devt_attr;
245 struct class_device_attribute uevent_attr;
246 struct device * dev; /* not necessary, but nice to have */
247 void * class_data; /* class-specific data */
248 struct class_device *parent; /* parent of this child device, if there is one */
249 struct attribute_group ** groups; /* optional groups */
251 void (*release)(struct class_device *dev);
252 int (*uevent)(struct class_device *dev, char **envp,
253 int num_envp, char *buffer, int buffer_size);
254 char class_id[BUS_ID_SIZE]; /* unique to this class */
255 };
257 static inline void *
258 class_get_devdata (struct class_device *dev)
259 {
260 return dev->class_data;
261 }
263 static inline void
264 class_set_devdata (struct class_device *dev, void *data)
265 {
266 dev->class_data = data;
267 }
270 extern int class_device_register(struct class_device *);
271 extern void class_device_unregister(struct class_device *);
272 extern void class_device_initialize(struct class_device *);
273 extern int class_device_add(struct class_device *);
274 extern void class_device_del(struct class_device *);
276 extern int class_device_rename(struct class_device *, char *);
278 extern struct class_device * class_device_get(struct class_device *);
279 extern void class_device_put(struct class_device *);
281 extern void class_device_remove_file(struct class_device *,
282 const struct class_device_attribute *);
283 extern int class_device_create_bin_file(struct class_device *,
284 struct bin_attribute *);
285 extern void class_device_remove_bin_file(struct class_device *,
286 struct bin_attribute *);
288 struct class_interface {
289 struct list_head node;
290 struct class *class;
292 int (*add) (struct class_device *, struct class_interface *);
293 void (*remove) (struct class_device *, struct class_interface *);
294 };
296 extern int class_interface_register(struct class_interface *);
297 extern void class_interface_unregister(struct class_interface *);
299 extern struct class *class_create(struct module *owner, char *name);
300 extern void class_destroy(struct class *cls);
301 extern struct class_device *class_device_create(struct class *cls,
302 struct class_device *parent,
303 dev_t devt,
304 struct device *device,
305 char *fmt, ...)
306 __attribute__((format(printf,5,6)));
307 extern void class_device_destroy(struct class *cls, dev_t devt);
310 /* interface for exporting device attributes */
311 struct device_attribute {
312 struct attribute attr;
313 ssize_t (*show)(struct device *dev, struct device_attribute *attr,
314 char *buf);
315 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
316 const char *buf, size_t count);
317 };
319 #define DEVICE_ATTR(_name,_mode,_show,_store) \
320 struct device_attribute dev_attr_##_name = __ATTR(_name,_mode,_show,_store)
322 extern int device_create_file(struct device *device, struct device_attribute * entry);
323 extern void device_remove_file(struct device * dev, struct device_attribute * attr);
324 struct device {
325 struct klist klist_children;
326 struct klist_node knode_parent; /* node in sibling list */
327 struct klist_node knode_driver;
328 struct klist_node knode_bus;
329 struct device * parent;
331 struct kobject kobj;
332 char bus_id[BUS_ID_SIZE]; /* position on parent bus */
333 struct device_attribute uevent_attr;
334 struct device_attribute *devt_attr;
336 struct semaphore sem; /* semaphore to synchronize calls to
337 * its driver.
338 */
340 struct bus_type * bus; /* type of bus device is on */
341 struct device_driver *driver; /* which driver has allocated this
342 device */
343 void *driver_data; /* data private to the driver */
344 void *platform_data; /* Platform specific data, device
345 core doesn't touch it */
346 void *firmware_data; /* Firmware specific data (e.g. ACPI,
347 BIOS data),reserved for device core*/
348 struct dev_pm_info power;
350 u64 *dma_mask; /* dma mask (if dma'able device) */
351 u64 coherent_dma_mask;/* Like dma_mask, but for
352 alloc_coherent mappings as
353 not all hardware supports
354 64 bit addresses for consistent
355 allocations such descriptors. */
357 struct list_head dma_pools; /* dma pools (if dma'ble) */
359 struct dma_coherent_mem *dma_mem; /* internal for coherent mem
360 override */
362 /* class_device migration path */
363 struct list_head node;
364 struct class *class; /* optional*/
365 dev_t devt; /* dev_t, creates the sysfs "dev" */
367 void (*release)(struct device * dev);
368 };
370 static inline void *
371 dev_get_drvdata (struct device *dev)
372 {
373 return dev->driver_data;
374 }
376 static inline void
377 dev_set_drvdata (struct device *dev, void *data)
378 {
379 dev->driver_data = data;
380 }
382 static inline int device_is_registered(struct device *dev)
383 {
384 return klist_node_attached(&dev->knode_bus);
385 }
387 /*
388 * High level routines for use by the bus drivers
389 */
390 extern int device_register(struct device * dev);
391 extern void device_unregister(struct device * dev);
392 extern void device_initialize(struct device * dev);
393 extern int device_add(struct device * dev);
394 extern void device_del(struct device * dev);
395 extern int device_for_each_child(struct device *, void *,
396 int (*fn)(struct device *, void *));
398 /*
399 * Manual binding of a device to driver. See drivers/base/bus.c
400 * for information on use.
401 */
402 extern void device_bind_driver(struct device * dev);
403 extern void device_release_driver(struct device * dev);
404 extern int device_attach(struct device * dev);
405 extern void driver_attach(struct device_driver * drv);
406 extern void device_reprobe(struct device *dev);
408 /*
409 * Easy functions for dynamically creating devices on the fly
410 */
411 extern struct device *device_create(struct class *cls, struct device *parent,
412 dev_t devt, char *fmt, ...)
413 __attribute__((format(printf,4,5)));
414 extern void device_destroy(struct class *cls, dev_t devt);
416 /*
417 * Platform "fixup" functions - allow the platform to have their say
418 * about devices and actions that the general device layer doesn't
419 * know about.
420 */
421 /* Notify platform of device discovery */
422 extern int (*platform_notify)(struct device * dev);
424 extern int (*platform_notify_remove)(struct device * dev);
427 /**
428 * get_device - atomically increment the reference count for the device.
429 *
430 */
431 extern struct device * get_device(struct device * dev);
432 extern void put_device(struct device * dev);
435 /* drivers/base/power/shutdown.c */
436 extern void device_shutdown(void);
439 /* drivers/base/firmware.c */
440 extern int firmware_register(struct subsystem *);
441 extern void firmware_unregister(struct subsystem *);
443 /* debugging and troubleshooting/diagnostic helpers. */
444 extern const char *dev_driver_string(struct device *dev);
445 #define dev_printk(level, dev, format, arg...) \
446 printk(level "%s %s: " format , dev_driver_string(dev) , (dev)->bus_id , ## arg)
448 #ifdef DEBUG
449 #define dev_dbg(dev, format, arg...) \
450 dev_printk(KERN_DEBUG , dev , format , ## arg)
451 #else
452 #define dev_dbg(dev, format, arg...) do { (void)(dev); } while (0)
453 #endif
455 #define dev_err(dev, format, arg...) \
456 dev_printk(KERN_ERR , dev , format , ## arg)
457 #define dev_info(dev, format, arg...) \
458 dev_printk(KERN_INFO , dev , format , ## arg)
459 #define dev_warn(dev, format, arg...) \
460 dev_printk(KERN_WARNING , dev , format , ## arg)
461 #define dev_notice(dev, format, arg...) \
462 dev_printk(KERN_NOTICE , dev , format , ## arg)
464 /* Create alias, so I can be autoloaded. */
465 #define MODULE_ALIAS_CHARDEV(major,minor) \
466 MODULE_ALIAS("char-major-" __stringify(major) "-" __stringify(minor))
467 #define MODULE_ALIAS_CHARDEV_MAJOR(major) \
468 MODULE_ALIAS("char-major-" __stringify(major) "-*")
469 #endif /* _DEVICE_H_ */