Integrate renesas MCU/SoC timer module [part 2 from review]
cover Integrate renesas MCU/SoC timer module [part 2 from review]
Patches wrote while reviewing Yoshinory's series.
I'm not reposting his patches with the fixup squashed because I made various comment on his v1 while reviewing. So posting with !fixup for easier integration while addressing review comments.
Based-on: <[email protected]>
Philippe Mathieu-Daudé (4):
!fixup hw/timer: Add renesas_timer.
!fixup hw/rx: rx62n switch renesas_timer.
hw/timer: Remove RENESAS_TMR / RENESAS_CMT
hw/timer: Remove SH_TIMER
include/hw/rx/rx62n.h | 3 +- include/hw/timer/renesas_cmt.h | 43 --- include/hw/timer/renesas_timer.h | 1 + include/hw/timer/renesas_tmr.h | 58 ---- hw/rx/rx62n.c | 6 +- hw/timer/renesas_cmt.c | 283 ------------------ hw/timer/renesas_tmr.c | 493 ------------------------------- hw/timer/sh_timer.c | 368 ----------------------- MAINTAINERS | 1 - hw/rx/Kconfig | 1 - hw/timer/Kconfig | 7 - hw/timer/meson.build | 3 - 12 files changed, 5 insertions(+), 1262 deletions(-) delete mode 100644 include/hw/timer/renesas_cmt.h delete mode 100644 include/hw/timer/renesas_tmr.h delete mode 100644 hw/timer/renesas_cmt.c delete mode 100644 hw/timer/renesas_tmr.c delete mode 100644 hw/timer/sh_timer.c
Signature · 1 line
2.31.1
PATCH 1/4 !fixup hw/timer: Add renesas_timer.
Fixup while reviewing.
--- include/hw/timer/renesas_timer.h | 1 + hw/timer/Kconfig | 3 +++ 2 files changed, 4 insertions(+)
include/hw/timer/renesas_timer.h +1 -0
@@ -30,6 +30,7 @@ enum {enum {CMT_NR_IRQ =1 *TIMER_CH_CMT , +TMU_NR_IRQ =1 *TIMER_CH_TMU , };enum {
hw/timer/Kconfig +3 -0
@@ -43,6 +43,9 @@ config SH_TIMER config RENESAS_TMR bool +config RENESAS_CMT + bool + config RENESAS_TIMER bool select PTIMER
Signature · 1 line
2.31.1
RFC PATCH 2/4 !fixup hw/rx: rx62n switch renesas_timer.
In reply to Philippe Mathieu-DaudéFixup while reviewing.
--- include/hw/rx/rx62n.h | 3 +-- hw/rx/rx62n.c | 6 +++--- hw/rx/Kconfig | 1 - 3 files changed, 4 insertions(+), 6 deletions(-)
include/hw/rx/rx62n.h +1 -2
@@ -26,7 +26,6 @@#include "target/rx/cpu.h" #include "hw/intc/rx_icu.h" -#include "hw/timer/renesas_tmr.h" #include "hw/timer/renesas_timer.h" #include "hw/char/renesas_sci.h" #include "qemu/units.h"
@@ -55,7 +54,7 @@ struct RX62NState {RXCPU cpu;RXICUState icu; -RTMRState tmr[RX62N_NR_TMR ]; +RenesasTMUState tmr[RX62N_NR_TMR ];RenesasCMTState cmt[RX62N_NR_CMT ];RSCIState sci[RX62N_NR_SCI ];
hw/rx/rx62n.c +3 -3
@@ -163,13 +163,13 @@ static void register_tmr(RX62NState *s, int unit)int i, irqbase;object_initialize_child (OBJECT (s),"tmr[*]" , - &s->tmr[unit],TYPE_RENESAS_TMR ); + &s->tmr[unit],TYPE_RENESAS_TMU ); tmr =SYS_BUS_DEVICE (&s->tmr[unit]);qdev_prop_set_uint64 (DEVICE (tmr),"input-freq" , s->pclk_freq_hz);sysbus_realize (tmr, &error_abort); - irqbase =RX62N_TMR_IRQ +TMR_NR_IRQ * unit; -for (i =0 ; i <TMR_NR_IRQ ; i++) { + irqbase =RX62N_TMR_IRQ +TMU_NR_IRQ * unit; +for (i =0 ; i <TMU_NR_IRQ ; i++) {sysbus_connect_irq (tmr, i, s->irq[irqbase + i]); }sysbus_mmio_map (tmr,0 ,RX62N_TMR_BASE + unit *0x10 );
hw/rx/Kconfig +0 -1
@@ -1,7 +1,6 @@ config RX62N_MCU bool select RX_ICU - select RENESAS_TMR select RENESAS_TIMER select RENESAS_SCI
Signature · 1 line
2.31.1
Re: [RFC PATCH 2/4] !fixup hw/rx: rx62n switch renesas_timer.
Quoted 68 lines · Philippe Mathieu-Daudé
Fixup while reviewing.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/rx/rx62n.h | 3 +-- hw/rx/rx62n.c | 6 +++--- hw/rx/Kconfig | 1 - 3 files changed, 4 insertions(+), 6 deletions(-)include/hw/rx/rx62n.h +1
-2@@ -26,7 +26,6 @@#include "target/rx/cpu.h" #include "hw/intc/rx_icu.h" -#include "hw/timer/renesas_tmr.h" #include "hw/timer/renesas_timer.h" #include "hw/char/renesas_sci.h" #include "qemu/units.h" @@ -55,7 +54,7 @@ struct RX62NState {RXCPU cpu;RXICUState icu; -RTMRState tmr[RX62N_NR_TMR ]; +RenesasTMUState tmr[RX62N_NR_TMR ];RenesasCMTState cmt[RX62N_NR_CMT ];RSCIState sci[RX62N_NR_SCI ];hw/rx/rx62n.c +3
-3@@ -163,13 +163,13 @@ static void register_tmr(RX62NState *s, int unit)int i, irqbase;object_initialize_child (OBJECT (s),"tmr[*]" , - &s->tmr[unit],TYPE_RENESAS_TMR ); + &s->tmr[unit],TYPE_RENESAS_TMU ); tmr =SYS_BUS_DEVICE (&s->tmr[unit]);qdev_prop_set_uint64 (DEVICE (tmr),"input-freq" , s->pclk_freq_hz);sysbus_realize (tmr, &error_abort); - irqbase =RX62N_TMR_IRQ +TMR_NR_IRQ * unit; -for (i =0 ; i <TMR_NR_IRQ ; i++) { + irqbase =RX62N_TMR_IRQ +TMU_NR_IRQ * unit; +for (i =0 ; i <TMU_NR_IRQ ; i++) {sysbus_connect_irq (tmr, i, s->irq[irqbase + i]); }sysbus_mmio_map (tmr,0 ,RX62N_TMR_BASE + unit *0x10 );hw/rx/Kconfig +0
-1@@ -1,7 +1,6 @@ config RX62N_MCU bool select RX_ICU - select RENESAS_TMR select RENESAS_TIMER select RENESAS_SCISignature · 1 line
2.31.1
The TMU and TMR are different, so the fix is not intended. TMR is implemented in renesas_tmr.c and has not been integrated yet. The features are also different and cannot be integrated immediately.
Signature · 1 line
Yosinori Sato
PATCH 3/4 hw/timer: Remove RENESAS_TMR / RENESAS_CMT
In reply to Philippe Mathieu-DaudéBoth RENESAS_TMR / RENESAS_CMT have been replaced by the generic RENESAS_TIMER.
--- include/hw/timer/renesas_cmt.h | 43 --- include/hw/timer/renesas_tmr.h | 58 ---- hw/timer/renesas_cmt.c | 283 ------------------- hw/timer/renesas_tmr.c | 493 --------------------------------- hw/timer/Kconfig | 6 - hw/timer/meson.build | 2 - 6 files changed, 885 deletions(-) delete mode 100644 include/hw/timer/renesas_cmt.h delete mode 100644 include/hw/timer/renesas_tmr.h delete mode 100644 hw/timer/renesas_cmt.c delete mode 100644 hw/timer/renesas_tmr.c
include/hw/timer/renesas_cmt.h deleted +0 -43
@@ -1,43 +0,0 @@ -/* -* Renesas Compare-match timer Object -* -* Copyright (c) 2019 Yoshinori Sato -* -* SPDX-License-Identifier: GPL-2.0-or-later -*/ - -#ifndef HW_TIMER_RENESAS_CMT_H -#define HW_TIMER_RENESAS_CMT_H - -#include "qemu/timer.h" -#include "hw/sysbus.h" -#include "qom/object.h" - -#define TYPE_RENESAS_CMT "renesas-cmt" -typedef struct RCMTState RCMTState ; -DECLARE_INSTANCE_CHECKER (RCMTState,RCMT , - TYPE_RENESAS_CMT) - -enum { -CMT_CH =2 , -CMT_NR_IRQ =1 *CMT_CH -}; - -struct RCMTState { -/*< private >*/ -SysBusDevice parent_obj; -/*< public >*/ - -uint64_t input_freq; -MemoryRegion memory; - -uint16_t cmstr; -uint16_t cmcr[CMT_CH ]; -uint16_t cmcnt[CMT_CH ]; -uint16_t cmcor[CMT_CH ]; -int64_t tick[CMT_CH ]; -qemu_irq cmi[CMT_CH ]; -QEMUTimer timer[CMT_CH ]; -}; - -#endif
include/hw/timer/renesas_tmr.h deleted +0 -58
58 lines not on this page · raw message
hw/timer/renesas_cmt.c deleted +0 -283
283 lines not on this page · raw message
hw/timer/renesas_tmr.c deleted +0 -493
493 lines not on this page · raw message
hw/timer/Kconfig +0 -6
@@ -40,12 +40,6 @@ config SH_TIMER bool select PTIMER -config RENESAS_TMR - bool - -config RENESAS_CMT - bool - config RENESAS_TIMER bool select PTIMER
hw/timer/meson.build +0 -2
@@ -8,8 +8,6 @@ softmmu_ss.add(when: 'CONFIG_CADENCE', if_true: files('cadence_ttc.c')) softmmu_ss.add(when: 'CONFIG_CMSDK_APB_DUALTIMER', if_true: files('cmsdk-apb-dualtimer.c')) softmmu_ss.add(when: 'CONFIG_CMSDK_APB_TIMER', if_true: files('cmsdk-apb-timer.c')) -softmmu_ss.add(when: 'CONFIG_RENESAS_TMR', if_true: files('renesas_tmr.c')) -softmmu_ss.add(when: 'CONFIG_RENESAS_CMT', if_true: files('renesas_cmt.c')) softmmu_ss.add(when: 'CONFIG_DIGIC', if_true: files('digic-timer.c')) softmmu_ss.add(when: 'CONFIG_ETRAXFS', if_true: files('etraxfs_timer.c')) softmmu_ss.add(when: 'CONFIG_EXYNOS4', if_true: files('exynos4210_mct.c'))
Signature · 1 line
2.31.1
PATCH 4/4 hw/timer: Remove SH_TIMER
In reply to Philippe Mathieu-DaudéSH_TIMER has been replaced by the generic RENESAS_TIMER.
--- hw/timer/sh_timer.c | 368 ------------------------------------------- MAINTAINERS | 1 - hw/timer/Kconfig | 4 - hw/timer/meson.build | 1 - 4 files changed, 374 deletions(-) delete mode 100644 hw/timer/sh_timer.c
hw/timer/sh_timer.c deleted +0 -368
@@ -1,368 +0,0 @@ -/* -* SuperH Timer modules. -* -* Copyright (c) 2007 Magnus Damm -* Based on arm_timer.c by Paul Brook -* Copyright (c) 2005-2006 CodeSourcery. -* -* This code is licensed under the GPL. -*/ - -#include "qemu/osdep.h" -#include "exec/memory.h" -#include "hw/hw.h" -#include "hw/irq.h" -#include "hw/sh4/sh.h" -#include "hw/timer/tmu012.h" -#include "hw/ptimer.h" - -//#define DEBUG_TIMER - -#define TIMER_TCR_TPSC (7 << 0) -#define TIMER_TCR_CKEG (3 << 3) -#define TIMER_TCR_UNIE (1 << 5) -#define TIMER_TCR_ICPE (3 << 6) -#define TIMER_TCR_UNF (1 << 8) -#define TIMER_TCR_ICPF (1 << 9) -#define TIMER_TCR_RESERVED (0x3f << 10) - -#define TIMER_FEAT_CAPT (1 << 0) -#define TIMER_FEAT_EXTCLK (1 << 1) - -#define OFFSET_TCOR 0 -#define OFFSET_TCNT 1 -#define OFFSET_TCR 2 -#define OFFSET_TCPR 3 - -typedef struct { -ptimer_state *timer; -uint32_t tcnt; -uint32_t tcor; -uint32_t tcr; -uint32_t tcpr; -int freq; -int int_level; -int old_level; -int feat; -int enabled; -qemu_irq irq; -}sh_timer_state ; - -/* Check all active timers, and schedule the next timer interrupt. */ - -static void sh_timer_update (sh_timer_state *s) -{ -int new_level = s->int_level && (s->tcr &TIMER_TCR_UNIE ); - -if (new_level != s->old_level) -qemu_set_irq (s->irq, new_level); - - s->old_level = s->int_level; - s->int_level = new_level; -} - -static uint32_t sh_timer_read (void *opaque,hwaddr offset) -{ -sh_timer_state *s = (sh_timer_state *)opaque; - -switch (offset >>2 ) { -case OFFSET_TCOR : -return s->tcor; -case OFFSET_TCNT : -return ptimer_get_count (s->timer); -case OFFSET_TCR : -return s->tcr | (s->int_level ?TIMER_TCR_UNF :0 ); -case OFFSET_TCPR : -if (s->feat &TIMER_FEAT_CAPT ) -return s->tcpr; -/* fall through */ -default : -hw_error ("sh_timer_read: Bad offset %x\n" , (int )offset); -return 0 ; - } -} - -static void sh_timer_write (void *opaque,hwaddr offset, -uint32_t value) -{ -sh_timer_state *s = (sh_timer_state *)opaque; -int freq; - -switch (offset >>2 ) { -case OFFSET_TCOR : - s->tcor = value; -ptimer_transaction_begin (s->timer); -ptimer_set_limit (s->timer, s->tcor,0 ); -ptimer_transaction_commit (s->timer); -break ; -case OFFSET_TCNT : - s->tcnt = value; -ptimer_transaction_begin (s->timer); -ptimer_set_count (s->timer, s->tcnt); -ptimer_transaction_commit (s->timer); -break ; -case OFFSET_TCR : -ptimer_transaction_begin (s->timer); -if (s->enabled) { -/* Pause the timer if it is running. This may cause some -inaccuracy dure to rounding, but avoids a whole lot of other -messyness. */ -ptimer_stop (s->timer); - } - freq = s->freq; -/* ??? Need to recalculate expiry time after changing divisor. */ -switch (value &TIMER_TCR_TPSC ) { -case 0 : freq >>=2 ;break ; -case 1 : freq >>=4 ;break ; -case 2 : freq >>=6 ;break ; -case 3 : freq >>=8 ;break ; -case 4 : freq >>=10 ;break ; -case 6 : -case 7 : -if (s->feat &TIMER_FEAT_EXTCLK ) { -break ; - } -/* fallthrough */ -default : -hw_error ("sh_timer_write: Reserved TPSC value\n" ); - } -switch ((value &TIMER_TCR_CKEG ) >>3 ) { -case 0 : -break ; -case 1 : -case 2 : -case 3 : -if (s->feat &TIMER_FEAT_EXTCLK ) { -break ; - } -/* fallthrough */ -default : -hw_error ("sh_timer_write: Reserved CKEG value\n" ); - } -switch ((value &TIMER_TCR_ICPE ) >>6 ) { -case 0 : -break ; -case 2 : -case 3 : -if (s->feat &TIMER_FEAT_CAPT ) { -break ; - } -/* fallthrough */ -default : -hw_error ("sh_timer_write: Reserved ICPE value\n" ); - } -if ((value &TIMER_TCR_UNF ) ==0 ) { - s->int_level =0 ; - } - - value &= ~TIMER_TCR_UNF ; - -if ((value &TIMER_TCR_ICPF ) && (!(s->feat &TIMER_FEAT_CAPT ))) { -hw_error ("sh_timer_write: Reserved ICPF value\n" ); - } - - value &= ~TIMER_TCR_ICPF ;/* capture not supported */ - -if (value &TIMER_TCR_RESERVED ) { -hw_error ("sh_timer_write: Reserved TCR bits set\n" ); - } - s->tcr = value; -ptimer_set_limit (s->timer, s->tcor,0 ); -ptimer_set_freq (s->timer, freq); -if (s->enabled) { -/* Restart the timer if still enabled. */ -ptimer_run (s->timer,0 ); - } -ptimer_transaction_commit (s->timer); -break ; -case OFFSET_TCPR : -if (s->feat &TIMER_FEAT_CAPT ) { - s->tcpr = value; -break ; - } -/* fallthrough */ -default : -hw_error ("sh_timer_write: Bad offset %x\n" , (int )offset); - } -sh_timer_update (s); -} - -static void sh_timer_start_stop (void *opaque,int enable) -{ -sh_timer_state *s = (sh_timer_state *)opaque; - -#ifdef DEBUG_TIMER -printf ("sh_timer_start_stop %d (%d)\n" , enable, s->enabled); -#endif - -ptimer_transaction_begin (s->timer); -if (s->enabled && !enable) { -ptimer_stop (s->timer); - } -if (!s->enabled && enable) { -ptimer_run (s->timer,0 ); - } -ptimer_transaction_commit (s->timer); - s->enabled = !!enable; - -#ifdef DEBUG_TIMER -printf ("sh_timer_start_stop done %d\n" , s->enabled); -#endif -} - -static void sh_timer_tick (void *opaque) -{ -sh_timer_state *s = (sh_timer_state *)opaque; - s->int_level = s->enabled; -sh_timer_update (s); -} - -static void *sh_timer_init (uint32_t freq,int feat,qemu_irq irq) -{ -sh_timer_state *s; - - s = (sh_timer_state *)g_malloc0 (sizeof (sh_timer_state)); - s->freq = freq; - s->feat = feat; - s->tcor =0xffffffff ; - s->tcnt =0xffffffff ; - s->tcpr =0xdeadbeef ; - s->tcr =0 ; - s->enabled =0 ; - s->irq = irq; - - s->timer =ptimer_init (sh_timer_tick, s,PTIMER_POLICY_DEFAULT ); - -sh_timer_write (s,OFFSET_TCOR >>2 , s->tcor); -sh_timer_write (s,OFFSET_TCNT >>2 , s->tcnt); -sh_timer_write (s,OFFSET_TCPR >>2 , s->tcpr); -sh_timer_write (s,OFFSET_TCR >>2 , s->tcpr); -/* ??? Save/restore. */ -return s; -} - -typedef struct { -MemoryRegion iomem; -MemoryRegion iomem_p4; -MemoryRegion iomem_a7; -void *timer[3 ]; -int level[3 ]; -uint32_t tocr; -uint32_t tstr; -int feat; -}tmu012_state ; - -static uint64_t tmu012_read (void *opaque,hwaddr offset, -unsigned size) -{ -tmu012_state *s = (tmu012_state *)opaque; - -#ifdef DEBUG_TIMER -printf ("tmu012_read 0x%lx\n" , (unsigned long ) offset); -#endif - -if (offset >=0x20 ) { -if (!(s->feat &TMU012_FEAT_3CHAN )) { -hw_error ("tmu012_write: Bad channel offset %x\n" , (int )offset); - } -return sh_timer_read (s->timer[2 ], offset -0x20 ); - } - -if (offset >=0x14 ) -return sh_timer_read (s->timer[1 ], offset -0x14 ); - -if (offset >=0x08 ) -return sh_timer_read (s->timer[0 ], offset -0x08 ); - -if (offset ==4 ) -return s->tstr; - -if ((s->feat &TMU012_FEAT_TOCR ) && offset ==0 ) -return s->tocr; - -hw_error ("tmu012_write: Bad offset %x\n" , (int )offset); -return 0 ; -} - -static void tmu012_write (void *opaque,hwaddr offset, -uint64_t value,unsigned size) -{ -tmu012_state *s = (tmu012_state *)opaque; - -#ifdef DEBUG_TIMER -printf ("tmu012_write 0x%lx 0x%08x\n" , (unsigned long ) offset, value); -#endif - -if (offset >=0x20 ) { -if (!(s->feat &TMU012_FEAT_3CHAN )) { -hw_error ("tmu012_write: Bad channel offset %x\n" , (int )offset); - } -sh_timer_write (s->timer[2 ], offset -0x20 , value); -return ; - } - -if (offset >=0x14 ) { -sh_timer_write (s->timer[1 ], offset -0x14 , value); -return ; - } - -if (offset >=0x08 ) { -sh_timer_write (s->timer[0 ], offset -0x08 , value); -return ; - } - -if (offset ==4 ) { -sh_timer_start_stop (s->timer[0 ], value & (1 <<0 )); -sh_timer_start_stop (s->timer[1 ], value & (1 <<1 )); -if (s->feat &TMU012_FEAT_3CHAN ) { -sh_timer_start_stop (s->timer[2 ], value & (1 <<2 )); - }else { -if (value & (1 <<2 )) { -hw_error ("tmu012_write: Bad channel\n" ); - } - } - - s->tstr = value; -return ; - } - -if ((s->feat &TMU012_FEAT_TOCR ) && offset ==0 ) { - s->tocr = value & (1 <<0 ); - } -} - -static const MemoryRegionOps tmu012_ops = { - .read = tmu012_read, - .write = tmu012_write, - .endianness =DEVICE_NATIVE_ENDIAN , -}; - -void tmu012_init (MemoryRegion *sysmem,hwaddr base, -int feat,uint32_t freq, -qemu_irq ch0_irq,qemu_irq ch1_irq, -qemu_irq ch2_irq0,qemu_irq ch2_irq1) -{ -tmu012_state *s; -int timer_feat = (feat &TMU012_FEAT_EXTCLK ) ?TIMER_FEAT_EXTCLK :0 ; - - s = (tmu012_state *)g_malloc0 (sizeof (tmu012_state)); - s->feat = feat; - s->timer[0 ] =sh_timer_init (freq, timer_feat, ch0_irq); - s->timer[1 ] =sh_timer_init (freq, timer_feat, ch1_irq); -if (feat &TMU012_FEAT_3CHAN ) { - s->timer[2 ] =sh_timer_init (freq, timer_feat |TIMER_FEAT_CAPT , - ch2_irq0);/* ch2_irq1 not supported */ - } - -memory_region_init_io (&s->iomem,NULL , &tmu012_ops, s, -"timer" ,0x100000000ULL ); - -memory_region_init_alias (&s->iomem_p4,NULL ,"timer-p4" , - &s->iomem,0 ,0x1000 ); -memory_region_add_subregion (sysmem,P4ADDR (base), &s->iomem_p4); - -memory_region_init_alias (&s->iomem_a7,NULL ,"timer-a7" , - &s->iomem,0 ,0x1000 ); -memory_region_add_subregion (sysmem,A7ADDR (base), &s->iomem_a7); -/* ??? Save/restore. */ -}
MAINTAINERS +0 -1
@@ -2188,7 +2188,6 @@ S: Odd Fixes F: hw/char/renesas_sci.c F: hw/char/sh_serial.c F: hw/timer/renesas_*.c -F: hw/timer/sh_timer.c F: include/hw/char/renesas_sci.h F: include/hw/sh4/sh.h F: include/hw/timer/renesas_*.h
hw/timer/Kconfig +0 -4
@@ -36,10 +36,6 @@ config CMSDK_APB_DUALTIMER bool select PTIMER -config SH_TIMER - bool - select PTIMER - config RENESAS_TIMER bool select PTIMER
hw/timer/meson.build +0 -1
@@ -25,7 +25,6 @@ softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_synctimer.c')) softmmu_ss.add(when: 'CONFIG_PXA2XX', if_true: files('pxa2xx_timer.c')) softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_systmr.c')) -softmmu_ss.add(when: 'CONFIG_SH_TIMER', if_true: files('sh_timer.c')) softmmu_ss.add(when: 'CONFIG_SLAVIO', if_true: files('slavio_timer.c')) softmmu_ss.add(when: 'CONFIG_SSE_COUNTER', if_true: files('sse-counter.c')) softmmu_ss.add(when: 'CONFIG_SSE_TIMER', if_true: files('sse-timer.c'))
Signature · 1 line
2.31.1