]> git.proxmox.com Git - mirror_qemu.git/blame - hw/wdt_ib700.c
qdev: add return value to init() callbacks.
[mirror_qemu.git] / hw / 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"
23#include "qemu-timer.h"
24#include "watchdog.h"
25#include "hw.h"
26#include "isa.h"
27#include "pc.h"
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
38/* This is the timer. We use a global here because the watchdog
39 * code ensures there is only one watchdog (it is located at a fixed,
40 * unchangable IO port, so there could only ever be one anyway).
41 */
42static QEMUTimer *timer = NULL;
43
44/* A write to this register enables the timer. */
45static void ib700_write_enable_reg(void *vp, uint32_t addr, uint32_t data)
46{
47 static int time_map[] = {
48 30, 28, 26, 24, 22, 20, 18, 16,
49 14, 12, 10, 8, 6, 4, 2, 0
50 };
51 int64 timeout;
52
53 ib700_debug("addr = %x, data = %x\n", addr, data);
54
55 timeout = (int64_t) time_map[data & 0xF] * ticks_per_sec;
56 qemu_mod_timer(timer, qemu_get_clock (vm_clock) + timeout);
57}
58
59/* A write (of any value) to this register disables the timer. */
60static void ib700_write_disable_reg(void *vp, uint32_t addr, uint32_t data)
61{
62 ib700_debug("addr = %x, data = %x\n", addr, data);
63
64 qemu_del_timer(timer);
65}
66
67/* This is called when the watchdog expires. */
68static void ib700_timer_expired(void *vp)
69{
70 ib700_debug("watchdog expired\n");
71
72 watchdog_perform_action();
73 qemu_del_timer(timer);
74}
75
76static void ib700_save(QEMUFile *f, void *vp)
77{
78 qemu_put_timer(f, timer);
79}
80
81static int ib700_load(QEMUFile *f, void *vp, int version)
82{
83 if (version != 0)
84 return -EINVAL;
85
86 qemu_get_timer(f, timer);
87
88 return 0;
89}
90
81a322d4 91static int wdt_ib700_init(ISADevice *dev)
9dd986cc 92{
09aaa160 93 timer = qemu_new_timer(vm_clock, ib700_timer_expired, NULL);
9dd986cc 94 register_savevm("ib700_wdt", -1, 0, ib700_save, ib700_load, NULL);
9dd986cc
RJ
95 register_ioport_write(0x441, 2, 1, ib700_write_disable_reg, NULL);
96 register_ioport_write(0x443, 2, 1, ib700_write_enable_reg, NULL);
81a322d4
GH
97
98 return 0;
9dd986cc
RJ
99}
100
101static WatchdogTimerModel model = {
102 .wdt_name = "ib700",
103 .wdt_description = "iBASE 700",
9dd986cc
RJ
104};
105
09aaa160
MA
106static ISADeviceInfo wdt_ib700_info = {
107 .qdev.name = "ib700",
108 .qdev.size = sizeof(ISADevice),
109 .init = wdt_ib700_init,
110};
111
112static void wdt_ib700_register_devices(void)
9dd986cc
RJ
113{
114 watchdog_add_model(&model);
09aaa160 115 isa_qdev_register(&wdt_ib700_info);
9dd986cc 116}
09aaa160
MA
117
118device_init(wdt_ib700_register_devices);