refactor: extract shared hw-virtio crate, eliminate VirtIO protocol duplication
Two VirtIO block and two VirtIO GPU implementations (adapter + driver)
shared 90% of their protocol logic. Extracted the common code into
hw-virtio, parameterized by MmioAccess trait.
New crate: hw-virtio (no_std, zero deps)
- mmio.rs: MmioAccess trait, DirectMmio, init_legacy_device(), scan
- queue.rs: VirtioQueue with descriptor chain submit + poll
- block.rs: block read protocol (3-descriptor chain)
- gpu.rs: GPU commands (create_2d, attach_backing, set_scanout,
transfer_to_host, resource_flush)
Adapter thin wrappers (identity-mapped, statics for DMA):
- virtio_blk.rs: 220 → 53 lines
- virtio_gpu.rs: 165 → 37 lines
Driver thin wrappers (mapped VAs, phys-info for DMA):
- drivers/block/virtio: 139 → 70 lines
- drivers/framebuffer/virtio: 146 → 95 lines
Also deleted input-server/input_device.rs (1-line re-export,
superseded by port-input-device).
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use crate::hw::uart::Uart;
|
||||
use crate::hw::virtio_blk::{mmio_read, mmio_write};
|
||||
use crate::{kernel_ref, mmu};
|
||||
use types::id::ProcessId;
|
||||
|
||||
@@ -86,22 +85,8 @@ fn write_phys_info(pt: &mut mmu::PageTable, reqhdr_phys: usize) {
|
||||
}
|
||||
|
||||
fn reinit_device(base: usize, vqueue_phys: usize) {
|
||||
mmio_write(base, 0x070, 0);
|
||||
while mmio_read(base, 0x070) != 0 {}
|
||||
|
||||
mmio_write(base, 0x070, 1);
|
||||
mmio_write(base, 0x070, mmio_read(base, 0x070) | 2);
|
||||
mmio_write(base, 0x028, 4096);
|
||||
mmio_write(base, 0x014, 0);
|
||||
mmio_write(base, 0x024, 0);
|
||||
mmio_write(base, 0x020, 0);
|
||||
|
||||
mmio_write(base, 0x030, 0);
|
||||
let queue_max = mmio_read(base, 0x034);
|
||||
mmio_write(base, 0x038, 8u32.min(queue_max));
|
||||
mmio_write(base, 0x040, (vqueue_phys / 4096) as u32);
|
||||
|
||||
mmio_write(base, 0x070, mmio_read(base, 0x070) | 4);
|
||||
let mmio = hw_virtio::mmio::DirectMmio::new(base);
|
||||
hw_virtio::mmio::init_legacy_device(&mmio, vqueue_phys, hw_virtio::queue::QUEUE_SIZE as u32);
|
||||
}
|
||||
|
||||
fn map_shared_buffer(init_pt: &mut mmu::PageTable, storage_pt: &mut mmu::PageTable) {
|
||||
|
||||
Reference in New Issue
Block a user