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 359958 2020-04-15 05:02:49Z 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 38359958Shselasky/* BSD specific defines */ 39359958Shselasky#define RCU_TYPE_REGULAR 0 40359958Shselasky#define RCU_TYPE_SLEEPABLE 1 41359958Shselasky#define RCU_TYPE_MAX 2 42359958Shselasky 43328653Shselasky#define RCU_INITIALIZER(v) \ 44328653Shselasky ((__typeof(*(v)) *)(v)) 45293194Shselasky 46328653Shselasky#define RCU_INIT_POINTER(p, v) do { \ 47328653Shselasky (p) = (v); \ 48328653Shselasky} while (0) 49293194Shselasky 50328653Shselasky#define call_rcu(ptr, func) do { \ 51359958Shselasky linux_call_rcu(RCU_TYPE_REGULAR, ptr, func); \ 52328653Shselasky} while (0) 53293194Shselasky 54328653Shselasky#define rcu_barrier(void) do { \ 55359958Shselasky linux_rcu_barrier(RCU_TYPE_REGULAR); \ 56328653Shselasky} while (0) 57293194Shselasky 58328653Shselasky#define rcu_read_lock(void) do { \ 59359958Shselasky linux_rcu_read_lock(RCU_TYPE_REGULAR); \ 60328653Shselasky} while (0) 61293194Shselasky 62328653Shselasky#define rcu_read_unlock(void) do { \ 63359958Shselasky linux_rcu_read_unlock(RCU_TYPE_REGULAR);\ 64328653Shselasky} while (0) 65293194Shselasky 66328653Shselasky#define synchronize_rcu(void) do { \ 67359958Shselasky linux_synchronize_rcu(RCU_TYPE_REGULAR); \ 68294837Shselasky} while (0) 69294837Shselasky 70328653Shselasky#define synchronize_rcu_expedited(void) do { \ 71359958Shselasky linux_synchronize_rcu(RCU_TYPE_REGULAR); \ 72294837Shselasky} while (0) 73294837Shselasky 74328653Shselasky#define kfree_rcu(ptr, rcu_head) do { \ 75328653Shselasky CTASSERT(offsetof(__typeof(*(ptr)), rcu_head) < \ 76328653Shselasky LINUX_KFREE_RCU_OFFSET_MAX); \ 77328653Shselasky call_rcu(&(ptr)->rcu_head, (rcu_callback_t)(uintptr_t) \ 78328653Shselasky offsetof(__typeof(*(ptr)), rcu_head)); \ 79294837Shselasky} while (0) 80294837Shselasky 81328653Shselasky#define rcu_access_pointer(p) \ 82329970Shselasky ((__typeof(*p) *)READ_ONCE(p)) 83328653Shselasky 84328653Shselasky#define rcu_dereference_protected(p, c) \ 85329970Shselasky ((__typeof(*p) *)READ_ONCE(p)) 86328653Shselasky 87328653Shselasky#define rcu_dereference(p) \ 88328653Shselasky rcu_dereference_protected(p, 0) 89328653Shselasky 90329970Shselasky#define rcu_dereference_raw(p) \ 91329970Shselasky ((__typeof(*p) *)READ_ONCE(p)) 92329970Shselasky 93328653Shselasky#define rcu_pointer_handoff(p) (p) 94328653Shselasky 95328653Shselasky#define rcu_assign_pointer(p, v) do { \ 96328653Shselasky atomic_store_rel_ptr((volatile uintptr_t *)&(p), \ 97328653Shselasky (uintptr_t)(v)); \ 98328653Shselasky} while (0) 99328653Shselasky 100328653Shselasky/* prototypes */ 101328653Shselasky 102359958Shselaskyextern void linux_call_rcu(unsigned type, struct rcu_head *ptr, rcu_callback_t func); 103359958Shselaskyextern void linux_rcu_barrier(unsigned type); 104359958Shselaskyextern void linux_rcu_read_lock(unsigned type); 105359958Shselaskyextern void linux_rcu_read_unlock(unsigned type); 106359958Shselaskyextern void linux_synchronize_rcu(unsigned type); 107328653Shselasky 108345934Shselasky/* Empty implementation for !DEBUG */ 109345934Shselasky#define init_rcu_head(...) 110345934Shselasky#define destroy_rcu_head(...) 111345934Shselasky#define init_rcu_head_on_stack(...) 112345934Shselasky#define destroy_rcu_head_on_stack(...) 113345934Shselasky 114293194Shselasky#endif /* _LINUX_RCUPDATE_H_ */ 115