Skip to contentSkip to conversation

hw/riscv: Restore Microchip PolarFire SoC Icicle Kit firmware boot

PATCH In review Bin Meng 5 participants 43 messages Nov 4 – Nov 23

Subsystems (3)
lore
Share & tools
lore

Bin Meng

author
#0 lore raw

v5 cover hw/riscv: Restore Microchip PolarFire SoC Icicle Kit firmware boot

The microchip-icicle-kit machine was originally validated with an older Hart Software Services (HSS) firmware stack. HSS v2026.04.1 cannot boot through U-Boot to Linux because several firmware-visible parts of the PolarFire SoC are missing or incomplete.

The first failure occurs before the UART is initialized because the L2 zero window is not mapped. HSS then needs additional L2 cache controller and DDR training behavior. Later boot stages exercise system services, the RTC, SDHC version 4 DMA, and high-capacity SD card block sizing, along with the complete DDR aliases. The existing models ither reject these accesses or expose behavior that does not match the hardware specifications.

This series restores the complete firmware boot flow. With these changes, QEMU boots the HSS v2026.04.1 eNVM image, loads its U-Boot payload from an SD card, and reaches the Buildroot 2026.05 Linux login prompt.

The changes are organized around the firmware boot sequence:

* Correct the L2-LIM size, map the L2 zero window, and provide the DMC status transitions required by HSS DDR initialization.
* Model the documented L2CC Config, WayEnable, and WayMask registers, and resize L2-LIM as cache ways are enabled.
* Complete SDHCI version 4 support used by the Cadence controller, including Host Control 2, SDMA system addressing, 64-bit ADMA2 descriptors, and SDMA boundary continuation.
* Run ADMA from a bounded timer-driven engine instead of performing work from command or unrelated MMIO accesses. This keeps DMA progress independent of guest register traffic and avoids consuming a polling deadline inside the command write.
* Advertise the Cadence controller's 64-bit system bus support.
* Add the PolarFire SoC serial-number system service and RTC, and honor the system-service notification control bit.
* Correct the DDR aliases and fix the board topology at its physical configuration of 2 GiB of RAM and five harts.
* Document direct and HSS boot, add focused qtests and a full firmware functional test, and restore the machine's Supported maintainer status.

Testing performed:

* Built qemu-system-riscv64 and the documentation.
* Passed various newly added qtests.
* Booted HSS v2026.04.1, U-Boot, and Buildroot 2026.05 Linux to the login prompt using the functional-test image.

The functional test uses the processmission/qemu-machine-images release v1.1.1 tarball:

https://github.com/processmission/qemu-machine-images/releases/download/
v1.1.1/riscv64-microchip-icicle-kit-v1.1.1.tar.zst

When restoring the HSS boot support, 3 potential bugs were identified in the upstream HSS source codes that either blocks the DDR training from succeed or traps in a multi-core race at the very beginning or after a succesfully DDR training but stuck at OpenSBI/U-Boot hand-off. There are already bug reports filed aginst various upstream projects.

Changes in v5:
- Select REGISTER to fix riscv32-softmmu link failures
- Rebase onto origin/master
- Drop the high-capacity SD block-size fix already merged upstream

Changes in v4:
- Drop the unused ADMA callback forward declaration
- Move helper definitions before the data-transfer declaration
- Merge the ADMA timer callback and batch routine
- Use HSS v2026.04.1 and the v1.1.1 test-image recipe
- Select the SoftConsole toolchain explicitly
- Use the generated complete boot-mode-1 eNVM binary
- Use the v1.1.1 test images with HSS v2026.04.1
- Add the execution bit to the python script
- Collect Conor Dooley's Tested-by for the complete series
- Collect Bernhard Beschow's Tested-by for the ADMA patch

Changes in v3:
- Name the QOM parent field parent_obj
- Move the LIM and Zero windows into L2CC
- Use the shared SiFive name and indexed WayMask registers
- Parameterize master count and the RAM-backed Zero aperture
- Resize a LIM alias while keeping its SRAM backing fixed
- Configure and instantiate the shared SiFive L2CC
- Map the register, LIM, and Zero windows exposed by the controller
- Remove the external RAM allocations and l2-lim link
- Keep the PolarFire master count and modeled Zero aperture unchanged
- hw/riscv: sifive_u: Correct the L2LIM maximum mapped size
- hw/riscv: sifive_u: Use the shared SiFive L2 cache controller
- Rename the test for the shared SiFive L2CC model
- Exercise 15 masters on PolarFire and 21 masters on FU540
- Decode the seven-bit opcode and nine-bit mailbox word offset
- Bound serial-number responses to the documented 2 KiB mailbox
- Mirror the current control flags in the status register
- Use default access sizing for the control and mailbox windows
- Split the NOTIFY fix from interrupt acknowledgement wiring
- Separate interrupt state ownership from the NOTIFY fix
- Link SYSREG to IOSCB for MESSAGE_INT reads and writes
- Support both clearing and setting the MESSAGE_INT pending bit
- Update commit message to mention the DDR aliases is modeled following the Icicle Kit reference design
- Change only the default hart count and retain the minimum of two
- Document reduced topologies and matching firmware requirements
- Include the DDR pattern-test patch used by the functional-test image
- Document the image-only FPGA programming tool check
- Describe startup-race symptoms and link the firmware investigations
- Explain how reduced hart topologies change the CLINT DTB tuples

Changes in v2:
- Use the Resettable API instead of a legacy reset handler
- tests/qtest: add Cadence SDHCI ADMA pacing/MMIO reproducer
- Assert bounded ADMA pacing and MMIO-independent progress
- Reuse existing SDHCI definitions and command helpers
- Verify transferred data against a known image pattern
- Make 64-bit system bus support a device property
- hw/riscv: pfsoc: Enable 64-bit SDHCI system bus support
- Reset the RTC to the documented hardware values
- Expect the documented hardware state after RTC reset
- MAINTAINERS: Move Conor Dooley to PolarFire SoC reviewer

Bin Meng (25):
hw/riscv: pfsoc: Correct the L2LIM maximum mapped size hw/riscv: pfsoc: Map the L2 zero device window
hw/misc: pfsoc: Support DDR training with newer HSS hw/misc: Add SiFive L2 cache controller model
hw/riscv: pfsoc: Map the SiFive L2CC memory windows hw/riscv: sifive_u: Correct the L2LIM maximum mapped size hw/riscv: sifive_u: Use the shared SiFive L2 cache controller tests/qtest: Add SiFive L2 cache controller coverage hw/sd: sdhci: Run ADMA independently of MMIO
hw/sd: cadence: Add 64-bit system bus property hw/riscv: pfsoc: Enable 64-bit SDHCI system bus support hw/rtc: Add PolarFire SoC RTC model
hw/riscv: pfsoc: Add PolarFire SoC RTC to Icicle Kit tests/qtest: Add PolarFire SoC RTC coverage
hw/misc: pfsoc: Model PolarFire SoC serial number service hw/misc: pfsoc: Honor service notification requests hw/misc: pfsoc: Let IOSCB own service interrupt state hw/riscv: pfsoc: Correct PolarFire SoC DDR aliases hw/riscv: pfsoc: Fix Icicle Kit RAM size at 2 GiB hw/riscv: pfsoc: Default Icicle Kit to five harts docs/system/riscv: Document Icicle Kit HSS boot docs/system/riscv: pfsoc: Document CLINT topology for direct Linux
boot
tests/functional/riscv64: Add Icicle Kit firmware boot test
MAINTAINERS: Add PolarFire SoC Icicle Kit maintainer
MAINTAINERS: Move Conor Dooley to PolarFire SoC reviewer

Wadim Mueller (1):
tests/qtest: add Cadence SDHCI ADMA pacing/MMIO reproducer

 MAINTAINERS                                   |  11 +-
 docs/system/riscv/microchip-icicle-kit.rst    | 162 +++++-
 docs/system/riscv/sifive_u.rst                |   2 +-
 include/hw/misc/mchp_pfsoc_dmc.h              |   6 +
 include/hw/misc/mchp_pfsoc_ioscb.h            |  10 +
 include/hw/misc/mchp_pfsoc_sysreg.h           |   3 +-
 include/hw/misc/sifive_l2cc.h                 |  42 ++
 include/hw/riscv/microchip_pfsoc.h            |   7 +
 include/hw/riscv/sifive_u.h                   |   3 +
 include/hw/rtc/mchp_pfsoc_rtc.h               |  46 ++
 include/hw/sd/cadence_sdhci.h                 |   1 +
 hw/misc/mchp_pfsoc_dmc.c                      | 273 +++++++++-
 hw/misc/mchp_pfsoc_ioscb.c                    | 174 ++++++-
 hw/misc/mchp_pfsoc_sysreg.c                   |  37 +-
 hw/misc/sifive_l2cc.c                         | 282 +++++++++++
 hw/riscv/microchip_pfsoc.c                    |  91 ++--
 hw/riscv/sifive_u.c                           |  32 +-
 hw/rtc/mchp_pfsoc_rtc.c                       | 477 ++++++++++++++++++
 hw/sd/cadence_sdhci.c                         |  11 +
 hw/sd/sdhci.c                                 | 146 +++---
 tests/qtest/cadence-sdhci-test.c              | 282 +++++++++++
 tests/qtest/mchp_pfsoc_rtc_test.c             | 315 ++++++++++++
 tests/qtest/sifive_l2cc_test.c                | 306 +++++++++++
 hw/misc/Kconfig                               |   4 +
 hw/misc/meson.build                           |   1 +
 hw/riscv/Kconfig                              |   3 +
 hw/rtc/Kconfig                                |   3 +
 hw/rtc/meson.build                            |   1 +
 tests/functional/riscv64/meson.build          |   2 +
 .../riscv64/test_microchip_icicle_kit.py      |  56 ++
 tests/qtest/meson.build                       |   8 +
 31 files changed, 2615 insertions(+), 182 deletions(-)
 create mode 100644 include/hw/misc/sifive_l2cc.h
 create mode 100644 include/hw/rtc/mchp_pfsoc_rtc.h
 create mode 100644 hw/misc/sifive_l2cc.c
 create mode 100644 hw/rtc/mchp_pfsoc_rtc.c
 create mode 100644 tests/qtest/cadence-sdhci-test.c
 create mode 100644 tests/qtest/mchp_pfsoc_rtc_test.c
 create mode 100644 tests/qtest/sifive_l2cc_test.c
 create mode 100755 tests/functional/riscv64/test_microchip_icicle_kit.py

---
base-commit: f29ccc287a6cfdd51d3a4fd17fbe9af3310a0ac5
branch: icicle-kit

Signature · 1 line
2.53.0
author
#2 lore raw

PATCH v5 2/26 hw/riscv: pfsoc: Map the L2 zero device window

HSS uses a window at 0x0a000000 while setting up the L2 cache, decompressing its runtime image, and executing that image. The missing mapping causes the E51 to trap before firmware can initialize its UART.

Represent the window with RAM to provide its persistent read, write, and execute effects without claiming to model the L2 cache itself.

---

(no changes since v1)

 include/hw/riscv/microchip_pfsoc.h |  1 +
 hw/riscv/microchip_pfsoc.c         | 13 +++++++++++++
 2 files changed, 14 insertions(+)
include/hw/riscv/microchip_pfsoc.h +1 -0
index a30b944afa..612fd2b69c 100644
@@ -90,6 +90,7 @@ enum {
     MICROCHIP_PFSOC_L2CC,
     MICROCHIP_PFSOC_DMA,
     MICROCHIP_PFSOC_L2LIM,
+    MICROCHIP_PFSOC_L2ZERO,
     MICROCHIP_PFSOC_PLIC,
     MICROCHIP_PFSOC_MMUART0,
     MICROCHIP_PFSOC_WDOG0,
hw/riscv/microchip_pfsoc.c +13 -0
index c6b76fa3c2..a91ca951de 100644
@@ -97,6 +97,7 @@ static const MemMapEntry microchip_pfsoc_memmap[] = {
     [MICROCHIP_PFSOC_L2CC] =            {  0x2010000,       0x1000 },
     [MICROCHIP_PFSOC_DMA] =             {  0x3000000,     0x100000 },
     [MICROCHIP_PFSOC_L2LIM] =           {  0x8000000,     0x200000 },
+    [MICROCHIP_PFSOC_L2ZERO] =          {  0xa000000,     0x200000 },
     [MICROCHIP_PFSOC_PLIC] =            {  0xc000000,    0x4000000 },
     [MICROCHIP_PFSOC_MMUART0] =         { 0x20000000,       0x1000 },
     [MICROCHIP_PFSOC_WDOG0] =           { 0x20001000,       0x1000 },
@@ -201,6 +202,7 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
     MemoryRegion *rsvd0_mem = g_new(MemoryRegion, 1);
     MemoryRegion *e51_dtim_mem = g_new(MemoryRegion, 1);
     MemoryRegion *l2lim_mem = g_new(MemoryRegion, 1);
+    MemoryRegion *l2zero_mem = g_new(MemoryRegion, 1);
     MemoryRegion *envm_data = g_new(MemoryRegion, 1);
     MemoryRegion *qspi_xip_mem = g_new(MemoryRegion, 1);
     char *plic_hart_config;
@@ -278,6 +280,17 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
                                 memmap[MICROCHIP_PFSOC_L2LIM].base,
                                 l2lim_mem);
 
+    /*
+     * HSS decompresses into the L2 zero-device window and executes there.
+     * Model it as RAM because QEMU does not model the backing L2 cache.
+     */
+    memory_region_init_ram(l2zero_mem, NULL, "microchip.pfsoc.l2zero",
+                           memmap[MICROCHIP_PFSOC_L2ZERO].size,
+                           &error_fatal);
+    memory_region_add_subregion(system_memory,
+                                memmap[MICROCHIP_PFSOC_L2ZERO].base,
+                                l2zero_mem);
+
     /* create PLIC hart topology configuration string */
     plic_hart_config = riscv_plic_hart_config_string(ms->smp.cpus);
 
Signature · 1 line
2.53.0
author
#19 lore raw

PATCH v5 12/26 hw/riscv: pfsoc: Enable 64-bit SDHCI system bus support

In reply to Bin Meng

PolarFire SoC software selects 64-bit ADMA descriptors for the Cadence SDHCI controller. The controller supports those descriptors, but the Cadence property remains disabled by default for other integrations.

Enable the bus64bit property from the PolarFire SoC so the generic SDHCI descriptor engine can execute 64-bit ADMA transfers.

---

(no changes since v2)

Changes in v2:
- New

 hw/riscv/microchip_pfsoc.c | 2 ++
 1 file changed, 2 insertions(+)
hw/riscv/microchip_pfsoc.c +2 -0
index d7613496f8..6d943a224b 100644
@@ -194,6 +194,8 @@ static void microchip_pfsoc_soc_instance_init(Object *obj)
 
     object_initialize_child(obj, "sd-controller", &s->sdhci,
                             TYPE_CADENCE_SDHCI);
+    object_property_set_bool(OBJECT(&s->sdhci), "bus64bit", true,
+                             &error_abort);
 
     object_initialize_child(obj, "ioscb", &s->ioscb, TYPE_MCHP_PFSOC_IOSCB);
 }
Signature · 1 line
2.53.0
author
#4 lore raw

PATCH v5 4/26 hw/misc: Add SiFive L2 cache controller model

In reply to Bin Meng

FU540 and PolarFire use the same SiFive L2 configuration and way-control interface. Implement Config, monotonic WayEnable, and indexed WayMask registers with a configurable master count for the 21-master FU540 and 15-master PolarFire integrations.

Own the fixed 2 MiB SRAM backing inside the controller and expose the remaining LIM ways through a resizable alias. Also expose a separately sized L2 Zero window backed by RAM to approximate scratchpad accesses. The Zero aperture is independent of the cache/LIM way partition; cache allocation, replacement, coherence, and ECC remain unimplemented.

Export register, LIM, and Zero windows for the SoC to map.

---

Changes in v5:
- Select REGISTER to fix riscv32-softmmu link failures

Changes in v3:
- Name the QOM parent field parent_obj
- Move the LIM and Zero windows into L2CC
- Use the shared SiFive name and indexed WayMask registers
- Parameterize master count and the RAM-backed Zero aperture
- Resize a LIM alias while keeping its SRAM backing fixed

Changes in v2:
- Use the Resettable API instead of a legacy reset handler

 include/hw/misc/sifive_l2cc.h |  42 +++++
 hw/misc/sifive_l2cc.c         | 282 ++++++++++++++++++++++++++++++++++
 hw/misc/Kconfig               |   4 +
 hw/misc/meson.build           |   1 +
 4 files changed, 329 insertions(+)
 create mode 100644 include/hw/misc/sifive_l2cc.h
 create mode 100644 hw/misc/sifive_l2cc.c
include/hw/misc/sifive_l2cc.h new file +42 -0
new file mode 100644
index 0000000000..b1cd9c4054
@@ -0,0 +1,42 @@
+/*
+ * SiFive L2 cache controller
+ *
+ * Copyright (c) 2026 Process Mission
+ *
+ * Author:
+ *   Bin Meng <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef SIFIVE_L2CC_H
+#define SIFIVE_L2CC_H
+
+#include "hw/core/register.h"
+#include "hw/core/sysbus.h"
+
+#define SIFIVE_L2CC_REG_SIZE    0x1000
+#define SIFIVE_L2CC_REG_NUM     (SIFIVE_L2CC_REG_SIZE / 8)
+#define SIFIVE_L2CC_MAX_MASTERS 21
+
+enum {
+    SIFIVE_L2CC_MMIO_REGS,
+    SIFIVE_L2CC_MMIO_LIM,
+    SIFIVE_L2CC_MMIO_ZERO,
+};
+
+typedef struct SiFiveL2CCState {
+    SysBusDevice parent_obj;
+    uint64_t regs[SIFIVE_L2CC_REG_NUM];
+    RegisterInfo regs_info[SIFIVE_L2CC_REG_NUM];
+    MemoryRegion lim_ram;
+    MemoryRegion lim;
+    MemoryRegion zero;
+    uint32_t num_masters;
+    uint64_t zero_size;
+} SiFiveL2CCState;
+
+#define TYPE_SIFIVE_L2CC "sifive.l2cc"
+OBJECT_DECLARE_SIMPLE_TYPE(SiFiveL2CCState, SIFIVE_L2CC)
+
+#endif
hw/misc/sifive_l2cc.c new file +282 -0

282 lines not on this page · raw message

hw/misc/Kconfig +4 -0
index 685b7ff1e7..9bd417af82 100644
@@ -239,6 +239,10 @@ config MCHP_PFSOC_IOSCB
 config MCHP_PFSOC_SYSREG
     bool
 
+config SIFIVE_L2CC
+    bool
+    select REGISTER
+
 config SIFIVE_TEST
     bool
 
hw/misc/meson.build +1 -0
index fc3800baec..a1118e583f 100644
@@ -33,6 +33,7 @@ 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'))
+system_ss.add(when: 'CONFIG_SIFIVE_L2CC', if_true: files('sifive_l2cc.c'))
 system_ss.add(when: 'CONFIG_SIFIVE_TEST', if_true: files('sifive_test.c'))
 system_ss.add(when: 'CONFIG_SIFIVE_E_PRCI', if_true: files('sifive_e_prci.c'))
 system_ss.add(when: 'CONFIG_SIFIVE_E_AON', if_true: files('sifive_e_aon.c'))
Signature · 1 line
2.53.0
author
#1 lore raw

PATCH v5 1/26 hw/riscv: pfsoc: Correct the L2LIM maximum mapped size

In reply to Bin Meng

PolarFire SoC has a 2MiB L2 cache, so the maximum mapped size of L2LIM should be set to 2MiB too.

---

(no changes since v1)

 hw/riscv/microchip_pfsoc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/riscv/microchip_pfsoc.c +1 -1
index 27c7c42231..c6b76fa3c2 100644
@@ -96,7 +96,7 @@ static const MemMapEntry microchip_pfsoc_memmap[] = {
     [MICROCHIP_PFSOC_CLINT] =           {  0x2000000,      0x10000 },
     [MICROCHIP_PFSOC_L2CC] =            {  0x2010000,       0x1000 },
     [MICROCHIP_PFSOC_DMA] =             {  0x3000000,     0x100000 },
-    [MICROCHIP_PFSOC_L2LIM] =           {  0x8000000,    0x2000000 },
+    [MICROCHIP_PFSOC_L2LIM] =           {  0x8000000,     0x200000 },
     [MICROCHIP_PFSOC_PLIC] =            {  0xc000000,    0x4000000 },
     [MICROCHIP_PFSOC_MMUART0] =         { 0x20000000,       0x1000 },
     [MICROCHIP_PFSOC_WDOG0] =           { 0x20001000,       0x1000 },
Signature · 1 line
2.53.0
author
#8 lore raw

PATCH v5 6/26 hw/riscv: sifive_u: Correct the L2LIM maximum mapped size

In reply to Bin Meng

FU540 SoC has a 2MiB L2 cache, so the maximum mapped size of L2LIM should be set to 2MiB too.

---

(no changes since v3)

Changes in v3:
- New

 hw/riscv/sifive_u.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/riscv/sifive_u.c +1 -1
index b7d5e7b4da..1ac0d1bbd9 100644
@@ -72,7 +72,7 @@ static const MemMapEntry sifive_u_memmap[] = {
     [SIFIVE_U_DEV_CLINT] =    {  0x2000000,    0x10000 },
     [SIFIVE_U_DEV_L2CC] =     {  0x2010000,     0x1000 },
     [SIFIVE_U_DEV_PDMA] =     {  0x3000000,   0x100000 },
-    [SIFIVE_U_DEV_L2LIM] =    {  0x8000000,  0x2000000 },
+    [SIFIVE_U_DEV_L2LIM] =    {  0x8000000,   0x200000 },
     [SIFIVE_U_DEV_PLIC] =     {  0xc000000,  0x4000000 },
     [SIFIVE_U_DEV_PRCI] =     { 0x10000000,     0x1000 },
     [SIFIVE_U_DEV_UART0] =    { 0x10010000,     0x1000 },
Signature · 1 line
2.53.0
author
#3 lore raw

PATCH v5 3/26 hw/misc: pfsoc: Support DDR training with newer HSS

In reply to Bin Meng

HSS v2024.06 performs DDR and SGMII initialization through the DMC register window before it can complete platform startup. The existing model, which was validated against older version HSS in the early days, exposes only a few fixed training results, so newer version HSS stalls while waiting for PVT, PLL, DLL, ADDCMD, and verification status.

Update the DMC model by adding the minimum state and status behavior needed by that firmware flow. Model the SGMII control registers, main DDR PLL lock, deterministic ADDCMD transitions, and successful gate and DQ/DQS verification. Keep training progress and writable controls per device and clear them on reset.

These values are compatibility responses for HSS v2024.06 rather than a cycle-accurate description of the DDR PHY. Document that limitation in the source.

While we are here, update the license text to use the SPDX format.

Note at the time being there is an HSS bug [1] that consistenly blocks the DDR traning from succeed when using an HSS image built from certain version compiler like GCC 8.3.0. A patch [2] was proposed and verified against HSS v2024.06.

[1] https://github.com/polarfire-soc/platform/issues/36
[2] https://github.com/processmission/qemu-machine-images/blob/main/
machine/riscv64/microchip-icicle-kit/ 0001-mpfs_hal-preserve-DDR-pattern-test-parameters.patch

---

(no changes since v2)

Changes in v2:
- Use the Resettable API instead of a legacy reset handler

 include/hw/misc/mchp_pfsoc_dmc.h |   6 +
 hw/misc/mchp_pfsoc_dmc.c         | 273 ++++++++++++++++++++++++++++---
 2 files changed, 255 insertions(+), 24 deletions(-)
include/hw/misc/mchp_pfsoc_dmc.h +6 -0
index 2ed582fb8c..6a1986c2c2 100644
@@ -28,10 +28,16 @@
 /* DDR SGMII PHY module */
 
 #define MCHP_PFSOC_DDR_SGMII_PHY_REG_SIZE   0x1000
+#define MCHP_PFSOC_DDR_SGMII_PHY_REG_NUM \
+    (MCHP_PFSOC_DDR_SGMII_PHY_REG_SIZE / sizeof(uint32_t))
 
 typedef struct MchpPfSoCDdrSgmiiPhyState {
     SysBusDevice parent;
     MemoryRegion sgmii_phy;
+    uint32_t regs[MCHP_PFSOC_DDR_SGMII_PHY_REG_NUM];
+    uint8_t training_status_bit;
+    uint8_t addcmd_tap;
+    bool addcmd_move_active;
 } MchpPfSoCDdrSgmiiPhyState;
 
 #define TYPE_MCHP_PFSOC_DDR_SGMII_PHY "mchp.pfsoc.ddr_sgmii_phy"
hw/misc/mchp_pfsoc_dmc.c +249 -24

329 lines not on this page · raw message

Signature · 1 line
2.53.0
author
#25 lore raw

PATCH v5 17/26 hw/misc: pfsoc: Honor service notification requests

In reply to Bin Meng

Polling firmware requests system services with REQUEST set and NOTIFY clear. Raising PLIC source 96 for those requests leaves an interrupt pending that Linux can receive before submitting its first request. The mailbox interrupt handler then has no response buffer to fill.

Raise the completion interrupt only for requests with NOTIFY set. The serial-number service already checks REQUEST before processing a command.

Fixes 592f0a9429b9 ("hw/{misc, riscv}: pfsoc: add system controller as unimplemented")

---

(no changes since v3)

Changes in v3:
- Split the NOTIFY fix from interrupt acknowledgement wiring

 hw/misc/mchp_pfsoc_ioscb.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/misc/mchp_pfsoc_ioscb.c +3 -1
index 850125c8b4..bde1917c10 100644
@@ -247,7 +247,9 @@ static void services_cr_write(MchpPfSoCIoscbState *s, uint32_t value)
     }
 
     s->services_sr = status << SERVICES_SR_STATUS_SHIFT;
-    qemu_irq_raise(s->irq);
+    if (value & SERVICES_CR_NOTIFY) {
+        qemu_irq_raise(s->irq);
+    }
 }
 
 static uint64_t mchp_pfsoc_ctrl_read(void *opaque, hwaddr offset,
Signature · 1 line
2.53.0
author
#17 lore raw

PATCH v5 11/26 hw/sd: cadence: Add 64-bit system bus property

In reply to Bin Meng

Cadence SDHCI integrations can differ in whether they provide a 64-bit system bus. Advertising the capability unconditionally could make a guest select unsupported ADMA descriptors.

Add a bus64bit property to the Cadence model and keep it disabled by default. When enabled, expose the corresponding capability through the generic SDHCI child.

---

(no changes since v2)

Changes in v2:
- Make 64-bit system bus support a device property

 include/hw/sd/cadence_sdhci.h |  1 +
 hw/sd/cadence_sdhci.c         | 11 +++++++++++
 2 files changed, 12 insertions(+)
include/hw/sd/cadence_sdhci.h +1 -0
index cd8288b7d8..553fa73842 100644
@@ -34,6 +34,7 @@ typedef struct CadenceSDHCIState {
     MemoryRegion container;
     MemoryRegion iomem;
     BusState *bus;
+    bool bus64bit;
 
     uint32_t regs[CADENCE_SDHCI_NUM_REGS];
 
hw/sd/cadence_sdhci.c +11 -0
index 8476baf67f..875823a50d 100644
@@ -25,6 +25,7 @@
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "migration/vmstate.h"
+#include "hw/core/qdev-properties.h"
 #include "hw/sd/cadence_sdhci.h"
 #include "sdhci-internal.h"
 
@@ -147,6 +148,11 @@ static void cadence_sdhci_realize(DeviceState *dev, Error **errp)
                           s, TYPE_CADENCE_SDHCI, CADENCE_SDHCI_REG_SIZE);
     memory_region_add_subregion(&s->container, 0, &s->iomem);
 
+    if (s->bus64bit) {
+        object_property_set_uint(OBJECT(&s->sdhci), "capareg",
+                                 SDHC_CAPAB_REG_DEFAULT |
+                                 R_SDHC_CAPAB_BUS64BIT_MASK, &error_abort);
+    }
     sysbus_realize(sbd_sdhci, errp);
     memory_region_add_subregion(&s->container, CADENCE_SDHCI_SRS_BASE,
                                 sysbus_mmio_get_region(sbd_sdhci, 0));
@@ -165,6 +171,10 @@ static const VMStateDescription vmstate_cadence_sdhci = {
     },
 };
 
