aboutsummaryrefslogtreecommitdiffstats
path: root/arch/c6x/include/asm/cmpxchg.h
diff options
context:
space:
mode:
Diffstat (limited to 'arch/c6x/include/asm/cmpxchg.h')
-rw-r--r--arch/c6x/include/asm/cmpxchg.h68
1 files changed, 68 insertions, 0 deletions
diff --git a/arch/c6x/include/asm/cmpxchg.h b/arch/c6x/include/asm/cmpxchg.h
new file mode 100644
index 000000000000..b27c8cefb8c3
--- /dev/null
+++ b/arch/c6x/include/asm/cmpxchg.h
@@ -0,0 +1,68 @@
1/*
2 * Port on Texas Instruments TMS320C6x architecture
3 *
4 * Copyright (C) 2004, 2009, 2010, 2011 Texas Instruments Incorporated
5 * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
6 *
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.
10 */
11#ifndef _ASM_C6X_CMPXCHG_H
12#define _ASM_C6X_CMPXCHG_H
13
14#include <linux/irqflags.h>
15
16/*
17 * Misc. functions
18 */
19static inline unsigned int __xchg(unsigned int x, volatile void *ptr, int size)
20{
21 unsigned int tmp;
22 unsigned long flags;
23
24 local_irq_save(flags);
25
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;
42 }
43 local_irq_restore(flags);
44 return tmp;
45}
46
47#define xchg(ptr, x) \
48 ((__typeof__(*(ptr)))__xchg((unsigned int)(x), (void *) (ptr), \
49 sizeof(*(ptr))))
50#define tas(ptr) xchg((ptr), 1)
51
52
53#include <asm-generic/cmpxchg-local.h>
54
55/*
56 * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
57 * them available.
58 */
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))
65
66#include <asm-generic/cmpxchg.h>
67
68#endif /* _ASM_C6X_CMPXCHG_H */