Subversion Repositories Kolibri OS

Rev

Rev 6936 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6936 Rev 7143
1
#ifndef _ASM_X86_PGTABLE_DEFS_H
1
#ifndef _ASM_X86_PGTABLE_DEFS_H
2
#define _ASM_X86_PGTABLE_DEFS_H
2
#define _ASM_X86_PGTABLE_DEFS_H
3
 
3
 
4
#include 
4
#include 
5
#include 
5
#include 
6
 
6
 
7
#define FIRST_USER_ADDRESS	0UL
7
#define FIRST_USER_ADDRESS	0UL
8
 
8
 
9
#define _PAGE_BIT_PRESENT	0	/* is present */
9
#define _PAGE_BIT_PRESENT	0	/* is present */
10
#define _PAGE_BIT_RW		1	/* writeable */
10
#define _PAGE_BIT_RW		1	/* writeable */
11
#define _PAGE_BIT_USER		2	/* userspace addressable */
11
#define _PAGE_BIT_USER		2	/* userspace addressable */
12
#define _PAGE_BIT_PWT		3	/* page write through */
12
#define _PAGE_BIT_PWT		3	/* page write through */
13
#define _PAGE_BIT_PCD		4	/* page cache disabled */
13
#define _PAGE_BIT_PCD		4	/* page cache disabled */
14
#define _PAGE_BIT_ACCESSED	5	/* was accessed (raised by CPU) */
14
#define _PAGE_BIT_ACCESSED	5	/* was accessed (raised by CPU) */
15
#define _PAGE_BIT_DIRTY		6	/* was written to (raised by CPU) */
15
#define _PAGE_BIT_DIRTY		6	/* was written to (raised by CPU) */
16
#define _PAGE_BIT_PSE		7	/* 4 MB (or 2MB) page */
16
#define _PAGE_BIT_PSE		7	/* 4 MB (or 2MB) page */
17
#define _PAGE_BIT_PAT		7	/* on 4KB pages */
17
#define _PAGE_BIT_PAT		7	/* on 4KB pages */
18
#define _PAGE_BIT_GLOBAL	8	/* Global TLB entry PPro+ */
18
#define _PAGE_BIT_GLOBAL	8	/* Global TLB entry PPro+ */
19
#define _PAGE_BIT_SOFTW1	9	/* available for programmer */
19
#define _PAGE_BIT_SOFTW1	9	/* available for programmer */
20
#define _PAGE_BIT_SOFTW2	10	/* " */
20
#define _PAGE_BIT_SOFTW2	10	/* " */
21
#define _PAGE_BIT_SOFTW3	11	/* " */
21
#define _PAGE_BIT_SOFTW3	11	/* " */
22
#define _PAGE_BIT_PAT_LARGE	12	/* On 2MB or 1GB pages */
22
#define _PAGE_BIT_PAT_LARGE	12	/* On 2MB or 1GB pages */
-
 
23
#define _PAGE_BIT_SOFTW4	58	/* available for programmer */
-
 
24
#define _PAGE_BIT_PKEY_BIT0	59	/* Protection Keys, bit 1/4 */
-
 
25
#define _PAGE_BIT_PKEY_BIT1	60	/* Protection Keys, bit 2/4 */
-
 
26
#define _PAGE_BIT_PKEY_BIT2	61	/* Protection Keys, bit 3/4 */
-
 
27
#define _PAGE_BIT_PKEY_BIT3	62	/* Protection Keys, bit 4/4 */
-
 
28
#define _PAGE_BIT_NX		63	/* No execute: only valid after cpuid check */
-
 
29
 
23
#define _PAGE_BIT_SPECIAL	_PAGE_BIT_SOFTW1
30
#define _PAGE_BIT_SPECIAL	_PAGE_BIT_SOFTW1
24
#define _PAGE_BIT_CPA_TEST	_PAGE_BIT_SOFTW1
31
#define _PAGE_BIT_CPA_TEST	_PAGE_BIT_SOFTW1
25
#define _PAGE_BIT_HIDDEN	_PAGE_BIT_SOFTW3 /* hidden by kmemcheck */
32
#define _PAGE_BIT_HIDDEN	_PAGE_BIT_SOFTW3 /* hidden by kmemcheck */
26
#define _PAGE_BIT_SOFT_DIRTY	_PAGE_BIT_SOFTW3 /* software dirty tracking */
33
#define _PAGE_BIT_SOFT_DIRTY	_PAGE_BIT_SOFTW3 /* software dirty tracking */
27
#define _PAGE_BIT_SOFTW4	58	/* available for programmer */
-
 
28
#define _PAGE_BIT_DEVMAP		_PAGE_BIT_SOFTW4
34
#define _PAGE_BIT_DEVMAP	_PAGE_BIT_SOFTW4
29
#define _PAGE_BIT_NX           63       /* No execute: only valid after cpuid check */
-
 
30
 
35
 
31
/* If _PAGE_BIT_PRESENT is clear, we use these: */
36
/* If _PAGE_BIT_PRESENT is clear, we use these: */
32
/* - if the user mapped it with PROT_NONE; pte_present gives true */
37
/* - if the user mapped it with PROT_NONE; pte_present gives true */
33
#define _PAGE_BIT_PROTNONE	_PAGE_BIT_GLOBAL
38
#define _PAGE_BIT_PROTNONE	_PAGE_BIT_GLOBAL
34
 
39
 
