1 #ifndef _H8300_SEMAPHORE_H
2 #define _H8300_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>
13 #include <asm/system.h>
14 #include <asm/atomic.h>
17 * Interrupt-safe semaphores..
19 * (C) Copyright 1996 Linus Torvalds
21 * H8/300 version by Yoshinori Sato
28 wait_queue_head_t wait;
31 #define __SEMAPHORE_INITIALIZER(name, n) \
33 .count = ATOMIC_INIT(n), \
35 .wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
38 #define __DECLARE_SEMAPHORE_GENERIC(name,count) \
39 struct semaphore name = __SEMAPHORE_INITIALIZER(name,count)
41 #define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1)
43 static inline void sema_init (struct semaphore *sem, int val)
45 *sem = (struct semaphore)__SEMAPHORE_INITIALIZER(*sem, val);
48 static inline void init_MUTEX (struct semaphore *sem)
53 static inline void init_MUTEX_LOCKED (struct semaphore *sem)
58 asmlinkage void __down_failed(void /* special register calling convention */);
59 asmlinkage int __down_failed_interruptible(void /* params in registers */);
60 asmlinkage int __down_failed_trylock(void /* params in registers */);
61 asmlinkage void __up_wakeup(void /* special register calling convention */);
63 asmlinkage void __down(struct semaphore * sem);
64 asmlinkage int __down_interruptible(struct semaphore * sem);
65 asmlinkage int __down_trylock(struct semaphore * sem);
66 asmlinkage void __up(struct semaphore * sem);
68 extern spinlock_t semaphore_wake_lock;
71 * This is ugly, but we want the default case to fall through.
72 * "down_failed" is a special asm handler that calls the C
73 * routine that actually waits. See arch/m68k/lib/semaphore.S
75 static inline void down(struct semaphore * sem)
77 register atomic_t *count asm("er0");
81 count = &(sem->count);
97 : "g"(sem),"m"(*count)
98 : "cc", "er1", "er2", "er3");
101 static inline int down_interruptible(struct semaphore * sem)
103 register atomic_t *count asm("er0");
107 count = &(sem->count);
108 __asm__ __volatile__(
117 "jsr @___down_interruptible\n\t"
123 : "=r" (count),"=m" (*count)
124 : "g"(sem),"m"(*count)
125 : "cc", "er1", "er2", "er3");
129 static inline int down_trylock(struct semaphore * sem)
131 register atomic_t *count asm("er0");
133 count = &(sem->count);
134 __asm__ __volatile__(
143 LOCK_SECTION_START(".align 2\n\t")
146 "jsr @___down_trylock\n\t"
153 : "=m" (*count),"=r"(count)
154 : "g"(sem),"m"(*count)
155 : "cc", "er1","er2", "er3");
160 * Note! This is subtle. We jump to wake people up only if
161 * the semaphore was negative (== somebody was waiting on it).
162 * The default case (no contention) will result in NO
163 * jumps for both down() and up().
165 static inline void up(struct semaphore * sem)
167 register atomic_t *count asm("er0");
169 count = &(sem->count);
170 __asm__ __volatile__(
184 : "g"(sem),"m"(*count)
185 : "cc", "er1", "er2", "er3");
188 #endif /* __ASSEMBLY__ */