Skip to contentSkip to conversation

hw/riscv: Add Microchip PolarFire SoC Icicle Kit board support

PATCH Superseded Bin Meng 10 participants 62 messages Aug 14, 2020 – Aug 25, 2020

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

cover hw/riscv: Add Microchip PolarFire SoC Icicle Kit board support

From: Bin Meng <[email protected]>

This adds support for Microchip PolarFire SoC Icicle Kit board. The Icicle Kit board integrates a PolarFire SoC, with one SiFive's E51 plus four U54 cores and many on-chip peripherals and an FPGA.

For more details about Microchip PolarFire Soc, please see:
https://www.microsemi.com/product-directory/soc-fpgas/5498-polarfire-soc-fpga

The Icicle Kit board information can be found here:
https://www.microsemi.com/existing-parts/parts/152514

Unlike SiFive FU540, the RISC-V core resect vector is at 0x20220000. The RISC-V CPU and HART codes has been updated to set the core's reset vector based on a configurable property from machine codes.

The following perepherals are created as an unimplemented device:

- Bus Error Uint 0/1/2/3/4
- L2 cache controller
- SYSREG
- MPUCFG
- IOSCBCFG
- GPIO

The following perepherals are emulated:
- SiFive CLINT
- SiFive PLIC
- PolarFire SoC Multi-Mode UART
- PolarFire SoC DMA
- Cadence eMMC/SDHCI controller
- Cadence Gigabit Ethernet MAC

Some bugs in the SD card codes are fixed during the development.

The BIOS image used by this machine is hss.bin, aka Hart Software Services, which can be built from:
https://github.com/polarfire-soc/hart-software-services

To launch this machine:

$ qemu-system-riscv64 -M microchip-icicle-kit -smp 5 \
    -bios path/to/hss.bin -sd path/to/sdcard.img \
    -nic tap,ifname=tap,script=no,model=cadence_gem \
    -display none -serial stdio \
    -chardev socket,id=serial1,path=serial1.sock,server,wait \
    -serial chardev:serial1

The memory is set to 1 GiB by default to match the hardware. A sanity check on ram size is performed in the machine init routine to prompt user to increase the RAM size to > 1 GiB when less than 1 GiB ram is detected.

HSS output is on the first serial port (stdio) and U-Boot/Linux outputs on the 2nd serial port. OpenSBI outputs on a random serial port due to the lottery mechanism used during the multi-core boot.

Bin Meng (18):
target/riscv: cpu: Add a new 'resetvec' property
hw/riscv: hart: Add a new 'resetvec' property target/riscv: cpu: Set reset vector based on the configured property
value
hw/riscv: Initial support for Microchip PolarFire SoC Icicle Kit board hw/char: Add Microchip PolarFire SoC MMUART emulation hw/riscv: microchip_pfsoc: Connect 5 MMUARTs
hw/sd: sd: Fix incorrect populated function switch status data
structure
hw/sd: sd: Correctly set the high capacity bit
hw/sd: sdhci: Make sdhci_poweron_reset() internal visible hw/sd: Add Cadence SDHCI emulation
hw/riscv: microchip_pfsoc: Connect a Cadence SDHCI controller and an
SD card
hw/dma: Add Microchip PolarFire Soc DMA controller emulation hw/riscv: microchip_pfsoc: Connect a DMA controller hw/net: cadence_gem: Add a new 'phy-addr' property hw/riscv: microchip_pfsoc: Connect 2 Cadence GEMs hw/riscv: microchip_pfsoc: Hook GPIO controllers
hw/riscv: clint: Avoid using hard-coded timebase frequency hw/riscv: microchip_pfsoc: Document the software used for testing

 MAINTAINERS                         |  11 +
 default-configs/riscv64-softmmu.mak |   1 +
 hw/char/Kconfig                     |   3 +
 hw/char/Makefile.objs               |   1 +
 hw/char/mchp_pfsoc_mmuart.c         |  82 +++++++
 hw/dma/Kconfig                      |   3 +
 hw/dma/Makefile.objs                |   1 +
 hw/dma/mchp_pfsoc_dma.c             | 322 +++++++++++++++++++++++++
 hw/net/cadence_gem.c                |   7 +-
 hw/riscv/Kconfig                    |   9 +
 hw/riscv/Makefile.objs              |   1 +
 hw/riscv/microchip_pfsoc.c          | 456 ++++++++++++++++++++++++++++++++++++
 hw/riscv/opentitan.c                |   1 +
 hw/riscv/riscv_hart.c               |   3 +
 hw/riscv/sifive_clint.c             |  25 +-
 hw/riscv/sifive_e.c                 |   4 +-
 hw/riscv/sifive_u.c                 |   5 +-
 hw/riscv/spike.c                    |   2 +-
 hw/riscv/virt.c                     |   3 +-
 hw/sd/Kconfig                       |   4 +
 hw/sd/Makefile.objs                 |   1 +
 hw/sd/cadence_sdhci.c               | 162 +++++++++++++
 hw/sd/sd.c                          |   8 +-
 hw/sd/sdhci-internal.h              |   1 +
 hw/sd/sdhci.c                       |   2 +-
 include/hw/char/mchp_pfsoc_mmuart.h |  61 +++++
 include/hw/dma/mchp_pfsoc_dma.h     |  57 +++++
 include/hw/net/cadence_gem.h        |   2 +
 include/hw/riscv/microchip_pfsoc.h  | 125 ++++++++++
 include/hw/riscv/riscv_hart.h       |   1 +
 include/hw/riscv/sifive_clint.h     |   3 +-
 include/hw/sd/cadence_sdhci.h       |  65 +++++
 target/riscv/cpu.c                  |   8 +-
 target/riscv/cpu.h                  |   7 +-
 target/riscv/cpu_helper.c           |   4 +-
 target/riscv/csr.c                  |   4 +-
 36 files changed, 1424 insertions(+), 31 deletions(-)
 create mode 100644 hw/char/mchp_pfsoc_mmuart.c
 create mode 100644 hw/dma/mchp_pfsoc_dma.c
 create mode 100644 hw/riscv/microchip_pfsoc.c
 create mode 100644 hw/sd/cadence_sdhci.c
 create mode 100644 include/hw/char/mchp_pfsoc_mmuart.h
 create mode 100644 include/hw/dma/mchp_pfsoc_dma.h
 create mode 100644 include/hw/riscv/microchip_pfsoc.h
 create mode 100644 include/hw/sd/cadence_sdhci.h
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 1/18 target/riscv: cpu: Add a new 'resetvec' property

From: Bin Meng <[email protected]>

Currently the reset vector address is hard-coded in a RISC-V CPU's instance_init() routine. In a real world we can have 2 exact same CPUs except for the reset vector address, which is pretty common in the RISC-V core IP licensing business.

Normally reset vector address is a configurable parameter. Let's create a 64-bit property to store the reset vector address which covers both 32-bit and 64-bit CPUs.

---

 target/riscv/cpu.c | 1 +
 target/riscv/cpu.h | 1 +
 2 files changed, 2 insertions(+)
target/riscv/cpu.c +1 -0
index 228b9bd..8067a26 100644
@@ -518,6 +518,7 @@ static Property riscv_cpu_properties[] = {
     DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64),
     DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true),
     DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true),
+    DEFINE_PROP_UINT64("resetvec", RISCVCPU, cfg.resetvec, DEFAULT_RSTVEC),
     DEFINE_PROP_END_OF_LIST(),
 };
 
target/riscv/cpu.h +1 -0
index a804a5d..d34bcfa 100644
@@ -291,6 +291,7 @@ typedef struct RISCVCPU {
         uint16_t elen;
         bool mmu;
         bool pmp;
+        uint64_t resetvec;
     } cfg;
 } RISCVCPU;
 
Signature · 1 line
2.7.4
Reviewed-by on v1 1/18
#2 lore raw

Re: [PATCH 01/18] target/riscv: cpu: Add a new 'resetvec' property

Quoted 8 lines · Bin Meng

From: Bin Meng <[email protected]>

Currently the reset vector address is hard-coded in a RISC-V CPU's instance_init() routine. In a real world we can have 2 exact same CPUs except for the reset vector address, which is pretty common in the RISC-V core IP licensing business.

Quoted 5 lines

Normally reset vector address is a configurable parameter. Let's create a 64-bit property to store the reset vector address which covers both 32-bit and 64-bit CPUs.

Alistair

Quoted 34 lines

---

 target/riscv/cpu.c | 1 +
 target/riscv/cpu.h | 1 +
 2 files changed, 2 insertions(+)
target/riscv/cpu.c +1 -0
index 228b9bd..8067a26 100644
@@ -518,6 +518,7 @@ static Property riscv_cpu_properties[] = {
     DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64),
     DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true),
     DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true),
+    DEFINE_PROP_UINT64("resetvec", RISCVCPU, cfg.resetvec, DEFAULT_RSTVEC),
     DEFINE_PROP_END_OF_LIST(),
 };
 
target/riscv/cpu.h +1 -1
index a804a5d..d34bcfa 100644
@@ -291,6 +291,7 @@ typedef struct RISCVCPU {
         uint16_t elen;
         bool mmu;
         bool pmp;
+        uint64_t resetvec;
     } cfg;
 } RISCVCPU;
 
--

2.7.4

author
#3 lore raw

PATCH 2/18 hw/riscv: hart: Add a new 'resetvec' property

In reply to Bin Meng

From: Bin Meng <[email protected]>

RISC-V machines do not instantiate RISC-V CPUs directly, instead they do that via the hart array. Add a new property for the reset vector address to allow the value to be passed to the CPU, before CPU is realized.

---

 hw/riscv/riscv_hart.c         | 3 +++
 include/hw/riscv/riscv_hart.h | 1 +
 2 files changed, 4 insertions(+)
hw/riscv/riscv_hart.c +3 -0
index f59fe52..613ea2a 100644
@@ -31,6 +31,8 @@ static Property riscv_harts_props[] = {
     DEFINE_PROP_UINT32("num-harts", RISCVHartArrayState, num_harts, 1),
     DEFINE_PROP_UINT32("hartid-base", RISCVHartArrayState, hartid_base, 0),
     DEFINE_PROP_STRING("cpu-type", RISCVHartArrayState, cpu_type),
+    DEFINE_PROP_UINT64("resetvec", RISCVHartArrayState, resetvec,
+                       DEFAULT_RSTVEC),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -44,6 +46,7 @@ static bool riscv_hart_realize(RISCVHartArrayState *s, int idx,
                                char *cpu_type, Error **errp)
 {
     object_initialize_child(OBJECT(s), "harts[*]", &s->harts[idx], cpu_type);
+    qdev_prop_set_uint64(DEVICE(&s->harts[idx]), "resetvec", s->resetvec);
     s->harts[idx].env.mhartid = s->hartid_base + idx;
     qemu_register_reset(riscv_harts_cpu_reset, &s->harts[idx]);
     return qdev_realize(DEVICE(&s->harts[idx]), NULL, errp);
include/hw/riscv/riscv_hart.h +1 -0
index c75856f..77aa4bc 100644
@@ -37,6 +37,7 @@ typedef struct RISCVHartArrayState {
     uint32_t num_harts;
     uint32_t hartid_base;
     char *cpu_type;
+    uint64_t resetvec;
     RISCVCPU *harts;
 } RISCVHartArrayState;
 
Signature · 1 line
2.7.4
Reviewed-by on v1 2/18
#4 lore raw

Re: [PATCH 02/18] hw/riscv: hart: Add a new 'resetvec' property

Quoted 9 lines · Bin Meng

From: Bin Meng <[email protected]>

RISC-V machines do not instantiate RISC-V CPUs directly, instead they do that via the hart array. Add a new property for the reset vector address to allow the value to be passed to the CPU, before CPU is realized.

Alistair

Quoted 43 lines

---

 hw/riscv/riscv_hart.c         | 3 +++
 include/hw/riscv/riscv_hart.h | 1 +
 2 files changed, 4 insertions(+)
hw/riscv/riscv_hart.c +3 -0
index f59fe52..613ea2a 100644
@@ -31,6 +31,8 @@ static Property riscv_harts_props[] = {
     DEFINE_PROP_UINT32("num-harts", RISCVHartArrayState, num_harts, 1),
     DEFINE_PROP_UINT32("hartid-base", RISCVHartArrayState, hartid_base, 0),
     DEFINE_PROP_STRING("cpu-type", RISCVHartArrayState, cpu_type),
+    DEFINE_PROP_UINT64("resetvec", RISCVHartArrayState, resetvec,
+                       DEFAULT_RSTVEC),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -44,6 +46,7 @@ static bool riscv_hart_realize(RISCVHartArrayState *s, int idx,
                                char *cpu_type, Error **errp)
 {
     object_initialize_child(OBJECT(s), "harts[*]", &s->harts[idx], cpu_type);
+    qdev_prop_set_uint64(DEVICE(&s->harts[idx]), "resetvec", s->resetvec);
     s->harts[idx].env.mhartid = s->hartid_base + idx;
     qemu_register_reset(riscv_harts_cpu_reset, &s->harts[idx]);
     return qdev_realize(DEVICE(&s->harts[idx]), NULL, errp);
include/hw/riscv/riscv_hart.h +1 -1
index c75856f..77aa4bc 100644
@@ -37,6 +37,7 @@ typedef struct RISCVHartArrayState {
     uint32_t num_harts;
     uint32_t hartid_base;
     char *cpu_type;
+    uint64_t resetvec;
     RISCVCPU *harts;
 } RISCVHartArrayState;
 
--

2.7.4

author
#5 lore raw

PATCH 3/18 target/riscv: cpu: Set reset vector based on the configured property value

In reply to Bin Meng

From: Bin Meng <[email protected]>

Now that we have the newly introduced 'resetvec' property in the RISC-V CPU and HART, instead of hard-coding the reset vector addr in the CPU's instance_init(), move that to riscv_cpu_realize() based on the configured property value from the RISC-V machines.

---

 hw/riscv/opentitan.c | 1 +
 hw/riscv/sifive_e.c  | 1 +
 hw/riscv/sifive_u.c  | 2 ++
 target/riscv/cpu.c   | 7 ++-----
 4 files changed, 6 insertions(+), 5 deletions(-)
hw/riscv/opentitan.c +1 -0
index a8f0039..b0a4eae 100644
@@ -111,6 +111,7 @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp)
                             &error_abort);
     object_property_set_int(OBJECT(&s->cpus), "num-harts", ms->smp.cpus,
                             &error_abort);
+    object_property_set_int(OBJECT(&s->cpus), "resetvec", 0x8090, &error_abort);
     sysbus_realize(SYS_BUS_DEVICE(&s->cpus), &error_abort);
 
     /* Boot ROM */
hw/riscv/sifive_e.c +1 -0
index c8b0604..c84d407 100644
@@ -177,6 +177,7 @@ static void sifive_e_soc_init(Object *obj)
     object_initialize_child(obj, "cpus", &s->cpus, TYPE_RISCV_HART_ARRAY);
     object_property_set_int(OBJECT(&s->cpus), "num-harts", ms->smp.cpus,
                             &error_abort);
+    object_property_set_int(OBJECT(&s->cpus), "resetvec", 0x1004, &error_abort);
     object_initialize_child(obj, "riscv.sifive.e.gpio0", &s->gpio,
                             TYPE_SIFIVE_GPIO);
 }
hw/riscv/sifive_u.c +2 -0
index 18301e6..e256da2 100644
@@ -611,6 +611,7 @@ static void sifive_u_soc_instance_init(Object *obj)
     qdev_prop_set_uint32(DEVICE(&s->e_cpus), "num-harts", 1);
     qdev_prop_set_uint32(DEVICE(&s->e_cpus), "hartid-base", 0);
     qdev_prop_set_string(DEVICE(&s->e_cpus), "cpu-type", SIFIVE_E_CPU);
+    qdev_prop_set_uint64(DEVICE(&s->e_cpus), "resetvec", 0x1004);
 
     object_initialize_child(obj, "u-cluster", &s->u_cluster, TYPE_CPU_CLUSTER);
     qdev_prop_set_uint32(DEVICE(&s->u_cluster), "cluster-id", 1);
@@ -620,6 +621,7 @@ static void sifive_u_soc_instance_init(Object *obj)
     qdev_prop_set_uint32(DEVICE(&s->u_cpus), "num-harts", ms->smp.cpus - 1);
     qdev_prop_set_uint32(DEVICE(&s->u_cpus), "hartid-base", 1);
     qdev_prop_set_string(DEVICE(&s->u_cpus), "cpu-type", SIFIVE_U_CPU);
+    qdev_prop_set_uint64(DEVICE(&s->u_cpus), "resetvec", 0x1004);
 
     object_initialize_child(obj, "prci", &s->prci, TYPE_SIFIVE_U_PRCI);
     object_initialize_child(obj, "otp", &s->otp, TYPE_SIFIVE_U_OTP);
target/riscv/cpu.c +2 -5
index 8067a26..bd41286 100644
@@ -128,7 +128,6 @@ static void riscv_any_cpu_init(Object *obj)
     CPURISCVState *env = &RISCV_CPU(obj)->env;
     set_misa(env, RVXLEN | RVI | RVM | RVA | RVF | RVD | RVC | RVU);
     set_priv_version(env, PRIV_VERSION_1_11_0);
-    set_resetvec(env, DEFAULT_RSTVEC);
 }
 
 static void riscv_base_cpu_init(Object *obj)
@@ -136,7 +135,6 @@ static void riscv_base_cpu_init(Object *obj)
     CPURISCVState *env = &RISCV_CPU(obj)->env;
     /* We set this in the realise function */
     set_misa(env, 0);
-    set_resetvec(env, DEFAULT_RSTVEC);
 }
 
 static void rvxx_sifive_u_cpu_init(Object *obj)
@@ -144,7 +142,6 @@ static void rvxx_sifive_u_cpu_init(Object *obj)
     CPURISCVState *env = &RISCV_CPU(obj)->env;
     set_misa(env, RVXLEN | RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU);
     set_priv_version(env, PRIV_VERSION_1_10_0);
-    set_resetvec(env, 0x1004);
 }
 
 static void rvxx_sifive_e_cpu_init(Object *obj)
@@ -152,7 +149,6 @@ static void rvxx_sifive_e_cpu_init(Object *obj)
     CPURISCVState *env = &RISCV_CPU(obj)->env;
     set_misa(env, RVXLEN | RVI | RVM | RVA | RVC | RVU);
     set_priv_version(env, PRIV_VERSION_1_10_0);
-    set_resetvec(env, 0x1004);
     qdev_prop_set_bit(DEVICE(obj), "mmu", false);
 }
 
@@ -163,7 +159,6 @@ static void rv32_ibex_cpu_init(Object *obj)
     CPURISCVState *env = &RISCV_CPU(obj)->env;
     set_misa(env, RV32 | RVI | RVM | RVC | RVU);
     set_priv_version(env, PRIV_VERSION_1_10_0);
-    set_resetvec(env, 0x8090);
     qdev_prop_set_bit(DEVICE(obj), "mmu", false);
 }
 
@@ -373,6 +368,8 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
         set_feature(env, RISCV_FEATURE_PMP);
     }
 
+    set_resetvec(env, cpu->cfg.resetvec);
+
     /* If misa isn't set (rv32 and rv64 machines) set it here */
     if (!env->misa) {
         /* Do some ISA extension error checking */
Signature · 1 line
2.7.4
Reviewed-by on v1 3/18
#6 lore raw

Re: [PATCH 03/18] target/riscv: cpu: Set reset vector based on the configured property value

Quoted 9 lines · Bin Meng

From: Bin Meng <[email protected]>

Now that we have the newly introduced 'resetvec' property in the RISC-V CPU and HART, instead of hard-coding the reset vector addr in the CPU's instance_init(), move that to riscv_cpu_realize() based on the configured property value from the RISC-V machines.

Alistair

Quoted 109 lines

---

 hw/riscv/opentitan.c | 1 +
 hw/riscv/sifive_e.c  | 1 +
 hw/riscv/sifive_u.c  | 2 ++
 target/riscv/cpu.c   | 7 ++-----
 4 files changed, 6 insertions(+), 5 deletions(-)
hw/riscv/opentitan.c +1 -0
index a8f0039..b0a4eae 100644
@@ -111,6 +111,7 @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp)
                             &error_abort);
     object_property_set_int(OBJECT(&s->cpus), "num-harts", ms->smp.cpus,
                             &error_abort);
+    object_property_set_int(OBJECT(&s->cpus), "resetvec", 0x8090, &error_abort);
     sysbus_realize(SYS_BUS_DEVICE(&s->cpus), &error_abort);
 
     /* Boot ROM */
hw/riscv/sifive_e.c +1 -0
index c8b0604..c84d407 100644
@@ -177,6 +177,7 @@ static void sifive_e_soc_init(Object *obj)
     object_initialize_child(obj, "cpus", &s->cpus, TYPE_RISCV_HART_ARRAY);
     object_property_set_int(OBJECT(&s->cpus), "num-harts", ms->smp.cpus,
                             &error_abort);
+    object_property_set_int(OBJECT(&s->cpus), "resetvec", 0x1004, &error_abort);
     object_initialize_child(obj, "riscv.sifive.e.gpio0", &s->gpio,
                             TYPE_SIFIVE_GPIO);
 }
hw/riscv/sifive_u.c +2 -0
index 18301e6..e256da2 100644
@@ -611,6 +611,7 @@ static void sifive_u_soc_instance_init(Object *obj)
     qdev_prop_set_uint32(DEVICE(&s->e_cpus), "num-harts", 1);
     qdev_prop_set_uint32(DEVICE(&s->e_cpus), "hartid-base", 0);
     qdev_prop_set_string(DEVICE(&s->e_cpus), "cpu-type", SIFIVE_E_CPU);
+    qdev_prop_set_uint64(DEVICE(&s->e_cpus), "resetvec", 0x1004);
 
     object_initialize_child(obj, "u-cluster", &s->u_cluster, TYPE_CPU_CLUSTER);
     qdev_prop_set_uint32(DEVICE(&s->u_cluster), "cluster-id", 1);
@@ -620,6 +621,7 @@ static void sifive_u_soc_instance_init(Object *obj)
     qdev_prop_set_uint32(DEVICE(&s->u_cpus), "num-harts", ms->smp.cpus - 1);
     qdev_prop_set_uint32(DEVICE(&s->u_cpus), "hartid-base", 1);
     qdev_prop_set_string(DEVICE(&s->u_cpus), "cpu-type", SIFIVE_U_CPU);
+    qdev_prop_set_uint64(DEVICE(&s->u_cpus), "resetvec", 0x1004);
 
     object_initialize_child(obj, "prci", &s->prci, TYPE_SIFIVE_U_PRCI);
     object_initialize_child(obj, "otp", &s->otp, TYPE_SIFIVE_U_OTP);
target/riscv/cpu.c +2 -6
index 8067a26..bd41286 100644
@@ -128,7 +128,6 @@ static void riscv_any_cpu_init(Object *obj)
     CPURISCVState *env = &RISCV_CPU(obj)->env;
     set_misa(env, RVXLEN | RVI | RVM | RVA | RVF | RVD | RVC | RVU);
     set_priv_version(env, PRIV_VERSION_1_11_0);
-    set_resetvec(env, DEFAULT_RSTVEC);
 }
 
 static void riscv_base_cpu_init(Object *obj)
@@ -136,7 +135,6 @@ static void riscv_base_cpu_init(Object *obj)
     CPURISCVState *env = &RISCV_CPU(obj)->env;
     /* We set this in the realise function */
     set_misa(env, 0);
-    set_resetvec(env, DEFAULT_RSTVEC);
 }
 
 static void rvxx_sifive_u_cpu_init(Object *obj)
@@ -144,7 +142,6 @@ static void rvxx_sifive_u_cpu_init(Object *obj)
     CPURISCVState *env = &RISCV_CPU(obj)->env;
     set_misa(env, RVXLEN | RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU);
     set_priv_version(env, PRIV_VERSION_1_10_0);
-    set_resetvec(env, 0x1004);
 }
 
 static void rvxx_sifive_e_cpu_init(Object *obj)
@@ -152,7 +149,6 @@ static void rvxx_sifive_e_cpu_init(Object *obj)
     CPURISCVState *env = &RISCV_CPU(obj)->env;
     set_misa(env, RVXLEN | RVI | RVM | RVA | RVC | RVU);
     set_priv_version(env, PRIV_VERSION_1_10_0);
-    set_resetvec(env, 0x1004);
     qdev_prop_set_bit(DEVICE(obj), "mmu", false);
 }
 
@@ -163,7 +159,6 @@ static void rv32_ibex_cpu_init(Object *obj)
     CPURISCVState *env = &RISCV_CPU(obj)->env;
     set_misa(env, RV32 | RVI | RVM | RVC | RVU);
     set_priv_version(env, PRIV_VERSION_1_10_0);
-    set_resetvec(env, 0x8090);
     qdev_prop_set_bit(DEVICE(obj), "mmu", false);
 }
 
@@ -373,6 +368,8 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
         set_feature(env, RISCV_FEATURE_PMP);
     }
 
