1 /* Generic system definitions, based on MN10300 definitions.
3 * It should be possible to use these on really simple architectures,
4 * but it serves more as a starting point for new ports.
6 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
7 * Written by David Howells (dhowells@redhat.com)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public Licence
11 * as published by the Free Software Foundation; either version
12 * 2 of the Licence, or (at your option) any later version.
14 #ifndef __ASM_GENERIC_SYSTEM_H
15 #define __ASM_GENERIC_SYSTEM_H
20 #include <linux/types.h>
21 #include <linux/irqflags.h>
23 #include <asm/cmpxchg-local.h>
27 /* context switching is now performed out-of-line in switch_to.S */
28 extern struct task_struct
*__switch_to(struct task_struct
*,
29 struct task_struct
*);
30 #define switch_to(prev, next, last) \
32 ((last) = __switch_to((prev), (next))); \
35 #define arch_align_stack(x) (x)
37 #define nop() asm volatile ("nop")
39 #endif /* !__ASSEMBLY__ */
42 * Force strict CPU ordering.
43 * And yes, this is required on UP too when we're talking
46 * This implementation only contains a compiler barrier.
49 #define mb() asm volatile ("": : :"memory")
51 #define wmb() asm volatile ("": : :"memory")
55 #define smp_rmb() rmb()
56 #define smp_wmb() wmb()
58 #define smp_mb() barrier()
59 #define smp_rmb() barrier()
60 #define smp_wmb() barrier()
63 #define set_mb(var, value) do { var = value; mb(); } while (0)
64 #define set_wmb(var, value) do { var = value; wmb(); } while (0)
66 #define read_barrier_depends() do {} while (0)
67 #define smp_read_barrier_depends() do {} while (0)
70 * we make sure local_irq_enable() doesn't cause priority inversion
74 /* This function doesn't exist, so you'll get a linker error
75 * if something tries to do an invalid xchg(). */
76 extern void __xchg_called_with_bad_pointer(void);
79 unsigned long __xchg(unsigned long x
, volatile void *ptr
, int size
)
81 unsigned long ret
, flags
;
86 return __xchg_u8(x
, ptr
);
88 local_irq_save(flags
);
89 ret
= *(volatile u8
*)ptr
;
90 *(volatile u8
*)ptr
= x
;
91 local_irq_restore(flags
);
93 #endif /* __xchg_u8 */
97 return __xchg_u16(x
, ptr
);
99 local_irq_save(flags
);
100 ret
= *(volatile u16
*)ptr
;
101 *(volatile u16
*)ptr
= x
;
102 local_irq_restore(flags
);
104 #endif /* __xchg_u16 */
108 return __xchg_u32(x
, ptr
);
110 local_irq_save(flags
);
111 ret
= *(volatile u32
*)ptr
;
112 *(volatile u32
*)ptr
= x
;
113 local_irq_restore(flags
);
115 #endif /* __xchg_u32 */
120 return __xchg_u64(x
, ptr
);
122 local_irq_save(flags
);
123 ret
= *(volatile u64
*)ptr
;
124 *(volatile u64
*)ptr
= x
;
125 local_irq_restore(flags
);
127 #endif /* __xchg_u64 */
128 #endif /* CONFIG_64BIT */
131 __xchg_called_with_bad_pointer();
136 #define xchg(ptr, x) \
137 ((__typeof__(*(ptr))) __xchg((unsigned long)(x), (ptr), sizeof(*(ptr))))
139 static inline unsigned long __cmpxchg(volatile unsigned long *m
,
140 unsigned long old
, unsigned long new)
142 unsigned long retval
;
145 local_irq_save(flags
);
149 local_irq_restore(flags
);
153 #define cmpxchg(ptr, o, n) \
154 ((__typeof__(*(ptr))) __cmpxchg((unsigned long *)(ptr), \
155 (unsigned long)(o), \
158 #endif /* !__ASSEMBLY__ */
160 #endif /* __KERNEL__ */
161 #endif /* __ASM_GENERIC_SYSTEM_H */