Skip to contentSkip to conversation

Unified peripheral emulation for Renesas chips

PATCH In review Yoshinori Sato 3 participants 21 messages May 27, 2021 – Jun 6, 2021 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

cover Unified peripheral emulation for Renesas chips

Renesas SH4 and RX have similar peripherals. Integrate the emulation code for these peripherals.

Migrate peripherals.
SH4 sh_timer(TMU) -> renesas_timer
SH4 sh_serial(SCI/SCIF) -> renesas_sci
RX renesas_cmt(CMT) -> renesas_timer
RX renesas_sci(SCIa) -> renesas_sci

I want to process the peripheral clocks of SH4 and RX in the same way, so I added a new clock generator. This will generate a peripheral clock from the master clock.

Yoshinori Sato (11):
hw/char: Renesas SCI module.
hw/char: remove sh_serial.
hw/timer: Renesas TMU/CMT module.
hw/timer: Remove sh_timer.
hw/timer: Remove renesas_cmt.
hw/rx: Add RX62N Clock generator
hw/timer: Renesas 8bit timer.
hw/rx: rx62n use new hw modules.
hw/sh4: sh7750 Add CPG.
hw/sh4: sh7750 use new hw modules.
hw/rx: rx-gdbsim Add bootstrup for linux

 include/hw/char/renesas_sci.h    |  129 +++-
 include/hw/rx/rx62n-cpg.h        |   72 +++
 include/hw/rx/rx62n.h            |   34 +-
 include/hw/sh4/sh.h              |    8 -
 include/hw/sh4/sh7751-cpg.h      |   94 +++
 include/hw/timer/renesas_cmt.h   |   43 --
 include/hw/timer/renesas_timer.h |   96 +++
 include/hw/timer/renesas_tmr.h   |   58 --
 include/hw/timer/renesas_tmr8.h  |   67 ++
 include/hw/timer/tmu012.h        |   23 -
 hw/char/renesas_sci.c            | 1039 +++++++++++++++++++++++++-----
 hw/char/sh_serial.c              |  431 -------------
 hw/rx/rx-gdbsim.c                |   89 +--
 hw/rx/rx62n-cpg.c                |  344 ++++++++++
 hw/rx/rx62n.c                    |   64 +-
 hw/sh4/sh7750.c                  |  110 +++-
 hw/sh4/sh7751-cpg.c              |  457 +++++++++++++
 hw/timer/renesas_cmt.c           |  283 --------
 hw/timer/renesas_timer.c         |  644 ++++++++++++++++++
 hw/timer/renesas_tmr.c           |  493 --------------
 hw/timer/renesas_tmr8.c          |  540 ++++++++++++++++
 hw/timer/sh_timer.c              |  368 -----------
 MAINTAINERS                      |    8 +-
 hw/char/Kconfig                  |    3 -
 hw/char/meson.build              |    1 -
 hw/rx/Kconfig                    |    4 +-
 hw/rx/meson.build                |    2 +-
 hw/sh4/Kconfig                   |    4 +-
 hw/sh4/meson.build               |    1 +
 hw/timer/Kconfig                 |   12 +-
 hw/timer/meson.build             |    5 +-
 31 files changed, 3501 insertions(+), 2025 deletions(-)
 create mode 100644 include/hw/rx/rx62n-cpg.h
 create mode 100644 include/hw/sh4/sh7751-cpg.h
 delete mode 100644 include/hw/timer/renesas_cmt.h
 create mode 100644 include/hw/timer/renesas_timer.h
 delete mode 100644 include/hw/timer/renesas_tmr.h
 create mode 100644 include/hw/timer/renesas_tmr8.h
 delete mode 100644 include/hw/timer/tmu012.h
 delete mode 100644 hw/char/sh_serial.c
 create mode 100644 hw/rx/rx62n-cpg.c
 create mode 100644 hw/sh4/sh7751-cpg.c
 delete mode 100644 hw/timer/renesas_cmt.c
 create mode 100644 hw/timer/renesas_timer.c
 delete mode 100644 hw/timer/renesas_tmr.c
 create mode 100644 hw/timer/renesas_tmr8.c
 delete mode 100644 hw/timer/sh_timer.c
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/11 hw/char: Renesas SCI module.

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.pdf

---
 include/hw/char/renesas_sci.h |  129 +++-
 hw/char/renesas_sci.c         | 1039 +++++++++++++++++++++++++++------
 2 files changed, 966 insertions(+), 202 deletions(-)
include/hw/char/renesas_sci.h +106 -23
index a4764e3eee..ae9554db60 100644
@@ -1,54 +1,137 @@
 /*
  * Renesas Serial Communication Interface
  *
- * Copyright (c) 2018 Yoshinori Sato
+ * Copyright (c) 2020 Yoshinori Sato
+ *
+ * This code is licensed under the GPL version 2 or later.
  *
- * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
-#ifndef HW_CHAR_RENESAS_SCI_H
-#define HW_CHAR_RENESAS_SCI_H
-
 #include "chardev/char-fe.h"
+#include "qemu/timer.h"
+#include "qemu/fifo8.h"
 #include "hw/sysbus.h"
 #include "qom/object.h"
 
+#define TYPE_RENESAS_SCI_BASE "renesas-sci-base"
+OBJECT_DECLARE_TYPE(RenesasSCIBaseState, RenesasSCIBaseClass,
+                    RENESAS_SCI_BASE)
 #define TYPE_RENESAS_SCI "renesas-sci"
-typedef struct RSCIState RSCIState;
-DECLARE_INSTANCE_CHECKER(RSCIState, RSCI,
-                         TYPE_RENESAS_SCI)
+OBJECT_DECLARE_TYPE(RenesasSCIState, RenesasSCIClass,
+                    RENESAS_SCI)
+#define TYPE_RENESAS_SCIA "renesas-scia"
+OBJECT_DECLARE_TYPE(RenesasSCIAState, RenesasSCIAClass,
+                    RENESAS_SCIA)
+#define TYPE_RENESAS_SCIF "renesas-scif"
+OBJECT_DECLARE_TYPE(RenesasSCIFState, RenesasSCIFClass,
+                    RENESAS_SCIF)
 
 enum {
     ERI = 0,
     RXI = 1,
     TXI = 2,
-    TEI = 3,
-    SCI_NR_IRQ = 4
+    BRI_TEI = 3,
+    SCI_NR_IRQ = 4,
+};
+
+enum {
+    RXTOUT,
+    RXNEXT,
+    TXEMPTY,
+    TXEND,
+    NR_SCI_EVENT,
 };
 
-struct RSCIState {
+enum {
+    SCI_REGSIZE_8 = 0,
+    SCI_REGSIZE_16 = 1,
+    SCI_REGSIZE_32 = 2,
+};
+
+typedef struct RenesasSCIBaseState {
     /*< private >*/
     SysBusDevice parent_obj;
-    /*< public >*/
-
     MemoryRegion memory;
-    QEMUTimer timer;
-    CharBackend chr;
-    qemu_irq irq[SCI_NR_IRQ];
+    MemoryRegion memory_p4;
+    MemoryRegion memory_a7;
 
+    /* SCI register */
     uint8_t smr;
     uint8_t brr;
     uint8_t scr;
     uint8_t tdr;
-    uint8_t ssr;
-    uint8_t rdr;
-    uint8_t scmr;
-    uint8_t semr;
+    uint16_t Xsr;
 
-    uint8_t read_ssr;
+    /* internal use */
+    uint16_t read_Xsr;
+    int64_t etu;
     int64_t trtime;
-    int64_t rx_next;
+    int64_t tx_start_time;
+    struct {
+        int64_t time;
+        int64_t (*handler)(struct RenesasSCIBaseState *sci);
+    } event[NR_SCI_EVENT];
+    QEMUTimer *event_timer;
+    CharBackend chr;
     uint64_t input_freq;
+    qemu_irq irq[SCI_NR_IRQ];
+    Fifo8 rxfifo;
+    int regshift;
+    uint32_t unit;
+    Clock *pck;
+} RenesasSCIBaseState;
+
+struct RenesasSCIState {
+    RenesasSCIBaseState parent_obj;
+
+    /* SCI specific register */
+    uint8_t sptr;
 };
 
