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/linkage.h>
13 #include <linux/types.h>
15 #include <asm/ptrace.h>
16 #include <asm/sysreg.h>
19 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
21 #define nop() asm volatile("nop")
23 #define mb() asm volatile("" : : : "memory")
25 #define wmb() asm volatile("sync 0" : : : "memory")
26 #define read_barrier_depends() do { } while(0)
27 #define set_mb(var, value) do { var = value; mb(); } while(0)
30 * Help PathFinder and other Nexus-compliant debuggers keep track of
31 * the current PID by emitting an Ownership Trace Message each time we
34 #ifdef CONFIG_OWNERSHIP_TRACE
36 #define finish_arch_switch(prev) \
38 __mtdr(DBGREG_PID, prev->pid); \
39 __mtdr(DBGREG_PID, current->pid); \
44 * switch_to(prev, next, last) should switch from task `prev' to task
45 * `next'. `prev' will never be the same as `next'.
47 * We just delegate everything to the __switch_to assembly function,
48 * which is implemented in arch/avr32/kernel/switch_to.S
50 * mb() tells GCC not to cache `current' across this call.
54 extern struct task_struct
*__switch_to(struct task_struct
*,
56 struct cpu_context
*);
57 #define switch_to(prev, next, last) \
59 last = __switch_to(prev, &prev->thread.cpu_context + 1, \
60 &next->thread.cpu_context); \
64 # error "The AVR32 port does not support SMP"
66 # define smp_mb() barrier()
67 # define smp_rmb() barrier()
68 # define smp_wmb() barrier()
69 # define smp_read_barrier_depends() do { } while(0)
72 #include <linux/irqflags.h>
74 extern void __xchg_called_with_bad_pointer(void);
76 static inline unsigned long xchg_u32(u32 val
, volatile u32
*m
)
80 asm volatile("xchg %[ret], %[m], %[val]"
81 : [ret
] "=&r"(ret
), "=m"(*m
)
82 : "m"(*m
), [m
] "r"(m
), [val
] "r"(val
)
87 static inline unsigned long __xchg(unsigned long x
,
93 return xchg_u32(x
, ptr
);
95 __xchg_called_with_bad_pointer();
100 static inline unsigned long __cmpxchg_u32(volatile int *m
, unsigned long old
,
107 " ld.w %[ret], %[m]\n"
108 " cp.w %[ret], %[old]\n"
110 " stcond %[m], %[new]\n"
113 : [ret
] "=&r"(ret
), [m
] "=m"(*m
)
114 : "m"(m
), [old
] "ir"(old
), [new] "r"(new)
119 extern unsigned long __cmpxchg_u64_unsupported_on_32bit_kernels(
120 volatile int * m
, unsigned long old
, unsigned long new);
121 #define __cmpxchg_u64 __cmpxchg_u64_unsupported_on_32bit_kernels
123 /* This function doesn't exist, so you'll get a linker error
124 if something tries to do an invalid cmpxchg(). */
125 extern void __cmpxchg_called_with_bad_pointer(void);
127 #define __HAVE_ARCH_CMPXCHG 1
129 static inline unsigned long __cmpxchg(volatile void *ptr
, unsigned long old
,
130 unsigned long new, int size
)
134 return __cmpxchg_u32(ptr
, old
, new);
136 return __cmpxchg_u64(ptr
, old
, new);
139 __cmpxchg_called_with_bad_pointer();
143 #define cmpxchg(ptr, old, new) \
144 ((typeof(*(ptr)))__cmpxchg((ptr), (unsigned long)(old), \
145 (unsigned long)(new), \
149 void NORET_TYPE
die(const char *str
, struct pt_regs
*regs
, long err
);
150 void _exception(long signr
, struct pt_regs
*regs
, int code
,
153 #define arch_align_stack(x) (x)
155 #endif /* __ASM_AVR32_SYSTEM_H */