18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2020 Loongson Technology Corporation Limited 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci#ifndef _ASM_PGTABLE_BITS_H 68c2ecf20Sopenharmony_ci#define _ASM_PGTABLE_BITS_H 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci/* Page table bits */ 98c2ecf20Sopenharmony_ci#define _PAGE_VALID_SHIFT 0 108c2ecf20Sopenharmony_ci#define _PAGE_ACCESSED_SHIFT 0 /* Reuse Valid for Accessed */ 118c2ecf20Sopenharmony_ci#define _PAGE_DIRTY_SHIFT 1 128c2ecf20Sopenharmony_ci#define _PAGE_PLV_SHIFT 2 /* 2~3, two bits */ 138c2ecf20Sopenharmony_ci#define _CACHE_SHIFT 4 /* 4~5, two bits */ 148c2ecf20Sopenharmony_ci#define _PAGE_GLOBAL_SHIFT 6 158c2ecf20Sopenharmony_ci#define _PAGE_HUGE_SHIFT 6 /* HUGE is a PMD bit */ 168c2ecf20Sopenharmony_ci#define _PAGE_PRESENT_SHIFT 7 178c2ecf20Sopenharmony_ci#define _PAGE_WRITE_SHIFT 8 188c2ecf20Sopenharmony_ci#define _PAGE_MODIFIED_SHIFT 9 198c2ecf20Sopenharmony_ci#define _PAGE_PROTNONE_SHIFT 10 208c2ecf20Sopenharmony_ci#define _PAGE_SPECIAL_SHIFT 11 218c2ecf20Sopenharmony_ci#define _PAGE_HGLOBAL_SHIFT 12 /* HGlobal is a PMD bit */ 228c2ecf20Sopenharmony_ci#define _PAGE_PFN_SHIFT 12 238c2ecf20Sopenharmony_ci#define _PAGE_PFN_END_SHIFT 48 248c2ecf20Sopenharmony_ci#define _PAGE_PRESENT_INVALID_SHIFT 60 258c2ecf20Sopenharmony_ci#define _PAGE_NO_READ_SHIFT 61 268c2ecf20Sopenharmony_ci#define _PAGE_NO_EXEC_SHIFT 62 278c2ecf20Sopenharmony_ci#define _PAGE_RPLV_SHIFT 63 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci/* Used by software */ 308c2ecf20Sopenharmony_ci#define _PAGE_PRESENT (_ULCAST_(1) << _PAGE_PRESENT_SHIFT) 318c2ecf20Sopenharmony_ci#define _PAGE_PRESENT_INVALID (_ULCAST_(1) << _PAGE_PRESENT_INVALID_SHIFT) 328c2ecf20Sopenharmony_ci#define _PAGE_WRITE (_ULCAST_(1) << _PAGE_WRITE_SHIFT) 338c2ecf20Sopenharmony_ci#define _PAGE_ACCESSED (_ULCAST_(1) << _PAGE_ACCESSED_SHIFT) 348c2ecf20Sopenharmony_ci#define _PAGE_MODIFIED (_ULCAST_(1) << _PAGE_MODIFIED_SHIFT) 358c2ecf20Sopenharmony_ci#define _PAGE_PROTNONE (_ULCAST_(1) << _PAGE_PROTNONE_SHIFT) 368c2ecf20Sopenharmony_ci#define _PAGE_SPECIAL (_ULCAST_(1) << _PAGE_SPECIAL_SHIFT) 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci/* Used by TLB hardware (placed in EntryLo*) */ 398c2ecf20Sopenharmony_ci#define _PAGE_VALID (_ULCAST_(1) << _PAGE_VALID_SHIFT) 408c2ecf20Sopenharmony_ci#define _PAGE_DIRTY (_ULCAST_(1) << _PAGE_DIRTY_SHIFT) 418c2ecf20Sopenharmony_ci#define _PAGE_PLV (_ULCAST_(3) << _PAGE_PLV_SHIFT) 428c2ecf20Sopenharmony_ci#define _PAGE_GLOBAL (_ULCAST_(1) << _PAGE_GLOBAL_SHIFT) 438c2ecf20Sopenharmony_ci#define _PAGE_HUGE (_ULCAST_(1) << _PAGE_HUGE_SHIFT) 448c2ecf20Sopenharmony_ci#define _PAGE_HGLOBAL (_ULCAST_(1) << _PAGE_HGLOBAL_SHIFT) 458c2ecf20Sopenharmony_ci#define _PAGE_NO_READ (_ULCAST_(1) << _PAGE_NO_READ_SHIFT) 468c2ecf20Sopenharmony_ci#define _PAGE_NO_EXEC (_ULCAST_(1) << _PAGE_NO_EXEC_SHIFT) 478c2ecf20Sopenharmony_ci#define _PAGE_RPLV (_ULCAST_(1) << _PAGE_RPLV_SHIFT) 488c2ecf20Sopenharmony_ci#define _CACHE_MASK (_ULCAST_(3) << _CACHE_SHIFT) 498c2ecf20Sopenharmony_ci#define _PFN_SHIFT (PAGE_SHIFT - 12 + _PAGE_PFN_SHIFT) 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci#define _PAGE_USER (PLV_USER << _PAGE_PLV_SHIFT) 528c2ecf20Sopenharmony_ci#define _PAGE_KERN (PLV_KERN << _PAGE_PLV_SHIFT) 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci#define _PFN_MASK (~((_ULCAST_(1) << (_PFN_SHIFT)) - 1) & \ 558c2ecf20Sopenharmony_ci ((_ULCAST_(1) << (_PAGE_PFN_END_SHIFT)) - 1)) 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci/* 588c2ecf20Sopenharmony_ci * Cache attributes 598c2ecf20Sopenharmony_ci */ 608c2ecf20Sopenharmony_ci#ifndef _CACHE_SUC 618c2ecf20Sopenharmony_ci#define _CACHE_SUC (0<<_CACHE_SHIFT) /* Strong-ordered UnCached */ 628c2ecf20Sopenharmony_ci#endif 638c2ecf20Sopenharmony_ci#ifndef _CACHE_CC 648c2ecf20Sopenharmony_ci#define _CACHE_CC (1<<_CACHE_SHIFT) /* Coherent Cached */ 658c2ecf20Sopenharmony_ci#endif 668c2ecf20Sopenharmony_ci#ifndef _CACHE_WUC 678c2ecf20Sopenharmony_ci#define _CACHE_WUC (2<<_CACHE_SHIFT) /* Weak-ordered UnCached */ 688c2ecf20Sopenharmony_ci#endif 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci#define __READABLE (_PAGE_VALID) 718c2ecf20Sopenharmony_ci#define __WRITEABLE (_PAGE_DIRTY | _PAGE_WRITE) 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci#define _PAGE_CHG_MASK (_PAGE_MODIFIED | _PAGE_SPECIAL | _PFN_MASK | _CACHE_MASK | _PAGE_PLV) 748c2ecf20Sopenharmony_ci#define _HPAGE_CHG_MASK (_PAGE_MODIFIED | _PAGE_SPECIAL | _PFN_MASK | _CACHE_MASK | _PAGE_PLV | _PAGE_HUGE) 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci#define PAGE_NONE __pgprot(_PAGE_PROTNONE | _PAGE_NO_READ | \ 778c2ecf20Sopenharmony_ci _PAGE_USER | _CACHE_CC) 788c2ecf20Sopenharmony_ci#define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_WRITE | \ 798c2ecf20Sopenharmony_ci _PAGE_USER | _CACHE_CC) 808c2ecf20Sopenharmony_ci#define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_USER | _CACHE_CC) 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci#define PAGE_KERNEL __pgprot(_PAGE_PRESENT | __READABLE | __WRITEABLE | \ 838c2ecf20Sopenharmony_ci _PAGE_GLOBAL | _PAGE_KERN | _CACHE_CC) 848c2ecf20Sopenharmony_ci#define PAGE_KERNEL_SUC __pgprot(_PAGE_PRESENT | __READABLE | __WRITEABLE | \ 858c2ecf20Sopenharmony_ci _PAGE_GLOBAL | _PAGE_KERN | _CACHE_SUC) 868c2ecf20Sopenharmony_ci#define PAGE_KERNEL_WUC __pgprot(_PAGE_PRESENT | __READABLE | __WRITEABLE | \ 878c2ecf20Sopenharmony_ci _PAGE_GLOBAL | _PAGE_KERN | _CACHE_WUC) 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci#define __P000 __pgprot(_CACHE_CC | _PAGE_USER | _PAGE_PROTNONE | _PAGE_NO_EXEC | _PAGE_NO_READ) 908c2ecf20Sopenharmony_ci#define __P001 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT | _PAGE_NO_EXEC) 918c2ecf20Sopenharmony_ci#define __P010 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT | _PAGE_NO_EXEC) 928c2ecf20Sopenharmony_ci#define __P011 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT | _PAGE_NO_EXEC) 938c2ecf20Sopenharmony_ci#define __P100 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT) 948c2ecf20Sopenharmony_ci#define __P101 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT) 958c2ecf20Sopenharmony_ci#define __P110 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT) 968c2ecf20Sopenharmony_ci#define __P111 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT) 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci#define __S000 __pgprot(_CACHE_CC | _PAGE_USER | _PAGE_PROTNONE | _PAGE_NO_EXEC | _PAGE_NO_READ) 998c2ecf20Sopenharmony_ci#define __S001 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT | _PAGE_NO_EXEC) 1008c2ecf20Sopenharmony_ci#define __S010 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT | _PAGE_NO_EXEC | _PAGE_WRITE) 1018c2ecf20Sopenharmony_ci#define __S011 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT | _PAGE_NO_EXEC | _PAGE_WRITE) 1028c2ecf20Sopenharmony_ci#define __S100 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT) 1038c2ecf20Sopenharmony_ci#define __S101 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT) 1048c2ecf20Sopenharmony_ci#define __S110 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT | _PAGE_WRITE) 1058c2ecf20Sopenharmony_ci#define __S111 __pgprot(_CACHE_CC | _PAGE_VALID | _PAGE_USER | _PAGE_PRESENT | _PAGE_WRITE) 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci#define _PAGE_IOREMAP pgprot_val(PAGE_KERNEL_SUC) 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci#define pgprot_noncached pgprot_noncached 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_cistatic inline pgprot_t pgprot_noncached(pgprot_t _prot) 1148c2ecf20Sopenharmony_ci{ 1158c2ecf20Sopenharmony_ci unsigned long prot = pgprot_val(_prot); 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci prot = (prot & ~_CACHE_MASK) | _CACHE_SUC; 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci return __pgprot(prot); 1208c2ecf20Sopenharmony_ci} 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ciextern bool wc_enabled; 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci#define pgprot_writecombine pgprot_writecombine 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_cistatic inline pgprot_t pgprot_writecombine(pgprot_t _prot) 1278c2ecf20Sopenharmony_ci{ 1288c2ecf20Sopenharmony_ci unsigned long prot = pgprot_val(_prot); 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci prot = (prot & ~_CACHE_MASK) | (wc_enabled ? _CACHE_WUC : _CACHE_SUC); 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci return __pgprot(prot); 1338c2ecf20Sopenharmony_ci} 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci#endif /* !__ASSEMBLY__ */ 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci#endif /* _ASM_PGTABLE_BITS_H */ 138