Kernel KVM virtualization development
 help / color / mirror / Atom feed
* [RFC PATCH 00/20] hw/arm: Add initial RK3588 and ROCK 5B support
@ 2026-11-13  9:47 Yifan Wang
  2026-11-13  9:47 ` [RFC PATCH 01/20] hw/char/dw8250: implement the UART status register Yifan Wang
                   ` (19 more replies)
  0 siblings, 20 replies; 22+ messages in thread
From: Yifan Wang @ 2026-11-13  9:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Yifan Wang, qemu-arm, qemu-block, kvm, Peter Maydell,
	Pierrick Bouvier, Paolo Bonzini, Alistair Francis, Kevin Wolf,
	Hanna Reitz, Kuan-Wei Chiu, Marc-André Lureau, bin.meng,
	tangtao1634

Hi,

This series adds initial support for the Rockchip RK3588 SoC and the
Radxa ROCK 5B board. It supports booting Linux through U-Boot SPL and
U-Boot from SPI NOR flash, as well as direct kernel boot.

The implementation includes the eight Cortex-A55/A76 CPUs, GICv3,
architectural timers, SRAM, UARTs, and the Rockchip SPI flash controller.
It also models the CRU, OTP, and HPTIMER registers needed by the boot
software.

Patches 1-5 extend DW8250 and ARM SMC support and add the XTX XT25F128
flash device. Patches 6-15 add the RK3588 SoC and its devices. Patches
16-18 add the ROCK 5B board and firmware boot support. Patch 19 adds
functional boot tests, and patch 20 adds documentation.

Both boot paths have been tested with Linux 6.12.4, with U-Boot 2025.01
used for the firmware boot path. The included functional tests cover
booting to a Buildroot shell, reboot, and poweroff.

Comments and suggestions are welcome.

Thanks,
Yifan

Chao Liu (20):
  hw/char/dw8250: implement the UART status register
  hw/char/dw8250: expose the baudbase property
  target/arm: report SMCCC v1.1 support
  target/arm: allow machines to handle SMC calls
  hw/block/m25p80: add the XTX XT25F128 SPI NOR flash
  hw/arm: add the Rockchip RK3588 SoC
  hw/timer: add Rockchip HPTIMER boot control
  hw/arm/rk3588: add the unimplemented device map
  hw/arm/rk3588: add the GICv3 interrupt controller
  hw/arm/rk3588: add the UARTs
  hw/misc: add the RK3588 clock and reset unit
  hw/misc: add the RK3588 OTP controller
  hw/ssi: add the Rockchip SPI flash controller
  hw/misc: add RK3588 SCMI server
  hw/arm/rk3588: wire up the SCMI server
  hw/arm: add Radxa ROCK 5B board
  hw/arm/rock-5b: connect the XTX XT25F128 SPI NOR flash
  hw/arm/rock-5b: add firmware booting
  tests/functional: add ROCK 5B boot tests
  docs/system/arm: document the Radxa ROCK 5B machine

 MAINTAINERS                              |  19 +
 docs/system/arm/rock-5b.rst              |  86 ++++
 docs/system/target-arm.rst               |   1 +
 hw/arm/Kconfig                           |  16 +
 hw/arm/meson.build                       |   3 +
 hw/arm/rk3588.c                          | 452 +++++++++++++++++
 hw/arm/rock-5b.c                         | 297 ++++++++++++
 hw/block/m25p80.c                        |  20 +
 hw/char/dw8250.c                         |  45 ++
 hw/misc/meson.build                      |   5 +
 hw/misc/rk3588-scmci.c                   | 589 +++++++++++++++++++++++
 hw/misc/rockchip_cru.c                   | 233 +++++++++
 hw/misc/rockchip_otp.c                   | 146 ++++++
 hw/ssi/Kconfig                           |   5 +
 hw/ssi/meson.build                       |   1 +
 hw/ssi/rockchip_sfc.c                    | 439 +++++++++++++++++
 hw/timer/meson.build                     |   1 +
 hw/timer/rockchip-hptimer.c              | 115 +++++
 include/hw/arm/arm-smc.h                 |  31 ++
 include/hw/arm/rk3588.h                  |  64 +++
 include/hw/misc/rk3588-scmci.h           |  25 +
 include/hw/timer/rockchip-hptimer.h      |  20 +
 target/arm/helper.c                      |  80 +++
 target/arm/internals.h                   |   3 +
 target/arm/kvm-consts.h                  |   5 +
 target/arm/tcg/psci.c                    |  15 +
 tests/functional/aarch64/meson.build     |   2 +
 tests/functional/aarch64/test_rock_5b.py | 118 +++++
 28 files changed, 2836 insertions(+)
 create mode 100644 docs/system/arm/rock-5b.rst
 create mode 100644 hw/arm/rk3588.c
 create mode 100644 hw/arm/rock-5b.c
 create mode 100644 hw/misc/rk3588-scmci.c
 create mode 100644 hw/misc/rockchip_cru.c
 create mode 100644 hw/misc/rockchip_otp.c
 create mode 100644 hw/ssi/rockchip_sfc.c
 create mode 100644 hw/timer/rockchip-hptimer.c
 create mode 100644 include/hw/arm/arm-smc.h
 create mode 100644 include/hw/arm/rk3588.h
 create mode 100644 include/hw/misc/rk3588-scmci.h
 create mode 100644 include/hw/timer/rockchip-hptimer.h
 create mode 100755 tests/functional/aarch64/test_rock_5b.py


base-commit: 49559567804523cb28cad002aa8e97f444e23ad7
-- 
2.53.0


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [RFC PATCH 01/20] hw/char/dw8250: implement the UART status register
  2026-11-13  9:47 [RFC PATCH 00/20] hw/arm: Add initial RK3588 and ROCK 5B support Yifan Wang
@ 2026-11-13  9:47 ` Yifan Wang
  2026-11-28 13:17   ` Kuan-Wei Chiu
  2026-11-13  9:47 ` [RFC PATCH 02/20] hw/char/dw8250: expose the baudbase property Yifan Wang
                   ` (18 subsequent siblings)
  19 siblings, 1 reply; 22+ messages in thread
From: Yifan Wang @ 2026-11-13  9:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Yifan Wang, qemu-arm, qemu-block, kvm, Peter Maydell,
	Pierrick Bouvier, Paolo Bonzini, Alistair Francis, Kevin Wolf,
	Hanna Reitz, Kuan-Wei Chiu, Marc-André Lureau, bin.meng,
	tangtao1634, Chao Liu

From: Chao Liu <chao.liu@processmission.com>

The Rock 5B machine runs a vendor U-Boot and Linux that read the UART
status register to check the transmitter and FIFO state. Implement the
register.

Signed-off-by: Chao Liu <chao.liu@processmission.com>
Signed-off-by: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
---
 hw/char/dw8250.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/hw/char/dw8250.c b/hw/char/dw8250.c
index 50baeae62c..4f9a8ea989 100644
--- a/hw/char/dw8250.c
+++ b/hw/char/dw8250.c
@@ -6,6 +6,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/bitops.h"
 #include "qemu/log.h"
 #include "qapi/error.h"
 #include "hw/char/dw8250.h"
@@ -14,20 +15,62 @@
 
 #define DW_UART_REGION_SIZE 0x100
 
+#define DW_UART_USR   (0x7C >> 2) /* UART Status Register */
 #define DW_UART_RE_EN (0xB4 >> 2) /* Receiver Output Enable Register */
 #define DW_UART_DLF   (0xC0 >> 2) /* Divisor Latch Fraction Register */
 #define DW_UART_CPR   (0xF4 >> 2) /* Component Parameter Register */
 #define DW_UART_UCV   (0xF8 >> 2) /* UART Component Version */
 #define DW_UART_CTR   (0xFC >> 2) /* Component Type Register */
 
+/* UART Status Register bits */
+#define DW_UART_USR_BUSY BIT(0) /* UART busy */
+#define DW_UART_USR_TFNF BIT(1) /* Transmit FIFO not full */
+#define DW_UART_USR_TFE  BIT(2) /* Transmit FIFO empty */
+#define DW_UART_USR_RFNE BIT(3) /* Receive FIFO not empty */
+#define DW_UART_USR_RFF  BIT(4) /* Receive FIFO full */
+
+/* FIFO Control Register bits */
+#define DW_UART_FCR_FIFO_EN BIT(0) /* FIFO enable */
+
+/* Line Status Register bits */
+#define DW_UART_LSR_DR   BIT(0) /* Receiver data ready */
+#define DW_UART_LSR_THRE BIT(5) /* Transmitter holding register empty */
+#define DW_UART_LSR_TEMT BIT(6) /* Transmitter empty */
+
 #define DW_UART_UCV_VALUE 0x3332332A /* "323*" -> v3.23a */
 #define DW_UART_CTR_VALUE 0x44570110 /* "DW" */
 
 static uint64_t dw8250_ext_read(void *opaque, hwaddr addr, unsigned int size)
 {
     DW8250State *s = opaque;
+    SerialState *serial = &s->serial_mm.serial;
 
     switch (addr >> s->regshift) {
+    case DW_UART_USR: {
+        bool fifo_enabled = serial->fcr & DW_UART_FCR_FIFO_EN;
+        bool thr_empty = serial->lsr & DW_UART_LSR_THRE;
+        bool tx_idle = serial->lsr & DW_UART_LSR_TEMT;
+        bool rx_ready = serial->lsr & DW_UART_LSR_DR;
+        bool tx_empty;
+        bool tx_full;
+        bool rx_full;
+
+        if (fifo_enabled) {
+            tx_empty = fifo8_is_empty(&serial->xmit_fifo);
+            tx_full = fifo8_is_full(&serial->xmit_fifo);
+            rx_full = fifo8_is_full(&serial->recv_fifo);
+        } else {
+            tx_empty = thr_empty;
+            tx_full = !thr_empty;
+            rx_full = rx_ready;
+        }
+
+        return (!tx_idle ? DW_UART_USR_BUSY : 0) |
+               (!tx_full ? DW_UART_USR_TFNF : 0) |
+               (tx_empty ? DW_UART_USR_TFE : 0) |
+               (rx_ready ? DW_UART_USR_RFNE : 0) |
+               (rx_full ? DW_UART_USR_RFF : 0);
+    }
     case DW_UART_UCV:
         return DW_UART_UCV_VALUE;
     case DW_UART_CPR:
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC PATCH 02/20] hw/char/dw8250: expose the baudbase property
  2026-11-13  9:47 [RFC PATCH 00/20] hw/arm: Add initial RK3588 and ROCK 5B support Yifan Wang
  2026-11-13  9:47 ` [RFC PATCH 01/20] hw/char/dw8250: implement the UART status register Yifan Wang
@ 2026-11-13  9:47 ` Yifan Wang
  2026-11-13  9:47 ` [RFC PATCH 03/20] target/arm: report SMCCC v1.1 support Yifan Wang
                   ` (17 subsequent siblings)
  19 siblings, 0 replies; 22+ messages in thread
From: Yifan Wang @ 2026-11-13  9:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Yifan Wang, qemu-arm, qemu-block, kvm, Peter Maydell,
	Pierrick Bouvier, Paolo Bonzini, Alistair Francis, Kevin Wolf,
	Hanna Reitz, Kuan-Wei Chiu, Marc-André Lureau, bin.meng,
	tangtao1634, Chao Liu

From: Chao Liu <chao.liu@processmission.com>

The RK3588 SoC clocks its UARTs at 24 MHz, so the embedded serial
device needs a matching baud base to calculate the guest baud rate
correctly. Alias the serial-mm baudbase property on the DW8250 device
so that the SoC model can set it.

Signed-off-by: Chao Liu <chao.liu@processmission.com>
Signed-off-by: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
---
 hw/char/dw8250.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/char/dw8250.c b/hw/char/dw8250.c
index 4f9a8ea989..6fba0d66aa 100644
--- a/hw/char/dw8250.c
+++ b/hw/char/dw8250.c
@@ -117,6 +117,8 @@ static void dw8250_instance_init(Object *obj)
 
     object_initialize_child(obj, "serial-mm", &s->serial_mm, TYPE_SERIAL_MM);
     object_property_add_alias(obj, "chardev", OBJECT(&s->serial_mm), "chardev");
+    object_property_add_alias(obj, "baudbase", OBJECT(&s->serial_mm),
+                              "baudbase");
 }
 
 static void dw8250_realize(DeviceState *dev, Error **errp)
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC PATCH 03/20] target/arm: report SMCCC v1.1 support
  2026-11-13  9:47 [RFC PATCH 00/20] hw/arm: Add initial RK3588 and ROCK 5B support Yifan Wang
  2026-11-13  9:47 ` [RFC PATCH 01/20] hw/char/dw8250: implement the UART status register Yifan Wang
  2026-11-13  9:47 ` [RFC PATCH 02/20] hw/char/dw8250: expose the baudbase property Yifan Wang
@ 2026-11-13  9:47 ` Yifan Wang
  2026-11-13  9:47 ` [RFC PATCH 04/20] target/arm: allow machines to handle SMC calls Yifan Wang
                   ` (16 subsequent siblings)
  19 siblings, 0 replies; 22+ messages in thread
From: Yifan Wang @ 2026-11-13  9:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Yifan Wang, qemu-arm, qemu-block, kvm, Peter Maydell,
	Pierrick Bouvier, Paolo Bonzini, Alistair Francis, Kevin Wolf,
	Hanna Reitz, Kuan-Wei Chiu, Marc-André Lureau, bin.meng,
	tangtao1634, Chao Liu

From: Chao Liu <chao.liu@processmission.com>

Guests use the SMCCC version call to select the conduit for firmware
services such as SCMI.  QEMU reports PSCI 1.1 but rejects the SMCCC
version call, so a guest running with the SMC PSCI conduit never
initializes SMCCC and cannot use SCMI over SMC.

Advertise SMCCC 1.1 through PSCI_FEATURES and the SMCCC version call.

Signed-off-by: Chao Liu <chao.liu@processmission.com>
Signed-off-by: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
---
 target/arm/kvm-consts.h |  5 +++++
 target/arm/tcg/psci.c   | 15 +++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/target/arm/kvm-consts.h b/target/arm/kvm-consts.h
index 9fba3e886d..ab64c91888 100644
--- a/target/arm/kvm-consts.h
+++ b/target/arm/kvm-consts.h
@@ -88,6 +88,11 @@ MISMATCH_CHECK(QEMU_PSCI_0_2_FN64_CPU_ON, PSCI_0_2_FN64_CPU_ON);
 MISMATCH_CHECK(QEMU_PSCI_0_2_FN64_MIGRATE, PSCI_0_2_FN64_MIGRATE);
 MISMATCH_CHECK(QEMU_PSCI_1_0_FN_PSCI_FEATURES, PSCI_1_0_FN_PSCI_FEATURES);
 
+/* SMCCC architecture calls. */
+#define QEMU_SMCCC_VERSION_FUNC_ID                0x80000000
+#define QEMU_SMCCC_ARCH_FEATURES_FUNC_ID          0x80000001
+#define QEMU_SMCCC_VERSION_1_1                     QEMU_PSCI_VERSION_1_1
+
 /* PSCI v0.2 return values used by TCG emulation of PSCI */
 
 /* No Trusted OS migration to worry about when offlining CPUs */
diff --git a/target/arm/tcg/psci.c b/target/arm/tcg/psci.c
index d8e01df762..81ca2fbb44 100644
--- a/target/arm/tcg/psci.c
+++ b/target/arm/tcg/psci.c
@@ -95,6 +95,20 @@ void arm_handle_psci_call(ARMCPU *cpu)
     case QEMU_PSCI_0_2_FN_PSCI_VERSION:
         ret = QEMU_PSCI_VERSION_1_1;
         break;
+    case QEMU_SMCCC_VERSION_FUNC_ID:
+        ret = QEMU_SMCCC_VERSION_1_1;
+        break;
+    case QEMU_SMCCC_ARCH_FEATURES_FUNC_ID:
+        switch ((uint32_t)param[1]) {
+        case QEMU_SMCCC_VERSION_FUNC_ID:
+        case QEMU_SMCCC_ARCH_FEATURES_FUNC_ID:
+            ret = 0;
+            break;
+        default:
+            ret = QEMU_PSCI_RET_NOT_SUPPORTED;
+            break;
+        }
+        break;
     case QEMU_PSCI_0_2_FN_MIGRATE_INFO_TYPE:
         ret = QEMU_PSCI_0_2_RET_TOS_MIGRATION_NOT_REQUIRED; /* No trusted OS */
         break;
@@ -177,6 +191,7 @@ void arm_handle_psci_call(ARMCPU *cpu)
     case QEMU_PSCI_1_0_FN_PSCI_FEATURES:
         switch (param[1]) {
         case QEMU_PSCI_0_2_FN_PSCI_VERSION:
+        case QEMU_SMCCC_VERSION_FUNC_ID:
         case QEMU_PSCI_0_2_FN_MIGRATE_INFO_TYPE:
         case QEMU_PSCI_0_2_FN_AFFINITY_INFO:
         case QEMU_PSCI_0_2_FN64_AFFINITY_INFO:
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC PATCH 04/20] target/arm: allow machines to handle SMC calls
  2026-11-13  9:47 [RFC PATCH 00/20] hw/arm: Add initial RK3588 and ROCK 5B support Yifan Wang
                   ` (2 preceding siblings ...)
  2026-11-13  9:47 ` [RFC PATCH 03/20] target/arm: report SMCCC v1.1 support Yifan Wang
@ 2026-11-13  9:47 ` Yifan Wang
  2026-11-13  9:47 ` [RFC PATCH 05/20] hw/block/m25p80: add the XTX XT25F128 SPI NOR flash Yifan Wang
                   ` (15 subsequent siblings)
  19 siblings, 0 replies; 22+ messages in thread
From: Yifan Wang @ 2026-11-13  9:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Yifan Wang, qemu-arm, qemu-block, kvm, Peter Maydell,
	Pierrick Bouvier, Paolo Bonzini, Alistair Francis, Kevin Wolf,
	Hanna Reitz, Kuan-Wei Chiu, Marc-André Lureau, bin.meng,
	tangtao1634, Chao Liu

From: Chao Liu <chao.liu@processmission.com>

Some machines model firmware services which use vendor SMC function IDs
while QEMU provides PSCI through the same SMC conduit.  There is
currently no way for such a machine to take over a call before the PSCI
path handles it.

Add a small registry for SMC function ID handlers.  Machines can
register a handler which inspects the call and returns whether it was
handled, without changing the behavior of existing callers.

Signed-off-by: Chao Liu <chao.liu@processmission.com>
Signed-off-by: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
---
 MAINTAINERS              |  1 +
 include/hw/arm/arm-smc.h | 31 ++++++++++++++++
 target/arm/helper.c      | 80 ++++++++++++++++++++++++++++++++++++++++
 target/arm/internals.h   |  3 ++
 4 files changed, 115 insertions(+)
 create mode 100644 include/hw/arm/arm-smc.h

diff --git a/MAINTAINERS b/MAINTAINERS
index fa0c6d0c9b..db1a62a0cb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -222,6 +222,7 @@ F: tests/tcg/arm/
 F: tests/tcg/aarch64/
 F: tests/qtest/arm-cpu-features.c
 F: hw/arm/
+F: include/hw/arm/arm-smc.h
 F: hw/cpu/a*mpcore.c
 F: include/hw/cpu/a*mpcore.h
 F: docs/system/target-arm.rst
diff --git a/include/hw/arm/arm-smc.h b/include/hw/arm/arm-smc.h
new file mode 100644
index 0000000000..e27d64218f
--- /dev/null
+++ b/include/hw/arm/arm-smc.h
@@ -0,0 +1,31 @@
+/*
+ * ARM SMC call dispatch
+ *
+ * Board and SoC models can register handlers for vendor or firmware
+ * SMC calling convention function IDs. Under TCG, dispatch follows the
+ * architectural trap checks and precedes exception delivery and QEMU's
+ * PSCI emulation, so firmware services can share the SMC conduit with PSCI.
+ *
+ * Copyright (C) 2026 Process Mission
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_ARM_ARM_SMC_H
+#define HW_ARM_ARM_SMC_H
+
+typedef bool (*ARMSCMCHandler)(const uint64_t args[8], uint64_t *ret,
+                              void *opaque);
+
+/*
+ * Register a handler for one SMCCC function ID.  The handler returns
+ * true when it has handled the call and set *ret. args contains the
+ * caller's x0-x7 or zero-extended r0-r7; the ARM dispatcher writes *ret
+ * to x0/r0 and preserves the other registers. Returns 0 on success and
+ * a negative value if the function ID is already registered.
+ */
+int arm_register_smc_handler(uint64_t func_id, ARMSCMCHandler handler,
+                             void *opaque);
+void arm_unregister_smc_handler(uint64_t func_id, ARMSCMCHandler handler);
+
+#endif /* HW_ARM_ARM_SMC_H */
diff --git a/target/arm/helper.c b/target/arm/helper.c
index f413b15eb7..61645fefa6 100644
--- a/target/arm/helper.c
+++ b/target/arm/helper.c
@@ -36,6 +36,7 @@
 #include "cpregs.h"
 #include "target/arm/gtimer.h"
 #include "qemu/plugin.h"
+#include "hw/arm/arm-smc.h"
 
 static void switch_mode(CPUARMState *env, int mode);
 #ifndef CONFIG_USER_ONLY
@@ -9815,6 +9816,78 @@ static void arm_cpu_do_interrupt_aarch64(CPUState *cs)
                   new_el, env->pc, pstate_read(env));
 }
 
+typedef struct ARMSCMCHandlerEntry {
+    uint64_t func_id;
+    ARMSCMCHandler handler;
+    void *opaque;
+    QTAILQ_ENTRY(ARMSCMCHandlerEntry) node;
+} ARMSCMCHandlerEntry;
+
+static QTAILQ_HEAD(, ARMSCMCHandlerEntry) arm_smc_handlers =
+    QTAILQ_HEAD_INITIALIZER(arm_smc_handlers);
+
+int arm_register_smc_handler(uint64_t func_id, ARMSCMCHandler handler,
+                             void *opaque)
+{
+    ARMSCMCHandlerEntry *entry;
+
+    QTAILQ_FOREACH(entry, &arm_smc_handlers, node) {
+        if (entry->func_id == func_id) {
+            return -1;
+        }
+    }
+
+    entry = g_new0(ARMSCMCHandlerEntry, 1);
+    entry->func_id = func_id;
+    entry->handler = handler;
+    entry->opaque = opaque;
+    QTAILQ_INSERT_TAIL(&arm_smc_handlers, entry, node);
+
+    return 0;
+}
+
+void arm_unregister_smc_handler(uint64_t func_id, ARMSCMCHandler handler)
+{
+    ARMSCMCHandlerEntry *entry, *next;
+
+    QTAILQ_FOREACH_SAFE(entry, &arm_smc_handlers, node, next) {
+        if (entry->func_id == func_id && entry->handler == handler) {
+            QTAILQ_REMOVE(&arm_smc_handlers, entry, node);
+            g_free(entry);
+            return;
+        }
+    }
+}
+
+bool arm_smc_handle_call(ARMCPU *cpu)
+{
+    CPUARMState *env = &cpu->env;
+    uint64_t func_id = is_a64(env) ? env->xregs[0] : env->regs[0];
+    ARMSCMCHandlerEntry *entry;
+
+    QTAILQ_FOREACH(entry, &arm_smc_handlers, node) {
+        uint64_t args[8], ret;
+
+        if (entry->func_id != func_id) {
+            continue;
+        }
+        for (size_t i = 0; i < ARRAY_SIZE(args); i++) {
+            args[i] = is_a64(env) ? env->xregs[i] : env->regs[i];
+        }
+        if (!entry->handler(args, &ret, entry->opaque)) {
+            return false;
+        }
+        if (is_a64(env)) {
+            env->xregs[0] = ret;
+        } else {
+            env->regs[0] = ret;
+        }
+        return true;
+    }
+
+    return false;
+}
+
 /*
  * Do semihosting call and set the appropriate return value. All the
  * permission and validity checks have been done at translate time.
@@ -9873,6 +9946,13 @@ void arm_cpu_do_interrupt(CPUState *cs)
                       env->exception.syndrome);
     }
 
+    if (tcg_enabled() && cs->exception_index == EXCP_SMC &&
+        arm_smc_handle_call(cpu)) {
+        qemu_log_mask(CPU_LOG_INT, "...handled as SMC handler call\n");
+        qemu_plugin_vcpu_hostcall_cb(cs, last_pc);
+        return;
+    }
+
     if (tcg_enabled() && arm_is_psci_call(cpu, cs->exception_index)) {
         arm_handle_psci_call(cpu);
         qemu_log_mask(CPU_LOG_INT, "...handled as PSCI call\n");
diff --git a/target/arm/internals.h b/target/arm/internals.h
index 033d6d66da..4c6825b201 100644
--- a/target/arm/internals.h
+++ b/target/arm/internals.h
@@ -717,6 +717,9 @@ bool arm_is_psci_call(ARMCPU *cpu, int excp_type);
 /* Actually handle a PSCI call */
 void arm_handle_psci_call(ARMCPU *cpu);
 
