system.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. #ifndef __ASM_ARM_SYSTEM_H
  2. #define __ASM_ARM_SYSTEM_H
  3. #ifdef __KERNEL__
  4. #include <asm/memory.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. #ifdef CONFIG_CPU_CP15
  45. #define read_cpuid(reg) \
  46. ({ \
  47. unsigned int __val; \
  48. asm("mrc p15, 0, %0, c0, c0, " __stringify(reg) \
  49. : "=r" (__val) \
  50. : \
  51. : "cc"); \
  52. __val; \
  53. })
  54. #else
  55. #define read_cpuid(reg) (processor_id)
  56. #endif
  57. /*
  58. * This is used to ensure the compiler did actually allocate the register we
  59. * asked it for some inline assembly sequences. Apparently we can't trust
  60. * the compiler from one version to another so a bit of paranoia won't hurt.
  61. * This string is meant to be concatenated with the inline asm string and
  62. * will cause compilation to stop on mismatch.
  63. * (for details, see gcc PR 15089)
  64. */
  65. #define __asmeq(x, y) ".ifnc " x "," y " ; .err ; .endif\n\t"
  66. #ifndef __ASSEMBLY__
  67. #include <linux/linkage.h>
  68. #include <linux/irqflags.h>
  69. #define __exception __attribute__((section(".exception.text")))
  70. struct thread_info;
  71. struct task_struct;
  72. /* information about the system we're running on */
  73. extern unsigned int system_rev;
  74. extern unsigned int system_serial_low;
  75. extern unsigned int system_serial_high;
  76. extern unsigned int mem_fclk_21285;
  77. struct pt_regs;
  78. void die(const char *msg, struct pt_regs *regs, int err)
  79. __attribute__((noreturn));
  80. struct siginfo;
  81. void arm_notify_die(const char *str, struct pt_regs *regs, struct siginfo *info,
  82. unsigned long err, unsigned long trap);
  83. void hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int,
  84. struct pt_regs *),
  85. int sig, const char *name);
  86. #define xchg(ptr,x) \
  87. ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  88. #define tas(ptr) (xchg((ptr),1))
  89. extern asmlinkage void __backtrace(void);
  90. extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
  91. struct mm_struct;
  92. extern void show_pte(struct mm_struct *mm, unsigned long addr);
  93. extern void __show_regs(struct pt_regs *);
  94. extern int cpu_architecture(void);
  95. extern void cpu_init(void);
  96. void arm_machine_restart(char mode);
  97. extern void (*arm_pm_restart)(char str);
  98. /*
  99. * Intel's XScale3 core supports some v6 features (supersections, L2)
  100. * but advertises itself as v5 as it does not support the v6 ISA. For
  101. * this reason, we need a way to explicitly test for this type of CPU.
  102. */
  103. #ifndef CONFIG_CPU_XSC3
  104. #define cpu_is_xsc3() 0
  105. #else
  106. static inline int cpu_is_xsc3(void)
  107. {
  108. extern unsigned int processor_id;
  109. if ((processor_id & 0xffffe000) == 0x69056000)
  110. return 1;
  111. return 0;
  112. }
  113. #endif
  114. #if !defined(CONFIG_CPU_XSCALE) && !defined(CONFIG_CPU_XSC3)
  115. #define cpu_is_xscale() 0
  116. #else
  117. #define cpu_is_xscale() 1
  118. #endif
  119. #define UDBG_UNDEFINED (1 << 0)
  120. #define UDBG_SYSCALL (1 << 1)
  121. #define UDBG_BADABORT (1 << 2)
  122. #define UDBG_SEGV (1 << 3)
  123. #define UDBG_BUS (1 << 4)
  124. extern unsigned int user_debug;
  125. #if __LINUX_ARM_ARCH__ >= 4
  126. #define vectors_high() (cr_alignment & CR_V)
  127. #else
  128. #define vectors_high() (0)
  129. #endif
  130. #if defined(CONFIG_CPU_XSC3) || __LINUX_ARM_ARCH__ >= 6
  131. #define isb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c5, 4" \
  132. : : "r" (0) : "memory")
  133. #define dsb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" \
  134. : : "r" (0) : "memory")
  135. #define dmb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" \
  136. : : "r" (0) : "memory")
  137. #else
  138. #define isb() __asm__ __volatile__ ("" : : : "memory")
  139. #define dsb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" \
  140. : : "r" (0) : "memory")
  141. #define dmb() __asm__ __volatile__ ("" : : : "memory")
  142. #endif
  143. #ifndef CONFIG_SMP
  144. #define mb() do { if (arch_is_coherent()) dmb(); else barrier(); } while (0)
  145. #define rmb() do { if (arch_is_coherent()) dmb(); else barrier(); } while (0)
  146. #define wmb() do { if (arch_is_coherent()) dmb(); else barrier(); } while (0)
  147. #define smp_mb() barrier()
  148. #define smp_rmb() barrier()
  149. #define smp_wmb() barrier()
  150. #else
  151. #define mb() dmb()
  152. #define rmb() dmb()
  153. #define wmb() dmb()
  154. #define smp_mb() dmb()
  155. #define smp_rmb() dmb()
  156. #define smp_wmb() dmb()
  157. #endif
  158. #define read_barrier_depends() do { } while(0)
  159. #define smp_read_barrier_depends() do { } while(0)
  160. #define set_mb(var, value) do { var = value; smp_mb(); } while (0)
  161. #define nop() __asm__ __volatile__("mov\tr0,r0\t@ nop\n\t");
  162. extern unsigned long cr_no_alignment; /* defined in entry-armv.S */
  163. extern unsigned long cr_alignment; /* defined in entry-armv.S */
  164. static inline unsigned int get_cr(void)
  165. {
  166. unsigned int val;
  167. asm("mrc p15, 0, %0, c1, c0, 0 @ get CR" : "=r" (val) : : "cc");
  168. return val;
  169. }
  170. static inline void set_cr(unsigned int val)
  171. {
  172. asm volatile("mcr p15, 0, %0, c1, c0, 0 @ set CR"
  173. : : "r" (val) : "cc");
  174. isb();
  175. }
  176. #ifndef CONFIG_SMP
  177. extern void adjust_cr(unsigned long mask, unsigned long set);
  178. #endif
  179. #define CPACC_FULL(n) (3 << (n * 2))
  180. #define CPACC_SVC(n) (1 << (n * 2))
  181. #define CPACC_DISABLE(n) (0 << (n * 2))
  182. static inline unsigned int get_copro_access(void)
  183. {
  184. unsigned int val;
  185. asm("mrc p15, 0, %0, c1, c0, 2 @ get copro access"
  186. : "=r" (val) : : "cc");
  187. return val;
  188. }
  189. static inline void set_copro_access(unsigned int val)
  190. {
  191. asm volatile("mcr p15, 0, %0, c1, c0, 2 @ set copro access"
  192. : : "r" (val) : "cc");
  193. isb();
  194. }
  195. /*
  196. * switch_mm() may do a full cache flush over the context switch,
  197. * so enable interrupts over the context switch to avoid high
  198. * latency.
  199. */
  200. #define __ARCH_WANT_INTERRUPTS_ON_CTXSW
  201. /*
  202. * switch_to(prev, next) should switch from task `prev' to `next'
  203. * `prev' will never be the same as `next'. schedule() itself
  204. * contains the memory barrier to tell GCC not to cache `current'.
  205. */
  206. extern struct task_struct *__switch_to(struct task_struct *, struct thread_info *, struct thread_info *);
  207. #define switch_to(prev,next,last) \
  208. do { \
  209. last = __switch_to(prev,task_thread_info(prev), task_thread_info(next)); \
  210. } while (0)
  211. /*
  212. * On SMP systems, when the scheduler does migration-cost autodetection,
  213. * it needs a way to flush as much of the CPU's caches as possible.
  214. *
  215. * TODO: fill this in!
  216. */
  217. static inline void sched_cacheflush(void)
  218. {
  219. }
  220. #if defined(CONFIG_CPU_SA1100) || defined(CONFIG_CPU_SA110)
  221. /*
  222. * On the StrongARM, "swp" is terminally broken since it bypasses the
  223. * cache totally. This means that the cache becomes inconsistent, and,
  224. * since we use normal loads/stores as well, this is really bad.
  225. * Typically, this causes oopsen in filp_close, but could have other,
  226. * more disasterous effects. There are two work-arounds:
  227. * 1. Disable interrupts and emulate the atomic swap
  228. * 2. Clean the cache, perform atomic swap, flush the cache
  229. *
  230. * We choose (1) since its the "easiest" to achieve here and is not
  231. * dependent on the processor type.
  232. *
  233. * NOTE that this solution won't work on an SMP system, so explcitly
  234. * forbid it here.
  235. */
  236. #define swp_is_buggy
  237. #endif
  238. static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
  239. {
  240. extern void __bad_xchg(volatile void *, int);
  241. unsigned long ret;
  242. #ifdef swp_is_buggy
  243. unsigned long flags;
  244. #endif
  245. #if __LINUX_ARM_ARCH__ >= 6
  246. unsigned int tmp;
  247. #endif
  248. switch (size) {
  249. #if __LINUX_ARM_ARCH__ >= 6
  250. case 1:
  251. asm volatile("@ __xchg1\n"
  252. "1: ldrexb %0, [%3]\n"
  253. " strexb %1, %2, [%3]\n"
  254. " teq %1, #0\n"
  255. " bne 1b"
  256. : "=&r" (ret), "=&r" (tmp)
  257. : "r" (x), "r" (ptr)
  258. : "memory", "cc");
  259. break;
  260. case 4:
  261. asm volatile("@ __xchg4\n"
  262. "1: ldrex %0, [%3]\n"
  263. " strex %1, %2, [%3]\n"
  264. " teq %1, #0\n"
  265. " bne 1b"
  266. : "=&r" (ret), "=&r" (tmp)
  267. : "r" (x), "r" (ptr)
  268. : "memory", "cc");
  269. break;
  270. #elif defined(swp_is_buggy)
  271. #ifdef CONFIG_SMP
  272. #error SMP is not supported on this platform
  273. #endif
  274. case 1:
  275. raw_local_irq_save(flags);
  276. ret = *(volatile unsigned char *)ptr;
  277. *(volatile unsigned char *)ptr = x;
  278. raw_local_irq_restore(flags);
  279. break;
  280. case 4:
  281. raw_local_irq_save(flags);
  282. ret = *(volatile unsigned long *)ptr;
  283. *(volatile unsigned long *)ptr = x;
  284. raw_local_irq_restore(flags);
  285. break;
  286. #else
  287. case 1:
  288. asm volatile("@ __xchg1\n"
  289. " swpb %0, %1, [%2]"
  290. : "=&r" (ret)
  291. : "r" (x), "r" (ptr)
  292. : "memory", "cc");
  293. break;
  294. case 4:
  295. asm volatile("@ __xchg4\n"
  296. " swp %0, %1, [%2]"
  297. : "=&r" (ret)
  298. : "r" (x), "r" (ptr)
  299. : "memory", "cc");
  300. break;
  301. #endif
  302. default:
  303. __bad_xchg(ptr, size), ret = 0;
  304. break;
  305. }
  306. return ret;
  307. }
  308. extern void disable_hlt(void);
  309. extern void enable_hlt(void);
  310. #endif /* __ASSEMBLY__ */
  311. #define arch_align_stack(x) (x)
  312. #endif /* __KERNEL__ */
  313. #endif