+static const Property cadence_sdhci_properties[] = {
+    DEFINE_PROP_BOOL("bus64bit", CadenceSDHCIState, bus64bit, false),
+};
+
 static void cadence_sdhci_class_init(ObjectClass *classp, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(classp);
@@ -172,6 +182,7 @@ static void cadence_sdhci_class_init(ObjectClass *classp, const void *data)
     dc->desc = "Cadence SD/SDIO/eMMC Host Controller (SD4HC)";
     dc->realize = cadence_sdhci_realize;
     device_class_set_legacy_reset(dc, cadence_sdhci_reset);
+    device_class_set_props(dc, cadence_sdhci_properties);
     dc->vmsd = &vmstate_cadence_sdhci;
 }
 
Signature · 1 line
2.53.0
author
#22 lore raw

PATCH v5 15/26 tests/qtest: Add PolarFire SoC RTC coverage

In reply to Bin Meng

Exercise RTC register masks, binary counter, upload and stop controls, alarm and wakeup interrupt behavior, reset state, and PLIC wiring on the Icicle Kit.

Also verify RTC state and pending interrupt migration, including streams from QEMU versions that predate the RTC device.

---

(no changes since v2)

Changes in v2:
- Expect the documented hardware state after RTC reset

 MAINTAINERS                       |   1 +
 tests/qtest/mchp_pfsoc_rtc_test.c | 315 ++++++++++++++++++++++++++++++
 tests/qtest/meson.build           |   5 +-
 3 files changed, 320 insertions(+), 1 deletion(-)
 create mode 100644 tests/qtest/mchp_pfsoc_rtc_test.c
MAINTAINERS +1 -0
index a4e33654ef..a8343e3d55 100644
@@ -1834,6 +1834,7 @@ F: include/hw/misc/mchp_pfsoc_dmc.h
 F: include/hw/misc/mchp_pfsoc_ioscb.h
 F: include/hw/misc/mchp_pfsoc_sysreg.h
 F: include/hw/rtc/mchp_pfsoc_rtc.h
+F: tests/qtest/mchp_pfsoc_rtc_test.c
 
 Shakti C class SoC
 L: [email protected]
tests/qtest/mchp_pfsoc_rtc_test.c new file +315 -0

315 lines not on this page · raw message

tests/qtest/meson.build +4 -1
index d08fbc1eb7..3fe0786af2 100644
@@ -318,7 +318,8 @@ qtests_riscv32 = \
 qtests_riscv64 = ['riscv-csr-test'] + \
   (unpack_edk2_blobs ? ['bios-tables-test'] : []) + \
   (config_all_devices.has_key('CONFIG_MICROCHIP_PFSOC') ?
-   ['cadence-sdhci-test'] : []) + \
+   ['cadence-sdhci-test',
+    'mchp_pfsoc_rtc_test'] : []) + \
   (config_all_devices.has_key('CONFIG_SIFIVE_L2CC') ? ['sifive_l2cc_test'] : []) + \
   (config_all_devices.has_key('CONFIG_IOMMU_TESTDEV') and
    config_all_devices.has_key('CONFIG_RISCV_IOMMU') ?
@@ -443,6 +444,8 @@ qtests = {
   'migration-test': test_migration_files + migration_tls_files + migration_colo_files,
   'sifive_l2cc_test': files('migration/migration-qmp.c',
                            'migration/migration-util.c'),
+  'mchp_pfsoc_rtc_test': files('migration/migration-qmp.c',
+                               'migration/migration-util.c'),
   'pxe-test': files('boot-sector.c'),
   'pnv-xive2-test': files('pnv-xive2-common.c', 'pnv-xive2-flush-sync.c',
                           'pnv-xive2-nvpg_bar.c'),
Signature · 1 line
2.53.0
author
#28 lore raw

PATCH v5 19/26 hw/riscv: pfsoc: Correct PolarFire SoC DDR aliases

In reply to Bin Meng

The Icicle Kit reference design maps the 32-bit cached and non-cached windows and both 64-bit windows to the same physical DDR from offset zero. The MSS Configurator User Guide describes configurable physical DDR offsets, so other FPGA designs can instead arrange these regions sequentially when their device trees describe that layout.

QEMU models the reference design used by the tested HSS and Linux images. Treating the high windows as only the portion above 1 GiB leaves their valid memory nodes unbacked with the board's 2 GiB of DDR. Map both high windows over the full machine RAM and qualify the source comment to describe this reference-design configuration.

---

(no changes since v3)

Changes in v3:
- Update commit message to mention the DDR aliases is modeled following the Icicle Kit reference design

 hw/riscv/microchip_pfsoc.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
hw/riscv/microchip_pfsoc.c +17 -3
index 63cec48f43..55ce1ac7da 100644
@@ -555,15 +555,29 @@ static void microchip_icicle_kit_machine_init(MachineState *machine)
                             TYPE_MICROCHIP_PFSOC);
     qdev_realize(DEVICE(&s->soc), NULL, &error_fatal);
 
-    /* Split RAM into low and high regions using aliases to machine->ram */
+    /*
+     * Model the Icicle Kit reference design, whose four CPU-visible windows
+     * alias the same physical DDR from offset zero. With 2 GiB of DDR, they
+     * map as follows:
+     *
+     * CPU address     Attribute           Visible size   DDR range
+     * 0x0080000000    32-bit cached       1 GiB          [0, 1 GiB)
+     * 0x00c0000000    32-bit non-cached   1 GiB          [0, 1 GiB)
+     * 0x1000000000    64-bit cached       2 GiB          [0, 2 GiB)
+     * 0x1400000000    64-bit non-cached   2 GiB          [0, 2 GiB)
+     *
+     * "Low" and "high" describe the CPU address windows, not the lower and
+     * upper portions of physical DDR. Other FPGA designs can configure
+     * different physical offsets through the MSS segmentation registers.
+     */
     mem_low_size = memmap[MICROCHIP_PFSOC_DRAM_LO].size;
-    mem_high_size = machine->ram_size - mem_low_size;
+    mem_high_size = machine->ram_size;
     memory_region_init_alias(mem_low, NULL,
                              "microchip.icicle.kit.ram_low", machine->ram,
                              0, mem_low_size);
     memory_region_init_alias(mem_high, NULL,
                              "microchip.icicle.kit.ram_high", machine->ram,
-                             mem_low_size, mem_high_size);
+                             0, mem_high_size);
 
     /* Register RAM */
     memory_region_add_subregion(system_memory,
Signature · 1 line
2.53.0
author
#21 lore raw

PATCH v5 14/26 hw/riscv: pfsoc: Add PolarFire SoC RTC to Icicle Kit

In reply to Bin Meng

The Icicle Kit memory map advertises the PolarFire RTC, but the machine leaves its MMIO range unmapped. Linux faults when it programs the RTC prescaler during boot.

Select and instantiate the RTC, map it at the documented address, and wire its wakeup and match outputs to PLIC interrupts 80 and 81.

---

(no changes since v1)

 include/hw/riscv/microchip_pfsoc.h |  4 ++++
 hw/riscv/microchip_pfsoc.c         | 11 +++++++++++
 hw/riscv/Kconfig                   |  1 +
 3 files changed, 16 insertions(+)
include/hw/riscv/microchip_pfsoc.h +4 -0
index 18f5003850..5827d6be2f 100644
@@ -31,6 +31,7 @@
 #include "hw/misc/mchp_pfsoc_ioscb.h"
 #include "hw/misc/mchp_pfsoc_sysreg.h"
 #include "hw/net/cadence_gem.h"
+#include "hw/rtc/mchp_pfsoc_rtc.h"
 #include "hw/sd/cadence_sdhci.h"
 #include "hw/riscv/riscv_hart.h"
 
@@ -53,6 +54,7 @@ typedef struct MicrochipPFSoCState {
     MchpPfSoCMMUartState *serial2;
     MchpPfSoCMMUartState *serial3;
     MchpPfSoCMMUartState *serial4;
+    MchpPfSoCRtcState rtc;
     MchpPfSoCSysregState sysreg;
     SiFivePDMAState dma;
     CadenceGEMState gem0;
@@ -148,6 +150,8 @@ enum {
     MICROCHIP_PFSOC_DMA_IRQ7 = 12,
     MICROCHIP_PFSOC_GEM0_IRQ = 64,
     MICROCHIP_PFSOC_GEM1_IRQ = 70,
+    MICROCHIP_PFSOC_RTC_WAKEUP_IRQ = 80,
+    MICROCHIP_PFSOC_RTC_MATCH_IRQ = 81,
     MICROCHIP_PFSOC_EMMC_SD_IRQ = 88,
     MICROCHIP_PFSOC_MMUART0_IRQ = 90,
     MICROCHIP_PFSOC_MMUART1_IRQ = 91,
hw/riscv/microchip_pfsoc.c +11 -0
index 6d943a224b..55ca8a244a 100644
@@ -184,6 +184,8 @@ static void microchip_pfsoc_soc_instance_init(Object *obj)
     object_initialize_child(obj, "sysreg", &s->sysreg,
                             TYPE_MCHP_PFSOC_SYSREG);
 
+    object_initialize_child(obj, "rtc", &s->rtc, TYPE_MCHP_PFSOC_RTC);
+
     object_initialize_child(obj, "ddr-sgmii-phy", &s->ddr_sgmii_phy,
                             TYPE_MCHP_PFSOC_DDR_SGMII_PHY);
     object_initialize_child(obj, "ddr-cfg", &s->ddr_cfg,
@@ -294,6 +296,15 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
         memmap[MICROCHIP_PFSOC_PLIC].size);
     g_free(plic_hart_config);
 
+    /* RTC */
+    sysbus_realize(SYS_BUS_DEVICE(&s->rtc), errp);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->rtc), 0,
+                    memmap[MICROCHIP_PFSOC_RTC].base);
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->rtc), 0,
+        qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_RTC_WAKEUP_IRQ));
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->rtc), 1,
+        qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_RTC_MATCH_IRQ));
+
     /* DMA */
     sysbus_realize(SYS_BUS_DEVICE(&s->dma), errp);
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->dma), 0,
hw/riscv/Kconfig +1 -0
index 19c6667ed6..147a02a49f 100644
@@ -19,6 +19,7 @@ config MICROCHIP_PFSOC
     select MCHP_PFSOC_DMC
     select MCHP_PFSOC_IOSCB
     select MCHP_PFSOC_MMUART
+    select MCHP_PFSOC_RTC
     select MCHP_PFSOC_SYSREG
     select RISCV_ACLINT
     select SIFIVE_L2CC
Signature · 1 line
2.53.0
author
#10 lore raw

PATCH v5 7/26 hw/riscv: sifive_u: Use the shared SiFive L2 cache controller

In reply to Bin Meng

FU540 and PolarFire use the same L2 configuration and way-control interface, with different master counts. The sifive_u machine currently leaves L2CC unimplemented and exposes L2-LIM as fixed RAM without WayEnable control.

Instantiate the shared SiFive L2CC with 21 masters and a modeled 2 MiB Zero window.

---

(no changes since v3)

Changes in v3:
- New

 docs/system/riscv/sifive_u.rst |  2 +-
 include/hw/riscv/sifive_u.h    |  3 +++
 hw/riscv/sifive_u.c            | 30 +++++++++++++-----------------
 hw/riscv/Kconfig               |  1 +
 4 files changed, 18 insertions(+), 18 deletions(-)
docs/system/riscv/sifive_u.rst +1 -1
index 0e4dcf3e70..e91853ffe2 100644
@@ -14,7 +14,7 @@ The ``sifive_u`` machine supports the following devices:
 * Core Local Interruptor (CLINT)
 * Platform-Level Interrupt Controller (PLIC)
 * Power, Reset, Clock, Interrupt (PRCI)
-* L2 Loosely Integrated Memory (L2-LIM)
+* L2 cache controller, including L2-LIM and L2-Zero windows
 * DDR memory controller
 * 2 UARTs
 * 1 GEM Ethernet controller
include/hw/riscv/sifive_u.h +3 -0
index aed966a62d..be5e6232ce 100644
@@ -28,6 +28,7 @@
 #include "hw/gpio/sifive_gpio.h"
 #include "hw/misc/sifive_u_otp.h"
 #include "hw/misc/sifive_u_prci.h"
+#include "hw/misc/sifive_l2cc.h"
 #include "hw/ssi/sifive_spi.h"
 #include "hw/timer/sifive_pwm.h"
 
@@ -45,6 +46,7 @@ typedef struct SiFiveUSoCState {
     RISCVHartArrayState e_cpus;
     RISCVHartArrayState u_cpus;
     DeviceState *plic;
+    SiFiveL2CCState l2cc;
     SiFiveUPRCIState prci;
     SIFIVEGPIOState gpio;
     SiFiveUOTPState otp;
@@ -82,6 +84,7 @@ enum {
     SIFIVE_U_DEV_L2CC,
     SIFIVE_U_DEV_PDMA,
     SIFIVE_U_DEV_L2LIM,
+    SIFIVE_U_DEV_L2ZERO,
     SIFIVE_U_DEV_PLIC,
     SIFIVE_U_DEV_PRCI,
     SIFIVE_U_DEV_UART0,
hw/riscv/sifive_u.c +13 -17
index 1ac0d1bbd9..3603cc2aa2 100644
@@ -73,6 +73,7 @@ static const MemMapEntry sifive_u_memmap[] = {
     [SIFIVE_U_DEV_L2CC] =     {  0x2010000,     0x1000 },
     [SIFIVE_U_DEV_PDMA] =     {  0x3000000,   0x100000 },
     [SIFIVE_U_DEV_L2LIM] =    {  0x8000000,   0x200000 },
+    [SIFIVE_U_DEV_L2ZERO] =   {  0xa000000,   0x200000 },
     [SIFIVE_U_DEV_PLIC] =     {  0xc000000,  0x4000000 },
     [SIFIVE_U_DEV_PRCI] =     { 0x10000000,     0x1000 },
     [SIFIVE_U_DEV_UART0] =    { 0x10010000,     0x1000 },
@@ -715,6 +716,10 @@ static void sifive_u_soc_instance_init(Object *obj)
     object_initialize_child(obj, "gem", &s->gem, TYPE_CADENCE_GEM);
     object_initialize_child(obj, "gpio", &s->gpio, TYPE_SIFIVE_GPIO);
     object_initialize_child(obj, "pdma", &s->dma, TYPE_SIFIVE_PDMA);
+    object_initialize_child(obj, "l2-cache-controller", &s->l2cc,
+                            TYPE_SIFIVE_L2CC);
+    qdev_prop_set_uint64(DEVICE(&s->l2cc), "zero-size",
+                         sifive_u_memmap[SIFIVE_U_DEV_L2ZERO].size);
     object_initialize_child(obj, "spi0", &s->spi0, TYPE_SIFIVE_SPI);
     object_initialize_child(obj, "spi2", &s->spi2, TYPE_SIFIVE_SPI);
     object_initialize_child(obj, "pwm0", &s->pwm[0], TYPE_SIFIVE_PWM);
@@ -728,7 +733,6 @@ static void sifive_u_soc_realize(DeviceState *dev, Error **errp)
     const MemMapEntry *memmap = sifive_u_memmap;
     MemoryRegion *system_memory = get_system_memory();
     MemoryRegion *mask_rom = g_new(MemoryRegion, 1);
-    MemoryRegion *l2lim_mem = g_new(MemoryRegion, 1);
     char *plic_hart_config;
     int i, j;
 
@@ -754,19 +758,14 @@ static void sifive_u_soc_realize(DeviceState *dev, Error **errp)
     memory_region_add_subregion(system_memory, memmap[SIFIVE_U_DEV_MROM].base,
                                 mask_rom);
 
-    /*
-     * 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, "riscv.sifive.u.l2lim",
-                           memmap[SIFIVE_U_DEV_L2LIM].size, &error_fatal);
-    memory_region_add_subregion(system_memory, memmap[SIFIVE_U_DEV_L2LIM].base,
-                                l2lim_mem);
+    /* L2 cache controller, LIM, and Zero windows */
+    sysbus_realize(SYS_BUS_DEVICE(&s->l2cc), &error_fatal);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->l2cc), SIFIVE_L2CC_MMIO_REGS,
+                    memmap[SIFIVE_U_DEV_L2CC].base);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->l2cc), SIFIVE_L2CC_MMIO_LIM,
+                    memmap[SIFIVE_U_DEV_L2LIM].base);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->l2cc), SIFIVE_L2CC_MMIO_ZERO,
+                    memmap[SIFIVE_U_DEV_L2ZERO].base);
 
     /* create PLIC hart topology configuration string */
     plic_hart_config = riscv_plic_hart_config_string(ms->smp.cpus);
@@ -868,9 +867,6 @@ static void sifive_u_soc_realize(DeviceState *dev, Error **errp)
     create_unimplemented_device("riscv.sifive.u.dmc",
         memmap[SIFIVE_U_DEV_DMC].base, memmap[SIFIVE_U_DEV_DMC].size);
 
-    create_unimplemented_device("riscv.sifive.u.l2cc",
-        memmap[SIFIVE_U_DEV_L2CC].base, memmap[SIFIVE_U_DEV_L2CC].size);
-
     sysbus_realize(SYS_BUS_DEVICE(&s->spi0), errp);
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi0), 0,
                     memmap[SIFIVE_U_DEV_QSPI0].base);
hw/riscv/Kconfig +1 -0
index a22ef994eb..19c6667ed6 100644
@@ -116,6 +116,7 @@ config SIFIVE_U
     select CPU_CLUSTER
     select DEVICE_TREE
     select RISCV_ACLINT
+    select SIFIVE_L2CC
     select SIFIVE_GPIO
     select SIFIVE_PDMA
     select SIFIVE_PLIC
Signature · 1 line
2.53.0
author
#37 lore raw

PATCH v5 24/26 tests/functional/riscv64: Add Icicle Kit firmware boot test

In reply to Bin Meng

Add functional coverage using the v1.1.1 HSS and SD card images.

Boot HSS v2026.04.1 and U-Boot with five harts and 2 GiB of RAM. Connect the test console to MMUART1 and let U-Boot start Linux.

The complete boot exercises the SDHCI controller in the DMA modes used at each stage. HSS uses Version 4 64-bit SDMA to load U-Boot. U-Boot uses ADMA2-64 to read the boot script and the large FIT image. Linux then selects 64-bit ADMA for SD card and rootfs I/O.

Check the machine identity, kernel ADMA initialization, root filesystem mount, and login prompt.

---

(no changes since v4)

Changes in v4:
- Use the v1.1.1 test images with HSS v2026.04.1
- Add the execution bit to the python script

 MAINTAINERS                                   |  1 +
 tests/functional/riscv64/meson.build          |  2 +
 .../riscv64/test_microchip_icicle_kit.py      | 56 +++++++++++++++++++
 3 files changed, 59 insertions(+)
 create mode 100755 tests/functional/riscv64/test_microchip_icicle_kit.py
MAINTAINERS +1 -0
index a8343e3d55..6c7437f8a5 100644
@@ -1834,6 +1834,7 @@ F: include/hw/misc/mchp_pfsoc_dmc.h
 F: include/hw/misc/mchp_pfsoc_ioscb.h
 F: include/hw/misc/mchp_pfsoc_sysreg.h
 F: include/hw/rtc/mchp_pfsoc_rtc.h
+F: tests/functional/riscv64/test_microchip_icicle_kit.py
 F: tests/qtest/mchp_pfsoc_rtc_test.c
 
 Shakti C class SoC
tests/functional/riscv64/meson.build +2 -0
index 211ea9acfc..231a1e49f6 100644
@@ -3,6 +3,7 @@
 test_riscv64_timeouts = {
   'boston' : 120,
   'k230' : 120,
+  'microchip_icicle_kit' : 180,
   'server_ref' : 120,
   'tuxrun' : 120,
 }
