Skip to contentSkip to conversation

hw/arm: Add initial RK3588 and ROCK 5B support

PATCH New Yifan Wang 1 participant 21 messages Nov 28

Subsystems (3)
lore
Share & tools
lore

Yifan Wang

author
#0 lore raw

v2 cover hw/arm: Add initial RK3588 and ROCK 5B support

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

Changes in v2:
- Reuse the common UART LSR/FCR definitions in patch 1, as suggested by Kuan-Wei Chiu.
- Rebase onto upstream master at 9751c6235807.

v1:
https://www.mail-archive.com/[email protected]/msg1243890.html

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                         |  37 ++
 hw/char/serial.c                         |  21 -
 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/char/serial.h                 |  25 +
 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 +++++
 30 files changed, 2853 insertions(+), 21 deletions(-)
 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: 9751c62358073580cbf330a4df22077a7c6a407c

Signature · 1 line
2.53.0
author
#1 lore raw

PATCH v2 1/20 hw/char/dw8250: implement the UART status register

From: Chao Liu <[email protected]>

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.

---
 hw/char/dw8250.c         | 35 +++++++++++++++++++++++++++++++++++
 hw/char/serial.c         | 21 ---------------------
 include/hw/char/serial.h | 25 +++++++++++++++++++++++++
 3 files changed, 60 insertions(+), 21 deletions(-)
hw/char/dw8250.c +35 -0
index 50baeae62c..80ace7f7a7 100644
@@ -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,54 @@
 
 #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 */
+
 #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 & UART_FCR_FE;
+        bool thr_empty = serial->lsr & UART_LSR_THRE;
+        bool tx_idle = serial->lsr & UART_LSR_TEMT;
+        bool rx_ready = serial->lsr & 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:
hw/char/serial.c +0 -21
index fefd2cf9fc..0a9821945c 100644
@@ -84,27 +84,6 @@
 #define UART_MSR_DCTS       0x01    /* Delta CTS */
 #define UART_MSR_ANY_DELTA  0x0F    /* Any of the delta bits! */
 
-#define UART_LSR_TEMT       0x40    /* Transmitter empty */
-#define UART_LSR_THRE       0x20    /* Transmit-hold-register empty */
-#define UART_LSR_BI         0x10    /* Break interrupt indicator */
-#define UART_LSR_FE         0x08    /* Frame error indicator */
-#define UART_LSR_PE         0x04    /* Parity error indicator */
-#define UART_LSR_OE         0x02    /* Overrun error indicator */
-#define UART_LSR_DR         0x01    /* Receiver data ready */
-#define UART_LSR_INT_ANY    0x1E    /* Any of the lsr-interrupt-triggering status bits */
-
-/* Interrupt trigger levels. The byte-counts are for 16550A - in newer UARTs the byte-count for each ITL is higher. */
-
-#define UART_FCR_ITL_1      0x00 /* 1 byte ITL */
-#define UART_FCR_ITL_2      0x40 /* 4 bytes ITL */
-#define UART_FCR_ITL_3      0x80 /* 8 bytes ITL */
-#define UART_FCR_ITL_4      0xC0 /* 14 bytes ITL */
-
-#define UART_FCR_DMS        0x08    /* DMA Mode Select */
-#define UART_FCR_XFR        0x04    /* XMIT Fifo Reset */
-#define UART_FCR_RFR        0x02    /* RCVR Fifo Reset */
-#define UART_FCR_FE         0x01    /* FIFO Enable */
-
 #define MAX_XMIT_RETRY      4
 
 static void serial_receive1(void *opaque, const uint8_t *buf, int size);
include/hw/char/serial.h +25 -0
index ea82ffac47..6bb6dad980 100644
@@ -34,6 +34,31 @@
 
 #define UART_FIFO_LENGTH    16      /* 16550A Fifo Length */
 
