aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorDmitry Osipenko <digetx@gmail.com>2016-10-24 16:26:52 +0100
committerPeter Maydell <peter.maydell@linaro.org>2016-10-24 16:26:52 +0100
commit3f6e6a13c1a059d44b9a55ec7af8c01ef096ff7e (patch)
treee430d703c1b3a2234b94d95b75a73f276fb1b3c6 /hw
parent516deb421afc6e4f6073d0de3f33867235eef3fd (diff)
downloadqemu-3f6e6a13c1a059d44b9a55ec7af8c01ef096ff7e.zip
qemu-3f6e6a13c1a059d44b9a55ec7af8c01ef096ff7e.tar.gz
qemu-3f6e6a13c1a059d44b9a55ec7af8c01ef096ff7e.tar.bz2
hw/ptimer: Add "no immediate reload" policy
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> Message-id: bf9385cd2550ca451d564fa46007688cee3f3d9d.1475421224.git.digetx@gmail.com Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw')
-rw-r--r--hw/core/ptimer.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c
index ed3fb6c..2a69daf 100644
--- a/hw/core/ptimer.c
+++ b/hw/core/ptimer.c
@@ -48,7 +48,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;
}
@@ -79,6 +79,12 @@ static void ptimer_reload(ptimer_state *s, int delta_adjust)
}
}
+ if (delta == 0 && (s->policy_mask & PTIMER_POLICY_NO_IMMEDIATE_RELOAD)) {
+ if (s->enabled == 1 && s->limit != 0) {
+ delta = 1;
+ }
+ }
+
if (delta == 0) {
if (!qtest_enabled()) {
fprintf(stderr, "Timer with delta zero, disabling\n");
@@ -113,21 +119,36 @@ static void ptimer_reload(ptimer_state *s, int delta_adjust)
static void ptimer_tick(void *opaque)
{
ptimer_state *s = (ptimer_state *)opaque;
- ptimer_trigger(s);
- s->delta = 0;
+ bool trigger = true;
+
if (s->enabled == 2) {
+ s->delta = 0;
s->enabled = 0;
} else {
int delta_adjust = DELTA_ADJUST;
- if (s->limit == 0) {
+ if (s->delta == 0 || s->limit == 0) {
/* If a "continuous trigger" policy is not used and limit == 0,
- we should error out. */
+ we should error out. delta == 0 means that this tick is
+ caused by a "no immediate reload" policy, so it shouldn't
+ be adjusted. */
delta_adjust = DELTA_NO_ADJUST;
}
+ if (!(s->policy_mask & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER)) {
+ /* Avoid re-trigger on deferred reload if "no immediate trigger"
+ policy isn't used. */
+ trigger = (delta_adjust == DELTA_ADJUST);
+ }
+
+ s->delta = s->limit;
+
ptimer_reload(s, delta_adjust);
}
+
+ if (trigger) {
+ ptimer_trigger(s);
+ }
}
uint64_t ptimer_get_count(ptimer_state *s)