-#endif
+struct RenesasSCIAState {
+    RenesasSCIBaseState parent_obj;
+
+    /* SCIa specific register */
+    uint8_t scmr;
+    uint8_t semr;
+};
+
+struct RenesasSCIFState {
+    RenesasSCIBaseState parent_obj;
+
+    /* SCIF specific register */
+    uint16_t fcr;
+    uint16_t sptr;
+    uint16_t lsr;
+
+    /* private */
+    uint16_t read_lsr;
+    int tdcnt;
+};
+
+typedef struct RenesasSCIBaseClass {
+    SysBusDeviceClass parent;
+
+    const struct MemoryRegionOps *ops;
+    void (*irq_fn)(struct RenesasSCIBaseState *sci, int request);
+    int (*divrate)(struct RenesasSCIBaseState *sci);
+} RenesasSCIBaseClass;
+
+typedef struct RenesasSCIClass {
+    RenesasSCIBaseClass parent;
+
+    void (*p_irq_fn)(struct RenesasSCIBaseState *sci, int request);
+} RenesasSCIClass;
+
+typedef struct RenesasSCIAClass {
+    RenesasSCIBaseClass parent;
+
+    void (*p_irq_fn)(struct RenesasSCIBaseState *sci, int request);
+    int (*p_divrate)(struct RenesasSCIBaseState *sci);
+} RenesasSCIAClass;
+
+typedef struct RenesasSCIFClass {
+    RenesasSCIBaseClass parent;
+
+    void (*p_irq_fn)(struct RenesasSCIBaseState *sci, int request);
+} RenesasSCIFClass;
hw/char/renesas_sci.c +860 -179

1,197 lines not on this page · raw message

Signature · 1 line
2.20.1
#2 lore raw

Re: [PATCH 01/11] hw/char: Renesas SCI module.

Quoted 9 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.pdf

Quoted 5 lines
---
 include/hw/char/renesas_sci.h |  129 +++-
 hw/char/renesas_sci.c         | 1039 +++++++++++++++++++++++++++------
 2 files changed, 966 insertions(+), 202 deletions(-)

This patch is much too large to review. Could you split it up into multiple logical pieces, please?

Quoted 6 lines
include/hw/char/renesas_sci.h +0 -0
index a4764e3eee..ae9554db60 100644

include/hw/char/renesas_sci.h line 6

Quoted 9 lines
include/hw/char/renesas_sci.h +3 -2
@@ -1,54 +1,137 @@
 /*
  * Renesas Serial Communication Interface
  *
- * Copyright (c) 2018 Yoshinori Sato
+ * Copyright (c) 2020 Yoshinori Sato
+ *
+ * This code is licensed under the GPL version 2 or later.
  *
- * SPDX-License-Identifier: GPL-2.0-or-later

Did you have a reason for deleting the SPDX line ?

include/hw/char/renesas_sci.h line 11

Quoted 5 lines
include/hw/char/renesas_sci.h +0 -3
  */
 
-#ifndef HW_CHAR_RENESAS_SCI_H
-#define HW_CHAR_RENESAS_SCI_H
-

Why have you deleted the multiple-include guard?

thanks
-- PMM

#3 lore raw

Re: [PATCH 01/11] hw/char: Renesas SCI module.

Quoted 11 lines · Peter Maydell
Quoted 9 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.pdf

Quoted 8 lines
Quoted 5 lines
---
 include/hw/char/renesas_sci.h |  129 +++-
 hw/char/renesas_sci.c         | 1039 +++++++++++++++++++++++++++------
 2 files changed, 966 insertions(+), 202 deletions(-)

This patch is much too large to review. Could you split it up into multiple logical pieces, please?

OK. I will snt v2.

Quoted 29 lines
Quoted 7 lines
include/hw/char/renesas_sci.h +0 -0
index a4764e3eee..ae9554db60 100644

include/hw/char/renesas_sci.h line 6

Quoted 9 lines
include/hw/char/renesas_sci.h +3 -2
@@ -1,54 +1,137 @@
 /*
  * Renesas Serial Communication Interface
  *
- * Copyright (c) 2018 Yoshinori Sato
+ * Copyright (c) 2020 Yoshinori Sato
+ *
+ * This code is licensed under the GPL version 2 or later.
  *
- * SPDX-License-Identifier: GPL-2.0-or-later

Did you have a reason for deleting the SPDX line ?

include/hw/char/renesas_sci.h line 11

Quoted 5 lines
include/hw/char/renesas_sci.h +0 -3
  */
 
-#ifndef HW_CHAR_RENESAS_SCI_H
-#define HW_CHAR_RENESAS_SCI_H
-

Why have you deleted the multiple-include guard?

thanks
-- PMM

Signature · 1 line
Yoshinori Sato
#4 lore raw

Re: [PATCH 01/11] hw/char: Renesas SCI module.

In reply to Peter Maydell
Quoted 11 lines · Peter Maydell
Quoted 9 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.pdf

Quoted 8 lines
Quoted 5 lines
---
 include/hw/char/renesas_sci.h |  129 +++-
 hw/char/renesas_sci.c         | 1039 +++++++++++++++++++++++++++------
 2 files changed, 966 insertions(+), 202 deletions(-)

This patch is much too large to review. Could you split it up into multiple logical pieces, please?

OK. I will snt v2.

Quoted 29 lines
Quoted 7 lines
include/hw/char/renesas_sci.h +0 -0
index a4764e3eee..ae9554db60 100644

include/hw/char/renesas_sci.h line 6

Quoted 9 lines
include/hw/char/renesas_sci.h +3 -2
@@ -1,54 +1,137 @@
 /*
  * Renesas Serial Communication Interface
  *
- * Copyright (c) 2018 Yoshinori Sato
+ * Copyright (c) 2020 Yoshinori Sato
+ *
+ * This code is licensed under the GPL version 2 or later.
  *
- * SPDX-License-Identifier: GPL-2.0-or-later

Did you have a reason for deleting the SPDX line ?

include/hw/char/renesas_sci.h line 11

Quoted 5 lines
include/hw/char/renesas_sci.h +0 -3
  */
 
-#ifndef HW_CHAR_RENESAS_SCI_H
-#define HW_CHAR_RENESAS_SCI_H
-

Why have you deleted the multiple-include guard?

thanks
-- PMM

Signature · 1 line
Yoshinori Sato
#5 lore raw

PATCH 2/11 hw/char: remove sh_serial.

In reply to Yoshinori Sato

Migrate to renesas_sci.

---
 hw/char/sh_serial.c | 431 --------------------------------------------
 MAINTAINERS         |   4 +-
 hw/char/Kconfig     |   3 -
 hw/char/meson.build |   1 -
 4 files changed, 2 insertions(+), 437 deletions(-)
 delete mode 100644 hw/char/sh_serial.c
hw/char/sh_serial.c deleted +0 -431
deleted file mode 100644
index 167f4d8cb9..0000000000
@@ -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;
-}
MAINTAINERS +2 -2
index a77f246569..ecfa97cefa 100644
@@ -1410,7 +1410,7 @@ R2D
 R: Yoshinori Sato <[email protected]>
 R: Magnus Damm <[email protected]>
 S: Odd Fixes
-F: hw/char/sh_serial.c
+F: hw/char/renesas_sci.c
 F: hw/sh4/r2d.c
 F: hw/intc/sh_intc.c
 F: hw/pci-host/sh_pci.c
@@ -1422,7 +1422,7 @@ R: Yoshinori Sato <[email protected]>
 R: Magnus Damm <[email protected]>
 S: Odd Fixes
 F: hw/block/tc58128.c
-F: hw/char/sh_serial.c
+F: hw/char/reness_sci.c
 F: hw/sh4/shix.c
 F: hw/intc/sh_intc.c
 F: hw/timer/sh_timer.c
