From 2b8dbfda5913761aa0bd42de9f9adf3a2a3bd4e5 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Tue, 9 Jul 2024 14:24:02 -0400 Subject: kernel/amd64: Add function to set cache policy Signed-off-by: Ian Moffett --- sys/arch/amd64/amd64/pmap.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'sys/arch/amd64') diff --git a/sys/arch/amd64/amd64/pmap.c b/sys/arch/amd64/amd64/pmap.c index 0f41e7a..1d95ec4 100644 --- a/sys/arch/amd64/amd64/pmap.c +++ b/sys/arch/amd64/amd64/pmap.c @@ -274,3 +274,32 @@ pmap_unmap(struct vas vas, vaddr_t va) { return pmap_update_tbl(vas, va, 0); } + +int +pmap_set_cache(struct vas vas, vaddr_t va, int type) +{ + uintptr_t *tbl; + int status; + size_t idx; + + if ((status = pmap_get_tbl(vas, va, false, &tbl)) != 0) + return status; + + idx = pmap_get_level_index(1, va); + + /* Set the caching policy */ + 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: + return -EINVAL; + } + + return 0; +} -- cgit v1.2.3