Received: from eggs.gnu.org ([2001:4830:134:3::10]:41220) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4T3r-0005tk-Q0 for qemu-devel@nongnu.org; Mon, 15 Jun 2015 08:00:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z4T3o-0001Vh-4i for qemu-devel@nongnu.org; Mon, 15 Jun 2015 08:00:19 -0400 Received: from e06smtp13.uk.ibm.com ([195.75.94.109]:50546) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4T3n-0001Ug-S4 for qemu-devel@nongnu.org; Mon, 15 Jun 2015 08:00:16 -0400 Received: from /spool/local by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 15 Jun 2015 13:00:14 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id 3A4BF1B08069 for ; Mon, 15 Jun 2015 13:01:12 +0100 (BST) Received: from d06av04.portsmouth.uk.ibm.com (d06av04.portsmouth.uk.ibm.com [9.149.37.216]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t5FC0CJc19922958 for ; Mon, 15 Jun 2015 12:00:12 GMT Received: from d06av04.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t5FC08N7000991 for ; Mon, 15 Jun 2015 06:00:10 -0600 From: Christian Borntraeger Date: Mon, 15 Jun 2015 14:00:29 +0200 Message-Id: <1434369631-76375-6-git-send-email-borntraeger@de.ibm.com> In-Reply-To: <1434369631-76375-1-git-send-email-borntraeger@de.ibm.com> References: <1434369631-76375-1-git-send-email-borntraeger@de.ibm.com> Subject: [Qemu-devel] [PULL 5/7] nmi: Implement inject_nmi() for non-monitor context use List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Alexey Kardashevskiy , qemu-devel , Alexander Graf , Christian Borntraeger , Jens Freimann , Cornelia Huck , Xu Wang From: Xu Wang Let's introduce a general "inject_nmi()" function that doesn't rely on the cpu index of the monitor, but uses cpu index 0 as default (except for x86). This function can then later be used from a non-monitor context. Signed-off-by: Xu Wang Reviewed-by: David Hildenbrand CC: Alexey Kardashevskiy Signed-off-by: Christian Borntraeger --- hw/core/nmi.c | 20 ++++++++++++++++++++ include/hw/nmi.h | 1 + 2 files changed, 21 insertions(+) diff --git a/hw/core/nmi.c b/hw/core/nmi.c index 3dff020..5260d6c 100644 --- a/hw/core/nmi.c +++ b/hw/core/nmi.c @@ -21,6 +21,7 @@ #include "hw/nmi.h" #include "qapi/qmp/qerror.h" +#include "monitor/monitor.h" struct do_nmi_s { int cpu_index; @@ -70,6 +71,25 @@ void nmi_monitor_handle(int cpu_index, Error **errp) } } +void inject_nmi(void) +{ +#if defined(TARGET_I386) + CPUState *cs; + + CPU_FOREACH(cs) { + X86CPU *cpu = X86_CPU(cs); + + if (!cpu->apic_state) { + cpu_interrupt(cs, CPU_INTERRUPT_NMI); + } else { + apic_deliver_nmi(cpu->apic_state); + } + } +#else + nmi_monitor_handle(0, NULL); +#endif +} + static const TypeInfo nmi_info = { .name = TYPE_NMI, .parent = TYPE_INTERFACE, diff --git a/include/hw/nmi.h b/include/hw/nmi.h index b541772..f4cec62 100644 --- a/include/hw/nmi.h +++ b/include/hw/nmi.h @@ -45,5 +45,6 @@ typedef struct NMIClass { } NMIClass; void nmi_monitor_handle(int cpu_index, Error **errp); +void inject_nmi(void); #endif /* NMI_H */ -- 2.3.0