5#include "mos/platform/platform_defs.h"
10#define MOS_MAX_PAGE_LEVEL 5
12#ifndef MOS_PLATFORM_PAGING_LEVELS
13#error "MOS_PLATFORM_PAGING_LEVELS must be defined"
16#if MOS_PLATFORM_PAGING_LEVELS > 4
17#error "more levels are not supported"
22#define define_pmlx(pmln) \
25 pte_content_t content; \
26 } __packed pmln##e_t; \
32#define pml_null(pmln) (pmln.table == NULL)
37#define pml1_index(vaddr) ((vaddr >> PML1_SHIFT) & PML1_MASK)
38#define PML1E_NPAGES 1ULL
40#if MOS_PLATFORM_PAGING_LEVELS >= 2
42#define pml2_index(vaddr) ((vaddr >> PML2_SHIFT) & PML2_MASK)
43#define PML2E_NPAGES (PML1_ENTRIES * PML1E_NPAGES)
44#if MOS_CONFIG(PML2_HUGE_CAPABLE)
45#define PML2_HUGE_MASK (PML1_MASK << PML1_SHIFT)
51#if MOS_PLATFORM_PAGING_LEVELS >= 3
53#define pml3_index(vaddr) ((vaddr >> PML3_SHIFT) & PML3_MASK)
54#define PML3E_NPAGES (PML2_ENTRIES * PML2E_NPAGES)
55#if MOS_CONFIG(PML3_HUGE_CAPABLE)
56#define PML3_HUGE_MASK (PML2_HUGE_MASK | (PML2_MASK << PML2_SHIFT))
63#if MOS_PLATFORM_PAGING_LEVELS >= 4
65#define pml4_index(vaddr) ((vaddr >> PML4_SHIFT) & PML4_MASK)
66#define PML4E_NPAGES (PML3_ENTRIES * PML3E_NPAGES)
67#if MOS_CONFIG(PML4_HUGE_CAPABLE)
68#define PML4_HUGE_MASK (PML3_HUGE_MASK | (PML3_MASK << PML3_SHIFT))
75#if MOS_PLATFORM_PAGING_LEVELS >= 5
76#error "TODO: more than 4 levels"
82#define MOS_PMLTOP MOS_CONCAT(pml, MOS_PLATFORM_PAGING_LEVELS)
89#define pgd_create(top) ((pgd_t){ .max = { .next = top } })
90#define pgd_pfn(pgd) va_pfn(pgd.max.next.table)
97 void (*pml2e_pre_traverse)(pml2_t pml2, pml2e_t *e,
ptr_t vaddr,
void *data);
99 void (*pml2e_post_traverse)(pml2_t pml2, pml2e_t *e,
ptr_t vaddr,
void *data);
107#define pml_create_table(x) ((MOS_CONCAT(x, _t)){ .table = (MOS_CONCAT(x, e_t) *) __create_page_table() })
108#define pml_destroy_table(x) __destroy_page_table(x.table)
110#define pmlxe_destroy(pmlxe) (pmlxe)->content = 0
MOSAPI void(1, 2) fatal_abort(const char *fmt
void __destroy_page_table(void *table)
#define define_pmlx(pmln)
#define MOS_MAX_PAGE_LEVEL
__nodiscard void * __create_page_table(void)
MOS_CONCAT(MOS_CONCAT(pml, 5), _t) max
#define new_named_opaque_type(base, name, type)