1 #ifndef _ASM_X86_PAGE_H_ 2 #define _ASM_X86_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 #define PAGE_SHIFT 12 17 #define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT) 18 #define PAGE_MASK (~(PAGE_SIZE-1)) 19 20 #ifndef __ASSEMBLY__ 21 22 #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE) 23 24 #ifdef __x86_64__ 25 #define LARGE_PAGE_SIZE (512 * PAGE_SIZE) 26 #else 27 #define LARGE_PAGE_SIZE (1024 * PAGE_SIZE) 28 #endif 29 30 #define PT_PRESENT_MASK (1ull << 0) 31 #define PT_WRITABLE_MASK (1ull << 1) 32 #define PT_USER_MASK (1ull << 2) 33 #define PT_ACCESSED_MASK (1ull << 5) 34 #define PT_DIRTY_MASK (1ull << 6) 35 #define PT_PAGE_SIZE_MASK (1ull << 7) 36 #define PT64_NX_MASK (1ull << 63) 37 #define PT_ADDR_MASK GENMASK_ULL(51, 12) 38 39 #define PDPTE64_PAGE_SIZE_MASK (1ull << 7) 40 #define PDPTE64_RSVD_MASK GENMASK_ULL(51, cpuid_maxphyaddr()) 41 42 #define PT_AD_MASK (PT_ACCESSED_MASK | PT_DIRTY_MASK) 43 44 #define PAE_PDPTE_RSVD_MASK (GENMASK_ULL(63, cpuid_maxphyaddr()) | \ 45 GENMASK_ULL(8, 5) | GENMASK_ULL(2, 1)) 46 47 48 #ifdef __x86_64__ 49 #define PAGE_LEVEL 4 50 #define PDPT_LEVEL 3 51 #define PGDIR_WIDTH 9 52 #define PGDIR_MASK 511 53 #else 54 #define PAGE_LEVEL 2 55 #define PGDIR_WIDTH 10 56 #define PGDIR_MASK 1023 57 #endif 58 59 #define PGDIR_BITS(lvl) (((lvl) - 1) * PGDIR_WIDTH + PAGE_SHIFT) 60 #define PGDIR_OFFSET(va, lvl) (((va) >> PGDIR_BITS(lvl)) & PGDIR_MASK) 61 62 #endif /* !__ASSEMBLY__ */ 63 #endif 64