xref: /OK3568_Linux_fs/kernel/arch/powerpc/kvm/book3s_hv_hmi.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-or-later
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Hypervisor Maintenance Interrupt (HMI) handling.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright 2015 IBM Corporation
6*4882a593Smuzhiyun  * Author: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #undef DEBUG
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #include <linux/types.h>
12*4882a593Smuzhiyun #include <linux/compiler.h>
13*4882a593Smuzhiyun #include <asm/paca.h>
14*4882a593Smuzhiyun #include <asm/hmi.h>
15*4882a593Smuzhiyun #include <asm/processor.h>
16*4882a593Smuzhiyun 
wait_for_subcore_guest_exit(void)17*4882a593Smuzhiyun void wait_for_subcore_guest_exit(void)
18*4882a593Smuzhiyun {
19*4882a593Smuzhiyun 	int i;
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun 	/*
22*4882a593Smuzhiyun 	 * NULL bitmap pointer indicates that KVM module hasn't
23*4882a593Smuzhiyun 	 * been loaded yet and hence no guests are running.
24*4882a593Smuzhiyun 	 * If no KVM is in use, no need to co-ordinate among threads
25*4882a593Smuzhiyun 	 * as all of them will always be in host and no one is going
26*4882a593Smuzhiyun 	 * to modify TB other than the opal hmi handler.
27*4882a593Smuzhiyun 	 * Hence, just return from here.
28*4882a593Smuzhiyun 	 */
29*4882a593Smuzhiyun 	if (!local_paca->sibling_subcore_state)
30*4882a593Smuzhiyun 		return;
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun 	for (i = 0; i < MAX_SUBCORE_PER_CORE; i++)
33*4882a593Smuzhiyun 		while (local_paca->sibling_subcore_state->in_guest[i])
34*4882a593Smuzhiyun 			cpu_relax();
35*4882a593Smuzhiyun }
36*4882a593Smuzhiyun 
wait_for_tb_resync(void)37*4882a593Smuzhiyun void wait_for_tb_resync(void)
38*4882a593Smuzhiyun {
39*4882a593Smuzhiyun 	if (!local_paca->sibling_subcore_state)
40*4882a593Smuzhiyun 		return;
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun 	while (test_bit(CORE_TB_RESYNC_REQ_BIT,
43*4882a593Smuzhiyun 				&local_paca->sibling_subcore_state->flags))
44*4882a593Smuzhiyun 		cpu_relax();
45*4882a593Smuzhiyun }
46