]> git.saurik.com Git - apple/xnu.git/blame - osfmk/i386/mp_native.c
xnu-7195.101.1.tar.gz
[apple/xnu.git] / osfmk / i386 / mp_native.c
CommitLineData
6d2010ae
A
1/*
2 * Copyright (c) 2000-2009 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 5 *
6d2010ae
A
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.
0a7de745 14 *
6d2010ae
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 17 *
6d2010ae
A
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.
0a7de745 25 *
6d2010ae
A
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29#include <mach/vm_types.h>
30#include <i386/acpi.h> /* install_real_mode_bootstrap */
31#include <i386/mp.h>
32#include <i386/lapic.h> /* lapic_* functions */
33#include <i386/machine_routines.h>
34#include <i386/cpu_data.h>
35#include <i386/pmap.h>
fe8ab488 36#include <i386/bit_routines.h>
6d2010ae
A
37
38/* PAL-related routines */
39void i386_cpu_IPI(int cpu);
0a7de745
A
40boolean_t i386_smp_init(int nmi_vector, i386_intr_func_t nmi_handler,
41 int ipi_vector, i386_intr_func_t ipi_handler);
6d2010ae
A
42void i386_start_cpu(int lapic_id, int cpu_num);
43void i386_send_NMI(int cpu);
44void handle_pending_TLB_flushes(void);
5c9f4661 45void NMIPI_enable(boolean_t);
6d2010ae 46
0a7de745 47extern void slave_pstart(void);
6d2010ae 48
0a7de745
A
49#ifdef MP_DEBUG
50int trappedalready = 0; /* (BRINGUP) */
51#endif /* MP_DEBUG */
6d2010ae
A
52
53boolean_t
54i386_smp_init(int nmi_vector, i386_intr_func_t nmi_handler, int ipi_vector, i386_intr_func_t ipi_handler)
55{
56 /* Local APIC? */
0a7de745 57 if (!lapic_probe()) {
6d2010ae 58 return FALSE;
0a7de745 59 }
6d2010ae
A
60
61 lapic_init();
f427ee49 62 lapic_configure(false);
0a7de745 63 lapic_set_intr_func(nmi_vector, nmi_handler);
6d2010ae
A
64 lapic_set_intr_func(ipi_vector, ipi_handler);
65
66 install_real_mode_bootstrap(slave_pstart);
67
68 return TRUE;
69}
70
71void
72i386_start_cpu(int lapic_id, __unused int cpu_num )
73{
bd504ef0 74 LAPIC_WRITE_ICR(lapic_id, LAPIC_ICR_DM_INIT);
6d2010ae 75 delay(100);
bd504ef0 76 LAPIC_WRITE_ICR(lapic_id,
0a7de745 77 LAPIC_ICR_DM_STARTUP | (REAL_MODE_BOOTSTRAP_OFFSET >> 12));
6d2010ae
A
78}
79
5c9f4661
A
80static boolean_t NMIPIs_enabled = FALSE;
81
0a7de745
A
82void
83NMIPI_enable(boolean_t enable)
84{
5c9f4661
A
85 NMIPIs_enabled = enable;
86}
87
6d2010ae
A
88void
89i386_send_NMI(int cpu)
90{
91 boolean_t state = ml_set_interrupts_enabled(FALSE);
5c9f4661
A
92
93 if (NMIPIs_enabled == FALSE) {
94 i386_cpu_IPI(cpu);
95 } else {
0a7de745
A
96 /* Program the interrupt command register */
97 /* The vector is ignored in this case--the target CPU will enter on the
98 * NMI vector.
99 */
100 LAPIC_WRITE_ICR(cpu_to_lapic[cpu],
101 LAPIC_VECTOR(INTERPROCESSOR) | LAPIC_ICR_DM_NMI);
5c9f4661 102 }
6d2010ae
A
103 (void) ml_set_interrupts_enabled(state);
104}
105
106void
107handle_pending_TLB_flushes(void)
108{
0a7de745 109 volatile int *my_word = &current_cpu_datap()->cpu_signals;
6d2010ae 110
0a7de745 111 if (i_bit(MP_TLB_FLUSH, my_word) && (pmap_tlb_flush_timeout == FALSE)) {
6d2010ae
A
112 DBGLOG(cpu_handle, cpu_number(), MP_TLB_FLUSH);
113 i_bit_clear(MP_TLB_FLUSH, my_word);
114 pmap_update_interrupt();
115 }
116}
117
118void
119i386_cpu_IPI(int cpu)
120{
0a7de745
A
121#ifdef MP_DEBUG
122 if (cpu_datap(cpu)->cpu_signals & 6) { /* (BRINGUP) */
6d2010ae
A
123 kprintf("i386_cpu_IPI: sending enter debugger signal (%08X) to cpu %d\n", cpu_datap(cpu)->cpu_signals, cpu);
124 }
0a7de745 125#endif /* MP_DEBUG */
6d2010ae 126
6d2010ae
A
127 lapic_send_ipi(cpu, LAPIC_VECTOR(INTERPROCESSOR));
128}