xref: /openbmc/qemu/hw/core/nmi.c (revision 9cb805fd2674f474d058fee6d7aa9e83fcd3d336)
1*9cb805fdSAlexey Kardashevskiy /*
2*9cb805fdSAlexey Kardashevskiy  *  NMI monitor handler class and helpers.
3*9cb805fdSAlexey Kardashevskiy  *
4*9cb805fdSAlexey Kardashevskiy  *  Copyright IBM Corp., 2014
5*9cb805fdSAlexey Kardashevskiy  *
6*9cb805fdSAlexey Kardashevskiy  *  Author: Alexey Kardashevskiy <aik@ozlabs.ru>
7*9cb805fdSAlexey Kardashevskiy  *
8*9cb805fdSAlexey Kardashevskiy  *  This program is free software; you can redistribute it and/or modify
9*9cb805fdSAlexey Kardashevskiy  *  it under the terms of the GNU General Public License as published by
10*9cb805fdSAlexey Kardashevskiy  *  the Free Software Foundation; either version 2 of the License,
11*9cb805fdSAlexey Kardashevskiy  *  or (at your option) any later version.
12*9cb805fdSAlexey Kardashevskiy  *
13*9cb805fdSAlexey Kardashevskiy  *  This program is distributed in the hope that it will be useful,
14*9cb805fdSAlexey Kardashevskiy  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15*9cb805fdSAlexey Kardashevskiy  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*9cb805fdSAlexey Kardashevskiy  *  GNU General Public License for more details.
17*9cb805fdSAlexey Kardashevskiy  *
18*9cb805fdSAlexey Kardashevskiy  *  You should have received a copy of the GNU General Public License
19*9cb805fdSAlexey Kardashevskiy  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
20*9cb805fdSAlexey Kardashevskiy  */
21*9cb805fdSAlexey Kardashevskiy 
22*9cb805fdSAlexey Kardashevskiy #include "hw/nmi.h"
23*9cb805fdSAlexey Kardashevskiy #include "qapi/qmp/qerror.h"
24*9cb805fdSAlexey Kardashevskiy 
25*9cb805fdSAlexey Kardashevskiy struct do_nmi_s {
26*9cb805fdSAlexey Kardashevskiy     int cpu_index;
27*9cb805fdSAlexey Kardashevskiy     Error *errp;
28*9cb805fdSAlexey Kardashevskiy     bool handled;
29*9cb805fdSAlexey Kardashevskiy };
30*9cb805fdSAlexey Kardashevskiy 
31*9cb805fdSAlexey Kardashevskiy static void nmi_children(Object *o, struct do_nmi_s *ns);
32*9cb805fdSAlexey Kardashevskiy 
33*9cb805fdSAlexey Kardashevskiy static int do_nmi(Object *o, void *opaque)
34*9cb805fdSAlexey Kardashevskiy {
35*9cb805fdSAlexey Kardashevskiy     struct do_nmi_s *ns = opaque;
36*9cb805fdSAlexey Kardashevskiy     NMIState *n = (NMIState *) object_dynamic_cast(o, TYPE_NMI);
37*9cb805fdSAlexey Kardashevskiy 
38*9cb805fdSAlexey Kardashevskiy     if (n) {
39*9cb805fdSAlexey Kardashevskiy         NMIClass *nc = NMI_GET_CLASS(n);
40*9cb805fdSAlexey Kardashevskiy 
41*9cb805fdSAlexey Kardashevskiy         ns->handled = true;
42*9cb805fdSAlexey Kardashevskiy         nc->nmi_monitor_handler(n, ns->cpu_index, &ns->errp);
43*9cb805fdSAlexey Kardashevskiy         if (ns->errp) {
44*9cb805fdSAlexey Kardashevskiy             return -1;
45*9cb805fdSAlexey Kardashevskiy         }
46*9cb805fdSAlexey Kardashevskiy     }
47*9cb805fdSAlexey Kardashevskiy     nmi_children(o, ns);
48*9cb805fdSAlexey Kardashevskiy 
49*9cb805fdSAlexey Kardashevskiy     return 0;
50*9cb805fdSAlexey Kardashevskiy }
51*9cb805fdSAlexey Kardashevskiy 
52*9cb805fdSAlexey Kardashevskiy static void nmi_children(Object *o, struct do_nmi_s *ns)
53*9cb805fdSAlexey Kardashevskiy {
54*9cb805fdSAlexey Kardashevskiy     object_child_foreach(o, do_nmi, ns);
55*9cb805fdSAlexey Kardashevskiy }
56*9cb805fdSAlexey Kardashevskiy 
57*9cb805fdSAlexey Kardashevskiy void nmi_monitor_handle(int cpu_index, Error **errp)
58*9cb805fdSAlexey Kardashevskiy {
59*9cb805fdSAlexey Kardashevskiy     struct do_nmi_s ns = {
60*9cb805fdSAlexey Kardashevskiy         .cpu_index = cpu_index,
61*9cb805fdSAlexey Kardashevskiy         .errp = NULL,
62*9cb805fdSAlexey Kardashevskiy         .handled = false
63*9cb805fdSAlexey Kardashevskiy     };
64*9cb805fdSAlexey Kardashevskiy 
65*9cb805fdSAlexey Kardashevskiy     nmi_children(object_get_root(), &ns);
66*9cb805fdSAlexey Kardashevskiy     if (ns.handled) {
67*9cb805fdSAlexey Kardashevskiy         error_propagate(errp, ns.errp);
68*9cb805fdSAlexey Kardashevskiy     } else {
69*9cb805fdSAlexey Kardashevskiy         error_set(errp, QERR_UNSUPPORTED);
70*9cb805fdSAlexey Kardashevskiy     }
71*9cb805fdSAlexey Kardashevskiy }
72*9cb805fdSAlexey Kardashevskiy 
73*9cb805fdSAlexey Kardashevskiy static const TypeInfo nmi_info = {
74*9cb805fdSAlexey Kardashevskiy     .name          = TYPE_NMI,
75*9cb805fdSAlexey Kardashevskiy     .parent        = TYPE_INTERFACE,
76*9cb805fdSAlexey Kardashevskiy     .class_size    = sizeof(NMIClass),
77*9cb805fdSAlexey Kardashevskiy };
78*9cb805fdSAlexey Kardashevskiy 
79*9cb805fdSAlexey Kardashevskiy static void nmi_register_types(void)
80*9cb805fdSAlexey Kardashevskiy {
81*9cb805fdSAlexey Kardashevskiy     type_register_static(&nmi_info);
82*9cb805fdSAlexey Kardashevskiy }
83*9cb805fdSAlexey Kardashevskiy 
84*9cb805fdSAlexey Kardashevskiy type_init(nmi_register_types)
85