35
#define _PAGE_PRESENT	(_AT(pteval_t, 1) << _PAGE_BIT_PRESENT)
40
#define _PAGE_PRESENT	(_AT(pteval_t, 1) << _PAGE_BIT_PRESENT)
36
#define _PAGE_RW	(_AT(pteval_t, 1) << _PAGE_BIT_RW)
41
#define _PAGE_RW	(_AT(pteval_t, 1) << _PAGE_BIT_RW)
37
#define _PAGE_USER	(_AT(pteval_t, 1) << _PAGE_BIT_USER)
42
#define _PAGE_USER	(_AT(pteval_t, 1) << _PAGE_BIT_USER)
38
#define _PAGE_PWT	(_AT(pteval_t, 1) << _PAGE_BIT_PWT)
43
#define _PAGE_PWT	(_AT(pteval_t, 1) << _PAGE_BIT_PWT)
39
#define _PAGE_PCD	(_AT(pteval_t, 1) << _PAGE_BIT_PCD)
44
#define _PAGE_PCD	(_AT(pteval_t, 1) << _PAGE_BIT_PCD)
40
#define _PAGE_ACCESSED	(_AT(pteval_t, 1) << _PAGE_BIT_ACCESSED)
45
#define _PAGE_ACCESSED	(_AT(pteval_t, 1) << _PAGE_BIT_ACCESSED)
41
#define _PAGE_DIRTY	(_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
46
#define _PAGE_DIRTY	(_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
42
#define _PAGE_PSE	(_AT(pteval_t, 1) << _PAGE_BIT_PSE)
47
#define _PAGE_PSE	(_AT(pteval_t, 1) << _PAGE_BIT_PSE)
43
#define _PAGE_GLOBAL	(_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
48
#define _PAGE_GLOBAL	(_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
44
#define _PAGE_SOFTW1	(_AT(pteval_t, 1) << _PAGE_BIT_SOFTW1)
49
#define _PAGE_SOFTW1	(_AT(pteval_t, 1) << _PAGE_BIT_SOFTW1)
45
#define _PAGE_SOFTW2	(_AT(pteval_t, 1) << _PAGE_BIT_SOFTW2)
50
#define _PAGE_SOFTW2	(_AT(pteval_t, 1) << _PAGE_BIT_SOFTW2)
46
#define _PAGE_PAT	(_AT(pteval_t, 1) << _PAGE_BIT_PAT)
51
#define _PAGE_PAT	(_AT(pteval_t, 1) << _PAGE_BIT_PAT)
47
#define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
52
#define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
48
#define _PAGE_SPECIAL	(_AT(pteval_t, 1) << _PAGE_BIT_SPECIAL)
53
#define _PAGE_SPECIAL	(_AT(pteval_t, 1) << _PAGE_BIT_SPECIAL)
49
#define _PAGE_CPA_TEST	(_AT(pteval_t, 1) << _PAGE_BIT_CPA_TEST)
54
#define _PAGE_CPA_TEST	(_AT(pteval_t, 1) << _PAGE_BIT_CPA_TEST)
-
 
55
#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
-
 
56
#define _PAGE_PKEY_BIT0	(_AT(pteval_t, 1) << _PAGE_BIT_PKEY_BIT0)
-
 
57
#define _PAGE_PKEY_BIT1	(_AT(pteval_t, 1) << _PAGE_BIT_PKEY_BIT1)
-
 
58
#define _PAGE_PKEY_BIT2	(_AT(pteval_t, 1) << _PAGE_BIT_PKEY_BIT2)
-
 
59
#define _PAGE_PKEY_BIT3	(_AT(pteval_t, 1) << _PAGE_BIT_PKEY_BIT3)
-
 
60
#else
-
 
61
#define _PAGE_PKEY_BIT0	(_AT(pteval_t, 0))
-
 
62
#define _PAGE_PKEY_BIT1	(_AT(pteval_t, 0))
-
 
63
#define _PAGE_PKEY_BIT2	(_AT(pteval_t, 0))
-
 
64
#define _PAGE_PKEY_BIT3	(_AT(pteval_t, 0))
-
 
65
#endif
50
#define __HAVE_ARCH_PTE_SPECIAL
66
#define __HAVE_ARCH_PTE_SPECIAL
-
 
67
 
-
 
68
#define _PAGE_PKEY_MASK (_PAGE_PKEY_BIT0 | \
-
 
69
			 _PAGE_PKEY_BIT1 | \
-
 
70
			 _PAGE_PKEY_BIT2 | \
-
 
71
			 _PAGE_PKEY_BIT3)
51
 
72
 
52
#ifdef CONFIG_KMEMCHECK
73
#ifdef CONFIG_KMEMCHECK
53
#define _PAGE_HIDDEN	(_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
74
#define _PAGE_HIDDEN	(_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
54
#else
75
#else
55
#define _PAGE_HIDDEN	(_AT(pteval_t, 0))
76
#define _PAGE_HIDDEN	(_AT(pteval_t, 0))
56
#endif
77
#endif
57
 
78
 
58
/*
79
/*
59
 * The same hidden bit is used by kmemcheck, but since kmemcheck
80
 * The same hidden bit is used by kmemcheck, but since kmemcheck
60
 * works on kernel pages while soft-dirty engine on user space,
81
 * works on kernel pages while soft-dirty engine on user space,
61
 * they do not conflict with each other.
82
 * they do not conflict with each other.
62
 */
83
 */
63
 
84
 
64
#ifdef CONFIG_MEM_SOFT_DIRTY
85
#ifdef CONFIG_MEM_SOFT_DIRTY
65
#define _PAGE_SOFT_DIRTY	(_AT(pteval_t, 1) << _PAGE_BIT_SOFT_DIRTY)
86
#define _PAGE_SOFT_DIRTY	(_AT(pteval_t, 1) << _PAGE_BIT_SOFT_DIRTY)
66
#else
87
#else
67
#define _PAGE_SOFT_DIRTY	(_AT(pteval_t, 0))
88
#define _PAGE_SOFT_DIRTY	(_AT(pteval_t, 0))
68
#endif
89
#endif
69
 
90
 
