2
0

reset.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Reset handlers.
  3. *
  4. * Copyright (c) 2003-2008 Fabrice Bellard
  5. * Copyright (c) 2016 Red Hat, Inc.
  6. * Copyright (c) 2024 Linaro, Ltd.
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  21. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #ifndef QEMU_SYSTEM_RESET_H
  27. #define QEMU_SYSTEM_RESET_H
  28. #include "hw/resettable.h"
  29. #include "qapi/qapi-events-run-state.h"
  30. typedef void QEMUResetHandler(void *opaque);
  31. /**
  32. * qemu_register_resettable: Register an object to be reset
  33. * @obj: object to be reset: it must implement the Resettable interface
  34. *
  35. * Register @obj on the list of objects which will be reset when the
  36. * simulation is reset. These objects will be reset in the order
  37. * they were added, using the three-phase Resettable protocol,
  38. * so first all objects go through the enter phase, then all objects
  39. * go through the hold phase, and then finally all go through the
  40. * exit phase.
  41. *
  42. * It is not permitted to register or unregister reset functions or
  43. * resettable objects from within any of the reset phase methods of @obj.
  44. *
  45. * We assume that the caller holds the BQL.
  46. */
  47. void qemu_register_resettable(Object *obj);
  48. /**
  49. * qemu_unregister_resettable: Unregister an object to be reset
  50. * @obj: object to unregister
  51. *
  52. * Remove @obj from the list of objects which are reset when the
  53. * simulation is reset. It must have been previously added to
  54. * the list via qemu_register_resettable().
  55. *
  56. * We assume that the caller holds the BQL.
  57. */
  58. void qemu_unregister_resettable(Object *obj);
  59. /**
  60. * qemu_register_reset: Register a callback for system reset
  61. * @func: function to call
  62. * @opaque: opaque data to pass to @func
  63. *
  64. * Register @func on the list of functions which are called when the
  65. * entire system is reset. Functions registered with this API and
  66. * Resettable objects registered with qemu_register_resettable() are
  67. * handled together, in the order in which they were registered.
  68. * Functions registered with this API are called in the 'hold' phase
  69. * of the 3-phase reset.
  70. *
  71. * In general this function should not be used in new code where possible;
  72. * for instance, device model reset is better accomplished using the
  73. * methods on DeviceState.
  74. *
  75. * It is not permitted to register or unregister reset functions or
  76. * resettable objects from within the @func callback.
  77. *
  78. * We assume that the caller holds the BQL.
  79. */
  80. void qemu_register_reset(QEMUResetHandler *func, void *opaque);
  81. /**
  82. * qemu_register_reset_nosnapshotload: Register a callback for system reset
  83. * @func: function to call
  84. * @opaque: opaque data to pass to @func
  85. *
  86. * This is the same as qemu_register_reset(), except that @func is
  87. * not called if the reason that the system is being reset is to
  88. * put it into a clean state prior to loading a snapshot (i.e. for
  89. * SHUTDOWN_CAUSE_SNAPSHOT_LOAD).
  90. */
  91. void qemu_register_reset_nosnapshotload(QEMUResetHandler *func, void *opaque);
  92. /**
  93. * qemu_unregister_reset: Unregister a system reset callback
  94. * @func: function registered with qemu_register_reset()
  95. * @opaque: the same opaque data that was passed to qemu_register_reset()
  96. *
  97. * Undo the effects of a qemu_register_reset(). The @func and @opaque
  98. * must both match the arguments originally used with qemu_register_reset().
  99. *
  100. * We assume that the caller holds the BQL.
  101. */
  102. void qemu_unregister_reset(QEMUResetHandler *func, void *opaque);
  103. /**
  104. * qemu_devices_reset: Perform a complete system reset
  105. * @reason: type of the reset
  106. *
  107. * This function performs the low-level work needed to do a complete reset
  108. * of the system (calling all the callbacks registered with
  109. * qemu_register_reset() and resetting all the Resettable objects registered
  110. * with qemu_register_resettable()). It should only be called by the code in a
  111. * MachineClass reset method.
  112. *
  113. * If you want to trigger a system reset from, for instance, a device
  114. * model, don't use this function. Use qemu_system_reset_request().
  115. */
  116. void qemu_devices_reset(ResetType type);
  117. #endif