| 63 | /// Creates the flattened device tree for this riscv64 VM. |
| 64 | #[allow(clippy::too_many_arguments)] |
| 65 | pub fn create_fdt<T: DeviceInfoForFdt + Clone + Debug, S: ::std::hash::BuildHasher>( |
| 66 | guest_mem: &GuestMemoryMmap, |
| 67 | cmdline: &str, |
| 68 | num_vcpu: u32, |
| 69 | isa_string: &str, |
| 70 | device_info: &HashMap<(DeviceType, String), T, S>, |
| 71 | aia_device: &Arc<Mutex<dyn Vaia>>, |
| 72 | initrd: &Option<InitramfsConfig>, |
| 73 | pci_space_info: &[PciSpaceInfo], |
| 74 | ) -> FdtWriterResult<Vec<u8>> { |
| 75 | // Allocate stuff necessary for the holding the blob. |
| 76 | let mut fdt = FdtWriter::new()?; |
| 77 | |
| 78 | // For an explanation why these nodes were introduced in the blob take a look at |
| 79 | // https://github.com/devicetree-org/devicetree-specification/releases/tag/v0.4 |
| 80 | // In chapter 3. |
| 81 | |
| 82 | // Header or the root node as per above mentioned documentation. |
| 83 | let root_node = fdt.begin_node("")?; |
| 84 | fdt.property_string("compatible", "linux,dummy-virt")?; |
| 85 | // For info on #address-cells and size-cells resort to Table 3.1 Root Node |
| 86 | // Properties |
| 87 | fdt.property_u32("#address-cells", ADDRESS_CELLS)?; |
| 88 | fdt.property_u32("#size-cells", SIZE_CELLS)?; |
| 89 | create_cpu_nodes(&mut fdt, num_vcpu, isa_string)?; |
| 90 | create_memory_node(&mut fdt, guest_mem)?; |
| 91 | create_chosen_node(&mut fdt, cmdline, initrd)?; |
| 92 | create_aia_node(&mut fdt, aia_device)?; |
| 93 | create_devices_node(&mut fdt, device_info)?; |
| 94 | create_pci_nodes(&mut fdt, pci_space_info)?; |
| 95 | |
| 96 | // End Header node. |
| 97 | fdt.end_node(root_node)?; |
| 98 | |
| 99 | let fdt_final = fdt.finish()?; |
| 100 | |
| 101 | Ok(fdt_final) |
| 102 | } |
| 103 | |
| 104 | pub fn write_fdt_to_memory(fdt_final: &[u8], guest_mem: &GuestMemoryMmap) -> Result<()> { |
| 105 | // Write FDT to memory. |