70
/*
91
/*
71
 * Tracking soft dirty bit when a page goes to a swap is tricky.
92
 * Tracking soft dirty bit when a page goes to a swap is tricky.
72
 * We need a bit which can be stored in pte _and_ not conflict
93
 * We need a bit which can be stored in pte _and_ not conflict
73
 * with swap entry format. On x86 bits 6 and 7 are *not* involved
94
 * with swap entry format. On x86 bits 6 and 7 are *not* involved
74
 * into swap entry computation, but bit 6 is used for nonlinear
95
 * into swap entry computation, but bit 6 is used for nonlinear
75
 * file mapping, so we borrow bit 7 for soft dirty tracking.
96
 * file mapping, so we borrow bit 7 for soft dirty tracking.
76
 *
97
 *
77
 * Please note that this bit must be treated as swap dirty page
98
 * Please note that this bit must be treated as swap dirty page
78
 * mark if and only if the PTE has present bit clear!
99
 * mark if and only if the PTE has present bit clear!
79
 */
100
 */
80
#ifdef CONFIG_MEM_SOFT_DIRTY
101
#ifdef CONFIG_MEM_SOFT_DIRTY
81
#define _PAGE_SWP_SOFT_DIRTY	_PAGE_PSE
102
#define _PAGE_SWP_SOFT_DIRTY	_PAGE_PSE
82
#else
103
#else
83
#define _PAGE_SWP_SOFT_DIRTY	(_AT(pteval_t, 0))
104
#define _PAGE_SWP_SOFT_DIRTY	(_AT(pteval_t, 0))
84
#endif
105
#endif
85
 
106
 
86
#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
107
#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
87
#define _PAGE_NX	(_AT(pteval_t, 1) << _PAGE_BIT_NX)
108
#define _PAGE_NX	(_AT(pteval_t, 1) << _PAGE_BIT_NX)
88
#define _PAGE_DEVMAP	(_AT(u64, 1) << _PAGE_BIT_DEVMAP)
109
#define _PAGE_DEVMAP	(_AT(u64, 1) << _PAGE_BIT_DEVMAP)
89
#define __HAVE_ARCH_PTE_DEVMAP
110
#define __HAVE_ARCH_PTE_DEVMAP
90
#else
111
#else
91
#define _PAGE_NX	(_AT(pteval_t, 0))
112
#define _PAGE_NX	(_AT(pteval_t, 0))
92
#define _PAGE_DEVMAP	(_AT(pteval_t, 0))
113
#define _PAGE_DEVMAP	(_AT(pteval_t, 0))
93
#endif
114
#endif
94
 
115
 
95
#define _PAGE_PROTNONE	(_AT(pteval_t, 1) << _PAGE_BIT_PROTNONE)
116
#define _PAGE_PROTNONE	(_AT(pteval_t, 1) << _PAGE_BIT_PROTNONE)
96
 
117
 
97
#define _PAGE_TABLE	(_PAGE_PRESENT | _PAGE_RW | _PAGE_USER |	\
118
#define _PAGE_TABLE	(_PAGE_PRESENT | _PAGE_RW | _PAGE_USER |	\
98
			 _PAGE_ACCESSED | _PAGE_DIRTY)
119
			 _PAGE_ACCESSED | _PAGE_DIRTY)
99
#define _KERNPG_TABLE	(_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED |	\
120
#define _KERNPG_TABLE	(_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED |	\
100
			 _PAGE_DIRTY)
121
			 _PAGE_DIRTY)
-
 
122
 
101
 
123
/*
-
 
124
 * Set of bits not changed in pte_modify.  The pte's
-
 
125
 * protection key is treated like _PAGE_RW, for
-
 
126
 * instance, and is *not* included in this mask since
-
 
127
 * pte_modify() does modify it.
102
/* Set of bits not changed in pte_modify */
128
 */
103
#define _PAGE_CHG_MASK	(PTE_PFN_MASK | _PAGE_PCD | _PAGE_PWT |		\
129
#define _PAGE_CHG_MASK	(PTE_PFN_MASK | _PAGE_PCD | _PAGE_PWT |		\
104
			 _PAGE_SPECIAL | _PAGE_ACCESSED | _PAGE_DIRTY |	\
130
			 _PAGE_SPECIAL | _PAGE_ACCESSED | _PAGE_DIRTY |	\
105
			 _PAGE_SOFT_DIRTY)
131
			 _PAGE_SOFT_DIRTY)
106
#define _HPAGE_CHG_MASK (_PAGE_CHG_MASK | _PAGE_PSE)
132
#define _HPAGE_CHG_MASK (_PAGE_CHG_MASK | _PAGE_PSE)
107
 
133
 
108
/*
134
/*
109
 * The cache modes defined here are used to translate between pure SW usage
135
 * The cache modes defined here are used to translate between pure SW usage
110
 * and the HW defined cache mode bits and/or PAT entries.
136
 * and the HW defined cache mode bits and/or PAT entries.
111
 *
137
 *
112
 * The resulting bits for PWT, PCD and PAT should be chosen in a way
138
 * The resulting bits for PWT, PCD and PAT should be chosen in a way
113
 * to have the WB mode at index 0 (all bits clear). This is the default
139
 * to have the WB mode at index 0 (all bits clear). This is the default
114
 * right now and likely would break too much if changed.
140
 * right now and likely would break too much if changed.
115
 */
141
 */
116
#ifndef __ASSEMBLY__
142
#ifndef __ASSEMBLY__
117
enum page_cache_mode {
143
enum page_cache_mode {
118
	_PAGE_CACHE_MODE_WB = 0,
144
	_PAGE_CACHE_MODE_WB = 0,
119
	_PAGE_CACHE_MODE_WC = 1,
145
	_PAGE_CACHE_MODE_WC = 1,
120
	_PAGE_CACHE_MODE_UC_MINUS = 2,
146
	_PAGE_CACHE_MODE_UC_MINUS = 2,
121
	_PAGE_CACHE_MODE_UC = 3,
147
	_PAGE_CACHE_MODE_UC = 3,
122
	_PAGE_CACHE_MODE_WT = 4,
148
	_PAGE_CACHE_MODE_WT = 4,
123
	_PAGE_CACHE_MODE_WP = 5,
149
	_PAGE_CACHE_MODE_WP = 5,
124
	_PAGE_CACHE_MODE_NUM = 8
150
	_PAGE_CACHE_MODE_NUM = 8
125
};
151
};
126
#endif
152
#endif
127
 
