Blame view

include/linux/kobject.h 6.79 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
  /*
   * kobject.h - generic kernel object infrastructure.
   *
f0e7e1bd7   Greg Kroah-Hartman   kobject: update t...
4
5
   * Copyright (c) 2002-2003 Patrick Mochel
   * Copyright (c) 2002-2003 Open Source Development Labs
79a6ee42f   Greg Kroah-Hartman   Kobject: fix codi...
6
7
   * Copyright (c) 2006-2008 Greg Kroah-Hartman <greg@kroah.com>
   * Copyright (c) 2006-2008 Novell Inc.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
8
9
10
   *
   * This file is released under the GPLv2.
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
11
12
   * Please read Documentation/kobject.txt before using the kobject
   * interface, ESPECIALLY the parts about reference counts and object
79a6ee42f   Greg Kroah-Hartman   Kobject: fix codi...
13
   * destructors.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
14
15
16
17
   */
  
  #ifndef _KOBJECT_H_
  #define _KOBJECT_H_
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
18
19
20
  #include <linux/types.h>
  #include <linux/list.h>
  #include <linux/sysfs.h>
4a7fb6363   Andrew Morton   add __must_check ...
21
  #include <linux/compiler.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
22
  #include <linux/spinlock.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
23
  #include <linux/kref.h>
8488a38f4   David Howells   kobject: Break th...
24
  #include <linux/kobject_ns.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
25
  #include <linux/kernel.h>
4508a7a73   NeilBrown   [PATCH] sysfs: Al...
26
  #include <linux/wait.h>
60063497a   Arun Sharma   atomic: use <linu...
27
  #include <linux/atomic.h>
c817a67ec   Russell King   kobject: delayed ...
28
  #include <linux/workqueue.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29

312c004d3   Kay Sievers   [PATCH] driver co...
30
  #define UEVENT_HELPER_PATH_LEN		256
7eff2e7a8   Kay Sievers   Driver core: chan...
31
32
  #define UEVENT_NUM_ENVP			32	/* number of env pointers */
  #define UEVENT_BUFFER_SIZE		2048	/* buffer for the variables */
0296b2281   Kay Sievers   [PATCH] remove CO...
33

86d56134f   Michael Marineau   kobject: Make sup...
34
  #ifdef CONFIG_UEVENT_HELPER
0296b2281   Kay Sievers   [PATCH] remove CO...
35
  /* path to the userspace helper executed on an event */
312c004d3   Kay Sievers   [PATCH] driver co...
36
  extern char uevent_helper[];
86d56134f   Michael Marineau   kobject: Make sup...
37
  #endif
0296b2281   Kay Sievers   [PATCH] remove CO...
38

312c004d3   Kay Sievers   [PATCH] driver co...
39
40
  /* counter to tag the uevent, read only except for the kobject core */
  extern u64 uevent_seqnum;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
41

60a96a595   Kay Sievers   Driver core: acce...
42
43
44
45
46
47
48
49
50
51
  /*
   * The actions here must match the index to the string array
   * in lib/kobject_uevent.c
   *
   * Do not add new actions here without checking with the driver-core
   * maintainers. Action strings are not meant to express subsystem
   * or device specific properties. In most cases you want to send a
   * kobject_uevent_env(kobj, KOBJ_CHANGE, env) with additional event
   * specific variables added to the event environment.
   */
0296b2281   Kay Sievers   [PATCH] remove CO...
52
  enum kobject_action {
60a96a595   Kay Sievers   Driver core: acce...
53
54
55
56
57
58
59
  	KOBJ_ADD,
  	KOBJ_REMOVE,
  	KOBJ_CHANGE,
  	KOBJ_MOVE,
  	KOBJ_ONLINE,
  	KOBJ_OFFLINE,
  	KOBJ_MAX
0296b2281   Kay Sievers   [PATCH] remove CO...
60
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
61
  struct kobject {
af5ca3f4e   Kay Sievers   Driver core: chan...
62
  	const char		*name;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
63
  	struct list_head	entry;
79a6ee42f   Greg Kroah-Hartman   Kobject: fix codi...
64
65
66
  	struct kobject		*parent;
  	struct kset		*kset;
  	struct kobj_type	*ktype;
f7025709e   Ulf Magnusson   kobject: explain ...
67
  	struct kernfs_node	*sd; /* sysfs directory entry */
a231934bd   Richard Kennedy   kobject: reorder ...
68
  	struct kref		kref;
c817a67ec   Russell King   kobject: delayed ...
69
70
71
  #ifdef CONFIG_DEBUG_KOBJECT_RELEASE
  	struct delayed_work	release;
  #endif
0f4dafc05   Kay Sievers   Kobject: auto-cle...
72
  	unsigned int state_initialized:1;
0f4dafc05   Kay Sievers   Kobject: auto-cle...
73
74
75
  	unsigned int state_in_sysfs:1;
  	unsigned int state_add_uevent_sent:1;
  	unsigned int state_remove_uevent_sent:1;
f67f129e5   Ming Lei   Driver core: impl...
76
  	unsigned int uevent_suppress:1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
77
  };
b9075fa96   Joe Perches   treewide: use __p...
78
79
  extern __printf(2, 3)
  int kobject_set_name(struct kobject *kobj, const char *name, ...);
8db148606   Nicolas Iooss   include, lib: add...
80
81
82
  extern __printf(2, 0)
  int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
  			   va_list vargs);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
