xref: /kvm-unit-tests/lib/s390x/asm/uv.h (revision 88fb0e5d52be357d3aab854c5c16303fe1608335)
1 /*
2  * s390x Ultravisor related definitions
3  *
4  * Copyright (c) 2020 IBM Corp
5  *
6  * Authors:
7  *  Janosch Frank <frankja@linux.ibm.com>
8  *
9  * This code is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU General Public License version 2.
11  */
12 #ifndef UV_H
13 #define UV_H
14 
15 #define UVC_RC_EXECUTED		0x0001
16 #define UVC_RC_INV_CMD		0x0002
17 #define UVC_RC_INV_STATE	0x0003
18 #define UVC_RC_INV_LEN		0x0005
19 #define UVC_RC_NO_RESUME	0x0007
20 
21 #define UVC_CMD_QUI			0x0001
22 #define UVC_CMD_SET_SHARED_ACCESS	0x1000
23 #define UVC_CMD_REMOVE_SHARED_ACCESS	0x1001
24 
25 /* Bits in installed uv calls */
26 enum uv_cmds_inst {
27 	BIT_UVC_CMD_QUI = 0,
28 	BIT_UVC_CMD_SET_SHARED_ACCESS = 8,
29 	BIT_UVC_CMD_REMOVE_SHARED_ACCESS = 9,
30 };
31 
32 struct uv_cb_header {
33 	u16 len;
34 	u16 cmd;	/* Command Code */
35 	u16 rc;		/* Response Code */
36 	u16 rrc;	/* Return Reason Code */
37 } __attribute__((packed))  __attribute__((aligned(8)));
38 
39 struct uv_cb_qui {
40 	struct uv_cb_header header;
41 	u64 reserved08;
42 	u64 inst_calls_list[4];
43 	u64 reserved30[15];
44 } __attribute__((packed))  __attribute__((aligned(8)));
45 
46 struct uv_cb_share {
47 	struct uv_cb_header header;
48 	u64 reserved08[3];
49 	u64 paddr;
50 	u64 reserved28;
51 } __attribute__((packed))  __attribute__((aligned(8)));
52 
53 static inline int uv_call_once(unsigned long r1, unsigned long r2)
54 {
55 	int cc;
56 
57 	asm volatile(
58 		"0:	.insn rrf,0xB9A40000,%[r1],%[r2],0,0\n"
59 		"		ipm	%[cc]\n"
60 		"		srl	%[cc],28\n"
61 		: [cc] "=d" (cc)
62 		: [r1] "a" (r1), [r2] "a" (r2)
63 		: "memory", "cc");
64 	return cc;
65 }
66 
67 static inline int uv_call(unsigned long r1, unsigned long r2)
68 {
69 	int cc;
70 
71 	/*
72 	 * CC 2 and 3 tell us to re-execute because the instruction
73 	 * hasn't yet finished.
74 	 */
75 	do {
76 		cc = uv_call_once(r1, r2);
77 	} while (cc > 1);
78 
79 	return cc;
80 }
81 
82 #endif
83