0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef _DEVICE_CLASS_H_
0015 #define _DEVICE_CLASS_H_
0016
0017 #include <linux/kobject.h>
0018 #include <linux/klist.h>
0019 #include <linux/pm.h>
0020 #include <linux/device/bus.h>
0021
0022 struct device;
0023 struct fwnode_handle;
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054 struct class {
0055 const char *name;
0056 struct module *owner;
0057
0058 const struct attribute_group **class_groups;
0059 const struct attribute_group **dev_groups;
0060 struct kobject *dev_kobj;
0061
0062 int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env);
0063 char *(*devnode)(struct device *dev, umode_t *mode);
0064
0065 void (*class_release)(struct class *class);
0066 void (*dev_release)(struct device *dev);
0067
0068 int (*shutdown_pre)(struct device *dev);
0069
0070 const struct kobj_ns_type_operations *ns_type;
0071 const void *(*namespace)(struct device *dev);
0072
0073 void (*get_ownership)(struct device *dev, kuid_t *uid, kgid_t *gid);
0074
0075 const struct dev_pm_ops *pm;
0076
0077 struct subsys_private *p;
0078 };
0079
0080 struct class_dev_iter {
0081 struct klist_iter ki;
0082 const struct device_type *type;
0083 };
0084
0085 extern struct kobject *sysfs_dev_block_kobj;
0086 extern struct kobject *sysfs_dev_char_kobj;
0087 extern int __must_check __class_register(struct class *class,
0088 struct lock_class_key *key);
0089 extern void class_unregister(struct class *class);
0090
0091
0092
0093 #define class_register(class) \
0094 ({ \
0095 static struct lock_class_key __key; \
0096 __class_register(class, &__key); \
0097 })
0098
0099 struct class_compat;
0100 struct class_compat *class_compat_register(const char *name);
0101 void class_compat_unregister(struct class_compat *cls);
0102 int class_compat_create_link(struct class_compat *cls, struct device *dev,
0103 struct device *device_link);
0104 void class_compat_remove_link(struct class_compat *cls, struct device *dev,
0105 struct device *device_link);
0106
0107 extern void class_dev_iter_init(struct class_dev_iter *iter,
0108 struct class *class,
0109 struct device *start,
0110 const struct device_type *type);
0111 extern struct device *class_dev_iter_next(struct class_dev_iter *iter);
0112 extern void class_dev_iter_exit(struct class_dev_iter *iter);
0113
0114 extern int class_for_each_device(struct class *class, struct device *start,
0115 void *data,
0116 int (*fn)(struct device *dev, void *data));
0117 extern struct device *class_find_device(struct class *class,
0118 struct device *start, const void *data,
0119 int (*match)(struct device *, const void *));
0120
0121
0122
0123
0124
0125
0126
0127 static inline struct device *class_find_device_by_name(struct class *class,
0128 const char *name)
0129 {
0130 return class_find_device(class, NULL, name, device_match_name);
0131 }
0132
0133
0134
0135
0136
0137
0138
0139 static inline struct device *
0140 class_find_device_by_of_node(struct class *class, const struct device_node *np)
0141 {
0142 return class_find_device(class, NULL, np, device_match_of_node);
0143 }
0144
0145
0146
0147
0148
0149
0150
0151 static inline struct device *
0152 class_find_device_by_fwnode(struct class *class,
0153 const struct fwnode_handle *fwnode)
0154 {
0155 return class_find_device(class, NULL, fwnode, device_match_fwnode);
0156 }
0157
0158
0159
0160
0161
0162
0163
0164 static inline struct device *class_find_device_by_devt(struct class *class,
0165 dev_t devt)
0166 {
0167 return class_find_device(class, NULL, &devt, device_match_devt);
0168 }
0169
0170 #ifdef CONFIG_ACPI
0171 struct acpi_device;
0172
0173
0174
0175
0176
0177
0178 static inline struct device *
0179 class_find_device_by_acpi_dev(struct class *class, const struct acpi_device *adev)
0180 {
0181 return class_find_device(class, NULL, adev, device_match_acpi_dev);
0182 }
0183 #else
0184 static inline struct device *
0185 class_find_device_by_acpi_dev(struct class *class, const void *adev)
0186 {
0187 return NULL;
0188 }
0189 #endif
0190
0191 struct class_attribute {
0192 struct attribute attr;
0193 ssize_t (*show)(struct class *class, struct class_attribute *attr,
0194 char *buf);
0195 ssize_t (*store)(struct class *class, struct class_attribute *attr,
0196 const char *buf, size_t count);
0197 };
0198
0199 #define CLASS_ATTR_RW(_name) \
0200 struct class_attribute class_attr_##_name = __ATTR_RW(_name)
0201 #define CLASS_ATTR_RO(_name) \
0202 struct class_attribute class_attr_##_name = __ATTR_RO(_name)
0203 #define CLASS_ATTR_WO(_name) \
0204 struct class_attribute class_attr_##_name = __ATTR_WO(_name)
0205
0206 extern int __must_check class_create_file_ns(struct class *class,
0207 const struct class_attribute *attr,
0208 const void *ns);
0209 extern void class_remove_file_ns(struct class *class,
0210 const struct class_attribute *attr,
0211 const void *ns);
0212
0213 static inline int __must_check class_create_file(struct class *class,
0214 const struct class_attribute *attr)
0215 {
0216 return class_create_file_ns(class, attr, NULL);
0217 }
0218
0219 static inline void class_remove_file(struct class *class,
0220 const struct class_attribute *attr)
0221 {
0222 return class_remove_file_ns(class, attr, NULL);
0223 }
0224
0225
0226 struct class_attribute_string {
0227 struct class_attribute attr;
0228 char *str;
0229 };
0230
0231
0232 #define _CLASS_ATTR_STRING(_name, _mode, _str) \
0233 { __ATTR(_name, _mode, show_class_attr_string, NULL), _str }
0234 #define CLASS_ATTR_STRING(_name, _mode, _str) \
0235 struct class_attribute_string class_attr_##_name = \
0236 _CLASS_ATTR_STRING(_name, _mode, _str)
0237
0238 extern ssize_t show_class_attr_string(struct class *class, struct class_attribute *attr,
0239 char *buf);
0240
0241 struct class_interface {
0242 struct list_head node;
0243 struct class *class;
0244
0245 int (*add_dev) (struct device *, struct class_interface *);
0246 void (*remove_dev) (struct device *, struct class_interface *);
0247 };
0248
0249 extern int __must_check class_interface_register(struct class_interface *);
0250 extern void class_interface_unregister(struct class_interface *);
0251
0252 extern struct class * __must_check __class_create(struct module *owner,
0253 const char *name,
0254 struct lock_class_key *key);
0255 extern void class_destroy(struct class *cls);
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273 #define class_create(owner, name) \
0274 ({ \
0275 static struct lock_class_key __key; \
0276 __class_create(owner, name, &__key); \
0277 })
0278
0279
0280 #endif