xref: /linux/arch/powerpc/include/asm/interrupt.h (revision 59dc5bfca0cb6a29db1a50847684eb5c19f8f400)
18d41fc61SNicholas Piggin /* SPDX-License-Identifier: GPL-2.0-or-later */
28d41fc61SNicholas Piggin #ifndef _ASM_POWERPC_INTERRUPT_H
38d41fc61SNicholas Piggin #define _ASM_POWERPC_INTERRUPT_H
48d41fc61SNicholas Piggin 
57153d4bfSXiongwei Song /* BookE/4xx */
67153d4bfSXiongwei Song #define INTERRUPT_CRITICAL_INPUT  0x100
77153d4bfSXiongwei Song 
87153d4bfSXiongwei Song /* BookE */
97153d4bfSXiongwei Song #define INTERRUPT_DEBUG           0xd00
107153d4bfSXiongwei Song #ifdef CONFIG_BOOKE
117153d4bfSXiongwei Song #define INTERRUPT_PERFMON         0x260
127153d4bfSXiongwei Song #define INTERRUPT_DOORBELL        0x280
137153d4bfSXiongwei Song #endif
147153d4bfSXiongwei Song 
157153d4bfSXiongwei Song /* BookS/4xx/8xx */
167153d4bfSXiongwei Song #define INTERRUPT_MACHINE_CHECK   0x200
177153d4bfSXiongwei Song 
187153d4bfSXiongwei Song /* BookS/8xx */
197153d4bfSXiongwei Song #define INTERRUPT_SYSTEM_RESET    0x100
207153d4bfSXiongwei Song 
217153d4bfSXiongwei Song /* BookS */
227153d4bfSXiongwei Song #define INTERRUPT_DATA_SEGMENT    0x380
237153d4bfSXiongwei Song #define INTERRUPT_INST_SEGMENT    0x480
247153d4bfSXiongwei Song #define INTERRUPT_TRACE           0xd00
257153d4bfSXiongwei Song #define INTERRUPT_H_DATA_STORAGE  0xe00
26e5223311SChristophe Leroy #define INTERRUPT_HMI			0xe60
277153d4bfSXiongwei Song #define INTERRUPT_H_FAC_UNAVAIL   0xf80
287153d4bfSXiongwei Song #ifdef CONFIG_PPC_BOOK3S
297153d4bfSXiongwei Song #define INTERRUPT_DOORBELL        0xa00
307153d4bfSXiongwei Song #define INTERRUPT_PERFMON         0xf00
317fab6397SChristophe Leroy #define INTERRUPT_ALTIVEC_UNAVAIL	0xf20
327153d4bfSXiongwei Song #endif
337153d4bfSXiongwei Song 
347153d4bfSXiongwei Song /* BookE/BookS/4xx/8xx */
357153d4bfSXiongwei Song #define INTERRUPT_DATA_STORAGE    0x300
367153d4bfSXiongwei Song #define INTERRUPT_INST_STORAGE    0x400
370f5eb28aSChristophe Leroy #define INTERRUPT_EXTERNAL		0x500
387153d4bfSXiongwei Song #define INTERRUPT_ALIGNMENT       0x600
397153d4bfSXiongwei Song #define INTERRUPT_PROGRAM         0x700
407153d4bfSXiongwei Song #define INTERRUPT_SYSCALL         0xc00
410f5eb28aSChristophe Leroy #define INTERRUPT_TRACE			0xd00
427153d4bfSXiongwei Song 
437153d4bfSXiongwei Song /* BookE/BookS/44x */
447153d4bfSXiongwei Song #define INTERRUPT_FP_UNAVAIL      0x800
457153d4bfSXiongwei Song 
467153d4bfSXiongwei Song /* BookE/BookS/44x/8xx */
477153d4bfSXiongwei Song #define INTERRUPT_DECREMENTER     0x900
487153d4bfSXiongwei Song 
497153d4bfSXiongwei Song #ifndef INTERRUPT_PERFMON
507153d4bfSXiongwei Song #define INTERRUPT_PERFMON         0x0
517153d4bfSXiongwei Song #endif
527153d4bfSXiongwei Song 
530f5eb28aSChristophe Leroy /* 8xx */
540f5eb28aSChristophe Leroy #define INTERRUPT_SOFT_EMU_8xx		0x1000
550f5eb28aSChristophe Leroy #define INTERRUPT_INST_TLB_MISS_8xx	0x1100
560f5eb28aSChristophe Leroy #define INTERRUPT_DATA_TLB_MISS_8xx	0x1200
570f5eb28aSChristophe Leroy #define INTERRUPT_INST_TLB_ERROR_8xx	0x1300
580f5eb28aSChristophe Leroy #define INTERRUPT_DATA_TLB_ERROR_8xx	0x1400
590f5eb28aSChristophe Leroy #define INTERRUPT_DATA_BREAKPOINT_8xx	0x1c00
600f5eb28aSChristophe Leroy #define INTERRUPT_INST_BREAKPOINT_8xx	0x1d00
610f5eb28aSChristophe Leroy 
627fab6397SChristophe Leroy /* 603 */
637fab6397SChristophe Leroy #define INTERRUPT_INST_TLB_MISS_603		0x1000
647fab6397SChristophe Leroy #define INTERRUPT_DATA_LOAD_TLB_MISS_603	0x1100
657fab6397SChristophe Leroy #define INTERRUPT_DATA_STORE_TLB_MISS_603	0x1200
667fab6397SChristophe Leroy 
670f5eb28aSChristophe Leroy #ifndef __ASSEMBLY__
680f5eb28aSChristophe Leroy 
690f5eb28aSChristophe Leroy #include <linux/context_tracking.h>
700f5eb28aSChristophe Leroy #include <linux/hardirq.h>
710f5eb28aSChristophe Leroy #include <asm/cputime.h>
720f5eb28aSChristophe Leroy #include <asm/ftrace.h>
730f5eb28aSChristophe Leroy #include <asm/kprobes.h>
740f5eb28aSChristophe Leroy #include <asm/runlatch.h>
750f5eb28aSChristophe Leroy 
76*59dc5bfcSNicholas Piggin #ifdef CONFIG_PPC_BOOK3S_64
77*59dc5bfcSNicholas Piggin static inline void srr_regs_clobbered(void)
78*59dc5bfcSNicholas Piggin {
79*59dc5bfcSNicholas Piggin 	local_paca->srr_valid = 0;
80*59dc5bfcSNicholas Piggin 	local_paca->hsrr_valid = 0;
81*59dc5bfcSNicholas Piggin }
82*59dc5bfcSNicholas Piggin #else
83*59dc5bfcSNicholas Piggin static inline void srr_regs_clobbered(void)
84*59dc5bfcSNicholas Piggin {
85*59dc5bfcSNicholas Piggin }
86*59dc5bfcSNicholas Piggin #endif
87*59dc5bfcSNicholas Piggin 
8898db179aSNicholas Piggin static inline void nap_adjust_return(struct pt_regs *regs)
8998db179aSNicholas Piggin {
9098db179aSNicholas Piggin #ifdef CONFIG_PPC_970_NAP
9198db179aSNicholas Piggin 	if (unlikely(test_thread_local_flags(_TLF_NAPPING))) {
9298db179aSNicholas Piggin 		/* Can avoid a test-and-clear because NMIs do not call this */
9398db179aSNicholas Piggin 		clear_thread_local_flags(_TLF_NAPPING);
94*59dc5bfcSNicholas Piggin 		regs_set_return_ip(regs, (unsigned long)power4_idle_nap_return);
9598db179aSNicholas Piggin 	}
9698db179aSNicholas Piggin #endif
9798db179aSNicholas Piggin }
9898db179aSNicholas Piggin 
9925b7e6bbSNicholas Piggin struct interrupt_state {
10025b7e6bbSNicholas Piggin };
10125b7e6bbSNicholas Piggin 
102d524dda7SChristophe Leroy static inline void booke_restore_dbcr0(void)
103d524dda7SChristophe Leroy {
104d524dda7SChristophe Leroy #ifdef CONFIG_PPC_ADV_DEBUG_REGS
105d524dda7SChristophe Leroy 	unsigned long dbcr0 = current->thread.debug.dbcr0;
106d524dda7SChristophe Leroy 
107d524dda7SChristophe Leroy 	if (IS_ENABLED(CONFIG_PPC32) && unlikely(dbcr0 & DBCR0_IDM)) {
108d524dda7SChristophe Leroy 		mtspr(SPRN_DBSR, -1);
109d524dda7SChristophe Leroy 		mtspr(SPRN_DBCR0, global_dbcr0[smp_processor_id()]);
110d524dda7SChristophe Leroy 	}
111d524dda7SChristophe Leroy #endif
112d524dda7SChristophe Leroy }
113d524dda7SChristophe Leroy 
11425b7e6bbSNicholas Piggin static inline void interrupt_enter_prepare(struct pt_regs *regs, struct interrupt_state *state)
11525b7e6bbSNicholas Piggin {
116be39e105SChristophe Leroy #ifdef CONFIG_PPC32
117be39e105SChristophe Leroy 	if (!arch_irq_disabled_regs(regs))
118be39e105SChristophe Leroy 		trace_hardirqs_off();
119f93d866eSChristophe Leroy 
120b5efec00SChristophe Leroy 	if (user_mode(regs)) {
121b5efec00SChristophe Leroy 		kuep_lock();
122f93d866eSChristophe Leroy 		account_cpu_user_entry();
123c1672883SChristophe Leroy 	} else {
124c1672883SChristophe Leroy 		kuap_save_and_lock(regs);
125b5efec00SChristophe Leroy 	}
126be39e105SChristophe Leroy #endif
127097157e1SNicholas Piggin 
128097157e1SNicholas Piggin #ifdef CONFIG_PPC64
12975b96950SNicholas Piggin 	if (irq_soft_mask_set_return(IRQS_ALL_DISABLED) == IRQS_ENABLED)
13075b96950SNicholas Piggin 		trace_hardirqs_off();
13175b96950SNicholas Piggin 	local_paca->irq_happened |= PACA_IRQ_HARD_DIS;
13275b96950SNicholas Piggin 
133f821bc97SNicholas Piggin 	if (user_mode(regs)) {
134f821bc97SNicholas Piggin 		CT_WARN_ON(ct_state() != CONTEXT_USER);
135f821bc97SNicholas Piggin 		user_exit_irqoff();
13656acfdd8SNicholas Piggin 
13756acfdd8SNicholas Piggin 		account_cpu_user_entry();
13856acfdd8SNicholas Piggin 		account_stolen_time();
139f821bc97SNicholas Piggin 	} else {
140f821bc97SNicholas Piggin 		/*
141f821bc97SNicholas Piggin 		 * CT_WARN_ON comes here via program_check_exception,
142f821bc97SNicholas Piggin 		 * so avoid recursion.
143f821bc97SNicholas Piggin 		 */
1447153d4bfSXiongwei Song 		if (TRAP(regs) != INTERRUPT_PROGRAM)
145f821bc97SNicholas Piggin 			CT_WARN_ON(ct_state() != CONTEXT_KERNEL);
146f821bc97SNicholas Piggin 	}
147f821bc97SNicholas Piggin #endif
14875b96950SNicholas Piggin 
14979f4bb17SChristophe Leroy 	booke_restore_dbcr0();
15025b7e6bbSNicholas Piggin }
15125b7e6bbSNicholas Piggin 
15225b7e6bbSNicholas Piggin /*
15325b7e6bbSNicholas Piggin  * Care should be taken to note that interrupt_exit_prepare and
15425b7e6bbSNicholas Piggin  * interrupt_async_exit_prepare do not necessarily return immediately to
15525b7e6bbSNicholas Piggin  * regs context (e.g., if regs is usermode, we don't necessarily return to
15625b7e6bbSNicholas Piggin  * user mode). Other interrupts might be taken between here and return,
15725b7e6bbSNicholas Piggin  * context switch / preemption may occur in the exit path after this, or a
15825b7e6bbSNicholas Piggin  * signal may be delivered, etc.
15925b7e6bbSNicholas Piggin  *
16025b7e6bbSNicholas Piggin  * The real interrupt exit code is platform specific, e.g.,
16125b7e6bbSNicholas Piggin  * interrupt_exit_user_prepare / interrupt_exit_kernel_prepare for 64s.
16225b7e6bbSNicholas Piggin  *
16325b7e6bbSNicholas Piggin  * However interrupt_nmi_exit_prepare does return directly to regs, because
16425b7e6bbSNicholas Piggin  * NMIs do not do "exit work" or replay soft-masked interrupts.
16525b7e6bbSNicholas Piggin  */
16625b7e6bbSNicholas Piggin static inline void interrupt_exit_prepare(struct pt_regs *regs, struct interrupt_state *state)
16725b7e6bbSNicholas Piggin {
16825b7e6bbSNicholas Piggin }
16925b7e6bbSNicholas Piggin 
17025b7e6bbSNicholas Piggin static inline void interrupt_async_enter_prepare(struct pt_regs *regs, struct interrupt_state *state)
17125b7e6bbSNicholas Piggin {
17286dbb394SNicholas Piggin #ifdef CONFIG_PPC_BOOK3S_64
17386dbb394SNicholas Piggin 	if (cpu_has_feature(CPU_FTR_CTRL) &&
17486dbb394SNicholas Piggin 	    !test_thread_local_flags(_TLF_RUNLATCH))
17586dbb394SNicholas Piggin 		__ppc64_runlatch_on();
17686dbb394SNicholas Piggin #endif
17786dbb394SNicholas Piggin 
1786fdb0f41SNicholas Piggin 	interrupt_enter_prepare(regs, state);
1791b1b6a6fSNicholas Piggin 	irq_enter();
18025b7e6bbSNicholas Piggin }
18125b7e6bbSNicholas Piggin 
18225b7e6bbSNicholas Piggin static inline void interrupt_async_exit_prepare(struct pt_regs *regs, struct interrupt_state *state)
18325b7e6bbSNicholas Piggin {
18498db179aSNicholas Piggin 	/*
18598db179aSNicholas Piggin 	 * Adjust at exit so the main handler sees the true NIA. This must
18698db179aSNicholas Piggin 	 * come before irq_exit() because irq_exit can enable interrupts, and
18798db179aSNicholas Piggin 	 * if another interrupt is taken before nap_adjust_return has run
18898db179aSNicholas Piggin 	 * here, then that interrupt would return directly to idle nap return.
18998db179aSNicholas Piggin 	 */
19098db179aSNicholas Piggin 	nap_adjust_return(regs);
19198db179aSNicholas Piggin 
1921b1b6a6fSNicholas Piggin 	irq_exit();
1936fdb0f41SNicholas Piggin 	interrupt_exit_prepare(regs, state);
19425b7e6bbSNicholas Piggin }
19525b7e6bbSNicholas Piggin 
19625b7e6bbSNicholas Piggin struct interrupt_nmi_state {
197118178e6SNicholas Piggin #ifdef CONFIG_PPC64
1986ecbb582SNicholas Piggin 	u8 irq_soft_mask;
1996ecbb582SNicholas Piggin 	u8 irq_happened;
200118178e6SNicholas Piggin 	u8 ftrace_enabled;
201118178e6SNicholas Piggin #endif
20225b7e6bbSNicholas Piggin };
20325b7e6bbSNicholas Piggin 
2043db8aa10SNicholas Piggin static inline bool nmi_disables_ftrace(struct pt_regs *regs)
2053db8aa10SNicholas Piggin {
2063db8aa10SNicholas Piggin 	/* Allow DEC and PMI to be traced when they are soft-NMI */
2073db8aa10SNicholas Piggin 	if (IS_ENABLED(CONFIG_PPC_BOOK3S_64)) {
2087153d4bfSXiongwei Song 		if (TRAP(regs) == INTERRUPT_DECREMENTER)
2093db8aa10SNicholas Piggin 		       return false;
2107153d4bfSXiongwei Song 		if (TRAP(regs) == INTERRUPT_PERFMON)
2113db8aa10SNicholas Piggin 		       return false;
2123db8aa10SNicholas Piggin 	}
2133db8aa10SNicholas Piggin 	if (IS_ENABLED(CONFIG_PPC_BOOK3E)) {
2147153d4bfSXiongwei Song 		if (TRAP(regs) == INTERRUPT_PERFMON)
2153db8aa10SNicholas Piggin 			return false;
2163db8aa10SNicholas Piggin 	}
2173db8aa10SNicholas Piggin 
2183db8aa10SNicholas Piggin 	return true;
2193db8aa10SNicholas Piggin }
2203db8aa10SNicholas Piggin 
22125b7e6bbSNicholas Piggin static inline void interrupt_nmi_enter_prepare(struct pt_regs *regs, struct interrupt_nmi_state *state)
22225b7e6bbSNicholas Piggin {
223118178e6SNicholas Piggin #ifdef CONFIG_PPC64
2246ecbb582SNicholas Piggin 	state->irq_soft_mask = local_paca->irq_soft_mask;
2256ecbb582SNicholas Piggin 	state->irq_happened = local_paca->irq_happened;
2266ecbb582SNicholas Piggin 
2276ecbb582SNicholas Piggin 	/*
2286ecbb582SNicholas Piggin 	 * Set IRQS_ALL_DISABLED unconditionally so irqs_disabled() does
2296ecbb582SNicholas Piggin 	 * the right thing, and set IRQ_HARD_DIS. We do not want to reconcile
2306ecbb582SNicholas Piggin 	 * because that goes through irq tracing which we don't want in NMI.
2316ecbb582SNicholas Piggin 	 */
2326ecbb582SNicholas Piggin 	local_paca->irq_soft_mask = IRQS_ALL_DISABLED;
2336ecbb582SNicholas Piggin 	local_paca->irq_happened |= PACA_IRQ_HARD_DIS;
2346ecbb582SNicholas Piggin 
2354ec5feecSNicholas Piggin 	if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) && !(regs->msr & MSR_PR) &&
2364ec5feecSNicholas Piggin 				regs->nip < (unsigned long)__end_interrupts) {
2374ec5feecSNicholas Piggin 		// Kernel code running below __end_interrupts is
2384ec5feecSNicholas Piggin 		// implicitly soft-masked.
2394ec5feecSNicholas Piggin 		regs->softe = IRQS_ALL_DISABLED;
2404ec5feecSNicholas Piggin 	}
2414ec5feecSNicholas Piggin 
2426ecbb582SNicholas Piggin 	/* Don't do any per-CPU operations until interrupt state is fixed */
2433db8aa10SNicholas Piggin 
2443db8aa10SNicholas Piggin 	if (nmi_disables_ftrace(regs)) {
245118178e6SNicholas Piggin 		state->ftrace_enabled = this_cpu_get_ftrace_enabled();
246118178e6SNicholas Piggin 		this_cpu_set_ftrace_enabled(0);
247118178e6SNicholas Piggin 	}
248118178e6SNicholas Piggin #endif
249118178e6SNicholas Piggin 
250118178e6SNicholas Piggin 	/*
251118178e6SNicholas Piggin 	 * Do not use nmi_enter() for pseries hash guest taking a real-mode
252118178e6SNicholas Piggin 	 * NMI because not everything it touches is within the RMA limit.
253118178e6SNicholas Piggin 	 */
254118178e6SNicholas Piggin 	if (!IS_ENABLED(CONFIG_PPC_BOOK3S_64) ||
255118178e6SNicholas Piggin 			!firmware_has_feature(FW_FEATURE_LPAR) ||
256118178e6SNicholas Piggin 			radix_enabled() || (mfmsr() & MSR_DR))
257118178e6SNicholas Piggin 		nmi_enter();
25825b7e6bbSNicholas Piggin }
25925b7e6bbSNicholas Piggin 
26025b7e6bbSNicholas Piggin static inline void interrupt_nmi_exit_prepare(struct pt_regs *regs, struct interrupt_nmi_state *state)
26125b7e6bbSNicholas Piggin {
262118178e6SNicholas Piggin 	if (!IS_ENABLED(CONFIG_PPC_BOOK3S_64) ||
263118178e6SNicholas Piggin 			!firmware_has_feature(FW_FEATURE_LPAR) ||
264118178e6SNicholas Piggin 			radix_enabled() || (mfmsr() & MSR_DR))
265118178e6SNicholas Piggin 		nmi_exit();
266118178e6SNicholas Piggin 
26798db179aSNicholas Piggin 	/*
26898db179aSNicholas Piggin 	 * nmi does not call nap_adjust_return because nmi should not create
26998db179aSNicholas Piggin 	 * new work to do (must use irq_work for that).
27098db179aSNicholas Piggin 	 */
27198db179aSNicholas Piggin 
272118178e6SNicholas Piggin #ifdef CONFIG_PPC64
2733db8aa10SNicholas Piggin 	if (nmi_disables_ftrace(regs))
274118178e6SNicholas Piggin 		this_cpu_set_ftrace_enabled(state->ftrace_enabled);
2756ecbb582SNicholas Piggin 
2766ecbb582SNicholas Piggin 	/* Check we didn't change the pending interrupt mask. */
2776ecbb582SNicholas Piggin 	WARN_ON_ONCE((state->irq_happened | PACA_IRQ_HARD_DIS) != local_paca->irq_happened);
2786ecbb582SNicholas Piggin 	local_paca->irq_happened = state->irq_happened;
2796ecbb582SNicholas Piggin 	local_paca->irq_soft_mask = state->irq_soft_mask;
2806ecbb582SNicholas Piggin #endif
28125b7e6bbSNicholas Piggin }
28225b7e6bbSNicholas Piggin 
283e4bb64c7SNicholas Piggin /*
284e4bb64c7SNicholas Piggin  * Don't use noinstr here like x86, but rather add NOKPROBE_SYMBOL to each
285e4bb64c7SNicholas Piggin  * function definition. The reason for this is the noinstr section is placed
286e4bb64c7SNicholas Piggin  * after the main text section, i.e., very far away from the interrupt entry
287e4bb64c7SNicholas Piggin  * asm. That creates problems with fitting linker stubs when building large
288e4bb64c7SNicholas Piggin  * kernels.
289e4bb64c7SNicholas Piggin  */
290e4bb64c7SNicholas Piggin #define interrupt_handler __visible noinline notrace __no_kcsan __no_sanitize_address
291e4bb64c7SNicholas Piggin 
2928d41fc61SNicholas Piggin /**
2938d41fc61SNicholas Piggin  * DECLARE_INTERRUPT_HANDLER_RAW - Declare raw interrupt handler function
2948d41fc61SNicholas Piggin  * @func:	Function name of the entry point
2958d41fc61SNicholas Piggin  * @returns:	Returns a value back to asm caller
2968d41fc61SNicholas Piggin  */
2978d41fc61SNicholas Piggin #define DECLARE_INTERRUPT_HANDLER_RAW(func)				\
2988d41fc61SNicholas Piggin 	__visible long func(struct pt_regs *regs)
2998d41fc61SNicholas Piggin 
3008d41fc61SNicholas Piggin /**
3018d41fc61SNicholas Piggin  * DEFINE_INTERRUPT_HANDLER_RAW - Define raw interrupt handler function
3028d41fc61SNicholas Piggin  * @func:	Function name of the entry point
3038d41fc61SNicholas Piggin  * @returns:	Returns a value back to asm caller
3048d41fc61SNicholas Piggin  *
3058d41fc61SNicholas Piggin  * @func is called from ASM entry code.
3068d41fc61SNicholas Piggin  *
3078d41fc61SNicholas Piggin  * This is a plain function which does no tracing, reconciling, etc.
3088d41fc61SNicholas Piggin  * The macro is written so it acts as function definition. Append the
3098d41fc61SNicholas Piggin  * body with a pair of curly brackets.
3108d41fc61SNicholas Piggin  *
3118d41fc61SNicholas Piggin  * raw interrupt handlers must not enable or disable interrupts, or
3128d41fc61SNicholas Piggin  * schedule, tracing and instrumentation (ftrace, lockdep, etc) would
3138d41fc61SNicholas Piggin  * not be advisable either, although may be possible in a pinch, the
3148d41fc61SNicholas Piggin  * trace will look odd at least.
3158d41fc61SNicholas Piggin  *
3168d41fc61SNicholas Piggin  * A raw handler may call one of the other interrupt handler functions
3178d41fc61SNicholas Piggin  * to be converted into that interrupt context without these restrictions.
3188d41fc61SNicholas Piggin  *
3198d41fc61SNicholas Piggin  * On PPC64, _RAW handlers may return with fast_interrupt_return.
3208d41fc61SNicholas Piggin  *
3218d41fc61SNicholas Piggin  * Specific handlers may have additional restrictions.
3228d41fc61SNicholas Piggin  */
3238d41fc61SNicholas Piggin #define DEFINE_INTERRUPT_HANDLER_RAW(func)				\
3248d41fc61SNicholas Piggin static __always_inline long ____##func(struct pt_regs *regs);		\
3258d41fc61SNicholas Piggin 									\
326e4bb64c7SNicholas Piggin interrupt_handler long func(struct pt_regs *regs)			\
3278d41fc61SNicholas Piggin {									\
3288d41fc61SNicholas Piggin 	long ret;							\
3298d41fc61SNicholas Piggin 									\
3308d41fc61SNicholas Piggin 	ret = ____##func (regs);					\
3318d41fc61SNicholas Piggin 									\
3328d41fc61SNicholas Piggin 	return ret;							\
3338d41fc61SNicholas Piggin }									\
334e4bb64c7SNicholas Piggin NOKPROBE_SYMBOL(func);							\
3358d41fc61SNicholas Piggin 									\
3368d41fc61SNicholas Piggin static __always_inline long ____##func(struct pt_regs *regs)
3378d41fc61SNicholas Piggin 
3388d41fc61SNicholas Piggin /**
3398d41fc61SNicholas Piggin  * DECLARE_INTERRUPT_HANDLER - Declare synchronous interrupt handler function
3408d41fc61SNicholas Piggin  * @func:	Function name of the entry point
3418d41fc61SNicholas Piggin  */
3428d41fc61SNicholas Piggin #define DECLARE_INTERRUPT_HANDLER(func)					\
3438d41fc61SNicholas Piggin 	__visible void func(struct pt_regs *regs)
3448d41fc61SNicholas Piggin 
3458d41fc61SNicholas Piggin /**
3468d41fc61SNicholas Piggin  * DEFINE_INTERRUPT_HANDLER - Define synchronous interrupt handler function
3478d41fc61SNicholas Piggin  * @func:	Function name of the entry point
3488d41fc61SNicholas Piggin  *
3498d41fc61SNicholas Piggin  * @func is called from ASM entry code.
3508d41fc61SNicholas Piggin  *
3518d41fc61SNicholas Piggin  * The macro is written so it acts as function definition. Append the
3528d41fc61SNicholas Piggin  * body with a pair of curly brackets.
3538d41fc61SNicholas Piggin  */
3548d41fc61SNicholas Piggin #define DEFINE_INTERRUPT_HANDLER(func)					\
3558d41fc61SNicholas Piggin static __always_inline void ____##func(struct pt_regs *regs);		\
3568d41fc61SNicholas Piggin 									\
357e4bb64c7SNicholas Piggin interrupt_handler void func(struct pt_regs *regs)			\
3588d41fc61SNicholas Piggin {									\
35925b7e6bbSNicholas Piggin 	struct interrupt_state state;					\
36025b7e6bbSNicholas Piggin 									\
36125b7e6bbSNicholas Piggin 	interrupt_enter_prepare(regs, &state);				\
36225b7e6bbSNicholas Piggin 									\
3638d41fc61SNicholas Piggin 	____##func (regs);						\
36425b7e6bbSNicholas Piggin 									\
36525b7e6bbSNicholas Piggin 	interrupt_exit_prepare(regs, &state);				\
3668d41fc61SNicholas Piggin }									\
367e4bb64c7SNicholas Piggin NOKPROBE_SYMBOL(func);							\
3688d41fc61SNicholas Piggin 									\
3698d41fc61SNicholas Piggin static __always_inline void ____##func(struct pt_regs *regs)
3708d41fc61SNicholas Piggin 
3718d41fc61SNicholas Piggin /**
3728d41fc61SNicholas Piggin  * DECLARE_INTERRUPT_HANDLER_RET - Declare synchronous interrupt handler function
3738d41fc61SNicholas Piggin  * @func:	Function name of the entry point
3748d41fc61SNicholas Piggin  * @returns:	Returns a value back to asm caller
3758d41fc61SNicholas Piggin  */
3768d41fc61SNicholas Piggin #define DECLARE_INTERRUPT_HANDLER_RET(func)				\
3778d41fc61SNicholas Piggin 	__visible long func(struct pt_regs *regs)
3788d41fc61SNicholas Piggin 
3798d41fc61SNicholas Piggin /**
3808d41fc61SNicholas Piggin  * DEFINE_INTERRUPT_HANDLER_RET - Define synchronous interrupt handler function
3818d41fc61SNicholas Piggin  * @func:	Function name of the entry point
3828d41fc61SNicholas Piggin  * @returns:	Returns a value back to asm caller
3838d41fc61SNicholas Piggin  *
3848d41fc61SNicholas Piggin  * @func is called from ASM entry code.
3858d41fc61SNicholas Piggin  *
3868d41fc61SNicholas Piggin  * The macro is written so it acts as function definition. Append the
3878d41fc61SNicholas Piggin  * body with a pair of curly brackets.
3888d41fc61SNicholas Piggin  */
3898d41fc61SNicholas Piggin #define DEFINE_INTERRUPT_HANDLER_RET(func)				\
3908d41fc61SNicholas Piggin static __always_inline long ____##func(struct pt_regs *regs);		\
3918d41fc61SNicholas Piggin 									\
392e4bb64c7SNicholas Piggin interrupt_handler long func(struct pt_regs *regs)			\
3938d41fc61SNicholas Piggin {									\
39425b7e6bbSNicholas Piggin 	struct interrupt_state state;					\
3958d41fc61SNicholas Piggin 	long ret;							\
3968d41fc61SNicholas Piggin 									\
39725b7e6bbSNicholas Piggin 	interrupt_enter_prepare(regs, &state);				\
39825b7e6bbSNicholas Piggin 									\
3998d41fc61SNicholas Piggin 	ret = ____##func (regs);					\
4008d41fc61SNicholas Piggin 									\
40125b7e6bbSNicholas Piggin 	interrupt_exit_prepare(regs, &state);				\
40225b7e6bbSNicholas Piggin 									\
4038d41fc61SNicholas Piggin 	return ret;							\
4048d41fc61SNicholas Piggin }									\
405e4bb64c7SNicholas Piggin NOKPROBE_SYMBOL(func);							\
4068d41fc61SNicholas Piggin 									\
4078d41fc61SNicholas Piggin static __always_inline long ____##func(struct pt_regs *regs)
4088d41fc61SNicholas Piggin 
4098d41fc61SNicholas Piggin /**
4108d41fc61SNicholas Piggin  * DECLARE_INTERRUPT_HANDLER_ASYNC - Declare asynchronous interrupt handler function
4118d41fc61SNicholas Piggin  * @func:	Function name of the entry point
4128d41fc61SNicholas Piggin  */
4138d41fc61SNicholas Piggin #define DECLARE_INTERRUPT_HANDLER_ASYNC(func)				\
4148d41fc61SNicholas Piggin 	__visible void func(struct pt_regs *regs)
4158d41fc61SNicholas Piggin 
4168d41fc61SNicholas Piggin /**
4178d41fc61SNicholas Piggin  * DEFINE_INTERRUPT_HANDLER_ASYNC - Define asynchronous interrupt handler function
4188d41fc61SNicholas Piggin  * @func:	Function name of the entry point
4198d41fc61SNicholas Piggin  *
4208d41fc61SNicholas Piggin  * @func is called from ASM entry code.
4218d41fc61SNicholas Piggin  *
4228d41fc61SNicholas Piggin  * The macro is written so it acts as function definition. Append the
4238d41fc61SNicholas Piggin  * body with a pair of curly brackets.
4248d41fc61SNicholas Piggin  */
4258d41fc61SNicholas Piggin #define DEFINE_INTERRUPT_HANDLER_ASYNC(func)				\
4268d41fc61SNicholas Piggin static __always_inline void ____##func(struct pt_regs *regs);		\
4278d41fc61SNicholas Piggin 									\
428e4bb64c7SNicholas Piggin interrupt_handler void func(struct pt_regs *regs)			\
4298d41fc61SNicholas Piggin {									\
43025b7e6bbSNicholas Piggin 	struct interrupt_state state;					\
43125b7e6bbSNicholas Piggin 									\
43225b7e6bbSNicholas Piggin 	interrupt_async_enter_prepare(regs, &state);			\
43325b7e6bbSNicholas Piggin 									\
4348d41fc61SNicholas Piggin 	____##func (regs);						\
43525b7e6bbSNicholas Piggin 									\
43625b7e6bbSNicholas Piggin 	interrupt_async_exit_prepare(regs, &state);			\
4378d41fc61SNicholas Piggin }									\
438e4bb64c7SNicholas Piggin NOKPROBE_SYMBOL(func);							\
4398d41fc61SNicholas Piggin 									\
4408d41fc61SNicholas Piggin static __always_inline void ____##func(struct pt_regs *regs)
4418d41fc61SNicholas Piggin 
4428d41fc61SNicholas Piggin /**
4438d41fc61SNicholas Piggin  * DECLARE_INTERRUPT_HANDLER_NMI - Declare NMI interrupt handler function
4448d41fc61SNicholas Piggin  * @func:	Function name of the entry point
4458d41fc61SNicholas Piggin  * @returns:	Returns a value back to asm caller
4468d41fc61SNicholas Piggin  */
4478d41fc61SNicholas Piggin #define DECLARE_INTERRUPT_HANDLER_NMI(func)				\
4488d41fc61SNicholas Piggin 	__visible long func(struct pt_regs *regs)
4498d41fc61SNicholas Piggin 
4508d41fc61SNicholas Piggin /**
4518d41fc61SNicholas Piggin  * DEFINE_INTERRUPT_HANDLER_NMI - Define NMI interrupt handler function
4528d41fc61SNicholas Piggin  * @func:	Function name of the entry point
4538d41fc61SNicholas Piggin  * @returns:	Returns a value back to asm caller
4548d41fc61SNicholas Piggin  *
4558d41fc61SNicholas Piggin  * @func is called from ASM entry code.
4568d41fc61SNicholas Piggin  *
4578d41fc61SNicholas Piggin  * The macro is written so it acts as function definition. Append the
4588d41fc61SNicholas Piggin  * body with a pair of curly brackets.
4598d41fc61SNicholas Piggin  */
4608d41fc61SNicholas Piggin #define DEFINE_INTERRUPT_HANDLER_NMI(func)				\
4618d41fc61SNicholas Piggin static __always_inline long ____##func(struct pt_regs *regs);		\
4628d41fc61SNicholas Piggin 									\
463e4bb64c7SNicholas Piggin interrupt_handler long func(struct pt_regs *regs)			\
4648d41fc61SNicholas Piggin {									\
46525b7e6bbSNicholas Piggin 	struct interrupt_nmi_state state;				\
4668d41fc61SNicholas Piggin 	long ret;							\
4678d41fc61SNicholas Piggin 									\
46825b7e6bbSNicholas Piggin 	interrupt_nmi_enter_prepare(regs, &state);			\
46925b7e6bbSNicholas Piggin 									\
4708d41fc61SNicholas Piggin 	ret = ____##func (regs);					\
4718d41fc61SNicholas Piggin 									\
47225b7e6bbSNicholas Piggin 	interrupt_nmi_exit_prepare(regs, &state);			\
47325b7e6bbSNicholas Piggin 									\
4748d41fc61SNicholas Piggin 	return ret;							\
4758d41fc61SNicholas Piggin }									\
476e4bb64c7SNicholas Piggin NOKPROBE_SYMBOL(func);							\
4778d41fc61SNicholas Piggin 									\
4788d41fc61SNicholas Piggin static __always_inline long ____##func(struct pt_regs *regs)
4798d41fc61SNicholas Piggin 
4803a96570fSNicholas Piggin 
4813a96570fSNicholas Piggin /* Interrupt handlers */
4823a96570fSNicholas Piggin /* kernel/traps.c */
4833a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(system_reset_exception);
4843a96570fSNicholas Piggin #ifdef CONFIG_PPC_BOOK3S_64
4853a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_ASYNC(machine_check_exception);
4863a96570fSNicholas Piggin #else
4873a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(machine_check_exception);
4883a96570fSNicholas Piggin #endif
4893a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(SMIException);
4903a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(handle_hmi_exception);
4913a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(unknown_exception);
4923a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_ASYNC(unknown_async_exception);
4933db8aa10SNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(unknown_nmi_exception);
4943a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(instruction_breakpoint_exception);
4953a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(RunModeException);
4963a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(single_step_exception);
4973a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(program_check_exception);
4983a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(emulation_assist_interrupt);
4993a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(alignment_exception);
5003a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(StackOverflow);
5013a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(stack_overflow_exception);
5023a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(kernel_fp_unavailable_exception);
5033a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(altivec_unavailable_exception);
5043a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(vsx_unavailable_exception);
5053a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(facility_unavailable_exception);
5063a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(fp_unavailable_tm);
5073a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(altivec_unavailable_tm);
5083a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(vsx_unavailable_tm);
5093a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(performance_monitor_exception_nmi);
5103a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_ASYNC(performance_monitor_exception_async);
5113a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_RAW(performance_monitor_exception);
5123a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(DebugException);
5133a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(altivec_assist_exception);
5143a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(CacheLockingException);
5153a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(SPEFloatingPointException);
5163a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(SPEFloatingPointRoundException);
5173db8aa10SNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(WatchdogException);
5183a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(kernel_bad_stack);
5193a96570fSNicholas Piggin 
5203a96570fSNicholas Piggin /* slb.c */
5213a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_RAW(do_slb_fault);
5223a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(do_bad_slb_fault);
5233a96570fSNicholas Piggin 
5243a96570fSNicholas Piggin /* hash_utils.c */
5253a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_RAW(do_hash_fault);
5263a96570fSNicholas Piggin 
5273a96570fSNicholas Piggin /* fault.c */
528c45ba4f4SNicholas Piggin DECLARE_INTERRUPT_HANDLER(do_page_fault);
5293a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(do_bad_page_fault_segv);
5303a96570fSNicholas Piggin 
5313a96570fSNicholas Piggin /* process.c */
5323a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(do_break);
5333a96570fSNicholas Piggin 
5343a96570fSNicholas Piggin /* time.c */
5353a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_ASYNC(timer_interrupt);
5363a96570fSNicholas Piggin 
5373a96570fSNicholas Piggin /* mce.c */
5383a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(machine_check_early);
5393a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(hmi_exception_realmode);
5403a96570fSNicholas Piggin 
5413a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_ASYNC(TAUException);
5423a96570fSNicholas Piggin 
543a58cbed6SChristophe Leroy void __noreturn unrecoverable_exception(struct pt_regs *regs);
5440b736881SChristophe Leroy 
5453a96570fSNicholas Piggin void replay_system_reset(void);
5463a96570fSNicholas Piggin void replay_soft_interrupts(void);
5473a96570fSNicholas Piggin 
548e6f8a6c8SNicholas Piggin static inline void interrupt_cond_local_irq_enable(struct pt_regs *regs)
549e6f8a6c8SNicholas Piggin {
550e6f8a6c8SNicholas Piggin 	if (!arch_irq_disabled_regs(regs))
551e6f8a6c8SNicholas Piggin 		local_irq_enable();
552e6f8a6c8SNicholas Piggin }
553e6f8a6c8SNicholas Piggin 
5540f5eb28aSChristophe Leroy #endif /* __ASSEMBLY__ */
5550f5eb28aSChristophe Leroy 
5568d41fc61SNicholas Piggin #endif /* _ASM_POWERPC_INTERRUPT_H */
557