1 #ifndef _SPARC_SEMAPHORE_H
2 #define _SPARC_SEMAPHORE_H
4 /* Dinky, good for nothing, just barely irq safe, Sparc semaphores. */
8 #include <asm/atomic.h>
9 #include <linux/wait.h>
10 #include <linux/rwsem.h>
15 wait_queue_head_t wait;
18 #define __SEMAPHORE_INITIALIZER(name, n) \
20 .count = ATOMIC24_INIT(n), \
22 .wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
25 #define __DECLARE_SEMAPHORE_GENERIC(name,count) \
26 struct semaphore name = __SEMAPHORE_INITIALIZER(name,count)
28 #define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1)
29 #define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name,0)
31 static inline void sema_init (struct semaphore *sem, int val)
33 atomic24_set(&sem->count, val);
35 init_waitqueue_head(&sem->wait);
38 static inline void init_MUTEX (struct semaphore *sem)
43 static inline void init_MUTEX_LOCKED (struct semaphore *sem)
48 extern void __down(struct semaphore * sem);
49 extern int __down_interruptible(struct semaphore * sem);
50 extern int __down_trylock(struct semaphore * sem);
51 extern void __up(struct semaphore * sem);
53 static inline void down(struct semaphore * sem)
55 register volatile int *ptr asm("g1");
56 register int increment asm("g2");
60 ptr = &(sem->count.counter);
65 "call ___atomic24_sub\n\t"
66 " add %%o7, 8, %%o7\n\t"
73 "save %%sp, -64, %%sp\n\t"
80 " restore %%l5, %%g0, %%g5\n\t"
83 : "0" (increment), "r" (ptr), "i" (__down)
84 : "g3", "g4", "g7", "memory", "cc");
87 static inline int down_interruptible(struct semaphore * sem)
89 register volatile int *ptr asm("g1");
90 register int increment asm("g2");
94 ptr = &(sem->count.counter);
99 "call ___atomic24_sub\n\t"
100 " add %%o7, 8, %%o7\n\t"
107 "save %%sp, -64, %%sp\n\t"
111 " mov %%g1, %%o0\n\t"
115 " restore %%o0, %%g0, %%g2\n\t"
118 : "0" (increment), "r" (ptr), "i" (__down_interruptible)
119 : "g3", "g4", "g7", "memory", "cc");
124 static inline int down_trylock(struct semaphore * sem)
126 register volatile int *ptr asm("g1");
127 register int increment asm("g2");
129 ptr = &(sem->count.counter);
132 __asm__ __volatile__(
134 "call ___atomic24_sub\n\t"
135 " add %%o7, 8, %%o7\n\t"
142 "save %%sp, -64, %%sp\n\t"
146 " mov %%g1, %%o0\n\t"
150 " restore %%o0, %%g0, %%g2\n\t"
153 : "0" (increment), "r" (ptr), "i" (__down_trylock)
154 : "g3", "g4", "g7", "memory", "cc");
159 static inline void up(struct semaphore * sem)
161 register volatile int *ptr asm("g1");
162 register int increment asm("g2");
164 ptr = &(sem->count.counter);
167 __asm__ __volatile__(
169 "call ___atomic24_add\n\t"
170 " add %%o7, 8, %%o7\n\t"
177 "save %%sp, -64, %%sp\n\t"
181 " mov %%g1, %%o0\n\t"
184 " restore %%l5, %%g0, %%g5\n\t"
187 : "0" (increment), "r" (ptr), "i" (__up)
188 : "g3", "g4", "g7", "memory", "cc");
191 #endif /* __KERNEL__ */
193 #endif /* !(_SPARC_SEMAPHORE_H) */