From 099203c15a03602f6fa25157bd73ee9095b0a939 Mon Sep 17 00:00:00 2001 From: Jason Chen CJ Date: Fri, 28 Sep 2018 15:20:02 +0800 Subject: [PATCH] ptdev: assert/deassert interrupt according to polarity add active_polarity to decide what signal to call: GSI_SET_LOW, GSI_SET_HIGH, GSI_FALLING_PULSE or GSI_RAISING_PULSE. Tracked-On: #1269 Signed-off-by: Jason Chen CJ --- hypervisor/arch/x86/assign.c | 41 +++++++++++++++++++++++++++---- hypervisor/include/common/ptdev.h | 1 + 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/hypervisor/arch/x86/assign.c b/hypervisor/arch/x86/assign.c index 339dfbb19..129b916d6 100644 --- a/hypervisor/arch/x86/assign.c +++ b/hypervisor/arch/x86/assign.c @@ -107,6 +107,23 @@ ptdev_build_physical_rte(struct vm *vm, vioapic_get_rte(vm, virt_sid->intx_id.pin, &virt_rte); rte = virt_rte; + /* init polarity & pin state */ + if ((rte.full & IOAPIC_RTE_INTPOL) != 0UL) { + if (entry->polarity == 0U) { + vioapic_set_irq_nolock(vm, + (uint32_t)virt_sid->intx_id.pin, + GSI_SET_HIGH); + } + entry->polarity = 1U; + } else { + if (entry->polarity == 1U) { + vioapic_set_irq_nolock(vm, + (uint32_t)virt_sid->intx_id.pin, + GSI_SET_LOW); + } + entry->polarity = 0U; + } + /* physical destination cpu mask */ phys = ((virt_rte.full & IOAPIC_RTE_DESTMOD) == IOAPIC_RTE_DESTPHY); dest = (uint32_t)(virt_rte.full >> IOAPIC_RTE_DEST_SHIFT); @@ -359,11 +376,21 @@ static void ptdev_intr_handle_irq(struct vm *vm, } if (trigger_lvl) { - vioapic_set_irq(vm, virt_sid->intx_id.pin, - GSI_SET_HIGH); + if (entry->polarity) { + vioapic_set_irq(vm, virt_sid->intx_id.pin, + GSI_SET_LOW); + } else { + vioapic_set_irq(vm, virt_sid->intx_id.pin, + GSI_SET_HIGH); + } } else { - vioapic_set_irq(vm, virt_sid->intx_id.pin, - GSI_RAISING_PULSE); + if (entry->polarity) { + vioapic_set_irq(vm, virt_sid->intx_id.pin, + GSI_FALLING_PULSE); + } else { + vioapic_set_irq(vm, virt_sid->intx_id.pin, + GSI_RAISING_PULSE); + } } dev_dbg(ACRN_DBG_PTIRQ, @@ -460,7 +487,11 @@ void ptdev_intx_ack(struct vm *vm, uint8_t virt_pin, */ switch (vpin_src) { case PTDEV_VPIN_IOAPIC: - vioapic_set_irq(vm, virt_pin, GSI_SET_LOW); + if (entry->polarity) { + vioapic_set_irq(vm, virt_pin, GSI_SET_HIGH); + } else { + vioapic_set_irq(vm, virt_pin, GSI_SET_LOW); + } break; case PTDEV_VPIN_PIC: vpic_set_irq(vm, virt_pin, GSI_SET_LOW); diff --git a/hypervisor/include/common/ptdev.h b/hypervisor/include/common/ptdev.h index 11a646118..a1ba72a5c 100644 --- a/hypervisor/include/common/ptdev.h +++ b/hypervisor/include/common/ptdev.h @@ -58,6 +58,7 @@ struct ptdev_remapping_info { struct vm *vm; uint32_t active; /* 1=active, 0=inactive and to free*/ uint32_t allocated_pirq; + uint32_t polarity; /* 0=active high, 1=active low*/ struct list_head softirq_node; struct list_head entry_node; struct ptdev_msi_info msi;