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 PT_AD_MASK (PT_ACCESSED_MASK | PT_DIRTY_MASK) 40 41 #ifdef __x86_64__ 42 #define PAGE_LEVEL 4 43 #define PGDIR_WIDTH 9 44 #define PGDIR_MASK 511 45 #else 46 #define PAGE_LEVEL 2 47 #define PGDIR_WIDTH 10 48 #define PGDIR_MASK 1023 49 #endif 50 51 #define PGDIR_BITS(lvl) (((lvl) - 1) * PGDIR_WIDTH + PAGE_SHIFT) 52 #define PGDIR_OFFSET(va, lvl) (((va) >> PGDIR_BITS(lvl)) & PGDIR_MASK) 53 54 #endif /* !__ASSEMBLY__ */ 55 #endif 56