Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * ACRN HSM: hypercalls of ACRN Hypervisor
0004  */
0005 #ifndef __ACRN_HSM_HYPERCALL_H
0006 #define __ACRN_HSM_HYPERCALL_H
0007 #include <asm/acrn.h>
0008 
0009 /*
0010  * Hypercall IDs of the ACRN Hypervisor
0011  */
0012 #define _HC_ID(x, y) (((x) << 24) | (y))
0013 
0014 #define HC_ID 0x80UL
0015 
0016 #define HC_ID_GEN_BASE          0x0UL
0017 #define HC_SOS_REMOVE_CPU       _HC_ID(HC_ID, HC_ID_GEN_BASE + 0x01)
0018 
0019 #define HC_ID_VM_BASE           0x10UL
0020 #define HC_CREATE_VM            _HC_ID(HC_ID, HC_ID_VM_BASE + 0x00)
0021 #define HC_DESTROY_VM           _HC_ID(HC_ID, HC_ID_VM_BASE + 0x01)
0022 #define HC_START_VM         _HC_ID(HC_ID, HC_ID_VM_BASE + 0x02)
0023 #define HC_PAUSE_VM         _HC_ID(HC_ID, HC_ID_VM_BASE + 0x03)
0024 #define HC_RESET_VM         _HC_ID(HC_ID, HC_ID_VM_BASE + 0x05)
0025 #define HC_SET_VCPU_REGS        _HC_ID(HC_ID, HC_ID_VM_BASE + 0x06)
0026 
0027 #define HC_ID_IRQ_BASE          0x20UL
0028 #define HC_INJECT_MSI           _HC_ID(HC_ID, HC_ID_IRQ_BASE + 0x03)
0029 #define HC_VM_INTR_MONITOR      _HC_ID(HC_ID, HC_ID_IRQ_BASE + 0x04)
0030 #define HC_SET_IRQLINE          _HC_ID(HC_ID, HC_ID_IRQ_BASE + 0x05)
0031 
0032 #define HC_ID_IOREQ_BASE        0x30UL
0033 #define HC_SET_IOREQ_BUFFER     _HC_ID(HC_ID, HC_ID_IOREQ_BASE + 0x00)
0034 #define HC_NOTIFY_REQUEST_FINISH    _HC_ID(HC_ID, HC_ID_IOREQ_BASE + 0x01)
0035 
0036 #define HC_ID_MEM_BASE          0x40UL
0037 #define HC_VM_SET_MEMORY_REGIONS    _HC_ID(HC_ID, HC_ID_MEM_BASE + 0x02)
0038 
0039 #define HC_ID_PCI_BASE          0x50UL
0040 #define HC_SET_PTDEV_INTR       _HC_ID(HC_ID, HC_ID_PCI_BASE + 0x03)
0041 #define HC_RESET_PTDEV_INTR     _HC_ID(HC_ID, HC_ID_PCI_BASE + 0x04)
0042 #define HC_ASSIGN_PCIDEV        _HC_ID(HC_ID, HC_ID_PCI_BASE + 0x05)
0043 #define HC_DEASSIGN_PCIDEV      _HC_ID(HC_ID, HC_ID_PCI_BASE + 0x06)
0044 #define HC_ASSIGN_MMIODEV       _HC_ID(HC_ID, HC_ID_PCI_BASE + 0x07)
0045 #define HC_DEASSIGN_MMIODEV     _HC_ID(HC_ID, HC_ID_PCI_BASE + 0x08)
0046 #define HC_CREATE_VDEV          _HC_ID(HC_ID, HC_ID_PCI_BASE + 0x09)
0047 #define HC_DESTROY_VDEV         _HC_ID(HC_ID, HC_ID_PCI_BASE + 0x0A)
0048 
0049 #define HC_ID_PM_BASE           0x80UL
0050 #define HC_PM_GET_CPU_STATE     _HC_ID(HC_ID, HC_ID_PM_BASE + 0x00)
0051 
0052 /**
0053  * hcall_sos_remove_cpu() - Remove a vCPU of Service VM
0054  * @cpu: The vCPU to be removed
0055  *
0056  * Return: 0 on success, <0 on failure
0057  */
0058 static inline long hcall_sos_remove_cpu(u64 cpu)
0059 {
0060     return acrn_hypercall1(HC_SOS_REMOVE_CPU, cpu);
0061 }
0062 
0063 /**
0064  * hcall_create_vm() - Create a User VM
0065  * @vminfo: Service VM GPA of info of User VM creation
0066  *
0067  * Return: 0 on success, <0 on failure
0068  */
0069 static inline long hcall_create_vm(u64 vminfo)
0070 {
0071     return acrn_hypercall1(HC_CREATE_VM, vminfo);
0072 }
0073 
0074 /**
0075  * hcall_start_vm() - Start a User VM
0076  * @vmid:   User VM ID
0077  *
0078  * Return: 0 on success, <0 on failure
0079  */
0080 static inline long hcall_start_vm(u64 vmid)
0081 {
0082     return acrn_hypercall1(HC_START_VM, vmid);
0083 }
0084 
0085 /**
0086  * hcall_pause_vm() - Pause a User VM
0087  * @vmid:   User VM ID
0088  *
0089  * Return: 0 on success, <0 on failure
0090  */
0091 static inline long hcall_pause_vm(u64 vmid)
0092 {
0093     return acrn_hypercall1(HC_PAUSE_VM, vmid);
0094 }
0095 
0096 /**
0097  * hcall_destroy_vm() - Destroy a User VM
0098  * @vmid:   User VM ID
0099  *
0100  * Return: 0 on success, <0 on failure
0101  */
0102 static inline long hcall_destroy_vm(u64 vmid)
0103 {
0104     return acrn_hypercall1(HC_DESTROY_VM, vmid);
0105 }
0106 
0107 /**
0108  * hcall_reset_vm() - Reset a User VM
0109  * @vmid:   User VM ID
0110  *
0111  * Return: 0 on success, <0 on failure
0112  */
0113 static inline long hcall_reset_vm(u64 vmid)
0114 {
0115     return acrn_hypercall1(HC_RESET_VM, vmid);
0116 }
0117 
0118 /**
0119  * hcall_set_vcpu_regs() - Set up registers of virtual CPU of a User VM
0120  * @vmid:   User VM ID
0121  * @regs_state: Service VM GPA of registers state
0122  *
0123  * Return: 0 on success, <0 on failure
0124  */
0125 static inline long hcall_set_vcpu_regs(u64 vmid, u64 regs_state)
0126 {
0127     return acrn_hypercall2(HC_SET_VCPU_REGS, vmid, regs_state);
0128 }
0129 
0130 /**
0131  * hcall_inject_msi() - Deliver a MSI interrupt to a User VM
0132  * @vmid:   User VM ID
0133  * @msi:    Service VM GPA of MSI message
0134  *
0135  * Return: 0 on success, <0 on failure
0136  */
0137 static inline long hcall_inject_msi(u64 vmid, u64 msi)
0138 {
0139     return acrn_hypercall2(HC_INJECT_MSI, vmid, msi);
0140 }
0141 
0142 /**
0143  * hcall_vm_intr_monitor() - Set a shared page for User VM interrupt statistics
0144  * @vmid:   User VM ID
0145  * @addr:   Service VM GPA of the shared page
0146  *
0147  * Return: 0 on success, <0 on failure
0148  */
0149 static inline long hcall_vm_intr_monitor(u64 vmid, u64 addr)
0150 {
0151     return acrn_hypercall2(HC_VM_INTR_MONITOR, vmid, addr);
0152 }
0153 
0154 /**
0155  * hcall_set_irqline() - Set or clear an interrupt line
0156  * @vmid:   User VM ID
0157  * @op:     Service VM GPA of interrupt line operations
0158  *
0159  * Return: 0 on success, <0 on failure
0160  */
0161 static inline long hcall_set_irqline(u64 vmid, u64 op)
0162 {
0163     return acrn_hypercall2(HC_SET_IRQLINE, vmid, op);
0164 }
0165 
0166 /**
0167  * hcall_set_ioreq_buffer() - Set up the shared buffer for I/O Requests.
0168  * @vmid:   User VM ID
0169  * @buffer: Service VM GPA of the shared buffer
0170  *
0171  * Return: 0 on success, <0 on failure
0172  */
0173 static inline long hcall_set_ioreq_buffer(u64 vmid, u64 buffer)
0174 {
0175     return acrn_hypercall2(HC_SET_IOREQ_BUFFER, vmid, buffer);
0176 }
0177 
0178 /**
0179  * hcall_notify_req_finish() - Notify ACRN Hypervisor of I/O request completion.
0180  * @vmid:   User VM ID
0181  * @vcpu:   The vCPU which initiated the I/O request
0182  *
0183  * Return: 0 on success, <0 on failure
0184  */
0185 static inline long hcall_notify_req_finish(u64 vmid, u64 vcpu)
0186 {
0187     return acrn_hypercall2(HC_NOTIFY_REQUEST_FINISH, vmid, vcpu);
0188 }
0189 
0190 /**
0191  * hcall_set_memory_regions() - Inform the hypervisor to set up EPT mappings
0192  * @regions_pa: Service VM GPA of &struct vm_memory_region_batch
0193  *
0194  * Return: 0 on success, <0 on failure
0195  */
0196 static inline long hcall_set_memory_regions(u64 regions_pa)
0197 {
0198     return acrn_hypercall1(HC_VM_SET_MEMORY_REGIONS, regions_pa);
0199 }
0200 
0201 /**
0202  * hcall_create_vdev() - Create a virtual device for a User VM
0203  * @vmid:   User VM ID
0204  * @addr:   Service VM GPA of the &struct acrn_vdev
0205  *
0206  * Return: 0 on success, <0 on failure
0207  */
0208 static inline long hcall_create_vdev(u64 vmid, u64 addr)
0209 {
0210     return acrn_hypercall2(HC_CREATE_VDEV, vmid, addr);
0211 }
0212 
0213 /**
0214  * hcall_destroy_vdev() - Destroy a virtual device of a User VM
0215  * @vmid:   User VM ID
0216  * @addr:   Service VM GPA of the &struct acrn_vdev
0217  *
0218  * Return: 0 on success, <0 on failure
0219  */
0220 static inline long hcall_destroy_vdev(u64 vmid, u64 addr)
0221 {
0222     return acrn_hypercall2(HC_DESTROY_VDEV, vmid, addr);
0223 }
0224 
0225 /**
0226  * hcall_assign_mmiodev() - Assign a MMIO device to a User VM
0227  * @vmid:   User VM ID
0228  * @addr:   Service VM GPA of the &struct acrn_mmiodev
0229  *
0230  * Return: 0 on success, <0 on failure
0231  */
0232 static inline long hcall_assign_mmiodev(u64 vmid, u64 addr)
0233 {
0234     return acrn_hypercall2(HC_ASSIGN_MMIODEV, vmid, addr);
0235 }
0236 
0237 /**
0238  * hcall_deassign_mmiodev() - De-assign a PCI device from a User VM
0239  * @vmid:   User VM ID
0240  * @addr:   Service VM GPA of the &struct acrn_mmiodev
0241  *
0242  * Return: 0 on success, <0 on failure
0243  */
0244 static inline long hcall_deassign_mmiodev(u64 vmid, u64 addr)
0245 {
0246     return acrn_hypercall2(HC_DEASSIGN_MMIODEV, vmid, addr);
0247 }
0248 
0249 /**
0250  * hcall_assign_pcidev() - Assign a PCI device to a User VM
0251  * @vmid:   User VM ID
0252  * @addr:   Service VM GPA of the &struct acrn_pcidev
0253  *
0254  * Return: 0 on success, <0 on failure
0255  */
0256 static inline long hcall_assign_pcidev(u64 vmid, u64 addr)
0257 {
0258     return acrn_hypercall2(HC_ASSIGN_PCIDEV, vmid, addr);
0259 }
0260 
0261 /**
0262  * hcall_deassign_pcidev() - De-assign a PCI device from a User VM
0263  * @vmid:   User VM ID
0264  * @addr:   Service VM GPA of the &struct acrn_pcidev
0265  *
0266  * Return: 0 on success, <0 on failure
0267  */
0268 static inline long hcall_deassign_pcidev(u64 vmid, u64 addr)
0269 {
0270     return acrn_hypercall2(HC_DEASSIGN_PCIDEV, vmid, addr);
0271 }
0272 
0273 /**
0274  * hcall_set_ptdev_intr() - Configure an interrupt for an assigned PCI device.
0275  * @vmid:   User VM ID
0276  * @irq:    Service VM GPA of the &struct acrn_ptdev_irq
0277  *
0278  * Return: 0 on success, <0 on failure
0279  */
0280 static inline long hcall_set_ptdev_intr(u64 vmid, u64 irq)
0281 {
0282     return acrn_hypercall2(HC_SET_PTDEV_INTR, vmid, irq);
0283 }
0284 
0285 /**
0286  * hcall_reset_ptdev_intr() - Reset an interrupt for an assigned PCI device.
0287  * @vmid:   User VM ID
0288  * @irq:    Service VM GPA of the &struct acrn_ptdev_irq
0289  *
0290  * Return: 0 on success, <0 on failure
0291  */
0292 static inline long hcall_reset_ptdev_intr(u64 vmid, u64 irq)
0293 {
0294     return acrn_hypercall2(HC_RESET_PTDEV_INTR, vmid, irq);
0295 }
0296 
0297 /*
0298  * hcall_get_cpu_state() - Get P-states and C-states info from the hypervisor
0299  * @state:  Service VM GPA of buffer of P-states and C-states
0300  */
0301 static inline long hcall_get_cpu_state(u64 cmd, u64 state)
0302 {
0303     return acrn_hypercall2(HC_PM_GET_CPU_STATE, cmd, state);
0304 }
0305 
0306 #endif /* __ACRN_HSM_HYPERCALL_H */