18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _MOTOROLA_PGTABLE_H 38c2ecf20Sopenharmony_ci#define _MOTOROLA_PGTABLE_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci/* 78c2ecf20Sopenharmony_ci * Definitions for MMU descriptors 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci#define _PAGE_PRESENT 0x001 108c2ecf20Sopenharmony_ci#define _PAGE_SHORT 0x002 118c2ecf20Sopenharmony_ci#define _PAGE_RONLY 0x004 128c2ecf20Sopenharmony_ci#define _PAGE_READWRITE 0x000 138c2ecf20Sopenharmony_ci#define _PAGE_ACCESSED 0x008 148c2ecf20Sopenharmony_ci#define _PAGE_DIRTY 0x010 158c2ecf20Sopenharmony_ci#define _PAGE_SUPER 0x080 /* 68040 supervisor only */ 168c2ecf20Sopenharmony_ci#define _PAGE_GLOBAL040 0x400 /* 68040 global bit, used for kva descs */ 178c2ecf20Sopenharmony_ci#define _PAGE_NOCACHE030 0x040 /* 68030 no-cache mode */ 188c2ecf20Sopenharmony_ci#define _PAGE_NOCACHE 0x060 /* 68040 cache mode, non-serialized */ 198c2ecf20Sopenharmony_ci#define _PAGE_NOCACHE_S 0x040 /* 68040 no-cache mode, serialized */ 208c2ecf20Sopenharmony_ci#define _PAGE_CACHE040 0x020 /* 68040 cache mode, cachable, copyback */ 218c2ecf20Sopenharmony_ci#define _PAGE_CACHE040W 0x000 /* 68040 cache mode, cachable, write-through */ 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define _DESCTYPE_MASK 0x003 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#define _CACHEMASK040 (~0x060) 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci/* 288c2ecf20Sopenharmony_ci * Currently set to the minimum alignment of table pointers (256 bytes). 298c2ecf20Sopenharmony_ci * The hardware only uses the low 4 bits for state: 308c2ecf20Sopenharmony_ci * 318c2ecf20Sopenharmony_ci * 3 - Used 328c2ecf20Sopenharmony_ci * 2 - Write Protected 338c2ecf20Sopenharmony_ci * 0,1 - Descriptor Type 348c2ecf20Sopenharmony_ci * 358c2ecf20Sopenharmony_ci * and has the rest of the bits reserved. 368c2ecf20Sopenharmony_ci */ 378c2ecf20Sopenharmony_ci#define _TABLE_MASK (0xffffff00) 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#define _PAGE_TABLE (_PAGE_SHORT) 408c2ecf20Sopenharmony_ci#define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_NOCACHE) 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define _PAGE_PROTNONE 0x004 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci/* This is the cache mode to be used for pages containing page descriptors for 478c2ecf20Sopenharmony_ci * processors >= '040. It is in pte_mknocache(), and the variable is defined 488c2ecf20Sopenharmony_ci * and initialized in head.S */ 498c2ecf20Sopenharmony_ciextern int m68k_pgtable_cachemode; 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci/* This is the cache mode for normal pages, for supervisor access on 528c2ecf20Sopenharmony_ci * processors >= '040. It is used in pte_mkcache(), and the variable is 538c2ecf20Sopenharmony_ci * defined and initialized in head.S */ 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci#if defined(CPU_M68060_ONLY) && defined(CONFIG_060_WRITETHROUGH) 568c2ecf20Sopenharmony_ci#define m68k_supervisor_cachemode _PAGE_CACHE040W 578c2ecf20Sopenharmony_ci#elif defined(CPU_M68040_OR_M68060_ONLY) 588c2ecf20Sopenharmony_ci#define m68k_supervisor_cachemode _PAGE_CACHE040 598c2ecf20Sopenharmony_ci#elif defined(CPU_M68020_OR_M68030_ONLY) 608c2ecf20Sopenharmony_ci#define m68k_supervisor_cachemode 0 618c2ecf20Sopenharmony_ci#else 628c2ecf20Sopenharmony_ciextern int m68k_supervisor_cachemode; 638c2ecf20Sopenharmony_ci#endif 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci#if defined(CPU_M68040_OR_M68060_ONLY) 668c2ecf20Sopenharmony_ci#define mm_cachebits _PAGE_CACHE040 678c2ecf20Sopenharmony_ci#elif defined(CPU_M68020_OR_M68030_ONLY) 688c2ecf20Sopenharmony_ci#define mm_cachebits 0 698c2ecf20Sopenharmony_ci#else 708c2ecf20Sopenharmony_ciextern unsigned long mm_cachebits; 718c2ecf20Sopenharmony_ci#endif 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci#define PAGE_NONE __pgprot(_PAGE_PROTNONE | _PAGE_ACCESSED | mm_cachebits) 748c2ecf20Sopenharmony_ci#define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED | mm_cachebits) 758c2ecf20Sopenharmony_ci#define PAGE_COPY __pgprot(_PAGE_PRESENT | _PAGE_RONLY | _PAGE_ACCESSED | mm_cachebits) 768c2ecf20Sopenharmony_ci#define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_RONLY | _PAGE_ACCESSED | mm_cachebits) 778c2ecf20Sopenharmony_ci#define PAGE_KERNEL __pgprot(_PAGE_PRESENT | _PAGE_DIRTY | _PAGE_ACCESSED | mm_cachebits) 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci/* Alternate definitions that are compile time constants, for 808c2ecf20Sopenharmony_ci initializing protection_map. The cachebits are fixed later. */ 818c2ecf20Sopenharmony_ci#define PAGE_NONE_C __pgprot(_PAGE_PROTNONE | _PAGE_ACCESSED) 828c2ecf20Sopenharmony_ci#define PAGE_SHARED_C __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED) 838c2ecf20Sopenharmony_ci#define PAGE_COPY_C __pgprot(_PAGE_PRESENT | _PAGE_RONLY | _PAGE_ACCESSED) 848c2ecf20Sopenharmony_ci#define PAGE_READONLY_C __pgprot(_PAGE_PRESENT | _PAGE_RONLY | _PAGE_ACCESSED) 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci/* 878c2ecf20Sopenharmony_ci * The m68k can't do page protection for execute, and considers that the same are read. 888c2ecf20Sopenharmony_ci * Also, write permissions imply read permissions. This is the closest we can get.. 898c2ecf20Sopenharmony_ci */ 908c2ecf20Sopenharmony_ci#define __P000 PAGE_NONE_C 918c2ecf20Sopenharmony_ci#define __P001 PAGE_READONLY_C 928c2ecf20Sopenharmony_ci#define __P010 PAGE_COPY_C 938c2ecf20Sopenharmony_ci#define __P011 PAGE_COPY_C 948c2ecf20Sopenharmony_ci#define __P100 PAGE_READONLY_C 958c2ecf20Sopenharmony_ci#define __P101 PAGE_READONLY_C 968c2ecf20Sopenharmony_ci#define __P110 PAGE_COPY_C 978c2ecf20Sopenharmony_ci#define __P111 PAGE_COPY_C 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci#define __S000 PAGE_NONE_C 1008c2ecf20Sopenharmony_ci#define __S001 PAGE_READONLY_C 1018c2ecf20Sopenharmony_ci#define __S010 PAGE_SHARED_C 1028c2ecf20Sopenharmony_ci#define __S011 PAGE_SHARED_C 1038c2ecf20Sopenharmony_ci#define __S100 PAGE_READONLY_C 1048c2ecf20Sopenharmony_ci#define __S101 PAGE_READONLY_C 1058c2ecf20Sopenharmony_ci#define __S110 PAGE_SHARED_C 1068c2ecf20Sopenharmony_ci#define __S111 PAGE_SHARED_C 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci/* 1098c2ecf20Sopenharmony_ci * Conversion functions: convert a page and protection to a page entry, 1108c2ecf20Sopenharmony_ci * and a page entry and page directory to the page they refer to. 1118c2ecf20Sopenharmony_ci */ 1128c2ecf20Sopenharmony_ci#define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot)) 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_cistatic inline pte_t pte_modify(pte_t pte, pgprot_t newprot) 1158c2ecf20Sopenharmony_ci{ 1168c2ecf20Sopenharmony_ci pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot); 1178c2ecf20Sopenharmony_ci return pte; 1188c2ecf20Sopenharmony_ci} 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_cistatic inline void pmd_set(pmd_t *pmdp, pte_t *ptep) 1218c2ecf20Sopenharmony_ci{ 1228c2ecf20Sopenharmony_ci pmd_val(*pmdp) = virt_to_phys(ptep) | _PAGE_TABLE | _PAGE_ACCESSED; 1238c2ecf20Sopenharmony_ci} 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_cistatic inline void pud_set(pud_t *pudp, pmd_t *pmdp) 1268c2ecf20Sopenharmony_ci{ 1278c2ecf20Sopenharmony_ci pud_val(*pudp) = _PAGE_TABLE | _PAGE_ACCESSED | __pa(pmdp); 1288c2ecf20Sopenharmony_ci} 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci#define __pte_page(pte) ((unsigned long)__va(pte_val(pte) & PAGE_MASK)) 1318c2ecf20Sopenharmony_ci#define pmd_page_vaddr(pmd) ((unsigned long)__va(pmd_val(pmd) & _TABLE_MASK)) 1328c2ecf20Sopenharmony_ci#define pud_pgtable(pud) ((pmd_t *)__va(pud_val(pud) & _TABLE_MASK)) 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci#define pte_none(pte) (!pte_val(pte)) 1368c2ecf20Sopenharmony_ci#define pte_present(pte) (pte_val(pte) & (_PAGE_PRESENT | _PAGE_PROTNONE)) 1378c2ecf20Sopenharmony_ci#define pte_clear(mm,addr,ptep) ({ pte_val(*(ptep)) = 0; }) 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci#define pte_page(pte) virt_to_page(__va(pte_val(pte))) 1408c2ecf20Sopenharmony_ci#define pte_pfn(pte) (pte_val(pte) >> PAGE_SHIFT) 1418c2ecf20Sopenharmony_ci#define pfn_pte(pfn, prot) __pte(((pfn) << PAGE_SHIFT) | pgprot_val(prot)) 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci#define pmd_none(pmd) (!pmd_val(pmd)) 1448c2ecf20Sopenharmony_ci#define pmd_bad(pmd) ((pmd_val(pmd) & _DESCTYPE_MASK) != _PAGE_TABLE) 1458c2ecf20Sopenharmony_ci#define pmd_present(pmd) (pmd_val(pmd) & _PAGE_TABLE) 1468c2ecf20Sopenharmony_ci#define pmd_clear(pmdp) ({ pmd_val(*pmdp) = 0; }) 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci/* 1498c2ecf20Sopenharmony_ci * m68k does not have huge pages (020/030 actually could), but generic code 1508c2ecf20Sopenharmony_ci * expects pmd_page() to exists, only to then DCE it all. Provide a dummy to 1518c2ecf20Sopenharmony_ci * make the compiler happy. 1528c2ecf20Sopenharmony_ci */ 1538c2ecf20Sopenharmony_ci#define pmd_page(pmd) NULL 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci#define pud_none(pud) (!pud_val(pud)) 1578c2ecf20Sopenharmony_ci#define pud_bad(pud) ((pud_val(pud) & _DESCTYPE_MASK) != _PAGE_TABLE) 1588c2ecf20Sopenharmony_ci#define pud_present(pud) (pud_val(pud) & _PAGE_TABLE) 1598c2ecf20Sopenharmony_ci#define pud_clear(pudp) ({ pud_val(*pudp) = 0; }) 1608c2ecf20Sopenharmony_ci#define pud_page(pud) (mem_map + ((unsigned long)(__va(pud_val(pud)) - PAGE_OFFSET) >> PAGE_SHIFT)) 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci#define pte_ERROR(e) \ 1638c2ecf20Sopenharmony_ci printk("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, pte_val(e)) 1648c2ecf20Sopenharmony_ci#define pmd_ERROR(e) \ 1658c2ecf20Sopenharmony_ci printk("%s:%d: bad pmd %08lx.\n", __FILE__, __LINE__, pmd_val(e)) 1668c2ecf20Sopenharmony_ci#define pgd_ERROR(e) \ 1678c2ecf20Sopenharmony_ci printk("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e)) 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci/* 1718c2ecf20Sopenharmony_ci * The following only work if pte_present() is true. 1728c2ecf20Sopenharmony_ci * Undefined behaviour if not.. 1738c2ecf20Sopenharmony_ci */ 1748c2ecf20Sopenharmony_cistatic inline int pte_write(pte_t pte) { return !(pte_val(pte) & _PAGE_RONLY); } 1758c2ecf20Sopenharmony_cistatic inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY; } 1768c2ecf20Sopenharmony_cistatic inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; } 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_cistatic inline pte_t pte_wrprotect(pte_t pte) { pte_val(pte) |= _PAGE_RONLY; return pte; } 1798c2ecf20Sopenharmony_cistatic inline pte_t pte_mkclean(pte_t pte) { pte_val(pte) &= ~_PAGE_DIRTY; return pte; } 1808c2ecf20Sopenharmony_cistatic inline pte_t pte_mkold(pte_t pte) { pte_val(pte) &= ~_PAGE_ACCESSED; return pte; } 1818c2ecf20Sopenharmony_cistatic inline pte_t pte_mkwrite(pte_t pte) { pte_val(pte) &= ~_PAGE_RONLY; return pte; } 1828c2ecf20Sopenharmony_cistatic inline pte_t pte_mkdirty(pte_t pte) { pte_val(pte) |= _PAGE_DIRTY; return pte; } 1838c2ecf20Sopenharmony_cistatic inline pte_t pte_mkyoung(pte_t pte) { pte_val(pte) |= _PAGE_ACCESSED; return pte; } 1848c2ecf20Sopenharmony_cistatic inline pte_t pte_mknocache(pte_t pte) 1858c2ecf20Sopenharmony_ci{ 1868c2ecf20Sopenharmony_ci pte_val(pte) = (pte_val(pte) & _CACHEMASK040) | m68k_pgtable_cachemode; 1878c2ecf20Sopenharmony_ci return pte; 1888c2ecf20Sopenharmony_ci} 1898c2ecf20Sopenharmony_cistatic inline pte_t pte_mkcache(pte_t pte) 1908c2ecf20Sopenharmony_ci{ 1918c2ecf20Sopenharmony_ci pte_val(pte) = (pte_val(pte) & _CACHEMASK040) | m68k_supervisor_cachemode; 1928c2ecf20Sopenharmony_ci return pte; 1938c2ecf20Sopenharmony_ci} 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci#define swapper_pg_dir kernel_pg_dir 1968c2ecf20Sopenharmony_ciextern pgd_t kernel_pg_dir[128]; 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci/* Encode and de-code a swap entry (must be !pte_none(e) && !pte_present(e)) */ 1998c2ecf20Sopenharmony_ci#define __swp_type(x) (((x).val >> 4) & 0xff) 2008c2ecf20Sopenharmony_ci#define __swp_offset(x) ((x).val >> 12) 2018c2ecf20Sopenharmony_ci#define __swp_entry(type, offset) ((swp_entry_t) { ((type) << 4) | ((offset) << 12) }) 2028c2ecf20Sopenharmony_ci#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) 2038c2ecf20Sopenharmony_ci#define __swp_entry_to_pte(x) ((pte_t) { (x).val }) 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci#endif /* !__ASSEMBLY__ */ 2068c2ecf20Sopenharmony_ci#endif /* _MOTOROLA_PGTABLE_H */ 207