pgtable-32.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 <asm/addrspace.h>
  12. #include <asm/page.h>
  13. #include <linux/linkage.h>
  14. #include <asm/cachectl.h>
  15. #include <asm/fixmap.h>
  16. #include <asm-generic/pgtable-nopmd.h>
  17. #ifdef CONFIG_HIGHMEM
  18. #include <asm/highmem.h>
  19. #endif
  20. /*
  21. * Regarding 32-bit MIPS huge page support (and the tradeoff it entails):
  22. *
  23. * We use the same huge page sizes as 64-bit MIPS. Assuming a 4KB page size,
  24. * our 2-level table layout would normally have a PGD entry cover a contiguous
  25. * 4MB virtual address region (pointing to a 4KB PTE page of 1,024 32-bit pte_t
  26. * pointers, each pointing to a 4KB physical page). The problem is that 4MB,
  27. * spanning both halves of a TLB EntryLo0,1 pair, requires 2MB hardware page
  28. * support, not one of the standard supported sizes (1MB,4MB,16MB,...).
  29. * To correct for this, when huge pages are enabled, we halve the number of
  30. * pointers a PTE page holds, making its last half go to waste. Correspondingly,
  31. * we double the number of PGD pages. Overall, page table memory overhead
  32. * increases to match 64-bit MIPS, but PTE lookups remain CPU cache-friendly.
  33. *
  34. * NOTE: We don't yet support huge pages if extended-addressing is enabled
  35. * (i.e. EVA, XPA, 36-bit Alchemy/Netlogic).
  36. */
  37. extern int temp_tlb_entry;
  38. /*
  39. * - add_temporary_entry() add a temporary TLB entry. We use TLB entries
  40. * starting at the top and working down. This is for populating the
  41. * TLB before trap_init() puts the TLB miss handler in place. It
  42. * should be used only for entries matching the actual page tables,
  43. * to prevent inconsistencies.
  44. */
  45. extern int add_temporary_entry(unsigned long entrylo0, unsigned long entrylo1,
  46. unsigned long entryhi, unsigned long pagemask);
  47. /*
  48. * Basically we have the same two-level (which is the logical three level
  49. * Linux page table layout folded) page tables as the i386. Some day
  50. * when we have proper page coloring support we can have a 1% quicker
  51. * tlb refill handling mechanism, but for now it is a bit slower but
  52. * works even with the cache aliasing problem the R4k and above have.
  53. */
  54. /* PGDIR_SHIFT determines what a third-level page table entry can map */
  55. #if defined(CONFIG_MIPS_HUGE_TLB_SUPPORT) && !defined(CONFIG_PHYS_ADDR_T_64BIT)
  56. # define PGDIR_SHIFT (2 * PAGE_SHIFT - PTE_T_LOG2 - 1)
  57. #else
  58. # define PGDIR_SHIFT (2 * PAGE_SHIFT - PTE_T_LOG2)
  59. #endif
  60. #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
  61. #define PGDIR_MASK (~(PGDIR_SIZE-1))
  62. /*
  63. * Entries per page directory level: we use two-level, so
  64. * we don't really have any PUD/PMD directory physically.
  65. */
  66. #if defined(CONFIG_MIPS_HUGE_TLB_SUPPORT) && !defined(CONFIG_PHYS_ADDR_T_64BIT)
  67. # define __PGD_TABLE_ORDER (32 - 3 * PAGE_SHIFT + PGD_T_LOG2 + PTE_T_LOG2 + 1)
  68. #else
  69. # define __PGD_TABLE_ORDER (32 - 3 * PAGE_SHIFT + PGD_T_LOG2 + PTE_T_LOG2)
  70. #endif
  71. #define PGD_TABLE_ORDER (__PGD_TABLE_ORDER >= 0 ? __PGD_TABLE_ORDER : 0)
  72. #define PUD_TABLE_ORDER aieeee_attempt_to_allocate_pud
  73. #define PMD_TABLE_ORDER aieeee_attempt_to_allocate_pmd
  74. #define PTRS_PER_PGD (USER_PTRS_PER_PGD * 2)
  75. #if defined(CONFIG_MIPS_HUGE_TLB_SUPPORT) && !defined(CONFIG_PHYS_ADDR_T_64BIT)
  76. # define PTRS_PER_PTE (PAGE_SIZE / sizeof(pte_t) / 2)
  77. #else
  78. # define PTRS_PER_PTE (PAGE_SIZE / sizeof(pte_t))
  79. #endif
  80. #define USER_PTRS_PER_PGD (0x80000000UL/PGDIR_SIZE)
  81. #define VMALLOC_START MAP_BASE
  82. #define PKMAP_END ((FIXADDR_START) & ~((LAST_PKMAP << PAGE_SHIFT)-1))
  83. #define PKMAP_BASE (PKMAP_END - PAGE_SIZE * LAST_PKMAP)
  84. #ifdef CONFIG_HIGHMEM
  85. # define VMALLOC_END (PKMAP_BASE-2*PAGE_SIZE)
  86. #else
  87. # define VMALLOC_END (FIXADDR_START-2*PAGE_SIZE)
  88. #endif
  89. #ifdef CONFIG_PHYS_ADDR_T_64BIT
  90. #define pte_ERROR(e) \
  91. printk("%s:%d: bad pte %016Lx.\n", __FILE__, __LINE__, pte_val(e))
  92. #else
  93. #define pte_ERROR(e) \
  94. printk("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, pte_val(e))
  95. #endif
  96. #define pgd_ERROR(e) \
  97. printk("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e))
  98. extern void load_pgd(unsigned long pg_dir);
  99. extern pte_t invalid_pte_table[PTRS_PER_PTE];
  100. /*
  101. * Empty pgd/pmd entries point to the invalid_pte_table.
  102. */
  103. static inline int pmd_none(pmd_t pmd)
  104. {
  105. return pmd_val(pmd) == (unsigned long) invalid_pte_table;
  106. }
  107. static inline int pmd_bad(pmd_t pmd)
  108. {
  109. #ifdef CONFIG_MIPS_HUGE_TLB_SUPPORT
  110. /* pmd_huge(pmd) but inline */
  111. if (unlikely(pmd_val(pmd) & _PAGE_HUGE))
  112. return 0;
  113. #endif
  114. if (unlikely(pmd_val(pmd) & ~PAGE_MASK))
  115. return 1;
  116. return 0;
  117. }
  118. static inline int pmd_present(pmd_t pmd)
  119. {
  120. return pmd_val(pmd) != (unsigned long) invalid_pte_table;
  121. }
  122. static inline void pmd_clear(pmd_t *pmdp)
  123. {
  124. pmd_val(*pmdp) = ((unsigned long) invalid_pte_table);
  125. }
  126. #if defined(CONFIG_XPA)
  127. #define MAX_POSSIBLE_PHYSMEM_BITS 40
  128. #define pte_pfn(x) (((unsigned long)((x).pte_high >> _PFN_SHIFT)) | (unsigned long)((x).pte_low << _PAGE_PRESENT_SHIFT))
  129. static inline pte_t
  130. pfn_pte(unsigned long pfn, pgprot_t prot)
  131. {
  132. pte_t pte;
  133. pte.pte_low = (pfn >> _PAGE_PRESENT_SHIFT) |
  134. (pgprot_val(prot) & ~_PFNX_MASK);
  135. pte.pte_high = (pfn << _PFN_SHIFT) |
  136. (pgprot_val(prot) & ~_PFN_MASK);
  137. return pte;
  138. }
  139. #elif defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32)
  140. #define MAX_POSSIBLE_PHYSMEM_BITS 36
  141. #define pte_pfn(x) ((unsigned long)((x).pte_high >> 6))
  142. static inline pte_t pfn_pte(unsigned long pfn, pgprot_t prot)
  143. {
  144. pte_t pte;
  145. pte.pte_high = (pfn << 6) | (pgprot_val(prot) & 0x3f);
  146. pte.pte_low = pgprot_val(prot);
  147. return pte;
  148. }
  149. #else
  150. #define MAX_POSSIBLE_PHYSMEM_BITS 32
  151. #define pte_pfn(x) ((unsigned long)((x).pte >> _PFN_SHIFT))
  152. #define pfn_pte(pfn, prot) __pte(((unsigned long long)(pfn) << _PFN_SHIFT) | pgprot_val(prot))
  153. #define pfn_pmd(pfn, prot) __pmd(((unsigned long long)(pfn) << _PFN_SHIFT) | pgprot_val(prot))
  154. #endif /* defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32) */
  155. #define pte_page(x) pfn_to_page(pte_pfn(x))
  156. #if defined(CONFIG_CPU_R3K_TLB)
  157. /* Swap entries must have VALID bit cleared. */
  158. #define __swp_type(x) (((x).val >> 10) & 0x1f)
  159. #define __swp_offset(x) ((x).val >> 15)
  160. #define __swp_entry(type,offset) ((swp_entry_t) { ((type) << 10) | ((offset) << 15) })
  161. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
  162. #define __swp_entry_to_pte(x) ((pte_t) { (x).val })
  163. #else
  164. #if defined(CONFIG_XPA)
  165. /* Swap entries must have VALID and GLOBAL bits cleared. */
  166. #define __swp_type(x) (((x).val >> 4) & 0x1f)
  167. #define __swp_offset(x) ((x).val >> 9)
  168. #define __swp_entry(type,offset) ((swp_entry_t) { ((type) << 4) | ((offset) << 9) })
  169. #define __pte_to_swp_entry(pte) ((swp_entry_t) { (pte).pte_high })
  170. #define __swp_entry_to_pte(x) ((pte_t) { 0, (x).val })
  171. #elif defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32)
  172. /* Swap entries must have VALID and GLOBAL bits cleared. */
  173. #define __swp_type(x) (((x).val >> 2) & 0x1f)
  174. #define __swp_offset(x) ((x).val >> 7)
  175. #define __swp_entry(type, offset) ((swp_entry_t) { ((type) << 2) | ((offset) << 7) })
  176. #define __pte_to_swp_entry(pte) ((swp_entry_t) { (pte).pte_high })
  177. #define __swp_entry_to_pte(x) ((pte_t) { 0, (x).val })
  178. #else
  179. /*
  180. * Constraints:
  181. * _PAGE_PRESENT at bit 0
  182. * _PAGE_MODIFIED at bit 4
  183. * _PAGE_GLOBAL at bit 6
  184. * _PAGE_VALID at bit 7
  185. */
  186. #define __swp_type(x) (((x).val >> 8) & 0x1f)
  187. #define __swp_offset(x) ((x).val >> 13)
  188. #define __swp_entry(type,offset) ((swp_entry_t) { ((type) << 8) | ((offset) << 13) })
  189. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
  190. #define __swp_entry_to_pte(x) ((pte_t) { (x).val })
  191. #endif /* defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32) */
  192. #endif /* defined(CONFIG_CPU_R3K_TLB) */
  193. #endif /* _ASM_PGTABLE_32_H */