Revert xen/io/ring.h of "Clean up a few header guard symbols"
[qemu/ar7.git] / hw / watchdog / wdt_diag288.c
blob29e5b5dcf6a419dde808a3837773b59cac4f1e98
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/watchdog.h"
16 #include "hw/sysbus.h"
17 #include "qemu/timer.h"
18 #include "hw/watchdog/wdt_diag288.h"
19 #include "qemu/log.h"
20 #include "qemu/module.h"
22 static WatchdogTimerModel model = {
23 .wdt_name = TYPE_WDT_DIAG288,
24 .wdt_description = "diag288 device for s390x platform",
27 static const VMStateDescription vmstate_diag288 = {
28 .name = "vmstate_diag288",
29 .version_id = 0,
30 .minimum_version_id = 0,
31 .fields = (VMStateField[]) {
32 VMSTATE_TIMER_PTR(timer, DIAG288State),
33 VMSTATE_BOOL(enabled, DIAG288State),
34 VMSTATE_END_OF_LIST()
38 static void wdt_diag288_reset(DeviceState *dev)
40 DIAG288State *diag288 = DIAG288(dev);
42 diag288->enabled = false;
43 timer_del(diag288->timer);
46 static void diag288_reset(void *opaque)
48 DeviceState *diag288 = opaque;
50 wdt_diag288_reset(diag288);
53 static void diag288_timer_expired(void *dev)
55 qemu_log_mask(CPU_LOG_RESET, "Watchdog timer expired.\n");
56 /* Reset the watchdog only if the guest gets notified about
57 * expiry. watchdog_perform_action() may temporarily relinquish
58 * the BQL; reset before triggering the action to avoid races with
59 * diag288 instructions. */
60 switch (get_watchdog_action()) {
61 case WATCHDOG_ACTION_DEBUG:
62 case WATCHDOG_ACTION_NONE:
63 case WATCHDOG_ACTION_PAUSE:
64 break;
65 default:
66 wdt_diag288_reset(dev);
68 watchdog_perform_action();
71 static int wdt_diag288_handle_timer(DIAG288State *diag288,
72 uint64_t func, uint64_t timeout)
74 switch (func) {
75 case WDT_DIAG288_INIT:
76 diag288->enabled = true;
77 /* fall through */
78 case WDT_DIAG288_CHANGE:
79 if (!diag288->enabled) {
80 return -1;
82 timer_mod(diag288->timer,
83 qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
84 timeout * NANOSECONDS_PER_SECOND);
85 break;
86 case WDT_DIAG288_CANCEL:
87 if (!diag288->enabled) {
88 return -1;
90 diag288->enabled = false;
91 timer_del(diag288->timer);
92 break;
93 default:
94 return -1;
97 return 0;
100 static void wdt_diag288_realize(DeviceState *dev, Error **errp)
102 DIAG288State *diag288 = DIAG288(dev);
104 qemu_register_reset(diag288_reset, diag288);
105 diag288->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, diag288_timer_expired,
106 dev);
109 static void wdt_diag288_unrealize(DeviceState *dev, Error **errp)
111 DIAG288State *diag288 = DIAG288(dev);
113 timer_del(diag288->timer);
114 timer_free(diag288->timer);
117 static void wdt_diag288_class_init(ObjectClass *klass, void *data)
119 DeviceClass *dc = DEVICE_CLASS(klass);
120 DIAG288Class *diag288 = DIAG288_CLASS(klass);
122 dc->realize = wdt_diag288_realize;
123 dc->unrealize = wdt_diag288_unrealize;
124 dc->reset = wdt_diag288_reset;
125 dc->hotpluggable = false;
126 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
127 dc->vmsd = &vmstate_diag288;
128 diag288->handle_timer = wdt_diag288_handle_timer;
131 static const TypeInfo wdt_diag288_info = {
132 .class_init = wdt_diag288_class_init,
133 .parent = TYPE_DEVICE,
134 .name = TYPE_WDT_DIAG288,
135 .instance_size = sizeof(DIAG288State),
136 .class_size = sizeof(DIAG288Class),
139 static void wdt_diag288_register_types(void)
141 watchdog_add_model(&model);
142 type_register_static(&wdt_diag288_info);
145 type_init(wdt_diag288_register_types)