From 2a0ce34f31533b8e6e8c7b7ed1a55990702958ac Mon Sep 17 00:00:00 2001 From: Colin Downs-Razouk Date: Tue, 26 May 2020 08:43:18 -0700 Subject: devices: irqchip: KvmKernelIrqchip x86_64 impl Implemented get/set_pic/ioapic/pit functions for the KvmKernelIrqchip. Added respective functions on KvmVm for interacting with the underlying KVM API. Added associated tests for get/set functions. BUG=chromium:1077058 TEST=ran devices tests and added get/set function tests Change-Id: I66a29828fe2f1fbdf54d7325656a003ac09e36d0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2219422 Reviewed-by: Udam Saini Reviewed-by: Stephen Barber Tested-by: kokoro Commit-Queue: Colin Downs-Razouk --- hypervisor/src/kvm/mod.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'hypervisor/src/kvm/mod.rs') diff --git a/hypervisor/src/kvm/mod.rs b/hypervisor/src/kvm/mod.rs index 5fdf124..bf87e3d 100644 --- a/hypervisor/src/kvm/mod.rs +++ b/hypervisor/src/kvm/mod.rs @@ -171,6 +171,34 @@ impl KvmVm { fn create_kvm_vcpu(&self, _id: usize) -> Result { Ok(KvmVcpu {}) } + + /// Crates an in kernel interrupt controller. + /// + /// See the documentation on the KVM_CREATE_IRQCHIP ioctl. + pub fn create_irq_chip(&self) -> Result<()> { + // Safe because we know that our file is a VM fd and we verify the return result. + let ret = unsafe { ioctl(self, KVM_CREATE_IRQCHIP()) }; + if ret == 0 { + Ok(()) + } else { + errno_result() + } + } + /// Sets the level on the given irq to 1 if `active` is true, and 0 otherwise. + pub fn set_irq_line(&self, irq: u32, active: bool) -> Result<()> { + let mut irq_level = kvm_irq_level::default(); + irq_level.__bindgen_anon_1.irq = irq; + irq_level.level = if active { 1 } else { 0 }; + + // Safe because we know that our file is a VM fd, we know the kernel will only read the + // correct amount of memory from our pointer, and we verify the return result. + let ret = unsafe { ioctl_with_ref(self, KVM_IRQ_LINE(), &irq_level) }; + if ret == 0 { + Ok(()) + } else { + errno_result() + } + } } impl Vm for KvmVm { -- cgit 1.4.1