xref: /dflybsd-src/sys/dev/drm/include/linux/rcupdate.h (revision e2a4a6b10bbe56932d54ec1764aad5be0fc49c6f)
139cfddd2SFrançois Tigeot /*
28b3e3662SFrançois Tigeot  * Copyright (c) 2017-2020 François Tigeot <ftigeot@wolfpond.org>
339cfddd2SFrançois Tigeot  * All rights reserved.
439cfddd2SFrançois Tigeot  *
539cfddd2SFrançois Tigeot  * Redistribution and use in source and binary forms, with or without
639cfddd2SFrançois Tigeot  * modification, are permitted provided that the following conditions
739cfddd2SFrançois Tigeot  * are met:
839cfddd2SFrançois Tigeot  * 1. Redistributions of source code must retain the above copyright
939cfddd2SFrançois Tigeot  *    notice unmodified, this list of conditions, and the following
1039cfddd2SFrançois Tigeot  *    disclaimer.
1139cfddd2SFrançois Tigeot  * 2. Redistributions in binary form must reproduce the above copyright
1239cfddd2SFrançois Tigeot  *    notice, this list of conditions and the following disclaimer in the
1339cfddd2SFrançois Tigeot  *    documentation and/or other materials provided with the distribution.
1439cfddd2SFrançois Tigeot  *
1539cfddd2SFrançois Tigeot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1639cfddd2SFrançois Tigeot  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1739cfddd2SFrançois Tigeot  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1839cfddd2SFrançois Tigeot  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1939cfddd2SFrançois Tigeot  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2039cfddd2SFrançois Tigeot  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2139cfddd2SFrançois Tigeot  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2239cfddd2SFrançois Tigeot  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2339cfddd2SFrançois Tigeot  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2439cfddd2SFrançois Tigeot  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2539cfddd2SFrançois Tigeot  */
2639cfddd2SFrançois Tigeot 
2741e2def0SFrançois Tigeot #ifndef _LINUX_RCUPDATE_H_
2841e2def0SFrançois Tigeot #define _LINUX_RCUPDATE_H_
2939cfddd2SFrançois Tigeot 
30d6aa1cc5SFrançois Tigeot #include <linux/types.h>
31d6aa1cc5SFrançois Tigeot #include <linux/cache.h>
32d6aa1cc5SFrançois Tigeot #include <linux/spinlock.h>
33d6aa1cc5SFrançois Tigeot #include <linux/threads.h>
34d6aa1cc5SFrançois Tigeot #include <linux/cpumask.h>
35d6aa1cc5SFrançois Tigeot #include <linux/seqlock.h>
36d6aa1cc5SFrançois Tigeot #include <linux/lockdep.h>
37d6aa1cc5SFrançois Tigeot #include <linux/completion.h>
38d6aa1cc5SFrançois Tigeot #include <linux/bug.h>
39d6aa1cc5SFrançois Tigeot #include <linux/compiler.h>
40d6aa1cc5SFrançois Tigeot #include <linux/ktime.h>
41d6aa1cc5SFrançois Tigeot 
42d6aa1cc5SFrançois Tigeot #include <asm/barrier.h>
43d6aa1cc5SFrançois Tigeot 
448b3e3662SFrançois Tigeot #include <linux/rcutree.h>
458b3e3662SFrançois Tigeot 
4639cfddd2SFrançois Tigeot static inline void
4741e2def0SFrançois Tigeot call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *))
4841e2def0SFrançois Tigeot {
4941e2def0SFrançois Tigeot 	func(head);
5041e2def0SFrançois Tigeot }
5141e2def0SFrançois Tigeot 
5241e2def0SFrançois Tigeot static inline void
5339cfddd2SFrançois Tigeot rcu_read_lock(void)
5439cfddd2SFrançois Tigeot {
5541e2def0SFrançois Tigeot 	preempt_disable();
5639cfddd2SFrançois Tigeot }
5739cfddd2SFrançois Tigeot 
5839cfddd2SFrançois Tigeot static inline void
5939cfddd2SFrançois Tigeot rcu_read_unlock(void)
6039cfddd2SFrançois Tigeot {
6141e2def0SFrançois Tigeot 	preempt_enable();
6239cfddd2SFrançois Tigeot }
6339cfddd2SFrançois Tigeot 
6421c41faeSFrançois Tigeot #define rcu_dereference_protected(p, condition)	\
6521c41faeSFrançois Tigeot 	((typeof(*p) *)(p))
6621c41faeSFrançois Tigeot 
6741e2def0SFrançois Tigeot #define rcu_dereference(p)					\
6841e2def0SFrançois Tigeot ({								\
6941e2def0SFrançois Tigeot 	typeof(*(p)) *__rcu_dereference_tmp = READ_ONCE(p);	\
7041e2def0SFrançois Tigeot 	__rcu_dereference_tmp;					\
7141e2def0SFrançois Tigeot })
7239cfddd2SFrançois Tigeot 
73*e2a4a6b1SFrançois Tigeot #define rcu_dereference_raw(p)			\
74*e2a4a6b1SFrançois Tigeot 	((__typeof(*p) *)READ_ONCE(p))
75*e2a4a6b1SFrançois Tigeot 
76411c4fe9SFrançois Tigeot #define rcu_assign_pointer(p, v)	\
77411c4fe9SFrançois Tigeot do {					\
78411c4fe9SFrançois Tigeot 	cpu_mfence();			\
79411c4fe9SFrançois Tigeot 	WRITE_ONCE((p), (v));		\
80411c4fe9SFrançois Tigeot } while (0)
81411c4fe9SFrançois Tigeot 
8241e2def0SFrançois Tigeot #define RCU_INIT_POINTER(p, v)		\
8341e2def0SFrançois Tigeot do {					\
8441e2def0SFrançois Tigeot 	p = v;				\
8541e2def0SFrançois Tigeot } while (0)
8641e2def0SFrançois Tigeot 
8741e2def0SFrançois Tigeot #define kfree_rcu(ptr, rcu_head)	\
8841e2def0SFrançois Tigeot do {					\
8941e2def0SFrançois Tigeot 	kfree(ptr);			\
9041e2def0SFrançois Tigeot } while (0)
9141e2def0SFrançois Tigeot 
928b3e3662SFrançois Tigeot #define rcu_access_pointer(p)	((typeof(*p) *)READ_ONCE(p))
938b3e3662SFrançois Tigeot 
948b3e3662SFrançois Tigeot #define rcu_pointer_handoff(p)	(p)
958b3e3662SFrançois Tigeot 
96*e2a4a6b1SFrançois Tigeot #define synchronize_rcu()
97*e2a4a6b1SFrançois Tigeot 
9841e2def0SFrançois Tigeot #endif  /* _LINUX_RCUPDATE_H_ */
99