qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

hw/ptimer: Add "no counter round down" policy

For most of the timers counter starts to decrement after first period
expires. Due to rounding down performed by the ptimer_get_count, it returns
counter - 1 for the running timer, so that for the ptimer user it looks
like counter gets decremented immediately after running the timer. Add "no
counter round down" policy that provides correct behaviour for those timers.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Message-id: ef39622d0ebfdc32a0877e59ffdf6910dc3db688.1475421224.git.digetx@gmail.com
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

authored by

Dmitry Osipenko and committed by
Peter Maydell
5580ea45 56700e1a

+13
+9
hw/core/ptimer.c
··· 231 231 } 232 232 } 233 233 } 234 + 235 + if (s->policy_mask & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN) { 236 + /* If now == last then delta == limit, i.e. the counter already 237 + represents the correct value. It would be rounded down a 1ns 238 + later. */ 239 + if (now != last) { 240 + counter += 1; 241 + } 242 + } 234 243 } else { 235 244 counter = s->delta; 236 245 }
+4
include/hw/ptimer.h
··· 51 51 * immediately, but after a one period. */ 52 52 #define PTIMER_POLICY_NO_IMMEDIATE_RELOAD (1 << 3) 53 53 54 + /* Make counter value of the running timer represent the actual value and 55 + * not the one less. */ 56 + #define PTIMER_POLICY_NO_COUNTER_ROUND_DOWN (1 << 4) 57 + 54 58 /* ptimer.c */ 55 59 typedef struct ptimer_state ptimer_state; 56 60 typedef void (*ptimer_cb)(void *opaque);