Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris...
[linux/fpc-iii.git] / arch / c6x / include / asm / cmpxchg.h
blobb27c8cefb8c3e92fb6a6e9b3055a6394bfe22f79
1 /*
2 * Port on Texas Instruments TMS320C6x architecture
4 * Copyright (C) 2004, 2009, 2010, 2011 Texas Instruments Incorporated
5 * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 #ifndef _ASM_C6X_CMPXCHG_H
12 #define _ASM_C6X_CMPXCHG_H
14 #include <linux/irqflags.h>
17 * Misc. functions
19 static inline unsigned int __xchg(unsigned int x, volatile void *ptr, int size)
21 unsigned int tmp;
22 unsigned long flags;
24 local_irq_save(flags);
26 switch (size) {
27 case 1:
28 tmp = 0;
29 tmp = *((unsigned char *) ptr);
30 *((unsigned char *) ptr) = (unsigned char) x;
31 break;
32 case 2:
33 tmp = 0;
34 tmp = *((unsigned short *) ptr);
35 *((unsigned short *) ptr) = x;
36 break;
37 case 4:
38 tmp = 0;
39 tmp = *((unsigned int *) ptr);
40 *((unsigned int *) ptr) = x;
41 break;
43 local_irq_restore(flags);
44 return tmp;
47 #define xchg(ptr, x) \
48 ((__typeof__(*(ptr)))__xchg((unsigned int)(x), (void *) (ptr), \
49 sizeof(*(ptr))))
50 #define tas(ptr) xchg((ptr), 1)
53 #include <asm-generic/cmpxchg-local.h>
56 * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
57 * them available.
59 #define cmpxchg_local(ptr, o, n) \
60 ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), \
61 (unsigned long)(o), \
62 (unsigned long)(n), \
63 sizeof(*(ptr))))
64 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
66 #include <asm-generic/cmpxchg.h>
68 #endif /* _ASM_C6X_CMPXCHG_H */