18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _SUN3_PGTABLE_H 38c2ecf20Sopenharmony_ci#define _SUN3_PGTABLE_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <asm/sun3mmu.h> 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 88c2ecf20Sopenharmony_ci#include <asm/virtconvert.h> 98c2ecf20Sopenharmony_ci#include <linux/linkage.h> 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci/* 128c2ecf20Sopenharmony_ci * This file contains all the things which change drastically for the sun3 138c2ecf20Sopenharmony_ci * pagetable stuff, to avoid making too much of a mess of the generic m68k 148c2ecf20Sopenharmony_ci * `pgtable.h'; this should only be included from the generic file. --m 158c2ecf20Sopenharmony_ci */ 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci/* For virtual address to physical address conversion */ 188c2ecf20Sopenharmony_ci#define VTOP(addr) __pa(addr) 198c2ecf20Sopenharmony_ci#define PTOV(addr) __va(addr) 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#endif /* !__ASSEMBLY__ */ 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/* These need to be defined for compatibility although the sun3 doesn't use them */ 258c2ecf20Sopenharmony_ci#define _PAGE_NOCACHE030 0x040 268c2ecf20Sopenharmony_ci#define _CACHEMASK040 (~0x060) 278c2ecf20Sopenharmony_ci#define _PAGE_NOCACHE_S 0x040 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci/* Page protection values within PTE. */ 308c2ecf20Sopenharmony_ci#define SUN3_PAGE_VALID (0x80000000) 318c2ecf20Sopenharmony_ci#define SUN3_PAGE_WRITEABLE (0x40000000) 328c2ecf20Sopenharmony_ci#define SUN3_PAGE_SYSTEM (0x20000000) 338c2ecf20Sopenharmony_ci#define SUN3_PAGE_NOCACHE (0x10000000) 348c2ecf20Sopenharmony_ci#define SUN3_PAGE_ACCESSED (0x02000000) 358c2ecf20Sopenharmony_ci#define SUN3_PAGE_MODIFIED (0x01000000) 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci/* Externally used page protection values. */ 398c2ecf20Sopenharmony_ci#define _PAGE_PRESENT (SUN3_PAGE_VALID) 408c2ecf20Sopenharmony_ci#define _PAGE_ACCESSED (SUN3_PAGE_ACCESSED) 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci/* Compound page protection values. */ 438c2ecf20Sopenharmony_ci//todo: work out which ones *should* have SUN3_PAGE_NOCACHE and fix... 448c2ecf20Sopenharmony_ci// is it just PAGE_KERNEL and PAGE_SHARED? 458c2ecf20Sopenharmony_ci#define PAGE_NONE __pgprot(SUN3_PAGE_VALID \ 468c2ecf20Sopenharmony_ci | SUN3_PAGE_ACCESSED \ 478c2ecf20Sopenharmony_ci | SUN3_PAGE_NOCACHE) 488c2ecf20Sopenharmony_ci#define PAGE_SHARED __pgprot(SUN3_PAGE_VALID \ 498c2ecf20Sopenharmony_ci | SUN3_PAGE_WRITEABLE \ 508c2ecf20Sopenharmony_ci | SUN3_PAGE_ACCESSED \ 518c2ecf20Sopenharmony_ci | SUN3_PAGE_NOCACHE) 528c2ecf20Sopenharmony_ci#define PAGE_COPY __pgprot(SUN3_PAGE_VALID \ 538c2ecf20Sopenharmony_ci | SUN3_PAGE_ACCESSED \ 548c2ecf20Sopenharmony_ci | SUN3_PAGE_NOCACHE) 558c2ecf20Sopenharmony_ci#define PAGE_READONLY __pgprot(SUN3_PAGE_VALID \ 568c2ecf20Sopenharmony_ci | SUN3_PAGE_ACCESSED \ 578c2ecf20Sopenharmony_ci | SUN3_PAGE_NOCACHE) 588c2ecf20Sopenharmony_ci#define PAGE_KERNEL __pgprot(SUN3_PAGE_VALID \ 598c2ecf20Sopenharmony_ci | SUN3_PAGE_WRITEABLE \ 608c2ecf20Sopenharmony_ci | SUN3_PAGE_SYSTEM \ 618c2ecf20Sopenharmony_ci | SUN3_PAGE_NOCACHE \ 628c2ecf20Sopenharmony_ci | SUN3_PAGE_ACCESSED \ 638c2ecf20Sopenharmony_ci | SUN3_PAGE_MODIFIED) 648c2ecf20Sopenharmony_ci#define PAGE_INIT __pgprot(SUN3_PAGE_VALID \ 658c2ecf20Sopenharmony_ci | SUN3_PAGE_WRITEABLE \ 668c2ecf20Sopenharmony_ci | SUN3_PAGE_SYSTEM \ 678c2ecf20Sopenharmony_ci | SUN3_PAGE_NOCACHE) 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci/* 708c2ecf20Sopenharmony_ci * Page protections for initialising protection_map. The sun3 has only two 718c2ecf20Sopenharmony_ci * protection settings, valid (implying read and execute) and writeable. These 728c2ecf20Sopenharmony_ci * are as close as we can get... 738c2ecf20Sopenharmony_ci */ 748c2ecf20Sopenharmony_ci#define __P000 PAGE_NONE 758c2ecf20Sopenharmony_ci#define __P001 PAGE_READONLY 768c2ecf20Sopenharmony_ci#define __P010 PAGE_COPY 778c2ecf20Sopenharmony_ci#define __P011 PAGE_COPY 788c2ecf20Sopenharmony_ci#define __P100 PAGE_READONLY 798c2ecf20Sopenharmony_ci#define __P101 PAGE_READONLY 808c2ecf20Sopenharmony_ci#define __P110 PAGE_COPY 818c2ecf20Sopenharmony_ci#define __P111 PAGE_COPY 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci#define __S000 PAGE_NONE 848c2ecf20Sopenharmony_ci#define __S001 PAGE_READONLY 858c2ecf20Sopenharmony_ci#define __S010 PAGE_SHARED 868c2ecf20Sopenharmony_ci#define __S011 PAGE_SHARED 878c2ecf20Sopenharmony_ci#define __S100 PAGE_READONLY 888c2ecf20Sopenharmony_ci#define __S101 PAGE_READONLY 898c2ecf20Sopenharmony_ci#define __S110 PAGE_SHARED 908c2ecf20Sopenharmony_ci#define __S111 PAGE_SHARED 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci/* Use these fake page-protections on PMDs. */ 938c2ecf20Sopenharmony_ci#define SUN3_PMD_VALID (0x00000001) 948c2ecf20Sopenharmony_ci#define SUN3_PMD_MASK (0x0000003F) 958c2ecf20Sopenharmony_ci#define SUN3_PMD_MAGIC (0x0000002B) 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci/* 1008c2ecf20Sopenharmony_ci * Conversion functions: convert a page and protection to a page entry, 1018c2ecf20Sopenharmony_ci * and a page entry and page directory to the page they refer to. 1028c2ecf20Sopenharmony_ci */ 1038c2ecf20Sopenharmony_ci#define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot)) 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_cistatic inline pte_t pte_modify(pte_t pte, pgprot_t newprot) 1068c2ecf20Sopenharmony_ci{ 1078c2ecf20Sopenharmony_ci pte_val(pte) = (pte_val(pte) & SUN3_PAGE_CHG_MASK) | pgprot_val(newprot); 1088c2ecf20Sopenharmony_ci return pte; 1098c2ecf20Sopenharmony_ci} 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci#define pmd_set(pmdp,ptep) do {} while (0) 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci#define __pte_page(pte) \ 1148c2ecf20Sopenharmony_ci((unsigned long) __va ((pte_val (pte) & SUN3_PAGE_PGNUM_MASK) << PAGE_SHIFT)) 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_cistatic inline unsigned long pmd_page_vaddr(pmd_t pmd) 1178c2ecf20Sopenharmony_ci{ 1188c2ecf20Sopenharmony_ci return (unsigned long)__va(pmd_val(pmd) & PAGE_MASK); 1198c2ecf20Sopenharmony_ci} 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_cistatic inline int pte_none (pte_t pte) { return !pte_val (pte); } 1228c2ecf20Sopenharmony_cistatic inline int pte_present (pte_t pte) { return pte_val (pte) & SUN3_PAGE_VALID; } 1238c2ecf20Sopenharmony_cistatic inline void pte_clear (struct mm_struct *mm, unsigned long addr, pte_t *ptep) 1248c2ecf20Sopenharmony_ci{ 1258c2ecf20Sopenharmony_ci pte_val (*ptep) = 0; 1268c2ecf20Sopenharmony_ci} 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci#define pte_pfn(pte) (pte_val(pte) & SUN3_PAGE_PGNUM_MASK) 1298c2ecf20Sopenharmony_ci#define pfn_pte(pfn, pgprot) \ 1308c2ecf20Sopenharmony_ci({ pte_t __pte; pte_val(__pte) = pfn | pgprot_val(pgprot); __pte; }) 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci#define pte_page(pte) virt_to_page(__pte_page(pte)) 1338c2ecf20Sopenharmony_ci#define pmd_page(pmd) virt_to_page(pmd_page_vaddr(pmd)) 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_cistatic inline int pmd_none2 (pmd_t *pmd) { return !pmd_val (*pmd); } 1378c2ecf20Sopenharmony_ci#define pmd_none(pmd) pmd_none2(&(pmd)) 1388c2ecf20Sopenharmony_ci//static inline int pmd_bad (pmd_t pmd) { return (pmd_val (pmd) & SUN3_PMD_MASK) != SUN3_PMD_MAGIC; } 1398c2ecf20Sopenharmony_cistatic inline int pmd_bad2 (pmd_t *pmd) { return 0; } 1408c2ecf20Sopenharmony_ci#define pmd_bad(pmd) pmd_bad2(&(pmd)) 1418c2ecf20Sopenharmony_cistatic inline int pmd_present2 (pmd_t *pmd) { return pmd_val (*pmd) & SUN3_PMD_VALID; } 1428c2ecf20Sopenharmony_ci/* #define pmd_present(pmd) pmd_present2(&(pmd)) */ 1438c2ecf20Sopenharmony_ci#define pmd_present(pmd) (!pmd_none2(&(pmd))) 1448c2ecf20Sopenharmony_cistatic inline void pmd_clear (pmd_t *pmdp) { pmd_val (*pmdp) = 0; } 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci#define pte_ERROR(e) \ 1488c2ecf20Sopenharmony_ci pr_err("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, pte_val(e)) 1498c2ecf20Sopenharmony_ci#define pgd_ERROR(e) \ 1508c2ecf20Sopenharmony_ci pr_err("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e)) 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci/* 1548c2ecf20Sopenharmony_ci * The following only work if pte_present() is true. 1558c2ecf20Sopenharmony_ci * Undefined behaviour if not... 1568c2ecf20Sopenharmony_ci * [we have the full set here even if they don't change from m68k] 1578c2ecf20Sopenharmony_ci */ 1588c2ecf20Sopenharmony_cistatic inline int pte_write(pte_t pte) { return pte_val(pte) & SUN3_PAGE_WRITEABLE; } 1598c2ecf20Sopenharmony_cistatic inline int pte_dirty(pte_t pte) { return pte_val(pte) & SUN3_PAGE_MODIFIED; } 1608c2ecf20Sopenharmony_cistatic inline int pte_young(pte_t pte) { return pte_val(pte) & SUN3_PAGE_ACCESSED; } 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_cistatic inline pte_t pte_wrprotect(pte_t pte) { pte_val(pte) &= ~SUN3_PAGE_WRITEABLE; return pte; } 1638c2ecf20Sopenharmony_cistatic inline pte_t pte_mkclean(pte_t pte) { pte_val(pte) &= ~SUN3_PAGE_MODIFIED; return pte; } 1648c2ecf20Sopenharmony_cistatic inline pte_t pte_mkold(pte_t pte) { pte_val(pte) &= ~SUN3_PAGE_ACCESSED; return pte; } 1658c2ecf20Sopenharmony_cistatic inline pte_t pte_mkwrite(pte_t pte) { pte_val(pte) |= SUN3_PAGE_WRITEABLE; return pte; } 1668c2ecf20Sopenharmony_cistatic inline pte_t pte_mkdirty(pte_t pte) { pte_val(pte) |= SUN3_PAGE_MODIFIED; return pte; } 1678c2ecf20Sopenharmony_cistatic inline pte_t pte_mkyoung(pte_t pte) { pte_val(pte) |= SUN3_PAGE_ACCESSED; return pte; } 1688c2ecf20Sopenharmony_cistatic inline pte_t pte_mknocache(pte_t pte) { pte_val(pte) |= SUN3_PAGE_NOCACHE; return pte; } 1698c2ecf20Sopenharmony_ci// use this version when caches work... 1708c2ecf20Sopenharmony_ci//static inline pte_t pte_mkcache(pte_t pte) { pte_val(pte) &= SUN3_PAGE_NOCACHE; return pte; } 1718c2ecf20Sopenharmony_ci// until then, use: 1728c2ecf20Sopenharmony_cistatic inline pte_t pte_mkcache(pte_t pte) { return pte; } 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ciextern pgd_t swapper_pg_dir[PTRS_PER_PGD]; 1758c2ecf20Sopenharmony_ciextern pgd_t kernel_pg_dir[PTRS_PER_PGD]; 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci/* Macros to (de)construct the fake PTEs representing swap pages. */ 1788c2ecf20Sopenharmony_ci#define __swp_type(x) ((x).val & 0x7F) 1798c2ecf20Sopenharmony_ci#define __swp_offset(x) (((x).val) >> 7) 1808c2ecf20Sopenharmony_ci#define __swp_entry(type,offset) ((swp_entry_t) { ((type) | ((offset) << 7)) }) 1818c2ecf20Sopenharmony_ci#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) 1828c2ecf20Sopenharmony_ci#define __swp_entry_to_pte(x) ((pte_t) { (x).val }) 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci#endif /* !__ASSEMBLY__ */ 1858c2ecf20Sopenharmony_ci#endif /* !_SUN3_PGTABLE_H */ 186