From 771c6db3213638c0adafdd9027297af626038e07 Mon Sep 17 00:00:00 2001 From: Yu Wang Date: Wed, 1 Aug 2018 08:57:48 +0000 Subject: [PATCH] hv: vioapic: refine vioapic_mmio_rw function Merge multiple if to switch-case. And set 0xFFFFFFFFU as the default value of undefined address. And the IOREGSEL register only bits 7:0 are defined, so mask the other bits for read operation. Signed-off-by: Yu Wang Acked-by: Anthony Xu --- hypervisor/arch/x86/guest/vioapic.c | 45 +++++++++++++++-------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/hypervisor/arch/x86/guest/vioapic.c b/hypervisor/arch/x86/guest/vioapic.c index 11df521eb..a25408743 100644 --- a/hypervisor/arch/x86/guest/vioapic.c +++ b/hypervisor/arch/x86/guest/vioapic.c @@ -431,45 +431,46 @@ vioapic_indirect_write(struct vioapic *vioapic, uint32_t addr, uint32_t data) static void vioapic_mmio_rw(struct vioapic *vioapic, uint64_t gpa, - uint32_t *data, bool doread) + uint32_t *data, bool do_read) { uint32_t offset; offset = (uint32_t)(gpa - VIOAPIC_BASE); - /* - * The IOAPIC specification allows 32-bit wide accesses to the + VIOAPIC_LOCK(vioapic); + + /* The IOAPIC specification allows 32-bit wide accesses to the * IOAPIC_REGSEL (offset 0) and IOAPIC_WINDOW (offset 16) registers. */ - if (offset != IOAPIC_REGSEL && - offset != IOAPIC_WINDOW && - offset != IOAPIC_EOIR) { - if (doread) { - *data = 0U; - } - } - - VIOAPIC_LOCK(vioapic); - if (offset == IOAPIC_REGSEL) { - if (doread) { + switch (offset) { + case IOAPIC_REGSEL: + if (do_read) { *data = vioapic->ioregsel; } else { - vioapic->ioregsel = *data; + vioapic->ioregsel = *data & 0xFFU; } - } else if (offset == IOAPIC_EOIR) { - /* only need to handle write operation */ - if (!doread) { + break; + case IOAPIC_EOIR: + if (!do_read) { vioapic_write_eoi(vioapic, *data); } - } else { - if (doread) { + break; + case IOAPIC_WINDOW: + if (do_read) { *data = vioapic_indirect_read(vioapic, vioapic->ioregsel); } else { - vioapic_indirect_write(vioapic, vioapic->ioregsel, - *data); + vioapic_indirect_write(vioapic, + vioapic->ioregsel, *data); } + break; + default: + if (do_read) { + *data = 0xFFFFFFFFU; + } + break; } + VIOAPIC_UNLOCK(vioapic); }