19cb805fdSAlexey Kardashevskiy /* 29cb805fdSAlexey Kardashevskiy * NMI monitor handler class and helpers. 39cb805fdSAlexey Kardashevskiy * 49cb805fdSAlexey Kardashevskiy * Copyright IBM Corp., 2014 59cb805fdSAlexey Kardashevskiy * 69cb805fdSAlexey Kardashevskiy * Author: Alexey Kardashevskiy <aik@ozlabs.ru> 79cb805fdSAlexey Kardashevskiy * 89cb805fdSAlexey Kardashevskiy * This program is free software; you can redistribute it and/or modify 99cb805fdSAlexey Kardashevskiy * it under the terms of the GNU General Public License as published by 109cb805fdSAlexey Kardashevskiy * the Free Software Foundation; either version 2 of the License, 119cb805fdSAlexey Kardashevskiy * or (at your option) any later version. 129cb805fdSAlexey Kardashevskiy * 139cb805fdSAlexey Kardashevskiy * This program is distributed in the hope that it will be useful, 149cb805fdSAlexey Kardashevskiy * but WITHOUT ANY WARRANTY; without even the implied warranty of 159cb805fdSAlexey Kardashevskiy * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 169cb805fdSAlexey Kardashevskiy * GNU General Public License for more details. 179cb805fdSAlexey Kardashevskiy * 189cb805fdSAlexey Kardashevskiy * You should have received a copy of the GNU General Public License 199cb805fdSAlexey Kardashevskiy * along with this program; if not, see <http://www.gnu.org/licenses/>. 209cb805fdSAlexey Kardashevskiy */ 219cb805fdSAlexey Kardashevskiy 2218c86e2bSPeter Maydell #include "qemu/osdep.h" 239cb805fdSAlexey Kardashevskiy #include "hw/nmi.h" 24da34e65cSMarkus Armbruster #include "qapi/error.h" 259cb805fdSAlexey Kardashevskiy #include "qapi/qmp/qerror.h" 26*0b8fa32fSMarkus Armbruster #include "qemu/module.h" 27f9a535e0SXu Wang #include "monitor/monitor.h" 289cb805fdSAlexey Kardashevskiy 299cb805fdSAlexey Kardashevskiy struct do_nmi_s { 309cb805fdSAlexey Kardashevskiy int cpu_index; 31533fdaedSMarkus Armbruster Error *err; 329cb805fdSAlexey Kardashevskiy bool handled; 339cb805fdSAlexey Kardashevskiy }; 349cb805fdSAlexey Kardashevskiy 359cb805fdSAlexey Kardashevskiy static void nmi_children(Object *o, struct do_nmi_s *ns); 369cb805fdSAlexey Kardashevskiy 379cb805fdSAlexey Kardashevskiy static int do_nmi(Object *o, void *opaque) 389cb805fdSAlexey Kardashevskiy { 399cb805fdSAlexey Kardashevskiy struct do_nmi_s *ns = opaque; 409cb805fdSAlexey Kardashevskiy NMIState *n = (NMIState *) object_dynamic_cast(o, TYPE_NMI); 419cb805fdSAlexey Kardashevskiy 429cb805fdSAlexey Kardashevskiy if (n) { 439cb805fdSAlexey Kardashevskiy NMIClass *nc = NMI_GET_CLASS(n); 449cb805fdSAlexey Kardashevskiy 459cb805fdSAlexey Kardashevskiy ns->handled = true; 46533fdaedSMarkus Armbruster nc->nmi_monitor_handler(n, ns->cpu_index, &ns->err); 47533fdaedSMarkus Armbruster if (ns->err) { 489cb805fdSAlexey Kardashevskiy return -1; 499cb805fdSAlexey Kardashevskiy } 509cb805fdSAlexey Kardashevskiy } 519cb805fdSAlexey Kardashevskiy nmi_children(o, ns); 529cb805fdSAlexey Kardashevskiy 539cb805fdSAlexey Kardashevskiy return 0; 549cb805fdSAlexey Kardashevskiy } 559cb805fdSAlexey Kardashevskiy 569cb805fdSAlexey Kardashevskiy static void nmi_children(Object *o, struct do_nmi_s *ns) 579cb805fdSAlexey Kardashevskiy { 589cb805fdSAlexey Kardashevskiy object_child_foreach(o, do_nmi, ns); 599cb805fdSAlexey Kardashevskiy } 609cb805fdSAlexey Kardashevskiy 619cb805fdSAlexey Kardashevskiy void nmi_monitor_handle(int cpu_index, Error **errp) 629cb805fdSAlexey Kardashevskiy { 639cb805fdSAlexey Kardashevskiy struct do_nmi_s ns = { 649cb805fdSAlexey Kardashevskiy .cpu_index = cpu_index, 65533fdaedSMarkus Armbruster .err = NULL, 669cb805fdSAlexey Kardashevskiy .handled = false 679cb805fdSAlexey Kardashevskiy }; 689cb805fdSAlexey Kardashevskiy 699cb805fdSAlexey Kardashevskiy nmi_children(object_get_root(), &ns); 709cb805fdSAlexey Kardashevskiy if (ns.handled) { 71533fdaedSMarkus Armbruster error_propagate(errp, ns.err); 729cb805fdSAlexey Kardashevskiy } else { 73c6bd8c70SMarkus Armbruster error_setg(errp, QERR_UNSUPPORTED); 749cb805fdSAlexey Kardashevskiy } 759cb805fdSAlexey Kardashevskiy } 769cb805fdSAlexey Kardashevskiy 779cb805fdSAlexey Kardashevskiy static const TypeInfo nmi_info = { 789cb805fdSAlexey Kardashevskiy .name = TYPE_NMI, 799cb805fdSAlexey Kardashevskiy .parent = TYPE_INTERFACE, 809cb805fdSAlexey Kardashevskiy .class_size = sizeof(NMIClass), 819cb805fdSAlexey Kardashevskiy }; 829cb805fdSAlexey Kardashevskiy 839cb805fdSAlexey Kardashevskiy static void nmi_register_types(void) 849cb805fdSAlexey Kardashevskiy { 859cb805fdSAlexey Kardashevskiy type_register_static(&nmi_info); 869cb805fdSAlexey Kardashevskiy } 879cb805fdSAlexey Kardashevskiy 889cb805fdSAlexey Kardashevskiy type_init(nmi_register_types) 89