+    set_resetvec(env, cpu->cfg.resetvec);
+
     /* If misa isn't set (rv32 and rv64 machines) set it here */
     if (!env->misa) {
         /* Do some ISA extension error checking */
--

2.7.4

author
#7 lore raw

PATCH 4/18 hw/riscv: Initial support for Microchip PolarFire SoC Icicle Kit board

In reply to Bin Meng

From: Bin Meng <[email protected]>

This is an initial support for Microchip PolarFire SoC Icicle Kit. The Icicle Kit board integrates a PolarFire SoC, with one SiFive's E51 plus four U54 cores and many on-chip peripherals and an FPGA.

For more details about Microchip PolarFire Soc, please see:
https://www.microsemi.com/product-directory/soc-fpgas/5498-polarfire-soc-fpga

Unlike SiFive FU540, the RISC-V core resect vector is at 0x20220000. The following perepherals are created as an unimplemented device:

- Bus Error Uint 0/1/2/3/4
- L2 cache controller
- SYSREG
- MPUCFG
- IOSCBCFG

More devices will be added later.

The BIOS image used by this machine is hss.bin, aka Hart Software Services, which can be built from:
https://github.com/polarfire-soc/hart-software-services

To launch this machine:

$ qemu-system-riscv64 -nographic -M microchip-icicle-kit

The memory is set to 1 GiB by default to match the hardware. A sanity check on ram size is performed in the machine init routine to prompt user to increase the RAM size to > 1 GiB when less than 1 GiB ram is detected.

---

 MAINTAINERS                         |   7 +
 default-configs/riscv64-softmmu.mak |   1 +
 hw/riscv/Kconfig                    |   6 +
 hw/riscv/Makefile.objs              |   1 +
 hw/riscv/microchip_pfsoc.c          | 312 ++++++++++++++++++++++++++++++++++++
 include/hw/riscv/microchip_pfsoc.h  |  88 ++++++++++
 6 files changed, 415 insertions(+)
 create mode 100644 hw/riscv/microchip_pfsoc.c
 create mode 100644 include/hw/riscv/microchip_pfsoc.h
MAINTAINERS +7 -0
index 0886eb3..8716cb6 100644
@@ -1314,6 +1314,13 @@ F: include/hw/riscv/opentitan.h
 F: include/hw/char/ibex_uart.h
 F: include/hw/intc/ibex_plic.h
 
+Microchip PolarFire SoC Icicle Kit
+M: Bin Meng <[email protected]>
+L: [email protected]
+S: Supported
+F: hw/riscv/microchip_pfsoc.c
+F: include/hw/riscv/microchip_pfsoc.h
+
 RX Machines
 -----------
 rx-gdbsim
default-configs/riscv64-softmmu.mak +1 -0
index aaf6d73..76b6195 100644
@@ -10,3 +10,4 @@ CONFIG_SPIKE=y
 CONFIG_SIFIVE_E=y
 CONFIG_SIFIVE_U=y
 CONFIG_RISCV_VIRT=y
+CONFIG_MICROCHIP_PFSOC=y
hw/riscv/Kconfig +6 -0
index 28947ef..3292fae 100644
@@ -48,3 +48,9 @@ config RISCV_VIRT
     select PCI_EXPRESS_GENERIC_BRIDGE
     select PFLASH_CFI01
     select SIFIVE
+
+config MICROCHIP_PFSOC
+    bool
+    select HART
+    select SIFIVE
+    select UNIMP
hw/riscv/Makefile.objs +1 -0
index 57cc708..419a5a0 100644
@@ -14,3 +14,4 @@ obj-$(CONFIG_SIFIVE_U) += sifive_u_prci.o
 obj-$(CONFIG_SIFIVE) += sifive_uart.o
 obj-$(CONFIG_SPIKE) += spike.o
 obj-$(CONFIG_RISCV_VIRT) += virt.o
+obj-$(CONFIG_MICROCHIP_PFSOC) += microchip_pfsoc.o
hw/riscv/microchip_pfsoc.c new file +312 -0

312 lines not on this page · raw message

include/hw/riscv/microchip_pfsoc.h new file +88 -0

88 lines not on this page · raw message

Signature · 1 line
2.7.4
Reviewed-by on v1 4/18
#8 lore raw

Re: [PATCH 04/18] hw/riscv: Initial support for Microchip PolarFire SoC Icicle Kit board

Quoted 26 lines · Bin Meng

From: Bin Meng <[email protected]>

This is an initial support for Microchip PolarFire SoC Icicle Kit. The Icicle Kit board integrates a PolarFire SoC, with one SiFive's E51 plus four U54 cores and many on-chip peripherals and an FPGA.

For more details about Microchip PolarFire Soc, please see:
https://www.microsemi.com/product-directory/soc-fpgas/5498-polarfire-soc-fpga

Unlike SiFive FU540, the RISC-V core resect vector is at 0x20220000. The following perepherals are created as an unimplemented device:

- Bus Error Uint 0/1/2/3/4
- L2 cache controller
- SYSREG
- MPUCFG
- IOSCBCFG

More devices will be added later.

The BIOS image used by this machine is hss.bin, aka Hart Software Services, which can be built from:
https://github.com/polarfire-soc/hart-software-services

To launch this machine:

Quoted 8 lines
$ qemu-system-riscv64 -nographic -M microchip-icicle-kit

The memory is set to 1 GiB by default to match the hardware. A sanity check on ram size is performed in the machine init routine to prompt user to increase the RAM size to > 1 GiB when less than 1 GiB ram is detected.

Looks good. I didn't check the addresses and PLIC config data with the datasheet, but I'm assuming it's correct.

Alistair

Quoted 478 lines

---

 MAINTAINERS                         |   7 +
 default-configs/riscv64-softmmu.mak |   1 +
 hw/riscv/Kconfig                    |   6 +
 hw/riscv/Makefile.objs              |   1 +
 hw/riscv/microchip_pfsoc.c          | 312 ++++++++++++++++++++++++++++++++++++
 include/hw/riscv/microchip_pfsoc.h  |  88 ++++++++++
 6 files changed, 415 insertions(+)
 create mode 100644 hw/riscv/microchip_pfsoc.c
 create mode 100644 include/hw/riscv/microchip_pfsoc.h
MAINTAINERS +7 -0
index 0886eb3..8716cb6 100644
@@ -1314,6 +1314,13 @@ F: include/hw/riscv/opentitan.h
 F: include/hw/char/ibex_uart.h
 F: include/hw/intc/ibex_plic.h
 
+Microchip PolarFire SoC Icicle Kit
+M: Bin Meng <[email protected]>
+L: [email protected]
+S: Supported
+F: hw/riscv/microchip_pfsoc.c
+F: include/hw/riscv/microchip_pfsoc.h
+
 RX Machines
 -----------
 rx-gdbsim
default-configs/riscv64-softmmu.mak +1 -0
index aaf6d73..76b6195 100644
@@ -10,3 +10,4 @@ CONFIG_SPIKE=y
 CONFIG_SIFIVE_E=y
 CONFIG_SIFIVE_U=y
 CONFIG_RISCV_VIRT=y
+CONFIG_MICROCHIP_PFSOC=y
hw/riscv/Kconfig +6 -0
index 28947ef..3292fae 100644
@@ -48,3 +48,9 @@ config RISCV_VIRT
     select PCI_EXPRESS_GENERIC_BRIDGE
     select PFLASH_CFI01
     select SIFIVE
+
+config MICROCHIP_PFSOC
+    bool
+    select HART
+    select SIFIVE
+    select UNIMP
hw/riscv/Makefile.objs +1 -0
index 57cc708..419a5a0 100644
@@ -14,3 +14,4 @@ obj-$(CONFIG_SIFIVE_U) += sifive_u_prci.o
 obj-$(CONFIG_SIFIVE) += sifive_uart.o
 obj-$(CONFIG_SPIKE) += spike.o
 obj-$(CONFIG_RISCV_VIRT) += virt.o
+obj-$(CONFIG_MICROCHIP_PFSOC) += microchip_pfsoc.o
hw/riscv/microchip_pfsoc.c new file +312 -0
new file mode 100644
index 0000000..20a642c
@@ -0,0 +1,312 @@
+/*
+ * QEMU RISC-V Board Compatible with Microchip PolarFire SoC Icicle Kit
+ *
+ * Copyright (c) 2020 Wind River Systems, Inc.
+ *
+ * Author:
+ *   Bin Meng <[email protected]>
+ *
+ * Provides a board compatible with the Microchip PolarFire SoC Icicle Kit
+ *
+ * 0) CLINT (Core Level Interruptor)
+ * 1) PLIC (Platform Level Interrupt Controller)
+ * 2) eNVM (Embedded Non-Volatile Memory)
+ *
+ * This board currently generates devicetree dynamically that indicates at least
+ * two harts and up to five harts.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2 or later, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/error-report.h"
+#include "qemu/log.h"
+#include "qemu/units.h"
+#include "qemu/cutils.h"
+#include "qapi/error.h"
+#include "hw/boards.h"
+#include "hw/irq.h"
+#include "hw/loader.h"
+#include "hw/sysbus.h"
+#include "hw/cpu/cluster.h"
+#include "target/riscv/cpu.h"
+#include "hw/misc/unimp.h"
+#include "hw/riscv/boot.h"
+#include "hw/riscv/riscv_hart.h"
+#include "hw/riscv/sifive_clint.h"
+#include "hw/riscv/sifive_plic.h"
+#include "hw/riscv/microchip_pfsoc.h"
+
+/*
+ * The BIOS image used by this machine is called Hart Software Services (HSS).
+ * See https://github.com/polarfire-soc/hart-software-services
+ */
+#define BIOS_FILENAME   "hss.bin"
+#define RESET_VECTOR    0x20220000
+
+static const struct MemmapEntry {
+    hwaddr base;
+    hwaddr size;
+} microchip_pfsoc_memmap[] = {
+    [MICROCHIP_PFSOC_DEBUG] =           {        0x0,     0x1000 },
+    [MICROCHIP_PFSOC_E51_DTIM] =        {  0x1000000,     0x2000 },
+    [MICROCHIP_PFSOC_BUSERR_UNIT0] =    {  0x1700000,     0x1000 },
+    [MICROCHIP_PFSOC_BUSERR_UNIT1] =    {  0x1701000,     0x1000 },
+    [MICROCHIP_PFSOC_BUSERR_UNIT2] =    {  0x1702000,     0x1000 },
+    [MICROCHIP_PFSOC_BUSERR_UNIT3] =    {  0x1703000,     0x1000 },
+    [MICROCHIP_PFSOC_BUSERR_UNIT4] =    {  0x1704000,     0x1000 },
+    [MICROCHIP_PFSOC_CLINT] =           {  0x2000000,    0x10000 },
+    [MICROCHIP_PFSOC_L2CC] =            {  0x2010000,     0x1000 },
+    [MICROCHIP_PFSOC_L2LIM] =           {  0x8000000,  0x2000000 },
+    [MICROCHIP_PFSOC_PLIC] =            {  0xc000000,  0x4000000 },
+    [MICROCHIP_PFSOC_SYSREG] =          { 0x20002000,     0x2000 },
+    [MICROCHIP_PFSOC_MPUCFG] =          { 0x20005000,     0x1000 },
+    [MICROCHIP_PFSOC_ENVM_CFG] =        { 0x20200000,     0x1000 },
+    [MICROCHIP_PFSOC_ENVM_DATA] =       { 0x20220000,    0x20000 },
+    [MICROCHIP_PFSOC_IOSCB_CFG] =       { 0x37080000,     0x1000 },
+    [MICROCHIP_PFSOC_DRAM] =            { 0x80000000,        0x0 },
+};
+
+static void microchip_pfsoc_soc_instance_init(Object *obj)
+{
+    MachineState *ms = MACHINE(qdev_get_machine());
+    MicrochipPFSoCState *s = MICROCHIP_PFSOC(obj);
+
+    object_initialize_child(obj, "e-cluster", &s->e_cluster, TYPE_CPU_CLUSTER);
+    qdev_prop_set_uint32(DEVICE(&s->e_cluster), "cluster-id", 0);
+
+    object_initialize_child(OBJECT(&s->e_cluster), "e-cpus", &s->e_cpus,
+                            TYPE_RISCV_HART_ARRAY);
+    qdev_prop_set_uint32(DEVICE(&s->e_cpus), "num-harts", 1);
+    qdev_prop_set_uint32(DEVICE(&s->e_cpus), "hartid-base", 0);
+    qdev_prop_set_string(DEVICE(&s->e_cpus), "cpu-type",
+                         TYPE_RISCV_CPU_SIFIVE_E51);
+    qdev_prop_set_uint64(DEVICE(&s->e_cpus), "resetvec", RESET_VECTOR);
+
+    object_initialize_child(obj, "u-cluster", &s->u_cluster, TYPE_CPU_CLUSTER);
+    qdev_prop_set_uint32(DEVICE(&s->u_cluster), "cluster-id", 1);
+
+    object_initialize_child(OBJECT(&s->u_cluster), "u-cpus", &s->u_cpus,
+                            TYPE_RISCV_HART_ARRAY);
+    qdev_prop_set_uint32(DEVICE(&s->u_cpus), "num-harts", ms->smp.cpus - 1);
+    qdev_prop_set_uint32(DEVICE(&s->u_cpus), "hartid-base", 1);
+    qdev_prop_set_string(DEVICE(&s->u_cpus), "cpu-type",
+                         TYPE_RISCV_CPU_SIFIVE_U54);
+    qdev_prop_set_uint64(DEVICE(&s->u_cpus), "resetvec", RESET_VECTOR);
+}
+
+static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
+{
+    MachineState *ms = MACHINE(qdev_get_machine());
+    MicrochipPFSoCState *s = MICROCHIP_PFSOC(dev);
+    const struct MemmapEntry *memmap = microchip_pfsoc_memmap;
+    MemoryRegion *system_memory = get_system_memory();
+    MemoryRegion *e51_dtim_mem = g_new(MemoryRegion, 1);
+    MemoryRegion *l2lim_mem = g_new(MemoryRegion, 1);
+    MemoryRegion *envm_data = g_new(MemoryRegion, 1);
+    char *plic_hart_config;
+    size_t plic_hart_config_len;
+    int i;
+
+    sysbus_realize(SYS_BUS_DEVICE(&s->e_cpus), &error_abort);
+    sysbus_realize(SYS_BUS_DEVICE(&s->u_cpus), &error_abort);
+    /*
+     * The cluster must be realized after the RISC-V hart array container,
+     * as the container's CPU object is only created on realize, and the
+     * CPU must exist and have been parented into the cluster before the
+     * cluster is realized.
+     */
+    qdev_realize(DEVICE(&s->e_cluster), NULL, &error_abort);
+    qdev_realize(DEVICE(&s->u_cluster), NULL, &error_abort);
+
+    /* E51 DTIM */
+    memory_region_init_ram(e51_dtim_mem, NULL, "microchip.pfsoc.e51_dtim_mem",
+                           memmap[MICROCHIP_PFSOC_E51_DTIM].size, &error_fatal);
+    memory_region_add_subregion(system_memory,
+                                memmap[MICROCHIP_PFSOC_E51_DTIM].base,
+                                e51_dtim_mem);
+
+    /* Bus Error Units */
+    create_unimplemented_device("microchip.pfsoc.buserr_unit0_mem",
+        memmap[MICROCHIP_PFSOC_BUSERR_UNIT0].base,
+        memmap[MICROCHIP_PFSOC_BUSERR_UNIT0].size);
+    create_unimplemented_device("microchip.pfsoc.buserr_unit1_mem",
+        memmap[MICROCHIP_PFSOC_BUSERR_UNIT1].base,
+        memmap[MICROCHIP_PFSOC_BUSERR_UNIT1].size);
+    create_unimplemented_device("microchip.pfsoc.buserr_unit2_mem",
+        memmap[MICROCHIP_PFSOC_BUSERR_UNIT2].base,
+        memmap[MICROCHIP_PFSOC_BUSERR_UNIT2].size);
+    create_unimplemented_device("microchip.pfsoc.buserr_unit3_mem",
+        memmap[MICROCHIP_PFSOC_BUSERR_UNIT3].base,
+        memmap[MICROCHIP_PFSOC_BUSERR_UNIT3].size);
+    create_unimplemented_device("microchip.pfsoc.buserr_unit4_mem",
+        memmap[MICROCHIP_PFSOC_BUSERR_UNIT4].base,
+        memmap[MICROCHIP_PFSOC_BUSERR_UNIT4].size);
+
+    /* CLINT */
+    sifive_clint_create(memmap[MICROCHIP_PFSOC_CLINT].base,
+        memmap[MICROCHIP_PFSOC_CLINT].size, ms->smp.cpus,
+        SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, false);
+
+    /* L2 cache controller */
+    create_unimplemented_device("microchip.pfsoc.l2cc",
+        memmap[MICROCHIP_PFSOC_L2CC].base, memmap[MICROCHIP_PFSOC_L2CC].size);
+
+    /*
+     * Add L2-LIM at reset size.
+     * This should be reduced in size as the L2 Cache Controller WayEnable
+     * register is incremented. Unfortunately I don't see a nice (or any) way
+     * to handle reducing or blocking out the L2 LIM while still allowing it
+     * be re returned to all enabled after a reset. For the time being, just
+     * leave it enabled all the time. This won't break anything, but will be
+     * too generous to misbehaving guests.
+     */
+    memory_region_init_ram(l2lim_mem, NULL, "microchip.pfsoc.l2lim",
+                           memmap[MICROCHIP_PFSOC_L2LIM].size, &error_fatal);
+    memory_region_add_subregion(system_memory,
+                                memmap[MICROCHIP_PFSOC_L2LIM].base,
+                                l2lim_mem);
+
+    /* create PLIC hart topology configuration string */
+    plic_hart_config_len = (strlen(MICROCHIP_PFSOC_PLIC_HART_CONFIG) + 1) *
+                           ms->smp.cpus;
+    plic_hart_config = g_malloc0(plic_hart_config_len);
+    for (i = 0; i < ms->smp.cpus; i++) {
+        if (i != 0) {
+            strncat(plic_hart_config, "," MICROCHIP_PFSOC_PLIC_HART_CONFIG,
+                    plic_hart_config_len);
+        } else {
+            strncat(plic_hart_config, "M", plic_hart_config_len);
+        }
+        plic_hart_config_len -= (strlen(MICROCHIP_PFSOC_PLIC_HART_CONFIG) + 1);
+    }
+
+    /* PLIC */
+    s->plic = sifive_plic_create(memmap[MICROCHIP_PFSOC_PLIC].base,
+        plic_hart_config,
+        MICROCHIP_PFSOC_PLIC_NUM_SOURCES,
+        MICROCHIP_PFSOC_PLIC_NUM_PRIORITIES,
+        MICROCHIP_PFSOC_PLIC_PRIORITY_BASE,
+        MICROCHIP_PFSOC_PLIC_PENDING_BASE,
+        MICROCHIP_PFSOC_PLIC_ENABLE_BASE,
+        MICROCHIP_PFSOC_PLIC_ENABLE_STRIDE,
+        MICROCHIP_PFSOC_PLIC_CONTEXT_BASE,
+        MICROCHIP_PFSOC_PLIC_CONTEXT_STRIDE,
+        memmap[MICROCHIP_PFSOC_PLIC].size);
+    g_free(plic_hart_config);
+
+    /* SYSREG */
+    create_unimplemented_device("microchip.pfsoc.sysreg",
+        memmap[MICROCHIP_PFSOC_SYSREG].base,
+        memmap[MICROCHIP_PFSOC_SYSREG].size);
+
+    /* MPUCFG */
+    create_unimplemented_device("microchip.pfsoc.mpucfg",
+        memmap[MICROCHIP_PFSOC_MPUCFG].base,
+        memmap[MICROCHIP_PFSOC_MPUCFG].size);
+
+    /* eNVM */
+    memory_region_init_rom(envm_data, OBJECT(dev), "microchip.pfsoc.envm.data",
+                           memmap[MICROCHIP_PFSOC_ENVM_DATA].size,
+                           &error_fatal);
+    memory_region_add_subregion(system_memory,
+                                memmap[MICROCHIP_PFSOC_ENVM_DATA].base,
+                                envm_data);
+
+    /* IOSCBCFG */
+    create_unimplemented_device("microchip.pfsoc.ioscb.cfg",
+        memmap[MICROCHIP_PFSOC_IOSCB_CFG].base,
+        memmap[MICROCHIP_PFSOC_IOSCB_CFG].size);
+}
+
+static void microchip_pfsoc_soc_class_init(ObjectClass *oc, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+
+    dc->realize = microchip_pfsoc_soc_realize;
+    /* Reason: Uses serial_hds in realize function, thus can't be used twice */
+    dc->user_creatable = false;
+}
+
+static const TypeInfo microchip_pfsoc_soc_type_info = {
+    .name = TYPE_MICROCHIP_PFSOC,
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(MicrochipPFSoCState),
+    .instance_init = microchip_pfsoc_soc_instance_init,
+    .class_init = microchip_pfsoc_soc_class_init,
+};
+
+static void microchip_pfsoc_soc_register_types(void)
+{
+    type_register_static(&microchip_pfsoc_soc_type_info);
+}
+
+type_init(microchip_pfsoc_soc_register_types)
+
+static void microchip_icicle_kit_machine_init(MachineState *machine)
+{
+    MachineClass *mc = MACHINE_GET_CLASS(machine);
+    const struct MemmapEntry *memmap = microchip_pfsoc_memmap;
+    MicrochipIcicleKitState *s = MICROCHIP_ICICLE_KIT_MACHINE(machine);
+    MemoryRegion *system_memory = get_system_memory();
+    MemoryRegion *main_mem = g_new(MemoryRegion, 1);
+
+    /* Sanity check on RAM size */
+    if (machine->ram_size < mc->default_ram_size) {
+        char *sz = size_to_str(mc->default_ram_size);
+        error_report("Invalid RAM size, should be bigger than %s", sz);
+        g_free(sz);
+        exit(EXIT_FAILURE);
+    }
+
+    /* Initialize SoC */
+    object_initialize_child(OBJECT(machine), "soc", &s->soc,
+                            TYPE_MICROCHIP_PFSOC);
+    qdev_realize(DEVICE(&s->soc), NULL, &error_abort);
+
+    /* Register RAM */
+    memory_region_init_ram(main_mem, NULL, "microchip.icicle.kit.ram",
+                           machine->ram_size, &error_fatal);
+    memory_region_add_subregion(system_memory,
+                                memmap[MICROCHIP_PFSOC_DRAM].base, main_mem);
+
+    /* Load the firmware */
+    riscv_find_and_load_firmware(machine, BIOS_FILENAME, RESET_VECTOR, NULL);
+}
+
+static void microchip_icicle_kit_machine_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+
+    mc->desc = "Microchip PolarFire SoC Icicle Kit";
+    mc->init = microchip_icicle_kit_machine_init;
+    mc->max_cpus = MICROCHIP_PFSOC_MANAGEMENT_CPU_COUNT +
+                   MICROCHIP_PFSOC_COMPUTE_CPU_COUNT;
+    mc->min_cpus = MICROCHIP_PFSOC_MANAGEMENT_CPU_COUNT + 1;
+    mc->default_cpus = mc->min_cpus;
+    mc->default_ram_size = 1 * GiB;
+}
+
+static const TypeInfo microchip_icicle_kit_machine_typeinfo = {
+    .name       = MACHINE_TYPE_NAME("microchip-icicle-kit"),
+    .parent     = TYPE_MACHINE,
+    .class_init = microchip_icicle_kit_machine_class_init,
+    .instance_size = sizeof(MicrochipIcicleKitState),
+};
+
+static void microchip_icicle_kit_machine_init_register_types(void)
+{
+    type_register_static(&microchip_icicle_kit_machine_typeinfo);
+}
+
+type_init(microchip_icicle_kit_machine_init_register_types)
include/hw/riscv/microchip_pfsoc.h new file +88 -1
new file mode 100644
index 0000000..1953ef1
@@ -0,0 +1,88 @@
+/*
+ * Microchip PolarFire SoC machine interface
+ *
+ * Copyright (c) 2020 Wind River Systems, Inc.
+ *
+ * Author:
+ *   Bin Meng <[email protected]>
+ *
+ * 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_MICROCHIP_PFSOC_H
+#define HW_MICROCHIP_PFSOC_H
+
+typedef struct MicrochipPFSoCState {
+    /*< private >*/
+    DeviceState parent_obj;
+
+    /*< public >*/
+    CPUClusterState e_cluster;
+    CPUClusterState u_cluster;
+    RISCVHartArrayState e_cpus;
+    RISCVHartArrayState u_cpus;
+    DeviceState *plic;
+} MicrochipPFSoCState;
+
+#define TYPE_MICROCHIP_PFSOC    "microchip.pfsoc"
+#define MICROCHIP_PFSOC(obj) \
+    OBJECT_CHECK(MicrochipPFSoCState, (obj), TYPE_MICROCHIP_PFSOC)
+
+typedef struct MicrochipIcicleKitState {
+    /*< private >*/
+    MachineState parent_obj;
+
+    /*< public >*/
+    MicrochipPFSoCState soc;
+} MicrochipIcicleKitState;
+
+#define TYPE_MICROCHIP_ICICLE_KIT_MACHINE \
+    MACHINE_TYPE_NAME("microchip-icicle-kit")
+#define MICROCHIP_ICICLE_KIT_MACHINE(obj) \
+    OBJECT_CHECK(MicrochipIcicleKitState, (obj), \
+                 TYPE_MICROCHIP_ICICLE_KIT_MACHINE)
+
+enum {
+    MICROCHIP_PFSOC_DEBUG,
+    MICROCHIP_PFSOC_E51_DTIM,
+    MICROCHIP_PFSOC_BUSERR_UNIT0,
+    MICROCHIP_PFSOC_BUSERR_UNIT1,
+    MICROCHIP_PFSOC_BUSERR_UNIT2,
+    MICROCHIP_PFSOC_BUSERR_UNIT3,
+    MICROCHIP_PFSOC_BUSERR_UNIT4,
+    MICROCHIP_PFSOC_CLINT,
+    MICROCHIP_PFSOC_L2CC,
+    MICROCHIP_PFSOC_L2LIM,
+    MICROCHIP_PFSOC_PLIC,
+    MICROCHIP_PFSOC_SYSREG,
+    MICROCHIP_PFSOC_MPUCFG,
+    MICROCHIP_PFSOC_ENVM_CFG,
+    MICROCHIP_PFSOC_ENVM_DATA,
+    MICROCHIP_PFSOC_IOSCB_CFG,
+    MICROCHIP_PFSOC_DRAM,
+};
+
+#define MICROCHIP_PFSOC_MANAGEMENT_CPU_COUNT    1
+#define MICROCHIP_PFSOC_COMPUTE_CPU_COUNT       4
+
+#define MICROCHIP_PFSOC_PLIC_HART_CONFIG        "MS"
+#define MICROCHIP_PFSOC_PLIC_NUM_SOURCES        185
+#define MICROCHIP_PFSOC_PLIC_NUM_PRIORITIES     7
+#define MICROCHIP_PFSOC_PLIC_PRIORITY_BASE      0x04
+#define MICROCHIP_PFSOC_PLIC_PENDING_BASE       0x1000
+#define MICROCHIP_PFSOC_PLIC_ENABLE_BASE        0x2000
+#define MICROCHIP_PFSOC_PLIC_ENABLE_STRIDE      0x80
+#define MICROCHIP_PFSOC_PLIC_CONTEXT_BASE       0x200000
+#define MICROCHIP_PFSOC_PLIC_CONTEXT_STRIDE     0x1000
+
+#endif /* HW_MICROCHIP_PFSOC_H */
--

2.7.4

author
#9 lore raw

PATCH 5/18 hw/char: Add Microchip PolarFire SoC MMUART emulation

In reply to Bin Meng

From: Bin Meng <[email protected]>

Microchip PolarFire SoC MMUART is ns16550 compatible, with some additional registers. Create a simple MMUART model built on top of the existing ns16550 model.

---

 MAINTAINERS                         |  2 +
 hw/char/Kconfig                     |  3 ++
 hw/char/Makefile.objs               |  1 +
 hw/char/mchp_pfsoc_mmuart.c         | 82 +++++++++++++++++++++++++++++++++++++
 include/hw/char/mchp_pfsoc_mmuart.h | 61 +++++++++++++++++++++++++++
 5 files changed, 149 insertions(+)
 create mode 100644 hw/char/mchp_pfsoc_mmuart.c
 create mode 100644 include/hw/char/mchp_pfsoc_mmuart.h
MAINTAINERS +2 -0
index 8716cb6..e51edac 100644
@@ -1319,7 +1319,9 @@ M: Bin Meng <[email protected]>
 L: [email protected]
 S: Supported
 F: hw/riscv/microchip_pfsoc.c
+F: hw/char/mchp_pfsoc_mmuart.c
 F: include/hw/riscv/microchip_pfsoc.h
+F: include/hw/char/mchp_pfsoc_mmuart.h
 
 RX Machines
 -----------
hw/char/Kconfig +3 -0
index b7e0e4d..1d64555 100644
@@ -52,3 +52,6 @@ config RENESAS_SCI
 
 config AVR_USART
     bool
+
+config MCHP_PFSOC_MMUART
+    bool
hw/char/Makefile.objs +1 -0
index bf177ac..f705845 100644
@@ -33,6 +33,7 @@ common-obj-$(CONFIG_LM32) += lm32_juart.o
 common-obj-$(CONFIG_LM32) += lm32_uart.o
 common-obj-$(CONFIG_MILKYMIST) += milkymist-uart.o
 common-obj-$(CONFIG_SCLPCONSOLE) += sclpconsole.o sclpconsole-lm.o
+common-obj-$(CONFIG_MCHP_PFSOC_MMUART) += mchp_pfsoc_mmuart.o
 
 obj-$(CONFIG_VIRTIO) += virtio-serial-bus.o
 obj-$(CONFIG_PSERIES) += spapr_vty.o
hw/char/mchp_pfsoc_mmuart.c new file +82 -0

82 lines not on this page · raw message

include/hw/char/mchp_pfsoc_mmuart.h new file +61 -0

61 lines not on this page · raw message

Signature · 1 line
2.7.4
#10 lore raw

Re: [PATCH 05/18] hw/char: Add Microchip PolarFire SoC MMUART emulation

Quoted 85 lines · Bin Meng

From: Bin Meng <[email protected]>

Microchip PolarFire SoC MMUART is ns16550 compatible, with some additional registers. Create a simple MMUART model built on top of the existing ns16550 model.

---

 MAINTAINERS                         |  2 +
 hw/char/Kconfig                     |  3 ++
 hw/char/Makefile.objs               |  1 +
 hw/char/mchp_pfsoc_mmuart.c         | 82 +++++++++++++++++++++++++++++++++++++
 include/hw/char/mchp_pfsoc_mmuart.h | 61 +++++++++++++++++++++++++++
 5 files changed, 149 insertions(+)
 create mode 100644 hw/char/mchp_pfsoc_mmuart.c
 create mode 100644 include/hw/char/mchp_pfsoc_mmuart.h
MAINTAINERS +2 -0
index 8716cb6..e51edac 100644
@@ -1319,7 +1319,9 @@ M: Bin Meng <[email protected]>
 L: [email protected]
 S: Supported
 F: hw/riscv/microchip_pfsoc.c
+F: hw/char/mchp_pfsoc_mmuart.c
 F: include/hw/riscv/microchip_pfsoc.h
+F: include/hw/char/mchp_pfsoc_mmuart.h
 
 RX Machines
 -----------
hw/char/Kconfig +3 -0
index b7e0e4d..1d64555 100644
@@ -52,3 +52,6 @@ config RENESAS_SCI
 
 config AVR_USART
     bool
+
+config MCHP_PFSOC_MMUART
+    bool
hw/char/Makefile.objs +1 -0
index bf177ac..f705845 100644
@@ -33,6 +33,7 @@ common-obj-$(CONFIG_LM32) += lm32_juart.o
 common-obj-$(CONFIG_LM32) += lm32_uart.o
 common-obj-$(CONFIG_MILKYMIST) += milkymist-uart.o
 common-obj-$(CONFIG_SCLPCONSOLE) += sclpconsole.o sclpconsole-lm.o
+common-obj-$(CONFIG_MCHP_PFSOC_MMUART) += mchp_pfsoc_mmuart.o
 
 obj-$(CONFIG_VIRTIO) += virtio-serial-bus.o
 obj-$(CONFIG_PSERIES) += spapr_vty.o
hw/char/mchp_pfsoc_mmuart.c new file +23 -0
new file mode 100644
index 0000000..9984acc
@@ -0,0 +1,82 @@
+/*
+ * Microchip PolarFire SoC MMUART emulation
+ *
+ * Copyright (c) 2020 Wind River Systems, Inc.
+ *
+ * Author:
+ *   Bin Meng <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 or
+ * (at your option) version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "qemu/osdep.h"

hw/char/mchp_pfsoc_mmuart.c line 33

Quoted 10 lines
hw/char/mchp_pfsoc_mmuart.c new file +10 -0
+#include "qemu/log.h"
+#include "chardev/char.h"
+#include "exec/address-spaces.h"
+#include "hw/char/mchp_pfsoc_mmuart.h"
+
+static uint64_t mchp_pfsoc_mmuart_read(void *opaque, hwaddr addr, unsigned size)
+{
+    MchpPfSoCMMUartState *s = opaque;
+
+    if ((addr % sizeof(uint32_t)) || (addr >= 0x34)) {

You can specify impl.min_access_size and impl.max_access_size as part of MemoryRegionOps so the allignment check isn't required here.

Quoted 5 lines
hw/char/mchp_pfsoc_mmuart.c new file +5 -0
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: read: addr=0x%" HWADDR_PRIx "\n",
+                      __func__, addr);
+        return 0;
+    }
+

hw/char/mchp_pfsoc_mmuart.c line 48

Quoted 10 lines
hw/char/mchp_pfsoc_mmuart.c new file +10 -0
+    return s->reg[addr / sizeof(uint32_t)];
+}
+
+static void mchp_pfsoc_mmuart_write(void *opaque, hwaddr addr,
+                                    uint64_t value, unsigned size)
+{
+    MchpPfSoCMMUartState *s = opaque;
+    uint32_t val32 = (uint32_t)value;
+
+    if ((addr % sizeof(uint32_t)) || (addr >= 0x34)) {

Same comment here about allignment.

Alistair

Quoted 105 lines
hw/char/mchp_pfsoc_mmuart.c new file +34 -0
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: bad write: addr=0x%" HWADDR_PRIx
+                      " v=0x%x\n", __func__, addr, val32);
+        return;
+    }
+
+    s->reg[addr / sizeof(uint32_t)] = val32;
+}
+
+static const MemoryRegionOps mchp_pfsoc_mmuart_ops = {
+    .read = mchp_pfsoc_mmuart_read,
+    .write = mchp_pfsoc_mmuart_write,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+};
+
+MchpPfSoCMMUartState *mchp_pfsoc_mmuart_create(MemoryRegion *sysmem,
+    hwaddr base, qemu_irq irq, Chardev *chr)
+{
+    MchpPfSoCMMUartState *s;
+
+    s = g_new0(MchpPfSoCMMUartState, 1);
+
+    memory_region_init_io(&s->iomem, NULL, &mchp_pfsoc_mmuart_ops, s,
+                          "mchp.pfsoc.mmuart", 0x1000);
+
+    s->base = base;
+    s->irq = irq;
+
+    s->serial = serial_mm_init(sysmem, base, 2, irq, 399193, chr,
+                               DEVICE_LITTLE_ENDIAN);
+
+    memory_region_add_subregion(sysmem, base + 0x20, &s->iomem);
+
+    return s;
+}
include/hw/char/mchp_pfsoc_mmuart.h new file +61 -1
new file mode 100644
index 0000000..f619902
@@ -0,0 +1,61 @@
+/*
+ * Microchip PolarFire SoC MMUART emulation
+ *
+ * Copyright (c) 2020 Wind River Systems, Inc.
+ *
+ * Author:
+ *   Bin Meng <[email protected]>
+ *
+ * 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.
+ */
+
+#ifndef HW_MCHP_PFSOC_MMUART_H
+#define HW_MCHP_PFSOC_MMUART_H
+
+#include "hw/char/serial.h"
+
+#define MCHP_PFSOC_MMUART_REG_SIZE  52
+
+typedef struct MchpPfSoCMMUartState {
+    MemoryRegion iomem;
+    hwaddr base;
+    qemu_irq irq;
+
+    SerialMM *serial;
+
+    uint32_t reg[MCHP_PFSOC_MMUART_REG_SIZE / sizeof(uint32_t)];
+} MchpPfSoCMMUartState;
+
+/**
+ * mchp_pfsoc_mmuart_create - Create a Microchip PolarFire SoC MMUART
+ *
+ * This is a helper routine for board to create a MMUART device that is
+ * compatible with Microchip PolarFire SoC.
+ *
+ * @sysmem: system memory region to map
+ * @base: base address of the MMUART registers
+ * @irq: IRQ number of the MMUART device
+ * @chr: character device to associate to
+ *
+ * @return: a pointer to the device specific control structure
+ */
+MchpPfSoCMMUartState *mchp_pfsoc_mmuart_create(MemoryRegion *sysmem,
+    hwaddr base, qemu_irq irq, Chardev *chr);
+
+#endif /* HW_MCHP_PFSOC_MMUART_H */
--

2.7.4

author
#11 lore raw

PATCH 6/18 hw/riscv: microchip_pfsoc: Connect 5 MMUARTs

In reply to Bin Meng

From: Bin Meng <[email protected]>

Microchip PolarFire SoC has 5 MMUARTs, and the Icicle Kit board wires 4 of them out. Let's connect all 5 MMUARTs.

---

 hw/riscv/Kconfig                   |  1 +
 hw/riscv/microchip_pfsoc.c         | 30 ++++++++++++++++++++++++++++++
 include/hw/riscv/microchip_pfsoc.h | 20 ++++++++++++++++++++
 3 files changed, 51 insertions(+)
hw/riscv/Kconfig +1 -0
index 3292fae..ceb7c16 100644
@@ -54,3 +54,4 @@ config MICROCHIP_PFSOC
     select HART
     select SIFIVE
     select UNIMP
+    select MCHP_PFSOC_MMUART
hw/riscv/microchip_pfsoc.c +30 -0
index 20a642c..f6b375c 100644
@@ -11,6 +11,7 @@
  * 0) CLINT (Core Level Interruptor)
  * 1) PLIC (Platform Level Interrupt Controller)
  * 2) eNVM (Embedded Non-Volatile Memory)
+ * 3) MMUARTs (Multi-Mode UART)
  *
  * This board currently generates devicetree dynamically that indicates at least
  * two harts and up to five harts.
@@ -38,6 +39,7 @@
 #include "hw/irq.h"
 #include "hw/loader.h"
 #include "hw/sysbus.h"
+#include "chardev/char.h"
 #include "hw/cpu/cluster.h"
 #include "target/riscv/cpu.h"
 #include "hw/misc/unimp.h"
@@ -46,6 +48,7 @@
 #include "hw/riscv/sifive_clint.h"
 #include "hw/riscv/sifive_plic.h"
 #include "hw/riscv/microchip_pfsoc.h"
+#include "sysemu/sysemu.h"
 
 /*
  * The BIOS image used by this machine is called Hart Software Services (HSS).
@@ -69,8 +72,13 @@ static const struct MemmapEntry {
     [MICROCHIP_PFSOC_L2CC] =            {  0x2010000,     0x1000 },
     [MICROCHIP_PFSOC_L2LIM] =           {  0x8000000,  0x2000000 },
     [MICROCHIP_PFSOC_PLIC] =            {  0xc000000,  0x4000000 },
+    [MICROCHIP_PFSOC_MMUART0] =         { 0x20000000,     0x1000 },
     [MICROCHIP_PFSOC_SYSREG] =          { 0x20002000,     0x2000 },
     [MICROCHIP_PFSOC_MPUCFG] =          { 0x20005000,     0x1000 },
+    [MICROCHIP_PFSOC_MMUART1] =         { 0x20100000,     0x1000 },
+    [MICROCHIP_PFSOC_MMUART2] =         { 0x20102000,     0x1000 },
+    [MICROCHIP_PFSOC_MMUART3] =         { 0x20104000,     0x1000 },
+    [MICROCHIP_PFSOC_MMUART4] =         { 0x20106000,     0x1000 },
     [MICROCHIP_PFSOC_ENVM_CFG] =        { 0x20200000,     0x1000 },
     [MICROCHIP_PFSOC_ENVM_DATA] =       { 0x20220000,    0x20000 },
     [MICROCHIP_PFSOC_IOSCB_CFG] =       { 0x37080000,     0x1000 },
@@ -215,6 +223,28 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
         memmap[MICROCHIP_PFSOC_MPUCFG].base,
         memmap[MICROCHIP_PFSOC_MPUCFG].size);
 
+    /* MMUARTs */
+    s->serial0 = mchp_pfsoc_mmuart_create(system_memory,
+        memmap[MICROCHIP_PFSOC_MMUART0].base,
+        qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_MMUART0_IRQ),
+        serial_hd(0));
+    s->serial1 = mchp_pfsoc_mmuart_create(system_memory,
+        memmap[MICROCHIP_PFSOC_MMUART1].base,
+        qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_MMUART1_IRQ),
+        serial_hd(1));
+    s->serial2 = mchp_pfsoc_mmuart_create(system_memory,
+        memmap[MICROCHIP_PFSOC_MMUART2].base,
+        qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_MMUART2_IRQ),
+        serial_hd(2));
+    s->serial3 = mchp_pfsoc_mmuart_create(system_memory,
+        memmap[MICROCHIP_PFSOC_MMUART3].base,
+        qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_MMUART3_IRQ),
+        serial_hd(3));
+    s->serial4 = mchp_pfsoc_mmuart_create(system_memory,
+        memmap[MICROCHIP_PFSOC_MMUART4].base,
+        qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_MMUART4_IRQ),
+        serial_hd(4));
+
     /* eNVM */
     memory_region_init_rom(envm_data, OBJECT(dev), "microchip.pfsoc.envm.data",
                            memmap[MICROCHIP_PFSOC_ENVM_DATA].size,
include/hw/riscv/microchip_pfsoc.h +20 -0
index 1953ef1..a5efa1d 100644
@@ -22,6 +22,8 @@
 #ifndef HW_MICROCHIP_PFSOC_H
 #define HW_MICROCHIP_PFSOC_H
 
+#include "hw/char/mchp_pfsoc_mmuart.h"
+
 typedef struct MicrochipPFSoCState {
     /*< private >*/
     DeviceState parent_obj;
@@ -32,6 +34,11 @@ typedef struct MicrochipPFSoCState {
     RISCVHartArrayState e_cpus;
     RISCVHartArrayState u_cpus;
     DeviceState *plic;
+    MchpPfSoCMMUartState *serial0;
+    MchpPfSoCMMUartState *serial1;
+    MchpPfSoCMMUartState *serial2;
+    MchpPfSoCMMUartState *serial3;
+    MchpPfSoCMMUartState *serial4;
 } MicrochipPFSoCState;
 
 #define TYPE_MICROCHIP_PFSOC    "microchip.pfsoc"
@@ -64,14 +71,27 @@ enum {
     MICROCHIP_PFSOC_L2CC,
     MICROCHIP_PFSOC_L2LIM,
     MICROCHIP_PFSOC_PLIC,
+    MICROCHIP_PFSOC_MMUART0,
     MICROCHIP_PFSOC_SYSREG,
     MICROCHIP_PFSOC_MPUCFG,
+    MICROCHIP_PFSOC_MMUART1,
+    MICROCHIP_PFSOC_MMUART2,
+    MICROCHIP_PFSOC_MMUART3,
+    MICROCHIP_PFSOC_MMUART4,
     MICROCHIP_PFSOC_ENVM_CFG,
     MICROCHIP_PFSOC_ENVM_DATA,
     MICROCHIP_PFSOC_IOSCB_CFG,
     MICROCHIP_PFSOC_DRAM,
 };
 
+enum {
+    MICROCHIP_PFSOC_MMUART0_IRQ = 90,
+    MICROCHIP_PFSOC_MMUART1_IRQ = 91,
+    MICROCHIP_PFSOC_MMUART2_IRQ = 92,
+    MICROCHIP_PFSOC_MMUART3_IRQ = 93,
+    MICROCHIP_PFSOC_MMUART4_IRQ = 94,
+};
+
 #define MICROCHIP_PFSOC_MANAGEMENT_CPU_COUNT    1
 #define MICROCHIP_PFSOC_COMPUTE_CPU_COUNT       4
 
Signature · 1 line
2.7.4
Reviewed-by on v1 6/18
#12 lore raw

Re: [PATCH 06/18] hw/riscv: microchip_pfsoc: Connect 5 MMUARTs

Quoted 7 lines · Bin Meng

From: Bin Meng <[email protected]>

Microchip PolarFire SoC has 5 MMUARTs, and the Icicle Kit board wires 4 of them out. Let's connect all 5 MMUARTs.

Alistair

Quoted 144 lines

---

 hw/riscv/Kconfig                   |  1 +
 hw/riscv/microchip_pfsoc.c         | 30 ++++++++++++++++++++++++++++++
 include/hw/riscv/microchip_pfsoc.h | 20 ++++++++++++++++++++
 3 files changed, 51 insertions(+)
hw/riscv/Kconfig +1 -0
index 3292fae..ceb7c16 100644
@@ -54,3 +54,4 @@ config MICROCHIP_PFSOC
     select HART
     select SIFIVE
     select UNIMP
+    select MCHP_PFSOC_MMUART
hw/riscv/microchip_pfsoc.c +30 -0
index 20a642c..f6b375c 100644
@@ -11,6 +11,7 @@
  * 0) CLINT (Core Level Interruptor)
  * 1) PLIC (Platform Level Interrupt Controller)
  * 2) eNVM (Embedded Non-Volatile Memory)
