blob: 95b3abf4851bb9cc70596edd3a239076910939ee [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __ASM_ARM_SYSTEM_H
2#define __ASM_ARM_SYSTEM_H
3
4#ifdef __KERNEL__
5
6#include <linux/config.h>
7
8#define CPU_ARCH_UNKNOWN 0
9#define CPU_ARCH_ARMv3 1
10#define CPU_ARCH_ARMv4 2
11#define CPU_ARCH_ARMv4T 3
12#define CPU_ARCH_ARMv5 4
13#define CPU_ARCH_ARMv5T 5
14#define CPU_ARCH_ARMv5TE 6
15#define CPU_ARCH_ARMv5TEJ 7
16#define CPU_ARCH_ARMv6 8
17
18/*
19 * CR1 bits (CP#15 CR1)
20 */
21#define CR_M (1 << 0) /* MMU enable */
22#define CR_A (1 << 1) /* Alignment abort enable */
23#define CR_C (1 << 2) /* Dcache enable */
24#define CR_W (1 << 3) /* Write buffer enable */
25#define CR_P (1 << 4) /* 32-bit exception handler */
26#define CR_D (1 << 5) /* 32-bit data address range */
27#define CR_L (1 << 6) /* Implementation defined */
28#define CR_B (1 << 7) /* Big endian */
29#define CR_S (1 << 8) /* System MMU protection */
30#define CR_R (1 << 9) /* ROM MMU protection */
31#define CR_F (1 << 10) /* Implementation defined */
32#define CR_Z (1 << 11) /* Implementation defined */
33#define CR_I (1 << 12) /* Icache enable */
34#define CR_V (1 << 13) /* Vectors relocated to 0xffff0000 */
35#define CR_RR (1 << 14) /* Round Robin cache replacement */
36#define CR_L4 (1 << 15) /* LDR pc can set T bit */
37#define CR_DT (1 << 16)
38#define CR_IT (1 << 18)
39#define CR_ST (1 << 19)
40#define CR_FI (1 << 21) /* Fast interrupt (lower latency mode) */
41#define CR_U (1 << 22) /* Unaligned access operation */
42#define CR_XP (1 << 23) /* Extended page tables */
43#define CR_VE (1 << 24) /* Vectored interrupts */
44
45#define CPUID_ID 0
46#define CPUID_CACHETYPE 1
47#define CPUID_TCM 2
48#define CPUID_TLBTYPE 3
49
50#define read_cpuid(reg) \
51 ({ \
52 unsigned int __val; \
53 asm("mrc p15, 0, %0, c0, c0, " __stringify(reg) \
54 : "=r" (__val) \
55 : \
56 : "cc"); \
57 __val; \
58 })
59
60/*
61 * This is used to ensure the compiler did actually allocate the register we
62 * asked it for some inline assembly sequences. Apparently we can't trust
63 * the compiler from one version to another so a bit of paranoia won't hurt.
64 * This string is meant to be concatenated with the inline asm string and
65 * will cause compilation to stop on mismatch.
66 * (for details, see gcc PR 15089)
67 */
68#define __asmeq(x, y) ".ifnc " x "," y " ; .err ; .endif\n\t"
69
70#ifndef __ASSEMBLY__
71
72#include <linux/linkage.h>
73
74struct thread_info;
75struct task_struct;
76
77/* information about the system we're running on */
78extern unsigned int system_rev;
79extern unsigned int system_serial_low;
80extern unsigned int system_serial_high;
81extern unsigned int mem_fclk_21285;
82
83struct pt_regs;
84
85void die(const char *msg, struct pt_regs *regs, int err)
86 __attribute__((noreturn));
87
Russell Kingcfb08102005-06-30 11:06:49 +010088struct siginfo;
89void notify_die(const char *str, struct pt_regs *regs, struct siginfo *info,
90 unsigned long err, unsigned long trap);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92void hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int,
93 struct pt_regs *),
94 int sig, const char *name);
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#define xchg(ptr,x) \
97 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
98
99#define tas(ptr) (xchg((ptr),1))
100
101extern asmlinkage void __backtrace(void);
Russell King652a12e2005-04-17 15:50:36 +0100102extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
Russell King5470dc62005-11-16 18:36:49 +0000103
104struct mm_struct;
Russell King652a12e2005-04-17 15:50:36 +0100105extern void show_pte(struct mm_struct *mm, unsigned long addr);
106extern void __show_regs(struct pt_regs *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108extern int cpu_architecture(void);
Russell King36c5ed22005-06-19 18:39:33 +0100109extern void cpu_init(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Lennert Buytenhek23bdf862006-03-28 21:00:40 +0100111/*
112 * Intel's XScale3 core supports some v6 features (supersections, L2)
113 * but advertises itself as v5 as it does not support the v6 ISA. For
114 * this reason, we need a way to explicitly test for this type of CPU.
115 */
116#ifndef CONFIG_CPU_XSC3
117#define cpu_is_xsc3() 0
118#else
119static inline int cpu_is_xsc3(void)
120{
121 extern unsigned int processor_id;
122
123 if ((processor_id & 0xffffe000) == 0x69056000)
124 return 1;
125
126 return 0;
127}
128#endif
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130#define set_cr(x) \
131 __asm__ __volatile__( \
132 "mcr p15, 0, %0, c1, c0, 0 @ set CR" \
133 : : "r" (x) : "cc")
134
135#define get_cr() \
136 ({ \
137 unsigned int __val; \
138 __asm__ __volatile__( \
139 "mrc p15, 0, %0, c1, c0, 0 @ get CR" \
140 : "=r" (__val) : : "cc"); \
141 __val; \
142 })
143
144extern unsigned long cr_no_alignment; /* defined in entry-armv.S */
145extern unsigned long cr_alignment; /* defined in entry-armv.S */
146
147#define UDBG_UNDEFINED (1 << 0)
148#define UDBG_SYSCALL (1 << 1)
149#define UDBG_BADABORT (1 << 2)
150#define UDBG_SEGV (1 << 3)
151#define UDBG_BUS (1 << 4)
152
153extern unsigned int user_debug;
154
155#if __LINUX_ARM_ARCH__ >= 4
156#define vectors_high() (cr_alignment & CR_V)
157#else
158#define vectors_high() (0)
159#endif
160
Russell King6d9b37a2005-07-26 19:44:26 +0100161#if __LINUX_ARM_ARCH__ >= 6
162#define mb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" \
163 : : "r" (0) : "memory")
164#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165#define mb() __asm__ __volatile__ ("" : : : "memory")
Russell King6d9b37a2005-07-26 19:44:26 +0100166#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167#define rmb() mb()
168#define wmb() mb()
169#define read_barrier_depends() do { } while(0)
170#define set_mb(var, value) do { var = value; mb(); } while (0)
171#define set_wmb(var, value) do { var = value; wmb(); } while (0)
172#define nop() __asm__ __volatile__("mov\tr0,r0\t@ nop\n\t");
173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174/*
Nick Piggin4866cde2005-06-25 14:57:23 -0700175 * switch_mm() may do a full cache flush over the context switch,
176 * so enable interrupts over the context switch to avoid high
177 * latency.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 */
Nick Piggin4866cde2005-06-25 14:57:23 -0700179#define __ARCH_WANT_INTERRUPTS_ON_CTXSW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181/*
182 * switch_to(prev, next) should switch from task `prev' to `next'
183 * `prev' will never be the same as `next'. schedule() itself
184 * contains the memory barrier to tell GCC not to cache `current'.
185 */
186extern struct task_struct *__switch_to(struct task_struct *, struct thread_info *, struct thread_info *);
187
188#define switch_to(prev,next,last) \
189do { \
Al Viroe7c1b322006-01-12 01:05:56 -0800190 last = __switch_to(prev,task_thread_info(prev), task_thread_info(next)); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191} while (0)
192
193/*
Ingo Molnar4dc7a0b2006-01-12 01:05:27 -0800194 * On SMP systems, when the scheduler does migration-cost autodetection,
195 * it needs a way to flush as much of the CPU's caches as possible.
196 *
197 * TODO: fill this in!
198 */
199static inline void sched_cacheflush(void)
200{
201}
202
203/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 * CPU interrupt mask handling.
205 */
206#if __LINUX_ARM_ARCH__ >= 6
207
208#define local_irq_save(x) \
209 ({ \
210 __asm__ __volatile__( \
211 "mrs %0, cpsr @ local_irq_save\n" \
212 "cpsid i" \
213 : "=r" (x) : : "memory", "cc"); \
214 })
215
216#define local_irq_enable() __asm__("cpsie i @ __sti" : : : "memory", "cc")
217#define local_irq_disable() __asm__("cpsid i @ __cli" : : : "memory", "cc")
218#define local_fiq_enable() __asm__("cpsie f @ __stf" : : : "memory", "cc")
219#define local_fiq_disable() __asm__("cpsid f @ __clf" : : : "memory", "cc")
220
221#else
222
223/*
224 * Save the current interrupt enable state & disable IRQs
225 */
226#define local_irq_save(x) \
227 ({ \
228 unsigned long temp; \
229 (void) (&temp == &x); \
230 __asm__ __volatile__( \
231 "mrs %0, cpsr @ local_irq_save\n" \
232" orr %1, %0, #128\n" \
233" msr cpsr_c, %1" \
234 : "=r" (x), "=r" (temp) \
235 : \
236 : "memory", "cc"); \
237 })
238
239/*
240 * Enable IRQs
241 */
242#define local_irq_enable() \
243 ({ \
244 unsigned long temp; \
245 __asm__ __volatile__( \
246 "mrs %0, cpsr @ local_irq_enable\n" \
247" bic %0, %0, #128\n" \
248" msr cpsr_c, %0" \
249 : "=r" (temp) \
250 : \
251 : "memory", "cc"); \
252 })
253
254/*
255 * Disable IRQs
256 */
257#define local_irq_disable() \
258 ({ \
259 unsigned long temp; \
260 __asm__ __volatile__( \
261 "mrs %0, cpsr @ local_irq_disable\n" \
262" orr %0, %0, #128\n" \
263" msr cpsr_c, %0" \
264 : "=r" (temp) \
265 : \
266 : "memory", "cc"); \
267 })
268
269/*
270 * Enable FIQs
271 */
272#define local_fiq_enable() \
273 ({ \
274 unsigned long temp; \
275 __asm__ __volatile__( \
276 "mrs %0, cpsr @ stf\n" \
277" bic %0, %0, #64\n" \
278" msr cpsr_c, %0" \
279 : "=r" (temp) \
280 : \
281 : "memory", "cc"); \
282 })
283
284/*
285 * Disable FIQs
286 */
287#define local_fiq_disable() \
288 ({ \
289 unsigned long temp; \
290 __asm__ __volatile__( \
291 "mrs %0, cpsr @ clf\n" \
292" orr %0, %0, #64\n" \
293" msr cpsr_c, %0" \
294 : "=r" (temp) \
295 : \
296 : "memory", "cc"); \
297 })
298
299#endif
300
301/*
302 * Save the current interrupt enable state.
303 */
304#define local_save_flags(x) \
305 ({ \
306 __asm__ __volatile__( \
307 "mrs %0, cpsr @ local_save_flags" \
308 : "=r" (x) : : "memory", "cc"); \
309 })
310
311/*
312 * restore saved IRQ & FIQ state
313 */
314#define local_irq_restore(x) \
315 __asm__ __volatile__( \
316 "msr cpsr_c, %0 @ local_irq_restore\n" \
317 : \
318 : "r" (x) \
319 : "memory", "cc")
320
321#define irqs_disabled() \
322({ \
323 unsigned long flags; \
324 local_save_flags(flags); \
Andrew Morton9a558cb2005-06-21 17:14:28 -0700325 (int)(flags & PSR_I_BIT); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326})
327
328#ifdef CONFIG_SMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
330#define smp_mb() mb()
331#define smp_rmb() rmb()
332#define smp_wmb() wmb()
333#define smp_read_barrier_depends() read_barrier_depends()
334
335#else
336
337#define smp_mb() barrier()
338#define smp_rmb() barrier()
339#define smp_wmb() barrier()
340#define smp_read_barrier_depends() do { } while(0)
341
Russell King053a7b52005-06-28 19:22:25 +0100342#endif /* CONFIG_SMP */
343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344#if defined(CONFIG_CPU_SA1100) || defined(CONFIG_CPU_SA110)
345/*
346 * On the StrongARM, "swp" is terminally broken since it bypasses the
347 * cache totally. This means that the cache becomes inconsistent, and,
348 * since we use normal loads/stores as well, this is really bad.
349 * Typically, this causes oopsen in filp_close, but could have other,
350 * more disasterous effects. There are two work-arounds:
351 * 1. Disable interrupts and emulate the atomic swap
352 * 2. Clean the cache, perform atomic swap, flush the cache
353 *
354 * We choose (1) since its the "easiest" to achieve here and is not
355 * dependent on the processor type.
Russell King053a7b52005-06-28 19:22:25 +0100356 *
357 * NOTE that this solution won't work on an SMP system, so explcitly
358 * forbid it here.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 */
360#define swp_is_buggy
361#endif
362
363static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
364{
365 extern void __bad_xchg(volatile void *, int);
366 unsigned long ret;
367#ifdef swp_is_buggy
368 unsigned long flags;
369#endif
Russell King95607822005-07-26 19:39:31 +0100370#if __LINUX_ARM_ARCH__ >= 6
371 unsigned int tmp;
372#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374 switch (size) {
Russell King95607822005-07-26 19:39:31 +0100375#if __LINUX_ARM_ARCH__ >= 6
376 case 1:
377 asm volatile("@ __xchg1\n"
378 "1: ldrexb %0, [%3]\n"
379 " strexb %1, %2, [%3]\n"
380 " teq %1, #0\n"
381 " bne 1b"
382 : "=&r" (ret), "=&r" (tmp)
383 : "r" (x), "r" (ptr)
384 : "memory", "cc");
385 break;
386 case 4:
387 asm volatile("@ __xchg4\n"
388 "1: ldrex %0, [%3]\n"
389 " strex %1, %2, [%3]\n"
390 " teq %1, #0\n"
391 " bne 1b"
392 : "=&r" (ret), "=&r" (tmp)
393 : "r" (x), "r" (ptr)
394 : "memory", "cc");
395 break;
396#elif defined(swp_is_buggy)
397#ifdef CONFIG_SMP
398#error SMP is not supported on this platform
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399#endif
Russell King95607822005-07-26 19:39:31 +0100400 case 1:
401 local_irq_save(flags);
402 ret = *(volatile unsigned char *)ptr;
403 *(volatile unsigned char *)ptr = x;
404 local_irq_restore(flags);
405 break;
406
407 case 4:
408 local_irq_save(flags);
409 ret = *(volatile unsigned long *)ptr;
410 *(volatile unsigned long *)ptr = x;
411 local_irq_restore(flags);
412 break;
413#else
414 case 1:
415 asm volatile("@ __xchg1\n"
416 " swpb %0, %1, [%2]"
417 : "=&r" (ret)
418 : "r" (x), "r" (ptr)
419 : "memory", "cc");
420 break;
421 case 4:
422 asm volatile("@ __xchg4\n"
423 " swp %0, %1, [%2]"
424 : "=&r" (ret)
425 : "r" (x), "r" (ptr)
426 : "memory", "cc");
427 break;
428#endif
429 default:
430 __bad_xchg(ptr, size), ret = 0;
431 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 }
433
434 return ret;
435}
436
Ben Dooksdabaeff2006-03-15 23:17:26 +0000437extern void disable_hlt(void);
438extern void enable_hlt(void);
439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440#endif /* __ASSEMBLY__ */
441
442#define arch_align_stack(x) (x)
443
444#endif /* __KERNEL__ */
445
446#endif