~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/unicore32/include/asm/pgtable.h

Version: ~ [ linux-5.9-rc6 ] ~ [ linux-5.8.10 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.66 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.146 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.198 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.236 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.236 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0-only */
  2 /*
  3  * linux/arch/unicore32/include/asm/pgtable.h
  4  *
  5  * Code specific to PKUnity SoC and UniCore ISA
  6  *
  7  * Copyright (C) 2001-2010 GUAN Xue-tao
  8  */
  9 #ifndef __UNICORE_PGTABLE_H__
 10 #define __UNICORE_PGTABLE_H__
 11 
 12 #define __ARCH_USE_5LEVEL_HACK
 13 #include <asm-generic/pgtable-nopmd.h>
 14 #include <asm/cpu-single.h>
 15 
 16 #include <asm/memory.h>
 17 #include <asm/pgtable-hwdef.h>
 18 
 19 /*
 20  * Just any arbitrary offset to the start of the vmalloc VM area: the
 21  * current 8MB value just means that there will be a 8MB "hole" after the
 22  * physical memory until the kernel virtual memory starts.  That means that
 23  * any out-of-bounds memory accesses will hopefully be caught.
 24  * The vmalloc() routines leaves a hole of 4kB between each vmalloced
 25  * area for the same reason. ;)
 26  *
 27  * Note that platforms may override VMALLOC_START, but they must provide
 28  * VMALLOC_END.  VMALLOC_END defines the (exclusive) limit of this space,
 29  * which may not overlap IO space.
 30  */
 31 #ifndef VMALLOC_START
 32 #define VMALLOC_OFFSET          SZ_8M
 33 #define VMALLOC_START           (((unsigned long)high_memory + VMALLOC_OFFSET) \
 34                                         & ~(VMALLOC_OFFSET-1))
 35 #define VMALLOC_END             (0xff000000UL)
 36 #endif
 37 
 38 #define PTRS_PER_PTE            1024
 39 #define PTRS_PER_PGD            1024
 40 
 41 /*
 42  * PGDIR_SHIFT determines what a third-level page table entry can map
 43  */
 44 #define PGDIR_SHIFT             22
 45 
 46 #ifndef __ASSEMBLY__
 47 extern void __pte_error(const char *file, int line, unsigned long val);
 48 extern void __pgd_error(const char *file, int line, unsigned long val);
 49 
 50 #define pte_ERROR(pte)          __pte_error(__FILE__, __LINE__, pte_val(pte))
 51 #define pgd_ERROR(pgd)          __pgd_error(__FILE__, __LINE__, pgd_val(pgd))
 52 #endif /* !__ASSEMBLY__ */
 53 
 54 #define PGDIR_SIZE              (1UL << PGDIR_SHIFT)
 55 #define PGDIR_MASK              (~(PGDIR_SIZE-1))
 56 
 57 /*
 58  * This is the lowest virtual address we can permit any user space
 59  * mapping to be mapped at.  This is particularly important for
 60  * non-high vector CPUs.
 61  */
 62 #define FIRST_USER_ADDRESS      PAGE_SIZE
 63 
 64 #define FIRST_USER_PGD_NR       1
 65 #define USER_PTRS_PER_PGD       ((TASK_SIZE/PGDIR_SIZE) - FIRST_USER_PGD_NR)
 66 
 67 /*
 68  * section address mask and size definitions.
 69  */
 70 #define SECTION_SHIFT           22
 71 #define SECTION_SIZE            (1UL << SECTION_SHIFT)
 72 #define SECTION_MASK            (~(SECTION_SIZE-1))
 73 
 74 #ifndef __ASSEMBLY__
 75 
 76 /*
 77  * The pgprot_* and protection_map entries will be fixed up in runtime
 78  * to include the cachable bits based on memory policy, as well as any
 79  * architecture dependent bits.
 80  */
 81 #define _PTE_DEFAULT            (PTE_PRESENT | PTE_YOUNG | PTE_CACHEABLE)
 82 
 83 extern pgprot_t pgprot_user;
 84 extern pgprot_t pgprot_kernel;
 85 
 86 #define PAGE_NONE               pgprot_user
 87 #define PAGE_SHARED             __pgprot(pgprot_val(pgprot_user | PTE_READ \
 88                                                                 | PTE_WRITE))
 89 #define PAGE_SHARED_EXEC        __pgprot(pgprot_val(pgprot_user | PTE_READ \
 90                                                                 | PTE_WRITE \
 91                                                                 | PTE_EXEC))
 92 #define PAGE_COPY               __pgprot(pgprot_val(pgprot_user | PTE_READ)
 93 #define PAGE_COPY_EXEC          __pgprot(pgprot_val(pgprot_user | PTE_READ \
 94                                                                 | PTE_EXEC))
 95 #define PAGE_READONLY           __pgprot(pgprot_val(pgprot_user | PTE_READ))
 96 #define PAGE_READONLY_EXEC      __pgprot(pgprot_val(pgprot_user | PTE_READ \
 97                                                                 | PTE_EXEC))
 98 #define PAGE_KERNEL             pgprot_kernel
 99 #define PAGE_KERNEL_EXEC        __pgprot(pgprot_val(pgprot_kernel | PTE_EXEC))