@@ -16,6 +17,7 @@ tests_riscv64_system_thorough = [
   'endianness',
   'boston',
   'k230',
+  'microchip_icicle_kit',
   'server_ref',
   'sifive_u',
   'tt_atlantis',
tests/functional/riscv64/test_microchip_icicle_kit.py new file +56 -0

56 lines not on this page · raw message

Signature · 1 line
2.53.0
author
#33 lore raw

PATCH v5 22/26 docs/system/riscv: Document Icicle Kit HSS boot

In reply to Bin Meng

With all previous changes, the Icicle Kit model is now able to boot HSS v2026.04.1 through a Buildroot 2026.05 SD image to U-Boot and Linux.

Document the tested source versions and exact commands to build HSS and Buildroot. Include the sparse resize and GPT relocation steps needed to make the generated SD image usable by QEMU.

Explain the pinned firmware baseline and include the DDR pattern-test patch used by the versioned test image. Document the tool check needed for image-only builds and distinguish the DDR training failure from the two investigated multi-hart startup races. Describe their visible symptoms, affected source versions, and all three DTB supply paths.

Also describe the RAM and serial setup, boot stages, and remaining model limitations.

---

(no changes since v4)

Changes in v4:
- Use HSS v2026.04.1 and the v1.1.1 test-image recipe
- Select the SoftConsole toolchain explicitly
- Use the generated complete boot-mode-1 eNVM binary

Changes in v3:
- Include the DDR pattern-test patch used by the functional-test image
- Document the image-only FPGA programming tool check
- Describe startup-race symptoms and link the firmware investigations

 docs/system/riscv/microchip-icicle-kit.rst | 129 ++++++++++++++++++++-
 1 file changed, 123 insertions(+), 6 deletions(-)
docs/system/riscv/microchip-icicle-kit.rst +123 -6
index 138289a913..2159e8e461 100644
@@ -19,12 +19,14 @@ The ``microchip-icicle-kit`` machine supports the following devices:
 * 4 U54 cores
 * Core Level Interruptor (CLINT)
 * Platform-Level Interrupt Controller (PLIC)
-* L2 Loosely Integrated Memory (L2-LIM)
+* L2 cache controller, including L2-LIM and L2-Zero windows
 * DDR memory controller
+* System controller and system services mailbox
 * 5 MMUARTs
 * 1 DMA controller
 * 2 GEM Ethernet controllers
 * 1 SDHC storage controller
+* 1 Real-Time Clock
 
 The machine has a fixed 2 GiB of RAM. Other memory sizes are rejected.
 The machine defaults to all five harts. ``-smp`` may select two to five harts,
@@ -103,10 +105,125 @@ CAVEATS:
 Running HSS
 -----------
 
-The machine ``microchip-icicle-kit`` used to run the Hart Software Services
-(HSS_), however, the HSS development progressed and the QEMU machine
-implementation lacks behind.  Currently, running the HSS no longer works.
-There is missing support in the clock and memory controller devices.  In
-particular, reading from the SD card does not work.
+The ``microchip-icicle-kit`` machine can boot the Hart Software Services
+(HSS_), which then loads an HSS payload containing U-Boot from an SD card.
+The following flow was tested with HSS v2026.04.1 and Buildroot 2026.05.
+These versions reproduce the firmware and SD card images used by the
+functional test.
+
+Configure HSS for the ``mpfs-icicle-kit-es`` board using its default
+configuration. QEMU provides the software-visible registers and deterministic
+status consumed by the HSS v2026.04.1 DDR initialization and training flow;
+it does not model the electrical properties of DDR training. HSS requires
+the RISC-V bare-metal toolchain supplied by Microchip SoftConsole to be
+available in ``PATH``.
+
+The versioned test image applies the `DDR pattern-test fix`_ before building
+HSS. Without this fix, the DDR state machine can reuse uninitialized
+pattern-test parameters across calls, particularly with the SoftConsole
+GCC 8.3.0 toolchain. Apply the same patch when reproducing the test image:
+
+.. code-block:: bash
+
+  $ git clone https://github.com/polarfire-soc/hart-software-services.git
+  $ cd hart-software-services
+  $ git checkout v2026.04.1
+  $ curl -L -o ddr-pattern-test.patch \
+      https://raw.githubusercontent.com/processmission/qemu-machine-images/v1.1.1/machine/riscv64/microchip-icicle-kit/0001-mpfs_hal-preserve-DDR-pattern-test-parameters.patch
+  $ git apply ddr-pattern-test.patch
+  $ cp boards/mpfs-icicle-kit-es/def_config .config
+  $ echo CONFIG_CC_USE_SOFTCONSOLE=y >> .config
+  $ FPGENPROG=/bin/true make -j$(nproc) BOARD=mpfs-icicle-kit-es
+
+``FPGENPROG=/bin/true`` satisfies the boot-mode programmer's FPGA programming
+tool check when generating an image for QEMU; no physical device is programmed.
+
+The HSS build creates the complete eNVM image, including the 256-byte
+boot header with the image size and per-hart reset vectors. Copy it to
+``build/hss.bin`` for the QEMU command below:
+
+.. code-block:: bash
+
+  $ cp build/bootmode1/hss-envm-wrapper-bm1-p0.bin build/hss.bin
+
+Do not pass ``build/hss-envm-wrapper.bin`` directly to QEMU. That file starts
+at eNVM offset 0x100 and does not contain the boot header with the image size
+and per-hart reset vectors.
+
+Build the SD card image with the tested Buildroot version:
+
+.. code-block:: bash
+
+  $ git clone https://gitlab.com/buildroot.org/buildroot.git
+  $ cd buildroot
+  $ git checkout 2026.05
+  $ make microchip_mpfs_icicle_defconfig
+  $ make
+
+This produces ``output/images/sdcard.img`` with three GPT partitions:
+
+* An HSS ``payload.bin`` containing U-Boot.
+* A FAT partition containing ``boot.scr`` and the kernel FIT image.
+* An ext4 Linux root filesystem.
+
+The QEMU SD card model requires a power-of-two image size. Make a sparse
+4 GiB working copy and relocate its backup GPT to the new end of the image:
+
+.. code-block:: bash
+
+  $ cp --reflink=auto output/images/sdcard.img sdcard.img
+  $ truncate -s 4G sdcard.img
+  $ sgdisk -e sdcard.img
+  $ sgdisk -v sdcard.img
+
+The Icicle Kit firmware device tree in the FIT image describes 2 GiB of RAM,
+matching the machine's fixed RAM size. The command below keeps ``-m 2G``
+explicit.  Attach the image as an SD card and route both board serial ports:
+
+.. code-block:: bash
+
+  $ qemu-system-riscv64 \
+      -M microchip-icicle-kit -smp 5 -m 2G \
+      -bios path/to/hss/build/hss.bin \
+      -drive if=sd,file=path/to/sdcard.img,format=raw \
+      -display none \
+      -serial file:hss.log \
+      -serial stdio \
+      -no-reboot
+
+HSS writes to MMUART0, which the command records in ``hss.log``. U-Boot and
+Linux use MMUART1, which remains connected to the terminal. A successful
+boot proceeds through HSS payload loading, U-Boot, the Linux kernel, and the
+login prompt from the root filesystem on the third partition.
+
+Known limitations
+-----------------
+
+* Two potential multi-hart startup races were reproduced with HSS v2024.06
+  under QEMU. The affected code paths are also present in the inspected
+  HSS v2026.04.1 sources; they have not been reproduced on physical hardware.
+  See `HSS startup races`_ for the investigation and affected source versions.
+
+  * In the eNVM wrapper, a late U54 can clear the decompression completion
+    flag after E51 has set it. A boot can stop before all harts enter HSS,
+    with the affected U54s waiting in ``wait_for_decompress_done``.
+  * After DDR training and payload loading, a U54 other than the configured
+    payload owner can win the OpenSBI coldboot lottery. With the minimal DTB
+    describing only ``cpu@1``, U-Boot on another hart can repeatedly print
+    ``Could not initialize timer (err -19)`` and ``resetting ...``.
+
+* Without the DDR pattern-test fix above, some GCC 8.3.0 builds remain at
+  60% DDR training progress while QEMU keeps running. This is a separate
+  firmware parameter-lifetime issue; see `DDR pattern-test issue`_.
+* The SD card model requires the raw image size to be a power of two. Keep
+  the backup GPT header at the end when resizing the image.
+* The machine does not generate an Icicle Kit device tree. Firmware boot can
+  obtain a DTB built into HSS, included in an HSS payload, or supplied by
+  subsequent software, such as U-Boot or a kernel FIT image. The DTB must
+  describe the selected hart topology and the modeled reference-design DDR
+  windows. Direct kernel boot must use ``-dtb`` as described above.
 
 .. _HSS: https://github.com/polarfire-soc/hart-software-services
+.. _DDR pattern-test fix: https://github.com/processmission/qemu-machine-images/blob/v1.1.1/machine/riscv64/microchip-icicle-kit/0001-mpfs_hal-preserve-DDR-pattern-test-parameters.patch
+.. _DDR pattern-test issue: https://github.com/polarfire-soc/platform/issues/36
+.. _HSS startup races: https://github.com/polarfire-soc/hart-software-services/issues/106
Signature · 1 line
2.53.0
author
#20 lore raw

PATCH v5 13/26 hw/rtc: Add PolarFire SoC RTC model

In reply to Bin Meng

The PolarFire SoC exposes an RTC with binary and calendar modes, programmable prescaling, alarms, and wakeup and match interrupts.

Add a standalone device model with explicit MMIO handling for time, commands, alarms, interrupt state, reset, and migration. Add its Kconfig and Meson entries and list it under the PolarFire SoC maintainer section.

Reset the device to its documented hardware values, with the binary counter stopped at zero.

---

(no changes since v2)

Changes in v2:
- Reset the RTC to the documented hardware values
- Use the Resettable API instead of a legacy reset handler

 MAINTAINERS                     |   2 +
 include/hw/rtc/mchp_pfsoc_rtc.h |  46 +++
 hw/rtc/mchp_pfsoc_rtc.c         | 477 ++++++++++++++++++++++++++++++++
 hw/rtc/Kconfig                  |   3 +
 hw/rtc/meson.build              |   1 +
 5 files changed, 529 insertions(+)
 create mode 100644 include/hw/rtc/mchp_pfsoc_rtc.h
 create mode 100644 hw/rtc/mchp_pfsoc_rtc.c
MAINTAINERS +2 -0
index 3c305d570f..a4e33654ef 100644
@@ -1827,11 +1827,13 @@ F: hw/char/mchp_pfsoc_mmuart.c
 F: hw/misc/mchp_pfsoc_dmc.c
 F: hw/misc/mchp_pfsoc_ioscb.c
 F: hw/misc/mchp_pfsoc_sysreg.c
+F: hw/rtc/mchp_pfsoc_rtc.c
 F: include/hw/riscv/microchip_pfsoc.h
 F: include/hw/char/mchp_pfsoc_mmuart.h
 F: include/hw/misc/mchp_pfsoc_dmc.h
 F: include/hw/misc/mchp_pfsoc_ioscb.h
 F: include/hw/misc/mchp_pfsoc_sysreg.h
+F: include/hw/rtc/mchp_pfsoc_rtc.h
 
 Shakti C class SoC
 L: [email protected]
include/hw/rtc/mchp_pfsoc_rtc.h new file +46 -0

46 lines not on this page · raw message

hw/rtc/mchp_pfsoc_rtc.c new file +477 -0

477 lines not on this page · raw message

hw/rtc/Kconfig +3 -0
index 315b0e4ecc..0d53546adc 100644
@@ -14,6 +14,9 @@ config M48T59
 config PL031
     bool
 
+config MCHP_PFSOC_RTC
+    bool
+
 config MC146818RTC
     depends on ISA_BUS
     bool
hw/rtc/meson.build +1 -0
index 6c87864dc0..4a666bfc94 100644
@@ -3,6 +3,7 @@ system_ss.add(when: 'CONFIG_DS1338', if_true: files('ds1338.c'))
 system_ss.add(when: 'CONFIG_M41T80', if_true: files('m41t80.c'))
 system_ss.add(when: 'CONFIG_M48T59', if_true: files('m48t59.c'))
 system_ss.add(when: 'CONFIG_PL031', if_true: files('pl031.c'))
+system_ss.add(when: 'CONFIG_MCHP_PFSOC_RTC', if_true: files('mchp_pfsoc_rtc.c'))
 system_ss.add(when: ['CONFIG_ISA_BUS', 'CONFIG_M48T59'], if_true: files('m48t59-isa.c'))
 system_ss.add(when: 'CONFIG_XLNX_ZYNQMP', if_true: files('xlnx-zynqmp-rtc.c'))
 
Signature · 1 line
2.53.0
author
#39 lore raw

PATCH v5 25/26 MAINTAINERS: Add PolarFire SoC Icicle Kit maintainer

In reply to Bin Meng

The preceding Icicle Kit updates restore HSS, U-Boot, and Linux boot. Functional test coverage is also added.

Restore myself as a maintainer and mark the machine as 'Supported' to reflect its active maintenance.

---

(no changes since v1)

 MAINTAINERS | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
MAINTAINERS +2 -1
index 6c7437f8a5..e50ebbe5d2 100644
@@ -1817,10 +1817,11 @@ F: target/riscv/xlrbr.decode
 F: tests/tcg/riscv64/test-crc32.S
 
 Microchip PolarFire SoC Icicle Kit
+M: Bin Meng <[email protected]>
 M: Conor Dooley <[email protected]>
 M: Sebastian Huber <[email protected]>
 L: [email protected]
-S: Odd Fixes
+S: Supported
 F: docs/system/riscv/microchip-icicle-kit.rst
 F: hw/riscv/microchip_pfsoc.c
 F: hw/char/mchp_pfsoc_mmuart.c
Signature · 1 line
2.53.0
author
#40 lore raw

PATCH v5 26/26 MAINTAINERS: Move Conor Dooley to PolarFire SoC reviewer

In reply to Bin Meng

Conor asked not to be listed as a maintainer, since that could imply that Microchip sponsors his work on the platform.

Keep him listed as a reviewer so he continues to receive relevant patches without suggesting an active maintenance commitment.

---

(no changes since v2)

Changes in v2:
- New

 MAINTAINERS | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
MAINTAINERS +1 -1
index e50ebbe5d2..54bf840cef 100644
@@ -1818,8 +1818,8 @@ F: tests/tcg/riscv64/test-crc32.S
 
 Microchip PolarFire SoC Icicle Kit
 M: Bin Meng <[email protected]>
-M: Conor Dooley <[email protected]>
 M: Sebastian Huber <[email protected]>
+R: Conor Dooley <[email protected]>
 L: [email protected]
 S: Supported
 F: docs/system/riscv/microchip-icicle-kit.rst
Signature · 1 line
2.53.0
author
#29 lore raw

PATCH v5 20/26 hw/riscv: pfsoc: Fix Icicle Kit RAM size at 2 GiB

In reply to Bin Meng

The Icicle Kit has 2 GiB of RAM, and its firmware device tree describes that fixed capacity. The model currently defaults to 1537 MiB and accepts any larger size, allowing configurations that do not match the board.

Set the default to 2 GiB and reject every other size. Update the documentation and L2CC qtest command line accordingly.

---

(no changes since v1)

 docs/system/riscv/microchip-icicle-kit.rst |  4 +---
 hw/riscv/microchip_pfsoc.c                 | 15 ++++-----------
 2 files changed, 5 insertions(+), 14 deletions(-)
docs/system/riscv/microchip-icicle-kit.rst +1 -3
index 7fdb96601a..b0ad24f174 100644
@@ -26,9 +26,7 @@ The ``microchip-icicle-kit`` machine supports the following devices:
 * 2 GEM Ethernet controllers
 * 1 SDHC storage controller
 
-The memory is set to 1537 MiB by default.  A sanity check on RAM size is
-performed in the machine init routine to prompt user to increase the RAM size
-to > 1537 MiB when less than 1537 MiB RAM is detected.
+The machine has a fixed 2 GiB of RAM. Other memory sizes are rejected.
 
 Boot options
 ------------
hw/riscv/microchip_pfsoc.c +4 -11
index 55ce1ac7da..f2a838be13 100644
@@ -542,10 +542,10 @@ static void microchip_icicle_kit_machine_init(MachineState *machine)
     DriveInfo *dinfo = drive_get(IF_SD, 0, 0);
     RISCVBootInfo boot_info;
 
-    /* Sanity check on RAM size */
-    if (machine->ram_size < mc->default_ram_size) {
+    /* The board has a fixed 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);
+        error_report("Invalid RAM size, should be %s", sz);
         g_free(sz);
         exit(EXIT_FAILURE);
     }
@@ -757,14 +757,7 @@ static void microchip_icicle_kit_machine_class_init(ObjectClass *oc,
     mc->default_ram_id = "microchip.icicle.kit.ram";
     mc->auto_create_sdcard = true;
 
-    /*
-     * Map 513 MiB high memory, the minimum required high memory size, because
-     * HSS will do memory test against the high memory address range regardless
-     * of physical memory installed.
-     *
-     * See memory_tests() in mss_ddr.c in the HSS source code.
-     */
-    mc->default_ram_size = 1537 * MiB;
+    mc->default_ram_size = 2 * GiB;
 
     object_class_property_add(oc, "clint-timebase-frequency", "uint32_t",
                               &uint32_type_info,
Signature · 1 line
2.53.0
author
#24 lore raw

PATCH v5 16/26 hw/misc: pfsoc: Model PolarFire SoC serial number service

In reply to Bin Meng

U-Boot requests the PolarFire SoC device serial number during board late initialization. The IOSCB previously rejected every request, so board setup could not complete.

Model the System Services control registers and byte-addressable mailbox. Obtain the 128-bit serial number from an optional device property, using a deterministic value when it is not configured. Return an explicit failure for unsupported services and reset the new runtime state with the rest of the device.

---

(no changes since v3)

Changes in v3:
- Decode the seven-bit opcode and nine-bit mailbox word offset
- Bound serial-number responses to the documented 2 KiB mailbox
- Mirror the current control flags in the status register
- Use default access sizing for the control and mailbox windows

 include/hw/misc/mchp_pfsoc_ioscb.h |   6 ++
 hw/misc/mchp_pfsoc_ioscb.c         | 156 +++++++++++++++++++++++++----
 2 files changed, 144 insertions(+), 18 deletions(-)
include/hw/misc/mchp_pfsoc_ioscb.h +6 -0
index 9687ea25b1..aa108d2d88 100644
@@ -25,6 +25,8 @@
 
 #include "hw/core/sysbus.h"
 
+#define MCHP_PFSOC_IOSCB_MAILBOX_SIZE 0x800
+
 typedef struct MchpPfSoCIoscbState {
     SysBusDevice parent;
     MemoryRegion container;
@@ -47,6 +49,10 @@ typedef struct MchpPfSoCIoscbState {
     MemoryRegion cfm_sgmii;
     MemoryRegion bc_sgmii;
     MemoryRegion io_calib_sgmii;
+    uint32_t services_cr;
+    uint32_t services_sr;
+    uint8_t mailbox_data[MCHP_PFSOC_IOSCB_MAILBOX_SIZE];
+    char *serial_number;
     qemu_irq irq;
 } MchpPfSoCIoscbState;
 
hw/misc/mchp_pfsoc_ioscb.c +138 -18

223 lines not on this page · raw message

Signature · 1 line
2.53.0
author
#31 lore raw

PATCH v5 21/26 hw/riscv: pfsoc: Default Icicle Kit to five harts

In reply to Bin Meng

The Icicle Kit contains one E51 management hart and four U54 application harts. Defaulting to two harts can accidentally boot firmware and a device tree that expect the full five-hart topology.

Default to all five harts, while retaining the existing two-to-five range for users intentionally configuring fewer application harts. Document that firmware and device trees must match the selected count.

---

(no changes since v3)

Changes in v3:
- Change only the default hart count and retain the minimum of two
- Document reduced topologies and matching firmware requirements

 docs/system/riscv/microchip-icicle-kit.rst | 3 +++
 hw/riscv/microchip_pfsoc.c                 | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)
docs/system/riscv/microchip-icicle-kit.rst +3 -0
index b0ad24f174..138289a913 100644
@@ -27,6 +27,9 @@ The ``microchip-icicle-kit`` machine supports the following devices:
 * 1 SDHC storage controller
 
 The machine has a fixed 2 GiB of RAM. Other memory sizes are rejected.
+The machine defaults to all five harts. ``-smp`` may select two to five harts,
+with one E51 and one to four U54 cores. The firmware and device tree must match
+the selected topology; the HSS boot flow below uses all five harts.
 
 Boot options
 ------------
hw/riscv/microchip_pfsoc.c +1 -1
index f2a838be13..90345aa262 100644
@@ -753,7 +753,7 @@ static void microchip_icicle_kit_machine_class_init(ObjectClass *oc,
     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_cpus = mc->max_cpus;
     mc->default_ram_id = "microchip.icicle.kit.ram";
     mc->auto_create_sdcard = true;
 
Signature · 1 line
2.53.0
author
#6 lore raw

PATCH v5 5/26 hw/riscv: pfsoc: Map the SiFive L2CC memory windows

In reply to Bin Meng

L2-LIM consists of cache SRAM ways controlled by L2CC WayEnable, and L2 Zero is the controller's scratchpad allocation interface. Creating their RAM stand-ins in the SoC and passing a LIM link splits ownership of the register state and the memory views it controls.

Instantiate the shared SiFive L2CC with 15 masters and the existing 2 MiB modeled Zero aperture. Let the controller own the backing and both windows, and map its register, LIM, and Zero regions from the SoC. Remove the external RAM allocations and the l2-lim link.

The device restores the visible LIM range after reset or migration. L2 Zero keeps its fixed aperture as a RAM approximation of scratchpad access rather than tracking the remaining LIM capacity.

---

(no changes since v3)

Changes in v3:
- Configure and instantiate the shared SiFive L2CC
- Map the register, LIM, and Zero windows exposed by the controller
- Remove the external RAM allocations and l2-lim link
- Keep the PolarFire master count and modeled Zero aperture unchanged

 include/hw/riscv/microchip_pfsoc.h |  2 ++
 hw/riscv/microchip_pfsoc.c         | 45 ++++++++++--------------------
 hw/riscv/Kconfig                   |  1 +
 3 files changed, 17 insertions(+), 31 deletions(-)
include/hw/riscv/microchip_pfsoc.h +2 -0
index 612fd2b69c..18f5003850 100644
@@ -27,6 +27,7 @@
 #include "hw/cpu/cluster.h"
 #include "hw/dma/sifive_pdma.h"
 #include "hw/misc/mchp_pfsoc_dmc.h"
+#include "hw/misc/sifive_l2cc.h"
 #include "hw/misc/mchp_pfsoc_ioscb.h"
 #include "hw/misc/mchp_pfsoc_sysreg.h"
 #include "hw/net/cadence_gem.h"
@@ -43,6 +44,7 @@ typedef struct MicrochipPFSoCState {
     RISCVHartArrayState e_cpus;
     RISCVHartArrayState u_cpus;
     DeviceState *plic;
+    SiFiveL2CCState l2cc;
     MchpPfSoCDdrSgmiiPhyState ddr_sgmii_phy;
     MchpPfSoCDdrCfgState ddr_cfg;
     MchpPfSoCIoscbState ioscb;
hw/riscv/microchip_pfsoc.c +14 -31

63 lines not on this page · raw message

hw/riscv/Kconfig +1 -0
index d89fdfcc86..a22ef994eb 100644
@@ -21,6 +21,7 @@ config MICROCHIP_PFSOC
     select MCHP_PFSOC_MMUART
     select MCHP_PFSOC_SYSREG
     select RISCV_ACLINT
+    select SIFIVE_L2CC
     select SIFIVE_PDMA
     select SIFIVE_PLIC
     select UNIMP
Signature · 1 line
2.53.0
author
#27 lore raw

PATCH v5 18/26 hw/misc: pfsoc: Let IOSCB own service interrupt state

In reply to Bin Meng

System service completion raises PLIC source 96 from IOSCB, while software accesses MESSAGE_INT through SYSREG. The MESSAGE_INT pending bit is not modelled explicitly, so reads return zero even when a service interrupt is active. Model the bit so service completion and register accesses use the same state.

Keep the pending state and PLIC output in IOSCB. Link SYSREG to IOSCB so MESSAGE_INT reads the current pending bit and writes update the same state.

---

(no changes since v3)

Changes in v3:
- Separate interrupt state ownership from the NOTIFY fix
- Link SYSREG to IOSCB for MESSAGE_INT reads and writes
- Support both clearing and setting the MESSAGE_INT pending bit

 include/hw/misc/mchp_pfsoc_ioscb.h  |  4 ++++
 include/hw/misc/mchp_pfsoc_sysreg.h |  3 ++-
 hw/misc/mchp_pfsoc_ioscb.c          | 20 ++++++++++++++--
 hw/misc/mchp_pfsoc_sysreg.c         | 37 ++++++++++++++++++++++-------
 hw/riscv/microchip_pfsoc.c          |  5 ++--
 5 files changed, 55 insertions(+), 14 deletions(-)
include/hw/misc/mchp_pfsoc_ioscb.h +4 -0
index aa108d2d88..e8386f9794 100644
@@ -53,6 +53,7 @@ typedef struct MchpPfSoCIoscbState {
     uint32_t services_sr;
     uint8_t mailbox_data[MCHP_PFSOC_IOSCB_MAILBOX_SIZE];
     char *serial_number;
+    bool irq_pending;
     qemu_irq irq;
 } MchpPfSoCIoscbState;
 
@@ -61,4 +62,7 @@ typedef struct MchpPfSoCIoscbState {
 #define MCHP_PFSOC_IOSCB(obj) \
     OBJECT_CHECK(MchpPfSoCIoscbState, (obj), TYPE_MCHP_PFSOC_IOSCB)
 
+bool mchp_pfsoc_ioscb_get_irq_pending(MchpPfSoCIoscbState *s);
+void mchp_pfsoc_ioscb_set_irq_pending(MchpPfSoCIoscbState *s, bool pending);
+
 #endif /* MCHP_PFSOC_IOSCB_H */
include/hw/misc/mchp_pfsoc_sysreg.h +2 -1
index c2b3688a94..d6c9027f2d 100644
@@ -24,13 +24,14 @@
 #define MCHP_PFSOC_SYSREG_H
 
 #include "hw/core/sysbus.h"
+#include "hw/misc/mchp_pfsoc_ioscb.h"
 
 #define MCHP_PFSOC_SYSREG_REG_SIZE  0x2000
 
 typedef struct MchpPfSoCSysregState {
     SysBusDevice parent;
     MemoryRegion sysreg;
-    qemu_irq irq;
+    MchpPfSoCIoscbState *ioscb;
 } MchpPfSoCSysregState;
 
 #define TYPE_MCHP_PFSOC_SYSREG "mchp.pfsoc.sysreg"
hw/misc/mchp_pfsoc_ioscb.c +18 -2
index bde1917c10..1f77da6852 100644
@@ -209,6 +209,22 @@ static const MemoryRegionOps mchp_pfsoc_io_calib_ddr_ops = {
 #define SERVICES_STATUS_SUCCESS             0
 #define SERVICES_STATUS_FAILED              1
 
+static void mchp_pfsoc_ioscb_update_irq(MchpPfSoCIoscbState *s)
+{
+    qemu_set_irq(s->irq, s->irq_pending);
+}
+
+bool mchp_pfsoc_ioscb_get_irq_pending(MchpPfSoCIoscbState *s)
+{
+    return s->irq_pending;
+}
+
+void mchp_pfsoc_ioscb_set_irq_pending(MchpPfSoCIoscbState *s, bool pending)
+{
+    s->irq_pending = pending;
+    mchp_pfsoc_ioscb_update_irq(s);
+}
+
 static void services_cr_write(MchpPfSoCIoscbState *s, uint32_t value)
 {
     uint32_t command;
@@ -248,7 +264,7 @@ static void services_cr_write(MchpPfSoCIoscbState *s, uint32_t value)
 
     s->services_sr = status << SERVICES_SR_STATUS_SHIFT;
     if (value & SERVICES_CR_NOTIFY) {
-        qemu_irq_raise(s->irq);
+        mchp_pfsoc_ioscb_set_irq_pending(s, true);
     }
 }
 
@@ -339,7 +355,7 @@ static void mchp_pfsoc_ioscb_reset(DeviceState *dev)
     s->services_cr = 0;
     s->services_sr = 0;
     memset(s->mailbox_data, 0, sizeof(s->mailbox_data));
-    qemu_irq_lower(s->irq);
+    mchp_pfsoc_ioscb_set_irq_pending(s, false);
 }
 
 static const Property mchp_pfsoc_ioscb_properties[] = {
hw/misc/mchp_pfsoc_sysreg.c +29 -8
index 1d9154280a..4c52338c8a 100644
@@ -24,20 +24,22 @@
 #include "qemu/bitops.h"
 #include "qemu/log.h"
 #include "qapi/error.h"
-#include "hw/core/irq.h"
+#include "hw/core/qdev-properties.h"
 #include "hw/core/sysbus.h"
 #include "hw/misc/mchp_pfsoc_sysreg.h"
 #include "system/runstate.h"
 
-#define CLOCK_CONFIG_CR 0x8
-#define RTC_CLOCK_CR    0xc
-#define MSS_RESET_CR    0x18
-#define ENVM_CR         0xb8
-#define MESSAGE_INT     0x118c
+#define CLOCK_CONFIG_CR     0x8
+#define RTC_CLOCK_CR        0xc
+#define MSS_RESET_CR        0x18
+#define ENVM_CR             0xb8
+#define MESSAGE_INT         0x118c
+#define MESSAGE_INT_PENDING BIT(0)
 
 static uint64_t mchp_pfsoc_sysreg_read(void *opaque, hwaddr offset,
                                        unsigned size)
 {
+    MchpPfSoCSysregState *s = opaque;
     uint32_t val = 0;
 
     switch (offset) {
@@ -56,6 +58,10 @@ static uint64_t mchp_pfsoc_sysreg_read(void *opaque, hwaddr offset,
         /* Indicate the eNVM is running at the configured divider rate */
         val = BIT(6);
         break;
+    case MESSAGE_INT:
+        val = mchp_pfsoc_ioscb_get_irq_pending(s->ioscb) ?
+              MESSAGE_INT_PENDING : 0;
+        break;
     default:
         qemu_log_mask(LOG_UNIMP, "%s: unimplemented device read "
                       "(size %d, offset 0x%" HWADDR_PRIx ")\n",
@@ -77,7 +83,12 @@ static void mchp_pfsoc_sysreg_write(void *opaque, hwaddr offset,
         }
         break;
     case MESSAGE_INT:
-        qemu_irq_lower(s->irq);
+        /*
+         * MESSAGE_INT bit 0 is read/write: writing zero clears the interrupt
+         * and writing one sets it. IOSCB owns the state and PLIC output.
+         */
+        mchp_pfsoc_ioscb_set_irq_pending(s->ioscb,
+                                        value & MESSAGE_INT_PENDING);
         break;
     default:
         qemu_log_mask(LOG_UNIMP, "%s: unimplemented device write "
@@ -97,20 +108,30 @@ static void mchp_pfsoc_sysreg_realize(DeviceState *dev, Error **errp)
 {
     MchpPfSoCSysregState *s = MCHP_PFSOC_SYSREG(dev);
 
+    if (!s->ioscb) {
+        error_setg(errp, "The 'ioscb' link must be set");
+        return;
+    }
+
     memory_region_init_io(&s->sysreg, OBJECT(dev),
                           &mchp_pfsoc_sysreg_ops, s,
                           "mchp.pfsoc.sysreg",
                           MCHP_PFSOC_SYSREG_REG_SIZE);
     sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->sysreg);
-    sysbus_init_irq(SYS_BUS_DEVICE(dev), &s->irq);
 }
 
+static const Property mchp_pfsoc_sysreg_properties[] = {
+    DEFINE_PROP_LINK("ioscb", MchpPfSoCSysregState, ioscb,
+                     TYPE_MCHP_PFSOC_IOSCB, MchpPfSoCIoscbState *),
+};
+
 static void mchp_pfsoc_sysreg_class_init(ObjectClass *klass, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     dc->desc = "Microchip PolarFire SoC SYSREG module";
     dc->realize = mchp_pfsoc_sysreg_realize;
+    device_class_set_props(dc, mchp_pfsoc_sysreg_properties);
 }
 
 static const TypeInfo mchp_pfsoc_sysreg_info = {
hw/riscv/microchip_pfsoc.c +2 -3
index 55ca8a244a..63cec48f43 100644
@@ -316,12 +316,11 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
     }
 
     /* SYSREG */
+    object_property_set_link(OBJECT(&s->sysreg), "ioscb", OBJECT(&s->ioscb),
+                             &error_abort);
     sysbus_realize(SYS_BUS_DEVICE(&s->sysreg), errp);
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->sysreg), 0,
                     memmap[MICROCHIP_PFSOC_SYSREG].base);
-    sysbus_connect_irq(SYS_BUS_DEVICE(&s->sysreg), 0,
-                       qdev_get_gpio_in(DEVICE(s->plic),
-                       MICROCHIP_PFSOC_MAILBOX_IRQ));
 
     /* AXISW */
     create_unimplemented_device("microchip.pfsoc.axisw",
Signature · 1 line
2.53.0
author
#16 lore raw

PATCH v5 10/26 tests/qtest: add Cadence SDHCI ADMA pacing/MMIO reproducer

In reply to Bin Meng

From: Wadim Mueller <[email protected]>

Add an image-free qtest for the microchip-icicle-kit machine that drives the generic SDHCI model (hw/sd/sdhci.c) through the Cadence wrapper (hw/sd/cadence_sdhci.c, SRS window at 0x20008200) directly over MMIO under "-accel qtest", where QEMU_CLOCK_VIRTUAL only advances when the test steps it.

It reproduces two aspects of the ADMA2 engine objectively, without any guest firmware:

1. Pacing: a 12-descriptor (> SDHC_ADMA_DESCS_PER_DELAY) non-interrupt ADMA2 CMD18 read completes after a model-dependent number of SDHC_TRANSFER_DELAY virtual-clock steps, which the test reports.

2. MMIO coupling: a chain carrying a DMA-boundary interrupt descriptor yields mid-chain and reschedules on the virtual clock. With the clock frozen, an interrupt-status read must not itself resume or complete the transfer. This asserts the behaviour intended by "Run ADMA independently of MMIO": it passes on the fixed model and fails on a model that resumes ADMA from an MMIO read.

The SD bring-up (CMD0/CMD8/ACMD41/CMD2/CMD3/CMD7/CMD16) and the ADMA2 descriptor-table layout mirror the pattern already used by the SDHCI device model; SDHCI register offsets and ADMA attribute bits are reproduced locally because sdhci-internal.h is not standalone-includable from a qtest.

[bmeng: strengthen checks, reuse SDHCI helpers, verify data]

---

(no changes since v2)

Changes in v2:
- Assert bounded ADMA pacing and MMIO-independent progress
- Reuse existing SDHCI definitions and command helpers
- Verify transferred data against a known image pattern
- New

 MAINTAINERS                      |   1 +
 tests/qtest/cadence-sdhci-test.c | 282 +++++++++++++++++++++++++++++++
 tests/qtest/meson.build          |   2 +
 3 files changed, 285 insertions(+)
 create mode 100644 tests/qtest/cadence-sdhci-test.c
MAINTAINERS +1 -0
index 4bef2dffb0..3c305d570f 100644
@@ -2462,6 +2462,7 @@ F: include/hw/sd/sd*
 F: hw/sd/core.c
 F: hw/sd/sd*
 F: hw/sd/ssi-sd.c
+F: tests/qtest/cadence-sdhci-test.c
 F: tests/qtest/fuzz-sdcard-test.c
 F: tests/qtest/sdhci-test.c
 F: tests/qtest/xilinx-zynq-sdhci-test.c
tests/qtest/cadence-sdhci-test.c new file +282 -0

282 lines not on this page · raw message

tests/qtest/meson.build +2 -0
index a001409de2..d08fbc1eb7 100644
@@ -317,6 +317,8 @@ qtests_riscv32 = \
 
 qtests_riscv64 = ['riscv-csr-test'] + \
   (unpack_edk2_blobs ? ['bios-tables-test'] : []) + \
+  (config_all_devices.has_key('CONFIG_MICROCHIP_PFSOC') ?
+   ['cadence-sdhci-test'] : []) + \
   (config_all_devices.has_key('CONFIG_SIFIVE_L2CC') ? ['sifive_l2cc_test'] : []) + \
   (config_all_devices.has_key('CONFIG_IOMMU_TESTDEV') and
    config_all_devices.has_key('CONFIG_RISCV_IOMMU') ?
Signature · 1 line
2.53.0
author
#12 lore raw

PATCH v5 8/26 tests/qtest: Add SiFive L2 cache controller coverage

In reply to Bin Meng

Exercise Config, WayEnable, and indexed WayMask registers on the PolarFire and FU540 integrations, including their different master counts, reset, monotonic writes, and unimplemented-register logging.

Verify that enabling cache ways hides the corresponding LIM range, while the controller's Zero window stays accessible. Check that reset restores hidden LIM data without clearing the Zero RAM stand-in.

Migrate register state and both RAM backings, verify the destination LIM view, and confirm that writes to hidden addresses do not alter the data restored by a later reset.

---

(no changes since v3)

Changes in v3:
- Rename the test for the shared SiFive L2CC model
- Exercise 15 masters on PolarFire and 21 masters on FU540

 MAINTAINERS                    |   1 +
 tests/qtest/sifive_l2cc_test.c | 306 +++++++++++++++++++++++++++++++++
 tests/qtest/meson.build        |   3 +
 3 files changed, 310 insertions(+)
 create mode 100644 tests/qtest/sifive_l2cc_test.c
MAINTAINERS +1 -0
index 55463103ff..4bef2dffb0 100644
@@ -1851,6 +1851,7 @@ F: docs/system/riscv/sifive_u.rst
 F: hw/*/*sifive*.c
 F: include/hw/*/*sifive*.h
 F: tests/functional/riscv64/test_sifive_u.py
+F: tests/qtest/sifive_l2cc_test.c
 
 Tenstorrent Machines
 M: Joel Stanley <[email protected]>
tests/qtest/sifive_l2cc_test.c new file +306 -0

306 lines not on this page · raw message

tests/qtest/meson.build +3 -0
index ff4bf9528a..a001409de2 100644
@@ -317,6 +317,7 @@ qtests_riscv32 = \
 
 qtests_riscv64 = ['riscv-csr-test'] + \
   (unpack_edk2_blobs ? ['bios-tables-test'] : []) + \
+  (config_all_devices.has_key('CONFIG_SIFIVE_L2CC') ? ['sifive_l2cc_test'] : []) + \
   (config_all_devices.has_key('CONFIG_IOMMU_TESTDEV') and
    config_all_devices.has_key('CONFIG_RISCV_IOMMU') ?
    ['iommu-riscv-test'] : []) + \
@@ -438,6 +439,8 @@ qtests = {
   'erst-test': files('erst-test.c'),
   'ivshmem-test': [rt, '../../contrib/ivshmem-server/ivshmem-server.c'],
   'migration-test': test_migration_files + migration_tls_files + migration_colo_files,
+  'sifive_l2cc_test': files('migration/migration-qmp.c',
+                           'migration/migration-util.c'),
   'pxe-test': files('boot-sector.c'),
   'pnv-xive2-test': files('pnv-xive2-common.c', 'pnv-xive2-flush-sync.c',
                           'pnv-xive2-nvpg_bar.c'),
Signature · 1 line
2.53.0
author
#35 lore raw

PATCH v5 23/26 docs/system/riscv: pfsoc: Document CLINT topology for direct Linux boot

In reply to Bin Meng

The generic OpenSBI platform derives the CLINT first hart and register slot count from interrupts-extended. Some S-mode-only MPFS device trees mask the E51 M-mode interrupt entries with 0xffffffff, which shifts the MSIP and MTIMECMP slots when the same DTB is used for direct boot.

Document the complete five-hart CLINT node. Require interrupts 3 and 7 for hart 0 as well as the U54 harts.

---

(no changes since v3)

Changes in v3:
- Explain how reduced hart topologies change the CLINT DTB tuples

 docs/system/riscv/microchip-icicle-kit.rst | 26 +++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
docs/system/riscv/microchip-icicle-kit.rst +25 -1
index 2159e8e461..038ea7221f 100644
@@ -66,7 +66,31 @@ should meet the following requirements:
   option.
 
 * It should contain a node for the CLINT device with a compatible string
-  "riscv,clint0".
+  "riscv,clint0" or "sifive,clint0".  Its ``interrupts-extended`` property
+  must describe the M-mode software interrupt (3) and timer interrupt (7) for
+  every hart, including the E51 hart 0.
+
+For example, the default five-hart Icicle Kit CLINT node can be described as:
+
+.. code-block:: none
+
+    clint: clint@2000000 {
+        compatible = "sifive,fu540-c000-clint", "sifive,clint0";
+        reg = <0x0 0x2000000 0x0 0xc000>;
+        interrupts-extended = <&cpu0_intc 3>, <&cpu0_intc 7>,
+                              <&cpu1_intc 3>, <&cpu1_intc 7>,
+                              <&cpu2_intc 3>, <&cpu2_intc 7>,
+                              <&cpu3_intc 3>, <&cpu3_intc 7>,
+                              <&cpu4_intc 3>, <&cpu4_intc 7>;
+    };
+
+When selecting fewer harts with ``-smp``, remove the absent hart nodes and their
+CLINT interrupt tuples from the DTB while retaining the E51 hart 0 entries.
+
+Do not replace the hart 0 interrupt numbers with ``0xffffffff`` when the same
+DTB is used to initialize the generic OpenSBI platform.  OpenSBI derives the
+first hart and the number of CLINT register slots from these interrupt tuples;
+masking hart 0 would shift the per-hart MSIP and MTIMECMP register mappings.
 
 When ``-bios`` is not specified or set to ``default``, the OpenSBI
 ``fw_dynamic`` BIOS image for the ``generic`` platform is used to boot an
Signature · 1 line
2.53.0
author
#15 lore raw

PATCH v5 9/26 hw/sd: sdhci: Run ADMA independently of MMIO

In reply to Bin Meng

The SDHCI model processes the first ADMA descriptor batch inside the command MMIO write, then resumes pending batches before every later SDHCI MMIO read or write. This makes register access perform bulk DMA work and can delay a status read even when completion bits are set.

On the Icicle Kit, U-Boot uses ADMA2-64 and CMD18 to load a roughly 19 MiB FIT image from SD. It can report:

Timeout for status update: 00000001 00000001
Timeout for status update: 00000003 00000001

The status already contains the requested Command Complete bit, and may also contain Transfer Complete. However, reading the interrupt status first executes a pending ADMA batch. The MMIO read can therefore return after U-Boot has reached its one-second polling deadline.

Turn the existing transfer timer into an ADMA-only engine. Starting an ADMA command arms the engine directly, and each timer callback runs one bounded batch before yielding. MMIO reads and writes no longer perform or schedule ADMA work. Keep PIO and SDMA synchronous.

Cancel the engine and clear ADMA activity and error state on DATA or ALL reset.

Mechanically reorder and inline existing functions per review.

---

(no changes since v4)

Changes in v4:
- Drop the unused ADMA callback forward declaration
- Move helper definitions before the data-transfer declaration
- Merge the ADMA timer callback and batch routine

 hw/sd/sdhci.c | 146 +++++++++++++++++++++++++++++---------------------
 1 file changed, 84 insertions(+), 62 deletions(-)
hw/sd/sdhci.c +84 -62
index bd74c60f72..0c5b0ed984 100644
@@ -277,6 +277,7 @@ static void sdhci_set_inserted(DeviceState *dev, bool level)
             }
         } else {
             s->prnsts = 0x1fa0000;
+            timer_del(s->transfer_timer);
             s->pwrcon &= ~SDHC_POWER_ON;
             s->clkcon &= ~SDHC_CLOCK_SDCLK_EN;
             if (s->norintstsen & SDHC_NISEN_REMOVE) {
@@ -348,7 +349,33 @@ static void sdhci_poweron_reset(DeviceState *dev)
     }
 }
 
-static void sdhci_data_transfer(void *opaque);
+static void sdhci_set_transfer_active(SDHCIState *s)
+{
+    s->prnsts |= SDHC_DATA_INHIBIT | SDHC_DAT_LINE_ACTIVE;
+    if (s->trnmod & SDHC_TRNS_READ) {
+        s->prnsts |= SDHC_DOING_READ;
+    } else {
+        s->prnsts |= SDHC_DOING_WRITE;
+    }
+}
+
+static void sdhci_schedule_adma(SDHCIState *s)
+{
+    timer_mod(s->transfer_timer,
+              qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + SDHC_TRANSFER_DELAY);
+}
+
+static bool sdhci_adma_transfer_active(SDHCIState *s)
+{
+    return TRANSFERRING_DATA(s->prnsts) &&
+           (s->trnmod & SDHC_TRNS_DMA) &&
+           (s->cmdreg & SDHC_CMD_DATA_PRESENT) &&
+           sdhci_get_dma_type(s) != SDHC_CTRL_SDMA &&
+           !(s->admaerr & SDHC_ADMAERR_STATE_MASK) &&
+           !(s->errintsts & SDHC_EIS_ADMAERR);
+}
+
+static void sdhci_data_transfer(SDHCIState *s);
 
 #define BLOCK_SIZE_MASK (4 * KiB - 1)
 
@@ -405,7 +432,13 @@ static void sdhci_send_command(SDHCIState *s)
     if (!timeout && (s->blksize & BLOCK_SIZE_MASK) &&
         (s->cmdreg & SDHC_CMD_DATA_PRESENT)) {
         s->data_count = 0;
-        sdhci_data_transfer(s);
+        if ((s->trnmod & SDHC_TRNS_DMA) &&
+            sdhci_get_dma_type(s) != SDHC_CTRL_SDMA) {
+            sdhci_set_transfer_active(s);
+            sdhci_schedule_adma(s);
+        } else {
+            sdhci_data_transfer(s);
+        }
     }
 }
 
@@ -848,10 +881,10 @@ static void get_adma_description(SDHCIState *s, ADMADescr *dscr)
     }
 }
 
-/* Advanced DMA data transfer */
-
-static void sdhci_do_adma(SDHCIState *s)
+/* Run one independently scheduled, quota-bounded ADMA batch */
+static void sdhci_adma_run_batch(void *opaque)
 {
+    SDHCIState *s = (SDHCIState *)opaque;
     unsigned int begin, length;
     const uint16_t block_size = s->blksize & BLOCK_SIZE_MASK;
     const MemTxAttrs attrs = { .memory = true };
@@ -859,6 +892,35 @@ static void sdhci_do_adma(SDHCIState *s)
     MemTxResult res = MEMTX_ERROR;
     int i;
 
+    if (!sdhci_adma_transfer_active(s)) {
+        return;
+    }
+
+    switch (sdhci_get_dma_type(s)) {
+    case SDHC_CTRL_ADMA1_32:
+        if (!(s->capareg & R_SDHC_CAPAB_ADMA1_MASK)) {
+            trace_sdhci_error("ADMA1 not supported");
+            return;
+        }
+        break;
+    case SDHC_CTRL_ADMA2_32:
+        if (!(s->capareg & R_SDHC_CAPAB_ADMA2_MASK)) {
+            trace_sdhci_error("ADMA2 not supported");
+            return;
+        }
+        break;
+    case SDHC_CTRL_ADMA2_64:
+        if (!(s->capareg & R_SDHC_CAPAB_ADMA2_MASK) ||
+            !(s->capareg & R_SDHC_CAPAB_BUS64BIT_MASK)) {
+            trace_sdhci_error("64 bit ADMA not supported");
+            return;
+        }
+        break;
+    default:
+        trace_sdhci_error("Unsupported ADMA type");
+        return;
+    }
+
     if (s->trnmod & SDHC_TRNS_BLK_CNT_EN && !s->blkcnt) {
         /* Stop Multiple Transfer */
         sdhci_end_transfer(s);
@@ -956,15 +1018,17 @@ static void sdhci_do_adma(SDHCIState *s)
             }
             if (res != MEMTX_OK) {
                 s->data_count = 0;
+                s->admaerr &= ~SDHC_ADMAERR_STATE_MASK;
+                s->admaerr |= SDHC_ADMAERR_STATE_ST_TFR;
                 if (s->errintstsen & SDHC_EISEN_ADMAERR) {
                     trace_sdhci_error("Set ADMA error flag");
                     s->errintsts |= SDHC_EIS_ADMAERR;
                     s->norintsts |= SDHC_NIS_ERR;
                 }
                 sdhci_update_irq(s);
-            } else {
-                s->admasysaddr += dscr.incr;
+                return;
             }
+            s->admasysaddr += dscr.incr;
             break;
         case SDHC_ADMA_ATTR_ACT_LINK:   /* link to next descriptor table */
             s->admasysaddr = dscr.addr;
@@ -1012,50 +1076,15 @@ static void sdhci_do_adma(SDHCIState *s)
     }
 
     /* we have unfinished business - reschedule to continue ADMA */
-    timer_mod(s->transfer_timer,
-                   qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + SDHC_TRANSFER_DELAY);
+    sdhci_schedule_adma(s);
 }
 
-/* Perform data transfer according to controller configuration */
-
-static void sdhci_data_transfer(void *opaque)
+/* Perform synchronous PIO or SDMA data transfer */
+static void sdhci_data_transfer(SDHCIState *s)
 {
-    SDHCIState *s = (SDHCIState *)opaque;
-
     if (s->trnmod & SDHC_TRNS_DMA) {
-        switch (sdhci_get_dma_type(s)) {
-        case SDHC_CTRL_SDMA:
-            sdhci_sdma_transfer(s);
-            break;
-        case SDHC_CTRL_ADMA1_32:
-            if (!(s->capareg & R_SDHC_CAPAB_ADMA1_MASK)) {
-                trace_sdhci_error("ADMA1 not supported");
-                break;
-            }
-
-            sdhci_do_adma(s);
-            break;
-        case SDHC_CTRL_ADMA2_32:
-            if (!(s->capareg & R_SDHC_CAPAB_ADMA2_MASK)) {
-                trace_sdhci_error("ADMA2 not supported");
-                break;
-            }
-
-            sdhci_do_adma(s);
-            break;
-        case SDHC_CTRL_ADMA2_64:
-            if (!(s->capareg & R_SDHC_CAPAB_ADMA2_MASK) ||
-                    !(s->capareg & R_SDHC_CAPAB_BUS64BIT_MASK)) {
-                trace_sdhci_error("64 bit ADMA not supported");
-                break;
-            }
-
-            sdhci_do_adma(s);
-            break;
-        default:
-            trace_sdhci_error("Unsupported DMA type");
-            break;
-        }
+        assert(sdhci_get_dma_type(s) == SDHC_CTRL_SDMA);
+        sdhci_sdma_transfer(s);
     } else {
         if ((s->trnmod & SDHC_TRNS_READ) && sdbus_data_ready(&s->sdbus)) {
             s->prnsts |= SDHC_DOING_READ | SDHC_DATA_INHIBIT |
@@ -1098,21 +1127,11 @@ sdhci_buff_access_is_sequential(SDHCIState *s, unsigned byte_num)
     return true;
 }
 
-static void sdhci_resume_pending_transfer(SDHCIState *s)
-{
-    timer_del(s->transfer_timer);
-    sdhci_data_transfer(s);
-}
-
 static uint64_t sdhci_read(void *opaque, hwaddr offset, unsigned size)
 {
     SDHCIState *s = (SDHCIState *)opaque;
     uint32_t ret = 0;
 
-    if (timer_pending(s->transfer_timer)) {
-        sdhci_resume_pending_transfer(s);
-    }
-
     switch (offset & ~0x3) {
     case SDHC_SYSAD:
         ret = s->sdmasysad;
@@ -1235,7 +1254,10 @@ static inline void sdhci_reset_write(SDHCIState *s, uint8_t value)
         s->norintsts &= ~SDHC_NIS_CMDCMP;
         break;
     case SDHC_RESET_DATA:
+        timer_del(s->transfer_timer);
         s->data_count = 0;
+        s->admaerr = 0;
+        s->errintsts &= ~SDHC_EIS_ADMAERR;
         s->prnsts &= ~(SDHC_SPACE_AVAILABLE | SDHC_DATA_AVAILABLE |
                 SDHC_DOING_READ | SDHC_DOING_WRITE |
                 SDHC_DATA_INHIBIT | SDHC_DAT_LINE_ACTIVE);
@@ -1244,6 +1266,10 @@ static inline void sdhci_reset_write(SDHCIState *s, uint8_t value)
         s->sdma_boundary_paused = false;
         s->norintsts &= ~(SDHC_NIS_WBUFRDY | SDHC_NIS_RBUFRDY |
                 SDHC_NIS_DMA | SDHC_NIS_TRSCMP | SDHC_NIS_BLKGAP);
+        if (!s->errintsts) {
+            s->norintsts &= ~SDHC_NIS_ERR;
+        }
+        sdhci_update_irq(s);
         break;
     }
 }
@@ -1257,10 +1283,6 @@ sdhci_write(void *opaque, hwaddr offset, uint64_t val, unsigned size)
     uint32_t value = val;
     value <<= shift;
 
-    if (timer_pending(s->transfer_timer)) {
-        sdhci_resume_pending_transfer(s);
-    }
-
     switch (offset & ~0x3) {
     case SDHC_SYSAD:
         if (!TRANSFERRING_DATA(s->prnsts) ||
@@ -1521,7 +1543,7 @@ void sdhci_initfn(SDHCIState *s)
     s->insert_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
                                    sdhci_raise_insertion_irq, s);
     s->transfer_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
-                                     sdhci_data_transfer, s);
+                                     sdhci_adma_run_batch, s);
 
     s->io_ops = &sdhci_mmio_ops;
 }
Signature · 1 line
2.53.0
#41 lore raw
In reply to Bin Meng
Quoted 60 lines · Bin Meng

The microchip-icicle-kit machine was originally validated with an older Hart Software Services (HSS) firmware stack. HSS v2026.04.1 cannot boot through U-Boot to Linux because several firmware-visible parts of the PolarFire SoC are missing or incomplete.

The first failure occurs before the UART is initialized because the L2 zero window is not mapped. HSS then needs additional L2 cache controller and DDR training behavior. Later boot stages exercise system services, the RTC, SDHC version 4 DMA, and high-capacity SD card block sizing, along with the complete DDR aliases. The existing models ither reject these accesses or expose behavior that does not match the hardware specifications.

This series restores the complete firmware boot flow. With these changes, QEMU boots the HSS v2026.04.1 eNVM image, loads its U-Boot payload from an SD card, and reaches the Buildroot 2026.05 Linux login prompt.

The changes are organized around the firmware boot sequence:

* Correct the L2-LIM size, map the L2 zero window, and provide the DMC status transitions required by HSS DDR initialization.
* Model the documented L2CC Config, WayEnable, and WayMask registers, and resize L2-LIM as cache ways are enabled.
* Complete SDHCI version 4 support used by the Cadence controller, including Host Control 2, SDMA system addressing, 64-bit ADMA2 descriptors, and SDMA boundary continuation.
* Run ADMA from a bounded timer-driven engine instead of performing work from command or unrelated MMIO accesses. This keeps DMA progress independent of guest register traffic and avoids consuming a polling deadline inside the command write.
* Advertise the Cadence controller's 64-bit system bus support.
* Add the PolarFire SoC serial-number system service and RTC, and honor the system-service notification control bit.
* Correct the DDR aliases and fix the board topology at its physical configuration of 2 GiB of RAM and five harts.
* Document direct and HSS boot, add focused qtests and a full firmware functional test, and restore the machine's Supported maintainer status.

Testing performed:

* Built qemu-system-riscv64 and the documentation.
* Passed various newly added qtests.
* Booted HSS v2026.04.1, U-Boot, and Buildroot 2026.05 Linux to the login prompt using the functional-test image.

The functional test uses the processmission/qemu-machine-images release v1.1.1 tarball:

https://github.com/processmission/qemu-machine-images/releases/download/
v1.1.1/riscv64-microchip-icicle-kit-v1.1.1.tar.zst

When restoring the HSS boot support, 3 potential bugs were identified in the upstream HSS source codes that either blocks the DDR training from succeed or traps in a multi-core race at the very beginning or after a succesfully DDR training but stuck at OpenSBI/U-Boot hand-off. There are already bug reports filed aginst various upstream projects.

Quoted 5 lines

Changes in v5:
- Select REGISTER to fix riscv32-softmmu link failures
- Rebase onto origin/master
- Drop the high-capacity SD block-size fix already merged upstream

Patch 8/11/15/22/23 still doesn't have any RB/TB tags. Ping for review?

Regards,
Bin

Reviewed-by on v5 8/26
#13 lore raw

Re: [PATCH v5 08/26] tests/qtest: Add SiFive L2 cache controller coverage

In reply to Bin Meng
Quoted 8 lines · Bin Meng

Exercise Config, WayEnable, and indexed WayMask registers on the PolarFire and FU540 integrations, including their different master counts, reset, monotonic writes, and unimplemented-register logging.

Verify that enabling cache ways hides the corresponding LIM range, while the controller's Zero window stays accessible. Check that reset restores hidden LIM data without clearing the Zero RAM stand-in.

Quoted 7 lines

Migrate register state and both RAM backings, verify the destination LIM view, and confirm that writes to hidden addresses do not alter the data restored by a later reset.

---

Quoted 358 lines

(no changes since v3)

Changes in v3:
- Rename the test for the shared SiFive L2CC model
- Exercise 15 masters on PolarFire and 21 masters on FU540

  MAINTAINERS                    |   1 +
  tests/qtest/sifive_l2cc_test.c | 306 +++++++++++++++++++++++++++++++++
  tests/qtest/meson.build        |   3 +
  3 files changed, 310 insertions(+)

create mode 100644 tests/qtest/sifive_l2cc_test.c

MAINTAINERS +1 -0
index 55463103ff..4bef2dffb0 100644
@@ -1851,6 +1851,7 @@ F: docs/system/riscv/sifive_u.rst
  F: hw/*/*sifive*.c
  F: include/hw/*/*sifive*.h
  F: tests/functional/riscv64/test_sifive_u.py
+F: tests/qtest/sifive_l2cc_test.c
 
  Tenstorrent Machines
  M: Joel Stanley <[email protected]>
tests/qtest/sifive_l2cc_test.c new file +306 -0
new file mode 100644
index 0000000000..fef80f3438
@@ -0,0 +1,306 @@
+/*
+ * QTest testcase for the SiFive L2 cache controller
+ *
+ * Copyright (c) 2026 Process Mission
+ *
+ * Author:
+ *   Bin Meng <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/units.h"
+#include "libqtest.h"
+#include "migration/migration-qmp.h"
+#include "migration/migration-util.h"
+
+#define L2CC_BASE                       0x02010000
+#define L2CC_CONFIG                     0x000
+#define L2CC_CONFIG_VALUE               0x06091004
+#define L2CC_WAY_ENABLE                 0x008
+#define L2CC_ECC_INJECT                 0x040
+#define L2CC_FLUSH64                    0x200
+#define L2CC_WAY_MASK_BASE              0x800
+#define L2CC_WAY_MASK_COUNT             15
+#define L2CC_MAX_MASTERS                21
+#define L2CC_WAY_MASK(n)                (L2CC_WAY_MASK_BASE + 8 * (n))
+#define L2CC_MASTER15                   L2CC_WAY_MASK(L2CC_WAY_MASK_COUNT)
+#define L2CC_WAY_ENABLE_RESET           0
+#define L2CC_WAY_MASK_RESET             UINT64_MAX
+
+#define L2_LIM_BASE                     0x08000000
+#define L2_WAY_SIZE                     (128 * KiB)
+#define L2_LIM_RESET_WAYS               15
+#define L2_ZERO_BASE                    0x0a000000
+#define L2_ZERO_SIZE                    (2 * MiB)
+
+static QTestState *sifive_l2cc_start(const char *firmware)
+{
+    return qtest_initf("-machine microchip-icicle-kit -smp 5 -m 2G "
+                       "-bios \"%s\"", firmware);
+}
+
+static char *sifive_l2cc_create_firmware(void)
+{
+    static const uint8_t firmware[] = {
+        0x13, 0x00, 0x00, 0x00,
+        0x6f, 0x00, 0x00, 0x00,
+    };
+    char *path;
+    int fd;
+    ssize_t written;
+
+    fd = g_file_open_tmp("sifive_l2cc_XXXXXX", &path, NULL);
+    g_assert_cmpint(fd, >=, 0);
+
+    written = write(fd, firmware, sizeof(firmware));
+    g_assert_cmpint(written, ==, sizeof(firmware));
+    close(fd);
+
+    return path;
+}
+
+static uint64_t l2cc_way_mask_test_value(unsigned int master)
+{
+    return UINT64_C(0xfedcba9876543201) + master;
+}
+
+static void test_l2cc_registers(void)
+{
+    g_autofree char *firmware = sifive_l2cc_create_firmware();
+    QTestState *qts = sifive_l2cc_start(firmware);
+    unsigned int i;
+
+    unlink(firmware);
+
+    g_assert_cmphex(qtest_readl(qts, L2CC_BASE + L2CC_CONFIG), ==,
+                    L2CC_CONFIG_VALUE);
+    qtest_writel(qts, L2CC_BASE + L2CC_CONFIG, UINT32_MAX);
+    g_assert_cmphex(qtest_readl(qts, L2CC_BASE + L2CC_CONFIG), ==,
+                    L2CC_CONFIG_VALUE);
+
+    g_assert_cmphex(qtest_readb(qts, L2CC_BASE + L2CC_WAY_ENABLE), ==,
+                    L2CC_WAY_ENABLE_RESET);
+    qtest_writeb(qts, L2CC_BASE + L2CC_WAY_ENABLE, 0xd);
+    g_assert_cmphex(qtest_readb(qts, L2CC_BASE + L2CC_WAY_ENABLE), ==, 0xd);
+    qtest_writeb(qts, L2CC_BASE + L2CC_WAY_ENABLE, 3);
+    g_assert_cmphex(qtest_readb(qts, L2CC_BASE + L2CC_WAY_ENABLE), ==, 0xd);
+    qtest_writeq(qts, L2CC_BASE + L2CC_WAY_ENABLE, 0xf);
+    g_assert_cmphex(qtest_readq(qts, L2CC_BASE + L2CC_WAY_ENABLE), ==, 0xf);
+    qtest_writeb(qts, L2CC_BASE + L2CC_WAY_ENABLE, 0xe);
+    g_assert_cmphex(qtest_readb(qts, L2CC_BASE + L2CC_WAY_ENABLE), ==, 0xf);
+
+    for (i = 0; i < L2CC_WAY_MASK_COUNT; i++) {
+        g_assert_cmphex(qtest_readq(qts, L2CC_BASE + L2CC_WAY_MASK(i)), ==,
+                        L2CC_WAY_MASK_RESET);
+        qtest_writeq(qts, L2CC_BASE + L2CC_WAY_MASK(i),
+                     l2cc_way_mask_test_value(i));
+    }
+    for (i = 0; i < L2CC_WAY_MASK_COUNT; i++) {
+        g_assert_cmphex(qtest_readq(qts, L2CC_BASE + L2CC_WAY_MASK(i)), ==,
+                        l2cc_way_mask_test_value(i));
+    }
+
+    qtest_system_reset(qts);
+    g_assert_cmphex(qtest_readl(qts, L2CC_BASE + L2CC_CONFIG), ==,
+                    L2CC_CONFIG_VALUE);
+    g_assert_cmphex(qtest_readb(qts, L2CC_BASE + L2CC_WAY_ENABLE), ==,
+                    L2CC_WAY_ENABLE_RESET);
+    for (i = 0; i < L2CC_WAY_MASK_COUNT; i++) {
+        g_assert_cmphex(qtest_readq(qts, L2CC_BASE + L2CC_WAY_MASK(i)), ==,
+                        L2CC_WAY_MASK_RESET);
+    }
+
+    qtest_quit(qts);
+}
+
+static void test_l2lim_topology(void)
+{
+    g_autofree char *firmware = sifive_l2cc_create_firmware();
+    uint32_t original[L2_LIM_RESET_WAYS];
+    const uint32_t poison = 0xdeadc0de;
+    const uint64_t zero_last = L2_ZERO_BASE + L2_ZERO_SIZE - 4;
+    QTestState *qts = sifive_l2cc_start(firmware);
+    unsigned int i;
+
+    unlink(firmware);
+
+    /* Check the fixed aperture, not the RAM stand-in's eviction behavior */
+    qtest_writel(qts, zero_last, 0xa55a9669);
+    g_assert_cmphex(qtest_readl(qts, zero_last), ==, 0xa55a9669);
+
+    for (i = 1; i <= L2_LIM_RESET_WAYS; i++) {
+        uint64_t l2lim_size = (L2_LIM_RESET_WAYS - i) * L2_WAY_SIZE;
+        uint64_t hidden = L2_LIM_BASE + l2lim_size;
+        uint32_t tail = 0x96000000 | i;
+
+        original[i - 1] = 0x69000000 | i;
+        qtest_writel(qts, hidden, original[i - 1]);
+        g_assert_cmphex(qtest_readl(qts, hidden), ==, original[i - 1]);
+
+        if (l2lim_size) {
+            qtest_writel(qts, hidden - 4, tail);
+            g_assert_cmphex(qtest_readl(qts, hidden - 4), ==, tail);
+        }
+
+        qtest_writeb(qts, L2CC_BASE + L2CC_WAY_ENABLE, i);
+        g_assert_cmphex(qtest_readb(qts,
+                                   L2CC_BASE + L2CC_WAY_ENABLE), ==, i);
+        if (l2lim_size) {
+            g_assert_cmphex(qtest_readl(qts, hidden - 4), ==, tail);
+        }
+        g_assert_cmphex(qtest_readl(qts, hidden), ==, 0);
+        qtest_writel(qts, hidden, poison);
+        g_assert_cmphex(qtest_readl(qts, hidden), ==, 0);
+        g_assert_cmphex(qtest_readl(qts, zero_last), ==, 0xa55a9669);
+    }
+
+    qtest_writeb(qts, L2CC_BASE + L2CC_WAY_ENABLE, UINT8_MAX);
+    g_assert_cmphex(qtest_readb(qts, L2CC_BASE + L2CC_WAY_ENABLE), ==,
+                    UINT8_MAX);
+    g_assert_cmphex(qtest_readl(qts, L2_LIM_BASE), ==, 0);
+    qtest_writeb(qts, L2CC_BASE + L2CC_WAY_ENABLE, 3);
+    g_assert_cmphex(qtest_readb(qts, L2CC_BASE + L2CC_WAY_ENABLE), ==,
+                    UINT8_MAX);
+    g_assert_cmphex(qtest_readl(qts, L2_LIM_BASE), ==, 0);
+
+    qtest_system_reset(qts);
+    g_assert_cmphex(qtest_readb(qts, L2CC_BASE + L2CC_WAY_ENABLE), ==,
+                    L2CC_WAY_ENABLE_RESET);
+    for (i = 1; i <= L2_LIM_RESET_WAYS; i++) {
+        uint64_t restored = L2_LIM_BASE +
+                            (L2_LIM_RESET_WAYS - i) * L2_WAY_SIZE;
+
+        g_assert_cmphex(qtest_readl(qts, restored), ==, original[i - 1]);
+    }
+    g_assert_cmphex(qtest_readl(qts, zero_last), ==, 0xa55a9669);
+
+    qtest_quit(qts);
+}
+
+static void test_l2cc_master_count(void)
+{
+    g_autofree char *firmware = sifive_l2cc_create_firmware();
+    QTestState *qts = qtest_initf(
+        "-machine sifive_u -smp 5 -bios \"%s\"", firmware);
+    const uint64_t zero_last = L2_ZERO_BASE + L2_ZERO_SIZE - 4;
+    unsigned int i;
+
+    unlink(firmware);
+
+    for (i = 0; i < L2CC_MAX_MASTERS; i++) {
+        g_assert_cmphex(qtest_readq(qts, L2CC_BASE + L2CC_WAY_MASK(i)), ==,
+                        L2CC_WAY_MASK_RESET);
+        qtest_writeq(qts, L2CC_BASE + L2CC_WAY_MASK(i),
+                     l2cc_way_mask_test_value(i));
+    }
+    for (i = 0; i < L2CC_MAX_MASTERS; i++) {
+        g_assert_cmphex(qtest_readq(qts, L2CC_BASE + L2CC_WAY_MASK(i)), ==,
+                        l2cc_way_mask_test_value(i));
+    }
+    g_assert_cmphex(qtest_readq(qts,
+                                L2CC_BASE + L2CC_WAY_MASK(L2CC_MAX_MASTERS)),
+                    ==, 0);
+    qtest_writel(qts, zero_last, 0x12345678);
+    qtest_writel(qts, L2_ZERO_BASE + L2_ZERO_SIZE, 0xdeadc0de);
+    g_assert_cmphex(qtest_readl(qts, L2_ZERO_BASE + L2_ZERO_SIZE), ==, 0);
+    qtest_writeb(qts, L2CC_BASE + L2CC_WAY_ENABLE, 15);
+    g_assert_cmphex(qtest_readl(qts, zero_last), ==, 0x12345678);
+    g_assert_cmphex(qtest_readl(qts, L2_LIM_BASE), ==, 0);
+
+    qtest_system_reset(qts);
+    for (i = 0; i < L2CC_MAX_MASTERS; i++) {
+        g_assert_cmphex(qtest_readq(qts, L2CC_BASE + L2CC_WAY_MASK(i)), ==,
+                        L2CC_WAY_MASK_RESET);
+    }
+    qtest_quit(qts);
+}
+
+static void test_l2cc_migration(void)
+{
+    g_autofree char *firmware = sifive_l2cc_create_firmware();
+    QTestState *from = sifive_l2cc_start(firmware);
+    QTestState *to = qtest_initf(
+        "-machine microchip-icicle-kit -smp 5 -m 2G "
+        "-bios \"%s\" -incoming defer", firmware);
+    const uint64_t hidden = L2_LIM_BASE + 8 * L2_WAY_SIZE;
+    const uint64_t zero_last = L2_ZERO_BASE + L2_ZERO_SIZE - 4;
+
+    unlink(firmware);
+
+    qtest_writel(from, L2_LIM_BASE, 0x11223344);
+    qtest_writel(from, hidden, 0x55667788);
+    qtest_writel(from, zero_last, 0x99aabbcc);
+    qtest_writeb(from, L2CC_BASE + L2CC_WAY_ENABLE, 7);
+    qtest_writeq(from, L2CC_BASE + L2CC_WAY_MASK(14), 0x1234);
+    g_assert_cmphex(qtest_readl(from, hidden), ==, 0);
+
+    migrate_incoming_qmp(to, "tcp:127.0.0.1:0", NULL, "{}");
+    migrate_qmp(from, to, NULL, NULL, "{}");
+    wait_for_migration_complete(from);
+
+    g_assert_cmphex(qtest_readb(to, L2CC_BASE + L2CC_WAY_ENABLE), ==, 7);
+    g_assert_cmphex(qtest_readq(to, L2CC_BASE + L2CC_WAY_MASK(14)), ==, 0x1234);
+    g_assert_cmphex(qtest_readl(to, L2_LIM_BASE), ==, 0x11223344);
+    g_assert_cmphex(qtest_readl(to, hidden), ==, 0);
+    qtest_writel(to, hidden, 0xdeadc0de);
+    g_assert_cmphex(qtest_readl(to, zero_last), ==, 0x99aabbcc);
+
+    qtest_system_reset(to);
+    g_assert_cmphex(qtest_readb(to, L2CC_BASE + L2CC_WAY_ENABLE), ==, 0);
+    g_assert_cmphex(qtest_readl(to, hidden), ==, 0x55667788);
+    g_assert_cmphex(qtest_readl(to, zero_last), ==, 0x99aabbcc);
+
+    qtest_quit(from);
+    qtest_quit(to);
+}
+
+static void test_l2cc_unimplemented(void)
+{
+    g_autofree char *firmware = sifive_l2cc_create_firmware();
+    g_autofree char *log_path = NULL;
+    g_autofree char *log = NULL;
+    QTestState *qts;
+    int fd;
+
+    fd = g_file_open_tmp("sifive_l2cc_unimp_XXXXXX", &log_path, NULL);
+    g_assert_cmpint(fd, >=, 0);
+    close(fd);
+
+    qts = qtest_initf(
+        "-machine microchip-icicle-kit -smp 5 -m 2G -bios \"%s\" "
+        "-d unimp -D \"%s\"", firmware, log_path);
+    unlink(firmware);
+
+    g_assert_cmphex(qtest_readl(qts, L2CC_BASE + L2CC_ECC_INJECT), ==, 0);
+    qtest_writeq(qts, L2CC_BASE + L2CC_FLUSH64, 0x1234);
+    g_assert_cmphex(qtest_readq(qts, L2CC_BASE + L2CC_MASTER15), ==, 0);
+    qtest_quit(qts);
+
+    g_assert_true(g_file_get_contents(log_path, &log, NULL, NULL));
+    g_assert_nonnull(strstr(log,
+        "unimplemented device read (size 4, offset 0x40)"));
+    g_assert_nonnull(strstr(log,
+        "unimplemented device write (size 8, value 0x1234, offset 0x200)"));
+    g_assert_nonnull(strstr(log,
+        "unimplemented device read (size 8, offset 0x878)"));
+    unlink(log_path);
+}
+
+int main(int argc, char **argv)
+{
+    g_test_init(&argc, &argv, NULL);
+
+    if (qtest_has_machine("microchip-icicle-kit")) {
+        qtest_add_func("/sifive_l2cc/registers", test_l2cc_registers);
+        qtest_add_func("/sifive_l2cc/l2lim_topology", test_l2lim_topology);
+        qtest_add_func("/sifive_l2cc/unimplemented", test_l2cc_unimplemented);
+        qtest_add_func("/sifive_l2cc/migration", test_l2cc_migration);
+    }
+    if (qtest_has_machine("sifive_u")) {
+        qtest_add_func("/sifive_l2cc/master_count", test_l2cc_master_count);
+    }
+
+    return g_test_run();
+}
tests/qtest/meson.build +3 -0
index ff4bf9528a..a001409de2 100644
@@ -317,6 +317,7 @@ qtests_riscv32 = \
 
  qtests_riscv64 = ['riscv-csr-test'] + \
    (unpack_edk2_blobs ? ['bios-tables-test'] : []) + \
+  (config_all_devices.has_key('CONFIG_SIFIVE_L2CC') ? ['sifive_l2cc_test'] : []) + \
    (config_all_devices.has_key('CONFIG_IOMMU_TESTDEV') and
     config_all_devices.has_key('CONFIG_RISCV_IOMMU') ?
     ['iommu-riscv-test'] : []) + \
@@ -438,6 +439,8 @@ qtests = {
    'erst-test': files('erst-test.c'),
    'ivshmem-test': [rt, '../../contrib/ivshmem-server/ivshmem-server.c'],
    'migration-test': test_migration_files + migration_tls_files + migration_colo_files,
+  'sifive_l2cc_test': files('migration/migration-qmp.c',
+                           'migration/migration-util.c'),
    'pxe-test': files('boot-sector.c'),
    'pnv-xive2-test': files('pnv-xive2-common.c', 'pnv-xive2-flush-sync.c',
                            'pnv-xive2-nvpg_bar.c'),
Reviewed-by on v5 11/26
#18 lore raw

Re: [PATCH v5 11/26] hw/sd: cadence: Add 64-bit system bus property

In reply to Bin Meng
Quoted 4 lines · Bin Meng

Cadence SDHCI integrations can differ in whether they provide a 64-bit system bus. Advertising the capability unconditionally could make a guest select unsupported ADMA descriptors.

Quoted 8 lines

Add a bus64bit property to the Cadence model and keep it disabled by default. When enabled, expose the corresponding capability through the generic SDHCI child.

---

hw/sd is not my turf but these changes are simple enough for me to ack.

Quoted 65 lines

(no changes since v2)

Changes in v2:
- Make 64-bit system bus support a device property

  include/hw/sd/cadence_sdhci.h |  1 +
  hw/sd/cadence_sdhci.c         | 11 +++++++++++
  2 files changed, 12 insertions(+)
include/hw/sd/cadence_sdhci.h +1 -0
index cd8288b7d8..553fa73842 100644
@@ -34,6 +34,7 @@ typedef struct CadenceSDHCIState {
      MemoryRegion container;
      MemoryRegion iomem;
      BusState *bus;
+    bool bus64bit;
 
      uint32_t regs[CADENCE_SDHCI_NUM_REGS];
 
hw/sd/cadence_sdhci.c +11 -0
index 8476baf67f..875823a50d 100644
@@ -25,6 +25,7 @@
  #include "qemu/error-report.h"
  #include "qapi/error.h"
  #include "migration/vmstate.h"
+#include "hw/core/qdev-properties.h"
  #include "hw/sd/cadence_sdhci.h"
  #include "sdhci-internal.h"
 
@@ -147,6 +148,11 @@ static void cadence_sdhci_realize(DeviceState *dev, Error **errp)
                            s, TYPE_CADENCE_SDHCI, CADENCE_SDHCI_REG_SIZE);
      memory_region_add_subregion(&s->container, 0, &s->iomem);
 
+    if (s->bus64bit) {
+        object_property_set_uint(OBJECT(&s->sdhci), "capareg",
+                                 SDHC_CAPAB_REG_DEFAULT |
+                                 R_SDHC_CAPAB_BUS64BIT_MASK, &error_abort);
+    }
      sysbus_realize(sbd_sdhci, errp);
      memory_region_add_subregion(&s->container, CADENCE_SDHCI_SRS_BASE,
                                  sysbus_mmio_get_region(sbd_sdhci, 0));
@@ -165,6 +171,10 @@ static const VMStateDescription vmstate_cadence_sdhci = {
      },
  };
 
+static const Property cadence_sdhci_properties[] = {
+    DEFINE_PROP_BOOL("bus64bit", CadenceSDHCIState, bus64bit, false),
+};
+
  static void cadence_sdhci_class_init(ObjectClass *classp, const void *data)
  {
      DeviceClass *dc = DEVICE_CLASS(classp);
@@ -172,6 +182,7 @@ static void cadence_sdhci_class_init(ObjectClass *classp, const void *data)
      dc->desc = "Cadence SD/SDIO/eMMC Host Controller (SD4HC)";
      dc->realize = cadence_sdhci_realize;
      device_class_set_legacy_reset(dc, cadence_sdhci_reset);
+    device_class_set_props(dc, cadence_sdhci_properties);
      dc->vmsd = &vmstate_cadence_sdhci;
  }
 
Reviewed-by on v5 15/26
#23 lore raw

Re: [PATCH v5 15/26] tests/qtest: Add PolarFire SoC RTC coverage

In reply to Bin Meng
Quoted 10 lines · Bin Meng

Exercise RTC register masks, binary counter, upload and stop controls, alarm and wakeup interrupt behavior, reset state, and PLIC wiring on the Icicle Kit.

Also verify RTC state and pending interrupt migration, including streams from QEMU versions that predate the RTC device.

---

Quoted 368 lines

(no changes since v2)

Changes in v2:
- Expect the documented hardware state after RTC reset

  MAINTAINERS                       |   1 +
  tests/qtest/mchp_pfsoc_rtc_test.c | 315 ++++++++++++++++++++++++++++++
  tests/qtest/meson.build           |   5 +-
  3 files changed, 320 insertions(+), 1 deletion(-)

create mode 100644 tests/qtest/mchp_pfsoc_rtc_test.c

MAINTAINERS +1 -0
index a4e33654ef..a8343e3d55 100644
@@ -1834,6 +1834,7 @@ F: include/hw/misc/mchp_pfsoc_dmc.h
  F: include/hw/misc/mchp_pfsoc_ioscb.h
  F: include/hw/misc/mchp_pfsoc_sysreg.h
  F: include/hw/rtc/mchp_pfsoc_rtc.h
+F: tests/qtest/mchp_pfsoc_rtc_test.c
 
  Shakti C class SoC
  L: [email protected]
tests/qtest/mchp_pfsoc_rtc_test.c new file +315 -0
new file mode 100644
index 0000000000..ed96c15faa
@@ -0,0 +1,315 @@
+/*
+ * QTest testcase for the Microchip PolarFire SoC RTC
+ *
+ * Copyright (c) 2026 Process Mission
+ *
+ * Author:
+ *   Bin Meng <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/bitops.h"
+#include "qemu/bswap.h"
+#include "qemu/timer.h"
+#include "libqtest.h"
+#include "migration/migration-qmp.h"
+#include "migration/migration-util.h"
+
+#define RTC_BASE            0x20124000
+#define RTC_CONTROL         0x00
+#define RTC_MODE            0x04
+#define RTC_PRESCALER       0x08
+#define RTC_ALARM_LOWER     0x0c
+#define RTC_ALARM_UPPER     0x10
+#define RTC_COMPARE_LOWER   0x14
+#define RTC_COMPARE_UPPER   0x18
+#define RTC_DATETIME_LOWER  0x20
+#define RTC_DATETIME_UPPER  0x24
+#define RTC_RUNNING         BIT(0)
+#define RTC_STOP            BIT(1)
+#define RTC_ALARM_ON        BIT(2)
+#define RTC_ALARM_OFF       BIT(3)
+#define RTC_UPLOAD          BIT(5)
+#define RTC_MATCH           BIT(7)
+#define RTC_WAKEUP_CLEAR    BIT(8)
+#define RTC_WAKEUP_SET      BIT(9)
+#define RTC_UPDATED         BIT(10)
+#define RTC_WAKEUP_ENABLE   BIT(1)
+#define RTC_WAKEUP_RESET    BIT(2)
+#define RTC_WAKEUP_CONTINUE BIT(3)
+#define RTC_PRESCALER_MASK  0x03ffffff
+#define RTC_UPPER_MASK      0x3fffffff
+#define PLIC_BASE           0x0c000000
+#define PLIC_PENDING        0x1000
+#define PLIC_RTC_PENDING    (BIT(16) | BIT(17))
+#define ENVM_BASE           0x20220000
+#define HSS_HEADER_SIZE     0x100
+#define HSS_HEADER_JUMP     0x1000006f
+#define HSS_PAYLOAD_BASE    (ENVM_BASE + HSS_HEADER_SIZE)
+#define HSS_PAYLOAD_SIZE    8
+
+static QTestState *microchip_icicle_kit_start_rtc(const char *firmware)
+{
+    return qtest_initf(
+        "-machine microchip-icicle-kit -smp 5 -m 2G -bios \"%s\" "
+        "-rtc clock=vm", firmware);
+}
+
+static QTestState *microchip_icicle_kit_start_ext(const char *qemu_var,
+                                                  const char *firmware)
+{
+    g_autofree char *args = g_strdup_printf(
+        "-machine microchip-icicle-kit -smp 5 -m 2G -bios \"%s\"",
+        firmware);
+
+    return qtest_init_ext(qemu_var, args, NULL, true);
+}
+
+static char *create_firmware(void)
+{
+    uint8_t firmware[HSS_HEADER_SIZE + HSS_PAYLOAD_SIZE] = { 0 };
+    static const uint8_t payload[] = {
+        0x13, 0x00, 0x00, 0x00,
+        0x6f, 0x00, 0x00, 0x00,
+    };
+    char *path;
+    int fd;
+    ssize_t written;
+    unsigned int i;
+
+    stl_le_p(&firmware[0], HSS_HEADER_JUMP);
+    stl_le_p(&firmware[4], HSS_PAYLOAD_SIZE);
+    for (i = 0; i < 5; i++) {
+        stl_le_p(&firmware[8 + i * sizeof(uint32_t)], HSS_PAYLOAD_BASE);
+    }
+    memcpy(&firmware[HSS_HEADER_SIZE], payload, sizeof(payload));
+
+    fd = g_file_open_tmp("microchip-icicle-kit-XXXXXX", &path, NULL);
+    g_assert_cmpint(fd, >=, 0);
+
+    written = write(fd, firmware, sizeof(firmware));
+    g_assert_cmpint(written, ==, sizeof(firmware));
+    close(fd);
+
+    return path;
+}
+
+static uint64_t rtc_read_binary_count(QTestState *qts)
+{
+    uint64_t count = qtest_readl(qts, RTC_BASE + RTC_DATETIME_LOWER);
+
+    count |= (uint64_t)qtest_readl(qts,
+                                   RTC_BASE + RTC_DATETIME_UPPER) << 32;
+    return count;
+}
+
+static void test_rtc(void)
+{
+    g_autofree char *firmware = create_firmware();
+    QTestState *qts = microchip_icicle_kit_start_rtc(firmware);
+    uint32_t control;
+
+    unlink(firmware);
+    qtest_irq_intercept_out_named(qts, "/machine/soc/rtc", "sysbus-irq");
+
+    g_assert_cmphex(qtest_readl(qts, RTC_BASE + RTC_CONTROL), ==, 0);
+    g_assert_cmphex(rtc_read_binary_count(qts), ==, 0);
+    qtest_clock_step(qts, 2 * NANOSECONDS_PER_SECOND);
+    g_assert_cmphex(rtc_read_binary_count(qts), ==, 0);
+
+    qtest_writel(qts, RTC_BASE + RTC_MODE, UINT32_MAX);
+    qtest_writel(qts, RTC_BASE + RTC_PRESCALER, UINT32_MAX);
+    g_assert_cmphex(qtest_readl(qts, RTC_BASE + RTC_MODE), ==, 0xf);
+    g_assert_cmphex(qtest_readl(qts, RTC_BASE + RTC_PRESCALER), ==,
+                    RTC_PRESCALER_MASK);
+    qtest_writel(qts, RTC_BASE + RTC_MODE, 0);
+
+    qtest_writel(qts, RTC_BASE + RTC_CONTROL, RTC_STOP);
+    g_assert_cmphex(qtest_readl(qts, RTC_BASE + RTC_CONTROL) &
+                    RTC_RUNNING, ==, 0);
+    qtest_clock_step(qts, 2 * NANOSECONDS_PER_SECOND);
+    g_assert_cmphex(rtc_read_binary_count(qts), ==, 0);
+
+    qtest_writel(qts, RTC_BASE + RTC_DATETIME_LOWER, 42);
+    qtest_writel(qts, RTC_BASE + RTC_DATETIME_UPPER, 0);
+    qtest_writel(qts, RTC_BASE + RTC_CONTROL, RTC_UPLOAD);
+    g_assert_cmphex(rtc_read_binary_count(qts), ==, 42);
+    g_assert_cmphex(qtest_readl(qts, RTC_BASE + RTC_CONTROL) &
+                    (RTC_UPLOAD | RTC_UPDATED), ==, RTC_UPDATED);
+
+    qtest_writel(qts, RTC_BASE + RTC_CONTROL, RTC_RUNNING);
+    qtest_clock_step(qts, NANOSECONDS_PER_SECOND);
+    g_assert_cmphex(rtc_read_binary_count(qts), ==, 43);
+    qtest_writel(qts, RTC_BASE + RTC_CONTROL, RTC_WAKEUP_SET);
+    g_assert_true(qtest_get_irq(qts, 0));
+    qtest_writel(qts, RTC_BASE + RTC_CONTROL, RTC_WAKEUP_CLEAR);
+    g_assert_false(qtest_get_irq(qts, 0));
+
+    qtest_writel(qts, RTC_BASE + RTC_ALARM_LOWER, 45);
+    qtest_writel(qts, RTC_BASE + RTC_ALARM_UPPER, 0);
+    qtest_writel(qts, RTC_BASE + RTC_COMPARE_LOWER, UINT32_MAX);
+    qtest_writel(qts, RTC_BASE + RTC_COMPARE_UPPER, RTC_UPPER_MASK);
+    qtest_writel(qts, RTC_BASE + RTC_MODE,
+                 RTC_WAKEUP_ENABLE | RTC_WAKEUP_CONTINUE);
+    qtest_writel(qts, RTC_BASE + RTC_CONTROL, RTC_ALARM_ON);
+    g_assert_false(qtest_get_irq(qts, 0));
+    g_assert_false(qtest_get_irq(qts, 1));
+    control = qtest_readl(qts, RTC_BASE + RTC_CONTROL);
+    g_assert_cmphex(control & RTC_ALARM_ON, ==, RTC_ALARM_ON);
+    qtest_writel(qts, RTC_BASE + RTC_CONTROL, control | RTC_ALARM_OFF);
+    g_assert_cmphex(qtest_readl(qts, RTC_BASE + RTC_CONTROL) &
+                    RTC_ALARM_ON, ==, 0);
+    qtest_clock_step(qts, 2 * NANOSECONDS_PER_SECOND);
+    g_assert_false(qtest_get_irq(qts, 0));
+    g_assert_false(qtest_get_irq(qts, 1));
+
+    qtest_writel(qts, RTC_BASE + RTC_DATETIME_LOWER, 43);
+    qtest_writel(qts, RTC_BASE + RTC_CONTROL, RTC_UPLOAD);
+    qtest_writel(qts, RTC_BASE + RTC_CONTROL, RTC_ALARM_ON);
+    qtest_clock_step(qts, 2 * NANOSECONDS_PER_SECOND);
+    g_assert_true(qtest_get_irq(qts, 0));
+    g_assert_true(qtest_get_irq(qts, 1));
+    g_assert_cmphex(qtest_readl(qts, RTC_BASE + RTC_CONTROL) & RTC_MATCH,
+                    ==, RTC_MATCH);
+    qtest_writel(qts, RTC_BASE + RTC_CONTROL, RTC_ALARM_OFF);
+    g_assert_false(qtest_get_irq(qts, 0));
+    g_assert_false(qtest_get_irq(qts, 1));
+
+    qtest_writel(qts, RTC_BASE + RTC_DATETIME_LOWER, 0);
+    qtest_writel(qts, RTC_BASE + RTC_DATETIME_UPPER, 0);
+    qtest_writel(qts, RTC_BASE + RTC_CONTROL, RTC_UPLOAD);
+    qtest_writel(qts, RTC_BASE + RTC_ALARM_LOWER, 2);
+    qtest_writel(qts, RTC_BASE + RTC_MODE,
+                 RTC_WAKEUP_ENABLE | RTC_WAKEUP_RESET |
+                 RTC_WAKEUP_CONTINUE);
+    qtest_writel(qts, RTC_BASE + RTC_CONTROL, RTC_ALARM_ON);
+    qtest_clock_step(qts, 2 * NANOSECONDS_PER_SECOND);
+    g_assert_true(qtest_get_irq(qts, 0));
+    g_assert_cmphex(rtc_read_binary_count(qts), ==, 0);
+    g_assert_cmphex(qtest_readl(qts, RTC_BASE + RTC_CONTROL) &
+                    RTC_ALARM_ON, ==, RTC_ALARM_ON);
+    qtest_writel(qts, RTC_BASE + RTC_CONTROL, RTC_WAKEUP_CLEAR);
+    qtest_clock_step(qts, 2 * NANOSECONDS_PER_SECOND);
+    g_assert_true(qtest_get_irq(qts, 0));
+    g_assert_cmphex(rtc_read_binary_count(qts), ==, 0);
+    qtest_writel(qts, RTC_BASE + RTC_CONTROL, RTC_ALARM_OFF);
+    g_assert_false(qtest_get_irq(qts, 0));
+    g_assert_false(qtest_get_irq(qts, 1));
+
+    qtest_system_reset(qts);
+    g_assert_cmphex(qtest_readl(qts, RTC_BASE + RTC_CONTROL), ==, 0);
+    g_assert_cmphex(qtest_readl(qts, RTC_BASE + RTC_MODE), ==, 0);
+    g_assert_cmphex(qtest_readl(qts, RTC_BASE + RTC_PRESCALER), ==, 0);
+    g_assert_false(qtest_get_irq(qts, 0));
+    g_assert_false(qtest_get_irq(qts, 1));
+
+    qtest_quit(qts);
+}
+
+static void test_rtc_plic(void)
+{
+    g_autofree char *firmware = create_firmware();
+    QTestState *qts = microchip_icicle_kit_start_rtc(firmware);
+
+    unlink(firmware);
+
+    qtest_writel(qts, RTC_BASE + RTC_DATETIME_LOWER, 42);
+    qtest_writel(qts, RTC_BASE + RTC_DATETIME_UPPER, 0);
+    qtest_writel(qts, RTC_BASE + RTC_CONTROL, RTC_UPLOAD);
+    qtest_writel(qts, RTC_BASE + RTC_CONTROL, RTC_RUNNING);
+    qtest_writel(qts, RTC_BASE + RTC_ALARM_LOWER, 43);
+    qtest_writel(qts, RTC_BASE + RTC_ALARM_UPPER, 0);
+    qtest_writel(qts, RTC_BASE + RTC_COMPARE_LOWER, UINT32_MAX);
+    qtest_writel(qts, RTC_BASE + RTC_COMPARE_UPPER, RTC_UPPER_MASK);
+    qtest_writel(qts, RTC_BASE + RTC_MODE,
+                 RTC_WAKEUP_ENABLE | RTC_WAKEUP_CONTINUE);
+    qtest_writel(qts, RTC_BASE + RTC_CONTROL, RTC_ALARM_ON);
+    qtest_clock_step(qts, NANOSECONDS_PER_SECOND);
+
+    g_assert_cmphex(qtest_readl(qts, PLIC_BASE + PLIC_PENDING + 8) &
+                    PLIC_RTC_PENDING, ==, PLIC_RTC_PENDING);
+
+    qtest_quit(qts);
+}
+
+static void test_machine_migration(void)
+{
+    g_autofree char *firmware = create_firmware();
+    const char *old_qemu = g_getenv("QTEST_QEMU_BINARY_OLD");
+    QTestState *from;
+    QTestState *to = qtest_initf(
+        "-machine microchip-icicle-kit -smp 5 -m 2G "
+        "-bios \"%s\" -incoming defer "
+        "-rtc clock=vm", firmware);
+
+    qtest_irq_intercept_out_named(to, "/machine/soc/rtc", "sysbus-irq");
+
+    /* Allow an older QEMU source to exercise migration compatibility */
+    if (old_qemu) {
+        from = microchip_icicle_kit_start_ext("QTEST_QEMU_BINARY_OLD",
+                                              firmware);
+    } else {
+        from = microchip_icicle_kit_start_rtc(firmware);
+        qtest_writel(from, RTC_BASE + RTC_DATETIME_LOWER, 0x23456789);
+        qtest_writel(from, RTC_BASE + RTC_DATETIME_UPPER, 1);
+        qtest_writel(from, RTC_BASE + RTC_CONTROL, RTC_UPLOAD);
+        qtest_writel(from, RTC_BASE + RTC_CONTROL, RTC_RUNNING);
+        qtest_writel(from, RTC_BASE + RTC_ALARM_LOWER, 0x2345678b);
+        qtest_writel(from, RTC_BASE + RTC_ALARM_UPPER, 1);
+        qtest_writel(from, RTC_BASE + RTC_COMPARE_LOWER, UINT32_MAX);
+        qtest_writel(from, RTC_BASE + RTC_COMPARE_UPPER, RTC_UPPER_MASK);
+        qtest_writel(from, RTC_BASE + RTC_MODE,
+                     RTC_WAKEUP_ENABLE | RTC_WAKEUP_CONTINUE);
+        qtest_writel(from, RTC_BASE + RTC_CONTROL, RTC_ALARM_ON);
+        qtest_writel(from, RTC_BASE + RTC_CONTROL, RTC_WAKEUP_SET);
+        qtest_writel(from, RTC_BASE + RTC_PRESCALER, 999999);
+    }
+
+    unlink(firmware);
+
+    migrate_incoming_qmp(to, "tcp:127.0.0.1:0", NULL, "{}");
+    migrate_qmp(from, to, NULL, NULL, "{}");
+    wait_for_migration_complete(from);
+
+    if (old_qemu) {
+        g_assert_cmphex(qtest_readl(to, RTC_BASE + RTC_CONTROL), ==, 0);
+        g_assert_cmphex(qtest_readl(to, RTC_BASE + RTC_PRESCALER), ==, 0);
+        g_assert_false(qtest_get_irq(to, 0));
+        g_assert_false(qtest_get_irq(to, 1));
+    } else {
+        g_assert_cmphex(rtc_read_binary_count(to), ==, 0x123456789);
+        g_assert_cmphex(qtest_readl(to, RTC_BASE + RTC_CONTROL) &
+                        (RTC_RUNNING | RTC_ALARM_ON), ==,
+                        RTC_RUNNING | RTC_ALARM_ON);
+        g_assert_cmphex(qtest_readl(to, RTC_BASE + RTC_PRESCALER), ==,
+                        999999);
+        g_assert_true(qtest_get_irq(to, 0));
+        g_assert_false(qtest_get_irq(to, 1));
+        qtest_writel(to, RTC_BASE + RTC_CONTROL, RTC_WAKEUP_CLEAR);
+        g_assert_false(qtest_get_irq(to, 0));
+        qtest_clock_step(to, 2 * NANOSECONDS_PER_SECOND);
+        g_assert_cmphex(rtc_read_binary_count(to), ==, 0x12345678b);
+        g_assert_true(qtest_get_irq(to, 0));
+        g_assert_true(qtest_get_irq(to, 1));
+        qtest_writel(to, RTC_BASE + RTC_CONTROL, RTC_ALARM_OFF);
+        g_assert_false(qtest_get_irq(to, 0));
+        g_assert_false(qtest_get_irq(to, 1));
+    }
+
+    qtest_quit(from);
+    qtest_quit(to);
+}
+
+int main(int argc, char **argv)
+{
+    g_test_init(&argc, &argv, NULL);
+
+    qtest_add_func("/mchp_pfsoc_rtc/registers", test_rtc);
+    qtest_add_func("/mchp_pfsoc_rtc/plic", test_rtc_plic);
+    qtest_add_func("/mchp_pfsoc_rtc/migration",
+                   test_machine_migration);
+
+    return g_test_run();
+}
tests/qtest/meson.build +4 -1
index d08fbc1eb7..3fe0786af2 100644
@@ -318,7 +318,8 @@ qtests_riscv32 = \
  qtests_riscv64 = ['riscv-csr-test'] + \
    (unpack_edk2_blobs ? ['bios-tables-test'] : []) + \
    (config_all_devices.has_key('CONFIG_MICROCHIP_PFSOC') ?
-   ['cadence-sdhci-test'] : []) + \
+   ['cadence-sdhci-test',
+    'mchp_pfsoc_rtc_test'] : []) + \
    (config_all_devices.has_key('CONFIG_SIFIVE_L2CC') ? ['sifive_l2cc_test'] : []) + \
    (config_all_devices.has_key('CONFIG_IOMMU_TESTDEV') and
     config_all_devices.has_key('CONFIG_RISCV_IOMMU') ?
@@ -443,6 +444,8 @@ qtests = {
    'migration-test': test_migration_files + migration_tls_files + migration_colo_files,
    'sifive_l2cc_test': files('migration/migration-qmp.c',
                             'migration/migration-util.c'),
+  'mchp_pfsoc_rtc_test': files('migration/migration-qmp.c',
+                               'migration/migration-util.c'),
    'pxe-test': files('boot-sector.c'),
    'pnv-xive2-test': files('pnv-xive2-common.c', 'pnv-xive2-flush-sync.c',
                            'pnv-xive2-nvpg_bar.c'),
Reviewed-by on v5 22/26
#34 lore raw

Re: [PATCH v5 22/26] docs/system/riscv: Document Icicle Kit HSS boot

In reply to Bin Meng
Quoted 13 lines · Bin Meng

With all previous changes, the Icicle Kit model is now able to boot HSS v2026.04.1 through a Buildroot 2026.05 SD image to U-Boot and Linux.

Document the tested source versions and exact commands to build HSS and Buildroot. Include the sparse resize and GPT relocation steps needed to make the generated SD image usable by QEMU.

Explain the pinned firmware baseline and include the DDR pattern-test patch used by the versioned test image. Document the tool check needed for image-only builds and distinguish the DDR training failure from the two investigated multi-hart startup races. Describe their visible symptoms, affected source versions, and all three DTB supply paths.

Quoted 6 lines

Also describe the RAM and serial setup, boot stages, and remaining model limitations.

---

Quoted 167 lines

(no changes since v4)

Changes in v4:
- Use HSS v2026.04.1 and the v1.1.1 test-image recipe
- Select the SoftConsole toolchain explicitly
- Use the generated complete boot-mode-1 eNVM binary

Changes in v3:
- Include the DDR pattern-test patch used by the functional-test image
- Document the image-only FPGA programming tool check
- Describe startup-race symptoms and link the firmware investigations

  docs/system/riscv/microchip-icicle-kit.rst | 129 ++++++++++++++++++++-
  1 file changed, 123 insertions(+), 6 deletions(-)
docs/system/riscv/microchip-icicle-kit.rst +123 -6
index 138289a913..2159e8e461 100644
@@ -19,12 +19,14 @@ The ``microchip-icicle-kit`` machine supports the following devices:
  * 4 U54 cores
  * Core Level Interruptor (CLINT)
  * Platform-Level Interrupt Controller (PLIC)
-* L2 Loosely Integrated Memory (L2-LIM)
+* L2 cache controller, including L2-LIM and L2-Zero windows
  * DDR memory controller
+* System controller and system services mailbox
  * 5 MMUARTs
  * 1 DMA controller
  * 2 GEM Ethernet controllers
  * 1 SDHC storage controller
+* 1 Real-Time Clock
 
  The machine has a fixed 2 GiB of RAM. Other memory sizes are rejected.
  The machine defaults to all five harts. ``-smp`` may select two to five harts,
@@ -103,10 +105,125 @@ CAVEATS:
  Running HSS
  -----------
 
-The machine ``microchip-icicle-kit`` used to run the Hart Software Services
-(HSS_), however, the HSS development progressed and the QEMU machine
-implementation lacks behind.  Currently, running the HSS no longer works.
-There is missing support in the clock and memory controller devices.  In
-particular, reading from the SD card does not work.
+The ``microchip-icicle-kit`` machine can boot the Hart Software Services
+(HSS_), which then loads an HSS payload containing U-Boot from an SD card.
+The following flow was tested with HSS v2026.04.1 and Buildroot 2026.05.
+These versions reproduce the firmware and SD card images used by the
+functional test.
+
+Configure HSS for the ``mpfs-icicle-kit-es`` board using its default
+configuration. QEMU provides the software-visible registers and deterministic
+status consumed by the HSS v2026.04.1 DDR initialization and training flow;
+it does not model the electrical properties of DDR training. HSS requires
+the RISC-V bare-metal toolchain supplied by Microchip SoftConsole to be
+available in ``PATH``.
+
+The versioned test image applies the `DDR pattern-test fix`_ before building
+HSS. Without this fix, the DDR state machine can reuse uninitialized
+pattern-test parameters across calls, particularly with the SoftConsole
+GCC 8.3.0 toolchain. Apply the same patch when reproducing the test image:
+
+.. code-block:: bash
+
+  $ git clone https://github.com/polarfire-soc/hart-software-services.git
+  $ cd hart-software-services
+  $ git checkout v2026.04.1
+  $ curl -L -o ddr-pattern-test.patch \
+      https://raw.githubusercontent.com/processmission/qemu-machine-images/v1.1.1/machine/riscv64/microchip-icicle-kit/0001-mpfs_hal-preserve-DDR-pattern-test-parameters.patch
+  $ git apply ddr-pattern-test.patch
+  $ cp boards/mpfs-icicle-kit-es/def_config .config
+  $ echo CONFIG_CC_USE_SOFTCONSOLE=y >> .config
+  $ FPGENPROG=/bin/true make -j$(nproc) BOARD=mpfs-icicle-kit-es
+
+``FPGENPROG=/bin/true`` satisfies the boot-mode programmer's FPGA programming
+tool check when generating an image for QEMU; no physical device is programmed.
+
+The HSS build creates the complete eNVM image, including the 256-byte
+boot header with the image size and per-hart reset vectors. Copy it to
+``build/hss.bin`` for the QEMU command below:
+
+.. code-block:: bash
+
+  $ cp build/bootmode1/hss-envm-wrapper-bm1-p0.bin build/hss.bin
+
+Do not pass ``build/hss-envm-wrapper.bin`` directly to QEMU. That file starts
+at eNVM offset 0x100 and does not contain the boot header with the image size
+and per-hart reset vectors.
+
+Build the SD card image with the tested Buildroot version:
+
+.. code-block:: bash
+
+  $ git clone https://gitlab.com/buildroot.org/buildroot.git
+  $ cd buildroot
+  $ git checkout 2026.05
+  $ make microchip_mpfs_icicle_defconfig
+  $ make
+
+This produces ``output/images/sdcard.img`` with three GPT partitions:
+
+* An HSS ``payload.bin`` containing U-Boot.
+* A FAT partition containing ``boot.scr`` and the kernel FIT image.
+* An ext4 Linux root filesystem.
+
+The QEMU SD card model requires a power-of-two image size. Make a sparse
+4 GiB working copy and relocate its backup GPT to the new end of the image:
+
+.. code-block:: bash
+
+  $ cp --reflink=auto output/images/sdcard.img sdcard.img
+  $ truncate -s 4G sdcard.img
+  $ sgdisk -e sdcard.img
+  $ sgdisk -v sdcard.img
+
+The Icicle Kit firmware device tree in the FIT image describes 2 GiB of RAM,
+matching the machine's fixed RAM size. The command below keeps ``-m 2G``
+explicit.  Attach the image as an SD card and route both board serial ports:
+
+.. code-block:: bash
+
+  $ qemu-system-riscv64 \
+      -M microchip-icicle-kit -smp 5 -m 2G \
+      -bios path/to/hss/build/hss.bin \
+      -drive if=sd,file=path/to/sdcard.img,format=raw \
+      -display none \
+      -serial file:hss.log \
+      -serial stdio \
+      -no-reboot
+
+HSS writes to MMUART0, which the command records in ``hss.log``. U-Boot and
+Linux use MMUART1, which remains connected to the terminal. A successful
+boot proceeds through HSS payload loading, U-Boot, the Linux kernel, and the
+login prompt from the root filesystem on the third partition.
+
+Known limitations
+-----------------
+
+* Two potential multi-hart startup races were reproduced with HSS v2024.06
+  under QEMU. The affected code paths are also present in the inspected
+  HSS v2026.04.1 sources; they have not been reproduced on physical hardware.
+  See `HSS startup races`_ for the investigation and affected source versions.
+
+  * In the eNVM wrapper, a late U54 can clear the decompression completion
+    flag after E51 has set it. A boot can stop before all harts enter HSS,
+    with the affected U54s waiting in ``wait_for_decompress_done``.
+  * After DDR training and payload loading, a U54 other than the configured
+    payload owner can win the OpenSBI coldboot lottery. With the minimal DTB
+    describing only ``cpu@1``, U-Boot on another hart can repeatedly print
+    ``Could not initialize timer (err -19)`` and ``resetting ...``.
+
+* Without the DDR pattern-test fix above, some GCC 8.3.0 builds remain at
+  60% DDR training progress while QEMU keeps running. This is a separate
+  firmware parameter-lifetime issue; see `DDR pattern-test issue`_.
+* The SD card model requires the raw image size to be a power of two. Keep
+  the backup GPT header at the end when resizing the image.
+* The machine does not generate an Icicle Kit device tree. Firmware boot can
+  obtain a DTB built into HSS, included in an HSS payload, or supplied by
+  subsequent software, such as U-Boot or a kernel FIT image. The DTB must
+  describe the selected hart topology and the modeled reference-design DDR
+  windows. Direct kernel boot must use ``-dtb`` as described above.
 
  .. _HSS: https://github.com/polarfire-soc/hart-software-services
+.. _DDR pattern-test fix: https://github.com/processmission/qemu-machine-images/blob/v1.1.1/machine/riscv64/microchip-icicle-kit/0001-mpfs_hal-preserve-DDR-pattern-test-parameters.patch
+.. _DDR pattern-test issue: https://github.com/polarfire-soc/platform/issues/36
+.. _HSS startup races: https://github.com/polarfire-soc/hart-software-services/issues/106
Reviewed-by on v5 23/26
#36 lore raw

Re: [PATCH v5 23/26] docs/system/riscv: pfsoc: Document CLINT topology for direct Linux boot

In reply to Bin Meng
Quoted 5 lines · Bin Meng

The generic OpenSBI platform derives the CLINT first hart and register slot count from interrupts-extended. Some S-mode-only MPFS device trees mask the E51 M-mode interrupt entries with 0xffffffff, which shifts the MSIP and MTIMECMP slots when the same DTB is used for direct boot.

Quoted 7 lines

Document the complete five-hart CLINT node. Require interrupts 3 and 7 for hart 0 as well as the U54 harts.

---

Quoted 45 lines

(no changes since v3)

Changes in v3:
- Explain how reduced hart topologies change the CLINT DTB tuples

  docs/system/riscv/microchip-icicle-kit.rst | 26 +++++++++++++++++++++-
  1 file changed, 25 insertions(+), 1 deletion(-)
docs/system/riscv/microchip-icicle-kit.rst +25 -1
index 2159e8e461..038ea7221f 100644
@@ -66,7 +66,31 @@ should meet the following requirements:
    option.
 
  * It should contain a node for the CLINT device with a compatible string
-  "riscv,clint0".
+  "riscv,clint0" or "sifive,clint0".  Its ``interrupts-extended`` property
+  must describe the M-mode software interrupt (3) and timer interrupt (7) for
+  every hart, including the E51 hart 0.
+
+For example, the default five-hart Icicle Kit CLINT node can be described as:
+
+.. code-block:: none
+
+    clint: clint@2000000 {
+        compatible = "sifive,fu540-c000-clint", "sifive,clint0";
+        reg = <0x0 0x2000000 0x0 0xc000>;
+        interrupts-extended = <&cpu0_intc 3>, <&cpu0_intc 7>,
+                              <&cpu1_intc 3>, <&cpu1_intc 7>,
+                              <&cpu2_intc 3>, <&cpu2_intc 7>,
+                              <&cpu3_intc 3>, <&cpu3_intc 7>,
+                              <&cpu4_intc 3>, <&cpu4_intc 7>;
+    };
+
+When selecting fewer harts with ``-smp``, remove the absent hart nodes and their
+CLINT interrupt tuples from the DTB while retaining the E51 hart 0 entries.
+
+Do not replace the hart 0 interrupt numbers with ``0xffffffff`` when the same
+DTB is used to initialize the generic OpenSBI platform.  OpenSBI derives the
+first hart and the number of CLINT register slots from these interrupt tuples;
+masking hart 0 would shift the per-hart MSIP and MTIMECMP register mappings.
 
  When ``-bios`` is not specified or set to ``default``, the OpenSBI
  ``fw_dynamic`` BIOS image for the ``generic`` platform is used to boot an
#42 lore raw
In reply to Bin Meng
Quoted 62 lines · Bin Meng
Quoted 60 lines · Bin Meng

The microchip-icicle-kit machine was originally validated with an older Hart Software Services (HSS) firmware stack. HSS v2026.04.1 cannot boot through U-Boot to Linux because several firmware-visible parts of the PolarFire SoC are missing or incomplete.

The first failure occurs before the UART is initialized because the L2 zero window is not mapped. HSS then needs additional L2 cache controller and DDR training behavior. Later boot stages exercise system services, the RTC, SDHC version 4 DMA, and high-capacity SD card block sizing, along with the complete DDR aliases. The existing models ither reject these accesses or expose behavior that does not match the hardware specifications.

This series restores the complete firmware boot flow. With these changes, QEMU boots the HSS v2026.04.1 eNVM image, loads its U-Boot payload from an SD card, and reaches the Buildroot 2026.05 Linux login prompt.

The changes are organized around the firmware boot sequence:

* Correct the L2-LIM size, map the L2 zero window, and provide the DMC status transitions required by HSS DDR initialization.
* Model the documented L2CC Config, WayEnable, and WayMask registers, and resize L2-LIM as cache ways are enabled.
* Complete SDHCI version 4 support used by the Cadence controller, including Host Control 2, SDMA system addressing, 64-bit ADMA2 descriptors, and SDMA boundary continuation.
* Run ADMA from a bounded timer-driven engine instead of performing work from command or unrelated MMIO accesses. This keeps DMA progress independent of guest register traffic and avoids consuming a polling deadline inside the command write.
* Advertise the Cadence controller's 64-bit system bus support.
* Add the PolarFire SoC serial-number system service and RTC, and honor the system-service notification control bit.
* Correct the DDR aliases and fix the board topology at its physical configuration of 2 GiB of RAM and five harts.
* Document direct and HSS boot, add focused qtests and a full firmware functional test, and restore the machine's Supported maintainer status.

Testing performed:

* Built qemu-system-riscv64 and the documentation.
* Passed various newly added qtests.
* Booted HSS v2026.04.1, U-Boot, and Buildroot 2026.05 Linux to the login prompt using the functional-test image.

The functional test uses the processmission/qemu-machine-images release v1.1.1 tarball:

https://github.com/processmission/qemu-machine-images/releases/download/
v1.1.1/riscv64-microchip-icicle-kit-v1.1.1.tar.zst

When restoring the HSS boot support, 3 potential bugs were identified in the upstream HSS source codes that either blocks the DDR training from succeed or traps in a multi-core race at the very beginning or after a succesfully DDR training but stuck at OpenSBI/U-Boot hand-off. There are already bug reports filed aginst various upstream projects.

Quoted 8 lines
Quoted 5 lines

Changes in v5:
- Select REGISTER to fix riscv32-softmmu link failures
- Rebase onto origin/master
- Drop the high-capacity SD block-size fix already merged upstream

Patch 8/11/15/22/23 still doesn't have any RB/TB tags. Ping for review?

Only #10 needs a review or testing tag. Ping?

Regards,
Bin

Acked-by on v5 5/26
#7 lore raw

Re: [PATCH v5 05/26] hw/riscv: pfsoc: Map the SiFive L2CC memory windows

In reply to Bin Meng
Quoted 12 lines · Bin Meng

L2-LIM consists of cache SRAM ways controlled by L2CC WayEnable, and L2 Zero is the controller's scratchpad allocation interface. Creating their RAM stand-ins in the SoC and passing a LIM link splits ownership
of the register state and the memory views it controls.

Instantiate the shared SiFive L2CC with 15 masters and the existing 2 MiB modeled Zero aperture. Let the controller own the backing and both windows, and map its register, LIM, and Zero regions from the SoC.
Remove the external RAM allocations and the l2-lim link.

Quoted 8 lines

The device restores the visible LIM range after reset or migration. L2 Zero keeps its fixed aperture as a RAM approximation of scratchpad access rather than tracking the remaining LIM capacity.

Reviewed-by Daniel Henrique Barboza

<[email protected]>

Alistair

Quoted 135 lines

---

(no changes since v3)

Changes in v3:
- Configure and instantiate the shared SiFive L2CC
- Map the register, LIM, and Zero windows exposed by the controller
- Remove the external RAM allocations and l2-lim link
- Keep the PolarFire master count and modeled Zero aperture unchanged

 include/hw/riscv/microchip_pfsoc.h |  2 ++ hw/riscv/microchip_pfsoc.c         | 45 ++++++++++------------------ --
 hw/riscv/Kconfig                   |  1 +

 3 files changed, 17 insertions(+), 31 deletions(-)
include/hw/riscv/microchip_pfsoc.h +2 -0
index 612fd2b69c..18f5003850 100644
@@ -27,6 +27,7 @@
  #include "hw/cpu/cluster.h"
  #include "hw/dma/sifive_pdma.h"
  #include "hw/misc/mchp_pfsoc_dmc.h"
+#include "hw/misc/sifive_l2cc.h"
  #include "hw/misc/mchp_pfsoc_ioscb.h"
  #include "hw/misc/mchp_pfsoc_sysreg.h"
  #include "hw/net/cadence_gem.h"
@@ -43,6 +44,7 @@ typedef struct MicrochipPFSoCState {
      RISCVHartArrayState e_cpus;
      RISCVHartArrayState u_cpus;
      DeviceState *plic;
+    SiFiveL2CCState l2cc;
      MchpPfSoCDdrSgmiiPhyState ddr_sgmii_phy;
      MchpPfSoCDdrCfgState ddr_cfg;
      MchpPfSoCIoscbState ioscb;
hw/riscv/microchip_pfsoc.c +0 -0
index a91ca951de..d7613496f8 100644
@@ -175,6 +175,12 @@ static void
 microchip_pfsoc_soc_instance_init(Object *obj)
      object_initialize_child(obj, "dma-controller", &s->dma,
                              TYPE_SIFIVE_PDMA);


+    object_initialize_child(obj, "l2-cache-controller", &s->l2cc, +                            TYPE_SIFIVE_L2CC);
+    qdev_prop_set_uint32(DEVICE(&s->l2cc), "num-masters", 15); +    qdev_prop_set_uint64(DEVICE(&s->l2cc), "zero-size", +
microchip_pfsoc_memmap[MICROCHIP_PFSOC_L2ZERO].size);
+
     object_initialize_child(obj, "sysreg", &s->sysreg, TYPE_MCHP_PFSOC_SYSREG);

hw/riscv/microchip_pfsoc.c +0 -2
@@ -201,8 +207,6 @@ static void
 microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
      MemoryRegion *system_memory = get_system_memory();
      MemoryRegion *rsvd0_mem = g_new(MemoryRegion, 1);
      MemoryRegion *e51_dtim_mem = g_new(MemoryRegion, 1);
-    MemoryRegion *l2lim_mem = g_new(MemoryRegion, 1);
-    MemoryRegion *l2zero_mem = g_new(MemoryRegion, 1);
      MemoryRegion *envm_data = g_new(MemoryRegion, 1);
      MemoryRegion *qspi_xip_mem = g_new(MemoryRegion, 1);

     char *plic_hart_config;

hw/riscv/microchip_pfsoc.c +0 -0
@@ -261,35 +265,14 @@ static void
 microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
          RISCV_ACLINT_DEFAULT_MTIMECMP, RISCV_ACLINT_DEFAULT_MTIME,
          iks->clint_timebase_freq, 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);
-
-    /*
-     * HSS decompresses into the L2 zero-device window and executes there.
-     * Model it as RAM because QEMU does not model the backing L2 cache.
-     */
-    memory_region_init_ram(l2zero_mem, NULL, "microchip.pfsoc.l2zero",
-                           memmap[MICROCHIP_PFSOC_L2ZERO].size, -                           &error_fatal);
-    memory_region_add_subregion(system_memory,
-                                memmap[MICROCHIP_PFSOC_L2ZERO].base, -                                l2zero_mem);
+    /* The L2CC owns the SRAM backing and both software-visible windows */
+    sysbus_realize(SYS_BUS_DEVICE(&s->l2cc), errp);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->l2cc), SIFIVE_L2CC_MMIO_REGS, +                    memmap[MICROCHIP_PFSOC_L2CC].base);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->l2cc), SIFIVE_L2CC_MMIO_LIM, +                    memmap[MICROCHIP_PFSOC_L2LIM].base); +    sysbus_mmio_map(SYS_BUS_DEVICE(&s->l2cc), SIFIVE_L2CC_MMIO_ZERO, +                    memmap[MICROCHIP_PFSOC_L2ZERO].base);
     /* create PLIC hart topology configuration string */ plic_hart_config = riscv_plic_hart_config_string(ms->smp.cpus);

hw/riscv/Kconfig +0 -0
index d89fdfcc86..a22ef994eb 100644
@@ -21,6 +21,7 @@ config MICROCHIP_PFSOC

     select MCHP_PFSOC_MMUART
     select MCHP_PFSOC_SYSREG
     select RISCV_ACLINT
+    select SIFIVE_L2CC
     select SIFIVE_PDMA
     select SIFIVE_PLIC
     select UNIMP

Reviewed-by on v5 4/26
#5 lore raw

Re: [PATCH v5 04/26] hw/misc: Add SiFive L2 cache controller model

In reply to Bin Meng
Quoted 370 lines · Bin Meng

FU540 and PolarFire use the same SiFive L2 configuration and way- control
interface. Implement Config, monotonic WayEnable, and indexed WayMask registers with a configurable master count for the 21-master FU540 and
15-master PolarFire integrations.

Own the fixed 2 MiB SRAM backing inside the controller and expose the remaining LIM ways through a resizable alias. Also expose a separately
sized L2 Zero window backed by RAM to approximate scratchpad accesses.
The Zero aperture is independent of the cache/LIM way partition; cache
allocation, replacement, coherence, and ECC remain unimplemented.

Export register, LIM, and Zero windows for the SoC to map.

---

Changes in v5:
- Select REGISTER to fix riscv32-softmmu link failures

Changes in v3:
- Name the QOM parent field parent_obj
- Move the LIM and Zero windows into L2CC
- Use the shared SiFive name and indexed WayMask registers
- Parameterize master count and the RAM-backed Zero aperture
- Resize a LIM alias while keeping its SRAM backing fixed

Changes in v2:
- Use the Resettable API instead of a legacy reset handler

 include/hw/misc/sifive_l2cc.h |  42 +++++
 hw/misc/sifive_l2cc.c         | 282
++++++++++++++++++++++++++++++++++
 hw/misc/Kconfig               |   4 +
 hw/misc/meson.build           |   1 +

 4 files changed, 329 insertions(+)

 create mode 100644 include/hw/misc/sifive_l2cc.h
 create mode 100644 hw/misc/sifive_l2cc.c

include/hw/misc/sifive_l2cc.h new file +42 -0
new file mode 100644
index 0000000000..b1cd9c4054
@@ -0,0 +1,42 @@
+/*
+ * SiFive L2 cache controller
+ *
+ * Copyright (c) 2026 Process Mission
+ *
+ * Author:
+ *   Bin Meng <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef SIFIVE_L2CC_H
+#define SIFIVE_L2CC_H
+
+#include "hw/core/register.h"
+#include "hw/core/sysbus.h"
+
+#define SIFIVE_L2CC_REG_SIZE    0x1000
+#define SIFIVE_L2CC_REG_NUM     (SIFIVE_L2CC_REG_SIZE / 8)
+#define SIFIVE_L2CC_MAX_MASTERS 21
+
+enum {
+    SIFIVE_L2CC_MMIO_REGS,
+    SIFIVE_L2CC_MMIO_LIM,
+    SIFIVE_L2CC_MMIO_ZERO,
+};
+
+typedef struct SiFiveL2CCState {
+    SysBusDevice parent_obj;
+    uint64_t regs[SIFIVE_L2CC_REG_NUM];
+    RegisterInfo regs_info[SIFIVE_L2CC_REG_NUM];
+    MemoryRegion lim_ram;
+    MemoryRegion lim;
+    MemoryRegion zero;
+    uint32_t num_masters;
+    uint64_t zero_size;
+} SiFiveL2CCState;
+
+#define TYPE_SIFIVE_L2CC "sifive.l2cc"
+OBJECT_DECLARE_SIMPLE_TYPE(SiFiveL2CCState, SIFIVE_L2CC)
+
+#endif
hw/misc/sifive_l2cc.c new file +37 -0
new file mode 100644
index 0000000000..f99c44b301
@@ -0,0 +1,282 @@
+/*
+ * SiFive L2 cache controller
+ *
+ * Copyright (c) 2026 Process Mission
+ *
+ * Author:
+ *   Bin Meng <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/log.h"
+#include "qemu/units.h"
+#include "qapi/error.h"
+#include "hw/core/qdev-properties.h"
+#include "hw/core/register.h"
+#include "hw/core/registerfields.h"
+#include "hw/misc/sifive_l2cc.h"
+#include "migration/vmstate.h"
+
+REG64(L2_CONFIG, 0x000)
+    FIELD(L2_CONFIG, BANKS, 0, 8)
+    FIELD(L2_CONFIG, WAYS, 8, 8)
+    FIELD(L2_CONFIG, LG_SETS, 16, 8)
+    FIELD(L2_CONFIG, LG_BLOCK_BYTES, 24, 8)
+REG64(L2_WAY_ENABLE, 0x008)
+    FIELD(L2_WAY_ENABLE, VALUE, 0, 8)
+REG64(L2_WAY_MASK, 0x800)
+
+#define L2_CONFIG_RESET         0x06091004
+#define L2_LIM_WAY_COUNT        15
+#define L2_WAY_SIZE             (128 * KiB)
+#define L2_CACHE_SIZE           (2 * MiB)
+#define L2_ZERO_MAX_SIZE        (32 * MiB)
+
+static void sifive_l2cc_update_l2lim(SiFiveL2CCState *s, uint64_t

way_enable)

hw/misc/sifive_l2cc.c new file +83 -0
+{
+    uint64_t l2lim_size;
+
+    if (way_enable >= L2_LIM_WAY_COUNT) {
+        l2lim_size = 0;
+    } else {
+        l2lim_size = (L2_LIM_WAY_COUNT - way_enable) * L2_WAY_SIZE;
+    }
+
+    memory_region_transaction_begin();
+    memory_region_set_size(&s->lim, l2lim_size);
+    memory_region_set_enabled(&s->lim, l2lim_size != 0);
+    memory_region_transaction_commit();
+}
+
+static uint64_t sifive_l2cc_way_enable_pre_write(RegisterInfo *reg,
+                                                 uint64_t value)
+{
+    uint64_t current = *(uint64_t *)reg->data;
+
+    return MAX(current, value);
+}
+
+static void sifive_l2cc_way_enable_post_write(RegisterInfo *reg,
+                                              uint64_t value)
+{
+    SiFiveL2CCState *s = SIFIVE_L2CC(reg->opaque);
+
+    sifive_l2cc_update_l2lim(s, value);
+}
+
+#define WAY_MASK_REGISTER(_id)                  \
+    {                                           \
+        .name = "WAY_MASK_" #_id,               \
+        .addr = A_L2_WAY_MASK + 8 * (_id),       \
+        .reset = UINT64_MAX,                    \
+    }
+
+static const RegisterAccessInfo sifive_l2cc_regs_info[] = {
+    {
+        .name = "CONFIG",
+        .addr = A_L2_CONFIG,
+        .reset = L2_CONFIG_RESET,
+        .ro = UINT64_MAX,
+    }, {
+        .name = "WAY_ENABLE",
+        .addr = A_L2_WAY_ENABLE,
+        .rsvd = ~R_L2_WAY_ENABLE_VALUE_MASK,
+        .pre_write = sifive_l2cc_way_enable_pre_write,
+        .post_write = sifive_l2cc_way_enable_post_write,
+    },
+    WAY_MASK_REGISTER(0),
+    WAY_MASK_REGISTER(1),
+    WAY_MASK_REGISTER(2),
+    WAY_MASK_REGISTER(3),
+    WAY_MASK_REGISTER(4),
+    WAY_MASK_REGISTER(5),
+    WAY_MASK_REGISTER(6),
+    WAY_MASK_REGISTER(7),
+    WAY_MASK_REGISTER(8),
+    WAY_MASK_REGISTER(9),
+    WAY_MASK_REGISTER(10),
+    WAY_MASK_REGISTER(11),
+    WAY_MASK_REGISTER(12),
+    WAY_MASK_REGISTER(13),
+    WAY_MASK_REGISTER(14),
+    WAY_MASK_REGISTER(15),
+    WAY_MASK_REGISTER(16),
+    WAY_MASK_REGISTER(17),
+    WAY_MASK_REGISTER(18),
+    WAY_MASK_REGISTER(19),
+    WAY_MASK_REGISTER(20),
+};
+
+static bool sifive_l2cc_register_implemented(SiFiveL2CCState *s,
+                                             hwaddr offset)
+{
+    if (offset == A_L2_CONFIG || offset == A_L2_WAY_ENABLE) {
+        return true;
+    }
+
+    return offset >= A_L2_WAY_MASK &&
+           offset < A_L2_WAY_MASK + 8 * s->num_masters && !(offset &

7);

hw/misc/sifive_l2cc.c new file +74 -0
+}
+
+static uint64_t sifive_l2cc_read(void *opaque, hwaddr offset,
+                                 unsigned size)
+{
+    RegisterInfoArray *reg_array = opaque;
+    SiFiveL2CCState *s = SIFIVE_L2CC(reg_array->r[0]->opaque);
+
+    if (sifive_l2cc_register_implemented(s, offset)) {
+        return register_read_memory(opaque, offset, size);
+    }
+
+    qemu_log_mask(LOG_UNIMP, "%s: unimplemented device read "
+                  "(size %u, offset 0x%" HWADDR_PRIx ")\n",
+                  __func__, size, offset);
+    return 0;
+}
+
+static void sifive_l2cc_write(void *opaque, hwaddr offset,
+                              uint64_t value, unsigned size)
+{
+    RegisterInfoArray *reg_array = opaque;
+    SiFiveL2CCState *s = SIFIVE_L2CC(reg_array->r[0]->opaque);
+
+    if (sifive_l2cc_register_implemented(s, offset)) {
+        register_write_memory(opaque, offset, value, size);
+        return;
+    }
+
+    qemu_log_mask(LOG_UNIMP, "%s: unimplemented device write "
+                  "(size %u, value 0x%" PRIx64
+                  ", offset 0x%" HWADDR_PRIx ")\n",
+                  __func__, size, value, offset);
+}
+
+static const MemoryRegionOps sifive_l2cc_ops = {
+    .read = sifive_l2cc_read,
+    .write = sifive_l2cc_write,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+    .valid = { .min_access_size = 1, .max_access_size = 8 },
+    .impl = { .min_access_size = 1, .max_access_size = 8 },
+};
+
+static void sifive_l2cc_reset_hold(Object *obj, ResetType type)
+{
+    SiFiveL2CCState *s = SIFIVE_L2CC(obj);
+    size_t i;
+
+    memset(s->regs, 0, sizeof(s->regs));
+    for (i = 0; i < 2 + s->num_masters; i++) {
+        hwaddr addr = sifive_l2cc_regs_info[i].addr;
+
+        register_reset(&s->regs_info[addr / sizeof(uint64_t)]);
+    }
+}
+
+static void sifive_l2cc_init(Object *obj)
+{
+    SiFiveL2CCState *s = SIFIVE_L2CC(obj);
+    RegisterInfoArray *reg_array;
+
+    reg_array = register_init_block64(
+        DEVICE(obj), sifive_l2cc_regs_info,
+        ARRAY_SIZE(sifive_l2cc_regs_info), s->regs_info, s->regs,
+        &sifive_l2cc_ops, false, SIFIVE_L2CC_REG_SIZE);
+    sysbus_init_mmio(SYS_BUS_DEVICE(obj), &reg_array->mem);
+}
+
+static void sifive_l2cc_realize(DeviceState *dev, Error **errp)
+{
+    SiFiveL2CCState *s = SIFIVE_L2CC(dev);
+    SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
+
+    if (!s->num_masters || s->num_masters > SIFIVE_L2CC_MAX_MASTERS)

{
+        error_setg(errp, "num-masters must be between 1 and %u", +                   SIFIVE_L2CC_MAX_MASTERS);
+        return;
+    }
+    if (!s->zero_size || s->zero_size > L2_ZERO_MAX_SIZE) { +        error_setg(errp, "zero-size must be between 1 byte and 32 MiB");
+        return;
+    }
+
+    /* Keep the SRAM backing fixed while WayEnable changes the LIM alias */
+    if (!memory_region_init_ram(&s->lim_ram, OBJECT(dev), +                                TYPE_SIFIVE_L2CC ".lim-ram", +                                L2_CACHE_SIZE, errp)) { +        return;
+    }
+    memory_region_init_alias(&s->lim, OBJECT(dev), TYPE_SIFIVE_L2CC ".lim",
+                             &s->lim_ram, 0, L2_LIM_WAY_COUNT * L2_WAY_SIZE);
+    sysbus_init_mmio(sbd, &s->lim);
+
+    /*
+     * L2 Zero allocates into enabled cache ways without external memory
+     * backing. Use a separate RAM stand-in because QEMU does not model
+     * cache allocation, replacement, or coherence. Its aperture size is
+     * independent of the cache/LIM way partition.
+     */
+    if (!memory_region_init_ram(&s->zero, OBJECT(dev),
+                                TYPE_SIFIVE_L2CC ".zero", +                                s->zero_size, errp)) {
+        return;
+    }
+    sysbus_init_mmio(sbd, &s->zero);

hw/misc/sifive_l2cc.c new file +28 -0
+
+    sifive_l2cc_update_l2lim(s, s->regs[R_L2_WAY_ENABLE]);
+}
+
+static const Property sifive_l2cc_properties[] = {
+    DEFINE_PROP_UINT32("num-masters", SiFiveL2CCState, num_masters,
+                       SIFIVE_L2CC_MAX_MASTERS),
+    DEFINE_PROP_SIZE("zero-size", SiFiveL2CCState, zero_size,
+                     L2_ZERO_MAX_SIZE),
+};
+
+static int sifive_l2cc_post_load(void *opaque, int version_id)
+{
+    SiFiveL2CCState *s = opaque;
+
+    sifive_l2cc_update_l2lim(s, s->regs[R_L2_WAY_ENABLE]);
+    return 0;
+}
+
+static const VMStateDescription vmstate_sifive_l2cc = {
+    .name = TYPE_SIFIVE_L2CC,
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .post_load = sifive_l2cc_post_load,
+    .fields = (const VMStateField[]) {
+        VMSTATE_UINT32_EQUAL(num_masters, SiFiveL2CCState),
+        VMSTATE_UINT64_EQUAL(zero_size, SiFiveL2CCState),
+        VMSTATE_UINT64_ARRAY(regs, SiFiveL2CCState,

SIFIVE_L2CC_REG_NUM),
+        VMSTATE_END_OF_LIST()
+    },

hw/misc/sifive_l2cc.c new file +3 -0
+};
+
+static void sifive_l2cc_class_init(ObjectClass *klass, const void

*data)