+/* Dispatch a registered SMC handler call, if any. */
+bool arm_smc_handle_call(ARMCPU *cpu);
+
 /**
  * arm_clear_exclusive: clear the exclusive monitor
  * @env: CPU env
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC PATCH 05/20] hw/block/m25p80: add the XTX XT25F128 SPI NOR flash
  2026-11-13  9:47 [RFC PATCH 00/20] hw/arm: Add initial RK3588 and ROCK 5B support Yifan Wang
                   ` (3 preceding siblings ...)
  2026-11-13  9:47 ` [RFC PATCH 04/20] target/arm: allow machines to handle SMC calls Yifan Wang
@ 2026-11-13  9:47 ` Yifan Wang
  2026-11-13  9:47 ` [RFC PATCH 06/20] hw/arm: add the Rockchip RK3588 SoC Yifan Wang
                   ` (14 subsequent siblings)
  19 siblings, 0 replies; 22+ messages in thread
From: Yifan Wang @ 2026-11-13  9:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Yifan Wang, qemu-arm, qemu-block, kvm, Peter Maydell,
	Pierrick Bouvier, Paolo Bonzini, Alistair Francis, Kevin Wolf,
	Hanna Reitz, Kuan-Wei Chiu, Marc-André Lureau, bin.meng,
	tangtao1634, Chao Liu

From: Chao Liu <chao.liu@processmission.com>

Add the 16 MiB XTX XT25F128 SPI NOR flash to m25p80 with JEDEC ID
0b 40 18, 64 KiB sectors and 4 KiB erase. XTX parts handle the status
registers, the quad enable bit and the read dummy cycles like Winbond
parts.

Signed-off-by: Chao Liu <chao.liu@processmission.com>
Signed-off-by: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
---
 hw/block/m25p80.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
index baf798c6b5..bad966d19a 100644
--- a/hw/block/m25p80.c
+++ b/hw/block/m25p80.c
@@ -356,6 +356,7 @@ static const FlashPartInfo known_devices[] = {
     { INFO("w25q32dw",    0xef6016,      0,  64 << 10,  64, ER_4K) },
     { INFO("w25q33pw",    0xef6016,      0,  64 << 10,  64, ER_4K | ER_32K),
       .sfdp_read = m25p80_sfdp_w25q33pw },
+    { INFO("xt25f128",    0x0b4018,      0,  64 << 10, 256, ER_4K) },
     { INFO("w25x64",      0xef3017,      0,  64 << 10, 128, ER_4K) },
     { INFO("w25q64",      0xef4017,      0,  64 << 10, 128, ER_4K) },
     { INFO("w25q80",      0xef5014,      0,  64 << 10,  16, ER_4K) },
@@ -468,6 +469,7 @@ typedef enum {
     MAN_MACRONIX,
     MAN_NUMONYX,
     MAN_WINBOND,
+    MAN_XTX,
     MAN_SST,
     MAN_ISSI,
     MAN_GENERIC,
@@ -545,6 +547,8 @@ static inline Manufacturer get_man(Flash *s)
         return MAN_NUMONYX;
     case 0xEF:
         return MAN_WINBOND;
+    case 0x0B:
+        return MAN_XTX;
     case 0x01:
         return MAN_SPANSION;
     case 0xC2:
@@ -652,6 +656,9 @@ static void flash_erase(Flash *s, int offset, FlashCMD cmd)
     }
     memset(s->storage + offset, 0xff, len);
     flash_sync_area(s, offset, len);
+    if (get_man(s) == MAN_XTX) {
+        s->write_enable = false;
+    }
 }
 
 static inline void flash_sync_dirty(Flash *s, int64_t newpage)
@@ -821,6 +828,7 @@ static void complete_collecting_data(Flash *s)
             }
             break;
         case MAN_WINBOND:
+        case MAN_XTX:
             if (s->len > 1) {
                 s->quad_enable = !!(s->data[1] & 0x02);
             }
@@ -835,6 +843,7 @@ static void complete_collecting_data(Flash *s)
     case WRSR2:
         switch (get_man(s)) {
         case MAN_WINBOND:
+        case MAN_XTX:
             s->quad_enable = !!(s->data[0] & 0x02);
             break;
         default:
@@ -1085,6 +1094,7 @@ static void decode_fast_read_cmd(Flash *s)
         s->needed_bytes += 1;
         break;
     case MAN_WINBOND:
+    case MAN_XTX:
         s->needed_bytes += 1;
         break;
     case MAN_NUMONYX:
@@ -1123,6 +1133,7 @@ static void decode_dio_read_cmd(Flash *s)
     /* Dummy cycles modeled with bytes writes instead of bits */
     switch (get_man(s)) {
     case MAN_WINBOND:
+    case MAN_XTX:
         s->needed_bytes += WINBOND_CONTINUOUS_READ_MODE_CMD_LEN;
         break;
     case MAN_SPANSION:
@@ -1159,6 +1170,7 @@ static void decode_qio_read_cmd(Flash *s)
     /* Dummy cycles modeled with bytes writes instead of bits */
     switch (get_man(s)) {
     case MAN_WINBOND:
+    case MAN_XTX:
         s->needed_bytes += WINBOND_CONTINUOUS_READ_MODE_CMD_LEN;
         s->needed_bytes += 2;
         break;
@@ -1337,6 +1349,7 @@ static void decode_new_cmd(Flash *s, uint32_t value)
             s->state = STATE_COLLECTING_VAR_LEN_DATA;
             break;
         case MAN_WINBOND:
+        case MAN_XTX:
             s->needed_bytes = 2;
             s->state = STATE_COLLECTING_VAR_LEN_DATA;
             break;
@@ -1363,6 +1376,7 @@ static void decode_new_cmd(Flash *s, uint32_t value)
 
         switch (get_man(s)) {
         case MAN_WINBOND:
+        case MAN_XTX:
             s->needed_bytes = 1;
             s->state = STATE_COLLECTING_DATA;
             s->pos = 0;
@@ -1542,6 +1556,7 @@ static void decode_new_cmd(Flash *s, uint32_t value)
             s->quad_enable = true;
             break;
         case MAN_WINBOND:
+        case MAN_XTX:
             s->data[0] = (!!s->quad_enable) << 1;
             s->pos = 0;
             s->len = 1;
@@ -1601,6 +1616,11 @@ static int m25p80_cs(SSIPeripheral *ss, bool select)
         if (s->state == STATE_COLLECTING_VAR_LEN_DATA) {
             complete_collecting_data(s);
         }
+        if (get_man(s) == MAN_XTX &&
+            s->state == STATE_PAGE_PROGRAM &&
+            s->cmd_in_progress != AAI_WP) {
+            s->write_enable = false;
+        }
         s->len = 0;
         s->pos = 0;
         s->state = STATE_IDLE;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC PATCH 06/20] hw/arm: add the Rockchip RK3588 SoC
  2026-11-13  9:47 [RFC PATCH 00/20] hw/arm: Add initial RK3588 and ROCK 5B support Yifan Wang
                   ` (4 preceding siblings ...)
  2026-11-13  9:47 ` [RFC PATCH 05/20] hw/block/m25p80: add the XTX XT25F128 SPI NOR flash Yifan Wang
@ 2026-11-13  9:47 ` Yifan Wang
  2026-11-13  9:47 ` [RFC PATCH 07/20] hw/timer: add Rockchip HPTIMER boot control Yifan Wang
                   ` (13 subsequent siblings)
  19 siblings, 0 replies; 22+ messages in thread
From: Yifan Wang @ 2026-11-13  9:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Yifan Wang, qemu-arm, qemu-block, kvm, Peter Maydell,
	Pierrick Bouvier, Paolo Bonzini, Alistair Francis, Kevin Wolf,
	Hanna Reitz, Kuan-Wei Chiu, Marc-André Lureau, bin.meng,
	tangtao1634, Chao Liu

From: Chao Liu <chao.liu@processmission.com>

Add the RK3588 SoC container with four Cortex-A55 and four Cortex-A76
CPUs, the system memory link and on-chip SRAM.

Signed-off-by: Chao Liu <chao.liu@processmission.com>
Signed-off-by: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
---
 MAINTAINERS             |   8 +++
 hw/arm/Kconfig          |   4 ++
 hw/arm/meson.build      |   2 +
 hw/arm/rk3588.c         | 149 ++++++++++++++++++++++++++++++++++++++++
 include/hw/arm/rk3588.h |  51 ++++++++++++++
 5 files changed, 214 insertions(+)
 create mode 100644 hw/arm/rk3588.c
 create mode 100644 include/hw/arm/rk3588.h

diff --git a/MAINTAINERS b/MAINTAINERS
index db1a62a0cb..e7caabd565 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1059,6 +1059,14 @@ F: include/hw/intc/realview_gic.h
 F: docs/system/arm/realview.rst
 F: tests/functional/arm/test_realview.py
 
+Rockchip RK3588
+M: Chao Liu <chao.liu@processmission.com>
+M: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
+L: qemu-arm@nongnu.org
+S: Maintained
+F: hw/arm/rk3588.c
+F: include/hw/arm/rk3588.h
+
 SABRELITE / i.MX6
 M: Peter Maydell <peter.maydell@linaro.org>
 R: Jean-Christophe Dubois <jcd@tribudubois.net>
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index e9f796f718..79b66de041 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -774,3 +774,7 @@ config AXIADO_EVK
     default y
     depends on TCG && ARM
     select AXIADO_SOC
+
+config RK3588
+    bool
+    select CPU_CLUSTER
diff --git a/hw/arm/meson.build b/hw/arm/meson.build
index f3c1b0e00f..70c835814f 100644
--- a/hw/arm/meson.build
+++ b/hw/arm/meson.build
@@ -120,4 +120,6 @@ arm_common_ss.add(when: ['CONFIG_AXIADO_EVK', 'TARGET_AARCH64'], if_true: files(
 
 arm_common_ss.add(files('boot.c'))
 
+arm_common_ss.add(when: 'CONFIG_RK3588', if_true: files('rk3588.c'))
+
 hw_common_arch += {'arm': arm_common_ss}
diff --git a/hw/arm/rk3588.c b/hw/arm/rk3588.c
new file mode 100644
index 0000000000..1e6f44433c
--- /dev/null
+++ b/hw/arm/rk3588.c
@@ -0,0 +1,149 @@
+/*
+ * Rockchip RK3588 SoC
+ *
+ * Copyright (C) 2026 Process Mission
+ *
+ * Authors:
+ *    Chao Liu <chao.liu@processmission.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/module.h"
+#include "qemu/units.h"
+#include "qapi/error.h"
+#include "hw/arm/rk3588.h"
+#include "hw/core/qdev-properties.h"
+#include "hw/core/sysbus.h"
+#include "hw/cpu/cluster.h"
+#include "migration/vmstate.h"
+
+/* MPIDR Aff0 values per Aff1: 1 (one CPU per RK3588 cluster). */
+#define RK3588_MPIDR_AFF0_PER_AFF1   (1)
+
+#define RK3588_CNTFRQ                24000000
+
+/* The RK3588 CPU map has one A55 quad cluster and two A76 dual clusters. */
+static const struct {
+    unsigned int num_cpus;
+    const char *cpu_type;
+} rk3588_cpu_clusters[] = {
+    [RK3588_CLUSTER_A55] = {
+        .num_cpus = RK3588_A55_CPUS,
+        .cpu_type = ARM_CPU_TYPE_NAME("cortex-a55"),
+    },
+    [RK3588_CLUSTER_A76_0] = {
+        .num_cpus = RK3588_A76_CPUS_PER_CLUSTER,
+        .cpu_type = ARM_CPU_TYPE_NAME("cortex-a76"),
+    },
+    [RK3588_CLUSTER_A76_1] = {
+        .num_cpus = RK3588_A76_CPUS_PER_CLUSTER,
+        .cpu_type = ARM_CPU_TYPE_NAME("cortex-a76"),
+    },
+};
+
+G_STATIC_ASSERT(ARRAY_SIZE(rk3588_cpu_clusters) == RK3588_CLUSTER_COUNT);
+
+static void rk3588_soc_realize(DeviceState *dev, Error **errp)
+{
+    RK3588SoCState *s = RK3588_SOC(dev);
+
+    if (!s->memory) {
+        error_setg(errp, "rk3588: memory link is required");
+        return;
+    }
+
+    for (unsigned int c = 0; c < RK3588_CLUSTER_COUNT; c++) {
+        if (!qdev_realize(DEVICE(&s->cluster[c]), NULL, errp)) {
+            return;
+        }
+    }
+
+    for (unsigned int n = 0; n < RK3588_NUM_CPUS; n++) {
+        ARMCPU *cpu = &s->cpu[n];
+        uint64_t mpidr = arm_build_mp_affinity(n, RK3588_MPIDR_AFF0_PER_AFF1);
+
+        CPU(cpu)->cpu_index = n;
+        object_property_set_int(OBJECT(cpu), "mp-affinity", mpidr,
+                                &error_abort);
+        object_property_set_int(OBJECT(cpu), "cntfrq", RK3588_CNTFRQ,
+                                &error_abort);
+        object_property_set_link(OBJECT(cpu), "memory",
+                                 OBJECT(s->memory), &error_abort);
+        if (n > 0) {
+            object_property_set_bool(OBJECT(cpu), "start-powered-off", true,
+                                     &error_abort);
+        }
+
+        if (!qdev_realize(DEVICE(cpu), NULL, errp)) {
+            return;
+        }
+    }
+
+    if (!memory_region_init_ram(&s->sram, OBJECT(s), "rk3588.sram",
+                                MiB, errp)) {
+        return;
+    }
+    memory_region_add_subregion(s->memory, RK3588_SRAM_BASE, &s->sram);
+}
+
+static void rk3588_soc_instance_init(Object *obj)
+{
+    RK3588SoCState *s = RK3588_SOC(obj);
+    unsigned int n = 0;
+
+    for (unsigned int c = 0; c < RK3588_CLUSTER_COUNT; c++) {
+        g_autofree char *cluster_name = g_strdup_printf("cluster%u", c);
+
+        object_initialize_child(obj, cluster_name, &s->cluster[c],
+                                TYPE_CPU_CLUSTER);
+        qdev_prop_set_uint32(DEVICE(&s->cluster[c]), "cluster-id", c);
+
+        for (unsigned int i = 0; i < rk3588_cpu_clusters[c].num_cpus; i++) {
+            g_autofree char *name = g_strdup_printf("cpu%u", n);
+
+            object_initialize_child(OBJECT(&s->cluster[c]), name,
+                                    &s->cpu[n],
+                                    rk3588_cpu_clusters[c].cpu_type);
+            n++;
+        }
+    }
+}
+
+static const Property rk3588_soc_properties[] = {
+    DEFINE_PROP_LINK("memory", RK3588SoCState, memory, TYPE_MEMORY_REGION,
+                     MemoryRegion *),
+};
+
+static const VMStateDescription vmstate_rk3588_soc = {
+    .name = TYPE_RK3588_SOC,
+    .unmigratable = true,
+};
+
+static void rk3588_soc_class_init(ObjectClass *oc, const void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+
+    dc->realize = rk3588_soc_realize;
+    dc->desc = "Rockchip RK3588";
+    dc->vmsd = &vmstate_rk3588_soc;
+    dc->user_creatable = false;
+    device_class_set_props(dc, rk3588_soc_properties);
+}
+
+static const TypeInfo rk3588_soc_typeinfo = {
+    .name = TYPE_RK3588_SOC,
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(RK3588SoCState),
+    .class_init = rk3588_soc_class_init,
+    .instance_init = rk3588_soc_instance_init,
+};
+
+static void rk3588_soc_register_types(void)
+{
+    type_register_static(&rk3588_soc_typeinfo);
+}
+
+type_init(rk3588_soc_register_types)
diff --git a/include/hw/arm/rk3588.h b/include/hw/arm/rk3588.h
new file mode 100644
index 0000000000..450af3d282
--- /dev/null
+++ b/include/hw/arm/rk3588.h
@@ -0,0 +1,51 @@
+/*
+ * Rockchip RK3588 SoC
+ *
+ * Copyright (C) 2026 Process Mission
+ *
+ * Authors:
+ *    Chao Liu <chao.liu@processmission.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ */
+
+#ifndef HW_ARM_RK3588_H
+#define HW_ARM_RK3588_H
+
+#include "qom/object.h"
+#include "target/arm/cpu.h"
+#include "hw/core/qdev.h"
+#include "hw/cpu/cluster.h"
+#include "system/memory.h"
+
+#define TYPE_RK3588_SOC "rockchip.rk3588.soc"
+OBJECT_DECLARE_SIMPLE_TYPE(RK3588SoCState, RK3588_SOC)
+
+#define RK3588_A55_CPUS              (4)
+#define RK3588_A76_CPUS_PER_CLUSTER  (2)
+
+typedef enum RK3588CpuClusterId {
+    RK3588_CLUSTER_A55,
+    RK3588_CLUSTER_A76_0,
+    RK3588_CLUSTER_A76_1,
+    RK3588_CLUSTER_COUNT,
+} RK3588CpuClusterId;
+
+#define RK3588_NUM_CPUS (RK3588_A55_CPUS + \
+    RK3588_A76_CPUS_PER_CLUSTER * (RK3588_CLUSTER_COUNT - 1))
+
+#define RK3588_SRAM_BASE             0xff000000
+
+struct RK3588SoCState {
+    /*< private >*/
+    DeviceState parent_obj;
+
+    /*< public >*/
+    ARMCPU cpu[RK3588_NUM_CPUS];
+    CPUClusterState cluster[RK3588_CLUSTER_COUNT];
+    MemoryRegion *memory;
+    MemoryRegion sram;
+};
+
+#endif /* HW_ARM_RK3588_H */
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC PATCH 07/20] hw/timer: add Rockchip HPTIMER boot control
  2026-11-13  9:47 [RFC PATCH 00/20] hw/arm: Add initial RK3588 and ROCK 5B support Yifan Wang
                   ` (5 preceding siblings ...)
  2026-11-13  9:47 ` [RFC PATCH 06/20] hw/arm: add the Rockchip RK3588 SoC Yifan Wang
@ 2026-11-13  9:47 ` Yifan Wang
  2026-11-13  9:47 ` [RFC PATCH 08/20] hw/arm/rk3588: add the unimplemented device map Yifan Wang
                   ` (12 subsequent siblings)
  19 siblings, 0 replies; 22+ messages in thread
From: Yifan Wang @ 2026-11-13  9:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Yifan Wang, qemu-arm, qemu-block, kvm, Peter Maydell,
	Pierrick Bouvier, Paolo Bonzini, Alistair Francis, Kevin Wolf,
	Hanna Reitz, Kuan-Wei Chiu, Marc-André Lureau, bin.meng,
	tangtao1634, Chao Liu

From: Chao Liu <chao.liu@processmission.com>

Implement the HPTIMER control register enable bit used during firmware
boot and connect the device to the RK3588 SoC. Reset the enable state in
the device; the board supplies the firmware handoff state.

Signed-off-by: Chao Liu <chao.liu@processmission.com>
Signed-off-by: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
---
 MAINTAINERS                         |   2 +
 hw/arm/rk3588.c                     |  23 ++++++
 hw/timer/meson.build                |   1 +
 hw/timer/rockchip-hptimer.c         | 115 ++++++++++++++++++++++++++++
 include/hw/arm/rk3588.h             |   2 +
 include/hw/timer/rockchip-hptimer.h |  20 +++++
 6 files changed, 163 insertions(+)
 create mode 100644 hw/timer/rockchip-hptimer.c
 create mode 100644 include/hw/timer/rockchip-hptimer.h

diff --git a/MAINTAINERS b/MAINTAINERS
index e7caabd565..4fc6f8e59d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1065,7 +1065,9 @@ M: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
 L: qemu-arm@nongnu.org
 S: Maintained
 F: hw/arm/rk3588.c
+F: hw/timer/rockchip-hptimer.c
 F: include/hw/arm/rk3588.h
+F: include/hw/timer/rockchip-hptimer.h
 
 SABRELITE / i.MX6
 M: Peter Maydell <peter.maydell@linaro.org>
diff --git a/hw/arm/rk3588.c b/hw/arm/rk3588.c
index 1e6f44433c..8255aee7fc 100644
--- a/hw/arm/rk3588.c
+++ b/hw/arm/rk3588.c
@@ -18,6 +18,7 @@
 #include "hw/core/qdev-properties.h"
 #include "hw/core/sysbus.h"
 #include "hw/cpu/cluster.h"
+#include "hw/timer/rockchip-hptimer.h"
 #include "migration/vmstate.h"
 
 /* MPIDR Aff0 values per Aff1: 1 (one CPU per RK3588 cluster). */
@@ -46,6 +47,20 @@ static const struct {
 
 G_STATIC_ASSERT(ARRAY_SIZE(rk3588_cpu_clusters) == RK3588_CLUSTER_COUNT);
 
+static bool rk3588_soc_create_hptimer(RK3588SoCState *s, Error **errp)
+{
+    SysBusDevice *hptimer = SYS_BUS_DEVICE(s->hptimer);
+
+    if (!sysbus_realize(hptimer, errp)) {
+        return false;
+    }
+
+    memory_region_add_subregion(s->memory, RK3588_HPTIMER_BASE,
+                                sysbus_mmio_get_region(hptimer, 0));
+
+    return true;
+}
+
 static void rk3588_soc_realize(DeviceState *dev, Error **errp)
 {
     RK3588SoCState *s = RK3588_SOC(dev);
@@ -82,6 +97,10 @@ static void rk3588_soc_realize(DeviceState *dev, Error **errp)
         }
     }
 
+    if (!rk3588_soc_create_hptimer(s, errp)) {
+        return;
+    }
+
     if (!memory_region_init_ram(&s->sram, OBJECT(s), "rk3588.sram",
                                 MiB, errp)) {
         return;
@@ -110,6 +129,10 @@ static void rk3588_soc_instance_init(Object *obj)
             n++;
         }
     }
+
+    s->hptimer = qdev_new(TYPE_ROCKCHIP_HPTIMER);
+    object_property_add_child(obj, "hptimer", OBJECT(s->hptimer));
+    object_unref(OBJECT(s->hptimer));
 }
 
 static const Property rk3588_soc_properties[] = {
diff --git a/hw/timer/meson.build b/hw/timer/meson.build
index e2bcdbdf65..5375f26b47 100644
--- a/hw/timer/meson.build
+++ b/hw/timer/meson.build
@@ -23,6 +23,7 @@ system_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_timer.c'))
 system_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_timer.c'))
 system_ss.add(when: 'CONFIG_PXA2XX_TIMER', if_true: files('pxa2xx_timer.c'))
 system_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_systmr.c'))
+system_ss.add(when: 'CONFIG_RK3588', if_true: files('rockchip-hptimer.c'))
 system_ss.add(when: 'CONFIG_SH_TIMER', if_true: files('sh_timer.c'))
 system_ss.add(when: 'CONFIG_SLAVIO', if_true: files('slavio_timer.c'))
 system_ss.add(when: 'CONFIG_SSE_COUNTER', if_true: files('sse-counter.c'))
diff --git a/hw/timer/rockchip-hptimer.c b/hw/timer/rockchip-hptimer.c
new file mode 100644
index 0000000000..200894036c
--- /dev/null
+++ b/hw/timer/rockchip-hptimer.c
@@ -0,0 +1,115 @@
+/*
+ * Rockchip RK3588 HPTIMER boot control register
+ *
+ * Copyright (C) 2026 Process Mission
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/log.h"
+#include "qemu/module.h"
+#include "qemu/units.h"
+#include "hw/core/resettable.h"
+#include "hw/core/sysbus.h"
+#include "hw/timer/rockchip-hptimer.h"
+#include "migration/vmstate.h"
+
+/* Model the enable state used at firmware handoff; the CPU provides timing. */
+struct RockchipHPTimerState {
+    SysBusDevice parent_obj;
+    MemoryRegion iomem;
+    uint32_t ctrl;
+};
+
+static uint64_t rockchip_hptimer_read(void *opaque, hwaddr offset,
+                                     unsigned size)
+{
+    RockchipHPTimerState *s = ROCKCHIP_HPTIMER(opaque);
+
+    switch (offset) {
+    case ROCKCHIP_HPTIMER_CTRL:
+        return s->ctrl;
+    default:
+        qemu_log_mask(LOG_UNIMP, "rockchip-hptimer: unimplemented read at "
+                      "0x%" HWADDR_PRIx "\n", offset);
+        return 0;
+    }
+}
+
+static void rockchip_hptimer_write(void *opaque, hwaddr offset,
+                                  uint64_t value, unsigned size)
+{
+    RockchipHPTimerState *s = ROCKCHIP_HPTIMER(opaque);
+
+    switch (offset) {
+    case ROCKCHIP_HPTIMER_CTRL:
+        s->ctrl = value & ROCKCHIP_HPTIMER_ENABLE;
+        break;
+    default:
+        qemu_log_mask(LOG_UNIMP, "rockchip-hptimer: unimplemented write at "
+                      "0x%" HWADDR_PRIx "\n", offset);
+        break;
+    }
+}
+
+static const MemoryRegionOps rockchip_hptimer_ops = {
+    .read = rockchip_hptimer_read,
+    .write = rockchip_hptimer_write,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+    .valid = {
+        .min_access_size = 4,
+        .max_access_size = 4,
+    },
+    .impl = {
+        .min_access_size = 4,
+        .max_access_size = 4,
+    },
+};
+
+static void rockchip_hptimer_reset_enter(Object *obj, ResetType type)
+{
+    RockchipHPTimerState *s = ROCKCHIP_HPTIMER(obj);
+
+    s->ctrl = 0;
+}
+
+static void rockchip_hptimer_init(Object *obj)
+{
+    RockchipHPTimerState *s = ROCKCHIP_HPTIMER(obj);
+
+    memory_region_init_io(&s->iomem, obj, &rockchip_hptimer_ops, s,
+                          TYPE_ROCKCHIP_HPTIMER, 16 * KiB);
+    sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
+}
+
+static const VMStateDescription vmstate_rockchip_hptimer = {
+    .name = TYPE_ROCKCHIP_HPTIMER,
+    .unmigratable = true,
+};
+
+static void rockchip_hptimer_class_init(ObjectClass *oc, const void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+    ResettableClass *rc = RESETTABLE_CLASS(oc);
+
+    rc->phases.enter = rockchip_hptimer_reset_enter;
+    dc->desc = "Rockchip RK3588 HPTIMER boot control";
+    dc->vmsd = &vmstate_rockchip_hptimer;
+    dc->user_creatable = false;
+}
+
+static const TypeInfo rockchip_hptimer_typeinfo = {
+    .name = TYPE_ROCKCHIP_HPTIMER,
+    .parent = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(RockchipHPTimerState),
+    .instance_init = rockchip_hptimer_init,
+    .class_init = rockchip_hptimer_class_init,
+};
+
+static void rockchip_hptimer_register_types(void)
+{
+    type_register_static(&rockchip_hptimer_typeinfo);
+}
+
+type_init(rockchip_hptimer_register_types)
diff --git a/include/hw/arm/rk3588.h b/include/hw/arm/rk3588.h
index 450af3d282..8539d2e64d 100644
--- a/include/hw/arm/rk3588.h
+++ b/include/hw/arm/rk3588.h
@@ -36,6 +36,7 @@ typedef enum RK3588CpuClusterId {
     RK3588_A76_CPUS_PER_CLUSTER * (RK3588_CLUSTER_COUNT - 1))
 
 #define RK3588_SRAM_BASE             0xff000000
+#define RK3588_HPTIMER_BASE          0xfd8c8000
 
 struct RK3588SoCState {
     /*< private >*/
@@ -46,6 +47,7 @@ struct RK3588SoCState {
     CPUClusterState cluster[RK3588_CLUSTER_COUNT];
     MemoryRegion *memory;
     MemoryRegion sram;
+    DeviceState *hptimer;
 };
 
 #endif /* HW_ARM_RK3588_H */
diff --git a/include/hw/timer/rockchip-hptimer.h b/include/hw/timer/rockchip-hptimer.h
new file mode 100644
index 0000000000..2e9f5fd819
--- /dev/null
+++ b/include/hw/timer/rockchip-hptimer.h
@@ -0,0 +1,20 @@
+/*
+ * Rockchip RK3588 HPTIMER
+ *
+ * Copyright (C) 2026 Process Mission
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_TIMER_ROCKCHIP_HPTIMER_H
+#define HW_TIMER_ROCKCHIP_HPTIMER_H
+
+#include "qom/object.h"
+
+#define TYPE_ROCKCHIP_HPTIMER "rockchip-hptimer"
+OBJECT_DECLARE_SIMPLE_TYPE(RockchipHPTimerState, ROCKCHIP_HPTIMER)
+
+#define ROCKCHIP_HPTIMER_CTRL   0x04
+#define ROCKCHIP_HPTIMER_ENABLE (1U << 0)
+
+#endif /* HW_TIMER_ROCKCHIP_HPTIMER_H */
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC PATCH 08/20] hw/arm/rk3588: add the unimplemented device map
  2026-11-13  9:47 [RFC PATCH 00/20] hw/arm: Add initial RK3588 and ROCK 5B support Yifan Wang
                   ` (6 preceding siblings ...)
  2026-11-13  9:47 ` [RFC PATCH 07/20] hw/timer: add Rockchip HPTIMER boot control Yifan Wang
@ 2026-11-13  9:47 ` Yifan Wang
  2026-11-13  9:47 ` [RFC PATCH 09/20] hw/arm/rk3588: add the GICv3 interrupt controller Yifan Wang
                   ` (11 subsequent siblings)
  19 siblings, 0 replies; 22+ messages in thread
From: Yifan Wang @ 2026-11-13  9:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Yifan Wang, qemu-arm, qemu-block, kvm, Peter Maydell,
	Pierrick Bouvier, Paolo Bonzini, Alistair Francis, Kevin Wolf,
	Hanna Reitz, Kuan-Wei Chiu, Marc-André Lureau, bin.meng,
	tangtao1634, Chao Liu

From: Chao Liu <chao.liu@processmission.com>

Add placeholder regions for the RK3588 peripheral windows that are not
modeled yet, so that guest accesses do not report errors while the
devices are being brought up.

Signed-off-by: Chao Liu <chao.liu@processmission.com>
Signed-off-by: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
---
 hw/arm/Kconfig  |  1 +
 hw/arm/rk3588.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+)

diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index 79b66de041..55fdc78364 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -778,3 +778,4 @@ config AXIADO_EVK
 config RK3588
     bool
     select CPU_CLUSTER
+    select UNIMP
diff --git a/hw/arm/rk3588.c b/hw/arm/rk3588.c
index 8255aee7fc..ecaaa09721 100644
--- a/hw/arm/rk3588.c
+++ b/hw/arm/rk3588.c
@@ -18,6 +18,7 @@
 #include "hw/core/qdev-properties.h"
 #include "hw/core/sysbus.h"
 #include "hw/cpu/cluster.h"
+#include "hw/misc/unimp.h"
 #include "hw/timer/rockchip-hptimer.h"
 #include "migration/vmstate.h"
 
@@ -26,6 +27,71 @@
 
 #define RK3588_CNTFRQ                24000000
 
+#define RK3588_UNIMPLEMENTED(name, base, size) \
+    { "unimpl-" name, "rk3588." name, base, size, -1000 }
+
+/* Peripheral windows from RK3588 TRM v1.0, Table 1-1. */
+static const UnimplementedDeviceConfig rk3588_unimpl_devices[] = {
+    RK3588_UNIMPLEMENTED("firewall-ddr", 0xfe030000, 32 * KiB),
+    RK3588_UNIMPLEMENTED("firewall-sysmem", 0xfe038000, 32 * KiB),
+    RK3588_UNIMPLEMENTED("usb3-2", 0xfcd00000, 4 * MiB),
+    RK3588_UNIMPLEMENTED("pmu0-grf", 0xfd588000, 8 * KiB),
+    RK3588_UNIMPLEMENTED("pmu1-grf", 0xfd58a000, 8 * KiB),
+    RK3588_UNIMPLEMENTED("sys-grf", 0xfd58c000, 16 * KiB),
+    RK3588_UNIMPLEMENTED("usb2phy1-grf", 0xfd5d4000, 16 * KiB),
+    RK3588_UNIMPLEMENTED("usb2phy2-grf", 0xfd5d8000, 16 * KiB),
+    RK3588_UNIMPLEMENTED("usb2phy3-grf", 0xfd5dc000, 16 * KiB),
+    RK3588_UNIMPLEMENTED("pmu1-ioc", 0xfd5f0000, 16 * KiB),
+    RK3588_UNIMPLEMENTED("pmu2-ioc", 0xfd5f4000, 16 * KiB),
+    RK3588_UNIMPLEMENTED("bus-ioc", 0xfd5f8000, 4 * KiB),
+    RK3588_UNIMPLEMENTED("vccio1-4-ioc", 0xfd5f9000, 4 * KiB),
+    RK3588_UNIMPLEMENTED("vccio3-5-ioc", 0xfd5fa000, 4 * KiB),
+    RK3588_UNIMPLEMENTED("vccio2-ioc", 0xfd5fb000, 4 * KiB),
+    RK3588_UNIMPLEMENTED("vccio6-ioc", 0xfd5fc000, 4 * KiB),
+    RK3588_UNIMPLEMENTED("emmc-ioc", 0xfd5fd000, 4 * KiB),
+    RK3588_UNIMPLEMENTED("cru-ns", 0xfd7c0000, 32 * KiB),
+    RK3588_UNIMPLEMENTED("php-ppll-cru", 0xfd7c8000, 32 * KiB),
+    RK3588_UNIMPLEMENTED("pmu1-cru", 0xfd7f0000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("bigcore0-cru", 0xfd810000, 8 * KiB),
+    RK3588_UNIMPLEMENTED("bigcore1-cru", 0xfd812000, 8 * KiB),
+    RK3588_UNIMPLEMENTED("dsu-cru", 0xfd818000, 16 * KiB),
+    RK3588_UNIMPLEMENTED("i2c0", 0xfd880000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("gpio0", 0xfd8a0000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("pwm0", 0xfd8b0000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("fspi", 0xfe2b0000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("sdmmc", 0xfe2c0000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("sdio", 0xfe2d0000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("emmc", 0xfe2e0000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("trng-ns", 0xfe378000, 32 * KiB),
+    RK3588_UNIMPLEMENTED("gic600", 0xfe600000, 4 * MiB),
+    RK3588_UNIMPLEMENTED("dmac0", 0xfea10000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("dmac1", 0xfea30000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("i2c4", 0xfeac0000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("timer-ns0", 0xfeae0000, 32 * KiB),
+    RK3588_UNIMPLEMENTED("wdt-ns", 0xfeaf0000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("spi2", 0xfeb20000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("uart1", 0xfeb40000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("uart2", 0xfeb50000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("uart3", 0xfeb60000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("uart4", 0xfeb70000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("uart5", 0xfeb80000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("uart6", 0xfeb90000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("uart7", 0xfeba0000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("uart8", 0xfebb0000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("uart9", 0xfebc0000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("gpio1", 0xfec20000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("gpio2", 0xfec30000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("gpio3", 0xfec40000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("gpio4", 0xfec50000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("i2c6", 0xfec80000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("i2c7", 0xfec90000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("otp-ns", 0xfecc0000, 64 * KiB),
+    RK3588_UNIMPLEMENTED("dmac2", 0xfed10000, 64 * KiB),
+    { }
+};
+
+#undef RK3588_UNIMPLEMENTED
+
 /* The RK3588 CPU map has one A55 quad cluster and two A76 dual clusters. */
 static const struct {
     unsigned int num_cpus;
@@ -101,6 +167,8 @@ static void rk3588_soc_realize(DeviceState *dev, Error **errp)
         return;
     }
 
+    create_unimplemented_devices(OBJECT(s), s->memory, rk3588_unimpl_devices);
+
     if (!memory_region_init_ram(&s->sram, OBJECT(s), "rk3588.sram",
                                 MiB, errp)) {
         return;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC PATCH 09/20] hw/arm/rk3588: add the GICv3 interrupt controller
  2026-11-13  9:47 [RFC PATCH 00/20] hw/arm: Add initial RK3588 and ROCK 5B support Yifan Wang
                   ` (7 preceding siblings ...)
  2026-11-13  9:47 ` [RFC PATCH 08/20] hw/arm/rk3588: add the unimplemented device map Yifan Wang
@ 2026-11-13  9:47 ` Yifan Wang
  2026-11-13  9:47 ` [RFC PATCH 10/20] hw/arm/rk3588: add the UARTs Yifan Wang
                   ` (10 subsequent siblings)
  19 siblings, 0 replies; 22+ messages in thread
From: Yifan Wang @ 2026-11-13  9:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Yifan Wang, qemu-arm, qemu-block, kvm, Peter Maydell,
	Pierrick Bouvier, Paolo Bonzini, Alistair Francis, Kevin Wolf,
	Hanna Reitz, Kuan-Wei Chiu, Marc-André Lureau, bin.meng,
	tangtao1634, Chao Liu

From: Chao Liu <chao.liu@processmission.com>

Add a GICv3 interrupt controller with 512 interrupts and wire the
architectural timer and maintenance interrupts to the CPUs.

Signed-off-by: Chao Liu <chao.liu@processmission.com>
Signed-off-by: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
---
 hw/arm/Kconfig          |  1 +
 hw/arm/rk3588.c         | 86 +++++++++++++++++++++++++++++++++++++++--
 include/hw/arm/rk3588.h |  2 +
 3 files changed, 86 insertions(+), 3 deletions(-)

diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index 55fdc78364..73e1154040 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -777,5 +777,6 @@ config AXIADO_EVK
 
 config RK3588
     bool
+    select ARM_GIC
     select CPU_CLUSTER
     select UNIMP
diff --git a/hw/arm/rk3588.c b/hw/arm/rk3588.c
index ecaaa09721..3682cf275b 100644
--- a/hw/arm/rk3588.c
+++ b/hw/arm/rk3588.c
@@ -15,18 +15,34 @@
 #include "qemu/units.h"
 #include "qapi/error.h"
 #include "hw/arm/rk3588.h"
+#include "hw/arm/bsa.h"
 #include "hw/core/qdev-properties.h"
 #include "hw/core/sysbus.h"
 #include "hw/cpu/cluster.h"
 #include "hw/misc/unimp.h"
 #include "hw/timer/rockchip-hptimer.h"
 #include "migration/vmstate.h"
+#include "qobject/qlist.h"
+#include "target/arm/gtimer.h"
 
 /* MPIDR Aff0 values per Aff1: 1 (one CPU per RK3588 cluster). */
 #define RK3588_MPIDR_AFF0_PER_AFF1   (1)
 
 #define RK3588_CNTFRQ                24000000
 
+#define RK3588_GIC_NUM_IRQS          512
+
+enum {
+    RK3588_DEV_GIC_DIST,
+    RK3588_DEV_GIC_REDIST,
+};
+
+/* Memory map of the modeled peripherals. */
+static const MemMapEntry rk3588_memmap[] = {
+    [RK3588_DEV_GIC_DIST]   = { 0xfe600000, 0x00010000 },
+    [RK3588_DEV_GIC_REDIST] = { 0xfe680000, 0x00100000 },
+};
+
 #define RK3588_UNIMPLEMENTED(name, base, size) \
     { "unimpl-" name, "rk3588." name, base, size, -1000 }
 
@@ -63,7 +79,6 @@ static const UnimplementedDeviceConfig rk3588_unimpl_devices[] = {
     RK3588_UNIMPLEMENTED("sdio", 0xfe2d0000, 64 * KiB),
     RK3588_UNIMPLEMENTED("emmc", 0xfe2e0000, 64 * KiB),
     RK3588_UNIMPLEMENTED("trng-ns", 0xfe378000, 32 * KiB),
-    RK3588_UNIMPLEMENTED("gic600", 0xfe600000, 4 * MiB),
     RK3588_UNIMPLEMENTED("dmac0", 0xfea10000, 64 * KiB),
     RK3588_UNIMPLEMENTED("dmac1", 0xfea30000, 64 * KiB),
     RK3588_UNIMPLEMENTED("i2c4", 0xfeac0000, 64 * KiB),
@@ -113,6 +128,69 @@ static const struct {
 
 G_STATIC_ASSERT(ARRAY_SIZE(rk3588_cpu_clusters) == RK3588_CLUSTER_COUNT);
 
+static bool rk3588_soc_create_gic(RK3588SoCState *s, Error **errp)
+{
+    DeviceState *gicdev = DEVICE(&s->gic);
+    SysBusDevice *gicsbd = SYS_BUS_DEVICE(gicdev);
+    QList *redist_region_count = qlist_new();
+
+    qdev_prop_set_uint32(gicdev, "num-cpu", RK3588_NUM_CPUS);
+    qdev_prop_set_uint32(gicdev, "num-irq", RK3588_GIC_NUM_IRQS);
+    qlist_append_int(redist_region_count, RK3588_NUM_CPUS);
+    qdev_prop_set_array(gicdev, "redist-region-count", redist_region_count);
+    object_property_set_link(OBJECT(gicdev), "sysmem",
+                             OBJECT(s->memory), &error_abort);
+
+    if (!sysbus_realize(gicsbd, errp)) {
+        return false;
+    }
+
+    memory_region_add_subregion(s->memory,
+        rk3588_memmap[RK3588_DEV_GIC_DIST].base,
+        sysbus_mmio_get_region(gicsbd, 0));
+    memory_region_add_subregion(s->memory,
+        rk3588_memmap[RK3588_DEV_GIC_REDIST].base,
+        sysbus_mmio_get_region(gicsbd, 1));
+
+    for (unsigned int i = 0; i < RK3588_NUM_CPUS; i++) {
+        DeviceState *cpudev = DEVICE(&s->cpu[i]);
+        int intidbase = RK3588_GIC_NUM_IRQS - GIC_INTERNAL + (i * GIC_INTERNAL);
+        static const int timer_irqs[] = {
+            [GTIMER_PHYS] = ARCH_TIMER_NS_EL1_IRQ,
+            [GTIMER_VIRT] = ARCH_TIMER_VIRT_IRQ,
+            [GTIMER_HYP] = ARCH_TIMER_NS_EL2_IRQ,
+            [GTIMER_SEC] = ARCH_TIMER_S_EL1_IRQ,
+            [GTIMER_HYPVIRT] = ARCH_TIMER_NS_EL2_VIRT_IRQ,
+        };
+
+        for (unsigned int j = 0; j < ARRAY_SIZE(timer_irqs); j++) {
+            qdev_connect_gpio_out(cpudev, j,
+                                  qdev_get_gpio_in(gicdev,
+                                                   intidbase + timer_irqs[j]));
+        }
+
+        qdev_connect_gpio_out_named(cpudev, "gicv3-maintenance-interrupt", 0,
+                                    qdev_get_gpio_in(gicdev,
+                                                     intidbase +
+                                                     ARCH_GIC_MAINT_IRQ));
+        qdev_connect_gpio_out_named(cpudev, "pmu-interrupt", 0,
+                                    qdev_get_gpio_in(gicdev,
+                                                     intidbase +
+                                                     VIRTUAL_PMU_IRQ));
+
+        sysbus_connect_irq(gicsbd, i,
+                           qdev_get_gpio_in(cpudev, ARM_CPU_IRQ));
+        sysbus_connect_irq(gicsbd, i + RK3588_NUM_CPUS,
+                           qdev_get_gpio_in(cpudev, ARM_CPU_FIQ));
+        sysbus_connect_irq(gicsbd, i + 2 * RK3588_NUM_CPUS,
+                           qdev_get_gpio_in(cpudev, ARM_CPU_VIRQ));
+        sysbus_connect_irq(gicsbd, i + 3 * RK3588_NUM_CPUS,
+                           qdev_get_gpio_in(cpudev, ARM_CPU_VFIQ));
+    }
+
+    return true;
+}
+
 static bool rk3588_soc_create_hptimer(RK3588SoCState *s, Error **errp)
 {
     SysBusDevice *hptimer = SYS_BUS_DEVICE(s->hptimer);
@@ -163,10 +241,10 @@ static void rk3588_soc_realize(DeviceState *dev, Error **errp)
         }
     }
 
-    if (!rk3588_soc_create_hptimer(s, errp)) {
+    if (!rk3588_soc_create_gic(s, errp) ||
+        !rk3588_soc_create_hptimer(s, errp)) {
         return;
     }
-
     create_unimplemented_devices(OBJECT(s), s->memory, rk3588_unimpl_devices);
 
     if (!memory_region_init_ram(&s->sram, OBJECT(s), "rk3588.sram",
@@ -198,6 +276,8 @@ static void rk3588_soc_instance_init(Object *obj)
         }
     }
 
+    object_initialize_child(obj, "gic", &s->gic, TYPE_ARM_GICV3);
+
     s->hptimer = qdev_new(TYPE_ROCKCHIP_HPTIMER);
     object_property_add_child(obj, "hptimer", OBJECT(s->hptimer));
     object_unref(OBJECT(s->hptimer));
diff --git a/include/hw/arm/rk3588.h b/include/hw/arm/rk3588.h
index 8539d2e64d..fcb9ef5964 100644
--- a/include/hw/arm/rk3588.h
+++ b/include/hw/arm/rk3588.h
@@ -17,6 +17,7 @@
 #include "target/arm/cpu.h"
 #include "hw/core/qdev.h"
 #include "hw/cpu/cluster.h"
+#include "hw/intc/arm_gicv3.h"
 #include "system/memory.h"
 
 #define TYPE_RK3588_SOC "rockchip.rk3588.soc"
@@ -45,6 +46,7 @@ struct RK3588SoCState {
     /*< public >*/
     ARMCPU cpu[RK3588_NUM_CPUS];
     CPUClusterState cluster[RK3588_CLUSTER_COUNT];
+    GICv3State gic;
     MemoryRegion *memory;
     MemoryRegion sram;
     DeviceState *hptimer;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC PATCH 10/20] hw/arm/rk3588: add the UARTs
  2026-11-13  9:47 [RFC PATCH 00/20] hw/arm: Add initial RK3588 and ROCK 5B support Yifan Wang
                   ` (8 preceding siblings ...)
  2026-11-13  9:47 ` [RFC PATCH 09/20] hw/arm/rk3588: add the GICv3 interrupt controller Yifan Wang
@ 2026-11-13  9:47 ` Yifan Wang
  2026-11-13  9:47 ` [RFC PATCH 11/20] hw/misc: add the RK3588 clock and reset unit Yifan Wang
                   ` (9 subsequent siblings)
  19 siblings, 0 replies; 22+ messages in thread
From: Yifan Wang @ 2026-11-13  9:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Yifan Wang, qemu-arm, qemu-block, kvm, Peter Maydell,
	Pierrick Bouvier, Paolo Bonzini, Alistair Francis, Kevin Wolf,
	Hanna Reitz, Kuan-Wei Chiu, Marc-André Lureau, bin.meng,
	tangtao1634, Chao Liu

From: Chao Liu <chao.liu@processmission.com>

Instantiate DW8250 UARTs for UART1 through UART9. They start at
0xfeb40000 with a 64 KiB stride, use GIC SPIs 332 through 340 and run
from a 24 MHz reference clock. UART0 in the PMU power domain remains an
unimplemented device.

Expose each UART's chardev property on the SoC so that boards can
connect their serial ports.

Signed-off-by: Chao Liu <chao.liu@processmission.com>
Signed-off-by: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
---
 hw/arm/Kconfig          |  1 +
 hw/arm/rk3588.c         | 69 +++++++++++++++++++++++++++++++++++------
 include/hw/arm/rk3588.h |  5 +++
 3 files changed, 66 insertions(+), 9 deletions(-)

diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index 73e1154040..b22d0ce4f6 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -779,4 +779,5 @@ config RK3588
     bool
     select ARM_GIC
     select CPU_CLUSTER
+    select DW8250
     select UNIMP
diff --git a/hw/arm/rk3588.c b/hw/arm/rk3588.c
index 3682cf275b..3dbd579806 100644
--- a/hw/arm/rk3588.c
+++ b/hw/arm/rk3588.c
@@ -32,15 +32,39 @@
 
 #define RK3588_GIC_NUM_IRQS          512
 
+/* UART1-UART9 are modeled; UART0 in the PMU power domain is unimplemented. */
+#define RK3588_FIRST_UART            (1)
+#define RK3588_UART1_SPI             332
+#define RK3588_UART_CLOCK            24000000
+#define RK3588_UART_BAUD_BASE        (RK3588_UART_CLOCK / 16)
+
 enum {
     RK3588_DEV_GIC_DIST,
     RK3588_DEV_GIC_REDIST,
+    RK3588_DEV_UART1,
+    RK3588_DEV_UART2,
+    RK3588_DEV_UART3,
+    RK3588_DEV_UART4,
+    RK3588_DEV_UART5,
+    RK3588_DEV_UART6,
+    RK3588_DEV_UART7,
+    RK3588_DEV_UART8,
+    RK3588_DEV_UART9,
 };
 
 /* Memory map of the modeled peripherals. */
 static const MemMapEntry rk3588_memmap[] = {
     [RK3588_DEV_GIC_DIST]   = { 0xfe600000, 0x00010000 },
     [RK3588_DEV_GIC_REDIST] = { 0xfe680000, 0x00100000 },
+    [RK3588_DEV_UART1]      = { 0xfeb40000, 0x00010000 },
+    [RK3588_DEV_UART2]      = { 0xfeb50000, 0x00010000 },
+    [RK3588_DEV_UART3]      = { 0xfeb60000, 0x00010000 },
+    [RK3588_DEV_UART4]      = { 0xfeb70000, 0x00010000 },
+    [RK3588_DEV_UART5]      = { 0xfeb80000, 0x00010000 },
+    [RK3588_DEV_UART6]      = { 0xfeb90000, 0x00010000 },
+    [RK3588_DEV_UART7]      = { 0xfeba0000, 0x00010000 },
+    [RK3588_DEV_UART8]      = { 0xfebb0000, 0x00010000 },
+    [RK3588_DEV_UART9]      = { 0xfebc0000, 0x00010000 },
 };
 
 #define RK3588_UNIMPLEMENTED(name, base, size) \
@@ -85,15 +109,6 @@ static const UnimplementedDeviceConfig rk3588_unimpl_devices[] = {
     RK3588_UNIMPLEMENTED("timer-ns0", 0xfeae0000, 32 * KiB),
     RK3588_UNIMPLEMENTED("wdt-ns", 0xfeaf0000, 64 * KiB),
     RK3588_UNIMPLEMENTED("spi2", 0xfeb20000, 64 * KiB),
-    RK3588_UNIMPLEMENTED("uart1", 0xfeb40000, 64 * KiB),
-    RK3588_UNIMPLEMENTED("uart2", 0xfeb50000, 64 * KiB),
-    RK3588_UNIMPLEMENTED("uart3", 0xfeb60000, 64 * KiB),
-    RK3588_UNIMPLEMENTED("uart4", 0xfeb70000, 64 * KiB),
-    RK3588_UNIMPLEMENTED("uart5", 0xfeb80000, 64 * KiB),
-    RK3588_UNIMPLEMENTED("uart6", 0xfeb90000, 64 * KiB),
-    RK3588_UNIMPLEMENTED("uart7", 0xfeba0000, 64 * KiB),
-    RK3588_UNIMPLEMENTED("uart8", 0xfebb0000, 64 * KiB),
-    RK3588_UNIMPLEMENTED("uart9", 0xfebc0000, 64 * KiB),
     RK3588_UNIMPLEMENTED("gpio1", 0xfec20000, 64 * KiB),
     RK3588_UNIMPLEMENTED("gpio2", 0xfec30000, 64 * KiB),
     RK3588_UNIMPLEMENTED("gpio3", 0xfec40000, 64 * KiB),
@@ -191,6 +206,28 @@ static bool rk3588_soc_create_gic(RK3588SoCState *s, Error **errp)
     return true;
 }
 
+static bool rk3588_soc_create_uart(RK3588SoCState *s, Error **errp)
+{
+    for (unsigned int i = RK3588_FIRST_UART; i < RK3588_NUM_UARTS; i++) {
+        SysBusDevice *uart = SYS_BUS_DEVICE(&s->uart[i]);
+        unsigned int n = i - RK3588_FIRST_UART;
+
+        qdev_prop_set_uint32(DEVICE(uart), "baudbase", RK3588_UART_BAUD_BASE);
+        if (!sysbus_realize(uart, errp)) {
+            return false;
+        }
+
+        memory_region_add_subregion(s->memory,
+            rk3588_memmap[RK3588_DEV_UART1 + n].base,
+            sysbus_mmio_get_region(uart, 0));
+        sysbus_connect_irq(uart, 0,
+                           qdev_get_gpio_in(DEVICE(&s->gic),
+                                            RK3588_UART1_SPI + n));
+    }
+
+    return true;
+}
+
 static bool rk3588_soc_create_hptimer(RK3588SoCState *s, Error **errp)
 {
     SysBusDevice *hptimer = SYS_BUS_DEVICE(s->hptimer);
@@ -245,6 +282,11 @@ static void rk3588_soc_realize(DeviceState *dev, Error **errp)
         !rk3588_soc_create_hptimer(s, errp)) {
         return;
     }
+
+    if (!rk3588_soc_create_uart(s, errp)) {
+        return;
+    }
+
     create_unimplemented_devices(OBJECT(s), s->memory, rk3588_unimpl_devices);
 
     if (!memory_region_init_ram(&s->sram, OBJECT(s), "rk3588.sram",
@@ -278,6 +320,15 @@ static void rk3588_soc_instance_init(Object *obj)
 
     object_initialize_child(obj, "gic", &s->gic, TYPE_ARM_GICV3);
 
+    for (unsigned int i = RK3588_FIRST_UART; i < RK3588_NUM_UARTS; i++) {
+        g_autofree char *name = g_strdup_printf("uart%u", i);
+        g_autofree char *alias = g_strdup_printf("uart%u-chardev", i);
+
+        object_initialize_child(obj, name, &s->uart[i], TYPE_DW8250);
+        object_property_add_alias(obj, alias, OBJECT(&s->uart[i]),
+                                  "chardev");
+    }
+
     s->hptimer = qdev_new(TYPE_ROCKCHIP_HPTIMER);
     object_property_add_child(obj, "hptimer", OBJECT(s->hptimer));
     object_unref(OBJECT(s->hptimer));
diff --git a/include/hw/arm/rk3588.h b/include/hw/arm/rk3588.h
index fcb9ef5964..61fa616795 100644
--- a/include/hw/arm/rk3588.h
+++ b/include/hw/arm/rk3588.h
@@ -15,6 +15,7 @@
 
 #include "qom/object.h"
 #include "target/arm/cpu.h"
+#include "hw/char/dw8250.h"
 #include "hw/core/qdev.h"
 #include "hw/cpu/cluster.h"
 #include "hw/intc/arm_gicv3.h"
@@ -36,6 +37,9 @@ typedef enum RK3588CpuClusterId {
 #define RK3588_NUM_CPUS (RK3588_A55_CPUS + \
     RK3588_A76_CPUS_PER_CLUSTER * (RK3588_CLUSTER_COUNT - 1))
 
+/* UART1-UART9 are modeled; UART0 in the PMU power domain is unimplemented. */
+#define RK3588_NUM_UARTS             (10)
+
 #define RK3588_SRAM_BASE             0xff000000
 #define RK3588_HPTIMER_BASE          0xfd8c8000
 
@@ -47,6 +51,7 @@ struct RK3588SoCState {
     ARMCPU cpu[RK3588_NUM_CPUS];
     CPUClusterState cluster[RK3588_CLUSTER_COUNT];
     GICv3State gic;
+    DW8250State uart[RK3588_NUM_UARTS];
     MemoryRegion *memory;
     MemoryRegion sram;
     DeviceState *hptimer;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC PATCH 11/20] hw/misc: add the RK3588 clock and reset unit
  2026-11-13  9:47 [RFC PATCH 00/20] hw/arm: Add initial RK3588 and ROCK 5B support Yifan Wang
                   ` (9 preceding siblings ...)
  2026-11-13  9:47 ` [RFC PATCH 10/20] hw/arm/rk3588: add the UARTs Yifan Wang
@ 2026-11-13  9:47 ` Yifan Wang
  2026-11-13  9:47 ` [RFC PATCH 12/20] hw/misc: add the RK3588 OTP controller Yifan Wang
                   ` (8 subsequent siblings)
  19 siblings, 0 replies; 22+ messages in thread
From: Yifan Wang @ 2026-11-13  9:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Yifan Wang, qemu-arm, qemu-block, kvm, Peter Maydell,
	Pierrick Bouvier, Paolo Bonzini, Alistair Francis, Kevin Wolf,
	Hanna Reitz, Kuan-Wei Chiu, Marc-André Lureau, bin.meng,
	tangtao1634, Chao Liu

From: Chao Liu <chao.liu@processmission.com>

Add a model of the RK3588 CRU registers that U-Boot programs before it
configures the SPI flash controller clock. The model stores the PLL
parameters and clock selections. CON0/CON1 and clock selections use
Rockchip high-word write masks; fractional PLL CON2 stores a 16-bit K
value. Report PLL lock when powered up with valid M, P and S values.
Other CRU registers read as zero and log as unimplemented.

Signed-off-by: Chao Liu <chao.liu@processmission.com>
Signed-off-by: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
---
 MAINTAINERS             |   1 +
 hw/arm/Kconfig          |   1 +
 hw/arm/rk3588.c         |  33 ++++--
 hw/misc/meson.build     |   2 +
 hw/misc/rockchip_cru.c  | 233 ++++++++++++++++++++++++++++++++++++++++
 include/hw/arm/rk3588.h |   1 +
 6 files changed, 261 insertions(+), 10 deletions(-)
 create mode 100644 hw/misc/rockchip_cru.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 4fc6f8e59d..2905276c7e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1065,6 +1065,7 @@ M: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
 L: qemu-arm@nongnu.org
 S: Maintained
 F: hw/arm/rk3588.c
+F: hw/misc/rockchip_cru.c
 F: hw/timer/rockchip-hptimer.c
 F: include/hw/arm/rk3588.h
 F: include/hw/timer/rockchip-hptimer.h
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index b22d0ce4f6..902c4ba377 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -780,4 +780,5 @@ config RK3588
     select ARM_GIC
     select CPU_CLUSTER
     select DW8250
+    select REGISTER
     select UNIMP
diff --git a/hw/arm/rk3588.c b/hw/arm/rk3588.c
index 3dbd579806..6e7cafea1c 100644
--- a/hw/arm/rk3588.c
+++ b/hw/arm/rk3588.c
@@ -41,6 +41,7 @@
 enum {
     RK3588_DEV_GIC_DIST,
     RK3588_DEV_GIC_REDIST,
+    RK3588_DEV_CRU,
     RK3588_DEV_UART1,
     RK3588_DEV_UART2,
     RK3588_DEV_UART3,
@@ -56,6 +57,7 @@ enum {
 static const MemMapEntry rk3588_memmap[] = {
     [RK3588_DEV_GIC_DIST]   = { 0xfe600000, 0x00010000 },
     [RK3588_DEV_GIC_REDIST] = { 0xfe680000, 0x00100000 },
+    [RK3588_DEV_CRU]        = { 0xfd7c0000, 0x0005c000 },
     [RK3588_DEV_UART1]      = { 0xfeb40000, 0x00010000 },
     [RK3588_DEV_UART2]      = { 0xfeb50000, 0x00010000 },
     [RK3588_DEV_UART3]      = { 0xfeb60000, 0x00010000 },
@@ -89,12 +91,6 @@ static const UnimplementedDeviceConfig rk3588_unimpl_devices[] = {
     RK3588_UNIMPLEMENTED("vccio2-ioc", 0xfd5fb000, 4 * KiB),
     RK3588_UNIMPLEMENTED("vccio6-ioc", 0xfd5fc000, 4 * KiB),
     RK3588_UNIMPLEMENTED("emmc-ioc", 0xfd5fd000, 4 * KiB),
-    RK3588_UNIMPLEMENTED("cru-ns", 0xfd7c0000, 32 * KiB),
-    RK3588_UNIMPLEMENTED("php-ppll-cru", 0xfd7c8000, 32 * KiB),
-    RK3588_UNIMPLEMENTED("pmu1-cru", 0xfd7f0000, 64 * KiB),
-    RK3588_UNIMPLEMENTED("bigcore0-cru", 0xfd810000, 8 * KiB),
-    RK3588_UNIMPLEMENTED("bigcore1-cru", 0xfd812000, 8 * KiB),
-    RK3588_UNIMPLEMENTED("dsu-cru", 0xfd818000, 16 * KiB),
     RK3588_UNIMPLEMENTED("i2c0", 0xfd880000, 64 * KiB),
     RK3588_UNIMPLEMENTED("gpio0", 0xfd8a0000, 64 * KiB),
     RK3588_UNIMPLEMENTED("pwm0", 0xfd8b0000, 64 * KiB),
@@ -206,6 +202,21 @@ static bool rk3588_soc_create_gic(RK3588SoCState *s, Error **errp)
     return true;
 }
 
+static bool rk3588_soc_create_cru(RK3588SoCState *s, Error **errp)
+{
+    SysBusDevice *cru = SYS_BUS_DEVICE(s->cru);
+
+    if (!sysbus_realize(cru, errp)) {
+        return false;
+    }
+
+    memory_region_add_subregion(s->memory,
+        rk3588_memmap[RK3588_DEV_CRU].base,
+        sysbus_mmio_get_region(cru, 0));
+
+    return true;
+}
+
 static bool rk3588_soc_create_uart(RK3588SoCState *s, Error **errp)
 {
     for (unsigned int i = RK3588_FIRST_UART; i < RK3588_NUM_UARTS; i++) {
@@ -279,14 +290,12 @@ static void rk3588_soc_realize(DeviceState *dev, Error **errp)
     }
 
     if (!rk3588_soc_create_gic(s, errp) ||
+        !rk3588_soc_create_cru(s, errp) ||
+        !rk3588_soc_create_uart(s, errp) ||
         !rk3588_soc_create_hptimer(s, errp)) {
         return;
     }
 
-    if (!rk3588_soc_create_uart(s, errp)) {
-        return;
-    }
-
     create_unimplemented_devices(OBJECT(s), s->memory, rk3588_unimpl_devices);
 
     if (!memory_region_init_ram(&s->sram, OBJECT(s), "rk3588.sram",
@@ -329,6 +338,10 @@ static void rk3588_soc_instance_init(Object *obj)
                                   "chardev");
     }
 
+    s->cru = qdev_new("rockchip-cru");
+    object_property_add_child(obj, "cru", OBJECT(s->cru));
+    object_unref(OBJECT(s->cru));
+
     s->hptimer = qdev_new(TYPE_ROCKCHIP_HPTIMER);
     object_property_add_child(obj, "hptimer", OBJECT(s->hptimer));
     object_unref(OBJECT(s->hptimer));
diff --git a/hw/misc/meson.build b/hw/misc/meson.build
index 7a071af82b..374af9331b 100644
--- a/hw/misc/meson.build
+++ b/hw/misc/meson.build
@@ -182,3 +182,5 @@ system_ss.add(when: 'CONFIG_AXIADO_CLK', if_true: files('axiado_clk.c'))
 
 # Qualcomm Hexagon DSP subsystems
 system_ss.add(when: 'CONFIG_QCOM_QDSP6SS_CLK', if_true: files('qcom-qdsp6ss-clk.c'))
+
+system_ss.add(when: 'CONFIG_RK3588', if_true: files('rockchip_cru.c'))
diff --git a/hw/misc/rockchip_cru.c b/hw/misc/rockchip_cru.c
new file mode 100644
index 0000000000..cd2115a514
--- /dev/null
+++ b/hw/misc/rockchip_cru.c
@@ -0,0 +1,233 @@
+/*
+ * Rockchip RK3588 clock registers
+ *
+ * Copyright (C) 2026 Process Mission
+ *
+ * Authors:
+ *    Chao Liu <chao.liu@processmission.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/bitops.h"
+#include "qemu/log.h"
+#include "qemu/module.h"
+#include "hw/core/register.h"
+#include "hw/core/sysbus.h"
+#include "qom/object.h"
+
+#define TYPE_ROCKCHIP_CRU "rockchip-cru"
+OBJECT_DECLARE_SIMPLE_TYPE(RockchipCRUState, ROCKCHIP_CRU)
+
+#define ROCKCHIP_CRU_SIZE 0x5c000
+#define ROCKCHIP_CRU_NUM_PLL_REGS (5 * 3 + 5 * 4)
+#define ROCKCHIP_CRU_NUM_REGS (ROCKCHIP_CRU_NUM_PLL_REGS + 11)
+
+struct RockchipCRUState {
+    SysBusDevice parent_obj;
+    MemoryRegion iomem;
+    RegisterInfo regs_info[ROCKCHIP_CRU_NUM_REGS];
+    uint32_t regs[ROCKCHIP_CRU_NUM_REGS];
+};
+
+#define PLL_POWER_DOWN BIT(13)
+#define PLL_LOCKED BIT(15)
+
+static uint64_t rockchip_cru_masked_write(RegisterInfo *reg, uint64_t value)
+{
+    uint32_t old = *(uint32_t *)reg->data;
+    uint16_t mask = value >> 16;
+
+    return (old & ~mask) | (value & mask);
+}
+
+static RegisterInfo *rockchip_cru_register(RockchipCRUState *s, hwaddr offset)
+{
+    for (unsigned int i = 0; i < ARRAY_SIZE(s->regs_info); i++) {
+        if (s->regs_info[i].access->addr == offset) {
+            return &s->regs_info[i];
+        }
+    }
+    return NULL;
+}
+
+static uint64_t rockchip_cru_pll_lock(RegisterInfo *reg, uint64_t value)
+{
+    RockchipCRUState *s = ROCKCHIP_CRU(reg->opaque);
+    hwaddr base = reg->access->addr - 0x18;
+    uint32_t con0 = *(uint32_t *)rockchip_cru_register(s, base)->data;
+    uint32_t con1 = *(uint32_t *)rockchip_cru_register(s, base + 4)->data;
+    bool powered = !(con1 & PLL_POWER_DOWN);
+    bool configured = (con0 & 0x3ff) >= 64 &&
+                      (con1 & 0x3f) &&
+                      extract32(con1, 6, 3) <= 6;
+
+    /* PLL settling is synchronous after configuration and power-up. */
+    return powered && configured ? PLL_LOCKED : 0;
+}
+
+#define CRU_PLL_CON0(label, base) \
+    { .name = label "_CON0", .addr = base, \
+      .pre_write = rockchip_cru_masked_write }
+
+#define CRU_PLL_CON1(label, base) \
+    { .name = label "_CON1", .addr = base + 4, \
+      .pre_write = rockchip_cru_masked_write }
+
+#define CRU_PLL_CON2(label, base) \
+    { .name = label "_CON2", .addr = base + 8, .ro = 0xffff0000 }
+
+#define CRU_PLL_CON6(label, base) \
+    { .name = label "_CON6", .addr = base + 0x18, .ro = UINT32_MAX, \
+      .post_read = rockchip_cru_pll_lock }
+
+#define CRU_CLOCK(label, offset) \
+    { .name = label, .addr = offset, .pre_write = rockchip_cru_masked_write }
+
+static const RegisterAccessInfo rockchip_cru_pll_regs[] = {
+    CRU_PLL_CON0("B0PLL", 0x50000),
+    CRU_PLL_CON1("B0PLL", 0x50000),
+    CRU_PLL_CON6("B0PLL", 0x50000),
+    CRU_PLL_CON0("B1PLL", 0x52020),
+    CRU_PLL_CON1("B1PLL", 0x52020),
+    CRU_PLL_CON6("B1PLL", 0x52020),
+    CRU_PLL_CON0("LPLL", 0x58040),
+    CRU_PLL_CON1("LPLL", 0x58040),
+    CRU_PLL_CON6("LPLL", 0x58040),
+    CRU_PLL_CON0("V0PLL", 0x00160),
+    CRU_PLL_CON1("V0PLL", 0x00160),
+    CRU_PLL_CON2("V0PLL", 0x00160),
+    CRU_PLL_CON6("V0PLL", 0x00160),
+    CRU_PLL_CON0("AUPLL", 0x00180),
+    CRU_PLL_CON1("AUPLL", 0x00180),
+    CRU_PLL_CON2("AUPLL", 0x00180),
+    CRU_PLL_CON6("AUPLL", 0x00180),
+    CRU_PLL_CON0("CPLL", 0x001a0),
+    CRU_PLL_CON1("CPLL", 0x001a0),
+    CRU_PLL_CON2("CPLL", 0x001a0),
+    CRU_PLL_CON6("CPLL", 0x001a0),
+    CRU_PLL_CON0("GPLL", 0x001c0),
+    CRU_PLL_CON1("GPLL", 0x001c0),
+    CRU_PLL_CON2("GPLL", 0x001c0),
+    CRU_PLL_CON6("GPLL", 0x001c0),
+    CRU_PLL_CON0("NPLL", 0x001e0),
+    CRU_PLL_CON1("NPLL", 0x001e0),
+    CRU_PLL_CON6("NPLL", 0x001e0),
+    CRU_PLL_CON0("PPLL", 0x08200),
+    CRU_PLL_CON1("PPLL", 0x08200),
+    CRU_PLL_CON2("PPLL", 0x08200),
+    CRU_PLL_CON6("PPLL", 0x08200),
+    CRU_PLL_CON0("SPLL", 0x18220),
+    CRU_PLL_CON1("SPLL", 0x18220),
+    CRU_PLL_CON6("SPLL", 0x18220),
+};
+
+static const RegisterAccessInfo rockchip_cru_clock_regs[] = {
+    CRU_CLOCK("MODE_CON0", 0x00280),
+    CRU_CLOCK("SBUS_MODE_CON0", 0x18280),
+    CRU_CLOCK("CLKSEL_CON8", 0x00320),
+    CRU_CLOCK("CLKSEL_CON9", 0x00324),
+    CRU_CLOCK("CLKSEL_CON38", 0x00398),
+    CRU_CLOCK("CLKSEL_CON78", 0x00438),
+    CRU_CLOCK("CLKSEL_CON165", 0x00594),
+    CRU_CLOCK("CLKGATE_CON19", 0x0084c),
+    CRU_CLOCK("BIGCORE0_MODE_CON0", 0x50280),
+    CRU_CLOCK("BIGCORE1_MODE_CON0", 0x52280),
+    CRU_CLOCK("DSU_MODE_CON0", 0x58280),
+};
+
+G_STATIC_ASSERT(ARRAY_SIZE(rockchip_cru_pll_regs) +
+                ARRAY_SIZE(rockchip_cru_clock_regs) == ROCKCHIP_CRU_NUM_REGS);
+
+static uint64_t rockchip_cru_read(void *opaque, hwaddr offset, unsigned size)
+{
+    RockchipCRUState *s = opaque;
+    RegisterInfo *reg = rockchip_cru_register(s, offset);
+
+    if (reg) {
+        return register_read(reg, UINT32_MAX, TYPE_ROCKCHIP_CRU, false);
+    }
+    qemu_log_mask(LOG_UNIMP, "rockchip-cru: unimplemented read at 0x%"
+                  HWADDR_PRIx "\n", offset);
+    return 0;
+}
+
+static void rockchip_cru_write(void *opaque, hwaddr offset, uint64_t value,
+                               unsigned size)
+{
+    RockchipCRUState *s = opaque;
+    RegisterInfo *reg = rockchip_cru_register(s, offset);
+
+    if (reg) {
+        register_write(reg, value, UINT32_MAX, TYPE_ROCKCHIP_CRU, false);
+        return;
+    }
+    qemu_log_mask(LOG_UNIMP, "rockchip-cru: unimplemented write at 0x%"
+                  HWADDR_PRIx " = 0x%" PRIx64 "\n", offset, value);
+}
+
+static const MemoryRegionOps rockchip_cru_ops = {
+    .read = rockchip_cru_read,
+    .write = rockchip_cru_write,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+    .valid.min_access_size = 4,
+    .valid.max_access_size = 4,
+};
+
+static void rockchip_cru_reset(DeviceState *dev)
+{
+    RockchipCRUState *s = ROCKCHIP_CRU(dev);
+
+    for (unsigned int i = 0; i < ARRAY_SIZE(s->regs_info); i++) {
+        register_reset(&s->regs_info[i]);
+    }
+}
+
+static void rockchip_cru_init(Object *obj)
+{
+    RockchipCRUState *s = ROCKCHIP_CRU(obj);
+
+    /* Keep sparse CRU addresses in a compact RegisterInfo array. */
+    for (unsigned int i = 0; i < ARRAY_SIZE(s->regs_info); i++) {
+        const RegisterAccessInfo *access;
+        unsigned int pll_regs = ARRAY_SIZE(rockchip_cru_pll_regs);
+
+        if (i < pll_regs) {
+            access = &rockchip_cru_pll_regs[i];
+        } else {
+            access = &rockchip_cru_clock_regs[i - pll_regs];
+        }
+        s->regs_info[i] = (RegisterInfo) {
+            .data = &s->regs[i],
+            .data_size = sizeof(s->regs[i]),
+            .access = access,
+            .opaque = s,
+        };
+    }
+    memory_region_init_io(&s->iomem, obj, &rockchip_cru_ops, s,
+                          TYPE_ROCKCHIP_CRU, ROCKCHIP_CRU_SIZE);
+    sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
+}
+
+static void rockchip_cru_class_init(ObjectClass *oc, const void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+
+    device_class_set_legacy_reset(dc, rockchip_cru_reset);
+}
+
+static const TypeInfo rockchip_cru_type_info = {
+    .name = TYPE_ROCKCHIP_CRU,
+    .parent = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(RockchipCRUState),
+    .instance_init = rockchip_cru_init,
+    .class_init = rockchip_cru_class_init,
+};
+
+static void rockchip_cru_register_types(void)
+{
+    type_register_static(&rockchip_cru_type_info);
+}
+
+type_init(rockchip_cru_register_types)
diff --git a/include/hw/arm/rk3588.h b/include/hw/arm/rk3588.h
index 61fa616795..18c66b6bae 100644
--- a/include/hw/arm/rk3588.h
+++ b/include/hw/arm/rk3588.h
@@ -52,6 +52,7 @@ struct RK3588SoCState {
     CPUClusterState cluster[RK3588_CLUSTER_COUNT];
     GICv3State gic;
     DW8250State uart[RK3588_NUM_UARTS];
+    DeviceState *cru;
     MemoryRegion *memory;
     MemoryRegion sram;
     DeviceState *hptimer;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC PATCH 12/20] hw/misc: add the RK3588 OTP controller
  2026-11-13  9:47 [RFC PATCH 00/20] hw/arm: Add initial RK3588 and ROCK 5B support Yifan Wang
                   ` (10 preceding siblings ...)
  2026-11-13  9:47 ` [RFC PATCH 11/20] hw/misc: add the RK3588 clock and reset unit Yifan Wang
@ 2026-11-13  9:47 ` Yifan Wang
  2026-11-13  9:47 ` [RFC PATCH 13/20] hw/ssi: add the Rockchip SPI flash controller Yifan Wang
                   ` (7 subsequent siblings)
  19 siblings, 0 replies; 22+ messages in thread
From: Yifan Wang @ 2026-11-13  9:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Yifan Wang, qemu-arm, qemu-block, kvm, Peter Maydell,
	Pierrick Bouvier, Paolo Bonzini, Alistair Francis, Kevin Wolf,
	Hanna Reitz, Kuan-Wei Chiu, Marc-André Lureau, bin.meng,
	tangtao1634, Chao Liu

From: Chao Liu <chao.liu@processmission.com>

Add a model of the RK3588 OTP automatic read interface that U-Boot uses
for CPU identity and device-tree initialization. The OTP array starts
unprogrammed: a read command fills up to four data registers with zero
words and sets a write-one-to-clear completion status bit. Commands
outside the 1024-word array are rejected as guest errors.

Signed-off-by: Chao Liu <chao.liu@processmission.com>
Signed-off-by: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
---
 MAINTAINERS             |   1 +
 hw/arm/rk3588.c         |  23 ++++++-
 hw/misc/meson.build     |   4 +-
 hw/misc/rockchip_otp.c  | 146 ++++++++++++++++++++++++++++++++++++++++
 include/hw/arm/rk3588.h |   1 +
 5 files changed, 173 insertions(+), 2 deletions(-)
 create mode 100644 hw/misc/rockchip_otp.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 2905276c7e..5a4ec869ea 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1066,6 +1066,7 @@ L: qemu-arm@nongnu.org
 S: Maintained
 F: hw/arm/rk3588.c
 F: hw/misc/rockchip_cru.c
+F: hw/misc/rockchip_otp.c
 F: hw/timer/rockchip-hptimer.c
 F: include/hw/arm/rk3588.h
 F: include/hw/timer/rockchip-hptimer.h
diff --git a/hw/arm/rk3588.c b/hw/arm/rk3588.c
index 6e7cafea1c..acd9149933 100644
--- a/hw/arm/rk3588.c
+++ b/hw/arm/rk3588.c
@@ -42,6 +42,7 @@ enum {
     RK3588_DEV_GIC_DIST,
     RK3588_DEV_GIC_REDIST,
     RK3588_DEV_CRU,
+    RK3588_DEV_OTP,
     RK3588_DEV_UART1,
     RK3588_DEV_UART2,
     RK3588_DEV_UART3,
@@ -58,6 +59,7 @@ static const MemMapEntry rk3588_memmap[] = {
     [RK3588_DEV_GIC_DIST]   = { 0xfe600000, 0x00010000 },
     [RK3588_DEV_GIC_REDIST] = { 0xfe680000, 0x00100000 },
     [RK3588_DEV_CRU]        = { 0xfd7c0000, 0x0005c000 },
+    [RK3588_DEV_OTP]        = { 0xfecc0000, 0x00000400 },
     [RK3588_DEV_UART1]      = { 0xfeb40000, 0x00010000 },
     [RK3588_DEV_UART2]      = { 0xfeb50000, 0x00010000 },
     [RK3588_DEV_UART3]      = { 0xfeb60000, 0x00010000 },
@@ -111,7 +113,6 @@ static const UnimplementedDeviceConfig rk3588_unimpl_devices[] = {
     RK3588_UNIMPLEMENTED("gpio4", 0xfec50000, 64 * KiB),
     RK3588_UNIMPLEMENTED("i2c6", 0xfec80000, 64 * KiB),
     RK3588_UNIMPLEMENTED("i2c7", 0xfec90000, 64 * KiB),
-    RK3588_UNIMPLEMENTED("otp-ns", 0xfecc0000, 64 * KiB),
     RK3588_UNIMPLEMENTED("dmac2", 0xfed10000, 64 * KiB),
     { }
 };
@@ -217,6 +218,21 @@ static bool rk3588_soc_create_cru(RK3588SoCState *s, Error **errp)
     return true;
 }
 
+static bool rk3588_soc_create_otp(RK3588SoCState *s, Error **errp)
+{
+    SysBusDevice *otp = SYS_BUS_DEVICE(s->otp);
+
+    if (!sysbus_realize(otp, errp)) {
+        return false;
+    }
+
+    memory_region_add_subregion(s->memory,
+        rk3588_memmap[RK3588_DEV_OTP].base,
+        sysbus_mmio_get_region(otp, 0));
+
+    return true;
+}
+
 static bool rk3588_soc_create_uart(RK3588SoCState *s, Error **errp)
 {
     for (unsigned int i = RK3588_FIRST_UART; i < RK3588_NUM_UARTS; i++) {
@@ -291,6 +307,7 @@ static void rk3588_soc_realize(DeviceState *dev, Error **errp)
 
     if (!rk3588_soc_create_gic(s, errp) ||
         !rk3588_soc_create_cru(s, errp) ||
+        !rk3588_soc_create_otp(s, errp) ||
         !rk3588_soc_create_uart(s, errp) ||
         !rk3588_soc_create_hptimer(s, errp)) {
         return;
@@ -342,6 +359,10 @@ static void rk3588_soc_instance_init(Object *obj)
     object_property_add_child(obj, "cru", OBJECT(s->cru));
     object_unref(OBJECT(s->cru));
 
+    s->otp = qdev_new("rockchip-otp");
+    object_property_add_child(obj, "otp", OBJECT(s->otp));
+    object_unref(OBJECT(s->otp));
+
     s->hptimer = qdev_new(TYPE_ROCKCHIP_HPTIMER);
     object_property_add_child(obj, "hptimer", OBJECT(s->hptimer));
     object_unref(OBJECT(s->hptimer));
diff --git a/hw/misc/meson.build b/hw/misc/meson.build
index 374af9331b..51c09b056e 100644
--- a/hw/misc/meson.build
+++ b/hw/misc/meson.build
@@ -183,4 +183,6 @@ system_ss.add(when: 'CONFIG_AXIADO_CLK', if_true: files('axiado_clk.c'))
 # Qualcomm Hexagon DSP subsystems
 system_ss.add(when: 'CONFIG_QCOM_QDSP6SS_CLK', if_true: files('qcom-qdsp6ss-clk.c'))
 
-system_ss.add(when: 'CONFIG_RK3588', if_true: files('rockchip_cru.c'))
+system_ss.add(when: 'CONFIG_RK3588', if_true: files(
+  'rockchip_cru.c',
+  'rockchip_otp.c'))
diff --git a/hw/misc/rockchip_otp.c b/hw/misc/rockchip_otp.c
new file mode 100644
index 0000000000..81e402fdcc
--- /dev/null
+++ b/hw/misc/rockchip_otp.c
@@ -0,0 +1,146 @@
+/*
+ * Rockchip OTP
+ *
+ * Copyright (C) 2026 Process Mission
+ *
+ * Authors:
+ *    Chao Liu <chao.liu@processmission.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * The automatic read interface exposes a bank of unprogrammed OTP words.
+ * Each read command fills the data registers and sets the read-done status;
+ * the status is cleared by a write-one-to-clear acknowledgement.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/bitops.h"
+#include "qemu/module.h"
+#include "qemu/log.h"
+#include "hw/core/register.h"
+#include "hw/core/sysbus.h"
+#include "qom/object.h"
+
+#define TYPE_ROCKCHIP_OTP "rockchip-otp"
+OBJECT_DECLARE_SIMPLE_TYPE(RockchipOTPState, ROCKCHIP_OTP)
+
+/* Size of the OTP window in the RK3588 address map. */
+#define ROCKCHIP_OTP_SIZE 0x400
+/* Highest byte address described by rockchip_otp_regs_info[]. */
+#define ROCKCHIP_OTP_MAX_REG 0x84
+#define ROCKCHIP_OTP_NUM_REGS \
+    ((ROCKCHIP_OTP_MAX_REG / sizeof(uint32_t)) + 1)
+/* Number of 32-bit words in the OTP array. */
+#define ROCKCHIP_OTP_NUM_WORDS 1024
+
+struct RockchipOTPState {
+    SysBusDevice parent_obj;
+
+    RegisterInfo regs_info[ROCKCHIP_OTP_NUM_REGS];
+    uint32_t regs[ROCKCHIP_OTP_NUM_REGS];
+};
+
+REG32(AUTO_CTRL, 0x04)
+REG32(AUTO_EN, 0x08)
+REG32(DOUT0, 0x20)
+REG32(DOUT1, 0x24)
+REG32(DOUT2, 0x28)
+REG32(DOUT3, 0x2c)
+REG32(INT_STATUS, 0x84)
+
+/* INT_STATUS: a read has finished. */
+#define ROCKCHIP_OTP_INT_STATUS_READ_DONE BIT(1)
+
+static void rockchip_otp_auto_read(RegisterInfo *reg, uint64_t value)
+{
+    RockchipOTPState *s = ROCKCHIP_OTP(reg->opaque);
+
+    if (value & 1) {
+        uint32_t control = s->regs[R_AUTO_CTRL];
+        unsigned int address = control >> 16;
+        unsigned int count = (control >> 8) & 0xff;
+
+        s->regs[R_AUTO_EN] = 0;
+        if (count == 0 || count > 4 ||
+            address + count > ROCKCHIP_OTP_NUM_WORDS) {
+            qemu_log_mask(LOG_GUEST_ERROR,
+                          "rockchip-otp: invalid read command\n");
+            return;
+        }
+        /* Unprogrammed fuse words read as zero. */
+        for (unsigned int i = 0; i < count; i++) {
+            s->regs[R_DOUT0 + i] = 0;
+        }
+        s->regs[R_INT_STATUS] |= ROCKCHIP_OTP_INT_STATUS_READ_DONE;
+    }
+}
+
+static const RegisterAccessInfo rockchip_otp_regs_info[] = {
+    { .name = "AUTO_CTRL", .addr = A_AUTO_CTRL },
+    { .name = "AUTO_EN", .addr = A_AUTO_EN,
+      .ro = ~1U, .post_write = rockchip_otp_auto_read },
+    { .name = "DOUT0", .addr = A_DOUT0, .ro = UINT32_MAX },
+    { .name = "DOUT1", .addr = A_DOUT1, .ro = UINT32_MAX },
+    { .name = "DOUT2", .addr = A_DOUT2, .ro = UINT32_MAX },
+    { .name = "DOUT3", .addr = A_DOUT3, .ro = UINT32_MAX },
+    { .name = "INT_STATUS", .addr = A_INT_STATUS,
+      .ro = ~ROCKCHIP_OTP_INT_STATUS_READ_DONE,
+      .w1c = ROCKCHIP_OTP_INT_STATUS_READ_DONE },
+};
+
+static const MemoryRegionOps rockchip_otp_ops = {
+    .read = register_read_memory,
+    .write = register_write_memory,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+    .valid = {
+        .min_access_size = 4,
+        .max_access_size = 4,
+    },
+    .impl = {
+        .min_access_size = 4,
+        .max_access_size = 4,
+    },
+};
+
+static void rockchip_otp_reset(DeviceState *dev)
+{
+    RockchipOTPState *s = ROCKCHIP_OTP(dev);
+
+    for (int i = 0; i < ARRAY_SIZE(s->regs_info); i++) {
+        register_reset(&s->regs_info[i]);
+    }
+}
+
+static void rockchip_otp_init(Object *obj)
+{
+    RockchipOTPState *s = ROCKCHIP_OTP(obj);
+    RegisterInfoArray *reg_array;
+
+    reg_array = register_init_block32(
+        DEVICE(obj), rockchip_otp_regs_info, ARRAY_SIZE(rockchip_otp_regs_info),
+        s->regs_info, s->regs, &rockchip_otp_ops, false, ROCKCHIP_OTP_SIZE);
+
+    sysbus_init_mmio(SYS_BUS_DEVICE(obj), &reg_array->mem);
+}
+
+static void rockchip_otp_class_init(ObjectClass *oc, const void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+
+    device_class_set_legacy_reset(dc, rockchip_otp_reset);
+}
+
+static const TypeInfo rockchip_otp_type_info = {
+    .name = TYPE_ROCKCHIP_OTP,
+    .parent = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(RockchipOTPState),
+    .instance_init = rockchip_otp_init,
+    .class_init = rockchip_otp_class_init,
+};
+
+static void rockchip_otp_register_types(void)
+{
+    type_register_static(&rockchip_otp_type_info);
+}
+
+type_init(rockchip_otp_register_types)
diff --git a/include/hw/arm/rk3588.h b/include/hw/arm/rk3588.h
index 18c66b6bae..1f854043de 100644
--- a/include/hw/arm/rk3588.h
+++ b/include/hw/arm/rk3588.h
@@ -53,6 +53,7 @@ struct RK3588SoCState {
     GICv3State gic;
     DW8250State uart[RK3588_NUM_UARTS];
     DeviceState *cru;
+    DeviceState *otp;
     MemoryRegion *memory;
     MemoryRegion sram;
     DeviceState *hptimer;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC PATCH 13/20] hw/ssi: add the Rockchip SPI flash controller
  2026-11-13  9:47 [RFC PATCH 00/20] hw/arm: Add initial RK3588 and ROCK 5B support Yifan Wang
                   ` (11 preceding siblings ...)
  2026-11-13  9:47 ` [RFC PATCH 12/20] hw/misc: add the RK3588 OTP controller Yifan Wang
@ 2026-11-13  9:47 ` Yifan Wang
  2026-11-13  9:47 ` [RFC PATCH 14/20] hw/misc: add RK3588 SCMI server Yifan Wang
                   ` (6 subsequent siblings)
  19 siblings, 0 replies; 22+ messages in thread
From: Yifan Wang @ 2026-11-13  9:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Yifan Wang, qemu-arm, qemu-block, kvm, Peter Maydell,
	Pierrick Bouvier, Paolo Bonzini, Alistair Francis, Kevin Wolf,
	Hanna Reitz, Kuan-Wei Chiu, Marc-André Lureau, bin.meng,
	tangtao1634, Chao Liu

From: Chao Liu <chao.liu@processmission.com>

Add a model of the Rockchip SPI flash controller. The ROCK 5B boots
U-Boot proper from the SPI NOR through this controller, so it is needed
for firmware booting.

The model implements command, address and dummy phases, PIO and DMA
data transfers, completion and error interrupts, interrupt masking and
clearing, and controller reset.

Signed-off-by: Chao Liu <chao.liu@processmission.com>
Signed-off-by: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
---
 MAINTAINERS             |   1 +
 hw/arm/Kconfig          |   1 +
 hw/arm/rk3588.c         |  29 ++-
 hw/ssi/Kconfig          |   5 +
 hw/ssi/meson.build      |   1 +
 hw/ssi/rockchip_sfc.c   | 439 ++++++++++++++++++++++++++++++++++++++++
 include/hw/arm/rk3588.h |   1 +
 7 files changed, 475 insertions(+), 2 deletions(-)
 create mode 100644 hw/ssi/rockchip_sfc.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 5a4ec869ea..7fd434ade2 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1067,6 +1067,7 @@ S: Maintained
 F: hw/arm/rk3588.c
 F: hw/misc/rockchip_cru.c
 F: hw/misc/rockchip_otp.c
+F: hw/ssi/rockchip_sfc.c
 F: hw/timer/rockchip-hptimer.c
 F: include/hw/arm/rk3588.h
 F: include/hw/timer/rockchip-hptimer.h
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index 902c4ba377..eaa55eae29 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -781,4 +781,5 @@ config RK3588
     select CPU_CLUSTER
     select DW8250
     select REGISTER
+    select ROCKCHIP_SFC
     select UNIMP
diff --git a/hw/arm/rk3588.c b/hw/arm/rk3588.c
index acd9149933..2319c54c76 100644
--- a/hw/arm/rk3588.c
+++ b/hw/arm/rk3588.c
@@ -29,7 +29,7 @@
 #define RK3588_MPIDR_AFF0_PER_AFF1   (1)
 
 #define RK3588_CNTFRQ                24000000
-
+#define RK3588_SFC_SPI               206
 #define RK3588_GIC_NUM_IRQS          512
 
 /* UART1-UART9 are modeled; UART0 in the PMU power domain is unimplemented. */
@@ -43,6 +43,7 @@ enum {
     RK3588_DEV_GIC_REDIST,
     RK3588_DEV_CRU,
     RK3588_DEV_OTP,
+    RK3588_DEV_SFC,
     RK3588_DEV_UART1,
     RK3588_DEV_UART2,
     RK3588_DEV_UART3,
@@ -60,6 +61,7 @@ static const MemMapEntry rk3588_memmap[] = {
     [RK3588_DEV_GIC_REDIST] = { 0xfe680000, 0x00100000 },
     [RK3588_DEV_CRU]        = { 0xfd7c0000, 0x0005c000 },
     [RK3588_DEV_OTP]        = { 0xfecc0000, 0x00000400 },
+    [RK3588_DEV_SFC]        = { 0xfe2b0000, 0x00004000 },
     [RK3588_DEV_UART1]      = { 0xfeb40000, 0x00010000 },
     [RK3588_DEV_UART2]      = { 0xfeb50000, 0x00010000 },
     [RK3588_DEV_UART3]      = { 0xfeb60000, 0x00010000 },
@@ -96,7 +98,6 @@ static const UnimplementedDeviceConfig rk3588_unimpl_devices[] = {
     RK3588_UNIMPLEMENTED("i2c0", 0xfd880000, 64 * KiB),
     RK3588_UNIMPLEMENTED("gpio0", 0xfd8a0000, 64 * KiB),
     RK3588_UNIMPLEMENTED("pwm0", 0xfd8b0000, 64 * KiB),
-    RK3588_UNIMPLEMENTED("fspi", 0xfe2b0000, 64 * KiB),
     RK3588_UNIMPLEMENTED("sdmmc", 0xfe2c0000, 64 * KiB),
     RK3588_UNIMPLEMENTED("sdio", 0xfe2d0000, 64 * KiB),
     RK3588_UNIMPLEMENTED("emmc", 0xfe2e0000, 64 * KiB),
@@ -233,6 +234,25 @@ static bool rk3588_soc_create_otp(RK3588SoCState *s, Error **errp)
     return true;
 }
 
+static bool rk3588_soc_create_sfc(RK3588SoCState *s, Error **errp)
+{
+    SysBusDevice *sfc = SYS_BUS_DEVICE(s->sfc);
+
+    object_property_set_link(OBJECT(s->sfc), "dma-memory",
+                             OBJECT(s->memory), &error_abort);
+    if (!sysbus_realize(sfc, errp)) {
+        return false;
+    }
+
+    memory_region_add_subregion(s->memory,
+        rk3588_memmap[RK3588_DEV_SFC].base,
+        sysbus_mmio_get_region(sfc, 0));
+    sysbus_connect_irq(sfc, 0,
+                       qdev_get_gpio_in(DEVICE(&s->gic), RK3588_SFC_SPI));
+
+    return true;
+}
+
 static bool rk3588_soc_create_uart(RK3588SoCState *s, Error **errp)
 {
     for (unsigned int i = RK3588_FIRST_UART; i < RK3588_NUM_UARTS; i++) {
@@ -308,6 +328,7 @@ static void rk3588_soc_realize(DeviceState *dev, Error **errp)
     if (!rk3588_soc_create_gic(s, errp) ||
         !rk3588_soc_create_cru(s, errp) ||
         !rk3588_soc_create_otp(s, errp) ||
+        !rk3588_soc_create_sfc(s, errp) ||
         !rk3588_soc_create_uart(s, errp) ||
         !rk3588_soc_create_hptimer(s, errp)) {
         return;
@@ -363,6 +384,10 @@ static void rk3588_soc_instance_init(Object *obj)
     object_property_add_child(obj, "otp", OBJECT(s->otp));
     object_unref(OBJECT(s->otp));
 
+    s->sfc = qdev_new("rockchip-sfc");
+    object_property_add_child(obj, "sfc", OBJECT(s->sfc));
+    object_unref(OBJECT(s->sfc));
+
     s->hptimer = qdev_new(TYPE_ROCKCHIP_HPTIMER);
     object_property_add_child(obj, "hptimer", OBJECT(s->hptimer));
     object_unref(OBJECT(s->hptimer));
diff --git a/hw/ssi/Kconfig b/hw/ssi/Kconfig
index d477d20e9b..5735b422c9 100644
--- a/hw/ssi/Kconfig
+++ b/hw/ssi/Kconfig
@@ -36,3 +36,8 @@ config ALLWINNER_A10_SPI
 config IMX_SPI
     bool
     select SSI
+
+config ROCKCHIP_SFC
+    bool
+    select REGISTER
+    select SSI
diff --git a/hw/ssi/meson.build b/hw/ssi/meson.build
index f334e48e2f..701ae09ed2 100644
--- a/hw/ssi/meson.build
+++ b/hw/ssi/meson.build
@@ -13,3 +13,4 @@ system_ss.add(when: 'CONFIG_IMX_SPI', if_true: files('imx_spi.c'))
 system_ss.add(when: 'CONFIG_IBEX', if_true: files('ibex_spi_host.c'))
 system_ss.add(when: 'CONFIG_BCM2835_SPI', if_true: files('bcm2835_spi.c'))
 system_ss.add(when: 'CONFIG_PNV_SPI', if_true: files('pnv_spi.c'))
+system_ss.add(when: 'CONFIG_ROCKCHIP_SFC', if_true: files('rockchip_sfc.c'))
diff --git a/hw/ssi/rockchip_sfc.c b/hw/ssi/rockchip_sfc.c
new file mode 100644
index 0000000000..7960655e83
--- /dev/null
+++ b/hw/ssi/rockchip_sfc.c
@@ -0,0 +1,439 @@
+/*
+ * Rockchip Serial Flash Controller
+ *
+ * Copyright (c) 2026 Process Mission
+ *
+ * Authors:
+ *    Chao Liu <chao.liu@processmission.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/bitops.h"
+#include "qemu/module.h"
+#include "qemu/units.h"
+#include "qapi/error.h"
+#include "hw/core/irq.h"
+#include "hw/core/qdev-properties.h"
+#include "hw/core/register.h"
+#include "hw/core/sysbus.h"
+#include "hw/ssi/ssi.h"
+#include "qom/object.h"
+
+#define TYPE_ROCKCHIP_SFC "rockchip-sfc"
+OBJECT_DECLARE_SIMPLE_TYPE(RockchipSFCState, ROCKCHIP_SFC)
+
+#define ROCKCHIP_SFC_MMIO_SIZE 0x4000
+#define ROCKCHIP_SFC_NUM_CS 2
+#define ROCKCHIP_SFC_NUM_REGS (0x10c / sizeof(uint32_t))
+
+struct RockchipSFCState {
+    SysBusDevice parent_obj;
+
+    RegisterInfo regs_info[ROCKCHIP_SFC_NUM_REGS];
+    uint32_t regs[ROCKCHIP_SFC_NUM_REGS];
+    MemoryRegion *dma_memory;
+    AddressSpace dma_as;
+    SSIBus *spi;
+    qemu_irq irq;
+    qemu_irq cs_lines[ROCKCHIP_SFC_NUM_CS];
+
+    uint32_t remaining;
+    uint8_t address_bytes;
+    uint8_t dummy_bytes;
+    uint8_t cs;
+    bool write;
+    bool pending;
+    bool started;
+    bool resetting;
+};
+
+REG32(CTRL, 0x000)
+REG32(IMR, 0x004)
+REG32(ICLR, 0x008)
+REG32(FTLR, 0x00c)
+REG32(RCVR, 0x010)
+REG32(AX, 0x014)
+REG32(ABIT, 0x018)
+REG32(ISR, 0x01c)
+REG32(FSR, 0x020)
+REG32(SR, 0x024)
+REG32(RISR, 0x028)
+REG32(VER, 0x02c)
+REG32(DLL_CTRL0, 0x03c)
+REG32(DMA_TRIGGER, 0x080)
+REG32(DMA_ADDR, 0x084)
+REG32(LEN_CTRL, 0x088)
+REG32(LEN_EXT, 0x08c)
+REG32(CMD, 0x100)
+REG32(ADDR, 0x104)
+REG32(DATA, 0x108)
+
+#define SFC_INT_FINISH   BIT(4)
+#define SFC_INT_BUS_ERR  BIT(5)
+#define SFC_INT_NSPI_ERR BIT(6)
+#define SFC_INT_DMA      BIT(7)
+#define SFC_MAX_LENGTH  (32 * MiB)
+#define SFC_LEN_CTRL_TRB_SEL BIT(0)
+
+static void rockchip_sfc_update_irq(RockchipSFCState *s)
+{
+    qemu_set_irq(s->irq, (s->regs[R_RISR] & ~s->regs[R_IMR]) != 0);
+}
+
+static void rockchip_sfc_end(RockchipSFCState *s)
+{
+    if (s->started) {
+        qemu_irq_raise(s->cs_lines[s->cs]);
+    }
+    s->pending = false;
+    s->started = false;
+    s->remaining = 0;
+}
+
+static void rockchip_sfc_complete(RockchipSFCState *s, uint32_t status)
+{
+    rockchip_sfc_end(s);
+    s->regs[R_RISR] |= status;
+    rockchip_sfc_update_irq(s);
+}
+
+static void rockchip_sfc_begin(RockchipSFCState *s)
+{
+    if (!s->pending || s->started) {
+        return;
+    }
+
+    qemu_irq_lower(s->cs_lines[s->cs]);
+    s->started = true;
+    ssi_transfer(s->spi, s->regs[R_CMD] & 0xff);
+    for (int i = s->address_bytes - 1; i >= 0; i--) {
+        ssi_transfer(s->spi, (s->regs[R_ADDR] >> (8 * i)) & 0xff);
+    }
+    for (unsigned int i = 0; i < s->dummy_bytes; i++) {
+        ssi_transfer(s->spi, 0);
+    }
+    if (!s->remaining) {
+        rockchip_sfc_complete(s, SFC_INT_FINISH);
+    }
+}
+
+static void rockchip_sfc_command(RockchipSFCState *s, uint32_t value)
+{
+    unsigned int address_mode = (value >> 14) & 3;
+    unsigned int dummy_cycles = (value >> 8) & 0xf;
+    unsigned int address_width = 1 << ((s->regs[R_CTRL] >> 10) & 3);
+    uint32_t len;
+
+    if (s->regs[R_LEN_CTRL] & SFC_LEN_CTRL_TRB_SEL) {
+        len = s->regs[R_LEN_EXT];
+    } else {
+        /* Normal mode: transfer bytes are in CMD[29:16]. */
+        len = (value >> 16) & 0x3fff;
+    }
+
+    rockchip_sfc_end(s);
+    s->cs = value >> 30;
+    if (s->cs >= ROCKCHIP_SFC_NUM_CS || len > SFC_MAX_LENGTH) {
+        rockchip_sfc_complete(s, SFC_INT_NSPI_ERR);
+        return;
+    }
+
+    switch (address_mode) {
+    case 1:
+        s->address_bytes = 3;
+        break;
+    case 2:
+        s->address_bytes = 4;
+        break;
+    case 3:
+        if ((s->regs[R_ABIT] & 7) != 7) {
+            rockchip_sfc_complete(s, SFC_INT_NSPI_ERR);
+            return;
+        }
+        s->address_bytes = ((s->regs[R_ABIT] & 31) + 1) / 8;
+        break;
+    default:
+        s->address_bytes = 0;
+        break;
+    }
+    s->dummy_bytes = DIV_ROUND_UP(dummy_cycles * address_width, 8);
+    s->write = (value >> 12) & 1;
+    s->remaining = len;
+    s->pending = true;
+    if (!s->address_bytes) {
+        rockchip_sfc_begin(s);
+    }
+}
+
+static uint32_t rockchip_sfc_read_data(RockchipSFCState *s)
+{
+    uint32_t value = 0;
+    unsigned int count;
+
+    if (!s->started || s->write) {
+        return 0;
+    }
+    count = MIN(4, s->remaining);
+    for (unsigned int i = 0; i < count; i++) {
+        value |= (uint32_t)ssi_transfer(s->spi, 0) << (i * 8);
+    }
+    s->remaining -= count;
+    if (!s->remaining) {
+        rockchip_sfc_complete(s, SFC_INT_FINISH);
+    }
+    return value;
+}
+
+static void rockchip_sfc_write_data(RockchipSFCState *s, uint32_t value)
+{
+    unsigned int count;
+
+    if (!s->started || !s->write) {
+        return;
+    }
+    count = MIN(4, s->remaining);
+    for (unsigned int i = 0; i < count; i++) {
+        ssi_transfer(s->spi, (value >> (i * 8)) & 0xff);
+    }
+    s->remaining -= count;
+    if (!s->remaining) {
+        rockchip_sfc_complete(s, SFC_INT_FINISH);
+    }
+}
+
+static void rockchip_sfc_dma(RockchipSFCState *s)
+{
+    uint8_t buffer[256];
+    hwaddr addr = s->regs[R_DMA_ADDR];
+    MemTxAttrs attrs = { .memory = true };
+
+    if (!s->started) {
+        rockchip_sfc_complete(s, SFC_INT_BUS_ERR);
+        return;
+    }
+
+    while (s->remaining) {
+        unsigned int count = MIN(sizeof(buffer), s->remaining);
+        MemTxResult result;
+
+        if (s->write) {
+            result = address_space_read(&s->dma_as, addr, attrs,
+                                        buffer, count);
+            if (result == MEMTX_OK) {
+                for (unsigned int i = 0; i < count; i++) {
+                    ssi_transfer(s->spi, buffer[i]);
+                }
+            }
+        } else {
+            for (unsigned int i = 0; i < count; i++) {
+                buffer[i] = ssi_transfer(s->spi, 0);
+            }
+            result = address_space_write(&s->dma_as, addr, attrs,
+                                         buffer, count);
+        }
+        if (result != MEMTX_OK) {
+            rockchip_sfc_complete(s, SFC_INT_BUS_ERR);
+            return;
+        }
+        s->remaining -= count;
+        addr += count;
+    }
+    rockchip_sfc_complete(s, SFC_INT_DMA | SFC_INT_FINISH);
+}
+
+static void rockchip_sfc_reset(DeviceState *dev)
+{
+    RockchipSFCState *s = ROCKCHIP_SFC(dev);
+
+    rockchip_sfc_end(s);
+    for (unsigned int i = 0; i < ROCKCHIP_SFC_NUM_CS; i++) {
+        qemu_irq_raise(s->cs_lines[i]);
+    }
+    s->resetting = true;
+    for (unsigned int i = 0; i < ARRAY_SIZE(s->regs_info); i++) {
+        register_reset(&s->regs_info[i]);
+    }
+    s->resetting = false;
+    s->cs = 0;
+    s->address_bytes = 0;
+    s->dummy_bytes = 0;
+    s->write = false;
+    rockchip_sfc_update_irq(s);
+}
+
+static uint64_t rockchip_sfc_status_read(RegisterInfo *reg, uint64_t value)
+{
+    RockchipSFCState *s = ROCKCHIP_SFC(reg->opaque);
+
+    switch (reg->access->addr) {
+    case A_ISR:
+        return s->regs[R_RISR] & ~s->regs[R_IMR];
+    case A_FSR:
+        if (s->started && !s->write && s->remaining) {
+            return (31 << 8) | BIT(1) |
+                   (MIN(DIV_ROUND_UP(s->remaining, 4), 31) << 16);
+        }
+        return (31 << 8) | BIT(1) | BIT(2);
+    case A_SR:
+        return s->pending ? 1 : 0;
+    case A_DATA:
+        return rockchip_sfc_read_data(s);
+    default:
+        g_assert_not_reached();
+    }
+}
+
+static void rockchip_sfc_register_write(RegisterInfo *reg, uint64_t value)
+{
+    RockchipSFCState *s = ROCKCHIP_SFC(reg->opaque);
+
+    if (s->resetting) {
+        return;
+    }
+
+    switch (reg->access->addr) {
+    case A_IMR:
+        rockchip_sfc_update_irq(s);
+        break;
+    case A_ICLR:
+        s->regs[R_RISR] &= ~value;
+        s->regs[R_ICLR] = 0;
+        rockchip_sfc_update_irq(s);
+        break;
+    case A_RCVR:
+        if (value & 1) {
+            rockchip_sfc_end(s);
+            s->regs[R_RISR] = 0;
+            rockchip_sfc_update_irq(s);
+        }
+        s->regs[R_RCVR] = 0;
+        break;
+    case A_DMA_TRIGGER:
+        if (value & 1) {
+            rockchip_sfc_dma(s);
+        }
+        s->regs[R_DMA_TRIGGER] = 0;
+        break;
+    case A_CMD:
+        rockchip_sfc_command(s, value);
+        break;
+    case A_ADDR:
+        rockchip_sfc_begin(s);
+        break;
+    case A_DATA:
+        rockchip_sfc_write_data(s, value);
+        break;
+    default:
+        g_assert_not_reached();
+    }
+}
+
+static const RegisterAccessInfo rockchip_sfc_regs[] = {
+    { .name = "CTRL", .addr = A_CTRL },
+    { .name = "IMR", .addr = A_IMR, .reset = UINT32_MAX,
+      .post_write = rockchip_sfc_register_write },
+    { .name = "ICLR", .addr = A_ICLR,
+      .post_write = rockchip_sfc_register_write },
+    { .name = "FTLR", .addr = A_FTLR },
+    { .name = "RCVR", .addr = A_RCVR,
+      .post_write = rockchip_sfc_register_write },
+    { .name = "AX", .addr = A_AX },
+    { .name = "ABIT", .addr = A_ABIT },
+    { .name = "ISR", .addr = A_ISR, .ro = UINT32_MAX,
+      .post_read = rockchip_sfc_status_read },
+    { .name = "FSR", .addr = A_FSR, .ro = UINT32_MAX,
+      .post_read = rockchip_sfc_status_read },
+    { .name = "SR", .addr = A_SR, .ro = UINT32_MAX,
+      .post_read = rockchip_sfc_status_read },
+    { .name = "RISR", .addr = A_RISR, .ro = UINT32_MAX },
+    { .name = "VER", .addr = A_VER, .ro = UINT32_MAX, .reset = 4 },
+    { .name = "DLL_CTRL0", .addr = A_DLL_CTRL0 },
+    { .name = "DMA_TRIGGER", .addr = A_DMA_TRIGGER,
+      .post_write = rockchip_sfc_register_write },
+    { .name = "DMA_ADDR", .addr = A_DMA_ADDR },
+    { .name = "LEN_CTRL", .addr = A_LEN_CTRL },
+    { .name = "LEN_EXT", .addr = A_LEN_EXT },
+    { .name = "CMD", .addr = A_CMD,
+      .post_write = rockchip_sfc_register_write },
+    { .name = "ADDR", .addr = A_ADDR,
+      .post_write = rockchip_sfc_register_write },
+    { .name = "DATA", .addr = A_DATA,
+      .post_read = rockchip_sfc_status_read,
+      .post_write = rockchip_sfc_register_write },
+};
+
+static const MemoryRegionOps rockchip_sfc_ops = {
+    .read = register_read_memory,
+    .write = register_write_memory,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+    .valid.min_access_size = 4,
+    .valid.max_access_size = 4,
+};
+
+static void rockchip_sfc_realize(DeviceState *dev, Error **errp)
+{
+    RockchipSFCState *s = ROCKCHIP_SFC(dev);
+
+    if (!s->dma_memory) {
+        error_setg(errp, "rockchip-sfc: dma-memory link is required");
+        return;
+    }
+    address_space_init(&s->dma_as, s->dma_memory, TYPE_ROCKCHIP_SFC);
+}
+
+static void rockchip_sfc_unrealize(DeviceState *dev)
+{
+    RockchipSFCState *s = ROCKCHIP_SFC(dev);
+
+    address_space_destroy(&s->dma_as);
+}
+
+static void rockchip_sfc_init(Object *obj)
+{
+    RockchipSFCState *s = ROCKCHIP_SFC(obj);
+    SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
+    RegisterInfoArray *reg_array;
+
+    s->spi = ssi_create_bus(DEVICE(obj), "spi");
+    qdev_init_gpio_out_named(DEVICE(obj), s->cs_lines, "cs",
+                             ROCKCHIP_SFC_NUM_CS);
+    sysbus_init_irq(sbd, &s->irq);
+    reg_array = register_init_block32(DEVICE(obj), rockchip_sfc_regs,
+                                     ARRAY_SIZE(rockchip_sfc_regs),
+                                     s->regs_info, s->regs, &rockchip_sfc_ops,
+                                     false, ROCKCHIP_SFC_MMIO_SIZE);
+    sysbus_init_mmio(sbd, &reg_array->mem);
+}
+
+static const Property rockchip_sfc_properties[] = {
+    DEFINE_PROP_LINK("dma-memory", RockchipSFCState, dma_memory,
+                     TYPE_MEMORY_REGION, MemoryRegion *),
+};
+
+static void rockchip_sfc_class_init(ObjectClass *oc, const void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+
+    dc->realize = rockchip_sfc_realize;
+    dc->unrealize = rockchip_sfc_unrealize;
+    device_class_set_props(dc, rockchip_sfc_properties);
+    device_class_set_legacy_reset(dc, rockchip_sfc_reset);
+}
+
+static const TypeInfo rockchip_sfc_info = {
+    .name = TYPE_ROCKCHIP_SFC,
+    .parent = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(RockchipSFCState),
+    .instance_init = rockchip_sfc_init,
+    .class_init = rockchip_sfc_class_init,
+};
+
+static void rockchip_sfc_register_types(void)
+{
+    type_register_static(&rockchip_sfc_info);
+}
+
+type_init(rockchip_sfc_register_types)
diff --git a/include/hw/arm/rk3588.h b/include/hw/arm/rk3588.h
index 1f854043de..1304c11598 100644
--- a/include/hw/arm/rk3588.h
+++ b/include/hw/arm/rk3588.h
@@ -54,6 +54,7 @@ struct RK3588SoCState {
     DW8250State uart[RK3588_NUM_UARTS];
     DeviceState *cru;
     DeviceState *otp;
+    DeviceState *sfc;
     MemoryRegion *memory;
     MemoryRegion sram;
     DeviceState *hptimer;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC PATCH 14/20] hw/misc: add RK3588 SCMI server
  2026-11-13  9:47 [RFC PATCH 00/20] hw/arm: Add initial RK3588 and ROCK 5B support Yifan Wang
                   ` (12 preceding siblings ...)
  2026-11-13  9:47 ` [RFC PATCH 13/20] hw/ssi: add the Rockchip SPI flash controller Yifan Wang
@ 2026-11-13  9:47 ` Yifan Wang
  2026-11-13  9:47 ` [RFC PATCH 15/20] hw/arm/rk3588: wire up the " Yifan Wang
                   ` (5 subsequent siblings)
  19 siblings, 0 replies; 22+ messages in thread
From: Yifan Wang @ 2026-11-13  9:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Yifan Wang, qemu-arm, qemu-block, kvm, Peter Maydell,
	Pierrick Bouvier, Paolo Bonzini, Alistair Francis, Kevin Wolf,
	Hanna Reitz, Kuan-Wei Chiu, Marc-André Lureau, bin.meng,
	tangtao1634, Chao Liu

From: Chao Liu <chao.liu@processmission.com>

RK3588 firmware exposes SCMI through the SMC transport.  Add a minimal
server implementing the Base and Clock protocols and the shared memory
area described by the upstream RK3588 device tree, so a guest can
exercise the standard arm,scmi-smc path without running a complete
BL31 image.

Provide the CPUL, DSU, CPUB01 and CPUB23 clocks using the nominal
PVTPLL rates accepted by TF-A v2.12. Clock rates and enable state are
maintained independently of the CRU registers.

Signed-off-by: Chao Liu <chao.liu@processmission.com>
Signed-off-by: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
---
 MAINTAINERS                    |   2 +
 hw/misc/meson.build            |   1 +
 hw/misc/rk3588-scmci.c         | 589 +++++++++++++++++++++++++++++++++
 include/hw/misc/rk3588-scmci.h |  25 ++
 4 files changed, 617 insertions(+)
 create mode 100644 hw/misc/rk3588-scmci.c
 create mode 100644 include/hw/misc/rk3588-scmci.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 7fd434ade2..c3d3388975 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1067,9 +1067,11 @@ S: Maintained
 F: hw/arm/rk3588.c
 F: hw/misc/rockchip_cru.c
 F: hw/misc/rockchip_otp.c
+F: hw/misc/rk3588-scmci.c
 F: hw/ssi/rockchip_sfc.c
 F: hw/timer/rockchip-hptimer.c
 F: include/hw/arm/rk3588.h
+F: include/hw/misc/rk3588-scmci.h
 F: include/hw/timer/rockchip-hptimer.h
 
 SABRELITE / i.MX6
diff --git a/hw/misc/meson.build b/hw/misc/meson.build
index 51c09b056e..8f13f5da77 100644
--- a/hw/misc/meson.build
+++ b/hw/misc/meson.build
@@ -16,6 +16,7 @@ system_ss.add(when: 'CONFIG_PL310', if_true: files('arm_l2x0.c'))
 system_ss.add(when: 'CONFIG_INTEGRATOR_DEBUG', if_true: files('arm_integrator_debug.c'))
 system_ss.add(when: 'CONFIG_A9SCU', if_true: files('a9scu.c'))
 system_ss.add(when: 'CONFIG_ARM11SCU', if_true: files('arm11scu.c'))
+system_ss.add(when: 'CONFIG_RK3588', if_true: files('rk3588-scmci.c'))
 
 system_ss.add(when: 'CONFIG_ARM_V7M', if_true: files('armv7m_ras.c'))
 
diff --git a/hw/misc/rk3588-scmci.c b/hw/misc/rk3588-scmci.c
new file mode 100644
index 0000000000..956919e823
--- /dev/null
+++ b/hw/misc/rk3588-scmci.c
@@ -0,0 +1,589 @@
+/*
+ * Rockchip RK3588 SCMI server
+ *
+ * The RK3588 firmware exposes SCMI through the SMC transport rather
+ * than through a mailbox.  This model provides the shared memory area
+ * and a minimal server implementing the Base and Clock protocols. Clock rates
+ * and enable state are maintained independently of CRU registers. It is
+ * intended to let a guest exercise the standard arm,scmi-smc path without
+ * running a complete BL31 image.
+ *
+ * Copyright (C) 2026 Process Mission
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qemu/bswap.h"
+#include "hw/arm/arm-smc.h"
+#include "hw/core/qdev-properties.h"
+#include "hw/core/resettable.h"
+#include "hw/core/sysbus.h"
+#include "hw/misc/rk3588-scmci.h"
+#include "system/memory.h"
+
+#define RK3588_SCMI_SHORT_NAME_SIZE     16
+#define RK3588_SCMI_MAX_STR_SIZE        64
+
+/*
+ * Use the U-Boot v2025.01 SPL boot rate, with DSU using its default
+ * LPLL source and divide-by-one setting.
+ */
+#define RK3588_SCMI_BOOT_RATE           816000000ULL
+
+#define RK3588_SCMI_CPUL                0
+#define RK3588_SCMI_DSU                 1
+#define RK3588_SCMI_CPUB01              2
+#define RK3588_SCMI_CPUB23              3
+
+/*
+ * TF-A v2.12 PVTPLL nominal rates, sorted ascending for enumeration and
+ * selection. These differ from the firmware's advertised rate lists.
+ */
+static const uint64_t rk3588_cpul_rates[] = {
+    408000000, 600000000, 816000000, 1008000000, 1200000000,
+    1416000000, 1608000000, 1704000000, 1800000000,
+};
+
+static const uint64_t rk3588_cpub_rates[] = {
+    408000000, 600000000, 816000000, 1008000000, 1200000000,
+    1416000000, 1608000000, 1800000000, 2016000000, 2112000000,
+    2208000000, 2256000000, 2304000000, 2352000000, 2400000000,
+};
+
+static const struct {
+    const char *name;
+    const uint64_t *rates;
+    size_t num_rates;
+} rk3588_scmi_clocks[] = {
+    [RK3588_SCMI_CPUL] = {
+        "scmi_clk_cpul", rk3588_cpul_rates, ARRAY_SIZE(rk3588_cpul_rates),
+    },
+    [RK3588_SCMI_DSU] = {
+        "scmi_clk_dsu", rk3588_cpul_rates, ARRAY_SIZE(rk3588_cpul_rates),
+    },
+    [RK3588_SCMI_CPUB01] = {
+        "scmi_clk_cpub01", rk3588_cpub_rates, ARRAY_SIZE(rk3588_cpub_rates),
+    },
+    [RK3588_SCMI_CPUB23] = {
+        "scmi_clk_cpub23", rk3588_cpub_rates, ARRAY_SIZE(rk3588_cpub_rates),
+    },
+};
+
+/* SCMI shared memory layout, see Linux struct scmi_shared_mem. */
+#define SCMI_SHMEM_RESERVED             0x00
+#define SCMI_SHMEM_CHANNEL_STATUS       0x04
+#define SCMI_SHMEM_RESERVED1            0x08
+#define SCMI_SHMEM_FLAGS                0x10
+#define SCMI_SHMEM_LENGTH               0x14
+#define SCMI_SHMEM_MSG_HEADER           0x18
+#define SCMI_SHMEM_MSG_PAYLOAD          0x1c
+
+/* Space for response data after the 32-bit SCMI status code. */
+#define RK3588_SCMI_RESP_MAX \
+    (RK3588_SCMI_SHMEM_SIZE - SCMI_SHMEM_MSG_PAYLOAD - sizeof(uint32_t))
+
+#define SCMI_SHMEM_CHANNEL_FREE         BIT(0)
+#define SCMI_SHMEM_CHANNEL_ERROR        BIT(1)
+
+#define SCMI_MSG_ID(hdr)                ((hdr) & 0xff)
+#define SCMI_MSG_PROTOCOL(hdr)          (((hdr) >> 10) & 0xff)
+
+#define SCMI_PROTOCOL_BASE              0x10
+#define SCMI_PROTOCOL_CLOCK             0x14
+
+#define SCMI_SUCCESS                    0
+#define SCMI_ERR_SUPPORT                (-1)
+#define SCMI_ERR_PARAMS                 (-2)
+#define SCMI_ERR_NOT_FOUND              (-4)
+#define SCMI_ERR_OUT_OF_RANGE           (-5)
+#define SCMI_ERR_PROTOCOL               (-10)
+
+#define SCMI_BASE_PROTOCOL_VERSION      0x00020001
+#define SCMI_CLOCK_PROTOCOL_VERSION     0x00020000
+
+#define SCMI_CLOCK_EXTENDED_NAMES        BIT(29)
+#define SCMI_CLOCK_ENABLED               BIT(0)
+
+#define SCMI_CLOCK_SET_ASYNC            BIT(0)
+#define SCMI_CLOCK_SET_IGNORE_RESP      BIT(1)
+#define SCMI_CLOCK_SET_ROUND_UP         BIT(2)
+#define SCMI_CLOCK_SET_ROUND_AUTO       BIT(3)
+
+/* Each rate list is preceded by a 32-bit count/flags field. */
+G_STATIC_ASSERT(sizeof(rk3588_cpul_rates) + sizeof(uint32_t) <=
+                RK3588_SCMI_RESP_MAX);
+G_STATIC_ASSERT(sizeof(rk3588_cpub_rates) + sizeof(uint32_t) <=
+                RK3588_SCMI_RESP_MAX);
+
+struct RK3588SCMIState {
+    /*< private >*/
+    SysBusDevice parent_obj;
+
+    /*< public >*/
+    MemoryRegion shmem;
+    uint8_t *shmem_ptr;
+    uint64_t clock_rate[ARRAY_SIZE(rk3588_scmi_clocks)];
+    uint32_t clock_config[ARRAY_SIZE(rk3588_scmi_clocks)];
+    bool smc_registered;
+};
+
+static uint32_t rk3588_scmi_rd32(RK3588SCMIState *s, hwaddr offset)
+{
+    return ldl_le_p(s->shmem_ptr + offset);
+}
+
+static void rk3588_scmi_wr32(RK3588SCMIState *s, hwaddr offset, uint32_t value)
+{
+    stl_le_p(s->shmem_ptr + offset, value);
+}
+
+static void rk3588_scmi_put_name(uint8_t *dst, const char *name)
+{
+    size_t len = strlen(name);
+
+    memset(dst, 0, RK3588_SCMI_SHORT_NAME_SIZE);
+    memcpy(dst, name, MIN(len, RK3588_SCMI_SHORT_NAME_SIZE));
+}
+
+static int32_t rk3588_scmi_base_protocol(RK3588SCMIState *s, uint8_t msg_id,
+                                         const uint8_t *req, size_t req_len,
+                                         uint8_t *resp, size_t *resp_len)
+{
+    uint32_t value;
+
+    switch (msg_id) {
+    case 0x0: /* PROTOCOL_VERSION */
+        stl_le_p(resp, SCMI_BASE_PROTOCOL_VERSION);
+        *resp_len = 4;
+        return SCMI_SUCCESS;
+
+    case 0x1: /* PROTOCOL_ATTRIBUTES */
+        resp[0] = 1; /* one implemented protocol: Clock */
+        resp[1] = 1; /* one agent */
+        resp[2] = 0;
+        resp[3] = 0;
+        *resp_len = 4;
+        return SCMI_SUCCESS;
+
+    case 0x2: /* PROTOCOL_MESSAGE_ATTRIBUTES */
+        if (req_len < 4) {
+            return SCMI_ERR_PROTOCOL;
+        }
+        value = ldl_le_p(req);
+        if (value > 0x7) {
+            return SCMI_ERR_NOT_FOUND;
+        }
+        stl_le_p(resp, 0);
+        *resp_len = 4;
+        return SCMI_SUCCESS;
+
+    case 0x3: /* BASE_DISCOVER_VENDOR */
+    case 0x4: /* BASE_DISCOVER_SUB_VENDOR */
+        rk3588_scmi_put_name(resp, "QEMU");
+        *resp_len = RK3588_SCMI_SHORT_NAME_SIZE;
+        return SCMI_SUCCESS;
+
+    case 0x5: /* BASE_DISCOVER_IMPLEMENT_VERSION */
+        stl_le_p(resp, 1);
+        *resp_len = 4;
+        return SCMI_SUCCESS;
+
+    case 0x6: /* BASE_DISCOVER_LIST_PROTOCOLS */
+        if (req_len < 4) {
+            return SCMI_ERR_PROTOCOL;
+        }
+        value = ldl_le_p(req);
+        if (value == 0) {
+            stl_le_p(resp, 1);
+            resp[4] = SCMI_PROTOCOL_CLOCK;
+            resp[5] = 0;
+            resp[6] = 0;
+            resp[7] = 0;
+            *resp_len = 8;
+        } else {
+            stl_le_p(resp, 0);
+            *resp_len = 4;
+        }
+        return SCMI_SUCCESS;
+
+    case 0x7: /* BASE_DISCOVER_AGENT */
+        if (req_len < 4) {
+            return SCMI_ERR_PROTOCOL;
+        }
+        value = ldl_le_p(req);
+        if (value == UINT32_MAX) {
+            value = 1; /* The single agent using this channel. */
+        }
+        if (value > 1) {
+            return SCMI_ERR_NOT_FOUND;
+        }
+        stl_le_p(resp, value);
+        rk3588_scmi_put_name(resp + 4, value ? "QEMU" : "platform");
+        *resp_len = 4 + RK3588_SCMI_SHORT_NAME_SIZE;
+        return SCMI_SUCCESS;
+
+    default:
+        return SCMI_ERR_SUPPORT;
+    }
+}
+
+/*
+ * Caller validates id. ROUND_AUTO takes precedence; ties select the lower rate.
+ */
+static int32_t rk3588_scmi_select_rate(uint32_t id, uint32_t flags,
+                                       uint64_t requested, uint64_t *selected)
+{
+    const uint64_t *rates = rk3588_scmi_clocks[id].rates;
+    size_t count = rk3588_scmi_clocks[id].num_rates;
+    size_t i;
+
+    for (i = 0; i < count && rates[i] < requested; i++) {
+        /* Find the first rate at least as high as requested. */
+    }
+    if (i < count && rates[i] == requested) {
+        *selected = rates[i];
+    } else if (flags & SCMI_CLOCK_SET_ROUND_AUTO) {
+        if (i == 0) {
+            *selected = rates[0];
+        } else if (i == count ||
+                   requested - rates[i - 1] <= rates[i] - requested) {
+            *selected = rates[i - 1];
+        } else {
+            *selected = rates[i];
+        }
+    } else if (flags & SCMI_CLOCK_SET_ROUND_UP) {
+        if (i == count) {
+            return SCMI_ERR_OUT_OF_RANGE;
+        }
+        *selected = rates[i];
+    } else {
+        if (i == 0) {
+            return SCMI_ERR_OUT_OF_RANGE;
+        }
+        *selected = rates[i - 1];
+    }
+    return SCMI_SUCCESS;
+}
+
+static int32_t rk3588_scmi_clock_protocol(RK3588SCMIState *s, uint8_t msg_id,
+                                          const uint8_t *req, size_t req_len,
+                                          uint8_t *resp, size_t *resp_len)
+{
+    uint32_t id;
+
+    switch (msg_id) {
+    case 0x0: /* PROTOCOL_VERSION */
+        stl_le_p(resp, SCMI_CLOCK_PROTOCOL_VERSION);
+        *resp_len = 4;
+        return SCMI_SUCCESS;
+
+    case 0x1: /* PROTOCOL_ATTRIBUTES */
+        stw_le_p(resp, ARRAY_SIZE(rk3588_scmi_clocks));
+        resp[2] = 0;
+        resp[3] = 0;
+        *resp_len = 4;
+        return SCMI_SUCCESS;
+
+    case 0x2: /* PROTOCOL_MESSAGE_ATTRIBUTES */
+        if (req_len < 4) {
+            return SCMI_ERR_PROTOCOL;
+        }
+        id = ldl_le_p(req);
+        if (id > 0x8 && id != 0xb) {
+            return SCMI_ERR_NOT_FOUND;
+        }
+        stl_le_p(resp, 0);
+        *resp_len = 4;
+        return SCMI_SUCCESS;
+
+    case 0x3: /* CLOCK_ATTRIBUTES */
+        if (req_len < 4) {
+            return SCMI_ERR_PROTOCOL;
+        }
+        id = ldl_le_p(req);
+        if (id >= ARRAY_SIZE(rk3588_scmi_clocks)) {
+            return SCMI_ERR_NOT_FOUND;
+        }
+        stl_le_p(resp, SCMI_CLOCK_EXTENDED_NAMES |
+                       (s->clock_config[id] & SCMI_CLOCK_ENABLED));
+        rk3588_scmi_put_name(resp + 4, rk3588_scmi_clocks[id].name);
+        stl_le_p(resp + 4 + RK3588_SCMI_SHORT_NAME_SIZE, 0);
+        *resp_len = 4 + RK3588_SCMI_SHORT_NAME_SIZE + 4;
+        return SCMI_SUCCESS;
+
+    case 0x4: { /* CLOCK_DESCRIBE_RATES */
+        uint32_t rate_index;
+        size_t count;
+
+        if (req_len < 8) {
+            return SCMI_ERR_PROTOCOL;
+        }
+        id = ldl_le_p(req);
+        rate_index = ldl_le_p(req + 4);
+        if (id >= ARRAY_SIZE(rk3588_scmi_clocks)) {
+            return SCMI_ERR_NOT_FOUND;
+        }
+        count = rk3588_scmi_clocks[id].num_rates;
+        if (rate_index >= count) {
+            return SCMI_ERR_OUT_OF_RANGE;
+        }
+        count -= rate_index;
+        stl_le_p(resp, count);
+        for (size_t i = 0; i < count; i++) {
+            stq_le_p(resp + 4 + i * 8,
+                     rk3588_scmi_clocks[id].rates[rate_index + i]);
+        }
+        *resp_len = 4 + count * 8;
+        return SCMI_SUCCESS;
+    }
+
+    case 0x5: { /* CLOCK_RATE_SET */
+        uint32_t flags;
+        uint64_t rate;
+        int32_t status;
+
+        if (req_len < 16) {
+            return SCMI_ERR_PROTOCOL;
+        }
+        flags = ldl_le_p(req);
+        id = ldl_le_p(req + 4);
+        if (id >= ARRAY_SIZE(rk3588_scmi_clocks)) {
+            return SCMI_ERR_NOT_FOUND;
+        }
+        if (flags & ~(SCMI_CLOCK_SET_ASYNC | SCMI_CLOCK_SET_IGNORE_RESP |
+                      SCMI_CLOCK_SET_ROUND_UP | SCMI_CLOCK_SET_ROUND_AUTO)) {
+            return SCMI_ERR_PARAMS;
+        }
+        if (flags & SCMI_CLOCK_SET_ASYNC) {
+            return SCMI_ERR_SUPPORT;
+        }
+        rate = ldq_le_p(req + 8);
+        status = rk3588_scmi_select_rate(id, flags, rate, &rate);
+        if (status != SCMI_SUCCESS) {
+            return status;
+        }
+        s->clock_rate[id] = rate;
+        if (id == RK3588_SCMI_CPUL) {
+            /* TF-A v2.12 also sets DSU to the requested CPUL rate. */
+            s->clock_rate[RK3588_SCMI_DSU] = rate;
+        }
+        *resp_len = 0;
+        return SCMI_SUCCESS;
+    }
+
+    case 0x6: /* CLOCK_RATE_GET */
+        if (req_len < 4) {
+            return SCMI_ERR_PROTOCOL;
+        }
+        id = ldl_le_p(req);
+        if (id >= ARRAY_SIZE(rk3588_scmi_clocks)) {
+            return SCMI_ERR_NOT_FOUND;
+        }
+        stq_le_p(resp, s->clock_rate[id]);
+        *resp_len = 8;
+        return SCMI_SUCCESS;
+
+    case 0x7: { /* CLOCK_CONFIG_SET */
+        uint32_t attributes;
+
+        if (req_len < 8) {
+            return SCMI_ERR_PROTOCOL;
+        }
+        id = ldl_le_p(req);
+        if (id >= ARRAY_SIZE(rk3588_scmi_clocks)) {
+            return SCMI_ERR_NOT_FOUND;
+        }
+        attributes = ldl_le_p(req + 4);
+        if (attributes & ~SCMI_CLOCK_ENABLED) {
+            return SCMI_ERR_PARAMS;
+        }
+        s->clock_config[id] = attributes;
+        *resp_len = 0;
+        return SCMI_SUCCESS;
+    }
+
+    case 0x8: /* CLOCK_NAME_GET */
+        if (req_len < 4) {
+            return SCMI_ERR_PROTOCOL;
+        }
+        id = ldl_le_p(req);
+        if (id >= ARRAY_SIZE(rk3588_scmi_clocks)) {
+            return SCMI_ERR_NOT_FOUND;
+        }
+        memset(resp, 0, 4 + RK3588_SCMI_MAX_STR_SIZE);
+        memcpy(resp + 4, rk3588_scmi_clocks[id].name,
+               strlen(rk3588_scmi_clocks[id].name));
+        *resp_len = 4 + RK3588_SCMI_MAX_STR_SIZE;
+        return SCMI_SUCCESS;
+
+    case 0xb: { /* CLOCK_CONFIG_GET */
+        uint32_t flags;
+
+        if (req_len < 8) {
+            return SCMI_ERR_PROTOCOL;
+        }
+        id = ldl_le_p(req);
+        if (id >= ARRAY_SIZE(rk3588_scmi_clocks)) {
+            return SCMI_ERR_NOT_FOUND;
+        }
+        flags = ldl_le_p(req + 4);
+        if (flags & ~0xffU) {
+            return SCMI_ERR_PARAMS;
+        }
+        if (flags) { /* OEM configuration type */
+            return SCMI_ERR_SUPPORT;
+        }
+        stl_le_p(resp, 0);
+        stl_le_p(resp + 4, s->clock_config[id]);
+        stl_le_p(resp + 8, 0);
+        *resp_len = 12;
+        return SCMI_SUCCESS;
+    }
+
+    default:
+        return SCMI_ERR_SUPPORT;
+    }
+}
+
+static void rk3588_scmi_process(RK3588SCMIState *s)
+{
+    uint32_t channel_status = rk3588_scmi_rd32(s, SCMI_SHMEM_CHANNEL_STATUS);
+    uint32_t length = rk3588_scmi_rd32(s, SCMI_SHMEM_LENGTH);
+    uint32_t header = rk3588_scmi_rd32(s, SCMI_SHMEM_MSG_HEADER);
+    uint32_t protocol = SCMI_MSG_PROTOCOL(header);
+    uint32_t msg_id = SCMI_MSG_ID(header);
+    const uint8_t *req = s->shmem_ptr + SCMI_SHMEM_MSG_PAYLOAD;
+    uint8_t resp[RK3588_SCMI_RESP_MAX];
+    size_t req_len;
+    size_t resp_len = 0;
+    int32_t status;
+
+    memset(resp, 0, sizeof(resp));
+
+    if (channel_status & SCMI_SHMEM_CHANNEL_ERROR) {
+        return;
+    }
+
+    if (length < 4 ||
+        length - 4 > RK3588_SCMI_SHMEM_SIZE - SCMI_SHMEM_MSG_PAYLOAD) {
+        status = SCMI_ERR_PROTOCOL;
+        resp_len = 0;
+    } else {
+        req_len = length - 4;
+
+        switch (protocol) {
+        case SCMI_PROTOCOL_BASE:
+            status = rk3588_scmi_base_protocol(s, msg_id, req, req_len,
+                                               resp, &resp_len);
+            break;
+        case SCMI_PROTOCOL_CLOCK:
+            status = rk3588_scmi_clock_protocol(s, msg_id, req, req_len,
+                                                resp, &resp_len);
+            break;
+        default:
+            status = SCMI_ERR_SUPPORT;
+            resp_len = 0;
+            break;
+        }
+    }
+
+    if (resp_len > RK3588_SCMI_RESP_MAX) {
+        status = SCMI_ERR_PROTOCOL;
+        resp_len = 0;
+    }
+
+    rk3588_scmi_wr32(s, SCMI_SHMEM_MSG_HEADER, header);
+    rk3588_scmi_wr32(s, SCMI_SHMEM_LENGTH, 8 + resp_len);
+    rk3588_scmi_wr32(s, SCMI_SHMEM_MSG_PAYLOAD, (uint32_t)status);
+    if (resp_len) {
+        memcpy(s->shmem_ptr + SCMI_SHMEM_MSG_PAYLOAD + 4, resp, resp_len);
+    }
+    rk3588_scmi_wr32(s, SCMI_SHMEM_CHANNEL_STATUS,
+                     SCMI_SHMEM_CHANNEL_FREE |
+                     (status == SCMI_ERR_PROTOCOL ?
+                      SCMI_SHMEM_CHANNEL_ERROR : 0));
+}
+
+static bool rk3588_scmi_smc_handler(const uint64_t args[8], uint64_t *ret,
+                                  void *opaque)
+{
+    RK3588SCMIState *s = RK3588_SCMCI(opaque);
+
+    rk3588_scmi_process(s);
+    *ret = 0;
+    return true;
+}
+
+static void rk3588_scmi_reset_hold(Object *obj, ResetType type)
+{
+    RK3588SCMIState *s = RK3588_SCMCI(obj);
+
+    memset(s->shmem_ptr, 0, RK3588_SCMI_SHMEM_SIZE);
+    rk3588_scmi_wr32(s, SCMI_SHMEM_CHANNEL_STATUS, SCMI_SHMEM_CHANNEL_FREE);
+    for (size_t i = 0; i < ARRAY_SIZE(rk3588_scmi_clocks); i++) {
+        s->clock_rate[i] = RK3588_SCMI_BOOT_RATE;
+        s->clock_config[i] = 0;
+    }
+}
+
+static void rk3588_scmi_realize(DeviceState *dev, Error **errp)
+{
+    RK3588SCMIState *s = RK3588_SCMCI(dev);
+
+    if (arm_register_smc_handler(RK3588_SCMI_SMC_ID, rk3588_scmi_smc_handler,
+                                 s) < 0) {
+        error_setg(errp, "rk3588-scmci: SMC function is already registered");
+        return;
+    }
+    s->smc_registered = true;
+}
+
+static void rk3588_scmi_unrealize(DeviceState *dev)
+{
+    RK3588SCMIState *s = RK3588_SCMCI(dev);
+
+    if (s->smc_registered) {
+        arm_unregister_smc_handler(RK3588_SCMI_SMC_ID,
+                                   rk3588_scmi_smc_handler);
+        s->smc_registered = false;
+    }
+}
+
+static void rk3588_scmi_instance_init(Object *obj)
+{
+    RK3588SCMIState *s = RK3588_SCMCI(obj);
+
+    memory_region_init_ram(&s->shmem, obj, TYPE_RK3588_SCMCI,
+                           RK3588_SCMI_SHMEM_SIZE, &error_fatal);
+    sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->shmem);
+    s->shmem_ptr = memory_region_get_ram_ptr(&s->shmem);
+}
+
+static void rk3588_scmi_class_init(ObjectClass *oc, const void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+    ResettableClass *rc = RESETTABLE_CLASS(oc);
+
+    rc->phases.hold = rk3588_scmi_reset_hold;
+    dc->realize = rk3588_scmi_realize;
+    dc->unrealize = rk3588_scmi_unrealize;
+    dc->desc = "Rockchip RK3588 SCMI server";
+    dc->user_creatable = false;
+}
+
+static const TypeInfo rk3588_scmi_typeinfo = {
+    .name = TYPE_RK3588_SCMCI,
+    .parent = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(RK3588SCMIState),
+    .instance_init = rk3588_scmi_instance_init,
+    .class_init = rk3588_scmi_class_init,
+};
+
+static void rk3588_scmi_register_types(void)
+{
+    type_register_static(&rk3588_scmi_typeinfo);
+}
+
+type_init(rk3588_scmi_register_types)
diff --git a/include/hw/misc/rk3588-scmci.h b/include/hw/misc/rk3588-scmci.h
new file mode 100644
index 0000000000..4a00f621d4
--- /dev/null
+++ b/include/hw/misc/rk3588-scmci.h
@@ -0,0 +1,25 @@
+/*
+ * Rockchip RK3588 SCMI server
+ *
+ * This device implements the SCMI shared memory and a minimal SCMI
+ * server for the RK3588 SMC transport.  The guest uses the standard
+ * "arm,scmi-smc" binding, with the SMC function ID and shared memory
+ * address documented by the upstream RK3588 device tree.
+ *
+ * Copyright (C) 2026 Process Mission
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_MISC_RK3588_SCMCI_H
+#define HW_MISC_RK3588_SCMCI_H
+
+#include "qom/object.h"
+
+#define TYPE_RK3588_SCMCI "rk3588-scmci"
+OBJECT_DECLARE_SIMPLE_TYPE(RK3588SCMIState, RK3588_SCMCI)
+
+#define RK3588_SCMI_SMC_ID      0x82000010
+#define RK3588_SCMI_SHMEM_SIZE  0x100
+
+#endif /* HW_MISC_RK3588_SCMCI_H */
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC PATCH 15/20] hw/arm/rk3588: wire up the SCMI server
  2026-11-13  9:47 [RFC PATCH 00/20] hw/arm: Add initial RK3588 and ROCK 5B support Yifan Wang
                   ` (13 preceding siblings ...)
  2026-11-13  9:47 ` [RFC PATCH 14/20] hw/misc: add RK3588 SCMI server Yifan Wang
@ 2026-11-13  9:47 ` Yifan Wang
  2026-11-13  9:47 ` [RFC PATCH 16/20] hw/arm: add Radxa ROCK 5B board Yifan Wang
                   ` (4 subsequent siblings)
  19 siblings, 0 replies; 22+ messages in thread
From: Yifan Wang @ 2026-11-13  9:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Yifan Wang, qemu-arm, qemu-block, kvm, Peter Maydell,
	Pierrick Bouvier, Paolo Bonzini, Alistair Francis, Kevin Wolf,
	Hanna Reitz, Kuan-Wei Chiu, Marc-André Lureau, bin.meng,
	tangtao1634, Chao Liu

From: Chao Liu <chao.liu@processmission.com>

Instantiate the SCMI server in the RK3588 SoC and map its shared memory
at the address reserved by the RK3588 device tree.  The shared memory
is overlaid on RAM so the guest can use it while the rest of the low
memory map is unchanged.

Signed-off-by: Chao Liu <chao.liu@processmission.com>
Signed-off-by: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
---
 hw/arm/rk3588.c         | 22 ++++++++++++++++++++++
 include/hw/arm/rk3588.h |  1 +
 2 files changed, 23 insertions(+)

diff --git a/hw/arm/rk3588.c b/hw/arm/rk3588.c
index 2319c54c76..f4ebb59d36 100644
--- a/hw/arm/rk3588.c
+++ b/hw/arm/rk3588.c
@@ -19,6 +19,7 @@
 #include "hw/core/qdev-properties.h"
 #include "hw/core/sysbus.h"
 #include "hw/cpu/cluster.h"
+#include "hw/misc/rk3588-scmci.h"
 #include "hw/misc/unimp.h"
 #include "hw/timer/rockchip-hptimer.h"
 #include "migration/vmstate.h"
@@ -29,6 +30,7 @@
 #define RK3588_MPIDR_AFF0_PER_AFF1   (1)
 
 #define RK3588_CNTFRQ                24000000
+#define RK3588_SCMI_SHMEM_BASE       0x0010f000
 #define RK3588_SFC_SPI               206
 #define RK3588_GIC_NUM_IRQS          512
 
@@ -253,6 +255,21 @@ static bool rk3588_soc_create_sfc(RK3588SoCState *s, Error **errp)
     return true;
 }
 
+static bool rk3588_soc_create_scmi(RK3588SoCState *s, Error **errp)
+{
+    SysBusDevice *scmi = SYS_BUS_DEVICE(s->scmi);
+
+    if (!sysbus_realize(scmi, errp)) {
+        return false;
+    }
+
+    memory_region_add_subregion_overlap(s->memory,
+        RK3588_SCMI_SHMEM_BASE,
+        sysbus_mmio_get_region(scmi, 0), 1);
+
+    return true;
+}
+
 static bool rk3588_soc_create_uart(RK3588SoCState *s, Error **errp)
 {
     for (unsigned int i = RK3588_FIRST_UART; i < RK3588_NUM_UARTS; i++) {
@@ -329,6 +346,7 @@ static void rk3588_soc_realize(DeviceState *dev, Error **errp)
         !rk3588_soc_create_cru(s, errp) ||
         !rk3588_soc_create_otp(s, errp) ||
         !rk3588_soc_create_sfc(s, errp) ||
+        !rk3588_soc_create_scmi(s, errp) ||
         !rk3588_soc_create_uart(s, errp) ||
         !rk3588_soc_create_hptimer(s, errp)) {
         return;
@@ -388,6 +406,10 @@ static void rk3588_soc_instance_init(Object *obj)
     object_property_add_child(obj, "sfc", OBJECT(s->sfc));
     object_unref(OBJECT(s->sfc));
 
+    s->scmi = qdev_new(TYPE_RK3588_SCMCI);
+    object_property_add_child(obj, "scmi", OBJECT(s->scmi));
+    object_unref(OBJECT(s->scmi));
+
     s->hptimer = qdev_new(TYPE_ROCKCHIP_HPTIMER);
     object_property_add_child(obj, "hptimer", OBJECT(s->hptimer));
     object_unref(OBJECT(s->hptimer));
diff --git a/include/hw/arm/rk3588.h b/include/hw/arm/rk3588.h
index 1304c11598..f85242f464 100644
--- a/include/hw/arm/rk3588.h
+++ b/include/hw/arm/rk3588.h
@@ -55,6 +55,7 @@ struct RK3588SoCState {
     DeviceState *cru;
     DeviceState *otp;
     DeviceState *sfc;
+    DeviceState *scmi;
     MemoryRegion *memory;
     MemoryRegion sram;
     DeviceState *hptimer;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC PATCH 16/20] hw/arm: add Radxa ROCK 5B board
  2026-11-13  9:47 [RFC PATCH 00/20] hw/arm: Add initial RK3588 and ROCK 5B support Yifan Wang
                   ` (14 preceding siblings ...)
  2026-11-13  9:47 ` [RFC PATCH 15/20] hw/arm/rk3588: wire up the " Yifan Wang
@ 2026-11-13  9:47 ` Yifan Wang
  2026-11-13  9:47 ` [RFC PATCH 17/20] hw/arm/rock-5b: connect the XTX XT25F128 SPI NOR flash Yifan Wang
                   ` (3 subsequent siblings)
  19 siblings, 0 replies; 22+ messages in thread
From: Yifan Wang @ 2026-11-13  9:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Yifan Wang, qemu-arm, qemu-block, kvm, Peter Maydell,
	Pierrick Bouvier, Paolo Bonzini, Alistair Francis, Kevin Wolf,
	Hanna Reitz, Kuan-Wei Chiu, Marc-André Lureau, bin.meng,
	tangtao1634, Chao Liu

From: Chao Liu <chao.liu@processmission.com>

Add initial support for the Radxa ROCK 5B board, which uses the RK3588
SoC and 128 MiB to 16 GiB of DRAM. Support direct Linux booting.

The first -serial option drives UART2, the debug console on the ROCK 5B
header. Further -serial options connect to UART1 and UART3 through UART9
in that order.

Signed-off-by: Chao Liu <chao.liu@processmission.com>
Signed-off-by: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
---
 MAINTAINERS        |   1 +
 hw/arm/Kconfig     |   6 ++
 hw/arm/meson.build |   1 +
 hw/arm/rock-5b.c   | 200 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 208 insertions(+)
 create mode 100644 hw/arm/rock-5b.c

diff --git a/MAINTAINERS b/MAINTAINERS
index c3d3388975..544d93c01d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1065,6 +1065,7 @@ M: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
 L: qemu-arm@nongnu.org
 S: Maintained
 F: hw/arm/rk3588.c
+F: hw/arm/rock-5b.c
 F: hw/misc/rockchip_cru.c
 F: hw/misc/rockchip_otp.c
 F: hw/misc/rk3588-scmci.c
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index eaa55eae29..40f7de823c 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -783,3 +783,9 @@ config RK3588
     select REGISTER
     select ROCKCHIP_SFC
     select UNIMP
+
+config ROCK5B
+    bool
+    default y
+    depends on TCG && AARCH64
+    select RK3588
diff --git a/hw/arm/meson.build b/hw/arm/meson.build
index 70c835814f..9af1e01037 100644
--- a/hw/arm/meson.build
+++ b/hw/arm/meson.build
@@ -121,5 +121,6 @@ arm_common_ss.add(when: ['CONFIG_AXIADO_EVK', 'TARGET_AARCH64'], if_true: files(
 arm_common_ss.add(files('boot.c'))
 
 arm_common_ss.add(when: 'CONFIG_RK3588', if_true: files('rk3588.c'))
+arm_common_ss.add(when: 'CONFIG_ROCK5B', if_true: files('rock-5b.c'))
 
 hw_common_arch += {'arm': arm_common_ss}
diff --git a/hw/arm/rock-5b.c b/hw/arm/rock-5b.c
new file mode 100644
index 0000000000..7906d53175
--- /dev/null
+++ b/hw/arm/rock-5b.c
@@ -0,0 +1,200 @@
+/*
+ * Radxa ROCK 5B Board emulation
+ *
+ * Copyright (C) 2026 Process Mission
+ *
+ * Authors:
+ *    Chao Liu <chao.liu@processmission.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/error-report.h"
+#include "qemu/module.h"
+#include "qemu/units.h"
+#include "qapi/error.h"
+#include "hw/arm/boot.h"
+#include "hw/arm/rk3588.h"
+#include "hw/core/boards.h"
+#include "hw/core/qdev-properties-system.h"
+#include "system/address-spaces.h"
+#include "system/device_tree.h"
+#include "system/kvm.h"
+#include "system/qtest.h"
+#include "system/system.h"
+
+#define TYPE_ROCK5B_MACHINE MACHINE_TYPE_NAME("rock-5b")
+OBJECT_DECLARE_SIMPLE_TYPE(Rock5BMachineState, ROCK5B_MACHINE)
+
+enum {
+    ROCK5B_LOW_RAM,
+    ROCK5B_HIGH_RAM,
+};
+
+static const MemMapEntry rock5b_memmap[] = {
+    [ROCK5B_LOW_RAM]  = { 0x000000000, 0x0f0000000 },
+    [ROCK5B_HIGH_RAM] = { 0x100000000, 0x310000000 },
+};
+
+/* Match the low-memory reservation made by Rockchip U-Boot for BL31. */
+#define ROCK5B_FIRMWARE_RESERVED_SIZE (2 * MiB)
+/* UART2 drives the board's debug header. */
+#define ROCK5B_CONSOLE_UART 2
+
+struct Rock5BMachineState {
+    MachineState parent_obj;
+
+    RK3588SoCState soc;
+    MemoryRegion low_ram;
+    MemoryRegion high_ram;
+    uint64_t low_ram_size;
+    uint64_t high_ram_size;
+    struct arm_boot_info binfo;
+};
+
+/*
+ * The first -serial option drives the debug console; further options
+ * connect to the remaining UARTs in index order.
+ */
+static void rock5b_connect_serial(Rock5BMachineState *s)
+{
+    unsigned int hd = 1;
+
+    /* UART0 in the PMU power domain is not modeled. */
+    for (unsigned int i = 1; i < RK3588_NUM_UARTS; i++) {
+        g_autofree char *prop = g_strdup_printf("uart%u-chardev", i);
+
+        qdev_prop_set_chr(DEVICE(&s->soc), prop,
+                          serial_hd(i == ROCK5B_CONSOLE_UART ? 0 : hd++));
+    }
+}
+
+/*
+ * arm_load_dtb() replaces the memory nodes with a single node for low RAM;
+ * add the RAM above the peripheral hole.
+ */
+static void rock5b_modify_dtb(const struct arm_boot_info *binfo, void *fdt)
+{
+    const Rock5BMachineState *s = container_of(binfo, Rock5BMachineState,
+                                               binfo);
+    hwaddr base = rock5b_memmap[ROCK5B_HIGH_RAM].base;
+    g_autofree char *node = NULL;
+    uint32_t acells, scells;
+
+    if (!s->high_ram_size) {
+        return;
+    }
+
+    acells = qemu_fdt_getprop_cell(fdt, "/", "#address-cells", NULL,
+                                   &error_fatal);
+    scells = qemu_fdt_getprop_cell(fdt, "/", "#size-cells", NULL,
+                                   &error_fatal);
+    node = g_strdup_printf("/memory@%" HWADDR_PRIx, base);
+    qemu_fdt_add_subnode(fdt, node);
+    qemu_fdt_setprop_string(fdt, node, "device_type", "memory");
+    if (qemu_fdt_setprop_sized_cells(fdt, node, "reg", acells, base,
+                                     scells, s->high_ram_size) < 0) {
+        error_report("rock-5b: device tree cells cannot describe RAM "
+                     "above 4 GiB");
+        exit(EXIT_FAILURE);
+    }
+}
+
+/*
+ * arm_load_kernel() enters Linux at EL2, keeps the SMC PSCI conduit and
+ * registers the CPU reset handlers.
+ */
+static void rock5b_direct_boot(Rock5BMachineState *s)
+{
+    s->binfo.ram_size = s->low_ram_size - ROCK5B_FIRMWARE_RESERVED_SIZE;
+    s->binfo.loader_start = ROCK5B_FIRMWARE_RESERVED_SIZE;
+    s->binfo.board_id = -1;
+    s->binfo.psci_conduit = QEMU_PSCI_CONDUIT_SMC;
+    s->binfo.modify_dtb = rock5b_modify_dtb;
+    arm_load_kernel(&s->soc.cpu[0], MACHINE(s), &s->binfo);
+}
+
+static void rock5b_init(MachineState *ms)
+{
+    Rock5BMachineState *s = ROCK5B_MACHINE(ms);
+
+    if (ms->ram_size < 128 * MiB || ms->ram_size > 16 * GiB) {
+        error_report("rock-5b: memory size must be between "
+                     "128 MiB and 16 GiB");
+        exit(EXIT_FAILURE);
+    }
+
+    if (kvm_enabled()) {
+        error_report("rock-5b: KVM is not supported");
+        exit(EXIT_FAILURE);
+    }
+
+    if (ms->firmware) {
+        error_report("rock-5b: -bios is not supported");
+        exit(EXIT_FAILURE);
+    }
+    if (ms->kernel_filename) {
+        if (!ms->dtb) {
+            error_report("rock-5b: direct Linux boot requires -dtb");
+            exit(EXIT_FAILURE);
+        }
+    } else if (!qtest_enabled()) {
+        error_report("rock-5b: supply a Linux kernel with -kernel");
+        exit(EXIT_FAILURE);
+    }
+
+    /* Initialize the SoC object. */
+    object_initialize_child(OBJECT(s), "soc", &s->soc, TYPE_RK3588_SOC);
+    object_property_set_link(OBJECT(&s->soc), "memory",
+                             OBJECT(get_system_memory()), &error_abort);
+    rock5b_connect_serial(s);
+    qdev_realize(DEVICE(&s->soc), NULL, &error_fatal);
+
+    s->low_ram_size = MIN(ms->ram_size,
+                          rock5b_memmap[ROCK5B_LOW_RAM].size);
+    s->high_ram_size = ms->ram_size - s->low_ram_size;
+    memory_region_init_alias(&s->low_ram, OBJECT(s), "rock-5b.low-ram",
+                             ms->ram, 0, s->low_ram_size);
+    memory_region_add_subregion(get_system_memory(),
+                                rock5b_memmap[ROCK5B_LOW_RAM].base,
+                                &s->low_ram);
+    if (s->high_ram_size) {
+        memory_region_init_alias(&s->high_ram, OBJECT(s),
+                                 "rock-5b.high-ram", ms->ram,
+                                 s->low_ram_size, s->high_ram_size);
+        memory_region_add_subregion(get_system_memory(),
+                                    rock5b_memmap[ROCK5B_HIGH_RAM].base,
+                                    &s->high_ram);
+    }
+
+    rock5b_direct_boot(s);
+}
+
+static void rock5b_class_init(ObjectClass *oc, const void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+
+    mc->desc = "Radxa ROCK 5B";
+    mc->init = rock5b_init;
+    mc->default_ram_size = 2 * GiB;
+    mc->default_ram_id = "rock-5b.ram";
+    mc->min_cpus = RK3588_NUM_CPUS;
+    mc->default_cpus = RK3588_NUM_CPUS;
+    mc->max_cpus = RK3588_NUM_CPUS;
+    mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a55");
+}
+
+static const TypeInfo rock5b_typeinfo = {
+    .name = TYPE_ROCK5B_MACHINE,
+    .parent = TYPE_MACHINE,
+    .instance_size = sizeof(Rock5BMachineState),
+    .class_init = rock5b_class_init,
+};
+
+static void rock5b_register_types(void)
+{
+    type_register_static(&rock5b_typeinfo);
+}
+
+type_init(rock5b_register_types)
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC PATCH 17/20] hw/arm/rock-5b: connect the XTX XT25F128 SPI NOR flash
  2026-11-13  9:47 [RFC PATCH 00/20] hw/arm: Add initial RK3588 and ROCK 5B support Yifan Wang
                   ` (15 preceding siblings ...)
  2026-11-13  9:47 ` [RFC PATCH 16/20] hw/arm: add Radxa ROCK 5B board Yifan Wang
@ 2026-11-13  9:47 ` Yifan Wang
  2026-11-13  9:47 ` [RFC PATCH 18/20] hw/arm/rock-5b: add firmware booting Yifan Wang
                   ` (2 subsequent siblings)
  19 siblings, 0 replies; 22+ messages in thread
From: Yifan Wang @ 2026-11-13  9:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Yifan Wang, qemu-arm, qemu-block, kvm, Peter Maydell,
	Pierrick Bouvier, Paolo Bonzini, Alistair Francis, Kevin Wolf,
	Hanna Reitz, Kuan-Wei Chiu, Marc-André Lureau, bin.meng,
	tangtao1634, Chao Liu

From: Chao Liu <chao.liu@processmission.com>

Connect an XT25F128 to chip select 0 of the ROCK 5B SFC. An optional
if=mtd,index=0 drive provides the flash contents and must be exactly
16 MiB; without a drive the flash starts erased.

Signed-off-by: Chao Liu <chao.liu@processmission.com>
Signed-off-by: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
---
 hw/arm/Kconfig   |  1 +
 hw/arm/rock-5b.c | 29 +++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index 40f7de823c..01ae699fee 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -789,3 +789,4 @@ config ROCK5B
     default y
     depends on TCG && AARCH64
     select RK3588
+    select SSI_M25P80
diff --git a/hw/arm/rock-5b.c b/hw/arm/rock-5b.c
index 7906d53175..abc898c50c 100644
--- a/hw/arm/rock-5b.c
+++ b/hw/arm/rock-5b.c
@@ -17,8 +17,12 @@
 #include "hw/arm/boot.h"
 #include "hw/arm/rk3588.h"
 #include "hw/core/boards.h"
+#include "hw/core/qdev-properties.h"
 #include "hw/core/qdev-properties-system.h"
+#include "hw/ssi/ssi.h"
 #include "system/address-spaces.h"
+#include "system/block-backend.h"
+#include "system/blockdev.h"
 #include "system/device_tree.h"
 #include "system/kvm.h"
 #include "system/qtest.h"
@@ -37,6 +41,7 @@ static const MemMapEntry rock5b_memmap[] = {
     [ROCK5B_HIGH_RAM] = { 0x100000000, 0x310000000 },
 };
 
+#define ROCK5B_FLASH_SIZE (16 * MiB)
 /* Match the low-memory reservation made by Rockchip U-Boot for BL31. */
 #define ROCK5B_FIRMWARE_RESERVED_SIZE (2 * MiB)
 /* UART2 drives the board's debug header. */
@@ -70,6 +75,28 @@ static void rock5b_connect_serial(Rock5BMachineState *s)
     }
 }
 
+static void rock5b_create_flash(Rock5BMachineState *s)
+{
+    DriveInfo *di = drive_get(IF_MTD, 0, 0);
+    DeviceState *flash = qdev_new("xt25f128");
+
+    object_property_add_child(OBJECT(s), "spi-nor", OBJECT(flash));
+    if (di) {
+        BlockBackend *blk = blk_by_legacy_dinfo(di);
+        int64_t length = blk_getlength(blk);
+
+        if (length != ROCK5B_FLASH_SIZE) {
+            error_report("rock-5b: SPI NOR image must be exactly 16 MiB");
+            exit(EXIT_FAILURE);
+        }
+        qdev_prop_set_drive_err(flash, "drive", blk, &error_fatal);
+    }
+    qdev_realize_and_unref(flash, qdev_get_child_bus(s->soc.sfc, "spi"),
+                           &error_fatal);
+    qdev_connect_gpio_out_named(s->soc.sfc, "cs", 0,
+                                qdev_get_gpio_in_named(flash, SSI_GPIO_CS, 0));
+}
+
 /*
  * arm_load_dtb() replaces the memory nodes with a single node for low RAM;
  * add the RAM above the peripheral hole.
@@ -168,6 +195,8 @@ static void rock5b_init(MachineState *ms)
                                     &s->high_ram);
     }
 
+    rock5b_create_flash(s);
+
     rock5b_direct_boot(s);
 }
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC PATCH 18/20] hw/arm/rock-5b: add firmware booting
  2026-11-13  9:47 [RFC PATCH 00/20] hw/arm: Add initial RK3588 and ROCK 5B support Yifan Wang
                   ` (16 preceding siblings ...)
  2026-11-13  9:47 ` [RFC PATCH 17/20] hw/arm/rock-5b: connect the XTX XT25F128 SPI NOR flash Yifan Wang
@ 2026-11-13  9:47 ` Yifan Wang
  2026-11-13  9:47 ` [RFC PATCH 19/20] tests/functional: add ROCK 5B boot tests Yifan Wang
  2026-11-13  9:47 ` [RFC PATCH 20/20] docs/system/arm: document the Radxa ROCK 5B machine Yifan Wang
  19 siblings, 0 replies; 22+ messages in thread
From: Yifan Wang @ 2026-11-13  9:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Yifan Wang, qemu-arm, qemu-block, kvm, Peter Maydell,
	Pierrick Bouvier, Paolo Bonzini, Alistair Francis, Kevin Wolf,
	Hanna Reitz, Kuan-Wei Chiu, Marc-André Lureau, bin.meng,
	tangtao1634, Chao Liu

From: Chao Liu <chao.liu@processmission.com>

Load a raw U-Boot SPL image supplied with -bios at address zero and
start it in non-secure EL2. SPL loads U-Boot proper from SPI NOR, and
QEMU provides PSCI and SCMI services through SMC calls.

Restore the SPI boot-source value in SRAM and the HPTIMER enable state
on reset before entering SPL.

Signed-off-by: Chao Liu <chao.liu@processmission.com>
Signed-off-by: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
---
 hw/arm/rock-5b.c | 98 ++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 83 insertions(+), 15 deletions(-)

diff --git a/hw/arm/rock-5b.c b/hw/arm/rock-5b.c
index abc898c50c..c097e17c5c 100644
--- a/hw/arm/rock-5b.c
+++ b/hw/arm/rock-5b.c
@@ -10,6 +10,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/datadir.h"
 #include "qemu/error-report.h"
 #include "qemu/module.h"
 #include "qemu/units.h"
@@ -17,15 +18,18 @@
 #include "hw/arm/boot.h"
 #include "hw/arm/rk3588.h"
 #include "hw/core/boards.h"
+#include "hw/core/loader.h"
 #include "hw/core/qdev-properties.h"
 #include "hw/core/qdev-properties-system.h"
 #include "hw/ssi/ssi.h"
+#include "hw/timer/rockchip-hptimer.h"
 #include "system/address-spaces.h"
 #include "system/block-backend.h"
 #include "system/blockdev.h"
 #include "system/device_tree.h"
 #include "system/kvm.h"
 #include "system/qtest.h"
+#include "system/reset.h"
 #include "system/system.h"
 
 #define TYPE_ROCK5B_MACHINE MACHINE_TYPE_NAME("rock-5b")
@@ -41,6 +45,10 @@ static const MemMapEntry rock5b_memmap[] = {
     [ROCK5B_HIGH_RAM] = { 0x100000000, 0x310000000 },
 };
 
+#define ROCK5B_SPL_ADDR   0x00000000
+#define ROCK5B_SPL_SIZE   (4 * MiB)
+#define ROCK5B_BOOTSOURCE_ADDR (RK3588_SRAM_BASE + 0x10)
+#define ROCK5B_BOOTSOURCE_ID  3 /* BROM_BOOTSOURCE_FSPI_M0 */
 #define ROCK5B_FLASH_SIZE (16 * MiB)
 /* Match the low-memory reservation made by Rockchip U-Boot for BL31. */
 #define ROCK5B_FIRMWARE_RESERVED_SIZE (2 * MiB)
@@ -58,6 +66,29 @@ struct Rock5BMachineState {
     struct arm_boot_info binfo;
 };
 
+static void rock5b_reset(void *opaque)
+{
+    Rock5BMachineState *s = opaque;
+
+    /* Restore the firmware handoff state before entering SPL at EL2. */
+    address_space_stl_le(&address_space_memory, ROCK5B_BOOTSOURCE_ADDR,
+                         ROCK5B_BOOTSOURCE_ID, MEMTXATTRS_UNSPECIFIED, NULL);
+    address_space_stl_le(&address_space_memory,
+                         RK3588_HPTIMER_BASE + ROCKCHIP_HPTIMER_CTRL,
+                         ROCKCHIP_HPTIMER_ENABLE, MEMTXATTRS_UNSPECIFIED, NULL);
+
+    for (unsigned int i = 0; i < RK3588_NUM_CPUS; i++) {
+        ARMCPU *cpu = &s->soc.cpu[i];
+
+        cpu_reset(CPU(cpu));
+        arm_emulate_firmware_reset(CPU(cpu), 2);
+        arm_rebuild_hflags(&cpu->env);
+        if (i == 0) {
+            cpu_set_pc(CPU(cpu), ROCK5B_SPL_ADDR);
+        }
+    }
+}
+
 /*
  * The first -serial option drives the debug console; further options
  * connect to the remaining UARTs in index order.
@@ -128,6 +159,35 @@ static void rock5b_modify_dtb(const struct arm_boot_info *binfo, void *fdt)
     }
 }
 
+static void rock5b_firmware_boot(Rock5BMachineState *s)
+{
+    MachineState *ms = MACHINE(s);
+
+    for (unsigned int i = 0; i < RK3588_NUM_CPUS; i++) {
+        object_property_set_int(OBJECT(&s->soc.cpu[i]), "psci-conduit",
+                                QEMU_PSCI_CONDUIT_SMC, &error_abort);
+    }
+
+    if (ms->firmware) {
+        g_autofree char *filename = qemu_find_file(QEMU_FILE_TYPE_BIOS,
+                                                  ms->firmware);
+        ssize_t size;
+
+        if (!filename) {
+            error_report("rock-5b: cannot find SPL '%s'", ms->firmware);
+            exit(EXIT_FAILURE);
+        }
+        size = load_image_targphys(filename, ROCK5B_SPL_ADDR,
+                                   ROCK5B_SPL_SIZE, &error_fatal);
+        if (size <= 0) {
+            error_report("rock-5b: SPL image is empty");
+            exit(EXIT_FAILURE);
+        }
+    }
+    /* Restore the firmware handoff state after device reset. */
+    qemu_register_reset(rock5b_reset, s);
+}
+
 /*
  * arm_load_kernel() enters Linux at EL2, keeps the SMC PSCI conduit and
  * registers the CPU reset handlers.
@@ -157,20 +217,6 @@ static void rock5b_init(MachineState *ms)
         exit(EXIT_FAILURE);
     }
 
-    if (ms->firmware) {
-        error_report("rock-5b: -bios is not supported");
-        exit(EXIT_FAILURE);
-    }
-    if (ms->kernel_filename) {
-        if (!ms->dtb) {
-            error_report("rock-5b: direct Linux boot requires -dtb");
-            exit(EXIT_FAILURE);
-        }
-    } else if (!qtest_enabled()) {
-        error_report("rock-5b: supply a Linux kernel with -kernel");
-        exit(EXIT_FAILURE);
-    }
-
     /* Initialize the SoC object. */
     object_initialize_child(OBJECT(s), "soc", &s->soc, TYPE_RK3588_SOC);
     object_property_set_link(OBJECT(&s->soc), "memory",
@@ -197,7 +243,29 @@ static void rock5b_init(MachineState *ms)
 
     rock5b_create_flash(s);
 
-    rock5b_direct_boot(s);
+    if (ms->kernel_filename) {
+        if (ms->firmware) {
+            error_report("rock-5b: -bios and -kernel cannot be combined");
+            exit(EXIT_FAILURE);
+        }
+        if (!ms->dtb) {
+            error_report("rock-5b: direct Linux boot requires -dtb");
+            exit(EXIT_FAILURE);
+        }
+        rock5b_direct_boot(s);
+    } else {
+        if (!ms->firmware && !qtest_enabled()) {
+            error_report("rock-5b: supply a U-Boot SPL image with -bios "
+                         "or a Linux kernel with -kernel");
+            exit(EXIT_FAILURE);
+        }
+        if (ms->dtb) {
+            error_report("rock-5b: -dtb requires -kernel; U-Boot proper "
+                         "passes the device tree from the FIT");
+            exit(EXIT_FAILURE);
+        }
+        rock5b_firmware_boot(s);
+    }
 }
 
 static void rock5b_class_init(ObjectClass *oc, const void *data)
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC PATCH 19/20] tests/functional: add ROCK 5B boot tests
  2026-11-13  9:47 [RFC PATCH 00/20] hw/arm: Add initial RK3588 and ROCK 5B support Yifan Wang
                   ` (17 preceding siblings ...)
  2026-11-13  9:47 ` [RFC PATCH 18/20] hw/arm/rock-5b: add firmware booting Yifan Wang
@ 2026-11-13  9:47 ` Yifan Wang
  2026-11-13  9:47 ` [RFC PATCH 20/20] docs/system/arm: document the Radxa ROCK 5B machine Yifan Wang
  19 siblings, 0 replies; 22+ messages in thread
From: Yifan Wang @ 2026-11-13  9:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Yifan Wang, qemu-arm, qemu-block, kvm, Peter Maydell,
	Pierrick Bouvier, Paolo Bonzini, Alistair Francis, Kevin Wolf,
	Hanna Reitz, Kuan-Wei Chiu, Marc-André Lureau, bin.meng,
	tangtao1634, Chao Liu

From: Chao Liu <chao.liu@processmission.com>

Add tests for both boot methods, direct Linux booting and firmware
booting, and check that the boot flow works for each of them.

Signed-off-by: Chao Liu <chao.liu@processmission.com>
Signed-off-by: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
---
 MAINTAINERS                              |   1 +
 tests/functional/aarch64/meson.build     |   2 +
 tests/functional/aarch64/test_rock_5b.py | 118 +++++++++++++++++++++++
 3 files changed, 121 insertions(+)
 create mode 100755 tests/functional/aarch64/test_rock_5b.py

diff --git a/MAINTAINERS b/MAINTAINERS
index 544d93c01d..6303b99755 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1074,6 +1074,7 @@ F: hw/timer/rockchip-hptimer.c
 F: include/hw/arm/rk3588.h
 F: include/hw/misc/rk3588-scmci.h
 F: include/hw/timer/rockchip-hptimer.h
+F: tests/functional/aarch64/test_rock_5b.py
 
 SABRELITE / i.MX6
 M: Peter Maydell <peter.maydell@linaro.org>
diff --git a/tests/functional/aarch64/meson.build b/tests/functional/aarch64/meson.build
index f0881bed16..d6b79314e6 100644
--- a/tests/functional/aarch64/meson.build
+++ b/tests/functional/aarch64/meson.build
@@ -11,6 +11,7 @@ test_aarch64_timeouts = {
   'reverse_debug' : 180,
   'rme_virt' : 1200,
   'rme_sbsaref' : 1200,
+  'rock_5b' : 180,
   'sbsaref_alpine' : 1200,
   'sbsaref_freebsd' : 720,
   'smmu' : 720,
@@ -45,6 +46,7 @@ tests_aarch64_system_thorough = [
   'reverse_debug',
   'rme_virt',
   'rme_sbsaref',
+  'rock_5b',
   'sbsaref',
   'sbsaref_alpine',
   'sbsaref_freebsd',
diff --git a/tests/functional/aarch64/test_rock_5b.py b/tests/functional/aarch64/test_rock_5b.py
new file mode 100755
index 0000000000..5789cfb2c2
--- /dev/null
+++ b/tests/functional/aarch64/test_rock_5b.py
@@ -0,0 +1,118 @@
+# Functional test for ROCK 5B SPL, U-Boot and direct Linux boot
+#
+# Copyright (C) 2026 Process Mission
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+from qemu_test import Asset, QemuSystemTest, skipIfMissingCommands
+from qemu_test import exec_command, exec_command_and_wait_for_pattern
+from qemu_test import wait_for_console_pattern
+
+
+class Rock5BMachine(QemuSystemTest):
+
+    ASSET_IMAGE = Asset(
+        ('https://github.com/processmission/qemu-machine-images/releases/'
+         'download/v1.2.0/aarch64-rock-5b-v1.2.0.tar.zst'),
+        'bbec789f25a5e87adb1aeabf58294551d2a26bbf076e0041935f307a9492ce6f')
+
+    UBOOT_PATTERNS = ('U-Boot SPL 2025.01',
+                      'Trying to boot from SPI',
+                      'U-Boot 2025.01',
+                      'SF: Detected xt25f128',
+                      'SF: 12582912 bytes @ 0x400000 Read: OK',
+                      'Starting kernel')
+    LINUX_PATTERNS = ('Booting Linux on physical CPU',)
+    LINUX_APPEND = ('console=ttyS2,1500000n8 '
+                    'earlycon=uart8250,mmio32,0xfeb50000 '
+                    'rdinit=/init')
+
+    def _extract_images(self) -> None:
+        self.require_accelerator('tcg')
+        self.set_machine('rock-5b')
+        archive = self.uncompress(self.ASSET_IMAGE, target='images.tar',
+                                  format='zstd')
+        self.archive_extract(archive, format='tar')
+
+    def _boot_and_login(self, patterns: tuple[str, ...]) -> None:
+        for pattern in patterns + ('rock5b login:',):
+            wait_for_console_pattern(self, pattern, 'Kernel panic')
+        exec_command_and_wait_for_pattern(self, 'root', '# ')
+
+    def _check_guest(self, command: str) -> None:
+        # Split the marker so an echoed command cannot satisfy the check.
+        exec_command_and_wait_for_pattern(
+            self,
+            command + " && printf '\\nROCK5B_%s\\n' OK"
+                      " || printf '\\nROCK5B_%s\\n' FAIL",
+            'ROCK5B_OK', 'ROCK5B_FAIL')
+        wait_for_console_pattern(self, '# ')
+
+    def _check_board(self) -> None:
+        self._check_guest('test "$(uname -m)" = aarch64')
+        self._check_guest('test "$(grep -c ^processor /proc/cpuinfo)" -eq 8')
+        self._check_guest('test -c /dev/ttyS2 && '
+                          'test -d /sys/devices/system/cpu/cpu7')
+        self._check_guest(
+            'test "$(tr -d \'\\000\' < /proc/device-tree/model)" '
+            '= \'Radxa ROCK 5B\'')
+        self._check_guest(
+            "tr '\\000' '\\n' < /proc/device-tree/compatible | "
+            "grep -qx 'radxa,rock-5b'")
+        self._check_guest(
+            "printf 'rock5b-boot\\n' > /root/boot-check && "
+            'test "$(cat /root/boot-check)" = rock5b-boot')
+
+    def _reboot_and_poweroff(self, patterns: tuple[str, ...]) -> None:
+        exec_command(self, 'reboot -f')
+        self._boot_and_login(patterns)
+        self._check_guest('test "$(grep -c ^processor /proc/cpuinfo)" -eq 8')
+        self._check_guest('test ! -e /root/boot-check')
+
+        exec_command_and_wait_for_pattern(self, 'poweroff -f',
+                                          'reboot: Power down')
+        self.vm.wait()
+        self.assertEqual(self.vm.exitcode(), 0)
+
+    @skipIfMissingCommands('zstd')
+    def test_flash_boot(self) -> None:
+        self._extract_images()
+        firmware = self.scratch_file('images', 'u-boot-spl.bin')
+        flash = self.scratch_file('images', 'spi-nor.img')
+
+        self.vm.set_console()
+        self.vm.add_args('-accel', 'tcg', '-m', '2G', '-smp', '8',
+                         '-bios', firmware,
+                         '-drive', f'if=mtd,index=0,file={flash},'
+                                   'format=raw,snapshot=on')
+        self.vm.launch()
+        self._boot_and_login(self.UBOOT_PATTERNS)
+        self._check_board()
+        self._reboot_and_poweroff(self.UBOOT_PATTERNS)
+
+    @skipIfMissingCommands('zstd')
+    def test_direct_boot(self) -> None:
+        self._extract_images()
+
+        self.vm.set_console()
+        # 5 GiB of RAM continues above the peripheral hole at 0x100000000.
+        self.vm.add_args('-accel', 'tcg', '-m', '5G', '-smp', '8',
+                         '-kernel', self.scratch_file('images', 'Image'),
+                         '-initrd',
+                         self.scratch_file('images', 'rootfs.cpio.gz'),
+                         '-dtb',
+                         self.scratch_file('images', 'rk3588-rock-5b.dtb'),
+                         '-append', self.LINUX_APPEND)
+        self.vm.launch()
+        self._boot_and_login(self.LINUX_PATTERNS)
+        self._check_board()
+        self._check_guest('grep -q rdinit=/init /proc/cmdline')
+        self._check_guest('test -d /proc/device-tree/memory@100000000')
+        # Low RAM ends at 0xf0000000, which is 3932160 KiB.
+        self._check_guest(
+            'test "$(awk \'/^MemTotal/ {print $2}\' /proc/meminfo)" '
+            '-gt 3932160')
+        self._reboot_and_poweroff(self.LINUX_PATTERNS)
+
+
+if __name__ == '__main__':
+    QemuSystemTest.main()
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [RFC PATCH 20/20] docs/system/arm: document the Radxa ROCK 5B machine
  2026-11-13  9:47 [RFC PATCH 00/20] hw/arm: Add initial RK3588 and ROCK 5B support Yifan Wang
                   ` (18 preceding siblings ...)
  2026-11-13  9:47 ` [RFC PATCH 19/20] tests/functional: add ROCK 5B boot tests Yifan Wang
@ 2026-11-13  9:47 ` Yifan Wang
  19 siblings, 0 replies; 22+ messages in thread
From: Yifan Wang @ 2026-11-13  9:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: Yifan Wang, qemu-arm, qemu-block, kvm, Peter Maydell,
	Pierrick Bouvier, Paolo Bonzini, Alistair Francis, Kevin Wolf,
	Hanna Reitz, Kuan-Wei Chiu, Marc-André Lureau, bin.meng,
	tangtao1634, Chao Liu

From: Chao Liu <chao.liu@processmission.com>

Document the currently implemented RK3588 SoC and ROCK 5B board,
covering the modeled hardware and the boot commands.

Signed-off-by: Chao Liu <chao.liu@processmission.com>
Signed-off-by: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
---
 MAINTAINERS                 |  1 +
 docs/system/arm/rock-5b.rst | 86 +++++++++++++++++++++++++++++++++++++
 docs/system/target-arm.rst  |  1 +
 3 files changed, 88 insertions(+)
 create mode 100644 docs/system/arm/rock-5b.rst

diff --git a/MAINTAINERS b/MAINTAINERS
index 6303b99755..3adebdcafa 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1074,6 +1074,7 @@ F: hw/timer/rockchip-hptimer.c
 F: include/hw/arm/rk3588.h
 F: include/hw/misc/rk3588-scmci.h
 F: include/hw/timer/rockchip-hptimer.h
+F: docs/system/arm/rock-5b.rst
 F: tests/functional/aarch64/test_rock_5b.py
 
 SABRELITE / i.MX6
diff --git a/docs/system/arm/rock-5b.rst b/docs/system/arm/rock-5b.rst
new file mode 100644
index 0000000000..0de25cdb6d
--- /dev/null
+++ b/docs/system/arm/rock-5b.rst
@@ -0,0 +1,86 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+Radxa ROCK 5B (``rock-5b``)
+===========================
+
+The ``rock-5b`` machine models the Radxa ROCK 5B single-board computer,
+which is built around the Rockchip RK3588 SoC.
+
+Supported devices
+-----------------
+
+The ``rock-5b`` machine supports the following devices:
+
+* 4 Cortex-A55 and 4 Cortex-A76 CPUs
+* GICv3 and the architectural timers
+* On-chip SRAM
+* HPTIMER boot control register (enable bit)
+* UART1 through UART9
+* Rockchip SFC with a 16 MiB SPI NOR flash
+* Clock and reset unit (CRU) registers
+* SCMI Base and Clock protocols over SMC (CPU and DSU clocks)
+* OTP controller
+
+The machine always uses all eight CPUs and supports 128 MiB to 16 GiB
+of RAM, with 2 GiB as the default.
+
+Boot options
+------------
+
+The ``rock-5b`` machine boots U-Boot SPL when ``-bios`` is given and
+Linux directly when ``-kernel`` is given; one of the two is required.
+Both methods start the primary CPU in non-secure EL2 and provide PSCI
+through SMC calls. DRAM is assumed to be initialized;
+BootROM, DDR training firmware and BL31 are not modeled.
+
+U-Boot SPL is supplied as a raw binary with ``-bios``. QEMU loads it
+at ``0x00000000``; SPL loads U-Boot proper from SPI NOR. The device tree
+is taken from the Linux FIT image loaded by U-Boot, so ``-dtb`` cannot be
+used with this method.
+
+Direct Linux boot supplies an AArch64 Linux ``Image`` with ``-kernel``
+and a device tree with ``-dtb``; ``-initrd`` and ``-append`` are optional.
+QEMU does not generate a device tree for this machine.
+
+Running
+-------
+
+The first ``-serial`` option connects to UART2, the debug console on
+the board's header; further ``-serial`` options connect to UART1 and
+UART3 through UART9 in that order.
+
+U-Boot SPL boot
+~~~~~~~~~~~~~~~
+
+With ``u-boot-spl.bin`` and ``spi-nor.img``:
+
+.. code-block:: bash
+
+   $ qemu-system-aarch64 \
+       -machine rock-5b -m 2G -smp 8 \
+       -display none -monitor none -serial stdio \
+       -bios u-boot-spl.bin \
+       -drive if=mtd,index=0,file=spi-nor.img,format=raw
+
+The SPI NOR image must be exactly 16 MiB. Add ``snapshot=on`` to the
+drive option to discard guest writes.
+
+Direct Linux boot
+~~~~~~~~~~~~~~~~~
+
+With ``Image``, ``rootfs.cpio.gz`` and ``rk3588-rock-5b.dtb``:
+
+.. code-block:: bash
+
+   $ qemu-system-aarch64 \
+       -machine rock-5b -m 2G -smp 8 \
+       -display none -monitor none -serial stdio \
+       -kernel Image -initrd rootfs.cpio.gz -dtb rk3588-rock-5b.dtb \
+       -append "console=ttyS2,1500000n8 rdinit=/init"
+
+Limitations
+-----------
+
+The machine is TCG-only; KVM is not supported. Only the devices listed
+above are modeled, and the remaining RK3588 peripherals are unimplemented.
+Migration and VM snapshots are unsupported.
diff --git a/docs/system/target-arm.rst b/docs/system/target-arm.rst
index 260cd7e4d6..f195f74ce2 100644
--- a/docs/system/target-arm.rst
+++ b/docs/system/target-arm.rst
@@ -95,6 +95,7 @@ Board-specific documentation
    arm/mcimx7d-sabre
    arm/imx8m
    arm/orangepi
+   arm/rock-5b
    arm/raspi
    arm/collie
    arm/sx1
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [RFC PATCH 01/20] hw/char/dw8250: implement the UART status register
  2026-11-13  9:47 ` [RFC PATCH 01/20] hw/char/dw8250: implement the UART status register Yifan Wang
@ 2026-11-28 13:17   ` Kuan-Wei Chiu
  0 siblings, 0 replies; 22+ messages in thread
From: Kuan-Wei Chiu @ 2026-11-28 13:17 UTC (permalink / raw)
  To: Yifan Wang
  Cc: qemu-devel, qemu-arm, qemu-block, kvm, Peter Maydell,
	Pierrick Bouvier, Paolo Bonzini, Alistair Francis, Kevin Wolf,
	Hanna Reitz, Marc-André Lureau, bin.meng, tangtao1634,
	Chao Liu

On Fri, Nov 13, 2026 at 05:47:35PM +0800, Yifan Wang wrote:
> From: Chao Liu <chao.liu@processmission.com>
> 
> The Rock 5B machine runs a vendor U-Boot and Linux that read the UART
> status register to check the transmitter and FIFO state. Implement the
> register.
> 
> Signed-off-by: Chao Liu <chao.liu@processmission.com>
> Signed-off-by: Yifan Wang <w-yf22@mails.tsinghua.edu.cn>
> ---
>  hw/char/dw8250.c | 43 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 43 insertions(+)
> 
> diff --git a/hw/char/dw8250.c b/hw/char/dw8250.c
> index 50baeae62c..4f9a8ea989 100644
> --- a/hw/char/dw8250.c
> +++ b/hw/char/dw8250.c
> @@ -6,6 +6,7 @@
>   */
>  
>  #include "qemu/osdep.h"
> +#include "qemu/bitops.h"
>  #include "qemu/log.h"
>  #include "qapi/error.h"
>  #include "hw/char/dw8250.h"
> @@ -14,20 +15,62 @@
>  
>  #define DW_UART_REGION_SIZE 0x100
>  
> +#define DW_UART_USR   (0x7C >> 2) /* UART Status Register */
>  #define DW_UART_RE_EN (0xB4 >> 2) /* Receiver Output Enable Register */
>  #define DW_UART_DLF   (0xC0 >> 2) /* Divisor Latch Fraction Register */
>  #define DW_UART_CPR   (0xF4 >> 2) /* Component Parameter Register */
>  #define DW_UART_UCV   (0xF8 >> 2) /* UART Component Version */
>  #define DW_UART_CTR   (0xFC >> 2) /* Component Type Register */
>  
> +/* UART Status Register bits */
> +#define DW_UART_USR_BUSY BIT(0) /* UART busy */
> +#define DW_UART_USR_TFNF BIT(1) /* Transmit FIFO not full */
> +#define DW_UART_USR_TFE  BIT(2) /* Transmit FIFO empty */
> +#define DW_UART_USR_RFNE BIT(3) /* Receive FIFO not empty */
> +#define DW_UART_USR_RFF  BIT(4) /* Receive FIFO full */
> +
> +/* FIFO Control Register bits */
> +#define DW_UART_FCR_FIFO_EN BIT(0) /* FIFO enable */
> +
> +/* Line Status Register bits */
> +#define DW_UART_LSR_DR   BIT(0) /* Receiver data ready */
> +#define DW_UART_LSR_THRE BIT(5) /* Transmitter holding register empty */
> +#define DW_UART_LSR_TEMT BIT(6) /* Transmitter empty */

Aren't these standard 16550A register bits already defined in
hw/char/serial.c?

Regards,
Kuan-Wei

> +
>  #define DW_UART_UCV_VALUE 0x3332332A /* "323*" -> v3.23a */
>  #define DW_UART_CTR_VALUE 0x44570110 /* "DW" */
>  
>  static uint64_t dw8250_ext_read(void *opaque, hwaddr addr, unsigned int size)
>  {
>      DW8250State *s = opaque;
> +    SerialState *serial = &s->serial_mm.serial;
>  
>      switch (addr >> s->regshift) {
> +    case DW_UART_USR: {
> +        bool fifo_enabled = serial->fcr & DW_UART_FCR_FIFO_EN;
> +        bool thr_empty = serial->lsr & DW_UART_LSR_THRE;
> +        bool tx_idle = serial->lsr & DW_UART_LSR_TEMT;
> +        bool rx_ready = serial->lsr & DW_UART_LSR_DR;
> +        bool tx_empty;
> +        bool tx_full;
> +        bool rx_full;
> +
> +        if (fifo_enabled) {
> +            tx_empty = fifo8_is_empty(&serial->xmit_fifo);
> +            tx_full = fifo8_is_full(&serial->xmit_fifo);
> +            rx_full = fifo8_is_full(&serial->recv_fifo);
> +        } else {
> +            tx_empty = thr_empty;
> +            tx_full = !thr_empty;
> +            rx_full = rx_ready;
> +        }
> +
> +        return (!tx_idle ? DW_UART_USR_BUSY : 0) |
> +               (!tx_full ? DW_UART_USR_TFNF : 0) |
> +               (tx_empty ? DW_UART_USR_TFE : 0) |
> +               (rx_ready ? DW_UART_USR_RFNE : 0) |
> +               (rx_full ? DW_UART_USR_RFF : 0);
> +    }
>      case DW_UART_UCV:
>          return DW_UART_UCV_VALUE;
>      case DW_UART_CPR:
> -- 
> 2.53.0
> 

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2026-11-28 13:17 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13  9:47 [RFC PATCH 00/20] hw/arm: Add initial RK3588 and ROCK 5B support Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 01/20] hw/char/dw8250: implement the UART status register Yifan Wang
2026-11-28 13:17   ` Kuan-Wei Chiu
2026-11-13  9:47 ` [RFC PATCH 02/20] hw/char/dw8250: expose the baudbase property Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 03/20] target/arm: report SMCCC v1.1 support Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 04/20] target/arm: allow machines to handle SMC calls Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 05/20] hw/block/m25p80: add the XTX XT25F128 SPI NOR flash Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 06/20] hw/arm: add the Rockchip RK3588 SoC Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 07/20] hw/timer: add Rockchip HPTIMER boot control Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 08/20] hw/arm/rk3588: add the unimplemented device map Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 09/20] hw/arm/rk3588: add the GICv3 interrupt controller Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 10/20] hw/arm/rk3588: add the UARTs Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 11/20] hw/misc: add the RK3588 clock and reset unit Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 12/20] hw/misc: add the RK3588 OTP controller Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 13/20] hw/ssi: add the Rockchip SPI flash controller Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 14/20] hw/misc: add RK3588 SCMI server Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 15/20] hw/arm/rk3588: wire up the " Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 16/20] hw/arm: add Radxa ROCK 5B board Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 17/20] hw/arm/rock-5b: connect the XTX XT25F128 SPI NOR flash Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 18/20] hw/arm/rock-5b: add firmware booting Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 19/20] tests/functional: add ROCK 5B boot tests Yifan Wang
2026-11-13  9:47 ` [RFC PATCH 20/20] docs/system/arm: document the Radxa ROCK 5B machine Yifan Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox