system.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. #ifndef __ASM_ARM_SYSTEM_H
  2. #define __ASM_ARM_SYSTEM_H
  3. #ifdef __KERNEL__
  4. #define CPU_ARCH_UNKNOWN 0
  5. #define CPU_ARCH_ARMv3 1
  6. #define CPU_ARCH_ARMv4 2
  7. #define CPU_ARCH_ARMv4T 3
  8. #define CPU_ARCH_ARMv5 4
  9. #define CPU_ARCH_ARMv5T 5
  10. #define CPU_ARCH_ARMv5TE 6
  11. #define CPU_ARCH_ARMv5TEJ 7
  12. #define CPU_ARCH_ARMv6 8
  13. #define CPU_ARCH_ARMv7 9
  14. /*
  15. * This is used to ensure the compiler did actually allocate the register we
  16. * asked it for some inline assembly sequences. Apparently we can't trust
  17. * the compiler from one version to another so a bit of paranoia won't hurt.
  18. * This string is meant to be concatenated with the inline asm string and
  19. * will cause compilation to stop on mismatch.
  20. * (for details, see gcc PR 15089)
  21. */
  22. #define __asmeq(x, y) ".ifnc " x "," y " ; .err ; .endif\n\t"
  23. #ifndef __ASSEMBLY__
  24. #include <linux/compiler.h>
  25. #include <linux/linkage.h>
  26. #include <linux/irqflags.h>
  27. #include <asm/outercache.h>
  28. struct thread_info;
  29. struct task_struct;
  30. /* information about the system we're running on */
  31. extern unsigned int system_rev;
  32. extern unsigned int system_serial_low;
  33. extern unsigned int system_serial_high;
  34. extern unsigned int mem_fclk_21285;
  35. struct pt_regs;
  36. void die(const char *msg, struct pt_regs *regs, int err);
  37. struct siginfo;
  38. void arm_notify_die(const char *str, struct pt_regs *regs, struct siginfo *info,
  39. unsigned long err, unsigned long trap);
  40. #ifdef CONFIG_ARM_LPAE
  41. #define FAULT_CODE_ALIGNMENT 33
  42. #define FAULT_CODE_DEBUG 34
  43. #else
  44. #define FAULT_CODE_ALIGNMENT 1
  45. #define FAULT_CODE_DEBUG 2
  46. #endif
  47. void hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int,
  48. struct pt_regs *),
  49. int sig, int code, const char *name);
  50. void hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int,
  51. struct pt_regs *),
  52. int sig, int code, const char *name);
  53. #define xchg(ptr,x) \
  54. ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  55. extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
  56. struct mm_struct;
  57. extern void show_pte(struct mm_struct *mm, unsigned long addr);
  58. extern void __show_regs(struct pt_regs *);
  59. extern int __pure cpu_architecture(void);
  60. extern void cpu_init(void);
  61. void soft_restart(unsigned long);
  62. extern void (*arm_pm_restart)(char str, const char *cmd);
  63. #define UDBG_UNDEFINED (1 << 0)
  64. #define UDBG_SYSCALL (1 << 1)
  65. #define UDBG_BADABORT (1 << 2)
  66. #define UDBG_SEGV (1 << 3)
  67. #define UDBG_BUS (1 << 4)
  68. extern unsigned int user_debug;
  69. #if __LINUX_ARM_ARCH__ >= 7 || \
  70. (__LINUX_ARM_ARCH__ == 6 && defined(CONFIG_CPU_32v6K))
  71. #define sev() __asm__ __volatile__ ("sev" : : : "memory")
  72. #define wfe() __asm__ __volatile__ ("wfe" : : : "memory")
  73. #define wfi() __asm__ __volatile__ ("wfi" : : : "memory")
  74. #endif
  75. #if __LINUX_ARM_ARCH__ >= 7
  76. #define isb() __asm__ __volatile__ ("isb" : : : "memory")
  77. #define dsb() __asm__ __volatile__ ("dsb" : : : "memory")
  78. #define dmb() __asm__ __volatile__ ("dmb" : : : "memory")
  79. #elif defined(CONFIG_CPU_XSC3) || __LINUX_ARM_ARCH__ == 6
  80. #define isb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c5, 4" \
  81. : : "r" (0) : "memory")
  82. #define dsb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" \
  83. : : "r" (0) : "memory")
  84. #define dmb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" \
  85. : : "r" (0) : "memory")
  86. #elif defined(CONFIG_CPU_FA526)
  87. #define isb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c5, 4" \
  88. : : "r" (0) : "memory")
  89. #define dsb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" \
  90. : : "r" (0) : "memory")
  91. #define dmb() __asm__ __volatile__ ("" : : : "memory")
  92. #else
  93. #define isb() __asm__ __volatile__ ("" : : : "memory")
  94. #define dsb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" \
  95. : : "r" (0) : "memory")
  96. #define dmb() __asm__ __volatile__ ("" : : : "memory")
  97. #endif
  98. #ifdef CONFIG_ARCH_HAS_BARRIERS
  99. #include <mach/barriers.h>
  100. #elif defined(CONFIG_ARM_DMA_MEM_BUFFERABLE) || defined(CONFIG_SMP)
  101. #define mb() do { dsb(); outer_sync(); } while (0)
  102. #define rmb() dsb()
  103. #define wmb() mb()
  104. #else
  105. #include <asm/memory.h>
  106. #define mb() do { if (arch_is_coherent()) dmb(); else barrier(); } while (0)
  107. #define rmb() do { if (arch_is_coherent()) dmb(); else barrier(); } while (0)
  108. #define wmb() do { if (arch_is_coherent()) dmb(); else barrier(); } while (0)
  109. #endif
  110. #ifndef CONFIG_SMP
  111. #define smp_mb() barrier()
  112. #define smp_rmb() barrier()
  113. #define smp_wmb() barrier()
  114. #else
  115. #define smp_mb() dmb()
  116. #define smp_rmb() dmb()
  117. #define smp_wmb() dmb()
  118. #endif
  119. #define read_barrier_depends() do { } while(0)
  120. #define smp_read_barrier_depends() do { } while(0)
  121. #define set_mb(var, value) do { var = value; smp_mb(); } while (0)
  122. #define nop() __asm__ __volatile__("mov\tr0,r0\t@ nop\n\t");
  123. /*
  124. * switch_mm() may do a full cache flush over the context switch,
  125. * so enable interrupts over the context switch to avoid high
  126. * latency.
  127. */
  128. #define __ARCH_WANT_INTERRUPTS_ON_CTXSW
  129. /*
  130. * switch_to(prev, next) should switch from task `prev' to `next'
  131. * `prev' will never be the same as `next'. schedule() itself
  132. * contains the memory barrier to tell GCC not to cache `current'.
  133. */
  134. extern struct task_struct *__switch_to(struct task_struct *, struct thread_info *, struct thread_info *);
  135. #define switch_to(prev,next,last) \
  136. do { \
  137. last = __switch_to(prev,task_thread_info(prev), task_thread_info(next)); \
  138. } while (0)
  139. #if defined(CONFIG_CPU_SA1100) || defined(CONFIG_CPU_SA110)
  140. /*
  141. * On the StrongARM, "swp" is terminally broken since it bypasses the
  142. * cache totally. This means that the cache becomes inconsistent, and,
  143. * since we use normal loads/stores as well, this is really bad.
  144. * Typically, this causes oopsen in filp_close, but could have other,
  145. * more disastrous effects. There are two work-arounds:
  146. * 1. Disable interrupts and emulate the atomic swap
  147. * 2. Clean the cache, perform atomic swap, flush the cache
  148. *
  149. * We choose (1) since its the "easiest" to achieve here and is not
  150. * dependent on the processor type.
  151. *
  152. * NOTE that this solution won't work on an SMP system, so explcitly
  153. * forbid it here.
  154. */
  155. #define swp_is_buggy
  156. #endif
  157. static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
  158. {
  159. extern void __bad_xchg(volatile void *, int);
  160. unsigned long ret;
  161. #ifdef swp_is_buggy
  162. unsigned long flags;
  163. #endif
  164. #if __LINUX_ARM_ARCH__ >= 6
  165. unsigned int tmp;
  166. #endif
  167. smp_mb();
  168. switch (size) {
  169. #if __LINUX_ARM_ARCH__ >= 6
  170. case 1:
  171. asm volatile("@ __xchg1\n"
  172. "1: ldrexb %0, [%3]\n"
  173. " strexb %1, %2, [%3]\n"
  174. " teq %1, #0\n"
  175. " bne 1b"
  176. : "=&r" (ret), "=&r" (tmp)
  177. : "r" (x), "r" (ptr)
  178. : "memory", "cc");
  179. break;
  180. case 4:
  181. asm volatile("@ __xchg4\n"
  182. "1: ldrex %0, [%3]\n"
  183. " strex %1, %2, [%3]\n"
  184. " teq %1, #0\n"
  185. " bne 1b"
  186. : "=&r" (ret), "=&r" (tmp)
  187. : "r" (x), "r" (ptr)
  188. : "memory", "cc");
  189. break;
  190. #elif defined(swp_is_buggy)
  191. #ifdef CONFIG_SMP
  192. #error SMP is not supported on this platform
  193. #endif
  194. case 1:
  195. raw_local_irq_save(flags);
  196. ret = *(volatile unsigned char *)ptr;
  197. *(volatile unsigned char *)ptr = x;
  198. raw_local_irq_restore(flags);
  199. break;
  200. case 4:
  201. raw_local_irq_save(flags);
  202. ret = *(volatile unsigned long *)ptr;
  203. *(volatile unsigned long *)ptr = x;
  204. raw_local_irq_restore(flags);
  205. break;
  206. #else
  207. case 1:
  208. asm volatile("@ __xchg1\n"
  209. " swpb %0, %1, [%2]"
  210. : "=&r" (ret)
  211. : "r" (x), "r" (ptr)
  212. : "memory", "cc");
  213. break;
  214. case 4:
  215. asm volatile("@ __xchg4\n"
  216. " swp %0, %1, [%2]"
  217. : "=&r" (ret)
  218. : "r" (x), "r" (ptr)
  219. : "memory", "cc");
  220. break;
  221. #endif
  222. default:
  223. __bad_xchg(ptr, size), ret = 0;
  224. break;
  225. }
  226. smp_mb();
  227. return ret;
  228. }
  229. extern void disable_hlt(void);
  230. extern void enable_hlt(void);
  231. void cpu_idle_wait(void);
  232. #include <asm-generic/cmpxchg-local.h>
  233. #if __LINUX_ARM_ARCH__ < 6
  234. /* min ARCH < ARMv6 */
  235. #ifdef CONFIG_SMP
  236. #error "SMP is not supported on this platform"
  237. #endif
  238. /*
  239. * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
  240. * them available.
  241. */
  242. #define cmpxchg_local(ptr, o, n) \
  243. ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
  244. (unsigned long)(n), sizeof(*(ptr))))
  245. #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
  246. #ifndef CONFIG_SMP
  247. #include <asm-generic/cmpxchg.h>
  248. #endif
  249. #else /* min ARCH >= ARMv6 */
  250. extern void __bad_cmpxchg(volatile void *ptr, int size);
  251. /*
  252. * cmpxchg only support 32-bits operands on ARMv6.
  253. */
  254. static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
  255. unsigned long new, int size)
  256. {
  257. unsigned long oldval, res;
  258. switch (size) {
  259. #ifndef CONFIG_CPU_V6 /* min ARCH >= ARMv6K */
  260. case 1:
  261. do {
  262. asm volatile("@ __cmpxchg1\n"
  263. " ldrexb %1, [%2]\n"
  264. " mov %0, #0\n"
  265. " teq %1, %3\n"
  266. " strexbeq %0, %4, [%2]\n"
  267. : "=&r" (res), "=&r" (oldval)
  268. : "r" (ptr), "Ir" (old), "r" (new)
  269. : "memory", "cc");
  270. } while (res);
  271. break;
  272. case 2:
  273. do {
  274. asm volatile("@ __cmpxchg1\n"
  275. " ldrexh %1, [%2]\n"
  276. " mov %0, #0\n"
  277. " teq %1, %3\n"
  278. " strexheq %0, %4, [%2]\n"
  279. : "=&r" (res), "=&r" (oldval)
  280. : "r" (ptr), "Ir" (old), "r" (new)
  281. : "memory", "cc");
  282. } while (res);
  283. break;
  284. #endif
  285. case 4:
  286. do {
  287. asm volatile("@ __cmpxchg4\n"
  288. " ldrex %1, [%2]\n"
  289. " mov %0, #0\n"
  290. " teq %1, %3\n"
  291. " strexeq %0, %4, [%2]\n"
  292. : "=&r" (res), "=&r" (oldval)
  293. : "r" (ptr), "Ir" (old), "r" (new)
  294. : "memory", "cc");
  295. } while (res);
  296. break;
  297. default:
  298. __bad_cmpxchg(ptr, size);
  299. oldval = 0;
  300. }
  301. return oldval;
  302. }
  303. static inline unsigned long __cmpxchg_mb(volatile void *ptr, unsigned long old,
  304. unsigned long new, int size)
  305. {
  306. unsigned long ret;
  307. smp_mb();
  308. ret = __cmpxchg(ptr, old, new, size);
  309. smp_mb();
  310. return ret;
  311. }
  312. #define cmpxchg(ptr,o,n) \
  313. ((__typeof__(*(ptr)))__cmpxchg_mb((ptr), \
  314. (unsigned long)(o), \
  315. (unsigned long)(n), \
  316. sizeof(*(ptr))))
  317. static inline unsigned long __cmpxchg_local(volatile void *ptr,
  318. unsigned long old,
  319. unsigned long new, int size)
  320. {
  321. unsigned long ret;
  322. switch (size) {
  323. #ifdef CONFIG_CPU_V6 /* min ARCH == ARMv6 */
  324. case 1:
  325. case 2:
  326. ret = __cmpxchg_local_generic(ptr, old, new, size);
  327. break;
  328. #endif
  329. default:
  330. ret = __cmpxchg(ptr, old, new, size);
  331. }
  332. return ret;
  333. }
  334. #define cmpxchg_local(ptr,o,n) \
  335. ((__typeof__(*(ptr)))__cmpxchg_local((ptr), \
  336. (unsigned long)(o), \
  337. (unsigned long)(n), \
  338. sizeof(*(ptr))))
  339. #ifndef CONFIG_CPU_V6 /* min ARCH >= ARMv6K */
  340. /*
  341. * Note : ARMv7-M (currently unsupported by Linux) does not support
  342. * ldrexd/strexd. If ARMv7-M is ever supported by the Linux kernel, it should
  343. * not be allowed to use __cmpxchg64.
  344. */
  345. static inline unsigned long long __cmpxchg64(volatile void *ptr,
  346. unsigned long long old,
  347. unsigned long long new)
  348. {
  349. register unsigned long long oldval asm("r0");
  350. register unsigned long long __old asm("r2") = old;
  351. register unsigned long long __new asm("r4") = new;
  352. unsigned long res;
  353. do {
  354. asm volatile(
  355. " @ __cmpxchg8\n"
  356. " ldrexd %1, %H1, [%2]\n"
  357. " mov %0, #0\n"
  358. " teq %1, %3\n"
  359. " teqeq %H1, %H3\n"
  360. " strexdeq %0, %4, %H4, [%2]\n"
  361. : "=&r" (res), "=&r" (oldval)
  362. : "r" (ptr), "Ir" (__old), "r" (__new)
  363. : "memory", "cc");
  364. } while (res);
  365. return oldval;
  366. }
  367. static inline unsigned long long __cmpxchg64_mb(volatile void *ptr,
  368. unsigned long long old,
  369. unsigned long long new)
  370. {
  371. unsigned long long ret;
  372. smp_mb();
  373. ret = __cmpxchg64(ptr, old, new);
  374. smp_mb();
  375. return ret;
  376. }
  377. #define cmpxchg64(ptr,o,n) \
  378. ((__typeof__(*(ptr)))__cmpxchg64_mb((ptr), \
  379. (unsigned long long)(o), \
  380. (unsigned long long)(n)))
  381. #define cmpxchg64_local(ptr,o,n) \
  382. ((__typeof__(*(ptr)))__cmpxchg64((ptr), \
  383. (unsigned long long)(o), \
  384. (unsigned long long)(n)))
  385. #else /* min ARCH = ARMv6 */
  386. #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
  387. #endif
  388. #endif /* __LINUX_ARM_ARCH__ >= 6 */
  389. #endif /* __ASSEMBLY__ */
  390. #define arch_align_stack(x) (x)
  391. #endif /* __KERNEL__ */
  392. #endif