hw/misc/sifive_l2cc.c line 266

Quoted 8 lines
hw/misc/sifive_l2cc.c new file +8 -0
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
+
+    rc->phases.hold = sifive_l2cc_reset_hold;
+    device_class_set_props(dc, sifive_l2cc_properties);
+    dc->realize = sifive_l2cc_realize;
+    dc->vmsd = &vmstate_sifive_l2cc;

This should be marked as user not creatable.

Otherwise:

Alistair

Quoted 51 lines
hw/misc/sifive_l2cc.c new file +16 -0
+}
+
+static const TypeInfo sifive_l2cc_info = {
+    .name = TYPE_SIFIVE_L2CC,
+    .parent = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(SiFiveL2CCState),
+    .instance_init = sifive_l2cc_init,
+    .class_init = sifive_l2cc_class_init,
+};
+
+static void sifive_l2cc_register_types(void)
+{
+    type_register_static(&sifive_l2cc_info);
+}
+
+type_init(sifive_l2cc_register_types)
hw/misc/Kconfig +0 -0
index 685b7ff1e7..9bd417af82 100644
@@ -239,6 +239,10 @@ config MCHP_PFSOC_IOSCB

 config MCHP_PFSOC_SYSREG
     bool

hw/misc/Kconfig +4 -0
+config SIFIVE_L2CC
+    bool
+    select REGISTER
+

 config SIFIVE_TEST
     bool

