1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include "qemu/osdep.h"
23#include "qemu/module.h"
24#include "qemu/timer.h"
25#include "sysemu/watchdog.h"
26#include "hw/hw.h"
27#include "hw/isa/isa.h"
28
29
30
31#ifdef IB700_DEBUG
32#define ib700_debug(fs,...) \
33 fprintf(stderr,"ib700: %s: "fs,__func__,##__VA_ARGS__)
34#else
35#define ib700_debug(fs,...)
36#endif
37
38#define TYPE_IB700 "ib700"
39#define IB700(obj) OBJECT_CHECK(IB700State, (obj), TYPE_IB700)
40
41typedef struct IB700state {
42 ISADevice parent_obj;
43
44 QEMUTimer *timer;
45
46 PortioList port_list;
47} IB700State;
48
49
50
51
52
53
54
55static void ib700_write_enable_reg(void *vp, uint32_t addr, uint32_t data)
56{
57 IB700State *s = vp;
58 static int time_map[] = {
59 30, 28, 26, 24, 22, 20, 18, 16,
60 14, 12, 10, 8, 6, 4, 2, 0
61 };
62 int64_t timeout;
63
64 ib700_debug("addr = %x, data = %x\n", addr, data);
65
66 timeout = (int64_t) time_map[data & 0xF] * NANOSECONDS_PER_SECOND;
67 timer_mod(s->timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + timeout);
68}
69
70
71static void ib700_write_disable_reg(void *vp, uint32_t addr, uint32_t data)
72{
73 IB700State *s = vp;
74
75 ib700_debug("addr = %x, data = %x\n", addr, data);
76
77 timer_del(s->timer);
78}
79
80
81static void ib700_timer_expired(void *vp)
82{
83 IB700State *s = vp;
84
85 ib700_debug("watchdog expired\n");
86
87 watchdog_perform_action();
88 timer_del(s->timer);
89}
90
91static const VMStateDescription vmstate_ib700 = {
92 .name = "ib700_wdt",
93 .version_id = 0,
94 .minimum_version_id = 0,
95 .fields = (VMStateField[]) {
96 VMSTATE_TIMER_PTR(timer, IB700State),
97 VMSTATE_END_OF_LIST()
98 }
99};
100
101static const MemoryRegionPortio wdt_portio_list[] = {
102 { 0x441, 2, 1, .write = ib700_write_disable_reg, },
103 { 0x443, 2, 1, .write = ib700_write_enable_reg, },
104 PORTIO_END_OF_LIST(),
105};
106
107static void wdt_ib700_realize(DeviceState *dev, Error **errp)
108{
109 IB700State *s = IB700(dev);
110
111 ib700_debug("watchdog init\n");
112
113 s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, ib700_timer_expired, s);
114
115 portio_list_init(&s->port_list, OBJECT(s), wdt_portio_list, s, "ib700");
116 portio_list_add(&s->port_list, isa_address_space_io(&s->parent_obj), 0);
117}
118
119static void wdt_ib700_reset(DeviceState *dev)
120{
121 IB700State *s = IB700(dev);
122
123 ib700_debug("watchdog reset\n");
124
125 timer_del(s->timer);
126}
127
128static WatchdogTimerModel model = {
129 .wdt_name = "ib700",
130 .wdt_description = "iBASE 700",
131};
132
133static void wdt_ib700_class_init(ObjectClass *klass, void *data)
134{
135 DeviceClass *dc = DEVICE_CLASS(klass);
136
137 dc->realize = wdt_ib700_realize;
138 dc->reset = wdt_ib700_reset;
139 dc->vmsd = &vmstate_ib700;
140 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
141}
142
143static const TypeInfo wdt_ib700_info = {
144 .name = TYPE_IB700,
145 .parent = TYPE_ISA_DEVICE,
146 .instance_size = sizeof(IB700State),
147 .class_init = wdt_ib700_class_init,
148};
149
150static void wdt_ib700_register_types(void)
151{
152 watchdog_add_model(&model);
153 type_register_static(&wdt_ib700_info);
154}
155
156type_init(wdt_ib700_register_types)
157