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 7698db179aSNicholas Piggin static inline void nap_adjust_return(struct pt_regs *regs) 7798db179aSNicholas Piggin { 7898db179aSNicholas Piggin #ifdef CONFIG_PPC_970_NAP 7998db179aSNicholas Piggin if (unlikely(test_thread_local_flags(_TLF_NAPPING))) { 8098db179aSNicholas Piggin /* Can avoid a test-and-clear because NMIs do not call this */ 8198db179aSNicholas Piggin clear_thread_local_flags(_TLF_NAPPING); 8298db179aSNicholas Piggin regs->nip = (unsigned long)power4_idle_nap_return; 8398db179aSNicholas Piggin } 8498db179aSNicholas Piggin #endif 8598db179aSNicholas Piggin } 8698db179aSNicholas Piggin 8725b7e6bbSNicholas Piggin struct interrupt_state { 8825b7e6bbSNicholas Piggin }; 8925b7e6bbSNicholas Piggin 90d524dda7SChristophe Leroy static inline void booke_restore_dbcr0(void) 91d524dda7SChristophe Leroy { 92d524dda7SChristophe Leroy #ifdef CONFIG_PPC_ADV_DEBUG_REGS 93d524dda7SChristophe Leroy unsigned long dbcr0 = current->thread.debug.dbcr0; 94d524dda7SChristophe Leroy 95d524dda7SChristophe Leroy if (IS_ENABLED(CONFIG_PPC32) && unlikely(dbcr0 & DBCR0_IDM)) { 96d524dda7SChristophe Leroy mtspr(SPRN_DBSR, -1); 97d524dda7SChristophe Leroy mtspr(SPRN_DBCR0, global_dbcr0[smp_processor_id()]); 98d524dda7SChristophe Leroy } 99d524dda7SChristophe Leroy #endif 100d524dda7SChristophe Leroy } 101d524dda7SChristophe Leroy 10225b7e6bbSNicholas Piggin static inline void interrupt_enter_prepare(struct pt_regs *regs, struct interrupt_state *state) 10325b7e6bbSNicholas Piggin { 104be39e105SChristophe Leroy #ifdef CONFIG_PPC32 105be39e105SChristophe Leroy if (!arch_irq_disabled_regs(regs)) 106be39e105SChristophe Leroy trace_hardirqs_off(); 107f93d866eSChristophe Leroy 108b5efec00SChristophe Leroy if (user_mode(regs)) { 109b5efec00SChristophe Leroy kuep_lock(); 110f93d866eSChristophe Leroy account_cpu_user_entry(); 111c1672883SChristophe Leroy } else { 112c1672883SChristophe Leroy kuap_save_and_lock(regs); 113b5efec00SChristophe Leroy } 114be39e105SChristophe Leroy #endif 115097157e1SNicholas Piggin 116097157e1SNicholas Piggin #ifdef CONFIG_PPC64 11775b96950SNicholas Piggin if (irq_soft_mask_set_return(IRQS_ALL_DISABLED) == IRQS_ENABLED) 11875b96950SNicholas Piggin trace_hardirqs_off(); 11975b96950SNicholas Piggin local_paca->irq_happened |= PACA_IRQ_HARD_DIS; 12075b96950SNicholas Piggin 121f821bc97SNicholas Piggin if (user_mode(regs)) { 122f821bc97SNicholas Piggin CT_WARN_ON(ct_state() != CONTEXT_USER); 123f821bc97SNicholas Piggin user_exit_irqoff(); 12456acfdd8SNicholas Piggin 12556acfdd8SNicholas Piggin account_cpu_user_entry(); 12656acfdd8SNicholas Piggin account_stolen_time(); 127f821bc97SNicholas Piggin } else { 128f821bc97SNicholas Piggin /* 129f821bc97SNicholas Piggin * CT_WARN_ON comes here via program_check_exception, 130f821bc97SNicholas Piggin * so avoid recursion. 131f821bc97SNicholas Piggin */ 1327153d4bfSXiongwei Song if (TRAP(regs) != INTERRUPT_PROGRAM) 133f821bc97SNicholas Piggin CT_WARN_ON(ct_state() != CONTEXT_KERNEL); 134f821bc97SNicholas Piggin } 135f821bc97SNicholas Piggin #endif 13675b96950SNicholas Piggin 13779f4bb17SChristophe Leroy booke_restore_dbcr0(); 13825b7e6bbSNicholas Piggin } 13925b7e6bbSNicholas Piggin 14025b7e6bbSNicholas Piggin /* 14125b7e6bbSNicholas Piggin * Care should be taken to note that interrupt_exit_prepare and 14225b7e6bbSNicholas Piggin * interrupt_async_exit_prepare do not necessarily return immediately to 14325b7e6bbSNicholas Piggin * regs context (e.g., if regs is usermode, we don't necessarily return to 14425b7e6bbSNicholas Piggin * user mode). Other interrupts might be taken between here and return, 14525b7e6bbSNicholas Piggin * context switch / preemption may occur in the exit path after this, or a 14625b7e6bbSNicholas Piggin * signal may be delivered, etc. 14725b7e6bbSNicholas Piggin * 14825b7e6bbSNicholas Piggin * The real interrupt exit code is platform specific, e.g., 14925b7e6bbSNicholas Piggin * interrupt_exit_user_prepare / interrupt_exit_kernel_prepare for 64s. 15025b7e6bbSNicholas Piggin * 15125b7e6bbSNicholas Piggin * However interrupt_nmi_exit_prepare does return directly to regs, because 15225b7e6bbSNicholas Piggin * NMIs do not do "exit work" or replay soft-masked interrupts. 15325b7e6bbSNicholas Piggin */ 15425b7e6bbSNicholas Piggin static inline void interrupt_exit_prepare(struct pt_regs *regs, struct interrupt_state *state) 15525b7e6bbSNicholas Piggin { 15625b7e6bbSNicholas Piggin } 15725b7e6bbSNicholas Piggin 15825b7e6bbSNicholas Piggin static inline void interrupt_async_enter_prepare(struct pt_regs *regs, struct interrupt_state *state) 15925b7e6bbSNicholas Piggin { 16086dbb394SNicholas Piggin #ifdef CONFIG_PPC_BOOK3S_64 16186dbb394SNicholas Piggin if (cpu_has_feature(CPU_FTR_CTRL) && 16286dbb394SNicholas Piggin !test_thread_local_flags(_TLF_RUNLATCH)) 16386dbb394SNicholas Piggin __ppc64_runlatch_on(); 16486dbb394SNicholas Piggin #endif 16586dbb394SNicholas Piggin 1666fdb0f41SNicholas Piggin interrupt_enter_prepare(regs, state); 1671b1b6a6fSNicholas Piggin irq_enter(); 16825b7e6bbSNicholas Piggin } 16925b7e6bbSNicholas Piggin 17025b7e6bbSNicholas Piggin static inline void interrupt_async_exit_prepare(struct pt_regs *regs, struct interrupt_state *state) 17125b7e6bbSNicholas Piggin { 17298db179aSNicholas Piggin /* 17398db179aSNicholas Piggin * Adjust at exit so the main handler sees the true NIA. This must 17498db179aSNicholas Piggin * come before irq_exit() because irq_exit can enable interrupts, and 17598db179aSNicholas Piggin * if another interrupt is taken before nap_adjust_return has run 17698db179aSNicholas Piggin * here, then that interrupt would return directly to idle nap return. 17798db179aSNicholas Piggin */ 17898db179aSNicholas Piggin nap_adjust_return(regs); 17998db179aSNicholas Piggin 1801b1b6a6fSNicholas Piggin irq_exit(); 1816fdb0f41SNicholas Piggin interrupt_exit_prepare(regs, state); 18225b7e6bbSNicholas Piggin } 18325b7e6bbSNicholas Piggin 18425b7e6bbSNicholas Piggin struct interrupt_nmi_state { 185118178e6SNicholas Piggin #ifdef CONFIG_PPC64 1866ecbb582SNicholas Piggin u8 irq_soft_mask; 1876ecbb582SNicholas Piggin u8 irq_happened; 188118178e6SNicholas Piggin u8 ftrace_enabled; 189118178e6SNicholas Piggin #endif 19025b7e6bbSNicholas Piggin }; 19125b7e6bbSNicholas Piggin 1923db8aa10SNicholas Piggin static inline bool nmi_disables_ftrace(struct pt_regs *regs) 1933db8aa10SNicholas Piggin { 1943db8aa10SNicholas Piggin /* Allow DEC and PMI to be traced when they are soft-NMI */ 1953db8aa10SNicholas Piggin if (IS_ENABLED(CONFIG_PPC_BOOK3S_64)) { 1967153d4bfSXiongwei Song if (TRAP(regs) == INTERRUPT_DECREMENTER) 1973db8aa10SNicholas Piggin return false; 1987153d4bfSXiongwei Song if (TRAP(regs) == INTERRUPT_PERFMON) 1993db8aa10SNicholas Piggin return false; 2003db8aa10SNicholas Piggin } 2013db8aa10SNicholas Piggin if (IS_ENABLED(CONFIG_PPC_BOOK3E)) { 2027153d4bfSXiongwei Song if (TRAP(regs) == INTERRUPT_PERFMON) 2033db8aa10SNicholas Piggin return false; 2043db8aa10SNicholas Piggin } 2053db8aa10SNicholas Piggin 2063db8aa10SNicholas Piggin return true; 2073db8aa10SNicholas Piggin } 2083db8aa10SNicholas Piggin 20925b7e6bbSNicholas Piggin static inline void interrupt_nmi_enter_prepare(struct pt_regs *regs, struct interrupt_nmi_state *state) 21025b7e6bbSNicholas Piggin { 211118178e6SNicholas Piggin #ifdef CONFIG_PPC64 2126ecbb582SNicholas Piggin state->irq_soft_mask = local_paca->irq_soft_mask; 2136ecbb582SNicholas Piggin state->irq_happened = local_paca->irq_happened; 2146ecbb582SNicholas Piggin 2156ecbb582SNicholas Piggin /* 2166ecbb582SNicholas Piggin * Set IRQS_ALL_DISABLED unconditionally so irqs_disabled() does 2176ecbb582SNicholas Piggin * the right thing, and set IRQ_HARD_DIS. We do not want to reconcile 2186ecbb582SNicholas Piggin * because that goes through irq tracing which we don't want in NMI. 2196ecbb582SNicholas Piggin */ 2206ecbb582SNicholas Piggin local_paca->irq_soft_mask = IRQS_ALL_DISABLED; 2216ecbb582SNicholas Piggin local_paca->irq_happened |= PACA_IRQ_HARD_DIS; 2226ecbb582SNicholas Piggin 223*4ec5feecSNicholas Piggin if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) && !(regs->msr & MSR_PR) && 224*4ec5feecSNicholas Piggin regs->nip < (unsigned long)__end_interrupts) { 225*4ec5feecSNicholas Piggin // Kernel code running below __end_interrupts is 226*4ec5feecSNicholas Piggin // implicitly soft-masked. 227*4ec5feecSNicholas Piggin regs->softe = IRQS_ALL_DISABLED; 228*4ec5feecSNicholas Piggin } 229*4ec5feecSNicholas Piggin 2306ecbb582SNicholas Piggin /* Don't do any per-CPU operations until interrupt state is fixed */ 2313db8aa10SNicholas Piggin 2323db8aa10SNicholas Piggin if (nmi_disables_ftrace(regs)) { 233118178e6SNicholas Piggin state->ftrace_enabled = this_cpu_get_ftrace_enabled(); 234118178e6SNicholas Piggin this_cpu_set_ftrace_enabled(0); 235118178e6SNicholas Piggin } 236118178e6SNicholas Piggin #endif 237118178e6SNicholas Piggin 238118178e6SNicholas Piggin /* 239118178e6SNicholas Piggin * Do not use nmi_enter() for pseries hash guest taking a real-mode 240118178e6SNicholas Piggin * NMI because not everything it touches is within the RMA limit. 241118178e6SNicholas Piggin */ 242118178e6SNicholas Piggin if (!IS_ENABLED(CONFIG_PPC_BOOK3S_64) || 243118178e6SNicholas Piggin !firmware_has_feature(FW_FEATURE_LPAR) || 244118178e6SNicholas Piggin radix_enabled() || (mfmsr() & MSR_DR)) 245118178e6SNicholas Piggin nmi_enter(); 24625b7e6bbSNicholas Piggin } 24725b7e6bbSNicholas Piggin 24825b7e6bbSNicholas Piggin static inline void interrupt_nmi_exit_prepare(struct pt_regs *regs, struct interrupt_nmi_state *state) 24925b7e6bbSNicholas Piggin { 250118178e6SNicholas Piggin if (!IS_ENABLED(CONFIG_PPC_BOOK3S_64) || 251118178e6SNicholas Piggin !firmware_has_feature(FW_FEATURE_LPAR) || 252118178e6SNicholas Piggin radix_enabled() || (mfmsr() & MSR_DR)) 253118178e6SNicholas Piggin nmi_exit(); 254118178e6SNicholas Piggin 25598db179aSNicholas Piggin /* 25698db179aSNicholas Piggin * nmi does not call nap_adjust_return because nmi should not create 25798db179aSNicholas Piggin * new work to do (must use irq_work for that). 25898db179aSNicholas Piggin */ 25998db179aSNicholas Piggin 260118178e6SNicholas Piggin #ifdef CONFIG_PPC64 2613db8aa10SNicholas Piggin if (nmi_disables_ftrace(regs)) 262118178e6SNicholas Piggin this_cpu_set_ftrace_enabled(state->ftrace_enabled); 2636ecbb582SNicholas Piggin 2646ecbb582SNicholas Piggin /* Check we didn't change the pending interrupt mask. */ 2656ecbb582SNicholas Piggin WARN_ON_ONCE((state->irq_happened | PACA_IRQ_HARD_DIS) != local_paca->irq_happened); 2666ecbb582SNicholas Piggin local_paca->irq_happened = state->irq_happened; 2676ecbb582SNicholas Piggin local_paca->irq_soft_mask = state->irq_soft_mask; 2686ecbb582SNicholas Piggin #endif 26925b7e6bbSNicholas Piggin } 27025b7e6bbSNicholas Piggin 271e4bb64c7SNicholas Piggin /* 272e4bb64c7SNicholas Piggin * Don't use noinstr here like x86, but rather add NOKPROBE_SYMBOL to each 273e4bb64c7SNicholas Piggin * function definition. The reason for this is the noinstr section is placed 274e4bb64c7SNicholas Piggin * after the main text section, i.e., very far away from the interrupt entry 275e4bb64c7SNicholas Piggin * asm. That creates problems with fitting linker stubs when building large 276e4bb64c7SNicholas Piggin * kernels. 277e4bb64c7SNicholas Piggin */ 278e4bb64c7SNicholas Piggin #define interrupt_handler __visible noinline notrace __no_kcsan __no_sanitize_address 279e4bb64c7SNicholas Piggin 2808d41fc61SNicholas Piggin /** 2818d41fc61SNicholas Piggin * DECLARE_INTERRUPT_HANDLER_RAW - Declare raw interrupt handler function 2828d41fc61SNicholas Piggin * @func: Function name of the entry point 2838d41fc61SNicholas Piggin * @returns: Returns a value back to asm caller 2848d41fc61SNicholas Piggin */ 2858d41fc61SNicholas Piggin #define DECLARE_INTERRUPT_HANDLER_RAW(func) \ 2868d41fc61SNicholas Piggin __visible long func(struct pt_regs *regs) 2878d41fc61SNicholas Piggin 2888d41fc61SNicholas Piggin /** 2898d41fc61SNicholas Piggin * DEFINE_INTERRUPT_HANDLER_RAW - Define raw interrupt handler function 2908d41fc61SNicholas Piggin * @func: Function name of the entry point 2918d41fc61SNicholas Piggin * @returns: Returns a value back to asm caller 2928d41fc61SNicholas Piggin * 2938d41fc61SNicholas Piggin * @func is called from ASM entry code. 2948d41fc61SNicholas Piggin * 2958d41fc61SNicholas Piggin * This is a plain function which does no tracing, reconciling, etc. 2968d41fc61SNicholas Piggin * The macro is written so it acts as function definition. Append the 2978d41fc61SNicholas Piggin * body with a pair of curly brackets. 2988d41fc61SNicholas Piggin * 2998d41fc61SNicholas Piggin * raw interrupt handlers must not enable or disable interrupts, or 3008d41fc61SNicholas Piggin * schedule, tracing and instrumentation (ftrace, lockdep, etc) would 3018d41fc61SNicholas Piggin * not be advisable either, although may be possible in a pinch, the 3028d41fc61SNicholas Piggin * trace will look odd at least. 3038d41fc61SNicholas Piggin * 3048d41fc61SNicholas Piggin * A raw handler may call one of the other interrupt handler functions 3058d41fc61SNicholas Piggin * to be converted into that interrupt context without these restrictions. 3068d41fc61SNicholas Piggin * 3078d41fc61SNicholas Piggin * On PPC64, _RAW handlers may return with fast_interrupt_return. 3088d41fc61SNicholas Piggin * 3098d41fc61SNicholas Piggin * Specific handlers may have additional restrictions. 3108d41fc61SNicholas Piggin */ 3118d41fc61SNicholas Piggin #define DEFINE_INTERRUPT_HANDLER_RAW(func) \ 3128d41fc61SNicholas Piggin static __always_inline long ____##func(struct pt_regs *regs); \ 3138d41fc61SNicholas Piggin \ 314e4bb64c7SNicholas Piggin interrupt_handler long func(struct pt_regs *regs) \ 3158d41fc61SNicholas Piggin { \ 3168d41fc61SNicholas Piggin long ret; \ 3178d41fc61SNicholas Piggin \ 3188d41fc61SNicholas Piggin ret = ____##func (regs); \ 3198d41fc61SNicholas Piggin \ 3208d41fc61SNicholas Piggin return ret; \ 3218d41fc61SNicholas Piggin } \ 322e4bb64c7SNicholas Piggin NOKPROBE_SYMBOL(func); \ 3238d41fc61SNicholas Piggin \ 3248d41fc61SNicholas Piggin static __always_inline long ____##func(struct pt_regs *regs) 3258d41fc61SNicholas Piggin 3268d41fc61SNicholas Piggin /** 3278d41fc61SNicholas Piggin * DECLARE_INTERRUPT_HANDLER - Declare synchronous interrupt handler function 3288d41fc61SNicholas Piggin * @func: Function name of the entry point 3298d41fc61SNicholas Piggin */ 3308d41fc61SNicholas Piggin #define DECLARE_INTERRUPT_HANDLER(func) \ 3318d41fc61SNicholas Piggin __visible void func(struct pt_regs *regs) 3328d41fc61SNicholas Piggin 3338d41fc61SNicholas Piggin /** 3348d41fc61SNicholas Piggin * DEFINE_INTERRUPT_HANDLER - Define synchronous interrupt handler function 3358d41fc61SNicholas Piggin * @func: Function name of the entry point 3368d41fc61SNicholas Piggin * 3378d41fc61SNicholas Piggin * @func is called from ASM entry code. 3388d41fc61SNicholas Piggin * 3398d41fc61SNicholas Piggin * The macro is written so it acts as function definition. Append the 3408d41fc61SNicholas Piggin * body with a pair of curly brackets. 3418d41fc61SNicholas Piggin */ 3428d41fc61SNicholas Piggin #define DEFINE_INTERRUPT_HANDLER(func) \ 3438d41fc61SNicholas Piggin static __always_inline void ____##func(struct pt_regs *regs); \ 3448d41fc61SNicholas Piggin \ 345e4bb64c7SNicholas Piggin interrupt_handler void func(struct pt_regs *regs) \ 3468d41fc61SNicholas Piggin { \ 34725b7e6bbSNicholas Piggin struct interrupt_state state; \ 34825b7e6bbSNicholas Piggin \ 34925b7e6bbSNicholas Piggin interrupt_enter_prepare(regs, &state); \ 35025b7e6bbSNicholas Piggin \ 3518d41fc61SNicholas Piggin ____##func (regs); \ 35225b7e6bbSNicholas Piggin \ 35325b7e6bbSNicholas Piggin interrupt_exit_prepare(regs, &state); \ 3548d41fc61SNicholas Piggin } \ 355e4bb64c7SNicholas Piggin NOKPROBE_SYMBOL(func); \ 3568d41fc61SNicholas Piggin \ 3578d41fc61SNicholas Piggin static __always_inline void ____##func(struct pt_regs *regs) 3588d41fc61SNicholas Piggin 3598d41fc61SNicholas Piggin /** 3608d41fc61SNicholas Piggin * DECLARE_INTERRUPT_HANDLER_RET - Declare synchronous interrupt handler function 3618d41fc61SNicholas Piggin * @func: Function name of the entry point 3628d41fc61SNicholas Piggin * @returns: Returns a value back to asm caller 3638d41fc61SNicholas Piggin */ 3648d41fc61SNicholas Piggin #define DECLARE_INTERRUPT_HANDLER_RET(func) \ 3658d41fc61SNicholas Piggin __visible long func(struct pt_regs *regs) 3668d41fc61SNicholas Piggin 3678d41fc61SNicholas Piggin /** 3688d41fc61SNicholas Piggin * DEFINE_INTERRUPT_HANDLER_RET - Define synchronous interrupt handler function 3698d41fc61SNicholas Piggin * @func: Function name of the entry point 3708d41fc61SNicholas Piggin * @returns: Returns a value back to asm caller 3718d41fc61SNicholas Piggin * 3728d41fc61SNicholas Piggin * @func is called from ASM entry code. 3738d41fc61SNicholas Piggin * 3748d41fc61SNicholas Piggin * The macro is written so it acts as function definition. Append the 3758d41fc61SNicholas Piggin * body with a pair of curly brackets. 3768d41fc61SNicholas Piggin */ 3778d41fc61SNicholas Piggin #define DEFINE_INTERRUPT_HANDLER_RET(func) \ 3788d41fc61SNicholas Piggin static __always_inline long ____##func(struct pt_regs *regs); \ 3798d41fc61SNicholas Piggin \ 380e4bb64c7SNicholas Piggin interrupt_handler long func(struct pt_regs *regs) \ 3818d41fc61SNicholas Piggin { \ 38225b7e6bbSNicholas Piggin struct interrupt_state state; \ 3838d41fc61SNicholas Piggin long ret; \ 3848d41fc61SNicholas Piggin \ 38525b7e6bbSNicholas Piggin interrupt_enter_prepare(regs, &state); \ 38625b7e6bbSNicholas Piggin \ 3878d41fc61SNicholas Piggin ret = ____##func (regs); \ 3888d41fc61SNicholas Piggin \ 38925b7e6bbSNicholas Piggin interrupt_exit_prepare(regs, &state); \ 39025b7e6bbSNicholas Piggin \ 3918d41fc61SNicholas Piggin return ret; \ 3928d41fc61SNicholas Piggin } \ 393e4bb64c7SNicholas Piggin NOKPROBE_SYMBOL(func); \ 3948d41fc61SNicholas Piggin \ 3958d41fc61SNicholas Piggin static __always_inline long ____##func(struct pt_regs *regs) 3968d41fc61SNicholas Piggin 3978d41fc61SNicholas Piggin /** 3988d41fc61SNicholas Piggin * DECLARE_INTERRUPT_HANDLER_ASYNC - Declare asynchronous interrupt handler function 3998d41fc61SNicholas Piggin * @func: Function name of the entry point 4008d41fc61SNicholas Piggin */ 4018d41fc61SNicholas Piggin #define DECLARE_INTERRUPT_HANDLER_ASYNC(func) \ 4028d41fc61SNicholas Piggin __visible void func(struct pt_regs *regs) 4038d41fc61SNicholas Piggin 4048d41fc61SNicholas Piggin /** 4058d41fc61SNicholas Piggin * DEFINE_INTERRUPT_HANDLER_ASYNC - Define asynchronous interrupt handler function 4068d41fc61SNicholas Piggin * @func: Function name of the entry point 4078d41fc61SNicholas Piggin * 4088d41fc61SNicholas Piggin * @func is called from ASM entry code. 4098d41fc61SNicholas Piggin * 4108d41fc61SNicholas Piggin * The macro is written so it acts as function definition. Append the 4118d41fc61SNicholas Piggin * body with a pair of curly brackets. 4128d41fc61SNicholas Piggin */ 4138d41fc61SNicholas Piggin #define DEFINE_INTERRUPT_HANDLER_ASYNC(func) \ 4148d41fc61SNicholas Piggin static __always_inline void ____##func(struct pt_regs *regs); \ 4158d41fc61SNicholas Piggin \ 416e4bb64c7SNicholas Piggin interrupt_handler void func(struct pt_regs *regs) \ 4178d41fc61SNicholas Piggin { \ 41825b7e6bbSNicholas Piggin struct interrupt_state state; \ 41925b7e6bbSNicholas Piggin \ 42025b7e6bbSNicholas Piggin interrupt_async_enter_prepare(regs, &state); \ 42125b7e6bbSNicholas Piggin \ 4228d41fc61SNicholas Piggin ____##func (regs); \ 42325b7e6bbSNicholas Piggin \ 42425b7e6bbSNicholas Piggin interrupt_async_exit_prepare(regs, &state); \ 4258d41fc61SNicholas Piggin } \ 426e4bb64c7SNicholas Piggin NOKPROBE_SYMBOL(func); \ 4278d41fc61SNicholas Piggin \ 4288d41fc61SNicholas Piggin static __always_inline void ____##func(struct pt_regs *regs) 4298d41fc61SNicholas Piggin 4308d41fc61SNicholas Piggin /** 4318d41fc61SNicholas Piggin * DECLARE_INTERRUPT_HANDLER_NMI - Declare NMI interrupt handler function 4328d41fc61SNicholas Piggin * @func: Function name of the entry point 4338d41fc61SNicholas Piggin * @returns: Returns a value back to asm caller 4348d41fc61SNicholas Piggin */ 4358d41fc61SNicholas Piggin #define DECLARE_INTERRUPT_HANDLER_NMI(func) \ 4368d41fc61SNicholas Piggin __visible long func(struct pt_regs *regs) 4378d41fc61SNicholas Piggin 4388d41fc61SNicholas Piggin /** 4398d41fc61SNicholas Piggin * DEFINE_INTERRUPT_HANDLER_NMI - Define NMI interrupt handler function 4408d41fc61SNicholas Piggin * @func: Function name of the entry point 4418d41fc61SNicholas Piggin * @returns: Returns a value back to asm caller 4428d41fc61SNicholas Piggin * 4438d41fc61SNicholas Piggin * @func is called from ASM entry code. 4448d41fc61SNicholas Piggin * 4458d41fc61SNicholas Piggin * The macro is written so it acts as function definition. Append the 4468d41fc61SNicholas Piggin * body with a pair of curly brackets. 4478d41fc61SNicholas Piggin */ 4488d41fc61SNicholas Piggin #define DEFINE_INTERRUPT_HANDLER_NMI(func) \ 4498d41fc61SNicholas Piggin static __always_inline long ____##func(struct pt_regs *regs); \ 4508d41fc61SNicholas Piggin \ 451e4bb64c7SNicholas Piggin interrupt_handler long func(struct pt_regs *regs) \ 4528d41fc61SNicholas Piggin { \ 45325b7e6bbSNicholas Piggin struct interrupt_nmi_state state; \ 4548d41fc61SNicholas Piggin long ret; \ 4558d41fc61SNicholas Piggin \ 45625b7e6bbSNicholas Piggin interrupt_nmi_enter_prepare(regs, &state); \ 45725b7e6bbSNicholas Piggin \ 4588d41fc61SNicholas Piggin ret = ____##func (regs); \ 4598d41fc61SNicholas Piggin \ 46025b7e6bbSNicholas Piggin interrupt_nmi_exit_prepare(regs, &state); \ 46125b7e6bbSNicholas Piggin \ 4628d41fc61SNicholas Piggin return ret; \ 4638d41fc61SNicholas Piggin } \ 464e4bb64c7SNicholas Piggin NOKPROBE_SYMBOL(func); \ 4658d41fc61SNicholas Piggin \ 4668d41fc61SNicholas Piggin static __always_inline long ____##func(struct pt_regs *regs) 4678d41fc61SNicholas Piggin 4683a96570fSNicholas Piggin 4693a96570fSNicholas Piggin /* Interrupt handlers */ 4703a96570fSNicholas Piggin /* kernel/traps.c */ 4713a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(system_reset_exception); 4723a96570fSNicholas Piggin #ifdef CONFIG_PPC_BOOK3S_64 4733a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_ASYNC(machine_check_exception); 4743a96570fSNicholas Piggin #else 4753a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(machine_check_exception); 4763a96570fSNicholas Piggin #endif 4773a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(SMIException); 4783a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(handle_hmi_exception); 4793a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(unknown_exception); 4803a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_ASYNC(unknown_async_exception); 4813db8aa10SNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(unknown_nmi_exception); 4823a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(instruction_breakpoint_exception); 4833a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(RunModeException); 4843a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(single_step_exception); 4853a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(program_check_exception); 4863a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(emulation_assist_interrupt); 4873a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(alignment_exception); 4883a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(StackOverflow); 4893a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(stack_overflow_exception); 4903a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(kernel_fp_unavailable_exception); 4913a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(altivec_unavailable_exception); 4923a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(vsx_unavailable_exception); 4933a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(facility_unavailable_exception); 4943a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(fp_unavailable_tm); 4953a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(altivec_unavailable_tm); 4963a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(vsx_unavailable_tm); 4973a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(performance_monitor_exception_nmi); 4983a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_ASYNC(performance_monitor_exception_async); 4993a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_RAW(performance_monitor_exception); 5003a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(DebugException); 5013a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(altivec_assist_exception); 5023a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(CacheLockingException); 5033a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(SPEFloatingPointException); 5043a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(SPEFloatingPointRoundException); 5053db8aa10SNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(WatchdogException); 5063a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(kernel_bad_stack); 5073a96570fSNicholas Piggin 5083a96570fSNicholas Piggin /* slb.c */ 5093a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_RAW(do_slb_fault); 5103a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(do_bad_slb_fault); 5113a96570fSNicholas Piggin 5123a96570fSNicholas Piggin /* hash_utils.c */ 5133a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_RAW(do_hash_fault); 5143a96570fSNicholas Piggin 5153a96570fSNicholas Piggin /* fault.c */ 516c45ba4f4SNicholas Piggin DECLARE_INTERRUPT_HANDLER(do_page_fault); 5173a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(do_bad_page_fault_segv); 5183a96570fSNicholas Piggin 5193a96570fSNicholas Piggin /* process.c */ 5203a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER(do_break); 5213a96570fSNicholas Piggin 5223a96570fSNicholas Piggin /* time.c */ 5233a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_ASYNC(timer_interrupt); 5243a96570fSNicholas Piggin 5253a96570fSNicholas Piggin /* mce.c */ 5263a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(machine_check_early); 5273a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_NMI(hmi_exception_realmode); 5283a96570fSNicholas Piggin 5293a96570fSNicholas Piggin DECLARE_INTERRUPT_HANDLER_ASYNC(TAUException); 5303a96570fSNicholas Piggin 531a58cbed6SChristophe Leroy void __noreturn unrecoverable_exception(struct pt_regs *regs); 5320b736881SChristophe Leroy 5333a96570fSNicholas Piggin void replay_system_reset(void); 5343a96570fSNicholas Piggin void replay_soft_interrupts(void); 5353a96570fSNicholas Piggin 536e6f8a6c8SNicholas Piggin static inline void interrupt_cond_local_irq_enable(struct pt_regs *regs) 537e6f8a6c8SNicholas Piggin { 538e6f8a6c8SNicholas Piggin if (!arch_irq_disabled_regs(regs)) 539e6f8a6c8SNicholas Piggin local_irq_enable(); 540e6f8a6c8SNicholas Piggin } 541e6f8a6c8SNicholas Piggin 5420f5eb28aSChristophe Leroy #endif /* __ASSEMBLY__ */ 5430f5eb28aSChristophe Leroy 5448d41fc61SNicholas Piggin #endif /* _ASM_POWERPC_INTERRUPT_H */ 545