+ * 3) MMUARTs (Multi-Mode UART)
  *
  * This board currently generates devicetree dynamically that indicates at least
  * two harts and up to five harts.
@@ -38,6 +39,7 @@
 #include "hw/irq.h"
 #include "hw/loader.h"
 #include "hw/sysbus.h"
+#include "chardev/char.h"
 #include "hw/cpu/cluster.h"
 #include "target/riscv/cpu.h"
 #include "hw/misc/unimp.h"
@@ -46,6 +48,7 @@
 #include "hw/riscv/sifive_clint.h"
 #include "hw/riscv/sifive_plic.h"
 #include "hw/riscv/microchip_pfsoc.h"
+#include "sysemu/sysemu.h"
 
 /*
  * The BIOS image used by this machine is called Hart Software Services (HSS).
@@ -69,8 +72,13 @@ static const struct MemmapEntry {
     [MICROCHIP_PFSOC_L2CC] =            {  0x2010000,     0x1000 },
     [MICROCHIP_PFSOC_L2LIM] =           {  0x8000000,  0x2000000 },
     [MICROCHIP_PFSOC_PLIC] =            {  0xc000000,  0x4000000 },
+    [MICROCHIP_PFSOC_MMUART0] =         { 0x20000000,     0x1000 },
     [MICROCHIP_PFSOC_SYSREG] =          { 0x20002000,     0x2000 },
     [MICROCHIP_PFSOC_MPUCFG] =          { 0x20005000,     0x1000 },
+    [MICROCHIP_PFSOC_MMUART1] =         { 0x20100000,     0x1000 },
+    [MICROCHIP_PFSOC_MMUART2] =         { 0x20102000,     0x1000 },
+    [MICROCHIP_PFSOC_MMUART3] =         { 0x20104000,     0x1000 },
+    [MICROCHIP_PFSOC_MMUART4] =         { 0x20106000,     0x1000 },
     [MICROCHIP_PFSOC_ENVM_CFG] =        { 0x20200000,     0x1000 },
     [MICROCHIP_PFSOC_ENVM_DATA] =       { 0x20220000,    0x20000 },
     [MICROCHIP_PFSOC_IOSCB_CFG] =       { 0x37080000,     0x1000 },
@@ -215,6 +223,28 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
         memmap[MICROCHIP_PFSOC_MPUCFG].base,
         memmap[MICROCHIP_PFSOC_MPUCFG].size);
 
+    /* MMUARTs */
+    s->serial0 = mchp_pfsoc_mmuart_create(system_memory,
+        memmap[MICROCHIP_PFSOC_MMUART0].base,
+        qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_MMUART0_IRQ),
+        serial_hd(0));
+    s->serial1 = mchp_pfsoc_mmuart_create(system_memory,
+        memmap[MICROCHIP_PFSOC_MMUART1].base,
+        qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_MMUART1_IRQ),
+        serial_hd(1));
+    s->serial2 = mchp_pfsoc_mmuart_create(system_memory,
+        memmap[MICROCHIP_PFSOC_MMUART2].base,
+        qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_MMUART2_IRQ),
+        serial_hd(2));
+    s->serial3 = mchp_pfsoc_mmuart_create(system_memory,
+        memmap[MICROCHIP_PFSOC_MMUART3].base,
+        qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_MMUART3_IRQ),
+        serial_hd(3));
+    s->serial4 = mchp_pfsoc_mmuart_create(system_memory,
+        memmap[MICROCHIP_PFSOC_MMUART4].base,
+        qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_MMUART4_IRQ),
+        serial_hd(4));
+
     /* eNVM */
     memory_region_init_rom(envm_data, OBJECT(dev), "microchip.pfsoc.envm.data",
                            memmap[MICROCHIP_PFSOC_ENVM_DATA].size,
include/hw/riscv/microchip_pfsoc.h +20 -1
index 1953ef1..a5efa1d 100644
@@ -22,6 +22,8 @@
 #ifndef HW_MICROCHIP_PFSOC_H
 #define HW_MICROCHIP_PFSOC_H
 
+#include "hw/char/mchp_pfsoc_mmuart.h"
+
 typedef struct MicrochipPFSoCState {
     /*< private >*/
     DeviceState parent_obj;
@@ -32,6 +34,11 @@ typedef struct MicrochipPFSoCState {
     RISCVHartArrayState e_cpus;
     RISCVHartArrayState u_cpus;
     DeviceState *plic;
+    MchpPfSoCMMUartState *serial0;
+    MchpPfSoCMMUartState *serial1;
+    MchpPfSoCMMUartState *serial2;
+    MchpPfSoCMMUartState *serial3;
+    MchpPfSoCMMUartState *serial4;
 } MicrochipPFSoCState;
 
 #define TYPE_MICROCHIP_PFSOC    "microchip.pfsoc"
@@ -64,14 +71,27 @@ enum {
     MICROCHIP_PFSOC_L2CC,
     MICROCHIP_PFSOC_L2LIM,
     MICROCHIP_PFSOC_PLIC,
+    MICROCHIP_PFSOC_MMUART0,
     MICROCHIP_PFSOC_SYSREG,
     MICROCHIP_PFSOC_MPUCFG,
+    MICROCHIP_PFSOC_MMUART1,
+    MICROCHIP_PFSOC_MMUART2,
+    MICROCHIP_PFSOC_MMUART3,
+    MICROCHIP_PFSOC_MMUART4,
     MICROCHIP_PFSOC_ENVM_CFG,
     MICROCHIP_PFSOC_ENVM_DATA,
     MICROCHIP_PFSOC_IOSCB_CFG,
     MICROCHIP_PFSOC_DRAM,
 };
 
+enum {
+    MICROCHIP_PFSOC_MMUART0_IRQ = 90,
+    MICROCHIP_PFSOC_MMUART1_IRQ = 91,
+    MICROCHIP_PFSOC_MMUART2_IRQ = 92,
+    MICROCHIP_PFSOC_MMUART3_IRQ = 93,
+    MICROCHIP_PFSOC_MMUART4_IRQ = 94,
+};
+
 #define MICROCHIP_PFSOC_MANAGEMENT_CPU_COUNT    1
 #define MICROCHIP_PFSOC_COMPUTE_CPU_COUNT       4
 
--

2.7.4

author
#13 lore raw

PATCH 7/18 hw/sd: sd: Fix incorrect populated function switch status data structure

In reply to Bin Meng

From: Bin Meng <[email protected]>

At present the function switch status data structure bit [399:376] are wrongly pupulated. These 3 bytes encode function switch status for the 6 function groups, with 4 bits per group, starting from function group 6 at bit 399, then followed by function group 5 at bit 395, and so on.

However the codes mistakenly fills in the function group 1 status at bit 399. This fixes the code logic.

---

 hw/sd/sd.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/sd/sd.c +5 -1
index fad9cf1..51f5900 100644
@@ -806,11 +806,15 @@ static void sd_function_switch(SDState *sd, uint32_t arg)
     sd->data[11] = 0x43;
     sd->data[12] = 0x80;	/* Supported group 1 functions */
     sd->data[13] = 0x03;
+
+    sd->data[14] = 0;
+    sd->data[15] = 0;
+    sd->data[16] = 0;
     for (i = 0; i < 6; i ++) {
         new_func = (arg >> (i * 4)) & 0x0f;
         if (mode && new_func != 0x0f)
             sd->function_group[i] = new_func;
-        sd->data[14 + (i >> 1)] = new_func << ((i * 4) & 4);
+        sd->data[16 - (i >> 1)] |= new_func << ((i % 2) * 4);
     }
     memset(&sd->data[17], 0, 47);
     stw_be_p(sd->data + 64, sd_crc16(sd->data, 64));
Signature · 1 line
2.7.4
Reviewed-by on v1 7/18
#14 lore raw

Re: [PATCH 07/18] hw/sd: sd: Fix incorrect populated function switch status data structure

+Sai Pavan

Quoted 11 lines · Bin Meng

From: Bin Meng <[email protected]>

At present the function switch status data structure bit [399:376] are wrongly pupulated. These 3 bytes encode function switch status for the 6 function groups, with 4 bits per group, starting from function group 6 at bit 399, then followed by function group 5 at bit 395, and so on.

However the codes mistakenly fills in the function group 1 status at bit 399. This fixes the code logic.

Fixes a1bb27b1e9 ("SD card emulation (initial implementation)")
Quoted 11 lines

---

 hw/sd/sd.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/sd/sd.c +0 -0
index fad9cf1..51f5900 100644

hw/sd/sd.c static void sd_function_switch(SDState *sd, uint32_t arg) · line 812

Quoted 7 lines
hw/sd/sd.c +4 -0
@@ -806,11 +806,15 @@ static void sd_function_switch(SDState *sd, uint32_t arg)
     sd->data[11] = 0x43;
     sd->data[12] = 0x80;	/* Supported group 1 functions */
     sd->data[13] = 0x03;
+
+    sd->data[14] = 0;
+    sd->data[15] = 0;
+    sd->data[16] = 0;

Pointless zero initialization.

I'll wait until next week in case Sai Pavan wants to test this patch (I don't have access to the Xilinx images anymore) then I'll queue this via my sd-next tree.

Regards,

Phil.

Quoted 10 lines
hw/sd/sd.c +1 -1
     for (i = 0; i < 6; i ++) {
         new_func = (arg >> (i * 4)) & 0x0f;
         if (mode && new_func != 0x0f)
             sd->function_group[i] = new_func;
-        sd->data[14 + (i >> 1)] = new_func << ((i * 4) & 4);
+        sd->data[16 - (i >> 1)] |= new_func << ((i % 2) * 4);
     }
     memset(&sd->data[17], 0, 47);
     stw_be_p(sd->data + 64, sd_crc16(sd->data, 64));
#15 lore raw

RE: [PATCH 07/18] hw/sd: sd: Fix incorrect populated function switch status data structure

Thanks Philippe,

I would test this and get back.

Regards,
Sai Pavan

Quoted 70 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]> On Behalf Of Philippe Mathieu-Daudé
Sent: Saturday, August 15, 2020 1:29 PM
To: Bin Meng <[email protected]>; Alistair Francis <[email protected]>; Bastian Koppelmann <[email protected] paderborn.de>; Palmer Dabbelt <[email protected]>; Sagar Karandikar <[email protected]>; [email protected]; qemu- [email protected]; Sai Pavan Boddu <[email protected]>
Cc: Bin Meng <[email protected]>; [email protected]
Subject: Re: [PATCH 07/18] hw/sd: sd: Fix incorrect populated function switch status data structure

+Sai Pavan

Quoted 10 lines · Bin Meng

From: Bin Meng <[email protected]>

At present the function switch status data structure bit [399:376] are wrongly pupulated. These 3 bytes encode function switch status for the 6 function groups, with 4 bits per group, starting from function group 6 at bit 399, then followed by function group 5 at bit 395, and so on.

However the codes mistakenly fills in the function group 1 status at bit 399. This fixes the code logic.

Fixes a1bb27b1e9 ("SD card emulation (initial implementation)")

hw/sd/sd.c static void sd_function_switch(SDState *sd,

Quoted 11 lines

---

 hw/sd/sd.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/sd/sd.c +0 -0
index fad9cf1..51f5900 100644
@@ -806,11 +806,15 @@ static void sd_function_switch(SDState *sd,

uint32_t arg)

hw/sd/sd.c static void sd_function_switch(SDState *sd, uint32_t arg) · line 812

Quoted 7 lines
hw/sd/sd.c +4 -0
     sd->data[11] = 0x43;
     sd->data[12] = 0x80;	/* Supported group 1 functions */
     sd->data[13] = 0x03;
+
+    sd->data[14] = 0;
+    sd->data[15] = 0;
+    sd->data[16] = 0;

Pointless zero initialization.

I'll wait until next week in case Sai Pavan wants to test this patch (I don't have access to the Xilinx images anymore) then I'll queue this via my sd-next tree.

Regards,

Phil.

Quoted 10 lines
hw/sd/sd.c +1 -1
     for (i = 0; i < 6; i ++) {
         new_func = (arg >> (i * 4)) & 0x0f;
         if (mode && new_func != 0x0f)
             sd->function_group[i] = new_func;
-        sd->data[14 + (i >> 1)] = new_func << ((i * 4) & 4);
+        sd->data[16 - (i >> 1)] |= new_func << ((i % 2) * 4);
     }
     memset(&sd->data[17], 0, 47);
     stw_be_p(sd->data + 64, sd_crc16(sd->data, 64));
#16 lore raw

Re: [PATCH 07/18] hw/sd: sd: Fix incorrect populated function switch status data structure

Hi Philippe,

First two patch of SD look good. Tested them over zynqmp and versal platforms.

Thanks,
Sai Pavan

Quoted 78 lines · Sai Pavan Boddu

Thanks Philippe,

I would test this and get back.

Regards,
Sai Pavan

Quoted 70 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]> On Behalf Of Philippe Mathieu-Daudé
Sent: Saturday, August 15, 2020 1:29 PM
To: Bin Meng <[email protected]>; Alistair Francis <[email protected]>; Bastian Koppelmann <[email protected] paderborn.de>; Palmer Dabbelt <[email protected]>; Sagar Karandikar <[email protected]>; [email protected]; qemu- [email protected]; Sai Pavan Boddu <[email protected]>
Cc: Bin Meng <[email protected]>; [email protected]
Subject: Re: [PATCH 07/18] hw/sd: sd: Fix incorrect populated function switch status data structure

+Sai Pavan

Quoted 10 lines · Bin Meng

From: Bin Meng <[email protected]>

At present the function switch status data structure bit [399:376] are wrongly pupulated. These 3 bytes encode function switch status for the 6 function groups, with 4 bits per group, starting from function group 6 at bit 399, then followed by function group 5 at bit 395, and so on.

However the codes mistakenly fills in the function group 1 status at bit 399. This fixes the code logic.

Fixes a1bb27b1e9 ("SD card emulation (initial implementation)")

hw/sd/sd.c static void sd_function_switch(SDState *sd,

Quoted 11 lines

---

 hw/sd/sd.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/sd/sd.c +0 -0
index fad9cf1..51f5900 100644
@@ -806,11 +806,15 @@ static void sd_function_switch(SDState *sd,

uint32_t arg)

hw/sd/sd.c static void sd_function_switch(SDState *sd, uint32_t arg) · line 812

Quoted 7 lines
hw/sd/sd.c +4 -0
     sd->data[11] = 0x43;
     sd->data[12] = 0x80;	/* Supported group 1 functions */
     sd->data[13] = 0x03;
+
+    sd->data[14] = 0;
+    sd->data[15] = 0;
+    sd->data[16] = 0;

Pointless zero initialization.

I'll wait until next week in case Sai Pavan wants to test this patch (I don't have access to the Xilinx images anymore) then I'll queue this via my sd-next tree.

Regards,

Phil.

Quoted 10 lines
hw/sd/sd.c +1 -1
     for (i = 0; i < 6; i ++) {
         new_func = (arg >> (i * 4)) & 0x0f;
         if (mode && new_func != 0x0f)
             sd->function_group[i] = new_func;
-        sd->data[14 + (i >> 1)] = new_func << ((i * 4) & 4);
+        sd->data[16 - (i >> 1)] |= new_func << ((i % 2) * 4);
     }
     memset(&sd->data[17], 0, 47);
     stw_be_p(sd->data + 64, sd_crc16(sd->data, 64));
author
#17 lore raw

Re: [PATCH 07/18] hw/sd: sd: Fix incorrect populated function switch status data structure

Hi Sai,

Quoted 6 lines · Sai Pavan Boddu

Hi Philippe,

First two patch of SD look good. Tested them over zynqmp and versal platforms.

Thanks for testing.

Can I add your Tested-by tag?

Regards,
Bin

#18 lore raw

RE: [PATCH 07/18] hw/sd: sd: Fix incorrect populated function switch status data structure

Hi Bin,

Quoted 20 lines

-----Original Message-----
From: Bin Meng <[email protected]>
Sent: Friday, August 21, 2020 3:38 PM
To: Sai Pavan Boddu <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>; Alistair Francis <[email protected]>; Bastian Koppelmann <[email protected] paderborn.de>; Palmer Dabbelt <[email protected]>; Sagar Karandikar <[email protected]>; [email protected]; qemu- [email protected]; Bin Meng <[email protected]>; qemu- [email protected]; Sai Pavan Boddu <[email protected]>
Subject: Re: [PATCH 07/18] hw/sd: sd: Fix incorrect populated function switch status data structure

Hi Sai,

Quoted 3 lines · Sai Pavan Boddu

Hi Philippe,

Quoted 7 lines
Quoted 3 lines

First two patch of SD look good. Tested them over zynqmp and versal platforms.

Thanks for testing.

Can I add your Tested-by tag?

[Sai Pavan Boddu] Sure. Thanks.

Regards,
Sai Pavan

Quoted 3 lines

Regards,
Bin

author
#19 lore raw

PATCH 8/18 hw/sd: sd: Correctly set the high capacity bit

In reply to Bin Meng

From: Bin Meng <[email protected]>

Per the SD spec, Standard Capacity SD Memory Card (SDSC) supports capacity up to and including 2 GiB.

---

 hw/sd/sd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/sd/sd.c +1 -1
index 51f5900..5e7fc3f 100644
@@ -313,7 +313,7 @@ static void sd_ocr_powerup(void *opaque)
     /* card power-up OK */
     sd->ocr = FIELD_DP32(sd->ocr, OCR, CARD_POWER_UP, 1);
 
-    if (sd->size > 1 * GiB) {
+    if (sd->size > 2 * GiB) {
         sd->ocr = FIELD_DP32(sd->ocr, OCR, CARD_CAPACITY, 1);
     }
 }
Signature · 1 line
2.7.4
#20 lore raw

Re: [PATCH 08/18] hw/sd: sd: Correctly set the high capacity bit

Quoted 5 lines · Bin Meng

From: Bin Meng <[email protected]>

Per the SD spec, Standard Capacity SD Memory Card (SDSC) supports capacity up to and including 2 GiB.

Fixes 2d7adea4fe ("hw/sd: Support SDHC size cards")
Quoted 11 lines

---

 hw/sd/sd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/sd/sd.c +0 -0
index 51f5900..5e7fc3f 100644

hw/sd/sd.c static void sd_ocr_powerup(void *opaque) · line 316

Quoted 5 lines
hw/sd/sd.c +1 -1
@@ -313,7 +313,7 @@ static void sd_ocr_powerup(void *opaque)
     /* card power-up OK */
     sd->ocr = FIELD_DP32(sd->ocr, OCR, CARD_POWER_UP, 1);
 
-    if (sd->size > 1 * GiB) {
+    if (sd->size > 2 * GiB) {

But you need to fix sd_set_csd() too, else this is incomplete.

Thanks,

Phil.

Quoted 4 lines
hw/sd/sd.c +0 -0
         sd->ocr = FIELD_DP32(sd->ocr, OCR, CARD_CAPACITY, 1);
     }
 }
author
#21 lore raw

Re: [PATCH 08/18] hw/sd: sd: Correctly set the high capacity bit

Hi Philippe,

Quoted 24 lines · Philippe Mathieu-Daudé
Quoted 5 lines · Bin Meng

From: Bin Meng <[email protected]>

Per the SD spec, Standard Capacity SD Memory Card (SDSC) supports capacity up to and including 2 GiB.

Fixes 2d7adea4fe ("hw/sd: Support SDHC size cards")
Quoted 14 lines

---

 hw/sd/sd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/sd/sd.c +0 -0
index 51f5900..5e7fc3f 100644
@@ -313,7 +313,7 @@ static void sd_ocr_powerup(void *opaque)
     /* card power-up OK */
     sd->ocr = FIELD_DP32(sd->ocr, OCR, CARD_POWER_UP, 1);
 
Quoted 5 lines

hw/sd/sd.c static void sd_ocr_powerup(void *opaque) · line 316

Quoted 2 lines
hw/sd/sd.c +1 -1
-    if (sd->size > 1 * GiB) {
+    if (sd->size > 2 * GiB) {

But you need to fix sd_set_csd() too, else this is incomplete.

Ah yes, I missed that. Will fix in v2. Thanks for the review.

Regards,
Bin

author
#22 lore raw

PATCH 9/18 hw/sd: sdhci: Make sdhci_poweron_reset() internal visible

In reply to Bin Meng

From: Bin Meng <[email protected]>

sdhci_poweron_reset() might be needed for any SDHCI compatible device that is built on top of the generic SDHCI device.

---

 hw/sd/sdhci-internal.h | 1 +
 hw/sd/sdhci.c          | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
hw/sd/sdhci-internal.h +1 -0
index e8c753d..b587e8e 100644
@@ -342,5 +342,6 @@ void sdhci_uninitfn(SDHCIState *s);
 void sdhci_common_realize(SDHCIState *s, Error **errp);
 void sdhci_common_unrealize(SDHCIState *s);
 void sdhci_common_class_init(ObjectClass *klass, void *data);
+void sdhci_poweron_reset(DeviceState *dev);
 
 #endif
hw/sd/sdhci.c +1 -1
index deac181..20f2fe0 100644
@@ -294,7 +294,7 @@ static void sdhci_reset(SDHCIState *s)
     s->pending_insert_state = false;
 }
 
-static void sdhci_poweron_reset(DeviceState *dev)
+void sdhci_poweron_reset(DeviceState *dev)
 {
     /* QOM (ie power-on) reset. This is identical to reset
      * commanded via device register apart from handling of the
Signature · 1 line
2.7.4
#23 lore raw

Re: [PATCH 09/18] hw/sd: sdhci: Make sdhci_poweron_reset() internal visible

Quoted 4 lines · Bin Meng

From: Bin Meng <[email protected]>

sdhci_poweron_reset() might be needed for any SDHCI compatible device that is built on top of the generic SDHCI device.

NAck. Please use device_legacy_reset() instead.

In next patch:

  device_legacy_reset(DEVICE(&sdhci->slot));

Thanks,

Phil.

Quoted 33 lines

---

 hw/sd/sdhci-internal.h | 1 +
 hw/sd/sdhci.c          | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
hw/sd/sdhci-internal.h +1 -0
index e8c753d..b587e8e 100644
@@ -342,5 +342,6 @@ void sdhci_uninitfn(SDHCIState *s);
 void sdhci_common_realize(SDHCIState *s, Error **errp);
 void sdhci_common_unrealize(SDHCIState *s);
 void sdhci_common_class_init(ObjectClass *klass, void *data);
+void sdhci_poweron_reset(DeviceState *dev);
 
 #endif
hw/sd/sdhci.c +1 -1
index deac181..20f2fe0 100644
@@ -294,7 +294,7 @@ static void sdhci_reset(SDHCIState *s)
     s->pending_insert_state = false;
 }
 
-static void sdhci_poweron_reset(DeviceState *dev)
+void sdhci_poweron_reset(DeviceState *dev)
 {
     /* QOM (ie power-on) reset. This is identical to reset
      * commanded via device register apart from handling of the
author
#24 lore raw

Re: [PATCH 09/18] hw/sd: sdhci: Make sdhci_poweron_reset() internal visible

Hi Philippe,

Quoted 4 lines · Philippe Mathieu-Daudé
Quoted 2 lines · Bin Meng

From: Bin Meng <[email protected]>

Quoted 9 lines
Quoted 2 lines

sdhci_poweron_reset() might be needed for any SDHCI compatible device that is built on top of the generic SDHCI device.

NAck. Please use device_legacy_reset() instead.

In next patch:

  device_legacy_reset(DEVICE(&sdhci->slot));

The function comments say this API is deprecated.

/**
* device_legacy_reset:
*
* Reset a single device (by calling the reset method).
* Note: This function is deprecated and will be removed when it becomes unused.
* Please use device_cold_reset() now.
*/

Should we use device_cold_reset() here?

Regards,
Bin

#25 lore raw

Re: [PATCH 09/18] hw/sd: sdhci: Make sdhci_poweron_reset() internal visible

Quoted 27 lines · Bin Meng

Hi Philippe,

Quoted 4 lines · Philippe Mathieu-Daudé
Quoted 2 lines · Bin Meng

From: Bin Meng <[email protected]>

Quoted 9 lines
Quoted 2 lines

sdhci_poweron_reset() might be needed for any SDHCI compatible device that is built on top of the generic SDHCI device.

NAck. Please use device_legacy_reset() instead.

In next patch:

  device_legacy_reset(DEVICE(&sdhci->slot));

The function comments say this API is deprecated.

/**
* device_legacy_reset:
*
* Reset a single device (by calling the reset method).
* Note: This function is deprecated and will be removed when it becomes unused.
* Please use device_cold_reset() now.
*/

Quoted 1 line

Should we use device_cold_reset() here?

Oops yes, certainly.

Quoted 4 lines

Regards,
Bin

author
#26 lore raw

PATCH 10/18 hw/sd: Add Cadence SDHCI emulation

In reply to Bin Meng

From: Bin Meng <[email protected]>

Cadence SD/SDIO/eMMC Host Controller (SD4HC) is an SDHCI compatible controller. The SDHCI compatible registers start from offset 0x200, which are called Slot Register Set (SRS) in its datasheet.

This creates a Cadence SDHCI model built on top of the existing generic SDHCI model. Cadence specific Host Register Set (HRS) is implemented to make guest software happy.

---

 hw/sd/Kconfig                 |   4 ++
 hw/sd/Makefile.objs           |   1 +
 hw/sd/cadence_sdhci.c         | 162 ++++++++++++++++++++++++++++++++++++++++++
 include/hw/sd/cadence_sdhci.h |  65 +++++++++++++++++
 4 files changed, 232 insertions(+)
 create mode 100644 hw/sd/cadence_sdhci.c
 create mode 100644 include/hw/sd/cadence_sdhci.h
hw/sd/Kconfig +4 -0
index c5e1e55..633b9af 100644
@@ -19,3 +19,7 @@ config SDHCI_PCI
     default y if PCI_DEVICES
     depends on PCI
     select SDHCI
+
+config CADENCE_SDHCI
+    bool
+    select SDHCI
hw/sd/Makefile.objs +1 -0
index 0d1df17..4d500a6 100644
@@ -10,3 +10,4 @@ common-obj-$(CONFIG_OMAP) += omap_mmc.o
 common-obj-$(CONFIG_PXA2XX) += pxa2xx_mmci.o
 common-obj-$(CONFIG_RASPI) += bcm2835_sdhost.o
 common-obj-$(CONFIG_ASPEED_SOC) += aspeed_sdhci.o
+common-obj-$(CONFIG_CADENCE_SDHCI) += cadence_sdhci.o
hw/sd/cadence_sdhci.c new file +162 -0

162 lines not on this page · raw message

include/hw/sd/cadence_sdhci.h new file +65 -0

65 lines not on this page · raw message

Signature · 1 line
2.7.4
#27 lore raw

Re: [PATCH 10/18] hw/sd: Add Cadence SDHCI emulation

Quoted 13 lines · Bin Meng

From: Bin Meng <[email protected]>

Cadence SD/SDIO/eMMC Host Controller (SD4HC) is an SDHCI compatible controller. The SDHCI compatible registers start from offset 0x200, which are called Slot Register Set (SRS) in its datasheet.

This creates a Cadence SDHCI model built on top of the existing generic SDHCI model. Cadence specific Host Register Set (HRS) is implemented to make guest software happy.

---

Quoted 7 lines
 hw/sd/Kconfig                 |   4 ++
 hw/sd/Makefile.objs           |   1 +
 hw/sd/cadence_sdhci.c         | 162 ++++++++++++++++++++++++++++++++++++++++++
 include/hw/sd/cadence_sdhci.h |  65 +++++++++++++++++
 4 files changed, 232 insertions(+)
 create mode 100644 hw/sd/cadence_sdhci.c
 create mode 100644 include/hw/sd/cadence_sdhci.h

Please consider using scripts/git.orderfile.

Quoted 54 lines
hw/sd/Kconfig +4 -0
index c5e1e55..633b9af 100644
@@ -19,3 +19,7 @@ config SDHCI_PCI
     default y if PCI_DEVICES
     depends on PCI
     select SDHCI
+
+config CADENCE_SDHCI
+    bool
+    select SDHCI
hw/sd/Makefile.objs +1 -0
index 0d1df17..4d500a6 100644
@@ -10,3 +10,4 @@ common-obj-$(CONFIG_OMAP) += omap_mmc.o
 common-obj-$(CONFIG_PXA2XX) += pxa2xx_mmci.o
 common-obj-$(CONFIG_RASPI) += bcm2835_sdhost.o
 common-obj-$(CONFIG_ASPEED_SOC) += aspeed_sdhci.o
+common-obj-$(CONFIG_CADENCE_SDHCI) += cadence_sdhci.o
hw/sd/cadence_sdhci.c new file +26 -0
new file mode 100644
index 0000000..67ffd14
@@ -0,0 +1,162 @@
+/*
+ * Cadence SDHCI emulation
+ *
+ * Copyright (c) 2020 Wind River Systems, Inc.
+ *
+ * Author:
+ *   Bin Meng <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 or
+ * (at your option) version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/error-report.h"
+#include "qemu/log.h"
+#include "qapi/error.h"

hw/sd/cadence_sdhci.c line 36

Quoted 10 lines
hw/sd/cadence_sdhci.c new file +10 -0
+#include "migration/vmstate.h"
+#include "hw/irq.h"
+#include "hw/sd/cadence_sdhci.h"
+#include "sdhci-internal.h"
+
+#define TO_REG(addr)    ((addr) / sizeof(uint32_t))
+
+static void cadence_sdhci_reset(DeviceState *dev)
+{
+    CadenceSDHCIState *sdhci = CADENCE_SDHCI(dev);

We usually use 's' for the model state.

hw/sd/cadence_sdhci.c line 39

Quoted 3 lines
hw/sd/cadence_sdhci.c new file +3 -0
+
+    memset(sdhci->regs, 0, CADENCE_SDHCI_REG_SIZE);
+    sdhci->regs[TO_REG(SDHCI_CDNS_HRS00)] = SDHCI_CDNS_HRS00_POR_VAL;

As commented in previous patch, here goes:

       device_legacy_reset(DEVICE(&sdhci->slot));
Quoted 23 lines
hw/sd/cadence_sdhci.c new file +23 -0
+}
+
+static uint64_t cadence_sdhci_read(void *opaque, hwaddr addr, unsigned int size)
+{
+    uint32_t val = 0;
+    CadenceSDHCIState *sdhci = opaque;
+
+    if (addr < CADENCE_SDHCI_REG_SIZE) {
+        val = sdhci->regs[TO_REG(addr)];
+    } else {
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "%s: Out-of-bounds read at 0x%" HWADDR_PRIx "\n",
+                      __func__, addr);
+    }
+
+    return (uint64_t)val;
+}
+
+static void cadence_sdhci_write(void *opaque, hwaddr addr, uint64_t val,
+                                unsigned int size)
+{
+    CadenceSDHCIState *sdhci = opaque;
+    uint32_t val32 = (uint32_t)val;

hw/sd/cadence_sdhci.c line 72

Quoted 10 lines
hw/sd/cadence_sdhci.c new file +10 -0
+
+    switch (addr) {
+    case SDHCI_CDNS_HRS00:
+        /*
+         * The only writable bit is SWR (software reset) and it automatically
+         * clears to zero, so essentially this register remains unchanged.
+         */
+        if (val32 & SDHCI_CDNS_HRS00_SWR) {
+            cadence_sdhci_reset(DEVICE(sdhci));
+            sdhci_poweron_reset(DEVICE(&sdhci->slot));

The 'slot' reset has to go in cadence_sdhci_reset().

Quoted 28 lines
hw/sd/cadence_sdhci.c new file +28 -0
+        }
+
+        break;
+    case SDHCI_CDNS_HRS04:
+        /*
+         * Only emulate the ACK bit behavior when read or write transaction
+         * are requested.
+         */
+        if (val32 & (SDHCI_CDNS_HRS04_WR | SDHCI_CDNS_HRS04_RD)) {
+            val32 |= SDHCI_CDNS_HRS04_ACK;
+        } else {
+            val32 &= ~SDHCI_CDNS_HRS04_ACK;
+        }
+
+        sdhci->regs[TO_REG(addr)] = val32;
+        break;
+    case SDHCI_CDNS_HRS06:
+        if (val32 & SDHCI_CDNS_HRS06_TUNE_UP) {
+            val32 &= ~SDHCI_CDNS_HRS06_TUNE_UP;
+        }
+
+        sdhci->regs[TO_REG(addr)] = val32;
+        break;
+    default:
+        if (addr < CADENCE_SDHCI_REG_SIZE) {
+            sdhci->regs[TO_REG(addr)] = val32;
+        } else {
+            qemu_log_mask(LOG_GUEST_ERROR,

hw/sd/cadence_sdhci.c line 110

Quoted 10 lines
hw/sd/cadence_sdhci.c new file +10 -0
+                          "%s: Out-of-bounds write at 0x%" HWADDR_PRIx "\n",
+                          __func__, addr);
+        }
+    }
+}
+
+static const MemoryRegionOps cadence_sdhci_ops = {
+    .read = cadence_sdhci_read,
+    .write = cadence_sdhci_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,

To make it obvious, please also add:

       .impl = {
           .min_access_size = 4,
           .max_access_size = 4,
       },

hw/sd/cadence_sdhci.c line 121

Quoted 11 lines
hw/sd/cadence_sdhci.c new file +11 -0
+    .valid = {
+        .min_access_size = 4,
+        .max_access_size = 4,
+    }
+};
+
+static void cadence_sdhci_realize(DeviceState *dev, Error **errp)
+{
+    SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
+    CadenceSDHCIState *sdhci = CADENCE_SDHCI(dev);
+    SysBusDevice *sbd_slot = SYS_BUS_DEVICE(&sdhci->slot);

Where is sdhci->slot initialized??

hw/sd/cadence_sdhci.c line 129

Quoted 8 lines
hw/sd/cadence_sdhci.c new file +8 -0
+
+    memory_region_init_io(&sdhci->iomem, OBJECT(sdhci), &cadence_sdhci_ops,
+                          sdhci, TYPE_CADENCE_SDHCI, 0x1000);
+    sysbus_init_mmio(sbd, &sdhci->iomem);
+
+    sysbus_realize(sbd_slot, errp);
+    memory_region_add_subregion(&sdhci->iomem, SDHCI_CDNS_SRS_BASE,
+                                &sdhci->slot.iomem);

You should not access private field that way, you have to use the public interface:

  memory_region_add_subregion(&sdhci->iomem, SDHCI_CDNS_SRS_BASE,
           sysbus_mmio_get_region(SYS_BUS_DEVICE(&sdhci->slot), 0));

To have this model useful, you need to propagate at least the 'sd-bus' and 'dma' properties from the 'slot', else how the TYPE_CADENCE_SDHCI user is supposed to set them?

Quoted 73 lines
hw/sd/cadence_sdhci.c new file +33 -0
+}
+
+static const VMStateDescription vmstate_cadence_sdhci = {
+    .name = TYPE_CADENCE_SDHCI,
+    .version_id = 1,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT32_ARRAY(regs, CadenceSDHCIState, CADENCE_SDHCI_NUM_REGS),
+        VMSTATE_END_OF_LIST(),
+    },
+};
+
+static void cadence_sdhci_class_init(ObjectClass *classp, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(classp);
+
+    dc->realize = cadence_sdhci_realize;
+    dc->reset = cadence_sdhci_reset;
+    dc->vmsd = &vmstate_cadence_sdhci;
+}
+
+static TypeInfo cadence_sdhci_info = {
+    .name          = TYPE_CADENCE_SDHCI,
+    .parent        = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(CadenceSDHCIState),
+    .class_init    = cadence_sdhci_class_init,
+};
+
+static void cadence_sdhci_register_types(void)
+{
+    type_register_static(&cadence_sdhci_info);
+}
+
+type_init(cadence_sdhci_register_types)
include/hw/sd/cadence_sdhci.h new file +34 -0
new file mode 100644
index 0000000..9ff78a9
@@ -0,0 +1,65 @@
+/*
+ * Cadence SDHCI emulation
+ *
+ * Copyright (c) 2020 Wind River Systems, Inc.
+ *
+ * Author:
+ *   Bin Meng <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 or
+ * (at your option) version 3 of the License.
+ *
+ * This program is distributed in the hope that 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 CADENCE_SDHCI_H
+#define CADENCE_SDHCI_H
+
+#include "qemu/bitops.h"
+#include "hw/sd/sdhci.h"
+
+/* HRS - Host Register Set (specific to Cadence) */
+
+#define SDHCI_CDNS_HRS00                0x00    /* general information */
+#define SDHCI_CDNS_HRS00_SWR                BIT(0)
+#define SDHCI_CDNS_HRS00_POR_VAL            0x00010000
+

