Extend sbuf hypercall to support other kinds of share buffer.
Signed-off-by: Conghui <conghui.chen@...>
Acked-by: Eddie Dong <eddie.dong@...>
---
hypervisor/arch/x86/guest/vmcall.c | 1 -
hypervisor/common/hypercall.c | 27 +++++++++++++++++++++
hypervisor/common/sbuf.c | 17 ++++++++++++++
hypervisor/debug/hypercall.c | 30 ------------------------
hypervisor/include/common/sbuf.h | 1 +
hypervisor/include/public/acrn_hv_defs.h | 8 +++----
hypervisor/release/hypercall.c | 6 -----
7 files changed, 49 insertions(+), 41 deletions(-)
diff --git a/hypervisor/arch/x86/guest/vmcall.c b/hypervisor/arch/x86/guest/vmcall.c
index a691149ba..66aac127c 100644
--- a/hypervisor/arch/x86/guest/vmcall.c
+++ b/hypervisor/arch/x86/guest/vmcall.c
@@ -181,7 +181,6 @@ struct acrn_vm *parse_target_vm(struct acrn_vm *service_vm, uint64_t hcall_id, u
case HC_GET_API_VERSION:
case HC_SERVICE_VM_OFFLINE_CPU:
case HC_SET_CALLBACK_VECTOR:
- case HC_SETUP_SBUF:
case HC_SETUP_HV_NPK_LOG:
case HC_PROFILING_OPS:
case HC_GET_HW_INFO:
diff --git a/hypervisor/common/hypercall.c b/hypervisor/common/hypercall.c
index 9d2ed892a..f86e3d9d7 100644
--- a/hypervisor/common/hypercall.c
+++ b/hypervisor/common/hypercall.c
@@ -518,6 +518,33 @@ int32_t hcall_set_ioreq_buffer(struct acrn_vcpu *vcpu, struct acrn_vm *target_vm
return ret;
}
+/**
+ * @brief Setup a share buffer for a VM.
+ *
+ * @param vcpu Pointer to vCPU that initiates the hypercall
+ * @param param1 guest physical address. This gpa points to
+ * struct sbuf_setup_param
+ *
+ * @pre is_service_vm(vcpu->vm)
+ * @return 0 on success, non-zero on error.
+ */
+int32_t hcall_setup_sbuf(struct acrn_vcpu *vcpu, struct acrn_vm *target_vm,
+ __unused uint64_t param1, uint64_t param2)
+{
+ struct acrn_vm *vm = vcpu->vm;
+ struct acrn_sbuf_param asp;
+ uint64_t *hva;
+ int ret = -1;
+
+ if (copy_from_gpa(vm, &asp, param2, sizeof(asp)) == 0) {
+ if (asp.gpa != 0U) {
+ hva = (uint64_t *)gpa2hva(vm, asp.gpa);
+ ret = sbuf_setup_common(target_vm, asp.cpu_id, asp.sbuf_id, hva);
+ }
+ }
+ return ret;
+}
+
/**
* @brief notify request done
*
diff --git a/hypervisor/common/sbuf.c b/hypervisor/common/sbuf.c
index 533ff712c..36ce9d2fa 100644
--- a/hypervisor/common/sbuf.c
+++ b/hypervisor/common/sbuf.c
@@ -79,4 +79,21 @@ uint32_t sbuf_put(struct shared_buf *sbuf, uint8_t *data)
return ele_size;
}
+int32_t sbuf_setup_common(__unused struct acrn_vm *vm, uint16_t cpu_id, uint32_t sbuf_id, uint64_t *hva)
+{
+ int32_t ret = 0;
+
+ switch (sbuf_id) {
+ case ACRN_TRACE:
+ case ACRN_HVLOG:
+ case ACRN_SEP:
+ case ACRN_SOCWATCH:
+ ret = sbuf_share_setup(cpu_id, sbuf_id, hva);
+ break;
+ default:
+ pr_err("%s not support sbuf_id %d", __func__, sbuf_id);
+ ret = -1;
+ }
+ return ret;
+}
diff --git a/hypervisor/debug/hypercall.c b/hypervisor/debug/hypercall.c
index 88374e15f..92cb80038 100644
--- a/hypervisor/debug/hypercall.c
+++ b/hypervisor/debug/hypercall.c
@@ -69,36 +69,6 @@ int32_t hcall_profiling_ops(struct acrn_vcpu *vcpu, __unused struct acrn_vm *tar
}
#endif /* PROFILING_ON */
-/**
- * @brief Setup a share buffer for a VM.
- *
- * @param vcpu Pointer to vCPU that initiates the hypercall
- * @param param1 guest physical address. This gpa points to
- * struct sbuf_setup_param
- *
- * @pre is_service_vm(vcpu->vm)
- * @return 0 on success, non-zero on error.
- */
-int32_t hcall_setup_sbuf(struct acrn_vcpu *vcpu, __unused struct acrn_vm *target_vm,
- uint64_t param1, __unused uint64_t param2)
-{
- struct acrn_vm *vm = vcpu->vm;
- struct sbuf_setup_param ssp;
- uint64_t *hva;
-
- if (copy_from_gpa(vm, &ssp, param1, sizeof(ssp)) != 0) {
- return -1;
- }
-
- if (ssp.gpa != 0U) {
- hva = (uint64_t *)gpa2hva(vm, ssp.gpa);
- } else {
- hva = (uint64_t *)NULL;
- }
-
- return sbuf_share_setup(ssp.pcpu_id, ssp.sbuf_id, hva);
-}
-
/**
* @brief Setup the hypervisor NPK log.
*
diff --git a/hypervisor/include/common/sbuf.h b/hypervisor/include/common/sbuf.h
index c5440f5a4..34a1b9e3c 100644
--- a/hypervisor/include/common/sbuf.h
+++ b/hypervisor/include/common/sbuf.h
@@ -21,5 +21,6 @@ uint32_t sbuf_put(struct shared_buf *sbuf, uint8_t *data);
int32_t sbuf_share_setup(uint16_t cpu_id, uint32_t sbuf_id, uint64_t *hva);
void sbuf_reset(void);
uint32_t sbuf_next_ptr(uint32_t pos, uint32_t span, uint32_t scope);
+int32_t sbuf_setup_common(__unused struct acrn_vm *vm, uint16_t cpu_id, uint32_t sbuf_id, uint64_t *hva);
#endif /* SHARED_BUFFER_H */
diff --git a/hypervisor/include/public/acrn_hv_defs.h b/hypervisor/include/public/acrn_hv_defs.h
index 728948186..c36955f4b 100644
--- a/hypervisor/include/public/acrn_hv_defs.h
+++ b/hypervisor/include/public/acrn_hv_defs.h
@@ -56,6 +56,7 @@
#define HC_VM_GPA2HPA BASE_HC_ID(HC_ID, HC_ID_MEM_BASE + 0x01UL)
#define HC_VM_SET_MEMORY_REGIONS BASE_HC_ID(HC_ID, HC_ID_MEM_BASE + 0x02UL)
#define HC_VM_WRITE_PROTECT_PAGE BASE_HC_ID(HC_ID, HC_ID_MEM_BASE + 0x03UL)
+#define HC_SETUP_SBUF BASE_HC_ID(HC_ID, HC_ID_MEM_BASE + 0x04UL)
/* PCI assignment*/
#define HC_ID_PCI_BASE 0x50UL
@@ -73,7 +74,6 @@
/* DEBUG */
#define HC_ID_DBG_BASE 0x60UL
-#define HC_SETUP_SBUF BASE_HC_ID(HC_ID, HC_ID_DBG_BASE + 0x00UL)
#define HC_SETUP_HV_NPK_LOG BASE_HC_ID(HC_ID, HC_ID_DBG_BASE + 0x01UL)
#define HC_PROFILING_OPS BASE_HC_ID(HC_ID, HC_ID_DBG_BASE + 0x02UL)
#define HC_GET_HW_INFO BASE_HC_ID(HC_ID, HC_ID_DBG_BASE + 0x03UL)
@@ -186,9 +186,9 @@ struct wp_data {
/**
* Setup parameter for share buffer, used for HC_SETUP_SBUF hypercall
*/
-struct sbuf_setup_param {
- /** sbuf physical cpu id */
- uint16_t pcpu_id;
+struct acrn_sbuf_param {
+ /** sbuf cpu id */
+ uint16_t cpu_id;
/** Reserved */
uint16_t reserved;
diff --git a/hypervisor/release/hypercall.c b/hypervisor/release/hypercall.c
index e2f84842b..b166a6a74 100644
--- a/hypervisor/release/hypercall.c
+++ b/hypervisor/release/hypercall.c
@@ -8,12 +8,6 @@
#include <errno.h>
#include <asm/guest/vm.h>
-int32_t hcall_setup_sbuf(__unused struct acrn_vcpu *vcpu, __unused struct acrn_vm *target_vm,
- __unused uint64_t param1, __unused uint64_t param2)
-{
- return -EPERM;
-}
-
int32_t hcall_setup_hv_npk_log(__unused struct acrn_vcpu *vcpu, __unused struct acrn_vm *target_vm,
__unused uint64_t param1, __unused uint64_t param2)
{
--
2.25.1