1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 23e731858SChristophe Leroy #ifndef _ASM_POWERPC_NOHASH_PTE_E500_H 33e731858SChristophe Leroy #define _ASM_POWERPC_NOHASH_PTE_E500_H 457e2a99fSBenjamin Herrenschmidt #ifdef __KERNEL__ 557e2a99fSBenjamin Herrenschmidt 657e2a99fSBenjamin Herrenschmidt /* PTE bit definitions for processors compliant to the Book3E 757e2a99fSBenjamin Herrenschmidt * architecture 2.06 or later. The position of the PTE bits 857e2a99fSBenjamin Herrenschmidt * matches the HW definition of the optional Embedded Page Table 957e2a99fSBenjamin Herrenschmidt * category. 1057e2a99fSBenjamin Herrenschmidt */ 1157e2a99fSBenjamin Herrenschmidt 1257e2a99fSBenjamin Herrenschmidt /* Architected bits */ 1357e2a99fSBenjamin Herrenschmidt #define _PAGE_PRESENT 0x000001 /* software: pte contains a translation */ 1457e2a99fSBenjamin Herrenschmidt #define _PAGE_SW1 0x000002 1557e2a99fSBenjamin Herrenschmidt #define _PAGE_BAP_SR 0x000004 1657e2a99fSBenjamin Herrenschmidt #define _PAGE_BAP_UR 0x000008 1757e2a99fSBenjamin Herrenschmidt #define _PAGE_BAP_SW 0x000010 1857e2a99fSBenjamin Herrenschmidt #define _PAGE_BAP_UW 0x000020 1957e2a99fSBenjamin Herrenschmidt #define _PAGE_BAP_SX 0x000040 2057e2a99fSBenjamin Herrenschmidt #define _PAGE_BAP_UX 0x000080 2157e2a99fSBenjamin Herrenschmidt #define _PAGE_PSIZE_MSK 0x000f00 2284319905SChristophe Leroy #define _PAGE_TSIZE_4K 0x000100 2357e2a99fSBenjamin Herrenschmidt #define _PAGE_DIRTY 0x001000 /* C: page changed */ 2457e2a99fSBenjamin Herrenschmidt #define _PAGE_SW0 0x002000 2557e2a99fSBenjamin Herrenschmidt #define _PAGE_U3 0x004000 2657e2a99fSBenjamin Herrenschmidt #define _PAGE_U2 0x008000 2757e2a99fSBenjamin Herrenschmidt #define _PAGE_U1 0x010000 2857e2a99fSBenjamin Herrenschmidt #define _PAGE_U0 0x020000 2957e2a99fSBenjamin Herrenschmidt #define _PAGE_ACCESSED 0x040000 30c199efa2SBharat Bhushan #define _PAGE_ENDIAN 0x080000 3157e2a99fSBenjamin Herrenschmidt #define _PAGE_GUARDED 0x100000 3257e2a99fSBenjamin Herrenschmidt #define _PAGE_COHERENT 0x200000 /* M: enforce memory coherence */ 3357e2a99fSBenjamin Herrenschmidt #define _PAGE_NO_CACHE 0x400000 /* I: cache inhibit */ 3457e2a99fSBenjamin Herrenschmidt #define _PAGE_WRITETHRU 0x800000 /* W: cache write-through */ 3557e2a99fSBenjamin Herrenschmidt 3684319905SChristophe Leroy #define _PAGE_PSIZE_SHIFT 7 3784319905SChristophe Leroy #define _PAGE_PSIZE_SHIFT_OFFSET 10 3884319905SChristophe Leroy 3957e2a99fSBenjamin Herrenschmidt /* "Higher level" linux bit combinations */ 40b6cb20fdSChristophe Leroy #define _PAGE_EXEC (_PAGE_BAP_SX | _PAGE_BAP_UX) /* .. and was cache cleaned */ 4148cf93bbSChristophe Leroy #define _PAGE_READ (_PAGE_BAP_SR | _PAGE_BAP_UR) /* User read permission */ 4248cf93bbSChristophe Leroy #define _PAGE_WRITE (_PAGE_BAP_SW | _PAGE_BAP_UW) /* User write permission */ 4348cf93bbSChristophe Leroy 4457e2a99fSBenjamin Herrenschmidt #define _PAGE_KERNEL_RW (_PAGE_BAP_SW | _PAGE_BAP_SR | _PAGE_DIRTY) 4557e2a99fSBenjamin Herrenschmidt #define _PAGE_KERNEL_RO (_PAGE_BAP_SR) 46ea3cc330SBenjamin Herrenschmidt #define _PAGE_KERNEL_RWX (_PAGE_BAP_SW | _PAGE_BAP_SR | _PAGE_DIRTY | _PAGE_BAP_SX) 47ea3cc330SBenjamin Herrenschmidt #define _PAGE_KERNEL_ROX (_PAGE_BAP_SR | _PAGE_BAP_SX) 4857e2a99fSBenjamin Herrenschmidt 4948cf93bbSChristophe Leroy #define _PAGE_NA 0 50b1fba034SChristophe Leroy #define _PAGE_NAX _PAGE_BAP_UX 5148cf93bbSChristophe Leroy #define _PAGE_RO _PAGE_READ 5248cf93bbSChristophe Leroy #define _PAGE_ROX (_PAGE_READ | _PAGE_BAP_UX) 5348cf93bbSChristophe Leroy #define _PAGE_RW (_PAGE_READ | _PAGE_WRITE) 5448cf93bbSChristophe Leroy #define _PAGE_RWX (_PAGE_READ | _PAGE_WRITE | _PAGE_BAP_UX) 55d20506d4SChristophe Leroy 5657e2a99fSBenjamin Herrenschmidt #define _PAGE_SPECIAL _PAGE_SW0 5757e2a99fSBenjamin Herrenschmidt 5857e2a99fSBenjamin Herrenschmidt #define PTE_RPN_SHIFT (24) 5957e2a99fSBenjamin Herrenschmidt 6041151e77SBecky Bruce #define PTE_WIMGE_SHIFT (19) 6141151e77SBecky Bruce #define PTE_BAP_SHIFT (2) 6241151e77SBecky Bruce 6357e2a99fSBenjamin Herrenschmidt /* On 32-bit, we never clear the top part of the PTE */ 6457e2a99fSBenjamin Herrenschmidt #ifdef CONFIG_PPC32 6557e2a99fSBenjamin Herrenschmidt #define _PTE_NONE_MASK 0xffffffff00000000ULL 6676acc2c1SKumar Gala #define _PMD_PRESENT 0 6776acc2c1SKumar Gala #define _PMD_PRESENT_MASK (PAGE_MASK) 6876acc2c1SKumar Gala #define _PMD_BAD (~PAGE_MASK) 69d82fd29cSChristophe Leroy #define _PMD_USER 0 70d82fd29cSChristophe Leroy #else 71d82fd29cSChristophe Leroy #define _PTE_NONE_MASK 0 7257e2a99fSBenjamin Herrenschmidt #endif 7357e2a99fSBenjamin Herrenschmidt 74d82fd29cSChristophe Leroy /* 75d82fd29cSChristophe Leroy * We define 2 sets of base prot bits, one for basic pages (ie, 76d82fd29cSChristophe Leroy * cacheable kernel and user pages) and one for non cacheable 77d82fd29cSChristophe Leroy * pages. We always set _PAGE_COHERENT when SMP is enabled or 78d82fd29cSChristophe Leroy * the processor might need it for DMA coherency. 79d82fd29cSChristophe Leroy */ 8084319905SChristophe Leroy #define _PAGE_BASE_NC (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_TSIZE_4K) 81d82fd29cSChristophe Leroy #if defined(CONFIG_SMP) 82d82fd29cSChristophe Leroy #define _PAGE_BASE (_PAGE_BASE_NC | _PAGE_COHERENT) 83d82fd29cSChristophe Leroy #else 84d82fd29cSChristophe Leroy #define _PAGE_BASE (_PAGE_BASE_NC) 85d82fd29cSChristophe Leroy #endif 86d82fd29cSChristophe Leroy 8748cf93bbSChristophe Leroy #include <asm/pgtable-masks.h> 88d82fd29cSChristophe Leroy 89bde1a133SChristophe Leroy #ifndef __ASSEMBLY__ pte_mkexec(pte_t pte)90b6cb20fdSChristophe Leroystatic inline pte_t pte_mkexec(pte_t pte) 91b6cb20fdSChristophe Leroy { 92b6cb20fdSChristophe Leroy return __pte((pte_val(pte) & ~_PAGE_BAP_SX) | _PAGE_BAP_UX); 93b6cb20fdSChristophe Leroy } 94b6cb20fdSChristophe Leroy #define pte_mkexec pte_mkexec 95b6cb20fdSChristophe Leroy pte_huge_size(pte_t pte)9684319905SChristophe Leroystatic inline unsigned long pte_huge_size(pte_t pte) 9784319905SChristophe Leroy { 9884319905SChristophe Leroy pte_basic_t val = pte_val(pte); 9984319905SChristophe Leroy 10084319905SChristophe Leroy return 1UL << (((val & _PAGE_PSIZE_MSK) >> _PAGE_PSIZE_SHIFT) + _PAGE_PSIZE_SHIFT_OFFSET); 10184319905SChristophe Leroy } 10284319905SChristophe Leroy #define pte_huge_size pte_huge_size 10384319905SChristophe Leroy pmd_leaf(pmd_t pmd)1047c44202eSChristophe Leroystatic inline int pmd_leaf(pmd_t pmd) 1057c44202eSChristophe Leroy { 1067c44202eSChristophe Leroy if (IS_ENABLED(CONFIG_PPC64)) 1077c44202eSChristophe Leroy return (long)pmd_val(pmd) > 0; 1087c44202eSChristophe Leroy else 1097c44202eSChristophe Leroy return pmd_val(pmd) & _PAGE_PSIZE_MSK; 1107c44202eSChristophe Leroy } 1117c44202eSChristophe Leroy #define pmd_leaf pmd_leaf 1127c44202eSChristophe Leroy pmd_leaf_size(pmd_t pmd)1137c44202eSChristophe Leroystatic inline unsigned long pmd_leaf_size(pmd_t pmd) 1147c44202eSChristophe Leroy { 1157c44202eSChristophe Leroy return pte_huge_size(__pte(pmd_val(pmd))); 1167c44202eSChristophe Leroy } 1177c44202eSChristophe Leroy #define pmd_leaf_size pmd_leaf_size 1187c44202eSChristophe Leroy 1197c44202eSChristophe Leroy #ifdef CONFIG_PPC64 pud_leaf(pud_t pud)1207c44202eSChristophe Leroystatic inline int pud_leaf(pud_t pud) 1217c44202eSChristophe Leroy { 1227c44202eSChristophe Leroy if (IS_ENABLED(CONFIG_PPC64)) 1237c44202eSChristophe Leroy return (long)pud_val(pud) > 0; 1247c44202eSChristophe Leroy else 1257c44202eSChristophe Leroy return pud_val(pud) & _PAGE_PSIZE_MSK; 1267c44202eSChristophe Leroy } 1277c44202eSChristophe Leroy #define pud_leaf pud_leaf 1287c44202eSChristophe Leroy pud_leaf_size(pud_t pud)1297c44202eSChristophe Leroystatic inline unsigned long pud_leaf_size(pud_t pud) 1307c44202eSChristophe Leroy { 1317c44202eSChristophe Leroy return pte_huge_size(__pte(pud_val(pud))); 1327c44202eSChristophe Leroy } 1337c44202eSChristophe Leroy #define pud_leaf_size pud_leaf_size 1347c44202eSChristophe Leroy 1357c44202eSChristophe Leroy #endif 1367c44202eSChristophe Leroy 137bde1a133SChristophe Leroy #endif /* __ASSEMBLY__ */ 138bde1a133SChristophe Leroy 13957e2a99fSBenjamin Herrenschmidt #endif /* __KERNEL__ */ 1403e731858SChristophe Leroy #endif /* _ASM_POWERPC_NOHASH_PTE_E500_H */ 141