David Howells | 6a846f3 | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 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 | */ |
| 19 | static 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)))) |
David Howells | 6a846f3 | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 50 | |
| 51 | #include <asm-generic/cmpxchg-local.h> |
| 52 | |
| 53 | /* |
| 54 | * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make |
| 55 | * them available. |
| 56 | */ |
| 57 | #define cmpxchg_local(ptr, o, n) \ |
| 58 | ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), \ |
| 59 | (unsigned long)(o), \ |
| 60 | (unsigned long)(n), \ |
| 61 | sizeof(*(ptr)))) |
| 62 | #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n)) |
| 63 | |
| 64 | #include <asm-generic/cmpxchg.h> |
| 65 | |
| 66 | #endif /* _ASM_C6X_CMPXCHG_H */ |