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)
30 static inline void sema_init (struct semaphore
*sem
, int val
)
32 atomic24_set(&sem
->count
, val
);
34 init_waitqueue_head(&sem
->wait
);
37 static inline void init_MUTEX (struct semaphore
*sem
)
42 static inline void init_MUTEX_LOCKED (struct semaphore
*sem
)
47 extern void __down(struct semaphore
* sem
);
48 extern int __down_interruptible(struct semaphore
* sem
);
49 extern int __down_trylock(struct semaphore
* sem
);
50 extern void __up(struct semaphore
* sem
);
52 static inline void down(struct semaphore
* sem
)
54 register volatile int *ptr
asm("g1");
55 register int increment
asm("g2");
59 ptr
= &(sem
->count
.counter
);
64 "call ___atomic24_sub\n\t"
65 " add %%o7, 8, %%o7\n\t"
72 "save %%sp, -64, %%sp\n\t"
79 " restore %%l5, %%g0, %%g5\n\t"
82 : "0" (increment
), "r" (ptr
), "i" (__down
)
83 : "g3", "g4", "g7", "memory", "cc");
86 static inline int down_interruptible(struct semaphore
* sem
)
88 register volatile int *ptr
asm("g1");
89 register int increment
asm("g2");
93 ptr
= &(sem
->count
.counter
);
98 "call ___atomic24_sub\n\t"
99 " add %%o7, 8, %%o7\n\t"
106 "save %%sp, -64, %%sp\n\t"
110 " mov %%g1, %%o0\n\t"
114 " restore %%o0, %%g0, %%g2\n\t"
117 : "0" (increment
), "r" (ptr
), "i" (__down_interruptible
)
118 : "g3", "g4", "g7", "memory", "cc");
123 static inline int down_trylock(struct semaphore
* sem
)
125 register volatile int *ptr
asm("g1");
126 register int increment
asm("g2");
128 ptr
= &(sem
->count
.counter
);
131 __asm__
__volatile__(
133 "call ___atomic24_sub\n\t"
134 " add %%o7, 8, %%o7\n\t"
141 "save %%sp, -64, %%sp\n\t"
145 " mov %%g1, %%o0\n\t"
149 " restore %%o0, %%g0, %%g2\n\t"
152 : "0" (increment
), "r" (ptr
), "i" (__down_trylock
)
153 : "g3", "g4", "g7", "memory", "cc");
158 static inline void up(struct semaphore
* sem
)
160 register volatile int *ptr
asm("g1");
161 register int increment
asm("g2");
163 ptr
= &(sem
->count
.counter
);
166 __asm__
__volatile__(
168 "call ___atomic24_add\n\t"
169 " add %%o7, 8, %%o7\n\t"
176 "save %%sp, -64, %%sp\n\t"
180 " mov %%g1, %%o0\n\t"
183 " restore %%l5, %%g0, %%g5\n\t"
186 : "0" (increment
), "r" (ptr
), "i" (__up
)
187 : "g3", "g4", "g7", "memory", "cc");
190 #endif /* __KERNEL__ */
192 #endif /* !(_SPARC_SEMAPHORE_H) */