]> git.proxmox.com Git - qemu.git/blame - hw/watchdog/wdt_ib700.c
Merge git://github.com/hw-claudio/qemu-aarch64-queue into tcg-next
[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
22#include "qemu-common.h"
1de7afc9 23#include "qemu/timer.h"
0d09e41a 24#include "sysemu/watchdog.h"
83c9f4ca 25#include "hw/hw.h"
0d09e41a
PB
26#include "hw/isa/isa.h"
27#include "hw/i386/pc.h"
9dd986cc
RJ
28
29/*#define IB700_DEBUG 1*/
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
61e477f4
AF
38#define TYPE_IB700 "ib700"
39#define IB700(obj) OBJECT_CHECK(IB700State, (obj), TYPE_IB700)
40
f309270b 41typedef struct IB700state {
61e477f4
AF
42 ISADevice parent_obj;
43
e8f27c72 44 QEMUTimer *timer;
f309270b
JQ
45} IB700State;
46
9dd986cc
RJ
47/* This is the timer. We use a global here because the watchdog
48 * code ensures there is only one watchdog (it is located at a fixed,
66a0a2cb 49 * unchangeable IO port, so there could only ever be one anyway).
9dd986cc 50 */
9dd986cc
RJ
51
52/* A write to this register enables the timer. */
53static void ib700_write_enable_reg(void *vp, uint32_t addr, uint32_t data)
54{
e8f27c72 55 IB700State *s = vp;
9dd986cc
RJ
56 static int time_map[] = {
57 30, 28, 26, 24, 22, 20, 18, 16,
58 14, 12, 10, 8, 6, 4, 2, 0
59 };
c910cf96 60 int64_t timeout;
9dd986cc
RJ
61
62 ib700_debug("addr = %x, data = %x\n", addr, data);
63
6ee093c9 64 timeout = (int64_t) time_map[data & 0xF] * get_ticks_per_sec();
74475455 65 qemu_mod_timer(s->timer, qemu_get_clock_ns (vm_clock) + timeout);
9dd986cc
RJ
66}
67
68/* A write (of any value) to this register disables the timer. */
69static void ib700_write_disable_reg(void *vp, uint32_t addr, uint32_t data)
70{
e8f27c72
JQ
71 IB700State *s = vp;
72
9dd986cc
RJ
73 ib700_debug("addr = %x, data = %x\n", addr, data);
74
e8f27c72 75 qemu_del_timer(s->timer);
9dd986cc
RJ
76}
77
78/* This is called when the watchdog expires. */
79static void ib700_timer_expired(void *vp)
80{
e8f27c72
JQ
81 IB700State *s = vp;
82
9dd986cc
RJ
83 ib700_debug("watchdog expired\n");
84
85 watchdog_perform_action();
e8f27c72 86 qemu_del_timer(s->timer);
9dd986cc
RJ
87}
88
9958068d
JQ
89static const VMStateDescription vmstate_ib700 = {
90 .name = "ib700_wdt",
91 .version_id = 0,
92 .minimum_version_id = 0,
93 .minimum_version_id_old = 0,
94 .fields = (VMStateField []) {
95 VMSTATE_TIMER(timer, IB700State),
96 VMSTATE_END_OF_LIST()
97 }
98};
9dd986cc 99
0c6c4e28
JK
100static const MemoryRegionPortio wdt_portio_list[] = {
101 { 0x441, 2, 1, .write = ib700_write_disable_reg, },
102 { 0x443, 2, 1, .write = ib700_write_enable_reg, },
103 PORTIO_END_OF_LIST(),
104};
105
db895a1e 106static void wdt_ib700_realize(DeviceState *dev, Error **errp)
9dd986cc 107{
61e477f4 108 IB700State *s = IB700(dev);
0c6c4e28 109 PortioList *port_list = g_new(PortioList, 1);
f309270b 110
36888c63
RJ
111 ib700_debug("watchdog init\n");
112
74475455 113 s->timer = qemu_new_timer_ns(vm_clock, ib700_timer_expired, s);
0c6c4e28 114
db10ca90 115 portio_list_init(port_list, OBJECT(s), wdt_portio_list, s, "ib700");
0c6c4e28 116 portio_list_add(port_list, isa_address_space_io(&s->parent_obj), 0);
9dd986cc
RJ
117}
118
36888c63
RJ
119static void wdt_ib700_reset(DeviceState *dev)
120{
61e477f4 121 IB700State *s = IB700(dev);
36888c63
RJ
122
123 ib700_debug("watchdog reset\n");
124
125 qemu_del_timer(s->timer);
126}
127
9dd986cc
RJ
128static WatchdogTimerModel model = {
129 .wdt_name = "ib700",
130 .wdt_description = "iBASE 700",
9dd986cc
RJ
131};
132
8f04ee08
AL
133static void wdt_ib700_class_init(ObjectClass *klass, void *data)
134{
39bffca2 135 DeviceClass *dc = DEVICE_CLASS(klass);
db895a1e
AF
136
137 dc->realize = wdt_ib700_realize;
39bffca2
AL
138 dc->reset = wdt_ib700_reset;
139 dc->vmsd = &vmstate_ib700;
8f04ee08
AL
140}
141
8c43a6f0 142static const TypeInfo wdt_ib700_info = {
61e477f4 143 .name = TYPE_IB700,
39bffca2
AL
144 .parent = TYPE_ISA_DEVICE,
145 .instance_size = sizeof(IB700State),
146 .class_init = wdt_ib700_class_init,
09aaa160
MA
147};
148
83f7d43a 149static void wdt_ib700_register_types(void)
9dd986cc
RJ
150{
151 watchdog_add_model(&model);
39bffca2 152 type_register_static(&wdt_ib700_info);
9dd986cc 153}
09aaa160 154
83f7d43a 155type_init(wdt_ib700_register_types)