map_range() id-maps pages. Pages may either be uncached (e.g., MMIO) or cached (e.g., RAM).
On arm and arm64, we only use two level paging. On both architectures, we will enter level one, IOW we skip level zero on arm64. The first level page table (the page directory) is allocated statically, the second level page tables (page middle directores, which have 512 entries) will dynamically be allocated as needed. As we only use level one and two, the paging granularity well be 2MiB (HUGE_PAGE_SIZE), same as for x86. Signed-off-by: Ralf Ramsauer <[email protected]> --- inmates/lib/arm-common/include/inmate.h | 2 ++ inmates/lib/arm-common/setup.c | 42 +++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/inmates/lib/arm-common/include/inmate.h b/inmates/lib/arm-common/include/inmate.h index 1fe3c849..eb24db49 100644 --- a/inmates/lib/arm-common/include/inmate.h +++ b/inmates/lib/arm-common/include/inmate.h @@ -104,6 +104,8 @@ u64 timer_get_ticks(void); u64 timer_ticks_to_ns(u64 ticks); void timer_start(u64 timeout); +extern u64 __attribute__((aligned(4096))) page_directory[4]; + #include <arch/inmate.h> #include "../inmate_common.h" diff --git a/inmates/lib/arm-common/setup.c b/inmates/lib/arm-common/setup.c index f79fd736..073101b3 100644 --- a/inmates/lib/arm-common/setup.c +++ b/inmates/lib/arm-common/setup.c @@ -37,6 +37,48 @@ */ #include <inmate.h> +#include <mach.h> +#include <asm/sysregs.h> + +u64 __attribute__((aligned(4096))) page_directory[4]; + +void map_range(void *start, unsigned long size, enum map_type map_type) +{ + u64 vaddr, pmd_entry; + unsigned pgd_index; + u64 *pmd; + + vaddr = (unsigned long)start; + + size += (vaddr & ~HUGE_PAGE_MASK) + HUGE_PAGE_SIZE - 1; + size &= HUGE_PAGE_MASK; + + while (size) { + pgd_index = PGD_INDEX(vaddr); + if (!(page_directory[pgd_index] & LONG_DESC_TABLE)) { + pmd = alloc(PAGE_SIZE, PAGE_SIZE); + memset(pmd, 0, PAGE_SIZE); + page_directory[pgd_index] = + (unsigned long)pmd | LONG_DESC_TABLE; + } else { + pmd = (u64*)(unsigned long) + (page_directory[pgd_index] & ~LONG_DESC_TABLE); + } + + pmd_entry = vaddr & HUGE_PAGE_MASK; + pmd_entry |= LATTR_AF | LATTR_INNER_SHAREABLE | \ + LATTR_AP_RW_EL1 | LONG_DESC_BLOCK; + if (map_type == MAP_CACHED) + pmd_entry |= LATTR_MAIR(0); + else + pmd_entry |= LATTR_MAIR(1); + + pmd[PMD_INDEX(vaddr)] = pmd_entry; + + size -= HUGE_PAGE_SIZE; + vaddr += HUGE_PAGE_SIZE; + } +} void arch_init_early(void) { -- 2.17.0 -- You received this message because you are subscribed to the Google Groups "Jailhouse" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
