Skip to contentSkip to conversation

kvm: Simplify kvm_handle_io

PATCH Applied Jan Kiszka 3 participants 3 messages Aug 13, 2013 – Aug 20, 2013 KVM

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 kvm: Simplify kvm_handle_io

Now that cpu_in/out is just a wrapper around address_space_rw, we can also call the latter directly. As host endianness == guest endianness, there is no need for the memory access helpers st*_p/ld*_p as well.

---
 kvm-all.c |   28 ++--------------------------
 1 files changed, 2 insertions(+), 26 deletions(-)
kvm-all.c +2 -26
index 716860f..c861354 100644
@@ -1499,32 +1499,8 @@ static void kvm_handle_io(uint16_t port, void *data, int direction, int size,
     uint8_t *ptr = data;
 
     for (i = 0; i < count; i++) {
-        if (direction == KVM_EXIT_IO_IN) {
-            switch (size) {
-            case 1:
-                stb_p(ptr, cpu_inb(port));
-                break;
-            case 2:
-                stw_p(ptr, cpu_inw(port));
-                break;
-            case 4:
-                stl_p(ptr, cpu_inl(port));
-                break;
-            }
-        } else {
-            switch (size) {
-            case 1:
-                cpu_outb(port, ldub_p(ptr));
-                break;
-            case 2:
-                cpu_outw(port, lduw_p(ptr));
-                break;
-            case 4:
-                cpu_outl(port, ldl_p(ptr));
-                break;
-            }
-        }
-
+        address_space_rw(&address_space_io, port, ptr, size,
+                         direction == KVM_EXIT_IO_OUT);
         ptr += size;
     }
 }
Signature · 1 line
1.7.3.4
Reviewed-by on v1 1/1
#1 lore raw

Am 13.08.2013 14:43, schrieb Jan Kiszka:

Quoted 8 lines

Now that cpu_in/out is just a wrapper around address_space_rw, we can also call the latter directly. As host endianness == guest endianness, there is no need for the memory access helpers st*_p/ld*_p as well.

---
 kvm-all.c |   28 ++--------------------------
 1 files changed, 2 insertions(+), 26 deletions(-)

Looks sensible,

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
maintainer Applied
#2 lore raw
In reply to Jan Kiszka

Il 13/08/2013 14:43, Jan Kiszka ha scritto:

Quoted 39 lines

Now that cpu_in/out is just a wrapper around address_space_rw, we can also call the latter directly. As host endianness == guest endianness, there is no need for the memory access helpers st*_p/ld*_p as well.

---
 kvm-all.c |   28 ++--------------------------
 1 files changed, 2 insertions(+), 26 deletions(-)
kvm-all.c +0 -21
index 716860f..c861354 100644
@@ -1499,32 +1499,8 @@ static void kvm_handle_io(uint16_t port, void *data, int direction, int size,
     uint8_t *ptr = data;
 
     for (i = 0; i < count; i++) {
-        if (direction == KVM_EXIT_IO_IN) {
-            switch (size) {
-            case 1:
-                stb_p(ptr, cpu_inb(port));
-                break;
-            case 2:
-                stw_p(ptr, cpu_inw(port));
-                break;
-            case 4:
-                stl_p(ptr, cpu_inl(port));
-                break;
-            }
-        } else {
-            switch (size) {
-            case 1:
-                cpu_outb(port, ldub_p(ptr));
-                break;
-            case 2:
-                cpu_outw(port, lduw_p(ptr));
-                break;
-            case 4:

kvm-all.c static void kvm_handle_io(uint16_t port, void *data, int direction, int size, · line 1506

Quoted 10 lines
kvm-all.c +2 -5
-                cpu_outl(port, ldl_p(ptr));
-                break;
-            }
-        }
-
+        address_space_rw(&address_space_io, port, ptr, size,
+                         direction == KVM_EXIT_IO_OUT);
         ptr += size;
     }
 }

Applied, thanks.

Paolo