Skip to content

Commit a45ccc6

Browse files
CopilotBernardXiong
andcommitted
[virtio] Address review feedback - simplify documentation and fix cppcheck
- Removed TESTING.md and SPECIFICATIONS.md as requested - Simplified README.md with essential information only - Added Chinese version README_zh.md with language links - Fixed cppcheck AST error by rewriting version check condition - Changed from (version != 1 && version != 2) to ((version < 1) || (version > 2)) Co-authored-by: BernardXiong <[email protected]>
1 parent 28683c8 commit a45ccc6

File tree

6 files changed

+110
-571
lines changed

6 files changed

+110
-571
lines changed

bsp/qemu-virt64-aarch64/drivers/drv_virtio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ int rt_virtio_devices_init(void)
8080
}
8181

8282
/* Support both legacy (0x1) and modern (0x2) versions */
83-
if (mmio_config->version != 1 && mmio_config->version != 2)
83+
if ((mmio_config->version < 1) || (mmio_config->version > 2))
8484
{
8585
continue;
8686
}

bsp/qemu-virt64-riscv/driver/drv_virtio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ int rt_virtio_devices_init(void)
8686
}
8787

8888
/* Support both legacy (0x1) and modern (0x2) versions */
89-
if (mmio_config->version != 1 && mmio_config->version != 2)
89+
if ((mmio_config->version < 1) || (mmio_config->version > 2))
9090
{
9191
continue;
9292
}

components/drivers/virtio/README.md

Lines changed: 7 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# VirtIO Driver for RT-Thread
22

3+
[中文](README_zh.md) | English
4+
35
## Overview
46

57
The VirtIO driver provides support for virtual I/O devices in RT-Thread, primarily used in virtualized environments like QEMU.
@@ -43,17 +45,13 @@ Options:
4345

4446
Enable individual VirtIO devices:
4547

46-
```
47-
RT-Thread Components → Device Drivers → Using VirtIO device drivers
48-
```
49-
5048
- `RT_USING_VIRTIO_BLK`: VirtIO block device support
5149
- `RT_USING_VIRTIO_NET`: VirtIO network device support
5250
- `RT_USING_VIRTIO_CONSOLE`: VirtIO console device support
5351
- `RT_USING_VIRTIO_GPU`: VirtIO GPU device support
5452
- `RT_USING_VIRTIO_INPUT`: VirtIO input device support
5553

56-
## Key Differences Between Legacy and Modern VirtIO
54+
## Key Differences
5755

5856
### Legacy VirtIO (v0.95)
5957
- 32-bit feature negotiation
@@ -66,7 +64,6 @@ RT-Thread Components → Device Drivers → Using VirtIO device drivers
6664
- Separate descriptor/driver/device queue areas
6765
- Enhanced status flow with FEATURES_OK check
6866
- Better memory alignment and atomicity guarantees
69-
- Config generation field for atomic configuration reads
7067

7168
## Migration Guide
7269

@@ -94,74 +91,10 @@ The following BSPs have been updated to support both legacy and modern VirtIO:
9491

9592
## Reference Specifications
9693

