system.h 10 KB

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