Skip to contentSkip to conversation

renesas_sci update

PATCH In review Yoshinori Sato 3 participants 9 messages Jun 16, 2021 – Jun 30, 2021

lore
Share & tools
lore
#0 lore raw

cover renesas_sci update

Renesas SH/RX have various SCI in serial interface.
The design of sh_serial is old, so I integrate these SCIs with renesas_sci.

Yoshinori Sato (3):
hw/char: renesas_sci: Refactor for merge all SCI variant.. hw/char: renesas_sci Add SCI and SCIF support. hw/sh4: sh7750 using renesas_sci.

 include/hw/char/renesas_sci.h |  117 +++-
 include/hw/rx/rx62n.h         |    2 +-
 include/hw/sh4/sh.h           |    8 -
 hw/char/renesas_sci.c         | 1053 +++++++++++++++++++++++++++------
 hw/rx/rx62n.c                 |    2 +-
 hw/sh4/sh7750.c               |   41 ++
 hw/sh4/Kconfig                |    2 +-
 7 files changed, 1025 insertions(+), 200 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/3 hw/char: renesas_sci: Refactor for merge all SCI variant..

In order to handle unified all of the SCI, SCIa and SCIF in one part, to separate the transmission and reception portion and a register portion.

RenesasSCIBase - common registers operation and event handling. RenesasSCIA - SCIa specific reigisters / functions.

---
 include/hw/char/renesas_sci.h |  80 ++++-
 include/hw/rx/rx62n.h         |   2 +-
 hw/char/renesas_sci.c         | 568 +++++++++++++++++++++++-----------
 hw/rx/rx62n.c                 |   2 +-
 4 files changed, 457 insertions(+), 195 deletions(-)
include/hw/char/renesas_sci.h +63 -17
index a4764e3eee..c666cf81d1 100644
@@ -1,7 +1,7 @@
 /*
  * Renesas Serial Communication Interface
  *
- * Copyright (c) 2018 Yoshinori Sato
+ * Copyright (c) 2020 Yoshinori Sato
  *
  * SPDX-License-Identifier: GPL-2.0-or-later
  */
@@ -10,45 +10,91 @@
 #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 "renesas-sci"
-typedef struct RSCIState RSCIState;
-DECLARE_INSTANCE_CHECKER(RSCIState, RSCI,
-                         TYPE_RENESAS_SCI)
+#define TYPE_RENESAS_SCI_BASE "renesas-sci-base"
+#define TYPE_RENESAS_SCIA "renesas-scia"
+
+OBJECT_DECLARE_TYPE(RenesasSCIBaseState, RenesasSCIBaseClass,
+                    RENESAS_SCI_BASE)
+OBJECT_DECLARE_TYPE(RenesasSCIAState, RenesasSCIAClass,
+                    RENESAS_SCIA)
 
 enum {
     ERI = 0,
     RXI = 1,
     TXI = 2,
-    TEI = 3,
-    SCI_NR_IRQ = 4
+    BRI_TEI = 3,
+    SCI_NR_IRQ = 4,
+};
+
+enum {
+    RXNEXT,
+    TXEMPTY,
+    TXEND,
+    NR_SCI_EVENT,
 };
 
