atomic.h revision 285631
1/* $NetBSD: atomic.h,v 1.1 2002/10/19 12:22:34 bsh Exp $ */ 2 3/*- 4 * Copyright (C) 2003-2004 Olivier Houchard 5 * Copyright (C) 1994-1997 Mark Brinicombe 6 * Copyright (C) 1994 Brini 7 * All rights reserved. 8 * 9 * This code is derived from software written for Brini by Mark Brinicombe 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by Brini. 22 * 4. The name of Brini may not be used to endorse or promote products 23 * derived from this software without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR 26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 28 * IN NO EVENT SHALL BRINI BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 31 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 32 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 33 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 * 36 * $FreeBSD: head/sys/arm/include/atomic.h 285631 2015-07-16 13:33:03Z andrew $ 37 */ 38 39#ifndef _MACHINE_ATOMIC_H_ 40#define _MACHINE_ATOMIC_H_ 41 42#include <sys/types.h> 43#include <machine/armreg.h> 44 45#include <machine/acle-compat.h> 46 47#ifndef _KERNEL 48#include <machine/sysarch.h> 49#else 50#include <machine/cpuconf.h> 51#endif 52 53#if __ARM_ARCH >= 6 54#include <machine/atomic-v6.h> 55#else /* < armv6 */ 56#include <machine/atomic-v4.h> 57#endif /* Arch >= v6 */ 58 59static __inline int 60atomic_load_32(volatile uint32_t *v) 61{ 62 63 return (*v); 64} 65 66static __inline void 67atomic_store_32(volatile uint32_t *dst, uint32_t src) 68{ 69 *dst = src; 70} 71 72static __inline int 73atomic_load_long(volatile u_long *v) 74{ 75 76 return (*v); 77} 78 79static __inline void 80atomic_store_long(volatile u_long *dst, u_long src) 81{ 82 *dst = src; 83} 84 85static __inline void 86atomic_thread_fence_acq(void) 87{ 88 89 dmb(); 90} 91 92static __inline void 93atomic_thread_fence_rel(void) 94{ 95 96 dmb(); 97} 98 99static __inline void 100atomic_thread_fence_acq_rel(void) 101{ 102 103 dmb(); 104} 105 106static __inline void 107atomic_thread_fence_seq_cst(void) 108{ 109 110 dmb(); 111} 112 113#define atomic_clear_ptr atomic_clear_32 114#define atomic_set_ptr atomic_set_32 115#define atomic_cmpset_ptr atomic_cmpset_32 116#define atomic_cmpset_rel_ptr atomic_cmpset_rel_32 117#define atomic_cmpset_acq_ptr atomic_cmpset_acq_32 118#define atomic_store_ptr atomic_store_32 119#define atomic_store_rel_ptr atomic_store_rel_32 120 121#define atomic_add_int atomic_add_32 122#define atomic_add_acq_int atomic_add_acq_32 123#define atomic_add_rel_int atomic_add_rel_32 124#define atomic_subtract_int atomic_subtract_32 125#define atomic_subtract_acq_int atomic_subtract_acq_32 126#define atomic_subtract_rel_int atomic_subtract_rel_32 127#define atomic_clear_int atomic_clear_32 128#define atomic_clear_acq_int atomic_clear_acq_32 129#define atomic_clear_rel_int atomic_clear_rel_32 130#define atomic_set_int atomic_set_32 131#define atomic_set_acq_int atomic_set_acq_32 132#define atomic_set_rel_int atomic_set_rel_32 133#define atomic_cmpset_int atomic_cmpset_32 134#define atomic_cmpset_acq_int atomic_cmpset_acq_32 135#define atomic_cmpset_rel_int atomic_cmpset_rel_32 136#define atomic_fetchadd_int atomic_fetchadd_32 137#define atomic_readandclear_int atomic_readandclear_32 138#define atomic_load_acq_int atomic_load_acq_32 139#define atomic_store_rel_int atomic_store_rel_32 140 141#endif /* _MACHINE_ATOMIC_H_ */ 142