123ef2b33SLoGin use system_error::SystemError; 223ef2b33SLoGin 323ef2b33SLoGin use crate::{ 423ef2b33SLoGin driver::open_firmware::fdt::OpenFirmwareFdtDriver, 523ef2b33SLoGin init::boot_params, 623ef2b33SLoGin libs::align::page_align_up, 723ef2b33SLoGin mm::{mmio_buddy::mmio_pool, MemoryManagementArch, PhysAddr}, 823ef2b33SLoGin }; 923ef2b33SLoGin 1023ef2b33SLoGin impl OpenFirmwareFdtDriver { 1123ef2b33SLoGin #[allow(dead_code)] map_fdt(&self) -> Result<(), SystemError>1223ef2b33SLoGin pub unsafe fn map_fdt(&self) -> Result<(), SystemError> { 1323ef2b33SLoGin let bp_guard = boot_params().read(); 1423ef2b33SLoGin let fdt_size = bp_guard.arch.fdt_size; 1523ef2b33SLoGin let fdt_paddr = bp_guard.arch.fdt_paddr; 1623ef2b33SLoGin 1723ef2b33SLoGin let offset = fdt_paddr.data() & crate::arch::MMArch::PAGE_OFFSET_MASK; 1823ef2b33SLoGin let map_size = page_align_up(fdt_size + offset); 1923ef2b33SLoGin let map_paddr = PhysAddr::new(fdt_paddr.data() & crate::arch::MMArch::PAGE_MASK); 20*2eab6dd7S曾俊 // debug!( 2123ef2b33SLoGin // "map_fdt paddr: {:?}, map_pa: {:?},fdt_size: {}, size: {:?}", 2223ef2b33SLoGin // fdt_paddr, 2323ef2b33SLoGin // map_paddr, 2423ef2b33SLoGin // fdt_size, 2523ef2b33SLoGin // map_size 2623ef2b33SLoGin // ); 2723ef2b33SLoGin let mmio_guard = mmio_pool().create_mmio(map_size)?; 2823ef2b33SLoGin 2923ef2b33SLoGin // drop the boot params guard in order to avoid deadlock 3023ef2b33SLoGin drop(bp_guard); 31*2eab6dd7S曾俊 // debug!("map_fdt: map fdt to {:?}, size: {}", map_paddr, map_size); 3223ef2b33SLoGin mmio_guard.map_phys(map_paddr, map_size)?; 3323ef2b33SLoGin let mut bp_guard = boot_params().write(); 3423ef2b33SLoGin let vaddr = mmio_guard.vaddr() + offset; 3523ef2b33SLoGin 3623ef2b33SLoGin self.set_fdt_map_guard(Some(mmio_guard)); 3723ef2b33SLoGin bp_guard.arch.fdt_vaddr.replace(vaddr); 3823ef2b33SLoGin 3923ef2b33SLoGin return Ok(()); 4023ef2b33SLoGin } 4123ef2b33SLoGin } 42