Skip to contentSkip to conversation

hw/riscv: Add support for Milk-V Duo board

PATCH In review Kuan-Wei Chiu 3 participants 13 messages Sep 27 – Sep 30

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v5 cover hw/riscv: Add support for Milk-V Duo board

Add initial support for the Milk-V Duo board.

The Sophgo CV1800B SoC features T-Head C906 processing, standard PLIC and CLINT controllers, a dw8250 uart, and basic clock control. The current implementation can successfully run OpenSBI and boot Linux v7.0 from an SD card to the Linux shell.
---
Changes in v5:
- Rebase on master branch.
- dw8250: Split MAINTAINERS entry into a standalone section.
- cv1800b_clk: Use sizeof(uint32_t) for REG_BYTE_WIDTH, check bounds against CV1800B_CLK_IOSIZE, and log guest errors on out-of-bounds accesses.
- boot test: Switch assets from personal github repo to tuxboot.

Changes in v4:
- dw8250: Fix memory access sizes, handle dynamic 'regshift', log unimplemented writes, and propagate errors.
- cv1800b_clk: Replace magic numbers with macros and sizeof().
- cv1800b: Move static properties and child device initialization to instance_init and propagate errp.
- milkv_duo: Use riscv_default_firmware_name(), riscv_load_fdt(), and

             DEFINE_TYPES().

- docs: Add a doc for milk-v duo board.
- tests: Add an end to end boot test.

Changes in v3:
- Rebase on master branch.
- Drop custom T-Head PMU CSR patch to avoid duplication.
- Use REG_BYTE_WIDTH macro in clock controller.

Changes in v2:
- Added link for the custom T-Head PMU CSRs
- Added qtest to validate basic for the dw8250 and clock controller.
- Removed RFC tag.

Kuan-Wei Chiu (7):
hw/char: Add dw8250 UART
hw/misc: Add Sophgo CV1800B clock controller hw/riscv: Add Sophgo CV1800B SoC support
hw/riscv: Add Milk-V Duo board support
tests/qtest: Add qtest for Milk-V Duo board tests/functional/riscv64: Add boot test for Milk-V Duo board docs/system/riscv: Add Milk-V Duo board documentation

 MAINTAINERS                                 |  18 ++
 configs/devices/riscv64-softmmu/default.mak |   1 +
 docs/system/riscv/milkv-duo.rst             |  49 ++++++
 docs/system/target-riscv.rst                |   1 +
 hw/char/Kconfig                             |   4 +
 hw/char/dw8250.c                            | 131 +++++++++++++++
 hw/char/meson.build                         |   1 +
 hw/misc/Kconfig                             |   3 +
 hw/misc/cv1800b_clk.c                       |  98 +++++++++++
 hw/misc/meson.build                         |   1 +
 hw/riscv/Kconfig                            |  14 ++
 hw/riscv/cv1800b.c                          | 177 ++++++++++++++++++++
 hw/riscv/meson.build                        |   3 +
 hw/riscv/milkv_duo.c                        | 118 +++++++++++++
 include/hw/char/dw8250.h                    |  27 +++
 include/hw/misc/cv1800b_clk.h               |  26 +++
 include/hw/riscv/cv1800b.h                  |  56 +++++++
 tests/functional/riscv64/meson.build        |   1 +
 tests/functional/riscv64/test_milkv_duo.py  |  53 ++++++
 tests/qtest/meson.build                     |   3 +-
 tests/qtest/milkv-duo-test.c                |  70 ++++++++
 21 files changed, 854 insertions(+), 1 deletion(-)
 create mode 100644 docs/system/riscv/milkv-duo.rst
 create mode 100644 hw/char/dw8250.c
 create mode 100644 hw/misc/cv1800b_clk.c
 create mode 100644 hw/riscv/cv1800b.c
 create mode 100644 hw/riscv/milkv_duo.c
 create mode 100644 include/hw/char/dw8250.h
 create mode 100644 include/hw/misc/cv1800b_clk.h
 create mode 100644 include/hw/riscv/cv1800b.h
 create mode 100755 tests/functional/riscv64/test_milkv_duo.py
 create mode 100644 tests/qtest/milkv-duo-test.c
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
#1 lore raw

PATCH v5 1/7 hw/char: Add dw8250 UART

Add the dw8250 uart support. This hardware is a widely used 16550A derivative that includes additional registers.

Without this specific device support, the Linux 8250_dw driver fails to probe the extended registers (UCV, CPR, etc.), which are essential for correct feature detection.

---
 MAINTAINERS              |   6 ++
 hw/char/Kconfig          |   4 ++
 hw/char/dw8250.c         | 131 +++++++++++++++++++++++++++++++++++++++
 hw/char/meson.build      |   1 +
 include/hw/char/dw8250.h |  27 ++++++++
 5 files changed, 169 insertions(+)
 create mode 100644 hw/char/dw8250.c
 create mode 100644 include/hw/char/dw8250.h
MAINTAINERS +6 -0
index 6be9c5725b..d4e9cf61ea 100644
@@ -2848,6 +2848,12 @@ S: Maintained
 F: hw/i2c/designware_i2c.c
 F: include/hw/i2c/designware_i2c.h
 
+DesignWare 8250 UART
+M: Kuan-Wei Chiu <[email protected]>
+S: Maintained
+F: hw/char/dw8250.c
+F: include/hw/char/dw8250.h
+
 Generic Loader
 M: Alistair Francis <[email protected]>
 S: Maintained
hw/char/Kconfig +4 -0
index 020c0a84bb..418d99b757 100644
@@ -95,3 +95,7 @@ config IP_OCTAL_232
     bool
     default y
     depends on IPACK
+
+config DW8250
+    bool
+    select SERIAL
hw/char/dw8250.c new file +131 -0

131 lines not on this page · raw message