hw/misc/meson.build +0 -0
index fc3800baec..a1118e583f 100644
@@ -33,6 +33,7 @@ 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')) +system_ss.add(when: 'CONFIG_SIFIVE_L2CC', if_true:
files('sifive_l2cc.c'))
 system_ss.add(when: 'CONFIG_SIFIVE_TEST', if_true:
files('sifive_test.c'))
 system_ss.add(when: 'CONFIG_SIFIVE_E_PRCI', if_true:
files('sifive_e_prci.c'))
 system_ss.add(when: 'CONFIG_SIFIVE_E_AON', if_true:
files('sifive_e_aon.c'))

Acked-by on v5 6/26
#9 lore raw

Re: [PATCH v5 06/26] hw/riscv: sifive_u: Correct the L2LIM maximum mapped size

In reply to Bin Meng
Quoted 7 lines · Bin Meng

FU540 SoC has a 2MiB L2 cache, so the maximum mapped size of L2LIM should be set to 2MiB too.

Reviewed-by Daniel Henrique Barboza

<[email protected]>

Alistair

Quoted 24 lines

---

(no changes since v3)

Changes in v3:
- New

 hw/riscv/sifive_u.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
hw/riscv/sifive_u.c +1 -1
index b7d5e7b4da..1ac0d1bbd9 100644
@@ -72,7 +72,7 @@ static const MemMapEntry sifive_u_memmap[] = {
      [SIFIVE_U_DEV_CLINT] =    {  0x2000000,    0x10000 },
      [SIFIVE_U_DEV_L2CC] =     {  0x2010000,     0x1000 },
      [SIFIVE_U_DEV_PDMA] =     {  0x3000000,   0x100000 },
-    [SIFIVE_U_DEV_L2LIM] =    {  0x8000000,  0x2000000 },
+    [SIFIVE_U_DEV_L2LIM] =    {  0x8000000,   0x200000 },
      [SIFIVE_U_DEV_PLIC] =     {  0xc000000,  0x4000000 },
      [SIFIVE_U_DEV_PRCI] =     { 0x10000000,     0x1000 },
      [SIFIVE_U_DEV_UART0] =    { 0x10010000,     0x1000 },
Acked-by on v5 7/26
#11 lore raw

Re: [PATCH v5 07/26] hw/riscv: sifive_u: Use the shared SiFive L2 cache controller

In reply to Bin Meng
Quoted 11 lines · Bin Meng

FU540 and PolarFire use the same L2 configuration and way-control interface, with different master counts. The sifive_u machine currently leaves L2CC unimplemented and exposes L2-LIM as fixed RAM without WayEnable control.

Instantiate the shared SiFive L2CC with 21 masters and a modeled 2 MiB Zero window.

Reviewed-by Daniel Henrique Barboza

<[email protected]>

Alistair

Quoted 155 lines

---

(no changes since v3)

Changes in v3:
- New

 docs/system/riscv/sifive_u.rst |  2 +- include/hw/riscv/sifive_u.h    |  3 +++ hw/riscv/sifive_u.c            | 30 +++++++++++++----------------- hw/riscv/Kconfig               |  1 +

 4 files changed, 18 insertions(+), 18 deletions(-)
docs/system/riscv/sifive_u.rst +0 -0
index 0e4dcf3e70..e91853ffe2 100644
@@ -14,7 +14,7 @@ The ``sifive_u`` machine supports the following

devices:
 * Core Local Interruptor (CLINT)
 * Platform-Level Interrupt Controller (PLIC)
 * Power, Reset, Clock, Interrupt (PRCI)

docs/system/riscv/sifive_u.rst +1 -1
-* L2 Loosely Integrated Memory (L2-LIM)
+* L2 cache controller, including L2-LIM and L2-Zero windows

 * DDR memory controller
 * 2 UARTs
 * 1 GEM Ethernet controller

include/hw/riscv/sifive_u.h +1 -0
index aed966a62d..be5e6232ce 100644
@@ -28,6 +28,7 @@
  #include "hw/gpio/sifive_gpio.h"
  #include "hw/misc/sifive_u_otp.h"
  #include "hw/misc/sifive_u_prci.h"
+#include "hw/misc/sifive_l2cc.h"
  #include "hw/ssi/sifive_spi.h"
  #include "hw/timer/sifive_pwm.h"

include/hw/riscv/sifive_u.h +2 -0
@@ -45,6 +46,7 @@ typedef struct SiFiveUSoCState {
      RISCVHartArrayState e_cpus;
      RISCVHartArrayState u_cpus;
      DeviceState *plic;
+    SiFiveL2CCState l2cc;
      SiFiveUPRCIState prci;
      SIFIVEGPIOState gpio;
      SiFiveUOTPState otp;
@@ -82,6 +84,7 @@ enum {
      SIFIVE_U_DEV_L2CC,
      SIFIVE_U_DEV_PDMA,
      SIFIVE_U_DEV_L2LIM,
+    SIFIVE_U_DEV_L2ZERO,
      SIFIVE_U_DEV_PLIC,
      SIFIVE_U_DEV_PRCI,
      SIFIVE_U_DEV_UART0,
hw/riscv/sifive_u.c +5 -0
index 1ac0d1bbd9..3603cc2aa2 100644
@@ -73,6 +73,7 @@ static const MemMapEntry sifive_u_memmap[] = {
      [SIFIVE_U_DEV_L2CC] =     {  0x2010000,     0x1000 },
      [SIFIVE_U_DEV_PDMA] =     {  0x3000000,   0x100000 },
      [SIFIVE_U_DEV_L2LIM] =    {  0x8000000,   0x200000 },
+    [SIFIVE_U_DEV_L2ZERO] =   {  0xa000000,   0x200000 },
      [SIFIVE_U_DEV_PLIC] =     {  0xc000000,  0x4000000 },
      [SIFIVE_U_DEV_PRCI] =     { 0x10000000,     0x1000 },
      [SIFIVE_U_DEV_UART0] =    { 0x10010000,     0x1000 },
@@ -715,6 +716,10 @@ static void sifive_u_soc_instance_init(Object
 *obj)
      object_initialize_child(obj, "gem", &s->gem, TYPE_CADENCE_GEM);
      object_initialize_child(obj, "gpio", &s->gpio,
 TYPE_SIFIVE_GPIO);
      object_initialize_child(obj, "pdma", &s->dma, TYPE_SIFIVE_PDMA);
+    object_initialize_child(obj, "l2-cache-controller", &s->l2cc,
+                            TYPE_SIFIVE_L2CC);
+    qdev_prop_set_uint64(DEVICE(&s->l2cc), "zero-size",
+                         sifive_u_memmap[SIFIVE_U_DEV_L2ZERO].size);
      object_initialize_child(obj, "spi0", &s->spi0, TYPE_SIFIVE_SPI);

     object_initialize_child(obj, "spi2", &s->spi2, TYPE_SIFIVE_SPI); object_initialize_child(obj, "pwm0", &s->pwm[0], TYPE_SIFIVE_PWM);

hw/riscv/sifive_u.c +0 -1
@@ -728,7 +733,6 @@ static void sifive_u_soc_realize(DeviceState
 *dev, Error **errp)
      const MemMapEntry *memmap = sifive_u_memmap;
      MemoryRegion *system_memory = get_system_memory();
      MemoryRegion *mask_rom = g_new(MemoryRegion, 1);
-    MemoryRegion *l2lim_mem = g_new(MemoryRegion, 1);
      char *plic_hart_config;
      int i, j;

hw/riscv/sifive_u.c +0 -0
@@ -754,19 +758,14 @@ static void sifive_u_soc_realize(DeviceState
 *dev, Error **errp)
      memory_region_add_subregion(system_memory,
 memmap[SIFIVE_U_DEV_MROM].base,
                                  mask_rom);


-    /*
-     * 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, "riscv.sifive.u.l2lim", -                           memmap[SIFIVE_U_DEV_L2LIM].size, &error_fatal);
-    memory_region_add_subregion(system_memory, memmap[SIFIVE_U_DEV_L2LIM].base,
-                                l2lim_mem);
+    /* L2 cache controller, LIM, and Zero windows */
+    sysbus_realize(SYS_BUS_DEVICE(&s->l2cc), &error_fatal); +    sysbus_mmio_map(SYS_BUS_DEVICE(&s->l2cc), SIFIVE_L2CC_MMIO_REGS, +                    memmap[SIFIVE_U_DEV_L2CC].base);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->l2cc), SIFIVE_L2CC_MMIO_LIM, +                    memmap[SIFIVE_U_DEV_L2LIM].base);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->l2cc), SIFIVE_L2CC_MMIO_ZERO, +                    memmap[SIFIVE_U_DEV_L2ZERO].base);

     /* create PLIC hart topology configuration string */ plic_hart_config = riscv_plic_hart_config_string(ms->smp.cpus);

