[CONNECTOR]: Update documentation to match reality.
[linux-2.6/verdex.git] / include / linux / kobject.h
blob3b22304f12fd9f542f9a09f10e7bcde9531a9fd7
1 /*
2 * kobject.h - generic kernel object infrastructure.
4 * Copyright (c) 2002-2003 Patrick Mochel
5 * Copyright (c) 2002-2003 Open Source Development Labs
7 * This file is released under the GPLv2.
9 *
10 * Please read Documentation/kobject.txt before using the kobject
11 * interface, ESPECIALLY the parts about reference counts and object
12 * destructors.
15 #ifndef _KOBJECT_H_
16 #define _KOBJECT_H_
18 #ifdef __KERNEL__
20 #include <linux/types.h>
21 #include <linux/list.h>
22 #include <linux/sysfs.h>
23 #include <linux/spinlock.h>
24 #include <linux/rwsem.h>
25 #include <linux/kref.h>
26 #include <linux/kobject_uevent.h>
27 #include <linux/kernel.h>
28 #include <asm/atomic.h>
30 #define KOBJ_NAME_LEN 20
32 /* counter to tag the hotplug event, read only except for the kobject core */
33 extern u64 hotplug_seqnum;
35 struct kobject {
36 const char * k_name;
37 char name[KOBJ_NAME_LEN];
38 struct kref kref;
39 struct list_head entry;
40 struct kobject * parent;
41 struct kset * kset;
42 struct kobj_type * ktype;
43 struct dentry * dentry;
46 extern int kobject_set_name(struct kobject *, const char *, ...)
47 __attribute__((format(printf,2,3)));
49 static inline const char * kobject_name(const struct kobject * kobj)
51 return kobj->k_name;
54 extern void kobject_init(struct kobject *);
55 extern void kobject_cleanup(struct kobject *);
57 extern int kobject_add(struct kobject *);
58 extern void kobject_del(struct kobject *);
60 extern int kobject_rename(struct kobject *, const char *new_name);
62 extern int kobject_register(struct kobject *);
63 extern void kobject_unregister(struct kobject *);
65 extern struct kobject * kobject_get(struct kobject *);
66 extern void kobject_put(struct kobject *);
68 extern char * kobject_get_path(struct kobject *, int);
70 struct kobj_type {
71 void (*release)(struct kobject *);
72 struct sysfs_ops * sysfs_ops;
73 struct attribute ** default_attrs;
77 /**
78 * kset - a set of kobjects of a specific type, belonging
79 * to a specific subsystem.
81 * All kobjects of a kset should be embedded in an identical
82 * type. This type may have a descriptor, which the kset points
83 * to. This allows there to exist sets of objects of the same
84 * type in different subsystems.
86 * A subsystem does not have to be a list of only one type
87 * of object; multiple ksets can belong to one subsystem. All
88 * ksets of a subsystem share the subsystem's lock.
90 * Each kset can support hotplugging; if it does, it will be given
91 * the opportunity to filter out specific kobjects from being
92 * reported, as well as to add its own "data" elements to the
93 * environment being passed to the hotplug helper.
95 struct kset_hotplug_ops {
96 int (*filter)(struct kset *kset, struct kobject *kobj);
97 const char *(*name)(struct kset *kset, struct kobject *kobj);
98 int (*hotplug)(struct kset *kset, struct kobject *kobj, char **envp,
99 int num_envp, char *buffer, int buffer_size);
102 struct kset {
103 struct subsystem * subsys;
104 struct kobj_type * ktype;
105 struct list_head list;
106 spinlock_t list_lock;
107 struct kobject kobj;
108 struct kset_hotplug_ops * hotplug_ops;
112 extern void kset_init(struct kset * k);
113 extern int kset_add(struct kset * k);
114 extern int kset_register(struct kset * k);
115 extern void kset_unregister(struct kset * k);
117 static inline struct kset * to_kset(struct kobject * kobj)
119 return kobj ? container_of(kobj,struct kset,kobj) : NULL;
122 static inline struct kset * kset_get(struct kset * k)
124 return k ? to_kset(kobject_get(&k->kobj)) : NULL;
127 static inline void kset_put(struct kset * k)
129 kobject_put(&k->kobj);
132 static inline struct kobj_type * get_ktype(struct kobject * k)
134 if (k->kset && k->kset->ktype)
135 return k->kset->ktype;
136 else
137 return k->ktype;
140 extern struct kobject * kset_find_obj(struct kset *, const char *);
144 * Use this when initializing an embedded kset with no other
145 * fields to initialize.
147 #define set_kset_name(str) .kset = { .kobj = { .name = str } }
151 struct subsystem {
152 struct kset kset;
153 struct rw_semaphore rwsem;
156 #define decl_subsys(_name,_type,_hotplug_ops) \
157 struct subsystem _name##_subsys = { \
158 .kset = { \
159 .kobj = { .name = __stringify(_name) }, \
160 .ktype = _type, \
161 .hotplug_ops =_hotplug_ops, \
164 #define decl_subsys_name(_varname,_name,_type,_hotplug_ops) \
165 struct subsystem _varname##_subsys = { \
166 .kset = { \
167 .kobj = { .name = __stringify(_name) }, \
168 .ktype = _type, \
169 .hotplug_ops =_hotplug_ops, \
173 /* The global /sys/kernel/ subsystem for people to chain off of */
174 extern struct subsystem kernel_subsys;
177 * Helpers for setting the kset of registered objects.
178 * Often, a registered object belongs to a kset embedded in a
179 * subsystem. These do no magic, just make the resulting code
180 * easier to follow.
184 * kobj_set_kset_s(obj,subsys) - set kset for embedded kobject.
185 * @obj: ptr to some object type.
186 * @subsys: a subsystem object (not a ptr).
188 * Can be used for any object type with an embedded ->kobj.
191 #define kobj_set_kset_s(obj,subsys) \
192 (obj)->kobj.kset = &(subsys).kset
195 * kset_set_kset_s(obj,subsys) - set kset for embedded kset.
196 * @obj: ptr to some object type.
197 * @subsys: a subsystem object (not a ptr).
199 * Can be used for any object type with an embedded ->kset.
200 * Sets the kset of @obj's embedded kobject (via its embedded
201 * kset) to @subsys.kset. This makes @obj a member of that
202 * kset.
205 #define kset_set_kset_s(obj,subsys) \
206 (obj)->kset.kobj.kset = &(subsys).kset
209 * subsys_set_kset(obj,subsys) - set kset for subsystem
210 * @obj: ptr to some object type.
211 * @subsys: a subsystem object (not a ptr).
213 * Can be used for any object type with an embedded ->subsys.
214 * Sets the kset of @obj's kobject to @subsys.kset. This makes
215 * the object a member of that kset.
218 #define subsys_set_kset(obj,_subsys) \
219 (obj)->subsys.kset.kobj.kset = &(_subsys).kset
221 extern void subsystem_init(struct subsystem *);
222 extern int subsystem_register(struct subsystem *);
223 extern void subsystem_unregister(struct subsystem *);
225 static inline struct subsystem * subsys_get(struct subsystem * s)
227 return s ? container_of(kset_get(&s->kset),struct subsystem,kset) : NULL;
230 static inline void subsys_put(struct subsystem * s)
232 kset_put(&s->kset);
235 struct subsys_attribute {
236 struct attribute attr;
237 ssize_t (*show)(struct subsystem *, char *);
238 ssize_t (*store)(struct subsystem *, const char *, size_t);
241 extern int subsys_create_file(struct subsystem * , struct subsys_attribute *);
242 extern void subsys_remove_file(struct subsystem * , struct subsys_attribute *);
244 #ifdef CONFIG_HOTPLUG
245 void kobject_hotplug(struct kobject *kobj, enum kobject_action action);
246 int add_hotplug_env_var(char **envp, int num_envp, int *cur_index,
247 char *buffer, int buffer_size, int *cur_len,
248 const char *format, ...)
249 __attribute__((format (printf, 7, 8)));
250 #else
251 static inline void kobject_hotplug(struct kobject *kobj, enum kobject_action action) { }
252 static inline int add_hotplug_env_var(char **envp, int num_envp, int *cur_index,
253 char *buffer, int buffer_size, int *cur_len,
254 const char *format, ...)
255 { return 0; }
256 #endif
258 #endif /* __KERNEL__ */
259 #endif /* _KOBJECT_H_ */