Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #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> |
| 14 | |
| 15 | #ifdef __ASSEMBLY__ |
| 16 | #define ASM_CONST(x) x |
| 17 | #else |
| 18 | #define __ASM_CONST(x) x##UL |
| 19 | #define ASM_CONST(x) __ASM_CONST(x) |
| 20 | #endif |
| 21 | |
| 22 | /* PAGE_SHIFT determines the page size */ |
| 23 | #define PAGE_SHIFT 12 |
| 24 | #define PAGE_SIZE (ASM_CONST(1) << PAGE_SHIFT) |
| 25 | #define PAGE_MASK (~(PAGE_SIZE-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | #define SID_SHIFT 28 |
| 28 | #define SID_MASK 0xfffffffffUL |
| 29 | #define ESID_MASK 0xfffffffff0000000UL |
| 30 | #define GET_ESID(x) (((x) >> SID_SHIFT) & SID_MASK) |
| 31 | |
| 32 | #define HPAGE_SHIFT 24 |
| 33 | #define HPAGE_SIZE ((1UL) << HPAGE_SHIFT) |
| 34 | #define HPAGE_MASK (~(HPAGE_SIZE - 1)) |
| 35 | |
| 36 | #ifdef CONFIG_HUGETLB_PAGE |
| 37 | |
| 38 | #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT) |
| 39 | |
David Gibson | c594ada | 2005-08-11 16:55:21 +1000 | [diff] [blame] | 40 | #define HTLB_AREA_SHIFT 40 |
| 41 | #define HTLB_AREA_SIZE (1UL << HTLB_AREA_SHIFT) |
| 42 | #define GET_HTLB_AREA(x) ((x) >> HTLB_AREA_SHIFT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | #define LOW_ESID_MASK(addr, len) (((1U << (GET_ESID(addr+len-1)+1)) \ |
| 45 | - (1U << GET_ESID(addr))) & 0xffff) |
David Gibson | c594ada | 2005-08-11 16:55:21 +1000 | [diff] [blame] | 46 | #define HTLB_AREA_MASK(addr, len) (((1U << (GET_HTLB_AREA(addr+len-1)+1)) \ |
| 47 | - (1U << GET_HTLB_AREA(addr))) & 0xffff) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | #define ARCH_HAS_HUGEPAGE_ONLY_RANGE |
| 50 | #define ARCH_HAS_PREPARE_HUGEPAGE_RANGE |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 51 | #define ARCH_HAS_SETCLEAR_HUGE_PTE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | #define touches_hugepage_low_range(mm, addr, len) \ |
David Gibson | c594ada | 2005-08-11 16:55:21 +1000 | [diff] [blame] | 54 | (LOW_ESID_MASK((addr), (len)) & (mm)->context.low_htlb_areas) |
| 55 | #define touches_hugepage_high_range(mm, addr, len) \ |
| 56 | (HTLB_AREA_MASK((addr), (len)) & (mm)->context.high_htlb_areas) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
| 58 | #define __within_hugepage_low_range(addr, len, segmask) \ |
| 59 | ((LOW_ESID_MASK((addr), (len)) | (segmask)) == (segmask)) |
| 60 | #define within_hugepage_low_range(addr, len) \ |
| 61 | __within_hugepage_low_range((addr), (len), \ |
David Gibson | c594ada | 2005-08-11 16:55:21 +1000 | [diff] [blame] | 62 | current->mm->context.low_htlb_areas) |
| 63 | #define __within_hugepage_high_range(addr, len, zonemask) \ |
| 64 | ((HTLB_AREA_MASK((addr), (len)) | (zonemask)) == (zonemask)) |
| 65 | #define within_hugepage_high_range(addr, len) \ |
| 66 | __within_hugepage_high_range((addr), (len), \ |
| 67 | current->mm->context.high_htlb_areas) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | #define is_hugepage_only_range(mm, addr, len) \ |
David Gibson | c594ada | 2005-08-11 16:55:21 +1000 | [diff] [blame] | 70 | (touches_hugepage_high_range((mm), (addr), (len)) || \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | touches_hugepage_low_range((mm), (addr), (len))) |
| 72 | #define HAVE_ARCH_HUGETLB_UNMAPPED_AREA |
| 73 | |
| 74 | #define in_hugepage_area(context, addr) \ |
| 75 | (cpu_has_feature(CPU_FTR_16M_PAGE) && \ |
David Gibson | c594ada | 2005-08-11 16:55:21 +1000 | [diff] [blame] | 76 | ( ((1 << GET_HTLB_AREA(addr)) & (context).high_htlb_areas) || \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | ( ((addr) < 0x100000000L) && \ |
David Gibson | c594ada | 2005-08-11 16:55:21 +1000 | [diff] [blame] | 78 | ((1 << GET_ESID(addr)) & (context).low_htlb_areas) ) ) ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
| 80 | #else /* !CONFIG_HUGETLB_PAGE */ |
| 81 | |
| 82 | #define in_hugepage_area(mm, addr) 0 |
| 83 | |
| 84 | #endif /* !CONFIG_HUGETLB_PAGE */ |
| 85 | |
| 86 | /* align addr on a size boundary - adjust address up/down if needed */ |
| 87 | #define _ALIGN_UP(addr,size) (((addr)+((size)-1))&(~((size)-1))) |
| 88 | #define _ALIGN_DOWN(addr,size) ((addr)&(~((size)-1))) |
| 89 | |
| 90 | /* align addr on a size boundary - adjust address up if needed */ |
| 91 | #define _ALIGN(addr,size) _ALIGN_UP(addr,size) |
| 92 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | /* to align the pointer to the (next) page boundary */ |
| 94 | #define PAGE_ALIGN(addr) _ALIGN(addr, PAGE_SIZE) |
| 95 | |
| 96 | #ifdef __KERNEL__ |
| 97 | #ifndef __ASSEMBLY__ |
| 98 | #include <asm/cache.h> |
| 99 | |
| 100 | #undef STRICT_MM_TYPECHECKS |
| 101 | |
| 102 | #define REGION_SIZE 4UL |
| 103 | #define REGION_SHIFT 60UL |
| 104 | #define REGION_MASK (((1UL<<REGION_SIZE)-1UL)<<REGION_SHIFT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | static __inline__ void clear_page(void *addr) |
| 107 | { |
| 108 | unsigned long lines, line_size; |
| 109 | |
| 110 | line_size = ppc64_caches.dline_size; |
| 111 | lines = ppc64_caches.dlines_per_page; |
| 112 | |
| 113 | __asm__ __volatile__( |
| 114 | "mtctr %1 # clear_page\n\ |
| 115 | 1: dcbz 0,%0\n\ |
| 116 | add %0,%0,%3\n\ |
| 117 | bdnz+ 1b" |
| 118 | : "=r" (addr) |
| 119 | : "r" (lines), "0" (addr), "r" (line_size) |
| 120 | : "ctr", "memory"); |
| 121 | } |
| 122 | |
| 123 | extern void copy_page(void *to, void *from); |
| 124 | struct page; |
| 125 | extern void clear_user_page(void *page, unsigned long vaddr, struct page *pg); |
| 126 | extern void copy_user_page(void *to, void *from, unsigned long vaddr, struct page *p); |
| 127 | |
| 128 | #ifdef STRICT_MM_TYPECHECKS |
| 129 | /* |
| 130 | * These are used to make use of C type-checking. |
| 131 | * Entries in the pte table are 64b, while entries in the pgd & pmd are 32b. |
| 132 | */ |
| 133 | typedef struct { unsigned long pte; } pte_t; |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 134 | typedef struct { unsigned long pmd; } pmd_t; |
| 135 | typedef struct { unsigned long pud; } pud_t; |
| 136 | typedef struct { unsigned long pgd; } pgd_t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | typedef struct { unsigned long pgprot; } pgprot_t; |
| 138 | |
| 139 | #define pte_val(x) ((x).pte) |
| 140 | #define pmd_val(x) ((x).pmd) |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 141 | #define pud_val(x) ((x).pud) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | #define pgd_val(x) ((x).pgd) |
| 143 | #define pgprot_val(x) ((x).pgprot) |
| 144 | |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 145 | #define __pte(x) ((pte_t) { (x) }) |
| 146 | #define __pmd(x) ((pmd_t) { (x) }) |
| 147 | #define __pud(x) ((pud_t) { (x) }) |
| 148 | #define __pgd(x) ((pgd_t) { (x) }) |
| 149 | #define __pgprot(x) ((pgprot_t) { (x) }) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
| 151 | #else |
| 152 | /* |
| 153 | * .. while these make it easier on the compiler |
| 154 | */ |
| 155 | typedef unsigned long pte_t; |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 156 | typedef unsigned long pmd_t; |
| 157 | typedef unsigned long pud_t; |
| 158 | typedef unsigned long pgd_t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | typedef unsigned long pgprot_t; |
| 160 | |
| 161 | #define pte_val(x) (x) |
| 162 | #define pmd_val(x) (x) |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 163 | #define pud_val(x) (x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | #define pgd_val(x) (x) |
| 165 | #define pgprot_val(x) (x) |
| 166 | |
| 167 | #define __pte(x) (x) |
| 168 | #define __pmd(x) (x) |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 169 | #define __pud(x) (x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | #define __pgd(x) (x) |
| 171 | #define __pgprot(x) (x) |
| 172 | |
| 173 | #endif |
| 174 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | #define __pa(x) ((unsigned long)(x)-PAGE_OFFSET) |
| 176 | |
| 177 | extern int page_is_ram(unsigned long pfn); |
| 178 | |
| 179 | extern u64 ppc64_pft_size; /* Log 2 of page table size */ |
| 180 | |
| 181 | /* We do define AT_SYSINFO_EHDR but don't use the gate mecanism */ |
| 182 | #define __HAVE_ARCH_GATE_AREA 1 |
| 183 | |
| 184 | #endif /* __ASSEMBLY__ */ |
| 185 | |
| 186 | #ifdef MODULE |
| 187 | #define __page_aligned __attribute__((__aligned__(PAGE_SIZE))) |
| 188 | #else |
| 189 | #define __page_aligned \ |
| 190 | __attribute__((__aligned__(PAGE_SIZE), \ |
| 191 | __section__(".data.page_aligned"))) |
| 192 | #endif |
| 193 | |
| 194 | |
| 195 | /* This must match the -Ttext linker address */ |
| 196 | /* Note: tophys & tovirt make assumptions about how */ |
| 197 | /* KERNELBASE is defined for performance reasons. */ |
| 198 | /* When KERNELBASE moves, those macros may have */ |
| 199 | /* to change! */ |
| 200 | #define PAGE_OFFSET ASM_CONST(0xC000000000000000) |
| 201 | #define KERNELBASE PAGE_OFFSET |
| 202 | #define VMALLOCBASE ASM_CONST(0xD000000000000000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
David Gibson | 1f8d419 | 2005-05-05 16:15:13 -0700 | [diff] [blame] | 204 | #define VMALLOC_REGION_ID (VMALLOCBASE >> REGION_SHIFT) |
| 205 | #define KERNEL_REGION_ID (KERNELBASE >> REGION_SHIFT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | #define USER_REGION_ID (0UL) |
David Gibson | 1f8d419 | 2005-05-05 16:15:13 -0700 | [diff] [blame] | 207 | #define REGION_ID(ea) (((unsigned long)(ea)) >> REGION_SHIFT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | #define __va(x) ((void *)((unsigned long)(x) + KERNELBASE)) |
| 210 | |
| 211 | #ifdef CONFIG_DISCONTIGMEM |
| 212 | #define page_to_pfn(page) discontigmem_page_to_pfn(page) |
| 213 | #define pfn_to_page(pfn) discontigmem_pfn_to_page(pfn) |
| 214 | #define pfn_valid(pfn) discontigmem_pfn_valid(pfn) |
Andy Whitcroft | 145e664 | 2005-06-23 00:08:03 -0700 | [diff] [blame] | 215 | #endif |
| 216 | #ifdef CONFIG_FLATMEM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | #define pfn_to_page(pfn) (mem_map + (pfn)) |
| 218 | #define page_to_pfn(page) ((unsigned long)((page) - mem_map)) |
| 219 | #define pfn_valid(pfn) ((pfn) < max_mapnr) |
| 220 | #endif |
| 221 | |
| 222 | #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) |
| 223 | #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT) |
| 224 | |
| 225 | #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) |
| 226 | |
| 227 | /* |
| 228 | * Unfortunately the PLT is in the BSS in the PPC32 ELF ABI, |
| 229 | * and needs to be executable. This means the whole heap ends |
| 230 | * up being executable. |
| 231 | */ |
| 232 | #define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \ |
| 233 | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) |
| 234 | |
| 235 | #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \ |
| 236 | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) |
| 237 | |
| 238 | #define VM_DATA_DEFAULT_FLAGS \ |
| 239 | (test_thread_flag(TIF_32BIT) ? \ |
| 240 | VM_DATA_DEFAULT_FLAGS32 : VM_DATA_DEFAULT_FLAGS64) |
| 241 | |
| 242 | /* |
| 243 | * This is the default if a program doesn't have a PT_GNU_STACK |
Anton Blanchard | a2f95a5 | 2005-05-01 08:58:45 -0700 | [diff] [blame] | 244 | * program header entry. The PPC64 ELF ABI has a non executable stack |
| 245 | * stack by default, so in the absense of a PT_GNU_STACK program header |
| 246 | * we turn execute permission off. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | */ |
Anton Blanchard | a2f95a5 | 2005-05-01 08:58:45 -0700 | [diff] [blame] | 248 | #define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \ |
| 249 | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) |
| 250 | |
| 251 | #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \ |
| 252 | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) |
| 253 | |
| 254 | #define VM_STACK_DEFAULT_FLAGS \ |
| 255 | (test_thread_flag(TIF_32BIT) ? \ |
| 256 | VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
| 258 | #endif /* __KERNEL__ */ |
Stephen Rothwell | fd4fd5a | 2005-09-03 15:54:30 -0700 | [diff] [blame] | 259 | |
| 260 | #include <asm-generic/page.h> |
| 261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | #endif /* _PPC64_PAGE_H */ |