Revert "vmm: Move CpuManager device to MMIO region"

This reverts commit 980e03fa0a.
This commit is contained in:
Rob Bradford 2020-01-24 10:36:39 +00:00 committed by Sebastien Boeuf
parent 6475052692
commit 6120d0fb1b

View File

@ -114,8 +114,8 @@ pub enum Error {
/// Cannot add legacy device to Bus. /// Cannot add legacy device to Bus.
BusError(devices::BusError), BusError(devices::BusError),
/// Failed to allocate MMIO range /// Failed to allocate IO port
AllocateMMIO, AllocateIOPort,
/// Asking for more vCPUs that we can have /// Asking for more vCPUs that we can have
DesiredVCPUCountExceedsMax, DesiredVCPUCountExceedsMax,
@ -373,8 +373,8 @@ impl Vcpu {
pub struct CpuManager { pub struct CpuManager {
boot_vcpus: u8, boot_vcpus: u8,
max_vcpus: u8, max_vcpus: u8,
io_bus: Arc<devices::Bus>, io_bus: Weak<devices::Bus>,
mmio_bus: Weak<devices::Bus>, mmio_bus: Arc<devices::Bus>,
ioapic: Option<Arc<Mutex<ioapic::Ioapic>>>, ioapic: Option<Arc<Mutex<ioapic::Ioapic>>>,
vm_memory: Arc<ArcSwap<GuestMemoryMmap>>, vm_memory: Arc<ArcSwap<GuestMemoryMmap>>,
cpuid: CpuId, cpuid: CpuId,
@ -384,8 +384,6 @@ pub struct CpuManager {
reset_evt: EventFd, reset_evt: EventFd,
vcpu_states: Vec<VcpuState>, vcpu_states: Vec<VcpuState>,
selected_cpu: u8, selected_cpu: u8,
#[cfg(feature = "acpi")]
device_base: GuestAddress,
} }
const CPU_ENABLE_FLAG: usize = 0; const CPU_ENABLE_FLAG: usize = 0;
@ -494,8 +492,6 @@ impl VcpuState {
} }
impl CpuManager { impl CpuManager {
pub const DEVICE_SIZE: u64 = 0xc;
pub fn new( pub fn new(
boot_vcpus: u8, boot_vcpus: u8,
max_vcpus: u8, max_vcpus: u8,
@ -508,19 +504,11 @@ impl CpuManager {
let mut vcpu_states = Vec::with_capacity(usize::from(max_vcpus)); let mut vcpu_states = Vec::with_capacity(usize::from(max_vcpus));
vcpu_states.resize_with(usize::from(max_vcpus), VcpuState::default); vcpu_states.resize_with(usize::from(max_vcpus), VcpuState::default);
#[cfg(feature = "acpi")]
let device_base = device_manager
.allocator()
.lock()
.unwrap()
.allocate_mmio_addresses(None, CpuManager::DEVICE_SIZE, None)
.ok_or(Error::AllocateMMIO)?;
let cpu_manager = Arc::new(Mutex::new(CpuManager { let cpu_manager = Arc::new(Mutex::new(CpuManager {
boot_vcpus, boot_vcpus,
max_vcpus, max_vcpus,
io_bus: device_manager.io_bus().clone(), io_bus: Arc::downgrade(&device_manager.io_bus().clone()),
mmio_bus: Arc::downgrade(&device_manager.mmio_bus().clone()), mmio_bus: device_manager.mmio_bus().clone(),
ioapic: device_manager.ioapic().clone(), ioapic: device_manager.ioapic().clone(),
vm_memory: guest_memory, vm_memory: guest_memory,
cpuid, cpuid,
@ -530,18 +518,22 @@ impl CpuManager {
vcpu_states, vcpu_states,
reset_evt, reset_evt,
selected_cpu: 0, selected_cpu: 0,
#[cfg(feature = "acpi")]
device_base,
})); }));
#[cfg(feature = "acpi")] device_manager
.allocator()
.lock()
.unwrap()
.allocate_io_addresses(Some(GuestAddress(0x0cd8)), 0x8, None)
.ok_or(Error::AllocateIOPort)?;
cpu_manager cpu_manager
.lock() .lock()
.unwrap() .unwrap()
.mmio_bus .io_bus
.upgrade() .upgrade()
.unwrap() .unwrap()
.insert(cpu_manager.clone(), device_base.0, CpuManager::DEVICE_SIZE) .insert(cpu_manager.clone(), 0x0cd8, 0xc)
.map_err(Error::BusError)?; .map_err(Error::BusError)?;
Ok(cpu_manager) Ok(cpu_manager)
@ -571,8 +563,8 @@ impl CpuManager {
let mut vcpu = Vcpu::new( let mut vcpu = Vcpu::new(
cpu_id, cpu_id,
&self.fd, &self.fd,
self.io_bus.clone(), self.io_bus.clone().upgrade().unwrap(),
self.mmio_bus.clone().upgrade().unwrap(), self.mmio_bus.clone(),
ioapic, ioapic,
creation_ts, creation_ts,
)?; )?;
@ -860,7 +852,7 @@ impl Aml for CPUMethods {
vec![ vec![
// Take lock defined above // Take lock defined above
&aml::Acquire::new("\\_SB_.PRES.CPLK".into(), 0xfff), &aml::Acquire::new("\\_SB_.PRES.CPLK".into(), 0xfff),
// Write CPU number (in first argument) to MMIO region via field // Write CPU number (in first argument) to I/O port via field
&aml::Store::new(&aml::Path::new("\\_SB_.PRES.CSEL"), &aml::Arg(0)), &aml::Store::new(&aml::Path::new("\\_SB_.PRES.CSEL"), &aml::Arg(0)),
&aml::Store::new(&aml::Local(0), &aml::ZERO), &aml::Store::new(&aml::Local(0), &aml::ZERO),
// Check if CPEN bit is set, if so make the local variable 0xf (see _STA for details of meaning) // Check if CPEN bit is set, if so make the local variable 0xf (see _STA for details of meaning)
@ -898,7 +890,7 @@ impl Aml for CPUMethods {
true, true,
vec![ vec![
&aml::Acquire::new("\\_SB_.PRES.CPLK".into(), 0xfff), &aml::Acquire::new("\\_SB_.PRES.CPLK".into(), 0xfff),
// Write CPU number (in first argument) to MMIO region via field // Write CPU number (in first argument) to I/O port via field
&aml::Store::new(&aml::Path::new("\\_SB_.PRES.CSEL"), &aml::Arg(0)), &aml::Store::new(&aml::Path::new("\\_SB_.PRES.CSEL"), &aml::Arg(0)),
// Set CEJ0 bit // Set CEJ0 bit
&aml::Store::new(&aml::Path::new("\\_SB_.PRES.CEJ0"), &aml::ONE), &aml::Store::new(&aml::Path::new("\\_SB_.PRES.CEJ0"), &aml::ONE),
@ -920,7 +912,7 @@ impl Aml for CPUMethods {
&aml::While::new( &aml::While::new(
&aml::LessThan::new(&aml::Local(0), &self.max_vcpus), &aml::LessThan::new(&aml::Local(0), &self.max_vcpus),
vec![ vec![
// Write CPU number (in first argument) to MMIO region via field // Write CPU number (in first argument) to I/O port via field
&aml::Store::new(&aml::Path::new("\\_SB_.PRES.CSEL"), &aml::Local(0)), &aml::Store::new(&aml::Path::new("\\_SB_.PRES.CSEL"), &aml::Local(0)),
// Check if CINS bit is set // Check if CINS bit is set
&aml::If::new( &aml::If::new(
@ -979,23 +971,15 @@ impl Aml for CpuManager {
&aml::Name::new("_HID".into(), &aml::EISAName::new("PNP0A06")), &aml::Name::new("_HID".into(), &aml::EISAName::new("PNP0A06")),
// Mutex to protect concurrent access as we write to choose CPU and then read back status // Mutex to protect concurrent access as we write to choose CPU and then read back status
&aml::Mutex::new("CPLK".into(), 0), &aml::Mutex::new("CPLK".into(), 0),
// MMIO region for CPU controller // I/O port for CPU controller
&aml::Name::new( &aml::Name::new(
"_CRS".into(), "_CRS".into(),
&aml::ResourceTemplate::new(vec![&aml::AddressSpace::new_memory( &aml::ResourceTemplate::new(vec![&aml::IO::new(
aml::AddressSpaceCachable::NotCacheable, 0x0cd8, 0x0cd8, 0x01, 0x0c,
true,
self.device_base.0,
self.device_base.0 + CpuManager::DEVICE_SIZE - 1,
)]), )]),
), ),
// OpRegion and Fields map MMIO region into individual field values // OpRegion and Fields map I/O port into individual field values
&aml::OpRegion::new( &aml::OpRegion::new("PRST".into(), aml::OpRegionSpace::SystemIO, 0x0cd8, 0x0c),
"PRST".into(),
aml::OpRegionSpace::SystemMemory,
self.device_base.0 as usize,
CpuManager::DEVICE_SIZE as usize,
),
&aml::Field::new( &aml::Field::new(
"PRST".into(), "PRST".into(),
aml::FieldAccessType::Byte, aml::FieldAccessType::Byte,