system.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  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. * CR1 bits (CP#15 CR1)
  16. */
  17. #define CR_M (1 << 0) /* MMU enable */
  18. #define CR_A (1 << 1) /* Alignment abort enable */
  19. #define CR_C (1 << 2) /* Dcache enable */
  20. #define CR_W (1 << 3) /* Write buffer enable */
  21. #define CR_P (1 << 4) /* 32-bit exception handler */
  22. #define CR_D (1 << 5) /* 32-bit data address range */
  23. #define CR_L (1 << 6) /* Implementation defined */
  24. #define CR_B (1 << 7) /* Big endian */
  25. #define CR_S (1 << 8) /* System MMU protection */
  26. #define CR_R (1 << 9) /* ROM MMU protection */
  27. #define CR_F (1 << 10) /* Implementation defined */
  28. #define CR_Z (1 << 11) /* Implementation defined */
  29. #define CR_I (1 << 12) /* Icache enable */
  30. #define CR_V (1 << 13) /* Vectors relocated to 0xffff0000 */
  31. #define CR_RR (1 << 14) /* Round Robin cache replacement */
  32. #define CR_L4 (1 << 15) /* LDR pc can set T bit */
  33. #define CR_DT (1 << 16)
  34. #define CR_IT (1 << 18)
  35. #define CR_ST (1 << 19)
  36. #define CR_FI (1 << 21) /* Fast interrupt (lower latency mode) */
  37. #define CR_U (1 << 22) /* Unaligned access operation */
  38. #define CR_XP (1 << 23) /* Extended page tables */
  39. #define CR_VE (1 << 24) /* Vectored interrupts */
  40. #define CR_EE (1 << 25) /* Exception (Big) Endian */
  41. #define CR_TRE (1 << 28) /* TEX remap enable */
  42. #define CR_AFE (1 << 29) /* Access flag enable */
  43. #define CR_TE (1 << 30) /* Thumb exception enable */
  44. /*
  45. * This is used to ensure the compiler did actually allocate the register we
  46. * asked it for some inline assembly sequences. Apparently we can't trust
  47. * the compiler from one version to another so a bit of paranoia won't hurt.
  48. * This string is meant to be concatenated with the inline asm string and
  49. * will cause compilation to stop on mismatch.
  50. * (for details, see gcc PR 15089)
  51. */
  52. #define __asmeq(x, y) ".ifnc " x "," y " ; .err ; .endif\n\t"
  53. #ifndef __ASSEMBLY__
  54. #include <linux/linkage.h>
  55. #include <linux/irqflags.h>
  56. #include <asm/outercache.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. struct siginfo;
  68. void arm_notify_die(const char *str, struct pt_regs *regs, struct siginfo *info,
  69. unsigned long err, unsigned long trap);
  70. void hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int,
  71. struct pt_regs *),
  72. int sig, int code, const char *name);
  73. #define xchg(ptr,x) \
  74. ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  75. extern asmlinkage void __backtrace(void);
  76. extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
  77. struct mm_struct;
  78. extern void show_pte(struct mm_struct *mm, unsigned long addr);
  79. extern void __show_regs(struct pt_regs *);
  80. extern int cpu_architecture(void);
  81. extern void cpu_init(void);
  82. void arm_machine_restart(char mode, const char *cmd);
  83. extern void (*arm_pm_restart)(char str, const char *cmd);
  84. #define UDBG_UNDEFINED (1 << 0)
  85. #define UDBG_SYSCALL (1 << 1)
  86. #define UDBG_BADABORT (1 << 2)
  87. #define UDBG_SEGV (1 << 3)
  88. #define UDBG_BUS (1 << 4)
  89. extern unsigned int user_debug;
  90. #if __LINUX_ARM_ARCH__ >= 4
  91. #define vectors_high() (cr_alignment & CR_V)
  92. #else
  93. #define vectors_high() (0)
  94. #endif
  95. #if __LINUX_ARM_ARCH__ >= 7
  96. #define isb() __asm__ __volatile__ ("isb" : : : "memory")
  97. #define dsb() __asm__ __volatile__ ("dsb" : : : "memory")
  98. #define dmb() __asm__ __volatile__ ("dmb" : : : "memory")
  99. #elif defined(CONFIG_CPU_XSC3) || __LINUX_ARM_ARCH__ == 6
  100. #define isb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c5, 4" \
  101. : : "r" (0) : "memory")
  102. #define dsb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" \
  103. : : "r" (0) : "memory")
  104. #define dmb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" \
  105. : : "r" (0) : "memory")
  106. #elif defined(CONFIG_CPU_FA526)
  107. #define isb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c5, 4" \
  108. : : "r" (0) : "memory")
  109. #define dsb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" \
  110. : : "r" (0) : "memory")
  111. #define dmb() __asm__ __volatile__ ("" : : : "memory")
  112. #else
  113. #define isb() __asm__ __volatile__ ("" : : : "memory")
  114. #define dsb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" \
  115. : : "r" (0) : "memory")
  116. #define dmb() __asm__ __volatile__ ("" : : : "memory")
  117. #endif
  118. #ifdef CONFIG_ARCH_HAS_BARRIERS
  119. #include <mach/barriers.h>
  120. #elif defined(CONFIG_ARM_DMA_MEM_BUFFERABLE) || defined(CONFIG_SMP)
  121. #define mb() do { dsb(); outer_sync(); } while (0)
  122. #define rmb() dmb()
  123. #define wmb() mb()
  124. #else
  125. #define mb() do { if (arch_is_coherent()) dmb(); else barrier(); } while (0)
  126. #define rmb() do { if (arch_is_coherent()) dmb(); else barrier(); } while (0)
  127. #define wmb() do { if (arch_is_coherent()) dmb(); else barrier(); } while (0)
  128. #endif
  129. #ifndef CONFIG_SMP
  130. #define smp_mb() barrier()
  131. #define smp_rmb() barrier()
  132. #define smp_wmb() barrier()
  133. #else
  134. #define smp_mb() dmb()
  135. #define smp_rmb() dmb()
  136. #define smp_wmb() dmb()
  137. #endif
  138. #define read_barrier_depends() do { } while(0)
  139. #define smp_read_barrier_depends() do { } while(0)
  140. #define set_mb(var, value) do { var = value; smp_mb(); } while (0)
  141. #define nop() __asm__ __volatile__("mov\tr0,r0\t@ nop\n\t");
  142. extern unsigned long cr_no_alignment; /* defined in entry-armv.S */
  143. extern unsigned long cr_alignment; /* defined in entry-armv.S */
  144. static inline unsigned int get_cr(void)
  145. {
  146. unsigned int val;
  147. asm("mrc p15, 0, %0, c1, c0, 0 @ get CR" : "=r" (val) : : "cc");
  148. return val;
  149. }
  150. static inline void set_cr(unsigned int val)
  151. {
  152. asm volatile("mcr p15, 0, %0, c1, c0, 0 @ set CR"
  153. : : "r" (val) : "cc");
  154. isb();
  155. }
  156. #ifndef CONFIG_SMP
  157. extern void adjust_cr(unsigned long mask, unsigned long set);
  158. #endif
  159. #define CPACC_FULL(n) (3 << (n * 2))
  160. #define CPACC_SVC(n) (1 << (n * 2))
  161. #define CPACC_DISABLE(n) (0 << (n * 2))
  162. static inline unsigned int get_copro_access(void)
  163. {
  164. unsigned int val;
  165. asm("mrc p15, 0, %0, c1, c0, 2 @ get copro access"
  166. : "=r" (val) : : "cc");
  167. return val;
  168. }
  169. static inline void set_copro_access(unsigned int val)
  170. {
  171. asm volatile("mcr p15, 0, %0, c1, c0, 2 @ set copro access"
  172. : : "r" (val) : "cc");
  173. isb();
  174. }
  175. /*
  176. * switch_mm() may do a full cache flush over the context switch,
  177. * so enable interrupts over the context switch to avoid high
  178. * latency.
  179. */
  180. #define __ARCH_WANT_INTERRUPTS_ON_CTXSW
  181. /*
  182. * switch_to(prev, next) should switch from task `prev' to `next'
  183. * `prev' will never be the same as `next'. schedule() itself
  184. * contains the memory barrier to tell GCC not to cache `current'.
  185. */
  186. extern struct task_struct *__switch_to(struct task_struct *, struct thread_info *, struct thread_info *);
  187. #define switch_to(prev,next,last) \
  188. do { \
  189. last = __switch_to(prev,task_thread_info(prev), task_thread_info(next)); \
  190. } while (0)
  191. #if defined(CONFIG_CPU_SA1100) || defined(CONFIG_CPU_SA110)
  192. /*
  193. * On the StrongARM, "swp" is terminally broken since it bypasses the
  194. * cache totally. This means that the cache becomes inconsistent, and,
  195. * since we use normal loads/stores as well, this is really bad.
  196. * Typically, this causes oopsen in filp_close, but could have other,
  197. * more disasterous effects. There are two work-arounds:
  198. * 1. Disable interrupts and emulate the atomic swap
  199. * 2. Clean the cache, perform atomic swap, flush the cache
  200. *
  201. * We choose (1) since its the "easiest" to achieve here and is not
  202. * dependent on the processor type.
  203. *
  204. * NOTE that this solution won't work on an SMP system, so explcitly
  205. * forbid it here.
  206. */
  207. #define swp_is_buggy
  208. #endif
  209. static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
  210. {
  211. extern void __bad_xchg(volatile void *, int);
  212. unsigned long ret;
  213. #ifdef swp_is_buggy
  214. unsigned long flags;
  215. #endif
  216. #if __LINUX_ARM_ARCH__ >= 6
  217. unsigned int tmp;
  218. #endif
  219. smp_mb();
  220. switch (size) {
  221. #if __LINUX_ARM_ARCH__ >= 6
  222. case 1:
  223. asm volatile("@ __xchg1\n"
  224. "1: ldrexb %0, [%3]\n"
  225. " strexb %1, %2, [%3]\n"
  226. " teq %1, #0\n"
  227. " bne 1b"
  228. : "=&r" (ret), "=&r" (tmp)
  229. : "r" (x), "r" (ptr)
  230. : "memory", "cc");
  231. break;
  232. case 4:
  233. asm volatile("@ __xchg4\n"
  234. "1: ldrex %0, [%3]\n"
  235. " strex %1, %2, [%3]\n"
  236. " teq %1, #0\n"
  237. " bne 1b"
  238. : "=&r" (ret), "=&r" (tmp)
  239. : "r" (x), "r" (ptr)
  240. : "memory", "cc");
  241. break;
  242. #elif defined(swp_is_buggy)
  243. #ifdef CONFIG_SMP
  244. #error SMP is not supported on this platform
  245. #endif
  246. case 1:
  247. raw_local_irq_save(flags);
  248. ret = *(volatile unsigned char *)ptr;
  249. *(volatile unsigned char *)ptr = x;
  250. raw_local_irq_restore(flags);
  251. break;
  252. case 4:
  253. raw_local_irq_save(flags);
  254. ret = *(volatile unsigned long *)ptr;
  255. *(volatile unsigned long *)ptr = x;
  256. raw_local_irq_restore(flags);
  257. break;
  258. #else
  259. case 1:
  260. asm volatile("@ __xchg1\n"
  261. " swpb %0, %1, [%2]"
  262. : "=&r" (ret)
  263. : "r" (x), "r" (ptr)
  264. : "memory", "cc");
  265. break;
  266. case 4:
  267. asm volatile("@ __xchg4\n"
  268. " swp %0, %1, [%2]"
  269. : "=&r" (ret)
  270. : "r" (x), "r" (ptr)
  271. : "memory", "cc");
  272. break;
  273. #endif
  274. default:
  275. __bad_xchg(ptr, size), ret = 0;
  276. break;
  277. }
  278. smp_mb();
  279. return ret;
  280. }
  281. extern void disable_hlt(void);
  282. extern void enable_hlt(void);
  283. #include <asm-generic/cmpxchg-local.h>
  284. #if __LINUX_ARM_ARCH__ < 6
  285. #ifdef CONFIG_SMP
  286. #error "SMP is not supported on this platform"
  287. #endif
  288. /*
  289. * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
  290. * them available.
  291. */
  292. #define cmpxchg_local(ptr, o, n) \
  293. ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
  294. (unsigned long)(n), sizeof(*(ptr))))
  295. #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
  296. #ifndef CONFIG_SMP
  297. #include <asm-generic/cmpxchg.h>
  298. #endif
  299. #else /* __LINUX_ARM_ARCH__ >= 6 */
  300. extern void __bad_cmpxchg(volatile void *ptr, int size);
  301. /*
  302. * cmpxchg only support 32-bits operands on ARMv6.
  303. */
  304. static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
  305. unsigned long new, int size)
  306. {
  307. unsigned long oldval, res;
  308. switch (size) {
  309. #ifdef CONFIG_CPU_32v6K
  310. case 1:
  311. do {
  312. asm volatile("@ __cmpxchg1\n"
  313. " ldrexb %1, [%2]\n"
  314. " mov %0, #0\n"
  315. " teq %1, %3\n"
  316. " strexbeq %0, %4, [%2]\n"
  317. : "=&r" (res), "=&r" (oldval)
  318. : "r" (ptr), "Ir" (old), "r" (new)
  319. : "memory", "cc");
  320. } while (res);
  321. break;
  322. case 2:
  323. do {
  324. asm volatile("@ __cmpxchg1\n"
  325. " ldrexh %1, [%2]\n"
  326. " mov %0, #0\n"
  327. " teq %1, %3\n"
  328. " strexheq %0, %4, [%2]\n"
  329. : "=&r" (res), "=&r" (oldval)
  330. : "r" (ptr), "Ir" (old), "r" (new)
  331. : "memory", "cc");
  332. } while (res);
  333. break;
  334. #endif /* CONFIG_CPU_32v6K */
  335. case 4:
  336. do {
  337. asm volatile("@ __cmpxchg4\n"
  338. " ldrex %1, [%2]\n"
  339. " mov %0, #0\n"
  340. " teq %1, %3\n"
  341. " strexeq %0, %4, [%2]\n"
  342. : "=&r" (res), "=&r" (oldval)
  343. : "r" (ptr), "Ir" (old), "r" (new)
  344. : "memory", "cc");
  345. } while (res);
  346. break;
  347. default:
  348. __bad_cmpxchg(ptr, size);
  349. oldval = 0;
  350. }
  351. return oldval;
  352. }
  353. static inline unsigned long __cmpxchg_mb(volatile void *ptr, unsigned long old,
  354. unsigned long new, int size)
  355. {
  356. unsigned long ret;
  357. smp_mb();
  358. ret = __cmpxchg(ptr, old, new, size);
  359. smp_mb();
  360. return ret;
  361. }
  362. #define cmpxchg(ptr,o,n) \
  363. ((__typeof__(*(ptr)))__cmpxchg_mb((ptr), \
  364. (unsigned long)(o), \
  365. (unsigned long)(n), \
  366. sizeof(*(ptr))))
  367. static inline unsigned long __cmpxchg_local(volatile void *ptr,
  368. unsigned long old,
  369. unsigned long new, int size)
  370. {
  371. unsigned long ret;
  372. switch (size) {
  373. #ifndef CONFIG_CPU_32v6K
  374. case 1:
  375. case 2:
  376. ret = __cmpxchg_local_generic(ptr, old, new, size);
  377. break;
  378. #endif /* !CONFIG_CPU_32v6K */
  379. default:
  380. ret = __cmpxchg(ptr, old, new, size);
  381. }
  382. return ret;
  383. }
  384. #define cmpxchg_local(ptr,o,n) \
  385. ((__typeof__(*(ptr)))__cmpxchg_local((ptr), \
  386. (unsigned long)(o), \
  387. (unsigned long)(n), \
  388. sizeof(*(ptr))))
  389. #ifdef CONFIG_CPU_32v6K
  390. /*
  391. * Note : ARMv7-M (currently unsupported by Linux) does not support
  392. * ldrexd/strexd. If ARMv7-M is ever supported by the Linux kernel, it should
  393. * not be allowed to use __cmpxchg64.
  394. */
  395. static inline unsigned long long __cmpxchg64(volatile void *ptr,
  396. unsigned long long old,
  397. unsigned long long new)
  398. {
  399. register unsigned long long oldval asm("r0");
  400. register unsigned long long __old asm("r2") = old;
  401. register unsigned long long __new asm("r4") = new;
  402. unsigned long res;
  403. do {
  404. asm volatile(
  405. " @ __cmpxchg8\n"
  406. " ldrexd %1, %H1, [%2]\n"
  407. " mov %0, #0\n"
  408. " teq %1, %3\n"
  409. " teqeq %H1, %H3\n"
  410. " strexdeq %0, %4, %H4, [%2]\n"
  411. : "=&r" (res), "=&r" (oldval)
  412. : "r" (ptr), "Ir" (__old), "r" (__new)
  413. : "memory", "cc");
  414. } while (res);
  415. return oldval;
  416. }
  417. static inline unsigned long long __cmpxchg64_mb(volatile void *ptr,
  418. unsigned long long old,
  419. unsigned long long new)
  420. {
  421. unsigned long long ret;
  422. smp_mb();
  423. ret = __cmpxchg64(ptr, old, new);
  424. smp_mb();
  425. return ret;
  426. }
  427. #define cmpxchg64(ptr,o,n) \
  428. ((__typeof__(*(ptr)))__cmpxchg64_mb((ptr), \
  429. (unsigned long long)(o), \
  430. (unsigned long long)(n)))
  431. #define cmpxchg64_local(ptr,o,n) \
  432. ((__typeof__(*(ptr)))__cmpxchg64((ptr), \
  433. (unsigned long long)(o), \
  434. (unsigned long long)(n)))
  435. #else /* !CONFIG_CPU_32v6K */
  436. #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
  437. #endif /* CONFIG_CPU_32v6K */
  438. #endif /* __LINUX_ARM_ARCH__ >= 6 */
  439. #endif /* __ASSEMBLY__ */
  440. #define arch_align_stack(x) (x)
  441. #endif /* __KERNEL__ */
  442. #endif