pgtable-32.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1994, 95, 96, 97, 98, 99, 2000, 2003 Ralf Baechle
  7. * Copyright (C) 1999, 2000, 2001 Silicon Graphics, Inc.
  8. */
  9. #ifndef _ASM_PGTABLE_32_H
  10. #define _ASM_PGTABLE_32_H
  11. #include <linux/config.h>
  12. #include <asm/addrspace.h>
  13. #include <asm/page.h>
  14. #include <linux/linkage.h>
  15. #include <asm/cachectl.h>
  16. #include <asm/fixmap.h>
  17. /*
  18. * - add_wired_entry() add a fixed TLB entry, and move wired register
  19. */
  20. extern void add_wired_entry(unsigned long entrylo0, unsigned long entrylo1,
  21. unsigned long entryhi, unsigned long pagemask);
  22. /*
  23. * - add_temporary_entry() add a temporary TLB entry. We use TLB entries
  24. * starting at the top and working down. This is for populating the
  25. * TLB before trap_init() puts the TLB miss handler in place. It
  26. * should be used only for entries matching the actual page tables,
  27. * to prevent inconsistencies.
  28. */
  29. extern int add_temporary_entry(unsigned long entrylo0, unsigned long entrylo1,
  30. unsigned long entryhi, unsigned long pagemask);
  31. /* Basically we have the same two-level (which is the logical three level
  32. * Linux page table layout folded) page tables as the i386. Some day
  33. * when we have proper page coloring support we can have a 1% quicker
  34. * tlb refill handling mechanism, but for now it is a bit slower but
  35. * works even with the cache aliasing problem the R4k and above have.
  36. */
  37. /* PMD_SHIFT determines the size of the area a second-level page table can map */
  38. #ifdef CONFIG_64BIT_PHYS_ADDR
  39. #define PMD_SHIFT 21
  40. #else
  41. #define PMD_SHIFT 22
  42. #endif
  43. #define PMD_SIZE (1UL << PMD_SHIFT)
  44. #define PMD_MASK (~(PMD_SIZE-1))
  45. /* PGDIR_SHIFT determines what a third-level page table entry can map */
  46. #define PGDIR_SHIFT PMD_SHIFT
  47. #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
  48. #define PGDIR_MASK (~(PGDIR_SIZE-1))
  49. /*
  50. * Entries per page directory level: we use two-level, so
  51. * we don't really have any PMD directory physically.
  52. */
  53. #ifdef CONFIG_64BIT_PHYS_ADDR
  54. #define PGD_ORDER 1
  55. #define PMD_ORDER 0
  56. #define PTE_ORDER 0
  57. #else
  58. #define PGD_ORDER 0
  59. #define PMD_ORDER 0
  60. #define PTE_ORDER 0
  61. #endif
  62. #define PTRS_PER_PGD ((PAGE_SIZE << PGD_ORDER) / sizeof(pgd_t))
  63. #define PTRS_PER_PMD 1
  64. #define PTRS_PER_PTE ((PAGE_SIZE << PTE_ORDER) / sizeof(pte_t))
  65. #define USER_PTRS_PER_PGD (0x80000000UL/PGDIR_SIZE)
  66. #define FIRST_USER_ADDRESS 0
  67. #define VMALLOC_START KSEG2
  68. #ifdef CONFIG_HIGHMEM
  69. # define VMALLOC_END (PKMAP_BASE-2*PAGE_SIZE)
  70. #else
  71. # define VMALLOC_END (FIXADDR_START-2*PAGE_SIZE)
  72. #endif
  73. #ifdef CONFIG_64BIT_PHYS_ADDR
  74. #define pte_ERROR(e) \
  75. printk("%s:%d: bad pte %016Lx.\n", __FILE__, __LINE__, pte_val(e))
  76. #else
  77. #define pte_ERROR(e) \
  78. printk("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, pte_val(e))
  79. #endif
  80. #define pmd_ERROR(e) \
  81. printk("%s:%d: bad pmd %08lx.\n", __FILE__, __LINE__, pmd_val(e))
  82. #define pgd_ERROR(e) \
  83. printk("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e))
  84. extern void load_pgd(unsigned long pg_dir);
  85. extern pte_t invalid_pte_table[PAGE_SIZE/sizeof(pte_t)];
  86. /*
  87. * Empty pgd/pmd entries point to the invalid_pte_table.
  88. */
  89. static inline int pmd_none(pmd_t pmd)
  90. {
  91. return pmd_val(pmd) == (unsigned long) invalid_pte_table;
  92. }
  93. #define pmd_bad(pmd) (pmd_val(pmd) & ~PAGE_MASK)
  94. static inline int pmd_present(pmd_t pmd)
  95. {
  96. return pmd_val(pmd) != (unsigned long) invalid_pte_table;
  97. }
  98. static inline void pmd_clear(pmd_t *pmdp)
  99. {
  100. pmd_val(*pmdp) = ((unsigned long) invalid_pte_table);
  101. }
  102. /*
  103. * The "pgd_xxx()" functions here are trivial for a folded two-level
  104. * setup: the pgd is never bad, and a pmd always exists (as it's folded
  105. * into the pgd entry)
  106. */
  107. static inline int pgd_none(pgd_t pgd) { return 0; }
  108. static inline int pgd_bad(pgd_t pgd) { return 0; }
  109. static inline int pgd_present(pgd_t pgd) { return 1; }
  110. static inline void pgd_clear(pgd_t *pgdp) { }
  111. #if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32)
  112. #define pte_page(x) pfn_to_page(pte_pfn(x))
  113. #define pte_pfn(x) ((unsigned long)((x).pte_high >> 6))
  114. static inline pte_t
  115. pfn_pte(unsigned long pfn, pgprot_t prot)
  116. {
  117. pte_t pte;
  118. pte.pte_high = (pfn << 6) | (pgprot_val(prot) & 0x3f);
  119. pte.pte_low = pgprot_val(prot);
  120. return pte;
  121. }
  122. #else
  123. #define pte_page(x) pfn_to_page(pte_pfn(x))
  124. #ifdef CONFIG_CPU_VR41XX
  125. #define pte_pfn(x) ((unsigned long)((x).pte >> (PAGE_SHIFT + 2)))
  126. #define pfn_pte(pfn, prot) __pte(((pfn) << (PAGE_SHIFT + 2)) | pgprot_val(prot))
  127. #else
  128. #define pte_pfn(x) ((unsigned long)((x).pte >> PAGE_SHIFT))
  129. #define pfn_pte(pfn, prot) __pte(((pfn) << PAGE_SHIFT) | pgprot_val(prot))
  130. #endif
  131. #endif /* defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32) */
  132. #define __pgd_offset(address) pgd_index(address)
  133. #define __pmd_offset(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))
  134. /* to find an entry in a kernel page-table-directory */
  135. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  136. #define pgd_index(address) ((address) >> PGDIR_SHIFT)
  137. /* to find an entry in a page-table-directory */
  138. #define pgd_offset(mm,addr) ((mm)->pgd + pgd_index(addr))
  139. /* Find an entry in the second-level page table.. */
  140. static inline pmd_t *pmd_offset(pgd_t *dir, unsigned long address)
  141. {
  142. return (pmd_t *) dir;
  143. }
  144. /* Find an entry in the third-level page table.. */
  145. #define __pte_offset(address) \
  146. (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
  147. #define pte_offset(dir, address) \
  148. ((pte_t *) (pmd_page_kernel(*dir)) + __pte_offset(address))
  149. #define pte_offset_kernel(dir, address) \
  150. ((pte_t *) pmd_page_kernel(*(dir)) + __pte_offset(address))
  151. #define pte_offset_map(dir, address) \
  152. ((pte_t *)page_address(pmd_page(*(dir))) + __pte_offset(address))
  153. #define pte_offset_map_nested(dir, address) \
  154. ((pte_t *)page_address(pmd_page(*(dir))) + __pte_offset(address))
  155. #define pte_unmap(pte) ((void)(pte))
  156. #define pte_unmap_nested(pte) ((void)(pte))
  157. #if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
  158. /* Swap entries must have VALID bit cleared. */
  159. #define __swp_type(x) (((x).val >> 10) & 0x1f)
  160. #define __swp_offset(x) ((x).val >> 15)
  161. #define __swp_entry(type,offset) \
  162. ((swp_entry_t) { ((type) << 10) | ((offset) << 15) })
  163. /*
  164. * Bits 0, 1, 2, 9 and 10 are taken, split up the 27 bits of offset
  165. * into this range:
  166. */
  167. #define PTE_FILE_MAX_BITS 27
  168. #define pte_to_pgoff(_pte) \
  169. ((((_pte).pte >> 3) & 0x3f ) + (((_pte).pte >> 11) << 8 ))
  170. #define pgoff_to_pte(off) \
  171. ((pte_t) { (((off) & 0x3f) << 3) + (((off) >> 8) << 11) + _PAGE_FILE })
  172. #else
  173. /* Swap entries must have VALID and GLOBAL bits cleared. */
  174. #define __swp_type(x) (((x).val >> 8) & 0x1f)
  175. #define __swp_offset(x) ((x).val >> 13)
  176. #define __swp_entry(type,offset) \
  177. ((swp_entry_t) { ((type) << 8) | ((offset) << 13) })
  178. /*
  179. * Bits 0, 1, 2, 7 and 8 are taken, split up the 27 bits of offset
  180. * into this range:
  181. */
  182. #define PTE_FILE_MAX_BITS 27
  183. #if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32)
  184. /* fixme */
  185. #define pte_to_pgoff(_pte) (((_pte).pte_high >> 6) + ((_pte).pte_high & 0x3f))
  186. #define pgoff_to_pte(off) \
  187. ((pte_t){(((off) & 0x3f) + ((off) << 6) + _PAGE_FILE)})
  188. #else
  189. #define pte_to_pgoff(_pte) \
  190. ((((_pte).pte >> 3) & 0x1f ) + (((_pte).pte >> 9) << 6 ))
  191. #define pgoff_to_pte(off) \
  192. ((pte_t) { (((off) & 0x1f) << 3) + (((off) >> 6) << 9) + _PAGE_FILE })
  193. #endif
  194. #endif
  195. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
  196. #define __swp_entry_to_pte(x) ((pte_t) { (x).val })
  197. #endif /* _ASM_PGTABLE_32_H */