Hypercall APIs¶
This section contains APIs for the hypercall services. Sources for the Device Model are found in the ACRN Hypervisor GitHub repo
-
group
acrn_hypercall
Hypercall.
Defines
-
GSI_SET_HIGH
¶ Operation types for setting IRQ line
-
GSI_SET_LOW
¶
-
GSI_RAISING_PULSE
¶
-
GSI_FALLING_PULSE
¶
-
SPACE_SYSTEM_MEMORY
¶ Info The power state data of a VCPU.
-
SPACE_SYSTEM_IO
¶
-
SPACE_PCI_CONFIG
¶
-
SPACE_Embedded_Control
¶
-
SPACE_SMBUS
¶
-
SPACE_PLATFORM_COMM
¶
-
SPACE_FFixedHW
¶
-
PMCMD_VMID_MASK
¶ Info PM command from DM/VHM.
The command would specify request type(e.g. get px count or data) for specific VM and specific VCPU with specific state number. For Px, PMCMD_STATE_NUM means Px number from 0 to (MAX_PSTATE - 1), For Cx, PMCMD_STATE_NUM means Cx entry index from 1 to MAX_CX_ENTRY.
-
PMCMD_VCPUID_MASK
¶
-
PMCMD_STATE_NUM_MASK
¶
-
PMCMD_TYPE_MASK
¶
-
PMCMD_VMID_SHIFT
¶
-
PMCMD_VCPUID_SHIFT
¶
-
PMCMD_STATE_NUM_SHIFT
¶
-
MAX_PTDEV_NUM
¶ Info to get a VM interrupt count data.
the parameter for HC_VM_INTR_MONITOR hypercall
-
INTR_CMD_GET_DATA
¶ cmd for intr monitor
-
INTR_CMD_DELAY_INT
¶
Enums
Functions
-
int32_t
hcall_sos_offline_cpu
(struct acrn_vm *vm, uint64_t lapicid)¶ offline vcpu from SOS
The function offline specific vcpu from SOS.
- Pre
- Pointer vm shall point to VM0
- Return
- 0 on success, non-zero on error.
- Parameters
vm
: Pointer to VM data structurelapicid
: lapic id of the vcpu which wants to offline
-
int32_t
hcall_get_api_version
(struct acrn_vm *vm, uint64_t param)¶ Get hypervisor api version.
The function only return api version information when VM is VM0.
- Pre
- Pointer vm shall point to VM0
- Return
- 0 on success, non-zero on error.
- Parameters
vm
: Pointer to VM data structureparam
: guest physical memory address. The api version returned will be copied to this gpa
-
int32_t
hcall_create_vm
(struct acrn_vm *vm, uint64_t param)¶ create virtual machine
Create a virtual machine based on parameter, currently there is no limitation for calling times of this function, will add MAX_VM_NUM support later.
- Pre
- Pointer vm shall point to VM0
- Return
- 0 on success, non-zero on error.
- Parameters
vm
: Pointer to VM data structureparam
: guest physical memory address. This gpa points to struct acrn_create_vm
-
int32_t
hcall_destroy_vm
(uint16_t vmid)¶ destroy virtual machine
Destroy a virtual machine, it will pause target VM then shutdown it. The function will return -1 if the target VM does not exist.
- Return
- 0 on success, non-zero on error.
- Parameters
vmid
: ID of the VM
-
int32_t
hcall_reset_vm
(uint16_t vmid)¶ reset virtual machine
Reset a virtual machine, it will make target VM rerun from pre-defined entry. Comparing to start vm, this function reset each vcpu state and do some initialization for guest. The function will return -1 if the target VM does not exist.
- Return
- 0 on success, non-zero on error.
- Parameters
vmid
: ID of the VM
-
int32_t
hcall_start_vm
(uint16_t vmid)¶ start virtual machine
Start a virtual machine, it will schedule target VM’s vcpu to run. The function will return -1 if the target VM does not exist or the IOReq buffer page for the VM is not ready.
- Return
- 0 on success, non-zero on error.
- Parameters
vmid
: ID of the VM
-
int32_t
hcall_pause_vm
(uint16_t vmid)¶ pause virtual machine
Pause a virtual machine, if the VM is already paused, the function will return 0 directly for success. The function will return -1 if the target VM does not exist.
- Return
- 0 on success, non-zero on error.
- Parameters
vmid
: ID of the VM
-
int32_t
hcall_create_vcpu
(struct acrn_vm *vm, uint16_t vmid, uint64_t param)¶ create vcpu
Create a vcpu based on parameter for a VM, it will allocate vcpu from freed physical cpus, if there is no available pcpu, the function will return -1.
- Pre
- Pointer vm shall point to VM0
- Return
- 0 on success, non-zero on error.
- Parameters
vm
: Pointer to VM data structurevmid
: ID of the VMparam
: guest physical address. This gpa points to struct acrn_create_vcpu
-
int32_t
hcall_set_vcpu_regs
(struct acrn_vm *vm, uint16_t vmid, uint64_t param)¶ set vcpu regs
Set the vcpu regs. It will set the vcpu init regs from DM. Now, it’s only applied to BSP. AP always uses fixed init regs. The function will return -1 if the targat VM or BSP doesn’t exist.
- Return
- 0 on success, non-zero on error.
- Parameters
vm
: Pointer to VM data structurevmid
: ID of the VMparam
: guest physical address. This gpa points to struct acrn_vcpu_regs
-
int32_t
hcall_set_irqline
(const struct acrn_vm *vm, uint16_t vmid, const struct acrn_irqline_ops *ops)¶ set or clear IRQ line
Set or clear a virtual IRQ line for a VM, which could be from ISA or IOAPIC, normally it triggers an edge IRQ. The function will return -1 if the target VM does not exist.
- Pre
- Pointer vm shall point to VM0
- Return
- 0 on success, non-zero on error.
- Parameters
vm
: Pointer to VM data structurevmid
: ID of the VMops
: request command for IRQ set or clear
-
int32_t
hcall_inject_msi
(struct acrn_vm *vm, uint16_t vmid, uint64_t param)¶ inject MSI interrupt
Inject a MSI interrupt for a VM. The function will return -1 if the target VM does not exist.
- Pre
- Pointer vm shall point to VM0
- Return
- 0 on success, non-zero on error.
- Parameters
vm
: Pointer to VM data structurevmid
: ID of the VMparam
: guest physical address. This gpa points to struct acrn_msi_entry
-
int32_t
hcall_set_ioreq_buffer
(struct acrn_vm *vm, uint16_t vmid, uint64_t param)¶ set ioreq shared buffer
Set the ioreq share buffer for a VM. The function will return -1 if the target VM does not exist.
- Pre
- Pointer vm shall point to VM0
- Return
- 0 on success, non-zero on error.
- Parameters
vm
: Pointer to VM data structurevmid
: ID of the VMparam
: guest physical address. This gpa points to struct acrn_set_ioreq_buffer
-
int32_t
hcall_notify_ioreq_finish
(uint16_t vmid, uint16_t vcpu_id)¶ notify request done
Notify the requestor VCPU for the completion of an ioreq. The function will return -1 if the target VM does not exist.
- Return
- 0 on success, non-zero on error.
- Parameters
vmid
: ID of the VMvcpu_id
: vcpu ID of the requestor
-
int32_t
hcall_set_vm_memory_regions
(struct acrn_vm *vm, uint64_t param)¶ setup ept memory mapping for multi regions
- Pre
- Pointer vm shall point to VM0
- Return
- 0 on success, non-zero on error.
- Parameters
vm
: Pointer to VM data structureparam
: guest physical address. This gpa points to struct set_memmaps
-
int32_t
hcall_write_protect_page
(struct acrn_vm *vm, uint16_t vmid, uint64_t wp_gpa)¶ change guest memory page write permission
- Pre
- Pointer vm shall point to VM0
- Return
- 0 on success, non-zero on error.
- Parameters
vm
: Pointer to VM data structurevmid
: ID of the VMwp_gpa
: guest physical address. This gpa points to struct wp_data
-
int32_t
hcall_gpa_to_hpa
(struct acrn_vm *vm, uint16_t vmid, uint64_t param)¶ translate guest physical address to host physical address
Translate guest physical address to host physical address for a VM. The function will return -1 if the target VM does not exist.
- Pre
- Pointer vm shall point to VM0
- Return
- 0 on success, non-zero on error.
- Parameters
vm
: Pointer to VM data structurevmid
: ID of the VMparam
: guest physical address. This gpa points to struct vm_gpa2hpa
-
int32_t
hcall_assign_ptdev
(struct acrn_vm *vm, uint16_t vmid, uint64_t param)¶ Assign one passthrough dev to VM.
- Pre
- Pointer vm shall point to VM0
- Return
- 0 on success, non-zero on error.
- Parameters
vm
: Pointer to VM data structurevmid
: ID of the VMparam
: the physical BDF of the assigning ptdev To keep the compatibility it still can be the guest physical address that points to the physical BDF of the assigning ptdev.(Depreciated)
-
int32_t
hcall_deassign_ptdev
(struct acrn_vm *vm, uint16_t vmid, uint64_t param)¶ Deassign one passthrough dev from VM.
- Pre
- Pointer vm shall point to VM0
- Return
- 0 on success, non-zero on error.
- Parameters
vm
: Pointer to VM data structurevmid
: ID of the VMparam
: the physical BDF of the deassigning ptdev To keep the compatibility it still can be the guest physical address that points to the physical BDF of the deassigning ptdev.(Depreciated)
-
int32_t
hcall_set_ptdev_intr_info
(struct acrn_vm *vm, uint16_t vmid, uint64_t param)¶ Set interrupt mapping info of ptdev.
- Pre
- Pointer vm shall point to VM0
- Return
- 0 on success, non-zero on error.
- Parameters
vm
: Pointer to VM data structurevmid
: ID of the VMparam
: guest physical address. This gpa points to data structure of hc_ptdev_irq including intr remapping info
-
int32_t
hcall_reset_ptdev_intr_info
(struct acrn_vm *vm, uint16_t vmid, uint64_t param)¶ Clear interrupt mapping info of ptdev.
- Pre
- Pointer vm shall point to VM0
- Return
- 0 on success, non-zero on error.
- Parameters
vm
: Pointer to VM data structurevmid
: ID of the VMparam
: guest physical address. This gpa points to data structure of hc_ptdev_irq including intr remapping info
-
int32_t
hcall_debug
(struct acrn_vm *vm, uint64_t param1, uint64_t param2, uint64_t hypcall_id)¶ Setup hypervisor debug infrastructure, such as share buffer, NPK log and profiling.
- Pre
- Pointer vm shall point to VM0
- Return
- 0 on success, non-zero on error.
- Parameters
vm
: Pointer to VM data structureparam1
: hypercall param1 from guestparam2
: hypercall param2 from guesthypcall_id
: hypercall ID from guest
-
int32_t
hcall_get_cpu_pm_state
(struct acrn_vm *vm, uint64_t cmd, uint64_t param)¶ Get VCPU Power state.
- Pre
- Pointer vm shall point to VM0
- Return
- 0 on success, non-zero on error.
- Parameters
vm
: pointer to VM data structurecmd
: cmd to show get which VCPU power state dataparam
: VCPU power state data
-
int32_t
hcall_vm_intr_monitor
(struct acrn_vm *vm, uint16_t vmid, uint64_t param)¶ Get VCPU a VM’s interrupt count data.
- Pre
- Pointer vm shall point to VM0
- Return
- 0 on success, non-zero on error.
- Parameters
vm
: pointer to VM data structurevmid
: id of the VMparam
: guest physical address. This gpa points to data structure of acrn_intr_monitor
-
int32_t
hcall_set_callback_vector
(const struct acrn_vm *vm, uint64_t param)¶ set upcall notifier vector
This is the API that helps to switch the notifer vecotr. If this API is not called, the hypervisor will use the default notifier vector(0xF7) to notify the SOS kernel.
- Pre
- Pointer vm shall point to VM0
- Return
- 0 on success, non-zero on error.
- Parameters
vm
: Pointer to VM data structureparam
: the expected notifier vector from guest
-
struct
mmio_request
¶ - #include <acrn_common.h>
Representation of a MMIO request.
-
struct
pio_request
¶ - #include <acrn_common.h>
Representation of a port I/O request.
Public Members
-
uint32_t
direction
¶ Direction of the access.
Either
REQUEST_READ
orREQUEST_WRITE
.
-
uint32_t
reserved
¶ reserved
-
uint64_t
address
¶ Port address of the I/O access.
-
uint64_t
size
¶ Width of the I/O access in byte.
-
uint32_t
value
¶ The value read for I/O reads or to be written for I/O writes.
-
uint32_t
-
struct
pci_request
¶ - #include <acrn_common.h>
Representation of a PCI configuration space access.
Public Members
-
uint32_t
direction
¶ Direction of the access.
Either
REQUEST_READ
orREQUEST_WRITE
.
-
uint32_t
reserved
[3]¶ Reserved.
-
int64_t
size
¶ Width of the I/O access in byte.
-
int32_t
value
¶ The value read for I/O reads or to be written for I/O writes.
-
int32_t
bus
¶ The
bus
part of the BDF of the device.
-
int32_t
dev
¶ The
device
part of the BDF of the device.
-
int32_t
func
¶ The
function
part of the BDF of the device.
-
int32_t
reg
¶ The register to be accessed in the configuration space.
-
uint32_t
-
union
vhm_io_request
¶ - #include <acrn_common.h>
Public Members
-
struct pio_request
pio
¶
-
struct pci_request
pci
¶
-
struct mmio_request
mmio
¶
-
int64_t
reserved1
[8]¶
-
struct pio_request
-
struct
vhm_request
¶ - #include <acrn_common.h>
256-byte VHM requests
The state transitions of a VHM request are:
FREE -> PENDING -> PROCESSING -> COMPLETE -> FREE -> …
When a request is in COMPLETE or FREE state, the request is owned by the hypervisor. SOS (VHM or DM) shall not read or write the internals of the request except the state.
When a request is in PENDING or PROCESSING state, the request is owned by SOS. The hypervisor shall not read or write the request other than the state.
Based on the rules above, a typical VHM request lifecycle should looks like the following.
SOS vCPU 0 SOS vCPU x UOS vCPU y Hypervisor:
- Fill in type, addr, etc.
- Pause UOS vCPU y
- Set state to PENDING (a)
- Fire upcall to SOS vCPU 0
VHM:
- Scan for pending requests
- Set state to PROCESSING (b)
- Assign requests to clients (c)
Client:
- Scan for assigned requests
- Handle the requests (d)
- Set state to COMPLETE
- Notify the hypervisor
Hypervisor:
- resume UOS vCPU y (e)
Hypervisor:
- Post-work (f)
- set state to FREE
Note that the following shall hold.
- (a) happens before (b)
- (c) happens before (d)
- (e) happens before (f)
- One vCPU cannot trigger another I/O request before the previous one has completed (i.e. the state switched to FREE)
Accesses to the state of a vhm_request shall be atomic and proper barriers are needed to ensure that:
- Setting state to PENDING is the last operation when issuing a request in the hypervisor, as the hypervisor shall not access the request any more.
- Due to similar reasons, setting state to COMPLETE is the last operation of request handling in VHM or clients in SOS.
Public Members
-
uint32_t
type
¶ Type of this request.
Byte offset: 0.
-
uint32_t
completion_polling
¶ Hypervisor will poll completion if set.
Byte offset: 4.
-
uint32_t
reserved0
[14]¶ Reserved.
Byte offset: 8.
-
union vhm_io_request
reqs
¶ Details about this request.
For REQ_PORTIO, this has type pio_request. For REQ_MMIO and REQ_WP, this has type mmio_request. For REQ_PCICFG, this has type pci_request.
Byte offset: 64.
-
uint32_t
reserved1
¶ Reserved.
Byte offset: 128.
-
int32_t
client
¶ The client which is distributed to handle this request.
Accessed by VHM only.
Byte offset: 132.
-
uint32_t
processed
¶ The status of this request.
Taking REQ_STATE_xxx as values.
Byte offset: 136.
-
union
vhm_request_buffer
¶ - #include <acrn_common.h>
-
struct
acrn_create_vm
¶ - #include <acrn_common.h>
Info to create a VM, the parameter for HC_CREATE_VM hypercall.
-
struct
acrn_create_vcpu
¶ - #include <acrn_common.h>
Info to create a VCPU.
the parameter for HC_CREATE_VCPU hypercall
-
struct
acrn_gp_regs
¶ - #include <acrn_common.h>
-
struct
acrn_descriptor_ptr
¶ - #include <acrn_common.h>
-
struct
acrn_vcpu_regs
¶ - #include <acrn_common.h>
registers info for vcpu.
Public Members
-
struct acrn_gp_regs
gprs
¶
-
struct acrn_descriptor_ptr
gdt
¶
-
struct acrn_descriptor_ptr
idt
¶
-
uint64_t
rip
¶
-
uint64_t
cs_base
¶
-
uint64_t
cr0
¶
-
uint64_t
cr4
¶
-
uint64_t
cr3
¶
-
uint64_t
ia32_efer
¶
-
uint64_t
rflags
¶
-
uint64_t
reserved_64
[4]¶
-
uint32_t
cs_ar
¶
-
uint32_t
cs_limit
¶
-
uint32_t
reserved_32
[3]¶
-
uint16_t
cs_sel
¶
-
uint16_t
ss_sel
¶
-
uint16_t
ds_sel
¶
-
uint16_t
es_sel
¶
-
uint16_t
fs_sel
¶
-
uint16_t
gs_sel
¶
-
uint16_t
ldt_sel
¶
-
uint16_t
tr_sel
¶
-
uint16_t
reserved_16
[4]¶
-
struct acrn_gp_regs
-
struct
acrn_set_vcpu_regs
¶ - #include <acrn_common.h>
Info to set vcpu state.
the pamameter for HC_SET_VCPU_STATE
Public Members
-
uint16_t
vcpu_id
¶ the virtual CPU ID for the VCPU to set state
-
uint16_t
reserved0
[3]¶ reserved space to make cpu_state aligned to 8 bytes
-
struct acrn_vcpu_regs
vcpu_regs
¶ the structure to hold vcpu state
-
uint16_t
-
struct
acrn_set_ioreq_buffer
¶ - #include <acrn_common.h>
Info to set ioreq buffer for a created VM.
the parameter for HC_SET_IOREQ_BUFFER hypercall
Public Members
-
uint64_t
req_buf
¶ guest physical address of VM request_buffer
-
uint64_t
-
struct
acrn_irqline_ops
¶ - #include <acrn_common.h>
Info to Set/Clear/Pulse a virtual IRQ line for a VM.
the parameter for HC_SET_IRQLINE hypercall
-
struct
acrn_msi_entry
¶ - #include <acrn_common.h>
Info to inject a MSI interrupt to VM.
the parameter for HC_INJECT_MSI hypercall
-
struct
acrn_nmi_entry
¶ - #include <acrn_common.h>
Info to inject a NMI interrupt for a VM.
-
struct
acrn_vm_pci_msix_remap
¶ - #include <acrn_common.h>
Info to remap pass-through PCI MSI for a VM.
the parameter for HC_VM_PCI_MSIX_REMAP hypercall
Public Members
-
uint16_t
virt_bdf
¶ pass-through PCI device virtual BDF#
-
uint16_t
phys_bdf
¶ pass-through PCI device physical BDF#
-
uint16_t
msi_ctl
¶ pass-through PCI device MSI/MSI-X cap control data
-
uint16_t
reserved
¶ reserved for alignment padding
-
uint64_t
msi_addr
¶ pass-through PCI device MSI address to remap, which will return the caller after remapping
-
uint32_t
msi_data
¶ pass-through PCI device MSI data to remap, which will return the caller after remapping
-
int32_t
msix
¶ pass-through PCI device is MSI or MSI-X 0 - MSI, 1 - MSI-X
-
uint32_t
msix_entry_index
¶ if the pass-through PCI device is MSI-X, this field contains the MSI-X entry table index
-
uint32_t
vector_ctl
¶ if the pass-through PCI device is MSI-X, this field contains Vector Control for MSI-X Entry, field defined in MSI-X spec
-
uint16_t
-
struct
acpi_generic_address
¶ - #include <acrn_common.h>
-
struct
cpu_cx_data
¶ - #include <acrn_common.h>
-
struct
cpu_px_data
¶ - #include <acrn_common.h>
-
struct
acpi_sx_pkg
¶ - #include <acrn_common.h>
-
struct
pm_s_state_data
¶ - #include <acrn_common.h>
Public Members
-
struct acpi_generic_address
pm1a_evt
¶
-
struct acpi_generic_address
pm1b_evt
¶
-
struct acpi_generic_address
pm1a_cnt
¶
-
struct acpi_generic_address
pm1b_cnt
¶
-
struct acpi_sx_pkg
s3_pkg
¶
-
struct acpi_sx_pkg
s5_pkg
¶
-
uint32_t *
wake_vector_32
¶
-
uint64_t *
wake_vector_64
¶
-
struct acpi_generic_address
-
struct
acrn_intr_monitor
¶ - #include <acrn_common.h>
-
struct
vm_memory_region
¶ - #include <acrn_hv_defs.h>
Info to set guest memory region mapping.
the parameter for HC_VM_SET_MEMORY_REGION hypercall
Public Members
-
uint32_t
type
¶ set memory region type: MR_ADD or MAP_DEL
-
uint32_t
prot
¶ memory attributes: memory type + RWX access right
-
uint64_t
gpa
¶ the beginning guest physical address of the memory reion
-
uint64_t
vm0_gpa
¶ VM0’s guest physcial address which gpa will be mapped to
-
uint64_t
size
¶ size of the memory region
-
uint32_t
-
struct
set_regions
¶ - #include <acrn_hv_defs.h>
set multi memory regions, used for HC_VM_SET_MEMORY_REGIONS
Public Members
-
uint16_t
vmid
¶ vmid for this hypercall
-
uint16_t
reserved0
¶ Reserved
-
uint32_t
reserved1
¶ Reserved
-
uint32_t
mr_num
¶ memory region numbers
-
uint64_t
regions_gpa
¶ the gpa of regions buffer, point to the regions array: struct vm_memory_region regions[mr_num] the max buffer size is one page.
-
uint16_t
-
struct
wp_data
¶ - #include <acrn_hv_defs.h>
Info to change guest one page write protect permission.
the parameter for HC_VM_WRITE_PROTECT_PAGE hypercall
-
struct
sbuf_setup_param
¶ - #include <acrn_hv_defs.h>
Setup parameter for share buffer, used for HC_SETUP_SBUF hypercall
-
struct
hv_npk_log_param
¶ - #include <acrn_hv_defs.h>
Info to setup the hypervisor NPK log.
the parameter for HC_SETUP_HV_NPK_LOG hypercall
-
struct
vm_gpa2hpa
¶ - #include <acrn_hv_defs.h>
Gpa to hpa translation parameter, used for HC_VM_GPA2HPA hypercall
-
struct
hc_ptdev_irq
¶ - #include <acrn_hv_defs.h>
Intr mapping info per ptdev, the parameter for HC_SET_PTDEV_INTR_INFO hypercall
- union
Public Members
-
INTX remapping info
-
MSIx remapping info
-
- struct
INTX remapping info
Public Members
-
virtual IOAPIC/PIC pin
-
Reserved
-
physical IOAPIC pin
-
Reserved
-
is virtual pin from PIC
-
Reserved
-
- struct
MSIx remapping info
Public Members
-
vector count of MSI/MSIX
-
-
struct
hc_api_version
¶ - #include <acrn_hv_defs.h>
Hypervisor api version info, return it for HC_GET_API_VERSION hypercall
-
struct
trusty_boot_param
¶ - #include <acrn_hv_defs.h>
Trusty boot params, used for HC_INITIALIZE_TRUSTY
Public Members
-
uint32_t
size_of_this_struct
¶ sizeof this structure
-
uint32_t
version
¶ version of this structure
-
uint32_t
base_addr
¶ trusty runtime memory base address
-
uint32_t
entry_point
¶ trusty entry point
-
uint32_t
mem_size
¶ trusty runtime memory size
-
uint32_t
padding
¶ padding
-
uint32_t
base_addr_high
¶ trusty runtime memory base address (high 32bit)
-
uint32_t
entry_point_high
¶ trusty entry point (high 32bit)
-
uint8_t
rpmb_key
[64]¶ rpmb key
-
uint32_t
-