RISC-V: Add Vega machine support for upstream QEMU
Subsystems (2)
PATCH 1/1 RISC-V: Add Vega machine support for upstream QEMU
Dear QEMU Maintainers,
This patch adds support for the Vega RISC-V machine model, developed as part of the Vega multicore platform at C-DAC, Thiruvananthapuram.
The Vega machine includes:
- Multi-core CPU configuration
- PLIC and ACLINT interrupt controllers
- DRAM and MMIO memory mapping
- UART and Timer initialization
The Vega platform functionality was verified on the 64-bit QEMU build by:
- Successfully booting a Linux image using the Berkeley Boot Loader (BBL)
- Running bare-metal example programs from the Vega SDK
---
For reference:
This patch submission is being sent to the official QEMU mailing list ([email protected], [email protected]) as part of our effort to
upstream the Vega RISC-V machine model developed under the Microprocessor Development Programme.
Best regards,
Karthika B
Project Engineer, HDG
C-DAC, Thiruvananthapuram
------------------------------------------------------------------------------------------------------------
[ C-DAC is on Social-Media too. Kindly follow us at:
Facebook: https://www.facebook.com/CDACINDIA & Twitter: @cdacindia ]
This e-mail is for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies and the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email is strictly prohibited and appropriate legal action will be taken.
------------------------------------------------------------------------------------------------------------
From c8218a7fc727b30f45516ffe2baeea819a9d5df3 Mon Sep 17 00:00:00 2001
From: Karthika B <[email protected]>
Date: Thu, 23 Oct 2025 15:07:57 +0530
Subject: [PATCH] riscv: Add Vega board support
This patch adds support for the Vega RISC-V machine model.
The Vega machine includes:
- Multi-core CPU configuration
- PLIC and ACLINT interrupt controllers
- DRAM and MMIO memory mapping
- UART and timer initialization
The Vega platform was verified to boot Vega SDK images successfully on both 32-bit and 64-bit QEMU builds.
--- README.md | 55 + configs/devices/riscv64-softmmu/default.mak | 1 + hw/intc/Kconfig | 7 + hw/intc/meson.build | 2 + hw/intc/vega_aclint.c | 551 +++++ hw/intc/vega_plic.c | 496 +++++ hw/riscv/Kconfig | 28 + hw/riscv/meson.build | 1 + hw/riscv/vega.c | 2076 +++++++++++++++++++ include/hw/intc/vega_aclint.h | 67 + include/hw/intc/vega_plic.h | 70 + include/hw/riscv/vega.h | 166 ++ 12 files changed, 3520 insertions(+) create mode 100644 README.md create mode 100644 hw/intc/vega_aclint.c create mode 100644 hw/intc/vega_plic.c create mode 100644 hw/riscv/vega.c create mode 100644 include/hw/intc/vega_aclint.h create mode 100644 include/hw/intc/vega_plic.h create mode 100644 include/hw/riscv/vega.h
README.md new file +55 -0
@@ -0,0 +1,55 @@ +# QEMU for Vega Machine +========================= + +This is a custom QEMU fork for simulating the RISC-V Vega multicore platform. + +## Features +============ +- Custom `vega` machine with multi-hart support +- Support for bare-metal and Linux kernel boot +- Custom ACLINT and PLIC integration +- `-M vega,baremetal=on` runtime option for selecting UART IRQ +- dram-base=0x0 runtime option for dram base address + +## Usage +======== + +#Build QEMU for 64-bit system +----------------------------- +./configure --target-list=riscv64-softmmu +make + +#FOR BARE METAL PROGRAM @DRAM_BASE 0X80000000 +-------------------------------------------- +./build/qemu-system-riscv64 -M vega,dram-base=0x80000000,baremetal-mode=on -smp 1 -m 2G -kernel spikedbg_8c -bios none -display none -serial stdio + +#FOR BARE METAL PROGRAM @DRAM_BASE 0X400000000 +--------------------------------------------- +./build/qemu-system-riscv64 -M vega,dram-base=0x400000000,baremetal-mode=on -smp 1 -m 2G -kernel spikedbg_40c -bios none -display none -serial stdio + +#FOR BOOTING LINUX(bbl) @DRAM_BASE 0X80000000 +-------------------------------------------- +./build/qemu-system-riscv64 -M vega,dram-base=0x80000000 -smp 4 -m 2G -display none -serial stdio -bios none -kernel bbl_8c -initrd rootfs.cpio -append "root=/dev/ram" -cpu rva23s64 + +#FOR BOOTING LINUX(bbl) @DRAM_BASE 0X400000000 +--------------------------------------------- +./build/qemu-system-riscv64 -M vega,dram-base=0x400000000 -smp 4 -m 2G -display none -serial stdio -bios none -kernel bbl_40c -initrd rootfs.cpio -append "root=/dev/ram" -cpu rva23s64 + +##FOR BOOTING U-BOOT (2025.07) @DRAM_BASE 0X80000000 +---------------------------------------------------- +./build_64/qemu-system-riscv64 -M vega,baremetal-mode=on,dram-base=0x80000000 -smp 1 -m 2G -kernel fw_payload.elf -bios none -display none -serial stdio -cpu rva23s64 + + +#Build QEMU for 32-bit system +---------------------------- +./configure --target-list=riscv32-softmmu +make + +#FOR BARE METAL PROGRAM @DRAM_BASE 0x200000 (FOR ARIES) +------------------------------------------------------ +./build/qemu-system-riscv32 -M vega,dram-base=0x200000,baremetal-mode=on -smp 1 -m 2G -kernel hello.elf -bios none -display none -serial stdio + +##Debug in Qemu with GDB support +================================ +Refer the user guide in the folder debug_guide/ (NOT UPDATED) +
configs/devices/riscv64-softmmu/default.mak +1 -0
@@ -12,3 +12,4 @@ # CONFIG_MICROCHIP_PFSOC=n # CONFIG_SHAKTI_C=n # CONFIG_XIANGSHAN_KUNMINGHU=n +# CONFIG_VEGA=n
hw/intc/Kconfig +7 -0
@@ -109,3 +109,10 @@ config LOONGARCH_PCH_MSI config LOONGARCH_EXTIOI bool + +config VEGA_ACLINT + bool + +config VEGA_PLIC + bool + select MSI_NONBROKEN
hw/intc/meson.build +2 -0
@@ -61,6 +61,8 @@ specific_ss.add(when: 'CONFIG_RISCV_APLIC', if_true: files('riscv_aplic.c')) specific_ss.add(when: 'CONFIG_RISCV_IMSIC', if_true: files('riscv_imsic.c')) specific_ss.add(when: 'CONFIG_SIFIVE_PLIC', if_true: files('sifive_plic.c')) specific_ss.add(when: 'CONFIG_XICS', if_true: files('xics.c', 'xive2.c')) +specific_ss.add(when: 'CONFIG_VEGA_ACLINT', if_true: files('vega_aclint.c')) +specific_ss.add(when: 'CONFIG_VEGA_PLIC', if_true: files('vega_plic.c')) specific_ss.add(when: ['CONFIG_KVM', 'CONFIG_XICS'], if_true: files('xics_kvm.c')) specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('xics_spapr.c', 'spapr_xive.c'))
hw/intc/vega_aclint.c new file +551 -0
551 lines not on this page · raw message
hw/intc/vega_plic.c new file +496 -0
497 lines not on this page · raw message
hw/riscv/Kconfig +28 -0
@@ -128,3 +128,31 @@ config XIANGSHAN_KUNMINGHU select RISCV_APLIC select RISCV_IMSIC select SERIAL_MM + +config VEGA + bool + default y + depends on RISCV32 || RISCV64 + imply PCI_DEVICES + imply VIRTIO_VGA + imply TEST_DEVICES + imply TPM_TIS_SYSBUS + select DEVICE_TREE + select RISCV_NUMA + select GOLDFISH_RTC + select PCI + select PCI_EXPRESS_GENERIC_BRIDGE + select PFLASH_CFI01 + select SERIAL_MM + select VEGA_ACLINT + select RISCV_APLIC + select RISCV_IOMMU + select RISCV_IMSIC + select VEGA_PLIC + select SIFIVE_TEST + select SMBIOS + select VIRTIO_MMIO + select FW_CFG_DMA + select PLATFORM_BUS + select ACPI + select ACPI_PCI
hw/riscv/meson.build +1 -0
@@ -14,5 +14,6 @@ riscv_ss.add(when: 'CONFIG_RISCV_IOMMU', if_true: files( 'riscv-iommu.c', 'riscv-iommu-pci.c', 'riscv-iommu-sys.c', 'riscv-iommu-hpm.c')) riscv_ss.add(when: 'CONFIG_MICROBLAZE_V', if_true: files('microblaze-v-generic.c')) riscv_ss.add(when: 'CONFIG_XIANGSHAN_KUNMINGHU', if_true: files('xiangshan_kmh.c')) +riscv_ss.add(when: 'CONFIG_VEGA', if_true: files('vega.c')) hw_arch += {'riscv': riscv_ss}
hw/riscv/vega.c new file +2076 -0
1,838 lines not on this page · raw message
include/hw/intc/vega_aclint.h new file +67 -0
67 lines not on this page · raw message
include/hw/intc/vega_plic.h new file +70 -0
70 lines not on this page · raw message
include/hw/riscv/vega.h new file +166 -0
166 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.43.0
Part of the diff is not shown here. View the raw message.
cover RISC-V: Add CDAC VEGA machine support
This series adds QEMU machine support for VEGA, a RISC-V SoC family developed by C-DAC (Centre for Development of Advanced Computing, India) as part of the DIR-V processor program.
VEGA series of microprocessors are developed as part of the Microprocessor Development Programme, initiated and funded by MeitY (Ministry of Electronics and Information Technology, Government of India), with the mission objective to design and develop indigenously a family of microprocessors, related IPs, and the complete ecosystem to enable fully indigenous product development catering to various requirements in the strategic, industrial, and commercial sectors. VEGA is developed at C-DAC, Thiruvananthapuram.
Background
----------
VEGA is a series of 32-bit and 64-bit single/multi-core RISC-V processors (Thejas32 and Thejas64) developed under the DIR-V program, integrated with multi-level caches, an MMU, and a coherent interconnect on real silicon. This series adds a QEMU 'vega' machine model supporting both the Thejas32 (RV32) and Thejas64 (RV64) variants, modelled on real silicon behaviour rather than a synthetic/virtual platform.
More details on the VEGA processor series:
https://vegaprocessors.in/
VEGA documentation:
https://cdac-vega.gitlab.io/
The model has been validated against Aries boards (Thejas32) and Thejas64 SoCs, booting:
- bare-metal ELF payloads via -bios (no DTB, fixed UART framing), for both RV32 and RV64, using the VEGA SDK's example UART "hello world" application
- Linux via BBL with a user-supplied -dtb describing the SoC (RV64)
What's included
----------------
- hw/riscv/vega.c - machine model, device creation, boot flow.
Note: VEGA does not generate its device tree internally; -dtb is required for any -kernel boot (see note below)
- hw/intc/vega_plic.c - CDAC PLIC variant (register layout
differs from the generic riscv,plic0; see patch N/N for details)
- hw/intc/vega_aclint.c - ACLINT MSWI/SSWI/MTIMER, with the
STIMECMP handling VEGA's boot ROM / BBL relies on
- target/riscv/cpu.c - adds TYPE_RISCV_CPU_VEGA32 and
TYPE_RISCV_CPU_VEGA64, CPU subtypes baking in VEGA's fixed baseline (IMA + S/U + Zicsr/Zifencei + SV32/SV39), so -M vega boots on either architecture without a manual -cpu string; see note below on why both are parented on sifive-u rather than the generic base CPU type
- docs/system/riscv/vega.rst - user-facing documentation
- tests/functional/riscv32/test_vega.py, tests/functional/riscv64/test_vega.py
- functional tests booting -M vega on both architectures (bare-metal on both; bare-metal + Linux/BBL on riscv64), fetching small test binaries from a stable, checksummed external asset repository
- MAINTAINERS entry
Notable hardware characteristics reviewers should know up front
-----------------------------------------------------------------
- The PLIC and CLINT/ACLINT are co-located at the same base address on real VEGA silicon (0x20010000). This is not a QEMU modelling error; it reflects the actual SoC memory map.
- The PLIC aperture is 0x400 bytes, sized for the current maximum hart count on this SoC family; it is not the generic upstream PLIC aperture size.
- UART register framing differs between boot modes: bare-metal always uses shift=2/io-width=4 (fixed 32-bit stride), while Linux boot reads reg-shift from the DTB serial node, since the two boot paths exercise the hardware through different firmware layers.
- TYPE_RISCV_CPU_VEGA32/VEGA64 are parented on TYPE_RISCV_CPU_SIFIVE_U rather than TYPE_RISCV_CPU_BASE or TYPE_RISCV_BARE_CPU. TYPE_RISCV_CPU_BASE's default misa_ext includes RVH, and the class-level misa_ext merge is OR-only (a subtype cannot clear a bit its parent already set), so RVH could not be disabled from a TYPE_RISCV_CPU_BASE-derived subtype. TYPE_RISCV_BARE_CPU avoids that, but unconditionally forces max_satp_mode to 'bare' for any CPU in its lineage regardless of what the subtype configures, which breaks paging. TYPE_RISCV_CPU_SIFIVE_U has neither issue, but silently sets priv_spec to PRIV_VERSION_1_10_0 (an older RISC-V privileged spec version) rather than the current one. This surfaced as a real boot hang against production BBL/DTB pairs (BBL's delegate_traps() mideleg assertion failed) that was not visible in simpler test boots, since the hang depends on firmware built against a newer priv spec than 1.10.0. Both VEGA CPU subtypes explicitly override priv_spec back to PRIV_VERSION_LATEST to fix this; anyone deriving a new CPU subtype from a SiFive-family parent should be aware this default does not propagate the way ISA extension bits might be assumed to.
- VEGA does not generate a device tree internally. -dtb is required for any -kernel (Linux/BBL) boot; the machine errors out clearly if a kernel is given without -dtb and without -bios firmware. A bare "-M vega" with no boot arguments at all (e.g. qtest's generic smoke tests) is a valid, inert state and does not error. This keeps the initial series scoped to what has been directly tested; internal FDT generation may follow as a later series.
- PLIC and CLINT compatible strings are "cdac,plic-1.0.0" and "riscv,clint0" respectively. CDAC's own Buildroot-based BBL/Linux builds use a CDAC-specific PLIC driver matched against the former, and use the generic CLINT compatible string directly (no CDAC-specific CLINT driver exists in any current VEGA firmware variant). A DTB intended to boot stock, unmodified riscv-pk/BBL (which only recognises "riscv,plic0" verbatim) will need to additionally advertise that generic string for the PLIC node.
What is NOT included / deliberately left out
---------------------------------------------
- No AIA/APLIC/IMSIC support: current VEGA silicon does not implement AIA, so that code path (present in earlier internal revisions) has been removed rather than left as dead code.
- No internal device-tree generation: see note above; -dtb is required for -kernel boots in this series.
- No SDHCI, SPI, I2C functional models yet: exposed as unimplemented-device stubs matching the real address ranges, so guest software can probe them safely; functional models may follow in later series.
- No RV32 Linux boot test yet: the functional test suite covers bare-metal on both architectures and a full Linux/BBL boot on riscv64 only, since an RV32 (Thejas32) Linux/BBL boot has not yet been verified; this may follow in a later series once available.
Testing
-------
- riscv32-softmmu and riscv64-softmmu builds, make check clean on both
- checkpatch.pl clean across the series
- Functional tests added under tests/functional/riscv32/test_vega.py and tests/functional/riscv64/test_vega.py, passing via both direct invocation and meson test on both architectures:
- bare-metal "hello world" boot (RV32 and RV64)
- full Linux boot via BBL to a login prompt (RV64)
- Manual testing additionally covered: virtio-net networking, and an extended stress-ng run (CPU, matrix, VM, filesystem, device-access stressors) under Linux on -M vega
We previously posted an early version of VEGA machine support (Message-ID: <[email protected]>) without a proper cover letter, MAINTAINERS entry, documentation, or tests, and sent via a webmail client rather than git send-email, which likely affected formatting. This series is a corrected resubmission addressing all of that: it is sent via git send-email, and adds the documentation, MAINTAINERS entry, and functional tests that were missing before. We've since read and followed docs/devel/submitting-a-patch.rst in full. Feedback on process as well as code is very welcome.
Karthika B (7):
hw/intc: Add CDAC VEGA PLIC device model hw/intc: Add CDAC VEGA ACLINT device model target/riscv: Add VEGA32 and VEGA64 CPU types hw/riscv: Add CDAC VEGA machine model docs/system/riscv: Add VEGA machine documentation tests/functional: Add VEGA machine functional tests
MAINTAINERS: Add entry for VEGA machine
MAINTAINERS | 14 + configs/devices/riscv64-softmmu/default.mak | 1 + docs/system/riscv/vega.rst | 219 +++++++ docs/system/target-riscv.rst | 1 + hw/intc/Kconfig | 7 + hw/intc/meson.build | 2 + hw/intc/vega_aclint.c | 668 ++++++++++++++++++++ hw/intc/vega_plic.c | 517 +++++++++++++++ hw/riscv/Kconfig | 11 + hw/riscv/meson.build | 1 + hw/riscv/vega.c | 502 +++++++++++++++ include/hw/intc/vega_aclint.h | 84 +++ include/hw/intc/vega_plic.h | 87 +++ include/hw/riscv/vega.h | 136 ++++ target/riscv/cpu-qom.h | 2 + target/riscv/cpu.c | 25 + tests/functional/riscv32/meson.build | 1 + tests/functional/riscv32/test_vega.py | 32 + tests/functional/riscv64/meson.build | 1 + tests/functional/riscv64/test_vega.py | 63 ++ 20 files changed, 2374 insertions(+) create mode 100644 docs/system/riscv/vega.rst create mode 100644 hw/intc/vega_aclint.c create mode 100644 hw/intc/vega_plic.c create mode 100644 hw/riscv/vega.c create mode 100644 include/hw/intc/vega_aclint.h create mode 100644 include/hw/intc/vega_plic.h create mode 100644 include/hw/riscv/vega.h create mode 100644 tests/functional/riscv32/test_vega.py create mode 100644 tests/functional/riscv64/test_vega.py
Signature · 13 lines
2.43.0 ------------------------------------------------------------------------------------------------------------ [ C-DAC is on Social-Media too. Kindly follow us at: Facebook: https://www.facebook.com/CDACINDIA & Twitter: @cdacindia ] This e-mail is for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies and the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email is strictly prohibited and appropriate legal action will be taken. ------------------------------------------------------------------------------------------------------------
PATCH 1/7 hw/intc: Add CDAC VEGA PLIC device model
--- hw/intc/Kconfig | 7 + hw/intc/meson.build | 2 + hw/intc/vega_plic.c | 517 ++++++++++++++++++++++++++++++++++++ include/hw/intc/vega_plic.h | 87 ++++++ 4 files changed, 613 insertions(+) create mode 100644 hw/intc/vega_plic.c create mode 100644 include/hw/intc/vega_plic.h
hw/intc/Kconfig +7 -0
@@ -117,3 +117,10 @@ config LOONGARCH_EXTIOI config LOONGARCH_DINTC bool + +config VEGA_ACLINT + bool + +config VEGA_PLIC + bool + select MSI_NONBROKEN
hw/intc/meson.build +2 -0
@@ -68,6 +68,8 @@ specific_ss.add(when: 'CONFIG_RISCV_APLIC', if_true: files('riscv_aplic.c')) specific_ss.add(when: 'CONFIG_RISCV_IMSIC', if_true: files('riscv_imsic.c')) specific_ss.add(when: 'CONFIG_SIFIVE_PLIC', if_true: files('sifive_plic.c')) specific_ss.add(when: 'CONFIG_XICS', if_true: files('xics.c', 'xive2.c')) +specific_ss.add(when: 'CONFIG_VEGA_ACLINT', if_true: files('vega_aclint.c')) +specific_ss.add(when: 'CONFIG_VEGA_PLIC', if_true: files('vega_plic.c')) specific_ss.add(when: ['CONFIG_KVM', 'CONFIG_XICS'], if_true: files('xics_kvm.c')) specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('xics_spapr.c', 'spapr_xive.c'))
hw/intc/vega_plic.c new file +517 -0
517 lines not on this page · raw message
include/hw/intc/vega_plic.h new file +87 -0
87 lines not on this page · raw message
Signature · 14 lines
2.43.0 ------------------------------------------------------------------------------------------------------------ [ C-DAC is on Social-Media too. Kindly follow us at: Facebook: https://www.facebook.com/CDACINDIA & Twitter: @cdacindia ] This e-mail is for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies and the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email is strictly prohibited and appropriate legal action will be taken. ------------------------------------------------------------------------------------------------------------
PATCH 2/7 hw/intc: Add CDAC VEGA ACLINT device model
In reply to Karthika B--- hw/intc/vega_aclint.c | 668 ++++++++++++++++++++++++++++++++++ include/hw/intc/vega_aclint.h | 84 +++++ 2 files changed, 752 insertions(+) create mode 100644 hw/intc/vega_aclint.c create mode 100644 include/hw/intc/vega_aclint.h
hw/intc/vega_aclint.c new file +668 -0
@@ -0,0 +1,668 @@ +/* +* VEGA ACLINT (Advanced Core Local Interruptor) emulation +* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* Copyright (c) 2025 C-DAC (Centre for Development of Advanced Computing) +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2 or later, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "hw/core/sysbus.h" +#include "target/riscv/cpu.h" +#include "target/riscv/time_helper.h" +#include "hw/core/qdev-properties.h" +#include "hw/intc/vega_aclint.h" +#include "qemu/timer.h" +#include "hw/core/irq.h" +#include "migration/vmstate.h" + +typedef struct vega_aclint_mtimer_callback { +VEGAAclintMTimerState *s; +int num; +}vega_aclint_mtimer_callback ; + +static uint64_t cpu_vega_read_rtc_raw (uint32_t timebase_freq) +{ +return muldiv64 (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ), + timebase_freq,NANOSECONDS_PER_SECOND ); +} + +static uint64_t cpu_vega_read_rtc (void *opaque) +{ +VEGAAclintMTimerState *mtimer = opaque; +return cpu_vega_read_rtc_raw (mtimer->timebase_freq) + mtimer->time_delta; +} + +/* +* Called when timecmp is written to update the QEMU timer or immediately +* trigger timer interrupt if mtimecmp <= current timer value. +*/ +static void vega_aclint_mtimer_write_timecmp (VEGAAclintMTimerState *mtimer, +RISCVCPU *cpu, +int hartid, +uint64_t value) +{ +uint32_t timebase_freq = mtimer->timebase_freq; +uint64_t next; +uint64_t diff; + +uint64_t rtc =cpu_vega_read_rtc (mtimer); + +/* Compute the relative hartid w.r.t the socket */ + hartid = hartid - mtimer->hartid_base; + + mtimer->timecmp[hartid] = value; +if (mtimer->timecmp[hartid] <= rtc) { +/* +* If we're setting an MTIMECMP value in the "past", +* immediately raise the timer interrupt +*/ +qemu_irq_raise (mtimer->timer_irqs[hartid]); +return ; + } + +/* otherwise, set up the future timer interrupt */ +qemu_irq_lower (mtimer->timer_irqs[hartid]); + diff = mtimer->timecmp[hartid] - rtc; +/* back to ns (note args switched in muldiv64) */ +uint64_t ns_diff =muldiv64 (diff,NANOSECONDS_PER_SECOND , timebase_freq); + +/* +* check if ns_diff overflowed and check if the addition would potentially +* overflow +*/ +if ((NANOSECONDS_PER_SECOND > timebase_freq && ns_diff < diff) || + ns_diff >INT64_MAX ) { + next =INT64_MAX ; + }else { +/* +* as it is very unlikely qemu_clock_get_ns will return a value +* greater than INT64_MAX, no additional check is needed for an +* unsigned integer overflow. +*/ + next =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + ns_diff; +/* +* if ns_diff is INT64_MAX next may still be outside the range +* of a signed integer. +*/ + next =MIN (next,INT64_MAX ); + } + +timer_mod (mtimer->timers[hartid], next); +} + +/* +* Callback used when the timer set using timer_mod expires. +* Should raise the timer interrupt line +*/ +static void vega_aclint_mtimer_cb (void *opaque) +{ +vega_aclint_mtimer_callback *state = opaque; + +qemu_irq_raise (state->s->timer_irqs[state->num]); +} + +/* CPU read MTIMER register */ +static uint64_t vega_aclint_mtimer_read (void *opaque,hwaddr addr, +unsigned size) +{ +VEGAAclintMTimerState *mtimer = opaque; + +/* STIMECMP[h] = timecmp_base + 0x10 + h*0x20 — stored in upper timecmp[] */ +if (addr >= (mtimer->timecmp_base +0x10 ) && + addr < (mtimer->timecmp_base +0x10 + (mtimer->num_harts <<5 )) && + ((addr - (mtimer->timecmp_base +0x10 )) %0x20 ) <8 ) { +size_t hartid = mtimer->hartid_base + + ((addr - (mtimer->timecmp_base +0x10 )) >>5 ); +if (hartid < mtimer->hartid_base + mtimer->num_harts) { +uint64_t stimecmp = mtimer->timecmp[hartid + mtimer->num_harts]; +return (size ==4 ) ? (stimecmp &0xFFFFFFFF ) : stimecmp; + } +return 0 ; + } +if (addr >= mtimer->timecmp_base && + addr < (mtimer->timecmp_base + (mtimer->num_harts <<5 )) && + ((addr - mtimer->timecmp_base) %0x20 ) <8 ) { +size_t hartid = mtimer->hartid_base + + ((addr - mtimer->timecmp_base) >>5 ); +CPUState *cpu =cpu_by_arch_id (hartid); +CPURISCVState *env = cpu ?cpu_env (cpu) :NULL ; +if (!env) { +qemu_log_mask (LOG_GUEST_ERROR , +"aclint-mtimer: invalid hartid: %zu" , hartid); + }else if ((addr &0x7 ) ==0 ) { +/* timecmp_lo for RV32/RV64 or timecmp for RV64 */ +uint64_t timecmp = mtimer->timecmp[hartid]; +return (size ==4 ) ? (timecmp &0xFFFFFFFF ) : timecmp; + }else if ((addr &0x7 ) ==4 ) { +/* timecmp_hi */ +uint64_t timecmp = mtimer->timecmp[hartid]; +return (timecmp >>32 ) &0xFFFFFFFF ; + }else { +qemu_log_mask (LOG_UNIMP , +"aclint-mtimer: invalid read: %08x" , (uint32_t )addr); +return 0 ; + } + }else if (addr == mtimer->time_base) { +/* time_lo for RV32/RV64 or timecmp for RV64 */ +uint64_t rtc =cpu_vega_read_rtc (mtimer); +return (size ==4 ) ? (rtc &0xFFFFFFFF ) : rtc; + }else if (addr == mtimer->time_base +4 ) { +/* time_hi */ +return (cpu_vega_read_rtc (mtimer) >>32 ) &0xFFFFFFFF ; + } + +qemu_log_mask (LOG_UNIMP , +"aclint-mtimer: invalid read: %08x" , (uint32_t )addr); +return 0 ; +} + +/* CPU write MTIMER register */ +static void vega_aclint_mtimer_write (void *opaque,hwaddr addr, +uint64_t value,unsigned size) +{ +VEGAAclintMTimerState *mtimer = opaque; +int i; + +/* +* STIMECMP[h] = timecmp_base + 0x10 + h*0x20. +* BBL's fdt.c VEGA_CLINT uses hls->timecmp = STIMECMP for sbi_set_timer. +* Writing STIMECMP must schedule a timer so MTIME>=STIMECMP fires MIP.STIP. +*/ +if (addr >= (mtimer->timecmp_base +0x10 ) && + addr < (mtimer->timecmp_base +0x10 + (mtimer->num_harts <<5 )) && + ((addr - (mtimer->timecmp_base +0x10 )) %0x20 ) <8 ) { +size_t hartid = mtimer->hartid_base + + ((addr - (mtimer->timecmp_base +0x10 )) >>5 ); +if (hartid < mtimer->hartid_base + mtimer->num_harts) { +uint64_t stimecmp = value; +uint32_t hart_idx = (uint32_t )(hartid - mtimer->hartid_base); + mtimer->timecmp[hartid + mtimer->num_harts] = stimecmp; +/* Schedule (or cancel) the STIP timer exactly like MTIMECMP */ +RISCVCPU *cpu =RISCV_CPU (cpu_by_arch_id (hartid)); +uint64_t rtc =cpu_vega_read_rtc (mtimer); +if (stimecmp <= rtc) { +riscv_cpu_update_mip (&cpu->env,MIP_STIP ,BOOL_TO_MASK (1 )); + }else { +riscv_cpu_update_mip (&cpu->env,MIP_STIP ,BOOL_TO_MASK (0 )); +uint64_t diff = stimecmp - rtc; +uint64_t ns_diff =muldiv64 (diff,NANOSECONDS_PER_SECOND , + mtimer->timebase_freq); +uint64_t next; +if ((NANOSECONDS_PER_SECOND > mtimer->timebase_freq && + ns_diff < diff) || ns_diff >INT64_MAX ) { + next =INT64_MAX ; + }else { + next =MIN (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + ns_diff, + (uint64_t )INT64_MAX ); + } +timer_mod (mtimer->stimecmp_timers[hart_idx], next); + } + } +return ; + } +if (addr >= mtimer->timecmp_base && + addr < (mtimer->timecmp_base + (mtimer->num_harts <<5 )) && + ((addr - mtimer->timecmp_base) %0x20 ) <8 ) { +size_t hartid = mtimer->hartid_base + + ((addr - mtimer->timecmp_base) >>5 ); + +CPUState *cpu =cpu_by_arch_id (hartid); +CPURISCVState *env = cpu ?cpu_env (cpu) :NULL ; +if (!env) { +qemu_log_mask (LOG_GUEST_ERROR , +"aclint-mtimer: invalid hartid: %zu" , hartid); + }else if ((addr &0x7 ) ==0 ) { +if (size ==4 ) { +/* timecmp_lo for RV32/RV64 */ +uint64_t timecmp_hi = mtimer->timecmp[hartid] >>32 ; +vega_aclint_mtimer_write_timecmp (mtimer,RISCV_CPU (cpu), hartid, + timecmp_hi <<32 | (value &0xFFFFFFFF )); + }else { +/* timecmp for RV64 */ +vega_aclint_mtimer_write_timecmp (mtimer,RISCV_CPU (cpu), hartid, + value); + } + }else if ((addr &0x7 ) ==4 ) { +if (size ==4 ) { +/* timecmp_hi for RV32/RV64 */ +uint64_t timecmp_lo = mtimer->timecmp[hartid]; +vega_aclint_mtimer_write_timecmp (mtimer,RISCV_CPU (cpu), hartid, + value <<32 | (timecmp_lo &0xFFFFFFFF )); + }else { +qemu_log_mask (LOG_GUEST_ERROR , +"aclint-mtimer: invalid timecmp_hi write: %08x" , + (uint32_t )addr); + } + }else { +qemu_log_mask (LOG_UNIMP , +"aclint-mtimer: invalid timecmp write: %08x" , + (uint32_t )addr); + } +return ; + }else if (addr == mtimer->time_base || addr == mtimer->time_base +4 ) { +uint64_t rtc_r =cpu_vega_read_rtc_raw (mtimer->timebase_freq); +uint64_t rtc =cpu_vega_read_rtc (mtimer); + +if (addr == mtimer->time_base) { +if (size ==4 ) { +/* time_lo for RV32/RV64 */ + mtimer->time_delta = ((rtc & ~0xFFFFFFFFULL ) | value) - rtc_r; + }else { +/* time for RV64 */ + mtimer->time_delta = value - rtc_r; + } + }else { +if (size ==4 ) { +/* time_hi for RV32/RV64 */ + mtimer->time_delta = (value <<32 | (rtc &0xFFFFFFFF )) - rtc_r; + }else { +qemu_log_mask (LOG_GUEST_ERROR , +"aclint-mtimer: invalid time_hi write: %08x" , + (uint32_t )addr); +return ; + } + } + +/* Check if timer interrupt is triggered for each hart. */ +for (i =0 ; i < mtimer->num_harts; i++) { +CPUState *cpu =cpu_by_arch_id (mtimer->hartid_base + i); +CPURISCVState *env = cpu ?cpu_env (cpu) :NULL ; +if (!env) { +continue ; + } +vega_aclint_mtimer_write_timecmp (mtimer,RISCV_CPU (cpu), + mtimer->hartid_base + i, + mtimer->timecmp[i]); +riscv_timer_write_timecmp (env, env->stimer, env->stimecmp,0 ,MIP_STIP ); +riscv_timer_write_timecmp (env, env->vstimer, env->vstimecmp, + env->htimedelta,MIP_VSTIP ); + + } +return ; + } + +qemu_log_mask (LOG_UNIMP , +"aclint-mtimer: invalid write: %08x" , (uint32_t )addr); +} + +static const MemoryRegionOps vega_aclint_mtimer_ops = { + .read = vega_aclint_mtimer_read, + .write = vega_aclint_mtimer_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =8 + }, + .impl = { + .min_access_size =4 , + .max_access_size =8 , + } +}; + +static const Property vega_aclint_mtimer_properties[] = { +DEFINE_PROP_UINT32 ("hartid-base" , VEGAAclintMTimerState, + hartid_base,0 ), +DEFINE_PROP_UINT32 ("num-harts" , VEGAAclintMTimerState, num_harts,1 ), +DEFINE_PROP_UINT32 ("timecmp-base" , VEGAAclintMTimerState, + timecmp_base,VEGA_ACLINT_DEFAULT_MTIMECMP ), +DEFINE_PROP_UINT32 ("time-base" , VEGAAclintMTimerState, + time_base,VEGA_ACLINT_DEFAULT_MTIME ), +DEFINE_PROP_UINT32 ("aperture-size" , VEGAAclintMTimerState, + aperture_size,VEGA_ACLINT_DEFAULT_MTIMER_SIZE ), +DEFINE_PROP_UINT32 ("timebase-freq" , VEGAAclintMTimerState, + timebase_freq,0 ), +}; + +/* +* Callback when STIMECMP timer fires: set MIP.STIP. +* Reuses the existing vega_aclint_mtimer_callback struct: +* .s = pointer to VEGAAclintMTimerState +* .num = hart index (relative to hartid_base) +*/ +static void vega_aclint_stimecmp_cb (void *opaque) +{ +vega_aclint_mtimer_callback *cb = opaque; +VEGAAclintMTimerState *mtimer = cb->s; +int hart_idx = cb->num; +size_t hartid = mtimer->hartid_base + hart_idx; + +RISCVCPU *cpu =RISCV_CPU (cpu_by_arch_id (hartid)); +uint64_t rtc =cpu_vega_read_rtc (mtimer); +uint64_t stimecmp = mtimer->timecmp[hartid + mtimer->num_harts]; + +if (rtc >= stimecmp) { +riscv_cpu_update_mip (&cpu->env,MIP_STIP ,BOOL_TO_MASK (1 )); + } +/* else: spurious wakeup, leave STIP cleared */ +} + +static void vega_aclint_mtimer_realize (DeviceState *dev,Error **errp) +{ +VEGAAclintMTimerState *s =VEGA_ACLINT_MTIMER (dev); +int i; + +memory_region_init_io (&s->mmio,OBJECT (dev), &vega_aclint_mtimer_ops, + s,TYPE_VEGA_ACLINT_MTIMER , s->aperture_size); +sysbus_init_mmio (SYS_BUS_DEVICE (dev), &s->mmio); + + s->timer_irqs =g_new (qemu_irq, s->num_harts); +qdev_init_gpio_out (dev, s->timer_irqs, s->num_harts); + + s->timers = g_new0(QEMUTimer *, s->num_harts); +/* Allocate 2×num_harts: lower half = MTIMECMP, upper half = STIMECMP */ +/* +* Initialise all MTIMECMP and STIMECMP slots to UINT64_MAX so the +* timer interrupt does not fire before software explicitly arms it. +* With the default g_new0 (value 0), MTIME >= MTIMECMP is true the +* instant the clock starts, causing a continuous timer interrupt storm +* that prevents Linux from completing early initialisation. +*/ + s->timecmp =g_new (uint64_t, s->num_harts *2 ); +for (int _i =0 ; _i < s->num_harts *2 ; _i++) { + s->timecmp[_i] =UINT64_MAX ; + } +/* Claim MTIP and STIP on each hart, create STIMECMP timers */ + s->stimecmp_timers = g_new(QEMUTimer *, s->num_harts); +for (i =0 ; i < s->num_harts; i++) { +RISCVCPU *cpu =RISCV_CPU (cpu_by_arch_id (s->hartid_base + i)); +if (riscv_cpu_claim_interrupts (cpu,MIP_MTIP ) <0 ) { +error_report ("MTIP already claimed" ); +exit (1 ); + } +if (riscv_cpu_claim_interrupts (cpu,MIP_STIP ) <0 ) { +error_report ("STIP already claimed" ); +exit (1 ); + } +vega_aclint_mtimer_callback *scb =g_new (vega_aclint_mtimer_callback,1 ); + scb->s = s; + scb->num = i; + s->stimecmp_timers[i] =timer_new_ns (QEMU_CLOCK_VIRTUAL , + vega_aclint_stimecmp_cb, scb); +timer_mod (s->stimecmp_timers[i],INT64_MAX ); + } +} + +static void vega_aclint_mtimer_reset_enter (Object *obj,ResetType type) +{ +/* +* According to RISC-V ACLINT spec: +* - On MTIMER device reset, the MTIME register is cleared to zero. +* - On MTIMER device reset, the MTIMECMP registers are in unknown state. +*/ +VEGAAclintMTimerState *mtimer =VEGA_ACLINT_MTIMER (obj); + +/* +* Clear mtime register by writing to 0 it. +* Pending mtime interrupts will also be cleared at the same time. +*/ +vega_aclint_mtimer_write (mtimer, mtimer->time_base,0 ,8 ); +} + +static const VMStateDescription vmstate_vega_mtimer = { + .name ="vega_mtimer" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (const VMStateField []) { +VMSTATE_VARRAY_UINT32 (timecmp, VEGAAclintMTimerState, + num_harts,0 , + vmstate_info_uint64, uint64_t), +VMSTATE_END_OF_LIST () + } +}; + +static void vega_aclint_mtimer_class_init (ObjectClass *klass,const void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + dc->realize = vega_aclint_mtimer_realize; +device_class_set_props (dc, vega_aclint_mtimer_properties); +ResettableClass *rc =RESETTABLE_CLASS (klass); + rc->phases.enter = vega_aclint_mtimer_reset_enter; + dc->vmsd = &vmstate_vega_mtimer; +} + +static const TypeInfo vega_aclint_mtimer_info = { + .name =TYPE_VEGA_ACLINT_MTIMER , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (VEGAAclintMTimerState), + .class_init = vega_aclint_mtimer_class_init, +}; + +/* +* Create ACLINT MTIMER device. +*/ +DeviceState *vega_aclint_mtimer_create (hwaddr addr,hwaddr size, +uint32_t hartid_base,uint32_t num_harts, +uint32_t timecmp_base,uint32_t time_base,uint32_t timebase_freq, +bool provide_rdtime) +{ +int i; +DeviceState *dev =qdev_new (TYPE_VEGA_ACLINT_MTIMER ); +VEGAAclintMTimerState *s =VEGA_ACLINT_MTIMER (dev); + +assert (num_harts <=VEGA_ACLINT_MAX_HARTS ); +assert (!(addr &0x7 )); +assert (!(timecmp_base &0x7 )); +assert (!(time_base &0x7 )); + +qdev_prop_set_uint32 (dev,"hartid-base" , hartid_base); +qdev_prop_set_uint32 (dev,"num-harts" , num_harts); +qdev_prop_set_uint32 (dev,"timecmp-base" , timecmp_base); +qdev_prop_set_uint32 (dev,"time-base" , time_base); +qdev_prop_set_uint32 (dev,"aperture-size" , size); +qdev_prop_set_uint32 (dev,"timebase-freq" , timebase_freq); +sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 , addr); + +for (i =0 ; i < num_harts; i++) { +CPUState *cpu =cpu_by_arch_id (hartid_base + i); +RISCVCPU *rvcpu =RISCV_CPU (cpu); +CPURISCVState *env = cpu ?cpu_env (cpu) :NULL ; +vega_aclint_mtimer_callback *cb = +g_new0 (vega_aclint_mtimer_callback,1 ); + +if (!env) { +g_free (cb); +continue ; + } +if (provide_rdtime) { +riscv_cpu_set_rdtime_fn (env, cpu_vega_read_rtc, dev); + } + + cb->s = s; + cb->num = i; + s->timers[i] =timer_new_ns (QEMU_CLOCK_VIRTUAL , + &vega_aclint_mtimer_cb, cb); +/* +* MTIMECMP initialized to UINT64_MAX in realize(); do NOT reset to 0 +* here — doing so causes M-mode timer to fire immediately once BBL +* enables MTIE after the first sbi_set_timer call. +*/ + +qdev_connect_gpio_out (dev, i, +qdev_get_gpio_in (DEVICE (rvcpu),IRQ_M_TIMER )); + } + +return dev; +} + +/* CPU read [M|S]SWI register */ +static uint64_t vega_aclint_swi_read (void *opaque,hwaddr addr, +unsigned size) +{ +VEGAAclintSwiState *swi = opaque; + +if (addr < (swi->num_harts <<4 )) { +size_t hartid = swi->hartid_base + (addr >>4 ); +CPUState *cpu =cpu_by_arch_id (hartid); +CPURISCVState *env = cpu ?cpu_env (cpu) :NULL ; +if (!env) { +qemu_log_mask (LOG_GUEST_ERROR , +"aclint-swi: invalid hartid: %zu" , hartid); + }else if ((addr &0x3 ) ==0 ) { +return (swi->sswi) ?0 : ((env->mip &MIP_MSIP ) >0 ); + } + } + +qemu_log_mask (LOG_UNIMP , +"aclint-swi: invalid read: %08x" , (uint32_t )addr); +return 0 ; +} + +/* CPU write [M|S]SWI register */ +static void vega_aclint_swi_write (void *opaque,hwaddr addr,uint64_t value, +unsigned size) +{ +VEGAAclintSwiState *swi = opaque; + +if (addr < (swi->num_harts <<4 )) { +size_t hartid = swi->hartid_base + (addr >>4 ); + +CPUState *cpu =cpu_by_arch_id (hartid); +CPURISCVState *env = cpu ?cpu_env (cpu) :NULL ; +if (!env) { +qemu_log_mask (LOG_GUEST_ERROR , +"aclint-swi: invalid hartid: %zu" , hartid); + }else if ((addr &0x3 ) ==0 ) { +if (value &0x1 ) { +qemu_irq_raise (swi->soft_irqs[hartid - swi->hartid_base]); + }else { +if (!swi->sswi) { +qemu_irq_lower (swi->soft_irqs[hartid - swi->hartid_base]); + } + } +return ; + } + } + +qemu_log_mask (LOG_UNIMP , +"aclint-swi: invalid write: %08x" , (uint32_t )addr); +} + +static const MemoryRegionOps vega_aclint_swi_ops = { + .read = vega_aclint_swi_read, + .write = vega_aclint_swi_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 + } +}; + +static const Property vega_aclint_swi_properties[] = { +DEFINE_PROP_UINT32 ("hartid-base" , VEGAAclintSwiState, hartid_base,0 ), +DEFINE_PROP_UINT32 ("num-harts" , VEGAAclintSwiState, num_harts,1 ), +DEFINE_PROP_UINT32 ("sswi" , VEGAAclintSwiState, sswi, false), +}; + +static void vega_aclint_swi_realize (DeviceState *dev,Error **errp) +{ +VEGAAclintSwiState *swi =VEGA_ACLINT_SWI (dev); +int i; + +memory_region_init_io (&swi->mmio,OBJECT (dev), &vega_aclint_swi_ops, swi, +TYPE_VEGA_ACLINT_SWI ,VEGA_ACLINT_SWI_SIZE ); +sysbus_init_mmio (SYS_BUS_DEVICE (dev), &swi->mmio); + + swi->soft_irqs =g_new (qemu_irq, swi->num_harts); +qdev_init_gpio_out (dev, swi->soft_irqs, swi->num_harts); + +/* Claim software interrupt bits */ +for (i =0 ; i < swi->num_harts; i++) { +RISCVCPU *cpu =RISCV_CPU (qemu_get_cpu (swi->hartid_base + i)); +/* We don't claim mip.SSIP because it is writable by software */ +if (riscv_cpu_claim_interrupts (cpu, swi->sswi ?0 :MIP_MSIP ) <0 ) { +error_report ("MSIP already claimed" ); +exit (1 ); + } + } +} + +static void vega_aclint_swi_reset_enter (Object *obj,ResetType type) +{ +/* +* According to RISC-V ACLINT spec: +* - On MSWI device reset, each MSIP register is cleared to zero. +* +* p.s. SSWI device reset does nothing since SETSIP register always reads 0. +*/ +VEGAAclintSwiState *swi =VEGA_ACLINT_SWI (obj); +int i; + +if (!swi->sswi) { +for (i =0 ; i < swi->num_harts; i++) { +/* Clear MSIP registers by lowering software interrupts. */ +qemu_irq_lower (swi->soft_irqs[i]); + } + } +} + +static void vega_aclint_swi_class_init (ObjectClass *klass,const void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + dc->realize = vega_aclint_swi_realize; +device_class_set_props (dc, vega_aclint_swi_properties); +ResettableClass *rc =RESETTABLE_CLASS (klass); + rc->phases.enter = vega_aclint_swi_reset_enter; +} + +static const TypeInfo vega_aclint_swi_info = { + .name =TYPE_VEGA_ACLINT_SWI , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (VEGAAclintSwiState), + .class_init = vega_aclint_swi_class_init, +}; + +/* +* Create ACLINT [M|S]SWI device. +*/ +DeviceState *vega_aclint_swi_create (hwaddr addr,uint32_t hartid_base, +uint32_t num_harts,bool sswi) +{ +int i; +DeviceState *dev =qdev_new (TYPE_VEGA_ACLINT_SWI ); + +assert (num_harts <=VEGA_ACLINT_MAX_HARTS ); +assert (!(addr &0x3 )); + +qdev_prop_set_uint32 (dev,"hartid-base" , hartid_base); +qdev_prop_set_uint32 (dev,"num-harts" , num_harts); +qdev_prop_set_uint32 (dev,"sswi" , sswi ? true : false); +sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 , addr); + +for (i =0 ; i < num_harts; i++) { +CPUState *cpu =cpu_by_arch_id (hartid_base + i); +RISCVCPU *rvcpu =RISCV_CPU (cpu); + +qdev_connect_gpio_out (dev, i, +qdev_get_gpio_in (DEVICE (rvcpu), + (sswi) ?IRQ_S_SOFT :IRQ_M_SOFT )); + } + +return dev; +} + +static void vega_aclint_register_types (void ) +{ +type_register_static (&vega_aclint_mtimer_info); +type_register_static (&vega_aclint_swi_info); +} + +type_init (vega_aclint_register_types)
include/hw/intc/vega_aclint.h new file +84 -0
84 lines not on this page · raw message
Signature · 14 lines
2.43.0 ------------------------------------------------------------------------------------------------------------ [ C-DAC is on Social-Media too. Kindly follow us at: Facebook: https://www.facebook.com/CDACINDIA & Twitter: @cdacindia ] This e-mail is for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies and the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email is strictly prohibited and appropriate legal action will be taken. ------------------------------------------------------------------------------------------------------------
PATCH 3/7 target/riscv: Add VEGA32 and VEGA64 CPU types
In reply to Karthika B--- target/riscv/cpu-qom.h | 2 ++ target/riscv/cpu.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+)
target/riscv/cpu-qom.h +2 -0
@@ -58,6 +58,8 @@#define TYPE_RISCV_CPU_XIANGSHAN_KMH RISCV_CPU_TYPE_NAME("xiangshan-kunminghu")#define TYPE_RISCV_CPU_MIPS_P8700 RISCV_CPU_TYPE_NAME("mips-p8700")#define TYPE_RISCV_CPU_HOST RISCV_CPU_TYPE_NAME("host") +#define TYPE_RISCV_CPU_VEGA32 RISCV_CPU_TYPE_NAME("vega32") +#define TYPE_RISCV_CPU_VEGA64 RISCV_CPU_TYPE_NAME("vega64")OBJECT_DECLARE_CPU_TYPE (RISCVCPU , RISCVCPUClass,RISCV_CPU )
target/riscv/cpu.c +25 -0
@@ -2987,6 +2987,20 @@ static const TypeInfo riscv_cpu_type_infos[] = { ),#endif + +#if defined(TARGET_RISCV32 ) +DEFINE_RISCV_CPU (TYPE_RISCV_CPU_VEGA32 ,TYPE_RISCV_CPU_SIFIVE_U , + .misa_mxl_max = MXL_RV32, + .misa_ext = RVI | RVM | RVA | RVS | RVU, + .priv_spec = PRIV_VERSION_LATEST, + + .cfg.max_satp_mode = VM_1_10_SV32, + .cfg.ext_zicsr = true, + .cfg.ext_zifencei = true, + .cfg.pmp = false, + ), +#endif + #if (defined(TARGET_RISCV64) && !defined(CONFIG_USER_ONLY)) DEFINE_RISCV_CPU(TYPE_RISCV_CPU_MAX32, TYPE_RISCV_DYNAMIC_CPU, .cfg.max_satp_mode = VM_1_10_SV32,
@@ -3032,6 +3046,17 @@ static const TypeInfo riscv_cpu_type_infos[] = { .misa_mxl_max = MXL_RV64, ), +DEFINE_RISCV_CPU (TYPE_RISCV_CPU_VEGA64 ,TYPE_RISCV_CPU_SIFIVE_U , + .misa_mxl_max = MXL_RV64, + .misa_ext = RVI | RVM | RVA | RVS | RVU, + .priv_spec = PRIV_VERSION_LATEST, + + .cfg.max_satp_mode = VM_1_10_SV39, + .cfg.ext_zicsr = true, + .cfg.ext_zifencei = true, + .cfg.pmp = false, + ), + DEFINE_RISCV_CPU(TYPE_RISCV_CPU_THEAD_C906, TYPE_RISCV_VENDOR_CPU, .misa_mxl_max = MXL_RV64, .misa_ext = RVG | RVC | RVS | RVU,
Signature · 14 lines
2.43.0 ------------------------------------------------------------------------------------------------------------ [ C-DAC is on Social-Media too. Kindly follow us at: Facebook: https://www.facebook.com/CDACINDIA & Twitter: @cdacindia ] This e-mail is for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies and the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email is strictly prohibited and appropriate legal action will be taken. ------------------------------------------------------------------------------------------------------------
PATCH 4/7 hw/riscv: Add CDAC VEGA machine model
In reply to Karthika B--- configs/devices/riscv64-softmmu/default.mak | 1 + hw/riscv/Kconfig | 11 + hw/riscv/meson.build | 1 + hw/riscv/vega.c | 502 ++++++++++++++++++++ include/hw/riscv/vega.h | 136 ++++++ 5 files changed, 651 insertions(+) create mode 100644 hw/riscv/vega.c create mode 100644 include/hw/riscv/vega.h
configs/devices/riscv64-softmmu/default.mak +1 -0
@@ -11,5 +11,6 @@ # CONFIG_RISCV_VIRT=n # CONFIG_MICROCHIP_PFSOC=n # CONFIG_SHAKTI_C=n +# CONFIG_VEGA=n # CONFIG_XIANGSHAN_KUNMINGHU=n # CONFIG_MIPS_BOSTON_AIA=n
hw/riscv/Kconfig +11 -0
@@ -120,6 +120,17 @@ config SPIKE select RISCV_ACLINT select SIFIVE_PLIC +config VEGA + bool + default y + depends on RISCV32 || RISCV64 + select DEVICE_TREE + select RISCV_NUMA + select SERIAL_MM + select VEGA_ACLINT + select VEGA_PLIC + select VIRTIO_MMIO + config XIANGSHAN_KUNMINGHU bool default y
hw/riscv/meson.build +1 -0
@@ -13,6 +13,7 @@ riscv_ss.add(when: 'CONFIG_ACPI', if_true: files('virt-acpi-build.c')) riscv_ss.add(when: 'CONFIG_RISCV_IOMMU', if_true: files( 'riscv-iommu.c', 'riscv-iommu-pci.c', 'riscv-iommu-sys.c', 'riscv-iommu-hpm.c')) riscv_ss.add(when: 'CONFIG_MICROBLAZE_V', if_true: files('microblaze-v-generic.c')) +riscv_ss.add(when: 'CONFIG_VEGA', if_true: files('vega.c')) riscv_ss.add(when: 'CONFIG_XIANGSHAN_KUNMINGHU', if_true: files('xiangshan_kmh.c')) riscv_ss.add(when: 'CONFIG_RISCV_MIPS_CPS', if_true: files('cps.c'))
hw/riscv/vega.c new file +502 -0
502 lines not on this page · raw message
include/hw/riscv/vega.h new file +136 -0
136 lines not on this page · raw message
Signature · 14 lines
2.43.0 ------------------------------------------------------------------------------------------------------------ [ C-DAC is on Social-Media too. Kindly follow us at: Facebook: https://www.facebook.com/CDACINDIA & Twitter: @cdacindia ] This e-mail is for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies and the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email is strictly prohibited and appropriate legal action will be taken. ------------------------------------------------------------------------------------------------------------
PATCH 5/7 docs/system/riscv: Add VEGA machine documentation
In reply to Karthika B--- docs/system/riscv/vega.rst | 219 +++++++++++++++++++++++++++++++++++ docs/system/target-riscv.rst | 1 + 2 files changed, 220 insertions(+) create mode 100644 docs/system/riscv/vega.rst
docs/system/riscv/vega.rst new file +219 -0
@@ -0,0 +1,219 @@ +CDAC VEGA series RISC-V SoC (``vega``) +======================================= + +VEGA is a series of 32-bit and 64-bit processors based on the RISC-V ISA, developed by C-DAC (Centre for Development of Advanced Computing, India) under the DIR-V program. The vega QEMU machine model supports both the 32-bit and 64-bit VEGA variants. + +As with other QEMU RISC-V machine models, vega provides functional emulation of the VEGA SoC’s memory map, interrupt controllers, and peripherals. + +For more details on the VEGA processor series, please see: +https://vegaprocessors.in/ + +For VEGA documentation, please see: +https://cdac-vega.gitlab.io/ + +Supported devices +------------------ + +The ``vega`` machine supports the following devices: + + * Up to 4 RISC-V cores, RV32 or RV64 + * Platform-Level Interrupt Controller (PLIC) + * Core Level Interruptor (CLINT) + * 1 UART + * 4 virtio-mmio transports + +Boot options +------------ + +The ``vega`` machine supports two boot modes. + +Bare-metal +~~~~~~~~~~ + +Bare-metal payloads are loaded via ``-bios`` (not ``-kernel``). No +device tree is generated or loaded in this mode; the UART is always +accessed with a fixed 4-byte register stride (shift=2, io-width=4). + +.. code-block:: bash + + $ qemu-system-riscv64 -M vega,dram-base=0x80000000 \ + -smp 1 -m 2G \ + -display none -serial stdio \ + -bios path/to/baremetal.elf + +VEGA SDK +^^^^^^^^ + +VEGA SDK can be used to build baremetal example applications, such as +a "hello world" UART program, for both the Thejas32 (``vega32``, RV32) +and Thejas64 (``vega64``, RV64) SoCs. + +Install VEGA tools +'''''''''''''''''' + +For Thejas32 SoC (Aries boards): + +.. code-block:: bash + + $ git clone https://gitlab.com/cdac-vega/vega-tools-rv32.git + $ cd vega-tools-rv32 + $ ./setup-env.sh + $ cd .. + +For Thejas64 SoC: + +.. code-block:: bash + + $ git clone https://gitlab.com/cdac-vega/vega-tools-rv64.git + $ cd vega-tools-rv64 + $ ./setup-env.sh + $ cd .. + +Install VEGA SDK +'''''''''''''''' + +For Thejas32 SoC (Aries boards): + +.. code-block:: bash + + $ git clone https://gitlab.com/cdac-vega/vega-sdk.git + $ cd vega-sdk + $ git checkout aries + $ ./setup.sh + +For Thejas64 SoC: + +.. code-block:: bash + + $ git clone https://gitlab.com/cdac-vega/vega-sdk.git + $ cd vega-sdk + $ ./setup-thejas64.sh + +Build and run the hello world example +'''''''''''''''''''''''''''''''''''''' +.. code-block:: bash + + $ cd vega-sdk + $ cd examples/uart/hello_world + $ make + + +.. note:: + + The ``dram-base`` value must match the address the payload was + actually linked for; it is not a fixed VEGA default. The examples + below use ``dram-base=0x20000``, matching this SDK's hello-world + build for both Thejas32 and Thejas64 -- other payloads (e.g. a + Linux boot via BBL) are linked for a different address and need + their own matching ``dram-base`` value. + +.. code-block:: bash + + $ qemu-system-riscv32 -M vega,dram-base=0x20000 \ + -smp 1 -m 2G \ + -display none -serial stdio \ + -bios hello.elf + +.. code-block:: bash + + $ qemu-system-riscv64 -M vega,dram-base=0x20000 \ + -smp 1 -m 2G \ + -display none -serial stdio \ + -bios hello.elf + +Both should print:: + + Hello World + + +Linux / BBL +~~~~~~~~~~~ + +Linux boot requires a user-supplied device tree via ``-dtb``. The +``vega`` machine does not generate a device tree internally; passing +``-kernel`` without ``-dtb`` (and without ``-bios``) is a +configuration error and QEMU will refuse to start. + +.. code-block:: bash + + $ qemu-system-riscv64 -M vega,dram-base=0x400000000 \ + -smp 4 -m 2G \ + -display none -serial stdio -bios none \ + -kernel bbl -dtb vega.dtb -initrd rootfs.cpio + +Networking (virtio-net) can be attached the same way as on other +virtio-mmio boards: + +.. code-block:: bash + + $ qemu-system-riscv64 -M vega,dram-base=0x400000000 \ + -smp 4 -m 2G \ + -display none -serial stdio -bios none \ + -kernel bbl -dtb vega.dtb -initrd rootfs.cpio \ + -netdev tap,id=net0,ifname=tap0,script=no,downscript=no \ + -device virtio-net-device,netdev=net0 + +.. note:: + + VEGA's PLIC uses the ``cdac,plic-1.0.0`` compatible string, + recognized by CDAC's own PLIC driver bundled in CDAC's + Buildroot-based BBL/Linux builds. The CLINT is addressed as a + standard ``riscv,clint0``, which CDAC's firmware uses directly + without a vendor-specific driver; all CDAC-produced VEGA firmware + variants use this generic CLINT compatible string. + +CPU defaults +------------ + +The ``vega`` machine supports both RV32 and RV64 harts, matching the +VEGA processor series. The CPU type defaults automatically to the +correct width for the binary in use (``qemu-system-riscv32`` selects +``vega32``, ``qemu-system-riscv64`` selects ``vega64``) and bakes in +VEGA's fixed baseline: I, M, A, S and U, Zicsr, and Zifencei, with the +current RISC-V privileged architecture specification and SV32/SV39 +paging respectively. No ``-cpu`` argument is required to boot. +Additional extensions (e.g. F/D/C) can still be enabled explicitly if +needed: + +.. code-block:: bash + + $ qemu-system-riscv64 -M vega -cpu vega64,f=true,d=true,c=true ... + $ qemu-system-riscv32 -M vega -cpu vega32,f=true,d=true,c=true ... + +.. note:: + + ``TYPE_RISCV_CPU_VEGA32``/``TYPE_RISCV_CPU_VEGA64`` are parented on + ``TYPE_RISCV_CPU_SIFIVE_U`` rather than the generic base CPU type, + since the generic type's default ISA extensions cannot be fully + narrowed for VEGA's actual silicon (QEMU's CPU-class extension + merge is additive only). One consequence worth documenting: SiFive + U's default privileged specification version (1.10.0) is explicitly + overridden back to the current version in both VEGA CPU types, + since firmware built against the modern privileged spec can hang + early in boot (in CLINT/timer setup) against the older version. If + you build a custom CPU subtype from a similar parent, do not assume + privileged spec version propagates the way ISA extension bits + might. + +dram-base option +----------------- + +VEGA silicon can be configured with DRAM at different base addresses. +This is exposed as a machine property: + +.. code-block:: bash + + $ qemu-system-riscv64 -M vega,dram-base=0x400000000 ... + +If ``dram-base`` is not specified, QEMU falls back to a default +address and prints a warning. + +PLIC and CLINT address overlap +------------------------------- + +On real VEGA silicon, the PLIC and CLINT are mapped at the same base +address but are distinguished by non-overlapping register offset +ranges, decoded internally by the SoC's interconnect. This is a +genuine hardware characteristic, not a QEMU modelling error; compiling +a VEGA device tree will produce a ``dtc`` ``unique_unit_address`` +warning for this reason, which is expected and can be ignored.
docs/system/target-riscv.rst +1 -0
@@ -71,6 +71,7 @@ undocumented; you can get a complete list by running riscv/mips riscv/shakti-c riscv/sifive_u + riscv/vega riscv/virt riscv/xiangshan-kunminghu
Signature · 14 lines
2.43.0 ------------------------------------------------------------------------------------------------------------ [ C-DAC is on Social-Media too. Kindly follow us at: Facebook: https://www.facebook.com/CDACINDIA & Twitter: @cdacindia ] This e-mail is for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies and the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email is strictly prohibited and appropriate legal action will be taken. ------------------------------------------------------------------------------------------------------------
PATCH 6/7 tests/functional: Add VEGA machine functional tests
In reply to Karthika B--- tests/functional/riscv32/meson.build | 1 + tests/functional/riscv32/test_vega.py | 32 ++++++++++++++ tests/functional/riscv64/meson.build | 1 + tests/functional/riscv64/test_vega.py | 63 +++++++++++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 tests/functional/riscv32/test_vega.py create mode 100644 tests/functional/riscv64/test_vega.py
tests/functional/riscv32/meson.build +1 -0
@@ -7,4 +7,5 @@ tests_riscv32_system_quick = [ tests_riscv32_system_thorough = [ 'tuxrun', + 'vega', ]
tests/functional/riscv32/test_vega.py new file +32 -0
@@ -0,0 +1,32 @@ +#!/usr/bin/env python3 +# +# Functional test that boots a bare-metal hello-world program on the +# VEGA machine (RV32, Thejas32) and checks the console output. +# +# SPDX-License-Identifier: GPL-2.0-or-later + +from qemu_test import Asset, QemuSystemTest +from qemu_test.cmd import wait_for_console_pattern + + +class Vega(QemuSystemTest): + + ASSET_HELLO32 = Asset( + 'https://gitlab.com/riscv-vega/vega_qemu_test_images/-/raw/v1.0/baremetal/hello32.elf', + '77d3449a495b78ff4d7aa93024682d3e8efa10e64a82c6c0029144ddd3b4c638') + + def test_riscv32_vega_hello(self): + self.set_machine('vega') + hello_path = self.ASSET_HELLO32.fetch() + + self.vm.set_console() + self.vm.add_args('-bios', hello_path, + '-M', 'vega,dram-base=0x20000', + '-no-reboot') + + self.vm.launch() + wait_for_console_pattern(self, 'Hello World') + + +if __name__ == '__main__': + QemuSystemTest.main()
tests/functional/riscv64/meson.build +1 -0
@@ -14,4 +14,5 @@ tests_riscv64_system_thorough = [ 'boston', 'sifive_u', 'tuxrun', + 'vega', ]
tests/functional/riscv64/test_vega.py new file +63 -0
63 lines not on this page · raw message
Signature · 14 lines
2.43.0 ------------------------------------------------------------------------------------------------------------ [ C-DAC is on Social-Media too. Kindly follow us at: Facebook: https://www.facebook.com/CDACINDIA & Twitter: @cdacindia ] This e-mail is for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies and the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email is strictly prohibited and appropriate legal action will be taken. ------------------------------------------------------------------------------------------------------------
PATCH 7/7 MAINTAINERS: Add entry for VEGA machine
In reply to Karthika B--- MAINTAINERS | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
MAINTAINERS +14 -0
@@ -1786,6 +1786,20 @@ F: docs/system/riscv/xiangshan-kunminghu.rst F: hw/riscv/xiangshan_kmh.c F: include/hw/riscv/xiangshan_kmh.h +VEGA +M: Karthika B <[email protected]> +L: [email protected] +S: Odd Fixes +F: hw/riscv/vega.c +F: hw/intc/vega_plic.c +F: hw/intc/vega_aclint.c +F: include/hw/riscv/vega.h +F: include/hw/intc/vega_plic.h +F: include/hw/intc/vega_aclint.h +F: docs/system/riscv/vega.rst +F: tests/functional/riscv32/test_vega.py +F: tests/functional/riscv64/test_vega.py + RX Machines ----------- rx-gdbsim
Signature · 14 lines
2.43.0 ------------------------------------------------------------------------------------------------------------ [ C-DAC is on Social-Media too. Kindly follow us at: Facebook: https://www.facebook.com/CDACINDIA & Twitter: @cdacindia ] This e-mail is for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies and the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email is strictly prohibited and appropriate legal action will be taken. ------------------------------------------------------------------------------------------------------------
Re: [PATCH 0/7] RISC-V: Add CDAC VEGA machine support
In reply to Karthika BQuoted 12 lines · Karthika B
This series adds QEMU machine support for VEGA, a RISC-V SoC family developed by C-DAC (Centre for Development of Advanced Computing, India) as part of the DIR-V processor program.
VEGA series of microprocessors are developed as part of the Microprocessor Development Programme, initiated and funded by MeitY (Ministry of Electronics and Information Technology, Government of India), with the mission objective to design and develop indigenously a family of microprocessors, related IPs, and the complete ecosystem to enable fully indigenous product development catering to various requirements in the strategic, industrial, and commercial sectors. VEGA is developed at C-DAC, Thiruvananthapuram.
Quoted 9 lines
Background
----------
VEGA is a series of 32-bit and 64-bit single/multi-core RISC-V processors (Thejas32 and Thejas64) developed under the DIR-V program, integrated with multi-level caches, an MMU, and a coherent interconnect on real silicon. This series adds a QEMU 'vega' machine model supporting both the Thejas32 (RV32) and Thejas64 (RV64) variants, modelled on real silicon behaviour rather than a synthetic/virtual platform.
Thanks for the series. It's cool to see some more RISC-V designs.
Thank you for submitting the patches.
For some context, we already have support for a Shakti machine, and that is being deprecated and removed as it hasn't been maintained by the original submitter.
I also noticed that you listed yourself as "Odd Fixes" in the maintainers file, so this won't be accepted.
We don't have the resource to maintain your custom board and reviewers are stretched very thin to look at your patches. If you don't want to maintain it, we aren't going to be able to either.
Quoted 6 lines
More details on the VEGA processor series:
https://vegaprocessors.in/
VEGA documentation:
https://cdac-vega.gitlab.io/
Quoted 6 lines
The model has been validated against Aries boards (Thejas32) and Thejas64 SoCs, booting:
- bare-metal ELF payloads via -bios (no DTB, fixed UART framing), for both RV32 and RV64, using the VEGA SDK's example UART "hello world" application
- Linux via BBL with a user-supplied -dtb describing the SoC (RV64)
No BBL, please use OpenSBI or an equivalent
Quoted 13 lines
What's included
----------------
- hw/riscv/vega.c - machine model, device creation, boot flow.
Note: VEGA does not generate its device
tree internally; -dtb is required for any
-kernel boot (see note below)
- hw/intc/vega_plic.c - CDAC PLIC variant (register layout differs from the generic riscv,plic0;
Why?
Quoted 29 lines
see patch N/N for details)
- hw/intc/vega_aclint.c - ACLINT MSWI/SSWI/MTIMER, with the STIMECMP handling VEGA's boot ROM / BBL relies on
- target/riscv/cpu.c - addsTYPE_RISCV_CPU_VEGA32andTYPE_RISCV_CPU_VEGA64, CPU subtypes baking in VEGA's fixed baseline (IMA +
S/U + Zicsr/Zifencei + SV32/SV39), so
-M vega boots on either architecture without a manual -cpu string; see note
below on why both are parented on sifive-u rather than the generic base
CPU type
-docs/system/riscv/vega.rst- user-facing documentation
-tests/functional/riscv32/test_vega.py,tests/functional/riscv64/test_vega.py
- functional tests booting -M vega on both architectures (bare-metal on both; bare-metal + Linux/BBL on riscv64), fetching small test binaries
from a stable, checksummed external asset repository
-MAINTAINERSentry
Quoted 1 line
Notable hardware characteristics reviewers should know up front
Have you read QEMU's AI policy?
https://www.qemu.org/docs/master/devel/code-provenance.html#use-of-ai-generated-content
Quoted 4 lines
-----------------------------------------------------------------
- The PLIC and CLINT/ACLINT are co-located at the same base address on real VEGA silicon (0x20010000). This is not a QEMU modelling error; it reflects the actual SoC memory map.
What? Why?
Quoted 50 lines
- The PLIC aperture is
0x400bytes, sized for the current maximum hart count on this SoC family; it is not the generic upstream PLIC aperture size.
- UART register framing differs between boot modes: bare-metal always
uses shift=2/io-width=4 (fixed 32-bit stride), while Linux boot reads reg-shift from the DTB serial node, since the two boot paths exercise the hardware through different firmware layers.
- TYPE_RISCV_CPU_VEGA32/VEGA64 are parented onTYPE_RISCV_CPU_SIFIVE_U
rather thanTYPE_RISCV_CPU_BASEorTYPE_RISCV_BARE_CPU. TYPE_RISCV_CPU_BASE's defaultmisa_extincludes RVH, and the class-levelmisa_extmerge is OR-only (a subtype cannot clear a bit
its parent already set), so RVH could not be disabled from a TYPE_RISCV_CPU_BASE-derived subtype.TYPE_RISCV_BARE_CPUavoids that, but unconditionally forcesmax_satp_modeto 'bare' for any CPU in its lineage regardless of what the subtype configures, which
breaks paging.TYPE_RISCV_CPU_SIFIVE_Uhas neither issue, but silently setspriv_spectoPRIV_VERSION_1_10_0(an older RISC-V privileged spec version) rather than the current one. This surfaced
as a real boot hang against production BBL/DTB pairs (BBL'sdelegate_traps()mideleg assertion failed) that was not visible in simpler test boots, since the hang depends on firmware built against a newer priv spec than 1.10.0. Both VEGA CPU subtypes explicitly overridepriv_specback toPRIV_VERSION_LATESTto fix this; anyone deriving a new CPU subtype from a SiFive-family parent
should be aware this default does not propagate the way ISA extension bits might be assumed to.
- VEGA does not generate a device tree internally. -dtb is required for any -kernel (Linux/BBL) boot; the machine errors out clearly if
a kernel is given without -dtb and without -bios firmware. A bare "-M vega" with no boot arguments at all (e.g. qtest's generic smoke tests) is a valid, inert state and does not error. This keeps
the initial series scoped to what has been directly tested; internal FDT generation may follow as a later series.
- PLIC and CLINT compatible strings are "cdac,plic-1.0.0" and "riscv,clint0" respectively. CDAC's own Buildroot-based BBL/Linux builds use a CDAC-specific PLIC driver matched against the former, and use the generic CLINT compatible string directly (no CDAC-specific CLINT driver exists in any current VEGA firmware variant). A DTB intended to boot stock, unmodified riscv-pk/BBL (which only recognises "riscv,plic0" verbatim) will need to additionally advertise that generic string for the PLIC node.
Quoted 6 lines
What is NOT included / deliberately left out
---------------------------------------------
- No AIA/APLIC/IMSIC support: current VEGA silicon does not implement
AIA, so that code path (present in earlier internal revisions) has been removed rather than left as dead code.
Again, please read the AI code policy
https://www.qemu.org/docs/master/devel/code-provenance.html#use-of-ai-generated-content
Alistair
Quoted 76 lines
- No internal device-tree generation: see note above; -dtb is required for -kernel boots in this series.
- No SDHCI, SPI, I2C functional models yet: exposed as unimplemented-device stubs matching the real address ranges, so guest software can probe them safely; functional models may follow in later series.
- No RV32 Linux boot test yet: the functional test suite covers bare-metal on both architectures and a full Linux/BBL boot on riscv64 only, since an RV32 (Thejas32) Linux/BBL boot has not yet been verified; this may follow in a later series once available.Testing
-------
- riscv32-softmmu and riscv64-softmmu builds,make checkclean on both
- checkpatch.pl clean across the series
- Functional tests added undertests/functional/riscv32/test_vega.pyandtests/functional/riscv64/test_vega.py, passing via both direct invocation andmeson teston both architectures:
- bare-metal "hello world" boot (RV32 and RV64)
- full Linux boot via BBL to a login prompt (RV64)
- Manual testing additionally covered: virtio-net networking, and an extended stress-ng run (CPU, matrix, VM, filesystem, device-access stressors) under Linux on -M vegaWe previously posted an early version of VEGA machine support (Message-ID: <[email protected]>) without a proper cover letter,
MAINTAINERSentry, documentation, or tests, and sent via a webmail client rather than git send-email, which likely affected formatting. This series is a corrected resubmission addressing all of that: it is sent via git send-email, and adds the documentation,MAINTAINERSentry, and functional tests that were missing before. We've since read and followeddocs/devel/submitting-a-patch.rstin full. Feedback on process as well as code is very welcome.Karthika B (7):
hw/intc: Add CDAC VEGA PLIC device model hw/intc: Add CDAC VEGA ACLINT device model target/riscv: Add VEGA32 and VEGA64 CPU types hw/riscv: Add CDAC VEGA machine model docs/system/riscv: Add VEGA machine documentation tests/functional: Add VEGA machine functional tests
MAINTAINERS: Add entry for VEGA machineMAINTAINERS | 14 + configs/devices/riscv64-softmmu/default.mak | 1 + docs/system/riscv/vega.rst | 219 +++++++ docs/system/target-riscv.rst | 1 + hw/intc/Kconfig | 7 + hw/intc/meson.build | 2 + hw/intc/vega_aclint.c | 668
++++++++++++++++++++
hw/intc/vega_plic.c | 517 +++++++++++++++ hw/riscv/Kconfig | 11 + hw/riscv/meson.build | 1 + hw/riscv/vega.c | 502 +++++++++++++++ include/hw/intc/vega_aclint.h | 84 +++ include/hw/intc/vega_plic.h | 87 +++ include/hw/riscv/vega.h | 136 ++++ target/riscv/cpu-qom.h | 2 + target/riscv/cpu.c | 25 + tests/functional/riscv32/meson.build | 1 + tests/functional/riscv32/test_vega.py | 32 + tests/functional/riscv64/meson.build | 1 + tests/functional/riscv64/test_vega.py | 63 ++20 files changed, 2374 insertions(+)create mode 100644
docs/system/riscv/vega.rstcreate mode 100644hw/intc/vega_aclint.c
create mode 100644hw/intc/vega_plic.c
create mode 100644hw/riscv/vega.c
create mode 100644include/hw/intc/vega_aclint.hcreate mode 100644include/hw/intc/vega_plic.hcreate mode 100644include/hw/riscv/vega.hcreate mode 100644tests/functional/riscv32/test_vega.pycreate mode 100644tests/functional/riscv64/test_vega.py