vmm: use acpi_tables helpers for PPTT

Use the helpers from the acpi_tables crate to construct the PPTT. This
is in preparation for adding cache hierarchy info to the PPTT which is
simpler using the helpers.

Signed-off-by: Anirudh Rayabharam <anrayabh@microsoft.com>
This commit is contained in:
Anirudh Rayabharam
2026-03-13 11:34:52 +00:00
committed by Rob Bradford
parent 3d5f06ff03
commit f5089c705b
2 changed files with 25 additions and 62 deletions

View File

@@ -938,9 +938,12 @@ fn create_acpi_tables_internal(
{
let pptt = cpu_manager.create_pptt();
let pptt_addr = prev_tbl_addr.checked_add(prev_tbl_len).unwrap();
tables_bytes.extend_from_slice(pptt.as_slice());
let mut pptt_bytes = Vec::new();
pptt.to_aml_bytes(&mut pptt_bytes);
tables_bytes.extend_from_slice(&pptt_bytes);
xsdt_table_pointers.push(pptt_addr.0);
prev_tbl_len = pptt.len() as u64;
prev_tbl_len = pptt_bytes.len() as u64;
prev_tbl_addr = pptt_addr;
}

View File

@@ -20,6 +20,8 @@ use std::sync::atomic::{AtomicBool, AtomicI32, Ordering};
use std::sync::{Arc, Barrier, Mutex};
use std::{any, cmp, hint, io, panic, result, thread, time};
#[cfg(target_arch = "aarch64")]
use acpi_tables::pptt::{PPTT, ProcessorNode};
use acpi_tables::sdt::Sdt;
use acpi_tables::{Aml, aml};
use anyhow::anyhow;
@@ -415,19 +417,6 @@ struct GicIts {
pub reserved1: u32,
}
#[cfg(target_arch = "aarch64")]
#[repr(C, packed)]
#[derive(IntoBytes, Immutable, FromBytes)]
struct ProcessorHierarchyNode {
pub r#type: u8,
pub length: u8,
pub reserved: u16,
pub flags: u32,
pub parent: u32,
pub acpi_processor_id: u32,
pub num_private_resources: u32,
}
#[cfg(target_arch = "riscv64")]
#[repr(C, packed)]
#[derive(IntoBytes, Immutable, FromBytes)]
@@ -1955,8 +1944,7 @@ impl CpuManager {
}
#[cfg(target_arch = "aarch64")]
pub fn create_pptt(&self) -> Sdt {
let pptt_start = 0;
pub fn create_pptt(&self) -> PPTT {
let mut cpus = 0;
let mut uid = 0;
// If topology is not specified, the default setting is:
@@ -1967,61 +1955,34 @@ impl CpuManager {
.unwrap_or((1, u16::try_from(self.max_vcpus()).unwrap(), 1, 1));
let cores_per_package = cores_per_die * dies_per_package;
let mut pptt = Sdt::new(*b"PPTT", 36, 2, *b"CLOUDH", *b"CHPPTT ", 1);
let mut pptt = PPTT::new(*b"CLOUDH", *b"CHPPTT ", 1);
for cluster_idx in 0..packages {
if cpus < self.config.boot_vcpus as usize {
let cluster_offset = pptt.len() - pptt_start;
let cluster_hierarchy_node = ProcessorHierarchyNode {
r#type: 0,
length: 20,
reserved: 0,
flags: 0x2,
parent: 0,
acpi_processor_id: cluster_idx as u32,
num_private_resources: 0,
};
pptt.append(cluster_hierarchy_node);
let cluster_hierarchy_node = ProcessorNode::new(None, cluster_idx as u32).valid();
let cluster_handle = pptt.add_processor(cluster_hierarchy_node);
for core_idx in 0..cores_per_package {
let core_offset = pptt.len() - pptt_start;
if threads_per_core > 1 {
let core_hierarchy_node = ProcessorHierarchyNode {
r#type: 0,
length: 20,
reserved: 0,
flags: 0x2,
parent: cluster_offset as u32,
acpi_processor_id: core_idx as u32,
num_private_resources: 0,
};
pptt.append(core_hierarchy_node);
let core_hierarchy_node =
ProcessorNode::new(Some(&cluster_handle), core_idx as u32).valid();
let core_handle = pptt.add_processor(core_hierarchy_node);
for _thread_idx in 0..threads_per_core {
let thread_hierarchy_node = ProcessorHierarchyNode {
r#type: 0,
length: 20,
reserved: 0,
flags: 0xE,
parent: core_offset as u32,
acpi_processor_id: uid as u32,
num_private_resources: 0,
};
pptt.append(thread_hierarchy_node);
let thread_hierarchy_node =
ProcessorNode::new(Some(&core_handle), uid as u32)
.valid()
.thread()
.leaf();
pptt.add_processor(thread_hierarchy_node);
uid += 1;
}
} else {
let thread_hierarchy_node = ProcessorHierarchyNode {
r#type: 0,
length: 20,
reserved: 0,
flags: 0xA,
parent: cluster_offset as u32,
acpi_processor_id: uid as u32,
num_private_resources: 0,
};
pptt.append(thread_hierarchy_node);
let thread_hierarchy_node =
ProcessorNode::new(Some(&cluster_handle), uid as u32)
.valid()
.leaf();
pptt.add_processor(thread_hierarchy_node);
uid += 1;
}
}
@@ -2029,7 +1990,6 @@ impl CpuManager {
}
}
pptt.update_checksum();
pptt
}