153
 
128
#define _PAGE_CACHE_MASK	(_PAGE_PAT | _PAGE_PCD | _PAGE_PWT)
154
#define _PAGE_CACHE_MASK	(_PAGE_PAT | _PAGE_PCD | _PAGE_PWT)
129
#define _PAGE_NOCACHE		(cachemode2protval(_PAGE_CACHE_MODE_UC))
155
#define _PAGE_NOCACHE		(cachemode2protval(_PAGE_CACHE_MODE_UC))
130
 
156
 
131
#define PAGE_NONE	__pgprot(_PAGE_PROTNONE | _PAGE_ACCESSED)
157
#define PAGE_NONE	__pgprot(_PAGE_PROTNONE | _PAGE_ACCESSED)
132
#define PAGE_SHARED	__pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | \
158
#define PAGE_SHARED	__pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | \
133
				 _PAGE_ACCESSED | _PAGE_NX)
159
				 _PAGE_ACCESSED | _PAGE_NX)
134
 
160
 
135
#define PAGE_SHARED_EXEC	__pgprot(_PAGE_PRESENT | _PAGE_RW |	\
161
#define PAGE_SHARED_EXEC	__pgprot(_PAGE_PRESENT | _PAGE_RW |	\
136
					 _PAGE_USER | _PAGE_ACCESSED)
162
					 _PAGE_USER | _PAGE_ACCESSED)
137
#define PAGE_COPY_NOEXEC	__pgprot(_PAGE_PRESENT | _PAGE_USER |	\
163
#define PAGE_COPY_NOEXEC	__pgprot(_PAGE_PRESENT | _PAGE_USER |	\
138
					 _PAGE_ACCESSED | _PAGE_NX)
164
					 _PAGE_ACCESSED | _PAGE_NX)
139
#define PAGE_COPY_EXEC		__pgprot(_PAGE_PRESENT | _PAGE_USER |	\
165
#define PAGE_COPY_EXEC		__pgprot(_PAGE_PRESENT | _PAGE_USER |	\
140
					 _PAGE_ACCESSED)
166
					 _PAGE_ACCESSED)
141
#define PAGE_COPY		PAGE_COPY_NOEXEC
167
#define PAGE_COPY		PAGE_COPY_NOEXEC
142
#define PAGE_READONLY		__pgprot(_PAGE_PRESENT | _PAGE_USER |	\
168
#define PAGE_READONLY		__pgprot(_PAGE_PRESENT | _PAGE_USER |	\
143
					 _PAGE_ACCESSED | _PAGE_NX)
169
					 _PAGE_ACCESSED | _PAGE_NX)
144
#define PAGE_READONLY_EXEC	__pgprot(_PAGE_PRESENT | _PAGE_USER |	\
170
#define PAGE_READONLY_EXEC	__pgprot(_PAGE_PRESENT | _PAGE_USER |	\
145
					 _PAGE_ACCESSED)
171
					 _PAGE_ACCESSED)
146
 
172
 
