--- a/src/drivers/virtio/mod.rs +++ b/src/drivers/virtio/mod.rs @@ -4,7 +4,7 @@ use std::sync::Mutex; use log::{info, warn}; use redox_driver_sys::memory::MmioRegion; -use redox_driver_sys::pci::{PciBarInfo, PciDevice, PciDeviceInfo}; +use redox_driver_sys::pci::{PciBarInfo, PciDeviceInfo}; use crate::driver::{DriverError, DriverEvent, GpuDriver, Result}; use crate::drivers::interrupt::InterruptHandle; @@ -32,11 +32,15 @@ fn find_fb_bar(info: &PciDeviceInfo) -> Result { .ok_or_else(|| DriverError::Pci("VirtIO GPU has no valid framebuffer BAR".into())) } -fn map_bar(device: &mut PciDevice, bar: &PciBarInfo, name: &str) -> Result { - device - .map_bar(bar.index, bar.addr, bar.size as usize) - .map_err(|e| DriverError::Mmio(format!("failed to map {name}: {e}"))) +fn map_bar(bar: &PciBarInfo, name: &str) -> Result { + MmioRegion::map( + bar.addr, + bar.size as usize, + redox_driver_sys::memory::CacheType::DeviceMemory, + redox_driver_sys::memory::MmioProt::READ_WRITE, + ) + .map_err(|e| DriverError::Mmio(format!("failed to map {name}: {e}"))) } impl VirtioDriver { @@ -47,10 +51,7 @@ impl VirtioDriver { } let fb_bar = find_fb_bar(&info)?; - let mut device = PciDevice::open_location(&info.location) - .map_err(|e| DriverError::Pci(format!("open PCI: {e}")))?; - let _mmio = map_bar(&mut device, &fb_bar, "VirtIO FB BAR")?; - drop(device); + let _mmio = map_bar(&fb_bar, "VirtIO FB BAR")?; info!( "redox-drm: VirtIO GPU at {}: {} MiB BAR at {:#x}",