1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Ultravisor related functionality 4 * 5 * Copyright 2020 IBM Corp. 6 * 7 * Authors: 8 * Janosch Frank <frankja@linux.ibm.com> 9 */ 10 #include <libcflat.h> 11 #include <bitops.h> 12 #include <alloc.h> 13 #include <alloc_page.h> 14 #include <asm/page.h> 15 #include <asm/arch_def.h> 16 17 #include <asm/facility.h> 18 #include <asm/uv.h> 19 #include <uv.h> 20 21 static struct uv_cb_qui uvcb_qui = { 22 .header.cmd = UVC_CMD_QUI, 23 .header.len = sizeof(uvcb_qui), 24 }; 25 26 bool uv_os_is_guest(void) 27 { 28 return test_facility(158) && 29 uv_query_test_call(BIT_UVC_CMD_SET_SHARED_ACCESS) && 30 uv_query_test_call(BIT_UVC_CMD_REMOVE_SHARED_ACCESS); 31 } 32 33 bool uv_os_is_host(void) 34 { 35 return test_facility(158) && uv_query_test_call(BIT_UVC_CMD_INIT_UV); 36 } 37 38 bool uv_query_test_call(unsigned int nr) 39 { 40 /* Query needs to be called first */ 41 assert(uvcb_qui.header.rc); 42 assert(nr < BITS_PER_LONG * ARRAY_SIZE(uvcb_qui.inst_calls_list)); 43 44 return test_bit_inv(nr, uvcb_qui.inst_calls_list); 45 } 46 47 int uv_setup(void) 48 { 49 if (!test_facility(158)) 50 return 0; 51 52 assert(!uv_call(0, (u64)&uvcb_qui)); 53 return 1; 54 } 55