147
#define __PAGE_KERNEL_EXEC						\
173
#define __PAGE_KERNEL_EXEC						\
148
	(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
174
	(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
149
#define __PAGE_KERNEL		(__PAGE_KERNEL_EXEC | _PAGE_NX)
175
#define __PAGE_KERNEL		(__PAGE_KERNEL_EXEC | _PAGE_NX)
150
 
176
 
151
#define __PAGE_KERNEL_RO		(__PAGE_KERNEL & ~_PAGE_RW)
177
#define __PAGE_KERNEL_RO		(__PAGE_KERNEL & ~_PAGE_RW)
152
#define __PAGE_KERNEL_RX		(__PAGE_KERNEL_EXEC & ~_PAGE_RW)
178
#define __PAGE_KERNEL_RX		(__PAGE_KERNEL_EXEC & ~_PAGE_RW)
153
#define __PAGE_KERNEL_NOCACHE		(__PAGE_KERNEL | _PAGE_NOCACHE)
179
#define __PAGE_KERNEL_NOCACHE		(__PAGE_KERNEL | _PAGE_NOCACHE)
154
#define __PAGE_KERNEL_VSYSCALL		(__PAGE_KERNEL_RX | _PAGE_USER)
180
#define __PAGE_KERNEL_VSYSCALL		(__PAGE_KERNEL_RX | _PAGE_USER)
155
#define __PAGE_KERNEL_VVAR		(__PAGE_KERNEL_RO | _PAGE_USER)
181
#define __PAGE_KERNEL_VVAR		(__PAGE_KERNEL_RO | _PAGE_USER)
156
#define __PAGE_KERNEL_LARGE		(__PAGE_KERNEL | _PAGE_PSE)
182
#define __PAGE_KERNEL_LARGE		(__PAGE_KERNEL | _PAGE_PSE)
157
#define __PAGE_KERNEL_LARGE_EXEC	(__PAGE_KERNEL_EXEC | _PAGE_PSE)
183
#define __PAGE_KERNEL_LARGE_EXEC	(__PAGE_KERNEL_EXEC | _PAGE_PSE)
158
 
184
 
159
#define __PAGE_KERNEL_IO		(__PAGE_KERNEL)
185
#define __PAGE_KERNEL_IO		(__PAGE_KERNEL)
160
#define __PAGE_KERNEL_IO_NOCACHE	(__PAGE_KERNEL_NOCACHE)
186
#define __PAGE_KERNEL_IO_NOCACHE	(__PAGE_KERNEL_NOCACHE)
161
 
187
 
162
#define PAGE_KERNEL			__pgprot(__PAGE_KERNEL)
188
#define PAGE_KERNEL			__pgprot(__PAGE_KERNEL)
163
#define PAGE_KERNEL_RO			__pgprot(__PAGE_KERNEL_RO)
189
#define PAGE_KERNEL_RO			__pgprot(__PAGE_KERNEL_RO)
164
#define PAGE_KERNEL_EXEC		__pgprot(__PAGE_KERNEL_EXEC)
190
#define PAGE_KERNEL_EXEC		__pgprot(__PAGE_KERNEL_EXEC)
165
#define PAGE_KERNEL_RX			__pgprot(__PAGE_KERNEL_RX)
191
#define PAGE_KERNEL_RX			__pgprot(__PAGE_KERNEL_RX)
166
#define PAGE_KERNEL_NOCACHE		__pgprot(__PAGE_KERNEL_NOCACHE)
192
#define PAGE_KERNEL_NOCACHE		__pgprot(__PAGE_KERNEL_NOCACHE)
167
#define PAGE_KERNEL_LARGE		__pgprot(__PAGE_KERNEL_LARGE)
193
#define PAGE_KERNEL_LARGE		__pgprot(__PAGE_KERNEL_LARGE)
168
#define PAGE_KERNEL_LARGE_EXEC		__pgprot(__PAGE_KERNEL_LARGE_EXEC)
194
#define PAGE_KERNEL_LARGE_EXEC		__pgprot(__PAGE_KERNEL_LARGE_EXEC)
169
#define PAGE_KERNEL_VSYSCALL		__pgprot(__PAGE_KERNEL_VSYSCALL)
195
#define PAGE_KERNEL_VSYSCALL		__pgprot(__PAGE_KERNEL_VSYSCALL)
170
#define PAGE_KERNEL_VVAR		__pgprot(__PAGE_KERNEL_VVAR)
196
#define PAGE_KERNEL_VVAR		__pgprot(__PAGE_KERNEL_VVAR)
171
 
197
 
172
#define PAGE_KERNEL_IO			__pgprot(__PAGE_KERNEL_IO)
198
#define PAGE_KERNEL_IO			__pgprot(__PAGE_KERNEL_IO)
173
#define PAGE_KERNEL_IO_NOCACHE		__pgprot(__PAGE_KERNEL_IO_NOCACHE)
199
#define PAGE_KERNEL_IO_NOCACHE		__pgprot(__PAGE_KERNEL_IO_NOCACHE)
174
 
200
 
175
/*         xwr */
201
/*         xwr */
176
#define __P000	PAGE_NONE
202
#define __P000	PAGE_NONE
177
#define __P001	PAGE_READONLY
203
#define __P001	PAGE_READONLY
178
#define __P010	PAGE_COPY
204
#define __P010	PAGE_COPY
179
#define __P011	PAGE_COPY
205
#define __P011	PAGE_COPY
180
#define __P100	PAGE_READONLY_EXEC
206
#define __P100	PAGE_READONLY_EXEC
181
#define __P101	PAGE_READONLY_EXEC
207
#define __P101	PAGE_READONLY_EXEC
182
#define __P110	PAGE_COPY_EXEC
208
#define __P110	PAGE_COPY_EXEC
183
#define __P111	PAGE_COPY_EXEC
209
#define __P111	PAGE_COPY_EXEC
184
 
210
 
185
#define __S000	PAGE_NONE
211
#define __S000	PAGE_NONE
186
#define __S001	PAGE_READONLY
212
#define __S001	PAGE_READONLY
187
#define __S010	PAGE_SHARED
213
#define __S010	PAGE_SHARED
188
#define __S011	PAGE_SHARED
214
#define __S011	PAGE_SHARED
189
#define __S100	PAGE_READONLY_EXEC
215
#define __S100	PAGE_READONLY_EXEC
190
#define __S101	PAGE_READONLY_EXEC
216
#define __S101	PAGE_READONLY_EXEC
191
#define __S110	PAGE_SHARED_EXEC
217
#define __S110	PAGE_SHARED_EXEC
192
#define __S111	PAGE_SHARED_EXEC
218
#define __S111	PAGE_SHARED_EXEC
193
 
219
 
194
/*
220
/*
195
 * early identity mapping  pte attrib macros.
221
 * early identity mapping  pte attrib macros.
196
 */
222
 */
197
#ifdef CONFIG_X86_64
223
#ifdef CONFIG_X86_64
198
#define __PAGE_KERNEL_IDENT_LARGE_EXEC	__PAGE_KERNEL_LARGE_EXEC
224
#define __PAGE_KERNEL_IDENT_LARGE_EXEC	__PAGE_KERNEL_LARGE_EXEC
199
#else
225
#else
200
#define PTE_IDENT_ATTR	 0x003		/* PRESENT+RW */
226
#define PTE_IDENT_ATTR	 0x003		/* PRESENT+RW */
201
#define PDE_IDENT_ATTR	 0x063		/* PRESENT+RW+DIRTY+ACCESSED */
227
#define PDE_IDENT_ATTR	 0x063		/* PRESENT+RW+DIRTY+ACCESSED */
202
#define PGD_IDENT_ATTR	 0x001		/* PRESENT (no other attributes) */
228
#define PGD_IDENT_ATTR	 0x001		/* PRESENT (no other attributes) */
203
#endif
229
#endif
204
 
230
 
205
#ifdef CONFIG_X86_32
231
#ifdef CONFIG_X86_32
206
# include 
232
# include 
207
#else
233
#else
208
# include 
234
# include 
209
#endif
235
#endif
210
 
236
 
211
#ifndef __ASSEMBLY__
237
#ifndef __ASSEMBLY__
212
 
238
 
213
#include 
239
#include 
214
 
240
 
215
/* Extracts the PFN from a (pte|pmd|pud|pgd)val_t of a 4KB page */
241
/* Extracts the PFN from a (pte|pmd|pud|pgd)val_t of a 4KB page */
216
#define PTE_PFN_MASK		((pteval_t)PHYSICAL_PAGE_MASK)
242
#define PTE_PFN_MASK		((pteval_t)PHYSICAL_PAGE_MASK)
-
 
243
 
217
 
244
/*
-
 
245
 *  Extracts the flags from a (pte|pmd|pud|pgd)val_t
-
 
246
 *  This includes the protection key value.
218
/* Extracts the flags from a (pte|pmd|pud|pgd)val_t of a 4KB page */
247
 */
219
#define PTE_FLAGS_MASK		(~PTE_PFN_MASK)
248
#define PTE_FLAGS_MASK		(~PTE_PFN_MASK)
220
 
249
 
221
typedef struct pgprot { pgprotval_t pgprot; } pgprot_t;
250
typedef struct pgprot { pgprotval_t pgprot; } pgprot_t;
222
 
251
 
223
typedef struct { pgdval_t pgd; } pgd_t;
252
typedef struct { pgdval_t pgd; } pgd_t;
224
 
253
 
225
static inline pgd_t native_make_pgd(pgdval_t val)
254
static inline pgd_t native_make_pgd(pgdval_t val)
226
{
255
{
227
	return (pgd_t) { val };
256
	return (pgd_t) { val };
228
}
257
}
229
 
258
 
230
static inline pgdval_t native_pgd_val(pgd_t pgd)
259
static inline pgdval_t native_pgd_val(pgd_t pgd)
231
{
260
{
232
	return pgd.pgd;
261
	return pgd.pgd;
233
}
262
}
234
 
263
 
235
static inline pgdval_t pgd_flags(pgd_t pgd)
264
static inline pgdval_t pgd_flags(pgd_t pgd)
236
{
265
{
237
	return native_pgd_val(pgd) & PTE_FLAGS_MASK;
266
	return native_pgd_val(pgd) & PTE_FLAGS_MASK;
238
}
267
}
239
 
268
 
240
#if CONFIG_PGTABLE_LEVELS > 3
269
#if CONFIG_PGTABLE_LEVELS > 3
241
typedef struct { pudval_t pud; } pud_t;
270
typedef struct { pudval_t pud; } pud_t;
242
 
271
 
243
static inline pud_t native_make_pud(pmdval_t val)
272
static inline pud_t native_make_pud(pmdval_t val)
244
{
273
{
245
	return (pud_t) { val };
274
	return (pud_t) { val };
246
}
275
}
247
 
276
 
248
static inline pudval_t native_pud_val(pud_t pud)
277
static inline pudval_t native_pud_val(pud_t pud)
249
{
278
{
250
	return pud.pud;
279
	return pud.pud;
251
}
280
}
252
#else
281
#else
253
#include 
282
#include 
254
 
283
 
255
static inline pudval_t native_pud_val(pud_t pud)
284
static inline pudval_t native_pud_val(pud_t pud)
256
{
285
{
257
	return native_pgd_val(pud.pgd);
286
	return native_pgd_val(pud.pgd);
258
}
287
}
259
#endif
288
#endif
260
 
289
 
261
#if CONFIG_PGTABLE_LEVELS > 2
290
#if CONFIG_PGTABLE_LEVELS > 2
262
typedef struct { pmdval_t pmd; } pmd_t;
291
typedef struct { pmdval_t pmd; } pmd_t;
263
 
292
 
264
static inline pmd_t native_make_pmd(pmdval_t val)
293
static inline pmd_t native_make_pmd(pmdval_t val)
265
{
294
{
266
	return (pmd_t) { val };
295
	return (pmd_t) { val };
267
}
296
}
268
 
297
 
269
static inline pmdval_t native_pmd_val(pmd_t pmd)
298
static inline pmdval_t native_pmd_val(pmd_t pmd)
270
{
299
{
271
	return pmd.pmd;
300
	return pmd.pmd;
272
}
301
}
273
#else
302
#else
274
#include 
303
#include 
275
 
304
 
276
static inline pmdval_t native_pmd_val(pmd_t pmd)
305
static inline pmdval_t native_pmd_val(pmd_t pmd)
277
{
306
{
278
	return native_pgd_val(pmd.pud.pgd);
307
	return native_pgd_val(pmd.pud.pgd);
279
}
308
}
280
#endif
309
#endif
281
 
310
 
282
static inline pudval_t pud_pfn_mask(pud_t pud)
311
static inline pudval_t pud_pfn_mask(pud_t pud)
283
{
312
{
284
	if (native_pud_val(pud) & _PAGE_PSE)
313
	if (native_pud_val(pud) & _PAGE_PSE)
285
		return PHYSICAL_PUD_PAGE_MASK;
314
		return PHYSICAL_PUD_PAGE_MASK;
286
	else
315
	else
287
		return PTE_PFN_MASK;
316
		return PTE_PFN_MASK;
288
}
317
}
289
 
318
 
290
static inline pudval_t pud_flags_mask(pud_t pud)
319
static inline pudval_t pud_flags_mask(pud_t pud)
291
{
320
{
292
	return ~pud_pfn_mask(pud);
321
	return ~pud_pfn_mask(pud);
293
}
322
}
294
 
323
 
295
static inline pudval_t pud_flags(pud_t pud)
324
static inline pudval_t pud_flags(pud_t pud)
296
{
325
{
297
	return native_pud_val(pud) & pud_flags_mask(pud);
326
	return native_pud_val(pud) & pud_flags_mask(pud);
298
}
327
}
299
 
328
 
300
static inline pmdval_t pmd_pfn_mask(pmd_t pmd)
329
static inline pmdval_t pmd_pfn_mask(pmd_t pmd)
301
{
330
{
302
	if (native_pmd_val(pmd) & _PAGE_PSE)
331
	if (native_pmd_val(pmd) & _PAGE_PSE)
303
		return PHYSICAL_PMD_PAGE_MASK;
332
		return PHYSICAL_PMD_PAGE_MASK;
304
	else
333
	else
305
		return PTE_PFN_MASK;
334
		return PTE_PFN_MASK;
306
}
335
}
307
 
336
 
308
static inline pmdval_t pmd_flags_mask(pmd_t pmd)
337
static inline pmdval_t pmd_flags_mask(pmd_t pmd)
309
{
338
{
310
	return ~pmd_pfn_mask(pmd);
339
	return ~pmd_pfn_mask(pmd);
311
}
340
}
312
 
341
 
313
static inline pmdval_t pmd_flags(pmd_t pmd)
342
static inline pmdval_t pmd_flags(pmd_t pmd)
314
{
343
{
315
	return native_pmd_val(pmd) & pmd_flags_mask(pmd);
344
	return native_pmd_val(pmd) & pmd_flags_mask(pmd);
316
}
345
}
317
 
346
 
318
static inline pte_t native_make_pte(pteval_t val)
347
static inline pte_t native_make_pte(pteval_t val)
319
{
348
{
320
	return (pte_t) { .pte = val };
349
	return (pte_t) { .pte = val };
321
}
350
}
322
 
351
 
323
static inline pteval_t native_pte_val(pte_t pte)
352
static inline pteval_t native_pte_val(pte_t pte)
324
{
353
{
325
	return pte.pte;
354
	return pte.pte;
326
}
355
}
327
 
356
 
328
static inline pteval_t pte_flags(pte_t pte)
357
static inline pteval_t pte_flags(pte_t pte)
329
{
358
{
330
	return native_pte_val(pte) & PTE_FLAGS_MASK;
359
	return native_pte_val(pte) & PTE_FLAGS_MASK;
331
}
360
}
332
 
361
 
333
#define pgprot_val(x)	((x).pgprot)
362
#define pgprot_val(x)	((x).pgprot)
334
#define __pgprot(x)	((pgprot_t) { (x) } )
363
#define __pgprot(x)	((pgprot_t) { (x) } )
335
 
364
 
336
extern uint16_t __cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM];
365
extern uint16_t __cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM];
337
extern uint8_t __pte2cachemode_tbl[8];
366
extern uint8_t __pte2cachemode_tbl[8];
338
 
