1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef _DEVICE_CLASS_H_
15#define _DEVICE_CLASS_H_
16
17#include <linux/kobject.h>
18#include <linux/klist.h>
19#include <linux/pm.h>
20#include <linux/device/bus.h>
21
22struct device;
23struct fwnode_handle;
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54struct class {
55 const char *name;
56 struct module *owner;
57
58 const struct attribute_group **class_groups;
59 const struct attribute_group **dev_groups;
60 struct kobject *dev_kobj;
61
62 int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env);
63 char *(*devnode)(struct device *dev, umode_t *mode);
64
65 void (*class_release)(struct class *class);
66 void (*dev_release)(struct device *dev);
67
68 int (*shutdown_pre)(struct device *dev);
69
70 const struct kobj_ns_type_operations *ns_type;
71 const void *(*namespace)(struct device *dev);
72
73 void (*get_ownership)(struct device *dev, kuid_t *uid, kgid_t *gid);
74
75 const struct dev_pm_ops *pm;
76
77 struct subsys_private *p;
78};
79
80struct class_dev_iter {
81 struct klist_iter ki;
82 const struct device_type *type;
83};
84
85extern struct kobject *sysfs_dev_block_kobj;
86extern struct kobject *sysfs_dev_char_kobj;
87extern int __must_check __class_register(struct class *class,
88 struct lock_class_key *key);
89extern void class_unregister(struct class *class);
90
91
92
93#define class_register(class) \
94({ \
95 static struct lock_class_key __key; \
96 __class_register(class, &__key); \
97})
98
99struct class_compat;
100struct class_compat *class_compat_register(const char *name);
101void class_compat_unregister(struct class_compat *cls);
102int class_compat_create_link(struct class_compat *cls, struct device *dev,
103 struct device *device_link);
104void class_compat_remove_link(struct class_compat *cls, struct device *dev,
105 struct device *device_link);
106
107extern void class_dev_iter_init(struct class_dev_iter *iter,
108 struct class *class,
109 struct device *start,
110 const struct device_type *type);
111extern struct device *class_dev_iter_next(struct class_dev_iter *iter);
112extern void class_dev_iter_exit(struct class_dev_iter *iter);
113
114extern int class_for_each_device(struct class *class, struct device *start,
115 void *data,
116 int (*fn)(struct device *dev, void *data));
117extern struct device *class_find_device(struct class *class,
118 struct device *start, const void *data,
119 int (*match)(struct device *, const void *));
120
121
122
123
124
125
126
127static inline struct device *class_find_device_by_name(struct class *class,
128 const char *name)
129{
130 return class_find_device(class, NULL, name, device_match_name);
131}
132
133
134
135
136
137
138
139static inline struct device *
140class_find_device_by_of_node(struct class *class, const struct device_node *np)
141{
142 return class_find_device(class, NULL, np, device_match_of_node);
143}
144
145
146
147
148
149
150
151static inline struct device *
152class_find_device_by_fwnode(struct class *class,
153 const struct fwnode_handle *fwnode)
154{
155 return class_find_device(class, NULL, fwnode, device_match_fwnode);
156}
157
158
159
160
161
162
163
164static inline struct device *class_find_device_by_devt(struct class *class,
165 dev_t devt)
166{
167 return class_find_device(class, NULL, &devt, device_match_devt);
168}
169
170#ifdef CONFIG_ACPI
171struct acpi_device;
172
173
174
175
176
177
178static inline struct device *
179class_find_device_by_acpi_dev(struct class *class, const struct acpi_device *adev)
180{
181 return class_find_device(class, NULL, adev, device_match_acpi_dev);
182}
183#else
184static inline struct device *
185class_find_device_by_acpi_dev(struct class *class, const void *adev)
186{
187 return NULL;
188}
189#endif
190
191struct class_attribute {
192 struct attribute attr;
193 ssize_t (*show)(struct class *class, struct class_attribute *attr,
194 char *buf);
195 ssize_t (*store)(struct class *class, struct class_attribute *attr,
196 const char *buf, size_t count);
197};
198
199#define CLASS_ATTR_RW(_name) \
200 struct class_attribute class_attr_##_name = __ATTR_RW(_name)
201#define CLASS_ATTR_RO(_name) \
202 struct class_attribute class_attr_##_name = __ATTR_RO(_name)
203#define CLASS_ATTR_WO(_name) \
204 struct class_attribute class_attr_##_name = __ATTR_WO(_name)
205
206extern int __must_check class_create_file_ns(struct class *class,
207 const struct class_attribute *attr,
208 const void *ns);
209extern void class_remove_file_ns(struct class *class,
210 const struct class_attribute *attr,
211 const void *ns);
212
213static inline int __must_check class_create_file(struct class *class,
214 const struct class_attribute *attr)
215{
216 return class_create_file_ns(class, attr, NULL);
217}
218
219static inline void class_remove_file(struct class *class,
220 const struct class_attribute *attr)
221{
222 return class_remove_file_ns(class, attr, NULL);
223}
224
225
226struct class_attribute_string {
227 struct class_attribute attr;
228 char *str;
229};
230
231
232#define _CLASS_ATTR_STRING(_name, _mode, _str) \
233 { __ATTR(_name, _mode, show_class_attr_string, NULL), _str }
234#define CLASS_ATTR_STRING(_name, _mode, _str) \
235 struct class_attribute_string class_attr_##_name = \
236 _CLASS_ATTR_STRING(_name, _mode, _str)
237
238extern ssize_t show_class_attr_string(struct class *class, struct class_attribute *attr,
239 char *buf);
240
241struct class_interface {
242 struct list_head node;
243 struct class *class;
244
245 int (*add_dev) (struct device *, struct class_interface *);
246 void (*remove_dev) (struct device *, struct class_interface *);
247};
248
249extern int __must_check class_interface_register(struct class_interface *);
250extern void class_interface_unregister(struct class_interface *);
251
252extern struct class * __must_check __class_create(struct module *owner,
253 const char *name,
254 struct lock_class_key *key);
255extern void class_destroy(struct class *cls);
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273#define class_create(owner, name) \
274({ \
275 static struct lock_class_key __key; \
276 __class_create(owner, name, &__key); \
277})
278
279
280#endif
281