tile: implement gettimeofday() via vDSO
[deliverable/linux.git] / arch / tile / include / asm / page.h
CommitLineData
867e359b
CM
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_PAGE_H
16#define _ASM_TILE_PAGE_H
17
18#include <linux/const.h>
5386e735
CM
19#include <hv/hypervisor.h>
20#include <arch/chip.h>
867e359b
CM
21
22/* PAGE_SHIFT and HPAGE_SHIFT determine the page sizes. */
d5d14ed6
CM
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
867e359b
CM
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
4a556f4f
CM
41/*
42 * We do define AT_SYSINFO_EHDR to support vDSO,
43 * but don't use the gate mechanism.
44 */
45#define __HAVE_ARCH_GATE_AREA 1
46
867e359b 47/*
76c567fb
CM
48 * If the Kconfig doesn't specify, set a maximum zone order that
49 * is enough so that we can create huge pages from small pages given
50 * the respective sizes of the two page types. See <linux/mmzone.h>.
867e359b 51 */
76c567fb
CM
52#ifndef CONFIG_FORCE_MAX_ZONEORDER
53#define CONFIG_FORCE_MAX_ZONEORDER (HPAGE_SHIFT - PAGE_SHIFT + 1)
867e359b
CM
54#endif
55
56#ifndef __ASSEMBLY__
57
58#include <linux/types.h>
59#include <linux/string.h>
60
61struct page;
62
63static inline void clear_page(void *page)
64{
65 memset(page, 0, PAGE_SIZE);
66}
67
68static inline void copy_page(void *to, void *from)
69{
70 memcpy(to, from, PAGE_SIZE);
71}
72
73static inline void clear_user_page(void *page, unsigned long vaddr,
74 struct page *pg)
75{
76 clear_page(page);
77}
78
79static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
80 struct page *topage)
81{
82 copy_page(to, from);
83}
84
85/*
86 * Hypervisor page tables are made of the same basic structure.
87 */
88
867e359b
CM
89typedef HV_PTE pte_t;
90typedef HV_PTE pgd_t;
91typedef HV_PTE pgprot_t;
92
93/*
94 * User L2 page tables are managed as one L2 page table per page,
95 * because we use the page allocator for them. This keeps the allocation
621b1955 96 * simple, but it's also inefficient, since L2 page tables are much smaller
867e359b
CM
97 * than pages (currently 2KB vs 64KB). So we should revisit this.
98 */
99typedef struct page *pgtable_t;
100
101/* Must be a macro since it is used to create constants. */
102#define __pgprot(val) hv_pte(val)
103
28d71741
CM
104/* Rarely-used initializers, typically with a "zero" value. */
105#define __pte(x) hv_pte(x)
106#define __pgd(x) hv_pte(x)
107
867e359b
CM
108static inline u64 pgprot_val(pgprot_t pgprot)
109{
110 return hv_pte_val(pgprot);
111}
112
113static inline u64 pte_val(pte_t pte)
114{
115 return hv_pte_val(pte);
116}
117
118static inline u64 pgd_val(pgd_t pgd)
119{
120 return hv_pte_val(pgd);
121}
122
123#ifdef __tilegx__
124
125typedef HV_PTE pmd_t;
126
28d71741
CM
127#define __pmd(x) hv_pte(x)
128
867e359b
CM
129static inline u64 pmd_val(pmd_t pmd)
130{
131 return hv_pte_val(pmd);
132}
133
134#endif
135
c745a8a1
CM
136static inline __attribute_const__ int get_order(unsigned long size)
137{
138 return BITS_PER_LONG - __builtin_clzl((size - 1) >> PAGE_SHIFT);
139}
140
867e359b
CM
141#endif /* !__ASSEMBLY__ */
142
143#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
144
621b1955 145#define HUGE_MAX_HSTATE 6
867e359b
CM
146
147#ifdef CONFIG_HUGETLB_PAGE
148#define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
149#endif
150
151/* Each memory controller has PAs distinct in their high bits. */
152#define NR_PA_HIGHBIT_SHIFT (CHIP_PA_WIDTH() - CHIP_LOG_NUM_MSHIMS())
153#define NR_PA_HIGHBIT_VALUES (1 << CHIP_LOG_NUM_MSHIMS())
154#define __pa_to_highbits(pa) ((phys_addr_t)(pa) >> NR_PA_HIGHBIT_SHIFT)
155#define __pfn_to_highbits(pfn) ((pfn) >> (NR_PA_HIGHBIT_SHIFT - PAGE_SHIFT))
156
157#ifdef __tilegx__
158
159/*
160 * We reserve the lower half of memory for user-space programs, and the
161 * upper half for system code. We re-map all of physical memory in the
162 * upper half, which takes a quarter of our VA space. Then we have
163 * the vmalloc regions. The supervisor code lives at 0xfffffff700000000,
164 * with the hypervisor above that.
165 *
166 * Loadable kernel modules are placed immediately after the static
167 * supervisor code, with each being allocated a 256MB region of
168 * address space, so we don't have to worry about the range of "jal"
169 * and other branch instructions.
170 *
171 * For now we keep life simple and just allocate one pmd (4GB) for vmalloc.
172 * Similarly, for now we don't play any struct page mapping games.
173 */
174
175#if CHIP_PA_WIDTH() + 2 > CHIP_VA_WIDTH()
176# error Too much PA to map with the VA available!
177#endif
178#define HALF_VA_SPACE (_AC(1, UL) << (CHIP_VA_WIDTH() - 1))
179
180#define MEM_LOW_END (HALF_VA_SPACE - 1) /* low half */
181#define MEM_HIGH_START (-HALF_VA_SPACE) /* high half */
182#define PAGE_OFFSET MEM_HIGH_START
bbaa22c3
CM
183#define FIXADDR_BASE _AC(0xfffffff400000000, UL) /* 4 GB */
184#define FIXADDR_TOP _AC(0xfffffff500000000, UL) /* 4 GB */
185#define _VMALLOC_START FIXADDR_TOP
867e359b
CM
186#define HUGE_VMAP_BASE _AC(0xfffffff600000000, UL) /* 4 GB */
187#define MEM_SV_START _AC(0xfffffff700000000, UL) /* 256 MB */
188#define MEM_SV_INTRPT MEM_SV_START
189#define MEM_MODULE_START _AC(0xfffffff710000000, UL) /* 256 MB */
190#define MEM_MODULE_END (MEM_MODULE_START + (256*1024*1024))
191#define MEM_HV_START _AC(0xfffffff800000000, UL) /* 32 GB */
192
193/* Highest DTLB address we will use */
194#define KERNEL_HIGH_VADDR MEM_SV_START
195
867e359b
CM
196#else /* !__tilegx__ */
197
198/*
199 * A PAGE_OFFSET of 0xC0000000 means that the kernel has
200 * a virtual address space of one gigabyte, which limits the
201 * amount of physical memory you can use to about 768MB.
202 * If you want more physical memory than this then see the CONFIG_HIGHMEM
203 * option in the kernel configuration.
204 *
a78c942d
CM
205 * The top 16MB chunk in the table below is unavailable to Linux. Since
206 * the kernel interrupt vectors must live at ether 0xfe000000 or 0xfd000000
207 * (depending on whether the kernel is at PL2 or Pl1), we map all of the
208 * bottom of RAM at this address with a huge page table entry to minimize
209 * its ITLB footprint (as well as at PAGE_OFFSET). The last architected
210 * requirement is that user interrupt vectors live at 0xfc000000, so we
211 * make that range of memory available to user processes. The remaining
212 * regions are sized as shown; the first four addresses use the PL 1
213 * values, and after that, we show "typical" values, since the actual
214 * addresses depend on kernel #defines.
867e359b 215 *
867e359b
CM
216 * MEM_HV_INTRPT 0xfe000000
217 * MEM_SV_INTRPT (kernel code) 0xfd000000
218 * MEM_USER_INTRPT (user vector) 0xfc000000
219 * FIX_KMAP_xxx 0xf8000000 (via NR_CPUS * KM_TYPE_NR)
220 * PKMAP_BASE 0xf7000000 (via LAST_PKMAP)
221 * HUGE_VMAP 0xf3000000 (via CONFIG_NR_HUGE_VMAPS)
222 * VMALLOC_START 0xf0000000 (via __VMALLOC_RESERVE)
223 * mapped LOWMEM 0xc0000000
224 */
225
226#define MEM_USER_INTRPT _AC(0xfc000000, UL)
a78c942d 227#if CONFIG_KERNEL_PL == 1
867e359b
CM
228#define MEM_SV_INTRPT _AC(0xfd000000, UL)
229#define MEM_HV_INTRPT _AC(0xfe000000, UL)
a78c942d
CM
230#else
231#define MEM_GUEST_INTRPT _AC(0xfd000000, UL)
232#define MEM_SV_INTRPT _AC(0xfe000000, UL)
233#define MEM_HV_INTRPT _AC(0xff000000, UL)
234#endif
867e359b
CM
235
236#define INTRPT_SIZE 0x4000
237
238/* Tolerate page size larger than the architecture interrupt region size. */
239#if PAGE_SIZE > INTRPT_SIZE
240#undef INTRPT_SIZE
241#define INTRPT_SIZE PAGE_SIZE
242#endif
243
244#define KERNEL_HIGH_VADDR MEM_USER_INTRPT
245#define FIXADDR_TOP (KERNEL_HIGH_VADDR - PAGE_SIZE)
246
247#define PAGE_OFFSET _AC(CONFIG_PAGE_OFFSET, UL)
248
249/* On 32-bit architectures we mix kernel modules in with other vmaps. */
250#define MEM_MODULE_START VMALLOC_START
251#define MEM_MODULE_END VMALLOC_END
252
253#endif /* __tilegx__ */
254
4a556f4f 255#if !defined(__ASSEMBLY__) && !defined(VDSO_BUILD)
867e359b
CM
256
257#ifdef CONFIG_HIGHMEM
258
259/* Map kernel virtual addresses to page frames, in HPAGE_SIZE chunks. */
260extern unsigned long pbase_map[];
261extern void *vbase_map[];
262
263static inline unsigned long kaddr_to_pfn(const volatile void *_kaddr)
264{
265 unsigned long kaddr = (unsigned long)_kaddr;
266 return pbase_map[kaddr >> HPAGE_SHIFT] +
267 ((kaddr & (HPAGE_SIZE - 1)) >> PAGE_SHIFT);
268}
269
270static inline void *pfn_to_kaddr(unsigned long pfn)
271{
272 return vbase_map[__pfn_to_highbits(pfn)] + (pfn << PAGE_SHIFT);
273}
274
275static inline phys_addr_t virt_to_phys(const volatile void *kaddr)
276{
277 unsigned long pfn = kaddr_to_pfn(kaddr);
278 return ((phys_addr_t)pfn << PAGE_SHIFT) +
279 ((unsigned long)kaddr & (PAGE_SIZE-1));
280}
281
282static inline void *phys_to_virt(phys_addr_t paddr)
283{
284 return pfn_to_kaddr(paddr >> PAGE_SHIFT) + (paddr & (PAGE_SIZE-1));
285}
286
287/* With HIGHMEM, we pack PAGE_OFFSET through high_memory with all valid VAs. */
288static inline int virt_addr_valid(const volatile void *kaddr)
289{
290 extern void *high_memory; /* copied from <linux/mm.h> */
291 return ((unsigned long)kaddr >= PAGE_OFFSET && kaddr < high_memory);
292}
293
294#else /* !CONFIG_HIGHMEM */
295
296static inline unsigned long kaddr_to_pfn(const volatile void *kaddr)
297{
298 return ((unsigned long)kaddr - PAGE_OFFSET) >> PAGE_SHIFT;
299}
300
301static inline void *pfn_to_kaddr(unsigned long pfn)
302{
303 return (void *)((pfn << PAGE_SHIFT) + PAGE_OFFSET);
304}
305
306static inline phys_addr_t virt_to_phys(const volatile void *kaddr)
307{
308 return (phys_addr_t)((unsigned long)kaddr - PAGE_OFFSET);
309}
310
311static inline void *phys_to_virt(phys_addr_t paddr)
312{
313 return (void *)((unsigned long)paddr + PAGE_OFFSET);
314}
315
316/* Check that the given address is within some mapped range of PAs. */
317#define virt_addr_valid(kaddr) pfn_valid(kaddr_to_pfn(kaddr))
318
319#endif /* !CONFIG_HIGHMEM */
320
321/* All callers are not consistent in how they call these functions. */
322#define __pa(kaddr) virt_to_phys((void *)(unsigned long)(kaddr))
323#define __va(paddr) phys_to_virt((phys_addr_t)(paddr))
324
325extern int devmem_is_allowed(unsigned long pagenr);
326
327#ifdef CONFIG_FLATMEM
328static inline int pfn_valid(unsigned long pfn)
329{
330 return pfn < max_mapnr;
331}
332#endif
333
334/* Provide as macros since these require some other headers included. */
335#define page_to_pa(page) ((phys_addr_t)(page_to_pfn(page)) << PAGE_SHIFT)
28d71741 336#define virt_to_page(kaddr) pfn_to_page(kaddr_to_pfn((void *)(kaddr)))
867e359b
CM
337#define page_to_virt(page) pfn_to_kaddr(page_to_pfn(page))
338
339struct mm_struct;
340extern pte_t *virt_to_pte(struct mm_struct *mm, unsigned long addr);
341
342#endif /* !__ASSEMBLY__ */
343
344#define VM_DATA_DEFAULT_FLAGS \
345 (VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
346
347#include <asm-generic/memory_model.h>
867e359b
CM
348
349#endif /* _ASM_TILE_PAGE_H */
This page took 0.183135 seconds and 5 git commands to generate.