diff mbox

[v16,11/16] hw/ptimer: Add "no immediate reload" policy

Message ID 18ca577ca44d4b4ee8d72a089b1eee90a45b1c8b.1473252818.git.digetx@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Dmitry Osipenko Sept. 7, 2016, 1:22 p.m. UTC
Immediate counter re-load on setting (or on starting to run with)
counter = 0 is a wrong behaviour for some of the timers. Add "no
immediate reload" policy that provides correct behaviour for such timers.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 hw/core/ptimer.c    | 8 +++++---
 include/hw/ptimer.h | 3 +++
 2 files changed, 8 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c
index 018589d..f7f5538 100644
--- a/hw/core/ptimer.c
+++ b/hw/core/ptimer.c
@@ -45,7 +45,7 @@  static void ptimer_reload(ptimer_state *s, int delta_adjust)
         ptimer_trigger(s);
     }
 
-    if (delta == 0) {
+    if (delta == 0 && !(s->policy_mask & PTIMER_POLICY_NO_IMMEDIATE_RELOAD)) {
         delta = s->delta = s->limit;
     }
 
@@ -107,11 +107,13 @@  static void ptimer_tick(void *opaque)
 {
     ptimer_state *s = (ptimer_state *)opaque;
     ptimer_trigger(s);
-    s->delta = 0;
     if (s->enabled == 2) {
+        s->delta = 0;
         s->enabled = 0;
     } else {
-        ptimer_reload(s, 1);
+        int delta_adjust = (s->delta != 0 && s->limit != 0) ? 1 : 0;
+        s->delta = s->limit;
+        ptimer_reload(s, delta_adjust);
     }
 }
 
diff --git a/include/hw/ptimer.h b/include/hw/ptimer.h
index 4b7c53c..131fed1 100644
--- a/include/hw/ptimer.h
+++ b/include/hw/ptimer.h
@@ -46,6 +46,9 @@ 
  * trigger.  */
 #define PTIMER_POLICY_NO_IMMEDIATE_TRIGGER  (1 << 2)
 
+/* Starting to run with/setting counter = 0 won't re-load counter.  */
+#define PTIMER_POLICY_NO_IMMEDIATE_RELOAD   (1 << 3)
+
 /* ptimer.c */
 typedef struct ptimer_state ptimer_state;
 typedef void (*ptimer_cb)(void *opaque);