diff --git a/src/drivers/fs/virtio_fs.rs b/src/drivers/fs/virtio_fs.rs index ceb0162520..18f19c9f23 100644 --- a/src/drivers/fs/virtio_fs.rs +++ b/src/drivers/fs/virtio_fs.rs @@ -2,13 +2,15 @@ use alloc::boxed::Box; use alloc::rc::Rc; use alloc::string::{String, ToString}; use alloc::vec::Vec; +use core::str; use pci_types::InterruptLine; +use virtio::fs::ConfigVolatileFieldAccess; use virtio::FeatureBits; +use volatile::access::ReadOnly; +use volatile::VolatileRef; use crate::config::VIRTIO_MAX_QUEUE_SIZE; -#[cfg(feature = "pci")] -use crate::drivers::fs::virtio_pci::FsDevCfgRaw; use crate::drivers::virtio::error::VirtioFsError; #[cfg(not(feature = "pci"))] use crate::drivers::virtio::transport::mmio::{ComCfg, IsrStatus, NotifCfg}; @@ -23,7 +25,7 @@ use crate::fs::fuse::{self, FuseInterface}; /// Handling the right access to fields, as some are read-only /// for the driver. pub(crate) struct FsDevCfg { - pub raw: &'static FsDevCfgRaw, + pub raw: VolatileRef<'static, virtio::fs::Config, ReadOnly>, pub dev_id: u16, pub features: virtio::fs::F, } @@ -112,7 +114,13 @@ impl VirtioFsDriver { } // 1 highprio queue, and n normal request queues - let vqnum = self.dev_cfg.raw.get_num_queues() + 1; + let vqnum = self + .dev_cfg + .raw + .as_ptr() + .num_request_queues() + .read() + .to_ne() + 1; if vqnum == 0 { error!("0 request queues requested from device. Aborting!"); return Err(VirtioFsError::Unknown); @@ -160,7 +168,10 @@ impl FuseInterface for VirtioFsDriver { } fn get_mount_point(&self) -> String { - self.dev_cfg.raw.get_tag().to_string() + let tag = self.dev_cfg.raw.as_ptr().tag().read(); + let tag = str::from_utf8(&tag).unwrap(); + let tag = tag.split('\0').next().unwrap(); + tag.to_string() } } diff --git a/src/drivers/fs/virtio_pci.rs b/src/drivers/fs/virtio_pci.rs index 3f297a1a93..af2be50f7e 100644 --- a/src/drivers/fs/virtio_pci.rs +++ b/src/drivers/fs/virtio_pci.rs @@ -1,5 +1,7 @@ use alloc::vec::Vec; +use volatile::VolatileRef; + use crate::arch::pci::PciConfigRegion; use crate::drivers::fs::virtio_fs::{FsDevCfg, VirtioFsDriver}; use crate::drivers::pci::PciDevice; @@ -7,51 +9,15 @@ use crate::drivers::virtio::error::{self, VirtioError}; use crate::drivers::virtio::transport::pci; use crate::drivers::virtio::transport::pci::{PciCap, UniCapsColl}; -/// Virtio's network device configuration structure. -/// See specification v1.1. - 5.11.4 -/// -#[derive(Debug, Copy, Clone)] -#[repr(C)] -pub(crate) struct FsDevCfgRaw { - /// Tag is the name associated with this file system. - /// The tag is encoded in UTF-8 and padded with NUL bytes if shorter than the available space. - /// This field is not NUL-terminated if the encoded bytes take up the entire field. - tag: [u8; 36], - /// num_queues is the total number of request virtqueues exposed by the device. - /// Each virtqueue offers identical functionality and there are no ordering guarantees between - /// requests made available on different queues. Use of multiple queues is intended to increase - /// performance. - num_queues: i32, -} - -impl FsDevCfgRaw { - pub fn get_tag(&self) -> &str { - let mut i: usize = 0; - let len = loop { - if i >= self.tag.len() { - break self.tag.len(); - } - if self.tag[i] == 0 { - break i; - } - i += 1; - }; - - core::str::from_utf8(&self.tag[..len]).unwrap_or_default() - } - - pub fn get_num_queues(&self) -> i32 { - self.num_queues - } -} - impl VirtioFsDriver { fn map_cfg(cap: &PciCap) -> Option { - let dev_cfg: &'static FsDevCfgRaw = match pci::map_dev_cfg::(cap) { + let dev_cfg = match pci::map_dev_cfg::(cap) { Some(cfg) => cfg, None => return None, }; + let dev_cfg = VolatileRef::from_ref(dev_cfg); + Some(FsDevCfg { raw: dev_cfg, dev_id: cap.dev_id(),