2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
29 * Mach Operating System
30 * Copyright (c) 1991,1990 Carnegie Mellon University
31 * All Rights Reserved.
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.
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.
43 * Carnegie Mellon requests users of this software to return to
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
62 #endif /* !defined(NCPUS) */
73 #include <i386/apic.h>
74 #include <i386/mp_events.h>
76 #define SPURIOUS_INTERRUPT 0xDD
77 #define INTERPROCESS_INTERRUPT 0xDE
78 #define APIC_ERROR_INTERRUPT 0xDF
80 #define LAPIC_ID_MAX (LAPIC_ID_MASK)
83 extern void lapic_dump(void);
84 extern void lapic_interrupt(int interrupt
, void *state
);
85 extern int lapic_to_cpu
[];
86 extern int cpu_to_lapic
[];
87 extern void lapic_cpu_map(int lapic
, int cpu_num
);
88 #endif /* ASSEMBLER */
90 #define CPU_NUMBER(r) \
91 movl EXT(lapic_id),r; \
93 shrl $(LAPIC_ID_SHIFT),r; \
94 andl $(LAPIC_ID_MASK),r; \
95 movl EXT(lapic_to_cpu)(,r,4),r
98 #define MP_IPL SPL6 /* software interrupt level */
100 /* word describing the reason for the interrupt, one per cpu */
103 #include <kern/lock.h>
104 extern int real_ncpus
; /* real number of cpus */
105 extern int wncpu
; /* wanted number of cpus */
106 decl_simple_lock_data(extern,kdb_lock
) /* kdb lock */
107 decl_simple_lock_data(extern,mp_putc_lock
)
109 extern int kdb_cpu
; /* current cpu running kdb */
110 extern int kdb_debug
;
111 extern int kdb_is_slave
[];
112 extern int kdb_active
[];
114 extern volatile boolean_t mp_kdp_trap
;
115 extern void mp_trap_enter();
116 extern void mp_trap_exit();
119 * All cpu rendezvous:
121 extern void mp_rendezvous(void (*setup_func
)(void *),
122 void (*action_func
)(void *),
123 void (*teardown_func
)(void *),
131 } cpu_signal_event_t
;
133 #define LOG_NENTRIES 100
135 uint64_t count
[MP_LAST
];
137 cpu_signal_event_t entry
[LOG_NENTRIES
];
138 } cpu_signal_event_log_t
;
140 extern cpu_signal_event_log_t cpu_signal
[NCPUS
];
141 extern cpu_signal_event_log_t cpu_handle
[NCPUS
];
143 #define DBGLOG(log,_cpu,_event) { \
144 cpu_signal_event_log_t *logp = &log[cpu_number()]; \
145 int next = logp->next_entry; \
146 cpu_signal_event_t *eventp = &logp->entry[next]; \
147 boolean_t spl = ml_set_interrupts_enabled(FALSE); \
149 logp->count[_event]++; \
151 eventp->time = rdtsc64(); \
152 eventp->cpu = _cpu; \
153 eventp->event = _event; \
154 if (next == (LOG_NENTRIES - 1)) \
155 logp->next_entry = 0; \
157 logp->next_entry++; \
159 (void) ml_set_interrupts_enabled(spl); \
162 #define DBGLOG(log,_cpu,_event)
163 #endif /* MP_DEBUG */
165 #endif /* ASSEMBLER */
167 #define i_bit(bit, word) ((long)(*(word)) & ((long)1 << (bit)))
171 * Device driver synchronization.
173 * at386_io_lock(op) and at386_io_unlock() are called
174 * by device drivers when accessing H/W. The underlying
175 * Processing is machine dependant. But the op argument
176 * to the at386_io_lock is generic
179 #define MP_DEV_OP_MAX 4
180 #define MP_DEV_WAIT MP_DEV_OP_MAX /* Wait for the lock */
183 * If the caller specifies an op value different than MP_DEV_WAIT, the
184 * at386_io_lock function must return true if lock was successful else
188 #define MP_DEV_OP_START 0 /* If lock busy, register a pending start op */
189 #define MP_DEV_OP_INTR 1 /* If lock busy, register a pending intr */
190 #define MP_DEV_OP_TIMEO 2 /* If lock busy, register a pending timeout */
191 #define MP_DEV_OP_CALLB 3 /* If lock busy, register a pending callback */
193 #else /* NCPUS > 1 */
194 #define at386_io_lock_state()
195 #define at386_io_lock(op) (TRUE)
196 #define at386_io_unlock()
197 #define mp_trap_enter()
198 #define mp_trap_exit()
199 #include <i386/apic.h>
200 #endif /* NCPUS > 1 */
203 #define _DISABLE_PREEMPTION(r) \
204 movl $ CPD_PREEMPTION_LEVEL,r ; \
207 #define _ENABLE_PREEMPTION(r) \
208 movl $ CPD_PREEMPTION_LEVEL,r ; \
214 call EXT(kernel_preempt_check) ; \
220 #define _ENABLE_PREEMPTION_NO_CHECK(r) \
221 movl $ CPD_PREEMPTION_LEVEL,r ; \
225 #define DISABLE_PREEMPTION(r) \
229 call EXT(_disable_preemption); \
233 #define ENABLE_PREEMPTION(r) \
237 call EXT(_enable_preemption); \
241 #define ENABLE_PREEMPTION_NO_CHECK(r) \
245 call EXT(_enable_preemption_no_check); \
250 #define MP_DISABLE_PREEMPTION(r) \
254 call EXT(_mp_disable_preemption); \
258 #define MP_ENABLE_PREEMPTION(r) \
262 call EXT(_mp_enable_preemption); \
266 #define MP_ENABLE_PREEMPTION_NO_CHECK(r) \
270 call EXT(_mp_enable_preemption_no_check); \
274 #else /* NCPUS > 1 */
275 #define MP_DISABLE_PREEMPTION(r)
276 #define MP_ENABLE_PREEMPTION(r)
277 #define MP_ENABLE_PREEMPTION_NO_CHECK(r)
278 #endif /* NCPUS > 1 */
279 #else /* MACH_ASSERT */
280 #define DISABLE_PREEMPTION(r) _DISABLE_PREEMPTION(r)
281 #define ENABLE_PREEMPTION(r) _ENABLE_PREEMPTION(r)
282 #define ENABLE_PREEMPTION_NO_CHECK(r) _ENABLE_PREEMPTION_NO_CHECK(r)
284 #define MP_DISABLE_PREEMPTION(r) _DISABLE_PREEMPTION(r)
285 #define MP_ENABLE_PREEMPTION(r) _ENABLE_PREEMPTION(r)
286 #define MP_ENABLE_PREEMPTION_NO_CHECK(r) _ENABLE_PREEMPTION_NO_CHECK(r)
287 #else /* NCPUS > 1 */
288 #define MP_DISABLE_PREEMPTION(r)
289 #define MP_ENABLE_PREEMPTION(r)
290 #define MP_ENABLE_PREEMPTION_NO_CHECK(r)
291 #endif /* NCPUS > 1 */
292 #endif /* MACH_ASSERT */
295 #define DISABLE_PREEMPTION(r)
296 #define ENABLE_PREEMPTION(r)
297 #define ENABLE_PREEMPTION_NO_CHECK(r)
298 #define MP_DISABLE_PREEMPTION(r)
299 #define MP_ENABLE_PREEMPTION(r)
300 #define MP_ENABLE_PREEMPTION_NO_CHECK(r)
303 #endif /* _I386AT_MP_H_ */