1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
4  */
5 #ifndef _ASM_POWERPC_RUNLATCH_H
6 #define _ASM_POWERPC_RUNLATCH_H
7 
8 #ifdef CONFIG_PPC64
9 
10 extern void __ppc64_runlatch_on(void);
11 extern void __ppc64_runlatch_off(void);
12 
13 /*
14  * We manually hard enable-disable, this is called
15  * in the idle loop and we don't want to mess up
16  * with soft-disable/enable & interrupt replay.
17  */
18 #define ppc64_runlatch_off()					\
19 	do {							\
20 		if (cpu_has_feature(CPU_FTR_CTRL) &&		\
21 		    test_thread_local_flags(_TLF_RUNLATCH)) {	\
22 			unsigned long msr = mfmsr();		\
23 			__hard_irq_disable();			\
24 			__ppc64_runlatch_off();			\
25 			if (msr & MSR_EE)			\
26 				__hard_irq_enable();		\
27 		}      						\
28 	} while (0)
29 
30 #define ppc64_runlatch_on()					\
31 	do {							\
32 		if (cpu_has_feature(CPU_FTR_CTRL) &&		\
33 		    !test_thread_local_flags(_TLF_RUNLATCH)) {	\
34 			unsigned long msr = mfmsr();		\
35 			__hard_irq_disable();			\
36 			__ppc64_runlatch_on();			\
37 			if (msr & MSR_EE)			\
38 				__hard_irq_enable();		\
39 		}      						\
40 	} while (0)
41 #else
42 #define ppc64_runlatch_on()
43 #define ppc64_runlatch_off()
44 #endif /* CONFIG_PPC64 */
45 
46 #endif /* _ASM_POWERPC_RUNLATCH_H */
47