]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blame - arch/score/include/asm/pgtable.h
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[mirror_ubuntu-eoan-kernel.git] / arch / score / include / asm / pgtable.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
6bc9a396
CL
2#ifndef _ASM_SCORE_PGTABLE_H
3#define _ASM_SCORE_PGTABLE_H
4
5#include <linux/const.h>
9849a569 6#define __ARCH_USE_5LEVEL_HACK
6bc9a396
CL
7#include <asm-generic/pgtable-nopmd.h>
8
9#include <asm/fixmap.h>
10#include <asm/setup.h>
11#include <asm/pgtable-bits.h>
12
13extern void load_pgd(unsigned long pg_dir);
14extern pte_t invalid_pte_table[PAGE_SIZE/sizeof(pte_t)];
15
16/* PGDIR_SHIFT determines what a third-level page table entry can map */
17#define PGDIR_SHIFT 22
18#define PGDIR_SIZE (_AC(1, UL) << PGDIR_SHIFT)
19#define PGDIR_MASK (~(PGDIR_SIZE - 1))
20
21/*
22 * Entries per page directory level: we use two-level, so
23 * we don't really have any PUD/PMD directory physically.
24 */
25#define PGD_ORDER 0
26#define PTE_ORDER 0
27
28#define PTRS_PER_PGD 1024
29#define PTRS_PER_PTE 1024
30
31#define USER_PTRS_PER_PGD (0x80000000UL/PGDIR_SIZE)
d016bf7e 32#define FIRST_USER_ADDRESS 0UL
6bc9a396
CL
33
34#define VMALLOC_START (0xc0000000UL)
35
36#define PKMAP_BASE (0xfd000000UL)
37
38#define VMALLOC_END (FIXADDR_START - 2*PAGE_SIZE)
39
40#define pte_ERROR(e) \
41 printk(KERN_ERR "%s:%d: bad pte %08lx.\n", \
42 __FILE__, __LINE__, pte_val(e))
43#define pgd_ERROR(e) \
44 printk(KERN_ERR "%s:%d: bad pgd %08lx.\n", \
45 __FILE__, __LINE__, pgd_val(e))
46
47/*
48 * Empty pgd/pmd entries point to the invalid_pte_table.
49 */
50static inline int pmd_none(pmd_t pmd)
51{
52 return pmd_val(pmd) == (unsigned long) invalid_pte_table;
53}
54
55#define pmd_bad(pmd) (pmd_val(pmd) & ~PAGE_MASK)
56
57static inline int pmd_present(pmd_t pmd)
58{
59 return pmd_val(pmd) != (unsigned long) invalid_pte_table;
60}
61
62static inline void pmd_clear(pmd_t *pmdp)
63{
64 pmd_val(*pmdp) = ((unsigned long) invalid_pte_table);
65}
66
67#define pte_page(x) pfn_to_page(pte_pfn(x))
68#define pte_pfn(x) ((unsigned long)((x).pte >> PAGE_SHIFT))
69#define pfn_pte(pfn, prot) \
70 __pte(((unsigned long long)(pfn) << PAGE_SHIFT) | pgprot_val(prot))
71
72#define __pgd_offset(address) pgd_index(address)
73#define __pud_offset(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD-1))
74#define __pmd_offset(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))
75
76/* to find an entry in a kernel page-table-directory */
77#define pgd_offset_k(address) pgd_offset(&init_mm, address)
78#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
79
80/* to find an entry in a page-table-directory */
81#define pgd_offset(mm, addr) ((mm)->pgd + pgd_index(addr))
82
83/* Find an entry in the third-level page table.. */
84#define __pte_offset(address) \
85 (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
86#define pte_offset(dir, address) \
87 ((pte_t *) pmd_page_vaddr(*(dir)) + __pte_offset(address))
88#define pte_offset_kernel(dir, address) \
89 ((pte_t *) pmd_page_vaddr(*(dir)) + __pte_offset(address))
90
91#define pte_offset_map(dir, address) \
92 ((pte_t *)page_address(pmd_page(*(dir))) + __pte_offset(address))
6bc9a396 93#define pte_unmap(pte) ((void)(pte))
6bc9a396 94
6bc9a396
CL
95#define __pte_to_swp_entry(pte) \
96 ((swp_entry_t) { pte_val(pte)})
97#define __swp_entry_to_pte(x) ((pte_t) {(x).val})
98
ffa818b4
CL
99#define pmd_phys(pmd) __pa((void *)pmd_val(pmd))
100#define pmd_page(pmd) (pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT))
6bc9a396
CL
101#define mk_pte(page, prot) pfn_pte(page_to_pfn(page), prot)
102static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
103
104#define set_pte(pteptr, pteval) (*(pteptr) = pteval)
105#define set_pte_at(mm, addr, ptep, pteval) set_pte(ptep, pteval)
106#define pte_clear(mm, addr, xp) \
107 do { set_pte_at(mm, addr, xp, __pte(0)); } while (0)
108
0402c91a
CL
109/*
110 * The "pgd_xxx()" functions here are trivial for a folded two-level
111 * setup: the pgd is never bad, and a pmd always exists (as it's folded
112 * into the pgd entry)
113 */
114#define pgd_present(pgd) (1)
6bc9a396
CL
115#define pgd_none(pgd) (0)
116#define pgd_bad(pgd) (0)
0402c91a 117#define pgd_clear(pgdp) do { } while (0)
6bc9a396
CL
118
119#define kern_addr_valid(addr) (1)
6bc9a396
CL
120#define pmd_page_vaddr(pmd) pmd_val(pmd)
121
122#define pte_none(pte) (!(pte_val(pte) & ~_PAGE_GLOBAL))
123#define pte_present(pte) (pte_val(pte) & _PAGE_PRESENT)
124
0402c91a
CL
125#define PAGE_NONE __pgprot(_PAGE_PRESENT | _PAGE_CACHE)
126#define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \
127 _PAGE_CACHE)
128#define PAGE_COPY __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_CACHE)
129#define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_CACHE)
130#define PAGE_KERNEL __pgprot(_PAGE_PRESENT | __READABLE | __WRITEABLE | \
131 _PAGE_GLOBAL | _PAGE_CACHE)
132#define PAGE_KERNEL_UNCACHED __pgprot(_PAGE_PRESENT | __READABLE | \
133 __WRITEABLE | _PAGE_GLOBAL & ~_PAGE_CACHE)
134
135#define __P000 PAGE_NONE
136#define __P001 PAGE_READONLY
137#define __P010 PAGE_COPY
138#define __P011 PAGE_COPY
139#define __P100 PAGE_READONLY
140#define __P101 PAGE_READONLY
141#define __P110 PAGE_COPY
142#define __P111 PAGE_COPY
143
144#define __S000 PAGE_NONE
145#define __S001 PAGE_READONLY
146#define __S010 PAGE_SHARED
147#define __S011 PAGE_SHARED
148#define __S100 PAGE_READONLY
149#define __S101 PAGE_READONLY
150#define __S110 PAGE_SHARED
151#define __S111 PAGE_SHARED
6bc9a396 152
ffa818b4
CL
153#define pgprot_noncached pgprot_noncached
154
155static inline pgprot_t pgprot_noncached(pgprot_t _prot)
156{
157 unsigned long prot = pgprot_val(_prot);
158
159 prot = (prot & ~_CACHE_MASK);
160
161 return __pgprot(prot);
162}
6bc9a396 163
ffa818b4 164#define __swp_type(x) ((x).val & 0x1f)
917e401e
KS
165#define __swp_offset(x) ((x).val >> 10)
166#define __swp_entry(type, offset) ((swp_entry_t){(type) | ((offset) << 10)})
6bc9a396 167
ffa818b4
CL
168extern unsigned long empty_zero_page;
169extern unsigned long zero_page_mask;
6bc9a396 170
ffa818b4
CL
171#define ZERO_PAGE(vaddr) \
172 (virt_to_page((void *)(empty_zero_page + \
173 (((unsigned long)(vaddr)) & zero_page_mask))))
6bc9a396
CL
174
175#define pgtable_cache_init() do {} while (0)
176
177#define arch_enter_lazy_cpu_mode() do {} while (0)
178
179static inline int pte_write(pte_t pte)
180{
181 return pte_val(pte) & _PAGE_WRITE;
182}
183
184static inline int pte_dirty(pte_t pte)
185{
186 return pte_val(pte) & _PAGE_MODIFIED;
187}
188
189static inline int pte_young(pte_t pte)
190{
191 return pte_val(pte) & _PAGE_ACCESSED;
192}
193
6bc9a396
CL
194#define pte_special(pte) (0)
195
196static inline pte_t pte_wrprotect(pte_t pte)
197{
198 pte_val(pte) &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE);
199 return pte;
200}
201
202static inline pte_t pte_mkclean(pte_t pte)
203{
204 pte_val(pte) &= ~(_PAGE_MODIFIED|_PAGE_SILENT_WRITE);
205 return pte;
206}
207
208static inline pte_t pte_mkold(pte_t pte)
209{
210 pte_val(pte) &= ~(_PAGE_ACCESSED|_PAGE_SILENT_READ);
211 return pte;
212}
213
214static inline pte_t pte_mkwrite(pte_t pte)
215{
216 pte_val(pte) |= _PAGE_WRITE;
217 if (pte_val(pte) & _PAGE_MODIFIED)
218 pte_val(pte) |= _PAGE_SILENT_WRITE;
219 return pte;
220}
221
222static inline pte_t pte_mkdirty(pte_t pte)
223{
224 pte_val(pte) |= _PAGE_MODIFIED;
225 if (pte_val(pte) & _PAGE_WRITE)
226 pte_val(pte) |= _PAGE_SILENT_WRITE;
227 return pte;
228}
229
230static inline pte_t pte_mkyoung(pte_t pte)
231{
232 pte_val(pte) |= _PAGE_ACCESSED;
233 if (pte_val(pte) & _PAGE_READ)
234 pte_val(pte) |= _PAGE_SILENT_READ;
235 return pte;
236}
237
238#define set_pmd(pmdptr, pmdval) \
239 do { *(pmdptr) = (pmdval); } while (0)
240#define pte_present(pte) (pte_val(pte) & _PAGE_PRESENT)
241
242extern unsigned long pgd_current;
ffa818b4 243extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
6bc9a396
CL
244extern void paging_init(void);
245
246static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
247{
248 return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot));
249}
250
251extern void __update_tlb(struct vm_area_struct *vma,
252 unsigned long address, pte_t pte);
253extern void __update_cache(struct vm_area_struct *vma,
254 unsigned long address, pte_t pte);
255
256static inline void update_mmu_cache(struct vm_area_struct *vma,
4b3073e1 257 unsigned long address, pte_t *ptep)
6bc9a396 258{
4b3073e1 259 pte_t pte = *ptep;
6bc9a396
CL
260 __update_tlb(vma, address, pte);
261 __update_cache(vma, address, pte);
262}
263
264#ifndef __ASSEMBLY__
265#include <asm-generic/pgtable.h>
266
267void setup_memory(void);
268#endif /* __ASSEMBLY__ */
269
270#endif /* _ASM_SCORE_PGTABLE_H */