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 <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2019-09-27 17:51:46 +01:00 committed by Sebastien Boeuf
parent 162791b571
commit b5ee9212c1
2 changed files with 10 additions and 4 deletions

View File

@ -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<VmFd>,
apic_address: GuestAddress,
}
impl BusDevice for Ioapic {
@ -194,12 +196,13 @@ impl BusDevice for Ioapic {
}
impl Ioapic {
pub fn new(vm_fd: Arc<VmFd>) -> Ioapic {
pub fn new(vm_fd: Arc<VmFd>, 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;

View File

@ -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)