blob: 3efc3288f7e9ce67afa7ab39af2baf84214382dc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _PPC64_PAGE_H
2#define _PPC64_PAGE_H
3
4/*
5 * Copyright (C) 2001 PPC64 Team, IBM Corp
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 */
12
13#include <linux/config.h>
David Gibson3ddfbcf2005-11-10 12:56:55 +110014#include <asm/asm-compat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +110016/*
17 * We support either 4k or 64k software page size. When using 64k pages
18 * however, wether we are really supporting 64k pages in HW or not is
19 * irrelevant to those definitions. We always define HW_PAGE_SHIFT to 12
20 * as use of 64k pages remains a linux kernel specific, every notion of
21 * page number shared with the firmware, TCEs, iommu, etc... still assumes
22 * a page size of 4096.
23 */
24#ifdef CONFIG_PPC_64K_PAGES
25#define PAGE_SHIFT 16
26#else
27#define PAGE_SHIFT 12
28#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +110030#define PAGE_SIZE (ASM_CONST(1) << PAGE_SHIFT)
31#define PAGE_MASK (~(PAGE_SIZE-1))
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +110033/* HW_PAGE_SHIFT is always 4k pages */
34#define HW_PAGE_SHIFT 12
35#define HW_PAGE_SIZE (ASM_CONST(1) << HW_PAGE_SHIFT)
36#define HW_PAGE_MASK (~(HW_PAGE_SIZE-1))
37
38/* PAGE_FACTOR is the number of bits factor between PAGE_SHIFT and
39 * HW_PAGE_SHIFT, that is 4k pages
40 */
41#define PAGE_FACTOR (PAGE_SHIFT - HW_PAGE_SHIFT)
42
43/* Segment size */
44#define SID_SHIFT 28
45#define SID_MASK 0xfffffffffUL
46#define ESID_MASK 0xfffffffff0000000UL
47#define GET_ESID(x) (((x) >> SID_SHIFT) & SID_MASK)
48
49/* Large pages size */
50
51#ifndef __ASSEMBLY__
52extern unsigned int HPAGE_SHIFT;
53#define HPAGE_SIZE ((1UL) << HPAGE_SHIFT)
54#define HPAGE_MASK (~(HPAGE_SIZE - 1))
55#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
56#endif /* __ASSEMBLY__ */
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58#ifdef CONFIG_HUGETLB_PAGE
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
David Gibsonc594ada2005-08-11 16:55:21 +100061#define HTLB_AREA_SHIFT 40
62#define HTLB_AREA_SIZE (1UL << HTLB_AREA_SHIFT)
63#define GET_HTLB_AREA(x) ((x) >> HTLB_AREA_SHIFT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +110065#define LOW_ESID_MASK(addr, len) (((1U << (GET_ESID(addr+len-1)+1)) \
66 - (1U << GET_ESID(addr))) & 0xffff)
67#define HTLB_AREA_MASK(addr, len) (((1U << (GET_HTLB_AREA(addr+len-1)+1)) \
68 - (1U << GET_HTLB_AREA(addr))) & 0xffff)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70#define ARCH_HAS_HUGEPAGE_ONLY_RANGE
71#define ARCH_HAS_PREPARE_HUGEPAGE_RANGE
David Gibsone28f7fa2005-08-05 19:39:06 +100072#define ARCH_HAS_SETCLEAR_HUGE_PTE
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74#define touches_hugepage_low_range(mm, addr, len) \
David Gibsonc594ada2005-08-11 16:55:21 +100075 (LOW_ESID_MASK((addr), (len)) & (mm)->context.low_htlb_areas)
76#define touches_hugepage_high_range(mm, addr, len) \
77 (HTLB_AREA_MASK((addr), (len)) & (mm)->context.high_htlb_areas)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79#define __within_hugepage_low_range(addr, len, segmask) \
80 ((LOW_ESID_MASK((addr), (len)) | (segmask)) == (segmask))
81#define within_hugepage_low_range(addr, len) \
82 __within_hugepage_low_range((addr), (len), \
David Gibsonc594ada2005-08-11 16:55:21 +100083 current->mm->context.low_htlb_areas)
84#define __within_hugepage_high_range(addr, len, zonemask) \
85 ((HTLB_AREA_MASK((addr), (len)) | (zonemask)) == (zonemask))
86#define within_hugepage_high_range(addr, len) \
87 __within_hugepage_high_range((addr), (len), \
88 current->mm->context.high_htlb_areas)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90#define is_hugepage_only_range(mm, addr, len) \
David Gibsonc594ada2005-08-11 16:55:21 +100091 (touches_hugepage_high_range((mm), (addr), (len)) || \
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 touches_hugepage_low_range((mm), (addr), (len)))
93#define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
94
95#define in_hugepage_area(context, addr) \
96 (cpu_has_feature(CPU_FTR_16M_PAGE) && \
David Gibsonc594ada2005-08-11 16:55:21 +100097 ( ((1 << GET_HTLB_AREA(addr)) & (context).high_htlb_areas) || \
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 ( ((addr) < 0x100000000L) && \
David Gibsonc594ada2005-08-11 16:55:21 +100099 ((1 << GET_ESID(addr)) & (context).low_htlb_areas) ) ) )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101#else /* !CONFIG_HUGETLB_PAGE */
102
103#define in_hugepage_area(mm, addr) 0
104
105#endif /* !CONFIG_HUGETLB_PAGE */
106
107/* align addr on a size boundary - adjust address up/down if needed */
108#define _ALIGN_UP(addr,size) (((addr)+((size)-1))&(~((size)-1)))
109#define _ALIGN_DOWN(addr,size) ((addr)&(~((size)-1)))
110
111/* align addr on a size boundary - adjust address up if needed */
112#define _ALIGN(addr,size) _ALIGN_UP(addr,size)
113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114/* to align the pointer to the (next) page boundary */
115#define PAGE_ALIGN(addr) _ALIGN(addr, PAGE_SIZE)
116
117#ifdef __KERNEL__
118#ifndef __ASSEMBLY__
119#include <asm/cache.h>
120
121#undef STRICT_MM_TYPECHECKS
122
123#define REGION_SIZE 4UL
124#define REGION_SHIFT 60UL
125#define REGION_MASK (((1UL<<REGION_SIZE)-1UL)<<REGION_SHIFT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
127static __inline__ void clear_page(void *addr)
128{
129 unsigned long lines, line_size;
130
131 line_size = ppc64_caches.dline_size;
132 lines = ppc64_caches.dlines_per_page;
133
134 __asm__ __volatile__(
135 "mtctr %1 # clear_page\n\
1361: dcbz 0,%0\n\
137 add %0,%0,%3\n\
138 bdnz+ 1b"
139 : "=r" (addr)
140 : "r" (lines), "0" (addr), "r" (line_size)
141 : "ctr", "memory");
142}
143
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100144extern void copy_4K_page(void *to, void *from);
145
146#ifdef CONFIG_PPC_64K_PAGES
147static inline void copy_page(void *to, void *from)
148{
149 unsigned int i;
150 for (i=0; i < (1 << (PAGE_SHIFT - 12)); i++) {
151 copy_4K_page(to, from);
152 to += 4096;
153 from += 4096;
154 }
155}
156#else /* CONFIG_PPC_64K_PAGES */
157static inline void copy_page(void *to, void *from)
158{
159 copy_4K_page(to, from);
160}
161#endif /* CONFIG_PPC_64K_PAGES */
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163struct page;
164extern void clear_user_page(void *page, unsigned long vaddr, struct page *pg);
165extern void copy_user_page(void *to, void *from, unsigned long vaddr, struct page *p);
166
167#ifdef STRICT_MM_TYPECHECKS
168/*
169 * These are used to make use of C type-checking.
170 * Entries in the pte table are 64b, while entries in the pgd & pmd are 32b.
171 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100172
173/* PTE level */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174typedef struct { unsigned long pte; } pte_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175#define pte_val(x) ((x).pte)
David Gibsone28f7fa2005-08-05 19:39:06 +1000176#define __pte(x) ((pte_t) { (x) })
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100177
178/* 64k pages additionally define a bigger "real PTE" type that gathers
179 * the "second half" part of the PTE for pseudo 64k pages
180 */
181#ifdef CONFIG_PPC_64K_PAGES
182typedef struct { pte_t pte; unsigned long hidx; } real_pte_t;
183#else
184typedef struct { pte_t pte; } real_pte_t;
185#endif
186
187/* PMD level */
188typedef struct { unsigned long pmd; } pmd_t;
189#define pmd_val(x) ((x).pmd)
David Gibsone28f7fa2005-08-05 19:39:06 +1000190#define __pmd(x) ((pmd_t) { (x) })
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100191
192/* PUD level exusts only on 4k pages */
193#ifndef CONFIG_PPC_64K_PAGES
194typedef struct { unsigned long pud; } pud_t;
195#define pud_val(x) ((x).pud)
David Gibsone28f7fa2005-08-05 19:39:06 +1000196#define __pud(x) ((pud_t) { (x) })
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100197#endif
198
199/* PGD level */
200typedef struct { unsigned long pgd; } pgd_t;
201#define pgd_val(x) ((x).pgd)
David Gibsone28f7fa2005-08-05 19:39:06 +1000202#define __pgd(x) ((pgd_t) { (x) })
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100203
204/* Page protection bits */
205typedef struct { unsigned long pgprot; } pgprot_t;
206#define pgprot_val(x) ((x).pgprot)
David Gibsone28f7fa2005-08-05 19:39:06 +1000207#define __pgprot(x) ((pgprot_t) { (x) })
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
209#else
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211/*
212 * .. while these make it easier on the compiler
213 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100215typedef unsigned long pte_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216#define pte_val(x) (x)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100217#define __pte(x) (x)
218
219#ifdef CONFIG_PPC_64K_PAGES
220typedef struct { pte_t pte; unsigned long hidx; } real_pte_t;
221#else
222typedef unsigned long real_pte_t;
223#endif
224
225
226typedef unsigned long pmd_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227#define pmd_val(x) (x)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100228#define __pmd(x) (x)
229
230#ifndef CONFIG_PPC_64K_PAGES
231typedef unsigned long pud_t;
David Gibsone28f7fa2005-08-05 19:39:06 +1000232#define pud_val(x) (x)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100233#define __pud(x) (x)
234#endif
235
236typedef unsigned long pgd_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237#define pgd_val(x) (x)
238#define pgprot_val(x) (x)
239
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100240typedef unsigned long pgprot_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241#define __pgd(x) (x)
242#define __pgprot(x) (x)
243
244#endif
245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246#define __pa(x) ((unsigned long)(x)-PAGE_OFFSET)
247
248extern int page_is_ram(unsigned long pfn);
249
250extern u64 ppc64_pft_size; /* Log 2 of page table size */
251
252/* We do define AT_SYSINFO_EHDR but don't use the gate mecanism */
253#define __HAVE_ARCH_GATE_AREA 1
254
255#endif /* __ASSEMBLY__ */
256
257#ifdef MODULE
258#define __page_aligned __attribute__((__aligned__(PAGE_SIZE)))
259#else
260#define __page_aligned \
261 __attribute__((__aligned__(PAGE_SIZE), \
262 __section__(".data.page_aligned")))
263#endif
264
265
266/* This must match the -Ttext linker address */
267/* Note: tophys & tovirt make assumptions about how */
268/* KERNELBASE is defined for performance reasons. */
269/* When KERNELBASE moves, those macros may have */
270/* to change! */
271#define PAGE_OFFSET ASM_CONST(0xC000000000000000)
272#define KERNELBASE PAGE_OFFSET
273#define VMALLOCBASE ASM_CONST(0xD000000000000000)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
David Gibson1f8d4192005-05-05 16:15:13 -0700275#define VMALLOC_REGION_ID (VMALLOCBASE >> REGION_SHIFT)
276#define KERNEL_REGION_ID (KERNELBASE >> REGION_SHIFT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277#define USER_REGION_ID (0UL)
David Gibson1f8d4192005-05-05 16:15:13 -0700278#define REGION_ID(ea) (((unsigned long)(ea)) >> REGION_SHIFT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280#define __va(x) ((void *)((unsigned long)(x) + KERNELBASE))
281
Andy Whitcroft145e6642005-06-23 00:08:03 -0700282#ifdef CONFIG_FLATMEM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283#define pfn_to_page(pfn) (mem_map + (pfn))
284#define page_to_pfn(page) ((unsigned long)((page) - mem_map))
285#define pfn_valid(pfn) ((pfn) < max_mapnr)
286#endif
287
288#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
289#define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
290
291#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
292
293/*
294 * Unfortunately the PLT is in the BSS in the PPC32 ELF ABI,
295 * and needs to be executable. This means the whole heap ends
296 * up being executable.
297 */
298#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
299 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
300
301#define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
302 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
303
304#define VM_DATA_DEFAULT_FLAGS \
305 (test_thread_flag(TIF_32BIT) ? \
306 VM_DATA_DEFAULT_FLAGS32 : VM_DATA_DEFAULT_FLAGS64)
307
308/*
309 * This is the default if a program doesn't have a PT_GNU_STACK
Anton Blancharda2f95a52005-05-01 08:58:45 -0700310 * program header entry. The PPC64 ELF ABI has a non executable stack
311 * stack by default, so in the absense of a PT_GNU_STACK program header
312 * we turn execute permission off.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 */
Anton Blancharda2f95a52005-05-01 08:58:45 -0700314#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
315 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
316
317#define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
318 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
319
320#define VM_STACK_DEFAULT_FLAGS \
321 (test_thread_flag(TIF_32BIT) ? \
322 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
324#endif /* __KERNEL__ */
Stephen Rothwellfd4fd5a2005-09-03 15:54:30 -0700325
326#include <asm-generic/page.h>
327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328#endif /* _PPC64_PAGE_H */