system.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. #ifndef __ASM_SH_SYSTEM_H
  2. #define __ASM_SH_SYSTEM_H
  3. /*
  4. * Copyright (C) 1999, 2000 Niibe Yutaka & Kaz Kojima
  5. * Copyright (C) 2002 Paul Mundt
  6. */
  7. #include <linux/irqflags.h>
  8. #include <linux/compiler.h>
  9. #include <linux/linkage.h>
  10. #include <asm/types.h>
  11. #include <asm/ptrace.h>
  12. #define AT_VECTOR_SIZE_ARCH 1 /* entries in ARCH_DLINFO */
  13. #if defined(CONFIG_CPU_SH4A) || defined(CONFIG_CPU_SH5)
  14. #define __icbi() \
  15. { \
  16. unsigned long __addr; \
  17. __addr = 0xa8000000; \
  18. __asm__ __volatile__( \
  19. "icbi %0\n\t" \
  20. : /* no output */ \
  21. : "m" (__m(__addr))); \
  22. }
  23. #endif
  24. /*
  25. * A brief note on ctrl_barrier(), the control register write barrier.
  26. *
  27. * Legacy SH cores typically require a sequence of 8 nops after
  28. * modification of a control register in order for the changes to take
  29. * effect. On newer cores (like the sh4a and sh5) this is accomplished
  30. * with icbi.
  31. *
  32. * Also note that on sh4a in the icbi case we can forego a synco for the
  33. * write barrier, as it's not necessary for control registers.
  34. *
  35. * Historically we have only done this type of barrier for the MMUCR, but
  36. * it's also necessary for the CCR, so we make it generic here instead.
  37. */
  38. #if defined(CONFIG_CPU_SH4A) || defined(CONFIG_CPU_SH5)
  39. #define mb() __asm__ __volatile__ ("synco": : :"memory")
  40. #define rmb() mb()
  41. #define wmb() __asm__ __volatile__ ("synco": : :"memory")
  42. #define ctrl_barrier() __icbi()
  43. #define read_barrier_depends() do { } while(0)
  44. #else
  45. #define mb() __asm__ __volatile__ ("": : :"memory")
  46. #define rmb() mb()
  47. #define wmb() __asm__ __volatile__ ("": : :"memory")
  48. #define ctrl_barrier() __asm__ __volatile__ ("nop;nop;nop;nop;nop;nop;nop;nop")
  49. #define read_barrier_depends() do { } while(0)
  50. #endif
  51. #ifdef CONFIG_SMP
  52. #define smp_mb() mb()
  53. #define smp_rmb() rmb()
  54. #define smp_wmb() wmb()
  55. #define smp_read_barrier_depends() read_barrier_depends()
  56. #else
  57. #define smp_mb() barrier()
  58. #define smp_rmb() barrier()
  59. #define smp_wmb() barrier()
  60. #define smp_read_barrier_depends() do { } while(0)
  61. #endif
  62. #define set_mb(var, value) do { (void)xchg(&var, value); } while (0)
  63. static inline unsigned long xchg_u32(volatile u32 *m, unsigned long val)
  64. {
  65. unsigned long flags, retval;
  66. local_irq_save(flags);
  67. retval = *m;
  68. *m = val;
  69. local_irq_restore(flags);
  70. return retval;
  71. }
  72. static inline unsigned long xchg_u8(volatile u8 *m, unsigned long val)
  73. {
  74. unsigned long flags, retval;
  75. local_irq_save(flags);
  76. retval = *m;
  77. *m = val & 0xff;
  78. local_irq_restore(flags);
  79. return retval;
  80. }
  81. extern void __xchg_called_with_bad_pointer(void);
  82. #define __xchg(ptr, x, size) \
  83. ({ \
  84. unsigned long __xchg__res; \
  85. volatile void *__xchg_ptr = (ptr); \
  86. switch (size) { \
  87. case 4: \
  88. __xchg__res = xchg_u32(__xchg_ptr, x); \
  89. break; \
  90. case 1: \
  91. __xchg__res = xchg_u8(__xchg_ptr, x); \
  92. break; \
  93. default: \
  94. __xchg_called_with_bad_pointer(); \
  95. __xchg__res = x; \
  96. break; \
  97. } \
  98. \
  99. __xchg__res; \
  100. })
  101. #define xchg(ptr,x) \
  102. ((__typeof__(*(ptr)))__xchg((ptr),(unsigned long)(x), sizeof(*(ptr))))
  103. static inline unsigned long __cmpxchg_u32(volatile int * m, unsigned long old,
  104. unsigned long new)
  105. {
  106. __u32 retval;
  107. unsigned long flags;
  108. local_irq_save(flags);
  109. retval = *m;
  110. if (retval == old)
  111. *m = new;
  112. local_irq_restore(flags); /* implies memory barrier */
  113. return retval;
  114. }
  115. /* This function doesn't exist, so you'll get a linker error
  116. * if something tries to do an invalid cmpxchg(). */
  117. extern void __cmpxchg_called_with_bad_pointer(void);
  118. #define __HAVE_ARCH_CMPXCHG 1
  119. static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old,
  120. unsigned long new, int size)
  121. {
  122. switch (size) {
  123. case 4:
  124. return __cmpxchg_u32(ptr, old, new);
  125. }
  126. __cmpxchg_called_with_bad_pointer();
  127. return old;
  128. }
  129. #define cmpxchg(ptr,o,n) \
  130. ({ \
  131. __typeof__(*(ptr)) _o_ = (o); \
  132. __typeof__(*(ptr)) _n_ = (n); \
  133. (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
  134. (unsigned long)_n_, sizeof(*(ptr))); \
  135. })
  136. extern void die(const char *str, struct pt_regs *regs, long err) __attribute__ ((noreturn));
  137. extern void *set_exception_table_vec(unsigned int vec, void *handler);
  138. static inline void *set_exception_table_evt(unsigned int evt, void *handler)
  139. {
  140. return set_exception_table_vec(evt >> 5, handler);
  141. }
  142. /*
  143. * SH-2A has both 16 and 32-bit opcodes, do lame encoding checks.
  144. */
  145. #ifdef CONFIG_CPU_SH2A
  146. extern unsigned int instruction_size(unsigned int insn);
  147. #elif defined(CONFIG_SUPERH32)
  148. #define instruction_size(insn) (2)
  149. #else
  150. #define instruction_size(insn) (4)
  151. #endif
  152. /* XXX
  153. * disable hlt during certain critical i/o operations
  154. */
  155. #define HAVE_DISABLE_HLT
  156. void disable_hlt(void);
  157. void enable_hlt(void);
  158. void default_idle(void);
  159. void per_cpu_trap_init(void);
  160. asmlinkage void break_point_trap(void);
  161. #ifdef CONFIG_SUPERH32
  162. #define BUILD_TRAP_HANDLER(name) \
  163. asmlinkage void name##_trap_handler(unsigned long r4, unsigned long r5, \
  164. unsigned long r6, unsigned long r7, \
  165. struct pt_regs __regs)
  166. #define TRAP_HANDLER_DECL \
  167. struct pt_regs *regs = RELOC_HIDE(&__regs, 0); \
  168. unsigned int vec = regs->tra;
  169. #else
  170. #define BUILD_TRAP_HANDLER(name) \
  171. asmlinkage void name##_trap_handler(unsigned int vec, struct pt_regs *regs)
  172. #define TRAP_HANDLER_DECL
  173. #endif
  174. BUILD_TRAP_HANDLER(address_error);
  175. BUILD_TRAP_HANDLER(debug);
  176. BUILD_TRAP_HANDLER(bug);
  177. #define arch_align_stack(x) (x)
  178. #ifdef CONFIG_SUPERH32
  179. # include "system_32.h"
  180. #else
  181. # include "system_64.h"
  182. #endif
  183. #endif