From 46480f6e23c088eb6f749ec25e142894277024a8 Mon Sep 17 00:00:00 2001 From: Yonghua Huang Date: Fri, 15 Feb 2019 19:57:36 +0800 Subject: [PATCH] hv: add new hypercall to fetch platform configurations add new hypercall get platform information, such as physical CPU number. Tracked-On: #2538 Signed-off-by: Yonghua Huang Acked-by: Eddie Dong --- hypervisor/arch/x86/guest/vmcall.c | 4 ++++ hypervisor/common/hypercall.c | 27 ++++++++++++++++++++++++ hypervisor/include/common/hypercall.h | 15 +++++++++++++ hypervisor/include/public/acrn_hv_defs.h | 20 ++++++++++++++++++ 4 files changed, 66 insertions(+) diff --git a/hypervisor/arch/x86/guest/vmcall.c b/hypervisor/arch/x86/guest/vmcall.c index f00c528f6..cee479719 100644 --- a/hypervisor/arch/x86/guest/vmcall.c +++ b/hypervisor/arch/x86/guest/vmcall.c @@ -40,6 +40,10 @@ static int32_t dispatch_hypercall(struct acrn_vcpu *vcpu) ret = hcall_get_api_version(vm, param1); break; + case HC_GET_PLATFORM_INFO: + ret = hcall_get_platform_info(vm, param1); + break; + case HC_SET_CALLBACK_VECTOR: ret = hcall_set_callback_vector(vm, param1); diff --git a/hypervisor/common/hypercall.c b/hypervisor/common/hypercall.c index ea4cf5039..e4dd4be0b 100644 --- a/hypervisor/common/hypercall.c +++ b/hypervisor/common/hypercall.c @@ -102,6 +102,33 @@ int32_t hcall_get_api_version(struct acrn_vm *vm, uint64_t param) return ret; } +/** + * @brief Get basic platform information. + * + * The function returns basic hardware or configuration information + * for the current platform. + * + * @param vm Pointer to VM data structure. + * @param param GPA pointer to struct hc_platform_info. + * + * @pre Pointer vm shall point to SOS_VM + * @return 0 on success, -1 in case of error. + */ +int32_t hcall_get_platform_info(struct acrn_vm *vm, uint64_t param) +{ + int32_t ret = 0; + struct hc_platform_info platform_info; + + platform_info.cpu_num = get_pcpu_nums(); + platform_info.max_vcpus_per_vm = CONFIG_MAX_VCPUS_PER_VM; + if (copy_to_gpa(vm, &platform_info, param, sizeof(platform_info)) != 0) { + pr_err("%s: Unable copy param to vm\n", __func__); + ret = -1; + } + + return ret; +} + /** * @brief create virtual machine * diff --git a/hypervisor/include/common/hypercall.h b/hypervisor/include/common/hypercall.h index 0c87c121a..2fe8bf9cd 100644 --- a/hypervisor/include/common/hypercall.h +++ b/hypervisor/include/common/hypercall.h @@ -51,6 +51,21 @@ int32_t hcall_sos_offline_cpu(struct acrn_vm *vm, uint64_t lapicid); */ int32_t hcall_get_api_version(struct acrn_vm *vm, uint64_t param); + +/** + * @brief Get basic platform information. + * + * The function returns basic hardware or configuration information + * for the current platform. + * + * @param vm Pointer to VM data structure. + * @param param GPA pointer to struct hc_platform_info. + * + * @pre Pointer vm shall point to SOS_VM + * @return 0 on success, -1 in case of error. + */ +int32_t hcall_get_platform_info(struct acrn_vm *vm, uint64_t param); + /** * @brief create virtual machine * diff --git a/hypervisor/include/public/acrn_hv_defs.h b/hypervisor/include/public/acrn_hv_defs.h index b009cc767..5a4abafcc 100644 --- a/hypervisor/include/public/acrn_hv_defs.h +++ b/hypervisor/include/public/acrn_hv_defs.h @@ -28,6 +28,7 @@ #define HC_GET_API_VERSION BASE_HC_ID(HC_ID, HC_ID_GEN_BASE + 0x00UL) #define HC_SOS_OFFLINE_CPU BASE_HC_ID(HC_ID, HC_ID_GEN_BASE + 0x01UL) #define HC_SET_CALLBACK_VECTOR BASE_HC_ID(HC_ID, HC_ID_GEN_BASE + 0x02UL) +#define HC_GET_PLATFORM_INFO BASE_HC_ID(HC_ID, HC_ID_GEN_BASE + 0x03UL) /* VM management */ #define HC_ID_VM_BASE 0x10UL @@ -281,6 +282,25 @@ struct hc_api_version { uint32_t minor_version; } __aligned(8); +/** + * Hypervisor API, return it for HC_GET_PLATFORM_INFO hypercall + */ +struct hc_platform_info { + /** Hardware Information */ + /** Physical CPU number */ + uint16_t cpu_num; + + /** Align the size of version & hardware info to 128Bytes. */ + uint8_t reserved0[126]; + + /** Configuration Information */ + /** Maximum vCPU number for one VM. */ + uint16_t max_vcpus_per_vm; + + /** Align the size of Configuration info to 128Bytes. */ + uint8_t reserved1[126]; +} __aligned(8); + /** * Trusty boot params, used for HC_INITIALIZE_TRUSTY */