18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Ultravisor Interfaces
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright IBM Corp. 2019
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Author(s):
88c2ecf20Sopenharmony_ci *	Vasily Gorbik <gor@linux.ibm.com>
98c2ecf20Sopenharmony_ci *	Janosch Frank <frankja@linux.ibm.com>
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci#ifndef _ASM_S390_UV_H
128c2ecf20Sopenharmony_ci#define _ASM_S390_UV_H
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/types.h>
158c2ecf20Sopenharmony_ci#include <linux/errno.h>
168c2ecf20Sopenharmony_ci#include <linux/bug.h>
178c2ecf20Sopenharmony_ci#include <linux/sched.h>
188c2ecf20Sopenharmony_ci#include <asm/page.h>
198c2ecf20Sopenharmony_ci#include <asm/gmap.h>
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define UVC_RC_EXECUTED		0x0001
228c2ecf20Sopenharmony_ci#define UVC_RC_INV_CMD		0x0002
238c2ecf20Sopenharmony_ci#define UVC_RC_INV_STATE	0x0003
248c2ecf20Sopenharmony_ci#define UVC_RC_INV_LEN		0x0005
258c2ecf20Sopenharmony_ci#define UVC_RC_NO_RESUME	0x0007
268c2ecf20Sopenharmony_ci#define UVC_RC_NEED_DESTROY	0x8000
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define UVC_CMD_QUI			0x0001
298c2ecf20Sopenharmony_ci#define UVC_CMD_INIT_UV			0x000f
308c2ecf20Sopenharmony_ci#define UVC_CMD_CREATE_SEC_CONF		0x0100
318c2ecf20Sopenharmony_ci#define UVC_CMD_DESTROY_SEC_CONF	0x0101
328c2ecf20Sopenharmony_ci#define UVC_CMD_CREATE_SEC_CPU		0x0120
338c2ecf20Sopenharmony_ci#define UVC_CMD_DESTROY_SEC_CPU		0x0121
348c2ecf20Sopenharmony_ci#define UVC_CMD_CONV_TO_SEC_STOR	0x0200
358c2ecf20Sopenharmony_ci#define UVC_CMD_CONV_FROM_SEC_STOR	0x0201
368c2ecf20Sopenharmony_ci#define UVC_CMD_DESTR_SEC_STOR		0x0202
378c2ecf20Sopenharmony_ci#define UVC_CMD_SET_SEC_CONF_PARAMS	0x0300
388c2ecf20Sopenharmony_ci#define UVC_CMD_UNPACK_IMG		0x0301
398c2ecf20Sopenharmony_ci#define UVC_CMD_VERIFY_IMG		0x0302
408c2ecf20Sopenharmony_ci#define UVC_CMD_CPU_RESET		0x0310
418c2ecf20Sopenharmony_ci#define UVC_CMD_CPU_RESET_INITIAL	0x0311
428c2ecf20Sopenharmony_ci#define UVC_CMD_PREPARE_RESET		0x0320
438c2ecf20Sopenharmony_ci#define UVC_CMD_CPU_RESET_CLEAR		0x0321
448c2ecf20Sopenharmony_ci#define UVC_CMD_CPU_SET_STATE		0x0330
458c2ecf20Sopenharmony_ci#define UVC_CMD_SET_UNSHARE_ALL		0x0340
468c2ecf20Sopenharmony_ci#define UVC_CMD_PIN_PAGE_SHARED		0x0341
478c2ecf20Sopenharmony_ci#define UVC_CMD_UNPIN_PAGE_SHARED	0x0342
488c2ecf20Sopenharmony_ci#define UVC_CMD_SET_SHARED_ACCESS	0x1000
498c2ecf20Sopenharmony_ci#define UVC_CMD_REMOVE_SHARED_ACCESS	0x1001
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci/* Bits in installed uv calls */
528c2ecf20Sopenharmony_cienum uv_cmds_inst {
538c2ecf20Sopenharmony_ci	BIT_UVC_CMD_QUI = 0,
548c2ecf20Sopenharmony_ci	BIT_UVC_CMD_INIT_UV = 1,
558c2ecf20Sopenharmony_ci	BIT_UVC_CMD_CREATE_SEC_CONF = 2,
568c2ecf20Sopenharmony_ci	BIT_UVC_CMD_DESTROY_SEC_CONF = 3,
578c2ecf20Sopenharmony_ci	BIT_UVC_CMD_CREATE_SEC_CPU = 4,
588c2ecf20Sopenharmony_ci	BIT_UVC_CMD_DESTROY_SEC_CPU = 5,
598c2ecf20Sopenharmony_ci	BIT_UVC_CMD_CONV_TO_SEC_STOR = 6,
608c2ecf20Sopenharmony_ci	BIT_UVC_CMD_CONV_FROM_SEC_STOR = 7,
618c2ecf20Sopenharmony_ci	BIT_UVC_CMD_SET_SHARED_ACCESS = 8,
628c2ecf20Sopenharmony_ci	BIT_UVC_CMD_REMOVE_SHARED_ACCESS = 9,
638c2ecf20Sopenharmony_ci	BIT_UVC_CMD_SET_SEC_PARMS = 11,
648c2ecf20Sopenharmony_ci	BIT_UVC_CMD_UNPACK_IMG = 13,
658c2ecf20Sopenharmony_ci	BIT_UVC_CMD_VERIFY_IMG = 14,
668c2ecf20Sopenharmony_ci	BIT_UVC_CMD_CPU_RESET = 15,
678c2ecf20Sopenharmony_ci	BIT_UVC_CMD_CPU_RESET_INITIAL = 16,
688c2ecf20Sopenharmony_ci	BIT_UVC_CMD_CPU_SET_STATE = 17,
698c2ecf20Sopenharmony_ci	BIT_UVC_CMD_PREPARE_RESET = 18,
708c2ecf20Sopenharmony_ci	BIT_UVC_CMD_CPU_PERFORM_CLEAR_RESET = 19,
718c2ecf20Sopenharmony_ci	BIT_UVC_CMD_UNSHARE_ALL = 20,
728c2ecf20Sopenharmony_ci	BIT_UVC_CMD_PIN_PAGE_SHARED = 21,
738c2ecf20Sopenharmony_ci	BIT_UVC_CMD_UNPIN_PAGE_SHARED = 22,
748c2ecf20Sopenharmony_ci};
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_cienum uv_feat_ind {
778c2ecf20Sopenharmony_ci	BIT_UV_FEAT_MISC = 0,
788c2ecf20Sopenharmony_ci};
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_cistruct uv_cb_header {
818c2ecf20Sopenharmony_ci	u16 len;
828c2ecf20Sopenharmony_ci	u16 cmd;	/* Command Code */
838c2ecf20Sopenharmony_ci	u16 rc;		/* Response Code */
848c2ecf20Sopenharmony_ci	u16 rrc;	/* Return Reason Code */
858c2ecf20Sopenharmony_ci} __packed __aligned(8);
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci/* Query Ultravisor Information */
888c2ecf20Sopenharmony_cistruct uv_cb_qui {
898c2ecf20Sopenharmony_ci	struct uv_cb_header header;
908c2ecf20Sopenharmony_ci	u64 reserved08;
918c2ecf20Sopenharmony_ci	u64 inst_calls_list[4];
928c2ecf20Sopenharmony_ci	u64 reserved30[2];
938c2ecf20Sopenharmony_ci	u64 uv_base_stor_len;
948c2ecf20Sopenharmony_ci	u64 reserved48;
958c2ecf20Sopenharmony_ci	u64 conf_base_phys_stor_len;
968c2ecf20Sopenharmony_ci	u64 conf_base_virt_stor_len;
978c2ecf20Sopenharmony_ci	u64 conf_virt_var_stor_len;
988c2ecf20Sopenharmony_ci	u64 cpu_stor_len;
998c2ecf20Sopenharmony_ci	u32 reserved70[3];
1008c2ecf20Sopenharmony_ci	u32 max_num_sec_conf;
1018c2ecf20Sopenharmony_ci	u64 max_guest_stor_addr;
1028c2ecf20Sopenharmony_ci	u8  reserved88[158 - 136];
1038c2ecf20Sopenharmony_ci	u16 max_guest_cpu_id;
1048c2ecf20Sopenharmony_ci	u64 uv_feature_indications;
1058c2ecf20Sopenharmony_ci	u8  reserveda0[200 - 168];
1068c2ecf20Sopenharmony_ci} __packed __aligned(8);
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci/* Initialize Ultravisor */
1098c2ecf20Sopenharmony_cistruct uv_cb_init {
1108c2ecf20Sopenharmony_ci	struct uv_cb_header header;
1118c2ecf20Sopenharmony_ci	u64 reserved08[2];
1128c2ecf20Sopenharmony_ci	u64 stor_origin;
1138c2ecf20Sopenharmony_ci	u64 stor_len;
1148c2ecf20Sopenharmony_ci	u64 reserved28[4];
1158c2ecf20Sopenharmony_ci} __packed __aligned(8);
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci/* Create Guest Configuration */
1188c2ecf20Sopenharmony_cistruct uv_cb_cgc {
1198c2ecf20Sopenharmony_ci	struct uv_cb_header header;
1208c2ecf20Sopenharmony_ci	u64 reserved08[2];
1218c2ecf20Sopenharmony_ci	u64 guest_handle;
1228c2ecf20Sopenharmony_ci	u64 conf_base_stor_origin;
1238c2ecf20Sopenharmony_ci	u64 conf_virt_stor_origin;
1248c2ecf20Sopenharmony_ci	u64 reserved30;
1258c2ecf20Sopenharmony_ci	u64 guest_stor_origin;
1268c2ecf20Sopenharmony_ci	u64 guest_stor_len;
1278c2ecf20Sopenharmony_ci	u64 guest_sca;
1288c2ecf20Sopenharmony_ci	u64 guest_asce;
1298c2ecf20Sopenharmony_ci	u64 reserved58[5];
1308c2ecf20Sopenharmony_ci} __packed __aligned(8);
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci/* Create Secure CPU */
1338c2ecf20Sopenharmony_cistruct uv_cb_csc {
1348c2ecf20Sopenharmony_ci	struct uv_cb_header header;
1358c2ecf20Sopenharmony_ci	u64 reserved08[2];
1368c2ecf20Sopenharmony_ci	u64 cpu_handle;
1378c2ecf20Sopenharmony_ci	u64 guest_handle;
1388c2ecf20Sopenharmony_ci	u64 stor_origin;
1398c2ecf20Sopenharmony_ci	u8  reserved30[6];
1408c2ecf20Sopenharmony_ci	u16 num;
1418c2ecf20Sopenharmony_ci	u64 state_origin;
1428c2ecf20Sopenharmony_ci	u64 reserved40[4];
1438c2ecf20Sopenharmony_ci} __packed __aligned(8);
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci/* Convert to Secure */
1468c2ecf20Sopenharmony_cistruct uv_cb_cts {
1478c2ecf20Sopenharmony_ci	struct uv_cb_header header;
1488c2ecf20Sopenharmony_ci	u64 reserved08[2];
1498c2ecf20Sopenharmony_ci	u64 guest_handle;
1508c2ecf20Sopenharmony_ci	u64 gaddr;
1518c2ecf20Sopenharmony_ci} __packed __aligned(8);
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci/* Convert from Secure / Pin Page Shared */
1548c2ecf20Sopenharmony_cistruct uv_cb_cfs {
1558c2ecf20Sopenharmony_ci	struct uv_cb_header header;
1568c2ecf20Sopenharmony_ci	u64 reserved08[2];
1578c2ecf20Sopenharmony_ci	u64 paddr;
1588c2ecf20Sopenharmony_ci} __packed __aligned(8);
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci/* Set Secure Config Parameter */
1618c2ecf20Sopenharmony_cistruct uv_cb_ssc {
1628c2ecf20Sopenharmony_ci	struct uv_cb_header header;
1638c2ecf20Sopenharmony_ci	u64 reserved08[2];
1648c2ecf20Sopenharmony_ci	u64 guest_handle;
1658c2ecf20Sopenharmony_ci	u64 sec_header_origin;
1668c2ecf20Sopenharmony_ci	u32 sec_header_len;
1678c2ecf20Sopenharmony_ci	u32 reserved2c;
1688c2ecf20Sopenharmony_ci	u64 reserved30[4];
1698c2ecf20Sopenharmony_ci} __packed __aligned(8);
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci/* Unpack */
1728c2ecf20Sopenharmony_cistruct uv_cb_unp {
1738c2ecf20Sopenharmony_ci	struct uv_cb_header header;
1748c2ecf20Sopenharmony_ci	u64 reserved08[2];
1758c2ecf20Sopenharmony_ci	u64 guest_handle;
1768c2ecf20Sopenharmony_ci	u64 gaddr;
1778c2ecf20Sopenharmony_ci	u64 tweak[2];
1788c2ecf20Sopenharmony_ci	u64 reserved38[3];
1798c2ecf20Sopenharmony_ci} __packed __aligned(8);
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci#define PV_CPU_STATE_OPR	1
1828c2ecf20Sopenharmony_ci#define PV_CPU_STATE_STP	2
1838c2ecf20Sopenharmony_ci#define PV_CPU_STATE_CHKSTP	3
1848c2ecf20Sopenharmony_ci#define PV_CPU_STATE_OPR_LOAD	5
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_cistruct uv_cb_cpu_set_state {
1878c2ecf20Sopenharmony_ci	struct uv_cb_header header;
1888c2ecf20Sopenharmony_ci	u64 reserved08[2];
1898c2ecf20Sopenharmony_ci	u64 cpu_handle;
1908c2ecf20Sopenharmony_ci	u8  reserved20[7];
1918c2ecf20Sopenharmony_ci	u8  state;
1928c2ecf20Sopenharmony_ci	u64 reserved28[5];
1938c2ecf20Sopenharmony_ci};
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci/*
1968c2ecf20Sopenharmony_ci * A common UV call struct for calls that take no payload
1978c2ecf20Sopenharmony_ci * Examples:
1988c2ecf20Sopenharmony_ci * Destroy cpu/config
1998c2ecf20Sopenharmony_ci * Verify
2008c2ecf20Sopenharmony_ci */
2018c2ecf20Sopenharmony_cistruct uv_cb_nodata {
2028c2ecf20Sopenharmony_ci	struct uv_cb_header header;
2038c2ecf20Sopenharmony_ci	u64 reserved08[2];
2048c2ecf20Sopenharmony_ci	u64 handle;
2058c2ecf20Sopenharmony_ci	u64 reserved20[4];
2068c2ecf20Sopenharmony_ci} __packed __aligned(8);
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci/* Set Shared Access */
2098c2ecf20Sopenharmony_cistruct uv_cb_share {
2108c2ecf20Sopenharmony_ci	struct uv_cb_header header;
2118c2ecf20Sopenharmony_ci	u64 reserved08[3];
2128c2ecf20Sopenharmony_ci	u64 paddr;
2138c2ecf20Sopenharmony_ci	u64 reserved28;
2148c2ecf20Sopenharmony_ci} __packed __aligned(8);
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_cistatic inline int __uv_call(unsigned long r1, unsigned long r2)
2178c2ecf20Sopenharmony_ci{
2188c2ecf20Sopenharmony_ci	int cc;
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ci	asm volatile(
2218c2ecf20Sopenharmony_ci		"	.insn rrf,0xB9A40000,%[r1],%[r2],0,0\n"
2228c2ecf20Sopenharmony_ci		"	ipm	%[cc]\n"
2238c2ecf20Sopenharmony_ci		"	srl	%[cc],28\n"
2248c2ecf20Sopenharmony_ci		: [cc] "=d" (cc)
2258c2ecf20Sopenharmony_ci		: [r1] "a" (r1), [r2] "a" (r2)
2268c2ecf20Sopenharmony_ci		: "memory", "cc");
2278c2ecf20Sopenharmony_ci	return cc;
2288c2ecf20Sopenharmony_ci}
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_cistatic inline int uv_call(unsigned long r1, unsigned long r2)
2318c2ecf20Sopenharmony_ci{
2328c2ecf20Sopenharmony_ci	int cc;
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci	do {
2358c2ecf20Sopenharmony_ci		cc = __uv_call(r1, r2);
2368c2ecf20Sopenharmony_ci	} while (cc > 1);
2378c2ecf20Sopenharmony_ci	return cc;
2388c2ecf20Sopenharmony_ci}
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci/* Low level uv_call that avoids stalls for long running busy conditions  */
2418c2ecf20Sopenharmony_cistatic inline int uv_call_sched(unsigned long r1, unsigned long r2)
2428c2ecf20Sopenharmony_ci{
2438c2ecf20Sopenharmony_ci	int cc;
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_ci	do {
2468c2ecf20Sopenharmony_ci		cc = __uv_call(r1, r2);
2478c2ecf20Sopenharmony_ci		cond_resched();
2488c2ecf20Sopenharmony_ci	} while (cc > 1);
2498c2ecf20Sopenharmony_ci	return cc;
2508c2ecf20Sopenharmony_ci}
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci/*
2538c2ecf20Sopenharmony_ci * special variant of uv_call that only transports the cpu or guest
2548c2ecf20Sopenharmony_ci * handle and the command, like destroy or verify.
2558c2ecf20Sopenharmony_ci */
2568c2ecf20Sopenharmony_cistatic inline int uv_cmd_nodata(u64 handle, u16 cmd, u16 *rc, u16 *rrc)
2578c2ecf20Sopenharmony_ci{
2588c2ecf20Sopenharmony_ci	struct uv_cb_nodata uvcb = {
2598c2ecf20Sopenharmony_ci		.header.cmd = cmd,
2608c2ecf20Sopenharmony_ci		.header.len = sizeof(uvcb),
2618c2ecf20Sopenharmony_ci		.handle = handle,
2628c2ecf20Sopenharmony_ci	};
2638c2ecf20Sopenharmony_ci	int cc;
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci	WARN(!handle, "No handle provided to Ultravisor call cmd %x\n", cmd);
2668c2ecf20Sopenharmony_ci	cc = uv_call_sched(0, (u64)&uvcb);
2678c2ecf20Sopenharmony_ci	*rc = uvcb.header.rc;
2688c2ecf20Sopenharmony_ci	*rrc = uvcb.header.rrc;
2698c2ecf20Sopenharmony_ci	return cc ? -EINVAL : 0;
2708c2ecf20Sopenharmony_ci}
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_cistruct uv_info {
2738c2ecf20Sopenharmony_ci	unsigned long inst_calls_list[4];
2748c2ecf20Sopenharmony_ci	unsigned long uv_base_stor_len;
2758c2ecf20Sopenharmony_ci	unsigned long guest_base_stor_len;
2768c2ecf20Sopenharmony_ci	unsigned long guest_virt_base_stor_len;
2778c2ecf20Sopenharmony_ci	unsigned long guest_virt_var_stor_len;
2788c2ecf20Sopenharmony_ci	unsigned long guest_cpu_stor_len;
2798c2ecf20Sopenharmony_ci	unsigned long max_sec_stor_addr;
2808c2ecf20Sopenharmony_ci	unsigned int max_num_sec_conf;
2818c2ecf20Sopenharmony_ci	unsigned short max_guest_cpu_id;
2828c2ecf20Sopenharmony_ci	unsigned long uv_feature_indications;
2838c2ecf20Sopenharmony_ci};
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ciextern struct uv_info uv_info;
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci#ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST
2888c2ecf20Sopenharmony_ciextern int prot_virt_guest;
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_cistatic inline int is_prot_virt_guest(void)
2918c2ecf20Sopenharmony_ci{
2928c2ecf20Sopenharmony_ci	return prot_virt_guest;
2938c2ecf20Sopenharmony_ci}
2948c2ecf20Sopenharmony_ci
2958c2ecf20Sopenharmony_cistatic inline int share(unsigned long addr, u16 cmd)
2968c2ecf20Sopenharmony_ci{
2978c2ecf20Sopenharmony_ci	struct uv_cb_share uvcb = {
2988c2ecf20Sopenharmony_ci		.header.cmd = cmd,
2998c2ecf20Sopenharmony_ci		.header.len = sizeof(uvcb),
3008c2ecf20Sopenharmony_ci		.paddr = addr
3018c2ecf20Sopenharmony_ci	};
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_ci	if (!is_prot_virt_guest())
3048c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
3058c2ecf20Sopenharmony_ci	/*
3068c2ecf20Sopenharmony_ci	 * Sharing is page wise, if we encounter addresses that are
3078c2ecf20Sopenharmony_ci	 * not page aligned, we assume something went wrong. If
3088c2ecf20Sopenharmony_ci	 * malloced structs are passed to this function, we could leak
3098c2ecf20Sopenharmony_ci	 * data to the hypervisor.
3108c2ecf20Sopenharmony_ci	 */
3118c2ecf20Sopenharmony_ci	BUG_ON(addr & ~PAGE_MASK);
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_ci	if (!uv_call(0, (u64)&uvcb))
3148c2ecf20Sopenharmony_ci		return 0;
3158c2ecf20Sopenharmony_ci	return -EINVAL;
3168c2ecf20Sopenharmony_ci}
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci/*
3198c2ecf20Sopenharmony_ci * Guest 2 request to the Ultravisor to make a page shared with the
3208c2ecf20Sopenharmony_ci * hypervisor for IO.
3218c2ecf20Sopenharmony_ci *
3228c2ecf20Sopenharmony_ci * @addr: Real or absolute address of the page to be shared
3238c2ecf20Sopenharmony_ci */
3248c2ecf20Sopenharmony_cistatic inline int uv_set_shared(unsigned long addr)
3258c2ecf20Sopenharmony_ci{
3268c2ecf20Sopenharmony_ci	return share(addr, UVC_CMD_SET_SHARED_ACCESS);
3278c2ecf20Sopenharmony_ci}
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_ci/*
3308c2ecf20Sopenharmony_ci * Guest 2 request to the Ultravisor to make a page unshared.
3318c2ecf20Sopenharmony_ci *
3328c2ecf20Sopenharmony_ci * @addr: Real or absolute address of the page to be unshared
3338c2ecf20Sopenharmony_ci */
3348c2ecf20Sopenharmony_cistatic inline int uv_remove_shared(unsigned long addr)
3358c2ecf20Sopenharmony_ci{
3368c2ecf20Sopenharmony_ci	return share(addr, UVC_CMD_REMOVE_SHARED_ACCESS);
3378c2ecf20Sopenharmony_ci}
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ci#else
3408c2ecf20Sopenharmony_ci#define is_prot_virt_guest() 0
3418c2ecf20Sopenharmony_cistatic inline int uv_set_shared(unsigned long addr) { return 0; }
3428c2ecf20Sopenharmony_cistatic inline int uv_remove_shared(unsigned long addr) { return 0; }
3438c2ecf20Sopenharmony_ci#endif
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_KVM)
3468c2ecf20Sopenharmony_ciextern int prot_virt_host;
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_cistatic inline int is_prot_virt_host(void)
3498c2ecf20Sopenharmony_ci{
3508c2ecf20Sopenharmony_ci	return prot_virt_host;
3518c2ecf20Sopenharmony_ci}
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_ciint gmap_make_secure(struct gmap *gmap, unsigned long gaddr, void *uvcb);
3548c2ecf20Sopenharmony_ciint uv_destroy_page(unsigned long paddr);
3558c2ecf20Sopenharmony_ciint uv_convert_from_secure(unsigned long paddr);
3568c2ecf20Sopenharmony_ciint gmap_convert_to_secure(struct gmap *gmap, unsigned long gaddr);
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_civoid setup_uv(void);
3598c2ecf20Sopenharmony_civoid adjust_to_uv_max(unsigned long *vmax);
3608c2ecf20Sopenharmony_ci#else
3618c2ecf20Sopenharmony_ci#define is_prot_virt_host() 0
3628c2ecf20Sopenharmony_cistatic inline void setup_uv(void) {}
3638c2ecf20Sopenharmony_cistatic inline void adjust_to_uv_max(unsigned long *vmax) {}
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_cistatic inline int uv_destroy_page(unsigned long paddr)
3668c2ecf20Sopenharmony_ci{
3678c2ecf20Sopenharmony_ci	return 0;
3688c2ecf20Sopenharmony_ci}
3698c2ecf20Sopenharmony_ci
3708c2ecf20Sopenharmony_cistatic inline int uv_convert_from_secure(unsigned long paddr)
3718c2ecf20Sopenharmony_ci{
3728c2ecf20Sopenharmony_ci	return 0;
3738c2ecf20Sopenharmony_ci}
3748c2ecf20Sopenharmony_ci#endif
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_ci#if defined(CONFIG_PROTECTED_VIRTUALIZATION_GUEST) || IS_ENABLED(CONFIG_KVM)
3778c2ecf20Sopenharmony_civoid uv_query_info(void);
3788c2ecf20Sopenharmony_ci#else
3798c2ecf20Sopenharmony_cistatic inline void uv_query_info(void) {}
3808c2ecf20Sopenharmony_ci#endif
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_ci#endif /* _ASM_S390_UV_H */
383