Patchwork [5/6] ib700: move timer to IB700State

login
register
mail settings
Submitter Juan Quintela
Date Oct. 14, 2009, 11:40 p.m.
Message ID <fc2507149c34dadd2df8e7bc645dca4f5507f5a0.1255563370.git.quintela@redhat.com>
Download mbox | patch
Permalink /patch/36036/
State New
Headers show

Comments

Juan Quintela - Oct. 14, 2009, 11:40 p.m.
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/wdt_ib700.c |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)
Richard W.M. Jones - Oct. 15, 2009, 8:42 a.m.
On Thu, Oct 15, 2009 at 01:40:01AM +0200, Juan Quintela wrote:
> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>
[...]

Simple clean-up, removes a global variable, and the fact that
the device registers a global port should ensure we can't have
more than one of them anyway.

ACK.

Rich.

Patch

diff --git a/hw/wdt_ib700.c b/hw/wdt_ib700.c
index e598df5..d2b9b41 100644
--- a/hw/wdt_ib700.c
+++ b/hw/wdt_ib700.c
@@ -37,17 +37,18 @@ 

 typedef struct IB700state {
     ISADevice dev;
+    QEMUTimer *timer;
 } IB700State;

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

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

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

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

-    qemu_del_timer(timer);
+    qemu_del_timer(s->timer);
 }

 /* This is called when the watchdog expires. */
 static void ib700_timer_expired(void *vp)
 {
+    IB700State *s = vp;
+
     ib700_debug("watchdog expired\n");

     watchdog_perform_action();
-    qemu_del_timer(timer);
+    qemu_del_timer(s->timer);
 }

 static void ib700_save(QEMUFile *f, void *vp)
 {
-    qemu_put_timer(f, timer);
+    IB700State *s = vp;
+
+    qemu_put_timer(f, s->timer);
 }

 static int ib700_load(QEMUFile *f, void *vp, int version)
 {
+    IB700State *s = vp;
+
     if (version != 0)
         return -EINVAL;

-    qemu_get_timer(f, timer);
+    qemu_get_timer(f, s->timer);

     return 0;
 }
@@ -96,7 +105,7 @@  static int wdt_ib700_init(ISADevice *dev)
 {
     IB700State *s = DO_UPCAST(IB700State, dev, dev);

-    timer = qemu_new_timer(vm_clock, ib700_timer_expired, s);
+    s->timer = qemu_new_timer(vm_clock, ib700_timer_expired, s);
     register_savevm("ib700_wdt", -1, 0, ib700_save, ib700_load, s);
     register_ioport_write(0x441, 2, 1, ib700_write_disable_reg, s);
     register_ioport_write(0x443, 2, 1, ib700_write_enable_reg, s);