hw/riscv/sifive_u.c +0 -0
@@ -868,9 +867,6 @@ static void sifive_u_soc_realize(DeviceState
 *dev, Error **errp)
      create_unimplemented_device("riscv.sifive.u.dmc",
          memmap[SIFIVE_U_DEV_DMC].base,
 memmap[SIFIVE_U_DEV_DMC].size);


-    create_unimplemented_device("riscv.sifive.u.l2cc", -        memmap[SIFIVE_U_DEV_L2CC].base, memmap[SIFIVE_U_DEV_L2CC].size);
-
     sysbus_realize(SYS_BUS_DEVICE(&s->spi0), errp); sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi0), 0, memmap[SIFIVE_U_DEV_QSPI0].base);

hw/riscv/Kconfig +0 -0
index a22ef994eb..19c6667ed6 100644
@@ -116,6 +116,7 @@ config SIFIVE_U

     select CPU_CLUSTER
     select DEVICE_TREE
     select RISCV_ACLINT
+    select SIFIVE_L2CC
     select SIFIVE_GPIO
     select SIFIVE_PDMA
     select SIFIVE_PLIC

Acked-by on v5 8/26
#14 lore raw

Re: [PATCH v5 08/26] tests/qtest: Add SiFive L2 cache controller coverage

In reply to Bin Meng
Quoted 8 lines · Bin Meng

