1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Ultravisor Interfaces
5 * Copyright IBM Corp. 2019
8 * Vasily Gorbik <gor@linux.ibm.com>
9 * Janosch Frank <frankja@linux.ibm.com>
11 #ifndef _ASM_S390_UV_H
12 #define _ASM_S390_UV_H
14 #include <linux/types.h>
15 #include <linux/errno.h>
16 #include <linux/bug.h>
19 #define UVC_RC_EXECUTED 0x0001
20 #define UVC_RC_INV_CMD 0x0002
21 #define UVC_RC_INV_STATE 0x0003
22 #define UVC_RC_INV_LEN 0x0005
23 #define UVC_RC_NO_RESUME 0x0007
25 #define UVC_CMD_QUI 0x0001
26 #define UVC_CMD_SET_SHARED_ACCESS 0x1000
27 #define UVC_CMD_REMOVE_SHARED_ACCESS 0x1001
29 /* Bits in installed uv calls */
32 BIT_UVC_CMD_SET_SHARED_ACCESS
= 8,
33 BIT_UVC_CMD_REMOVE_SHARED_ACCESS
= 9,
38 u16 cmd
; /* Command Code */
39 u16 rc
; /* Response Code */
40 u16 rrc
; /* Return Reason Code */
41 } __packed
__aligned(8);
44 struct uv_cb_header header
;
46 u64 inst_calls_list
[4];
48 } __packed
__aligned(8);
51 struct uv_cb_header header
;
55 } __packed
__aligned(8);
57 static inline int uv_call(unsigned long r1
, unsigned long r2
)
62 "0: .insn rrf,0xB9A40000,%[r1],%[r2],0,0\n"
67 : [r1
] "a" (r1
), [r2
] "a" (r2
)
72 #ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST
73 extern int prot_virt_guest
;
75 static inline int is_prot_virt_guest(void)
77 return prot_virt_guest
;
80 static inline int share(unsigned long addr
, u16 cmd
)
82 struct uv_cb_share uvcb
= {
84 .header
.len
= sizeof(uvcb
),
88 if (!is_prot_virt_guest())
91 * Sharing is page wise, if we encounter addresses that are
92 * not page aligned, we assume something went wrong. If
93 * malloced structs are passed to this function, we could leak
94 * data to the hypervisor.
96 BUG_ON(addr
& ~PAGE_MASK
);
98 if (!uv_call(0, (u64
)&uvcb
))
104 * Guest 2 request to the Ultravisor to make a page shared with the
107 * @addr: Real or absolute address of the page to be shared
109 static inline int uv_set_shared(unsigned long addr
)
111 return share(addr
, UVC_CMD_SET_SHARED_ACCESS
);
115 * Guest 2 request to the Ultravisor to make a page unshared.
117 * @addr: Real or absolute address of the page to be unshared
119 static inline int uv_remove_shared(unsigned long addr
)
121 return share(addr
, UVC_CMD_REMOVE_SHARED_ACCESS
);
124 void uv_query_info(void);
126 #define is_prot_virt_guest() 0
127 static inline int uv_set_shared(unsigned long addr
) { return 0; }
128 static inline int uv_remove_shared(unsigned long addr
) { return 0; }
129 static inline void uv_query_info(void) {}
132 #endif /* _ASM_S390_UV_H */