367
 
339
#define __pte2cm_idx(cb)				\
368
#define __pte2cm_idx(cb)				\
340
	((((cb) >> (_PAGE_BIT_PAT - 2)) & 4) |		\
369
	((((cb) >> (_PAGE_BIT_PAT - 2)) & 4) |		\
341
	 (((cb) >> (_PAGE_BIT_PCD - 1)) & 2) |		\
370
	 (((cb) >> (_PAGE_BIT_PCD - 1)) & 2) |		\
342
	 (((cb) >> _PAGE_BIT_PWT) & 1))
371
	 (((cb) >> _PAGE_BIT_PWT) & 1))
343
#define __cm_idx2pte(i)					\
372
#define __cm_idx2pte(i)					\
344
	((((i) & 4) << (_PAGE_BIT_PAT - 2)) |		\
373
	((((i) & 4) << (_PAGE_BIT_PAT - 2)) |		\
345
	 (((i) & 2) << (_PAGE_BIT_PCD - 1)) |		\
374
	 (((i) & 2) << (_PAGE_BIT_PCD - 1)) |		\
346
	 (((i) & 1) << _PAGE_BIT_PWT))
375
	 (((i) & 1) << _PAGE_BIT_PWT))
347
 
376
 
348
static inline unsigned long cachemode2protval(enum page_cache_mode pcm)
377
static inline unsigned long cachemode2protval(enum page_cache_mode pcm)
349
{
378
{
350
	if (likely(pcm == 0))
379
	if (likely(pcm == 0))
351
		return 0;
380
		return 0;
352
	return __cachemode2pte_tbl[pcm];
381
	return __cachemode2pte_tbl[pcm];
353
}
382
}
354
static inline pgprot_t cachemode2pgprot(enum page_cache_mode pcm)
383
static inline pgprot_t cachemode2pgprot(enum page_cache_mode pcm)
355
{
384
{
356
	return __pgprot(cachemode2protval(pcm));
385
	return __pgprot(cachemode2protval(pcm));
357
}
386
}
358
static inline enum page_cache_mode pgprot2cachemode(pgprot_t pgprot)
387
static inline enum page_cache_mode pgprot2cachemode(pgprot_t pgprot)
359
{
388
{
360
	unsigned long masked;
389
	unsigned long masked;
361
 
390
 
362
	masked = pgprot_val(pgprot) & _PAGE_CACHE_MASK;
391
	masked = pgprot_val(pgprot) & _PAGE_CACHE_MASK;
363
	if (likely(masked == 0))
392
	if (likely(masked == 0))
364
		return 0;
393
		return 0;
365
	return __pte2cachemode_tbl[__pte2cm_idx(masked)];
394
	return __pte2cachemode_tbl[__pte2cm_idx(masked)];
366
}
395
}
367
static inline pgprot_t pgprot_4k_2_large(pgprot_t pgprot)
396
static inline pgprot_t pgprot_4k_2_large(pgprot_t pgprot)
368
{
397
{
369
	pgprotval_t val = pgprot_val(pgprot);
398
	pgprotval_t val = pgprot_val(pgprot);
370
	pgprot_t new;
399
	pgprot_t new;
371
 
400
 
372
	pgprot_val(new) = (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) |
401
	pgprot_val(new) = (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) |
373
		((val & _PAGE_PAT) << (_PAGE_BIT_PAT_LARGE - _PAGE_BIT_PAT));
402
		((val & _PAGE_PAT) << (_PAGE_BIT_PAT_LARGE - _PAGE_BIT_PAT));
374
	return new;
403
	return new;
375
}
404
}
376
static inline pgprot_t pgprot_large_2_4k(pgprot_t pgprot)
405
static inline pgprot_t pgprot_large_2_4k(pgprot_t pgprot)
377
{
406
{
378
	pgprotval_t val = pgprot_val(pgprot);
407
	pgprotval_t val = pgprot_val(pgprot);
379
	pgprot_t new;
408
	pgprot_t new;
380
 
409
 
381
	pgprot_val(new) = (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) |
410
	pgprot_val(new) = (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) |
382
			  ((val & _PAGE_PAT_LARGE) >>
411
			  ((val & _PAGE_PAT_LARGE) >>
383
			   (_PAGE_BIT_PAT_LARGE - _PAGE_BIT_PAT));
412
			   (_PAGE_BIT_PAT_LARGE - _PAGE_BIT_PAT));
384
	return new;
413
	return new;
385
}
414
}
386
 
