rcupdate.h revision 329970
178344Sobrien/*-
278344Sobrien * Copyright (c) 2016-2017 Mellanox Technologies, Ltd.
378344Sobrien * All rights reserved.
478344Sobrien *
578344Sobrien * Redistribution and use in source and binary forms, with or without
678344Sobrien * modification, are permitted provided that the following conditions
778344Sobrien * are met:
878344Sobrien * 1. Redistributions of source code must retain the above copyright
978344Sobrien *    notice unmodified, this list of conditions, and the following
1078344Sobrien *    disclaimer.
1178344Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1278344Sobrien *    notice, this list of conditions and the following disclaimer in the
1378344Sobrien *    documentation and/or other materials provided with the distribution.
1478344Sobrien *
1578344Sobrien * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1678344Sobrien * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1778344Sobrien * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1878344Sobrien * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1978344Sobrien * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2078344Sobrien * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2178344Sobrien * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2278344Sobrien * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2378344Sobrien * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2478344Sobrien * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2578344Sobrien *
2678344Sobrien * $FreeBSD: stable/11/sys/compat/linuxkpi/common/include/linux/rcupdate.h 329970 2018-02-25 10:33:55Z hselasky $
2778344Sobrien */
2878344Sobrien#ifndef	_LINUX_RCUPDATE_H_
2978344Sobrien#define	_LINUX_RCUPDATE_H_
3078344Sobrien
3178344Sobrien#include <linux/compiler.h>
3278344Sobrien#include <linux/types.h>
3378344Sobrien
3478344Sobrien#include <machine/atomic.h>
3578344Sobrien
3678344Sobrien#define	LINUX_KFREE_RCU_OFFSET_MAX	4096	/* exclusive */
3778344Sobrien
3878344Sobrien#define	RCU_INITIALIZER(v)			\
3978344Sobrien	((__typeof(*(v)) *)(v))
4078344Sobrien
4178344Sobrien#define	RCU_INIT_POINTER(p, v) do {		\
4278344Sobrien	(p) = (v);				\
4378344Sobrien} while (0)
4478344Sobrien
4578344Sobrien#define	call_rcu(ptr, func) do {		\
4678344Sobrien	linux_call_rcu(ptr, func);		\
4778344Sobrien} while (0)
4878344Sobrien
4978344Sobrien#define	rcu_barrier(void) do {			\
5078344Sobrien	linux_rcu_barrier();			\
5178344Sobrien} while (0)
5278344Sobrien
5378344Sobrien#define	rcu_read_lock(void) do {		\
5478344Sobrien	linux_rcu_read_lock();			\
5578344Sobrien} while (0)
5678344Sobrien
5778344Sobrien#define	rcu_read_unlock(void) do {		\
5878344Sobrien	linux_rcu_read_unlock();		\
5978344Sobrien} while (0)
6078344Sobrien
6178344Sobrien#define	synchronize_rcu(void) do {	\
6278344Sobrien	linux_synchronize_rcu();	\
6378344Sobrien} while (0)
6478344Sobrien
6578344Sobrien#define	synchronize_rcu_expedited(void) do {	\
6678344Sobrien	linux_synchronize_rcu();		\
6778344Sobrien} while (0)
6878344Sobrien
6978344Sobrien#define	kfree_rcu(ptr, rcu_head) do {				\
7078344Sobrien	CTASSERT(offsetof(__typeof(*(ptr)), rcu_head) <		\
7178344Sobrien	    LINUX_KFREE_RCU_OFFSET_MAX);			\
7278344Sobrien	call_rcu(&(ptr)->rcu_head, (rcu_callback_t)(uintptr_t)	\
7378344Sobrien	    offsetof(__typeof(*(ptr)), rcu_head));		\
7478344Sobrien} while (0)
7578344Sobrien
7678344Sobrien#define	rcu_access_pointer(p)			\
7778344Sobrien	((__typeof(*p) *)READ_ONCE(p))
7878344Sobrien
7978344Sobrien#define	rcu_dereference_protected(p, c)		\
8078344Sobrien	((__typeof(*p) *)READ_ONCE(p))
8178344Sobrien
8278344Sobrien#define	rcu_dereference(p)			\
8378344Sobrien	rcu_dereference_protected(p, 0)
8478344Sobrien
8578344Sobrien#define	rcu_dereference_raw(p)			\
8678344Sobrien	((__typeof(*p) *)READ_ONCE(p))
8778344Sobrien
8878344Sobrien#define	rcu_pointer_handoff(p) (p)
8978344Sobrien
9078344Sobrien#define	rcu_assign_pointer(p, v) do {				\
9178344Sobrien	atomic_store_rel_ptr((volatile uintptr_t *)&(p),	\
9278344Sobrien	    (uintptr_t)(v));					\
9378344Sobrien} while (0)
9478344Sobrien
9578344Sobrien/* prototypes */
9678344Sobrien
9778344Sobrienextern void linux_call_rcu(struct rcu_head *ptr, rcu_callback_t func);
9878344Sobrienextern void linux_rcu_barrier(void);
9978344Sobrienextern void linux_rcu_read_lock(void);
10078344Sobrienextern void linux_rcu_read_unlock(void);
10178344Sobrienextern void linux_synchronize_rcu(void);
10278344Sobrien
10378344Sobrien#endif					/* _LINUX_RCUPDATE_H_ */
10478344Sobrien