1 /*
2  * Copyright (c) 2015 Intel corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file IRQ offload - x86 implementation
9  */
10 
11 #include <zephyr/kernel.h>
12 #include <zephyr/irq_offload.h>
13 
14 extern void (*_irq_sw_handler)(void);
15 NANO_CPU_INT_REGISTER(_irq_sw_handler, NANO_SOFT_IRQ,
16 		      CONFIG_IRQ_OFFLOAD_VECTOR / 16,
17 		      CONFIG_IRQ_OFFLOAD_VECTOR, 0);
18 
19 __pinned_bss
20 static irq_offload_routine_t offload_routine;
21 
22 __pinned_bss
23 static const void *offload_param;
24 
25 /* Called by asm stub */
26 __pinned_func
z_irq_do_offload(void)27 void z_irq_do_offload(void)
28 {
29 	offload_routine(offload_param);
30 }
31 
32 __pinned_func
arch_irq_offload(irq_offload_routine_t routine,const void * parameter)33 void arch_irq_offload(irq_offload_routine_t routine, const void *parameter)
34 {
35 	unsigned int key;
36 
37 	/*
38 	 * Lock interrupts here to prevent any concurrency issues with
39 	 * the two globals
40 	 */
41 	key = irq_lock();
42 	offload_routine = routine;
43 	offload_param = parameter;
44 
45 	__asm__ volatile("int %[vector]" : :
46 			 [vector] "i" (CONFIG_IRQ_OFFLOAD_VECTOR));
47 
48 	irq_unlock(key);
49 }
50 
arch_irq_offload_init(void)51 void arch_irq_offload_init(void)
52 {
53 }
54