Skip to content

hw/riscv: add SpacemiT K3 Pico-ITX machine#9

Merged
zevorn merged 13 commits into
develfrom
agent/spacemit-k3-linux
Jul 15, 2026
Merged

hw/riscv: add SpacemiT K3 Pico-ITX machine#9
zevorn merged 13 commits into
develfrom
agent/spacemit-k3-linux

Conversation

@zevorn

@zevorn zevorn commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • base the series directly on downstream devel at 90ff589972, with no upstream synchronization merge in the PR
  • add the dedicated spacemit-x100 CPU type as the first K3 patch
  • add the k3-pico-itx machine with eight X100 harts, fixed 2 GiB RAM, ACLINT, APLIC/IMSIC, and UART0
  • model the K3 clock/boot controls, SDHCI controller, SD card attachment, ADMA, and interrupt routing needed by U-Boot
  • cover topology, CPU requirements, address windows, FDT compatibility, timer/Sstc, interrupt routing, UART, SD registers, and SD ADMA with qtests
  • cover both direct Linux boot and OpenSBI -> U-Boot proper -> SD -> Linux with functional tests
  • document both boot paths in the board RST and add K3 to the downstream README.md machine table
  • keep the 11 K3 patches atomic and add two independent downstream CI fixes

Boot paths

The direct path is:

QEMU reset vector -> OpenSBI fw_dynamic.bin -> Linux Image -> initramfs

The firmware path is:

QEMU reset vector -> OpenSBI fw_dynamic.bin -> U-Boot proper -> SD -> Linux

BootROM, bootinfo parsing, SPL, LPDDR training, and HS boot are intentionally out of scope. QEMU supplies initialized RAM and starts generic OpenSBI directly.

Pinned functional-test assets are published at:
https://github.com/zevorn/spacemit-k3-qemu-images/releases/tag/sdk-v1.0.2-qemu2

Review and CI fixes

  • validate root DT compatibility with fdt_node_check_compatible() so compatible string lists are accepted
  • add positive and negative compatible-property qtests
  • require the RVV extension as well as VLEN=256 for every K3 X100 hart, with a TCG negative test for v=false
  • use GLib portable file/spawn APIs and declare the libfdt test dependency for Windows and MinGW builds
  • adapt the machine firmware loading call to the downstream devel API
  • keep the functional Meson list and target RST aligned with the older downstream baseline
  • disable redundant Sphinx builds in the cross-build matrix through EXTRA_CONFIGURE_OPTS=--disable-docs; native CI jobs continue to build documentation
  • backport upstream e03b7dac65d9 so lockless PageFlags readers cannot race with mutable interval-tree bounds; this fixes the aarch64-host vma-pthread Bad address failure without skipping the test

Validation

  • fresh focused riscv64 debug/-Werror build with --disable-docs --disable-gio
  • fresh all-target CI-equivalent build without -Werror (4288/4288 targets)
  • qemu:qtest-riscv64/spacemit-k3-test — 10 subtests passed
  • qemu:func-riscv64-spacemit_k3 with the thorough setup — 2 subtests passed
  • TCG backport stable patch-id matches upstream e03b7dac65d9
  • strict per-commit checkpatch — 13 patches, 0 errors and 0 warnings
  • workflow YAML parse and cross-build option-path review
  • git diff --check origin/devel..HEAD
  • exact DCO audit — all 13 commits contain only Signed-off-by: Chao Liu <[email protected]>
  • independent final, RVV, CI, and TCG backport reviews — clean

@zevorn
zevorn force-pushed the agent/spacemit-k3-linux branch from abaed40 to e11d21e Compare July 14, 2026 02:57
@zevorn
zevorn marked this pull request as ready for review July 14, 2026 07:08
@zevorn

zevorn commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: e11d21ed2f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e88f8e534f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread hw/riscv/spacemit-k3.c Outdated
@zevorn
zevorn force-pushed the agent/spacemit-k3-linux branch 2 times, most recently from 1ccf249 to 681910e Compare July 15, 2026 01:18

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 681910e55e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread hw/riscv/spacemit-k3.c
@zevorn
zevorn force-pushed the agent/spacemit-k3-linux branch from 681910e to 5e89e4b Compare July 15, 2026 01:37
SpacemiT K3 uses eight X100 application harts implementing RVA23S64.
Add a spacemit-x100 vendor CPU with RVH, a 256-bit VLEN, Sv39, and AIA
support so board models can select the hardware CPU directly.

Signed-off-by: Chao Liu <[email protected]>
@zevorn
zevorn force-pushed the agent/spacemit-k3-linux branch from 5e89e4b to 08207c0 Compare July 15, 2026 02:14
zevorn added 10 commits July 15, 2026 10:20
Model the Linux-visible X100 subset with two four-hart RVA23S64
clusters, fixed 2 GiB RAM, a 24 MHz ACLINT, M/S APLIC and IMSIC
controllers, and UART0.

