Merge branch 'hw-breakpoint' of git://repo.or.cz/linux-2.6/linux-wd into devel-stable
[pandora-kernel.git] / arch / arm / include / asm / system.h
1 #ifndef __ASM_ARM_SYSTEM_H
2 #define __ASM_ARM_SYSTEM_H
3
4 #ifdef __KERNEL__
5
6 #define CPU_ARCH_UNKNOWN        0
7 #define CPU_ARCH_ARMv3          1
8 #define CPU_ARCH_ARMv4          2
9 #define CPU_ARCH_ARMv4T         3
10 #define CPU_ARCH_ARMv5          4
11 #define CPU_ARCH_ARMv5T         5
12 #define CPU_ARCH_ARMv5TE        6
13 #define CPU_ARCH_ARMv5TEJ       7
14 #define CPU_ARCH_ARMv6          8
15 #define CPU_ARCH_ARMv7          9
16
17 /*
18  * CR1 bits (CP#15 CR1)
19  */
20 #define CR_M    (1 << 0)        /* MMU enable                           */
21 #define CR_A    (1 << 1)        /* Alignment abort enable               */
22 #define CR_C    (1 << 2)        /* Dcache enable                        */
23 #define CR_W    (1 << 3)        /* Write buffer enable                  */
24 #define CR_P    (1 << 4)        /* 32-bit exception handler             */
25 #define CR_D    (1 << 5)        /* 32-bit data address range            */
26 #define CR_L    (1 << 6)        /* Implementation defined               */
27 #define CR_B    (1 << 7)        /* Big endian                           */
28 #define CR_S    (1 << 8)        /* System MMU protection                */
29 #define CR_R    (1 << 9)        /* ROM MMU protection                   */
30 #define CR_F    (1 << 10)       /* Implementation defined               */
31 #define CR_Z    (1 << 11)       /* Implementation defined               */
32 #define CR_I    (1 << 12)       /* Icache enable                        */
33 #define CR_V    (1 << 13)       /* Vectors relocated to 0xffff0000      */
34 #define CR_RR   (1 << 14)       /* Round Robin cache replacement        */
35 #define CR_L4   (1 << 15)       /* LDR pc can set T bit                 */
36 #define CR_DT   (1 << 16)
37 #define CR_IT   (1 << 18)
38 #define CR_ST   (1 << 19)
39 #define CR_FI   (1 << 21)       /* Fast interrupt (lower latency mode)  */
40 #define CR_U    (1 << 22)       /* Unaligned access operation           */
41 #define CR_XP   (1 << 23)       /* Extended page tables                 */
42 #define CR_VE   (1 << 24)       /* Vectored interrupts                  */
43 #define CR_EE   (1 << 25)       /* Exception (Big) Endian               */
44 #define CR_TRE  (1 << 28)       /* TEX remap enable                     */
45 #define CR_AFE  (1 << 29)       /* Access flag enable                   */
46 #define CR_TE   (1 << 30)       /* Thumb exception enable               */
47
48 /*
49  * This is used to ensure the compiler did actually allocate the register we
50  * asked it for some inline assembly sequences.  Apparently we can't trust
51  * the compiler from one version to another so a bit of paranoia won't hurt.
52  * This string is meant to be concatenated with the inline asm string and
53  * will cause compilation to stop on mismatch.
54  * (for details, see gcc PR 15089)
55  */
56 #define __asmeq(x, y)  ".ifnc " x "," y " ; .err ; .endif\n\t"
57
58 #ifndef __ASSEMBLY__
59
60 #include <linux/linkage.h>
61 #include <linux/irqflags.h>
62
63 #include <asm/outercache.h>
64
65 #define __exception     __attribute__((section(".exception.text")))
66 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
67 #define __exception_irq_entry   __irq_entry
68 #else
69 #define __exception_irq_entry   __exception
70 #endif
71
72 struct thread_info;
73 struct task_struct;
74
75 /* information about the system we're running on */
76 extern unsigned int system_rev;
77 extern unsigned int system_serial_low;
78 extern unsigned int system_serial_high;
79 extern unsigned int mem_fclk_21285;
80
81 struct pt_regs;
82
83 void die(const char *msg, struct pt_regs *regs, int err);
84
85 struct siginfo;
86 void arm_notify_die(const char *str, struct pt_regs *regs, struct siginfo *info,
87                 unsigned long err, unsigned long trap);
88
89 void hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int,
90                                        struct pt_regs *),
91                      int sig, int code, const char *name);
92
93 void hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int,
94                                        struct pt_regs *),
95                      int sig, int code, const char *name);
96
97 #define xchg(ptr,x) \
98         ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
99
100 extern asmlinkage void __backtrace(void);
101 extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
102
103 struct mm_struct;
104 extern void show_pte(struct mm_struct *mm, unsigned long addr);
105 extern void __show_regs(struct pt_regs *);
106
107 extern int cpu_architecture(void);
108 extern void cpu_init(void);
109
110 void arm_machine_restart(char mode, const char *cmd);
111 extern void (*arm_pm_restart)(char str, const char *cmd);
112
113 #define UDBG_UNDEFINED  (1 << 0)
114 #define UDBG_SYSCALL    (1 << 1)
115 #define UDBG_BADABORT   (1 << 2)
116 #define UDBG_SEGV       (1 << 3)
117 #define UDBG_BUS        (1 << 4)
118
119 extern unsigned int user_debug;
120
121 #if __LINUX_ARM_ARCH__ >= 4
122 #define vectors_high()  (cr_alignment & CR_V)
123 #else
124 #define vectors_high()  (0)
125 #endif
126
127 #if __LINUX_ARM_ARCH__ >= 7
128 #define isb() __asm__ __volatile__ ("isb" : : : "memory")
129 #define dsb() __asm__ __volatile__ ("dsb" : : : "memory")
130 #define dmb() __asm__ __volatile__ ("dmb" : : : "memory")
131 #elif defined(CONFIG_CPU_XSC3) || __LINUX_ARM_ARCH__ == 6
132 #define isb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c5, 4" \
133                                     : : "r" (0) : "memory")
134 #define dsb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" \
135                                     : : "r" (0) : "memory")
136 #define dmb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" \
137                                     : : "r" (0) : "memory")
138 #elif defined(CONFIG_CPU_FA526)
139 #define isb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c5, 4" \
140                                     : : "r" (0) : "memory")
141 #define dsb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" \
142                                     : : "r" (0) : "memory")
143 #define dmb() __asm__ __volatile__ ("" : : : "memory")
144 #else
145 #define isb() __asm__ __volatile__ ("" : : : "memory")
146 #define dsb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" \
147                                     : : "r" (0) : "memory")
148 #define dmb() __asm__ __volatile__ ("" : : : "memory")
149 #endif
150
151 #ifdef CONFIG_ARCH_HAS_BARRIERS
152 #include <mach/barriers.h>
153 #elif defined(CONFIG_ARM_DMA_MEM_BUFFERABLE) || defined(CONFIG_SMP)
154 #define mb()            do { dsb(); outer_sync(); } while (0)
155 #define rmb()           dmb()
156 #define wmb()           mb()
157 #else
158 #define mb()    do { if (arch_is_coherent()) dmb(); else barrier(); } while (0)
159 #define rmb()   do { if (arch_is_coherent()) dmb(); else barrier(); } while (0)
160 #define wmb()   do { if (arch_is_coherent()) dmb(); else barrier(); } while (0)
161 #endif
162
163 #ifndef CONFIG_SMP
164 #define smp_mb()        barrier()
165 #define smp_rmb()       barrier()
166 #define smp_wmb()       barrier()
167 #else
168 #define smp_mb()        dmb()
169 #define smp_rmb()       dmb()
170 #define smp_wmb()       dmb()
171 #endif
172
173 #define read_barrier_depends()          do { } while(0)
174 #define smp_read_barrier_depends()      do { } while(0)
175
176 #define set_mb(var, value)      do { var = value; smp_mb(); } while (0)
177 #define nop() __asm__ __volatile__("mov\tr0,r0\t@ nop\n\t");
178
179 extern unsigned long cr_no_alignment;   /* defined in entry-armv.S */
180 extern unsigned long cr_alignment;      /* defined in entry-armv.S */
181
182 static inline unsigned int get_cr(void)
183 {
184         unsigned int val;
185         asm("mrc p15, 0, %0, c1, c0, 0  @ get CR" : "=r" (val) : : "cc");
186         return val;
187 }
188
189 static inline void set_cr(unsigned int val)
190 {
191         asm volatile("mcr p15, 0, %0, c1, c0, 0 @ set CR"
192           : : "r" (val) : "cc");
193         isb();
194 }
195
196 #ifndef CONFIG_SMP
197 extern void adjust_cr(unsigned long mask, unsigned long set);
198 #endif
199
200 #define CPACC_FULL(n)           (3 << (n * 2))
201 #define CPACC_SVC(n)            (1 << (n * 2))
202 #define CPACC_DISABLE(n)        (0 << (n * 2))
203
204 static inline unsigned int get_copro_access(void)
205 {
206         unsigned int val;
207         asm("mrc p15, 0, %0, c1, c0, 2 @ get copro access"
208           : "=r" (val) : : "cc");
209         return val;
210 }
211
212 static inline void set_copro_access(unsigned int val)
213 {
214         asm volatile("mcr p15, 0, %0, c1, c0, 2 @ set copro access"
215           : : "r" (val) : "cc");
216         isb();
217 }
218
219 /*
220  * switch_mm() may do a full cache flush over the context switch,
221  * so enable interrupts over the context switch to avoid high
222  * latency.
223  */
224 #define __ARCH_WANT_INTERRUPTS_ON_CTXSW
225
226 /*
227  * switch_to(prev, next) should switch from task `prev' to `next'
228  * `prev' will never be the same as `next'.  schedule() itself
229  * contains the memory barrier to tell GCC not to cache `current'.
230  */
231 extern struct task_struct *__switch_to(struct task_struct *, struct thread_info *, struct thread_info *);
232
233 #define switch_to(prev,next,last)                                       \
234 do {                                                                    \
235         last = __switch_to(prev,task_thread_info(prev), task_thread_info(next));        \
236 } while (0)
237
238 #if defined(CONFIG_CPU_SA1100) || defined(CONFIG_CPU_SA110)
239 /*
240  * On the StrongARM, "swp" is terminally broken since it bypasses the
241  * cache totally.  This means that the cache becomes inconsistent, and,
242  * since we use normal loads/stores as well, this is really bad.
243  * Typically, this causes oopsen in filp_close, but could have other,
244  * more disasterous effects.  There are two work-arounds:
245  *  1. Disable interrupts and emulate the atomic swap
246  *  2. Clean the cache, perform atomic swap, flush the cache
247  *
248  * We choose (1) since its the "easiest" to achieve here and is not
249  * dependent on the processor type.
250  *
251  * NOTE that this solution won't work on an SMP system, so explcitly
252  * forbid it here.
253  */
254 #define swp_is_buggy
255 #endif
256
257 static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
258 {
259         extern void __bad_xchg(volatile void *, int);
260         unsigned long ret;
261 #ifdef swp_is_buggy
262         unsigned long flags;
263 #endif
264 #if __LINUX_ARM_ARCH__ >= 6
265         unsigned int tmp;
266 #endif
267
268         smp_mb();
269
270         switch (size) {
271 #if __LINUX_ARM_ARCH__ >= 6
272         case 1:
273                 asm volatile("@ __xchg1\n"
274                 "1:     ldrexb  %0, [%3]\n"
275                 "       strexb  %1, %2, [%3]\n"
276                 "       teq     %1, #0\n"
277                 "       bne     1b"
278                         : "=&r" (ret), "=&r" (tmp)
279                         : "r" (x), "r" (ptr)
280                         : "memory", "cc");
281                 break;
282         case 4:
283                 asm volatile("@ __xchg4\n"
284                 "1:     ldrex   %0, [%3]\n"
285                 "       strex   %1, %2, [%3]\n"
286                 "       teq     %1, #0\n"
287                 "       bne     1b"
288                         : "=&r" (ret), "=&r" (tmp)
289                         : "r" (x), "r" (ptr)
290                         : "memory", "cc");
291                 break;
292 #elif defined(swp_is_buggy)
293 #ifdef CONFIG_SMP
294 #error SMP is not supported on this platform
295 #endif
296         case 1:
297                 raw_local_irq_save(flags);
298                 ret = *(volatile unsigned char *)ptr;
299                 *(volatile unsigned char *)ptr = x;
300                 raw_local_irq_restore(flags);
301                 break;
302
303         case 4:
304                 raw_local_irq_save(flags);
305                 ret = *(volatile unsigned long *)ptr;
306                 *(volatile unsigned long *)ptr = x;
307                 raw_local_irq_restore(flags);
308                 break;
309 #else
310         case 1:
311                 asm volatile("@ __xchg1\n"
312                 "       swpb    %0, %1, [%2]"
313                         : "=&r" (ret)
314                         : "r" (x), "r" (ptr)
315                         : "memory", "cc");
316                 break;
317         case 4:
318                 asm volatile("@ __xchg4\n"
319                 "       swp     %0, %1, [%2]"
320                         : "=&r" (ret)
321                         : "r" (x), "r" (ptr)
322                         : "memory", "cc");
323                 break;
324 #endif
325         default:
326                 __bad_xchg(ptr, size), ret = 0;
327                 break;
328         }
329         smp_mb();
330
331         return ret;
332 }
333
334 extern void disable_hlt(void);
335 extern void enable_hlt(void);
336
337 void cpu_idle_wait(void);
338
339 #include <asm-generic/cmpxchg-local.h>
340
341 #if __LINUX_ARM_ARCH__ < 6
342
343 #ifdef CONFIG_SMP
344 #error "SMP is not supported on this platform"
345 #endif
346
347 /*
348  * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
349  * them available.
350  */
351 #define cmpxchg_local(ptr, o, n)                                               \
352         ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
353                         (unsigned long)(n), sizeof(*(ptr))))
354 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
355
356 #ifndef CONFIG_SMP
357 #include <asm-generic/cmpxchg.h>
358 #endif
359
360 #else   /* __LINUX_ARM_ARCH__ >= 6 */
361
362 extern void __bad_cmpxchg(volatile void *ptr, int size);
363
364 /*
365  * cmpxchg only support 32-bits operands on ARMv6.
366  */
367
368 static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
369                                       unsigned long new, int size)
370 {
371         unsigned long oldval, res;
372
373         switch (size) {
374 #ifdef CONFIG_CPU_32v6K
375         case 1:
376                 do {
377                         asm volatile("@ __cmpxchg1\n"
378                         "       ldrexb  %1, [%2]\n"
379                         "       mov     %0, #0\n"
380                         "       teq     %1, %3\n"
381                         "       strexbeq %0, %4, [%2]\n"
382                                 : "=&r" (res), "=&r" (oldval)
383                                 : "r" (ptr), "Ir" (old), "r" (new)
384                                 : "memory", "cc");
385                 } while (res);
386                 break;
387         case 2:
388                 do {
389                         asm volatile("@ __cmpxchg1\n"
390                         "       ldrexh  %1, [%2]\n"
391                         "       mov     %0, #0\n"
392                         "       teq     %1, %3\n"
393                         "       strexheq %0, %4, [%2]\n"
394                                 : "=&r" (res), "=&r" (oldval)
395                                 : "r" (ptr), "Ir" (old), "r" (new)
396                                 : "memory", "cc");
397                 } while (res);
398                 break;
399 #endif /* CONFIG_CPU_32v6K */
400         case 4:
401                 do {
402                         asm volatile("@ __cmpxchg4\n"
403                         "       ldrex   %1, [%2]\n"
404                         "       mov     %0, #0\n"
405                         "       teq     %1, %3\n"
406                         "       strexeq %0, %4, [%2]\n"
407                                 : "=&r" (res), "=&r" (oldval)
408                                 : "r" (ptr), "Ir" (old), "r" (new)
409                                 : "memory", "cc");
410                 } while (res);
411                 break;
412         default:
413                 __bad_cmpxchg(ptr, size);
414                 oldval = 0;
415         }
416
417         return oldval;
418 }
419
420 static inline unsigned long __cmpxchg_mb(volatile void *ptr, unsigned long old,
421                                          unsigned long new, int size)
422 {
423         unsigned long ret;
424
425         smp_mb();
426         ret = __cmpxchg(ptr, old, new, size);
427         smp_mb();
428
429         return ret;
430 }
431
432 #define cmpxchg(ptr,o,n)                                                \
433         ((__typeof__(*(ptr)))__cmpxchg_mb((ptr),                        \
434                                           (unsigned long)(o),           \
435                                           (unsigned long)(n),           \
436                                           sizeof(*(ptr))))
437
438 static inline unsigned long __cmpxchg_local(volatile void *ptr,
439                                             unsigned long old,
440                                             unsigned long new, int size)
441 {
442         unsigned long ret;
443
444         switch (size) {
445 #ifndef CONFIG_CPU_32v6K
446         case 1:
447         case 2:
448                 ret = __cmpxchg_local_generic(ptr, old, new, size);
449                 break;
450 #endif  /* !CONFIG_CPU_32v6K */
451         default:
452                 ret = __cmpxchg(ptr, old, new, size);
453         }
454
455         return ret;
456 }
457
458 #define cmpxchg_local(ptr,o,n)                                          \
459         ((__typeof__(*(ptr)))__cmpxchg_local((ptr),                     \
460                                        (unsigned long)(o),              \
461                                        (unsigned long)(n),              \
462                                        sizeof(*(ptr))))
463
464 #ifdef CONFIG_CPU_32v6K
465
466 /*
467  * Note : ARMv7-M (currently unsupported by Linux) does not support
468  * ldrexd/strexd. If ARMv7-M is ever supported by the Linux kernel, it should
469  * not be allowed to use __cmpxchg64.
470  */
471 static inline unsigned long long __cmpxchg64(volatile void *ptr,
472                                              unsigned long long old,
473                                              unsigned long long new)
474 {
475         register unsigned long long oldval asm("r0");
476         register unsigned long long __old asm("r2") = old;
477         register unsigned long long __new asm("r4") = new;
478         unsigned long res;
479
480         do {
481                 asm volatile(
482                 "       @ __cmpxchg8\n"
483                 "       ldrexd  %1, %H1, [%2]\n"
484                 "       mov     %0, #0\n"
485                 "       teq     %1, %3\n"
486                 "       teqeq   %H1, %H3\n"
487                 "       strexdeq %0, %4, %H4, [%2]\n"
488                         : "=&r" (res), "=&r" (oldval)
489                         : "r" (ptr), "Ir" (__old), "r" (__new)
490                         : "memory", "cc");
491         } while (res);
492
493         return oldval;
494 }
495
496 static inline unsigned long long __cmpxchg64_mb(volatile void *ptr,
497                                                 unsigned long long old,
498                                                 unsigned long long new)
499 {
500         unsigned long long ret;
501
502         smp_mb();
503         ret = __cmpxchg64(ptr, old, new);
504         smp_mb();
505
506         return ret;
507 }
508
509 #define cmpxchg64(ptr,o,n)                                              \
510         ((__typeof__(*(ptr)))__cmpxchg64_mb((ptr),                      \
511                                             (unsigned long long)(o),    \
512                                             (unsigned long long)(n)))
513
514 #define cmpxchg64_local(ptr,o,n)                                        \
515         ((__typeof__(*(ptr)))__cmpxchg64((ptr),                         \
516                                          (unsigned long long)(o),       \
517                                          (unsigned long long)(n)))
518
519 #else   /* !CONFIG_CPU_32v6K */
520
521 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
522
523 #endif  /* CONFIG_CPU_32v6K */
524
525 #endif  /* __LINUX_ARM_ARCH__ >= 6 */
526
527 #endif /* __ASSEMBLY__ */
528
529 #define arch_align_stack(x) (x)
530
531 #endif /* __KERNEL__ */
532
533 #endif