MOS Source Code
Loading...
Searching...
No Matches
pml1.c
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
4
7
8#include <mos_stdlib.h>
9
10#if MOS_PLATFORM_PAGING_LEVELS < 1
11#error "Give up your mind"
12#endif
13
14void pml1_traverse(pml1_t pml1, ptr_t *vaddr, size_t *n_pages, pagetable_walk_options_t callback, void *data)
15{
16 for (size_t pml1_i = pml1_index(*vaddr); pml1_i < PML1_ENTRIES && *n_pages; pml1_i++)
17 {
18 pml1e_t *pml1e = pml1_entry(pml1, *vaddr);
19 if (callback.pml1e_callback)
20 callback.pml1e_callback(pml1, pml1e, *vaddr, data);
21 (*vaddr) += MIN(*n_pages, PML1E_NPAGES) * MOS_PAGE_SIZE;
22 (*n_pages) -= MIN(*n_pages, PML1E_NPAGES);
23 }
24}
25
26bool pml1_destroy_range(pml1_t pml1, ptr_t *vaddr, size_t *n_pages)
27{
28 const bool should_zap_this_pml1 = pml1_index(*vaddr) == 0 && *n_pages >= PML1_ENTRIES * PML1E_NPAGES;
29
30 for (size_t pml1_i = pml1_index(*vaddr); pml1_i < PML1_ENTRIES && *n_pages; pml1_i++)
31 {
32 pml1e_t *pml1e = pml1_entry(pml1, *vaddr);
34
35 (*vaddr) += PML1E_NPAGES * MOS_PAGE_SIZE;
36 (*n_pages) -= PML1E_NPAGES;
37 }
38
39 if (should_zap_this_pml1)
41
42 return should_zap_this_pml1;
43}
44
46{
47 return &pml1.table[pml1_index(vaddr)];
48}
49
50bool pml1e_is_present(const pml1e_t *pml1e)
51{
52 return platform_pml1e_get_present(pml1e);
53}
54
56{
57 return platform_pml1e_get_pfn(pml1e);
58}
pfn_t platform_pml1e_get_pfn(const pml1e_t *pml1e)
Definition mm.c:78
bool platform_pml1e_get_present(const pml1e_t *pml1)
Definition mm.c:90
#define MOS_ASSERT(cond)
Definition assert.h:14
#define MOS_PAGE_SIZE
Definition autoconf.h:6
bool callback(pb_istream_t *stream, uint8_t *buf, size_t count)
#define MIN(a, b)
Definition mos_stdlib.h:30
void pml1_traverse(pml1_t pml1, ptr_t *vaddr, size_t *n_pages, pagetable_walk_options_t callback, void *data)
Definition pml1.c:14
bool pml1_destroy_range(pml1_t pml1, ptr_t *vaddr, size_t *n_pages)
Definition pml1.c:26
pfn_t pml1e_get_pfn(const pml1e_t *pml1e)
Definition pml1.c:55
bool pml1e_is_present(const pml1e_t *pml1e)
Definition pml1.c:50
pml1e_t * pml1_entry(pml1_t pml1, ptr_t vaddr)
Definition pml1.c:45
#define pml_destroy_table(x)
Definition pml_types.h:108
#define pml1_index(vaddr)
Definition pml_types.h:37
#define PML1E_NPAGES
Definition pml_types.h:38
#define PML1_ENTRIES
pml1e_t * table
Definition pml_types.h:35
unsigned long long pfn_t
Definition types.h:41
unsigned long ptr_t
Definition types.h:25