]> Git Repo - qemu.git/blob - hw/watchdog/wdt_diag288.c
s390x/watchdog: introduce diag288 watchdog device
[qemu.git] / hw / watchdog / wdt_diag288.c
1 /*
2  * watchdog device diag288 support
3  *
4  * Copyright IBM, Corp. 2015
5  *
6  * Authors:
7  *  Xu Wang <[email protected]>
8  *
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.
11  *
12  */
13
14 #include "sysemu/watchdog.h"
15 #include "hw/sysbus.h"
16 #include "qemu/timer.h"
17 #include "hw/watchdog/wdt_diag288.h"
18
19 static WatchdogTimerModel model = {
20     .wdt_name = TYPE_WDT_DIAG288,
21     .wdt_description = "diag288 device for s390x platform",
22 };
23
24 static void wdt_diag288_reset(DeviceState *dev)
25 {
26     DIAG288State *diag288 = DIAG288(dev);
27
28     diag288->enabled = false;
29     timer_del(diag288->timer);
30 }
31
32 static void diag288_timer_expired(void *dev)
33 {
34     qemu_log_mask(CPU_LOG_RESET, "Watchdog timer expired.\n");
35     watchdog_perform_action();
36     wdt_diag288_reset(dev);
37 }
38
39 static int wdt_diag288_handle_timer(DIAG288State *diag288,
40                                      uint64_t func, uint64_t timeout)
41 {
42     switch (func) {
43     case WDT_DIAG288_INIT:
44         diag288->enabled = true;
45         /* fall through */
46     case WDT_DIAG288_CHANGE:
47         if (!diag288->enabled) {
48             return -1;
49         }
50         timer_mod(diag288->timer,
51                   qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
52                   timeout * get_ticks_per_sec());
53         break;
54     case WDT_DIAG288_CANCEL:
55         if (!diag288->enabled) {
56             return -1;
57         }
58         diag288->enabled = false;
59         timer_del(diag288->timer);
60         break;
61     default:
62         return -1;
63     }
64
65     return 0;
66 }
67
68 static void wdt_diag288_realize(DeviceState *dev, Error **errp)
69 {
70     DIAG288State *diag288 = DIAG288(dev);
71
72     diag288->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, diag288_timer_expired,
73                                   dev);
74 }
75
76 static void wdt_diag288_unrealize(DeviceState *dev, Error **errp)
77 {
78     DIAG288State *diag288 = DIAG288(dev);
79
80     timer_del(diag288->timer);
81     timer_free(diag288->timer);
82 }
83
84 static void wdt_diag288_class_init(ObjectClass *klass, void *data)
85 {
86     DeviceClass *dc = DEVICE_CLASS(klass);
87     DIAG288Class *diag288 = DIAG288_CLASS(klass);
88
89     dc->realize = wdt_diag288_realize;
90     dc->unrealize = wdt_diag288_unrealize;
91     dc->reset = wdt_diag288_reset;
92     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
93     diag288->handle_timer = wdt_diag288_handle_timer;
94 }
95
96 static const TypeInfo wdt_diag288_info = {
97     .class_init = wdt_diag288_class_init,
98     .parent = TYPE_DEVICE,
99     .name  = TYPE_WDT_DIAG288,
100     .instance_size  = sizeof(DIAG288State),
101     .class_size = sizeof(DIAG288Class),
102 };
103
104 static void wdt_diag288_register_types(void)
105 {
106     watchdog_add_model(&model);
107     type_register_static(&wdt_diag288_info);
108 }
109
110 type_init(wdt_diag288_register_types)
This page took 0.029205 seconds and 4 git commands to generate.