Skip to content

Commit 941eb9d

Browse files
junjiemao1lijinxia
authored andcommitted
HV: io: move I/O emulation post-work to io.c
There are some functions for the post work of I/O emulation. This patch moves these functions to io.c for clarity. No functional change introduced. Signed-off-by: Junjie Mao <junjie.mao@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent d817951 commit 941eb9d

File tree

3 files changed

+64
-61
lines changed

3 files changed

+64
-61
lines changed

hypervisor/arch/x86/io.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,68 @@ int32_t dm_emulate_mmio_post(struct vcpu *vcpu)
107107
return emulate_mmio_post(vcpu, io_req);
108108
}
109109

110+
static void complete_ioreq(struct vcpu *vcpu)
111+
{
112+
union vhm_request_buffer *req_buf;
113+
struct vhm_request *vhm_req;
114+
115+
req_buf = (union vhm_request_buffer *)
116+
vcpu->vm->sw.io_shared_page;
117+
vhm_req = &req_buf->req_queue[vcpu->vcpu_id];
118+
119+
vhm_req->valid = 0;
120+
atomic_store32(&vcpu->ioreq_pending, 0U);
121+
}
122+
123+
void emulate_io_post(struct vcpu *vcpu)
124+
{
125+
union vhm_request_buffer *req_buf;
126+
struct vhm_request *vhm_req;
127+
128+
req_buf = (union vhm_request_buffer *)vcpu->vm->sw.io_shared_page;
129+
vhm_req = &req_buf->req_queue[vcpu->vcpu_id];
130+
131+
if ((vhm_req->valid == 0) ||
132+
((vhm_req->processed != REQ_STATE_SUCCESS) &&
133+
(vhm_req->processed != REQ_STATE_FAILED))) {
134+
return;
135+
}
136+
137+
/*
138+
* If vcpu is in Zombie state and will be destroyed soon. Just
139+
* mark ioreq done and don't resume vcpu.
140+
*/
141+
if (vcpu->state == VCPU_ZOMBIE) {
142+
complete_ioreq(vcpu);
143+
return;
144+
}
145+
146+
switch (vcpu->req.type) {
147+
case REQ_MMIO:
148+
request_vcpu_pre_work(vcpu, ACRN_VCPU_MMIO_COMPLETE);
149+
break;
150+
151+
case REQ_PORTIO:
152+
case REQ_PCICFG:
153+
/* REQ_PORTIO on 0xcf8 & 0xcfc may switch to REQ_PCICFG in some
154+
* cases. It works to apply the post-work for REQ_PORTIO on
155+
* REQ_PCICFG because the format of the first 28 bytes of
156+
* REQ_PORTIO & REQ_PCICFG requests are exactly the same and
157+
* post-work is mainly interested in the read value.
158+
*/
159+
dm_emulate_pio_post(vcpu);
160+
break;
161+
162+
default:
163+
/* REQ_WP can only be triggered on writes which do not need
164+
* post-work. Just mark the ioreq done. */
165+
complete_ioreq(vcpu);
166+
break;
167+
}
168+
169+
resume_vcpu(vcpu);
170+
}
171+
110172
/**
111173
* Try handling the given request by any port I/O handler registered in the
112174
* hypervisor.

hypervisor/common/hypercall.c

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -361,60 +361,8 @@ int32_t hcall_set_ioreq_buffer(struct vm *vm, uint16_t vmid, uint64_t param)
361361
return ret;
362362
}
363363

364-
static void complete_ioreq(struct vcpu *vcpu)
365-
{
366-
union vhm_request_buffer *req_buf;
367-
struct vhm_request *vhm_req;
368-
369-
req_buf = (union vhm_request_buffer *)
370-
vcpu->vm->sw.io_shared_page;
371-
vhm_req = &req_buf->req_queue[vcpu->vcpu_id];
372-
373-
vhm_req->valid = 0;
374-
atomic_store32(&vcpu->ioreq_pending, 0U);
375-
}
376-
377-
static void emulate_io_post(struct vcpu *vcpu)
378-
{
379-
/*
380-
* If vcpu is in Zombie state and will be destroyed soon. Just
381-
* mark ioreq done and don't resume vcpu.
382-
*/
383-
if (vcpu->state == VCPU_ZOMBIE) {
384-
complete_ioreq(vcpu);
385-
return;
386-
}
387-
388-
switch (vcpu->req.type) {
389-
case REQ_MMIO:
390-
request_vcpu_pre_work(vcpu, ACRN_VCPU_MMIO_COMPLETE);
391-
break;
392-
393-
case REQ_PORTIO:
394-
case REQ_PCICFG:
395-
/* REQ_PORTIO on 0xcf8 & 0xcfc may switch to REQ_PCICFG in some
396-
* cases. It works to apply the post-work for REQ_PORTIO on
397-
* REQ_PCICFG because the format of the first 28 bytes of
398-
* REQ_PORTIO & REQ_PCICFG requests are exactly the same and
399-
* post-work is mainly interested in the read value.
400-
*/
401-
dm_emulate_pio_post(vcpu);
402-
break;
403-
404-
default:
405-
/* REQ_WP can only be triggered on writes which do not need
406-
* post-work. Just mark the ioreq done. */
407-
complete_ioreq(vcpu);
408-
break;
409-
}
410-
411-
resume_vcpu(vcpu);
412-
}
413-
414364
int32_t hcall_notify_ioreq_finish(uint16_t vmid, uint16_t vcpu_id)
415365
{
416-
union vhm_request_buffer *req_buf;
417-
struct vhm_request *req;
418366
struct vcpu *vcpu;
419367
struct vm *target_vm = get_vm_from_vmid(vmid);
420368

@@ -434,14 +382,7 @@ int32_t hcall_notify_ioreq_finish(uint16_t vmid, uint16_t vcpu_id)
434382
return -EINVAL;
435383
}
436384

437-
req_buf = (union vhm_request_buffer *)target_vm->sw.io_shared_page;
438-
req = req_buf->req_queue + vcpu_id;
439-
440-
if ((req->valid != 0) &&
441-
((req->processed == REQ_STATE_SUCCESS) ||
442-
(req->processed == REQ_STATE_FAILED))) {
443-
emulate_io_post(vcpu);
444-
}
385+
emulate_io_post(vcpu);
445386

446387
return 0;
447388
}

hypervisor/include/arch/x86/ioreq.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ void allow_guest_io_access(struct vm *vm, uint32_t address_arg, uint32_t nbyte
115115
void register_io_emulation_handler(struct vm *vm, struct vm_io_range *range,
116116
io_read_fn_t io_read_fn_ptr,
117117
io_write_fn_t io_write_fn_ptr);
118-
int dm_emulate_pio_post(struct vcpu *vcpu);
119118

120119
int register_mmio_emulation_handler(struct vm *vm,
121120
hv_mem_io_handler_t read_write, uint64_t start,
@@ -126,6 +125,7 @@ int32_t emulate_mmio_post(struct vcpu *vcpu, struct io_request *io_req);
126125
int32_t dm_emulate_mmio_post(struct vcpu *vcpu);
127126

128127
int32_t emulate_io(struct vcpu *vcpu, struct io_request *io_req);
128+
void emulate_io_post(struct vcpu *vcpu);
129129

130130
int32_t acrn_insert_request_wait(struct vcpu *vcpu, struct io_request *req);
131131

0 commit comments

Comments
 (0)