oops, forgot one. Remove another curproc/cred dependancy
[dragonfly.git] / sys / i386 / include / lock.h
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 1997, by Steve Passe
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
12 *
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
23 * SUCH DAMAGE.
24 *
25 * $FreeBSD: src/sys/i386/include/lock.h,v 1.11.2.2 2000/09/30 02:49:34 ps Exp $
1de703da 26 * $DragonFly: src/sys/i386/include/Attic/lock.h,v 1.2 2003/06/17 04:28:35 dillon Exp $
984263bc
MD
27 */
28
29
30#ifndef _MACHINE_LOCK_H_
31#define _MACHINE_LOCK_H_
32
33
34#ifdef LOCORE
35
36#ifdef SMP
37
38#define MPLOCKED lock ;
39
40/*
41 * Some handy macros to allow logical organization.
42 */
43
44#define MP_LOCK call _get_mplock
45
46#define MP_TRYLOCK \
47 pushl $_mp_lock ; /* GIANT_LOCK */ \
48 call _MPtrylock ; /* try to get lock */ \
49 add $4, %esp
50
51#define MP_RELLOCK \
52 movl $_mp_lock,%edx ; /* GIANT_LOCK */ \
53 call _MPrellock_edx
54
55/*
56 * Protects the IO APIC and apic_imen as a critical region.
57 */
58#define IMASK_LOCK \
59 pushl $_imen_lock ; /* address of lock */ \
60 call _s_lock ; /* MP-safe */ \
61 addl $4, %esp
62
63#define IMASK_UNLOCK \
64 movl $0, _imen_lock
65
66#else /* SMP */
67
68#define MPLOCKED /* NOP */
69
70#define MP_LOCK /* NOP */
71
72#endif /* SMP */
73
74#else /* LOCORE */
75
76#ifdef SMP
77
78#include <machine/smptests.h> /** xxx_LOCK */
79
80/*
81 * Locks regions protected in UP kernel via cli/sti.
82 */
83#ifdef USE_MPINTRLOCK
84#define MPINTR_LOCK() s_lock(&mpintr_lock)
85#define MPINTR_UNLOCK() s_unlock(&mpintr_lock)
86#else
87#define MPINTR_LOCK()
88#define MPINTR_UNLOCK()
89#endif /* USE_MPINTRLOCK */
90
91/*
92 * sio/cy lock.
93 * XXX should rc (RISCom/8) use this?
94 */
95#ifdef USE_COMLOCK
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"); }
102#else
103#define COM_LOCK()
104#define COM_UNLOCK()
105#define COM_DISABLE_INTR() disable_intr()
106#define COM_ENABLE_INTR() enable_intr()
107#endif /* USE_COMLOCK */
108
109/*
110 * Clock hardware/struct lock.
111 * XXX pcaudio and friends still need this lock installed.
112 */
113#ifdef USE_CLOCKLOCK
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"); }
120#else
121#define CLOCK_LOCK()
122#define CLOCK_UNLOCK()
123#define CLOCK_DISABLE_INTR() disable_intr()
124#define CLOCK_ENABLE_INTR() enable_intr()
125#endif /* USE_CLOCKLOCK */
126
127#else /* SMP */
128
129#define MPINTR_LOCK()
130#define MPINTR_UNLOCK()
131
132#define COM_LOCK()
133#define COM_UNLOCK()
134#define CLOCK_LOCK()
135#define CLOCK_UNLOCK()
136
137#endif /* SMP */
138
139/*
140 * Simple spin lock.
141 * It is an error to hold one of these locks while a process is sleeping.
142 */
143struct simplelock {
144 volatile int lock_data;
145};
146
147/* functions in simplelock.s */
148void s_lock_init __P((struct simplelock *));
149void s_lock __P((struct simplelock *));
150int s_lock_try __P((struct simplelock *));
151void ss_lock __P((struct simplelock *));
152void ss_unlock __P((struct simplelock *));
153void s_lock_np __P((struct simplelock *));
154void s_unlock_np __P((struct simplelock *));
155
156/* inline simplelock functions */
157static __inline void
158s_unlock(struct simplelock *lkp)
159{
160 lkp->lock_data = 0;
161}
162
163/* global data in mp_machdep.c */
164extern struct simplelock imen_lock;
165extern struct simplelock cpl_lock;
166extern struct simplelock fast_intr_lock;
167extern struct simplelock intr_lock;
168extern struct simplelock clock_lock;
169extern struct simplelock com_lock;
170extern struct simplelock mpintr_lock;
171extern struct simplelock mcount_lock;
172
173#if !defined(SIMPLELOCK_DEBUG) && MAXCPU > 1
174/*
175 * This set of defines turns on the real functions in i386/isa/apic_ipl.s.
176 */
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)
181
182#endif /* !SIMPLELOCK_DEBUG && MAXCPU > 1 */
183
184#endif /* LOCORE */
185
186#endif /* !_MACHINE_LOCK_H_ */