]> git.ipfire.org Git - thirdparty/qemu.git/blame - hw/watchdog/wdt_ib700.c
Include migration/vmstate.h less
[thirdparty/qemu.git] / hw / watchdog / wdt_ib700.c
CommitLineData
9dd986cc
RJ
1/*
2 * Virtual hardware watchdog.
3 *
4 * Copyright (C) 2009 Red Hat Inc.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
8167ee88 17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
9dd986cc
RJ
18 *
19 * By Richard W.M. Jones (rjones@redhat.com).
20 */
21
0430891c 22#include "qemu/osdep.h"
0b8fa32f 23#include "qemu/module.h"
1de7afc9 24#include "qemu/timer.h"
0d09e41a 25#include "sysemu/watchdog.h"
83c9f4ca 26#include "hw/hw.h"
0d09e41a 27#include "hw/isa/isa.h"
d6454270 28#include "migration/vmstate.h"
9dd986cc
RJ
29
30/*#define IB700_DEBUG 1*/
31
32#ifdef IB700_DEBUG
33#define ib700_debug(fs,...) \
34 fprintf(stderr,"ib700: %s: "fs,__func__,##__VA_ARGS__)
35#else
36#define ib700_debug(fs,...)
37#endif
38
61e477f4
AF
39#define TYPE_IB700 "ib700"
40#define IB700(obj) OBJECT_CHECK(IB700State, (obj), TYPE_IB700)
41
f309270b 42typedef struct IB700state {
61e477f4
AF
43 ISADevice parent_obj;
44
e8f27c72 45 QEMUTimer *timer;
848696bf
KB
46
47 PortioList port_list;
f309270b
JQ
48} IB700State;
49
9dd986cc
RJ
50/* This is the timer. We use a global here because the watchdog
51 * code ensures there is only one watchdog (it is located at a fixed,
66a0a2cb 52 * unchangeable IO port, so there could only ever be one anyway).
9dd986cc 53 */
9dd986cc
RJ
54
55/* A write to this register enables the timer. */
56static void ib700_write_enable_reg(void *vp, uint32_t addr, uint32_t data)
57{
e8f27c72 58 IB700State *s = vp;
9dd986cc
RJ
59 static int time_map[] = {
60 30, 28, 26, 24, 22, 20, 18, 16,
61 14, 12, 10, 8, 6, 4, 2, 0
62 };
c910cf96 63 int64_t timeout;
9dd986cc
RJ
64
65 ib700_debug("addr = %x, data = %x\n", addr, data);
66
73bcb24d 67 timeout = (int64_t) time_map[data & 0xF] * NANOSECONDS_PER_SECOND;
bc72ad67 68 timer_mod(s->timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + timeout);
9dd986cc
RJ
69}
70
71/* A write (of any value) to this register disables the timer. */
72static void ib700_write_disable_reg(void *vp, uint32_t addr, uint32_t data)
73{
e8f27c72
JQ
74 IB700State *s = vp;
75
9dd986cc
RJ
76 ib700_debug("addr = %x, data = %x\n", addr, data);
77
bc72ad67 78 timer_del(s->timer);
9dd986cc
RJ
79}
80
81/* This is called when the watchdog expires. */
82static void ib700_timer_expired(void *vp)
83{
e8f27c72
JQ
84 IB700State *s = vp;
85
9dd986cc
RJ
86 ib700_debug("watchdog expired\n");
87
88 watchdog_perform_action();
bc72ad67 89 timer_del(s->timer);
9dd986cc
RJ
90}
91
9958068d
JQ
92static const VMStateDescription vmstate_ib700 = {
93 .name = "ib700_wdt",
94 .version_id = 0,
95 .minimum_version_id = 0,
d49805ae 96 .fields = (VMStateField[]) {
e720677e 97 VMSTATE_TIMER_PTR(timer, IB700State),
9958068d
JQ
98 VMSTATE_END_OF_LIST()
99 }
100};
9dd986cc 101
0c6c4e28
JK
102static const MemoryRegionPortio wdt_portio_list[] = {
103 { 0x441, 2, 1, .write = ib700_write_disable_reg, },
104 { 0x443, 2, 1, .write = ib700_write_enable_reg, },
105 PORTIO_END_OF_LIST(),
106};
107
db895a1e 108static void wdt_ib700_realize(DeviceState *dev, Error **errp)
9dd986cc 109{
61e477f4 110 IB700State *s = IB700(dev);
f309270b 111
36888c63
RJ
112 ib700_debug("watchdog init\n");
113
bc72ad67 114 s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, ib700_timer_expired, s);
0c6c4e28 115
848696bf
KB
116 portio_list_init(&s->port_list, OBJECT(s), wdt_portio_list, s, "ib700");
117 portio_list_add(&s->port_list, isa_address_space_io(&s->parent_obj), 0);
9dd986cc
RJ
118}
119
36888c63
RJ
120static void wdt_ib700_reset(DeviceState *dev)
121{
61e477f4 122 IB700State *s = IB700(dev);
36888c63
RJ
123
124 ib700_debug("watchdog reset\n");
125
bc72ad67 126 timer_del(s->timer);
36888c63
RJ
127}
128
9dd986cc
RJ
129static WatchdogTimerModel model = {
130 .wdt_name = "ib700",
131 .wdt_description = "iBASE 700",
9dd986cc
RJ
132};
133
8f04ee08
AL
134static void wdt_ib700_class_init(ObjectClass *klass, void *data)
135{
39bffca2 136 DeviceClass *dc = DEVICE_CLASS(klass);
db895a1e
AF
137
138 dc->realize = wdt_ib700_realize;
39bffca2
AL
139 dc->reset = wdt_ib700_reset;
140 dc->vmsd = &vmstate_ib700;
125ee0ed 141 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
8f04ee08
AL
142}
143
8c43a6f0 144static const TypeInfo wdt_ib700_info = {
61e477f4 145 .name = TYPE_IB700,
39bffca2
AL
146 .parent = TYPE_ISA_DEVICE,
147 .instance_size = sizeof(IB700State),
148 .class_init = wdt_ib700_class_init,
09aaa160
MA
149};
150
83f7d43a 151static void wdt_ib700_register_types(void)
9dd986cc
RJ
152{
153 watchdog_add_model(&model);
39bffca2 154 type_register_static(&wdt_ib700_info);
9dd986cc 155}
09aaa160 156
83f7d43a 157type_init(wdt_ib700_register_types)