hw/char/meson.build +1 -0
index fc3d7ee506..b2250ee6ae 100644
@@ -38,6 +38,7 @@ system_ss.add(when: 'CONFIG_STM32L4X5_USART', if_true: files('stm32l4x5_usart.c'
 system_ss.add(when: 'CONFIG_MCHP_PFSOC_MMUART', if_true: files('mchp_pfsoc_mmuart.c'))
 system_ss.add(when: 'CONFIG_HTIF', if_true: files('riscv_htif.c'))
 system_ss.add(when: 'CONFIG_GOLDFISH_TTY', if_true: files('goldfish_tty.c'))
+system_ss.add(when: 'CONFIG_DW8250', if_true: files('dw8250.c'))
 
 specific_ss.add(when: 'CONFIG_TERMINAL3270', if_true: files('terminal3270.c'))
 specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_vty.c'))
include/hw/char/dw8250.h new file +27 -0
new file mode 100644
index 0000000000..59396ad202
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Synopsys DesignWare APB UART (DW 8250)
+ *
+ * Copyright (c) 2026 Kuan-Wei Chiu <[email protected]>
+ */
+
+#ifndef HW_CHAR_DW8250_H
+#define HW_CHAR_DW8250_H
+
+#include "hw/core/sysbus.h"
+#include "qom/object.h"
+
+#define TYPE_DW8250 "dw8250"
+OBJECT_DECLARE_SIMPLE_TYPE(DW8250State, DW8250)
+
+struct DW8250State {
+    SysBusDevice parent_obj;
+
+    MemoryRegion container;
+    MemoryRegion ext_iomem;
+    DeviceState *serial_mm;
+
+    uint8_t regshift;
+};
+
+#endif
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
#5 lore raw

PATCH v5 2/7 hw/misc: Add Sophgo CV1800B clock controller

In reply to Kuan-Wei Chiu

Add a stub for the CV1800B clock controller. This is specifically required for the SDHCI controller to function correctly under Linux.

The Linux 'sophgo,cv1800-clk' driver probes this device to determine the clock tree configuration. This implementation sets the bypass registers (CLK_BYP_0 and CLK_BYP_1) to 0xFFFFFFFF during reset, matching the POR default state. This bypasses the PLLs and allows the SDHCI and other peripherals to operate using the 25MHz reference clock.

Without this device, the SD card driver fails to initialize, preventing the system from mounting the root filesystem from the SD card.

---
 hw/misc/Kconfig               |  3 ++
 hw/misc/cv1800b_clk.c         | 98 +++++++++++++++++++++++++++++++++++
 hw/misc/meson.build           |  1 +
 include/hw/misc/cv1800b_clk.h | 26 ++++++++++
 4 files changed, 128 insertions(+)
 create mode 100644 hw/misc/cv1800b_clk.c
 create mode 100644 include/hw/misc/cv1800b_clk.h
hw/misc/Kconfig +3 -0
index 46e3c03cc8..7abd22869a 100644
@@ -263,4 +263,7 @@ config AXIADO_CLK
 config K230_DECOMP_GZIP
     bool
 
+config SOPHGO_CV1800B_CLK
+    bool
+
 source macio/Kconfig
hw/misc/cv1800b_clk.c new file +98 -0

98 lines not on this page · raw message

hw/misc/meson.build +1 -0
index 9790afa104..244bf278a9 100644
@@ -39,6 +39,7 @@ 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'))
+system_ss.add(when: 'CONFIG_SOPHGO_CV1800B_CLK', if_true: files('cv1800b_clk.c'))
 
 subdir('macio')
 
include/hw/misc/cv1800b_clk.h new file +26 -0
new file mode 100644
index 0000000000..4d03d887c6
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Sophgo CV1800B Clock Controller
+ *
+ * Copyright (c) 2026 Kuan-Wei Chiu <[email protected]>
+ */
+
+#ifndef HW_MISC_CV1800B_CLK_H
+#define HW_MISC_CV1800B_CLK_H
+
+#include "hw/core/sysbus.h"
+#include "qom/object.h"
+
+#define TYPE_CV1800B_CLK "cv1800b-clk"
+OBJECT_DECLARE_SIMPLE_TYPE(CV1800BClkState, CV1800B_CLK)
+
+#define CV1800B_CLK_IOSIZE 0x1000
+
+struct CV1800BClkState {
+    SysBusDevice parent_obj;
+
+    MemoryRegion iomem;
+    uint32_t regs[CV1800B_CLK_IOSIZE / sizeof(uint32_t)];
+};
+
+#endif
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
#7 lore raw

PATCH v5 3/7 hw/riscv: Add Sophgo CV1800B SoC support

In reply to Kuan-Wei Chiu

Add the Sophgo CV1800B SoC, which is the heart of the Milk-V Duo board.

The SoC features a T-Head C906 CPU along with integrated PLIC, CLINT, and dw8250 UART. The memory map and interrupts are configured according to the CV1800B datasheet. [1]

Several peripheral blocks are included as unimplemented devices to ensure that drivers can probe successfully without causing errors during boot.

---
 hw/riscv/Kconfig           |   8 ++
 hw/riscv/cv1800b.c         | 177 +++++++++++++++++++++++++++++++++++++
 hw/riscv/meson.build       |   2 +
 include/hw/riscv/cv1800b.h |  56 ++++++++++++
 4 files changed, 243 insertions(+)
 create mode 100644 hw/riscv/cv1800b.c
 create mode 100644 include/hw/riscv/cv1800b.h
hw/riscv/Kconfig +8 -0
index d06ac26648..b7c0871c67 100644
@@ -164,3 +164,11 @@ config K230
     select K230_WDT
     select K230_GSDMA
     select K230_DECOMP_GZIP
+
+config SOPHGO_CV1800B
+    bool
+    depends on RISCV64
+    select RISCV_ACLINT
+    select SIFIVE_PLIC
+    select SOPHGO_CV1800B_CLK
+    select DW8250
hw/riscv/cv1800b.c new file +177 -0

177 lines not on this page · raw message

hw/riscv/meson.build +2 -0
index 7aa3c1578d..45895486d4 100644
@@ -22,4 +22,6 @@ riscv_ss.add(when: 'CONFIG_RISCV_MIPS_CPS', if_true: files('cps.c'))
 riscv_ss.add(when: 'CONFIG_MIPS_BOSTON_AIA', if_true: files('boston-aia.c'))
 riscv_ss.add(when: 'CONFIG_K230', if_true: files('k230.c'))
 
+riscv_ss.add(when: 'CONFIG_SOPHGO_CV1800B', if_true: files('cv1800b.c'))
+
 hw_arch += {'riscv': riscv_ss}
include/hw/riscv/cv1800b.h new file +56 -0

56 lines not on this page · raw message

Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
#8 lore raw

PATCH v5 4/7 hw/riscv: Add Milk-V Duo board support

In reply to Kuan-Wei Chiu

Add support for the Milk-V Duo development board, which is powered by the Sophgo CV1800B SoC.

The implementation includes:
- Board-level machine initialization with 64mb of default ram.
- Integration of the CV1800B SoC.
- Support for loading external FDT, kernel, and initrd images.
- Proper setup of the reset vector to match the CV1800B's boot flow.

---
 MAINTAINERS                                 |   9 ++
 configs/devices/riscv64-softmmu/default.mak |   1 +
 hw/riscv/Kconfig                            |   6 +
 hw/riscv/meson.build                        |   1 +
 hw/riscv/milkv_duo.c                        | 118 ++++++++++++++++++++
 5 files changed, 135 insertions(+)
 create mode 100644 hw/riscv/milkv_duo.c
MAINTAINERS +9 -0
index d4e9cf61ea..bef8c2f3b0 100644
@@ -1872,6 +1872,15 @@ F: tests/qtest/k230-wdt-test.c
 F: tests/qtest/k230-gsdma-test.c
 F: tests/qtest/k230-decomp-gzip-test.c
 
+Milk-V Duo
+M: Kuan-Wei Chiu <[email protected]>
+S: Maintained
+F: hw/misc/cv1800b_clk.c
+F: hw/riscv/cv1800b.c
+F: hw/riscv/milkv_duo.c
+F: include/hw/misc/cv1800b_clk.h
+F: include/hw/riscv/cv1800b.h
+
 RX Machines
 -----------
 rx-gdbsim
configs/devices/riscv64-softmmu/default.mak +1 -0
index a8e4d0ab33..2ba91b14d4 100644
@@ -13,3 +13,4 @@
 # CONFIG_SHAKTI_C=n
 # CONFIG_XIANGSHAN_KUNMINGHU=n
 # CONFIG_MIPS_BOSTON_AIA=n
+# CONFIG_MILKV_DUO=n
hw/riscv/Kconfig +6 -0
index b7c0871c67..70a331f7ae 100644
@@ -172,3 +172,9 @@ config SOPHGO_CV1800B
     select SIFIVE_PLIC
     select SOPHGO_CV1800B_CLK
     select DW8250
+
+config MILKV_DUO
+    bool
+    depends on RISCV64
+    default y
+    select SOPHGO_CV1800B
hw/riscv/meson.build +1 -0
index 45895486d4..a40e80645b 100644
@@ -23,5 +23,6 @@ riscv_ss.add(when: 'CONFIG_MIPS_BOSTON_AIA', if_true: files('boston-aia.c'))
 riscv_ss.add(when: 'CONFIG_K230', if_true: files('k230.c'))
 
 riscv_ss.add(when: 'CONFIG_SOPHGO_CV1800B', if_true: files('cv1800b.c'))
+riscv_ss.add(when: 'CONFIG_MILKV_DUO', if_true: files('milkv_duo.c'))
 
 hw_arch += {'riscv': riscv_ss}
hw/riscv/milkv_duo.c new file +118 -0

118 lines not on this page · raw message

Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
#9 lore raw

PATCH v5 5/7 tests/qtest: Add qtest for Milk-V Duo board

In reply to Kuan-Wei Chiu

Add minimal qtest coverage for the Milk-V Duo machine to validate basic MMIO mapping and register access.

Currently tested:
- Verify DW8250 UART component version and type signatures.
- Test read/write access to CV1800B clock bypass register.

Tested with:

$ meson test -C build -v qemu:qtest-riscv64/milkv-duo-test
[...]
Ok:                 1
Fail:               0
---
 MAINTAINERS                  |  1 +
 tests/qtest/meson.build      |  3 +-
 tests/qtest/milkv-duo-test.c | 70 ++++++++++++++++++++++++++++++++++++
 3 files changed, 73 insertions(+), 1 deletion(-)
 create mode 100644 tests/qtest/milkv-duo-test.c
MAINTAINERS +1 -0
index bef8c2f3b0..f7e4159679 100644
@@ -1880,6 +1880,7 @@ F: hw/riscv/cv1800b.c
 F: hw/riscv/milkv_duo.c
 F: include/hw/misc/cv1800b_clk.h
 F: include/hw/riscv/cv1800b.h
+F: tests/qtest/milkv-duo-test.c
 
 RX Machines
 -----------
tests/qtest/meson.build +2 -1
index 33f58b0e95..dc76093e24 100644
@@ -309,7 +309,8 @@ qtests_riscv64 = ['riscv-csr-test'] + \
    config_all_devices.has_key('CONFIG_RISCV_IOMMU') ?
    ['iommu-riscv-test'] : []) + \
   (config_all_devices.has_key('CONFIG_K230') ?
-   ['k230-ddr-test', 'k230-wdt-test', 'k230-gsdma-test', 'k230-decomp-gzip-test'] : [])
+   ['k230-ddr-test', 'k230-wdt-test', 'k230-gsdma-test', 'k230-decomp-gzip-test'] : []) + \
+   ['milkv-duo-test']
 
 qtests_hexagon = ['boot-serial-test', 'l2vic-test', 'qct-qtimer-test']
 
