rcupdate.h revision 329970
1293194Shselasky/*-
2328653Shselasky * Copyright (c) 2016-2017 Mellanox Technologies, Ltd.
3293194Shselasky * All rights reserved.
4293194Shselasky *
5293194Shselasky * Redistribution and use in source and binary forms, with or without
6293194Shselasky * modification, are permitted provided that the following conditions
7293194Shselasky * are met:
8293194Shselasky * 1. Redistributions of source code must retain the above copyright
9293194Shselasky *    notice unmodified, this list of conditions, and the following
10293194Shselasky *    disclaimer.
11293194Shselasky * 2. Redistributions in binary form must reproduce the above copyright
12293194Shselasky *    notice, this list of conditions and the following disclaimer in the
13293194Shselasky *    documentation and/or other materials provided with the distribution.
14293194Shselasky *
15293194Shselasky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16293194Shselasky * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17293194Shselasky * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18293194Shselasky * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19293194Shselasky * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20293194Shselasky * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21293194Shselasky * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22293194Shselasky * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23293194Shselasky * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24293194Shselasky * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25293194Shselasky *
26293194Shselasky * $FreeBSD: stable/11/sys/compat/linuxkpi/common/include/linux/rcupdate.h 329970 2018-02-25 10:33:55Z hselasky $
27293194Shselasky */
28293194Shselasky#ifndef	_LINUX_RCUPDATE_H_
29293194Shselasky#define	_LINUX_RCUPDATE_H_
30293194Shselasky
31328653Shselasky#include <linux/compiler.h>
32328653Shselasky#include <linux/types.h>
33293194Shselasky
34328653Shselasky#include <machine/atomic.h>
35293194Shselasky
36328653Shselasky#define	LINUX_KFREE_RCU_OFFSET_MAX	4096	/* exclusive */
37293194Shselasky
38328653Shselasky#define	RCU_INITIALIZER(v)			\
39328653Shselasky	((__typeof(*(v)) *)(v))
40293194Shselasky
41328653Shselasky#define	RCU_INIT_POINTER(p, v) do {		\
42328653Shselasky	(p) = (v);				\
43328653Shselasky} while (0)
44293194Shselasky
45328653Shselasky#define	call_rcu(ptr, func) do {		\
46328653Shselasky	linux_call_rcu(ptr, func);		\
47328653Shselasky} while (0)
48293194Shselasky
49328653Shselasky#define	rcu_barrier(void) do {			\
50328653Shselasky	linux_rcu_barrier();			\
51328653Shselasky} while (0)
52293194Shselasky
53328653Shselasky#define	rcu_read_lock(void) do {		\
54328653Shselasky	linux_rcu_read_lock();			\
55328653Shselasky} while (0)
56293194Shselasky
57328653Shselasky#define	rcu_read_unlock(void) do {		\
58328653Shselasky	linux_rcu_read_unlock();		\
59328653Shselasky} while (0)
60293194Shselasky
61328653Shselasky#define	synchronize_rcu(void) do {	\
62328653Shselasky	linux_synchronize_rcu();	\
63294837Shselasky} while (0)
64294837Shselasky
65328653Shselasky#define	synchronize_rcu_expedited(void) do {	\
66328653Shselasky	linux_synchronize_rcu();		\
67294837Shselasky} while (0)
68294837Shselasky
69328653Shselasky#define	kfree_rcu(ptr, rcu_head) do {				\
70328653Shselasky	CTASSERT(offsetof(__typeof(*(ptr)), rcu_head) <		\
71328653Shselasky	    LINUX_KFREE_RCU_OFFSET_MAX);			\
72328653Shselasky	call_rcu(&(ptr)->rcu_head, (rcu_callback_t)(uintptr_t)	\
73328653Shselasky	    offsetof(__typeof(*(ptr)), rcu_head));		\
74294837Shselasky} while (0)
75294837Shselasky
76328653Shselasky#define	rcu_access_pointer(p)			\
77329970Shselasky	((__typeof(*p) *)READ_ONCE(p))
78328653Shselasky
79328653Shselasky#define	rcu_dereference_protected(p, c)		\
80329970Shselasky	((__typeof(*p) *)READ_ONCE(p))
81328653Shselasky
82328653Shselasky#define	rcu_dereference(p)			\
83328653Shselasky	rcu_dereference_protected(p, 0)
84328653Shselasky
85329970Shselasky#define	rcu_dereference_raw(p)			\
86329970Shselasky	((__typeof(*p) *)READ_ONCE(p))
87329970Shselasky
88328653Shselasky#define	rcu_pointer_handoff(p) (p)
89328653Shselasky
90328653Shselasky#define	rcu_assign_pointer(p, v) do {				\
91328653Shselasky	atomic_store_rel_ptr((volatile uintptr_t *)&(p),	\
92328653Shselasky	    (uintptr_t)(v));					\
93328653Shselasky} while (0)
94328653Shselasky
95328653Shselasky/* prototypes */
96328653Shselasky
97328653Shselaskyextern void linux_call_rcu(struct rcu_head *ptr, rcu_callback_t func);
98328653Shselaskyextern void linux_rcu_barrier(void);
99328653Shselaskyextern void linux_rcu_read_lock(void);
100328653Shselaskyextern void linux_rcu_read_unlock(void);
101328653Shselaskyextern void linux_synchronize_rcu(void);
102328653Shselasky
103293194Shselasky#endif					/* _LINUX_RCUPDATE_H_ */
104