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