From b5ee9212c115e0cca41cab43ec650fa6c66736f1 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Fri, 27 Sep 2019 17:51:46 +0100 Subject: [PATCH] vmm, devices: Use APIC address constant In order to avoid introducing a dependency on arch in the devices crate pass the constant in to the IOAPIC device creation. Signed-off-by: Rob Bradford --- devices/src/ioapic.rs | 7 +++++-- vmm/src/device_manager.rs | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/devices/src/ioapic.rs b/devices/src/ioapic.rs index 5f89eaea5..8fdcfae2a 100644 --- a/devices/src/ioapic.rs +++ b/devices/src/ioapic.rs @@ -15,6 +15,7 @@ use kvm_bindings::kvm_msi; use kvm_ioctls::VmFd; use std::sync::Arc; use std::{io, result}; +use vm_memory::GuestAddress; #[derive(Debug)] pub enum Error { @@ -156,6 +157,7 @@ pub struct Ioapic { reg_sel: u32, reg_entries: [RedirectionTableEntry; NUM_IOAPIC_PINS], vm_fd: Arc, + apic_address: GuestAddress, } impl BusDevice for Ioapic { @@ -194,12 +196,13 @@ impl BusDevice for Ioapic { } impl Ioapic { - pub fn new(vm_fd: Arc) -> Ioapic { + pub fn new(vm_fd: Arc, apic_address: GuestAddress) -> Ioapic { Ioapic { id: 0, reg_sel: 0, reg_entries: [0; NUM_IOAPIC_PINS], vm_fd, + apic_address, } } @@ -239,7 +242,7 @@ impl Ioapic { let redirection_hint: u8 = 1; // Generate MSI message address - let address_lo: u32 = 0xfee0_0000 + let address_lo: u32 = self.apic_address.0 as u32 | u32::from(destination_id) << 12 | u32::from(redirection_hint) << 3 | u32::from(destination_mode) << 2; diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 616c7f9c6..495bdd75d 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -28,7 +28,7 @@ use qcow::{self, ImageType, QcowFile}; use std::fs::{File, OpenOptions}; use std::io::{self, sink, stdout}; -use arch::layout::{IOAPIC_SIZE, IOAPIC_START}; +use arch::layout::{APIC_START, IOAPIC_SIZE, IOAPIC_START}; use std::os::unix::fs::OpenOptionsExt; use std::os::unix::io::AsRawFd; use std::ptr::null_mut; @@ -305,7 +305,10 @@ impl DeviceManager { let ioapic = if userspace_ioapic { // Create IOAPIC - let ioapic = Arc::new(Mutex::new(ioapic::Ioapic::new(vm_info.vm_fd.clone()))); + let ioapic = Arc::new(Mutex::new(ioapic::Ioapic::new( + vm_info.vm_fd.clone(), + APIC_START, + ))); buses .mmio .insert(ioapic.clone(), IOAPIC_START.0, IOAPIC_SIZE)