1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef _SUN3_PGTABLE_H
3*4882a593Smuzhiyun #define _SUN3_PGTABLE_H
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun #include <asm/sun3mmu.h>
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun #ifndef __ASSEMBLY__
8*4882a593Smuzhiyun #include <asm/virtconvert.h>
9*4882a593Smuzhiyun #include <linux/linkage.h>
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun /*
12*4882a593Smuzhiyun * This file contains all the things which change drastically for the sun3
13*4882a593Smuzhiyun * pagetable stuff, to avoid making too much of a mess of the generic m68k
14*4882a593Smuzhiyun * `pgtable.h'; this should only be included from the generic file. --m
15*4882a593Smuzhiyun */
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun /* For virtual address to physical address conversion */
18*4882a593Smuzhiyun #define VTOP(addr) __pa(addr)
19*4882a593Smuzhiyun #define PTOV(addr) __va(addr)
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun #endif /* !__ASSEMBLY__ */
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun /* These need to be defined for compatibility although the sun3 doesn't use them */
25*4882a593Smuzhiyun #define _PAGE_NOCACHE030 0x040
26*4882a593Smuzhiyun #define _CACHEMASK040 (~0x060)
27*4882a593Smuzhiyun #define _PAGE_NOCACHE_S 0x040
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun /* Page protection values within PTE. */
30*4882a593Smuzhiyun #define SUN3_PAGE_VALID (0x80000000)
31*4882a593Smuzhiyun #define SUN3_PAGE_WRITEABLE (0x40000000)
32*4882a593Smuzhiyun #define SUN3_PAGE_SYSTEM (0x20000000)
33*4882a593Smuzhiyun #define SUN3_PAGE_NOCACHE (0x10000000)
34*4882a593Smuzhiyun #define SUN3_PAGE_ACCESSED (0x02000000)
35*4882a593Smuzhiyun #define SUN3_PAGE_MODIFIED (0x01000000)
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun /* Externally used page protection values. */
39*4882a593Smuzhiyun #define _PAGE_PRESENT (SUN3_PAGE_VALID)
40*4882a593Smuzhiyun #define _PAGE_ACCESSED (SUN3_PAGE_ACCESSED)
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun /* Compound page protection values. */
43*4882a593Smuzhiyun //todo: work out which ones *should* have SUN3_PAGE_NOCACHE and fix...
44*4882a593Smuzhiyun // is it just PAGE_KERNEL and PAGE_SHARED?
45*4882a593Smuzhiyun #define PAGE_NONE __pgprot(SUN3_PAGE_VALID \
46*4882a593Smuzhiyun | SUN3_PAGE_ACCESSED \
47*4882a593Smuzhiyun | SUN3_PAGE_NOCACHE)
48*4882a593Smuzhiyun #define PAGE_SHARED __pgprot(SUN3_PAGE_VALID \
49*4882a593Smuzhiyun | SUN3_PAGE_WRITEABLE \
50*4882a593Smuzhiyun | SUN3_PAGE_ACCESSED \
51*4882a593Smuzhiyun | SUN3_PAGE_NOCACHE)
52*4882a593Smuzhiyun #define PAGE_COPY __pgprot(SUN3_PAGE_VALID \
53*4882a593Smuzhiyun | SUN3_PAGE_ACCESSED \
54*4882a593Smuzhiyun | SUN3_PAGE_NOCACHE)
55*4882a593Smuzhiyun #define PAGE_READONLY __pgprot(SUN3_PAGE_VALID \
56*4882a593Smuzhiyun | SUN3_PAGE_ACCESSED \
57*4882a593Smuzhiyun | SUN3_PAGE_NOCACHE)
58*4882a593Smuzhiyun #define PAGE_KERNEL __pgprot(SUN3_PAGE_VALID \
59*4882a593Smuzhiyun | SUN3_PAGE_WRITEABLE \
60*4882a593Smuzhiyun | SUN3_PAGE_SYSTEM \
61*4882a593Smuzhiyun | SUN3_PAGE_NOCACHE \
62*4882a593Smuzhiyun | SUN3_PAGE_ACCESSED \
63*4882a593Smuzhiyun | SUN3_PAGE_MODIFIED)
64*4882a593Smuzhiyun #define PAGE_INIT __pgprot(SUN3_PAGE_VALID \
65*4882a593Smuzhiyun | SUN3_PAGE_WRITEABLE \
66*4882a593Smuzhiyun | SUN3_PAGE_SYSTEM \
67*4882a593Smuzhiyun | SUN3_PAGE_NOCACHE)
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun /*
70*4882a593Smuzhiyun * Page protections for initialising protection_map. The sun3 has only two
71*4882a593Smuzhiyun * protection settings, valid (implying read and execute) and writeable. These
72*4882a593Smuzhiyun * are as close as we can get...
73*4882a593Smuzhiyun */
74*4882a593Smuzhiyun #define __P000 PAGE_NONE
75*4882a593Smuzhiyun #define __P001 PAGE_READONLY
76*4882a593Smuzhiyun #define __P010 PAGE_COPY
77*4882a593Smuzhiyun #define __P011 PAGE_COPY
78*4882a593Smuzhiyun #define __P100 PAGE_READONLY
79*4882a593Smuzhiyun #define __P101 PAGE_READONLY
80*4882a593Smuzhiyun #define __P110 PAGE_COPY
81*4882a593Smuzhiyun #define __P111 PAGE_COPY
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun #define __S000 PAGE_NONE
84*4882a593Smuzhiyun #define __S001 PAGE_READONLY
85*4882a593Smuzhiyun #define __S010 PAGE_SHARED
86*4882a593Smuzhiyun #define __S011 PAGE_SHARED
87*4882a593Smuzhiyun #define __S100 PAGE_READONLY
88*4882a593Smuzhiyun #define __S101 PAGE_READONLY
89*4882a593Smuzhiyun #define __S110 PAGE_SHARED
90*4882a593Smuzhiyun #define __S111 PAGE_SHARED
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun /* Use these fake page-protections on PMDs. */
93*4882a593Smuzhiyun #define SUN3_PMD_VALID (0x00000001)
94*4882a593Smuzhiyun #define SUN3_PMD_MASK (0x0000003F)
95*4882a593Smuzhiyun #define SUN3_PMD_MAGIC (0x0000002B)
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun #ifndef __ASSEMBLY__
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun /*
100*4882a593Smuzhiyun * Conversion functions: convert a page and protection to a page entry,
101*4882a593Smuzhiyun * and a page entry and page directory to the page they refer to.
102*4882a593Smuzhiyun */
103*4882a593Smuzhiyun #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
104*4882a593Smuzhiyun
pte_modify(pte_t pte,pgprot_t newprot)105*4882a593Smuzhiyun static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
106*4882a593Smuzhiyun {
107*4882a593Smuzhiyun pte_val(pte) = (pte_val(pte) & SUN3_PAGE_CHG_MASK) | pgprot_val(newprot);
108*4882a593Smuzhiyun return pte;
109*4882a593Smuzhiyun }
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun #define pmd_set(pmdp,ptep) do {} while (0)
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun #define __pte_page(pte) \
114*4882a593Smuzhiyun ((unsigned long) __va ((pte_val (pte) & SUN3_PAGE_PGNUM_MASK) << PAGE_SHIFT))
115*4882a593Smuzhiyun
pmd_page_vaddr(pmd_t pmd)116*4882a593Smuzhiyun static inline unsigned long pmd_page_vaddr(pmd_t pmd)
117*4882a593Smuzhiyun {
118*4882a593Smuzhiyun return (unsigned long)__va(pmd_val(pmd) & PAGE_MASK);
119*4882a593Smuzhiyun }
120*4882a593Smuzhiyun
pte_none(pte_t pte)121*4882a593Smuzhiyun static inline int pte_none (pte_t pte) { return !pte_val (pte); }
pte_present(pte_t pte)122*4882a593Smuzhiyun static inline int pte_present (pte_t pte) { return pte_val (pte) & SUN3_PAGE_VALID; }
pte_clear(struct mm_struct * mm,unsigned long addr,pte_t * ptep)123*4882a593Smuzhiyun static inline void pte_clear (struct mm_struct *mm, unsigned long addr, pte_t *ptep)
124*4882a593Smuzhiyun {
125*4882a593Smuzhiyun pte_val (*ptep) = 0;
126*4882a593Smuzhiyun }
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun #define pte_pfn(pte) (pte_val(pte) & SUN3_PAGE_PGNUM_MASK)
129*4882a593Smuzhiyun #define pfn_pte(pfn, pgprot) \
130*4882a593Smuzhiyun ({ pte_t __pte; pte_val(__pte) = pfn | pgprot_val(pgprot); __pte; })
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun #define pte_page(pte) virt_to_page(__pte_page(pte))
133*4882a593Smuzhiyun #define pmd_page(pmd) virt_to_page(pmd_page_vaddr(pmd))
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun
pmd_none2(pmd_t * pmd)136*4882a593Smuzhiyun static inline int pmd_none2 (pmd_t *pmd) { return !pmd_val (*pmd); }
137*4882a593Smuzhiyun #define pmd_none(pmd) pmd_none2(&(pmd))
138*4882a593Smuzhiyun //static inline int pmd_bad (pmd_t pmd) { return (pmd_val (pmd) & SUN3_PMD_MASK) != SUN3_PMD_MAGIC; }
pmd_bad2(pmd_t * pmd)139*4882a593Smuzhiyun static inline int pmd_bad2 (pmd_t *pmd) { return 0; }
140*4882a593Smuzhiyun #define pmd_bad(pmd) pmd_bad2(&(pmd))
pmd_present2(pmd_t * pmd)141*4882a593Smuzhiyun static inline int pmd_present2 (pmd_t *pmd) { return pmd_val (*pmd) & SUN3_PMD_VALID; }
142*4882a593Smuzhiyun /* #define pmd_present(pmd) pmd_present2(&(pmd)) */
143*4882a593Smuzhiyun #define pmd_present(pmd) (!pmd_none2(&(pmd)))
pmd_clear(pmd_t * pmdp)144*4882a593Smuzhiyun static inline void pmd_clear (pmd_t *pmdp) { pmd_val (*pmdp) = 0; }
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun #define pte_ERROR(e) \
148*4882a593Smuzhiyun pr_err("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, pte_val(e))
149*4882a593Smuzhiyun #define pgd_ERROR(e) \
150*4882a593Smuzhiyun pr_err("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e))
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun
153*4882a593Smuzhiyun /*
154*4882a593Smuzhiyun * The following only work if pte_present() is true.
155*4882a593Smuzhiyun * Undefined behaviour if not...
156*4882a593Smuzhiyun * [we have the full set here even if they don't change from m68k]
157*4882a593Smuzhiyun */
pte_write(pte_t pte)158*4882a593Smuzhiyun static inline int pte_write(pte_t pte) { return pte_val(pte) & SUN3_PAGE_WRITEABLE; }
pte_dirty(pte_t pte)159*4882a593Smuzhiyun static inline int pte_dirty(pte_t pte) { return pte_val(pte) & SUN3_PAGE_MODIFIED; }
pte_young(pte_t pte)160*4882a593Smuzhiyun static inline int pte_young(pte_t pte) { return pte_val(pte) & SUN3_PAGE_ACCESSED; }
161*4882a593Smuzhiyun
pte_wrprotect(pte_t pte)162*4882a593Smuzhiyun static inline pte_t pte_wrprotect(pte_t pte) { pte_val(pte) &= ~SUN3_PAGE_WRITEABLE; return pte; }
pte_mkclean(pte_t pte)163*4882a593Smuzhiyun static inline pte_t pte_mkclean(pte_t pte) { pte_val(pte) &= ~SUN3_PAGE_MODIFIED; return pte; }
pte_mkold(pte_t pte)164*4882a593Smuzhiyun static inline pte_t pte_mkold(pte_t pte) { pte_val(pte) &= ~SUN3_PAGE_ACCESSED; return pte; }
pte_mkwrite(pte_t pte)165*4882a593Smuzhiyun static inline pte_t pte_mkwrite(pte_t pte) { pte_val(pte) |= SUN3_PAGE_WRITEABLE; return pte; }
pte_mkdirty(pte_t pte)166*4882a593Smuzhiyun static inline pte_t pte_mkdirty(pte_t pte) { pte_val(pte) |= SUN3_PAGE_MODIFIED; return pte; }
pte_mkyoung(pte_t pte)167*4882a593Smuzhiyun static inline pte_t pte_mkyoung(pte_t pte) { pte_val(pte) |= SUN3_PAGE_ACCESSED; return pte; }
pte_mknocache(pte_t pte)168*4882a593Smuzhiyun static inline pte_t pte_mknocache(pte_t pte) { pte_val(pte) |= SUN3_PAGE_NOCACHE; return pte; }
169*4882a593Smuzhiyun // use this version when caches work...
170*4882a593Smuzhiyun //static inline pte_t pte_mkcache(pte_t pte) { pte_val(pte) &= SUN3_PAGE_NOCACHE; return pte; }
171*4882a593Smuzhiyun // until then, use:
pte_mkcache(pte_t pte)172*4882a593Smuzhiyun static inline pte_t pte_mkcache(pte_t pte) { return pte; }
173*4882a593Smuzhiyun
174*4882a593Smuzhiyun extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
175*4882a593Smuzhiyun extern pgd_t kernel_pg_dir[PTRS_PER_PGD];
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun /* Macros to (de)construct the fake PTEs representing swap pages. */
178*4882a593Smuzhiyun #define __swp_type(x) ((x).val & 0x7F)
179*4882a593Smuzhiyun #define __swp_offset(x) (((x).val) >> 7)
180*4882a593Smuzhiyun #define __swp_entry(type,offset) ((swp_entry_t) { ((type) | ((offset) << 7)) })
181*4882a593Smuzhiyun #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
182*4882a593Smuzhiyun #define __swp_entry_to_pte(x) ((pte_t) { (x).val })
183*4882a593Smuzhiyun
184*4882a593Smuzhiyun #endif /* !__ASSEMBLY__ */
185*4882a593Smuzhiyun #endif /* !_SUN3_PGTABLE_H */
186