HelenOS sources
This source file includes following definitions.
- tlb_arch_init
- dtlb_insert_mapping
- dtlb_pte_copy
- itlb_pte_copy
- fast_instruction_access_mmu_miss
- fast_data_access_mmu_miss
- fast_data_access_protection
- tlb_print
- describe_dmmu_fault
- tlb_invalidate_all
- tlb_invalidate_asid
- tlb_invalidate_pages
#include <mm/tlb.h>
#include <mm/as.h>
#include <mm/asid.h>
#include <arch/sun4v/hypercall.h>
#include <arch/mm/frame.h>
#include <arch/mm/page.h>
#include <arch/mm/tte.h>
#include <arch/mm/tlb.h>
#include <arch/interrupt.h>
#include <assert.h>
#include <interrupt.h>
#include <arch.h>
#include <stdio.h>
#include <log.h>
#include <typedefs.h>
#include <config.h>
#include <arch/trap/trap.h>
#include <arch/trap/exception.h>
#include <panic.h>
#include <arch/asm.h>
#include <arch/cpu.h>
#include <arch/mm/pagesize.h>
#include <genarch/mm/page_ht.h>
#ifdef CONFIG_TSB
#include <arch/mm/tsb.h>
#endif
static void itlb_pte_copy(pte_t *);
static void dtlb_pte_copy(pte_t *, bool);
#define DMISS_ADDRESS(page_and_ctx) (((page_and_ctx) >> 13) << 13)
#define DMISS_CONTEXT(page_and_ctx) ((page_and_ctx) & 0x1fff)
static const char *fault_types[] = {
"unknown",
"fast miss",
"fast protection",
"MMU miss",
"invalid RA",
"privileged violation",
"protection violation",
"NFO access",
"so page/NFO side effect",
"invalid VA",
"invalid ASI",
"nc atomic",
"privileged action",
"unknown",
"unaligned access",
"invalid page size"
};
extern mmu_fault_status_area_t mmu_fsas[MAX_NUM_STRANDS];
void tlb_arch_init(void)
{
tlb_invalidate_all();
}
void dtlb_insert_mapping(uintptr_t page, uintptr_t frame, int pagesize,
bool locked, bool cacheable)
{
tte_data_t data;
data.value = 0;
data.v = true;
data.nfo = false;
data.ra = frame >> FRAME_WIDTH;
data.ie = false;
data.e = false;
data.cp = cacheable;
#ifdef CONFIG_VIRT_IDX_DCACHE
data.cv = cacheable;
#endif
data.p = true;
data.x = false;
data.w = true;
data.size = pagesize;
if (locked) {
__hypercall_fast4(
MMU_MAP_PERM_ADDR, page, 0, data.value, MMU_FLAG_DTLB);
} else {
__hypercall_hyperfast(
page, ASID_KERNEL, data.value, MMU_FLAG_DTLB, 0,
MMU_MAP_ADDR);
}
}
void dtlb_pte_copy(pte_t *t, bool ro)
{
tte_data_t data;
data.value = 0;
data.v = true;
data.nfo = false;
data.ra = (t->frame) >> FRAME_WIDTH;
data.ie = false;
data.e = false;
data.cp = t->c;
#ifdef CONFIG_VIRT_IDX_DCACHE
data.cv = t->c;
#endif
data.p = t->k;
data.x = false;
data.w = ro ? false : t->w;
data.size = PAGESIZE_8K;
__hypercall_hyperfast(
t->page, t->as->asid, data.value, MMU_FLAG_DTLB, 0, MMU_MAP_ADDR);
}
void itlb_pte_copy(pte_t *t)
{
tte_data_t data;
data.value = 0;
data.v = true;
data.nfo = false;
data.ra = (t->frame) >> FRAME_WIDTH;
data.ie = false;
data.e = false;
data.cp = t->c;
data.cv = false;
data.p = t->k;
data.x = true;
data.w = false;
data.size = PAGESIZE_8K;
__hypercall_hyperfast(
t->page, t->as->asid, data.value, MMU_FLAG_ITLB, 0, MMU_MAP_ADDR);
}
void fast_instruction_access_mmu_miss(unsigned int tt, istate_t *istate)
{
uintptr_t va = ALIGN_DOWN(istate->tpc, PAGE_SIZE);
pte_t t;
bool found = page_mapping_find(AS, va, true, &t);
if (found && PTE_EXECUTABLE(&t)) {
assert(t.p);
t.a = true;
itlb_pte_copy(&t);
#ifdef CONFIG_TSB
itsb_pte_copy(&t);
#endif
page_mapping_update(AS, va, true, &t);
} else {
as_page_fault(va, PF_ACCESS_EXEC, istate);
}
}
void fast_data_access_mmu_miss(unsigned int tt, istate_t *istate)
{
pte_t t;
uintptr_t va = DMISS_ADDRESS(istate->tlb_tag_access);
uint16_t ctx = DMISS_CONTEXT(istate->tlb_tag_access);
as_t *as = AS;
if (ctx == ASID_KERNEL) {
if (va == 0) {
panic("NULL pointer dereference.");
} else if (va >= end_of_identity) {
as = AS_KERNEL;
} else {
panic("Unexpected kernel page fault.");
}
}
bool found = page_mapping_find(as, va, true, &t);
if (found) {
assert(t.p);
t.a = true;
dtlb_pte_copy(&t, true);
#ifdef CONFIG_TSB
dtsb_pte_copy(&t, true);
#endif
page_mapping_update(as, va, true, &t);
} else {
as_page_fault(va, PF_ACCESS_READ, istate);
}
}
void fast_data_access_protection(unsigned int tt, istate_t *istate)
{
pte_t t;
uintptr_t va = DMISS_ADDRESS(istate->tlb_tag_access);
uint16_t ctx = DMISS_CONTEXT(istate->tlb_tag_access);
as_t *as = AS;
if (ctx == ASID_KERNEL)
as = AS_KERNEL;
bool found = page_mapping_find(as, va, true, &t);
if (found && PTE_WRITABLE(&t)) {
assert(t.p);
t.a = true;
t.d = true;
mmu_demap_page(va, ctx, MMU_FLAG_DTLB);
dtlb_pte_copy(&t, false);
#ifdef CONFIG_TSB
dtsb_pte_copy(&t, false);
#endif
page_mapping_update(as, va, true, &t);
} else {
as_page_fault(va, PF_ACCESS_WRITE, istate);
}
}
void tlb_print(void)
{
log(LF_ARCH, LVL_WARN, "Operation not possible on Niagara.");
}
void describe_dmmu_fault(void)
{
uint64_t myid;
__hypercall_fast_ret1(0, 0, 0, 0, 0, CPU_MYID, &myid);
assert(mmu_fsas[myid].dft < 16);
printf("condition which caused the fault: %s\n",
fault_types[mmu_fsas[myid].dft]);
}
void tlb_invalidate_all(void)
{
uint64_t errno = __hypercall_fast3(MMU_DEMAP_ALL, 0, 0,
MMU_FLAG_DTLB | MMU_FLAG_ITLB);
if (errno != HV_EOK)
panic("Error code = %" PRIu64 ".\n", errno);
}
void tlb_invalidate_asid(asid_t asid)
{
nucleus_enter();
__hypercall_fast4(MMU_DEMAP_CTX, 0, 0, asid,
MMU_FLAG_ITLB | MMU_FLAG_DTLB);
nucleus_leave();
}
void tlb_invalidate_pages(asid_t asid, uintptr_t page, size_t cnt)
{
unsigned int i;
nucleus_enter();
for (i = 0; i < cnt; i++) {
__hypercall_fast5(MMU_DEMAP_PAGE, 0, 0, page + i * PAGE_SIZE,
asid, MMU_FLAG_DTLB | MMU_FLAG_ITLB);
}
nucleus_leave();
}
HelenOS homepage, sources at GitHub