Skip to content

Commit 771c6db

Browse files
ywan170lijinxia
authored andcommitted
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 <yu1.wang@intel.com> Acked-by: Anthony Xu <anthony.xu@intel.com>
1 parent f0d2291 commit 771c6db

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

hypervisor/arch/x86/guest/vioapic.c

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -431,45 +431,46 @@ vioapic_indirect_write(struct vioapic *vioapic, uint32_t addr, uint32_t data)
431431

432432
static void
433433
vioapic_mmio_rw(struct vioapic *vioapic, uint64_t gpa,
434-
uint32_t *data, bool doread)
434+
uint32_t *data, bool do_read)
435435
{
436436
uint32_t offset;
437437

438438
offset = (uint32_t)(gpa - VIOAPIC_BASE);
439439

440-
/*
441-
* The IOAPIC specification allows 32-bit wide accesses to the
440+
VIOAPIC_LOCK(vioapic);
441+
442+
/* The IOAPIC specification allows 32-bit wide accesses to the
442443
* IOAPIC_REGSEL (offset 0) and IOAPIC_WINDOW (offset 16) registers.
443444
*/
444-
if (offset != IOAPIC_REGSEL &&
445-
offset != IOAPIC_WINDOW &&
446-
offset != IOAPIC_EOIR) {
447-
if (doread) {
448-
*data = 0U;
449-
}
450-
}
451-
452-
VIOAPIC_LOCK(vioapic);
453-
if (offset == IOAPIC_REGSEL) {
454-
if (doread) {
445+
switch (offset) {
446+
case IOAPIC_REGSEL:
447+
if (do_read) {
455448
*data = vioapic->ioregsel;
456449
} else {
457-
vioapic->ioregsel = *data;
450+
vioapic->ioregsel = *data & 0xFFU;
458451
}
459-
} else if (offset == IOAPIC_EOIR) {
460-
/* only need to handle write operation */
461-
if (!doread) {
452+
break;
453+
case IOAPIC_EOIR:
454+
if (!do_read) {
462455
vioapic_write_eoi(vioapic, *data);
463456
}
464-
} else {
465-
if (doread) {
457+
break;
458+
case IOAPIC_WINDOW:
459+
if (do_read) {
466460
*data = vioapic_indirect_read(vioapic,
467461
vioapic->ioregsel);
468462
} else {
469-
vioapic_indirect_write(vioapic, vioapic->ioregsel,
470-
*data);
463+
vioapic_indirect_write(vioapic,
464+
vioapic->ioregsel, *data);
471465
}
466+
break;
467+
default:
468+
if (do_read) {
469+
*data = 0xFFFFFFFFU;
470+
}
471+
break;
472472
}
473+
473474
VIOAPIC_UNLOCK(vioapic);
474475
}
475476

0 commit comments

Comments
 (0)