From fcfe3daf6619a2cce46ae6c2406c092f5a365e06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=9D=BF?= Date: Tue, 26 May 2026 14:39:38 +0800 Subject: [PATCH 01/17] Add RISC-V support and IRQ handling improvements - Implemented IRQ handling for RISC-V architecture, including local IRQ registration and handling. - Introduced a virtual IRQ injector for hypervisor support. - Enhanced the IRQ interface to accommodate RISC-V specific requirements. - Added PLIC (Platform-Level Interrupt Controller) support for RISC-V, including initialization and IRQ management. - Updated the build system to support RISC-V targets and dynamic platform features. - Modified various configuration files to enable RISC-V features and ensure compatibility with existing systems. - Improved QEMU configuration for RISC-V to handle dynamic root filesystem patches. --- Cargo.lock | 27 ++ components/axcpu/src/exception_table.rs | 24 +- components/axcpu/src/riscv/macros.rs | 10 +- .../page_table_entry/src/arch/riscv.rs | 7 +- components/riscv_vcpu/src/mem_extable.S | 6 +- components/someboot/Cargo.toml | 1 + components/someboot/build.rs | 1 - components/someboot/src/arch/riscv64/entry.rs | 6 +- components/someboot/src/arch/riscv64/link.ld | 2 +- components/someboot/src/arch/riscv64/mod.rs | 58 +++- components/someboot/src/arch/riscv64/trap.rs | 8 +- components/someboot/src/fdt/earlycon.rs | 2 +- drivers/ax-driver/Cargo.toml | 1 + drivers/ax-driver/src/block/cvsd.rs | 34 ++ drivers/ax-driver/src/lib.rs | 2 + drivers/ax-driver/src/serial/mod.rs | 4 +- drivers/ax-driver/src/soc/mod.rs | 2 + drivers/ax-driver/src/soc/sg2002.rs | 62 ++++ drivers/rdrive/src/probe/fdt/mod.rs | 16 + .../configs/board/licheerv-nano-sg2002.toml | 7 +- os/StarryOS/configs/board/qemu-riscv64.toml | 9 +- os/StarryOS/kernel/src/file/mod.rs | 2 +- os/StarryOS/kernel/src/pseudofs/dev/mod.rs | 20 +- os/StarryOS/kernel/src/pseudofs/sysfs.rs | 6 +- os/StarryOS/kernel/src/syscall/mm/mmap.rs | 2 +- os/StarryOS/starryos/Cargo.toml | 7 + os/StarryOS/starryos/src/main.rs | 1 + .../modules/axconfig/src/driver_dyn_config.rs | 58 +++- os/axvisor/Cargo.toml | 6 +- .../configs/board/qemu-riscv64-dyn.toml | 15 + os/axvisor/configs/board/qemu-riscv64.toml | 1 + os/axvisor/src/hal/arch/riscv64/api.rs | 4 + os/axvisor/src/hal/arch/riscv64/mod.rs | 7 +- platform/axplat-dyn/Cargo.toml | 1 + platform/axplat-dyn/src/irq.rs | 159 ++++++++- platform/axplat-dyn/src/lib.rs | 3 +- platform/somehal/Cargo.toml | 6 + platform/somehal/src/arch/riscv64/mod.rs | 24 +- platform/somehal/src/arch/riscv64/plic.rs | 304 ++++++++++++++++++ platform/somehal/src/common.rs | 9 + platform/somehal/src/irq.rs | 8 + scripts/axbuild/src/arceos/build.rs | 5 + scripts/axbuild/src/build.rs | 13 +- scripts/axbuild/src/starry/build.rs | 109 +++++-- scripts/axbuild/src/starry/rootfs.rs | 111 ++++++- .../pie/riscv64gc-unknown-none-elf.json | 36 +++ .../build-riscv64gc-unknown-none-elf.toml | 9 +- .../build-riscv64gc-unknown-none-elf.toml | 9 +- .../build-riscv64gc-unknown-none-elf.toml | 9 +- .../build-riscv64gc-unknown-none-elf.toml | 9 +- .../build-riscv64gc-unknown-none-elf.toml | 9 +- 51 files changed, 1117 insertions(+), 134 deletions(-) create mode 100644 drivers/ax-driver/src/soc/sg2002.rs create mode 100644 os/axvisor/configs/board/qemu-riscv64-dyn.toml create mode 100644 platform/somehal/src/arch/riscv64/plic.rs create mode 100644 scripts/targets/pie/riscv64gc-unknown-none-elf.json diff --git a/Cargo.lock b/Cargo.lock index 28751eaa9f..e4d0263248 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6789,6 +6789,19 @@ dependencies = [ "riscv-pac", ] +[[package]] +name = "riscv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05cfa3f7b30c84536a9025150d44d26b8e1cc20ddf436448d74cd9591eefb25" +dependencies = [ + "critical-section", + "embedded-hal", + "paste", + "riscv-macros 0.3.0", + "riscv-pac", +] + [[package]] name = "riscv" version = "0.16.0" @@ -6830,6 +6843,17 @@ dependencies = [ "syn 2.0.117", ] +[[package]] +name = "riscv-macros" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d323d13972c1b104aa036bc692cd08b822c8bbf23d79a27c526095856499799" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + [[package]] name = "riscv-macros" version = "0.4.0" @@ -7770,12 +7794,15 @@ dependencies = [ "aarch64-cpu 11.2.0", "anyhow", "arm-gic-driver", + "ax-riscv-plic", "kernutil", "log", "mmio-api", "page-table-generic", "rdif-intc", "rdrive", + "riscv 0.15.0", + "sbi-rt 0.0.3", "someboot", "somehal-macros", "spin", diff --git a/components/axcpu/src/exception_table.rs b/components/axcpu/src/exception_table.rs index cfa5bbe81f..aa475cc2d7 100644 --- a/components/axcpu/src/exception_table.rs +++ b/components/axcpu/src/exception_table.rs @@ -3,13 +3,13 @@ use crate::TrapFrame; #[repr(C)] #[derive(Debug, PartialEq, Eq)] struct ExceptionTableEntry { - #[cfg(target_arch = "aarch64")] + #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))] from: i32, - #[cfg(target_arch = "aarch64")] + #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))] to: i32, - #[cfg(not(target_arch = "aarch64"))] + #[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))] from: usize, - #[cfg(not(target_arch = "aarch64"))] + #[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))] to: usize, } @@ -22,7 +22,13 @@ impl ExceptionTableEntry { (base + self.from as isize) as usize } - #[cfg(not(target_arch = "aarch64"))] + #[cfg(target_arch = "riscv64")] + { + let base = unsafe { _ex_table_start.as_ptr() } as isize; + (base + self.from as isize) as usize + } + + #[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))] { self.from } @@ -36,7 +42,13 @@ impl ExceptionTableEntry { (base + self.to as isize) as usize } - #[cfg(not(target_arch = "aarch64"))] + #[cfg(target_arch = "riscv64")] + { + let base = unsafe { _ex_table_start.as_ptr() } as isize; + (base + self.to as isize) as usize + } + + #[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))] { self.to } diff --git a/components/axcpu/src/riscv/macros.rs b/components/axcpu/src/riscv/macros.rs index cd1cb822f9..35d75bedda 100644 --- a/components/axcpu/src/riscv/macros.rs +++ b/components/axcpu/src/riscv/macros.rs @@ -15,8 +15,8 @@ macro_rules! __asm_macros { .macro _asm_extable, from, to .pushsection __ex_table, "a" .balign 4 - .word \from - .word \to + .word \from - _ex_table_start + .word \to - _ex_table_start .popsection .endm @@ -40,9 +40,9 @@ macro_rules! __asm_macros { .macro _asm_extable, from, to .pushsection __ex_table, "a" - .balign 8 - .quad \from - .quad \to + .balign 4 + .word \from - _ex_table_start + .word \to - _ex_table_start .popsection .endm diff --git a/components/page_table_multiarch/page_table_entry/src/arch/riscv.rs b/components/page_table_multiarch/page_table_entry/src/arch/riscv.rs index 7e43a0fe63..6eed06635c 100644 --- a/components/page_table_multiarch/page_table_entry/src/arch/riscv.rs +++ b/components/page_table_multiarch/page_table_entry/src/arch/riscv.rs @@ -118,16 +118,13 @@ impl Rv64PTE { #[cfg(feature = "xuantie-c9xx")] { // CPU T-Head XUANTIE-C9xx extended flags: - // Memory: Shareable, Bufferable, Cacheable, Non-strong-order - // Device: Shareable, Non-bufferable, Non-cacheable, Strong-order if mflags.contains(MappingFlags::DEVICE) { self.0 |= (PTEFlags::SH | PTEFlags::SO).bits() as u64; + } else if mflags.contains(MappingFlags::UNCACHED) { + self.0 |= (PTEFlags::SH | PTEFlags::B).bits() as u64; } else { self.0 |= (PTEFlags::SH | PTEFlags::B | PTEFlags::C).bits() as u64; } - if mflags.contains(MappingFlags::UNCACHED) { - self.0 &= !((PTEFlags::B | PTEFlags::C).bits() as u64); - } } self.0 |= (extended_flags & !Self::PHYS_ADDR_MASK); PTEFlags::from_bits_truncate(self.0 as usize) diff --git a/components/riscv_vcpu/src/mem_extable.S b/components/riscv_vcpu/src/mem_extable.S index 2033de9573..de5d4bbff1 100644 --- a/components/riscv_vcpu/src/mem_extable.S +++ b/components/riscv_vcpu/src/mem_extable.S @@ -7,9 +7,9 @@ // Adds the faulting instruction and fixup target to the exception table. .macro add_extable from, to .pushsection __ex_table, "a" -.balign 8 -.quad \from -.quad \to +.balign 4 +.word \from - _ex_table_start +.word \to - _ex_table_start .popsection .endm .option push diff --git a/components/someboot/Cargo.toml b/components/someboot/Cargo.toml index 524c03d0b6..883c64c31d 100644 --- a/components/someboot/Cargo.toml +++ b/components/someboot/Cargo.toml @@ -14,6 +14,7 @@ efi = [] hv = [] mmu = [] percpu-prealloc = [] +thead-mae = [] uspace = ["mmu"] [dependencies] diff --git a/components/someboot/build.rs b/components/someboot/build.rs index 754c099381..2e421ec416 100644 --- a/components/someboot/build.rs +++ b/components/someboot/build.rs @@ -40,7 +40,6 @@ fn main() { } else if build.uspace { println!("cargo:rustc-cfg=uspace"); } - if build.page_size == 4096 { println!("cargo:rustc-cfg=page_size_4k"); } else if build.page_size == 16384 { diff --git a/components/someboot/src/arch/riscv64/entry.rs b/components/someboot/src/arch/riscv64/entry.rs index 2fc518788d..da988f33c7 100644 --- a/components/someboot/src/arch/riscv64/entry.rs +++ b/components/someboot/src/arch/riscv64/entry.rs @@ -50,7 +50,8 @@ pub unsafe extern "C" fn kernel_entry(_hart_id: usize, _fdt_addr: usize) -> ! { "mv t0, a1", "lla sp, __cpu0_stack_top", "mv a0, t0", - "j {primary_head_entry}", + "lla t1, {primary_head_entry}", + "jr t1", primary_head_entry = sym primary_head_entry, ) } @@ -98,7 +99,8 @@ pub(crate) unsafe extern "C" fn _secondary_entry(_hartid: usize, _cpu_meta_paddr "mv t0, a1", "ld sp, {stack_top_offset}(t0)", "mv a0, t0", - "j {secondary_start}", + "lla t1, {secondary_start}", + "jr t1", secondary_start = sym secondary_start, stack_top_offset = const offset_of!(PerCpuMeta, stack_top), ) diff --git a/components/someboot/src/arch/riscv64/link.ld b/components/someboot/src/arch/riscv64/link.ld index 27148429ae..fb11e5bf6e 100644 --- a/components/someboot/src/arch/riscv64/link.ld +++ b/components/someboot/src/arch/riscv64/link.ld @@ -1,5 +1,5 @@ PROVIDE(PAGE_SIZE = 0x1000); -PROVIDE(STACK_SIZE = 0x4000); +PROVIDE(STACK_SIZE = 0x40000); VM_LOAD_ADDRESS = ${kernel_load_vaddr}; OUTPUT_ARCH(riscv) diff --git a/components/someboot/src/arch/riscv64/mod.rs b/components/someboot/src/arch/riscv64/mod.rs index d96cbf685a..91fad21b65 100644 --- a/components/someboot/src/arch/riscv64/mod.rs +++ b/components/someboot/src/arch/riscv64/mod.rs @@ -13,7 +13,7 @@ mod trap; use core::sync::atomic::{AtomicUsize, Ordering}; pub(crate) use entry::_secondary_entry; -use page_table_generic::{PageTableEntry, PhysAddr, PteConfig, TableMeta, VirtAddr}; +use page_table_generic::{MemAttributes, PageTableEntry, PhysAddr, PteConfig, TableMeta, VirtAddr}; pub use relocate::apply as relocate; use crate::{ @@ -37,10 +37,59 @@ const PTE_U: usize = 1 << 4; const PTE_G: usize = 1 << 5; const PTE_A: usize = 1 << 6; const PTE_D: usize = 1 << 7; +const PTE_PPN_MASK: usize = (1 << 44) - 1; + +#[cfg(feature = "thead-mae")] +const PTE_THEAD_SEC: usize = 1 << 59; +#[cfg(feature = "thead-mae")] +const PTE_THEAD_SH: usize = 1 << 60; +#[cfg(feature = "thead-mae")] +const PTE_THEAD_B: usize = 1 << 61; +#[cfg(feature = "thead-mae")] +const PTE_THEAD_C: usize = 1 << 62; +#[cfg(feature = "thead-mae")] +const PTE_THEAD_SO: usize = 1 << 63; +#[cfg(feature = "thead-mae")] +const PTE_THEAD_PMA: usize = PTE_THEAD_C | PTE_THEAD_B | PTE_THEAD_SH; +#[cfg(feature = "thead-mae")] +const PTE_THEAD_NOCACHE: usize = PTE_THEAD_B | PTE_THEAD_SH; +#[cfg(feature = "thead-mae")] +const PTE_THEAD_IO: usize = PTE_THEAD_SO | PTE_THEAD_SH; +#[cfg(feature = "thead-mae")] +const PTE_THEAD_MT_MASK: usize = + PTE_THEAD_SEC | PTE_THEAD_SH | PTE_THEAD_B | PTE_THEAD_C | PTE_THEAD_SO; static KERNEL_PAGE_TABLE_ADDR: AtomicUsize = AtomicUsize::new(0); static TIMEBASE_FREQ: AtomicUsize = AtomicUsize::new(0); +#[cfg(feature = "thead-mae")] +fn thead_mae_pte_bits(mem_attr: MemAttributes) -> usize { + match mem_attr { + MemAttributes::Device => PTE_THEAD_IO, + MemAttributes::Uncached => PTE_THEAD_NOCACHE, + MemAttributes::Normal | MemAttributes::PerCpu => PTE_THEAD_PMA, + } +} + +#[cfg(not(feature = "thead-mae"))] +fn thead_mae_pte_bits(_mem_attr: MemAttributes) -> usize { + 0 +} + +#[cfg(feature = "thead-mae")] +fn thead_mae_mem_attr(bits: usize) -> MemAttributes { + match bits & PTE_THEAD_MT_MASK { + PTE_THEAD_IO => MemAttributes::Device, + PTE_THEAD_NOCACHE => MemAttributes::Uncached, + _ => MemAttributes::Normal, + } +} + +#[cfg(not(feature = "thead-mae"))] +fn thead_mae_mem_attr(_bits: usize) -> MemAttributes { + MemAttributes::Normal +} + #[derive(Clone, Copy, Debug, Default)] #[repr(transparent)] pub struct Entry(usize); @@ -75,9 +124,10 @@ impl PageTableEntry for Entry { if config.writable || config.dirty { bits |= PTE_D; } + bits |= thead_mae_pte_bits(config.mem_attr); } - bits |= (config.paddr.raw() >> 12) << SV39_PPN_SHIFT; + bits |= ((config.paddr.raw() >> 12) & PTE_PPN_MASK) << SV39_PPN_SHIFT; Self(bits) } @@ -91,7 +141,7 @@ impl PageTableEntry for Entry { let global = (bits & PTE_G) != 0; let dirty = (bits & PTE_D) != 0; let huge = is_dir && (read || writable || executable); - let paddr = PhysAddr::new((bits >> SV39_PPN_SHIFT) << 12); + let paddr = PhysAddr::new(((bits >> SV39_PPN_SHIFT) & PTE_PPN_MASK) << 12); PteConfig { paddr, @@ -104,7 +154,7 @@ impl PageTableEntry for Entry { global, is_dir, huge, - mem_attr: Default::default(), + mem_attr: thead_mae_mem_attr(bits), } } diff --git a/components/someboot/src/arch/riscv64/trap.rs b/components/someboot/src/arch/riscv64/trap.rs index e1fdae1d8d..4149eea46b 100644 --- a/components/someboot/src/arch/riscv64/trap.rs +++ b/components/someboot/src/arch/riscv64/trap.rs @@ -3,7 +3,6 @@ use core::{arch::global_asm, mem::offset_of}; use crate::irq; const SCAUSE_INTERRUPT_BIT: usize = 1usize << (usize::BITS as usize - 1); -const SCAUSE_SUPERVISOR_TIMER: usize = 5; #[repr(C)] struct TrapFrame { @@ -66,11 +65,8 @@ pub fn trap_addr() -> usize { extern "C" fn __riscv64_handle_trap(tf: &mut TrapFrame) { let scause = tf.scause; if (scause & SCAUSE_INTERRUPT_BIT) != 0 { - let cause = scause & !SCAUSE_INTERRUPT_BIT; - if cause == SCAUSE_SUPERVISOR_TIMER { - irq::handle_irq(irq::systimer_irq()); - return; - } + irq::handle_irq(irq::IrqId::new(scause)); + return; } panic!( diff --git a/components/someboot/src/fdt/earlycon.rs b/components/someboot/src/fdt/earlycon.rs index a3fab04bfe..539b04a669 100644 --- a/components/someboot/src/fdt/earlycon.rs +++ b/components/someboot/src/fdt/earlycon.rs @@ -59,7 +59,7 @@ fn set_by_stdout() -> Option<()> { installed = true; break; } - "snps,dw-apb-uart" => { + "snps,dw-apb-uart" | "ns16550a" | "ns16550" => { let mut serial = ns16550::Ns16550::new_mmio(addr, clock, reg_width); serial.open(); let tx = serial.take_tx()?; diff --git a/drivers/ax-driver/Cargo.toml b/drivers/ax-driver/Cargo.toml index d3d3b8a066..20623dab46 100644 --- a/drivers/ax-driver/Cargo.toml +++ b/drivers/ax-driver/Cargo.toml @@ -47,6 +47,7 @@ rockchip-dwc-xhci = ["usb", "fdt", "rockchip-soc", "rockchip-pm"] xhci-mmio = ["usb", "fdt"] xhci-pci = ["usb", "pci"] serial = ["fdt", "dep:some-serial"] +sg2002-placeholder = ["fdt"] rtc = ["fdt", "dep:ax-arm-pl031"] rknpu = ["fdt", "rockchip-pm", "rockchip-soc", "dep:rockchip-npu"] rockchip-sdhci = [ diff --git a/drivers/ax-driver/src/block/cvsd.rs b/drivers/ax-driver/src/block/cvsd.rs index 9074b4bd18..40aaee9083 100644 --- a/drivers/ax-driver/src/block/cvsd.rs +++ b/drivers/ax-driver/src/block/cvsd.rs @@ -1,3 +1,5 @@ +#[cfg(probe = "fdt")] +use rdrive::register::FdtInfo; use rdrive::{PlatformDevice, probe::OnProbeError}; #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] use {alloc::format, sg200x_bsp::sdmmc::Sdmmc}; @@ -19,6 +21,38 @@ module_driver!( }], ); +#[cfg(probe = "fdt")] +module_driver!( + name: "FDT CVSD", + level: ProbeLevel::PostKernel, + priority: ProbePriority::DEFAULT, + probe_kinds: &[ProbeKind::Fdt { + compatibles: &["cvitek,cv181x-sd"], + on_probe: probe_fdt, + }], +); + +#[cfg(probe = "fdt")] +fn probe_fdt(info: FdtInfo<'_>, plat_dev: PlatformDevice) -> Result<(), OnProbeError> { + let sdmmc = + info.node.regs().into_iter().next().ok_or_else(|| { + OnProbeError::other(alloc::format!("[{}] has no reg", info.node.name())) + })?; + let syscon = info + .find_compatible(&["syscon"]) + .into_iter() + .find_map(|node| node.regs().into_iter().next()) + .ok_or_else(|| OnProbeError::other("CVSD syscon node not found in FDT"))?; + + register_mmio( + plat_dev, + sdmmc.address as usize, + sdmmc.size.unwrap_or(0x1000) as usize, + syscon.address as usize, + syscon.size.unwrap_or(0x1000) as usize, + ) +} + #[cfg(probe = "static")] fn probe_static( info: rdrive::probe::static_::StaticInfo, diff --git a/drivers/ax-driver/src/lib.rs b/drivers/ax-driver/src/lib.rs index e568b03d22..d1aadd8765 100644 --- a/drivers/ax-driver/src/lib.rs +++ b/drivers/ax-driver/src/lib.rs @@ -20,6 +20,7 @@ pub mod error; all(feature = "rtc", feature = "fdt"), all(feature = "rockchip-soc", feature = "fdt"), all(feature = "rockchip-pm", feature = "fdt"), + all(feature = "sg2002-placeholder", feature = "fdt"), all(feature = "rockchip-dwmmc", feature = "fdt"), all(feature = "rockchip-sdhci", feature = "fdt"), all(feature = "phytium-mci", feature = "fdt"), @@ -51,6 +52,7 @@ pub mod serial; #[cfg(any( feature = "rockchip-soc", feature = "rockchip-pm", + feature = "sg2002-placeholder", feature = "rockchip-dwmmc" ))] pub mod soc; diff --git a/drivers/ax-driver/src/serial/mod.rs b/drivers/ax-driver/src/serial/mod.rs index 69a8a839b9..9262d2d69d 100644 --- a/drivers/ax-driver/src/serial/mod.rs +++ b/drivers/ax-driver/src/serial/mod.rs @@ -7,7 +7,7 @@ module_driver!( level: ProbeLevel::PreKernel, priority: ProbePriority::DEFAULT, probe_kinds: &[ProbeKind::Fdt { - compatibles: &["arm,pl011", "snps,dw-apb-uart"], + compatibles: &["arm,pl011", "snps,dw-apb-uart", "ns16550a", "ns16550"], on_probe: probe }], ); @@ -32,7 +32,7 @@ fn probe(info: FdtInfo<'_>, plat_dev: PlatformDevice) -> Result<(), OnProbeError break; } - if compatible == "snps,dw-apb-uart" { + if matches!(compatible, "snps,dw-apb-uart" | "ns16550a" | "ns16550") { serial = Some(ns16550::Ns16550::new_mmio_boxed( mmio_base, clock_freq, reg_width, )); diff --git a/drivers/ax-driver/src/soc/mod.rs b/drivers/ax-driver/src/soc/mod.rs index 050818eaf9..9724f5ccab 100644 --- a/drivers/ax-driver/src/soc/mod.rs +++ b/drivers/ax-driver/src/soc/mod.rs @@ -16,6 +16,8 @@ mod rockchip; #[cfg(feature = "rockchip-dwmmc")] pub mod scmi; +#[cfg(feature = "sg2002-placeholder")] +mod sg2002; #[cfg(feature = "rockchip-soc")] pub use rockchip::{ diff --git a/drivers/ax-driver/src/soc/sg2002.rs b/drivers/ax-driver/src/soc/sg2002.rs new file mode 100644 index 0000000000..5acd6431e4 --- /dev/null +++ b/drivers/ax-driver/src/soc/sg2002.rs @@ -0,0 +1,62 @@ +use log::info; +use rdrive::{PlatformDevice, probe::OnProbeError, register::FdtInfo}; + +const PLACEHOLDER_COMPATIBLES: &[&str] = &[ + "cvitek,tpu", + "cvitek,cvitek-ion", + "cvitek,cvi-pwm", + "snps,dw-apb-gpio", + "cvitek,cv182x-usb", + "cvitek,cif", + "cvitek,mipi_tx", + "cvitek,sys", + "cvitek,base", + "cvitek,vi", + "cvitek,vpss", + "cvitek,ive", + "cvitek,vo", + "cvitek,fb", + "cvitek,dwa", + "cvitek,asic-vcodec", + "cvitek,asic-jpeg", + "cvitek,cvi_vc_drv", + "cvitek,rtos_cmdqu", + "cvitek,audio", + "cvitek,cv181x-thermal", +]; + +module_driver!( + name: "SG2002 placeholder", + level: ProbeLevel::PostKernel, + priority: ProbePriority::DEFAULT, + probe_kinds: &[ProbeKind::Fdt { + compatibles: &["cvitek,cv181x"], + on_probe: probe, + }], +); + +fn probe(info: FdtInfo<'_>, _plat_dev: PlatformDevice) -> Result<(), OnProbeError> { + let mut mapped = 0usize; + for node in info.find_compatible(PLACEHOLDER_COMPATIBLES) { + for reg in node.regs() { + let Some(size) = reg.size else { + continue; + }; + if size == 0 { + continue; + } + let mmio = crate::mmio::iomap(reg.address as usize, size as usize)?; + mapped += 1; + info!( + "SG2002 placeholder mapped {}: {:#x}+{:#x} -> {:#x}", + node.name(), + reg.address, + size, + mmio.as_ptr() as usize + ); + } + } + + info!("SG2002 placeholder mapped {mapped} region(s)"); + Ok(()) +} diff --git a/drivers/rdrive/src/probe/fdt/mod.rs b/drivers/rdrive/src/probe/fdt/mod.rs index 923d4b8150..8531d0f1d5 100644 --- a/drivers/rdrive/src/probe/fdt/mod.rs +++ b/drivers/rdrive/src/probe/fdt/mod.rs @@ -56,6 +56,14 @@ pub struct FdtInfo<'a> { } impl<'a> FdtInfo<'a> { + pub fn get_by_phandle(&self, phandle: Phandle) -> Option> { + system().get_by_phandle(phandle) + } + + pub fn find_compatible(&self, compatible: &[&str]) -> Vec> { + system().find_compatible(compatible) + } + pub fn phandle_to_device_id(&self, phandle: Phandle) -> Option { self.phandle_2_device_id.get(&phandle).copied() } @@ -91,6 +99,14 @@ impl System { self.phandle_2_device_id.get(&phandle).copied() } + pub fn get_by_phandle(&self, phandle: Phandle) -> Option> { + self.fdt.get_by_phandle(phandle) + } + + pub fn find_compatible(&self, compatible: &[&str]) -> Vec> { + self.fdt.find_compatible(compatible) + } + pub fn new(fdt_addr: NonNull) -> Result { let fdt = unsafe { Fdt::from_ptr(fdt_addr.as_ptr()) } .map_err(|error| DriverError::Fdt(format!("{error:?}")))?; diff --git a/os/StarryOS/configs/board/licheerv-nano-sg2002.toml b/os/StarryOS/configs/board/licheerv-nano-sg2002.toml index 2e3d5a70a8..2927a0c22b 100644 --- a/os/StarryOS/configs/board/licheerv-nano-sg2002.toml +++ b/os/StarryOS/configs/board/licheerv-nano-sg2002.toml @@ -1,9 +1,10 @@ env = { UIMAGE = "y" } features = [ - "sg2002", - "myplat", + "sg2002-dyn", + "ax-feat/plat-dyn", "ax-driver/cvsd", + "ax-driver/serial", ] log = "Info" -plat_dyn = false +plat_dyn = true target = "riscv64gc-unknown-none-elf" diff --git a/os/StarryOS/configs/board/qemu-riscv64.toml b/os/StarryOS/configs/board/qemu-riscv64.toml index 4902ae62f3..f58dbe74c1 100644 --- a/os/StarryOS/configs/board/qemu-riscv64.toml +++ b/os/StarryOS/configs/board/qemu-riscv64.toml @@ -1,8 +1,9 @@ env = {} features = [ - "ax-hal/riscv64-qemu-virt", - "qemu", - "ax-driver/pci", + "ax-feat/plat-dyn", + "starry-kernel/plat-dyn", + "ax-driver/pci-fdt", + "ax-driver/serial", "ax-driver/virtio-blk", "ax-driver/virtio-net", "ax-driver/virtio-gpu", @@ -10,5 +11,5 @@ features = [ "ax-driver/virtio-socket", ] log = "Warn" -plat_dyn = false +plat_dyn = true target = "riscv64gc-unknown-none-elf" diff --git a/os/StarryOS/kernel/src/file/mod.rs b/os/StarryOS/kernel/src/file/mod.rs index 83986bea28..a163cfa057 100644 --- a/os/StarryOS/kernel/src/file/mod.rs +++ b/os/StarryOS/kernel/src/file/mod.rs @@ -2,7 +2,7 @@ pub mod epoll; pub mod event; mod fs; pub mod inotify; -#[cfg(feature = "sg2002")] +#[cfg(all(feature = "sg2002", not(feature = "plat-dyn")))] pub mod ion; pub mod memfd; mod net; diff --git a/os/StarryOS/kernel/src/pseudofs/dev/mod.rs b/os/StarryOS/kernel/src/pseudofs/dev/mod.rs index 8c2ab6448e..b51e2f59c3 100644 --- a/os/StarryOS/kernel/src/pseudofs/dev/mod.rs +++ b/os/StarryOS/kernel/src/pseudofs/dev/mod.rs @@ -16,7 +16,7 @@ mod r#loop; mod loop_block; #[cfg(feature = "ext4")] pub use r#loop::LoopDevice; -#[cfg(feature = "sg2002")] +#[cfg(all(feature = "sg2002", not(feature = "plat-dyn")))] pub mod ion; #[cfg(feature = "memtrack")] mod memtrack; @@ -24,19 +24,19 @@ mod memtrack; mod rknpu_card; #[cfg(all(feature = "rknpu", not(any(windows, unix))))] mod rknpu_drm; -#[cfg(feature = "sg2002")] +#[cfg(all(feature = "sg2002", not(feature = "plat-dyn")))] pub mod tpu; pub mod tty; -#[cfg(feature = "sg2002")] +#[cfg(all(feature = "sg2002", not(feature = "plat-dyn")))] mod cvi_camera; -#[cfg(feature = "sg2002")] +#[cfg(all(feature = "sg2002", not(feature = "plat-dyn")))] mod cvi_usb_camera; -#[cfg(feature = "sg2002")] +#[cfg(all(feature = "sg2002", not(feature = "plat-dyn")))] mod pinmux; -#[cfg(feature = "sg2002")] +#[cfg(all(feature = "sg2002", not(feature = "plat-dyn")))] pub(super) mod pwm; -#[cfg(feature = "sg2002")] +#[cfg(all(feature = "sg2002", not(feature = "plat-dyn")))] mod tty_serial; use alloc::{format, sync::Arc}; @@ -45,10 +45,10 @@ use core::any::Any; use ax_errno::AxError; use ax_sync::Mutex; use axfs_ng_vfs::{DeviceId, Filesystem, NodeFlags, NodeType, VfsResult}; -#[cfg(feature = "sg2002")] +#[cfg(all(feature = "sg2002", not(feature = "plat-dyn")))] use spin::Once; -#[cfg(feature = "sg2002")] +#[cfg(all(feature = "sg2002", not(feature = "plat-dyn")))] pub static ION_DEVICE: Once> = Once::new(); #[cfg(feature = "dev-log")] pub use log::bind_dev_log; @@ -394,7 +394,7 @@ fn builder(fs: Arc) -> DirMaker { SimpleDir::new_maker(fs.clone(), Arc::new(event::input_devices(fs.clone()))), ); - #[cfg(feature = "sg2002")] + #[cfg(all(feature = "sg2002", not(feature = "plat-dyn")))] { root.add( "cvi-tpu0", diff --git a/os/StarryOS/kernel/src/pseudofs/sysfs.rs b/os/StarryOS/kernel/src/pseudofs/sysfs.rs index b22a5c38d9..ed0033b261 100644 --- a/os/StarryOS/kernel/src/pseudofs/sysfs.rs +++ b/os/StarryOS/kernel/src/pseudofs/sysfs.rs @@ -186,9 +186,9 @@ struct ClassDir { impl SimpleDirOps for ClassDir { fn child_names<'a>(&'a self) -> Box> + 'a> { - #[cfg(feature = "sg2002")] + #[cfg(all(feature = "sg2002", not(feature = "plat-dyn")))] let names: &'static [&'static str] = &["drm", "graphics", "input", "pwm"]; - #[cfg(not(feature = "sg2002"))] + #[cfg(any(not(feature = "sg2002"), feature = "plat-dyn"))] let names: &'static [&'static str] = &["drm", "graphics", "input"]; Box::new(names.iter().copied().map(Cow::Borrowed)) } @@ -205,7 +205,7 @@ impl SimpleDirOps for ClassDir { Arc::new(ClassSubsystemDir::new(fs, "graphics", &["fb0"])), ), "input" => SimpleDir::new_maker(fs.clone(), Arc::new(InputClassDir { fs })), - #[cfg(feature = "sg2002")] + #[cfg(all(feature = "sg2002", not(feature = "plat-dyn")))] "pwm" => crate::pseudofs::dev::pwm::pwm_class_dir_maker(fs), _ => return Err(VfsError::NotFound), })) diff --git a/os/StarryOS/kernel/src/syscall/mm/mmap.rs b/os/StarryOS/kernel/src/syscall/mm/mmap.rs index 976447b064..98b6b1c587 100644 --- a/os/StarryOS/kernel/src/syscall/mm/mmap.rs +++ b/os/StarryOS/kernel/src/syscall/mm/mmap.rs @@ -241,7 +241,7 @@ pub fn sys_mmap( // IonBufferFile 特殊处理:直接线性映射物理地址,跳过通用 file_mmap/device_mmap 路径。 // 这样可以避免通用路径中 `range.start += offset` 对 Ion buffer 的错误偏移。 - #[cfg(feature = "sg2002")] + #[cfg(all(feature = "sg2002", not(feature = "plat-dyn")))] if let Some(ref file) = file { use crate::file::ion::IonBufferFile; if let Some(ion_file) = file.downcast_ref::() { diff --git a/os/StarryOS/starryos/Cargo.toml b/os/StarryOS/starryos/Cargo.toml index 1171a16c9f..0f1d3a25e3 100644 --- a/os/StarryOS/starryos/Cargo.toml +++ b/os/StarryOS/starryos/Cargo.toml @@ -31,6 +31,13 @@ sg2002 = [ "dep:ax-plat-riscv64-sg2002", "starry-kernel/sg2002", ] +sg2002-dyn = [ + "dep:axplat-dyn", + "axplat-dyn/thead-mae", + "starry-kernel/sg2002", + "starry-kernel/plat-dyn", + "ax-driver/sg2002-placeholder", +] # Enable the GICv3 distributor + redistributor + system-register # CPU interface on aarch64. Only meaningful when the target is the diff --git a/os/StarryOS/starryos/src/main.rs b/os/StarryOS/starryos/src/main.rs index 531d66c44c..352f42feff 100644 --- a/os/StarryOS/starryos/src/main.rs +++ b/os/StarryOS/starryos/src/main.rs @@ -22,6 +22,7 @@ fn main() { #[cfg(all( feature = "sg2002", + not(feature = "sg2002-dyn"), any(target_arch = "riscv32", target_arch = "riscv64") ))] extern crate ax_plat_riscv64_sg2002; diff --git a/os/arceos/modules/axconfig/src/driver_dyn_config.rs b/os/arceos/modules/axconfig/src/driver_dyn_config.rs index 3cc8bab13a..c97818c528 100644 --- a/os/arceos/modules/axconfig/src/driver_dyn_config.rs +++ b/os/arceos/modules/axconfig/src/driver_dyn_config.rs @@ -1,9 +1,49 @@ +#[cfg(target_arch = "aarch64")] +mod arch { + pub const ARCH: &str = "aarch64"; + pub const PACKAGE: &str = "axplat-aarch64-generic"; + pub const PLATFORM: &str = "aarch64-generic"; + pub const TIMER_IRQ: usize = 0xf0; + pub const IPI_IRQ: usize = 0; + pub const KERNEL_ASPACE_BASE: usize = 0xffff_8000_0000_0000; + pub const KERNEL_ASPACE_SIZE: usize = 0x0000_7fff_ffff_f000; + pub const KERNEL_BASE_PADDR: usize = 0x20_0000; + pub const KERNEL_BASE_VADDR: usize = 0xffff_8000_0020_0000; +} + +#[cfg(target_arch = "riscv64")] +mod arch { + pub const ARCH: &str = "riscv64"; + pub const PACKAGE: &str = "axplat-dyn"; + pub const PLATFORM: &str = "riscv64-plat-dyn"; + const INTERRUPT_FLAG: usize = 1usize << (usize::BITS as usize - 1); + pub const TIMER_IRQ: usize = INTERRUPT_FLAG | 5; + pub const IPI_IRQ: usize = INTERRUPT_FLAG | 1; + pub const KERNEL_ASPACE_BASE: usize = 0xffff_ffc0_0000_0000; + pub const KERNEL_ASPACE_SIZE: usize = 0x0000_003f_ffff_f000; + pub const KERNEL_BASE_PADDR: usize = 0x8020_0000; + pub const KERNEL_BASE_VADDR: usize = 0xffff_ffff_8000_0000; +} + +#[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))] +mod arch { + pub const ARCH: &str = "aarch64"; + pub const PACKAGE: &str = "axplat-aarch64-generic"; + pub const PLATFORM: &str = "aarch64-generic"; + pub const TIMER_IRQ: usize = 0xf0; + pub const IPI_IRQ: usize = 0; + pub const KERNEL_ASPACE_BASE: usize = 0xffff_8000_0000_0000; + pub const KERNEL_ASPACE_SIZE: usize = 0x0000_7fff_ffff_f000; + pub const KERNEL_BASE_PADDR: usize = 0x20_0000; + pub const KERNEL_BASE_VADDR: usize = 0xffff_8000_0020_0000; +} + #[doc = " Architecture identifier."] -pub const ARCH: &str = "aarch64"; +pub const ARCH: &str = arch::ARCH; #[doc = " Platform package."] -pub const PACKAGE: &str = "axplat-aarch64-generic"; +pub const PACKAGE: &str = arch::PACKAGE; #[doc = " Platform identifier."] -pub const PLATFORM: &str = "aarch64-generic"; +pub const PLATFORM: &str = arch::PLATFORM; #[doc = " Stack size of each task."] pub const TASK_STACK_SIZE: usize = 0x40000; #[doc = " Number of timer ticks per second (Hz). A timer tick may contain several timer"] @@ -28,9 +68,9 @@ pub mod devices { #[doc = " PCI device memory ranges."] pub const PCI_RANGES: &[(usize, usize)] = &[]; #[doc = " Timer interrupt num (PPI, physical timer)."] - pub const TIMER_IRQ: usize = 0xf0; + pub const TIMER_IRQ: usize = super::arch::TIMER_IRQ; #[doc = " IPI interrupt num."] - pub const IPI_IRQ: usize = 0; + pub const IPI_IRQ: usize = super::arch::IPI_IRQ; #[doc = " VirtIO MMIO regions with format (`base_paddr`, `size`)."] pub const VIRTIO_MMIO_REGIONS: &[(usize, usize)] = &[]; #[doc = " SDMMC controller physical address."] @@ -54,13 +94,13 @@ pub mod plat { #[doc = " Platform family (deprecated)."] pub const FAMILY: &str = ""; #[doc = " Kernel address space base."] - pub const KERNEL_ASPACE_BASE: usize = 0xffff_8000_0000_0000; + pub const KERNEL_ASPACE_BASE: usize = super::arch::KERNEL_ASPACE_BASE; #[doc = " Kernel address space size."] - pub const KERNEL_ASPACE_SIZE: usize = 0x0000_7fff_ffff_f000; + pub const KERNEL_ASPACE_SIZE: usize = super::arch::KERNEL_ASPACE_SIZE; #[doc = " No need."] - pub const KERNEL_BASE_PADDR: usize = 0x20_0000; + pub const KERNEL_BASE_PADDR: usize = super::arch::KERNEL_BASE_PADDR; #[doc = " Base virtual address of the kernel image."] - pub const KERNEL_BASE_VADDR: usize = 0xffff_8000_0020_0000; + pub const KERNEL_BASE_VADDR: usize = super::arch::KERNEL_BASE_VADDR; #[doc = " Offset of bus address and phys address. some boards, the bus address is"] #[doc = " different from the physical address."] pub const PHYS_BUS_OFFSET: usize = 0; diff --git a/os/axvisor/Cargo.toml b/os/axvisor/Cargo.toml index aeb1ab5756..383e093835 100644 --- a/os/axvisor/Cargo.toml +++ b/os/axvisor/Cargo.toml @@ -40,6 +40,10 @@ vmx = ["axvm/vmx"] svm = ["axvm/svm"] sstc = ["riscv_vcpu/sstc"] dyn-plat = ["ax-std/plat-dyn", "dep:axplat-dyn"] +riscv64-qemu-virt-hv = [ + "dep:ax-plat-riscv64-qemu-virt", + "ax-plat-riscv64-qemu-virt/hypervisor", +] rockchip-soc = ["ax-driver/rockchip-soc"] rockchip-sdhci = ["ax-driver/rockchip-sdhci", "ax-driver/rockchip-soc"] rockchip-dwmmc = ["ax-driver/rockchip-dwmmc", "ax-driver/rockchip-soc"] @@ -105,7 +109,7 @@ arm-gic-driver = { workspace = true, features = ["rdif"] } [target.'cfg(target_arch = "loongarch64")'.dependencies] ax-plat-loongarch64-qemu-virt = { workspace = true, default-features = false, features = ["irq", "smp"] } [target.'cfg(target_arch = "riscv64")'.dependencies] -ax-plat-riscv64-qemu-virt = { workspace = true, features = ["hypervisor"] } +ax-plat-riscv64-qemu-virt = { workspace = true, optional = true } riscv_vcpu = { workspace = true } riscv_vplic = { workspace = true } # xtask dependencies (only used on host platforms) diff --git a/os/axvisor/configs/board/qemu-riscv64-dyn.toml b/os/axvisor/configs/board/qemu-riscv64-dyn.toml new file mode 100644 index 0000000000..a1c8aab23e --- /dev/null +++ b/os/axvisor/configs/board/qemu-riscv64-dyn.toml @@ -0,0 +1,15 @@ +env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } +features = [ + "dyn-plat", + "ax-hal/plat-dyn", + "ax-driver/fdt", + "ax-driver/virtio-blk", + "ept-level-4", + "fs", + "sstc" +] +log = "Info" +plat_dyn = true +target = "riscv64gc-unknown-none-elf" +vm_configs = [] +max_cpu_num = 4 diff --git a/os/axvisor/configs/board/qemu-riscv64.toml b/os/axvisor/configs/board/qemu-riscv64.toml index da0062ef6c..a525ba5228 100644 --- a/os/axvisor/configs/board/qemu-riscv64.toml +++ b/os/axvisor/configs/board/qemu-riscv64.toml @@ -1,5 +1,6 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ + "riscv64-qemu-virt-hv", "ax-hal/riscv64-qemu-virt-hv", "ax-driver/fdt", "ax-driver/virtio-blk", diff --git a/os/axvisor/src/hal/arch/riscv64/api.rs b/os/axvisor/src/hal/arch/riscv64/api.rs index 93241c1d35..9876da4d2c 100644 --- a/os/axvisor/src/hal/arch/riscv64/api.rs +++ b/os/axvisor/src/hal/arch/riscv64/api.rs @@ -1,4 +1,8 @@ pub(super) fn init_platform_irq_injector() { + #[cfg(feature = "dyn-plat")] + axplat_dyn::register_virtual_irq_injector(crate::hal::arch::inject_interrupt); + + #[cfg(not(feature = "dyn-plat"))] ax_plat_riscv64_qemu_virt::irq::register_virtual_irq_injector( crate::hal::arch::inject_interrupt, ); diff --git a/os/axvisor/src/hal/arch/riscv64/mod.rs b/os/axvisor/src/hal/arch/riscv64/mod.rs index 75b0987487..71dd44c6a0 100644 --- a/os/axvisor/src/hal/arch/riscv64/mod.rs +++ b/os/axvisor/src/hal/arch/riscv64/mod.rs @@ -2,10 +2,11 @@ mod api; pub mod cache; use crate::vmm::vm_list::get_vm_by_id; -use ax_plat_riscv64_qemu_virt::config::devices::PLIC_PADDR; use axaddrspace::{GuestPhysAddr, device::AccessWidth}; use axvisor_api::vmm::current_vm_id; +const GUEST_PLIC_PADDR: usize = 0x0c00_0000; + pub fn hardware_check() { api::init_platform_irq_injector(); // TODO: implement hardware checks for RISC-V64 @@ -19,12 +20,12 @@ pub fn inject_interrupt(irq_id: usize) { let vplic = get_vm_by_id(current_vm_id()) .unwrap() .get_devices() - .find_mmio_dev(GuestPhysAddr::from_usize(PLIC_PADDR)) + .find_mmio_dev(GuestPhysAddr::from_usize(GUEST_PLIC_PADDR)) .unwrap(); // Calulate the pending register offset and value. let reg_offset = riscv_vplic::PLIC_PENDING_OFFSET + (irq_id / 32) * 4; - let addr = GuestPhysAddr::from_usize(PLIC_PADDR + reg_offset); + let addr = GuestPhysAddr::from_usize(GUEST_PLIC_PADDR + reg_offset); let width = AccessWidth::Dword; let val: u32 = 1 << (irq_id % 32); diff --git a/platform/axplat-dyn/Cargo.toml b/platform/axplat-dyn/Cargo.toml index 78f20be7e8..6c233a85d0 100644 --- a/platform/axplat-dyn/Cargo.toml +++ b/platform/axplat-dyn/Cargo.toml @@ -17,6 +17,7 @@ rtc = [] fp-simd = ["ax-cpu/fp-simd"] uspace = ["somehal/uspace"] hv = ["somehal/hv", "ax-cpu/arm-el2"] +thead-mae = ["somehal/thead-mae", "ax-cpu/xuantie-c9xx"] [dependencies] anyhow = { version = "1", default-features = false } diff --git a/platform/axplat-dyn/src/irq.rs b/platform/axplat-dyn/src/irq.rs index c3371cf9c8..64569ce535 100644 --- a/platform/axplat-dyn/src/irq.rs +++ b/platform/axplat-dyn/src/irq.rs @@ -1,12 +1,37 @@ +use core::sync::atomic::{AtomicPtr, Ordering}; + use ax_plat::irq::{HandlerTable, IrqHandler, IrqIf}; use somehal::irq_handler; /// The maximum number of IRQs. const MAX_IRQ_COUNT: usize = 1024; +#[cfg(target_arch = "aarch64")] const GIC_SPECIAL_IRQ_START: usize = 1020; +#[cfg(target_arch = "riscv64")] +const INTC_IRQ_BASE: usize = 1usize << (usize::BITS as usize - 1); +#[cfg(target_arch = "riscv64")] +const S_SOFT: usize = INTC_IRQ_BASE | 1; +#[cfg(target_arch = "riscv64")] +const S_TIMER: usize = INTC_IRQ_BASE | 5; +#[cfg(target_arch = "riscv64")] +const S_EXT: usize = INTC_IRQ_BASE | 9; + static IRQ_HANDLER_TABLE: HandlerTable = HandlerTable::new(); +#[cfg(target_arch = "riscv64")] +static TIMER_HANDLER: AtomicPtr<()> = AtomicPtr::new(core::ptr::null_mut()); +#[cfg(target_arch = "riscv64")] +static IPI_HANDLER: AtomicPtr<()> = AtomicPtr::new(core::ptr::null_mut()); + +#[cfg(all(target_arch = "riscv64", feature = "hv"))] +static VIRTUAL_IRQ_INJECTOR: AtomicPtr<()> = AtomicPtr::new(core::ptr::null_mut()); + +#[cfg(all(target_arch = "riscv64", feature = "hv"))] +pub fn register_virtual_irq_injector(injector: fn(usize)) { + VIRTUAL_IRQ_INJECTOR.store(injector as *mut (), Ordering::Release); +} + struct IrqIfImpl; #[impl_plat_interface] @@ -23,6 +48,18 @@ impl IrqIf for IrqIfImpl { fn register(irq_num: usize, handler: IrqHandler) -> bool { debug!("register handler IRQ {}", irq_num); + #[cfg(target_arch = "riscv64")] + { + if register_local_irq(irq_num, handler) { + Self::set_enable(irq_num, true); + return true; + } + if is_riscv_local_irq(irq_num) { + warn!("register handler for local IRQ {} failed", irq_num); + return false; + } + } + if IRQ_HANDLER_TABLE.register_handler(irq_num, handler) { Self::set_enable(irq_num, true); return true; @@ -38,6 +75,15 @@ impl IrqIf for IrqIfImpl { fn unregister(irq_num: usize) -> Option { trace!("unregister handler IRQ {}", irq_num); Self::set_enable(irq_num, false); + #[cfg(target_arch = "riscv64")] + { + if let Some(handler) = unregister_local_irq(irq_num) { + return Some(handler); + } + if is_riscv_local_irq(irq_num) { + return None; + } + } IRQ_HANDLER_TABLE.unregister_handler(irq_num) } @@ -46,23 +92,126 @@ impl IrqIf for IrqIfImpl { /// It is called by the common interrupt handler. It should look up in the /// IRQ handler table and calls the corresponding handler. If necessary, it /// also acknowledges the interrupt controller after handling. - fn handle(_irq_num: usize) -> Option { - let irq = somehal::irq::irq_handler_raw(); + fn handle(irq_num: usize) -> Option { + let irq = somehal::irq::irq_handler_with_raw(irq_num)?; Some(irq.raw()) } - fn send_ipi(_id: usize, _target: ax_plat::irq::IpiTarget) { - todo!() + fn send_ipi(_id: usize, target: ax_plat::irq::IpiTarget) { + match target { + ax_plat::irq::IpiTarget::Current { cpu_id } + | ax_plat::irq::IpiTarget::Other { cpu_id } => { + somehal::irq::send_ipi_to_cpu(cpu_id); + } + ax_plat::irq::IpiTarget::AllExceptCurrent { cpu_id, cpu_num } => { + for target_cpu in 0..cpu_num { + if target_cpu != cpu_id { + somehal::irq::send_ipi_to_cpu(target_cpu); + } + } + } + } } } #[irq_handler] fn somehal_handle_irq(irq: somehal::irq::IrqId) { + #[cfg(target_arch = "aarch64")] if irq.raw() >= GIC_SPECIAL_IRQ_START { trace!("Ignoring special IRQ {irq:?}"); return; } - if !IRQ_HANDLER_TABLE.handle(irq.raw()) { + + #[cfg(target_arch = "riscv64")] + if handle_riscv_local_irq(irq.raw()) { + return; + } + + #[cfg(all(target_arch = "riscv64", feature = "hv"))] + if inject_virtual_irq(irq.raw()) { + return; + } + + if irq.raw() < MAX_IRQ_COUNT && IRQ_HANDLER_TABLE.handle(irq.raw()) { + return; + } + + if irq.raw() >= MAX_IRQ_COUNT { + warn!("IRQ {irq:?} is outside handler table"); + } else { warn!("Unhandled IRQ {irq:?}"); } } + +#[cfg(target_arch = "riscv64")] +fn is_riscv_local_irq(irq: usize) -> bool { + matches!(irq, S_TIMER | S_SOFT | S_EXT) || irq & INTC_IRQ_BASE != 0 +} + +#[cfg(target_arch = "riscv64")] +fn register_local_irq(irq: usize, handler: IrqHandler) -> bool { + let slot = match irq { + S_TIMER => &TIMER_HANDLER, + S_SOFT => &IPI_HANDLER, + S_EXT => return false, + _ => return false, + }; + slot.compare_exchange( + core::ptr::null_mut(), + handler as *mut (), + Ordering::AcqRel, + Ordering::Acquire, + ) + .is_ok() +} + +#[cfg(target_arch = "riscv64")] +fn unregister_local_irq(irq: usize) -> Option { + let slot = match irq { + S_TIMER => &TIMER_HANDLER, + S_SOFT => &IPI_HANDLER, + _ => return None, + }; + let handler = slot.swap(core::ptr::null_mut(), Ordering::AcqRel); + if handler.is_null() { + None + } else { + Some(unsafe { core::mem::transmute::<*mut (), IrqHandler>(handler) }) + } +} + +#[cfg(target_arch = "riscv64")] +fn handle_riscv_local_irq(irq: usize) -> bool { + let slot = match irq { + S_TIMER => &TIMER_HANDLER, + S_SOFT => &IPI_HANDLER, + S_EXT => return false, + _ if irq & INTC_IRQ_BASE != 0 => { + warn!("Unhandled RISC-V local IRQ {irq:#x}"); + return true; + } + _ => return false, + }; + let handler = slot.load(Ordering::Acquire); + if handler.is_null() { + warn!("Unhandled RISC-V local IRQ {irq:#x}"); + return true; + } + unsafe { + core::mem::transmute::<*mut (), IrqHandler>(handler)(irq); + } + true +} + +#[cfg(all(target_arch = "riscv64", feature = "hv"))] +fn inject_virtual_irq(irq: usize) -> bool { + let injector = VIRTUAL_IRQ_INJECTOR.load(Ordering::Acquire); + if injector.is_null() { + warn!("virtual IRQ injector is not registered"); + return false; + } + unsafe { + core::mem::transmute::<*mut (), fn(usize)>(injector)(irq); + } + true +} diff --git a/platform/axplat-dyn/src/lib.rs b/platform/axplat-dyn/src/lib.rs index 8d8614d897..cabac9f71a 100644 --- a/platform/axplat-dyn/src/lib.rs +++ b/platform/axplat-dyn/src/lib.rs @@ -1,6 +1,5 @@ #![no_std] #![cfg(not(any(windows, unix)))] -#![feature(used_with_arg)] extern crate alloc; extern crate ax_driver as _; @@ -28,6 +27,8 @@ fn somehal_handle_irq(_irq: somehal::irq::IrqId) {} pub use boot::boot_stack_bounds; pub use generic_timer::try_init_epoch_offset; +#[cfg(all(feature = "irq", target_arch = "riscv64", feature = "hv"))] +pub use irq::register_virtual_irq_injector; // pub mod config { // //! Platform configuration module. diff --git a/platform/somehal/Cargo.toml b/platform/somehal/Cargo.toml index 9e473568ef..9299564a95 100644 --- a/platform/somehal/Cargo.toml +++ b/platform/somehal/Cargo.toml @@ -14,6 +14,7 @@ efi = ["someboot/efi"] hv = ["mmu", "someboot/hv"] mmu = ["someboot/mmu"] percpu-prealloc = ["someboot/percpu-prealloc"] +thead-mae = ["someboot/thead-mae"] uspace = ["mmu", "someboot/uspace"] [dependencies] @@ -34,3 +35,8 @@ spin = "0.10" [target.'cfg(target_arch = "aarch64")'.dependencies] aarch64-cpu = "11" arm-gic-driver = {workspace = true, features = ["rdif"]} + +[target.'cfg(target_arch = "riscv64")'.dependencies] +ax-riscv-plic = { workspace = true } +riscv = "0.15" +sbi-rt = { version = "0.0.3", features = ["legacy"] } diff --git a/platform/somehal/src/arch/riscv64/mod.rs b/platform/somehal/src/arch/riscv64/mod.rs index b3ff36e065..586ad646d2 100644 --- a/platform/somehal/src/arch/riscv64/mod.rs +++ b/platform/somehal/src/arch/riscv64/mod.rs @@ -1,27 +1,35 @@ use crate::common::PlatOp; +mod plic; + pub struct Plat; impl PlatOp for Plat { fn irq_set_enable(irq: rdrive::IrqId, enable: bool) { - let raw: usize = irq.into(); - let irq = someboot::irq::IrqId::new(raw); - if irq == someboot::irq::systimer_irq() { - someboot::irq::irq_set_enable(irq, enable); - } + plic::irq_set_enable(irq, enable); } fn irq_handler() -> someboot::irq::IrqId { - someboot::irq::systimer_irq() + someboot::irq::IrqId::new(plic::systick_irq().raw()) + } + + fn irq_handler_with_raw(raw: usize) -> Option { + plic::irq_handler_with_raw(raw) } fn systick_irq() -> rdrive::IrqId { - someboot::irq::systimer_irq().raw().into() + plic::systick_irq() } fn secondary_init() {} - fn secondary_init_intc() {} + fn secondary_init_intc() { + plic::secondary_init_intc(); + } fn secondary_init_systick() {} + + fn send_ipi_to_cpu(cpu_id: usize) { + plic::send_ipi_to_cpu(cpu_id); + } } diff --git a/platform/somehal/src/arch/riscv64/plic.rs b/platform/somehal/src/arch/riscv64/plic.rs new file mode 100644 index 0000000000..06273e1ad6 --- /dev/null +++ b/platform/somehal/src/arch/riscv64/plic.rs @@ -0,0 +1,304 @@ +use alloc::{format, vec::Vec}; +use core::{num::NonZeroU32, ptr::NonNull}; + +use ax_riscv_plic::{PLICRegs, Plic}; +use kernutil::StaticCell; +use rdif_intc::Interface; +use rdrive::{ + DriverGeneric, Phandle, PlatformDevice, module_driver, + probe::{OnProbeError, fdt::NodeType}, + register::FdtInfo, +}; +use riscv::register::{sie, sip}; +use sbi_rt::HartMask; +use spin::Mutex; + +use crate::{common::ioremap, irq::_handle_irq}; + +const INTC_IRQ_BASE: usize = 1usize << (usize::BITS as usize - 1); +const S_SOFT: usize = INTC_IRQ_BASE | 1; +const S_TIMER: usize = INTC_IRQ_BASE | 5; +const S_EXT: usize = INTC_IRQ_BASE | 9; +const SUPERVISOR_EXTERNAL_INTERRUPT: u32 = 9; +const DEFAULT_PRIORITY: u32 = 1; +const DEFAULT_PLIC_SIZE: usize = 0x400_0000; + +static PLIC: StaticCell> = StaticCell::uninit(); + +module_driver!( + name: "RISC-V PLIC", + level: ProbeLevel::PreKernel, + priority: ProbePriority::INTC, + probe_kinds: &[ProbeKind::Fdt { + compatibles: &[ + "riscv,plic0", + "sifive,plic-1.0.0", + "starfive,jh7110-plic", + ], + on_probe: probe_plic + }], +); + +pub fn systick_irq() -> rdrive::IrqId { + S_TIMER.into() +} + +pub fn irq_set_enable(irq: rdrive::IrqId, enable: bool) { + let raw: usize = irq.into(); + match raw { + S_TIMER => unsafe { + if enable { + sie::set_stimer(); + } else { + sie::clear_stimer(); + } + }, + S_SOFT => unsafe { + if enable { + sie::set_ssoft(); + } else { + sie::clear_ssoft(); + } + }, + S_EXT => unsafe { + if enable { + sie::set_sext(); + } else { + sie::clear_sext(); + } + }, + external if external & INTC_IRQ_BASE == 0 => set_external_irq_enable(external, enable), + other => warn!("unsupported RISC-V local IRQ {other:#x}"), + } +} + +pub fn irq_handler_with_raw(raw: usize) -> Option { + match raw { + S_TIMER => { + _handle_irq(S_TIMER.into()); + Some(S_TIMER.into()) + } + S_SOFT => { + unsafe { + sip::clear_ssoft(); + } + _handle_irq(S_SOFT.into()); + Some(S_SOFT.into()) + } + S_EXT => handle_external_irq(), + external if external & INTC_IRQ_BASE == 0 => { + _handle_irq(external.into()); + Some(external.into()) + } + other => { + warn!("unsupported RISC-V interrupt cause {other:#x}"); + None + } + } +} + +pub fn secondary_init_intc() { + enable_local_interrupts(); + if PLIC.is_init() { + unsafe { + PLIC.update(|plic| plic.lock().init_current_context()); + } + } +} + +pub fn send_ipi_to_cpu(cpu_id: usize) { + let Some(hart_id) = someboot::smp::cpu_idx_to_id(cpu_id) else { + warn!("failed to resolve hart id for logical CPU {cpu_id}"); + return; + }; + let res = sbi_rt::send_ipi(HartMask::from_mask_base(1, hart_id)); + if !res.is_ok() { + warn!("send_ipi to hart {hart_id} failed: {res:?}"); + } +} + +fn probe_plic(info: FdtInfo<'_>, dev: PlatformDevice) -> Result<(), OnProbeError> { + let reg = info + .node + .regs() + .into_iter() + .next() + .ok_or_else(|| OnProbeError::other(format!("[{}] has no reg", info.node.name())))?; + let mmio = ioremap( + reg.address, + reg.size.unwrap_or(DEFAULT_PLIC_SIZE as u64) as usize, + ) + .map_err(|err| OnProbeError::other(format!("failed to map PLIC: {err:?}")))?; + let plic = unsafe { + Plic::new( + NonNull::new(mmio.as_ptr() as *mut PLICRegs) + .ok_or_else(|| OnProbeError::other("PLIC MMIO mapping is null"))?, + ) + }; + let ndev = info + .node + .as_node() + .get_property("riscv,ndev") + .and_then(|prop| prop.get_u32()) + .unwrap_or(1024) as usize; + let contexts = parse_supervisor_contexts(&info); + + let mut plic = RiscvPlic { + inner: plic, + context_by_cpu: contexts, + sources: ndev, + }; + plic.init_current_context(); + PLIC.init(Mutex::new(plic)); + enable_local_interrupts(); + + dev.register(rdif_intc::Intc::new(RiscvPlicIntc)); + Ok(()) +} + +fn parse_supervisor_contexts(info: &FdtInfo<'_>) -> Vec> { + let mut contexts = Vec::new(); + let Some(prop) = info.node.as_node().get_property("interrupts-extended") else { + return contexts; + }; + + let mut reader = prop.as_reader(); + let mut context = 0; + while let (Some(phandle), Some(interrupt)) = (reader.read_u32(), reader.read_u32()) { + if interrupt == SUPERVISOR_EXTERNAL_INTERRUPT + && let Some(cpu_idx) = cpu_idx_from_intc_phandle(info, Phandle::from(phandle)) + { + if contexts.len() <= cpu_idx { + contexts.resize(cpu_idx + 1, None); + } + contexts[cpu_idx] = Some(context); + } + context += 1; + } + contexts +} + +fn cpu_idx_from_intc_phandle(info: &FdtInfo<'_>, phandle: Phandle) -> Option { + let intc = info.get_by_phandle(phandle)?; + if let Some(cpu_idx) = intc.parent().and_then(|cpu| cpu_idx_from_cpu_node(&cpu)) { + return Some(cpu_idx); + } + let cpu = info.get_by_phandle(intc.as_node().interrupt_parent()?)?; + cpu_idx_from_cpu_node(&cpu) +} + +fn cpu_idx_from_cpu_node(cpu: &NodeType<'_>) -> Option { + let hart_id = cpu.regs().first()?.address as usize; + someboot::smp::cpu_id_to_idx(hart_id) +} + +fn enable_local_interrupts() { + unsafe { + sie::set_ssoft(); + sie::set_stimer(); + sie::set_sext(); + } +} + +fn set_external_irq_enable(irq: usize, enable: bool) { + if !PLIC.is_init() { + warn!("PLIC is not initialized when setting IRQ {irq}"); + return; + } + let Some(source) = NonZeroU32::new(irq as u32) else { + return; + }; + unsafe { + PLIC.update(|plic| { + let mut plic = plic.lock(); + if enable { + plic.enable_source(source); + } else { + plic.disable_source(source); + } + }); + } +} + +fn handle_external_irq() -> Option { + if !PLIC.is_init() { + warn!("PLIC is not initialized for external IRQ"); + return None; + } + unsafe { PLIC.update(|plic| plic.lock().handle_external_irq()) } +} + +struct RiscvPlic { + inner: Plic, + context_by_cpu: Vec>, + sources: usize, +} + +impl RiscvPlic { + fn current_context(&self) -> Option { + let cpu_idx = someboot::smp::cpu_idx(); + self.context_by_cpu.get(cpu_idx).and_then(|ctx| *ctx) + } + + fn init_current_context(&mut self) { + if let Some(context) = self.current_context() { + self.inner.init_by_context(context); + trace!("PLIC context {context} initialized"); + } else { + warn!( + "PLIC supervisor context for logical CPU {} is not found", + someboot::smp::cpu_idx() + ); + } + } + + fn enable_source(&mut self, source: NonZeroU32) { + if source.get() as usize > self.sources { + warn!("skip enabling out-of-range PLIC source {}", source.get()); + return; + } + self.inner.set_priority(source, DEFAULT_PRIORITY); + let current = self.current_context(); + for context in self.context_by_cpu.iter().filter_map(|context| *context) { + self.inner.enable(source, context); + } + if current.is_none() { + warn!( + "PLIC supervisor context for logical CPU {} is not found", + someboot::smp::cpu_idx() + ); + } + } + + fn disable_source(&mut self, source: NonZeroU32) { + for context in self.context_by_cpu.iter().filter_map(|context| *context) { + self.inner.disable(source, context); + } + } + + fn handle_external_irq(&mut self) -> Option { + let context = self.current_context()?; + let Some(source) = self.inner.claim(context) else { + debug!("Spurious external IRQ"); + return None; + }; + let irq = someboot::irq::IrqId::new(source.get() as usize); + _handle_irq(irq.raw().into()); + self.inner.complete(context, source); + Some(irq) + } +} + +struct RiscvPlicIntc; + +impl DriverGeneric for RiscvPlicIntc { + fn name(&self) -> &str { + "RISC-V PLIC" + } +} + +impl Interface for RiscvPlicIntc { + fn setup_irq_by_fdt(&mut self, irq_prop: &[u32]) -> rdrive::IrqId { + (irq_prop.first().copied().unwrap_or(0) as usize).into() + } +} diff --git a/platform/somehal/src/common.rs b/platform/somehal/src/common.rs index 6fe98b084a..f185bc0620 100644 --- a/platform/somehal/src/common.rs +++ b/platform/somehal/src/common.rs @@ -8,6 +8,11 @@ pub trait PlatOp { fn irq_handler() -> someboot::irq::IrqId; + fn irq_handler_with_raw(raw: usize) -> Option { + let _ = raw; + Some(Self::irq_handler()) + } + fn systick_irq() -> IrqId; fn secondary_init(); @@ -15,6 +20,10 @@ pub trait PlatOp { fn secondary_init_intc(); fn secondary_init_systick(); + + fn send_ipi_to_cpu(cpu_id: usize) { + let _ = cpu_id; + } } #[allow(dead_code)] diff --git a/platform/somehal/src/irq.rs b/platform/somehal/src/irq.rs index f5760c638d..dffe9f3946 100644 --- a/platform/somehal/src/irq.rs +++ b/platform/somehal/src/irq.rs @@ -33,3 +33,11 @@ pub(crate) fn _handle_irq(hwirq: IrqId) { pub fn irq_handler_raw() -> IrqId { Plat::irq_handler().raw().into() } + +pub fn irq_handler_with_raw(raw: usize) -> Option { + Plat::irq_handler_with_raw(raw).map(|irq| irq.raw().into()) +} + +pub fn send_ipi_to_cpu(cpu_id: usize) { + Plat::send_ipi_to_cpu(cpu_id); +} diff --git a/scripts/axbuild/src/arceos/build.rs b/scripts/axbuild/src/arceos/build.rs index 46857f4653..d485cb59f6 100644 --- a/scripts/axbuild/src/arceos/build.rs +++ b/scripts/axbuild/src/arceos/build.rs @@ -411,6 +411,11 @@ AX_IP = "10.0.2.15" true, Some(false) )); + assert!(build::resolve_effective_plat_dyn( + "riscv64gc-unknown-none-elf", + true, + None + )); assert!(!build::resolve_effective_plat_dyn( "x86_64-unknown-none", true, diff --git a/scripts/axbuild/src/build.rs b/scripts/axbuild/src/build.rs index 58abad4fb5..dcd48221ce 100644 --- a/scripts/axbuild/src/build.rs +++ b/scripts/axbuild/src/build.rs @@ -469,7 +469,10 @@ pub(crate) fn cargo_target_json_path(target: &str, plat_dyn: bool) -> anyhow::Re }; if plat_dyn { - if target != "aarch64-unknown-none-softfloat" { + if !matches!( + target, + "aarch64-unknown-none-softfloat" | "riscv64gc-unknown-none-elf" + ) { bail!("unsupported PIE target `{target}`"); } Ok(Path::new(TARGET_JSON_ROOT) @@ -659,7 +662,7 @@ pub(crate) fn resolve_effective_plat_dyn( } fn supports_platform_dynamic(target: &str) -> bool { - target.starts_with("aarch64-") + target.starts_with("aarch64-") || target.starts_with("riscv64") } fn default_to_bin_for_target(target: &str) -> bool { @@ -1432,10 +1435,10 @@ mod tests { } #[test] - fn cargo_target_json_path_rejects_unsupported_pie_target() { - let err = cargo_target_json_path("riscv64gc-unknown-none-elf", true).unwrap_err(); + fn cargo_target_json_path_maps_riscv64_pie_target() { + let path = cargo_target_json_path("riscv64gc-unknown-none-elf", true).unwrap(); - assert!(err.to_string().contains("unsupported PIE target")); + assert!(path.ends_with("scripts/targets/pie/riscv64gc-unknown-none-elf.json")); } #[test] diff --git a/scripts/axbuild/src/starry/build.rs b/scripts/axbuild/src/starry/build.rs index f92bb3007b..4a7c48dd24 100644 --- a/scripts/axbuild/src/starry/build.rs +++ b/scripts/axbuild/src/starry/build.rs @@ -146,31 +146,51 @@ fn uimg_arch_for(arch: &str) -> String { fn inject_uimage_post_build_cmd(cargo: &mut Cargo, arch: &str) -> anyhow::Result<()> { let uimg_arch = uimg_arch_for(arch); - let config_path = cargo - .env - .get("AX_CONFIG_PATH") - .cloned() - .ok_or_else(|| anyhow::anyhow!("AX_CONFIG_PATH is required for UIMAGE generation"))?; + let paddr = uimage_load_paddr_expr(cargo, arch)?; let cmd = format!( - "paddr=$(ax-config-gen {config_path} -r plat.kernel-base-paddr | tr -d _) && \ - bin=${{KERNEL_ELF%.elf}}.bin && mkimage -A {uimg_arch} -O linux -T kernel -C none -a \ - \"$paddr\" -d \"$bin\" \"${{bin%.bin}}.uimg\"" + "paddr={paddr} && bin=${{KERNEL_ELF%.elf}}.bin && mkimage -A {uimg_arch} -O linux -T \ + kernel -C none -a \"$paddr\" -d \"$bin\" \"${{bin%.bin}}.uimg\"" ); cargo.post_build_cmds.push(cmd); Ok(()) } +fn uimage_load_paddr_expr(cargo: &Cargo, arch: &str) -> anyhow::Result { + if let Some(config_path) = cargo.env.get("AX_CONFIG_PATH") { + return Ok(format!( + "$(ax-config-gen {config_path} -r plat.kernel-base-paddr | tr -d _)" + )); + } + + if !uses_dynamic_platform(&cargo.features) { + return Err(anyhow::anyhow!( + "AX_CONFIG_PATH is required for UIMAGE generation" + )); + } + + match arch { + "aarch64" => Ok("0x200000".to_string()), + "riscv64" => Ok("0x80200000".to_string()), + other => Err(anyhow::anyhow!( + "AX_CONFIG_PATH is required for UIMAGE generation on {other}" + )), + } +} + fn remove_qemu_feature_for_dynamic_platform(cargo: &mut Cargo) { - let uses_dynamic_platform = cargo.features.iter().any(|feature| { + if uses_dynamic_platform(&cargo.features) { + cargo.features.retain(|feature| feature != "qemu"); + } +} + +fn uses_dynamic_platform(features: &[String]) -> bool { + features.iter().any(|feature| { matches!( feature.as_str(), "plat-dyn" | "ax-feat/plat-dyn" | "ax-std/plat-dyn" | "ax-hal/plat-dyn" ) - }); - if uses_dynamic_platform { - cargo.features.retain(|feature| feature != "qemu"); - } + }) } fn uses_static_default_platform(features: &[String]) -> bool { @@ -182,12 +202,7 @@ fn uses_static_default_platform(features: &[String]) -> bool { }) || features.iter().any(|feature| { feature.starts_with("ax-hal/") && feature != "ax-hal/plat-dyn" && feature != "ax-hal/myplat" }); - let has_dynamic = features.iter().any(|feature| { - matches!( - feature.as_str(), - "plat-dyn" | "ax-feat/plat-dyn" | "ax-std/plat-dyn" | "ax-hal/plat-dyn" - ) - }); + let has_dynamic = uses_dynamic_platform(features); let has_custom = features.iter().any(|feature| { matches!( feature.as_str(), @@ -558,6 +573,62 @@ HELLO = "world" assert!(!cargo.env.contains_key("AX_PLATFORM")); } + #[test] + fn uimage_load_paddr_uses_dynamic_riscv64_fallback_without_axconfig() { + let cargo = Cargo { + env: HashMap::new(), + target: "scripts/targets/pie/riscv64gc-unknown-none-elf.json".to_string(), + package: STARRY_PACKAGE.to_string(), + bin: None, + features: vec!["ax-feat/plat-dyn".to_string()], + log: None, + extra_config: None, + profile: None, + disable_someboot_build_config: true, + args: Vec::new(), + pre_build_cmds: Vec::new(), + post_build_cmds: Vec::new(), + to_bin: true, + }; + + assert_eq!( + uimage_load_paddr_expr(&cargo, "riscv64").unwrap(), + "0x80200000" + ); + } + + #[test] + fn uimage_load_paddr_prefers_axconfig_when_available() { + let mut cargo = Cargo { + env: HashMap::from([( + "AX_CONFIG_PATH".to_string(), + "/tmp/generated.axconfig.toml".to_string(), + )]), + target: "riscv64gc-unknown-none-elf".to_string(), + package: STARRY_PACKAGE.to_string(), + bin: None, + features: vec!["ax-feat/plat-dyn".to_string()], + log: None, + extra_config: None, + profile: None, + disable_someboot_build_config: true, + args: Vec::new(), + pre_build_cmds: Vec::new(), + post_build_cmds: Vec::new(), + to_bin: true, + }; + + assert_eq!( + uimage_load_paddr_expr(&cargo, "riscv64").unwrap(), + "$(ax-config-gen /tmp/generated.axconfig.toml -r plat.kernel-base-paddr | tr -d _)" + ); + + inject_uimage_post_build_cmd(&mut cargo, "riscv64").unwrap(); + assert!( + cargo.post_build_cmds[0].contains("paddr=$(ax-config-gen /tmp/generated.axconfig.toml") + ); + } + #[test] fn resolve_build_info_path_supports_starry_subworkspace_root() { let root = tempdir().unwrap(); diff --git a/scripts/axbuild/src/starry/rootfs.rs b/scripts/axbuild/src/starry/rootfs.rs index abfe3e0602..58b3cc8d88 100644 --- a/scripts/axbuild/src/starry/rootfs.rs +++ b/scripts/axbuild/src/starry/rootfs.rs @@ -107,10 +107,11 @@ pub(super) async fn load_patched_qemu_config( } }; + let mode = rootfs_patch_mode(request, cargo); if let Some(rootfs) = explicit_rootfs { - patch_qemu_rootfs_path(&mut qemu, rootfs); + patch_qemu_rootfs_path_with_mode(&mut qemu, rootfs, mode); } else if apply_default_args { - patch_qemu_rootfs(&mut qemu, request, starry.app.workspace_root(), None)?; + patch_qemu_rootfs(&mut qemu, request, starry.app.workspace_root(), None, mode)?; } qemu_test::apply_smp_qemu_arg(&mut qemu, request.smp); @@ -241,6 +242,7 @@ pub(crate) fn patch_qemu_rootfs( request: &ResolvedStarryRequest, workspace_root: &Path, explicit_rootfs: Option<&Path>, + mode: RootfsPatchMode, ) -> anyhow::Result<()> { let expected_target = starry_target_for_arch_checked(&request.arch)?; if request.target != expected_target { @@ -251,7 +253,7 @@ pub(crate) fn patch_qemu_rootfs( ); } let rootfs_path = qemu_rootfs_path(request, workspace_root, explicit_rootfs)?; - patch_qemu_rootfs_path(qemu, &rootfs_path); + patch_qemu_rootfs_path_with_mode(qemu, &rootfs_path, mode); Ok(()) } @@ -269,8 +271,27 @@ pub(crate) fn qemu_rootfs_path( } /// Patches a QEMU config with a concrete Starry rootfs path. -pub(crate) fn patch_qemu_rootfs_path(qemu: &mut QemuConfig, rootfs_path: &Path) { - patch_rootfs(qemu, rootfs_path, RootfsPatchMode::EnsureDiskBootNet); +pub(crate) fn patch_qemu_rootfs_path_with_mode( + qemu: &mut QemuConfig, + rootfs_path: &Path, + mode: RootfsPatchMode, +) { + patch_rootfs(qemu, rootfs_path, mode); +} + +fn rootfs_patch_mode(request: &ResolvedStarryRequest, cargo: &Cargo) -> RootfsPatchMode { + if request.plat_dyn == Some(true) + || cargo.features.iter().any(|feature| { + matches!( + feature.as_str(), + "ax-feat/plat-dyn" | "ax-std/plat-dyn" | "starry-kernel/plat-dyn" + ) + }) + { + RootfsPatchMode::ReplaceDriveOnly + } else { + RootfsPatchMode::EnsureDiskBootNet + } } #[cfg(test)] @@ -306,7 +327,14 @@ mod tests { }; let mut qemu = QemuConfig::default(); - patch_qemu_rootfs(&mut qemu, &request, root.path(), None).unwrap(); + patch_qemu_rootfs( + &mut qemu, + &request, + root.path(), + None, + RootfsPatchMode::EnsureDiskBootNet, + ) + .unwrap(); assert_eq!( qemu.args, @@ -367,7 +395,14 @@ mod tests { ..Default::default() }; - patch_qemu_rootfs(&mut qemu, &request, root.path(), None).unwrap(); + patch_qemu_rootfs( + &mut qemu, + &request, + root.path(), + None, + RootfsPatchMode::EnsureDiskBootNet, + ) + .unwrap(); assert_eq!( qemu.args, @@ -393,4 +428,66 @@ mod tests { ] ); } + + #[tokio::test] + async fn patch_qemu_rootfs_for_dynamic_platform_replaces_drive_only() { + let root = tempdir().unwrap(); + let rootfs_dir = root.path().join("tmp/axbuild/rootfs"); + fs::create_dir_all(&rootfs_dir).unwrap(); + fs::write( + rootfs_dir.join("rootfs-riscv64-alpine.img"), + vec![0; 1024 * 1024], + ) + .unwrap(); + + let request = ResolvedStarryRequest { + package: "starryos".to_string(), + arch: "riscv64".to_string(), + target: "riscv64gc-unknown-none-elf".to_string(), + plat_dyn: Some(true), + smp: None, + debug: false, + build_info_path: PathBuf::from("/tmp/.build.toml"), + build_info_override: None, + qemu_config: None, + uboot_config: None, + }; + let mut qemu = QemuConfig { + args: vec![ + "-machine".to_string(), + "virt".to_string(), + "-device".to_string(), + "virtio-blk-device,drive=disk0".to_string(), + "-drive".to_string(), + "id=disk0,if=none,format=raw,file=/old/rootfs.img".to_string(), + ], + ..Default::default() + }; + + patch_qemu_rootfs( + &mut qemu, + &request, + root.path(), + None, + RootfsPatchMode::ReplaceDriveOnly, + ) + .unwrap(); + + assert_eq!( + qemu.args, + vec![ + "-machine".to_string(), + "virt".to_string(), + "-device".to_string(), + "virtio-blk-device,drive=disk0".to_string(), + "-drive".to_string(), + format!( + "id=disk0,if=none,format=raw,file={}", + root.path() + .join("tmp/axbuild/rootfs/rootfs-riscv64-alpine.img") + .display() + ), + ] + ); + } } diff --git a/scripts/targets/pie/riscv64gc-unknown-none-elf.json b/scripts/targets/pie/riscv64gc-unknown-none-elf.json new file mode 100644 index 0000000000..1e18d1b92a --- /dev/null +++ b/scripts/targets/pie/riscv64gc-unknown-none-elf.json @@ -0,0 +1,36 @@ +{ + "arch": "riscv64", + "cpu": "generic-rv64", + "crt-objects-fallback": "false", + "data-layout": "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128", + "eh-frame-header": false, + "emit-debug-gdb-scripts": false, + "features": "+m,+a,+f,+d,+c,+zicsr,+zifencei", + "linker": "rust-lld", + "linker-flavor": "gnu-lld", + "llvm-abiname": "lp64d", + "llvm-target": "riscv64", + "max-atomic-width": 64, + "metadata": { + "description": "Bare RISC-V (RV64IMAFDC ISA)", + "host_tools": false, + "std": false, + "tier": 2 + }, + "panic-strategy": "abort", + "position-independent-executables": true, + "pre-link-args": { + "gnu-lld": [ + "-pie", + "-znostart-stop-gc", + "-Taxplat.x" + ] + }, + "relocation-model": "pic", + "static-position-independent-executables": true, + "supported-sanitizers": [ + "shadow-call-stack", + "kernel-address" + ], + "target-pointer-width": 64 +} diff --git a/test-suit/starryos/normal/board-licheerv-nano-sg2002/build-riscv64gc-unknown-none-elf.toml b/test-suit/starryos/normal/board-licheerv-nano-sg2002/build-riscv64gc-unknown-none-elf.toml index 8bcd941406..0151ef9647 100644 --- a/test-suit/starryos/normal/board-licheerv-nano-sg2002/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/starryos/normal/board-licheerv-nano-sg2002/build-riscv64gc-unknown-none-elf.toml @@ -1,7 +1,12 @@ # Build-time config template for StarryOS on SG2002. target = "riscv64gc-unknown-none-elf" env = {} -features = ["sg2002", "myplat", "ax-driver/cvsd"] +features = [ + "sg2002-dyn", + "ax-feat/plat-dyn", + "ax-driver/cvsd", + "ax-driver/serial", +] log = "Info" max_cpu_num = 1 -plat_dyn = false +plat_dyn = true diff --git a/test-suit/starryos/normal/qemu-smp1/build-riscv64gc-unknown-none-elf.toml b/test-suit/starryos/normal/qemu-smp1/build-riscv64gc-unknown-none-elf.toml index 2df21769c5..a6eaa912c6 100644 --- a/test-suit/starryos/normal/qemu-smp1/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/starryos/normal/qemu-smp1/build-riscv64gc-unknown-none-elf.toml @@ -1,8 +1,9 @@ env = {AX_IP = "10.0.2.15", AX_GW = "10.0.2.2"} features = [ - "ax-hal/riscv64-qemu-virt", - "qemu", - "ax-driver/pci", + "ax-feat/plat-dyn", + "starry-kernel/plat-dyn", + "ax-driver/pci-fdt", + "ax-driver/serial", "ax-driver/virtio-blk", "ax-driver/virtio-net", "ax-driver/virtio-gpu", @@ -10,5 +11,5 @@ features = [ "ax-driver/virtio-socket", ] log = "Warn" -plat_dyn = false +plat_dyn = true target = "riscv64gc-unknown-none-elf" diff --git a/test-suit/starryos/normal/qemu-smp4/build-riscv64gc-unknown-none-elf.toml b/test-suit/starryos/normal/qemu-smp4/build-riscv64gc-unknown-none-elf.toml index f9e4ff6cb8..bf52f3db69 100644 --- a/test-suit/starryos/normal/qemu-smp4/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/starryos/normal/qemu-smp4/build-riscv64gc-unknown-none-elf.toml @@ -1,8 +1,9 @@ env = {AX_IP = "10.0.2.15", AX_GW = "10.0.2.2"} features = [ - "ax-hal/riscv64-qemu-virt", - "qemu", - "ax-driver/pci", + "ax-feat/plat-dyn", + "starry-kernel/plat-dyn", + "ax-driver/pci-fdt", + "ax-driver/serial", "ax-driver/virtio-blk", "ax-driver/virtio-net", "ax-driver/virtio-gpu", @@ -11,5 +12,5 @@ features = [ ] max_cpu_num = 4 log = "Warn" -plat_dyn = false +plat_dyn = true target = "riscv64gc-unknown-none-elf" diff --git a/test-suit/starryos/stress/postgresql/build-riscv64gc-unknown-none-elf.toml b/test-suit/starryos/stress/postgresql/build-riscv64gc-unknown-none-elf.toml index 2df21769c5..a6eaa912c6 100644 --- a/test-suit/starryos/stress/postgresql/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/starryos/stress/postgresql/build-riscv64gc-unknown-none-elf.toml @@ -1,8 +1,9 @@ env = {AX_IP = "10.0.2.15", AX_GW = "10.0.2.2"} features = [ - "ax-hal/riscv64-qemu-virt", - "qemu", - "ax-driver/pci", + "ax-feat/plat-dyn", + "starry-kernel/plat-dyn", + "ax-driver/pci-fdt", + "ax-driver/serial", "ax-driver/virtio-blk", "ax-driver/virtio-net", "ax-driver/virtio-gpu", @@ -10,5 +11,5 @@ features = [ "ax-driver/virtio-socket", ] log = "Warn" -plat_dyn = false +plat_dyn = true target = "riscv64gc-unknown-none-elf" diff --git a/test-suit/starryos/stress/stress-ng-0/build-riscv64gc-unknown-none-elf.toml b/test-suit/starryos/stress/stress-ng-0/build-riscv64gc-unknown-none-elf.toml index 2df21769c5..a6eaa912c6 100644 --- a/test-suit/starryos/stress/stress-ng-0/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/starryos/stress/stress-ng-0/build-riscv64gc-unknown-none-elf.toml @@ -1,8 +1,9 @@ env = {AX_IP = "10.0.2.15", AX_GW = "10.0.2.2"} features = [ - "ax-hal/riscv64-qemu-virt", - "qemu", - "ax-driver/pci", + "ax-feat/plat-dyn", + "starry-kernel/plat-dyn", + "ax-driver/pci-fdt", + "ax-driver/serial", "ax-driver/virtio-blk", "ax-driver/virtio-net", "ax-driver/virtio-gpu", @@ -10,5 +11,5 @@ features = [ "ax-driver/virtio-socket", ] log = "Warn" -plat_dyn = false +plat_dyn = true target = "riscv64gc-unknown-none-elf" From bda78dc762246e5224ce5e18a37c7780dbfa6f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=9D=BF?= Date: Tue, 26 May 2026 15:34:09 +0800 Subject: [PATCH 02/17] fix(axvisor): enable riscv64 qemu platform feature in CI --- .../axvisor/normal/qemu/build-riscv64gc-unknown-none-elf.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/test-suit/axvisor/normal/qemu/build-riscv64gc-unknown-none-elf.toml b/test-suit/axvisor/normal/qemu/build-riscv64gc-unknown-none-elf.toml index 4e9112e70c..a617ef0f96 100644 --- a/test-suit/axvisor/normal/qemu/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/axvisor/normal/qemu/build-riscv64gc-unknown-none-elf.toml @@ -1,5 +1,6 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ + "riscv64-qemu-virt-hv", "ax-hal/riscv64-qemu-virt-hv", "ax-driver/fdt", "ax-driver/virtio-blk", From ef54984e2f4d2b4fd3f2fd1db6e7eca4626f18e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=9D=BF?= Date: Tue, 26 May 2026 16:22:26 +0800 Subject: [PATCH 03/17] fix(axvisor): boot riscv64 dynamic hv --- components/someboot/build.rs | 2 +- .../someboot/src/arch/riscv64/addrspace.rs | 8 +-- components/someboot/src/arch/riscv64/mod.rs | 4 +- drivers/ax-driver/src/pci/fdt.rs | 66 +++++++++++++++++-- drivers/ax-driver/src/pci/mod.rs | 12 +++- os/axvisor/configs/board/qemu-riscv64.toml | 5 +- .../build-riscv64gc-unknown-none-elf.toml | 5 +- 7 files changed, 84 insertions(+), 18 deletions(-) diff --git a/components/someboot/build.rs b/components/someboot/build.rs index 2e421ec416..923cae1a8a 100644 --- a/components/someboot/build.rs +++ b/components/someboot/build.rs @@ -157,7 +157,7 @@ impl Build { fn prepare_riscv64(&mut self) { let ld_src = "src/arch/riscv64/link.ld"; - if self.uspace { + if self.uspace || self.hv { self.kernel_vaddr = 0xffff_ffff_8000_0000; } else { self.kernel_vaddr = 0x8020_0000; diff --git a/components/someboot/src/arch/riscv64/addrspace.rs b/components/someboot/src/arch/riscv64/addrspace.rs index 7f44c598a8..0614261afe 100644 --- a/components/someboot/src/arch/riscv64/addrspace.rs +++ b/components/someboot/src/arch/riscv64/addrspace.rs @@ -1,11 +1,11 @@ include!(concat!(env!("OUT_DIR"), "/defines.rs")); -#[cfg(uspace)] +#[cfg(any(uspace, hv))] pub const PAGE_OFFSET: usize = 0xffff_ffc0_0000_0000; -#[cfg(not(uspace))] +#[cfg(not(any(uspace, hv)))] pub const PAGE_OFFSET: usize = 0; -#[cfg(uspace)] +#[cfg(any(uspace, hv))] pub const PERCPU_BASE: usize = 0xffff_ffe0_0000_0000; -#[cfg(not(uspace))] +#[cfg(not(any(uspace, hv)))] pub const PERCPU_BASE: usize = PAGE_OFFSET; diff --git a/components/someboot/src/arch/riscv64/mod.rs b/components/someboot/src/arch/riscv64/mod.rs index 91fad21b65..b7e498233f 100644 --- a/components/someboot/src/arch/riscv64/mod.rs +++ b/components/someboot/src/arch/riscv64/mod.rs @@ -21,7 +21,7 @@ use crate::{ mem::{PageTableInfo, mmu}, power::CpuOnError, }; -#[cfg(uspace)] +#[cfg(any(uspace, hv))] use crate::{mem::__kimage_va_to_pa, smp::percpu_va_range}; const KERNEL_LOAD_ADDRESS: usize = 0x8020_0000; @@ -226,7 +226,7 @@ impl ArchTrait for Arch { fn virt_to_phys(vaddr: *const u8) -> usize { let vaddr = vaddr as usize; - #[cfg(uspace)] + #[cfg(any(uspace, hv))] { if mmu::is_mmu_enabled() { if percpu_va_range().contains(&vaddr) { diff --git a/drivers/ax-driver/src/pci/fdt.rs b/drivers/ax-driver/src/pci/fdt.rs index b3788fe574..194fb01709 100644 --- a/drivers/ax-driver/src/pci/fdt.rs +++ b/drivers/ax-driver/src/pci/fdt.rs @@ -1,14 +1,41 @@ extern crate alloc; use alloc::format; -#[cfg(target_os = "none")] +#[cfg(all( + target_os = "none", + any( + feature = "intel-net", + feature = "ixgbe", + feature = "realtek-rtl8125", + feature = "virtio-net", + feature = "xhci-pci", + ) +))] use alloc::vec::Vec; -#[cfg(target_os = "none")] +#[cfg(all( + target_os = "none", + any( + feature = "intel-net", + feature = "ixgbe", + feature = "realtek-rtl8125", + feature = "virtio-net", + feature = "xhci-pci", + ) +))] use fdt_edit::Fdt; use fdt_edit::{NodeType, PciRange, PciSpace}; use log::{debug, trace, warn}; -#[cfg(target_os = "none")] +#[cfg(all( + target_os = "none", + any( + feature = "intel-net", + feature = "ixgbe", + feature = "realtek-rtl8125", + feature = "virtio-net", + feature = "xhci-pci", + ) +))] use rdrive::probe::pci::PciAddress; use rdrive::{ PlatformDevice, @@ -131,7 +158,16 @@ pub(super) fn register_fdt_legacy_irq(info: &FdtInfo<'_>, logical_bus_end: u8) { super::register_legacy_irq_route(0, logical_bus_end, irq); } -#[cfg(target_os = "none")] +#[cfg(all( + target_os = "none", + any( + feature = "intel-net", + feature = "ixgbe", + feature = "realtek-rtl8125", + feature = "virtio-net", + feature = "xhci-pci", + ) +))] pub fn fdt_irq_for_endpoint( address: PciAddress, interrupt_pin: u8, @@ -144,7 +180,16 @@ pub fn fdt_irq_for_endpoint( result.map(Some) } -#[cfg(target_os = "none")] +#[cfg(all( + target_os = "none", + any( + feature = "intel-net", + feature = "ixgbe", + feature = "realtek-rtl8125", + feature = "virtio-net", + feature = "xhci-pci", + ) +))] fn resolve_pci_irq_from_fdt( fdt: &Fdt, address: PciAddress, @@ -214,7 +259,16 @@ fn resolve_pci_irq_from_fdt( }) } -#[cfg(target_os = "none")] +#[cfg(all( + target_os = "none", + any( + feature = "intel-net", + feature = "ixgbe", + feature = "realtek-rtl8125", + feature = "virtio-net", + feature = "xhci-pci", + ) +))] fn decode_irq_cells(specifier: &[u32]) -> Option { match specifier { [irq] => Some(*irq as usize), diff --git a/drivers/ax-driver/src/pci/mod.rs b/drivers/ax-driver/src/pci/mod.rs index c6d063badb..83446aaddc 100644 --- a/drivers/ax-driver/src/pci/mod.rs +++ b/drivers/ax-driver/src/pci/mod.rs @@ -31,7 +31,17 @@ use crate::virtio::VirtIoHalImpl; #[cfg(feature = "pci-fdt")] mod fdt; -#[cfg(all(feature = "pci-fdt", target_os = "none"))] +#[cfg(all( + feature = "pci-fdt", + target_os = "none", + any( + feature = "intel-net", + feature = "ixgbe", + feature = "realtek-rtl8125", + feature = "virtio-net", + feature = "xhci-pci", + ) +))] pub(crate) use fdt::fdt_irq_for_endpoint; const MAX_PCIE_LEGACY_IRQS: usize = 8; diff --git a/os/axvisor/configs/board/qemu-riscv64.toml b/os/axvisor/configs/board/qemu-riscv64.toml index a525ba5228..a1c8aab23e 100644 --- a/os/axvisor/configs/board/qemu-riscv64.toml +++ b/os/axvisor/configs/board/qemu-riscv64.toml @@ -1,7 +1,7 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ - "riscv64-qemu-virt-hv", - "ax-hal/riscv64-qemu-virt-hv", + "dyn-plat", + "ax-hal/plat-dyn", "ax-driver/fdt", "ax-driver/virtio-blk", "ept-level-4", @@ -9,6 +9,7 @@ features = [ "sstc" ] log = "Info" +plat_dyn = true target = "riscv64gc-unknown-none-elf" vm_configs = [] max_cpu_num = 4 diff --git a/test-suit/axvisor/normal/qemu/build-riscv64gc-unknown-none-elf.toml b/test-suit/axvisor/normal/qemu/build-riscv64gc-unknown-none-elf.toml index a617ef0f96..1b626039e3 100644 --- a/test-suit/axvisor/normal/qemu/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/axvisor/normal/qemu/build-riscv64gc-unknown-none-elf.toml @@ -1,7 +1,7 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ - "riscv64-qemu-virt-hv", - "ax-hal/riscv64-qemu-virt-hv", + "dyn-plat", + "ax-hal/plat-dyn", "ax-driver/fdt", "ax-driver/virtio-blk", "ept-level-4", @@ -9,6 +9,7 @@ features = [ "sstc" ] log = "Info" +plat_dyn = true target = "riscv64gc-unknown-none-elf" vm_configs = ["os/axvisor/configs/vms/linux-riscv64-qemu-smp1.toml"] max_cpu_num = 4 From 81da8daa1490a86e57ab235ee04aded1c4d65ba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=9D=BF?= Date: Tue, 26 May 2026 17:58:29 +0800 Subject: [PATCH 04/17] feat(riscv64): support dynamic platform drivers --- .../build-aarch64-unknown-none-softfloat.toml | 3 +- .../build-aarch64-unknown-none-softfloat.toml | 1 + .../axplat-aarch64-qemu-virt/Cargo.toml | 2 +- .../axplat-loongarch64-qemu-virt/Cargo.toml | 2 +- .../axplat-riscv64-qemu-virt/Cargo.toml | 2 +- .../axplat-riscv64-sg2002/Cargo.toml | 2 +- .../platforms/axplat-x86-pc/Cargo.toml | 2 +- components/someboot/src/acpi/mod.rs | 5 + components/someboot/src/lib.rs | 1 + drivers/ax-driver/Cargo.toml | 57 +++--- drivers/ax-driver/build.rs | 33 ++-- drivers/ax-driver/src/block/cvsd.rs | 6 +- drivers/ax-driver/src/lib.rs | 25 ++- drivers/ax-driver/src/net/binding.rs | 13 +- drivers/ax-driver/src/pci/fdt.rs | 2 +- drivers/ax-driver/src/pci/mod.rs | 6 +- drivers/ax-driver/src/usb/mod.rs | 2 +- drivers/ax-driver/src/virtio/block.rs | 10 +- drivers/ax-driver/src/virtio/display.rs | 6 +- drivers/ax-driver/src/virtio/input.rs | 6 +- drivers/ax-driver/src/virtio/mod.rs | 2 +- drivers/ax-driver/src/virtio/net.rs | 6 +- drivers/ax-driver/src/virtio/vsock.rs | 6 +- drivers/intc/riscv_plic/src/lib.rs | 39 ++++- .../configs/board/licheerv-nano-sg2002.toml | 1 + .../configs/board/orangepi-5-plus.toml | 3 +- .../configs/board/qemu-aarch64-dyn.toml | 1 + os/StarryOS/configs/board/qemu-aarch64.toml | 2 +- .../configs/board/qemu-loongarch64.toml | 2 +- os/StarryOS/configs/board/qemu-riscv64.toml | 2 +- os/StarryOS/configs/board/qemu-x86_64.toml | 2 +- os/arceos/README.md | 2 +- os/arceos/doc/ixgbe.md | 6 +- os/arceos/modules/axruntime/src/devices.rs | 28 +++ os/arceos/modules/axruntime/src/lib.rs | 12 +- os/arceos/ulib/arceos-rust/lib/Cargo.toml | 4 +- os/axvisor/configs/board/orangepi-5-plus.toml | 1 + os/axvisor/configs/board/phytiumpi.toml | 1 + os/axvisor/configs/board/qemu-aarch64.toml | 1 + .../configs/board/qemu-loongarch64.toml | 2 +- .../configs/board/qemu-riscv64-dyn.toml | 2 +- os/axvisor/configs/board/qemu-riscv64.toml | 2 +- os/axvisor/configs/board/qemu-x86_64.toml | 2 +- os/axvisor/configs/board/rdk-s100.toml | 1 + os/axvisor/configs/board/roc-rk3568-pc.toml | 1 + os/axvisor/configs/board/tac-e400.toml | 1 + platform/axplat-dyn/Cargo.toml | 2 +- platform/axplat-dyn/src/drivers/mod.rs | 4 + platform/somehal/src/arch/riscv64/plic.rs | 162 ++++++++++++------ platform/somehal/src/driver.rs | 12 ++ platform/x86-qemu-q35/Cargo.toml | 2 +- scripts/axbuild/src/arceos/cbuild.rs | 6 +- scripts/axbuild/src/axvisor/build.rs | 6 +- scripts/axbuild/src/build.rs | 5 +- .../build-aarch64-unknown-none-softfloat.toml | 2 +- ...ld-loongarch64-unknown-none-softfloat.toml | 2 +- .../build-riscv64gc-unknown-none-elf.toml | 2 +- .../httpclient/build-x86_64-unknown-none.toml | 2 +- .../build-aarch64-unknown-none-softfloat.toml | 2 +- ...ld-loongarch64-unknown-none-softfloat.toml | 2 +- .../build-riscv64gc-unknown-none-elf.toml | 2 +- .../display/build-x86_64-unknown-none.toml | 2 +- .../build-aarch64-unknown-none-softfloat.toml | 2 +- ...ld-loongarch64-unknown-none-softfloat.toml | 2 +- .../build-riscv64gc-unknown-none-elf.toml | 2 +- .../fs/shell/build-x86_64-unknown-none.toml | 2 +- .../build-aarch64-unknown-none-softfloat.toml | 2 +- ...ld-loongarch64-unknown-none-softfloat.toml | 2 +- .../build-riscv64gc-unknown-none-elf.toml | 2 +- .../echoserver/build-x86_64-unknown-none.toml | 2 +- .../build-aarch64-unknown-none-softfloat.toml | 2 +- ...ld-loongarch64-unknown-none-softfloat.toml | 2 +- .../build-riscv64gc-unknown-none-elf.toml | 2 +- .../httpclient/build-x86_64-unknown-none.toml | 2 +- .../build-aarch64-unknown-none-softfloat.toml | 2 +- ...ld-loongarch64-unknown-none-softfloat.toml | 2 +- .../build-riscv64gc-unknown-none-elf.toml | 2 +- .../httpserver/build-x86_64-unknown-none.toml | 2 +- .../build-aarch64-unknown-none-softfloat.toml | 2 +- ...ld-loongarch64-unknown-none-softfloat.toml | 2 +- .../build-riscv64gc-unknown-none-elf.toml | 2 +- .../udpserver/build-x86_64-unknown-none.toml | 2 +- .../build-aarch64-unknown-none-softfloat.toml | 1 + .../build-aarch64-unknown-none-softfloat.toml | 1 + .../build-aarch64-unknown-none-softfloat.toml | 1 + .../build-aarch64-unknown-none-softfloat.toml | 1 + .../build-aarch64-unknown-none-softfloat.toml | 1 + ...ld-loongarch64-unknown-none-softfloat.toml | 2 +- .../build-riscv64gc-unknown-none-elf.toml | 2 +- .../qemu/build-x86_64-unknown-none.toml | 2 +- .../svm/qemu/build-x86_64-unknown-none.toml | 2 +- .../build-aarch64-unknown-none-softfloat.toml | 2 +- .../build-riscv64gc-unknown-none-elf.toml | 1 + .../build-aarch64-unknown-none-softfloat.toml | 3 +- .../build-aarch64-unknown-none-softfloat.toml | 1 + .../qemu-dhcp/build-x86_64-unknown-none.toml | 2 +- .../build-aarch64-unknown-none-softfloat.toml | 2 +- ...ld-loongarch64-unknown-none-softfloat.toml | 2 +- .../build-riscv64gc-unknown-none-elf.toml | 2 +- .../qemu-smp1/build-x86_64-unknown-none.toml | 2 +- .../build-aarch64-unknown-none-softfloat.toml | 2 +- ...ld-loongarch64-unknown-none-softfloat.toml | 2 +- .../build-riscv64gc-unknown-none-elf.toml | 2 +- .../qemu-smp4/build-x86_64-unknown-none.toml | 2 +- .../build-aarch64-unknown-none-softfloat.toml | 2 +- ...ld-loongarch64-unknown-none-softfloat.toml | 2 +- .../build-riscv64gc-unknown-none-elf.toml | 2 +- .../postgresql/build-x86_64-unknown-none.toml | 2 +- .../build-aarch64-unknown-none-softfloat.toml | 2 +- ...ld-loongarch64-unknown-none-softfloat.toml | 2 +- .../build-riscv64gc-unknown-none-elf.toml | 2 +- .../build-x86_64-unknown-none.toml | 2 +- 112 files changed, 396 insertions(+), 231 deletions(-) diff --git a/apps/starry/orangepi-5-plus-uvc-rknn/build-aarch64-unknown-none-softfloat.toml b/apps/starry/orangepi-5-plus-uvc-rknn/build-aarch64-unknown-none-softfloat.toml index f9a746df72..c1c2589b4f 100644 --- a/apps/starry/orangepi-5-plus-uvc-rknn/build-aarch64-unknown-none-softfloat.toml +++ b/apps/starry/orangepi-5-plus-uvc-rknn/build-aarch64-unknown-none-softfloat.toml @@ -2,10 +2,11 @@ target = "aarch64-unknown-none-softfloat" env = {} features = [ + "ax-driver/plat-dyn", "ax-hal/plat-dyn", "starry-kernel/plat-dyn", "ax-driver/irq", - "ax-driver/pci-list-devices", + "ax-driver/list-pci-devices", "ax-driver/rk3588-pcie", "ax-driver/realtek-rtl8125", "ax-driver/rockchip-soc", diff --git a/apps/starry/orangepi-5-plus-uvc/build-aarch64-unknown-none-softfloat.toml b/apps/starry/orangepi-5-plus-uvc/build-aarch64-unknown-none-softfloat.toml index a931ef284e..dd00ceec04 100644 --- a/apps/starry/orangepi-5-plus-uvc/build-aarch64-unknown-none-softfloat.toml +++ b/apps/starry/orangepi-5-plus-uvc/build-aarch64-unknown-none-softfloat.toml @@ -2,6 +2,7 @@ target = "aarch64-unknown-none-softfloat" env = {} features = [ + "ax-driver/plat-dyn", "ax-hal/plat-dyn", "starry-kernel/plat-dyn", "ax-driver/rockchip-soc", diff --git a/components/axplat_crates/platforms/axplat-aarch64-qemu-virt/Cargo.toml b/components/axplat_crates/platforms/axplat-aarch64-qemu-virt/Cargo.toml index 948e148731..89c39b7117 100644 --- a/components/axplat_crates/platforms/axplat-aarch64-qemu-virt/Cargo.toml +++ b/components/axplat_crates/platforms/axplat-aarch64-qemu-virt/Cargo.toml @@ -30,7 +30,7 @@ ax-page-table-entry = { workspace = true } ax-config-macros = { workspace = true } ax-plat-aarch64-peripherals = { workspace = true } ax-cpu = { workspace = true } -ax-driver = { workspace = true, features = ["pci", "virtio"] } +ax-driver = { workspace = true, features = ["plat-static", "virtio"] } ax-plat = { workspace = true } axklib = { workspace = true, optional = true } mmio-api.workspace = true diff --git a/components/axplat_crates/platforms/axplat-loongarch64-qemu-virt/Cargo.toml b/components/axplat_crates/platforms/axplat-loongarch64-qemu-virt/Cargo.toml index 87fbda9b75..b4d135415d 100644 --- a/components/axplat_crates/platforms/axplat-loongarch64-qemu-virt/Cargo.toml +++ b/components/axplat_crates/platforms/axplat-loongarch64-qemu-virt/Cargo.toml @@ -27,7 +27,7 @@ uart_16550 = "0.5" ax-config-macros = { workspace = true } ax-cpu = { workspace = true } -ax-driver = { workspace = true, features = ["pci"] } +ax-driver = { workspace = true, features = ["plat-static"] } ax-plat = { workspace = true } axklib = { workspace = true, optional = true } mmio-api.workspace = true diff --git a/components/axplat_crates/platforms/axplat-riscv64-qemu-virt/Cargo.toml b/components/axplat_crates/platforms/axplat-riscv64-qemu-virt/Cargo.toml index 6cdc7a6442..7db1c1b412 100644 --- a/components/axplat_crates/platforms/axplat-riscv64-qemu-virt/Cargo.toml +++ b/components/axplat_crates/platforms/axplat-riscv64-qemu-virt/Cargo.toml @@ -29,7 +29,7 @@ some-serial.workspace = true ax-config-macros = { workspace = true } ax-cpu = { workspace = true } -ax-driver = { workspace = true, features = ["pci", "virtio"] } +ax-driver = { workspace = true, features = ["plat-static", "virtio"] } ax-plat = { workspace = true } axklib = { workspace = true, optional = true } mmio-api.workspace = true diff --git a/components/axplat_crates/platforms/axplat-riscv64-sg2002/Cargo.toml b/components/axplat_crates/platforms/axplat-riscv64-sg2002/Cargo.toml index b08b88146e..c44156bfc6 100644 --- a/components/axplat_crates/platforms/axplat-riscv64-sg2002/Cargo.toml +++ b/components/axplat_crates/platforms/axplat-riscv64-sg2002/Cargo.toml @@ -25,7 +25,7 @@ dw_uart_rs = "0.2.0" log = { workspace = true } ax-config-macros = { workspace = true } ax-cpu = { workspace = true, features = ["xuantie-c9xx"] } -ax-driver = { workspace = true, features = ["block"] } +ax-driver = { workspace = true, features = ["plat-static", "block"] } ax-kspin = { workspace = true } ax-lazyinit = { workspace = true } ax-plat = { workspace = true } diff --git a/components/axplat_crates/platforms/axplat-x86-pc/Cargo.toml b/components/axplat_crates/platforms/axplat-x86-pc/Cargo.toml index 808ec12786..cad9fb1fb8 100644 --- a/components/axplat_crates/platforms/axplat-x86-pc/Cargo.toml +++ b/components/axplat_crates/platforms/axplat-x86-pc/Cargo.toml @@ -26,7 +26,7 @@ ax-percpu.workspace = true heapless = "0.9" ax-config-macros = { workspace = true } ax-cpu = { workspace = true } -ax-driver = { workspace = true, features = ["pci"] } +ax-driver = { workspace = true, features = ["plat-static"] } ax-plat = { workspace = true } axklib.workspace = true diff --git a/components/someboot/src/acpi/mod.rs b/components/someboot/src/acpi/mod.rs index 4eb8a6ecb8..dfd5deab6a 100644 --- a/components/someboot/src/acpi/mod.rs +++ b/components/someboot/src/acpi/mod.rs @@ -35,6 +35,11 @@ fn rsdp() -> Option> { NonNull::new(ptr) } +pub fn rsdp_addr_phys() -> Option { + let rsdp = unsafe { RSDP }; + (rsdp != 0).then_some(rsdp) +} + pub fn tables() -> Result, acpi::AcpiError> { unsafe { let rsdp = if RSDP == 0 { diff --git a/components/someboot/src/lib.rs b/components/someboot/src/lib.rs index 14f1c1b6e6..d5679a68fc 100644 --- a/components/someboot/src/lib.rs +++ b/components/someboot/src/lib.rs @@ -47,6 +47,7 @@ pub mod power; pub mod smp; pub mod timer; +pub use acpi::rsdp_addr_phys; pub use fdt::{fdt_addr, fdt_addr_phys}; pub use page_table_generic::*; pub use somehal_macros::{entry, irq_handler, someboot_secondary_entry as secondary_entry}; diff --git a/drivers/ax-driver/Cargo.toml b/drivers/ax-driver/Cargo.toml index 0825a400b6..fe02a0e75e 100644 --- a/drivers/ax-driver/Cargo.toml +++ b/drivers/ax-driver/Cargo.toml @@ -13,14 +13,12 @@ name = "ax_driver" [features] default = [] -fdt = ["dep:fdt-edit"] -acpi = [] -pci = ["dep:pcie", "dep:heapless", "dep:rdif-pcie", "dep:spin"] -pci-fdt = ["pci", "fdt", "dep:rdif-intc"] +plat-static = [] +plat-dyn = ["dep:fdt-edit"] irq = [] -block = ["dep:ax-errno", "dep:ax-kspin", "dep:rd-block", "dep:spin"] -net = ["dep:rd-net", "dep:spin"] +block = ["dep:ax-errno", "dep:ax-kspin", "dep:rd-block"] +net = ["dep:rd-net"] display = ["dep:ax-errno", "dep:rdif-display"] input = ["dep:ax-errno", "dep:rdif-input"] vsock = ["dep:ax-errno", "dep:rdif-vsock"] @@ -35,24 +33,24 @@ virtio-socket = ["vsock", "virtio"] ramdisk = ["block", "dep:ramdisk"] bcm2835-sdhci = ["block", "dep:bcm2835-sdhci"] -cvsd = ["block", "fdt", "dep:sg200x-bsp"] -ahci = ["block", "pci", "dep:simple-ahci"] -ixgbe = ["net", "pci", "dep:ax-alloc", "dep:ixgbe-driver"] +cvsd = ["block", "plat-dyn", "dep:sg200x-bsp"] +ahci = ["block", "dep:simple-ahci"] +ixgbe = ["net", "dep:ax-alloc", "dep:ixgbe-driver"] fxmac = ["net", "dep:ax-alloc", "dep:ax-crate-interface", "dep:fxmac_rs"] -intel-net = ["net", "pci", "dep:eth-intel"] -realtek-rtl8125 = ["net", "pci", "dep:realtek-rtl8125"] +intel-net = ["net", "dep:eth-intel"] +realtek-rtl8125 = ["net", "dep:realtek-rtl8125"] usb = ["dep:crab-usb"] -rockchip-dwc-xhci = ["usb", "fdt", "rockchip-soc", "rockchip-pm"] -xhci-mmio = ["usb", "fdt"] -xhci-pci = ["usb", "pci"] -serial = ["fdt", "dep:some-serial"] -sg2002-placeholder = ["fdt"] -rtc = ["fdt", "dep:ax-arm-pl031"] -rknpu = ["fdt", "rockchip-pm", "rockchip-soc", "dep:rockchip-npu"] +rockchip-dwc-xhci = ["usb", "plat-dyn", "rockchip-soc", "rockchip-pm"] +xhci-mmio = ["usb", "plat-dyn"] +xhci-pci = ["usb"] +serial = ["plat-dyn", "dep:some-serial"] +sg2002-placeholder = ["plat-dyn"] +rtc = ["plat-dyn", "dep:ax-arm-pl031"] +rknpu = ["plat-dyn", "rockchip-pm", "rockchip-soc", "dep:rockchip-npu"] rockchip-sdhci = [ "block", - "fdt", + "plat-dyn", "rockchip-soc", "dep:ax-kspin", "dep:rdif-clk", @@ -62,7 +60,7 @@ rockchip-sdhci = [ ] phytium-mci = [ "block", - "fdt", + "plat-dyn", "dep:ax-kspin", "dep:phytium-mci-host", "dep:sdmmc-protocol", @@ -70,7 +68,7 @@ phytium-mci = [ ] rockchip-dwmmc = [ "block", - "fdt", + "plat-dyn", "rockchip-soc", "dep:arm-scmi-rs", "dep:ax-kspin", @@ -80,15 +78,14 @@ rockchip-dwmmc = [ "sdmmc-protocol/sdio", ] rk3588-pcie = [ - "pci-fdt", + "plat-dyn", "rockchip-soc", "rockchip-pm", - "dep:rdif-pcie", "dep:rk3588-pci", ] -rockchip-soc = ["fdt", "dep:rdif-clk", "dep:rockchip-soc"] +rockchip-soc = ["plat-dyn", "dep:rdif-clk", "dep:rockchip-soc"] rockchip-pm = ["rockchip-soc", "dep:rockchip-pm"] -pci-list-devices = ["pci"] +list-pci-devices = [] [dependencies] anyhow = { workspace = true } @@ -107,19 +104,19 @@ dwmmc-host = { workspace = true, optional = true } eth-intel = { workspace = true, optional = true } fdt-edit = { workspace = true, optional = true } fxmac_rs = { workspace = true, optional = true } -heapless = { workspace = true, optional = true } +heapless.workspace = true ixgbe-driver = { workspace = true, optional = true } log.workspace = true mmio-api.workspace = true -pcie = { workspace = true, optional = true } +pcie.workspace = true ramdisk = { workspace = true, optional = true } rd-block = { workspace = true, optional = true } rd-net = { workspace = true, optional = true } rdif-clk = { workspace = true, optional = true } rdif-display = { workspace = true, optional = true } rdif-input = { workspace = true, optional = true } -rdif-intc = { workspace = true, optional = true } -rdif-pcie = { workspace = true, optional = true } +rdif-intc.workspace = true +rdif-pcie.workspace = true rdif-vsock = { workspace = true, optional = true } realtek-rtl8125 = { workspace = true, optional = true } rdrive.workspace = true @@ -134,5 +131,5 @@ sdmmc-protocol = { workspace = true, default-features = false, optional = true } sg200x-bsp = { workspace = true, optional = true } simple-ahci = { workspace = true, optional = true } some-serial = { workspace = true, optional = true } -spin = { workspace = true, optional = true } +spin.workspace = true virtio-drivers = { workspace = true, optional = true } diff --git a/drivers/ax-driver/build.rs b/drivers/ax-driver/build.rs index 18fdbe491a..3d186f6c3b 100644 --- a/drivers/ax-driver/build.rs +++ b/drivers/ax-driver/build.rs @@ -6,14 +6,6 @@ const VIRTIO_DEV_FEATURES: &[&str] = &[ "virtio-socket", ]; -fn make_cfg_values(str_list: &[&str]) -> String { - str_list - .iter() - .map(|s| format!("{s:?}")) - .collect::>() - .join(", ") -} - fn has_feature(feature: &str) -> bool { std::env::var(format!( "CARGO_FEATURE_{}", @@ -26,10 +18,6 @@ fn has_any_feature(features: &[&str]) -> bool { features.iter().any(|feature| has_feature(feature)) } -fn enable_cfg(key: &str, value: &str) { - println!("cargo:rustc-cfg={key}=\"{value}\""); -} - fn enable_cfg_flag(key: &str) { println!("cargo:rustc-cfg={key}"); } @@ -37,16 +25,19 @@ fn enable_cfg_flag(key: &str) { fn main() { let has_virtio_core = has_feature("virtio-core"); let has_virtio_dev = has_any_feature(VIRTIO_DEV_FEATURES); - let has_pci = has_feature("pci"); - let has_fdt = has_feature("fdt"); + let has_plat_static = has_feature("plat-static"); + let has_plat_dyn = has_feature("plat-dyn"); let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default(); let target_has_cvsd = matches!(target_arch.as_str(), "riscv32" | "riscv64"); - if has_pci { - enable_cfg("probe", "pci"); + if has_plat_static && has_plat_dyn { + panic!("ax-driver features `plat-static` and `plat-dyn` are mutually exclusive"); + } + if has_plat_static { + enable_cfg_flag("plat_static"); } - if has_fdt { - enable_cfg("probe", "fdt"); + if has_plat_dyn { + enable_cfg_flag("plat_dyn"); } if has_virtio_core || has_virtio_dev { enable_cfg_flag("virtio_dev"); @@ -55,10 +46,8 @@ fn main() { enable_cfg_flag("sync_block_dev"); } - println!( - "cargo::rustc-check-cfg=cfg(probe, values({}))", - make_cfg_values(&["pci", "fdt"]) - ); + println!("cargo::rustc-check-cfg=cfg(plat_static)"); + println!("cargo::rustc-check-cfg=cfg(plat_dyn)"); println!("cargo::rustc-check-cfg=cfg(virtio_dev)"); println!("cargo::rustc-check-cfg=cfg(sync_block_dev)"); } diff --git a/drivers/ax-driver/src/block/cvsd.rs b/drivers/ax-driver/src/block/cvsd.rs index aec11d6a59..a9c87f1149 100644 --- a/drivers/ax-driver/src/block/cvsd.rs +++ b/drivers/ax-driver/src/block/cvsd.rs @@ -1,4 +1,4 @@ -#[cfg(probe = "fdt")] +#[cfg(plat_dyn)] use rdrive::register::FdtInfo; use rdrive::{PlatformDevice, probe::OnProbeError}; #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] @@ -11,7 +11,7 @@ use super::{SyncBlockOps, register_sync_block}; const BLOCK_SIZE: usize = 512; pub const DEVICE_NAME: &str = "cvsd"; -#[cfg(probe = "fdt")] +#[cfg(plat_dyn)] crate::model_register!( name: "FDT CVSD", level: ProbeLevel::PostKernel, @@ -22,7 +22,7 @@ crate::model_register!( }], ); -#[cfg(probe = "fdt")] +#[cfg(plat_dyn)] fn probe_fdt(info: FdtInfo<'_>, plat_dev: PlatformDevice) -> Result<(), OnProbeError> { let sdmmc = info.node.regs().into_iter().next().ok_or_else(|| { diff --git a/drivers/ax-driver/src/lib.rs b/drivers/ax-driver/src/lib.rs index 35d9a986cc..dcb0f0a7c9 100644 --- a/drivers/ax-driver/src/lib.rs +++ b/drivers/ax-driver/src/lib.rs @@ -45,19 +45,19 @@ crate::model_register!( pub mod error; #[cfg(any( - feature = "serial", - all(feature = "rtc", feature = "fdt"), - all(feature = "rockchip-soc", feature = "fdt"), - all(feature = "rockchip-pm", feature = "fdt"), - all(feature = "sg2002-placeholder", feature = "fdt"), - all(feature = "rockchip-dwmmc", feature = "fdt"), - all(feature = "rockchip-sdhci", feature = "fdt"), - all(feature = "phytium-mci", feature = "fdt"), - all(feature = "rk3588-pcie", feature = "fdt"), - all(feature = "rknpu", feature = "fdt"), - all(feature = "xhci-mmio", target_os = "none"), + all(feature = "serial", plat_dyn), + all(feature = "rtc", plat_dyn), + all(feature = "rockchip-soc", plat_dyn), + all(feature = "rockchip-pm", plat_dyn), + all(feature = "sg2002-placeholder", plat_dyn), + all(feature = "rockchip-dwmmc", plat_dyn), + all(feature = "rockchip-sdhci", plat_dyn), + all(feature = "phytium-mci", plat_dyn), + all(feature = "rk3588-pcie", plat_dyn), + all(feature = "rknpu", plat_dyn), + all(feature = "xhci-mmio", target_os = "none", plat_dyn), all(feature = "xhci-pci", target_os = "none"), - all(virtio_dev, probe = "fdt") + all(virtio_dev, plat_dyn) ))] pub mod mmio; @@ -72,7 +72,6 @@ pub mod net; #[cfg(feature = "vsock")] pub mod vsock; -#[cfg(feature = "pci")] pub mod pci; #[cfg(feature = "rknpu")] pub mod rknpu; diff --git a/drivers/ax-driver/src/net/binding.rs b/drivers/ax-driver/src/net/binding.rs index 32d4b0eda0..400bcf7f6e 100644 --- a/drivers/ax-driver/src/net/binding.rs +++ b/drivers/ax-driver/src/net/binding.rs @@ -42,7 +42,17 @@ impl DriverGeneric for PlatformNetDevice { } pub fn pci_legacy_irq(endpoint: &EndpointRc) -> Option { - #[cfg(all(feature = "pci-fdt", target_os = "none"))] + #[cfg(all( + plat_dyn, + target_os = "none", + any( + feature = "intel-net", + feature = "ixgbe", + feature = "realtek-rtl8125", + feature = "virtio-net", + feature = "xhci-pci", + ) + ))] { let interrupt_pin = endpoint.interrupt_pin(); if interrupt_pin != 0 { @@ -57,7 +67,6 @@ pub fn pci_legacy_irq(endpoint: &EndpointRc) -> Option { } } - #[cfg(feature = "pci")] if let Some(irq) = crate::pci::legacy_irq_for_endpoint(endpoint.address(), endpoint.interrupt_pin()) { diff --git a/drivers/ax-driver/src/pci/fdt.rs b/drivers/ax-driver/src/pci/fdt.rs index 194fb01709..eebeef5e56 100644 --- a/drivers/ax-driver/src/pci/fdt.rs +++ b/drivers/ax-driver/src/pci/fdt.rs @@ -281,7 +281,7 @@ fn decode_irq_cells(specifier: &[u32]) -> Option { } } -#[cfg(feature = "pci-list-devices")] +#[cfg(feature = "list-pci-devices")] mod pci_list_devices { use log::info; use rdrive::probe::pci::{EndpointRc, FnOnProbe}; diff --git a/drivers/ax-driver/src/pci/mod.rs b/drivers/ax-driver/src/pci/mod.rs index 83446aaddc..440ba7e553 100644 --- a/drivers/ax-driver/src/pci/mod.rs +++ b/drivers/ax-driver/src/pci/mod.rs @@ -29,10 +29,10 @@ use virtio_drivers::transport::{ #[cfg(virtio_dev)] use crate::virtio::VirtIoHalImpl; -#[cfg(feature = "pci-fdt")] +#[cfg(plat_dyn)] mod fdt; #[cfg(all( - feature = "pci-fdt", + plat_dyn, target_os = "none", any( feature = "intel-net", @@ -115,7 +115,7 @@ pub const fn has_static_endpoint_drivers() -> bool { feature = "virtio-gpu", feature = "virtio-input", feature = "virtio-socket", - feature = "pci-list-devices", + feature = "list-pci-devices", )) } diff --git a/drivers/ax-driver/src/usb/mod.rs b/drivers/ax-driver/src/usb/mod.rs index 1d76c99e08..9977cb1e49 100644 --- a/drivers/ax-driver/src/usb/mod.rs +++ b/drivers/ax-driver/src/usb/mod.rs @@ -240,7 +240,7 @@ fn pci_static_irq(endpoint: &rdrive::probe::pci::EndpointRc) -> Option { pub(crate) fn pci_irq_or_error( endpoint: &rdrive::probe::pci::EndpointRc, ) -> Result { - #[cfg(feature = "pci-fdt")] + #[cfg(plat_dyn)] if let Some(irq) = crate::pci::fdt_irq_for_endpoint(endpoint.address(), endpoint.interrupt_pin())? { diff --git a/drivers/ax-driver/src/virtio/block.rs b/drivers/ax-driver/src/virtio/block.rs index 0eb6a863cf..8081ce07a7 100644 --- a/drivers/ax-driver/src/virtio/block.rs +++ b/drivers/ax-driver/src/virtio/block.rs @@ -3,7 +3,7 @@ extern crate alloc; use alloc::format; use rdrive::{DriverGeneric, PlatformDevice, probe::OnProbeError}; -#[cfg(any(probe = "fdt", probe = "pci"))] +#[cfg(any(plat_dyn, plat_static))] use virtio_drivers::transport::DeviceType; use virtio_drivers::{ Error as VirtIoError, @@ -15,7 +15,7 @@ use crate::{block::PlatformDeviceBlock, virtio::VirtIoHalImpl}; const VIRTIO_BLK_DMA_BUFFER_SIZE: usize = 32 * SECTOR_SIZE; -#[cfg(probe = "pci")] +#[cfg(any(plat_static, plat_dyn))] crate::model_register!( name: "VirtIO Block", level: ProbeLevel::PostKernel, @@ -25,7 +25,7 @@ crate::model_register!( }], ); -#[cfg(probe = "pci")] +#[cfg(any(plat_static, plat_dyn))] fn probe_pci( endpoint: &mut rdrive::probe::pci::EndpointRc, plat_dev: PlatformDevice, @@ -34,7 +34,7 @@ fn probe_pci( register_transport(plat_dev, transport) } -#[cfg(probe = "fdt")] +#[cfg(plat_dyn)] crate::model_register!( name: "VirtIO MMIO Block", level: ProbeLevel::PostKernel, @@ -45,7 +45,7 @@ crate::model_register!( }], ); -#[cfg(probe = "fdt")] +#[cfg(plat_dyn)] fn probe_fdt( info: rdrive::register::FdtInfo<'_>, plat_dev: PlatformDevice, diff --git a/drivers/ax-driver/src/virtio/display.rs b/drivers/ax-driver/src/virtio/display.rs index 76e512c5a5..cf09df0f0e 100644 --- a/drivers/ax-driver/src/virtio/display.rs +++ b/drivers/ax-driver/src/virtio/display.rs @@ -4,13 +4,13 @@ use alloc::format; use rdif_display::{DisplayError, DisplayInfo, FrameBuffer, PixelFormat}; use rdrive::{DriverGeneric, PlatformDevice, probe::OnProbeError}; -#[cfg(probe = "pci")] +#[cfg(any(plat_static, plat_dyn))] use virtio_drivers::transport::DeviceType; use virtio_drivers::{Error as VirtIoError, device::gpu::VirtIOGpu, transport::Transport}; use crate::{display::PlatformDeviceDisplay, virtio::VirtIoHalImpl}; -#[cfg(probe = "pci")] +#[cfg(any(plat_static, plat_dyn))] crate::model_register!( name: "VirtIO GPU", level: ProbeLevel::PostKernel, @@ -20,7 +20,7 @@ crate::model_register!( }], ); -#[cfg(probe = "pci")] +#[cfg(any(plat_static, plat_dyn))] fn probe_pci( endpoint: &mut rdrive::probe::pci::EndpointRc, plat_dev: PlatformDevice, diff --git a/drivers/ax-driver/src/virtio/input.rs b/drivers/ax-driver/src/virtio/input.rs index a60e12d890..db93d0795e 100644 --- a/drivers/ax-driver/src/virtio/input.rs +++ b/drivers/ax-driver/src/virtio/input.rs @@ -4,7 +4,7 @@ use alloc::{borrow::ToOwned, format, string::String}; use rdif_input::{AbsInfo, EventType, InputDeviceId, InputError, InputEvent}; use rdrive::{DriverGeneric, PlatformDevice, probe::OnProbeError}; -#[cfg(probe = "pci")] +#[cfg(any(plat_static, plat_dyn))] use virtio_drivers::transport::DeviceType; use virtio_drivers::{ Error as VirtIoError, @@ -14,7 +14,7 @@ use virtio_drivers::{ use crate::{input::PlatformDeviceInput, virtio::VirtIoHalImpl}; -#[cfg(probe = "pci")] +#[cfg(any(plat_static, plat_dyn))] crate::model_register!( name: "VirtIO Input", level: ProbeLevel::PostKernel, @@ -24,7 +24,7 @@ crate::model_register!( }], ); -#[cfg(probe = "pci")] +#[cfg(any(plat_static, plat_dyn))] fn probe_pci( endpoint: &mut rdrive::probe::pci::EndpointRc, plat_dev: PlatformDevice, diff --git a/drivers/ax-driver/src/virtio/mod.rs b/drivers/ax-driver/src/virtio/mod.rs index 8ace7d4174..9ac7d1d300 100644 --- a/drivers/ax-driver/src/virtio/mod.rs +++ b/drivers/ax-driver/src/virtio/mod.rs @@ -138,7 +138,7 @@ pub fn register_static_transport( Err(rdrive::probe::OnProbeError::NotMatch) } -#[cfg(probe = "fdt")] +#[cfg(plat_dyn)] pub fn probe_fdt_mmio_device( info: &rdrive::register::FdtInfo<'_>, ) -> Result<(DeviceType, MmioTransport<'static>), rdrive::probe::OnProbeError> { diff --git a/drivers/ax-driver/src/virtio/net.rs b/drivers/ax-driver/src/virtio/net.rs index c89c3460cb..4e07c37579 100644 --- a/drivers/ax-driver/src/virtio/net.rs +++ b/drivers/ax-driver/src/virtio/net.rs @@ -9,7 +9,7 @@ use core::{ use ax_kernel_guard::NoPreemptIrqSave; use rd_net::{DmaBuffer, Event, IRxQueue, ITxQueue, Interface, NetError, QueueConfig}; use rdrive::{DriverGeneric, PlatformDevice, probe::OnProbeError}; -#[cfg(probe = "pci")] +#[cfg(any(plat_static, plat_dyn))] use virtio_drivers::transport::DeviceType; use virtio_drivers::{Error as VirtIoError, device::net::VirtIONetRaw, transport::Transport}; @@ -21,7 +21,7 @@ use crate::{ const QUEUE_SIZE: usize = 64; const BUFFER_SIZE: usize = 2048; -#[cfg(probe = "pci")] +#[cfg(any(plat_static, plat_dyn))] crate::model_register!( name: "VirtIO Net", level: ProbeLevel::PostKernel, @@ -305,7 +305,7 @@ struct RxInflight { len: usize, } -#[cfg(probe = "pci")] +#[cfg(any(plat_static, plat_dyn))] fn probe_pci( endpoint: &mut rdrive::probe::pci::EndpointRc, plat_dev: PlatformDevice, diff --git a/drivers/ax-driver/src/virtio/vsock.rs b/drivers/ax-driver/src/virtio/vsock.rs index 5fd1eeb279..7571ac1e8e 100644 --- a/drivers/ax-driver/src/virtio/vsock.rs +++ b/drivers/ax-driver/src/virtio/vsock.rs @@ -4,7 +4,7 @@ use alloc::format; use rdif_vsock::{VsockAddr as RdifVsockAddr, VsockConnId, VsockError, VsockEvent}; use rdrive::{DriverGeneric, PlatformDevice, probe::OnProbeError}; -#[cfg(probe = "pci")] +#[cfg(any(plat_static, plat_dyn))] use virtio_drivers::transport::DeviceType; use virtio_drivers::{ Error as VirtIoError, @@ -19,7 +19,7 @@ use crate::{virtio::VirtIoHalImpl, vsock::PlatformDeviceVsock}; const DEFAULT_RX_BUFFER_CAPACITY: u32 = 32 * 1024; -#[cfg(probe = "pci")] +#[cfg(any(plat_static, plat_dyn))] crate::model_register!( name: "VirtIO Socket", level: ProbeLevel::PostKernel, @@ -29,7 +29,7 @@ crate::model_register!( }], ); -#[cfg(probe = "pci")] +#[cfg(any(plat_static, plat_dyn))] fn probe_pci( endpoint: &mut rdrive::probe::pci::EndpointRc, plat_dev: PlatformDevice, diff --git a/drivers/intc/riscv_plic/src/lib.rs b/drivers/intc/riscv_plic/src/lib.rs index e3aadafcba..5de76cf2ab 100644 --- a/drivers/intc/riscv_plic/src/lib.rs +++ b/drivers/intc/riscv_plic/src/lib.rs @@ -65,6 +65,15 @@ pub struct Plic { unsafe impl Send for Plic {} unsafe impl Sync for Plic {} +/// Lock-free PLIC operations used by interrupt entry code. +#[derive(Clone, Copy)] +pub struct PlicIrqHandler { + base: NonNull, +} + +unsafe impl Send for PlicIrqHandler {} +unsafe impl Sync for PlicIrqHandler {} + impl Plic { /// Create a new instance of the PLIC from the base address. /// @@ -76,9 +85,14 @@ impl Plic { Self { base } } + /// Returns a lock-free handler for per-context interrupt entry operations. + pub const fn irq_handler(&self) -> PlicIrqHandler { + PlicIrqHandler { base: self.base } + } + /// Initialize the PLIC by context, setting the priority threshold to 0. pub fn init_by_context(&mut self, ctx: usize) { - self.regs().contexts[ctx].priority_threshold.set(0); + self.irq_handler().init_by_context(ctx); } const fn regs(&self) -> &PLICRegs { @@ -190,7 +204,7 @@ impl Plic { /// See §8. #[inline] pub fn claim(&mut self, ctx: usize) -> Option { - NonZeroU32::new(self.regs().contexts[ctx].interrupt_claim_complete.get()) + self.irq_handler().claim(ctx) } /// Mark that interrupt identified by `source` is completed in `context`. @@ -198,6 +212,27 @@ impl Plic { /// See §9. #[inline] pub fn complete(&mut self, ctx: usize, source: NonZeroU32) { + self.irq_handler().complete(ctx, source); + } +} + +impl PlicIrqHandler { + const fn regs(&self) -> &PLICRegs { + unsafe { self.base.as_ref() } + } + + /// Initialize the PLIC by context, setting the priority threshold to 0. + pub fn init_by_context(&self, ctx: usize) { + self.regs().contexts[ctx].priority_threshold.set(0); + } + + /// Claim an interrupt in `context`, returning its source. + pub fn claim(&self, ctx: usize) -> Option { + NonZeroU32::new(self.regs().contexts[ctx].interrupt_claim_complete.get()) + } + + /// Mark that interrupt identified by `source` is completed in `context`. + pub fn complete(&self, ctx: usize, source: NonZeroU32) { self.regs().contexts[ctx] .interrupt_claim_complete .set(source.get()); diff --git a/os/StarryOS/configs/board/licheerv-nano-sg2002.toml b/os/StarryOS/configs/board/licheerv-nano-sg2002.toml index 2927a0c22b..eaa27471d5 100644 --- a/os/StarryOS/configs/board/licheerv-nano-sg2002.toml +++ b/os/StarryOS/configs/board/licheerv-nano-sg2002.toml @@ -1,5 +1,6 @@ env = { UIMAGE = "y" } features = [ + "ax-driver/plat-dyn", "sg2002-dyn", "ax-feat/plat-dyn", "ax-driver/cvsd", diff --git a/os/StarryOS/configs/board/orangepi-5-plus.toml b/os/StarryOS/configs/board/orangepi-5-plus.toml index d3d5a0aa93..b97d639681 100644 --- a/os/StarryOS/configs/board/orangepi-5-plus.toml +++ b/os/StarryOS/configs/board/orangepi-5-plus.toml @@ -3,9 +3,10 @@ target = "aarch64-unknown-none-softfloat" # Runtime U-Boot settings live in `orangepi-5-plus-uboot.toml`. env = {} features = [ + "ax-driver/plat-dyn", "ax-hal/plat-dyn", "starry-kernel/plat-dyn", - "ax-driver/pci-list-devices", + "ax-driver/list-pci-devices", "ax-driver/rk3588-pcie", "ax-driver/realtek-rtl8125", "ax-driver/rockchip-soc", diff --git a/os/StarryOS/configs/board/qemu-aarch64-dyn.toml b/os/StarryOS/configs/board/qemu-aarch64-dyn.toml index d94a5bb8e3..4c9fe454f3 100644 --- a/os/StarryOS/configs/board/qemu-aarch64-dyn.toml +++ b/os/StarryOS/configs/board/qemu-aarch64-dyn.toml @@ -1,5 +1,6 @@ env = {} features = [ + "ax-driver/plat-dyn", "ax-hal/plat-dyn", "ax-driver/virtio-blk", "ax-driver/virtio-net", diff --git a/os/StarryOS/configs/board/qemu-aarch64.toml b/os/StarryOS/configs/board/qemu-aarch64.toml index 100371542c..be8795b4d2 100644 --- a/os/StarryOS/configs/board/qemu-aarch64.toml +++ b/os/StarryOS/configs/board/qemu-aarch64.toml @@ -2,7 +2,7 @@ env = {} features = [ "ax-hal/aarch64-qemu-virt", "qemu", - "ax-driver/pci", + "ax-driver/plat-static", "ax-driver/virtio-blk", "ax-driver/virtio-net", "ax-driver/virtio-gpu", diff --git a/os/StarryOS/configs/board/qemu-loongarch64.toml b/os/StarryOS/configs/board/qemu-loongarch64.toml index 4c35f73930..664004de9a 100644 --- a/os/StarryOS/configs/board/qemu-loongarch64.toml +++ b/os/StarryOS/configs/board/qemu-loongarch64.toml @@ -4,7 +4,7 @@ log = "Warn" features = [ "ax-hal/loongarch64-qemu-virt", "qemu", - "ax-driver/pci", + "ax-driver/plat-static", "ax-driver/virtio-blk", "ax-driver/virtio-net", "ax-driver/virtio-gpu", diff --git a/os/StarryOS/configs/board/qemu-riscv64.toml b/os/StarryOS/configs/board/qemu-riscv64.toml index f58dbe74c1..964056bc6f 100644 --- a/os/StarryOS/configs/board/qemu-riscv64.toml +++ b/os/StarryOS/configs/board/qemu-riscv64.toml @@ -2,7 +2,7 @@ env = {} features = [ "ax-feat/plat-dyn", "starry-kernel/plat-dyn", - "ax-driver/pci-fdt", + "ax-driver/plat-dyn", "ax-driver/serial", "ax-driver/virtio-blk", "ax-driver/virtio-net", diff --git a/os/StarryOS/configs/board/qemu-x86_64.toml b/os/StarryOS/configs/board/qemu-x86_64.toml index 7efd9aa1bd..1128aa2eb9 100644 --- a/os/StarryOS/configs/board/qemu-x86_64.toml +++ b/os/StarryOS/configs/board/qemu-x86_64.toml @@ -4,7 +4,7 @@ log = "Warn" features = [ "ax-hal/x86-pc", "qemu", - "ax-driver/pci", + "ax-driver/plat-static", "ax-driver/virtio-blk", "ax-driver/virtio-net", "ax-driver/virtio-gpu", diff --git a/os/arceos/README.md b/os/arceos/README.md index 60aab66a23..4807d32caf 100644 --- a/os/arceos/README.md +++ b/os/arceos/README.md @@ -209,7 +209,7 @@ You may also need to select the corrsponding device drivers by setting the `FEAT # Build the shell app for raspi4, and use the SD card driver make MYPLAT=axplat-aarch64-raspi SMP=4 A=examples/shell FEATURES=page-alloc-4g,ax-driver/bcm2835-sdhci # Build httpserver for the bare-metal x86_64 platform, and use the ixgbe and ramdisk driver -make PLAT_CONFIG=$(pwd)/configs/custom/x86_64-pc-oslab.toml A=examples/httpserver FEATURES=page-alloc-4g,ax-driver/pci,ax-driver/ixgbe,ax-driver/ramdisk SMP=4 +make PLAT_CONFIG=$(pwd)/configs/custom/x86_64-pc-oslab.toml A=examples/httpserver FEATURES=page-alloc-4g,ax-driver/plat-static,ax-driver/ixgbe,ax-driver/ramdisk SMP=4 ``` ## How to reuse ArceOS modules in your own project diff --git a/os/arceos/doc/ixgbe.md b/os/arceos/doc/ixgbe.md index 23f1a8597f..4b6e7e340e 100644 --- a/os/arceos/doc/ixgbe.md +++ b/os/arceos/doc/ixgbe.md @@ -6,7 +6,7 @@ You can use the following command to compile an 'httpserver' app application: ```shell make PLAT_CONFIG=$(pwd)/configs/custom/x86_64-pc-oslab.toml defconfig -make A=examples/httpserver PLAT_CONFIG=$(pwd)/configs/custom/x86_64-pc-oslab.toml FEATURES=ax-driver/pci,ax-driver/ixgbe +make A=examples/httpserver PLAT_CONFIG=$(pwd)/configs/custom/x86_64-pc-oslab.toml FEATURES=ax-driver/plat-static,ax-driver/ixgbe ``` You can also use the following command to start the iperf application: @@ -14,7 +14,7 @@ You can also use the following command to start the iperf application: ```shell git clone https://github.com/arceos-org/arceos-apps.git make PLAT_CONFIG=$(pwd)/configs/custom/x86_64-pc-oslab.toml defconfig -make A=arceos-apps/c/iperf PLAT_CONFIG=$(pwd)/configs/custom/x86_64-pc-oslab.toml FEATURES=ax-driver/pci,ax-driver/ixgbe,ax-driver/ramdisk +make A=arceos-apps/c/iperf PLAT_CONFIG=$(pwd)/configs/custom/x86_64-pc-oslab.toml FEATURES=ax-driver/plat-static,ax-driver/ixgbe,ax-driver/ramdisk ``` ## Use ixgbe NIC in QEMU with PCI passthrough @@ -38,7 +38,7 @@ make A=arceos-apps/c/iperf PLAT_CONFIG=$(pwd)/configs/custom/x86_64-pc-oslab.tom 3. Build and run ArceOS: ```shell - make A=examples/httpserver FEATURES=ax-driver/pci,ax-driver/ixgbe VFIO_PCI=02:00.0 IP=x.x.x.x GW=x.x.x.x run + make A=examples/httpserver FEATURES=ax-driver/plat-static,ax-driver/ixgbe VFIO_PCI=02:00.0 IP=x.x.x.x GW=x.x.x.x run ``` 4. If no longer in use, bind the NIC back to the `ixgbe` driver: diff --git a/os/arceos/modules/axruntime/src/devices.rs b/os/arceos/modules/axruntime/src/devices.rs index f7bfe6643f..f218302dfe 100644 --- a/os/arceos/modules/axruntime/src/devices.rs +++ b/os/arceos/modules/axruntime/src/devices.rs @@ -1,5 +1,9 @@ pub(crate) fn probe_all_devices() { info!("Probe platform devices..."); + if !rdrive::is_initialized() { + warn!("rdrive is not initialized; skip platform device probe"); + return; + } rdrive::probe_all(false) .unwrap_or_else(|err| panic!("failed to probe platform devices: {err:?}")); } @@ -9,6 +13,9 @@ pub(crate) fn take_dyn_fs_block_devices() -> alloc::vec::Vec> { #[cfg(target_os = "none")] { + if !rdrive::is_initialized() { + return alloc::vec::Vec::new(); + } ax_driver::block::take_block_devices() .into_iter() .map(|dev| { @@ -39,6 +46,9 @@ pub(crate) fn take_dyn_fs_ng_block_devices() -> alloc::vec::Vec> { #[cfg(target_os = "none")] { + if !rdrive::is_initialized() { + return alloc::vec::Vec::new(); + } ax_driver::block::take_block_devices() .into_iter() .map(|dev| { @@ -68,6 +78,10 @@ pub(crate) fn take_static_fs_ng_block_devices() pub(crate) fn init_dyn_display() { #[cfg(target_os = "none")] { + if !rdrive::is_initialized() { + ax_display::init_display(core::iter::empty::()); + return; + } let devices = ax_driver::display::take_display_devices() .unwrap_or_else(|err| panic!("failed to open display devices: {err:?}")) .into_iter() @@ -100,6 +114,10 @@ pub(crate) fn init_static_display() { pub(crate) fn init_dyn_input() { #[cfg(target_os = "none")] { + if !rdrive::is_initialized() { + ax_input::init_input(core::iter::empty::()); + return; + } let devices = ax_driver::input::take_input_devices() .unwrap_or_else(|err| panic!("failed to open input devices: {err:?}")) .into_iter() @@ -170,6 +188,10 @@ pub(crate) fn take_static_net_ng_drivers() pub(crate) fn init_dyn_vsock() { #[cfg(target_os = "none")] { + if !rdrive::is_initialized() { + ax_net_ng::init_vsock(alloc::vec::Vec::new()); + return; + } let devices = ax_driver::vsock::take_vsock_devices() .unwrap_or_else(|err| panic!("failed to open vsock devices: {err:?}")); ax_net_ng::init_vsock(devices); @@ -190,6 +212,9 @@ pub(crate) fn init_static_vsock() { fn take_dyn_net_drivers() -> alloc::vec::Vec> { #[cfg(target_os = "none")] { + if !rdrive::is_initialized() { + return alloc::vec::Vec::new(); + } let mut devices = alloc::vec::Vec::new(); for dev in rdrive::get_list::() { let (net, name, irq_num) = ax_driver::net::take_rd_net_device(dev) @@ -211,6 +236,9 @@ fn take_dyn_net_drivers() -> alloc::vec::Vec alloc::vec::Vec> { #[cfg(target_os = "none")] { + if !rdrive::is_initialized() { + return alloc::vec::Vec::new(); + } let mut devices = alloc::vec::Vec::new(); for dev in rdrive::get_list::() { let (net, name, irq_num) = ax_driver::net::take_rd_net_device(dev) diff --git a/os/arceos/modules/axruntime/src/lib.rs b/os/arceos/modules/axruntime/src/lib.rs index 31f957e60e..aafffd8880 100644 --- a/os/arceos/modules/axruntime/src/lib.rs +++ b/os/arceos/modules/axruntime/src/lib.rs @@ -251,13 +251,17 @@ pub fn rust_main(cpu_id: usize, arg: usize) -> ! { info!("Initialize platform devices..."); ax_hal::init_later(cpu_id, arg); - if !rdrive::is_initialized() { + if cfg!(not(feature = "plat-dyn")) && !rdrive::is_initialized() { rdrive::init(rdrive::Platform::Static) .unwrap_or_else(|err| panic!("failed to initialize static rdrive source: {err:?}")); } - registers::append_linker_registers(); - rdrive::probe_pre_kernel() - .unwrap_or_else(|err| panic!("failed to run pre-kernel driver probes: {err:?}")); + if rdrive::is_initialized() { + registers::append_linker_registers(); + rdrive::probe_pre_kernel() + .unwrap_or_else(|err| panic!("failed to run pre-kernel driver probes: {err:?}")); + } else { + warn!("rdrive is not initialized; skip pre-kernel driver probe"); + } #[cfg(feature = "multitask")] ax_task::init_scheduler(); diff --git a/os/arceos/ulib/arceos-rust/lib/Cargo.toml b/os/arceos/ulib/arceos-rust/lib/Cargo.toml index be7f862865..a9a5e45157 100644 --- a/os/arceos/ulib/arceos-rust/lib/Cargo.toml +++ b/os/arceos/ulib/arceos-rust/lib/Cargo.toml @@ -61,11 +61,11 @@ stack-guard-page = ["multitask", "paging", "ax-feat/stack-guard-page"] # File system fd = ["ax-posix-api/fd"] -fs = ["ax-api/fs", "ax-posix-api/fs", "ax-feat/fs", "ax-driver/pci", "ax-driver/virtio-blk"] +fs = ["ax-api/fs", "ax-posix-api/fs", "ax-feat/fs", "ax-driver/virtio-blk"] # Networking dns = [] -net = ["ax-api/net", "ax-posix-api/net", "ax-posix-api/poll", "ax-feat/net", "ax-driver/pci", "ax-driver/virtio-net"] +net = ["ax-api/net", "ax-posix-api/net", "ax-posix-api/poll", "ax-feat/net", "ax-driver/virtio-net"] # Display display = ["ax-api/display", "ax-feat/display"] diff --git a/os/axvisor/configs/board/orangepi-5-plus.toml b/os/axvisor/configs/board/orangepi-5-plus.toml index e8f449b079..f279d3963e 100644 --- a/os/axvisor/configs/board/orangepi-5-plus.toml +++ b/os/axvisor/configs/board/orangepi-5-plus.toml @@ -1,5 +1,6 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ + "ax-driver/plat-dyn", "sdmmc", "rockchip-soc", "fs", diff --git a/os/axvisor/configs/board/phytiumpi.toml b/os/axvisor/configs/board/phytiumpi.toml index 42a0ed4050..c81e3e627a 100644 --- a/os/axvisor/configs/board/phytiumpi.toml +++ b/os/axvisor/configs/board/phytiumpi.toml @@ -1,5 +1,6 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ + "ax-driver/plat-dyn", "fs", "phytium-mci", ] diff --git a/os/axvisor/configs/board/qemu-aarch64.toml b/os/axvisor/configs/board/qemu-aarch64.toml index 317e9aae7c..590f33a70a 100644 --- a/os/axvisor/configs/board/qemu-aarch64.toml +++ b/os/axvisor/configs/board/qemu-aarch64.toml @@ -1,5 +1,6 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ + "ax-driver/plat-dyn", "ax-hal/plat-dyn", "ept-level-4", "ax-driver/virtio-blk", diff --git a/os/axvisor/configs/board/qemu-loongarch64.toml b/os/axvisor/configs/board/qemu-loongarch64.toml index b7945d66d0..06e413dfe1 100644 --- a/os/axvisor/configs/board/qemu-loongarch64.toml +++ b/os/axvisor/configs/board/qemu-loongarch64.toml @@ -2,7 +2,7 @@ env = {AX_IP = "10.0.2.15", AX_GW = "10.0.2.2"} features = [ "ax-hal/loongarch64-qemu-virt", "ax-driver/virtio-blk", - "ax-driver/pci", + "ax-driver/plat-static", "ept-level-4", "fs", ] diff --git a/os/axvisor/configs/board/qemu-riscv64-dyn.toml b/os/axvisor/configs/board/qemu-riscv64-dyn.toml index a1c8aab23e..1b73a30882 100644 --- a/os/axvisor/configs/board/qemu-riscv64-dyn.toml +++ b/os/axvisor/configs/board/qemu-riscv64-dyn.toml @@ -2,7 +2,7 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ "dyn-plat", "ax-hal/plat-dyn", - "ax-driver/fdt", + "ax-driver/plat-dyn", "ax-driver/virtio-blk", "ept-level-4", "fs", diff --git a/os/axvisor/configs/board/qemu-riscv64.toml b/os/axvisor/configs/board/qemu-riscv64.toml index a1c8aab23e..1b73a30882 100644 --- a/os/axvisor/configs/board/qemu-riscv64.toml +++ b/os/axvisor/configs/board/qemu-riscv64.toml @@ -2,7 +2,7 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ "dyn-plat", "ax-hal/plat-dyn", - "ax-driver/fdt", + "ax-driver/plat-dyn", "ax-driver/virtio-blk", "ept-level-4", "fs", diff --git a/os/axvisor/configs/board/qemu-x86_64.toml b/os/axvisor/configs/board/qemu-x86_64.toml index 64e99f9093..ffae3f21b0 100644 --- a/os/axvisor/configs/board/qemu-x86_64.toml +++ b/os/axvisor/configs/board/qemu-x86_64.toml @@ -2,7 +2,7 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ "ax-hal/x86-qemu-q35", "ax-driver/virtio-blk", - "ax-driver/pci", + "ax-driver/plat-static", "ept-level-4", "fs", ] diff --git a/os/axvisor/configs/board/rdk-s100.toml b/os/axvisor/configs/board/rdk-s100.toml index 252da5797d..cb50bbb3af 100644 --- a/os/axvisor/configs/board/rdk-s100.toml +++ b/os/axvisor/configs/board/rdk-s100.toml @@ -1,5 +1,6 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ + "ax-driver/plat-dyn", "ax-hal/plat-dyn", "ept-level-4", ] diff --git a/os/axvisor/configs/board/roc-rk3568-pc.toml b/os/axvisor/configs/board/roc-rk3568-pc.toml index 211950cdb6..234d3d70b5 100644 --- a/os/axvisor/configs/board/roc-rk3568-pc.toml +++ b/os/axvisor/configs/board/roc-rk3568-pc.toml @@ -1,5 +1,6 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ + "ax-driver/plat-dyn", "fs", "rockchip-sdhci", ] diff --git a/os/axvisor/configs/board/tac-e400.toml b/os/axvisor/configs/board/tac-e400.toml index 252da5797d..cb50bbb3af 100644 --- a/os/axvisor/configs/board/tac-e400.toml +++ b/os/axvisor/configs/board/tac-e400.toml @@ -1,5 +1,6 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ + "ax-driver/plat-dyn", "ax-hal/plat-dyn", "ept-level-4", ] diff --git a/platform/axplat-dyn/Cargo.toml b/platform/axplat-dyn/Cargo.toml index 6c233a85d0..0d959fd92a 100644 --- a/platform/axplat-dyn/Cargo.toml +++ b/platform/axplat-dyn/Cargo.toml @@ -24,7 +24,7 @@ anyhow = { version = "1", default-features = false } ax-alloc = { workspace = true, features = ["buddy-slab"] } ax-config-macros = { workspace = true } ax-cpu.workspace = true -ax-driver = { workspace = true, features = ["fdt", "pci-fdt"] } +ax-driver = { workspace = true, features = ["plat-dyn"] } ax-errno.workspace = true axklib.workspace = true ax-plat.workspace = true diff --git a/platform/axplat-dyn/src/drivers/mod.rs b/platform/axplat-dyn/src/drivers/mod.rs index c2d12a2374..9edd46844a 100644 --- a/platform/axplat-dyn/src/drivers/mod.rs +++ b/platform/axplat-dyn/src/drivers/mod.rs @@ -1,5 +1,9 @@ use ax_errno::AxError; pub fn probe_all_devices() -> Result<(), AxError> { + if !rdrive::is_initialized() { + warn!("rdrive is not initialized; skip platform device probe"); + return Ok(()); + } rdrive::probe_all(false).map_err(|_| AxError::BadState) } diff --git a/platform/somehal/src/arch/riscv64/plic.rs b/platform/somehal/src/arch/riscv64/plic.rs index 06273e1ad6..d471a3f345 100644 --- a/platform/somehal/src/arch/riscv64/plic.rs +++ b/platform/somehal/src/arch/riscv64/plic.rs @@ -1,17 +1,16 @@ use alloc::{format, vec::Vec}; use core::{num::NonZeroU32, ptr::NonNull}; -use ax_riscv_plic::{PLICRegs, Plic}; +use ax_riscv_plic::{PLICRegs, Plic, PlicIrqHandler}; use kernutil::StaticCell; use rdif_intc::Interface; use rdrive::{ - DriverGeneric, Phandle, PlatformDevice, module_driver, + Device, DriverGeneric, Phandle, PlatformDevice, module_driver, probe::{OnProbeError, fdt::NodeType}, register::FdtInfo, }; use riscv::register::{sie, sip}; use sbi_rt::HartMask; -use spin::Mutex; use crate::{common::ioremap, irq::_handle_irq}; @@ -23,7 +22,7 @@ const SUPERVISOR_EXTERNAL_INTERRUPT: u32 = 9; const DEFAULT_PRIORITY: u32 = 1; const DEFAULT_PLIC_SIZE: usize = 0x400_0000; -static PLIC: StaticCell> = StaticCell::uninit(); +static IRQ_HANDLER: StaticCell = StaticCell::uninit(); module_driver!( name: "RISC-V PLIC", @@ -99,10 +98,8 @@ pub fn irq_handler_with_raw(raw: usize) -> Option { pub fn secondary_init_intc() { enable_local_interrupts(); - if PLIC.is_init() { - unsafe { - PLIC.update(|plic| plic.lock().init_current_context()); - } + if let Some(handler) = get_irq_handler() { + handler.init_current_context(); } } @@ -143,16 +140,20 @@ fn probe_plic(info: FdtInfo<'_>, dev: PlatformDevice) -> Result<(), OnProbeError .unwrap_or(1024) as usize; let contexts = parse_supervisor_contexts(&info); - let mut plic = RiscvPlic { + let irq_handler = RiscvPlicIrqHandler { + inner: plic.irq_handler(), + context_by_cpu: contexts.clone(), + }; + IRQ_HANDLER.init(irq_handler); + IRQ_HANDLER.init_current_context(); + let plic = RiscvPlic { inner: plic, context_by_cpu: contexts, sources: ndev, }; - plic.init_current_context(); - PLIC.init(Mutex::new(plic)); enable_local_interrupts(); - dev.register(rdif_intc::Intc::new(RiscvPlicIntc)); + dev.register(rdif_intc::Intc::new(plic)); Ok(()) } @@ -201,31 +202,59 @@ fn enable_local_interrupts() { } fn set_external_irq_enable(irq: usize, enable: bool) { - if !PLIC.is_init() { - warn!("PLIC is not initialized when setting IRQ {irq}"); - return; - } let Some(source) = NonZeroU32::new(irq as u32) else { return; }; - unsafe { - PLIC.update(|plic| { - let mut plic = plic.lock(); - if enable { - plic.enable_source(source); - } else { - plic.disable_source(source); - } - }); - } + with_plic("setting PLIC IRQ enable", |plic| { + if enable { + plic.enable_source(source); + } else { + plic.disable_source(source); + } + }); } fn handle_external_irq() -> Option { - if !PLIC.is_init() { - warn!("PLIC is not initialized for external IRQ"); + let Some(handler) = get_irq_handler() else { + warn!("RISC-V PLIC IRQ handler is not registered for external IRQ"); + return None; + }; + let source = handler.claim_current()?; + let irq = someboot::irq::IrqId::new(source.get() as usize); + _handle_irq(irq.raw().into()); + handler.complete_current(source); + Some(irq) +} + +fn with_plic(op: &str, f: impl FnOnce(&mut RiscvPlic) -> R) -> Option { + let Some(intc) = get_plic() else { + warn!("RISC-V PLIC is not registered when {op}"); + return None; + }; + let Ok(mut intc) = intc.lock() else { + warn!("failed to lock RISC-V PLIC when {op}"); return None; + }; + let Some(plic) = intc.typed_mut::() else { + warn!("registered interrupt controller is not RISC-V PLIC when {op}"); + return None; + }; + Some(f(plic)) +} + +fn get_plic() -> Option> { + if !rdrive::is_initialized() { + return None; + } + rdrive::get_one() +} + +fn get_irq_handler() -> Option<&'static RiscvPlicIrqHandler> { + if IRQ_HANDLER.is_init() { + Some(&IRQ_HANDLER) + } else { + None } - unsafe { PLIC.update(|plic| plic.lock().handle_external_irq()) } } struct RiscvPlic { @@ -234,13 +263,17 @@ struct RiscvPlic { sources: usize, } -impl RiscvPlic { +struct RiscvPlicIrqHandler { + inner: PlicIrqHandler, + context_by_cpu: Vec>, +} + +impl RiscvPlicIrqHandler { fn current_context(&self) -> Option { - let cpu_idx = someboot::smp::cpu_idx(); - self.context_by_cpu.get(cpu_idx).and_then(|ctx| *ctx) + current_context(&self.context_by_cpu) } - fn init_current_context(&mut self) { + fn init_current_context(&self) { if let Some(context) = self.current_context() { self.inner.init_by_context(context); trace!("PLIC context {context} initialized"); @@ -252,13 +285,41 @@ impl RiscvPlic { } } + fn claim_current(&self) -> Option { + let Some(context) = self.current_context() else { + warn!( + "PLIC supervisor context for logical CPU {} is not found", + someboot::smp::cpu_idx() + ); + return None; + }; + let Some(source) = self.inner.claim(context) else { + debug!("Spurious external IRQ"); + return None; + }; + Some(source) + } + + fn complete_current(&self, source: NonZeroU32) { + let Some(context) = self.current_context() else { + warn!( + "PLIC supervisor context for logical CPU {} is not found", + someboot::smp::cpu_idx() + ); + return; + }; + self.inner.complete(context, source); + } +} + +impl RiscvPlic { fn enable_source(&mut self, source: NonZeroU32) { if source.get() as usize > self.sources { warn!("skip enabling out-of-range PLIC source {}", source.get()); return; } self.inner.set_priority(source, DEFAULT_PRIORITY); - let current = self.current_context(); + let current = current_context(&self.context_by_cpu); for context in self.context_by_cpu.iter().filter_map(|context| *context) { self.inner.enable(source, context); } @@ -275,30 +336,31 @@ impl RiscvPlic { self.inner.disable(source, context); } } - - fn handle_external_irq(&mut self) -> Option { - let context = self.current_context()?; - let Some(source) = self.inner.claim(context) else { - debug!("Spurious external IRQ"); - return None; - }; - let irq = someboot::irq::IrqId::new(source.get() as usize); - _handle_irq(irq.raw().into()); - self.inner.complete(context, source); - Some(irq) - } } -struct RiscvPlicIntc; +fn current_context(context_by_cpu: &[Option]) -> Option { + let cpu_idx = someboot::smp::cpu_idx(); + context_by_cpu.get(cpu_idx).and_then(|ctx| *ctx) +} -impl DriverGeneric for RiscvPlicIntc { +impl DriverGeneric for RiscvPlic { fn name(&self) -> &str { "RISC-V PLIC" } } -impl Interface for RiscvPlicIntc { +impl Interface for RiscvPlic { fn setup_irq_by_fdt(&mut self, irq_prop: &[u32]) -> rdrive::IrqId { - (irq_prop.first().copied().unwrap_or(0) as usize).into() + let Some(source) = irq_prop.first().copied().map(|source| source as usize) else { + warn!("empty PLIC interrupt specifier"); + return 0usize.into(); + }; + if source > self.sources { + warn!( + "PLIC interrupt source {} exceeds riscv,ndev {}", + source, self.sources + ); + } + source.into() } } diff --git a/platform/somehal/src/driver.rs b/platform/somehal/src/driver.rs index 7cc021f467..0336f165c9 100644 --- a/platform/somehal/src/driver.rs +++ b/platform/somehal/src/driver.rs @@ -7,5 +7,17 @@ pub fn rdrive_setup() { addr: NonNull::new(addr).unwrap(), }) .unwrap(); + } else if let Some(rsdp) = someboot::rsdp_addr_phys() { + info!("Initializing rdrive with ACPI RSDP at {:#x}", rsdp); + if let Err(err) = rdrive::init(rdrive::Platform::Acpi(rdrive::probe::acpi::AcpiRoot { + rsdp, + })) { + warn!( + "failed to initialize rdrive with ACPI RSDP {:#x}: {:?}", + rsdp, err + ); + } + } else { + warn!("No FDT or ACPI RSDP found; skip rdrive initialization"); } } diff --git a/platform/x86-qemu-q35/Cargo.toml b/platform/x86-qemu-q35/Cargo.toml index 9f840eadb3..1c8ffb962c 100644 --- a/platform/x86-qemu-q35/Cargo.toml +++ b/platform/x86-qemu-q35/Cargo.toml @@ -26,7 +26,7 @@ smp = ["ax-plat/smp", "ax-kspin/smp"] [target.'cfg(target_arch = "x86_64")'.dependencies] ax-config-macros = { workspace = true } ax-cpu = { workspace = true, features = ["arm-el2"] } -ax-driver = { workspace = true, features = ["pci"] } +ax-driver = { workspace = true, features = ["plat-static"] } ax-plat.workspace = true axklib.workspace = true bitflags = "2.6" diff --git a/scripts/axbuild/src/arceos/cbuild.rs b/scripts/axbuild/src/arceos/cbuild.rs index a432758f7f..cb38846663 100644 --- a/scripts/axbuild/src/arceos/cbuild.rs +++ b/scripts/axbuild/src/arceos/cbuild.rs @@ -418,7 +418,7 @@ mod tests { let features = c_config_features(&strings(&[ "ax-libc/net", "ax-feat/paging", - "ax-driver/pci", + "ax-driver/plat-static", "ax-driver/virtio-net", "ax-hal/riscv64-qemu-virt", "some-crate/feature", @@ -433,13 +433,13 @@ mod tests { #[test] fn map_c_app_features_preserves_driver_features() { let features = map_c_app_features( - &strings(&["net", "ax-driver/pci", "ax-driver/virtio-net"]), + &strings(&["net", "ax-driver/plat-static", "ax-driver/virtio-net"]), &strings(&["ax-hal/riscv64-qemu-virt"]), ); assert!(features.contains(&"ax-libc/net".to_string())); assert!(features.contains(&"ax-libc/fd".to_string())); - assert!(features.contains(&"ax-driver/pci".to_string())); + assert!(features.contains(&"ax-driver/plat-static".to_string())); assert!(features.contains(&"ax-driver/virtio-net".to_string())); assert!(features.contains(&"ax-hal/riscv64-qemu-virt".to_string())); } diff --git a/scripts/axbuild/src/axvisor/build.rs b/scripts/axbuild/src/axvisor/build.rs index f09c126e01..a73c5f866f 100644 --- a/scripts/axbuild/src/axvisor/build.rs +++ b/scripts/axbuild/src/axvisor/build.rs @@ -398,7 +398,7 @@ mod tests { r#" env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } target = "aarch64-unknown-none-softfloat" -features = ["ept-level-4", "ax-driver/fdt"] +features = ["ept-level-4", "ax-driver/plat-dyn"] log = "Info" plat_dyn = true vm_configs = [] @@ -413,7 +413,7 @@ vm_configs = [] .unwrap(); assert!(cargo.features.contains(&"ept-level-4".to_string())); - assert!(cargo.features.contains(&"ax-driver/fdt".to_string())); + assert!(cargo.features.contains(&"ax-driver/plat-dyn".to_string())); assert!(path.exists()); } @@ -600,7 +600,7 @@ plat_dyn = false &config_path, r#" env = {} -features = ["ept-level-4", "ax-driver/fdt"] +features = ["ept-level-4", "ax-driver/plat-dyn"] log = "Info" "#, ) diff --git a/scripts/axbuild/src/build.rs b/scripts/axbuild/src/build.rs index 460590d65a..b9b9ff25d9 100644 --- a/scripts/axbuild/src/build.rs +++ b/scripts/axbuild/src/build.rs @@ -1367,7 +1367,7 @@ mod tests { let mut envs = HashMap::new(); let mut features = vec![ "ax-hal/riscv64-qemu-virt".to_string(), - "ax-driver/pci".to_string(), + "ax-driver/plat-dyn".to_string(), "ax-driver/virtio-blk".to_string(), "ax-driver/virtio-net".to_string(), "dns".to_string(), @@ -1379,7 +1379,8 @@ mod tests { assert_eq!( envs.get("ARCEOS_RUST_FEATURES"), Some( - &"ax-hal/riscv64-qemu-virt,ax-driver/pci,ax-driver/virtio-blk,ax-driver/virtio-net" + &"ax-hal/riscv64-qemu-virt,ax-driver/plat-dyn,ax-driver/virtio-blk,ax-driver/\ + virtio-net" .to_string() ) ); diff --git a/test-suit/arceos/c/httpclient/build-aarch64-unknown-none-softfloat.toml b/test-suit/arceos/c/httpclient/build-aarch64-unknown-none-softfloat.toml index df8bbaf350..09a79b30c2 100644 --- a/test-suit/arceos/c/httpclient/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/arceos/c/httpclient/build-aarch64-unknown-none-softfloat.toml @@ -1,4 +1,4 @@ -features = ["alloc", "paging", "net", "ax-driver/pci", "ax-driver/virtio-net"] +features = ["alloc", "paging", "net", "ax-driver/plat-static", "ax-driver/virtio-net"] log = "Info" [env] diff --git a/test-suit/arceos/c/httpclient/build-loongarch64-unknown-none-softfloat.toml b/test-suit/arceos/c/httpclient/build-loongarch64-unknown-none-softfloat.toml index df8bbaf350..09a79b30c2 100644 --- a/test-suit/arceos/c/httpclient/build-loongarch64-unknown-none-softfloat.toml +++ b/test-suit/arceos/c/httpclient/build-loongarch64-unknown-none-softfloat.toml @@ -1,4 +1,4 @@ -features = ["alloc", "paging", "net", "ax-driver/pci", "ax-driver/virtio-net"] +features = ["alloc", "paging", "net", "ax-driver/plat-static", "ax-driver/virtio-net"] log = "Info" [env] diff --git a/test-suit/arceos/c/httpclient/build-riscv64gc-unknown-none-elf.toml b/test-suit/arceos/c/httpclient/build-riscv64gc-unknown-none-elf.toml index df8bbaf350..09a79b30c2 100644 --- a/test-suit/arceos/c/httpclient/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/arceos/c/httpclient/build-riscv64gc-unknown-none-elf.toml @@ -1,4 +1,4 @@ -features = ["alloc", "paging", "net", "ax-driver/pci", "ax-driver/virtio-net"] +features = ["alloc", "paging", "net", "ax-driver/plat-static", "ax-driver/virtio-net"] log = "Info" [env] diff --git a/test-suit/arceos/c/httpclient/build-x86_64-unknown-none.toml b/test-suit/arceos/c/httpclient/build-x86_64-unknown-none.toml index df8bbaf350..09a79b30c2 100644 --- a/test-suit/arceos/c/httpclient/build-x86_64-unknown-none.toml +++ b/test-suit/arceos/c/httpclient/build-x86_64-unknown-none.toml @@ -1,4 +1,4 @@ -features = ["alloc", "paging", "net", "ax-driver/pci", "ax-driver/virtio-net"] +features = ["alloc", "paging", "net", "ax-driver/plat-static", "ax-driver/virtio-net"] log = "Info" [env] diff --git a/test-suit/arceos/rust/display/build-aarch64-unknown-none-softfloat.toml b/test-suit/arceos/rust/display/build-aarch64-unknown-none-softfloat.toml index eda3a4a847..d50567d1c3 100644 --- a/test-suit/arceos/rust/display/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/arceos/rust/display/build-aarch64-unknown-none-softfloat.toml @@ -1,4 +1,4 @@ -features = ["ax-std", "ax-hal/aarch64-qemu-virt", "ax-driver/pci", "ax-driver/virtio-gpu"] +features = ["ax-std", "ax-hal/aarch64-qemu-virt", "ax-driver/plat-static", "ax-driver/virtio-gpu"] log = "Warn" max_cpu_num = 4 diff --git a/test-suit/arceos/rust/display/build-loongarch64-unknown-none-softfloat.toml b/test-suit/arceos/rust/display/build-loongarch64-unknown-none-softfloat.toml index 92f3749d99..4404257456 100644 --- a/test-suit/arceos/rust/display/build-loongarch64-unknown-none-softfloat.toml +++ b/test-suit/arceos/rust/display/build-loongarch64-unknown-none-softfloat.toml @@ -1,4 +1,4 @@ -features = ["ax-std", "ax-hal/loongarch64-qemu-virt", "ax-driver/pci", "ax-driver/virtio-gpu"] +features = ["ax-std", "ax-hal/loongarch64-qemu-virt", "ax-driver/plat-static", "ax-driver/virtio-gpu"] log = "Warn" max_cpu_num = 4 diff --git a/test-suit/arceos/rust/display/build-riscv64gc-unknown-none-elf.toml b/test-suit/arceos/rust/display/build-riscv64gc-unknown-none-elf.toml index d490390524..e71ba13870 100644 --- a/test-suit/arceos/rust/display/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/arceos/rust/display/build-riscv64gc-unknown-none-elf.toml @@ -1,4 +1,4 @@ -features = ["ax-std", "ax-hal/riscv64-qemu-virt", "ax-driver/pci", "ax-driver/virtio-gpu"] +features = ["ax-std", "ax-hal/riscv64-qemu-virt", "ax-driver/plat-static", "ax-driver/virtio-gpu"] log = "Warn" max_cpu_num = 4 diff --git a/test-suit/arceos/rust/display/build-x86_64-unknown-none.toml b/test-suit/arceos/rust/display/build-x86_64-unknown-none.toml index 4a36bd895c..22ce22029f 100644 --- a/test-suit/arceos/rust/display/build-x86_64-unknown-none.toml +++ b/test-suit/arceos/rust/display/build-x86_64-unknown-none.toml @@ -1,4 +1,4 @@ -features = ["ax-std", "ax-hal/x86-pc", "ax-driver/pci", "ax-driver/virtio-gpu"] +features = ["ax-std", "ax-hal/x86-pc", "ax-driver/plat-static", "ax-driver/virtio-gpu"] log = "Warn" max_cpu_num = 4 diff --git a/test-suit/arceos/rust/fs/shell/build-aarch64-unknown-none-softfloat.toml b/test-suit/arceos/rust/fs/shell/build-aarch64-unknown-none-softfloat.toml index 928217c53f..772b5e3785 100644 --- a/test-suit/arceos/rust/fs/shell/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/arceos/rust/fs/shell/build-aarch64-unknown-none-softfloat.toml @@ -1,4 +1,4 @@ -features = ["ax-std", "ax-hal/aarch64-qemu-virt", "ax-driver/virtio-blk"] +features = ["ax-std", "ax-hal/aarch64-qemu-virt", "ax-driver/plat-static", "ax-driver/virtio-blk"] log = "Warn" max_cpu_num = 4 diff --git a/test-suit/arceos/rust/fs/shell/build-loongarch64-unknown-none-softfloat.toml b/test-suit/arceos/rust/fs/shell/build-loongarch64-unknown-none-softfloat.toml index 3f3e37f2da..356b482ab5 100644 --- a/test-suit/arceos/rust/fs/shell/build-loongarch64-unknown-none-softfloat.toml +++ b/test-suit/arceos/rust/fs/shell/build-loongarch64-unknown-none-softfloat.toml @@ -1,4 +1,4 @@ -features = ["ax-std", "ax-hal/loongarch64-qemu-virt", "ax-driver/pci", "ax-driver/virtio-blk"] +features = ["ax-std", "ax-hal/loongarch64-qemu-virt", "ax-driver/plat-static", "ax-driver/virtio-blk"] log = "Warn" max_cpu_num = 4 diff --git a/test-suit/arceos/rust/fs/shell/build-riscv64gc-unknown-none-elf.toml b/test-suit/arceos/rust/fs/shell/build-riscv64gc-unknown-none-elf.toml index 1f6cd09f11..9b91c050c3 100644 --- a/test-suit/arceos/rust/fs/shell/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/arceos/rust/fs/shell/build-riscv64gc-unknown-none-elf.toml @@ -1,4 +1,4 @@ -features = ["ax-std", "ax-hal/riscv64-qemu-virt", "ax-driver/pci", "ax-driver/virtio-blk"] +features = ["ax-std", "ax-hal/riscv64-qemu-virt", "ax-driver/plat-static", "ax-driver/virtio-blk"] log = "Warn" max_cpu_num = 4 diff --git a/test-suit/arceos/rust/fs/shell/build-x86_64-unknown-none.toml b/test-suit/arceos/rust/fs/shell/build-x86_64-unknown-none.toml index 9b12da4c8d..4c89f16752 100644 --- a/test-suit/arceos/rust/fs/shell/build-x86_64-unknown-none.toml +++ b/test-suit/arceos/rust/fs/shell/build-x86_64-unknown-none.toml @@ -1,4 +1,4 @@ -features = ["ax-std", "ax-hal/x86-pc", "ax-driver/pci", "ax-driver/virtio-blk"] +features = ["ax-std", "ax-hal/x86-pc", "ax-driver/plat-static", "ax-driver/virtio-blk"] log = "Warn" max_cpu_num = 4 diff --git a/test-suit/arceos/rust/net/echoserver/build-aarch64-unknown-none-softfloat.toml b/test-suit/arceos/rust/net/echoserver/build-aarch64-unknown-none-softfloat.toml index 702f89231d..d885073496 100644 --- a/test-suit/arceos/rust/net/echoserver/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/arceos/rust/net/echoserver/build-aarch64-unknown-none-softfloat.toml @@ -1,4 +1,4 @@ -features = ["ax-std", "ax-hal/aarch64-qemu-virt", "ax-driver/pci", "ax-driver/virtio-net"] +features = ["ax-std", "ax-hal/aarch64-qemu-virt", "ax-driver/plat-static", "ax-driver/virtio-net"] log = "Warn" max_cpu_num = 4 plat_dyn = false diff --git a/test-suit/arceos/rust/net/echoserver/build-loongarch64-unknown-none-softfloat.toml b/test-suit/arceos/rust/net/echoserver/build-loongarch64-unknown-none-softfloat.toml index 90c976edd0..71b6acb4b4 100644 --- a/test-suit/arceos/rust/net/echoserver/build-loongarch64-unknown-none-softfloat.toml +++ b/test-suit/arceos/rust/net/echoserver/build-loongarch64-unknown-none-softfloat.toml @@ -1,4 +1,4 @@ -features = ["ax-std", "ax-hal/loongarch64-qemu-virt", "ax-driver/pci", "ax-driver/virtio-net"] +features = ["ax-std", "ax-hal/loongarch64-qemu-virt", "ax-driver/plat-static", "ax-driver/virtio-net"] log = "Warn" max_cpu_num = 4 diff --git a/test-suit/arceos/rust/net/echoserver/build-riscv64gc-unknown-none-elf.toml b/test-suit/arceos/rust/net/echoserver/build-riscv64gc-unknown-none-elf.toml index 5187b10d7a..62722e59d6 100644 --- a/test-suit/arceos/rust/net/echoserver/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/arceos/rust/net/echoserver/build-riscv64gc-unknown-none-elf.toml @@ -1,4 +1,4 @@ -features = ["ax-std", "ax-hal/riscv64-qemu-virt", "ax-driver/pci", "ax-driver/virtio-net"] +features = ["ax-std", "ax-hal/riscv64-qemu-virt", "ax-driver/plat-static", "ax-driver/virtio-net"] log = "Warn" max_cpu_num = 4 diff --git a/test-suit/arceos/rust/net/echoserver/build-x86_64-unknown-none.toml b/test-suit/arceos/rust/net/echoserver/build-x86_64-unknown-none.toml index 47ca5d96c6..eff1acc096 100644 --- a/test-suit/arceos/rust/net/echoserver/build-x86_64-unknown-none.toml +++ b/test-suit/arceos/rust/net/echoserver/build-x86_64-unknown-none.toml @@ -1,4 +1,4 @@ -features = ["ax-std", "ax-hal/x86-pc", "ax-driver/pci", "ax-driver/virtio-net"] +features = ["ax-std", "ax-hal/x86-pc", "ax-driver/plat-static", "ax-driver/virtio-net"] log = "Warn" max_cpu_num = 4 diff --git a/test-suit/arceos/rust/net/httpclient/build-aarch64-unknown-none-softfloat.toml b/test-suit/arceos/rust/net/httpclient/build-aarch64-unknown-none-softfloat.toml index fa1c413f97..3b6c8c9826 100644 --- a/test-suit/arceos/rust/net/httpclient/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/arceos/rust/net/httpclient/build-aarch64-unknown-none-softfloat.toml @@ -1,4 +1,4 @@ -features = ["ax-std", "ax-hal/plat-dyn", "ax-driver/virtio-net"] +features = ["ax-std", "ax-hal/plat-dyn", "ax-driver/plat-dyn", "ax-driver/virtio-net"] log = "Warn" max_cpu_num = 4 plat_dyn = true diff --git a/test-suit/arceos/rust/net/httpclient/build-loongarch64-unknown-none-softfloat.toml b/test-suit/arceos/rust/net/httpclient/build-loongarch64-unknown-none-softfloat.toml index 610dc403ec..0e39320b3d 100644 --- a/test-suit/arceos/rust/net/httpclient/build-loongarch64-unknown-none-softfloat.toml +++ b/test-suit/arceos/rust/net/httpclient/build-loongarch64-unknown-none-softfloat.toml @@ -1,4 +1,4 @@ -features = ["ax-std", "ax-hal/loongarch64-qemu-virt", "ax-driver/pci", "ax-driver/virtio-net"] +features = ["ax-std", "ax-hal/loongarch64-qemu-virt", "ax-driver/plat-static", "ax-driver/virtio-net"] log = "Warn" max_cpu_num = 4 diff --git a/test-suit/arceos/rust/net/httpclient/build-riscv64gc-unknown-none-elf.toml b/test-suit/arceos/rust/net/httpclient/build-riscv64gc-unknown-none-elf.toml index ee9b43a5d6..d19a749068 100644 --- a/test-suit/arceos/rust/net/httpclient/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/arceos/rust/net/httpclient/build-riscv64gc-unknown-none-elf.toml @@ -1,4 +1,4 @@ -features = ["ax-std", "ax-hal/riscv64-qemu-virt", "ax-driver/pci", "ax-driver/virtio-net"] +features = ["ax-std", "ax-hal/riscv64-qemu-virt", "ax-driver/plat-static", "ax-driver/virtio-net"] log = "Warn" max_cpu_num = 4 diff --git a/test-suit/arceos/rust/net/httpclient/build-x86_64-unknown-none.toml b/test-suit/arceos/rust/net/httpclient/build-x86_64-unknown-none.toml index 47ca5d96c6..eff1acc096 100644 --- a/test-suit/arceos/rust/net/httpclient/build-x86_64-unknown-none.toml +++ b/test-suit/arceos/rust/net/httpclient/build-x86_64-unknown-none.toml @@ -1,4 +1,4 @@ -features = ["ax-std", "ax-hal/x86-pc", "ax-driver/pci", "ax-driver/virtio-net"] +features = ["ax-std", "ax-hal/x86-pc", "ax-driver/plat-static", "ax-driver/virtio-net"] log = "Warn" max_cpu_num = 4 diff --git a/test-suit/arceos/rust/net/httpserver/build-aarch64-unknown-none-softfloat.toml b/test-suit/arceos/rust/net/httpserver/build-aarch64-unknown-none-softfloat.toml index 702f89231d..d885073496 100644 --- a/test-suit/arceos/rust/net/httpserver/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/arceos/rust/net/httpserver/build-aarch64-unknown-none-softfloat.toml @@ -1,4 +1,4 @@ -features = ["ax-std", "ax-hal/aarch64-qemu-virt", "ax-driver/pci", "ax-driver/virtio-net"] +features = ["ax-std", "ax-hal/aarch64-qemu-virt", "ax-driver/plat-static", "ax-driver/virtio-net"] log = "Warn" max_cpu_num = 4 plat_dyn = false diff --git a/test-suit/arceos/rust/net/httpserver/build-loongarch64-unknown-none-softfloat.toml b/test-suit/arceos/rust/net/httpserver/build-loongarch64-unknown-none-softfloat.toml index 90c976edd0..71b6acb4b4 100644 --- a/test-suit/arceos/rust/net/httpserver/build-loongarch64-unknown-none-softfloat.toml +++ b/test-suit/arceos/rust/net/httpserver/build-loongarch64-unknown-none-softfloat.toml @@ -1,4 +1,4 @@ -features = ["ax-std", "ax-hal/loongarch64-qemu-virt", "ax-driver/pci", "ax-driver/virtio-net"] +features = ["ax-std", "ax-hal/loongarch64-qemu-virt", "ax-driver/plat-static", "ax-driver/virtio-net"] log = "Warn" max_cpu_num = 4 diff --git a/test-suit/arceos/rust/net/httpserver/build-riscv64gc-unknown-none-elf.toml b/test-suit/arceos/rust/net/httpserver/build-riscv64gc-unknown-none-elf.toml index 5187b10d7a..62722e59d6 100644 --- a/test-suit/arceos/rust/net/httpserver/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/arceos/rust/net/httpserver/build-riscv64gc-unknown-none-elf.toml @@ -1,4 +1,4 @@ -features = ["ax-std", "ax-hal/riscv64-qemu-virt", "ax-driver/pci", "ax-driver/virtio-net"] +features = ["ax-std", "ax-hal/riscv64-qemu-virt", "ax-driver/plat-static", "ax-driver/virtio-net"] log = "Warn" max_cpu_num = 4 diff --git a/test-suit/arceos/rust/net/httpserver/build-x86_64-unknown-none.toml b/test-suit/arceos/rust/net/httpserver/build-x86_64-unknown-none.toml index 47ca5d96c6..eff1acc096 100644 --- a/test-suit/arceos/rust/net/httpserver/build-x86_64-unknown-none.toml +++ b/test-suit/arceos/rust/net/httpserver/build-x86_64-unknown-none.toml @@ -1,4 +1,4 @@ -features = ["ax-std", "ax-hal/x86-pc", "ax-driver/pci", "ax-driver/virtio-net"] +features = ["ax-std", "ax-hal/x86-pc", "ax-driver/plat-static", "ax-driver/virtio-net"] log = "Warn" max_cpu_num = 4 diff --git a/test-suit/arceos/rust/net/udpserver/build-aarch64-unknown-none-softfloat.toml b/test-suit/arceos/rust/net/udpserver/build-aarch64-unknown-none-softfloat.toml index 702f89231d..d885073496 100644 --- a/test-suit/arceos/rust/net/udpserver/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/arceos/rust/net/udpserver/build-aarch64-unknown-none-softfloat.toml @@ -1,4 +1,4 @@ -features = ["ax-std", "ax-hal/aarch64-qemu-virt", "ax-driver/pci", "ax-driver/virtio-net"] +features = ["ax-std", "ax-hal/aarch64-qemu-virt", "ax-driver/plat-static", "ax-driver/virtio-net"] log = "Warn" max_cpu_num = 4 plat_dyn = false diff --git a/test-suit/arceos/rust/net/udpserver/build-loongarch64-unknown-none-softfloat.toml b/test-suit/arceos/rust/net/udpserver/build-loongarch64-unknown-none-softfloat.toml index 90c976edd0..71b6acb4b4 100644 --- a/test-suit/arceos/rust/net/udpserver/build-loongarch64-unknown-none-softfloat.toml +++ b/test-suit/arceos/rust/net/udpserver/build-loongarch64-unknown-none-softfloat.toml @@ -1,4 +1,4 @@ -features = ["ax-std", "ax-hal/loongarch64-qemu-virt", "ax-driver/pci", "ax-driver/virtio-net"] +features = ["ax-std", "ax-hal/loongarch64-qemu-virt", "ax-driver/plat-static", "ax-driver/virtio-net"] log = "Warn" max_cpu_num = 4 diff --git a/test-suit/arceos/rust/net/udpserver/build-riscv64gc-unknown-none-elf.toml b/test-suit/arceos/rust/net/udpserver/build-riscv64gc-unknown-none-elf.toml index 5187b10d7a..62722e59d6 100644 --- a/test-suit/arceos/rust/net/udpserver/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/arceos/rust/net/udpserver/build-riscv64gc-unknown-none-elf.toml @@ -1,4 +1,4 @@ -features = ["ax-std", "ax-hal/riscv64-qemu-virt", "ax-driver/pci", "ax-driver/virtio-net"] +features = ["ax-std", "ax-hal/riscv64-qemu-virt", "ax-driver/plat-static", "ax-driver/virtio-net"] log = "Warn" max_cpu_num = 4 diff --git a/test-suit/arceos/rust/net/udpserver/build-x86_64-unknown-none.toml b/test-suit/arceos/rust/net/udpserver/build-x86_64-unknown-none.toml index 47ca5d96c6..eff1acc096 100644 --- a/test-suit/arceos/rust/net/udpserver/build-x86_64-unknown-none.toml +++ b/test-suit/arceos/rust/net/udpserver/build-x86_64-unknown-none.toml @@ -1,4 +1,4 @@ -features = ["ax-std", "ax-hal/x86-pc", "ax-driver/pci", "ax-driver/virtio-net"] +features = ["ax-std", "ax-hal/x86-pc", "ax-driver/plat-static", "ax-driver/virtio-net"] log = "Warn" max_cpu_num = 4 diff --git a/test-suit/axvisor/normal/board-orangepi-5-plus/build-aarch64-unknown-none-softfloat.toml b/test-suit/axvisor/normal/board-orangepi-5-plus/build-aarch64-unknown-none-softfloat.toml index 5ad4b8a556..f290c11f18 100644 --- a/test-suit/axvisor/normal/board-orangepi-5-plus/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/axvisor/normal/board-orangepi-5-plus/build-aarch64-unknown-none-softfloat.toml @@ -1,5 +1,6 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ + "ax-driver/plat-dyn", "sdmmc", "rockchip-soc", "fs", diff --git a/test-suit/axvisor/normal/board-phytiumpi/build-aarch64-unknown-none-softfloat.toml b/test-suit/axvisor/normal/board-phytiumpi/build-aarch64-unknown-none-softfloat.toml index c460cd1906..820dca9115 100644 --- a/test-suit/axvisor/normal/board-phytiumpi/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/axvisor/normal/board-phytiumpi/build-aarch64-unknown-none-softfloat.toml @@ -1,5 +1,6 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ + "ax-driver/plat-dyn", "fs", "phytium-mci", ] diff --git a/test-suit/axvisor/normal/board-rdk-s100/build-aarch64-unknown-none-softfloat.toml b/test-suit/axvisor/normal/board-rdk-s100/build-aarch64-unknown-none-softfloat.toml index 3744939244..726844440c 100644 --- a/test-suit/axvisor/normal/board-rdk-s100/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/axvisor/normal/board-rdk-s100/build-aarch64-unknown-none-softfloat.toml @@ -1,5 +1,6 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ + "ax-driver/plat-dyn", "ax-hal/plat-dyn", "ept-level-4", ] diff --git a/test-suit/axvisor/normal/board-roc-rk3568-pc/build-aarch64-unknown-none-softfloat.toml b/test-suit/axvisor/normal/board-roc-rk3568-pc/build-aarch64-unknown-none-softfloat.toml index 722f81a042..6dd9b0de34 100644 --- a/test-suit/axvisor/normal/board-roc-rk3568-pc/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/axvisor/normal/board-roc-rk3568-pc/build-aarch64-unknown-none-softfloat.toml @@ -1,5 +1,6 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ + "ax-driver/plat-dyn", "rockchip-sdhci", "rockchip-soc", "fs", diff --git a/test-suit/axvisor/normal/qemu/build-aarch64-unknown-none-softfloat.toml b/test-suit/axvisor/normal/qemu/build-aarch64-unknown-none-softfloat.toml index 85565cb686..4a244cd393 100644 --- a/test-suit/axvisor/normal/qemu/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/axvisor/normal/qemu/build-aarch64-unknown-none-softfloat.toml @@ -1,5 +1,6 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ + "ax-driver/plat-dyn", "ax-hal/plat-dyn", "ept-level-4", "ax-driver/virtio-blk", diff --git a/test-suit/axvisor/normal/qemu/build-loongarch64-unknown-none-softfloat.toml b/test-suit/axvisor/normal/qemu/build-loongarch64-unknown-none-softfloat.toml index d16951f9f4..1e7fa7e04b 100644 --- a/test-suit/axvisor/normal/qemu/build-loongarch64-unknown-none-softfloat.toml +++ b/test-suit/axvisor/normal/qemu/build-loongarch64-unknown-none-softfloat.toml @@ -1,7 +1,7 @@ env = {AX_IP = "10.0.2.15", AX_GW = "10.0.2.2"} features = [ "ax-driver/virtio-blk", - "ax-driver/pci", + "ax-driver/plat-static", "ept-level-4", "fs", ] diff --git a/test-suit/axvisor/normal/qemu/build-riscv64gc-unknown-none-elf.toml b/test-suit/axvisor/normal/qemu/build-riscv64gc-unknown-none-elf.toml index 1b626039e3..251cc12f51 100644 --- a/test-suit/axvisor/normal/qemu/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/axvisor/normal/qemu/build-riscv64gc-unknown-none-elf.toml @@ -2,7 +2,7 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ "dyn-plat", "ax-hal/plat-dyn", - "ax-driver/fdt", + "ax-driver/plat-dyn", "ax-driver/virtio-blk", "ept-level-4", "fs", diff --git a/test-suit/axvisor/normal/qemu/build-x86_64-unknown-none.toml b/test-suit/axvisor/normal/qemu/build-x86_64-unknown-none.toml index fccc9c223a..96a1fc057a 100644 --- a/test-suit/axvisor/normal/qemu/build-x86_64-unknown-none.toml +++ b/test-suit/axvisor/normal/qemu/build-x86_64-unknown-none.toml @@ -1,7 +1,7 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ "ax-driver/virtio-blk", - "ax-driver/pci", + "ax-driver/plat-static", "ept-level-4", "fs", "vmx", diff --git a/test-suit/axvisor/svm/qemu/build-x86_64-unknown-none.toml b/test-suit/axvisor/svm/qemu/build-x86_64-unknown-none.toml index 832d68593f..c160743f7c 100644 --- a/test-suit/axvisor/svm/qemu/build-x86_64-unknown-none.toml +++ b/test-suit/axvisor/svm/qemu/build-x86_64-unknown-none.toml @@ -1,7 +1,7 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ "ax-driver/virtio-blk", - "ax-driver/pci", + "ax-driver/plat-static", "ept-level-4", "fs", "svm", diff --git a/test-suit/starryos/aarch64-hvf/test-aarch64-gicv3-smoke/build-aarch64-unknown-none-softfloat.toml b/test-suit/starryos/aarch64-hvf/test-aarch64-gicv3-smoke/build-aarch64-unknown-none-softfloat.toml index 8255f9fe7d..2bdb5fcd87 100644 --- a/test-suit/starryos/aarch64-hvf/test-aarch64-gicv3-smoke/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/starryos/aarch64-hvf/test-aarch64-gicv3-smoke/build-aarch64-unknown-none-softfloat.toml @@ -3,7 +3,7 @@ features = [ "ax-hal/plat-dyn", "ax-feat/display", "ax-feat/rtc", - "ax-driver/pci", + "ax-driver/plat-dyn", "ax-driver/rtc", "ax-driver/virtio-blk", "ax-driver/virtio-net", diff --git a/test-suit/starryos/normal/board-licheerv-nano-sg2002/build-riscv64gc-unknown-none-elf.toml b/test-suit/starryos/normal/board-licheerv-nano-sg2002/build-riscv64gc-unknown-none-elf.toml index 0151ef9647..52274b55b9 100644 --- a/test-suit/starryos/normal/board-licheerv-nano-sg2002/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/starryos/normal/board-licheerv-nano-sg2002/build-riscv64gc-unknown-none-elf.toml @@ -2,6 +2,7 @@ target = "riscv64gc-unknown-none-elf" env = {} features = [ + "ax-driver/plat-dyn", "sg2002-dyn", "ax-feat/plat-dyn", "ax-driver/cvsd", diff --git a/test-suit/starryos/normal/board-orangepi-5-plus/build-aarch64-unknown-none-softfloat.toml b/test-suit/starryos/normal/board-orangepi-5-plus/build-aarch64-unknown-none-softfloat.toml index 5ca9f332f2..e900e7c3ac 100644 --- a/test-suit/starryos/normal/board-orangepi-5-plus/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/starryos/normal/board-orangepi-5-plus/build-aarch64-unknown-none-softfloat.toml @@ -3,9 +3,10 @@ target = "aarch64-unknown-none-softfloat" # Runtime U-Boot settings live in `orangepi-5-plus-uboot.toml`. env = {} features = [ + "ax-driver/plat-dyn", "ax-hal/plat-dyn", "starry-kernel/plat-dyn", - "ax-driver/pci-list-devices", + "ax-driver/list-pci-devices", "ax-driver/rk3588-pcie", "ax-driver/realtek-rtl8125", "ax-driver/rockchip-soc", diff --git a/test-suit/starryos/normal/qemu-aarch64-plat-dyn/build-aarch64-unknown-none-softfloat.toml b/test-suit/starryos/normal/qemu-aarch64-plat-dyn/build-aarch64-unknown-none-softfloat.toml index 3069e0b191..2293a4dd31 100644 --- a/test-suit/starryos/normal/qemu-aarch64-plat-dyn/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/starryos/normal/qemu-aarch64-plat-dyn/build-aarch64-unknown-none-softfloat.toml @@ -1,5 +1,6 @@ env = {} features = [ + "ax-driver/plat-dyn", "ax-hal/plat-dyn", "ax-feat/rtc", "ax-driver/rtc", diff --git a/test-suit/starryos/normal/qemu-dhcp/build-x86_64-unknown-none.toml b/test-suit/starryos/normal/qemu-dhcp/build-x86_64-unknown-none.toml index 7efd9aa1bd..1128aa2eb9 100644 --- a/test-suit/starryos/normal/qemu-dhcp/build-x86_64-unknown-none.toml +++ b/test-suit/starryos/normal/qemu-dhcp/build-x86_64-unknown-none.toml @@ -4,7 +4,7 @@ log = "Warn" features = [ "ax-hal/x86-pc", "qemu", - "ax-driver/pci", + "ax-driver/plat-static", "ax-driver/virtio-blk", "ax-driver/virtio-net", "ax-driver/virtio-gpu", diff --git a/test-suit/starryos/normal/qemu-smp1/build-aarch64-unknown-none-softfloat.toml b/test-suit/starryos/normal/qemu-smp1/build-aarch64-unknown-none-softfloat.toml index 857f3a3dbd..6791ff12d1 100644 --- a/test-suit/starryos/normal/qemu-smp1/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/starryos/normal/qemu-smp1/build-aarch64-unknown-none-softfloat.toml @@ -3,7 +3,7 @@ features = [ "ax-hal/plat-dyn", "ax-feat/display", "ax-feat/rtc", - "ax-driver/pci", + "ax-driver/plat-dyn", "ax-driver/rtc", "ax-driver/virtio-blk", "ax-driver/virtio-net", diff --git a/test-suit/starryos/normal/qemu-smp1/build-loongarch64-unknown-none-softfloat.toml b/test-suit/starryos/normal/qemu-smp1/build-loongarch64-unknown-none-softfloat.toml index 0dc0ec2bb6..b6e12457d5 100644 --- a/test-suit/starryos/normal/qemu-smp1/build-loongarch64-unknown-none-softfloat.toml +++ b/test-suit/starryos/normal/qemu-smp1/build-loongarch64-unknown-none-softfloat.toml @@ -4,7 +4,7 @@ log = "Warn" features = [ "ax-hal/loongarch64-qemu-virt", "qemu", - "ax-driver/pci", + "ax-driver/plat-static", "ax-driver/virtio-blk", "ax-driver/virtio-net", "ax-driver/virtio-gpu", diff --git a/test-suit/starryos/normal/qemu-smp1/build-riscv64gc-unknown-none-elf.toml b/test-suit/starryos/normal/qemu-smp1/build-riscv64gc-unknown-none-elf.toml index a6eaa912c6..e1f84e80b1 100644 --- a/test-suit/starryos/normal/qemu-smp1/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/starryos/normal/qemu-smp1/build-riscv64gc-unknown-none-elf.toml @@ -2,7 +2,7 @@ env = {AX_IP = "10.0.2.15", AX_GW = "10.0.2.2"} features = [ "ax-feat/plat-dyn", "starry-kernel/plat-dyn", - "ax-driver/pci-fdt", + "ax-driver/plat-dyn", "ax-driver/serial", "ax-driver/virtio-blk", "ax-driver/virtio-net", diff --git a/test-suit/starryos/normal/qemu-smp1/build-x86_64-unknown-none.toml b/test-suit/starryos/normal/qemu-smp1/build-x86_64-unknown-none.toml index 94d8986bbb..48f79a5df5 100644 --- a/test-suit/starryos/normal/qemu-smp1/build-x86_64-unknown-none.toml +++ b/test-suit/starryos/normal/qemu-smp1/build-x86_64-unknown-none.toml @@ -4,7 +4,7 @@ log = "Warn" features = [ "ax-hal/x86-pc", "qemu", - "ax-driver/pci", + "ax-driver/plat-static", "ax-driver/virtio-blk", "ax-driver/virtio-net", "ax-driver/virtio-gpu", diff --git a/test-suit/starryos/normal/qemu-smp4/build-aarch64-unknown-none-softfloat.toml b/test-suit/starryos/normal/qemu-smp4/build-aarch64-unknown-none-softfloat.toml index 0cc1c3db01..b093f2f61e 100644 --- a/test-suit/starryos/normal/qemu-smp4/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/starryos/normal/qemu-smp4/build-aarch64-unknown-none-softfloat.toml @@ -3,7 +3,7 @@ features = [ "ax-hal/plat-dyn", "ax-feat/display", "ax-feat/rtc", - "ax-driver/pci", + "ax-driver/plat-dyn", "ax-driver/rtc", "ax-driver/virtio-blk", "ax-driver/virtio-net", diff --git a/test-suit/starryos/normal/qemu-smp4/build-loongarch64-unknown-none-softfloat.toml b/test-suit/starryos/normal/qemu-smp4/build-loongarch64-unknown-none-softfloat.toml index aea79288ad..fb74bee24c 100644 --- a/test-suit/starryos/normal/qemu-smp4/build-loongarch64-unknown-none-softfloat.toml +++ b/test-suit/starryos/normal/qemu-smp4/build-loongarch64-unknown-none-softfloat.toml @@ -4,7 +4,7 @@ log = "Warn" features = [ "ax-hal/loongarch64-qemu-virt", "qemu", - "ax-driver/pci", + "ax-driver/plat-static", "ax-driver/virtio-blk", "ax-driver/virtio-net", "ax-driver/virtio-gpu", diff --git a/test-suit/starryos/normal/qemu-smp4/build-riscv64gc-unknown-none-elf.toml b/test-suit/starryos/normal/qemu-smp4/build-riscv64gc-unknown-none-elf.toml index bf52f3db69..ad03a672b6 100644 --- a/test-suit/starryos/normal/qemu-smp4/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/starryos/normal/qemu-smp4/build-riscv64gc-unknown-none-elf.toml @@ -2,7 +2,7 @@ env = {AX_IP = "10.0.2.15", AX_GW = "10.0.2.2"} features = [ "ax-feat/plat-dyn", "starry-kernel/plat-dyn", - "ax-driver/pci-fdt", + "ax-driver/plat-dyn", "ax-driver/serial", "ax-driver/virtio-blk", "ax-driver/virtio-net", diff --git a/test-suit/starryos/normal/qemu-smp4/build-x86_64-unknown-none.toml b/test-suit/starryos/normal/qemu-smp4/build-x86_64-unknown-none.toml index 3f616671f3..415120f3e0 100644 --- a/test-suit/starryos/normal/qemu-smp4/build-x86_64-unknown-none.toml +++ b/test-suit/starryos/normal/qemu-smp4/build-x86_64-unknown-none.toml @@ -4,7 +4,7 @@ log = "Warn" features = [ "ax-hal/x86-pc", "qemu", - "ax-driver/pci", + "ax-driver/plat-static", "ax-driver/virtio-blk", "ax-driver/virtio-net", "ax-driver/virtio-gpu", diff --git a/test-suit/starryos/stress/postgresql/build-aarch64-unknown-none-softfloat.toml b/test-suit/starryos/stress/postgresql/build-aarch64-unknown-none-softfloat.toml index 857f3a3dbd..6791ff12d1 100644 --- a/test-suit/starryos/stress/postgresql/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/starryos/stress/postgresql/build-aarch64-unknown-none-softfloat.toml @@ -3,7 +3,7 @@ features = [ "ax-hal/plat-dyn", "ax-feat/display", "ax-feat/rtc", - "ax-driver/pci", + "ax-driver/plat-dyn", "ax-driver/rtc", "ax-driver/virtio-blk", "ax-driver/virtio-net", diff --git a/test-suit/starryos/stress/postgresql/build-loongarch64-unknown-none-softfloat.toml b/test-suit/starryos/stress/postgresql/build-loongarch64-unknown-none-softfloat.toml index 0dc0ec2bb6..b6e12457d5 100644 --- a/test-suit/starryos/stress/postgresql/build-loongarch64-unknown-none-softfloat.toml +++ b/test-suit/starryos/stress/postgresql/build-loongarch64-unknown-none-softfloat.toml @@ -4,7 +4,7 @@ log = "Warn" features = [ "ax-hal/loongarch64-qemu-virt", "qemu", - "ax-driver/pci", + "ax-driver/plat-static", "ax-driver/virtio-blk", "ax-driver/virtio-net", "ax-driver/virtio-gpu", diff --git a/test-suit/starryos/stress/postgresql/build-riscv64gc-unknown-none-elf.toml b/test-suit/starryos/stress/postgresql/build-riscv64gc-unknown-none-elf.toml index a6eaa912c6..e1f84e80b1 100644 --- a/test-suit/starryos/stress/postgresql/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/starryos/stress/postgresql/build-riscv64gc-unknown-none-elf.toml @@ -2,7 +2,7 @@ env = {AX_IP = "10.0.2.15", AX_GW = "10.0.2.2"} features = [ "ax-feat/plat-dyn", "starry-kernel/plat-dyn", - "ax-driver/pci-fdt", + "ax-driver/plat-dyn", "ax-driver/serial", "ax-driver/virtio-blk", "ax-driver/virtio-net", diff --git a/test-suit/starryos/stress/postgresql/build-x86_64-unknown-none.toml b/test-suit/starryos/stress/postgresql/build-x86_64-unknown-none.toml index 94d8986bbb..48f79a5df5 100644 --- a/test-suit/starryos/stress/postgresql/build-x86_64-unknown-none.toml +++ b/test-suit/starryos/stress/postgresql/build-x86_64-unknown-none.toml @@ -4,7 +4,7 @@ log = "Warn" features = [ "ax-hal/x86-pc", "qemu", - "ax-driver/pci", + "ax-driver/plat-static", "ax-driver/virtio-blk", "ax-driver/virtio-net", "ax-driver/virtio-gpu", diff --git a/test-suit/starryos/stress/stress-ng-0/build-aarch64-unknown-none-softfloat.toml b/test-suit/starryos/stress/stress-ng-0/build-aarch64-unknown-none-softfloat.toml index 857f3a3dbd..6791ff12d1 100644 --- a/test-suit/starryos/stress/stress-ng-0/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/starryos/stress/stress-ng-0/build-aarch64-unknown-none-softfloat.toml @@ -3,7 +3,7 @@ features = [ "ax-hal/plat-dyn", "ax-feat/display", "ax-feat/rtc", - "ax-driver/pci", + "ax-driver/plat-dyn", "ax-driver/rtc", "ax-driver/virtio-blk", "ax-driver/virtio-net", diff --git a/test-suit/starryos/stress/stress-ng-0/build-loongarch64-unknown-none-softfloat.toml b/test-suit/starryos/stress/stress-ng-0/build-loongarch64-unknown-none-softfloat.toml index 0dc0ec2bb6..b6e12457d5 100644 --- a/test-suit/starryos/stress/stress-ng-0/build-loongarch64-unknown-none-softfloat.toml +++ b/test-suit/starryos/stress/stress-ng-0/build-loongarch64-unknown-none-softfloat.toml @@ -4,7 +4,7 @@ log = "Warn" features = [ "ax-hal/loongarch64-qemu-virt", "qemu", - "ax-driver/pci", + "ax-driver/plat-static", "ax-driver/virtio-blk", "ax-driver/virtio-net", "ax-driver/virtio-gpu", diff --git a/test-suit/starryos/stress/stress-ng-0/build-riscv64gc-unknown-none-elf.toml b/test-suit/starryos/stress/stress-ng-0/build-riscv64gc-unknown-none-elf.toml index a6eaa912c6..e1f84e80b1 100644 --- a/test-suit/starryos/stress/stress-ng-0/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/starryos/stress/stress-ng-0/build-riscv64gc-unknown-none-elf.toml @@ -2,7 +2,7 @@ env = {AX_IP = "10.0.2.15", AX_GW = "10.0.2.2"} features = [ "ax-feat/plat-dyn", "starry-kernel/plat-dyn", - "ax-driver/pci-fdt", + "ax-driver/plat-dyn", "ax-driver/serial", "ax-driver/virtio-blk", "ax-driver/virtio-net", diff --git a/test-suit/starryos/stress/stress-ng-0/build-x86_64-unknown-none.toml b/test-suit/starryos/stress/stress-ng-0/build-x86_64-unknown-none.toml index 94d8986bbb..48f79a5df5 100644 --- a/test-suit/starryos/stress/stress-ng-0/build-x86_64-unknown-none.toml +++ b/test-suit/starryos/stress/stress-ng-0/build-x86_64-unknown-none.toml @@ -4,7 +4,7 @@ log = "Warn" features = [ "ax-hal/x86-pc", "qemu", - "ax-driver/pci", + "ax-driver/plat-static", "ax-driver/virtio-blk", "ax-driver/virtio-net", "ax-driver/virtio-gpu", From 30fbf97c3237c47c80c93b0ce0810ff0b3297b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=9D=BF?= Date: Wed, 27 May 2026 11:17:35 +0800 Subject: [PATCH 05/17] fix(ax-driver): correct feature handling for plat-static and plat-dyn --- drivers/ax-driver/build.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/ax-driver/build.rs b/drivers/ax-driver/build.rs index 3d186f6c3b..897e8664f8 100644 --- a/drivers/ax-driver/build.rs +++ b/drivers/ax-driver/build.rs @@ -30,14 +30,10 @@ fn main() { let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default(); let target_has_cvsd = matches!(target_arch.as_str(), "riscv32" | "riscv64"); - if has_plat_static && has_plat_dyn { - panic!("ax-driver features `plat-static` and `plat-dyn` are mutually exclusive"); - } - if has_plat_static { - enable_cfg_flag("plat_static"); - } if has_plat_dyn { enable_cfg_flag("plat_dyn"); + } else if has_plat_static { + enable_cfg_flag("plat_static"); } if has_virtio_core || has_virtio_dev { enable_cfg_flag("virtio_dev"); From 784fa4b249ea292dc4d2f286982e8076f44c97af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=9D=BF?= Date: Wed, 27 May 2026 11:48:40 +0800 Subject: [PATCH 06/17] fix(somehal): use runtime CPU id for riscv64 PLIC context --- components/someboot/src/smp/mod.rs | 12 ++-- platform/axplat-dyn/src/init.rs | 8 ++- platform/somehal/src/arch/riscv64/mod.rs | 4 ++ platform/somehal/src/arch/riscv64/plic.rs | 71 +++++++++++++++++------ 4 files changed, 69 insertions(+), 26 deletions(-) diff --git a/components/someboot/src/smp/mod.rs b/components/someboot/src/smp/mod.rs index c7d4e803a0..6d83fc5734 100644 --- a/components/someboot/src/smp/mod.rs +++ b/components/someboot/src/smp/mod.rs @@ -110,12 +110,12 @@ pub fn cpu_hart_id() -> usize { pub fn cpu_idx() -> usize { let hart_id = cpu_hart_id(); - for (idx, id) in __cpu_id_list().enumerate() { - if id == hart_id { - return idx; - } - } - panic!("Current CPU hart id {hart_id:#x} not found in CPU list"); + cpu_id_to_idx(hart_id) + .unwrap_or_else(|| panic!("Current CPU hart id {hart_id:#x} not found in CPU list")) +} + +pub fn try_cpu_idx() -> Option { + cpu_id_to_idx(cpu_hart_id()) } pub fn cpu_id_to_idx(hart_id: usize) -> Option { diff --git a/platform/axplat-dyn/src/init.rs b/platform/axplat-dyn/src/init.rs index d68349a3e8..190995198f 100644 --- a/platform/axplat-dyn/src/init.rs +++ b/platform/axplat-dyn/src/init.rs @@ -9,7 +9,9 @@ impl InitIf for InitIfImpl { /// This function should be called immediately after the kernel has booted, /// and performed earliest platform configuration and initialization (e.g., /// early console, clocking). - fn init_early(_cpu_id: usize, _dtb: usize) { + fn init_early(cpu_id: usize, _dtb: usize) { + #[cfg(target_arch = "riscv64")] + somehal::arch::register_current_cpu_id(cpu_id, ax_plat::percpu::this_cpu_id); ax_cpu::init::init_trap(); #[cfg(all(target_arch = "aarch64", feature = "fp-simd"))] { @@ -21,7 +23,9 @@ impl InitIf for InitIfImpl { /// Initializes the platform at the early stage for secondary cores. #[cfg(feature = "smp")] - fn init_early_secondary(_cpu_id: usize) { + fn init_early_secondary(cpu_id: usize) { + #[cfg(target_arch = "riscv64")] + somehal::arch::register_current_cpu_id(cpu_id, ax_plat::percpu::this_cpu_id); ax_cpu::init::init_trap(); #[cfg(all(target_arch = "aarch64", feature = "fp-simd"))] { diff --git a/platform/somehal/src/arch/riscv64/mod.rs b/platform/somehal/src/arch/riscv64/mod.rs index da1f1fe8b4..6d0d0fee40 100644 --- a/platform/somehal/src/arch/riscv64/mod.rs +++ b/platform/somehal/src/arch/riscv64/mod.rs @@ -4,6 +4,10 @@ mod plic; pub struct Plat; +pub fn register_current_cpu_id(cpu_idx: usize, reader: fn() -> usize) { + plic::register_current_cpu_id(cpu_idx, reader); +} + impl PlatOp for Plat { fn irq_set_enable(irq: rdrive::IrqId, enable: bool) { plic::irq_set_enable(irq, enable); diff --git a/platform/somehal/src/arch/riscv64/plic.rs b/platform/somehal/src/arch/riscv64/plic.rs index d471a3f345..27832dbe42 100644 --- a/platform/somehal/src/arch/riscv64/plic.rs +++ b/platform/somehal/src/arch/riscv64/plic.rs @@ -1,5 +1,9 @@ use alloc::{format, vec::Vec}; -use core::{num::NonZeroU32, ptr::NonNull}; +use core::{ + num::NonZeroU32, + ptr::NonNull, + sync::atomic::{AtomicPtr, AtomicUsize, Ordering}, +}; use ax_riscv_plic::{PLICRegs, Plic, PlicIrqHandler}; use kernutil::StaticCell; @@ -23,6 +27,8 @@ const DEFAULT_PRIORITY: u32 = 1; const DEFAULT_PLIC_SIZE: usize = 0x400_0000; static IRQ_HANDLER: StaticCell = StaticCell::uninit(); +static CURRENT_CPU_ID: AtomicPtr<()> = AtomicPtr::new(core::ptr::null_mut()); +static CURRENT_CPU_ID_READY: AtomicUsize = AtomicUsize::new(0); module_driver!( name: "RISC-V PLIC", @@ -42,6 +48,13 @@ pub fn systick_irq() -> rdrive::IrqId { S_TIMER.into() } +pub fn register_current_cpu_id(cpu_idx: usize, reader: fn() -> usize) { + if let Some(bit) = cpu_ready_bit(cpu_idx) { + CURRENT_CPU_ID_READY.fetch_or(bit, Ordering::Release); + } + CURRENT_CPU_ID.store(reader as *mut (), Ordering::Release); +} + pub fn irq_set_enable(irq: rdrive::IrqId, enable: bool) { let raw: usize = irq.into(); match raw { @@ -278,19 +291,13 @@ impl RiscvPlicIrqHandler { self.inner.init_by_context(context); trace!("PLIC context {context} initialized"); } else { - warn!( - "PLIC supervisor context for logical CPU {} is not found", - someboot::smp::cpu_idx() - ); + warn_missing_current_context(); } } fn claim_current(&self) -> Option { let Some(context) = self.current_context() else { - warn!( - "PLIC supervisor context for logical CPU {} is not found", - someboot::smp::cpu_idx() - ); + warn_missing_current_context(); return None; }; let Some(source) = self.inner.claim(context) else { @@ -302,10 +309,7 @@ impl RiscvPlicIrqHandler { fn complete_current(&self, source: NonZeroU32) { let Some(context) = self.current_context() else { - warn!( - "PLIC supervisor context for logical CPU {} is not found", - someboot::smp::cpu_idx() - ); + warn_missing_current_context(); return; }; self.inner.complete(context, source); @@ -324,10 +328,7 @@ impl RiscvPlic { self.inner.enable(source, context); } if current.is_none() { - warn!( - "PLIC supervisor context for logical CPU {} is not found", - someboot::smp::cpu_idx() - ); + warn_missing_current_context(); } } @@ -339,10 +340,44 @@ impl RiscvPlic { } fn current_context(context_by_cpu: &[Option]) -> Option { - let cpu_idx = someboot::smp::cpu_idx(); + let cpu_idx = current_cpu_idx()?; context_by_cpu.get(cpu_idx).and_then(|ctx| *ctx) } +fn current_cpu_idx() -> Option { + let reader = CURRENT_CPU_ID.load(Ordering::Acquire); + if !reader.is_null() { + if let Some(cpu_idx) = someboot::smp::try_cpu_idx() + && !cpu_reader_is_ready(cpu_idx) + { + return Some(cpu_idx); + } + + let reader = unsafe { core::mem::transmute::<*mut (), fn() -> usize>(reader) }; + return Some(reader()); + } + + someboot::smp::try_cpu_idx() +} + +fn cpu_ready_bit(cpu_idx: usize) -> Option { + (cpu_idx < usize::BITS as usize).then(|| 1usize << cpu_idx) +} + +fn cpu_reader_is_ready(cpu_idx: usize) -> bool { + cpu_ready_bit(cpu_idx) + .map(|bit| CURRENT_CPU_ID_READY.load(Ordering::Acquire) & bit != 0) + .unwrap_or(false) +} + +fn warn_missing_current_context() { + if let Some(cpu_idx) = current_cpu_idx() { + warn!("PLIC supervisor context for logical CPU {cpu_idx} is not found"); + } else { + warn!("PLIC supervisor context for current logical CPU is not found"); + } +} + impl DriverGeneric for RiscvPlic { fn name(&self) -> &str { "RISC-V PLIC" From f33b1ddd8f5472cc5f73bc04617e9217b33780b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=9D=BF?= Date: Wed, 27 May 2026 12:36:54 +0800 Subject: [PATCH 07/17] fix(build): replace pci driver feature with plat-dyn in configuration --- .../build-aarch64-unknown-none-softfloat.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-suit/starryos/normal/qemu-smp4-buddy-slab/build-aarch64-unknown-none-softfloat.toml b/test-suit/starryos/normal/qemu-smp4-buddy-slab/build-aarch64-unknown-none-softfloat.toml index f24592654f..4c9c78ec92 100644 --- a/test-suit/starryos/normal/qemu-smp4-buddy-slab/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/starryos/normal/qemu-smp4-buddy-slab/build-aarch64-unknown-none-softfloat.toml @@ -3,7 +3,7 @@ features = [ "ax-hal/plat-dyn", "ax-feat/display", "ax-feat/rtc", - "ax-driver/pci", + "ax-driver/plat-dyn", "ax-driver/rtc", "ax-driver/virtio-blk", "ax-driver/virtio-net", From 068a9237b893d18740471b42c0a423495f9a466f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=9D=BF?= Date: Wed, 27 May 2026 13:48:12 +0800 Subject: [PATCH 08/17] Refactor platform feature configurations across various board TOML files - Removed "plat-dyn" features from multiple configurations to streamline platform feature management. - Updated related build scripts to ensure compatibility with the new feature structure. - Adjusted tests to reflect the removal of deprecated features and ensure proper functionality. - Consolidated platform feature handling in build scripts to improve clarity and maintainability. --- .../build-aarch64-unknown-none-softfloat.toml | 3 -- .../build-aarch64-unknown-none-softfloat.toml | 3 -- .../configs/board/licheerv-nano-sg2002.toml | 6 ++-- .../configs/board/orangepi-5-plus.toml | 3 -- .../configs/board/qemu-aarch64-dyn.toml | 3 -- os/StarryOS/configs/board/qemu-riscv64.toml | 3 -- os/StarryOS/kernel/Cargo.toml | 1 + os/StarryOS/starryos/Cargo.toml | 4 +-- os/arceos/api/axfeat/Cargo.toml | 1 - os/arceos/modules/axruntime/Cargo.toml | 1 + os/axvisor/configs/board/orangepi-5-plus.toml | 1 - os/axvisor/configs/board/phytiumpi.toml | 1 - os/axvisor/configs/board/qemu-aarch64.toml | 2 -- .../configs/board/qemu-riscv64-dyn.toml | 3 -- os/axvisor/configs/board/qemu-riscv64.toml | 3 -- os/axvisor/configs/board/rdk-s100.toml | 2 -- os/axvisor/configs/board/roc-rk3568-pc.toml | 1 - os/axvisor/configs/board/tac-e400.toml | 2 -- scripts/axbuild/src/arceos/build.rs | 2 +- scripts/axbuild/src/axvisor/build.rs | 29 +++++++++++++++++-- scripts/axbuild/src/build.rs | 8 ++--- scripts/axbuild/src/starry/build.rs | 28 ++++++++++++------ scripts/axbuild/src/starry/rootfs.rs | 2 +- scripts/axbuild/src/starry/test.rs | 9 +++--- .../build-aarch64-unknown-none-softfloat.toml | 2 +- .../build-aarch64-unknown-none-softfloat.toml | 1 - .../build-aarch64-unknown-none-softfloat.toml | 1 - .../build-aarch64-unknown-none-softfloat.toml | 2 -- .../build-aarch64-unknown-none-softfloat.toml | 1 - .../build-aarch64-unknown-none-softfloat.toml | 2 -- .../build-riscv64gc-unknown-none-elf.toml | 3 -- .../build-aarch64-unknown-none-softfloat.toml | 3 -- .../build-riscv64gc-unknown-none-elf.toml | 6 ++-- .../build-aarch64-unknown-none-softfloat.toml | 3 -- .../build-aarch64-unknown-none-softfloat.toml | 3 -- .../build-aarch64-unknown-none-softfloat.toml | 3 -- .../build-riscv64gc-unknown-none-elf.toml | 3 -- .../build-aarch64-unknown-none-softfloat.toml | 3 -- .../build-aarch64-unknown-none-softfloat.toml | 3 -- .../build-riscv64gc-unknown-none-elf.toml | 3 -- .../build-aarch64-unknown-none-softfloat.toml | 3 -- .../build-riscv64gc-unknown-none-elf.toml | 3 -- .../build-aarch64-unknown-none-softfloat.toml | 3 -- .../build-riscv64gc-unknown-none-elf.toml | 3 -- 44 files changed, 65 insertions(+), 110 deletions(-) diff --git a/apps/starry/orangepi-5-plus-uvc-rknn/build-aarch64-unknown-none-softfloat.toml b/apps/starry/orangepi-5-plus-uvc-rknn/build-aarch64-unknown-none-softfloat.toml index c1c2589b4f..97f221b4a9 100644 --- a/apps/starry/orangepi-5-plus-uvc-rknn/build-aarch64-unknown-none-softfloat.toml +++ b/apps/starry/orangepi-5-plus-uvc-rknn/build-aarch64-unknown-none-softfloat.toml @@ -2,9 +2,6 @@ target = "aarch64-unknown-none-softfloat" env = {} features = [ - "ax-driver/plat-dyn", - "ax-hal/plat-dyn", - "starry-kernel/plat-dyn", "ax-driver/irq", "ax-driver/list-pci-devices", "ax-driver/rk3588-pcie", diff --git a/apps/starry/orangepi-5-plus-uvc/build-aarch64-unknown-none-softfloat.toml b/apps/starry/orangepi-5-plus-uvc/build-aarch64-unknown-none-softfloat.toml index dd00ceec04..ef3f84f4a4 100644 --- a/apps/starry/orangepi-5-plus-uvc/build-aarch64-unknown-none-softfloat.toml +++ b/apps/starry/orangepi-5-plus-uvc/build-aarch64-unknown-none-softfloat.toml @@ -2,9 +2,6 @@ target = "aarch64-unknown-none-softfloat" env = {} features = [ - "ax-driver/plat-dyn", - "ax-hal/plat-dyn", - "starry-kernel/plat-dyn", "ax-driver/rockchip-soc", "ax-driver/rockchip-dwc-xhci", "ax-driver/rockchip-sdhci", diff --git a/os/StarryOS/configs/board/licheerv-nano-sg2002.toml b/os/StarryOS/configs/board/licheerv-nano-sg2002.toml index eaa27471d5..03a58c86a0 100644 --- a/os/StarryOS/configs/board/licheerv-nano-sg2002.toml +++ b/os/StarryOS/configs/board/licheerv-nano-sg2002.toml @@ -1,8 +1,8 @@ env = { UIMAGE = "y" } features = [ - "ax-driver/plat-dyn", - "sg2002-dyn", - "ax-feat/plat-dyn", + "starry-kernel/sg2002", + "axplat-dyn/thead-mae", + "ax-driver/sg2002-placeholder", "ax-driver/cvsd", "ax-driver/serial", ] diff --git a/os/StarryOS/configs/board/orangepi-5-plus.toml b/os/StarryOS/configs/board/orangepi-5-plus.toml index b97d639681..e88f614967 100644 --- a/os/StarryOS/configs/board/orangepi-5-plus.toml +++ b/os/StarryOS/configs/board/orangepi-5-plus.toml @@ -3,9 +3,6 @@ target = "aarch64-unknown-none-softfloat" # Runtime U-Boot settings live in `orangepi-5-plus-uboot.toml`. env = {} features = [ - "ax-driver/plat-dyn", - "ax-hal/plat-dyn", - "starry-kernel/plat-dyn", "ax-driver/list-pci-devices", "ax-driver/rk3588-pcie", "ax-driver/realtek-rtl8125", diff --git a/os/StarryOS/configs/board/qemu-aarch64-dyn.toml b/os/StarryOS/configs/board/qemu-aarch64-dyn.toml index 4c9fe454f3..72d8d8bd27 100644 --- a/os/StarryOS/configs/board/qemu-aarch64-dyn.toml +++ b/os/StarryOS/configs/board/qemu-aarch64-dyn.toml @@ -1,11 +1,8 @@ env = {} features = [ - "ax-driver/plat-dyn", - "ax-hal/plat-dyn", "ax-driver/virtio-blk", "ax-driver/virtio-net", "starry-kernel/input", - "starry-kernel/plat-dyn", "starry-kernel/vsock", "ax-driver/intel-net", ] diff --git a/os/StarryOS/configs/board/qemu-riscv64.toml b/os/StarryOS/configs/board/qemu-riscv64.toml index 964056bc6f..898a6e773d 100644 --- a/os/StarryOS/configs/board/qemu-riscv64.toml +++ b/os/StarryOS/configs/board/qemu-riscv64.toml @@ -1,8 +1,5 @@ env = {} features = [ - "ax-feat/plat-dyn", - "starry-kernel/plat-dyn", - "ax-driver/plat-dyn", "ax-driver/serial", "ax-driver/virtio-blk", "ax-driver/virtio-net", diff --git a/os/StarryOS/kernel/Cargo.toml b/os/StarryOS/kernel/Cargo.toml index 90af40394d..e88712190f 100644 --- a/os/StarryOS/kernel/Cargo.toml +++ b/os/StarryOS/kernel/Cargo.toml @@ -21,6 +21,7 @@ input = ["dep:ax-input", "ax-feat/input"] memtrack = ["ax-feat/dwarf", "ax-alloc/tracking", "dep:gimli"] rknpu = ["dep:ax-driver", "ax-driver/rknpu"] plat-dyn = [ + "ax-feat/plat-dyn", "dep:ax-driver", "ax-driver/usb", "dep:crab-usb", diff --git a/os/StarryOS/starryos/Cargo.toml b/os/StarryOS/starryos/Cargo.toml index 1241c0cc97..36f14f6c0c 100644 --- a/os/StarryOS/starryos/Cargo.toml +++ b/os/StarryOS/starryos/Cargo.toml @@ -31,12 +31,12 @@ sg2002 = [ "starry-kernel/sg2002", ] sg2002-dyn = [ - "dep:axplat-dyn", + "plat-dyn", "axplat-dyn/thead-mae", "starry-kernel/sg2002", - "starry-kernel/plat-dyn", "ax-driver/sg2002-placeholder", ] +plat-dyn = ["dep:axplat-dyn", "starry-kernel/plat-dyn"] # Enable the GICv3 distributor + redistributor + system-register # CPU interface on aarch64. Only meaningful when the target is the diff --git a/os/arceos/api/axfeat/Cargo.toml b/os/arceos/api/axfeat/Cargo.toml index d8582ceb4d..f28021a749 100644 --- a/os/arceos/api/axfeat/Cargo.toml +++ b/os/arceos/api/axfeat/Cargo.toml @@ -28,7 +28,6 @@ ipi = ["irq", "dep:ax-ipi", "ax-hal/ipi", "ax-runtime/ipi", "ax-task?/ipi"] myplat = ["ax-hal/myplat"] defplat = ["ax-hal/defplat"] plat-dyn = [ - "ax-hal/plat-dyn", "paging", "ax-runtime/plat-dyn", "ax-config/plat-dyn", diff --git a/os/arceos/modules/axruntime/Cargo.toml b/os/arceos/modules/axruntime/Cargo.toml index 0a330852ef..79973b8749 100644 --- a/os/arceos/modules/axruntime/Cargo.toml +++ b/os/arceos/modules/axruntime/Cargo.toml @@ -23,6 +23,7 @@ stack-guard-page = ["multitask", "paging", "ax-task/stack-guard-page"] tls = ["ax-hal/tls", "ax-task?/tls"] plat-dyn = [ + "ax-driver/plat-dyn", "ax-hal/plat-dyn", "paging", "buddy-slab", diff --git a/os/axvisor/configs/board/orangepi-5-plus.toml b/os/axvisor/configs/board/orangepi-5-plus.toml index f279d3963e..e8f449b079 100644 --- a/os/axvisor/configs/board/orangepi-5-plus.toml +++ b/os/axvisor/configs/board/orangepi-5-plus.toml @@ -1,6 +1,5 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ - "ax-driver/plat-dyn", "sdmmc", "rockchip-soc", "fs", diff --git a/os/axvisor/configs/board/phytiumpi.toml b/os/axvisor/configs/board/phytiumpi.toml index c81e3e627a..42a0ed4050 100644 --- a/os/axvisor/configs/board/phytiumpi.toml +++ b/os/axvisor/configs/board/phytiumpi.toml @@ -1,6 +1,5 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ - "ax-driver/plat-dyn", "fs", "phytium-mci", ] diff --git a/os/axvisor/configs/board/qemu-aarch64.toml b/os/axvisor/configs/board/qemu-aarch64.toml index 590f33a70a..ed80bad75a 100644 --- a/os/axvisor/configs/board/qemu-aarch64.toml +++ b/os/axvisor/configs/board/qemu-aarch64.toml @@ -1,7 +1,5 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ - "ax-driver/plat-dyn", - "ax-hal/plat-dyn", "ept-level-4", "ax-driver/virtio-blk", "fs", diff --git a/os/axvisor/configs/board/qemu-riscv64-dyn.toml b/os/axvisor/configs/board/qemu-riscv64-dyn.toml index 1b73a30882..ab922ad886 100644 --- a/os/axvisor/configs/board/qemu-riscv64-dyn.toml +++ b/os/axvisor/configs/board/qemu-riscv64-dyn.toml @@ -1,8 +1,5 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ - "dyn-plat", - "ax-hal/plat-dyn", - "ax-driver/plat-dyn", "ax-driver/virtio-blk", "ept-level-4", "fs", diff --git a/os/axvisor/configs/board/qemu-riscv64.toml b/os/axvisor/configs/board/qemu-riscv64.toml index 1b73a30882..ab922ad886 100644 --- a/os/axvisor/configs/board/qemu-riscv64.toml +++ b/os/axvisor/configs/board/qemu-riscv64.toml @@ -1,8 +1,5 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ - "dyn-plat", - "ax-hal/plat-dyn", - "ax-driver/plat-dyn", "ax-driver/virtio-blk", "ept-level-4", "fs", diff --git a/os/axvisor/configs/board/rdk-s100.toml b/os/axvisor/configs/board/rdk-s100.toml index cb50bbb3af..c8a96cc301 100644 --- a/os/axvisor/configs/board/rdk-s100.toml +++ b/os/axvisor/configs/board/rdk-s100.toml @@ -1,7 +1,5 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ - "ax-driver/plat-dyn", - "ax-hal/plat-dyn", "ept-level-4", ] log = "Info" diff --git a/os/axvisor/configs/board/roc-rk3568-pc.toml b/os/axvisor/configs/board/roc-rk3568-pc.toml index 234d3d70b5..211950cdb6 100644 --- a/os/axvisor/configs/board/roc-rk3568-pc.toml +++ b/os/axvisor/configs/board/roc-rk3568-pc.toml @@ -1,6 +1,5 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ - "ax-driver/plat-dyn", "fs", "rockchip-sdhci", ] diff --git a/os/axvisor/configs/board/tac-e400.toml b/os/axvisor/configs/board/tac-e400.toml index cb50bbb3af..c8a96cc301 100644 --- a/os/axvisor/configs/board/tac-e400.toml +++ b/os/axvisor/configs/board/tac-e400.toml @@ -1,7 +1,5 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ - "ax-driver/plat-dyn", - "ax-hal/plat-dyn", "ept-level-4", ] log = "Info" diff --git a/scripts/axbuild/src/arceos/build.rs b/scripts/axbuild/src/arceos/build.rs index d485cb59f6..b86fb0182c 100644 --- a/scripts/axbuild/src/arceos/build.rs +++ b/scripts/axbuild/src/arceos/build.rs @@ -182,7 +182,7 @@ mod tests { build_info.resolve_features("ax-helloworld", "aarch64-unknown-none-softfloat", true); assert!(build_info.features.contains(&"ax-std/plat-dyn".to_string())); - assert!(build_info.features.contains(&"ax-hal/plat-dyn".to_string())); + assert!(!build_info.features.contains(&"ax-hal/plat-dyn".to_string())); assert!(!build_info.features.contains(&"ax-std/defplat".to_string())); let args = ArceosBuildInfo::build_cargo_args( diff --git a/scripts/axbuild/src/axvisor/build.rs b/scripts/axbuild/src/axvisor/build.rs index a73c5f866f..1d8e6a5637 100644 --- a/scripts/axbuild/src/axvisor/build.rs +++ b/scripts/axbuild/src/axvisor/build.rs @@ -125,6 +125,9 @@ fn to_cargo_config( metadata: &cargo_metadata::Metadata, ) -> anyhow::Result { config.target = request.target.clone(); + let plat_dyn = config + .build_info + .effective_plat_dyn(&config.target, request.plat_dyn); let mut cargo = config .build_info .into_prepared_base_cargo_config_with_metadata( @@ -133,6 +136,15 @@ fn to_cargo_config( request.plat_dyn, metadata, )?; + if plat_dyn { + cargo.features.retain(|feature| { + !matches!( + feature.as_str(), + "ax-std/plat-dyn" | "ax-feat/plat-dyn" | "dyn-plat" + ) + }); + cargo.features.push("dyn-plat".to_string()); + } patch_axvisor_cargo_config(&mut cargo, request, &config.vm_configs)?; Ok(cargo) } @@ -398,7 +410,7 @@ mod tests { r#" env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } target = "aarch64-unknown-none-softfloat" -features = ["ept-level-4", "ax-driver/plat-dyn"] +features = ["ept-level-4"] log = "Info" plat_dyn = true vm_configs = [] @@ -413,7 +425,17 @@ vm_configs = [] .unwrap(); assert!(cargo.features.contains(&"ept-level-4".to_string())); - assert!(cargo.features.contains(&"ax-driver/plat-dyn".to_string())); + assert!(cargo.features.contains(&"dyn-plat".to_string())); + assert!( + !cargo + .features + .contains(&concat!("ax-driver/", "plat-dyn").to_string()) + ); + assert!( + !cargo + .features + .contains(&concat!("ax-hal/", "plat-dyn").to_string()) + ); assert!(path.exists()); } @@ -600,8 +622,9 @@ plat_dyn = false &config_path, r#" env = {} -features = ["ept-level-4", "ax-driver/plat-dyn"] +features = ["ept-level-4"] log = "Info" +plat_dyn = false "#, ) .unwrap(); diff --git a/scripts/axbuild/src/build.rs b/scripts/axbuild/src/build.rs index b9b9ff25d9..6ea14601ea 100644 --- a/scripts/axbuild/src/build.rs +++ b/scripts/axbuild/src/build.rs @@ -337,15 +337,11 @@ impl BuildInfo { } fn push_platform_feature(&mut self, target: &str, plat_dyn: bool, has_myplat: bool) { - if has_myplat || has_ax_hal_platform_feature(&self.features) { + if plat_dyn || has_myplat || has_ax_hal_platform_feature(&self.features) { return; } - let feature = if plat_dyn { - "ax-hal/plat-dyn" - } else { - default_ax_hal_platform_feature(target).unwrap_or("ax-hal/defplat") - }; + let feature = default_ax_hal_platform_feature(target).unwrap_or("ax-hal/defplat"); self.features.push(feature.to_string()); } diff --git a/scripts/axbuild/src/starry/build.rs b/scripts/axbuild/src/starry/build.rs index 275ba78310..d67514e0ce 100644 --- a/scripts/axbuild/src/starry/build.rs +++ b/scripts/axbuild/src/starry/build.rs @@ -90,12 +90,22 @@ pub(crate) fn load_cargo_config(request: &ResolvedStarryRequest) -> anyhow::Resu if let Some(smp) = request.smp { build_info.max_cpu_num = Some(smp); } + let plat_dyn = build_info.effective_plat_dyn(&request.target, request.plat_dyn); let mut cargo = build_info.into_prepared_base_cargo_config_with_metadata( &request.package, &request.target, request.plat_dyn, metadata, )?; + if plat_dyn { + cargo.features.retain(|feature| { + !matches!( + feature.as_str(), + "ax-feat/plat-dyn" | "ax-std/plat-dyn" | "starry-kernel/plat-dyn" + ) + }); + cargo.features.push("plat-dyn".to_string()); + } patch_starry_cargo_config(&mut cargo, request, metadata)?; Ok(cargo) } @@ -204,7 +214,11 @@ fn uses_dynamic_platform(features: &[String]) -> bool { features.iter().any(|feature| { matches!( feature.as_str(), - "plat-dyn" | "ax-feat/plat-dyn" | "ax-std/plat-dyn" | "ax-hal/plat-dyn" + "plat-dyn" + | "ax-feat/plat-dyn" + | "ax-std/plat-dyn" + | "starry-kernel/plat-dyn" + | "ax-hal/plat-dyn" ) }) } @@ -520,7 +534,7 @@ HELLO = "world" env: HashMap::new(), features: vec![ "common".to_string(), - "ax-feat/plat-dyn".to_string(), + "plat-dyn".to_string(), "ax-driver/rockchip-soc".to_string(), "ax-driver/rockchip-sdhci".to_string(), ], @@ -569,11 +583,7 @@ HELLO = "world" ); let build_info = StarryBuildInfo { env: HashMap::new(), - features: vec![ - "qemu".to_string(), - "ax-feat/plat-dyn".to_string(), - "starry-kernel/plat-dyn".to_string(), - ], + features: vec!["qemu".to_string(), "plat-dyn".to_string()], log: LogLevel::Info, max_cpu_num: None, axconfig_overrides: Vec::new(), @@ -603,7 +613,7 @@ HELLO = "world" target: "scripts/targets/pie/riscv64gc-unknown-none-elf.json".to_string(), package: STARRY_PACKAGE.to_string(), bin: None, - features: vec!["ax-feat/plat-dyn".to_string()], + features: vec!["plat-dyn".to_string()], log: None, extra_config: None, profile: None, @@ -630,7 +640,7 @@ HELLO = "world" target: "riscv64gc-unknown-none-elf".to_string(), package: STARRY_PACKAGE.to_string(), bin: None, - features: vec!["ax-feat/plat-dyn".to_string()], + features: vec!["plat-dyn".to_string()], log: None, extra_config: None, profile: None, diff --git a/scripts/axbuild/src/starry/rootfs.rs b/scripts/axbuild/src/starry/rootfs.rs index 58b3cc8d88..59aeecf7c3 100644 --- a/scripts/axbuild/src/starry/rootfs.rs +++ b/scripts/axbuild/src/starry/rootfs.rs @@ -284,7 +284,7 @@ fn rootfs_patch_mode(request: &ResolvedStarryRequest, cargo: &Cargo) -> RootfsPa || cargo.features.iter().any(|feature| { matches!( feature.as_str(), - "ax-feat/plat-dyn" | "ax-std/plat-dyn" | "starry-kernel/plat-dyn" + "plat-dyn" | "ax-feat/plat-dyn" | "ax-std/plat-dyn" | "starry-kernel/plat-dyn" ) }) { diff --git a/scripts/axbuild/src/starry/test.rs b/scripts/axbuild/src/starry/test.rs index 5df98cadd8..519985f2de 100644 --- a/scripts/axbuild/src/starry/test.rs +++ b/scripts/axbuild/src/starry/test.rs @@ -1772,8 +1772,8 @@ mod tests { fs::create_dir_all(build_config.parent().unwrap()).unwrap(); fs::write( &build_config, - "target = \"aarch64-unknown-none-softfloat\"\nenv = {}\nfeatures = [\"qemu\", \ - \"starry-kernel/plat-dyn\"]\nlog = \"Warn\"\nplat_dyn = true\n", + "target = \"aarch64-unknown-none-softfloat\"\nenv = {}\nfeatures = [\"qemu\"]\nlog = \ + \"Warn\"\nplat_dyn = true\n", ) .unwrap(); let mut request = starry_request( @@ -1793,9 +1793,10 @@ mod tests { let (_group_request, cargo) = Starry::qemu_group_build_context(&request, &build_config).unwrap(); - assert!(cargo.features.contains(&"ax-feat/plat-dyn".to_string())); + assert!(cargo.features.contains(&"plat-dyn".to_string())); + assert!(!cargo.features.contains(&"ax-feat/plat-dyn".to_string())); assert!( - cargo + !cargo .features .contains(&"starry-kernel/plat-dyn".to_string()) ); diff --git a/test-suit/arceos/rust/net/httpclient/build-aarch64-unknown-none-softfloat.toml b/test-suit/arceos/rust/net/httpclient/build-aarch64-unknown-none-softfloat.toml index 3b6c8c9826..0fcc053015 100644 --- a/test-suit/arceos/rust/net/httpclient/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/arceos/rust/net/httpclient/build-aarch64-unknown-none-softfloat.toml @@ -1,4 +1,4 @@ -features = ["ax-std", "ax-hal/plat-dyn", "ax-driver/plat-dyn", "ax-driver/virtio-net"] +features = ["ax-std", "ax-driver/virtio-net"] log = "Warn" max_cpu_num = 4 plat_dyn = true diff --git a/test-suit/axvisor/normal/board-orangepi-5-plus/build-aarch64-unknown-none-softfloat.toml b/test-suit/axvisor/normal/board-orangepi-5-plus/build-aarch64-unknown-none-softfloat.toml index f290c11f18..5ad4b8a556 100644 --- a/test-suit/axvisor/normal/board-orangepi-5-plus/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/axvisor/normal/board-orangepi-5-plus/build-aarch64-unknown-none-softfloat.toml @@ -1,6 +1,5 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ - "ax-driver/plat-dyn", "sdmmc", "rockchip-soc", "fs", diff --git a/test-suit/axvisor/normal/board-phytiumpi/build-aarch64-unknown-none-softfloat.toml b/test-suit/axvisor/normal/board-phytiumpi/build-aarch64-unknown-none-softfloat.toml index 820dca9115..c460cd1906 100644 --- a/test-suit/axvisor/normal/board-phytiumpi/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/axvisor/normal/board-phytiumpi/build-aarch64-unknown-none-softfloat.toml @@ -1,6 +1,5 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ - "ax-driver/plat-dyn", "fs", "phytium-mci", ] diff --git a/test-suit/axvisor/normal/board-rdk-s100/build-aarch64-unknown-none-softfloat.toml b/test-suit/axvisor/normal/board-rdk-s100/build-aarch64-unknown-none-softfloat.toml index 726844440c..82d078a057 100644 --- a/test-suit/axvisor/normal/board-rdk-s100/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/axvisor/normal/board-rdk-s100/build-aarch64-unknown-none-softfloat.toml @@ -1,7 +1,5 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ - "ax-driver/plat-dyn", - "ax-hal/plat-dyn", "ept-level-4", ] log = "Info" diff --git a/test-suit/axvisor/normal/board-roc-rk3568-pc/build-aarch64-unknown-none-softfloat.toml b/test-suit/axvisor/normal/board-roc-rk3568-pc/build-aarch64-unknown-none-softfloat.toml index 6dd9b0de34..722f81a042 100644 --- a/test-suit/axvisor/normal/board-roc-rk3568-pc/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/axvisor/normal/board-roc-rk3568-pc/build-aarch64-unknown-none-softfloat.toml @@ -1,6 +1,5 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ - "ax-driver/plat-dyn", "rockchip-sdhci", "rockchip-soc", "fs", diff --git a/test-suit/axvisor/normal/qemu/build-aarch64-unknown-none-softfloat.toml b/test-suit/axvisor/normal/qemu/build-aarch64-unknown-none-softfloat.toml index 4a244cd393..7079f96928 100644 --- a/test-suit/axvisor/normal/qemu/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/axvisor/normal/qemu/build-aarch64-unknown-none-softfloat.toml @@ -1,7 +1,5 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ - "ax-driver/plat-dyn", - "ax-hal/plat-dyn", "ept-level-4", "ax-driver/virtio-blk", "fs", diff --git a/test-suit/axvisor/normal/qemu/build-riscv64gc-unknown-none-elf.toml b/test-suit/axvisor/normal/qemu/build-riscv64gc-unknown-none-elf.toml index 251cc12f51..7cbfe678fb 100644 --- a/test-suit/axvisor/normal/qemu/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/axvisor/normal/qemu/build-riscv64gc-unknown-none-elf.toml @@ -1,8 +1,5 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ - "dyn-plat", - "ax-hal/plat-dyn", - "ax-driver/plat-dyn", "ax-driver/virtio-blk", "ept-level-4", "fs", diff --git a/test-suit/starryos/aarch64-hvf/test-aarch64-gicv3-smoke/build-aarch64-unknown-none-softfloat.toml b/test-suit/starryos/aarch64-hvf/test-aarch64-gicv3-smoke/build-aarch64-unknown-none-softfloat.toml index 2bdb5fcd87..ad16f45be8 100644 --- a/test-suit/starryos/aarch64-hvf/test-aarch64-gicv3-smoke/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/starryos/aarch64-hvf/test-aarch64-gicv3-smoke/build-aarch64-unknown-none-softfloat.toml @@ -1,16 +1,13 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } features = [ - "ax-hal/plat-dyn", "ax-feat/display", "ax-feat/rtc", - "ax-driver/plat-dyn", "ax-driver/rtc", "ax-driver/virtio-blk", "ax-driver/virtio-net", "gic-v3", "cntv-timer", "starry-kernel/input", - "starry-kernel/plat-dyn", "starry-kernel/vsock", ] # CNTV PPI 11 = IRQ 27. The kernel's `cntv-timer` path programs the diff --git a/test-suit/starryos/normal/board-licheerv-nano-sg2002/build-riscv64gc-unknown-none-elf.toml b/test-suit/starryos/normal/board-licheerv-nano-sg2002/build-riscv64gc-unknown-none-elf.toml index 7f03b9e7e6..5d1445e2fb 100644 --- a/test-suit/starryos/normal/board-licheerv-nano-sg2002/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/starryos/normal/board-licheerv-nano-sg2002/build-riscv64gc-unknown-none-elf.toml @@ -2,9 +2,9 @@ target = "riscv64gc-unknown-none-elf" env = {} features = [ - "ax-driver/plat-dyn", - "sg2002-dyn", - "ax-feat/plat-dyn", + "starry-kernel/sg2002", + "axplat-dyn/thead-mae", + "ax-driver/sg2002-placeholder", "ax-driver/cvsd", "ax-driver/serial", ] diff --git a/test-suit/starryos/normal/board-orangepi-5-plus/build-aarch64-unknown-none-softfloat.toml b/test-suit/starryos/normal/board-orangepi-5-plus/build-aarch64-unknown-none-softfloat.toml index e900e7c3ac..3a3a986c62 100644 --- a/test-suit/starryos/normal/board-orangepi-5-plus/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/starryos/normal/board-orangepi-5-plus/build-aarch64-unknown-none-softfloat.toml @@ -3,9 +3,6 @@ target = "aarch64-unknown-none-softfloat" # Runtime U-Boot settings live in `orangepi-5-plus-uboot.toml`. env = {} features = [ - "ax-driver/plat-dyn", - "ax-hal/plat-dyn", - "starry-kernel/plat-dyn", "ax-driver/list-pci-devices", "ax-driver/rk3588-pcie", "ax-driver/realtek-rtl8125", diff --git a/test-suit/starryos/normal/qemu-aarch64-plat-dyn/build-aarch64-unknown-none-softfloat.toml b/test-suit/starryos/normal/qemu-aarch64-plat-dyn/build-aarch64-unknown-none-softfloat.toml index 2293a4dd31..71d3294162 100644 --- a/test-suit/starryos/normal/qemu-aarch64-plat-dyn/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/starryos/normal/qemu-aarch64-plat-dyn/build-aarch64-unknown-none-softfloat.toml @@ -1,13 +1,10 @@ env = {} features = [ - "ax-driver/plat-dyn", - "ax-hal/plat-dyn", "ax-feat/rtc", "ax-driver/rtc", "ax-driver/virtio-blk", "ax-driver/virtio-net", "starry-kernel/input", - "starry-kernel/plat-dyn", "starry-kernel/vsock", "ax-driver/intel-net", "ax-driver/xhci-pci", diff --git a/test-suit/starryos/normal/qemu-smp1/build-aarch64-unknown-none-softfloat.toml b/test-suit/starryos/normal/qemu-smp1/build-aarch64-unknown-none-softfloat.toml index 6791ff12d1..6642260288 100644 --- a/test-suit/starryos/normal/qemu-smp1/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/starryos/normal/qemu-smp1/build-aarch64-unknown-none-softfloat.toml @@ -1,9 +1,7 @@ env = {AX_IP = "10.0.2.15", AX_GW = "10.0.2.2"} features = [ - "ax-hal/plat-dyn", "ax-feat/display", "ax-feat/rtc", - "ax-driver/plat-dyn", "ax-driver/rtc", "ax-driver/virtio-blk", "ax-driver/virtio-net", @@ -11,7 +9,6 @@ features = [ "ax-driver/virtio-input", "ax-driver/virtio-socket", "starry-kernel/input", - "starry-kernel/plat-dyn", "starry-kernel/vsock", ] log = "Warn" diff --git a/test-suit/starryos/normal/qemu-smp1/build-riscv64gc-unknown-none-elf.toml b/test-suit/starryos/normal/qemu-smp1/build-riscv64gc-unknown-none-elf.toml index e1f84e80b1..65cff80fdf 100644 --- a/test-suit/starryos/normal/qemu-smp1/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/starryos/normal/qemu-smp1/build-riscv64gc-unknown-none-elf.toml @@ -1,8 +1,5 @@ env = {AX_IP = "10.0.2.15", AX_GW = "10.0.2.2"} features = [ - "ax-feat/plat-dyn", - "starry-kernel/plat-dyn", - "ax-driver/plat-dyn", "ax-driver/serial", "ax-driver/virtio-blk", "ax-driver/virtio-net", diff --git a/test-suit/starryos/normal/qemu-smp4-buddy-slab/build-aarch64-unknown-none-softfloat.toml b/test-suit/starryos/normal/qemu-smp4-buddy-slab/build-aarch64-unknown-none-softfloat.toml index 4c9c78ec92..8b785b5ae5 100644 --- a/test-suit/starryos/normal/qemu-smp4-buddy-slab/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/starryos/normal/qemu-smp4-buddy-slab/build-aarch64-unknown-none-softfloat.toml @@ -1,9 +1,7 @@ env = {AX_IP = "10.0.2.15", AX_GW = "10.0.2.2"} features = [ - "ax-hal/plat-dyn", "ax-feat/display", "ax-feat/rtc", - "ax-driver/plat-dyn", "ax-driver/rtc", "ax-driver/virtio-blk", "ax-driver/virtio-net", @@ -11,7 +9,6 @@ features = [ "ax-driver/virtio-input", "ax-driver/virtio-socket", "starry-kernel/input", - "starry-kernel/plat-dyn", "starry-kernel/vsock", "starryos/buddy-slab", ] diff --git a/test-suit/starryos/normal/qemu-smp4/build-aarch64-unknown-none-softfloat.toml b/test-suit/starryos/normal/qemu-smp4/build-aarch64-unknown-none-softfloat.toml index b093f2f61e..3f72491b2b 100644 --- a/test-suit/starryos/normal/qemu-smp4/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/starryos/normal/qemu-smp4/build-aarch64-unknown-none-softfloat.toml @@ -1,9 +1,7 @@ env = {AX_IP = "10.0.2.15", AX_GW = "10.0.2.2"} features = [ - "ax-hal/plat-dyn", "ax-feat/display", "ax-feat/rtc", - "ax-driver/plat-dyn", "ax-driver/rtc", "ax-driver/virtio-blk", "ax-driver/virtio-net", @@ -11,7 +9,6 @@ features = [ "ax-driver/virtio-input", "ax-driver/virtio-socket", "starry-kernel/input", - "starry-kernel/plat-dyn", "starry-kernel/vsock", ] max_cpu_num = 4 diff --git a/test-suit/starryos/normal/qemu-smp4/build-riscv64gc-unknown-none-elf.toml b/test-suit/starryos/normal/qemu-smp4/build-riscv64gc-unknown-none-elf.toml index ad03a672b6..f8d2a9b987 100644 --- a/test-suit/starryos/normal/qemu-smp4/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/starryos/normal/qemu-smp4/build-riscv64gc-unknown-none-elf.toml @@ -1,8 +1,5 @@ env = {AX_IP = "10.0.2.15", AX_GW = "10.0.2.2"} features = [ - "ax-feat/plat-dyn", - "starry-kernel/plat-dyn", - "ax-driver/plat-dyn", "ax-driver/serial", "ax-driver/virtio-blk", "ax-driver/virtio-net", diff --git a/test-suit/starryos/stress/postgresql/build-aarch64-unknown-none-softfloat.toml b/test-suit/starryos/stress/postgresql/build-aarch64-unknown-none-softfloat.toml index 6791ff12d1..6642260288 100644 --- a/test-suit/starryos/stress/postgresql/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/starryos/stress/postgresql/build-aarch64-unknown-none-softfloat.toml @@ -1,9 +1,7 @@ env = {AX_IP = "10.0.2.15", AX_GW = "10.0.2.2"} features = [ - "ax-hal/plat-dyn", "ax-feat/display", "ax-feat/rtc", - "ax-driver/plat-dyn", "ax-driver/rtc", "ax-driver/virtio-blk", "ax-driver/virtio-net", @@ -11,7 +9,6 @@ features = [ "ax-driver/virtio-input", "ax-driver/virtio-socket", "starry-kernel/input", - "starry-kernel/plat-dyn", "starry-kernel/vsock", ] log = "Warn" diff --git a/test-suit/starryos/stress/postgresql/build-riscv64gc-unknown-none-elf.toml b/test-suit/starryos/stress/postgresql/build-riscv64gc-unknown-none-elf.toml index e1f84e80b1..65cff80fdf 100644 --- a/test-suit/starryos/stress/postgresql/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/starryos/stress/postgresql/build-riscv64gc-unknown-none-elf.toml @@ -1,8 +1,5 @@ env = {AX_IP = "10.0.2.15", AX_GW = "10.0.2.2"} features = [ - "ax-feat/plat-dyn", - "starry-kernel/plat-dyn", - "ax-driver/plat-dyn", "ax-driver/serial", "ax-driver/virtio-blk", "ax-driver/virtio-net", diff --git a/test-suit/starryos/stress/stress-ng-0/build-aarch64-unknown-none-softfloat.toml b/test-suit/starryos/stress/stress-ng-0/build-aarch64-unknown-none-softfloat.toml index 6791ff12d1..6642260288 100644 --- a/test-suit/starryos/stress/stress-ng-0/build-aarch64-unknown-none-softfloat.toml +++ b/test-suit/starryos/stress/stress-ng-0/build-aarch64-unknown-none-softfloat.toml @@ -1,9 +1,7 @@ env = {AX_IP = "10.0.2.15", AX_GW = "10.0.2.2"} features = [ - "ax-hal/plat-dyn", "ax-feat/display", "ax-feat/rtc", - "ax-driver/plat-dyn", "ax-driver/rtc", "ax-driver/virtio-blk", "ax-driver/virtio-net", @@ -11,7 +9,6 @@ features = [ "ax-driver/virtio-input", "ax-driver/virtio-socket", "starry-kernel/input", - "starry-kernel/plat-dyn", "starry-kernel/vsock", ] log = "Warn" diff --git a/test-suit/starryos/stress/stress-ng-0/build-riscv64gc-unknown-none-elf.toml b/test-suit/starryos/stress/stress-ng-0/build-riscv64gc-unknown-none-elf.toml index e1f84e80b1..65cff80fdf 100644 --- a/test-suit/starryos/stress/stress-ng-0/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/starryos/stress/stress-ng-0/build-riscv64gc-unknown-none-elf.toml @@ -1,8 +1,5 @@ env = {AX_IP = "10.0.2.15", AX_GW = "10.0.2.2"} features = [ - "ax-feat/plat-dyn", - "starry-kernel/plat-dyn", - "ax-driver/plat-dyn", "ax-driver/serial", "ax-driver/virtio-blk", "ax-driver/virtio-net", From 201d431bc2429010de4f00f860ef1bc06baac699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=9D=BF?= Date: Wed, 27 May 2026 14:18:58 +0800 Subject: [PATCH 09/17] fix(build): remove unnecessary parameter from build_cargo_args call --- scripts/axbuild/src/starry/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/axbuild/src/starry/build.rs b/scripts/axbuild/src/starry/build.rs index c73000dd61..f0a2c55990 100644 --- a/scripts/axbuild/src/starry/build.rs +++ b/scripts/axbuild/src/starry/build.rs @@ -809,7 +809,7 @@ HELLO = "world" let mut cargo = build_info.into_base_cargo_config_with_log( request.package.clone(), request.target.clone(), - StarryBuildInfo::build_cargo_args(&request.target, false, &[]), + StarryBuildInfo::build_cargo_args(&request.target, &[]), ); let metadata = crate::build::workspace_metadata().unwrap(); From 59410b10bf93fa0e141c10d2401e8729ca97c359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=9D=BF?= Date: Wed, 27 May 2026 15:00:53 +0800 Subject: [PATCH 10/17] feat: add riscv_goldfish dependency and support for Goldfish RTC --- Cargo.lock | 1 + drivers/ax-driver/Cargo.toml | 5 +- drivers/ax-driver/src/time.rs | 51 ++++++++++++++----- .../build-riscv64gc-unknown-none-elf.toml | 2 + .../build-riscv64gc-unknown-none-elf.toml | 2 + .../build-riscv64gc-unknown-none-elf.toml | 2 + .../build-riscv64gc-unknown-none-elf.toml | 2 + 7 files changed, 50 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6e4741a49f..e255bda8f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -901,6 +901,7 @@ dependencies = [ "rdrive", "rdrive-macros", "realtek-rtl8125", + "riscv_goldfish", "rk3588-pci", "rockchip-npu", "rockchip-pm", diff --git a/drivers/ax-driver/Cargo.toml b/drivers/ax-driver/Cargo.toml index fe02a0e75e..1f05376de1 100644 --- a/drivers/ax-driver/Cargo.toml +++ b/drivers/ax-driver/Cargo.toml @@ -46,7 +46,7 @@ xhci-mmio = ["usb", "plat-dyn"] xhci-pci = ["usb"] serial = ["plat-dyn", "dep:some-serial"] sg2002-placeholder = ["plat-dyn"] -rtc = ["plat-dyn", "dep:ax-arm-pl031"] +rtc = ["plat-dyn", "dep:ax-arm-pl031", "dep:riscv_goldfish"] rknpu = ["plat-dyn", "rockchip-pm", "rockchip-soc", "dep:rockchip-npu"] rockchip-sdhci = [ "block", @@ -133,3 +133,6 @@ simple-ahci = { workspace = true, optional = true } some-serial = { workspace = true, optional = true } spin.workspace = true virtio-drivers = { workspace = true, optional = true } + +[target.'cfg(target_arch = "riscv64")'.dependencies] +riscv_goldfish = { version = "0.1", optional = true } diff --git a/drivers/ax-driver/src/time.rs b/drivers/ax-driver/src/time.rs index 590e194d51..eddffb2a87 100644 --- a/drivers/ax-driver/src/time.rs +++ b/drivers/ax-driver/src/time.rs @@ -1,6 +1,8 @@ -use ax_arm_pl031::Rtc; +use ax_arm_pl031::Rtc as Pl031Rtc; use log::{debug, info}; use rdrive::{PlatformDevice, probe::OnProbeError, register::FdtInfo}; +#[cfg(target_arch = "riscv64")] +use riscv_goldfish::Rtc as GoldfishRtc; use crate::mmio::iomap; @@ -10,11 +12,35 @@ crate::model_register!( priority: ProbePriority::DEFAULT, probe_kinds: &[ProbeKind::Fdt { compatibles: &["arm,pl031"], - on_probe: probe + on_probe: probe_pl031 }], ); -fn probe(info: FdtInfo<'_>, _plat_dev: PlatformDevice) -> Result<(), OnProbeError> { +#[cfg(target_arch = "riscv64")] +crate::model_register!( + name: "goldfish rtc", + level: ProbeLevel::PostKernel, + priority: ProbePriority::DEFAULT, + probe_kinds: &[ProbeKind::Fdt { + compatibles: &["google,goldfish-rtc"], + on_probe: probe_goldfish + }], +); + +fn probe_pl031(info: FdtInfo<'_>, _plat_dev: PlatformDevice) -> Result<(), OnProbeError> { + let mmio_base = map_first_reg(&info)?; + let rtc = unsafe { Pl031Rtc::new(mmio_base.as_ptr().cast()) }; + init_epoch_offset(info.node.name(), u64::from(rtc.get_unix_timestamp())) +} + +#[cfg(target_arch = "riscv64")] +fn probe_goldfish(info: FdtInfo<'_>, _plat_dev: PlatformDevice) -> Result<(), OnProbeError> { + let mmio_base = map_first_reg(&info)?; + let rtc = GoldfishRtc::new(mmio_base.as_ptr() as usize); + init_epoch_offset(info.node.name(), rtc.get_unix_timestamp()) +} + +fn map_first_reg(info: &FdtInfo<'_>) -> Result, OnProbeError> { let regs = info.node.regs(); let Some(base_reg) = regs.first() else { return Err(OnProbeError::other(alloc::format!( @@ -24,24 +50,21 @@ fn probe(info: FdtInfo<'_>, _plat_dev: PlatformDevice) -> Result<(), OnProbeErro }; let mmio_size = base_reg.size.unwrap_or(0x1000); - let mmio_base = iomap(base_reg.address as usize, mmio_size as usize)?; - let rtc = unsafe { Rtc::new(mmio_base.as_ptr().cast()) }; - let unix_timestamp = rtc.get_unix_timestamp(); + iomap(base_reg.address as usize, mmio_size as usize) +} + +fn init_epoch_offset(node_name: &str, unix_timestamp: u64) -> Result<(), OnProbeError> { if unix_timestamp == 0 { return Err(OnProbeError::other(alloc::format!( - "[{}] returned zero unix timestamp", - info.node.name() + "[{node_name}] returned zero unix timestamp" ))); } - let epoch_time_nanos = u64::from(unix_timestamp) * 1_000_000_000; + let epoch_time_nanos = unix_timestamp * 1_000_000_000; if axklib::time::try_init_epoch_offset(epoch_time_nanos) { - info!("Initialized wall clock from {}", info.node.name()); + info!("Initialized wall clock from {node_name}"); } else { - debug!( - "Skipping RTC {} because epoch offset is already initialized", - info.node.name() - ); + debug!("Skipping RTC {node_name} because epoch offset is already initialized",); } Ok(()) diff --git a/test-suit/starryos/normal/qemu-smp1/build-riscv64gc-unknown-none-elf.toml b/test-suit/starryos/normal/qemu-smp1/build-riscv64gc-unknown-none-elf.toml index 65cff80fdf..d5a03b3263 100644 --- a/test-suit/starryos/normal/qemu-smp1/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/starryos/normal/qemu-smp1/build-riscv64gc-unknown-none-elf.toml @@ -1,5 +1,7 @@ env = {AX_IP = "10.0.2.15", AX_GW = "10.0.2.2"} features = [ + "ax-feat/rtc", + "ax-driver/rtc", "ax-driver/serial", "ax-driver/virtio-blk", "ax-driver/virtio-net", diff --git a/test-suit/starryos/normal/qemu-smp4/build-riscv64gc-unknown-none-elf.toml b/test-suit/starryos/normal/qemu-smp4/build-riscv64gc-unknown-none-elf.toml index f8d2a9b987..a4668fafd3 100644 --- a/test-suit/starryos/normal/qemu-smp4/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/starryos/normal/qemu-smp4/build-riscv64gc-unknown-none-elf.toml @@ -1,5 +1,7 @@ env = {AX_IP = "10.0.2.15", AX_GW = "10.0.2.2"} features = [ + "ax-feat/rtc", + "ax-driver/rtc", "ax-driver/serial", "ax-driver/virtio-blk", "ax-driver/virtio-net", diff --git a/test-suit/starryos/stress/postgresql/build-riscv64gc-unknown-none-elf.toml b/test-suit/starryos/stress/postgresql/build-riscv64gc-unknown-none-elf.toml index 65cff80fdf..d5a03b3263 100644 --- a/test-suit/starryos/stress/postgresql/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/starryos/stress/postgresql/build-riscv64gc-unknown-none-elf.toml @@ -1,5 +1,7 @@ env = {AX_IP = "10.0.2.15", AX_GW = "10.0.2.2"} features = [ + "ax-feat/rtc", + "ax-driver/rtc", "ax-driver/serial", "ax-driver/virtio-blk", "ax-driver/virtio-net", diff --git a/test-suit/starryos/stress/stress-ng-0/build-riscv64gc-unknown-none-elf.toml b/test-suit/starryos/stress/stress-ng-0/build-riscv64gc-unknown-none-elf.toml index 65cff80fdf..d5a03b3263 100644 --- a/test-suit/starryos/stress/stress-ng-0/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/starryos/stress/stress-ng-0/build-riscv64gc-unknown-none-elf.toml @@ -1,5 +1,7 @@ env = {AX_IP = "10.0.2.15", AX_GW = "10.0.2.2"} features = [ + "ax-feat/rtc", + "ax-driver/rtc", "ax-driver/serial", "ax-driver/virtio-blk", "ax-driver/virtio-net", From 4a35043c73a655d69fcc0b50431d8cc7ea6d9839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=9D=BF?= Date: Wed, 27 May 2026 16:15:26 +0800 Subject: [PATCH 11/17] refactor(smp): replace cpu_idx with early_current_cpu_idx for better boot-time CPU identification --- .../someboot/src/arch/aarch64/paging/mod.rs | 2 +- components/someboot/src/arch/riscv64/mod.rs | 4 -- .../someboot/src/arch/riscv64/paging.rs | 2 +- components/someboot/src/arch/x86_64/paging.rs | 2 +- components/someboot/src/arch/x86_64/power.rs | 9 +++- components/someboot/src/lib.rs | 2 +- components/someboot/src/smp/mod.rs | 15 ++++-- platforms/axplat-dyn/src/boot.rs | 2 +- platforms/somehal/src/arch/aarch64/mod.rs | 2 +- platforms/somehal/src/arch/loongarch64/mod.rs | 2 +- platforms/somehal/src/arch/riscv64/mod.rs | 4 +- platforms/somehal/src/arch/riscv64/plic.rs | 46 ++++++++----------- platforms/somehal/src/arch/x86_64/mod.rs | 2 +- platforms/somehal/src/common.rs | 2 +- platforms/somehal/src/lib.rs | 2 +- 15 files changed, 49 insertions(+), 49 deletions(-) diff --git a/components/someboot/src/arch/aarch64/paging/mod.rs b/components/someboot/src/arch/aarch64/paging/mod.rs index bb10fe2e97..ae1bda059c 100644 --- a/components/someboot/src/arch/aarch64/paging/mod.rs +++ b/components/someboot/src/arch/aarch64/paging/mod.rs @@ -26,7 +26,7 @@ pub fn enable_mmu() -> ! { let mmu_entry_phys = super::entry::mmu_entry as *const () as usize; println!("MMU Entry point at physical address: {:#x}", mmu_entry_phys); - let meta = crate::smp::cpu_meta(crate::smp::cpu_idx()).unwrap(); + let meta = crate::smp::cpu_meta(crate::smp::early_current_cpu_idx()).unwrap(); let v_sp = meta.stack_top_virt; let v_entry = __kimage_va(mmu_entry_phys) as usize; diff --git a/components/someboot/src/arch/riscv64/mod.rs b/components/someboot/src/arch/riscv64/mod.rs index b7e498233f..74f4858680 100644 --- a/components/someboot/src/arch/riscv64/mod.rs +++ b/components/someboot/src/arch/riscv64/mod.rs @@ -287,10 +287,6 @@ impl ArchTrait for Arch { } fn cpu_on(hartid: usize, entry: usize, arg: usize) -> Result<(), CpuOnError> { - if hartid == Self::cpu_current_hartid() { - return Err(CpuOnError::AlreadyOn); - } - match sbi::hart_start(hartid, entry, arg) { Ok(()) => Ok(()), Err(sbi::HartStartError::AlreadyAvailable | sbi::HartStartError::AlreadyStarted) => { diff --git a/components/someboot/src/arch/riscv64/paging.rs b/components/someboot/src/arch/riscv64/paging.rs index 75fc4aa912..dff0fa8741 100644 --- a/components/someboot/src/arch/riscv64/paging.rs +++ b/components/someboot/src/arch/riscv64/paging.rs @@ -15,7 +15,7 @@ pub fn enable_mmu() -> ! { } let mmu_entry_phys = super::entry::mmu_entry as *const () as usize; - let meta = crate::smp::cpu_meta(crate::smp::cpu_idx()).unwrap(); + let meta = crate::smp::cpu_meta(crate::smp::early_current_cpu_idx()).unwrap(); let v_sp = meta.stack_top_virt; let v_entry = __kimage_va(mmu_entry_phys) as usize; diff --git a/components/someboot/src/arch/x86_64/paging.rs b/components/someboot/src/arch/x86_64/paging.rs index bcac10ab2a..181fa943b5 100644 --- a/components/someboot/src/arch/x86_64/paging.rs +++ b/components/someboot/src/arch/x86_64/paging.rs @@ -124,7 +124,7 @@ pub fn enable_mmu() -> ! { panic!("failed to setup x86_64 page table: {err:?}"); } - let meta = crate::smp::cpu_meta(crate::smp::cpu_idx()).unwrap(); + let meta = crate::smp::cpu_meta(crate::smp::early_current_cpu_idx()).unwrap(); let v_sp = meta.stack_top_virt; let v_entry = __kimage_va(super::entry::mmu_entry as *const () as usize) as usize; diff --git a/components/someboot/src/arch/x86_64/power.rs b/components/someboot/src/arch/x86_64/power.rs index 92948b482f..504e1b3846 100644 --- a/components/someboot/src/arch/x86_64/power.rs +++ b/components/someboot/src/arch/x86_64/power.rs @@ -132,8 +132,15 @@ pub(crate) fn notify_ap_started(apic_id: usize) { AP_BOOTED_ID.store(apic_id, Ordering::Release); } +fn current_apic_id() -> usize { + x86::cpuid::CpuId::new() + .get_feature_info() + .map(|info| info.initial_local_apic_id() as usize) + .unwrap_or(0) +} + pub(crate) fn cpu_on(apic_id: usize, entry: usize, arg: usize) -> Result<(), CpuOnError> { - if apic_id == crate::smp::cpu_hart_id() { + if apic_id == current_apic_id() { return Err(CpuOnError::AlreadyOn); } let apic_id = u8::try_from(apic_id).map_err(|_| CpuOnError::InvalidParameters)?; diff --git a/components/someboot/src/lib.rs b/components/someboot/src/lib.rs index d5679a68fc..c956b65b82 100644 --- a/components/someboot/src/lib.rs +++ b/components/someboot/src/lib.rs @@ -177,7 +177,7 @@ fn prime_entry() -> ! { } let entry = __someboot_main as *const () as usize; - let sp = crate::smp::cpu_meta(crate::smp::cpu_idx()) + let sp = crate::smp::cpu_meta(crate::smp::early_current_cpu_idx()) .unwrap() .stack_top; let sp = __percpu(sp); diff --git a/components/someboot/src/smp/mod.rs b/components/someboot/src/smp/mod.rs index 6d83fc5734..75e7d14929 100644 --- a/components/someboot/src/smp/mod.rs +++ b/components/someboot/src/smp/mod.rs @@ -104,18 +104,23 @@ pub fn percpu_data_ptr(idx: usize) -> Option<*mut u8> { layout::percpu_data_ptr(idx) } -pub fn cpu_hart_id() -> usize { +/// Returns the current hardware CPU ID from the early boot register convention. +/// +/// On RISC-V this reads `tp`, which is only a boot-time hart ID scratch +/// register before handing control to the runtime. Runtime code must use its +/// own per-CPU current-CPU reader instead. +pub fn early_current_hart_id() -> usize { Arch::cpu_current_hartid() } -pub fn cpu_idx() -> usize { - let hart_id = cpu_hart_id(); +pub fn early_current_cpu_idx() -> usize { + let hart_id = early_current_hart_id(); cpu_id_to_idx(hart_id) .unwrap_or_else(|| panic!("Current CPU hart id {hart_id:#x} not found in CPU list")) } -pub fn try_cpu_idx() -> Option { - cpu_id_to_idx(cpu_hart_id()) +pub fn try_early_cpu_idx() -> Option { + cpu_id_to_idx(early_current_hart_id()) } pub fn cpu_id_to_idx(hart_id: usize) -> Option { diff --git a/platforms/axplat-dyn/src/boot.rs b/platforms/axplat-dyn/src/boot.rs index d1b16cc13a..667a2860d3 100644 --- a/platforms/axplat-dyn/src/boot.rs +++ b/platforms/axplat-dyn/src/boot.rs @@ -11,7 +11,7 @@ fn main() -> ! { args = fdt; } - ax_plat::call_main(somehal::smp::cpu_idx(), args) + ax_plat::call_main(somehal::smp::early_current_cpu_idx(), args) } #[somehal::secondary_entry] diff --git a/platforms/somehal/src/arch/aarch64/mod.rs b/platforms/somehal/src/arch/aarch64/mod.rs index 063fb5ae98..2200602ced 100644 --- a/platforms/somehal/src/arch/aarch64/mod.rs +++ b/platforms/somehal/src/arch/aarch64/mod.rs @@ -24,7 +24,7 @@ impl PlatOp for Plat { fn secondary_init() {} - fn secondary_init_intc() { + fn secondary_init_intc(_cpu_idx: usize) { gic::init_current_cpu(); } diff --git a/platforms/somehal/src/arch/loongarch64/mod.rs b/platforms/somehal/src/arch/loongarch64/mod.rs index 589a8c1266..078425f223 100644 --- a/platforms/somehal/src/arch/loongarch64/mod.rs +++ b/platforms/somehal/src/arch/loongarch64/mod.rs @@ -15,7 +15,7 @@ impl PlatOp for Plat { fn secondary_init() {} - fn secondary_init_intc() {} + fn secondary_init_intc(_cpu_idx: usize) {} fn secondary_init_systick() {} } diff --git a/platforms/somehal/src/arch/riscv64/mod.rs b/platforms/somehal/src/arch/riscv64/mod.rs index 6d0d0fee40..55552474e4 100644 --- a/platforms/somehal/src/arch/riscv64/mod.rs +++ b/platforms/somehal/src/arch/riscv64/mod.rs @@ -27,8 +27,8 @@ impl PlatOp for Plat { fn secondary_init() {} - fn secondary_init_intc() { - plic::secondary_init_intc(); + fn secondary_init_intc(cpu_idx: usize) { + plic::secondary_init_intc(cpu_idx); } fn secondary_init_systick() {} diff --git a/platforms/somehal/src/arch/riscv64/plic.rs b/platforms/somehal/src/arch/riscv64/plic.rs index 27832dbe42..a4ac2a72e6 100644 --- a/platforms/somehal/src/arch/riscv64/plic.rs +++ b/platforms/somehal/src/arch/riscv64/plic.rs @@ -2,7 +2,7 @@ use alloc::{format, vec::Vec}; use core::{ num::NonZeroU32, ptr::NonNull, - sync::atomic::{AtomicPtr, AtomicUsize, Ordering}, + sync::atomic::{AtomicPtr, Ordering}, }; use ax_riscv_plic::{PLICRegs, Plic, PlicIrqHandler}; @@ -28,7 +28,6 @@ const DEFAULT_PLIC_SIZE: usize = 0x400_0000; static IRQ_HANDLER: StaticCell = StaticCell::uninit(); static CURRENT_CPU_ID: AtomicPtr<()> = AtomicPtr::new(core::ptr::null_mut()); -static CURRENT_CPU_ID_READY: AtomicUsize = AtomicUsize::new(0); module_driver!( name: "RISC-V PLIC", @@ -48,10 +47,7 @@ pub fn systick_irq() -> rdrive::IrqId { S_TIMER.into() } -pub fn register_current_cpu_id(cpu_idx: usize, reader: fn() -> usize) { - if let Some(bit) = cpu_ready_bit(cpu_idx) { - CURRENT_CPU_ID_READY.fetch_or(bit, Ordering::Release); - } +pub fn register_current_cpu_id(_cpu_idx: usize, reader: fn() -> usize) { CURRENT_CPU_ID.store(reader as *mut (), Ordering::Release); } @@ -109,10 +105,10 @@ pub fn irq_handler_with_raw(raw: usize) -> Option { } } -pub fn secondary_init_intc() { +pub fn secondary_init_intc(cpu_idx: usize) { enable_local_interrupts(); if let Some(handler) = get_irq_handler() { - handler.init_current_context(); + handler.init_context(cpu_idx); } } @@ -288,13 +284,25 @@ impl RiscvPlicIrqHandler { fn init_current_context(&self) { if let Some(context) = self.current_context() { - self.inner.init_by_context(context); - trace!("PLIC context {context} initialized"); + self.init_context_by_context_id(context); } else { warn_missing_current_context(); } } + fn init_context(&self, cpu_idx: usize) { + if let Some(context) = self.context_by_cpu.get(cpu_idx).and_then(|ctx| *ctx) { + self.init_context_by_context_id(context); + } else { + warn!("PLIC supervisor context for logical CPU {cpu_idx} is not found"); + } + } + + fn init_context_by_context_id(&self, context: usize) { + self.inner.init_by_context(context); + trace!("PLIC context {context} initialized"); + } + fn claim_current(&self) -> Option { let Some(context) = self.current_context() else { warn_missing_current_context(); @@ -347,27 +355,11 @@ fn current_context(context_by_cpu: &[Option]) -> Option { fn current_cpu_idx() -> Option { let reader = CURRENT_CPU_ID.load(Ordering::Acquire); if !reader.is_null() { - if let Some(cpu_idx) = someboot::smp::try_cpu_idx() - && !cpu_reader_is_ready(cpu_idx) - { - return Some(cpu_idx); - } - let reader = unsafe { core::mem::transmute::<*mut (), fn() -> usize>(reader) }; return Some(reader()); } - someboot::smp::try_cpu_idx() -} - -fn cpu_ready_bit(cpu_idx: usize) -> Option { - (cpu_idx < usize::BITS as usize).then(|| 1usize << cpu_idx) -} - -fn cpu_reader_is_ready(cpu_idx: usize) -> bool { - cpu_ready_bit(cpu_idx) - .map(|bit| CURRENT_CPU_ID_READY.load(Ordering::Acquire) & bit != 0) - .unwrap_or(false) + someboot::smp::try_early_cpu_idx() } fn warn_missing_current_context() { diff --git a/platforms/somehal/src/arch/x86_64/mod.rs b/platforms/somehal/src/arch/x86_64/mod.rs index b4da28abf0..be2d02e560 100644 --- a/platforms/somehal/src/arch/x86_64/mod.rs +++ b/platforms/somehal/src/arch/x86_64/mod.rs @@ -22,7 +22,7 @@ impl PlatOp for Plat { fn secondary_init() {} - fn secondary_init_intc() {} + fn secondary_init_intc(_cpu_idx: usize) {} fn secondary_init_systick() {} } diff --git a/platforms/somehal/src/common.rs b/platforms/somehal/src/common.rs index 2506a2faad..d36fe418d7 100644 --- a/platforms/somehal/src/common.rs +++ b/platforms/somehal/src/common.rs @@ -21,7 +21,7 @@ pub trait PlatOp { fn secondary_init(); - fn secondary_init_intc(); + fn secondary_init_intc(cpu_idx: usize); fn secondary_init_systick(); diff --git a/platforms/somehal/src/lib.rs b/platforms/somehal/src/lib.rs index b3f7f66212..bec4b660b3 100644 --- a/platforms/somehal/src/lib.rs +++ b/platforms/somehal/src/lib.rs @@ -59,7 +59,7 @@ pub fn __somehal_secondary_default() -> ! { fn secondary_entry() -> ! { someboot::set_kernel_page_table_paddr(meta.primary_table_paddr); arch::Plat::secondary_init(); - arch::Plat::secondary_init_intc(); + arch::Plat::secondary_init_intc(meta.cpu_idx); arch::Plat::secondary_init_systick(); unsafe extern "Rust" { From 954843b295edab96fc823d19a27839851036190e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=9D=BF?= Date: Wed, 27 May 2026 17:34:05 +0800 Subject: [PATCH 12/17] feat(build): add starry-kernel/input feature to the build configuration --- .../normal/qemu-smp1/build-riscv64gc-unknown-none-elf.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/test-suit/starryos/normal/qemu-smp1/build-riscv64gc-unknown-none-elf.toml b/test-suit/starryos/normal/qemu-smp1/build-riscv64gc-unknown-none-elf.toml index d5a03b3263..66c877a2a2 100644 --- a/test-suit/starryos/normal/qemu-smp1/build-riscv64gc-unknown-none-elf.toml +++ b/test-suit/starryos/normal/qemu-smp1/build-riscv64gc-unknown-none-elf.toml @@ -8,6 +8,7 @@ features = [ "ax-driver/virtio-gpu", "ax-driver/virtio-input", "ax-driver/virtio-socket", + "starry-kernel/input", ] log = "Warn" plat_dyn = true From 25f9dbd7dd922a23c68647b39617bb86c121a09a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=9D=BF?= <34859362+ZR233@users.noreply.github.com> Date: Wed, 27 May 2026 17:15:29 +0800 Subject: [PATCH 13/17] refactor(axruntime): remove alloc feature, make it unconditional (#985) alloc is needed by every consumer of axruntime. Remove the alloc feature entirely and make ax-alloc a required dependency. Propagating changes to axfeat to remove the now-unnecessary alloc forwarding from 15 features. Co-authored-by: Claude Opus 4.7 --- os/arceos/api/axfeat/Cargo.toml | 27 +++++++++++--------------- os/arceos/modules/axruntime/Cargo.toml | 10 ++++------ os/arceos/modules/axruntime/src/lib.rs | 14 +------------ 3 files changed, 16 insertions(+), 35 deletions(-) diff --git a/os/arceos/api/axfeat/Cargo.toml b/os/arceos/api/axfeat/Cargo.toml index f28021a749..05657df2ec 100644 --- a/os/arceos/api/axfeat/Cargo.toml +++ b/os/arceos/api/axfeat/Cargo.toml @@ -11,7 +11,7 @@ license.workspace = true default = ["alloc"] # Multicore -smp = ["alloc", "ax-hal/smp", "ax-runtime/smp", "ax-task?/smp", "ax-kspin/smp"] +smp = ["ax-hal/smp", "ax-runtime/smp", "ax-task?/smp", "ax-kspin/smp"] # Floating point/SIMD fp-simd = ["ax-hal/fp-simd"] @@ -21,7 +21,7 @@ uspace = ["ax-hal/uspace", "ax-task?/uspace"] hv = ["ax-hal/hv"] # Interrupts -irq = ["alloc", "ax-hal/irq", "ax-runtime/irq", "ax-task?/irq", "ax-driver?/irq"] +irq = ["ax-hal/irq", "ax-runtime/irq", "ax-task?/irq", "ax-driver?/irq"] ipi = ["irq", "dep:ax-ipi", "ax-hal/ipi", "ax-runtime/ipi", "ax-task?/ipi"] # Custom or default platforms @@ -43,20 +43,19 @@ aarch64-gic-v3 = ["ax-hal/aarch64-gic-v3"] aarch64-cntv-timer = ["ax-hal/aarch64-cntv-timer"] # Memory -alloc = ["ax-alloc", "ax-runtime/alloc"] +alloc = ["ax-alloc"] alloc-tlsf = ["ax-alloc/tlsf"] alloc-slab = ["ax-alloc/slab"] alloc-buddy = ["ax-alloc/buddy"] -buddy-slab = ["alloc", "ax-runtime/buddy-slab"] +buddy-slab = ["ax-runtime/buddy-slab"] page-alloc-64g = ["ax-alloc/page-alloc-64g"] # up to 64G memory capacity page-alloc-4g = ["ax-alloc/page-alloc-4g"] # up to 4G memory capacity -paging = ["alloc", "ax-hal/paging", "ax-runtime/paging"] -tls = ["alloc", "ax-hal/tls", "ax-runtime/tls", "ax-task?/tls"] -dma = ["alloc", "paging"] +paging = ["ax-hal/paging", "ax-runtime/paging"] +tls = ["ax-hal/tls", "ax-runtime/tls", "ax-task?/tls"] +dma = ["paging"] # Multi-threading and scheduler multitask = [ - "alloc", "ax-task/multitask", "ax-sync/multitask", "ax-runtime/multitask", @@ -76,31 +75,28 @@ stack-guard-page = [ # File system fs = [ - "alloc", "paging", "dep:ax-fs", "ax-runtime/fs", ] # TODO: try to remove "paging" -fs-ng = ["alloc", "paging", "dep:ax-fs-ng", "ax-runtime/fs-ng"] +fs-ng = ["paging", "dep:ax-fs-ng", "ax-runtime/fs-ng"] fs-ng-ext4 = ["fs-ng", "ax-fs-ng/ext4"] fs-ng-fat = ["fs-ng", "ax-fs-ng/fat"] fs-ng-times = ["fs-ng", "ax-fs-ng/times"] # Networking net = [ - "alloc", "paging", "irq", "multitask", "dep:ax-net", "ax-runtime/net", ] -net-ng = ["alloc", "paging", "irq", "multitask", "dep:ax-net-ng", "ax-runtime/net-ng"] +net-ng = ["paging", "irq", "multitask", "dep:ax-net-ng", "ax-runtime/net-ng"] vsock = ["ax-runtime/vsock"] # Display display = [ - "alloc", "paging", "dep:ax-display", "ax-runtime/display", @@ -108,7 +104,6 @@ display = [ # Input input = [ - "alloc", "paging", "dep:ax-input", "ax-runtime/input", @@ -118,8 +113,8 @@ input = [ rtc = ["ax-hal/rtc", "ax-runtime/rtc"] # Backtrace -backtrace = ["alloc", "axbacktrace/alloc"] -dwarf = ["alloc", "axbacktrace/dwarf"] +backtrace = ["axbacktrace/alloc"] +dwarf = ["axbacktrace/dwarf"] [dependencies] ax-alloc = { workspace = true, optional = true, features = ["default"] } diff --git a/os/arceos/modules/axruntime/Cargo.toml b/os/arceos/modules/axruntime/Cargo.toml index 79973b8749..65230c060e 100644 --- a/os/arceos/modules/axruntime/Cargo.toml +++ b/os/arceos/modules/axruntime/Cargo.toml @@ -10,15 +10,14 @@ version = "0.5.16" [features] default = [] -alloc = ["dep:ax-alloc"] -buddy-slab = ["alloc", "ax-alloc/buddy-slab"] +buddy-slab = ["ax-alloc/buddy-slab"] dma = ["paging"] ipi = ["dep:ax-ipi"] irq = ["ax-hal/irq", "ax-task?/irq", "dep:ax-percpu"] multitask = ["ax-task/multitask"] -paging = ["alloc", "ax-hal/paging", "dep:ax-mm", "dep:axklib"] +paging = ["ax-hal/paging", "dep:ax-mm", "dep:axklib"] rtc = [] -smp = ["alloc", "ax-hal/smp", "ax-task?/smp"] +smp = ["ax-hal/smp", "ax-task?/smp"] stack-guard-page = ["multitask", "paging", "ax-task/stack-guard-page"] tls = ["ax-hal/tls", "ax-task?/tls"] @@ -32,7 +31,6 @@ plat-dyn = [ "smp", "stack-guard-page", "tls", - "alloc", ] display = ["dep:ax-display", "ax-driver/display"] @@ -58,7 +56,7 @@ net-ng = ["dep:ax-net-ng", "dep:rd-net", "dep:spin", "dep:axklib", "ax-driver/ne vsock = ["net-ng", "ax-net-ng/vsock", "ax-driver/vsock"] [dependencies] -ax-alloc = {workspace = true, optional = true, features = ["default"]} +ax-alloc = {workspace = true, features = ["default"]} ax-config = {workspace = true} ax-crate-interface = {workspace = true} ax-ctor-bare = {workspace = true} diff --git a/os/arceos/modules/axruntime/src/lib.rs b/os/arceos/modules/axruntime/src/lib.rs index c9f0b9fe50..61cba02dee 100644 --- a/os/arceos/modules/axruntime/src/lib.rs +++ b/os/arceos/modules/axruntime/src/lib.rs @@ -19,7 +19,6 @@ //! //! # Cargo Features //! -//! - `alloc`: Enable global memory allocator. //! - `paging`: Enable page table manipulation support. //! - `irq`: Enable interrupt handling support. //! - `multitask`: Enable multi-threading support. @@ -56,15 +55,6 @@ pub use ax_hal as hal; #[cfg(feature = "smp")] pub use self::mp::rust_main_secondary; -#[cfg(any( - all(any(feature = "fs", feature = "fs-ng"), not(feature = "plat-dyn")), - all(any(feature = "fs", feature = "fs-ng"), feature = "plat-dyn"), - feature = "net", - feature = "net-ng", - feature = "display", - feature = "input", - feature = "vsock" -))] extern crate alloc; const LOGO: &str = r#" @@ -166,7 +156,7 @@ pub fn rust_main(cpu_id: usize, arg: usize) -> ! { ax_hal::mem::clear_bss() }; ax_hal::percpu::init_primary(cpu_id); - #[cfg(all(feature = "alloc", feature = "buddy-slab"))] + #[cfg(feature = "buddy-slab")] // After per-CPU init, before scheduler/IPI/IRQ paths can allocate. ax_alloc::init_percpu_slab(cpu_id); ax_hal::init_early(cpu_id, arg); @@ -214,7 +204,6 @@ pub fn rust_main(cpu_id: usize, arg: usize) -> ! { ); } - #[cfg(feature = "alloc")] init_allocator(); { @@ -357,7 +346,6 @@ pub fn rust_main(cpu_id: usize, arg: usize) -> ! { } } -#[cfg(feature = "alloc")] fn init_allocator() { use ax_hal::mem::{MemRegionFlags, memory_regions, phys_to_virt}; From 2109d06b15c675ab2756fdd50e5199debc2e4788 Mon Sep 17 00:00:00 2001 From: ZCShou <72115@163.com> Date: Wed, 27 May 2026 18:44:26 +0800 Subject: [PATCH 14/17] Remove range-alloc-arceos crate and its associated files (#991) - Deleted LICENSE, LICENSE.APACHE, LICENSE.MIT, README.md, README_CN.md, and src/lib.rs files. - Removed tests and examples related to the range allocator functionality. --- Cargo.lock | 5 - Cargo.toml | 1 - docs/docs/components/crates/axdevice.md | 8 +- docs/docs/components/crates/axvm.md | 2 +- .../components/crates/range-alloc-arceos.md | 248 --------- docs/docs/components/layers.md | 6 +- docs/docs/components/overview.md | 1 - memory/range-alloc-arceos/.github/config.json | 10 - .../.github/workflows/check.yml | 66 --- .../.github/workflows/deploy.yml | 126 ----- .../.github/workflows/push.yml | 147 ------ .../.github/workflows/release.yml | 160 ------ .../.github/workflows/test.yml | 50 -- memory/range-alloc-arceos/.gitignore | 16 - memory/range-alloc-arceos/CHANGELOG.md | 14 - memory/range-alloc-arceos/Cargo.toml | 13 - memory/range-alloc-arceos/LICENSE | 201 ------- memory/range-alloc-arceos/LICENSE.APACHE | 176 ------- memory/range-alloc-arceos/LICENSE.MIT | 21 - memory/range-alloc-arceos/README.md | 81 --- memory/range-alloc-arceos/README_CN.md | 81 --- memory/range-alloc-arceos/src/lib.rs | 491 ------------------ memory/range-alloc-arceos/tests/test.rs | 60 --- scripts/repo/repos.csv | 1 - scripts/test/std_crates.csv | 1 - virtualization/axdevice/Cargo.toml | 1 - virtualization/axdevice/src/device.rs | 20 +- virtualization/axdevice/src/lib.rs | 1 + virtualization/axdevice/src/range_alloc.rs | 145 ++++++ 29 files changed, 164 insertions(+), 1989 deletions(-) delete mode 100644 docs/docs/components/crates/range-alloc-arceos.md delete mode 100644 memory/range-alloc-arceos/.github/config.json delete mode 100644 memory/range-alloc-arceos/.github/workflows/check.yml delete mode 100644 memory/range-alloc-arceos/.github/workflows/deploy.yml delete mode 100644 memory/range-alloc-arceos/.github/workflows/push.yml delete mode 100644 memory/range-alloc-arceos/.github/workflows/release.yml delete mode 100644 memory/range-alloc-arceos/.github/workflows/test.yml delete mode 100644 memory/range-alloc-arceos/.gitignore delete mode 100644 memory/range-alloc-arceos/CHANGELOG.md delete mode 100644 memory/range-alloc-arceos/Cargo.toml delete mode 100644 memory/range-alloc-arceos/LICENSE delete mode 100644 memory/range-alloc-arceos/LICENSE.APACHE delete mode 100644 memory/range-alloc-arceos/LICENSE.MIT delete mode 100644 memory/range-alloc-arceos/README.md delete mode 100644 memory/range-alloc-arceos/README_CN.md delete mode 100644 memory/range-alloc-arceos/src/lib.rs delete mode 100644 memory/range-alloc-arceos/tests/test.rs create mode 100644 virtualization/axdevice/src/range_alloc.rs diff --git a/Cargo.lock b/Cargo.lock index 136fba9eb6..b35b735342 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1732,7 +1732,6 @@ dependencies = [ "axvmconfig", "cfg-if", "log", - "range-alloc-arceos", "riscv_vplic", ] @@ -6477,10 +6476,6 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" -[[package]] -name = "range-alloc-arceos" -version = "0.3.9" - [[package]] name = "ranges-ext" version = "0.6.4" diff --git a/Cargo.toml b/Cargo.toml index f1467fc54f..0b26287924 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -265,7 +265,6 @@ enumerate = { version = "0.1.1", path = "drivers/examples/enumerate" } eth-intel = { version = "0.1.2", path = "drivers/net/eth-intel" } loongarch_vcpu = { version = "0.5.3", path = "virtualization/loongarch_vcpu" } mingo = { version = "0.8.3", path = "os/arceos/tools/raspi4/chainloader" } -range-alloc-arceos = { version = "0.3.9", path = "memory/range-alloc-arceos" } riscv-h = { version = "0.4.7", path = "virtualization/riscv-h" } riscv_vcpu = { version = "0.5.9", path = "virtualization/riscv_vcpu" } riscv_vplic = { version = "0.4.12", path = "virtualization/riscv_vplic" } diff --git a/docs/docs/components/crates/axdevice.md b/docs/docs/components/crates/axdevice.md index 952d2d431f..272549dc15 100644 --- a/docs/docs/components/crates/axdevice.md +++ b/docs/docs/components/crates/axdevice.md @@ -65,7 +65,7 @@ - `emu_mmio_devices` - `emu_sys_reg_devices` - `emu_port_devices` -- `ivc_channel: Option>>` +- `ivc_channel: Option>` 前三者决定地址访问分发,最后一个则是 Inter-VM Communication 区间分配器,用于在配置的 IVC GPA 范围内按 4K 对齐切片。 @@ -79,7 +79,7 @@ flowchart TD B --> C[遍历 EmulatedDeviceConfig] C --> D{按 EmulatedDeviceType 匹配} D --> E[实例化具体设备对象] - D --> F[初始化 IVC RangeAllocator] + D --> F[初始化内部 IVC RangeAllocator] D --> G[不支持类型发出 warn] E --> H[加入 MMIO/sysreg/port 容器] ``` @@ -194,7 +194,7 @@ let mut devices = AxVmDevices::new(config); `IVCChannel` 在本 crate 中不是一个 MMIO 设备对象,而是一个 GPA 区间分配器: -- 初始化时只建立 `RangeAllocator`。 +- 初始化时只建立 `axdevice` 内部的 IVC `RangeAllocator`。 - 分配和释放必须满足 4K 对齐。 - 重复声明多个 IVCChannel 配置时,仅首次生效,后续配置会被忽略并打印告警。 @@ -209,7 +209,7 @@ let mut devices = AxVmDevices::new(config); | `axdevice_base` | 统一设备 trait 定义 | | `axvmconfig` | 设备配置和设备类型枚举 | | `axaddrspace` | GPA、端口、系统寄存器地址类型与访问宽度 | -| `range-alloc-arceos` | IVC 区间分配 | +| 内部 `range_alloc` 模块 | IVC 区间分配 | | `memory_addr` | 4K 对齐检查等辅助能力 | | `ax-errno` | 统一错误类型 | | `spin` | IVC 分配器锁 | diff --git a/docs/docs/components/crates/axvm.md b/docs/docs/components/crates/axvm.md index 55a62c2a51..7debb9ff99 100644 --- a/docs/docs/components/crates/axvm.md +++ b/docs/docs/components/crates/axvm.md @@ -137,7 +137,7 @@ graph LR ### 间接依赖 - `ax-page-table-multiarch`、`ax-page-table-entry`:通过地址空间和页表路径参与 VM 内存管理。 -- `ax-memory-set`、`range-alloc-arceos` 等:在地址空间和内存建模路径上间接提供支撑。 +- `ax-memory-set` 等:在地址空间和内存建模路径上间接提供支撑。 - `axvisor_api` 生态:更多出现在消费者侧,但会影响 `axvm` 的宿主接入方式。 ### 3.3 关键直接消费者 diff --git a/docs/docs/components/crates/range-alloc-arceos.md b/docs/docs/components/crates/range-alloc-arceos.md deleted file mode 100644 index 7152decedf..0000000000 --- a/docs/docs/components/crates/range-alloc-arceos.md +++ /dev/null @@ -1,248 +0,0 @@ -# `range-alloc-arceos` - -> 路径:`memory/range-alloc-arceos` -> 类型:库 crate -> 分层:组件层 / 区间分配算法组件 -> 版本:`0.1.4` -> 文档依据:当前仓库源码、`Cargo.toml`、`README.md`、`src/lib.rs`、`tests/test.rs`、`virtualization/axdevice/src/device.rs`、`virtualization/axvm/src/vm.rs`、`os/axvisor/src/vmm/hvc.rs` - -`range-alloc-arceos` 的真实定位是一个**泛型连续区间分配器**。它管理的是一个初始范围上的“哪些子区间空闲、哪些子区间已占用”,并提供 best-fit 分配与回收合并逻辑。它不是页分配器,不处理地址映射,不理解设备,不负责对齐策略,更不是完整的内存管理子系统。 - -## 架构设计 - -### 设计定位 - -这个 crate 的问题模型非常明确: - -- 有一个初始区间 `start..end` -- 需要不断从中分配连续子区间 -- 需要在释放时把相邻空闲区间重新合并 -- 希望尽量降低碎片化 - -因此它选择的核心数据结构不是树或位图,而是: - -- 一个有序的 `Vec> free_ranges` - -并把已分配区间看作“初始区间减去空闲区间”的补集。 - -### 1.2 核心数据结构 - -`RangeAllocator` 内部只有两项状态: - -| 字段 | 作用 | -| --- | --- | -| `initial_range` | 整个分配器负责管理的总范围 | -| `free_ranges` | 当前空闲区间表,按起始地址升序排列且互不重叠 | - -这两个不变量非常关键: - -- `free_ranges` 必须有序 -- `free_ranges` 之间不能重叠 - -几乎所有接口都围绕维护这两个不变量展开。 - -### 1.3 分配策略:best-fit - -`allocate_range(length)` 的实现会遍历所有空闲区间,并选择: - -- 能满足请求的最小空闲区间 - -这是一种典型的 best-fit 策略。它的好处是: - -- 优先消耗最贴合请求的空闲块 -- 尽量保留大块连续空间 - -若找不到足够大的单个区间,则返回: - -- `RangeAllocationError { fragmented_free_length }` - -其中 `fragmented_free_length` 表示把所有空闲区间长度加起来后,总共还有多少空闲量。这个字段能帮助调用者区分: - -- 是真的没空间了 -- 还是只是碎片太多,凑不出连续区间 - -### 1.4 回收策略:邻接合并 - -`free_range(range)` 的逻辑重点不在简单插入,而在合并: - -- 如果与左邻接,则与左合并 -- 如果与右邻接,则与右合并 -- 如果左右都邻接,则把三段合成一段 -- 否则在有序位置插入 - -源码中还有断言确保: - -- 释放区间必须位于 `initial_range` 内 -- 区间必须非空 -- 插入后不会与现有空闲区间重叠 - -这意味着: - -- 双重释放或越界释放不是被“静默忽略”,而是会触发断言 - -### 1.5 扩容与观察接口 - -除了分配/回收,这个 crate 还提供了几个非常实用的辅助接口: - -- `grow_to(new_end)`:扩展管理上界 -- `allocated_ranges()`:通过空闲表反推出当前已分配区间 -- `reset()`:恢复到初始全空闲状态 -- `is_empty()`:检查是否尚未分配任何区间 -- `total_available()`:统计所有空闲区间的总长度 - -尤其是 `allocated_ranges()`,说明这个分配器不仅能“给空间”,也适合做状态观察和调试。 - -### 1.6 与 Axvisor 当前实现的真实关系 - -当前仓库里的真实调用链非常清晰: - -1. `axdevice::AxVmDevices` 在 `IVCChannel` 设备配置初始化时,创建 `RangeAllocator` -2. 这个区间的范围来自 IVC 共享内存的 guest physical address 空间 -3. `axvm::VM::alloc_ivc_channel()` 先把请求大小向上对齐到 4K -4. 然后调用 `devices.alloc_ivc_channel()`,最终落到 `RangeAllocator::allocate_range()` -5. `os/axvisor/src/vmm/hvc.rs` 在处理 IVC hypercall 时使用这套分配/回收能力 - -这条链路很重要,因为它清楚地说明了: - -- 对齐是 `axvm` 做的,不是本 crate 做的 -- 地址映射是 `axdevice` / `axvm` / `axvisor` 做的,不是本 crate 做的 -- 本 crate 只是区间分配算法核心 - -## 核心功能 - -### 功能概览 - -- 用初始区间构造分配器 -- 按 best-fit 分配连续区间 -- 回收区间并自动合并相邻空闲块 -- 动态扩展管理范围上界 -- 枚举已分配区间 -- 查询空闲总量与是否为空 - -### 2.2 当前仓库中的典型调用链 - -真实调用链可以概括为: - -`range-alloc-arceos` -> `axdevice::AxVmDevices` -> `axvm::VM::{alloc_ivc_channel, release_ivc_channel}` -> `os/axvisor::vmm::hvc` - -也就是说,它当前主要服务于: - -- Axvisor 的 IVC 共享内存 GPA 区间管理 - -### 边界说明 - -`range-alloc-arceos` 不负责: - -- 地址对齐 -- 物理页分配 -- 页表映射 -- 内存清零 -- 共享内存元数据管理 - -它只是一个**泛型区间分配算法组件**。 - -## 依赖关系 - -### 直接依赖 - -该 crate 没有额外三方依赖,主要依靠: - -- `alloc::vec::Vec` -- `core::ops::Range` - -完成实现。 - -### 主要消费者 - -当前仓库内可确认的直接消费者: - -- `axdevice` - -明确可见的间接链路: - -- `range-alloc-arceos` -> `axdevice` -> `axvm` -> `os/axvisor` - -### 3.3 关系解读 - -| 层级 | 角色 | -| --- | --- | -| `range-alloc-arceos` | 连续区间分配算法 | -| `axdevice` | 为 VM 设备层提供 IVC GPA 区间池 | -| `axvm` | 负责对齐请求并包装返回值 | -| `os/axvisor` | 在 HyperCall 处理中真正消费分配结果 | - -## 开发指南 - -### 4.1 适合什么时候使用 - -适合使用该 crate 的场景是: - -- 资源天然可以表达为一个线性区间 -- 分配单位是“连续范围”而不是单点 -- 希望能观察碎片化情况 -- 对齐策略可以由上层单独处理 - -不适合直接把它当成: - -- 伙伴系统 -- 物理页分配器 -- 完整地址空间管理器 - -### 4.2 维护时的关键注意事项 - -- `free_ranges` 的有序、不重叠不变量必须始终保持 -- `free_range()` 的断言意味着重叠回收会直接失败,不是容错逻辑 -- 若要新增“带对齐分配”接口,应明确这是否属于本 crate 的职责扩张 -- `T` 的 trait bound 是经过精简设计的,不要轻易扩大或改变数值语义 - -### 4.3 与上层系统的职责分工 - -- 大小 4K 对齐:`axvm` -- GPA 空间来源:`axdevice` -- IVC 映射与共享内存语义:`axvisor` -- 连续区间 best-fit 分配/合并:本 crate - -这条分工线非常清楚,文档里不能把它写成“IVC 管理模块”。 - -## 测试 - -### 测试覆盖 - -当前测试已经相对充分: - -- `src/lib.rs` 中有较多单元测试 -- `tests/test.rs` 还有额外集成测试 - -现有测试覆盖了: - -- 基本分配/释放 -- 空间耗尽 -- `grow_to()` -- 中间空洞 -- best-fit 选择 -- 邻接合并 -- 碎片化行为 - -### 5.2 建议补充的测试 - -- double free / 重叠 free 的 `should_panic` 测试 -- 与 `axdevice` / `axvm` 结合的 4K 对齐集成测试 -- 更大整数类型或边界类型参数测试 - -### 5.3 风险点 - -- 如果文档忽略“对齐由上层完成”,调用者很容易误用 -- `free_range()` 的断言语义需要明确,否则回收错误会在运行时直接崩溃 -- best-fit 不是唯一策略,今后若替换策略需要同步评估上层碎片行为 - -## 跨项目定位 - -| 项目 | 位置 | 角色 | 说明 | -| --- | --- | --- | --- | -| ArceOS | 当前仓库未见直接接线 | 通用区间算法组件 | 目前不在 ArceOS 主线路径上 | -| StarryOS | 当前仓库未见直接接线 | 通用区间算法组件 | 尚未看到直接使用 | -| Axvisor | `axdevice` / `axvm` / `hvc` IVC 链路 | IVC GPA 连续区间分配算法 | 当前最明确、最真实的使用场景 | - -## 总结 - -`range-alloc-arceos` 的价值在于把“连续区间 best-fit 分配 + 合并回收”这件事做成了一个独立、泛型、`no_std` 友好的算法组件。当前仓库里它主要服务于 Axvisor 的 IVC GPA 区间管理,但它本身并不理解 IVC、设备或内存映射。理解它时最重要的边界,就是把它看成**区间分配算法**,而不是更高层的资源子系统。 diff --git a/docs/docs/components/layers.md b/docs/docs/components/layers.md index c781aa0ccc..c71560dab7 100644 --- a/docs/docs/components/layers.md +++ b/docs/docs/components/layers.md @@ -110,7 +110,6 @@ flowchart TB | 0 | 基础层(无仓库内直接依赖) | 组件层 | `axpoll` | `0.3.2` | `components/axpoll` | | 0 | 基础层(无仓库内直接依赖) | 组件层 | `axvisor_api_proc` | `0.5.0` | `virtualization/axvisor_api_proc` | | 0 | 基础层(无仓库内直接依赖) | 组件层 | `bitmap-allocator` | `0.4.1` | `memory/bitmap-allocator` | -| 0 | 基础层(无仓库内直接依赖) | 组件层 | `range-alloc-arceos` | `0.3.4` | `memory/range-alloc-arceos` | | 0 | 基础层(无仓库内直接依赖) | 组件层 | `riscv-h` | `0.4.0` | `virtualization/riscv-h` | | 0 | 基础层(无仓库内直接依赖) | 组件层 | `rsext4` | `0.3.0` | `components/rsext4` | | 0 | 基础层(无仓库内直接依赖) | 组件层 | `smoltcp` | `0.14.0` | `components/starry-smoltcp` | @@ -225,7 +224,7 @@ flowchart TB | 层级 | 数 | 成员 | |------|-----|------| -| 0 | 29 | `aarch64_sysreg` `ax-arm-pl031` `ax-cap-access` `ax-config-gen` `ax-cpumask` `ax-crate-interface` `ax-crate-interface-lite` `ax-ctor-bare-macros` `ax-errno` `ax-handler-table` `ax-int-ratio` `ax-lazyinit` `ax-linked-list-r4l` `ax-memory-addr` `ax-percpu-macros` `ax-riscv-plic` `ax-timer-list` `axbacktrace` `axpoll` `axvisor_api_proc` `bitmap-allocator` `bwbench-client` `deptool` `mingo` `range-alloc-arceos` `riscv-h` `rsext4` `smoltcp` | +| 0 | 28 | `aarch64_sysreg` `ax-arm-pl031` `ax-cap-access` `ax-config-gen` `ax-cpumask` `ax-crate-interface` `ax-crate-interface-lite` `ax-ctor-bare-macros` `ax-errno` `ax-handler-table` `ax-int-ratio` `ax-lazyinit` `ax-linked-list-r4l` `ax-memory-addr` `ax-percpu-macros` `ax-riscv-plic` `ax-timer-list` `axbacktrace` `axpoll` `axvisor_api_proc` `bitmap-allocator` `bwbench-client` `deptool` `mingo` `riscv-h` `rsext4` `smoltcp` | | 1 | 19 | `ax-allocator` `ax-config-macros` `ax-ctor-bare` `ax-fs-vfs` `ax-io` `ax-kernel-guard` `ax-memory-set` `ax-page-table-entry` `ax-plat-macros` `ax-sched` `axfs-ng-vfs` `axhvc` `axklib` `axvmconfig` `define-simple-traits` `define-weak-traits` `fxmac_rs` `smoltcp-fuzz` `starry-vm` | | 2 | 10 | `ax-config` `ax-fs-devfs` `ax-fs-ramfs` `ax-kspin` `ax-page-table-multiarch` `ax-percpu` `axbuild` `impl-simple-traits` `impl-weak-partial` `impl-weak-traits` | | 3 | 11 | `ax-alloc` `ax-cpu` `ax-log` `ax-plat` `axaddrspace` `scope-local` `starry-process` `test-simple` `test-weak` `test-weak-partial` `tg-xtask` | @@ -341,7 +340,7 @@ flowchart TB | `axaddrspace` | 3 | ArceOS-Hypervisor guest address space management … | `ax-errno` `ax-lazyinit` `ax-memory-addr` `ax-memory-set` `ax-page-table-entry` `ax-page-table-multiarch` | `arm_vcpu` `arm_vgic` `axdevice` `axdevice_base` `axvcpu` `axvisor` `axvisor_api` `axvm` `riscv_vcpu` `riscv_vplic` `x86_vcpu` `x86_vlapic` | | `axbacktrace` | 0 | Backtrace for ArceOS | — | `ax-alloc` `ax-cpu` `ax-feat` `ax-runtime` `starry-kernel` | | `axbuild` | 2 | An OS build lib toolkit used by arceos | `axvmconfig` | `axvisor` `starryos` `tg-xtask` | -| `axdevice` | 6 | A reusable, OS-agnostic device abstraction layer … | `arm_vgic` `ax-errno` `ax-memory-addr` `axaddrspace` `axdevice_base` `axvmconfig` `range-alloc-arceos` `riscv_vplic` | `axvisor` `axvm` | +| `axdevice` | 6 | A reusable, OS-agnostic device abstraction layer … | `arm_vgic` `ax-errno` `ax-memory-addr` `axaddrspace` `axdevice_base` `axvmconfig` `riscv_vplic` | `axvisor` `axvm` | | `axdevice_base` | 4 | Basic traits and structures for emulated devices … | `ax-errno` `axaddrspace` `axvmconfig` | `arm_vcpu` `arm_vgic` `axdevice` `axvisor` `axvm` `riscv_vplic` `x86_vcpu` `x86_vlapic` | | `axfs-ng-vfs` | 1 | Virtual filesystem layer for ArceOS | `ax-errno` `axpoll` | `ax-fs-ng` `ax-net-ng` `starry-kernel` | | `axhvc` | 1 | AxVisor HyperCall definitions for guest-hyperviso… | `ax-errno` | `axvisor` | @@ -367,7 +366,6 @@ flowchart TB | `impl-weak-traits` | 2 | Full implementation of weak_default traits define… | `ax-crate-interface` `define-weak-traits` | `test-weak` | | | 6 | 可复用基础组件 | `ax-config-macros` `ax-cpu` `ax-plat` `ax-plat-aarch64-qemu-virt` `ax-plat-loongarch64-qemu-virt` `ax-plat-riscv64-qemu-virt` `ax-plat-x86-pc` | — | | `mingo` | 0 | ArceOS 配套工具与辅助程序 | — | — | -| `range-alloc-arceos` | 0 | Generic range allocator | — | `axdevice` | | `riscv-h` | 0 | RISC-V virtualization-related registers | — | `riscv_vcpu` `riscv_vplic` | | `riscv_vcpu` | 6 | ArceOS-Hypervisor riscv vcpu module | `ax-crate-interface` `ax-errno` `ax-memory-addr` `ax-page-table-entry` `axaddrspace` `axvcpu` `axvisor_api` `riscv-h` | `axvisor` `axvm` | | `riscv_vplic` | 5 | RISCV Virtual PLIC implementation. | `ax-errno` `axaddrspace` `axdevice_base` `axvisor_api` `riscv-h` | `axdevice` `axvisor` | diff --git a/docs/docs/components/overview.md b/docs/docs/components/overview.md index aad60b4895..df0fc2bcea 100644 --- a/docs/docs/components/overview.md +++ b/docs/docs/components/overview.md @@ -200,7 +200,6 @@ flowchart TB | `impl-weak-partial` | 组件层 | `components/crate_interface/test_crates/impl-weak-partial` | 2 | 1 | [查看](crates/impl-weak-partial) | | `impl-weak-traits` | 组件层 | `components/crate_interface/test_crates/impl-weak-traits` | 2 | 1 | [查看](crates/impl-weak-traits) | | `mingo` | ArceOS 层 | `os/arceos/tools/raspi4/chainloader` | 0 | 0 | [查看](crates/mingo) | -| `range-alloc-arceos` | 组件层 | `memory/range-alloc-arceos` | 0 | 1 | [查看](crates/range-alloc-arceos) | | `riscv-h` | 组件层 | `virtualization/riscv-h` | 0 | 2 | [查看](crates/riscv-h) | | `ax-riscv-plic` | 组件层 | `drivers/intc/riscv_plic` | 0 | 1 | [查看](crates/ax-riscv-plic) | | `riscv_vcpu` | 组件层 | `virtualization/riscv_vcpu` | 8 | 2 | [查看](crates/riscv-vcpu) | diff --git a/memory/range-alloc-arceos/.github/config.json b/memory/range-alloc-arceos/.github/config.json deleted file mode 100644 index 12a9fab08b..0000000000 --- a/memory/range-alloc-arceos/.github/config.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "targets": [ - "x86_64-unknown-none" - ], - "rust_components": [ - "rust-src", - "clippy", - "rustfmt" - ] -} diff --git a/memory/range-alloc-arceos/.github/workflows/check.yml b/memory/range-alloc-arceos/.github/workflows/check.yml deleted file mode 100644 index 330fa15e9c..0000000000 --- a/memory/range-alloc-arceos/.github/workflows/check.yml +++ /dev/null @@ -1,66 +0,0 @@ -name: Quality Checks - -on: - push: - branches: - - '**' - tags-ignore: - - '**' - pull_request: - workflow_call: - -jobs: - load-config: - name: Load CI Configuration - runs-on: ubuntu-latest - outputs: - targets: ${{ steps.config.outputs.targets }} - rust_components: ${{ steps.config.outputs.rust_components }} - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Load configuration - id: config - run: | - TARGETS=$(jq -c '.targets' .github/config.json) - COMPONENTS=$(jq -r '.rust_components | join(", ")' .github/config.json) - - echo "targets=$TARGETS" >> $GITHUB_OUTPUT - echo "rust_components=$COMPONENTS" >> $GITHUB_OUTPUT - - check: - name: Check - runs-on: ubuntu-latest - needs: load-config - strategy: - fail-fast: false - matrix: - target: ${{ fromJson(needs.load-config.outputs.targets) }} - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@nightly - with: - components: ${{ needs.load-config.outputs.rust_components }} - targets: ${{ matrix.target }} - - - name: Check rust version - run: rustc --version --verbose - - - name: Check code format - run: cargo fmt --all -- --check - - - name: Build - run: cargo build --target ${{ matrix.target }} --all-features - - - name: Run clippy - run: cargo clippy --target ${{ matrix.target }} --all-features -- -D warnings - - - name: Build documentation - env: - RUSTDOCFLAGS: -D rustdoc::broken_intra_doc_links -D missing-docs - run: cargo doc --no-deps --target ${{ matrix.target }} --all-features diff --git a/memory/range-alloc-arceos/.github/workflows/deploy.yml b/memory/range-alloc-arceos/.github/workflows/deploy.yml deleted file mode 100644 index fda9a323d2..0000000000 --- a/memory/range-alloc-arceos/.github/workflows/deploy.yml +++ /dev/null @@ -1,126 +0,0 @@ -name: Deploy - -on: - push: - tags: - - 'v[0-9]+.[0-9]+.[0-9]+' - -permissions: - contents: read - pages: write - id-token: write - -concurrency: - group: 'pages' - cancel-in-progress: false - -env: - CARGO_TERM_COLOR: always - RUST_BACKTRACE: 1 - -jobs: - verify-tag: - name: Verify Tag - runs-on: ubuntu-latest - outputs: - should_deploy: ${{ steps.check.outputs.should_deploy }} - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Check if tag is on main or master branch - id: check - run: | - git fetch origin main master || true - BRANCHES=$(git branch -r --contains ${{ github.ref }}) - - if echo "$BRANCHES" | grep -qE 'origin/(main|master)'; then - echo "✓ Tag is on main or master branch" - echo "should_deploy=true" >> $GITHUB_OUTPUT - else - echo "✗ Tag is not on main or master branch, skipping deployment" - echo "Tag is on: $BRANCHES" - echo "should_deploy=false" >> $GITHUB_OUTPUT - fi - - - name: Verify version consistency - if: steps.check.outputs.should_deploy == 'true' - run: | - # Extract version from git tag (remove 'v' prefix) - TAG_VERSION="${{ github.ref_name }}" - TAG_VERSION="${TAG_VERSION#v}" - # Extract version from Cargo.toml - CARGO_VERSION=$(grep -m1 '^version' Cargo.toml | sed 's/.*"\(.*\)"/\1/') - echo "Git tag version: $TAG_VERSION" - echo "Cargo.toml version: $CARGO_VERSION" - if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then - echo "ERROR: Version mismatch! Tag version ($TAG_VERSION) != Cargo.toml version ($CARGO_VERSION)" - exit 1 - fi - echo "✓ Version check passed!" - - check: - uses: ./.github/workflows/check.yml - needs: verify-tag - if: needs.verify-tag.outputs.should_deploy == 'true' - - test: - uses: ./.github/workflows/test.yml - needs: verify-tag - if: needs.verify-tag.outputs.should_deploy == 'true' - - build: - name: Build documentation - runs-on: ubuntu-latest - needs: [verify-tag, check, test] - if: needs.verify-tag.outputs.should_deploy == 'true' - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@nightly - - - name: Build docs - env: - RUSTDOCFLAGS: -D rustdoc::broken_intra_doc_links -D missing-docs - run: | - # Build documentation - cargo doc --no-deps --all-features - - # Auto-detect documentation directory - # Check if doc exists in target/doc or target/*/doc - if [ -d "target/doc" ]; then - DOC_DIR="target/doc" - else - # Find doc directory under target/*/doc pattern - DOC_DIR=$(find target -type d -name doc -path "target/*/doc" | head -n 1) - if [ -z "$DOC_DIR" ]; then - echo "Error: Could not find documentation directory" - exit 1 - fi - fi - - echo "Documentation found in: $DOC_DIR" - printf '' $(cargo tree | head -1 | cut -d' ' -f1) > "${DOC_DIR}/index.html" - echo "DOC_DIR=${DOC_DIR}" >> $GITHUB_ENV - - - name: Upload artifact - uses: actions/upload-pages-artifact@v3 - with: - path: ${{ env.DOC_DIR }} - - deploy: - name: Deploy to GitHub Pages - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - runs-on: ubuntu-latest - needs: [verify-tag, build] - if: needs.verify-tag.outputs.should_deploy == 'true' - steps: - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v4 diff --git a/memory/range-alloc-arceos/.github/workflows/push.yml b/memory/range-alloc-arceos/.github/workflows/push.yml deleted file mode 100644 index a18de4a047..0000000000 --- a/memory/range-alloc-arceos/.github/workflows/push.yml +++ /dev/null @@ -1,147 +0,0 @@ -# ═══════════════════════════════════════════════════════════════════════════════ -# 组件仓库 GitHub Actions 配置模板 -# ═══════════════════════════════════════════════════════════════════════════════ -# -# 此文件用于子仓库,当子仓库有更新时通知主仓库进行 subtree pull 同步。 -# -# 【使用步骤】 -# ───────────────────────────────────────────────────────────────────────────── -# 1. 将此文件复制到子仓库的 .github/workflows/ 目录: -# cp scripts/push.yml <子仓库>/.github/workflows/push.yml -# -# 2. 在子仓库中配置 Secret: -# GitHub 仓库 → Settings → Secrets → Actions → New repository secret -# 名称: PARENT_REPO_TOKEN -# 值: 具有主仓库 repo 权限的 Personal Access Token -# -# 3. 修改下方 env 块中的一个变量(标注了「需要修改」的行): -# PARENT_REPO - 主仓库路径,例如 rcore-os/tgoskits -# (subtree 目录由主仓库自动从 git 历史中推断,无需手动指定) -# -# 【Token 权限要求】 -# ───────────────────────────────────────────────────────────────────────────── -# PARENT_REPO_TOKEN 需要 Classic Personal Access Token,权限包括: -# - repo (Full control of private repositories) -# 或 -# - Fine-grained token: Contents (Read and Write) -# -# 【触发条件】 -# ───────────────────────────────────────────────────────────────────────────── -# - 自动触发:推送到 dev 或 main 分支时 -# - 手动触发:Actions → Notify Parent Repository → Run workflow -# -# 【工作流程】 -# ───────────────────────────────────────────────────────────────────────────── -# 子仓库 push → 触发此工作流 → 调用主仓库 API → 主仓库 subtree pull -# -# 【注意事项】 -# ───────────────────────────────────────────────────────────────────────────── -# - 主仓库需要配置接收 repository_dispatch 事件的同步工作流 -# - 如果不需要子仓库到主仓库的同步,可以不使用此文件 -# -# ═══════════════════════════════════════════════════════════════════════════════ - -name: Notify Parent Repository - -# 当有新的推送时触发 -on: - push: - branches: - - main - - master - workflow_dispatch: - -jobs: - notify: - runs-on: ubuntu-latest - steps: - - name: Get repository info - id: repo - env: - GH_REPO_NAME: ${{ github.event.repository.name }} - GH_REF_NAME: ${{ github.ref_name }} - GH_SERVER_URL: ${{ github.server_url }} - GH_REPOSITORY: ${{ github.repository }} - run: | - # 直接使用 GitHub Actions 内置变量,通过 env 传入避免 shell 注入 - COMPONENT="$GH_REPO_NAME" - BRANCH="$GH_REF_NAME" - # 构造标准 HTTPS URL,供主仓库按 URL 精确匹配 repos.list - REPO_URL="${GH_SERVER_URL}/${GH_REPOSITORY}" - - echo "component=${COMPONENT}" >> $GITHUB_OUTPUT - echo "branch=${BRANCH}" >> $GITHUB_OUTPUT - echo "repo_url=${REPO_URL}" >> $GITHUB_OUTPUT - - echo "Component: ${COMPONENT}" - echo "Branch: ${BRANCH}" - echo "Repo URL: ${REPO_URL}" - - - name: Notify parent repository - env: - # ── 需要修改 ────────────────────────────────────────────────────────── - PARENT_REPO: "rcore-os/tgoskits" # 主仓库路径 - # ── 无需修改 ────────────────────────────────────────────────────────── - DISPATCH_TOKEN: ${{ secrets.PARENT_REPO_TOKEN }} - # 将用户可控内容通过 env 传入,避免直接插值到 shell 脚本 - COMMIT_MESSAGE: ${{ github.event.head_commit.message }} - GIT_ACTOR: ${{ github.actor }} - GIT_SHA: ${{ github.sha }} - STEP_COMPONENT: ${{ steps.repo.outputs.component }} - STEP_BRANCH: ${{ steps.repo.outputs.branch }} - STEP_REPO_URL: ${{ steps.repo.outputs.repo_url }} - run: | - COMPONENT="$STEP_COMPONENT" - BRANCH="$STEP_BRANCH" - REPO_URL="$STEP_REPO_URL" - - echo "Notifying parent repository about update in ${COMPONENT}:${BRANCH}" - - # 使用 jq 安全构建 JSON,避免 commit message 中任何特殊字符导致注入 - PAYLOAD=$(jq -n \ - --arg component "$COMPONENT" \ - --arg branch "$BRANCH" \ - --arg repo_url "$REPO_URL" \ - --arg commit "$GIT_SHA" \ - --arg message "$COMMIT_MESSAGE" \ - --arg author "$GIT_ACTOR" \ - '{ - event_type: "subtree-update", - client_payload: { - component: $component, - branch: $branch, - repo_url: $repo_url, - commit: $commit, - message: $message, - author: $author - } - }') - - curl --fail --show-error -X POST \ - -H "Accept: application/vnd.github.v3+json" \ - -H "Authorization: token ${DISPATCH_TOKEN}" \ - https://api.github.com/repos/${PARENT_REPO}/dispatches \ - -d "$PAYLOAD" - - echo "Notification sent successfully" - - - name: Create summary - env: - STEP_COMPONENT: ${{ steps.repo.outputs.component }} - STEP_BRANCH: ${{ steps.repo.outputs.branch }} - STEP_REPO_URL: ${{ steps.repo.outputs.repo_url }} - GIT_SHA: ${{ github.sha }} - GIT_ACTOR: ${{ github.actor }} - run: | - COMPONENT="$STEP_COMPONENT" - BRANCH="$STEP_BRANCH" - REPO_URL="$STEP_REPO_URL" - - echo "## Notification Summary" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "- **Component**: ${COMPONENT}" >> $GITHUB_STEP_SUMMARY - echo "- **Branch**: ${BRANCH}" >> $GITHUB_STEP_SUMMARY - echo "- **Repo URL**: ${REPO_URL}" >> $GITHUB_STEP_SUMMARY - echo "- **Commit**: \`${GIT_SHA}\`" >> $GITHUB_STEP_SUMMARY - echo "- **Author**: ${GIT_ACTOR}" >> $GITHUB_STEP_SUMMARY - echo "- **Status**: ✅ Notification sent" >> $GITHUB_STEP_SUMMARY diff --git a/memory/range-alloc-arceos/.github/workflows/release.yml b/memory/range-alloc-arceos/.github/workflows/release.yml deleted file mode 100644 index 2e857b48b5..0000000000 --- a/memory/range-alloc-arceos/.github/workflows/release.yml +++ /dev/null @@ -1,160 +0,0 @@ -name: Release - -on: - push: - tags: - - 'v[0-9]+.[0-9]+.[0-9]+' - - 'v[0-9]+.[0-9]+.[0-9]+-pre.[0-9]+' - -permissions: - contents: write - -jobs: - verify-tag: - name: Verify Tag - runs-on: ubuntu-latest - outputs: - should_release: ${{ steps.check.outputs.should_release }} - is_prerelease: ${{ steps.check.outputs.is_prerelease }} - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Check tag type and branch - id: check - run: | - git fetch origin main master dev || true - - TAG="${{ github.ref_name }}" - BRANCHES=$(git branch -r --contains ${{ github.ref }}) - - echo "Tag: $TAG" - echo "Branches containing this tag: $BRANCHES" - - # Check if it's a prerelease tag - if [[ "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+-pre\.[0-9]+$ ]]; then - echo "📦 Detected prerelease tag" - echo "is_prerelease=true" >> $GITHUB_OUTPUT - - if echo "$BRANCHES" | grep -q 'origin/dev'; then - echo "✓ Prerelease tag is on dev branch" - echo "should_release=true" >> $GITHUB_OUTPUT - else - echo "✗ Prerelease tag must be on dev branch, skipping release" - echo "should_release=false" >> $GITHUB_OUTPUT - fi - elif [[ "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "📦 Detected stable release tag" - echo "is_prerelease=false" >> $GITHUB_OUTPUT - - if echo "$BRANCHES" | grep -qE 'origin/(main|master)'; then - echo "✓ Stable release tag is on main or master branch" - echo "should_release=true" >> $GITHUB_OUTPUT - else - echo "✗ Stable release tag must be on main or master branch, skipping release" - echo "should_release=false" >> $GITHUB_OUTPUT - fi - else - echo "✗ Unknown tag format, skipping release" - echo "is_prerelease=false" >> $GITHUB_OUTPUT - echo "should_release=false" >> $GITHUB_OUTPUT - fi - - - name: Verify version consistency - if: steps.check.outputs.should_release == 'true' - run: | - # Extract version from git tag (remove 'v' prefix) - TAG_VERSION="${{ github.ref_name }}" - TAG_VERSION="${TAG_VERSION#v}" - # Extract version from Cargo.toml - CARGO_VERSION=$(grep -m1 '^version' Cargo.toml | sed 's/.*"\(.*\)"/\1/') - echo "Git tag version: $TAG_VERSION" - echo "Cargo.toml version: $CARGO_VERSION" - if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then - echo "ERROR: Version mismatch! Tag version ($TAG_VERSION) != Cargo.toml version ($CARGO_VERSION)" - exit 1 - fi - echo "✓ Version check passed!" - - check: - uses: ./.github/workflows/check.yml - needs: verify-tag - if: needs.verify-tag.outputs.should_release == 'true' - - test: - uses: ./.github/workflows/test.yml - needs: [verify-tag, check] - if: needs.verify-tag.outputs.should_release == 'true' - - release: - name: Create GitHub Release - runs-on: ubuntu-latest - needs: [verify-tag, check] - if: needs.verify-tag.outputs.should_release == 'true' - - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Generate release notes - id: release_notes - run: | - CURRENT_TAG="${{ github.ref_name }}" - - # Get previous tag - PREVIOUS_TAG=$(git tag --sort=-version:refname | grep -A1 "^${CURRENT_TAG}$" | tail -n1) - - if [ -z "$PREVIOUS_TAG" ] || [ "$PREVIOUS_TAG" == "$CURRENT_TAG" ]; then - echo "No previous tag found, this is the first release" - CHANGELOG="Initial release" - else - echo "Generating changelog from $PREVIOUS_TAG to $CURRENT_TAG" - - # Generate changelog with commit messages - CHANGELOG=$(git log --pretty=format:"- %s (%h)" "${PREVIOUS_TAG}..${CURRENT_TAG}") - - if [ -z "$CHANGELOG" ]; then - CHANGELOG="No changes" - fi - fi - - # Write changelog to output file (multi-line) - { - echo "changelog<> $GITHUB_OUTPUT - - - name: Create GitHub Release - uses: softprops/action-gh-release@v2 - with: - draft: false - prerelease: ${{ needs.verify-tag.outputs.is_prerelease == 'true' }} - body: | - ## Changes - ${{ steps.release_notes.outputs.changelog }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - publish: - name: Publish to crates.io - runs-on: ubuntu-latest - needs: [verify-tag, check] - if: needs.verify-tag.outputs.should_release == 'true' - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@nightly - - - name: Dry run publish - run: cargo publish --dry-run - - - name: Publish to crates.io - run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }} diff --git a/memory/range-alloc-arceos/.github/workflows/test.yml b/memory/range-alloc-arceos/.github/workflows/test.yml deleted file mode 100644 index dc3b293d9d..0000000000 --- a/memory/range-alloc-arceos/.github/workflows/test.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: Test - -on: - push: - branches: - - '**' - tags-ignore: - - '**' - pull_request: - workflow_call: - -jobs: - load-config: - name: Load CI Configuration - runs-on: ubuntu-latest - outputs: - targets: ${{ steps.config.outputs.targets }} - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Load configuration - id: config - run: | - TARGETS=$(jq -c '.targets' .github/config.json) - echo "targets=$TARGETS" >> $GITHUB_OUTPUT - - test: - name: Test - runs-on: ubuntu-latest - needs: load-config - strategy: - fail-fast: false - matrix: - target: ${{ fromJson(needs.load-config.outputs.targets) }} - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@nightly - - # - name: Run tests - # run: cargo test --target ${{ matrix.target }} --all-features -- --nocapture - - # - name: Run doc tests - # run: cargo test --target ${{ matrix.target }} --doc - - name: Run tests - run: echo "Tests are skipped!" diff --git a/memory/range-alloc-arceos/.gitignore b/memory/range-alloc-arceos/.gitignore deleted file mode 100644 index e3507286da..0000000000 --- a/memory/range-alloc-arceos/.gitignore +++ /dev/null @@ -1,16 +0,0 @@ -# Junk -.DS_Store -.vscode/ -.#* -*.iml -.idea -.fuse_hidden* - -# Compiled -/doc -target/ -examples/generated-wasm - -# Service -Cargo.lock -*.swp diff --git a/memory/range-alloc-arceos/CHANGELOG.md b/memory/range-alloc-arceos/CHANGELOG.md deleted file mode 100644 index 588dfd25f4..0000000000 --- a/memory/range-alloc-arceos/CHANGELOG.md +++ /dev/null @@ -1,14 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [Unreleased] - -## [0.3.9](https://github.com/rcore-os/tgoskits/compare/range-alloc-arceos-v0.3.8...range-alloc-arceos-v0.3.9) - 2026-05-15 - -### Other - -- *(range-alloc-arceos)* inherit workspace metadata diff --git a/memory/range-alloc-arceos/Cargo.toml b/memory/range-alloc-arceos/Cargo.toml deleted file mode 100644 index 4d971eab8e..0000000000 --- a/memory/range-alloc-arceos/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "range-alloc-arceos" -version = "0.3.9" -description = "Generic range allocator" -homepage = "https://github.com/arceos-hypervisor/range-alloc-arceos" -repository = "https://github.com/arceos-hypervisor/range-alloc-arceos" -keywords = ["allocator"] -authors = ["the gfx-rs Developers"] -documentation = "https://docs.rs/range-alloc-arceos" -categories = ["memory-management"] -edition.workspace = true -readme = "README.md" -license = "Apache-2.0" diff --git a/memory/range-alloc-arceos/LICENSE b/memory/range-alloc-arceos/LICENSE deleted file mode 100644 index 261eeb9e9f..0000000000 --- a/memory/range-alloc-arceos/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/memory/range-alloc-arceos/LICENSE.APACHE b/memory/range-alloc-arceos/LICENSE.APACHE deleted file mode 100644 index d9a10c0d8e..0000000000 --- a/memory/range-alloc-arceos/LICENSE.APACHE +++ /dev/null @@ -1,176 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS diff --git a/memory/range-alloc-arceos/LICENSE.MIT b/memory/range-alloc-arceos/LICENSE.MIT deleted file mode 100644 index c706b62c79..0000000000 --- a/memory/range-alloc-arceos/LICENSE.MIT +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2023 The gfx-rs developers - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/memory/range-alloc-arceos/README.md b/memory/range-alloc-arceos/README.md deleted file mode 100644 index f9d2507153..0000000000 --- a/memory/range-alloc-arceos/README.md +++ /dev/null @@ -1,81 +0,0 @@ -

range-alloc-arceos

- -

Generic range allocator

- -
- -[![Crates.io](https://img.shields.io/crates/v/range-alloc-arceos.svg)](https://crates.io/crates/range-alloc-arceos) -[![Docs.rs](https://docs.rs/range-alloc-arceos/badge.svg)](https://docs.rs/range-alloc-arceos) -[![Rust](https://img.shields.io/badge/edition-2018-orange.svg)](https://www.rust-lang.org/) -[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](./LICENSE) - -
- -English | [中文](README_CN.md) - -# Introduction - -`range-alloc-arceos` provides Generic range allocator. It is maintained as part of the TGOSKits component set and is intended for Rust projects that integrate with ArceOS, AxVisor, or related low-level systems software. - -## Quick Start - -### Installation - -Add this crate to your `Cargo.toml`: - -```toml -[dependencies] -range-alloc-arceos = "0.3.4" -``` - -### Run Check and Test - -```bash -# Enter the crate directory -cd memory/range-alloc-arceos - -# Format code -cargo fmt --all - -# Run clippy -cargo clippy --all-targets --all-features - -# Run tests -cargo test --all-features - -# Build documentation -cargo doc --no-deps -``` - -## Integration - -### Example - -```rust -use range_alloc_arceos as _; - -fn main() { - // Integrate `range-alloc-arceos` into your project here. -} -``` - -### Documentation - -Generate and view API documentation: - -```bash -cargo doc --no-deps --open -``` - -Online documentation: [docs.rs/range-alloc-arceos](https://docs.rs/range-alloc-arceos) - -# Contributing - -1. Fork the repository and create a branch -2. Run local format and checks -3. Run local tests relevant to this crate -4. Submit a PR and ensure CI passes - -# License - -Licensed under the Apache License, Version 2.0. See [LICENSE](./LICENSE) for details. diff --git a/memory/range-alloc-arceos/README_CN.md b/memory/range-alloc-arceos/README_CN.md deleted file mode 100644 index 2ec6e1ef78..0000000000 --- a/memory/range-alloc-arceos/README_CN.md +++ /dev/null @@ -1,81 +0,0 @@ -

range-alloc-arceos

- -

Generic range allocator

- -
- -[![Crates.io](https://img.shields.io/crates/v/range-alloc-arceos.svg)](https://crates.io/crates/range-alloc-arceos) -[![Docs.rs](https://docs.rs/range-alloc-arceos/badge.svg)](https://docs.rs/range-alloc-arceos) -[![Rust](https://img.shields.io/badge/edition-2018-orange.svg)](https://www.rust-lang.org/) -[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](./LICENSE) - -
- -[English](README.md) | 中文 - -# 介绍 - -`range-alloc-arceos` 提供了 Generic range allocator。它是 TGOSKits 组件集合的一部分,可用于集成 ArceOS、AxVisor 及相关底层系统软件的 Rust 项目。 - -## 快速开始 - -### 添加依赖 - -在 `Cargo.toml` 中加入: - -```toml -[dependencies] -range-alloc-arceos = "0.3.4" -``` - -### 检查与测试 - -```bash -# 进入 crate 目录 -cd memory/range-alloc-arceos - -# 代码格式化 -cargo fmt --all - -# 运行 clippy -cargo clippy --all-targets --all-features - -# 运行测试 -cargo test --all-features - -# 生成文档 -cargo doc --no-deps -``` - -## 集成方式 - -### 示例 - -```rust -use range_alloc_arceos as _; - -fn main() { - // 在这里将 `range-alloc-arceos` 集成到你的项目中。 -} -``` - -### 文档 - -生成并查看 API 文档: - -```bash -cargo doc --no-deps --open -``` - -在线文档:[docs.rs/range-alloc-arceos](https://docs.rs/range-alloc-arceos) - -# 贡献 - -1. Fork 仓库并创建分支 -2. 在本地运行格式化与检查 -3. 运行与该 crate 相关的测试 -4. 提交 PR 并确保 CI 通过 - -# 许可证 - -本项目采用 Apache License 2.0 许可证。详情见 [LICENSE](./LICENSE)。 diff --git a/memory/range-alloc-arceos/src/lib.rs b/memory/range-alloc-arceos/src/lib.rs deleted file mode 100644 index 44d31eda4f..0000000000 --- a/memory/range-alloc-arceos/src/lib.rs +++ /dev/null @@ -1,491 +0,0 @@ -//! A simple, fast range allocator for managing contiguous ranges of resources. -//! -//! This crate provides a [`RangeAllocator`] that efficiently allocates and frees -//! contiguous ranges from an initial range. It uses a best-fit allocation strategy -//! to minimize memory fragmentation. -//! -//! # Example -//! -//! ``` -//! use range_alloc_arceos::RangeAllocator; -//! -//! let mut allocator = RangeAllocator::new(0..100); -//! -//! // Allocate a range of length 10 -//! let range = allocator.allocate_range(10).unwrap(); -//! assert_eq!(range, 0..10); -//! -//! // Free the range when done -//! allocator.free_range(range); -//! ``` - -#![no_std] - -extern crate alloc; - -use alloc::{vec, vec::Vec}; -use core::{ - fmt::Debug, - iter::Sum, - ops::{Add, AddAssign, Range, Sub}, -}; - -/// A range allocator that manages allocation and deallocation of contiguous ranges. -/// -/// The allocator starts with an initial range and maintains a list of free ranges. -/// It uses a best-fit allocation strategy to minimize fragmentation when allocating -/// new ranges. -/// -/// # Type Parameters -/// -/// * `T` - The type used for range bounds. Must support arithmetic operations and ordering. -#[derive(Debug)] -pub struct RangeAllocator { - /// The range this allocator covers. - initial_range: Range, - /// A Vec of ranges in this heap which are unused. - /// Must be ordered with ascending range start to permit short circuiting allocation. - /// No two ranges in this vec may overlap. - free_ranges: Vec>, -} - -/// Error type returned when a range allocation fails. -/// -/// This error indicates that there is not enough contiguous space available -/// to satisfy the allocation request, although there may be enough total free -/// space if it were defragmented. -#[derive(Clone, Debug, PartialEq)] -pub struct RangeAllocationError { - /// The total length of all free ranges combined. - /// - /// This value represents how much space would be available if all fragmented - /// free ranges could be combined into one contiguous range. - pub fragmented_free_length: T, -} - -impl RangeAllocator -where - T: Clone + Copy + Add + AddAssign + Sub + Eq + PartialOrd + Debug, -{ - /// Creates a new range allocator with the specified initial range. - /// - /// The entire initial range is marked as free and available for allocation. - /// - /// # Arguments - /// - /// * `range` - The initial range that this allocator will manage. - /// - /// # Example - /// - /// ``` - /// use range_alloc_arceos::RangeAllocator; - /// - /// let allocator = RangeAllocator::new(0..1024); - /// ``` - pub fn new(range: Range) -> Self { - RangeAllocator { - initial_range: range.clone(), - free_ranges: vec![range], - } - } - - /// Returns a reference to the initial range managed by this allocator. - /// - /// This is the range that was provided when the allocator was created, - /// or the expanded range if [`grow_to`](Self::grow_to) was called. - pub fn initial_range(&self) -> &Range { - &self.initial_range - } - - /// Grows the allocator's range to a new end point. - /// - /// This extends the upper bound of the initial range and makes the new space - /// available for allocation. If the last free range ends at the current upper - /// bound, it is extended; otherwise, a new free range is added. - /// - /// # Arguments - /// - /// * `new_end` - The new end point for the range (must be greater than the current end). - pub fn grow_to(&mut self, new_end: T) { - let initial_range_end = self.initial_range.end; - if let Some(last_range) = self - .free_ranges - .last_mut() - .filter(|last_range| last_range.end == initial_range_end) - { - last_range.end = new_end; - } else { - self.free_ranges.push(self.initial_range.end..new_end); - } - - self.initial_range.end = new_end; - } - - /// Allocates a contiguous range of the specified length. - /// - /// This method uses a best-fit allocation strategy to find the smallest free range - /// that can satisfy the request, minimizing fragmentation. If no single contiguous - /// range is large enough, it returns an error with information about the total - /// fragmented free space. - /// - /// # Arguments - /// - /// * `length` - The length of the range to allocate. - /// - /// # Returns - /// - /// * `Ok(Range)` - The allocated range if successful. - /// * `Err(RangeAllocationError)` - If allocation fails, containing information - /// about the total fragmented free space available. - /// - /// # Example - /// - /// ``` - /// use range_alloc_arceos::RangeAllocator; - /// - /// let mut allocator = RangeAllocator::new(0..100); - /// let range = allocator.allocate_range(20).unwrap(); - /// assert_eq!(range, 0..20); - /// ``` - pub fn allocate_range(&mut self, length: T) -> Result, RangeAllocationError> { - assert_ne!(length + length, length); - let mut best_fit: Option<(usize, Range)> = None; - - // This is actually correct. With the trait bound as it is, we have - // no way to summon a value of 0 directly, so we make one by subtracting - // something from itself. Once the trait bound can be changed, this can - // be fixed. - #[allow(clippy::eq_op)] - let mut fragmented_free_length = length - length; - for (index, range) in self.free_ranges.iter().cloned().enumerate() { - let range_length = range.end - range.start; - fragmented_free_length += range_length; - if range_length < length { - continue; - } else if range_length == length { - // Found a perfect fit, so stop looking. - best_fit = Some((index, range)); - break; - } - best_fit = Some(match best_fit { - Some((best_index, best_range)) => { - // Find best fit for this allocation to reduce memory fragmentation. - if range_length < best_range.end - best_range.start { - (index, range) - } else { - (best_index, best_range.clone()) - } - } - None => (index, range), - }); - } - match best_fit { - Some((index, range)) => { - if range.end - range.start == length { - self.free_ranges.remove(index); - } else { - self.free_ranges[index].start += length; - } - Ok(range.start..(range.start + length)) - } - None => Err(RangeAllocationError { - fragmented_free_length, - }), - } - } - - /// Frees a previously allocated range, making it available for future allocations. - /// - /// This method attempts to merge the freed range with adjacent free ranges to - /// reduce fragmentation. The freed range must be within the initial range and - /// must not be empty. - /// - /// # Arguments - /// - /// * `range` - The range to free. Must be within the allocator's initial range. - /// - /// # Panics - /// - /// Panics if the range is outside the initial range or if the range is empty - /// (start >= end). - /// - /// # Example - /// - /// ``` - /// use range_alloc_arceos::RangeAllocator; - /// - /// let mut allocator = RangeAllocator::new(0..100); - /// let range = allocator.allocate_range(20).unwrap(); - /// allocator.free_range(range); - /// ``` - pub fn free_range(&mut self, range: Range) { - assert!(self.initial_range.start <= range.start && range.end <= self.initial_range.end); - assert!(range.start < range.end); - - // Get insertion position. - let i = self - .free_ranges - .iter() - .position(|r| r.start > range.start) - .unwrap_or(self.free_ranges.len()); - - // Try merging with neighboring ranges in the free list. - // Before: |left|-(range)-|right| - if i > 0 && range.start == self.free_ranges[i - 1].end { - // Merge with |left|. - self.free_ranges[i - 1].end = - if i < self.free_ranges.len() && range.end == self.free_ranges[i].start { - // Check for possible merge with |left| and |right|. - let right = self.free_ranges.remove(i); - right.end - } else { - range.end - }; - - return; - } else if i < self.free_ranges.len() && range.end == self.free_ranges[i].start { - // Merge with |right|. - self.free_ranges[i].start = if i > 0 && range.start == self.free_ranges[i - 1].end { - // Check for possible merge with |left| and |right|. - let left = self.free_ranges.remove(i - 1); - left.start - } else { - range.start - }; - - return; - } - - // Debug checks - assert!( - (i == 0 || self.free_ranges[i - 1].end < range.start) - && (i >= self.free_ranges.len() || range.end < self.free_ranges[i].start) - ); - - self.free_ranges.insert(i, range); - } - - /// Returns an iterator over allocated non-empty ranges - pub fn allocated_ranges(&self) -> impl Iterator> + '_ { - let first = match self.free_ranges.first() { - Some(Range { start, .. }) if *start > self.initial_range.start => { - Some(self.initial_range.start..*start) - } - None => Some(self.initial_range.clone()), - _ => None, - }; - - let last = match self.free_ranges.last() { - Some(Range { end, .. }) if *end < self.initial_range.end => { - Some(*end..self.initial_range.end) - } - _ => None, - }; - - let mid = self - .free_ranges - .iter() - .zip(self.free_ranges.iter().skip(1)) - .map(|(ra, rb)| ra.end..rb.start); - - first.into_iter().chain(mid).chain(last) - } - - /// Resets the allocator to its initial state. - /// - /// This marks the entire initial range as free, effectively deallocating - /// all previously allocated ranges. - pub fn reset(&mut self) { - self.free_ranges.clear(); - self.free_ranges.push(self.initial_range.clone()); - } - - /// Returns `true` if no ranges have been allocated. - /// - /// This checks whether the allocator is in its initial state with all space free. - pub fn is_empty(&self) -> bool { - self.free_ranges.len() == 1 && self.free_ranges[0] == self.initial_range - } -} - -impl + Sum> RangeAllocator { - /// Returns the total amount of free space available across all free ranges. - /// - /// This sums the lengths of all free ranges, giving the total amount of space - /// that could be allocated if fragmentation is not an issue. - pub fn total_available(&self) -> T { - self.free_ranges - .iter() - .map(|range| range.end - range.start) - .sum() - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_basic_allocation() { - let mut alloc = RangeAllocator::new(0..10); - // Test if an allocation works - assert_eq!(alloc.allocate_range(4), Ok(0..4)); - assert!(alloc.allocated_ranges().eq(core::iter::once(0..4))); - // Free the prior allocation - alloc.free_range(0..4); - // Make sure the free actually worked - assert_eq!(alloc.free_ranges, vec![0..10]); - assert!(alloc.allocated_ranges().eq(core::iter::empty())); - } - - #[test] - fn test_out_of_space() { - let mut alloc = RangeAllocator::new(0..10); - // Test if the allocator runs out of space correctly - assert_eq!(alloc.allocate_range(10), Ok(0..10)); - assert!(alloc.allocated_ranges().eq(core::iter::once(0..10))); - assert!(alloc.allocate_range(4).is_err()); - alloc.free_range(0..10); - } - - #[test] - fn test_grow() { - let mut alloc = RangeAllocator::new(0..11); - // Test if the allocator runs out of space correctly - assert_eq!(alloc.allocate_range(10), Ok(0..10)); - assert!(alloc.allocated_ranges().eq(core::iter::once(0..10))); - assert!(alloc.allocate_range(4).is_err()); - alloc.grow_to(20); - assert_eq!(alloc.allocate_range(4), Ok(10..14)); - alloc.free_range(0..14); - } - - #[test] - fn test_grow_with_hole_at_start() { - let mut alloc = RangeAllocator::new(0..6); - - assert_eq!(alloc.allocate_range(3), Ok(0..3)); - assert_eq!(alloc.allocate_range(3), Ok(3..6)); - alloc.free_range(0..3); - - alloc.grow_to(9); - assert_eq!(alloc.allocated_ranges().collect::>(), [3..6]); - } - #[test] - fn test_grow_with_hole_in_middle() { - let mut alloc = RangeAllocator::new(0..6); - - assert_eq!(alloc.allocate_range(2), Ok(0..2)); - assert_eq!(alloc.allocate_range(2), Ok(2..4)); - assert_eq!(alloc.allocate_range(2), Ok(4..6)); - alloc.free_range(2..4); - - alloc.grow_to(9); - assert_eq!(alloc.allocated_ranges().collect::>(), [0..2, 4..6]); - } - - #[test] - fn test_dont_use_block_that_is_too_small() { - let mut alloc = RangeAllocator::new(0..10); - // Allocate three blocks then free the middle one and check for correct state - assert_eq!(alloc.allocate_range(3), Ok(0..3)); - assert_eq!(alloc.allocate_range(3), Ok(3..6)); - assert_eq!(alloc.allocate_range(3), Ok(6..9)); - alloc.free_range(3..6); - assert_eq!(alloc.free_ranges, vec![3..6, 9..10]); - assert_eq!( - alloc.allocated_ranges().collect::>>(), - vec![0..3, 6..9] - ); - // Now request space that the middle block can fill, but the end one can't. - assert_eq!(alloc.allocate_range(3), Ok(3..6)); - } - - #[test] - fn test_free_blocks_in_middle() { - let mut alloc = RangeAllocator::new(0..100); - // Allocate many blocks then free every other block. - assert_eq!(alloc.allocate_range(10), Ok(0..10)); - assert_eq!(alloc.allocate_range(10), Ok(10..20)); - assert_eq!(alloc.allocate_range(10), Ok(20..30)); - assert_eq!(alloc.allocate_range(10), Ok(30..40)); - assert_eq!(alloc.allocate_range(10), Ok(40..50)); - assert_eq!(alloc.allocate_range(10), Ok(50..60)); - assert_eq!(alloc.allocate_range(10), Ok(60..70)); - assert_eq!(alloc.allocate_range(10), Ok(70..80)); - assert_eq!(alloc.allocate_range(10), Ok(80..90)); - assert_eq!(alloc.allocate_range(10), Ok(90..100)); - assert_eq!(alloc.free_ranges, vec![]); - assert!(alloc.allocated_ranges().eq(core::iter::once(0..100))); - alloc.free_range(10..20); - alloc.free_range(30..40); - alloc.free_range(50..60); - alloc.free_range(70..80); - alloc.free_range(90..100); - // Check that the right blocks were freed. - assert_eq!( - alloc.free_ranges, - vec![10..20, 30..40, 50..60, 70..80, 90..100] - ); - assert_eq!( - alloc.allocated_ranges().collect::>>(), - vec![0..10, 20..30, 40..50, 60..70, 80..90] - ); - // Fragment the memory on purpose a bit. - assert_eq!(alloc.allocate_range(6), Ok(10..16)); - assert_eq!(alloc.allocate_range(6), Ok(30..36)); - assert_eq!(alloc.allocate_range(6), Ok(50..56)); - assert_eq!(alloc.allocate_range(6), Ok(70..76)); - assert_eq!(alloc.allocate_range(6), Ok(90..96)); - // Check for fragmentation. - assert_eq!( - alloc.free_ranges, - vec![16..20, 36..40, 56..60, 76..80, 96..100] - ); - assert_eq!( - alloc.allocated_ranges().collect::>>(), - vec![0..16, 20..36, 40..56, 60..76, 80..96] - ); - // Fill up the fragmentation - assert_eq!(alloc.allocate_range(4), Ok(16..20)); - assert_eq!(alloc.allocate_range(4), Ok(36..40)); - assert_eq!(alloc.allocate_range(4), Ok(56..60)); - assert_eq!(alloc.allocate_range(4), Ok(76..80)); - assert_eq!(alloc.allocate_range(4), Ok(96..100)); - // Check that nothing is free. - assert_eq!(alloc.free_ranges, vec![]); - assert!(alloc.allocated_ranges().eq(core::iter::once(0..100))); - } - - #[test] - fn test_ignore_block_if_another_fits_better() { - let mut alloc = RangeAllocator::new(0..10); - // Allocate blocks such that the only free spaces available are 3..6 and 9..10 - // in order to prepare for the next test. - assert_eq!(alloc.allocate_range(3), Ok(0..3)); - assert_eq!(alloc.allocate_range(3), Ok(3..6)); - assert_eq!(alloc.allocate_range(3), Ok(6..9)); - alloc.free_range(3..6); - assert_eq!(alloc.free_ranges, vec![3..6, 9..10]); - assert_eq!( - alloc.allocated_ranges().collect::>>(), - vec![0..3, 6..9] - ); - // Now request space that can be filled by 3..6 but should be filled by 9..10 - // because 9..10 is a perfect fit. - assert_eq!(alloc.allocate_range(1), Ok(9..10)); - } - - #[test] - fn test_merge_neighbors() { - let mut alloc = RangeAllocator::new(0..9); - assert_eq!(alloc.allocate_range(3), Ok(0..3)); - assert_eq!(alloc.allocate_range(3), Ok(3..6)); - assert_eq!(alloc.allocate_range(3), Ok(6..9)); - alloc.free_range(0..3); - alloc.free_range(6..9); - alloc.free_range(3..6); - assert_eq!(alloc.free_ranges, vec![0..9]); - assert!(alloc.allocated_ranges().eq(core::iter::empty())); - } -} diff --git a/memory/range-alloc-arceos/tests/test.rs b/memory/range-alloc-arceos/tests/test.rs deleted file mode 100644 index 23d2a3e1f2..0000000000 --- a/memory/range-alloc-arceos/tests/test.rs +++ /dev/null @@ -1,60 +0,0 @@ -use range_alloc_arceos::RangeAllocator; - -#[test] -fn test_simple_allocation() { - let mut allocator = RangeAllocator::new(0..100); - - let r1 = allocator.allocate_range(10).expect("Alloc 10 failed"); - assert_eq!(r1, 0..10); - - let r2 = allocator.allocate_range(20).expect("Alloc 20 failed"); - assert_eq!(r2, 10..30); - - allocator.free_range(r1); - - let r3 = allocator.allocate_range(5).expect("Alloc 5 failed"); - assert_eq!(r3, 0..5); -} - -#[test] -fn test_out_of_memory() { - let mut allocator = RangeAllocator::new(0..10); - - let _r1 = allocator.allocate_range(10).unwrap(); - - let r2 = allocator.allocate_range(1); - assert!(r2.is_err(), "Should return error when OOM"); -} - -#[test] -fn test_fragmentation_and_merge() { - let mut allocator = RangeAllocator::new(0..100); - - let a = allocator.allocate_range(20).unwrap(); - let b = allocator.allocate_range(20).unwrap(); - let c = allocator.allocate_range(20).unwrap(); - let _d = allocator.allocate_range(40).unwrap(); - - allocator.free_range(a); - allocator.free_range(c); - - assert!(allocator.allocate_range(30).is_err()); - - allocator.free_range(b); - - let big = allocator - .allocate_range(60) - .expect("Should merge ranges A, B, C"); - assert_eq!(big, 0..60); -} - -#[test] -fn test_alignment_gaps() { - let mut allocator = RangeAllocator::new(1000..2000); - - let r1 = allocator.allocate_range(100).unwrap(); - assert_eq!(r1, 1000..1100); - - let r2 = allocator.allocate_range(100).unwrap(); - assert_eq!(r2, 1100..1200); -} diff --git a/scripts/repo/repos.csv b/scripts/repo/repos.csv index e8563fb38a..a1ea8b50e0 100644 --- a/scripts/repo/repos.csv +++ b/scripts/repo/repos.csv @@ -12,7 +12,6 @@ https://github.com/arceos-hypervisor/axvcpu,,virtualization/axvcpu,Hypervisor, https://github.com/arceos-hypervisor/axvisor_api,,virtualization/axvisor_api,Hypervisor, https://github.com/arceos-hypervisor/axvm,,virtualization/axvm,Hypervisor, https://github.com/arceos-hypervisor/axvmconfig,,virtualization/axvmconfig,Hypervisor, -https://github.com/arceos-hypervisor/range-alloc,,memory/range-alloc-arceos,Hypervisor, https://github.com/arceos-hypervisor/x86_vcpu,,virtualization/x86_vcpu,Hypervisor, https://github.com/arceos-hypervisor/x86_vlapic.git,,virtualization/x86_vlapic,Hypervisor, https://github.com/arceos-hypervisor/arm_vcpu,,virtualization/arm_vcpu,Hypervisor, diff --git a/scripts/test/std_crates.csv b/scripts/test/std_crates.csv index 0d474d1cc9..c5614430d9 100644 --- a/scripts/test/std_crates.csv +++ b/scripts/test/std_crates.csv @@ -26,7 +26,6 @@ ax-kernel-guard ax-kspin ax-lazyinit ax-linked-list-r4l -range-alloc-arceos riscv-h ax-riscv-plic riscv_vplic diff --git a/virtualization/axdevice/Cargo.toml b/virtualization/axdevice/Cargo.toml index f1113db5e4..5dce2a9698 100644 --- a/virtualization/axdevice/Cargo.toml +++ b/virtualization/axdevice/Cargo.toml @@ -25,7 +25,6 @@ ax-memory-addr = { workspace = true } axvmconfig = { workspace = true, default-features = false } axaddrspace = { workspace = true } axdevice_base = { workspace = true } -range-alloc-arceos = { workspace = true } [target.'cfg(target_arch = "aarch64")'.dependencies] arm_vgic = { workspace = true, features = ["vgicv3"] } [target.'cfg(target_arch = "riscv64")'.dependencies] diff --git a/virtualization/axdevice/src/device.rs b/virtualization/axdevice/src/device.rs index b53693c16d..b79b2dd78b 100644 --- a/virtualization/axdevice/src/device.rs +++ b/virtualization/axdevice/src/device.rs @@ -28,11 +28,10 @@ use axaddrspace::{ }; use axdevice_base::{BaseDeviceOps, BaseMmioDeviceOps, BasePortDeviceOps, BaseSysRegDeviceOps}; use axvmconfig::{EmulatedDeviceConfig, EmulatedDeviceType}; -use range_alloc_arceos::RangeAllocator; #[cfg(target_arch = "riscv64")] use riscv_vplic::VPlicGlobal; -use crate::AxVmDeviceConfig; +use crate::{AxVmDeviceConfig, range_alloc::RangeAllocator}; /// A set of emulated device types that can be accessed by a specific address range type. pub struct AxEmuDevices { @@ -88,7 +87,7 @@ pub struct AxVmDevices { emu_sys_reg_devices: AxEmuSysRegDevices, emu_port_devices: AxEmuPortDevices, /// IVC channel range allocator - ivc_channel: Option>>, + ivc_channel: Option>, } #[inline] @@ -321,8 +320,8 @@ impl AxVmDevices { allocator .lock() .allocate_range(size) - .map_err(|e| { - warn!("Failed to allocate IVC channel range: {e:x?}"); + .ok_or_else(|| { + warn!("Failed to allocate IVC channel range with size {size:#x}"); ax_errno::ax_err_type!(NoMemory, "IVC channel allocation failed") }) .map(|range| { @@ -344,10 +343,13 @@ impl AxVmDevices { } if let Some(allocator) = &self.ivc_channel { - allocator - .lock() - .free_range(addr.as_usize()..addr.as_usize() + size); - Ok(()) + let range = addr.as_usize()..addr.as_usize() + size; + if allocator.lock().free_range(range.clone()) { + debug!("Released IVC channel range: {range:x?}"); + Ok(()) + } else { + ax_err!(InvalidInput, "Invalid IVC channel range") + } } else { ax_err!(InvalidInput, "IVC channel not exists") } diff --git a/virtualization/axdevice/src/lib.rs b/virtualization/axdevice/src/lib.rs index 0b21f651ee..8d0be745c7 100644 --- a/virtualization/axdevice/src/lib.rs +++ b/virtualization/axdevice/src/lib.rs @@ -28,6 +28,7 @@ extern crate log; mod config; mod device; +mod range_alloc; pub use config::AxVmDeviceConfig; pub use device::AxVmDevices; diff --git a/virtualization/axdevice/src/range_alloc.rs b/virtualization/axdevice/src/range_alloc.rs new file mode 100644 index 0000000000..0118316808 --- /dev/null +++ b/virtualization/axdevice/src/range_alloc.rs @@ -0,0 +1,145 @@ +use alloc::{vec, vec::Vec}; +use core::ops::Range; + +/// A minimal best-fit range allocator for IVC GPA ranges. +#[derive(Debug)] +pub(crate) struct RangeAllocator { + initial: Range, + free: Vec>, +} + +impl RangeAllocator { + pub(crate) fn new(range: Range) -> Self { + Self { + initial: range.clone(), + free: vec![range], + } + } + + pub(crate) fn allocate_range(&mut self, size: usize) -> Option> { + debug_assert!(size > 0); + + let mut best_fit = None; + for (index, range) in self.free.iter().enumerate() { + let len = range.end - range.start; + if len < size { + continue; + } + if len == size { + best_fit = Some(index); + break; + } + match best_fit { + Some(best_index) + if len >= self.free[best_index].end - self.free[best_index].start => {} + _ => best_fit = Some(index), + } + } + + let index = best_fit?; + let start = self.free[index].start; + let end = start + size; + if self.free[index].end == end { + self.free.remove(index); + } else { + self.free[index].start = end; + } + Some(start..end) + } + + pub(crate) fn free_range(&mut self, range: Range) -> bool { + if range.start >= range.end + || range.start < self.initial.start + || range.end > self.initial.end + { + return false; + } + + let index = self + .free + .iter() + .position(|free| free.start > range.start) + .unwrap_or(self.free.len()); + + if index > 0 && self.free[index - 1].end > range.start { + return false; + } + if index < self.free.len() && range.end > self.free[index].start { + return false; + } + + if index > 0 && self.free[index - 1].end == range.start { + self.free[index - 1].end = range.end; + if index < self.free.len() && self.free[index - 1].end == self.free[index].start { + let next = self.free.remove(index); + self.free[index - 1].end = next.end; + } + } else if index < self.free.len() && range.end == self.free[index].start { + self.free[index].start = range.start; + } else { + self.free.insert(index, range); + } + + true + } +} + +#[cfg(test)] +mod tests { + use super::RangeAllocator; + + #[test] + fn allocates_and_reuses_ranges() { + let mut allocator = RangeAllocator::new(0..0x4000); + + assert_eq!(allocator.allocate_range(0x1000), Some(0..0x1000)); + assert_eq!(allocator.allocate_range(0x1000), Some(0x1000..0x2000)); + + assert!(allocator.free_range(0..0x1000)); + assert_eq!(allocator.allocate_range(0x1000), Some(0..0x1000)); + } + + #[test] + fn picks_best_fit_range() { + let mut allocator = RangeAllocator::new(0..0x9000); + + assert_eq!(allocator.allocate_range(0x3000), Some(0..0x3000)); + assert_eq!(allocator.allocate_range(0x3000), Some(0x3000..0x6000)); + assert_eq!(allocator.allocate_range(0x3000), Some(0x6000..0x9000)); + + assert!(allocator.free_range(0..0x3000)); + assert!(allocator.free_range(0x6000..0x9000)); + + assert_eq!(allocator.allocate_range(0x3000), Some(0..0x3000)); + assert_eq!(allocator.allocate_range(0x3000), Some(0x6000..0x9000)); + } + + #[test] + fn merges_neighboring_freed_ranges() { + let mut allocator = RangeAllocator::new(0..0x3000); + + assert_eq!(allocator.allocate_range(0x1000), Some(0..0x1000)); + assert_eq!(allocator.allocate_range(0x1000), Some(0x1000..0x2000)); + assert_eq!(allocator.allocate_range(0x1000), Some(0x2000..0x3000)); + + assert!(allocator.free_range(0..0x1000)); + assert!(allocator.free_range(0x2000..0x3000)); + assert!(allocator.free_range(0x1000..0x2000)); + + assert_eq!(allocator.allocate_range(0x3000), Some(0..0x3000)); + } + + #[test] + fn rejects_invalid_or_duplicate_frees() { + let mut allocator = RangeAllocator::new(0x1000..0x3000); + + assert!(!allocator.free_range(0x1000..0x1000)); + assert!(!allocator.free_range(0..0x1000)); + assert!(!allocator.free_range(0x2000..0x4000)); + assert!(!allocator.free_range(0x1000..0x2000)); + + assert_eq!(allocator.allocate_range(0x1000), Some(0x1000..0x2000)); + assert!(allocator.free_range(0x1000..0x2000)); + assert!(!allocator.free_range(0x1000..0x2000)); + } +} From 00b427c6c746d8ac08778f8ee902b12dafdec63b Mon Sep 17 00:00:00 2001 From: ZCShou <72115@163.com> Date: Wed, 27 May 2026 18:48:37 +0800 Subject: [PATCH 15/17] Refactor linker scripts and CI configuration (#992) * refactor(linker-scripts): remove unused linker scripts for hello, irq, and smp kernels * refactor(ci): switch clippy and std tests to self-hosted runners --- .github/workflows/ci.yml | 14 ++--- .../examples/hello-kernel/linker_x86_64.lds | 52 ------------------- .../examples/irq-kernel/linker_x86_64.lds | 52 ------------------- .../examples/smp-kernel/linker_x86_64.lds | 52 ------------------- docs/docs/build/ci.md | 14 +++-- 5 files changed, 14 insertions(+), 170 deletions(-) delete mode 100644 components/axplat_crates/examples/hello-kernel/linker_x86_64.lds delete mode 100644 components/axplat_crates/examples/irq-kernel/linker_x86_64.lds delete mode 100644 components/axplat_crates/examples/smp-kernel/linker_x86_64.lds diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a3796fc505..4465357e09 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -271,8 +271,9 @@ jobs: matrix: include: - name: Run clippy - use_container: true - runs_on: '["ubuntu-latest"]' + use_container: false + runs_on: '["self-hosted","linux","qcs"]' + self_hosted_owner: rcore-os command: | set -eux git_cmd() { @@ -300,16 +301,17 @@ jobs: else cargo xtask clippy fi - cache_key: clippy + cache_key: "" container_image: base fetch_depth: full limit_to_owner: "" main_pr_only: false - name: Test with std - use_container: true - runs_on: '["ubuntu-latest"]' + use_container: false + runs_on: '["self-hosted","linux","qcs"]' + self_hosted_owner: rcore-os command: cargo xtask test - cache_key: test-std + cache_key: "" container_image: base limit_to_owner: "" main_pr_only: false diff --git a/components/axplat_crates/examples/hello-kernel/linker_x86_64.lds b/components/axplat_crates/examples/hello-kernel/linker_x86_64.lds deleted file mode 100644 index 113e7914c0..0000000000 --- a/components/axplat_crates/examples/hello-kernel/linker_x86_64.lds +++ /dev/null @@ -1,52 +0,0 @@ -ENTRY(_start) -SECTIONS -{ - . = 0xffff800000200000; - _skernel = .; - - .text : ALIGN(4K) { - _stext = .; - *(.text.boot) - *(.text .text.*) - _etext = .; - } - - .rodata : ALIGN(4K) { - _srodata = .; - *(.rodata .rodata.*) - _erodata = .; - } - - .data : ALIGN(4K) { - _sdata = .; - *(.data .data.*) - *(.got .got.*) - } - - . = ALIGN(4K); - _percpu_start = .; - _percpu_end = _percpu_start + SIZEOF(.percpu); - .percpu 0x0 : AT(_percpu_start) { - _percpu_load_start = .; - *(.percpu .percpu.*) - _percpu_load_end = .; - . = _percpu_load_start + ALIGN(64) * 1; - } - . = _percpu_end; - _edata = .; - - .bss : AT(.) ALIGN(4K) { - *(.bss.stack) - . = ALIGN(4K); - _sbss = .; - *(.bss .bss.*) - *(COMMON) - _ebss = .; - } - - _ekernel = .; - - /DISCARD/ : { - *(.comment) - } -} diff --git a/components/axplat_crates/examples/irq-kernel/linker_x86_64.lds b/components/axplat_crates/examples/irq-kernel/linker_x86_64.lds deleted file mode 100644 index 113e7914c0..0000000000 --- a/components/axplat_crates/examples/irq-kernel/linker_x86_64.lds +++ /dev/null @@ -1,52 +0,0 @@ -ENTRY(_start) -SECTIONS -{ - . = 0xffff800000200000; - _skernel = .; - - .text : ALIGN(4K) { - _stext = .; - *(.text.boot) - *(.text .text.*) - _etext = .; - } - - .rodata : ALIGN(4K) { - _srodata = .; - *(.rodata .rodata.*) - _erodata = .; - } - - .data : ALIGN(4K) { - _sdata = .; - *(.data .data.*) - *(.got .got.*) - } - - . = ALIGN(4K); - _percpu_start = .; - _percpu_end = _percpu_start + SIZEOF(.percpu); - .percpu 0x0 : AT(_percpu_start) { - _percpu_load_start = .; - *(.percpu .percpu.*) - _percpu_load_end = .; - . = _percpu_load_start + ALIGN(64) * 1; - } - . = _percpu_end; - _edata = .; - - .bss : AT(.) ALIGN(4K) { - *(.bss.stack) - . = ALIGN(4K); - _sbss = .; - *(.bss .bss.*) - *(COMMON) - _ebss = .; - } - - _ekernel = .; - - /DISCARD/ : { - *(.comment) - } -} diff --git a/components/axplat_crates/examples/smp-kernel/linker_x86_64.lds b/components/axplat_crates/examples/smp-kernel/linker_x86_64.lds deleted file mode 100644 index 113e7914c0..0000000000 --- a/components/axplat_crates/examples/smp-kernel/linker_x86_64.lds +++ /dev/null @@ -1,52 +0,0 @@ -ENTRY(_start) -SECTIONS -{ - . = 0xffff800000200000; - _skernel = .; - - .text : ALIGN(4K) { - _stext = .; - *(.text.boot) - *(.text .text.*) - _etext = .; - } - - .rodata : ALIGN(4K) { - _srodata = .; - *(.rodata .rodata.*) - _erodata = .; - } - - .data : ALIGN(4K) { - _sdata = .; - *(.data .data.*) - *(.got .got.*) - } - - . = ALIGN(4K); - _percpu_start = .; - _percpu_end = _percpu_start + SIZEOF(.percpu); - .percpu 0x0 : AT(_percpu_start) { - _percpu_load_start = .; - *(.percpu .percpu.*) - _percpu_load_end = .; - . = _percpu_load_start + ALIGN(64) * 1; - } - . = _percpu_end; - _edata = .; - - .bss : AT(.) ALIGN(4K) { - *(.bss.stack) - . = ALIGN(4K); - _sbss = .; - *(.bss .bss.*) - *(COMMON) - _ebss = .; - } - - _ekernel = .; - - /DISCARD/ : { - *(.comment) - } -} diff --git a/docs/docs/build/ci.md b/docs/docs/build/ci.md index a8c3c462e4..2fa75ee096 100644 --- a/docs/docs/build/ci.md +++ b/docs/docs/build/ci.md @@ -89,8 +89,8 @@ push 到 `main` / `dev` 时强制运行 CI 检查。若非 `main` / `dev` 分支 | Job 名称 | Runner | 使用容器 | Cache Key | 功能说明 | |----------|--------|----------|-----------|----------| -| Run clippy | `ubuntu-latest` | 是(`base`) | `clippy` | `cargo xtask clippy --since `;需要完整 git 历史 | -| Test with std | `ubuntu-latest` | 是(`base`) | `test-std` | `cargo xtask test`,运行 `scripts/test/std_crates.csv` 中的 host 测试 | +| Run clippy | `self-hosted linux qcs` | 否 | 无 | `cargo xtask clippy --since `;需要完整 git 历史;fork PR 回退到 `ubuntu-latest` + `base` 容器 | +| Test with std | `self-hosted linux qcs` | 否 | 无 | `cargo xtask test`,运行 `scripts/test/std_crates.csv` 中的 host 测试;fork PR 回退到 `ubuntu-latest` + `base` 容器 | | Test axvisor aarch64 qemu | `self-hosted linux qcs` | 否 | 无 | `cargo xtask axvisor test qemu --arch aarch64`;`rcore-os` 仓库使用 self-hosted,fork PR 回退到 `ubuntu-latest` + `base` 容器 | | Test axvisor riscv64 qemu | `self-hosted linux qcs` | 否 | 无 | `cargo xtask axvisor test qemu --arch riscv64`;`rcore-os` 仓库使用 self-hosted,fork PR 回退到 `ubuntu-latest` + `base` 容器 | | Test axvisor loongarch64 qemu | `ubuntu-latest` | 是(`axvisor-lvz`) | `test-axvisor-loongarch64` | `cargo xtask axvisor test qemu --arch loongarch64`,使用带 LVZ 支持的镜像 | @@ -112,13 +112,13 @@ StarryOS stress 测试条目保留在 workflow 中,但当前处于注释状态 ## Self-Hosted Runner 约定 -self-hosted runner 任务优先在 `rcore-os` 仓库内运行。带 `self_hosted_owner` 的 QEMU 测试在 fork PR 或非 `rcore-os` 仓库中会回退到 `ubuntu-latest` + 对应容器,避免没有对应 runner 时长时间排队。迁移到 self-hosted 的 QEMU 测试直接在原生 runner 环境中运行,不再套 Docker container。 +self-hosted runner 任务优先在 `rcore-os` 仓库内运行。带 `self_hosted_owner` 的任务在 fork PR 或非 `rcore-os` 仓库中会回退到 `ubuntu-latest` + 对应容器,避免没有对应 runner 时长时间排队。迁移到 self-hosted 的任务直接在原生 runner 环境中运行,不再套 Docker container。 现有 label 约定: | Label | 用途 | |-------|------| -| `self-hosted`, `linux`, `qcs` | ArceOS QEMU 测试、Axvisor aarch64/riscv64 QEMU | +| `self-hosted`, `linux`, `qcs` | clippy、std 测试、ArceOS QEMU 测试、Axvisor aarch64/riscv64 QEMU | | `self-hosted`, `linux`, `intel`, `kvm` | Axvisor x86_64 KVM 测试 | | `self-hosted`, `linux`, `board` | 物理板卡测试 | @@ -127,11 +127,9 @@ self-hosted runner 任务优先在 `rcore-os` 仓库内运行。带 `self_hosted | Cache Key | 使用 Job | 保存时机 | 说明 | |-----------|----------|----------|------| | `sync-lint` | Run sync-lint | `push` 事件 | xtask 与 sync-lint 工具链编译产物 | -| `clippy` | Run clippy | `push` 事件 | xtask 与目标 crate 编译产物 | -| `test-std` | Test with std | `push` 事件 | host std 测试编译产物 | | `test-axvisor-loongarch64` | Test axvisor loongarch64 QEMU | `push` 事件 | Axvisor loongarch64 编译产物 | | `test-starry-riscv64/aarch64/loongarch64/x86_64` | Test starry riscv64/aarch64/loongarch64/x86_64 QEMU | `push` 事件 | StarryOS QEMU 编译产物 | -| 无(`cache_key: ""`) | self-hosted runner job | - | 依赖 self-hosted runner 本地磁盘缓存,不使用 GitHub Actions cache | +| 无(`cache_key: ""`) | self-hosted runner job,包括 Run clippy 和 Test with std | - | 依赖 self-hosted runner 本地磁盘缓存,不使用 GitHub Actions cache | self-hosted runner 不设置 `cache_key`,避免 `Swatinem/rust-cache@v2` 的 post-job 清理影响 runner 上跨次运行自然积累的共享缓存。 @@ -141,7 +139,7 @@ CI 使用两个容器镜像: | 镜像 | Dockerfile | 用途 | |------|------------|------| -| `base` | `container/Dockerfile` | 常规 clippy、sync-lint、std 测试、StarryOS QEMU,以及 self-hosted QEMU 测试在 fork PR 或非 `rcore-os` 仓库中的回退环境 | +| `base` | `container/Dockerfile` | sync-lint、StarryOS QEMU,以及 clippy、std、self-hosted QEMU 测试在 fork PR 或非 `rcore-os` 仓库中的回退环境 | | `axvisor-lvz` | `container/Dockerfile.axvisor-lvz` | Axvisor loongarch64 QEMU,额外包含 LVZ 支持 | 基础镜像以 `ubuntu:24.04` 为底,内置 Rust 工具链、QEMU、musl cross-toolchain、libav、libudev 等依赖。容器内的 musl cross-toolchain 已通过 `PATH` 配置好,`reusable-command.yml` 会在 container job 启动时验证 QEMU user emulators 和 musl compiler 是否存在,不再在运行时动态下载。 From 0394eedb4ea3d2c03411813dc1097b4ea8e76a80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=9D=BF?= Date: Wed, 27 May 2026 20:45:38 +0800 Subject: [PATCH 16/17] feat(deps): update spin to version 0.12.0 and bump other dependencies --- Cargo.lock | 358 ++++++++++++++++++++++++----------------------------- 1 file changed, 164 insertions(+), 194 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b35b735342..f296a4c2bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -567,7 +567,7 @@ dependencies = [ "nb", "num-align", "smccc", - "spin", + "spin 0.12.0", "thiserror 2.0.18", "tock-registers 0.10.1", ] @@ -585,7 +585,7 @@ dependencies = [ "axvisor_api", "log", "numeric-enum-macro", - "spin", + "spin 0.12.0", ] [[package]] @@ -602,7 +602,7 @@ dependencies = [ "axvisor_api", "bitmaps", "log", - "spin", + "spin 0.12.0", "tock-registers 0.10.1", ] @@ -664,9 +664,9 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "autocfg" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" [[package]] name = "aws-lc-rs" @@ -911,7 +911,7 @@ dependencies = [ "sg200x-bsp", "simple-ahci", "some-serial", - "spin", + "spin 0.12.0", "virtio-drivers", ] @@ -962,7 +962,7 @@ dependencies = [ "axfatfs", "log", "rsext4", - "spin", + "spin 0.12.0", ] [[package]] @@ -971,7 +971,7 @@ version = "0.3.11" dependencies = [ "ax-fs-vfs", "log", - "spin", + "spin 0.12.0", ] [[package]] @@ -997,7 +997,7 @@ dependencies = [ "rsext4", "scope-local", "slab", - "spin", + "spin 0.12.0", "starry-fatfs", ] @@ -1007,7 +1007,7 @@ version = "0.3.12" dependencies = [ "ax-fs-vfs", "log", - "spin", + "spin 0.12.0", ] [[package]] @@ -1038,16 +1038,16 @@ dependencies = [ "ax-plat-loongarch64-qemu-virt", "ax-plat-riscv64-qemu-virt", "ax-plat-riscv64-sg2002", + "ax-plat-riscv64-visionfive2", "ax-plat-x86-pc", + "ax-plat-x86-qemu-q35", "axplat-dyn", - "axplat-riscv64-visionfive2", - "axplat-x86-qemu-q35", "cfg-if", "fdt-parser", "heapless 0.9.3", "log", "rdrive", - "spin", + "spin 0.12.0", "toml 1.1.2+spec-1.1.0", ] @@ -1233,7 +1233,7 @@ dependencies = [ "cfg-if", "log", "smoltcp 0.13.1", - "spin", + "spin 0.12.0", ] [[package]] @@ -1262,7 +1262,7 @@ dependencies = [ "rdif-vsock", "ringbuf", "smoltcp 0.13.1", - "spin", + "spin 0.12.0", ] [[package]] @@ -1297,7 +1297,7 @@ dependencies = [ "ax-kernel-guard", "ax-percpu-macros", "cfg-if", - "spin", + "spin 0.12.0", "x86", ] @@ -1354,7 +1354,7 @@ dependencies = [ "ax-plat", "log", "some-serial", - "spin", + "spin 0.12.0", ] [[package]] @@ -1464,7 +1464,25 @@ dependencies = [ "sbi-rt 0.0.3", "sg200x-bsp", "some-serial", - "spin", + "spin 0.12.0", +] + +[[package]] +name = "ax-plat-riscv64-visionfive2" +version = "0.1.4" +dependencies = [ + "ax-config-macros", + "ax-cpu", + "ax-kspin", + "ax-lazyinit", + "ax-plat", + "ax-riscv-plic", + "log", + "rdrive", + "riscv 0.14.0", + "riscv_goldfish", + "sbi-rt 0.0.3", + "uart_16550 0.4.0", ] [[package]] @@ -1492,6 +1510,31 @@ dependencies = [ "x86_rtc", ] +[[package]] +name = "ax-plat-x86-qemu-q35" +version = "0.4.8" +dependencies = [ + "ax-config-macros", + "ax-cpu", + "ax-driver", + "ax-int-ratio", + "ax-kspin", + "ax-lazyinit", + "ax-percpu", + "ax-plat", + "axklib", + "bitflags 2.11.1", + "heapless 0.9.3", + "log", + "multiboot", + "raw-cpuid 11.6.0", + "uart_16550 0.4.0", + "x2apic", + "x86", + "x86_64", + "x86_rtc", +] + [[package]] name = "ax-posix-api" version = "0.5.16" @@ -1511,7 +1554,7 @@ dependencies = [ "bindgen 0.72.1", "flatten_objects", "scope-local", - "spin", + "spin 0.12.0", ] [[package]] @@ -1555,7 +1598,7 @@ dependencies = [ "rd-block", "rd-net", "rdrive", - "spin", + "spin 0.12.0", ] [[package]] @@ -1585,7 +1628,7 @@ dependencies = [ "ax-kspin", "ax-lazyinit", "lock_api", - "spin", + "spin 0.12.0", ] [[package]] @@ -1624,7 +1667,7 @@ dependencies = [ "extern-trait", "futures-util", "log", - "spin", + "spin 0.12.0", ] [[package]] @@ -1672,7 +1715,7 @@ dependencies = [ "gimli 0.33.0", "log", "paste", - "spin", + "spin 0.12.0", ] [[package]] @@ -1831,50 +1874,7 @@ dependencies = [ "log", "rdrive", "somehal", - "spin", -] - -[[package]] -name = "axplat-riscv64-visionfive2" -version = "0.1.4" -dependencies = [ - "ax-config-macros", - "ax-cpu", - "ax-kspin", - "ax-lazyinit", - "ax-plat", - "ax-riscv-plic", - "log", - "rdrive", - "riscv 0.14.0", - "riscv_goldfish", - "sbi-rt 0.0.3", - "uart_16550 0.4.0", -] - -[[package]] -name = "axplat-x86-qemu-q35" -version = "0.4.8" -dependencies = [ - "ax-config-macros", - "ax-cpu", - "ax-driver", - "ax-int-ratio", - "ax-kspin", - "ax-lazyinit", - "ax-percpu", - "ax-plat", - "axklib", - "bitflags 2.11.1", - "heapless 0.9.3", - "log", - "multiboot", - "raw-cpuid 11.6.0", - "uart_16550 0.4.0", - "x2apic", - "x86", - "x86_64", - "x86_rtc", + "spin 0.12.0", ] [[package]] @@ -1885,7 +1885,7 @@ dependencies = [ "bitflags 2.11.1", "futures", "linux-raw-sys 0.12.1", - "spin", + "spin 0.12.0", "tokio", ] @@ -1974,6 +1974,7 @@ dependencies = [ "ax-percpu", "ax-plat-loongarch64-qemu-virt", "ax-plat-riscv64-qemu-virt", + "ax-plat-x86-qemu-q35", "ax-std", "ax-timer-list", "axaddrspace", @@ -1983,7 +1984,6 @@ dependencies = [ "axhvc", "axklib", "axplat-dyn", - "axplat-x86-qemu-q35", "axvcpu", "axvisor_api", "axvm", @@ -2002,7 +2002,7 @@ dependencies = [ "rdrive", "riscv_vcpu", "riscv_vplic", - "spin", + "spin 0.12.0", "syn 2.0.117", "tokio", "toml 0.9.12+spec-1.1.0", @@ -2052,7 +2052,7 @@ dependencies = [ "log", "loongarch_vcpu", "riscv_vcpu", - "spin", + "spin 0.12.0", "x86_vcpu", ] @@ -2310,7 +2310,7 @@ dependencies = [ "divan", "log", "rand 0.10.1", - "spin", + "spin 0.12.0", ] [[package]] @@ -2325,14 +2325,14 @@ version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b672b945a3e4f4f40bfd4cd5ee07df9e796a42254ce7cd6d2599ad969244c44a" dependencies = [ - "spin", + "spin 0.10.0", ] [[package]] name = "bumpalo" -version = "3.20.2" +version = "3.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" [[package]] name = "bwbench-client" @@ -2645,9 +2645,9 @@ dependencies = [ [[package]] name = "compact_str" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b79c4069c6cad78e2e0cdfcbd26275770669fb39fd308a752dc110e83b9af32" +checksum = "7fd622ebbb56a5b2ccb651b32b911cdeb2a9b4b11776b2473bf26a26a286244e" dependencies = [ "castaway", "cfg-if", @@ -2659,9 +2659,9 @@ dependencies = [ [[package]] name = "compact_str" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb1325a1cece981e8a296ab8f0f9b63ae357bd0784a9faaf548cc7b480707a" +checksum = "9dfdd1c2274d9aa354115b09dc9a901d6c5576818cdf70d14cae2bdb47df00ab" dependencies = [ "castaway", "cfg-if", @@ -2825,7 +2825,7 @@ dependencies = [ "mbarrier", "nb", "num_enum", - "spin", + "spin 0.12.0", "thiserror 2.0.18", "tock-registers 0.10.1", "trait-ffi", @@ -3039,9 +3039,9 @@ dependencies = [ [[package]] name = "crypto-common" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77727bb15fa921304124b128af125e7e3b968275d1b108b379190264f4423710" +checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" dependencies = [ "hybrid-array", ] @@ -3123,7 +3123,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "321ec774d27fafc66e812034d0025f8858bd7d9095304ff8fc200e0b9f9cc257" dependencies = [ "ahash 0.8.12", - "compact_str 0.8.1", + "compact_str 0.8.2", "crossbeam-channel", "cursive-macros", "enum-map", @@ -3383,14 +3383,14 @@ checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" dependencies = [ "block-buffer 0.12.0", "const-oid", - "crypto-common 0.2.1", + "crypto-common 0.2.2", ] [[package]] name = "displaydoc" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +checksum = "1ac70aa55017e108007fbaf5aa0f54b021c98f92ff8af59d42eda9da96e3dd4f" dependencies = [ "proc-macro2", "quote", @@ -3507,9 +3507,9 @@ checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" [[package]] name = "either" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" +checksum = "91622ff5e7162018101f2fea40d6ebf4a78bbe5a49736a2020649edf9693679e" [[package]] name = "embedded-graphics" @@ -3631,9 +3631,9 @@ dependencies = [ [[package]] name = "enumset" -version = "1.1.12" +version = "1.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f96a4a12fe60ac746ae295a1a4ecb5bb02debc20856506c8635288065f142de" +checksum = "839c4174b41e75c8f7306110b2c51996a293b8d1d850edd529011841d9fede7d" dependencies = [ "enumset_derive", ] @@ -3886,9 +3886,9 @@ checksum = "9844ddc3a6e533d62bba727eb6c28b5d360921d5175e9ff0f1e621a5c590a4d5" [[package]] name = "fitimage" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cb4d07a1e7a76a7ac4b6b754d45670b1a82c8a0484d80cceeb30c99ad65ce1d" +checksum = "92edd7c1c55efd27b5a17dd6d505affafcfe48dfaed7423d4c4ae7361e56a7d8" dependencies = [ "anyhow", "byteorder", @@ -4065,9 +4065,9 @@ checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" [[package]] name = "futures-timer" -version = "3.0.3" +version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" +checksum = "af43fadb8a98512d547e37b4e92e0ced13e205c061b87b4623eff01d918d6968" [[package]] name = "futures-util" @@ -4183,9 +4183,9 @@ checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" [[package]] name = "goblin" -version = "0.10.5" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "983a6aafb3b12d4c41ea78d39e189af4298ce747353945ff5105b54a056e5cd9" +checksum = "0d494b2004fbc8cf419a6d2115488df4e11140f6f4abd877519de1bbd90c5370" dependencies = [ "log", "plain", @@ -4313,18 +4313,6 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" -[[package]] -name = "hello-kernel" -version = "0.3.1" -dependencies = [ - "ax-plat", - "ax-plat-aarch64-qemu-virt", - "ax-plat-loongarch64-qemu-virt", - "ax-plat-riscv64-qemu-virt", - "ax-plat-x86-pc", - "cfg-if", -] - [[package]] name = "hermit-abi" version = "0.5.2" @@ -4339,9 +4327,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "http" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a" +checksum = "8be7462df143984c4598a256ef469b251d7d7f9e271135073e78fc535414f3d0" dependencies = [ "bytes", "itoa", @@ -4736,20 +4724,6 @@ version = "2.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2" -[[package]] -name = "irq-kernel" -version = "0.3.1" -dependencies = [ - "ax-config-macros", - "ax-cpu", - "ax-plat", - "ax-plat-aarch64-qemu-virt", - "ax-plat-loongarch64-qemu-virt", - "ax-plat-riscv64-qemu-virt", - "ax-plat-x86-pc", - "cfg-if", -] - [[package]] name = "is-terminal" version = "0.4.17" @@ -4815,9 +4789,9 @@ dependencies = [ [[package]] name = "jiff" -version = "0.2.24" +version = "0.2.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f00b5dbd620d61dfdcb6007c9c1f6054ebd75319f163d886a9055cec1155073d" +checksum = "392c70591e8749fe235ddaf513e6f58b26bce3dcc16524cecc8936f75afa161e" dependencies = [ "jiff-static", "log", @@ -4828,9 +4802,9 @@ dependencies = [ [[package]] name = "jiff-static" -version = "0.2.24" +version = "0.2.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e000de030ff8022ea1da3f466fbb0f3a809f5e51ed31f6dd931c35181ad8e6d7" +checksum = "47b605b0c050d845fc355bb11eb3f9a8deddc218ea60c76e61aa1f2adfb2c96a" dependencies = [ "proc-macro2", "quote", @@ -4862,9 +4836,9 @@ dependencies = [ [[package]] name = "jkconfig" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8746ebf553e6e9d0620a918072432b44aa9563f6f19d17432b613828df708a1" +checksum = "d4cbaedffb63dabcbab61e23e0adc1fc7bc0d7420f2f56124e2bc0002d9274ab" dependencies = [ "anyhow", "cargo_metadata", @@ -4950,9 +4924,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.98" +version = "0.3.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67df7112613f8bfd9150013a0314e196f4800d3201ae742489d999db2f979f08" +checksum = "142bc4740e452c1e57ade0cbc129f139c9093e354346f0872ef985f4f5cf5f11" dependencies = [ "cfg-if", "futures-util", @@ -5079,6 +5053,12 @@ dependencies = [ "yaxpeax-x86", ] +[[package]] +name = "ksym" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b543b77d8cfa33302b6b51b6a255f9e85b06997b7c4a0a7354fcc8304036eb09" + [[package]] name = "ktest-helper" version = "0.1.1" @@ -5256,9 +5236,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.29" +version = "0.4.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" +checksum = "616ec5685824bcc94416c6d4a7a446eea774a31efd7062c8480ba6fd06d7a6e5" [[package]] name = "loongArch64" @@ -5395,9 +5375,9 @@ checksum = "ae960838283323069879657ca3de837e9f7bbb4c7bf6ea7f1b290d5e9476d2e0" [[package]] name = "memchr" -version = "2.8.0" +version = "2.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" +checksum = "6b947ae49db0d222b1dbc6b113ce7248a3fc3a6ca21b696717bfc000ba4484d8" [[package]] name = "memmap2" @@ -5608,9 +5588,9 @@ dependencies = [ [[package]] name = "num-conv" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6673768db2d862beb9b39a78fdcb1a69439615d5794a1be50caa9bc92c81967" +checksum = "521739c6d2bac4aa25192232afe6841231376b2b26d4d9fae5ecf8ca5772e441" [[package]] name = "num-derive" @@ -5730,7 +5710,7 @@ dependencies = [ "mmio-api", "pcie", "rd-block", - "spin", + "spin 0.12.0", "tock-registers 0.10.1", ] @@ -5802,9 +5782,9 @@ dependencies = [ [[package]] name = "ostool" -version = "0.19.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f785cb91e2622849c3f0e55d5363989934d365967c06f0a8ce8fd944f3b834ba" +checksum = "c4d0470fd8561e21f458d865490c928ebff45c0e1037a45f634a527acb8f15ff" dependencies = [ "anyhow", "async-trait", @@ -5818,7 +5798,7 @@ dependencies = [ "fitimage", "futures", "indicatif", - "jkconfig 0.2.3", + "jkconfig 0.2.4", "log", "lzma-rs", "network-interface", @@ -6397,7 +6377,7 @@ dependencies = [ "dma-api", "rd-block", "rdif-block", - "spin", + "spin 0.12.0", ] [[package]] @@ -6505,7 +6485,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ef8dea09a92caaf73bff7adb70b76162e5937524058a7e5bff37869cbbec293" dependencies = [ "bitflags 2.11.1", - "compact_str 0.9.0", + "compact_str 0.9.1", "hashbrown 0.16.1", "indoc", "itertools 0.14.0", @@ -6723,7 +6703,7 @@ dependencies = [ "futures", "heapless 0.9.3", "rdif-base", - "spin", + "spin 0.12.0", "thiserror 2.0.18", ] @@ -6764,7 +6744,7 @@ dependencies = [ "rdif-intc", "rdif-pcie", "rdrive-macros", - "spin", + "spin 0.12.0", "thiserror 2.0.18", ] @@ -6785,7 +6765,7 @@ dependencies = [ "log", "mmio-api", "rdif-eth", - "spin", + "spin 0.12.0", "thiserror 2.0.18", "tock-registers 0.10.1", ] @@ -6865,9 +6845,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62e0021ea2c22aed41653bc7e1419abb2c97e038ff2c33d0e1309e49a97deec0" +checksum = "219c5811de6525e5416c7d5d53bb656d3afdbc6c5af816e0802bcfa42dbdc1c3" dependencies = [ "base64 0.22.1", "bytes", @@ -7148,7 +7128,7 @@ dependencies = [ "mbarrier", "num-align", "rdif-base", - "spin", + "spin 0.12.0", "thiserror 2.0.18", "tock-registers 0.10.1", ] @@ -7175,7 +7155,7 @@ dependencies = [ "log", "mbarrier", "num-align", - "spin", + "spin 0.12.0", "thiserror 2.0.18", "tock-registers 0.10.1", ] @@ -7186,7 +7166,7 @@ version = "0.4.1" dependencies = [ "bitflags 2.11.1", "log", - "spin", + "spin 0.12.0", ] [[package]] @@ -7474,7 +7454,7 @@ version = "0.3.7" dependencies = [ "ax-percpu", "ctor 0.6.3", - "spin", + "spin 0.12.0", ] [[package]] @@ -7605,9 +7585,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.149" +version = "1.0.150" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9" dependencies = [ "itoa", "memchr", @@ -7881,23 +7861,6 @@ dependencies = [ "managed", ] -[[package]] -name = "smp-kernel" -version = "0.3.1" -dependencies = [ - "ax-config-macros", - "ax-cpu", - "ax-memory-addr", - "ax-percpu", - "ax-plat", - "ax-plat-aarch64-qemu-virt", - "ax-plat-loongarch64-qemu-virt", - "ax-plat-riscv64-qemu-virt", - "ax-plat-x86-pc", - "cfg-if", - "const-str", -] - [[package]] name = "socket2" version = "0.6.3" @@ -7961,7 +7924,7 @@ dependencies = [ "smccc", "some-serial", "somehal-macros", - "spin", + "spin 0.12.0", "syn 2.0.117", "thiserror 2.0.18", "tock-registers 0.10.1", @@ -7988,7 +7951,7 @@ dependencies = [ "sbi-rt 0.0.3", "someboot", "somehal-macros", - "spin", + "spin 0.12.0", "thiserror 2.0.18", "tock-registers 0.10.1", ] @@ -8008,6 +7971,12 @@ name = "spin" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5fe4ccb98d9c292d56fec89a5e07da7fc4cf0dc11e156b41793132775d3e591" + +[[package]] +name = "spin" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1527984ca054dfca79333baec451042863f485fbee01b7bf6d911de915cac865" dependencies = [ "lock_api", ] @@ -8106,6 +8075,7 @@ dependencies = [ "kernel-elf-parser", "kmod-loader", "kprobe", + "ksym", "ktracepoint", "linux-raw-sys 0.12.1", "lock_api", @@ -8120,7 +8090,7 @@ dependencies = [ "sg200x-bsp", "slab", "some-serial", - "spin", + "spin 0.12.0", "starry-process", "starry-signal", "starry-vm", @@ -8355,9 +8325,9 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tar" -version = "0.4.45" +version = "0.4.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22692a6476a21fa75fdfc11d452fda482af402c008cdbaf3476414e122040973" +checksum = "3f6221d9a6003c78398e3b239969f352578258df48c8eb051caadae0015bc840" dependencies = [ "filetime", "libc", @@ -9115,9 +9085,9 @@ dependencies = [ [[package]] name = "uboot-shell" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3b3d5d2959cc2e9a28cb2c4ad30f99a33f6831f4f159b08c696604b9494b672" +checksum = "2237321472e37a34980340e0a6f8ba406167fb010209ead2f0e594bdfb718e02" dependencies = [ "colored", "futures", @@ -9315,7 +9285,7 @@ dependencies = [ "futures", "log", "num_enum", - "spin", + "spin 0.12.0", "thiserror 2.0.18", ] @@ -9528,9 +9498,9 @@ dependencies = [ [[package]] name = "wasm-bindgen" -version = "0.2.121" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49ace1d07c165b0864824eee619580c4689389afa9dc9ed3a4c75040d82e6790" +checksum = "3ed04576f974d2b2fba0f38c51dbc5518011e38c36bf1143164be765528fd409" dependencies = [ "cfg-if", "once_cell", @@ -9541,9 +9511,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.71" +version = "0.4.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96492d0d3ffba25305a7dc88720d250b1401d7edca02cc3bcd50633b424673b8" +checksum = "9473dbd2991ae90b6291c3c32c30c6187ac49aa32f9905d1cce280ec1e110b0f" dependencies = [ "js-sys", "wasm-bindgen", @@ -9551,9 +9521,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.121" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e68e6f4afd367a562002c05637acb8578ff2dea1943df76afb9e83d177c8578" +checksum = "916151b09da36bd82f6615cbf3a419e2f0ba23a03c6160e8e92eb6bd4aa1dec6" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -9561,9 +9531,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.121" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d95a9ec35c64b2a7cb35d3fead40c4238d0940c86d107136999567a4703259f2" +checksum = "299047362ccbfce148b67ab7e73349f77748e00c8296f9542adfad2ad82c5c5e" dependencies = [ "bumpalo", "proc-macro2", @@ -9574,9 +9544,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.121" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4e0100b01e9f0d03189a92b96772a1fb998639d981193d7dbab487302513441" +checksum = "9a929b2c61f11ba3e9bc35b50c1f25cb38e0e892c0c231ae2b8cf78d5dad4437" dependencies = [ "unicode-ident", ] @@ -9636,9 +9606,9 @@ checksum = "dba9c05687e501b2710833fbe2cc7ff8cc24411fb0d81967498ca44598942f88" [[package]] name = "web-sys" -version = "0.3.98" +version = "0.3.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b572dff8bcf38bad0fa19729c89bb5748b2b9b1d8be70cf90df697e3a8f32aa" +checksum = "6d621441cfc37b84979402712047321980c178f299193a3589d05b99e8763436" dependencies = [ "js-sys", "wasm-bindgen", @@ -10347,9 +10317,9 @@ dependencies = [ [[package]] name = "yaxpeax-x86" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a9a30b7dd533c7b1a73eaf7c4ea162a7a632a2bb29b9fff47d8f2cc8513a883" +checksum = "a159e15f66ce40b5dfc28213366f8ff42ff8f0508e2e72e431c62573f025ac5e" dependencies = [ "cfg-if", "num-traits", From d7f95f1691b8be9ddc088d4121e49de2b6f9521e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=9D=BF?= Date: Wed, 27 May 2026 21:17:06 +0800 Subject: [PATCH 17/17] feat: remove riscv64-qemu-virt references and update platform support in configuration --- Cargo.lock | 1 - docs/docs/build/configuration.md | 4 ++-- os/arceos/modules/axhal/Cargo.toml | 4 ---- os/arceos/modules/axhal/build.rs | 5 ----- os/axvisor/Cargo.toml | 5 ----- os/axvisor/configs/board/qemu-riscv64-dyn.toml | 12 ------------ os/axvisor/src/hal/arch/riscv64/api.rs | 9 +++------ scripts/axbuild/src/axvisor/board.rs | 1 + scripts/axbuild/src/build.rs | 5 ----- scripts/axbuild/src/context/tests.rs | 2 +- scripts/axbuild/src/starry/test.rs | 14 +++++++++++++- .../normal/qemu-smp1/bugfix/qemu-aarch64.toml | 2 +- .../normal/qemu-smp1/bugfix/qemu-loongarch64.toml | 2 +- .../normal/qemu-smp1/bugfix/qemu-riscv64.toml | 2 +- .../normal/qemu-smp1/bugfix/qemu-x86_64.toml | 2 +- 15 files changed, 24 insertions(+), 46 deletions(-) delete mode 100644 os/axvisor/configs/board/qemu-riscv64-dyn.toml diff --git a/Cargo.lock b/Cargo.lock index f296a4c2bd..a882b41b79 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1973,7 +1973,6 @@ dependencies = [ "ax-page-table-multiarch", "ax-percpu", "ax-plat-loongarch64-qemu-virt", - "ax-plat-riscv64-qemu-virt", "ax-plat-x86-qemu-q35", "ax-std", "ax-timer-list", diff --git a/docs/docs/build/configuration.md b/docs/docs/build/configuration.md index 69d5c27e51..590b1d51e0 100644 --- a/docs/docs/build/configuration.md +++ b/docs/docs/build/configuration.md @@ -64,7 +64,7 @@ flowchart TD 除默认值差异外,各架构还有一些需要注意的特殊行为: -- **plat_dyn**:仅 `aarch64` 支持 `plat_dyn = true`(动态平台加载),其他架构使用静态平台绑定 +- **plat_dyn**:`aarch64` 和 `riscv64` 支持 `plat_dyn = true`(动态平台加载),其他架构使用静态平台绑定 - **to_bin**:`x86_64` 不使用 `--bin`(直接生成 ELF 即可),其余架构默认将 ELF 转为 raw binary - **LoongArch QEMU**:运行 Axvisor loongarch64 时自动搜索 LVZ 版 QEMU(详见 [运行](./run#loongarch-特殊处理)) @@ -286,7 +286,7 @@ axconfig 仅在**静态平台模式**(`plat_dyn = false`)下生成。动态 |--------|-------------|-----------------| | ArceOS | `true`(aarch64)/ `false`(其他) | 仅 `plat_dyn = false` 时 | | StarryOS | `false` | 始终生成 | -| Axvisor | `true`(aarch64)/ `false`(其他) | 仅 `plat_dyn = false` 时 | +| Axvisor | `true`(aarch64/riscv64)/ `false`(其他) | 仅 `plat_dyn = false` 时 | ### 生成流程 diff --git a/os/arceos/modules/axhal/Cargo.toml b/os/arceos/modules/axhal/Cargo.toml index 9e4fb56fd9..ec775a64c8 100644 --- a/os/arceos/modules/axhal/Cargo.toml +++ b/os/arceos/modules/axhal/Cargo.toml @@ -102,10 +102,6 @@ aarch64-phytium-pi = ["dep:ax-plat-aarch64-phytium-pi"] riscv64-qemu-virt = ["dep:ax-plat-riscv64-qemu-virt"] riscv64-sg2002 = ["dep:ax-plat-riscv64-sg2002"] riscv64-visionfive2 = ["dep:ax-plat-riscv64-visionfive2"] -riscv64-qemu-virt-hv = [ - "dep:ax-plat-riscv64-qemu-virt", - "ax-plat-riscv64-qemu-virt/hypervisor", -] loongarch64-qemu-virt = ["dep:ax-plat-loongarch64-qemu-virt"] x86-qemu-q35 = ["dep:ax-plat-x86-qemu-q35", "ax-plat-x86-qemu-q35/reboot-on-system-off"] defplat = [ diff --git a/os/arceos/modules/axhal/build.rs b/os/arceos/modules/axhal/build.rs index 116ca0125c..0354c4b780 100644 --- a/os/arceos/modules/axhal/build.rs +++ b/os/arceos/modules/axhal/build.rs @@ -65,11 +65,6 @@ const PLATFORM_FEATURES: &[PlatformFeature] = &[ target_arch: Some("riscv64"), crate_name: "ax_plat_riscv64_visionfive2", }, - PlatformFeature { - feature: "riscv64-qemu-virt-hv", - target_arch: Some("riscv64"), - crate_name: "ax_plat_riscv64_qemu_virt", - }, PlatformFeature { feature: "loongarch64-qemu-virt", target_arch: Some("loongarch64"), diff --git a/os/axvisor/Cargo.toml b/os/axvisor/Cargo.toml index 395a9aa617..ca265eb539 100644 --- a/os/axvisor/Cargo.toml +++ b/os/axvisor/Cargo.toml @@ -40,10 +40,6 @@ vmx = ["axvm/vmx"] svm = ["axvm/svm"] sstc = ["riscv_vcpu/sstc"] dyn-plat = ["ax-std/plat-dyn", "dep:axplat-dyn"] -riscv64-qemu-virt-hv = [ - "dep:ax-plat-riscv64-qemu-virt", - "ax-plat-riscv64-qemu-virt/hypervisor", -] rockchip-soc = ["ax-driver/rockchip-soc"] rockchip-sdhci = ["ax-driver/rockchip-sdhci", "ax-driver/rockchip-soc"] rockchip-dwmmc = ["ax-driver/rockchip-dwmmc", "ax-driver/rockchip-soc"] @@ -109,7 +105,6 @@ arm-gic-driver = { workspace = true, features = ["rdif"] } [target.'cfg(target_arch = "loongarch64")'.dependencies] ax-plat-loongarch64-qemu-virt = { workspace = true, default-features = false, features = ["irq", "smp"] } [target.'cfg(target_arch = "riscv64")'.dependencies] -ax-plat-riscv64-qemu-virt = { workspace = true, optional = true } riscv_vcpu = { workspace = true } riscv_vplic = { workspace = true } # xtask dependencies (only used on host platforms) diff --git a/os/axvisor/configs/board/qemu-riscv64-dyn.toml b/os/axvisor/configs/board/qemu-riscv64-dyn.toml deleted file mode 100644 index ab922ad886..0000000000 --- a/os/axvisor/configs/board/qemu-riscv64-dyn.toml +++ /dev/null @@ -1,12 +0,0 @@ -env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } -features = [ - "ax-driver/virtio-blk", - "ept-level-4", - "fs", - "sstc" -] -log = "Info" -plat_dyn = true -target = "riscv64gc-unknown-none-elf" -vm_configs = [] -max_cpu_num = 4 diff --git a/os/axvisor/src/hal/arch/riscv64/api.rs b/os/axvisor/src/hal/arch/riscv64/api.rs index 9876da4d2c..7a845e27f1 100644 --- a/os/axvisor/src/hal/arch/riscv64/api.rs +++ b/os/axvisor/src/hal/arch/riscv64/api.rs @@ -1,9 +1,6 @@ +#[cfg(not(feature = "dyn-plat"))] +compile_error!("riscv64 Axvisor requires the dyn-plat feature"); + pub(super) fn init_platform_irq_injector() { - #[cfg(feature = "dyn-plat")] axplat_dyn::register_virtual_irq_injector(crate::hal::arch::inject_interrupt); - - #[cfg(not(feature = "dyn-plat"))] - ax_plat_riscv64_qemu_virt::irq::register_virtual_irq_injector( - crate::hal::arch::inject_interrupt, - ); } diff --git a/scripts/axbuild/src/axvisor/board.rs b/scripts/axbuild/src/axvisor/board.rs index 7f03fdb8c9..f6a8c87094 100644 --- a/scripts/axbuild/src/axvisor/board.rs +++ b/scripts/axbuild/src/axvisor/board.rs @@ -152,6 +152,7 @@ env = { AX_IP = "10.0.2.15", AX_GW = "10.0.2.2" } target = "riscv64gc-unknown-none-elf" features = ["ept-level-4"] log = "Info" +plat_dyn = true "#, ); diff --git a/scripts/axbuild/src/build.rs b/scripts/axbuild/src/build.rs index 4f477ec200..d2dce88ebc 100644 --- a/scripts/axbuild/src/build.rs +++ b/scripts/axbuild/src/build.rs @@ -928,7 +928,6 @@ fn ax_hal_platform_feature_name<'a>( let platform = feature.strip_prefix("ax-hal/")?; match platform { "plat-dyn" => Some(platform), - "riscv64-qemu-virt-hv" => Some(platform), _ if metadata .map(|metadata| platform_package_by_name(metadata, platform).is_some()) .unwrap_or_else(|| is_known_ax_hal_platform_feature(platform)) => @@ -1034,10 +1033,6 @@ fn platform_packages(metadata: &Metadata) -> Vec { } fn platform_package_by_name(metadata: &Metadata, platform_name: &str) -> Option { - if platform_name == "riscv64-qemu-virt-hv" { - return platform_package_by_name(metadata, "riscv64-qemu-virt"); - } - platform_packages(metadata) .into_iter() .find(|platform| platform.metadata.platform == platform_name) diff --git a/scripts/axbuild/src/context/tests.rs b/scripts/axbuild/src/context/tests.rs index 1288a3ccd6..c81a09985e 100644 --- a/scripts/axbuild/src/context/tests.rs +++ b/scripts/axbuild/src/context/tests.rs @@ -489,7 +489,7 @@ fn prepare_axvisor_request_prefers_cli_over_snapshot() { config = "os/axvisor/.build.toml" arch = "riscv64" target = "riscv64gc-unknown-none-elf" -plat_dyn = false +plat_dyn = true vmconfigs = ["tmp/snapshot-vm.toml"] [qemu] diff --git a/scripts/axbuild/src/starry/test.rs b/scripts/axbuild/src/starry/test.rs index a6930f5738..76795e87b4 100644 --- a/scripts/axbuild/src/starry/test.rs +++ b/scripts/axbuild/src/starry/test.rs @@ -1340,12 +1340,24 @@ mod tests { #[test] fn bug_ext4_dir_ops_qemu_configs_fail_on_lockdep_fatal() { let workspace_root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../.."); - let case_dir = workspace_root.join("test-suit/starryos/normal/qemu-smp1/bug-ext4-dir-ops"); + let case_dir = workspace_root.join("test-suit/starryos/normal/qemu-smp1/bugfix"); for arch in ["aarch64", "loongarch64", "riscv64", "x86_64"] { let path = case_dir.join(format!("qemu-{arch}.toml")); let content = fs::read_to_string(&path).unwrap(); let config: toml::Value = toml::from_str(&content).unwrap(); + let test_commands = config + .get("test_commands") + .and_then(toml::Value::as_array) + .unwrap(); + assert!( + test_commands + .iter() + .filter_map(toml::Value::as_str) + .any(|command| command == "/usr/bin/bug-ext4-dir-ops"), + "{} must include the bug-ext4-dir-ops grouped command", + path.display() + ); let fail_regex = config .get("fail_regex") .and_then(toml::Value::as_array) diff --git a/test-suit/starryos/normal/qemu-smp1/bugfix/qemu-aarch64.toml b/test-suit/starryos/normal/qemu-smp1/bugfix/qemu-aarch64.toml index d719a0adf8..4bfffbcf74 100644 --- a/test-suit/starryos/normal/qemu-smp1/bugfix/qemu-aarch64.toml +++ b/test-suit/starryos/normal/qemu-smp1/bugfix/qemu-aarch64.toml @@ -96,5 +96,5 @@ test_commands = [ "/usr/bin/bug-waitid-basic", ] success_regex = ["(?m)^STARRY_GROUPED_TESTS_PASSED\\s*$"] -fail_regex = ['(?i)\bpanic(?:ked)?\b', '(?m)^STARRY_GROUPED_TEST_FAILED:'] +fail_regex = ['(?i)\bpanic(?:ked)?\b', "(?m)^lockdep fatal violation\\s*$", '(?m)^STARRY_GROUPED_TEST_FAILED:'] timeout = 360 diff --git a/test-suit/starryos/normal/qemu-smp1/bugfix/qemu-loongarch64.toml b/test-suit/starryos/normal/qemu-smp1/bugfix/qemu-loongarch64.toml index 50a7e7d342..7b92c33e8f 100644 --- a/test-suit/starryos/normal/qemu-smp1/bugfix/qemu-loongarch64.toml +++ b/test-suit/starryos/normal/qemu-smp1/bugfix/qemu-loongarch64.toml @@ -97,5 +97,5 @@ test_commands = [ "/usr/bin/bug-waitid-basic", ] success_regex = ["(?m)^STARRY_GROUPED_TESTS_PASSED\\s*$"] -fail_regex = ['(?i)\bpanic(?:ked)?\b', '(?m)^STARRY_GROUPED_TEST_FAILED:'] +fail_regex = ['(?i)\bpanic(?:ked)?\b', "(?m)^lockdep fatal violation\\s*$", '(?m)^STARRY_GROUPED_TEST_FAILED:'] timeout = 360 diff --git a/test-suit/starryos/normal/qemu-smp1/bugfix/qemu-riscv64.toml b/test-suit/starryos/normal/qemu-smp1/bugfix/qemu-riscv64.toml index 343b4466cc..dd019dcaa5 100644 --- a/test-suit/starryos/normal/qemu-smp1/bugfix/qemu-riscv64.toml +++ b/test-suit/starryos/normal/qemu-smp1/bugfix/qemu-riscv64.toml @@ -105,5 +105,5 @@ test_commands = [ "/usr/bin/bug-waitid-basic", ] success_regex = ["(?m)^STARRY_GROUPED_TESTS_PASSED\\s*$"] -fail_regex = ['(?i)\bpanic(?:ked)?\b', '(?m)^STARRY_GROUPED_TEST_FAILED:'] +fail_regex = ['(?i)\bpanic(?:ked)?\b', "(?m)^lockdep fatal violation\\s*$", '(?m)^STARRY_GROUPED_TEST_FAILED:'] timeout = 360 diff --git a/test-suit/starryos/normal/qemu-smp1/bugfix/qemu-x86_64.toml b/test-suit/starryos/normal/qemu-smp1/bugfix/qemu-x86_64.toml index 21f1152c8e..e8b1a476ed 100644 --- a/test-suit/starryos/normal/qemu-smp1/bugfix/qemu-x86_64.toml +++ b/test-suit/starryos/normal/qemu-smp1/bugfix/qemu-x86_64.toml @@ -102,5 +102,5 @@ test_commands = [ "/usr/bin/bug-waitid-basic", ] success_regex = ["(?m)^STARRY_GROUPED_TESTS_PASSED\\s*$"] -fail_regex = ['(?i)\bpanic(?:ked)?\b', '(?m)^STARRY_GROUPED_TEST_FAILED:'] +fail_regex = ['(?i)\bpanic(?:ked)?\b', "(?m)^lockdep fatal violation\\s*$", '(?m)^STARRY_GROUPED_TEST_FAILED:'] timeout = 360