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 769b69d48cSNicholas Piggin #ifdef CONFIG_PPC_BOOK3S_64 77f23699c9SNicholas Piggin extern char __end_soft_masked[]; 78325678fdSNicholas Piggin bool search_kernel_soft_mask_table(unsigned long addr); 79f23699c9SNicholas Piggin unsigned long search_kernel_restart_table(unsigned long addr); 80f23699c9SNicholas Piggin 8113799748SNicholas Piggin DECLARE_STATIC_KEY_FALSE(interrupt_exit_not_reentrant); 8213799748SNicholas Piggin 839b69d48cSNicholas Piggin static inline bool is_implicit_soft_masked(struct pt_regs *regs) 849b69d48cSNicholas Piggin { 859b69d48cSNicholas Piggin if (regs->msr & MSR_PR) 869b69d48cSNicholas Piggin return false; 879b69d48cSNicholas Piggin 889b69d48cSNicholas Piggin if (regs->nip >= (unsigned long)__end_soft_masked) 899b69d48cSNicholas Piggin return false; 909b69d48cSNicholas Piggin 91325678fdSNicholas Piggin return search_kernel_soft_mask_table(regs->nip); 929b69d48cSNicholas Piggin } 939b69d48cSNicholas Piggin 9459dc5bfcSNicholas Piggin static inline void srr_regs_clobbered(void) 9559dc5bfcSNicholas Piggin { 9659dc5bfcSNicholas Piggin local_paca->srr_valid = 0; 9759dc5bfcSNicholas Piggin local_paca->hsrr_valid = 0; 9859dc5bfcSNicholas Piggin } 9959dc5bfcSNicholas Piggin #else 1009b69d48cSNicholas Piggin static inline bool is_implicit_soft_masked(struct pt_regs *regs) 1019b69d48cSNicholas Piggin { 1029b69d48cSNicholas Piggin return false; 1039b69d48cSNicholas Piggin } 1049b69d48cSNicholas Piggin 10559dc5bfcSNicholas Piggin static inline void srr_regs_clobbered(void) 10659dc5bfcSNicholas Piggin { 10759dc5bfcSNicholas Piggin } 10859dc5bfcSNicholas Piggin #endif 10959dc5bfcSNicholas Piggin 11098db179aSNicholas Piggin static inline void nap_adjust_return(struct pt_regs *regs) 11198db179aSNicholas Piggin { 11298db179aSNicholas Piggin #ifdef CONFIG_PPC_970_NAP 11398db179aSNicholas Piggin if (unlikely(test_thread_local_flags(_TLF_NAPPING))) { 11498db179aSNicholas Piggin /* Can avoid a test-and-clear because NMIs do not call this */ 11598db179aSNicholas Piggin clear_thread_local_flags(_TLF_NAPPING); 11659dc5bfcSNicholas Piggin regs_set_return_ip(regs, (unsigned long)power4_idle_nap_return); 11798db179aSNicholas Piggin } 11898db179aSNicholas Piggin #endif 11998db179aSNicholas Piggin } 12098db179aSNicholas Piggin 12125b7e6bbSNicholas Piggin struct interrupt_state { 12225b7e6bbSNicholas Piggin }; 12325b7e6bbSNicholas Piggin 124d524dda7SChristophe Leroy static inline void booke_restore_dbcr0(void) 125d524dda7SChristophe Leroy { 126d524dda7SChristophe Leroy #ifdef CONFIG_PPC_ADV_DEBUG_REGS 127d524dda7SChristophe Leroy unsigned long dbcr0 = current->thread.debug.dbcr0; 128d524dda7SChristophe Leroy 129d524dda7SChristophe Leroy if (IS_ENABLED(CONFIG_PPC32) && unlikely(dbcr0 & DBCR0_IDM)) { 130d524dda7SChristophe Leroy mtspr(SPRN_DBSR, -1); 131d524dda7SChristophe Leroy mtspr(SPRN_DBCR0, global_dbcr0[smp_processor_id()]); 132d524dda7SChristophe Leroy } 133d524dda7SChristophe Leroy #endif 134d524dda7SChristophe Leroy } 135d524dda7SChristophe Leroy 13625b7e6bbSNicholas Piggin static inline void interrupt_enter_prepare(struct pt_regs *regs, struct interrupt_state *state) 13725b7e6bbSNicholas Piggin { 138be39e105SChristophe Leroy #ifdef CONFIG_PPC32 139be39e105SChristophe Leroy if (!arch_irq_disabled_regs(regs)) 140be39e105SChristophe Leroy trace_hardirqs_off(); 141f93d866eSChristophe Leroy 142b5efec00SChristophe Leroy if (user_mode(regs)) { 143b5efec00SChristophe Leroy kuep_lock(); 144f93d866eSChristophe Leroy account_cpu_user_entry(); 145c1672883SChristophe Leroy } else { 146c1672883SChristophe Leroy kuap_save_and_lock(regs); 147b5efec00SChristophe Leroy } 148be39e105SChristophe Leroy #endif 149097157e1SNicholas Piggin 150097157e1SNicholas Piggin #ifdef CONFIG_PPC64 15175b96950SNicholas Piggin if (irq_soft_mask_set_return(IRQS_ALL_DISABLED) == IRQS_ENABLED) 15275b96950SNicholas Piggin trace_hardirqs_off(); 15375b96950SNicholas Piggin local_paca->irq_happened |= PACA_IRQ_HARD_DIS; 15475b96950SNicholas Piggin 155f821bc97SNicholas Piggin if (user_mode(regs)) { 156f821bc97SNicholas Piggin CT_WARN_ON(ct_state() != CONTEXT_USER); 157f821bc97SNicholas Piggin user_exit_irqoff(); 15856acfdd8SNicholas Piggin 15956acfdd8SNicholas Piggin account_cpu_user_entry(); 16056acfdd8SNicholas Piggin account_stolen_time(); 161f821bc97SNicholas Piggin } else { 162f821bc97SNicholas Piggin /* 163f821bc97SNicholas Piggin * CT_WARN_ON comes here via program_check_exception, 164f821bc97SNicholas Piggin * so avoid recursion. 165f821bc97SNicholas Piggin */ 1669d1988caSNicholas Piggin if (TRAP(regs) != INTERRUPT_PROGRAM) { 167f821bc97SNicholas Piggin CT_WARN_ON(ct_state() != CONTEXT_KERNEL); 1689b69d48cSNicholas Piggin BUG_ON(is_implicit_soft_masked(regs)); 1699d1988caSNicholas Piggin } 1709b69d48cSNicholas Piggin #ifdef CONFIG_PPC_BOOK3S 1719d1988caSNicholas Piggin /* Move this under a debugging check */ 1729d1988caSNicholas Piggin if (arch_irq_disabled_regs(regs)) 1739d1988caSNicholas Piggin BUG_ON(search_kernel_restart_table(regs->nip)); 1749b69d48cSNicholas Piggin #endif 175f821bc97SNicholas Piggin } 1762b43dd76SNicholas Piggin if (IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG)) 1772b43dd76SNicholas Piggin BUG_ON(!arch_irq_disabled_regs(regs) && !(regs->msr & MSR_EE)); 178f821bc97SNicholas Piggin #endif 17975b96950SNicholas Piggin 18079f4bb17SChristophe Leroy booke_restore_dbcr0(); 18125b7e6bbSNicholas Piggin } 18225b7e6bbSNicholas Piggin 18325b7e6bbSNicholas Piggin /* 18425b7e6bbSNicholas Piggin * Care should be taken to note that interrupt_exit_prepare and 18525b7e6bbSNicholas Piggin * interrupt_async_exit_prepare do not necessarily return immediately to 18625b7e6bbSNicholas Piggin * regs context (e.g., if regs is usermode, we don't necessarily return to 18725b7e6bbSNicholas Piggin * user mode). Other interrupts might be taken between here and return, 18825b7e6bbSNicholas Piggin * context switch / preemption may occur in the exit path after this, or a 18925b7e6bbSNicholas Piggin * signal may be delivered, etc. 19025b7e6bbSNicholas Piggin * 19125b7e6bbSNicholas Piggin * The real interrupt exit code is platform specific, e.g., 19225b7e6bbSNicholas Piggin * interrupt_exit_user_prepare / interrupt_exit_kernel_prepare for 64s. 19325b7e6bbSNicholas Piggin * 19425b7e6bbSNicholas Piggin * However interrupt_nmi_exit_prepare does return directly to regs, because 19525b7e6bbSNicholas Piggin * NMIs do not do "exit work" or replay soft-masked interrupts. 19625b7e6bbSNicholas Piggin */ 19725b7e6bbSNicholas Piggin static inline void interrupt_exit_prepare(struct pt_regs *regs, struct interrupt_state *state) 19825b7e6bbSNicholas Piggin { 19925b7e6bbSNicholas Piggin } 20025b7e6bbSNicholas Piggin 20125b7e6bbSNicholas Piggin static inline void interrupt_async_enter_prepare(struct pt_regs *regs, struct interrupt_state *state) 20225b7e6bbSNicholas Piggin { 20386dbb394SNicholas Piggin #ifdef CONFIG_PPC_BOOK3S_64 20486dbb394SNicholas Piggin if (cpu_has_feature(CPU_FTR_CTRL) && 20586dbb394SNicholas Piggin !test_thread_local_flags(_TLF_RUNLATCH)) 20686dbb394SNicholas Piggin __ppc64_runlatch_on(); 20786dbb394SNicholas Piggin #endif 20886dbb394SNicholas Piggin 2096fdb0f41SNicholas Piggin interrupt_enter_prepare(regs, state); 2101b1b6a6fSNicholas Piggin irq_enter(); 21125b7e6bbSNicholas Piggin } 21225b7e6bbSNicholas Piggin 21325b7e6bbSNicholas Piggin static inline void interrupt_async_exit_prepare(struct pt_regs *regs, struct interrupt_state *state) 21425b7e6bbSNicholas Piggin { 21598db179aSNicholas Piggin /* 21698db179aSNicholas Piggin * Adjust at exit so the main handler sees the true NIA. This must 21798db179aSNicholas Piggin * come before irq_exit() because irq_exit can enable interrupts, and 21898db179aSNicholas Piggin * if another interrupt is taken before nap_adjust_return has run 21998db179aSNicholas Piggin * here, then that interrupt would return directly to idle nap return. 22098db179aSNicholas Piggin */ 22198db179aSNicholas Piggin nap_adjust_return(regs); 22298db179aSNicholas Piggin 2231b1b6a6fSNicholas Piggin irq_exit(); 2246fdb0f41SNicholas Piggin interrupt_exit_prepare(regs, state); 22525b7e6bbSNicholas Piggin } 22625b7e6bbSNicholas Piggin 22725b7e6bbSNicholas Piggin struct interrupt_nmi_state { 228118178e6SNicholas Piggin #ifdef CONFIG_PPC64 2296ecbb582SNicholas Piggin u8 irq_soft_mask; 2306ecbb582SNicholas Piggin u8 irq_happened; 231118178e6SNicholas Piggin u8 ftrace_enabled; 2321b048222SNicholas Piggin u64 softe; 233118178e6SNicholas Piggin #endif 23425b7e6bbSNicholas Piggin }; 23525b7e6bbSNicholas Piggin 2363db8aa10SNicholas Piggin static inline bool nmi_disables_ftrace(struct pt_regs *regs) 2373db8aa10SNicholas Piggin { 2383db8aa10SNicholas Piggin /* Allow DEC and PMI to be traced when they are soft-NMI */ 2393db8aa10SNicholas Piggin if (IS_ENABLED(CONFIG_PPC_BOOK3S_64)) { 2407153d4bfSXiongwei Song if (TRAP(regs) == INTERRUPT_DECREMENTER) 2413db8aa10SNicholas Piggin return false; 2427153d4bfSXiongwei Song if (TRAP(regs) == INTERRUPT_PERFMON) 2433db8aa10SNicholas Piggin return false; 2443db8aa10SNicholas Piggin } 2453db8aa10SNicholas Piggin if (IS_ENABLED(CONFIG_PPC_BOOK3E)) { 2467153d4bfSXiongwei Song if (TRAP(regs) == INTERRUPT_PERFMON) 2473db8aa10SNicholas Piggin return false; 2483db8aa10SNicholas Piggin } 2493db8aa10SNicholas Piggin 2503db8aa10SNicholas Piggin return true; 2513db8aa10SNicholas Piggin } 2523db8aa10SNicholas Piggin 25325b7e6bbSNicholas Piggin static inline void interrupt_nmi_enter_prepare(struct pt_regs *regs, struct interrupt_nmi_state *state) 25425b7e6bbSNicholas Piggin { 255118178e6SNicholas Piggin #ifdef CONFIG_PPC64 2566ecbb582SNicholas Piggin state->irq_soft_mask = local_paca->irq_soft_mask; 2576ecbb582SNicholas Piggin state->irq_happened = local_paca->irq_happened; 2581b048222SNicholas Piggin state->softe = regs->softe; 2596ecbb582SNicholas Piggin 2606ecbb582SNicholas Piggin /* 2616ecbb582SNicholas Piggin * Set IRQS_ALL_DISABLED unconditionally so irqs_disabled() does 2626ecbb582SNicholas Piggin * the right thing, and set IRQ_HARD_DIS. We do not want to reconcile 2636ecbb582SNicholas Piggin * because that goes through irq tracing which we don't want in NMI. 2646ecbb582SNicholas Piggin */ 2656ecbb582SNicholas Piggin local_paca->irq_soft_mask = IRQS_ALL_DISABLED; 2666ecbb582SNicholas Piggin local_paca->irq_happened |= PACA_IRQ_HARD_DIS; 2676ecbb582SNicholas Piggin 268*768c4701SNicholas Piggin if (!(regs->msr & MSR_EE) || is_implicit_soft_masked(regs)) { 269*768c4701SNicholas Piggin /* 270*768c4701SNicholas Piggin * Adjust regs->softe to be soft-masked if it had not been 271*768c4701SNicholas Piggin * reconcied (e.g., interrupt entry with MSR[EE]=0 but softe 272*768c4701SNicholas Piggin * not yet set disabled), or if it was in an implicit soft 273*768c4701SNicholas Piggin * masked state. This makes arch_irq_disabled_regs(regs) 274*768c4701SNicholas Piggin * behave as expected. 275*768c4701SNicholas Piggin */ 2764ec5feecSNicholas Piggin regs->softe = IRQS_ALL_DISABLED; 2774ec5feecSNicholas Piggin } 2784ec5feecSNicholas Piggin 2796ecbb582SNicholas Piggin /* Don't do any per-CPU operations until interrupt state is fixed */ 2803db8aa10SNicholas Piggin 2813db8aa10SNicholas Piggin if (nmi_disables_ftrace(regs)) { 282118178e6SNicholas Piggin state->ftrace_enabled = this_cpu_get_ftrace_enabled(); 283118178e6SNicholas Piggin this_cpu_set_ftrace_enabled(0); 284118178e6SNicholas Piggin } 285118178e6SNicholas Piggin #endif 286118178e6SNicholas Piggin 287118178e6SNicholas Piggin /* 288118178e6SNicholas Piggin * Do not use nmi_enter() for pseries hash guest taking a real-mode 289118178e6SNicholas Piggin * NMI because not everything it touches is within the RMA limit. 290118178e6SNicholas Piggin */ 291118178e6SNicholas Piggin if (!IS_ENABLED(CONFIG_PPC_BOOK3S_64) || 292118178e6SNicholas Piggin !firmware_has_feature(FW_FEATURE_LPAR) || 293118178e6SNicholas Piggin radix_enabled() || (mfmsr() & MSR_DR)) 294118178e6SNicholas Piggin nmi_enter(); 29525b7e6bbSNicholas Piggin } 29625b7e6bbSNicholas Piggin 29725b7e6bbSNicholas Piggin static inline void interrupt_nmi_exit_prepare(struct pt_regs *regs, struct interrupt_nmi_state *state) 29825b7e6bbSNicholas Piggin { 299118178e6SNicholas Piggin if (!IS_ENABLED(CONFIG_PPC_BOOK3S_64) || 300118178e6SNicholas Piggin !firmware_has_feature(FW_FEATURE_LPAR) || 301118178e6SNicholas Piggin radix_enabled() || (mfmsr() & MSR_DR)) 302118178e6SNicholas Piggin nmi_exit(); 303118178e6SNicholas Piggin 30498db179aSNicholas Piggin /* 30598db179aSNicholas Piggin * nmi does not call nap_adjust_return because nmi should not create 30698db179aSNicholas Piggin * new work to do (must use irq_work for that). 30798db179aSNicholas Piggin */ 30898db179aSNicholas Piggin 309118178e6SNicholas Piggin #ifdef CONFIG_PPC64 3109b69d48cSNicholas Piggin #ifdef CONFIG_PPC_BOOK3S 311f23699c9SNicholas Piggin if (arch_irq_disabled_regs(regs)) { 312f23699c9SNicholas Piggin unsigned long rst = search_kernel_restart_table(regs->nip); 313f23699c9SNicholas Piggin if (rst) 314f23699c9SNicholas Piggin regs_set_return_ip(regs, rst); 315f23699c9SNicholas Piggin } 316f23699c9SNicholas Piggin #endif 317f23699c9SNicholas Piggin 3183db8aa10SNicholas Piggin if (nmi_disables_ftrace(regs)) 319118178e6SNicholas Piggin this_cpu_set_ftrace_enabled(state->ftrace_enabled); 3206ecbb582SNicholas Piggin 3216ecbb582SNicholas Piggin /* Check we didn't change the pending interrupt mask. */ 3226ecbb582SNicholas Piggin WARN_ON_ONCE((state->irq_happened | PACA_IRQ_HARD_DIS) != local_paca->irq_happened); 3231b048222SNicholas Piggin regs->softe = state->softe; 3246ecbb582SNicholas Piggin local_paca->irq_happened = state->irq_happened; 3256ecbb582SNicholas Piggin local_paca->irq_soft_mask = state->irq_soft_mask; 3266ecbb582SNicholas Piggin #endif 32725b7e6bbSNicholas Piggin } 32825b7e6bbSNicholas Piggin 329e4bb64c7SNicholas Piggin /* 330e4bb64c7SNicholas Piggin * Don't use noinstr here like x86, but rather add NOKPROBE_SYMBOL to each 331e4bb64c7SNicholas Piggin * function definition. The reason for this is the noinstr section is placed 332e4bb64c7SNicholas Piggin * after the main text section, i.e., very far away from the interrupt entry 333e4bb64c7SNicholas Piggin * asm. That creates problems with fitting linker stubs when building large 334e4bb64c7SNicholas Piggin * kernels. 335e4bb64c7SNicholas Piggin */ 336e4bb64c7SNicholas Piggin #define interrupt_handler __visible noinline notrace __no_kcsan __no_sanitize_address 337e4bb64c7SNicholas Piggin 3388d41fc61SNicholas Piggin /** 3398d41fc61SNicholas Piggin * DECLARE_INTERRUPT_HANDLER_RAW - Declare raw interrupt handler function 3408d41fc61SNicholas Piggin * @func: Function name of the entry point 3418d41fc61SNicholas Piggin * @returns: Returns a value back to asm caller 3428d41fc61SNicholas Piggin */ 3438d41fc61SNicholas Piggin #define DECLARE_INTERRUPT_HANDLER_RAW(func) \ 3448d41fc61SNicholas Piggin __visible long func(struct pt_regs *regs) 3458d41fc61SNicholas Piggin 3468d41fc61SNicholas Piggin /** 3478d41fc61SNicholas Piggin * DEFINE_INTERRUPT_HANDLER_RAW - Define raw interrupt handler function 3488d41fc61SNicholas Piggin * @func: Function name of the entry point 3498d41fc61SNicholas Piggin * @returns: Returns a value back to asm caller 3508d41fc61SNicholas Piggin * 3518d41fc61SNicholas Piggin * @func is called from ASM entry code. 3528d41fc61SNicholas Piggin * 3538d41fc61SNicholas Piggin * This is a plain function which does no tracing, reconciling, etc. 3548d41fc61SNicholas Piggin * The macro is written so it acts as function definition. Append the 3558d41fc61SNicholas Piggin * body with a pair of curly brackets. 3568d41fc61SNicholas Piggin * 3578d41fc61SNicholas Piggin * raw interrupt handlers must not enable or disable interrupts, or 3588d41fc61SNicholas Piggin * schedule, tracing and instrumentation (ftrace, lockdep, etc) would 3598d41fc61SNicholas Piggin * not be advisable either, although may be possible in a pinch, the 3608d41fc61SNicholas Piggin * trace will look odd at least. 3618d41fc61SNicholas Piggin * 3628d41fc61SNicholas Piggin * A raw handler may call one of the other interrupt handler functions 3638d41fc61SNicholas Piggin * to be converted into that interrupt context without these restrictions. 3648d41fc61SNicholas Piggin * 3658d41fc61SNicholas Piggin * On PPC64, _RAW handlers may return with fast_interrupt_return. 3668d41fc61SNicholas Piggin * 3678d41fc61SNicholas Piggin * Specific handlers may have additional restrictions. 3688d41fc61SNicholas Piggin */ 3698d41fc61SNicholas Piggin #define DEFINE_INTERRUPT_HANDLER_RAW(func) \ 3708d41fc61SNicholas Piggin static __always_inline long ____##func(struct pt_regs *regs); \ 3718d41fc61SNicholas Piggin \ 372e4bb64c7SNicholas Piggin interrupt_handler long func(struct pt_regs *regs) \ 3738d41fc61SNicholas Piggin { \ 3748d41fc61SNicholas Piggin long ret; \ 3758d41fc61SNicholas Piggin \ 3768d41fc61SNicholas Piggin ret = ____##func (regs); \ 3778d41fc61SNicholas Piggin \ 3788d41fc61SNicholas Piggin return ret; \ 3798d41fc61SNicholas Piggin } \ 380e4bb64c7SNicholas Piggin NOKPROBE_SYMBOL(func); \ 3818d41fc61SNicholas Piggin \ 3828d41fc61SNicholas Piggin static __always_inline long ____##func(struct pt_regs *regs) 3838d41fc61SNicholas Piggin 3848d41fc61SNicholas Piggin /** 3858d41fc61SNicholas Piggin * DECLARE_INTERRUPT_HANDLER - Declare synchronous interrupt handler function 3868d41fc61SNicholas Piggin * @func: Function name of the entry point 3878d41fc61SNicholas Piggin */ 3888d41fc61SNicholas Piggin #define DECLARE_INTERRUPT_HANDLER(func) \ 3898d41fc61SNicholas Piggin __visible void func(struct pt_regs *regs) 3908d41fc61SNicholas Piggin 3918d41fc61SNicholas Piggin /** 3928d41fc61SNicholas Piggin * DEFINE_INTERRUPT_HANDLER - Define synchronous interrupt handler function 3938d41fc61SNicholas Piggin * @func: Function name of the entry point 3948d41fc61SNicholas Piggin * 3958d41fc61SNicholas Piggin * @func is called from ASM entry code. 3968d41fc61SNicholas Piggin * 3978d41fc61SNicholas Piggin * The macro is written so it acts as function definition. Append the 3988d41fc61SNicholas Piggin * body with a pair of curly brackets. 3998d41fc61SNicholas Piggin */ 4008d41fc61SNicholas Piggin #define DEFINE_INTERRUPT_HANDLER(func) \ 4018d41fc61SNicholas Piggin static __always_inline void ____##func(struct pt_regs *regs); \ 4028d41fc61SNicholas Piggin \ 403e4bb64c7SNicholas Piggin interrupt_handler void func(struct pt_regs *regs) \ 4048d41fc61SNicholas Piggin { \ 40525b7e6bbSNicholas Piggin struct interrupt_state state; \ 40625b7e6bbSNicholas Piggin \ 40725b7e6bbSNicholas Piggin interrupt_enter_prepare(regs, &state); \ 40825b7e6bbSNicholas Piggin \ 4098d41fc61SNicholas Piggin ____##func (regs); \ 41025b7e6bbSNicholas Piggin \ 41125b7e6bbSNicholas Piggin interrupt_exit_prepare(regs, &state); \ 4128d41fc61SNicholas Piggin } \ 413e4bb64c7SNicholas Piggin NOKPROBE_SYMBOL(func); \ 4148d41fc61SNicholas Piggin \ 4158d41fc61SNicholas Piggin static __always_inline void ____##func(struct pt_regs *regs) 4168d41fc61SNicholas Piggin 4178d41fc61SNicholas Piggin /** 4188d41fc61SNicholas Piggin * DECLARE_INTERRUPT_HANDLER_RET - Declare synchronous interrupt handler function 4198d41fc61SNicholas Piggin * @func: Function name of the entry point 4208d41fc61SNicholas Piggin * @returns: Returns a value back to asm caller 4218d41fc61SNicholas Piggin */ 4228d41fc61SNicholas Piggin #define DECLARE_INTERRUPT_HANDLER_RET(func) \ 4238d41fc61SNicholas Piggin __visible long func(struct pt_regs *regs) 4248d41fc61SNicholas Piggin 4258d41fc61SNicholas Piggin /** 4268d41fc61SNicholas Piggin * DEFINE_INTERRUPT_HANDLER_RET - Define synchronous interrupt handler function 4278d41fc61SNicholas Piggin * @func: Function name of the entry point 4288d41fc61SNicholas Piggin * @returns: Returns a value back to asm caller 4298d41fc61SNicholas Piggin * 4308d41fc61SNicholas Piggin * @func is called from ASM entry code. 4318d41fc61SNicholas Piggin * 4328d41fc61SNicholas Piggin * The macro is written so it acts as function definition. Append the 4338d41fc61SNicholas Piggin * body with a pair of curly brackets. 4348d41fc61SNicholas Piggin */ 4358d41fc61SNicholas Piggin #define DEFINE_INTERRUPT_HANDLER_RET(func) \ 4368d41fc61SNicholas Piggin static __always_inline long ____##func(struct pt_regs *regs); \ 4378d41fc61SNicholas Piggin \ 438e4bb64c7SNicholas Piggin interrupt_handler long func(struct pt_regs *regs) \ 4398d41fc61SNicholas Piggin { \ 44025b7e6bbSNicholas Piggin struct interrupt_state state; \ 4418d41fc61SNicholas Piggin long ret; \ 4428d41fc61SNicholas Piggin \ 44325b7e6bbSNicholas Piggin interrupt_enter_prepare(regs, &state); \ 44425b7e6bbSNicholas Piggin \ 4458d41fc61SNicholas Piggin ret = ____##func (regs); \ 4468d41fc61SNicholas Piggin \ 44725b7e6bbSNicholas Piggin interrupt_exit_prepare(regs, &state); \ 44825b7e6bbSNicholas Piggin \ 4498d41fc61SNicholas Piggin return ret; \ 4508d41fc61SNicholas Piggin } \ 451e4bb64c7SNicholas Piggin NOKPROBE_SYMBOL(func); \ 4528d41fc61SNicholas Piggin \ 4538d41fc61SNicholas Piggin static __always_inline long ____##func(struct pt_regs *regs) 4548d41fc61SNicholas Piggin 4558d41fc61SNicholas Piggin /** 4568d41fc61SNicholas Piggin * DECLARE_INTERRUPT_HANDLER_ASYNC - Declare asynchronous interrupt handler function 4578d41fc61SNicholas Piggin * @func: Function name of the entry point 4588d41fc61SNicholas Piggin */ 4598d41fc61SNicholas Piggin #define DECLARE_INTERRUPT_HANDLER_ASYNC(func) \ 4608d41fc61SNicholas Piggin __visible void func(struct pt_regs *regs) 4618d41fc61SNicholas Piggin 4628d41fc61SNicholas Piggin /** 4638d41fc61SNicholas Piggin * DEFINE_INTERRUPT_HANDLER_ASYNC - Define asynchronous interrupt handler function 4648d41fc61SNicholas Piggin * @func: Function name of the entry point 4658d41fc61SNicholas Piggin * 4668d41fc61SNicholas Piggin * @func is called from ASM entry code. 4678d41fc61SNicholas Piggin * 4688d41fc61SNicholas Piggin * The macro is written so it acts as function definition. Append the 4698d41fc61SNicholas Piggin * body with a pair of curly brackets. 4708d41fc61SNicholas Piggin */ 4718d41fc61SNicholas Piggin #define DEFINE_INTERRUPT_HANDLER_ASYNC(func) \ 4728d41fc61SNicholas Piggin static __always_inline void ____##func(struct pt_regs *regs); \ 4738d41fc61SNicholas Piggin \ 474e4bb64c7SNicholas Piggin interrupt_handler void func(struct pt_regs *regs) \ 4758d41fc61SNicholas Piggin { \ 47625b7e6bbSNicholas Piggin struct interrupt_state state; \ 47725b7e6bbSNicholas Piggin \ 47825b7e6bbSNicholas Piggin interrupt_async_enter_prepare(regs, &state); \ 47925b7e6bbSNicholas Piggin \ 4808d41fc61SNicholas Piggin ____##func (regs); \ 48125b7e6bbSNicholas Piggin \ 48225b7e6bbSNicholas Piggin interrupt_async_exit_prepare(regs, &state); \ 4838d41fc61SNicholas Piggin } \ 484e4bb64c7SNicholas Piggin NOKPROBE_SYMBOL(func); \ 4858d41fc61SNicholas Piggin \ 4868d41fc61SNicholas Piggin static __always_inline void ____##func(struct pt_regs *regs) 4878d41fc61SNicholas Piggin 4888d41fc61SNicholas Piggin /** 4898d41fc61SNicholas Piggin * DECLARE_INTERRUPT_HANDLER_NMI - Declare NMI interrupt handler function 4908d41fc61SNicholas Piggin * @func: Function name of the entry point 4918d41fc61SNicholas Piggin * @returns: Returns a value back to asm caller 4928d41fc61SNicholas Piggin */ 4938d41fc61SNicholas Piggin #define DECLARE_INTERRUPT_HANDLER_NMI(func) \ 4948d41fc61SNicholas Piggin __visible long func(struct pt_regs *regs) 4958d41fc61SNicholas Piggin 4968d41fc61SNicholas Piggin /** 4978d41fc61SNicholas Piggin * DEFINE_INTERRUPT_HANDLER_NMI - Define NMI interrupt handler function 4988d41fc61SNicholas Piggin * @func: Function name of the entry point 4998d41fc61SNicholas Piggin * @returns: Returns a value back to asm caller 5008d41fc61SNicholas Piggin * 5018d41fc61SNicholas Piggin * @func is called from ASM entry code. 5028d41fc61SNicholas Piggin * 5038d41fc61SNicholas Piggin * The macro is written so it acts as function definition. Append the 5048d41fc61SNicholas Piggin * body with a pair of curly brackets. 5058d41fc61SNicholas Piggin */ 5068d41fc61SNicholas Piggin #define DEFINE_INTERRUPT_HANDLER_NMI(func) \ 5078d41fc61SNicholas Piggin static __always_inline long ____##func(struct pt_regs *regs); \ 5088d41fc61SNicholas Piggin \ 509e4bb64c7SNicholas Piggin interrupt_handler long func(struct pt_regs *regs) \ 5108d41fc61SNicholas Piggin { \ 51125b7e6bbSNicholas Piggin struct interrupt_nmi_state state; \ 5128d41fc61SNicholas Piggin long ret; \ 5138d41fc61SNicholas Piggin \ 51425b7e6bbSNicholas Piggin interrupt_nmi_enter_prepare(regs, &state); \ 51525b7e6bbSNicholas Piggin \ 5168d41fc61SNicholas Piggin ret = ____##func (regs); \ 5178d41fc61SNicholas Piggin \ 51825b7e6bbSNicholas Piggin interrupt_nmi_exit_prepare(regs, &state); \ 51925b7e6bbSNicholas Piggin \ 5208d41fc61SNicholas Piggin return ret; \ 5218d41fc61SNicholas Piggin } \ 522e4bb64c7SNicholas Piggin NOKPROBE_SYMBOL(func); \ 5238d41fc61SNicholas Piggin \ 5248d41fc61SNicholas Piggin static __always_inline long ____##func(struct pt_regs *regs) 5258d41fc61SNicholas Piggin 5263a96570fSNicholas Piggin 5273a96570fSNicholas Piggin /* Interrupt handlers */ 5283a96570fSNicholas Piggin /* kernel/traps.c */ 5293a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(system_reset_exception); 5303a96570fSNicholas Piggin #ifdef CONFIG_PPC_BOOK3S_64 5313a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_ASYNC(machine_check_exception); 5323a96570fSNicholas Piggin #else 5333a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(machine_check_exception); 5343a96570fSNicholas Piggin #endif 5353a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(SMIException); 5363a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(handle_hmi_exception); 5373a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(unknown_exception); 5383a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_ASYNC(unknown_async_exception); 5393db8aa10SNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(unknown_nmi_exception); 5403a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(instruction_breakpoint_exception); 5413a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(RunModeException); 5423a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(single_step_exception); 5433a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(program_check_exception); 5443a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(emulation_assist_interrupt); 5453a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(alignment_exception); 5463a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(StackOverflow); 5473a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(stack_overflow_exception); 5483a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(kernel_fp_unavailable_exception); 5493a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(altivec_unavailable_exception); 5503a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(vsx_unavailable_exception); 5513a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(facility_unavailable_exception); 5523a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(fp_unavailable_tm); 5533a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(altivec_unavailable_tm); 5543a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(vsx_unavailable_tm); 5553a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(performance_monitor_exception_nmi); 5563a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_ASYNC(performance_monitor_exception_async); 5573a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_RAW(performance_monitor_exception); 5583a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(DebugException); 5593a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(altivec_assist_exception); 5603a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(CacheLockingException); 5613a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(SPEFloatingPointException); 5623a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(SPEFloatingPointRoundException); 5633db8aa10SNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(WatchdogException); 5643a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(kernel_bad_stack); 5653a96570fSNicholas Piggin 5663a96570fSNicholas Piggin /* slb.c */ 5673a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_RAW(do_slb_fault); 5683a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(do_bad_slb_fault); 5693a96570fSNicholas Piggin 5703a96570fSNicholas Piggin /* hash_utils.c */ 5713a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_RAW(do_hash_fault); 5723a96570fSNicholas Piggin 5733a96570fSNicholas Piggin /* fault.c */ 574c45ba4f4SNicholas Piggin DECLARE_INTERRUPT_HANDLER(do_page_fault); 5753a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(do_bad_page_fault_segv); 5763a96570fSNicholas Piggin 5773a96570fSNicholas Piggin /* process.c */ 5783a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(do_break); 5793a96570fSNicholas Piggin 5803a96570fSNicholas Piggin /* time.c */ 5813a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_ASYNC(timer_interrupt); 5823a96570fSNicholas Piggin 5833a96570fSNicholas Piggin /* mce.c */ 5843a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(machine_check_early); 5853a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(hmi_exception_realmode); 5863a96570fSNicholas Piggin 5873a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_ASYNC(TAUException); 5883a96570fSNicholas Piggin 58998694166SChristophe Leroy /* irq.c */ 59098694166SChristophe Leroy DECLARE_INTERRUPT_HANDLER_ASYNC(do_IRQ); 59198694166SChristophe Leroy 592a58cbed6SChristophe Leroy void __noreturn unrecoverable_exception(struct pt_regs *regs); 5930b736881SChristophe Leroy 5943a96570fSNicholas Piggin void replay_system_reset(void); 5953a96570fSNicholas Piggin void replay_soft_interrupts(void); 5963a96570fSNicholas Piggin 597e6f8a6c8SNicholas Piggin static inline void interrupt_cond_local_irq_enable(struct pt_regs *regs) 598e6f8a6c8SNicholas Piggin { 599e6f8a6c8SNicholas Piggin if (!arch_irq_disabled_regs(regs)) 600e6f8a6c8SNicholas Piggin local_irq_enable(); 601e6f8a6c8SNicholas Piggin } 602e6f8a6c8SNicholas Piggin 6030f5eb28aSChristophe Leroy #endif /* __ASSEMBLY__ */ 6040f5eb28aSChristophe Leroy 6058d41fc61SNicholas Piggin #endif /* _ASM_POWERPC_INTERRUPT_H */ 606