system.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. #ifndef __ASM_ARM_SYSTEM_H
  2. #define __ASM_ARM_SYSTEM_H
  3. #ifdef __KERNEL__
  4. #include <linux/config.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. /*
  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 CPUID_ID 0
  41. #define CPUID_CACHETYPE 1
  42. #define CPUID_TCM 2
  43. #define CPUID_TLBTYPE 3
  44. #define read_cpuid(reg) \
  45. ({ \
  46. unsigned int __val; \
  47. asm("mrc p15, 0, %0, c0, c0, " __stringify(reg) \
  48. : "=r" (__val) \
  49. : \
  50. : "cc"); \
  51. __val; \
  52. })
  53. /*
  54. * This is used to ensure the compiler did actually allocate the register we
  55. * asked it for some inline assembly sequences. Apparently we can't trust
  56. * the compiler from one version to another so a bit of paranoia won't hurt.
  57. * This string is meant to be concatenated with the inline asm string and
  58. * will cause compilation to stop on mismatch.
  59. * (for details, see gcc PR 15089)
  60. */
  61. #define __asmeq(x, y) ".ifnc " x "," y " ; .err ; .endif\n\t"
  62. #ifndef __ASSEMBLY__
  63. #include <linux/linkage.h>
  64. struct thread_info;
  65. struct task_struct;
  66. /* information about the system we're running on */
  67. extern unsigned int system_rev;
  68. extern unsigned int system_serial_low;
  69. extern unsigned int system_serial_high;
  70. extern unsigned int mem_fclk_21285;
  71. struct pt_regs;
  72. void die(const char *msg, struct pt_regs *regs, int err)
  73. __attribute__((noreturn));
  74. void die_if_kernel(const char *str, struct pt_regs *regs, int err);
  75. void hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int,
  76. struct pt_regs *),
  77. int sig, const char *name);
  78. #include <asm/proc-fns.h>
  79. #define xchg(ptr,x) \
  80. ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  81. #define tas(ptr) (xchg((ptr),1))
  82. extern asmlinkage void __backtrace(void);
  83. extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
  84. extern void show_pte(struct mm_struct *mm, unsigned long addr);
  85. extern void __show_regs(struct pt_regs *);
  86. extern int cpu_architecture(void);
  87. extern void cpu_init(void);
  88. #define set_cr(x) \
  89. __asm__ __volatile__( \
  90. "mcr p15, 0, %0, c1, c0, 0 @ set CR" \
  91. : : "r" (x) : "cc")
  92. #define get_cr() \
  93. ({ \
  94. unsigned int __val; \
  95. __asm__ __volatile__( \
  96. "mrc p15, 0, %0, c1, c0, 0 @ get CR" \
  97. : "=r" (__val) : : "cc"); \
  98. __val; \
  99. })
  100. extern unsigned long cr_no_alignment; /* defined in entry-armv.S */
  101. extern unsigned long cr_alignment; /* defined in entry-armv.S */
  102. #define UDBG_UNDEFINED (1 << 0)
  103. #define UDBG_SYSCALL (1 << 1)
  104. #define UDBG_BADABORT (1 << 2)
  105. #define UDBG_SEGV (1 << 3)
  106. #define UDBG_BUS (1 << 4)
  107. extern unsigned int user_debug;
  108. #if __LINUX_ARM_ARCH__ >= 4
  109. #define vectors_high() (cr_alignment & CR_V)
  110. #else
  111. #define vectors_high() (0)
  112. #endif
  113. #define mb() __asm__ __volatile__ ("" : : : "memory")
  114. #define rmb() mb()
  115. #define wmb() mb()
  116. #define read_barrier_depends() do { } while(0)
  117. #define set_mb(var, value) do { var = value; mb(); } while (0)
  118. #define set_wmb(var, value) do { var = value; wmb(); } while (0)
  119. #define nop() __asm__ __volatile__("mov\tr0,r0\t@ nop\n\t");
  120. #ifdef CONFIG_SMP
  121. /*
  122. * Define our own context switch locking. This allows us to enable
  123. * interrupts over the context switch, otherwise we end up with high
  124. * interrupt latency. The real problem area is switch_mm() which may
  125. * do a full cache flush.
  126. */
  127. #define prepare_arch_switch(rq,next) \
  128. do { \
  129. spin_lock(&(next)->switch_lock); \
  130. spin_unlock_irq(&(rq)->lock); \
  131. } while (0)
  132. #define finish_arch_switch(rq,prev) \
  133. spin_unlock(&(prev)->switch_lock)
  134. #define task_running(rq,p) \
  135. ((rq)->curr == (p) || spin_is_locked(&(p)->switch_lock))
  136. #else
  137. /*
  138. * Our UP-case is more simple, but we assume knowledge of how
  139. * spin_unlock_irq() and friends are implemented. This avoids
  140. * us needlessly decrementing and incrementing the preempt count.
  141. */
  142. #define prepare_arch_switch(rq,next) local_irq_enable()
  143. #define finish_arch_switch(rq,prev) spin_unlock(&(rq)->lock)
  144. #define task_running(rq,p) ((rq)->curr == (p))
  145. #endif
  146. /*
  147. * switch_to(prev, next) should switch from task `prev' to `next'
  148. * `prev' will never be the same as `next'. schedule() itself
  149. * contains the memory barrier to tell GCC not to cache `current'.
  150. */
  151. extern struct task_struct *__switch_to(struct task_struct *, struct thread_info *, struct thread_info *);
  152. #define switch_to(prev,next,last) \
  153. do { \
  154. last = __switch_to(prev,prev->thread_info,next->thread_info); \
  155. } while (0)
  156. /*
  157. * CPU interrupt mask handling.
  158. */
  159. #if __LINUX_ARM_ARCH__ >= 6
  160. #define local_irq_save(x) \
  161. ({ \
  162. __asm__ __volatile__( \
  163. "mrs %0, cpsr @ local_irq_save\n" \
  164. "cpsid i" \
  165. : "=r" (x) : : "memory", "cc"); \
  166. })
  167. #define local_irq_enable() __asm__("cpsie i @ __sti" : : : "memory", "cc")
  168. #define local_irq_disable() __asm__("cpsid i @ __cli" : : : "memory", "cc")
  169. #define local_fiq_enable() __asm__("cpsie f @ __stf" : : : "memory", "cc")
  170. #define local_fiq_disable() __asm__("cpsid f @ __clf" : : : "memory", "cc")
  171. #else
  172. /*
  173. * Save the current interrupt enable state & disable IRQs
  174. */
  175. #define local_irq_save(x) \
  176. ({ \
  177. unsigned long temp; \
  178. (void) (&temp == &x); \
  179. __asm__ __volatile__( \
  180. "mrs %0, cpsr @ local_irq_save\n" \
  181. " orr %1, %0, #128\n" \
  182. " msr cpsr_c, %1" \
  183. : "=r" (x), "=r" (temp) \
  184. : \
  185. : "memory", "cc"); \
  186. })
  187. /*
  188. * Enable IRQs
  189. */
  190. #define local_irq_enable() \
  191. ({ \
  192. unsigned long temp; \
  193. __asm__ __volatile__( \
  194. "mrs %0, cpsr @ local_irq_enable\n" \
  195. " bic %0, %0, #128\n" \
  196. " msr cpsr_c, %0" \
  197. : "=r" (temp) \
  198. : \
  199. : "memory", "cc"); \
  200. })
  201. /*
  202. * Disable IRQs
  203. */
  204. #define local_irq_disable() \
  205. ({ \
  206. unsigned long temp; \
  207. __asm__ __volatile__( \
  208. "mrs %0, cpsr @ local_irq_disable\n" \
  209. " orr %0, %0, #128\n" \
  210. " msr cpsr_c, %0" \
  211. : "=r" (temp) \
  212. : \
  213. : "memory", "cc"); \
  214. })
  215. /*
  216. * Enable FIQs
  217. */
  218. #define local_fiq_enable() \
  219. ({ \
  220. unsigned long temp; \
  221. __asm__ __volatile__( \
  222. "mrs %0, cpsr @ stf\n" \
  223. " bic %0, %0, #64\n" \
  224. " msr cpsr_c, %0" \
  225. : "=r" (temp) \
  226. : \
  227. : "memory", "cc"); \
  228. })
  229. /*
  230. * Disable FIQs
  231. */
  232. #define local_fiq_disable() \
  233. ({ \
  234. unsigned long temp; \
  235. __asm__ __volatile__( \
  236. "mrs %0, cpsr @ clf\n" \
  237. " orr %0, %0, #64\n" \
  238. " msr cpsr_c, %0" \
  239. : "=r" (temp) \
  240. : \
  241. : "memory", "cc"); \
  242. })
  243. #endif
  244. /*
  245. * Save the current interrupt enable state.
  246. */
  247. #define local_save_flags(x) \
  248. ({ \
  249. __asm__ __volatile__( \
  250. "mrs %0, cpsr @ local_save_flags" \
  251. : "=r" (x) : : "memory", "cc"); \
  252. })
  253. /*
  254. * restore saved IRQ & FIQ state
  255. */
  256. #define local_irq_restore(x) \
  257. __asm__ __volatile__( \
  258. "msr cpsr_c, %0 @ local_irq_restore\n" \
  259. : \
  260. : "r" (x) \
  261. : "memory", "cc")
  262. #define irqs_disabled() \
  263. ({ \
  264. unsigned long flags; \
  265. local_save_flags(flags); \
  266. (int)(flags & PSR_I_BIT); \
  267. })
  268. #ifdef CONFIG_SMP
  269. #error SMP not supported
  270. #define smp_mb() mb()
  271. #define smp_rmb() rmb()
  272. #define smp_wmb() wmb()
  273. #define smp_read_barrier_depends() read_barrier_depends()
  274. #else
  275. #define smp_mb() barrier()
  276. #define smp_rmb() barrier()
  277. #define smp_wmb() barrier()
  278. #define smp_read_barrier_depends() do { } while(0)
  279. #if defined(CONFIG_CPU_SA1100) || defined(CONFIG_CPU_SA110)
  280. /*
  281. * On the StrongARM, "swp" is terminally broken since it bypasses the
  282. * cache totally. This means that the cache becomes inconsistent, and,
  283. * since we use normal loads/stores as well, this is really bad.
  284. * Typically, this causes oopsen in filp_close, but could have other,
  285. * more disasterous effects. There are two work-arounds:
  286. * 1. Disable interrupts and emulate the atomic swap
  287. * 2. Clean the cache, perform atomic swap, flush the cache
  288. *
  289. * We choose (1) since its the "easiest" to achieve here and is not
  290. * dependent on the processor type.
  291. */
  292. #define swp_is_buggy
  293. #endif
  294. static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
  295. {
  296. extern void __bad_xchg(volatile void *, int);
  297. unsigned long ret;
  298. #ifdef swp_is_buggy
  299. unsigned long flags;
  300. #endif
  301. switch (size) {
  302. #ifdef swp_is_buggy
  303. case 1:
  304. local_irq_save(flags);
  305. ret = *(volatile unsigned char *)ptr;
  306. *(volatile unsigned char *)ptr = x;
  307. local_irq_restore(flags);
  308. break;
  309. case 4:
  310. local_irq_save(flags);
  311. ret = *(volatile unsigned long *)ptr;
  312. *(volatile unsigned long *)ptr = x;
  313. local_irq_restore(flags);
  314. break;
  315. #else
  316. case 1: __asm__ __volatile__ ("swpb %0, %1, [%2]"
  317. : "=&r" (ret)
  318. : "r" (x), "r" (ptr)
  319. : "memory", "cc");
  320. break;
  321. case 4: __asm__ __volatile__ ("swp %0, %1, [%2]"
  322. : "=&r" (ret)
  323. : "r" (x), "r" (ptr)
  324. : "memory", "cc");
  325. break;
  326. #endif
  327. default: __bad_xchg(ptr, size), ret = 0;
  328. }
  329. return ret;
  330. }
  331. #endif /* CONFIG_SMP */
  332. #endif /* __ASSEMBLY__ */
  333. #define arch_align_stack(x) (x)
  334. #endif /* __KERNEL__ */
  335. #endif