tests/qtest/milkv-duo-test.c new file +70 -0

70 lines not on this page · raw message

Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
#12 lore raw

PATCH v5 7/7 docs/system/riscv: Add Milk-V Duo board documentation

In reply to Kuan-Wei Chiu

Add documentation for the Milk-V Duo board. This includes a brief overview of the hardware, a list of supported devices, and practical instructions on how to boot the machine using OpenSBI and a Linux kernel with an emulated SD card.

---
 MAINTAINERS                     |  1 +
 docs/system/riscv/milkv-duo.rst | 49 +++++++++++++++++++++++++++++++++
 docs/system/target-riscv.rst    |  1 +
 3 files changed, 51 insertions(+)
 create mode 100644 docs/system/riscv/milkv-duo.rst
MAINTAINERS +1 -0
index 689424fd1c..027139bde2 100644
@@ -1875,6 +1875,7 @@ F: tests/qtest/k230-decomp-gzip-test.c
 Milk-V Duo
 M: Kuan-Wei Chiu <[email protected]>
 S: Maintained
+F: docs/system/riscv/milkv-duo.rst
 F: hw/misc/cv1800b_clk.c
 F: hw/riscv/cv1800b.c
 F: hw/riscv/milkv_duo.c
docs/system/riscv/milkv-duo.rst new file +49 -0

49 lines not on this page · raw message

docs/system/target-riscv.rst +1 -0
index 2639866a3e..1e49055e29 100644
@@ -69,6 +69,7 @@ undocumented; you can get a complete list by running
    riscv/k230
    riscv/microblaze-v-generic
    riscv/microchip-icicle-kit
+   riscv/milkv-duo
    riscv/mips
    riscv/shakti-c
    riscv/sifive_u
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
#10 lore raw

PATCH v5 6/7 tests/functional/riscv64: Add boot test for Milk-V Duo board

In reply to Kuan-Wei Chiu

Add a functional boot test for the Milk-V Duo board to validate the end-to-end boot flow.

$ ./build/run ./tests/functional/riscv64/test_milkv_duo.py
TAP version 13
ok 1 test_milkv_duo.MilkvDuoMachine.test_riscv64_milkv_duo
1..1
---
 MAINTAINERS                                |  1 +
 tests/functional/riscv64/meson.build       |  1 +
 tests/functional/riscv64/test_milkv_duo.py | 53 ++++++++++++++++++++++
 3 files changed, 55 insertions(+)
 create mode 100755 tests/functional/riscv64/test_milkv_duo.py