hw/char/Kconfig +0 -3
index 4cf36ac637..a8bf0c6a77 100644
@@ -50,9 +50,6 @@ config SCLPCONSOLE
 config TERMINAL3270
     bool
 
-config SH_SCI
-    bool
-
 config RENESAS_SCI
     bool
 
hw/char/meson.build +0 -1
index 8361d0ab28..b9a88aa200 100644
@@ -29,7 +29,6 @@ softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_uart.c'))
 softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_aux.c'))
 softmmu_ss.add(when: 'CONFIG_RENESAS_SCI', if_true: files('renesas_sci.c'))
 softmmu_ss.add(when: 'CONFIG_SIFIVE_UART', if_true: files('sifive_uart.c'))
-softmmu_ss.add(when: 'CONFIG_SH_SCI', if_true: files('sh_serial.c'))
 softmmu_ss.add(when: 'CONFIG_STM32F2XX_USART', if_true: files('stm32f2xx_usart.c'))
 softmmu_ss.add(when: 'CONFIG_MCHP_PFSOC_MMUART', if_true: files('mchp_pfsoc_mmuart.c'))
 
Signature · 1 line
2.20.1
#6 lore raw

Re: [PATCH 02/11] hw/char: remove sh_serial.

Quoted 11 lines · Yoshinori Sato

Migrate to renesas_sci.

---
 hw/char/sh_serial.c | 431 --------------------------------------------
 MAINTAINERS         |   4 +-
 hw/char/Kconfig     |   3 -
 hw/char/meson.build |   1 -
 4 files changed, 2 insertions(+), 437 deletions(-)
 delete mode 100644 hw/char/sh_serial.c

This won't compile, because there are still boards which use the old code you are removing here. The patchset has to be able to compile and work at every step, so you need to first add new devices, then convert the boards to use them, and then as the last step you can remove the old implementations.

Checking, I find that patch 1 doesn't compile either.

thanks
-- PMM

#7 lore raw

Re: [PATCH 02/11] hw/char: remove sh_serial.

Quoted 20 lines · Peter Maydell
Quoted 11 lines · Yoshinori Sato

Migrate to renesas_sci.

---
 hw/char/sh_serial.c | 431 --------------------------------------------
 MAINTAINERS         |   4 +-
 hw/char/Kconfig     |   3 -
 hw/char/meson.build |   1 -
 4 files changed, 2 insertions(+), 437 deletions(-)
 delete mode 100644 hw/char/sh_serial.c

This won't compile, because there are still boards which use the old code you are removing here. The patchset has to be able to compile and work at every step, so you need to first add new devices, then convert the boards to use them, and then as the last step you can remove the old implementations.

Quoted 4 lines

Checking, I find that patch 1 doesn't compile either.

thanks
-- PMM

OK. I will sent v2.

Signature · 1 line
Yoshinori Sato
#8 lore raw

Re: [PATCH 02/11] hw/char: remove sh_serial.

In reply to Peter Maydell
Quoted 20 lines · Peter Maydell
Quoted 11 lines · Yoshinori Sato

Migrate to renesas_sci.

---
 hw/char/sh_serial.c | 431 --------------------------------------------
 MAINTAINERS         |   4 +-
 hw/char/Kconfig     |   3 -
 hw/char/meson.build |   1 -
 4 files changed, 2 insertions(+), 437 deletions(-)
 delete mode 100644 hw/char/sh_serial.c

This won't compile, because there are still boards which use the old code you are removing here. The patchset has to be able to compile and work at every step, so you need to first add new devices, then convert the boards to use them, and then as the last step you can remove the old implementations.

Quoted 4 lines

Checking, I find that patch 1 doesn't compile either.

thanks
-- PMM

OK. I will sent v2.

Signature · 1 line
Yoshinori Sato
#9 lore raw

Re: [PATCH 02/11] hw/char: remove sh_serial.

In reply to Peter Maydell
Quoted 20 lines · Peter Maydell
Quoted 11 lines · Yoshinori Sato

Migrate to renesas_sci.

---
 hw/char/sh_serial.c | 431 --------------------------------------------
 MAINTAINERS         |   4 +-
 hw/char/Kconfig     |   3 -
 hw/char/meson.build |   1 -
 4 files changed, 2 insertions(+), 437 deletions(-)
 delete mode 100644 hw/char/sh_serial.c

This won't compile, because there are still boards which use the old code you are removing here. The patchset has to be able to compile and work at every step, so you need to first add new devices, then convert the boards to use them, and then as the last step you can remove the old implementations.

Quoted 4 lines

Checking, I find that patch 1 doesn't compile either.

thanks
-- PMM

OK. I will sent v2.

Signature · 1 line
Yoshinori Sato
#10 lore raw

PATCH 3/11 hw/timer: Renesas TMU/CMT module.

In reply to Yoshinori Sato

TMU - 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 |  96 +++++
 hw/timer/renesas_timer.c         | 644 +++++++++++++++++++++++++++++++
 hw/timer/Kconfig                 |   3 +
 hw/timer/meson.build             |   1 +
 4 files changed, 744 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 +96 -0
new file mode 100644
index 0000000000..d71feec54e
@@ -0,0 +1,96 @@
+/*
+ * 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"
+#include "hw/qdev-clock.h"
+
+#define TYPE_RENESAS_TIMER_BASE "renesas-timer"
+OBJECT_DECLARE_TYPE(RenesasTimerBaseState, RenesasTimerBaseClass,
+                    RENESAS_TIMER_BASE)
+#define TYPE_RENESAS_CMT "renesas-cmt"
+OBJECT_DECLARE_TYPE(RenesasCMTState, RenesasCMTClass,
+                    RENESAS_CMT)
+#define TYPE_RENESAS_TMU "renesas-tmu"
+OBJECT_DECLARE_TYPE(RenesasTMUState, RenesasTMUClass,
+                    RENESAS_TMU)
+
+enum {
+    TIMER_CH_CMT = 2,
+    TIMER_CH_TMU = 3,
+};
+
+enum {
+    CMT_NR_IRQ = 1 * TIMER_CH_CMT,
+};
+
+struct RenesasTimerBaseState;
+
+enum dirction {
+    countup, countdown,
+};
+
+struct rtimer_ch {
+    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 RenesasTimerBaseState *tmrp;
+};
+
+typedef struct RenesasTimerBaseState {
+    SysBusDevice parent_obj;
+
+    uint64_t input_freq;
+    MemoryRegion memory;
+    Clock *pck;
+
+    struct rtimer_ch ch[TIMER_CH_TMU];
+    int num_ch;
+    enum dirction direction;
+    int unit;
+} RenesasTimerBaseState;
+
+typedef struct RenesasCMTState {
+    RenesasTimerBaseState parent_obj;
+} RenesasCMTState;
+
+typedef struct RenesasTMUState {
+    RenesasTimerBaseState parent_obj;
+    uint8_t tocr;
+    MemoryRegion memory_p4;
+    MemoryRegion memory_a7;
+} RenesasTMUState;
+
+typedef struct RenesasTimerBaseClass {
+    SysBusDeviceClass parent;
+    int (*divrate)(RenesasTimerBaseState *tmr, int ch);
+    void (*timer_event)(void *opaque);
+    int64_t (*delta_to_tcnt)(RenesasTimerBaseState *tmr, int ch, int64_t delta);
+    int64_t (*get_next)(RenesasTimerBaseState *tmr, int ch);
+    void (*update_clk)(RenesasTimerBaseState *tmr, int ch);
+} RenesasTimerBaseClass;
+
+typedef struct RenesasCMTClass {
+    RenesasTimerBaseClass parent;
+} RenesasCMTClass;
+
+typedef struct RenesasTMUClass {
+    RenesasTimerBaseClass parent;
+    void (*p_update_clk)(RenesasTimerBaseState *tmr, int ch);
+} RenesasTMUClass;
+
+#endif
hw/timer/renesas_timer.c new file +644 -0

644 lines not on this page · raw message

hw/timer/Kconfig +3 -0
index bac2511715..347add12dd 100644
@@ -54,3 +54,6 @@ config SSE_TIMER
 
 config AVR_TIMER16
     bool
+
+config RENESAS_TIMER
+    bool
hw/timer/meson.build +1 -0
index 157f540ecd..9019dce993 100644
@@ -33,5 +33,6 @@ 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'))
 softmmu_ss.add(when: 'CONFIG_STM32F2XX_TIMER', if_true: files('stm32f2xx_timer.c'))
 softmmu_ss.add(when: 'CONFIG_XILINX', if_true: files('xilinx_timer.c'))
+softmmu_ss.add(when: 'CONFIG_RENESAS_TIMER', if_true: files('renesas_timer.c'))
 
 specific_ss.add(when: 'CONFIG_AVR_TIMER16', if_true: files('avr_timer16.c'))
Signature · 1 line
2.20.1
#11 lore raw

PATCH 4/11 hw/timer: Remove sh_timer.

In reply to Yoshinori Sato

Migrate to renesas_timer.

---
 include/hw/timer/tmu012.h |  23 ---
 hw/timer/sh_timer.c       | 368 --------------------------------------
 MAINTAINERS               |   4 +-
 hw/timer/Kconfig          |   4 -
 hw/timer/meson.build      |   1 -
 5 files changed, 2 insertions(+), 398 deletions(-)
 delete mode 100644 include/hw/timer/tmu012.h
 delete mode 100644 hw/timer/sh_timer.c
include/hw/timer/tmu012.h deleted +0 -23
deleted file mode 100644
index 808ed8de1d..0000000000
@@ -1,23 +0,0 @@
-/*
- * SuperH Timer
- *
- * Copyright (c) 2007 Magnus Damm
- *
- * This code is licensed under the GPL.
- */
-
-#ifndef HW_TIMER_TMU012_H
-#define HW_TIMER_TMU012_H
-
-#include "exec/hwaddr.h"
-
-#define TMU012_FEAT_TOCR   (1 << 0)
-#define TMU012_FEAT_3CHAN  (1 << 1)
-#define TMU012_FEAT_EXTCLK (1 << 2)
-
-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);
-
-#endif
hw/timer/sh_timer.c deleted +0 -368

