meson: Use -b to ignore CR vs. CR-LF issues on Windows
[qemu/ar7.git] / hw / watchdog / wdt_diag288.c
blob71a945f0bdf3df0faed7ba585d62f244fe2f49ba
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 "hw/sysbus.h"
18 #include "qemu/timer.h"
19 #include "hw/watchdog/wdt_diag288.h"
20 #include "migration/vmstate.h"
21 #include "qemu/log.h"
22 #include "qemu/module.h"
24 static WatchdogTimerModel model = {
25 .wdt_name = TYPE_WDT_DIAG288,
26 .wdt_description = "diag288 device for s390x platform",
29 static const VMStateDescription vmstate_diag288 = {
30 .name = "vmstate_diag288",
31 .version_id = 0,
32 .minimum_version_id = 0,
33 .fields = (VMStateField[]) {
34 VMSTATE_TIMER_PTR(timer, DIAG288State),
35 VMSTATE_BOOL(enabled, DIAG288State),
36 VMSTATE_END_OF_LIST()
40 static void wdt_diag288_reset(DeviceState *dev)
42 DIAG288State *diag288 = DIAG288(dev);
44 diag288->enabled = false;
45 timer_del(diag288->timer);
48 static void diag288_reset(void *opaque)
50 DeviceState *diag288 = opaque;
52 wdt_diag288_reset(diag288);
55 static void diag288_timer_expired(void *dev)
57 qemu_log_mask(CPU_LOG_RESET, "Watchdog timer expired.\n");
58 /* Reset the watchdog only if the guest gets notified about
59 * expiry. watchdog_perform_action() may temporarily relinquish
60 * the BQL; reset before triggering the action to avoid races with
61 * diag288 instructions. */
62 switch (get_watchdog_action()) {
63 case WATCHDOG_ACTION_DEBUG:
64 case WATCHDOG_ACTION_NONE:
65 case WATCHDOG_ACTION_PAUSE:
66 break;
67 default:
68 wdt_diag288_reset(dev);
70 watchdog_perform_action();
73 static int wdt_diag288_handle_timer(DIAG288State *diag288,
74 uint64_t func, uint64_t timeout)
76 switch (func) {
77 case WDT_DIAG288_INIT:
78 diag288->enabled = true;
79 /* fall through */
80 case WDT_DIAG288_CHANGE:
81 if (!diag288->enabled) {
82 return -1;
84 timer_mod(diag288->timer,
85 qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
86 timeout * NANOSECONDS_PER_SECOND);
87 break;
88 case WDT_DIAG288_CANCEL:
89 if (!diag288->enabled) {
90 return -1;
92 diag288->enabled = false;
93 timer_del(diag288->timer);
94 break;
95 default:
96 return -1;
99 return 0;
102 static void wdt_diag288_realize(DeviceState *dev, Error **errp)
104 DIAG288State *diag288 = DIAG288(dev);
106 qemu_register_reset(diag288_reset, diag288);
107 diag288->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, diag288_timer_expired,
108 dev);
111 static void wdt_diag288_unrealize(DeviceState *dev)
113 DIAG288State *diag288 = DIAG288(dev);
115 timer_del(diag288->timer);
116 timer_free(diag288->timer);
119 static void wdt_diag288_class_init(ObjectClass *klass, void *data)
121 DeviceClass *dc = DEVICE_CLASS(klass);
122 DIAG288Class *diag288 = DIAG288_CLASS(klass);
124 dc->realize = wdt_diag288_realize;
125 dc->unrealize = wdt_diag288_unrealize;
126 dc->reset = wdt_diag288_reset;
127 dc->hotpluggable = false;
128 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
129 dc->vmsd = &vmstate_diag288;
130 diag288->handle_timer = wdt_diag288_handle_timer;
133 static const TypeInfo wdt_diag288_info = {
134 .class_init = wdt_diag288_class_init,
135 .parent = TYPE_DEVICE,
136 .name = TYPE_WDT_DIAG288,
137 .instance_size = sizeof(DIAG288State),
138 .class_size = sizeof(DIAG288Class),
141 static void wdt_diag288_register_types(void)
143 watchdog_add_model(&model);
144 type_register_static(&wdt_diag288_info);
147 type_init(wdt_diag288_register_types)