1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <asm/mcfmmu.h>
9 * MMUDR bits, in proper place. We write these directly into the MMUDR
10 * after masking from the pte.
12 #define CF_PAGE_LOCKED MMUDR_LK /* 0x00000002 */
13 #define CF_PAGE_EXEC MMUDR_X /* 0x00000004 */
14 #define CF_PAGE_WRITABLE MMUDR_W /* 0x00000008 */
15 #define CF_PAGE_READABLE MMUDR_R /* 0x00000010 */
16 #define CF_PAGE_SYSTEM MMUDR_SP /* 0x00000020 */
17 #define CF_PAGE_COPYBACK MMUDR_CM_CCB /* 0x00000040 */
18 #define CF_PAGE_NOCACHE MMUDR_CM_NCP /* 0x00000080 */
20 #define CF_CACHEMASK (~MMUDR_CM_CCB)
21 #define CF_PAGE_MMUDR_MASK 0x000000fe
23 #define _PAGE_NOCACHE030 CF_PAGE_NOCACHE
26 * MMUTR bits, need shifting down.
28 #define CF_PAGE_MMUTR_MASK 0x00000c00
29 #define CF_PAGE_MMUTR_SHIFT 10
31 #define CF_PAGE_VALID (MMUTR_V << CF_PAGE_MMUTR_SHIFT)
32 #define CF_PAGE_SHARED (MMUTR_SG << CF_PAGE_MMUTR_SHIFT)
35 * Fake bits, not implemented in CF, will get masked out before
38 #define CF_PAGE_DIRTY 0x00000001
39 #define CF_PAGE_ACCESSED 0x00001000
41 #define _PAGE_CACHE040 0x020 /* 68040 cache mode, cachable, copyback */
42 #define _PAGE_NOCACHE_S 0x040 /* 68040 no-cache mode, serialized */
43 #define _PAGE_NOCACHE 0x060 /* 68040 cache mode, non-serialized */
44 #define _PAGE_CACHE040W 0x000 /* 68040 cache mode, cachable, write-through */
45 #define _DESCTYPE_MASK 0x003
46 #define _CACHEMASK040 (~0x060)
47 #define _PAGE_GLOBAL040 0x400 /* 68040 global bit, used for kva descs */
50 * Externally used page protection values.
52 #define _PAGE_PRESENT (CF_PAGE_VALID)
53 #define _PAGE_ACCESSED (CF_PAGE_ACCESSED)
54 #define _PAGE_DIRTY (CF_PAGE_DIRTY)
55 #define _PAGE_READWRITE (CF_PAGE_READABLE \
61 * Compound page protection values.
63 #define PAGE_NONE __pgprot(CF_PAGE_VALID \
66 #define PAGE_SHARED __pgprot(CF_PAGE_VALID \
70 #define PAGE_INIT __pgprot(CF_PAGE_VALID \
76 #define PAGE_KERNEL __pgprot(CF_PAGE_VALID \
84 #define PAGE_COPY __pgprot(CF_PAGE_VALID \
90 * Page protections for initialising protection_map. See mm/mmap.c
91 * for use. In general, the bit positions are xwr, and P-items are
92 * private, the S-items are shared.
94 #define __P000 PAGE_NONE
95 #define __P001 __pgprot(CF_PAGE_VALID \
98 #define __P010 __pgprot(CF_PAGE_VALID \
101 #define __P011 __pgprot(CF_PAGE_VALID \
105 #define __P100 __pgprot(CF_PAGE_VALID \
108 #define __P101 __pgprot(CF_PAGE_VALID \
112 #define __P110 __pgprot(CF_PAGE_VALID \
116 #define __P111 __pgprot(CF_PAGE_VALID \
122 #define __S000 PAGE_NONE
123 #define __S001 __pgprot(CF_PAGE_VALID \
126 #define __S010 PAGE_SHARED
127 #define __S011 __pgprot(CF_PAGE_VALID \
131 #define __S100 __pgprot(CF_PAGE_VALID \
134 #define __S101 __pgprot(CF_PAGE_VALID \
138 #define __S110 __pgprot(CF_PAGE_VALID \
142 #define __S111 __pgprot(CF_PAGE_VALID \
148 #define PTE_MASK PAGE_MASK
149 #define CF_PAGE_CHG_MASK (PTE_MASK | CF_PAGE_ACCESSED | CF_PAGE_DIRTY)
154 * Conversion functions: convert a page and protection to a page entry,
155 * and a page entry and page directory to the page they refer to.
157 #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
159 static inline pte_t
pte_modify(pte_t pte
, pgprot_t newprot
)
161 pte_val(pte
) = (pte_val(pte
) & CF_PAGE_CHG_MASK
) | pgprot_val(newprot
);
165 #define pmd_set(pmdp, ptep) do {} while (0)
167 static inline void pgd_set(pgd_t
*pgdp
, pmd_t
*pmdp
)
169 pgd_val(*pgdp
) = virt_to_phys(pmdp
);
172 #define __pte_page(pte) ((unsigned long) (pte_val(pte) & PAGE_MASK))
173 #define __pmd_page(pmd) ((unsigned long) (pmd_val(pmd)))
175 static inline int pte_none(pte_t pte
)
177 return !pte_val(pte
);
180 static inline int pte_present(pte_t pte
)
182 return pte_val(pte
) & CF_PAGE_VALID
;
185 static inline void pte_clear(struct mm_struct
*mm
, unsigned long addr
,
191 #define pte_pagenr(pte) ((__pte_page(pte) - PAGE_OFFSET) >> PAGE_SHIFT)
192 #define pte_page(pte) virt_to_page(__pte_page(pte))
194 static inline int pmd_none2(pmd_t
*pmd
) { return !pmd_val(*pmd
); }
195 #define pmd_none(pmd) pmd_none2(&(pmd))
196 static inline int pmd_bad2(pmd_t
*pmd
) { return 0; }
197 #define pmd_bad(pmd) pmd_bad2(&(pmd))
198 #define pmd_present(pmd) (!pmd_none2(&(pmd)))
199 static inline void pmd_clear(pmd_t
*pmdp
) { pmd_val(*pmdp
) = 0; }
201 #define pte_ERROR(e) \
202 printk(KERN_ERR "%s:%d: bad pte %08lx.\n", \
203 __FILE__, __LINE__, pte_val(e))
204 #define pgd_ERROR(e) \
205 printk(KERN_ERR "%s:%d: bad pgd %08lx.\n", \
206 __FILE__, __LINE__, pgd_val(e))
209 * The following only work if pte_present() is true.
210 * Undefined behaviour if not...
211 * [we have the full set here even if they don't change from m68k]
213 static inline int pte_read(pte_t pte
)
215 return pte_val(pte
) & CF_PAGE_READABLE
;
218 static inline int pte_write(pte_t pte
)
220 return pte_val(pte
) & CF_PAGE_WRITABLE
;
223 static inline int pte_exec(pte_t pte
)
225 return pte_val(pte
) & CF_PAGE_EXEC
;
228 static inline int pte_dirty(pte_t pte
)
230 return pte_val(pte
) & CF_PAGE_DIRTY
;
233 static inline int pte_young(pte_t pte
)
235 return pte_val(pte
) & CF_PAGE_ACCESSED
;
238 static inline int pte_special(pte_t pte
)
243 static inline pte_t
pte_wrprotect(pte_t pte
)
245 pte_val(pte
) &= ~CF_PAGE_WRITABLE
;
249 static inline pte_t
pte_rdprotect(pte_t pte
)
251 pte_val(pte
) &= ~CF_PAGE_READABLE
;
255 static inline pte_t
pte_exprotect(pte_t pte
)
257 pte_val(pte
) &= ~CF_PAGE_EXEC
;
261 static inline pte_t
pte_mkclean(pte_t pte
)
263 pte_val(pte
) &= ~CF_PAGE_DIRTY
;
267 static inline pte_t
pte_mkold(pte_t pte
)
269 pte_val(pte
) &= ~CF_PAGE_ACCESSED
;
273 static inline pte_t
pte_mkwrite(pte_t pte
)
275 pte_val(pte
) |= CF_PAGE_WRITABLE
;
279 static inline pte_t
pte_mkread(pte_t pte
)
281 pte_val(pte
) |= CF_PAGE_READABLE
;
285 static inline pte_t
pte_mkexec(pte_t pte
)
287 pte_val(pte
) |= CF_PAGE_EXEC
;
291 static inline pte_t
pte_mkdirty(pte_t pte
)
293 pte_val(pte
) |= CF_PAGE_DIRTY
;
297 static inline pte_t
pte_mkyoung(pte_t pte
)
299 pte_val(pte
) |= CF_PAGE_ACCESSED
;
303 static inline pte_t
pte_mknocache(pte_t pte
)
305 pte_val(pte
) |= 0x80 | (pte_val(pte
) & ~0x40);
309 static inline pte_t
pte_mkcache(pte_t pte
)
311 pte_val(pte
) &= ~CF_PAGE_NOCACHE
;
315 static inline pte_t
pte_mkspecial(pte_t pte
)
320 #define swapper_pg_dir kernel_pg_dir
321 extern pgd_t kernel_pg_dir
[PTRS_PER_PGD
];
324 * Find an entry in a pagetable directory.
326 #define pgd_index(address) ((address) >> PGDIR_SHIFT)
327 #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
330 * Find an entry in a kernel pagetable directory.
332 #define pgd_offset_k(address) pgd_offset(&init_mm, address)
335 * Find an entry in the third-level pagetable.
337 #define __pte_offset(address) ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
338 #define pte_offset_kernel(dir, address) \
339 ((pte_t *) __pmd_page(*(dir)) + __pte_offset(address))
342 * Disable caching for page at given kernel virtual address.
344 static inline void nocache_page(void *vaddr
)
351 unsigned long addr
= (unsigned long) vaddr
;
353 dir
= pgd_offset_k(addr
);
354 p4dp
= p4d_offset(dir
, addr
);
355 pudp
= pud_offset(p4dp
, addr
);
356 pmdp
= pmd_offset(pudp
, addr
);
357 ptep
= pte_offset_kernel(pmdp
, addr
);
358 *ptep
= pte_mknocache(*ptep
);
362 * Enable caching for page at given kernel virtual address.
364 static inline void cache_page(void *vaddr
)
371 unsigned long addr
= (unsigned long) vaddr
;
373 dir
= pgd_offset_k(addr
);
374 p4dp
= p4d_offset(dir
, addr
);
375 pudp
= pud_offset(p4dp
, addr
);
376 pmdp
= pmd_offset(pudp
, addr
);
377 ptep
= pte_offset_kernel(pmdp
, addr
);
378 *ptep
= pte_mkcache(*ptep
);
382 * Encode and de-code a swap entry (must be !pte_none(e) && !pte_present(e))
384 #define __swp_type(x) ((x).val & 0xFF)
385 #define __swp_offset(x) ((x).val >> 11)
386 #define __swp_entry(typ, off) ((swp_entry_t) { (typ) | \
388 #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
389 #define __swp_entry_to_pte(x) (__pte((x).val))
391 #define pmd_page(pmd) (pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT))
393 #define pte_offset_map(pmdp, addr) ((pte_t *)__pmd_page(*pmdp) + \
395 #define pte_unmap(pte) ((void) 0)
396 #define pfn_pte(pfn, prot) __pte(((pfn) << PAGE_SHIFT) | pgprot_val(prot))
397 #define pte_pfn(pte) (pte_val(pte) >> PAGE_SHIFT)
399 #endif /* !__ASSEMBLY__ */
400 #endif /* _MCF_PGTABLE_H */