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_clear
  4. pmd_none
  5. pmd_bad
  6. pmd_present
  7. pmd_clear
  8. pgd_none
  9. pgd_bad
  10. pgd_present
  11. pgd_clear
  12. pte_read
  13. pte_write
  14. pte_exec
  15. pte_dirty
  16. pte_young
  17. pte_cow
  18. pte_wrprotect
  19. pte_rdprotect
  20. pte_exprotect
  21. pte_mkclean
  22. pte_mkold
  23. pte_uncow
  24. pte_mkwrite
  25. pte_mkread
  26. pte_mkexec
  27. pte_mkdirty
  28. pte_mkyoung
  29. pte_mkcow
  30. mk_pte
  31. pte_modify
  32. pte_page
  33. pmd_page
  34. pgd_page
  35. pgd_set
  36. pgd_offset
  37. pmd_offset
  38. pte_offset
  39. pte_free_kernel
  40. pte_alloc_kernel
  41. pmd_free_kernel
  42. pmd_alloc_kernel
  43. pte_free
  44. pte_alloc
  45. pmd_free
  46. pmd_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 void pte_clear(pte_t *ptep)       { pte_val(*ptep) = 0; }
     /* [previous][next][first][last][top][bottom][index][help] */
 149 
 150 extern inline int pmd_none(pmd_t pmd)           { return !pmd_val(pmd); }
     /* [previous][next][first][last][top][bottom][index][help] */
 151 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] */
 152 extern inline int pmd_present(pmd_t pmd)        { return pmd_val(pmd) & _PAGE_VALID; }
     /* [previous][next][first][last][top][bottom][index][help] */
 153 extern inline void pmd_clear(pmd_t * pmdp)      { pmd_val(*pmdp) = 0; }
     /* [previous][next][first][last][top][bottom][index][help] */
 154 
 155 extern inline int pgd_none(pgd_t pgd)           { return !pgd_val(pgd); }
     /* [previous][next][first][last][top][bottom][index][help] */
 156 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] */
 157 extern inline int pgd_present(pgd_t pgd)        { return pgd_val(pgd) & _PAGE_VALID; }
     /* [previous][next][first][last][top][bottom][index][help] */
 158 extern inline void pgd_clear(pgd_t * pgdp)      { pgd_val(*pgdp) = 0; }
     /* [previous][next][first][last][top][bottom][index][help] */
 159 
 160 /*
 161  * The following only work if pte_present() is true.
 162  * Undefined behaviour if not..
 163  */
 164 extern inline int pte_read(pte_t pte)           { return pte_val(pte) & _PAGE_VALID; }
     /* [previous][next][first][last][top][bottom][index][help] */
 165 extern inline int pte_write(pte_t pte)          { return pte_val(pte) & _PAGE_WRITE; }
     /* [previous][next][first][last][top][bottom][index][help] */
 166 extern inline int pte_exec(pte_t pte)           { return pte_val(pte) & _PAGE_VALID; }
     /* [previous][next][first][last][top][bottom][index][help] */
 167 extern inline int pte_dirty(pte_t pte)          { return pte_val(pte) & _PAGE_REF; }
     /* [previous][next][first][last][top][bottom][index][help] */
 168 extern inline int pte_young(pte_t pte)          { return pte_val(pte) & _PAGE_REF; }
     /* [previous][next][first][last][top][bottom][index][help] */
 169 extern inline int pte_cow(pte_t pte)            { return pte_val(pte) & _PAGE_COW; }
     /* [previous][next][first][last][top][bottom][index][help] */
 170 
 171 extern inline pte_t pte_wrprotect(pte_t pte)    { pte_val(pte) &= ~_PAGE_WRITE; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 172 extern inline pte_t pte_rdprotect(pte_t pte)    { pte_val(pte) &= ~_PAGE_VALID; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 173 extern inline pte_t pte_exprotect(pte_t pte)    { pte_val(pte) &= ~_PAGE_VALID; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 174 extern inline pte_t pte_mkclean(pte_t pte)      { pte_val(pte) &= ~_PAGE_DIRTY; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 175 extern inline pte_t pte_mkold(pte_t pte)        { pte_val(pte) &= ~_PAGE_REF; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 176 extern inline pte_t pte_uncow(pte_t pte)        { pte_val(pte) &= ~_PAGE_COW; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 177 extern inline pte_t pte_mkwrite(pte_t pte)      { pte_val(pte) |= _PAGE_WRITE; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 178 extern inline pte_t pte_mkread(pte_t pte)       { pte_val(pte) |= _PAGE_VALID; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 179 extern inline pte_t pte_mkexec(pte_t pte)       { pte_val(pte) |= _PAGE_VALID; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 180 extern inline pte_t pte_mkdirty(pte_t pte)      { pte_val(pte) |= _PAGE_DIRTY; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 181 extern inline pte_t pte_mkyoung(pte_t pte)      { pte_val(pte) |= _PAGE_REF; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 182 extern inline pte_t pte_mkcow(pte_t pte)        { pte_val(pte) |= _PAGE_COW; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 183 
 184 /*
 185  * Conversion functions: convert a page and protection to a page entry,
 186  * and a page entry and page directory to the page they refer to.
 187  */
 188 extern inline pte_t mk_pte(unsigned long page, pgprot_t pgprot)
     /* [previous][next][first][last][top][bottom][index][help] */
 189 { pte_t pte; pte_val(pte) = page | pgprot_val(pgprot); return pte; }
 190 
 191 extern inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
     /* [previous][next][first][last][top][bottom][index][help] */
 192 { pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot); return pte; }
 193 
 194 extern inline unsigned long pte_page(pte_t pte) { return pte_val(pte) & PAGE_MASK; }
     /* [previous][next][first][last][top][bottom][index][help] */
 195 
 196 extern inline unsigned long pmd_page(pmd_t pmd) { return pmd_val(pmd) & PAGE_MASK; }
     /* [previous][next][first][last][top][bottom][index][help] */
 197 
 198 extern inline unsigned long pgd_page(pgd_t pgd) { return pgd_val(pgd) & PAGE_MASK; }
     /* [previous][next][first][last][top][bottom][index][help] */
 199 
 200 extern inline void pgd_set(pgd_t * pgdp, pte_t * ptep)
     /* [previous][next][first][last][top][bottom][index][help] */
 201 { pgd_val(*pgdp) = _PAGE_TABLE | (unsigned long) ptep; }
 202 
 203 /* to find an entry in a page-table-directory */
 204 #define PAGE_DIR_OFFSET(tsk,address) \
 205 ((((unsigned long)(address)) >> 22) + (pgd_t *) (tsk)->tss.cr3)
 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.cr3 + (address >> PGDIR_SHIFT);
 211 }
 212 
 213 /* Find an entry in the second-level page table.. */
 214 extern inline pmd_t * pmd_offset(pgd_t * dir, unsigned long address)
     /* [previous][next][first][last][top][bottom][index][help] */
 215 {
 216         return (pmd_t *) dir;
 217 }
 218 
 219 /* Find an entry in the third-level page table.. */ 
 220 extern inline pte_t * pte_offset(pmd_t * dir, unsigned long address)
     /* [previous][next][first][last][top][bottom][index][help] */
 221 {
 222         return (pte_t *) pmd_page(*dir) + ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1));
 223 }
 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_val(*pmd) = _PAGE_TABLE | (unsigned long) page;
 245                                 mem_map[MAP_NR(page)] = MAP_PAGE_RESERVED;
 246                                 return page + address;
 247                         }
 248                         pmd_val(*pmd) = _PAGE_TABLE | (unsigned long) 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_val(*pmd) = _PAGE_TABLE | (unsigned long) BAD_PAGETABLE;
 256                 return NULL;
 257         }
 258         return (pte_t *) pmd_page(*pmd) + address;
 259 }
 260 
 261 /*
 262  * allocating and freeing a pmd is trivial: the 1-entry pmd is
 263  * inside the pgd, so has no extra memory associated with it.
 264  */
 265 extern inline void pmd_free_kernel(pmd_t * pmd)
     /* [previous][next][first][last][top][bottom][index][help] */
 266 {
 267 }
 268 
 269 extern inline pmd_t * pmd_alloc_kernel(pgd_t * pgd, unsigned long address)
     /* [previous][next][first][last][top][bottom][index][help] */
 270 {
 271         return (pmd_t *) pgd;
 272 }
 273 
 274 extern inline void pte_free(pte_t * pte)
     /* [previous][next][first][last][top][bottom][index][help] */
 275 {
 276         free_page((unsigned long) pte);
 277 }
 278 
 279 extern inline pte_t * pte_alloc(pmd_t * pmd, unsigned long address)
     /* [previous][next][first][last][top][bottom][index][help] */
 280 {
 281         address = (address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1);
 282         if (pmd_none(*pmd)) {
 283                 pte_t * page = (pte_t *) get_free_page(GFP_KERNEL);
 284                 if (pmd_none(*pmd)) {
 285                         if (page) {
 286                                 pmd_val(*pmd) = _PAGE_TABLE | (unsigned long) page;
 287                                 return page + address;
 288                         }
 289                         pmd_val(*pmd) = _PAGE_TABLE | (unsigned long) BAD_PAGETABLE;
 290                         return NULL;
 291                 }
 292                 free_page((unsigned long) page);
 293         }
 294         if (pmd_bad(*pmd)) {
 295                 printk("Bad pmd in pte_alloc: %08lx\n", pmd_val(*pmd));
 296                 pmd_val(*pmd) = _PAGE_TABLE | (unsigned long) BAD_PAGETABLE;
 297                 return NULL;
 298         }
 299         return (pte_t *) pmd_page(*pmd) + address;
 300 }
 301 
 302 /*
 303  * allocating and freeing a pmd is trivial: the 1-entry pmd is
 304  * inside the pgd, so has no extra memory associated with it.
 305  */
 306 extern inline void pmd_free(pmd_t * pmd)
     /* [previous][next][first][last][top][bottom][index][help] */
 307 {
 308 }
 309 
 310 extern inline pmd_t * pmd_alloc(pgd_t * pgd, unsigned long address)
     /* [previous][next][first][last][top][bottom][index][help] */
 311 {
 312         return (pmd_t *) pgd;
 313 }
 314 
 315 extern pgd_t swapper_pg_dir[1024];
 316 
 317 #endif /* !(_SPARC_PGTABLE_H) */

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