Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 
0003 #ifndef __ASM_CSKY_PGTABLE_H
0004 #define __ASM_CSKY_PGTABLE_H
0005 
0006 #include <asm/fixmap.h>
0007 #include <asm/memory.h>
0008 #include <asm/addrspace.h>
0009 #include <abi/pgtable-bits.h>
0010 #include <asm-generic/pgtable-nopmd.h>
0011 
0012 #define PGDIR_SHIFT     22
0013 #define PGDIR_SIZE      (1UL << PGDIR_SHIFT)
0014 #define PGDIR_MASK      (~(PGDIR_SIZE-1))
0015 
0016 #define USER_PTRS_PER_PGD   (PAGE_OFFSET/PGDIR_SIZE)
0017 
0018 /*
0019  * C-SKY is two-level paging structure:
0020  */
0021 
0022 #define PTRS_PER_PGD    (PAGE_SIZE / sizeof(pgd_t))
0023 #define PTRS_PER_PMD    1
0024 #define PTRS_PER_PTE    (PAGE_SIZE / sizeof(pte_t))
0025 
0026 #define pte_ERROR(e) \
0027     pr_err("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, (e).pte_low)
0028 #define pgd_ERROR(e) \
0029     pr_err("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e))
0030 
0031 #define pmd_pfn(pmd)    (pmd_phys(pmd) >> PAGE_SHIFT)
0032 #define pmd_page(pmd)   (pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT))
0033 #define pte_clear(mm, addr, ptep)   set_pte((ptep), \
0034     (((unsigned int) addr >= PAGE_OFFSET) ? __pte(_PAGE_GLOBAL) : __pte(0)))
0035 #define pte_none(pte)       (!(pte_val(pte) & ~_PAGE_GLOBAL))
0036 #define pte_present(pte)    (pte_val(pte) & _PAGE_PRESENT)
0037 #define pte_pfn(x)  ((unsigned long)((x).pte_low >> PAGE_SHIFT))
0038 #define pfn_pte(pfn, prot) __pte(((unsigned long long)(pfn) << PAGE_SHIFT) \
0039                 | pgprot_val(prot))
0040 
0041 #define __pte_to_swp_entry(pte)     ((swp_entry_t) { pte_val(pte) })
0042 #define __swp_entry_to_pte(x)       ((pte_t) { (x).val })
0043 
0044 #define pte_page(x)         pfn_to_page(pte_pfn(x))
0045 #define __mk_pte(page_nr, pgprot)   __pte(((page_nr) << PAGE_SHIFT) | \
0046                     pgprot_val(pgprot))
0047 
0048 /*
0049  * C-SKY only has VALID and DIRTY bit in hardware. So we need to use the
0050  * two bits emulate PRESENT, READ, WRITE, EXEC, MODIFIED, ACCESSED.
0051  */
0052 #define _PAGE_BASE  (_PAGE_PRESENT | _PAGE_ACCESSED)
0053 
0054 #define PAGE_NONE   __pgprot(_PAGE_PROT_NONE)
0055 #define PAGE_READ   __pgprot(_PAGE_BASE | _PAGE_READ | \
0056                 _CACHE_CACHED)
0057 #define PAGE_WRITE  __pgprot(_PAGE_BASE | _PAGE_READ | _PAGE_WRITE | \
0058                 _CACHE_CACHED)
0059 #define PAGE_SHARED PAGE_WRITE
0060 
0061 #define PAGE_KERNEL __pgprot(_PAGE_BASE | _PAGE_READ | _PAGE_VALID | \
0062                 _PAGE_WRITE | _PAGE_DIRTY | _PAGE_MODIFIED | \
0063                 _PAGE_GLOBAL | \
0064                 _CACHE_CACHED)
0065 
0066 #define _PAGE_IOREMAP       (_PAGE_BASE | _PAGE_READ | _PAGE_VALID | \
0067                 _PAGE_WRITE | _PAGE_DIRTY | _PAGE_MODIFIED | \
0068                 _PAGE_GLOBAL | \
0069                 _CACHE_UNCACHED | _PAGE_SO)
0070 
0071 #define _PAGE_CHG_MASK  (~(unsigned long) \
0072                 (_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \
0073                 _CACHE_MASK | _PAGE_GLOBAL))
0074 
0075 #define MAX_SWAPFILES_CHECK() \
0076         BUILD_BUG_ON(MAX_SWAPFILES_SHIFT != 5)
0077 
0078 extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)];
0079 #define ZERO_PAGE(vaddr)    (virt_to_page(empty_zero_page))
0080 
0081 extern void load_pgd(unsigned long pg_dir);
0082 extern pte_t invalid_pte_table[PTRS_PER_PTE];
0083 
0084 static inline void set_pte(pte_t *p, pte_t pte)
0085 {
0086     *p = pte;
0087 #if defined(CONFIG_CPU_NEED_TLBSYNC)
0088     dcache_wb_line((u32)p);
0089 #endif
0090     /* prevent out of order excution */
0091     smp_mb();
0092 }
0093 #define set_pte_at(mm, addr, ptep, pteval) set_pte(ptep, pteval)
0094 
0095 static inline pte_t *pmd_page_vaddr(pmd_t pmd)
0096 {
0097     unsigned long ptr;
0098 
0099     ptr = pmd_val(pmd);
0100 
0101     return __va(ptr);
0102 }
0103 
0104 #define pmd_phys(pmd) pmd_val(pmd)
0105 
0106 static inline void set_pmd(pmd_t *p, pmd_t pmd)
0107 {
0108     *p = pmd;
0109 #if defined(CONFIG_CPU_NEED_TLBSYNC)
0110     dcache_wb_line((u32)p);
0111 #endif
0112     /* prevent specul excute */
0113     smp_mb();
0114 }
0115 
0116 
0117 static inline int pmd_none(pmd_t pmd)
0118 {
0119     return pmd_val(pmd) == __pa(invalid_pte_table);
0120 }
0121 
0122 #define pmd_bad(pmd)    (pmd_val(pmd) & ~PAGE_MASK)
0123 
0124 static inline int pmd_present(pmd_t pmd)
0125 {
0126     return (pmd_val(pmd) != __pa(invalid_pte_table));
0127 }
0128 
0129 static inline void pmd_clear(pmd_t *p)
0130 {
0131     pmd_val(*p) = (__pa(invalid_pte_table));
0132 #if defined(CONFIG_CPU_NEED_TLBSYNC)
0133     dcache_wb_line((u32)p);
0134 #endif
0135 }
0136 
0137 /*
0138  * The following only work if pte_present() is true.
0139  * Undefined behaviour if not..
0140  */
0141 static inline int pte_read(pte_t pte)
0142 {
0143     return pte.pte_low & _PAGE_READ;
0144 }
0145 
0146 static inline int pte_write(pte_t pte)
0147 {
0148     return (pte).pte_low & _PAGE_WRITE;
0149 }
0150 
0151 static inline int pte_dirty(pte_t pte)
0152 {
0153     return (pte).pte_low & _PAGE_MODIFIED;
0154 }
0155 
0156 static inline int pte_young(pte_t pte)
0157 {
0158     return (pte).pte_low & _PAGE_ACCESSED;
0159 }
0160 
0161 static inline pte_t pte_wrprotect(pte_t pte)
0162 {
0163     pte_val(pte) &= ~(_PAGE_WRITE | _PAGE_DIRTY);
0164     return pte;
0165 }
0166 
0167 static inline pte_t pte_mkclean(pte_t pte)
0168 {
0169     pte_val(pte) &= ~(_PAGE_MODIFIED|_PAGE_DIRTY);
0170     return pte;
0171 }
0172 
0173 static inline pte_t pte_mkold(pte_t pte)
0174 {
0175     pte_val(pte) &= ~(_PAGE_ACCESSED|_PAGE_VALID);
0176     return pte;
0177 }
0178 
0179 static inline pte_t pte_mkwrite(pte_t pte)
0180 {
0181     pte_val(pte) |= _PAGE_WRITE;
0182     if (pte_val(pte) & _PAGE_MODIFIED)
0183         pte_val(pte) |= _PAGE_DIRTY;
0184     return pte;
0185 }
0186 
0187 static inline pte_t pte_mkdirty(pte_t pte)
0188 {
0189     pte_val(pte) |= _PAGE_MODIFIED;
0190     if (pte_val(pte) & _PAGE_WRITE)
0191         pte_val(pte) |= _PAGE_DIRTY;
0192     return pte;
0193 }
0194 
0195 static inline pte_t pte_mkyoung(pte_t pte)
0196 {
0197     pte_val(pte) |= _PAGE_ACCESSED;
0198     if (pte_val(pte) & _PAGE_READ)
0199         pte_val(pte) |= _PAGE_VALID;
0200     return pte;
0201 }
0202 
0203 #define __HAVE_PHYS_MEM_ACCESS_PROT
0204 struct file;
0205 extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
0206                      unsigned long size, pgprot_t vma_prot);
0207 
0208 /*
0209  * Macro to make mark a page protection value as "uncacheable".  Note
0210  * that "protection" is really a misnomer here as the protection value
0211  * contains the memory attribute bits, dirty bits, and various other
0212  * bits as well.
0213  */
0214 #define pgprot_noncached pgprot_noncached
0215 
0216 static inline pgprot_t pgprot_noncached(pgprot_t _prot)
0217 {
0218     unsigned long prot = pgprot_val(_prot);
0219 
0220     prot = (prot & ~_CACHE_MASK) | _CACHE_UNCACHED | _PAGE_SO;
0221 
0222     return __pgprot(prot);
0223 }
0224 
0225 #define pgprot_writecombine pgprot_writecombine
0226 static inline pgprot_t pgprot_writecombine(pgprot_t _prot)
0227 {
0228     unsigned long prot = pgprot_val(_prot);
0229 
0230     prot = (prot & ~_CACHE_MASK) | _CACHE_UNCACHED;
0231 
0232     return __pgprot(prot);
0233 }
0234 
0235 /*
0236  * Conversion functions: convert a page and protection to a page entry,
0237  * and a page entry and page directory to the page they refer to.
0238  */
0239 #define mk_pte(page, pgprot)    pfn_pte(page_to_pfn(page), (pgprot))
0240 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
0241 {
0242     return __pte((pte_val(pte) & _PAGE_CHG_MASK) |
0243              (pgprot_val(newprot)));
0244 }
0245 
0246 extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
0247 extern void paging_init(void);
0248 
0249 void update_mmu_cache(struct vm_area_struct *vma, unsigned long address,
0250               pte_t *pte);
0251 
0252 /* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
0253 #define kern_addr_valid(addr)   (1)
0254 
0255 #define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \
0256     remap_pfn_range(vma, vaddr, pfn, size, prot)
0257 
0258 #endif /* __ASM_CSKY_PGTABLE_H */