1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2f15cbe6fSPaul Mundt #ifndef __ASM_SH_CMPXCHG_GRB_H
3f15cbe6fSPaul Mundt #define __ASM_SH_CMPXCHG_GRB_H
4f15cbe6fSPaul Mundt
xchg_u32(volatile u32 * m,unsigned long val)5f15cbe6fSPaul Mundt static inline unsigned long xchg_u32(volatile u32 *m, unsigned long val)
6f15cbe6fSPaul Mundt {
7f15cbe6fSPaul Mundt unsigned long retval;
8f15cbe6fSPaul Mundt
9f15cbe6fSPaul Mundt __asm__ __volatile__ (
10f15cbe6fSPaul Mundt " .align 2 \n\t"
11f15cbe6fSPaul Mundt " mova 1f, r0 \n\t" /* r0 = end point */
12f15cbe6fSPaul Mundt " nop \n\t"
13f15cbe6fSPaul Mundt " mov r15, r1 \n\t" /* r1 = saved sp */
14f15cbe6fSPaul Mundt " mov #-4, r15 \n\t" /* LOGIN */
15f15cbe6fSPaul Mundt " mov.l @%1, %0 \n\t" /* load old value */
16f15cbe6fSPaul Mundt " mov.l %2, @%1 \n\t" /* store new value */
17f15cbe6fSPaul Mundt "1: mov r1, r15 \n\t" /* LOGOUT */
18f15cbe6fSPaul Mundt : "=&r" (retval),
195bdbd4faSSrinivas KANDAGATLA "+r" (m),
205bdbd4faSSrinivas KANDAGATLA "+r" (val) /* inhibit r15 overloading */
215bdbd4faSSrinivas KANDAGATLA :
22f15cbe6fSPaul Mundt : "memory", "r0", "r1");
23f15cbe6fSPaul Mundt
24f15cbe6fSPaul Mundt return retval;
25f15cbe6fSPaul Mundt }
26f15cbe6fSPaul Mundt
xchg_u16(volatile u16 * m,unsigned long val)273226aad8SMichael S. Tsirkin static inline unsigned long xchg_u16(volatile u16 *m, unsigned long val)
283226aad8SMichael S. Tsirkin {
293226aad8SMichael S. Tsirkin unsigned long retval;
303226aad8SMichael S. Tsirkin
313226aad8SMichael S. Tsirkin __asm__ __volatile__ (
323226aad8SMichael S. Tsirkin " .align 2 \n\t"
333226aad8SMichael S. Tsirkin " mova 1f, r0 \n\t" /* r0 = end point */
343226aad8SMichael S. Tsirkin " mov r15, r1 \n\t" /* r1 = saved sp */
353226aad8SMichael S. Tsirkin " mov #-6, r15 \n\t" /* LOGIN */
363226aad8SMichael S. Tsirkin " mov.w @%1, %0 \n\t" /* load old value */
373226aad8SMichael S. Tsirkin " extu.w %0, %0 \n\t" /* extend as unsigned */
383226aad8SMichael S. Tsirkin " mov.w %2, @%1 \n\t" /* store new value */
393226aad8SMichael S. Tsirkin "1: mov r1, r15 \n\t" /* LOGOUT */
403226aad8SMichael S. Tsirkin : "=&r" (retval),
413226aad8SMichael S. Tsirkin "+r" (m),
423226aad8SMichael S. Tsirkin "+r" (val) /* inhibit r15 overloading */
433226aad8SMichael S. Tsirkin :
443226aad8SMichael S. Tsirkin : "memory" , "r0", "r1");
453226aad8SMichael S. Tsirkin
463226aad8SMichael S. Tsirkin return retval;
473226aad8SMichael S. Tsirkin }
483226aad8SMichael S. Tsirkin
xchg_u8(volatile u8 * m,unsigned long val)49f15cbe6fSPaul Mundt static inline unsigned long xchg_u8(volatile u8 *m, unsigned long val)
50f15cbe6fSPaul Mundt {
51f15cbe6fSPaul Mundt unsigned long retval;
52f15cbe6fSPaul Mundt
53f15cbe6fSPaul Mundt __asm__ __volatile__ (
54f15cbe6fSPaul Mundt " .align 2 \n\t"
55f15cbe6fSPaul Mundt " mova 1f, r0 \n\t" /* r0 = end point */
56f15cbe6fSPaul Mundt " mov r15, r1 \n\t" /* r1 = saved sp */
57f15cbe6fSPaul Mundt " mov #-6, r15 \n\t" /* LOGIN */
58f15cbe6fSPaul Mundt " mov.b @%1, %0 \n\t" /* load old value */
59f15cbe6fSPaul Mundt " extu.b %0, %0 \n\t" /* extend as unsigned */
60f15cbe6fSPaul Mundt " mov.b %2, @%1 \n\t" /* store new value */
61f15cbe6fSPaul Mundt "1: mov r1, r15 \n\t" /* LOGOUT */
62f15cbe6fSPaul Mundt : "=&r" (retval),
635bdbd4faSSrinivas KANDAGATLA "+r" (m),
645bdbd4faSSrinivas KANDAGATLA "+r" (val) /* inhibit r15 overloading */
655bdbd4faSSrinivas KANDAGATLA :
66f15cbe6fSPaul Mundt : "memory" , "r0", "r1");
67f15cbe6fSPaul Mundt
68f15cbe6fSPaul Mundt return retval;
69f15cbe6fSPaul Mundt }
70f15cbe6fSPaul Mundt
__cmpxchg_u32(volatile int * m,unsigned long old,unsigned long new)71f15cbe6fSPaul Mundt static inline unsigned long __cmpxchg_u32(volatile int *m, unsigned long old,
72f15cbe6fSPaul Mundt unsigned long new)
73f15cbe6fSPaul Mundt {
74f15cbe6fSPaul Mundt unsigned long retval;
75f15cbe6fSPaul Mundt
76f15cbe6fSPaul Mundt __asm__ __volatile__ (
77f15cbe6fSPaul Mundt " .align 2 \n\t"
78f15cbe6fSPaul Mundt " mova 1f, r0 \n\t" /* r0 = end point */
79f15cbe6fSPaul Mundt " nop \n\t"
80f15cbe6fSPaul Mundt " mov r15, r1 \n\t" /* r1 = saved sp */
81f15cbe6fSPaul Mundt " mov #-8, r15 \n\t" /* LOGIN */
825bdbd4faSSrinivas KANDAGATLA " mov.l @%3, %0 \n\t" /* load old value */
835bdbd4faSSrinivas KANDAGATLA " cmp/eq %0, %1 \n\t"
84f15cbe6fSPaul Mundt " bf 1f \n\t" /* if not equal */
855bdbd4faSSrinivas KANDAGATLA " mov.l %2, @%3 \n\t" /* store new value */
86f15cbe6fSPaul Mundt "1: mov r1, r15 \n\t" /* LOGOUT */
875bdbd4faSSrinivas KANDAGATLA : "=&r" (retval),
885bdbd4faSSrinivas KANDAGATLA "+r" (old), "+r" (new) /* old or new can be r15 */
895bdbd4faSSrinivas KANDAGATLA : "r" (m)
90f15cbe6fSPaul Mundt : "memory" , "r0", "r1", "t");
91f15cbe6fSPaul Mundt
92f15cbe6fSPaul Mundt return retval;
93f15cbe6fSPaul Mundt }
94f15cbe6fSPaul Mundt
95f15cbe6fSPaul Mundt #endif /* __ASM_SH_CMPXCHG_GRB_H */
96