hw/riscv/k230: add IOMUX register block model
Subsystems (2)
v3 cover hw/riscv/k230: add IOMUX register block model
Add a SysBus model for the 64 K230 Function IO configuration registers documented by the K230 Technical Reference Manual. The model retains the writable configuration fields needed by the SDK U-Boot and Linux read-modify-write paths.
The series adds the device model, wires it into the K230 SoC at 0x91105000, and adds qtest coverage.
Changes in v3:
- Migrated the model from the deprecated device_class_set_legacy_reset() to the Resettable interface.
- Added a comment to the model stating that bit 31 (DI) is read-only and reads as zero, since the model does not simulate external pin input (TRM V0.3.1, section 12.9.2.2).
- Added MAINTAINERS entries for the model and the qtest.
- Defined an independent K230_IOMUX_EXPECTED_WRITABLE_MASK (0x00003fff) in the test instead of reusing the implementation mask, with a comment explaining the bit layout.
Changes in v2:
- Split the device model, SoC wiring, and qtest coverage into separate patches.
- Removed redundant MMIO bounds, access-size, and alignment checks.
- Limited register storage to the 64 documented Function IO registers.
- Applied the documented 0x00003fff writable mask.
- Treated offsets 0x100 through 0x7ff as reserved.
- Added tests for write masking, read-modify-write accesses, IO63, reserved offsets, and system reset.
Tested with:
- qtest-riscv64/k230-iomux-test
- U-Boot and Linux boot tests with no unimplemented-device warnings for the IOMUX region
Thanks to Alistair Francis and Chao Liu for the v1 review comments that shaped the v2 series structure and the register semantics.
v2:
https://lore.kernel.org/qemu-devel/[email protected]/
v1:
https://lore.kernel.org/qemu-devel/[email protected]/
Kangjie Huang (3):
hw/misc/k230_iomux: add Kendryte K230 IOMUX model hw/riscv/k230: wire up the IOMUX device tests/qtest: add test for K230 IOMUX
MAINTAINERS | 3 + docs/system/riscv/k230.rst | 1 + hw/misc/Kconfig | 3 + hw/misc/k230_iomux.c | 125 ++++++++++++++++++++++++++ hw/misc/meson.build | 1 + hw/misc/trace-events | 4 + hw/riscv/Kconfig | 1 + hw/riscv/k230.c | 11 ++- include/hw/misc/k230_iomux.h | 43 +++++++++ include/hw/riscv/k230.h | 2 + tests/qtest/k230-iomux-test.c | 160 ++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 5 +- 12 files changed, 355 insertions(+), 4 deletions(-) create mode 100644 hw/misc/k230_iomux.c create mode 100644 include/hw/misc/k230_iomux.h create mode 100644 tests/qtest/k230-iomux-test.c
base-commit: d49f87606ac1a6e15701b26c1b16c5d7e948ffcb
Signature · 1 line
2.43.0
PATCH v3 1/3 hw/misc/k230_iomux: add Kendryte K230 IOMUX model
Add a SysBus model for the 64 K230 Function IO configuration registers documented by the K230 Technical Reference Manual.
Preserve the writable configuration fields across aligned 32-bit accesses, apply the documented reset values, and ignore writes to read-only and reserved fields. Offsets outside the documented register list read as zero and ignore writes.
This provides the register behavior used by the Kendryte SDK U-Boot pinctrl-single driver and Linux IOMUX configuration code.
--- MAINTAINERS | 2 + hw/misc/Kconfig | 3 + hw/misc/k230_iomux.c | 125 +++++++++++++++++++++++++++++++++++ hw/misc/meson.build | 1 + hw/misc/trace-events | 4 ++ include/hw/misc/k230_iomux.h | 43 ++++++++++++ 6 files changed, 178 insertions(+) create mode 100644 hw/misc/k230_iomux.c create mode 100644 include/hw/misc/k230_iomux.h
MAINTAINERS +2 -0
@@ -1845,8 +1845,10 @@ S: Maintained F: docs/system/riscv/k230.rst F: hw/riscv/k230.c F: hw/watchdog/k230_wdt.c +F: hw/misc/k230_iomux.c F: include/hw/riscv/k230.h F: include/hw/watchdog/k230_wdt.h +F: include/hw/misc/k230_iomux.h F: tests/functional/riscv64/test_k230.py F: tests/qtest/k230-wdt-test.c
hw/misc/Kconfig +3 -0
@@ -260,4 +260,7 @@ config XLNX_ZYNQ_DDRC config AXIADO_CLK bool +config K230_IOMUX + bool + source macio/Kconfig
hw/misc/k230_iomux.c new file +125 -0
125 lines not on this page · raw message
hw/misc/meson.build +1 -0
@@ -171,3 +171,4 @@ system_ss.add(when: 'CONFIG_SBSA_REF', if_true: files('sbsa_ec.c')) system_ss.add(when: 'CONFIG_LASI', if_true: files('lasi.c')) system_ss.add(when: 'CONFIG_AXIADO_CLK', if_true: files('axiado_clk.c')) +system_ss.add(when: 'CONFIG_K230_IOMUX', if_true: files('k230_iomux.c'))
hw/misc/trace-events +4 -0
@@ -405,6 +405,10 @@ djmemc_write(int reg, uint64_t value, unsigned int size) "reg=0x%x value=0x%"PRI iosb_read(int reg, uint64_t value, unsigned int size) "reg=0x%x value=0x%"PRIx64" size=%u" iosb_write(int reg, uint64_t value, unsigned int size) "reg=0x%x value=0x%"PRIx64" size=%u" +# k230_iomux.c +k230_iomux_read(uint64_t offset, uint32_t value) "offset=0x%" PRIx64 " value=0x%" PRIx32 +k230_iomux_write(uint64_t offset, uint64_t value) "offset=0x%" PRIx64 " value=0x%" PRIx64 + # aspeed_sli.c aspeed_sli_write(uint64_t offset, unsigned int size, uint32_t data) "To 0x%" PRIx64 " of size %u: 0x%" PRIx32 aspeed_sli_read(uint64_t offset, unsigned int size, uint32_t data) "To 0x%" PRIx64 " of size %u: 0x%" PRIx32
include/hw/misc/k230_iomux.h new file +43 -0
43 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v3 1/3] hw/misc/k230_iomux: add Kendryte K230 IOMUX model
Hi all
Quoted 3 lines · Kangjie Huang <[email protected]> 于2026年8月13日周四 21:58写道:
Add a SysBus model for the 64 K230 Function IO configuration registers documented by the K230 Technical Reference Manual.
......
Quoted 4 lines
Suggested-by Alistair Francis <[email protected]>Suggested-by Chao Liu <[email protected]>Suggested-by Junze Cao <[email protected]>Signed-off-by Kangjie Huang <[email protected]>
Hi all,
Just to clarify, I added the Suggested-by tags for Alistair Francis and Junze Cao in this patch just based on their concrete suggestions during the public review. Neither tag was explicitly provided by them. Sorry for any confusion this may have caused.
Thank you again for your suggestions.
Best regards,
Kangjie
Re: [PATCH v3 1/3] hw/misc/k230_iomux: add Kendryte K230 IOMUX model
Quoted 10 lines · Kangjie Huang
Hi all
Quoted 3 lines · Kangjie Huang <[email protected]> 于2026年8月13日周四 21:58写道:
Add a SysBus model for the 64 K230 Function IO configuration registers documented by the K230 Technical Reference Manual.
......
Quoted 4 lines
Suggested-by Alistair Francis <[email protected]>Suggested-by Chao Liu <[email protected]>Suggested-by Junze Cao <[email protected]>Signed-off-by Kangjie Huang <[email protected]>
Quoted 8 lines
Hi all,
Just to clarify, I added the Suggested-by tags for Alistair Francis and
Junze Cao in this patch just based on their concrete suggestions during the
public review. Neither tag was explicitly provided by them. Sorry for any confusion this may have caused.
Please don't add Suggested-by tags just for review comments. Generally you would only add Suggested-by for new patches where the idea was largely contributed by someone
Alistair
Quoted 4 lines
Thank you again for your suggestions.
Best regards,
Kangjie
Re: [PATCH v3 1/3] hw/misc/k230_iomux: add Kendryte K230 IOMUX model
Quoted 4 lines · Alistair <[email protected]> 于2026年8月14日周五 23:09写道:
Please don't add Suggested-by tags just for review comments. Generally you would only add Suggested-by for new patches where the idea was largely contributed by someone
Hi Alistair,
I Understood, Thank you very much. I will not add Suggested-by tags based only on review comments.
Best regards,
Kangjie
PATCH v3 2/3 hw/riscv/k230: wire up the IOMUX device
In reply to Kangjie HuangInstantiate the K230 IOMUX device and map its MMIO region at 0x91105000, replacing the unimplemented device covering the same SoC address window.
Select the model from the K230 machine configuration and document the newly modeled device.
--- docs/system/riscv/k230.rst | 1 + hw/riscv/Kconfig | 1 + hw/riscv/k230.c | 11 ++++++++--- include/hw/riscv/k230.h | 2 ++ 4 files changed, 12 insertions(+), 3 deletions(-)
docs/system/riscv/k230.rst +1 -0
@@ -20,6 +20,7 @@ The ``k230`` machine supports the following devices: * Platform-Level Interrupt Controller (PLIC) * 2 K230 Watchdog Timer * 5 UART +* K230 IOMUX register block Boot options ------------
hw/riscv/Kconfig +1 -0
@@ -162,3 +162,4 @@ config K230 select SERIAL_MM select UNIMP select K230_WDT + select K230_IOMUX
hw/riscv/k230.c +8 -3
@@ -110,6 +110,7 @@ static void k230_soc_init(Object *obj)object_initialize_child (obj,"c908-cpu" , cpu0,TYPE_RISCV_HART_ARRAY );object_initialize_child (obj,"k230-wdt0" , &s->wdt[0 ],TYPE_K230_WDT );object_initialize_child (obj,"k230-wdt1" , &s->wdt[1 ],TYPE_K230_WDT ); +object_initialize_child (obj,"k230-iomux" , &s->iomux,TYPE_K230_IOMUX );qdev_prop_set_uint32 (DEVICE (cpu0),"hartid-base" ,0 );qdev_prop_set_string (DEVICE (cpu0),"cpu-type" ,TYPE_RISCV_CPU_THEAD_C908 );
@@ -198,6 +199,11 @@ static void k230_soc_realize(DeviceState *dev, Error **errp) } } +/* IOMUX */ +if (!sysbus_realize (SYS_BUS_DEVICE (&s->iomux), errp)) { +return ; + } +sysbus_mmio_map (SYS_BUS_DEVICE (&s->wdt[0 ]),0 , memmap[K230_DEV_WDT0 ].base);sysbus_connect_irq (SYS_BUS_DEVICE (&s->wdt[0 ]),0 ,qdev_get_gpio_in (DEVICE (s->c908_plic),K230_WDT0_IRQ ));
@@ -206,6 +212,8 @@ static void k230_soc_realize(DeviceState *dev, Error **errp)sysbus_connect_irq (SYS_BUS_DEVICE (&s->wdt[1 ]),0 ,qdev_get_gpio_in (DEVICE (s->c908_plic),K230_WDT1_IRQ )); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->iomux),0 , memmap[K230_DEV_IOMUX ].base); +/* unimplemented devices */ create_unimplemented_device("kpu.l2-cache", memmap[K230_DEV_KPU_L2_CACHE].base,
@@ -280,9 +288,6 @@ static void k230_soc_realize(DeviceState *dev, Error **errp)create_unimplemented_device ("ipcm" , memmap[K230_DEV_MAILBOX ].base, memmap[K230_DEV_MAILBOX ].size); -create_unimplemented_device ("iomux" , memmap[K230_DEV_IOMUX ].base, - memmap[K230_DEV_IOMUX ].size); -create_unimplemented_device ("timer" , memmap[K230_DEV_TIMER ].base, memmap[K230_DEV_TIMER ].size);
include/hw/riscv/k230.h +2 -0
@@ -18,6 +18,7 @@#include "hw/core/boards.h" #include "hw/riscv/riscv_hart.h" #include "hw/watchdog/k230_wdt.h" +#include "hw/misc/k230_iomux.h" #define C908_CPU_HARTID (0)
@@ -33,6 +34,7 @@ typedef struct K230SoCState {RISCVHartArrayState c908_cpu;/* Small core */ K230WdtState wdt[2 ]; +K230IomuxState iomux;MemoryRegion sram;MemoryRegion bootrom;
Signature · 1 line
2.43.0
PATCH v3 3/3 tests/qtest: add test for K230 IOMUX
In reply to Kangjie HuangCover the 64 documented reset values, writable field storage and masking, read-modify-write accesses, the final IO63 register, reserved offsets, and system reset.
--- MAINTAINERS | 1 + tests/qtest/k230-iomux-test.c | 160 ++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 5 +- 3 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 tests/qtest/k230-iomux-test.c
MAINTAINERS +1 -0
@@ -1851,6 +1851,7 @@ F: include/hw/watchdog/k230_wdt.h F: include/hw/misc/k230_iomux.h F: tests/functional/riscv64/test_k230.py F: tests/qtest/k230-wdt-test.c +F: tests/qtest/k230-iomux-test.c RX Machines -----------
tests/qtest/k230-iomux-test.c new file +160 -0
160 lines not on this page · raw message
tests/qtest/meson.build +4 -1
@@ -297,7 +297,10 @@ qtests_riscv64 = ['riscv-csr-test'] + \ (config_all_devices.has_key('CONFIG_IOMMU_TESTDEV') and config_all_devices.has_key('CONFIG_RISCV_IOMMU') ? ['iommu-riscv-test'] : []) + \ - (config_all_devices.has_key('CONFIG_K230') ? ['k230-wdt-test'] : []) + (config_all_devices.has_key('CONFIG_K230') ? [ + 'k230-wdt-test', + 'k230-iomux-test', + ] : []) qtests_hexagon = ['boot-serial-test', 'l2vic-test', 'qct-qtimer-test']
Signature · 1 line
2.43.0