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 $
29 #ifndef _MACHINE_LOCK_H_
30 #define _MACHINE_LOCK_H_
37 #define MPLOCKED lock ;
40 * Some handy macros to allow logical organization.
43 #define MP_LOCK call _get_mplock
46 pushl $_mp_lock ; /* GIANT_LOCK */ \
47 call _MPtrylock ; /* try to get lock */ \
51 movl $_mp_lock,%edx ; /* GIANT_LOCK */ \
55 * Protects the IO APIC and apic_imen as a critical region.
58 pushl $_imen_lock ; /* address of lock */ \
59 call _s_lock ; /* MP-safe */ \
62 #define IMASK_UNLOCK \
67 #define MPLOCKED /* NOP */
69 #define MP_LOCK /* NOP */
77 #include <machine/smptests.h> /** xxx_LOCK */
80 * Locks regions protected in UP kernel via cli/sti.
83 #define MPINTR_LOCK() s_lock(&mpintr_lock)
84 #define MPINTR_UNLOCK() s_unlock(&mpintr_lock)
87 #define MPINTR_UNLOCK()
88 #endif /* USE_MPINTRLOCK */
92 * XXX should rc (RISCom/8) use this?
95 #define COM_LOCK() s_lock(&com_lock)
96 #define COM_UNLOCK() s_unlock(&com_lock)
97 #define COM_DISABLE_INTR() \
98 { __asm __volatile("cli" : : : "memory"); COM_LOCK(); }
99 #define COM_ENABLE_INTR() \
100 { COM_UNLOCK(); __asm __volatile("sti"); }
104 #define COM_DISABLE_INTR() disable_intr()
105 #define COM_ENABLE_INTR() enable_intr()
106 #endif /* USE_COMLOCK */
109 * Clock hardware/struct lock.
110 * XXX pcaudio and friends still need this lock installed.
113 #define CLOCK_LOCK() s_lock(&clock_lock)
114 #define CLOCK_UNLOCK() s_unlock(&clock_lock)
115 #define CLOCK_DISABLE_INTR() \
116 { __asm __volatile("cli" : : : "memory"); CLOCK_LOCK(); }
117 #define CLOCK_ENABLE_INTR() \
118 { CLOCK_UNLOCK(); __asm __volatile("sti"); }
121 #define CLOCK_UNLOCK()
122 #define CLOCK_DISABLE_INTR() disable_intr()
123 #define CLOCK_ENABLE_INTR() enable_intr()
124 #endif /* USE_CLOCKLOCK */
128 #define MPINTR_LOCK()
129 #define MPINTR_UNLOCK()
134 #define CLOCK_UNLOCK()
140 * It is an error to hold one of these locks while a process is sleeping.
143 volatile int lock_data;
146 /* functions in simplelock.s */
147 void s_lock_init __P((struct simplelock *));
148 void s_lock __P((struct simplelock *));
149 int s_lock_try __P((struct simplelock *));
150 void ss_lock __P((struct simplelock *));
151 void ss_unlock __P((struct simplelock *));
152 void s_lock_np __P((struct simplelock *));
153 void s_unlock_np __P((struct simplelock *));
155 /* inline simplelock functions */
157 s_unlock(struct simplelock *lkp)
162 /* global data in mp_machdep.c */
163 extern struct simplelock imen_lock;
164 extern struct simplelock cpl_lock;
165 extern struct simplelock fast_intr_lock;
166 extern struct simplelock intr_lock;
167 extern struct simplelock clock_lock;
168 extern struct simplelock com_lock;
169 extern struct simplelock mpintr_lock;
170 extern struct simplelock mcount_lock;
172 #if !defined(SIMPLELOCK_DEBUG) && MAXCPU > 1
174 * This set of defines turns on the real functions in i386/isa/apic_ipl.s.
176 #define simple_lock_init(alp) s_lock_init(alp)
177 #define simple_lock(alp) s_lock(alp)
178 #define simple_lock_try(alp) s_lock_try(alp)
179 #define simple_unlock(alp) s_unlock(alp)
181 #endif /* !SIMPLELOCK_DEBUG && MAXCPU > 1 */
185 #endif /* !_MACHINE_LOCK_H_ */