Exercise Config, WayEnable, and indexed WayMask registers on the PolarFire and FU540 integrations, including their different master counts, reset, monotonic writes, and unimplemented-register logging.

Verify that enabling cache ways hides the corresponding LIM range, while the controller's Zero window stays accessible. Check that reset restores hidden LIM data without clearing the Zero RAM stand-in.

Quoted 6 lines

Migrate register state and both RAM backings, verify the destination LIM view, and confirm that writes to hidden addresses do not alter the
data restored by a later reset.

Alistair

Quoted 402 lines

---

(no changes since v3)

Changes in v3:
- Rename the test for the shared SiFive L2CC model
- Exercise 15 masters on PolarFire and 21 masters on FU540

 MAINTAINERS                    |   1 +
 tests/qtest/sifive_l2cc_test.c | 306
+++++++++++++++++++++++++++++++++
 tests/qtest/meson.build        |   3 +

 3 files changed, 310 insertions(+)

 create mode 100644 tests/qtest/sifive_l2cc_test.c

MAINTAINERS +0 -0
index 55463103ff..4bef2dffb0 100644
@@ -1851,6 +1851,7 @@ F: docs/system/riscv/sifive_u.rst

 F: hw/*/*sifive*.c
 F: include/hw/*/*sifive*.h
 F: tests/functional/riscv64/test_sifive_u.py
+F: tests/qtest/sifive_l2cc_test.c

 Tenstorrent Machines
 M: Joel Stanley <[email protected]>

