From 312b5687c905a7614cdd1e5080a69bd12cbc95b4 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sun, 2 Jun 2024 21:42:28 -0400 Subject: kernel/amd64: pmap: Add helper to set cache policy Signed-off-by: Ian Moffett --- sys/arch/amd64/amd64/pmap.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'sys/arch') diff --git a/sys/arch/amd64/amd64/pmap.c b/sys/arch/amd64/amd64/pmap.c index e95471b..9443727 100644 --- a/sys/arch/amd64/amd64/pmap.c +++ b/sys/arch/amd64/amd64/pmap.c @@ -254,6 +254,38 @@ pmap_modify_tbl(struct vm_ctx *ctx, struct vas vas, vaddr_t va, size_t val) return 0; } +int +pmap_set_cache(struct vm_ctx *ctx, struct vas vas, vaddr_t va, int type) +{ + uintptr_t *tbl; + int status; + size_t idx; + + if ((status = pmap_get_tbl(ctx, vas, va, false, &tbl)) != 0) { + return status; + } + + idx = pmap_get_level_index(1, va); + + /* Set the policy based on the type */ + switch (type) { + case VM_CACHE_UC: + tbl[idx] |= PTE_PCD; + tbl[idx] &= ~(PTE_PWT); + break; + case VM_CACHE_WT: + tbl[idx] &= ~(PTE_PCD); + tbl[idx] |= PTE_PWT; + break; + default: + /* Invalid type */ + return 1; + } + + pmap_flush(va); + return 0; +} + int pmap_map(struct vm_ctx *ctx, struct vas vas, vaddr_t va, paddr_t pa, vm_prot_t prot) -- cgit v1.2.3