xref: /openbmc/linux/drivers/virt/acrn/hypercall.h (revision f5c27da4)
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 #define HC_CREATE_VDEV			_HC_ID(HC_ID, HC_ID_PCI_BASE + 0x09)
47 #define HC_DESTROY_VDEV			_HC_ID(HC_ID, HC_ID_PCI_BASE + 0x0A)
48 
49 #define HC_ID_PM_BASE			0x80UL
50 #define HC_PM_GET_CPU_STATE		_HC_ID(HC_ID, HC_ID_PM_BASE + 0x00)
51 
52 /**
53  * hcall_sos_remove_cpu() - Remove a vCPU of Service VM
54  * @cpu: The vCPU to be removed
55  *
56  * Return: 0 on success, <0 on failure
57  */
58 static inline long hcall_sos_remove_cpu(u64 cpu)
59 {
60 	return acrn_hypercall1(HC_SOS_REMOVE_CPU, cpu);
61 }
62 
63 /**
64  * hcall_create_vm() - Create a User VM
65  * @vminfo:	Service VM GPA of info of User VM creation
66  *
67  * Return: 0 on success, <0 on failure
68  */
69 static inline long hcall_create_vm(u64 vminfo)
70 {
71 	return acrn_hypercall1(HC_CREATE_VM, vminfo);
72 }
73 
74 /**
75  * hcall_start_vm() - Start a User VM
76  * @vmid:	User VM ID
77  *
78  * Return: 0 on success, <0 on failure
79  */
80 static inline long hcall_start_vm(u64 vmid)
81 {
82 	return acrn_hypercall1(HC_START_VM, vmid);
83 }
84 
85 /**
86  * hcall_pause_vm() - Pause a User VM
87  * @vmid:	User VM ID
88  *
89  * Return: 0 on success, <0 on failure
90  */
91 static inline long hcall_pause_vm(u64 vmid)
92 {
93 	return acrn_hypercall1(HC_PAUSE_VM, vmid);
94 }
95 
96 /**
97  * hcall_destroy_vm() - Destroy a User VM
98  * @vmid:	User VM ID
99  *
100  * Return: 0 on success, <0 on failure
101  */
102 static inline long hcall_destroy_vm(u64 vmid)
103 {
104 	return acrn_hypercall1(HC_DESTROY_VM, vmid);
105 }
106 
107 /**
108  * hcall_reset_vm() - Reset a User VM
109  * @vmid:	User VM ID
110  *
111  * Return: 0 on success, <0 on failure
112  */
113 static inline long hcall_reset_vm(u64 vmid)
114 {
115 	return acrn_hypercall1(HC_RESET_VM, vmid);
116 }
117 
118 /**
119  * hcall_set_vcpu_regs() - Set up registers of virtual CPU of a User VM
120  * @vmid:	User VM ID
121  * @regs_state:	Service VM GPA of registers state
122  *
123  * Return: 0 on success, <0 on failure
124  */
125 static inline long hcall_set_vcpu_regs(u64 vmid, u64 regs_state)
126 {
127 	return acrn_hypercall2(HC_SET_VCPU_REGS, vmid, regs_state);
128 }
129 
130 /**
131  * hcall_inject_msi() - Deliver a MSI interrupt to a User VM
132  * @vmid:	User VM ID
133  * @msi:	Service VM GPA of MSI message
134  *
135  * Return: 0 on success, <0 on failure
136  */
137 static inline long hcall_inject_msi(u64 vmid, u64 msi)
138 {
139 	return acrn_hypercall2(HC_INJECT_MSI, vmid, msi);
140 }
141 
142 /**
143  * hcall_vm_intr_monitor() - Set a shared page for User VM interrupt statistics
144  * @vmid:	User VM ID
145  * @addr:	Service VM GPA of the shared page
146  *
147  * Return: 0 on success, <0 on failure
148  */
149 static inline long hcall_vm_intr_monitor(u64 vmid, u64 addr)
150 {
151 	return acrn_hypercall2(HC_VM_INTR_MONITOR, vmid, addr);
152 }
153 
154 /**
155  * hcall_set_irqline() - Set or clear an interrupt line
156  * @vmid:	User VM ID
157  * @op:		Service VM GPA of interrupt line operations
158  *
159  * Return: 0 on success, <0 on failure
160  */
161 static inline long hcall_set_irqline(u64 vmid, u64 op)
162 {
163 	return acrn_hypercall2(HC_SET_IRQLINE, vmid, op);
164 }
165 
166 /**
167  * hcall_set_ioreq_buffer() - Set up the shared buffer for I/O Requests.
168  * @vmid:	User VM ID
169  * @buffer:	Service VM GPA of the shared buffer
170  *
171  * Return: 0 on success, <0 on failure
172  */
173 static inline long hcall_set_ioreq_buffer(u64 vmid, u64 buffer)
174 {
175 	return acrn_hypercall2(HC_SET_IOREQ_BUFFER, vmid, buffer);
176 }
177 
178 /**
179  * hcall_notify_req_finish() - Notify ACRN Hypervisor of I/O request completion.
180  * @vmid:	User VM ID
181  * @vcpu:	The vCPU which initiated the I/O request
182  *
183  * Return: 0 on success, <0 on failure
184  */
185 static inline long hcall_notify_req_finish(u64 vmid, u64 vcpu)
186 {
187 	return acrn_hypercall2(HC_NOTIFY_REQUEST_FINISH, vmid, vcpu);
188 }
189 
190 /**
191  * hcall_set_memory_regions() - Inform the hypervisor to set up EPT mappings
192  * @regions_pa:	Service VM GPA of &struct vm_memory_region_batch
193  *
194  * Return: 0 on success, <0 on failure
195  */
196 static inline long hcall_set_memory_regions(u64 regions_pa)
197 {
198 	return acrn_hypercall1(HC_VM_SET_MEMORY_REGIONS, regions_pa);
199 }
200 
201 /**
202  * hcall_create_vdev() - Create a virtual device for a User VM
203  * @vmid:	User VM ID
204  * @addr:	Service VM GPA of the &struct acrn_vdev
205  *
206  * Return: 0 on success, <0 on failure
207  */
208 static inline long hcall_create_vdev(u64 vmid, u64 addr)
209 {
210 	return acrn_hypercall2(HC_CREATE_VDEV, vmid, addr);
211 }
212 
213 /**
214  * hcall_destroy_vdev() - Destroy a virtual device of a User VM
215  * @vmid:	User VM ID
216  * @addr:	Service VM GPA of the &struct acrn_vdev
217  *
218  * Return: 0 on success, <0 on failure
219  */
220 static inline long hcall_destroy_vdev(u64 vmid, u64 addr)
221 {
222 	return acrn_hypercall2(HC_DESTROY_VDEV, vmid, addr);
223 }
224 
225 /**
226  * hcall_assign_mmiodev() - Assign a MMIO device to a User VM
227  * @vmid:	User VM ID
228  * @addr:	Service VM GPA of the &struct acrn_mmiodev
229  *
230  * Return: 0 on success, <0 on failure
231  */
232 static inline long hcall_assign_mmiodev(u64 vmid, u64 addr)
233 {
234 	return acrn_hypercall2(HC_ASSIGN_MMIODEV, vmid, addr);
235 }
236 
237 /**
238  * hcall_deassign_mmiodev() - De-assign a PCI device from a User VM
239  * @vmid:	User VM ID
240  * @addr:	Service VM GPA of the &struct acrn_mmiodev
241  *
242  * Return: 0 on success, <0 on failure
243  */
244 static inline long hcall_deassign_mmiodev(u64 vmid, u64 addr)
245 {
246 	return acrn_hypercall2(HC_DEASSIGN_MMIODEV, vmid, addr);
247 }
248 
249 /**
250  * hcall_assign_pcidev() - Assign a PCI device to a User VM
251  * @vmid:	User VM ID
252  * @addr:	Service VM GPA of the &struct acrn_pcidev
253  *
254  * Return: 0 on success, <0 on failure
255  */
256 static inline long hcall_assign_pcidev(u64 vmid, u64 addr)
257 {
258 	return acrn_hypercall2(HC_ASSIGN_PCIDEV, vmid, addr);
259 }
260 
261 /**
262  * hcall_deassign_pcidev() - De-assign a PCI device from a User VM
263  * @vmid:	User VM ID
264  * @addr:	Service VM GPA of the &struct acrn_pcidev
265  *
266  * Return: 0 on success, <0 on failure
267  */
268 static inline long hcall_deassign_pcidev(u64 vmid, u64 addr)
269 {
270 	return acrn_hypercall2(HC_DEASSIGN_PCIDEV, vmid, addr);
271 }
272 
273 /**
274  * hcall_set_ptdev_intr() - Configure an interrupt for an assigned PCI device.
275  * @vmid:	User VM ID
276  * @irq:	Service VM GPA of the &struct acrn_ptdev_irq
277  *
278  * Return: 0 on success, <0 on failure
279  */
280 static inline long hcall_set_ptdev_intr(u64 vmid, u64 irq)
281 {
282 	return acrn_hypercall2(HC_SET_PTDEV_INTR, vmid, irq);
283 }
284 
285 /**
286  * hcall_reset_ptdev_intr() - Reset an interrupt for an assigned PCI device.
287  * @vmid:	User VM ID
288  * @irq:	Service VM GPA of the &struct acrn_ptdev_irq
289  *
290  * Return: 0 on success, <0 on failure
291  */
292 static inline long hcall_reset_ptdev_intr(u64 vmid, u64 irq)
293 {
294 	return acrn_hypercall2(HC_RESET_PTDEV_INTR, vmid, irq);
295 }
296 
297 /*
298  * hcall_get_cpu_state() - Get P-states and C-states info from the hypervisor
299  * @state:	Service VM GPA of buffer of P-states and C-states
300  */
301 static inline long hcall_get_cpu_state(u64 cmd, u64 state)
302 {
303 	return acrn_hypercall2(HC_PM_GET_CPU_STATE, cmd, state);
304 }
305 
306 #endif /* __ACRN_HSM_HYPERCALL_H */
307