include/hw/sd/cadence_sdhci.h line 44

Quoted 10 lines
include/hw/sd/cadence_sdhci.h new file +10 -0
+#define SDHCI_CDNS_HRS04                0x10    /* PHY access port */
+#define SDHCI_CDNS_HRS04_WR                 BIT(24)
+#define SDHCI_CDNS_HRS04_RD                 BIT(25)
+#define SDHCI_CDNS_HRS04_ACK                BIT(26)
+
+#define SDHCI_CDNS_HRS06                0x18    /* eMMC control */
+#define SDHCI_CDNS_HRS06_TUNE_UP            BIT(15)
+
+/* SRS - Slot Register Set (SDHCI-compatible) */
+#define SDHCI_CDNS_SRS_BASE             0x200

Please keep the previous definitions local to cadence_sdhci.c.

Quoted 4 lines
include/hw/sd/cadence_sdhci.h new file +4 -0
+
+#define CADENCE_SDHCI_CAPABILITIES 0x01E80080
+#define CADENCE_SDHCI_REG_SIZE     0x100
+#define CADENCE_SDHCI_NUM_REGS     (CADENCE_SDHCI_REG_SIZE / sizeof(uint32_t))

include/hw/sd/cadence_sdhci.h line 58

Quoted 10 lines
include/hw/sd/cadence_sdhci.h new file +10 -0
+
+typedef struct CadenceSDHCIState {
+    SysBusDevice parent;
+
+    MemoryRegion iomem;
+    qemu_irq irq;
+
+    uint32_t regs[CADENCE_SDHCI_NUM_REGS];
+
+    SDHCIState slot;

Why name this 'slot' and not 'sdhci' or 'generic_sdhci'?

Thanks,

Phil.

Quoted 8 lines
include/hw/sd/cadence_sdhci.h new file +7 -0
+} CadenceSDHCIState;
+
+#define TYPE_CADENCE_SDHCI  "cadence.sdhci"
+#define CADENCE_SDHCI(obj)  OBJECT_CHECK(CadenceSDHCIState, (obj), \
+                                         TYPE_CADENCE_SDHCI)
+
+#endif /* CADENCE_SDHCI_H */
author
#28 lore raw

PATCH 11/18 hw/riscv: microchip_pfsoc: Connect a Cadence SDHCI controller and an SD card

In reply to Bin Meng

From: Bin Meng <[email protected]>

Microchip PolarFire SoC integrates one Cadence SDHCI controller. On the Icicle Kit board, one eMMC chip and an external SD card connect to this controller depending on different configuration.

As QEMU does not support eMMC yet, we just emulate the SD card configuration. To test this, the Hart Software Services (HSS) should choose the SD card configuration:

$ cp boards/icicle-kit-es/def_config.sdcard .config
$ make BOARD=icicle-kit-es

The SD card image can be built from the Yocto BSP at:
https://github.com/polarfire-soc/meta-polarfire-soc-yocto-bsp

Note the generated SD card image should be resized before use:

$ qemu-img resize /path/to/sdcard.img 4G

Launch QEMU with the following command:

$ qemu-system-riscv64 -nographic -M microchip-icicle-kit -sd sdcard.img

---

 hw/riscv/Kconfig                   |  1 +
 hw/riscv/microchip_pfsoc.c         | 26 ++++++++++++++++++++++++++
 include/hw/riscv/microchip_pfsoc.h |  4 ++++
 3 files changed, 31 insertions(+)
hw/riscv/Kconfig +1 -0
index ceb7c16..7412db9 100644
@@ -55,3 +55,4 @@ config MICROCHIP_PFSOC
     select SIFIVE
     select UNIMP
     select MCHP_PFSOC_MMUART
+    select CADENCE_SDHCI
hw/riscv/microchip_pfsoc.c +26 -0
index f6b375c..7c09078 100644
@@ -12,6 +12,7 @@
  * 1) PLIC (Platform Level Interrupt Controller)
  * 2) eNVM (Embedded Non-Volatile Memory)
  * 3) MMUARTs (Multi-Mode UART)
+ * 4) Cadence eMMC/SDHC controller and an SD card connected to it
  *
  * This board currently generates devicetree dynamically that indicates at least
  * two harts and up to five harts.
@@ -75,6 +76,7 @@ static const struct MemmapEntry {
     [MICROCHIP_PFSOC_MMUART0] =         { 0x20000000,     0x1000 },
     [MICROCHIP_PFSOC_SYSREG] =          { 0x20002000,     0x2000 },
     [MICROCHIP_PFSOC_MPUCFG] =          { 0x20005000,     0x1000 },
+    [MICROCHIP_PFSOC_EMMC_SD] =         { 0x20008000,     0x1000 },
     [MICROCHIP_PFSOC_MMUART1] =         { 0x20100000,     0x1000 },
     [MICROCHIP_PFSOC_MMUART2] =         { 0x20102000,     0x1000 },
     [MICROCHIP_PFSOC_MMUART3] =         { 0x20104000,     0x1000 },
@@ -111,6 +113,11 @@ static void microchip_pfsoc_soc_instance_init(Object *obj)
     qdev_prop_set_string(DEVICE(&s->u_cpus), "cpu-type",
                          TYPE_RISCV_CPU_SIFIVE_U54);
     qdev_prop_set_uint64(DEVICE(&s->u_cpus), "resetvec", RESET_VECTOR);
+
+    object_initialize_child(obj, "sd-controller", &s->sdhci,
+                            TYPE_CADENCE_SDHCI);
+    object_initialize_child(OBJECT(&s->sdhci), "sd-controller.sdhci",
+                            &s->sdhci.slot, TYPE_SYSBUS_SDHCI);
 }
 
 static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
@@ -223,6 +230,13 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
         memmap[MICROCHIP_PFSOC_MPUCFG].base,
         memmap[MICROCHIP_PFSOC_MPUCFG].size);
 
+    /* SDHCI */
+    sysbus_realize(SYS_BUS_DEVICE(&s->sdhci), errp);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->sdhci), 0,
+                    memmap[MICROCHIP_PFSOC_EMMC_SD].base);
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->sdhci.slot), 0,
+        qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_EMMC_SD_IRQ));
+
     /* MMUARTs */
     s->serial0 = mchp_pfsoc_mmuart_create(system_memory,
         memmap[MICROCHIP_PFSOC_MMUART0].base,
@@ -290,6 +304,7 @@ static void microchip_icicle_kit_machine_init(MachineState *machine)
     MicrochipIcicleKitState *s = MICROCHIP_ICICLE_KIT_MACHINE(machine);
     MemoryRegion *system_memory = get_system_memory();
     MemoryRegion *main_mem = g_new(MemoryRegion, 1);
+    DriveInfo *dinfo = drive_get_next(IF_SD);
 
     /* Sanity check on RAM size */
     if (machine->ram_size < mc->default_ram_size) {
@@ -312,6 +327,17 @@ static void microchip_icicle_kit_machine_init(MachineState *machine)
 
     /* Load the firmware */
     riscv_find_and_load_firmware(machine, BIOS_FILENAME, RESET_VECTOR, NULL);
+
+    /* Attach an SD card */
+    if (dinfo) {
+        SDHCIState *sdhci = &(s->soc.sdhci.slot);
+        DeviceState *card = qdev_new(TYPE_SD_CARD);
+        BusState *bus = qdev_get_child_bus(DEVICE(sdhci), "sd-bus");
+
+        qdev_prop_set_drive_err(card, "drive", blk_by_legacy_dinfo(dinfo),
+                                &error_fatal);
+        qdev_realize_and_unref(card, bus, &error_fatal);
+    }
 }
 
 static void microchip_icicle_kit_machine_class_init(ObjectClass *oc, void *data)
include/hw/riscv/microchip_pfsoc.h +4 -0
index a5efa1d..d810ee8 100644
@@ -23,6 +23,7 @@
 #define HW_MICROCHIP_PFSOC_H
 
 #include "hw/char/mchp_pfsoc_mmuart.h"
+#include "hw/sd/cadence_sdhci.h"
 
 typedef struct MicrochipPFSoCState {
     /*< private >*/
@@ -39,6 +40,7 @@ typedef struct MicrochipPFSoCState {
     MchpPfSoCMMUartState *serial2;
     MchpPfSoCMMUartState *serial3;
     MchpPfSoCMMUartState *serial4;
+    CadenceSDHCIState sdhci;
 } MicrochipPFSoCState;
 
 #define TYPE_MICROCHIP_PFSOC    "microchip.pfsoc"
@@ -74,6 +76,7 @@ enum {
     MICROCHIP_PFSOC_MMUART0,
     MICROCHIP_PFSOC_SYSREG,
     MICROCHIP_PFSOC_MPUCFG,
+    MICROCHIP_PFSOC_EMMC_SD,
     MICROCHIP_PFSOC_MMUART1,
     MICROCHIP_PFSOC_MMUART2,
     MICROCHIP_PFSOC_MMUART3,
@@ -85,6 +88,7 @@ enum {
 };
 
 enum {
+    MICROCHIP_PFSOC_EMMC_SD_IRQ = 88,
     MICROCHIP_PFSOC_MMUART0_IRQ = 90,
     MICROCHIP_PFSOC_MMUART1_IRQ = 91,
     MICROCHIP_PFSOC_MMUART2_IRQ = 92,
Signature · 1 line
2.7.4
#29 lore raw

Re: [PATCH 11/18] hw/riscv: microchip_pfsoc: Connect a Cadence SDHCI controller and an SD card

Quoted 60 lines · Bin Meng

From: Bin Meng <[email protected]>

Microchip PolarFire SoC integrates one Cadence SDHCI controller. On the Icicle Kit board, one eMMC chip and an external SD card connect to this controller depending on different configuration.

As QEMU does not support eMMC yet, we just emulate the SD card configuration. To test this, the Hart Software Services (HSS) should choose the SD card configuration:

$ cp boards/icicle-kit-es/def_config.sdcard .config
$ make BOARD=icicle-kit-es

The SD card image can be built from the Yocto BSP at:
https://github.com/polarfire-soc/meta-polarfire-soc-yocto-bsp

Note the generated SD card image should be resized before use:

$ qemu-img resize /path/to/sdcard.img 4G

Launch QEMU with the following command:

$ qemu-system-riscv64 -nographic -M microchip-icicle-kit -sd sdcard.img

---

 hw/riscv/Kconfig                   |  1 +
 hw/riscv/microchip_pfsoc.c         | 26 ++++++++++++++++++++++++++
 include/hw/riscv/microchip_pfsoc.h |  4 ++++
 3 files changed, 31 insertions(+)
hw/riscv/Kconfig +1 -0
index ceb7c16..7412db9 100644
@@ -55,3 +55,4 @@ config MICROCHIP_PFSOC
     select SIFIVE
     select UNIMP
     select MCHP_PFSOC_MMUART
+    select CADENCE_SDHCI
hw/riscv/microchip_pfsoc.c +2 -0
index f6b375c..7c09078 100644
@@ -12,6 +12,7 @@
  * 1) PLIC (Platform Level Interrupt Controller)
  * 2) eNVM (Embedded Non-Volatile Memory)
  * 3) MMUARTs (Multi-Mode UART)
+ * 4) Cadence eMMC/SDHC controller and an SD card connected to it
  *
  * This board currently generates devicetree dynamically that indicates at least
  * two harts and up to five harts.
@@ -75,6 +76,7 @@ static const struct MemmapEntry {
     [MICROCHIP_PFSOC_MMUART0] =         { 0x20000000,     0x1000 },
     [MICROCHIP_PFSOC_SYSREG] =          { 0x20002000,     0x2000 },
     [MICROCHIP_PFSOC_MPUCFG] =          { 0x20005000,     0x1000 },
+    [MICROCHIP_PFSOC_EMMC_SD] =         { 0x20008000,     0x1000 },
     [MICROCHIP_PFSOC_MMUART1] =         { 0x20100000,     0x1000 },
     [MICROCHIP_PFSOC_MMUART2] =         { 0x20102000,     0x1000 },
     [MICROCHIP_PFSOC_MMUART3] =         { 0x20104000,     0x1000 },

hw/riscv/microchip_pfsoc.c static void microchip_pfsoc_soc_instance_init(Object *obj) · line 120

Quoted 8 lines
hw/riscv/microchip_pfsoc.c +5 -0
@@ -111,6 +113,11 @@ static void microchip_pfsoc_soc_instance_init(Object *obj)
     qdev_prop_set_string(DEVICE(&s->u_cpus), "cpu-type",
                          TYPE_RISCV_CPU_SIFIVE_U54);
     qdev_prop_set_uint64(DEVICE(&s->u_cpus), "resetvec", RESET_VECTOR);
+
+    object_initialize_child(obj, "sd-controller", &s->sdhci,
+                            TYPE_CADENCE_SDHCI);
+    object_initialize_child(OBJECT(&s->sdhci), "sd-controller.sdhci",
+                            &s->sdhci.slot, TYPE_SYSBUS_SDHCI);

OK now I see this patch, so NAck. TYPE_SYSBUS_SDHCI has to be initialized in TYPE_CADENCE_SDHCI, not in all TYPE_CADENCE_SDHCI users.

hw/riscv/microchip_pfsoc.c static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp) · line 233

Quoted 8 lines
hw/riscv/microchip_pfsoc.c +1 -0
 }
 
 static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
@@ -223,6 +230,13 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
         memmap[MICROCHIP_PFSOC_MPUCFG].base,
         memmap[MICROCHIP_PFSOC_MPUCFG].size);
 
+    /* SDHCI */

Consider setting the SDHCI DMA MR here.

Quoted 18 lines
hw/riscv/microchip_pfsoc.c +7 -0
+    sysbus_realize(SYS_BUS_DEVICE(&s->sdhci), errp);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->sdhci), 0,
+                    memmap[MICROCHIP_PFSOC_EMMC_SD].base);
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->sdhci.slot), 0,
+        qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_EMMC_SD_IRQ));
+
     /* MMUARTs */
     s->serial0 = mchp_pfsoc_mmuart_create(system_memory,
         memmap[MICROCHIP_PFSOC_MMUART0].base,
@@ -290,6 +304,7 @@ static void microchip_icicle_kit_machine_init(MachineState *machine)
     MicrochipIcicleKitState *s = MICROCHIP_ICICLE_KIT_MACHINE(machine);
     MemoryRegion *system_memory = get_system_memory();
     MemoryRegion *main_mem = g_new(MemoryRegion, 1);
+    DriveInfo *dinfo = drive_get_next(IF_SD);
 
     /* Sanity check on RAM size */
     if (machine->ram_size < mc->default_ram_size) {

hw/riscv/microchip_pfsoc.c static void microchip_icicle_kit_machine_init(MachineState *machine) · line 333

Quoted 7 lines
hw/riscv/microchip_pfsoc.c +4 -0
@@ -312,6 +327,17 @@ static void microchip_icicle_kit_machine_init(MachineState *machine)
 
     /* Load the firmware */
     riscv_find_and_load_firmware(machine, BIOS_FILENAME, RESET_VECTOR, NULL);
+
+    /* Attach an SD card */
+    if (dinfo) {
+        SDHCIState *sdhci = &(s->soc.sdhci.slot);

NAck again, you are not supposed to access this field here. This is why in the previous patch I asked why the "sd-bus" property was not propagated from child to parent.

Thanks,

Phil.

Quoted 47 lines
hw/riscv/microchip_pfsoc.c +7 -0
+        DeviceState *card = qdev_new(TYPE_SD_CARD);
+        BusState *bus = qdev_get_child_bus(DEVICE(sdhci), "sd-bus");
+
+        qdev_prop_set_drive_err(card, "drive", blk_by_legacy_dinfo(dinfo),
+                                &error_fatal);
+        qdev_realize_and_unref(card, bus, &error_fatal);
+    }
 }
 
 static void microchip_icicle_kit_machine_class_init(ObjectClass *oc, void *data)
include/hw/riscv/microchip_pfsoc.h +4 -0
index a5efa1d..d810ee8 100644
@@ -23,6 +23,7 @@
 #define HW_MICROCHIP_PFSOC_H
 
 #include "hw/char/mchp_pfsoc_mmuart.h"
+#include "hw/sd/cadence_sdhci.h"
 
 typedef struct MicrochipPFSoCState {
     /*< private >*/
@@ -39,6 +40,7 @@ typedef struct MicrochipPFSoCState {
     MchpPfSoCMMUartState *serial2;
     MchpPfSoCMMUartState *serial3;
     MchpPfSoCMMUartState *serial4;
+    CadenceSDHCIState sdhci;
 } MicrochipPFSoCState;
 
 #define TYPE_MICROCHIP_PFSOC    "microchip.pfsoc"
@@ -74,6 +76,7 @@ enum {
     MICROCHIP_PFSOC_MMUART0,
     MICROCHIP_PFSOC_SYSREG,
     MICROCHIP_PFSOC_MPUCFG,
+    MICROCHIP_PFSOC_EMMC_SD,
     MICROCHIP_PFSOC_MMUART1,
     MICROCHIP_PFSOC_MMUART2,
     MICROCHIP_PFSOC_MMUART3,
@@ -85,6 +88,7 @@ enum {
 };
 
 enum {
+    MICROCHIP_PFSOC_EMMC_SD_IRQ = 88,
     MICROCHIP_PFSOC_MMUART0_IRQ = 90,
     MICROCHIP_PFSOC_MMUART1_IRQ = 91,
     MICROCHIP_PFSOC_MMUART2_IRQ = 92,
author
#30 lore raw

PATCH 12/18 hw/dma: Add Microchip PolarFire Soc DMA controller emulation

In reply to Bin Meng

From: Bin Meng <[email protected]>

Microchip PolarFire SoC integrates a DMA engine that supports:
* Independent concurrent DMA transfers using 4 DMA channels
* Generation of interrupts on various conditions during execution

This creates a simple model to support polling mode which is enough for firmware usage. While there are codes for interrupts handling, please note the interrupt path has not been validated due to missing kernel driver for testing as of now.

---

 MAINTAINERS                     |   2 +
 hw/dma/Kconfig                  |   3 +
 hw/dma/Makefile.objs            |   1 +
 hw/dma/mchp_pfsoc_dma.c         | 322 ++++++++++++++++++++++++++++++++++++++++
 include/hw/dma/mchp_pfsoc_dma.h |  57 +++++++
 5 files changed, 385 insertions(+)
 create mode 100644 hw/dma/mchp_pfsoc_dma.c
 create mode 100644 include/hw/dma/mchp_pfsoc_dma.h
MAINTAINERS +2 -0
index e51edac..0aacc90 100644
@@ -1320,8 +1320,10 @@ L: [email protected]
 S: Supported
 F: hw/riscv/microchip_pfsoc.c
 F: hw/char/mchp_pfsoc_mmuart.c
+F: hw/dma/mchp_pfsoc_dma.c
 F: include/hw/riscv/microchip_pfsoc.h
 F: include/hw/char/mchp_pfsoc_mmuart.h
+F: include/hw/dma/mchp_pfsoc_dma.h
 
 RX Machines
 -----------
hw/dma/Kconfig +3 -0
index 5c61b67..778e20b 100644
@@ -20,3 +20,6 @@ config ZYNQ_DEVCFG
 
 config STP2000
     bool
+
+config MCHP_PFSOC_DMA
+    bool
hw/dma/Makefile.objs +1 -0
index f4b1cfe..fd7e836 100644
@@ -14,3 +14,4 @@ common-obj-$(CONFIG_XLNX_ZYNQMP_ARM) += xlnx-zdma.o
 common-obj-$(CONFIG_OMAP) += omap_dma.o soc_dma.o
 common-obj-$(CONFIG_PXA2XX) += pxa2xx_dma.o
 common-obj-$(CONFIG_RASPI) += bcm2835_dma.o
+common-obj-$(CONFIG_MCHP_PFSOC_DMA) += mchp_pfsoc_dma.o
hw/dma/mchp_pfsoc_dma.c new file +322 -0

322 lines not on this page · raw message

include/hw/dma/mchp_pfsoc_dma.h new file +57 -0

57 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#31 lore raw

PATCH 13/18 hw/riscv: microchip_pfsoc: Connect a DMA controller

In reply to Bin Meng

From: Bin Meng <[email protected]>

Connect a DMA controller to Microchip PolarFire SoC. Note interrupt has not been connected due to missing information in the manual how interrupts are routed to PLIC.

On the Icicle Kit board, the HSS firmware utilizes the on-chip DMA controller to move the 2nd stage bootloader in the system memory.

---

 hw/riscv/Kconfig                   |  1 +
 hw/riscv/microchip_pfsoc.c         | 10 ++++++++++
 include/hw/riscv/microchip_pfsoc.h |  3 +++
 3 files changed, 14 insertions(+)
hw/riscv/Kconfig +1 -0
index 7412db9..9323701 100644
@@ -55,4 +55,5 @@ config MICROCHIP_PFSOC
     select SIFIVE
     select UNIMP
     select MCHP_PFSOC_MMUART
+    select MCHP_PFSOC_DMA
     select CADENCE_SDHCI
hw/riscv/microchip_pfsoc.c +10 -0
index 7c09078..1c67cbc 100644
@@ -13,6 +13,7 @@
  * 2) eNVM (Embedded Non-Volatile Memory)
  * 3) MMUARTs (Multi-Mode UART)
  * 4) Cadence eMMC/SDHC controller and an SD card connected to it
+ * 5) DMA (Direct Memory Access Controller)
  *
  * This board currently generates devicetree dynamically that indicates at least
  * two harts and up to five harts.
@@ -71,6 +72,7 @@ static const struct MemmapEntry {
     [MICROCHIP_PFSOC_BUSERR_UNIT4] =    {  0x1704000,     0x1000 },
     [MICROCHIP_PFSOC_CLINT] =           {  0x2000000,    0x10000 },
     [MICROCHIP_PFSOC_L2CC] =            {  0x2010000,     0x1000 },
+    [MICROCHIP_PFSOC_DMA] =             {  0x3000000,   0x100000 },
     [MICROCHIP_PFSOC_L2LIM] =           {  0x8000000,  0x2000000 },
     [MICROCHIP_PFSOC_PLIC] =            {  0xc000000,  0x4000000 },
     [MICROCHIP_PFSOC_MMUART0] =         { 0x20000000,     0x1000 },
@@ -114,6 +116,9 @@ static void microchip_pfsoc_soc_instance_init(Object *obj)
                          TYPE_RISCV_CPU_SIFIVE_U54);
     qdev_prop_set_uint64(DEVICE(&s->u_cpus), "resetvec", RESET_VECTOR);
 
+    object_initialize_child(obj, "dma-controller", &s->dma,
+                            TYPE_MCHP_PFSOC_DMA);
+
     object_initialize_child(obj, "sd-controller", &s->sdhci,
                             TYPE_CADENCE_SDHCI);
     object_initialize_child(OBJECT(&s->sdhci), "sd-controller.sdhci",
@@ -220,6 +225,11 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
         memmap[MICROCHIP_PFSOC_PLIC].size);
     g_free(plic_hart_config);
 
+    /* DMA */
+    sysbus_realize(SYS_BUS_DEVICE(&s->dma), errp);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->dma), 0,
+                    memmap[MICROCHIP_PFSOC_DMA].base);
+
     /* SYSREG */
     create_unimplemented_device("microchip.pfsoc.sysreg",
         memmap[MICROCHIP_PFSOC_SYSREG].base,
include/hw/riscv/microchip_pfsoc.h +3 -0
index d810ee8..7825935 100644
@@ -23,6 +23,7 @@
 #define HW_MICROCHIP_PFSOC_H
 
 #include "hw/char/mchp_pfsoc_mmuart.h"
+#include "hw/dma/mchp_pfsoc_dma.h"
 #include "hw/sd/cadence_sdhci.h"
 
 typedef struct MicrochipPFSoCState {
@@ -40,6 +41,7 @@ typedef struct MicrochipPFSoCState {
     MchpPfSoCMMUartState *serial2;
     MchpPfSoCMMUartState *serial3;
     MchpPfSoCMMUartState *serial4;
+    MchpPfSoCDMAState dma;
     CadenceSDHCIState sdhci;
 } MicrochipPFSoCState;
 
@@ -71,6 +73,7 @@ enum {
     MICROCHIP_PFSOC_BUSERR_UNIT4,
     MICROCHIP_PFSOC_CLINT,
     MICROCHIP_PFSOC_L2CC,
+    MICROCHIP_PFSOC_DMA,
     MICROCHIP_PFSOC_L2LIM,
     MICROCHIP_PFSOC_PLIC,
     MICROCHIP_PFSOC_MMUART0,
Signature · 1 line
2.7.4
#32 lore raw

Re: [PATCH 13/18] hw/riscv: microchip_pfsoc: Connect a DMA controller

Quoted 48 lines · Bin Meng

From: Bin Meng <[email protected]>

Connect a DMA controller to Microchip PolarFire SoC. Note interrupt has not been connected due to missing information in the manual how interrupts are routed to PLIC.

On the Icicle Kit board, the HSS firmware utilizes the on-chip DMA controller to move the 2nd stage bootloader in the system memory.

---

 hw/riscv/Kconfig                   |  1 +
 hw/riscv/microchip_pfsoc.c         | 10 ++++++++++
 include/hw/riscv/microchip_pfsoc.h |  3 +++
 3 files changed, 14 insertions(+)
hw/riscv/Kconfig +1 -0
index 7412db9..9323701 100644
@@ -55,4 +55,5 @@ config MICROCHIP_PFSOC
     select SIFIVE
     select UNIMP
     select MCHP_PFSOC_MMUART
+    select MCHP_PFSOC_DMA
     select CADENCE_SDHCI
hw/riscv/microchip_pfsoc.c +2 -0
index 7c09078..1c67cbc 100644
@@ -13,6 +13,7 @@
  * 2) eNVM (Embedded Non-Volatile Memory)
  * 3) MMUARTs (Multi-Mode UART)
  * 4) Cadence eMMC/SDHC controller and an SD card connected to it
+ * 5) DMA (Direct Memory Access Controller)
  *
  * This board currently generates devicetree dynamically that indicates at least
  * two harts and up to five harts.
@@ -71,6 +72,7 @@ static const struct MemmapEntry {
     [MICROCHIP_PFSOC_BUSERR_UNIT4] =    {  0x1704000,     0x1000 },
     [MICROCHIP_PFSOC_CLINT] =           {  0x2000000,    0x10000 },
     [MICROCHIP_PFSOC_L2CC] =            {  0x2010000,     0x1000 },
+    [MICROCHIP_PFSOC_DMA] =             {  0x3000000,   0x100000 },
     [MICROCHIP_PFSOC_L2LIM] =           {  0x8000000,  0x2000000 },
     [MICROCHIP_PFSOC_PLIC] =            {  0xc000000,  0x4000000 },
     [MICROCHIP_PFSOC_MMUART0] =         { 0x20000000,     0x1000 },

hw/riscv/microchip_pfsoc.c static void microchip_pfsoc_soc_instance_init(Object *obj) · line 123

Quoted 8 lines
hw/riscv/microchip_pfsoc.c +3 -0
@@ -114,6 +116,9 @@ static void microchip_pfsoc_soc_instance_init(Object *obj)
                          TYPE_RISCV_CPU_SIFIVE_U54);
     qdev_prop_set_uint64(DEVICE(&s->u_cpus), "resetvec", RESET_VECTOR);
 
+    object_initialize_child(obj, "dma-controller", &s->dma,
+                            TYPE_MCHP_PFSOC_DMA);
+
     object_initialize_child(obj, "sd-controller", &s->sdhci,
                             TYPE_CADENCE_SDHCI);

I haven't looked at the chip specs, but maybe you can add the SD controller after the DMA controller so so you can directly link a DMA address space to it.

Quoted 42 lines
hw/riscv/microchip_pfsoc.c +5 -0
     object_initialize_child(OBJECT(&s->sdhci), "sd-controller.sdhci",
@@ -220,6 +225,11 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
         memmap[MICROCHIP_PFSOC_PLIC].size);
     g_free(plic_hart_config);
 
+    /* DMA */
+    sysbus_realize(SYS_BUS_DEVICE(&s->dma), errp);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->dma), 0,
+                    memmap[MICROCHIP_PFSOC_DMA].base);
+
     /* SYSREG */
     create_unimplemented_device("microchip.pfsoc.sysreg",
         memmap[MICROCHIP_PFSOC_SYSREG].base,
include/hw/riscv/microchip_pfsoc.h +3 -0
index d810ee8..7825935 100644
@@ -23,6 +23,7 @@
 #define HW_MICROCHIP_PFSOC_H
 
 #include "hw/char/mchp_pfsoc_mmuart.h"
+#include "hw/dma/mchp_pfsoc_dma.h"
 #include "hw/sd/cadence_sdhci.h"
 
 typedef struct MicrochipPFSoCState {
@@ -40,6 +41,7 @@ typedef struct MicrochipPFSoCState {
     MchpPfSoCMMUartState *serial2;
     MchpPfSoCMMUartState *serial3;
     MchpPfSoCMMUartState *serial4;
+    MchpPfSoCDMAState dma;
     CadenceSDHCIState sdhci;
 } MicrochipPFSoCState;
 
@@ -71,6 +73,7 @@ enum {
     MICROCHIP_PFSOC_BUSERR_UNIT4,
     MICROCHIP_PFSOC_CLINT,
     MICROCHIP_PFSOC_L2CC,
+    MICROCHIP_PFSOC_DMA,
     MICROCHIP_PFSOC_L2LIM,
     MICROCHIP_PFSOC_PLIC,
     MICROCHIP_PFSOC_MMUART0,
author
#33 lore raw

Re: [PATCH 13/18] hw/riscv: microchip_pfsoc: Connect a DMA controller

Hi Philippe,

Quoted 53 lines · Philippe Mathieu-Daudé
Quoted 51 lines · Bin Meng

From: Bin Meng <[email protected]>

Connect a DMA controller to Microchip PolarFire SoC. Note interrupt has not been connected due to missing information in the manual how interrupts are routed to PLIC.

On the Icicle Kit board, the HSS firmware utilizes the on-chip DMA controller to move the 2nd stage bootloader in the system memory.

---

 hw/riscv/Kconfig                   |  1 +
 hw/riscv/microchip_pfsoc.c         | 10 ++++++++++
 include/hw/riscv/microchip_pfsoc.h |  3 +++
 3 files changed, 14 insertions(+)
hw/riscv/Kconfig +1 -0
index 7412db9..9323701 100644
@@ -55,4 +55,5 @@ config MICROCHIP_PFSOC
     select SIFIVE
     select UNIMP
     select MCHP_PFSOC_MMUART
+    select MCHP_PFSOC_DMA
     select CADENCE_SDHCI
hw/riscv/microchip_pfsoc.c +2 -0
index 7c09078..1c67cbc 100644
@@ -13,6 +13,7 @@
  * 2) eNVM (Embedded Non-Volatile Memory)
  * 3) MMUARTs (Multi-Mode UART)
  * 4) Cadence eMMC/SDHC controller and an SD card connected to it
