summary refs log tree commit diff
diff options
context:
space:
mode:
authorColin Downs-Razouk <colindr@google.com>2020-05-11 08:13:50 -0700
committerCommit Bot <commit-bot@chromium.org>2020-06-04 19:17:44 +0000
commitba7662437018e380bbf208c23fda39cb62907a62 (patch)
tree8cb7eed588647112a16f8fe792d62e3581aa61b1
parent814a8da0ed70187bf06618ee3a545ca3361b5933 (diff)
downloadcrosvm-ba7662437018e380bbf208c23fda39cb62907a62.tar
crosvm-ba7662437018e380bbf208c23fda39cb62907a62.tar.gz
crosvm-ba7662437018e380bbf208c23fda39cb62907a62.tar.bz2
crosvm-ba7662437018e380bbf208c23fda39cb62907a62.tar.lz
crosvm-ba7662437018e380bbf208c23fda39cb62907a62.tar.xz
crosvm-ba7662437018e380bbf208c23fda39cb62907a62.tar.zst
crosvm-ba7662437018e380bbf208c23fda39cb62907a62.zip
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 <noreply+kokoro@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
-rw-r--r--devices/src/irqchip/kvm/mod.rs5
-rw-r--r--devices/src/irqchip/kvm/x86_64.rs57
-rw-r--r--devices/src/irqchip/mod.rs5
-rw-r--r--devices/src/irqchip/x86_64.rs38
4 files changed, 105 insertions, 0 deletions
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<KvmVcpu> for KvmKernelIrqChip {
+    /// Get the current state of the PIC
+    fn get_pic_state(&self, _select: PicSelect) -> Result<PicState> {
+        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<IoapicState> {
+        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<LapicState> {
+        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<PitState> {
+        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<V: VcpuX86_64>: IrqChip<V> {
+    /// Get the current state of the PIC
+    fn get_pic_state(&self, select: PicSelect) -> Result<PicState>;
+
+    /// 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<IoapicState>;
+
+    /// 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<LapicState>;
+
+    /// 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<PitState>;
+
+    /// Sets the state of the PIT.
+    fn set_pit(&mut self, state: &PitState) -> Result<()>;
+}