368 lines not on this page · raw message

MAINTAINERS +2 -2
index ecfa97cefa..4e41c3ff91 100644
@@ -1414,7 +1414,7 @@ F: hw/char/renesas_sci.c
 F: hw/sh4/r2d.c
 F: hw/intc/sh_intc.c
 F: hw/pci-host/sh_pci.c
-F: hw/timer/sh_timer.c
+F: hw/timer/renesas_timer.c
 F: include/hw/sh4/sh_intc.h
 
 Shix
@@ -1425,7 +1425,7 @@ F: hw/block/tc58128.c
 F: hw/char/reness_sci.c
 F: hw/sh4/shix.c
 F: hw/intc/sh_intc.c
-F: hw/timer/sh_timer.c
+F: hw/timer/renesas_timer.c
 F: include/hw/sh4/sh_intc.h
 
 SPARC Machines
hw/timer/Kconfig +0 -4
index 347add12dd..ec19708a4d 100644
@@ -36,10 +36,6 @@ config CMSDK_APB_DUALTIMER
     bool
     select PTIMER
 
-config SH_TIMER
-    bool
-    select PTIMER
-
 config RENESAS_TMR
     bool
 
hw/timer/meson.build +0 -1
index 9019dce993..ec70821c0b 100644
@@ -27,7 +27,6 @@ softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_gptimer.c'))
 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.20.1
#12 lore raw

PATCH 5/11 hw/timer: Remove renesas_cmt.

In reply to Yoshinori Sato

Migrate to renesas_timer.

---
 include/hw/timer/renesas_cmt.h |  43 -----
 hw/timer/renesas_cmt.c         | 283 ---------------------------------
 hw/timer/meson.build           |   1 -
 3 files changed, 327 deletions(-)
 delete mode 100644 include/hw/timer/renesas_cmt.h
 delete mode 100644 hw/timer/renesas_cmt.c
include/hw/timer/renesas_cmt.h deleted +0 -43
deleted file mode 100644
index 1c0b65c1d5..0000000000
@@ -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
hw/timer/renesas_cmt.c deleted +0 -283

283 lines not on this page · raw message

hw/timer/meson.build +0 -1
index ec70821c0b..03b40cfbee 100644
@@ -9,7 +9,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.20.1
#13 lore raw

PATCH 6/11 hw/rx: Add RX62N Clock generator

In reply to Yoshinori Sato

This module generated core and peripheral clock.

---
 include/hw/rx/rx62n-cpg.h |  72 ++++++++
 include/hw/rx/rx62n.h     |   8 +-
 hw/rx/rx62n-cpg.c         | 344 ++++++++++++++++++++++++++++++++++++++
 hw/rx/rx62n.c             |  39 +++--
 hw/rx/meson.build         |   2 +-
 5 files changed, 449 insertions(+), 16 deletions(-)
 create mode 100644 include/hw/rx/rx62n-cpg.h
 create mode 100644 hw/rx/rx62n-cpg.c
include/hw/rx/rx62n-cpg.h new file +72 -0
new file mode 100644
index 0000000000..d90a067313
@@ -0,0 +1,72 @@
+/*
+ * RX62N Clock generator circuit
+ *
+ * Datasheet: RX62N Group, RX621 Group User's Manual: Hardware
+ * (Rev.1.40 R01UH0033EJ0140)
+ *
+ * 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/>.
+ */
+
+#ifndef HW_RX_RX62N_CPG_H
+#define HW_RX_RX62N_CPG_H
+
+#include "hw/sysbus.h"
+#include "hw/qdev-clock.h"
+
+#define TYPE_RX62N_CPG "rx62n-cpg"
+#define RX62NCPG(obj) OBJECT_CHECK(RX62NCPGState, (obj), TYPE_RX62N_CPG)
+
+enum {
+    CK_TMR8_1,
+    CK_TMR8_0,
+    CK_MTU_1,
+    CK_MTU_0,
+    CK_CMT_1,
+    CK_CMT_0,
+    CK_EDMAC,
+    CK_SCI6,
+    CK_SCI5,
+    CK_SCI3,
+    CK_SCI2,
+    CK_SCI1,
+    CK_SCI0,
+    NUM_SUBCLOCK,
+};
+
+typedef struct RX62NCPGState {
+    SysBusDevice parent_obj;
+    uint32_t mstpcr[3];
+    uint32_t sckcr;
+    uint8_t  bckcr;
+    uint8_t  ostdcr;
+
+    int ick;
+    Clock *clk_ick;
+    int bck;
+    Clock *clk_bck;
+    int pck;
+    Clock *clk_pck;
+    Clock *dev_clocks[NUM_SUBCLOCK];
+    uint32_t xtal_freq_hz;
+    MemoryRegion memory;
+} RX62NCPGState;
+
+typedef struct RX62NCPGClass {
+    SysBusDeviceClass parent;
+} RX62NCPGClass;
+
+#define OSTDCR_KEY 0xac
+
+#endif
include/hw/rx/rx62n.h +4 -4
index 3ed80dba0d..44f5fcc74d 100644
@@ -29,6 +29,7 @@
 #include "hw/timer/renesas_tmr.h"
 #include "hw/timer/renesas_cmt.h"
 #include "hw/char/renesas_sci.h"
+#include "hw/rx/rx62n-cpg.h"
 #include "qemu/units.h"
 #include "qom/object.h"
 
@@ -58,9 +59,9 @@ struct RX62NState {
     RTMRState tmr[RX62N_NR_TMR];
     RCMTState cmt[RX62N_NR_CMT];
     RSCIState sci[RX62N_NR_SCI];
+    RX62NCPGState cpg;
 
     MemoryRegion *sysmem;
-    bool kernel;
 
     MemoryRegion iram;
     MemoryRegion iomem1;
@@ -72,8 +73,7 @@ struct RX62NState {
 
     /* Input Clock (XTAL) frequency */
     uint32_t xtal_freq_hz;
-    /* Peripheral Module Clock frequency */
-    uint32_t pclk_freq_hz;
-};
+} RX62NState;
+
 
 #endif