+ * 5) DMA (Direct Memory Access Controller)
  *
  * This board currently generates devicetree dynamically that indicates at least
  * two harts and up to five harts.
@@ -71,6 +72,7 @@ static const struct MemmapEntry {
     [MICROCHIP_PFSOC_BUSERR_UNIT4] =    {  0x1704000,     0x1000 },
     [MICROCHIP_PFSOC_CLINT] =           {  0x2000000,    0x10000 },
     [MICROCHIP_PFSOC_L2CC] =            {  0x2010000,     0x1000 },
+    [MICROCHIP_PFSOC_DMA] =             {  0x3000000,   0x100000 },
     [MICROCHIP_PFSOC_L2LIM] =           {  0x8000000,  0x2000000 },
     [MICROCHIP_PFSOC_PLIC] =            {  0xc000000,  0x4000000 },
     [MICROCHIP_PFSOC_MMUART0] =         { 0x20000000,     0x1000 },
@@ -114,6 +116,9 @@ static void microchip_pfsoc_soc_instance_init(Object *obj)
                          TYPE_RISCV_CPU_SIFIVE_U54);
     qdev_prop_set_uint64(DEVICE(&s->u_cpus), "resetvec", RESET_VECTOR);
 
Quoted 10 lines

hw/riscv/microchip_pfsoc.c static void microchip_pfsoc_soc_instance_init(Object *obj) · line 123

Quoted 5 lines
hw/riscv/microchip_pfsoc.c +3 -0
+    object_initialize_child(obj, "dma-controller", &s->dma,
+                            TYPE_MCHP_PFSOC_DMA);
+
     object_initialize_child(obj, "sd-controller", &s->sdhci,
                             TYPE_CADENCE_SDHCI);

I haven't looked at the chip specs, but maybe you can add the SD controller after the DMA controller so so you can directly link a DMA address space to it.

I am not sure I understand what you meant about adding the SD controller after the DMA controller. The Cadence SD controller has its own built-in DMA and does not depend on this DMA controller.

Regards,
Bin

#34 lore raw

Re: [PATCH 13/18] hw/riscv: microchip_pfsoc: Connect a DMA controller

Quoted 67 lines · Bin Meng

Hi Philippe,

Quoted 53 lines · Philippe Mathieu-Daudé
Quoted 51 lines · Bin Meng

From: Bin Meng <[email protected]>

Connect a DMA controller to Microchip PolarFire SoC. Note interrupt has not been connected due to missing information in the manual how interrupts are routed to PLIC.

On the Icicle Kit board, the HSS firmware utilizes the on-chip DMA controller to move the 2nd stage bootloader in the system memory.

---

 hw/riscv/Kconfig                   |  1 +
 hw/riscv/microchip_pfsoc.c         | 10 ++++++++++
 include/hw/riscv/microchip_pfsoc.h |  3 +++
 3 files changed, 14 insertions(+)
hw/riscv/Kconfig +1 -0
index 7412db9..9323701 100644
@@ -55,4 +55,5 @@ config MICROCHIP_PFSOC
     select SIFIVE
     select UNIMP
     select MCHP_PFSOC_MMUART
+    select MCHP_PFSOC_DMA
     select CADENCE_SDHCI
hw/riscv/microchip_pfsoc.c +2 -0
index 7c09078..1c67cbc 100644
@@ -13,6 +13,7 @@
  * 2) eNVM (Embedded Non-Volatile Memory)
  * 3) MMUARTs (Multi-Mode UART)
  * 4) Cadence eMMC/SDHC controller and an SD card connected to it
+ * 5) DMA (Direct Memory Access Controller)
  *
  * This board currently generates devicetree dynamically that indicates at least
  * two harts and up to five harts.
@@ -71,6 +72,7 @@ static const struct MemmapEntry {
     [MICROCHIP_PFSOC_BUSERR_UNIT4] =    {  0x1704000,     0x1000 },
     [MICROCHIP_PFSOC_CLINT] =           {  0x2000000,    0x10000 },
     [MICROCHIP_PFSOC_L2CC] =            {  0x2010000,     0x1000 },
+    [MICROCHIP_PFSOC_DMA] =             {  0x3000000,   0x100000 },
     [MICROCHIP_PFSOC_L2LIM] =           {  0x8000000,  0x2000000 },
     [MICROCHIP_PFSOC_PLIC] =            {  0xc000000,  0x4000000 },
     [MICROCHIP_PFSOC_MMUART0] =         { 0x20000000,     0x1000 },
@@ -114,6 +116,9 @@ static void microchip_pfsoc_soc_instance_init(Object *obj)
                          TYPE_RISCV_CPU_SIFIVE_U54);
     qdev_prop_set_uint64(DEVICE(&s->u_cpus), "resetvec", RESET_VECTOR);
 
Quoted 10 lines

hw/riscv/microchip_pfsoc.c static void microchip_pfsoc_soc_instance_init(Object *obj) · line 123

Quoted 5 lines
hw/riscv/microchip_pfsoc.c +3 -0
+    object_initialize_child(obj, "dma-controller", &s->dma,
+                            TYPE_MCHP_PFSOC_DMA);
+
     object_initialize_child(obj, "sd-controller", &s->sdhci,
                             TYPE_CADENCE_SDHCI);

I haven't looked at the chip specs, but maybe you can add the SD controller after the DMA controller so so you can directly link a DMA address space to it.

Quoted 3 lines

I am not sure I understand what you meant about adding the SD controller after the DMA controller. The Cadence SD controller has its own built-in DMA and does not depend on this DMA controller.

Ah OK. What I'm concerned about is the SD controller do its DMA access in a proper DMA address space.

Quoted 4 lines

Regards,
Bin

author
#35 lore raw

PATCH 14/18 hw/net: cadence_gem: Add a new 'phy-addr' property

In reply to Bin Meng

From: Bin Meng <[email protected]>

At present the PHY address of the PHY connected to GEM is hard-coded to either 23 (BOARD_PHY_ADDRESS) or 0. This might not be the case for all boards. Add a new 'phy-addr' property so that board can specify the PHY address for each GEM instance.

---

 hw/net/cadence_gem.c         | 7 +++++--
 include/hw/net/cadence_gem.h | 2 ++
 2 files changed, 7 insertions(+), 2 deletions(-)