MAINTAINERS +1 -0
index f7e4159679..689424fd1c 100644
@@ -1880,6 +1880,7 @@ F: hw/riscv/cv1800b.c
 F: hw/riscv/milkv_duo.c
 F: include/hw/misc/cv1800b_clk.h
 F: include/hw/riscv/cv1800b.h
+F: tests/functional/riscv64/test_milkv_duo.py
 F: tests/qtest/milkv-duo-test.c
 
 RX Machines
tests/functional/riscv64/meson.build +1 -0
index d1a3e6c2bf..8a4f1d00f9 100644
@@ -18,4 +18,5 @@ tests_riscv64_system_thorough = [
   'sifive_u',
   'tt_atlantis',
   'tuxrun',
+  'milkv_duo',
 ]
tests/functional/riscv64/test_milkv_duo.py new file +53 -0

53 lines not on this page · raw message

Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
Acked-by on v5 2/7
#6 lore raw

Re: [PATCH v5 2/7] hw/misc: Add Sophgo CV1800B clock controller

In reply to Kuan-Wei Chiu
Quoted 10 lines · Kuan-Wei Chiu

Add a stub for the CV1800B clock controller. This is specifically required for the SDHCI controller to function correctly under Linux.

The Linux 'sophgo,cv1800-clk' driver probes this device to determine the clock tree configuration. This implementation sets the bypass registers (CLK_BYP_0 and CLK_BYP_1) to 0xFFFFFFFF during reset, matching the POR default state. This bypasses the PLLs and allows the SDHCI and other peripherals to operate using the 25MHz reference clock.

Quoted 5 lines

Without this device, the SD card driver fails to initialize, preventing
the system from mounting the root filesystem from the SD card.

Alistair

Quoted 182 lines

---
 hw/misc/Kconfig               |  3 ++
 hw/misc/cv1800b_clk.c         | 98
+++++++++++++++++++++++++++++++++++
 hw/misc/meson.build           |  1 +
 include/hw/misc/cv1800b_clk.h | 26 ++++++++++

 4 files changed, 128 insertions(+)

 create mode 100644 hw/misc/cv1800b_clk.c
 create mode 100644 include/hw/misc/cv1800b_clk.h

hw/misc/Kconfig +0 -0
index 46e3c03cc8..7abd22869a 100644
@@ -263,4 +263,7 @@ config AXIADO_CLK

 config K230_DECOMP_GZIP
     bool

hw/misc/Kconfig +3 -0
+config SOPHGO_CV1800B_CLK
+    bool
+

 source macio/Kconfig

hw/misc/cv1800b_clk.c new file +16 -0
new file mode 100644
index 0000000000..38807995ac
@@ -0,0 +1,98 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Sophgo CV1800B Clock Controller
+ *
+ * Copyright (c) 2026 Kuan-Wei Chiu <[email protected]>
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/log.h"
+#include "hw/misc/cv1800b_clk.h"
+
+#define REG_BYTE_WIDTH    (sizeof(uint32_t))
+#define REG_CLK_BYP_0     (0x030 / REG_BYTE_WIDTH)
+#define REG_CLK_BYP_1     (0x034 / REG_BYTE_WIDTH)
+
+static uint64_t cv1800b_clk_read(void *opaque, hwaddr addr, unsigned

int size)

hw/misc/cv1800b_clk.c new file +9 -0
+{
+    CV1800BClkState *s = opaque;
+    uint32_t val = 0;
+
+    if (addr < CV1800B_CLK_IOSIZE) {
+        val = s->regs[addr / REG_BYTE_WIDTH];
+    } else {
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "%s: Out-of-bounds read at offset 0x%"

HWADDR_PRIx "\n",
+                      __func__, addr);
+    }

hw/misc/cv1800b_clk.c new file +5 -0
+
+    return val;
+}
+
+static void cv1800b_clk_write(void *opaque, hwaddr addr, uint64_t

val, unsigned int size)

hw/misc/cv1800b_clk.c new file +8 -0
+{
+    CV1800BClkState *s = opaque;
+
+    if (addr < CV1800B_CLK_IOSIZE) {
+        s->regs[addr / REG_BYTE_WIDTH] = val;
+    } else {
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "%s: Out-of-bounds write at offset 0x%"

HWADDR_PRIx "\n",
+                      __func__, addr);
+    }

hw/misc/cv1800b_clk.c new file +21 -0
+}
+
+static const MemoryRegionOps cv1800b_clk_ops = {
+    .read = cv1800b_clk_read,
+    .write = cv1800b_clk_write,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+    .valid = {
+        .min_access_size = 4,
+        .max_access_size = 4,
+    },
+};
+
+static void cv1800b_clk_reset_hold(Object *obj, ResetType type)
+{
+    CV1800BClkState *s = CV1800B_CLK(obj);
+
+    memset(s->regs, 0, sizeof(s->regs));
+
+    /*
+     * TODO: Implement proper PLL state machines.
+     * For now, use POR default to bypass PLLs and boot via 25MHz

XTAL.
+     */
+    s->regs[REG_CLK_BYP_0] = 0xFFFFFFFF;
+    s->regs[REG_CLK_BYP_1] = 0xFFFFFFFF;

hw/misc/cv1800b_clk.c new file +12 -0
+}
+
+static void cv1800b_clk_init(Object *obj)
+{
+    CV1800BClkState *s = CV1800B_CLK(obj);
+
+    memory_region_init_io(&s->iomem, obj, &cv1800b_clk_ops, s,
+                            TYPE_CV1800B_CLK, CV1800B_CLK_IOSIZE);
+    sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
+}
+
+static void cv1800b_clk_class_init(ObjectClass *klass, const void

*data)

hw/misc/cv1800b_clk.c new file +20 -0
+{
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
+
+    rc->phases.hold = cv1800b_clk_reset_hold;
+}
+
+static const TypeInfo cv1800b_clk_info = {
+    .name = TYPE_CV1800B_CLK,
+    .parent = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(CV1800BClkState),
+    .instance_init = cv1800b_clk_init,
+    .class_init = cv1800b_clk_class_init,
+};
+
+static void cv1800b_clk_register_types(void)
+{
+    type_register_static(&cv1800b_clk_info);
+}
+
+type_init(cv1800b_clk_register_types)
hw/misc/meson.build +0 -0
index 9790afa104..244bf278a9 100644
@@ -39,6 +39,7 @@ 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'))
+system_ss.add(when: 'CONFIG_SOPHGO_CV1800B_CLK', if_true:
files('cv1800b_clk.c'))

 subdir('macio')

