2323#include <asm/highmem.h>
2424#endif
2525
26+ /*
27+ * Regarding 32-bit MIPS huge page support (and the tradeoff it entails):
28+ *
29+ * We use the same huge page sizes as 64-bit MIPS. Assuming a 4KB page size,
30+ * our 2-level table layout would normally have a PGD entry cover a contiguous
31+ * 4MB virtual address region (pointing to a 4KB PTE page of 1,024 32-bit pte_t
32+ * pointers, each pointing to a 4KB physical page). The problem is that 4MB,
33+ * spanning both halves of a TLB EntryLo0,1 pair, requires 2MB hardware page
34+ * support, not one of the standard supported sizes (1MB,4MB,16MB,...).
35+ * To correct for this, when huge pages are enabled, we halve the number of
36+ * pointers a PTE page holds, making its last half go to waste. Correspondingly,
37+ * we double the number of PGD pages. Overall, page table memory overhead
38+ * increases to match 64-bit MIPS, but PTE lookups remain CPU cache-friendly.
39+ *
40+ * NOTE: We don't yet support huge pages if extended-addressing is enabled
41+ * (i.e. EVA, XPA, 36-bit Alchemy/Netlogic).
42+ */
43+
2644extern int temp_tlb_entry ;
2745
2846/*
@@ -44,22 +62,36 @@ extern int add_temporary_entry(unsigned long entrylo0, unsigned long entrylo1,
4462 */
4563
4664/* PGDIR_SHIFT determines what a third-level page table entry can map */
47- #define PGDIR_SHIFT (2 * PAGE_SHIFT + PTE_ORDER - PTE_T_LOG2)
65+ #if defined(CONFIG_MIPS_HUGE_TLB_SUPPORT ) && !defined(CONFIG_PHYS_ADDR_T_64BIT )
66+ # define PGDIR_SHIFT (2 * PAGE_SHIFT + PTE_ORDER - PTE_T_LOG2 - 1)
67+ #else
68+ # define PGDIR_SHIFT (2 * PAGE_SHIFT + PTE_ORDER - PTE_T_LOG2)
69+ #endif
70+
4871#define PGDIR_SIZE (1UL << PGDIR_SHIFT)
4972#define PGDIR_MASK (~(PGDIR_SIZE-1))
5073
5174/*
5275 * Entries per page directory level: we use two-level, so
5376 * we don't really have any PUD/PMD directory physically.
5477 */
55- #define __PGD_ORDER (32 - 3 * PAGE_SHIFT + PGD_T_LOG2 + PTE_T_LOG2)
78+ #if defined(CONFIG_MIPS_HUGE_TLB_SUPPORT ) && !defined(CONFIG_PHYS_ADDR_T_64BIT )
79+ # define __PGD_ORDER (32 - 3 * PAGE_SHIFT + PGD_T_LOG2 + PTE_T_LOG2 + 1)
80+ #else
81+ # define __PGD_ORDER (32 - 3 * PAGE_SHIFT + PGD_T_LOG2 + PTE_T_LOG2)
82+ #endif
83+
5684#define PGD_ORDER (__PGD_ORDER >= 0 ? __PGD_ORDER : 0)
5785#define PUD_ORDER aieeee_attempt_to_allocate_pud
5886#define PMD_ORDER 1
5987#define PTE_ORDER 0
6088
6189#define PTRS_PER_PGD (USER_PTRS_PER_PGD * 2)
62- #define PTRS_PER_PTE ((PAGE_SIZE << PTE_ORDER) / sizeof(pte_t))
90+ #if defined(CONFIG_MIPS_HUGE_TLB_SUPPORT ) && !defined(CONFIG_PHYS_ADDR_T_64BIT )
91+ # define PTRS_PER_PTE ((PAGE_SIZE << PTE_ORDER) / sizeof(pte_t) / 2)
92+ #else
93+ # define PTRS_PER_PTE ((PAGE_SIZE << PTE_ORDER) / sizeof(pte_t))
94+ #endif
6395
6496#define USER_PTRS_PER_PGD (0x80000000UL/PGDIR_SIZE)
6597#define FIRST_USER_ADDRESS 0UL
@@ -87,7 +119,7 @@ extern int add_temporary_entry(unsigned long entrylo0, unsigned long entrylo1,
87119
88120extern void load_pgd (unsigned long pg_dir );
89121
90- extern pte_t invalid_pte_table [PAGE_SIZE / sizeof ( pte_t ) ];
122+ extern pte_t invalid_pte_table [PTRS_PER_PTE ];
91123
92124/*
93125 * Empty pgd/pmd entries point to the invalid_pte_table.
@@ -97,7 +129,19 @@ static inline int pmd_none(pmd_t pmd)
97129 return pmd_val (pmd ) == (unsigned long ) invalid_pte_table ;
98130}
99131
100- #define pmd_bad (pmd ) (pmd_val(pmd) & ~PAGE_MASK)
132+ static inline int pmd_bad (pmd_t pmd )
133+ {
134+ #ifdef CONFIG_MIPS_HUGE_TLB_SUPPORT
135+ /* pmd_huge(pmd) but inline */
136+ if (unlikely (pmd_val (pmd ) & _PAGE_HUGE ))
137+ return 0 ;
138+ #endif
139+
140+ if (unlikely (pmd_val (pmd ) & ~PAGE_MASK ))
141+ return 1 ;
142+
143+ return 0 ;
144+ }
101145
102146static inline int pmd_present (pmd_t pmd )
103147{
@@ -146,6 +190,7 @@ static inline pte_t pfn_pte(unsigned long pfn, pgprot_t prot)
146190#else
147191#define pte_pfn (x ) ((unsigned long)((x).pte >> _PFN_SHIFT))
148192#define pfn_pte (pfn , prot ) __pte(((unsigned long long)(pfn) << _PFN_SHIFT) | pgprot_val(prot))
193+ #define pfn_pmd (pfn , prot ) __pmd(((unsigned long long)(pfn) << _PFN_SHIFT) | pgprot_val(prot))
149194#endif
150195#endif /* defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32) */
151196
@@ -159,6 +204,7 @@ static inline pte_t pfn_pte(unsigned long pfn, pgprot_t prot)
159204#define pgd_offset_k (address ) pgd_offset(&init_mm, address)
160205
161206#define pgd_index (address ) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
207+ #define pmd_index (address ) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))
162208
163209/* to find an entry in a page-table-directory */
164210#define pgd_offset (mm , addr ) ((mm)->pgd + pgd_index(addr))
0 commit comments