1 #ifndef _ASMX86_PAGE_H_ 2 #define _ASMX86_PAGE_H_ 3 /* 4 * Copyright (C) 2016, Red Hat Inc, Alexander Gordeev <agordeev@redhat.com> 5 * 6 * This work is licensed under the terms of the GNU LGPL, version 2. 7 */ 8 9 10 #include <linux/const.h> 11 #include <bitops.h> 12 13 typedef unsigned long pteval_t; 14 typedef unsigned long pgd_t; 15 16 #include <asm-generic/page.h> 17 18 #ifndef __ASSEMBLY__ 19 20 #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE) 21 22 #ifdef __x86_64__ 23 #define LARGE_PAGE_SIZE (512 * PAGE_SIZE) 24 #else 25 #define LARGE_PAGE_SIZE (1024 * PAGE_SIZE) 26 #endif 27 28 #define PT_PRESENT_MASK (1ull << 0) 29 #define PT_WRITABLE_MASK (1ull << 1) 30 #define PT_USER_MASK (1ull << 2) 31 #define PT_ACCESSED_MASK (1ull << 5) 32 #define PT_DIRTY_MASK (1ull << 6) 33 #define PT_PAGE_SIZE_MASK (1ull << 7) 34 #define PT_GLOBAL_MASK (1ull << 8) 35 #define PT64_NX_MASK (1ull << 63) 36 #define PT_ADDR_MASK GENMASK_ULL(51, 12) 37 38 #define PDPTE64_PAGE_SIZE_MASK (1ull << 7) 39 #define PDPTE64_RSVD_MASK GENMASK_ULL(51, cpuid_maxphyaddr()) 40 41 #define PT_AD_MASK (PT_ACCESSED_MASK | PT_DIRTY_MASK) 42 43 #define PAE_PDPTE_RSVD_MASK (GENMASK_ULL(63, cpuid_maxphyaddr()) | \ 44 GENMASK_ULL(8, 5) | GENMASK_ULL(2, 1)) 45 46 47 #ifdef __x86_64__ 48 #define PAGE_LEVEL 4 49 #define PDPT_LEVEL 3 50 #define PGDIR_WIDTH 9 51 #define PGDIR_MASK 511 52 #else 53 #define PAGE_LEVEL 2 54 #define PGDIR_WIDTH 10 55 #define PGDIR_MASK 1023 56 #endif 57 58 #define PGDIR_BITS(lvl) (((lvl) - 1) * PGDIR_WIDTH + PAGE_SHIFT) 59 #define PGDIR_OFFSET(va, lvl) (((va) >> PGDIR_BITS(lvl)) & PGDIR_MASK) 60 61 #endif /* !__ASSEMBLY__ */ 62 #endif 63