Add RX hardware emulation
cover Add RX hardware emulation
Hello.
This series add to hardware emulation module for RX target.
Details below.
Interrupt controller, 8bit timer, 16bit comapare match timer and SCI is RX62N integrated peripheral.
rx-virt - RX62N MCU and external RAM. It like gdb simulator.
The compare match timer has a CPU interface similar to the SH4 timer. sh_timer will be deprecated and integrated into this module. SCI is also implemented in sh_serial, but the functionality is omitted. I implemented the complete one as renesas_sci.
git repository here.git://git.pf.osdn.net/gitroot/y/ys/ysato/qemu.git tags/hw-rx-20200601
Yoshinori Sato (10):
hw/intc: RX62N interrupt controller (ICUa)
hw/timer: Renesas 8bit timer module.
hw/timer: Renesas TMU/CMT module.
hw/char: Renesas SCI module.
hw/rx: RX MCU and target
Add rx-softmmu
hw/sh4: Convert renesas_sci.
hw/char: remove sh_serial.c
hw/sh4: Convert to renesas_timer.c
hw/timer: remove sh_timer.c
default-configs/rx-softmmu.mak | 1 + include/hw/char/renesas_sci.h | 77 +++ include/hw/intc/rx_icu.h | 56 +++ include/hw/rx/rx.h | 7 + include/hw/rx/rx62n.h | 91 ++++ include/hw/sh4/sh.h | 21 - include/hw/timer/renesas_8timer.h | 61 +++ include/hw/timer/renesas_timer.h | 59 +++ hw/char/renesas_sci.c | 786 ++++++++++++++++++++++++++++++ hw/char/sh_serial.c | 431 ---------------- hw/intc/rx_icu.c | 379 ++++++++++++++ hw/rx/rx-virt.c | 143 ++++++ hw/rx/rx62n.c | 240 +++++++++ hw/sh4/sh7750.c | 78 ++- hw/timer/renesas_8timer.c | 466 ++++++++++++++++++ hw/timer/renesas_timer.c | 421 ++++++++++++++++ hw/timer/sh_timer.c | 341 ------------- hw/Kconfig | 1 + hw/char/Kconfig | 3 + hw/char/Makefile.objs | 3 +- hw/intc/Makefile.objs | 1 + hw/rx/Kconfig | 13 + hw/rx/Makefile.objs | 2 + hw/sh4/Kconfig | 3 +- hw/timer/Kconfig | 6 + hw/timer/Makefile.objs | 4 +- 26 files changed, 2891 insertions(+), 803 deletions(-) create mode 100644 include/hw/char/renesas_sci.h create mode 100644 include/hw/intc/rx_icu.h create mode 100644 include/hw/rx/rx.h create mode 100644 include/hw/rx/rx62n.h create mode 100644 include/hw/timer/renesas_8timer.h create mode 100644 include/hw/timer/renesas_timer.h create mode 100644 hw/char/renesas_sci.c delete mode 100644 hw/char/sh_serial.c create mode 100644 hw/intc/rx_icu.c create mode 100644 hw/rx/rx-virt.c create mode 100644 hw/rx/rx62n.c create mode 100644 hw/timer/renesas_8timer.c create mode 100644 hw/timer/renesas_timer.c delete mode 100644 hw/timer/sh_timer.c create mode 100644 hw/rx/Kconfig create mode 100644 hw/rx/Makefile.objs
Signature · 1 line
2.20.1
PATCH 9/10 hw/sh4: Convert to renesas_timer.c
Using unified TMU/CMT module.
--- include/hw/sh4/sh.h | 10 --------- hw/sh4/sh7750.c | 47 +++++++++++++++++++++++++++++++++--------- hw/sh4/Kconfig | 2 +- hw/timer/Makefile.objs | 1 - 4 files changed, 38 insertions(+), 22 deletions(-)
include/hw/sh4/sh.h +0 -10
@@ -28,16 +28,6 @@ typedef struct {int sh7750_register_io_device (struct SH7750State *s,sh7750_io_device * device); -/* sh_timer.c */ -#define TMU012_FEAT_TOCR (1 << 0) -#define TMU012_FEAT_3CHAN (1 << 1) -#define TMU012_FEAT_EXTCLK (1 << 2) -void tmu012_init (struct 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); - -/* sh7750.c */ qemu_irq sh7750_irl (struct SH7750State *s);
hw/sh4/sh7750.c +37 -10
77 lines not on this page · raw message
hw/sh4/Kconfig +1 -1
@@ -21,5 +21,5 @@ config SH7750 config SH4 bool - select PTIMER + select RENESAS_TIMER select RENESAS_SCI
hw/timer/Makefile.objs +0 -1
@@ -22,7 +22,6 @@ common-obj-$(CONFIG_EXYNOS4) += exynos4210_pwm.o common-obj-$(CONFIG_OMAP) += omap_gptimer.o common-obj-$(CONFIG_OMAP) += omap_synctimer.o common-obj-$(CONFIG_PXA2XX) += pxa2xx_timer.o -common-obj-$(CONFIG_SH4) += sh_timer.o common-obj-$(CONFIG_DIGIC) += digic-timer.o common-obj-$(CONFIG_MIPS_CPS) += mips_gictimer.o
Signature · 1 line
2.20.1
PATCH 10/10 hw/timer: remove sh_timer.c
In reply to Yoshinori SatoSH4 TMU using new module. This file is obsolute.
--- hw/timer/sh_timer.c | 341 -------------------------------------------- 1 file changed, 341 deletions(-) delete mode 100644 hw/timer/sh_timer.c
hw/timer/sh_timer.c deleted +0 -341
@@ -1,341 +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 "hw/hw.h" -#include "hw/irq.h" -#include "hw/sh4/sh.h" -#include "qemu/timer.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 ; -default :hw_error ("sh_timer_write: Reserved TPSC value\n" );break ; - } -switch ((value &TIMER_TCR_CKEG ) >>3 ) { -case 0 :break ; -case 1 : -case 2 : -case 3 :if (s->feat &TIMER_FEAT_EXTCLK )break ; -default :hw_error ("sh_timer_write: Reserved CKEG value\n" );break ; - } -switch ((value &TIMER_TCR_ICPE ) >>6 ) { -case 0 :break ; -case 2 : -case 3 :if (s->feat &TIMER_FEAT_CAPT )break ; -default :hw_error ("sh_timer_write: Reserved ICPE value\n" );break ; - } -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 ; - } -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. */ -}
Signature · 1 line
2.20.1
PATCH 6/10 Add rx-softmmu
In reply to Yoshinori SatoMessage-Id: <[email protected]>
pick ed65c02993 target/rx: Add RX to SysEmuTarget pick 01372568ae tests: Add rx to machine-none-test.c [PMD: Squashed patches from Richard Henderson modifying
qapi/common.json and tests/machine-none-test.c]
--- default-configs/rx-softmmu.mak | 1 + hw/Kconfig | 1 + 2 files changed, 2 insertions(+)
default-configs/rx-softmmu.mak +1 -0
@@ -1,2 +1,3 @@ # Default configuration for rx-softmmu +CONFIG_RX_VIRT=y
hw/Kconfig +1 -0
@@ -55,6 +55,7 @@ source nios2/Kconfig source openrisc/Kconfig source ppc/Kconfig source riscv/Kconfig +source rx/Kconfig source s390x/Kconfig source sh4/Kconfig source sparc/Kconfig
Signature · 1 line
2.20.1
PATCH 1/10 hw/intc: RX62N interrupt controller (ICUa)
In reply to Yoshinori SatoThis implementation supported only ICUa.
Hardware manual.
https://www.renesas.com/us/en/doc/products/mpumcu/doc/rx_family/r01uh0033ej0140_rx62n.pdf
--- include/hw/intc/rx_icu.h | 56 ++++++ hw/intc/rx_icu.c | 379 +++++++++++++++++++++++++++++++++++++++ hw/intc/Makefile.objs | 1 + 3 files changed, 436 insertions(+) create mode 100644 include/hw/intc/rx_icu.h create mode 100644 hw/intc/rx_icu.c
include/hw/intc/rx_icu.h new file +56 -0
@@ -0,0 +1,56 @@ +#ifndef RX_ICU_H +#define RX_ICU_H + +#include "qemu-common.h" +#include "hw/irq.h" + +enum TRG_MODE { +TRG_LEVEL =0 , +TRG_NEDGE =1 ,/* Falling */ +TRG_PEDGE =2 ,/* Raising */ +TRG_BEDGE =3 ,/* Both */ +}; + +struct IRQSource { +enum TRG_MODE sense; +int level; +}; + +enum { +/* Software interrupt request */ +SWI =27 , +NR_IRQS =256 , +}; + +struct RXICUState { +SysBusDevice parent_obj; + +MemoryRegion memory; +struct IRQSource src[NR_IRQS ]; +char *icutype; +uint32_t nr_irqs; +uint32_t *map; +uint32_t nr_sense; +uint32_t *init_sense; + +uint8_t ir[NR_IRQS ]; +uint8_t dtcer[NR_IRQS ]; +uint8_t ier[NR_IRQS /8 ]; +uint8_t ipr[142 ]; +uint8_t dmasr[4 ]; +uint16_t fir; +uint8_t nmisr; +uint8_t nmier; +uint8_t nmiclr; +uint8_t nmicr; +int req_irq; +qemu_irq _irq; +qemu_irq _fir; +qemu_irq _swi; +}; +typedef struct RXICUState RXICUState ; + +#define TYPE_RXICU "rx-icu" +#define RXICU (obj) OBJECT_CHECK(RXICUState, (obj), TYPE_RXICU) + +#endif /* RX_ICU_H */
hw/intc/rx_icu.c new file +379 -0
379 lines not on this page · raw message
hw/intc/Makefile.objs +1 -0
@@ -49,3 +49,4 @@ obj-$(CONFIG_ARM_GIC) += arm_gicv3_cpuif.o obj-$(CONFIG_MIPS_CPS) += mips_gic.o obj-$(CONFIG_NIOS2) += nios2_iic.o obj-$(CONFIG_OMPIC) += ompic.o +obj-$(CONFIG_RX) += rx_icu.o
Signature · 1 line
2.20.1
PATCH 7/10 hw/sh4: Convert renesas_sci.
In reply to Yoshinori SatoUsing new implementation SCI module.
--- include/hw/sh4/sh.h | 11 ----------- hw/sh4/sh7750.c | 45 +++++++++++++++++++++++++++++++++++++++++---- hw/sh4/Kconfig | 1 + 3 files changed, 42 insertions(+), 15 deletions(-)
include/hw/sh4/sh.h +0 -11
@@ -38,17 +38,6 @@ void tmu012_init(struct MemoryRegion *sysmem, hwaddr base, qemu_irq ch2_irq0, qemu_irq ch2_irq1); -/* sh_serial.c */ -#define SH_SERIAL_FEAT_SCIF (1 << 0) -void sh_serial_init (MemoryRegion *sysmem, -hwaddr base,int feat, -uint32_t freq,Chardev *chr, -qemu_irq eri_source, -qemu_irq rxi_source, -qemu_irq txi_source, -qemu_irq tei_source, -qemu_irq bri_source); -/* sh7750.c */ qemu_irq sh7750_irl (struct SH7750State *s);
hw/sh4/sh7750.c +41 -4
74 lines not on this page · raw message
hw/sh4/Kconfig +1 -0
@@ -22,3 +22,4 @@ config SH7750 config SH4 bool select PTIMER + select RENESAS_SCI
Signature · 1 line
2.20.1
PATCH 3/10 hw/timer: Renesas TMU/CMT module.
In reply to Yoshinori SatoTMU - SH4 Timer module.
CMT - Compare and match timer used by some Renesas MCUs.
The two modules have similar interfaces and have been merged.
--- include/hw/timer/renesas_timer.h | 59 +++++ hw/timer/renesas_timer.c | 421 +++++++++++++++++++++++++++++++ hw/timer/Kconfig | 3 + hw/timer/Makefile.objs | 1 + 4 files changed, 484 insertions(+) create mode 100644 include/hw/timer/renesas_timer.h create mode 100644 hw/timer/renesas_timer.c
include/hw/timer/renesas_timer.h new file +59 -0
@@ -0,0 +1,59 @@ +/* +* Renesas Timer unit Object +* +* Copyright (c) 2020 Yoshinori Sato +* +* This code is licensed under the GPL version 2 or later. +* +*/ + +#ifndef HW_RENESAS_TIMER_H +#define HW_RENESAS_TIMER_H + +#include "hw/sysbus.h" + +#define TYPE_RENESAS_TIMER "renesas-timer" +#define RTIMER (obj) OBJECT_CHECK(RTIMERState, (obj), TYPE_RENESAS_TIMER) + +enum { +TIMER_CH_CMT =2 , +/* TMU have 5channels. It separated 0-2 and 3-4. */ +TIMER_CH_TMU =3 , +}; + +enum { +RTIMER_FEAT_CMT , +RTIMER_FEAT_TMU_LOW , +RTIMER_FEAT_TMU_HIGH , +}; + +struct RTIMERState ; + +struct channel_rtimer { +uint32_t cnt; +uint32_t cor; +uint16_t ctrl; +qemu_irq irq; +int64_t base; +int64_t next; +uint64_t clk; +bool start; +QEMUTimer *timer; +struct RTIMERState *tmrp; +}; + +typedef struct RTIMERState { +SysBusDevice parent_obj; + +uint64_t input_freq; +MemoryRegion memory; +MemoryRegion memory_p4; +MemoryRegion memory_a7; + +uint8_t tocr; +struct channel_rtimer ch[TIMER_CH_TMU ]; +uint32_t feature; +int num_ch; +}RTIMERState ; + +#endif
hw/timer/renesas_timer.c new file +421 -0
421 lines not on this page · raw message
hw/timer/Kconfig +3 -0
@@ -38,3 +38,6 @@ config CMSDK_APB_DUALTIMER config RENESAS_8TMR bool + +config RENESAS_TIMER + bool
hw/timer/Makefile.objs +1 -0
@@ -37,3 +37,4 @@ common-obj-$(CONFIG_MSF2) += mss-timer.o common-obj-$(CONFIG_RASPI) += bcm2835_systmr.o common-obj-$(CONFIG_RENESAS_8TMR) += renesas_8timer.o +common-obj-$(CONFIG_RENESAS_TIMER) += renesas_timer.o
Signature · 1 line
2.20.1
PATCH 2/10 hw/timer: Renesas 8bit timer module.
In reply to Yoshinori Sato8bit or 16bit timer.
This implementation support only internal clock mode.
Hardware manual.
https://www.renesas.com/us/en/doc/products/mpumcu/doc/rx_family/r01uh0033ej0140_rx62n.pdf
--- include/hw/timer/renesas_8timer.h | 61 ++++ hw/timer/renesas_8timer.c | 466 ++++++++++++++++++++++++++++++ hw/timer/Kconfig | 3 + hw/timer/Makefile.objs | 2 + 4 files changed, 532 insertions(+) create mode 100644 include/hw/timer/renesas_8timer.h create mode 100644 hw/timer/renesas_8timer.c
include/hw/timer/renesas_8timer.h new file +61 -0
@@ -0,0 +1,61 @@ +/* +* Renesas 8bit timer Object +* +* Copyright (c) 2018 Yoshinori Sato +* +* This code is licensed under the GPL version 2 or later. +* +*/ + +#ifndef HW_RENESAS_TMR_H +#define HW_RENESAS_TMR_H + +#include "hw/sysbus.h" + +#define TYPE_RENESAS_8TMR "renesas-8tmr" +#define RTMR (obj) OBJECT_CHECK(RTMRState, (obj), TYPE_RENESAS_8TMR) + +enum timer_event { + cmia, cmib, ovi, wovi, +TMR_NR_EVENTS , +}; + +enum { +TMR_CH =2 , +TMR_NR_COR =2 , +TMR_NR_IRQ =3 , +}; + +enum { +IRQ_CMIA ,IRQ_CMIB ,IRQ_OVI , +}; + +struct RTMRState ; + +struct channel_8tmr { +uint16_t cnt; +uint16_t cor[TMR_NR_COR ]; +uint8_t tcr; +uint8_t tccr; +uint8_t tcsr; +qemu_irq irq[TMR_NR_IRQ ]; +QEMUTimer *timer; +int64_t base; +int64_t next; +int64_t clk; +enum timer_event event; +int id; +struct RTMRState *tmrp; +bool word; +}; + +typedef struct RTMRState { +SysBusDevice parent_obj; + +uint64_t input_freq; +MemoryRegion memory; + +struct channel_8tmr ch[TMR_CH ]; +}RTMRState ; + +#endif
hw/timer/renesas_8timer.c new file +466 -0
466 lines not on this page · raw message
hw/timer/Kconfig +3 -0
@@ -35,3 +35,6 @@ config CMSDK_APB_TIMER config CMSDK_APB_DUALTIMER bool select PTIMER + +config RENESAS_8TMR + bool
hw/timer/Makefile.objs +2 -0
@@ -35,3 +35,5 @@ common-obj-$(CONFIG_CMSDK_APB_TIMER) += cmsdk-apb-timer.o common-obj-$(CONFIG_CMSDK_APB_DUALTIMER) += cmsdk-apb-dualtimer.o common-obj-$(CONFIG_MSF2) += mss-timer.o common-obj-$(CONFIG_RASPI) += bcm2835_systmr.o + +common-obj-$(CONFIG_RENESAS_8TMR) += renesas_8timer.o
Signature · 1 line
2.20.1
PATCH 5/10 hw/rx: RX MCU and target
In reply to Yoshinori Satorx62n - RX62N MCU.
rx-virt - RX QEMU virtual target.
This has the same specifications as the gdb simulator.
--- include/hw/rx/rx.h | 7 ++ include/hw/rx/rx62n.h | 91 ++++++++++++++++ hw/rx/rx-virt.c | 143 +++++++++++++++++++++++++ hw/rx/rx62n.c | 240 ++++++++++++++++++++++++++++++++++++++++++ hw/rx/Kconfig | 13 +++ hw/rx/Makefile.objs | 2 + 6 files changed, 496 insertions(+) create mode 100644 include/hw/rx/rx.h create mode 100644 include/hw/rx/rx62n.h create mode 100644 hw/rx/rx-virt.c create mode 100644 hw/rx/rx62n.c create mode 100644 hw/rx/Kconfig create mode 100644 hw/rx/Makefile.objs
include/hw/rx/rx.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef QEMU_RX_H +#define QEMU_RX_H +/* Definitions for RX board emulation. */ + +#include "target/rx/cpu-qom.h" + +#endif
include/hw/rx/rx62n.h new file +91 -0
91 lines not on this page · raw message
hw/rx/rx-virt.c new file +143 -0
143 lines not on this page · raw message
hw/rx/rx62n.c new file +240 -0
240 lines not on this page · raw message
hw/rx/Kconfig new file +13 -0
@@ -0,0 +1,13 @@ +config RX + bool + +config RX62N + bool + select RX + select RENESAS_8TMR + select RENESAS_TIMER + select RENESAS_SCI + +config RX_VIRT + bool + select RX62N
hw/rx/Makefile.objs new file +2 -0
@@ -0,0 +1,2 @@ +obj-$(CONFIG_RX62N) += rx62n.o +obj-$(CONFIG_RX_VIRT) += rx-virt.o
Signature · 1 line
2.20.1
PATCH 8/10 hw/char: remove sh_serial.c
In reply to Yoshinori SatoSH4 SCI module convert to renesas_sci.c.
This file is obsolute.
--- hw/char/sh_serial.c | 431 -------------------------------------------- 1 file changed, 431 deletions(-) delete mode 100644 hw/char/sh_serial.c
hw/char/sh_serial.c deleted +0 -431
@@ -1,431 +0,0 @@ -/* -* QEMU SCI/SCIF serial port emulation -* -* Copyright (c) 2007 Magnus Damm -* -* Based on serial.c - QEMU 16450 UART emulation -* Copyright (c) 2003-2004 Fabrice Bellard -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -*/ - -#include "qemu/osdep.h" -#include "hw/irq.h" -#include "hw/sh4/sh.h" -#include "chardev/char-fe.h" -#include "qapi/error.h" -#include "qemu/timer.h" - -//#define DEBUG_SERIAL - -#define SH_SERIAL_FLAG_TEND (1 << 0) -#define SH_SERIAL_FLAG_TDE (1 << 1) -#define SH_SERIAL_FLAG_RDF (1 << 2) -#define SH_SERIAL_FLAG_BRK (1 << 3) -#define SH_SERIAL_FLAG_DR (1 << 4) - -#define SH_RX_FIFO_LENGTH (16) - -typedef struct { -MemoryRegion iomem; -MemoryRegion iomem_p4; -MemoryRegion iomem_a7; -uint8_t smr; -uint8_t brr; -uint8_t scr; -uint8_t dr;/* ftdr / tdr */ -uint8_t sr;/* fsr / ssr */ -uint16_t fcr; -uint8_t sptr; - -uint8_t rx_fifo[SH_RX_FIFO_LENGTH ];/* frdr / rdr */ -uint8_t rx_cnt; -uint8_t rx_tail; -uint8_t rx_head; - -int freq; -int feat; -int flags; -int rtrg; - -CharBackend chr; -QEMUTimer *fifo_timeout_timer; -uint64_t etu;/* Elementary Time Unit (ns) */ - -qemu_irq eri; -qemu_irq rxi; -qemu_irq txi; -qemu_irq tei; -qemu_irq bri; -}sh_serial_state ; - -static void sh_serial_clear_fifo (sh_serial_state * s) -{ -memset (s->rx_fifo,0 ,SH_RX_FIFO_LENGTH ); - s->rx_cnt =0 ; - s->rx_head =0 ; - s->rx_tail =0 ; -} - -static void sh_serial_write (void *opaque,hwaddr offs, -uint64_t val,unsigned size) -{ -sh_serial_state *s = opaque; -unsigned char ch; - -#ifdef DEBUG_SERIAL -printf ("sh_serial: write offs=0x%02x val=0x%02x\n" , - offs, val); -#endif -switch (offs) { -case 0x00 :/* SMR */ - s->smr = val & ((s->feat &SH_SERIAL_FEAT_SCIF ) ?0x7b :0xff ); -return ; -case 0x04 :/* BRR */ - s->brr = val; -return ; -case 0x08 :/* SCR */ -/* TODO : For SH7751, SCIF mask should be 0xfb. */ - s->scr = val & ((s->feat &SH_SERIAL_FEAT_SCIF ) ?0xfa :0xff ); -if (!(val & (1 <<5 ))) - s->flags |=SH_SERIAL_FLAG_TEND ; -if ((s->feat &SH_SERIAL_FEAT_SCIF ) && s->txi) { -qemu_set_irq (s->txi, val & (1 <<7 )); - } -if (!(val & (1 <<6 ))) { -qemu_set_irq (s->rxi,0 ); - } -return ; -case 0x0c :/* FTDR / TDR */ -if (qemu_chr_fe_backend_connected (&s->chr)) { - ch = val; -/* XXX this blocks entire thread. Rewrite to use -* qemu_chr_fe_write and background I/O callbacks */ -qemu_chr_fe_write_all (&s->chr, &ch,1 ); - } - s->dr = val; - s->flags &= ~SH_SERIAL_FLAG_TDE ; -return ; -#if 0 -case 0x14 :/* FRDR / RDR */ - ret =0 ; -break ; -#endif - } -if (s->feat &SH_SERIAL_FEAT_SCIF ) { -switch (offs) { -case 0x10 :/* FSR */ -if (!(val & (1 <<6 ))) - s->flags &= ~SH_SERIAL_FLAG_TEND ; -if (!(val & (1 <<5 ))) - s->flags &= ~SH_SERIAL_FLAG_TDE ; -if (!(val & (1 <<4 ))) - s->flags &= ~SH_SERIAL_FLAG_BRK ; -if (!(val & (1 <<1 ))) - s->flags &= ~SH_SERIAL_FLAG_RDF ; -if (!(val & (1 <<0 ))) - s->flags &= ~SH_SERIAL_FLAG_DR ; - -if (!(val & (1 <<1 )) || !(val & (1 <<0 ))) { -if (s->rxi) { -qemu_set_irq (s->rxi,0 ); - } - } -return ; -case 0x18 :/* FCR */ - s->fcr = val; -switch ((val >>6 ) &3 ) { -case 0 : - s->rtrg =1 ; -break ; -case 1 : - s->rtrg =4 ; -break ; -case 2 : - s->rtrg =8 ; -break ; -case 3 : - s->rtrg =14 ; -break ; - } -if (val & (1 <<1 )) { -sh_serial_clear_fifo (s); - s->sr &= ~(1 <<1 ); - } - -return ; -case 0x20 :/* SPTR */ - s->sptr = val &0xf3 ; -return ; -case 0x24 :/* LSR */ -return ; - } - } -else { -switch (offs) { -#if 0 -case 0x0c : - ret = s->dr; -break ; -case 0x10 : - ret =0 ; -break ; -#endif -case 0x1c : - s->sptr = val &0x8f ; -return ; - } - } - -fprintf (stderr,"sh_serial: unsupported write to 0x%02" - HWADDR_PRIx"\n" , offs); -abort (); -} - -static uint64_t sh_serial_read (void *opaque,hwaddr offs, -unsigned size) -{ -sh_serial_state *s = opaque; -uint32_t ret = ~0 ; - -#if 0 -switch (offs) { -case 0x00 : - ret = s->smr; -break ; -case 0x04 : - ret = s->brr; -break ; -case 0x08 : - ret = s->scr; -break ; -case 0x14 : - ret =0 ; -break ; - } -#endif -if (s->feat &SH_SERIAL_FEAT_SCIF ) { -switch (offs) { -case 0x00 :/* SMR */ - ret = s->smr; -break ; -case 0x08 :/* SCR */ - ret = s->scr; -break ; -case 0x10 :/* FSR */ - ret =0 ; -if (s->flags &SH_SERIAL_FLAG_TEND ) - ret |= (1 <<6 ); -if (s->flags &SH_SERIAL_FLAG_TDE ) - ret |= (1 <<5 ); -if (s->flags &SH_SERIAL_FLAG_BRK ) - ret |= (1 <<4 ); -if (s->flags &SH_SERIAL_FLAG_RDF ) - ret |= (1 <<1 ); -if (s->flags &SH_SERIAL_FLAG_DR ) - ret |= (1 <<0 ); - -if (s->scr & (1 <<5 )) - s->flags |=SH_SERIAL_FLAG_TDE |SH_SERIAL_FLAG_TEND ; - -break ; -case 0x14 : -if (s->rx_cnt >0 ) { - ret = s->rx_fifo[s->rx_tail++]; - s->rx_cnt--; -if (s->rx_tail ==SH_RX_FIFO_LENGTH ) - s->rx_tail =0 ; -if (s->rx_cnt < s->rtrg) - s->flags &= ~SH_SERIAL_FLAG_RDF ; - } -break ; -case 0x18 : - ret = s->fcr; -break ; -case 0x1c : - ret = s->rx_cnt; -break ; -case 0x20 : - ret = s->sptr; -break ; -case 0x24 : - ret =0 ; -break ; - } - } -else { -switch (offs) { -#if 0 -case 0x0c : - ret = s->dr; -break ; -case 0x10 : - ret =0 ; -break ; -case 0x14 : - ret = s->rx_fifo[0 ]; -break ; -#endif -case 0x1c : - ret = s->sptr; -break ; - } - } -#ifdef DEBUG_SERIAL -printf ("sh_serial: read offs=0x%02x val=0x%x\n" , - offs, ret); -#endif - -if (ret & ~((1 <<16 ) -1 )) { -fprintf (stderr,"sh_serial: unsupported read from 0x%02" - HWADDR_PRIx"\n" , offs); -abort (); - } - -return ret; -} - -static int sh_serial_can_receive (sh_serial_state *s) -{ -return s->scr & (1 <<4 ); -} - -static void sh_serial_receive_break (sh_serial_state *s) -{ -if (s->feat &SH_SERIAL_FEAT_SCIF ) - s->sr |= (1 <<4 ); -} - -static int sh_serial_can_receive1 (void *opaque) -{ -sh_serial_state *s = opaque; -return sh_serial_can_receive (s); -} - -static void sh_serial_timeout_int (void *opaque) -{ -sh_serial_state *s = opaque; - - s->flags |=SH_SERIAL_FLAG_RDF ; -if (s->scr & (1 <<6 ) && s->rxi) { -qemu_set_irq (s->rxi,1 ); - } -} - -static void sh_serial_receive1 (void *opaque,const uint8_t *buf,int size) -{ -sh_serial_state *s = opaque; - -if (s->feat &SH_SERIAL_FEAT_SCIF ) { -int i; -for (i =0 ; i < size; i++) { -if (s->rx_cnt <SH_RX_FIFO_LENGTH ) { - s->rx_fifo[s->rx_head++] = buf[i]; -if (s->rx_head ==SH_RX_FIFO_LENGTH ) { - s->rx_head =0 ; - } - s->rx_cnt++; -if (s->rx_cnt >= s->rtrg) { - s->flags |=SH_SERIAL_FLAG_RDF ; -if (s->scr & (1 <<6 ) && s->rxi) { -timer_del (s->fifo_timeout_timer); -qemu_set_irq (s->rxi,1 ); - } - }else { -timer_mod (s->fifo_timeout_timer, -qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +15 * s->etu); - } - } - } - }else { - s->rx_fifo[0 ] = buf[0 ]; - } -} - -static void sh_serial_event (void *opaque,QEMUChrEvent event) -{ -sh_serial_state *s = opaque; -if (event ==CHR_EVENT_BREAK ) -sh_serial_receive_break (s); -} - -static const MemoryRegionOps sh_serial_ops = { - .read = sh_serial_read, - .write = sh_serial_write, - .endianness =DEVICE_NATIVE_ENDIAN , -}; - -void sh_serial_init (MemoryRegion *sysmem, -hwaddr base,int feat, -uint32_t freq,Chardev *chr, -qemu_irq eri_source, -qemu_irq rxi_source, -qemu_irq txi_source, -qemu_irq tei_source, -qemu_irq bri_source) -{ -sh_serial_state *s; - - s =g_malloc0 (sizeof (sh_serial_state)); - - s->feat = feat; - s->flags =SH_SERIAL_FLAG_TEND |SH_SERIAL_FLAG_TDE ; - s->rtrg =1 ; - - s->smr =0 ; - s->brr =0xff ; - s->scr =1 <<5 ;/* pretend that TX is enabled so early printk works */ - s->sptr =0 ; - -if (feat &SH_SERIAL_FEAT_SCIF ) { - s->fcr =0 ; - } -else { - s->dr =0xff ; - } - -sh_serial_clear_fifo (s); - -memory_region_init_io (&s->iomem,NULL , &sh_serial_ops, s, -"serial" ,0x100000000ULL ); - -memory_region_init_alias (&s->iomem_p4,NULL ,"serial-p4" , &s->iomem, -0 ,0x28 ); -memory_region_add_subregion (sysmem,P4ADDR (base), &s->iomem_p4); - -memory_region_init_alias (&s->iomem_a7,NULL ,"serial-a7" , &s->iomem, -0 ,0x28 ); -memory_region_add_subregion (sysmem,A7ADDR (base), &s->iomem_a7); - -if (chr) { -qemu_chr_fe_init (&s->chr, chr, &error_abort); -qemu_chr_fe_set_handlers (&s->chr, sh_serial_can_receive1, - sh_serial_receive1, - sh_serial_event,NULL , s,NULL , true); - } - - s->fifo_timeout_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , - sh_serial_timeout_int, s); - s->etu =NANOSECONDS_PER_SECOND /9600 ; - s->eri = eri_source; - s->rxi = rxi_source; - s->txi = txi_source; - s->tei = tei_source; - s->bri = bri_source; -}
Signature · 1 line
2.20.1
PATCH 4/10 hw/char: Renesas SCI module.
In reply to Yoshinori SatoThis module supported SCI / SCIa / SCIF.
Hardware manual.
SCI / SCIF
https://www.renesas.com/us/en/doc/products/mpumcu/001/r01uh0457ej0401_sh7751.pdf
SCIa
https://www.renesas.com/us/en/doc/products/mpumcu/doc/rx_family/r01uh0033ej0140_rx62n.pdf
--- include/hw/char/renesas_sci.h | 77 ++++ hw/char/renesas_sci.c | 786 ++++++++++++++++++++++++++++++++++ hw/char/Kconfig | 3 + hw/char/Makefile.objs | 3 +- 4 files changed, 868 insertions(+), 1 deletion(-) create mode 100644 include/hw/char/renesas_sci.h create mode 100644 hw/char/renesas_sci.c
include/hw/char/renesas_sci.h new file +77 -0
@@ -0,0 +1,77 @@ +/* +* Renesas Serial Communication Interface +* +* Copyright (c) 2020 Yoshinori Sato +* +* This code is licensed under the GPL version 2 or later. +* +*/ + +#include "chardev/char-fe.h" +#include "qemu/timer.h" +#include "qemu/fifo8.h" +#include "hw/sysbus.h" + +#define TYPE_RENESAS_SCI "renesas-sci" +#define RSCI (obj) OBJECT_CHECK(RSCIState, (obj), TYPE_RENESAS_SCI) + +enum { +ERI =0 , +RXI =1 , +TXI =2 , +TEI =3 , +BRI =3 , +SCI_NR_IRQ =4 , +}; + +enum { +SCI_FEAT_SCI =0x00 , +SCI_FEAT_SCIA =0x01 , +SCI_FEAT_SCIF =0x10 , +}; + +enum { +RXTOUT , +RXNEXT , +TXEMPTY , +TXEND , +NR_SCI_EVENT , +}; + +typedef struct RSCIState { +SysBusDevice parent_obj; +MemoryRegion memory; +MemoryRegion memory_p4; +MemoryRegion memory_a7; + +/* SCI register */ +uint8_t smr; +uint8_t brr; +uint8_t scr; +uint8_t tdr; +uint16_t Xsr; +uint8_t scmr; +uint8_t semr; +uint16_t fcr; +uint16_t sptr; +uint16_t lsr; + +/* internal use */ +uint16_t read_Xsr; +uint16_t read_lsr; +int64_t etu; +int64_t trtime; +int64_t tx_start_time; +int tdcnt; +int regsize; +struct { +int64_t time; +int64_t (*handler)(struct RSCIState *sci); + } event[NR_SCI_EVENT ]; +QEMUTimer *event_timer; +CharBackend chr; +uint64_t input_freq; +int feature; +qemu_irq irq[SCI_NR_IRQ ]; +Fifo8 rxfifo; +}RSCIState ;
hw/char/renesas_sci.c new file +786 -0
786 lines not on this page · raw message
hw/char/Kconfig +3 -0
@@ -46,3 +46,6 @@ config SCLPCONSOLE config TERMINAL3270 bool + +config RENESAS_SCI + bool
hw/char/Makefile.objs +2 -1
@@ -16,7 +16,6 @@ common-obj-$(CONFIG_CADENCE) += cadence_uart.o common-obj-$(CONFIG_EXYNOS4) += exynos4210_uart.o common-obj-$(CONFIG_COLDFIRE) += mcf_uart.o common-obj-$(CONFIG_OMAP) += omap_uart.o -common-obj-$(CONFIG_SH4) += sh_serial.o common-obj-$(CONFIG_DIGIC) += digic-uart.o common-obj-$(CONFIG_STM32F2XX_USART) += stm32f2xx_usart.o common-obj-$(CONFIG_RASPI) += bcm2835_aux.o
@@ -31,6 +30,8 @@ common-obj-$(CONFIG_LM32) += lm32_uart.o common-obj-$(CONFIG_MILKYMIST) += milkymist-uart.o common-obj-$(CONFIG_SCLPCONSOLE) += sclpconsole.o sclpconsole-lm.o +common-obj-$(CONFIG_RENESAS_SCI) += renesas_sci.o + obj-$(CONFIG_VIRTIO) += virtio-serial-bus.o obj-$(CONFIG_PSERIES) += spapr_vty.o obj-$(CONFIG_TERMINAL3270) += terminal3270.o
Signature · 1 line
2.20.1
Quoted 9 lines · Yoshinori Sato
Hello.
This series add to hardware emulation module for RX target.
Details below.
Interrupt controller, 8bit timer, 16bit comapare match timer and SCI is RX62N integrated peripheral.
rx-virt - RX62N MCU and external RAM. It like gdb simulator.
Quoted 7 lines
The compare match timer has a CPU interface similar to the SH4 timer.
sh_timerwill be deprecated and integrated into this module. SCI is also implemented insh_serial, but the functionality is omitted. I implemented the complete one asrenesas_sci.git repository here.
git://git.pf.osdn.net/gitroot/y/ys/ysato/qemu.gittags/hw-rx-20200601
Sigh. It is a bit unfortunate and demotivating that we can not coordinate this. I was going to send a pre-merge for this today.
What is positive is you unified some SH4/RX peripherals.
I'll try to merge both series. If it takes too long, I might send my current queue for you to review, then go back to this one you just sent.
Regards,
Phil.
Quoted 22 lines · Philippe Mathieu-Daudé
Quoted 9 lines · Yoshinori Sato
Hello.
This series add to hardware emulation module for RX target.
Details below.
Interrupt controller, 8bit timer, 16bit comapare match timer and SCI is RX62N integrated peripheral.
rx-virt - RX62N MCU and external RAM. It like gdb simulator.Quoted 7 lines
The compare match timer has a CPU interface similar to the SH4 timer.
sh_timerwill be deprecated and integrated into this module. SCI is also implemented insh_serial, but the functionality is omitted. I implemented the complete one asrenesas_sci.git repository here.
git://git.pf.osdn.net/gitroot/y/ys/ysato/qemu.gittags/hw-rx-20200601Sigh. It is a bit unfortunate and demotivating that we can not coordinate this. I was going to send a pre-merge for this today.
Quoted 9 lines
What is positive is you unified some SH4/RX peripherals.
I'll try to merge both series. If it takes too long, I might send my current queue for you to review, then go back to this one you just sent.
Regards,
Phil.
Oh. Sorry.
The old code had some spec differences.
I have fixed those mistakes here.
I would like to merge this if possible.
Signature · 1 line
Yosinori Sato
Hi Yoshinori,
Quoted 31 lines · Yoshinori Sato
Quoted 29 lines · Philippe Mathieu-Daudé
Quoted 9 lines · Yoshinori Sato
Hello.
This series add to hardware emulation module for RX target.
Details below.
Interrupt controller, 8bit timer, 16bit comapare match timer and SCI is RX62N integrated peripheral.
rx-virt - RX62N MCU and external RAM. It like gdb simulator.Quoted 7 lines
The compare match timer has a CPU interface similar to the SH4 timer.
sh_timerwill be deprecated and integrated into this module. SCI is also implemented insh_serial, but the functionality is omitted. I implemented the complete one asrenesas_sci.git repository here.
git://git.pf.osdn.net/gitroot/y/ys/ysato/qemu.gittags/hw-rx-20200601Sigh. It is a bit unfortunate and demotivating that we can not coordinate this. I was going to send a pre-merge for this today.
What is positive is you unified some SH4/RX peripherals.
I'll try to merge both series. If it takes too long, I might send my current queue for you to review, then go back to this one you just sent.
Regards,
Quoted 7 lines
Quoted 2 lines
Phil.
Oh. Sorry.
The old code had some spec differences.
I have fixed those mistakes here.
Yes, I am glad to see how it evolved, in particular how you merged the SH4/RX common peripherals :)
Quoted 2 lines
I would like to merge this if possible.
I posted the v33 of your v32:
https://www.mail-archive.com/[email protected]/msg708317.html
As it is mostly reviewed and tested, it seems more reasonable to merge what is reviewed, and then apply your latest patches on top. It took us already a long time to get there, and I'd not start again to review 30 more times this version.
I believe if would be easier this way, you review/ack the v33 and we get the peripheral cleanup on top. My 2 cents, feel free to disagree and insist on restarting the whole review process.
Regards,
Phil.
Re: [PATCH 01/10] hw/intc: RX62N interrupt controller (ICUa)
In reply to Yoshinori SatoQuoted 4 lines · Yoshinori Sato
This implementation supported only ICUa.
Hardware manual.
https://www.renesas.com/us/en/doc/products/mpumcu/doc/rx_family/r01uh0033ej0140_rx62n.pdf
Quoted 8 lines
Signed-off-by Yoshinori Sato <[email protected]>--- include/hw/intc/rx_icu.h | 56 ++++++ hw/intc/rx_icu.c | 379 +++++++++++++++++++++++++++++++++++++++ hw/intc/Makefile.objs | 1 + 3 files changed, 436 insertions(+) create mode 100644 include/hw/intc/rx_icu.h create mode 100644 hw/intc/rx_icu.c
Good news, no logical change with the version I sent:
https://www.mail-archive.com/[email protected]/msg708323.html
Re: [PATCH 05/10] hw/rx: RX MCU and target
In reply to Yoshinori SatoQuoted 20 lines · Yoshinori Sato
rx62n - RX62N MCU.
rx-virt - RX QEMU virtual target.
This has the same specifications as the gdb simulator.Signed-off-by Yoshinori Sato <[email protected]>--- include/hw/rx/rx.h | 7 ++ include/hw/rx/rx62n.h | 91 ++++++++++++++++ hw/rx/rx-virt.c | 143 +++++++++++++++++++++++++ hw/rx/rx62n.c | 240 ++++++++++++++++++++++++++++++++++++++++++ hw/rx/Kconfig | 13 +++ hw/rx/Makefile.objs | 2 + 6 files changed, 496 insertions(+) create mode 100644 include/hw/rx/rx.h create mode 100644 include/hw/rx/rx62n.h create mode 100644 hw/rx/rx-virt.c create mode 100644 hw/rx/rx62n.c create mode 100644 hw/rx/Kconfig create mode 100644 hw/rx/Makefile.objs
[...]
Quoted 22 lines
hw/rx/rx62n.c new file +22
-0+static void register_tmr (RX62NState *s,int unit) +{ +SysBusDevice *tmr; +int i, irqbase; + +object_initialize_child (OBJECT (s),"tmr[*]" , &s->tmr[unit], +sizeof (RTMRState),TYPE_RENESAS_8TMR , + &error_abort,NULL ); + + tmr =SYS_BUS_DEVICE (&s->tmr[unit]); +qdev_prop_set_uint64 (DEVICE (tmr),"input-freq" ,RX62N_PCLK ); + +qdev_init_nofail (DEVICE (tmr)); +sysbus_mmio_map (tmr,0 ,RX62N_TMRBASE + unit *0x10 ); + irqbase =RX62N_TMR_IRQBASE +TMR_NR_IRQ * unit; +for (i =0 ; i <TMR_NR_IRQ ; i++) { +sysbus_connect_irq (tmr, i, s->irq[irqbase + i]); + } +} + +static void register_cmt (RX62NState *s,int unit) +{
hw/rx/rx62n.c line 152
Quoted 10 lines
hw/rx/rx62n.c new file +10
-0+SysBusDevice *cmt; +int i, irqbase; + +object_initialize_child (OBJECT (s),"cmt[*]" , &s->cmt[unit], +sizeof (RTIMERState),TYPE_RENESAS_TIMER , + &error_abort,NULL ); + + cmt =SYS_BUS_DEVICE (&s->cmt[unit]); +qdev_prop_set_uint64 (DEVICE (cmt),"input-freq" ,RX62N_PCLK ); +qdev_prop_set_int32 (DEVICE (cmt),"feature" ,RTIMER_FEAT_CMT );
OK, single logical change, no problem.
Quoted 29 lines
hw/rx/rx62n.c new file +29
-0+qdev_init_nofail (DEVICE (cmt)); +sysbus_mmio_map (cmt,0 ,RX62N_CMTBASE + unit *0x10 ); + irqbase =RX62N_CMT_IRQBASE +TIMER_CH_CMT * unit; +for (i =0 ; i <TIMER_CH_CMT ; i++) { +sysbus_connect_irq (cmt, i, s->irq[irqbase + i]); + } +} + +static void register_sci (RX62NState *s,int unit) +{ +SysBusDevice *sci; +int i, irqbase; + +object_initialize_child (OBJECT (s),"sci[*]" , &s->sci[unit], +sizeof (RSCIState),TYPE_RENESAS_SCI , + &error_abort,NULL ); + sci =SYS_BUS_DEVICE (&s->sci[unit]); + +qdev_prop_set_chr (DEVICE (sci),"chardev" ,serial_hd (unit)); +qdev_prop_set_uint64 (DEVICE (sci),"input-freq" ,RX62N_PCLK ); +qdev_prop_set_int32 (DEVICE (sci),"feature" ,SCI_FEAT_SCIA ); +qdev_prop_set_int32 (DEVICE (sci),"register-size" ,8 ); +qdev_init_nofail (DEVICE (sci)); +sysbus_mmio_map (sci,0 ,RX62N_SCIBASE + unit *0x08 ); + irqbase =RX62N_SCI_IRQBASE +SCI_NR_IRQ * unit; +for (i =0 ; i <SCI_NR_IRQ ; i++) { +sysbus_connect_irq (sci, i, s->irq[irqbase + i]); + } +}[...]
Re: [PATCH 04/10] hw/char: Renesas SCI module.
In reply to Yoshinori SatoQuoted 37 lines · Yoshinori Sato
This module supported SCI / SCIa / SCIF.
Hardware manual.
SCI / SCIF
https://www.renesas.com/us/en/doc/products/mpumcu/001/r01uh0457ej0401_sh7751.pdf
SCIa
https://www.renesas.com/us/en/doc/products/mpumcu/doc/rx_family/r01uh0033ej0140_rx62n.pdfSigned-off-by Yoshinori Sato <[email protected]>--- include/hw/char/renesas_sci.h | 77 ++++ hw/char/renesas_sci.c | 786 ++++++++++++++++++++++++++++++++++ hw/char/Kconfig | 3 + hw/char/Makefile.objs | 3 +- 4 files changed, 868 insertions(+), 1 deletion(-) create mode 100644 include/hw/char/renesas_sci.h create mode 100644 hw/char/renesas_sci.cinclude/hw/char/renesas_sci.h new file +13
-0@@ -0,0 +1,77 @@ +/* +* Renesas Serial Communication Interface +* +* Copyright (c) 2020 Yoshinori Sato +* +* This code is licensed under the GPL version 2 or later. +* +*/ + +#include "chardev/char-fe.h" +#include "qemu/timer.h" +#include "qemu/fifo8.h" +#include "hw/sysbus.h"
include/hw/char/renesas_sci.h line 23
Quoted 10 lines
include/hw/char/renesas_sci.h new file +10
-0+ +#define TYPE_RENESAS_SCI "renesas-sci" +#define RSCI (obj) OBJECT_CHECK(RSCIState, (obj), TYPE_RENESAS_SCI) + +enum { +ERI =0 , +RXI =1 , +TXI =2 , +TEI =3 , +BRI =3 ,
So same interrupt number have different meaning for each model.
Quoted 449 lines
include/hw/char/renesas_sci.h new file +54
-0+ SCI_NR_IRQ = 4, +}; + +enum { +SCI_FEAT_SCI =0x00 , +SCI_FEAT_SCIA =0x01 , +SCI_FEAT_SCIF =0x10 , +}; + +enum { +RXTOUT , +RXNEXT , +TXEMPTY , +TXEND , +NR_SCI_EVENT , +}; + +typedef struct RSCIState { +SysBusDevice parent_obj; +MemoryRegion memory; +MemoryRegion memory_p4; +MemoryRegion memory_a7; + +/* SCI register */ +uint8_t smr; +uint8_t brr; +uint8_t scr; +uint8_t tdr; +uint16_t Xsr; +uint8_t scmr; +uint8_t semr; +uint16_t fcr; +uint16_t sptr; +uint16_t lsr; + +/* internal use */ +uint16_t read_Xsr; +uint16_t read_lsr; +int64_t etu; +int64_t trtime; +int64_t tx_start_time; +int tdcnt; +int regsize; +struct { +int64_t time; +int64_t (*handler)(struct RSCIState *sci); + } event[NR_SCI_EVENT ]; +QEMUTimer *event_timer; +CharBackend chr; +uint64_t input_freq; +int feature; +qemu_irq irq[SCI_NR_IRQ ]; +Fifo8 rxfifo; +}RSCIState ;hw/char/renesas_sci.c new file +389
-0@@ -0,0 +1,786 @@ +/* +* Renesas Serial Communication Interface (SCI / SCIa / SCIF) +* +* Datasheet: RX62N Group, RX621 Group User's Manual: Hardware +* (Rev.1.40 R01UH0033EJ0140) +* And SH7751 Group, SH7751R Group User's Manual: Hardware +* (Rev.4.01 R01UH0457EJ0401) +* +* Copyright (c) 2020 Yoshinori Sato +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2 or later, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "qemu-common.h" +#include "hw/hw.h" +#include "hw/irq.h" +#include "hw/sysbus.h" +#include "hw/registerfields.h" +#include "hw/qdev-properties.h" +#include "hw/char/renesas_sci.h" +#include "migration/vmstate.h" +#include "qemu/error-report.h" + +/* SCI register map */ +REG8(SMR, 0) + FIELD(SMR, CKS, 0, 2) + FIELD(SMR, MP, 2, 1) + FIELD(SMR, STOP, 3, 1) + FIELD(SMR, PM, 4, 1) + FIELD(SMR, PE, 5, 1) + FIELD(SMR, CHR, 6, 1) + FIELD(SMR, CM, 7, 1) +REG16(BRR, 2) +REG16(SCR, 4) + FIELD(SCR, CKE, 0, 2) + FIELD(SCR, TEIE, 2, 1) + FIELD(SCR, MPIE, 3, 1) + FIELD(SCR, REIE, 3, 1) + FIELD(SCR, RE, 4, 1) + FIELD(SCR, TE, 5, 1) + FIELD(SCR, RIE, 6, 1) + FIELD(SCR, TIE, 7, 1) +REG16(TDR, 6) +REG16(SSR, 8) + FIELD(SSR, MPBT, 0, 1) + FIELD(SSR, MPB, 1, 1) + FIELD(SSR, TEND, 2, 1) + FIELD(SSR, ERR, 3, 3) + FIELD(SSR, PER, 3, 1) + FIELD(SSR, FER, 4, 1) + FIELD(SSR, ORER, 5, 1) + FIELD(SSR, RDRF, 6, 1) + FIELD(SSR, TDRE, 7, 1) +REG16(FSR, 8) + FIELD(FSR, DR, 0, 1) + FIELD(FSR, RDF, 1, 1) + FIELD(FSR, RDF_DR, 0, 2) + FIELD(FSR, PER, 2, 1) + FIELD(FSR, FER, 3, 1) + FIELD(FSR, BRK, 4, 1) + FIELD(FSR, TDFE, 5, 1) + FIELD(FSR, TEND, 6, 1) + FIELD(FSR, ER, 7, 1) + FIELD(FSR, FERn, 8, 4) + FIELD(FSR, PERn, 12, 4) +REG16(RDR, 10) +REG16(SCMR, 12) + FIELD(SCMR, SMIF, 0, 1) + FIELD(SCMR, SINV, 2, 1) + FIELD(SCMR, SDIR, 3, 1) + FIELD(SCMR, BCP2, 7, 1) +REG16(FCR, 12) + FIELD(FCR, LOOP, 0, 1) + FIELD(FCR, RFRST, 1, 1) + FIELD(FCR, TFRST, 2, 1) + FIELD(FCR, MCE, 3, 1) + FIELD(FCR, TTRG, 4, 2) + FIELD(FCR, RTRG, 6, 2) + FIELD(FCR, RSTRG, 8, 3) +REG16(SEMR, 14) + FIELD(SEMR, ACS0, 0, 1) + FIELD(SEMR, ABCS, 4, 1) +REG16(FDR, 14) + FIELD(FDR, Rn, 0, 4) + FIELD(FDR, Tn, 8, 4) +REG16(SPTR, 16) + FIELD(SPTR, SPB2DT, 0, 1) + FIELD(SPTR, SPB2IO, 1, 1) + FIELD(SPTR, SCKDT, 2, 1) + FIELD(SPTR, SCKIO, 3, 1) + FIELD(SPTR, CTSDT, 4, 1) + FIELD(SPTR, CTSIO, 5, 1) + FIELD(SPTR, RTSDT, 6, 1) + FIELD(SPTR, RTSIO, 7, 1) + FIELD(SPTR, EIO, 7, 1) +REG16(LSR, 18) + FIELD(LSR, ORER, 0, 1) + +#define SCIF_FIFO_DEPTH 16 +#define IS_SCI (sci) (sci->feature < SCI_FEAT_SCIF) +#define IS_SCIA (sci) (IS_SCI(sci) && sci->feature >= SCI_FEAT_SCIA) +#define IS_SCIF (sci) (!IS_SCI(sci)) + +static const int sci_rtrg[] = {1 ,4 ,8 ,14 }; + +static void update_event_time (RSCIState *sci,int evt,int64_t t) +{ +if (t >0 ) { + t +=qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); + sci->event[evt].time = t; +if (timer_expire_time_ns (sci->event_timer) > t) { +timer_mod (sci->event_timer, t); + } + }else { + sci->event[evt].time =0 ; + } +} + +static int sci_is_rxi (RSCIState *sci) +{ +int eio; +int enable; + enable =FIELD_EX16 (sci->scr,SCR ,RIE ); +if (IS_SCI (sci)) { + eio = (sci->feature !=SCI_FEAT_SCI ) || + (FIELD_EX16 (sci->sptr,SPTR ,EIO ) ==0 ); +return FIELD_EX16 (sci->Xsr,SSR ,RDRF ) && enable && eio; + }else { +return (FIELD_EX16 (sci->Xsr,FSR ,RDF_DR ) !=0 ) && enable; + } +} + +static int sci_is_txi (RSCIState *sci) +{ +int enable =FIELD_EX16 (sci->scr,SCR ,TIE ); +if (IS_SCI (sci)) { +return enable &&FIELD_EX16 (sci->Xsr,SSR ,TDRE ); + }else { +return enable &&FIELD_EX16 (sci->Xsr,FSR ,TDFE ); + } +} + +static void sci_irq (RSCIState *sci,int req) +{ +int br; +int irq; +int rie; + +switch (req) { +case ERI : + rie =FIELD_EX16 (sci->scr,SCR ,RIE ); +if (IS_SCI (sci)) { + irq = rie && (FIELD_EX16 (sci->Xsr,SSR ,ERR ) !=0 ); + }else { + irq = (rie ||FIELD_EX16 (sci->scr,SCR ,REIE )) && +FIELD_EX16 (sci->Xsr,FSR ,ER ); + } +qemu_set_irq (sci->irq[ERI ], irq); +break ; +case RXI : +if (IS_SCIA (sci)) { +if (sci_is_rxi (sci)) { +qemu_irq_pulse (sci->irq[RXI ]); + } + }else { +qemu_set_irq (sci->irq[RXI ],sci_is_rxi (sci)); + } +break ; +case TXI : +if (IS_SCIA (sci)) { +if (sci_is_txi (sci)) { +qemu_irq_pulse (sci->irq[TXI ]); + } + }else { +qemu_set_irq (sci->irq[TXI ],sci_is_txi (sci)); + } +break ; +case BRI :/* TEI */ +if (IS_SCI (sci)) { +qemu_set_irq (sci->irq[TEI ], +FIELD_EX16 (sci->Xsr,SSR ,TEND ) && +FIELD_EX16 (sci->scr,SCR ,TEIE )); + }else { + rie =FIELD_EX16 (sci->scr,SCR ,RIE ); + br = (rie ||FIELD_EX16 (sci->scr,SCR ,REIE )) && +FIELD_EX16 (sci->Xsr,FSR ,BRK ); +qemu_set_irq (sci->irq[BRI ], br); + } +break ; + } +} + +static int can_receive (void *opaque) +{ +RSCIState *sci =RSCI (opaque); +int fifo_free =0 ; +if (FIELD_EX16 (sci->scr,SCR ,RE )) { +/* Receiver enabled */ + fifo_free =fifo8_num_free (&sci->rxfifo); +if (IS_SCIF (sci) && fifo_free ==0 ) { +/* FIFO overrun */ + sci->lsr =FIELD_DP16 (sci->lsr,LSR ,ORER ,1 ); +sci_irq (sci,ERI ); + } + } +return fifo_free; +} + +static void sci_receive (void *opaque,const uint8_t *buf,int size) +{ +RSCIState *sci =RSCI (opaque); +int rtrg; + +fifo8_push_all (&sci->rxfifo, buf, size); +if (sci->event[RXNEXT ].time ==0 ) { +if (IS_SCI (sci)) { + sci->Xsr =FIELD_DP16 (sci->Xsr,SSR ,RDRF ,1 ); +update_event_time (sci,RXNEXT , sci->trtime); + }else { + rtrg = sci_rtrg[FIELD_EX16 (sci->fcr,FCR ,RTRG )]; +if (fifo8_num_used (&sci->rxfifo) >= rtrg) { + sci->Xsr =FIELD_DP16 (sci->Xsr,FSR ,RDF ,1 ); + }else { +update_event_time (sci,RXTOUT ,15 * sci->etu); + } + } +sci_irq (sci,RXI ); + } +} + +static void sci_send_byte (RSCIState *sci) +{ +if (IS_SCI (sci)) { +if (qemu_chr_fe_backend_connected (&sci->chr)) { +qemu_chr_fe_write_all (&sci->chr, &sci->tdr,1 ); + } + sci->Xsr =FIELD_DP16 (sci->Xsr,SSR ,TEND ,0 ); + sci->Xsr =FIELD_DP16 (sci->Xsr,SSR ,TDRE ,1 ); + } +} + +static int transmit_byte (RSCIState *sci) +{ +int64_t elapsed; +int byte =0 ; +if (sci->tx_start_time >0 ) { + elapsed =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) - sci->tx_start_time; + byte = elapsed / sci->trtime; +if (byte > sci->tdcnt) { + byte = sci->tdcnt; + } + } +return byte; +} + +static int64_t sci_rx_timeout (RSCIState *sci) +{ +if (IS_SCIF (sci)) { + sci->Xsr =FIELD_DP16 (sci->Xsr,FSR ,DR ,1 ); +sci_irq (sci,RXI ); + } +return 0 ; +} + +static int64_t sci_rx_next (RSCIState *sci) +{ +int64_t next_event =0 ; +if (IS_SCI (sci) && !fifo8_is_empty (&sci->rxfifo)) { +if (FIELD_EX16 (sci->Xsr,SSR ,RDRF )) { +/* Receiver overrun */ + sci->Xsr =FIELD_DP16 (sci->Xsr,SSR ,ORER ,1 ); +sci_irq (sci,ERI ); + }else { +/* Trigger next event */ + sci->Xsr =FIELD_DP16 (sci->Xsr,SSR ,RDRF ,1 ); +sci_irq (sci,RXI ); + next_event = sci->trtime; + } + } +return next_event; +} + +static int64_t sci_tx_empty (RSCIState *sci) +{ +int64_t ret =0 ; +if (IS_SCI (sci)) { +if (!FIELD_EX16 (sci->Xsr,SSR ,TDRE )) { +sci_send_byte (sci); + ret = sci->trtime; +sci_irq (sci,TXI ); + }else { + sci->Xsr =FIELD_DP16 (sci->Xsr,SSR ,TEND ,1 ); +sci_irq (sci,TEI ); + } + }else { + sci->tdcnt -=transmit_byte (sci); + sci->Xsr =FIELD_DP16 (sci->Xsr,FSR ,TDFE ,1 ); +sci_irq (sci,TXI ); + } +return ret; +} + +static int64_t sci_tx_end (RSCIState *sci) +{ +if (IS_SCIF (sci)) { + sci->tdcnt =0 ; + sci->Xsr =FIELD_DP16 (sci->Xsr,FSR ,TEND ,1 ); +sci_irq (sci,TEI ); + } +return 0 ; +} + +static void sci_timer_event (void *opaque) +{ +RSCIState *sci =RSCI (opaque); +int64_t now, next, t; +int i; + + now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); + next =INT64_MAX ; +for (i =0 ; i <NR_SCI_EVENT ; i++) { +if (sci->event[i].time >0 && sci->event[i].time <= now) { + t = sci->event[i].handler (sci); + sci->event[i].time = (t >0 ) ? now + t :0 ; + } +if (sci->event[i].time >0 ) { + next =MIN (next, sci->event[i].time); + } + } +if (next <INT64_MAX ) { +timer_mod (sci->event_timer, next); + }else { +timer_del (sci->event_timer); + } +} + +static void update_trtime (RSCIState *sci) +{ +int divrate; +if (IS_SCIA (sci)) { + divrate =16 * (2 -FIELD_EX8 (sci->semr,SEMR ,ABCS )); + }else { + divrate =32 ; + } + +/* x bit transmit time (divrate * brr) / base freq */ + sci->etu = divrate *1 << (2 *FIELD_EX16 (sci->smr,SMR ,CKS )); + sci->etu *= sci->brr +1 ; + sci->etu *=NANOSECONDS_PER_SECOND ; + sci->etu /= sci->input_freq; + +/* char per bits */ + sci->trtime =8 -FIELD_EX16 (sci->smr,SMR ,CHR ); + sci->trtime +=FIELD_EX16 (sci->smr,SMR ,PE ); + sci->trtime +=FIELD_EX16 (sci->smr,SMR ,STOP ) +1 +1 ; + sci->trtime *= sci->etu; +} + +#define IS_TR_ENABLED (scr) \ + (FIELD_EX16(scr, SCR, TE) || FIELD_EX16(scr, SCR, RE)) + +#define SCI_IS_NOT_SUPPORTED (sci, name) \ + if (sci->feature == SCI_FEAT_SCI) { \ + qemu_log_mask(LOG_GUEST_ERROR, \ + "reneas_sci: " #name " is not supported.\n"); \ + } + +static void sci_write (void *opaque,hwaddr addr,uint64_t val,unsigned size) +{ +RSCIState *sci =RSCI (opaque); +int txtrg; +int rxtrg; +uint8_t txd; +uint16_t ssr_mask; +bool tx_start = false; +
hw/char/renesas_sci.c line 399
Quoted 10 lines
hw/char/renesas_sci.c new file +10
-0+if (IS_SCI (sci)) { + txtrg =1 ; + }else { + txtrg =1 << (3 -FIELD_EX16 (sci->fcr,FCR ,TTRG )); + } +switch (sci->regsize) { +case 8 : + addr <<=1 ;break ; +case 32 : + addr >>=1 ;break ;
This should be handled by sci_ops.impl, such:
static const MemoryRegionOps sci_ops = {
.impl = {
.min_access_size = 2,
.max_access_size = 2,
},
.valid = {
.min_access_size = 1,
.max_access_size = 4,
},
...Then access_with_adjusted_size() will automagically do the conversion for you.
Quoted 374 lines
hw/char/renesas_sci.c new file +374
-0+ } +switch (addr) { +case A_SMR : +if (IS_SCIA (sci) &&IS_TR_ENABLED (sci->scr)) { +qemu_log_mask (LOG_GUEST_ERROR , +"reneas_sci: SMR write protected.\n" ); +break ; + } + sci->smr = val; +update_trtime (sci); +break ; +case A_BRR : +if (IS_SCIA (sci) &&IS_TR_ENABLED (sci->scr)) { +qemu_log_mask (LOG_GUEST_ERROR , +"reneas_sci: BRR write protected.\n" ); +break ; + } + sci->brr = val; +update_trtime (sci); +break ; +case A_SCR : + sci->scr = val; +if (FIELD_EX16 (sci->scr,SCR ,TE )) { +/* Transmitter enable */ +if (IS_SCI (sci)) { + sci->Xsr =FIELD_DP16 (sci->Xsr,SSR ,TDRE ,1 ); + sci->Xsr =FIELD_DP16 (sci->Xsr,SSR ,TEND ,1 ); + }else { + sci->Xsr =FIELD_DP16 (sci->Xsr,FSR ,TEND ,1 ); + sci->Xsr =FIELD_DP16 (sci->Xsr,FSR ,TDFE ,1 ); + sci->tx_start_time =0 ; + } +sci_irq (sci,TXI ); +sci_irq (sci,TEI ); + }else { +/* Transmitter disable */ +update_event_time (sci,TXEND ,0 ); +update_event_time (sci,TXEMPTY ,0 ); + } +break ; +case A_TDR : +if (IS_SCI (sci)) { + sci->tdr = val; +if (IS_SCIA (sci)) { +if (FIELD_EX16 (sci->Xsr,SSR ,TEND )) { +update_event_time (sci,TXEMPTY , sci->trtime); +sci_send_byte (sci); + }else { + sci->Xsr =FIELD_DP16 (sci->Xsr,SSR ,TDRE ,0 ); + } +sci_irq (sci,TXI ); +sci_irq (sci,TEI ); + } + }else { +if (sci->tx_start_time >0 ) { + sci->tdcnt -=transmit_byte (sci); + }else { + sci->tx_start_time =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); + } +if (sci->tdcnt >=SCIF_FIFO_DEPTH ) { +break ; + } + txd = val; +if (qemu_chr_fe_backend_connected (&sci->chr)) { +qemu_chr_fe_write_all (&sci->chr, &txd,1 ); + } +if (FIELD_EX16 (sci->fcr,FCR ,LOOP ) &&can_receive (sci) >0 ) { +/* Loopback mode */ +sci_receive (sci, &txd,1 ); + } + sci->tdcnt++; + sci->Xsr =FIELD_DP16 (sci->Xsr,FSR ,TEND ,0 ); +update_event_time (sci,TXEND , sci->tdcnt); +if (sci->tdcnt > txtrg) { + sci->Xsr =FIELD_DP16 (sci->Xsr,FSR ,TDFE ,0 ); +update_event_time (sci,TXEMPTY , sci->tdcnt - txtrg +1 ); +sci_irq (sci,TXI ); + } + } +break ; +case A_FSR :/* A_SSR */ +if (IS_SCI (sci)) { +/* Mask for read only bits */ + ssr_mask =IS_SCIA (sci) ?0xc7 :0x07 ; + sci->Xsr =FIELD_DP16 (sci->Xsr,SSR ,MPBT , +FIELD_EX16 (val,SSR ,MPBT )); + sci->Xsr &= (val | ssr_mask); +/* Clear ERI */ +sci_irq (sci,ERI ); +if (sci->feature ==SCI_FEAT_SCI ) { + tx_start =FIELD_EX16 (sci->read_Xsr,SSR ,TDRE ) && + !FIELD_EX16 (sci->Xsr,SSR ,TDRE ) && + (FIELD_EX16 (sci->Xsr,SSR ,ERR ) ==0 ); +if (tx_start) { +sci_send_byte (sci); +update_event_time (sci,TXEMPTY , sci->trtime); +sci_irq (sci,TXI ); + } + } + }else { + rxtrg = sci_rtrg[FIELD_EX16 (sci->fcr,FCR ,RTRG )]; + ssr_mask = ~(sci->read_Xsr &0xf3 ); + sci->tdcnt -=transmit_byte (sci); +if (sci->tdcnt < txtrg) { + ssr_mask =FIELD_DP16 (ssr_mask,FSR ,TDFE ,1 ); + } +if (fifo8_num_used (&sci->rxfifo) >= rxtrg) { + ssr_mask =FIELD_DP16 (ssr_mask,FSR ,RDF ,1 ); + } + sci->Xsr &= (val | ssr_mask); +sci_irq (sci,ERI ); +sci_irq (sci,RXI ); +sci_irq (sci,TXI ); + } +break ; +case A_RDR : +qemu_log_mask (LOG_GUEST_ERROR ,"reneas_sci: RDR is read only.\n" ); +break ; +case A_FCR :/* A_SCMR / A_SPTR */ +if (IS_SCI (sci)) { +if (sci->feature ==SCI_FEAT_SCI ) { + sci->sptr = val; + }else { + sci->scmr = val; + } + }else { + sci->fcr = val; +if (FIELD_EX16 (sci->fcr,FCR ,RFRST )) { +fifo8_reset (&sci->rxfifo); +update_event_time (sci,RXTOUT ,0 ); +update_event_time (sci,RXNEXT ,0 ); + } +if (FIELD_EX16 (sci->fcr,FCR ,TFRST )) { + sci->tdcnt =0 ; + } + } +break ; +case A_FDR :/* A_SEMR */ +if (IS_SCI (sci)) { +SCI_IS_NOT_SUPPORTED (sci,SEMR ); + sci->semr = val; + }else { +qemu_log_mask (LOG_GUEST_ERROR ,"reneas_sci: FDR is read only.\n" ); + } +break ; +case A_SPTR : +if (IS_SCI (sci)) { + goto error; + }else { + sci->sptr = val; + } +break ; +case A_LSR : +if (IS_SCI (sci)) { + goto error; + }else { +if (FIELD_EX16 (sci->read_lsr,LSR ,ORER ) !=1 ) { + val =FIELD_DP16 (val,LSR ,ORER ,1 ); + } + sci->lsr &= val; +sci_irq (sci,ERI ); + } +break ; +default : + error: +qemu_log_mask (LOG_UNIMP ,"renesas_sci: Register 0x%" HWADDR_PRIX +" not implemented\n" , addr); + } +} + +static uint64_t sci_read (void *opaque,hwaddr addr,unsigned size) +{ +RSCIState *sci =RSCI (opaque); +uint64_t ret; + +switch (sci->regsize) { +case 8 : + addr <<=1 ;break ; +case 32 : + addr >>=1 ;break ; + } + +switch (addr) { +case A_SMR : +return sci->smr; +case A_BRR : +return sci->brr; +case A_SCR : +return sci->scr; +case A_TDR : +if (IS_SCI (sci)) { +return sci->tdr; + }else { +qemu_log_mask (LOG_GUEST_ERROR ,"reneas_sci: TDR is write only.\n" ); +return UINT64_MAX ; + } +case A_FSR :/* A_SSR */ + sci->read_Xsr = sci->Xsr; +return sci->Xsr; +case A_RDR : + ret =fifo8_pop (&sci->rxfifo); +if (IS_SCIA (sci)) { + sci->Xsr =FIELD_DP16 (sci->Xsr,SSR ,RDRF ,0 ); + } +return ret; +case A_FCR :/* A_SCMR / A_SPTR */ +if (IS_SCI (sci)) { +if (IS_SCIA (sci)) { +return sci->scmr; + }else { +return sci->sptr; + } + }else { +return sci->fcr &0x7ff ; + } +case A_FDR :/* A_SEMR */ +if (IS_SCI (sci)) { +SCI_IS_NOT_SUPPORTED (sci,SEMR ); +return sci->semr; + }else { + ret =0 ; + ret =FIELD_DP16 (ret,FDR , Rn,fifo8_num_used (&sci->rxfifo)); + ret =FIELD_DP16 (ret,FDR , Tn, sci->tdcnt -transmit_byte (sci)); +return ret; + } +case A_SPTR : +if (IS_SCI (sci)) { + goto error; + }else { +return sci->sptr; + } +case A_LSR : +if (IS_SCI (sci)) { + goto error; + }else { + sci->read_lsr = sci->lsr; +return sci->lsr; + } +default : + error: +qemu_log_mask (LOG_UNIMP ,"renesas_sci: Register 0x%" HWADDR_PRIX +" not implemented.\n" , addr); + } +return UINT64_MAX ; +} + +static const MemoryRegionOps sci_ops = { + .write = sci_write, + .read = sci_read, + .endianness =DEVICE_NATIVE_ENDIAN , + .impl = { + .max_access_size =4 , + }, +}; + +static void sci_register_init (RSCIState *sci) +{ +int i; + sci->smr = sci->scr =0x00 ; + sci->brr =0xff ; +if (IS_SCI (sci)) { + sci->tdr =0xff ; + sci->Xsr =0x84 ; + sci->scmr =0x00 ; + sci->semr =0x00 ; + sci->sptr =0x00 ; + }else { + sci->Xsr =0x0060 ; + sci->fcr =0x0000 ; + sci->sptr =0x0000 ; + sci->lsr =0x0000 ; + } +update_trtime (sci); +for (i =0 ; i <NR_SCI_EVENT ; i++) { + sci->event[i].time =0 ; + } +} + +static void sci_event (void *opaque,QEMUChrEvent event) +{ +RSCIState *sci =RSCI (opaque); +if (event ==CHR_EVENT_BREAK ) { +if (IS_SCI (sci)) { + sci->Xsr =FIELD_DP16 (sci->Xsr,SSR ,FER ,1 ); + }else { + sci->Xsr =FIELD_DP16 (sci->Xsr,FSR ,BRK ,1 ); + } +sci_irq (sci,ERI ); + } +} + +static void rsci_realize (DeviceState *dev,Error **errp) +{ +SysBusDevice *d =SYS_BUS_DEVICE (dev); +RSCIState *sci =RSCI (dev); +int i; +int size; + +if (sci->input_freq ==0 ) { +qemu_log_mask (LOG_GUEST_ERROR , +"renesas_sci: input-freq property must be set." ); +return ; + } +if (sci->regsize !=8 && sci->regsize !=16 && sci->regsize !=32 ) { +qemu_log_mask (LOG_GUEST_ERROR , +"renesas_sci: Invalid regsize." ); +return ; + } + + size =IS_SCI (sci) ?16 :20 ; +switch (sci->regsize) { +case 8 : + size >>=1 ; +break ; +case 32 : + size <<=1 ; +break ; + } +memory_region_init_io (&sci->memory,OBJECT (sci), &sci_ops, + sci,"renesas-sci" , size); +sysbus_init_mmio (d, &sci->memory); +memory_region_init_alias (&sci->memory_p4,NULL ,"renesas-sci-p4" , + &sci->memory,0 , size); +sysbus_init_mmio (d, &sci->memory_p4); +memory_region_init_alias (&sci->memory_a7,NULL ,"renesas-sci-a7" , + &sci->memory,0 , size); +sysbus_init_mmio (d, &sci->memory_a7); + +for (i =0 ; i <SCI_NR_IRQ ; i++) { +sysbus_init_irq (d, &sci->irq[i]); + } + sci->event_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , sci_timer_event, sci); + +qemu_chr_fe_set_handlers (&sci->chr, can_receive, sci_receive, + sci_event,NULL , sci,NULL , true); +fifo8_create (&sci->rxfifo,SCIF_FIFO_DEPTH ); +sci_register_init (sci); +} + +static const VMStateDescription vmstate_rsci = { + .name ="renesas-sci" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_END_OF_LIST () + } +}; + +static Property rsci_properties[] = { +DEFINE_PROP_UINT64 ("input-freq" , RSCIState, input_freq,0 ), +DEFINE_PROP_INT32 ("register-size" , RSCIState, regsize,8 ), +DEFINE_PROP_INT32 ("feature" , RSCIState, feature,0 ), +DEFINE_PROP_CHR ("chardev" , RSCIState, chr), +DEFINE_PROP_END_OF_LIST (), +}; + +static void rsci_init (Object *obj) +{ +RSCIState *sci =RSCI (obj); + sci->event[RXTOUT ].handler = sci_rx_timeout; + sci->event[RXNEXT ].handler = sci_rx_next; + sci->event[TXEMPTY ].handler = sci_tx_empty; + sci->event[TXEND ].handler = sci_tx_end; +} +static void rsci_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = rsci_realize; + dc->vmsd = &vmstate_rsci; +device_class_set_props (dc, rsci_properties); +} + +static const TypeInfo rsci_info = {
hw/char/renesas_sci.c line 783
Quoted 10 lines
hw/char/renesas_sci.c new file +10
-0+ .name = TYPE_RENESAS_SCI, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(RSCIState), + .instance_init = rsci_init, + .class_init = rsci_class_init, +}; + +static void rsci_register_types (void ) +{ +type_register_static (&rsci_info);
I'd rather register a type for each SCI / SCIa / SCIF models.
TYPE_RENESAS_SCI_COMMON the abstract base,
then i.e. TYPE_RENESAS_SCI_A only implements a SCIa with its register mapped at correct addresses, no need to use 'if IS_SCI()' all over the place.
I need more time to review.
Quoted 3 lines
hw/char/renesas_sci.c new file +3
-0+} + +type_init (rsci_register_types)