2 * Copyright (c) 1989, 1990 William F. Jolitz.
3 * Copyright (c) 1990 The Regents of the University of California.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 4. Neither the name of the University nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * from: vector.s, 386BSD 0.1 unknown origin
35 * Interrupt entry points for external interrupts triggered by I/O APICs
36 * as well as IPI handlers.
39 #include <machine/asmacros.h>
40 #include <machine/apicreg.h>
41 #include <machine/smptests.h>
46 * Macros to create and destroy a trap frame.
49 pushl $0 ; /* dummy error code */ \
50 pushl $0 ; /* dummy trap type */ \
51 pushal ; /* 8 ints */ \
52 pushl %ds ; /* save data and extra segments ... */ \
64 * I/O Interrupt Entry Point. Rather than having one entry point for
65 * each interrupt source, we use one entry point for each 32-bit word
66 * in the ISR. The handler determines the highest bit set in the ISR,
67 * translates that into a vector, and passes the vector to the
68 * lapic_handle_intr() function.
70 #define ISR_VEC(index, vec_name) \
75 movl $KDSEL, %eax ; /* reload with kernel's data segment */ \
78 movl $KPSEL, %eax ; /* reload with per-CPU data segment */ \
80 FAKE_MCOUNT(TF_EIP(%esp)) ; \
81 movl lapic, %edx ; /* pointer to local APIC */ \
82 movl LA_ISR + 16 * (index)(%edx), %eax ; /* load ISR */ \
83 bsrl %eax, %eax ; /* index of highset set bit in ISR */ \
85 addl $(32 * index),%eax ; \
87 pushl %eax ; /* pass the IRQ */ \
88 call lapic_handle_intr ; \
89 addl $4, %esp ; /* discard parameter */ \
92 2: movl $-1, %eax ; /* send a vector of -1 */ \
96 * Handle "spurious INTerrupts".
98 * This is different than the "spurious INTerrupt" generated by an
99 * 8259 PIC for missing INTs. See the APIC documentation for details.
100 * This routine should NOT do an 'EOI' cycle.
106 /* No EOI cycle used here */
110 ISR_VEC(1, apic_isr1)
111 ISR_VEC(2, apic_isr2)
112 ISR_VEC(3, apic_isr3)
113 ISR_VEC(4, apic_isr4)
114 ISR_VEC(5, apic_isr5)
115 ISR_VEC(6, apic_isr6)
116 ISR_VEC(7, apic_isr7)
119 * Local APIC periodic timer handler.
125 movl $KDSEL, %eax /* reload with kernel's data segment */
132 movl $0, LA_EOI(%edx) /* End Of Interrupt to APIC */
134 FAKE_MCOUNT(TF_EIP(%esp))
136 pushl $0 /* XXX convert trapframe to clockframe */
137 call lapic_handle_timer
138 addl $4, %esp /* XXX convert clockframe to trapframe */
144 * Global address space TLB shootdown.
151 movl $KDSEL, %eax /* Kernel data selector */
154 #if defined(COUNT_XINVLTLB_HITS) || defined(COUNT_IPIS)
156 movl $KPSEL, %eax /* Private space selector */
158 movl PCPU(CPUID), %eax
160 #ifdef COUNT_XINVLTLB_HITS
161 incl xhits_gbl(,%eax,4)
164 movl ipi_invltlb_counts(,%eax,4),%eax
169 movl %cr3, %eax /* invalidate the TLB */
173 movl $0, LA_EOI(%eax) /* End Of Interrupt to APIC */
183 * Single page TLB shootdown
190 movl $KDSEL, %eax /* Kernel data selector */
193 #if defined(COUNT_XINVLTLB_HITS) || defined(COUNT_IPIS)
195 movl $KPSEL, %eax /* Private space selector */
197 movl PCPU(CPUID), %eax
199 #ifdef COUNT_XINVLTLB_HITS
200 incl xhits_pg(,%eax,4)
203 movl ipi_invlpg_counts(,%eax,4),%eax
208 movl smp_tlb_addr1, %eax
209 invlpg (%eax) /* invalidate single page */
212 movl $0, LA_EOI(%eax) /* End Of Interrupt to APIC */
222 * Page range TLB shootdown.
230 movl $KDSEL, %eax /* Kernel data selector */
233 #if defined(COUNT_XINVLTLB_HITS) || defined(COUNT_IPIS)
235 movl $KPSEL, %eax /* Private space selector */
237 movl PCPU(CPUID), %eax
239 #ifdef COUNT_XINVLTLB_HITS
240 incl xhits_rng(,%eax,4)
243 movl ipi_invlrng_counts(,%eax,4),%eax
248 movl smp_tlb_addr1, %edx
249 movl smp_tlb_addr2, %eax
250 1: invlpg (%edx) /* invalidate single page */
251 addl $PAGE_SIZE, %edx
256 movl $0, LA_EOI(%eax) /* End Of Interrupt to APIC */
274 movl $KDSEL, %eax /* Kernel data selector */
279 movl $KPSEL, %eax /* Private space selector */
281 movl PCPU(CPUID), %eax
283 movl ipi_invlcache_counts(,%eax,4),%eax
290 movl $0, LA_EOI(%eax) /* End Of Interrupt to APIC */
300 * Handler for IPIs sent via the per-cpu IPI bitmap.
305 IDTVEC(ipi_intr_bitmap_handler)
308 movl $KDSEL, %eax /* reload with kernel's data segment */
315 movl $0, LA_EOI(%edx) /* End Of Interrupt to APIC */
317 FAKE_MCOUNT(TF_EIP(%esp))
319 pushl $0 /* XXX convert trapframe to clockframe */
320 call ipi_bitmap_handler
321 addl $4, %esp /* XXX convert clockframe to trapframe */
326 * Executed by a CPU when it receives an Xcpustop IPI from another CPU,
328 * - Signals its receipt.
329 * - Waits for permission to restart.
330 * - Signals its restart.
340 pushl %ds /* save current data segment */
345 movl %eax, %ds /* use KERNEL data segment */
351 movl $0, LA_EOI(%eax) /* End Of Interrupt to APIC */
353 movl PCPU(CPUID), %eax
354 imull $PCB_SIZE, %eax
355 leal CNAME(stoppcbs)(%eax), %eax
357 call CNAME(savectx) /* Save process context */
360 movl PCPU(CPUID), %eax
363 btsl %eax, CNAME(stopped_cpus) /* stopped_cpus |= (1<<id) */
365 btl %eax, CNAME(started_cpus) /* while (!(started_cpus & (1<<id))) */
369 btrl %eax, CNAME(started_cpus) /* started_cpus &= ~(1<<id) */
371 btrl %eax, CNAME(stopped_cpus) /* stopped_cpus &= ~(1<<id) */
376 movl CNAME(cpustop_restartfunc), %eax
379 movl $0, CNAME(cpustop_restartfunc) /* One-shot */
385 popl %ds /* restore previous data segment */
394 * Executed by a CPU when it receives a RENDEZVOUS IPI from another CPU.
396 * - Calls the generic rendezvous action function.
403 movl %eax, %ds /* use KERNEL data segment */
409 movl PCPU(CPUID), %eax
410 movl ipi_rendezvous_counts(,%eax,4), %eax
413 call smp_rendezvous_action
416 movl $0, LA_EOI(%eax) /* End Of Interrupt to APIC */
421 * Clean up when we lose out on the lazy context switch optimization.
422 * ie: when we are about to release a PTD but a cpu is still borrowing it.
428 movl %eax, %ds /* use KERNEL data segment */
434 movl PCPU(CPUID), %eax
435 movl ipi_lazypmap_counts(,%eax,4), %eax
438 call pmap_lazyfix_action
441 movl $0, LA_EOI(%eax) /* End Of Interrupt to APIC */