2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1991,1990 Carnegie Mellon University
28 * All Rights Reserved.
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
63 #include <i386/apic.h>
64 #include <i386/mp_events.h>
66 #define LAPIC_ID_MAX (LAPIC_ID_MASK)
68 #define MAX_CPUS (LAPIC_ID_MAX + 1)
71 #include <sys/cdefs.h>
72 #include <mach/boolean.h>
73 #include <mach/kern_return.h>
77 extern kern_return_t
intel_startCPU(int slot_num
);
78 extern void i386_init_slave(void);
79 extern void smp_init(void);
81 extern void cpu_interrupt(int cpu
);
83 extern void lapic_init(void);
84 extern void lapic_shutdown(void);
85 extern void lapic_smm_restore(void);
86 extern boolean_t
lapic_probe(void);
87 extern void lapic_dump(void);
88 extern int lapic_interrupt(int interrupt
, void *state
);
89 extern void lapic_end_of_interrupt(void);
90 extern int lapic_to_cpu
[];
91 extern int cpu_to_lapic
[];
92 extern int lapic_interrupt_base
;
93 extern void lapic_cpu_map(int lapic
, int cpu_num
);
95 extern void lapic_set_timer(
97 lapic_timer_mode_t mode
,
98 lapic_timer_divide_t divisor
,
99 lapic_timer_count_t initial_count
);
101 extern void lapic_get_timer(
102 lapic_timer_mode_t
*mode
,
103 lapic_timer_divide_t
*divisor
,
104 lapic_timer_count_t
*initial_count
,
105 lapic_timer_count_t
*current_count
);
107 typedef void (*i386_intr_func_t
)(void *);
108 extern void lapic_set_timer_func(i386_intr_func_t func
);
109 extern void lapic_set_pmi_func(i386_intr_func_t func
);
113 #endif /* ASSEMBLER */
115 #define CPU_NUMBER(r) \
116 movl %gs:CPU_NUMBER_GS,r
118 #define CPU_NUMBER_FROM_LAPIC(r) \
119 movl EXT(lapic_id),r; \
121 shrl $(LAPIC_ID_SHIFT),r; \
122 andl $(LAPIC_ID_MASK),r; \
123 movl EXT(lapic_to_cpu)(,r,4),r
126 /* word describing the reason for the interrupt, one per cpu */
129 #include <kern/lock.h>
131 extern unsigned int real_ncpus
; /* real number of cpus */
132 extern unsigned int max_ncpus
; /* max number of cpus */
133 decl_simple_lock_data(extern,kdb_lock
) /* kdb lock */
137 extern void console_init(void);
138 extern void *console_cpu_alloc(boolean_t boot_cpu
);
139 extern void console_cpu_free(void *console_buf
);
141 extern int kdb_cpu
; /* current cpu running kdb */
142 extern int kdb_debug
;
143 extern int kdb_is_slave
[];
144 extern int kdb_active
[];
146 extern volatile boolean_t mp_kdp_trap
;
147 extern void mp_kdp_enter(void);
148 extern void mp_kdp_exit(void);
151 * All cpu rendezvous:
153 extern void mp_rendezvous(void (*setup_func
)(void *),
154 void (*action_func
)(void *),
155 void (*teardown_func
)(void *),
165 } cpu_signal_event_t
;
167 #define LOG_NENTRIES 100
169 uint64_t count
[MP_LAST
];
171 cpu_signal_event_t entry
[LOG_NENTRIES
];
172 } cpu_signal_event_log_t
;
174 extern cpu_signal_event_log_t
*cpu_signal
[];
175 extern cpu_signal_event_log_t
*cpu_handle
[];
177 #define DBGLOG(log,_cpu,_event) { \
178 boolean_t spl = ml_set_interrupts_enabled(FALSE); \
179 cpu_signal_event_log_t *logp = log[cpu_number()]; \
180 int next = logp->next_entry; \
181 cpu_signal_event_t *eventp = &logp->entry[next]; \
183 logp->count[_event]++; \
185 eventp->time = rdtsc64(); \
186 eventp->cpu = _cpu; \
187 eventp->event = _event; \
188 if (next == (LOG_NENTRIES - 1)) \
189 logp->next_entry = 0; \
191 logp->next_entry++; \
193 (void) ml_set_interrupts_enabled(spl); \
196 #define DBGLOG_CPU_INIT(cpu) { \
197 cpu_signal_event_log_t **sig_logpp = &cpu_signal[cpu]; \
198 cpu_signal_event_log_t **hdl_logpp = &cpu_handle[cpu]; \
200 if (*sig_logpp == NULL && \
201 kmem_alloc(kernel_map, \
202 (vm_offset_t *) sig_logpp, \
203 sizeof(cpu_signal_event_log_t)) != KERN_SUCCESS)\
204 panic("DBGLOG_CPU_INIT cpu_signal allocation failed\n");\
205 bzero(*sig_logpp, sizeof(cpu_signal_event_log_t)); \
206 if (*hdl_logpp == NULL && \
207 kmem_alloc(kernel_map, \
208 (vm_offset_t *) hdl_logpp, \
209 sizeof(cpu_signal_event_log_t)) != KERN_SUCCESS)\
210 panic("DBGLOG_CPU_INIT cpu_handle allocation failed\n");\
211 bzero(*sig_logpp, sizeof(cpu_signal_event_log_t)); \
214 #define DBGLOG(log,_cpu,_event)
215 #define DBGLOG_CPU_INIT(cpu)
216 #endif /* MP_DEBUG */
218 #endif /* ASSEMBLER */
220 #define i_bit(bit, word) ((long)(*(word)) & ((long)1 << (bit)))
224 * Device driver synchronization.
226 * at386_io_lock(op) and at386_io_unlock() are called
227 * by device drivers when accessing H/W. The underlying
228 * Processing is machine dependant. But the op argument
229 * to the at386_io_lock is generic
232 #define MP_DEV_OP_MAX 4
233 #define MP_DEV_WAIT MP_DEV_OP_MAX /* Wait for the lock */
236 * If the caller specifies an op value different than MP_DEV_WAIT, the
237 * at386_io_lock function must return true if lock was successful else
241 #define MP_DEV_OP_START 0 /* If lock busy, register a pending start op */
242 #define MP_DEV_OP_INTR 1 /* If lock busy, register a pending intr */
243 #define MP_DEV_OP_TIMEO 2 /* If lock busy, register a pending timeout */
244 #define MP_DEV_OP_CALLB 3 /* If lock busy, register a pending callback */
247 #define _DISABLE_PREEMPTION \
248 incl %gs:CPU_PREEMPTION_LEVEL
250 #define _ENABLE_PREEMPTION \
251 decl %gs:CPU_PREEMPTION_LEVEL ; \
256 call EXT(kernel_preempt_check) ; \
262 #define _ENABLE_PREEMPTION_NO_CHECK \
263 decl %gs:CPU_PREEMPTION_LEVEL
266 #define DISABLE_PREEMPTION \
270 call EXT(_disable_preemption); \
274 #define ENABLE_PREEMPTION \
278 call EXT(_enable_preemption); \
282 #define ENABLE_PREEMPTION_NO_CHECK \
286 call EXT(_enable_preemption_no_check); \
290 #define MP_DISABLE_PREEMPTION \
294 call EXT(_mp_disable_preemption); \
298 #define MP_ENABLE_PREEMPTION \
302 call EXT(_mp_enable_preemption); \
306 #define MP_ENABLE_PREEMPTION_NO_CHECK \
310 call EXT(_mp_enable_preemption_no_check); \
314 #else /* MACH_ASSERT */
315 #define DISABLE_PREEMPTION _DISABLE_PREEMPTION
316 #define ENABLE_PREEMPTION _ENABLE_PREEMPTION
317 #define ENABLE_PREEMPTION_NO_CHECK _ENABLE_PREEMPTION_NO_CHECK
318 #define MP_DISABLE_PREEMPTION _DISABLE_PREEMPTION
319 #define MP_ENABLE_PREEMPTION _ENABLE_PREEMPTION
320 #define MP_ENABLE_PREEMPTION_NO_CHECK _ENABLE_PREEMPTION_NO_CHECK
321 #endif /* MACH_ASSERT */
324 #define DISABLE_PREEMPTION
325 #define ENABLE_PREEMPTION
326 #define ENABLE_PREEMPTION_NO_CHECK
327 #define MP_DISABLE_PREEMPTION
328 #define MP_ENABLE_PREEMPTION
329 #define MP_ENABLE_PREEMPTION_NO_CHECK
332 #endif /* _I386AT_MP_H_ */
334 #endif /* KERNEL_PRIVATE */