system.h 9.3 KB

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