xref: /linux/arch/s390/boot/uv.c (revision c5cf505446db70247a0beb5e70693a5f4754894d)
15abb9351SVasily Gorbik // SPDX-License-Identifier: GPL-2.0
25abb9351SVasily Gorbik #include <asm/uv.h>
35abb9351SVasily Gorbik #include <asm/facility.h>
45abb9351SVasily Gorbik #include <asm/sections.h>
55abb9351SVasily Gorbik 
6*c5cf5054SAlexander Egorenkov #include "uv.h"
7*c5cf5054SAlexander Egorenkov 
8ecdc5d84SVasily Gorbik /* will be used in arch/s390/kernel/uv.c */
9ecdc5d84SVasily Gorbik #ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST
105abb9351SVasily Gorbik int __bootdata_preserved(prot_virt_guest);
11ecdc5d84SVasily Gorbik #endif
121d6671aeSVasily Gorbik #if IS_ENABLED(CONFIG_KVM)
131d6671aeSVasily Gorbik int __bootdata_preserved(prot_virt_host);
141d6671aeSVasily Gorbik #endif
15ecdc5d84SVasily Gorbik struct uv_info __bootdata_preserved(uv_info);
165abb9351SVasily Gorbik 
175abb9351SVasily Gorbik void uv_query_info(void)
185abb9351SVasily Gorbik {
195abb9351SVasily Gorbik 	struct uv_cb_qui uvcb = {
205abb9351SVasily Gorbik 		.header.cmd = UVC_CMD_QUI,
215abb9351SVasily Gorbik 		.header.len = sizeof(uvcb)
225abb9351SVasily Gorbik 	};
235abb9351SVasily Gorbik 
245abb9351SVasily Gorbik 	if (!test_facility(158))
255abb9351SVasily Gorbik 		return;
265abb9351SVasily Gorbik 
2727dc0700SChristian Borntraeger 	/* rc==0x100 means that there is additional data we do not process */
2827dc0700SChristian Borntraeger 	if (uv_call(0, (uint64_t)&uvcb) && uvcb.header.rc != 0x100)
295abb9351SVasily Gorbik 		return;
305abb9351SVasily Gorbik 
31ecdc5d84SVasily Gorbik 	if (IS_ENABLED(CONFIG_KVM)) {
32ecdc5d84SVasily Gorbik 		memcpy(uv_info.inst_calls_list, uvcb.inst_calls_list, sizeof(uv_info.inst_calls_list));
33ecdc5d84SVasily Gorbik 		uv_info.uv_base_stor_len = uvcb.uv_base_stor_len;
34ecdc5d84SVasily Gorbik 		uv_info.guest_base_stor_len = uvcb.conf_base_phys_stor_len;
35ecdc5d84SVasily Gorbik 		uv_info.guest_virt_base_stor_len = uvcb.conf_base_virt_stor_len;
36ecdc5d84SVasily Gorbik 		uv_info.guest_virt_var_stor_len = uvcb.conf_virt_var_stor_len;
37ecdc5d84SVasily Gorbik 		uv_info.guest_cpu_stor_len = uvcb.cpu_stor_len;
38ecdc5d84SVasily Gorbik 		uv_info.max_sec_stor_addr = ALIGN(uvcb.max_guest_stor_addr, PAGE_SIZE);
39ecdc5d84SVasily Gorbik 		uv_info.max_num_sec_conf = uvcb.max_num_sec_conf;
40e82080e1SJanosch Frank 		uv_info.max_guest_cpu_id = uvcb.max_guest_cpu_id;
4185b18d7bSJanosch Frank 		uv_info.uv_feature_indications = uvcb.uv_feature_indications;
42ecdc5d84SVasily Gorbik 	}
43ecdc5d84SVasily Gorbik 
44ecdc5d84SVasily Gorbik #ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST
455abb9351SVasily Gorbik 	if (test_bit_inv(BIT_UVC_CMD_SET_SHARED_ACCESS, (unsigned long *)uvcb.inst_calls_list) &&
465abb9351SVasily Gorbik 	    test_bit_inv(BIT_UVC_CMD_REMOVE_SHARED_ACCESS, (unsigned long *)uvcb.inst_calls_list))
475abb9351SVasily Gorbik 		prot_virt_guest = 1;
48ecdc5d84SVasily Gorbik #endif
495abb9351SVasily Gorbik }
500c4f2623SVasily Gorbik 
510c4f2623SVasily Gorbik #if IS_ENABLED(CONFIG_KVM)
520c4f2623SVasily Gorbik static bool has_uv_sec_stor_limit(void)
530c4f2623SVasily Gorbik {
540c4f2623SVasily Gorbik 	/*
550c4f2623SVasily Gorbik 	 * keep these conditions in line with setup_uv()
560c4f2623SVasily Gorbik 	 */
570c4f2623SVasily Gorbik 	if (!is_prot_virt_host())
580c4f2623SVasily Gorbik 		return false;
590c4f2623SVasily Gorbik 
600c4f2623SVasily Gorbik 	if (is_prot_virt_guest())
610c4f2623SVasily Gorbik 		return false;
620c4f2623SVasily Gorbik 
630c4f2623SVasily Gorbik 	if (!test_facility(158))
640c4f2623SVasily Gorbik 		return false;
650c4f2623SVasily Gorbik 
660c4f2623SVasily Gorbik 	return !!uv_info.max_sec_stor_addr;
670c4f2623SVasily Gorbik }
680c4f2623SVasily Gorbik 
690c4f2623SVasily Gorbik void adjust_to_uv_max(unsigned long *vmax)
700c4f2623SVasily Gorbik {
710c4f2623SVasily Gorbik 	if (has_uv_sec_stor_limit())
720c4f2623SVasily Gorbik 		*vmax = min_t(unsigned long, *vmax, uv_info.max_sec_stor_addr);
730c4f2623SVasily Gorbik }
740c4f2623SVasily Gorbik #endif
75