fix(starry): map sg2002 tty serial MMIO via iomap#1270
Merged
Conversation
通过 ax_mm::iomap 动态映射 UART 寄存器和 pinmux 寄存器组,替换原来
"裸物理地址 + PHYS_VIRT_OFFSET" 的访问方式。动态平台(plat-dyn)下
PHYS_VIRT_OFFSET 为 0 且无静态线性 MMIO 窗口,旧写法会访问未映射地址
导致初始化挂死。
- 新增 iomap_usize / map_pinmux,对 UART 与 FMUX/IOBLK/GRTC 各区映射
- TtySerial 改存映射后的 vaddr,write/set_baud 直接复用
- IRQ handler 经 UART{1,2}_VADDR 原子量获取已映射地址,并在使能中断前
发布,避免 handler 读到未映射地址
Contributor
There was a problem hiding this comment.
Review: fix(starry): map sg2002 tty serial MMIO via iomap
变更内容
本 PR 将 tty_serial.rs 中的 UART 和 pinmux 寄存器访问方式从 phys_to_virt(paddr) 替换为 ax_mm::iomap(paddr, size)。核心原因是动态平台(plat-dyn)下 PHYS_VIRT_OFFSET == 0 且无静态线性 MMIO 窗口,旧写法会访问未映射地址导致初始化挂死。
具体变更:
- 新增
iomap_usize()封装ax_mm::iomap,对 UART 与 pinmux 各区域进行动态映射 TtySerial从存储PhysAddr改为存储映射后的vaddr: usizewrite_at()/set_baud()直接复用已映射的vaddr,避免重复调用phys_to_virt- IRQ handler 通过
UART{1,2}_VADDR原子量获取已映射地址,在 IRQ 使能前发布 map_pinmux()提取 pinmux 初始化为独立函数,消除new_tty_s1/new_tty_s2的重复代码
实现逻辑分析
实现方向正确:
- iomap 一致性:与同目录
kpu.rs中axklib::mem::iomap用法一致,是项目中 MMIO 映射的标准模式 - IRQ handler 安全性:
vaddr_slot.store(vaddr, Relaxed)发生在request_shared_irq和set_enable之前,中断机制本身保证了 handler 运行前 store 已对同 CPU 可见。裸指针 MMIO 操作作为隐式编译器屏障进一步保证了正确性。Relaxed对于 ARM/RISC-V 的同 CPU 中断前发布场景是充分的 - iomap 幂等性:注释正确说明
iomap对已映射页是幂等的,map_pinmux()可安全重复调用 - 代码简化:
map_pinmux()消除了两处重复的unsafe { Pinmux::new(FMUX_BASE + PHYS_VIRT_OFFSET, ...) }模式
CI 状态
CI 已通过(head SHA: 2a0b9a3):
- ✅ Detect changed paths — success
- ✅ Run clippy / run_host — success
- ✅ Test axvisor self-hosted x86_64 UEFI / run_host — success
- ✅ Test axvisor self-hosted board roc-rk3568-pc-linux / run_host — success
- ✅ Test axvisor loongarch64 qemu / run_container — success
- ✅ Test arceos aarch64 qemu / run_host — success
- ✅ Test with std / run_host — success
- ✅ Test starry self-hosted board orangepi-5-plus / run_host — success
- ⏭ Test starry self-hosted board licheerv-nano-sg2002 / run_container — skipped(路径过滤未触发,预期行为)
- ⏭ Test with std / run_container — skipped(与 run_host 互斥,预期行为)
- ⏭ Run sync-lint / run_host — skipped
- ⏭ Publish base container image — skipped
无 CI 失败。SG2002 board 测试跳过是路径过滤的预期行为,不影响本 PR 评估。
重复/重叠分析
- dev 分支近期 tty_serial.rs 变更历史:#1065(shared IRQ)、#965(DW APB UART 集成)、#963(HAL 路由)——均不冲突
- 当前 open PR 中未发现与本 PR 修改相同文件或相同 sg2002 UART/pinmux 面的变更
- 本 PR 是独立且互补的平台修复,不重复已有实现
未添加测试
本 PR 修改的是 SG2002 板级特定的 UART/pinmux 驱动代码,只能在实物板(licheerv-nano-sg2002)上验证,无法在 QEMU CI 中覆盖。SG2002 board CI 路径过滤跳过是项目已有的配置行为。实物板验证由 PR 作者和合入者(ZR233)在合入前完成。
crates.io patch
本 PR 未引入任何 [patch.crates-io] 覆盖。未修改 Cargo.toml 或 Cargo.lock。
结论
PR 实现正确,解决了一个真实的平台兼容性问题(plat-dyn 下 PHYS_VIRT_OFFSET 为 0 导致 UART 初始化挂死)。代码质量好,注释充分,CI 通过,无阻塞问题。
Powered by mimo-v2.5-pro
fzg-23
pushed a commit
to fzg-23/tgoskits
that referenced
this pull request
Jun 16, 2026
通过 ax_mm::iomap 动态映射 UART 寄存器和 pinmux 寄存器组,替换原来
"裸物理地址 + PHYS_VIRT_OFFSET" 的访问方式。动态平台(plat-dyn)下
PHYS_VIRT_OFFSET 为 0 且无静态线性 MMIO 窗口,旧写法会访问未映射地址
导致初始化挂死。
- 新增 iomap_usize / map_pinmux,对 UART 与 FMUX/IOBLK/GRTC 各区映射
- TtySerial 改存映射后的 vaddr,write/set_baud 直接复用
- IRQ handler 经 UART{1,2}_VADDR 原子量获取已映射地址,并在使能中断前
发布,避免 handler 读到未映射地址
luodeb
pushed a commit
that referenced
this pull request
Jun 30, 2026
通过 ax_mm::iomap 动态映射 UART 寄存器和 pinmux 寄存器组,替换原来
"裸物理地址 + PHYS_VIRT_OFFSET" 的访问方式。动态平台(plat-dyn)下
PHYS_VIRT_OFFSET 为 0 且无静态线性 MMIO 窗口,旧写法会访问未映射地址
导致初始化挂死。
- 新增 iomap_usize / map_pinmux,对 UART 与 FMUX/IOBLK/GRTC 各区映射
- TtySerial 改存映射后的 vaddr,write/set_baud 直接复用
- IRQ handler 经 UART{1,2}_VADDR 原子量获取已映射地址,并在使能中断前
发布,避免 handler 读到未映射地址
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
通过 ax_mm::iomap 动态映射 UART 寄存器和 pinmux 寄存器组,替换原来
"裸物理地址 + PHYS_VIRT_OFFSET" 的访问方式。动态平台(plat-dyn)下
PHYS_VIRT_OFFSET 为 0 且无静态线性 MMIO 窗口,旧写法会访问未映射地址
导致初始化挂死。