pre-2.3.4..
[davej-history.git] / include / asm-m68k / semaphore.h
blobe1bdb10f44c27e981599b490c566647be532f906
1 #ifndef _M68K_SEMAPHORE_H
2 #define _M68K_SEMAPHORE_H
4 #include <linux/linkage.h>
6 #include <asm/system.h>
7 #include <asm/atomic.h>
8 #include <asm/spinlock.h>
11 * SMP- and interrupt-safe semaphores..
13 * (C) Copyright 1996 Linus Torvalds
15 * m68k version by Andreas Schwab
18 struct semaphore {
19 atomic_t count;
20 atomic_t waking;
21 wait_queue_head_t wait;
24 #define MUTEX ((struct semaphore) { ATOMIC_INIT(1), ATOMIC_INIT(0), NULL })
25 #define MUTEX_LOCKED ((struct semaphore) { ATOMIC_INIT(0), ATOMIC_INIT(0), NULL })
27 asmlinkage void __down_failed(void /* special register calling convention */);
28 asmlinkage int __down_failed_interruptible(void /* params in registers */);
29 asmlinkage int __down_failed_trylock(void /* params in registers */);
30 asmlinkage void __up_wakeup(void /* special register calling convention */);
32 asmlinkage void __down(struct semaphore * sem);
33 asmlinkage int __down_interruptible(struct semaphore * sem);
34 asmlinkage int __down_trylock(struct semaphore * sem);
35 asmlinkage void __up(struct semaphore * sem);
37 #define sema_init(sem, val) atomic_set(&((sem)->count), val)
40 * This is ugly, but we want the default case to fall through.
41 * "down_failed" is a special asm handler that calls the C
42 * routine that actually waits. See arch/m68k/lib/semaphore.S
44 extern inline void down(struct semaphore * sem)
46 register struct semaphore *sem1 __asm__ ("%a1") = sem;
47 __asm__ __volatile__(
48 "| atomic down operation\n\t"
49 "subql #1,%0@\n\t"
50 "jmi 2f\n\t"
51 "1:\n"
52 ".section .text.lock,\"ax\"\n"
53 ".even\n"
54 "2:\tpea 1b\n\t"
55 "jbra __down_failed\n"
56 ".previous"
57 : /* no outputs */
58 : "a" (sem1)
59 : "memory");
62 extern inline int down_interruptible(struct semaphore * sem)
64 register struct semaphore *sem1 __asm__ ("%a1") = sem;
65 register int result __asm__ ("%d0");
67 __asm__ __volatile__(
68 "| atomic interruptible down operation\n\t"
69 "subql #1,%1@\n\t"
70 "jmi 2f\n\t"
71 "clrl %0\n"
72 "1:\n"
73 ".section .text.lock,\"ax\"\n"
74 ".even\n"
75 "2:\tpea 1b\n\t"
76 "jbra __down_failed_interruptible\n"
77 ".previous"
78 : "=d" (result)
79 : "a" (sem1)
80 : "%d0", "memory");
81 return result;
84 extern inline int down_trylock(struct semaphore * sem)
86 register struct semaphore *sem1 __asm__ ("%a1") = sem;
87 register int result __asm__ ("%d0");
89 __asm__ __volatile__(
90 "| atomic down trylock operation\n\t"
91 "subql #1,%1@\n\t"
92 "jmi 2f\n\t"
93 "clrl %0\n"
94 "1:\n"
95 ".section .text.lock,\"ax\"\n"
96 ".even\n"
97 "2:\tpea 1b\n\t"
98 "jbra __down_failed_trylock\n"
99 ".previous"
100 : "=d" (result)
101 : "a" (sem1)
102 : "%d0", "memory");
103 return result;
107 * Note! This is subtle. We jump to wake people up only if
108 * the semaphore was negative (== somebody was waiting on it).
109 * The default case (no contention) will result in NO
110 * jumps for both down() and up().
112 extern inline void up(struct semaphore * sem)
114 register struct semaphore *sem1 __asm__ ("%a1") = sem;
115 __asm__ __volatile__(
116 "| atomic up operation\n\t"
117 "addql #1,%0@\n\t"
118 "jle 2f\n"
119 "1:\n"
120 ".section .text.lock,\"ax\"\n"
121 ".even\n"
122 "2:\t"
123 "pea 1b\n\t"
124 "jbra __up_wakeup\n"
125 ".previous"
126 : /* no outputs */
127 : "a" (sem1)
128 : "memory");
131 #endif