xref: /openbmc/linux/drivers/virt/acrn/hypercall.h (revision 29a9f27574692a71c04fd41ca4bbf8eae842af13)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * ACRN HSM: hypercalls of ACRN Hypervisor
4  */
5 #ifndef __ACRN_HSM_HYPERCALL_H
6 #define __ACRN_HSM_HYPERCALL_H
7 #include <asm/acrn.h>
8 
9 /*
10  * Hypercall IDs of the ACRN Hypervisor
11  */
12 #define _HC_ID(x, y) (((x) << 24) | (y))
13 
14 #define HC_ID 0x80UL
15 
16 #define HC_ID_GEN_BASE			0x0UL
17 #define HC_SOS_REMOVE_CPU		_HC_ID(HC_ID, HC_ID_GEN_BASE + 0x01)
18 
19 #define HC_ID_VM_BASE			0x10UL
20 #define HC_CREATE_VM			_HC_ID(HC_ID, HC_ID_VM_BASE + 0x00)
21 #define HC_DESTROY_VM			_HC_ID(HC_ID, HC_ID_VM_BASE + 0x01)
22 #define HC_START_VM			_HC_ID(HC_ID, HC_ID_VM_BASE + 0x02)
23 #define HC_PAUSE_VM			_HC_ID(HC_ID, HC_ID_VM_BASE + 0x03)
24 #define HC_RESET_VM			_HC_ID(HC_ID, HC_ID_VM_BASE + 0x05)
25 #define HC_SET_VCPU_REGS		_HC_ID(HC_ID, HC_ID_VM_BASE + 0x06)
26 
27 #define HC_ID_IRQ_BASE			0x20UL
28 #define HC_INJECT_MSI			_HC_ID(HC_ID, HC_ID_IRQ_BASE + 0x03)
29 #define HC_VM_INTR_MONITOR		_HC_ID(HC_ID, HC_ID_IRQ_BASE + 0x04)
30 #define HC_SET_IRQLINE			_HC_ID(HC_ID, HC_ID_IRQ_BASE + 0x05)
31 
32 #define HC_ID_IOREQ_BASE		0x30UL
33 #define HC_SET_IOREQ_BUFFER		_HC_ID(HC_ID, HC_ID_IOREQ_BASE + 0x00)
34 #define HC_NOTIFY_REQUEST_FINISH	_HC_ID(HC_ID, HC_ID_IOREQ_BASE + 0x01)
35 
36 #define HC_ID_MEM_BASE			0x40UL
37 #define HC_VM_SET_MEMORY_REGIONS	_HC_ID(HC_ID, HC_ID_MEM_BASE + 0x02)
38 
39 #define HC_ID_PCI_BASE			0x50UL
40 #define HC_SET_PTDEV_INTR		_HC_ID(HC_ID, HC_ID_PCI_BASE + 0x03)
41 #define HC_RESET_PTDEV_INTR		_HC_ID(HC_ID, HC_ID_PCI_BASE + 0x04)
42 #define HC_ASSIGN_PCIDEV		_HC_ID(HC_ID, HC_ID_PCI_BASE + 0x05)
43 #define HC_DEASSIGN_PCIDEV		_HC_ID(HC_ID, HC_ID_PCI_BASE + 0x06)
44 #define HC_ASSIGN_MMIODEV		_HC_ID(HC_ID, HC_ID_PCI_BASE + 0x07)
45 #define HC_DEASSIGN_MMIODEV		_HC_ID(HC_ID, HC_ID_PCI_BASE + 0x08)
46 
47 #define HC_ID_PM_BASE			0x80UL
48 #define HC_PM_GET_CPU_STATE		_HC_ID(HC_ID, HC_ID_PM_BASE + 0x00)
49 
50 /**
51  * hcall_sos_remove_cpu() - Remove a vCPU of Service VM
52  * @cpu: The vCPU to be removed
53  *
54  * Return: 0 on success, <0 on failure
55  */
56 static inline long hcall_sos_remove_cpu(u64 cpu)
57 {
58 	return acrn_hypercall1(HC_SOS_REMOVE_CPU, cpu);
59 }
60 
61 /**
62  * hcall_create_vm() - Create a User VM
63  * @vminfo:	Service VM GPA of info of User VM creation
64  *
65  * Return: 0 on success, <0 on failure
66  */
67 static inline long hcall_create_vm(u64 vminfo)
68 {
69 	return acrn_hypercall1(HC_CREATE_VM, vminfo);
70 }
71 
72 /**
73  * hcall_start_vm() - Start a User VM
74  * @vmid:	User VM ID
75  *
76  * Return: 0 on success, <0 on failure
77  */
78 static inline long hcall_start_vm(u64 vmid)
79 {
80 	return acrn_hypercall1(HC_START_VM, vmid);
81 }
82 
83 /**
84  * hcall_pause_vm() - Pause a User VM
85  * @vmid:	User VM ID
86  *
87  * Return: 0 on success, <0 on failure
88  */
89 static inline long hcall_pause_vm(u64 vmid)
90 {
91 	return acrn_hypercall1(HC_PAUSE_VM, vmid);
92 }
93 
94 /**
95  * hcall_destroy_vm() - Destroy a User VM
96  * @vmid:	User VM ID
97  *
98  * Return: 0 on success, <0 on failure
99  */
100 static inline long hcall_destroy_vm(u64 vmid)
101 {
102 	return acrn_hypercall1(HC_DESTROY_VM, vmid);
103 }
104 
105 /**
106  * hcall_reset_vm() - Reset a User VM
107  * @vmid:	User VM ID
108  *
109  * Return: 0 on success, <0 on failure
110  */
111 static inline long hcall_reset_vm(u64 vmid)
112 {
113 	return acrn_hypercall1(HC_RESET_VM, vmid);
114 }
115 
116 /**
117  * hcall_set_vcpu_regs() - Set up registers of virtual CPU of a User VM
118  * @vmid:	User VM ID
119  * @regs_state:	Service VM GPA of registers state
120  *
121  * Return: 0 on success, <0 on failure
122  */
123 static inline long hcall_set_vcpu_regs(u64 vmid, u64 regs_state)
124 {
125 	return acrn_hypercall2(HC_SET_VCPU_REGS, vmid, regs_state);
126 }
127 
128 /**
129  * hcall_inject_msi() - Deliver a MSI interrupt to a User VM
130  * @vmid:	User VM ID
131  * @msi:	Service VM GPA of MSI message
132  *
133  * Return: 0 on success, <0 on failure
134  */
135 static inline long hcall_inject_msi(u64 vmid, u64 msi)
136 {
137 	return acrn_hypercall2(HC_INJECT_MSI, vmid, msi);
138 }
139 
140 /**
141  * hcall_vm_intr_monitor() - Set a shared page for User VM interrupt statistics
142  * @vmid:	User VM ID
143  * @addr:	Service VM GPA of the shared page
144  *
145  * Return: 0 on success, <0 on failure
146  */
147 static inline long hcall_vm_intr_monitor(u64 vmid, u64 addr)
148 {
149 	return acrn_hypercall2(HC_VM_INTR_MONITOR, vmid, addr);
150 }
151 
152 /**
153  * hcall_set_irqline() - Set or clear an interrupt line
154  * @vmid:	User VM ID
155  * @op:		Service VM GPA of interrupt line operations
156  *
157  * Return: 0 on success, <0 on failure
158  */
159 static inline long hcall_set_irqline(u64 vmid, u64 op)
160 {
161 	return acrn_hypercall2(HC_SET_IRQLINE, vmid, op);
162 }
163 
164 /**
165  * hcall_set_ioreq_buffer() - Set up the shared buffer for I/O Requests.
166  * @vmid:	User VM ID
167  * @buffer:	Service VM GPA of the shared buffer
168  *
169  * Return: 0 on success, <0 on failure
170  */
171 static inline long hcall_set_ioreq_buffer(u64 vmid, u64 buffer)
172 {
173 	return acrn_hypercall2(HC_SET_IOREQ_BUFFER, vmid, buffer);
174 }
175 
176 /**
177  * hcall_notify_req_finish() - Notify ACRN Hypervisor of I/O request completion.
178  * @vmid:	User VM ID
179  * @vcpu:	The vCPU which initiated the I/O request
180  *
181  * Return: 0 on success, <0 on failure
182  */
183 static inline long hcall_notify_req_finish(u64 vmid, u64 vcpu)
184 {
185 	return acrn_hypercall2(HC_NOTIFY_REQUEST_FINISH, vmid, vcpu);
186 }
187 
188 /**
189  * hcall_set_memory_regions() - Inform the hypervisor to set up EPT mappings
190  * @regions_pa:	Service VM GPA of &struct vm_memory_region_batch
191  *
192  * Return: 0 on success, <0 on failure
193  */
194 static inline long hcall_set_memory_regions(u64 regions_pa)
195 {
196 	return acrn_hypercall1(HC_VM_SET_MEMORY_REGIONS, regions_pa);
197 }
198 
199 /**
200  * hcall_assign_mmiodev() - Assign a MMIO device to a User VM
201  * @vmid:	User VM ID
202  * @addr:	Service VM GPA of the &struct acrn_mmiodev
203  *
204  * Return: 0 on success, <0 on failure
205  */
206 static inline long hcall_assign_mmiodev(u64 vmid, u64 addr)
207 {
208 	return acrn_hypercall2(HC_ASSIGN_MMIODEV, vmid, addr);
209 }
210 
211 /**
212  * hcall_deassign_mmiodev() - De-assign a PCI device from a User VM
213  * @vmid:	User VM ID
214  * @addr:	Service VM GPA of the &struct acrn_mmiodev
215  *
216  * Return: 0 on success, <0 on failure
217  */
218 static inline long hcall_deassign_mmiodev(u64 vmid, u64 addr)
219 {
220 	return acrn_hypercall2(HC_DEASSIGN_MMIODEV, vmid, addr);
221 }
222 
223 /**
224  * hcall_assign_pcidev() - Assign a PCI device to a User VM
225  * @vmid:	User VM ID
226  * @addr:	Service VM GPA of the &struct acrn_pcidev
227  *
228  * Return: 0 on success, <0 on failure
229  */
230 static inline long hcall_assign_pcidev(u64 vmid, u64 addr)
231 {
232 	return acrn_hypercall2(HC_ASSIGN_PCIDEV, vmid, addr);
233 }
234 
235 /**
236  * hcall_deassign_pcidev() - De-assign a PCI device from a User VM
237  * @vmid:	User VM ID
238  * @addr:	Service VM GPA of the &struct acrn_pcidev
239  *
240  * Return: 0 on success, <0 on failure
241  */
242 static inline long hcall_deassign_pcidev(u64 vmid, u64 addr)
243 {
244 	return acrn_hypercall2(HC_DEASSIGN_PCIDEV, vmid, addr);
245 }
246 
247 /**
248  * hcall_set_ptdev_intr() - Configure an interrupt for an assigned PCI device.
249  * @vmid:	User VM ID
250  * @irq:	Service VM GPA of the &struct acrn_ptdev_irq
251  *
252  * Return: 0 on success, <0 on failure
253  */
254 static inline long hcall_set_ptdev_intr(u64 vmid, u64 irq)
255 {
256 	return acrn_hypercall2(HC_SET_PTDEV_INTR, vmid, irq);
257 }
258 
259 /**
260  * hcall_reset_ptdev_intr() - Reset an interrupt for an assigned PCI device.
261  * @vmid:	User VM ID
262  * @irq:	Service VM GPA of the &struct acrn_ptdev_irq
263  *
264  * Return: 0 on success, <0 on failure
265  */
266 static inline long hcall_reset_ptdev_intr(u64 vmid, u64 irq)
267 {
268 	return acrn_hypercall2(HC_RESET_PTDEV_INTR, vmid, irq);
269 }
270 
271 /*
272  * hcall_get_cpu_state() - Get P-states and C-states info from the hypervisor
273  * @state:	Service VM GPA of buffer of P-states and C-states
274  */
275 static inline long hcall_get_cpu_state(u64 cmd, u64 state)
276 {
277 	return acrn_hypercall2(HC_PM_GET_CPU_STATE, cmd, state);
278 }
279 
280 #endif /* __ACRN_HSM_HYPERCALL_H */
281