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.
Signed-off-by: Chao Liu <[email protected]> Signed-off-by: Yifan Wang <[email protected]> --- 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 <[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]> 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 <[email protected]> + * + * 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 <[email protected]> + * + * 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
