11# VirtIO Driver for RT-Thread
22
3+ [ 中文] ( README_zh.md ) | English
4+
35## Overview
46
57The 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
4446Enable 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
0 commit comments