hw/riscv/virt: Add CXL support to the RISC-V virt machine
v6 cover hw/riscv/virt: Add CXL support to the RISC-V virt machine
This series adds CXL support to the RISC-V virt machine, following the approach used by the ARM virt machine: CXL host bridges (pxb-cxl) are described as ACPI0016 devices, an ACPI0017 (CXLM) device is added to the DSDT with a _DEP on the CXL host bridges, and a CEDT table is built. A bios-tables test is added to pin down the generated ACPI tables.
Changes since v5
----------------
- Rebased onto current master, over the gpex_pcie_init() move to device-common.c: s->pci_bus is now assigned at the riscv_gpex_pcie_init() call site in virt_machine_init().
- tests/qtest: switched to the renamed in-tree firmware blobs pc-bios/edk2-riscv64-{code,vars}.fd (Junjie). The goldens are unchanged and still match with the updated edk2-stable202608 blob; all riscv64 ACPI cases pass.
- hw/riscv/virt-acpi-build: the _DEP commit message now cites the
companion kernel commit bf5418a5fe63 ("ACPI: scan: Honor _DEP for
ACPI0016 PCI/CXL host bridge") alongside 3a59c3b772e5, both in
v7.2 (Junjie).- Collected review tags: Junjie Cao's Reviewed-by/Tested-by on patches 1, 2 and 6. Michael S. Tsirkin acked the ACPI parts on the v5 cover letter thread.
Changes since v4
----------------
- tests/qtest: DSDT.cxl regenerated against the in-tree edk2-riscv-code.fd blob that the test boots (Junjie): the v4 golden carried the window allocation of my local edk2-stable202602 build. The 64-bit window is now 0x400100000..0x40010FFFF with the matching PCI0 range shift; the AML fragment in the commit message is updated accordingly. CEDT.cxl is unchanged.
- hw/riscv/virt: pci_bus_add_fw_cfg_extra_pci_roots() moved out of the cxl block (Junjie), so plain pxb-pcie expander bridges are also advertised to firmware with cxl=off, in line with arm/virt, pc and hppa.
- Collected review tags.
Changes since v3
----------------
- The CXL host bridge resource handling is reworked, following Junjie Cao's suggestion (and Igor Mammedov's earlier "fix UEFI" direction):
instead of reserving a fixed 256 MiB carve-out and simulating the firmware PCI initialization in QEMU, the machine now advertises the pxb-cxl expander root buses to firmware via the etc/extra-pci-roots fw_cfg file (pci_bus_add_fw_cfg_extra_pci_roots(), as arm/virt and x86 do). EDK2's PciBusDxe then enumerates behind the CXL host bridge and assigns the root-port window and bus numbers, and build_crs() emits a correct _CRS for the ACPI0016 host bridge. This keeps the machine code minimal (a single call, no carve-out), scales to multiple pxb-cxl host bridges, and lets firmware size the window to what is actually behind the bridge.
- The bios-tables test is split into the staged flow documented in bios-tables-test.c, and ordered the same way the riscv64 goldens were originally added upstream (Sunil V L's commit cc3ba2422554 et al.):
the feature code comes first, then three consecutive commits -- empty golden files + allowed-diff.h, the test code, and the populated golden master binaries with an emptied allowed-diff.h.
Changes since v2
----------------
- hw/riscv/virt: The MMIO-window patch no longer touches the common gpex code (Igor). The gpex_cfg.cxl_mmio32 field and the is_cxl static _CRS branch are dropped; the ACPI0016 _CRS now comes from the generic build_crs() path. Since EDK2 does not enumerate the pxb-cxl expander bridge, riscv simulates the firmware PCI initialization (reserved window + depth-first bridge bus numbers) and re-applies it via a reset handler.
- hw/riscv/virt: Drops the machine-global window/bus-range synthesis that did not scale past one pxb-cxl (Junjie). The series targets a single CXL host bridge for now, documented in the commit message and a TODO.
- hw/riscv/virt: CXL host register region and FMW setup folded into a single cxl_host_state_init() helper; redundant braces removed in create_fdt_pcie() (Daniel).
- hw/riscv/virt-acpi-build: the _DEP commit message documents the kernel-compatibility behaviour (Alistair).
- Carried review tags: Sunil V L's Reviewed-by on the _DEP patch and Alistair Francis's Acked-by on the test.
Changes since v1
----------------
- hw/riscv/virt: PCIBus *bus renamed to PCIBus *pci_bus (Jonathan).
- hw/riscv/virt: Dropped outer if (s->pci_bus) guard around cxl_hook_up_pxb_registers(); the function already handles a NULL bus internally (Jonathan).
- hw/riscv/virt-acpi-build: All s->bus references updated to
s->pci_bus; iasl -d decompiled DSDT fragment added to commit
message.
- hw/riscv/virt,gpex: Commit message expanded with PCI-to-PCI Bridge
Spec §3.2.5.8/9/10 citations (Jonathan). - Original patch 4 ("Map committed HDM decoder ranges as RAM for direct DMA") dropped; superseded by Alireza Sanaee's v8 series [1], which is now merged upstream and thus no longer a prerequisite.
- New patch 4: RISC-V ACPI bios-tables test for CXL, with golden AML files generated and included.
[1] https://lore.kernel.org/qemu-devel/[email protected]/
Test
----
Built riscv64-softmmu and ran the new bios-tables test together with the existing riscv64 ACPI tests; all pass.
Also booted an RVA22 guest with EDK2 firmware, using pxb-cxl + cxl-rp + cxl-type3 + a CFMW: EDK2's PciBusDxe enumerates behind the CXL host bridge (advertised via etc/extra-pci-roots), the root port and Type3 device show up (0000:0c:00.0 / 0000:0d:00.0), and 'cxl list' reports the memdev (4 GiB) and the CFMWS root decoder.
QEMU invocation (CXL-relevant options shown):
qemu-system-riscv64 \
-M virt,aia=aplic-imsic,acpi=on,cxl=on \
-cpu rva22s64 -smp 2 -m 4G \
-object memory-backend-ram,id=vmem0,share=on,size=4G \
-device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1 \
-device cxl-rp,port=0,bus=cxl.1,id=rp0,chassis=0,slot=2 \
-device cxl-type3,bus=rp0,volatile-memdev=vmem0 \
-M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G \
...Verification (total system memory grows by 4 GiB after onlining):
# cxl list
# cxl enable-memdev mem0
# cxl create-region -m -t ram -d decoder0.0 -w 1 mem0 -s 4G
# daxctl online-memory dax0.0
# free -hChen Pei (6):
hw/riscv/virt: Add CXL support to the RISC-V virt machine hw/riscv/virt-acpi-build: Add _DEP to ACPI0017 for CXL host bridge
dependency
hw/riscv/virt: Advertise the CXL host bridge to firmware via
extra-pci-roots
tests/qtest: Prepare golden files for the RISC-V CXL ACPI test tests/qtest: Add RISC-V ACPI bios tables test for CXL tests/qtest: Update RISC-V CXL ACPI golden master binaries
hw/riscv/Kconfig | 2 + hw/riscv/virt-acpi-build.c | 52 +++++++++++++++++++++++++ hw/riscv/virt.c | 56 +++++++++++++++++++++++++++++++--- include/hw/riscv/virt.h | 3 ++ tests/data/acpi/riscv64/virt/CEDT.cxl | Bin 0 -> 108 bytes tests/data/acpi/riscv64/virt/DSDT.cxl | Bin 0 -> 6331 bytes tests/qtest/bios-tables-test.c | 54 ++++++++++++++++++++++++++ 7 files changed, 163 insertions(+), 4 deletions(-) create mode 100644 tests/data/acpi/riscv64/virt/CEDT.cxl create mode 100644 tests/data/acpi/riscv64/virt/DSDT.cxl
Signature · 1 line
2.50.1
PATCH v6 1/6 hw/riscv/virt: Add CXL support to the RISC-V virt machine
Enable CXL support on the RISC-V virt machine following the same approach used by the ARM virt machine:
- Add PXB and ACPI_CXL Kconfig selections
- Add CXLState and PCIBus pointer to RISCVVirtState
- Register CXL machine properties via cxl_machine_init()
- Create CXL host register region above the PCIe high MMIO region
- Call cxl_hook_up_pxb_registers() and cxl_fmws_link_targets() at machine_done time
- Map Fixed Memory Windows above the CXL host register region
- Add ACPI0017 device in DSDT and build CEDT table in virt-acpi-build.c
--- hw/riscv/Kconfig | 2 ++ hw/riscv/virt-acpi-build.c | 20 ++++++++++++++++ hw/riscv/virt.c | 47 ++++++++++++++++++++++++++++++++++---- include/hw/riscv/virt.h | 3 +++ 4 files changed, 68 insertions(+), 4 deletions(-)
hw/riscv/Kconfig +2 -0
@@ -66,8 +66,10 @@ config RISCV_VIRT select VIRTIO_MMIO select FW_CFG_DMA select PLATFORM_BUS + select PXB select ACPI select ACPI_PCI + select ACPI_CXL config SHAKTI_C bool
hw/riscv/virt-acpi-build.c +20 -0
@@ -29,12 +29,16 @@#include "hw/acpi/aml-build.h" #include "hw/acpi/pci.h" #include "hw/acpi/utils.h" +#include "hw/acpi/cxl.h" #include "hw/intc/riscv_aclint.h" #include "hw/nvram/fw_cfg_acpi.h" #include "hw/pci-host/gpex.h" +#include "hw/pci/pci_bus.h" #include "hw/riscv/virt.h" #include "hw/riscv/numa.h" #include "hw/virtio/virtio-acpi.h" +#include "hw/cxl/cxl.h" +#include "hw/cxl/cxl_host.h" #include "kvm/kvm_riscv.h" #include "migration/vmstate.h" #include "qapi/error.h"
@@ -518,6 +522,17 @@ static void build_dsdt(GArray *table_data,acpi_dsdt_add_gpex_host (scope,PCIE_IRQ + s->num_sources *2 ); } +if (s->cxl_devices_state.is_enabled) { +Aml *cxl_dev =aml_device ("CXLM" ); +aml_append (cxl_dev,aml_name_decl ("_HID" ,aml_string ("ACPI0017" ))); +Aml *method =aml_method ("_STA" ,0 ,AML_NOTSERIALIZED ); +aml_append (method,aml_return (aml_int (0x0B ))); +aml_append (cxl_dev, method); +build_cxl_dsm_method (cxl_dev); + +aml_append (scope, cxl_dev); + } +aml_append (dsdt, scope);/* copy AML table into ACPI tables blob and patch header there */
@@ -925,6 +940,11 @@ static void virt_acpi_build(RISCVVirtState *s, AcpiBuildTables *tables) s->oem_table_id); } +if (s->cxl_devices_state.is_enabled) { +cxl_build_cedt (table_offsets, tables_blob, tables->linker, + s->oem_id, s->oem_table_id, &s->cxl_devices_state); + } +if (ms->numa_state->num_nodes >0 ) {acpi_add_table (table_offsets, tables_blob);build_srat (tables_blob, tables->linker, s);
hw/riscv/virt.c +43 -4
89 lines not on this page · raw message
include/hw/riscv/virt.h +3 -0
@@ -24,6 +24,7 @@#include "hw/core/sysbus.h" #include "hw/block/flash.h" #include "hw/intc/riscv_imsic.h" +#include "hw/cxl/cxl.h" #define VIRT_CPUS_MAX_BITS 9#define VIRT_CPUS_MAX (1 << VIRT_CPUS_MAX_BITS)
@@ -66,6 +67,8 @@ struct RISCVVirtState {OnOffAuto iommu_sys;uint16_t pci_iommu_bdf;uint16_t num_sources; +CXLState cxl_devices_state; +PCIBus *pci_bus; };enum {
Signature · 1 line
2.50.1
Quoted 11 lines · Chen Pei
Enable CXL support on the RISC-V virt machine following the same approach used by the ARM virt machine:
- Add PXB andACPI_CXLKconfigselections
- Add CXLState and PCIBus pointer to RISCVVirtState
- Register CXL machine properties viacxl_machine_init()
- Create CXL host register region above the PCIe high MMIO region
- Callcxl_hook_up_pxb_registers()andcxl_fmws_link_targets()atmachine_donetime
- Map Fixed Memory Windows above the CXL host register region
- Add ACPI0017 device in DSDT and build CEDT table invirt-acpi-build.c
Quoted 3 lines
Reviewed-by Junjie Cao <[email protected]>Tested-by Junjie Cao <[email protected]>Signed-off-by Chen Pei <[email protected]>
Thanks,
Chao
Quoted 197 lines
--- hw/riscv/Kconfig | 2 ++ hw/riscv/virt-acpi-build.c | 20 ++++++++++++++++ hw/riscv/virt.c | 47 ++++++++++++++++++++++++++++++++++---- include/hw/riscv/virt.h | 3 +++ 4 files changed, 68 insertions(+), 4 deletions(-)hw/riscv/Kconfig +2
-0@@ -66,8 +66,10 @@ config RISCV_VIRT select VIRTIO_MMIO select FW_CFG_DMA select PLATFORM_BUS + select PXB select ACPI select ACPI_PCI + select ACPI_CXL config SHAKTI_C boolhw/riscv/virt-acpi-build.c +20
-0@@ -29,12 +29,16 @@#include "hw/acpi/aml-build.h" #include "hw/acpi/pci.h" #include "hw/acpi/utils.h" +#include "hw/acpi/cxl.h" #include "hw/intc/riscv_aclint.h" #include "hw/nvram/fw_cfg_acpi.h" #include "hw/pci-host/gpex.h" +#include "hw/pci/pci_bus.h" #include "hw/riscv/virt.h" #include "hw/riscv/numa.h" #include "hw/virtio/virtio-acpi.h" +#include "hw/cxl/cxl.h" +#include "hw/cxl/cxl_host.h" #include "kvm/kvm_riscv.h" #include "migration/vmstate.h" #include "qapi/error.h" @@ -518,6 +522,17 @@ static void build_dsdt(GArray *table_data,acpi_dsdt_add_gpex_host (scope,PCIE_IRQ + s->num_sources *2 ); } +if (s->cxl_devices_state.is_enabled) { +Aml *cxl_dev =aml_device ("CXLM" ); +aml_append (cxl_dev,aml_name_decl ("_HID" ,aml_string ("ACPI0017" ))); +Aml *method =aml_method ("_STA" ,0 ,AML_NOTSERIALIZED ); +aml_append (method,aml_return (aml_int (0x0B ))); +aml_append (cxl_dev, method); +build_cxl_dsm_method (cxl_dev); + +aml_append (scope, cxl_dev); + } +aml_append (dsdt, scope);/* copy AML table into ACPI tables blob and patch header there */ @@ -925,6 +940,11 @@ static void virt_acpi_build(RISCVVirtState *s, AcpiBuildTables *tables) s->oem_table_id); } +if (s->cxl_devices_state.is_enabled) { +cxl_build_cedt (table_offsets, tables_blob, tables->linker, + s->oem_id, s->oem_table_id, &s->cxl_devices_state); + } +if (ms->numa_state->num_nodes >0 ) {acpi_add_table (table_offsets, tables_blob);build_srat (tables_blob, tables->linker, s);hw/riscv/virt.c +43
-4@@ -56,6 +56,8 @@#include "hw/pci/pci.h" #include "hw/pci-host/gpex.h" #include "hw/display/ramfb.h" +#include "hw/cxl/cxl.h" +#include "hw/cxl/cxl_host.h" #include "hw/acpi/aml-build.h" #include "qapi/qapi-visit-common.h" #include "hw/virtio/virtio-iommu.h" @@ -540,6 +542,29 @@ static void create_fdt(RISCVVirtState *s)create_fdt_pmu (s); } +static void cxl_host_state_init (RISCVVirtState *s) +{ +MemoryRegion *sysmem =get_system_memory (); +MemoryRegion *mr = &s->cxl_devices_state.host_mr; +hwaddr base; + +if (!s->cxl_devices_state.is_enabled) { +return ; + } + + base = virt_high_pcie_memmap.base + virt_high_pcie_memmap.size; + base =ROUND_UP (base,64 * KiB); + +memory_region_init (mr,OBJECT (s),"cxl_host_reg" ,64 * KiB *16 ); +memory_region_add_subregion (sysmem, base, mr); + +/* Map the Fixed Memory Windows above the CXL host register region. */ + base +=memory_region_size (mr); + base =ROUND_UP (base,256 * MiB); +cxl_fmws_set_memmap (base,UINT64_MAX ); +cxl_fmws_update_mmio (); +} +static FWCfgState *create_fw_cfg (const MachineState *ms,hwaddr base) {FWCfgState *fw_cfg;@@ -625,6 +650,13 @@ static void virt_machine_done(Notifier *notifier, void *data)BlockBackend *pflash_blk0;RISCVBootInfo boot_info; +cxl_hook_up_pxb_registers (s->pci_bus, &s->cxl_devices_state, + &error_fatal); + +if (s->cxl_devices_state.is_enabled) { +cxl_fmws_link_targets (&error_fatal); + } +/* * An user provided dtb must include everything, including * dynamic sysbus devices. Our FDT needs to be finalized. @@ -716,6 +748,7 @@ static void virt_machine_init(MachineState *machine)MemoryRegion *system_memory =get_system_memory ();MemoryRegion *mask_rom =g_new (MemoryRegion,1 );DeviceState *mmio_irqchip, *virtio_irqchip, *pcie_irqchip; +DeviceState *gpex_dev;int i, base_hartid, hart_count;int socket_count =riscv_socket_count (machine);@@ -871,6 +904,8 @@ static void virt_machine_init(MachineState *machine)ROUND_UP (virt_high_pcie_memmap.base, virt_high_pcie_memmap.size); } +cxl_host_state_init (s); +/* register system main memory (actual RAM) */ memory_region_add_subregion (system_memory, s->memmap[VIRT_DRAM ].base, machine->ram);@@ -898,10 +933,12 @@ static void virt_machine_init(MachineState *machine) qdev_get_gpio_in(virtio_irqchip, VIRTIO_IRQ + i)); } -riscv_gpex_pcie_init (system_memory, pcie_irqchip, - &s->memmap[VIRT_PCIE_ECAM ], &s->memmap[VIRT_PCIE_MMIO ], - &virt_high_pcie_memmap, &s->memmap[VIRT_PCIE_PIO ], -PCIE_IRQ ); + gpex_dev =riscv_gpex_pcie_init (system_memory, pcie_irqchip, + &s->memmap[VIRT_PCIE_ECAM ], + &s->memmap[VIRT_PCIE_MMIO ], + &virt_high_pcie_memmap, + &s->memmap[VIRT_PCIE_PIO ],PCIE_IRQ ); + s->pci_bus =PCI_HOST_BRIDGE (gpex_dev)->bus; s->platform_bus_dev = riscv_create_platform_bus(mmio_irqchip, &s->memmap[VIRT_PLATFORM_BUS], VIRT_PLATFORM_BUS_IRQ,@@ -972,6 +1009,8 @@ static void virt_machine_instance_init(Object *obj) s->acpi =ON_OFF_AUTO_AUTO ; s->iommu_sys =ON_OFF_AUTO_AUTO ; s->num_sources =VIRT_IRQCHIP_NUM_SOURCES ; + +cxl_machine_init (obj, &s->cxl_devices_state); }static char *virt_get_aia_guests (Object *obj,Error **errp)include/hw/riscv/virt.h +3
-0@@ -24,6 +24,7 @@#include "hw/core/sysbus.h" #include "hw/block/flash.h" #include "hw/intc/riscv_imsic.h" +#include "hw/cxl/cxl.h" #define VIRT_CPUS_MAX_BITS 9#define VIRT_CPUS_MAX (1 << VIRT_CPUS_MAX_BITS)@@ -66,6 +67,8 @@ struct RISCVVirtState {OnOffAuto iommu_sys;uint16_t pci_iommu_bdf;uint16_t num_sources; +CXLState cxl_devices_state; +PCIBus *pci_bus; };enum {Signature · 1 line
2.50.1
Quoted 11 lines · On Mon, 7 Sep 2026 17:37:28 +0800 Chen Pei <[email protected]> wrote:
Enable CXL support on the RISC-V virt machine following the same approach used by the ARM virt machine:
- Add PXB andACPI_CXLKconfigselections
- Add CXLState and PCIBus pointer to RISCVVirtState
- Register CXL machine properties viacxl_machine_init()
- Create CXL host register region above the PCIe high MMIO region
- Callcxl_hook_up_pxb_registers()andcxl_fmws_link_targets()atmachine_donetime
- Map Fixed Memory Windows above the CXL host register region
- Add ACPI0017 device in DSDT and build CEDT table invirt-acpi-build.c
Quoted 3 lines
Reviewed-by Junjie Cao <[email protected]>Tested-by Junjie Cao <[email protected]>Signed-off-by Chen Pei <[email protected]>
Sorry for delay. LGTM
Quoted 194 lines
--- hw/riscv/Kconfig | 2 ++ hw/riscv/virt-acpi-build.c | 20 ++++++++++++++++ hw/riscv/virt.c | 47 ++++++++++++++++++++++++++++++++++---- include/hw/riscv/virt.h | 3 +++ 4 files changed, 68 insertions(+), 4 deletions(-)hw/riscv/Kconfig +2
-0@@ -66,8 +66,10 @@ config RISCV_VIRT select VIRTIO_MMIO select FW_CFG_DMA select PLATFORM_BUS + select PXB select ACPI select ACPI_PCI + select ACPI_CXL config SHAKTI_C boolhw/riscv/virt-acpi-build.c +20
-0@@ -29,12 +29,16 @@#include "hw/acpi/aml-build.h" #include "hw/acpi/pci.h" #include "hw/acpi/utils.h" +#include "hw/acpi/cxl.h" #include "hw/intc/riscv_aclint.h" #include "hw/nvram/fw_cfg_acpi.h" #include "hw/pci-host/gpex.h" +#include "hw/pci/pci_bus.h" #include "hw/riscv/virt.h" #include "hw/riscv/numa.h" #include "hw/virtio/virtio-acpi.h" +#include "hw/cxl/cxl.h" +#include "hw/cxl/cxl_host.h" #include "kvm/kvm_riscv.h" #include "migration/vmstate.h" #include "qapi/error.h" @@ -518,6 +522,17 @@ static void build_dsdt(GArray *table_data,acpi_dsdt_add_gpex_host (scope,PCIE_IRQ + s->num_sources *2 ); } +if (s->cxl_devices_state.is_enabled) { +Aml *cxl_dev =aml_device ("CXLM" ); +aml_append (cxl_dev,aml_name_decl ("_HID" ,aml_string ("ACPI0017" ))); +Aml *method =aml_method ("_STA" ,0 ,AML_NOTSERIALIZED ); +aml_append (method,aml_return (aml_int (0x0B ))); +aml_append (cxl_dev, method); +build_cxl_dsm_method (cxl_dev); + +aml_append (scope, cxl_dev); + } +aml_append (dsdt, scope);/* copy AML table into ACPI tables blob and patch header there */ @@ -925,6 +940,11 @@ static void virt_acpi_build(RISCVVirtState *s, AcpiBuildTables *tables) s->oem_table_id); } +if (s->cxl_devices_state.is_enabled) { +cxl_build_cedt (table_offsets, tables_blob, tables->linker, + s->oem_id, s->oem_table_id, &s->cxl_devices_state); + } +if (ms->numa_state->num_nodes >0 ) {acpi_add_table (table_offsets, tables_blob);build_srat (tables_blob, tables->linker, s);hw/riscv/virt.c +43
-4@@ -56,6 +56,8 @@#include "hw/pci/pci.h" #include "hw/pci-host/gpex.h" #include "hw/display/ramfb.h" +#include "hw/cxl/cxl.h" +#include "hw/cxl/cxl_host.h" #include "hw/acpi/aml-build.h" #include "qapi/qapi-visit-common.h" #include "hw/virtio/virtio-iommu.h" @@ -540,6 +542,29 @@ static void create_fdt(RISCVVirtState *s)create_fdt_pmu (s); } +static void cxl_host_state_init (RISCVVirtState *s) +{ +MemoryRegion *sysmem =get_system_memory (); +MemoryRegion *mr = &s->cxl_devices_state.host_mr; +hwaddr base; + +if (!s->cxl_devices_state.is_enabled) { +return ; + } + + base = virt_high_pcie_memmap.base + virt_high_pcie_memmap.size; + base =ROUND_UP (base,64 * KiB); + +memory_region_init (mr,OBJECT (s),"cxl_host_reg" ,64 * KiB *16 ); +memory_region_add_subregion (sysmem, base, mr); + +/* Map the Fixed Memory Windows above the CXL host register region. */ + base +=memory_region_size (mr); + base =ROUND_UP (base,256 * MiB); +cxl_fmws_set_memmap (base,UINT64_MAX ); +cxl_fmws_update_mmio (); +} +static FWCfgState *create_fw_cfg (const MachineState *ms,hwaddr base) {FWCfgState *fw_cfg;@@ -625,6 +650,13 @@ static void virt_machine_done(Notifier *notifier, void *data)BlockBackend *pflash_blk0;RISCVBootInfo boot_info; +cxl_hook_up_pxb_registers (s->pci_bus, &s->cxl_devices_state, + &error_fatal); + +if (s->cxl_devices_state.is_enabled) { +cxl_fmws_link_targets (&error_fatal); + } +/* * An user provided dtb must include everything, including * dynamic sysbus devices. Our FDT needs to be finalized. @@ -716,6 +748,7 @@ static void virt_machine_init(MachineState *machine)MemoryRegion *system_memory =get_system_memory ();MemoryRegion *mask_rom =g_new (MemoryRegion,1 );DeviceState *mmio_irqchip, *virtio_irqchip, *pcie_irqchip; +DeviceState *gpex_dev;int i, base_hartid, hart_count;int socket_count =riscv_socket_count (machine);@@ -871,6 +904,8 @@ static void virt_machine_init(MachineState *machine)ROUND_UP (virt_high_pcie_memmap.base, virt_high_pcie_memmap.size); } +cxl_host_state_init (s); +/* register system main memory (actual RAM) */ memory_region_add_subregion (system_memory, s->memmap[VIRT_DRAM ].base, machine->ram);@@ -898,10 +933,12 @@ static void virt_machine_init(MachineState *machine) qdev_get_gpio_in(virtio_irqchip, VIRTIO_IRQ + i)); } -riscv_gpex_pcie_init (system_memory, pcie_irqchip, - &s->memmap[VIRT_PCIE_ECAM ], &s->memmap[VIRT_PCIE_MMIO ], - &virt_high_pcie_memmap, &s->memmap[VIRT_PCIE_PIO ], -PCIE_IRQ ); + gpex_dev =riscv_gpex_pcie_init (system_memory, pcie_irqchip, + &s->memmap[VIRT_PCIE_ECAM ], + &s->memmap[VIRT_PCIE_MMIO ], + &virt_high_pcie_memmap, + &s->memmap[VIRT_PCIE_PIO ],PCIE_IRQ ); + s->pci_bus =PCI_HOST_BRIDGE (gpex_dev)->bus; s->platform_bus_dev = riscv_create_platform_bus(mmio_irqchip, &s->memmap[VIRT_PLATFORM_BUS], VIRT_PLATFORM_BUS_IRQ,@@ -972,6 +1009,8 @@ static void virt_machine_instance_init(Object *obj) s->acpi =ON_OFF_AUTO_AUTO ; s->iommu_sys =ON_OFF_AUTO_AUTO ; s->num_sources =VIRT_IRQCHIP_NUM_SOURCES ; + +cxl_machine_init (obj, &s->cxl_devices_state); }static char *virt_get_aia_guests (Object *obj,Error **errp)include/hw/riscv/virt.h +3
-0@@ -24,6 +24,7 @@#include "hw/core/sysbus.h" #include "hw/block/flash.h" #include "hw/intc/riscv_imsic.h" +#include "hw/cxl/cxl.h" #define VIRT_CPUS_MAX_BITS 9#define VIRT_CPUS_MAX (1 << VIRT_CPUS_MAX_BITS)@@ -66,6 +67,8 @@ struct RISCVVirtState {OnOffAuto iommu_sys;uint16_t pci_iommu_bdf;uint16_t num_sources; +CXLState cxl_devices_state; +PCIBus *pci_bus; };enum {
Quoted 11 lines · Chen Pei
Enable CXL support on the RISC-V virt machine following the same approach used by the ARM virt machine:
- Add PXB andACPI_CXLKconfigselections
- Add CXLState and PCIBus pointer to RISCVVirtState
- Register CXL machine properties viacxl_machine_init()
- Create CXL host register region above the PCIe high MMIO region
- Callcxl_hook_up_pxb_registers()andcxl_fmws_link_targets()atmachine_donetime
- Map Fixed Memory Windows above the CXL host register region
- Add ACPI0017 device in DSDT and build CEDT table invirt-acpi-build.c
Quoted 3 lines
Reviewed-by Junjie Cao <[email protected]>Tested-by Junjie Cao <[email protected]>Signed-off-by Chen Pei <[email protected]>
Thanks,
Nutty
Quoted 194 lines
--- hw/riscv/Kconfig | 2 ++ hw/riscv/virt-acpi-build.c | 20 ++++++++++++++++ hw/riscv/virt.c | 47 ++++++++++++++++++++++++++++++++++---- include/hw/riscv/virt.h | 3 +++ 4 files changed, 68 insertions(+), 4 deletions(-)hw/riscv/Kconfig +2
-0@@ -66,8 +66,10 @@ config RISCV_VIRT select VIRTIO_MMIO select FW_CFG_DMA select PLATFORM_BUS + select PXB select ACPI select ACPI_PCI + select ACPI_CXL config SHAKTI_C boolhw/riscv/virt-acpi-build.c +20
-0@@ -29,12 +29,16 @@#include "hw/acpi/aml-build.h" #include "hw/acpi/pci.h" #include "hw/acpi/utils.h" +#include "hw/acpi/cxl.h" #include "hw/intc/riscv_aclint.h" #include "hw/nvram/fw_cfg_acpi.h" #include "hw/pci-host/gpex.h" +#include "hw/pci/pci_bus.h" #include "hw/riscv/virt.h" #include "hw/riscv/numa.h" #include "hw/virtio/virtio-acpi.h" +#include "hw/cxl/cxl.h" +#include "hw/cxl/cxl_host.h" #include "kvm/kvm_riscv.h" #include "migration/vmstate.h" #include "qapi/error.h" @@ -518,6 +522,17 @@ static void build_dsdt(GArray *table_data,acpi_dsdt_add_gpex_host (scope,PCIE_IRQ + s->num_sources *2 ); } +if (s->cxl_devices_state.is_enabled) { +Aml *cxl_dev =aml_device ("CXLM" ); +aml_append (cxl_dev,aml_name_decl ("_HID" ,aml_string ("ACPI0017" ))); +Aml *method =aml_method ("_STA" ,0 ,AML_NOTSERIALIZED ); +aml_append (method,aml_return (aml_int (0x0B ))); +aml_append (cxl_dev, method); +build_cxl_dsm_method (cxl_dev); + +aml_append (scope, cxl_dev); + } +aml_append (dsdt, scope);/* copy AML table into ACPI tables blob and patch header there */ @@ -925,6 +940,11 @@ static void virt_acpi_build(RISCVVirtState *s, AcpiBuildTables *tables) s->oem_table_id); } +if (s->cxl_devices_state.is_enabled) { +cxl_build_cedt (table_offsets, tables_blob, tables->linker, + s->oem_id, s->oem_table_id, &s->cxl_devices_state); + } +if (ms->numa_state->num_nodes >0 ) {acpi_add_table (table_offsets, tables_blob);build_srat (tables_blob, tables->linker, s);hw/riscv/virt.c +43
-4@@ -56,6 +56,8 @@#include "hw/pci/pci.h" #include "hw/pci-host/gpex.h" #include "hw/display/ramfb.h" +#include "hw/cxl/cxl.h" +#include "hw/cxl/cxl_host.h" #include "hw/acpi/aml-build.h" #include "qapi/qapi-visit-common.h" #include "hw/virtio/virtio-iommu.h" @@ -540,6 +542,29 @@ static void create_fdt(RISCVVirtState *s)create_fdt_pmu (s); } +static void cxl_host_state_init (RISCVVirtState *s) +{ +MemoryRegion *sysmem =get_system_memory (); +MemoryRegion *mr = &s->cxl_devices_state.host_mr; +hwaddr base; + +if (!s->cxl_devices_state.is_enabled) { +return ; + } + + base = virt_high_pcie_memmap.base + virt_high_pcie_memmap.size; + base =ROUND_UP (base,64 * KiB); + +memory_region_init (mr,OBJECT (s),"cxl_host_reg" ,64 * KiB *16 ); +memory_region_add_subregion (sysmem, base, mr); + +/* Map the Fixed Memory Windows above the CXL host register region. */ + base +=memory_region_size (mr); + base =ROUND_UP (base,256 * MiB); +cxl_fmws_set_memmap (base,UINT64_MAX ); +cxl_fmws_update_mmio (); +} +static FWCfgState *create_fw_cfg (const MachineState *ms,hwaddr base) {FWCfgState *fw_cfg;@@ -625,6 +650,13 @@ static void virt_machine_done(Notifier *notifier, void *data)BlockBackend *pflash_blk0;RISCVBootInfo boot_info; +cxl_hook_up_pxb_registers (s->pci_bus, &s->cxl_devices_state, + &error_fatal); + +if (s->cxl_devices_state.is_enabled) { +cxl_fmws_link_targets (&error_fatal); + } +/* * An user provided dtb must include everything, including * dynamic sysbus devices. Our FDT needs to be finalized. @@ -716,6 +748,7 @@ static void virt_machine_init(MachineState *machine)MemoryRegion *system_memory =get_system_memory ();MemoryRegion *mask_rom =g_new (MemoryRegion,1 );DeviceState *mmio_irqchip, *virtio_irqchip, *pcie_irqchip; +DeviceState *gpex_dev;int i, base_hartid, hart_count;int socket_count =riscv_socket_count (machine);@@ -871,6 +904,8 @@ static void virt_machine_init(MachineState *machine)ROUND_UP (virt_high_pcie_memmap.base, virt_high_pcie_memmap.size); } +cxl_host_state_init (s); +/* register system main memory (actual RAM) */ memory_region_add_subregion (system_memory, s->memmap[VIRT_DRAM ].base, machine->ram);@@ -898,10 +933,12 @@ static void virt_machine_init(MachineState *machine) qdev_get_gpio_in(virtio_irqchip, VIRTIO_IRQ + i)); } -riscv_gpex_pcie_init (system_memory, pcie_irqchip, - &s->memmap[VIRT_PCIE_ECAM ], &s->memmap[VIRT_PCIE_MMIO ], - &virt_high_pcie_memmap, &s->memmap[VIRT_PCIE_PIO ], -PCIE_IRQ ); + gpex_dev =riscv_gpex_pcie_init (system_memory, pcie_irqchip, + &s->memmap[VIRT_PCIE_ECAM ], + &s->memmap[VIRT_PCIE_MMIO ], + &virt_high_pcie_memmap, + &s->memmap[VIRT_PCIE_PIO ],PCIE_IRQ ); + s->pci_bus =PCI_HOST_BRIDGE (gpex_dev)->bus; s->platform_bus_dev = riscv_create_platform_bus(mmio_irqchip, &s->memmap[VIRT_PLATFORM_BUS], VIRT_PLATFORM_BUS_IRQ,@@ -972,6 +1009,8 @@ static void virt_machine_instance_init(Object *obj) s->acpi =ON_OFF_AUTO_AUTO ; s->iommu_sys =ON_OFF_AUTO_AUTO ; s->num_sources =VIRT_IRQCHIP_NUM_SOURCES ; + +cxl_machine_init (obj, &s->cxl_devices_state); }static char *virt_get_aia_guests (Object *obj,Error **errp)include/hw/riscv/virt.h +3
-0@@ -24,6 +24,7 @@#include "hw/core/sysbus.h" #include "hw/block/flash.h" #include "hw/intc/riscv_imsic.h" +#include "hw/cxl/cxl.h" #define VIRT_CPUS_MAX_BITS 9#define VIRT_CPUS_MAX (1 << VIRT_CPUS_MAX_BITS)@@ -66,6 +67,8 @@ struct RISCVVirtState {OnOffAuto iommu_sys;uint16_t pci_iommu_bdf;uint16_t num_sources; +CXLState cxl_devices_state; +PCIBus *pci_bus; };enum {
PATCH v6 2/6 hw/riscv/virt-acpi-build: Add _DEP to ACPI0017 for CXL host bridge dependency
In reply to Chen PeiOn RISC-V QEMU virt platform with CXL enabled, the probe ordering of acpi_pci_root (ACPI0016) and cxl_acpi (ACPI0017) is not guaranteed. If cxl_acpi probes before acpi_pci_root has attached the CXL host bridges, the CXL port topology will be incomplete because to_cxl_host_bridge() silently skips devices whose PCI root is not yet ready.
Add a _DEP object to the ACPI0017 device in the DSDT, declaring its dependency on the ACPI0016 CXL host bridge devices. This tells the OS to defer ACPI0017 enumeration until all ACPI0016 devices have been attached by acpi_pci_root.
This pairs with two kernel commits, both merged in v7.2:bf5418a5fe63 ("ACPI: scan: Honor _DEP for ACPI0016 PCI/CXL host bridge") makes the ACPI core defer ACPI0017 enumeration while its _DEP targets are unattached, and 3a59c3b772e5 ("ACPI: PCI: Clear _DEP dependencies after PCI root bridge attach") clears the dependency from acpi_pci_root_add() once the host bridge is attached.
Note on kernel compatibility: this is a "new QEMU feature requires a sufficiently new kernel" situation. Kernels that process _DEP but lack the acpi_dev_clear_dependencies() call will leave the CXLM device deferred, so CXL memory is unusable there; kernels old enough to ignore _DEP entirely behave exactly as before this change. In neither case is existing (non-CXL) PCIe affected.
The resulting DSDT fragment (iasl -d output) for a single CXL host bridge at bus 0x0C looks like:
Device (CXLM)
{
Name (_HID, "ACPI0017")
Name (_DEP, Package (0x01)
{
\_SB.PC0C
})
Method (_STA, 0, NotSerialized)
{
Return (0x0B)
}
...
}--- hw/riscv/virt-acpi-build.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
hw/riscv/virt-acpi-build.c +32 -0
@@ -525,6 +525,38 @@ static void build_dsdt(GArray *table_data,if (s->cxl_devices_state.is_enabled) {Aml *cxl_dev =aml_device ("CXLM" );aml_append (cxl_dev,aml_name_decl ("_HID" ,aml_string ("ACPI0017" ))); + +/* +* Declare a _DEP on every ACPI0016 CXL host bridge so the OS +* defers ACPI0017 enumeration until acpi_pci_root has attached +* the CXL host bridges. Without this, cxl_acpi may probe before +* to_cxl_host_bridge() can resolve the PCI root and the CXL +* port topology comes up empty. +*/ +if (s->pci_bus) { +PCIBus *bus; +uint32_t num_cxl_hbs =0 ; + + QLIST_FOREACH(bus, &s->pci_bus->child, sibling) { +if (pci_bus_is_root (bus) &&pci_bus_is_cxl (bus)) { + num_cxl_hbs++; + } + } + +if (num_cxl_hbs >0 ) { +Aml *dep_pkg =aml_package (num_cxl_hbs); + + QLIST_FOREACH(bus, &s->pci_bus->child, sibling) { +if (pci_bus_is_root (bus) &&pci_bus_is_cxl (bus)) { +aml_append (dep_pkg, +aml_name ("\\_SB.PC%.02X" , +pci_bus_num (bus))); + } + } +aml_append (cxl_dev,aml_name_decl ("_DEP" , dep_pkg)); + } + } +Aml *method =aml_method ("_STA" ,0 ,AML_NOTSERIALIZED );aml_append (method,aml_return (aml_int (0x0B )));aml_append (cxl_dev, method);
Signature · 1 line
2.50.1
Re: [PATCH v6 2/6] hw/riscv/virt-acpi-build: Add _DEP to ACPI0017 for CXL host bridge dependency
Quoted 43 lines · On Mon, 7 Sep 2026 17:37:29 +0800 Chen Pei <[email protected]> wrote:
On RISC-V QEMU virt platform with CXL enabled, the probe ordering of
acpi_pci_root(ACPI0016) andcxl_acpi(ACPI0017) is not guaranteed. Ifcxl_acpiprobes beforeacpi_pci_roothas attached the CXL host bridges, the CXL port topology will be incomplete becauseto_cxl_host_bridge()silently skips devices whose PCI root is not yet ready.Add a
_DEPobject to the ACPI0017 device in the DSDT, declaring its dependency on the ACPI0016 CXL host bridge devices. This tells the OS to defer ACPI0017 enumeration until all ACPI0016 devices have been attached byacpi_pci_root.This pairs with two kernel commits, both merged in v7.2:
bf5418a5fe63("ACPI: scan: Honor_DEPfor ACPI0016 PCI/CXL host bridge") makes the ACPI core defer ACPI0017 enumeration while its_DEPtargets are unattached, and3a59c3b772e5("ACPI: PCI: Clear_DEPdependencies after PCI root bridge attach") clears the dependency fromacpi_pci_root_add()once the host bridge is attached.Note on kernel compatibility: this is a "new QEMU feature requires a sufficiently new kernel" situation. Kernels that process
_DEPbut lack theacpi_dev_clear_dependencies()call will leave the CXLM device deferred, so CXL memory is unusable there; kernels old enough to ignore_DEPentirely behave exactly as before this change. In neither case is existing (non-CXL) PCIe affected.The resulting DSDT fragment (iasl -d output) for a single CXL host bridge at bus
0x0Clooks like:Device (CXLM) { Name (_HID, "ACPI0017") Name (_DEP, Package (0x01) { \_SB.PC0C }) Method (_STA, 0, NotSerialized) { Return (0x0B) } ... }
Quoted 3 lines
Reviewed-by Sunil V L <[email protected]>Reviewed-by Junjie Cao <[email protected]>Signed-off-by Chen Pei <[email protected]>
Whilst by luck we don't need this for Linux to be happy on other architectures, it may make sense to do it anyway.
When we do that maybe this should be factored out as a helper. For now LGTM
Quoted 47 lines
--- hw/riscv/virt-acpi-build.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)hw/riscv/virt-acpi-build.c +32
-0@@ -525,6 +525,38 @@ static void build_dsdt(GArray *table_data,if (s->cxl_devices_state.is_enabled) {Aml *cxl_dev =aml_device ("CXLM" );aml_append (cxl_dev,aml_name_decl ("_HID" ,aml_string ("ACPI0017" ))); + +/* +* Declare a _DEP on every ACPI0016 CXL host bridge so the OS +* defers ACPI0017 enumeration until acpi_pci_root has attached +* the CXL host bridges. Without this, cxl_acpi may probe before +* to_cxl_host_bridge() can resolve the PCI root and the CXL +* port topology comes up empty. +*/ +if (s->pci_bus) { +PCIBus *bus; +uint32_t num_cxl_hbs =0 ; + + QLIST_FOREACH(bus, &s->pci_bus->child, sibling) { +if (pci_bus_is_root (bus) &&pci_bus_is_cxl (bus)) { + num_cxl_hbs++; + } + } + +if (num_cxl_hbs >0 ) { +Aml *dep_pkg =aml_package (num_cxl_hbs); + + QLIST_FOREACH(bus, &s->pci_bus->child, sibling) { +if (pci_bus_is_root (bus) &&pci_bus_is_cxl (bus)) { +aml_append (dep_pkg, +aml_name ("\\_SB.PC%.02X" , +pci_bus_num (bus))); + } + } +aml_append (cxl_dev,aml_name_decl ("_DEP" , dep_pkg)); + } + } +Aml *method =aml_method ("_STA" ,0 ,AML_NOTSERIALIZED );aml_append (method,aml_return (aml_int (0x0B )));aml_append (cxl_dev, method);
PATCH v6 3/6 hw/riscv/virt: Advertise the CXL host bridge to firmware via extra-pci-roots
In reply to Chen PeiThe pxb-cxl expander bridge presents as a class 0x0600 host bridge with a type-0 header, so EDK2's PciBusDxe never recurses into it and never assigns the CXL root port a memory window or bus numbers. As a result build_crs() produces an empty _CRS for the ACPI0016 host bridge and the CXL devices behind it are not enumerated by the OS.
Advertise the pxb-cxl expander root buses to firmware via the etc/extra-pci-roots fw_cfg file, the same way arm/virt and x86 do, by calling pci_bus_add_fw_cfg_extra_pci_roots() from virt_machine_done(). EDK2's PciBusDxe then enumerates behind the CXL host bridge and assigns the root-port window and bus numbers. The ACPI tables are rebuilt when the guest reads them (after that firmware enumeration), so build_crs() then emits a correct _CRS for the ACPI0016 host bridge.
The call is made unconditionally, in line with arm/virt, pc and hppa, so plain pxb-pcie expander bridges, which likewise depend on etc/extra-pci-roots, are advertised as well; the generator simply returns nothing when there is no expander root bus.
This approach also scales to multiple pxb-cxl host bridges (each gets its own window from the shared aperture) and lets firmware size the window to what is actually behind the bridge, rather than reserving a fixed carve-out.
Verified by booting an RVA22 guest: the CXL root port and Type3 device enumerate, and 'cxl enable-memdev' / 'cxl create-region' / 'daxctl online-memory' bring the CXL memory online as system RAM.
--- hw/riscv/virt.c | 9 +++++++++ 1 file changed, 9 insertions(+)
hw/riscv/virt.c +9 -0
@@ -657,6 +657,15 @@ static void virt_machine_done(Notifier *notifier, void *data)cxl_fmws_link_targets (&error_fatal); } +/* +* Advertise the pxb/pxb-cxl expander root buses to firmware so that +* it enumerates behind them and assigns bus numbers and windows. For +* the CXL host bridges, build_crs() then builds the ACPI0016 _CRS +* from the resulting state when the guest reads the ACPI tables. +* This is a no-op without any expander root bus. +*/ +pci_bus_add_fw_cfg_extra_pci_roots (s->fw_cfg, s->pci_bus, &error_abort); +/* * An user provided dtb must include everything, including * dynamic sysbus devices. Our FDT needs to be finalized.
Signature · 1 line
2.50.1
Re: [PATCH v6 3/6] hw/riscv/virt: Advertise the CXL host bridge to firmware via extra-pci-roots
Quoted 24 lines · On Mon, 7 Sep 2026 17:37:30 +0800 Chen Pei <[email protected]> wrote:
The pxb-cxl expander bridge presents as a class
0x0600host bridge with a type-0 header, so EDK2's PciBusDxe never recurses into it and never assigns the CXL root port a memory window or bus numbers. As a resultbuild_crs()produces an empty_CRSfor the ACPI0016 host bridge and the CXL devices behind it are not enumerated by the OS.Advertise the pxb-cxl expander root buses to firmware via the etc/extra-pci-roots
fw_cfgfile, the same way arm/virt and x86 do, by callingpci_bus_add_fw_cfg_extra_pci_roots()fromvirt_machine_done(). EDK2's PciBusDxe then enumerates behind the CXL host bridge and assigns the root-port window and bus numbers. The ACPI tables are rebuilt when the guest reads them (after that firmware enumeration), sobuild_crs()then emits a correct_CRSfor the ACPI0016 host bridge.The call is made unconditionally, in line with arm/virt, pc and hppa, so plain pxb-pcie expander bridges, which likewise depend on etc/extra-pci-roots, are advertised as well; the generator simply returns nothing when there is no expander root bus.
This approach also scales to multiple pxb-cxl host bridges (each gets its own window from the shared aperture) and lets firmware size the window to what is actually behind the bridge, rather than reserving a fixed carve-out.
Quoted 7 lines
Verified by booting an RVA22 guest: the CXL root port and Type3 device enumerate, and 'cxl enable-memdev' / 'cxl create-region' / 'daxctl online-memory' bring the CXL memory online as system RAM.
Reviewed-by Junjie Cao <[email protected]>Tested-by Junjie Cao <[email protected]>Signed-off-by Chen Pei <[email protected]>
Aligns with other arch, so makes sense.
PATCH v6 4/6 tests/qtest: Prepare golden files for the RISC-V CXL ACPI test
In reply to Chen PeiAdd empty DSDT.cxl and CEDT.cxl golden files and list them in bios-tables-test-allowed-diff.h, in preparation for the RISC-V CXL bios-tables test added in the following patch. The populated golden master binaries are committed separately in a final patch, following the bios-tables-test update process.
--- tests/data/acpi/riscv64/virt/CEDT.cxl | 0 tests/data/acpi/riscv64/virt/DSDT.cxl | 0 tests/qtest/bios-tables-test-allowed-diff.h | 2 ++ 3 files changed, 2 insertions(+) create mode 100644 tests/data/acpi/riscv64/virt/CEDT.cxl create mode 100644 tests/data/acpi/riscv64/virt/DSDT.cxl
tests/data/acpi/riscv64/virt/CEDT.cxl new file +0 -0
tests/data/acpi/riscv64/virt/DSDT.cxl new file +0 -0
tests/qtest/bios-tables-test-allowed-diff.h +2 -0
@@ -1 +1,3 @@/* List of comma-separated changed AML files to ignore */ +"riscv64/virt/DSDT.cxl" , +"riscv64/virt/CEDT.cxl",
Signature · 1 line
2.50.1
Re: [PATCH v6 4/6] tests/qtest: Prepare golden files for the RISC-V CXL ACPI test
Quoted 8 lines · On Mon, 7 Sep 2026 17:37:31 +0800 Chen Pei <[email protected]> wrote:
Add empty DSDT.cxl and CEDT.cxl golden files and list them in
bios-tables-test-allowed-diff.h, in preparation for the RISC-V CXL bios-tables test added in the following patch. The populated golden master binaries are committed separately in a final patch, following the bios-tables-test update process.Reviewed-by Junjie Cao <[email protected]>Signed-off-by Chen Pei <[email protected]>
boilerplate but for completeness
PATCH v6 5/6 tests/qtest: Add RISC-V ACPI bios tables test for CXL
In reply to Chen PeiAdd test_acpi_riscv64_virt_tcg_cxl() to verify that enabling CXL on the RISC-V virt machine produces correct ACPI tables, including the ACPI0017 CXLM device with _DEP in the DSDT and the CEDT table.
The test boots with cxl=on, one pxb-cxl bus (bus_nr=12), a CXL root port, a cxl-type3 device and a fixed memory window, mirroring the existing x86 q35 CXL test pattern.
Since pxb-cxl is a root bus, using -cdrom causes QEMU to auto-plug the cdrom drive into pxb-cxl, triggering "Only PCI/PCIe bridges can be plugged into pxb-cxl". The ISO is instead attached explicitly via a virtio-scsi-pci controller on pcie.0, following the same approach as test_acpi_aarch64_virt_tcg_pxb().
--- tests/qtest/bios-tables-test.c | 54 ++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)
tests/qtest/bios-tables-test.c +54 -0
@@ -2214,6 +2214,56 @@ static void test_acpi_riscv64_virt_tcg(void)free_test_data (&data); } +#ifdef CONFIG_POSIX +static void test_acpi_riscv64_virt_tcg_cxl (void ) +{ +gchar *tmp_path =g_dir_make_tmp ("qemu-test-cxl.XXXXXX" ,NULL ); +gchar *params; + +test_data data = { + .machine ="virt" , + .arch ="riscv64" , + .tcg_only = true, + .uefi_fl1 ="pc-bios/edk2-riscv64-code.fd" , + .uefi_fl2 ="pc-bios/edk2-riscv64-vars.fd" , + .ram_start =0x80000000ULL , + .scan_len =128ULL * MiB, + .variant =".cxl" , + }; + +/* +* While using -cdrom, the cdrom would auto-plug into pxb-cxl because +* its bus is also a root bus, triggering "Only PCI/PCIe bridges can be +* plugged into pxb-cxl". Attach the ISO explicitly to a scsi controller +* on pcie.0 instead, following the same pattern as +* test_acpi_aarch64_virt_tcg_pxb(). +*/ + params =g_strdup_printf ("-cpu rva22s64" +" -machine cxl=on" +" -device pcie-root-port,chassis=1,id=pci.1,bus=pcie.0" +" -device virtio-scsi-pci,id=scsi0,bus=pci.1" +" -drive file=tests/data/uefi-boot-images/" +"bios-tables-test.riscv64.iso.qcow2," +"if=none,media=cdrom,id=drive-scsi0-0-0-1,readonly=on" +" -device scsi-cd,bus=scsi0.0,scsi-id=0," +"drive=drive-scsi0-0-0-1,id=scsi0-0-0-1,bootindex=1" +" -object memory-backend-file,id=cxl-mem1,mem-path=%s,size=256M" +" -object memory-backend-file,id=lsa1,mem-path=%s,size=256M" +" -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1" +" -device cxl-rp,port=0,bus=cxl.1,id=rp1,chassis=0,slot=2" +" -device cxl-type3,bus=rp1,persistent-memdev=cxl-mem1,lsa=lsa1" +" -M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G," +"cxl-fmw.0.interleave-granularity=8k" , + tmp_path, tmp_path); +test_acpi_one (params, &data); + +g_free (params); +g_assert (g_rmdir (tmp_path) ==0 ); +g_free (tmp_path); +free_test_data (&data); +} +#endif /* CONFIG_POSIX */ +static void test_acpi_aarch64_virt_tcg (void ) {test_data data = {
@@ -2971,6 +3021,10 @@ int main(int argc, char *argv[]) test_acpi_riscv64_virt_tcg_numamem);qtest_add_func ("acpi/virt/acpispcr" , test_acpi_riscv64_virt_tcg_acpi_spcr); +#ifdef CONFIG_POSIX +qtest_add_func ("acpi/virt/cxl" , + test_acpi_riscv64_virt_tcg_cxl); +#endif } }else if (strcmp (arch,"loongarch64" ) ==0 ) {if (has_tcg &&qtest_has_machine ("virt" )) {
Signature · 1 line
2.50.1
Re: [PATCH v6 5/6] tests/qtest: Add RISC-V ACPI bios tables test for CXL
Quoted 14 lines · On Mon, 7 Sep 2026 17:37:32 +0800 Chen Pei <[email protected]> wrote:
Add
test_acpi_riscv64_virt_tcg_cxl()to verify that enabling CXL on the RISC-V virt machine produces correct ACPI tables, including the ACPI0017 CXLM device with_DEPin the DSDT and the CEDT table.The test boots with cxl=on, one pxb-cxl bus (bus_nr=12), a CXL root port, a cxl-type3 device and a fixed memory window, mirroring the existing x86 q35 CXL test pattern.
Since pxb-cxl is a root bus, using -cdrom causes QEMU to auto-plug the cdrom drive into pxb-cxl, triggering "Only PCI/PCIe bridges can be plugged into pxb-cxl". The ISO is instead attached explicitly via a virtio-scsi-pci controller on pcie.0, following the same approach as
test_acpi_aarch64_virt_tcg_pxb().
Quoted 4 lines
Acked-by Alistair Francis <[email protected]>Reviewed-by Junjie Cao <[email protected]>Tested-by Junjie Cao <[email protected]>Signed-off-by Chen Pei <[email protected]>
One possible extra thing below and a general comment. This does the job though so no need to change anything.
Quoted 40 lines
--- tests/qtest/bios-tables-test.c | 54 ++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)tests/qtest/bios-tables-test.c +28
-0@@ -2214,6 +2214,56 @@ static void test_acpi_riscv64_virt_tcg(void)free_test_data (&data); } +#ifdef CONFIG_POSIX +static void test_acpi_riscv64_virt_tcg_cxl (void ) +{ +gchar *tmp_path =g_dir_make_tmp ("qemu-test-cxl.XXXXXX" ,NULL ); +gchar *params; + +test_data data = { + .machine ="virt" , + .arch ="riscv64" , + .tcg_only = true, + .uefi_fl1 ="pc-bios/edk2-riscv64-code.fd" , + .uefi_fl2 ="pc-bios/edk2-riscv64-vars.fd" , + .ram_start =0x80000000ULL , + .scan_len =128ULL * MiB, + .variant =".cxl" , + }; + +/* +* While using -cdrom, the cdrom would auto-plug into pxb-cxl because +* its bus is also a root bus, triggering "Only PCI/PCIe bridges can be +* plugged into pxb-cxl". Attach the ISO explicitly to a scsi controller +* on pcie.0 instead, following the same pattern as +* test_acpi_aarch64_virt_tcg_pxb(). +*/ + params =g_strdup_printf ("-cpu rva22s64" +" -machine cxl=on" +" -device pcie-root-port,chassis=1,id=pci.1,bus=pcie.0" + " -device virtio-scsi-pci,id=scsi0,bus=pci.1"
tests/qtest/bios-tables-test.c static void test_acpi_riscv64_virt_tcg(void) · line 2254
Quoted 10 lines
tests/qtest/bios-tables-test.c +10
-0+" -drive file=tests/data/uefi-boot-images/" +"bios-tables-test.riscv64.iso.qcow2," +"if=none,media=cdrom,id=drive-scsi0-0-0-1,readonly=on" +" -device scsi-cd,bus=scsi0.0,scsi-id=0," +"drive=drive-scsi0-0-0-1,id=scsi0-0-0-1,bootindex=1" +" -object memory-backend-file,id=cxl-mem1,mem-path=%s,size=256M" +" -object memory-backend-file,id=lsa1,mem-path=%s,size=256M" +" -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1" +" -device cxl-rp,port=0,bus=cxl.1,id=rp1,chassis=0,slot=2" +" -device cxl-type3,bus=rp1,persistent-memdev=cxl-mem1,lsa=lsa1"
Only thing maybe to consider adding is the serial number given the problems we've had with that in the past and that persistent mem is basically unuseable without one (it ends up as part of the stuff stored in LSA).
I am a bit curious if you actually care enough about persistent for that to be better to test than volatile, but doesn't really matter wrt to what is being tested in practice which is the arch integration.
Quoted 26 lines
tests/qtest/bios-tables-test.c +16
-0+" -M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G," +"cxl-fmw.0.interleave-granularity=8k" , + tmp_path, tmp_path); +test_acpi_one (params, &data); + +g_free (params); +g_assert (g_rmdir (tmp_path) ==0 ); +g_free (tmp_path); +free_test_data (&data); +} +#endif /* CONFIG_POSIX */ +static void test_acpi_aarch64_virt_tcg (void ) {test_data data = {@@ -2971,6 +3021,10 @@ int main(int argc, char *argv[]) test_acpi_riscv64_virt_tcg_numamem);qtest_add_func ("acpi/virt/acpispcr" , test_acpi_riscv64_virt_tcg_acpi_spcr); +#ifdef CONFIG_POSIX +qtest_add_func ("acpi/virt/cxl" , + test_acpi_riscv64_virt_tcg_cxl); +#endif } }else if (strcmp (arch,"loongarch64" ) ==0 ) {if (has_tcg &&qtest_has_machine ("virt" )) {
PATCH v6 6/6 tests/qtest: Update RISC-V CXL ACPI golden master binaries
In reply to Chen PeiPopulate the DSDT.cxl and CEDT.cxl golden master binaries for the RISC-V CXL bios-tables test and empty bios-tables-test-allowed-diff.h, following the bios-tables-test update process.
The expected AML added by this series is:
DSDT.cxl:
Device (PC0C) // ACPI0016 CXL host bridge (pxb-cxl, bus 0x0C)
Name (_CRS, ResourceTemplate () {
DWordMemory (... 0x40400000 .. 0x405FFFFF ...) // 32-bit MMIO
QWordMemory (... 0x400100000 .. 0x40010FFFF ...) // 64-bit MMIO
WordBusNumber (... 0x000C .. 0x000D ...)
})
Method (_OSC, ...) // PCI host bridge + CXL UUIDs
Device (CXLM) // ACPI0017 CXL memory controller
Name (_HID, "ACPI0017")
Name (_DEP, Package () { \_SB.PC0C })
Method (_STA, ...) / Method (_DSM, ...)CEDT.cxl:
CHBS : CXL Host Bridge Structure, Register base 0x800000000
CFMWS: CXL Fixed Memory Window, base 0x810000000, size 4G
--- tests/data/acpi/riscv64/virt/CEDT.cxl | Bin 0 -> 108 bytes tests/data/acpi/riscv64/virt/DSDT.cxl | Bin 0 -> 6331 bytes tests/qtest/bios-tables-test-allowed-diff.h | 2 -- 3 files changed, 2 deletions(-)
tests/data/acpi/riscv64/virt/CEDT.cxl binary +0 -0
tests/data/acpi/riscv64/virt/DSDT.cxl binary +0 -0
tests/qtest/bios-tables-test-allowed-diff.h +0 -2
@@ -1,3 +1 @@/* List of comma-separated changed AML files to ignore */ -"riscv64/virt/DSDT.cxl" , -"riscv64/virt/CEDT.cxl",
Signature · 1 line
2.50.1
Re: [PATCH v6 6/6] tests/qtest: Update RISC-V CXL ACPI golden master binaries
Quoted 20 lines · On Mon, 7 Sep 2026 17:37:33 +0800 Chen Pei <[email protected]> wrote:
Populate the DSDT.cxl and CEDT.cxl golden master binaries for the RISC-V CXL bios-tables test and empty
bios-tables-test-allowed-diff.h, following the bios-tables-test update process.The expected AML added by this series is:
DSDT.cxl:
Device (PC0C) // ACPI0016 CXL host bridge (pxb-cxl, bus0x0C)Name (_CRS, ResourceTemplate () { DWordMemory (... 0x40400000 .. 0x405FFFFF ...) // 32-bit MMIO QWordMemory (... 0x400100000 .. 0x40010FFFF ...) // 64-bit MMIO WordBusNumber (... 0x000C .. 0x000D ...) }) Method (_OSC, ...) // PCI host bridge + CXL UUIDs Device (CXLM) // ACPI0017 CXL memory controller Name (_HID, "ACPI0017") Name (_DEP, Package () { \_SB.PC0C }) Method (_STA, ...) / Method (_DSM, ...)
Quoted 7 lines
CEDT.cxl:
CHBS : CXL Host Bridge Structure, Register base0x800000000
CFMWS: CXL Fixed Memory Window, base0x810000000, size 4GReviewed-by Junjie Cao <[email protected]>Tested-by Junjie Cao <[email protected]>Signed-off-by Chen Pei <[email protected]>
Hi Chen Pei,
Quoted 3 lines · Chen Pei
- Collected review tags: Junjie Cao's Reviewed-by/Tested-by on patches 1, 2 and 6. Michael S. Tsirkin acked the ACPI parts on the v5 cover letter thread.
My tags on 1-6 stand for v6, retested on master 35500e5c41 and on riscv-to-apply.next b23a62773a. Thanks for the quick turnarounds and the careful respins throughout.
Alistair, Palmer: no open points from me, and the series touches nothing under hw/cxl, so there is no dependency on the CXL tree.
Many thanks,
Junjie
Quoted 5 lines · Chen Pei
This series adds CXL support to the RISC-V virt machine, following the approach used by the ARM virt machine: CXL host bridges (pxb-cxl) are described as ACPI0016 devices, an ACPI0017 (CXLM) device is added to the DSDT with a
_DEPon the CXL host bridges, and a CEDT table is built. A bios-tables test is added to pin down the generated ACPI tables.
ACPI things:
pls merge in riscv tree.
Quoted 147 lines
Changes since v5
----------------
- Rebased onto current master, over thegpex_pcie_init()move todevice-common.c:s->pci_busis now assigned at theriscv_gpex_pcie_init()call site invirt_machine_init().
- tests/qtest: switched to the renamed in-tree firmware blobs pc-bios/edk2-riscv64-{code,vars}.fd (Junjie). The goldens are unchanged and still match with the updated edk2-stable202608 blob; all riscv64 ACPI cases pass.
- hw/riscv/virt-acpi-build: the_DEPcommit message now cites thecompanion kernel commit bf5418a5fe63 ("ACPI: scan: Honor _DEP for ACPI0016 PCI/CXL host bridge") alongside 3a59c3b772e5, both in v7.2 (Junjie).- Collected review tags: Junjie Cao's Reviewed-by/Tested-by on patches 1, 2 and 6. Michael S. Tsirkin acked the ACPI parts on the v5 cover letter thread.
Changes since v4
----------------
- tests/qtest: DSDT.cxl regenerated against the in-tree edk2-riscv-code.fd blob that the test boots (Junjie): the v4 golden carried the window allocation of my local edk2-stable202602 build. The 64-bit window is now 0x400100000..0x40010FFFF with the matching PCI0 range shift; the AML fragment in the commit message is updated accordingly. CEDT.cxl is unchanged.
- hw/riscv/virt:pci_bus_add_fw_cfg_extra_pci_roots()moved out of the cxl block (Junjie), so plain pxb-pcie expander bridges are also advertised to firmware with cxl=off, in line with arm/virt, pc and hppa.
- Collected review tags.Changes since v3
----------------
- The CXL host bridge resource handling is reworked, following Junjie Cao's suggestion (and Igor Mammedov's earlier "fix UEFI" direction):
instead of reserving a fixed 256 MiB carve-out and simulating the firmware PCI initialization in QEMU, the machine now advertises the pxb-cxl expander root buses to firmware via the etc/extra-pci-rootsfw_cfgfile (pci_bus_add_fw_cfg_extra_pci_roots(), as arm/virt and x86 do). EDK2's PciBusDxe then enumerates behind the CXL host bridge and assigns the root-port window and bus numbers, andbuild_crs()emits a correct_CRSfor the ACPI0016 host bridge. This keeps the machine code minimal (a single call, no carve-out), scales to multiple pxb-cxl host bridges, and lets firmware size the window to what is actually behind the bridge.
- The bios-tables test is split into the staged flow documented inbios-tables-test.c, and ordered the same way the riscv64 goldens were originally added upstream (Sunil V L's commitcc3ba2422554et al.):
the feature code comes first, then three consecutive commits -- empty golden files +allowed-diff.h, the test code, and the populated golden master binaries with an emptiedallowed-diff.h.Changes since v2
----------------
- hw/riscv/virt: The MMIO-window patch no longer touches the common gpex code (Igor). The gpex_cfg.cxl_mmio32 field and theis_cxlstatic_CRSbranch are dropped; the ACPI0016_CRSnow comes from the genericbuild_crs()path. Since EDK2 does not enumerate the pxb-cxl expander bridge, riscv simulates the firmware PCI initialization (reserved window + depth-first bridge bus numbers) and re-applies it via a reset handler.
- hw/riscv/virt: Drops the machine-global window/bus-range synthesis that did not scale past one pxb-cxl (Junjie). The series targets a single CXL host bridge for now, documented in the commit message and a TODO.
- hw/riscv/virt: CXL host register region and FMW setup folded into a singlecxl_host_state_init()helper; redundant braces removed increate_fdt_pcie()(Daniel).
- hw/riscv/virt-acpi-build: the_DEPcommit message documents the kernel-compatibility behaviour (Alistair).
- Carried review tags: Sunil V L's Reviewed-by on the_DEPpatch and Alistair Francis's Acked-by on the test.Changes since v1
----------------
- hw/riscv/virt: PCIBus *bus renamed to PCIBus*pci_bus(Jonathan).
- hw/riscv/virt: Dropped outer if (s->pci_bus) guard aroundcxl_hook_up_pxb_registers(); the function already handles a NULL bus internally (Jonathan).
- hw/riscv/virt-acpi-build: Alls->busreferences updated tos->pci_bus; iasl -d decompiled DSDT fragment added to commit message. - hw/riscv/virt,gpex: Commit message expanded with PCI-to-PCI Bridge Spec §3.2.5.8/9/10 citations (Jonathan).- Original patch 4 ("Map committed HDM decoder ranges as RAM for direct DMA") dropped; superseded by Alireza Sanaee's v8 series [1], which is now merged upstream and thus no longer a prerequisite.
- New patch 4: RISC-V ACPI bios-tables test for CXL, with golden AML files generated and included.[1] https://lore.kernel.org/qemu-devel/[email protected]/
Test
----
Built riscv64-softmmu and ran the new bios-tables test together with the existing riscv64 ACPI tests; all pass.Also booted an RVA22 guest with EDK2 firmware, using pxb-cxl + cxl-rp + cxl-type3 + a CFMW: EDK2's PciBusDxe enumerates behind the CXL host bridge (advertised via etc/extra-pci-roots), the root port and Type3 device show up (0000:0c:00.0 / 0000:0d:00.0), and 'cxl list' reports the memdev (4 GiB) and the CFMWS root decoder.
QEMU invocation (CXL-relevant options shown):
qemu-system-riscv64 \ -M virt,aia=aplic-imsic,acpi=on,cxl=on \ -cpu rva22s64 -smp 2 -m 4G \ -object memory-backend-ram,id=vmem0,share=on,size=4G \ -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1 \ -device cxl-rp,port=0,bus=cxl.1,id=rp0,chassis=0,slot=2 \ -device cxl-type3,bus=rp0,volatile-memdev=vmem0 \ -M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G \ ...Verification (total system memory grows by 4 GiB after onlining):
# cxl list # cxl enable-memdev mem0 # cxl create-region -m -t ram -d decoder0.0 -w 1 mem0 -s 4G # daxctl online-memory dax0.0 # free -hChen Pei (6):
hw/riscv/virt: Add CXL support to the RISC-V virt machine hw/riscv/virt-acpi-build: Add_DEPto ACPI0017 for CXL host bridge
dependency
hw/riscv/virt: Advertise the CXL host bridge to firmware via
extra-pci-roots
tests/qtest: Prepare golden files for the RISC-V CXL ACPI test tests/qtest: Add RISC-V ACPI bios tables test for CXL tests/qtest: Update RISC-V CXL ACPI golden master binarieshw/riscv/Kconfig | 2 + hw/riscv/virt-acpi-build.c | 52 +++++++++++++++++++++++++ hw/riscv/virt.c | 56 +++++++++++++++++++++++++++++++--- include/hw/riscv/virt.h | 3 ++ tests/data/acpi/riscv64/virt/CEDT.cxl | Bin 0 -> 108 bytes tests/data/acpi/riscv64/virt/DSDT.cxl | Bin 0 -> 6331 bytes tests/qtest/bios-tables-test.c | 54 ++++++++++++++++++++++++++ 7 files changed, 163 insertions(+), 4 deletions(-) create mode 100644 tests/data/acpi/riscv64/virt/CEDT.cxl create mode 100644 tests/data/acpi/riscv64/virt/DSDT.cxlSignature · 1 line
2.50.1