hw/rx/rx62n-cpg.c new file +344 -0

344 lines not on this page · raw message

hw/rx/rx62n.c +28 -11
index fa5add9f9d..cfd41930bf 100644
@@ -45,6 +45,7 @@
 #define RX62N_TMR_BASE  0x00088200
 #define RX62N_CMT_BASE  0x00088000
 #define RX62N_SCI_BASE  0x00088240
+#define RX62N_CPG_BASE  0x00080010
 
 /*
  * RX62N Peripheral IRQ
@@ -56,7 +57,6 @@
 
 #define RX62N_XTAL_MIN_HZ  (8 * 1000 * 1000)
 #define RX62N_XTAL_MAX_HZ (14 * 1000 * 1000)
-#define RX62N_PCLK_MAX_HZ (50 * 1000 * 1000)
 
 struct RX62NClass {
     /*< private >*/
@@ -161,36 +161,45 @@ static void register_tmr(RX62NState *s, int unit)
 {
     SysBusDevice *tmr;
     int i, irqbase;
+    char ckname[16];
 
     object_initialize_child(OBJECT(s), "tmr[*]",
                             &s->tmr[unit], TYPE_RENESAS_TMR);
     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++) {
         sysbus_connect_irq(tmr, i, s->irq[irqbase + i]);
     }
     sysbus_mmio_map(tmr, 0, RX62N_TMR_BASE + unit * 0x10);
+
+    qdev_prop_set_uint32(DEVICE(tmr), "unit", unit);
+    sysbus_realize(tmr, &error_abort);
+    snprintf(ckname, sizeof(ckname), "pck_tmr8-%d", unit);
+    qdev_connect_clock_in(DEVICE(tmr), "pck",
+                          qdev_get_clock_out(DEVICE(&s->cpg), ckname));
 }
 
 static void register_cmt(RX62NState *s, int unit)
 {
     SysBusDevice *cmt;
     int i, irqbase;
+    char ckname[16];
 
     object_initialize_child(OBJECT(s), "cmt[*]",
                             &s->cmt[unit], TYPE_RENESAS_CMT);
     cmt = SYS_BUS_DEVICE(&s->cmt[unit]);
-    qdev_prop_set_uint64(DEVICE(cmt), "input-freq", s->pclk_freq_hz);
-    sysbus_realize(cmt, &error_abort);
+    qdev_prop_set_uint32(DEVICE(cmt), "unit", unit);
 
     irqbase = RX62N_CMT_IRQ + CMT_NR_IRQ * unit;
     for (i = 0; i < CMT_NR_IRQ; i++) {
         sysbus_connect_irq(cmt, i, s->irq[irqbase + i]);
     }
     sysbus_mmio_map(cmt, 0, RX62N_CMT_BASE + unit * 0x10);
+    sysbus_realize(cmt, &error_abort);
+    snprintf(ckname, sizeof(ckname), "pck_cmt-%d", unit);
+    qdev_connect_clock_in(DEVICE(cmt), "pck",
+                          qdev_get_clock_out(DEVICE(&s->cpg), ckname));
 }
 
 static void register_sci(RX62NState *s, int unit)
@@ -202,7 +211,6 @@ static void register_sci(RX62NState *s, int unit)
                             &s->sci[unit], TYPE_RENESAS_SCI);
     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", s->pclk_freq_hz);
     sysbus_realize(sci, &error_abort);
 
     irqbase = RX62N_SCI_IRQ + SCI_NR_IRQ * unit;
@@ -212,6 +220,18 @@ static void register_sci(RX62NState *s, int unit)
     sysbus_mmio_map(sci, 0, RX62N_SCI_BASE + unit * 0x08);
 }
 
+static void register_cpg(RX62NState *s)
+{
+    SysBusDevice *cpg;
+
+    object_initialize_child(OBJECT(s), "rx62n-cpg", &s->cpg,
+                            TYPE_RX62N_CPG);
+    cpg = SYS_BUS_DEVICE(&s->cpg);
+    qdev_prop_set_uint64(DEVICE(cpg), "xtal-frequency-hz", s->xtal_freq_hz);
+
+    sysbus_mmio_map(cpg, 0, RX62N_CPG_BASE);
+}
+
 static void rx62n_realize(DeviceState *dev, Error **errp)
 {
     RX62NState *s = RX62N_MCU(dev);
@@ -227,11 +247,6 @@ static void rx62n_realize(DeviceState *dev, Error **errp)
         error_setg(errp, "\"xtal-frequency-hz\" property in incorrect range.");
         return;
     }
-    /* Use a 4x fixed multiplier */
-    s->pclk_freq_hz = 4 * s->xtal_freq_hz;
-    /* PCLK range: 8-50 MHz */
-    assert(s->pclk_freq_hz <= RX62N_PCLK_MAX_HZ);
-
     memory_region_init_ram(&s->iram, OBJECT(dev), "iram",
                            rxc->ram_size, &error_abort);
     memory_region_add_subregion(s->sysmem, RX62N_IRAM_BASE, &s->iram);
@@ -248,11 +263,13 @@ static void rx62n_realize(DeviceState *dev, Error **errp)
 
     register_icu(s);
     s->cpu.env.ack = qdev_get_gpio_in_named(DEVICE(&s->icu), "ack", 0);
+    register_cpg(s);
     register_tmr(s, 0);
     register_tmr(s, 1);
     register_cmt(s, 0);
     register_cmt(s, 1);
     register_sci(s, 0);
