18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Hypervisor Maintenance Interrupt (HMI) handling. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright 2015 IBM Corporation 68c2ecf20Sopenharmony_ci * Author: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#undef DEBUG 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <linux/types.h> 128c2ecf20Sopenharmony_ci#include <linux/compiler.h> 138c2ecf20Sopenharmony_ci#include <asm/paca.h> 148c2ecf20Sopenharmony_ci#include <asm/hmi.h> 158c2ecf20Sopenharmony_ci#include <asm/processor.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_civoid wait_for_subcore_guest_exit(void) 188c2ecf20Sopenharmony_ci{ 198c2ecf20Sopenharmony_ci int i; 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci /* 228c2ecf20Sopenharmony_ci * NULL bitmap pointer indicates that KVM module hasn't 238c2ecf20Sopenharmony_ci * been loaded yet and hence no guests are running. 248c2ecf20Sopenharmony_ci * If no KVM is in use, no need to co-ordinate among threads 258c2ecf20Sopenharmony_ci * as all of them will always be in host and no one is going 268c2ecf20Sopenharmony_ci * to modify TB other than the opal hmi handler. 278c2ecf20Sopenharmony_ci * Hence, just return from here. 288c2ecf20Sopenharmony_ci */ 298c2ecf20Sopenharmony_ci if (!local_paca->sibling_subcore_state) 308c2ecf20Sopenharmony_ci return; 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci for (i = 0; i < MAX_SUBCORE_PER_CORE; i++) 338c2ecf20Sopenharmony_ci while (local_paca->sibling_subcore_state->in_guest[i]) 348c2ecf20Sopenharmony_ci cpu_relax(); 358c2ecf20Sopenharmony_ci} 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_civoid wait_for_tb_resync(void) 388c2ecf20Sopenharmony_ci{ 398c2ecf20Sopenharmony_ci if (!local_paca->sibling_subcore_state) 408c2ecf20Sopenharmony_ci return; 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci while (test_bit(CORE_TB_RESYNC_REQ_BIT, 438c2ecf20Sopenharmony_ci &local_paca->sibling_subcore_state->flags)) 448c2ecf20Sopenharmony_ci cpu_relax(); 458c2ecf20Sopenharmony_ci} 46