atomic.h revision 285631
1129198Scognet/* $NetBSD: atomic.h,v 1.1 2002/10/19 12:22:34 bsh Exp $ */
2129198Scognet
3139735Simp/*-
4129198Scognet * Copyright (C) 2003-2004 Olivier Houchard
5129198Scognet * Copyright (C) 1994-1997 Mark Brinicombe
6129198Scognet * Copyright (C) 1994 Brini
7129198Scognet * All rights reserved.
8129198Scognet *
9129198Scognet * This code is derived from software written for Brini by Mark Brinicombe
10129198Scognet *
11129198Scognet * Redistribution and use in source and binary forms, with or without
12129198Scognet * modification, are permitted provided that the following conditions
13129198Scognet * are met:
14129198Scognet * 1. Redistributions of source code must retain the above copyright
15129198Scognet *    notice, this list of conditions and the following disclaimer.
16129198Scognet * 2. Redistributions in binary form must reproduce the above copyright
17129198Scognet *    notice, this list of conditions and the following disclaimer in the
18129198Scognet *    documentation and/or other materials provided with the distribution.
19129198Scognet * 3. All advertising materials mentioning features or use of this software
20129198Scognet *    must display the following acknowledgement:
21129198Scognet *	This product includes software developed by Brini.
22129198Scognet * 4. The name of Brini may not be used to endorse or promote products
23129198Scognet *    derived from this software without specific prior written permission.
24129198Scognet *
25129198Scognet * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR
26129198Scognet * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27129198Scognet * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28129198Scognet * IN NO EVENT SHALL BRINI BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29129198Scognet * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30129198Scognet * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
31129198Scognet * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32129198Scognet * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
33129198Scognet * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34129198Scognet * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35129198Scognet *
36129198Scognet * $FreeBSD: head/sys/arm/include/atomic.h 285631 2015-07-16 13:33:03Z andrew $
37129198Scognet */
38129198Scognet
39129198Scognet#ifndef	_MACHINE_ATOMIC_H_
40129198Scognet#define	_MACHINE_ATOMIC_H_
41129198Scognet
42129198Scognet#include <sys/types.h>
43271398Sandrew#include <machine/armreg.h>
44129198Scognet
45285631Sandrew#include <machine/acle-compat.h>
46285631Sandrew
47175982Sraj#ifndef _KERNEL
48175982Sraj#include <machine/sysarch.h>
49239268Sgonzo#else
50239268Sgonzo#include <machine/cpuconf.h>
51175982Sraj#endif
52175982Sraj
53285631Sandrew#if __ARM_ARCH >= 6
54285631Sandrew#include <machine/atomic-v6.h>
55239268Sgonzo#else /* < armv6 */
56285631Sandrew#include <machine/atomic-v4.h>
57239268Sgonzo#endif /* Arch >= v6 */
58239268Sgonzo
59239268Sgonzostatic __inline int
60144761Scognetatomic_load_32(volatile uint32_t *v)
61144761Scognet{
62144761Scognet
63144761Scognet	return (*v);
64144761Scognet}
65144761Scognet
66144761Scognetstatic __inline void
67144761Scognetatomic_store_32(volatile uint32_t *dst, uint32_t src)
68144761Scognet{
69144761Scognet	*dst = src;
70144761Scognet}
71144761Scognet
72239268Sgonzostatic __inline int
73239268Sgonzoatomic_load_long(volatile u_long *v)
74144761Scognet{
75144761Scognet
76239268Sgonzo	return (*v);
77144761Scognet}
78144761Scognet
79239268Sgonzostatic __inline void
80239268Sgonzoatomic_store_long(volatile u_long *dst, u_long src)
81239268Sgonzo{
82239268Sgonzo	*dst = src;
83239268Sgonzo}
84129198Scognet
85285283Skibstatic __inline void
86285283Skibatomic_thread_fence_acq(void)
87285283Skib{
88285283Skib
89285283Skib	dmb();
90285283Skib}
91285283Skib
92285283Skibstatic __inline void
93285283Skibatomic_thread_fence_rel(void)
94285283Skib{
95285283Skib
96285283Skib	dmb();
97285283Skib}
98285283Skib
99285283Skibstatic __inline void
100285283Skibatomic_thread_fence_acq_rel(void)
101285283Skib{
102285283Skib
103285283Skib	dmb();
104285283Skib}
105285283Skib
106285283Skibstatic __inline void
107285283Skibatomic_thread_fence_seq_cst(void)
108285283Skib{
109285283Skib
110285283Skib	dmb();
111285283Skib}
112285283Skib
113279543Sian#define atomic_clear_ptr		atomic_clear_32
114279543Sian#define atomic_set_ptr			atomic_set_32
115279543Sian#define atomic_cmpset_ptr		atomic_cmpset_32
116279543Sian#define atomic_cmpset_rel_ptr		atomic_cmpset_rel_32
117279543Sian#define atomic_cmpset_acq_ptr		atomic_cmpset_acq_32
118279543Sian#define atomic_store_ptr		atomic_store_32
119279543Sian#define atomic_store_rel_ptr		atomic_store_rel_32
120165786Sticso
121165786Sticso#define atomic_add_int			atomic_add_32
122239268Sgonzo#define atomic_add_acq_int		atomic_add_acq_32
123239268Sgonzo#define atomic_add_rel_int		atomic_add_rel_32
124165786Sticso#define atomic_subtract_int		atomic_subtract_32
125239268Sgonzo#define atomic_subtract_acq_int		atomic_subtract_acq_32
126239268Sgonzo#define atomic_subtract_rel_int		atomic_subtract_rel_32
127165786Sticso#define atomic_clear_int		atomic_clear_32
128239268Sgonzo#define atomic_clear_acq_int		atomic_clear_acq_32
129239268Sgonzo#define atomic_clear_rel_int		atomic_clear_rel_32
130137222Scognet#define atomic_set_int			atomic_set_32
131239268Sgonzo#define atomic_set_acq_int		atomic_set_acq_32
132239268Sgonzo#define atomic_set_rel_int		atomic_set_rel_32
133165786Sticso#define atomic_cmpset_int		atomic_cmpset_32
134239268Sgonzo#define atomic_cmpset_acq_int		atomic_cmpset_acq_32
135239268Sgonzo#define atomic_cmpset_rel_int		atomic_cmpset_rel_32
136165786Sticso#define atomic_fetchadd_int		atomic_fetchadd_32
137137222Scognet#define atomic_readandclear_int		atomic_readandclear_32
138239268Sgonzo#define atomic_load_acq_int		atomic_load_acq_32
139239268Sgonzo#define atomic_store_rel_int		atomic_store_rel_32
140165786Sticso
141129198Scognet#endif /* _MACHINE_ATOMIC_H_ */
142