| 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 "qemu/osdep.h" |
| 23 | #include "hw/core/nmi.h" |
| 24 | #include "qapi/error.h" |
| 25 | |
| 26 | static int do_nmi(Object *o, void *opaque) |
| 27 | { |
| 28 | bool *handled = opaque; |
| 29 | NMIState *n = (NMIState *) object_dynamic_cast(o, TYPE_NMI); |
| 30 | |
| 31 | if (n) { |
| 32 | *handled = true; |
| 33 | NMI_GET_CLASS(n)->raise_nmi(n); |
| 34 | /* |
| 35 | * We expect only one object to implement TYPE_NMI, so once |
| 36 | * we've asked it to deliver the NMI we can stop looking. |
| 37 | */ |
| 38 | return 1; |
| 39 | } |
| 40 | |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | bool nmi_inject(Error **errp) |
| 45 | { |
| 46 | bool handled = false; |
| 47 | |
| 48 | object_child_foreach_recursive(object_get_root(), do_nmi, &handled); |
| 49 | if (!handled) { |
| 50 | error_setg(errp, "machine does not provide NMIs"); |
| 51 | return false; |
| 52 | } |
| 53 | return true; |
| 54 | } |
| 55 | |
| 56 | static const TypeInfo nmi_info = { |
| 57 | .name = TYPE_NMI, |
| 58 | .parent = TYPE_INTERFACE, |
| 59 | .class_size = sizeof(NMIClass), |
| 60 | }; |
| 61 | |
| 62 | static void nmi_register_types(void) |
| 63 | { |
| 64 | type_register_static(&nmi_info); |
| 65 | } |
| 66 | |
| 67 | type_init(nmi_register_types) |