root/include/asm-alpha/pgtable.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. mk_pte
  2. pte_modify
  3. pmd_set
  4. pgd_set
  5. pte_page
  6. pmd_page
  7. pgd_page
  8. pte_none
  9. pte_present
  10. pte_clear
  11. pmd_none
  12. pmd_bad
  13. pmd_present
  14. pmd_clear
  15. pgd_none
  16. pgd_bad
  17. pgd_present
  18. pgd_clear
  19. pte_read
  20. pte_write
  21. pte_exec
  22. pte_dirty
  23. pte_young
  24. pte_cow
  25. pte_wrprotect
  26. pte_rdprotect
  27. pte_exprotect
  28. pte_mkclean
  29. pte_mkold
  30. pte_uncow
  31. pte_mkwrite
  32. pte_mkread
  33. pte_mkexec
  34. pte_mkdirty
  35. pte_mkyoung
  36. pte_mkcow
  37. SET_PAGE_DIR
  38. pgd_offset
  39. pmd_offset
  40. pte_offset
  41. pte_free_kernel
  42. pte_alloc_kernel
  43. pmd_free_kernel
  44. pmd_alloc_kernel
  45. pte_free
  46. pte_alloc
  47. pmd_free
  48. pmd_alloc

   1 #ifndef _ALPHA_PGTABLE_H
   2 #define _ALPHA_PGTABLE_H
   3 
   4 /*
   5  * This file contains the functions and defines necessary to modify and use
   6  * the alpha page table tree.
   7  *
   8  * This hopefully works with any standard alpha page-size, as defined
   9  * in <asm/page.h> (currently 8192).
  10  */
  11 
  12 /* PMD_SHIFT determines the size of the area a second-level page table can map */
  13 #define PMD_SHIFT       (PAGE_SHIFT + (PAGE_SHIFT-3))
  14 #define PMD_SIZE        (1UL << PMD_SHIFT)
  15 #define PMD_MASK        (~(PMD_SIZE-1))
  16 
  17 /* PGDIR_SHIFT determines what a third-level page table entry can map */
  18 #define PGDIR_SHIFT     (PAGE_SHIFT + 2*(PAGE_SHIFT-3))
  19 #define PGDIR_SIZE      (1UL << PGDIR_SHIFT)
  20 #define PGDIR_MASK      (~(PGDIR_SIZE-1))
  21 
  22 /*
  23  * entries per page directory level: the alpha is three-level, with
  24  * all levels having a one-page page table.
  25  */
  26 #define PTRS_PER_PTE    (1UL << (PAGE_SHIFT-3))
  27 #define PTRS_PER_PMD    (1UL << (PAGE_SHIFT-3))
  28 #define PTRS_PER_PGD    (1UL << (PAGE_SHIFT-3))
  29 
  30 /* the no. of pointers that fit on a page: this will go away */
  31 #define PTRS_PER_PAGE   (1UL << (PAGE_SHIFT-3))
  32 
  33 #define VMALLOC_START           0xFFFFFE0000000000
  34 #define VMALLOC_VMADDR(x)       ((unsigned long)(x))
  35 
  36 /*
  37  * OSF/1 PAL-code-imposed page table bits
  38  */
  39 #define _PAGE_VALID     0x0001
  40 #define _PAGE_FOR       0x0002  /* used for page protection (fault on read) */
  41 #define _PAGE_FOW       0x0004  /* used for page protection (fault on write) */
  42 #define _PAGE_FOE       0x0008  /* used for page protection (fault on exec) */
  43 #define _PAGE_ASM       0x0010
  44 #define _PAGE_KRE       0x0100  /* xxx - see below on the "accessed" bit */
  45 #define _PAGE_URE       0x0200  /* xxx */
  46 #define _PAGE_KWE       0x1000  /* used to do the dirty bit in software */
  47 #define _PAGE_UWE       0x2000  /* used to do the dirty bit in software */
  48 
  49 /* .. and these are ours ... */
  50 #define _PAGE_COW       0x10000
  51 #define _PAGE_DIRTY     0x20000
  52 #define _PAGE_ACCESSED  0x40000
  53 
  54 /*
  55  * NOTE! The "accessed" bit isn't necessarily exact: it can be kept exactly
  56  * by software (use the KRE/URE/KWE/UWE bits appropritely), but I'll fake it.
  57  * Under Linux/AXP, the "accessed" bit just means "read", and I'll just use
  58  * the KRE/URE bits to watch for it. That way we don't need to overload the
  59  * KWE/UWE bits with both handling dirty and accessed.
  60  *
  61  * Note that the kernel uses the accessed bit just to check whether to page
  62  * out a page or not, so it doesn't have to be exact anyway.
  63  */
  64 
  65 #define __DIRTY_BITS    (_PAGE_DIRTY | _PAGE_KWE | _PAGE_UWE)
  66 #define __ACCESS_BITS   (_PAGE_ACCESSED | _PAGE_KRE | _PAGE_URE)
  67 
  68 #define _PFN_MASK       0xFFFFFFFF00000000
  69 
  70 #define _PAGE_TABLE     (_PAGE_VALID | __DIRTY_BITS | __ACCESS_BITS)
  71 #define _PAGE_CHG_MASK  (_PFN_MASK | __DIRTY_BITS | __ACCESS_BITS)
  72 
  73 /*
  74  * All the normal masks have the "page accessed" bits on, as any time they are used,
  75  * the page is accessed. They are cleared only by the page-out routines
  76  */
  77 #define PAGE_NONE       __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOR | _PAGE_FOW | _PAGE_FOE)
  78 #define PAGE_SHARED     __pgprot(_PAGE_VALID | __ACCESS_BITS)
  79 #define PAGE_COPY       __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_COW)
  80 #define PAGE_READONLY   __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
  81 #define PAGE_KERNEL     __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
  82 
  83 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
  84 
  85 #define __P000  _PAGE_NORMAL(_PAGE_COW | _PAGE_FOR | _PAGE_FOW | _PAGE_FOE)
  86 #define __P001  _PAGE_NORMAL(_PAGE_COW | _PAGE_FOW | _PAGE_FOE)
  87 #define __P010  _PAGE_NORMAL(_PAGE_COW | _PAGE_FOR | _PAGE_FOE)
  88 #define __P011  _PAGE_NORMAL(_PAGE_COW | _PAGE_FOE)
  89 #define __P100  _PAGE_NORMAL(_PAGE_COW | _PAGE_FOR | _PAGE_FOW)
  90 #define __P101  _PAGE_NORMAL(_PAGE_COW | _PAGE_FOW)
  91 #define __P110  _PAGE_NORMAL(_PAGE_COW | _PAGE_FOR)
  92 #define __P111  _PAGE_NORMAL(_PAGE_COW)
  93 
  94 #define __S000  _PAGE_NORMAL(_PAGE_FOR | _PAGE_FOW | _PAGE_FOE)
  95 #define __S001  _PAGE_NORMAL(_PAGE_FOW | _PAGE_FOE)
  96 #define __S010  _PAGE_NORMAL(_PAGE_FOR | _PAGE_FOE)
  97 #define __S011  _PAGE_NORMAL(_PAGE_FOE)
  98 #define __S100  _PAGE_NORMAL(_PAGE_FOR | _PAGE_FOW)
  99 #define __S101  _PAGE_NORMAL(_PAGE_FOW)
 100 #define __S110  _PAGE_NORMAL(_PAGE_FOR)
 101 #define __S111  _PAGE_NORMAL(0)
 102 
 103 /*
 104  * BAD_PAGETABLE is used when we need a bogus page-table, while
 105  * BAD_PAGE is used for a bogus page.
 106  *
 107  * ZERO_PAGE is a global shared page that is always zero: used
 108  * for zero-mapped memory areas etc..
 109  */
 110 extern pte_t __bad_page(void);
 111 extern pmd_t * __bad_pagetable(void);
 112 
 113 extern unsigned long __zero_page(void);
 114 
 115 #define BAD_PAGETABLE __bad_pagetable()
 116 #define BAD_PAGE __bad_page()
 117 #define ZERO_PAGE __zero_page()
 118 
 119 /* number of bits that fit into a memory pointer */
 120 #define BITS_PER_PTR                    (8*sizeof(unsigned long))
 121 
 122 /* to align the pointer to a pointer address */
 123 #define PTR_MASK                        (~(sizeof(void*)-1))
 124 
 125 /* sizeof(void*)==1<<SIZEOF_PTR_LOG2 */
 126 #define SIZEOF_PTR_LOG2                 3
 127 
 128 /* to find an entry in a page-table */
 129 #define PAGE_PTR(address)               \
 130   ((unsigned long)(address)>>(PAGE_SHIFT-SIZEOF_PTR_LOG2)&PTR_MASK&~PAGE_MASK)
 131 
 132 extern unsigned long high_memory;
 133 
 134 /*
 135  * Conversion functions: convert a page and protection to a page entry,
 136  * and a page entry and page directory to the page they refer to.
 137  */
 138 extern inline pte_t mk_pte(unsigned long page, pgprot_t pgprot)
     /* [previous][next][first][last][top][bottom][index][help] */
 139 { pte_t pte; pte_val(pte) = ((page-PAGE_OFFSET) << (32-PAGE_SHIFT)) | pgprot_val(pgprot); return pte; }
 140 
 141 extern inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
     /* [previous][next][first][last][top][bottom][index][help] */
 142 { pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot); return pte; }
 143 
 144 extern inline void pmd_set(pmd_t * pmdp, pte_t * ptep)
     /* [previous][next][first][last][top][bottom][index][help] */
 145 { pmd_val(*pmdp) = _PAGE_TABLE | ((((unsigned long) ptep) - PAGE_OFFSET) << (32-PAGE_SHIFT)); }
 146 
 147 extern inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
     /* [previous][next][first][last][top][bottom][index][help] */
 148 { pgd_val(*pgdp) = _PAGE_TABLE | ((((unsigned long) pmdp) - PAGE_OFFSET) << (32-PAGE_SHIFT)); }
 149 
 150 extern inline unsigned long pte_page(pte_t pte)
     /* [previous][next][first][last][top][bottom][index][help] */
 151 { return PAGE_OFFSET + ((pte_val(pte) & _PFN_MASK) >> (32-PAGE_SHIFT)); }
 152 
 153 extern inline unsigned long pmd_page(pmd_t pmd)
     /* [previous][next][first][last][top][bottom][index][help] */
 154 { return PAGE_OFFSET + ((pmd_val(pmd) & _PFN_MASK) >> (32-PAGE_SHIFT)); }
 155 
 156 extern inline unsigned long pgd_page(pgd_t pgd)
     /* [previous][next][first][last][top][bottom][index][help] */
 157 { return PAGE_OFFSET + ((pgd_val(pgd) & _PFN_MASK) >> (32-PAGE_SHIFT)); }
 158 
 159 extern inline int pte_none(pte_t pte)           { return !pte_val(pte); }
     /* [previous][next][first][last][top][bottom][index][help] */
 160 extern inline int pte_present(pte_t pte)        { return pte_val(pte) & _PAGE_VALID; }
     /* [previous][next][first][last][top][bottom][index][help] */
 161 extern inline void pte_clear(pte_t *ptep)       { pte_val(*ptep) = 0; }
     /* [previous][next][first][last][top][bottom][index][help] */
 162 
 163 extern inline int pmd_none(pmd_t pmd)           { return !pmd_val(pmd); }
     /* [previous][next][first][last][top][bottom][index][help] */
 164 extern inline int pmd_bad(pmd_t pmd)            { return (pmd_val(pmd) & ~_PFN_MASK) != _PAGE_TABLE || pmd_page(pmd) > high_memory; }
     /* [previous][next][first][last][top][bottom][index][help] */
 165 extern inline int pmd_present(pmd_t pmd)        { return pmd_val(pmd) & _PAGE_VALID; }
     /* [previous][next][first][last][top][bottom][index][help] */
 166 extern inline void pmd_clear(pmd_t * pmdp)      { pmd_val(*pmdp) = 0; }
     /* [previous][next][first][last][top][bottom][index][help] */
 167 
 168 extern inline int pgd_none(pgd_t pgd)           { return !pgd_val(pgd); }
     /* [previous][next][first][last][top][bottom][index][help] */
 169 extern inline int pgd_bad(pgd_t pgd)            { return (pgd_val(pgd) & ~_PFN_MASK) != _PAGE_TABLE || pgd_page(pgd) > high_memory; }
     /* [previous][next][first][last][top][bottom][index][help] */
 170 extern inline int pgd_present(pgd_t pgd)        { return pgd_val(pgd) & _PAGE_VALID; }
     /* [previous][next][first][last][top][bottom][index][help] */
 171 extern inline void pgd_clear(pgd_t * pgdp)      { pgd_val(*pgdp) = 0; }
     /* [previous][next][first][last][top][bottom][index][help] */
 172 
 173 /*
 174  * The following only work if pte_present() is true.
 175  * Undefined behaviour if not..
 176  */
 177 extern inline int pte_read(pte_t pte)           { return !(pte_val(pte) & _PAGE_FOR); }
     /* [previous][next][first][last][top][bottom][index][help] */
 178 extern inline int pte_write(pte_t pte)          { return !(pte_val(pte) & _PAGE_FOW); }
     /* [previous][next][first][last][top][bottom][index][help] */
 179 extern inline int pte_exec(pte_t pte)           { return !(pte_val(pte) & _PAGE_FOE); }
     /* [previous][next][first][last][top][bottom][index][help] */
 180 extern inline int pte_dirty(pte_t pte)          { return pte_val(pte) & _PAGE_DIRTY; }
     /* [previous][next][first][last][top][bottom][index][help] */
 181 extern inline int pte_young(pte_t pte)          { return pte_val(pte) & _PAGE_ACCESSED; }
     /* [previous][next][first][last][top][bottom][index][help] */
 182 extern inline int pte_cow(pte_t pte)            { return pte_val(pte) & _PAGE_COW; }
     /* [previous][next][first][last][top][bottom][index][help] */
 183 
 184 extern inline pte_t pte_wrprotect(pte_t pte)    { pte_val(pte) |= _PAGE_FOW; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 185 extern inline pte_t pte_rdprotect(pte_t pte)    { pte_val(pte) |= _PAGE_FOR; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 186 extern inline pte_t pte_exprotect(pte_t pte)    { pte_val(pte) |= _PAGE_FOE; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 187 extern inline pte_t pte_mkclean(pte_t pte)      { pte_val(pte) &= ~(__DIRTY_BITS); return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 188 extern inline pte_t pte_mkold(pte_t pte)        { pte_val(pte) &= ~(__ACCESS_BITS); return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 189 extern inline pte_t pte_uncow(pte_t pte)        { pte_val(pte) &= ~_PAGE_COW; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 190 extern inline pte_t pte_mkwrite(pte_t pte)      { pte_val(pte) &= _PAGE_FOW; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 191 extern inline pte_t pte_mkread(pte_t pte)       { pte_val(pte) &= _PAGE_FOR; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 192 extern inline pte_t pte_mkexec(pte_t pte)       { pte_val(pte) &= _PAGE_FOE; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 193 extern inline pte_t pte_mkdirty(pte_t pte)      { pte_val(pte) |= __DIRTY_BITS; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 194 extern inline pte_t pte_mkyoung(pte_t pte)      { pte_val(pte) |= __ACCESS_BITS; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 195 extern inline pte_t pte_mkcow(pte_t pte)        { pte_val(pte) |= _PAGE_COW; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 196 
 197 /* to set the page-dir */
 198 extern inline void SET_PAGE_DIR(struct task_struct * tsk, pgd_t * pgdir)
     /* [previous][next][first][last][top][bottom][index][help] */
 199 {
 200         tsk->tss.ptbr = ((unsigned long) pgdir - PAGE_OFFSET) >> PAGE_SHIFT;
 201         if (tsk == current)
 202                 invalidate();
 203 }
 204 
 205 #define PAGE_DIR_OFFSET(tsk,address) pgd_offset((tsk),(address))
 206 
 207 /* to find an entry in a page-table-directory */
 208 extern inline pgd_t * pgd_offset(struct task_struct * tsk, unsigned long address)
     /* [previous][next][first][last][top][bottom][index][help] */
 209 {
 210         return (pgd_t *) ((tsk->tss.ptbr << PAGE_SHIFT) + PAGE_OFFSET) +
 211                 ((address >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1));
 212 }
 213 
 214 /* Find an entry in the second-level page table.. */
 215 extern inline pmd_t * pmd_offset(pgd_t * dir, unsigned long address)
     /* [previous][next][first][last][top][bottom][index][help] */
 216 {
 217         return (pmd_t *) pgd_page(*dir) + ((address >> PMD_SHIFT) & (PTRS_PER_PMD - 1));
 218 }
 219 
 220 /* Find an entry in the third-level page table.. */
 221 extern inline pte_t * pte_offset(pmd_t * dir, unsigned long address)
     /* [previous][next][first][last][top][bottom][index][help] */
 222 {
 223         return (pte_t *) pmd_page(*dir) + ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1));
 224 }
 225 
 226 /*              
 227  * Allocate and free page tables. The xxx_kernel() versions are
 228  * used to allocate a kernel page table - this turns on ASN bits
 229  * if any, and marks the page tables reserved.
 230  */
 231 extern inline void pte_free_kernel(pte_t * pte)
     /* [previous][next][first][last][top][bottom][index][help] */
 232 {
 233         mem_map[MAP_NR(pte)] = 1;
 234         free_page((unsigned long) pte);
 235 }
 236 
 237 extern inline pte_t * pte_alloc_kernel(pmd_t *pmd, unsigned long address)
     /* [previous][next][first][last][top][bottom][index][help] */
 238 {
 239         address = (address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1);
 240         if (pmd_none(*pmd)) {
 241                 pte_t *page = (pte_t *) get_free_page(GFP_KERNEL);
 242                 if (pmd_none(*pmd)) {
 243                         if (page) {
 244                                 pmd_set(pmd, page);
 245                                 mem_map[MAP_NR(page)] = MAP_PAGE_RESERVED;
 246                                 return page + address;
 247                         }
 248                         pmd_set(pmd, (pte_t *) BAD_PAGETABLE);
 249                         return NULL;
 250                 }
 251                 free_page((unsigned long) page);
 252         }
 253         if (pmd_bad(*pmd)) {
 254                 printk("Bad pmd in pte_alloc: %08lx\n", pmd_val(*pmd));
 255                 pmd_set(pmd, (pte_t *) BAD_PAGETABLE);
 256                 return NULL;
 257         }
 258         return (pte_t *) pmd_page(*pmd) + address;
 259 }
 260 
 261 extern inline void pmd_free_kernel(pmd_t * pmd)
     /* [previous][next][first][last][top][bottom][index][help] */
 262 {
 263         mem_map[MAP_NR(pmd)] = 1;
 264         free_page((unsigned long) pmd);
 265 }
 266 
 267 extern inline pmd_t * pmd_alloc_kernel(pgd_t *pgd, unsigned long address)
     /* [previous][next][first][last][top][bottom][index][help] */
 268 {
 269         address = (address >> PMD_SHIFT) & (PTRS_PER_PMD - 1);
 270         if (pgd_none(*pgd)) {
 271                 pmd_t *page = (pmd_t *) get_free_page(GFP_KERNEL);
 272                 if (pgd_none(*pgd)) {
 273                         if (page) {
 274                                 pgd_set(pgd, page);
 275                                 mem_map[MAP_NR(page)] = MAP_PAGE_RESERVED;
 276                                 return page + address;
 277                         }
 278                         pgd_set(pgd, BAD_PAGETABLE);
 279                         return NULL;
 280                 }
 281                 free_page((unsigned long) page);
 282         }
 283         if (pgd_bad(*pgd)) {
 284                 printk("Bad pgd in pmd_alloc: %08lx\n", pgd_val(*pgd));
 285                 pgd_set(pgd, BAD_PAGETABLE);
 286                 return NULL;
 287         }
 288         return (pmd_t *) pgd_page(*pgd) + address;
 289 }
 290 
 291 extern inline void pte_free(pte_t * pte)
     /* [previous][next][first][last][top][bottom][index][help] */
 292 {
 293         free_page((unsigned long) pte);
 294 }
 295 
 296 extern inline pte_t * pte_alloc(pmd_t *pmd, unsigned long address)
     /* [previous][next][first][last][top][bottom][index][help] */
 297 {
 298         address = (address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1);
 299         if (pmd_none(*pmd)) {
 300                 pte_t *page = (pte_t *) get_free_page(GFP_KERNEL);
 301                 if (pmd_none(*pmd)) {
 302                         if (page) {
 303                                 pmd_set(pmd, page);
 304                                 return page + address;
 305                         }
 306                         pmd_set(pmd, (pte_t *) BAD_PAGETABLE);
 307                         return NULL;
 308                 }
 309                 free_page((unsigned long) page);
 310         }
 311         if (pmd_bad(*pmd)) {
 312                 printk("Bad pmd in pte_alloc: %08lx\n", pmd_val(*pmd));
 313                 pmd_set(pmd, (pte_t *) BAD_PAGETABLE);
 314                 return NULL;
 315         }
 316         return (pte_t *) pmd_page(*pmd) + address;
 317 }
 318 
 319 extern inline void pmd_free(pmd_t * pmd)
     /* [previous][next][first][last][top][bottom][index][help] */
 320 {
 321         free_page((unsigned long) pmd);
 322 }
 323 
 324 extern inline pmd_t * pmd_alloc(pgd_t *pgd, unsigned long address)
     /* [previous][next][first][last][top][bottom][index][help] */
 325 {
 326         address = (address >> PMD_SHIFT) & (PTRS_PER_PMD - 1);
 327         if (pgd_none(*pgd)) {
 328                 pmd_t *page = (pmd_t *) get_free_page(GFP_KERNEL);
 329                 if (pgd_none(*pgd)) {
 330                         if (page) {
 331                                 pgd_set(pgd, page);
 332                                 return page + address;
 333                         }
 334                         pgd_set(pgd, BAD_PAGETABLE);
 335                         return NULL;
 336                 }
 337                 free_page((unsigned long) page);
 338         }
 339         if (pgd_bad(*pgd)) {
 340                 printk("Bad pgd in pmd_alloc: %08lx\n", pgd_val(*pgd));
 341                 pgd_set(pgd, BAD_PAGETABLE);
 342                 return NULL;
 343         }
 344         return (pmd_t *) pgd_page(*pgd) + address;
 345 }
 346 
 347 extern pgd_t swapper_pg_dir[1024];
 348 
 349 #endif /* _ALPHA_PGTABLE_H */

/* [previous][next][first][last][top][bottom][index][help] */