Skip to content

Commit 007180b

Browse files
author
szy
committed
add cfg
1 parent 63a1c4f commit 007180b

File tree

3 files changed

+46
-30
lines changed

3 files changed

+46
-30
lines changed

doc/FDT_Configuration_Guide.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
本文档详细说明了在 AxVisor 中如何配置和使用设备树(FDT)来生成客户机 VM 的设备树。
44

5+
本文档所述功能只在aarch64 架构下支持。
6+
57
## 1. 概述
68

79
AxVisor 支持两种方式生成客户机 VM 的设备树:
810

911
1. **使用预定义的设备树文件**:通过 [kernel] 部分的 `dtb_path` 指定设备树文件路径
10-
2. **动态生成设备树**:当 `dtb_path` 为空时,根据配置文件中的参数动态生成设备树
12+
2. **动态生成设备树**:当 `dtb_path` 字段未使用时,根据配置文件中的参数动态生成设备树
1113

1214
无论采用哪种方式,CPU 节点和内存节点都会根据配置进行更新。
1315

src/vmm/config.rs

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use core::alloc::Layout;
77
use fdt_parser::Fdt;
88
use memory_addr::MemoryAddr;
99

10-
use crate::vmm::{VM, fdt::*, images::ImageLoader, vm_list::push_vm};
10+
use crate::vmm::{VM, images::ImageLoader, vm_list::push_vm};
11+
12+
#[cfg(target_arch = "aarch64")]
13+
use crate::vmm::fdt::*;
1114

1215
use alloc::collections::BTreeMap;
1316
use alloc::sync::Arc;
@@ -125,6 +128,39 @@ pub fn get_vm_dtb_arc(vm_cfg: &AxVMConfig) -> Option<Arc<[u8]>> {
125128
None
126129
}
127130

131+
/// Handle all FDT-related operations for aarch64 architecture
132+
#[cfg(target_arch = "aarch64")]
133+
fn handle_fdt_operations(vm_config: &mut AxVMConfig, vm_create_config: &AxVMCrateConfig) {
134+
let host_fdt_bytes = get_host_fdt();
135+
let host_fdt = Fdt::from_bytes(host_fdt_bytes)
136+
.map_err(|e| format!("Failed to parse FDT: {:#?}", e))
137+
.expect("Failed to parse FDT");
138+
set_phys_cpu_sets(vm_config, &host_fdt, vm_create_config);
139+
140+
if let Some(provided_dtb) = get_developer_provided_dtb(vm_config, vm_create_config) {
141+
info!("VM[{}] found DTB , parsing...", vm_config.id());
142+
update_provided_fdt(&provided_dtb, host_fdt_bytes, vm_create_config);
143+
} else {
144+
info!(
145+
"VM[{}] DTB not found, generating based on the configuration file.",
146+
vm_config.id()
147+
);
148+
setup_guest_fdt_from_vmm(host_fdt_bytes, vm_config, vm_create_config);
149+
}
150+
151+
// Overlay VM config with the given DTB.
152+
if let Some(dtb_arc) = get_vm_dtb_arc(vm_config) {
153+
let dtb = dtb_arc.as_ref();
154+
parse_passthrough_devices_address(vm_config, dtb);
155+
parse_vm_interrupt(vm_config, dtb);
156+
} else {
157+
error!(
158+
"VM[{}] DTB not found in memory, skipping...",
159+
vm_config.id()
160+
);
161+
}
162+
}
163+
128164
pub fn init_guest_vms() {
129165
GENERATED_DTB_CACHE.init_once(Mutex::new(BTreeMap::new()));
130166

@@ -151,34 +187,9 @@ pub fn init_guest_vms() {
151187

152188
let mut vm_config = AxVMConfig::from(vm_create_config.clone());
153189

154-
let host_fdt_bytes = get_host_fdt();
155-
let host_fdt = Fdt::from_bytes(host_fdt_bytes)
156-
.map_err(|e| format!("Failed to parse FDT: {:#?}", e))
157-
.expect("Failed to parse FDT");
158-
set_phys_cpu_sets(&mut vm_config, &host_fdt, &vm_create_config);
159-
160-
if let Some(provided_dtb) = get_developer_provided_dtb(&vm_config, &vm_create_config) {
161-
info!("VM[{}] found DTB , parsing...", vm_config.id());
162-
update_provided_fdt(&provided_dtb, host_fdt_bytes, &vm_create_config);
163-
} else {
164-
info!(
165-
"VM[{}] DTB not found, generating based on the configuration file.",
166-
vm_config.id()
167-
);
168-
setup_guest_fdt_from_vmm(host_fdt_bytes, &mut vm_config, &vm_create_config);
169-
}
170-
171-
// Overlay VM config with the given DTB.
172-
if let Some(dtb_arc) = get_vm_dtb_arc(&vm_config) {
173-
let dtb = dtb_arc.as_ref();
174-
parse_passthrough_devices_address(&mut vm_config, dtb);
175-
parse_vm_interrupt(&mut vm_config, dtb);
176-
} else {
177-
error!(
178-
"VM[{}] DTB not found in memory, skipping...",
179-
vm_config.id()
180-
);
181-
}
190+
// Handle FDT-related operations for aarch64
191+
#[cfg(target_arch = "aarch64")]
192+
handle_fdt_operations(&mut vm_config, &vm_create_config);
182193

183194
// info!("after parse_vm_interrupt, crate VM[{}] with config: {:#?}", vm_config.id(), vm_config);
184195
info!("Creating VM[{}] {:?}", vm_config.id(), vm_config.name());

src/vmm/images/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::hal::CacheOp;
1111
use crate::vmm::VMRef;
1212
use crate::vmm::config::{config, get_vm_dtb_arc};
1313

14+
#[cfg(target_arch = "aarch64")]
1415
use crate::vmm::fdt::update_fdt;
1516

1617
mod linux;
@@ -113,6 +114,7 @@ impl ImageLoader {
113114
Byte::from(dtb_slice.len())
114115
);
115116

117+
#[cfg(target_arch = "aarch64")]
116118
update_fdt(
117119
self.dtb_load_gpa.unwrap(),
118120
NonNull::new(dtb_slice.as_ptr() as *mut u8).unwrap(),
@@ -259,6 +261,7 @@ mod fs {
259261
Byte::from(dtb_slice.len())
260262
);
261263

264+
#[cfg(target_arch = "aarch64")]
262265
update_fdt(
263266
loader.dtb_load_gpa.unwrap(),
264267
NonNull::new(dtb_slice.as_ptr() as *mut u8).unwrap(),

0 commit comments

Comments
 (0)