1 /* $OpenBSD: ipifuncs.c,v 1.39 2024/06/07 16:53:35 kettenis Exp $ */
2 /* $NetBSD: ipifuncs.c,v 1.1 2003/04/26 18:39:28 fvdl Exp $ */
3
4 /*-
5 * Copyright (c) 2000 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by RedBack Networks Inc.
10 *
11 * Author: Bill Sommerfeld
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 /*
36 * Interprocessor interrupt handlers.
37 */
38
39 #include <sys/param.h>
40 #include <sys/device.h>
41 #include <sys/memrange.h>
42 #include <sys/systm.h>
43
44 #include <uvm/uvm_extern.h>
45
46 #include <machine/intr.h>
47 #include <machine/atomic.h>
48 #include <machine/cpuvar.h>
49 #include <machine/i82093var.h>
50 #include <machine/i82489var.h>
51 #include <machine/fpu.h>
52 #include <machine/mplock.h>
53
54 #include <machine/db_machdep.h>
55
56 #include "vmm.h"
57 #if NVMM > 0
58 #include <machine/vmmvar.h>
59 #endif /* NVMM > 0 */
60
61 void x86_64_ipi_nop(struct cpu_info *);
62 void x86_64_ipi_halt(struct cpu_info *);
63 void x86_64_ipi_wbinvd(struct cpu_info *);
64
65 #if NVMM > 0
66 void x86_64_ipi_vmclear_vmm(struct cpu_info *);
67 void x86_64_ipi_start_vmm(struct cpu_info *);
68 void x86_64_ipi_stop_vmm(struct cpu_info *);
69 #endif /* NVMM > 0 */
70
71 #include "pctr.h"
72 #if NPCTR > 0
73 #include <machine/pctr.h>
74 #define x86_64_ipi_reload_pctr pctr_reload
75 #else
76 #define x86_64_ipi_reload_pctr NULL
77 #endif
78
79 #ifdef MTRR
80 void x86_64_ipi_reload_mtrr(struct cpu_info *);
81 #else
82 #define x86_64_ipi_reload_mtrr NULL
83 #endif
84
85 void (*ipifunc[X86_NIPI])(struct cpu_info *) =
86 {
87 x86_64_ipi_halt,
88 x86_64_ipi_nop,
89 #if NVMM > 0
90 x86_64_ipi_vmclear_vmm,
91 #else
92 NULL,
93 #endif
94 NULL,
95 x86_64_ipi_reload_pctr,
96 x86_64_ipi_reload_mtrr,
97 x86_setperf_ipi,
98 #ifdef DDB
99 x86_ipi_db,
100 #else
101 NULL,
102 #endif
103 #if NVMM > 0
104 x86_64_ipi_start_vmm,
105 x86_64_ipi_stop_vmm,
106 #else
107 NULL,
108 NULL,
109 #endif
110 x86_64_ipi_wbinvd,
111 };
112
113 void
x86_64_ipi_nop(struct cpu_info * ci)114 x86_64_ipi_nop(struct cpu_info *ci)
115 {
116 }
117
118 void
x86_64_ipi_halt(struct cpu_info * ci)119 x86_64_ipi_halt(struct cpu_info *ci)
120 {
121 SCHED_ASSERT_UNLOCKED();
122 KERNEL_ASSERT_UNLOCKED();
123
124 intr_disable();
125 lapic_disable();
126 wbinvd();
127 atomic_clearbits_int(&ci->ci_flags, CPUF_RUNNING);
128 wbinvd();
129
130 for(;;) {
131 if (cpu_suspend_cycle_fcn)
132 cpu_suspend_cycle_fcn();
133 else
134 __asm volatile("hlt");
135 }
136 }
137
138 #ifdef MTRR
139 void
x86_64_ipi_reload_mtrr(struct cpu_info * ci)140 x86_64_ipi_reload_mtrr(struct cpu_info *ci)
141 {
142 if (mem_range_softc.mr_op != NULL)
143 mem_range_softc.mr_op->reload(&mem_range_softc);
144 }
145 #endif
146
147 #if NVMM > 0
148 void
x86_64_ipi_vmclear_vmm(struct cpu_info * ci)149 x86_64_ipi_vmclear_vmm(struct cpu_info *ci)
150 {
151 vmclear_on_cpu(ci);
152 }
153
154 void
x86_64_ipi_start_vmm(struct cpu_info * ci)155 x86_64_ipi_start_vmm(struct cpu_info *ci)
156 {
157 start_vmm_on_cpu(ci);
158 }
159
160 void
x86_64_ipi_stop_vmm(struct cpu_info * ci)161 x86_64_ipi_stop_vmm(struct cpu_info *ci)
162 {
163 stop_vmm_on_cpu(ci);
164 }
165 #endif /* NVMM > 0 */
166
167 void
x86_64_ipi_wbinvd(struct cpu_info * ci)168 x86_64_ipi_wbinvd(struct cpu_info *ci)
169 {
170 wbinvd();
171 }
172