hypercall.h 8.0 KB

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