diff options
author | Laurent Vivier <Laurent.Vivier@bull.net> | 2007-08-05 03:43:32 -0400 |
---|---|---|
committer | Avi Kivity <avi@qumranet.com> | 2007-10-13 04:18:23 -0400 |
commit | 3090dd7377c7eb5cbe229e2a538f9dc7e5b06814 (patch) | |
tree | 7f93e361f5bcea61b9b10f607fb69e4d9b124478 /drivers/kvm/kvm_main.c | |
parent | e70669abd4e60dfea3ac1639848e20e2b8dd1255 (diff) |
KVM: Clean up kvm_setup_pio()
Split kvm_setup_pio() into two functions, one to setup in/out pio
(kvm_emulate_pio()) and one to setup ins/outs pio (kvm_emulate_pio_string()).
Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net>
Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'drivers/kvm/kvm_main.c')
-rw-r--r-- | drivers/kvm/kvm_main.c | 63 |
1 files changed, 39 insertions, 24 deletions
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c index 661d065fd866..d154487b7729 100644 --- a/drivers/kvm/kvm_main.c +++ b/drivers/kvm/kvm_main.c | |||
@@ -1735,8 +1735,39 @@ static void pio_string_write(struct kvm_io_device *pio_dev, | |||
1735 | } | 1735 | } |
1736 | } | 1736 | } |
1737 | 1737 | ||
1738 | int kvm_setup_pio(struct kvm_vcpu *vcpu, struct kvm_run *run, int in, | 1738 | int kvm_emulate_pio (struct kvm_vcpu *vcpu, struct kvm_run *run, int in, |
1739 | int size, unsigned long count, int string, int down, | 1739 | int size, unsigned port) |
1740 | { | ||
1741 | struct kvm_io_device *pio_dev; | ||
1742 | |||
1743 | vcpu->run->exit_reason = KVM_EXIT_IO; | ||
1744 | vcpu->run->io.direction = in ? KVM_EXIT_IO_IN : KVM_EXIT_IO_OUT; | ||
1745 | vcpu->run->io.size = vcpu->pio.size = size; | ||
1746 | vcpu->run->io.data_offset = KVM_PIO_PAGE_OFFSET * PAGE_SIZE; | ||
1747 | vcpu->run->io.count = vcpu->pio.count = vcpu->pio.cur_count = 1; | ||
1748 | vcpu->run->io.port = vcpu->pio.port = port; | ||
1749 | vcpu->pio.in = in; | ||
1750 | vcpu->pio.string = 0; | ||
1751 | vcpu->pio.down = 0; | ||
1752 | vcpu->pio.guest_page_offset = 0; | ||
1753 | vcpu->pio.rep = 0; | ||
1754 | |||
1755 | kvm_arch_ops->cache_regs(vcpu); | ||
1756 | memcpy(vcpu->pio_data, &vcpu->regs[VCPU_REGS_RAX], 4); | ||
1757 | kvm_arch_ops->decache_regs(vcpu); | ||
1758 | |||
1759 | pio_dev = vcpu_find_pio_dev(vcpu, port); | ||
1760 | if (pio_dev) { | ||
1761 | kernel_pio(pio_dev, vcpu, vcpu->pio_data); | ||
1762 | complete_pio(vcpu); | ||
1763 | return 1; | ||
1764 | } | ||
1765 | return 0; | ||
1766 | } | ||
1767 | EXPORT_SYMBOL_GPL(kvm_emulate_pio); | ||
1768 | |||
1769 | int kvm_emulate_pio_string(struct kvm_vcpu *vcpu, struct kvm_run *run, int in, | ||
1770 | int size, unsigned long count, int down, | ||
1740 | gva_t address, int rep, unsigned port) | 1771 | gva_t address, int rep, unsigned port) |
1741 | { | 1772 | { |
1742 | unsigned now, in_page; | 1773 | unsigned now, in_page; |
@@ -1747,33 +1778,16 @@ int kvm_setup_pio(struct kvm_vcpu *vcpu, struct kvm_run *run, int in, | |||
1747 | 1778 | ||
1748 | vcpu->run->exit_reason = KVM_EXIT_IO; | 1779 | vcpu->run->exit_reason = KVM_EXIT_IO; |
1749 | vcpu->run->io.direction = in ? KVM_EXIT_IO_IN : KVM_EXIT_IO_OUT; | 1780 | vcpu->run->io.direction = in ? KVM_EXIT_IO_IN : KVM_EXIT_IO_OUT; |
1750 | vcpu->run->io.size = size; | 1781 | vcpu->run->io.size = vcpu->pio.size = size; |
1751 | vcpu->run->io.data_offset = KVM_PIO_PAGE_OFFSET * PAGE_SIZE; | 1782 | vcpu->run->io.data_offset = KVM_PIO_PAGE_OFFSET * PAGE_SIZE; |
1752 | vcpu->run->io.count = count; | 1783 | vcpu->run->io.count = vcpu->pio.count = vcpu->pio.cur_count = count; |
1753 | vcpu->run->io.port = port; | 1784 | vcpu->run->io.port = vcpu->pio.port = port; |
1754 | vcpu->pio.count = count; | ||
1755 | vcpu->pio.cur_count = count; | ||
1756 | vcpu->pio.size = size; | ||
1757 | vcpu->pio.in = in; | 1785 | vcpu->pio.in = in; |
1758 | vcpu->pio.port = port; | 1786 | vcpu->pio.string = 1; |
1759 | vcpu->pio.string = string; | ||
1760 | vcpu->pio.down = down; | 1787 | vcpu->pio.down = down; |
1761 | vcpu->pio.guest_page_offset = offset_in_page(address); | 1788 | vcpu->pio.guest_page_offset = offset_in_page(address); |
1762 | vcpu->pio.rep = rep; | 1789 | vcpu->pio.rep = rep; |
1763 | 1790 | ||
1764 | pio_dev = vcpu_find_pio_dev(vcpu, port); | ||
1765 | if (!string) { | ||
1766 | kvm_arch_ops->cache_regs(vcpu); | ||
1767 | memcpy(vcpu->pio_data, &vcpu->regs[VCPU_REGS_RAX], 4); | ||
1768 | kvm_arch_ops->decache_regs(vcpu); | ||
1769 | if (pio_dev) { | ||
1770 | kernel_pio(pio_dev, vcpu, vcpu->pio_data); | ||
1771 | complete_pio(vcpu); | ||
1772 | return 1; | ||
1773 | } | ||
1774 | return 0; | ||
1775 | } | ||
1776 | |||
1777 | if (!count) { | 1791 | if (!count) { |
1778 | kvm_arch_ops->skip_emulated_instruction(vcpu); | 1792 | kvm_arch_ops->skip_emulated_instruction(vcpu); |
1779 | return 1; | 1793 | return 1; |
@@ -1818,6 +1832,7 @@ int kvm_setup_pio(struct kvm_vcpu *vcpu, struct kvm_run *run, int in, | |||
1818 | } | 1832 | } |
1819 | } | 1833 | } |
1820 | 1834 | ||
1835 | pio_dev = vcpu_find_pio_dev(vcpu, port); | ||
1821 | if (!vcpu->pio.in) { | 1836 | if (!vcpu->pio.in) { |
1822 | /* string PIO write */ | 1837 | /* string PIO write */ |
1823 | ret = pio_copy_data(vcpu); | 1838 | ret = pio_copy_data(vcpu); |
@@ -1834,7 +1849,7 @@ int kvm_setup_pio(struct kvm_vcpu *vcpu, struct kvm_run *run, int in, | |||
1834 | 1849 | ||
1835 | return ret; | 1850 | return ret; |
1836 | } | 1851 | } |
1837 | EXPORT_SYMBOL_GPL(kvm_setup_pio); | 1852 | EXPORT_SYMBOL_GPL(kvm_emulate_pio_string); |
1838 | 1853 | ||
1839 | static int kvm_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) | 1854 | static int kvm_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) |
1840 | { | 1855 | { |