Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions alioth/src/virtio/dev/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ where
}

#[derive(Debug)]
pub struct VirtioDevice<D, S, E>
pub struct VirtioDevice<S, E>
where
D: Virtio,
S: IrqSender,
E: IoeventFd,
{
pub name: Arc<str>,
pub device_config: Arc<D::Config>,
pub id: DeviceId,
pub device_config: Arc<dyn Mmio>,
pub reg: Arc<Register>,
pub queue_regs: Arc<[Queue]>,
pub ioeventfds: Arc<[(E, bool)]>,
Expand All @@ -132,9 +132,8 @@ where
worker_handle: Option<JoinHandle<()>>,
}

impl<D, S, E> VirtioDevice<D, S, E>
impl<S, E> VirtioDevice<S, E>
where
D: Virtio,
S: IrqSender,
E: IoeventFd,
{
Expand All @@ -150,17 +149,19 @@ where
Ok(())
}

pub fn new<R>(
pub fn new<D, R>(
name: impl Into<Arc<str>>,
dev: D,
memory: Arc<RamBus>,
registry: &R,
restricted_memory: bool,
) -> Result<Self>
where
D: Virtio,
R: IoeventFdRegistry<IoeventFd = E>,
{
let name = name.into();
let id = D::DEVICE_ID;
let device_config = dev.config();
let mut dev_feat = dev.feature();
if restricted_memory {
Expand Down Expand Up @@ -199,6 +200,7 @@ where
);
let virtio_dev = VirtioDevice {
name,
id,
reg,
queue_regs,
ioeventfds,
Expand All @@ -212,9 +214,8 @@ where
}
}

impl<D, S, E> Drop for VirtioDevice<D, S, E>
impl<S, E> Drop for VirtioDevice<S, E>
where
D: Virtio,
S: IrqSender,
E: IoeventFd,
{
Expand Down
21 changes: 9 additions & 12 deletions alioth/src/virtio/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -633,43 +633,41 @@ impl PciCap for VirtioPciNotifyCap {
}

#[derive(Debug)]
pub struct VirtioPciDevice<D, M, E>
pub struct VirtioPciDevice<M, E>
where
D: Virtio,
M: MsiSender,
E: IoeventFd,
{
pub dev: VirtioDevice<D, PciIrqSender<M>, E>,
pub dev: VirtioDevice<PciIrqSender<M>, E>,
pub config: EmulatedConfig,
pub registers: Arc<VirtioPciRegisterMmio<M>>,
}

impl<D, M, E> VirtioPciDevice<D, M, E>
impl<M, E> VirtioPciDevice<M, E>
where
M: MsiSender,
D: Virtio,
E: IoeventFd,
{
pub fn new<R>(
dev: VirtioDevice<D, PciIrqSender<M>, E>,
dev: VirtioDevice<PciIrqSender<M>, E>,
msi_sender: M,
ioeventfd_reg: R,
) -> Result<Self>
where
R: IoeventFdRegistry<IoeventFd = E>,
{
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();
Expand Down Expand Up @@ -869,10 +867,9 @@ where
}
}

impl<D, M, E> Pci for VirtioPciDevice<D, M, E>
impl<M, E> Pci for VirtioPciDevice<M, E>
where
M: MsiSender,
D: Virtio,
E: IoeventFd,
{
fn config(&self) -> &dyn PciConfig {
Expand Down
5 changes: 2 additions & 3 deletions alioth/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ where
_event_tx: Sender<u32>,
}

pub type VirtioPciDev<D, H> = VirtioPciDevice<
D,
pub type VirtioPciDev<H> = VirtioPciDevice<
<<H as Hypervisor>::Vm as Vm>::MsiSender,
<<<H as Hypervisor>::Vm as Vm>::IoeventFdRegistry as IoeventFdRegistry>::IoeventFd,
>;
Expand Down Expand Up @@ -228,7 +227,7 @@ where
&self,
name: impl Into<Arc<str>>,
param: P,
) -> Result<Arc<VirtioPciDev<D, H>>, Error>
) -> Result<Arc<VirtioPciDev<H>>, Error>
where
P: DevParam<Device = D>,
D: Virtio,
Expand Down