]> git.proxmox.com Git - mirror_qemu.git/blame - hw/core/nmi.c
Include qemu/module.h where needed, drop it from qemu-common.h
[mirror_qemu.git] / hw / core / nmi.c
CommitLineData
9cb805fd
AK
1/*
2 * NMI monitor handler class and helpers.
3 *
4 * Copyright IBM Corp., 2014
5 *
6 * Author: Alexey Kardashevskiy <aik@ozlabs.ru>
7 *
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.
12 *
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.
17 *
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/>.
20 */
21
18c86e2b 22#include "qemu/osdep.h"
9cb805fd 23#include "hw/nmi.h"
da34e65c 24#include "qapi/error.h"
9cb805fd 25#include "qapi/qmp/qerror.h"
0b8fa32f 26#include "qemu/module.h"
f9a535e0 27#include "monitor/monitor.h"
9cb805fd
AK
28
29struct do_nmi_s {
30 int cpu_index;
533fdaed 31 Error *err;
9cb805fd
AK
32 bool handled;
33};
34
35static void nmi_children(Object *o, struct do_nmi_s *ns);
36
37static int do_nmi(Object *o, void *opaque)
38{
39 struct do_nmi_s *ns = opaque;
40 NMIState *n = (NMIState *) object_dynamic_cast(o, TYPE_NMI);
41
42 if (n) {
43 NMIClass *nc = NMI_GET_CLASS(n);
44
45 ns->handled = true;
533fdaed
MA
46 nc->nmi_monitor_handler(n, ns->cpu_index, &ns->err);
47 if (ns->err) {
9cb805fd
AK
48 return -1;
49 }
50 }
51 nmi_children(o, ns);
52
53 return 0;
54}
55
56static void nmi_children(Object *o, struct do_nmi_s *ns)
57{
58 object_child_foreach(o, do_nmi, ns);
59}
60
61void nmi_monitor_handle(int cpu_index, Error **errp)
62{
63 struct do_nmi_s ns = {
64 .cpu_index = cpu_index,
533fdaed 65 .err = NULL,
9cb805fd
AK
66 .handled = false
67 };
68
69 nmi_children(object_get_root(), &ns);
70 if (ns.handled) {
533fdaed 71 error_propagate(errp, ns.err);
9cb805fd 72 } else {
c6bd8c70 73 error_setg(errp, QERR_UNSUPPORTED);
9cb805fd
AK
74 }
75}
76
77static const TypeInfo nmi_info = {
78 .name = TYPE_NMI,
79 .parent = TYPE_INTERFACE,
80 .class_size = sizeof(NMIClass),
81};
82
83static void nmi_register_types(void)
84{
85 type_register_static(&nmi_info);
86}
87
88type_init(nmi_register_types)