+#define UART_LSR_TEMT       0x40    /* Transmitter empty */
+#define UART_LSR_THRE       0x20    /* Transmit-hold-register empty */
+#define UART_LSR_BI         0x10    /* Break interrupt indicator */
+#define UART_LSR_FE         0x08    /* Frame error indicator */
+#define UART_LSR_PE         0x04    /* Parity error indicator */
+#define UART_LSR_OE         0x02    /* Overrun error indicator */
+#define UART_LSR_DR         0x01    /* Receiver data ready */
+/* Any of the lsr-interrupt-triggering status bits */
+#define UART_LSR_INT_ANY    0x1E
+
+/*
+ * Interrupt trigger levels. The byte-counts are for 16550A - in newer UARTs
+ * the byte-count for each ITL is higher.
+ */
+
+#define UART_FCR_ITL_1      0x00 /* 1 byte ITL */
+#define UART_FCR_ITL_2      0x40 /* 4 bytes ITL */
+#define UART_FCR_ITL_3      0x80 /* 8 bytes ITL */
+#define UART_FCR_ITL_4      0xC0 /* 14 bytes ITL */
+
+#define UART_FCR_DMS        0x08    /* DMA Mode Select */
+#define UART_FCR_XFR        0x04    /* XMIT Fifo Reset */
+#define UART_FCR_RFR        0x02    /* RCVR Fifo Reset */
+#define UART_FCR_FE         0x01    /* FIFO Enable */
+
 struct SerialState {
     DeviceState parent;
 
Signature · 1 line
2.53.0
author
#2 lore raw

PATCH v2 2/20 hw/char/dw8250: expose the baudbase property

In reply to Yifan Wang

From: Chao Liu <[email protected]>

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.

---
 hw/char/dw8250.c | 2 ++
 1 file changed, 2 insertions(+)
hw/char/dw8250.c +2 -0
index 80ace7f7a7..a888ab207a 100644
@@ -109,6 +109,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)
Signature · 1 line
2.53.0
author
#3 lore raw

PATCH v2 3/20 target/arm: report SMCCC v1.1 support

In reply to Yifan Wang

From: Chao Liu <[email protected]>

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.

---
 target/arm/kvm-consts.h |  5 +++++
 target/arm/tcg/psci.c   | 15 +++++++++++++++
 2 files changed, 20 insertions(+)
target/arm/kvm-consts.h +5 -0
index 9fba3e886d..ab64c91888 100644
@@ -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 */
target/arm/tcg/psci.c +15 -0
index d8e01df762..81ca2fbb44 100644
@@ -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:
Signature · 1 line
2.53.0
author
#4 lore raw

PATCH v2 4/20 target/arm: allow machines to handle SMC calls

In reply to Yifan Wang

From: Chao Liu <[email protected]>

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.

---
 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
MAINTAINERS +1 -0
index 9e001a85ee..037c93cba5 100644
@@ -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
include/hw/arm/arm-smc.h new file +31 -0
new file mode 100644
index 0000000000..e27d64218f
@@ -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 */
target/arm/helper.c +80 -0

98 lines not on this page · raw message

target/arm/internals.h +3 -0
index 033d6d66da..4c6825b201 100644
@@ -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
Signature · 1 line
2.53.0
author
#5 lore raw

PATCH v2 5/20 hw/block/m25p80: add the XTX XT25F128 SPI NOR flash

In reply to Yifan Wang

From: Chao Liu <[email protected]>

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.

---
 hw/block/m25p80.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
hw/block/m25p80.c +20 -0
index 92e67fdc5e..b14375e834 100644
@@ -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:
@@ -1086,6 +1095,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:
@@ -1124,6 +1134,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:
@@ -1160,6 +1171,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;
@@ -1338,6 +1350,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;
@@ -1364,6 +1377,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;
@@ -1543,6 +1557,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;
@@ -1602,6 +1617,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;
Signature · 1 line
2.53.0
author
#6 lore raw

PATCH v2 6/20 hw/arm: add the Rockchip RK3588 SoC

In reply to Yifan Wang

From: Chao Liu <[email protected]>

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

---
 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
MAINTAINERS +8 -0
index 037c93cba5..ee7258829d 100644
@@ -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 <[email protected]>
+M: Yifan Wang <[email protected]>
+L: [email protected]
+S: Maintained
+F: hw/arm/rk3588.c
+F: include/hw/arm/rk3588.h
+
 SABRELITE / i.MX6
 M: Peter Maydell <[email protected]>
 R: Jean-Christophe Dubois <[email protected]>
hw/arm/Kconfig +4 -0
index e9f796f718..79b66de041 100644
@@ -774,3 +774,7 @@ config AXIADO_EVK
     default y
     depends on TCG && ARM
     select AXIADO_SOC
