Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arch/sparc: Introduce xchg16 for SPARC

SPARC supports 32 bit and 64 bit xchg right now. Add the support
for 16 bit (2 byte) xchg. This is required to support queued spinlock
feature which uses 2 byte xchg. This is achieved using 4 byte cas
instructions with byte manipulations.

Also re-arranged the code to call __cmpxchg_u32 inside xchg16.

Signed-off-by: Babu Moger <babu.moger@oracle.com>
Reviewed-by: Håkon Bugge <haakon.bugge@oracle.com>
Reviewed-by: Steven Sistare <steven.sistare@oracle.com>
Reviewed-by: Shannon Nelson <shannon.nelson@oracle.com>
Reviewed-by: Jane Chu <jane.chu@oracle.com>
Reviewed-by: Vijay Kumar <vijay.ac.kumar@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Babu Moger and committed by
David S. Miller
79d39e2b a37594f1

+39 -10
+39 -10
arch/sparc/include/asm/cmpxchg_64.h
··· 6 6 #ifndef __ARCH_SPARC64_CMPXCHG__ 7 7 #define __ARCH_SPARC64_CMPXCHG__ 8 8 9 + static inline unsigned long 10 + __cmpxchg_u32(volatile int *m, int old, int new) 11 + { 12 + __asm__ __volatile__("cas [%2], %3, %0" 13 + : "=&r" (new) 14 + : "0" (new), "r" (m), "r" (old) 15 + : "memory"); 16 + 17 + return new; 18 + } 19 + 9 20 static inline unsigned long xchg32(__volatile__ unsigned int *m, unsigned int val) 10 21 { 11 22 unsigned long tmp1, tmp2; ··· 55 44 56 45 void __xchg_called_with_bad_pointer(void); 57 46 47 + /* 48 + * Use 4 byte cas instruction to achieve 2 byte xchg. Main logic 49 + * here is to get the bit shift of the byte we are interested in. 50 + * The XOR is handy for reversing the bits for big-endian byte order. 51 + */ 52 + static inline unsigned long 53 + xchg16(__volatile__ unsigned short *m, unsigned short val) 54 + { 55 + unsigned long maddr = (unsigned long)m; 56 + int bit_shift = (((unsigned long)m & 2) ^ 2) << 3; 57 + unsigned int mask = 0xffff << bit_shift; 58 + unsigned int *ptr = (unsigned int *) (maddr & ~2); 59 + unsigned int old32, new32, load32; 60 + 61 + /* Read the old value */ 62 + load32 = *ptr; 63 + 64 + do { 65 + old32 = load32; 66 + new32 = (load32 & (~mask)) | val << bit_shift; 67 + load32 = __cmpxchg_u32(ptr, old32, new32); 68 + } while (load32 != old32); 69 + 70 + return (load32 & mask) >> bit_shift; 71 + } 72 + 58 73 static inline unsigned long __xchg(unsigned long x, __volatile__ void * ptr, 59 74 int size) 60 75 { 61 76 switch (size) { 77 + case 2: 78 + return xchg16(ptr, x); 62 79 case 4: 63 80 return xchg32(ptr, x); 64 81 case 8: ··· 104 65 105 66 #include <asm-generic/cmpxchg-local.h> 106 67 107 - static inline unsigned long 108 - __cmpxchg_u32(volatile int *m, int old, int new) 109 - { 110 - __asm__ __volatile__("cas [%2], %3, %0" 111 - : "=&r" (new) 112 - : "0" (new), "r" (m), "r" (old) 113 - : "memory"); 114 - 115 - return new; 116 - } 117 68 118 69 static inline unsigned long 119 70 __cmpxchg_u64(volatile long *m, unsigned long old, unsigned long new)