415
 
387
 
416
 
388
typedef struct page *pgtable_t;
417
typedef struct page *pgtable_t;
389
 
418
 
390
extern pteval_t __supported_pte_mask;
419
extern pteval_t __supported_pte_mask;
391
extern void set_nx(void);
420
extern void set_nx(void);
392
extern int nx_enabled;
421
extern int nx_enabled;
393
 
422
 
394
#define pgprot_writecombine	pgprot_writecombine
423
#define pgprot_writecombine	pgprot_writecombine
395
extern pgprot_t pgprot_writecombine(pgprot_t prot);
424
extern pgprot_t pgprot_writecombine(pgprot_t prot);
396
 
425
 
397
#define pgprot_writethrough	pgprot_writethrough
426
#define pgprot_writethrough	pgprot_writethrough
398
extern pgprot_t pgprot_writethrough(pgprot_t prot);
427
extern pgprot_t pgprot_writethrough(pgprot_t prot);
399
 
428
 
400
/* Indicate that x86 has its own track and untrack pfn vma functions */
429
/* Indicate that x86 has its own track and untrack pfn vma functions */
401
#define __HAVE_PFNMAP_TRACKING
430
#define __HAVE_PFNMAP_TRACKING
402
 
431
 
403
#define __HAVE_PHYS_MEM_ACCESS_PROT
432
#define __HAVE_PHYS_MEM_ACCESS_PROT
404
struct file;
433
struct file;
405
pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
434
pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
406
                              unsigned long size, pgprot_t vma_prot);