100 
101 #define __PAGE_NONE             __pgprot(_PTE_DEFAULT)
102 #define __PAGE_SHARED           __pgprot(_PTE_DEFAULT | PTE_READ \
103                                                         | PTE_WRITE)
104 #define __PAGE_SHARED_EXEC      __pgprot(_PTE_DEFAULT | PTE_READ \
105                                                         | PTE_WRITE \
106                                                         | PTE_EXEC)
107 #define __PAGE_COPY             __pgprot(_PTE_DEFAULT | PTE_READ)
108 #define __PAGE_COPY_EXEC        __pgprot(_PTE_DEFAULT | PTE_READ \
109                                                         | PTE_EXEC)
110 #define __PAGE_READONLY         __pgprot(_PTE_DEFAULT | PTE_READ)
111 #define __PAGE_READONLY_EXEC    __pgprot(_PTE_DEFAULT | PTE_READ \
112                                                         | PTE_EXEC)
113 
114 #endif /* __ASSEMBLY__ */
115 
116 /*
117  * The table below defines the page protection levels that we insert into our
118  * Linux page table version.  These get translated into the best that the
119  * architecture can perform.  Note that on UniCore hardware:
120  *  1) We cannot do execute protection
121  *  2) If we could do execute protection, then read is implied
122  *  3) write implies read permissions
123  */
124 #define __P000  __PAGE_NONE
125 #define __P001  __PAGE_READONLY
126 #define __P010  __PAGE_COPY
127 #define __P011  __PAGE_COPY
128 #define __P100  __PAGE_READONLY_EXEC
129 #define __P101  __PAGE_READONLY_EXEC
130 #define __P110  __PAGE_COPY_EXEC
131 #define __P111  __PAGE_COPY_EXEC
132 
133 #define __S000  __PAGE_NONE
134 #define __S001  __PAGE_READONLY
135 #define __S010  __PAGE_SHARED
136 #define __S011  __PAGE_SHARED
137 #define __S100  __PAGE_READONLY_EXEC
138 #define __S101  __PAGE_READONLY_EXEC
139 #define __S110  __PAGE_SHARED_EXEC
140 #define __S111  __PAGE_SHARED_EXEC
141 
142 #ifndef __ASSEMBLY__
143 /*
144  * ZERO_PAGE is a global shared page that is always zero: used
145  * for zero-mapped memory areas etc..
146  */
147 extern struct page *empty_zero_page;
148 #define ZERO_PAGE(vaddr)                (empty_zero_page)
149 
150 #define pte_pfn(pte)                    (pte_val(pte) >> PAGE_SHIFT)
151 #define pfn_pte(pfn, prot)              (__pte(((pfn) << PAGE_SHIFT) \
152                                                 | pgprot_val(prot)))
153 
154 #define pte_none(pte)                   (!pte_val(pte))
155 #define pte_clear(mm, addr, ptep)       set_pte(ptep, __pte(0))
156 #define pte_page(pte)                   (pfn_to_page(pte_pfn(pte)))
157 #define pte_offset_kernel(dir, addr)    (pmd_page_vaddr(*(dir)) \
158                                                 + __pte_index(addr))
159 
160 #define pte_offset_map(dir, addr)       (pmd_page_vaddr(*(dir)) \
161                                                 + __pte_index(addr))
162 #define pte_unmap(pte)                  do { } while (0)
163 
164 #define set_pte(ptep, pte)      cpu_set_pte(ptep, pte)
165 
166 #define set_pte_at(mm, addr, ptep, pteval)      \
167         do {                                    \
168                 set_pte(ptep, pteval);          \
169         } while (0)
170 
171 /*
172  * The following only work if pte_present() is true.
173  * Undefined behaviour if not..
174  */
175 #define pte_present(pte)        (pte_val(pte) & PTE_PRESENT)
176 #define pte_write(pte)          (pte_val(pte) & PTE_WRITE)
177 #define pte_dirty(pte)          (pte_val(pte) & PTE_DIRTY)
178 #define pte_young(pte)          (pte_val(pte) & PTE_YOUNG)
179 #define pte_exec(pte)           (pte_val(pte) & PTE_EXEC)
180 #define pte_special(pte)        (0)
181 
182 #define PTE_BIT_FUNC(fn, op) \
183 static inline pte_t pte_##fn(pte_t pte) { pte_val(pte) op; return pte; }
184 
185 PTE_BIT_FUNC(wrprotect, &= ~PTE_WRITE);
186 PTE_BIT_FUNC(mkwrite,   |= PTE_WRITE);
187 PTE_BIT_FUNC(mkclean,   &= ~PTE_DIRTY);
188 PTE_BIT_FUNC(mkdirty,   |= PTE_DIRTY);
189 PTE_BIT_FUNC(mkold,     &= ~PTE_YOUNG);
190 PTE_BIT_FUNC(mkyoung,   |= PTE_YOUNG);
191 
192 static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
193 
194 /*
195  * Mark the prot value as uncacheable.
196  */
197 #define pgprot_noncached(prot)          \
198         __pgprot(pgprot_val(prot) & ~PTE_CACHEABLE)
199 #define pgprot_writecombine(prot)       \
200         __pgprot(pgprot_val(prot) & ~PTE_CACHEABLE)
201 #define pgprot_dmacoherent(prot)        \
202         __pgprot(pgprot_val(prot) & ~PTE_CACHEABLE)
203 
204 #define pmd_none(pmd)           (!pmd_val(pmd))
205 #define pmd_present(pmd)        (pmd_val(pmd) & PMD_PRESENT)
206 #define pmd_bad(pmd)            (((pmd_val(pmd) &               \
207                                 (PMD_PRESENT | PMD_TYPE_MASK))  \
208                                 != (PMD_PRESENT | PMD_TYPE_TABLE)))
209 
210 #define set_pmd(pmdpd, pmdval)          \
211         do {                            \
212                 *(pmdpd) = pmdval;      \
213         } while (0)
214 
215 #define pmd_clear(pmdp)                 \
216         do {                            \
217                 set_pmd(pmdp, __pmd(0));\
218                 clean_pmd_entry(pmdp);  \
219         } while (0)
220 
221 #define pmd_page_vaddr(pmd) ((pte_t *)__va(pmd_val(pmd) & PAGE_MASK))
222 #define pmd_page(pmd)           pfn_to_page(__phys_to_pfn(pmd_val(pmd)))
223 
224 /*
225  * Conversion functions: convert a page and protection to a page entry,
226  * and a page entry and page directory to the page they refer to.
227  */
228 #define mk_pte(page, prot)      pfn_pte(page_to_pfn(page), prot)
229 
230 /* to find an entry in a page-table-directory */
231 #define pgd_index(addr)         ((addr) >> PGDIR_SHIFT)
232 
233 #define pgd_offset(mm, addr)    ((mm)->pgd+pgd_index(addr))
234 
235 /* to find an entry in a kernel page-table-directory */
236 #define pgd_offset_k(addr)      pgd_offset(&init_mm, addr)
237 
238 /* Find an entry in the third-level page table.. */
239 #define __pte_index(addr)       (((addr) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
240 
241 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
242 {
243         const unsigned long mask = PTE_EXEC | PTE_WRITE | PTE_READ;
244         pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
245         return pte;
246 }
247 
248 extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
249 
250 /*
251  * Encode and decode a swap entry.  Swap entries are stored in the Linux
252  * page tables as follows:
253  *
254  *   3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
255  *   1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
256  *   <--------------- offset --------------> <--- type --> 0 0 0 0 0
257  *
258  * This gives us up to 127 swap files and 32GB per swap file.  Note that
259  * the offset field is always non-zero.
260  */
261 #define __SWP_TYPE_SHIFT        5
262 #define __SWP_TYPE_BITS         7
263 #define __SWP_TYPE_MASK         ((1 << __SWP_TYPE_BITS) - 1)
264 #define __SWP_OFFSET_SHIFT      (__SWP_TYPE_BITS + __SWP_TYPE_SHIFT)
265 
266 #define __swp_type(x)           (((x).val >> __SWP_TYPE_SHIFT)          \
267                                 & __SWP_TYPE_MASK)
268 #define __swp_offset(x)         ((x).val >> __SWP_OFFSET_SHIFT)
269 #define __swp_entry(type, offset) ((swp_entry_t) {                      \
270                                 ((type) << __SWP_TYPE_SHIFT) |          \
271                                 ((offset) << __SWP_OFFSET_SHIFT) })
272 
273 #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
274 #define __swp_entry_to_pte(swp) ((pte_t) { (swp).val })
275 
276 /*
277  * It is an error for the kernel to have more swap files than we can
278  * encode in the PTEs.  This ensures that we know when MAX_SWAPFILES
279  * is increased beyond what we presently support.
280  */
281 #define MAX_SWAPFILES_CHECK()   \
282         BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > __SWP_TYPE_BITS)
283 
284 /* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
285 /* FIXME: this is not correct */
286 #define kern_addr_valid(addr)   (1)
287 
288 #include <asm-generic/pgtable.h>
289 
290 #define pgtable_cache_init() do { } while (0)
291 
292 #endif /* !__ASSEMBLY__ */
293 
294 #endif /* __UNICORE_PGTABLE_H__ */
295 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp