vpci/
bus_control.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! VPCI bus control for Underhill.
5//!
6//! TODO: move to a different crate.
7
8// TODO: should this be in this crate? nothing in this crate actually ends up
9// using this code...
10
11use anyhow::Result;
12use async_trait::async_trait;
13use mesh::Receiver;
14use mesh::payload::Protobuf;
15
16/// Events signaled on a Virtual PCI bus.
17#[derive(Debug, Protobuf)]
18pub enum VpciBusEvent {
19    /// Device has been enumerated by the bus.
20    DeviceEnumerated,
21    /// Device is about to be detached from the bus.
22    PrepareForRemoval,
23}
24
25/// A trait used to control a Virtual PCI bus.
26#[async_trait]
27pub trait VpciBusControl {
28    /// Offers the bus and its attached device to the target partition.
29    /// The bus and device must have been pre-configured (through some other mechanism,
30    /// not provided by this trait) before they are offered.
31    async fn offer_device(&self) -> Result<()>;
32
33    /// Revokes the bus and its attached device from the target partition.
34    async fn revoke_device(&self) -> Result<()>;
35
36    /// Returns a reference to an object used to receive bus events.
37    fn notifier(&mut self) -> &mut Receiver<VpciBusEvent>;
38}