From patchwork Fri Apr 17 07:52:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cornelia Huck X-Patchwork-Id: 461956 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id EBC2D140283 for ; Fri, 17 Apr 2015 17:53:46 +1000 (AEST) Received: from localhost ([::1]:39945 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yj15t-0007T8-1S for incoming@patchwork.ozlabs.org; Fri, 17 Apr 2015 03:53:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57557) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yj155-0005wl-DU for qemu-devel@nongnu.org; Fri, 17 Apr 2015 03:52:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yj152-0006Xf-HB for qemu-devel@nongnu.org; Fri, 17 Apr 2015 03:52:55 -0400 Received: from e06smtp17.uk.ibm.com ([195.75.94.113]:45836) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yj152-0006Wy-8A for qemu-devel@nongnu.org; Fri, 17 Apr 2015 03:52:52 -0400 Received: from /spool/local by e06smtp17.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 17 Apr 2015 08:52:50 +0100 Received: from d06dlp02.portsmouth.uk.ibm.com (9.149.20.14) by e06smtp17.uk.ibm.com (192.168.101.147) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 17 Apr 2015 08:52:48 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id C065E2190061 for ; Fri, 17 Apr 2015 08:52:32 +0100 (BST) Received: from d06av06.portsmouth.uk.ibm.com (d06av06.portsmouth.uk.ibm.com [9.149.37.217]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t3H7qlO64260280 for ; Fri, 17 Apr 2015 07:52:48 GMT Received: from d06av06.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t3H2lDMU007617 for ; Thu, 16 Apr 2015 22:47:13 -0400 Received: from gondolin.boeblingen.de.ibm.com (dyn-9-152-224-143.boeblingen.de.ibm.com [9.152.224.143]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t3H2lAhk007386; Thu, 16 Apr 2015 22:47:12 -0400 From: Cornelia Huck To: qemu-devel@nongnu.org Date: Fri, 17 Apr 2015 09:52:40 +0200 Message-Id: <1429257161-29597-6-git-send-email-cornelia.huck@de.ibm.com> X-Mailer: git-send-email 2.3.5 In-Reply-To: <1429257161-29597-1-git-send-email-cornelia.huck@de.ibm.com> References: <1429257161-29597-1-git-send-email-cornelia.huck@de.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15041707-0029-0000-0000-0000043F0CC4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.75.94.113 Cc: armbru@redhat.com, mdroth@linux.vnet.ibm.com, agraf@suse.de, borntraeger@de.ibm.com, jfrei@linux.vnet.ibm.com, Cornelia Huck , Xu Wang , lcapitulino@redhat.com Subject: [Qemu-devel] [PATCH 5/6] nmi: Implement inject_nmi() for non-monitor context use X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Signed-off-by: Cornelia Huck --- 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 */