diff --git a/vmm/src/cpu.rs b/vmm/src/cpu.rs index d058889bd..dac22317c 100644 --- a/vmm/src/cpu.rs +++ b/vmm/src/cpu.rs @@ -132,7 +132,7 @@ pub enum Error { } pub type Result = result::Result; -#[cfg(feature = "acpi")] +#[cfg(all(target_arch = "x86_64", feature = "acpi"))] #[repr(packed)] struct LocalApic { pub r#type: u8, @@ -394,6 +394,7 @@ pub struct CpuManager { seccomp_action: SeccompAction, vmmops: Arc>, #[cfg(feature = "acpi")] + #[cfg_attr(target_arch = "aarch64", allow(dead_code))] acpi_address: GuestAddress, } @@ -1260,12 +1261,13 @@ struct Cpu { cpu_id: u8, } -#[cfg(feature = "acpi")] +#[cfg(all(target_arch = "x86_64", feature = "acpi"))] const MADT_CPU_ENABLE_FLAG: usize = 0; #[cfg(feature = "acpi")] -impl Aml for Cpu { - fn to_aml_bytes(&self) -> Vec { +impl Cpu { + #[cfg(target_arch = "x86_64")] + fn generate_mat(&self) -> Vec { let lapic = LocalApic { r#type: 0, length: 8, @@ -1278,11 +1280,22 @@ impl Aml for Cpu { mat_data.resize(std::mem::size_of_val(&lapic), 0); unsafe { *(mat_data.as_mut_ptr() as *mut LocalApic) = lapic }; + mat_data + } +} + +#[cfg(feature = "acpi")] +impl Aml for Cpu { + fn to_aml_bytes(&self) -> Vec { + #[cfg(target_arch = "x86_64")] + let mat_data: Vec = self.generate_mat(); + aml::Device::new( format!("C{:03}", self.cpu_id).as_str().into(), vec![ &aml::Name::new("_HID".into(), &"ACPI0007"), &aml::Name::new("_UID".into(), &self.cpu_id), + // Currently, AArch64 cannot support following fields. /* _STA return value: Bit [0] – Set if the device is present. @@ -1292,6 +1305,7 @@ impl Aml for Cpu { Bit [4] – Set if the battery is present. Bits [31:5] – Reserved (must be cleared). */ + #[cfg(target_arch = "x86_64")] &aml::Method::new( "_STA".into(), 0, @@ -1305,8 +1319,10 @@ impl Aml for Cpu { // The Linux kernel expects every CPU device to have a _MAT entry // containing the LAPIC for this processor with the enabled bit set // even it if is disabled in the MADT (non-boot CPU) + #[cfg(target_arch = "x86_64")] &aml::Name::new("_MAT".into(), &aml::Buffer::new(mat_data)), // Trigger CPU ejection + #[cfg(target_arch = "x86_64")] &aml::Method::new( "_EJ0".into(), 1, @@ -1467,6 +1483,7 @@ impl Aml for CpuManager { fn to_aml_bytes(&self) -> Vec { let mut bytes = Vec::new(); // CPU hotplug controller + #[cfg(target_arch = "x86_64")] bytes.extend_from_slice( &aml::Device::new( "_SB_.PRES".into(),