2 * Copyright (c) 1997, by Steve Passe
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. The name of the developer may NOT be used to endorse or promote products
11 * derived from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * $FreeBSD: src/sys/i386/include/lock.h,v 1.11.2.2 2000/09/30 02:49:34 ps Exp $
26 * $DragonFly: src/sys/platform/pc32/include/lock.h,v 1.2 2003/06/17 04:28:35 dillon Exp $
30 #ifndef _MACHINE_LOCK_H_
31 #define _MACHINE_LOCK_H_
38 #define MPLOCKED lock ;
41 * Some handy macros to allow logical organization.
44 #define MP_LOCK call _get_mplock
47 pushl $_mp_lock ; /* GIANT_LOCK */ \
48 call _MPtrylock ; /* try to get lock */ \
52 movl $_mp_lock,%edx ; /* GIANT_LOCK */ \
56 * Protects the IO APIC and apic_imen as a critical region.
59 pushl $_imen_lock ; /* address of lock */ \
60 call _s_lock ; /* MP-safe */ \
63 #define IMASK_UNLOCK \
68 #define MPLOCKED /* NOP */
70 #define MP_LOCK /* NOP */
78 #include <machine/smptests.h> /** xxx_LOCK */
81 * Locks regions protected in UP kernel via cli/sti.
84 #define MPINTR_LOCK() s_lock(&mpintr_lock)
85 #define MPINTR_UNLOCK() s_unlock(&mpintr_lock)
88 #define MPINTR_UNLOCK()
89 #endif /* USE_MPINTRLOCK */
93 * XXX should rc (RISCom/8) use this?
96 #define COM_LOCK() s_lock(&com_lock)
97 #define COM_UNLOCK() s_unlock(&com_lock)
98 #define COM_DISABLE_INTR() \
99 { __asm __volatile("cli" : : : "memory"); COM_LOCK(); }
100 #define COM_ENABLE_INTR() \
101 { COM_UNLOCK(); __asm __volatile("sti"); }
105 #define COM_DISABLE_INTR() disable_intr()
106 #define COM_ENABLE_INTR() enable_intr()
107 #endif /* USE_COMLOCK */
110 * Clock hardware/struct lock.
111 * XXX pcaudio and friends still need this lock installed.
114 #define CLOCK_LOCK() s_lock(&clock_lock)
115 #define CLOCK_UNLOCK() s_unlock(&clock_lock)
116 #define CLOCK_DISABLE_INTR() \
117 { __asm __volatile("cli" : : : "memory"); CLOCK_LOCK(); }
118 #define CLOCK_ENABLE_INTR() \
119 { CLOCK_UNLOCK(); __asm __volatile("sti"); }
122 #define CLOCK_UNLOCK()
123 #define CLOCK_DISABLE_INTR() disable_intr()
124 #define CLOCK_ENABLE_INTR() enable_intr()
125 #endif /* USE_CLOCKLOCK */
129 #define MPINTR_LOCK()
130 #define MPINTR_UNLOCK()
135 #define CLOCK_UNLOCK()
141 * It is an error to hold one of these locks while a process is sleeping.
144 volatile int lock_data;
147 /* functions in simplelock.s */
148 void s_lock_init __P((struct simplelock *));
149 void s_lock __P((struct simplelock *));
150 int s_lock_try __P((struct simplelock *));
151 void ss_lock __P((struct simplelock *));
152 void ss_unlock __P((struct simplelock *));
153 void s_lock_np __P((struct simplelock *));
154 void s_unlock_np __P((struct simplelock *));
156 /* inline simplelock functions */
158 s_unlock(struct simplelock *lkp)
163 /* global data in mp_machdep.c */
164 extern struct simplelock imen_lock;
165 extern struct simplelock cpl_lock;
166 extern struct simplelock fast_intr_lock;
167 extern struct simplelock intr_lock;
168 extern struct simplelock clock_lock;
169 extern struct simplelock com_lock;
170 extern struct simplelock mpintr_lock;
171 extern struct simplelock mcount_lock;
173 #if !defined(SIMPLELOCK_DEBUG) && MAXCPU > 1
175 * This set of defines turns on the real functions in i386/isa/apic_ipl.s.
177 #define simple_lock_init(alp) s_lock_init(alp)
178 #define simple_lock(alp) s_lock(alp)
179 #define simple_lock_try(alp) s_lock_try(alp)
180 #define simple_unlock(alp) s_unlock(alp)
182 #endif /* !SIMPLELOCK_DEBUG && MAXCPU > 1 */
186 #endif /* !_MACHINE_LOCK_H_ */