-struct RSCIState {
+enum {
+    SCI_REGWIDTH_8 = 8,
+    SCI_REGWIDTH_16 = 16,
+    SCI_REGWIDTH_32 = 32,
+};
+
+typedef struct RenesasSCIBaseState {
     /*< private >*/
     SysBusDevice parent_obj;
-    /*< public >*/
 
     MemoryRegion memory;
-    QEMUTimer timer;
+    QEMUTimer *event_timer;
+
+    /*< public >*/
+    uint64_t input_freq;
+    int64_t etu;
+    int64_t trtime;
+    int64_t tx_start_time;
+    Fifo8 rxfifo;
+    int regshift;
+    uint32_t unit;
     CharBackend chr;
     qemu_irq irq[SCI_NR_IRQ];
+    struct {
+        int64_t time;
+        int64_t (*handler)(struct RenesasSCIBaseState *sci);
+    } event[NR_SCI_EVENT];
 
+    /* common SCI register */
     uint8_t smr;
     uint8_t brr;
     uint8_t scr;
     uint8_t tdr;
-    uint8_t ssr;
-    uint8_t rdr;
+    uint16_t Xsr;
+} RenesasSCIBaseState;
+
+struct RenesasSCIAState {
+    RenesasSCIBaseState parent_obj;
+
+    /* SCIa specific register */
     uint8_t scmr;
     uint8_t semr;
-
-    uint8_t read_ssr;
-    int64_t trtime;
-    int64_t rx_next;
-    uint64_t input_freq;
 };
 
+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 RenesasSCIAClass {
+    RenesasSCIBaseClass parent;
+
+    void (*p_irq_fn)(struct RenesasSCIBaseState *sci, int request);
+    int (*p_divrate)(struct RenesasSCIBaseState *sci);
+} RenesasSCIAClass;
+
 #endif
include/hw/rx/rx62n.h +1 -1
index 3ed80dba0d..d6e6e168f9 100644
@@ -57,7 +57,7 @@ struct RX62NState {
     RXICUState icu;
     RTMRState tmr[RX62N_NR_TMR];
     RCMTState cmt[RX62N_NR_CMT];
-    RSCIState sci[RX62N_NR_SCI];
+    RenesasSCIAState sci[RX62N_NR_SCI];
 
     MemoryRegion *sysmem;
     bool kernel;
hw/char/renesas_sci.c +392 -176

726 lines not on this page · raw message

hw/rx/rx62n.c +1 -1
index fa5add9f9d..32c44ead1f 100644
@@ -199,7 +199,7 @@ static void register_sci(RX62NState *s, int unit)
     int i, irqbase;
 
     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_uint64(DEVICE(sci), "input-freq", s->pclk_freq_hz);
Signature · 1 line
2.20.1
#2 lore raw

Re: [PATCH 1/3] hw/char: renesas_sci: Refactor for merge all SCI variant..

Quoted 7 lines · Yoshinori Sato

In order to handle unified all of the SCI, SCIa and SCIF in one part, to separate the transmission and reception portion and a register portion.

RenesasSCIBase - common registers operation and event handling. RenesasSCIA - SCIa specific reigisters / functions.

Quoted 7 lines
---
 include/hw/char/renesas_sci.h |  80 ++++-
 include/hw/rx/rx62n.h         |   2 +-
 hw/char/renesas_sci.c         | 568 +++++++++++++++++++++++-----------
 hw/rx/rx62n.c                 |   2 +-
 4 files changed, 457 insertions(+), 195 deletions(-)

I'm not going to ask you to split it up any further, but this patch was really painful to review because it's making so many changes which are changing multiple different things at once (which is part of why I've been putting it off for two weeks). It should probably have been at least four or five different patches. For future contributions, if you make them as more, smaller, self-contained commits as you go along they will likely be much easier to review. (Personally I find that writing them that way to start with is much easier than trying to split up a larger commit afterwards.)

Quoted 12 lines
include/hw/char/renesas_sci.h +6 -2
+typedef struct RenesasSCIBaseState {
     /*< private >*/
     SysBusDevice parent_obj;
-    /*< public >*/
 
     MemoryRegion memory;
-    QEMUTimer timer;
+    QEMUTimer *event_timer;
+
+    /*< public >*/
+    uint64_t input_freq;
+    int64_t etu;

include/hw/char/renesas_sci.h line 66

Quoted 10 lines
include/hw/char/renesas_sci.h +8 -0
+    int64_t trtime;
+    int64_t tx_start_time;
+    Fifo8 rxfifo;
+    int regshift;
+    uint32_t unit;
     CharBackend chr;
     qemu_irq irq[SCI_NR_IRQ];
+    struct {
+        int64_t time;
+        int64_t (*handler)(struct RenesasSCIBaseState *sci);

At least in this series, these handler function pointers seem to be set in the device init function and never changed. Could they be pointers in the class struct instead ?

Quoted 28 lines
include/hw/char/renesas_sci.h +12 -7
+    } event[NR_SCI_EVENT];
 
+    /* common SCI register */
     uint8_t smr;
     uint8_t brr;
     uint8_t scr;
     uint8_t tdr;
-    uint8_t ssr;
-    uint8_t rdr;
+    uint16_t Xsr;
+} RenesasSCIBaseState;
+
+struct RenesasSCIAState {
+    RenesasSCIBaseState parent_obj;
+
+    /* SCIa specific register */
     uint8_t scmr;
     uint8_t semr;
-
-    uint8_t read_ssr;
-    int64_t trtime;
-    int64_t rx_next;
-    uint64_t input_freq;
 };
 
+typedef struct RenesasSCIBaseClass {
+    SysBusDeviceClass parent;
+

include/hw/char/renesas_sci.h line 97

Quoted 10 lines
include/hw/char/renesas_sci.h +10 -0
+    const struct MemoryRegionOps *ops;
+    void (*irq_fn)(struct RenesasSCIBaseState *sci, int request);
+    int (*divrate)(struct RenesasSCIBaseState *sci);
+} RenesasSCIBaseClass;
+
+typedef struct RenesasSCIAClass {
+    RenesasSCIBaseClass parent;
+
+    void (*p_irq_fn)(struct RenesasSCIBaseState *sci, int request);
+    int (*p_divrate)(struct RenesasSCIBaseState *sci);

These two fields seem to never be used. (If they can be removed, then you don't need a class struct at all for RenesasSCIA.)

Quoted 56 lines
include/hw/char/renesas_sci.h +2 -0
+} RenesasSCIAClass;
+
 #endif
include/hw/rx/rx62n.h +1 -1
index 3ed80dba0d..d6e6e168f9 100644
@@ -57,7 +57,7 @@ struct RX62NState {
     RXICUState icu;
     RTMRState tmr[RX62N_NR_TMR];
     RCMTState cmt[RX62N_NR_CMT];
-    RSCIState sci[RX62N_NR_SCI];
+    RenesasSCIAState sci[RX62N_NR_SCI];
 
     MemoryRegion *sysmem;
     bool kernel;
hw/char/renesas_sci.c +11 -4
index 1c63467290..c1126b7817 100644
@@ -4,7 +4,7 @@
  * Datasheet: RX62N Group, RX621 Group User's Manual: Hardware
  *            (Rev.1.40 R01UH0033EJ0140)
  *
- * Copyright (c) 2019 Yoshinori Sato
+ * Copyright (c) 2020 Yoshinori Sato
  *
  * SPDX-License-Identifier: GPL-2.0-or-later
  *
@@ -23,15 +23,22 @@
 
 #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/qdev-properties-system.h"
 #include "hw/char/renesas_sci.h"
 #include "migration/vmstate.h"
+#include "qemu/error-report.h"
 
-/* SCI register map */
-REG8(SMR, 0)
+/*
+ * SCI register map
+ * SCI(a) register size all 8bit.
+ */
+REG32(SMR, 0) /* 8bit */
   FIELD(SMR, CKS,  0, 2)
   FIELD(SMR, MP,   2, 1)
   FIELD(SMR, STOP, 3, 1)

hw/char/renesas_sci.c REG8(SMR, 0) · line 51

Quoted 9 lines
hw/char/renesas_sci.c +3 -3
@@ -39,263 +46,447 @@ REG8(SMR, 0)
   FIELD(SMR, PE,   5, 1)
   FIELD(SMR, CHR,  6, 1)
   FIELD(SMR, CM,   7, 1)
-REG8(BRR, 1)
-REG8(SCR, 2)
-  FIELD(SCR, CKE,  0, 2)
+REG32(BRR, 4) /* 8bit */
+REG32(SCR, 8)
+  FIELD(SCR, CKE, 0, 2)

This is an unnecessary whitespace change. In the old code, these FIELD() macro lines have been set up so that the bitnumber arguments align. I don't have a strong opinion on whether that's better or worse than just having one space after every comma. But if you want to change it then please:
(1) do that change in its own patch
(2) do it consistently -- here you have changed CKE but left RE, TE, etc alone. Similarly below you change the line for SRR.ERR but leave SRR.MPB alone.

Quoted 48 lines
hw/char/renesas_sci.c +12 -10
   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)
-REG8(TDR, 3)
-REG8(SSR, 4)
+REG32(TDR, 12) /* 8bit */
+REG32(SSR, 16) /* 8bit */
   FIELD(SSR, MPBT, 0, 1)
   FIELD(SSR, MPB,  1, 1)
   FIELD(SSR, TEND, 2, 1)
-  FIELD(SSR, ERR,  3, 3)
+  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)
-REG8(RDR, 5)
-REG8(SCMR, 6)
+REG32(RDR, 20) /* 8bit */
+REG32(SCMR, 24) /* 8bit */
   FIELD(SCMR, SMIF, 0, 1)
   FIELD(SCMR, SINV, 2, 1)
   FIELD(SCMR, SDIR, 3, 1)
   FIELD(SCMR, BCP2, 7, 1)
-REG8(SEMR, 7)
+REG8(SEMR, 28)
   FIELD(SEMR, ACS0, 0, 1)
   FIELD(SEMR, ABCS, 4, 1)
 
 
 
-static void rsci_realize(DeviceState *dev, Error **errp)
+static void rsci_common_realize(DeviceState *dev, Error **errp)
 {
-    RSCIState *sci = RSCI(dev);
+    RenesasSCIBaseState *sci = RENESAS_SCI_BASE(dev);
+    int r;
 
-    if (sci->input_freq == 0) {
+    r = sci->regshift;
+    if ((r % 8) != 0 || ((r / 8) >> 1) > 2) {
         qemu_log_mask(LOG_GUEST_ERROR,
-                      "renesas_sci: input-freq property must be set.");

hw/char/renesas_sci.c REG8(SMR, 0)

Quoted 10 lines
hw/char/renesas_sci.c +6 -2
+                      "renesas_sci: Invalid register size.");
         return;
     }
-    qemu_chr_fe_set_handlers(&sci->chr, can_receive, receive,
-                             sci_event, NULL, sci, NULL, true);
+    sci->regshift = (r / 8) >> 1;
+    sci->smr = sci->scr = 0x00;
+    sci->brr = 0xff;
+    sci->tdr = 0xff;
+    sci->Xsr = 0x84;

realize functions shouldn't generally set state fields like this -- instead that should be done in the device's reset function. (These devices seem to all be missing a reset function.)

Quoted 13 lines
hw/char/renesas_sci.c +2 -3
+    update_trtime(sci);
+
 }
 
 
 static const VMStateDescription vmstate_rsci = {
@@ -303,49 +494,74 @@ static const VMStateDescription vmstate_rsci = {
     .version_id = 1,
     .minimum_version_id = 1,
     .fields = (VMStateField[]) {
-        VMSTATE_INT64(trtime, RSCIState),
-        VMSTATE_INT64(rx_next, RSCIState),
-        VMSTATE_UINT8(smr, RSCIState),

hw/char/renesas_sci.c static const VMStateDescription vmstate_rsci = { · line 497

Quoted 10 lines
hw/char/renesas_sci.c +0 -9
-        VMSTATE_UINT8(brr, RSCIState),
-        VMSTATE_UINT8(scr, RSCIState),
-        VMSTATE_UINT8(tdr, RSCIState),
-        VMSTATE_UINT8(ssr, RSCIState),
-        VMSTATE_UINT8(rdr, RSCIState),
-        VMSTATE_UINT8(scmr, RSCIState),
-        VMSTATE_UINT8(semr, RSCIState),
-        VMSTATE_UINT8(read_ssr, RSCIState),
-        VMSTATE_TIMER(timer, RSCIState),
         VMSTATE_END_OF_LIST()

This change seems to have lost all the migration support.

hw/char/renesas_sci.c static const VMStateDescription vmstate_rsci = { · line 499

Quoted 2 lines
hw/char/renesas_sci.c +0 -0
     }
 };

thanks
-- PMM

#3 lore raw

PATCH 2/3 hw/char: renesas_sci Add SCI and SCIF support.

In reply to Yoshinori Sato

This peripheral using SH7750.

---
 include/hw/char/renesas_sci.h |  43 ++-
 hw/char/renesas_sci.c         | 489 ++++++++++++++++++++++++++++++++++
 2 files changed, 531 insertions(+), 1 deletion(-)
include/hw/char/renesas_sci.h +42 -1
index c666cf81d1..aa6be53628 100644
@@ -16,12 +16,18 @@
 #include "qom/object.h"
 
 #define TYPE_RENESAS_SCI_BASE "renesas-sci-base"
+#define TYPE_RENESAS_SCI "renesas-sci"
 #define TYPE_RENESAS_SCIA "renesas-scia"
+#define TYPE_RENESAS_SCIF "renesas-scif"
 
 OBJECT_DECLARE_TYPE(RenesasSCIBaseState, RenesasSCIBaseClass,
                     RENESAS_SCI_BASE)
+OBJECT_DECLARE_TYPE(RenesasSCIState, RenesasSCIClass,
+                    RENESAS_SCI)
 OBJECT_DECLARE_TYPE(RenesasSCIAState, RenesasSCIAClass,
                     RENESAS_SCIA)
+OBJECT_DECLARE_TYPE(RenesasSCIFState, RenesasSCIFClass,
+                    RENESAS_SCIF)
 
 enum {
     ERI = 0,
@@ -32,6 +38,7 @@ enum {
 };
 
 enum {
+    RXTOUT,
     RXNEXT,
     TXEMPTY,
     TXEND,
@@ -49,13 +56,14 @@ typedef struct RenesasSCIBaseState {
     SysBusDevice parent_obj;
 
     MemoryRegion memory;
+    MemoryRegion memory_p4;
+    MemoryRegion memory_a7;
     QEMUTimer *event_timer;
 
     /*< public >*/
     uint64_t input_freq;
     int64_t etu;
     int64_t trtime;
-    int64_t tx_start_time;
     Fifo8 rxfifo;
     int regshift;
     uint32_t unit;
@@ -65,6 +73,7 @@ typedef struct RenesasSCIBaseState {
         int64_t time;
         int64_t (*handler)(struct RenesasSCIBaseState *sci);
     } event[NR_SCI_EVENT];
+    uint16_t read_Xsr;
 
     /* common SCI register */
     uint8_t smr;
@@ -74,6 +83,13 @@ typedef struct RenesasSCIBaseState {
     uint16_t Xsr;
 } RenesasSCIBaseState;
 
+struct RenesasSCIState {
+    RenesasSCIBaseState parent_obj;
+
+    /* SCI specific register */
+    uint8_t sptr;
+};
+
 struct RenesasSCIAState {
     RenesasSCIBaseState parent_obj;
 
@@ -82,6 +98,19 @@ struct RenesasSCIAState {
     uint8_t semr;
 };
 
+struct RenesasSCIFState {
+    RenesasSCIBaseState parent_obj;
+
+    /* SCIF specific register */
+    uint16_t fcr;
+    uint16_t sptr;
+    uint16_t lsr;
+
+    /* private */
+    int64_t tx_fifo_top_t;
+    int txremain;
+};
+
 typedef struct RenesasSCIBaseClass {
     SysBusDeviceClass parent;
 
@@ -90,6 +119,12 @@ typedef struct RenesasSCIBaseClass {
     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;
 
@@ -97,4 +132,10 @@ typedef struct RenesasSCIAClass {
     int (*p_divrate)(struct RenesasSCIBaseState *sci);
 } RenesasSCIAClass;
 
+typedef struct RenesasSCIFClass {
+    RenesasSCIBaseClass parent;
+
+    void (*p_irq_fn)(struct RenesasSCIBaseState *sci, int request);
+} RenesasSCIFClass;
+
 #endif
hw/char/renesas_sci.c +489 -0

614 lines not on this page · raw message

Signature · 1 line
2.20.1
#4 lore raw

Re: [PATCH 2/3] hw/char: renesas_sci Add SCI and SCIF support.

Quoted 22 lines · Yoshinori Sato

This peripheral using SH7750.

---
 include/hw/char/renesas_sci.h |  43 ++-
 hw/char/renesas_sci.c         | 489 ++++++++++++++++++++++++++++++++++
 2 files changed, 531 insertions(+), 1 deletion(-)
 enum {
     ERI = 0,
include/hw/char/renesas_sci.h +1 -0
@@ -32,6 +38,7 @@ enum {
 };
 
 enum {
+    RXTOUT,
     RXNEXT,
     TXEMPTY,
     TXEND,
@@ -49,13 +56,14 @@ typedef struct RenesasSCIBaseState {
     SysBusDevice parent_obj;
 

include/hw/char/renesas_sci.h typedef struct RenesasSCIBaseState { · line 58

Quoted 10 lines
include/hw/char/renesas_sci.h +2 -1
     MemoryRegion memory;
+    MemoryRegion memory_p4;
+    MemoryRegion memory_a7;
     QEMUTimer *event_timer;
 
     /*< public >*/
     uint64_t input_freq;
     int64_t etu;
     int64_t trtime;
-    int64_t tx_start_time;

It looks like you added this field in patch 1, where it wasn't used, and then deleted it again in patch 2...

thanks
-- PMM

#5 lore raw

PATCH 3/3 hw/sh4: sh7750 using renesas_sci.

In reply to Yoshinori Sato
---
 include/hw/sh4/sh.h |  8 --------
 hw/sh4/sh7750.c     | 41 +++++++++++++++++++++++++++++++++++++++++
 hw/sh4/Kconfig      |  2 +-
 3 files changed, 42 insertions(+), 9 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 +41 -0

59 lines not on this page · raw message

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

Re: [PATCH 3/3] hw/sh4: sh7750 using renesas_sci.

Quoted 14 lines · Yoshinori Sato
---
 include/hw/sh4/sh.h |  8 --------
 hw/sh4/sh7750.c     | 41 +++++++++++++++++++++++++++++++++++++++++
 hw/sh4/Kconfig      |  2 +-
 3 files changed, 42 insertions(+), 9 deletions(-)
include/hw/sh4/sh.h +0 -0
index becb596979..74e1ba59a8 100644
@@ -55,14 +55,6 @@ int sh7750_register_io_device(struct SH7750State *s,
 

include/hw/sh4/sh.h int sh7750_register_io_device(struct SH7750State *s, · line 65

Quoted 10 lines
include/hw/sh4/sh.h +0 -8
 /* 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);

This change means that the code in sh_serial.c will no longer compile, because it has a non-static function with no previous prototype. The patch as a whole compiles because the change to hw/sh4/Kconfig file removes the selection of SH_SCI and so we never try to compile sh_serial.c. But we shouldn't leave dead code around in the tree.

Option A:
I guess the idea is to avoid having to rename sh_serial_init(), which makes sense. If you want to take this route, then in this patch we should mention that in the commit message, something like:

===begin===
hw/sh4: Switch sh7750 to new renesas-sci devices

Switch the sh7750 away from the old serial device implementation in sh_serial.c to use the new renesas-sci devices.

Note that deleting the prototype for sh_serial_init() means that sh_serial.c will no longer be able to compile (it would hit a warning about having a non-static function without a previous prototype). This is OK because we remove the only place that was selecting the SH_SCI Kconfig feature, so we won't attempt to compile that source file. In the following commit, we will delete the file entirely.

===end===

Then in a new patch to go after this one, remove:
* the file sh_serial.c itself
* the "config SH_SCI" section in hw/char/Kconfig
* the line for sh_serial.c in hw/char/meson.build

Option B: would be to give your new sh7750.c function a different name than sh_serial_init() (eg sci_init()) and change the two callsites in this patch. Then you could keep the old sh_serial_init() prototype in this patch and delete it as part of the new "remove sh_serial.c" patch (which is where removal of the prototype more logically belongs.)

I don't mind which of the two you go for.

Quoted 39 lines
include/hw/sh4/sh.h +0 -0
 /* sh7750.c */
 qemu_irq sh7750_irl(struct SH7750State *s);
hw/sh4/sh7750.c +15 -0
index d53a436d8c..1ef8b73c65 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/char/renesas_sci.h"
+#include "hw/qdev-properties.h"
 
 #define NB_DEVICES 4
 
@@ -752,6 +755,44 @@ static const MemoryRegionOps sh7750_mmct_ops = {
     .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
+static 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)
+{
+    RenesasSCIBaseState *sci;
+    char ckname[16];
+

hw/sh4/sh7750.c static const MemoryRegionOps sh7750_mmct_ops = { · line 779

Quoted 10 lines
hw/sh4/sh7750.c +10 -0
+    switch(feat) {
+    case 0: /* SCI */
+        sci = RENESAS_SCI_BASE(qdev_new(TYPE_RENESAS_SCI));
+        snprintf(ckname, sizeof(ckname), "pck_sci");
+        break;
+    case SH_SERIAL_FEAT_SCIF:
+        sci = RENESAS_SCI_BASE(qdev_new(TYPE_RENESAS_SCIF));
+        snprintf(ckname, sizeof(ckname), "pck_scif");
+        break;
+    }

The ckname[] array seems to be set but never used ?

Since you never use 'sci' as a RenesasSCIBaseState, you could instead declare

Device *sci;

and then
sci = qdev_new(TYPE_RENESAS_whatever);

and avoid some of the DEVICE() casts below.

You might also prefer to have a SysBusDevice *sbd which you can then set with
sbd = SYS_BUS_DEVICE(sci);
and use sbd instead of casting every time you need it.

hw/sh4/sh7750.c static const MemoryRegionOps sh7750_mmct_ops = { · line 789

Quoted 10 lines
hw/sh4/sh7750.c +10 -0
+    qdev_prop_set_chr(DEVICE(sci), "chardev", chr);
+    qdev_prop_set_uint32(DEVICE(sci), "register-size", SCI_REGWIDTH_32);
+    qdev_prop_set_uint64(DEVICE(sci), "input-freq", freq);
+    sysbus_connect_irq(SYS_BUS_DEVICE(sci), 0, eri_source);
+    sysbus_connect_irq(SYS_BUS_DEVICE(sci), 1, rxi_source);
+    sysbus_connect_irq(SYS_BUS_DEVICE(sci), 2, txi_source);
+    if (tei_source)
+        sysbus_connect_irq(SYS_BUS_DEVICE(sci), 3, tei_source);
+    if (bri_source)
+        sysbus_connect_irq(SYS_BUS_DEVICE(sci), 3, bri_source);

QEMU coding style requires braces for all if statements, even when they're only one line.

hw/sh4/sh7750.c static const MemoryRegionOps sh7750_mmct_ops = { · line 794

Quoted 5 lines
hw/sh4/sh7750.c +5 -0
+    sysbus_realize(SYS_BUS_DEVICE(sci), &error_abort);
+    sysbus_mmio_map(SYS_BUS_DEVICE(sci), 0, base);
+    sysbus_mmio_map(SYS_BUS_DEVICE(sci), 1, P4ADDR(base));
+    sysbus_mmio_map(SYS_BUS_DEVICE(sci), 2, A7ADDR(base));
+}

thanks
-- PMM

#7 lore raw

Re: [PATCH 3/3] hw/sh4: sh7750 using renesas_sci.

Quoted 62 lines · Peter Maydell
Quoted 14 lines · Yoshinori Sato
---
 include/hw/sh4/sh.h |  8 --------
 hw/sh4/sh7750.c     | 41 +++++++++++++++++++++++++++++++++++++++++
 hw/sh4/Kconfig      |  2 +-
 3 files changed, 42 insertions(+), 9 deletions(-)
include/hw/sh4/sh.h +0 -0
index becb596979..74e1ba59a8 100644
@@ -55,14 +55,6 @@ int sh7750_register_io_device(struct SH7750State *s,
 

include/hw/sh4/sh.h int sh7750_register_io_device(struct SH7750State *s, · line 65

Quoted 10 lines
include/hw/sh4/sh.h +0 -8
 /* 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);

This change means that the code in sh_serial.c will no longer compile, because it has a non-static function with no previous prototype. The patch as a whole compiles because the change to hw/sh4/Kconfig file removes the selection of SH_SCI and so we never try to compile sh_serial.c. But we shouldn't leave dead code around in the tree.

Option A:
I guess the idea is to avoid having to rename sh_serial_init(), which makes sense. If you want to take this route, then in this patch we should mention that in the commit message, something like:

===begin===
hw/sh4: Switch sh7750 to new renesas-sci devices

Switch the sh7750 away from the old serial device implementation in sh_serial.c to use the new renesas-sci devices.

Note that deleting the prototype for sh_serial_init() means that sh_serial.c will no longer be able to compile (it would hit a warning about having a non-static function without a previous prototype). This is OK because we remove the only place that was selecting the SH_SCI Kconfig feature, so we won't attempt to compile that source file. In the following commit, we will delete the file entirely.

===end===

Then in a new patch to go after this one, remove:
* the file sh_serial.c itself
* the "config SH_SCI" section in hw/char/Kconfig
* the line for sh_serial.c in hw/char/meson.build

Quoted 8 lines

Option B: would be to give your new sh7750.c function a different name than sh_serial_init() (eg sci_init()) and change the two callsites in this patch. Then you could keep the old sh_serial_init() prototype in this patch and delete it as part of the new "remove sh_serial.c" patch (which is where removal of the prototype more logically belongs.)

I don't mind which of the two you go for.

I think option B is fine.
I would like to change sh7750 to qom as the next step. I don't want to make any major changes at this step.

Quoted 43 lines
Quoted 43 lines
include/hw/sh4/sh.h +0 -0
 /* sh7750.c */
 qemu_irq sh7750_irl(struct SH7750State *s);
hw/sh4/sh7750.c +19 -0
index d53a436d8c..1ef8b73c65 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/char/renesas_sci.h"
+#include "hw/qdev-properties.h"
 
 #define NB_DEVICES 4
 
@@ -752,6 +755,44 @@ static const MemoryRegionOps sh7750_mmct_ops = {
     .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
+static 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)
+{
+    RenesasSCIBaseState *sci;
+    char ckname[16];
+
+    switch(feat) {
+    case 0: /* SCI */
+        sci = RENESAS_SCI_BASE(qdev_new(TYPE_RENESAS_SCI));
+        snprintf(ckname, sizeof(ckname), "pck_sci");
Quoted 8 lines

hw/sh4/sh7750.c static const MemoryRegionOps sh7750_mmct_ops = { · line 779

Quoted 6 lines
hw/sh4/sh7750.c +6 -0
+        break;
+    case SH_SERIAL_FEAT_SCIF:
+        sci = RENESAS_SCI_BASE(qdev_new(TYPE_RENESAS_SCIF));
+        snprintf(ckname, sizeof(ckname), "pck_scif");
+        break;
+    }

The ckname[] array seems to be set but never used ?

Yes.
This array used old changes. I forgot remove it.

Quoted 10 lines

Since you never use 'sci' as a RenesasSCIBaseState, you could instead declare

   Device *sci;

and then
sci = qdev_new(TYPE_RENESAS_whatever);

and avoid some of the DEVICE() casts below.

OK.

Quoted 4 lines

You might also prefer to have a SysBusDevice *sbd which you can then set with
sbd = SYS_BUS_DEVICE(sci);
and use sbd instead of casting every time you need it.

OK.

Quoted 11 lines

hw/sh4/sh7750.c static const MemoryRegionOps sh7750_mmct_ops = { · line 789

Quoted 10 lines
hw/sh4/sh7750.c +10 -0
+    qdev_prop_set_chr(DEVICE(sci), "chardev", chr);
+    qdev_prop_set_uint32(DEVICE(sci), "register-size", SCI_REGWIDTH_32);
+    qdev_prop_set_uint64(DEVICE(sci), "input-freq", freq);
+    sysbus_connect_irq(SYS_BUS_DEVICE(sci), 0, eri_source);
+    sysbus_connect_irq(SYS_BUS_DEVICE(sci), 1, rxi_source);
+    sysbus_connect_irq(SYS_BUS_DEVICE(sci), 2, txi_source);
+    if (tei_source)
+        sysbus_connect_irq(SYS_BUS_DEVICE(sci), 3, tei_source);
+    if (bri_source)
+        sysbus_connect_irq(SYS_BUS_DEVICE(sci), 3, bri_source);
Quoted 2 lines

QEMU coding style requires braces for all if statements, even when they're only one line.

It was before checking with checkpatch.pl.
I will clean it in the next patch.

Quoted 8 lines

hw/sh4/sh7750.c static const MemoryRegionOps sh7750_mmct_ops = { · line 794

Quoted 5 lines
hw/sh4/sh7750.c +5 -0
+    sysbus_realize(SYS_BUS_DEVICE(sci), &error_abort);
+    sysbus_mmio_map(SYS_BUS_DEVICE(sci), 0, base);
+    sysbus_mmio_map(SYS_BUS_DEVICE(sci), 1, P4ADDR(base));
+    sysbus_mmio_map(SYS_BUS_DEVICE(sci), 2, A7ADDR(base));
+}

thanks
-- PMM

Signature · 1 line
Yoshinori Sato
#8 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 0/3] renesas_sci update

=== 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

 - [tag update]      patchew/[email protected] -> patchew/[email protected]
 - [tag update]      patchew/[email protected] -> patchew/[email protected]
 - [tag update]      patchew/[email protected] -> patchew/[email protected]
 - [tag update]      patchew/[email protected] -> patchew/[email protected]
 * [new tag]         patchew/[email protected] -> patchew/[email protected]

Switched to a new branch 'test'
2aee00f hw/sh4: sh7750 using renesas_sci.
163b17f hw/char: renesas_sci Add SCI and SCIF support. 3a37650 hw/char: renesas_sci: Refactor for merge all SCI variant..

=== OUTPUT BEGIN ===
1/3 Checking commit 3a3765029d7c (hw/char: renesas_sci: Refactor for merge all SCI variant..) 2/3 Checking commit 163b17f2e78e (hw/char: renesas_sci Add SCI and SCIF support.)
ERROR: spaces required around that ':' (ctx:VxW)
#24: FILE: hw/char/renesas_sci.c:6:
+ * And SH7751 Group, SH7751R Group User's Manual: Hardware

                                                        ^

ERROR: space prohibited after that '*' (ctx:ExW)
#25: FILE: hw/char/renesas_sci.c:7:
+ * (Rev.4.01 R01UH0457EJ0401)
^

total: 2 errors, 0 warnings, 715 lines checked

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

3/3 Checking commit 2aee00ffc830 (hw/sh4: sh7750 using renesas_sci.)
ERROR: space required before the open parenthesis '(' #63: FILE: hw/sh4/sh7750.c:770:
+ switch(feat) {

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

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

total: 3 errors, 0 warnings, 79 lines checked

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

=== 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]