virt/io.rs
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use crate::VpHaltReason;
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 /// Memory mapped IO read.
24 #[must_use]
25 fn read_mmio(&self, vp: VpIndex, address: u64, data: &mut [u8]) -> impl Future<Output = ()>;
26
27 /// Memory mapped IO write.
28 #[must_use]
29 fn write_mmio(&self, vp: VpIndex, address: u64, data: &[u8]) -> impl Future<Output = ()>;
30
31 /// Programmed IO read.
32 #[must_use]
33 fn read_io(&self, vp: VpIndex, port: u16, data: &mut [u8]) -> impl Future<Output = ()>;
34
35 /// Programmed IO write.
36 #[must_use]
37 fn write_io(&self, vp: VpIndex, port: u16, data: &[u8]) -> impl Future<Output = ()>;
38
39 /// Report an internal fatal error.
40 ///
41 /// The intention behind this method is to allow the top-level VMM
42 /// to specify an error handling policy, while still being able to capture
43 /// stacks and other context from the point of failure. We previously would
44 /// return a `VpHaltReason::Panic` here, but that meant the stack trace
45 /// would be from the point of the panic handler, which lost context.
46 /// See vmotherboard's `FatalErrorPolicy` for an example.
47 #[track_caller]
48 fn fatal_error(&self, error: Box<dyn std::error::Error + Send + Sync>) -> VpHaltReason;
49}