summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-07-09 14:24:02 -0400
committerIan Moffett <ian@osmora.org>2024-07-09 14:24:02 -0400
commit2b8dbfda5913761aa0bd42de9f9adf3a2a3bd4e5 (patch)
treef0c44bc714850f691ac104a015c0eee7989bd3ac /sys
parent6ff4b38d6378f36dc11acd6bee4c676f41462cc1 (diff)
kernel/amd64: Add function to set cache policy
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/amd64/amd64/pmap.c29
-rw-r--r--sys/include/vm/pmap.h10
2 files changed, 39 insertions, 0 deletions
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;
+}
diff --git a/sys/include/vm/pmap.h b/sys/include/vm/pmap.h
index 4cd334c..741eaf2 100644
--- a/sys/include/vm/pmap.h
+++ b/sys/include/vm/pmap.h
@@ -39,6 +39,10 @@
#define PROT_EXEC BIT(1) /* Executable */
#define PROT_USER BIT(2) /* User accessible */
+/* Caching types */
+#define VM_CACHE_UC 0x00000U /* Uncachable */
+#define VM_CACHE_WT 0x00001U /* Write-through */
+
typedef uint32_t vm_prot_t;
/*
@@ -71,4 +75,10 @@ int pmap_map(struct vas vas, vaddr_t va, paddr_t pa, vm_prot_t prot);
*/
int pmap_unmap(struct vas vas, vaddr_t va);
+/*
+ * Mark a virtual address with a specific
+ * caching type.
+ */
+int pmap_set_cache(struct vas vas, vaddr_t va, int type);
+
#endif /* !_VM_PMAP_H_ */