+    sysbus_realize(SYS_BUS_DEVICE(&s->cpg), &error_abort);
 }
 
 static Property rx62n_properties[] = {
hw/rx/meson.build +1 -1
index d223512a78..e1c5278b6f 100644
@@ -1,5 +1,5 @@
 rx_ss = ss.source_set()
 rx_ss.add(when: 'CONFIG_RX_GDBSIM', if_true: files('rx-gdbsim.c'))
-rx_ss.add(when: 'CONFIG_RX62N_MCU', if_true: files('rx62n.c'))
+rx_ss.add(when: 'CONFIG_RX62N_MCU', if_true: files('rx62n.c', 'rx62n-cpg.c'))
 
 hw_arch += {'rx': rx_ss}
Signature · 1 line
2.20.1
#14 lore raw

PATCH 7/11 hw/timer: Renesas 8bit timer.

In reply to Yoshinori Sato

Rewrite timer api.

---
 include/hw/timer/renesas_tmr.h  |  58 ----
 include/hw/timer/renesas_tmr8.h |  67 ++++
 hw/timer/renesas_tmr.c          | 493 -----------------------------
 hw/timer/renesas_tmr8.c         | 540 ++++++++++++++++++++++++++++++++
 hw/timer/Kconfig                |   5 +-
 hw/timer/meson.build            |   2 +-
 6 files changed, 609 insertions(+), 556 deletions(-)
 delete mode 100644 include/hw/timer/renesas_tmr.h
 create mode 100644 include/hw/timer/renesas_tmr8.h
 delete mode 100644 hw/timer/renesas_tmr.c
 create mode 100644 hw/timer/renesas_tmr8.c
include/hw/timer/renesas_tmr.h deleted +0 -58
deleted file mode 100644
index caf7eec0dc..0000000000
@@ -1,58 +0,0 @@
-/*
- * Renesas 8bit timer Object
- *
- * Copyright (c) 2018 Yoshinori Sato
- *
- * SPDX-License-Identifier: GPL-2.0-or-later
- */
-
-#ifndef HW_TIMER_RENESAS_TMR_H
-#define HW_TIMER_RENESAS_TMR_H
-
-#include "qemu/timer.h"
-#include "hw/sysbus.h"
-#include "qom/object.h"
-
-#define TYPE_RENESAS_TMR "renesas-tmr"
-typedef struct RTMRState RTMRState;
-DECLARE_INSTANCE_CHECKER(RTMRState, RTMR,
-                         TYPE_RENESAS_TMR)
-
-enum timer_event {
-    cmia = 0,
-    cmib = 1,
-    ovi = 2,
-    none = 3,
-    TMR_NR_EVENTS = 4
-};
-
-enum {
-    TMR_CH = 2,
-    TMR_NR_IRQ = 3 * TMR_CH
-};
-
-struct RTMRState {
-    /*< private >*/
-    SysBusDevice parent_obj;
-    /*< public >*/
-
-    uint64_t input_freq;
-    MemoryRegion memory;
-
-    int64_t tick;
-    uint8_t tcnt[TMR_CH];
-    uint8_t tcora[TMR_CH];
-    uint8_t tcorb[TMR_CH];
-    uint8_t tcr[TMR_CH];
-    uint8_t tccr[TMR_CH];
-    uint8_t tcor[TMR_CH];
-    uint8_t tcsr[TMR_CH];
-    int64_t div_round[TMR_CH];
-    uint8_t next[TMR_CH];
-    qemu_irq cmia[TMR_CH];
-    qemu_irq cmib[TMR_CH];
-    qemu_irq ovi[TMR_CH];
-    QEMUTimer timer[TMR_CH];
-};
-
-#endif
include/hw/timer/renesas_tmr8.h new file +67 -0

67 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/renesas_tmr8.c new file +540 -0

540 lines not on this page · raw message

hw/timer/Kconfig +1 -4
index ec19708a4d..6aee6f8a13 100644
@@ -36,10 +36,7 @@ config CMSDK_APB_DUALTIMER
     bool
     select PTIMER
 
-config RENESAS_TMR
-    bool
-
-config RENESAS_CMT
+config RENESAS_TMR8
     bool
 
 config SSE_COUNTER
hw/timer/meson.build +1 -1
index 03b40cfbee..0b4e8850ed 100644
@@ -8,7 +8,7 @@ softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_timer.c'))
 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_TMR8', if_true: files('renesas_tmr8.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.20.1
#15 lore raw

Re: [PATCH 07/11] hw/timer: Renesas 8bit timer.

Quoted 17 lines · Yoshinori Sato

Rewrite timer api.

---
 include/hw/timer/renesas_tmr.h  |  58 ----
 include/hw/timer/renesas_tmr8.h |  67 ++++
 hw/timer/renesas_tmr.c          | 493 -----------------------------
 hw/timer/renesas_tmr8.c         | 540 ++++++++++++++++++++++++++++++++
 hw/timer/Kconfig                |   5 +-
 hw/timer/meson.build            |   2 +-
 6 files changed, 609 insertions(+), 556 deletions(-)
 delete mode 100644 include/hw/timer/renesas_tmr.h
 create mode 100644 include/hw/timer/renesas_tmr8.h
 delete mode 100644 hw/timer/renesas_tmr.c
 create mode 100644 hw/timer/renesas_tmr8.c

hw/timer/renesas_tmr8.c line 514

Quoted 8 lines
hw/timer/renesas_tmr8.c new file +8 -0
+static const VMStateDescription vmstate_rtmr = {
+    .name = "renesas-8tmr",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields = (VMStateField[]) {
+        VMSTATE_END_OF_LIST()
+    }
+};

This seems to be missing the fields for the actual state ?

More generally, complete rewrites of devices are a pain to code review. Could this be structured as incremental improvements to the existing code ?

thanks
-- PMM

#16 lore raw

PATCH 8/11 hw/rx: rx62n use new hw modules.

In reply to Yoshinori Sato
---
 include/hw/rx/rx62n.h | 10 +++++-----
 hw/rx/rx62n.c         | 18 ++++++++++++------
 hw/rx/Kconfig         |  4 ++--
 3 files changed, 19 insertions(+), 13 deletions(-)
include/hw/rx/rx62n.h +5 -5
index 44f5fcc74d..942ed0639f 100644
@@ -26,8 +26,8 @@
 
 #include "target/rx/cpu.h"
 #include "hw/intc/rx_icu.h"
-#include "hw/timer/renesas_tmr.h"
-#include "hw/timer/renesas_cmt.h"
+#include "hw/timer/renesas_tmr8.h"
+#include "hw/timer/renesas_timer.h"
 #include "hw/char/renesas_sci.h"
 #include "hw/rx/rx62n-cpg.h"
 #include "qemu/units.h"
@@ -56,9 +56,9 @@ struct RX62NState {
 
     RXCPU cpu;
     RXICUState icu;
-    RTMRState tmr[RX62N_NR_TMR];
-    RCMTState cmt[RX62N_NR_CMT];
-    RSCIState sci[RX62N_NR_SCI];
+    RenesasTMR8State tmr[RX62N_NR_TMR];
+    RenesasCMTState cmt[RX62N_NR_CMT];
+    RenesasSCIState sci[RX62N_NR_SCI];
     RX62NCPGState cpg;
 
     MemoryRegion *sysmem;
hw/rx/rx62n.c +12 -6
index cfd41930bf..58eff0b4a3 100644
@@ -164,7 +164,7 @@ static void register_tmr(RX62NState *s, int unit)
     char ckname[16];
 
     object_initialize_child(OBJECT(s), "tmr[*]",
-                            &s->tmr[unit], TYPE_RENESAS_TMR);
+                            &s->tmr[unit], TYPE_RENESAS_TMR8);
     tmr = SYS_BUS_DEVICE(&s->tmr[unit]);
 
     irqbase = RX62N_TMR_IRQ + TMR_NR_IRQ * unit;
@@ -174,10 +174,10 @@ static void register_tmr(RX62NState *s, int unit)
     sysbus_mmio_map(tmr, 0, RX62N_TMR_BASE + unit * 0x10);
 
     qdev_prop_set_uint32(DEVICE(tmr), "unit", unit);
-    sysbus_realize(tmr, &error_abort);
     snprintf(ckname, sizeof(ckname), "pck_tmr8-%d", unit);
     qdev_connect_clock_in(DEVICE(tmr), "pck",
                           qdev_get_clock_out(DEVICE(&s->cpg), ckname));
+    sysbus_realize(tmr, &error_abort);
 }
 
 static void register_cmt(RX62NState *s, int unit)
@@ -190,6 +190,9 @@ static void register_cmt(RX62NState *s, int unit)
                             &s->cmt[unit], TYPE_RENESAS_CMT);
     cmt = SYS_BUS_DEVICE(&s->cmt[unit]);
     qdev_prop_set_uint32(DEVICE(cmt), "unit", unit);
+    snprintf(ckname, sizeof(ckname), "pck_cmt-%d", unit);
+    qdev_connect_clock_in(DEVICE(cmt), "pck",
+                          qdev_get_clock_out(DEVICE(&s->cpg), ckname));
 
     irqbase = RX62N_CMT_IRQ + CMT_NR_IRQ * unit;
     for (i = 0; i < CMT_NR_IRQ; i++) {
@@ -197,20 +200,23 @@ static void register_cmt(RX62NState *s, int unit)
     }
     sysbus_mmio_map(cmt, 0, RX62N_CMT_BASE + unit * 0x10);
     sysbus_realize(cmt, &error_abort);
-    snprintf(ckname, sizeof(ckname), "pck_cmt-%d", unit);
-    qdev_connect_clock_in(DEVICE(cmt), "pck",
-                          qdev_get_clock_out(DEVICE(&s->cpg), ckname));
 }
 
 static void register_sci(RX62NState *s, int unit)
 {
     SysBusDevice *sci;
     int i, irqbase;
+    char ckname[16];
 
     object_initialize_child(OBJECT(s), "sci[*]",
-                            &s->sci[unit], TYPE_RENESAS_SCI);
+                            &s->sci[unit], TYPE_RENESAS_SCIA);
     sci = SYS_BUS_DEVICE(&s->sci[unit]);
     qdev_prop_set_chr(DEVICE(sci), "chardev", serial_hd(unit));
