Exemple #1
0
/**
 * Gets the physical address from the virtual address
 *
 * @param virt the virtual address to get the mapping for
 *
 * @return the physical address that it maps to or SYSERR if it does not exist
 */
void * get_phys_addr(void * virt) {
    struct mmu_L1_4k_desc * L1_table;
    struct mmu_L1_4k_desc * L1_desc;
    struct mmu_L2_4k_desc * L2_table;
    struct mmu_L2_4k_desc * L2_desc;

    //if the mmu is disabled, return the address as it will be treated as physical
    if(!mmu_is_enabled())
        return virt;

    //get the base of the page table
    L1_table = (struct mmu_L1_4k_desc *)get_page_table_addr();

    //get the L1 descriptor
    L1_desc = &(L1_table[((unsigned int)virt & 0xFFF00000) >> 20]);

    //check L1 description to make sure it is valid
    if(L1_desc->type == MMU_L1_NOMAP_TYPE)
        return (void *)SYSERR;

    //get the L2 table
    L2_table = (struct mmu_L2_4k_desc *)(L1_desc->L2_base_addr << 10);

    //get the L2 descriptor
    L2_desc = &(L2_table[((unsigned int)virt & 0x000FF000) >> 12]);

    //check L2 description to make sure it is valid
    if(L2_desc->type == MMU_L2_NOMAP_TYPE)
        return (void *)SYSERR;

    //return the physical address
    return (void *)((L2_desc->phy_base_addr << 12) | ((unsigned int)virt & 0x00000FFF));
}
lpaddr_t
platform_get_gic_cpu_address(void) {
    assert(mmu_is_enabled());
    return platform_get_private_region() + A15MPCORE_GICC_OFFSET;
}
lpaddr_t
platform_get_distributor_address(void) {
    assert(mmu_is_enabled());
    return platform_get_private_region() + A15MPCORE_GICD_OFFSET;
}