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 __MUTEX_INITIALIZER(name) \
26 __SEMAPHORE_INITIALIZER(name,1)
28 #define __DECLARE_SEMAPHORE_GENERIC(name,count) \
29 struct semaphore name = __SEMAPHORE_INITIALIZER(name,count)
31 #define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1)
32 #define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name,0)
34 static inline void sema_init (struct semaphore
*sem
, int val
)
36 atomic24_set(&sem
->count
, val
);
38 init_waitqueue_head(&sem
->wait
);
41 static inline void init_MUTEX (struct semaphore
*sem
)
46 static inline void init_MUTEX_LOCKED (struct semaphore
*sem
)
51 extern void __down(struct semaphore
* sem
);
52 extern int __down_interruptible(struct semaphore
* sem
);
53 extern int __down_trylock(struct semaphore
* sem
);
54 extern void __up(struct semaphore
* sem
);
56 static inline void down(struct semaphore
* sem
)
58 register volatile int *ptr
asm("g1");
59 register int increment
asm("g2");
63 ptr
= &(sem
->count
.counter
);
68 "call ___atomic24_sub\n\t"
69 " add %%o7, 8, %%o7\n\t"
76 "save %%sp, -64, %%sp\n\t"
83 " restore %%l5, %%g0, %%g5\n\t"
86 : "0" (increment
), "r" (ptr
), "i" (__down
)
87 : "g3", "g4", "g7", "memory", "cc");
90 static inline int down_interruptible(struct semaphore
* sem
)
92 register volatile int *ptr
asm("g1");
93 register int increment
asm("g2");
97 ptr
= &(sem
->count
.counter
);
100 __asm__
__volatile__(
102 "call ___atomic24_sub\n\t"
103 " add %%o7, 8, %%o7\n\t"
110 "save %%sp, -64, %%sp\n\t"
114 " mov %%g1, %%o0\n\t"
118 " restore %%o0, %%g0, %%g2\n\t"
121 : "0" (increment
), "r" (ptr
), "i" (__down_interruptible
)
122 : "g3", "g4", "g7", "memory", "cc");
127 static inline int down_trylock(struct semaphore
* sem
)
129 register volatile int *ptr
asm("g1");
130 register int increment
asm("g2");
132 ptr
= &(sem
->count
.counter
);
135 __asm__
__volatile__(
137 "call ___atomic24_sub\n\t"
138 " add %%o7, 8, %%o7\n\t"
145 "save %%sp, -64, %%sp\n\t"
149 " mov %%g1, %%o0\n\t"
153 " restore %%o0, %%g0, %%g2\n\t"
156 : "0" (increment
), "r" (ptr
), "i" (__down_trylock
)
157 : "g3", "g4", "g7", "memory", "cc");
162 static inline void up(struct semaphore
* sem
)
164 register volatile int *ptr
asm("g1");
165 register int increment
asm("g2");
167 ptr
= &(sem
->count
.counter
);
170 __asm__
__volatile__(
172 "call ___atomic24_add\n\t"
173 " add %%o7, 8, %%o7\n\t"
180 "save %%sp, -64, %%sp\n\t"
184 " mov %%g1, %%o0\n\t"
187 " restore %%l5, %%g0, %%g5\n\t"
190 : "0" (increment
), "r" (ptr
), "i" (__up
)
191 : "g3", "g4", "g7", "memory", "cc");
194 #endif /* __KERNEL__ */
196 #endif /* !(_SPARC_SEMAPHORE_H) */