nmi.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #include "qemu/osdep.h"
  22. #include "hw/nmi.h"
  23. #include "qapi/error.h"
  24. #include "qemu/module.h"
  25. #include "monitor/monitor.h"
  26. struct do_nmi_s {
  27. int cpu_index;
  28. Error *err;
  29. bool handled;
  30. };
  31. static void nmi_children(Object *o, struct do_nmi_s *ns);
  32. static int do_nmi(Object *o, void *opaque)
  33. {
  34. struct do_nmi_s *ns = opaque;
  35. NMIState *n = (NMIState *) object_dynamic_cast(o, TYPE_NMI);
  36. if (n) {
  37. NMIClass *nc = NMI_GET_CLASS(n);
  38. ns->handled = true;
  39. nc->nmi_monitor_handler(n, ns->cpu_index, &ns->err);
  40. if (ns->err) {
  41. return -1;
  42. }
  43. }
  44. nmi_children(o, ns);
  45. return 0;
  46. }
  47. static void nmi_children(Object *o, struct do_nmi_s *ns)
  48. {
  49. object_child_foreach(o, do_nmi, ns);
  50. }
  51. void nmi_monitor_handle(int cpu_index, Error **errp)
  52. {
  53. struct do_nmi_s ns = {
  54. .cpu_index = cpu_index,
  55. .err = NULL,
  56. .handled = false
  57. };
  58. nmi_children(object_get_root(), &ns);
  59. if (ns.handled) {
  60. error_propagate(errp, ns.err);
  61. } else {
  62. error_setg(errp, "machine does not provide NMIs");
  63. }
  64. }
  65. static const TypeInfo nmi_info = {
  66. .name = TYPE_NMI,
  67. .parent = TYPE_INTERFACE,
  68. .class_size = sizeof(NMIClass),
  69. };
  70. static void nmi_register_types(void)
  71. {
  72. type_register_static(&nmi_info);
  73. }
  74. type_init(nmi_register_types)