[PATCH] x86_64: fix cpu_to_node setup for sparse apic_ids
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / asm-m68k / semaphore.h
blobab94cf3ed4477b70b3f61c39b0dcec7d4cfffd04
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 __MUTEX_INITIALIZER(name) \
40 __SEMAPHORE_INITIALIZER(name,1)
42 #define __DECLARE_SEMAPHORE_GENERIC(name,count) \
43 struct semaphore name = __SEMAPHORE_INITIALIZER(name,count)
45 #define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1)
46 #define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name,0)
48 static inline void sema_init(struct semaphore *sem, int val)
50 *sem = (struct semaphore)__SEMAPHORE_INITIALIZER(*sem, val);
53 static inline void init_MUTEX (struct semaphore *sem)
55 sema_init(sem, 1);
58 static inline void init_MUTEX_LOCKED (struct semaphore *sem)
60 sema_init(sem, 0);
63 asmlinkage void __down_failed(void /* special register calling convention */);
64 asmlinkage int __down_failed_interruptible(void /* params in registers */);
65 asmlinkage int __down_failed_trylock(void /* params in registers */);
66 asmlinkage void __up_wakeup(void /* special register calling convention */);
68 asmlinkage void __down(struct semaphore * sem);
69 asmlinkage int __down_interruptible(struct semaphore * sem);
70 asmlinkage int __down_trylock(struct semaphore * sem);
71 asmlinkage void __up(struct semaphore * sem);
74 * This is ugly, but we want the default case to fall through.
75 * "down_failed" is a special asm handler that calls the C
76 * routine that actually waits. See arch/m68k/lib/semaphore.S
78 static inline void down(struct semaphore *sem)
80 register struct semaphore *sem1 __asm__ ("%a1") = sem;
82 might_sleep();
83 __asm__ __volatile__(
84 "| atomic down operation\n\t"
85 "subql #1,%0@\n\t"
86 "jmi 2f\n\t"
87 "1:\n"
88 LOCK_SECTION_START(".even\n\t")
89 "2:\tpea 1b\n\t"
90 "jbra __down_failed\n"
91 LOCK_SECTION_END
92 : /* no outputs */
93 : "a" (sem1)
94 : "memory");
97 static inline int down_interruptible(struct semaphore *sem)
99 register struct semaphore *sem1 __asm__ ("%a1") = sem;
100 register int result __asm__ ("%d0");
102 might_sleep();
103 __asm__ __volatile__(
104 "| atomic interruptible down operation\n\t"
105 "subql #1,%1@\n\t"
106 "jmi 2f\n\t"
107 "clrl %0\n"
108 "1:\n"
109 LOCK_SECTION_START(".even\n\t")
110 "2:\tpea 1b\n\t"
111 "jbra __down_failed_interruptible\n"
112 LOCK_SECTION_END
113 : "=d" (result)
114 : "a" (sem1)
115 : "memory");
116 return result;
119 static inline int down_trylock(struct semaphore *sem)
121 register struct semaphore *sem1 __asm__ ("%a1") = sem;
122 register int result __asm__ ("%d0");
124 __asm__ __volatile__(
125 "| atomic down trylock operation\n\t"
126 "subql #1,%1@\n\t"
127 "jmi 2f\n\t"
128 "clrl %0\n"
129 "1:\n"
130 LOCK_SECTION_START(".even\n\t")
131 "2:\tpea 1b\n\t"
132 "jbra __down_failed_trylock\n"
133 LOCK_SECTION_END
134 : "=d" (result)
135 : "a" (sem1)
136 : "memory");
137 return result;
141 * Note! This is subtle. We jump to wake people up only if
142 * the semaphore was negative (== somebody was waiting on it).
143 * The default case (no contention) will result in NO
144 * jumps for both down() and up().
146 static inline void up(struct semaphore *sem)
148 register struct semaphore *sem1 __asm__ ("%a1") = sem;
150 __asm__ __volatile__(
151 "| atomic up operation\n\t"
152 "addql #1,%0@\n\t"
153 "jle 2f\n"
154 "1:\n"
155 LOCK_SECTION_START(".even\n\t")
156 "2:\t"
157 "pea 1b\n\t"
158 "jbra __up_wakeup\n"
159 LOCK_SECTION_END
160 : /* no outputs */
161 : "a" (sem1)
162 : "memory");
165 #endif /* __ASSEMBLY__ */
167 #endif