system.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  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. /*
  14. * CR1 bits (CP#15 CR1)
  15. */
  16. #define CR_M (1 << 0) /* MMU enable */
  17. #define CR_A (1 << 1) /* Alignment abort enable */
  18. #define CR_C (1 << 2) /* Dcache enable */
  19. #define CR_W (1 << 3) /* Write buffer enable */
  20. #define CR_P (1 << 4) /* 32-bit exception handler */
  21. #define CR_D (1 << 5) /* 32-bit data address range */
  22. #define CR_L (1 << 6) /* Implementation defined */
  23. #define CR_B (1 << 7) /* Big endian */
  24. #define CR_S (1 << 8) /* System MMU protection */
  25. #define CR_R (1 << 9) /* ROM MMU protection */
  26. #define CR_F (1 << 10) /* Implementation defined */
  27. #define CR_Z (1 << 11) /* Implementation defined */
  28. #define CR_I (1 << 12) /* Icache enable */
  29. #define CR_V (1 << 13) /* Vectors relocated to 0xffff0000 */
  30. #define CR_RR (1 << 14) /* Round Robin cache replacement */
  31. #define CR_L4 (1 << 15) /* LDR pc can set T bit */
  32. #define CR_DT (1 << 16)
  33. #define CR_IT (1 << 18)
  34. #define CR_ST (1 << 19)
  35. #define CR_FI (1 << 21) /* Fast interrupt (lower latency mode) */
  36. #define CR_U (1 << 22) /* Unaligned access operation */
  37. #define CR_XP (1 << 23) /* Extended page tables */
  38. #define CR_VE (1 << 24) /* Vectored interrupts */
  39. #define CPUID_ID 0
  40. #define CPUID_CACHETYPE 1
  41. #define CPUID_TCM 2
  42. #define CPUID_TLBTYPE 3
  43. #define read_cpuid(reg) \
  44. ({ \
  45. unsigned int __val; \
  46. asm("mrc p15, 0, %0, c0, c0, " __stringify(reg) \
  47. : "=r" (__val) \
  48. : \
  49. : "cc"); \
  50. __val; \
  51. })
  52. /*
  53. * This is used to ensure the compiler did actually allocate the register we
  54. * asked it for some inline assembly sequences. Apparently we can't trust
  55. * the compiler from one version to another so a bit of paranoia won't hurt.
  56. * This string is meant to be concatenated with the inline asm string and
  57. * will cause compilation to stop on mismatch.
  58. * (for details, see gcc PR 15089)
  59. */
  60. #define __asmeq(x, y) ".ifnc " x "," y " ; .err ; .endif\n\t"
  61. #ifndef __ASSEMBLY__
  62. #include <linux/linkage.h>
  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. __attribute__((noreturn));
  73. struct siginfo;
  74. void notify_die(const char *str, struct pt_regs *regs, struct siginfo *info,
  75. unsigned long err, unsigned long trap);
  76. void hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int,
  77. struct pt_regs *),
  78. int sig, const char *name);
  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. struct mm_struct;
  85. extern void show_pte(struct mm_struct *mm, unsigned long addr);
  86. extern void __show_regs(struct pt_regs *);
  87. extern int cpu_architecture(void);
  88. extern void cpu_init(void);
  89. void arm_machine_restart(char mode);
  90. extern void (*arm_pm_restart)(char str);
  91. /*
  92. * Intel's XScale3 core supports some v6 features (supersections, L2)
  93. * but advertises itself as v5 as it does not support the v6 ISA. For
  94. * this reason, we need a way to explicitly test for this type of CPU.
  95. */
  96. #ifndef CONFIG_CPU_XSC3
  97. #define cpu_is_xsc3() 0
  98. #else
  99. static inline int cpu_is_xsc3(void)
  100. {
  101. extern unsigned int processor_id;
  102. if ((processor_id & 0xffffe000) == 0x69056000)
  103. return 1;
  104. return 0;
  105. }
  106. #endif
  107. #if !defined(CONFIG_CPU_XSCALE) && !defined(CONFIG_CPU_XSC3)
  108. #define cpu_is_xscale() 0
  109. #else
  110. #define cpu_is_xscale() 1
  111. #endif
  112. #define set_cr(x) \
  113. __asm__ __volatile__( \
  114. "mcr p15, 0, %0, c1, c0, 0 @ set CR" \
  115. : : "r" (x) : "cc")
  116. #define get_cr() \
  117. ({ \
  118. unsigned int __val; \
  119. __asm__ __volatile__( \
  120. "mrc p15, 0, %0, c1, c0, 0 @ get CR" \
  121. : "=r" (__val) : : "cc"); \
  122. __val; \
  123. })
  124. extern unsigned long cr_no_alignment; /* defined in entry-armv.S */
  125. extern unsigned long cr_alignment; /* defined in entry-armv.S */
  126. #define UDBG_UNDEFINED (1 << 0)
  127. #define UDBG_SYSCALL (1 << 1)
  128. #define UDBG_BADABORT (1 << 2)
  129. #define UDBG_SEGV (1 << 3)
  130. #define UDBG_BUS (1 << 4)
  131. extern unsigned int user_debug;
  132. #if __LINUX_ARM_ARCH__ >= 4
  133. #define vectors_high() (cr_alignment & CR_V)
  134. #else
  135. #define vectors_high() (0)
  136. #endif
  137. #if __LINUX_ARM_ARCH__ >= 6
  138. #define mb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" \
  139. : : "r" (0) : "memory")
  140. #else
  141. #define mb() __asm__ __volatile__ ("" : : : "memory")
  142. #endif
  143. #define rmb() mb()
  144. #define wmb() mb()
  145. #define read_barrier_depends() do { } while(0)
  146. #define set_mb(var, value) do { var = value; mb(); } while (0)
  147. #define set_wmb(var, value) do { var = value; wmb(); } while (0)
  148. #define nop() __asm__ __volatile__("mov\tr0,r0\t@ nop\n\t");
  149. /*
  150. * switch_mm() may do a full cache flush over the context switch,
  151. * so enable interrupts over the context switch to avoid high
  152. * latency.
  153. */
  154. #define __ARCH_WANT_INTERRUPTS_ON_CTXSW
  155. /*
  156. * switch_to(prev, next) should switch from task `prev' to `next'
  157. * `prev' will never be the same as `next'. schedule() itself
  158. * contains the memory barrier to tell GCC not to cache `current'.
  159. */
  160. extern struct task_struct *__switch_to(struct task_struct *, struct thread_info *, struct thread_info *);
  161. #define switch_to(prev,next,last) \
  162. do { \
  163. last = __switch_to(prev,task_thread_info(prev), task_thread_info(next)); \
  164. } while (0)
  165. /*
  166. * On SMP systems, when the scheduler does migration-cost autodetection,
  167. * it needs a way to flush as much of the CPU's caches as possible.
  168. *
  169. * TODO: fill this in!
  170. */
  171. static inline void sched_cacheflush(void)
  172. {
  173. }
  174. /*
  175. * CPU interrupt mask handling.
  176. */
  177. #if __LINUX_ARM_ARCH__ >= 6
  178. #define local_irq_save(x) \
  179. ({ \
  180. __asm__ __volatile__( \
  181. "mrs %0, cpsr @ local_irq_save\n" \
  182. "cpsid i" \
  183. : "=r" (x) : : "memory", "cc"); \
  184. })
  185. #define local_irq_enable() __asm__("cpsie i @ __sti" : : : "memory", "cc")
  186. #define local_irq_disable() __asm__("cpsid i @ __cli" : : : "memory", "cc")
  187. #define local_fiq_enable() __asm__("cpsie f @ __stf" : : : "memory", "cc")
  188. #define local_fiq_disable() __asm__("cpsid f @ __clf" : : : "memory", "cc")
  189. #else
  190. /*
  191. * Save the current interrupt enable state & disable IRQs
  192. */
  193. #define local_irq_save(x) \
  194. ({ \
  195. unsigned long temp; \
  196. (void) (&temp == &x); \
  197. __asm__ __volatile__( \
  198. "mrs %0, cpsr @ local_irq_save\n" \
  199. " orr %1, %0, #128\n" \
  200. " msr cpsr_c, %1" \
  201. : "=r" (x), "=r" (temp) \
  202. : \
  203. : "memory", "cc"); \
  204. })
  205. /*
  206. * Enable IRQs
  207. */
  208. #define local_irq_enable() \
  209. ({ \
  210. unsigned long temp; \
  211. __asm__ __volatile__( \
  212. "mrs %0, cpsr @ local_irq_enable\n" \
  213. " bic %0, %0, #128\n" \
  214. " msr cpsr_c, %0" \
  215. : "=r" (temp) \
  216. : \
  217. : "memory", "cc"); \
  218. })
  219. /*
  220. * Disable IRQs
  221. */
  222. #define local_irq_disable() \
  223. ({ \
  224. unsigned long temp; \
  225. __asm__ __volatile__( \
  226. "mrs %0, cpsr @ local_irq_disable\n" \
  227. " orr %0, %0, #128\n" \
  228. " msr cpsr_c, %0" \
  229. : "=r" (temp) \
  230. : \
  231. : "memory", "cc"); \
  232. })
  233. /*
  234. * Enable FIQs
  235. */
  236. #define local_fiq_enable() \
  237. ({ \
  238. unsigned long temp; \
  239. __asm__ __volatile__( \
  240. "mrs %0, cpsr @ stf\n" \
  241. " bic %0, %0, #64\n" \
  242. " msr cpsr_c, %0" \
  243. : "=r" (temp) \
  244. : \
  245. : "memory", "cc"); \
  246. })
  247. /*
  248. * Disable FIQs
  249. */
  250. #define local_fiq_disable() \
  251. ({ \
  252. unsigned long temp; \
  253. __asm__ __volatile__( \
  254. "mrs %0, cpsr @ clf\n" \
  255. " orr %0, %0, #64\n" \
  256. " msr cpsr_c, %0" \
  257. : "=r" (temp) \
  258. : \
  259. : "memory", "cc"); \
  260. })
  261. #endif
  262. /*
  263. * Save the current interrupt enable state.
  264. */
  265. #define local_save_flags(x) \
  266. ({ \
  267. __asm__ __volatile__( \
  268. "mrs %0, cpsr @ local_save_flags" \
  269. : "=r" (x) : : "memory", "cc"); \
  270. })
  271. /*
  272. * restore saved IRQ & FIQ state
  273. */
  274. #define local_irq_restore(x) \
  275. __asm__ __volatile__( \
  276. "msr cpsr_c, %0 @ local_irq_restore\n" \
  277. : \
  278. : "r" (x) \
  279. : "memory", "cc")
  280. #define irqs_disabled() \
  281. ({ \
  282. unsigned long flags; \
  283. local_save_flags(flags); \
  284. (int)(flags & PSR_I_BIT); \
  285. })
  286. #ifdef CONFIG_SMP
  287. #define smp_mb() mb()
  288. #define smp_rmb() rmb()
  289. #define smp_wmb() wmb()
  290. #define smp_read_barrier_depends() read_barrier_depends()
  291. #else
  292. #define smp_mb() barrier()
  293. #define smp_rmb() barrier()
  294. #define smp_wmb() barrier()
  295. #define smp_read_barrier_depends() do { } while(0)
  296. #endif /* CONFIG_SMP */
  297. #if defined(CONFIG_CPU_SA1100) || defined(CONFIG_CPU_SA110)
  298. /*
  299. * On the StrongARM, "swp" is terminally broken since it bypasses the
  300. * cache totally. This means that the cache becomes inconsistent, and,
  301. * since we use normal loads/stores as well, this is really bad.
  302. * Typically, this causes oopsen in filp_close, but could have other,
  303. * more disasterous effects. There are two work-arounds:
  304. * 1. Disable interrupts and emulate the atomic swap
  305. * 2. Clean the cache, perform atomic swap, flush the cache
  306. *
  307. * We choose (1) since its the "easiest" to achieve here and is not
  308. * dependent on the processor type.
  309. *
  310. * NOTE that this solution won't work on an SMP system, so explcitly
  311. * forbid it here.
  312. */
  313. #define swp_is_buggy
  314. #endif
  315. static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
  316. {
  317. extern void __bad_xchg(volatile void *, int);
  318. unsigned long ret;
  319. #ifdef swp_is_buggy
  320. unsigned long flags;
  321. #endif
  322. #if __LINUX_ARM_ARCH__ >= 6
  323. unsigned int tmp;
  324. #endif
  325. switch (size) {
  326. #if __LINUX_ARM_ARCH__ >= 6
  327. case 1:
  328. asm volatile("@ __xchg1\n"
  329. "1: ldrexb %0, [%3]\n"
  330. " strexb %1, %2, [%3]\n"
  331. " teq %1, #0\n"
  332. " bne 1b"
  333. : "=&r" (ret), "=&r" (tmp)
  334. : "r" (x), "r" (ptr)
  335. : "memory", "cc");
  336. break;
  337. case 4:
  338. asm volatile("@ __xchg4\n"
  339. "1: ldrex %0, [%3]\n"
  340. " strex %1, %2, [%3]\n"
  341. " teq %1, #0\n"
  342. " bne 1b"
  343. : "=&r" (ret), "=&r" (tmp)
  344. : "r" (x), "r" (ptr)
  345. : "memory", "cc");
  346. break;
  347. #elif defined(swp_is_buggy)
  348. #ifdef CONFIG_SMP
  349. #error SMP is not supported on this platform
  350. #endif
  351. case 1:
  352. local_irq_save(flags);
  353. ret = *(volatile unsigned char *)ptr;
  354. *(volatile unsigned char *)ptr = x;
  355. local_irq_restore(flags);
  356. break;
  357. case 4:
  358. local_irq_save(flags);
  359. ret = *(volatile unsigned long *)ptr;
  360. *(volatile unsigned long *)ptr = x;
  361. local_irq_restore(flags);
  362. break;
  363. #else
  364. case 1:
  365. asm volatile("@ __xchg1\n"
  366. " swpb %0, %1, [%2]"
  367. : "=&r" (ret)
  368. : "r" (x), "r" (ptr)
  369. : "memory", "cc");
  370. break;
  371. case 4:
  372. asm volatile("@ __xchg4\n"
  373. " swp %0, %1, [%2]"
  374. : "=&r" (ret)
  375. : "r" (x), "r" (ptr)
  376. : "memory", "cc");
  377. break;
  378. #endif
  379. default:
  380. __bad_xchg(ptr, size), ret = 0;
  381. break;
  382. }
  383. return ret;
  384. }
  385. extern void disable_hlt(void);
  386. extern void enable_hlt(void);
  387. #endif /* __ASSEMBLY__ */
  388. #define arch_align_stack(x) (x)
  389. #endif /* __KERNEL__ */
  390. #endif