]> Git Repo - qemu.git/blame - hw/core/nmi.c
Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging
[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 <[email protected]>
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"
f9a535e0 24#include "monitor/monitor.h"
9cb805fd
AK
25
26struct do_nmi_s {
27 int cpu_index;
28 Error *errp;
29 bool handled;
30};
31
32static void nmi_children(Object *o, struct do_nmi_s *ns);
33
34static int do_nmi(Object *o, void *opaque)
35{
36 struct do_nmi_s *ns = opaque;
37 NMIState *n = (NMIState *) object_dynamic_cast(o, TYPE_NMI);
38
39 if (n) {
40 NMIClass *nc = NMI_GET_CLASS(n);
41
42 ns->handled = true;
43 nc->nmi_monitor_handler(n, ns->cpu_index, &ns->errp);
44 if (ns->errp) {
45 return -1;
46 }
47 }
48 nmi_children(o, ns);
49
50 return 0;
51}
52
53static void nmi_children(Object *o, struct do_nmi_s *ns)
54{
55 object_child_foreach(o, do_nmi, ns);
56}
57
58void nmi_monitor_handle(int cpu_index, Error **errp)
59{
60 struct do_nmi_s ns = {
61 .cpu_index = cpu_index,
62 .errp = NULL,
63 .handled = false
64 };
65
66 nmi_children(object_get_root(), &ns);
67 if (ns.handled) {
68 error_propagate(errp, ns.errp);
69 } else {
c6bd8c70 70 error_setg(errp, QERR_UNSUPPORTED);
9cb805fd
AK
71 }
72}
73
f9a535e0
XW
74void inject_nmi(void)
75{
76#if defined(TARGET_I386)
77 CPUState *cs;
78
79 CPU_FOREACH(cs) {
80 X86CPU *cpu = X86_CPU(cs);
81
82 if (!cpu->apic_state) {
83 cpu_interrupt(cs, CPU_INTERRUPT_NMI);
84 } else {
85 apic_deliver_nmi(cpu->apic_state);
86 }
87 }
88#else
89 nmi_monitor_handle(0, NULL);
90#endif
91}
92
9cb805fd
AK
93static const TypeInfo nmi_info = {
94 .name = TYPE_NMI,
95 .parent = TYPE_INTERFACE,
96 .class_size = sizeof(NMIClass),
97};
98
99static void nmi_register_types(void)
100{
101 type_register_static(&nmi_info);
102}
103
104type_init(nmi_register_types)
This page took 0.093139 seconds and 4 git commands to generate.