sp1: vm: Add function to unmap vm regions

Signed-off-by: Ian Moffett <ian@mirocom.org>
This commit is contained in:
2026-04-26 00:22:01 -04:00
parent 9fb213cc41
commit 336d6e2c52
2 changed files with 33 additions and 5 deletions
+23 -5
View File
@@ -51,15 +51,33 @@ mm_vm_map(struct mmu_vfr *vfr, struct vm_map *mapping, int prot)
for (size_t i = 0; i < len; i += gran) { for (size_t i = 0; i < len; i += gran) {
status = mu_mmu_map(vfr, vma + i, pma + i, prot, mapping->ps); status = mu_mmu_map(vfr, vma + i, pma + i, prot, mapping->ps);
/* /* Destroy what we created on failure */
* TODO: We need to clean up here instead of leaving a big hole
* when this fails.
*/
if (status != STATUS_SUCCESS) { if (status != STATUS_SUCCESS) {
pr_trace("mapping failed, leaked %d bytes\n", len); mm_vm_unmap(vfr, mapping);
return status; return status;
} }
} }
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
status_t
mm_vm_unmap(struct mmu_vfr *vfr, struct vm_map *mapping)
{
size_t gran, len;
uintptr_t vma;
if (vfr == NULL || mapping == NULL) {
return STATUS_INVALID_PARAM;
}
gran = GRAN(mapping->ps);
vma = ALIGN_DOWN(mapping->vma_base, gran);
len = ALIGN_UP(len + (len & (gran - 1)), gran);
for (size_t i = 0; i < len; i += gran) {
mu_mmu_unmap(vfr, vma + i, mapping->ps);
}
return STATUS_SUCCESS;
}
+10
View File
@@ -24,6 +24,8 @@
* @vma_base: Virtual memory base * @vma_base: Virtual memory base
* @pma_base: Physical memory base * @pma_base: Physical memory base
* @length: Number of bytes to map * @length: Number of bytes to map
*
* XXX: `pma_base' is unused when unmapping regions
*/ */
struct vm_map { struct vm_map {
pagesize_t ps; pagesize_t ps;
@@ -49,6 +51,14 @@ struct vm_map {
*/ */
status_t mm_vm_map(struct mmu_vfr *vfr, struct vm_map *mapping, int prot); status_t mm_vm_map(struct mmu_vfr *vfr, struct vm_map *mapping, int prot);
/*
* Destroy a virtual memory mapping
*
* @vfr: Virtual fuck region to unmap within
* @mapping: Mapping to destroy
*/
status_t mm_vm_unmap(struct mmu_vfr *vfr, struct vm_map *mapping);
/* /*
* Initialize the virtual memory management * Initialize the virtual memory management
*/ */