]> git.proxmox.com Git - mirror_qemu.git/blame - hw/core/nmi.c
Merge remote-tracking branch 'remotes/awilliam/tags/vfio-update-20150609.0' into...
[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
22#include "hw/nmi.h"
23#include "qapi/qmp/qerror.h"
24
25struct do_nmi_s {
26 int cpu_index;
27 Error *errp;
28 bool handled;
29};
30
31static void nmi_children(Object *o, struct do_nmi_s *ns);
32
33static int do_nmi(Object *o, void *opaque)
34{
35 struct do_nmi_s *ns = opaque;
36 NMIState *n = (NMIState *) object_dynamic_cast(o, TYPE_NMI);
37
38 if (n) {
39 NMIClass *nc = NMI_GET_CLASS(n);
40
41 ns->handled = true;
42 nc->nmi_monitor_handler(n, ns->cpu_index, &ns->errp);
43 if (ns->errp) {
44 return -1;
45 }
46 }
47 nmi_children(o, ns);
48
49 return 0;
50}
51
52static void nmi_children(Object *o, struct do_nmi_s *ns)
53{
54 object_child_foreach(o, do_nmi, ns);
55}
56
57void nmi_monitor_handle(int cpu_index, Error **errp)
58{
59 struct do_nmi_s ns = {
60 .cpu_index = cpu_index,
61 .errp = NULL,
62 .handled = false
63 };
64
65 nmi_children(object_get_root(), &ns);
66 if (ns.handled) {
67 error_propagate(errp, ns.errp);
68 } else {
69 error_set(errp, QERR_UNSUPPORTED);
70 }
71}
72
73static const TypeInfo nmi_info = {
74 .name = TYPE_NMI,
75 .parent = TYPE_INTERFACE,
76 .class_size = sizeof(NMIClass),
77};
78
79static void nmi_register_types(void)
80{
81 type_register_static(&nmi_info);
82}
83
84type_init(nmi_register_types)