Skip to content

refactor(drivers): split shared driver stack from ArceOS#831

Merged
ZR233 merged 56 commits into
rcore-os:devfrom
ZR233:refactor/driver
May 25, 2026
Merged

refactor(drivers): split shared driver stack from ArceOS#831
ZR233 merged 56 commits into
rcore-os:devfrom
ZR233:refactor/driver

Conversation

@ZR233

@ZR233 ZR233 commented May 21, 2026

Copy link
Copy Markdown
Member

背景

当前驱动实现和 ArceOS 平台 glue 耦合较深,跨 ArceOS、StarryOS、Axvisor 复用驱动时需要重复处理设备注册、MMIO/DMA、PCI/IRQ 路由和块/网络/显示/输入等接口边界。这个分支将公共驱动能力从单一 OS 模块中拆出,整理为更清晰的 Driver Core / Capability Boundary / OS Glue 分层。

主要改动

  • 新增并整理 drivers/ax-driver,承载通用块设备、网络、PCI、VirtIO、USB、SoC 等驱动实现。
  • 新增/调整 RDIF 相关接口与 rdrive 探测注册流程,让驱动 crate 通过统一接口暴露给不同内核侧。
  • 调整 ArceOS、StarryOS、Axvisor 以及平台配置中的驱动依赖、feature 和构建参数,使它们使用拆分后的驱动栈。
  • 将原先位于 ArceOS/动态平台中的部分驱动实现迁移到共享驱动 crate,并清理重复或过时的实现入口。
  • 移除已不再被 workspace、运行时代码、feature 配置或测试配置依赖的遗留 components/axdriver_crates 包组,并清理 workspace、lockfile、repo 元数据和文档引用。
  • 修复 StarryOS x86_64 util-linux 在新驱动栈下明显变慢的问题:rd-block 支持按设备 DMA buffer 合并连续块请求,ax-driver 块设备适配层保留上层批量 I/O 语义,virtio-blk 将 DMA buffer 调整为 32 个 sector。
  • 修复 aarch64 ArceOS std QEMU 配置中运行内存与平台声明不一致的问题,将 std qemu-smp1 的 aarch64 QEMU 内存改为 512M,避免 thread_test 在堆扩展后触发 DataAbort。
  • 调整 StarryOS x86_64 个别长耗时 case 的 timeout,为 CI 容器波动保留余量;其中 util-linux 的主要耗时回归已通过批量块 I/O 修复。

处理逻辑

  • 先保留 OS 侧现有设备初始化语义,只把可复用驱动实现和设备接口边界向 drivers/ 下沉,降低行为变化范围。
  • 平台侧继续通过原有配置和 feature 选择设备组合,驱动 crate 负责具体设备能力,OS 侧只消费统一接口。
  • 对遗留 components/axdriver_crates,先确认仓库代码、workspace feature 和测试配置已切到 drivers/ax-driverrdriverd-blockrd-netrdif-*,再完整移除旧本地 path crate,避免继续暴露已弃用入口。
  • 对 aarch64 std QEMU 失败,根因是平台配置声明 RAM 为 512M,但 std QEMU 只启动 128M;thread_test 压力下 allocator 访问到声明内存范围内、QEMU 实际内存范围外的地址。因此同步 QEMU 内存到 512M。
  • 对 StarryOS x86_64 util-linux 变慢,根因是新 ax-driver/rd-block 路径把 ext4/rsext4 传下来的批量块 I/O 拆成大量 512B 同步请求,loop/ext4 的 writeback 和 umount 阶段因此被放大。修复后,rd-block 根据设备声明的 buffer 大小切分连续请求,ax-driverBlock 适配层使用 merged read/write,virtio-blk 最终可以把多 sector buffer 直接交给 VirtIOBlk::read_blocks/write_blocks

性能提升

util-linux x86_64 的变慢集中在 loop/ext4 写回路径。修复前,本分支在旧 CI 日志中 qemu run 约 64.36s、case 约 70.53s;本地单跑也出现过 qemu run 约 80.52s、case 约 102.33s。对比 dev 上同类 CI 日志,util-linux 通常约 38-41s。

修复后本地验证:

  • cargo xtask starry test qemu --arch x86_64 -c util-linux
  • qemu run: 18.86s
  • PASS util-linux (19.69s)

也就是说,QEMU 阶段相对修复前约 64-80s 降到 18.86s,约 3.4x-4.3x 加速,并且已经低于 dev 日志中的 38-41s 水平。

验证

  • cargo metadata --locked --format-version 1
  • cargo tree --locked --workspace -i ax-driver-base,预期找不到该 package
  • cargo tree --locked --workspace -i ax-driver-virtio,预期找不到该 package
  • cargo tree --locked -p ax-driver --edges normal,features
  • cargo fmt --all -- --check
  • cargo fmt --all
  • cargo xtask clippy --package rd-block
  • cargo xtask clippy --package ax-driver
  • cargo xtask clippy --package axplat-dyn
  • cargo xtask clippy --package ax-runtime
  • cargo xtask sync-lint --since c41e98ba2fef8aa529a7a50fa1fd11deab5d7fac
  • cargo xtask arceos test qemu --arch aarch64 --test-group std --test-case thread_test
  • cargo xtask starry test qemu --arch x86_64 -c test-mmap-prot-write
  • cargo xtask starry test qemu --arch x86_64 -c util-linux

