2 * Copyright (C) 2004-2006 Atmel Corporation
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 #ifndef __ASM_AVR32_SYSTEM_H
9 #define __ASM_AVR32_SYSTEM_H
11 #include <linux/compiler.h>
12 #include <linux/types.h>
14 #include <asm/ptrace.h>
15 #include <asm/sysreg.h>
18 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
20 #define nop() asm volatile("nop")
22 #define mb() asm volatile("" : : : "memory")
24 #define wmb() asm volatile("sync 0" : : : "memory")
25 #define read_barrier_depends() do { } while(0)
26 #define set_mb(var, value) do { var = value; mb(); } while(0)
29 * Help PathFinder and other Nexus-compliant debuggers keep track of
30 * the current PID by emitting an Ownership Trace Message each time we
33 #ifdef CONFIG_OWNERSHIP_TRACE
35 #define finish_arch_switch(prev) \
37 __mtdr(DBGREG_PID, prev->pid); \
38 __mtdr(DBGREG_PID, current->pid); \
43 * switch_to(prev, next, last) should switch from task `prev' to task
44 * `next'. `prev' will never be the same as `next'.
46 * We just delegate everything to the __switch_to assembly function,
47 * which is implemented in arch/avr32/kernel/switch_to.S
49 * mb() tells GCC not to cache `current' across this call.
53 extern struct task_struct *__switch_to(struct task_struct *,
55 struct cpu_context *);
56 #define switch_to(prev, next, last) \
58 last = __switch_to(prev, &prev->thread.cpu_context + 1, \
59 &next->thread.cpu_context); \
63 # error "The AVR32 port does not support SMP"
65 # define smp_mb() barrier()
66 # define smp_rmb() barrier()
67 # define smp_wmb() barrier()
68 # define smp_read_barrier_depends() do { } while(0)
71 #include <linux/irqflags.h>
73 extern void __xchg_called_with_bad_pointer(void);
76 extern unsigned long __builtin_xchg(void *ptr, unsigned long x);
79 #define xchg_u32(val, m) __builtin_xchg((void *)m, val)
81 static inline unsigned long __xchg(unsigned long x,
87 return xchg_u32(x, ptr);
89 __xchg_called_with_bad_pointer();
94 static inline unsigned long __cmpxchg_u32(volatile int *m, unsigned long old,
101 " ld.w %[ret], %[m]\n"
102 " cp.w %[ret], %[old]\n"
104 " stcond %[m], %[new]\n"
107 : [ret] "=&r"(ret), [m] "=m"(*m)
108 : "m"(m), [old] "ir"(old), [new] "r"(new)
113 extern unsigned long __cmpxchg_u64_unsupported_on_32bit_kernels(
114 volatile int * m, unsigned long old, unsigned long new);
115 #define __cmpxchg_u64 __cmpxchg_u64_unsupported_on_32bit_kernels
117 /* This function doesn't exist, so you'll get a linker error
118 if something tries to do an invalid cmpxchg(). */
119 extern void __cmpxchg_called_with_bad_pointer(void);
121 #define __HAVE_ARCH_CMPXCHG 1
123 static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
124 unsigned long new, int size)
128 return __cmpxchg_u32(ptr, old, new);
130 return __cmpxchg_u64(ptr, old, new);
133 __cmpxchg_called_with_bad_pointer();
137 #define cmpxchg(ptr, old, new) \
138 ((typeof(*(ptr)))__cmpxchg((ptr), (unsigned long)(old), \
139 (unsigned long)(new), \
143 extern void __die(const char *, struct pt_regs *, unsigned long,
144 const char *, const char *, unsigned long);
145 extern void __die_if_kernel(const char *, struct pt_regs *, unsigned long,
146 const char *, const char *, unsigned long);
148 #define die(msg, regs, err) \
149 __die(msg, regs, err, __FILE__ ":", __FUNCTION__, __LINE__)
150 #define die_if_kernel(msg, regs, err) \
151 __die_if_kernel(msg, regs, err, __FILE__ ":", __FUNCTION__, __LINE__)
153 #define arch_align_stack(x) (x)
155 #endif /* __ASM_AVR32_SYSTEM_H */