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;
35 # define __SEM_DEBUG_INIT(name) \
36 , (long)&(name).__magic
38 # define __SEM_DEBUG_INIT(name)
41 #define __SEMAPHORE_INITIALIZER(name,count) \
42 { ATOMIC_INIT(count), 0, __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
43 __SEM_DEBUG_INIT(name) }
45 #define __MUTEX_INITIALIZER(name) \
46 __SEMAPHORE_INITIALIZER(name,1)
48 #define __DECLARE_SEMAPHORE_GENERIC(name,count) \
49 struct semaphore name = __SEMAPHORE_INITIALIZER(name,count)
51 #define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1)
52 #define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name,0)
54 static inline void sema_init (struct semaphore *sem, int val)
56 *sem = (struct semaphore)__SEMAPHORE_INITIALIZER(*sem, val);
59 static inline void init_MUTEX (struct semaphore *sem)
64 static inline void init_MUTEX_LOCKED (struct semaphore *sem)
69 asmlinkage void __down_failed(void /* special register calling convention */);
70 asmlinkage int __down_failed_interruptible(void /* params in registers */);
71 asmlinkage int __down_failed_trylock(void /* params in registers */);
72 asmlinkage void __up_wakeup(void /* special register calling convention */);
74 asmlinkage void __down(struct semaphore * sem);
75 asmlinkage int __down_interruptible(struct semaphore * sem);
76 asmlinkage int __down_trylock(struct semaphore * sem);
77 asmlinkage void __up(struct semaphore * sem);
79 extern spinlock_t semaphore_wake_lock;
82 * This is ugly, but we want the default case to fall through.
83 * "down_failed" is a special asm handler that calls the C
84 * routine that actually waits. See arch/m68k/lib/semaphore.S
86 static inline void down(struct semaphore * sem)
88 register atomic_t *count asm("er0");
91 CHECK_MAGIC(sem->__magic);
95 count = &(sem->count);
112 : "cc", "er1", "er2", "er3");
115 static inline int down_interruptible(struct semaphore * sem)
117 register atomic_t *count asm("er0");
120 CHECK_MAGIC(sem->__magic);
124 count = &(sem->count);
125 __asm__ __volatile__(
134 "jsr @___down_interruptible\n\t"
140 : "=r" (count),"+m" (*count)
142 : "cc", "er1", "er2", "er3");
146 static inline int down_trylock(struct semaphore * sem)
148 register atomic_t *count asm("er0");
151 CHECK_MAGIC(sem->__magic);
154 count = &(sem->count);
155 __asm__ __volatile__(
164 LOCK_SECTION_START(".align 2\n\t")
167 "jsr @___down_trylock\n\t"
174 : "+m" (*count),"=r"(count)
176 : "cc", "er1","er2", "er3");
181 * Note! This is subtle. We jump to wake people up only if
182 * the semaphore was negative (== somebody was waiting on it).
183 * The default case (no contention) will result in NO
184 * jumps for both down() and up().
186 static inline void up(struct semaphore * sem)
188 register atomic_t *count asm("er0");
191 CHECK_MAGIC(sem->__magic);
194 count = &(sem->count);
195 __asm__ __volatile__(
210 : "cc", "er1", "er2", "er3");
213 #endif /* __ASSEMBLY__ */