Skip to content

Commit

Permalink
hv: add hypercall to set vcpu init state
Browse files Browse the repository at this point in the history
DM will use this hypercall to initialize the UOS BSP state.

Tracked-On: #1231
Signed-off-by: Yin Fengwei <fengwei.yin@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
  • Loading branch information
fyin1 authored and wenlingz committed Oct 15, 2018
1 parent 66b53f8 commit 3cfbc00
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
5 changes: 5 additions & 0 deletions hypervisor/arch/x86/guest/vmcall.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ int vmcall_vmexit_handler(struct vcpu *vcpu)
ret = hcall_create_vcpu(vm, (uint16_t)param1, param2);
break;

case HC_SET_VCPU_REGS:
/* param1: vmid */
ret = hcall_set_vcpu_regs(vm, (uint16_t)param1, param2);
break;

case HC_ASSERT_IRQLINE:
/* param1: vmid */
ret = hcall_assert_irqline(vm, (uint16_t)param1, param2);
Expand Down
34 changes: 34 additions & 0 deletions hypervisor/common/hypercall.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,40 @@ int32_t hcall_pulse_irqline(struct vm *vm, uint16_t vmid, uint64_t param)
return ret;
}

/**
*@pre Pointer vm shall point to VM0
*/
int32_t hcall_set_vcpu_regs(struct vm *vm, uint16_t vmid, uint64_t param)
{
struct vm *target_vm = get_vm_from_vmid(vmid);
struct acrn_set_vcpu_regs vcpu_regs;
struct vcpu *vcpu;

if ((target_vm == NULL) || (param == 0U) || is_vm0(target_vm)) {
return -1;
}

/* Only allow setup init ctx while target_vm is inactive */
if (target_vm->state == VM_STARTED) {
return -1;
}

if (copy_from_gpa(vm, &vcpu_regs, param, sizeof(vcpu_regs)) != 0) {
pr_err("%s: Unable copy param to vm\n", __func__);
return -1;
}

vcpu = vcpu_from_vid(target_vm, vcpu_regs.vcpu_id);
if (vcpu == NULL) {
pr_err("%s: invalid vcpu_id for set_vcpu_regs\n", __func__);
return -1;
}

set_vcpu_regs(vcpu, &(vcpu_regs.vcpu_regs));

return 0;
}

/**
*@pre Pointer vm shall point to VM0
*/
Expand Down
16 changes: 16 additions & 0 deletions hypervisor/include/common/hypercall.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,22 @@ int32_t hcall_pause_vm(uint16_t vmid);
*/
int32_t hcall_create_vcpu(struct vm *vm, uint16_t vmid, uint64_t param);

/**
* @brief 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.
*
* @param vm Pointer to VM data structure
* @param vmid ID of the VM
* @param param guest physical address. This gpa points to
* struct acrn_vcpu_regs
*
* @return 0 on success, non-zero on error.
*/
int32_t hcall_set_vcpu_regs(struct vm *vm, uint16_t vmid, uint64_t param);

/**
* @brief assert IRQ line
*
Expand Down
16 changes: 16 additions & 0 deletions hypervisor/include/public/acrn_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,22 @@ struct acrn_vcpu_regs {
uint16_t reserved_16[4];
};

/**
* @brief Info to set vcpu state
*
* the pamameter for HC_SET_VCPU_STATE
*/
struct acrn_set_vcpu_regs {
/** the virtual CPU ID for the VCPU to set state */
uint16_t vcpu_id;

/** reserved space to make cpu_state aligned to 8 bytes */
uint16_t reserved0[3];

/** the structure to hold vcpu state */
struct acrn_vcpu_regs vcpu_regs;
} __attribute__((aligned(8)));

/**
* @brief Info to set ioreq buffer for a created VM
*
Expand Down
1 change: 1 addition & 0 deletions hypervisor/include/public/acrn_hv_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#define HC_PAUSE_VM BASE_HC_ID(HC_ID, HC_ID_VM_BASE + 0x03UL)
#define HC_CREATE_VCPU BASE_HC_ID(HC_ID, HC_ID_VM_BASE + 0x04UL)
#define HC_RESET_VM BASE_HC_ID(HC_ID, HC_ID_VM_BASE + 0x05UL)
#define HC_SET_VCPU_REGS BASE_HC_ID(HC_ID, HC_ID_VM_BASE + 0x06UL)

/* IRQ and Interrupts */
#define HC_ID_IRQ_BASE 0x20UL
Expand Down

0 comments on commit 3cfbc00

Please sign in to comment.