blob: 3fb061bab9ecd75f0fc912d23fc7cbb71f5c45c7 [file] [log] [blame]
Michael Ellerman5cd16ee2005-11-11 14:25:24 +11001#ifndef _ASM_POWERPC_PAGE_64_H
2#define _ASM_POWERPC_PAGE_64_H
Arnd Bergmann88ced032005-12-16 22:43:46 +01003#ifdef __KERNEL__
Michael Ellerman5cd16ee2005-11-11 14:25:24 +11004
5/*
6 * Copyright (C) 2001 PPC64 Team, IBM Corp
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
12 */
13
14/*
15 * We always define HW_PAGE_SHIFT to 12 as use of 64K pages remains Linux
16 * specific, every notion of page number shared with the firmware, TCEs,
17 * iommu, etc... still uses a page size of 4K.
18 */
19#define HW_PAGE_SHIFT 12
20#define HW_PAGE_SIZE (ASM_CONST(1) << HW_PAGE_SHIFT)
21#define HW_PAGE_MASK (~(HW_PAGE_SIZE-1))
22
23/*
24 * PAGE_FACTOR is the number of bits factor between PAGE_SHIFT and
25 * HW_PAGE_SHIFT, that is 4K pages.
26 */
27#define PAGE_FACTOR (PAGE_SHIFT - HW_PAGE_SHIFT)
28
Michael Ellerman5cd16ee2005-11-11 14:25:24 +110029/* Segment size */
30#define SID_SHIFT 28
31#define SID_MASK 0xfffffffffUL
32#define ESID_MASK 0xfffffffff0000000UL
33#define GET_ESID(x) (((x) >> SID_SHIFT) & SID_MASK)
34
35#ifndef __ASSEMBLY__
36#include <asm/cache.h>
37
38typedef unsigned long pte_basic_t;
39
40static __inline__ void clear_page(void *addr)
41{
42 unsigned long lines, line_size;
43
44 line_size = ppc64_caches.dline_size;
45 lines = ppc64_caches.dlines_per_page;
46
47 __asm__ __volatile__(
48 "mtctr %1 # clear_page\n\
491: dcbz 0,%0\n\
50 add %0,%0,%3\n\
51 bdnz+ 1b"
52 : "=r" (addr)
53 : "r" (lines), "0" (addr), "r" (line_size)
54 : "ctr", "memory");
55}
56
57extern void copy_4K_page(void *to, void *from);
58
59#ifdef CONFIG_PPC_64K_PAGES
60static inline void copy_page(void *to, void *from)
61{
62 unsigned int i;
63 for (i=0; i < (1 << (PAGE_SHIFT - 12)); i++) {
64 copy_4K_page(to, from);
65 to += 4096;
66 from += 4096;
67 }
68}
69#else /* CONFIG_PPC_64K_PAGES */
70static inline void copy_page(void *to, void *from)
71{
72 copy_4K_page(to, from);
73}
74#endif /* CONFIG_PPC_64K_PAGES */
75
76/* Log 2 of page table size */
77extern u64 ppc64_pft_size;
78
79/* Large pages size */
Andy Whitcroftb50ce232005-11-18 01:11:02 -080080#ifdef CONFIG_HUGETLB_PAGE
Michael Ellerman5cd16ee2005-11-11 14:25:24 +110081extern unsigned int HPAGE_SHIFT;
Andy Whitcroftb50ce232005-11-18 01:11:02 -080082#else
83#define HPAGE_SHIFT PAGE_SHIFT
84#endif
Michael Ellerman5cd16ee2005-11-11 14:25:24 +110085#define HPAGE_SIZE ((1UL) << HPAGE_SHIFT)
86#define HPAGE_MASK (~(HPAGE_SIZE - 1))
87#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
88
89#endif /* __ASSEMBLY__ */
90
91#ifdef CONFIG_HUGETLB_PAGE
92
93#define HTLB_AREA_SHIFT 40
94#define HTLB_AREA_SIZE (1UL << HTLB_AREA_SHIFT)
95#define GET_HTLB_AREA(x) ((x) >> HTLB_AREA_SHIFT)
96
David Gibson9a94c572005-11-24 13:34:56 +110097#define LOW_ESID_MASK(addr, len) \
98 (((1U << (GET_ESID(min((addr)+(len)-1, 0x100000000UL))+1)) \
99 - (1U << GET_ESID(min((addr), 0x100000000UL)))) & 0xffff)
Michael Ellerman5cd16ee2005-11-11 14:25:24 +1100100#define HTLB_AREA_MASK(addr, len) (((1U << (GET_HTLB_AREA(addr+len-1)+1)) \
101 - (1U << GET_HTLB_AREA(addr))) & 0xffff)
102
103#define ARCH_HAS_HUGEPAGE_ONLY_RANGE
104#define ARCH_HAS_PREPARE_HUGEPAGE_RANGE
105#define ARCH_HAS_SETCLEAR_HUGE_PTE
106
107#define touches_hugepage_low_range(mm, addr, len) \
David Gibson9a94c572005-11-24 13:34:56 +1100108 (((addr) < 0x100000000UL) \
109 && (LOW_ESID_MASK((addr), (len)) & (mm)->context.low_htlb_areas))
Michael Ellerman5cd16ee2005-11-11 14:25:24 +1100110#define touches_hugepage_high_range(mm, addr, len) \
David Gibson9a94c572005-11-24 13:34:56 +1100111 ((((addr) + (len)) > 0x100000000UL) \
112 && (HTLB_AREA_MASK((addr), (len)) & (mm)->context.high_htlb_areas))
Michael Ellerman5cd16ee2005-11-11 14:25:24 +1100113
114#define __within_hugepage_low_range(addr, len, segmask) \
David Gibson9a94c572005-11-24 13:34:56 +1100115 ( (((addr)+(len)) <= 0x100000000UL) \
116 && ((LOW_ESID_MASK((addr), (len)) | (segmask)) == (segmask)))
Michael Ellerman5cd16ee2005-11-11 14:25:24 +1100117#define within_hugepage_low_range(addr, len) \
118 __within_hugepage_low_range((addr), (len), \
119 current->mm->context.low_htlb_areas)
120#define __within_hugepage_high_range(addr, len, zonemask) \
David Gibson9a94c572005-11-24 13:34:56 +1100121 ( ((addr) >= 0x100000000UL) \
122 && ((HTLB_AREA_MASK((addr), (len)) | (zonemask)) == (zonemask)))
Michael Ellerman5cd16ee2005-11-11 14:25:24 +1100123#define within_hugepage_high_range(addr, len) \
124 __within_hugepage_high_range((addr), (len), \
125 current->mm->context.high_htlb_areas)
126
127#define is_hugepage_only_range(mm, addr, len) \
128 (touches_hugepage_high_range((mm), (addr), (len)) || \
129 touches_hugepage_low_range((mm), (addr), (len)))
130#define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
131
132#define in_hugepage_area(context, addr) \
133 (cpu_has_feature(CPU_FTR_16M_PAGE) && \
David Gibson5e391dc2005-11-23 13:37:45 -0800134 ( ( (addr) >= 0x100000000UL) \
135 ? ((1 << GET_HTLB_AREA(addr)) & (context).high_htlb_areas) \
136 : ((1 << GET_ESID(addr)) & (context).low_htlb_areas) ) )
Michael Ellerman5cd16ee2005-11-11 14:25:24 +1100137
138#else /* !CONFIG_HUGETLB_PAGE */
139
140#define in_hugepage_area(mm, addr) 0
141
142#endif /* !CONFIG_HUGETLB_PAGE */
143
144#ifdef MODULE
145#define __page_aligned __attribute__((__aligned__(PAGE_SIZE)))
146#else
147#define __page_aligned \
148 __attribute__((__aligned__(PAGE_SIZE), \
149 __section__(".data.page_aligned")))
150#endif
151
152#define VM_DATA_DEFAULT_FLAGS \
153 (test_thread_flag(TIF_32BIT) ? \
154 VM_DATA_DEFAULT_FLAGS32 : VM_DATA_DEFAULT_FLAGS64)
155
156/*
157 * This is the default if a program doesn't have a PT_GNU_STACK
158 * program header entry. The PPC64 ELF ABI has a non executable stack
159 * stack by default, so in the absense of a PT_GNU_STACK program header
160 * we turn execute permission off.
161 */
162#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
163 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
164
165#define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
166 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
167
168#define VM_STACK_DEFAULT_FLAGS \
169 (test_thread_flag(TIF_32BIT) ? \
170 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
171
172#include <asm-generic/page.h>
173
Arnd Bergmann88ced032005-12-16 22:43:46 +0100174#endif /* __KERNEL__ */
Michael Ellerman5cd16ee2005-11-11 14:25:24 +1100175#endif /* _ASM_POWERPC_PAGE_64_H */