+    qdev_prop_set_uint32(DEVICE(sci), "unit", unit);
+    qdev_prop_set_uint32(DEVICE(sci), "register-size", SCI_REGSIZE_8);
+    snprintf(ckname, sizeof(ckname), "pck_sci-%d", unit);
+    qdev_connect_clock_in(DEVICE(sci), "pck",
+                          qdev_get_clock_out(DEVICE(&s->cpg), ckname));
     sysbus_realize(sci, &error_abort);
 
     irqbase = RX62N_SCI_IRQ + SCI_NR_IRQ * unit;
hw/rx/Kconfig +2 -2
index 2b297c5a6a..9cd1082623 100644
@@ -1,8 +1,8 @@
 config RX62N_MCU
     bool
     select RX_ICU
-    select RENESAS_TMR
-    select RENESAS_CMT
+    select RENESAS_TMR8
+    select RENESAS_TIMER
     select RENESAS_SCI
 
 config RX_GDBSIM
Signature · 1 line
2.20.1
#17 lore raw

PATCH 9/11 hw/sh4: sh7750 Add CPG.

In reply to Yoshinori Sato

CPG required new hw modules.

---
 include/hw/sh4/sh7751-cpg.h |  94 ++++++++
 hw/sh4/sh7750.c             |  25 ++
 hw/sh4/sh7751-cpg.c         | 457 ++++++++++++++++++++++++++++++++++++
 hw/sh4/meson.build          |   1 +
 4 files changed, 577 insertions(+)
 create mode 100644 include/hw/sh4/sh7751-cpg.h
 create mode 100644 hw/sh4/sh7751-cpg.c
include/hw/sh4/sh7751-cpg.h new file +94 -0
new file mode 100644
index 0000000000..79f9abe210
@@ -0,0 +1,94 @@
+/*
+ * SH7751(R) Clock generator circuit
+ *
+ * Datasheet: 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/>.
+ */
+
+#ifndef HW_SH4_SH7751_CPG_H
+#define HW_SH4_SH7751_CPG_H
+
+#include "hw/sysbus.h"
+#include "hw/qdev-clock.h"
+
+#define TYPE_SH7751_CPG_BASE "sh7751-cpg-base"
+#define SH7751CPGBase(obj) \
+    OBJECT_CHECK(SH7751CPGBaseState, (obj), TYPE_SH7751_CPG_BASE)
+#define TYPE_SH7751_CPG "sh7751-cpg"
+#define SH7751CPG(obj) OBJECT_CHECK(SH7751CPGState, (obj), TYPE_SH7751_CPG)
+#define TYPE_SH7751R_CPG "sh7751r-cpg"
+#define SH7751RCPG(obj) OBJECT_CHECK(SH7751RCPGState, (obj), TYPE_SH7751R_CPG)
+#define SH7751CPG_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(SH7751CPGBaseClass, obj, TYPE_SH7751_CPG_BASE)
+#define SH7751CPGBaseClass(klass) \
+    OBJECT_CLASS_CHECK(SH7751CPGBaseClass, klass, TYPE_SH7751_CPG_BASE)
+
+enum {
+    CK_DMAC,
+    CK_SCIF,
+    CK_TMU_0,
+    CK_RTC,
+    CK_SCI,
+    CK_SQ,
+    CK_UBC,
+    CK_PCIC,
+    CK_TMU_1,
+    CK_INTC,
+    NUM_SUBCLOCK,
+};
+
+typedef struct SH7751CPGBaseState {
+    SysBusDevice parent_obj;
+    uint8_t stbcr[2];
+    uint32_t clkstp00;
+    uint16_t freqcr;
+
+    uint32_t clock_mode;
+    int ick;
+    Clock *clk_ick;
+    int bck;
+    Clock *clk_bck;
+    int pck;
+    Clock *clk_pck;
+    Clock *dev_clocks[NUM_SUBCLOCK];
+    uint32_t xtal_freq_hz;
+    MemoryRegion memory[3 * 2];
+} SH7751CPGBaseState;
+
+typedef struct {
+    SH7751CPGBaseState parent_obj;
+} SH7751CPGState;
+
+typedef struct {
+    SH7751CPGBaseState parent_obj;
+} SH7751RCPGState;
+
+typedef struct {
+    SysBusDeviceClass parent;
+    int (*pll1mul)(int mode, uint16_t freqcr);
+    uint16_t *initfreqcr;
+} SH7751CPGBaseClass;
+
+typedef struct {
+    SH7751CPGBaseClass parent;
+} SH7751CPGClass;
+
+typedef struct {
+    SH7751CPGBaseClass parent;
+} SH7751RCPGClass;
+
+#endif
hw/sh4/sh7750.c +25 -0
index d53a436d8c..2f6c382aa6 100644
@@ -24,6 +24,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qapi/error.h"
 #include "hw/irq.h"
 #include "hw/sh4/sh.h"
 #include "sysemu/sysemu.h"
@@ -32,6 +33,8 @@
 #include "hw/sh4/sh_intc.h"
 #include "hw/timer/tmu012.h"
 #include "exec/exec-all.h"
+#include "hw/sh4/sh7751-cpg.h"
+#include "hw/qdev-properties.h"
 
 #define NB_DEVICES 4
 
