rapidio: add enabling SRIO port RX and TX
[safe/jmp/linux-2.6] / include / linux / device.h
index a286429..0713e10 100644 (file)
@@ -2,7 +2,8 @@
  * device.h - generic, centralized driver model
  *
  * Copyright (c) 2001-2003 Patrick Mochel <mochel@osdl.org>
- * Copyright (c) 2004-2007 Greg Kroah-Hartman <gregkh@suse.de>
+ * Copyright (c) 2004-2009 Greg Kroah-Hartman <gregkh@suse.de>
+ * Copyright (c) 2008-2009 Novell Inc.
  *
  * This file is released under the GPLv2
  *
@@ -21,7 +22,6 @@
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/pm.h>
-#include <linux/semaphore.h>
 #include <asm/atomic.h>
 #include <asm/device.h>
 
@@ -33,6 +33,7 @@ struct class;
 struct class_private;
 struct bus_type;
 struct bus_type_private;
+struct device_node;
 
 struct bus_attribute {
        struct attribute        attr;
@@ -105,7 +106,7 @@ extern int bus_unregister_notifier(struct bus_type *bus,
 
 /* All 4 notifers below get called with the target struct device *
  * as an argument. Note that those functions are likely to be called
- * with the device semaphore held in the core, so be careful.
+ * with the device lock held in the core, so be careful.
  */
 #define BUS_NOTIFY_ADD_DEVICE          0x00000001 /* device added */
 #define BUS_NOTIFY_DEL_DEVICE          0x00000002 /* device removed */
@@ -123,14 +124,20 @@ struct device_driver {
        struct bus_type         *bus;
 
        struct module           *owner;
-       const char              *mod_name;      /* used for built-in modules */
+       const char              *mod_name;      /* used for built-in modules */
+
+       bool suppress_bind_attrs;       /* disables bind/unbind via sysfs */
+
+#if defined(CONFIG_OF)
+       const struct of_device_id       *of_match_table;
+#endif
 
        int (*probe) (struct device *dev);
        int (*remove) (struct device *dev);
        void (*shutdown) (struct device *dev);
        int (*suspend) (struct device *dev, pm_message_t state);
        int (*resume) (struct device *dev);
-       struct attribute_group **groups;
+       const struct attribute_group **groups;
 
        const struct dev_pm_ops *pm;
 
@@ -163,9 +170,9 @@ struct driver_attribute driver_attr_##_name =               \
        __ATTR(_name, _mode, _show, _store)
 
 extern int __must_check driver_create_file(struct device_driver *driver,
-                                          struct driver_attribute *attr);
+                                       const struct driver_attribute *attr);
 extern void driver_remove_file(struct device_driver *driver,
-                              struct driver_attribute *attr);
+                              const struct driver_attribute *attr);
 
 extern int __must_check driver_add_kobj(struct device_driver *drv,
                                        struct kobject *kobj,
@@ -192,7 +199,7 @@ struct class {
        struct kobject                  *dev_kobj;
 
        int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env);
-       char *(*nodename)(struct device *dev);
+       char *(*devnode)(struct device *dev, mode_t *mode);
 
        void (*class_release)(struct class *class);
        void (*dev_release)(struct device *dev);
@@ -200,6 +207,9 @@ struct class {
        int (*suspend)(struct device *dev, pm_message_t state);
        int (*resume)(struct device *dev);
 
+       const struct kobj_ns_type_operations *ns_type;
+       const void *(*namespace)(struct device *dev);
+
        const struct dev_pm_ops *pm;
 
        struct class_private *p;
@@ -224,6 +234,14 @@ extern void class_unregister(struct class *class);
        __class_register(class, &__key);        \
 })
 
+struct class_compat;
+struct class_compat *class_compat_register(const char *name);
+void class_compat_unregister(struct class_compat *cls);
+int class_compat_create_link(struct class_compat *cls, struct device *dev,
+                            struct device *device_link);
+void class_compat_remove_link(struct class_compat *cls, struct device *dev,
+                             struct device *device_link);
+
 extern void class_dev_iter_init(struct class_dev_iter *iter,
                                struct class *class,
                                struct device *start,
@@ -240,8 +258,10 @@ extern struct device *class_find_device(struct class *class,
 
 struct class_attribute {
        struct attribute attr;
-       ssize_t (*show)(struct class *class, char *buf);
-       ssize_t (*store)(struct class *class, const char *buf, size_t count);
+       ssize_t (*show)(struct class *class, struct class_attribute *attr,
+                       char *buf);
+       ssize_t (*store)(struct class *class, struct class_attribute *attr,
+                       const char *buf, size_t count);
 };
 
 #define CLASS_ATTR(_name, _mode, _show, _store)                        \
@@ -252,6 +272,23 @@ extern int __must_check class_create_file(struct class *class,
 extern void class_remove_file(struct class *class,
                              const struct class_attribute *attr);
 
+/* Simple class attribute that is just a static string */
+
+struct class_attribute_string {
+       struct class_attribute attr;
+       char *str;
+};
+
+/* Currently read-only only */
+#define _CLASS_ATTR_STRING(_name, _mode, _str) \
+       { __ATTR(_name, _mode, show_class_attr_string, NULL), _str }
+#define CLASS_ATTR_STRING(_name, _mode, _str) \
+       struct class_attribute_string class_attr_##_name = \
+               _CLASS_ATTR_STRING(_name, _mode, _str)
+
+extern ssize_t show_class_attr_string(struct class *class, struct class_attribute *attr,
+                        char *buf);
+
 struct class_interface {
        struct list_head        node;
        struct class            *class;
@@ -287,9 +324,9 @@ extern void class_destroy(struct class *cls);
  */
 struct device_type {
        const char *name;
-       struct attribute_group **groups;
+       const struct attribute_group **groups;
        int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
-       char *(*nodename)(struct device *dev);
+       char *(*devnode)(struct device *dev, mode_t *mode);
        void (*release)(struct device *dev);
 
        const struct dev_pm_ops *pm;
@@ -308,13 +345,13 @@ struct device_attribute {
 struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)
 
 extern int __must_check device_create_file(struct device *device,
-                                          struct device_attribute *entry);
+                                       const struct device_attribute *entry);
 extern void device_remove_file(struct device *dev,
-                              struct device_attribute *attr);
+                              const struct device_attribute *attr);
 extern int __must_check device_create_bin_file(struct device *dev,
-                                              struct bin_attribute *attr);
+                                       const struct bin_attribute *attr);
 extern void device_remove_bin_file(struct device *dev,
-                                  struct bin_attribute *attr);
+                                  const struct bin_attribute *attr);
 extern int device_schedule_callback_owner(struct device *dev,
                void (*func)(struct device *dev), struct module *owner);
 
@@ -374,14 +411,13 @@ struct device {
        const char              *init_name; /* initial name of the device */
        struct device_type      *type;
 
-       struct semaphore        sem;    /* semaphore to synchronize calls to
+       struct mutex            mutex;  /* mutex to synchronize calls to
                                         * its driver.
                                         */
 
        struct bus_type *bus;           /* type of bus device is on */
        struct device_driver *driver;   /* which driver has allocated this
                                           device */
-       void            *driver_data;   /* data private to the driver */
        void            *platform_data; /* Platform specific data, device
                                           core doesn't touch it */
        struct dev_pm_info      power;
@@ -404,6 +440,9 @@ struct device {
                                             override */
        /* arch specific additions */
        struct dev_archdata     archdata;
+#ifdef CONFIG_OF
+       struct device_node      *of_node;
+#endif
 
        dev_t                   devt;   /* dev_t, creates the sysfs "dev" */
 
@@ -412,7 +451,7 @@ struct device {
 
        struct klist_node       knode_class;
        struct class            *class;
-       struct attribute_group  **groups;       /* optional groups */
+       const struct attribute_group **groups;  /* optional groups */
 
        void    (*release)(struct device *dev);
 };
@@ -422,6 +461,10 @@ struct device {
 
 static inline const char *dev_name(const struct device *dev)
 {
+       /* Use the init name until the kobject becomes available */
+       if (dev->init_name)
+               return dev->init_name;
+
        return kobject_name(&dev->kobj);
 }
 
@@ -447,16 +490,6 @@ static inline void set_dev_node(struct device *dev, int node)
 }
 #endif
 
-static inline void *dev_get_drvdata(const struct device *dev)
-{
-       return dev->driver_data;
-}
-
-static inline void dev_set_drvdata(struct device *dev, void *data)
-{
-       dev->driver_data = data;
-}
-
 static inline unsigned int dev_get_uevent_suppress(const struct device *dev)
 {
        return dev->kobj.uevent_suppress;
@@ -472,6 +505,38 @@ static inline int device_is_registered(struct device *dev)
        return dev->kobj.state_in_sysfs;
 }
 
+static inline void device_enable_async_suspend(struct device *dev)
+{
+       if (dev->power.status == DPM_ON)
+               dev->power.async_suspend = true;
+}
+
+static inline void device_disable_async_suspend(struct device *dev)
+{
+       if (dev->power.status == DPM_ON)
+               dev->power.async_suspend = false;
+}
+
+static inline bool device_async_suspend_enabled(struct device *dev)
+{
+       return !!dev->power.async_suspend;
+}
+
+static inline void device_lock(struct device *dev)
+{
+       mutex_lock(&dev->mutex);
+}
+
+static inline int device_trylock(struct device *dev)
+{
+       return mutex_trylock(&dev->mutex);
+}
+
+static inline void device_unlock(struct device *dev)
+{
+       mutex_unlock(&dev->mutex);
+}
+
 void driver_init(void);
 
 /*
@@ -489,7 +554,10 @@ extern struct device *device_find_child(struct device *dev, void *data,
 extern int device_rename(struct device *dev, char *new_name);
 extern int device_move(struct device *dev, struct device *new_parent,
                       enum dpm_order dpm_order);
-extern const char *device_get_nodename(struct device *dev, const char **tmp);
+extern const char *device_get_devnode(struct device *dev,
+                                     mode_t *mode, const char **tmp);
+extern void *dev_get_drvdata(const struct device *dev);
+extern void dev_set_drvdata(struct device *dev, void *data);
 
 /*
  * Root device objects for grouping under /sys/devices
@@ -502,6 +570,11 @@ static inline struct device *root_device_register(const char *name)
 }
 extern void root_device_unregister(struct device *root);
 
+static inline void *dev_get_platdata(const struct device *dev)
+{
+       return dev->platform_data;
+}
+
 /*
  * Manual binding of a device to driver. See drivers/base/bus.c
  * for information on use.
@@ -547,6 +620,16 @@ extern void put_device(struct device *dev);
 
 extern void wait_for_device_probe(void);
 
+#ifdef CONFIG_DEVTMPFS
+extern int devtmpfs_create_node(struct device *dev);
+extern int devtmpfs_delete_node(struct device *dev);
+extern int devtmpfs_mount(const char *mntdir);
+#else
+static inline int devtmpfs_create_node(struct device *dev) { return 0; }
+static inline int devtmpfs_delete_node(struct device *dev) { return 0; }
+static inline int devtmpfs_mount(const char *mountpoint) { return 0; }
+#endif
+
 /* drivers/base/power/shutdown.c */
 extern void device_shutdown(void);