[PATCH v2] hw/riscv/k230: add k230_sram_create() helper function
Jian Cai <[email protected]> Tue, 21 Jul 2026 14:04:07 +0800
| Newsgroups | org.nongnu.qemu-riscv,org.nongnu.qemu-devel |
|---|---|
| Message-ID | <[email protected]> |
The K230 shared SRAM (2 MB at 0x80200000) has no software-visible controller registers: it is a pure on-chip RAM block accessed via the AXI bus. Replace the inline memory_region_init_ram calls in k230_soc_realize() with a static k230_sram_create() helper, which follows the same pattern as the existing k230_create_plic() and k230_create_uart() helpers. Also fix two non-ASCII characters (registered sign and em-dash) in k230.rst that would cause git send-email to reject the patch as 8-bit. Reference: K230 TRM V0.3.1 (2024-11-18), Section 5.2 Sram https://github.com/revyos/external-docs/blob/master/K230/en-us/ K230_Technical_Reference_Manual_V0.3.1_20241118.pdf Signed-off-by: Jian Cai <[email protected]> --- Changes in v2: - Dropped SysBusDevice model per Chao Liu's review; use a static helper function k230_sram_create() in k230.c instead. - Removed k230_sram.c, k230_sram.h, and k230-sram-test.c. - Fixed two non-ASCII characters (registered sign, em-dash) in k230.rst. - Removed SRAM entries from MAINTAINERS (no new files added). - v1: [RFC PATCH 0/3] hw/riscv: add K230 SRAM device model https://lore.kernel.org/qemu-devel/ docs/system/riscv/k230.rst | 3 ++- hw/riscv/k230.c | 14 ++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/docs/system/riscv/k230.rst b/docs/system/riscv/k230.rst index cea8202e55..18eb6806f6 100644 --- a/docs/system/riscv/k230.rst +++ b/docs/system/riscv/k230.rst @@ -2,7 +2,7 @@ Kendryte K230 virt reference platform (``k230``) ========================================================================== The ``k230`` machine is compatible with the Kendryte K230 SDK. -The K230 is a chip from the AIoT SoC series made by Kendryte ® — a part of +The K230 is a chip from the AIoT SoC series made by Kendryte (R) -- a part of Canaan Inc. It uses a brand-new multi-heterogeneous unit accelerated computing structure. @@ -111,3 +111,4 @@ this machine does not emulate those controllers yet. Replace ``${INITRD_END}`` with the host-calculated value above when typing the command. ``cma=0`` avoids the SDK kernel reserving too much of the little-core memory window for initramfs boot. + diff --git a/hw/riscv/k230.c b/hw/riscv/k230.c index 656f28190c..96add64c2a 100644 --- a/hw/riscv/k230.c +++ b/hw/riscv/k230.c @@ -14,6 +14,7 @@ */ #include "qemu/osdep.h" +#include "qemu/units.h" #include "cpu-qom.h" #include "qemu/cutils.h" #include "qemu/error-report.h" @@ -151,6 +152,14 @@ static void k230_create_uart(MemoryRegion *sys_mem, DeviceState *plic, 399193, serial_hd(index), DEVICE_LITTLE_ENDIAN); } +static void k230_sram_create(K230SoCState *s) +{ + memory_region_init_ram(&s->sram, OBJECT(s), "k230.sram", + memmap[K230_DEV_SRAM].size, &error_fatal); + memory_region_add_subregion(get_system_memory(), + memmap[K230_DEV_SRAM].base, &s->sram); +} + static void k230_soc_realize(DeviceState *dev, Error **errp) { K230SoCState *s = RISCV_K230_SOC(dev); @@ -162,10 +171,7 @@ static void k230_soc_realize(DeviceState *dev, Error **errp) c908_cpus = s->c908_cpu.num_harts; /* SRAM */ - memory_region_init_ram(&s->sram, OBJECT(dev), "sram", - memmap[K230_DEV_SRAM].size, &error_fatal); - memory_region_add_subregion(sys_mem, memmap[K230_DEV_SRAM].base, - &s->sram); + k230_sram_create(s); /* BootROM */ memory_region_init_rom(&s->bootrom, OBJECT(dev), "bootrom", -- 2.43.0