hw/net/cadence_gem.c +5 -2
index a93b5c0..9fa03de 100644
@@ -1446,7 +1446,8 @@ static uint64_t gem_read(void *opaque, hwaddr offset, unsigned size)
             uint32_t phy_addr, reg_num;
 
             phy_addr = (retval & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT;
-            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0) {
+            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0 ||
+                phy_addr == s->phy_addr) {
                 reg_num = (retval & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT;
                 retval &= 0xFFFF0000;
                 retval |= gem_phy_read(s, reg_num);
@@ -1569,7 +1570,8 @@ static void gem_write(void *opaque, hwaddr offset, uint64_t val,
             uint32_t phy_addr, reg_num;
 
             phy_addr = (val & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT;
-            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0) {
+            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0 ||
+                phy_addr == s->phy_addr) {
                 reg_num = (val & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT;
                 gem_phy_write(s, reg_num, val);
             }
@@ -1682,6 +1684,7 @@ static Property gem_properties[] = {
     DEFINE_NIC_PROPERTIES(CadenceGEMState, conf),
     DEFINE_PROP_UINT32("revision", CadenceGEMState, revision,
                        GEM_MODID_VALUE),
+    DEFINE_PROP_UINT8("phy-addr", CadenceGEMState, phy_addr, 0),
     DEFINE_PROP_UINT8("num-priority-queues", CadenceGEMState,
                       num_priority_queues, 1),
     DEFINE_PROP_UINT8("num-type1-screeners", CadenceGEMState,
include/hw/net/cadence_gem.h +2 -0
index 54e646f..01c6189 100644
@@ -73,6 +73,8 @@ typedef struct CadenceGEMState {
     /* Mask of register bits which are write 1 to clear */
     uint32_t regs_w1c[CADENCE_GEM_MAXREG];
 
+    /* PHY address */
+    uint8_t phy_addr;
     /* PHY registers backing store */
     uint16_t phy_regs[32];
 
Signature · 1 line
2.7.4
#36 lore raw

Re: [PATCH 14/18] hw/net: cadence_gem: Add a new 'phy-addr' property

Quoted 39 lines · Bin Meng

From: Bin Meng <[email protected]>

At present the PHY address of the PHY connected to GEM is hard-coded to either 23 (BOARD_PHY_ADDRESS) or 0. This might not be the case for all boards. Add a new 'phy-addr' property so that board can specify the PHY address for each GEM instance.

---

 hw/net/cadence_gem.c         | 7 +++++--
 include/hw/net/cadence_gem.h | 2 ++
 2 files changed, 7 insertions(+), 2 deletions(-)
hw/net/cadence_gem.c +4 -2
index a93b5c0..9fa03de 100644
@@ -1446,7 +1446,8 @@ static uint64_t gem_read(void *opaque, hwaddr offset, unsigned size)
             uint32_t phy_addr, reg_num;
 
             phy_addr = (retval & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT;
-            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0) {
+            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0 ||
+                phy_addr == s->phy_addr) {
                 reg_num = (retval & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT;
                 retval &= 0xFFFF0000;
                 retval |= gem_phy_read(s, reg_num);
@@ -1569,7 +1570,8 @@ static void gem_write(void *opaque, hwaddr offset, uint64_t val,
             uint32_t phy_addr, reg_num;
 
             phy_addr = (val & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT;
-            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0) {
+            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0 ||
+                phy_addr == s->phy_addr) {
                 reg_num = (val & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT;
                 gem_phy_write(s, reg_num, val);
             }

hw/net/cadence_gem.c static Property gem_properties[] = { · line 1687

Quoted 4 lines
hw/net/cadence_gem.c +1 -0
@@ -1682,6 +1684,7 @@ static Property gem_properties[] = {
     DEFINE_NIC_PROPERTIES(CadenceGEMState, conf),
     DEFINE_PROP_UINT32("revision", CadenceGEMState, revision,
                        GEM_MODID_VALUE),
+    DEFINE_PROP_UINT8("phy-addr", CadenceGEMState, phy_addr, 0),

This patch would be complete by moving the BOARD_PHY_ADDRESS definition to each board using this NIC, and setting the "phy-addr" property to this value.

Quoted 17 lines
hw/net/cadence_gem.c +0 -0
     DEFINE_PROP_UINT8("num-priority-queues", CadenceGEMState,
                       num_priority_queues, 1),
     DEFINE_PROP_UINT8("num-type1-screeners", CadenceGEMState,
include/hw/net/cadence_gem.h +2 -0
index 54e646f..01c6189 100644
@@ -73,6 +73,8 @@ typedef struct CadenceGEMState {
     /* Mask of register bits which are write 1 to clear */
     uint32_t regs_w1c[CADENCE_GEM_MAXREG];
 
+    /* PHY address */
+    uint8_t phy_addr;
     /* PHY registers backing store */
     uint16_t phy_regs[32];
 
author Acked-by Edgar E. Iglesias Reviewed-by Beniamino Galvani
#37 lore raw

Re: [PATCH 14/18] hw/net: cadence_gem: Add a new 'phy-addr' property

Quoted 33 lines · Philippe Mathieu-Daudé
Quoted 31 lines · Bin Meng

From: Bin Meng <[email protected]>

At present the PHY address of the PHY connected to GEM is hard-coded to either 23 (BOARD_PHY_ADDRESS) or 0. This might not be the case for all boards. Add a new 'phy-addr' property so that board can specify the PHY address for each GEM instance.

---

 hw/net/cadence_gem.c         | 7 +++++--
 include/hw/net/cadence_gem.h | 2 ++
 2 files changed, 7 insertions(+), 2 deletions(-)
hw/net/cadence_gem.c +2 -1
index a93b5c0..9fa03de 100644
@@ -1446,7 +1446,8 @@ static uint64_t gem_read(void *opaque, hwaddr offset, unsigned size)
             uint32_t phy_addr, reg_num;
 
             phy_addr = (retval & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT;
-            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0) {
+            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0 ||
+                phy_addr == s->phy_addr) {
                 reg_num = (retval & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT;
                 retval &= 0xFFFF0000;
                 retval |= gem_phy_read(s, reg_num);
@@ -1569,7 +1570,8 @@ static void gem_write(void *opaque, hwaddr offset, uint64_t val,
             uint32_t phy_addr, reg_num;
 
Quoted 16 lines

hw/net/cadence_gem.c static Property gem_properties[] = { · line 1687

Quoted 12 lines
hw/net/cadence_gem.c +3 -1
             phy_addr = (val & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT;
-            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0) {
+            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0 ||
+                phy_addr == s->phy_addr) {
                 reg_num = (val & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT;
                 gem_phy_write(s, reg_num, val);
             }
@@ -1682,6 +1684,7 @@ static Property gem_properties[] = {
     DEFINE_NIC_PROPERTIES(CadenceGEMState, conf),
     DEFINE_PROP_UINT32("revision", CadenceGEMState, revision,
                        GEM_MODID_VALUE),
+    DEFINE_PROP_UINT8("phy-addr", CadenceGEMState, phy_addr, 0),

This patch would be complete by moving the BOARD_PHY_ADDRESS definition to each board using this NIC, and setting the "phy-addr" property to this value.

I actually have no idea which board in QEMU is using this special PHY address instead of default 0.

It looks BOARD_PHY_ADDRESS has been there since the initial version of the cadence_gem model.

commit e9f186e514a70557d695cadd2c2287ef97737023

Author: Peter A. G. Crosthwaite <[email protected]>
Date:   Mon Mar 5 14:39:12 2012 +1000

cadence_gem: initial version of device model

Device model for cadence gem ethernet controller.

Later PHY address 0 was added via the following commit:

commit 553893736885e4f2dda424bff3e2200e1b6482a5

Author: Peter Crosthwaite <[email protected]>
Date:   Thu Apr 3 23:55:19 2014 -0700

net: cadence_gem: Make phy respond to broadcast

Phys must respond to address 0 by specification. Implement.

Message-id:
6f4d53b04ddbfb19895bfb61a595e69f1c08859a.1396594056.git.peter.crosthwaite@xilinx.com

I doubt the commit message said that PHYs must respond to address 0. I am not aware of such specs. The issue was probably that whatever board 2nd commit was tested against did not have a PHY at address BOARD_PHY_ADDRESS.

+ a couple of Xilinx folks to comment.

Quoted 12 lines
Quoted 12 lines
hw/net/cadence_gem.c +0 -0
     DEFINE_PROP_UINT8("num-priority-queues", CadenceGEMState,
                       num_priority_queues, 1),
     DEFINE_PROP_UINT8("num-type1-screeners", CadenceGEMState,
include/hw/net/cadence_gem.h +0 -0
index 54e646f..01c6189 100644
@@ -73,6 +73,8 @@ typedef struct CadenceGEMState {
     /* Mask of register bits which are write 1 to clear */
     uint32_t regs_w1c[CADENCE_GEM_MAXREG];
 
Quoted 4 lines

include/hw/net/cadence_gem.h typedef struct CadenceGEMState { · line 79

Quoted 4 lines
include/hw/net/cadence_gem.h +2 -0
+    /* PHY address */
+    uint8_t phy_addr;
     /* PHY registers backing store */
     uint16_t phy_regs[32];

Regards,
Bin

#38 lore raw

Re: [PATCH 14/18] hw/net: cadence_gem: Add a new 'phy-addr' property

Quoted 51 lines · Bin Meng
Quoted 33 lines · Philippe Mathieu-Daudé
Quoted 31 lines · Bin Meng

From: Bin Meng <[email protected]>

At present the PHY address of the PHY connected to GEM is hard-coded to either 23 (BOARD_PHY_ADDRESS) or 0. This might not be the case for all boards. Add a new 'phy-addr' property so that board can specify the PHY address for each GEM instance.

---

 hw/net/cadence_gem.c         | 7 +++++--
 include/hw/net/cadence_gem.h | 2 ++
 2 files changed, 7 insertions(+), 2 deletions(-)
hw/net/cadence_gem.c +2 -1
index a93b5c0..9fa03de 100644
@@ -1446,7 +1446,8 @@ static uint64_t gem_read(void *opaque, hwaddr offset, unsigned size)
             uint32_t phy_addr, reg_num;
 
             phy_addr = (retval & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT;
-            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0) {
+            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0 ||
+                phy_addr == s->phy_addr) {
                 reg_num = (retval & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT;
                 retval &= 0xFFFF0000;
                 retval |= gem_phy_read(s, reg_num);
@@ -1569,7 +1570,8 @@ static void gem_write(void *opaque, hwaddr offset, uint64_t val,
             uint32_t phy_addr, reg_num;
 
Quoted 16 lines

hw/net/cadence_gem.c static Property gem_properties[] = { · line 1687

Quoted 12 lines
hw/net/cadence_gem.c +3 -1
             phy_addr = (val & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT;
-            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0) {
+            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0 ||
+                phy_addr == s->phy_addr) {
                 reg_num = (val & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT;
                 gem_phy_write(s, reg_num, val);
             }
@@ -1682,6 +1684,7 @@ static Property gem_properties[] = {
     DEFINE_NIC_PROPERTIES(CadenceGEMState, conf),
     DEFINE_PROP_UINT32("revision", CadenceGEMState, revision,
                        GEM_MODID_VALUE),
+    DEFINE_PROP_UINT8("phy-addr", CadenceGEMState, phy_addr, 0),

This patch would be complete by moving the BOARD_PHY_ADDRESS definition to each board using this NIC, and setting the "phy-addr" property to this value.

Quoted 2 lines

I actually have no idea which board in QEMU is using this special PHY address instead of default 0.

It seems safe to assume all do use address 23.

Anyway you can simply get ride of BOARD_PHY_ADDRESS in the read/write using:

DEFINE_PROP_UINT8("phy-addr", CadenceGEMState,
phy_addr, BOARD_PHY_ADDRESS),

Quoted 61 lines

It looks BOARD_PHY_ADDRESS has been there since the initial version of the cadence_gem model.

commit e9f186e514a70557d695cadd2c2287ef97737023

Author: Peter A. G. Crosthwaite <[email protected]>
Date:   Mon Mar 5 14:39:12 2012 +1000

cadence_gem: initial version of device model

Device model for cadence gem ethernet controller.

Later PHY address 0 was added via the following commit:

commit 553893736885e4f2dda424bff3e2200e1b6482a5

Author: Peter Crosthwaite <[email protected]>
Date:   Thu Apr 3 23:55:19 2014 -0700

net: cadence_gem: Make phy respond to broadcast

Phys must respond to address 0 by specification. Implement.

Message-id:
6f4d53b04ddbfb19895bfb61a595e69f1c08859a.1396594056.git.peter.crosthwaite@xilinx.com

I doubt the commit message said that PHYs must respond to address 0. I am not aware of such specs. The issue was probably that whatever board 2nd commit was tested against did not have a PHY at address BOARD_PHY_ADDRESS.

+ a couple of Xilinx folks to comment.

Quoted 12 lines
Quoted 12 lines
hw/net/cadence_gem.c +0 -0
     DEFINE_PROP_UINT8("num-priority-queues", CadenceGEMState,
                       num_priority_queues, 1),
     DEFINE_PROP_UINT8("num-type1-screeners", CadenceGEMState,
include/hw/net/cadence_gem.h +0 -0
index 54e646f..01c6189 100644
@@ -73,6 +73,8 @@ typedef struct CadenceGEMState {
     /* Mask of register bits which are write 1 to clear */
     uint32_t regs_w1c[CADENCE_GEM_MAXREG];
 
Quoted 4 lines

include/hw/net/cadence_gem.h typedef struct CadenceGEMState { · line 79

Quoted 4 lines
include/hw/net/cadence_gem.h +2 -0
+    /* PHY address */
+    uint8_t phy_addr;
     /* PHY registers backing store */
     uint16_t phy_regs[32];

Regards,
Bin

#39 lore raw

Re: [PATCH 14/18] hw/net: cadence_gem: Add a new 'phy-addr' property

In reply to Bin Meng
Quoted 52 lines · Bin Meng
Quoted 33 lines · Philippe Mathieu-Daudé
Quoted 31 lines · Bin Meng

From: Bin Meng <[email protected]>

At present the PHY address of the PHY connected to GEM is hard-coded to either 23 (BOARD_PHY_ADDRESS) or 0. This might not be the case for all boards. Add a new 'phy-addr' property so that board can specify the PHY address for each GEM instance.

---

 hw/net/cadence_gem.c         | 7 +++++--
 include/hw/net/cadence_gem.h | 2 ++
 2 files changed, 7 insertions(+), 2 deletions(-)
hw/net/cadence_gem.c +2 -1
index a93b5c0..9fa03de 100644
@@ -1446,7 +1446,8 @@ static uint64_t gem_read(void *opaque, hwaddr offset, unsigned size)
             uint32_t phy_addr, reg_num;
 
             phy_addr = (retval & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT;
-            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0) {
+            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0 ||
+                phy_addr == s->phy_addr) {
                 reg_num = (retval & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT;
                 retval &= 0xFFFF0000;
                 retval |= gem_phy_read(s, reg_num);
@@ -1569,7 +1570,8 @@ static void gem_write(void *opaque, hwaddr offset, uint64_t val,
             uint32_t phy_addr, reg_num;
 
Quoted 16 lines

hw/net/cadence_gem.c static Property gem_properties[] = { · line 1687

Quoted 12 lines
hw/net/cadence_gem.c +3 -1
             phy_addr = (val & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT;
-            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0) {
+            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0 ||
+                phy_addr == s->phy_addr) {
                 reg_num = (val & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT;
                 gem_phy_write(s, reg_num, val);
             }
@@ -1682,6 +1684,7 @@ static Property gem_properties[] = {
     DEFINE_NIC_PROPERTIES(CadenceGEMState, conf),
     DEFINE_PROP_UINT32("revision", CadenceGEMState, revision,
                        GEM_MODID_VALUE),
+    DEFINE_PROP_UINT8("phy-addr", CadenceGEMState, phy_addr, 0),

This patch would be complete by moving the BOARD_PHY_ADDRESS definition to each board using this NIC, and setting the "phy-addr" property to this value.

Quoted 2 lines

I actually have no idea which board in QEMU is using this special PHY address instead of default 0.

Given Xilinx's QEMU fork has not used this value for quite some time, I suspect it was only used to match an early chip emulation platform/board.

https://github.com/Xilinx/qemu/blame/master/hw/net/cadence_gem.c#L248

Quoted 31 lines

It looks BOARD_PHY_ADDRESS has been there since the initial version of the cadence_gem model.

commit e9f186e514a70557d695cadd2c2287ef97737023

Author: Peter A. G. Crosthwaite <[email protected]>
Date:   Mon Mar 5 14:39:12 2012 +1000

cadence_gem: initial version of device model

Device model for cadence gem ethernet controller.

Later PHY address 0 was added via the following commit:

commit 553893736885e4f2dda424bff3e2200e1b6482a5

Author: Peter Crosthwaite <[email protected]>
Date:   Thu Apr 3 23:55:19 2014 -0700

net: cadence_gem: Make phy respond to broadcast

Phys must respond to address 0 by specification. Implement.

Message-id:
6f4d53b04ddbfb19895bfb61a595e69f1c08859a.1396594056.git.peter.crosthwaite@xilinx.com

Quoted 7 lines

I doubt the commit message said that PHYs must respond to address 0. I am not aware of such specs. The issue was probably that whatever board 2nd commit was tested against did not have a PHY at address BOARD_PHY_ADDRESS.

It is common for phy devices to support it as a broadcast address. It is also commonly written in Xilinx documentation that it is treated as a broadcast address. e.g. the axi ethernet core
(https://www.xilinx.com/support/documentation/ip_documentation/axi_ethernet/v7_0/pg138-axi-ethernet.pdf
page 45). But 802.3 does not require it, instead address 0 is only reserved.

With this commit the "must" refers to the device specification, in that QEMU is emulating a real phy (though more specifically the phy(s) that were being emulated for Zynq boards) that does respond to address 0 as a broadcast. This change was a trade off in order to make QEMU behave as it would on hardware, such that software using address 0 as broadcast would work correctly.

Regards,
Nathan

Quoted 22 lines

+ a couple of Xilinx folks to comment.

Quoted 12 lines
Quoted 12 lines
hw/net/cadence_gem.c +0 -0
     DEFINE_PROP_UINT8("num-priority-queues", CadenceGEMState,
                       num_priority_queues, 1),
     DEFINE_PROP_UINT8("num-type1-screeners", CadenceGEMState,
include/hw/net/cadence_gem.h +0 -0
index 54e646f..01c6189 100644
@@ -73,6 +73,8 @@ typedef struct CadenceGEMState {
     /* Mask of register bits which are write 1 to clear */
     uint32_t regs_w1c[CADENCE_GEM_MAXREG];
 
Quoted 4 lines

include/hw/net/cadence_gem.h typedef struct CadenceGEMState { · line 79

Quoted 4 lines
include/hw/net/cadence_gem.h +2 -0
+    /* PHY address */
+    uint8_t phy_addr;
     /* PHY registers backing store */
     uint16_t phy_regs[32];

Regards,
Bin

author
#40 lore raw

Re: [PATCH 14/18] hw/net: cadence_gem: Add a new 'phy-addr' property

Quoted 109 lines · Nathan Rossi
Quoted 52 lines · Bin Meng
Quoted 33 lines · Philippe Mathieu-Daudé
Quoted 31 lines · Bin Meng

From: Bin Meng <[email protected]>

At present the PHY address of the PHY connected to GEM is hard-coded to either 23 (BOARD_PHY_ADDRESS) or 0. This might not be the case for all boards. Add a new 'phy-addr' property so that board can specify the PHY address for each GEM instance.

---

 hw/net/cadence_gem.c         | 7 +++++--
 include/hw/net/cadence_gem.h | 2 ++
 2 files changed, 7 insertions(+), 2 deletions(-)
hw/net/cadence_gem.c +2 -1
index a93b5c0..9fa03de 100644
@@ -1446,7 +1446,8 @@ static uint64_t gem_read(void *opaque, hwaddr offset, unsigned size)
             uint32_t phy_addr, reg_num;
 
             phy_addr = (retval & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT;
-            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0) {
+            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0 ||
+                phy_addr == s->phy_addr) {
                 reg_num = (retval & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT;
                 retval &= 0xFFFF0000;
                 retval |= gem_phy_read(s, reg_num);
@@ -1569,7 +1570,8 @@ static void gem_write(void *opaque, hwaddr offset, uint64_t val,
             uint32_t phy_addr, reg_num;
 
Quoted 16 lines

hw/net/cadence_gem.c static Property gem_properties[] = { · line 1687

Quoted 12 lines
hw/net/cadence_gem.c +3 -1
             phy_addr = (val & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT;
-            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0) {
+            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0 ||
+                phy_addr == s->phy_addr) {
                 reg_num = (val & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT;
                 gem_phy_write(s, reg_num, val);
             }
@@ -1682,6 +1684,7 @@ static Property gem_properties[] = {
     DEFINE_NIC_PROPERTIES(CadenceGEMState, conf),
     DEFINE_PROP_UINT32("revision", CadenceGEMState, revision,
                        GEM_MODID_VALUE),
+    DEFINE_PROP_UINT8("phy-addr", CadenceGEMState, phy_addr, 0),

This patch would be complete by moving the BOARD_PHY_ADDRESS definition to each board using this NIC, and setting the "phy-addr" property to this value.

Quoted 2 lines

I actually have no idea which board in QEMU is using this special PHY address instead of default 0.

Given Xilinx's QEMU fork has not used this value for quite some time, I suspect it was only used to match an early chip emulation platform/board.

https://github.com/Xilinx/qemu/blame/master/hw/net/cadence_gem.c#L248

Quoted 31 lines

It looks BOARD_PHY_ADDRESS has been there since the initial version of the cadence_gem model.

commit e9f186e514a70557d695cadd2c2287ef97737023

Author: Peter A. G. Crosthwaite <[email protected]>
Date:   Mon Mar 5 14:39:12 2012 +1000

cadence_gem: initial version of device model

Device model for cadence gem ethernet controller.

Later PHY address 0 was added via the following commit:

commit 553893736885e4f2dda424bff3e2200e1b6482a5

Author: Peter Crosthwaite <[email protected]>
Date:   Thu Apr 3 23:55:19 2014 -0700

net: cadence_gem: Make phy respond to broadcast

Phys must respond to address 0 by specification. Implement.

Message-id:
6f4d53b04ddbfb19895bfb61a595e69f1c08859a.1396594056.git.peter.crosthwaite@xilinx.com

Quoted 7 lines

I doubt the commit message said that PHYs must respond to address 0. I am not aware of such specs. The issue was probably that whatever board 2nd commit was tested against did not have a PHY at address BOARD_PHY_ADDRESS.

It is common for phy devices to support it as a broadcast address. It is also commonly written in Xilinx documentation that it is treated as a broadcast address. e.g. the axi ethernet core
(https://www.xilinx.com/support/documentation/ip_documentation/axi_ethernet/v7_0/pg138-axi-ethernet.pdf
page 45). But 802.3 does not require it, instead address 0 is only reserved.

Quoted 7 lines

With this commit the "must" refers to the device specification, in that QEMU is emulating a real phy (though more specifically the phy(s) that were being emulated for Zynq boards) that does respond to address 0 as a broadcast. This change was a trade off in order to make QEMU behave as it would on hardware, such that software using address 0 as broadcast would work correctly.

Thanks Nathan. So is it safe to just remove BOARD_PHY_ADDRESS and set "phy-addr" property default value to 0?

Regards,
Bin

#41 lore raw

Re: [PATCH 14/18] hw/net: cadence_gem: Add a new 'phy-addr' property

Quoted 118 lines · Bin Meng
Quoted 109 lines · Nathan Rossi
Quoted 52 lines · Bin Meng
Quoted 33 lines · Philippe Mathieu-Daudé
Quoted 31 lines · Bin Meng

From: Bin Meng <[email protected]>

At present the PHY address of the PHY connected to GEM is hard-coded to either 23 (BOARD_PHY_ADDRESS) or 0. This might not be the case for all boards. Add a new 'phy-addr' property so that board can specify the PHY address for each GEM instance.

---

 hw/net/cadence_gem.c         | 7 +++++--
 include/hw/net/cadence_gem.h | 2 ++
 2 files changed, 7 insertions(+), 2 deletions(-)
hw/net/cadence_gem.c +2 -1
index a93b5c0..9fa03de 100644
@@ -1446,7 +1446,8 @@ static uint64_t gem_read(void *opaque, hwaddr offset, unsigned size)
             uint32_t phy_addr, reg_num;
 
             phy_addr = (retval & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT;
-            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0) {
+            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0 ||
+                phy_addr == s->phy_addr) {
                 reg_num = (retval & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT;
                 retval &= 0xFFFF0000;
                 retval |= gem_phy_read(s, reg_num);
@@ -1569,7 +1570,8 @@ static void gem_write(void *opaque, hwaddr offset, uint64_t val,
             uint32_t phy_addr, reg_num;
 
Quoted 16 lines

hw/net/cadence_gem.c static Property gem_properties[] = { · line 1687

Quoted 12 lines
hw/net/cadence_gem.c +3 -1
             phy_addr = (val & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT;
-            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0) {
+            if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0 ||
+                phy_addr == s->phy_addr) {
                 reg_num = (val & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT;
                 gem_phy_write(s, reg_num, val);
             }
@@ -1682,6 +1684,7 @@ static Property gem_properties[] = {
     DEFINE_NIC_PROPERTIES(CadenceGEMState, conf),
     DEFINE_PROP_UINT32("revision", CadenceGEMState, revision,
                        GEM_MODID_VALUE),
+    DEFINE_PROP_UINT8("phy-addr", CadenceGEMState, phy_addr, 0),

This patch would be complete by moving the BOARD_PHY_ADDRESS definition to each board using this NIC, and setting the "phy-addr" property to this value.

Quoted 2 lines

I actually have no idea which board in QEMU is using this special PHY address instead of default 0.

Given Xilinx's QEMU fork has not used this value for quite some time, I suspect it was only used to match an early chip emulation platform/board.

https://github.com/Xilinx/qemu/blame/master/hw/net/cadence_gem.c#L248

Quoted 31 lines

It looks BOARD_PHY_ADDRESS has been there since the initial version of the cadence_gem model.

commit e9f186e514a70557d695cadd2c2287ef97737023

Author: Peter A. G. Crosthwaite <[email protected]>
Date:   Mon Mar 5 14:39:12 2012 +1000

cadence_gem: initial version of device model

Device model for cadence gem ethernet controller.

Later PHY address 0 was added via the following commit:

commit 553893736885e4f2dda424bff3e2200e1b6482a5

Author: Peter Crosthwaite <[email protected]>
Date:   Thu Apr 3 23:55:19 2014 -0700

net: cadence_gem: Make phy respond to broadcast

Phys must respond to address 0 by specification. Implement.

Message-id:
6f4d53b04ddbfb19895bfb61a595e69f1c08859a.1396594056.git.peter.crosthwaite@xilinx.com

Quoted 7 lines

I doubt the commit message said that PHYs must respond to address 0. I am not aware of such specs. The issue was probably that whatever board 2nd commit was tested against did not have a PHY at address BOARD_PHY_ADDRESS.

It is common for phy devices to support it as a broadcast address. It is also commonly written in Xilinx documentation that it is treated as a broadcast address. e.g. the axi ethernet core
(https://www.xilinx.com/support/documentation/ip_documentation/axi_ethernet/v7_0/pg138-axi-ethernet.pdf
page 45). But 802.3 does not require it, instead address 0 is only reserved.

Quoted 7 lines

With this commit the "must" refers to the device specification, in that QEMU is emulating a real phy (though more specifically the phy(s) that were being emulated for Zynq boards) that does respond to address 0 as a broadcast. This change was a trade off in order to make QEMU behave as it would on hardware, such that software using address 0 as broadcast would work correctly.

Quoted 2 lines

Thanks Nathan. So is it safe to just remove BOARD_PHY_ADDRESS and set "phy-addr" property default value to 0?

I'd do as following:

First patch, introduce "phy-addr" property (default to BOARD_PHY_ADDRESS) and remove BOARD_PHY_ADDRESS in code:

DEFINE_PROP_UINT8("phy-addr", CadenceGEMState,
phy_addr, BOARD_PHY_ADDRESS),

Second patch set "phy-addr" to BOARD_PHY_ADDRESS in all current boards using this PHY and set the default to 0.

Thanks,

Phil.

Quoted 4 lines

Regards,
Bin

author
#42 lore raw

PATCH 15/18 hw/riscv: microchip_pfsoc: Connect 2 Cadence GEMs

In reply to Bin Meng

From: Bin Meng <[email protected]>

Microchip PolarFire SoC integrates 2 Candence GEMs to provide IEEE 802.3 standard-compliant 10/100/1000 Mbps ethernet interface.

On the Icicle Kit board, GEM0 connects to a PHY at address 8 while GEM1 connects to a PHY at address 9.

The 2nd stage bootloader (U-Boot) is using GEM1 by default, so we must specify 2 '-nic' options from the command line in order to get a working ethernet.

---

 hw/riscv/microchip_pfsoc.c         | 39 ++++++++++++++++++++++++++++++++++++++
 include/hw/riscv/microchip_pfsoc.h |  7 +++++++
 2 files changed, 46 insertions(+)
hw/riscv/microchip_pfsoc.c +39 -0
index 1c67cbc..625b511 100644
@@ -14,6 +14,7 @@
  * 3) MMUARTs (Multi-Mode UART)
  * 4) Cadence eMMC/SDHC controller and an SD card connected to it
  * 5) DMA (Direct Memory Access Controller)
+ * 6) GEM (Gigabit Ethernet MAC Controller)
  *
  * This board currently generates devicetree dynamically that indicates at least
  * two harts and up to five harts.
@@ -59,6 +60,9 @@
 #define BIOS_FILENAME   "hss.bin"
 #define RESET_VECTOR    0x20220000
 
+/* GEM version */
+#define GEM_REVISION    0x0107010c
+
 static const struct MemmapEntry {
     hwaddr base;
     hwaddr size;
@@ -83,6 +87,8 @@ static const struct MemmapEntry {
     [MICROCHIP_PFSOC_MMUART2] =         { 0x20102000,     0x1000 },
     [MICROCHIP_PFSOC_MMUART3] =         { 0x20104000,     0x1000 },
     [MICROCHIP_PFSOC_MMUART4] =         { 0x20106000,     0x1000 },
+    [MICROCHIP_PFSOC_GEM0] =            { 0x20110000,     0x2000 },
+    [MICROCHIP_PFSOC_GEM1] =            { 0x20112000,     0x2000 },
     [MICROCHIP_PFSOC_ENVM_CFG] =        { 0x20200000,     0x1000 },
     [MICROCHIP_PFSOC_ENVM_DATA] =       { 0x20220000,    0x20000 },
     [MICROCHIP_PFSOC_IOSCB_CFG] =       { 0x37080000,     0x1000 },
@@ -119,6 +125,9 @@ static void microchip_pfsoc_soc_instance_init(Object *obj)
     object_initialize_child(obj, "dma-controller", &s->dma,
                             TYPE_MCHP_PFSOC_DMA);
 
+    object_initialize_child(obj, "gem0", &s->gem0, TYPE_CADENCE_GEM);
+    object_initialize_child(obj, "gem1", &s->gem1, TYPE_CADENCE_GEM);
+
     object_initialize_child(obj, "sd-controller", &s->sdhci,
                             TYPE_CADENCE_SDHCI);
     object_initialize_child(OBJECT(&s->sdhci), "sd-controller.sdhci",
@@ -136,6 +145,7 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
     MemoryRegion *envm_data = g_new(MemoryRegion, 1);
     char *plic_hart_config;
     size_t plic_hart_config_len;
+    NICInfo *nd;
     int i;
 
     sysbus_realize(SYS_BUS_DEVICE(&s->e_cpus), &error_abort);
@@ -269,6 +279,35 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
         qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_MMUART4_IRQ),
         serial_hd(4));
 
+    /* GEMs */
+
+    nd = &nd_table[0];
+    if (nd->used) {
+        qemu_check_nic_model(nd, TYPE_CADENCE_GEM);
+        qdev_set_nic_properties(DEVICE(&s->gem0), nd);
+    }
+    nd = &nd_table[1];
+    if (nd->used) {
+        qemu_check_nic_model(nd, TYPE_CADENCE_GEM);
+        qdev_set_nic_properties(DEVICE(&s->gem1), nd);
+    }
+
+    object_property_set_int(OBJECT(&s->gem0), "revision", GEM_REVISION, errp);
+    object_property_set_int(OBJECT(&s->gem0), "phy-addr", 8, errp);
+    sysbus_realize(SYS_BUS_DEVICE(&s->gem0), errp);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->gem0), 0,
+                    memmap[MICROCHIP_PFSOC_GEM0].base);
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->gem0), 0,
+        qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_GEM0_IRQ));
+
+    object_property_set_int(OBJECT(&s->gem1), "revision", GEM_REVISION, errp);
+    object_property_set_int(OBJECT(&s->gem1), "phy-addr", 9, errp);
+    sysbus_realize(SYS_BUS_DEVICE(&s->gem1), errp);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->gem1), 0,
+                    memmap[MICROCHIP_PFSOC_GEM1].base);
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->gem1), 0,
+        qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_GEM1_IRQ));
+
     /* eNVM */
     memory_region_init_rom(envm_data, OBJECT(dev), "microchip.pfsoc.envm.data",
                            memmap[MICROCHIP_PFSOC_ENVM_DATA].size,
include/hw/riscv/microchip_pfsoc.h +7 -0
index 7825935..60f994c 100644
@@ -24,6 +24,7 @@
 
 #include "hw/char/mchp_pfsoc_mmuart.h"
 #include "hw/dma/mchp_pfsoc_dma.h"
+#include "hw/net/cadence_gem.h"
 #include "hw/sd/cadence_sdhci.h"
 
 typedef struct MicrochipPFSoCState {
@@ -42,6 +43,8 @@ typedef struct MicrochipPFSoCState {
     MchpPfSoCMMUartState *serial3;
     MchpPfSoCMMUartState *serial4;
     MchpPfSoCDMAState dma;
+    CadenceGEMState gem0;
+    CadenceGEMState gem1;
     CadenceSDHCIState sdhci;
 } MicrochipPFSoCState;
 
@@ -84,6 +87,8 @@ enum {
     MICROCHIP_PFSOC_MMUART2,
     MICROCHIP_PFSOC_MMUART3,
     MICROCHIP_PFSOC_MMUART4,
+    MICROCHIP_PFSOC_GEM0,
+    MICROCHIP_PFSOC_GEM1,
     MICROCHIP_PFSOC_ENVM_CFG,
     MICROCHIP_PFSOC_ENVM_DATA,
     MICROCHIP_PFSOC_IOSCB_CFG,
@@ -91,6 +96,8 @@ enum {
 };
 
 enum {
+    MICROCHIP_PFSOC_GEM0_IRQ = 64,
+    MICROCHIP_PFSOC_GEM1_IRQ = 70,
     MICROCHIP_PFSOC_EMMC_SD_IRQ = 88,
     MICROCHIP_PFSOC_MMUART0_IRQ = 90,
     MICROCHIP_PFSOC_MMUART1_IRQ = 91,
Signature · 1 line
2.7.4
Reviewed-by on v1 15/18
#43 lore raw

Re: [PATCH 15/18] hw/riscv: microchip_pfsoc: Connect 2 Cadence GEMs

Quoted 6 lines · Bin Meng

From: Bin Meng <[email protected]>

Microchip PolarFire SoC integrates 2 Candence GEMs to provide IEEE 802.3 standard-compliant 10/100/1000 Mbps ethernet interface.

Quoted 8 lines

On the Icicle Kit board, GEM0 connects to a PHY at address 8 while GEM1 connects to a PHY at address 9.

The 2nd stage bootloader (U-Boot) is using GEM1 by default, so we must specify 2 '-nic' options from the command line in order to get a working ethernet.

Alistair

Quoted 134 lines

---

 hw/riscv/microchip_pfsoc.c         | 39 ++++++++++++++++++++++++++++++++++++++
 include/hw/riscv/microchip_pfsoc.h |  7 +++++++
 2 files changed, 46 insertions(+)
hw/riscv/microchip_pfsoc.c +39 -0
index 1c67cbc..625b511 100644
@@ -14,6 +14,7 @@
  * 3) MMUARTs (Multi-Mode UART)
  * 4) Cadence eMMC/SDHC controller and an SD card connected to it
  * 5) DMA (Direct Memory Access Controller)
+ * 6) GEM (Gigabit Ethernet MAC Controller)
  *
  * This board currently generates devicetree dynamically that indicates at least
  * two harts and up to five harts.
@@ -59,6 +60,9 @@
 #define BIOS_FILENAME   "hss.bin"
 #define RESET_VECTOR    0x20220000
 
+/* GEM version */
+#define GEM_REVISION    0x0107010c
+
 static const struct MemmapEntry {
     hwaddr base;
     hwaddr size;
@@ -83,6 +87,8 @@ static const struct MemmapEntry {
     [MICROCHIP_PFSOC_MMUART2] =         { 0x20102000,     0x1000 },
     [MICROCHIP_PFSOC_MMUART3] =         { 0x20104000,     0x1000 },
     [MICROCHIP_PFSOC_MMUART4] =         { 0x20106000,     0x1000 },
+    [MICROCHIP_PFSOC_GEM0] =            { 0x20110000,     0x2000 },
+    [MICROCHIP_PFSOC_GEM1] =            { 0x20112000,     0x2000 },
     [MICROCHIP_PFSOC_ENVM_CFG] =        { 0x20200000,     0x1000 },
     [MICROCHIP_PFSOC_ENVM_DATA] =       { 0x20220000,    0x20000 },
     [MICROCHIP_PFSOC_IOSCB_CFG] =       { 0x37080000,     0x1000 },
@@ -119,6 +125,9 @@ static void microchip_pfsoc_soc_instance_init(Object *obj)
     object_initialize_child(obj, "dma-controller", &s->dma,
                             TYPE_MCHP_PFSOC_DMA);
 
+    object_initialize_child(obj, "gem0", &s->gem0, TYPE_CADENCE_GEM);
+    object_initialize_child(obj, "gem1", &s->gem1, TYPE_CADENCE_GEM);
+
     object_initialize_child(obj, "sd-controller", &s->sdhci,
                             TYPE_CADENCE_SDHCI);
     object_initialize_child(OBJECT(&s->sdhci), "sd-controller.sdhci",
@@ -136,6 +145,7 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
     MemoryRegion *envm_data = g_new(MemoryRegion, 1);
     char *plic_hart_config;
     size_t plic_hart_config_len;
+    NICInfo *nd;
     int i;
 
     sysbus_realize(SYS_BUS_DEVICE(&s->e_cpus), &error_abort);
@@ -269,6 +279,35 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
         qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_MMUART4_IRQ),
         serial_hd(4));
 
+    /* GEMs */
+
+    nd = &nd_table[0];
+    if (nd->used) {
+        qemu_check_nic_model(nd, TYPE_CADENCE_GEM);
+        qdev_set_nic_properties(DEVICE(&s->gem0), nd);
+    }
+    nd = &nd_table[1];
+    if (nd->used) {
+        qemu_check_nic_model(nd, TYPE_CADENCE_GEM);
+        qdev_set_nic_properties(DEVICE(&s->gem1), nd);
+    }
+
+    object_property_set_int(OBJECT(&s->gem0), "revision", GEM_REVISION, errp);
+    object_property_set_int(OBJECT(&s->gem0), "phy-addr", 8, errp);
+    sysbus_realize(SYS_BUS_DEVICE(&s->gem0), errp);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->gem0), 0,
+                    memmap[MICROCHIP_PFSOC_GEM0].base);
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->gem0), 0,
+        qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_GEM0_IRQ));
+
+    object_property_set_int(OBJECT(&s->gem1), "revision", GEM_REVISION, errp);
+    object_property_set_int(OBJECT(&s->gem1), "phy-addr", 9, errp);
+    sysbus_realize(SYS_BUS_DEVICE(&s->gem1), errp);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->gem1), 0,
+                    memmap[MICROCHIP_PFSOC_GEM1].base);
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->gem1), 0,
+        qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_GEM1_IRQ));
+
     /* eNVM */
     memory_region_init_rom(envm_data, OBJECT(dev), "microchip.pfsoc.envm.data",
                            memmap[MICROCHIP_PFSOC_ENVM_DATA].size,
include/hw/riscv/microchip_pfsoc.h +7 -1
index 7825935..60f994c 100644
@@ -24,6 +24,7 @@
 
 #include "hw/char/mchp_pfsoc_mmuart.h"
 #include "hw/dma/mchp_pfsoc_dma.h"
+#include "hw/net/cadence_gem.h"
 #include "hw/sd/cadence_sdhci.h"
 
 typedef struct MicrochipPFSoCState {
@@ -42,6 +43,8 @@ typedef struct MicrochipPFSoCState {
     MchpPfSoCMMUartState *serial3;
     MchpPfSoCMMUartState *serial4;
     MchpPfSoCDMAState dma;
+    CadenceGEMState gem0;
+    CadenceGEMState gem1;
     CadenceSDHCIState sdhci;
 } MicrochipPFSoCState;
 
@@ -84,6 +87,8 @@ enum {
     MICROCHIP_PFSOC_MMUART2,
     MICROCHIP_PFSOC_MMUART3,
     MICROCHIP_PFSOC_MMUART4,
+    MICROCHIP_PFSOC_GEM0,
+    MICROCHIP_PFSOC_GEM1,
     MICROCHIP_PFSOC_ENVM_CFG,
     MICROCHIP_PFSOC_ENVM_DATA,
     MICROCHIP_PFSOC_IOSCB_CFG,
@@ -91,6 +96,8 @@ enum {
 };
 
 enum {
+    MICROCHIP_PFSOC_GEM0_IRQ = 64,
+    MICROCHIP_PFSOC_GEM1_IRQ = 70,
     MICROCHIP_PFSOC_EMMC_SD_IRQ = 88,
     MICROCHIP_PFSOC_MMUART0_IRQ = 90,
     MICROCHIP_PFSOC_MMUART1_IRQ = 91,
--

2.7.4

author
#44 lore raw

PATCH 16/18 hw/riscv: microchip_pfsoc: Hook GPIO controllers

In reply to Bin Meng

From: Bin Meng <[email protected]>

Microchip PolarFire SoC integrates 3 GPIOs controllers. It seems enough to create unimplemented devices to cover their register spaces at this point.

With this commit, QEMU can boot to U-Boot (2nd stage bootloader) all the way to the Linux shell login prompt, with a modified HSS (1st stage bootloader).

---

 hw/riscv/microchip_pfsoc.c         | 14 ++++++++++++++
 include/hw/riscv/microchip_pfsoc.h |  3 +++
 2 files changed, 17 insertions(+)
hw/riscv/microchip_pfsoc.c +14 -0
index 625b511..139284a 100644
@@ -89,6 +89,9 @@ static const struct MemmapEntry {
     [MICROCHIP_PFSOC_MMUART4] =         { 0x20106000,     0x1000 },
     [MICROCHIP_PFSOC_GEM0] =            { 0x20110000,     0x2000 },
     [MICROCHIP_PFSOC_GEM1] =            { 0x20112000,     0x2000 },
+    [MICROCHIP_PFSOC_GPIO0] =           { 0x20120000,     0x1000 },
+    [MICROCHIP_PFSOC_GPIO1] =           { 0x20121000,     0x1000 },
+    [MICROCHIP_PFSOC_GPIO2] =           { 0x20122000,     0x1000 },
     [MICROCHIP_PFSOC_ENVM_CFG] =        { 0x20200000,     0x1000 },
     [MICROCHIP_PFSOC_ENVM_DATA] =       { 0x20220000,    0x20000 },
     [MICROCHIP_PFSOC_IOSCB_CFG] =       { 0x37080000,     0x1000 },
@@ -308,6 +311,17 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
     sysbus_connect_irq(SYS_BUS_DEVICE(&s->gem1), 0,
         qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_GEM1_IRQ));
 
+    /* GPIOs */
+    create_unimplemented_device("microchip.pfsoc.gpio0",
+        memmap[MICROCHIP_PFSOC_GPIO0].base,
+        memmap[MICROCHIP_PFSOC_GPIO0].size);
+    create_unimplemented_device("microchip.pfsoc.gpio1",
+        memmap[MICROCHIP_PFSOC_GPIO1].base,
+        memmap[MICROCHIP_PFSOC_GPIO1].size);
+    create_unimplemented_device("microchip.pfsoc.gpio2",
+        memmap[MICROCHIP_PFSOC_GPIO2].base,
+        memmap[MICROCHIP_PFSOC_GPIO2].size);
+
     /* eNVM */
     memory_region_init_rom(envm_data, OBJECT(dev), "microchip.pfsoc.envm.data",
                            memmap[MICROCHIP_PFSOC_ENVM_DATA].size,
include/hw/riscv/microchip_pfsoc.h +3 -0
index 60f994c..993b17c 100644
@@ -89,6 +89,9 @@ enum {
     MICROCHIP_PFSOC_MMUART4,
     MICROCHIP_PFSOC_GEM0,
     MICROCHIP_PFSOC_GEM1,
+    MICROCHIP_PFSOC_GPIO0,
+    MICROCHIP_PFSOC_GPIO1,
+    MICROCHIP_PFSOC_GPIO2,
     MICROCHIP_PFSOC_ENVM_CFG,
     MICROCHIP_PFSOC_ENVM_DATA,
     MICROCHIP_PFSOC_IOSCB_CFG,
Signature · 1 line
2.7.4
Reviewed-by on v1 16/18
#45 lore raw

Re: [PATCH 16/18] hw/riscv: microchip_pfsoc: Hook GPIO controllers

Quoted 7 lines · Bin Meng

From: Bin Meng <[email protected]>

Microchip PolarFire SoC integrates 3 GPIOs controllers. It seems enough to create unimplemented devices to cover their register spaces at this point.

Quoted 5 lines

With this commit, QEMU can boot to U-Boot (2nd stage bootloader) all the way to the Linux shell login prompt, with a modified HSS (1st stage bootloader).

Alistair

Quoted 56 lines

---

 hw/riscv/microchip_pfsoc.c         | 14 ++++++++++++++
 include/hw/riscv/microchip_pfsoc.h |  3 +++
 2 files changed, 17 insertions(+)
hw/riscv/microchip_pfsoc.c +14 -0
index 625b511..139284a 100644
@@ -89,6 +89,9 @@ static const struct MemmapEntry {
     [MICROCHIP_PFSOC_MMUART4] =         { 0x20106000,     0x1000 },
     [MICROCHIP_PFSOC_GEM0] =            { 0x20110000,     0x2000 },
     [MICROCHIP_PFSOC_GEM1] =            { 0x20112000,     0x2000 },
+    [MICROCHIP_PFSOC_GPIO0] =           { 0x20120000,     0x1000 },
+    [MICROCHIP_PFSOC_GPIO1] =           { 0x20121000,     0x1000 },
+    [MICROCHIP_PFSOC_GPIO2] =           { 0x20122000,     0x1000 },
     [MICROCHIP_PFSOC_ENVM_CFG] =        { 0x20200000,     0x1000 },
     [MICROCHIP_PFSOC_ENVM_DATA] =       { 0x20220000,    0x20000 },
     [MICROCHIP_PFSOC_IOSCB_CFG] =       { 0x37080000,     0x1000 },
@@ -308,6 +311,17 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
     sysbus_connect_irq(SYS_BUS_DEVICE(&s->gem1), 0,
         qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_GEM1_IRQ));
 
+    /* GPIOs */
+    create_unimplemented_device("microchip.pfsoc.gpio0",
+        memmap[MICROCHIP_PFSOC_GPIO0].base,
+        memmap[MICROCHIP_PFSOC_GPIO0].size);
+    create_unimplemented_device("microchip.pfsoc.gpio1",
+        memmap[MICROCHIP_PFSOC_GPIO1].base,
+        memmap[MICROCHIP_PFSOC_GPIO1].size);
+    create_unimplemented_device("microchip.pfsoc.gpio2",
+        memmap[MICROCHIP_PFSOC_GPIO2].base,
+        memmap[MICROCHIP_PFSOC_GPIO2].size);
+
     /* eNVM */
     memory_region_init_rom(envm_data, OBJECT(dev), "microchip.pfsoc.envm.data",
                            memmap[MICROCHIP_PFSOC_ENVM_DATA].size,
include/hw/riscv/microchip_pfsoc.h +3 -1
index 60f994c..993b17c 100644
@@ -89,6 +89,9 @@ enum {
     MICROCHIP_PFSOC_MMUART4,
     MICROCHIP_PFSOC_GEM0,
     MICROCHIP_PFSOC_GEM1,
+    MICROCHIP_PFSOC_GPIO0,
+    MICROCHIP_PFSOC_GPIO1,
+    MICROCHIP_PFSOC_GPIO2,
     MICROCHIP_PFSOC_ENVM_CFG,
     MICROCHIP_PFSOC_ENVM_DATA,
     MICROCHIP_PFSOC_IOSCB_CFG,
--

2.7.4

author
#46 lore raw

PATCH 17/18 hw/riscv: clint: Avoid using hard-coded timebase frequency

In reply to Bin Meng

From: Bin Meng <[email protected]>

At present the CLINT timestamp is using a hard-coded timebase frequency value SIFIVE_CLINT_TIMEBASE_FREQ. This might not be true for all boards.

Add a new 'timebase-freq' property to the CLINT device, and update various functions to accept this as a parameter.

---

 hw/riscv/microchip_pfsoc.c      |  6 +++++-
 hw/riscv/sifive_clint.c         | 25 ++++++++++++++-----------
 hw/riscv/sifive_e.c             |  3 ++-
 hw/riscv/sifive_u.c             |  3 ++-
 hw/riscv/spike.c                |  2 +-
 hw/riscv/virt.c                 |  3 ++-
 include/hw/riscv/sifive_clint.h |  3 ++-
 target/riscv/cpu.h              |  6 ++++--
 target/riscv/cpu_helper.c       |  4 +++-
 target/riscv/csr.c              |  4 ++--
 10 files changed, 37 insertions(+), 22 deletions(-)
hw/riscv/microchip_pfsoc.c +5 -1
index 139284a..e8b7f86 100644
@@ -60,6 +60,9 @@
 #define BIOS_FILENAME   "hss.bin"
 #define RESET_VECTOR    0x20220000
 
+/* CLINT timebase frequency */
+#define CLINT_TIMEBASE_FREQ 1000000
+
 /* GEM version */
 #define GEM_REVISION    0x0107010c
 
@@ -189,7 +192,8 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
     /* CLINT */
     sifive_clint_create(memmap[MICROCHIP_PFSOC_CLINT].base,
         memmap[MICROCHIP_PFSOC_CLINT].size, ms->smp.cpus,
-        SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, false);
+        SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE,
+        CLINT_TIMEBASE_FREQ, false);
 
     /* L2 cache controller */
     create_unimplemented_device("microchip.pfsoc.l2cc",
hw/riscv/sifive_clint.c +14 -11
index 669c21a..a568568 100644
@@ -29,22 +29,23 @@
 #include "hw/riscv/sifive_clint.h"
 #include "qemu/timer.h"
 
-static uint64_t cpu_riscv_read_rtc(void)
+static uint64_t cpu_riscv_read_rtc(uint32_t timebase_freq)
 {
     return muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL),
-        SIFIVE_CLINT_TIMEBASE_FREQ, NANOSECONDS_PER_SECOND);
+        timebase_freq, NANOSECONDS_PER_SECOND);
 }
 
 /*
  * Called when timecmp is written to update the QEMU timer or immediately
  * trigger timer interrupt if mtimecmp <= current timer value.
  */
-static void sifive_clint_write_timecmp(RISCVCPU *cpu, uint64_t value)
+static void sifive_clint_write_timecmp(RISCVCPU *cpu, uint64_t value,
+                                       uint32_t timebase_freq)
 {
     uint64_t next;
     uint64_t diff;
 
-    uint64_t rtc_r = cpu_riscv_read_rtc();
+    uint64_t rtc_r = cpu_riscv_read_rtc(timebase_freq);
 
     cpu->env.timecmp = value;
     if (cpu->env.timecmp <= rtc_r) {
@@ -59,7 +60,7 @@ static void sifive_clint_write_timecmp(RISCVCPU *cpu, uint64_t value)
     diff = cpu->env.timecmp - rtc_r;
     /* back to ns (note args switched in muldiv64) */
     next = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
-        muldiv64(diff, NANOSECONDS_PER_SECOND, SIFIVE_CLINT_TIMEBASE_FREQ);
+        muldiv64(diff, NANOSECONDS_PER_SECOND, timebase_freq);
     timer_mod(cpu->env.timer, next);
 }
 
@@ -111,10 +112,10 @@ static uint64_t sifive_clint_read(void *opaque, hwaddr addr, unsigned size)
         }
     } else if (addr == clint->time_base) {
         /* time_lo */
-        return cpu_riscv_read_rtc() & 0xFFFFFFFF;
+        return cpu_riscv_read_rtc(clint->timebase_freq) & 0xFFFFFFFF;
     } else if (addr == clint->time_base + 4) {
         /* time_hi */
-        return (cpu_riscv_read_rtc() >> 32) & 0xFFFFFFFF;
+        return (cpu_riscv_read_rtc(clint->timebase_freq) >> 32) & 0xFFFFFFFF;
     }
 
     error_report("clint: invalid read: %08x", (uint32_t)addr);
@@ -151,13 +152,13 @@ static void sifive_clint_write(void *opaque, hwaddr addr, uint64_t value,
             /* timecmp_lo */
             uint64_t timecmp_hi = env->timecmp >> 32;
             sifive_clint_write_timecmp(RISCV_CPU(cpu),
-                timecmp_hi << 32 | (value & 0xFFFFFFFF));
+                timecmp_hi << 32 | (value & 0xFFFFFFFF), clint->timebase_freq);
             return;
         } else if ((addr & 0x7) == 4) {
             /* timecmp_hi */
             uint64_t timecmp_lo = env->timecmp;
             sifive_clint_write_timecmp(RISCV_CPU(cpu),
-                value << 32 | (timecmp_lo & 0xFFFFFFFF));
+                value << 32 | (timecmp_lo & 0xFFFFFFFF), clint->timebase_freq);
         } else {
             error_report("clint: invalid timecmp write: %08x", (uint32_t)addr);
         }
@@ -191,6 +192,7 @@ static Property sifive_clint_properties[] = {
     DEFINE_PROP_UINT32("timecmp-base", SiFiveCLINTState, timecmp_base, 0),
     DEFINE_PROP_UINT32("time-base", SiFiveCLINTState, time_base, 0),
     DEFINE_PROP_UINT32("aperture-size", SiFiveCLINTState, aperture_size, 0),
+    DEFINE_PROP_UINT32("timebase-freq", SiFiveCLINTState, timebase_freq, 0),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -229,7 +231,7 @@ type_init(sifive_clint_register_types)
  */
 DeviceState *sifive_clint_create(hwaddr addr, hwaddr size, uint32_t num_harts,
     uint32_t sip_base, uint32_t timecmp_base, uint32_t time_base,
-    bool provide_rdtime)
+    uint32_t timebase_freq, bool provide_rdtime)
 {
     int i;
     for (i = 0; i < num_harts; i++) {
@@ -239,7 +241,7 @@ DeviceState *sifive_clint_create(hwaddr addr, hwaddr size, uint32_t num_harts,
             continue;
         }
         if (provide_rdtime) {
-            riscv_cpu_set_rdtime_fn(env, cpu_riscv_read_rtc);
+            riscv_cpu_set_rdtime_fn(env, cpu_riscv_read_rtc, timebase_freq);
         }
         env->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
                                   &sifive_clint_timer_cb, cpu);
@@ -252,6 +254,7 @@ DeviceState *sifive_clint_create(hwaddr addr, hwaddr size, uint32_t num_harts,
     qdev_prop_set_uint32(dev, "timecmp-base", timecmp_base);
     qdev_prop_set_uint32(dev, "time-base", time_base);
     qdev_prop_set_uint32(dev, "aperture-size", size);
+    qdev_prop_set_uint32(dev, "timebase-freq", timebase_freq);
     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr);
     return dev;
hw/riscv/sifive_e.c +2 -1
index c84d407..e7f6460 100644
@@ -213,7 +213,8 @@ static void sifive_e_soc_realize(DeviceState *dev, Error **errp)
         memmap[SIFIVE_E_PLIC].size);
     sifive_clint_create(memmap[SIFIVE_E_CLINT].base,
         memmap[SIFIVE_E_CLINT].size, ms->smp.cpus,
-        SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, false);
+        SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE,
+        SIFIVE_CLINT_TIMEBASE_FREQ, false);
     create_unimplemented_device("riscv.sifive.e.aon",
         memmap[SIFIVE_E_AON].base, memmap[SIFIVE_E_AON].size);
     sifive_e_prci_create(memmap[SIFIVE_E_PRCI].base);
hw/riscv/sifive_u.c +2 -1
index e256da2..5ec9fca 100644
@@ -706,7 +706,8 @@ static void sifive_u_soc_realize(DeviceState *dev, Error **errp)
         serial_hd(1), qdev_get_gpio_in(DEVICE(s->plic), SIFIVE_U_UART1_IRQ));
     sifive_clint_create(memmap[SIFIVE_U_CLINT].base,
         memmap[SIFIVE_U_CLINT].size, ms->smp.cpus,
-        SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, false);
+        SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE,
+        SIFIVE_CLINT_TIMEBASE_FREQ, false);
 
     if (!sysbus_realize(SYS_BUS_DEVICE(&s->prci), errp)) {
         return;
hw/riscv/spike.c +1 -1
index 13958bd..ae8593a 100644
@@ -235,7 +235,7 @@ static void spike_board_init(MachineState *machine)
     /* Core Local Interruptor (timer and IPI) */
     sifive_clint_create(memmap[SPIKE_CLINT].base, memmap[SPIKE_CLINT].size,
         smp_cpus, SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE,
-        false);
+        SIFIVE_CLINT_TIMEBASE_FREQ, false);
 }
 
 static void spike_machine_init(MachineClass *mc)
hw/riscv/virt.c +2 -1
index 6e91cf1..af0d06a 100644
@@ -572,7 +572,8 @@ static void virt_machine_init(MachineState *machine)
         memmap[VIRT_PLIC].size);
     sifive_clint_create(memmap[VIRT_CLINT].base,
         memmap[VIRT_CLINT].size, smp_cpus,
-        SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, true);
+        SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE,
+        SIFIVE_CLINT_TIMEBASE_FREQ, true);
     sifive_test_create(memmap[VIRT_TEST].base);
 
     for (i = 0; i < VIRTIO_COUNT; i++) {
include/hw/riscv/sifive_clint.h +2 -1
index 4a720bf..eb8577a 100644
@@ -38,11 +38,12 @@ typedef struct SiFiveCLINTState {
     uint32_t timecmp_base;
     uint32_t time_base;
     uint32_t aperture_size;
+    uint32_t timebase_freq;
 } SiFiveCLINTState;
 
 DeviceState *sifive_clint_create(hwaddr addr, hwaddr size, uint32_t num_harts,
     uint32_t sip_base, uint32_t timecmp_base, uint32_t time_base,
-    bool provide_rdtime);
+    uint32_t timebase_freq, bool provide_rdtime);
 
 enum {
     SIFIVE_SIP_BASE     = 0x0,
target/riscv/cpu.h +4 -2
index d34bcfa..02486c3 100644
@@ -219,7 +219,8 @@ struct CPURISCVState {
     pmp_table_t pmp_state;
 
     /* machine specific rdtime callback */
-    uint64_t (*rdtime_fn)(void);
+    uint64_t (*rdtime_fn)(uint32_t);
+    uint32_t rdtime_fn_arg;
 
     /* True if in debugger mode.  */
     bool debugger;
@@ -347,7 +348,8 @@ void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env);
 int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint32_t interrupts);
 uint32_t riscv_cpu_update_mip(RISCVCPU *cpu, uint32_t mask, uint32_t value);
 #define BOOL_TO_MASK(x) (-!!(x)) /* helper for riscv_cpu_update_mip value */
-void riscv_cpu_set_rdtime_fn(CPURISCVState *env, uint64_t (*fn)(void));
+void riscv_cpu_set_rdtime_fn(CPURISCVState *env, uint64_t (*fn)(uint32_t),
+                             uint32_t arg);
 #endif
 void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv);
 
target/riscv/cpu_helper.c +3 -1
index fd1d373..c82a521 100644
@@ -258,9 +258,11 @@ uint32_t riscv_cpu_update_mip(RISCVCPU *cpu, uint32_t mask, uint32_t value)
     return old;
 }
 
-void riscv_cpu_set_rdtime_fn(CPURISCVState *env, uint64_t (*fn)(void))
+void riscv_cpu_set_rdtime_fn(CPURISCVState *env, uint64_t (*fn)(uint32_t),
+                             uint32_t arg)
 {
     env->rdtime_fn = fn;
+    env->rdtime_fn_arg = arg;
 }
 
 void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv)
target/riscv/csr.c +2 -2
index 6a96a01..6cef1ac 100644
@@ -294,7 +294,7 @@ static int read_time(CPURISCVState *env, int csrno, target_ulong *val)
         return -1;
     }
 
-    *val = env->rdtime_fn() + delta;
+    *val = env->rdtime_fn(env->rdtime_fn_arg) + delta;
     return 0;
 }
 
@@ -307,7 +307,7 @@ static int read_timeh(CPURISCVState *env, int csrno, target_ulong *val)
         return -1;
     }
 
-    *val = (env->rdtime_fn() + delta) >> 32;
+    *val = (env->rdtime_fn(env->rdtime_fn_arg) + delta) >> 32;
     return 0;
 }
 #endif
Signature · 1 line
2.7.4
Reviewed-by on v1 17/18
#47 lore raw

Re: [PATCH 17/18] hw/riscv: clint: Avoid using hard-coded timebase frequency

Quoted 11 lines · Bin Meng

From: Bin Meng <[email protected]>

At present the CLINT timestamp is using a hard-coded timebase frequency value SIFIVE_CLINT_TIMEBASE_FREQ. This might not be true for all boards.

Add a new 'timebase-freq' property to the CLINT device, and update various functions to accept this as a parameter.

Alistair

Quoted 282 lines

---

 hw/riscv/microchip_pfsoc.c      |  6 +++++-
 hw/riscv/sifive_clint.c         | 25 ++++++++++++++-----------
 hw/riscv/sifive_e.c             |  3 ++-
 hw/riscv/sifive_u.c             |  3 ++-
 hw/riscv/spike.c                |  2 +-
 hw/riscv/virt.c                 |  3 ++-
 include/hw/riscv/sifive_clint.h |  3 ++-
 target/riscv/cpu.h              |  6 ++++--
 target/riscv/cpu_helper.c       |  4 +++-
 target/riscv/csr.c              |  4 ++--
 10 files changed, 37 insertions(+), 22 deletions(-)
hw/riscv/microchip_pfsoc.c +5 -1
index 139284a..e8b7f86 100644
@@ -60,6 +60,9 @@
 #define BIOS_FILENAME   "hss.bin"
 #define RESET_VECTOR    0x20220000
 
+/* CLINT timebase frequency */
+#define CLINT_TIMEBASE_FREQ 1000000
+
 /* GEM version */
 #define GEM_REVISION    0x0107010c
 
@@ -189,7 +192,8 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
     /* CLINT */
     sifive_clint_create(memmap[MICROCHIP_PFSOC_CLINT].base,
         memmap[MICROCHIP_PFSOC_CLINT].size, ms->smp.cpus,
-        SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, false);
+        SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE,
+        CLINT_TIMEBASE_FREQ, false);
 
     /* L2 cache controller */
     create_unimplemented_device("microchip.pfsoc.l2cc",
hw/riscv/sifive_clint.c +14 -11
index 669c21a..a568568 100644
@@ -29,22 +29,23 @@
 #include "hw/riscv/sifive_clint.h"
 #include "qemu/timer.h"
 
-static uint64_t cpu_riscv_read_rtc(void)
+static uint64_t cpu_riscv_read_rtc(uint32_t timebase_freq)
 {
     return muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL),
-        SIFIVE_CLINT_TIMEBASE_FREQ, NANOSECONDS_PER_SECOND);
+        timebase_freq, NANOSECONDS_PER_SECOND);
 }
 
 /*
  * Called when timecmp is written to update the QEMU timer or immediately
  * trigger timer interrupt if mtimecmp <= current timer value.
  */
-static void sifive_clint_write_timecmp(RISCVCPU *cpu, uint64_t value)
+static void sifive_clint_write_timecmp(RISCVCPU *cpu, uint64_t value,
+                                       uint32_t timebase_freq)
 {
     uint64_t next;
     uint64_t diff;
 
-    uint64_t rtc_r = cpu_riscv_read_rtc();
+    uint64_t rtc_r = cpu_riscv_read_rtc(timebase_freq);
 
     cpu->env.timecmp = value;
     if (cpu->env.timecmp <= rtc_r) {
@@ -59,7 +60,7 @@ static void sifive_clint_write_timecmp(RISCVCPU *cpu, uint64_t value)
     diff = cpu->env.timecmp - rtc_r;
     /* back to ns (note args switched in muldiv64) */
     next = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
-        muldiv64(diff, NANOSECONDS_PER_SECOND, SIFIVE_CLINT_TIMEBASE_FREQ);
+        muldiv64(diff, NANOSECONDS_PER_SECOND, timebase_freq);
     timer_mod(cpu->env.timer, next);
 }
 
@@ -111,10 +112,10 @@ static uint64_t sifive_clint_read(void *opaque, hwaddr addr, unsigned size)
         }
     } else if (addr == clint->time_base) {
         /* time_lo */
-        return cpu_riscv_read_rtc() & 0xFFFFFFFF;
+        return cpu_riscv_read_rtc(clint->timebase_freq) & 0xFFFFFFFF;
     } else if (addr == clint->time_base + 4) {
         /* time_hi */
-        return (cpu_riscv_read_rtc() >> 32) & 0xFFFFFFFF;
+        return (cpu_riscv_read_rtc(clint->timebase_freq) >> 32) & 0xFFFFFFFF;
     }
 
     error_report("clint: invalid read: %08x", (uint32_t)addr);
@@ -151,13 +152,13 @@ static void sifive_clint_write(void *opaque, hwaddr addr, uint64_t value,
             /* timecmp_lo */
             uint64_t timecmp_hi = env->timecmp >> 32;
             sifive_clint_write_timecmp(RISCV_CPU(cpu),
-                timecmp_hi << 32 | (value & 0xFFFFFFFF));
+                timecmp_hi << 32 | (value & 0xFFFFFFFF), clint->timebase_freq);
             return;
         } else if ((addr & 0x7) == 4) {
             /* timecmp_hi */
             uint64_t timecmp_lo = env->timecmp;
             sifive_clint_write_timecmp(RISCV_CPU(cpu),
-                value << 32 | (timecmp_lo & 0xFFFFFFFF));
+                value << 32 | (timecmp_lo & 0xFFFFFFFF), clint->timebase_freq);
         } else {
             error_report("clint: invalid timecmp write: %08x", (uint32_t)addr);
         }
@@ -191,6 +192,7 @@ static Property sifive_clint_properties[] = {
     DEFINE_PROP_UINT32("timecmp-base", SiFiveCLINTState, timecmp_base, 0),
     DEFINE_PROP_UINT32("time-base", SiFiveCLINTState, time_base, 0),
     DEFINE_PROP_UINT32("aperture-size", SiFiveCLINTState, aperture_size, 0),
+    DEFINE_PROP_UINT32("timebase-freq", SiFiveCLINTState, timebase_freq, 0),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -229,7 +231,7 @@ type_init(sifive_clint_register_types)
  */
 DeviceState *sifive_clint_create(hwaddr addr, hwaddr size, uint32_t num_harts,
     uint32_t sip_base, uint32_t timecmp_base, uint32_t time_base,
-    bool provide_rdtime)
+    uint32_t timebase_freq, bool provide_rdtime)
 {
     int i;
     for (i = 0; i < num_harts; i++) {
@@ -239,7 +241,7 @@ DeviceState *sifive_clint_create(hwaddr addr, hwaddr size, uint32_t num_harts,
             continue;
         }
         if (provide_rdtime) {
-            riscv_cpu_set_rdtime_fn(env, cpu_riscv_read_rtc);
+            riscv_cpu_set_rdtime_fn(env, cpu_riscv_read_rtc, timebase_freq);
         }
         env->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
                                   &sifive_clint_timer_cb, cpu);
@@ -252,6 +254,7 @@ DeviceState *sifive_clint_create(hwaddr addr, hwaddr size, uint32_t num_harts,
     qdev_prop_set_uint32(dev, "timecmp-base", timecmp_base);
     qdev_prop_set_uint32(dev, "time-base", time_base);
     qdev_prop_set_uint32(dev, "aperture-size", size);
+    qdev_prop_set_uint32(dev, "timebase-freq", timebase_freq);
     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr);
     return dev;
hw/riscv/sifive_e.c +2 -1
index c84d407..e7f6460 100644
@@ -213,7 +213,8 @@ static void sifive_e_soc_realize(DeviceState *dev, Error **errp)
         memmap[SIFIVE_E_PLIC].size);
     sifive_clint_create(memmap[SIFIVE_E_CLINT].base,
         memmap[SIFIVE_E_CLINT].size, ms->smp.cpus,
-        SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, false);
+        SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE,
+        SIFIVE_CLINT_TIMEBASE_FREQ, false);
     create_unimplemented_device("riscv.sifive.e.aon",
         memmap[SIFIVE_E_AON].base, memmap[SIFIVE_E_AON].size);
     sifive_e_prci_create(memmap[SIFIVE_E_PRCI].base);
hw/riscv/sifive_u.c +2 -1
index e256da2..5ec9fca 100644
@@ -706,7 +706,8 @@ static void sifive_u_soc_realize(DeviceState *dev, Error **errp)
         serial_hd(1), qdev_get_gpio_in(DEVICE(s->plic), SIFIVE_U_UART1_IRQ));
     sifive_clint_create(memmap[SIFIVE_U_CLINT].base,
         memmap[SIFIVE_U_CLINT].size, ms->smp.cpus,
-        SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, false);
+        SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE,
+        SIFIVE_CLINT_TIMEBASE_FREQ, false);
 
     if (!sysbus_realize(SYS_BUS_DEVICE(&s->prci), errp)) {
         return;
hw/riscv/spike.c +1 -1
index 13958bd..ae8593a 100644
@@ -235,7 +235,7 @@ static void spike_board_init(MachineState *machine)
     /* Core Local Interruptor (timer and IPI) */
     sifive_clint_create(memmap[SPIKE_CLINT].base, memmap[SPIKE_CLINT].size,
         smp_cpus, SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE,
-        false);
+        SIFIVE_CLINT_TIMEBASE_FREQ, false);
 }
 
 static void spike_machine_init(MachineClass *mc)
hw/riscv/virt.c +2 -1
index 6e91cf1..af0d06a 100644
@@ -572,7 +572,8 @@ static void virt_machine_init(MachineState *machine)
         memmap[VIRT_PLIC].size);
     sifive_clint_create(memmap[VIRT_CLINT].base,
         memmap[VIRT_CLINT].size, smp_cpus,
-        SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, true);
+        SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE,
+        SIFIVE_CLINT_TIMEBASE_FREQ, true);
     sifive_test_create(memmap[VIRT_TEST].base);
 
     for (i = 0; i < VIRTIO_COUNT; i++) {
include/hw/riscv/sifive_clint.h +2 -1
index 4a720bf..eb8577a 100644
@@ -38,11 +38,12 @@ typedef struct SiFiveCLINTState {
     uint32_t timecmp_base;
     uint32_t time_base;
     uint32_t aperture_size;
+    uint32_t timebase_freq;
 } SiFiveCLINTState;
 
 DeviceState *sifive_clint_create(hwaddr addr, hwaddr size, uint32_t num_harts,
     uint32_t sip_base, uint32_t timecmp_base, uint32_t time_base,
-    bool provide_rdtime);
+    uint32_t timebase_freq, bool provide_rdtime);
 
 enum {
     SIFIVE_SIP_BASE     = 0x0,
target/riscv/cpu.h +4 -2
index d34bcfa..02486c3 100644
@@ -219,7 +219,8 @@ struct CPURISCVState {
     pmp_table_t pmp_state;
 
     /* machine specific rdtime callback */
-    uint64_t (*rdtime_fn)(void);
+    uint64_t (*rdtime_fn)(uint32_t);
+    uint32_t rdtime_fn_arg;
 
     /* True if in debugger mode.  */
     bool debugger;
@@ -347,7 +348,8 @@ void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env);
 int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint32_t interrupts);
 uint32_t riscv_cpu_update_mip(RISCVCPU *cpu, uint32_t mask, uint32_t value);
 #define BOOL_TO_MASK(x) (-!!(x)) /* helper for riscv_cpu_update_mip value */
-void riscv_cpu_set_rdtime_fn(CPURISCVState *env, uint64_t (*fn)(void));
+void riscv_cpu_set_rdtime_fn(CPURISCVState *env, uint64_t (*fn)(uint32_t),
+                             uint32_t arg);
 #endif
 void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv);
 
target/riscv/cpu_helper.c +3 -1
index fd1d373..c82a521 100644
@@ -258,9 +258,11 @@ uint32_t riscv_cpu_update_mip(RISCVCPU *cpu, uint32_t mask, uint32_t value)
     return old;
 }
 
-void riscv_cpu_set_rdtime_fn(CPURISCVState *env, uint64_t (*fn)(void))
+void riscv_cpu_set_rdtime_fn(CPURISCVState *env, uint64_t (*fn)(uint32_t),
+                             uint32_t arg)
 {
     env->rdtime_fn = fn;
+    env->rdtime_fn_arg = arg;
 }
 
 void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv)
target/riscv/csr.c +2 -3
index 6a96a01..6cef1ac 100644
@@ -294,7 +294,7 @@ static int read_time(CPURISCVState *env, int csrno, target_ulong *val)
         return -1;
     }
 
-    *val = env->rdtime_fn() + delta;
+    *val = env->rdtime_fn(env->rdtime_fn_arg) + delta;
     return 0;
 }
 
@@ -307,7 +307,7 @@ static int read_timeh(CPURISCVState *env, int csrno, target_ulong *val)
         return -1;
     }
 
-    *val = (env->rdtime_fn() + delta) >> 32;
+    *val = (env->rdtime_fn(env->rdtime_fn_arg) + delta) >> 32;
     return 0;
 }
 #endif
--

2.7.4

author
#48 lore raw

PATCH 18/18 hw/riscv: microchip_pfsoc: Document the software used for testing

In reply to Bin Meng

From: Bin Meng <[email protected]>

Add some useful comments to document the software used for testing. including how to patch HSS to bypass the DDR memory initialization, HSS and Yocto BSP build instructions, etc.

To launch this machine for testing:

$ qemu-system-riscv64 -M microchip-icicle-kit -smp 5 \
    -bios path/to/hss.bin -sd path/to/sdcard.img \
    -nic user,model=cadence_gem \
    -nic tap,ifname=tap,model=cadence_gem \
    -display none -serial stdio \
    -chardev socket,id=serial1,path=serial1.sock,server,wait \
    -serial chardev:serial1

---

 hw/riscv/microchip_pfsoc.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
hw/riscv/microchip_pfsoc.c +21 -0
index e8b7f86..1575fef 100644
@@ -56,6 +56,27 @@
 /*
  * The BIOS image used by this machine is called Hart Software Services (HSS).
  * See https://github.com/polarfire-soc/hart-software-services
+ *
+ * As of now the DDR memory controller in the Microchip PolarFire SoC has not
+ * been modeled. Simply creating unimplemented devices does not make HSS happy.
+ * Emulating the DDR memory controller is tedious, so a patched HSS should be
+ * used as the BIOS for this machine.
+ *
+ * To patch HSS, open boards/icicle-kit-es/hss_board_init.c in the HSS source
+ * tree, find the boardInitFunctions[] array that contains the initialization
+ * routines for this board, and remove the line that contains 'HSS_DDRInit'.
+ *
+ * QEMU does not support eMMC hence the SD configuration shall be used in the
+ * HSS and Yocto BSP build. The eMMC configuration is not supported.
+ *
+ * Instructions to build HSS:
+ *   $ cp boards/icicle-kit-es/def_config.sdcard .config
+ *   $ make BOARD=icicle-kit-es
+ *
+ * For Yocto build, "MACHINE=icicle-kit-es-sd" should be specified, otherwise
+ * when booting Linux kernel the rootfs cannot be mounted. The generated image
+ * is something like: mpfs-dev-cli-icicle-kit-es-sd.rootfs.wic. Resize the file
+ * with 'qemu-image' to a power of 2 before passing to QEMU '-sd' command line.
  */
 #define BIOS_FILENAME   "hss.bin"
 #define RESET_VECTOR    0x20220000
Signature · 1 line
2.7.4
#49 lore raw

Re: [PATCH 18/18] hw/riscv: microchip_pfsoc: Document the software used for testing

Quoted 42 lines · Bin Meng

From: Bin Meng <[email protected]>

Add some useful comments to document the software used for testing. including how to patch HSS to bypass the DDR memory initialization, HSS and Yocto BSP build instructions, etc.

To launch this machine for testing:

$ qemu-system-riscv64 -M microchip-icicle-kit -smp 5 \
    -bios path/to/hss.bin -sd path/to/sdcard.img \
    -nic user,model=cadence_gem \
    -nic tap,ifname=tap,model=cadence_gem \
    -display none -serial stdio \
    -chardev socket,id=serial1,path=serial1.sock,server,wait \
    -serial chardev:serial1

---

 hw/riscv/microchip_pfsoc.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
hw/riscv/microchip_pfsoc.c +11 -0
index e8b7f86..1575fef 100644
@@ -56,6 +56,27 @@
 /*
  * The BIOS image used by this machine is called Hart Software Services (HSS).
  * See https://github.com/polarfire-soc/hart-software-services
+ *
+ * As of now the DDR memory controller in the Microchip PolarFire SoC has not
+ * been modeled. Simply creating unimplemented devices does not make HSS happy.
+ * Emulating the DDR memory controller is tedious, so a patched HSS should be
+ * used as the BIOS for this machine.
+ *
+ * To patch HSS, open boards/icicle-kit-es/hss_board_init.c in the HSS source
+ * tree, find the boardInitFunctions[] array that contains the initialization
+ * routines for this board, and remove the line that contains 'HSS_DDRInit'.
+ *
+ * QEMU does not support eMMC hence the SD configuration shall be used in the

hw/riscv/microchip_pfsoc.c line 79

Quoted 10 lines
hw/riscv/microchip_pfsoc.c +10 -0
+ * HSS and Yocto BSP build. The eMMC configuration is not supported.
+ *
+ * Instructions to build HSS:
+ *   $ cp boards/icicle-kit-es/def_config.sdcard .config
+ *   $ make BOARD=icicle-kit-es
+ *
+ * For Yocto build, "MACHINE=icicle-kit-es-sd" should be specified, otherwise
+ * when booting Linux kernel the rootfs cannot be mounted. The generated image
+ * is something like: mpfs-dev-cli-icicle-kit-es-sd.rootfs.wic. Resize the file
+ * with 'qemu-image' to a power of 2 before passing to QEMU '-sd' command line.

Instead of adding comments in the code (where it's hard for users to find and prone to getting out of date) can you drop this patch and instead update the RISC-V QEMU wiki?

https://wiki.qemu.org/Documentation/Platforms/RISCV

Just add an Icicle section.

Alistair

Quoted 7 lines
hw/riscv/microchip_pfsoc.c +0 -1
  */
 #define BIOS_FILENAME   "hss.bin"
 #define RESET_VECTOR    0x20220000
--

2.7.4

#50 lore raw
In reply to Bin Meng
Quoted 6 lines · Bin Meng

From: Bin Meng <[email protected]>

This adds support for Microchip PolarFire SoC Icicle Kit board. The Icicle Kit board integrates a PolarFire SoC, with one SiFive's E51 plus four U54 cores and many on-chip peripherals and an FPGA.

Nice Work !!! This is very helpful.

Quoted 34 lines

For more details about Microchip PolarFire Soc, please see:
https://www.microsemi.com/product-directory/soc-fpgas/5498-polarfire-soc-fpga

The Icicle Kit board information can be found here:
https://www.microsemi.com/existing-parts/parts/152514

Unlike SiFive FU540, the RISC-V core resect vector is at 0x20220000. The RISC-V CPU and HART codes has been updated to set the core's reset vector based on a configurable property from machine codes.

The following perepherals are created as an unimplemented device:

- Bus Error Uint 0/1/2/3/4
- L2 cache controller
- SYSREG
- MPUCFG
- IOSCBCFG
- GPIO

The following perepherals are emulated:
- SiFive CLINT
- SiFive PLIC
- PolarFire SoC Multi-Mode UART
- PolarFire SoC DMA
- Cadence eMMC/SDHCI controller
- Cadence Gigabit Ethernet MAC

Some bugs in the SD card codes are fixed during the development.

The BIOS image used by this machine is hss.bin, aka Hart Software Services, which can be built from:
https://github.com/polarfire-soc/hart-software-services

Quoted 7 lines

To launch this machine:

$ qemu-system-riscv64 -M microchip-icicle-kit -smp 5 \
    -bios path/to/hss.bin -sd path/to/sdcard.img \
    -nic tap,ifname=tap,script=no,model=cadence_gem \
    -display none -serial stdio \
    -chardev socket,id=serial1,path=serial1.sock,server,wait \
    -serial chardev:serial1

Currently, it is fine to use HSS (with OpenSBI v0.6 as a library) but this is not aligned with the existing booting flow of many RISC-V systems.

It will be nice to have standard U-Boot RISC-V boot-flow working on Microchip PolarFire SoC:
U-Boot SPL (BIOS) => FW_DYNAMIC (Generic) => U-Boot S-mode

The Microchip HSS is quite convoluted. It has:
1. DDR Init
2. Boot device support
3. SBI support using OpenSBI as library
4. Simple TEE support

I think point 1) and 2) above should be part of U-Boot SPL. The point 3) can be OpenSBI FW_DYNAMIC.

