qapi: Call QAPIDoc.check() always
[qemu/kevin.git] / hw / watchdog / wdt_diag288.c
blob1b73b16fb358a27dbe95af5d14377a23a645ea2f
1 /*
2 * watchdog device diag288 support
4 * Copyright IBM, Corp. 2015
6 * Authors:
7 * Xu Wang <gesaint@linux.vnet.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or (at your
10 * option) any later version. See the COPYING file in the top-level directory.
14 #include "qemu/osdep.h"
15 #include "sysemu/reset.h"
16 #include "sysemu/watchdog.h"
17 #include "qemu/timer.h"
18 #include "hw/watchdog/wdt_diag288.h"
19 #include "migration/vmstate.h"
20 #include "qemu/log.h"
22 static const VMStateDescription vmstate_diag288 = {
23 .name = "vmstate_diag288",
24 .version_id = 0,
25 .minimum_version_id = 0,
26 .fields = (const VMStateField[]) {
27 VMSTATE_TIMER_PTR(timer, DIAG288State),
28 VMSTATE_BOOL(enabled, DIAG288State),
29 VMSTATE_END_OF_LIST()
33 static void wdt_diag288_reset(DeviceState *dev)
35 DIAG288State *diag288 = DIAG288(dev);
37 diag288->enabled = false;
38 timer_del(diag288->timer);
41 static void diag288_reset(void *opaque)
43 DeviceState *diag288 = opaque;
45 wdt_diag288_reset(diag288);
48 static void diag288_timer_expired(void *dev)
50 qemu_log_mask(CPU_LOG_RESET, "Watchdog timer expired.\n");
51 /* Reset the watchdog only if the guest gets notified about
52 * expiry. watchdog_perform_action() may temporarily relinquish
53 * the BQL; reset before triggering the action to avoid races with
54 * diag288 instructions. */
55 switch (get_watchdog_action()) {
56 case WATCHDOG_ACTION_DEBUG:
57 case WATCHDOG_ACTION_NONE:
58 case WATCHDOG_ACTION_PAUSE:
59 break;
60 default:
61 wdt_diag288_reset(dev);
63 watchdog_perform_action();
66 static int wdt_diag288_handle_timer(DIAG288State *diag288,
67 uint64_t func, uint64_t timeout)
69 switch (func) {
70 case WDT_DIAG288_INIT:
71 diag288->enabled = true;
72 /* fall through */
73 case WDT_DIAG288_CHANGE:
74 if (!diag288->enabled) {
75 return -1;
77 timer_mod(diag288->timer,
78 qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
79 timeout * NANOSECONDS_PER_SECOND);
80 break;
81 case WDT_DIAG288_CANCEL:
82 if (!diag288->enabled) {
83 return -1;
85 diag288->enabled = false;
86 timer_del(diag288->timer);
87 break;
88 default:
89 return -1;
92 return 0;
95 static void wdt_diag288_realize(DeviceState *dev, Error **errp)
97 DIAG288State *diag288 = DIAG288(dev);
99 qemu_register_reset(diag288_reset, diag288);
100 diag288->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, diag288_timer_expired,
101 dev);
104 static void wdt_diag288_unrealize(DeviceState *dev)
106 DIAG288State *diag288 = DIAG288(dev);
108 timer_free(diag288->timer);
111 static void wdt_diag288_class_init(ObjectClass *klass, void *data)
113 DeviceClass *dc = DEVICE_CLASS(klass);
114 DIAG288Class *diag288 = DIAG288_CLASS(klass);
116 dc->realize = wdt_diag288_realize;
117 dc->unrealize = wdt_diag288_unrealize;
118 dc->reset = wdt_diag288_reset;
119 dc->hotpluggable = false;
120 set_bit(DEVICE_CATEGORY_WATCHDOG, dc->categories);
121 dc->vmsd = &vmstate_diag288;
122 diag288->handle_timer = wdt_diag288_handle_timer;
123 dc->desc = "diag288 device for s390x platform";
126 static const TypeInfo wdt_diag288_info = {
127 .class_init = wdt_diag288_class_init,
128 .parent = TYPE_DEVICE,
129 .name = TYPE_WDT_DIAG288,
130 .instance_size = sizeof(DIAG288State),
131 .class_size = sizeof(DIAG288Class),
134 static void wdt_diag288_register_types(void)
136 type_register_static(&wdt_diag288_info);
139 type_init(wdt_diag288_register_types)