virt/
io.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use hvdef::Vtl;
5use std::future::Future;
6use vm_topology::processor::VpIndex;
7
8/// This trait provides the operations between the VP dispatch loop and the
9/// platform's devices.
10pub trait CpuIo {
11    /// Check if a given address will be handled by a device.
12    fn is_mmio(&self, address: u64) -> bool;
13
14    /// Gets the vector of the next interrupt to inject from the legacy
15    /// interrupt controller (PIC) and sets the IRQ in service.
16    fn acknowledge_pic_interrupt(&self) -> Option<u8>;
17
18    /// Handle End Of Interrupt (EOI)
19    ///
20    /// A `u32` is used for the IRQ value for (future) ARM compat.
21    fn handle_eoi(&self, irq: u32);
22
23    /// Signal a synic event.
24    fn signal_synic_event(&self, vtl: Vtl, connection_id: u32, flag: u16) -> hvdef::HvResult<()>;
25
26    /// Post a synic message.
27    fn post_synic_message(
28        &self,
29        vtl: Vtl,
30        connection_id: u32,
31        secure: bool,
32        message: &[u8],
33    ) -> hvdef::HvResult<()>;
34
35    /// Memory mapped IO read.
36    #[must_use]
37    fn read_mmio(&self, vp: VpIndex, address: u64, data: &mut [u8]) -> impl Future<Output = ()>;
38
39    /// Memory mapped IO write.
40    #[must_use]
41    fn write_mmio(&self, vp: VpIndex, address: u64, data: &[u8]) -> impl Future<Output = ()>;
42
43    /// Programmed IO read.
44    #[must_use]
45    fn read_io(&self, vp: VpIndex, port: u16, data: &mut [u8]) -> impl Future<Output = ()>;
46
47    /// Programmed IO write.
48    #[must_use]
49    fn write_io(&self, vp: VpIndex, port: u16, data: &[u8]) -> impl Future<Output = ()>;
50}