1 // SPDX-License-Identifier: GPL-2.0-only
3 * Based on arch/arm/kernel/irq.c
5 * Copyright (C) 1992 Linus Torvalds
6 * Modifications for ARM processor Copyright (C) 1995-2000 Russell King.
7 * Support for Dynamic Tick Timer Copyright (C) 2004-2005 Nokia Corporation.
8 * Dynamic Tick Timer written by Tony Lindgren <tony@atomide.com> and
9 * Tuukka Tikkanen <tuukka.tikkanen@elektrobit.com>.
10 * Copyright (C) 2012 ARM Ltd.
13 #include <linux/hardirq.h>
14 #include <linux/init.h>
15 #include <linux/irq.h>
16 #include <linux/irqchip.h>
17 #include <linux/kprobes.h>
18 #include <linux/memory.h>
19 #include <linux/scs.h>
20 #include <linux/seq_file.h>
21 #include <linux/smp.h>
22 #include <linux/vmalloc.h>
23 #include <asm/daifflags.h>
24 #include <asm/exception.h>
26 #include <asm/softirq_stack.h>
27 #include <asm/stacktrace.h>
28 #include <asm/vmap_stack.h>
30 /* Only access this in an NMI enter/exit */
31 DEFINE_PER_CPU(struct nmi_ctx
, nmi_contexts
);
33 DEFINE_PER_CPU(unsigned long *, irq_stack_ptr
);
36 DECLARE_PER_CPU(unsigned long *, irq_shadow_call_stack_ptr
);
38 #ifdef CONFIG_SHADOW_CALL_STACK
39 DEFINE_PER_CPU(unsigned long *, irq_shadow_call_stack_ptr
);
42 static void init_irq_scs(void)
46 if (!scs_is_enabled())
49 for_each_possible_cpu(cpu
)
50 per_cpu(irq_shadow_call_stack_ptr
, cpu
) =
51 scs_alloc(early_cpu_to_node(cpu
));
54 #ifdef CONFIG_VMAP_STACK
55 static void __init
init_irq_stacks(void)
60 for_each_possible_cpu(cpu
) {
61 p
= arch_alloc_vmap_stack(IRQ_STACK_SIZE
, early_cpu_to_node(cpu
));
62 per_cpu(irq_stack_ptr
, cpu
) = p
;
66 /* irq stack only needs to be 16 byte aligned - not IRQ_STACK_SIZE aligned. */
67 DEFINE_PER_CPU_ALIGNED(unsigned long [IRQ_STACK_SIZE
/sizeof(long)], irq_stack
);
69 static void init_irq_stacks(void)
73 for_each_possible_cpu(cpu
)
74 per_cpu(irq_stack_ptr
, cpu
) = per_cpu(irq_stack
, cpu
);
78 #ifndef CONFIG_PREEMPT_RT
79 static void ____do_softirq(struct pt_regs
*regs
)
84 void do_softirq_own_stack(void)
86 call_on_irq_stack(NULL
, ____do_softirq
);
90 static void default_handle_irq(struct pt_regs
*regs
)
92 panic("IRQ taken without a root IRQ handler\n");
95 static void default_handle_fiq(struct pt_regs
*regs
)
97 panic("FIQ taken without a root FIQ handler\n");
100 void (*handle_arch_irq
)(struct pt_regs
*) __ro_after_init
= default_handle_irq
;
101 void (*handle_arch_fiq
)(struct pt_regs
*) __ro_after_init
= default_handle_fiq
;
103 int __init
set_handle_irq(void (*handle_irq
)(struct pt_regs
*))
105 if (handle_arch_irq
!= default_handle_irq
)
108 handle_arch_irq
= handle_irq
;
109 pr_info("Root IRQ handler: %ps\n", handle_irq
);
113 int __init
set_handle_fiq(void (*handle_fiq
)(struct pt_regs
*))
115 if (handle_arch_fiq
!= default_handle_fiq
)
118 handle_arch_fiq
= handle_fiq
;
119 pr_info("Root FIQ handler: %ps\n", handle_fiq
);
123 void __init
init_IRQ(void)
129 if (system_uses_irq_prio_masking()) {
131 * Now that we have a stack for our IRQ handler, set
132 * the PMR/PSR pair to a consistent state.
134 WARN_ON(read_sysreg(daif
) & PSR_A_BIT
);
135 local_daif_restore(DAIF_PROCCTX_NOIRQ
);