]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/AT386/mp/mp.h
xnu-344.21.74.tar.gz
[apple/xnu.git] / osfmk / i386 / AT386 / mp / mp.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * @OSF_COPYRIGHT@
27 */
28 /*
29 * Mach Operating System
30 * Copyright (c) 1991,1990 Carnegie Mellon University
31 * All Rights Reserved.
32 *
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
38 *
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
42 *
43 * Carnegie Mellon requests users of this software to return to
44 *
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
49 *
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
52 */
53
54 /*
55 */
56
57 #ifndef _I386AT_MP_H_
58 #define _I386AT_MP_H_
59
60 #include <cpus.h>
61 #include <platforms.h>
62 #include <mp_v1_1.h>
63 #include <mach_rt.h>
64 #include <mach_assert.h>
65
66 #if NCPUS > 1
67 #include <i386/apic.h>
68 #include <i386/AT386/mp/mp_events.h>
69
70 #define CPU_NUMBER(r) \
71 movl EXT(lapic_id), r ; \
72 movl 0(r),r ; \
73 shrl $ LAPIC_ID_SHIFT, r; \
74 andl $ LAPIC_ID_MASK, r
75
76
77 #define MP_IPL SPL6 /* software interrupt level */
78
79 /* word describing the reason for the interrupt, one per cpu */
80
81 #ifndef ASSEMBLER
82 #include <kern/lock.h>
83 extern cpu_int_word[];
84 extern real_ncpus; /* real number of cpus */
85 extern wncpu; /* wanted number of cpus */
86 decl_simple_lock_data(extern,kdb_lock) /* kdb lock */
87
88 extern int kdb_cpu; /* current cpu running kdb */
89 extern int kdb_debug;
90 extern int kdb_is_slave[];
91 extern int kdb_active[];
92 #endif /* ASSEMBLER */
93
94 #define i_bit(bit, word) ((long)(*(word)) & ((long)1 << (bit)))
95
96
97 /*
98 * Device driver synchronization.
99 *
100 * at386_io_lock(op) and at386_io_unlock() are called
101 * by device drivers when accessing H/W. The underlying
102 * Processing is machine dependant. But the op argument
103 * to the at386_io_lock is generic
104 */
105
106 #define MP_DEV_OP_MAX 4
107 #define MP_DEV_WAIT MP_DEV_OP_MAX /* Wait for the lock */
108
109 /*
110 * If the caller specifies an op value different than MP_DEV_WAIT, the
111 * at386_io_lock function must return true if lock was successful else
112 * false
113 */
114
115 #define MP_DEV_OP_START 0 /* If lock busy, register a pending start op */
116 #define MP_DEV_OP_INTR 1 /* If lock busy, register a pending intr */
117 #define MP_DEV_OP_TIMEO 2 /* If lock busy, register a pending timeout */
118 #define MP_DEV_OP_CALLB 3 /* If lock busy, register a pending callback */
119
120 #else /* NCPUS > 1 */
121 #define at386_io_lock_state()
122 #define at386_io_lock(op) (TRUE)
123 #define at386_io_unlock()
124 #if MP_V1_1
125 #include <i386/apic.h>
126 #endif /* MP_V1_1 */
127 #endif /* NCPUS > 1 */
128
129 #if MACH_RT
130 #define _DISABLE_PREEMPTION(r) \
131 movl $ CPD_PREEMPTION_LEVEL,r ; \
132 incl %gs:(r)
133
134 #define _ENABLE_PREEMPTION(r) \
135 movl $ CPD_PREEMPTION_LEVEL,r ; \
136 decl %gs:(r) ; \
137 jne 9f ; \
138 pushl %eax ; \
139 pushl %ecx ; \
140 pushl %edx ; \
141 call EXT(kernel_preempt_check) ; \
142 popl %edx ; \
143 popl %ecx ; \
144 popl %eax ; \
145 9:
146
147 #define _ENABLE_PREEMPTION_NO_CHECK(r) \
148 movl $ CPD_PREEMPTION_LEVEL,r ; \
149 decl %gs:(r)
150
151 #if MACH_ASSERT
152 #define DISABLE_PREEMPTION(r) \
153 pushl %eax; \
154 pushl %ecx; \
155 pushl %edx; \
156 call EXT(_disable_preemption); \
157 popl %edx; \
158 popl %ecx; \
159 popl %eax
160 #define ENABLE_PREEMPTION(r) \
161 pushl %eax; \
162 pushl %ecx; \
163 pushl %edx; \
164 call EXT(_enable_preemption); \
165 popl %edx; \
166 popl %ecx; \
167 popl %eax
168 #define ENABLE_PREEMPTION_NO_CHECK(r) \
169 pushl %eax; \
170 pushl %ecx; \
171 pushl %edx; \
172 call EXT(_enable_preemption_no_check); \
173 popl %edx; \
174 popl %ecx; \
175 popl %eax
176 #if NCPUS > 1
177 #define MP_DISABLE_PREEMPTION(r) \
178 pushl %eax; \
179 pushl %ecx; \
180 pushl %edx; \
181 call EXT(_mp_disable_preemption); \
182 popl %edx; \
183 popl %ecx; \
184 popl %eax
185 #define MP_ENABLE_PREEMPTION(r) \
186 pushl %eax; \
187 pushl %ecx; \
188 pushl %edx; \
189 call EXT(_mp_enable_preemption); \
190 popl %edx; \
191 popl %ecx; \
192 popl %eax
193 #define MP_ENABLE_PREEMPTION_NO_CHECK(r) \
194 pushl %eax; \
195 pushl %ecx; \
196 pushl %edx; \
197 call EXT(_mp_enable_preemption_no_check); \
198 popl %edx; \
199 popl %ecx; \
200 popl %eax
201 #else /* NCPUS > 1 */
202 #define MP_DISABLE_PREEMPTION(r)
203 #define MP_ENABLE_PREEMPTION(r)
204 #define MP_ENABLE_PREEMPTION_NO_CHECK(r)
205 #endif /* NCPUS > 1 */
206 #else /* MACH_ASSERT */
207 #define DISABLE_PREEMPTION(r) _DISABLE_PREEMPTION(r)
208 #define ENABLE_PREEMPTION(r) _ENABLE_PREEMPTION(r)
209 #define ENABLE_PREEMPTION_NO_CHECK(r) _ENABLE_PREEMPTION_NO_CHECK(r)
210 #if NCPUS > 1
211 #define MP_DISABLE_PREEMPTION(r) _DISABLE_PREEMPTION(r)
212 #define MP_ENABLE_PREEMPTION(r) _ENABLE_PREEMPTION(r)
213 #define MP_ENABLE_PREEMPTION_NO_CHECK(r) _ENABLE_PREEMPTION_NO_CHECK(r)
214 #else /* NCPUS > 1 */
215 #define MP_DISABLE_PREEMPTION(r)
216 #define MP_ENABLE_PREEMPTION(r)
217 #define MP_ENABLE_PREEMPTION_NO_CHECK(r)
218 #endif /* NCPUS > 1 */
219 #endif /* MACH_ASSERT */
220
221 #else /* MACH_RT */
222 #define DISABLE_PREEMPTION(r)
223 #define ENABLE_PREEMPTION(r)
224 #define ENABLE_PREEMPTION_NO_CHECK(r)
225 #define MP_DISABLE_PREEMPTION(r)
226 #define MP_ENABLE_PREEMPTION(r)
227 #define MP_ENABLE_PREEMPTION_NO_CHECK(r)
228 #endif /* MACH_RT */
229
230 #endif /* _I386AT_MP_H_ */