system.h 14 KB

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