Use the dedicated spacemit-x100 CPU type and keep H disabled for this
Linux-first subset because the VS interrupt path is not modeled.

Support direct Linux boot through generic OpenSBI and an external device
tree. Keep the A100 harts and vendor firmware path outside the current
machine contract.

Signed-off-by: Chao Liu <[email protected]>
Cover the fixed spacemit-x100 CPU type and topology, 256-bit VLEN,
firmware and DRAM windows, 24 MHz timer and Sstc behavior, per-hart M/S
IMSIC routing, and the UART0 interrupt path through the M/S APLIC
hierarchy.

Signed-off-by: Chao Liu <[email protected]>
Boot pinned SDK v1.0.2 artifacts through generic OpenSBI and verify
the Linux-visible platform contract, all eight X100 harts, interrupt
controllers, UART, and the initramfs completion marker.

Use content-addressed assets from the public K3 QEMU image release.

Signed-off-by: Chao Liu <[email protected]>
SDHCI currently clears Transfer Mode DMA unless the controller advertises
SDMA.  This prevents ADMA-only controllers from using DMA even when ADMA1
or ADMA2 is available.

Keep DMA enabled when any implemented DMA engine is advertised.  Check the
SDMA capability in the transfer dispatcher as well, matching the existing
ADMA checks and preventing an ADMA-only controller from selecting SDMA.

Signed-off-by: Chao Liu <[email protected]>
K3 U-Boot reads the boot source from the chip interface unit and programs
the application power management unit while probing SDHCI0.  Unmapped
accesses stop the boot path before storage initialization.

Add narrow CIU and APMU models.  Report SD as the boot source and implement
the SDH0 reset, gate, mux, divider, and self-clearing frequency-change
fields.  Log accesses outside the modeled firmware contract instead of
providing a catch-all register bank.

Signed-off-by: Chao Liu <[email protected]>
K3 SDHCI0 follows the standard version 3 register layout but adds a small
vendor register bank for card-mode and transmit-clock controls.  The generic
SDHCI device cannot expose those registers or the K3 capability set directly.

Add a wrapper which embeds the generic controller, advertises the 3.3 V SD
High Speed and ADMA2 features used by K3 U-Boot, and implements only the
vendor fields touched on that boot path.  Pass the SD bus and interrupt
through so the board can attach storage and route IRQ 99 separately.

Signed-off-by: Chao Liu <[email protected]>
K3 U-Boot proper expects writable on-chip SRAM, a small handoff scratch
window, the SDHCI0 clock and boot controls, and an SD card on the first host.
The machine currently exposes only the reset-vector page and standard RISC-V
platform devices, so firmware cannot reach storage.

Expand the SRAM mapping, add the reset-cleared scratch window, map the K3
control and SDHCI devices, route SDHCI0 interrupt 99 to the APLIC, and attach
legacy SD unit zero.  Keep BootROM, SPL, and DDR training outside the model;
generic OpenSBI continues to load either Linux directly or U-Boot proper.

Signed-off-by: Chao Liu <[email protected]>
The K3 machine now exposes the storage devices required by U-Boot, but the
existing tests cover only the original direct-Linux platform subset.  A
firmware test alone would not localize regressions in reset state, DMA, or AIA
routing.

Extend the machine qtest for the SRAM and boot-control registers, then attach
a deterministic temporary SD image and read its first sector through a
64-bit ADMA2 descriptor above 4 GiB.  Verify the data and route SDHCI0 source
99 through the delegated APLIC to an S-mode IMSIC.

Signed-off-by: Chao Liu <[email protected]>
Describe the Linux-first X100 subset, fixed topology and memory map,
supported interrupt and serial devices, direct OpenSBI boot command, and
current model limitations.

Add the machine and its tests to MAINTAINERS.

Signed-off-by: Chao Liu <[email protected]>
@zevorn
zevorn force-pushed the agent/spacemit-k3-linux branch from 08207c0 to ca42d0c Compare July 15, 2026 02:24
zevorn and others added 2 commits July 15, 2026 10:41
Cross-build jobs validate compilation and installation across container
toolchains. Building the same Sphinx documentation in every container adds
no cross-target coverage and can fail nondeterministically when Sphinx
parallel workers exit with EOFError.

Disable documentation through EXTRA_CONFIGURE_OPTS for the cross-build
matrix. Native jobs continue to build the documentation.

Signed-off-by: Chao Liu <[email protected]>
page_check_range() may race with pageflags_set_clear() when the latter
mutates interval-tree node bounds after a reader has found the node. This
can make a valid guest range appear inaccessible and fail vma-pthread with
Bad address.

Keep node bounds immutable by replacing changed nodes and freeing the old
ones through RCU. Guard lockless readers so they cannot use freed nodes.

This is a downstream backport of upstream commit e03b7da.

Signed-off-by: Chao Liu <[email protected]>
@zevorn
zevorn merged commit 468ac21 into devel Jul 15, 2026
45 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants