Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / hw / core / nmi.c
bloba7bce8a04a121dcbe06478f79365009f33c23aec
1 /*
2 * NMI monitor handler class and helpers.
4 * Copyright IBM Corp., 2014
6 * Author: Alexey Kardashevskiy <aik@ozlabs.ru>
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/>.
22 #include "qemu/osdep.h"
23 #include "hw/nmi.h"
24 #include "qapi/error.h"
25 #include "qemu/module.h"
26 #include "monitor/monitor.h"
28 struct do_nmi_s {
29 int cpu_index;
30 Error *err;
31 bool handled;
34 static void nmi_children(Object *o, struct do_nmi_s *ns);
36 static int do_nmi(Object *o, void *opaque)
38 struct do_nmi_s *ns = opaque;
39 NMIState *n = (NMIState *) object_dynamic_cast(o, TYPE_NMI);
41 if (n) {
42 NMIClass *nc = NMI_GET_CLASS(n);
44 ns->handled = true;
45 nc->nmi_monitor_handler(n, ns->cpu_index, &ns->err);
46 if (ns->err) {
47 return -1;
50 nmi_children(o, ns);
52 return 0;
55 static void nmi_children(Object *o, struct do_nmi_s *ns)
57 object_child_foreach(o, do_nmi, ns);
60 void nmi_monitor_handle(int cpu_index, Error **errp)
62 struct do_nmi_s ns = {
63 .cpu_index = cpu_index,
64 .err = NULL,
65 .handled = false
68 nmi_children(object_get_root(), &ns);
69 if (ns.handled) {
70 error_propagate(errp, ns.err);
71 } else {
72 error_setg(errp, "machine does not provide NMIs");
76 static const TypeInfo nmi_info = {
77 .name = TYPE_NMI,
78 .parent = TYPE_INTERFACE,
79 .class_size = sizeof(NMIClass),
82 static void nmi_register_types(void)
84 type_register_static(&nmi_info);
87 type_init(nmi_register_types)