@@ -52,7 +52,9 @@ const IRQ_TYPE_LEVEL_HI: u32 = 4;
5252/// Creates the flattened device tree for this aarch64 microVM.
5353pub fn create_fdt < T : DeviceInfoForFDT + Clone + Debug , M : GuestMemory > (
5454 guest_mem : & M ,
55- vcpu_mpidr : Vec < u64 > ,
55+ // field 0: boot_onlined, decides whether to online this cpu at boot
56+ // field 1: vcpu_mpidr
57+ vcpu_state : Vec < ( u32 , u64 ) > ,
5658 cmdline : & str ,
5759 device_info : Option < & HashMap < ( DeviceType , String ) , T > > ,
5860 gic_device : & Box < dyn GICDevice > ,
@@ -75,7 +77,7 @@ pub fn create_fdt<T: DeviceInfoForFDT + Clone + Debug, M: GuestMemory>(
7577 // This is not mandatory but we use it to point the root node to the node
7678 // containing description of the interrupt controller for this VM.
7779 fdt. property_u32 ( "interrupt-parent" , GIC_PHANDLE ) ?;
78- create_cpu_nodes ( & mut fdt, & vcpu_mpidr ) ?;
80+ create_cpu_nodes ( & mut fdt, & vcpu_state ) ?;
7981 create_memory_node ( & mut fdt, guest_mem) ?;
8082 create_chosen_node ( & mut fdt, cmdline, initrd) ?;
8183 create_gic_node ( & mut fdt, gic_device. as_ref ( ) ) ?;
@@ -98,15 +100,15 @@ pub fn create_fdt<T: DeviceInfoForFDT + Clone + Debug, M: GuestMemory>(
98100}
99101
100102// Following are the auxiliary function for creating the different nodes that we append to our FDT.
101- fn create_cpu_nodes ( fdt : & mut FdtWriter , vcpu_mpidr : & [ u64 ] ) -> Result < ( ) > {
103+ fn create_cpu_nodes ( fdt : & mut FdtWriter , vcpu_state : & [ ( u32 , u64 ) ] ) -> Result < ( ) > {
102104 // See https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/arm/cpus.yaml.
103105 let cpus_node = fdt. begin_node ( "cpus" ) ?;
104106 // As per documentation, on ARM v8 64-bit systems value should be set to 2.
105107 fdt. property_u32 ( "#address-cells" , 0x02 ) ?;
106108 fdt. property_u32 ( "#size-cells" , 0x0 ) ?;
107- let num_cpus = vcpu_mpidr . len ( ) ;
109+ let num_cpus = vcpu_state . len ( ) ;
108110
109- for ( cpu_index, iter) in vcpu_mpidr . iter ( ) . enumerate ( ) . take ( num_cpus) {
111+ for ( cpu_index, iter) in vcpu_state . iter ( ) . enumerate ( ) . take ( num_cpus) {
110112 let cpu_name = format ! ( "cpu@{cpu_index:x}" ) ;
111113 let cpu_node = fdt. begin_node ( & cpu_name) ?;
112114 fdt. property_string ( "device_type" , "cpu" ) ?;
@@ -115,9 +117,12 @@ fn create_cpu_nodes(fdt: &mut FdtWriter, vcpu_mpidr: &[u64]) -> Result<()> {
115117 // This is required on armv8 64-bit. See aforementioned documentation.
116118 fdt. property_string ( "enable-method" , "psci" ) ?;
117119 }
120+ // boot-onlined attribute is used to indicate whether this cpu should be onlined at boot.
121+ // 0 means offline, 1 means online.
122+ fdt. property_u32 ( "boot-onlined" , iter. 0 ) ?;
118123 // Set the field to first 24 bits of the MPIDR - Multiprocessor Affinity Register.
119124 // See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0488c/BABHBJCI.html.
120- fdt. property_u64 ( "reg" , iter & 0x7FFFFF ) ?;
125+ fdt. property_u64 ( "reg" , iter. 1 & 0x7FFFFF ) ?;
121126 fdt. end_node ( cpu_node) ?;
122127 }
123128 fdt. end_node ( cpus_node) ?;
@@ -497,7 +502,7 @@ mod tests {
497502 let vpmu_feature = VpmuFeatureLevel :: Disabled ;
498503 assert ! ( create_fdt(
499504 & mem,
500- vec![ 0 ] ,
505+ vec![ ( 1 , 0 ) ] ,
501506 "console=tty0" ,
502507 Some ( & dev_info) ,
503508 & gic,
@@ -517,7 +522,7 @@ mod tests {
517522 let vpmu_feature = VpmuFeatureLevel :: Disabled ;
518523 let dtb = create_fdt (
519524 & mem,
520- vec ! [ 0 ] ,
525+ vec ! [ ( 1 , 0 ) ] ,
521526 "console=tty0" ,
522527 None :: < & HashMap < ( DeviceType , String ) , MMIODeviceInfo > > ,
523528 & gic,
@@ -554,7 +559,7 @@ mod tests {
554559 let vpmu_feature = VpmuFeatureLevel :: Disabled ;
555560 let dtb = create_fdt (
556561 & mem,
557- vec ! [ 0 ] ,
562+ vec ! [ ( 1 , 0 ) ] ,
558563 "console=tty0" ,
559564 None :: < & HashMap < ( DeviceType , String ) , MMIODeviceInfo > > ,
560565 & gic,
@@ -591,7 +596,7 @@ mod tests {
591596 let vpmu_feature = VpmuFeatureLevel :: FullyEnabled ;
592597 let dtb = create_fdt (
593598 & mem,
594- vec ! [ 0 ] ,
599+ vec ! [ ( 1 , 0 ) ] ,
595600 "console=tty0" ,
596601 None :: < & std:: collections:: HashMap < ( DeviceType , std:: string:: String ) , MMIODeviceInfo > > ,
597602 & gic,
0 commit comments