1 #ifndef _M68K_SEMAPHORE_H
2 #define _M68K_SEMAPHORE_H
4 #define RW_LOCK_BIAS 0x01000000
8 #include <linux/linkage.h>
9 #include <linux/wait.h>
10 #include <linux/spinlock.h>
11 #include <linux/rwsem.h>
12 #include <linux/stringify.h>
14 #include <asm/system.h>
15 #include <asm/atomic.h>
18 * Interrupt-safe semaphores..
20 * (C) Copyright 1996 Linus Torvalds
22 * m68k version by Andreas Schwab
29 wait_queue_head_t wait;
32 #define __SEMAPHORE_INITIALIZER(name, n) \
34 .count = ATOMIC_INIT(n), \
35 .waking = ATOMIC_INIT(0), \
36 .wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
39 #define __MUTEX_INITIALIZER(name) \
40 __SEMAPHORE_INITIALIZER(name,1)
42 #define __DECLARE_SEMAPHORE_GENERIC(name,count) \
43 struct semaphore name = __SEMAPHORE_INITIALIZER(name,count)
45 #define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1)
46 #define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name,0)
48 static inline void sema_init(struct semaphore *sem, int val)
50 *sem = (struct semaphore)__SEMAPHORE_INITIALIZER(*sem, val);
53 static inline void init_MUTEX (struct semaphore *sem)
58 static inline void init_MUTEX_LOCKED (struct semaphore *sem)
63 asmlinkage void __down_failed(void /* special register calling convention */);
64 asmlinkage int __down_failed_interruptible(void /* params in registers */);
65 asmlinkage int __down_failed_trylock(void /* params in registers */);
66 asmlinkage void __up_wakeup(void /* special register calling convention */);
68 asmlinkage void __down(struct semaphore * sem);
69 asmlinkage int __down_interruptible(struct semaphore * sem);
70 asmlinkage int __down_trylock(struct semaphore * sem);
71 asmlinkage void __up(struct semaphore * sem);
74 * This is ugly, but we want the default case to fall through.
75 * "down_failed" is a special asm handler that calls the C
76 * routine that actually waits. See arch/m68k/lib/semaphore.S
78 static inline void down(struct semaphore *sem)
80 register struct semaphore *sem1 __asm__ ("%a1") = sem;
84 "| atomic down operation\n\t"
88 LOCK_SECTION_START(".even\n\t")
90 "jbra __down_failed\n"
97 static inline int down_interruptible(struct semaphore *sem)
99 register struct semaphore *sem1 __asm__ ("%a1") = sem;
100 register int result __asm__ ("%d0");
103 __asm__ __volatile__(
104 "| atomic interruptible down operation\n\t"
109 LOCK_SECTION_START(".even\n\t")
111 "jbra __down_failed_interruptible\n"
119 static inline int down_trylock(struct semaphore *sem)
121 register struct semaphore *sem1 __asm__ ("%a1") = sem;
122 register int result __asm__ ("%d0");
124 __asm__ __volatile__(
125 "| atomic down trylock operation\n\t"
130 LOCK_SECTION_START(".even\n\t")
132 "jbra __down_failed_trylock\n"
141 * Note! This is subtle. We jump to wake people up only if
142 * the semaphore was negative (== somebody was waiting on it).
143 * The default case (no contention) will result in NO
144 * jumps for both down() and up().
146 static inline void up(struct semaphore *sem)
148 register struct semaphore *sem1 __asm__ ("%a1") = sem;
150 __asm__ __volatile__(
151 "| atomic up operation\n\t"
155 LOCK_SECTION_START(".even\n\t")
165 #endif /* __ASSEMBLY__ */