1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
/* Copyright (C) 2012-2015 Free Software Foundation, Inc.
Contributed by Richard Henderson <rth@redhat.com>.
This file is part of the GNU Atomic Library (libatomic).
Libatomic is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Libatomic is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
#include <config/arm/arm-config.h>
/* Kernel helper for 32-bit compare-and-exchange. */
typedef int (__kernel_cmpxchg_t) (UWORD oldval, UWORD newval, UWORD *ptr);
#define __kernel_cmpxchg (*(__kernel_cmpxchg_t *) 0xffff0fc0)
/* Kernel helper for 64-bit compare-and-exchange. */
typedef int (__kernel_cmpxchg64_t) (const U_8 * oldval, const U_8 * newval,
U_8 *ptr);
#define __kernel_cmpxchg64 (*(__kernel_cmpxchg64_t *) 0xffff0f60)
/* Kernel helper for memory barrier. */
typedef void (__kernel_dmb_t) (void);
#define __kernel_dmb (*(__kernel_dmb_t *) 0xffff0fa0)
/* Kernel helper page version number. */
#define __kernel_helper_version (*(unsigned int *)0xffff0ffc)
#ifndef HAVE_STREX
static inline bool
atomic_compare_exchange_w (UWORD *mptr, UWORD *eptr, UWORD newval,
bool weak_p UNUSED, int sm UNUSED, int fm UNUSED)
{
bool ret = true;
UWORD oldval;
oldval = *eptr;
if (__builtin_expect (__kernel_cmpxchg (oldval, newval, mptr) != 0, 0))
{
oldval = *mptr;
ret = false;
}
*eptr = oldval;
return ret;
}
# define atomic_compare_exchange_w atomic_compare_exchange_w
# if N == WORDSIZE
# define atomic_compare_exchange_n atomic_compare_exchange_w
# endif
#endif /* HAVE_STREX */
#if !defined(HAVE_STREXBHD) && defined(HAVE_KERNEL64) && N == 8
static inline bool
atomic_compare_exchange_n (UTYPE *mptr, UTYPE *eptr, UTYPE newval,
bool weak_p UNUSED, int sm UNUSED, int fm UNUSED)
{
if (__kernel_cmpxchg64 (eptr, &newval, mptr) == 0)
return true;
else
{
*eptr = *mptr;
return false;
}
}
#define atomic_compare_exchange_n atomic_compare_exchange_n
#endif
#if !defined(HAVE_DMB) && !defined(HAVE_DMB_MCR)
static inline void
pre_barrier(int model UNUSED)
{
__kernel_dmb ();
}
static inline void
post_barrier(int model UNUSED)
{
__kernel_dmb ();
}
# define pre_post_barrier 1
#endif /* !HAVE_DMB */
#if HAVE_IFUNC
extern bool libat_have_strexbhd HIDDEN;
# define IFUNC_COND_1 libat_have_strexbhd
# define IFUNC_COND_2 (__kernel_helper_version >= 5)
/* Alternative 1 is -march=armv7-a -- we have everything native. */
# if IFUNC_ALT == 1
# undef HAVE_ATOMIC_CAS_1
# undef HAVE_ATOMIC_CAS_2
# undef HAVE_ATOMIC_CAS_4
# undef HAVE_ATOMIC_CAS_8
# undef HAVE_ATOMIC_EXCHANGE_1
# undef HAVE_ATOMIC_EXCHANGE_2
# undef HAVE_ATOMIC_EXCHANGE_4
# undef HAVE_ATOMIC_EXCHANGE_8
# undef HAVE_ATOMIC_LDST_1
# undef HAVE_ATOMIC_LDST_2
# undef HAVE_ATOMIC_LDST_4
# undef HAVE_ATOMIC_LDST_8
# undef HAVE_ATOMIC_FETCH_OP_1
# undef HAVE_ATOMIC_FETCH_OP_2
# undef HAVE_ATOMIC_FETCH_OP_4
# undef HAVE_ATOMIC_FETCH_OP_8
# undef HAVE_ATOMIC_TAS_1
# undef HAVE_ATOMIC_TAS_2
# undef HAVE_ATOMIC_TAS_4
# undef HAVE_ATOMIC_TAS_8
# define HAVE_ATOMIC_CAS_1 1
# define HAVE_ATOMIC_CAS_2 1
# define HAVE_ATOMIC_CAS_4 1
# define HAVE_ATOMIC_CAS_8 1
# define HAVE_ATOMIC_EXCHANGE_1 1
# define HAVE_ATOMIC_EXCHANGE_2 1
# define HAVE_ATOMIC_EXCHANGE_4 1
# define HAVE_ATOMIC_EXCHANGE_8 1
# define HAVE_ATOMIC_LDST_1 1
# define HAVE_ATOMIC_LDST_2 1
# define HAVE_ATOMIC_LDST_4 1
# define HAVE_ATOMIC_LDST_8 1
# define HAVE_ATOMIC_FETCH_OP_1 1
# define HAVE_ATOMIC_FETCH_OP_2 1
# define HAVE_ATOMIC_FETCH_OP_4 1
# define HAVE_ATOMIC_FETCH_OP_8 1
# define HAVE_ATOMIC_TAS_1 1
# define HAVE_ATOMIC_TAS_2 1
# define HAVE_ATOMIC_TAS_4 1
# define HAVE_ATOMIC_TAS_8 1
# endif /* IFUNC_ALT == 1 */
# undef MAYBE_HAVE_ATOMIC_CAS_1
# define MAYBE_HAVE_ATOMIC_CAS_1 IFUNC_COND_1
# undef MAYBE_HAVE_ATOMIC_EXCHANGE_1
# define MAYBE_HAVE_ATOMIC_EXCHANGE_1 MAYBE_HAVE_ATOMIC_CAS_1
# undef MAYBE_HAVE_ATOMIC_LDST_1
# define MAYBE_HAVE_ATOMIC_LDST_1 MAYBE_HAVE_ATOMIC_CAS_1
# undef MAYBE_HAVE_ATOMIC_CAS_2
# define MAYBE_HAVE_ATOMIC_CAS_2 IFUNC_COND_1
# undef MAYBE_HAVE_ATOMIC_EXCHANGE_2
# define MAYBE_HAVE_ATOMIC_EXCHANGE_2 MAYBE_HAVE_ATOMIC_CAS_2
# undef MAYBE_HAVE_ATOMIC_LDST_2
# define MAYBE_HAVE_ATOMIC_LDST_2 MAYBE_HAVE_ATOMIC_CAS_2
# undef MAYBE_HAVE_ATOMIC_CAS_4
# define MAYBE_HAVE_ATOMIC_CAS_4 IFUNC_COND_1
# undef MAYBE_HAVE_ATOMIC_EXCHANGE_4
# define MAYBE_HAVE_ATOMIC_EXCHANGE_4 MAYBE_HAVE_ATOMIC_CAS_4
# undef MAYBE_HAVE_ATOMIC_LDST_4
# define MAYBE_HAVE_ATOMIC_LDST_4 MAYBE_HAVE_ATOMIC_CAS_4
# undef MAYBE_HAVE_ATOMIC_CAS_8
# define MAYBE_HAVE_ATOMIC_CAS_8 (IFUNC_COND_1 | IFUNC_COND_2)
# undef MAYBE_HAVE_ATOMIC_EXCHANGE_8
# define MAYBE_HAVE_ATOMIC_EXCHANGE_8 MAYBE_HAVE_ATOMIC_CAS_8
# undef MAYBE_HAVE_ATOMIC_LDST_8
# define MAYBE_HAVE_ATOMIC_LDST_8 MAYBE_HAVE_ATOMIC_CAS_8
# define IFUNC_NCOND(N) (N == 8 ? 2 : 1)
#endif /* HAVE_IFUNC */
#include_next <host-config.h>
|