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