host-config.h 5.6 KB

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