GNU Linux-libre 6.1.90-gnu
[releases.git] / arch / m68k / include / asm / mcf_pgtable.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _MCF_PGTABLE_H
3 #define _MCF_PGTABLE_H
4
5 #include <asm/mcfmmu.h>
6 #include <asm/page.h>
7
8 /*
9  * MMUDR bits, in proper place. We write these directly into the MMUDR
10  * after masking from the pte.
11  */
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 */
19
20 #define CF_CACHEMASK            (~MMUDR_CM_CCB)
21 #define CF_PAGE_MMUDR_MASK      0x000000fe
22
23 #define _PAGE_NOCACHE030        CF_PAGE_NOCACHE
24
25 /*
26  * MMUTR bits, need shifting down.
27  */
28 #define CF_PAGE_MMUTR_MASK      0x00000c00
29 #define CF_PAGE_MMUTR_SHIFT     10
30
31 #define CF_PAGE_VALID           (MMUTR_V << CF_PAGE_MMUTR_SHIFT)
32 #define CF_PAGE_SHARED          (MMUTR_SG << CF_PAGE_MMUTR_SHIFT)
33
34 /*
35  * Fake bits, not implemented in CF, will get masked out before
36  * hitting hardware.
37  */
38 #define CF_PAGE_DIRTY           0x00000001
39 #define CF_PAGE_ACCESSED        0x00001000
40
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 */
48
49 /*
50  * Externally used page protection values.
51  */
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 \
56                                 | CF_PAGE_WRITABLE \
57                                 | CF_PAGE_SYSTEM \
58                                 | CF_PAGE_SHARED)
59
60 /*
61  * Compound page protection values.
62  */
63 #define PAGE_NONE       __pgprot(CF_PAGE_VALID \
64                                  | CF_PAGE_ACCESSED)
65
66 #define PAGE_SHARED     __pgprot(CF_PAGE_VALID \
67                                  | CF_PAGE_ACCESSED \
68                                  | CF_PAGE_SHARED)
69
70 #define PAGE_INIT       __pgprot(CF_PAGE_VALID \
71                                  | CF_PAGE_READABLE \
72                                  | CF_PAGE_WRITABLE \
73                                  | CF_PAGE_EXEC \
74                                  | CF_PAGE_SYSTEM)
75
76 #define PAGE_KERNEL     __pgprot(CF_PAGE_VALID \
77                                  | CF_PAGE_ACCESSED \
78                                  | CF_PAGE_READABLE \
79                                  | CF_PAGE_WRITABLE \
80                                  | CF_PAGE_EXEC \
81                                  | CF_PAGE_SYSTEM \
82                                  | CF_PAGE_SHARED)
83
84 #define PAGE_COPY       __pgprot(CF_PAGE_VALID \
85                                  | CF_PAGE_ACCESSED \
86                                  | CF_PAGE_READABLE \
87                                  | CF_PAGE_DIRTY)
88
89 #define PTE_MASK        PAGE_MASK
90 #define CF_PAGE_CHG_MASK (PTE_MASK | CF_PAGE_ACCESSED | CF_PAGE_DIRTY)
91
92 #ifndef __ASSEMBLY__
93
94 #define pmd_pgtable(pmd) pfn_to_virt(pmd_val(pmd) >> PAGE_SHIFT)
95
96 /*
97  * Conversion functions: convert a page and protection to a page entry,
98  * and a page entry and page directory to the page they refer to.
99  */
100 #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
101
102 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
103 {
104         pte_val(pte) = (pte_val(pte) & CF_PAGE_CHG_MASK) | pgprot_val(newprot);
105         return pte;
106 }
107
108 #define pmd_set(pmdp, ptep) do {} while (0)
109
110 static inline void pgd_set(pgd_t *pgdp, pmd_t *pmdp)
111 {
112         pgd_val(*pgdp) = virt_to_phys(pmdp);
113 }
114
115 #define __pte_page(pte) ((unsigned long) (pte_val(pte) & PAGE_MASK))
116 #define pmd_page_vaddr(pmd)     ((unsigned long) (pmd_val(pmd)))
117
118 static inline int pte_none(pte_t pte)
119 {
120         return !pte_val(pte);
121 }
122
123 static inline int pte_present(pte_t pte)
124 {
125         return pte_val(pte) & CF_PAGE_VALID;
126 }
127
128 static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
129         pte_t *ptep)
130 {
131         pte_val(*ptep) = 0;
132 }
133
134 #define pte_pagenr(pte) ((__pte_page(pte) - PAGE_OFFSET) >> PAGE_SHIFT)
135 #define pte_page(pte)   virt_to_page(__pte_page(pte))
136
137 static inline int pmd_none2(pmd_t *pmd) { return !pmd_val(*pmd); }
138 #define pmd_none(pmd) pmd_none2(&(pmd))
139 static inline int pmd_bad2(pmd_t *pmd) { return 0; }
140 #define pmd_bad(pmd) pmd_bad2(&(pmd))
141 #define pmd_present(pmd) (!pmd_none2(&(pmd)))
142 static inline void pmd_clear(pmd_t *pmdp) { pmd_val(*pmdp) = 0; }
143
144 #define pte_ERROR(e) \
145         printk(KERN_ERR "%s:%d: bad pte %08lx.\n",      \
146         __FILE__, __LINE__, pte_val(e))
147 #define pgd_ERROR(e) \
148         printk(KERN_ERR "%s:%d: bad pgd %08lx.\n",      \
149         __FILE__, __LINE__, pgd_val(e))
150
151 /*
152  * The following only work if pte_present() is true.
153  * Undefined behaviour if not...
154  * [we have the full set here even if they don't change from m68k]
155  */
156 static inline int pte_read(pte_t pte)
157 {
158         return pte_val(pte) & CF_PAGE_READABLE;
159 }
160
161 static inline int pte_write(pte_t pte)
162 {
163         return pte_val(pte) & CF_PAGE_WRITABLE;
164 }
165
166 static inline int pte_exec(pte_t pte)
167 {
168         return pte_val(pte) & CF_PAGE_EXEC;
169 }
170
171 static inline int pte_dirty(pte_t pte)
172 {
173         return pte_val(pte) & CF_PAGE_DIRTY;
174 }
175
176 static inline int pte_young(pte_t pte)
177 {
178         return pte_val(pte) & CF_PAGE_ACCESSED;
179 }
180
181 static inline pte_t pte_wrprotect(pte_t pte)
182 {
183         pte_val(pte) &= ~CF_PAGE_WRITABLE;
184         return pte;
185 }
186
187 static inline pte_t pte_rdprotect(pte_t pte)
188 {
189         pte_val(pte) &= ~CF_PAGE_READABLE;
190         return pte;
191 }
192
193 static inline pte_t pte_exprotect(pte_t pte)
194 {
195         pte_val(pte) &= ~CF_PAGE_EXEC;
196         return pte;
197 }
198
199 static inline pte_t pte_mkclean(pte_t pte)
200 {
201         pte_val(pte) &= ~CF_PAGE_DIRTY;
202         return pte;
203 }
204
205 static inline pte_t pte_mkold(pte_t pte)
206 {
207         pte_val(pte) &= ~CF_PAGE_ACCESSED;
208         return pte;
209 }
210
211 static inline pte_t pte_mkwrite(pte_t pte)
212 {
213         pte_val(pte) |= CF_PAGE_WRITABLE;
214         return pte;
215 }
216
217 static inline pte_t pte_mkread(pte_t pte)
218 {
219         pte_val(pte) |= CF_PAGE_READABLE;
220         return pte;
221 }
222
223 static inline pte_t pte_mkexec(pte_t pte)
224 {
225         pte_val(pte) |= CF_PAGE_EXEC;
226         return pte;
227 }
228
229 static inline pte_t pte_mkdirty(pte_t pte)
230 {
231         pte_val(pte) |= CF_PAGE_DIRTY;
232         return pte;
233 }
234
235 static inline pte_t pte_mkyoung(pte_t pte)
236 {
237         pte_val(pte) |= CF_PAGE_ACCESSED;
238         return pte;
239 }
240
241 static inline pte_t pte_mknocache(pte_t pte)
242 {
243         pte_val(pte) |= 0x80 | (pte_val(pte) & ~0x40);
244         return pte;
245 }
246
247 static inline pte_t pte_mkcache(pte_t pte)
248 {
249         pte_val(pte) &= ~CF_PAGE_NOCACHE;
250         return pte;
251 }
252
253 #define swapper_pg_dir kernel_pg_dir
254 extern pgd_t kernel_pg_dir[PTRS_PER_PGD];
255
256 /*
257  * Encode and de-code a swap entry (must be !pte_none(e) && !pte_present(e))
258  */
259 #define __swp_type(x)           ((x).val & 0xFF)
260 #define __swp_offset(x)         ((x).val >> 11)
261 #define __swp_entry(typ, off)   ((swp_entry_t) { (typ) | \
262                                         (off << 11) })
263 #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
264 #define __swp_entry_to_pte(x)   (__pte((x).val))
265
266 #define pmd_pfn(pmd)            (pmd_val(pmd) >> PAGE_SHIFT)
267 #define pmd_page(pmd)           (pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT))
268
269 #define pfn_pte(pfn, prot)      __pte(((pfn) << PAGE_SHIFT) | pgprot_val(prot))
270 #define pte_pfn(pte)            (pte_val(pte) >> PAGE_SHIFT)
271
272 #endif  /* !__ASSEMBLY__ */
273 #endif  /* _MCF_PGTABLE_H */