xref: /OK3568_Linux_fs/kernel/arch/m68k/include/asm/motorola_pgtable.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef _MOTOROLA_PGTABLE_H
3*4882a593Smuzhiyun #define _MOTOROLA_PGTABLE_H
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun 
6*4882a593Smuzhiyun /*
7*4882a593Smuzhiyun  * Definitions for MMU descriptors
8*4882a593Smuzhiyun  */
9*4882a593Smuzhiyun #define _PAGE_PRESENT	0x001
10*4882a593Smuzhiyun #define _PAGE_SHORT	0x002
11*4882a593Smuzhiyun #define _PAGE_RONLY	0x004
12*4882a593Smuzhiyun #define _PAGE_READWRITE	0x000
13*4882a593Smuzhiyun #define _PAGE_ACCESSED	0x008
14*4882a593Smuzhiyun #define _PAGE_DIRTY	0x010
15*4882a593Smuzhiyun #define _PAGE_SUPER	0x080	/* 68040 supervisor only */
16*4882a593Smuzhiyun #define _PAGE_GLOBAL040	0x400	/* 68040 global bit, used for kva descs */
17*4882a593Smuzhiyun #define _PAGE_NOCACHE030 0x040	/* 68030 no-cache mode */
18*4882a593Smuzhiyun #define _PAGE_NOCACHE	0x060	/* 68040 cache mode, non-serialized */
19*4882a593Smuzhiyun #define _PAGE_NOCACHE_S	0x040	/* 68040 no-cache mode, serialized */
20*4882a593Smuzhiyun #define _PAGE_CACHE040	0x020	/* 68040 cache mode, cachable, copyback */
21*4882a593Smuzhiyun #define _PAGE_CACHE040W	0x000	/* 68040 cache mode, cachable, write-through */
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun #define _DESCTYPE_MASK	0x003
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun #define _CACHEMASK040	(~0x060)
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun /*
28*4882a593Smuzhiyun  * Currently set to the minimum alignment of table pointers (256 bytes).
29*4882a593Smuzhiyun  * The hardware only uses the low 4 bits for state:
30*4882a593Smuzhiyun  *
31*4882a593Smuzhiyun  *    3 - Used
32*4882a593Smuzhiyun  *    2 - Write Protected
33*4882a593Smuzhiyun  *  0,1 - Descriptor Type
34*4882a593Smuzhiyun  *
35*4882a593Smuzhiyun  * and has the rest of the bits reserved.
36*4882a593Smuzhiyun  */
37*4882a593Smuzhiyun #define _TABLE_MASK	(0xffffff00)
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun #define _PAGE_TABLE	(_PAGE_SHORT)
40*4882a593Smuzhiyun #define _PAGE_CHG_MASK  (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_NOCACHE)
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun #define _PAGE_PROTNONE	0x004
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun #ifndef __ASSEMBLY__
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun /* This is the cache mode to be used for pages containing page descriptors for
47*4882a593Smuzhiyun  * processors >= '040. It is in pte_mknocache(), and the variable is defined
48*4882a593Smuzhiyun  * and initialized in head.S */
49*4882a593Smuzhiyun extern int m68k_pgtable_cachemode;
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun /* This is the cache mode for normal pages, for supervisor access on
52*4882a593Smuzhiyun  * processors >= '040. It is used in pte_mkcache(), and the variable is
53*4882a593Smuzhiyun  * defined and initialized in head.S */
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun #if defined(CPU_M68060_ONLY) && defined(CONFIG_060_WRITETHROUGH)
56*4882a593Smuzhiyun #define m68k_supervisor_cachemode _PAGE_CACHE040W
57*4882a593Smuzhiyun #elif defined(CPU_M68040_OR_M68060_ONLY)
58*4882a593Smuzhiyun #define m68k_supervisor_cachemode _PAGE_CACHE040
59*4882a593Smuzhiyun #elif defined(CPU_M68020_OR_M68030_ONLY)
60*4882a593Smuzhiyun #define m68k_supervisor_cachemode 0
61*4882a593Smuzhiyun #else
62*4882a593Smuzhiyun extern int m68k_supervisor_cachemode;
63*4882a593Smuzhiyun #endif
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun #if defined(CPU_M68040_OR_M68060_ONLY)
66*4882a593Smuzhiyun #define mm_cachebits _PAGE_CACHE040
67*4882a593Smuzhiyun #elif defined(CPU_M68020_OR_M68030_ONLY)
68*4882a593Smuzhiyun #define mm_cachebits 0
69*4882a593Smuzhiyun #else
70*4882a593Smuzhiyun extern unsigned long mm_cachebits;
71*4882a593Smuzhiyun #endif
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun #define PAGE_NONE	__pgprot(_PAGE_PROTNONE | _PAGE_ACCESSED | mm_cachebits)
74*4882a593Smuzhiyun #define PAGE_SHARED	__pgprot(_PAGE_PRESENT | _PAGE_ACCESSED | mm_cachebits)
75*4882a593Smuzhiyun #define PAGE_COPY	__pgprot(_PAGE_PRESENT | _PAGE_RONLY | _PAGE_ACCESSED | mm_cachebits)
76*4882a593Smuzhiyun #define PAGE_READONLY	__pgprot(_PAGE_PRESENT | _PAGE_RONLY | _PAGE_ACCESSED | mm_cachebits)
77*4882a593Smuzhiyun #define PAGE_KERNEL	__pgprot(_PAGE_PRESENT | _PAGE_DIRTY | _PAGE_ACCESSED | mm_cachebits)
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun /* Alternate definitions that are compile time constants, for
80*4882a593Smuzhiyun    initializing protection_map.  The cachebits are fixed later.  */
81*4882a593Smuzhiyun #define PAGE_NONE_C	__pgprot(_PAGE_PROTNONE | _PAGE_ACCESSED)
82*4882a593Smuzhiyun #define PAGE_SHARED_C	__pgprot(_PAGE_PRESENT | _PAGE_ACCESSED)
83*4882a593Smuzhiyun #define PAGE_COPY_C	__pgprot(_PAGE_PRESENT | _PAGE_RONLY | _PAGE_ACCESSED)
84*4882a593Smuzhiyun #define PAGE_READONLY_C	__pgprot(_PAGE_PRESENT | _PAGE_RONLY | _PAGE_ACCESSED)
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun /*
87*4882a593Smuzhiyun  * The m68k can't do page protection for execute, and considers that the same are read.
88*4882a593Smuzhiyun  * Also, write permissions imply read permissions. This is the closest we can get..
89*4882a593Smuzhiyun  */
90*4882a593Smuzhiyun #define __P000	PAGE_NONE_C
91*4882a593Smuzhiyun #define __P001	PAGE_READONLY_C
92*4882a593Smuzhiyun #define __P010	PAGE_COPY_C
93*4882a593Smuzhiyun #define __P011	PAGE_COPY_C
94*4882a593Smuzhiyun #define __P100	PAGE_READONLY_C
95*4882a593Smuzhiyun #define __P101	PAGE_READONLY_C
96*4882a593Smuzhiyun #define __P110	PAGE_COPY_C
97*4882a593Smuzhiyun #define __P111	PAGE_COPY_C
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun #define __S000	PAGE_NONE_C
100*4882a593Smuzhiyun #define __S001	PAGE_READONLY_C
101*4882a593Smuzhiyun #define __S010	PAGE_SHARED_C
102*4882a593Smuzhiyun #define __S011	PAGE_SHARED_C
103*4882a593Smuzhiyun #define __S100	PAGE_READONLY_C
104*4882a593Smuzhiyun #define __S101	PAGE_READONLY_C
105*4882a593Smuzhiyun #define __S110	PAGE_SHARED_C
106*4882a593Smuzhiyun #define __S111	PAGE_SHARED_C
107*4882a593Smuzhiyun 
108*4882a593Smuzhiyun /*
109*4882a593Smuzhiyun  * Conversion functions: convert a page and protection to a page entry,
110*4882a593Smuzhiyun  * and a page entry and page directory to the page they refer to.
111*4882a593Smuzhiyun  */
112*4882a593Smuzhiyun #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
113*4882a593Smuzhiyun 
pte_modify(pte_t pte,pgprot_t newprot)114*4882a593Smuzhiyun static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
115*4882a593Smuzhiyun {
116*4882a593Smuzhiyun 	pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot);
117*4882a593Smuzhiyun 	return pte;
118*4882a593Smuzhiyun }
119*4882a593Smuzhiyun 
pmd_set(pmd_t * pmdp,pte_t * ptep)120*4882a593Smuzhiyun static inline void pmd_set(pmd_t *pmdp, pte_t *ptep)
121*4882a593Smuzhiyun {
122*4882a593Smuzhiyun 	pmd_val(*pmdp) = virt_to_phys(ptep) | _PAGE_TABLE | _PAGE_ACCESSED;
123*4882a593Smuzhiyun }
124*4882a593Smuzhiyun 
pud_set(pud_t * pudp,pmd_t * pmdp)125*4882a593Smuzhiyun static inline void pud_set(pud_t *pudp, pmd_t *pmdp)
126*4882a593Smuzhiyun {
127*4882a593Smuzhiyun 	pud_val(*pudp) = _PAGE_TABLE | _PAGE_ACCESSED | __pa(pmdp);
128*4882a593Smuzhiyun }
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun #define __pte_page(pte) ((unsigned long)__va(pte_val(pte) & PAGE_MASK))
131*4882a593Smuzhiyun #define pmd_page_vaddr(pmd) ((unsigned long)__va(pmd_val(pmd) & _TABLE_MASK))
132*4882a593Smuzhiyun #define pud_page_vaddr(pud) ((unsigned long)__va(pud_val(pud) & _TABLE_MASK))
133*4882a593Smuzhiyun 
134*4882a593Smuzhiyun 
135*4882a593Smuzhiyun #define pte_none(pte)		(!pte_val(pte))
136*4882a593Smuzhiyun #define pte_present(pte)	(pte_val(pte) & (_PAGE_PRESENT | _PAGE_PROTNONE))
137*4882a593Smuzhiyun #define pte_clear(mm,addr,ptep)		({ pte_val(*(ptep)) = 0; })
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun #define pte_page(pte)		virt_to_page(__va(pte_val(pte)))
140*4882a593Smuzhiyun #define pte_pfn(pte)		(pte_val(pte) >> PAGE_SHIFT)
141*4882a593Smuzhiyun #define pfn_pte(pfn, prot)	__pte(((pfn) << PAGE_SHIFT) | pgprot_val(prot))
142*4882a593Smuzhiyun 
143*4882a593Smuzhiyun #define pmd_none(pmd)		(!pmd_val(pmd))
144*4882a593Smuzhiyun #define pmd_bad(pmd)		((pmd_val(pmd) & _DESCTYPE_MASK) != _PAGE_TABLE)
145*4882a593Smuzhiyun #define pmd_present(pmd)	(pmd_val(pmd) & _PAGE_TABLE)
146*4882a593Smuzhiyun #define pmd_clear(pmdp)		({ pmd_val(*pmdp) = 0; })
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun /*
149*4882a593Smuzhiyun  * m68k does not have huge pages (020/030 actually could), but generic code
150*4882a593Smuzhiyun  * expects pmd_page() to exists, only to then DCE it all. Provide a dummy to
151*4882a593Smuzhiyun  * make the compiler happy.
152*4882a593Smuzhiyun  */
153*4882a593Smuzhiyun #define pmd_page(pmd)		NULL
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun 
156*4882a593Smuzhiyun #define pud_none(pud)		(!pud_val(pud))
157*4882a593Smuzhiyun #define pud_bad(pud)		((pud_val(pud) & _DESCTYPE_MASK) != _PAGE_TABLE)
158*4882a593Smuzhiyun #define pud_present(pud)	(pud_val(pud) & _PAGE_TABLE)
159*4882a593Smuzhiyun #define pud_clear(pudp)		({ pud_val(*pudp) = 0; })
160*4882a593Smuzhiyun #define pud_page(pud)		(mem_map + ((unsigned long)(__va(pud_val(pud)) - PAGE_OFFSET) >> PAGE_SHIFT))
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun #define pte_ERROR(e) \
163*4882a593Smuzhiyun 	printk("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, pte_val(e))
164*4882a593Smuzhiyun #define pmd_ERROR(e) \
165*4882a593Smuzhiyun 	printk("%s:%d: bad pmd %08lx.\n", __FILE__, __LINE__, pmd_val(e))
166*4882a593Smuzhiyun #define pgd_ERROR(e) \
167*4882a593Smuzhiyun 	printk("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e))
168*4882a593Smuzhiyun 
169*4882a593Smuzhiyun 
170*4882a593Smuzhiyun /*
171*4882a593Smuzhiyun  * The following only work if pte_present() is true.
172*4882a593Smuzhiyun  * Undefined behaviour if not..
173*4882a593Smuzhiyun  */
pte_write(pte_t pte)174*4882a593Smuzhiyun static inline int pte_write(pte_t pte)		{ return !(pte_val(pte) & _PAGE_RONLY); }
pte_dirty(pte_t pte)175*4882a593Smuzhiyun static inline int pte_dirty(pte_t pte)		{ return pte_val(pte) & _PAGE_DIRTY; }
pte_young(pte_t pte)176*4882a593Smuzhiyun static inline int pte_young(pte_t pte)		{ return pte_val(pte) & _PAGE_ACCESSED; }
177*4882a593Smuzhiyun 
pte_wrprotect(pte_t pte)178*4882a593Smuzhiyun static inline pte_t pte_wrprotect(pte_t pte)	{ pte_val(pte) |= _PAGE_RONLY; return pte; }
pte_mkclean(pte_t pte)179*4882a593Smuzhiyun static inline pte_t pte_mkclean(pte_t pte)	{ pte_val(pte) &= ~_PAGE_DIRTY; return pte; }
pte_mkold(pte_t pte)180*4882a593Smuzhiyun static inline pte_t pte_mkold(pte_t pte)	{ pte_val(pte) &= ~_PAGE_ACCESSED; return pte; }
pte_mkwrite(pte_t pte)181*4882a593Smuzhiyun static inline pte_t pte_mkwrite(pte_t pte)	{ pte_val(pte) &= ~_PAGE_RONLY; return pte; }
pte_mkdirty(pte_t pte)182*4882a593Smuzhiyun static inline pte_t pte_mkdirty(pte_t pte)	{ pte_val(pte) |= _PAGE_DIRTY; return pte; }
pte_mkyoung(pte_t pte)183*4882a593Smuzhiyun static inline pte_t pte_mkyoung(pte_t pte)	{ pte_val(pte) |= _PAGE_ACCESSED; return pte; }
pte_mknocache(pte_t pte)184*4882a593Smuzhiyun static inline pte_t pte_mknocache(pte_t pte)
185*4882a593Smuzhiyun {
186*4882a593Smuzhiyun 	pte_val(pte) = (pte_val(pte) & _CACHEMASK040) | m68k_pgtable_cachemode;
187*4882a593Smuzhiyun 	return pte;
188*4882a593Smuzhiyun }
pte_mkcache(pte_t pte)189*4882a593Smuzhiyun static inline pte_t pte_mkcache(pte_t pte)
190*4882a593Smuzhiyun {
191*4882a593Smuzhiyun 	pte_val(pte) = (pte_val(pte) & _CACHEMASK040) | m68k_supervisor_cachemode;
192*4882a593Smuzhiyun 	return pte;
193*4882a593Smuzhiyun }
194*4882a593Smuzhiyun 
195*4882a593Smuzhiyun #define swapper_pg_dir kernel_pg_dir
196*4882a593Smuzhiyun extern pgd_t kernel_pg_dir[128];
197*4882a593Smuzhiyun 
198*4882a593Smuzhiyun /* Encode and de-code a swap entry (must be !pte_none(e) && !pte_present(e)) */
199*4882a593Smuzhiyun #define __swp_type(x)		(((x).val >> 4) & 0xff)
200*4882a593Smuzhiyun #define __swp_offset(x)		((x).val >> 12)
201*4882a593Smuzhiyun #define __swp_entry(type, offset) ((swp_entry_t) { ((type) << 4) | ((offset) << 12) })
202*4882a593Smuzhiyun #define __pte_to_swp_entry(pte)	((swp_entry_t) { pte_val(pte) })
203*4882a593Smuzhiyun #define __swp_entry_to_pte(x)	((pte_t) { (x).val })
204*4882a593Smuzhiyun 
205*4882a593Smuzhiyun #endif	/* !__ASSEMBLY__ */
206*4882a593Smuzhiyun #endif /* _MOTOROLA_PGTABLE_H */
207