2 * Copyright (c) 2010 Isilon Systems, Inc.
3 * Copyright (c) 2010 iX Systems, Inc.
4 * Copyright (c) 2010 Panasas, Inc.
5 * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice unmodified, this list of conditions, and the following
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef _LINUX_KOBJECT_H_
32 #define _LINUX_KOBJECT_H_
34 #include <machine/stdarg.h>
36 #include <linux/kernel.h>
37 #include <linux/kref.h>
38 #include <linux/slab.h>
44 void (*release)(struct kobject *kobj);
45 const struct sysfs_ops *sysfs_ops;
46 struct attribute **default_attrs;
49 extern const struct kobj_type linux_kfree_type;
52 struct kobject *parent;
55 const struct kobj_type *ktype;
56 struct list_head entry;
57 struct sysctl_oid *oidp;
60 extern struct kobject *mm_kobj;
68 struct kobj_attribute {
69 struct attribute attr;
70 ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr,
72 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
73 const char *buf, size_t count);
77 kobject_init(struct kobject *kobj, const struct kobj_type *ktype)
80 kref_init(&kobj->kref);
81 INIT_LIST_HEAD(&kobj->entry);
86 void linux_kobject_release(struct kref *kref);
89 kobject_put(struct kobject *kobj)
93 kref_put(&kobj->kref, linux_kobject_release);
96 static inline struct kobject *
97 kobject_get(struct kobject *kobj)
101 kref_get(&kobj->kref);
105 int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, va_list);
106 int kobject_add(struct kobject *kobj, struct kobject *parent,
107 const char *fmt, ...);
109 static inline struct kobject *
112 struct kobject *kobj;
114 kobj = kzalloc(sizeof(*kobj), GFP_KERNEL);
117 kobject_init(kobj, &linux_kfree_type);
122 static inline struct kobject *
123 kobject_create_and_add(const char *name, struct kobject *parent)
125 struct kobject *kobj;
127 kobj = kobject_create();
130 if (kobject_add(kobj, parent, "%s", name) == 0)
138 kobject_name(const struct kobject *kobj)
144 int kobject_set_name(struct kobject *kobj, const char *fmt, ...);
145 int kobject_init_and_add(struct kobject *kobj, const struct kobj_type *ktype,
146 struct kobject *parent, const char *fmt, ...);
148 #endif /* _LINUX_KOBJECT_H_ */