arch: x86_64: allow more than 2 E820_RAM ranges

The 'generate_ram_ranges' function currently hardcodes the assumption
that there are only 2 E820 RAM entries. This is not flexible enough to
handle vendor specific memory holes. Returning a Vec is also more
convenient for users of this function.

Signed-off-by: Thomas Barrett <tbarrett@crusoeenergy.com>
This commit is contained in:
Thomas Barrett
2024-02-14 20:58:38 +00:00
committed by Rob Bradford
parent bcdd23956f
commit ce7db3f7c3
2 changed files with 22 additions and 62 deletions

View File

@@ -92,15 +92,10 @@ fn generate_memory_map(
let mut memory_map = Vec::new();
// Get usable physical memory ranges
let (first_ram_range, second_ram_range) =
arch::generate_ram_ranges(guest_mem).map_err(Error::InvalidGuestMemmap)?;
let ram_ranges = arch::generate_ram_ranges(guest_mem).map_err(Error::InvalidGuestMemmap)?;
// Create the memory map entry for memory region before the gap
memory_map.push(igvm_memmap_from_ram_range(first_ram_range));
// Create the memory map entry for memory region after the gap if any
if let Some(second_ram_range) = second_ram_range {
memory_map.push(igvm_memmap_from_ram_range(second_ram_range));
for ram_range in ram_ranges {
memory_map.push(igvm_memmap_from_ram_range(ram_range));
}
Ok(memory_map)