1 /*
2 * Copyright (c) 2020 Antony Pavlov <antonynpavlov@gmail.com>
3 *
4 * based on arch/nios2/core/irq_manage.c
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 */
8
9 #include <zephyr/kernel.h>
10 #include <kswap.h>
11 #include <zephyr/logging/log.h>
12 LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL);
13
14
15 uint32_t mips_cp0_status_int_mask;
16
17
z_irq_spurious(const void * unused)18 FUNC_NORETURN void z_irq_spurious(const void *unused)
19 {
20 unsigned long cause;
21
22 ARG_UNUSED(unused);
23 cause = (read_c0_cause() & CAUSE_EXP_MASK) >> CAUSE_EXP_SHIFT;
24
25 LOG_ERR("Spurious interrupt detected! CAUSE: %ld", cause);
26
27 z_mips_fatal_error(K_ERR_SPURIOUS_IRQ, NULL);
28 }
29
arch_irq_enable(unsigned int irq)30 void arch_irq_enable(unsigned int irq)
31 {
32 unsigned int key;
33 uint32_t irq_mask;
34
35 key = irq_lock();
36
37 irq_mask = ST0_IP0 << irq;
38 mips_cp0_status_int_mask |= irq_mask;
39 write_c0_status(read_c0_status() | irq_mask);
40
41 irq_unlock(key);
42 }
43
arch_irq_disable(unsigned int irq)44 void arch_irq_disable(unsigned int irq)
45 {
46 unsigned int key;
47 uint32_t irq_mask;
48
49 key = irq_lock();
50
51 irq_mask = ST0_IP0 << irq;
52 mips_cp0_status_int_mask &= ~irq_mask;
53 write_c0_status(read_c0_status() & ~irq_mask);
54
55 irq_unlock(key);
56 };
57
arch_irq_is_enabled(unsigned int irq)58 int arch_irq_is_enabled(unsigned int irq)
59 {
60 return read_c0_status() & (ST0_IP0 << irq);
61 }
62
z_mips_enter_irq(uint32_t ipending)63 void z_mips_enter_irq(uint32_t ipending)
64 {
65 _current_cpu->nested++;
66
67 #ifdef CONFIG_IRQ_OFFLOAD
68 z_irq_do_offload();
69 #endif
70
71 while (ipending) {
72 int index;
73 struct _isr_table_entry *ite;
74
75 if (IS_ENABLED(CONFIG_TRACING_ISR)) {
76 sys_trace_isr_enter();
77 }
78
79 index = find_lsb_set(ipending) - 1;
80 ipending &= ~BIT(index);
81
82 ite = &_sw_isr_table[index];
83
84 ite->isr(ite->arg);
85
86 if (IS_ENABLED(CONFIG_TRACING_ISR)) {
87 sys_trace_isr_exit();
88 }
89 }
90
91 _current_cpu->nested--;
92
93 if (IS_ENABLED(CONFIG_STACK_SENTINEL)) {
94 z_check_stack_sentinel();
95 }
96 }
97
98 #ifdef CONFIG_DYNAMIC_INTERRUPTS
arch_irq_connect_dynamic(unsigned int irq,unsigned int priority,void (* routine)(const void * parameter),const void * parameter,uint32_t flags)99 int arch_irq_connect_dynamic(unsigned int irq, unsigned int priority,
100 void (*routine)(const void *parameter),
101 const void *parameter, uint32_t flags)
102 {
103 ARG_UNUSED(flags);
104 ARG_UNUSED(priority);
105
106 z_isr_install(irq, routine, parameter);
107 return irq;
108 }
109 #endif /* CONFIG_DYNAMIC_INTERRUPTS */
110