linux/arch/tile/include/asm/page.h
<<
>>
Prefs
   1/*
   2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
   3 *
   4 *   This program is free software; you can redistribute it and/or
   5 *   modify it under the terms of the GNU General Public License
   6 *   as published by the Free Software Foundation, version 2.
   7 *
   8 *   This program is distributed in the hope that it will be useful, but
   9 *   WITHOUT ANY WARRANTY; without even the implied warranty of
  10 *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11 *   NON INFRINGEMENT.  See the GNU General Public License for
  12 *   more details.
  13 */
  14
  15#ifndef _ASM_TILE_PAGE_H
  16#define _ASM_TILE_PAGE_H
  17
  18#include <linux/const.h>
  19
  20/* PAGE_SHIFT and HPAGE_SHIFT determine the page sizes. */
  21#define PAGE_SHIFT      16
  22#define HPAGE_SHIFT     24
  23
  24#define PAGE_SIZE       (_AC(1, UL) << PAGE_SHIFT)
  25#define HPAGE_SIZE      (_AC(1, UL) << HPAGE_SHIFT)
  26
  27#define PAGE_MASK       (~(PAGE_SIZE - 1))
  28#define HPAGE_MASK      (~(HPAGE_SIZE - 1))
  29
  30#ifdef __KERNEL__
  31
  32#include <hv/hypervisor.h>
  33#include <arch/chip.h>
  34
  35/*
  36 * The {,H}PAGE_SHIFT values must match the HV_LOG2_PAGE_SIZE_xxx
  37 * definitions in <hv/hypervisor.h>.  We validate this at build time
  38 * here, and again at runtime during early boot.  We provide a
  39 * separate definition since userspace doesn't have <hv/hypervisor.h>.
  40 *
  41 * Be careful to distinguish PAGE_SHIFT from HV_PTE_INDEX_PFN, since
  42 * they are the same on i386 but not TILE.
  43 */
  44#if HV_LOG2_PAGE_SIZE_SMALL != PAGE_SHIFT
  45# error Small page size mismatch in Linux
  46#endif
  47#if HV_LOG2_PAGE_SIZE_LARGE != HPAGE_SHIFT
  48# error Huge page size mismatch in Linux
  49#endif
  50
  51#ifndef __ASSEMBLY__
  52
  53#include <linux/types.h>
  54#include <linux/string.h>
  55
  56struct page;
  57
  58static inline void clear_page(void *page)
  59{
  60        memset(page, 0, PAGE_SIZE);
  61}
  62
  63static inline void copy_page(void *to, void *from)
  64{
  65        memcpy(to, from, PAGE_SIZE);
  66}
  67
  68static inline void clear_user_page(void *page, unsigned long vaddr,
  69                                struct page *pg)
  70{
  71        clear_page(page);
  72}
  73
  74static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
  75                                struct page *topage)
  76{
  77        copy_page(to, from);
  78}
  79
  80/*
  81 * Hypervisor page tables are made of the same basic structure.
  82 */
  83
  84typedef __u64 pteval_t;
  85typedef __u64 pmdval_t;
  86typedef __u64 pudval_t;
  87typedef __u64 pgdval_t;
  88typedef __u64 pgprotval_t;
  89
  90typedef HV_PTE pte_t;
  91typedef HV_PTE pgd_t;
  92typedef HV_PTE pgprot_t;
  93
  94/*
  95 * User L2 page tables are managed as one L2 page table per page,
  96 * because we use the page allocator for them.  This keeps the allocation
  97 * simple and makes it potentially useful to implement HIGHPTE at some point.
  98 * However, it's also inefficient, since L2 page tables are much smaller
  99 * than pages (currently 2KB vs 64KB).  So we should revisit this.
 100 */
 101typedef struct page *pgtable_t;
 102
 103/* Must be a macro since it is used to create constants. */
 104#define __pgprot(val) hv_pte(val)
 105
 106static inline u64 pgprot_val(pgprot_t pgprot)
 107{
 108        return hv_pte_val(pgprot);
 109}
 110
 111static inline u64 pte_val(pte_t pte)
 112{
 113        return hv_pte_val(pte);
 114}
 115
 116static inline u64 pgd_val(pgd_t pgd)
 117{
 118        return hv_pte_val(pgd);
 119}
 120
 121#ifdef __tilegx__
 122
 123typedef HV_PTE pmd_t;
 124
 125static inline u64 pmd_val(pmd_t pmd)
 126{
 127        return hv_pte_val(pmd);
 128}
 129
 130#endif
 131
 132static inline __attribute_const__ int get_order(unsigned long size)
 133{
 134        return BITS_PER_LONG - __builtin_clzl((size - 1) >> PAGE_SHIFT);
 135}
 136
 137#endif /* !__ASSEMBLY__ */
 138
 139#define HUGETLB_PAGE_ORDER      (HPAGE_SHIFT - PAGE_SHIFT)
 140
 141#define HUGE_MAX_HSTATE         2
 142
 143#ifdef CONFIG_HUGETLB_PAGE
 144#define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
 145#endif
 146
 147/* Each memory controller has PAs distinct in their high bits. */
 148#define NR_PA_HIGHBIT_SHIFT (CHIP_PA_WIDTH() - CHIP_LOG_NUM_MSHIMS())
 149#define NR_PA_HIGHBIT_VALUES (1 << CHIP_LOG_NUM_MSHIMS())
 150#define __pa_to_highbits(pa) ((phys_addr_t)(pa) >> NR_PA_HIGHBIT_SHIFT)
 151#define __pfn_to_highbits(pfn) ((pfn) >> (NR_PA_HIGHBIT_SHIFT - PAGE_SHIFT))
 152
 153#ifdef __tilegx__
 154
 155/*
 156 * We reserve the lower half of memory for user-space programs, and the
 157 * upper half for system code.  We re-map all of physical memory in the
 158 * upper half, which takes a quarter of our VA space.  Then we have
 159 * the vmalloc regions.  The supervisor code lives at 0xfffffff700000000,
 160 * with the hypervisor above that.
 161 *
 162 * Loadable kernel modules are placed immediately after the static
 163 * supervisor code, with each being allocated a 256MB region of
 164 * address space, so we don't have to worry about the range of "jal"
 165 * and other branch instructions.
 166 *
 167 * For now we keep life simple and just allocate one pmd (4GB) for vmalloc.
 168 * Similarly, for now we don't play any struct page mapping games.
 169 */
 170
 171#if CHIP_PA_WIDTH() + 2 > CHIP_VA_WIDTH()
 172# error Too much PA to map with the VA available!
 173#endif
 174#define HALF_VA_SPACE           (_AC(1, UL) << (CHIP_VA_WIDTH() - 1))
 175
 176#define MEM_LOW_END             (HALF_VA_SPACE - 1)         /* low half */
 177#define MEM_HIGH_START          (-HALF_VA_SPACE)            /* high half */
 178#define PAGE_OFFSET             MEM_HIGH_START
 179#define _VMALLOC_START          _AC(0xfffffff500000000, UL) /* 4 GB */
 180#define HUGE_VMAP_BASE          _AC(0xfffffff600000000, UL) /* 4 GB */
 181#define MEM_SV_START            _AC(0xfffffff700000000, UL) /* 256 MB */
 182#define MEM_SV_INTRPT           MEM_SV_START
 183#define MEM_MODULE_START        _AC(0xfffffff710000000, UL) /* 256 MB */
 184#define MEM_MODULE_END          (MEM_MODULE_START + (256*1024*1024))
 185#define MEM_HV_START            _AC(0xfffffff800000000, UL) /* 32 GB */
 186
 187/* Highest DTLB address we will use */
 188#define KERNEL_HIGH_VADDR       MEM_SV_START
 189
 190/* Since we don't currently provide any fixmaps, we use an impossible VA. */
 191#define FIXADDR_TOP             MEM_HV_START
 192
 193#else /* !__tilegx__ */
 194
 195/*
 196 * A PAGE_OFFSET of 0xC0000000 means that the kernel has
 197 * a virtual address space of one gigabyte, which limits the
 198 * amount of physical memory you can use to about 768MB.
 199 * If you want more physical memory than this then see the CONFIG_HIGHMEM
 200 * option in the kernel configuration.
 201 *
 202 * The top 16MB chunk in the table below is unavailable to Linux.  Since
 203 * the kernel interrupt vectors must live at ether 0xfe000000 or 0xfd000000
 204 * (depending on whether the kernel is at PL2 or Pl1), we map all of the
 205 * bottom of RAM at this address with a huge page table entry to minimize
 206 * its ITLB footprint (as well as at PAGE_OFFSET).  The last architected
 207 * requirement is that user interrupt vectors live at 0xfc000000, so we
 208 * make that range of memory available to user processes.  The remaining
 209 * regions are sized as shown; the first four addresses use the PL 1
 210 * values, and after that, we show "typical" values, since the actual
 211 * addresses depend on kernel #defines.
 212 *
 213 * MEM_HV_INTRPT                   0xfe000000
 214 * MEM_SV_INTRPT (kernel code)     0xfd000000
 215 * MEM_USER_INTRPT (user vector)   0xfc000000
 216 * FIX_KMAP_xxx                    0xf8000000 (via NR_CPUS * KM_TYPE_NR)
 217 * PKMAP_BASE                      0xf7000000 (via LAST_PKMAP)
 218 * HUGE_VMAP                       0xf3000000 (via CONFIG_NR_HUGE_VMAPS)
 219 * VMALLOC_START                   0xf0000000 (via __VMALLOC_RESERVE)
 220 * mapped LOWMEM                   0xc0000000
 221 */
 222
 223#define MEM_USER_INTRPT         _AC(0xfc000000, UL)
 224#if CONFIG_KERNEL_PL == 1
 225#define MEM_SV_INTRPT           _AC(0xfd000000, UL)
 226#define MEM_HV_INTRPT           _AC(0xfe000000, UL)
 227#else
 228#define MEM_GUEST_INTRPT        _AC(0xfd000000, UL)
 229#define MEM_SV_INTRPT           _AC(0xfe000000, UL)
 230#define MEM_HV_INTRPT           _AC(0xff000000, UL)
 231#endif
 232
 233#define INTRPT_SIZE             0x4000
 234
 235/* Tolerate page size larger than the architecture interrupt region size. */
 236#if PAGE_SIZE > INTRPT_SIZE
 237#undef INTRPT_SIZE
 238#define INTRPT_SIZE PAGE_SIZE
 239#endif
 240
 241#define KERNEL_HIGH_VADDR       MEM_USER_INTRPT
 242#define FIXADDR_TOP             (KERNEL_HIGH_VADDR - PAGE_SIZE)
 243
 244#define PAGE_OFFSET             _AC(CONFIG_PAGE_OFFSET, UL)
 245
 246/* On 32-bit architectures we mix kernel modules in with other vmaps. */
 247#define MEM_MODULE_START        VMALLOC_START
 248#define MEM_MODULE_END          VMALLOC_END
 249
 250#endif /* __tilegx__ */
 251
 252#ifndef __ASSEMBLY__
 253
 254#ifdef CONFIG_HIGHMEM
 255
 256/* Map kernel virtual addresses to page frames, in HPAGE_SIZE chunks. */
 257extern unsigned long pbase_map[];
 258extern void *vbase_map[];
 259
 260static inline unsigned long kaddr_to_pfn(const volatile void *_kaddr)
 261{
 262        unsigned long kaddr = (unsigned long)_kaddr;
 263        return pbase_map[kaddr >> HPAGE_SHIFT] +
 264                ((kaddr & (HPAGE_SIZE - 1)) >> PAGE_SHIFT);
 265}
 266
 267static inline void *pfn_to_kaddr(unsigned long pfn)
 268{
 269        return vbase_map[__pfn_to_highbits(pfn)] + (pfn << PAGE_SHIFT);
 270}
 271
 272static inline phys_addr_t virt_to_phys(const volatile void *kaddr)
 273{
 274        unsigned long pfn = kaddr_to_pfn(kaddr);
 275        return ((phys_addr_t)pfn << PAGE_SHIFT) +
 276                ((unsigned long)kaddr & (PAGE_SIZE-1));
 277}
 278
 279static inline void *phys_to_virt(phys_addr_t paddr)
 280{
 281        return pfn_to_kaddr(paddr >> PAGE_SHIFT) + (paddr & (PAGE_SIZE-1));
 282}
 283
 284/* With HIGHMEM, we pack PAGE_OFFSET through high_memory with all valid VAs. */
 285static inline int virt_addr_valid(const volatile void *kaddr)
 286{
 287        extern void *high_memory;  /* copied from <linux/mm.h> */
 288        return ((unsigned long)kaddr >= PAGE_OFFSET && kaddr < high_memory);
 289}
 290
 291#else /* !CONFIG_HIGHMEM */
 292
 293static inline unsigned long kaddr_to_pfn(const volatile void *kaddr)
 294{
 295        return ((unsigned long)kaddr - PAGE_OFFSET) >> PAGE_SHIFT;
 296}
 297
 298static inline void *pfn_to_kaddr(unsigned long pfn)
 299{
 300        return (void *)((pfn << PAGE_SHIFT) + PAGE_OFFSET);
 301}
 302
 303static inline phys_addr_t virt_to_phys(const volatile void *kaddr)
 304{
 305        return (phys_addr_t)((unsigned long)kaddr - PAGE_OFFSET);
 306}
 307
 308static inline void *phys_to_virt(phys_addr_t paddr)
 309{
 310        return (void *)((unsigned long)paddr + PAGE_OFFSET);
 311}
 312
 313/* Check that the given address is within some mapped range of PAs. */
 314#define virt_addr_valid(kaddr) pfn_valid(kaddr_to_pfn(kaddr))
 315
 316#endif /* !CONFIG_HIGHMEM */
 317
 318/* All callers are not consistent in how they call these functions. */
 319#define __pa(kaddr) virt_to_phys((void *)(unsigned long)(kaddr))
 320#define __va(paddr) phys_to_virt((phys_addr_t)(paddr))
 321
 322extern int devmem_is_allowed(unsigned long pagenr);
 323
 324#ifdef CONFIG_FLATMEM
 325static inline int pfn_valid(unsigned long pfn)
 326{
 327        return pfn < max_mapnr;
 328}
 329#endif
 330
 331/* Provide as macros since these require some other headers included. */
 332#define page_to_pa(page) ((phys_addr_t)(page_to_pfn(page)) << PAGE_SHIFT)
 333#define virt_to_page(kaddr) pfn_to_page(kaddr_to_pfn(kaddr))
 334#define page_to_virt(page) pfn_to_kaddr(page_to_pfn(page))
 335
 336struct mm_struct;
 337extern pte_t *virt_to_pte(struct mm_struct *mm, unsigned long addr);
 338
 339#endif /* !__ASSEMBLY__ */
 340
 341#define VM_DATA_DEFAULT_FLAGS \
 342        (VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
 343
 344#include <asm-generic/memory_model.h>
 345
 346#endif /* __KERNEL__ */
 347
 348#endif /* _ASM_TILE_PAGE_H */
 349