1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#include "mos/mm/paging/table_ops/do_unmap.h"
4
5#include "mos/platform/platform.h"
6
7static void pml1e_do_unmap_callback(pml1_t pml1, pml1e_t *e, ptr_t vaddr, void *data)
8{
9 MOS_UNUSED(pml1);
10 MOS_UNUSED(vaddr);
11
12 struct pagetable_do_unmap_data *unmap_data = data;
13 if (!platform_pml1e_get_present(pml1: e))
14 return; // nothing to do (page isn't mapped)
15
16 const pfn_t pfn = platform_pml1e_get_pfn(pml1: e);
17 if (unmap_data->do_unref)
18 pmm_unref_one(pfn);
19
20 pmlxe_destroy(e);
21 platform_invalidate_tlb(vaddr);
22}
23
24static void pml2e_do_unmap_callback(pml2_t pml2, pml2e_t *e, ptr_t vaddr, void *data)
25{
26 MOS_UNUSED(pml2);
27 MOS_UNUSED(e);
28 MOS_UNUSED(vaddr);
29 MOS_UNUSED(data);
30}
31
32static void pml3e_do_unmap_callback(pml3_t pml3, pml3e_t *e, ptr_t vaddr, void *data)
33{
34 MOS_UNUSED(pml3);
35 MOS_UNUSED(e);
36 MOS_UNUSED(vaddr);
37 MOS_UNUSED(data);
38}
39
40static void pml4e_do_unmap_callback(pml4_t pml4, pml4e_t *e, ptr_t vaddr, void *data)
41{
42 MOS_UNUSED(pml4);
43 MOS_UNUSED(e);
44 MOS_UNUSED(vaddr);
45 MOS_UNUSED(data);
46}
47
48const pagetable_walk_options_t pagetable_do_unmap_callbacks = {
49 .readonly = true,
50 .pml1e_callback = pml1e_do_unmap_callback,
51 .pml2e_pre_traverse = pml2e_do_unmap_callback,
52 .pml3e_pre_traverse = pml3e_do_unmap_callback,
53 .pml4e_pre_traverse = pml4e_do_unmap_callback,
54};
55