最新 head: 5e4096b0b

ZR233 added 28 commits May 18, 2026 16:33
- Implemented the RK3588 PCIe host driver in `resources.rs`, handling GPIO resets, memory mapping, and configuration.
- Created slot drivers for multiple PCIe slots in `slots.rs`, enabling dynamic probing of PCIe devices.
- Added memory window programming logic in `windows.rs`, including configuration window detection and logging of resources.
- Introduced a new `PlatformVsockDevice` in `vsock.rs` for managing Virtio socket devices, with registration and device handling.
- Updated `virtio.rs` to use the new Virtio driver interface.
- Modified the Clippy crates list to include new dependencies for the added components.
- Adjusted build configuration to remove unnecessary Virtio net feature for the AArch64 platform.
- Updated Cargo.lock and Cargo.toml to include dma-api and mmio-api dependencies.
- Implemented DMA operations in axklib with a new dma.rs file, providing functionality for allocating and managing DMA pages.
- Created mmio.rs to handle memory-mapped I/O operations, including ioremap and iounmap functionalities.
- Refactored axruntime and various platform drivers to utilize the new DMA and MMIO abstractions, replacing previous implementations.
- Removed obsolete DmaImpl struct and related code from drivers, streamlining the DMA handling process.
- Ensured compatibility with existing driver interfaces by adapting to the new DMA and MMIO APIs.
- Consolidated static device initialization logic into `devices.rs`.
- Introduced `StaticBlockDevice` to handle block device operations.
- Removed old static device modules (`block.rs`, `dma.rs`, `virtio.rs`, `virtio_block.rs`) and their associated functionality.
- Updated `Cargo.toml` files to remove unused driver dependencies.
- Adjusted build configurations to reflect the removal of static device drivers.
- Enhanced error handling and device probing for static devices.
- Removed the `virtio/input.rs`, `virtio/vsock.rs`, and `vsock.rs` files as they are no longer needed.
- Updated `Cargo.toml` files to change dependencies from `ax-driver` to `ax-drivers` for better modularization.
- Refactored device initialization in `devices.rs` to utilize the new `ax-drivers` bindings for display, input, net, and vsock devices.
- Simplified PCI driver implementations by using the new `ax-drivers` functions for transport and IRQ registration.
- Cleaned up the `virtio` and `pci` driver implementations to align with the new structure and removed legacy code.
- Updated the `clippy_crates.csv` to include `ax-driver` and `ax-drivers` for linting checks.
- Removed static driver registration and initialization functions from `init.rs`, `registers.rs`, and `source.rs`.
- Updated `ramdisk.rs`, `sdmmc.rs`, `fxmac.rs`, and other driver files to use a simplified registration approach.
- Introduced `register_mmio` and `register_ecam_controller` functions for dynamic device registration.
- Enhanced the `probe_pci` functions across various drivers to focus solely on PCI device registration.
- Removed unnecessary static device descriptors and streamlined the initialization process for static devices.
- Updated Cargo.toml files to reflect changes in dependencies and features, including the addition of `sdmmc` and `cvsd`.
- Added new driver registration logic in the `riscv64-visionfive2` platform to support SD/MMC devices.
- Deleted the `virtio.rs`, `virtio_pci.rs`, `display.rs`, `input.rs`, `serial/mod.rs`, `net/mod.rs`, `usb/mod.rs`, `vsock.rs`, and `pci.rs` files to streamline the driver architecture.
- Moved relevant functionality to `ax_drivers` for better modularity and maintainability.
- Updated `mod.rs` to reflect the removal of unused modules and adjusted the driver registration process.
- Enhanced the `generic_timer.rs` by making `try_init_epoch_offset` public for broader access.
- Cleaned up the `lib.rs` to expose necessary components while removing deprecated references.
- Removed the `bindings` module and integrated its contents directly into the respective driver modules (block, display, input, net, vsock).
- Created new binding files for block, display, input, net, and vsock drivers to encapsulate their platform-specific device structures and functionalities.
- Updated references throughout the codebase to reflect the new module structure, ensuring that all driver implementations correctly utilize the new bindings.
- Improved organization and clarity of the driver code by separating concerns and enhancing modularity.
- Updated linker scripts to define driver registration sections for various architectures (x86, RISC-V, Loongarch).
- Refactored driver initialization in axplat crates to conditionally include PCI and Virtio drivers based on feature flags.
- Introduced new driver modules for RISC-V and x86 platforms to handle Virtio block devices.
- Enhanced Cargo.toml files to include necessary dependencies for PCI and Virtio drivers.
- Modified initialization routines to ensure proper setup of drivers during platform initialization.
- Updated configuration files for QEMU boards to enable PCI and Virtio features.
- Removed the `registers.rs` files from various platforms, consolidating the register handling into a new `registers.rs` in the `axruntime` module.
- Updated the `init.rs` files across platforms to eliminate direct driver initialization calls, instead relying on a unified `probe_all_devices` function.
- Introduced static device registration for various drivers (SD/MMC, PCIe ECAM, VirtIO) using the new static device registration mechanism.
- Enhanced the `StaticDeviceDesc` structure to support additional properties like `regs` and `pci_ecam`.
- Updated the build scripts to include new static features for drivers.
- Adjusted the `DriversIf` trait implementation to provide static device descriptions for platforms.
- Updated feature lists in multiple TOML files for aarch64, loongarch64, riscv64gc, and x86_64 architectures to include new hardware abstraction layer (HAL) and driver features.
- Added support for PCI, VirtIO block, VirtIO net, and other drivers to improve hardware compatibility and performance.
- Adjusted features in the axvisor and starryos test suites to ensure consistency and leverage new capabilities.
- Ensured that all configurations now utilize the latest HAL and driver features for enhanced functionality and stability.
…x-driver"

