1 #ifndef _PPC_SEMAPHORE_HELPER_H
2 #define _PPC_SEMAPHORE_HELPER_H
5 * SMP- and interrupt-safe semaphores..
7 * (C) Copyright 1996 Linus Torvalds
8 * Adapted for PowerPC by Gary Thomas and Paul Mackerras
11 #include <asm/atomic.h>
14 * These two (wake_one_more and waking_non_zero) _must_ execute
15 * atomically wrt each other.
17 * This is trivially done with load with reservation and
18 * store conditional on the ppc.
21 static inline void wake_one_more(struct semaphore
* sem
)
23 atomic_inc(&sem
->waking
);
26 static inline int waking_non_zero(struct semaphore
*sem
)
30 /* Atomic decrement sem->waking iff it is > 0 */
32 "1: lwarx %1,0,%2\n" /* tmp = sem->waking */
33 " cmpwi 0,%1,0\n" /* test tmp */
34 " addic %1,%1,-1\n" /* --tmp */
35 " ble- 2f\n" /* exit if tmp was <= 0 */
36 " stwcx. %1,0,%2\n" /* update sem->waking */
37 " bne- 1b\n" /* try again if update failed*/
38 " li %0,1\n" /* ret = 1 */
40 : "=r" (ret
), "=&r" (tmp
)
41 : "r" (&sem
->waking
), "0" (0)
47 * waking_non_zero_interruptible:
52 static inline int waking_non_zero_interruptible(struct semaphore
*sem
,
53 struct task_struct
*tsk
)
57 /* Atomic decrement sem->waking iff it is > 0 */
59 "1: lwarx %1,0,%2\n" /* tmp = sem->waking */
60 " cmpwi 0,%1,0\n" /* test tmp */
61 " addic %1,%1,-1\n" /* --tmp */
62 " ble- 2f\n" /* exit if tmp was <= 0 */
63 " stwcx. %1,0,%2\n" /* update sem->waking */
64 " bne- 1b\n" /* try again if update failed*/
65 " li %0,1\n" /* ret = 1 */
67 : "=r" (ret
), "=&r" (tmp
)
68 : "r" (&sem
->waking
), "0" (0)
71 if (ret
== 0 && signal_pending(tsk
)) {
72 atomic_inc(&sem
->count
);
79 * waking_non_zero_trylock:
83 static inline int waking_non_zero_trylock(struct semaphore
*sem
)
87 /* Atomic decrement sem->waking iff it is > 0 */
89 "1: lwarx %1,0,%2\n" /* tmp = sem->waking */
90 " cmpwi 0,%1,0\n" /* test tmp */
91 " addic %1,%1,-1\n" /* --tmp */
92 " ble- 2f\n" /* exit if tmp was <= 0 */
93 " stwcx. %1,0,%2\n" /* update sem->waking */
94 " bne- 1b\n" /* try again if update failed*/
95 " li %0,0\n" /* ret = 0 */
97 : "=r" (ret
), "=&r" (tmp
)
98 : "r" (&sem
->waking
), "0" (1)
102 atomic_inc(&sem
->count
);
107 #endif /* _PPC_SEMAPHORE_HELPER_H */