xref: /kvm-unit-tests/lib/x86/asm/page.h (revision c865f654ffe4c5955038aaf74f702ba62f3eb014)
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 PT64_NX_MASK		(1ull << 63)
35 #define PT_ADDR_MASK		GENMASK_ULL(51, 12)
36 
37 #define PDPTE64_PAGE_SIZE_MASK	  (1ull << 7)
38 #define PDPTE64_RSVD_MASK	  GENMASK_ULL(51, cpuid_maxphyaddr())
39 
40 #define PT_AD_MASK              (PT_ACCESSED_MASK | PT_DIRTY_MASK)
41 
42 #define PAE_PDPTE_RSVD_MASK     (GENMASK_ULL(63, cpuid_maxphyaddr()) |	\
43 				 GENMASK_ULL(8, 5) | GENMASK_ULL(2, 1))
44 
45 
46 #ifdef __x86_64__
47 #define	PAGE_LEVEL	4
48 #define	PDPT_LEVEL	3
49 #define	PGDIR_WIDTH	9
50 #define	PGDIR_MASK	511
51 #else
52 #define	PAGE_LEVEL	2
53 #define	PGDIR_WIDTH	10
54 #define	PGDIR_MASK	1023
55 #endif
56 
57 #define PGDIR_BITS(lvl)        (((lvl) - 1) * PGDIR_WIDTH + PAGE_SHIFT)
58 #define PGDIR_OFFSET(va, lvl)  (((va) >> PGDIR_BITS(lvl)) & PGDIR_MASK)
59 
60 #endif /* !__ASSEMBLY__ */
61 #endif
62