- Updated multiple TOML configuration files across various test suites to change the feature prefix from "ax-drivers" to "ax-driver" for consistency and clarity.
- This change affects configurations for platforms including x86_64, aarch64, loongarch64, and riscv64 in both normal and stress test scenarios.
- Ensured that all relevant files reflect this naming convention to maintain uniformity across the codebase.
- Added virtio-net-pci and netdev configurations to QEMU arguments for aarch64, loongarch64, riscv64, and x86_64 test cases to enable networking capabilities.
- Removed unnecessary PCI and virtio driver features from build configurations for aarch64, loongarch64, riscv64, and x86_64.
- Updated hello world, HTTP client, IO test, thread test, and Tokio test configurations to include virtio-blk-pci for disk access.
- Adjusted Cargo.toml files to streamline dependencies by removing unused features related to multitasking and IRQ handling.
@ZR233
ZR233 marked this pull request as ready for review May 21, 2026 07:41
- Replaced instances of `ax-driver-base`, `axdriver_*` with new naming conventions: `rdrive`, `rd-*`, and `rdif-*` across various documentation files.
- Updated dependency references in `ax-hal`, `ax-input`, `ax-net-ng`, `ax-posix-api`, `ax-runtime`, and `axplat-dyn` to reflect the new driver structure.
- Removed references to deprecated driver crates in `layers.md`, `overview.md`, and `components.md`.
- Adjusted the driver subsystem section in the documentation to align with the new driver architecture.
- Modified the repository management script to remove specific handling for `axdriver_crates` due to structural changes.

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

审查意见:refactor(drivers): split shared driver stack from ArceOS

总体评价

本次 PR 将公共驱动能力从 ArceOS 拆出到 drivers/ax-driver(v0.6.0),引入 rdif-displayrdif-inputrdif-vsock 新 RDIF 接口,新增 rd-block-volume 分区扫描库,并完整清理了废弃的 components/axdriver_crates 包组及旧 os/arceos/modules/axdriver。Driver Core / Capability Boundary / OS Glue 三层方向正确,代码质量整体良好。

与前轮审查意见的关系

前轮审查提出的所有阻塞点和代码建议在当前 head 884afd12c 中均已解决:

  • 合并冲突git merge-tree 确认无冲突,mergeable: true
  • DMA alloc_for_layout 文档注释:已添加 doc comment,明确说明 dma_alloc_pages 应保证 DMA mask 和对齐约束,下方检查为防御性验证。
  • SyncBlockOps::flush() 移除:已从 trait 中移除。
  • SyncBlockQueue::poll_request 优化:现在直接返回 Ok(()),与 VirtIO block 的实现保持一致。

