system.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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/irqflags.h>
  70. #define __exception __attribute__((section(".exception.text")))
  71. struct thread_info;
  72. struct task_struct;
  73. /* information about the system we're running on */
  74. extern unsigned int system_rev;
  75. extern unsigned int system_serial_low;
  76. extern unsigned int system_serial_high;
  77. extern unsigned int mem_fclk_21285;
  78. struct pt_regs;
  79. void die(const char *msg, struct pt_regs *regs, int err)
  80. __attribute__((noreturn));
  81. struct siginfo;
  82. void arm_notify_die(const char *str, struct pt_regs *regs, struct siginfo *info,
  83. unsigned long err, unsigned long trap);
  84. void hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int,
  85. struct pt_regs *),
  86. int sig, const char *name);
  87. #define xchg(ptr,x) \
  88. ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  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 __LINUX_ARM_ARCH__ >= 7
  131. #define isb() __asm__ __volatile__ ("isb" : : : "memory")
  132. #define dsb() __asm__ __volatile__ ("dsb" : : : "memory")
  133. #define dmb() __asm__ __volatile__ ("dmb" : : : "memory")
  134. #elif defined(CONFIG_CPU_XSC3) || __LINUX_ARM_ARCH__ == 6
  135. #define isb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c5, 4" \
  136. : : "r" (0) : "memory")
  137. #define dsb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" \
  138. : : "r" (0) : "memory")
  139. #define dmb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" \
  140. : : "r" (0) : "memory")
  141. #else
  142. #define isb() __asm__ __volatile__ ("" : : : "memory")
  143. #define dsb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" \
  144. : : "r" (0) : "memory")
  145. #define dmb() __asm__ __volatile__ ("" : : : "memory")
  146. #endif
  147. #ifndef CONFIG_SMP
  148. #define mb() do { if (arch_is_coherent()) dmb(); else barrier(); } while (0)
  149. #define rmb() do { if (arch_is_coherent()) dmb(); else barrier(); } while (0)
  150. #define wmb() do { if (arch_is_coherent()) dmb(); else barrier(); } while (0)
  151. #define smp_mb() barrier()
  152. #define smp_rmb() barrier()
  153. #define smp_wmb() barrier()
  154. #else
  155. #define mb() dmb()
  156. #define rmb() dmb()
  157. #define wmb() dmb()
  158. #define smp_mb() dmb()
  159. #define smp_rmb() dmb()
  160. #define smp_wmb() dmb()
  161. #endif
  162. #define read_barrier_depends() do { } while(0)
  163. #define smp_read_barrier_depends() do { } while(0)
  164. #define set_mb(var, value) do { var = value; smp_mb(); } while (0)
  165. #define nop() __asm__ __volatile__("mov\tr0,r0\t@ nop\n\t");
  166. extern unsigned long cr_no_alignment; /* defined in entry-armv.S */
  167. extern unsigned long cr_alignment; /* defined in entry-armv.S */
  168. static inline unsigned int get_cr(void)
  169. {
  170. unsigned int val;
  171. asm("mrc p15, 0, %0, c1, c0, 0 @ get CR" : "=r" (val) : : "cc");
  172. return val;
  173. }
  174. static inline void set_cr(unsigned int val)
  175. {
  176. asm volatile("mcr p15, 0, %0, c1, c0, 0 @ set CR"
  177. : : "r" (val) : "cc");
  178. isb();
  179. }
  180. #ifndef CONFIG_SMP
  181. extern void adjust_cr(unsigned long mask, unsigned long set);
  182. #endif
  183. #define CPACC_FULL(n) (3 << (n * 2))
  184. #define CPACC_SVC(n) (1 << (n * 2))
  185. #define CPACC_DISABLE(n) (0 << (n * 2))
  186. static inline unsigned int get_copro_access(void)
  187. {
  188. unsigned int val;
  189. asm("mrc p15, 0, %0, c1, c0, 2 @ get copro access"
  190. : "=r" (val) : : "cc");
  191. return val;
  192. }
  193. static inline void set_copro_access(unsigned int val)
  194. {
  195. asm volatile("mcr p15, 0, %0, c1, c0, 2 @ set copro access"
  196. : : "r" (val) : "cc");
  197. isb();
  198. }
  199. /*
  200. * switch_mm() may do a full cache flush over the context switch,
  201. * so enable interrupts over the context switch to avoid high
  202. * latency.
  203. */
  204. #define __ARCH_WANT_INTERRUPTS_ON_CTXSW
  205. /*
  206. * switch_to(prev, next) should switch from task `prev' to `next'
  207. * `prev' will never be the same as `next'. schedule() itself
  208. * contains the memory barrier to tell GCC not to cache `current'.
  209. */
  210. extern struct task_struct *__switch_to(struct task_struct *, struct thread_info *, struct thread_info *);
  211. #define switch_to(prev,next,last) \
  212. do { \
  213. last = __switch_to(prev,task_thread_info(prev), task_thread_info(next)); \
  214. } while (0)
  215. /*
  216. * On SMP systems, when the scheduler does migration-cost autodetection,
  217. * it needs a way to flush as much of the CPU's caches as possible.
  218. *
  219. * TODO: fill this in!
  220. */
  221. static inline void sched_cacheflush(void)
  222. {
  223. }
  224. #if defined(CONFIG_CPU_SA1100) || defined(CONFIG_CPU_SA110)
  225. /*
  226. * On the StrongARM, "swp" is terminally broken since it bypasses the
  227. * cache totally. This means that the cache becomes inconsistent, and,
  228. * since we use normal loads/stores as well, this is really bad.
  229. * Typically, this causes oopsen in filp_close, but could have other,
  230. * more disasterous effects. There are two work-arounds:
  231. * 1. Disable interrupts and emulate the atomic swap
  232. * 2. Clean the cache, perform atomic swap, flush the cache
  233. *
  234. * We choose (1) since its the "easiest" to achieve here and is not
  235. * dependent on the processor type.
  236. *
  237. * NOTE that this solution won't work on an SMP system, so explcitly
  238. * forbid it here.
  239. */
  240. #define swp_is_buggy
  241. #endif
  242. static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
  243. {
  244. extern void __bad_xchg(volatile void *, int);
  245. unsigned long ret;
  246. #ifdef swp_is_buggy
  247. unsigned long flags;
  248. #endif
  249. #if __LINUX_ARM_ARCH__ >= 6
  250. unsigned int tmp;
  251. #endif
  252. switch (size) {
  253. #if __LINUX_ARM_ARCH__ >= 6
  254. case 1:
  255. asm volatile("@ __xchg1\n"
  256. "1: ldrexb %0, [%3]\n"
  257. " strexb %1, %2, [%3]\n"
  258. " teq %1, #0\n"
  259. " bne 1b"
  260. : "=&r" (ret), "=&r" (tmp)
  261. : "r" (x), "r" (ptr)
  262. : "memory", "cc");
  263. break;
  264. case 4:
  265. asm volatile("@ __xchg4\n"
  266. "1: ldrex %0, [%3]\n"
  267. " strex %1, %2, [%3]\n"
  268. " teq %1, #0\n"
  269. " bne 1b"
  270. : "=&r" (ret), "=&r" (tmp)
  271. : "r" (x), "r" (ptr)
  272. : "memory", "cc");
  273. break;
  274. #elif defined(swp_is_buggy)
  275. #ifdef CONFIG_SMP
  276. #error SMP is not supported on this platform
  277. #endif
  278. case 1:
  279. raw_local_irq_save(flags);
  280. ret = *(volatile unsigned char *)ptr;
  281. *(volatile unsigned char *)ptr = x;
  282. raw_local_irq_restore(flags);
  283. break;
  284. case 4:
  285. raw_local_irq_save(flags);
  286. ret = *(volatile unsigned long *)ptr;
  287. *(volatile unsigned long *)ptr = x;
  288. raw_local_irq_restore(flags);
  289. break;
  290. #else
  291. case 1:
  292. asm volatile("@ __xchg1\n"
  293. " swpb %0, %1, [%2]"
  294. : "=&r" (ret)
  295. : "r" (x), "r" (ptr)
  296. : "memory", "cc");
  297. break;
  298. case 4:
  299. asm volatile("@ __xchg4\n"
  300. " swp %0, %1, [%2]"
  301. : "=&r" (ret)
  302. : "r" (x), "r" (ptr)
  303. : "memory", "cc");
  304. break;
  305. #endif
  306. default:
  307. __bad_xchg(ptr, size), ret = 0;
  308. break;
  309. }
  310. return ret;
  311. }
  312. extern void disable_hlt(void);
  313. extern void enable_hlt(void);
  314. #endif /* __ASSEMBLY__ */
  315. #define arch_align_stack(x) (x)
  316. #endif /* __KERNEL__ */
  317. #endif