Lastly,for point 4), we are working on a new OpenSBI feature using which we can run independent Secure OS and Non-Secure OS using U-Boot_SPL+OpenSBI (for both SiFive Unleashed and Microchip PolarFire).

Do you have plans for adding U-Boot SPL support for this board ??

Regards,
Anup

Quoted 84 lines

The memory is set to 1 GiB by default to match the hardware. A sanity check on ram size is performed in the machine init routine to prompt user to increase the RAM size to > 1 GiB when less than 1 GiB ram is detected.

HSS output is on the first serial port (stdio) and U-Boot/Linux outputs on the 2nd serial port. OpenSBI outputs on a random serial port due to the lottery mechanism used during the multi-core boot.

Bin Meng (18):
target/riscv: cpu: Add a new 'resetvec' property
hw/riscv: hart: Add a new 'resetvec' property target/riscv: cpu: Set reset vector based on the configured property
value
hw/riscv: Initial support for Microchip PolarFire SoC Icicle Kit board hw/char: Add Microchip PolarFire SoC MMUART emulation hw/riscv: microchip_pfsoc: Connect 5 MMUARTs
hw/sd: sd: Fix incorrect populated function switch status data
structure
hw/sd: sd: Correctly set the high capacity bit
hw/sd: sdhci: Make sdhci_poweron_reset() internal visible hw/sd: Add Cadence SDHCI emulation
hw/riscv: microchip_pfsoc: Connect a Cadence SDHCI controller and an
SD card
hw/dma: Add Microchip PolarFire Soc DMA controller emulation hw/riscv: microchip_pfsoc: Connect a DMA controller hw/net: cadence_gem: Add a new 'phy-addr' property hw/riscv: microchip_pfsoc: Connect 2 Cadence GEMs hw/riscv: microchip_pfsoc: Hook GPIO controllers
hw/riscv: clint: Avoid using hard-coded timebase frequency hw/riscv: microchip_pfsoc: Document the software used for testing

 MAINTAINERS                         |  11 +
 default-configs/riscv64-softmmu.mak |   1 +
 hw/char/Kconfig                     |   3 +
 hw/char/Makefile.objs               |   1 +
 hw/char/mchp_pfsoc_mmuart.c         |  82 +++++++
 hw/dma/Kconfig                      |   3 +
 hw/dma/Makefile.objs                |   1 +
 hw/dma/mchp_pfsoc_dma.c             | 322 +++++++++++++++++++++++++
 hw/net/cadence_gem.c                |   7 +-
 hw/riscv/Kconfig                    |   9 +
 hw/riscv/Makefile.objs              |   1 +
 hw/riscv/microchip_pfsoc.c          | 456 ++++++++++++++++++++++++++++++++++++
 hw/riscv/opentitan.c                |   1 +
 hw/riscv/riscv_hart.c               |   3 +
 hw/riscv/sifive_clint.c             |  25 +-
 hw/riscv/sifive_e.c                 |   4 +-
 hw/riscv/sifive_u.c                 |   5 +-
 hw/riscv/spike.c                    |   2 +-
 hw/riscv/virt.c                     |   3 +-
 hw/sd/Kconfig                       |   4 +
 hw/sd/Makefile.objs                 |   1 +
 hw/sd/cadence_sdhci.c               | 162 +++++++++++++
 hw/sd/sd.c                          |   8 +-
 hw/sd/sdhci-internal.h              |   1 +
 hw/sd/sdhci.c                       |   2 +-
 include/hw/char/mchp_pfsoc_mmuart.h |  61 +++++
 include/hw/dma/mchp_pfsoc_dma.h     |  57 +++++
 include/hw/net/cadence_gem.h        |   2 +
 include/hw/riscv/microchip_pfsoc.h  | 125 ++++++++++
 include/hw/riscv/riscv_hart.h       |   1 +
 include/hw/riscv/sifive_clint.h     |   3 +-
 include/hw/sd/cadence_sdhci.h       |  65 +++++
 target/riscv/cpu.c                  |   8 +-
 target/riscv/cpu.h                  |   7 +-
 target/riscv/cpu_helper.c           |   4 +-
 target/riscv/csr.c                  |   4 +-
 36 files changed, 1424 insertions(+), 31 deletions(-)
 create mode 100644 hw/char/mchp_pfsoc_mmuart.c
 create mode 100644 hw/dma/mchp_pfsoc_dma.c
 create mode 100644 hw/riscv/microchip_pfsoc.c
 create mode 100644 hw/sd/cadence_sdhci.c
 create mode 100644 include/hw/char/mchp_pfsoc_mmuart.h
 create mode 100644 include/hw/dma/mchp_pfsoc_dma.h
 create mode 100644 include/hw/riscv/microchip_pfsoc.h
 create mode 100644 include/hw/sd/cadence_sdhci.h

--
2.7.4

author
#51 lore raw

Hi Anup,

Quoted 10 lines · Anup Patel
Quoted 6 lines · Bin Meng

From: Bin Meng <[email protected]>

This adds support for Microchip PolarFire SoC Icicle Kit board. The Icicle Kit board integrates a PolarFire SoC, with one SiFive's E51 plus four U54 cores and many on-chip peripherals and an FPGA.

Nice Work !!! This is very helpful.

Thanks!

Quoted 43 lines
Quoted 35 lines

For more details about Microchip PolarFire Soc, please see:
https://www.microsemi.com/product-directory/soc-fpgas/5498-polarfire-soc-fpga

The Icicle Kit board information can be found here:
https://www.microsemi.com/existing-parts/parts/152514

Unlike SiFive FU540, the RISC-V core resect vector is at 0x20220000. The RISC-V CPU and HART codes has been updated to set the core's reset vector based on a configurable property from machine codes.

The following perepherals are created as an unimplemented device:

- Bus Error Uint 0/1/2/3/4
- L2 cache controller
- SYSREG
- MPUCFG
- IOSCBCFG
- GPIO

The following perepherals are emulated:
- SiFive CLINT
- SiFive PLIC
- PolarFire SoC Multi-Mode UART
- PolarFire SoC DMA
- Cadence eMMC/SDHCI controller
- Cadence Gigabit Ethernet MAC

Some bugs in the SD card codes are fixed during the development.

The BIOS image used by this machine is hss.bin, aka Hart Software Services, which can be built from:
https://github.com/polarfire-soc/hart-software-services

Quoted 7 lines

To launch this machine:

$ qemu-system-riscv64 -M microchip-icicle-kit -smp 5 \
    -bios path/to/hss.bin -sd path/to/sdcard.img \
    -nic tap,ifname=tap,script=no,model=cadence_gem \
    -display none -serial stdio \
    -chardev socket,id=serial1,path=serial1.sock,server,wait \
    -serial chardev:serial1
Quoted 3 lines

Currently, it is fine to use HSS (with OpenSBI v0.6 as a library) but this is not aligned with the existing booting flow of many RISC-V systems.

Yep, unfortunately this is the case currently.

Quoted 5 lines

It will be nice to have standard U-Boot RISC-V boot-flow working on Microchip PolarFire SoC:
U-Boot SPL (BIOS) => FW_DYNAMIC (Generic) => U-Boot S-mode

Agreed.

Quoted 9 lines

The Microchip HSS is quite convoluted. It has:
1. DDR Init
2. Boot device support
3. SBI support using OpenSBI as library
4. Simple TEE support

I think point 1) and 2) above should be part of U-Boot SPL. The point 3) can be OpenSBI FW_DYNAMIC.

Quoted 6 lines

Lastly,for point 4), we are working on a new OpenSBI feature using which we can run independent Secure OS and Non-Secure OS using U-Boot_SPL+OpenSBI (for both SiFive Unleashed and Microchip PolarFire).

Do you have plans for adding U-Boot SPL support for this board ??

+ Cyril Jean from Microchip

I will have to leave this question to Cyril to comment.

Regards,
Bin

#52 lore raw

Hi Anup,

Quoted 28 lines · Bin Meng

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Hi Anup,

Quoted 7 lines · Anup Patel
Quoted 5 lines · Bin Meng

From: Bin Meng <[email protected]>

This adds support for Microchip PolarFire SoC Icicle Kit board. The Icicle Kit board integrates a PolarFire SoC, with one SiFive's E51 plus four U54 cores and many on-chip peripherals and an FPGA.

Nice Work !!! This is very helpful.

Thanks!

Quoted 14 lines

The Microchip HSS is quite convoluted. It has:
1. DDR Init
2. Boot device support
3. SBI support using OpenSBI as library
4. Simple TEE support

I think point 1) and 2) above should be part of U-Boot SPL. The point 3) can be OpenSBI FW_DYNAMIC.

Lastly,for point 4), we are working on a new OpenSBI feature using which we can run independent Secure OS and Non-Secure OS using U-Boot_SPL+OpenSBI (for both SiFive Unleashed and Microchip PolarFire).

Quoted 5 lines
Quoted 1 line

Do you have plans for adding U-Boot SPL support for this board ??

+ Cyril Jean from Microchip

I will have to leave this question to Cyril to comment.

I currently do not have a plan to support U-Boot SPL. The idea of the HSS is to contain all the silicon specific initialization and configuration code within the HSS before jumping to U-Boot S-mode. I would rather keep all this within the HSS for the time being. I would wait until we reach production silicon before attempting to move this to U-Boot SPL as the HSS is likely to contain some opaque silicon related changes for another while.

Regards,

Cyril.

#53 lore raw
Quoted 37 lines · via

Hi Anup,

Quoted 28 lines · Bin Meng

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Hi Anup,

Quoted 7 lines · Anup Patel
Quoted 5 lines · Bin Meng

From: Bin Meng <[email protected]>

This adds support for Microchip PolarFire SoC Icicle Kit board. The Icicle Kit board integrates a PolarFire SoC, with one SiFive's E51 plus four U54 cores and many on-chip peripherals and an FPGA.

Nice Work !!! This is very helpful.

Thanks!

Quoted 14 lines

The Microchip HSS is quite convoluted. It has:
1. DDR Init
2. Boot device support
3. SBI support using OpenSBI as library
4. Simple TEE support

I think point 1) and 2) above should be part of U-Boot SPL. The point 3) can be OpenSBI FW_DYNAMIC.

Lastly,for point 4), we are working on a new OpenSBI feature using which we can run independent Secure OS and Non-Secure OS using U-Boot_SPL+OpenSBI (for both SiFive Unleashed and Microchip PolarFire).

Quoted 5 lines
Quoted 1 line

Do you have plans for adding U-Boot SPL support for this board ??

+ Cyril Jean from Microchip

I will have to leave this question to Cyril to comment.

Quoted 7 lines

I currently do not have a plan to support U-Boot SPL. The idea of the HSS is to contain all the silicon specific initialization and configuration code within the HSS before jumping to U-Boot S-mode. I would rather keep all this within the HSS for the time being. I would wait until we reach production silicon before attempting to move this to U-Boot SPL as the HSS is likely to contain some opaque silicon related changes for another while.

That is unfortunate, a lot of work has gone into making the boot flow simple and easy to use.

QEMU now includes OpenSBI by default to make it easy for users to boot Linux. The Icicle Kit board is now the most difficult QEMU board to boot Linux on. Not to mention it makes it hard to impossible to support it in standard tool flows such as meta-riscv.

Alistair

Quoted 6 lines

Regards,

Cyril.

#54 lore raw
Quoted 49 lines · Alistair Francis

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 36 lines · via

Hi Anup,

Quoted 28 lines · Bin Meng

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Hi Anup,

Quoted 7 lines · Anup Patel
Quoted 5 lines · Bin Meng

From: Bin Meng <[email protected]>

This adds support for Microchip PolarFire SoC Icicle Kit board. The Icicle Kit board integrates a PolarFire SoC, with one SiFive's E51 plus four U54 cores and many on-chip peripherals and an FPGA.

Nice Work !!! This is very helpful.

Thanks!

Quoted 14 lines

The Microchip HSS is quite convoluted. It has:
1. DDR Init
2. Boot device support
3. SBI support using OpenSBI as library
4. Simple TEE support

I think point 1) and 2) above should be part of U-Boot SPL. The point 3) can be OpenSBI FW_DYNAMIC.

Lastly,for point 4), we are working on a new OpenSBI feature using which we can run independent Secure OS and Non-Secure OS using U-Boot_SPL+OpenSBI (for both SiFive Unleashed and Microchip PolarFire).

Quoted 5 lines
Quoted 1 line

Do you have plans for adding U-Boot SPL support for this board ??

+ Cyril Jean from Microchip

I will have to leave this question to Cyril to comment.

Quoted 7 lines

I currently do not have a plan to support U-Boot SPL. The idea of the HSS is to contain all the silicon specific initialization and configuration code within the HSS before jumping to U-Boot S-mode. I would rather keep all this within the HSS for the time being. I would wait until we reach production silicon before attempting to move this to U-Boot SPL as the HSS is likely to contain some opaque silicon related changes for another while.

That is unfortunate, a lot of work has gone into making the boot flow simple and easy to use.

Quoted 6 lines

QEMU now includes OpenSBI by default to make it easy for users to boot Linux. The Icicle Kit board is now the most difficult QEMU board to boot Linux on. Not to mention it makes it hard to impossible to support it in standard tool flows such as meta-riscv.

Alistair

If it is such a problem we can add a U-Boot SPL stage and the HSS can be treated as standard SoC ROM code.

Cyril.

#55 lore raw
Quoted 56 lines · On Tue, Aug 18, 2020 at 1:23 AM <[email protected]> wrote:
Quoted 54 lines · Alistair Francis

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 36 lines · via

Hi Anup,

Quoted 28 lines · Bin Meng

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Hi Anup,

Quoted 7 lines · Anup Patel
Quoted 5 lines · Bin Meng

From: Bin Meng <[email protected]>

This adds support for Microchip PolarFire SoC Icicle Kit board. The Icicle Kit board integrates a PolarFire SoC, with one SiFive's E51 plus four U54 cores and many on-chip peripherals and an FPGA.

Nice Work !!! This is very helpful.

Thanks!

Quoted 14 lines

The Microchip HSS is quite convoluted. It has:
1. DDR Init
2. Boot device support
3. SBI support using OpenSBI as library
4. Simple TEE support

I think point 1) and 2) above should be part of U-Boot SPL. The point 3) can be OpenSBI FW_DYNAMIC.

Lastly,for point 4), we are working on a new OpenSBI feature using which we can run independent Secure OS and Non-Secure OS using U-Boot_SPL+OpenSBI (for both SiFive Unleashed and Microchip PolarFire).

Quoted 5 lines
Quoted 1 line

Do you have plans for adding U-Boot SPL support for this board ??

+ Cyril Jean from Microchip

I will have to leave this question to Cyril to comment.

Quoted 7 lines

I currently do not have a plan to support U-Boot SPL. The idea of the HSS is to contain all the silicon specific initialization and configuration code within the HSS before jumping to U-Boot S-mode. I would rather keep all this within the HSS for the time being. I would wait until we reach production silicon before attempting to move this to U-Boot SPL as the HSS is likely to contain some opaque silicon related changes for another while.

That is unfortunate, a lot of work has gone into making the boot flow simple and easy to use.

QEMU now includes OpenSBI by default to make it easy for users to boot Linux. The Icicle Kit board is now the most difficult QEMU board to boot Linux on. Not to mention it makes it hard to impossible to support it in standard tool flows such as meta-riscv.