本地验证结果(head 884afd12c

  • cargo fmt --all -- --check: ✅ 通过
  • cargo clippy -p rd-block-volume -p rdif-display -p rdif-input -p rdif-vsock --all-features -- -D warnings: ✅ 通过
  • cargo test -p rd-block-volume: ✅ 5 个测试通过(GPT/MBR 分区扫描)
  • cargo test -p rdif-input: ✅ 1 个测试通过
  • cargo test -p rdif-vsock: ✅ 2 个测试通过
  • cargo test -p rdif-display: ✅ 1 个测试通过
  • git merge-tree: ✅ 无冲突
  • 旧包 components/axdriver_cratesos/arceos/modules/axdriver: ✅ 已从 workspace 完整移除

代码审查要点

  1. Feature flag 体系完整ax-driver/Cargo.toml 的 feature 设计覆盖块设备、网络、显示、输入、vsock、VirtIO、USB、PCI、SoC 等所有驱动类别,依赖方向清晰,每个类别有独立的 feature gate。

  2. build.rs cfg 设计精巧:通过 probe cfg(static/fdt/pci)和 sync_block_dev 等自定义 cfg 实现条件编译,配合 rustc-check-cfg 声明,编译器诊断友好。sync_block_dev 仅在 ahci/bcm2835-sdhci/sdmmc 或 cvsd on riscv 时启用,覆盖准确。

  3. VirtIO 驱动适配层干净VirtIoHalImpl 正确委托给 axklibvirt_to_phys/ioremap_rawvirtio/block.rsbuff_config 设置 VIRTIO_BLK_DMA_BUFFER_SIZE = 32 * SECTOR_SIZE,解决了性能回归问题。poll_request 返回 Ok(()) 与同步设备语义一致。

  4. rd-block-volume 分区扫描:GPT/MBR 扫描逻辑干净,5 个单元测试覆盖完整,无外部依赖(仅 alloc),适合作为 no_std 基础库。

  5. QEMU 配置修复正确:aarch64 std QEMU 内存 128M→512M 修复 DataAbort,根因分析清晰。StarryOS timeout 放宽(util-linuxtest-mmap-prot-write)合理。

  6. axplat-dyn 依赖简化:原先直接依赖大量驱动 crate,现在统一委托给 ax-driver,依赖图更清晰。

  7. 配置迁移一致:所有 build config 中的 feature 引用已从 axplat-dyn/*ax-feat/* 统一迁移到 ax-driver/*,与新的 crate 结构匹配。

重复/重叠分析

  • base 分支:dev 上不存在等效的统一驱动栈重构,旧 components/axdriver_crates 包组已被本 PR 替换。
  • 相关 open PR
    • PR #847(kprobe):内核探针功能,与驱动栈无关。
    • PR #863(capget 测试):syscall 测试,与驱动栈无关。
    • 未发现其他与驱动栈拆分重复或冲突的 open PR。
  • 结论:本 PR 独特,无重复。

遗留观察(非阻塞)

  • VirtIoHalImpl share 缺少 cache flush:与旧代码行为一致,KlibDma DMA 框架已就绪,后续可在非 cache-coherent 平台上统一管理 streaming DMA 的 cache 一致性。
  • 远端 CI 全部 skipped:fork PR 上 CI 未触发,这是 fork PR 的已知行为,需要维护者在 GitHub Actions 中 approve workflow 运行。mergeable: true 表明合入无技术障碍。

结论

代码拆分正确、本地 fmt/clippy/test 全部通过、新接口设计干净、文档完善、前轮建议全部采纳、无合并冲突。建议合入。

Powered by glm-5.1

ZR233 added 5 commits May 25, 2026 09:24
# Conflicts:
#	Cargo.lock
#	Cargo.toml
#	components/axdriver_crates/axdriver_net/Cargo.toml
#	components/axdriver_crates/axdriver_net/src/net_buf.rs
#	drivers/ax-driver/src/block/binding.rs
#	drivers/ax-driver/src/soc/scmi.rs
#	drivers/rdrive/src/lib.rs
#	os/StarryOS/kernel/Cargo.toml
#	os/StarryOS/kernel/src/pseudofs/dev/loop.rs
#	os/StarryOS/kernel/src/pseudofs/dev/tty/mod.rs
#	os/StarryOS/kernel/src/pseudofs/dev/tty/terminal/job.rs
#	os/arceos/api/arceos_api/Cargo.toml
#	os/arceos/api/axfeat/Cargo.toml
#	os/arceos/modules/axdriver/Cargo.toml
#	os/arceos/modules/axfs-ng/Cargo.toml
#	os/arceos/modules/axfs-ng/src/fs/ext4/lwext4/fs.rs
#	os/arceos/modules/axfs-ng/src/fs/ext4/rsext4/fs.rs
#	os/arceos/modules/axfs-ng/src/fs/fat/fs.rs
#	os/arceos/modules/axfs/src/dev.rs
#	platform/axplat-dyn/src/drivers/blk/virtio_pci.rs
#	platform/axplat-dyn/src/drivers/mod.rs
#	platform/axplat-dyn/src/drivers/net/virtio_pci.rs
#	platform/axplat-dyn/src/drivers/pci.rs

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

审查意见:refactor(drivers): split shared driver stack from ArceOS

总体评价

本次 PR 将公共驱动能力从 ArceOS 单一 OS 模块拆出到 drivers/ax-driver(v0.6.0),引入 rdif-displayrdif-inputrdif-vsockrd-block-volume 等新接口和库,并完整清理了废弃的 components/axdriver_crates 包组(8 个子 crate)。Driver Core / Capability Boundary / OS Glue 三层分层方向正确,代码质量整体良好。

与历史审查意见的关系

前五轮审查(mai-team-app)的核心阻塞点是合并冲突和远端 CI。当前 head d046c8cb5 的 merge-base 与 dev HEAD(7793fb648)完全一致,合并冲突已解决。

前轮代码层面建议的评估(延续上轮结论):

  • DMA alloc_for_layout 后验逻辑dma_alloc_pages 接受 dma_mask 参数,在约束内尝试分配;后验检查是安全兜底,不构成阻塞。
  • VirtIoHalImpl share 缺少 cache flush:与旧代码行为一致,KlibDma DMA 框架已就绪,后续可统一管理。不构成阻塞。
  • SyncBlockQueue poll_request 调用 flush():默认 flush() 返回 Ok(()),性能影响微小。VirtIO block 的 poll_request 已直接返回 Ok(()),建议 SyncBlockQueue 保持一致。不构成阻塞。

本地验证结果

  • cargo fmt --check:✅ 通过
  • cargo clippy -p ax-driver --all-features -- -D warnings:✅ 通过
  • cargo test -p rd-block-volume --all-features:✅ 5 个测试通过(GPT/MBR 分区扫描)
  • cargo test -p rdif-display:✅ 1 个测试通过
  • cargo test -p rdif-input:✅ 1 个测试通过
  • cargo test -p rdif-vsock:✅ 2 个测试通过

代码审查重点

  1. drivers/ax-driver 架构设计:新的 ax-driver crate 通过 rdrive probe 机制统一管理设备注册,平台侧通过 DriversIf::static_devices_fn() 声明静态设备描述,不再直接依赖具体驱动 crate。axplat-dyndrivers.rs 精简为 rdrive::probe_all(false) 一行调用,依赖从直接依赖大量驱动 crate 统一为 ax-driver。架构清晰。

  2. Feature flag 体系ax-driver/Cargo.toml 的 feature 设计覆盖了块设备(ramdisk/ahci/cvsd/bcm2835-sdhci/rockchip-sdhci/rockchip-dwmmc/phytium-mci)、网络(ixgbe/fxmac/intel-net/realtek-rtl8125)、VirtIO(blk/net/gpu/input/socket)、USB(dwc-xhci/xhci-mmio/xhci-pci)、PCI(rk3588-pcie)、SoC(rockchip/rockchip-pm)、串口/RTC/NPU 等所有驱动类别。依赖方向清晰,每个驱动类别有独立 feature gate。

  3. build.rs cfg 设计:通过 probe cfg(static/fdt/pci)和 sync_block_dev 等自定义 cfg 实现条件编译,配合 rustc-check-cfg 声明,编译器诊断友好。build.rs 中 feature→cfg 映射逻辑正确。

  4. VirtIO 块设备性能修复virtio/block.rsbuff_config 设置 VIRTIO_BLK_DMA_BUFFER_SIZE = 32 * SECTOR_SIZE,配合 rd-blockmax_blocks_per_request()block_ranges() 按 buffer 大小拆分连续请求,解决了新驱动栈下 util-linux 变慢的性能回归。PR 正文报告的加速数据(64-80s → 18.86s,约 3.4x-4.3x)来自合理的批量 I/O 语义修复。

  5. 新 RDIF 接口rdif-displayrdif-inputrdif-vsock 三个新接口 trait 设计干净,默认实现合理,与现有 rdif-* 系列风格一致。

  6. rd-block-volume 分区扫描:GPT/MBR 扫描逻辑干净,5 个单元测试覆盖完整(GPT 单分区、MBR 主分区、MBR 逻辑分区、GPT 数组边界、全盘回退),无外部依赖(仅 alloc),适合作为 no_std 基础库。

  7. 驱动 crate 解耦arm-scmi-rsnvme-driverramdiskrdif-serialrealtek-rtl8125crab-usb 等从 ax-kspin 迁移到 spin,提升了驱动 crate 的跨内核可移植性。

  8. QEMU 配置修复:aarch64 std QEMU 内存 128M→512M 修复 DataAbort 问题,根因分析(平台声明 512M 但 QEMU 只给 128M)清晰。

重复与重叠分析

  • dev 基线检查:dev 分支上 components/axdriver_crates 目录仍然存在(PR #861 只迁移了 spin 用法但未移除旧 crate),PR #831 是第一个完整清理该目录的 PR。dev 上没有等效的驱动拆分实现,PR #831 是唯一的。

  • 相关开放 PR 检查

    • PR #859(AxVisor board tests)也涉及 rockchip-sdhci/rockchip-dwmmc/phytium-mci 的 feature 拆分,但 PR #859 是 AxVisor 板级测试增强,其 driver feature 命名与本 PR 一致。PR #859 为 draft 状态,应在本 PR 合入后 rebase,不构成冲突。
    • PR #704(UART support for RK3588)为 draft,与本 PR 的驱动框架无关。
    • 结论:无重复、无冲突、无被取代风险。PR #831 是基础性重构,其他 driver 相关 PR 宜在本 PR 后合入。

⚠️ 阻塞项

远端 CI 全部 skipped:当前 head d046c8cb5 上所有 GitHub Actions check run 均为 skipped(共 15+ 个 job,包括 clippy、test starry、test arceos、test axvisor、test with std 等)。mergeable_state: unknown 意味着无法确认分支保护规则是否满足。

这是第六轮审查仍持续存在的问题。虽然本地 fmt/clippy/unit test 全部通过,但涉及 532 个文件、14k+ 行新增的驱动重构,无法仅靠本地验证覆盖所有平台(aarch64/riscv64/loongarch64/x86_64 的 ArceOS/StarryOS/AxVisor QEMU 和板级测试)。

请作者确认:

  1. GitHub Actions 工作流是否在 fork PR 上正确触发(可能需要 repo maintainer 手动 approve fork 运行,或配置 pull_request_target 事件)
  2. 远端 CI 全部通过后方可合入

结论

代码拆分正确、架构分层清晰、本地 fmt/clippy/test 全部通过、合并冲突已解决、无重复/冲突 PR。远端 CI 全部 skipped 是唯一阻塞项。请确认 CI 正常运行后可合入。

Powered by deepseek-v4-pro

ZR233 added 2 commits May 25, 2026 11:16
# Conflicts:
#	scripts/axbuild/src/axvisor/build.rs
#	scripts/axbuild/src/build.rs

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

审查意见:refactor(drivers): split shared driver stack from ArceOS

总体评价

本次 PR 将公共驱动能力从 ArceOS 单一 OS 模块拆出到 drivers/ax-driver(v0.6.0),引入 rdif-displayrdif-inputrdif-vsock 新 RDIF 接口,新增 rd-block-volume 分区扫描库,并完整清理了废弃的 components/axdriver_crates 包组及旧 os/arceos/modules/axdriver。Driver Core / Capability Boundary / OS Glue 三层方向正确,代码质量整体良好。

与前九轮审查意见的关系

前九轮审查提出的所有阻塞点和代码建议在最新提交中均已解决:

  • 合并冲突:当前 head 8f77a431 已合并最新 dev,无冲突。
  • DMA alloc_for_layout 文档注释:已添加 doc comment,明确说明 dma_alloc_pages 应保证 DMA mask 和对齐约束。
  • SyncBlockOps::flush() 移除:已从 trait 中移除。
  • SyncBlockQueue::poll_request 优化:现在直接返回 Ok(()),与 VirtIO block 的 poll_request 实现一致。
  • 旧包 components/axdriver_crates:已从 workspace 完整移除。
  • rdif-eth DmaBuffer 结构体:将 submit() 接口从 (bus_addr, len) 升级为 DmaBuffer 结构体,保留 virtbus_addrlen 三个字段,向后兼容且设计合理。

本地验证结果(head 8f77a431

  • cargo fmt --all -- --check: ✅ 通过
  • cargo clippy -p rd-block-volume -p rdif-display -p rdif-input -p rdif-vsock --all-features -- -D warnings: ✅ 通过,零 warning
  • cargo test -p rd-block-volume: ✅ 5 个测试通过(GPT/MBR 分区扫描)
  • cargo test -p rdif-input: ✅ 1 个测试通过
  • cargo test -p rdif-vsock: ✅ 2 个测试通过
  • cargo test -p rdif-display: ✅ 1 个测试通过

代码审查要点

  1. Feature flag 体系完整ax-driver/Cargo.toml 的 feature 设计覆盖块设备、网络、显示、输入、vsock、VirtIO、USB、PCI、SoC 等所有驱动类别,依赖方向清晰。

  2. build.rs cfg 设计精巧:通过 probe cfg(static/fdt/pci)和 sync_block_dev 自定义 cfg 实现条件编译,配合 rustc-check-cfg 声明,编译器诊断友好。

  3. VirtIO 驱动适配层干净VirtIoHalImpl 正确委托给 axklibvirt_to_phys/ioremap_raw,拆分后注册逻辑清晰(register_static_transportDeviceType 路由到对应子模块)。

  4. rd-block-volume 分区扫描:GPT/MBR 扫描逻辑干净,5 个单元测试覆盖完整,无外部依赖(仅 alloc),适合作为 no_std 基础库。

  5. QEMU 配置修复正确:aarch64 std QEMU 内存 128M→512M 修复 DataAbort,根因分析清晰。StarryOS timeout 放宽(util-linux 60→120,test-mmap-prot-write 30→60)合理。

  6. apk-curl 重试机制:新增 3 次重试 + sleep 2 的 shell 脚本逻辑,应对网络波动导致的偶发失败,设计合理。

  7. rdif-eth DmaBuffer 引入:将原先 (bus_addr, len) 的接口扩展为包含 virt 指针的 DmaBuffer 结构,使驱动能直接访问 CPU 虚拟地址构建描述符,设计正确且已同步更新 e1000/ixgbe 等消费方。

重复/重叠分析

  • base 分支:dev 上不存在等效的统一驱动栈重构,旧 components/axdriver_crates 包组已被本 PR 完整替换。
  • 相关 open PR:PR #839(axbuild 重构)、PR #847(kprobe 内核探针)、PR #849(LKM 支持)均与驱动栈拆分互补,无重叠。
  • 结论:本 PR 独特,无重复。

远端 CI 状态

当前 head 8f77a431 上 CI 已运行:

  • Check formatting / run_host: ✅ success
  • Detect changed paths: ✅ success
  • Run sync-lint / run_container: ⏳ queued(容器环境中排队)
  • 其他 job(Publish 镜像、容器格式检查等):均为 skipped

fork PR 上 CI 部分 skipped 是已知行为。格式检查和路径检测已通过,表明代码质量良好。

遗留观察(非阻塞)

  • VirtIoHalImpl share 缺少 cache flush:与旧代码行为一致,KlibDma DMA 框架已就绪,后续可在非 cache-coherent 平台上统一管理 streaming DMA 的 cache 一致性。
  • StarryOS build config feature 迁移:大量 qemu-*.tomlax-feat/bus-mmio/ax-feat/bus-pci 迁移到 ax-hal/<plat> + ax-driver/<driver> 明确 feature,迁移完整且一致。

结论

代码拆分正确、本地 fmt/clippy/test 全部通过、新接口设计干净、文档完善、前九轮建议全部采纳。建议合入。

Powered by deepseek-v4-pro

@ZR233
ZR233 merged commit 9b05e5e into rcore-os:dev May 25, 2026
43 checks passed
@ZR233
ZR233 deleted the refactor/driver branch May 25, 2026 04:18
@github-actions github-actions Bot mentioned this pull request May 25, 2026
@github-actions github-actions Bot mentioned this pull request May 27, 2026
54dK3n pushed a commit to 54dK3n/tgoskits that referenced this pull request May 31, 2026
* feat(docs): 添加 rdrive + rdif 驱动框架文档,记录宿主物理设备重构目标

* Add RK3588 PCIe driver support and related components

- Implemented the RK3588 PCIe host driver in `resources.rs`, handling GPIO resets, memory mapping, and configuration.
- Created slot drivers for multiple PCIe slots in `slots.rs`, enabling dynamic probing of PCIe devices.
- Added memory window programming logic in `windows.rs`, including configuration window detection and logging of resources.
- Introduced a new `PlatformVsockDevice` in `vsock.rs` for managing Virtio socket devices, with registration and device handling.
- Updated `virtio.rs` to use the new Virtio driver interface.
- Modified the Clippy crates list to include new dependencies for the added components.
- Adjusted build configuration to remove unnecessary Virtio net feature for the AArch64 platform.

* Add DMA and MMIO support to axklib

- Updated Cargo.lock and Cargo.toml to include dma-api and mmio-api dependencies.
- Implemented DMA operations in axklib with a new dma.rs file, providing functionality for allocating and managing DMA pages.
- Created mmio.rs to handle memory-mapped I/O operations, including ioremap and iounmap functionalities.
- Refactored axruntime and various platform drivers to utilize the new DMA and MMIO abstractions, replacing previous implementations.
- Removed obsolete DmaImpl struct and related code from drivers, streamlining the DMA handling process.
- Ensured compatibility with existing driver interfaces by adapting to the new DMA and MMIO APIs.

* Refactor static device management and remove deprecated components

- Consolidated static device initialization logic into `devices.rs`.
- Introduced `StaticBlockDevice` to handle block device operations.
- Removed old static device modules (`block.rs`, `dma.rs`, `virtio.rs`, `virtio_block.rs`) and their associated functionality.
- Updated `Cargo.toml` files to remove unused driver dependencies.
- Adjusted build configurations to reflect the removal of static device drivers.
- Enhanced error handling and device probing for static devices.

* Refactor axdriver module structure and update dependencies

- Removed the `virtio/input.rs`, `virtio/vsock.rs`, and `vsock.rs` files as they are no longer needed.
- Updated `Cargo.toml` files to change dependencies from `ax-driver` to `ax-drivers` for better modularization.
- Refactored device initialization in `devices.rs` to utilize the new `ax-drivers` bindings for display, input, net, and vsock devices.
- Simplified PCI driver implementations by using the new `ax-drivers` functions for transport and IRQ registration.
- Cleaned up the `virtio` and `pci` driver implementations to align with the new structure and removed legacy code.
- Updated the `clippy_crates.csv` to include `ax-driver` and `ax-drivers` for linting checks.

* Refactor and streamline driver registration and initialization

- Removed static driver registration and initialization functions from `init.rs`, `registers.rs`, and `source.rs`.
- Updated `ramdisk.rs`, `sdmmc.rs`, `fxmac.rs`, and other driver files to use a simplified registration approach.
- Introduced `register_mmio` and `register_ecam_controller` functions for dynamic device registration.
- Enhanced the `probe_pci` functions across various drivers to focus solely on PCI device registration.
- Removed unnecessary static device descriptors and streamlined the initialization process for static devices.
- Updated Cargo.toml files to reflect changes in dependencies and features, including the addition of `sdmmc` and `cvsd`.
- Added new driver registration logic in the `riscv64-visionfive2` platform to support SD/MMC devices.

* Refactor: Remove obsolete drivers and consolidate functionality

- Deleted the `virtio.rs`, `virtio_pci.rs`, `display.rs`, `input.rs`, `serial/mod.rs`, `net/mod.rs`, `usb/mod.rs`, `vsock.rs`, and `pci.rs` files to streamline the driver architecture.
- Moved relevant functionality to `ax_drivers` for better modularity and maintainability.
- Updated `mod.rs` to reflect the removal of unused modules and adjusted the driver registration process.
- Enhanced the `generic_timer.rs` by making `try_init_epoch_offset` public for broader access.
- Cleaned up the `lib.rs` to expose necessary components while removing deprecated references.

* Refactor: Update dependencies and remove obsolete driver modules

* Refactor driver bindings and module structure

- Removed the `bindings` module and integrated its contents directly into the respective driver modules (block, display, input, net, vsock).
- Created new binding files for block, display, input, net, and vsock drivers to encapsulate their platform-specific device structures and functionalities.
- Updated references throughout the codebase to reflect the new module structure, ensuring that all driver implementations correctly utilize the new bindings.
- Improved organization and clarity of the driver code by separating concerns and enhancing modularity.

* Add PCI and Virtio support across multiple platforms

- Updated linker scripts to define driver registration sections for various architectures (x86, RISC-V, Loongarch).
- Refactored driver initialization in axplat crates to conditionally include PCI and Virtio drivers based on feature flags.
- Introduced new driver modules for RISC-V and x86 platforms to handle Virtio block devices.
- Enhanced Cargo.toml files to include necessary dependencies for PCI and Virtio drivers.
- Modified initialization routines to ensure proper setup of drivers during platform initialization.
- Updated configuration files for QEMU boards to enable PCI and Virtio features.

* Refactor driver initialization and static device registration

- Removed the `registers.rs` files from various platforms, consolidating the register handling into a new `registers.rs` in the `axruntime` module.
- Updated the `init.rs` files across platforms to eliminate direct driver initialization calls, instead relying on a unified `probe_all_devices` function.
- Introduced static device registration for various drivers (SD/MMC, PCIe ECAM, VirtIO) using the new static device registration mechanism.
- Enhanced the `StaticDeviceDesc` structure to support additional properties like `regs` and `pci_ecam`.
- Updated the build scripts to include new static features for drivers.
- Adjusted the `DriversIf` trait implementation to provide static device descriptions for platforms.

* Enhance feature sets across various build configurations

- Updated feature lists in multiple TOML files for aarch64, loongarch64, riscv64gc, and x86_64 architectures to include new hardware abstraction layer (HAL) and driver features.
- Added support for PCI, VirtIO block, VirtIO net, and other drivers to improve hardware compatibility and performance.
- Adjusted features in the axvisor and starryos test suites to ensure consistency and leverage new capabilities.
- Ensured that all configurations now utilize the latest HAL and driver features for enhanced functionality and stability.

* 为 virtio-net 驱动添加 ax-kernel-guard 依赖并重构 IRQ 处理逻辑

* 重构 PCI 设备 IRQ 处理逻辑,更新相关驱动以支持新的 IRQ 路由机制

* Refactor feature names in configuration files from "ax-drivers" to "ax-driver"

- Updated multiple TOML configuration files across various test suites to change the feature prefix from "ax-drivers" to "ax-driver" for consistency and clarity.
- This change affects configurations for platforms including x86_64, aarch64, loongarch64, and riscv64 in both normal and stress test scenarios.
- Ensured that all relevant files reflect this naming convention to maintain uniformity across the codebase.

* 更新 ax-driver 版本至 0.6.0,并相应修改 CHANGELOG

* 在构建配置中添加对 "ax-hal/riscv64-qemu-virt-hv" 的支持

* 重构特性解析逻辑,添加平台特性检查并优化特性列表生成

* 优化文件系统块设备的条件编译,支持非动态平台和特定操作系统

* 移除 qemu 特性中的动态平台支持,优化特性列表

* 优化 Tty 设备的会话管理逻辑,确保终端与会话的正确关联;增加 JobControl 的会话设置错误处理;调整 QEMU 测试超时时间至 120 秒

* fix(axbuild): preserve driver features for C tests

* 优化 pass_std_build_nested_features 函数以支持可变特性列表,并添加单元测试验证功能

* Update QEMU configurations and dependencies for various architectures

- Added virtio-net-pci and netdev configurations to QEMU arguments for aarch64, loongarch64, riscv64, and x86_64 test cases to enable networking capabilities.
- Removed unnecessary PCI and virtio driver features from build configurations for aarch64, loongarch64, riscv64, and x86_64.
- Updated hello world, HTTP client, IO test, thread test, and Tokio test configurations to include virtio-blk-pci for disk access.
- Adjusted Cargo.toml files to streamline dependencies by removing unused features related to multitasking and IRQ handling.

* fix: 增加 QEMU 配置中的内存大小至 512M

* Refactor driver-related documentation and code structure

- Replaced instances of `ax-driver-base`, `axdriver_*` with new naming conventions: `rdrive`, `rd-*`, and `rdif-*` across various documentation files.
- Updated dependency references in `ax-hal`, `ax-input`, `ax-net-ng`, `ax-posix-api`, `ax-runtime`, and `axplat-dyn` to reflect the new driver structure.
- Removed references to deprecated driver crates in `layers.md`, `overview.md`, and `components.md`.
- Adjusted the driver subsystem section in the documentation to align with the new driver architecture.
- Modified the repository management script to remove specific handling for `axdriver_crates` due to structural changes.

* fix(starryos): relax x86_64 qemu test timeouts

* 优化块设备的读写操作,合并块读取和写入方法,提升性能

* 重构块设备读写方法,移除合并操作,简化代码逻辑

* 为 DmaPages 结构体添加 DMA 统一页面分配方法,并移除 SyncBlockOps 中的 flush 方法实现

* 为 PCI 和 USB 驱动程序添加 IRQ 解析功能,重构相关方法以提高可读性和可维护性

* 移除不再使用的 simple-sdmmc 驱动相关代码,更新文档以反映当前驱动栈状态

* 重构设备初始化逻辑,使用 cfg_if 宏简化条件编译,提升可读性

* 重构平台特性管理,简化条件编译逻辑,移除冗余代码

* 添加对 rk3588-pcie 的支持到 Orange Pi 5 Plus 的构建配置

* 为 UsbKernel 实现 DmaOp 特性,添加 prepare_read 和 confirm_write 方法

* refactor(root): simplify partition selection logic and add helper functions

* refactor(driver): replace crate::register_driver! with module_driver! macro for driver registration

* refactor(driver): remove unused device feature constants and simplify configuration logic

* refactor(ci): rename required_repository_owner to limit_to_owner for clarity

* refactor: replace ax-kspin with spin in various drivers and update dependencies

* refactor: remove ax-kspin dependency and update mutex usage in USB driver

* refactor: add ax-hal dependency to arceos-stack-guard-page

* refactor: update UVC stream parameters and change Mutex to BlockingMutex for submitted URBs

* refactor: enhance std feature normalization and add test for runtime feature propagation
This was referenced Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant