root/include/asm-sparc/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. pte_read
  19. pte_write
  20. pte_exec
  21. pte_dirty
  22. pte_young
  23. pte_cow
  24. pte_wrprotect
  25. pte_rdprotect
  26. pte_exprotect
  27. pte_mkclean
  28. pte_mkold
  29. pte_uncow
  30. pte_mkwrite
  31. pte_mkread
  32. pte_mkexec
  33. pte_mkdirty
  34. pte_mkyoung
  35. pte_mkcow
  36. mk_pte
  37. pte_modify
  38. pte_page
  39. pmd_page
  40. pgd_page
  41. pgd_set
  42. pgd_offset
  43. pmd_offset
  44. pte_offset
  45. pte_free_kernel
  46. pte_alloc_kernel
  47. pmd_free_kernel
  48. pmd_alloc_kernel
  49. pte_free
  50. pte_alloc
  51. pmd_free
  52. pmd_alloc
  53. pgd_free
  54. pgd_alloc

   1 #ifndef _SPARC_PGTABLE_H
   2 #define _SPARC_PGTABLE_H
   3 
   4 /*  asm-sparc/pgtable.h:  Defines and functions used to work
   5  *                        with Sparc page tables.
   6  *
   7  *  Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
   8  */
   9 
  10 /* PMD_SHIFT determines the size of the area a second-level page table can map */
  11 #define PMD_SHIFT       22
  12 #define PMD_SIZE        (1UL << PMD_SHIFT)
  13 #define PMD_MASK        (~(PMD_SIZE-1))
  14 
  15 /* PGDIR_SHIFT determines what a third-level page table entry can map */
  16 #define PGDIR_SHIFT       22
  17 #define PGDIR_SIZE        (1UL << PGDIR_SHIFT)
  18 #define PGDIR_MASK        (~(PGDIR_SIZE-1))
  19 #define PGDIR_ALIGN(addr) (((addr)+PGDIR_SIZE-1)&PGDIR_MASK)
  20 
  21 /*
  22  * Just following the i386 lead, because it works on the Sparc sun4c
  23  * machines.  Two-level, therefore there is no real PMD.
  24  */
  25 
  26 #define PTRS_PER_PTE    1024
  27 #define PTRS_PER_PMD    1
  28 #define PTRS_PER_PGD    1024
  29 
  30 /* the no. of pointers that fit on a page: this will go away */
  31 #define PTRS_PER_PAGE   (PAGE_SIZE/sizeof(void*))
  32 
  33 /* Just any arbitrary offset to the start of the vmalloc VM area: the
  34  * current 8MB value just means that there will be a 8MB "hole" after the
  35  * physical memory until the kernel virtual memory starts.  That means that
  36  * any out-of-bounds memory accesses will hopefully be caught.
  37  * The vmalloc() routines leaves a hole of 4kB between each vmalloced
  38  * area for the same reason. ;)
  39  */
  40 #define VMALLOC_OFFSET  (8*1024*1024)
  41 #define VMALLOC_START ((high_memory + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1))
  42 #define VMALLOC_VMADDR(x) (TASK_SIZE + (unsigned long)(x))
  43 
  44 /*
  45  * Sparc page table fields.
  46  */
  47 
  48 #define _PAGE_VALID     0x80000000   /* valid page */
  49 #define _PAGE_WRITE     0x40000000   /* can be written to */
  50 #define _PAGE_PRIV      0x20000000   /* bit to signify privileged page */
  51 #define _PAGE_REF       0x02000000   /* Page had been accessed/referenced */
  52 #define _PAGE_DIRTY     0x01000000   /* Page has been modified, is dirty */
  53 #define _PAGE_COW       0x00800000   /* COW page, hardware ignores this bit (untested) */
  54 
  55 
  56 /* Sparc sun4c mmu has only a writable bit. Thus if a page is valid it can be
  57  * read in a load, and executed as code automatically. Although, the memory fault
  58  * hardware does make a distinction between date-read faults and insn-read faults
  59  * which is determined by which trap happened plus magic sync/async fault register
  60  * values which must be checked in the actual fault handler.
  61  */
  62 
  63 /* We want the swapper not to swap out page tables, thus dirty and writable
  64  * so that the kernel can change the entries as needed. Also valid for
  65  * obvious reasons.
  66  */
  67 #define _PAGE_TABLE     (_PAGE_VALID | _PAGE_WRITE | _PAGE_DIRTY)
  68 #define _PAGE_CHG_MASK  (PAGE_MASK | _PAGE_REF | _PAGE_DIRTY)
  69 
  70 #define PAGE_NONE       __pgprot(_PAGE_VALID | _PAGE_REF)
  71 #define PAGE_SHARED     __pgprot(_PAGE_VALID | _PAGE_WRITE | _PAGE_REF)
  72 #define PAGE_COPY       __pgprot(_PAGE_VALID | _PAGE_REF | _PAGE_COW)
  73 #define PAGE_READONLY   __pgprot(_PAGE_VALID | _PAGE_REF)
  74 #define PAGE_KERNEL     __pgprot(_PAGE_VALID | _PAGE_PRIV)
  75 
  76 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | _PAGE_REF | (x))
  77 
  78 /* I define these like the i386 does because the check for text or data fault
  79  * is done at trap time by the low level handler. Maybe I can set these bits
  80  * then once determined. I leave them like this for now though.
  81  */
  82 #define __P000  PAGE_NONE
  83 #define __P001  PAGE_READONLY
  84 #define __P010  PAGE_COPY
  85 #define __P011  PAGE_COPY
  86 #define __P100  PAGE_READONLY
  87 #define __P101  PAGE_READONLY
  88 #define __P110  PAGE_COPY
  89 #define __P111  PAGE_COPY
  90 
  91 #define __S000  PAGE_NONE
  92 #define __S001  PAGE_READONLY
  93 #define __S010  PAGE_SHARED
  94 #define __S011  PAGE_SHARED
  95 #define __S100  PAGE_READONLY
  96 #define __S101  PAGE_READONLY
  97 #define __S110  PAGE_SHARED
  98 #define __S111  PAGE_SHARED
  99 
 100 
 101 extern unsigned long pg0[1024];
 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 pte_t * __bad_pagetable(void);
 112 
 113 extern unsigned long __zero_page(void);
 114 
 115 
 116 #define BAD_PAGETABLE __bad_pagetable()
 117 #define BAD_PAGE __bad_page()
 118 #define ZERO_PAGE __zero_page()
 119 
 120 /* number of bits that fit into a memory pointer */
 121 #define BITS_PER_PTR      (8*sizeof(unsigned long))   /* better check this stuff */
 122 
 123 /* to align the pointer to a pointer address */
 124 #define PTR_MASK          (~(sizeof(void*)-1))
 125 
 126 
 127 #define SIZEOF_PTR_LOG2   2
 128 
 129 
 130 /* to set the page-dir
 131  *
 132  * On the Sparc the page segments hold 64 pte's which means 256k/segment.
 133  * Therefore there is no global idea of 'the' page directory, although we
 134  * make a virtual one in kernel memory so that we can keep the stats on
 135  * all the pages since not all can be loaded at once in the mmu.
 136  */
 137 
 138 #define SET_PAGE_DIR(tsk,pgdir)
 139 
 140 /* to find an entry in a page-table */
 141 #define PAGE_PTR(address) \
 142 ((unsigned long)(address)>>(PAGE_SHIFT-SIZEOF_PTR_LOG2)&PTR_MASK&~PAGE_MASK)
 143 
 144 extern unsigned long high_memory;
 145 
 146 extern inline int pte_none(pte_t pte)           { return !pte_val(pte); }
     /* [previous][next][first][last][top][bottom][index][help] */
 147 extern inline int pte_present(pte_t pte)        { return pte_val(pte) & _PAGE_VALID; }
     /* [previous][next][first][last][top][bottom][index][help] */
 148 extern inline int pte_inuse(pte_t *ptep)        { return mem_map[MAP_NR(ptep)] > 1; }
     /* [previous][next][first][last][top][bottom][index][help] */
 149 extern inline void pte_clear(pte_t *ptep)       { pte_val(*ptep) = 0; }
     /* [previous][next][first][last][top][bottom][index][help] */
 150 extern inline void pte_reuse(pte_t *ptep)
     /* [previous][next][first][last][top][bottom][index][help] */
 151 {
 152   if(!(mem_map[MAP_NR(ptep)] & MAP_PAGE_RESERVED))
 153     mem_map[MAP_NR(ptep)]++;
 154 }
 155 
 156 extern inline int pmd_none(pmd_t pmd)           { return !pmd_val(pmd); }
     /* [previous][next][first][last][top][bottom][index][help] */
 157 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] */
 158 extern inline int pmd_present(pmd_t pmd)        { return pmd_val(pmd) & _PAGE_VALID; }
     /* [previous][next][first][last][top][bottom][index][help] */
 159 extern inline int pmd_inuse(pmd_t *pmdp)        { return 0; }
     /* [previous][next][first][last][top][bottom][index][help] */
 160 extern inline void pmd_clear(pmd_t *pmdp)       { pmd_val(*pmdp) = 0; }
     /* [previous][next][first][last][top][bottom][index][help] */
 161 extern inline void pmd_reuse(pmd_t * pmdp)      { }
     /* [previous][next][first][last][top][bottom][index][help] */
 162 
 163 extern inline int pgd_none(pgd_t pgd)           { return !pgd_val(pgd); }
     /* [previous][next][first][last][top][bottom][index][help] */
 164 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] */
 165 extern inline int pgd_present(pgd_t pgd)        { return pgd_val(pgd) & _PAGE_VALID; }
     /* [previous][next][first][last][top][bottom][index][help] */
 166 extern inline int pgd_inuse(pgd_t *pgdp)        { return mem_map[MAP_NR(pgdp)] > 1; }
     /* [previous][next][first][last][top][bottom][index][help] */
 167 extern inline void pgd_clear(pgd_t * pgdp)      { pgd_val(*pgdp) = 0; }
     /* [previous][next][first][last][top][bottom][index][help] */
 168 extern inline void pgd_reuse(pgd_t *pgdp)
     /* [previous][next][first][last][top][bottom][index][help] */
 169 {
 170   if (!(mem_map[MAP_NR(pgdp)] & MAP_PAGE_RESERVED))
 171     mem_map[MAP_NR(pgdp)]++;
 172 }
 173 
 174 /*
 175  * The following only work if pte_present() is true.
 176  * Undefined behaviour if not..
 177  */
 178 extern inline int pte_read(pte_t pte)           { return pte_val(pte) & _PAGE_VALID; }
     /* [previous][next][first][last][top][bottom][index][help] */
 179 extern inline int pte_write(pte_t pte)          { return pte_val(pte) & _PAGE_WRITE; }
     /* [previous][next][first][last][top][bottom][index][help] */
 180 extern inline int pte_exec(pte_t pte)           { return pte_val(pte) & _PAGE_VALID; }
     /* [previous][next][first][last][top][bottom][index][help] */
 181 extern inline int pte_dirty(pte_t pte)          { return pte_val(pte) & _PAGE_REF; }
     /* [previous][next][first][last][top][bottom][index][help] */
 182 extern inline int pte_young(pte_t pte)          { return pte_val(pte) & _PAGE_REF; }
     /* [previous][next][first][last][top][bottom][index][help] */
 183 extern inline int pte_cow(pte_t pte)            { return pte_val(pte) & _PAGE_COW; }
     /* [previous][next][first][last][top][bottom][index][help] */
 184 
 185 extern inline pte_t pte_wrprotect(pte_t pte)    { pte_val(pte) &= ~_PAGE_WRITE; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 186 extern inline pte_t pte_rdprotect(pte_t pte)    { pte_val(pte) &= ~_PAGE_VALID; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 187 extern inline pte_t pte_exprotect(pte_t pte)    { pte_val(pte) &= ~_PAGE_VALID; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 188 extern inline pte_t pte_mkclean(pte_t pte)      { pte_val(pte) &= ~_PAGE_DIRTY; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 189 extern inline pte_t pte_mkold(pte_t pte)        { pte_val(pte) &= ~_PAGE_REF; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 190 extern inline pte_t pte_uncow(pte_t pte)        { pte_val(pte) &= ~_PAGE_COW; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 191 extern inline pte_t pte_mkwrite(pte_t pte)      { pte_val(pte) |= _PAGE_WRITE; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 192 extern inline pte_t pte_mkread(pte_t pte)       { pte_val(pte) |= _PAGE_VALID; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 193 extern inline pte_t pte_mkexec(pte_t pte)       { pte_val(pte) |= _PAGE_VALID; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 194 extern inline pte_t pte_mkdirty(pte_t pte)      { pte_val(pte) |= _PAGE_DIRTY; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 195 extern inline pte_t pte_mkyoung(pte_t pte)      { pte_val(pte) |= _PAGE_REF; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 196 extern inline pte_t pte_mkcow(pte_t pte)        { pte_val(pte) |= _PAGE_COW; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 197 
 198 /*
 199  * Conversion functions: convert a page and protection to a page entry,
 200  * and a page entry and page directory to the page they refer to.
 201  */
 202 extern inline pte_t mk_pte(unsigned long page, pgprot_t pgprot)
     /* [previous][next][first][last][top][bottom][index][help] */
 203 { pte_t pte; pte_val(pte) = page | pgprot_val(pgprot); return pte; }
 204 
 205 extern inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
     /* [previous][next][first][last][top][bottom][index][help] */
 206 { pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot); return pte; }
 207 
 208 extern inline unsigned long pte_page(pte_t pte) { return pte_val(pte) & PAGE_MASK; }
     /* [previous][next][first][last][top][bottom][index][help] */
 209 
 210 extern inline unsigned long pmd_page(pmd_t pmd) { return pmd_val(pmd) & PAGE_MASK; }
     /* [previous][next][first][last][top][bottom][index][help] */
 211 
 212 extern inline unsigned long pgd_page(pgd_t pgd) { return pgd_val(pgd) & PAGE_MASK; }
     /* [previous][next][first][last][top][bottom][index][help] */
 213 
 214 extern inline void pgd_set(pgd_t * pgdp, pte_t * ptep)
     /* [previous][next][first][last][top][bottom][index][help] */
 215 { pgd_val(*pgdp) = _PAGE_TABLE | (unsigned long) ptep; }
 216 
 217 /* to find an entry in a page-table-directory */
 218 #define PAGE_DIR_OFFSET(tsk,address) \
 219 ((((unsigned long)(address)) >> 22) + (pgd_t *) (tsk)->tss.cr3)
 220 
 221 /* to find an entry in a page-table-directory */
 222 extern inline pgd_t * pgd_offset(struct task_struct * tsk, unsigned long address)
     /* [previous][next][first][last][top][bottom][index][help] */
 223 {
 224         return (pgd_t *) tsk->tss.cr3 + (address >> PGDIR_SHIFT);
 225 }
 226 
 227 /* Find an entry in the second-level page table.. */
 228 extern inline pmd_t * pmd_offset(pgd_t * dir, unsigned long address)
     /* [previous][next][first][last][top][bottom][index][help] */
 229 {
 230         return (pmd_t *) dir;
 231 }
 232 
 233 /* Find an entry in the third-level page table.. */ 
 234 extern inline pte_t * pte_offset(pmd_t * dir, unsigned long address)
     /* [previous][next][first][last][top][bottom][index][help] */
 235 {
 236         return (pte_t *) pmd_page(*dir) + ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1));
 237 }
 238 
 239 
 240 /*
 241  * Allocate and free page tables. The xxx_kernel() versions are
 242  * used to allocate a kernel page table - this turns on ASN bits
 243  * if any, and marks the page tables reserved.
 244  */
 245 extern inline void pte_free_kernel(pte_t * pte)
     /* [previous][next][first][last][top][bottom][index][help] */
 246 {
 247         mem_map[MAP_NR(pte)] = 1;
 248         free_page((unsigned long) pte);
 249 }
 250 
 251 extern inline pte_t * pte_alloc_kernel(pmd_t * pmd, unsigned long address)
     /* [previous][next][first][last][top][bottom][index][help] */
 252 {
 253         address = (address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1);
 254         if (pmd_none(*pmd)) {
 255                 pte_t * page = (pte_t *) get_free_page(GFP_KERNEL);
 256                 if (pmd_none(*pmd)) {
 257                         if (page) {
 258                                 pmd_val(*pmd) = _PAGE_TABLE | (unsigned long) page;
 259                                 mem_map[MAP_NR(page)] = MAP_PAGE_RESERVED;
 260                                 return page + address;
 261                         }
 262                         pmd_val(*pmd) = _PAGE_TABLE | (unsigned long) BAD_PAGETABLE;
 263                         return NULL;
 264                 }
 265                 free_page((unsigned long) page);
 266         }
 267         if (pmd_bad(*pmd)) {
 268                 printk("Bad pmd in pte_alloc: %08lx\n", pmd_val(*pmd));
 269                 pmd_val(*pmd) = _PAGE_TABLE | (unsigned long) BAD_PAGETABLE;
 270                 return NULL;
 271         }
 272         return (pte_t *) pmd_page(*pmd) + address;
 273 }
 274 
 275 /*
 276  * allocating and freeing a pmd is trivial: the 1-entry pmd is
 277  * inside the pgd, so has no extra memory associated with it.
 278  */
 279 extern inline void pmd_free_kernel(pmd_t * pmd)
     /* [previous][next][first][last][top][bottom][index][help] */
 280 {
 281 }
 282 
 283 extern inline pmd_t * pmd_alloc_kernel(pgd_t * pgd, unsigned long address)
     /* [previous][next][first][last][top][bottom][index][help] */
 284 {
 285         return (pmd_t *) pgd;
 286 }
 287 
 288 extern inline void pte_free(pte_t * pte)
     /* [previous][next][first][last][top][bottom][index][help] */
 289 {
 290         free_page((unsigned long) pte);
 291 }
 292 
 293 extern inline pte_t * pte_alloc(pmd_t * pmd, unsigned long address)
     /* [previous][next][first][last][top][bottom][index][help] */
 294 {
 295         address = (address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1);
 296         if (pmd_none(*pmd)) {
 297                 pte_t * page = (pte_t *) get_free_page(GFP_KERNEL);
 298                 if (pmd_none(*pmd)) {
 299                         if (page) {
 300                                 pmd_val(*pmd) = _PAGE_TABLE | (unsigned long) page;
 301                                 return page + address;
 302                         }
 303                         pmd_val(*pmd) = _PAGE_TABLE | (unsigned long) BAD_PAGETABLE;
 304                         return NULL;
 305                 }
 306                 free_page((unsigned long) page);
 307         }
 308         if (pmd_bad(*pmd)) {
 309                 printk("Bad pmd in pte_alloc: %08lx\n", pmd_val(*pmd));
 310                 pmd_val(*pmd) = _PAGE_TABLE | (unsigned long) BAD_PAGETABLE;
 311                 return NULL;
 312         }
 313         return (pte_t *) pmd_page(*pmd) + address;
 314 }
 315 
 316 /*
 317  * allocating and freeing a pmd is trivial: the 1-entry pmd is
 318  * inside the pgd, so has no extra memory associated with it.
 319  */
 320 extern inline void pmd_free(pmd_t * pmd)
     /* [previous][next][first][last][top][bottom][index][help] */
 321 {
 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         return (pmd_t *) pgd;
 327 }
 328 
 329 extern inline void pgd_free(pgd_t *pgd)
     /* [previous][next][first][last][top][bottom][index][help] */
 330 {
 331   free_page((unsigned long) pgd);
 332 }
 333 extern inline pgd_t *pgd_alloc(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 334 {
 335   return (pgd_t *) get_free_page(GFP_KERNEL);
 336 }
 337 
 338 extern pgd_t swapper_pg_dir[1024];
 339 
 340 #endif /* !(_SPARC_PGTABLE_H) */

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