Skip to content

Commit

Permalink
td-shim: use fixed-size array for ACPI table installation
Browse files Browse the repository at this point in the history
Replace the vector with a fixed-array to record the table offsets
of ACPI tables. The maximum number of ACPI tables is 128 according to
Linux Kernel implementation.

Signed-off-by: Jiaqi Gao <jiaqi.gao@intel.com>
  • Loading branch information
gaojiaqi7 committed May 24, 2024
1 parent 2c5c43c commit 1c44bff
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions td-shim/src/bin/td-shim/acpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,32 @@
// SPDX-License-Identifier: BSD-2-Clause-Patent
extern crate alloc;

use alloc::vec::Vec;
use td_shim_interface::acpi::{calculate_checksum, Rsdp, Xsdt};

use super::*;

#[derive(Default)]
const ACPI_MAX_TABLES: usize = 128;

pub struct AcpiTables<'a> {
acpi_memory: &'a mut [u8],
pa: u64,
size: usize,
fadt: Option<(usize, usize)>, // FADT offset in acpi memory
dsdt: Option<usize>, // DSDT offset in acpi memory
table_offset: Vec<usize>,
table_offset: [usize; ACPI_MAX_TABLES],
num_tables: usize,
}

impl<'a> AcpiTables<'a> {
pub fn new(td_acpi_mem: &'a mut [u8], pa: u64) -> Self {
AcpiTables {
acpi_memory: td_acpi_mem,
pa,
..Default::default()
size: 0,
fadt: None,
dsdt: None,
table_offset: [0; ACPI_MAX_TABLES],
num_tables: 0,
}
}

Expand Down Expand Up @@ -116,7 +121,11 @@ impl<'a> AcpiTables<'a> {
return;
}
}
self.table_offset.push(self.size);
if self.num_tables >= ACPI_MAX_TABLES {
panic!("Number of ACPI table exceeds limit 0x{:X}", ACPI_MAX_TABLES,);
}
self.table_offset[self.num_tables] = self.size;
self.num_tables += 1;
}

self.acpi_memory[self.size..self.size + table.len()].copy_from_slice(table);
Expand Down

0 comments on commit 1c44bff

Please sign in to comment.