Skip to contentSkip to conversation

riscv: Add K230 DDR controller and PHY models

PATCH Applied Junze Cao 2 participants 5 messages Aug 7 – Aug 11

Subsystems (2)
lore
Share & tools
lore

Junze Cao

author
#0 lore raw

v2 cover riscv: Add K230 DDR controller and PHY models

The K230 SDK U-Boot SPL initializes DRAM by programming the DDRC CFG and DDR PHY MMIO regions. The k230 machine currently exposes the DDR configuration region as unimplemented and does not provide the PHY, so the SPL cannot complete the training and DFI handshakes.

Add minimal models for the register behavior exercised by the SDK SPL. The controller model provides reset values, register access policy, DFI and software-update handshakes, and the Init-to-Normal transition. The PHY model provides CSR ownership, the training mailbox, and DFI completion. Wire both devices into the k230 machine and document the resulting SPL support.

These device models allow firmware to complete the DDR initialization sequence.

Changes in v2:

* Add LOG_UNIMP messages for unimplemented DDR PHY register accesses, including reads returning zero and ignored writes.

Testing performed:

* scripts/checkpatch.pl --branch upstream/master..HEAD
* meson test -C build --print-errorlogs qemu:qtest-riscv64/k230-ddr-test (6 subtests passed)
* Booted the K230 SDK U-Boot SPL through DDR initialization to its SPI boot path

---
Junze Cao (3):
hw/misc: Add K230 DDR controller and PHY models hw/riscv: Connect K230 DDR controller and PHY models tests/qtest: Add K230 DDR controller tests

 MAINTAINERS                 |   3 +
 docs/system/riscv/k230.rst  |   4 +
 hw/misc/k230_ddr.c          | 556 ++++++++++++++++++++++++++++++++++++++++++++
 hw/misc/meson.build         |   1 +
 hw/riscv/k230.c             |  19 +-
 include/hw/misc/k230_ddr.h  |  59 +++++
 include/hw/riscv/k230.h     |   4 +
 tests/qtest/k230-ddr-test.c | 226 ++++++++++++++++++
 tests/qtest/meson.build     |   3 +-
 9 files changed, 871 insertions(+), 4 deletions(-)

---
base-commit: 3e3ccab106f879b1512f8e0d51a827dd4de30e22
change-id: 20260807-k230-ddr-v2-f8037b6ac237

Best regards,

Signature · 1 line
Junze Cao <[email protected]>
author
#1 lore raw

PATCH v2 1/3 hw/misc: Add K230 DDR controller and PHY models

The K230 SDK U-Boot SPL programs K230 DDRC CFG and K230 DDR PHY registers before DRAM can be used.

Add separate SysBus devices for both register ranges. Model controller reset values, DFI and software-update handshakes. For the PHY, model register ownership, the training mailbox, and DFI completion.

Include migration state for both devices.

---
 MAINTAINERS                |   2 +
 hw/misc/k230_ddr.c         | 556 +++++++++++++++++++++++++++++++++++++++++++++
 hw/misc/meson.build        |   1 +
 include/hw/misc/k230_ddr.h |  59 +++++
 4 files changed, 618 insertions(+)
MAINTAINERS +2 -0
index 902db77218..f12728ff47 100644
@@ -1827,8 +1827,10 @@ M: Chao Liu <[email protected]>
 L: [email protected]
 S: Maintained
 F: docs/system/riscv/k230.rst
+F: hw/misc/k230_ddr.c
 F: hw/riscv/k230.c
 F: hw/watchdog/k230_wdt.c
+F: include/hw/misc/k230_ddr.h
 F: include/hw/riscv/k230.h
 F: include/hw/watchdog/k230_wdt.h
 F: tests/functional/riscv64/test_k230.py
hw/misc/k230_ddr.c new file +556 -0

556 lines not on this page · raw message

hw/misc/meson.build +1 -0
index 23265f6035..6d5e2b2647 100644
@@ -28,6 +28,7 @@ system_ss.add(when: 'CONFIG_IOSB', if_true: files('iosb.c'))
 system_ss.add(when: 'CONFIG_VIRT_CTRL', if_true: files('virt_ctrl.c'))
 
 # RISC-V devices
+system_ss.add(when: 'CONFIG_K230', if_true: files('k230_ddr.c'))
 system_ss.add(when: 'CONFIG_MCHP_PFSOC_DMC', if_true: files('mchp_pfsoc_dmc.c'))
 system_ss.add(when: 'CONFIG_MCHP_PFSOC_IOSCB', if_true: files('mchp_pfsoc_ioscb.c'))
 system_ss.add(when: 'CONFIG_MCHP_PFSOC_SYSREG', if_true: files('mchp_pfsoc_sysreg.c'))
include/hw/misc/k230_ddr.h new file +59 -0

59 lines not on this page · raw message

Signature · 1 line
2.53.0
author
#2 lore raw

