Blame view

include/linux/kobject.h 6.64 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
34
  
  /* path to the userspace helper executed on an event */
312c004d3   Kay Sievers   [PATCH] driver co...
35
  extern char uevent_helper[];
0296b2281   Kay Sievers   [PATCH] remove CO...
36

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

60a96a595   Kay Sievers   Driver core: acce...
40
41
42
43
44
45
46
47
48
49
  /*
   * 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...
50
  enum kobject_action {
60a96a595   Kay Sievers   Driver core: acce...
51
52
53
54
55
56
57
  	KOBJ_ADD,
  	KOBJ_REMOVE,
  	KOBJ_CHANGE,
  	KOBJ_MOVE,
  	KOBJ_ONLINE,
  	KOBJ_OFFLINE,
  	KOBJ_MAX
0296b2281   Kay Sievers   [PATCH] remove CO...
58
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
59
  struct kobject {
af5ca3f4e   Kay Sievers   Driver core: chan...
60
  	const char		*name;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
61
  	struct list_head	entry;
79a6ee42f   Greg Kroah-Hartman   Kobject: fix codi...
62
63
64
65
  	struct kobject		*parent;
  	struct kset		*kset;
  	struct kobj_type	*ktype;
  	struct sysfs_dirent	*sd;
a231934bd   Richard Kennedy   kobject: reorder ...
66
  	struct kref		kref;
c817a67ec   Russell King   kobject: delayed ...
67
68
69
  #ifdef CONFIG_DEBUG_KOBJECT_RELEASE
  	struct delayed_work	release;
  #endif
0f4dafc05   Kay Sievers   Kobject: auto-cle...
70
  	unsigned int state_initialized:1;
0f4dafc05   Kay Sievers   Kobject: auto-cle...
71
72
73
  	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...
74
  	unsigned int uevent_suppress:1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
75
  };
b9075fa96   Joe Perches   treewide: use __p...
76
77
  extern __printf(2, 3)
  int kobject_set_name(struct kobject *kobj, const char *name, ...);
1fa5ae857   Kay Sievers   driver core: get ...
78
79
  extern int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
  				  va_list vargs);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
80

79a6ee42f   Greg Kroah-Hartman   Kobject: fix codi...
81
  static inline const char *kobject_name(const struct kobject *kobj)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
82
  {
af5ca3f4e   Kay Sievers   Driver core: chan...
83
  	return kobj->name;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
84
  }
f9cb074bf   Greg Kroah-Hartman   Kobject: rename k...
85
  extern void kobject_init(struct kobject *kobj, struct kobj_type *ktype);
b9075fa96   Joe Perches   treewide: use __p...
86
87
88
89
90
91
92
  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...
93

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

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

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

79a6ee42f   Greg Kroah-Hartman   Kobject: fix codi...
105
  extern char *kobject_get_path(struct kobject *kobj, gfp_t flag);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
106
107
  
  struct kobj_type {
79a6ee42f   Greg Kroah-Hartman   Kobject: fix codi...
108
  	void (*release)(struct kobject *kobj);
52cf25d0a   Emese Revfy   Driver core: Cons...
109
  	const struct sysfs_ops *sysfs_ops;
79a6ee42f   Greg Kroah-Hartman   Kobject: fix codi...
110
  	struct attribute **default_attrs;
bc451f205   Eric W. Biederman   kobj: Add basic i...
111
112
  	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
113
  };
7eff2e7a8   Kay Sievers   Driver core: chan...
114
115
116
117
118
119
  struct kobj_uevent_env {
  	char *envp[UEVENT_NUM_ENVP];
  	int envp_idx;
  	char buf[UEVENT_BUFFER_SIZE];
  	int buflen;
  };
a56156489   Randy Dunlap   kset: kernel-doc ...
120
  struct kset_uevent_ops {
9cd43611c   Emese Revfy   kobject: Constify...
121
122
123
  	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...
124
  		      struct kobj_uevent_env *env);
a56156489   Randy Dunlap   kset: kernel-doc ...
125
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
126

23b5212cc   Kay Sievers   Driver Core: add ...
127
128
129
130
131
132
133
  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...
134
  extern const struct sysfs_ops kobj_sysfs_ops;
23b5212cc   Kay Sievers   Driver Core: add ...
135

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

6adf7554b   Greg Kroah-Hartman   kset: add some ke...
138
139
  /**
   * struct kset - a set of kobjects of a specific type, belonging to a specific subsystem.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
140
   *
6adf7554b   Greg Kroah-Hartman   kset: add some ke...
141
142
143
144
145
   * 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
146
   *
6adf7554b   Greg Kroah-Hartman   kset: add some ke...
147
148
149
150
151
152
153
   * @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
154
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
155
  struct kset {
79a6ee42f   Greg Kroah-Hartman   Kobject: fix codi...
156
157
158
  	struct list_head list;
  	spinlock_t list_lock;
  	struct kobject kobj;
9cd43611c   Emese Revfy   kobject: Constify...
159
  	const struct kset_uevent_ops *uevent_ops;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
160
  };
79a6ee42f   Greg Kroah-Hartman   Kobject: fix codi...
161
162
163
  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...
164
  extern struct kset * __must_check kset_create_and_add(const char *name,
9cd43611c   Emese Revfy   kobject: Constify...
165
  						const struct kset_uevent_ops *u,
b727c7028   Greg Kroah-Hartman   kset: add kset_cr...
166
  						struct kobject *parent_kobj);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
167

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

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

542cfce6f   Aneesh Kumar K.V   kobject: kobject_...
197
198
  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...
199
  			char *envp[]);
0296b2281   Kay Sievers   [PATCH] remove CO...
200

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

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