summary refs log tree commit diff
path: root/devices/src/irqchip/mod.rs
blob: 3284bc6f99f10b09e09ee09d21bb63d30900ff81 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2020 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

mod kvm;
pub use self::kvm::KvmKernelIrqChip;

use std::marker::{Send, Sized};

use hypervisor::{IrqRoute, Vcpu};
use sys_util::{EventFd, Result};

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod x86_64;
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub use x86_64::*;

/// Trait that abstracts interactions with interrupt controllers.
///
/// Each VM will have one IrqChip instance which is responsible for routing IRQ lines and
/// registering IRQ events. Depending on the implementation, the IrqChip may interact with an
/// underlying hypervisor API or emulate devices in userspace.
///
/// This trait is generic over a Vcpu type because some IrqChip implementations can support
/// multiple hypervisors with a single implementation.
pub trait IrqChip<V: Vcpu>: Send + Sized {
    /// Add a vcpu to the irq chip.
    fn add_vcpu(&mut self, vcpu_id: usize, vcpu: V) -> Result<()>;

    /// Register an event that can trigger an interrupt for a particular GSI.
    fn register_irq_event(
        &mut self,
        irq: u32,
        irq_event: &EventFd,
        resample_event: Option<&EventFd>,
    ) -> Result<()>;

    /// Unregister an event for a particular GSI.
    fn unregister_irq_event(
        &mut self,
        irq: u32,
        irq_event: &EventFd,
        resample_event: Option<&EventFd>,
    ) -> Result<()>;

    /// Route an IRQ line to an interrupt controller, or to a particular MSI vector.
    fn route_irq(&mut self, route: IrqRoute) -> Result<()>;

    /// Return a vector of all registered irq numbers and their associated events.  To be used by
    /// the main thread to wait for irq events to be triggered.
    fn irq_event_tokens(&self) -> Result<Vec<(u32, EventFd)>>;

    /// Either assert or deassert an IRQ line.  Sends to either an interrupt controller, or does
    /// a send_msi if the irq is associated with an MSI.
    fn service_irq(&mut self, irq: u32, level: bool) -> Result<()>;

    /// Broadcast an end of interrupt.
    fn broadcast_eoi(&mut self, vector: u8) -> Result<()>;

    /// Return true if there is a pending interrupt for the specified vcpu.
    fn interrupt_requested(&self, vcpu_id: usize) -> bool;

    /// Check if the specified vcpu has any pending interrupts. Returns None for no interrupts,
    /// otherwise Some(u32) should be the injected interrupt vector.
    fn get_external_interrupt(&mut self, vcpu_id: usize) -> Result<Option<u32>>;

    /// Attempt to clone this IrqChip instance.
    fn try_clone(&self) -> Result<Self>;
}