+
+config RK3588
+    bool
+    select CPU_CLUSTER
hw/arm/meson.build +2 -0
index f3c1b0e00f..70c835814f 100644
@@ -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}
hw/arm/rk3588.c new file +149 -0

149 lines not on this page · raw message

include/hw/arm/rk3588.h new file +51 -0

51 lines not on this page · raw message

Signature · 1 line
2.53.0
author
#7 lore raw

PATCH v2 7/20 hw/timer: add Rockchip HPTIMER boot control

In reply to Yifan Wang

From: Chao Liu <[email protected]>

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.

---
 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
MAINTAINERS +2 -0
index ee7258829d..a4697719c7 100644
@@ -1065,7 +1065,9 @@ M: Yifan Wang <[email protected]>
 L: [email protected]
 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 <[email protected]>
hw/arm/rk3588.c +23 -0
index 1e6f44433c..8255aee7fc 100644
@@ -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[] = {
hw/timer/meson.build +1 -0
index e2bcdbdf65..5375f26b47 100644
@@ -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'))
hw/timer/rockchip-hptimer.c new file +115 -0

115 lines not on this page · raw message

include/hw/arm/rk3588.h +2 -0
index 450af3d282..8539d2e64d 100644
@@ -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 */
include/hw/timer/rockchip-hptimer.h new file +20 -0
new file mode 100644
index 0000000000..2e9f5fd819
@@ -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 */
Signature · 1 line
2.53.0
author
#8 lore raw

PATCH v2 8/20 hw/arm/rk3588: add the unimplemented device map

In reply to Yifan Wang

From: Chao Liu <[email protected]>

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.

---
 hw/arm/Kconfig  |  1 +
 hw/arm/rk3588.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+)
hw/arm/Kconfig +1 -0
index 79b66de041..55fdc78364 100644
@@ -778,3 +778,4 @@ config AXIADO_EVK
 config RK3588
     bool
     select CPU_CLUSTER
+    select UNIMP
hw/arm/rk3588.c +68 -0

86 lines not on this page · raw message

Signature · 1 line
2.53.0
author
#9 lore raw

PATCH v2 9/20 hw/arm/rk3588: add the GICv3 interrupt controller

In reply to Yifan Wang

From: Chao Liu <[email protected]>

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

---
 hw/arm/Kconfig          |  1 +
 hw/arm/rk3588.c         | 86 +++++++++++++++++++++++++++++++++++++++--
 include/hw/arm/rk3588.h |  2 +
 3 files changed, 86 insertions(+), 3 deletions(-)
hw/arm/Kconfig +1 -0
index 55fdc78364..73e1154040 100644
@@ -777,5 +777,6 @@ config AXIADO_EVK
 
 config RK3588
     bool
+    select ARM_GIC
     select CPU_CLUSTER
     select UNIMP
hw/arm/rk3588.c +83 -3

130 lines not on this page · raw message

include/hw/arm/rk3588.h +2 -0
index 8539d2e64d..fcb9ef5964 100644
@@ -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;
Signature · 1 line
2.53.0
author
#10 lore raw

PATCH v2 10/20 hw/arm/rk3588: add the UARTs

In reply to Yifan Wang

From: Chao Liu <[email protected]>

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.

---
 hw/arm/Kconfig          |  1 +
 hw/arm/rk3588.c         | 69 +++++++++++++++++++++++++++++++++++------
 include/hw/arm/rk3588.h |  5 +++
 3 files changed, 66 insertions(+), 9 deletions(-)
hw/arm/Kconfig +1 -0
index 73e1154040..b22d0ce4f6 100644
@@ -779,4 +779,5 @@ config RK3588
     bool
     select ARM_GIC
     select CPU_CLUSTER
+    select DW8250
     select UNIMP
hw/arm/rk3588.c +60 -9

108 lines not on this page · raw message

include/hw/arm/rk3588.h +5 -0
index fcb9ef5964..61fa616795 100644
@@ -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;
Signature · 1 line
2.53.0
author
#11 lore raw

PATCH v2 11/20 hw/misc: add the RK3588 clock and reset unit

In reply to Yifan Wang

From: Chao Liu <[email protected]>

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.

---
 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
MAINTAINERS +1 -0
index a4697719c7..32a8c71821 100644
@@ -1065,6 +1065,7 @@ M: Yifan Wang <[email protected]>
 L: [email protected]
 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
