Revision e8f27c72

b/hw/wdt_ib700.c
37 37

  
38 38
typedef struct IB700state {
39 39
    ISADevice dev;
40
    QEMUTimer *timer;
40 41
} IB700State;
41 42

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

  
48 48
/* A write to this register enables the timer. */
49 49
static void ib700_write_enable_reg(void *vp, uint32_t addr, uint32_t data)
50 50
{
51
    IB700State *s = vp;
51 52
    static int time_map[] = {
52 53
        30, 28, 26, 24, 22, 20, 18, 16,
53 54
        14, 12, 10,  8,  6,  4,  2,  0
......
57 58
    ib700_debug("addr = %x, data = %x\n", addr, data);
58 59

  
59 60
    timeout = (int64_t) time_map[data & 0xF] * get_ticks_per_sec();
60
    qemu_mod_timer(timer, qemu_get_clock (vm_clock) + timeout);
61
    qemu_mod_timer(s->timer, qemu_get_clock (vm_clock) + timeout);
61 62
}
62 63

  
63 64
/* A write (of any value) to this register disables the timer. */
64 65
static void ib700_write_disable_reg(void *vp, uint32_t addr, uint32_t data)
65 66
{
67
    IB700State *s = vp;
68

  
66 69
    ib700_debug("addr = %x, data = %x\n", addr, data);
67 70

  
68
    qemu_del_timer(timer);
71
    qemu_del_timer(s->timer);
69 72
}
70 73

  
71 74
/* This is called when the watchdog expires. */
72 75
static void ib700_timer_expired(void *vp)
73 76
{
77
    IB700State *s = vp;
78

  
74 79
    ib700_debug("watchdog expired\n");
75 80

  
76 81
    watchdog_perform_action();
77
    qemu_del_timer(timer);
82
    qemu_del_timer(s->timer);
78 83
}
79 84

  
80 85
static void ib700_save(QEMUFile *f, void *vp)
81 86
{
82
    qemu_put_timer(f, timer);
87
    IB700State *s = vp;
88

  
89
    qemu_put_timer(f, s->timer);
83 90
}
84 91

  
85 92
static int ib700_load(QEMUFile *f, void *vp, int version)
86 93
{
94
    IB700State *s = vp;
95

  
87 96
    if (version != 0)
88 97
        return -EINVAL;
89 98

  
90
    qemu_get_timer(f, timer);
99
    qemu_get_timer(f, s->timer);
91 100

  
92 101
    return 0;
93 102
}
......
96 105
{
97 106
    IB700State *s = DO_UPCAST(IB700State, dev, dev);
98 107

  
99
    timer = qemu_new_timer(vm_clock, ib700_timer_expired, s);
108
    s->timer = qemu_new_timer(vm_clock, ib700_timer_expired, s);
100 109
    register_savevm("ib700_wdt", -1, 0, ib700_save, ib700_load, s);
101 110
    register_ioport_write(0x441, 2, 1, ib700_write_disable_reg, s);
102 111
    register_ioport_write(0x443, 2, 1, ib700_write_enable_reg, s);

Also available in: Unified diff