system.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. #ifndef __ASM_ARM_SYSTEM_H
  2. #define __ASM_ARM_SYSTEM_H
  3. #ifdef __KERNEL__
  4. #include <asm/memory.h>
  5. #define CPU_ARCH_UNKNOWN 0
  6. #define CPU_ARCH_ARMv3 1
  7. #define CPU_ARCH_ARMv4 2
  8. #define CPU_ARCH_ARMv4T 3
  9. #define CPU_ARCH_ARMv5 4
  10. #define CPU_ARCH_ARMv5T 5
  11. #define CPU_ARCH_ARMv5TE 6
  12. #define CPU_ARCH_ARMv5TEJ 7
  13. #define CPU_ARCH_ARMv6 8
  14. #define CPU_ARCH_ARMv7 9
  15. /*
  16. * CR1 bits (CP#15 CR1)
  17. */
  18. #define CR_M (1 << 0) /* MMU enable */
  19. #define CR_A (1 << 1) /* Alignment abort enable */
  20. #define CR_C (1 << 2) /* Dcache enable */
  21. #define CR_W (1 << 3) /* Write buffer enable */
  22. #define CR_P (1 << 4) /* 32-bit exception handler */
  23. #define CR_D (1 << 5) /* 32-bit data address range */
  24. #define CR_L (1 << 6) /* Implementation defined */
  25. #define CR_B (1 << 7) /* Big endian */
  26. #define CR_S (1 << 8) /* System MMU protection */
  27. #define CR_R (1 << 9) /* ROM MMU protection */
  28. #define CR_F (1 << 10) /* Implementation defined */
  29. #define CR_Z (1 << 11) /* Implementation defined */
  30. #define CR_I (1 << 12) /* Icache enable */
  31. #define CR_V (1 << 13) /* Vectors relocated to 0xffff0000 */
  32. #define CR_RR (1 << 14) /* Round Robin cache replacement */
  33. #define CR_L4 (1 << 15) /* LDR pc can set T bit */
  34. #define CR_DT (1 << 16)
  35. #define CR_IT (1 << 18)
  36. #define CR_ST (1 << 19)
  37. #define CR_FI (1 << 21) /* Fast interrupt (lower latency mode) */
  38. #define CR_U (1 << 22) /* Unaligned access operation */
  39. #define CR_XP (1 << 23) /* Extended page tables */
  40. #define CR_VE (1 << 24) /* Vectored interrupts */
  41. #define CR_EE (1 << 25) /* Exception (Big) Endian */
  42. #define CR_TRE (1 << 28) /* TEX remap enable */
  43. #define CR_AFE (1 << 29) /* Access flag enable */
  44. #define CR_TE (1 << 30) /* Thumb exception enable */
  45. /*
  46. * This is used to ensure the compiler did actually allocate the register we
  47. * asked it for some inline assembly sequences. Apparently we can't trust
  48. * the compiler from one version to another so a bit of paranoia won't hurt.
  49. * This string is meant to be concatenated with the inline asm string and
  50. * will cause compilation to stop on mismatch.
  51. * (for details, see gcc PR 15089)
  52. */
  53. #define __asmeq(x, y) ".ifnc " x "," y " ; .err ; .endif\n\t"
  54. #ifndef __ASSEMBLY__
  55. #include <linux/linkage.h>
  56. #include <linux/irqflags.h>
  57. #define __exception __attribute__((section(".exception.text")))
  58. struct thread_info;
  59. struct task_struct;
  60. /* information about the system we're running on */
  61. extern unsigned int system_rev;
  62. extern unsigned int system_serial_low;
  63. extern unsigned int system_serial_high;
  64. extern unsigned int mem_fclk_21285;
  65. struct pt_regs;
  66. void die(const char *msg, struct pt_regs *regs, int err)
  67. __attribute__((noreturn));
  68. struct siginfo;
  69. void arm_notify_die(const char *str, struct pt_regs *regs, struct siginfo *info,
  70. unsigned long err, unsigned long trap);
  71. void hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int,
  72. struct pt_regs *),
  73. int sig, const char *name);
  74. #define xchg(ptr,x) \
  75. ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  76. extern asmlinkage void __backtrace(void);
  77. extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
  78. struct mm_struct;
  79. extern void show_pte(struct mm_struct *mm, unsigned long addr);
  80. extern void __show_regs(struct pt_regs *);
  81. extern int cpu_architecture(void);
  82. extern void cpu_init(void);
  83. void arm_machine_restart(char mode);
  84. extern void (*arm_pm_restart)(char str);
  85. #define UDBG_UNDEFINED (1 << 0)
  86. #define UDBG_SYSCALL (1 << 1)
  87. #define UDBG_BADABORT (1 << 2)
  88. #define UDBG_SEGV (1 << 3)
  89. #define UDBG_BUS (1 << 4)
  90. extern unsigned int user_debug;
  91. #if __LINUX_ARM_ARCH__ >= 4
  92. #define vectors_high() (cr_alignment & CR_V)
  93. #else
  94. #define vectors_high() (0)
  95. #endif
  96. #if __LINUX_ARM_ARCH__ >= 7
  97. #define isb() __asm__ __volatile__ ("isb" : : : "memory")
  98. #define dsb() __asm__ __volatile__ ("dsb" : : : "memory")
  99. #define dmb() __asm__ __volatile__ ("dmb" : : : "memory")
  100. #elif defined(CONFIG_CPU_XSC3) || __LINUX_ARM_ARCH__ == 6
  101. #define isb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c5, 4" \
  102. : : "r" (0) : "memory")
  103. #define dsb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" \
  104. : : "r" (0) : "memory")
  105. #define dmb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" \
  106. : : "r" (0) : "memory")
  107. #else
  108. #define isb() __asm__ __volatile__ ("" : : : "memory")
  109. #define dsb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" \
  110. : : "r" (0) : "memory")
  111. #define dmb() __asm__ __volatile__ ("" : : : "memory")
  112. #endif
  113. #ifndef CONFIG_SMP
  114. #define mb() do { if (arch_is_coherent()) dmb(); else barrier(); } while (0)
  115. #define rmb() do { if (arch_is_coherent()) dmb(); else barrier(); } while (0)
  116. #define wmb() do { if (arch_is_coherent()) dmb(); else barrier(); } while (0)
  117. #define smp_mb() barrier()
  118. #define smp_rmb() barrier()
  119. #define smp_wmb() barrier()
  120. #else
  121. #define mb() dmb()
  122. #define rmb() dmb()
  123. #define wmb() dmb()
  124. #define smp_mb() dmb()
  125. #define smp_rmb() dmb()
  126. #define smp_wmb() dmb()
  127. #endif
  128. #define read_barrier_depends() do { } while(0)
  129. #define smp_read_barrier_depends() do { } while(0)
  130. #define set_mb(var, value) do { var = value; smp_mb(); } while (0)
  131. #define nop() __asm__ __volatile__("mov\tr0,r0\t@ nop\n\t");
  132. extern unsigned long cr_no_alignment; /* defined in entry-armv.S */
  133. extern unsigned long cr_alignment; /* defined in entry-armv.S */
  134. static inline unsigned int get_cr(void)
  135. {
  136. unsigned int val;
  137. asm("mrc p15, 0, %0, c1, c0, 0 @ get CR" : "=r" (val) : : "cc");
  138. return val;
  139. }
  140. static inline void set_cr(unsigned int val)
  141. {
  142. asm volatile("mcr p15, 0, %0, c1, c0, 0 @ set CR"
  143. : : "r" (val) : "cc");
  144. isb();
  145. }
  146. #ifndef CONFIG_SMP
  147. extern void adjust_cr(unsigned long mask, unsigned long set);
  148. #endif
  149. #define CPACC_FULL(n) (3 << (n * 2))
  150. #define CPACC_SVC(n) (1 << (n * 2))
  151. #define CPACC_DISABLE(n) (0 << (n * 2))
  152. static inline unsigned int get_copro_access(void)
  153. {
  154. unsigned int val;
  155. asm("mrc p15, 0, %0, c1, c0, 2 @ get copro access"
  156. : "=r" (val) : : "cc");
  157. return val;
  158. }
  159. static inline void set_copro_access(unsigned int val)
  160. {
  161. asm volatile("mcr p15, 0, %0, c1, c0, 2 @ set copro access"
  162. : : "r" (val) : "cc");
  163. isb();
  164. }
  165. /*
  166. * switch_mm() may do a full cache flush over the context switch,
  167. * so enable interrupts over the context switch to avoid high
  168. * latency.
  169. */
  170. #define __ARCH_WANT_INTERRUPTS_ON_CTXSW
  171. /*
  172. * switch_to(prev, next) should switch from task `prev' to `next'
  173. * `prev' will never be the same as `next'. schedule() itself
  174. * contains the memory barrier to tell GCC not to cache `current'.
  175. */
  176. extern struct task_struct *__switch_to(struct task_struct *, struct thread_info *, struct thread_info *);
  177. #define switch_to(prev,next,last) \
  178. do { \
  179. last = __switch_to(prev,task_thread_info(prev), task_thread_info(next)); \
  180. } while (0)
  181. #if defined(CONFIG_CPU_SA1100) || defined(CONFIG_CPU_SA110)
  182. /*
  183. * On the StrongARM, "swp" is terminally broken since it bypasses the
  184. * cache totally. This means that the cache becomes inconsistent, and,
  185. * since we use normal loads/stores as well, this is really bad.
  186. * Typically, this causes oopsen in filp_close, but could have other,
  187. * more disasterous effects. There are two work-arounds:
  188. * 1. Disable interrupts and emulate the atomic swap
  189. * 2. Clean the cache, perform atomic swap, flush the cache
  190. *
  191. * We choose (1) since its the "easiest" to achieve here and is not
  192. * dependent on the processor type.
  193. *
  194. * NOTE that this solution won't work on an SMP system, so explcitly
  195. * forbid it here.
  196. */
  197. #define swp_is_buggy
  198. #endif
  199. static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
  200. {
  201. extern void __bad_xchg(volatile void *, int);
  202. unsigned long ret;
  203. #ifdef swp_is_buggy
  204. unsigned long flags;
  205. #endif
  206. #if __LINUX_ARM_ARCH__ >= 6
  207. unsigned int tmp;
  208. #endif
  209. switch (size) {
  210. #if __LINUX_ARM_ARCH__ >= 6
  211. case 1:
  212. asm volatile("@ __xchg1\n"
  213. "1: ldrexb %0, [%3]\n"
  214. " strexb %1, %2, [%3]\n"
  215. " teq %1, #0\n"
  216. " bne 1b"
  217. : "=&r" (ret), "=&r" (tmp)
  218. : "r" (x), "r" (ptr)
  219. : "memory", "cc");
  220. break;
  221. case 4:
  222. asm volatile("@ __xchg4\n"
  223. "1: ldrex %0, [%3]\n"
  224. " strex %1, %2, [%3]\n"
  225. " teq %1, #0\n"
  226. " bne 1b"
  227. : "=&r" (ret), "=&r" (tmp)
  228. : "r" (x), "r" (ptr)
  229. : "memory", "cc");
  230. break;
  231. #elif defined(swp_is_buggy)
  232. #ifdef CONFIG_SMP
  233. #error SMP is not supported on this platform
  234. #endif
  235. case 1:
  236. raw_local_irq_save(flags);
  237. ret = *(volatile unsigned char *)ptr;
  238. *(volatile unsigned char *)ptr = x;
  239. raw_local_irq_restore(flags);
  240. break;
  241. case 4:
  242. raw_local_irq_save(flags);
  243. ret = *(volatile unsigned long *)ptr;
  244. *(volatile unsigned long *)ptr = x;
  245. raw_local_irq_restore(flags);
  246. break;
  247. #else
  248. case 1:
  249. asm volatile("@ __xchg1\n"
  250. " swpb %0, %1, [%2]"
  251. : "=&r" (ret)
  252. : "r" (x), "r" (ptr)
  253. : "memory", "cc");
  254. break;
  255. case 4:
  256. asm volatile("@ __xchg4\n"
  257. " swp %0, %1, [%2]"
  258. : "=&r" (ret)
  259. : "r" (x), "r" (ptr)
  260. : "memory", "cc");
  261. break;
  262. #endif
  263. default:
  264. __bad_xchg(ptr, size), ret = 0;
  265. break;
  266. }
  267. return ret;
  268. }
  269. extern void disable_hlt(void);
  270. extern void enable_hlt(void);
  271. #include <asm-generic/cmpxchg-local.h>
  272. /*
  273. * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
  274. * them available.
  275. */
  276. #define cmpxchg_local(ptr, o, n) \
  277. ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
  278. (unsigned long)(n), sizeof(*(ptr))))
  279. #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
  280. #ifndef CONFIG_SMP
  281. #include <asm-generic/cmpxchg.h>
  282. #endif
  283. #endif /* __ASSEMBLY__ */
  284. #define arch_align_stack(x) (x)
  285. #endif /* __KERNEL__ */
  286. #endif