blob: fe7de7571bacb91d2377018b229533e9cb6093d5 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#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
Catalin Marinasbbe88882007-05-08 22:27:46 +010015#define CPU_ARCH_ARMv7 9
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
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 */
Russell Kingb1cce6b2008-11-04 10:52:28 +000043#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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Linus Torvalds1da177e2005-04-16 15:20:36 -070048/*
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
Dave Martin2ecccf92011-08-19 17:58:35 +010060#include <linux/compiler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#include <linux/linkage.h>
Russell King255d1f82006-12-18 00:12:47 +000062#include <linux/irqflags.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Catalin Marinase7c56502010-03-24 16:49:54 +010064#include <asm/outercache.h>
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066struct thread_info;
67struct task_struct;
68
69/* information about the system we're running on */
70extern unsigned int system_rev;
71extern unsigned int system_serial_low;
72extern unsigned int system_serial_high;
73extern unsigned int mem_fclk_21285;
74
75struct pt_regs;
76
Russell Kinga9221de2010-01-20 17:02:54 +000077void die(const char *msg, struct pt_regs *regs, int err);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Russell Kingcfb08102005-06-30 11:06:49 +010079struct siginfo;
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -070080void arm_notify_die(const char *str, struct pt_regs *regs, struct siginfo *info,
Russell Kingcfb08102005-06-30 11:06:49 +010081 unsigned long err, unsigned long trap);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83void hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int,
84 struct pt_regs *),
Kirill A. Shutemov6338a6a2010-07-22 13:18:19 +010085 int sig, int code, const char *name);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Will Deacon3a4b5dc2010-09-03 10:39:59 +010087void hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int,
88 struct pt_regs *),
89 int sig, int code, const char *name);
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#define xchg(ptr,x) \
92 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
93
Russell King652a12e2005-04-17 15:50:36 +010094extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
Russell King5470dc62005-11-16 18:36:49 +000095
96struct mm_struct;
Russell King652a12e2005-04-17 15:50:36 +010097extern void show_pte(struct mm_struct *mm, unsigned long addr);
98extern void __show_regs(struct pt_regs *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Dave Martin2ecccf92011-08-19 17:58:35 +0100100extern int __pure cpu_architecture(void);
Russell King36c5ed22005-06-19 18:39:33 +0100101extern void cpu_init(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Russell Kingbe093be2009-03-19 16:20:24 +0000103void arm_machine_restart(char mode, const char *cmd);
Russell Kinge879c862011-11-01 13:16:26 +0000104void soft_restart(unsigned long);
Russell Kingbe093be2009-03-19 16:20:24 +0000105extern void (*arm_pm_restart)(char str, const char *cmd);
Richard Purdie74617fb2006-06-19 19:57:12 +0100106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107#define UDBG_UNDEFINED (1 << 0)
108#define UDBG_SYSCALL (1 << 1)
109#define UDBG_BADABORT (1 << 2)
110#define UDBG_SEGV (1 << 3)
111#define UDBG_BUS (1 << 4)
112
113extern unsigned int user_debug;
114
115#if __LINUX_ARM_ARCH__ >= 4
116#define vectors_high() (cr_alignment & CR_V)
117#else
118#define vectors_high() (0)
119#endif
120
Shiraz Hashim3d290052010-12-23 11:32:41 +0100121#if __LINUX_ARM_ARCH__ >= 7 || \
122 (__LINUX_ARM_ARCH__ == 6 && defined(CONFIG_CPU_32v6K))
123#define sev() __asm__ __volatile__ ("sev" : : : "memory")
124#define wfe() __asm__ __volatile__ ("wfe" : : : "memory")
125#define wfi() __asm__ __volatile__ ("wfi" : : : "memory")
126#endif
127
Catalin Marinas56163fc2007-05-08 22:53:44 +0100128#if __LINUX_ARM_ARCH__ >= 7
129#define isb() __asm__ __volatile__ ("isb" : : : "memory")
130#define dsb() __asm__ __volatile__ ("dsb" : : : "memory")
131#define dmb() __asm__ __volatile__ ("dmb" : : : "memory")
132#elif defined(CONFIG_CPU_XSC3) || __LINUX_ARM_ARCH__ == 6
Catalin Marinasdcda7e42007-02-05 14:47:35 +0100133#define isb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c5, 4" \
134 : : "r" (0) : "memory")
135#define dsb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" \
136 : : "r" (0) : "memory")
137#define dmb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" \
138 : : "r" (0) : "memory")
Paulius Zaleckas28853ac2009-03-25 13:10:01 +0200139#elif defined(CONFIG_CPU_FA526)
140#define isb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c5, 4" \
141 : : "r" (0) : "memory")
142#define dsb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" \
143 : : "r" (0) : "memory")
144#define dmb() __asm__ __volatile__ ("" : : : "memory")
Russell King6d9b37a2005-07-26 19:44:26 +0100145#else
Catalin Marinasdcda7e42007-02-05 14:47:35 +0100146#define isb() __asm__ __volatile__ ("" : : : "memory")
147#define dsb() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" \
148 : : "r" (0) : "memory")
149#define dmb() __asm__ __volatile__ ("" : : : "memory")
Russell King6d9b37a2005-07-26 19:44:26 +0100150#endif
Catalin Marinas9623b372007-02-28 12:30:38 +0100151
Catalin Marinase7c56502010-03-24 16:49:54 +0100152#ifdef CONFIG_ARCH_HAS_BARRIERS
153#include <mach/barriers.h>
Russell Kingac1d4262010-05-17 17:24:04 +0100154#elif defined(CONFIG_ARM_DMA_MEM_BUFFERABLE) || defined(CONFIG_SMP)
Catalin Marinase7c56502010-03-24 16:49:54 +0100155#define mb() do { dsb(); outer_sync(); } while (0)
Catalin Marinasa904f5f2011-04-06 16:18:47 +0100156#define rmb() dsb()
Catalin Marinase7c56502010-03-24 16:49:54 +0100157#define wmb() mb()
Russell King26a26d32009-11-20 21:06:43 +0000158#else
Axel Lin7c0ab432011-01-03 02:26:53 +0100159#include <asm/memory.h>
Lennert Buytenhek398e6922007-03-31 12:03:20 +0100160#define mb() do { if (arch_is_coherent()) dmb(); else barrier(); } while (0)
161#define rmb() do { if (arch_is_coherent()) dmb(); else barrier(); } while (0)
162#define wmb() do { if (arch_is_coherent()) dmb(); else barrier(); } while (0)
Russell King26a26d32009-11-20 21:06:43 +0000163#endif
164
165#ifndef CONFIG_SMP
Lennert Buytenhek398e6922007-03-31 12:03:20 +0100166#define smp_mb() barrier()
167#define smp_rmb() barrier()
168#define smp_wmb() barrier()
Catalin Marinas9623b372007-02-28 12:30:38 +0100169#else
Catalin Marinase7c56502010-03-24 16:49:54 +0100170#define smp_mb() dmb()
171#define smp_rmb() dmb()
172#define smp_wmb() dmb()
Lennert Buytenhek398e6922007-03-31 12:03:20 +0100173#endif
Russell King26a26d32009-11-20 21:06:43 +0000174
Lennert Buytenhek398e6922007-03-31 12:03:20 +0100175#define read_barrier_depends() do { } while(0)
176#define smp_read_barrier_depends() do { } while(0)
Catalin Marinas9623b372007-02-28 12:30:38 +0100177
178#define set_mb(var, value) do { var = value; smp_mb(); } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179#define nop() __asm__ __volatile__("mov\tr0,r0\t@ nop\n\t");
180
Catalin Marinas56660fa2007-02-05 14:48:02 +0100181extern unsigned long cr_no_alignment; /* defined in entry-armv.S */
182extern unsigned long cr_alignment; /* defined in entry-armv.S */
183
184static inline unsigned int get_cr(void)
185{
186 unsigned int val;
187 asm("mrc p15, 0, %0, c1, c0, 0 @ get CR" : "=r" (val) : : "cc");
188 return val;
189}
190
191static inline void set_cr(unsigned int val)
192{
193 asm volatile("mcr p15, 0, %0, c1, c0, 0 @ set CR"
194 : : "r" (val) : "cc");
195 isb();
196}
197
198#ifndef CONFIG_SMP
199extern void adjust_cr(unsigned long mask, unsigned long set);
200#endif
201
202#define CPACC_FULL(n) (3 << (n * 2))
203#define CPACC_SVC(n) (1 << (n * 2))
204#define CPACC_DISABLE(n) (0 << (n * 2))
205
206static inline unsigned int get_copro_access(void)
207{
208 unsigned int val;
209 asm("mrc p15, 0, %0, c1, c0, 2 @ get copro access"
210 : "=r" (val) : : "cc");
211 return val;
212}
213
214static inline void set_copro_access(unsigned int val)
215{
216 asm volatile("mcr p15, 0, %0, c1, c0, 2 @ set copro access"
217 : : "r" (val) : "cc");
218 isb();
219}
220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221/*
Nick Piggin4866cde2005-06-25 14:57:23 -0700222 * switch_mm() may do a full cache flush over the context switch,
223 * so enable interrupts over the context switch to avoid high
224 * latency.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 */
Nick Piggin4866cde2005-06-25 14:57:23 -0700226#define __ARCH_WANT_INTERRUPTS_ON_CTXSW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
228/*
229 * switch_to(prev, next) should switch from task `prev' to `next'
230 * `prev' will never be the same as `next'. schedule() itself
231 * contains the memory barrier to tell GCC not to cache `current'.
232 */
233extern struct task_struct *__switch_to(struct task_struct *, struct thread_info *, struct thread_info *);
234
235#define switch_to(prev,next,last) \
236do { \
Al Viroe7c1b322006-01-12 01:05:56 -0800237 last = __switch_to(prev,task_thread_info(prev), task_thread_info(next)); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238} while (0)
239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240#if defined(CONFIG_CPU_SA1100) || defined(CONFIG_CPU_SA110)
241/*
242 * On the StrongARM, "swp" is terminally broken since it bypasses the
243 * cache totally. This means that the cache becomes inconsistent, and,
244 * since we use normal loads/stores as well, this is really bad.
245 * Typically, this causes oopsen in filp_close, but could have other,
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300246 * more disastrous effects. There are two work-arounds:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 * 1. Disable interrupts and emulate the atomic swap
248 * 2. Clean the cache, perform atomic swap, flush the cache
249 *
250 * We choose (1) since its the "easiest" to achieve here and is not
251 * dependent on the processor type.
Russell King053a7b52005-06-28 19:22:25 +0100252 *
253 * NOTE that this solution won't work on an SMP system, so explcitly
254 * forbid it here.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 */
256#define swp_is_buggy
257#endif
258
259static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
260{
261 extern void __bad_xchg(volatile void *, int);
262 unsigned long ret;
263#ifdef swp_is_buggy
264 unsigned long flags;
265#endif
Russell King95607822005-07-26 19:39:31 +0100266#if __LINUX_ARM_ARCH__ >= 6
267 unsigned int tmp;
268#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Russell Kingbac4e962009-05-25 20:58:00 +0100270 smp_mb();
271
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 switch (size) {
Russell King95607822005-07-26 19:39:31 +0100273#if __LINUX_ARM_ARCH__ >= 6
274 case 1:
275 asm volatile("@ __xchg1\n"
276 "1: ldrexb %0, [%3]\n"
277 " strexb %1, %2, [%3]\n"
278 " teq %1, #0\n"
279 " bne 1b"
280 : "=&r" (ret), "=&r" (tmp)
281 : "r" (x), "r" (ptr)
282 : "memory", "cc");
283 break;
284 case 4:
285 asm volatile("@ __xchg4\n"
286 "1: ldrex %0, [%3]\n"
287 " strex %1, %2, [%3]\n"
288 " teq %1, #0\n"
289 " bne 1b"
290 : "=&r" (ret), "=&r" (tmp)
291 : "r" (x), "r" (ptr)
292 : "memory", "cc");
293 break;
294#elif defined(swp_is_buggy)
295#ifdef CONFIG_SMP
296#error SMP is not supported on this platform
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297#endif
Russell King95607822005-07-26 19:39:31 +0100298 case 1:
Lennert Buytenheke7cc2c52006-09-21 03:35:20 +0100299 raw_local_irq_save(flags);
Russell King95607822005-07-26 19:39:31 +0100300 ret = *(volatile unsigned char *)ptr;
301 *(volatile unsigned char *)ptr = x;
Lennert Buytenheke7cc2c52006-09-21 03:35:20 +0100302 raw_local_irq_restore(flags);
Russell King95607822005-07-26 19:39:31 +0100303 break;
304
305 case 4:
Lennert Buytenheke7cc2c52006-09-21 03:35:20 +0100306 raw_local_irq_save(flags);
Russell King95607822005-07-26 19:39:31 +0100307 ret = *(volatile unsigned long *)ptr;
308 *(volatile unsigned long *)ptr = x;
Lennert Buytenheke7cc2c52006-09-21 03:35:20 +0100309 raw_local_irq_restore(flags);
Russell King95607822005-07-26 19:39:31 +0100310 break;
311#else
312 case 1:
313 asm volatile("@ __xchg1\n"
314 " swpb %0, %1, [%2]"
315 : "=&r" (ret)
316 : "r" (x), "r" (ptr)
317 : "memory", "cc");
318 break;
319 case 4:
320 asm volatile("@ __xchg4\n"
321 " swp %0, %1, [%2]"
322 : "=&r" (ret)
323 : "r" (x), "r" (ptr)
324 : "memory", "cc");
325 break;
326#endif
327 default:
328 __bad_xchg(ptr, size), ret = 0;
329 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 }
Russell Kingbac4e962009-05-25 20:58:00 +0100331 smp_mb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
333 return ret;
334}
335
Ben Dooksdabaeff2006-03-15 23:17:26 +0000336extern void disable_hlt(void);
337extern void enable_hlt(void);
338
Kevin Hilmanc7b0aff2010-10-01 22:13:47 +0100339void cpu_idle_wait(void);
340
Mathieu Desnoyers176393d2008-02-07 00:16:11 -0800341#include <asm-generic/cmpxchg-local.h>
342
Mathieu Desnoyersecd322c2009-05-28 16:07:39 -0400343#if __LINUX_ARM_ARCH__ < 6
Russell King4ed67a52011-01-17 15:42:42 +0000344/* min ARCH < ARMv6 */
Mathieu Desnoyersecd322c2009-05-28 16:07:39 -0400345
346#ifdef CONFIG_SMP
347#error "SMP is not supported on this platform"
348#endif
349
Mathieu Desnoyers176393d2008-02-07 00:16:11 -0800350/*
351 * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
352 * them available.
353 */
354#define cmpxchg_local(ptr, o, n) \
355 ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
356 (unsigned long)(n), sizeof(*(ptr))))
357#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
358
359#ifndef CONFIG_SMP
360#include <asm-generic/cmpxchg.h>
361#endif
362
Russell King4ed67a52011-01-17 15:42:42 +0000363#else /* min ARCH >= ARMv6 */
Mathieu Desnoyersecd322c2009-05-28 16:07:39 -0400364
365extern void __bad_cmpxchg(volatile void *ptr, int size);
366
367/*
368 * cmpxchg only support 32-bits operands on ARMv6.
369 */
370
371static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
372 unsigned long new, int size)
373{
374 unsigned long oldval, res;
375
376 switch (size) {
Russell King4ed67a52011-01-17 15:42:42 +0000377#ifndef CONFIG_CPU_V6 /* min ARCH >= ARMv6K */
Mathieu Desnoyersecd322c2009-05-28 16:07:39 -0400378 case 1:
379 do {
380 asm volatile("@ __cmpxchg1\n"
381 " ldrexb %1, [%2]\n"
382 " mov %0, #0\n"
383 " teq %1, %3\n"
384 " strexbeq %0, %4, [%2]\n"
385 : "=&r" (res), "=&r" (oldval)
386 : "r" (ptr), "Ir" (old), "r" (new)
387 : "memory", "cc");
388 } while (res);
389 break;
390 case 2:
391 do {
392 asm volatile("@ __cmpxchg1\n"
393 " ldrexh %1, [%2]\n"
394 " mov %0, #0\n"
395 " teq %1, %3\n"
396 " strexheq %0, %4, [%2]\n"
397 : "=&r" (res), "=&r" (oldval)
398 : "r" (ptr), "Ir" (old), "r" (new)
399 : "memory", "cc");
400 } while (res);
401 break;
Russell King4ed67a52011-01-17 15:42:42 +0000402#endif
Mathieu Desnoyersecd322c2009-05-28 16:07:39 -0400403 case 4:
404 do {
405 asm volatile("@ __cmpxchg4\n"
406 " ldrex %1, [%2]\n"
407 " mov %0, #0\n"
408 " teq %1, %3\n"
409 " strexeq %0, %4, [%2]\n"
410 : "=&r" (res), "=&r" (oldval)
411 : "r" (ptr), "Ir" (old), "r" (new)
412 : "memory", "cc");
413 } while (res);
414 break;
415 default:
416 __bad_cmpxchg(ptr, size);
417 oldval = 0;
418 }
419
420 return oldval;
421}
422
423static inline unsigned long __cmpxchg_mb(volatile void *ptr, unsigned long old,
424 unsigned long new, int size)
425{
426 unsigned long ret;
427
428 smp_mb();
429 ret = __cmpxchg(ptr, old, new, size);
430 smp_mb();
431
432 return ret;
433}
434
435#define cmpxchg(ptr,o,n) \
436 ((__typeof__(*(ptr)))__cmpxchg_mb((ptr), \
437 (unsigned long)(o), \
438 (unsigned long)(n), \
439 sizeof(*(ptr))))
440
441static inline unsigned long __cmpxchg_local(volatile void *ptr,
442 unsigned long old,
443 unsigned long new, int size)
444{
445 unsigned long ret;
446
447 switch (size) {
Russell King4ed67a52011-01-17 15:42:42 +0000448#ifdef CONFIG_CPU_V6 /* min ARCH == ARMv6 */
Mathieu Desnoyersecd322c2009-05-28 16:07:39 -0400449 case 1:
450 case 2:
451 ret = __cmpxchg_local_generic(ptr, old, new, size);
452 break;
Russell King4ed67a52011-01-17 15:42:42 +0000453#endif
Mathieu Desnoyersecd322c2009-05-28 16:07:39 -0400454 default:
455 ret = __cmpxchg(ptr, old, new, size);
456 }
457
458 return ret;
459}
460
461#define cmpxchg_local(ptr,o,n) \
462 ((__typeof__(*(ptr)))__cmpxchg_local((ptr), \
463 (unsigned long)(o), \
464 (unsigned long)(n), \
465 sizeof(*(ptr))))
466
Russell King4ed67a52011-01-17 15:42:42 +0000467#ifndef CONFIG_CPU_V6 /* min ARCH >= ARMv6K */
Mathieu Desnoyersecd322c2009-05-28 16:07:39 -0400468
469/*
470 * Note : ARMv7-M (currently unsupported by Linux) does not support
471 * ldrexd/strexd. If ARMv7-M is ever supported by the Linux kernel, it should
472 * not be allowed to use __cmpxchg64.
473 */
474static inline unsigned long long __cmpxchg64(volatile void *ptr,
475 unsigned long long old,
476 unsigned long long new)
477{
478 register unsigned long long oldval asm("r0");
479 register unsigned long long __old asm("r2") = old;
480 register unsigned long long __new asm("r4") = new;
481 unsigned long res;
482
483 do {
484 asm volatile(
485 " @ __cmpxchg8\n"
486 " ldrexd %1, %H1, [%2]\n"
487 " mov %0, #0\n"
488 " teq %1, %3\n"
489 " teqeq %H1, %H3\n"
490 " strexdeq %0, %4, %H4, [%2]\n"
491 : "=&r" (res), "=&r" (oldval)
492 : "r" (ptr), "Ir" (__old), "r" (__new)
493 : "memory", "cc");
494 } while (res);
495
496 return oldval;
497}
498
499static inline unsigned long long __cmpxchg64_mb(volatile void *ptr,
500 unsigned long long old,
501 unsigned long long new)
502{
503 unsigned long long ret;
504
505 smp_mb();
506 ret = __cmpxchg64(ptr, old, new);
507 smp_mb();
508
509 return ret;
510}
511
512#define cmpxchg64(ptr,o,n) \
513 ((__typeof__(*(ptr)))__cmpxchg64_mb((ptr), \
514 (unsigned long long)(o), \
515 (unsigned long long)(n)))
516
517#define cmpxchg64_local(ptr,o,n) \
518 ((__typeof__(*(ptr)))__cmpxchg64((ptr), \
519 (unsigned long long)(o), \
520 (unsigned long long)(n)))
521
Russell King4ed67a52011-01-17 15:42:42 +0000522#else /* min ARCH = ARMv6 */
Mathieu Desnoyersecd322c2009-05-28 16:07:39 -0400523
524#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
525
Russell King4ed67a52011-01-17 15:42:42 +0000526#endif
Mathieu Desnoyersecd322c2009-05-28 16:07:39 -0400527
528#endif /* __LINUX_ARM_ARCH__ >= 6 */
529
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530#endif /* __ASSEMBLY__ */
531
532#define arch_align_stack(x) (x)
533
534#endif /* __KERNEL__ */
535
536#endif