linux/arch/powerpc/include/asm/page.h
<<
>>
Prefs
   1#ifndef _ASM_POWERPC_PAGE_H
   2#define _ASM_POWERPC_PAGE_H
   3
   4/*
   5 * Copyright (C) 2001,2005 IBM Corporation.
   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#ifndef __ASSEMBLY__
  14#include <linux/types.h>
  15#else
  16#include <asm/types.h>
  17#endif
  18#include <asm/asm-compat.h>
  19#include <asm/kdump.h>
  20
  21/*
  22 * On regular PPC32 page size is 4K (but we support 4K/16K/64K/256K pages
  23 * on PPC44x). For PPC64 we support either 4K or 64K software
  24 * page size. When using 64K pages however, whether we are really supporting
  25 * 64K pages in HW or not is irrelevant to those definitions.
  26 */
  27#if defined(CONFIG_PPC_256K_PAGES)
  28#define PAGE_SHIFT              18
  29#elif defined(CONFIG_PPC_64K_PAGES)
  30#define PAGE_SHIFT              16
  31#elif defined(CONFIG_PPC_16K_PAGES)
  32#define PAGE_SHIFT              14
  33#else
  34#define PAGE_SHIFT              12
  35#endif
  36
  37#define PAGE_SIZE               (ASM_CONST(1) << PAGE_SHIFT)
  38
  39#ifndef __ASSEMBLY__
  40#ifdef CONFIG_HUGETLB_PAGE
  41extern bool hugetlb_disabled;
  42extern unsigned int HPAGE_SHIFT;
  43#else
  44#define HPAGE_SHIFT PAGE_SHIFT
  45#endif
  46#define HPAGE_SIZE              ((1UL) << HPAGE_SHIFT)
  47#define HPAGE_MASK              (~(HPAGE_SIZE - 1))
  48#define HUGETLB_PAGE_ORDER      (HPAGE_SHIFT - PAGE_SHIFT)
  49#define HUGE_MAX_HSTATE         (MMU_PAGE_COUNT-1)
  50#endif
  51
  52/* We do define AT_SYSINFO_EHDR but don't use the gate mechanism */
  53#define __HAVE_ARCH_GATE_AREA           1
  54
  55/*
  56 * Subtle: (1 << PAGE_SHIFT) is an int, not an unsigned long. So if we
  57 * assign PAGE_MASK to a larger type it gets extended the way we want
  58 * (i.e. with 1s in the high bits)
  59 */
  60#define PAGE_MASK      (~((1 << PAGE_SHIFT) - 1))
  61
  62/*
  63 * KERNELBASE is the virtual address of the start of the kernel, it's often
  64 * the same as PAGE_OFFSET, but _might not be_.
  65 *
  66 * The kdump dump kernel is one example where KERNELBASE != PAGE_OFFSET.
  67 *
  68 * PAGE_OFFSET is the virtual address of the start of lowmem.
  69 *
  70 * PHYSICAL_START is the physical address of the start of the kernel.
  71 *
  72 * MEMORY_START is the physical address of the start of lowmem.
  73 *
  74 * KERNELBASE, PAGE_OFFSET, and PHYSICAL_START are all configurable on
  75 * ppc32 and based on how they are set we determine MEMORY_START.
  76 *
  77 * For the linear mapping the following equation should be true:
  78 * KERNELBASE - PAGE_OFFSET = PHYSICAL_START - MEMORY_START
  79 *
  80 * Also, KERNELBASE >= PAGE_OFFSET and PHYSICAL_START >= MEMORY_START
  81 *
  82 * There are two ways to determine a physical address from a virtual one:
  83 * va = pa + PAGE_OFFSET - MEMORY_START
  84 * va = pa + KERNELBASE - PHYSICAL_START
  85 *
  86 * If you want to know something's offset from the start of the kernel you
  87 * should subtract KERNELBASE.
  88 *
  89 * If you want to test if something's a kernel address, use is_kernel_addr().
  90 */
  91
  92#define KERNELBASE      ASM_CONST(CONFIG_KERNEL_START)
  93#define PAGE_OFFSET     ASM_CONST(CONFIG_PAGE_OFFSET)
  94#define LOAD_OFFSET     ASM_CONST((CONFIG_KERNEL_START-CONFIG_PHYSICAL_START))
  95
  96#if defined(CONFIG_NONSTATIC_KERNEL)
  97#ifndef __ASSEMBLY__
  98
  99extern phys_addr_t memstart_addr;
 100extern phys_addr_t kernstart_addr;
 101
 102#ifdef CONFIG_RELOCATABLE_PPC32
 103extern long long virt_phys_offset;
 104#endif
 105
 106#endif /* __ASSEMBLY__ */
 107#define PHYSICAL_START  kernstart_addr
 108
 109#else   /* !CONFIG_NONSTATIC_KERNEL */
 110#define PHYSICAL_START  ASM_CONST(CONFIG_PHYSICAL_START)
 111#endif
 112
 113/* See Description below for VIRT_PHYS_OFFSET */
 114#ifdef CONFIG_RELOCATABLE_PPC32
 115#define VIRT_PHYS_OFFSET virt_phys_offset
 116#else
 117#define VIRT_PHYS_OFFSET (KERNELBASE - PHYSICAL_START)
 118#endif
 119
 120
 121#ifdef CONFIG_PPC64
 122#define MEMORY_START    0UL
 123#elif defined(CONFIG_NONSTATIC_KERNEL)
 124#define MEMORY_START    memstart_addr
 125#else
 126#define MEMORY_START    (PHYSICAL_START + PAGE_OFFSET - KERNELBASE)
 127#endif
 128
 129#ifdef CONFIG_FLATMEM
 130#define ARCH_PFN_OFFSET         ((unsigned long)(MEMORY_START >> PAGE_SHIFT))
 131#define pfn_valid(pfn)          ((pfn) >= ARCH_PFN_OFFSET && (pfn) < max_mapnr)
 132#endif
 133
 134#define virt_to_page(kaddr)     pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
 135#define pfn_to_kaddr(pfn)       __va((pfn) << PAGE_SHIFT)
 136#define virt_addr_valid(kaddr)  pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
 137
 138/*
 139 * On Book-E parts we need __va to parse the device tree and we can't
 140 * determine MEMORY_START until then.  However we can determine PHYSICAL_START
 141 * from information at hand (program counter, TLB lookup).
 142 *
 143 * On BookE with RELOCATABLE (RELOCATABLE_PPC32)
 144 *
 145 *   With RELOCATABLE_PPC32,  we support loading the kernel at any physical 
 146 *   address without any restriction on the page alignment.
 147 *
 148 *   We find the runtime address of _stext and relocate ourselves based on 
 149 *   the following calculation:
 150 *
 151 *        virtual_base = ALIGN_DOWN(KERNELBASE,256M) +
 152 *                              MODULO(_stext.run,256M)
 153 *   and create the following mapping:
 154 *
 155 *        ALIGN_DOWN(_stext.run,256M) => ALIGN_DOWN(KERNELBASE,256M)
 156 *
 157 *   When we process relocations, we cannot depend on the
 158 *   existing equation for the __va()/__pa() translations:
 159 *
 160 *         __va(x) = (x)  - PHYSICAL_START + KERNELBASE
 161 *
 162 *   Where:
 163 *       PHYSICAL_START = kernstart_addr = Physical address of _stext
 164 *       KERNELBASE = Compiled virtual address of _stext.
 165 *
 166 *   This formula holds true iff, kernel load address is TLB page aligned.
 167 *
 168 *   In our case, we need to also account for the shift in the kernel Virtual 
 169 *   address.
 170 *
 171 *   E.g.,
 172 *
 173 *   Let the kernel be loaded at 64MB and KERNELBASE be 0xc0000000 (same as PAGE_OFFSET).
 174 *   In this case, we would be mapping 0 to 0xc0000000, and kernstart_addr = 64M
 175 *
 176 *   Now __va(1MB) = (0x100000) - (0x4000000) + 0xc0000000
 177 *                 = 0xbc100000 , which is wrong.
 178 *
 179 *   Rather, it should be : 0xc0000000 + 0x100000 = 0xc0100000
 180 *              according to our mapping.
 181 *
 182 *   Hence we use the following formula to get the translations right:
 183 *
 184 *        __va(x) = (x) - [ PHYSICAL_START - Effective KERNELBASE ]
 185 *
 186 *        Where :
 187 *              PHYSICAL_START = dynamic load address.(kernstart_addr variable)
 188 *              Effective KERNELBASE = virtual_base =
 189 *                                   = ALIGN_DOWN(KERNELBASE,256M) +
 190 *                                              MODULO(PHYSICAL_START,256M)
 191 *
 192 *      To make the cost of __va() / __pa() more light weight, we introduce
 193 *      a new variable virt_phys_offset, which will hold :
 194 *
 195 *      virt_phys_offset = Effective KERNELBASE - PHYSICAL_START
 196 *                       = ALIGN_DOWN(KERNELBASE,256M) - 
 197 *                              ALIGN_DOWN(PHYSICALSTART,256M)
 198 *
 199 *      Hence :
 200 *
 201 *      __va(x) = x - PHYSICAL_START + Effective KERNELBASE
 202 *              = x + virt_phys_offset
 203 *
 204 *              and
 205 *      __pa(x) = x + PHYSICAL_START - Effective KERNELBASE
 206 *              = x - virt_phys_offset
 207 *              
 208 * On non-Book-E PPC64 PAGE_OFFSET and MEMORY_START are constants so use
 209 * the other definitions for __va & __pa.
 210 */
 211#ifdef CONFIG_BOOKE
 212#define __va(x) ((void *)(unsigned long)((phys_addr_t)(x) + VIRT_PHYS_OFFSET))
 213#define __pa(x) ((unsigned long)(x) - VIRT_PHYS_OFFSET)
 214#else
 215#ifdef CONFIG_PPC64
 216/*
 217 * gcc miscompiles (unsigned long)(&static_var) - PAGE_OFFSET
 218 * with -mcmodel=medium, so we use & and | instead of - and + on 64-bit.
 219 */
 220#define __va(x) ((void *)(unsigned long)((phys_addr_t)(x) | PAGE_OFFSET))
 221#define __pa(x) ((unsigned long)(x) & 0x0fffffffffffffffUL)
 222
 223#else /* 32-bit, non book E */
 224#define __va(x) ((void *)(unsigned long)((phys_addr_t)(x) + PAGE_OFFSET - MEMORY_START))
 225#define __pa(x) ((unsigned long)(x) - PAGE_OFFSET + MEMORY_START)
 226#endif
 227#endif
 228
 229/*
 230 * Unfortunately the PLT is in the BSS in the PPC32 ELF ABI,
 231 * and needs to be executable.  This means the whole heap ends
 232 * up being executable.
 233 */
 234#define VM_DATA_DEFAULT_FLAGS32 \
 235        (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
 236                                 VM_READ | VM_WRITE | \
 237                                 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
 238
 239#define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
 240                                 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
 241
 242#ifdef __powerpc64__
 243#include <asm/page_64.h>
 244#else
 245#include <asm/page_32.h>
 246#endif
 247
 248/* align addr on a size boundary - adjust address up/down if needed */
 249#define _ALIGN_UP(addr,size)    (((addr)+((size)-1))&(~((size)-1)))
 250#define _ALIGN_DOWN(addr,size)  ((addr)&(~((size)-1)))
 251
 252/* align addr on a size boundary - adjust address up if needed */
 253#define _ALIGN(addr,size)     _ALIGN_UP(addr,size)
 254
 255/*
 256 * Don't compare things with KERNELBASE or PAGE_OFFSET to test for
 257 * "kernelness", use is_kernel_addr() - it should do what you want.
 258 */
 259#ifdef CONFIG_PPC_BOOK3E_64
 260#define is_kernel_addr(x)       ((x) >= 0x8000000000000000ul)
 261#else
 262#define is_kernel_addr(x)       ((x) >= PAGE_OFFSET)
 263#endif
 264
 265#ifndef CONFIG_PPC_BOOK3S_64
 266/*
 267 * Use the top bit of the higher-level page table entries to indicate whether
 268 * the entries we point to contain hugepages.  This works because we know that
 269 * the page tables live in kernel space.  If we ever decide to support having
 270 * page tables at arbitrary addresses, this breaks and will have to change.
 271 */
 272#ifdef CONFIG_PPC64
 273#define PD_HUGE 0x8000000000000000
 274#else
 275#define PD_HUGE 0x80000000
 276#endif
 277#endif /* CONFIG_PPC_BOOK3S_64 */
 278
 279/*
 280 * Some number of bits at the level of the page table that points to
 281 * a hugepte are used to encode the size.  This masks those bits.
 282 */
 283#define HUGEPD_SHIFT_MASK     0x3f
 284
 285#ifndef __ASSEMBLY__
 286
 287#undef STRICT_MM_TYPECHECKS
 288
 289#ifdef STRICT_MM_TYPECHECKS
 290/* These are used to make use of C type-checking. */
 291
 292/* PTE level */
 293typedef struct { pte_basic_t pte; } pte_t;
 294#define pte_val(x)      ((x).pte)
 295#define __pte(x)        ((pte_t) { (x) })
 296
 297/* 64k pages additionally define a bigger "real PTE" type that gathers
 298 * the "second half" part of the PTE for pseudo 64k pages
 299 */
 300#if defined(CONFIG_PPC_64K_PAGES) && defined(CONFIG_PPC_STD_MMU_64)
 301typedef struct { pte_t pte; unsigned long hidx; } real_pte_t;
 302#else
 303typedef struct { pte_t pte; } real_pte_t;
 304#endif
 305
 306/* PMD level */
 307#ifdef CONFIG_PPC64
 308typedef struct { unsigned long pmd; } pmd_t;
 309#define pmd_val(x)      ((x).pmd)
 310#define __pmd(x)        ((pmd_t) { (x) })
 311
 312/* PUD level exusts only on 4k pages */
 313#ifndef CONFIG_PPC_64K_PAGES
 314typedef struct { unsigned long pud; } pud_t;
 315#define pud_val(x)      ((x).pud)
 316#define __pud(x)        ((pud_t) { (x) })
 317#endif /* !CONFIG_PPC_64K_PAGES */
 318#endif /* CONFIG_PPC64 */
 319
 320/* PGD level */
 321typedef struct { unsigned long pgd; } pgd_t;
 322#define pgd_val(x)      ((x).pgd)
 323#define __pgd(x)        ((pgd_t) { (x) })
 324
 325/* Page protection bits */
 326typedef struct { unsigned long pgprot; } pgprot_t;
 327#define pgprot_val(x)   ((x).pgprot)
 328#define __pgprot(x)     ((pgprot_t) { (x) })
 329
 330#else
 331
 332/*
 333 * .. while these make it easier on the compiler
 334 */
 335
 336typedef pte_basic_t pte_t;
 337#define pte_val(x)      (x)
 338#define __pte(x)        (x)
 339
 340#if defined(CONFIG_PPC_64K_PAGES) && defined(CONFIG_PPC_STD_MMU_64)
 341typedef struct { pte_t pte; unsigned long hidx; } real_pte_t;
 342#else
 343typedef pte_t real_pte_t;
 344#endif
 345
 346
 347#ifdef CONFIG_PPC64
 348typedef unsigned long pmd_t;
 349#define pmd_val(x)      (x)
 350#define __pmd(x)        (x)
 351
 352#ifndef CONFIG_PPC_64K_PAGES
 353typedef unsigned long pud_t;
 354#define pud_val(x)      (x)
 355#define __pud(x)        (x)
 356#endif /* !CONFIG_PPC_64K_PAGES */
 357#endif /* CONFIG_PPC64 */
 358
 359typedef unsigned long pgd_t;
 360#define pgd_val(x)      (x)
 361#define pgprot_val(x)   (x)
 362
 363typedef unsigned long pgprot_t;
 364#define __pgd(x)        (x)
 365#define __pgprot(x)     (x)
 366
 367#endif
 368
 369typedef struct { signed long pd; } hugepd_t;
 370
 371#ifdef CONFIG_HUGETLB_PAGE
 372#ifdef CONFIG_PPC_BOOK3S_64
 373static inline int hugepd_ok(hugepd_t hpd)
 374{
 375        /*
 376         * hugepd pointer, bottom two bits == 00 and next 4 bits
 377         * indicate size of table
 378         */
 379        return (((hpd.pd & 0x3) == 0x0) && ((hpd.pd & HUGEPD_SHIFT_MASK) != 0));
 380}
 381#else
 382static inline int hugepd_ok(hugepd_t hpd)
 383{
 384        return (hpd.pd > 0);
 385}
 386#endif
 387
 388#define is_hugepd(pdep)               (hugepd_ok(*((hugepd_t *)(pdep))))
 389int pgd_huge(pgd_t pgd);
 390#else /* CONFIG_HUGETLB_PAGE */
 391#define is_hugepd(pdep)                 0
 392#define pgd_huge(pgd)                   0
 393#endif /* CONFIG_HUGETLB_PAGE */
 394
 395struct page;
 396extern void clear_user_page(void *page, unsigned long vaddr, struct page *pg);
 397extern void copy_user_page(void *to, void *from, unsigned long vaddr,
 398                struct page *p);
 399extern int page_is_ram(unsigned long pfn);
 400extern int devmem_is_allowed(unsigned long pfn);
 401
 402#ifdef CONFIG_PPC_SMLPAR
 403void arch_free_page(struct page *page, int order);
 404#define HAVE_ARCH_FREE_PAGE
 405#endif
 406
 407struct vm_area_struct;
 408
 409#ifdef CONFIG_PPC_64K_PAGES
 410typedef pte_t *pgtable_t;
 411#else
 412typedef struct page *pgtable_t;
 413#endif
 414
 415#include <asm-generic/memory_model.h>
 416#endif /* __ASSEMBLY__ */
 417
 418#endif /* _ASM_POWERPC_PAGE_H */
 419