83

79a6ee42f   Greg Kroah-Hartman   Kobject: fix codi...
84
  static inline const char *kobject_name(const struct kobject *kobj)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
85
  {
af5ca3f4e   Kay Sievers   Driver core: chan...
86
  	return kobj->name;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
87
  }
f9cb074bf   Greg Kroah-Hartman   Kobject: rename k...
88
  extern void kobject_init(struct kobject *kobj, struct kobj_type *ktype);
b9075fa96   Joe Perches   treewide: use __p...
89
90
91
92
93
94
95
  extern __printf(3, 4) __must_check
  int kobject_add(struct kobject *kobj, struct kobject *parent,
  		const char *fmt, ...);
  extern __printf(4, 5) __must_check
  int kobject_init_and_add(struct kobject *kobj,
  			 struct kobj_type *ktype, struct kobject *parent,
  			 const char *fmt, ...);
c11c4154e   Greg Kroah-Hartman   kobject: add kobj...
96

79a6ee42f   Greg Kroah-Hartman   Kobject: fix codi...
97
  extern void kobject_del(struct kobject *kobj);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
98

43968d2f1   Greg Kroah-Hartman   kobject: get rid ...
99
  extern struct kobject * __must_check kobject_create(void);
3f9e3ee9d   Greg Kroah-Hartman   kobject: add kobj...
100
101
  extern struct kobject * __must_check kobject_create_and_add(const char *name,
  						struct kobject *parent);
4a7fb6363   Andrew Morton   add __must_check ...
102
  extern int __must_check kobject_rename(struct kobject *, const char *new_name);
8a82472f8   Cornelia Huck   driver core: Intr...
103
  extern int __must_check kobject_move(struct kobject *, struct kobject *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
104

79a6ee42f   Greg Kroah-Hartman   Kobject: fix codi...
105
106
  extern struct kobject *kobject_get(struct kobject *kobj);
  extern void kobject_put(struct kobject *kobj);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
107

e34ff4906   Tejun Heo   sysfs: remove kty...
108
  extern const void *kobject_namespace(struct kobject *kobj);
79a6ee42f   Greg Kroah-Hartman   Kobject: fix codi...
109
  extern char *kobject_get_path(struct kobject *kobj, gfp_t flag);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
110
111
  
  struct kobj_type {
79a6ee42f   Greg Kroah-Hartman   Kobject: fix codi...
112
  	void (*release)(struct kobject *kobj);
52cf25d0a   Emese Revfy   Driver core: Cons...
113
  	const struct sysfs_ops *sysfs_ops;
79a6ee42f   Greg Kroah-Hartman   Kobject: fix codi...
114
  	struct attribute **default_attrs;
bc451f205   Eric W. Biederman   kobj: Add basic i...
115
116
  	const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
  	const void *(*namespace)(struct kobject *kobj);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
117
  };
7eff2e7a8   Kay Sievers   Driver core: chan...
118
  struct kobj_uevent_env {
bcccff93a   Vladimir Davydov   kobject: don't bl...
119
  	char *argv[3];
7eff2e7a8   Kay Sievers   Driver core: chan...
120
121
122
123
124
  	char *envp[UEVENT_NUM_ENVP];
  	int envp_idx;
  	char buf[UEVENT_BUFFER_SIZE];
  	int buflen;
  };
a56156489   Randy Dunlap   kset: kernel-doc ...
125
  struct kset_uevent_ops {
9cd43611c   Emese Revfy   kobject: Constify...
126
127
128
  	int (* const filter)(struct kset *kset, struct kobject *kobj);
  	const char *(* const name)(struct kset *kset, struct kobject *kobj);
  	int (* const uevent)(struct kset *kset, struct kobject *kobj,
7eff2e7a8   Kay Sievers   Driver core: chan...
129
  		      struct kobj_uevent_env *env);
a56156489   Randy Dunlap   kset: kernel-doc ...
130
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
131

23b5212cc   Kay Sievers   Driver Core: add ...
132
133
134
135
136
137
138
  struct kobj_attribute {
  	struct attribute attr;
  	ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr,
  			char *buf);
  	ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
  			 const char *buf, size_t count);
  };
52cf25d0a   Emese Revfy   Driver core: Cons...
139
  extern const struct sysfs_ops kobj_sysfs_ops;
23b5212cc   Kay Sievers   Driver Core: add ...
140

bc451f205   Eric W. Biederman   kobj: Add basic i...
141
  struct sock;
