1 use system_error::SystemError; 2 3 use crate::{ 4 driver::open_firmware::fdt::OpenFirmwareFdtDriver, 5 init::boot_params, 6 libs::align::page_align_up, 7 mm::{mmio_buddy::mmio_pool, MemoryManagementArch, PhysAddr}, 8 }; 9 10 impl OpenFirmwareFdtDriver { 11 #[allow(dead_code)] 12 pub unsafe fn map_fdt(&self) -> Result<(), SystemError> { 13 let bp_guard = boot_params().read(); 14 let fdt_size = bp_guard.arch.fdt_size; 15 let fdt_paddr = bp_guard.arch.fdt_paddr; 16 17 let offset = fdt_paddr.data() & crate::arch::MMArch::PAGE_OFFSET_MASK; 18 let map_size = page_align_up(fdt_size + offset); 19 let map_paddr = PhysAddr::new(fdt_paddr.data() & crate::arch::MMArch::PAGE_MASK); 20 // kdebug!( 21 // "map_fdt paddr: {:?}, map_pa: {:?},fdt_size: {}, size: {:?}", 22 // fdt_paddr, 23 // map_paddr, 24 // fdt_size, 25 // map_size 26 // ); 27 let mmio_guard = mmio_pool().create_mmio(map_size)?; 28 29 // drop the boot params guard in order to avoid deadlock 30 drop(bp_guard); 31 mmio_guard.map_phys(map_paddr, map_size)?; 32 let mut bp_guard = boot_params().write(); 33 let vaddr = mmio_guard.vaddr() + offset; 34 35 self.set_fdt_map_guard(Some(mmio_guard)); 36 bp_guard.arch.fdt_vaddr.replace(vaddr); 37 38 return Ok(()); 39 } 40 } 41