Statistics
| Branch: | Revision:

root / hw / wdt_ib700.c @ f7897430

History | View | Annotate | Download (3 kB)

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
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
19
 * USA.
20
 *
21
 * By Richard W.M. Jones (rjones@redhat.com).
22
 */
23

    
24
#include "qemu-common.h"
25
#include "qemu-timer.h"
26
#include "watchdog.h"
27
#include "hw.h"
28
#include "isa.h"
29
#include "pc.h"
30

    
31
/*#define IB700_DEBUG 1*/
32

    
33
#ifdef IB700_DEBUG
34
#define ib700_debug(fs,...)                                        \
35
    fprintf(stderr,"ib700: %s: "fs,__func__,##__VA_ARGS__)
36
#else
37
#define ib700_debug(fs,...)
38
#endif
39

    
40
/* This is the timer.  We use a global here because the watchdog
41
 * code ensures there is only one watchdog (it is located at a fixed,
42
 * unchangable IO port, so there could only ever be one anyway).
43
 */
44
static QEMUTimer *timer = NULL;
45

    
46
/* A write to this register enables the timer. */
47
static void ib700_write_enable_reg(void *vp, uint32_t addr, uint32_t data)
48
{
49
    static int time_map[] = {
50
        30, 28, 26, 24, 22, 20, 18, 16,
51
        14, 12, 10,  8,  6,  4,  2,  0
52
    };
53
    int64 timeout;
54

    
55
    ib700_debug("addr = %x, data = %x\n", addr, data);
56

    
57
    timeout = (int64_t) time_map[data & 0xF] * ticks_per_sec;
58
    qemu_mod_timer(timer, qemu_get_clock (vm_clock) + timeout);
59
}
60

    
61
/* A write (of any value) to this register disables the timer. */
62
static void ib700_write_disable_reg(void *vp, uint32_t addr, uint32_t data)
63
{
64
    ib700_debug("addr = %x, data = %x\n", addr, data);
65

    
66
    qemu_del_timer(timer);
67
}
68

    
69
/* This is called when the watchdog expires. */
70
static void ib700_timer_expired(void *vp)
71
{
72
    ib700_debug("watchdog expired\n");
73

    
74
    watchdog_perform_action();
75
    qemu_del_timer(timer);
76
}
77

    
78
static void ib700_save(QEMUFile *f, void *vp)
79
{
80
    qemu_put_timer(f, timer);
81
}
82

    
83
static int ib700_load(QEMUFile *f, void *vp, int version)
84
{
85
    if (version != 0)
86
        return -EINVAL;
87

    
88
    qemu_get_timer(f, timer);
89

    
90
    return 0;
91
}
92

    
93
/* Create and initialize a virtual IB700 during PC creation. */
94
static void ib700_pc_init(PCIBus *unused)
95
{
96
    register_savevm("ib700_wdt", -1, 0, ib700_save, ib700_load, NULL);
97

    
98
    register_ioport_write(0x441, 2, 1, ib700_write_disable_reg, NULL);
99
    register_ioport_write(0x443, 2, 1, ib700_write_enable_reg, NULL);
100
}
101

    
102
static WatchdogTimerModel model = {
103
    .wdt_name = "ib700",
104
    .wdt_description = "iBASE 700",
105
    .wdt_pc_init = ib700_pc_init,
106
};
107

    
108
void wdt_ib700_init(void)
109
{
110
    watchdog_add_model(&model);
111
    timer = qemu_new_timer(vm_clock, ib700_timer_expired, NULL);
112
}