linux/include/asm-cris/pgtable.h
<<
>>
Prefs
   1/*
   2 * CRIS pgtable.h - macros and functions to manipulate page tables.
   3 */
   4
   5#ifndef _CRIS_PGTABLE_H
   6#define _CRIS_PGTABLE_H
   7
   8#include <asm-generic/4level-fixup.h>
   9
  10#ifndef __ASSEMBLY__
  11#include <linux/config.h>
  12#include <linux/sched.h>
  13#include <asm/mmu.h>
  14#endif
  15#include <asm/arch/pgtable.h>
  16
  17/*
  18 * The Linux memory management assumes a three-level page table setup. On
  19 * CRIS, we use that, but "fold" the mid level into the top-level page
  20 * table. Since the MMU TLB is software loaded through an interrupt, it
  21 * supports any page table structure, so we could have used a three-level
  22 * setup, but for the amounts of memory we normally use, a two-level is
  23 * probably more efficient.
  24 *
  25 * This file contains the functions and defines necessary to modify and use
  26 * the CRIS page table tree.
  27 */
  28#ifndef __ASSEMBLY__
  29extern void paging_init(void);
  30#endif
  31
  32/* Certain architectures need to do special things when pte's
  33 * within a page table are directly modified.  Thus, the following
  34 * hook is made available.
  35 */
  36#define set_pte(pteptr, pteval) ((*(pteptr)) = (pteval))
  37/*
  38 * (pmds are folded into pgds so this doesn't get actually called,
  39 * but the define is needed for a generic inline function.)
  40 */
  41#define set_pmd(pmdptr, pmdval) (*(pmdptr) = pmdval)
  42#define set_pgd(pgdptr, pgdval) (*(pgdptr) = pgdval)
  43
  44/* PMD_SHIFT determines the size of the area a second-level page table can
  45 * map. It is equal to the page size times the number of PTE's that fit in
  46 * a PMD page. A PTE is 4-bytes in CRIS. Hence the following number.
  47 */
  48
  49#define PMD_SHIFT       (PAGE_SHIFT + (PAGE_SHIFT-2))
  50#define PMD_SIZE        (1UL << PMD_SHIFT)
  51#define PMD_MASK        (~(PMD_SIZE-1))
  52
  53/* PGDIR_SHIFT determines what a third-level page table entry can map.
  54 * Since we fold into a two-level structure, this is the same as PMD_SHIFT.
  55 */
  56
  57#define PGDIR_SHIFT     PMD_SHIFT
  58#define PGDIR_SIZE      (1UL << PGDIR_SHIFT)
  59#define PGDIR_MASK      (~(PGDIR_SIZE-1))
  60
  61/*
  62 * entries per page directory level: we use a two-level, so
  63 * we don't really have any PMD directory physically.
  64 * pointers are 4 bytes so we can use the page size and 
  65 * divide it by 4 (shift by 2).
  66 */
  67#define PTRS_PER_PTE    (1UL << (PAGE_SHIFT-2))
  68#define PTRS_PER_PMD    1
  69#define PTRS_PER_PGD    (1UL << (PAGE_SHIFT-2))
  70
  71/* calculate how many PGD entries a user-level program can use
  72 * the first mappable virtual address is 0
  73 * (TASK_SIZE is the maximum virtual address space)
  74 */
  75
  76#define USER_PTRS_PER_PGD       (TASK_SIZE/PGDIR_SIZE)
  77#define FIRST_USER_PGD_NR       0
  78
  79/* zero page used for uninitialized stuff */
  80#ifndef __ASSEMBLY__
  81extern unsigned long empty_zero_page;
  82#define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
  83#endif
  84
  85/* number of bits that fit into a memory pointer */
  86#define BITS_PER_PTR                    (8*sizeof(unsigned long))
  87
  88/* to align the pointer to a pointer address */
  89#define PTR_MASK                        (~(sizeof(void*)-1))
  90
  91/* sizeof(void*)==1<<SIZEOF_PTR_LOG2 */
  92/* 64-bit machines, beware!  SRB. */
  93#define SIZEOF_PTR_LOG2                 2
  94
  95/* to find an entry in a page-table */
  96#define PAGE_PTR(address) \
  97((unsigned long)(address)>>(PAGE_SHIFT-SIZEOF_PTR_LOG2)&PTR_MASK&~PAGE_MASK)
  98
  99/* to set the page-dir */
 100#define SET_PAGE_DIR(tsk,pgdir)
 101
 102#define pte_none(x)     (!pte_val(x))
 103#define pte_present(x)  (pte_val(x) & _PAGE_PRESENT)
 104#define pte_clear(xp)   do { pte_val(*(xp)) = 0; } while (0)
 105
 106#define pmd_none(x)     (!pmd_val(x))
 107/* by removing the _PAGE_KERNEL bit from the comparision, the same pmd_bad
 108 * works for both _PAGE_TABLE and _KERNPG_TABLE pmd entries.
 109 */
 110#define pmd_bad(x)      ((pmd_val(x) & (~PAGE_MASK & ~_PAGE_KERNEL)) != _PAGE_TABLE)
 111#define pmd_present(x)  (pmd_val(x) & _PAGE_PRESENT)
 112#define pmd_clear(xp)   do { pmd_val(*(xp)) = 0; } while (0)
 113
 114#ifndef __ASSEMBLY__
 115
 116/*
 117 * The "pgd_xxx()" functions here are trivial for a folded two-level
 118 * setup: the pgd is never bad, and a pmd always exists (as it's folded
 119 * into the pgd entry)
 120 */
 121extern inline int pgd_none(pgd_t pgd)           { return 0; }
 122extern inline int pgd_bad(pgd_t pgd)            { return 0; }
 123extern inline int pgd_present(pgd_t pgd)        { return 1; }
 124extern inline void pgd_clear(pgd_t * pgdp)      { }
 125
 126/*
 127 * The following only work if pte_present() is true.
 128 * Undefined behaviour if not..
 129 */
 130
 131extern inline int pte_read(pte_t pte)           { return pte_val(pte) & _PAGE_READ; }
 132extern inline int pte_write(pte_t pte)          { return pte_val(pte) & _PAGE_WRITE; }
 133extern inline int pte_exec(pte_t pte)           { return pte_val(pte) & _PAGE_READ; }
 134extern inline int pte_dirty(pte_t pte)          { return pte_val(pte) & _PAGE_MODIFIED; }
 135extern inline int pte_young(pte_t pte)          { return pte_val(pte) & _PAGE_ACCESSED; }
 136extern inline int pte_file(pte_t pte)           { return pte_val(pte) & _PAGE_FILE; }
 137
 138extern inline pte_t pte_wrprotect(pte_t pte)
 139{
 140        pte_val(pte) &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE);
 141        return pte;
 142}
 143
 144extern inline pte_t pte_rdprotect(pte_t pte)
 145{
 146        pte_val(pte) &= ~(_PAGE_READ | _PAGE_SILENT_READ);
 147        return pte;
 148}
 149
 150extern inline pte_t pte_exprotect(pte_t pte)
 151{
 152        pte_val(pte) &= ~(_PAGE_READ | _PAGE_SILENT_READ);
 153        return pte;
 154}
 155
 156extern inline pte_t pte_mkclean(pte_t pte)
 157{
 158        pte_val(pte) &= ~(_PAGE_MODIFIED | _PAGE_SILENT_WRITE); 
 159        return pte; 
 160}
 161
 162extern inline pte_t pte_mkold(pte_t pte)
 163{
 164        pte_val(pte) &= ~(_PAGE_ACCESSED | _PAGE_SILENT_READ);
 165        return pte;
 166}
 167
 168extern inline pte_t pte_mkwrite(pte_t pte)
 169{
 170        pte_val(pte) |= _PAGE_WRITE;
 171        if (pte_val(pte) & _PAGE_MODIFIED)
 172                pte_val(pte) |= _PAGE_SILENT_WRITE;
 173        return pte;
 174}
 175
 176extern inline pte_t pte_mkread(pte_t pte)
 177{
 178        pte_val(pte) |= _PAGE_READ;
 179        if (pte_val(pte) & _PAGE_ACCESSED)
 180                pte_val(pte) |= _PAGE_SILENT_READ;
 181        return pte;
 182}
 183
 184extern inline pte_t pte_mkexec(pte_t pte)
 185{
 186        pte_val(pte) |= _PAGE_READ;
 187        if (pte_val(pte) & _PAGE_ACCESSED)
 188                pte_val(pte) |= _PAGE_SILENT_READ;
 189        return pte;
 190}
 191
 192extern inline pte_t pte_mkdirty(pte_t pte)
 193{
 194        pte_val(pte) |= _PAGE_MODIFIED;
 195        if (pte_val(pte) & _PAGE_WRITE)
 196                pte_val(pte) |= _PAGE_SILENT_WRITE;
 197        return pte;
 198}
 199
 200extern inline pte_t pte_mkyoung(pte_t pte)
 201{
 202        pte_val(pte) |= _PAGE_ACCESSED;
 203        if (pte_val(pte) & _PAGE_READ)
 204        {
 205                pte_val(pte) |= _PAGE_SILENT_READ;
 206                if ((pte_val(pte) & (_PAGE_WRITE | _PAGE_MODIFIED)) ==
 207                    (_PAGE_WRITE | _PAGE_MODIFIED))
 208                        pte_val(pte) |= _PAGE_SILENT_WRITE;
 209        }
 210        return pte;
 211}
 212
 213/*
 214 * Conversion functions: convert a page and protection to a page entry,
 215 * and a page entry and page directory to the page they refer to.
 216 */
 217
 218/* What actually goes as arguments to the various functions is less than
 219 * obvious, but a rule of thumb is that struct page's goes as struct page *,
 220 * really physical DRAM addresses are unsigned long's, and DRAM "virtual"
 221 * addresses (the 0xc0xxxxxx's) goes as void *'s.
 222 */
 223
 224extern inline pte_t __mk_pte(void * page, pgprot_t pgprot)
 225{
 226        pte_t pte;
 227        /* the PTE needs a physical address */
 228        pte_val(pte) = __pa(page) | pgprot_val(pgprot);
 229        return pte;
 230}
 231
 232#define mk_pte(page, pgprot) __mk_pte(page_address(page), (pgprot))
 233
 234#define mk_pte_phys(physpage, pgprot) \
 235({                                                                      \
 236        pte_t __pte;                                                    \
 237                                                                        \
 238        pte_val(__pte) = (physpage) + pgprot_val(pgprot);               \
 239        __pte;                                                          \
 240})
 241
 242extern inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
 243{ pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot); return pte; }
 244
 245
 246/* pte_val refers to a page in the 0x4xxxxxxx physical DRAM interval
 247 * __pte_page(pte_val) refers to the "virtual" DRAM interval
 248 * pte_pagenr refers to the page-number counted starting from the virtual DRAM start
 249 */
 250
 251extern inline unsigned long __pte_page(pte_t pte)
 252{
 253        /* the PTE contains a physical address */
 254        return (unsigned long)__va(pte_val(pte) & PAGE_MASK);
 255}
 256
 257#define pte_pagenr(pte)         ((__pte_page(pte) - PAGE_OFFSET) >> PAGE_SHIFT)
 258
 259/* permanent address of a page */
 260
 261#define __page_address(page)    (PAGE_OFFSET + (((page) - mem_map) << PAGE_SHIFT))
 262#define pte_page(pte)           (mem_map+pte_pagenr(pte))
 263
 264/* only the pte's themselves need to point to physical DRAM (see above)
 265 * the pagetable links are purely handled within the kernel SW and thus
 266 * don't need the __pa and __va transformations.
 267 */
 268
 269extern inline void pmd_set(pmd_t * pmdp, pte_t * ptep)
 270{ pmd_val(*pmdp) = _PAGE_TABLE | (unsigned long) ptep; }
 271
 272#define pmd_page(pmd)           (pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT))
 273#define pmd_page_kernel(pmd)    ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))
 274
 275/* to find an entry in a page-table-directory. */
 276#define pgd_index(address) ((address >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
 277
 278/* to find an entry in a page-table-directory */
 279extern inline pgd_t * pgd_offset(struct mm_struct * mm, unsigned long address)
 280{
 281        return mm->pgd + pgd_index(address);
 282}
 283
 284/* to find an entry in a kernel page-table-directory */
 285#define pgd_offset_k(address) pgd_offset(&init_mm, address)
 286
 287/* Find an entry in the second-level page table.. */
 288extern inline pmd_t * pmd_offset(pgd_t * dir, unsigned long address)
 289{
 290        return (pmd_t *) dir;
 291}
 292
 293/* Find an entry in the third-level page table.. */
 294#define __pte_offset(address) \
 295        (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
 296#define pte_offset_kernel(dir, address) \
 297        ((pte_t *) pmd_page_kernel(*(dir)) +  __pte_offset(address))
 298#define pte_offset_map(dir, address) \
 299        ((pte_t *)page_address(pmd_page(*(dir))) + __pte_offset(address))
 300#define pte_offset_map_nested(dir, address) pte_offset_map(dir, address)
 301
 302#define pte_unmap(pte) do { } while (0)
 303#define pte_unmap_nested(pte) do { } while (0)
 304#define pte_pfn(x)              ((unsigned long)(__va((x).pte)) >> PAGE_SHIFT)
 305#define pfn_pte(pfn, prot)      __pte((__pa((pfn) << PAGE_SHIFT)) | pgprot_val(prot))
 306
 307#define pte_ERROR(e) \
 308        printk("%s:%d: bad pte %p(%08lx).\n", __FILE__, __LINE__, &(e), pte_val(e))
 309#define pmd_ERROR(e) \
 310        printk("%s:%d: bad pmd %p(%08lx).\n", __FILE__, __LINE__, &(e), pmd_val(e))
 311#define pgd_ERROR(e) \
 312        printk("%s:%d: bad pgd %p(%08lx).\n", __FILE__, __LINE__, &(e), pgd_val(e))
 313
 314
 315extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; /* defined in head.S */
 316
 317/*
 318 * CRIS doesn't have any external MMU info: the kernel page
 319 * tables contain all the necessary information.
 320 * 
 321 * Actually I am not sure on what this could be used for.
 322 */
 323extern inline void update_mmu_cache(struct vm_area_struct * vma,
 324        unsigned long address, pte_t pte)
 325{
 326}
 327
 328/* Encode and de-code a swap entry (must be !pte_none(e) && !pte_present(e)) */
 329/* Since the PAGE_PRESENT bit is bit 4, we can use the bits above */
 330
 331#define __swp_type(x)                   (((x).val >> 5) & 0x7f)
 332#define __swp_offset(x)                 ((x).val >> 12)
 333#define __swp_entry(type, offset)       ((swp_entry_t) { ((type) << 5) | ((offset) << 12) })
 334#define __pte_to_swp_entry(pte)         ((swp_entry_t) { pte_val(pte) })
 335#define __swp_entry_to_pte(x)           ((pte_t) { (x).val })
 336
 337#define kern_addr_valid(addr)   (1)
 338
 339#include <asm-generic/pgtable.h>
 340
 341/*
 342 * No page table caches to initialise
 343 */
 344#define pgtable_cache_init()   do { } while (0)
 345
 346#define pte_to_pgoff(x) (pte_val(x) >> 6)
 347#define pgoff_to_pte(x) __pte(((x) << 6) | _PAGE_FILE)
 348
 349#endif /* __ASSEMBLY__ */
 350#endif /* _CRIS_PGTABLE_H */
 351
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.