1 | #ifndef _LINUX_KOBJECT_H
|
---|
2 | #define _LINUX_KOBJECT_H
|
---|
3 |
|
---|
4 | #include <linux/types.h>
|
---|
5 | #include <linux/list.h>
|
---|
6 | #include <linux/kref.h>
|
---|
7 | #include <linux/kobject_ns.h>
|
---|
8 | #include <linux/kernel.h>
|
---|
9 |
|
---|
10 | /*
|
---|
11 | * The actions here must match the index to the string array
|
---|
12 | * in lib/kobject_uevent.c
|
---|
13 | *
|
---|
14 | * Do not add new actions here without checking with the driver-core
|
---|
15 | * maintainers. Action strings are not meant to express subsystem
|
---|
16 | * or device specific properties. In most cases you want to send a
|
---|
17 | * kobject_uevent_env(kobj, KOBJ_CHANGE, env) with additional event
|
---|
18 | * specific variables added to the event environment.
|
---|
19 | */
|
---|
20 | enum kobject_action {
|
---|
21 | KOBJ_ADD,
|
---|
22 | KOBJ_REMOVE,
|
---|
23 | KOBJ_CHANGE,
|
---|
24 | KOBJ_MOVE,
|
---|
25 | KOBJ_ONLINE,
|
---|
26 | KOBJ_OFFLINE,
|
---|
27 | KOBJ_MAX
|
---|
28 | };
|
---|
29 |
|
---|
30 | struct kobject {
|
---|
31 | const char *name;
|
---|
32 | struct list_head entry;
|
---|
33 | struct kobject *parent;
|
---|
34 | struct kset *kset;
|
---|
35 | struct kobj_type *ktype;
|
---|
36 | struct kernfs_node *sd;
|
---|
37 | struct kref kref;
|
---|
38 | #ifdef CONFIG_DEBUG_KOBJECT_RELEASE
|
---|
39 | struct delayed_work release;
|
---|
40 | #endif
|
---|
41 | unsigned int state_initialized:1;
|
---|
42 | unsigned int state_in_sysfs:1;
|
---|
43 | unsigned int state_add_uevent_sent:1;
|
---|
44 | unsigned int state_remove_uevent_sent:1;
|
---|
45 | unsigned int uevent_suppress:1;
|
---|
46 | };
|
---|
47 |
|
---|
48 | extern int kobject_set_name(struct kobject *kobj, const char *name, ...);
|
---|
49 | extern int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
|
---|
50 | va_list vargs);
|
---|
51 |
|
---|
52 | static inline const char *kobject_name(const struct kobject *kobj)
|
---|
53 | {
|
---|
54 | return kobj->name;
|
---|
55 | }
|
---|
56 |
|
---|
57 | extern void kobject_init(struct kobject *kobj, struct kobj_type *ktype);
|
---|
58 | extern struct kobject *kobject_get(struct kobject *kobj);
|
---|
59 | extern void kobject_put(struct kobject *kobj);
|
---|
60 |
|
---|
61 | struct kobj_type {
|
---|
62 | void (*release)(struct kobject *kobj);
|
---|
63 | const struct sysfs_ops *sysfs_ops;
|
---|
64 | struct attribute **default_attrs;
|
---|
65 | const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
|
---|
66 | const void *(*namespace)(struct kobject *kobj);
|
---|
67 | };
|
---|
68 |
|
---|
69 | struct kset_uevent_ops {
|
---|
70 | int (* const filter)(struct kset *kset, struct kobject *kobj);
|
---|
71 | const char *(* const name)(struct kset *kset, struct kobject *kobj);
|
---|
72 | int (* const uevent)(struct kset *kset, struct kobject *kobj,
|
---|
73 | struct kobj_uevent_env *env);
|
---|
74 | };
|
---|
75 |
|
---|
76 | static inline struct kobj_type *get_ktype(struct kobject *kobj)
|
---|
77 | {
|
---|
78 | return kobj->ktype;
|
---|
79 | }
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * struct kset - a set of kobjects of a specific type, belonging to a specific subsystem.
|
---|
83 | *
|
---|
84 | * A kset defines a group of kobjects. They can be individually
|
---|
85 | * different "types" but overall these kobjects all want to be grouped
|
---|
86 | * together and operated on in the same manner. ksets are used to
|
---|
87 | * define the attribute callbacks and other common events that happen to
|
---|
88 | * a kobject.
|
---|
89 | *
|
---|
90 | * @list: the list of all kobjects for this kset
|
---|
91 | * @list_lock: a lock for iterating over the kobjects
|
---|
92 | * @kobj: the embedded kobject for this kset (recursion, isn't it fun...)
|
---|
93 | * @uevent_ops: the set of uevent operations for this kset. These are
|
---|
94 | * called whenever a kobject has something happen to it so that the kset
|
---|
95 | * can add new environment variables, or filter out the uevents if so
|
---|
96 | * desired.
|
---|
97 | */
|
---|
98 | struct kset {
|
---|
99 | struct list_head list;
|
---|
100 | spinlock_t list_lock;
|
---|
101 | struct kobject kobj;
|
---|
102 | const struct kset_uevent_ops *uevent_ops;
|
---|
103 | };
|
---|
104 |
|
---|
105 | extern int kset_register(struct kset *kset);
|
---|
106 | extern void kset_unregister(struct kset *kset);
|
---|
107 | extern struct kset * kset_create_and_add(const char *name,
|
---|
108 | const struct kset_uevent_ops *u,
|
---|
109 | struct kobject *parent_kobj);
|
---|
110 |
|
---|
111 | static inline struct kset *to_kset(struct kobject *kobj)
|
---|
112 | {
|
---|
113 | return kobj ? container_of(kobj, struct kset, kobj) : NULL;
|
---|
114 | }
|
---|
115 |
|
---|
116 | static inline struct kset *kset_get(struct kset *k)
|
---|
117 | {
|
---|
118 | return k ? to_kset(kobject_get(&k->kobj)) : NULL;
|
---|
119 | }
|
---|
120 |
|
---|
121 | static inline void kset_put(struct kset *k)
|
---|
122 | {
|
---|
123 | kobject_put(&k->kobj);
|
---|
124 | }
|
---|
125 |
|
---|
126 | static inline int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...) { return 0;}
|
---|
127 |
|
---|
128 | extern int kobject_init_and_add(struct kobject *kobj,
|
---|
129 | struct kobj_type *ktype, struct kobject *parent,
|
---|
130 | const char *fmt, ...);
|
---|
131 |
|
---|
132 | extern void kobject_del(struct kobject *kobj);
|
---|
133 | extern struct kobject *kset_find_obj(struct kset *, const char *);
|
---|
134 | extern struct kobject *kset_find_obj_hinted(struct kset *, const char *,
|
---|
135 | struct kobject *);
|
---|
136 |
|
---|
137 | #endif /* _LINUX_KOBJECT_H */
|
---|