]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - include/linux/device.h
include: Convert ethernet mac address declarations to use ETH_ALEN
[mirror_ubuntu-bionic-kernel.git] / include / linux / device.h
index 9d4835a8f8b8df4f3d277b7244c2f1b7abeebe5c..22b546a585916b2c8b5754c3f321130c7231d1fe 100644 (file)
@@ -47,7 +47,11 @@ struct bus_attribute {
 };
 
 #define BUS_ATTR(_name, _mode, _show, _store)  \
-struct bus_attribute bus_attr_##_name = __ATTR(_name, _mode, _show, _store)
+       struct bus_attribute bus_attr_##_name = __ATTR(_name, _mode, _show, _store)
+#define BUS_ATTR_RW(_name) \
+       struct bus_attribute bus_attr_##_name = __ATTR_RW(_name)
+#define BUS_ATTR_RO(_name) \
+       struct bus_attribute bus_attr_##_name = __ATTR_RO(_name)
 
 extern int __must_check bus_create_file(struct bus_type *,
                                        struct bus_attribute *);
@@ -71,6 +75,10 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *);
  *             the specific driver's probe to initial the matched device.
  * @remove:    Called when a device removed from this bus.
  * @shutdown:  Called at shut-down time to quiesce the device.
+ *
+ * @online:    Called to put the device back online (after offlining it).
+ * @offline:   Called to put the device offline for hot-removal. May fail.
+ *
  * @suspend:   Called when a device on this bus wants to go to sleep mode.
  * @resume:    Called to bring a device on this bus out of sleep mode.
  * @pm:                Power management operations of this bus, callback the specific
@@ -105,6 +113,9 @@ struct bus_type {
        int (*remove)(struct device *dev);
        void (*shutdown)(struct device *dev);
 
+       int (*online)(struct device *dev);
+       int (*offline)(struct device *dev);
+
        int (*suspend)(struct device *dev, pm_message_t state);
        int (*resume)(struct device *dev);
 
@@ -254,9 +265,12 @@ struct driver_attribute {
                         size_t count);
 };
 
-#define DRIVER_ATTR(_name, _mode, _show, _store)       \
-struct driver_attribute driver_attr_##_name =          \
-       __ATTR(_name, _mode, _show, _store)
+#define DRIVER_ATTR(_name, _mode, _show, _store) \
+       struct driver_attribute driver_attr_##_name = __ATTR(_name, _mode, _show, _store)
+#define DRIVER_ATTR_RW(_name) \
+       struct driver_attribute driver_attr_##_name = __ATTR_RW(_name)
+#define DRIVER_ATTR_RO(_name) \
+       struct driver_attribute driver_attr_##_name = __ATTR_RO(_name)
 
 extern int __must_check driver_create_file(struct device_driver *driver,
                                        const struct driver_attribute *attr);
@@ -306,6 +320,7 @@ int subsys_virtual_register(struct bus_type *subsys,
  * @name:      Name of the class.
  * @owner:     The module owner.
  * @class_attrs: Default attributes of this class.
+ * @dev_groups:        Default attributes of the devices that belong to the class.
  * @dev_attrs: Default attributes of the devices belong to the class.
  * @dev_bin_attrs: Default binary attributes of the devices belong to the class.
  * @dev_kobj:  The kobject that represents this class and links it into the hierarchy.
@@ -335,7 +350,8 @@ struct class {
        struct module           *owner;
 
        struct class_attribute          *class_attrs;
-       struct device_attribute         *dev_attrs;
+       struct device_attribute         *dev_attrs;     /* use dev_groups instead */
+       const struct attribute_group    **dev_groups;
        struct bin_attribute            *dev_bin_attrs;
        struct kobject                  *dev_kobj;
 
@@ -407,8 +423,12 @@ struct class_attribute {
                                 const struct class_attribute *attr);
 };
 
-#define CLASS_ATTR(_name, _mode, _show, _store)                        \
-struct class_attribute class_attr_##_name = __ATTR(_name, _mode, _show, _store)
+#define CLASS_ATTR(_name, _mode, _show, _store) \
+       struct class_attribute class_attr_##_name = __ATTR(_name, _mode, _show, _store)
+#define CLASS_ATTR_RW(_name) \
+       struct class_attribute class_attr_##_name = __ATTR_RW(_name)
+#define CLASS_ATTR_RO(_name) \
+       struct class_attribute class_attr_##_name = __ATTR_RO(_name)
 
 extern int __must_check class_create_file(struct class *class,
                                          const struct class_attribute *attr);
@@ -416,7 +436,6 @@ 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;
@@ -505,6 +524,10 @@ ssize_t device_store_bool(struct device *dev, struct device_attribute *attr,
 
 #define DEVICE_ATTR(_name, _mode, _show, _store) \
        struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)
+#define DEVICE_ATTR_RW(_name) \
+       struct device_attribute dev_attr_##_name = __ATTR_RW(_name)
+#define DEVICE_ATTR_RO(_name) \
+       struct device_attribute dev_attr_##_name = __ATTR_RO(_name)
 #define DEVICE_ULONG_ATTR(_name, _mode, _var) \
        struct dev_ext_attribute dev_attr_##_name = \
                { __ATTR(_name, _mode, device_show_ulong, device_store_ulong), &(_var) }
@@ -652,6 +675,9 @@ struct acpi_dev_node {
  *             device (i.e. the bus driver that discovered the device).
  * @iommu_group: IOMMU group the device belongs to.
  *
+ * @offline_disabled: If set, the device is permanently online.
+ * @offline:   Set after successful invocation of bus type's .offline().
+ *
  * At the lowest level, every device in a Linux system is represented by an
  * instance of struct device. The device structure contains the information
  * that the device model core needs to model the system. Most subsystems,
@@ -723,6 +749,9 @@ struct device {
 
        void    (*release)(struct device *dev);
        struct iommu_group      *iommu_group;
+
+       bool                    offline_disabled:1;
+       bool                    offline:1;
 };
 
 static inline struct device *kobj_to_dev(struct kobject *kobj)
@@ -859,6 +888,15 @@ extern const char *device_get_devnode(struct device *dev,
 extern void *dev_get_drvdata(const struct device *dev);
 extern int dev_set_drvdata(struct device *dev, void *data);
 
+static inline bool device_supports_offline(struct device *dev)
+{
+       return dev->bus && dev->bus->offline && dev->bus->online;
+}
+
+extern void lock_device_hotplug(void);
+extern void unlock_device_hotplug(void);
+extern int device_offline(struct device *dev);
+extern int device_online(struct device *dev);
 /*
  * Root device objects for grouping under /sys/devices
  */
@@ -902,6 +940,11 @@ extern __printf(5, 6)
 struct device *device_create(struct class *cls, struct device *parent,
                             dev_t devt, void *drvdata,
                             const char *fmt, ...);
+extern __printf(6, 7)
+struct device *device_create_with_groups(struct class *cls,
+                            struct device *parent, dev_t devt, void *drvdata,
+                            const struct attribute_group **groups,
+                            const char *fmt, ...);
 extern void device_destroy(struct class *cls, dev_t devt);
 
 /*