2 * NMI monitor handler class and helpers.
4 * Copyright IBM Corp., 2014
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License,
11 * or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
23 #include "qapi/qmp/qerror.h"
24 #include "monitor/monitor.h"
32 static void nmi_children(Object *o, struct do_nmi_s *ns);
34 static int do_nmi(Object *o, void *opaque)
36 struct do_nmi_s *ns = opaque;
37 NMIState *n = (NMIState *) object_dynamic_cast(o, TYPE_NMI);
40 NMIClass *nc = NMI_GET_CLASS(n);
43 nc->nmi_monitor_handler(n, ns->cpu_index, &ns->errp);
53 static void nmi_children(Object *o, struct do_nmi_s *ns)
55 object_child_foreach(o, do_nmi, ns);
58 void nmi_monitor_handle(int cpu_index, Error **errp)
60 struct do_nmi_s ns = {
61 .cpu_index = cpu_index,
66 nmi_children(object_get_root(), &ns);
68 error_propagate(errp, ns.errp);
70 error_setg(errp, QERR_UNSUPPORTED);
76 #if defined(TARGET_I386)
80 X86CPU *cpu = X86_CPU(cs);
82 if (!cpu->apic_state) {
83 cpu_interrupt(cs, CPU_INTERRUPT_NMI);
85 apic_deliver_nmi(cpu->apic_state);
89 nmi_monitor_handle(0, NULL);
93 static const TypeInfo nmi_info = {
95 .parent = TYPE_INTERFACE,
96 .class_size = sizeof(NMIClass),
99 static void nmi_register_types(void)
101 type_register_static(&nmi_info);
104 type_init(nmi_register_types)