Linux 2.6.25.20
[linux/fpc-iii.git] / include / asm-m68k / semaphore.h
blob64d6b119bb0a096a4dcd669d15678a3e15197288
1 #ifndef _M68K_SEMAPHORE_H
2 #define _M68K_SEMAPHORE_H
4 #define RW_LOCK_BIAS 0x01000000
6 #ifndef __ASSEMBLY__
8 #include <linux/linkage.h>
9 #include <linux/wait.h>
10 #include <linux/spinlock.h>
11 #include <linux/rwsem.h>
12 #include <linux/stringify.h>
14 #include <asm/system.h>
15 #include <asm/atomic.h>
18 * Interrupt-safe semaphores..
20 * (C) Copyright 1996 Linus Torvalds
22 * m68k version by Andreas Schwab
26 struct semaphore {
27 atomic_t count;
28 atomic_t waking;
29 wait_queue_head_t wait;
32 #define __SEMAPHORE_INITIALIZER(name, n) \
33 { \
34 .count = ATOMIC_INIT(n), \
35 .waking = ATOMIC_INIT(0), \
36 .wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
39 #define __DECLARE_SEMAPHORE_GENERIC(name,count) \
40 struct semaphore name = __SEMAPHORE_INITIALIZER(name,count)
42 #define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1)
44 static inline void sema_init(struct semaphore *sem, int val)
46 *sem = (struct semaphore)__SEMAPHORE_INITIALIZER(*sem, val);
49 static inline void init_MUTEX (struct semaphore *sem)
51 sema_init(sem, 1);
54 static inline void init_MUTEX_LOCKED (struct semaphore *sem)
56 sema_init(sem, 0);
59 asmlinkage void __down_failed(void /* special register calling convention */);
60 asmlinkage int __down_failed_interruptible(void /* params in registers */);
61 asmlinkage int __down_failed_trylock(void /* params in registers */);
62 asmlinkage void __up_wakeup(void /* special register calling convention */);
64 asmlinkage void __down(struct semaphore * sem);
65 asmlinkage int __down_interruptible(struct semaphore * sem);
66 asmlinkage int __down_trylock(struct semaphore * sem);
67 asmlinkage void __up(struct semaphore * sem);
70 * This is ugly, but we want the default case to fall through.
71 * "down_failed" is a special asm handler that calls the C
72 * routine that actually waits. See arch/m68k/lib/semaphore.S
74 static inline void down(struct semaphore *sem)
76 register struct semaphore *sem1 __asm__ ("%a1") = sem;
78 might_sleep();
79 __asm__ __volatile__(
80 "| atomic down operation\n\t"
81 "subql #1,%0@\n\t"
82 "jmi 2f\n\t"
83 "1:\n"
84 LOCK_SECTION_START(".even\n\t")
85 "2:\tpea 1b\n\t"
86 "jbra __down_failed\n"
87 LOCK_SECTION_END
88 : /* no outputs */
89 : "a" (sem1)
90 : "memory");
93 static inline int down_interruptible(struct semaphore *sem)
95 register struct semaphore *sem1 __asm__ ("%a1") = sem;
96 register int result __asm__ ("%d0");
98 might_sleep();
99 __asm__ __volatile__(
100 "| atomic interruptible down operation\n\t"
101 "subql #1,%1@\n\t"
102 "jmi 2f\n\t"
103 "clrl %0\n"
104 "1:\n"
105 LOCK_SECTION_START(".even\n\t")
106 "2:\tpea 1b\n\t"
107 "jbra __down_failed_interruptible\n"
108 LOCK_SECTION_END
109 : "=d" (result)
110 : "a" (sem1)
111 : "memory");
112 return result;
115 static inline int down_trylock(struct semaphore *sem)
117 register struct semaphore *sem1 __asm__ ("%a1") = sem;
118 register int result __asm__ ("%d0");
120 __asm__ __volatile__(
121 "| atomic down trylock operation\n\t"
122 "subql #1,%1@\n\t"
123 "jmi 2f\n\t"
124 "clrl %0\n"
125 "1:\n"
126 LOCK_SECTION_START(".even\n\t")
127 "2:\tpea 1b\n\t"
128 "jbra __down_failed_trylock\n"
129 LOCK_SECTION_END
130 : "=d" (result)
131 : "a" (sem1)
132 : "memory");
133 return result;
137 * Note! This is subtle. We jump to wake people up only if
138 * the semaphore was negative (== somebody was waiting on it).
139 * The default case (no contention) will result in NO
140 * jumps for both down() and up().
142 static inline void up(struct semaphore *sem)
144 register struct semaphore *sem1 __asm__ ("%a1") = sem;
146 __asm__ __volatile__(
147 "| atomic up operation\n\t"
148 "addql #1,%0@\n\t"
149 "jle 2f\n"
150 "1:\n"
151 LOCK_SECTION_START(".even\n\t")
152 "2:\t"
153 "pea 1b\n\t"
154 "jbra __up_wakeup\n"
155 LOCK_SECTION_END
156 : /* no outputs */
157 : "a" (sem1)
158 : "memory");
161 #endif /* __ASSEMBLY__ */
163 #endif