2 * kobject.h - generic kernel object infrastructure.
4 * Copyright (c) 2002-2003 Patrick Mochel
5 * Copyright (c) 2002-2003 Open Source Development Labs
6 * Copyright (c) 2006-2008 Greg Kroah-Hartman <greg@kroah.com>
7 * Copyright (c) 2006-2008 Novell Inc.
9 * This file is released under the GPLv2.
11 * Please read Documentation/kobject.txt before using the kobject
12 * interface, ESPECIALLY the parts about reference counts and object
19 #include <linux/atomic.h>
20 #include <linux/bug.h>
21 #include <linux/compiler.h>
22 #include <linux/kernel.h>
23 #include <linux/kref.h>
24 #include <linux/sysfs.h>
25 #include <linux/types.h>
26 #include <linux/wait.h>
27 #include <linux/workqueue.h>
32 void (*release)(struct kobject *kobj);
33 const struct sysfs_ops *sysfs_ops;
34 struct attribute **default_attrs;
35 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
36 const void *(*namespace)(struct kobject *kobj);
39 struct kobj_uevent_env {
42 struct kobj_attribute {
43 struct attribute attr;
44 ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr,
46 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
47 const char *buf, size_t count);
51 struct kobject *parent;
53 struct kobj_type *ktype;
54 struct kernfs_node *sd; /* sysfs directory entry */
56 unsigned int state_initialized:1;
57 unsigned int state_in_sysfs:1;
58 unsigned int state_add_uevent_sent:1;
59 unsigned int state_remove_uevent_sent:1;
60 unsigned int uevent_suppress:1;
67 static inline struct kobj_type *get_ktype(struct kobject *kobj)
72 #define kobject_add(...) 0
74 static inline void kobject_init(struct kobject *kobj, struct kobj_type *ktype)
76 memset(kobj, 0, sizeof(*kobj));
78 kref_init(&kobj->kref);
80 kobj->state_initialized = 1;
83 static inline void kobject_del(struct kobject *kobj);
85 static inline void kobject_cleanup(struct kobject *kobj)
87 struct kobj_type *t = get_ktype(kobj);
89 /* remove from sysfs if the caller did not do it */
90 if (kobj->state_in_sysfs)
97 static inline void kobject_release(struct kref *kref)
99 struct kobject *kobj = container_of(kref, struct kobject, kref);
101 kobject_cleanup(kobj);
104 static inline void kobject_put(struct kobject *kobj)
107 BUG_ON(!kobj->state_initialized);
109 kref_put(&kobj->kref, kobject_release);
112 static inline void kobject_del(struct kobject *kobj)
114 struct kernfs_node *sd;
120 kobj->state_in_sysfs = 0;
122 kobj_kset_leave(kobj);
124 kobject_put(kobj->parent);
128 static inline struct kobject *kobject_get(struct kobject *kobj)
131 BUG_ON(!kobj->state_initialized);
133 kref_get(&kobj->kref);
137 static inline void kset_unregister(struct kset *kset) {}
139 #define kset_create_and_add(_name, _u, _parent) \
140 ((struct kset *) kzalloc(sizeof(struct kset), GFP_KERNEL))
142 #endif /* _KOBJECT_H_ */