2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * Mach Operating System
33 * Copyright (c) 1991,1990 Carnegie Mellon University
34 * All Rights Reserved.
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
69 #include <i386/apic.h>
70 #include <i386/mp_events.h>
72 #define LAPIC_ID_MAX (LAPIC_ID_MASK)
74 #define MAX_CPUS (LAPIC_ID_MAX + 1)
77 #include <sys/cdefs.h>
78 #include <mach/boolean.h>
79 #include <mach/kern_return.h>
83 extern kern_return_t
intel_startCPU(int slot_num
);
84 extern void i386_init_slave(void);
85 extern void smp_init(void);
87 extern void cpu_interrupt(int cpu
);
89 extern void lapic_init(void);
90 extern void lapic_shutdown(void);
91 extern void lapic_smm_restore(void);
92 extern boolean_t
lapic_probe(void);
93 extern void lapic_dump(void);
94 extern int lapic_interrupt(int interrupt
, void *state
);
95 extern void lapic_end_of_interrupt(void);
96 extern int lapic_to_cpu
[];
97 extern int cpu_to_lapic
[];
98 extern int lapic_interrupt_base
;
99 extern void lapic_cpu_map(int lapic
, int cpu_num
);
101 extern void lapic_set_timer(
103 lapic_timer_mode_t mode
,
104 lapic_timer_divide_t divisor
,
105 lapic_timer_count_t initial_count
);
107 extern void lapic_get_timer(
108 lapic_timer_mode_t
*mode
,
109 lapic_timer_divide_t
*divisor
,
110 lapic_timer_count_t
*initial_count
,
111 lapic_timer_count_t
*current_count
);
113 typedef void (*i386_intr_func_t
)(void *);
114 extern void lapic_set_timer_func(i386_intr_func_t func
);
115 extern void lapic_set_pmi_func(i386_intr_func_t func
);
119 #endif /* ASSEMBLER */
121 #define CPU_NUMBER(r) \
122 movl %gs:CPU_NUMBER_GS,r
124 #define CPU_NUMBER_FROM_LAPIC(r) \
125 movl EXT(lapic_id),r; \
127 shrl $(LAPIC_ID_SHIFT),r; \
128 andl $(LAPIC_ID_MASK),r; \
129 movl EXT(lapic_to_cpu)(,r,4),r
132 /* word describing the reason for the interrupt, one per cpu */
135 #include <kern/lock.h>
137 extern unsigned int real_ncpus
; /* real number of cpus */
138 extern unsigned int max_ncpus
; /* max number of cpus */
139 decl_simple_lock_data(extern,kdb_lock
) /* kdb lock */
143 extern void console_init(void);
144 extern void *console_cpu_alloc(boolean_t boot_cpu
);
145 extern void console_cpu_free(void *console_buf
);
147 extern int kdb_cpu
; /* current cpu running kdb */
148 extern int kdb_debug
;
149 extern int kdb_is_slave
[];
150 extern int kdb_active
[];
152 extern volatile boolean_t mp_kdp_trap
;
153 extern void mp_kdp_enter(void);
154 extern void mp_kdp_exit(void);
157 * All cpu rendezvous:
159 extern void mp_rendezvous(void (*setup_func
)(void *),
160 void (*action_func
)(void *),
161 void (*teardown_func
)(void *),
171 } cpu_signal_event_t
;
173 #define LOG_NENTRIES 100
175 uint64_t count
[MP_LAST
];
177 cpu_signal_event_t entry
[LOG_NENTRIES
];
178 } cpu_signal_event_log_t
;
180 extern cpu_signal_event_log_t
*cpu_signal
[];
181 extern cpu_signal_event_log_t
*cpu_handle
[];
183 #define DBGLOG(log,_cpu,_event) { \
184 boolean_t spl = ml_set_interrupts_enabled(FALSE); \
185 cpu_signal_event_log_t *logp = log[cpu_number()]; \
186 int next = logp->next_entry; \
187 cpu_signal_event_t *eventp = &logp->entry[next]; \
189 logp->count[_event]++; \
191 eventp->time = rdtsc64(); \
192 eventp->cpu = _cpu; \
193 eventp->event = _event; \
194 if (next == (LOG_NENTRIES - 1)) \
195 logp->next_entry = 0; \
197 logp->next_entry++; \
199 (void) ml_set_interrupts_enabled(spl); \
202 #define DBGLOG_CPU_INIT(cpu) { \
203 cpu_signal_event_log_t **sig_logpp = &cpu_signal[cpu]; \
204 cpu_signal_event_log_t **hdl_logpp = &cpu_handle[cpu]; \
206 if (*sig_logpp == NULL && \
207 kmem_alloc(kernel_map, \
208 (vm_offset_t *) sig_logpp, \
209 sizeof(cpu_signal_event_log_t)) != KERN_SUCCESS)\
210 panic("DBGLOG_CPU_INIT cpu_signal allocation failed\n");\
211 bzero(*sig_logpp, sizeof(cpu_signal_event_log_t)); \
212 if (*hdl_logpp == NULL && \
213 kmem_alloc(kernel_map, \
214 (vm_offset_t *) hdl_logpp, \
215 sizeof(cpu_signal_event_log_t)) != KERN_SUCCESS)\
216 panic("DBGLOG_CPU_INIT cpu_handle allocation failed\n");\
217 bzero(*sig_logpp, sizeof(cpu_signal_event_log_t)); \
220 #define DBGLOG(log,_cpu,_event)
221 #define DBGLOG_CPU_INIT(cpu)
222 #endif /* MP_DEBUG */
224 #endif /* ASSEMBLER */
226 #define i_bit(bit, word) ((long)(*(word)) & ((long)1 << (bit)))
230 * Device driver synchronization.
232 * at386_io_lock(op) and at386_io_unlock() are called
233 * by device drivers when accessing H/W. The underlying
234 * Processing is machine dependant. But the op argument
235 * to the at386_io_lock is generic
238 #define MP_DEV_OP_MAX 4
239 #define MP_DEV_WAIT MP_DEV_OP_MAX /* Wait for the lock */
242 * If the caller specifies an op value different than MP_DEV_WAIT, the
243 * at386_io_lock function must return true if lock was successful else
247 #define MP_DEV_OP_START 0 /* If lock busy, register a pending start op */
248 #define MP_DEV_OP_INTR 1 /* If lock busy, register a pending intr */
249 #define MP_DEV_OP_TIMEO 2 /* If lock busy, register a pending timeout */
250 #define MP_DEV_OP_CALLB 3 /* If lock busy, register a pending callback */
253 #define _DISABLE_PREEMPTION \
254 incl %gs:CPU_PREEMPTION_LEVEL
256 #define _ENABLE_PREEMPTION \
257 decl %gs:CPU_PREEMPTION_LEVEL ; \
262 call EXT(kernel_preempt_check) ; \
268 #define _ENABLE_PREEMPTION_NO_CHECK \
269 decl %gs:CPU_PREEMPTION_LEVEL
272 #define DISABLE_PREEMPTION \
276 call EXT(_disable_preemption); \
280 #define ENABLE_PREEMPTION \
284 call EXT(_enable_preemption); \
288 #define ENABLE_PREEMPTION_NO_CHECK \
292 call EXT(_enable_preemption_no_check); \
296 #define MP_DISABLE_PREEMPTION \
300 call EXT(_mp_disable_preemption); \
304 #define MP_ENABLE_PREEMPTION \
308 call EXT(_mp_enable_preemption); \
312 #define MP_ENABLE_PREEMPTION_NO_CHECK \
316 call EXT(_mp_enable_preemption_no_check); \
320 #else /* MACH_ASSERT */
321 #define DISABLE_PREEMPTION _DISABLE_PREEMPTION
322 #define ENABLE_PREEMPTION _ENABLE_PREEMPTION
323 #define ENABLE_PREEMPTION_NO_CHECK _ENABLE_PREEMPTION_NO_CHECK
324 #define MP_DISABLE_PREEMPTION _DISABLE_PREEMPTION
325 #define MP_ENABLE_PREEMPTION _ENABLE_PREEMPTION
326 #define MP_ENABLE_PREEMPTION_NO_CHECK _ENABLE_PREEMPTION_NO_CHECK
327 #endif /* MACH_ASSERT */
330 #define DISABLE_PREEMPTION
331 #define ENABLE_PREEMPTION
332 #define ENABLE_PREEMPTION_NO_CHECK
333 #define MP_DISABLE_PREEMPTION
334 #define MP_ENABLE_PREEMPTION
335 #define MP_ENABLE_PREEMPTION_NO_CHECK
338 #endif /* _I386AT_MP_H_ */
340 #endif /* KERNEL_PRIVATE */