Merge branch 'upstream-fixes'
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / asm-powerpc / page_64.h
1 #ifndef _ASM_POWERPC_PAGE_64_H
2 #define _ASM_POWERPC_PAGE_64_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 /*
14 * We always define HW_PAGE_SHIFT to 12 as use of 64K pages remains Linux
15 * specific, every notion of page number shared with the firmware, TCEs,
16 * iommu, etc... still uses a page size of 4K.
17 */
18 #define HW_PAGE_SHIFT 12
19 #define HW_PAGE_SIZE (ASM_CONST(1) << HW_PAGE_SHIFT)
20 #define HW_PAGE_MASK (~(HW_PAGE_SIZE-1))
21
22 /*
23 * PAGE_FACTOR is the number of bits factor between PAGE_SHIFT and
24 * HW_PAGE_SHIFT, that is 4K pages.
25 */
26 #define PAGE_FACTOR (PAGE_SHIFT - HW_PAGE_SHIFT)
27
28 #define REGION_SIZE 4UL
29 #define REGION_SHIFT 60UL
30 #define REGION_MASK (((1UL<<REGION_SIZE)-1UL)<<REGION_SHIFT)
31
32 #define VMALLOCBASE ASM_CONST(0xD000000000000000)
33 #define VMALLOC_REGION_ID (VMALLOCBASE >> REGION_SHIFT)
34 #define KERNEL_REGION_ID (KERNELBASE >> REGION_SHIFT)
35 #define USER_REGION_ID (0UL)
36 #define REGION_ID(ea) (((unsigned long)(ea)) >> REGION_SHIFT)
37
38 /* Segment size */
39 #define SID_SHIFT 28
40 #define SID_MASK 0xfffffffffUL
41 #define ESID_MASK 0xfffffffff0000000UL
42 #define GET_ESID(x) (((x) >> SID_SHIFT) & SID_MASK)
43
44 #ifndef __ASSEMBLY__
45 #include <asm/cache.h>
46
47 typedef unsigned long pte_basic_t;
48
49 static __inline__ void clear_page(void *addr)
50 {
51 unsigned long lines, line_size;
52
53 line_size = ppc64_caches.dline_size;
54 lines = ppc64_caches.dlines_per_page;
55
56 __asm__ __volatile__(
57 "mtctr %1 # clear_page\n\
58 1: dcbz 0,%0\n\
59 add %0,%0,%3\n\
60 bdnz+ 1b"
61 : "=r" (addr)
62 : "r" (lines), "0" (addr), "r" (line_size)
63 : "ctr", "memory");
64 }
65
66 extern void copy_4K_page(void *to, void *from);
67
68 #ifdef CONFIG_PPC_64K_PAGES
69 static inline void copy_page(void *to, void *from)
70 {
71 unsigned int i;
72 for (i=0; i < (1 << (PAGE_SHIFT - 12)); i++) {
73 copy_4K_page(to, from);
74 to += 4096;
75 from += 4096;
76 }
77 }
78 #else /* CONFIG_PPC_64K_PAGES */
79 static inline void copy_page(void *to, void *from)
80 {
81 copy_4K_page(to, from);
82 }
83 #endif /* CONFIG_PPC_64K_PAGES */
84
85 /* Log 2 of page table size */
86 extern u64 ppc64_pft_size;
87
88 /* Large pages size */
89 extern unsigned int HPAGE_SHIFT;
90 #define HPAGE_SIZE ((1UL) << HPAGE_SHIFT)
91 #define HPAGE_MASK (~(HPAGE_SIZE - 1))
92 #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
93
94 #endif /* __ASSEMBLY__ */
95
96 #ifdef CONFIG_HUGETLB_PAGE
97
98 #define HTLB_AREA_SHIFT 40
99 #define HTLB_AREA_SIZE (1UL << HTLB_AREA_SHIFT)
100 #define GET_HTLB_AREA(x) ((x) >> HTLB_AREA_SHIFT)
101
102 #define LOW_ESID_MASK(addr, len) (((1U << (GET_ESID(addr+len-1)+1)) \
103 - (1U << GET_ESID(addr))) & 0xffff)
104 #define HTLB_AREA_MASK(addr, len) (((1U << (GET_HTLB_AREA(addr+len-1)+1)) \
105 - (1U << GET_HTLB_AREA(addr))) & 0xffff)
106
107 #define ARCH_HAS_HUGEPAGE_ONLY_RANGE
108 #define ARCH_HAS_PREPARE_HUGEPAGE_RANGE
109 #define ARCH_HAS_SETCLEAR_HUGE_PTE
110
111 #define touches_hugepage_low_range(mm, addr, len) \
112 (LOW_ESID_MASK((addr), (len)) & (mm)->context.low_htlb_areas)
113 #define touches_hugepage_high_range(mm, addr, len) \
114 (HTLB_AREA_MASK((addr), (len)) & (mm)->context.high_htlb_areas)
115
116 #define __within_hugepage_low_range(addr, len, segmask) \
117 ((LOW_ESID_MASK((addr), (len)) | (segmask)) == (segmask))
118 #define within_hugepage_low_range(addr, len) \
119 __within_hugepage_low_range((addr), (len), \
120 current->mm->context.low_htlb_areas)
121 #define __within_hugepage_high_range(addr, len, zonemask) \
122 ((HTLB_AREA_MASK((addr), (len)) | (zonemask)) == (zonemask))
123 #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) && \
134 ( ((1 << GET_HTLB_AREA(addr)) & (context).high_htlb_areas) || \
135 ( ((addr) < 0x100000000L) && \
136 ((1 << GET_ESID(addr)) & (context).low_htlb_areas) ) ) )
137
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
174 #endif /* _ASM_POWERPC_PAGE_64_H */