Quoted 4 lines
Quoted 1 line

Alistair

If it is such a problem we can add a U-Boot SPL stage and the HSS can be treated as standard SoC ROM code.

It's not mandatory for U-Boot SPL to have stable DRAM calibration settings from the start itself. The initial U-Boot SPL support for most platforms (accross
architectures) usually include basic working DRAM calibration settings which is later on updated with separate patches. Also, we don't need all U-Boot drivers to be upstreamed in one-go as this can be done in phases.

The advantage we have with PolarFire SoC Icicle board is that we already have a U-Boot S-mode. and we believe the OpenSBI generic platform will work fine for PolarFire SoC Icicle board so the only thing missing right now is the U-Boot SPL support for OpenSource boot-flow.

It will certainly accelerate open-source development if we have boot-flow U-Boot_SPL => OpenSBI (FW_DYNAMIC) => U-Boot_S-mode working on PolarFire SoC Icicle board. Initially, we just need DRAM, SD/eMMC, and Serial port support for U-Boot SPL and U-Boot S-mode. Later on, more patches can add ethernet and other booting device drivers to U-Boot.

Regarding security services of HSS, we are working on a OpenSBI feature which will allow HSS security services to run as independent binary in M-mode (not linked to OpenSBI) and OpenSBI FW_DYNAMIC will be a separate binary acting as a secure monitor.

Regards,
Anup

#56 lore raw
Quoted 79 lines · Anup Patel

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 50 lines · On Tue, Aug 18, 2020 at 1:23 AM <[email protected]> wrote:
Quoted 49 lines · Alistair Francis

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 36 lines · via

Hi Anup,

Quoted 28 lines · Bin Meng

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Hi Anup,

Quoted 7 lines · Anup Patel
Quoted 5 lines · Bin Meng

From: Bin Meng <[email protected]>

This adds support for Microchip PolarFire SoC Icicle Kit board. The Icicle Kit board integrates a PolarFire SoC, with one SiFive's E51 plus four U54 cores and many on-chip peripherals and an FPGA.

Nice Work !!! This is very helpful.

Thanks!

Quoted 14 lines

The Microchip HSS is quite convoluted. It has:
1. DDR Init
2. Boot device support
3. SBI support using OpenSBI as library
4. Simple TEE support

I think point 1) and 2) above should be part of U-Boot SPL. The point 3) can be OpenSBI FW_DYNAMIC.

Lastly,for point 4), we are working on a new OpenSBI feature using which we can run independent Secure OS and Non-Secure OS using U-Boot_SPL+OpenSBI (for both SiFive Unleashed and Microchip PolarFire).

Quoted 5 lines
Quoted 1 line

Do you have plans for adding U-Boot SPL support for this board ??

+ Cyril Jean from Microchip

I will have to leave this question to Cyril to comment.

Quoted 7 lines

I currently do not have a plan to support U-Boot SPL. The idea of the HSS is to contain all the silicon specific initialization and configuration code within the HSS before jumping to U-Boot S-mode. I would rather keep all this within the HSS for the time being. I would wait until we reach production silicon before attempting to move this to U-Boot SPL as the HSS is likely to contain some opaque silicon related changes for another while.

That is unfortunate, a lot of work has gone into making the boot flow simple and easy to use.

Quoted 8 lines
Quoted 6 lines

QEMU now includes OpenSBI by default to make it easy for users to boot Linux. The Icicle Kit board is now the most difficult QEMU board to boot Linux on. Not to mention it makes it hard to impossible to support it in standard tool flows such as meta-riscv.

Alistair

If it is such a problem we can add a U-Boot SPL stage and the HSS can be treated as standard SoC ROM code.

It's not mandatory for U-Boot SPL to have stable DRAM calibration settings from the start itself. The initial U-Boot SPL support for most platforms (accross
architectures) usually include basic working DRAM calibration settings which is later on updated with separate patches. Also, we don't need all U-Boot drivers to be upstreamed in one-go as this can be done in phases.

The advantage we have with PolarFire SoC Icicle board is that we already have a U-Boot S-mode. and we believe the OpenSBI generic platform will work fine for PolarFire SoC Icicle board so the only thing missing right now is the U-Boot SPL support for OpenSource boot-flow.

It will certainly accelerate open-source development if we have boot-flow U-Boot_SPL => OpenSBI (FW_DYNAMIC) => U-Boot_S-mode working on PolarFire SoC Icicle board. Initially, we just need DRAM, SD/eMMC, and Serial port support for U-Boot SPL and U-Boot S-mode. Later on, more patches can add ethernet and other booting device drivers to U-Boot.

Quoted 7 lines

Regarding security services of HSS, we are working on a OpenSBI feature which will allow HSS security services to run as independent binary in M-mode (not linked to OpenSBI) and OpenSBI FW_DYNAMIC will be a separate binary acting as a secure monitor.

Regards,
Anup

What I have in mind is that the external memory will be up and running by the time we get to U-Boot SPL. In the case of PolarFire SoC the ROM code equivalent brings up the DDR memory interface so we do not need to worry about this as part of U-Boot.

Sounds to me the component that needs to be upstreamed next is the eMMC support so that it can be used as part of U-Boot SPL. Correct?

Regards,

Cyril.

#57 lore raw
Quoted 86 lines · On Tue, Aug 18, 2020 at 6:39 PM <[email protected]> wrote:
Quoted 84 lines · Anup Patel

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 50 lines · On Tue, Aug 18, 2020 at 1:23 AM <[email protected]> wrote:
Quoted 49 lines · Alistair Francis

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 36 lines · via

Hi Anup,

Quoted 28 lines · Bin Meng

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Hi Anup,

Quoted 7 lines · Anup Patel
Quoted 5 lines · Bin Meng

From: Bin Meng <[email protected]>

This adds support for Microchip PolarFire SoC Icicle Kit board. The Icicle Kit board integrates a PolarFire SoC, with one SiFive's E51 plus four U54 cores and many on-chip peripherals and an FPGA.

Nice Work !!! This is very helpful.

Thanks!

Quoted 14 lines

The Microchip HSS is quite convoluted. It has:
1. DDR Init
2. Boot device support
3. SBI support using OpenSBI as library
4. Simple TEE support

I think point 1) and 2) above should be part of U-Boot SPL. The point 3) can be OpenSBI FW_DYNAMIC.

Lastly,for point 4), we are working on a new OpenSBI feature using which we can run independent Secure OS and Non-Secure OS using U-Boot_SPL+OpenSBI (for both SiFive Unleashed and Microchip PolarFire).

Quoted 5 lines
Quoted 1 line

Do you have plans for adding U-Boot SPL support for this board ??

+ Cyril Jean from Microchip

I will have to leave this question to Cyril to comment.

Quoted 7 lines

I currently do not have a plan to support U-Boot SPL. The idea of the HSS is to contain all the silicon specific initialization and configuration code within the HSS before jumping to U-Boot S-mode. I would rather keep all this within the HSS for the time being. I would wait until we reach production silicon before attempting to move this to U-Boot SPL as the HSS is likely to contain some opaque silicon related changes for another while.

That is unfortunate, a lot of work has gone into making the boot flow simple and easy to use.

Quoted 8 lines
Quoted 6 lines

QEMU now includes OpenSBI by default to make it easy for users to boot Linux. The Icicle Kit board is now the most difficult QEMU board to boot Linux on. Not to mention it makes it hard to impossible to support it in standard tool flows such as meta-riscv.

Alistair

If it is such a problem we can add a U-Boot SPL stage and the HSS can be treated as standard SoC ROM code.

It's not mandatory for U-Boot SPL to have stable DRAM calibration settings from the start itself. The initial U-Boot SPL support for most platforms (accross
architectures) usually include basic working DRAM calibration settings which is later on updated with separate patches. Also, we don't need all U-Boot drivers to be upstreamed in one-go as this can be done in phases.

The advantage we have with PolarFire SoC Icicle board is that we already have a U-Boot S-mode. and we believe the OpenSBI generic platform will work fine for PolarFire SoC Icicle board so the only thing missing right now is the U-Boot SPL support for OpenSource boot-flow.

It will certainly accelerate open-source development if we have boot-flow U-Boot_SPL => OpenSBI (FW_DYNAMIC) => U-Boot_S-mode working on PolarFire SoC Icicle board. Initially, we just need DRAM, SD/eMMC, and Serial port support for U-Boot SPL and U-Boot S-mode. Later on, more patches can add ethernet and other booting device drivers to U-Boot.

Regarding security services of HSS, we are working on a OpenSBI feature which will allow HSS security services to run as independent binary in M-mode (not linked to OpenSBI) and OpenSBI FW_DYNAMIC will be a separate binary acting as a secure monitor.

Quoted 7 lines
Quoted 2 lines

Regards,
Anup

What I have in mind is that the external memory will be up and running by the time we get to U-Boot SPL. In the case of PolarFire SoC the ROM code equivalent brings up the DDR memory interface so we do not need to worry about this as part of U-Boot.

Keeping DRAM configuration as part of a separate ROM booting stage prior to the U-Boot SPL sounds good to me. This will lead to following boot-flow:

ROM/HSS (M-mode) => U-Boot SPL (M-mode) => OpenSBI (M-mode) => U-Boot S-mode

Quoted 3 lines

Sounds to me the component that needs to be upstreamed next is the eMMC support so that it can be used as part of U-Boot SPL. Correct?

Maybe as a PHASE1 patch series for PolarFire U-Boot support can target the following:
1. Minimal U-Boot board support for PolarFire IcIcle Board with single defconfig to build both U-Boot SPL and U-Boot S-mode
2. Serial port driver (probably re-use existing driver)
3. SD and eMMC driver

Supporting SD booting is highly desirable for PHASE1. At least, U-Boot SPL, OpenSBI, U-Boot S-mode, and Linux should come as separate images from SD card. The ROM/HSS can reside and boot from on-board flash/eMMC.

Above is my suggestion based on experience with SiFive Unleashed.

The general idea behind OpenSource boot-flow is to have each booting stage as a separate binary so that users can selectively upgrade a particular booting stage without re-compiling/re-flashing other booting stages.

Various distros and yocto already support building most of the above booting stages (U-Boot, OpenSBI, Linux, etc) so we can reuse a lot of existing work. Eventually, I am confident we will endup moving more stuff from ROM/HSS to U-Boot SPL for ease in maintenance.

Regards,
Anup

author
#58 lore raw
Quoted 96 lines · Anup Patel
Quoted 86 lines · On Tue, Aug 18, 2020 at 6:39 PM <[email protected]> wrote:
Quoted 84 lines · Anup Patel

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 50 lines · On Tue, Aug 18, 2020 at 1:23 AM <[email protected]> wrote:
Quoted 49 lines · Alistair Francis

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 36 lines · via

Hi Anup,

Quoted 28 lines · Bin Meng

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Hi Anup,

Quoted 7 lines · Anup Patel
Quoted 5 lines · Bin Meng

From: Bin Meng <[email protected]>

This adds support for Microchip PolarFire SoC Icicle Kit board. The Icicle Kit board integrates a PolarFire SoC, with one SiFive's E51 plus four U54 cores and many on-chip peripherals and an FPGA.

Nice Work !!! This is very helpful.

Thanks!

Quoted 14 lines

The Microchip HSS is quite convoluted. It has:
1. DDR Init
2. Boot device support
3. SBI support using OpenSBI as library
4. Simple TEE support

I think point 1) and 2) above should be part of U-Boot SPL. The point 3) can be OpenSBI FW_DYNAMIC.

Lastly,for point 4), we are working on a new OpenSBI feature using which we can run independent Secure OS and Non-Secure OS using U-Boot_SPL+OpenSBI (for both SiFive Unleashed and Microchip PolarFire).

Quoted 5 lines
Quoted 1 line

Do you have plans for adding U-Boot SPL support for this board ??

+ Cyril Jean from Microchip

I will have to leave this question to Cyril to comment.

Quoted 7 lines

I currently do not have a plan to support U-Boot SPL. The idea of the HSS is to contain all the silicon specific initialization and configuration code within the HSS before jumping to U-Boot S-mode. I would rather keep all this within the HSS for the time being. I would wait until we reach production silicon before attempting to move this to U-Boot SPL as the HSS is likely to contain some opaque silicon related changes for another while.

That is unfortunate, a lot of work has gone into making the boot flow simple and easy to use.

Quoted 8 lines
Quoted 6 lines

QEMU now includes OpenSBI by default to make it easy for users to boot Linux. The Icicle Kit board is now the most difficult QEMU board to boot Linux on. Not to mention it makes it hard to impossible to support it in standard tool flows such as meta-riscv.

Alistair

If it is such a problem we can add a U-Boot SPL stage and the HSS can be treated as standard SoC ROM code.

It's not mandatory for U-Boot SPL to have stable DRAM calibration settings from the start itself. The initial U-Boot SPL support for most platforms (accross
architectures) usually include basic working DRAM calibration settings which is later on updated with separate patches. Also, we don't need all U-Boot drivers to be upstreamed in one-go as this can be done in phases.

The advantage we have with PolarFire SoC Icicle board is that we already have a U-Boot S-mode. and we believe the OpenSBI generic platform will work fine for PolarFire SoC Icicle board so the only thing missing right now is the U-Boot SPL support for OpenSource boot-flow.

It will certainly accelerate open-source development if we have boot-flow U-Boot_SPL => OpenSBI (FW_DYNAMIC) => U-Boot_S-mode working on PolarFire SoC Icicle board. Initially, we just need DRAM, SD/eMMC, and Serial port support for U-Boot SPL and U-Boot S-mode. Later on, more patches can add ethernet and other booting device drivers to U-Boot.

Regarding security services of HSS, we are working on a OpenSBI feature which will allow HSS security services to run as independent binary in M-mode (not linked to OpenSBI) and OpenSBI FW_DYNAMIC will be a separate binary acting as a secure monitor.

Quoted 7 lines
Quoted 2 lines

Regards,
Anup

What I have in mind is that the external memory will be up and running by the time we get to U-Boot SPL. In the case of PolarFire SoC the ROM code equivalent brings up the DDR memory interface so we do not need to worry about this as part of U-Boot.

Quoted 4 lines

Keeping DRAM configuration as part of a separate ROM booting stage prior to the U-Boot SPL sounds good to me. This will lead to following boot-flow:

ROM/HSS (M-mode) => U-Boot SPL (M-mode) => OpenSBI (M-mode) => U-Boot S-mode

If we want to keep the HSS, meaning that DDR memory is already initialized, then there is no need to create an additional step of U-Boot SPL phase, because there is no size limitation any more.

Right now, the boot workflow on PolarFire is:

HSS + OpenSBI (as a library) (M-mode) => U-Boot S-mode

It's just not the canonical way because of the HSS and OpenSBI as a library.

A canonical way should be:

U-Boot SPL (M-mode) => OpenSBI dynamic (M-mode) => U-Boot S-mode

So we should be aiming to replace HSS with U-Boot SPL.

Quoted 24 lines
Quoted 4 lines

Sounds to me the component that needs to be upstreamed next is the eMMC support so that it can be used as part of U-Boot SPL. Correct?

Maybe as a PHASE1 patch series for PolarFire U-Boot support can target the following:
1. Minimal U-Boot board support for PolarFire IcIcle Board with single defconfig to build both U-Boot SPL and U-Boot S-mode
2. Serial port driver (probably re-use existing driver)
3. SD and eMMC driver

Supporting SD booting is highly desirable for PHASE1. At least, U-Boot SPL, OpenSBI, U-Boot S-mode, and Linux should come as separate images from SD card. The ROM/HSS can reside and boot from on-board flash/eMMC.

Above is my suggestion based on experience with SiFive Unleashed.

The general idea behind OpenSource boot-flow is to have each booting stage as a separate binary so that users can selectively upgrade a particular booting stage without re-compiling/re-flashing other booting stages.

Quoted 4 lines

Various distros and yocto already support building most of the above booting stages (U-Boot, OpenSBI, Linux, etc) so we can reuse a lot of existing work. Eventually, I am confident we will endup moving more stuff from ROM/HSS to U-Boot SPL for ease in maintenance.

Regards,
Bin

#59 lore raw
Quoted 136 lines · Bin Meng

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 88 lines · Anup Patel
Quoted 87 lines · On Tue, Aug 18, 2020 at 6:39 PM <[email protected]> wrote:
Quoted 86 lines · Anup Patel

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 50 lines · On Tue, Aug 18, 2020 at 1:23 AM <[email protected]> wrote:
Quoted 49 lines · Alistair Francis

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 36 lines · via

Hi Anup,

Quoted 28 lines · Bin Meng

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Hi Anup,

Quoted 7 lines · Anup Patel
Quoted 5 lines · Bin Meng

From: Bin Meng <[email protected]>

This adds support for Microchip PolarFire SoC Icicle Kit board. The Icicle Kit board integrates a PolarFire SoC, with one SiFive's E51 plus four U54 cores and many on-chip peripherals and an FPGA.

Nice Work !!! This is very helpful.

Thanks!

Quoted 14 lines

The Microchip HSS is quite convoluted. It has:
1. DDR Init
2. Boot device support
3. SBI support using OpenSBI as library
4. Simple TEE support

I think point 1) and 2) above should be part of U-Boot SPL. The point 3) can be OpenSBI FW_DYNAMIC.

Lastly,for point 4), we are working on a new OpenSBI feature using which we can run independent Secure OS and Non-Secure OS using U-Boot_SPL+OpenSBI (for both SiFive Unleashed and Microchip PolarFire).

Quoted 5 lines
Quoted 1 line

Do you have plans for adding U-Boot SPL support for this board ??

+ Cyril Jean from Microchip

I will have to leave this question to Cyril to comment.

Quoted 7 lines

I currently do not have a plan to support U-Boot SPL. The idea of the HSS is to contain all the silicon specific initialization and configuration code within the HSS before jumping to U-Boot S-mode. I would rather keep all this within the HSS for the time being. I would wait until we reach production silicon before attempting to move this to U-Boot SPL as the HSS is likely to contain some opaque silicon related changes for another while.

That is unfortunate, a lot of work has gone into making the boot flow simple and easy to use.

Quoted 8 lines
Quoted 6 lines

QEMU now includes OpenSBI by default to make it easy for users to boot Linux. The Icicle Kit board is now the most difficult QEMU board to boot Linux on. Not to mention it makes it hard to impossible to support it in standard tool flows such as meta-riscv.

Alistair

If it is such a problem we can add a U-Boot SPL stage and the HSS can be treated as standard SoC ROM code.

It's not mandatory for U-Boot SPL to have stable DRAM calibration settings from the start itself. The initial U-Boot SPL support for most platforms (accross
architectures) usually include basic working DRAM calibration settings which is later on updated with separate patches. Also, we don't need all U-Boot drivers to be upstreamed in one-go as this can be done in phases.

The advantage we have with PolarFire SoC Icicle board is that we already have a U-Boot S-mode. and we believe the OpenSBI generic platform will work fine for PolarFire SoC Icicle board so the only thing missing right now is the U-Boot SPL support for OpenSource boot-flow.

It will certainly accelerate open-source development if we have boot-flow U-Boot_SPL => OpenSBI (FW_DYNAMIC) => U-Boot_S-mode working on PolarFire SoC Icicle board. Initially, we just need DRAM, SD/eMMC, and Serial port support for U-Boot SPL and U-Boot S-mode. Later on, more patches can add ethernet and other booting device drivers to U-Boot.

Regarding security services of HSS, we are working on a OpenSBI feature which will allow HSS security services to run as independent binary in M-mode (not linked to OpenSBI) and OpenSBI FW_DYNAMIC will be a separate binary acting as a secure monitor.

Regards,
Anup

Quoted 8 lines
Quoted 4 lines

What I have in mind is that the external memory will be up and running by the time we get to U-Boot SPL. In the case of PolarFire SoC the ROM code equivalent brings up the DDR memory interface so we do not need to worry about this as part of U-Boot.

Keeping DRAM configuration as part of a separate ROM booting stage prior to the U-Boot SPL sounds good to me. This will lead to following boot-flow:

ROM/HSS (M-mode) => U-Boot SPL (M-mode) => OpenSBI (M-mode) => U-Boot S-mode

If we want to keep the HSS, meaning that DDR memory is already initialized, then there is no need to create an additional step of U-Boot SPL phase, because there is no size limitation any more.

Right now, the boot workflow on PolarFire is:

HSS + OpenSBI (as a library) (M-mode) => U-Boot S-mode

It's just not the canonical way because of the HSS and OpenSBI as a library.

A canonical way should be:

U-Boot SPL (M-mode) => OpenSBI dynamic (M-mode) => U-Boot S-mode

So we should be aiming to replace HSS with U-Boot SPL.

Quoted 21 lines
Quoted 2 lines

Sounds to me the component that needs to be upstreamed next is the eMMC support so that it can be used as part of U-Boot SPL. Correct?

Maybe as a PHASE1 patch series for PolarFire U-Boot support can target the following:
1. Minimal U-Boot board support for PolarFire IcIcle Board with single defconfig to build both U-Boot SPL and U-Boot S-mode
2. Serial port driver (probably re-use existing driver)
3. SD and eMMC driver

Supporting SD booting is highly desirable for PHASE1. At least, U-Boot SPL, OpenSBI, U-Boot S-mode, and Linux should come as separate images from SD card. The ROM/HSS can reside and boot from on-board flash/eMMC.

Above is my suggestion based on experience with SiFive Unleashed.

The general idea behind OpenSource boot-flow is to have each booting stage as a separate binary so that users can selectively upgrade a particular booting stage without re-compiling/re-flashing other booting stages.

Quoted 6 lines
Quoted 4 lines

Various distros and yocto already support building most of the above booting stages (U-Boot, OpenSBI, Linux, etc) so we can reuse a lot of existing work. Eventually, I am confident we will endup moving more stuff from ROM/HSS to U-Boot SPL for ease in maintenance.

Regards,
Bin

I am OK with supporting U-Boot SPL as a community boot flow but the HSS is not going to disappear completely for many PolarFire SoC deployments. We need to have the HSS running on the monitor core after the system has booted for various reasons. Some of the current HSS functionalities can be migrated at a later time.

The HSS was designed to easily enable and disable features through Kconfig which should allow to assign features to different boot stages depending on the overall system deployment. Keeping the HSS as ROM code capable of starting various early boot stages in either M mode or S mode allows us (Microchip engineering and non pure Linux users) to mix different operating systems on the same platform and more easily debug hardware bring-up.

What I am trying to get at is that we need to balance the QEMU ease of use with the ability to bring-up and debug actual hardware. My preferred approach is to keep all the hardware bring up in one place, the HSS, so that you do not have to worry about obscure silicon idiosyncrasies once you reach the open source boot flow. Silicon/board bring up steps/features can be brought out of the HSS into the open source boot stages once these steps are mature.

PolarFire SoC is the third family of SoC FPGA I have worked on. So I have a fair idea of the amount of pain in front of me to bring the entire device family to market :-) We decided early on in the architecture of PolarFire SoC that we would make all code executing on the RISC-V processors open source and user modifiable. This includes all code typically hidden away in your typical SoC ROM code. This is why PolarFire SoC has on-chip flash memory used to store the HSS and why the HSS should be thought as including ROM code. The current Icicle Kit uses engineering samples from the first device in the PolarFire SoC family. So we are really at the beginning of the process of validating very early boot steps on a significant number of devices. I do not want to expose the open source community to the pain of bringing up a family of devices because of the decision to open source all code. So I am asking you to not rush in trying to migrate components from the HSS to a later boot stage just yet. It can be done but based on experience I think that now is not the right time yet.

Regards,

Cyril.

#60 lore raw
Quoted 151 lines · On Wed, Aug 19, 2020 at 3:13 AM <[email protected]> wrote:
Quoted 136 lines · Bin Meng

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 88 lines · Anup Patel
Quoted 87 lines · On Tue, Aug 18, 2020 at 6:39 PM <[email protected]> wrote:
Quoted 86 lines · Anup Patel

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 50 lines · On Tue, Aug 18, 2020 at 1:23 AM <[email protected]> wrote:
Quoted 49 lines · Alistair Francis

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 36 lines · via

Hi Anup,

Quoted 28 lines · Bin Meng

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Hi Anup,

Quoted 7 lines · Anup Patel
Quoted 5 lines · Bin Meng

From: Bin Meng <[email protected]>

This adds support for Microchip PolarFire SoC Icicle Kit board. The Icicle Kit board integrates a PolarFire SoC, with one SiFive's E51 plus four U54 cores and many on-chip peripherals and an FPGA.

Nice Work !!! This is very helpful.

Thanks!

Quoted 14 lines

The Microchip HSS is quite convoluted. It has:
1. DDR Init
2. Boot device support
3. SBI support using OpenSBI as library
4. Simple TEE support

I think point 1) and 2) above should be part of U-Boot SPL. The point 3) can be OpenSBI FW_DYNAMIC.

Lastly,for point 4), we are working on a new OpenSBI feature using which we can run independent Secure OS and Non-Secure OS using U-Boot_SPL+OpenSBI (for both SiFive Unleashed and Microchip PolarFire).

Quoted 5 lines
Quoted 1 line

Do you have plans for adding U-Boot SPL support for this board ??

+ Cyril Jean from Microchip

I will have to leave this question to Cyril to comment.

Quoted 7 lines

I currently do not have a plan to support U-Boot SPL. The idea of the HSS is to contain all the silicon specific initialization and configuration code within the HSS before jumping to U-Boot S-mode. I would rather keep all this within the HSS for the time being. I would wait until we reach production silicon before attempting to move this to U-Boot SPL as the HSS is likely to contain some opaque silicon related changes for another while.

That is unfortunate, a lot of work has gone into making the boot flow simple and easy to use.

Quoted 8 lines
Quoted 6 lines

QEMU now includes OpenSBI by default to make it easy for users to boot Linux. The Icicle Kit board is now the most difficult QEMU board to boot Linux on. Not to mention it makes it hard to impossible to support it in standard tool flows such as meta-riscv.

Alistair

If it is such a problem we can add a U-Boot SPL stage and the HSS can be treated as standard SoC ROM code.

It's not mandatory for U-Boot SPL to have stable DRAM calibration settings from the start itself. The initial U-Boot SPL support for most platforms (accross
architectures) usually include basic working DRAM calibration settings which is later on updated with separate patches. Also, we don't need all U-Boot drivers to be upstreamed in one-go as this can be done in phases.

The advantage we have with PolarFire SoC Icicle board is that we already have a U-Boot S-mode. and we believe the OpenSBI generic platform will work fine for PolarFire SoC Icicle board so the only thing missing right now is the U-Boot SPL support for OpenSource boot-flow.

It will certainly accelerate open-source development if we have boot-flow U-Boot_SPL => OpenSBI (FW_DYNAMIC) => U-Boot_S-mode working on PolarFire SoC Icicle board. Initially, we just need DRAM, SD/eMMC, and Serial port support for U-Boot SPL and U-Boot S-mode. Later on, more patches can add ethernet and other booting device drivers to U-Boot.

Regarding security services of HSS, we are working on a OpenSBI feature which will allow HSS security services to run as independent binary in M-mode (not linked to OpenSBI) and OpenSBI FW_DYNAMIC will be a separate binary acting as a secure monitor.

Regards,
Anup

Quoted 8 lines
Quoted 4 lines

What I have in mind is that the external memory will be up and running by the time we get to U-Boot SPL. In the case of PolarFire SoC the ROM code equivalent brings up the DDR memory interface so we do not need to worry about this as part of U-Boot.

Keeping DRAM configuration as part of a separate ROM booting stage prior to the U-Boot SPL sounds good to me. This will lead to following boot-flow:

ROM/HSS (M-mode) => U-Boot SPL (M-mode) => OpenSBI (M-mode) => U-Boot S-mode

If we want to keep the HSS, meaning that DDR memory is already initialized, then there is no need to create an additional step of U-Boot SPL phase, because there is no size limitation any more.

Right now, the boot workflow on PolarFire is:

HSS + OpenSBI (as a library) (M-mode) => U-Boot S-mode

It's just not the canonical way because of the HSS and OpenSBI as a library.

A canonical way should be:

U-Boot SPL (M-mode) => OpenSBI dynamic (M-mode) => U-Boot S-mode

So we should be aiming to replace HSS with U-Boot SPL.

Quoted 21 lines
Quoted 2 lines

Sounds to me the component that needs to be upstreamed next is the eMMC support so that it can be used as part of U-Boot SPL. Correct?

Maybe as a PHASE1 patch series for PolarFire U-Boot support can target the following:
1. Minimal U-Boot board support for PolarFire IcIcle Board with single defconfig to build both U-Boot SPL and U-Boot S-mode
2. Serial port driver (probably re-use existing driver)
3. SD and eMMC driver

Supporting SD booting is highly desirable for PHASE1. At least, U-Boot SPL, OpenSBI, U-Boot S-mode, and Linux should come as separate images from SD card. The ROM/HSS can reside and boot from on-board flash/eMMC.

Above is my suggestion based on experience with SiFive Unleashed.

The general idea behind OpenSource boot-flow is to have each booting stage as a separate binary so that users can selectively upgrade a particular booting stage without re-compiling/re-flashing other booting stages.

Quoted 6 lines
Quoted 4 lines

Various distros and yocto already support building most of the above booting stages (U-Boot, OpenSBI, Linux, etc) so we can reuse a lot of existing work. Eventually, I am confident we will endup moving more stuff from ROM/HSS to U-Boot SPL for ease in maintenance.

Regards,
Bin

I am OK with supporting U-Boot SPL as a community boot flow but the HSS is not going to disappear completely for many PolarFire SoC deployments. We need to have the HSS running on the monitor core after the system has booted for various reasons. Some of the current HSS functionalities can be migrated at a later time.

Quoted 7 lines

The HSS was designed to easily enable and disable features through Kconfig which should allow to assign features to different boot stages depending on the overall system deployment. Keeping the HSS as ROM code capable of starting various early boot stages in either M mode or S mode allows us (Microchip engineering and non pure Linux users) to mix different operating systems on the same platform and more easily debug hardware bring-up.

Thanks for explaining this.

I have changed the CC list a bit to be a little more targeted.

Quoted 3 lines

What I am trying to get at is that we need to balance the QEMU ease of use with the ability to bring-up and debug actual hardware. My preferred

Agreed. I don't think anyone has been saying that these changes should be for QEMU only. All of the changes talked about apply to both the QEMU model and the hardware.

Quoted 3 lines

approach is to keep all the hardware bring up in one place, the HSS, so that you do not have to worry about obscure silicon idiosyncrasies once you reach the open source boot flow. Silicon/board bring up

That is a noble goal, but doesn't HSS currently pull in the OpenSBI library, so it's doing more than just dealing with silicon bugs. As well as that HSS is not supported by distros, so distros can't build or ship it. For example OE won't build it in the meta-riscv layer, meaning that the Icle board just isn't supported. This means the board misses out on core work, for example it won't be able to utilise the RISC-V AGL work that has started.

Also, how are users expected to update HSS as bugs and vulnerabilities are found if it isn't shipped by distros?

Quoted 8 lines

steps/features can be brought out of the HSS into the open source boot stages once these steps are mature.

PolarFire SoC is the third family of SoC FPGA I have worked on. So I have a fair idea of the amount of pain in front of me to bring the entire device family to market :-) We decided early on in the architecture of PolarFire SoC that we would make all code executing on the RISC-V processors open source and user modifiable. This includes all

Awesome!!! That is so great to hear.

Quoted 1 line

code typically hidden away in your typical SoC ROM code. This is why

Again, this is just awesome!

Quoted 2 lines

PolarFire SoC has on-chip flash memory used to store the HSS and why the HSS should be thought as including ROM code. The current Icicle Kit uses

If we could change it to be more like a traditional ROM in terms of features then that would be really helpful. In that case we wouldn't need it for QEMU and only use it for hardware. It would only handle basic hardware boot up and then hand it over to U-Boot SPL/OpenSBI.

Quoted 5 lines

engineering samples from the first device in the PolarFire SoC family. So we are really at the beginning of the process of validating very early boot steps on a significant number of devices. I do not want to expose the open source community to the pain of bringing up a family of devices because of the decision to open source all code. So I am asking

I understand what you mean. In saying that it is usually easiest to start with the goal of upstreaming and then work towards that. That way all of the architectures decisions are made in that context. Maybe at first you have a fork while everything is in flux, but then it's really helpful to have the work upstreamed.

I think we have all seen too many "open source" projects that just fork everything, dump their code and never contribute back. Unfortunately when that happens we end up with duplicate work and frustrated engineers. As well as that the original project misses out on all the advantages of open source as they aren't benefiting from others work as well.

Quoted 3 lines

you to not rush in trying to migrate components from the HSS to a later boot stage just yet. It can be done but based on experience I think that now is not the right time yet.

The open source focus is great to hear. I think we are all really glad that MicroChip is doing this. It's a great first step, but it doesn't end there.

Alistair

Quoted 5 lines

Regards,

Cyril.

#61 lore raw
In reply to Bin Meng
Patchew URL: https://patchew.org/QEMU/[email protected]/

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

Hi,

This series failed the docker-quick@centos7 build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-centos7 V=1 NETWORK=1
time make docker-test-quick@centos7 SHOW_ENV=1 J=14 NETWORK=1 === TEST SCRIPT END ===

TEST check-unit: tests/test-char
Unexpected error in object_property_try_add() at /tmp/qemu-test/src/qom/object.c:1181:
attempt to add duplicate property 'serial-id' to object (type 'container')
ERROR test-char - too few tests run (expected 38, got 9)
make: *** [check-unit] Error 1
make: *** Waiting for unfinished jobs....
TEST check-qtest-x86_64: tests/qtest/hd-geo-test
qemu-system-aarch64: -accel kvm: invalid accelerator kvm
---
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', '--label', 'com.qemu.instance.uuid=5d87ed4b32104d3fa300f89248e59809', '-u', '1003', '--security-opt', 'seccomp=unconfined', '--rm', '-e', 'TARGET_LIST=', '-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14', '-e', 'DEBUG=', '-e', 'SHOW_ENV=1', '-e', 'CCACHE_DIR=/var/tmp/ccache', '-v', '/home/patchew2/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', '/var/tmp/patchew-tester-tmp-okrr9kbl/src/docker-src.2020-08-14-13.56.55.12251:/var/tmp/qemu:z,ro', 'qemu/centos7', '/var/tmp/qemu/run', 'test-quick']' returned non-zero exit status 2. filter=--filter=label=com.qemu.instance.uuid=5d87ed4b32104d3fa300f89248e59809
make[1]: *** [docker-run] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-okrr9kbl/src'
make: *** [docker-run-test-quick@centos7] Error 2

real 13m35.300s
user 0m8.266s

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