hw/arm/Kconfig +1 -0
index b22d0ce4f6..902c4ba377 100644
@@ -780,4 +780,5 @@ config RK3588
     select ARM_GIC
     select CPU_CLUSTER
     select DW8250
+    select REGISTER
     select UNIMP
hw/arm/rk3588.c +23 -10
index 3dbd579806..6e7cafea1c 100644
@@ -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));
hw/misc/meson.build +2 -0
index 7a071af82b..374af9331b 100644
@@ -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'))
hw/misc/rockchip_cru.c new file +233 -0

233 lines not on this page · raw message

include/hw/arm/rk3588.h +1 -0
index 61fa616795..18c66b6bae 100644
@@ -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;
Signature · 1 line
2.53.0
author
#12 lore raw

PATCH v2 12/20 hw/misc: add the RK3588 OTP controller

In reply to Yifan Wang

From: Chao Liu <[email protected]>

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.

---
 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
MAINTAINERS +1 -0
index 32a8c71821..bcbaa090e8 100644
@@ -1066,6 +1066,7 @@ L: [email protected]
 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
hw/arm/rk3588.c +22 -1
index 6e7cafea1c..acd9149933 100644
@@ -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));
hw/misc/meson.build +3 -1
index 374af9331b..51c09b056e 100644
@@ -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'))
hw/misc/rockchip_otp.c new file +146 -0

146 lines not on this page · raw message

include/hw/arm/rk3588.h +1 -0
index 18c66b6bae..1f854043de 100644
@@ -53,6 +53,7 @@ struct RK3588SoCState {
     GICv3State gic;
     DW8250State uart[RK3588_NUM_UARTS];
     DeviceState *cru;
+    DeviceState *otp;
     MemoryRegion *memory;
     MemoryRegion sram;
     DeviceState *hptimer;
Signature · 1 line
2.53.0
author
#13 lore raw

PATCH v2 13/20 hw/ssi: add the Rockchip SPI flash controller

In reply to Yifan Wang

From: Chao Liu <[email protected]>

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.

---
 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
MAINTAINERS +1 -0
index bcbaa090e8..200d827112 100644
@@ -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
hw/arm/Kconfig +1 -0
index 902c4ba377..eaa55eae29 100644
@@ -781,4 +781,5 @@ config RK3588
     select CPU_CLUSTER
     select DW8250
     select REGISTER
+    select ROCKCHIP_SFC
     select UNIMP
hw/arm/rk3588.c +27 -2
index acd9149933..2319c54c76 100644
@@ -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));
hw/ssi/Kconfig +5 -0
index d477d20e9b..5735b422c9 100644
@@ -36,3 +36,8 @@ config ALLWINNER_A10_SPI
 config IMX_SPI
     bool
     select SSI
+
+config ROCKCHIP_SFC
+    bool
+    select REGISTER
+    select SSI
hw/ssi/meson.build +1 -0
index f334e48e2f..701ae09ed2 100644
@@ -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'))
hw/ssi/rockchip_sfc.c new file +439 -0

439 lines not on this page · raw message