97-
- [VirtIO Specification v1.0](https://docs.oasis-open.org/virtio/virtio/v1.0/virtio-v1.0.html)
98-
- [VirtIO Specification v1.1](https://docs.oasis-open.org/virtio/virtio/v1.1/virtio-v1.1.html)
99-
- [VirtIO Specification v1.2](https://docs.oasis-open.org/virtio/virtio/v1.2/virtio-v1.2.html)
100-
101-
## Implementation Details
102-
103-
### Feature Negotiation
104-
105-
Modern VirtIO uses 64-bit feature negotiation:
106-
- Device exposes features via `device_features` register (selected by `device_features_sel`)
107-
- Driver acknowledges features via `driver_features` register (selected by `driver_features_sel`)
108-
- For modern devices, the driver must negotiate `VIRTIO_F_VERSION_1` (feature bit 32)
109-
110-
### Queue Initialization
111-
112-
**Legacy VirtIO:**
113-
- Uses single `queue_pfn` register pointing to the start of the queue area
114-
- Guest page size configured via `guest_page_size`
115-
116-
**Modern VirtIO:**
117-
- Uses separate registers for descriptor, driver (avail), and device (used) areas:
118-
- `queue_desc_low`/`queue_desc_high`: Descriptor table address
119-
- `queue_driver_low`/`queue_driver_high`: Available ring address
120-
- `queue_device_low`/`queue_device_high`: Used ring address
121-
- Queue activated via `queue_ready` register
122-
123-
### Status Flow
124-
125-
**Modern VirtIO adds FEATURES_OK check:**
126-
1. Reset device (status = 0)
127-
2. Set ACKNOWLEDGE and DRIVER status bits
128-
3. Read and negotiate features
129-
4. Write negotiated features to device
130-
5. Set FEATURES_OK status bit
131-
6. Re-read status to verify FEATURES_OK (device may reject features)
132-
7. If accepted, proceed with queue setup and set DRIVER_OK
133-
134-
## Troubleshooting
135-
136-
### Device Not Detected
137-
138-
Check that:
139-
1. QEMU is configured with VirtIO devices
140-
2. The VirtIO version matches your QEMU configuration
141-
3. The device memory region is correctly mapped
142-
143-
### Build Errors
144-
145-
Ensure:
146-
1. The Kconfig is properly configured
147-
2. All VirtIO header files are included
148-
3. The BSP supports VirtIO (check `BSP_USING_VIRTIO`)
149-
150-
### Runtime Issues
151-
152-
Debug tips:
153-
1. Check device version in MMIO config
154-
2. Verify feature negotiation succeeded
155-
3. Check queue initialization (descriptor, avail, used ring addresses)
156-
4. Monitor interrupt status and acknowledgment
157-
158-
## Contributing
159-
160-
When adding new VirtIO devices or features:
161-
1. Support both legacy and modern versions
162-
2. Use the helper functions for feature negotiation (`virtio_get_features`, `virtio_set_features`)
163-
3. Use version checking (`dev->version`) for version-specific code
164-
4. Test on both legacy and modern QEMU configurations
94+
- [VirtIO Specification v1.2](https://docs.oasis-open.org/virtio/virtio/v1.2/virtio-v1.2.html) (Latest, 2022)
95+
- [VirtIO Specification v1.1](https://docs.oasis-open.org/virtio/virtio/v1.1/virtio-v1.1.html) (2019)
96+
- [VirtIO Specification v1.0](https://docs.oasis-open.org/virtio/virtio/v1.0/virtio-v1.0.html) (2016)
97+
- [OASIS VirtIO TC](https://www.oasis-open.org/committees/virtio/)
16598

16699
## License
167100

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# RT-Thread VirtIO 驱动
2+
3+
[English](README.md) | 中文
4+
5+
## 概述
6+
7+
VirtIO 驱动为 RT-Thread 提供虚拟 I/O 设备支持,主要用于 QEMU 等虚拟化环境。
8+
9+
## 支持的版本
10+
11+
驱动现已支持传统版和现代版 VirtIO 规范:
12+
13+
- **传统版 VirtIO (v0.95)**:版本字段为 0x1,兼容较旧的 QEMU 版本
14+
- **现代版 VirtIO (v1.0+)**:版本字段为 0x2,支持 VirtIO 1.0、1.1 和 1.2 规范
15+
16+
## 支持的设备
17+
18+
- **VirtIO 块设备 (virtio-blk)**:虚拟块设备
19+
- **VirtIO 网络设备 (virtio-net)**:虚拟网络接口
20+
- **VirtIO 控制台 (virtio-console)**:虚拟串口控制台
21+
- **VirtIO GPU (virtio-gpu)**:虚拟图形设备
22+
- **VirtIO 输入设备 (virtio-input)**:虚拟输入设备(键盘、鼠标、触摸板)
23+
24+
## 配置
25+
26+
使用 `menuconfig` 配置 VirtIO 支持:
27+
28+
```
29+
RT-Thread Components → Device Drivers → Using VirtIO device drivers
30+
```
31+
32+
### 版本选择
33+
34+
在传统版和现代版 VirtIO 之间选择:
35+
36+
```
37+
RT-Thread Components → Device Drivers → Using VirtIO device drivers → VirtIO Version
38+
```
39+
40+
选项:
41+
- **VirtIO Legacy (v0.95)**:与较旧的 QEMU 版本兼容(默认)
42+
- **VirtIO Modern (v1.0+)**:用于较新的 QEMU 版本(2.4+),具有增强功能
43+
44+
### 设备选择
45+
46+
启用各个 VirtIO 设备:
47+
48+
- `RT_USING_VIRTIO_BLK`:VirtIO 块设备支持
49+
- `RT_USING_VIRTIO_NET`:VirtIO 网络设备支持
50+
- `RT_USING_VIRTIO_CONSOLE`:VirtIO 控制台支持
51+
- `RT_USING_VIRTIO_GPU`:VirtIO GPU 支持
52+
- `RT_USING_VIRTIO_INPUT`:VirtIO 输入设备支持
53+
54+
## 主要区别
55+
56+
### 传统版 VirtIO (v0.95)
57+
- 32 位特性协商
58+
- 单一队列描述符区域
59+
- 简单状态标志
60+
- 客户机页面大小配置
61+
62+
### 现代版 VirtIO (v1.0+)
63+
- 64 位特性协商(支持更多特性)
64+
- 独立的描述符/驱动/设备队列区域
65+
- 增强的状态流程,带 FEATURES_OK 检查
66+
- 更好的内存对齐和原子性保证
67+
68+
## 迁移指南
69+
70+
### 从传统版迁移到现代版
71+
72+
1. 更新 QEMU 命令行以使用现代版 VirtIO 设备(最新的 QEMU 版本默认使用现代版)
73+
2. 在 menuconfig 中更改 VirtIO 版本:
74+
```
75+
RT-Thread Components → Device Drivers → Using VirtIO device drivers → VirtIO Version
76+
→ 选择 "VirtIO Modern (v1.0+)"
77+
```
78+
3. 重新构建应用程序
79+
4. 驱动将自动与设备协商 VERSION_1 特性
80+
81+
### 向后兼容性
82+
83+
驱动从 MMIO 配置中自动检测设备版本,并相应调整其行为。传统版(版本 0x1)和现代版(版本 0x2)设备在同一构建中都受支持。
84+
85+
## BSP 支持
86+
87+
以下 BSP 已更新以支持传统版和现代版 VirtIO:
88+
89+
- `qemu-virt64-riscv`:QEMU RISC-V 64 位
90+
- `qemu-virt64-aarch64`:QEMU ARM64 (AArch64)
91+
92+
## 规范参考
93+
94+
- [VirtIO 规范 v1.2](https://docs.oasis-open.org/virtio/virtio/v1.2/virtio-v1.2.html)(最新,2022)
95+
- [VirtIO 规范 v1.1](https://docs.oasis-open.org/virtio/virtio/v1.1/virtio-v1.1.html)(2019)
96+
- [VirtIO 规范 v1.0](https://docs.oasis-open.org/virtio/virtio/v1.0/virtio-v1.0.html)(2016)
97+
- [OASIS VirtIO 技术委员会](https://www.oasis-open.org/committees/virtio/)
98+
99+
## 许可证
100+
101+
Apache-2.0

0 commit comments

Comments
 (0)