1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef _ASM_TILE_PAGE_H
16#define _ASM_TILE_PAGE_H
17
18#include <linux/const.h>
19#include <hv/hypervisor.h>
20#include <arch/chip.h>
21
22
23#if defined(CONFIG_PAGE_SIZE_16KB)
24#define PAGE_SHIFT 14
25#define CTX_PAGE_FLAG HV_CTX_PG_SM_16K
26#elif defined(CONFIG_PAGE_SIZE_64KB)
27#define PAGE_SHIFT 16
28#define CTX_PAGE_FLAG HV_CTX_PG_SM_64K
29#else
30#define PAGE_SHIFT HV_LOG2_DEFAULT_PAGE_SIZE_SMALL
31#define CTX_PAGE_FLAG 0
32#endif
33#define HPAGE_SHIFT HV_LOG2_DEFAULT_PAGE_SIZE_LARGE
34
35#define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
36#define HPAGE_SIZE (_AC(1, UL) << HPAGE_SHIFT)
37
38#define PAGE_MASK (~(PAGE_SIZE - 1))
39#define HPAGE_MASK (~(HPAGE_SIZE - 1))
40
41
42
43
44
45
46#ifndef CONFIG_FORCE_MAX_ZONEORDER
47#define CONFIG_FORCE_MAX_ZONEORDER (HPAGE_SHIFT - PAGE_SHIFT + 1)
48#endif
49
50#ifndef __ASSEMBLY__
51
52#include <linux/types.h>
53#include <linux/string.h>
54
55struct page;
56
57static inline void clear_page(void *page)
58{
59 memset(page, 0, PAGE_SIZE);
60}
61
62static inline void copy_page(void *to, void *from)
63{
64 memcpy(to, from, PAGE_SIZE);
65}
66
67static inline void clear_user_page(void *page, unsigned long vaddr,
68 struct page *pg)
69{
70 clear_page(page);
71}
72
73static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
74 struct page *topage)
75{
76 copy_page(to, from);
77}
78
79
80
81
82
83typedef HV_PTE pte_t;
84typedef HV_PTE pgd_t;
85typedef HV_PTE pgprot_t;
86
87
88
89
90
91
92
93typedef struct page *pgtable_t;
94
95
96#define __pgprot(val) hv_pte(val)
97
98
99#define __pte(x) hv_pte(x)
100#define __pgd(x) hv_pte(x)
101
102static inline u64 pgprot_val(pgprot_t pgprot)
103{
104 return hv_pte_val(pgprot);
105}
106
107static inline u64 pte_val(pte_t pte)
108{
109 return hv_pte_val(pte);
110}
111
112static inline u64 pgd_val(pgd_t pgd)
113{
114 return hv_pte_val(pgd);
115}
116
117#ifdef __tilegx__
118
119typedef HV_PTE pmd_t;
120
121#define __pmd(x) hv_pte(x)
122
123static inline u64 pmd_val(pmd_t pmd)
124{
125 return hv_pte_val(pmd);
126}
127
128#endif
129
130static inline __attribute_const__ int get_order(unsigned long size)
131{
132 return BITS_PER_LONG - __builtin_clzl((size - 1) >> PAGE_SHIFT);
133}
134
135#endif
136
137#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
138
139#define HUGE_MAX_HSTATE 6
140
141#ifdef CONFIG_HUGETLB_PAGE
142#define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
143#endif
144
145
146#define NR_PA_HIGHBIT_SHIFT (CHIP_PA_WIDTH() - CHIP_LOG_NUM_MSHIMS())
147#define NR_PA_HIGHBIT_VALUES (1 << CHIP_LOG_NUM_MSHIMS())
148#define __pa_to_highbits(pa) ((phys_addr_t)(pa) >> NR_PA_HIGHBIT_SHIFT)
149#define __pfn_to_highbits(pfn) ((pfn) >> (NR_PA_HIGHBIT_SHIFT - PAGE_SHIFT))
150
151#ifdef __tilegx__
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169#if CHIP_PA_WIDTH() + 2 > CHIP_VA_WIDTH()
170# error Too much PA to map with the VA available!
171#endif
172#define HALF_VA_SPACE (_AC(1, UL) << (CHIP_VA_WIDTH() - 1))
173
174#define MEM_LOW_END (HALF_VA_SPACE - 1)
175#define MEM_HIGH_START (-HALF_VA_SPACE)
176#define PAGE_OFFSET MEM_HIGH_START
177#define FIXADDR_BASE _AC(0xfffffff400000000, UL)
178#define FIXADDR_TOP _AC(0xfffffff500000000, UL)
179#define _VMALLOC_START FIXADDR_TOP
180#define HUGE_VMAP_BASE _AC(0xfffffff600000000, UL)
181#define MEM_SV_START _AC(0xfffffff700000000, UL)
182#define MEM_SV_INTRPT MEM_SV_START
183#define MEM_MODULE_START _AC(0xfffffff710000000, UL)
184#define MEM_MODULE_END (MEM_MODULE_START + (256*1024*1024))
185#define MEM_HV_START _AC(0xfffffff800000000, UL)
186
187
188#define KERNEL_HIGH_VADDR MEM_SV_START
189
190#else
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220#define MEM_USER_INTRPT _AC(0xfc000000, UL)
221#if CONFIG_KERNEL_PL == 1
222#define MEM_SV_INTRPT _AC(0xfd000000, UL)
223#define MEM_HV_INTRPT _AC(0xfe000000, UL)
224#else
225#define MEM_GUEST_INTRPT _AC(0xfd000000, UL)
226#define MEM_SV_INTRPT _AC(0xfe000000, UL)
227#define MEM_HV_INTRPT _AC(0xff000000, UL)
228#endif
229
230#define INTRPT_SIZE 0x4000
231
232
233#if PAGE_SIZE > INTRPT_SIZE
234#undef INTRPT_SIZE
235#define INTRPT_SIZE PAGE_SIZE
236#endif
237
238#define KERNEL_HIGH_VADDR MEM_USER_INTRPT
239#define FIXADDR_TOP (KERNEL_HIGH_VADDR - PAGE_SIZE)
240
241#define PAGE_OFFSET _AC(CONFIG_PAGE_OFFSET, UL)
242
243
244#define MEM_MODULE_START VMALLOC_START
245#define MEM_MODULE_END VMALLOC_END
246
247#endif
248
249#ifndef __ASSEMBLY__
250
251#ifdef CONFIG_HIGHMEM
252
253
254extern unsigned long pbase_map[];
255extern void *vbase_map[];
256
257static inline unsigned long kaddr_to_pfn(const volatile void *_kaddr)
258{
259 unsigned long kaddr = (unsigned long)_kaddr;
260 return pbase_map[kaddr >> HPAGE_SHIFT] +
261 ((kaddr & (HPAGE_SIZE - 1)) >> PAGE_SHIFT);
262}
263
264static inline void *pfn_to_kaddr(unsigned long pfn)
265{
266 return vbase_map[__pfn_to_highbits(pfn)] + (pfn << PAGE_SHIFT);
267}
268
269static inline phys_addr_t virt_to_phys(const volatile void *kaddr)
270{
271 unsigned long pfn = kaddr_to_pfn(kaddr);
272 return ((phys_addr_t)pfn << PAGE_SHIFT) +
273 ((unsigned long)kaddr & (PAGE_SIZE-1));
274}
275
276static inline void *phys_to_virt(phys_addr_t paddr)
277{
278 return pfn_to_kaddr(paddr >> PAGE_SHIFT) + (paddr & (PAGE_SIZE-1));
279}
280
281
282static inline int virt_addr_valid(const volatile void *kaddr)
283{
284 extern void *high_memory;
285 return ((unsigned long)kaddr >= PAGE_OFFSET && kaddr < high_memory);
286}
287
288#else
289
290static inline unsigned long kaddr_to_pfn(const volatile void *kaddr)
291{
292 return ((unsigned long)kaddr - PAGE_OFFSET) >> PAGE_SHIFT;
293}
294
295static inline void *pfn_to_kaddr(unsigned long pfn)
296{
297 return (void *)((pfn << PAGE_SHIFT) + PAGE_OFFSET);
298}
299
300static inline phys_addr_t virt_to_phys(const volatile void *kaddr)
301{
302 return (phys_addr_t)((unsigned long)kaddr - PAGE_OFFSET);
303}
304
305static inline void *phys_to_virt(phys_addr_t paddr)
306{
307 return (void *)((unsigned long)paddr + PAGE_OFFSET);
308}
309
310
311#define virt_addr_valid(kaddr) pfn_valid(kaddr_to_pfn(kaddr))
312
313#endif
314
315
316#define __pa(kaddr) virt_to_phys((void *)(unsigned long)(kaddr))
317#define __va(paddr) phys_to_virt((phys_addr_t)(paddr))
318
319extern int devmem_is_allowed(unsigned long pagenr);
320
321#ifdef CONFIG_FLATMEM
322static inline int pfn_valid(unsigned long pfn)
323{
324 return pfn < max_mapnr;
325}
326#endif
327
328
329#define page_to_pa(page) ((phys_addr_t)(page_to_pfn(page)) << PAGE_SHIFT)
330#define virt_to_page(kaddr) pfn_to_page(kaddr_to_pfn((void *)(kaddr)))
331#define page_to_virt(page) pfn_to_kaddr(page_to_pfn(page))
332
333struct mm_struct;
334extern pte_t *virt_to_pte(struct mm_struct *mm, unsigned long addr);
335
336#endif
337
338#define VM_DATA_DEFAULT_FLAGS \
339 (VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
340
341#include <asm-generic/memory_model.h>
342
343#endif
344