include/hw/arm/rk3588.h +1 -0
index 1f854043de..1304c11598 100644
@@ -54,6 +54,7 @@ struct RK3588SoCState {
     DW8250State uart[RK3588_NUM_UARTS];
     DeviceState *cru;
     DeviceState *otp;
+    DeviceState *sfc;
     MemoryRegion *memory;
     MemoryRegion sram;
     DeviceState *hptimer;
Signature · 1 line
2.53.0
author
#14 lore raw

PATCH v2 14/20 hw/misc: add RK3588 SCMI server

In reply to Yifan Wang

From: Chao Liu <[email protected]>

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.

---
 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
MAINTAINERS +2 -0
index 200d827112..f0dac01ebd 100644
@@ -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
hw/misc/meson.build +1 -0
index 51c09b056e..8f13f5da77 100644
@@ -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'))
 
hw/misc/rk3588-scmci.c new file +589 -0

589 lines not on this page · raw message

include/hw/misc/rk3588-scmci.h new file +25 -0
new file mode 100644
index 0000000000..4a00f621d4
@@ -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 */
Signature · 1 line
2.53.0
author
#15 lore raw

PATCH v2 15/20 hw/arm/rk3588: wire up the SCMI server

In reply to Yifan Wang

From: Chao Liu <[email protected]>

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.

---
 hw/arm/rk3588.c         | 22 ++++++++++++++++++++++
 include/hw/arm/rk3588.h |  1 +
 2 files changed, 23 insertions(+)
hw/arm/rk3588.c +22 -0
index 2319c54c76..f4ebb59d36 100644
@@ -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));
include/hw/arm/rk3588.h +1 -0
index 1304c11598..f85242f464 100644
@@ -55,6 +55,7 @@ struct RK3588SoCState {
     DeviceState *cru;
     DeviceState *otp;
     DeviceState *sfc;
+    DeviceState *scmi;
     MemoryRegion *memory;
     MemoryRegion sram;
     DeviceState *hptimer;
Signature · 1 line
2.53.0
author
#16 lore raw

PATCH v2 16/20 hw/arm: add Radxa ROCK 5B board

In reply to Yifan Wang

From: Chao Liu <[email protected]>

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.

---
 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
MAINTAINERS +1 -0
index f0dac01ebd..e5360538ec 100644
@@ -1065,6 +1065,7 @@ M: Yifan Wang <[email protected]>
 L: [email protected]
 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
hw/arm/Kconfig +6 -0
index eaa55eae29..40f7de823c 100644
@@ -783,3 +783,9 @@ config RK3588
     select REGISTER
     select ROCKCHIP_SFC
     select UNIMP
+
+config ROCK5B
+    bool
+    default y
+    depends on TCG && AARCH64
+    select RK3588
hw/arm/meson.build +1 -0
index 70c835814f..9af1e01037 100644
@@ -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}
hw/arm/rock-5b.c new file +200 -0

200 lines not on this page · raw message

Signature · 1 line
2.53.0
author
#17 lore raw

PATCH v2 17/20 hw/arm/rock-5b: connect the XTX XT25F128 SPI NOR flash

In reply to Yifan Wang

From: Chao Liu <[email protected]>

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.

---
 hw/arm/Kconfig   |  1 +
 hw/arm/rock-5b.c | 29 +++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)
hw/arm/Kconfig +1 -0
index 40f7de823c..01ae699fee 100644
@@ -789,3 +789,4 @@ config ROCK5B
     default y
     depends on TCG && AARCH64
     select RK3588
+    select SSI_M25P80
hw/arm/rock-5b.c +29 -0
index 7906d53175..abc898c50c 100644
@@ -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);
 }
 
Signature · 1 line
2.53.0
author
#18 lore raw

PATCH v2 18/20 hw/arm/rock-5b: add firmware booting

In reply to Yifan Wang

From: Chao Liu <[email protected]>

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.

---
 hw/arm/rock-5b.c | 98 ++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 83 insertions(+), 15 deletions(-)
hw/arm/rock-5b.c +83 -15
index abc898c50c..c097e17c5c 100644
@@ -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)
Signature · 1 line
2.53.0
author
#19 lore raw

PATCH v2 19/20 tests/functional: add ROCK 5B boot tests

In reply to Yifan Wang

From: Chao Liu <[email protected]>

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

---
 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
MAINTAINERS +1 -0
index e5360538ec..c0b8723c1d 100644
@@ -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 <[email protected]>
tests/functional/aarch64/meson.build +2 -0
index f0881bed16..d6b79314e6 100644
@@ -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',
tests/functional/aarch64/test_rock_5b.py new file +118 -0

118 lines not on this page · raw message

Signature · 1 line
2.53.0
author
#20 lore raw

PATCH v2 20/20 docs/system/arm: document the Radxa ROCK 5B machine

In reply to Yifan Wang

From: Chao Liu <[email protected]>

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

---
 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
MAINTAINERS +1 -0
index c0b8723c1d..e3a60f5fe5 100644
@@ -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
docs/system/arm/rock-5b.rst new file +86 -0

86 lines not on this page · raw message

docs/system/target-arm.rst +1 -0
index 260cd7e4d6..f195f74ce2 100644
@@ -95,6 +95,7 @@ Board-specific documentation
    arm/mcimx7d-sabre
    arm/imx8m
    arm/orangepi
+   arm/rock-5b
    arm/raspi
    arm/collie
    arm/sx1
Signature · 1 line
2.53.0