be867b194   Serge E. Hallyn   sysfs: Comment sy...
142

6adf7554b   Greg Kroah-Hartman   kset: add some ke...
143
144
  /**
   * struct kset - a set of kobjects of a specific type, belonging to a specific subsystem.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
145
   *
6adf7554b   Greg Kroah-Hartman   kset: add some ke...
146
147
148
149
150
   * A kset defines a group of kobjects.  They can be individually
   * different "types" but overall these kobjects all want to be grouped
   * together and operated on in the same manner.  ksets are used to
   * define the attribute callbacks and other common events that happen to
   * a kobject.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
151
   *
6adf7554b   Greg Kroah-Hartman   kset: add some ke...
152
153
154
155
156
157
158
   * @list: the list of all kobjects for this kset
   * @list_lock: a lock for iterating over the kobjects
   * @kobj: the embedded kobject for this kset (recursion, isn't it fun...)
   * @uevent_ops: the set of uevent operations for this kset.  These are
   * called whenever a kobject has something happen to it so that the kset
   * can add new environment variables, or filter out the uevents if so
   * desired.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
159
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
160
  struct kset {
79a6ee42f   Greg Kroah-Hartman   Kobject: fix codi...
161
162
163
  	struct list_head list;
  	spinlock_t list_lock;
  	struct kobject kobj;
9cd43611c   Emese Revfy   kobject: Constify...
164
  	const struct kset_uevent_ops *uevent_ops;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
165
  };
79a6ee42f   Greg Kroah-Hartman   Kobject: fix codi...
166
167
168
  extern void kset_init(struct kset *kset);
  extern int __must_check kset_register(struct kset *kset);
  extern void kset_unregister(struct kset *kset);
b727c7028   Greg Kroah-Hartman   kset: add kset_cr...
169
  extern struct kset * __must_check kset_create_and_add(const char *name,
9cd43611c   Emese Revfy   kobject: Constify...
170
  						const struct kset_uevent_ops *u,
b727c7028   Greg Kroah-Hartman   kset: add kset_cr...
171
  						struct kobject *parent_kobj);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
172

79a6ee42f   Greg Kroah-Hartman   Kobject: fix codi...
173
  static inline struct kset *to_kset(struct kobject *kobj)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
174
  {
79a6ee42f   Greg Kroah-Hartman   Kobject: fix codi...
175
  	return kobj ? container_of(kobj, struct kset, kobj) : NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
176
  }
79a6ee42f   Greg Kroah-Hartman   Kobject: fix codi...
177
  static inline struct kset *kset_get(struct kset *k)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
178
179
180
  {
  	return k ? to_kset(kobject_get(&k->kobj)) : NULL;
  }
79a6ee42f   Greg Kroah-Hartman   Kobject: fix codi...
181
  static inline void kset_put(struct kset *k)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
182
183
184
  {
  	kobject_put(&k->kobj);
  }
3514faca1   Greg Kroah-Hartman   kobject: remove s...
185
  static inline struct kobj_type *get_ktype(struct kobject *kobj)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
186
  {
3514faca1   Greg Kroah-Hartman   kobject: remove s...
187
  	return kobj->ktype;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
188
  }
79a6ee42f   Greg Kroah-Hartman   Kobject: fix codi...
189
  extern struct kobject *kset_find_obj(struct kset *, const char *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
190

0ff21e466   Greg Kroah-Hartman   kobject: convert ...
191
192
  /* The global /sys/kernel/ kobject for people to chain off of */
  extern struct kobject *kernel_kobj;
ff7ea79cf   Nishanth Aravamudan   mm: create /sys/k...
193
194
  /* The global /sys/kernel/mm/ kobject for people to chain off of */
  extern struct kobject *mm_kobj;
2d72fc00a   Greg Kroah-Hartman   kobject: convert ...
195
196
  /* The global /sys/hypervisor/ kobject for people to chain off of */
  extern struct kobject *hypervisor_kobj;
d76e15fb2   Greg Kroah-Hartman   driver core: make...
197
198
  /* The global /sys/power/ kobject for people to chain off of */
  extern struct kobject *power_kobj;
f62ed9e33   Greg Kroah-Hartman   firmware: change ...
199
200
  /* The global /sys/firmware/ kobject for people to chain off of */
  extern struct kobject *firmware_kobj;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
201

542cfce6f   Aneesh Kumar K.V   kobject: kobject_...
202
203
  int kobject_uevent(struct kobject *kobj, enum kobject_action action);
  int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
8a82472f8   Cornelia Huck   driver core: Intr...
204
  			char *envp[]);
0296b2281   Kay Sievers   [PATCH] remove CO...
205

b9075fa96   Joe Perches   treewide: use __p...
206
207
  __printf(2, 3)
  int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...);
5c5daf657   Kay Sievers   Driver core: excl...
208
209
210
  
  int kobject_action_type(const char *buf, size_t count,
  			enum kobject_action *type);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
211

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
212
  #endif /* _KOBJECT_H_ */