Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions configs/vms/linux-aarch64-a1000-smp8.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ dtb_path = "/path/to/dtb"
# Memory regions with format (`base_paddr`, `size`, `flags`, `map_type`).
# For `map_type`, 0 means `MAP_ALLOC`, 1 means `MAP_IDENTICAL`.
memory_regions = [
[0x8000_0000, 0x2000_0000, 0x7, 1], # System RAM 1G MAP_IDENTICAL
[0x1_ce80_0000, 0x2000_0000, 0x7, 1], # System RAM 1G MAP_IDENTICAL
[0x8000_0000, 0x7000_0000, 0xf, 2],
]
#
# Device specifications
Expand All @@ -50,7 +51,6 @@ emu_devices = []
# Name Base-Ipa Base-Pa Length Alloc-Irq.
passthrough_devices = [
["most-devices", 0x0, 0x0, 0x8000_0000, 0x1],
["memory", 0x8000_0000, 0x8000_0000, 0x7000_0000, 0x1]
]
excluded_devices = [
# ["/gic-v3"],
Expand Down
10 changes: 2 additions & 8 deletions configs/vms/linux-aarch64-rk3588-smp8.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ dtb_path = "/path/to/dtb"
# For `map_type`, 0 means `MAP_ALLOC`, 1 means `MAP_IDENTICAL`.
memory_regions = [
[0x940_0000, 0xd550_0000, 0x7, 1], # ram 3G MAP_IDENTICAL
[0x920_0000, 0x2000, 0x7, 1]
[0x920_0000, 0x2000, 0xf, 2]

]

#
Expand Down Expand Up @@ -108,13 +109,6 @@ passthrough_devices = [
0x10_f000,
0x17,
],
[
"device",
0x920_0000,
0x920_0000,
0x2000,
0x17,
],
]

excluded_devices = [
Expand Down
6 changes: 6 additions & 0 deletions src/vmm/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ fn vm_alloc_memorys(vm_create_config: &AxVMCrateConfig, vm: &VM) {
vm.alloc_memory_region(Layout::from_size_align(memory.size, ALIGN).unwrap(), None)
.expect("Failed to allocate memory region for VM");
}
VmMemMappingType::MapReserved => {
info!("VM[{}] map same region: {:#x?}", vm.id(), memory);
let layout = Layout::from_size_align(memory.size, ALIGN).unwrap();
vm.map_reserved_memory_region(layout, Some(GuestPhysAddr::from(memory.gpa)))
.expect("Failed to map memory region for VM");
}
}
}
}
127 changes: 74 additions & 53 deletions src/vmm/fdt/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,70 +218,91 @@ fn add_pci_ranges_config(vm_cfg: &mut AxVMConfig, node_name: &str, range: &PciRa
}

pub fn parse_passthrough_devices_address(vm_cfg: &mut AxVMConfig, dtb: &[u8]) {
let fdt = Fdt::from_bytes(dtb)
.expect("Failed to parse DTB image, perhaps the DTB is invalid or corrupted");
let devices = vm_cfg.pass_through_devices().to_vec();
if !devices.is_empty() && devices[0].length != 0 {
for (index, device) in devices.iter().enumerate() {
add_device_address_config(
vm_cfg,
&device.name,
device.base_gpa,
device.length,
index,
None,
);
}
} else {
let fdt = Fdt::from_bytes(dtb)
.expect("Failed to parse DTB image, perhaps the DTB is invalid or corrupted");

// Clear existing passthrough device configurations
vm_cfg.clear_pass_through_devices();
// Clear existing passthrough device configurations
vm_cfg.clear_pass_through_devices();

// Traverse all device tree nodes
for node in fdt.all_nodes() {
// Skip root node
if node.name() == "/" || node.name().starts_with("memory") {
continue;
}
// Traverse all device tree nodes
for node in fdt.all_nodes() {
// Skip root node
if node.name() == "/" || node.name().starts_with("memory") {
continue;
}

let node_name = node.name().to_string();
let node_name = node.name().to_string();

// Check if it's a PCIe device node
if node_name.starts_with("pcie@") || node_name.contains("pci") {
// Process PCIe device's ranges property
if let Some(pci) = node.clone().into_pci()
&& let Ok(ranges) = pci.ranges()
{
for (index, range) in ranges.enumerate() {
add_pci_ranges_config(vm_cfg, &node_name, &range, index);
// Check if it's a PCIe device node
if node_name.starts_with("pcie@") || node_name.contains("pci") {
// Process PCIe device's ranges property
if let Some(pci) = node.clone().into_pci()
&& let Ok(ranges) = pci.ranges()
{
for (index, range) in ranges.enumerate() {
add_pci_ranges_config(vm_cfg, &node_name, &range, index);
}
}
}

// Process PCIe device's reg property (ECAM space)
if let Some(reg_iter) = node.reg() {
for (index, reg) in reg_iter.enumerate() {
let base_address = reg.address as usize;
let size = reg.size.unwrap_or(0);

add_device_address_config(
vm_cfg,
&node_name,
base_address,
size,
index,
Some("ecam"),
);
// Process PCIe device's reg property (ECAM space)
if let Some(reg_iter) = node.reg() {
for (index, reg) in reg_iter.enumerate() {
let base_address = reg.address as usize;
let size = reg.size.unwrap_or(0);

add_device_address_config(
vm_cfg,
&node_name,
base_address,
size,
index,
Some("ecam"),
);
}
}
}
} else {
// Get device's reg property (process regular devices)
if let Some(reg_iter) = node.reg() {
// Process all address segments of the device
for (index, reg) in reg_iter.enumerate() {
// Get device's address and size information
let base_address = reg.address as usize;
let size = reg.size.unwrap_or(0);

add_device_address_config(vm_cfg, &node_name, base_address, size, index, None);
} else {
// Get device's reg property (process regular devices)
if let Some(reg_iter) = node.reg() {
// Process all address segments of the device
for (index, reg) in reg_iter.enumerate() {
// Get device's address and size information
let base_address = reg.address as usize;
let size = reg.size.unwrap_or(0);

add_device_address_config(
vm_cfg,
&node_name,
base_address,
size,
index,
None,
);
}
}
}
}
trace!(
"All passthrough devices: {:#x?}",
vm_cfg.pass_through_devices()
);
debug!(
"Finished parsing passthrough devices, total: {}",
vm_cfg.pass_through_devices().len()
);
}
trace!(
"All passthrough devices: {:#x?}",
vm_cfg.pass_through_devices()
);
debug!(
"Finished parsing passthrough devices, total: {}",
vm_cfg.pass_through_devices().len()
);
}

pub fn parse_vm_interrupt(vm_cfg: &mut AxVMConfig, dtb: &[u8]) {
Expand Down
Loading