18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public 38c2ecf20Sopenharmony_ci * License. See the file "COPYING" in the main directory of this archive 48c2ecf20Sopenharmony_ci * for more details. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Copyright (C) 1994, 95, 96, 97, 98, 99, 2000, 2003 Ralf Baechle 78c2ecf20Sopenharmony_ci * Copyright (C) 1999, 2000, 2001 Silicon Graphics, Inc. 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci#ifndef _ASM_PGTABLE_32_H 108c2ecf20Sopenharmony_ci#define _ASM_PGTABLE_32_H 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <asm/addrspace.h> 138c2ecf20Sopenharmony_ci#include <asm/page.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include <linux/linkage.h> 168c2ecf20Sopenharmony_ci#include <asm/cachectl.h> 178c2ecf20Sopenharmony_ci#include <asm/fixmap.h> 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#include <asm-generic/pgtable-nopmd.h> 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#ifdef CONFIG_HIGHMEM 228c2ecf20Sopenharmony_ci#include <asm/highmem.h> 238c2ecf20Sopenharmony_ci#endif 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci/* 268c2ecf20Sopenharmony_ci * Regarding 32-bit MIPS huge page support (and the tradeoff it entails): 278c2ecf20Sopenharmony_ci * 288c2ecf20Sopenharmony_ci * We use the same huge page sizes as 64-bit MIPS. Assuming a 4KB page size, 298c2ecf20Sopenharmony_ci * our 2-level table layout would normally have a PGD entry cover a contiguous 308c2ecf20Sopenharmony_ci * 4MB virtual address region (pointing to a 4KB PTE page of 1,024 32-bit pte_t 318c2ecf20Sopenharmony_ci * pointers, each pointing to a 4KB physical page). The problem is that 4MB, 328c2ecf20Sopenharmony_ci * spanning both halves of a TLB EntryLo0,1 pair, requires 2MB hardware page 338c2ecf20Sopenharmony_ci * support, not one of the standard supported sizes (1MB,4MB,16MB,...). 348c2ecf20Sopenharmony_ci * To correct for this, when huge pages are enabled, we halve the number of 358c2ecf20Sopenharmony_ci * pointers a PTE page holds, making its last half go to waste. Correspondingly, 368c2ecf20Sopenharmony_ci * we double the number of PGD pages. Overall, page table memory overhead 378c2ecf20Sopenharmony_ci * increases to match 64-bit MIPS, but PTE lookups remain CPU cache-friendly. 388c2ecf20Sopenharmony_ci * 398c2ecf20Sopenharmony_ci * NOTE: We don't yet support huge pages if extended-addressing is enabled 408c2ecf20Sopenharmony_ci * (i.e. EVA, XPA, 36-bit Alchemy/Netlogic). 418c2ecf20Sopenharmony_ci */ 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ciextern int temp_tlb_entry; 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci/* 468c2ecf20Sopenharmony_ci * - add_temporary_entry() add a temporary TLB entry. We use TLB entries 478c2ecf20Sopenharmony_ci * starting at the top and working down. This is for populating the 488c2ecf20Sopenharmony_ci * TLB before trap_init() puts the TLB miss handler in place. It 498c2ecf20Sopenharmony_ci * should be used only for entries matching the actual page tables, 508c2ecf20Sopenharmony_ci * to prevent inconsistencies. 518c2ecf20Sopenharmony_ci */ 528c2ecf20Sopenharmony_ciextern int add_temporary_entry(unsigned long entrylo0, unsigned long entrylo1, 538c2ecf20Sopenharmony_ci unsigned long entryhi, unsigned long pagemask); 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci/* 568c2ecf20Sopenharmony_ci * Basically we have the same two-level (which is the logical three level 578c2ecf20Sopenharmony_ci * Linux page table layout folded) page tables as the i386. Some day 588c2ecf20Sopenharmony_ci * when we have proper page coloring support we can have a 1% quicker 598c2ecf20Sopenharmony_ci * tlb refill handling mechanism, but for now it is a bit slower but 608c2ecf20Sopenharmony_ci * works even with the cache aliasing problem the R4k and above have. 618c2ecf20Sopenharmony_ci */ 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci/* PGDIR_SHIFT determines what a third-level page table entry can map */ 648c2ecf20Sopenharmony_ci#if defined(CONFIG_MIPS_HUGE_TLB_SUPPORT) && !defined(CONFIG_PHYS_ADDR_T_64BIT) 658c2ecf20Sopenharmony_ci# define PGDIR_SHIFT (2 * PAGE_SHIFT + PTE_ORDER - PTE_T_LOG2 - 1) 668c2ecf20Sopenharmony_ci#else 678c2ecf20Sopenharmony_ci# define PGDIR_SHIFT (2 * PAGE_SHIFT + PTE_ORDER - PTE_T_LOG2) 688c2ecf20Sopenharmony_ci#endif 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci#define PGDIR_SIZE (1UL << PGDIR_SHIFT) 718c2ecf20Sopenharmony_ci#define PGDIR_MASK (~(PGDIR_SIZE-1)) 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci/* 748c2ecf20Sopenharmony_ci * Entries per page directory level: we use two-level, so 758c2ecf20Sopenharmony_ci * we don't really have any PUD/PMD directory physically. 768c2ecf20Sopenharmony_ci */ 778c2ecf20Sopenharmony_ci#if defined(CONFIG_MIPS_HUGE_TLB_SUPPORT) && !defined(CONFIG_PHYS_ADDR_T_64BIT) 788c2ecf20Sopenharmony_ci# define __PGD_ORDER (32 - 3 * PAGE_SHIFT + PGD_T_LOG2 + PTE_T_LOG2 + 1) 798c2ecf20Sopenharmony_ci#else 808c2ecf20Sopenharmony_ci# define __PGD_ORDER (32 - 3 * PAGE_SHIFT + PGD_T_LOG2 + PTE_T_LOG2) 818c2ecf20Sopenharmony_ci#endif 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci#define PGD_ORDER (__PGD_ORDER >= 0 ? __PGD_ORDER : 0) 848c2ecf20Sopenharmony_ci#define PUD_ORDER aieeee_attempt_to_allocate_pud 858c2ecf20Sopenharmony_ci#define PMD_ORDER aieeee_attempt_to_allocate_pmd 868c2ecf20Sopenharmony_ci#define PTE_ORDER 0 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci#define PTRS_PER_PGD (USER_PTRS_PER_PGD * 2) 898c2ecf20Sopenharmony_ci#if defined(CONFIG_MIPS_HUGE_TLB_SUPPORT) && !defined(CONFIG_PHYS_ADDR_T_64BIT) 908c2ecf20Sopenharmony_ci# define PTRS_PER_PTE ((PAGE_SIZE << PTE_ORDER) / sizeof(pte_t) / 2) 918c2ecf20Sopenharmony_ci#else 928c2ecf20Sopenharmony_ci# define PTRS_PER_PTE ((PAGE_SIZE << PTE_ORDER) / sizeof(pte_t)) 938c2ecf20Sopenharmony_ci#endif 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci#define USER_PTRS_PER_PGD (0x80000000UL/PGDIR_SIZE) 968c2ecf20Sopenharmony_ci#define FIRST_USER_ADDRESS 0UL 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci#define VMALLOC_START MAP_BASE 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci#define PKMAP_END ((FIXADDR_START) & ~((LAST_PKMAP << PAGE_SHIFT)-1)) 1018c2ecf20Sopenharmony_ci#define PKMAP_BASE (PKMAP_END - PAGE_SIZE * LAST_PKMAP) 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci#ifdef CONFIG_HIGHMEM 1048c2ecf20Sopenharmony_ci# define VMALLOC_END (PKMAP_BASE-2*PAGE_SIZE) 1058c2ecf20Sopenharmony_ci#else 1068c2ecf20Sopenharmony_ci# define VMALLOC_END (FIXADDR_START-2*PAGE_SIZE) 1078c2ecf20Sopenharmony_ci#endif 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci#ifdef CONFIG_PHYS_ADDR_T_64BIT 1108c2ecf20Sopenharmony_ci#define pte_ERROR(e) \ 1118c2ecf20Sopenharmony_ci printk("%s:%d: bad pte %016Lx.\n", __FILE__, __LINE__, pte_val(e)) 1128c2ecf20Sopenharmony_ci#else 1138c2ecf20Sopenharmony_ci#define pte_ERROR(e) \ 1148c2ecf20Sopenharmony_ci printk("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, pte_val(e)) 1158c2ecf20Sopenharmony_ci#endif 1168c2ecf20Sopenharmony_ci#define pgd_ERROR(e) \ 1178c2ecf20Sopenharmony_ci printk("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e)) 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ciextern void load_pgd(unsigned long pg_dir); 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ciextern pte_t invalid_pte_table[PTRS_PER_PTE]; 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci/* 1248c2ecf20Sopenharmony_ci * Empty pgd/pmd entries point to the invalid_pte_table. 1258c2ecf20Sopenharmony_ci */ 1268c2ecf20Sopenharmony_cistatic inline int pmd_none(pmd_t pmd) 1278c2ecf20Sopenharmony_ci{ 1288c2ecf20Sopenharmony_ci return pmd_val(pmd) == (unsigned long) invalid_pte_table; 1298c2ecf20Sopenharmony_ci} 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_cistatic inline int pmd_bad(pmd_t pmd) 1328c2ecf20Sopenharmony_ci{ 1338c2ecf20Sopenharmony_ci#ifdef CONFIG_MIPS_HUGE_TLB_SUPPORT 1348c2ecf20Sopenharmony_ci /* pmd_huge(pmd) but inline */ 1358c2ecf20Sopenharmony_ci if (unlikely(pmd_val(pmd) & _PAGE_HUGE)) 1368c2ecf20Sopenharmony_ci return 0; 1378c2ecf20Sopenharmony_ci#endif 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci if (unlikely(pmd_val(pmd) & ~PAGE_MASK)) 1408c2ecf20Sopenharmony_ci return 1; 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci return 0; 1438c2ecf20Sopenharmony_ci} 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_cistatic inline int pmd_present(pmd_t pmd) 1468c2ecf20Sopenharmony_ci{ 1478c2ecf20Sopenharmony_ci return pmd_val(pmd) != (unsigned long) invalid_pte_table; 1488c2ecf20Sopenharmony_ci} 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_cistatic inline void pmd_clear(pmd_t *pmdp) 1518c2ecf20Sopenharmony_ci{ 1528c2ecf20Sopenharmony_ci pmd_val(*pmdp) = ((unsigned long) invalid_pte_table); 1538c2ecf20Sopenharmony_ci} 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci#if defined(CONFIG_XPA) 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci#define MAX_POSSIBLE_PHYSMEM_BITS 40 1588c2ecf20Sopenharmony_ci#define pte_pfn(x) (((unsigned long)((x).pte_high >> _PFN_SHIFT)) | (unsigned long)((x).pte_low << _PAGE_PRESENT_SHIFT)) 1598c2ecf20Sopenharmony_cistatic inline pte_t 1608c2ecf20Sopenharmony_cipfn_pte(unsigned long pfn, pgprot_t prot) 1618c2ecf20Sopenharmony_ci{ 1628c2ecf20Sopenharmony_ci pte_t pte; 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci pte.pte_low = (pfn >> _PAGE_PRESENT_SHIFT) | 1658c2ecf20Sopenharmony_ci (pgprot_val(prot) & ~_PFNX_MASK); 1668c2ecf20Sopenharmony_ci pte.pte_high = (pfn << _PFN_SHIFT) | 1678c2ecf20Sopenharmony_ci (pgprot_val(prot) & ~_PFN_MASK); 1688c2ecf20Sopenharmony_ci return pte; 1698c2ecf20Sopenharmony_ci} 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci#elif defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32) 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci#define MAX_POSSIBLE_PHYSMEM_BITS 36 1748c2ecf20Sopenharmony_ci#define pte_pfn(x) ((unsigned long)((x).pte_high >> 6)) 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_cistatic inline pte_t pfn_pte(unsigned long pfn, pgprot_t prot) 1778c2ecf20Sopenharmony_ci{ 1788c2ecf20Sopenharmony_ci pte_t pte; 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci pte.pte_high = (pfn << 6) | (pgprot_val(prot) & 0x3f); 1818c2ecf20Sopenharmony_ci pte.pte_low = pgprot_val(prot); 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci return pte; 1848c2ecf20Sopenharmony_ci} 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci#else 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci#define MAX_POSSIBLE_PHYSMEM_BITS 32 1898c2ecf20Sopenharmony_ci#ifdef CONFIG_CPU_VR41XX 1908c2ecf20Sopenharmony_ci#define pte_pfn(x) ((unsigned long)((x).pte >> (PAGE_SHIFT + 2))) 1918c2ecf20Sopenharmony_ci#define pfn_pte(pfn, prot) __pte(((pfn) << (PAGE_SHIFT + 2)) | pgprot_val(prot)) 1928c2ecf20Sopenharmony_ci#else 1938c2ecf20Sopenharmony_ci#define pte_pfn(x) ((unsigned long)((x).pte >> _PFN_SHIFT)) 1948c2ecf20Sopenharmony_ci#define pfn_pte(pfn, prot) __pte(((unsigned long long)(pfn) << _PFN_SHIFT) | pgprot_val(prot)) 1958c2ecf20Sopenharmony_ci#define pfn_pmd(pfn, prot) __pmd(((unsigned long long)(pfn) << _PFN_SHIFT) | pgprot_val(prot)) 1968c2ecf20Sopenharmony_ci#endif 1978c2ecf20Sopenharmony_ci#endif /* defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32) */ 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci#define pte_page(x) pfn_to_page(pte_pfn(x)) 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci#if defined(CONFIG_CPU_R3K_TLB) 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci/* Swap entries must have VALID bit cleared. */ 2048c2ecf20Sopenharmony_ci#define __swp_type(x) (((x).val >> 10) & 0x1f) 2058c2ecf20Sopenharmony_ci#define __swp_offset(x) ((x).val >> 15) 2068c2ecf20Sopenharmony_ci#define __swp_entry(type,offset) ((swp_entry_t) { ((type) << 10) | ((offset) << 15) }) 2078c2ecf20Sopenharmony_ci#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) 2088c2ecf20Sopenharmony_ci#define __swp_entry_to_pte(x) ((pte_t) { (x).val }) 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci#else 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci#if defined(CONFIG_XPA) 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci/* Swap entries must have VALID and GLOBAL bits cleared. */ 2158c2ecf20Sopenharmony_ci#define __swp_type(x) (((x).val >> 4) & 0x1f) 2168c2ecf20Sopenharmony_ci#define __swp_offset(x) ((x).val >> 9) 2178c2ecf20Sopenharmony_ci#define __swp_entry(type,offset) ((swp_entry_t) { ((type) << 4) | ((offset) << 9) }) 2188c2ecf20Sopenharmony_ci#define __pte_to_swp_entry(pte) ((swp_entry_t) { (pte).pte_high }) 2198c2ecf20Sopenharmony_ci#define __swp_entry_to_pte(x) ((pte_t) { 0, (x).val }) 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_ci#elif defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32) 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci/* Swap entries must have VALID and GLOBAL bits cleared. */ 2248c2ecf20Sopenharmony_ci#define __swp_type(x) (((x).val >> 2) & 0x1f) 2258c2ecf20Sopenharmony_ci#define __swp_offset(x) ((x).val >> 7) 2268c2ecf20Sopenharmony_ci#define __swp_entry(type, offset) ((swp_entry_t) { ((type) << 2) | ((offset) << 7) }) 2278c2ecf20Sopenharmony_ci#define __pte_to_swp_entry(pte) ((swp_entry_t) { (pte).pte_high }) 2288c2ecf20Sopenharmony_ci#define __swp_entry_to_pte(x) ((pte_t) { 0, (x).val }) 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci#else 2318c2ecf20Sopenharmony_ci/* 2328c2ecf20Sopenharmony_ci * Constraints: 2338c2ecf20Sopenharmony_ci * _PAGE_PRESENT at bit 0 2348c2ecf20Sopenharmony_ci * _PAGE_MODIFIED at bit 4 2358c2ecf20Sopenharmony_ci * _PAGE_GLOBAL at bit 6 2368c2ecf20Sopenharmony_ci * _PAGE_VALID at bit 7 2378c2ecf20Sopenharmony_ci */ 2388c2ecf20Sopenharmony_ci#define __swp_type(x) (((x).val >> 8) & 0x1f) 2398c2ecf20Sopenharmony_ci#define __swp_offset(x) ((x).val >> 13) 2408c2ecf20Sopenharmony_ci#define __swp_entry(type,offset) ((swp_entry_t) { ((type) << 8) | ((offset) << 13) }) 2418c2ecf20Sopenharmony_ci#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) 2428c2ecf20Sopenharmony_ci#define __swp_entry_to_pte(x) ((pte_t) { (x).val }) 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci#endif /* defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32) */ 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_ci#endif /* defined(CONFIG_CPU_R3K_TLB) */ 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci#endif /* _ASM_PGTABLE_32_H */ 249