root/include/asm-i386/pgtable.h

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

INCLUDED FROM


DEFINITIONS

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

   1 #ifndef _I386_PGTABLE_H
   2 #define _I386_PGTABLE_H
   3 
   4 /*
   5  * The Linux memory management assumes a three-level page table setup. On
   6  * the i386, we use that, but "fold" the mid level into the top-level page
   7  * table, so that we physically have the same two-level page table as the
   8  * i386 mmu expects.
   9  *
  10  * This file contains the functions and defines necessary to modify and use
  11  * the i386 page table tree.
  12  */
  13 
  14 /* PMD_SHIFT determines the size of the area a second-level page table can map */
  15 #define PMD_SHIFT       22
  16 #define PMD_SIZE        (1UL << PMD_SHIFT)
  17 #define PMD_MASK        (~(PMD_SIZE-1))
  18 
  19 /* PGDIR_SHIFT determines what a third-level page table entry can map */
  20 #define PGDIR_SHIFT     22
  21 #define PGDIR_SIZE      (1UL << PGDIR_SHIFT)
  22 #define PGDIR_MASK      (~(PGDIR_SIZE-1))
  23 
  24 /*
  25  * entries per page directory level: the i386 is two-level, so
  26  * we don't really have any PMD directory physically.
  27  */
  28 #define PTRS_PER_PTE    1024
  29 #define PTRS_PER_PMD    1
  30 #define PTRS_PER_PGD    1024
  31 
  32 /* Just any arbitrary offset to the start of the vmalloc VM area: the
  33  * current 8MB value just means that there will be a 8MB "hole" after the
  34  * physical memory until the kernel virtual memory starts.  That means that
  35  * any out-of-bounds memory accesses will hopefully be caught.
  36  * The vmalloc() routines leaves a hole of 4kB between each vmalloced
  37  * area for the same reason. ;)
  38  */
  39 #define VMALLOC_OFFSET  (8*1024*1024)
  40 #define VMALLOC_START ((high_memory + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1))
  41 #define VMALLOC_VMADDR(x) (TASK_SIZE + (unsigned long)(x))
  42 
  43 #define _PAGE_PRESENT   0x001
  44 #define _PAGE_RW        0x002
  45 #define _PAGE_USER      0x004
  46 #define _PAGE_ACCESSED  0x020
  47 #define _PAGE_DIRTY     0x040
  48 #define _PAGE_COW       0x200   /* implemented in software (one of the AVL bits) */
  49 
  50 #define _PAGE_TABLE     (_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_ACCESSED | _PAGE_DIRTY)
  51 #define _PAGE_CHG_MASK  (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
  52 
  53 #define PAGE_NONE       __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED)
  54 #define PAGE_SHARED     __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_ACCESSED)
  55 #define PAGE_COPY       __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED | _PAGE_COW)
  56 #define PAGE_READONLY   __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED)
  57 #define PAGE_KERNEL     __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED)
  58 
  59 /*
  60  * The i386 can't do page protection for execute, and considers that the same are read.
  61  * Also, write permissions imply read permissions. This is the closest we can get..
  62  */
  63 #define __P000  PAGE_NONE
  64 #define __P001  PAGE_READONLY
  65 #define __P010  PAGE_COPY
  66 #define __P011  PAGE_COPY
  67 #define __P100  PAGE_READONLY
  68 #define __P101  PAGE_READONLY
  69 #define __P110  PAGE_COPY
  70 #define __P111  PAGE_COPY
  71 
  72 #define __S000  PAGE_NONE
  73 #define __S001  PAGE_READONLY
  74 #define __S010  PAGE_SHARED
  75 #define __S011  PAGE_SHARED
  76 #define __S100  PAGE_READONLY
  77 #define __S101  PAGE_READONLY
  78 #define __S110  PAGE_SHARED
  79 #define __S111  PAGE_SHARED
  80 
  81 /*
  82  * Define this if things work differently on a i386 and a i486:
  83  * it will (on a i486) warn about kernel memory accesses that are
  84  * done without a 'verify_area(VERIFY_WRITE,..)'
  85  */
  86 #undef CONFIG_TEST_VERIFY_AREA
  87 
  88 /* page table for 0-4MB for everybody */
  89 extern unsigned long pg0[1024];
  90 
  91 /*
  92  * BAD_PAGETABLE is used when we need a bogus page-table, while
  93  * BAD_PAGE is used for a bogus page.
  94  *
  95  * ZERO_PAGE is a global shared page that is always zero: used
  96  * for zero-mapped memory areas etc..
  97  */
  98 extern pte_t __bad_page(void);
  99 extern pte_t * __bad_pagetable(void);
 100 
 101 extern unsigned long __zero_page(void);
 102 
 103 #define BAD_PAGETABLE __bad_pagetable()
 104 #define BAD_PAGE __bad_page()
 105 #define ZERO_PAGE __zero_page()
 106 
 107 /* number of bits that fit into a memory pointer */
 108 #define BITS_PER_PTR                    (8*sizeof(unsigned long))
 109 
 110 /* to align the pointer to a pointer address */
 111 #define PTR_MASK                        (~(sizeof(void*)-1))
 112 
 113 /* sizeof(void*)==1<<SIZEOF_PTR_LOG2 */
 114 /* 64-bit machines, beware!  SRB. */
 115 #define SIZEOF_PTR_LOG2                 2
 116 
 117 /* to find an entry in a page-table */
 118 #define PAGE_PTR(address) \
 119 ((unsigned long)(address)>>(PAGE_SHIFT-SIZEOF_PTR_LOG2)&PTR_MASK&~PAGE_MASK)
 120 
 121 /* to set the page-dir */
 122 #define SET_PAGE_DIR(tsk,pgdir) \
 123 do { \
 124         (tsk)->tss.cr3 = (unsigned long) (pgdir); \
 125         if ((tsk) == current) \
 126                 __asm__ __volatile__("movl %0,%%cr3": :"a" ((tsk)->tss.cr3)); \
 127 } while (0)
 128 
 129 extern unsigned long high_memory;
 130 
 131 extern inline int pte_none(pte_t pte)           { return !pte_val(pte); }
     /* [previous][next][first][last][top][bottom][index][help] */
 132 extern inline int pte_present(pte_t pte)        { return pte_val(pte) & _PAGE_PRESENT; }
     /* [previous][next][first][last][top][bottom][index][help] */
 133 extern inline int pte_inuse(pte_t *ptep)        { return mem_map[MAP_NR(ptep)] > 1; }
     /* [previous][next][first][last][top][bottom][index][help] */
 134 extern inline void pte_clear(pte_t *ptep)       { pte_val(*ptep) = 0; }
     /* [previous][next][first][last][top][bottom][index][help] */
 135 extern inline void pte_reuse(pte_t * ptep)
     /* [previous][next][first][last][top][bottom][index][help] */
 136 {
 137         if (!(mem_map[MAP_NR(ptep)] & MAP_PAGE_RESERVED))
 138                 mem_map[MAP_NR(ptep)]++;
 139 }
 140 
 141 extern inline int pmd_none(pmd_t pmd)           { return !pmd_val(pmd); }
     /* [previous][next][first][last][top][bottom][index][help] */
 142 extern inline int pmd_bad(pmd_t pmd)            { return (pmd_val(pmd) & ~PAGE_MASK) != _PAGE_TABLE || pmd_val(pmd) > high_memory; }
     /* [previous][next][first][last][top][bottom][index][help] */
 143 extern inline int pmd_present(pmd_t pmd)        { return pmd_val(pmd) & _PAGE_PRESENT; }
     /* [previous][next][first][last][top][bottom][index][help] */
 144 extern inline int pmd_inuse(pmd_t *pmdp)        { return 0; }
     /* [previous][next][first][last][top][bottom][index][help] */
 145 extern inline void pmd_clear(pmd_t * pmdp)      { pmd_val(*pmdp) = 0; }
     /* [previous][next][first][last][top][bottom][index][help] */
 146 extern inline void pmd_reuse(pmd_t * pmdp)      { }
     /* [previous][next][first][last][top][bottom][index][help] */
 147 
 148 #ifdef THREE_LEVEL
 149 /*
 150  * The "pgd_xxx()" functions here are trivial for a folded two-level
 151  * setup: the pgd is never bad, and a pmd always exists (as it's folded
 152  * into the pgd entry)
 153  */
 154 extern inline int pgd_none(pgd_t pgd)           { return 0; }
     /* [previous][next][first][last][top][bottom][index][help] */
 155 extern inline int pgd_bad(pgd_t pgd)            { return 0; }
     /* [previous][next][first][last][top][bottom][index][help] */
 156 extern inline int pgd_present(pgd_t pgd)        { return 1; }
     /* [previous][next][first][last][top][bottom][index][help] */
 157 extern inline int pgd_inuse(pgd_t * pgdp)       { return mem_map[MAP_NR(pgdp)] > 1; }
     /* [previous][next][first][last][top][bottom][index][help] */
 158 extern inline void pgd_clear(pgd_t * pgdp)      { }
     /* [previous][next][first][last][top][bottom][index][help] */
 159 extern inline void pgd_reuse(pgd_t * pgdp)
     /* [previous][next][first][last][top][bottom][index][help] */
 160 {
 161         if (!(mem_map[MAP_NR(pgdp)] & MAP_PAGE_RESERVED))
 162                 mem_map[MAP_NR(pgdp)]++;
 163 }
 164 #else
 165 /*
 166  * These are the old (and incorrect) ones needed for code that doesn't
 167  * know about three-level yet..
 168  */
 169 extern inline int pgd_none(pgd_t pgd)           { return !pgd_val(pgd); }
     /* [previous][next][first][last][top][bottom][index][help] */
 170 extern inline int pgd_bad(pgd_t pgd)            { return (pgd_val(pgd) & ~PAGE_MASK) != _PAGE_TABLE || pgd_val(pgd) > high_memory; }
     /* [previous][next][first][last][top][bottom][index][help] */
 171 extern inline int pgd_present(pgd_t pgd)        { return pgd_val(pgd) & _PAGE_PRESENT; }
     /* [previous][next][first][last][top][bottom][index][help] */
 172 extern inline void pgd_clear(pgd_t * pgdp)      { pgd_val(*pgdp) = 0; }
     /* [previous][next][first][last][top][bottom][index][help] */
 173 #endif
 174 
 175 /*
 176  * The following only work if pte_present() is true.
 177  * Undefined behaviour if not..
 178  */
 179 extern inline int pte_read(pte_t pte)           { return pte_val(pte) & _PAGE_USER; }
     /* [previous][next][first][last][top][bottom][index][help] */
 180 extern inline int pte_write(pte_t pte)          { return pte_val(pte) & _PAGE_RW; }
     /* [previous][next][first][last][top][bottom][index][help] */
 181 extern inline int pte_exec(pte_t pte)           { return pte_val(pte) & _PAGE_USER; }
     /* [previous][next][first][last][top][bottom][index][help] */
 182 extern inline int pte_dirty(pte_t pte)          { return pte_val(pte) & _PAGE_DIRTY; }
     /* [previous][next][first][last][top][bottom][index][help] */
 183 extern inline int pte_young(pte_t pte)          { return pte_val(pte) & _PAGE_ACCESSED; }
     /* [previous][next][first][last][top][bottom][index][help] */
 184 extern inline int pte_cow(pte_t pte)            { return pte_val(pte) & _PAGE_COW; }
     /* [previous][next][first][last][top][bottom][index][help] */
 185 
 186 extern inline pte_t pte_wrprotect(pte_t pte)    { pte_val(pte) &= ~_PAGE_RW; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 187 extern inline pte_t pte_rdprotect(pte_t pte)    { pte_val(pte) &= ~_PAGE_USER; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 188 extern inline pte_t pte_exprotect(pte_t pte)    { pte_val(pte) &= ~_PAGE_USER; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 189 extern inline pte_t pte_mkclean(pte_t pte)      { pte_val(pte) &= ~_PAGE_DIRTY; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 190 extern inline pte_t pte_mkold(pte_t pte)        { pte_val(pte) &= ~_PAGE_ACCESSED; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 191 extern inline pte_t pte_uncow(pte_t pte)        { pte_val(pte) &= ~_PAGE_COW; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 192 extern inline pte_t pte_mkwrite(pte_t pte)      { pte_val(pte) |= _PAGE_RW; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 193 extern inline pte_t pte_mkread(pte_t pte)       { pte_val(pte) |= _PAGE_USER; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 194 extern inline pte_t pte_mkexec(pte_t pte)       { pte_val(pte) |= _PAGE_USER; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 195 extern inline pte_t pte_mkdirty(pte_t pte)      { pte_val(pte) |= _PAGE_DIRTY; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 196 extern inline pte_t pte_mkyoung(pte_t pte)      { pte_val(pte) |= _PAGE_ACCESSED; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 197 extern inline pte_t pte_mkcow(pte_t pte)        { pte_val(pte) |= _PAGE_COW; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 198 
 199 /*
 200  * Conversion functions: convert a page and protection to a page entry,
 201  * and a page entry and page directory to the page they refer to.
 202  */
 203 extern inline pte_t mk_pte(unsigned long page, pgprot_t pgprot)
     /* [previous][next][first][last][top][bottom][index][help] */
 204 { pte_t pte; pte_val(pte) = page | pgprot_val(pgprot); return pte; }
 205 
 206 extern inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
     /* [previous][next][first][last][top][bottom][index][help] */
 207 { pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot); return pte; }
 208 
 209 extern inline unsigned long pte_page(pte_t pte)
     /* [previous][next][first][last][top][bottom][index][help] */
 210 { return pte_val(pte) & PAGE_MASK; }
 211 
 212 extern inline unsigned long pmd_page(pmd_t pmd)
     /* [previous][next][first][last][top][bottom][index][help] */
 213 { return pmd_val(pmd) & PAGE_MASK; }
 214 
 215 #ifndef THREE_LEVEL
 216 
 217 extern inline unsigned long pgd_page(pgd_t pgd)
     /* [previous][next][first][last][top][bottom][index][help] */
 218 { return pgd_val(pgd) & PAGE_MASK; }
 219 
 220 extern inline void pgd_set(pgd_t * pgdp, pte_t * ptep)
     /* [previous][next][first][last][top][bottom][index][help] */
 221 { pgd_val(*pgdp) = _PAGE_TABLE | (unsigned long) ptep; }
 222 
 223 #define PAGE_DIR_OFFSET(tsk,address) pgd_offset((tsk),(address))
 224 
 225 /* the no. of pointers that fit on a page: this will go away */
 226 #define PTRS_PER_PAGE   (PAGE_SIZE/sizeof(void*))
 227 
 228 #endif
 229 
 230 /* to find an entry in a page-table-directory */
 231 extern inline pgd_t * pgd_offset(struct task_struct * tsk, unsigned long address)
     /* [previous][next][first][last][top][bottom][index][help] */
 232 {
 233         return (pgd_t *) tsk->tss.cr3 + (address >> PGDIR_SHIFT);
 234 }
 235 
 236 /* Find an entry in the second-level page table.. */
 237 extern inline pmd_t * pmd_offset(pgd_t * dir, unsigned long address)
     /* [previous][next][first][last][top][bottom][index][help] */
 238 {
 239         return (pmd_t *) dir;
 240 }
 241 
 242 /* Find an entry in the third-level page table.. */ 
 243 extern inline pte_t * pte_offset(pmd_t * dir, unsigned long address)
     /* [previous][next][first][last][top][bottom][index][help] */
 244 {
 245         return (pte_t *) pmd_page(*dir) + ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1));
 246 }
 247 
 248 /*
 249  * Allocate and free page tables. The xxx_kernel() versions are
 250  * used to allocate a kernel page table - this turns on ASN bits
 251  * if any, and marks the page tables reserved.
 252  */
 253 extern inline void pte_free_kernel(pte_t * pte)
     /* [previous][next][first][last][top][bottom][index][help] */
 254 {
 255         mem_map[MAP_NR(pte)] = 1;
 256         free_page((unsigned long) pte);
 257 }
 258 
 259 extern inline pte_t * pte_alloc_kernel(pmd_t * pmd, unsigned long address)
     /* [previous][next][first][last][top][bottom][index][help] */
 260 {
 261         address = (address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1);
 262         if (pmd_none(*pmd)) {
 263                 pte_t * page = (pte_t *) get_free_page(GFP_KERNEL);
 264                 if (pmd_none(*pmd)) {
 265                         if (page) {
 266                                 pmd_val(*pmd) = _PAGE_TABLE | (unsigned long) page;
 267                                 mem_map[MAP_NR(page)] = MAP_PAGE_RESERVED;
 268                                 return page + address;
 269                         }
 270                         pmd_val(*pmd) = _PAGE_TABLE | (unsigned long) BAD_PAGETABLE;
 271                         return NULL;
 272                 }
 273                 free_page((unsigned long) page);
 274         }
 275         if (pmd_bad(*pmd)) {
 276                 printk("Bad pmd in pte_alloc: %08lx\n", pmd_val(*pmd));
 277                 pmd_val(*pmd) = _PAGE_TABLE | (unsigned long) BAD_PAGETABLE;
 278                 return NULL;
 279         }
 280         return (pte_t *) pmd_page(*pmd) + address;
 281 }
 282 
 283 /*
 284  * allocating and freeing a pmd is trivial: the 1-entry pmd is
 285  * inside the pgd, so has no extra memory associated with it.
 286  */
 287 extern inline void pmd_free_kernel(pmd_t * pmd)
     /* [previous][next][first][last][top][bottom][index][help] */
 288 {
 289 }
 290 
 291 extern inline pmd_t * pmd_alloc_kernel(pgd_t * pgd, unsigned long address)
     /* [previous][next][first][last][top][bottom][index][help] */
 292 {
 293         return (pmd_t *) pgd;
 294 }
 295 
 296 extern inline void pte_free(pte_t * pte)
     /* [previous][next][first][last][top][bottom][index][help] */
 297 {
 298         free_page((unsigned long) pte);
 299 }
 300 
 301 extern inline pte_t * pte_alloc(pmd_t * pmd, unsigned long address)
     /* [previous][next][first][last][top][bottom][index][help] */
 302 {
 303         address = (address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1);
 304         if (pmd_none(*pmd)) {
 305                 pte_t * page = (pte_t *) get_free_page(GFP_KERNEL);
 306                 if (pmd_none(*pmd)) {
 307                         if (page) {
 308                                 pmd_val(*pmd) = _PAGE_TABLE | (unsigned long) page;
 309                                 return page + address;
 310                         }
 311                         pmd_val(*pmd) = _PAGE_TABLE | (unsigned long) BAD_PAGETABLE;
 312                         return NULL;
 313                 }
 314                 free_page((unsigned long) page);
 315         }
 316         if (pmd_bad(*pmd)) {
 317                 printk("Bad pmd in pte_alloc: %08lx\n", pmd_val(*pmd));
 318                 pmd_val(*pmd) = _PAGE_TABLE | (unsigned long) BAD_PAGETABLE;
 319                 return NULL;
 320         }
 321         return (pte_t *) pmd_page(*pmd) + address;
 322 }
 323 
 324 /*
 325  * allocating and freeing a pmd is trivial: the 1-entry pmd is
 326  * inside the pgd, so has no extra memory associated with it.
 327  */
 328 extern inline void pmd_free(pmd_t * pmd)
     /* [previous][next][first][last][top][bottom][index][help] */
 329 {
 330 }
 331 
 332 extern inline pmd_t * pmd_alloc(pgd_t * pgd, unsigned long address)
     /* [previous][next][first][last][top][bottom][index][help] */
 333 {
 334         return (pmd_t *) pgd;
 335 }
 336 
 337 extern inline void pgd_free(pgd_t * pgd)
     /* [previous][next][first][last][top][bottom][index][help] */
 338 {
 339         free_page((unsigned long) pgd);
 340 }
 341 
 342 extern inline pgd_t * pgd_alloc(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 343 {
 344         return (pgd_t *) get_free_page(GFP_KERNEL);
 345 }
 346 
 347 extern pgd_t swapper_pg_dir[1024];
 348 
 349 #endif /* _I386_PAGE_H */

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