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*f23699c9SNicholas Piggin #ifdef CONFIG_PPC64 77*f23699c9SNicholas Piggin extern char __end_soft_masked[]; 78*f23699c9SNicholas Piggin unsigned long search_kernel_restart_table(unsigned long addr); 79*f23699c9SNicholas Piggin #endif 80*f23699c9SNicholas Piggin 8159dc5bfcSNicholas Piggin #ifdef CONFIG_PPC_BOOK3S_64 8259dc5bfcSNicholas Piggin static inline void srr_regs_clobbered(void) 8359dc5bfcSNicholas Piggin { 8459dc5bfcSNicholas Piggin local_paca->srr_valid = 0; 8559dc5bfcSNicholas Piggin local_paca->hsrr_valid = 0; 8659dc5bfcSNicholas Piggin } 8759dc5bfcSNicholas Piggin #else 8859dc5bfcSNicholas Piggin static inline void srr_regs_clobbered(void) 8959dc5bfcSNicholas Piggin { 9059dc5bfcSNicholas Piggin } 9159dc5bfcSNicholas Piggin #endif 9259dc5bfcSNicholas Piggin 9398db179aSNicholas Piggin static inline void nap_adjust_return(struct pt_regs *regs) 9498db179aSNicholas Piggin { 9598db179aSNicholas Piggin #ifdef CONFIG_PPC_970_NAP 9698db179aSNicholas Piggin if (unlikely(test_thread_local_flags(_TLF_NAPPING))) { 9798db179aSNicholas Piggin /* Can avoid a test-and-clear because NMIs do not call this */ 9898db179aSNicholas Piggin clear_thread_local_flags(_TLF_NAPPING); 9959dc5bfcSNicholas Piggin regs_set_return_ip(regs, (unsigned long)power4_idle_nap_return); 10098db179aSNicholas Piggin } 10198db179aSNicholas Piggin #endif 10298db179aSNicholas Piggin } 10398db179aSNicholas Piggin 10425b7e6bbSNicholas Piggin struct interrupt_state { 10525b7e6bbSNicholas Piggin }; 10625b7e6bbSNicholas Piggin 107d524dda7SChristophe Leroy static inline void booke_restore_dbcr0(void) 108d524dda7SChristophe Leroy { 109d524dda7SChristophe Leroy #ifdef CONFIG_PPC_ADV_DEBUG_REGS 110d524dda7SChristophe Leroy unsigned long dbcr0 = current->thread.debug.dbcr0; 111d524dda7SChristophe Leroy 112d524dda7SChristophe Leroy if (IS_ENABLED(CONFIG_PPC32) && unlikely(dbcr0 & DBCR0_IDM)) { 113d524dda7SChristophe Leroy mtspr(SPRN_DBSR, -1); 114d524dda7SChristophe Leroy mtspr(SPRN_DBCR0, global_dbcr0[smp_processor_id()]); 115d524dda7SChristophe Leroy } 116d524dda7SChristophe Leroy #endif 117d524dda7SChristophe Leroy } 118d524dda7SChristophe Leroy 11925b7e6bbSNicholas Piggin static inline void interrupt_enter_prepare(struct pt_regs *regs, struct interrupt_state *state) 12025b7e6bbSNicholas Piggin { 121be39e105SChristophe Leroy #ifdef CONFIG_PPC32 122be39e105SChristophe Leroy if (!arch_irq_disabled_regs(regs)) 123be39e105SChristophe Leroy trace_hardirqs_off(); 124f93d866eSChristophe Leroy 125b5efec00SChristophe Leroy if (user_mode(regs)) { 126b5efec00SChristophe Leroy kuep_lock(); 127f93d866eSChristophe Leroy account_cpu_user_entry(); 128c1672883SChristophe Leroy } else { 129c1672883SChristophe Leroy kuap_save_and_lock(regs); 130b5efec00SChristophe Leroy } 131be39e105SChristophe Leroy #endif 132097157e1SNicholas Piggin 133097157e1SNicholas Piggin #ifdef CONFIG_PPC64 13475b96950SNicholas Piggin if (irq_soft_mask_set_return(IRQS_ALL_DISABLED) == IRQS_ENABLED) 13575b96950SNicholas Piggin trace_hardirqs_off(); 13675b96950SNicholas Piggin local_paca->irq_happened |= PACA_IRQ_HARD_DIS; 13775b96950SNicholas Piggin 138f821bc97SNicholas Piggin if (user_mode(regs)) { 139f821bc97SNicholas Piggin CT_WARN_ON(ct_state() != CONTEXT_USER); 140f821bc97SNicholas Piggin user_exit_irqoff(); 14156acfdd8SNicholas Piggin 14256acfdd8SNicholas Piggin account_cpu_user_entry(); 14356acfdd8SNicholas Piggin account_stolen_time(); 144f821bc97SNicholas Piggin } else { 145f821bc97SNicholas Piggin /* 146f821bc97SNicholas Piggin * CT_WARN_ON comes here via program_check_exception, 147f821bc97SNicholas Piggin * so avoid recursion. 148f821bc97SNicholas Piggin */ 1497153d4bfSXiongwei Song if (TRAP(regs) != INTERRUPT_PROGRAM) 150f821bc97SNicholas Piggin CT_WARN_ON(ct_state() != CONTEXT_KERNEL); 151f821bc97SNicholas Piggin } 152f821bc97SNicholas Piggin #endif 15375b96950SNicholas Piggin 15479f4bb17SChristophe Leroy booke_restore_dbcr0(); 15525b7e6bbSNicholas Piggin } 15625b7e6bbSNicholas Piggin 15725b7e6bbSNicholas Piggin /* 15825b7e6bbSNicholas Piggin * Care should be taken to note that interrupt_exit_prepare and 15925b7e6bbSNicholas Piggin * interrupt_async_exit_prepare do not necessarily return immediately to 16025b7e6bbSNicholas Piggin * regs context (e.g., if regs is usermode, we don't necessarily return to 16125b7e6bbSNicholas Piggin * user mode). Other interrupts might be taken between here and return, 16225b7e6bbSNicholas Piggin * context switch / preemption may occur in the exit path after this, or a 16325b7e6bbSNicholas Piggin * signal may be delivered, etc. 16425b7e6bbSNicholas Piggin * 16525b7e6bbSNicholas Piggin * The real interrupt exit code is platform specific, e.g., 16625b7e6bbSNicholas Piggin * interrupt_exit_user_prepare / interrupt_exit_kernel_prepare for 64s. 16725b7e6bbSNicholas Piggin * 16825b7e6bbSNicholas Piggin * However interrupt_nmi_exit_prepare does return directly to regs, because 16925b7e6bbSNicholas Piggin * NMIs do not do "exit work" or replay soft-masked interrupts. 17025b7e6bbSNicholas Piggin */ 17125b7e6bbSNicholas Piggin static inline void interrupt_exit_prepare(struct pt_regs *regs, struct interrupt_state *state) 17225b7e6bbSNicholas Piggin { 17325b7e6bbSNicholas Piggin } 17425b7e6bbSNicholas Piggin 17525b7e6bbSNicholas Piggin static inline void interrupt_async_enter_prepare(struct pt_regs *regs, struct interrupt_state *state) 17625b7e6bbSNicholas Piggin { 17786dbb394SNicholas Piggin #ifdef CONFIG_PPC_BOOK3S_64 17886dbb394SNicholas Piggin if (cpu_has_feature(CPU_FTR_CTRL) && 17986dbb394SNicholas Piggin !test_thread_local_flags(_TLF_RUNLATCH)) 18086dbb394SNicholas Piggin __ppc64_runlatch_on(); 18186dbb394SNicholas Piggin #endif 18286dbb394SNicholas Piggin 1836fdb0f41SNicholas Piggin interrupt_enter_prepare(regs, state); 1841b1b6a6fSNicholas Piggin irq_enter(); 18525b7e6bbSNicholas Piggin } 18625b7e6bbSNicholas Piggin 18725b7e6bbSNicholas Piggin static inline void interrupt_async_exit_prepare(struct pt_regs *regs, struct interrupt_state *state) 18825b7e6bbSNicholas Piggin { 18998db179aSNicholas Piggin /* 19098db179aSNicholas Piggin * Adjust at exit so the main handler sees the true NIA. This must 19198db179aSNicholas Piggin * come before irq_exit() because irq_exit can enable interrupts, and 19298db179aSNicholas Piggin * if another interrupt is taken before nap_adjust_return has run 19398db179aSNicholas Piggin * here, then that interrupt would return directly to idle nap return. 19498db179aSNicholas Piggin */ 19598db179aSNicholas Piggin nap_adjust_return(regs); 19698db179aSNicholas Piggin 1971b1b6a6fSNicholas Piggin irq_exit(); 1986fdb0f41SNicholas Piggin interrupt_exit_prepare(regs, state); 19925b7e6bbSNicholas Piggin } 20025b7e6bbSNicholas Piggin 20125b7e6bbSNicholas Piggin struct interrupt_nmi_state { 202118178e6SNicholas Piggin #ifdef CONFIG_PPC64 2036ecbb582SNicholas Piggin u8 irq_soft_mask; 2046ecbb582SNicholas Piggin u8 irq_happened; 205118178e6SNicholas Piggin u8 ftrace_enabled; 206118178e6SNicholas Piggin #endif 20725b7e6bbSNicholas Piggin }; 20825b7e6bbSNicholas Piggin 2093db8aa10SNicholas Piggin static inline bool nmi_disables_ftrace(struct pt_regs *regs) 2103db8aa10SNicholas Piggin { 2113db8aa10SNicholas Piggin /* Allow DEC and PMI to be traced when they are soft-NMI */ 2123db8aa10SNicholas Piggin if (IS_ENABLED(CONFIG_PPC_BOOK3S_64)) { 2137153d4bfSXiongwei Song if (TRAP(regs) == INTERRUPT_DECREMENTER) 2143db8aa10SNicholas Piggin return false; 2157153d4bfSXiongwei Song if (TRAP(regs) == INTERRUPT_PERFMON) 2163db8aa10SNicholas Piggin return false; 2173db8aa10SNicholas Piggin } 2183db8aa10SNicholas Piggin if (IS_ENABLED(CONFIG_PPC_BOOK3E)) { 2197153d4bfSXiongwei Song if (TRAP(regs) == INTERRUPT_PERFMON) 2203db8aa10SNicholas Piggin return false; 2213db8aa10SNicholas Piggin } 2223db8aa10SNicholas Piggin 2233db8aa10SNicholas Piggin return true; 2243db8aa10SNicholas Piggin } 2253db8aa10SNicholas Piggin 22625b7e6bbSNicholas Piggin static inline void interrupt_nmi_enter_prepare(struct pt_regs *regs, struct interrupt_nmi_state *state) 22725b7e6bbSNicholas Piggin { 228118178e6SNicholas Piggin #ifdef CONFIG_PPC64 2296ecbb582SNicholas Piggin state->irq_soft_mask = local_paca->irq_soft_mask; 2306ecbb582SNicholas Piggin state->irq_happened = local_paca->irq_happened; 2316ecbb582SNicholas Piggin 2326ecbb582SNicholas Piggin /* 2336ecbb582SNicholas Piggin * Set IRQS_ALL_DISABLED unconditionally so irqs_disabled() does 2346ecbb582SNicholas Piggin * the right thing, and set IRQ_HARD_DIS. We do not want to reconcile 2356ecbb582SNicholas Piggin * because that goes through irq tracing which we don't want in NMI. 2366ecbb582SNicholas Piggin */ 2376ecbb582SNicholas Piggin local_paca->irq_soft_mask = IRQS_ALL_DISABLED; 2386ecbb582SNicholas Piggin local_paca->irq_happened |= PACA_IRQ_HARD_DIS; 2396ecbb582SNicholas Piggin 2404ec5feecSNicholas Piggin if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) && !(regs->msr & MSR_PR) && 2414ec5feecSNicholas Piggin regs->nip < (unsigned long)__end_interrupts) { 2424ec5feecSNicholas Piggin // Kernel code running below __end_interrupts is 2434ec5feecSNicholas Piggin // implicitly soft-masked. 2444ec5feecSNicholas Piggin regs->softe = IRQS_ALL_DISABLED; 2454ec5feecSNicholas Piggin } 2464ec5feecSNicholas Piggin 2476ecbb582SNicholas Piggin /* Don't do any per-CPU operations until interrupt state is fixed */ 2483db8aa10SNicholas Piggin 2493db8aa10SNicholas Piggin if (nmi_disables_ftrace(regs)) { 250118178e6SNicholas Piggin state->ftrace_enabled = this_cpu_get_ftrace_enabled(); 251118178e6SNicholas Piggin this_cpu_set_ftrace_enabled(0); 252118178e6SNicholas Piggin } 253118178e6SNicholas Piggin #endif 254118178e6SNicholas Piggin 255118178e6SNicholas Piggin /* 256118178e6SNicholas Piggin * Do not use nmi_enter() for pseries hash guest taking a real-mode 257118178e6SNicholas Piggin * NMI because not everything it touches is within the RMA limit. 258118178e6SNicholas Piggin */ 259118178e6SNicholas Piggin if (!IS_ENABLED(CONFIG_PPC_BOOK3S_64) || 260118178e6SNicholas Piggin !firmware_has_feature(FW_FEATURE_LPAR) || 261118178e6SNicholas Piggin radix_enabled() || (mfmsr() & MSR_DR)) 262118178e6SNicholas Piggin nmi_enter(); 26325b7e6bbSNicholas Piggin } 26425b7e6bbSNicholas Piggin 26525b7e6bbSNicholas Piggin static inline void interrupt_nmi_exit_prepare(struct pt_regs *regs, struct interrupt_nmi_state *state) 26625b7e6bbSNicholas Piggin { 267118178e6SNicholas Piggin if (!IS_ENABLED(CONFIG_PPC_BOOK3S_64) || 268118178e6SNicholas Piggin !firmware_has_feature(FW_FEATURE_LPAR) || 269118178e6SNicholas Piggin radix_enabled() || (mfmsr() & MSR_DR)) 270118178e6SNicholas Piggin nmi_exit(); 271118178e6SNicholas Piggin 27298db179aSNicholas Piggin /* 27398db179aSNicholas Piggin * nmi does not call nap_adjust_return because nmi should not create 27498db179aSNicholas Piggin * new work to do (must use irq_work for that). 27598db179aSNicholas Piggin */ 27698db179aSNicholas Piggin 277118178e6SNicholas Piggin #ifdef CONFIG_PPC64 278*f23699c9SNicholas Piggin if (arch_irq_disabled_regs(regs)) { 279*f23699c9SNicholas Piggin unsigned long rst = search_kernel_restart_table(regs->nip); 280*f23699c9SNicholas Piggin if (rst) 281*f23699c9SNicholas Piggin regs_set_return_ip(regs, rst); 282*f23699c9SNicholas Piggin } 283*f23699c9SNicholas Piggin #endif 284*f23699c9SNicholas Piggin 285*f23699c9SNicholas Piggin #ifdef CONFIG_PPC64 2863db8aa10SNicholas Piggin if (nmi_disables_ftrace(regs)) 287118178e6SNicholas Piggin this_cpu_set_ftrace_enabled(state->ftrace_enabled); 2886ecbb582SNicholas Piggin 2896ecbb582SNicholas Piggin /* Check we didn't change the pending interrupt mask. */ 2906ecbb582SNicholas Piggin WARN_ON_ONCE((state->irq_happened | PACA_IRQ_HARD_DIS) != local_paca->irq_happened); 2916ecbb582SNicholas Piggin local_paca->irq_happened = state->irq_happened; 2926ecbb582SNicholas Piggin local_paca->irq_soft_mask = state->irq_soft_mask; 2936ecbb582SNicholas Piggin #endif 29425b7e6bbSNicholas Piggin } 29525b7e6bbSNicholas Piggin 296e4bb64c7SNicholas Piggin /* 297e4bb64c7SNicholas Piggin * Don't use noinstr here like x86, but rather add NOKPROBE_SYMBOL to each 298e4bb64c7SNicholas Piggin * function definition. The reason for this is the noinstr section is placed 299e4bb64c7SNicholas Piggin * after the main text section, i.e., very far away from the interrupt entry 300e4bb64c7SNicholas Piggin * asm. That creates problems with fitting linker stubs when building large 301e4bb64c7SNicholas Piggin * kernels. 302e4bb64c7SNicholas Piggin */ 303e4bb64c7SNicholas Piggin #define interrupt_handler __visible noinline notrace __no_kcsan __no_sanitize_address 304e4bb64c7SNicholas Piggin 3058d41fc61SNicholas Piggin /** 3068d41fc61SNicholas Piggin * DECLARE_INTERRUPT_HANDLER_RAW - Declare raw interrupt handler function 3078d41fc61SNicholas Piggin * @func: Function name of the entry point 3088d41fc61SNicholas Piggin * @returns: Returns a value back to asm caller 3098d41fc61SNicholas Piggin */ 3108d41fc61SNicholas Piggin #define DECLARE_INTERRUPT_HANDLER_RAW(func) \ 3118d41fc61SNicholas Piggin __visible long func(struct pt_regs *regs) 3128d41fc61SNicholas Piggin 3138d41fc61SNicholas Piggin /** 3148d41fc61SNicholas Piggin * DEFINE_INTERRUPT_HANDLER_RAW - Define raw interrupt handler function 3158d41fc61SNicholas Piggin * @func: Function name of the entry point 3168d41fc61SNicholas Piggin * @returns: Returns a value back to asm caller 3178d41fc61SNicholas Piggin * 3188d41fc61SNicholas Piggin * @func is called from ASM entry code. 3198d41fc61SNicholas Piggin * 3208d41fc61SNicholas Piggin * This is a plain function which does no tracing, reconciling, etc. 3218d41fc61SNicholas Piggin * The macro is written so it acts as function definition. Append the 3228d41fc61SNicholas Piggin * body with a pair of curly brackets. 3238d41fc61SNicholas Piggin * 3248d41fc61SNicholas Piggin * raw interrupt handlers must not enable or disable interrupts, or 3258d41fc61SNicholas Piggin * schedule, tracing and instrumentation (ftrace, lockdep, etc) would 3268d41fc61SNicholas Piggin * not be advisable either, although may be possible in a pinch, the 3278d41fc61SNicholas Piggin * trace will look odd at least. 3288d41fc61SNicholas Piggin * 3298d41fc61SNicholas Piggin * A raw handler may call one of the other interrupt handler functions 3308d41fc61SNicholas Piggin * to be converted into that interrupt context without these restrictions. 3318d41fc61SNicholas Piggin * 3328d41fc61SNicholas Piggin * On PPC64, _RAW handlers may return with fast_interrupt_return. 3338d41fc61SNicholas Piggin * 3348d41fc61SNicholas Piggin * Specific handlers may have additional restrictions. 3358d41fc61SNicholas Piggin */ 3368d41fc61SNicholas Piggin #define DEFINE_INTERRUPT_HANDLER_RAW(func) \ 3378d41fc61SNicholas Piggin static __always_inline long ____##func(struct pt_regs *regs); \ 3388d41fc61SNicholas Piggin \ 339e4bb64c7SNicholas Piggin interrupt_handler long func(struct pt_regs *regs) \ 3408d41fc61SNicholas Piggin { \ 3418d41fc61SNicholas Piggin long ret; \ 3428d41fc61SNicholas Piggin \ 3438d41fc61SNicholas Piggin ret = ____##func (regs); \ 3448d41fc61SNicholas Piggin \ 3458d41fc61SNicholas Piggin return ret; \ 3468d41fc61SNicholas Piggin } \ 347e4bb64c7SNicholas Piggin NOKPROBE_SYMBOL(func); \ 3488d41fc61SNicholas Piggin \ 3498d41fc61SNicholas Piggin static __always_inline long ____##func(struct pt_regs *regs) 3508d41fc61SNicholas Piggin 3518d41fc61SNicholas Piggin /** 3528d41fc61SNicholas Piggin * DECLARE_INTERRUPT_HANDLER - Declare synchronous interrupt handler function 3538d41fc61SNicholas Piggin * @func: Function name of the entry point 3548d41fc61SNicholas Piggin */ 3558d41fc61SNicholas Piggin #define DECLARE_INTERRUPT_HANDLER(func) \ 3568d41fc61SNicholas Piggin __visible void func(struct pt_regs *regs) 3578d41fc61SNicholas Piggin 3588d41fc61SNicholas Piggin /** 3598d41fc61SNicholas Piggin * DEFINE_INTERRUPT_HANDLER - Define synchronous interrupt handler function 3608d41fc61SNicholas Piggin * @func: Function name of the entry point 3618d41fc61SNicholas Piggin * 3628d41fc61SNicholas Piggin * @func is called from ASM entry code. 3638d41fc61SNicholas Piggin * 3648d41fc61SNicholas Piggin * The macro is written so it acts as function definition. Append the 3658d41fc61SNicholas Piggin * body with a pair of curly brackets. 3668d41fc61SNicholas Piggin */ 3678d41fc61SNicholas Piggin #define DEFINE_INTERRUPT_HANDLER(func) \ 3688d41fc61SNicholas Piggin static __always_inline void ____##func(struct pt_regs *regs); \ 3698d41fc61SNicholas Piggin \ 370e4bb64c7SNicholas Piggin interrupt_handler void func(struct pt_regs *regs) \ 3718d41fc61SNicholas Piggin { \ 37225b7e6bbSNicholas Piggin struct interrupt_state state; \ 37325b7e6bbSNicholas Piggin \ 37425b7e6bbSNicholas Piggin interrupt_enter_prepare(regs, &state); \ 37525b7e6bbSNicholas Piggin \ 3768d41fc61SNicholas Piggin ____##func (regs); \ 37725b7e6bbSNicholas Piggin \ 37825b7e6bbSNicholas Piggin interrupt_exit_prepare(regs, &state); \ 3798d41fc61SNicholas Piggin } \ 380e4bb64c7SNicholas Piggin NOKPROBE_SYMBOL(func); \ 3818d41fc61SNicholas Piggin \ 3828d41fc61SNicholas Piggin static __always_inline void ____##func(struct pt_regs *regs) 3838d41fc61SNicholas Piggin 3848d41fc61SNicholas Piggin /** 3858d41fc61SNicholas Piggin * DECLARE_INTERRUPT_HANDLER_RET - Declare synchronous interrupt handler function 3868d41fc61SNicholas Piggin * @func: Function name of the entry point 3878d41fc61SNicholas Piggin * @returns: Returns a value back to asm caller 3888d41fc61SNicholas Piggin */ 3898d41fc61SNicholas Piggin #define DECLARE_INTERRUPT_HANDLER_RET(func) \ 3908d41fc61SNicholas Piggin __visible long func(struct pt_regs *regs) 3918d41fc61SNicholas Piggin 3928d41fc61SNicholas Piggin /** 3938d41fc61SNicholas Piggin * DEFINE_INTERRUPT_HANDLER_RET - Define synchronous interrupt handler function 3948d41fc61SNicholas Piggin * @func: Function name of the entry point 3958d41fc61SNicholas Piggin * @returns: Returns a value back to asm caller 3968d41fc61SNicholas Piggin * 3978d41fc61SNicholas Piggin * @func is called from ASM entry code. 3988d41fc61SNicholas Piggin * 3998d41fc61SNicholas Piggin * The macro is written so it acts as function definition. Append the 4008d41fc61SNicholas Piggin * body with a pair of curly brackets. 4018d41fc61SNicholas Piggin */ 4028d41fc61SNicholas Piggin #define DEFINE_INTERRUPT_HANDLER_RET(func) \ 4038d41fc61SNicholas Piggin static __always_inline long ____##func(struct pt_regs *regs); \ 4048d41fc61SNicholas Piggin \ 405e4bb64c7SNicholas Piggin interrupt_handler long func(struct pt_regs *regs) \ 4068d41fc61SNicholas Piggin { \ 40725b7e6bbSNicholas Piggin struct interrupt_state state; \ 4088d41fc61SNicholas Piggin long ret; \ 4098d41fc61SNicholas Piggin \ 41025b7e6bbSNicholas Piggin interrupt_enter_prepare(regs, &state); \ 41125b7e6bbSNicholas Piggin \ 4128d41fc61SNicholas Piggin ret = ____##func (regs); \ 4138d41fc61SNicholas Piggin \ 41425b7e6bbSNicholas Piggin interrupt_exit_prepare(regs, &state); \ 41525b7e6bbSNicholas Piggin \ 4168d41fc61SNicholas Piggin return ret; \ 4178d41fc61SNicholas Piggin } \ 418e4bb64c7SNicholas Piggin NOKPROBE_SYMBOL(func); \ 4198d41fc61SNicholas Piggin \ 4208d41fc61SNicholas Piggin static __always_inline long ____##func(struct pt_regs *regs) 4218d41fc61SNicholas Piggin 4228d41fc61SNicholas Piggin /** 4238d41fc61SNicholas Piggin * DECLARE_INTERRUPT_HANDLER_ASYNC - Declare asynchronous interrupt handler function 4248d41fc61SNicholas Piggin * @func: Function name of the entry point 4258d41fc61SNicholas Piggin */ 4268d41fc61SNicholas Piggin #define DECLARE_INTERRUPT_HANDLER_ASYNC(func) \ 4278d41fc61SNicholas Piggin __visible void func(struct pt_regs *regs) 4288d41fc61SNicholas Piggin 4298d41fc61SNicholas Piggin /** 4308d41fc61SNicholas Piggin * DEFINE_INTERRUPT_HANDLER_ASYNC - Define asynchronous interrupt handler function 4318d41fc61SNicholas Piggin * @func: Function name of the entry point 4328d41fc61SNicholas Piggin * 4338d41fc61SNicholas Piggin * @func is called from ASM entry code. 4348d41fc61SNicholas Piggin * 4358d41fc61SNicholas Piggin * The macro is written so it acts as function definition. Append the 4368d41fc61SNicholas Piggin * body with a pair of curly brackets. 4378d41fc61SNicholas Piggin */ 4388d41fc61SNicholas Piggin #define DEFINE_INTERRUPT_HANDLER_ASYNC(func) \ 4398d41fc61SNicholas Piggin static __always_inline void ____##func(struct pt_regs *regs); \ 4408d41fc61SNicholas Piggin \ 441e4bb64c7SNicholas Piggin interrupt_handler void func(struct pt_regs *regs) \ 4428d41fc61SNicholas Piggin { \ 44325b7e6bbSNicholas Piggin struct interrupt_state state; \ 44425b7e6bbSNicholas Piggin \ 44525b7e6bbSNicholas Piggin interrupt_async_enter_prepare(regs, &state); \ 44625b7e6bbSNicholas Piggin \ 4478d41fc61SNicholas Piggin ____##func (regs); \ 44825b7e6bbSNicholas Piggin \ 44925b7e6bbSNicholas Piggin interrupt_async_exit_prepare(regs, &state); \ 4508d41fc61SNicholas Piggin } \ 451e4bb64c7SNicholas Piggin NOKPROBE_SYMBOL(func); \ 4528d41fc61SNicholas Piggin \ 4538d41fc61SNicholas Piggin static __always_inline void ____##func(struct pt_regs *regs) 4548d41fc61SNicholas Piggin 4558d41fc61SNicholas Piggin /** 4568d41fc61SNicholas Piggin * DECLARE_INTERRUPT_HANDLER_NMI - Declare NMI interrupt handler function 4578d41fc61SNicholas Piggin * @func: Function name of the entry point 4588d41fc61SNicholas Piggin * @returns: Returns a value back to asm caller 4598d41fc61SNicholas Piggin */ 4608d41fc61SNicholas Piggin #define DECLARE_INTERRUPT_HANDLER_NMI(func) \ 4618d41fc61SNicholas Piggin __visible long func(struct pt_regs *regs) 4628d41fc61SNicholas Piggin 4638d41fc61SNicholas Piggin /** 4648d41fc61SNicholas Piggin * DEFINE_INTERRUPT_HANDLER_NMI - Define NMI interrupt handler function 4658d41fc61SNicholas Piggin * @func: Function name of the entry point 4668d41fc61SNicholas Piggin * @returns: Returns a value back to asm caller 4678d41fc61SNicholas Piggin * 4688d41fc61SNicholas Piggin * @func is called from ASM entry code. 4698d41fc61SNicholas Piggin * 4708d41fc61SNicholas Piggin * The macro is written so it acts as function definition. Append the 4718d41fc61SNicholas Piggin * body with a pair of curly brackets. 4728d41fc61SNicholas Piggin */ 4738d41fc61SNicholas Piggin #define DEFINE_INTERRUPT_HANDLER_NMI(func) \ 4748d41fc61SNicholas Piggin static __always_inline long ____##func(struct pt_regs *regs); \ 4758d41fc61SNicholas Piggin \ 476e4bb64c7SNicholas Piggin interrupt_handler long func(struct pt_regs *regs) \ 4778d41fc61SNicholas Piggin { \ 47825b7e6bbSNicholas Piggin struct interrupt_nmi_state state; \ 4798d41fc61SNicholas Piggin long ret; \ 4808d41fc61SNicholas Piggin \ 48125b7e6bbSNicholas Piggin interrupt_nmi_enter_prepare(regs, &state); \ 48225b7e6bbSNicholas Piggin \ 4838d41fc61SNicholas Piggin ret = ____##func (regs); \ 4848d41fc61SNicholas Piggin \ 48525b7e6bbSNicholas Piggin interrupt_nmi_exit_prepare(regs, &state); \ 48625b7e6bbSNicholas Piggin \ 4878d41fc61SNicholas Piggin return ret; \ 4888d41fc61SNicholas Piggin } \ 489e4bb64c7SNicholas Piggin NOKPROBE_SYMBOL(func); \ 4908d41fc61SNicholas Piggin \ 4918d41fc61SNicholas Piggin static __always_inline long ____##func(struct pt_regs *regs) 4928d41fc61SNicholas Piggin 4933a96570fSNicholas Piggin 4943a96570fSNicholas Piggin /* Interrupt handlers */ 4953a96570fSNicholas Piggin /* kernel/traps.c */ 4963a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(system_reset_exception); 4973a96570fSNicholas Piggin #ifdef CONFIG_PPC_BOOK3S_64 4983a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_ASYNC(machine_check_exception); 4993a96570fSNicholas Piggin #else 5003a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(machine_check_exception); 5013a96570fSNicholas Piggin #endif 5023a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(SMIException); 5033a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(handle_hmi_exception); 5043a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(unknown_exception); 5053a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_ASYNC(unknown_async_exception); 5063db8aa10SNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(unknown_nmi_exception); 5073a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(instruction_breakpoint_exception); 5083a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(RunModeException); 5093a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(single_step_exception); 5103a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(program_check_exception); 5113a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(emulation_assist_interrupt); 5123a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(alignment_exception); 5133a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(StackOverflow); 5143a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(stack_overflow_exception); 5153a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(kernel_fp_unavailable_exception); 5163a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(altivec_unavailable_exception); 5173a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(vsx_unavailable_exception); 5183a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(facility_unavailable_exception); 5193a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(fp_unavailable_tm); 5203a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(altivec_unavailable_tm); 5213a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(vsx_unavailable_tm); 5223a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(performance_monitor_exception_nmi); 5233a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_ASYNC(performance_monitor_exception_async); 5243a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_RAW(performance_monitor_exception); 5253a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(DebugException); 5263a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(altivec_assist_exception); 5273a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(CacheLockingException); 5283a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(SPEFloatingPointException); 5293a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(SPEFloatingPointRoundException); 5303db8aa10SNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(WatchdogException); 5313a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(kernel_bad_stack); 5323a96570fSNicholas Piggin 5333a96570fSNicholas Piggin /* slb.c */ 5343a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_RAW(do_slb_fault); 5353a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(do_bad_slb_fault); 5363a96570fSNicholas Piggin 5373a96570fSNicholas Piggin /* hash_utils.c */ 5383a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_RAW(do_hash_fault); 5393a96570fSNicholas Piggin 5403a96570fSNicholas Piggin /* fault.c */ 541c45ba4f4SNicholas Piggin DECLARE_INTERRUPT_HANDLER(do_page_fault); 5423a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(do_bad_page_fault_segv); 5433a96570fSNicholas Piggin 5443a96570fSNicholas Piggin /* process.c */ 5453a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(do_break); 5463a96570fSNicholas Piggin 5473a96570fSNicholas Piggin /* time.c */ 5483a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_ASYNC(timer_interrupt); 5493a96570fSNicholas Piggin 5503a96570fSNicholas Piggin /* mce.c */ 5513a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(machine_check_early); 5523a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(hmi_exception_realmode); 5533a96570fSNicholas Piggin 5543a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_ASYNC(TAUException); 5553a96570fSNicholas Piggin 556a58cbed6SChristophe Leroy void __noreturn unrecoverable_exception(struct pt_regs *regs); 5570b736881SChristophe Leroy 5583a96570fSNicholas Piggin void replay_system_reset(void); 5593a96570fSNicholas Piggin void replay_soft_interrupts(void); 5603a96570fSNicholas Piggin 561e6f8a6c8SNicholas Piggin static inline void interrupt_cond_local_irq_enable(struct pt_regs *regs) 562e6f8a6c8SNicholas Piggin { 563e6f8a6c8SNicholas Piggin if (!arch_irq_disabled_regs(regs)) 564e6f8a6c8SNicholas Piggin local_irq_enable(); 565e6f8a6c8SNicholas Piggin } 566e6f8a6c8SNicholas Piggin 5670f5eb28aSChristophe Leroy #endif /* __ASSEMBLY__ */ 5680f5eb28aSChristophe Leroy 5698d41fc61SNicholas Piggin #endif /* _ASM_POWERPC_INTERRUPT_H */ 570