system.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* system.h: FR-V CPU control definitions
  2. *
  3. * Copyright (C) 2003 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #ifndef _ASM_SYSTEM_H
  12. #define _ASM_SYSTEM_H
  13. #include <linux/types.h>
  14. #include <linux/linkage.h>
  15. #include <linux/kernel.h>
  16. struct thread_struct;
  17. /*
  18. * switch_to(prev, next) should switch from task `prev' to `next'
  19. * `prev' will never be the same as `next'.
  20. * The `mb' is to tell GCC not to cache `current' across this call.
  21. */
  22. extern asmlinkage
  23. struct task_struct *__switch_to(struct thread_struct *prev_thread,
  24. struct thread_struct *next_thread,
  25. struct task_struct *prev);
  26. #define switch_to(prev, next, last) \
  27. do { \
  28. (prev)->thread.sched_lr = \
  29. (unsigned long) __builtin_return_address(0); \
  30. (last) = __switch_to(&(prev)->thread, &(next)->thread, (prev)); \
  31. mb(); \
  32. } while(0)
  33. /*
  34. * Force strict CPU ordering.
  35. */
  36. #define nop() asm volatile ("nop"::)
  37. #define mb() asm volatile ("membar" : : :"memory")
  38. #define rmb() asm volatile ("membar" : : :"memory")
  39. #define wmb() asm volatile ("membar" : : :"memory")
  40. #define read_barrier_depends() do { } while (0)
  41. #define smp_mb() barrier()
  42. #define smp_rmb() barrier()
  43. #define smp_wmb() barrier()
  44. #define smp_read_barrier_depends() do {} while(0)
  45. #define set_mb(var, value) \
  46. do { var = (value); barrier(); } while (0)
  47. extern void die_if_kernel(const char *, ...) __attribute__((format(printf, 1, 2)));
  48. extern void free_initmem(void);
  49. #define arch_align_stack(x) (x)
  50. /*****************************************************************************/
  51. /*
  52. * compare and conditionally exchange value with memory
  53. * - if (*ptr == test) then orig = *ptr; *ptr = test;
  54. * - if (*ptr != test) then orig = *ptr;
  55. */
  56. extern uint64_t __cmpxchg_64(uint64_t test, uint64_t new, volatile uint64_t *v);
  57. #ifndef CONFIG_FRV_OUTOFLINE_ATOMIC_OPS
  58. #define cmpxchg(ptr, test, new) \
  59. ({ \
  60. __typeof__(ptr) __xg_ptr = (ptr); \
  61. __typeof__(*(ptr)) __xg_orig, __xg_tmp; \
  62. __typeof__(*(ptr)) __xg_test = (test); \
  63. __typeof__(*(ptr)) __xg_new = (new); \
  64. \
  65. switch (sizeof(__xg_orig)) { \
  66. case 4: \
  67. asm volatile( \
  68. "0: \n" \
  69. " orcc gr0,gr0,gr0,icc3 \n" \
  70. " ckeq icc3,cc7 \n" \
  71. " ld.p %M0,%1 \n" \
  72. " orcr cc7,cc7,cc3 \n" \
  73. " sub%I4cc %1,%4,%2,icc0 \n" \
  74. " bne icc0,#0,1f \n" \
  75. " cst.p %3,%M0 ,cc3,#1 \n" \
  76. " corcc gr29,gr29,gr0 ,cc3,#1 \n" \
  77. " beq icc3,#0,0b \n" \
  78. "1: \n" \
  79. : "+U"(*__xg_ptr), "=&r"(__xg_orig), "=&r"(__xg_tmp) \
  80. : "r"(__xg_new), "NPr"(__xg_test) \
  81. : "memory", "cc7", "cc3", "icc3", "icc0" \
  82. ); \
  83. break; \
  84. \
  85. default: \
  86. __xg_orig = (__typeof__(__xg_orig))0; \
  87. asm volatile("break"); \
  88. break; \
  89. } \
  90. \
  91. __xg_orig; \
  92. })
  93. #else
  94. extern uint32_t __cmpxchg_32(uint32_t *v, uint32_t test, uint32_t new);
  95. #define cmpxchg(ptr, test, new) \
  96. ({ \
  97. __typeof__(ptr) __xg_ptr = (ptr); \
  98. __typeof__(*(ptr)) __xg_orig; \
  99. __typeof__(*(ptr)) __xg_test = (test); \
  100. __typeof__(*(ptr)) __xg_new = (new); \
  101. \
  102. switch (sizeof(__xg_orig)) { \
  103. case 4: __xg_orig = (__force __typeof__(*ptr)) \
  104. __cmpxchg_32((__force uint32_t *)__xg_ptr, \
  105. (__force uint32_t)__xg_test, \
  106. (__force uint32_t)__xg_new); break; \
  107. default: \
  108. __xg_orig = (__typeof__(__xg_orig))0; \
  109. asm volatile("break"); \
  110. break; \
  111. } \
  112. \
  113. __xg_orig; \
  114. })
  115. #endif
  116. #include <asm-generic/cmpxchg-local.h>
  117. static inline unsigned long __cmpxchg_local(volatile void *ptr,
  118. unsigned long old,
  119. unsigned long new, int size)
  120. {
  121. switch (size) {
  122. case 4:
  123. return cmpxchg((unsigned long *)ptr, old, new);
  124. default:
  125. return __cmpxchg_local_generic(ptr, old, new, size);
  126. }
  127. return old;
  128. }
  129. /*
  130. * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
  131. * them available.
  132. */
  133. #define cmpxchg_local(ptr, o, n) \
  134. ((__typeof__(*(ptr)))__cmpxchg_local((ptr), (unsigned long)(o), \
  135. (unsigned long)(n), sizeof(*(ptr))))
  136. #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
  137. #endif /* _ASM_SYSTEM_H */