1 /*
2  * Copyright (c) 2024 Intel Corporation.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #include <zephyr/kernel.h>
7 #include <zephyr/irq_offload.h>
8 #include <kernel_arch_data.h>
9 #include <x86_mmu.h>
10 #include <zephyr/init.h>
11 
12 #define NR_IRQ_VECTORS (IV_NR_VECTORS - IV_IRQS)  /* # vectors free for IRQs */
13 
14 extern void (*x86_irq_funcs[NR_IRQ_VECTORS])(const void *arg);
15 extern const void *x86_irq_args[NR_IRQ_VECTORS];
16 
17 
arch_smp_init(void)18 int arch_smp_init(void)
19 {
20 	/*
21 	 * z_sched_ipi() doesn't have the same signature as a typical ISR, so
22 	 * we fudge it with a cast. the argument is ignored, no harm done.
23 	 */
24 
25 	x86_irq_funcs[CONFIG_SCHED_IPI_VECTOR - IV_IRQS] =
26 		(void *) z_sched_ipi;
27 
28 	/* TLB shootdown handling */
29 	x86_irq_funcs[CONFIG_TLB_IPI_VECTOR - IV_IRQS] = z_x86_tlb_ipi;
30 	return 0;
31 }
32 
33 /*
34  * it is not clear exactly how/where/why to abstract this, as it
35  * assumes the use of a local APIC (but there's no other mechanism).
36  */
arch_sched_broadcast_ipi(void)37 void arch_sched_broadcast_ipi(void)
38 {
39 	z_loapic_ipi(0, LOAPIC_ICR_IPI_OTHERS, CONFIG_SCHED_IPI_VECTOR);
40 }
41