2 * arch/sh/include/asm/mutex-llsc.h
4 * SH-4A optimized mutex locking primitives
6 * Please look into asm-generic/mutex-xchg.h for a formal definition.
8 #ifndef __ASM_SH_MUTEX_LLSC_H
9 #define __ASM_SH_MUTEX_LLSC_H
12 * Attempting to lock a mutex on SH4A is done like in ARMv6+ architecure.
13 * with a bastardized atomic decrement (it is not a reliable atomic decrement
14 * but it satisfies the defined semantics for our purpose, while being
15 * smaller and faster than a real atomic decrement or atomic swap.
16 * The idea is to attempt decrementing the lock value only once. If once
17 * decremented it isn't zero, or if its store-back fails due to a dispute
18 * on the exclusive store, we simply bail out immediately through the slow
19 * path where the lock will be reattempted until it succeeds.
22 __mutex_fastpath_lock(atomic_t *count, void (*fail_fn)(atomic_t *))
26 __asm__ __volatile__ (
31 : "=&z" (__res), "=&r" (__ex_flag)
32 : "r" (&(count)->counter)
36 if (unlikely(__res != 0))
41 __mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *))
45 __asm__ __volatile__ (
50 : "=&z" (__res), "=&r" (__ex_flag)
51 : "r" (&(count)->counter)
55 if (unlikely(__res != 0))
56 __res = fail_fn(count);
62 __mutex_fastpath_unlock(atomic_t *count, void (*fail_fn)(atomic_t *))
66 __asm__ __volatile__ (
67 "movli.l @%2, %0 \n\t"
69 "movco.l %0, @%2 \n\t"
71 : "=&z" (__res), "=&r" (__ex_flag)
72 : "r" (&(count)->counter)
76 if (unlikely(__res <= 0))
81 * If the unlock was done on a contended lock, or if the unlock simply fails
82 * then the mutex remains locked.
84 #define __mutex_slowpath_needs_to_unlock() 1
87 * For __mutex_fastpath_trylock we do an atomic decrement and check the
88 * result and put it in the __res variable.
91 __mutex_fastpath_trylock(atomic_t *count, int (*fail_fn)(atomic_t *))
95 __asm__ __volatile__ (
96 "1: movli.l @%2, %0 \n\t"
106 : "=&z" (__orig), "=&r" (__res)
107 : "r" (&count->counter)
112 #endif /* __ASM_SH_MUTEX_LLSC_H */