PATCH v2 2/3 hw/riscv: Connect K230 DDR controller and PHY models

In reply to Junze Cao

Replace the unimplemented K230 DDR configuration region with the DDRC model and map the PHY model at 0x9a000000.

Connect the controller to the PHY so DFI status reflects PHY training and initialization state.

---
 docs/system/riscv/k230.rst |  4 ++++
 hw/riscv/k230.c            | 19 ++++++++++++++++---
 include/hw/riscv/k230.h    |  4 ++++
 3 files changed, 24 insertions(+), 3 deletions(-)
docs/system/riscv/k230.rst +4 -0
index cea8202e55..06a819fbdb 100644
@@ -20,12 +20,16 @@ The ``k230`` machine supports the following devices:
 * Platform-Level Interrupt Controller (PLIC)
 * 2 K230 Watchdog Timer
 * 5 UART
+* K230 DDRC CFG and DDR PHY
 
 Boot options
 ------------
 The ``k230`` machine supports K230 SDK boot through M-mode U-Boot, which then
 starts OpenSBI/Linux with ``bootm``. It also supports direct Linux boot.
 
+The DDRC CFG and DDR PHY models allow the K230 SDK U-Boot SPL to complete DDR
+initialization before loading the next boot stage.
+
 K230 SDK Linux kernels use T-HEAD C9xx private MAEE page table attributes. QEMU
 does not implement MAEE in the generic RISC-V MMU, so such kernels need to be
 built with standard RISC-V PTE bits before they can boot under QEMU.
hw/riscv/k230.c +16 -3
index 656f28190c..627150b463 100644
@@ -97,6 +97,7 @@ static const MemMapEntry memmap[] = {
     [K230_DEV_SPI] =          { 0x91584000,  0x00001000 },
     [K230_DEV_HI_SYS_CFG] =   { 0x91585000,  0x00000400 },
     [K230_DEV_DDRC_CFG] =     { 0x98000000,  0x02000000 },
+    [K230_DEV_DDR_PHY] =      { 0x9A000000,  0x00400000 },
     [K230_DEV_FLASH] =        { 0xC0000000,  0x08000000 },
     [K230_DEV_PLIC] =         { 0xF00000000, 0x00400000 },
     [K230_DEV_CLINT] =        { 0xF04000000, 0x00400000 },
@@ -108,6 +109,11 @@ static void k230_soc_init(Object *obj)
     RISCVHartArrayState *cpu0 = &s->c908_cpu;
 
     object_initialize_child(obj, "c908-cpu", cpu0, TYPE_RISCV_HART_ARRAY);
+    object_initialize_child(obj, "ddr-cfg", &s->ddr_cfg,
+                            TYPE_K230_DDR_CFG);
+    object_initialize_child(obj, "ddr-phy", &s->ddr_phy,
+                            TYPE_K230_DDR_PHY);
+    s->ddr_cfg.phy = &s->ddr_phy;
     object_initialize_child(obj, "k230-wdt0", &s->wdt[0], TYPE_K230_WDT);
     object_initialize_child(obj, "k230-wdt1", &s->wdt[1], TYPE_K230_WDT);
 
@@ -158,6 +164,16 @@ static void k230_soc_realize(DeviceState *dev, Error **errp)
     int c908_cpus;
 
     sysbus_realize(SYS_BUS_DEVICE(&s->c908_cpu), &error_fatal);
+    if (!sysbus_realize(SYS_BUS_DEVICE(&s->ddr_cfg), errp)) {
+        return;
+    }
+    if (!sysbus_realize(SYS_BUS_DEVICE(&s->ddr_phy), errp)) {
+        return;
+    }
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->ddr_cfg), 0,
+                    memmap[K230_DEV_DDRC_CFG].base);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->ddr_phy), 0,
+                    memmap[K230_DEV_DDR_PHY].base);
 
     c908_cpus = s->c908_cpu.num_harts;
 
@@ -361,9 +377,6 @@ static void k230_soc_realize(DeviceState *dev, Error **errp)
     create_unimplemented_device("hi_sys_cfg", memmap[K230_DEV_HI_SYS_CFG].base,
                                 memmap[K230_DEV_HI_SYS_CFG].size);
 
-    create_unimplemented_device("ddrc_cfg", memmap[K230_DEV_DDRC_CFG].base,
-                                memmap[K230_DEV_DDRC_CFG].size);
-
     create_unimplemented_device("flash", memmap[K230_DEV_FLASH].base,
                                 memmap[K230_DEV_FLASH].size);
 }
include/hw/riscv/k230.h +4 -0
index 592e1c26bf..80ca16338c 100644
@@ -16,6 +16,7 @@
 #define HW_K230_H
 
 #include "hw/core/boards.h"
+#include "hw/misc/k230_ddr.h"
 #include "hw/riscv/riscv_hart.h"
 #include "hw/watchdog/k230_wdt.h"
 
