system.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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. #define __exception __attribute__((section(".exception.text")))
  57. struct thread_info;
  58. struct task_struct;
  59. /* information about the system we're running on */
  60. extern unsigned int system_rev;
  61. extern unsigned int system_serial_low;
  62. extern unsigned int system_serial_high;
  63. extern unsigned int mem_fclk_21285;
  64. struct pt_regs;
  65. void die(const char *msg, struct pt_regs *regs, int err);
  66. struct siginfo;
  67. void arm_notify_die(const char *str, struct pt_regs *regs, struct siginfo *info,
  68. unsigned long err, unsigned long trap);
  69. void hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int,
  70. struct pt_regs *),
  71. int sig, const char *name);
  72. #define xchg(ptr,x) \
  73. ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  74. extern asmlinkage void __backtrace(void);
  75. extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
  76. struct mm_struct;
  77. extern void show_pte(struct mm_struct *mm, unsigned long addr);
  78. extern void __show_regs(struct pt_regs *);
  79. extern int cpu_architecture(void);
  80. extern void cpu_init(void);
  81. void arm_machine_restart(char mode, const char *cmd);
  82. extern void (*arm_pm_restart)(char str, const char *cmd);
  83. #define UDBG_UNDEFINED (1 << 0)
  84. #define UDBG_SYSCALL (1 << 1)
  85. #define UDBG_BADABORT (1 << 2)
  86. #define UDBG_SEGV (1 << 3)
  87. #define UDBG_BUS (1 << 4)
  88. extern unsigned int user_debug;
  89. #if __LINUX_ARM_ARCH__ >= 4
  90. #define vectors_high() (cr_alignment & CR_V)
  91. #else
  92. #define vectors_high() (0)
  93. #endif
  94. #if __LINUX_ARM_ARCH__ >= 7
  95. #define isb() __asm__ __volatile__ ("isb" : : : "memory")
  96. #define dsb() __asm__ __volatile__ ("dsb" : : : "memory")
  97. #define dmb() __asm__ __volatile__ ("dmb" : : : "memory")
  98. #elif defined(CONFIG_CPU_XSC3) || __LINUX_ARM_ARCH__ == 6
  99. #define isb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c5, 4" \
  100. : : "r" (0) : "memory")
  101. #define dsb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" \
  102. : : "r" (0) : "memory")
  103. #define dmb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" \
  104. : : "r" (0) : "memory")
  105. #elif defined(CONFIG_CPU_FA526)
  106. #define isb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c5, 4" \
  107. : : "r" (0) : "memory")
  108. #define dsb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" \
  109. : : "r" (0) : "memory")
  110. #define dmb() __asm__ __volatile__ ("" : : : "memory")
  111. #else
  112. #define isb() __asm__ __volatile__ ("" : : : "memory")
  113. #define dsb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" \
  114. : : "r" (0) : "memory")
  115. #define dmb() __asm__ __volatile__ ("" : : : "memory")
  116. #endif
  117. #if __LINUX_ARM_ARCH__ >= 7 || defined(CONFIG_SMP)
  118. #define mb() dmb()
  119. #define rmb() dmb()
  120. #define wmb() dmb()
  121. #else
  122. #define mb() do { if (arch_is_coherent()) dmb(); else barrier(); } while (0)
  123. #define rmb() do { if (arch_is_coherent()) dmb(); else barrier(); } while (0)
  124. #define wmb() do { if (arch_is_coherent()) dmb(); else barrier(); } while (0)
  125. #endif
  126. #ifndef CONFIG_SMP
  127. #define smp_mb() barrier()
  128. #define smp_rmb() barrier()
  129. #define smp_wmb() barrier()
  130. #else
  131. #define smp_mb() mb()
  132. #define smp_rmb() rmb()
  133. #define smp_wmb() wmb()
  134. #endif
  135. #define read_barrier_depends() do { } while(0)
  136. #define smp_read_barrier_depends() do { } while(0)
  137. #define set_mb(var, value) do { var = value; smp_mb(); } while (0)
  138. #define nop() __asm__ __volatile__("mov\tr0,r0\t@ nop\n\t");
  139. extern unsigned long cr_no_alignment; /* defined in entry-armv.S */
  140. extern unsigned long cr_alignment; /* defined in entry-armv.S */
  141. static inline unsigned int get_cr(void)
  142. {
  143. unsigned int val;
  144. asm("mrc p15, 0, %0, c1, c0, 0 @ get CR" : "=r" (val) : : "cc");
  145. return val;
  146. }
  147. static inline void set_cr(unsigned int val)
  148. {
  149. asm volatile("mcr p15, 0, %0, c1, c0, 0 @ set CR"
  150. : : "r" (val) : "cc");
  151. isb();
  152. }
  153. #ifndef CONFIG_SMP
  154. extern void adjust_cr(unsigned long mask, unsigned long set);
  155. #endif
  156. #define CPACC_FULL(n) (3 << (n * 2))
  157. #define CPACC_SVC(n) (1 << (n * 2))
  158. #define CPACC_DISABLE(n) (0 << (n * 2))
  159. static inline unsigned int get_copro_access(void)
  160. {
  161. unsigned int val;
  162. asm("mrc p15, 0, %0, c1, c0, 2 @ get copro access"
  163. : "=r" (val) : : "cc");
  164. return val;
  165. }
  166. static inline void set_copro_access(unsigned int val)
  167. {
  168. asm volatile("mcr p15, 0, %0, c1, c0, 2 @ set copro access"
  169. : : "r" (val) : "cc");
  170. isb();
  171. }
  172. /*
  173. * switch_mm() may do a full cache flush over the context switch,
  174. * so enable interrupts over the context switch to avoid high
  175. * latency.
  176. */
  177. #define __ARCH_WANT_INTERRUPTS_ON_CTXSW
  178. /*
  179. * switch_to(prev, next) should switch from task `prev' to `next'
  180. * `prev' will never be the same as `next'. schedule() itself
  181. * contains the memory barrier to tell GCC not to cache `current'.
  182. */
  183. extern struct task_struct *__switch_to(struct task_struct *, struct thread_info *, struct thread_info *);
  184. #define switch_to(prev,next,last) \
  185. do { \
  186. last = __switch_to(prev,task_thread_info(prev), task_thread_info(next)); \
  187. } while (0)
  188. #if defined(CONFIG_CPU_SA1100) || defined(CONFIG_CPU_SA110)
  189. /*
  190. * On the StrongARM, "swp" is terminally broken since it bypasses the
  191. * cache totally. This means that the cache becomes inconsistent, and,
  192. * since we use normal loads/stores as well, this is really bad.
  193. * Typically, this causes oopsen in filp_close, but could have other,
  194. * more disasterous effects. There are two work-arounds:
  195. * 1. Disable interrupts and emulate the atomic swap
  196. * 2. Clean the cache, perform atomic swap, flush the cache
  197. *
  198. * We choose (1) since its the "easiest" to achieve here and is not
  199. * dependent on the processor type.
  200. *
  201. * NOTE that this solution won't work on an SMP system, so explcitly
  202. * forbid it here.
  203. */
  204. #define swp_is_buggy
  205. #endif
  206. static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
  207. {
  208. extern void __bad_xchg(volatile void *, int);
  209. unsigned long ret;
  210. #ifdef swp_is_buggy
  211. unsigned long flags;
  212. #endif
  213. #if __LINUX_ARM_ARCH__ >= 6
  214. unsigned int tmp;
  215. #endif
  216. smp_mb();
  217. switch (size) {
  218. #if __LINUX_ARM_ARCH__ >= 6
  219. case 1:
  220. asm volatile("@ __xchg1\n"
  221. "1: ldrexb %0, [%3]\n"
  222. " strexb %1, %2, [%3]\n"
  223. " teq %1, #0\n"
  224. " bne 1b"
  225. : "=&r" (ret), "=&r" (tmp)
  226. : "r" (x), "r" (ptr)
  227. : "memory", "cc");
  228. break;
  229. case 4:
  230. asm volatile("@ __xchg4\n"
  231. "1: ldrex %0, [%3]\n"
  232. " strex %1, %2, [%3]\n"
  233. " teq %1, #0\n"
  234. " bne 1b"
  235. : "=&r" (ret), "=&r" (tmp)
  236. : "r" (x), "r" (ptr)
  237. : "memory", "cc");
  238. break;
  239. #elif defined(swp_is_buggy)
  240. #ifdef CONFIG_SMP
  241. #error SMP is not supported on this platform
  242. #endif
  243. case 1:
  244. raw_local_irq_save(flags);
  245. ret = *(volatile unsigned char *)ptr;
  246. *(volatile unsigned char *)ptr = x;
  247. raw_local_irq_restore(flags);
  248. break;
  249. case 4:
  250. raw_local_irq_save(flags);
  251. ret = *(volatile unsigned long *)ptr;
  252. *(volatile unsigned long *)ptr = x;
  253. raw_local_irq_restore(flags);
  254. break;
  255. #else
  256. case 1:
  257. asm volatile("@ __xchg1\n"
  258. " swpb %0, %1, [%2]"
  259. : "=&r" (ret)
  260. : "r" (x), "r" (ptr)
  261. : "memory", "cc");
  262. break;
  263. case 4:
  264. asm volatile("@ __xchg4\n"
  265. " swp %0, %1, [%2]"
  266. : "=&r" (ret)
  267. : "r" (x), "r" (ptr)
  268. : "memory", "cc");
  269. break;
  270. #endif
  271. default:
  272. __bad_xchg(ptr, size), ret = 0;
  273. break;
  274. }
  275. smp_mb();
  276. return ret;
  277. }
  278. extern void disable_hlt(void);
  279. extern void enable_hlt(void);
  280. #include <asm-generic/cmpxchg-local.h>
  281. #if __LINUX_ARM_ARCH__ < 6
  282. #ifdef CONFIG_SMP
  283. #error "SMP is not supported on this platform"
  284. #endif
  285. /*
  286. * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
  287. * them available.
  288. */
  289. #define cmpxchg_local(ptr, o, n) \
  290. ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
  291. (unsigned long)(n), sizeof(*(ptr))))
  292. #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
  293. #ifndef CONFIG_SMP
  294. #include <asm-generic/cmpxchg.h>
  295. #endif
  296. #else /* __LINUX_ARM_ARCH__ >= 6 */
  297. extern void __bad_cmpxchg(volatile void *ptr, int size);
  298. /*
  299. * cmpxchg only support 32-bits operands on ARMv6.
  300. */
  301. static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
  302. unsigned long new, int size)
  303. {
  304. unsigned long oldval, res;
  305. switch (size) {
  306. #ifdef CONFIG_CPU_32v6K
  307. case 1:
  308. do {
  309. asm volatile("@ __cmpxchg1\n"
  310. " ldrexb %1, [%2]\n"
  311. " mov %0, #0\n"
  312. " teq %1, %3\n"
  313. " strexbeq %0, %4, [%2]\n"
  314. : "=&r" (res), "=&r" (oldval)
  315. : "r" (ptr), "Ir" (old), "r" (new)
  316. : "memory", "cc");
  317. } while (res);
  318. break;
  319. case 2:
  320. do {
  321. asm volatile("@ __cmpxchg1\n"
  322. " ldrexh %1, [%2]\n"
  323. " mov %0, #0\n"
  324. " teq %1, %3\n"
  325. " strexheq %0, %4, [%2]\n"
  326. : "=&r" (res), "=&r" (oldval)
  327. : "r" (ptr), "Ir" (old), "r" (new)
  328. : "memory", "cc");
  329. } while (res);
  330. break;
  331. #endif /* CONFIG_CPU_32v6K */
  332. case 4:
  333. do {
  334. asm volatile("@ __cmpxchg4\n"
  335. " ldrex %1, [%2]\n"
  336. " mov %0, #0\n"
  337. " teq %1, %3\n"
  338. " strexeq %0, %4, [%2]\n"
  339. : "=&r" (res), "=&r" (oldval)
  340. : "r" (ptr), "Ir" (old), "r" (new)
  341. : "memory", "cc");
  342. } while (res);
  343. break;
  344. default:
  345. __bad_cmpxchg(ptr, size);
  346. oldval = 0;
  347. }
  348. return oldval;
  349. }
  350. static inline unsigned long __cmpxchg_mb(volatile void *ptr, unsigned long old,
  351. unsigned long new, int size)
  352. {
  353. unsigned long ret;
  354. smp_mb();
  355. ret = __cmpxchg(ptr, old, new, size);
  356. smp_mb();
  357. return ret;
  358. }
  359. #define cmpxchg(ptr,o,n) \
  360. ((__typeof__(*(ptr)))__cmpxchg_mb((ptr), \
  361. (unsigned long)(o), \
  362. (unsigned long)(n), \
  363. sizeof(*(ptr))))
  364. static inline unsigned long __cmpxchg_local(volatile void *ptr,
  365. unsigned long old,
  366. unsigned long new, int size)
  367. {
  368. unsigned long ret;
  369. switch (size) {
  370. #ifndef CONFIG_CPU_32v6K
  371. case 1:
  372. case 2:
  373. ret = __cmpxchg_local_generic(ptr, old, new, size);
  374. break;
  375. #endif /* !CONFIG_CPU_32v6K */
  376. default:
  377. ret = __cmpxchg(ptr, old, new, size);
  378. }
  379. return ret;
  380. }
  381. #define cmpxchg_local(ptr,o,n) \
  382. ((__typeof__(*(ptr)))__cmpxchg_local((ptr), \
  383. (unsigned long)(o), \
  384. (unsigned long)(n), \
  385. sizeof(*(ptr))))
  386. #ifdef CONFIG_CPU_32v6K
  387. /*
  388. * Note : ARMv7-M (currently unsupported by Linux) does not support
  389. * ldrexd/strexd. If ARMv7-M is ever supported by the Linux kernel, it should
  390. * not be allowed to use __cmpxchg64.
  391. */
  392. static inline unsigned long long __cmpxchg64(volatile void *ptr,
  393. unsigned long long old,
  394. unsigned long long new)
  395. {
  396. register unsigned long long oldval asm("r0");
  397. register unsigned long long __old asm("r2") = old;
  398. register unsigned long long __new asm("r4") = new;
  399. unsigned long res;
  400. do {
  401. asm volatile(
  402. " @ __cmpxchg8\n"
  403. " ldrexd %1, %H1, [%2]\n"
  404. " mov %0, #0\n"
  405. " teq %1, %3\n"
  406. " teqeq %H1, %H3\n"
  407. " strexdeq %0, %4, %H4, [%2]\n"
  408. : "=&r" (res), "=&r" (oldval)
  409. : "r" (ptr), "Ir" (__old), "r" (__new)
  410. : "memory", "cc");
  411. } while (res);
  412. return oldval;
  413. }
  414. static inline unsigned long long __cmpxchg64_mb(volatile void *ptr,
  415. unsigned long long old,
  416. unsigned long long new)
  417. {
  418. unsigned long long ret;
  419. smp_mb();
  420. ret = __cmpxchg64(ptr, old, new);
  421. smp_mb();
  422. return ret;
  423. }
  424. #define cmpxchg64(ptr,o,n) \
  425. ((__typeof__(*(ptr)))__cmpxchg64_mb((ptr), \
  426. (unsigned long long)(o), \
  427. (unsigned long long)(n)))
  428. #define cmpxchg64_local(ptr,o,n) \
  429. ((__typeof__(*(ptr)))__cmpxchg64((ptr), \
  430. (unsigned long long)(o), \
  431. (unsigned long long)(n)))
  432. #else /* !CONFIG_CPU_32v6K */
  433. #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
  434. #endif /* CONFIG_CPU_32v6K */
  435. #endif /* __LINUX_ARM_ARCH__ >= 6 */
  436. #endif /* __ASSEMBLY__ */
  437. #define arch_align_stack(x) (x)
  438. #endif /* __KERNEL__ */
  439. #endif