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/sysfs.h>
24 #include <linux/types.h>
25 #include <linux/workqueue.h>
30 void (*release)(struct kobject *kobj);
31 const struct sysfs_ops *sysfs_ops;
32 const struct attribute_group **default_groups;
33 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
34 const void *(*namespace)(struct kobject *kobj);
37 struct kobj_uevent_env {
40 struct kobj_attribute {
41 struct attribute attr;
42 ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr,
44 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
45 const char *buf, size_t count);
49 struct kobject *parent;
51 const struct kobj_type *ktype;
52 struct kernfs_node *sd; /* sysfs directory entry */
54 unsigned int state_initialized:1;
55 unsigned int state_in_sysfs:1;
56 unsigned int state_add_uevent_sent:1;
57 unsigned int state_remove_uevent_sent:1;
58 unsigned int uevent_suppress:1;
65 #define kobject_add(...) 0
67 static inline void kobject_init(struct kobject *kobj, const struct kobj_type *ktype)
69 memset(kobj, 0, sizeof(*kobj));
71 atomic_set(&kobj->ref, 1);
73 kobj->state_initialized = 1;
76 static inline void kobject_del(struct kobject *kobj);
78 static inline void kobject_cleanup(struct kobject *kobj)
80 const struct kobj_type *t = kobj->ktype;
82 /* remove from sysfs if the caller did not do it */
83 if (kobj->state_in_sysfs)
90 static inline void kobject_put(struct kobject *kobj)
93 BUG_ON(!kobj->state_initialized);
95 if (atomic_dec_and_test(&kobj->ref))
96 kobject_cleanup(kobj);
99 static inline void kobject_del(struct kobject *kobj)
104 kobj->state_in_sysfs = 0;
106 kobj_kset_leave(kobj);
108 kobject_put(kobj->parent);
112 static inline struct kobject *kobject_get(struct kobject *kobj)
115 BUG_ON(!kobj->state_initialized);
117 atomic_inc(&kobj->ref);
121 static inline void kset_unregister(struct kset *kset)
126 #define kset_create_and_add(_name, _u, _parent) \
127 ((struct kset *) kzalloc(sizeof(struct kset), GFP_KERNEL))
129 #endif /* _KOBJECT_H_ */