@@ -32,6 +33,8 @@ typedef struct K230SoCState {
     /*< public >*/
     RISCVHartArrayState c908_cpu; /* Small core */
 
+    K230DDRCfgState ddr_cfg;
+    K230DDRPhyState ddr_phy;
     K230WdtState wdt[2];
     MemoryRegion sram;
     MemoryRegion bootrom;
@@ -112,6 +115,7 @@ enum {
     K230_DEV_SPI,
     K230_DEV_HI_SYS_CFG,
     K230_DEV_DDRC_CFG,
+    K230_DEV_DDR_PHY,
     K230_DEV_FLASH,
     K230_DEV_PLIC,
     K230_DEV_CLINT,
Signature · 1 line
2.53.0
author
#3 lore raw

PATCH v2 3/3 tests/qtest: Add K230 DDR controller tests

In reply to Junze Cao

Add qtests for DDRC and PHY reset values, register access policy, the software-update handshake, and PHY register ownership.

Exercise PHY training and mailbox acknowledgement through the DFI initialization sequence. Include negative coverage to ensure DFI cannot complete before PHY training or enter Normal mode before completion is enabled.

---
 MAINTAINERS                 |   1 +
 tests/qtest/k230-ddr-test.c | 226 ++++++++++++++++++++++++++++++++++++++++++++
 tests/qtest/meson.build     |   3 +-
 3 files changed, 229 insertions(+), 1 deletion(-)
MAINTAINERS +1 -0
index f12728ff47..cf764b2efc 100644
@@ -1834,6 +1834,7 @@ F: include/hw/misc/k230_ddr.h
 F: include/hw/riscv/k230.h
 F: include/hw/watchdog/k230_wdt.h
 F: tests/functional/riscv64/test_k230.py
+F: tests/qtest/k230-ddr-test.c
 F: tests/qtest/k230-wdt-test.c
 
 RX Machines
tests/qtest/k230-ddr-test.c new file +226 -0

226 lines not on this page · raw message

tests/qtest/meson.build +2 -1
index 56ff860e21..dc110f72c8 100644
@@ -297,7 +297,8 @@ qtests_riscv64 = ['riscv-csr-test'] + \
   (config_all_devices.has_key('CONFIG_IOMMU_TESTDEV') and
    config_all_devices.has_key('CONFIG_RISCV_IOMMU') ?
    ['iommu-riscv-test'] : []) + \
-  (config_all_devices.has_key('CONFIG_K230') ? ['k230-wdt-test'] : [])
+  (config_all_devices.has_key('CONFIG_K230') ?
+   ['k230-ddr-test', 'k230-wdt-test'] : [])
 
 qtests_hexagon = ['boot-serial-test']
 
Signature · 1 line
2.53.0
Applied
#4 lore raw
In reply to Junze Cao
Quoted 33 lines · Junze Cao

The K230 SDK U-Boot SPL initializes DRAM by programming the DDRC CFG and DDR PHY MMIO regions. The k230 machine currently exposes the DDR configuration region as unimplemented and does not provide the PHY, so
the SPL cannot complete the training and DFI handshakes.

Add minimal models for the register behavior exercised by the SDK SPL.
The controller model provides reset values, register access policy, DFI
and software-update handshakes, and the Init-to-Normal transition. The
PHY model provides CSR ownership, the training mailbox, and DFI completion. Wire both devices into the k230 machine and document the resulting SPL support.

These device models allow firmware to complete the DDR initialization sequence.

Changes in v2:

* Add LOG_UNIMP messages for unimplemented DDR PHY register accesses, including reads returning zero and ignored writes.

Testing performed:

* scripts/checkpatch.pl --branch upstream/master..HEAD
* meson test -C build --print-errorlogs qemu:qtest-riscv64/k230-ddr-test (6 subtests passed)
* Booted the K230 SDK U-Boot SPL through DDR initialization to its SPI
  boot path

Quoted 5 lines

---
Junze Cao (3):
      hw/misc: Add K230 DDR controller and PHY models hw/riscv: Connect K230 DDR controller and PHY models tests/qtest: Add K230 DDR controller tests

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 20 lines

 MAINTAINERS                 |   3 + docs/system/riscv/k230.rst  |   4 + hw/misc/k230_ddr.c          | 556
++++++++++++++++++++++++++++++++++++++++++++
 hw/misc/meson.build         |   1 + hw/riscv/k230.c             |  19 +- include/hw/misc/k230_ddr.h  |  59 +++++ include/hw/riscv/k230.h     |   4 + tests/qtest/k230-ddr-test.c | 226 ++++++++++++++++++ tests/qtest/meson.build     |   3 +-

 9 files changed, 871 insertions(+), 4 deletions(-)

---
base-commit: 3e3ccab106f879b1512f8e0d51a827dd4de30e22
change-id: 20260807-k230-ddr-v2-f8037b6ac237

Best regards,
--
Junze Cao <[email protected]>