K230: add gsdma and decomp_gzip
Subsystems (2)
cover K230: add gsdma and decomp_gzip
Hi all,
This patch series adds GSDMA and Decomp_gzip to the K230 board. Enable k230 to use k230_unzip to decompress files during the u-boot phase.
This series includes the following features:
*patch1: add K230 gsdma which supports sdma, gdma is temporarily not supported *patch2: add gsdma to K230 board
*patch3: add K230 gsdma qtest
*patch4: add K230 decomp_gzip which decompress data work with sdma *patch5: add decomp_gzip to K230 board
*patch6: add K230 decomp_gzip qtest
*patch7: add a noc-stub region in K230 board
Thanks
Tao Ding (7):
hw/dma: add K230 gsdma
hw/riscv: k230: add gsdma in K230 board tests/qtest: add test for K230 gsdma hw/misc: add K230 decomp gzip
hw/riscv: k230: add decomp gzip in K230 board tests/qtest: add test for K230 decomp gzip hw/riscv: k230: add a noc stub region in K230 board
hw/dma/Kconfig | 3 + hw/dma/k230_gsdma.c | 532 ++++++++++++++++++++++++++++ hw/dma/meson.build | 1 + hw/dma/trace-events | 6 + hw/misc/Kconfig | 3 + hw/misc/k230_decomp_gzip.c | 498 ++++++++++++++++++++++++++ hw/misc/meson.build | 1 + hw/misc/trace-events | 4 + hw/riscv/Kconfig | 2 + hw/riscv/k230.c | 38 +- include/hw/dma/k230_gsdma.h | 128 +++++++ include/hw/misc/k230_decomp_gzip.h | 92 +++++ include/hw/riscv/k230.h | 5 + tests/qtest/k230-decomp-gzip-test.c | 181 ++++++++++ tests/qtest/k230-gsdma-test.c | 201 +++++++++++ tests/qtest/meson.build | 2 +- 16 files changed, 1689 insertions(+), 8 deletions(-) create mode 100644 hw/dma/k230_gsdma.c create mode 100644 hw/misc/k230_decomp_gzip.c create mode 100644 include/hw/dma/k230_gsdma.h create mode 100644 include/hw/misc/k230_decomp_gzip.h create mode 100644 tests/qtest/k230-decomp-gzip-test.c create mode 100644 tests/qtest/k230-gsdma-test.c
base-commit: bd6079a7a1d14de0918a7715ef6db85dc32de3bb
Signature · 1 line
2.43.0
PATCH 1/7 hw/dma: add K230 gsdma
K230 GSDMA includes SDMA (System Direct Memory Access) and GDMA (Graphic Direct Memory Access). In this patch, add SDMA for k230 board. The following features have not been implemented:
1. axi protocol related
2. channel arbitration
3. lower power mode
SDMA supports transfer data between memory, in which case SDMA is the controller. It also supports transfer data to decomp_gzip and caching it through SRAM. In this case, decomp_gzip is the controller, which controls SDMA through handshake signals.
According to "K230 Technical Reference Manual v0.3.1" section 2.5.2.
https://download.kendryte.com/developer/k230/HDK/K230%E7%A1%AC%E4%BB%B6%E6%96%87%E6%A1%A3/K230_Technical_Reference_Manual_V0.3.1_20241118.pdf
This commit includes:
- K230 SDMA (System Direct Memory Access) model (k230_gsdma.c, k230_gsdma.h)
- GSDMA trace log (trace-events)
- Kconfig and meson.build
--- hw/dma/Kconfig | 3 + hw/dma/k230_gsdma.c | 532 ++++++++++++++++++++++++++++++++++++ hw/dma/meson.build | 1 + hw/dma/trace-events | 6 + include/hw/dma/k230_gsdma.h | 128 +++++++++ 5 files changed, 670 insertions(+) create mode 100644 hw/dma/k230_gsdma.c create mode 100644 include/hw/dma/k230_gsdma.h
hw/dma/Kconfig +3 -0
@@ -30,3 +30,6 @@ config SIFIVE_PDMA config XLNX_CSU_DMA bool select REGISTER + +config K230_GSDMA + bool
hw/dma/k230_gsdma.c new file +532 -0
532 lines not on this page · raw message
hw/dma/meson.build +1 -0
@@ -12,3 +12,4 @@ system_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_dma.c', 'soc_dma.c')) system_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_dma.c')) system_ss.add(when: 'CONFIG_SIFIVE_PDMA', if_true: files('sifive_pdma.c')) system_ss.add(when: 'CONFIG_XLNX_CSU_DMA', if_true: files('xlnx_csu_dma.c')) +system_ss.add(when: 'CONFIG_K230_GSDMA', if_true: files('k230_gsdma.c'))
hw/dma/trace-events +6 -0
@@ -47,3 +47,9 @@ pl330_iomem_read(uint32_t addr, uint32_t data) "addr: 0x%08"PRIx32" data: 0x%08" # xilinx_axidma.c xilinx_axidma_loading_desc_fail(uint32_t res) "error:%u" + +# k230_gsdma.c +k230_gsdma_read(uint64_t addr, unsigned int size, uint64_t data) "K230 GSDMA read: [0x%"PRIx64"] size %u -> 0x%"PRIx64 +k230_gsdma_write(uint64_t addr, unsigned int size, uint64_t data) "K230 GSDMA write: [0x%"PRIx64"] size %u <- 0x%"PRIx64 +k230_gsdma_read_sdma_llt(uint64_t addr, uint32_t cfg, uint32_t src_addr, uint32_t line_size, uint32_t line_cfg, uint32_t dst_addr, uint32_t next_llt_addr) "K230 GSDMA read SDMA LLT: addr=0x%"PRIx64" cfg=0x%"PRIx32" src=0x%"PRIx32" line_size=0x%"PRIx32" line_cfg=0x%"PRIx32" dst=0x%"PRIx32" next=0x%"PRIx32 +k230_gsdma_read_sdma_llt_failed(uint64_t addr) "K230 GSDMA read SDMA LLT failed: addr=0x%"PRIx64
include/hw/dma/k230_gsdma.h new file +128 -0
128 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH 1/7] hw/dma: add K230 gsdma
hw/dma/k230_gsdma.c line 81
Quoted 13 lines · Tao Ding
hw/dma/k230_gsdma.c new file +0
-0@@ -0,0 +1,532 @@[ ... skip 75 lines ... ]
hw/dma/k230_gsdma.c new file +6
-0+/* Stride line size required for 2d mode */ +uint32_t line_space =extract32 (line_cfg,16 ,16 ); + +bool dat_mode = c->cfg &K230_GSDMA_CH_CFG_DAT_MODE ; +bool src_fixed = c->cfg &K230_GSDMA_CH_CFG_SRC_FIXED ; +bool dst_fixed = c->cfg &K230_GSDMA_CH_CFG_DST_FIXED ;
The handling for chx_dat_endian is completely missing here. Could you please check this register field in the TRM and implement its functionality?
hw/dma/k230_gsdma.c line 126
Quoted 7 lines
[ ... skip 39 lines ... ]
hw/dma/k230_gsdma.c new file +6
-0+ remaining -= chunk; + } + +if (!dat_mode) { +if (llt_cfg &K230_GSDMA_LLT_2D_MODE ) {/*2d mode*/ + src += line_size + line_space;
The 2D mode semantics here don't match the TRM.
According to the TRM, when in 2D mode and SRC_FIXED equals 1, the correct behaviour is that SRC_ADDR should not increment. There is currently no check here to determine whether SRC_FIXED is set to 1.
hw/dma/k230_gsdma.c line 194
Quoted 7 lines
[ ... skip 62 lines ... ]
hw/dma/k230_gsdma.c new file +6
-0+return ; + } + + addr = next; + } +
When CHx_CTL.START is written via MMIO, the entire llt is processed synchronously. During this period, the vCPU is unable to stop, resume, or reset command. This could potentially cause QEMU to be blocked here for an indefinite amount of time.
For the implementation, please refer to the reference in i8257.c.
hw/dma/k230_gsdma.c line 515
Quoted 7 lines
[ ... skip 315 lines ... ]
hw/dma/k230_gsdma.c new file +6
-0+static void k230_gsdma_class_init (ObjectClass *klass,const void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = k230_gsdma_realize; +device_class_set_legacy_reset (dc, k230_gsdma_reset);
This interface is no longer recommended for use. For further details, please refer to the comments for this interface in qdev.h.
Signature · 1 line
bbbbbq <[email protected]>
Re: [PATCH 1/7] hw/dma: add K230 gsdma
Quoted 15 lines · Junze Cao
hw/dma/k230_gsdma.c line 81
Quoted 13 lines · Tao Ding
hw/dma/k230_gsdma.c new file +0
-0@@ -0,0 +1,532 @@[ ... skip 75 lines ... ]
hw/dma/k230_gsdma.c new file +6
-0+/* Stride line size required for 2d mode */ +uint32_t line_space =extract32 (line_cfg,16 ,16 ); + +bool dat_mode = c->cfg &K230_GSDMA_CH_CFG_DAT_MODE ; +bool src_fixed = c->cfg &K230_GSDMA_CH_CFG_SRC_FIXED ; +bool dst_fixed = c->cfg &K230_GSDMA_CH_CFG_DST_FIXED ;The handling for
chx_dat_endianis completely missing here. Could you please check this register field in the TRM and implement its functionality?
It will be added in the next patch.
Quoted 10 lines
hw/dma/k230_gsdma.c line 126
Quoted 7 lines
[ ... skip 39 lines ... ]
hw/dma/k230_gsdma.c new file +6
-0+ remaining -= chunk; + } + +if (!dat_mode) { +if (llt_cfg &K230_GSDMA_LLT_2D_MODE ) {/*2d mode*/ + src += line_size + line_space;The 2D mode semantics here don't match the TRM.
According to the TRM, when in 2D mode andSRC_FIXEDequals 1, the correct behaviour is thatSRC_ADDRshould not increment. There is currently no check here to determine whetherSRC_FIXEDis set to 1.
yes, it's a bug.
Quoted 10 lines
hw/dma/k230_gsdma.c line 194
Quoted 7 lines
[ ... skip 62 lines ... ]
hw/dma/k230_gsdma.c new file +6
-0+return ; + } + + addr = next; + } +When CHx_CTL.START is written via MMIO, the entire llt is processed synchronously. During this period, the vCPU is unable to stop, resume, or reset command. This could potentially cause QEMU to be blocked here for an indefinite amount of time.
For the implementation, please refer to the reference in
i8257.c.
Yes, the transmission is processed synchronously after startup.
Only when the software is set incorrectly, such as LLT being a circular linked list.
DMA may fall into a dead loop, in which case stop and other operations cannot be performed.
I think we can add a limit on the maximum number of LLT processing times.
For example, when transmitting 1GB, assuming that LLT is performed every 4KB, the number of LLTs is 1GB/4KB=0x40000.
Quoted 9 lines
hw/dma/k230_gsdma.c line 515
Quoted 7 lines
[ ... skip 315 lines ... ]
hw/dma/k230_gsdma.c new file +6
-0+static void k230_gsdma_class_init (ObjectClass *klass,const void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = k230_gsdma_realize; +device_class_set_legacy_reset (dc, k230_gsdma_reset);This interface is no longer recommended for use. For further details, please refer to the comments for this interface in
qdev.h.
PATCH 2/7 hw/riscv: k230: add gsdma in K230 board
In reply to Tao DingThis commit replaces the unimplemented part of GSDMA in K230. And connect the interrupt to plic.
--- hw/riscv/Kconfig | 1 + hw/riscv/k230.c | 12 +++++++++--- include/hw/riscv/k230.h | 3 +++ 3 files changed, 13 insertions(+), 3 deletions(-)
hw/riscv/Kconfig +1 -0
@@ -162,3 +162,4 @@ config K230 select SERIAL_MM select UNIMP select K230_WDT + select K230_GSDMA
hw/riscv/k230.c +9 -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-gsdma" , &s->gsdma,TYPE_K230_GSDMA );qdev_prop_set_uint32 (DEVICE (cpu0),"hartid-base" ,0 );qdev_prop_set_string (DEVICE (cpu0),"cpu-type" ,TYPE_RISCV_CPU_THEAD_C908 );
@@ -206,6 +207,14 @@ 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 )); +/* Gsdma */ +if (!sysbus_realize (SYS_BUS_DEVICE (&s->gsdma), errp)) { +return ; + } +sysbus_mmio_map (SYS_BUS_DEVICE (&s->gsdma),0 , memmap[K230_DEV_GSDMA ].base); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->gsdma),0 , +qdev_get_gpio_in (DEVICE (s->c908_plic),K230_GSDMA_IRQ )); +/* unimplemented devices */ create_unimplemented_device("kpu.l2-cache", memmap[K230_DEV_KPU_L2_CACHE].base,
@@ -221,9 +230,6 @@ static void k230_soc_realize(DeviceState *dev, Error **errp) memmap[K230_DEV_AI_2D_ENGINE ].base, memmap[K230_DEV_AI_2D_ENGINE].size); -create_unimplemented_device ("gsdma" , memmap[K230_DEV_GSDMA ].base, - memmap[K230_DEV_GSDMA ].size); -create_unimplemented_device ("dma" , memmap[K230_DEV_DMA ].base, memmap[K230_DEV_DMA ].size);
include/hw/riscv/k230.h +3 -0
@@ -18,6 +18,7 @@#include "hw/core/boards.h" #include "hw/riscv/riscv_hart.h" #include "hw/watchdog/k230_wdt.h" +#include "hw/dma/k230_gsdma.h" #define C908_CPU_HARTID (0)
@@ -33,6 +34,7 @@ typedef struct K230SoCState {RISCVHartArrayState c908_cpu;/* Small core */ K230WdtState wdt[2 ]; +K230GSDMAState gsdma;MemoryRegion sram;MemoryRegion bootrom;
@@ -129,6 +131,7 @@ enum {K230_UART4_IRQ =20 ,K230_WDT0_IRQ =107 ,K230_WDT1_IRQ =108 , + K230_GSDMA_IRQ = 140, };#define K230_UART_COUNT 5
Signature · 1 line
2.43.0
Re: [PATCH 2/7] hw/riscv: k230: add gsdma in K230 board
# Add your code comments below. There is no need to trim or delete
# any existing content -- just insert your comments under the relevant # lines of code. Lines starting with "> " are quoted diff context and # lines starting with "| " are comments from other reviewers. # The final email will be reformatted automatically to include only # the sections that have your comments. #
Quoted 71 lines
This commit replaces the unimplemented part of GSDMA in K230. And connect the interrupt to plic.
Signed-off-by Tao Ding <[email protected]>hw/riscv/Kconfig +1
-0@@ -162,3 +162,4 @@ config K230 select SERIAL_MM select UNIMP select K230_WDT + select K230_GSDMAhw/riscv/k230.c +9
-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-gsdma" , &s->gsdma,TYPE_K230_GSDMA );qdev_prop_set_uint32 (DEVICE (cpu0),"hartid-base" ,0 );qdev_prop_set_string (DEVICE (cpu0),"cpu-type" ,TYPE_RISCV_CPU_THEAD_C908 );@@ -206,6 +207,14 @@ 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 )); +/* Gsdma */ +if (!sysbus_realize (SYS_BUS_DEVICE (&s->gsdma), errp)) { +return ; + } +sysbus_mmio_map (SYS_BUS_DEVICE (&s->gsdma),0 , memmap[K230_DEV_GSDMA ].base); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->gsdma),0 , +qdev_get_gpio_in (DEVICE (s->c908_plic),K230_GSDMA_IRQ )); +/* unimplemented devices */ create_unimplemented_device("kpu.l2-cache", memmap[K230_DEV_KPU_L2_CACHE].base,@@ -221,9 +230,6 @@ static void k230_soc_realize(DeviceState *dev, Error **errp) memmap[K230_DEV_AI_2D_ENGINE ].base, memmap[K230_DEV_AI_2D_ENGINE].size); -create_unimplemented_device ("gsdma" , memmap[K230_DEV_GSDMA ].base, - memmap[K230_DEV_GSDMA ].size); -create_unimplemented_device ("dma" , memmap[K230_DEV_DMA ].base, memmap[K230_DEV_DMA ].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/dma/k230_gsdma.h" #define C908_CPU_HARTID (0)@@ -33,6 +34,7 @@ typedef struct K230SoCState {RISCVHartArrayState c908_cpu;/* Small core */ K230WdtState wdt[2 ]; +K230GSDMAState gsdma;MemoryRegion sram;MemoryRegion bootrom;
include/hw/riscv/k230.h enum { · line 137
Quoted 7 lines
include/hw/riscv/k230.h +1
-0@@ -129,6 +131,7 @@ enum {K230_UART4_IRQ =20 ,K230_WDT0_IRQ =107 ,K230_WDT1_IRQ =108 , + K230_GSDMA_IRQ = 140, };#define K230_UART_COUNT 5
Signature · 1 line
Junze Cao <[email protected]>
PATCH 3/7 tests/qtest: add test for K230 gsdma
In reply to Tao DingThis commit adds test cases for GSDMA.
Imitate the behavior of the driver, set LLT and sdma registers. After the data transmission is completed, check the destination address data.
Run this qtest:
$ mkdir build && cd build && ../configure --target-list="riscv64-softmmu"
$ QTEST_QEMU_BINARY=./qemu-system-riscv64 tests/qtest/k230-gsdma-test--- tests/qtest/k230-gsdma-test.c | 201 ++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 2 +- 2 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 tests/qtest/k230-gsdma-test.c
tests/qtest/k230-gsdma-test.c new file +201 -0
@@ -0,0 +1,201 @@ +/* +* QTest testcase for K230 GSDMA +* +* Copyright (c) 2026 Tao Ding <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "qemu/bitops.h" +#include "exec/hwaddr.h" +#include "hw/dma/k230_gsdma.h" +#include "libqtest.h" + +#define K230_GSDMA_BASE 0x80800000 +#define TEST_LLT_ADDR0 0x10000 +#define TEST_LLT_ADDR1 0x10040 +#define TEST_LLT_ADDR2 0x10080 + +#define TEST_SRC_ADDR0 0x20000 +#define TEST_SRC_ADDR1 0x22000 +#define TEST_SRC_ADDR2 0x23000 +#define TEST_DST_ADDR0 0x30000 +#define TEST_DST_ADDR1 0x32000 +#define TEST_DST_ADDR2 0x33000 + +static inline uint64_t gsdma_reg (hwaddr off) +{ +return K230_GSDMA_BASE + off; +} + +static inline uint64_t gsdma_ch_reg (unsigned int ch,hwaddr off) +{ +return K230_GSDMA_BASE +K230_GSDMA_CH_BASE + + ch *K230_GSDMA_CH_STRIDE + off; +} + +static void write_sdma_llt_node_full (QTestState *qts,hwaddr addr, +uint32_t cfg,hwaddr src, +uint32_t size,hwaddr dst, +hwaddr next) +{ +qtest_writel (qts, addr + offsetof(K230GSDMALLT , cfg), cfg); +qtest_writel (qts, addr + offsetof(K230GSDMALLT , src_addr), src); +qtest_writel (qts, addr + offsetof(K230GSDMALLT , line_size), size); +qtest_writel (qts, addr + offsetof(K230GSDMALLT , line_cfg),0x1 ); +qtest_writel (qts, addr + offsetof(K230GSDMALLT , dst_addr), dst); +qtest_writel (qts, addr + offsetof(K230GSDMALLT , next_llt_addr), next); +} + +static void write_sdma_llt_node (QTestState *qts,hwaddr addr,uint32_t cfg, +uint32_t next) +{ +write_sdma_llt_node_full (qts, addr, cfg,0x11110000 ,0x200 , +0x22220000 , next); +} + +static void fill_pattern (uint8_t *buf,size_t size,uint8_t seed) +{ +for (size_t i =0 ; i < size; i++) { + buf[i] = seed + i *37 ; + } +} + +static void test_global_registers (void ) +{ +QTestState *qts =qtest_init ("-machine k230" ); + + g_assert_cmphex(qtest_readl(qts, gsdma_reg(K230_GSDMA_DMA_CFG)), ==, +K230_GSDMA_DMA_CFG_RESET ); + +qtest_writel (qts,gsdma_reg (K230_GSDMA_DMA_CH_EN ),0xff ); + g_assert_cmphex(qtest_readl(qts, gsdma_reg(K230_GSDMA_DMA_CH_EN)), ==, +K230_GSDMA_DMA_CH_EN_MASK ); + +qtest_writel (qts,gsdma_reg (K230_GSDMA_DMA_INT_MASK ),0x12345 ); + g_assert_cmphex(qtest_readl(qts, gsdma_reg(K230_GSDMA_DMA_INT_MASK)), ==, +0x12345 ); + +qtest_writel (qts,gsdma_reg (K230_GSDMA_DMA_CFG ),0xa5a5a5a5 ); + g_assert_cmphex(qtest_readl(qts, gsdma_reg(K230_GSDMA_DMA_CFG)), ==, +0xa5a5a5a5 ); + +qtest_writel (qts,gsdma_reg (K230_GSDMA_DMA_WEIGHT ),0xff55aa55 ); + g_assert_cmphex(qtest_readl(qts, gsdma_reg(K230_GSDMA_DMA_WEIGHT)), ==, +0x55aa55 ); + +qtest_quit (qts); +} + +static void test_sdma_pause_resume (void ) +{ +uint32_t int_stat; +QTestState *qts =qtest_init ("-machine k230" ); + +write_sdma_llt_node (qts,TEST_LLT_ADDR0 ,K230_GSDMA_LLT_PAUSE , +TEST_LLT_ADDR1 ); +write_sdma_llt_node (qts,TEST_LLT_ADDR1 ,K230_GSDMA_LLT_NODE_INTR ,0 ); + +qtest_writel (qts,gsdma_reg (K230_GSDMA_DMA_CH_EN ),BIT (0 )); +qtest_writel (qts,gsdma_ch_reg (0 ,K230_GSDMA_CH_LLT_SADDR ),TEST_LLT_ADDR0 ); +qtest_writel (qts,gsdma_ch_reg (0 ,K230_GSDMA_CH_CTL ),K230_GSDMA_CTL_START ); + + g_assert_cmphex(qtest_readl(qts, gsdma_ch_reg(0, K230_GSDMA_CH_STATUS)), ==, +K230_GSDMA_SDMA_STATUS_PAUSE ); +g_assert_cmphex (qtest_readl (qts,gsdma_ch_reg (0 ,K230_GSDMA_CH_CURRENT_LLT )), + ==, TEST_LLT_ADDR0); + + int_stat =qtest_readl (qts,gsdma_reg (K230_GSDMA_DMA_INT_STAT )); + g_assert_cmphex(int_stat & K230_GSDMA_SDMA_PAUSE_INT(0), ==, +K230_GSDMA_SDMA_PAUSE_INT (0 )); + g_assert_cmphex(int_stat & K230_GSDMA_SDMA_DONE_INT(0), ==, 0); + +qtest_writel (qts,gsdma_reg (K230_GSDMA_DMA_INT_STAT ), int_stat); +qtest_writel (qts,gsdma_ch_reg (0 ,K230_GSDMA_CH_CTL ),K230_GSDMA_CTL_RESUME ); + + g_assert_cmphex(qtest_readl(qts, gsdma_ch_reg(0, K230_GSDMA_CH_STATUS)), ==, +0 ); +g_assert_cmphex (qtest_readl (qts,gsdma_ch_reg (0 ,K230_GSDMA_CH_CURRENT_LLT )), + ==, TEST_LLT_ADDR1); + + int_stat =qtest_readl (qts,gsdma_reg (K230_GSDMA_DMA_INT_STAT )); + g_assert_cmphex(int_stat & K230_GSDMA_SDMA_DONE_INT(0), ==, +K230_GSDMA_SDMA_DONE_INT (0 )); + g_assert_cmphex(int_stat & K230_GSDMA_SDMA_ITEM_INT(0), ==, +K230_GSDMA_SDMA_ITEM_INT (0 )); + +qtest_quit (qts); +} + +static void test_sdma_three_llt_copy (void ) +{ +uint8_t src0[0x1000 ]; +uint8_t src1[1 ]; +uint8_t src2[511 ]; +uint8_t dst0[sizeof (src0)]; +uint8_t dst1[sizeof (src1)]; +uint8_t dst2[sizeof (src2)]; +uint32_t int_stat; +QTestState *qts =qtest_init ("-machine k230" ); + +fill_pattern (src0,sizeof (src0),0x10 ); +fill_pattern (src1,sizeof (src1),0x31 ); +fill_pattern (src2,sizeof (src2),0x52 ); +memset (dst0,0xa5 ,sizeof (dst0)); +memset (dst1,0xa5 ,sizeof (dst1)); +memset (dst2,0xa5 ,sizeof (dst2)); + +qtest_memwrite (qts,TEST_SRC_ADDR0 , src0,sizeof (src0)); +qtest_memwrite (qts,TEST_SRC_ADDR1 , src1,sizeof (src1)); +qtest_memwrite (qts,TEST_SRC_ADDR2 , src2,sizeof (src2)); +qtest_memwrite (qts,TEST_DST_ADDR0 , dst0,sizeof (dst0)); +qtest_memwrite (qts,TEST_DST_ADDR1 , dst1,sizeof (dst1)); +qtest_memwrite (qts,TEST_DST_ADDR2 , dst2,sizeof (dst2)); + +write_sdma_llt_node_full (qts,TEST_LLT_ADDR0 ,0 ,TEST_SRC_ADDR0 , +sizeof (src0),TEST_DST_ADDR0 ,TEST_LLT_ADDR1 ); +write_sdma_llt_node_full (qts,TEST_LLT_ADDR1 ,0 ,TEST_SRC_ADDR1 , +sizeof (src1),TEST_DST_ADDR1 ,TEST_LLT_ADDR2 ); +write_sdma_llt_node_full (qts,TEST_LLT_ADDR2 ,0 ,TEST_SRC_ADDR2 , +sizeof (src2),TEST_DST_ADDR2 ,0 ); + +qtest_writel (qts,gsdma_reg (K230_GSDMA_DMA_CH_EN ),BIT (0 )); +qtest_writel (qts,gsdma_ch_reg (0 ,K230_GSDMA_CH_LLT_SADDR ),TEST_LLT_ADDR0 ); +qtest_writel (qts,gsdma_ch_reg (0 ,K230_GSDMA_CH_CTL ),K230_GSDMA_CTL_START ); + + g_assert_cmphex(qtest_readl(qts, gsdma_ch_reg(0, K230_GSDMA_CH_STATUS)), ==, +0 ); +g_assert_cmphex (qtest_readl (qts,gsdma_ch_reg (0 ,K230_GSDMA_CH_CURRENT_LLT )), + ==, TEST_LLT_ADDR2); + + int_stat =qtest_readl (qts,gsdma_reg (K230_GSDMA_DMA_INT_STAT )); + g_assert_cmphex(int_stat & K230_GSDMA_SDMA_DONE_INT(0), ==, +K230_GSDMA_SDMA_DONE_INT (0 )); + g_assert_cmphex(int_stat & K230_GSDMA_SDMA_PAUSE_INT(0), ==, 0); + +memset (dst0,0 ,sizeof (dst0)); +memset (dst1,0 ,sizeof (dst1)); +memset (dst2,0 ,sizeof (dst2)); +qtest_memread (qts,TEST_DST_ADDR0 , dst0,sizeof (dst0)); +qtest_memread (qts,TEST_DST_ADDR1 , dst1,sizeof (dst1)); +qtest_memread (qts,TEST_DST_ADDR2 , dst2,sizeof (dst2)); + +g_assert_cmpmem (dst0,sizeof (dst0), src0,sizeof (src0)); +g_assert_cmpmem (dst1,sizeof (dst1), src1,sizeof (src1)); +g_assert_cmpmem (dst2,sizeof (dst2), src2,sizeof (src2)); + +qtest_quit (qts); +} + +int main (int argc,char **argv) +{ +g_test_init (&argc, &argv,NULL ); + +qtest_add_func ("/k230-gsdma/global-registers" , test_global_registers); +qtest_add_func ("/k230-gsdma/sdma-pause-resume" , test_sdma_pause_resume); +qtest_add_func ("/k230-gsdma/sdma-three-llt-copy" , + test_sdma_three_llt_copy); + +return g_test_run (); +}
tests/qtest/meson.build +1 -1
@@ -297,7 +297,7 @@ 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-gsdma-test'] : []) qtests_hexagon = ['boot-serial-test']
Signature · 1 line
2.43.0
Re: [PATCH 3/7] tests/qtest: add test for K230 gsdma
tests/qtest/meson.build qtests_riscv64 = ['riscv-csr-test'] + \ · line 303
Quoted 13 lines · Tao Ding
tests/qtest/meson.build +1
-1@@ -297,7 +297,7 @@ 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-gsdma-test'] : []) qtests_hexagon = ['boot-serial-test']
The new source files haven't been added to the MAINTAINERS. Please update.
Other than that, there are no issues.
Signature · 1 line
Junze Cao <[email protected]>
PATCH 4/7 hw/misc: add K230 decomp gzip
In reply to Tao DingDecompression accelerator is mainly used to implement hardware GZIP decompression function. According to the k230 SDK, this hardware will be used during the uboot phase to decompress compressed files.
Decomp_gzip does not have the ability to access the system bus.
Therefore, SDMA is required for data transmission. A typical scenario is SDMA moving compressed data from DDR to SRAM, and Decomp_gzip reading data from SRAM. After decompression, decomp_gzip writes the data back to SRAM, and SDMA moves the data from SRAM to DDR.
According to "K230 Technical Reference Manual v0.3.1" section 15.
https://download.kendryte.com/developer/k230/HDK/K230%E7%A1%AC%E4%BB%B6%E6%96%87%E6%A1%A3/K230_Technical_Reference_Manual_V0.3.1_20241118.pdf
--- hw/misc/Kconfig | 3 + hw/misc/k230_decomp_gzip.c | 498 +++++++++++++++++++++++++++++ hw/misc/meson.build | 1 + hw/misc/trace-events | 4 + include/hw/misc/k230_decomp_gzip.h | 92 ++++++ 5 files changed, 598 insertions(+) create mode 100644 hw/misc/k230_decomp_gzip.c create mode 100644 include/hw/misc/k230_decomp_gzip.h
hw/misc/Kconfig +3 -0
@@ -257,4 +257,7 @@ config XLNX_VERSAL_TRNG config XLNX_ZYNQ_DDRC bool +config K230_DECOMP_GZIP + bool + source macio/Kconfig
hw/misc/k230_decomp_gzip.c new file +498 -0
498 lines not on this page · raw message
hw/misc/meson.build +1 -0
@@ -36,6 +36,7 @@ system_ss.add(when: 'CONFIG_SIFIVE_E_PRCI', if_true: files('sifive_e_prci.c')) system_ss.add(when: 'CONFIG_SIFIVE_E_AON', if_true: files('sifive_e_aon.c')) system_ss.add(when: 'CONFIG_SIFIVE_U_OTP', if_true: files('sifive_u_otp.c')) system_ss.add(when: 'CONFIG_SIFIVE_U_PRCI', if_true: files('sifive_u_prci.c')) +system_ss.add(when: 'CONFIG_K230_DECOMP_GZIP', if_true: files('k230_decomp_gzip.c')) subdir('macio')
hw/misc/trace-events +4 -0
@@ -442,3 +442,7 @@ iommu_testdev_dma_read(uint64_t gva, uint32_t len) "gva=0x%" PRIx64 " len=%u" iommu_testdev_dma_verify(uint32_t expected, uint32_t actual) "expected=0x%x actual=0x%x" iommu_testdev_dma_result(uint32_t result) "DMA completed result=0x%x" iommu_testdev_dma_armed(bool armed) "armed=%d" + +# k230_decomp_gzip.c +k230_decomp_gzip_read(uint64_t offset, unsigned int size, uint64_t value) "K230 DECOMP GZIP read: [0x%"PRIx64"] size %u -> 0x%"PRIx64 +k230_decomp_gzip_write(uint64_t offset, unsigned int size, uint64_t value) "K230 DECOMP GZIP write: [0x%"PRIx64"] size %u <- 0x%"PRIx64
include/hw/misc/k230_decomp_gzip.h new file +92 -0
92 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH 4/7] hw/misc: add K230 decomp gzip
Quoted 18 lines · Tao Ding
hw/misc/k230_decomp_gzip.c new file +0
-0@@ -0,0 +1,498 @@[ ... skip 184 lines ... ]
hw/misc/k230_decomp_gzip.c new file +11
-0+ s->output_buf, produced)) { +return false; + } + s->output.current_offset += produced; + s->total_produced += produced; + } + +if (consumed) { + s->input.current_offset += consumed; + } +
hw/misc/k230_decomp_gzip.c line 205
Quoted 10 lines
hw/misc/k230_decomp_gzip.c new file +10
-0+if (ret ==Z_STREAM_END ) { + s->stream_end = true; +if (s->total_produced != output_size) { +return false; + } + } + +return true; +} +
The current implementation calls a universal DEFLATE decoder, which natively supports three BType formats: 00, 01, and 10. Based on the K230 technical manual's semantics, the current settings support the Dynamic Huffman format. I believe we need to add a BType==10 validation.
Quoted 12 lines
[ ... skip 109 lines ... ]
hw/misc/k230_decomp_gzip.c new file +11
-0+if (!(s->gzip_src_size &K230_DECOMP_GZIP_CTRL_EN ) || + input_size ==0 || s->gzip_out_size ==0 ) { +k230_decomp_gzip_finish (s, false); +return ; + } + + s->active = true; +k230_decomp_gzip_update_ctrl_en (s); +k230_decomp_gzip_kick (s); +} +
hw/misc/k230_decomp_gzip.c line 335
Quoted 10 lines
hw/misc/k230_decomp_gzip.c new file +10
-0+static uint64_t k230_decomp_gzip_read (void *opaque,hwaddr offset, +unsigned size) +{ +K230DecompGzipState *s = opaque; +uint64_t value =0 ; + +switch (offset) { +case K230_DECOMP_GZIP_DECOMP_START : + value = s->decomp_start; +break ;
Bit 0 of this register, decomp_start, is write-only. I believe the semantics here are inconsistent with the manual.
Quoted 12 lines
[ ... skip 124 lines ... ]
hw/misc/k230_decomp_gzip.c new file +11
-0+ +memory_region_init_io (&s->iomem,OBJECT (dev), &k230_decomp_gzip_ops, s, +TYPE_K230_DECOMP_GZIP , +K230_DECOMP_GZIP_MMIO_SIZE ); +sysbus_init_mmio (sbd, &s->iomem); +qdev_init_gpio_in (dev, k230_decomp_gzip_handle_ack, +K230_DECOMP_GZIP_NUM_GPIOS_IN ); +qdev_init_gpio_out (dev, s->signal_out, +K230_DECOMP_GZIP_NUM_GPIOS_OUT ); +} +
hw/misc/k230_decomp_gzip.c line 480
Quoted 10 lines
hw/misc/k230_decomp_gzip.c new file +10
-0+static const Property k230_decomp_gzip_properties[] = { +DEFINE_PROP_UINT64 ("sram-base" , K230DecompGzipState, sram_base,0 ), +}; + +static void k230_decomp_gzip_class_init (ObjectClass *oc,const void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); + + dc->realize = k230_decomp_gzip_realize; +device_class_set_legacy_reset (dc, k230_decomp_gzip_reset);
This interface has been deprecated; please refer to qdev.h for further details. This issue is similar to patch 1/7 (actually, it's identical).
Signature · 1 line
Junze Cao <[email protected]>
PATCH 5/7 hw/riscv: k230: add decomp gzip in K230 board
In reply to Tao DingThis commit replaces the unimplemented part of Decomp_gzip in K230. Connect to the handshake interface of GSDMA.
--- hw/riscv/Kconfig | 1 + hw/riscv/k230.c | 23 +++++++++++++++++++---- include/hw/riscv/k230.h | 2 ++ 3 files changed, 22 insertions(+), 4 deletions(-)
hw/riscv/Kconfig +1 -0
@@ -163,3 +163,4 @@ config K230 select UNIMP select K230_WDT select K230_GSDMA + select K230_DECOMP_GZIP
hw/riscv/k230.c +19 -4
@@ -111,6 +111,8 @@ static void k230_soc_init(Object *obj)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-gsdma" , &s->gsdma,TYPE_K230_GSDMA ); +object_initialize_child (obj,"k230-decomp-gzip" , &s->decomp_gzip, +TYPE_K230_DECOMP_GZIP );qdev_prop_set_uint32 (DEVICE (cpu0),"hartid-base" ,0 );qdev_prop_set_string (DEVICE (cpu0),"cpu-type" ,TYPE_RISCV_CPU_THEAD_C908 );
@@ -215,6 +217,23 @@ static void k230_soc_realize(DeviceState *dev, Error **errp)sysbus_connect_irq (SYS_BUS_DEVICE (&s->gsdma),0 ,qdev_get_gpio_in (DEVICE (s->c908_plic),K230_GSDMA_IRQ )); +/* Decomp gzip */ +qdev_prop_set_uint64 (DEVICE (&s->decomp_gzip),"sram-base" , + memmap[K230_DEV_SRAM ].base); +if (!sysbus_realize (SYS_BUS_DEVICE (&s->decomp_gzip), errp)) { +return ; + } +sysbus_mmio_map (SYS_BUS_DEVICE (&s->decomp_gzip),0 , + memmap[K230_DEV_DECOMP_GZIP ].base); +for (int i =0 ; i <K230_DECOMP_GZIP_NUM_GPIOS_OUT ; i++) { +qdev_connect_gpio_out (DEVICE (&s->decomp_gzip), i, +qdev_get_gpio_in (DEVICE (&s->gsdma), i)); + } +for (int i =0 ; i <K230_DECOMP_GZIP_NUM_GPIOS_IN ; i++) { +qdev_connect_gpio_out (DEVICE (&s->gsdma), i, +qdev_get_gpio_in (DEVICE (&s->decomp_gzip), i)); + } +/* unimplemented devices */ create_unimplemented_device("kpu.l2-cache", memmap[K230_DEV_KPU_L2_CACHE].base,
@@ -233,10 +252,6 @@ static void k230_soc_realize(DeviceState *dev, Error **errp)create_unimplemented_device ("dma" , memmap[K230_DEV_DMA ].base, memmap[K230_DEV_DMA ].size); -create_unimplemented_device ("decomp-gzip" , - memmap[K230_DEV_DECOMP_GZIP ].base, - memmap[K230_DEV_DECOMP_GZIP ].size); -create_unimplemented_device ("2d-engine.non-ai" , memmap[K230_DEV_NON_AI_2D ].base, memmap[K230_DEV_NON_AI_2D ].size);
include/hw/riscv/k230.h +2 -0
@@ -19,6 +19,7 @@#include "hw/riscv/riscv_hart.h" #include "hw/watchdog/k230_wdt.h" #include "hw/dma/k230_gsdma.h" +#include "hw/misc/k230_decomp_gzip.h" #define C908_CPU_HARTID (0)
@@ -35,6 +36,7 @@ typedef struct K230SoCState {K230WdtState wdt[2 ];K230GSDMAState gsdma; +K230DecompGzipState decomp_gzip;MemoryRegion sram;MemoryRegion bootrom;
Signature · 1 line
2.43.0
Re: [PATCH 5/7] hw/riscv: k230: add decomp gzip in K230 board
Quoted 2 lines · Tao Ding
This commit replaces the unimplemented part of
Decomp_gzipin K230. Connect to the handshake interface of GSDMA.
Signature · 1 line
Junze Cao <[email protected]>
Re: [PATCH 5/7] hw/riscv: k230: add decomp gzip in K230 board
In reply to Tao Dinginclude/hw/riscv/k230.h typedef struct K230SoCState { · line 42
Quoted 12 lines · Tao Ding
include/hw/riscv/k230.h +1
-0@@ -35,6 +36,7 @@ typedef struct K230SoCState {K230WdtState wdt[2 ];K230GSDMAState gsdma; +K230DecompGzipState decomp_gzip;MemoryRegion sram;MemoryRegion bootrom;
Please disregard the Reviewed-by tag in my previous reply; it used an obsolete identity. The review itself is unchanged.
Signature · 1 line
Junze Cao <[email protected]>
PATCH 6/7 tests/qtest: add test for K230 decomp gzip
In reply to Tao DingThis commit adds test cases for Decomp_gzip.
A compressed data segment has been pre-set, configure GSDMA and decomp_gzip. Compare the decompressed data with the original data
Run this qtest:
$ mkdir build && cd build && ../configure --target-list="riscv64-softmmu"
$ QTEST_QEMU_BINARY=./qemu-system-riscv64 tests/qtest/k230-decomp-gzip-test--- tests/qtest/k230-decomp-gzip-test.c | 181 ++++++++++++++++++++++++++++ tests/qtest/meson.build | 2 +- 2 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 tests/qtest/k230-decomp-gzip-test.c
tests/qtest/k230-decomp-gzip-test.c new file +181 -0
@@ -0,0 +1,181 @@ +/* +* QTest testcase for K230 GZIP decompression engine +* +* Copyright (c) 2026 Tao Ding <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "qemu/bitops.h" +#include "libqtest.h" +#include "hw/dma/k230_gsdma.h" +#include "hw/misc/k230_decomp_gzip.h" + +#define K230_DECOMP_GZIP_BASE 0x80808000 +#define K230_GSDMA_BASE 0x80800000 +#define K230_SRAM_BASE 0x80200000 +#define TEST_LLT_ADDR0 0x01000000 +#define TEST_LLT_ADDR1 0x01000040 +#define TEST_SRC_ADDR 0x01100000 +#define TEST_DST_ADDR 0x01200000 + +#define TEST_PAYLOAD_LEN (sizeof(test_payload) - 1) + +static inline uint64_t gzip_reg (hwaddr off) +{ +return K230_DECOMP_GZIP_BASE + off; +} + +static inline uint64_t gsdma_reg (hwaddr off) +{ +return K230_GSDMA_BASE + off; +} + +static inline uint64_t gsdma_ch_reg (unsigned int ch,hwaddr off) +{ +return K230_GSDMA_BASE +K230_GSDMA_CH_BASE + + ch *K230_GSDMA_CH_STRIDE + off; +} + +static inline hwaddr k230_sram_addr (hwaddr off) +{ +return K230_SRAM_BASE + off; +} + +static inline hwaddr k230_sram_input_addr (unsigned int slot) +{ +return k230_sram_addr (K230_DECOMP_GZIP_SRAM_IN_BASE + + slot *K230_DECOMP_GZIP_BLOCK_SIZE ); +} + +static const uint8_t test_gzip_data[] = { +0x1f ,0x8b ,0x09 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x02 ,0xff ,0xf3 ,0x36 ,0x32 ,0x36 ,0x50 ,0x48 , +0xaf ,0xca ,0x2c ,0x50 ,0x28 ,0x2e ,0x29 ,0x4a , +0x4d ,0xcc ,0xcd ,0xcc ,0x4b ,0x57 ,0x28 ,0x49 , +0x2d ,0x2e ,0xe1 ,0xf2 ,0x1e ,0x5a ,0x12 ,0x00 , +0xdb ,0x9d ,0xbc ,0xdd ,0xc8 ,0x00 ,0x00 ,0x00 , +}; + +static const uint8_t test_payload[] = +"K230 gzip streaming test\n" +"K230 gzip streaming test\n" +"K230 gzip streaming test\n" +"K230 gzip streaming test\n" +"K230 gzip streaming test\n" +"K230 gzip streaming test\n" +"K230 gzip streaming test\n" +"K230 gzip streaming test\n" ; + +static void write_sdma_llt_node (QTestState *qts,hwaddr addr,uint32_t src, +uint32_t dst,uint32_t len,uint32_t next) +{ +qtest_writel (qts, addr + offsetof(K230GSDMALLT , cfg),0 ); +qtest_writel (qts, addr + offsetof(K230GSDMALLT , src_addr), src); +qtest_writel (qts, addr + offsetof(K230GSDMALLT , line_size), len); +qtest_writel (qts, addr + offsetof(K230GSDMALLT , line_cfg),0x1 ); +qtest_writel (qts, addr + offsetof(K230GSDMALLT , dst_addr), dst); +qtest_writel (qts, addr + offsetof(K230GSDMALLT , next_llt_addr), next); +} + +static void test_reset_and_rw (void ) +{ +QTestState *qts =qtest_init ("-machine k230" ); + +g_assert_cmphex (qtest_readl (qts,gzip_reg (K230_DECOMP_GZIP_DECOMP_START )), + ==, 0); +g_assert_cmphex (qtest_readl (qts,gzip_reg (K230_DECOMP_GZIP_GZIP_SRC_SIZE )), + ==, 0); +g_assert_cmphex (qtest_readl (qts,gzip_reg (K230_DECOMP_GZIP_GZIP_OUT_SIZE )), + ==, 0); +g_assert_cmphex (qtest_readl (qts,gzip_reg (K230_DECOMP_GZIP_DECOMP_STAT )), + ==, 0); + +qtest_writel (qts,gzip_reg (K230_DECOMP_GZIP_DECOMP_START ), +K230_DECOMP_GZIP_START ); + +qtest_writel (qts,gzip_reg (K230_DECOMP_GZIP_GZIP_SRC_SIZE ),0xffffffff ); +g_assert_cmphex (qtest_readl (qts,gzip_reg (K230_DECOMP_GZIP_GZIP_SRC_SIZE )), + ==, 0xffffffff); + +qtest_writel (qts,gzip_reg (K230_DECOMP_GZIP_GZIP_OUT_SIZE ),0x12345678 ); +g_assert_cmphex (qtest_readl (qts,gzip_reg (K230_DECOMP_GZIP_GZIP_OUT_SIZE )), + ==, 0x12345678); + +qtest_quit (qts); +} + +static void test_gsdma_handshake_flow (void ) +{ +QTestState *qts =qtest_init ("-machine k230" ); +uint32_t stat; +uint8_t output[TEST_PAYLOAD_LEN ]; + +qtest_memwrite (qts,TEST_SRC_ADDR , test_gzip_data,sizeof (test_gzip_data)); +write_sdma_llt_node (qts,TEST_LLT_ADDR0 ,TEST_SRC_ADDR , +k230_sram_input_addr (0 ), +sizeof (test_gzip_data),0 ); +write_sdma_llt_node (qts,TEST_LLT_ADDR1 , +k230_sram_addr (K230_DECOMP_GZIP_SRAM_OUT_BASE ), +TEST_DST_ADDR ,TEST_PAYLOAD_LEN ,0 ); + +qtest_writel (qts,gsdma_reg (K230_GSDMA_DMA_CH_EN ),BIT (0 ) |BIT (1 )); +qtest_writel (qts,gsdma_ch_reg (0 ,K230_GSDMA_CH_CFG ), +K230_GSDMA_CH0_CFG_DECOMP_CTRL_EN ); +qtest_writel (qts,gsdma_ch_reg (1 ,K230_GSDMA_CH_CFG ),0 ); +qtest_writel (qts,gsdma_ch_reg (0 ,K230_GSDMA_CH_LLT_SADDR ),TEST_LLT_ADDR0 ); +qtest_writel (qts,gsdma_ch_reg (1 ,K230_GSDMA_CH_LLT_SADDR ),TEST_LLT_ADDR1 ); +qtest_writel (qts,gsdma_ch_reg (0 ,K230_GSDMA_CH_CTL ),K230_GSDMA_CTL_START ); +qtest_writel (qts,gsdma_ch_reg (1 ,K230_GSDMA_CH_CTL ),K230_GSDMA_CTL_START ); + +g_assert_cmphex (qtest_readl (qts,gsdma_reg (K230_GSDMA_DMA_CH_EN )), + ==, BIT(0) | BIT(1)); +g_assert_cmphex (qtest_readl (qts,gsdma_ch_reg (0 ,K230_GSDMA_CH_CFG )) & +K230_GSDMA_CH0_CFG_DECOMP_CTRL_EN , + ==, K230_GSDMA_CH0_CFG_DECOMP_CTRL_EN); +g_assert_cmphex (qtest_readl (qts,gsdma_ch_reg (0 ,K230_GSDMA_CH_LLT_SADDR )), + ==, TEST_LLT_ADDR0); +g_assert_cmphex (qtest_readl (qts,gsdma_ch_reg (1 ,K230_GSDMA_CH_LLT_SADDR )), + ==, TEST_LLT_ADDR1); + +qtest_writel (qts,gzip_reg (K230_DECOMP_GZIP_GZIP_SRC_SIZE ), +K230_DECOMP_GZIP_CTRL_EN |sizeof (test_gzip_data)); +qtest_writel (qts,gzip_reg (K230_DECOMP_GZIP_GZIP_OUT_SIZE ), +TEST_PAYLOAD_LEN ); +qtest_writel (qts,gzip_reg (K230_DECOMP_GZIP_DECOMP_START ), +K230_DECOMP_GZIP_START ); + + stat =qtest_readl (qts,gzip_reg (K230_DECOMP_GZIP_DECOMP_STAT )); + g_assert_cmphex(stat & K230_DECOMP_GZIP_STAT_CRC_OK, ==, +K230_DECOMP_GZIP_STAT_CRC_OK ); + +g_assert_cmphex (qtest_readl (qts, +gsdma_ch_reg (0 ,K230_GSDMA_CH_CURRENT_LLT )), + ==, TEST_LLT_ADDR0); +g_assert_cmphex (qtest_readl (qts, +gsdma_ch_reg (1 ,K230_GSDMA_CH_CURRENT_LLT )), + ==, TEST_LLT_ADDR1); + + stat =qtest_readl (qts,gsdma_reg (K230_GSDMA_DMA_INT_STAT )); + g_assert_cmphex(stat & K230_GSDMA_SDMA_DONE_INT(0), ==, +K230_GSDMA_SDMA_DONE_INT (0 )); + g_assert_cmphex(stat & K230_GSDMA_SDMA_DONE_INT(1), ==, +K230_GSDMA_SDMA_DONE_INT (1 )); + +qtest_memread (qts,TEST_DST_ADDR , output,sizeof (output)); +g_assert_cmpmem (output,sizeof (output), test_payload,TEST_PAYLOAD_LEN ); + +qtest_quit (qts); +} + +int main (int argc,char **argv) +{ +g_test_init (&argc, &argv,NULL ); + +qtest_add_func ("/k230-decomp-gzip/reset-and-rw" , test_reset_and_rw); +qtest_add_func ("/k230-decomp-gzip/gsdma-handshake-flow" , + test_gsdma_handshake_flow); + +return g_test_run (); +}
tests/qtest/meson.build +1 -1
@@ -297,7 +297,7 @@ 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', 'k230-gsdma-test'] : []) + (config_all_devices.has_key('CONFIG_K230') ? ['k230-wdt-test', 'k230-gsdma-test', 'k230-decomp-gzip-test'] : []) qtests_hexagon = ['boot-serial-test']
Signature · 1 line
2.43.0
Re: [PATCH 6/7] tests/qtest: add test for K230 decomp gzip
Quoted 18 lines · Tao Ding
tests/qtest/k230-decomp-gzip-test.c new file +0
-0@@ -0,0 +1,181 @@[ ... skip 38 lines ... ]
tests/qtest/k230-decomp-gzip-test.c new file +11
-0+} + +static inline hwaddr k230_sram_addr (hwaddr off) +{ +return K230_SRAM_BASE + off; +} + +static inline hwaddr k230_sram_input_addr (unsigned int slot) +{ +return k230_sram_addr (K230_DECOMP_GZIP_SRAM_IN_BASE + + slot *K230_DECOMP_GZIP_BLOCK_SIZE );
tests/qtest/k230-decomp-gzip-test.c line 59
Quoted 10 lines
tests/qtest/k230-decomp-gzip-test.c new file +10
-0+} + +static const uint8_t test_gzip_data[] = { +0x1f ,0x8b ,0x09 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x02 ,0xff ,0xf3 ,0x36 ,0x32 ,0x36 ,0x50 ,0x48 , +0xaf ,0xca ,0x2c ,0x50 ,0x28 ,0x2e ,0x29 ,0x4a , +0x4d ,0xcc ,0xcd ,0xcc ,0x4b ,0x57 ,0x28 ,0x49 , +0x2d ,0x2e ,0xe1 ,0xf2 ,0x1e ,0x5a ,0x12 ,0x00 , +0xdb ,0x9d ,0xbc ,0xdd ,0xc8 ,0x00 ,0x00 ,0x00 , +};
What is the source of the data here?
Was it extracted from the SDK?
I've noticed that this data is in fixed Huffman format, but the K230 GZIP manual only supports dynamic Huffman format.
Signature · 1 line
Junze Cao <[email protected]>
PATCH 7/7 hw/riscv: k230: add a noc stub region in K230 board
In reply to Tao DingThe NOC address was accessed in the k230_unzip driver, but it is currently not in k230. This commit uses create_unimplemented_device to preset the region.
---
Steps to decompress in uboot:
1. Prepare uboot and k230_sdk
u-boot (https://github.com/zevorn/k230-boot-assets) k230_sdk (https://github.com/kendryte/k230_sdk) 2. Compress image (in sh file, modify ROOT and K230_SDK_ROOT) ROOT=k230-boot-assets K230_SDK_ROOT=k230_sdk DST=$ROOT/buildroot/uboot-boot cd $DST $K230_SDK_ROOT/tools/k230_priv_gzip -n8 -f -k Image sed -i -e "1s/\x08/\x09/" Image.gz cd - 3. Launch qemu (in sh file, modify ROOT and QEMU) ROOT=k230-boot-assets QEMU=qemu/build/qemu-system-riscv64 COMMON=$ROOT/common DST=$ROOT/buildroot/uboot-boot INITRD_END=$(printf "0x%x" $((0x0a100000 + $(stat -c %s "$DST/rootfs.cpio.gz")))) echo "Use this U-Boot initrd end: $INITRD_END" $QEMU -M k230 \ -bios "$COMMON/u-boot" \ -device loader,file="$COMMON/fw_jump.uImage",addr=0xc100000,force-raw=on \ -device loader,file="$DST/Image.gz",addr=0xd000000,force-raw=on \ -device loader,file="$DST/rootfs.cpio.gz",addr=0xa100000,force-raw=on \ -device loader,file="$DST/k230-qemu.dtb",addr=0xa000000,force-raw=on \ -nographic -no-reboot \ -d guest_errors \ -D qemu.log 4. Input in uboot k230_unzip 0xd000000 0x6c354f 0x8200000 setenv bootargs console=ttyS0,115200 earlycon=sbi cma=0 fdt addr 0xa000000 fdt resize 8192 fdt set /chosen linux,initrd-start <0x0 0xa100000> fdt set /chosen linux,initrd-end <0x0 0xba2d5fe> bootm 0xc100000 - 0xa000000
hw/riscv/k230.c | 3 +++ 1 file changed, 3 insertions(+)
hw/riscv/k230.c +3 -0
@@ -234,6 +234,9 @@ static void k230_soc_realize(DeviceState *dev, Error **errp) qdev_get_gpio_in(DEVICE(&s->decomp_gzip), i)); } +/* Noc stub, the k230 decomp_gzip driver in uboot will access this region */ +create_unimplemented_device ("noc-stub" ,0x91302000 ,0x1000 ); +/* unimplemented devices */ create_unimplemented_device("kpu.l2-cache", memmap[K230_DEV_KPU_L2_CACHE].base,
Signature · 1 line
2.43.0
Re: [PATCH 7/7] hw/riscv: k230: add a noc stub region in K230 board
Quoted 2 lines · Tao Ding
The NOC address was accessed in the
k230_unzipdriver, but it is currently not in k230. This commit usescreate_unimplemented_deviceto preset the region.
Signature · 1 line
Junze Cao <[email protected]>
Re: [PATCH 7/7] hw/riscv: k230: add a noc stub region in K230 board
In reply to Tao DingQuoted 5 lines · Tao Ding
hw/riscv/k230.c +0
-0
hw/riscv/k230.c static void k230_soc_realize(DeviceState *dev, Error **errp) · line 242
Quoted 9 lines
hw/riscv/k230.c +3
-0@@ -234,6 +234,9 @@ static void k230_soc_realize(DeviceState *dev, Error **errp) qdev_get_gpio_in(DEVICE(&s->decomp_gzip), i)); } +/* Noc stub, the k230 decomp_gzip driver in uboot will access this region */ +create_unimplemented_device ("noc-stub" ,0x91302000 ,0x1000 ); +/* unimplemented devices */ create_unimplemented_device("kpu.l2-cache", memmap[K230_DEV_KPU_L2_CACHE].base,
Please disregard the Reviewed-by tag in my previous reply; it used an obsolete identity. The review itself is unchanged.
Signature · 1 line
Junze Cao <[email protected]>
Hi Tao,
Quoted 5 lines · Tao Ding
Hi all,
This patch series adds GSDMA and
Decomp_gzipto the K230 board. Enable k230 to usek230_unzipto decompress files during the u-boot phase.
Thanks for the contribution!
I believe you need to update the K230 documentation. If peripheral modeling for things like UNGIP and GSDMA has been added, could the boot flow in the firmware linux booting path be simplified to better align with the hardware's actual boot process?
cc Junze, Can you help review this? Thanks!
Thanks,
Chao
Quoted 50 lines
This series includes the following features:
*patch1: add K230 gsdma which supports sdma, gdma is temporarily not supported *patch2: add gsdma to K230 board
*patch3: add K230 gsdma qtest
*patch4: add K230decomp_gzipwhich decompress data work with sdma *patch5: adddecomp_gzipto K230 board
*patch6: add K230decomp_gzipqtest
*patch7: add a noc-stub region in K230 boardThanks
Tao Ding (7):
hw/dma: add K230 gsdma
hw/riscv: k230: add gsdma in K230 board tests/qtest: add test for K230 gsdma hw/misc: add K230 decomp gzip
hw/riscv: k230: add decomp gzip in K230 board tests/qtest: add test for K230 decomp gzip hw/riscv: k230: add a noc stub region in K230 boardhw/dma/Kconfig | 3 + hw/dma/k230_gsdma.c | 532 ++++++++++++++++++++++++++++ hw/dma/meson.build | 1 + hw/dma/trace-events | 6 + hw/misc/Kconfig | 3 + hw/misc/k230_decomp_gzip.c | 498 ++++++++++++++++++++++++++ hw/misc/meson.build | 1 + hw/misc/trace-events | 4 + hw/riscv/Kconfig | 2 + hw/riscv/k230.c | 38 +- include/hw/dma/k230_gsdma.h | 128 +++++++ include/hw/misc/k230_decomp_gzip.h | 92 +++++ include/hw/riscv/k230.h | 5 + tests/qtest/k230-decomp-gzip-test.c | 181 ++++++++++ tests/qtest/k230-gsdma-test.c | 201 +++++++++++ tests/qtest/meson.build | 2 +- 16 files changed, 1689 insertions(+), 8 deletions(-) create mode 100644 hw/dma/k230_gsdma.c create mode 100644 hw/misc/k230_decomp_gzip.c create mode 100644 include/hw/dma/k230_gsdma.h create mode 100644 include/hw/misc/k230_decomp_gzip.h create mode 100644 tests/qtest/k230-decomp-gzip-test.c create mode 100644 tests/qtest/k230-gsdma-test.cbase-commit:
bd6079a7a1d14de0918a7715ef6db85dc32de3bbSignature · 1 line
2.43.0
Quoted 19 lines · Tao Ding
[...]
hw/misc/meson.build | 1 + hw/misc/trace-events | 4 + hw/riscv/Kconfig | 2 + hw/riscv/k230.c | 38 +- include/hw/dma/k230_gsdma.h | 128 +++++++ include/hw/misc/k230_decomp_gzip.h | 92 +++++ include/hw/riscv/k230.h | 5 + tests/qtest/k230-decomp-gzip-test.c | 181 ++++++++++ tests/qtest/k230-gsdma-test.c | 201 +++++++++++ tests/qtest/meson.build | 2 +- 16 files changed, 1689 insertions(+), 8 deletions(-) create mode 100644 hw/dma/k230_gsdma.c create mode 100644 hw/misc/k230_decomp_gzip.c create mode 100644 include/hw/dma/k230_gsdma.h create mode 100644 include/hw/misc/k230_decomp_gzip.h create mode 100644 tests/qtest/k230-decomp-gzip-test.c create mode 100644 tests/qtest/k230-gsdma-test.c
Quoted 3 lines
base-commit:
bd6079a7a1d14de0918a7715ef6db85dc32de3bb--
2.43.0
This series adds K230-specific GSDMA and decompression-GZIP models, but it does not update MAINTAINERS. The existing "K230 Machines" entry does not cover the new source, header, or qtest files.
Signature · 1 line
Junze Cao <[email protected]>