@@ -752,9 +755,29 @@ static const MemoryRegionOps sh7750_mmct_ops = {
     .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
+static SH7751CPGBaseState *sh_cpg_init(MemoryRegion *sysmem,
+                                      int cputype)
+{
+    const char *cpgtype;
+    SH7751CPGBaseState *cpg;
+    if (cputype & (SH_CPU_SH7750R | SH_CPU_SH7751R)) {
+        cpgtype = TYPE_SH7751R_CPG;
+    } else {
+        cpgtype = TYPE_SH7751_CPG;
+    }
+    cpg = SH7751CPGBase(qdev_new(cpgtype));
+    qdev_prop_set_uint32(DEVICE(cpg), "xtal-frequency-hz", 20 * 1000 * 1000);
+    qdev_prop_set_uint32(DEVICE(cpg), "clock-mode", 5);
+    sysbus_mmio_map(SYS_BUS_DEVICE(cpg), 0, 0x1fc00000);
+    sysbus_mmio_map(SYS_BUS_DEVICE(cpg), 1, P4ADDR(0x1fc00000));
+    sysbus_mmio_map(SYS_BUS_DEVICE(cpg), 2, A7ADDR(0x1fc00000));
+    return cpg;
+}
+
 SH7750State *sh7750_init(SuperHCPU *cpu, MemoryRegion *sysmem)
 {
     SH7750State *s;
+    SH7751CPGBaseState *cpg;
 
     s = g_malloc0(sizeof(SH7750State));
     s->cpu = cpu;
@@ -800,6 +823,7 @@ SH7750State *sh7750_init(SuperHCPU *cpu, MemoryRegion *sysmem)
 
     cpu->env.intc_handle = &s->intc;
 
+    cpg = sh_cpg_init(sysmem, cpu->env.id);
     sh_serial_init(sysmem, 0x1fe00000,
                    0, s->periph_freq, serial_hd(0),
                    s->intc.irqs[SCI1_ERI],
@@ -824,6 +848,7 @@ SH7750State *sh7750_init(SuperHCPU *cpu, MemoryRegion *sysmem)
 		s->intc.irqs[TMU2_TUNI],
 		s->intc.irqs[TMU2_TICPI]);
 
+    sysbus_realize(SYS_BUS_DEVICE(cpg), &error_abort);
     if (cpu->env.id & (SH_CPU_SH7750 | SH_CPU_SH7750S | SH_CPU_SH7751)) {
         sh_intc_register_sources(&s->intc,
 				 _INTC_ARRAY(vectors_dma4),
hw/sh4/sh7751-cpg.c new file +457 -0

457 lines not on this page · raw message

hw/sh4/meson.build +1 -0
index 424d5674de..7ed8246152 100644
@@ -2,6 +2,7 @@ sh4_ss = ss.source_set()
 sh4_ss.add(files(
   'sh7750.c',
   'sh7750_regnames.c',
+  'sh7751-cpg.c',
 ))
 sh4_ss.add(when: 'CONFIG_R2D', if_true: files('r2d.c'))
 sh4_ss.add(when: 'CONFIG_SHIX', if_true: files('shix.c'))
Signature · 1 line
2.20.1
#18 lore raw

PATCH 10/11 hw/sh4: sh7750 use new hw modules.

In reply to Yoshinori Sato
---
 include/hw/sh4/sh.h |  8 -----
 hw/sh4/sh7750.c     | 87 +++++++++++++++++++++++++++++++++++++++------
 hw/sh4/Kconfig      |  4 +--
 3 files changed, 79 insertions(+), 20 deletions(-)
include/hw/sh4/sh.h +0 -8
index becb596979..74e1ba59a8 100644
@@ -55,14 +55,6 @@ int sh7750_register_io_device(struct SH7750State *s,
 
 /* 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 +77 -10

132 lines not on this page · raw message

hw/sh4/Kconfig +2 -2
index ab733a3f76..b2da634d22 100644
@@ -20,5 +20,5 @@ config SHIX
 config SH7750
     bool
     select SH_INTC
-    select SH_SCI
-    select SH_TIMER
+    select RENESAS_TIMER
+    select RENESAS_SCI
Signature · 1 line
2.20.1
#19 lore raw

PATCH 11/11 hw/rx: rx-gdbsim Add bootstrup for linux

In reply to Yoshinori Sato

linux kernel require initializing some peripherals.

---
 include/hw/rx/rx62n.h | 16 ++++----
 hw/rx/rx-gdbsim.c     | 89 +++++++++++++++++++++++++------------------
 hw/rx/rx62n.c         | 15 --------
 3 files changed, 59 insertions(+), 61 deletions(-)
include/hw/rx/rx62n.h +7 -9
index 942ed0639f..3bbeb5da52 100644
@@ -33,14 +33,6 @@
 #include "qemu/units.h"
 #include "qom/object.h"
 
-#define TYPE_RX62N_MCU "rx62n-mcu"
-typedef struct RX62NState RX62NState;
-DECLARE_INSTANCE_CHECKER(RX62NState, RX62N_MCU,
-                         TYPE_RX62N_MCU)
-
-#define TYPE_R5F562N7_MCU "r5f562n7-mcu"
-#define TYPE_R5F562N8_MCU "r5f562n8-mcu"
-
 #define EXT_CS_BASE         0x01000000
 #define VECTOR_TABLE_BASE   0xffffff80
 #define RX62N_CFLASH_BASE   0xfff80000
@@ -49,7 +41,7 @@ DECLARE_INSTANCE_CHECKER(RX62NState, RX62N_MCU,
 #define RX62N_NR_CMT    2
 #define RX62N_NR_SCI    6
 
-struct RX62NState {
+typedef struct RX62NState {
     /*< private >*/
     DeviceState parent_obj;
     /*< public >*/
@@ -75,5 +67,11 @@ struct RX62NState {
     uint32_t xtal_freq_hz;
 } RX62NState;
 
+#define TYPE_RX62N_MCU "rx62n-mcu"
+
+#define TYPE_R5F562N7_MCU "r5f562n7-mcu"
+#define TYPE_R5F562N8_MCU "r5f562n8-mcu"
+DECLARE_INSTANCE_CHECKER(RX62NState, RX62N_MCU,
+                         TYPE_RX62N_MCU)
 
 #endif
hw/rx/rx-gdbsim.c +52 -37

135 lines not on this page · raw message

hw/rx/rx62n.c +0 -15
index 58eff0b4a3..d84ffa148c 100644
@@ -58,20 +58,6 @@
 #define RX62N_XTAL_MIN_HZ  (8 * 1000 * 1000)
 #define RX62N_XTAL_MAX_HZ (14 * 1000 * 1000)
 
-struct RX62NClass {
-    /*< private >*/
-    DeviceClass parent_class;
-    /*< public >*/
-    const char *name;
-    uint64_t ram_size;
-    uint64_t rom_flash_size;
-    uint64_t data_flash_size;
-};
-typedef struct RX62NClass RX62NClass;
-
-DECLARE_CLASS_CHECKERS(RX62NClass, RX62N_MCU,
-                       TYPE_RX62N_MCU)
-
 /*
  * IRQ -> IPR mapping table
  * 0x00 - 0x91: IPR no (IPR00 to IPR91)
@@ -281,7 +267,6 @@ static void rx62n_realize(DeviceState *dev, Error **errp)
 static Property rx62n_properties[] = {
     DEFINE_PROP_LINK("main-bus", RX62NState, sysmem, TYPE_MEMORY_REGION,
                      MemoryRegion *),
-    DEFINE_PROP_BOOL("load-kernel", RX62NState, kernel, false),
     DEFINE_PROP_UINT32("xtal-frequency-hz", RX62NState, xtal_freq_hz, 0),
     DEFINE_PROP_END_OF_LIST(),
 };
Signature · 1 line
2.20.1
#20 lore raw
In reply to Yoshinori Sato
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [PATCH 00/11] Unified peripheral emulation for Renesas chips

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
0d61629 hw/rx: rx-gdbsim Add bootstrup for linux
5595fd4 hw/sh4: sh7750 use new hw modules.
f85d3d2 hw/sh4: sh7750 Add CPG.
9422b37 hw/rx: rx62n use new hw modules.
88d7ca2 hw/timer: Renesas 8bit timer.
afe51ff hw/rx: Add RX62N Clock generator
87c0b3e hw/timer: Remove renesas_cmt.
e0a4816 hw/timer: Remove sh_timer.
0f983ff hw/timer: Renesas TMU/CMT module.
a5ba8bb hw/char: remove sh_serial.
872e5de hw/char: Renesas SCI module.

=== OUTPUT BEGIN ===
1/11 Checking commit 872e5de1daf1 (hw/char: Renesas SCI module.) 2/11 Checking commit a5ba8bb0a18d (hw/char: remove sh_serial.) 3/11 Checking commit 0f983ff94436 (hw/timer: Renesas TMU/CMT module.)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #44:
new file mode 100644

total: 0 errors, 1 warnings, 752 lines checked

Patch 3/11 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
4/11 Checking commit e0a48164d14f (hw/timer: Remove sh_timer.) 5/11 Checking commit 87c0b3e06524 (hw/timer: Remove renesas_cmt.)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #30:
deleted file mode 100644

total: 0 errors, 1 warnings, 7 lines checked

Patch 5/11 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
6/11 Checking commit afe51ff3750d (hw/rx: Add RX62N Clock generator)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #31:
new file mode 100644

total: 0 errors, 1 warnings, 561 lines checked

Patch 6/11 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
7/11 Checking commit 88d7ca270dfb (hw/timer: Renesas 8bit timer.)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #50:
deleted file mode 100644

total: 0 errors, 1 warnings, 626 lines checked

Patch 7/11 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
8/11 Checking commit 9422b37a5c14 (hw/rx: rx62n use new hw modules.) 9/11 Checking commit f85d3d235566 (hw/sh4: sh7750 Add CPG.)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #98:
new file mode 100644

total: 0 errors, 1 warnings, 616 lines checked

Patch 9/11 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
10/11 Checking commit 5595fd490cbc (hw/sh4: sh7750 use new hw modules.)
ERROR: space required before the open parenthesis '('
#88: FILE: hw/sh4/sh7750.c:819:
+ switch(feat) {

ERROR: braces {} are necessary for all arms of this statement #105: FILE: hw/sh4/sh7750.c:836:
+ if (tei_source)
[...]

ERROR: braces {} are necessary for all arms of this statement #107: FILE: hw/sh4/sh7750.c:838:
+ if (bri_source)
[...]

ERROR: code indent should never use tabs
#142: FILE: hw/sh4/sh7750.c:916:
+^I^Is->intc.irqs[TMU2_TICPI], cpg);$

ERROR: code indent should never use tabs
#157: FILE: hw/sh4/sh7750.c:937:
+^I^I NULL, NULL, cpg);$

total: 5 errors, 0 warnings, 153 lines checked

Patch 10/11 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

11/11 Checking commit 0d616299f2f2 (hw/rx: rx-gdbsim Add bootstrup for linux) === OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]