xref: /openbmc/linux/arch/powerpc/kvm/book3s_hv_hmi.c (revision 92ab45c5)
1 /*
2  * Hypervisor Maintenance Interrupt (HMI) handling.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.
16  *
17  * Copyright 2015 IBM Corporation
18  * Author: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
19  */
20 
21 #undef DEBUG
22 
23 #include <linux/types.h>
24 #include <linux/compiler.h>
25 #include <asm/paca.h>
26 #include <asm/hmi.h>
27 #include <asm/processor.h>
28 
29 void wait_for_subcore_guest_exit(void)
30 {
31 	int i;
32 
33 	/*
34 	 * NULL bitmap pointer indicates that KVM module hasn't
35 	 * been loaded yet and hence no guests are running.
36 	 * If no KVM is in use, no need to co-ordinate among threads
37 	 * as all of them will always be in host and no one is going
38 	 * to modify TB other than the opal hmi handler.
39 	 * Hence, just return from here.
40 	 */
41 	if (!local_paca->sibling_subcore_state)
42 		return;
43 
44 	for (i = 0; i < MAX_SUBCORE_PER_CORE; i++)
45 		while (local_paca->sibling_subcore_state->in_guest[i])
46 			cpu_relax();
47 }
48 
49 void wait_for_tb_resync(void)
50 {
51 	if (!local_paca->sibling_subcore_state)
52 		return;
53 
54 	while (test_bit(CORE_TB_RESYNC_REQ_BIT,
55 				&local_paca->sibling_subcore_state->flags))
56 		cpu_relax();
57 }
58