system.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 5 /* 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. #ifdef CONFIG_GUSA_RB
  64. #include <asm/cmpxchg-grb.h>
  65. #elif defined(CONFIG_CPU_SH4A)
  66. #include <asm/cmpxchg-llsc.h>
  67. #else
  68. #include <asm/cmpxchg-irq.h>
  69. #endif
  70. extern void __xchg_called_with_bad_pointer(void);
  71. #define __xchg(ptr, x, size) \
  72. ({ \
  73. unsigned long __xchg__res; \
  74. volatile void *__xchg_ptr = (ptr); \
  75. switch (size) { \
  76. case 4: \
  77. __xchg__res = xchg_u32(__xchg_ptr, x); \
  78. break; \
  79. case 1: \
  80. __xchg__res = xchg_u8(__xchg_ptr, x); \
  81. break; \
  82. default: \
  83. __xchg_called_with_bad_pointer(); \
  84. __xchg__res = x; \
  85. break; \
  86. } \
  87. \
  88. __xchg__res; \
  89. })
  90. #define xchg(ptr,x) \
  91. ((__typeof__(*(ptr)))__xchg((ptr),(unsigned long)(x), sizeof(*(ptr))))
  92. /* This function doesn't exist, so you'll get a linker error
  93. * if something tries to do an invalid cmpxchg(). */
  94. extern void __cmpxchg_called_with_bad_pointer(void);
  95. #define __HAVE_ARCH_CMPXCHG 1
  96. static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old,
  97. unsigned long new, int size)
  98. {
  99. switch (size) {
  100. case 4:
  101. return __cmpxchg_u32(ptr, old, new);
  102. }
  103. __cmpxchg_called_with_bad_pointer();
  104. return old;
  105. }
  106. #define cmpxchg(ptr,o,n) \
  107. ({ \
  108. __typeof__(*(ptr)) _o_ = (o); \
  109. __typeof__(*(ptr)) _n_ = (n); \
  110. (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
  111. (unsigned long)_n_, sizeof(*(ptr))); \
  112. })
  113. extern void die(const char *str, struct pt_regs *regs, long err) __attribute__ ((noreturn));
  114. void free_initmem(void);
  115. void free_initrd_mem(unsigned long start, unsigned long end);
  116. extern void *set_exception_table_vec(unsigned int vec, void *handler);
  117. static inline void *set_exception_table_evt(unsigned int evt, void *handler)
  118. {
  119. return set_exception_table_vec(evt >> 5, handler);
  120. }
  121. /*
  122. * SH-2A has both 16 and 32-bit opcodes, do lame encoding checks.
  123. */
  124. #ifdef CONFIG_CPU_SH2A
  125. extern unsigned int instruction_size(unsigned int insn);
  126. #elif defined(CONFIG_SUPERH32)
  127. #define instruction_size(insn) (2)
  128. #else
  129. #define instruction_size(insn) (4)
  130. #endif
  131. extern unsigned long cached_to_uncached;
  132. extern struct dentry *sh_debugfs_root;
  133. void per_cpu_trap_init(void);
  134. void default_idle(void);
  135. void cpu_idle_wait(void);
  136. asmlinkage void break_point_trap(void);
  137. #ifdef CONFIG_SUPERH32
  138. #define BUILD_TRAP_HANDLER(name) \
  139. asmlinkage void name##_trap_handler(unsigned long r4, unsigned long r5, \
  140. unsigned long r6, unsigned long r7, \
  141. struct pt_regs __regs)
  142. #define TRAP_HANDLER_DECL \
  143. struct pt_regs *regs = RELOC_HIDE(&__regs, 0); \
  144. unsigned int vec = regs->tra; \
  145. (void)vec;
  146. #else
  147. #define BUILD_TRAP_HANDLER(name) \
  148. asmlinkage void name##_trap_handler(unsigned int vec, struct pt_regs *regs)
  149. #define TRAP_HANDLER_DECL
  150. #endif
  151. BUILD_TRAP_HANDLER(address_error);
  152. BUILD_TRAP_HANDLER(debug);
  153. BUILD_TRAP_HANDLER(bug);
  154. BUILD_TRAP_HANDLER(breakpoint);
  155. BUILD_TRAP_HANDLER(singlestep);
  156. BUILD_TRAP_HANDLER(fpu_error);
  157. BUILD_TRAP_HANDLER(fpu_state_restore);
  158. #define arch_align_stack(x) (x)
  159. struct mem_access {
  160. unsigned long (*from)(void *dst, const void __user *src, unsigned long cnt);
  161. unsigned long (*to)(void __user *dst, const void *src, unsigned long cnt);
  162. };
  163. #ifdef CONFIG_SUPERH32
  164. # include "system_32.h"
  165. #else
  166. # include "system_64.h"
  167. #endif
  168. #endif