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>
17 #include <linux/sched.h>
21 #define UVC_RC_EXECUTED 0x0001
22 #define UVC_RC_INV_CMD 0x0002
23 #define UVC_RC_INV_STATE 0x0003
24 #define UVC_RC_INV_LEN 0x0005
25 #define UVC_RC_NO_RESUME 0x0007
26 #define UVC_RC_NEED_DESTROY 0x8000
28 #define UVC_CMD_QUI 0x0001
29 #define UVC_CMD_INIT_UV 0x000f
30 #define UVC_CMD_CREATE_SEC_CONF 0x0100
31 #define UVC_CMD_DESTROY_SEC_CONF 0x0101
32 #define UVC_CMD_CREATE_SEC_CPU 0x0120
33 #define UVC_CMD_DESTROY_SEC_CPU 0x0121
34 #define UVC_CMD_CONV_TO_SEC_STOR 0x0200
35 #define UVC_CMD_CONV_FROM_SEC_STOR 0x0201
36 #define UVC_CMD_DESTR_SEC_STOR 0x0202
37 #define UVC_CMD_SET_SEC_CONF_PARAMS 0x0300
38 #define UVC_CMD_UNPACK_IMG 0x0301
39 #define UVC_CMD_VERIFY_IMG 0x0302
40 #define UVC_CMD_CPU_RESET 0x0310
41 #define UVC_CMD_CPU_RESET_INITIAL 0x0311
42 #define UVC_CMD_PREPARE_RESET 0x0320
43 #define UVC_CMD_CPU_RESET_CLEAR 0x0321
44 #define UVC_CMD_CPU_SET_STATE 0x0330
45 #define UVC_CMD_SET_UNSHARE_ALL 0x0340
46 #define UVC_CMD_PIN_PAGE_SHARED 0x0341
47 #define UVC_CMD_UNPIN_PAGE_SHARED 0x0342
48 #define UVC_CMD_SET_SHARED_ACCESS 0x1000
49 #define UVC_CMD_REMOVE_SHARED_ACCESS 0x1001
51 /* Bits in installed uv calls */
54 BIT_UVC_CMD_INIT_UV = 1,
55 BIT_UVC_CMD_CREATE_SEC_CONF = 2,
56 BIT_UVC_CMD_DESTROY_SEC_CONF = 3,
57 BIT_UVC_CMD_CREATE_SEC_CPU = 4,
58 BIT_UVC_CMD_DESTROY_SEC_CPU = 5,
59 BIT_UVC_CMD_CONV_TO_SEC_STOR = 6,
60 BIT_UVC_CMD_CONV_FROM_SEC_STOR = 7,
61 BIT_UVC_CMD_SET_SHARED_ACCESS = 8,
62 BIT_UVC_CMD_REMOVE_SHARED_ACCESS = 9,
63 BIT_UVC_CMD_SET_SEC_PARMS = 11,
64 BIT_UVC_CMD_UNPACK_IMG = 13,
65 BIT_UVC_CMD_VERIFY_IMG = 14,
66 BIT_UVC_CMD_CPU_RESET = 15,
67 BIT_UVC_CMD_CPU_RESET_INITIAL = 16,
68 BIT_UVC_CMD_CPU_SET_STATE = 17,
69 BIT_UVC_CMD_PREPARE_RESET = 18,
70 BIT_UVC_CMD_CPU_PERFORM_CLEAR_RESET = 19,
71 BIT_UVC_CMD_UNSHARE_ALL = 20,
72 BIT_UVC_CMD_PIN_PAGE_SHARED = 21,
73 BIT_UVC_CMD_UNPIN_PAGE_SHARED = 22,
82 u16 cmd; /* Command Code */
83 u16 rc; /* Response Code */
84 u16 rrc; /* Return Reason Code */
85 } __packed __aligned(8);
87 /* Query Ultravisor Information */
89 struct uv_cb_header header;
91 u64 inst_calls_list[4];
95 u64 conf_base_phys_stor_len;
96 u64 conf_base_virt_stor_len;
97 u64 conf_virt_var_stor_len;
100 u32 max_num_sec_conf;
101 u64 max_guest_stor_addr;
102 u8 reserved88[158 - 136];
103 u16 max_guest_cpu_id;
104 u64 uv_feature_indications;
105 u8 reserveda0[200 - 168];
106 } __packed __aligned(8);
108 /* Initialize Ultravisor */
110 struct uv_cb_header header;
115 } __packed __aligned(8);
117 /* Create Guest Configuration */
119 struct uv_cb_header header;
122 u64 conf_base_stor_origin;
123 u64 conf_virt_stor_origin;
125 u64 guest_stor_origin;
130 } __packed __aligned(8);
132 /* Create Secure CPU */
134 struct uv_cb_header header;
143 } __packed __aligned(8);
145 /* Convert to Secure */
147 struct uv_cb_header header;
151 } __packed __aligned(8);
153 /* Convert from Secure / Pin Page Shared */
155 struct uv_cb_header header;
158 } __packed __aligned(8);
160 /* Set Secure Config Parameter */
162 struct uv_cb_header header;
165 u64 sec_header_origin;
169 } __packed __aligned(8);
173 struct uv_cb_header header;
179 } __packed __aligned(8);
181 #define PV_CPU_STATE_OPR 1
182 #define PV_CPU_STATE_STP 2
183 #define PV_CPU_STATE_CHKSTP 3
184 #define PV_CPU_STATE_OPR_LOAD 5
186 struct uv_cb_cpu_set_state {
187 struct uv_cb_header header;
196 * A common UV call struct for calls that take no payload
201 struct uv_cb_nodata {
202 struct uv_cb_header header;
206 } __packed __aligned(8);
208 /* Set Shared Access */
210 struct uv_cb_header header;
214 } __packed __aligned(8);
216 static inline int __uv_call(unsigned long r1, unsigned long r2)
221 " .insn rrf,0xB9A40000,%[r1],%[r2],0,0\n"
225 : [r1] "a" (r1), [r2] "a" (r2)
230 static inline int uv_call(unsigned long r1, unsigned long r2)
235 cc = __uv_call(r1, r2);
240 /* Low level uv_call that avoids stalls for long running busy conditions */
241 static inline int uv_call_sched(unsigned long r1, unsigned long r2)
246 cc = __uv_call(r1, r2);
253 * special variant of uv_call that only transports the cpu or guest
254 * handle and the command, like destroy or verify.
256 static inline int uv_cmd_nodata(u64 handle, u16 cmd, u16 *rc, u16 *rrc)
258 struct uv_cb_nodata uvcb = {
260 .header.len = sizeof(uvcb),
265 WARN(!handle, "No handle provided to Ultravisor call cmd %x\n", cmd);
266 cc = uv_call_sched(0, (u64)&uvcb);
267 *rc = uvcb.header.rc;
268 *rrc = uvcb.header.rrc;
269 return cc ? -EINVAL : 0;
273 unsigned long inst_calls_list[4];
274 unsigned long uv_base_stor_len;
275 unsigned long guest_base_stor_len;
276 unsigned long guest_virt_base_stor_len;
277 unsigned long guest_virt_var_stor_len;
278 unsigned long guest_cpu_stor_len;
279 unsigned long max_sec_stor_addr;
280 unsigned int max_num_sec_conf;
281 unsigned short max_guest_cpu_id;
282 unsigned long uv_feature_indications;
285 extern struct uv_info uv_info;
287 #ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST
288 extern int prot_virt_guest;
290 static inline int is_prot_virt_guest(void)
292 return prot_virt_guest;
295 static inline int share(unsigned long addr, u16 cmd)
297 struct uv_cb_share uvcb = {
299 .header.len = sizeof(uvcb),
303 if (!is_prot_virt_guest())
306 * Sharing is page wise, if we encounter addresses that are
307 * not page aligned, we assume something went wrong. If
308 * malloced structs are passed to this function, we could leak
309 * data to the hypervisor.
311 BUG_ON(addr & ~PAGE_MASK);
313 if (!uv_call(0, (u64)&uvcb))
319 * Guest 2 request to the Ultravisor to make a page shared with the
322 * @addr: Real or absolute address of the page to be shared
324 static inline int uv_set_shared(unsigned long addr)
326 return share(addr, UVC_CMD_SET_SHARED_ACCESS);
330 * Guest 2 request to the Ultravisor to make a page unshared.
332 * @addr: Real or absolute address of the page to be unshared
334 static inline int uv_remove_shared(unsigned long addr)
336 return share(addr, UVC_CMD_REMOVE_SHARED_ACCESS);
340 #define is_prot_virt_guest() 0
341 static inline int uv_set_shared(unsigned long addr) { return 0; }
342 static inline int uv_remove_shared(unsigned long addr) { return 0; }
345 #if IS_ENABLED(CONFIG_KVM)
346 extern int prot_virt_host;
348 static inline int is_prot_virt_host(void)
350 return prot_virt_host;
353 int gmap_make_secure(struct gmap *gmap, unsigned long gaddr, void *uvcb);
354 int uv_destroy_page(unsigned long paddr);
355 int uv_convert_from_secure(unsigned long paddr);
356 int gmap_convert_to_secure(struct gmap *gmap, unsigned long gaddr);
360 #define is_prot_virt_host() 0
361 static inline void setup_uv(void) {}
363 static inline int uv_destroy_page(unsigned long paddr)
368 static inline int uv_convert_from_secure(unsigned long paddr)
374 #endif /* _ASM_S390_UV_H */