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 <[email protected]>
  • Loading branch information
gaojiaqi7 committed May 24, 2024
1 parent 2c5c43c commit 5576869
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 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_table: 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_table: 0,
}
}

Expand Down Expand Up @@ -116,11 +121,12 @@ impl<'a> AcpiTables<'a> {
return;
}
}
self.table_offset.push(self.size);
self.table_offset[self.num_table] = self.size;
}

self.acpi_memory[self.size..self.size + table.len()].copy_from_slice(table);
self.size += table.len();
self.num_table += 1;
}

fn offset_to_address(&self, offset: usize) -> u64 {
Expand Down

0 comments on commit 5576869

Please sign in to comment.