fn map_physical_persistent_memory() {
    use atopology::MemoryType;
    let desc_iter = atopology::MACHINE_TOPOLOGY.persistent_memory();
    let kcb = kcb::get_kcb();
    for entry in desc_iter {
        if entry.phys_start == 0x0 {
            debug!("Don't map memory entry at physical zero? {:#?}", entry);
            continue;
        }

        // Compute physical base and size for the region we're about to map
        let phys_range_start = PAddr::from(entry.phys_start);
        let size = entry.page_count as usize * BASE_PAGE_SIZE;
        let phys_range_end =
            PAddr::from(entry.phys_start + entry.page_count * BASE_PAGE_SIZE as u64);

        if phys_range_start.as_u64() <= 0xfee00000u64 && phys_range_end.as_u64() >= 0xfee00000u64 {
            debug!("{:?} covers APIC range, ignore for now.", entry);
            continue;
        }

        let rights: MapAction = match entry.ty {
            MemoryType::PERSISTENT_MEMORY => MapAction::ReadWriteKernel,
            _ => {
                error!("Unknown memory type, what should we do? {:#?}", entry);
                MapAction::None
            }
        };

        debug!(
            "Doing {:?} on {:#x} -- {:#x}",
            rights, phys_range_start, phys_range_end
        );
        if rights != MapAction::None && entry.ty == MemoryType::PERSISTENT_MEMORY {
            kcb.arch
                .init_vspace()
                .map_identity(phys_range_start, size, rights)
                .expect("Unable to add PMem address to user-space");

            kcb.arch
                .init_vspace()
                .map_identity_with_offset(PAddr::from(KERNEL_BASE), phys_range_start, size, rights)
                .expect("Unable to add PMem address to Kernel-space");
        }
    }
}
/// Map the persistent memory addresses to the vspace.
///
/// # TODO
/// This is a temporary hack until the bootloader shows us the persistent regions
/// when we query the uefi memory map. For some reason they don't show up with
/// current qemu edk2 OVMF builds. So we query ACPI directly here to find them.
Map the persistent memory addresses to the vspace.
Map the persistent memory addresses to the vspace .
fn map_physical_persistent_memory() {
    use atopology::MemoryType;
    let desc_iter = atopology::MACHINE_TOPOLOGY.persistent_memory();
    let kcb = kcb::get_kcb();
    for entry in desc_iter {
        if entry.phys_start == 0x0 {
            debug!("Don't map memory entry at physical zero? {:#?}", entry);
            continue;
        }
        // Compute physical base and size for the region we're about to map
        let phys_range_start = PAddr::from(entry.phys_start);
        let size = entry.page_count as usize * BASE_PAGE_SIZE;
        let phys_range_end =
            PAddr::from(entry.phys_start + entry.page_count * BASE_PAGE_SIZE as u64);
        if phys_range_start.as_u64() <= 0xfee00000u64 && phys_range_end.as_u64() >= 0xfee00000u64 {
            debug!("{:?} covers APIC range, ignore for now.", entry);
            continue;
        }
        let rights: MapAction = match entry.ty {
            MemoryType::PERSISTENT_MEMORY => MapAction::ReadWriteKernel,
            _ => {
                error!("Unknown memory type, what should we do? {:#?}", entry);
                MapAction::None
            }
        };
        debug!(
            "Doing {:?} on {:#x} -- {:#x}",
            rights, phys_range_start, phys_range_end
        );
        if rights != MapAction::None && entry.ty == MemoryType::PERSISTENT_MEMORY {
            kcb.arch
                .init_vspace()
                .map_identity(phys_range_start, size, rights)
                .expect("Unable to add PMem address to user-space");
            kcb.arch
                .init_vspace()
                .map_identity_with_offset(PAddr::from(KERNEL_BASE), phys_range_start, size, rights)
                .expect("Unable to add PMem address to Kernel-space");
        }
    }
}
fn map_physical_persistent_memory ( ) { use atopology :: MemoryType ; let desc_iter = atopology :: MACHINE_TOPOLOGY . persistent_memory ( ) ; let kcb = kcb :: get_kcb ( ) ; for entry in desc_iter { if entry . phys_start == 0x0 { debug ! ( " " entry ) ; continue ; } // Compute physical base and size for the region we're about to map let phys_range_start = PAddr :: from ( entry . phys_start ) ; let size = entry . page_count as usize * BASE_PAGE_SIZE ; let phys_range_end = PAddr :: from ( entry . phys_start + entry . page_count * BASE_PAGE_SIZE as u64 ) ; if phys_range_start . as_u64 ( ) <= 0xfee00000u64 && phys_range_end . as_u64 ( ) >= 0xfee00000u64 { debug ! ( " " entry ) ; continue ; } let rights : MapAction = match entry . ty { MemoryType :: PERSISTENT_MEMORY => MapAction :: ReadWriteKernel , _ => { error ! ( " " entry ) ; MapAction :: None } } ; debug ! ( " " rights phys_range_start phys_range_end ) ; if rights != MapAction :: None && entry . ty == MemoryType :: PERSISTENT_MEMORY { kcb . arch . init_vspace ( ) . map_identity ( phys_range_start , size , rights ) . expect ( " " ) ; kcb . arch . init_vspace ( ) . map_identity_with_offset ( PAddr :: from ( KERNEL_BASE ) , phys_range_start , size , rights ) . expect ( " " ) ; } } }
Map the persistent memory addresses to the vspace.
Map the persistent memory addresses to the vspace .
todo
This is a temporary hack until the bootloader shows us the persistent regions
when we query the uefi memory map. For some reason they don't show up with
current qemu edk2 OVMF builds. So we query ACPI directly here to find them.
This is a temporary hack until the bootloader shows us the persistent regions when we query the uefi memory map . For some reason they don ' t show up with current qemu edk2 OVMF builds . So we query ACPI directly here to find them .