xref: /dflybsd-src/sys/dev/drm/include/linux/kobject.h (revision 15dba7a934ccec493b5479b70a07107f7689c597)
11b7db0e0SFrançois Tigeot /*
2*15dba7a9SFrançois Tigeot  * Copyright (c) 2016-2018 François Tigeot <ftigeot@wolfpond.org>
31b7db0e0SFrançois Tigeot  * All rights reserved.
41b7db0e0SFrançois Tigeot  *
51b7db0e0SFrançois Tigeot  * Redistribution and use in source and binary forms, with or without
61b7db0e0SFrançois Tigeot  * modification, are permitted provided that the following conditions
71b7db0e0SFrançois Tigeot  * are met:
81b7db0e0SFrançois Tigeot  * 1. Redistributions of source code must retain the above copyright
91b7db0e0SFrançois Tigeot  *    notice unmodified, this list of conditions, and the following
101b7db0e0SFrançois Tigeot  *    disclaimer.
111b7db0e0SFrançois Tigeot  * 2. Redistributions in binary form must reproduce the above copyright
121b7db0e0SFrançois Tigeot  *    notice, this list of conditions and the following disclaimer in the
131b7db0e0SFrançois Tigeot  *    documentation and/or other materials provided with the distribution.
141b7db0e0SFrançois Tigeot  *
151b7db0e0SFrançois Tigeot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
161b7db0e0SFrançois Tigeot  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
171b7db0e0SFrançois Tigeot  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
181b7db0e0SFrançois Tigeot  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
191b7db0e0SFrançois Tigeot  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
201b7db0e0SFrançois Tigeot  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
211b7db0e0SFrançois Tigeot  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
221b7db0e0SFrançois Tigeot  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
231b7db0e0SFrançois Tigeot  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
241b7db0e0SFrançois Tigeot  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
251b7db0e0SFrançois Tigeot  */
261b7db0e0SFrançois Tigeot 
271b7db0e0SFrançois Tigeot #ifndef _LINUX_KOBJECT_H_
281b7db0e0SFrançois Tigeot #define _LINUX_KOBJECT_H_
291b7db0e0SFrançois Tigeot 
301b7db0e0SFrançois Tigeot #include <linux/types.h>
311b7db0e0SFrançois Tigeot #include <linux/list.h>
32*15dba7a9SFrançois Tigeot #include <linux/sysfs.h>
331b7db0e0SFrançois Tigeot #include <linux/compiler.h>
341b7db0e0SFrançois Tigeot #include <linux/spinlock.h>
351b7db0e0SFrançois Tigeot #include <linux/kref.h>
361b7db0e0SFrançois Tigeot #include <linux/kernel.h>
371b7db0e0SFrançois Tigeot #include <linux/wait.h>
381b7db0e0SFrançois Tigeot #include <linux/atomic.h>
39c30871e1SFrançois Tigeot 
40c30871e1SFrançois Tigeot enum kobject_action {
41c30871e1SFrançois Tigeot 	KOBJ_ADD,
42c30871e1SFrançois Tigeot 	KOBJ_REMOVE,
43c30871e1SFrançois Tigeot 	KOBJ_CHANGE,
44c30871e1SFrançois Tigeot 	KOBJ_MOVE,
45c30871e1SFrançois Tigeot 	KOBJ_ONLINE,
46c30871e1SFrançois Tigeot 	KOBJ_OFFLINE,
47c30871e1SFrançois Tigeot 	KOBJ_MAX
48c30871e1SFrançois Tigeot };
491b7db0e0SFrançois Tigeot 
501b7db0e0SFrançois Tigeot struct kobject {
5139cfddd2SFrançois Tigeot 	const char *name;
52*15dba7a9SFrançois Tigeot 	struct kref kref;
53*15dba7a9SFrançois Tigeot 	struct kobj_type *ktype;
54*15dba7a9SFrançois Tigeot };
55*15dba7a9SFrançois Tigeot 
56*15dba7a9SFrançois Tigeot struct kobj_type {
57*15dba7a9SFrançois Tigeot 	void (*release)(struct kobject *kobj);
58*15dba7a9SFrançois Tigeot 	const struct sysfs_ops *sysfs_ops;
59*15dba7a9SFrançois Tigeot 	struct attribute **default_attrs;
601b7db0e0SFrançois Tigeot };
611b7db0e0SFrançois Tigeot 
62c30871e1SFrançois Tigeot static inline int
kobject_uevent_env(struct kobject * kobj,enum kobject_action action,char * envp[])63c30871e1SFrançois Tigeot kobject_uevent_env(struct kobject *kobj, enum kobject_action action, char *envp[])
64c30871e1SFrançois Tigeot {
65c30871e1SFrançois Tigeot 	return 0;
66c30871e1SFrançois Tigeot }
67c30871e1SFrançois Tigeot 
68*15dba7a9SFrançois Tigeot extern __printf(4, 5) __must_check
69*15dba7a9SFrançois Tigeot int kobject_init_and_add(struct kobject *kobj,
70*15dba7a9SFrançois Tigeot 			 struct kobj_type *ktype, struct kobject *parent,
71*15dba7a9SFrançois Tigeot 			 const char *fmt, ...);
72*15dba7a9SFrançois Tigeot 
73*15dba7a9SFrançois Tigeot extern void kobject_release(struct kref *kref);
74*15dba7a9SFrançois Tigeot 
75*15dba7a9SFrançois Tigeot static inline void
kobject_put(struct kobject * kobj)76*15dba7a9SFrançois Tigeot kobject_put(struct kobject *kobj)
77*15dba7a9SFrançois Tigeot {
78*15dba7a9SFrançois Tigeot 	if (kobj != NULL)
79*15dba7a9SFrançois Tigeot 		kref_put(&kobj->kref, kobject_release);
80*15dba7a9SFrançois Tigeot }
81*15dba7a9SFrançois Tigeot 
82*15dba7a9SFrançois Tigeot static inline void
kobject_del(struct kobject * kobj)83*15dba7a9SFrançois Tigeot kobject_del(struct kobject *kobj)
84*15dba7a9SFrançois Tigeot {
85*15dba7a9SFrançois Tigeot 	/*
86*15dba7a9SFrançois Tigeot 	   This function is supposed to unlink the object from a hierarchy.
87*15dba7a9SFrançois Tigeot 	   There is no such hierarchy in the DragonFly implementation, doing
88*15dba7a9SFrançois Tigeot 	   nothing is fine.
89*15dba7a9SFrançois Tigeot 	*/
90*15dba7a9SFrançois Tigeot }
91*15dba7a9SFrançois Tigeot 
921b7db0e0SFrançois Tigeot #endif	/* _LINUX_KOBJECT_H_ */
93