include/hw/misc/cv1800b_clk.h new file +26 -0
new file mode 100644
index 0000000000..4d03d887c6
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Sophgo CV1800B Clock Controller
+ *
+ * Copyright (c) 2026 Kuan-Wei Chiu <[email protected]>
+ */
+
+#ifndef HW_MISC_CV1800B_CLK_H
+#define HW_MISC_CV1800B_CLK_H
+
+#include "hw/core/sysbus.h"
+#include "qom/object.h"
+
+#define TYPE_CV1800B_CLK "cv1800b-clk"
+OBJECT_DECLARE_SIMPLE_TYPE(CV1800BClkState, CV1800B_CLK)
+
+#define CV1800B_CLK_IOSIZE 0x1000
+
+struct CV1800BClkState {
+    SysBusDevice parent_obj;
+
+    MemoryRegion iomem;
+    uint32_t regs[CV1800B_CLK_IOSIZE / sizeof(uint32_t)];
+};
+
+#endif
Acked-by on v5 6/7
#11 lore raw

Re: [PATCH v5 6/7] tests/functional/riscv64: Add boot test for Milk-V Duo board

In reply to Kuan-Wei Chiu
Quoted 9 lines · Kuan-Wei Chiu

Add a functional boot test for the Milk-V Duo board to validate the end-to-end boot flow.

$ ./build/run ./tests/functional/riscv64/test_milkv_duo.py
TAP version 13
ok 1 test_milkv_duo.MilkvDuoMachine.test_riscv64_milkv_duo
1..1

Alistair

Quoted 101 lines

---
 MAINTAINERS                                |  1 + tests/functional/riscv64/meson.build       |  1 + tests/functional/riscv64/test_milkv_duo.py | 53
++++++++++++++++++++++

 3 files changed, 55 insertions(+)

 create mode 100755 tests/functional/riscv64/test_milkv_duo.py

MAINTAINERS +0 -0
index f7e4159679..689424fd1c 100644
@@ -1880,6 +1880,7 @@ F: hw/riscv/cv1800b.c

 F: hw/riscv/milkv_duo.c
 F: include/hw/misc/cv1800b_clk.h
 F: include/hw/riscv/cv1800b.h
+F: tests/functional/riscv64/test_milkv_duo.py
 F: tests/qtest/milkv-duo-test.c

 RX Machines

tests/functional/riscv64/meson.build +1 -0
index d1a3e6c2bf..8a4f1d00f9 100644
@@ -18,4 +18,5 @@ tests_riscv64_system_thorough = [
    'sifive_u',
    'tt_atlantis',
    'tuxrun',
+  'milkv_duo',

 ]

tests/functional/riscv64/test_milkv_duo.py new file +10 -0
new file mode 100755
index 0000000000..6a7e2a5d19
@@ -0,0 +1,53 @@
+#!/usr/bin/env python3
+#
+# Functional test that boots a Linux kernel on a Milk-V Duo machine
+#
+# Copyright (c) 2026 Kuan-Wei Chiu <[email protected]>
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+from qemu_test import LinuxKernelTest, Asset
+from qemu_test import skipIfMissingCommands,

wait_for_console_pattern

tests/functional/riscv64/test_milkv_duo.py new file +8 -0
+
+class MilkvDuoMachine(LinuxKernelTest):
+
+    timeout = 120
+
+    ASSET_KERNEL = Asset(
+        'https://storage.tuxboot.com/kernels/6.11.9/riscv64/Image',
+       

'174f8bb87f08961e54fa3fcd954a8e31f4645f6d6af4dd43983d5e9841490fb0' +    )
+    ASSET_DTBS = Asset(
+ 'https://storage.tuxboot.com/kernels/6.11.9/riscv64/dtbs.tar.xz', + '97e5e65a7e6c68303e53486af120c0846ee8df572e9c15f0c4dccb831d0cef4b' +    )
+    ASSET_ROOTFS = Asset(
+ 'https://storage.tuxboot.com/buildroot/20241119/riscv64/rootfs.ext4.z st',
+ 'aa4736a9872651dfc0d95e709465eedf1134fd19d42b8cb305bfd776f9801004' +    )

