Received: from eggs.gnu.org ([2001:4830:134:3::10]:48288) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ay9x8-0004tY-Eo for qemu-devel@nongnu.org; Wed, 04 May 2016 23:27:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ay9ww-0008Cr-Kd for qemu-devel@nongnu.org; Wed, 04 May 2016 23:27:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36570) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ay9ww-00089g-FF for qemu-devel@nongnu.org; Wed, 04 May 2016 23:27:38 -0400 From: Peter Xu Date: Thu, 5 May 2016 11:25:53 +0800 Message-Id: <1462418761-12714-19-git-send-email-peterx@redhat.com> In-Reply-To: <1462418761-12714-1-git-send-email-peterx@redhat.com> References: <1462418761-12714-1-git-send-email-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v6 18/26] ioapic: clear remote irr bit for edge-triggered interrupts List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: imammedo@redhat.com, rth@twiddle.net, ehabkost@redhat.com, jasowang@redhat.com, marcel@redhat.com, mst@redhat.com, pbonzini@redhat.com, jan.kiszka@web.de, rkrcmar@redhat.com, alex.williamson@redhat.com, wexu@redhat.com, davidkiarie4@gmail.com, peterx@redhat.com This is to better emulate IOAPIC version 0x1X hardware. Linux kernel leveraged this "feature" to do explicit EOI since EOI register is still not introduced at that time. This will also fix the issue that level triggered interrupts failed to work when IR enabled (tested with Linux kernel version 4.5). Reviewed-by: Radim Kr=C4=8Dm=C3=A1=C5=99 Signed-off-by: Peter Xu --- hw/intc/ioapic.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/hw/intc/ioapic.c b/hw/intc/ioapic.c index d7ebb5c..ce06954 100644 --- a/hw/intc/ioapic.c +++ b/hw/intc/ioapic.c @@ -281,6 +281,34 @@ ioapic_mem_read(void *opaque, hwaddr addr, unsigned = int size) return val; } =20 +/* + * This is to satisfy the hack in Linux kernel. One hack of it is to + * simulate clearing the Remote IRR bit of IOAPIC entry using the + * following: + * + * "For IO-APIC's with EOI register, we use that to do an explicit EOI. + * Otherwise, we simulate the EOI message manually by changing the trigg= er + * mode to edge and then back to level, with RTE being masked during + * this." + * + * (See linux kernel __eoi_ioapic_pin() comment in commit c0205701) + * + * This is based on the assumption that, Remote IRR bit will be + * cleared by IOAPIC hardware when configured as edge-triggered + * interrupts. + * + * Without this, level-triggered interrupts in IR mode might fail to + * work correctly. + */ +static inline void +ioapic_fix_edge_remote_irr(uint64_t *entry) +{ + if (!(*entry & IOAPIC_LVT_TRIGGER_MODE)) { + /* Edge-triggered interrupts, make sure remote IRR is zero */ + *entry &=3D ~((uint64_t)IOAPIC_LVT_REMOTE_IRR); + } +} + static void ioapic_mem_write(void *opaque, hwaddr addr, uint64_t val, unsigned int size) @@ -318,6 +346,7 @@ ioapic_mem_write(void *opaque, hwaddr addr, uint64_t = val, /* restore RO bits */ s->ioredtbl[index] &=3D IOAPIC_RW_BITS; s->ioredtbl[index] |=3D ro_bits; + ioapic_fix_edge_remote_irr(&s->ioredtbl[index]); ioapic_service(s); } } --=20 2.4.11