12874c5fdSThomas Gleixner/* SPDX-License-Identifier: GPL-2.0-or-later */
22e1ae9c0SLiu Yu-B13201/*
32e1ae9c0SLiu Yu-B13201 * Copyright (C) 2012 Freescale Semiconductor, Inc.
42e1ae9c0SLiu Yu-B13201 */
52e1ae9c0SLiu Yu-B13201
6*39326182SMasahiro Yamada#include <linux/export.h>
72e1ae9c0SLiu Yu-B13201#include <linux/threads.h>
82f979de8SLiu Yu-B13201#include <asm/epapr_hcalls.h>
92e1ae9c0SLiu Yu-B13201#include <asm/reg.h>
102e1ae9c0SLiu Yu-B13201#include <asm/page.h>
112e1ae9c0SLiu Yu-B13201#include <asm/cputable.h>
122e1ae9c0SLiu Yu-B13201#include <asm/thread_info.h>
132e1ae9c0SLiu Yu-B13201#include <asm/ppc_asm.h>
142f979de8SLiu Yu-B13201#include <asm/asm-compat.h>
152e1ae9c0SLiu Yu-B13201#include <asm/asm-offsets.h>
162e1ae9c0SLiu Yu-B13201
17f070986aSStuart Yoder#ifndef CONFIG_PPC64
182f979de8SLiu Yu-B13201/* epapr_ev_idle() was derived from e500_idle() */
192f979de8SLiu Yu-B13201_GLOBAL(epapr_ev_idle)
20f7354ccaSChristophe Leroy	PPC_LL	r4, TI_LOCAL_FLAGS(r2)	/* set napping bit */
212f979de8SLiu Yu-B13201	ori	r4, r4,_TLF_NAPPING	/* so when we take an exception */
22f7354ccaSChristophe Leroy	PPC_STL	r4, TI_LOCAL_FLAGS(r2)	/* it will return to our caller */
232f979de8SLiu Yu-B13201
243c2ce491SChristophe Leroy#ifdef CONFIG_BOOKE_OR_40x
252f979de8SLiu Yu-B13201	wrteei	1
263c2ce491SChristophe Leroy#else
273c2ce491SChristophe Leroy	mfmsr	r4
283c2ce491SChristophe Leroy	ori	r4, r4, MSR_EE
293c2ce491SChristophe Leroy	mtmsr	r4
303c2ce491SChristophe Leroy#endif
312f979de8SLiu Yu-B13201
322f979de8SLiu Yu-B13201idle_loop:
332f979de8SLiu Yu-B13201	LOAD_REG_IMMEDIATE(r11, EV_HCALL_TOKEN(EV_IDLE))
342f979de8SLiu Yu-B13201
352f979de8SLiu Yu-B13201.global epapr_ev_idle_start
362f979de8SLiu Yu-B13201epapr_ev_idle_start:
372f979de8SLiu Yu-B13201	li	r3, -1
382f979de8SLiu Yu-B13201	nop
392f979de8SLiu Yu-B13201	nop
402f979de8SLiu Yu-B13201	nop
412f979de8SLiu Yu-B13201
422f979de8SLiu Yu-B13201	/*
432f979de8SLiu Yu-B13201	 * Guard against spurious wakeups from a hypervisor --
442f979de8SLiu Yu-B13201	 * only interrupt will cause us to return to LR due to
452f979de8SLiu Yu-B13201	 * _TLF_NAPPING.
462f979de8SLiu Yu-B13201	 */
472f979de8SLiu Yu-B13201	b	idle_loop
48f070986aSStuart Yoder#endif
492f979de8SLiu Yu-B13201
502e1ae9c0SLiu Yu-B13201/* Hypercall entry point. Will be patched with device tree instructions. */
512e1ae9c0SLiu Yu-B13201.global epapr_hypercall_start
522e1ae9c0SLiu Yu-B13201epapr_hypercall_start:
532e1ae9c0SLiu Yu-B13201	li	r3, -1
542e1ae9c0SLiu Yu-B13201	nop
552e1ae9c0SLiu Yu-B13201	nop
562e1ae9c0SLiu Yu-B13201	nop
572e1ae9c0SLiu Yu-B13201	blr
589445aa1aSAl ViroEXPORT_SYMBOL(epapr_hypercall_start)
59