2 * Copyright (c) 2000-2009 Apple 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@
29 #include <mach/vm_types.h>
30 #include <i386/acpi.h> /* install_real_mode_bootstrap */
32 #include <i386/lapic.h> /* lapic_* functions */
33 #include <i386/machine_routines.h>
34 #include <i386/cpu_data.h>
35 #include <i386/pmap.h>
37 /* PAL-related routines */
38 void i386_cpu_IPI(int cpu
);
39 boolean_t
i386_smp_init(int nmi_vector
, i386_intr_func_t nmi_handler
,
40 int ipi_vector
, i386_intr_func_t ipi_handler
);
41 void i386_start_cpu(int lapic_id
, int cpu_num
);
42 void i386_send_NMI(int cpu
);
43 void handle_pending_TLB_flushes(void);
45 extern void slave_pstart(void);
48 int trappedalready
= 0; /* (BRINGUP) */
52 i386_smp_init(int nmi_vector
, i386_intr_func_t nmi_handler
, int ipi_vector
, i386_intr_func_t ipi_handler
)
60 lapic_set_intr_func(nmi_vector
, nmi_handler
);
61 lapic_set_intr_func(ipi_vector
, ipi_handler
);
63 install_real_mode_bootstrap(slave_pstart
);
69 i386_start_cpu(int lapic_id
, __unused
int cpu_num
)
71 LAPIC_WRITE(ICRD
, lapic_id
<< LAPIC_ICRD_DEST_SHIFT
);
72 LAPIC_WRITE(ICR
, LAPIC_ICR_DM_INIT
);
75 LAPIC_WRITE(ICRD
, lapic_id
<< LAPIC_ICRD_DEST_SHIFT
);
76 LAPIC_WRITE(ICR
, LAPIC_ICR_DM_STARTUP
|(REAL_MODE_BOOTSTRAP_OFFSET
>>12));
80 i386_send_NMI(int cpu
)
82 boolean_t state
= ml_set_interrupts_enabled(FALSE
);
83 /* Program the interrupt command register */
84 LAPIC_WRITE(ICRD
, cpu_to_lapic
[cpu
] << LAPIC_ICRD_DEST_SHIFT
);
85 /* The vector is ignored in this case--the target CPU will enter on the
88 LAPIC_WRITE(ICR
, LAPIC_VECTOR(INTERPROCESSOR
)|LAPIC_ICR_DM_NMI
);
89 (void) ml_set_interrupts_enabled(state
);
93 handle_pending_TLB_flushes(void)
95 volatile int *my_word
= ¤t_cpu_datap()->cpu_signals
;
97 if (i_bit(MP_TLB_FLUSH
, my_word
) && (pmap_tlb_flush_timeout
== FALSE
)) {
98 DBGLOG(cpu_handle
, cpu_number(), MP_TLB_FLUSH
);
99 i_bit_clear(MP_TLB_FLUSH
, my_word
);
100 pmap_update_interrupt();
105 i386_cpu_IPI(int cpu
)
108 if(cpu_datap(cpu
)->cpu_signals
& 6) { /* (BRINGUP) */
109 kprintf("i386_cpu_IPI: sending enter debugger signal (%08X) to cpu %d\n", cpu_datap(cpu
)->cpu_signals
, cpu
);
111 #endif /* MP_DEBUG */
115 if(!trappedalready
&& (cpu_datap(cpu
)->cpu_signals
& 6)) { /* (BRINGUP) */
116 if(kdb_cpu
!= cpu_number()) {
118 panic("i386_cpu_IPI: sending enter debugger signal (%08X) to cpu %d and I do not own debugger, owner = %08X\n",
119 cpu_datap(cpu
)->cpu_signals
, cpu
, kdb_cpu
);
122 #endif /* MP_DEBUG */
125 lapic_send_ipi(cpu
, LAPIC_VECTOR(INTERPROCESSOR
));