@@ -7,7 +7,10 @@ use core::alloc::Layout;
7
7
use fdt_parser:: Fdt ;
8
8
use memory_addr:: MemoryAddr ;
9
9
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:: * ;
11
14
12
15
use alloc:: collections:: BTreeMap ;
13
16
use alloc:: sync:: Arc ;
@@ -125,6 +128,39 @@ pub fn get_vm_dtb_arc(vm_cfg: &AxVMConfig) -> Option<Arc<[u8]>> {
125
128
None
126
129
}
127
130
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
+
128
164
pub fn init_guest_vms ( ) {
129
165
GENERATED_DTB_CACHE . init_once ( Mutex :: new ( BTreeMap :: new ( ) ) ) ;
130
166
@@ -151,34 +187,9 @@ pub fn init_guest_vms() {
151
187
152
188
let mut vm_config = AxVMConfig :: from ( vm_create_config. clone ( ) ) ;
153
189
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) ;
182
193
183
194
// info!("after parse_vm_interrupt, crate VM[{}] with config: {:#?}", vm_config.id(), vm_config);
184
195
info ! ( "Creating VM[{}] {:?}" , vm_config. id( ) , vm_config. name( ) ) ;
0 commit comments