tests/qtest/sifive_l2cc_test.c new file +27 -0
new file mode 100644
index 0000000000..fef80f3438
@@ -0,0 +1,306 @@
+/*
+ * QTest testcase for the SiFive L2 cache controller
+ *
+ * Copyright (c) 2026 Process Mission
+ *
+ * Author:
+ *   Bin Meng <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/units.h"
+#include "libqtest.h"
+#include "migration/migration-qmp.h"
+#include "migration/migration-util.h"
+
+#define L2CC_BASE                       0x02010000
+#define L2CC_CONFIG                     0x000
+#define L2CC_CONFIG_VALUE               0x06091004
+#define L2CC_WAY_ENABLE                 0x008
+#define L2CC_ECC_INJECT                 0x040
+#define L2CC_FLUSH64                    0x200
+#define L2CC_WAY_MASK_BASE              0x800
+#define L2CC_WAY_MASK_COUNT             15
+#define L2CC_MAX_MASTERS                21
+#define L2CC_WAY_MASK(n)                (L2CC_WAY_MASK_BASE + 8 *

(n))
+#define L2CC_MASTER15
L2CC_WAY_MASK(L2CC_WAY_MASK_COUNT)

tests/qtest/sifive_l2cc_test.c new file +55 -0
+#define L2CC_WAY_ENABLE_RESET           0
+#define L2CC_WAY_MASK_RESET             UINT64_MAX
+
+#define L2_LIM_BASE                     0x08000000
+#define L2_WAY_SIZE                     (128 * KiB)
+#define L2_LIM_RESET_WAYS               15
+#define L2_ZERO_BASE                    0x0a000000
+#define L2_ZERO_SIZE                    (2 * MiB)
+
+static QTestState *sifive_l2cc_start(const char *firmware)
+{
+    return qtest_initf("-machine microchip-icicle-kit -smp 5 -m 2G "
+                       "-bios \"%s\"", firmware);
+}
+
+static char *sifive_l2cc_create_firmware(void)
+{
+    static const uint8_t firmware[] = {
+        0x13, 0x00, 0x00, 0x00,
+        0x6f, 0x00, 0x00, 0x00,
+    };
+    char *path;
+    int fd;
+    ssize_t written;
+
+    fd = g_file_open_tmp("sifive_l2cc_XXXXXX", &path, NULL);
+    g_assert_cmpint(fd, >=, 0);
+
+    written = write(fd, firmware, sizeof(firmware));
+    g_assert_cmpint(written, ==, sizeof(firmware));
+    close(fd);
+
+    return path;
+}
+
+static uint64_t l2cc_way_mask_test_value(unsigned int master)
+{
+    return UINT64_C(0xfedcba9876543201) + master;
+}
+
+static void test_l2cc_registers(void)
+{
+    g_autofree char *firmware = sifive_l2cc_create_firmware();
+    QTestState *qts = sifive_l2cc_start(firmware);
+    unsigned int i;
+
+    unlink(firmware);
+
+    g_assert_cmphex(qtest_readl(qts, L2CC_BASE + L2CC_CONFIG), ==,
+                    L2CC_CONFIG_VALUE);
+    qtest_writel(qts, L2CC_BASE + L2CC_CONFIG, UINT32_MAX);
+    g_assert_cmphex(qtest_readl(qts, L2CC_BASE + L2CC_CONFIG), ==,
+                    L2CC_CONFIG_VALUE);
+
+    g_assert_cmphex(qtest_readb(qts, L2CC_BASE + L2CC_WAY_ENABLE),

==,
+                    L2CC_WAY_ENABLE_RESET);
+    qtest_writeb(qts, L2CC_BASE + L2CC_WAY_ENABLE, 0xd); +    g_assert_cmphex(qtest_readb(qts, L2CC_BASE + L2CC_WAY_ENABLE), ==, 0xd);
+    qtest_writeb(qts, L2CC_BASE + L2CC_WAY_ENABLE, 3); +    g_assert_cmphex(qtest_readb(qts, L2CC_BASE + L2CC_WAY_ENABLE), ==, 0xd);
+    qtest_writeq(qts, L2CC_BASE + L2CC_WAY_ENABLE, 0xf); +    g_assert_cmphex(qtest_readq(qts, L2CC_BASE + L2CC_WAY_ENABLE), ==, 0xf);
+    qtest_writeb(qts, L2CC_BASE + L2CC_WAY_ENABLE, 0xe); +    g_assert_cmphex(qtest_readb(qts, L2CC_BASE + L2CC_WAY_ENABLE), ==, 0xf);
+
+    for (i = 0; i < L2CC_WAY_MASK_COUNT; i++) {
+        g_assert_cmphex(qtest_readq(qts, L2CC_BASE + L2CC_WAY_MASK(i)), ==,
+                        L2CC_WAY_MASK_RESET);
+        qtest_writeq(qts, L2CC_BASE + L2CC_WAY_MASK(i), +                     l2cc_way_mask_test_value(i));
+    }
+    for (i = 0; i < L2CC_WAY_MASK_COUNT; i++) {
+        g_assert_cmphex(qtest_readq(qts, L2CC_BASE + L2CC_WAY_MASK(i)), ==,
+                        l2cc_way_mask_test_value(i));
+    }
+
+    qtest_system_reset(qts);
+    g_assert_cmphex(qtest_readl(qts, L2CC_BASE + L2CC_CONFIG), ==, +                    L2CC_CONFIG_VALUE);
+    g_assert_cmphex(qtest_readb(qts, L2CC_BASE + L2CC_WAY_ENABLE), ==,
+                    L2CC_WAY_ENABLE_RESET);
+    for (i = 0; i < L2CC_WAY_MASK_COUNT; i++) {
+        g_assert_cmphex(qtest_readq(qts, L2CC_BASE + L2CC_WAY_MASK(i)), ==,
+                        L2CC_WAY_MASK_RESET);
+    }

tests/qtest/sifive_l2cc_test.c new file +16 -0
+
+    qtest_quit(qts);
+}
+
+static void test_l2lim_topology(void)
+{
+    g_autofree char *firmware = sifive_l2cc_create_firmware();
+    uint32_t original[L2_LIM_RESET_WAYS];
+    const uint32_t poison = 0xdeadc0de;
+    const uint64_t zero_last = L2_ZERO_BASE + L2_ZERO_SIZE - 4;
+    QTestState *qts = sifive_l2cc_start(firmware);
+    unsigned int i;
+
+    unlink(firmware);
+
+    /* Check the fixed aperture, not the RAM stand-in's eviction

behavior */
+    qtest_writel(qts, zero_last, 0xa55a9669);
+    g_assert_cmphex(qtest_readl(qts, zero_last), ==, 0xa55a9669);

tests/qtest/sifive_l2cc_test.c new file +9 -0
+
+    for (i = 1; i <= L2_LIM_RESET_WAYS; i++) {
+        uint64_t l2lim_size = (L2_LIM_RESET_WAYS - i) * L2_WAY_SIZE;
+        uint64_t hidden = L2_LIM_BASE + l2lim_size;
+        uint32_t tail = 0x96000000 | i;
+
+        original[i - 1] = 0x69000000 | i;
+        qtest_writel(qts, hidden, original[i - 1]);
+        g_assert_cmphex(qtest_readl(qts, hidden), ==, original[i -

1]);

tests/qtest/sifive_l2cc_test.c new file +9 -0
+
+        if (l2lim_size) {
+            qtest_writel(qts, hidden - 4, tail);
+            g_assert_cmphex(qtest_readl(qts, hidden - 4), ==, tail);
+        }
+
+        qtest_writeb(qts, L2CC_BASE + L2CC_WAY_ENABLE, i);
+        g_assert_cmphex(qtest_readb(qts,
+                                   L2CC_BASE + L2CC_WAY_ENABLE), ==,

i);
+        if (l2lim_size) {
+            g_assert_cmphex(qtest_readl(qts, hidden - 4), ==, tail); +        }
+        g_assert_cmphex(qtest_readl(qts, hidden), ==, 0); +        qtest_writel(qts, hidden, poison);
+        g_assert_cmphex(qtest_readl(qts, hidden), ==, 0); +        g_assert_cmphex(qtest_readl(qts, zero_last), ==, 0xa55a9669);
+    }
+
+    qtest_writeb(qts, L2CC_BASE + L2CC_WAY_ENABLE, UINT8_MAX); +    g_assert_cmphex(qtest_readb(qts, L2CC_BASE + L2CC_WAY_ENABLE), ==,
+                    UINT8_MAX);
+    g_assert_cmphex(qtest_readl(qts, L2_LIM_BASE), ==, 0); +    qtest_writeb(qts, L2CC_BASE + L2CC_WAY_ENABLE, 3);
+    g_assert_cmphex(qtest_readb(qts, L2CC_BASE + L2CC_WAY_ENABLE), ==,
+                    UINT8_MAX);
+    g_assert_cmphex(qtest_readl(qts, L2_LIM_BASE), ==, 0); +
+    qtest_system_reset(qts);
+    g_assert_cmphex(qtest_readb(qts, L2CC_BASE + L2CC_WAY_ENABLE), ==,
+                    L2CC_WAY_ENABLE_RESET);
+    for (i = 1; i <= L2_LIM_RESET_WAYS; i++) {
+        uint64_t restored = L2_LIM_BASE +
+                            (L2_LIM_RESET_WAYS - i) * L2_WAY_SIZE; +
+        g_assert_cmphex(qtest_readl(qts, restored), ==, original[i - 1]);
+    }
+    g_assert_cmphex(qtest_readl(qts, zero_last), ==, 0xa55a9669);

tests/qtest/sifive_l2cc_test.c new file +16 -0
+
+    qtest_quit(qts);
+}
+
+static void test_l2cc_master_count(void)
+{
+    g_autofree char *firmware = sifive_l2cc_create_firmware();
+    QTestState *qts = qtest_initf(
+        "-machine sifive_u -smp 5 -bios \"%s\"", firmware);
+    const uint64_t zero_last = L2_ZERO_BASE + L2_ZERO_SIZE - 4;
+    unsigned int i;
+
+    unlink(firmware);
+
+    for (i = 0; i < L2CC_MAX_MASTERS; i++) {
+        g_assert_cmphex(qtest_readq(qts, L2CC_BASE +

L2CC_WAY_MASK(i)), ==,
+                        L2CC_WAY_MASK_RESET);
+        qtest_writeq(qts, L2CC_BASE + L2CC_WAY_MASK(i), +                     l2cc_way_mask_test_value(i));
+    }
+    for (i = 0; i < L2CC_MAX_MASTERS; i++) {
+        g_assert_cmphex(qtest_readq(qts, L2CC_BASE + L2CC_WAY_MASK(i)), ==,
+                        l2cc_way_mask_test_value(i));
+    }
+    g_assert_cmphex(qtest_readq(qts,
+                                L2CC_BASE + L2CC_WAY_MASK(L2CC_MAX_MASTERS)),
+                    ==, 0);
+    qtest_writel(qts, zero_last, 0x12345678);
+    qtest_writel(qts, L2_ZERO_BASE + L2_ZERO_SIZE, 0xdeadc0de); +    g_assert_cmphex(qtest_readl(qts, L2_ZERO_BASE + L2_ZERO_SIZE), ==, 0);
+    qtest_writeb(qts, L2CC_BASE + L2CC_WAY_ENABLE, 15); +    g_assert_cmphex(qtest_readl(qts, zero_last), ==, 0x12345678); +    g_assert_cmphex(qtest_readl(qts, L2_LIM_BASE), ==, 0); +
+    qtest_system_reset(qts);
+    for (i = 0; i < L2CC_MAX_MASTERS; i++) {
+        g_assert_cmphex(qtest_readq(qts, L2CC_BASE + L2CC_WAY_MASK(i)), ==,
+                        L2CC_WAY_MASK_RESET);
+    }
+    qtest_quit(qts);

tests/qtest/sifive_l2cc_test.c new file +26 -0
+}
+
+static void test_l2cc_migration(void)
+{
+    g_autofree char *firmware = sifive_l2cc_create_firmware();
+    QTestState *from = sifive_l2cc_start(firmware);
+    QTestState *to = qtest_initf(
+        "-machine microchip-icicle-kit -smp 5 -m 2G "
+        "-bios \"%s\" -incoming defer", firmware);
+    const uint64_t hidden = L2_LIM_BASE + 8 * L2_WAY_SIZE;
+    const uint64_t zero_last = L2_ZERO_BASE + L2_ZERO_SIZE - 4;
+
+    unlink(firmware);
+
+    qtest_writel(from, L2_LIM_BASE, 0x11223344);
+    qtest_writel(from, hidden, 0x55667788);
+    qtest_writel(from, zero_last, 0x99aabbcc);
+    qtest_writeb(from, L2CC_BASE + L2CC_WAY_ENABLE, 7);
+    qtest_writeq(from, L2CC_BASE + L2CC_WAY_MASK(14), 0x1234);
+    g_assert_cmphex(qtest_readl(from, hidden), ==, 0);
+
+    migrate_incoming_qmp(to, "tcp:127.0.0.1:0", NULL, "{}");
+    migrate_qmp(from, to, NULL, NULL, "{}");
+    wait_for_migration_complete(from);
+
+    g_assert_cmphex(qtest_readb(to, L2CC_BASE + L2CC_WAY_ENABLE),

==, 7);
+    g_assert_cmphex(qtest_readq(to, L2CC_BASE + L2CC_WAY_MASK(14)), ==, 0x1234);
+    g_assert_cmphex(qtest_readl(to, L2_LIM_BASE), ==, 0x11223344); +    g_assert_cmphex(qtest_readl(to, hidden), ==, 0);
+    qtest_writel(to, hidden, 0xdeadc0de);
+    g_assert_cmphex(qtest_readl(to, zero_last), ==, 0x99aabbcc); +
+    qtest_system_reset(to);
+    g_assert_cmphex(qtest_readb(to, L2CC_BASE + L2CC_WAY_ENABLE), ==, 0);
+    g_assert_cmphex(qtest_readl(to, hidden), ==, 0x55667788); +    g_assert_cmphex(qtest_readl(to, zero_last), ==, 0x99aabbcc);

tests/qtest/sifive_l2cc_test.c new file +14 -0
+
+    qtest_quit(from);
+    qtest_quit(to);
+}
+
+static void test_l2cc_unimplemented(void)
+{
+    g_autofree char *firmware = sifive_l2cc_create_firmware();
+    g_autofree char *log_path = NULL;
+    g_autofree char *log = NULL;
+    QTestState *qts;
+    int fd;
+
+    fd = g_file_open_tmp("sifive_l2cc_unimp_XXXXXX", &log_path,

NULL);
+    g_assert_cmpint(fd, >=, 0);
+    close(fd);

tests/qtest/sifive_l2cc_test.c new file +7 -0
+
+    qts = qtest_initf(
+        "-machine microchip-icicle-kit -smp 5 -m 2G -bios \"%s\" "
+        "-d unimp -D \"%s\"", firmware, log_path);
+    unlink(firmware);
+
+    g_assert_cmphex(qtest_readl(qts, L2CC_BASE + L2CC_ECC_INJECT),

==, 0);
+    qtest_writeq(qts, L2CC_BASE + L2CC_FLUSH64, 0x1234); +    g_assert_cmphex(qtest_readq(qts, L2CC_BASE + L2CC_MASTER15), ==, 0);
+    qtest_quit(qts);
+
+    g_assert_true(g_file_get_contents(log_path, &log, NULL, NULL)); +    g_assert_nonnull(strstr(log,
+        "unimplemented device read (size 4, offset 0x40)")); +    g_assert_nonnull(strstr(log,
+        "unimplemented device write (size 8, value 0x1234, offset 0x200)"));
+    g_assert_nonnull(strstr(log,
+        "unimplemented device read (size 8, offset 0x878)")); +    unlink(log_path);

tests/qtest/sifive_l2cc_test.c new file +8 -0
+}
+
+int main(int argc, char **argv)
+{
+    g_test_init(&argc, &argv, NULL);
+
+    if (qtest_has_machine("microchip-icicle-kit")) {
+        qtest_add_func("/sifive_l2cc/registers",

test_l2cc_registers);
+        qtest_add_func("/sifive_l2cc/l2lim_topology", test_l2lim_topology);
+        qtest_add_func("/sifive_l2cc/unimplemented", test_l2cc_unimplemented);
+        qtest_add_func("/sifive_l2cc/migration", test_l2cc_migration);
+    }
+    if (qtest_has_machine("sifive_u")) {
+        qtest_add_func("/sifive_l2cc/master_count", test_l2cc_master_count);
+    }

tests/qtest/sifive_l2cc_test.c new file +3 -0
+
+    return g_test_run();
+}
tests/qtest/meson.build +0 -0
index ff4bf9528a..a001409de2 100644
@@ -317,6 +317,7 @@ qtests_riscv32 = \


 qtests_riscv64 = ['riscv-csr-test'] + \
   (unpack_edk2_blobs ? ['bios-tables-test'] : []) + \
+  (config_all_devices.has_key('CONFIG_SIFIVE_L2CC') ? ['sifive_l2cc_test'] : []) + \
   (config_all_devices.has_key('CONFIG_IOMMU_TESTDEV') and config_all_devices.has_key('CONFIG_RISCV_IOMMU') ? ['iommu-riscv-test'] : []) + \

tests/qtest/meson.build +0 -0
@@ -438,6 +439,8 @@ qtests = {
    'erst-test': files('erst-test.c'),

   'ivshmem-test': [rt, '../../contrib/ivshmem-server/ivshmem- server.c'],
   'migration-test': test_migration_files + migration_tls_files + migration_colo_files,
+  'sifive_l2cc_test': files('migration/migration-qmp.c', +                           'migration/migration-util.c'), 'pxe-test': files('boot-sector.c'), 'pnv-xive2-test': files('pnv-xive2-common.c', 'pnv-xive2-flush- sync.c',
                           'pnv-xive2-nvpg_bar.c'),

Acked-by Alistair Francis on v5 17/26
#26 lore raw

Re: [PATCH v5 17/26] hw/misc: pfsoc: Honor service notification requests

In reply to Bin Meng
Quoted 5 lines · Bin Meng

Polling firmware requests system services with REQUEST set and NOTIFY clear. Raising PLIC source 96 for those requests leaves an interrupt pending that Linux can receive before submitting its first request. The mailbox interrupt handler then has no response buffer to fill.

Quoted 8 lines

Raise the completion interrupt only for requests with NOTIFY set. The serial-number service already checks REQUEST before processing a command.

Fixes 592f0a9429b9 ("hw/{misc, riscv}: pfsoc: add system controller

as unimplemented")

Alistair

Quoted 27 lines

---

(no changes since v3)

Changes in v3:
- Split the NOTIFY fix from interrupt acknowledgement wiring

 hw/misc/mchp_pfsoc_ioscb.c | 4 +++-

 1 file changed, 3 insertions(+), 1 deletion(-)
hw/misc/mchp_pfsoc_ioscb.c +0 -0
index 850125c8b4..bde1917c10 100644
@@ -247,7 +247,9 @@ static void services_cr_write(MchpPfSoCIoscbState
 *s, uint32_t value)
      }


     s->services_sr = status << SERVICES_SR_STATUS_SHIFT; -    qemu_irq_raise(s->irq);
+    if (value & SERVICES_CR_NOTIFY) {
+        qemu_irq_raise(s->irq);
+    }
 }

 static uint64_t mchp_pfsoc_ctrl_read(void *opaque, hwaddr offset,

Acked-by on v5 20/26
#30 lore raw

Re: [PATCH v5 20/26] hw/riscv: pfsoc: Fix Icicle Kit RAM size at 2 GiB

In reply to Bin Meng
Quoted 5 lines · Bin Meng

The Icicle Kit has 2 GiB of RAM, and its firmware device tree describes that fixed capacity. The model currently defaults to 1537 MiB and accepts any larger size, allowing configurations that do not match the board.

Quoted 7 lines

Set the default to 2 GiB and reject every other size. Update the documentation and L2CC qtest command line accordingly.

Alistair

Quoted 68 lines

---

(no changes since v1)

 docs/system/riscv/microchip-icicle-kit.rst |  4 +--- hw/riscv/microchip_pfsoc.c                 | 15 ++++-----------

 2 files changed, 5 insertions(+), 14 deletions(-)
docs/system/riscv/microchip-icicle-kit.rst +0 -0
index 7fdb96601a..b0ad24f174 100644
@@ -26,9 +26,7 @@ The ``microchip-icicle-kit`` machine supports the

following devices:
 * 2 GEM Ethernet controllers
 * 1 SDHC storage controller

-The memory is set to 1537 MiB by default.  A sanity check on RAM size is
-performed in the machine init routine to prompt user to increase the RAM size

docs/system/riscv/microchip-icicle-kit.rst +1 -1
-to > 1537 MiB when less than 1537 MiB RAM is detected.
+The machine has a fixed 2 GiB of RAM. Other memory sizes are

rejected.

 Boot options
 ------------

hw/riscv/microchip_pfsoc.c +0 -0
index 55ce1ac7da..f2a838be13 100644
@@ -542,10 +542,10 @@ static void
 microchip_icicle_kit_machine_init(MachineState *machine)
      DriveInfo *dinfo = drive_get(IF_SD, 0, 0);
      RISCVBootInfo boot_info;


-    /* Sanity check on RAM size */
-    if (machine->ram_size < mc->default_ram_size) {
+    /* The board has a fixed 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);
+        error_report("Invalid RAM size, should be %s", sz); g_free(sz);
         exit(EXIT_FAILURE);
     }

hw/riscv/microchip_pfsoc.c +0 -0
@@ -757,14 +757,7 @@ static void
 microchip_icicle_kit_machine_class_init(ObjectClass *oc,
      mc->default_ram_id = "microchip.icicle.kit.ram";
      mc->auto_create_sdcard = true;


-    /*
-     * Map 513 MiB high memory, the minimum required high memory size, because
-     * HSS will do memory test against the high memory address range regardless
-     * of physical memory installed.
-     *
-     * See memory_tests() in mss_ddr.c in the HSS source code. -     */
-    mc->default_ram_size = 1537 * MiB;
+    mc->default_ram_size = 2 * GiB;

     object_class_property_add(oc, "clint-timebase-frequency", "uint32_t",
                               &uint32_type_info,

Acked-by on v5 21/26
#32 lore raw

Re: [PATCH v5 21/26] hw/riscv: pfsoc: Default Icicle Kit to five harts

In reply to Bin Meng
Quoted 10 lines · Bin Meng

The Icicle Kit contains one E51 management hart and four U54 application
harts. Defaulting to two harts can accidentally boot firmware and a device tree that expect the full five-hart topology.

Default to all five harts, while retaining the existing two-to-five range for users intentionally configuring fewer application harts. Document that firmware and device trees must match the selected count.

Quoted 4 lines
Reviewed-by Daniel Henrique Barboza

<[email protected]>

Alistair

Quoted 46 lines

---

(no changes since v3)

Changes in v3:
- Change only the default hart count and retain the minimum of two
- Document reduced topologies and matching firmware requirements

 docs/system/riscv/microchip-icicle-kit.rst | 3 +++ hw/riscv/microchip_pfsoc.c                 | 2 +-

 2 files changed, 4 insertions(+), 1 deletion(-)
docs/system/riscv/microchip-icicle-kit.rst +0 -0
index b0ad24f174..138289a913 100644
@@ -27,6 +27,9 @@ The ``microchip-icicle-kit`` machine supports the

following devices:
 * 1 SDHC storage controller

 The machine has a fixed 2 GiB of RAM. Other memory sizes are rejected.
+The machine defaults to all five harts. ``-smp`` may select two to five harts,
+with one E51 and one to four U54 cores. The firmware and device tree must match
+the selected topology; the HSS boot flow below uses all five harts.
 Boot options
 ------------

hw/riscv/microchip_pfsoc.c +0 -0
index f2a838be13..90345aa262 100644
@@ -753,7 +753,7 @@ static void
 microchip_icicle_kit_machine_class_init(ObjectClass *oc,

     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_cpus = mc->max_cpus; mc->default_ram_id = "microchip.icicle.kit.ram"; mc->auto_create_sdcard = true;

Acked-by on v5 24/26
#38 lore raw

Re: [PATCH v5 24/26] tests/functional/riscv64: Add Icicle Kit firmware boot test

In reply to Bin Meng
Quoted 11 lines · Bin Meng

Add functional coverage using the v1.1.1 HSS and SD card images.

Boot HSS v2026.04.1 and U-Boot with five harts and 2 GiB of RAM. Connect
the test console to MMUART1 and let U-Boot start Linux.

The complete boot exercises the SDHCI controller in the DMA modes used at each stage. HSS uses Version 4 64-bit SDMA to load U-Boot. U-Boot uses ADMA2-64 to read the boot script and the large FIT image. Linux then selects 64-bit ADMA for SD card and rootfs I/O.

Quoted 5 lines

Check the machine identity, kernel ADMA initialization, root filesystem mount, and login prompt.

Alistair

Quoted 117 lines

---

(no changes since v4)

Changes in v4:
- Use the v1.1.1 test images with HSS v2026.04.1
- Add the execution bit to the python script

 MAINTAINERS                                   |  1 + tests/functional/riscv64/meson.build          |  2 + .../riscv64/test_microchip_icicle_kit.py      | 56
+++++++++++++++++++

 3 files changed, 59 insertions(+)

 create mode 100755 tests/functional/riscv64/test_microchip_icicle_kit.py

MAINTAINERS +0 -0
index a8343e3d55..6c7437f8a5 100644
@@ -1834,6 +1834,7 @@ F: include/hw/misc/mchp_pfsoc_dmc.h

 F: include/hw/misc/mchp_pfsoc_ioscb.h
 F: include/hw/misc/mchp_pfsoc_sysreg.h
 F: include/hw/rtc/mchp_pfsoc_rtc.h
+F: tests/functional/riscv64/test_microchip_icicle_kit.py
 F: tests/qtest/mchp_pfsoc_rtc_test.c

 Shakti C class SoC

tests/functional/riscv64/meson.build +2 -0
index 211ea9acfc..231a1e49f6 100644
@@ -3,6 +3,7 @@
  test_riscv64_timeouts = {
    'boston' : 120,
    'k230' : 120,
+  'microchip_icicle_kit' : 180,
    'server_ref' : 120,
    'tuxrun' : 120,
  }
@@ -16,6 +17,7 @@ tests_riscv64_system_thorough = [
    'endianness',
    'boston',
    'k230',
+  'microchip_icicle_kit',
    'server_ref',
    'sifive_u',
    'tt_atlantis',
tests/functional/riscv64/test_microchip_icicle_kit.py new file +3 -0
new file mode 100755
index 0000000000..ee627a87a8
@@ -0,0 +1,56 @@
+#!/usr/bin/env python3
+#
+# Functional test that boots HSS, U-Boot, and Linux on an Icicle

Kit.

tests/functional/riscv64/test_microchip_icicle_kit.py new file +15 -0
+#
+# Copyright (c) 2026 Process Mission
+#
+# Author:
+#   Bin Meng <[email protected]>
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+from qemu_test import Asset, LinuxKernelTest, skipIfMissingCommands
+
+
+class MicrochipIcicleKitMachine(LinuxKernelTest):
+
+    ASSET_IMAGES = Asset(
+       

('https://github.com/processmission/qemu-machine-images/releases/' +         'download/v1.1.1/'
+         'riscv64-microchip-icicle-kit-v1.1.1.tar.zst'), + '226e4322e5ec53513eccdf16e4e967cdef7d57a0ba19431470ca68b883457538')

tests/functional/riscv64/test_microchip_icicle_kit.py new file +21 -0
+
+    @skipIfMissingCommands('zstd')
+    def test_microchip_icicle_kit_boot(self):
+        self.set_machine('microchip-icicle-kit')
+
+        archive_path = self.uncompress(
+            self.ASSET_IMAGES,
+            target='microchip_icicle_kit_images.tar',
+            format='zstd')
+        self.archive_extract(archive_path, format='tar')
+        firmware_path = self.scratch_file('images', 'hss.bin')
+        sdcard_path = self.scratch_file('images', 'sdcard.img')
+
+        self.vm.set_console(console_index=1)
+        self.vm.add_args(
+            '-smp', '5',
+            '-m', '2G',
+            '-display', 'none',
+            '-bios', firmware_path,
+            '-snapshot',
+            '-drive',

f'file={sdcard_path},format=raw,if=sd,index=0',
+            '-no-reboot')
+        self.vm.launch()

tests/functional/riscv64/test_microchip_icicle_kit.py new file +12 -0
+
+        self.wait_for_console_pattern('U-Boot ')
+        self.wait_for_console_pattern('Starting kernel ...')
+        self.wait_for_console_pattern(
+            'Machine model: Microchip PolarFire-SoC Icicle Kit')
+        self.wait_for_console_pattern('using ADMA 64-bit')
+        self.wait_for_console_pattern('VFS: Mounted root')
+        self.wait_for_console_pattern('mpfs_icicle login:')
+
+
+if __name__ == '__main__':
+    LinuxKernelTest.main()