From 01001c2aa2216c92603e1bdc334613e5adcacb04 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Fri, 21 Nov 2025 22:45:41 -0500 Subject: kern/amd64: mu: Add pmap unmap function Signed-off-by: Ian Moffett --- sys/arch/amd64/cpu/mmu.c | 21 +++++++++++++++++++++ sys/inc/mu/mmu.h | 9 +++++++++ sys/mu/mmu_stub.c | 10 ++++++++++ 3 files changed, 40 insertions(+) (limited to 'sys') diff --git a/sys/arch/amd64/cpu/mmu.c b/sys/arch/amd64/cpu/mmu.c index b709ee1..2be4b12 100644 --- a/sys/arch/amd64/cpu/mmu.c +++ b/sys/arch/amd64/cpu/mmu.c @@ -192,6 +192,27 @@ mu_pmap_map(struct mmu_vas *vas, uintptr_t pa, uintptr_t va, return 0; } +int +mu_pmap_unmap(struct mmu_vas *vas, uintptr_t va, pagesize_t ps) +{ + uintptr_t *pagetbl; + size_t index; + + if (vas == NULL) { + return -EINVAL; + } + + pagetbl = pmap_get_level(vas, va, false, PMAP_PML1); + if (pagetbl == NULL) { + return 0; + } + + index = pmap_get_index(va, PMAP_PML1); + pagetbl[index] = 0; + pmap_invlpg(va); + return 0; +} + int mu_pmap_readvas(struct mmu_vas *vas) { diff --git a/sys/inc/mu/mmu.h b/sys/inc/mu/mmu.h index da2a286..d9be17a 100644 --- a/sys/inc/mu/mmu.h +++ b/sys/inc/mu/mmu.h @@ -49,6 +49,15 @@ __strong int mu_pmap_map( uint16_t prot, pagesize_t ps ); +/* + * Destroy a virtual to physical address mapping + * + * @vas: Virtual addres space to unmap from + * @va: Virtual address to unmap + * @ps: Pagesize of region covered by virtual address + */ +__strong int mu_pmap_unmap(struct mmu_vas *vas, uintptr_t va, pagesize_t ps); + /* * Copy the current VAS leaving the user-side * zeroed diff --git a/sys/mu/mmu_stub.c b/sys/mu/mmu_stub.c index 586edd4..729303b 100644 --- a/sys/mu/mmu_stub.c +++ b/sys/mu/mmu_stub.c @@ -42,6 +42,16 @@ mu_pmap_map(struct mmu_vas *vas, uintptr_t pa, uintptr_t va, uint16_t prot, (void)ps; } +__weak int +mu_pmap_unmap(struct mmu_vas *vas, uintptr_t va, pagesize_t ps) +{ + (void)vas; + (void)va; + (void)ps; + + return 0; +} + __weak int mu_pmap_forkvas(struct mmu_vas *result) { -- cgit v1.2.3