From 31b00b0ce9b7093b974a536f9dd02b5d1db8aa41 Mon Sep 17 00:00:00 2001 From: Changyuan Lyu Date: Sat, 19 Apr 2025 12:21:20 -0700 Subject: [PATCH] refactor(virtio): remove generic paramter D from VirtioDevice Signed-off-by: Changyuan Lyu --- alioth/src/virtio/dev/dev.rs | 17 +++++++++-------- alioth/src/virtio/pci.rs | 21 +++++++++------------ alioth/src/vm.rs | 5 ++--- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/alioth/src/virtio/dev/dev.rs b/alioth/src/virtio/dev/dev.rs index 411885f2..c0d024b7 100644 --- a/alioth/src/virtio/dev/dev.rs +++ b/alioth/src/virtio/dev/dev.rs @@ -115,14 +115,14 @@ where } #[derive(Debug)] -pub struct VirtioDevice +pub struct VirtioDevice where - D: Virtio, S: IrqSender, E: IoeventFd, { pub name: Arc, - pub device_config: Arc, + pub id: DeviceId, + pub device_config: Arc, pub reg: Arc, pub queue_regs: Arc<[Queue]>, pub ioeventfds: Arc<[(E, bool)]>, @@ -132,9 +132,8 @@ where worker_handle: Option>, } -impl VirtioDevice +impl VirtioDevice where - D: Virtio, S: IrqSender, E: IoeventFd, { @@ -150,7 +149,7 @@ where Ok(()) } - pub fn new( + pub fn new( name: impl Into>, dev: D, memory: Arc, @@ -158,9 +157,11 @@ where restricted_memory: bool, ) -> Result where + D: Virtio, R: IoeventFdRegistry, { let name = name.into(); + let id = D::DEVICE_ID; let device_config = dev.config(); let mut dev_feat = dev.feature(); if restricted_memory { @@ -199,6 +200,7 @@ where ); let virtio_dev = VirtioDevice { name, + id, reg, queue_regs, ioeventfds, @@ -212,9 +214,8 @@ where } } -impl Drop for VirtioDevice +impl Drop for VirtioDevice where - D: Virtio, S: IrqSender, E: IoeventFd, { diff --git a/alioth/src/virtio/pci.rs b/alioth/src/virtio/pci.rs index e7df475f..8d3a6483 100644 --- a/alioth/src/virtio/pci.rs +++ b/alioth/src/virtio/pci.rs @@ -38,7 +38,7 @@ use crate::pci::{self, Pci, PciBar}; use crate::utils::{ get_atomic_high32, get_atomic_low32, get_high32, get_low32, set_atomic_high32, set_atomic_low32, }; -use crate::virtio::dev::{Register, Virtio, VirtioDevice, WakeEvent}; +use crate::virtio::dev::{Register, VirtioDevice, WakeEvent}; use crate::virtio::queue::Queue; use crate::virtio::worker::Waker; use crate::virtio::{DevStatus, DeviceId, IrqSender, Result, error}; @@ -633,43 +633,41 @@ impl PciCap for VirtioPciNotifyCap { } #[derive(Debug)] -pub struct VirtioPciDevice +pub struct VirtioPciDevice where - D: Virtio, M: MsiSender, E: IoeventFd, { - pub dev: VirtioDevice, E>, + pub dev: VirtioDevice, E>, pub config: EmulatedConfig, pub registers: Arc>, } -impl VirtioPciDevice +impl VirtioPciDevice where M: MsiSender, - D: Virtio, E: IoeventFd, { pub fn new( - dev: VirtioDevice, E>, + dev: VirtioDevice, E>, msi_sender: M, ioeventfd_reg: R, ) -> Result where R: IoeventFdRegistry, { - let (class, subclass) = get_class(D::DEVICE_ID); + let (class, subclass) = get_class(dev.id); let mut header = DeviceHeader { common: CommonHeader { vendor: VIRTIO_VENDOR_ID, - device: VIRTIO_DEVICE_ID_BASE + D::DEVICE_ID as u16, + device: VIRTIO_DEVICE_ID_BASE + dev.id as u16, revision: 0x1, header_type: HeaderType::Device as u8, class, subclass, ..Default::default() }, - subsystem: VIRTIO_DEVICE_ID_BASE + D::DEVICE_ID as u16, + subsystem: VIRTIO_DEVICE_ID_BASE + dev.id as u16, ..Default::default() }; let device_config = dev.device_config.clone(); @@ -869,10 +867,9 @@ where } } -impl Pci for VirtioPciDevice +impl Pci for VirtioPciDevice where M: MsiSender, - D: Virtio, E: IoeventFd, { fn config(&self) -> &dyn PciConfig { diff --git a/alioth/src/vm.rs b/alioth/src/vm.rs index ca0c6589..01663393 100644 --- a/alioth/src/vm.rs +++ b/alioth/src/vm.rs @@ -112,8 +112,7 @@ where _event_tx: Sender, } -pub type VirtioPciDev = VirtioPciDevice< - D, +pub type VirtioPciDev = VirtioPciDevice< <::Vm as Vm>::MsiSender, <<::Vm as Vm>::IoeventFdRegistry as IoeventFdRegistry>::IoeventFd, >; @@ -228,7 +227,7 @@ where &self, name: impl Into>, param: P, - ) -> Result>, Error> + ) -> Result>, Error> where P: DevParam, D: Virtio,