blob: fcfd32271bff7f6d890922eb7a7b2dea7da34186 [file] [log] [blame]
Paul Mundtee43a842008-08-07 18:01:43 +09001#ifndef __ASM_SH_CMPXCHG_LLSC_H
2#define __ASM_SH_CMPXCHG_LLSC_H
3
4static inline unsigned long xchg_u32(volatile u32 *m, unsigned long val)
5{
6 unsigned long retval;
7 unsigned long tmp;
8
9 __asm__ __volatile__ (
10 "1: \n\t"
Matt Fleming42990702009-01-20 21:14:37 +000011 "movli.l @%2, %0 ! xchg_u32 \n\t"
12 "mov %0, %1 \n\t"
13 "mov %3, %0 \n\t"
14 "movco.l %0, @%2 \n\t"
Paul Mundtee43a842008-08-07 18:01:43 +090015 "bf 1b \n\t"
16 "synco \n\t"
Matt Fleming42990702009-01-20 21:14:37 +000017 : "=&z"(tmp), "=&r" (retval)
18 : "r" (m), "r" (val)
Paul Mundtee43a842008-08-07 18:01:43 +090019 : "t", "memory"
20 );
21
22 return retval;
23}
24
Paul Mundtee43a842008-08-07 18:01:43 +090025static inline unsigned long
Michael S. Tsirkin3226aad2016-01-07 17:54:54 +020026__cmpxchg_u32(volatile u32 *m, unsigned long old, unsigned long new)
Paul Mundtee43a842008-08-07 18:01:43 +090027{
28 unsigned long retval;
29 unsigned long tmp;
30
31 __asm__ __volatile__ (
32 "1: \n\t"
Matt Fleming42990702009-01-20 21:14:37 +000033 "movli.l @%2, %0 ! __cmpxchg_u32 \n\t"
34 "mov %0, %1 \n\t"
35 "cmp/eq %1, %3 \n\t"
Paul Mundtee43a842008-08-07 18:01:43 +090036 "bf 2f \n\t"
Aoi Shinkai4c7c9972009-06-10 16:15:42 +000037 "mov %4, %0 \n\t"
Paul Mundtee43a842008-08-07 18:01:43 +090038 "2: \n\t"
Matt Fleming42990702009-01-20 21:14:37 +000039 "movco.l %0, @%2 \n\t"
Paul Mundtee43a842008-08-07 18:01:43 +090040 "bf 1b \n\t"
41 "synco \n\t"
Matt Fleming42990702009-01-20 21:14:37 +000042 : "=&z" (tmp), "=&r" (retval)
43 : "r" (m), "r" (old), "r" (new)
Paul Mundtee43a842008-08-07 18:01:43 +090044 : "t", "memory"
45 );
46
47 return retval;
48}
49
Michael S. Tsirkin9e3f84c2016-01-08 09:23:58 +020050#include <asm/cmpxchg-xchg.h>
Michael S. Tsirkin3226aad2016-01-07 17:54:54 +020051
Paul Mundtee43a842008-08-07 18:01:43 +090052#endif /* __ASM_SH_CMPXCHG_LLSC_H */