vmm_core/emuplat/
apic.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Code to bridge between the `vmotherboard` interrupt controller and a `virt`
5//! partition APIC.
6
7use hvdef::Vtl;
8use std::sync::Arc;
9use virt::X86Partition;
10use vm_topology::processor::VpIndex;
11use vmcore::line_interrupt::LineSetTarget;
12
13/// A [`LineSetTarget`] implementation that raises APIC local interrupt lines.
14pub struct ApicLintLineTarget<T: X86Partition> {
15    partition: Arc<T>,
16    vtl: Vtl,
17}
18
19impl<T: X86Partition> ApicLintLineTarget<T> {
20    /// Creates a new APIC LINT line set target.
21    pub fn new(partition: Arc<T>, vtl: Vtl) -> Self {
22        Self { partition, vtl }
23    }
24}
25
26impl<T: X86Partition> LineSetTarget for ApicLintLineTarget<T> {
27    fn set_irq(&self, vector: u32, high: bool) {
28        if !high {
29            return;
30        }
31        let vp_index = VpIndex::new(vector / 2);
32        let lint = vector % 2;
33        self.partition.pulse_lint(vp_index, self.vtl, lint as u8);
34    }
35}