tests/functional/riscv64/test_milkv_duo.py new file +8 -0
+
+    @skipIfMissingCommands('zstd')
+    def test_riscv64_milkv_duo(self):
+        self.set_machine('milkv-duo')
+
+        kernel_path = self.ASSET_KERNEL.fetch()
+        dtb_path = self.archive_extract(
+            self.ASSET_DTBS, member='dtbs/sophgo/cv1800b-milkv-

duo.dtb')
+        rootfs_path = self.uncompress(self.ASSET_ROOTFS) +
+        self.vm.set_console()
+        self.vm.add_args('-bios', 'default',
+                         '-kernel', kernel_path,
+                         '-dtb', dtb_path,
+                         '-drive', f'file={rootfs_path},format=raw,id=sd-card,snapshot=on', +                         '-device', 'sd-card,drive=sd-card', +                         '-append', 'console=ttyS0,115200 root=/dev/mmcblk0 rootwait earlycon')

tests/functional/riscv64/test_milkv_duo.py new file +9 -0
+
+        self.vm.launch()
+
+        wait_for_console_pattern(self, 'Machine model: Milk-V Duo')
+        wait_for_console_pattern(self, 'Welcome to TuxTest')
+        wait_for_console_pattern(self, 'tuxtest login:')
+
+if __name__ == '__main__':
+    LinuxKernelTest.main()
#2 lore raw

Re: [PATCH v5 1/7] hw/char: Add dw8250 UART

In reply to Kuan-Wei Chiu
Quoted 48 lines · Kuan-Wei Chiu

Add the dw8250 uart support. This hardware is a widely used 16550A derivative that includes additional registers.

Without this specific device support, the Linux 8250_dw driver fails to
probe the extended registers (UCV, CPR, etc.), which are essential for
correct feature detection.

---
 MAINTAINERS              |   6 ++
 hw/char/Kconfig          |   4 ++
 hw/char/dw8250.c         | 131
+++++++++++++++++++++++++++++++++++++++
 hw/char/meson.build      |   1 +
 include/hw/char/dw8250.h |  27 ++++++++

 5 files changed, 169 insertions(+)

 create mode 100644 hw/char/dw8250.c
 create mode 100644 include/hw/char/dw8250.h

MAINTAINERS +0 -0
index 6be9c5725b..d4e9cf61ea 100644
@@ -2848,6 +2848,12 @@ S: Maintained

 F: hw/i2c/designware_i2c.c
 F: include/hw/i2c/designware_i2c.h

MAINTAINERS +6 -0
+DesignWare 8250 UART
+M: Kuan-Wei Chiu <[email protected]>
+S: Maintained
+F: hw/char/dw8250.c
+F: include/hw/char/dw8250.h
+

 Generic Loader
 M: Alistair Francis <[email protected]>
 S: Maintained

hw/char/Kconfig +0 -0
index 020c0a84bb..418d99b757 100644
@@ -95,3 +95,7 @@ config IP_OCTAL_232

     bool
     default y
     depends on IPACK

hw/char/Kconfig config IP_OCTAL_232 · line 101

Quoted 4 lines
hw/char/Kconfig +4 -0
+
+config DW8250
+    bool
+    select SERIAL

This should be SERIAL_MM as you use "serial-mm" in the driver.

I'll just rename this when I apply it as SERIAL_MM selects SERIAL

Alistair

Quoted 199 lines
hw/char/dw8250.c new file +17 -0
new file mode 100644
index 0000000000..ccf05dd9ad
@@ -0,0 +1,131 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Synopsys DesignWare APB UART (DW 8250)
+ *
+ * Copyright (c) 2026 Kuan-Wei Chiu <[email protected]>
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/log.h"
+#include "qapi/error.h"
+#include "hw/char/dw8250.h"
+#include "hw/core/qdev-properties.h"
+#include "hw/core/qdev-properties-system.h"
+
+#define DW_UART_REGION_SIZE 0x100
+
+#define DW_UART_RE_EN (0xB4 >> 2) /* Receiver Output Enable Register

*/
+#define DW_UART_DLF   (0xC0 >> 2) /* Divisor Latch Fraction Register */

hw/char/dw8250.c new file +8 -0
+#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 */
+
+#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)

hw/char/dw8250.c new file +8 -0
+{
+    DW8250State *s = opaque;
+
+    switch (addr >> s->regshift) {
+    case DW_UART_UCV:
+        return DW_UART_UCV_VALUE;
+    case DW_UART_CPR:
+        return 0x00000000; /* No advanced features (DMA, extra

FIFOs) */
+    case DW_UART_CTR:
+        return DW_UART_CTR_VALUE;

hw/char/dw8250.c new file +15 -0
+
+    case DW_UART_RE_EN:
+    case DW_UART_DLF:
+        /*
+         * Return 0 to indicate these optional features
+         * (RS485 and Fractional Divisor) are not implemented.
+         */
+        return 0x00000000;
+
+    default:
+        return 0;
+    }
+}
+
+static void dw8250_ext_write(void *opaque, hwaddr addr, uint64_t

val, unsigned int size)
+{
+    qemu_log_mask(LOG_UNIMP, "%s: Unimplemented write to address 0x%" HWADDR_PRIx "\n",
+                  __func__, addr);

hw/char/dw8250.c new file +22 -0
+}
+
+static const MemoryRegionOps dw8250_ext_ops = {
+    .read = dw8250_ext_read,
+    .write = dw8250_ext_write,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+    .impl = {
+        .min_access_size = 4,
+        .max_access_size = 4,
+    },
+    .valid = {
+        .min_access_size = 1,
+        .max_access_size = 4,
+    },
+};
+
+static void dw8250_instance_init(Object *obj)
+{
+    DW8250State *s = DW8250(obj);
+
+    s->serial_mm = qdev_new("serial-mm");
+    object_property_add_child(obj, "serial-mm", OBJECT(s-
Quoted 1 line

serial_mm));

+    object_property_add_alias(obj, "chardev", OBJECT(s->serial_mm), "chardev");

hw/char/dw8250.c new file +9 -0
+}
+
+static void dw8250_realize(DeviceState *dev, Error **errp)
+{
+    DW8250State *s = DW8250(dev);
+    SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
+    SysBusDevice *serial_sbd = SYS_BUS_DEVICE(s->serial_mm);
+
+    memory_region_init(&s->container, OBJECT(dev), "dw8250-

container",
+                       DW_UART_REGION_SIZE);
+    sysbus_init_mmio(sbd, &s->container);
+
+    qdev_prop_set_uint8(s->serial_mm, "regshift", s->regshift); +    qdev_prop_set_uint8(s->serial_mm, "endianness", DEVICE_LITTLE_ENDIAN);
+    if (!sysbus_realize(serial_sbd, errp)) {
+        return;
+    }
+
+    memory_region_init_io(&s->ext_iomem, OBJECT(dev), &dw8250_ext_ops, s,
+                          "dw8250-ext", DW_UART_REGION_SIZE); +    memory_region_add_subregion(&s->container, 0, &s->ext_iomem); +
+    memory_region_add_subregion_overlap(&s->container, 0, +
sysbus_mmio_get_region(serial_sbd, 0), 1);

hw/char/dw8250.c new file +30 -0
+
+    sysbus_pass_irq(sbd, serial_sbd);
+}
+
+static const Property dw8250_properties[] = {
+    DEFINE_PROP_UINT8("regshift", DW8250State, regshift, 2),
+};
+
+static void dw8250_class_init(ObjectClass *klass, const void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->realize = dw8250_realize;
+    device_class_set_props(dc, dw8250_properties);
+}
+
+static const TypeInfo dw8250_info = {
+    .name          = TYPE_DW8250,
+    .parent        = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(DW8250State),
+    .instance_init = dw8250_instance_init,
+    .class_init    = dw8250_class_init,
+};
+
+static void dw8250_register_types(void)
+{
+    type_register_static(&dw8250_info);
+}
+
+type_init(dw8250_register_types)
hw/char/meson.build +0 -0
index fc3d7ee506..b2250ee6ae 100644
@@ -38,6 +38,7 @@ system_ss.add(when: 'CONFIG_STM32L4X5_USART',

if_true: files('stm32l4x5_usart.c'
 system_ss.add(when: 'CONFIG_MCHP_PFSOC_MMUART', if_true:
files('mchp_pfsoc_mmuart.c'))
 system_ss.add(when: 'CONFIG_HTIF', if_true: files('riscv_htif.c')) system_ss.add(when: 'CONFIG_GOLDFISH_TTY', if_true:
files('goldfish_tty.c'))
+system_ss.add(when: 'CONFIG_DW8250', if_true: files('dw8250.c'))
 specific_ss.add(when: 'CONFIG_TERMINAL3270', if_true:
files('terminal3270.c'))
 specific_ss.add(when: 'CONFIG_PSERIES', if_true:
files('spapr_vty.c'))

include/hw/char/dw8250.h new file +27 -0
new file mode 100644
index 0000000000..59396ad202
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Synopsys DesignWare APB UART (DW 8250)
+ *
+ * Copyright (c) 2026 Kuan-Wei Chiu <[email protected]>
+ */
+
+#ifndef HW_CHAR_DW8250_H
+#define HW_CHAR_DW8250_H
+
+#include "hw/core/sysbus.h"
+#include "qom/object.h"
+
+#define TYPE_DW8250 "dw8250"
+OBJECT_DECLARE_SIMPLE_TYPE(DW8250State, DW8250)
+
+struct DW8250State {
+    SysBusDevice parent_obj;
+
+    MemoryRegion container;
+    MemoryRegion ext_iomem;
+    DeviceState *serial_mm;
+
+    uint8_t regshift;
+};
+
+#endif
#3 lore raw

Re: [PATCH v5 1/7] hw/char: Add dw8250 UART

In reply to Kuan-Wei Chiu

Hello,

Seems like we have a mem leak down there:

Quoted 121 lines · Kuan-Wei Chiu

Add the dw8250 uart support. This hardware is a widely used 16550A derivative that includes additional registers.

Without this specific device support, the Linux 8250_dw driver fails to probe the extended registers (UCV, CPR, etc.), which are essential for correct feature detection.

---
  MAINTAINERS              |   6 ++
  hw/char/Kconfig          |   4 ++
  hw/char/dw8250.c         | 131 +++++++++++++++++++++++++++++++++++++++
  hw/char/meson.build      |   1 +
  include/hw/char/dw8250.h |  27 ++++++++
  5 files changed, 169 insertions(+)

create mode 100644 hw/char/dw8250.c
create mode 100644 include/hw/char/dw8250.h

MAINTAINERS +6 -0
index 6be9c5725b..d4e9cf61ea 100644
@@ -2848,6 +2848,12 @@ S: Maintained
  F: hw/i2c/designware_i2c.c
  F: include/hw/i2c/designware_i2c.h
 
+DesignWare 8250 UART
+M: Kuan-Wei Chiu <[email protected]>
+S: Maintained
+F: hw/char/dw8250.c
+F: include/hw/char/dw8250.h
+
  Generic Loader
  M: Alistair Francis <[email protected]>
  S: Maintained
hw/char/Kconfig +4 -0
index 020c0a84bb..418d99b757 100644
@@ -95,3 +95,7 @@ config IP_OCTAL_232
      bool
      default y
      depends on IPACK
+
+config DW8250
+    bool
+    select SERIAL
hw/char/dw8250.c new file +66 -0
new file mode 100644
index 0000000000..ccf05dd9ad
@@ -0,0 +1,131 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Synopsys DesignWare APB UART (DW 8250)
+ *
+ * Copyright (c) 2026 Kuan-Wei Chiu <[email protected]>
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/log.h"
+#include "qapi/error.h"
+#include "hw/char/dw8250.h"
+#include "hw/core/qdev-properties.h"
+#include "hw/core/qdev-properties-system.h"
+
+#define DW_UART_REGION_SIZE 0x100
+
+#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 */
+
+#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;
+
+    switch (addr >> s->regshift) {
+    case DW_UART_UCV:
+        return DW_UART_UCV_VALUE;
+    case DW_UART_CPR:
+        return 0x00000000; /* No advanced features (DMA, extra FIFOs) */
+    case DW_UART_CTR:
+        return DW_UART_CTR_VALUE;
+
+    case DW_UART_RE_EN:
+    case DW_UART_DLF:
+        /*
+         * Return 0 to indicate these optional features
+         * (RS485 and Fractional Divisor) are not implemented.
+         */
+        return 0x00000000;
+
+    default:
+        return 0;
+    }
+}
+
+static void dw8250_ext_write(void *opaque, hwaddr addr, uint64_t val, unsigned int size)
+{
+    qemu_log_mask(LOG_UNIMP, "%s: Unimplemented write to address 0x%" HWADDR_PRIx "\n",
+                  __func__, addr);
+}
+
+static const MemoryRegionOps dw8250_ext_ops = {
+    .read = dw8250_ext_read,
+    .write = dw8250_ext_write,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+    .impl = {
+        .min_access_size = 4,
+        .max_access_size = 4,
+    },
+    .valid = {
+        .min_access_size = 1,

hw/char/dw8250.c line 76

Quoted 10 lines
hw/char/dw8250.c new file +10 -0
+        .max_access_size = 4,
+    },
+};
+
+static void dw8250_instance_init(Object *obj)
+{
+    DW8250State *s = DW8250(obj);
+
+    s->serial_mm = qdev_new("serial-mm");
+    object_property_add_child(obj, "serial-mm", OBJECT(s->serial_mm));

^ here. s->serial_mm is being alloc in qdev_new() and then during object_property_add_child().

This is being fixed by Portia in another patch:

[PATCH 1/5] hw/char/dw8250: Fix leak when creating child device
https://lore.kernel.org/qemu-devel/[email protected]/

Given that this isn't merged yet I suggest fixing the leak in this patch instead.

Thanks,
Daniel

Quoted 100 lines
hw/char/dw8250.c new file +55 -0
+    object_property_add_alias(obj, "chardev", OBJECT(s->serial_mm), "chardev");
+}
+
+static void dw8250_realize(DeviceState *dev, Error **errp)
+{
+    DW8250State *s = DW8250(dev);
+    SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
+    SysBusDevice *serial_sbd = SYS_BUS_DEVICE(s->serial_mm);
+
+    memory_region_init(&s->container, OBJECT(dev), "dw8250-container",
+                       DW_UART_REGION_SIZE);
+    sysbus_init_mmio(sbd, &s->container);
+
+    qdev_prop_set_uint8(s->serial_mm, "regshift", s->regshift);
+    qdev_prop_set_uint8(s->serial_mm, "endianness", DEVICE_LITTLE_ENDIAN);
+    if (!sysbus_realize(serial_sbd, errp)) {
+        return;
+    }
+
+    memory_region_init_io(&s->ext_iomem, OBJECT(dev), &dw8250_ext_ops, s,
+                          "dw8250-ext", DW_UART_REGION_SIZE);
+    memory_region_add_subregion(&s->container, 0, &s->ext_iomem);
+
+    memory_region_add_subregion_overlap(&s->container, 0,
+                                        sysbus_mmio_get_region(serial_sbd, 0), 1);
+
+    sysbus_pass_irq(sbd, serial_sbd);
+}
+
+static const Property dw8250_properties[] = {
+    DEFINE_PROP_UINT8("regshift", DW8250State, regshift, 2),
+};
+
+static void dw8250_class_init(ObjectClass *klass, const void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->realize = dw8250_realize;
+    device_class_set_props(dc, dw8250_properties);
+}
+
+static const TypeInfo dw8250_info = {
+    .name          = TYPE_DW8250,
+    .parent        = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(DW8250State),
+    .instance_init = dw8250_instance_init,
+    .class_init    = dw8250_class_init,
+};
+
+static void dw8250_register_types(void)
+{
+    type_register_static(&dw8250_info);
+}
+
+type_init(dw8250_register_types)
hw/char/meson.build +1 -0
index fc3d7ee506..b2250ee6ae 100644
@@ -38,6 +38,7 @@ system_ss.add(when: 'CONFIG_STM32L4X5_USART', if_true: files('stm32l4x5_usart.c'
  system_ss.add(when: 'CONFIG_MCHP_PFSOC_MMUART', if_true: files('mchp_pfsoc_mmuart.c'))
  system_ss.add(when: 'CONFIG_HTIF', if_true: files('riscv_htif.c'))
  system_ss.add(when: 'CONFIG_GOLDFISH_TTY', if_true: files('goldfish_tty.c'))
+system_ss.add(when: 'CONFIG_DW8250', if_true: files('dw8250.c'))
 
  specific_ss.add(when: 'CONFIG_TERMINAL3270', if_true: files('terminal3270.c'))
  specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_vty.c'))
include/hw/char/dw8250.h new file +27 -0
new file mode 100644
index 0000000000..59396ad202
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Synopsys DesignWare APB UART (DW 8250)
+ *
+ * Copyright (c) 2026 Kuan-Wei Chiu <[email protected]>
+ */
+
+#ifndef HW_CHAR_DW8250_H
+#define HW_CHAR_DW8250_H
+
+#include "hw/core/sysbus.h"
+#include "qom/object.h"
+
+#define TYPE_DW8250 "dw8250"
+OBJECT_DECLARE_SIMPLE_TYPE(DW8250State, DW8250)
+
+struct DW8250State {
+    SysBusDevice parent_obj;
+
+    MemoryRegion container;
+    MemoryRegion ext_iomem;
+    DeviceState *serial_mm;
+
+    uint8_t regshift;
+};
+
+#endif
#4 lore raw

Re: [PATCH v5 1/7] hw/char: Add dw8250 UART

Quoted 152 lines · Daniel Henrique Barboza

Hello,

Seems like we have a mem leak down there:

Quoted 141 lines · Kuan-Wei Chiu

Add the dw8250 uart support. This hardware is a widely used 16550A derivative that includes additional registers.

Without this specific device support, the Linux 8250_dw driver fails to
probe the extended registers (UCV, CPR, etc.), which are essential for
correct feature detection.

---
  MAINTAINERS              |   6 ++
  hw/char/Kconfig          |   4 ++
  hw/char/dw8250.c         | 131
+++++++++++++++++++++++++++++++++++++++
  hw/char/meson.build      |   1 +
  include/hw/char/dw8250.h |  27 ++++++++

  5 files changed, 169 insertions(+)

  create mode 100644 hw/char/dw8250.c
  create mode 100644 include/hw/char/dw8250.h

MAINTAINERS +0 -0
index 6be9c5725b..d4e9cf61ea 100644
@@ -2848,6 +2848,12 @@ S: Maintained

  F: hw/i2c/designware_i2c.c
  F: include/hw/i2c/designware_i2c.h

MAINTAINERS +6 -0
+DesignWare 8250 UART
+M: Kuan-Wei Chiu <[email protected]>
+S: Maintained
+F: hw/char/dw8250.c
+F: include/hw/char/dw8250.h
+

  Generic Loader
  M: Alistair Francis <[email protected]>
  S: Maintained

hw/char/Kconfig +0 -0
index 020c0a84bb..418d99b757 100644
@@ -95,3 +95,7 @@ config IP_OCTAL_232

      bool
      default y
      depends on IPACK

hw/char/Kconfig +4 -0
+
+config DW8250
+    bool
+    select SERIAL
hw/char/dw8250.c new file +17 -0
new file mode 100644
index 0000000000..ccf05dd9ad
@@ -0,0 +1,131 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Synopsys DesignWare APB UART (DW 8250)
+ *
+ * Copyright (c) 2026 Kuan-Wei Chiu <[email protected]>
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/log.h"
+#include "qapi/error.h"
+#include "hw/char/dw8250.h"
+#include "hw/core/qdev-properties.h"
+#include "hw/core/qdev-properties-system.h"
+
+#define DW_UART_REGION_SIZE 0x100
+
+#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 */

hw/char/dw8250.c new file +7 -0
+#define DW_UART_UCV   (0xF8 >> 2) /* UART Component Version */
+#define DW_UART_CTR   (0xFC >> 2) /* Component Type Register */
+
+#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)

hw/char/dw8250.c new file +8 -0
+{
+    DW8250State *s = opaque;
+
+    switch (addr >> s->regshift) {
+    case DW_UART_UCV:
+        return DW_UART_UCV_VALUE;
+    case DW_UART_CPR:
+        return 0x00000000; /* No advanced features (DMA, extra

FIFOs) */
+    case DW_UART_CTR:
+        return DW_UART_CTR_VALUE;

hw/char/dw8250.c new file +15 -0
+
+    case DW_UART_RE_EN:
+    case DW_UART_DLF:
+        /*
+         * Return 0 to indicate these optional features
+         * (RS485 and Fractional Divisor) are not implemented.
+         */
+        return 0x00000000;
+
+    default:
+        return 0;
+    }
+}
+
+static void dw8250_ext_write(void *opaque, hwaddr addr, uint64_t

val, unsigned int size)
+{
+    qemu_log_mask(LOG_UNIMP, "%s: Unimplemented write to address 0x%" HWADDR_PRIx "\n",
+                  __func__, addr);

hw/char/dw8250.c new file +22 -0
+}
+
+static const MemoryRegionOps dw8250_ext_ops = {
+    .read = dw8250_ext_read,
+    .write = dw8250_ext_write,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+    .impl = {
+        .min_access_size = 4,
+        .max_access_size = 4,
+    },
+    .valid = {
+        .min_access_size = 1,
+        .max_access_size = 4,
+    },
+};
+
+static void dw8250_instance_init(Object *obj)
+{
+    DW8250State *s = DW8250(obj);
+
+    s->serial_mm = qdev_new("serial-mm");
+    object_property_add_child(obj, "serial-mm", OBJECT(s-
Quoted 1 line
Quoted 1 line

serial_mm));

^ here. s->serial_mm is being alloc in qdev_new() and then during object_property_add_child().

Quoted 8 lines

This is being fixed by Portia in another patch:

[PATCH 1/5] hw/char/dw8250: Fix leak when creating child device
https://lore.kernel.org/qemu-devel/[email protected]/

Given that this isn't merged yet I suggest fixing the leak in this patch instead.

I've pulled in Portia's patch and squashed it. It's a pretty simple fix and as it's already in my tree it's an easy fix

Alistair