From ba7662437018e380bbf208c23fda39cb62907a62 Mon Sep 17 00:00:00 2001 From: Colin Downs-Razouk Date: Mon, 11 May 2020 08:13:50 -0700 Subject: devices: irqchip: IrqChipX86_64 trait This trait handles the x86-specific features of an irqchip, including getting and setting the state of the pic, ioapic, lapics, and pit. Also includes an empty implementation of this trait for the KvmKernelIrqChip. BUG=chromium:1077058 TEST=cargo test -p devices Change-Id: I36034661f4a2baedc7ac2b8f311cab6327afefba Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2197717 Tested-by: kokoro Commit-Queue: Colin Downs-Razouk Reviewed-by: Daniel Verkamp Reviewed-by: Stephen Barber --- devices/src/irqchip/kvm/mod.rs | 5 ++++ devices/src/irqchip/kvm/x86_64.rs | 57 +++++++++++++++++++++++++++++++++++++++ devices/src/irqchip/mod.rs | 5 ++++ devices/src/irqchip/x86_64.rs | 38 ++++++++++++++++++++++++++ 4 files changed, 105 insertions(+) create mode 100644 devices/src/irqchip/kvm/x86_64.rs create mode 100644 devices/src/irqchip/x86_64.rs (limited to 'devices') diff --git a/devices/src/irqchip/kvm/mod.rs b/devices/src/irqchip/kvm/mod.rs index 56794a3..bdc9d3f 100644 --- a/devices/src/irqchip/kvm/mod.rs +++ b/devices/src/irqchip/kvm/mod.rs @@ -8,6 +8,11 @@ use std::sync::Arc; use sync::Mutex; 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::*; + use crate::IrqChip; /// IrqChip implementation where the entire IrqChip is emulated by KVM. diff --git a/devices/src/irqchip/kvm/x86_64.rs b/devices/src/irqchip/kvm/x86_64.rs new file mode 100644 index 0000000..6f59935 --- /dev/null +++ b/devices/src/irqchip/kvm/x86_64.rs @@ -0,0 +1,57 @@ +// 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. + +use hypervisor::kvm::KvmVcpu; +use hypervisor::{IoapicState, LapicState, PicSelect, PicState, PitState}; + +use sys_util::Result; + +use crate::{Bus, IrqChipX86_64, KvmKernelIrqChip}; + +impl IrqChipX86_64 for KvmKernelIrqChip { + /// Get the current state of the PIC + fn get_pic_state(&self, _select: PicSelect) -> Result { + unimplemented!("get_pic_state for KvmKernelIrqChip is not yet implemented"); + } + + /// Set the current state of the PIC + fn set_pic_state(&mut self, _select: PicSelect, _state: &PicState) -> Result<()> { + unimplemented!("set_pic_state for KvmKernelIrqChip is not yet implemented"); + } + + /// Get the current state of the IOAPIC + fn get_ioapic_state(&self) -> Result { + unimplemented!("get_ioapic_state for KvmKernelIrqChip is not yet implemented"); + } + + /// Set the current state of the IOAPIC + fn set_ioapic_state(&mut self, _state: &IoapicState) -> Result<()> { + unimplemented!("set_ioapic_state for KvmKernelIrqChip is not yet implemented"); + } + + /// Get the current state of the specified VCPU's local APIC + fn get_lapic_state(&self, _vcpu_id: usize) -> Result { + unimplemented!("get_lapic_state for KvmKernelIrqChip is not yet implemented"); + } + + /// Set the current state of the specified VCPU's local APIC + fn set_lapic_state(&mut self, _vcpu_id: usize, _state: &LapicState) -> Result<()> { + unimplemented!("set_lapic_state for KvmKernelIrqChip is not yet implemented"); + } + + /// Create a PIT (Programmable Interval Timer) for this VM. + fn create_pit(&mut self, _io_bus: &mut Bus) -> Result<()> { + unimplemented!("create_pit for KvmKernelIrqChip is not yet implemented"); + } + + /// Retrieves the state of the PIT. + fn get_pit(&self) -> Result { + unimplemented!("get_pit for KvmKernelIrqChip is not yet implemented"); + } + + /// Sets the state of the PIT. + fn set_pit(&mut self, _state: &PitState) -> Result<()> { + unimplemented!("set_pit for KvmKernelIrqChip is not yet implemented"); + } +} diff --git a/devices/src/irqchip/mod.rs b/devices/src/irqchip/mod.rs index a8023e9..3284bc6 100644 --- a/devices/src/irqchip/mod.rs +++ b/devices/src/irqchip/mod.rs @@ -10,6 +10,11 @@ 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 diff --git a/devices/src/irqchip/x86_64.rs b/devices/src/irqchip/x86_64.rs new file mode 100644 index 0000000..4b50427 --- /dev/null +++ b/devices/src/irqchip/x86_64.rs @@ -0,0 +1,38 @@ +// 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. + +use crate::Bus; +use hypervisor::{IoapicState, LapicState, PicSelect, PicState, PitState, VcpuX86_64}; +use sys_util::Result; + +use crate::IrqChip; + +pub trait IrqChipX86_64: IrqChip { + /// Get the current state of the PIC + fn get_pic_state(&self, select: PicSelect) -> Result; + + /// Set the current state of the PIC + fn set_pic_state(&mut self, select: PicSelect, state: &PicState) -> Result<()>; + + /// Get the current state of the IOAPIC + fn get_ioapic_state(&self) -> Result; + + /// Set the current state of the IOAPIC + fn set_ioapic_state(&mut self, state: &IoapicState) -> Result<()>; + + /// Get the current state of the specified VCPU's local APIC + fn get_lapic_state(&self, vcpu_id: usize) -> Result; + + /// Set the current state of the specified VCPU's local APIC + fn set_lapic_state(&mut self, vcpu_id: usize, state: &LapicState) -> Result<()>; + + /// Create a PIT (Programmable Interval Timer) for this VM. + fn create_pit(&mut self, io_bus: &mut Bus) -> Result<()>; + + /// Retrieves the state of the PIT. + fn get_pit(&self) -> Result; + + /// Sets the state of the PIT. + fn set_pit(&mut self, state: &PitState) -> Result<()>; +} -- cgit 1.4.1