[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-arm] [PATCH for-3.0 4/4] hw/timer/cmsdk-apb-timer: run or stop tim
From: |
Peter Maydell |
Subject: |
[Qemu-arm] [PATCH for-3.0 4/4] hw/timer/cmsdk-apb-timer: run or stop timer on writes to RELOAD and VALUE |
Date: |
Tue, 3 Jul 2018 18:10:44 +0100 |
If the CMSDK APB timer is set up with a zero RELOAD value
then it will count down to zero, fire once and then stay
at zero. From the point of view of the ptimer system, the
timer is disabled; but the enable bit in the CTRL register
is still set and if the guest subsequently writes to the
RELOAD or VALUE registers this should cause the timer to
start counting down again.
Add code to the write paths for RELOAD and VALUE so that
we correctly restart the timer in this situation.
Conversely, if the new RELOAD and VALUE are both zero,
we should stop the ptimer.
Signed-off-by: Peter Maydell <address@hidden>
---
hw/timer/cmsdk-apb-timer.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/hw/timer/cmsdk-apb-timer.c b/hw/timer/cmsdk-apb-timer.c
index 3ebdc7be408..801d1dba741 100644
--- a/hw/timer/cmsdk-apb-timer.c
+++ b/hw/timer/cmsdk-apb-timer.c
@@ -126,10 +126,26 @@ static void cmsdk_apb_timer_write(void *opaque, hwaddr
offset, uint64_t value,
break;
case A_RELOAD:
/* Writing to reload also sets the current timer value */
+ if (!value) {
+ ptimer_stop(s->timer);
+ }
ptimer_set_limit(s->timer, value, 1);
+ if (value && (s->ctrl & R_CTRL_EN_MASK)) {
+ /*
+ * Make sure timer is running (it might have stopped if this
+ * was an expired one-shot timer)
+ */
+ ptimer_run(s->timer, 0);
+ }
break;
case A_VALUE:
+ if (!value && !ptimer_get_limit(s->timer)) {
+ ptimer_stop(s->timer);
+ }
ptimer_set_count(s->timer, value);
+ if (value && (s->ctrl & R_CTRL_EN_MASK)) {
+ ptimer_run(s->timer, ptimer_get_limit(s->timer) == 0);
+ }
break;
case A_INTSTATUS:
/* Just one bit, which is W1C. */
--
2.17.1
- [Qemu-arm] [PATCH for-3.0 0/4] cmsdk-apb-timer: various bugfixes, Peter Maydell, 2018/07/03
- [Qemu-arm] [PATCH for-3.0 4/4] hw/timer/cmsdk-apb-timer: run or stop timer on writes to RELOAD and VALUE,
Peter Maydell <=
- [Qemu-arm] [PATCH for-3.0 3/4] hw/timer/cmsdk-apb-timer: Correctly identify and set one-shot mode, Peter Maydell, 2018/07/03
- [Qemu-arm] [PATCH for-3.0 2/4] hw/timer/cmsdk-apb-timer: Correct ptimer policy settings, Peter Maydell, 2018/07/03
- [Qemu-arm] [PATCH for-3.0 1/4] ptimer: Add TRIGGER_ONLY_ON_DECREMENT policy option, Peter Maydell, 2018/07/03
- Re: [Qemu-arm] [Qemu-devel] [PATCH for-3.0 0/4] cmsdk-apb-timer: various bugfixes, Richard Henderson, 2018/07/03
- Re: [Qemu-arm] [PATCH for-3.0 0/4] cmsdk-apb-timer: various bugfixes, Guenter Roeck, 2018/07/03