435
                              unsigned long size, pgprot_t vma_prot);
407
int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn,
436
int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn,
408
                              unsigned long size, pgprot_t *vma_prot);
437
                              unsigned long size, pgprot_t *vma_prot);
409
 
438
 
410
/* Install a pte for a particular vaddr in kernel space. */
439
/* Install a pte for a particular vaddr in kernel space. */
411
void set_pte_vaddr(unsigned long vaddr, pte_t pte);
440
void set_pte_vaddr(unsigned long vaddr, pte_t pte);
412
 
441
 
413
#ifdef CONFIG_X86_32
442
#ifdef CONFIG_X86_32
414
extern void native_pagetable_init(void);
443
extern void native_pagetable_init(void);
415
#else
444
#else
416
#define native_pagetable_init        paging_init
445
#define native_pagetable_init        paging_init
417
#endif
446
#endif
418
 
447
 
419
struct seq_file;
448
struct seq_file;
420
extern void arch_report_meminfo(struct seq_file *m);
449
extern void arch_report_meminfo(struct seq_file *m);
421
 
450
 
422
enum pg_level {
451
enum pg_level {
423
	PG_LEVEL_NONE,
452
	PG_LEVEL_NONE,
424
	PG_LEVEL_4K,
453
	PG_LEVEL_4K,
425
	PG_LEVEL_2M,
454
	PG_LEVEL_2M,
426
	PG_LEVEL_1G,
455
	PG_LEVEL_1G,
427
	PG_LEVEL_NUM
456
	PG_LEVEL_NUM
428
};
457
};
429
 
458
 
430
#ifdef CONFIG_PROC_FS
459
#ifdef CONFIG_PROC_FS
431
extern void update_page_count(int level, unsigned long pages);
460
extern void update_page_count(int level, unsigned long pages);
432
#else
461
#else
433
static inline void update_page_count(int level, unsigned long pages) { }
462
static inline void update_page_count(int level, unsigned long pages) { }
434
#endif
463
#endif
435
 
464
 
436
/*
465
/*
437
 * Helper function that returns the kernel pagetable entry controlling
466
 * Helper function that returns the kernel pagetable entry controlling
438
 * the virtual address 'address'. NULL means no pagetable entry present.
467
 * the virtual address 'address'. NULL means no pagetable entry present.
439
 * NOTE: the return type is pte_t but if the pmd is PSE then we return it
468
 * NOTE: the return type is pte_t but if the pmd is PSE then we return it
440
 * as a pte too.
469
 * as a pte too.
441
 */
470
 */
442
extern pte_t *lookup_address(unsigned long address, unsigned int *level);
471
extern pte_t *lookup_address(unsigned long address, unsigned int *level);
443
extern pte_t *lookup_address_in_pgd(pgd_t *pgd, unsigned long address,
472
extern pte_t *lookup_address_in_pgd(pgd_t *pgd, unsigned long address,
444
				    unsigned int *level);
473
				    unsigned int *level);
445
extern pmd_t *lookup_pmd_address(unsigned long address);
474
extern pmd_t *lookup_pmd_address(unsigned long address);
446
extern phys_addr_t slow_virt_to_phys(void *__address);
475
extern phys_addr_t slow_virt_to_phys(void *__address);
447
extern int kernel_map_pages_in_pgd(pgd_t *pgd, u64 pfn, unsigned long address,
476
extern int kernel_map_pages_in_pgd(pgd_t *pgd, u64 pfn, unsigned long address,
448
				   unsigned numpages, unsigned long page_flags);
477
				   unsigned numpages, unsigned long page_flags);
449
void kernel_unmap_pages_in_pgd(pgd_t *root, unsigned long address,
478
void kernel_unmap_pages_in_pgd(pgd_t *root, unsigned long address,
450
			       unsigned numpages);
479
			       unsigned numpages);
451
#endif	/* !__ASSEMBLY__ */
480
#endif	/* !__ASSEMBLY__ */
452
 
481
 
453
#endif /* _ASM_X86_PGTABLE_DEFS_H */
482
#endif /* _ASM_X86_PGTABLE_DEFS_H */