mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-09-30 21:16:03 +00:00
hv: refine IOREQ state operation functions in hypervisor
1) add functions to set/get VHM request state. 2) modify 'complete_ioreq()' in io.c 3) update the caller code Tracked-On: #2056 Signed-off-by: Yonghua Huang <yonghua.huang@intel.com> Acked-by: Anthony Xu <anthony.xu@intel.com>
This commit is contained in:
@@ -65,30 +65,15 @@ static void acrn_print_request(uint16_t vcpu_id, const struct vhm_request *req)
|
||||
void reset_vm_ioreqs(struct acrn_vm *vm)
|
||||
{
|
||||
uint16_t i;
|
||||
union vhm_request_buffer *req_buf;
|
||||
|
||||
req_buf = vm->sw.io_shared_page;
|
||||
for (i = 0U; i < VHM_REQUEST_MAX; i++) {
|
||||
atomic_store32(&req_buf->req_queue[i].processed, REQ_STATE_FREE);
|
||||
set_vhm_req_state(vm, i, REQ_STATE_FREE);
|
||||
}
|
||||
}
|
||||
|
||||
static bool has_complete_ioreq(struct acrn_vcpu *vcpu)
|
||||
static inline bool has_complete_ioreq(struct acrn_vcpu *vcpu)
|
||||
{
|
||||
union vhm_request_buffer *req_buf = NULL;
|
||||
struct vhm_request *vhm_req;
|
||||
struct acrn_vm *vm;
|
||||
|
||||
vm = vcpu->vm;
|
||||
req_buf = (union vhm_request_buffer *)vm->sw.io_shared_page;
|
||||
if (req_buf != NULL) {
|
||||
vhm_req = &req_buf->req_queue[vcpu->vcpu_id];
|
||||
if (atomic_load32(&vhm_req->processed) == REQ_STATE_COMPLETE) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return (get_vhm_req_state(vcpu->vm, vcpu->vcpu_id) == REQ_STATE_COMPLETE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,13 +117,13 @@ int32_t acrn_insert_request_wait(struct acrn_vcpu *vcpu, const struct io_request
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ASSERT(get_vhm_req_state(vcpu->vm, vcpu->vcpu_id) == REQ_STATE_FREE,
|
||||
"VHM request buffer is busy");
|
||||
|
||||
req_buf = (union vhm_request_buffer *)(vcpu->vm->sw.io_shared_page);
|
||||
cur = vcpu->vcpu_id;
|
||||
vhm_req = &req_buf->req_queue[cur];
|
||||
|
||||
ASSERT(atomic_load32(&vhm_req->processed) == REQ_STATE_FREE,
|
||||
"VHM request buffer is busy");
|
||||
|
||||
/* ACRN insert request to VHM and inject upcall */
|
||||
vhm_req->type = io_req->type;
|
||||
(void)memcpy_s(&vhm_req->reqs, sizeof(union vhm_io_request),
|
||||
@@ -158,7 +143,7 @@ int32_t acrn_insert_request_wait(struct acrn_vcpu *vcpu, const struct io_request
|
||||
* before we perform upcall.
|
||||
* because VHM can work in pulling mode without wait for upcall
|
||||
*/
|
||||
atomic_store32(&vhm_req->processed, REQ_STATE_PENDING);
|
||||
set_vhm_req_state(vcpu->vm, vcpu->vcpu_id, REQ_STATE_PENDING);
|
||||
|
||||
acrn_print_request(vcpu->vcpu_id, vhm_req);
|
||||
|
||||
@@ -167,3 +152,34 @@ int32_t acrn_insert_request_wait(struct acrn_vcpu *vcpu, const struct io_request
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t get_vhm_req_state(struct acrn_vm *vm, uint16_t vhm_req_id)
|
||||
{
|
||||
uint32_t state;
|
||||
union vhm_request_buffer *req_buf = NULL;
|
||||
struct vhm_request *vhm_req;
|
||||
|
||||
req_buf = (union vhm_request_buffer *)vm->sw.io_shared_page;
|
||||
if (req_buf == NULL) {
|
||||
return (uint32_t)-1;
|
||||
}
|
||||
|
||||
vhm_req = &req_buf->req_queue[vhm_req_id];
|
||||
state = atomic_load32(&vhm_req->processed);
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
void set_vhm_req_state(struct acrn_vm *vm, uint16_t vhm_req_id, uint32_t state)
|
||||
{
|
||||
union vhm_request_buffer *req_buf = NULL;
|
||||
struct vhm_request *vhm_req;
|
||||
|
||||
req_buf = (union vhm_request_buffer *)vm->sw.io_shared_page;
|
||||
if (req_buf == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
vhm_req = &req_buf->req_queue[vhm_req_id];
|
||||
atomic_store32(&vhm_req->processed, state);
|
||||
}
|
||||
|
Reference in New Issue
Block a user