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

hw/timer/imx_epit.c: Switch to transaction-based ptimer API

Switch the imx_epit.c code away from bottom-half based ptimers to
the new transaction-based ptimer API. This just requires adding
begin/commit calls around the various places that modify the ptimer
state, and using the new ptimer_init() function to create the timer.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20191008171740.9679-18-peter.maydell@linaro.org

+27 -5
+27 -5
hw/timer/imx_epit.c
··· 17 17 #include "migration/vmstate.h" 18 18 #include "hw/irq.h" 19 19 #include "hw/misc/imx_ccm.h" 20 - #include "qemu/main-loop.h" 21 20 #include "qemu/module.h" 22 21 #include "qemu/log.h" 23 22 ··· 74 73 } 75 74 } 76 75 76 + /* 77 + * Must be called from within a ptimer_transaction_begin/commit block 78 + * for both s->timer_cmp and s->timer_reload. 79 + */ 77 80 static void imx_epit_set_freq(IMXEPITState *s) 78 81 { 79 82 uint32_t clksrc; ··· 105 108 s->lr = EPIT_TIMER_MAX; 106 109 s->cmp = 0; 107 110 s->cnt = 0; 111 + ptimer_transaction_begin(s->timer_cmp); 112 + ptimer_transaction_begin(s->timer_reload); 108 113 /* stop both timers */ 109 114 ptimer_stop(s->timer_cmp); 110 115 ptimer_stop(s->timer_reload); ··· 117 122 /* if the timer is still enabled, restart it */ 118 123 ptimer_run(s->timer_reload, 0); 119 124 } 125 + ptimer_transaction_commit(s->timer_cmp); 126 + ptimer_transaction_commit(s->timer_reload); 120 127 } 121 128 122 129 static uint32_t imx_epit_update_count(IMXEPITState *s) ··· 164 171 return reg_value; 165 172 } 166 173 174 + /* Must be called from ptimer_transaction_begin/commit block for s->timer_cmp */ 167 175 static void imx_epit_reload_compare_timer(IMXEPITState *s) 168 176 { 169 177 if ((s->cr & (CR_EN | CR_OCIEN)) == (CR_EN | CR_OCIEN)) { ··· 191 199 192 200 switch (offset >> 2) { 193 201 case 0: /* CR */ 202 + ptimer_transaction_begin(s->timer_cmp); 203 + ptimer_transaction_begin(s->timer_reload); 194 204 195 205 oldcr = s->cr; 196 206 s->cr = value & 0x03ffffff; ··· 231 241 } else { 232 242 ptimer_stop(s->timer_cmp); 233 243 } 244 + 245 + ptimer_transaction_commit(s->timer_cmp); 246 + ptimer_transaction_commit(s->timer_reload); 234 247 break; 235 248 236 249 case 1: /* SR - ACK*/ ··· 244 257 case 2: /* LR - set ticks */ 245 258 s->lr = value; 246 259 260 + ptimer_transaction_begin(s->timer_cmp); 261 + ptimer_transaction_begin(s->timer_reload); 247 262 if (s->cr & CR_RLD) { 248 263 /* Also set the limit if the LRD bit is set */ 249 264 /* If IOVW bit is set then set the timer value */ ··· 255 270 } 256 271 257 272 imx_epit_reload_compare_timer(s); 273 + ptimer_transaction_commit(s->timer_cmp); 274 + ptimer_transaction_commit(s->timer_reload); 258 275 break; 259 276 260 277 case 3: /* CMP */ 261 278 s->cmp = value; 262 279 280 + ptimer_transaction_begin(s->timer_cmp); 263 281 imx_epit_reload_compare_timer(s); 282 + ptimer_transaction_commit(s->timer_cmp); 264 283 265 284 break; 266 285 ··· 281 300 imx_epit_update_int(s); 282 301 } 283 302 303 + static void imx_epit_reload(void *opaque) 304 + { 305 + /* No action required on rollover of timer_reload */ 306 + } 307 + 284 308 static const MemoryRegionOps imx_epit_ops = { 285 309 .read = imx_epit_read, 286 310 .write = imx_epit_write, ··· 308 332 { 309 333 IMXEPITState *s = IMX_EPIT(dev); 310 334 SysBusDevice *sbd = SYS_BUS_DEVICE(dev); 311 - QEMUBH *bh; 312 335 313 336 DPRINTF("\n"); 314 337 ··· 317 340 0x00001000); 318 341 sysbus_init_mmio(sbd, &s->iomem); 319 342 320 - s->timer_reload = ptimer_init_with_bh(NULL, PTIMER_POLICY_DEFAULT); 343 + s->timer_reload = ptimer_init(imx_epit_reload, s, PTIMER_POLICY_DEFAULT); 321 344 322 - bh = qemu_bh_new(imx_epit_cmp, s); 323 - s->timer_cmp = ptimer_init_with_bh(bh, PTIMER_POLICY_DEFAULT); 345 + s->timer_cmp = ptimer_init(imx_epit_cmp, s, PTIMER_POLICY_DEFAULT); 324 346 } 325 347 326 348 static void imx_epit_class_init(ObjectClass *klass, void *data)