system.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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. struct siginfo;
  75. void notify_die(const char *str, struct pt_regs *regs, struct siginfo *info,
  76. unsigned long err, unsigned long trap);
  77. void hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int,
  78. struct pt_regs *),
  79. int sig, const char *name);
  80. #define xchg(ptr,x) \
  81. ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  82. #define tas(ptr) (xchg((ptr),1))
  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. /*
  91. * Intel's XScale3 core supports some v6 features (supersections, L2)
  92. * but advertises itself as v5 as it does not support the v6 ISA. For
  93. * this reason, we need a way to explicitly test for this type of CPU.
  94. */
  95. #ifndef CONFIG_CPU_XSC3
  96. #define cpu_is_xsc3() 0
  97. #else
  98. static inline int cpu_is_xsc3(void)
  99. {
  100. extern unsigned int processor_id;
  101. if ((processor_id & 0xffffe000) == 0x69056000)
  102. return 1;
  103. return 0;
  104. }
  105. #endif
  106. #define set_cr(x) \
  107. __asm__ __volatile__( \
  108. "mcr p15, 0, %0, c1, c0, 0 @ set CR" \
  109. : : "r" (x) : "cc")
  110. #define get_cr() \
  111. ({ \
  112. unsigned int __val; \
  113. __asm__ __volatile__( \
  114. "mrc p15, 0, %0, c1, c0, 0 @ get CR" \
  115. : "=r" (__val) : : "cc"); \
  116. __val; \
  117. })
  118. extern unsigned long cr_no_alignment; /* defined in entry-armv.S */
  119. extern unsigned long cr_alignment; /* defined in entry-armv.S */
  120. #define UDBG_UNDEFINED (1 << 0)
  121. #define UDBG_SYSCALL (1 << 1)
  122. #define UDBG_BADABORT (1 << 2)
  123. #define UDBG_SEGV (1 << 3)
  124. #define UDBG_BUS (1 << 4)
  125. extern unsigned int user_debug;
  126. #if __LINUX_ARM_ARCH__ >= 4
  127. #define vectors_high() (cr_alignment & CR_V)
  128. #else
  129. #define vectors_high() (0)
  130. #endif
  131. #if __LINUX_ARM_ARCH__ >= 6
  132. #define mb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" \
  133. : : "r" (0) : "memory")
  134. #else
  135. #define mb() __asm__ __volatile__ ("" : : : "memory")
  136. #endif
  137. #define rmb() mb()
  138. #define wmb() mb()
  139. #define read_barrier_depends() do { } while(0)
  140. #define set_mb(var, value) do { var = value; mb(); } while (0)
  141. #define set_wmb(var, value) do { var = value; wmb(); } while (0)
  142. #define nop() __asm__ __volatile__("mov\tr0,r0\t@ nop\n\t");
  143. /*
  144. * switch_mm() may do a full cache flush over the context switch,
  145. * so enable interrupts over the context switch to avoid high
  146. * latency.
  147. */
  148. #define __ARCH_WANT_INTERRUPTS_ON_CTXSW
  149. /*
  150. * switch_to(prev, next) should switch from task `prev' to `next'
  151. * `prev' will never be the same as `next'. schedule() itself
  152. * contains the memory barrier to tell GCC not to cache `current'.
  153. */
  154. extern struct task_struct *__switch_to(struct task_struct *, struct thread_info *, struct thread_info *);
  155. #define switch_to(prev,next,last) \
  156. do { \
  157. last = __switch_to(prev,task_thread_info(prev), task_thread_info(next)); \
  158. } while (0)
  159. /*
  160. * On SMP systems, when the scheduler does migration-cost autodetection,
  161. * it needs a way to flush as much of the CPU's caches as possible.
  162. *
  163. * TODO: fill this in!
  164. */
  165. static inline void sched_cacheflush(void)
  166. {
  167. }
  168. /*
  169. * CPU interrupt mask handling.
  170. */
  171. #if __LINUX_ARM_ARCH__ >= 6
  172. #define local_irq_save(x) \
  173. ({ \
  174. __asm__ __volatile__( \
  175. "mrs %0, cpsr @ local_irq_save\n" \
  176. "cpsid i" \
  177. : "=r" (x) : : "memory", "cc"); \
  178. })
  179. #define local_irq_enable() __asm__("cpsie i @ __sti" : : : "memory", "cc")
  180. #define local_irq_disable() __asm__("cpsid i @ __cli" : : : "memory", "cc")
  181. #define local_fiq_enable() __asm__("cpsie f @ __stf" : : : "memory", "cc")
  182. #define local_fiq_disable() __asm__("cpsid f @ __clf" : : : "memory", "cc")
  183. #else
  184. /*
  185. * Save the current interrupt enable state & disable IRQs
  186. */
  187. #define local_irq_save(x) \
  188. ({ \
  189. unsigned long temp; \
  190. (void) (&temp == &x); \
  191. __asm__ __volatile__( \
  192. "mrs %0, cpsr @ local_irq_save\n" \
  193. " orr %1, %0, #128\n" \
  194. " msr cpsr_c, %1" \
  195. : "=r" (x), "=r" (temp) \
  196. : \
  197. : "memory", "cc"); \
  198. })
  199. /*
  200. * Enable IRQs
  201. */
  202. #define local_irq_enable() \
  203. ({ \
  204. unsigned long temp; \
  205. __asm__ __volatile__( \
  206. "mrs %0, cpsr @ local_irq_enable\n" \
  207. " bic %0, %0, #128\n" \
  208. " msr cpsr_c, %0" \
  209. : "=r" (temp) \
  210. : \
  211. : "memory", "cc"); \
  212. })
  213. /*
  214. * Disable IRQs
  215. */
  216. #define local_irq_disable() \
  217. ({ \
  218. unsigned long temp; \
  219. __asm__ __volatile__( \
  220. "mrs %0, cpsr @ local_irq_disable\n" \
  221. " orr %0, %0, #128\n" \
  222. " msr cpsr_c, %0" \
  223. : "=r" (temp) \
  224. : \
  225. : "memory", "cc"); \
  226. })
  227. /*
  228. * Enable FIQs
  229. */
  230. #define local_fiq_enable() \
  231. ({ \
  232. unsigned long temp; \
  233. __asm__ __volatile__( \
  234. "mrs %0, cpsr @ stf\n" \
  235. " bic %0, %0, #64\n" \
  236. " msr cpsr_c, %0" \
  237. : "=r" (temp) \
  238. : \
  239. : "memory", "cc"); \
  240. })
  241. /*
  242. * Disable FIQs
  243. */
  244. #define local_fiq_disable() \
  245. ({ \
  246. unsigned long temp; \
  247. __asm__ __volatile__( \
  248. "mrs %0, cpsr @ clf\n" \
  249. " orr %0, %0, #64\n" \
  250. " msr cpsr_c, %0" \
  251. : "=r" (temp) \
  252. : \
  253. : "memory", "cc"); \
  254. })
  255. #endif
  256. /*
  257. * Save the current interrupt enable state.
  258. */
  259. #define local_save_flags(x) \
  260. ({ \
  261. __asm__ __volatile__( \
  262. "mrs %0, cpsr @ local_save_flags" \
  263. : "=r" (x) : : "memory", "cc"); \
  264. })
  265. /*
  266. * restore saved IRQ & FIQ state
  267. */
  268. #define local_irq_restore(x) \
  269. __asm__ __volatile__( \
  270. "msr cpsr_c, %0 @ local_irq_restore\n" \
  271. : \
  272. : "r" (x) \
  273. : "memory", "cc")
  274. #define irqs_disabled() \
  275. ({ \
  276. unsigned long flags; \
  277. local_save_flags(flags); \
  278. (int)(flags & PSR_I_BIT); \
  279. })
  280. #ifdef CONFIG_SMP
  281. #define smp_mb() mb()
  282. #define smp_rmb() rmb()
  283. #define smp_wmb() wmb()
  284. #define smp_read_barrier_depends() read_barrier_depends()
  285. #else
  286. #define smp_mb() barrier()
  287. #define smp_rmb() barrier()
  288. #define smp_wmb() barrier()
  289. #define smp_read_barrier_depends() do { } while(0)
  290. #endif /* CONFIG_SMP */
  291. #if defined(CONFIG_CPU_SA1100) || defined(CONFIG_CPU_SA110)
  292. /*
  293. * On the StrongARM, "swp" is terminally broken since it bypasses the
  294. * cache totally. This means that the cache becomes inconsistent, and,
  295. * since we use normal loads/stores as well, this is really bad.
  296. * Typically, this causes oopsen in filp_close, but could have other,
  297. * more disasterous effects. There are two work-arounds:
  298. * 1. Disable interrupts and emulate the atomic swap
  299. * 2. Clean the cache, perform atomic swap, flush the cache
  300. *
  301. * We choose (1) since its the "easiest" to achieve here and is not
  302. * dependent on the processor type.
  303. *
  304. * NOTE that this solution won't work on an SMP system, so explcitly
  305. * forbid it here.
  306. */
  307. #define swp_is_buggy
  308. #endif
  309. static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
  310. {
  311. extern void __bad_xchg(volatile void *, int);
  312. unsigned long ret;
  313. #ifdef swp_is_buggy
  314. unsigned long flags;
  315. #endif
  316. #if __LINUX_ARM_ARCH__ >= 6
  317. unsigned int tmp;
  318. #endif
  319. switch (size) {
  320. #if __LINUX_ARM_ARCH__ >= 6
  321. case 1:
  322. asm volatile("@ __xchg1\n"
  323. "1: ldrexb %0, [%3]\n"
  324. " strexb %1, %2, [%3]\n"
  325. " teq %1, #0\n"
  326. " bne 1b"
  327. : "=&r" (ret), "=&r" (tmp)
  328. : "r" (x), "r" (ptr)
  329. : "memory", "cc");
  330. break;
  331. case 4:
  332. asm volatile("@ __xchg4\n"
  333. "1: ldrex %0, [%3]\n"
  334. " strex %1, %2, [%3]\n"
  335. " teq %1, #0\n"
  336. " bne 1b"
  337. : "=&r" (ret), "=&r" (tmp)
  338. : "r" (x), "r" (ptr)
  339. : "memory", "cc");
  340. break;
  341. #elif defined(swp_is_buggy)
  342. #ifdef CONFIG_SMP
  343. #error SMP is not supported on this platform
  344. #endif
  345. case 1:
  346. local_irq_save(flags);
  347. ret = *(volatile unsigned char *)ptr;
  348. *(volatile unsigned char *)ptr = x;
  349. local_irq_restore(flags);
  350. break;
  351. case 4:
  352. local_irq_save(flags);
  353. ret = *(volatile unsigned long *)ptr;
  354. *(volatile unsigned long *)ptr = x;
  355. local_irq_restore(flags);
  356. break;
  357. #else
  358. case 1:
  359. asm volatile("@ __xchg1\n"
  360. " swpb %0, %1, [%2]"
  361. : "=&r" (ret)
  362. : "r" (x), "r" (ptr)
  363. : "memory", "cc");
  364. break;
  365. case 4:
  366. asm volatile("@ __xchg4\n"
  367. " swp %0, %1, [%2]"
  368. : "=&r" (ret)
  369. : "r" (x), "r" (ptr)
  370. : "memory", "cc");
  371. break;
  372. #endif
  373. default:
  374. __bad_xchg(ptr, size), ret = 0;
  375. break;
  376. }
  377. return ret;
  378. }
  379. extern void disable_hlt(void);
  380. extern void enable_hlt(void);
  381. #endif /* __ASSEMBLY__ */
  382. #define arch_align_stack(x) (x)
  383. #endif /* __KERNEL__ */
  384. #endif