18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci#ifndef _ASM_POWERPC_RUNLATCH_H
68c2ecf20Sopenharmony_ci#define _ASM_POWERPC_RUNLATCH_H
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC64
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ciextern void __ppc64_runlatch_on(void);
118c2ecf20Sopenharmony_ciextern void __ppc64_runlatch_off(void);
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/*
148c2ecf20Sopenharmony_ci * We manually hard enable-disable, this is called
158c2ecf20Sopenharmony_ci * in the idle loop and we don't want to mess up
168c2ecf20Sopenharmony_ci * with soft-disable/enable & interrupt replay.
178c2ecf20Sopenharmony_ci */
188c2ecf20Sopenharmony_ci#define ppc64_runlatch_off()					\
198c2ecf20Sopenharmony_ci	do {							\
208c2ecf20Sopenharmony_ci		if (cpu_has_feature(CPU_FTR_CTRL) &&		\
218c2ecf20Sopenharmony_ci		    test_thread_local_flags(_TLF_RUNLATCH)) {	\
228c2ecf20Sopenharmony_ci			unsigned long msr = mfmsr();		\
238c2ecf20Sopenharmony_ci			__hard_irq_disable();			\
248c2ecf20Sopenharmony_ci			__ppc64_runlatch_off();			\
258c2ecf20Sopenharmony_ci			if (msr & MSR_EE)			\
268c2ecf20Sopenharmony_ci				__hard_irq_enable();		\
278c2ecf20Sopenharmony_ci		}      						\
288c2ecf20Sopenharmony_ci	} while (0)
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#define ppc64_runlatch_on()					\
318c2ecf20Sopenharmony_ci	do {							\
328c2ecf20Sopenharmony_ci		if (cpu_has_feature(CPU_FTR_CTRL) &&		\
338c2ecf20Sopenharmony_ci		    !test_thread_local_flags(_TLF_RUNLATCH)) {	\
348c2ecf20Sopenharmony_ci			unsigned long msr = mfmsr();		\
358c2ecf20Sopenharmony_ci			__hard_irq_disable();			\
368c2ecf20Sopenharmony_ci			__ppc64_runlatch_on();			\
378c2ecf20Sopenharmony_ci			if (msr & MSR_EE)			\
388c2ecf20Sopenharmony_ci				__hard_irq_enable();		\
398c2ecf20Sopenharmony_ci		}      						\
408c2ecf20Sopenharmony_ci	} while (0)
418c2ecf20Sopenharmony_ci#else
428c2ecf20Sopenharmony_ci#define ppc64_runlatch_on()
438c2ecf20Sopenharmony_ci#define ppc64_runlatch_off()
448c2ecf20Sopenharmony_ci#endif /* CONFIG_PPC64 */
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#endif /* _ASM_POWERPC_RUNLATCH_H */
47