Commit 6f6fbe98 authored by Xiao Guangrong's avatar Xiao Guangrong Committed by Avi Kivity

KVM: x86: cleanup port-in/port-out emulated

Remove the same code between emulator_pio_in_emulated and
emulator_pio_out_emulated
Signed-off-by: default avatarXiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
parent 1cb3f3ae
...@@ -4349,32 +4349,24 @@ static int kernel_pio(struct kvm_vcpu *vcpu, void *pd) ...@@ -4349,32 +4349,24 @@ static int kernel_pio(struct kvm_vcpu *vcpu, void *pd)
return r; return r;
} }
static int emulator_pio_in_out(struct kvm_vcpu *vcpu, int size,
static int emulator_pio_in_emulated(struct x86_emulate_ctxt *ctxt, unsigned short port, void *val,
int size, unsigned short port, void *val, unsigned int count, bool in)
unsigned int count)
{ {
struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt); trace_kvm_pio(!in, port, size, count);
if (vcpu->arch.pio.count)
goto data_avail;
trace_kvm_pio(0, port, size, count);
vcpu->arch.pio.port = port; vcpu->arch.pio.port = port;
vcpu->arch.pio.in = 1; vcpu->arch.pio.in = in;
vcpu->arch.pio.count = count; vcpu->arch.pio.count = count;
vcpu->arch.pio.size = size; vcpu->arch.pio.size = size;
if (!kernel_pio(vcpu, vcpu->arch.pio_data)) { if (!kernel_pio(vcpu, vcpu->arch.pio_data)) {
data_avail:
memcpy(val, vcpu->arch.pio_data, size * count);
vcpu->arch.pio.count = 0; vcpu->arch.pio.count = 0;
return 1; return 1;
} }
vcpu->run->exit_reason = KVM_EXIT_IO; vcpu->run->exit_reason = KVM_EXIT_IO;
vcpu->run->io.direction = KVM_EXIT_IO_IN; vcpu->run->io.direction = in ? KVM_EXIT_IO_IN : KVM_EXIT_IO_OUT;
vcpu->run->io.size = size; vcpu->run->io.size = size;
vcpu->run->io.data_offset = KVM_PIO_PAGE_OFFSET * PAGE_SIZE; vcpu->run->io.data_offset = KVM_PIO_PAGE_OFFSET * PAGE_SIZE;
vcpu->run->io.count = count; vcpu->run->io.count = count;
...@@ -4383,36 +4375,37 @@ static int emulator_pio_in_emulated(struct x86_emulate_ctxt *ctxt, ...@@ -4383,36 +4375,37 @@ static int emulator_pio_in_emulated(struct x86_emulate_ctxt *ctxt,
return 0; return 0;
} }
static int emulator_pio_out_emulated(struct x86_emulate_ctxt *ctxt, static int emulator_pio_in_emulated(struct x86_emulate_ctxt *ctxt,
int size, unsigned short port, int size, unsigned short port, void *val,
const void *val, unsigned int count) unsigned int count)
{ {
struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt); struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
int ret;
trace_kvm_pio(1, port, size, count); if (vcpu->arch.pio.count)
goto data_avail;
vcpu->arch.pio.port = port;
vcpu->arch.pio.in = 0;
vcpu->arch.pio.count = count;
vcpu->arch.pio.size = size;
memcpy(vcpu->arch.pio_data, val, size * count);
if (!kernel_pio(vcpu, vcpu->arch.pio_data)) { ret = emulator_pio_in_out(vcpu, size, port, val, count, true);
if (ret) {
data_avail:
memcpy(val, vcpu->arch.pio_data, size * count);
vcpu->arch.pio.count = 0; vcpu->arch.pio.count = 0;
return 1; return 1;
} }
vcpu->run->exit_reason = KVM_EXIT_IO;
vcpu->run->io.direction = KVM_EXIT_IO_OUT;
vcpu->run->io.size = size;
vcpu->run->io.data_offset = KVM_PIO_PAGE_OFFSET * PAGE_SIZE;
vcpu->run->io.count = count;
vcpu->run->io.port = port;
return 0; return 0;
} }
static int emulator_pio_out_emulated(struct x86_emulate_ctxt *ctxt,
int size, unsigned short port,
const void *val, unsigned int count)
{
struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
memcpy(vcpu->arch.pio_data, val, size * count);
return emulator_pio_in_out(vcpu, size, port, (void *)val, count, false);
}
static unsigned long get_segment_base(struct kvm_vcpu *vcpu, int seg) static unsigned long get_segment_base(struct kvm_vcpu *vcpu, int seg)
{ {
return kvm_x86_ops->get_segment_base(vcpu, seg); return kvm_x86_ops->get_segment_base(vcpu, seg);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment