1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 2f15cbe6fSPaul Mundt #ifndef __ASM_SH_PGTABLE_32_H 3f15cbe6fSPaul Mundt #define __ASM_SH_PGTABLE_32_H 4f15cbe6fSPaul Mundt 5f15cbe6fSPaul Mundt /* 6f15cbe6fSPaul Mundt * Linux PTEL encoding. 7f15cbe6fSPaul Mundt * 8f15cbe6fSPaul Mundt * Hardware and software bit definitions for the PTEL value (see below for 9f15cbe6fSPaul Mundt * notes on SH-X2 MMUs and 64-bit PTEs): 10f15cbe6fSPaul Mundt * 11f15cbe6fSPaul Mundt * - Bits 0 and 7 are reserved on SH-3 (_PAGE_WT and _PAGE_SZ1 on SH-4). 12f15cbe6fSPaul Mundt * 13f15cbe6fSPaul Mundt * - Bit 1 is the SH-bit, but is unused on SH-3 due to an MMU bug (the 14f15cbe6fSPaul Mundt * hardware PTEL value can't have the SH-bit set when MMUCR.IX is set, 15f15cbe6fSPaul Mundt * which is the default in cpu-sh3/mmu_context.h:MMU_CONTROL_INIT). 16f15cbe6fSPaul Mundt * 17f15cbe6fSPaul Mundt * In order to keep this relatively clean, do not use these for defining 18f15cbe6fSPaul Mundt * SH-3 specific flags until all of the other unused bits have been 19f15cbe6fSPaul Mundt * exhausted. 20f15cbe6fSPaul Mundt * 21f15cbe6fSPaul Mundt * - Bit 9 is reserved by everyone and used by _PAGE_PROTNONE. 22f15cbe6fSPaul Mundt * 23f15cbe6fSPaul Mundt * - Bits 10 and 11 are low bits of the PPN that are reserved on >= 4K pages. 24c0b96cf6SPaul Mundt * Bit 10 is used for _PAGE_ACCESSED, and bit 11 is used for _PAGE_SPECIAL. 25f15cbe6fSPaul Mundt * 26f15cbe6fSPaul Mundt * - On 29 bit platforms, bits 31 to 29 are used for the space attributes 27f15cbe6fSPaul Mundt * and timing control which (together with bit 0) are moved into the 28f15cbe6fSPaul Mundt * old-style PTEA on the parts that support it. 29f15cbe6fSPaul Mundt * 30f15cbe6fSPaul Mundt * SH-X2 MMUs and extended PTEs 31f15cbe6fSPaul Mundt * 32f15cbe6fSPaul Mundt * SH-X2 supports an extended mode TLB with split data arrays due to the 33f15cbe6fSPaul Mundt * number of bits needed for PR and SZ (now EPR and ESZ) encodings. The PR and 34f15cbe6fSPaul Mundt * SZ bit placeholders still exist in data array 1, but are implemented as 35f15cbe6fSPaul Mundt * reserved bits, with the real logic existing in data array 2. 36f15cbe6fSPaul Mundt * 37f15cbe6fSPaul Mundt * The downside to this is that we can no longer fit everything in to a 32-bit 38f15cbe6fSPaul Mundt * PTE encoding, so a 64-bit pte_t is necessary for these parts. On the plus 39f15cbe6fSPaul Mundt * side, this gives us quite a few spare bits to play with for future usage. 40f15cbe6fSPaul Mundt */ 41f15cbe6fSPaul Mundt /* Legacy and compat mode bits */ 42f15cbe6fSPaul Mundt #define _PAGE_WT 0x001 /* WT-bit on SH-4, 0 on SH-3 */ 43f15cbe6fSPaul Mundt #define _PAGE_HW_SHARED 0x002 /* SH-bit : shared among processes */ 44f15cbe6fSPaul Mundt #define _PAGE_DIRTY 0x004 /* D-bit : page changed */ 45f15cbe6fSPaul Mundt #define _PAGE_CACHABLE 0x008 /* C-bit : cachable */ 46f15cbe6fSPaul Mundt #define _PAGE_SZ0 0x010 /* SZ0-bit : Size of page */ 47f15cbe6fSPaul Mundt #define _PAGE_RW 0x020 /* PR0-bit : write access allowed */ 48f15cbe6fSPaul Mundt #define _PAGE_USER 0x040 /* PR1-bit : user space access allowed*/ 49f15cbe6fSPaul Mundt #define _PAGE_SZ1 0x080 /* SZ1-bit : Size of page (on SH-4) */ 50f15cbe6fSPaul Mundt #define _PAGE_PRESENT 0x100 /* V-bit : page is valid */ 51f15cbe6fSPaul Mundt #define _PAGE_PROTNONE 0x200 /* software: if not present */ 52f15cbe6fSPaul Mundt #define _PAGE_ACCESSED 0x400 /* software: page referenced */ 53c0b96cf6SPaul Mundt #define _PAGE_SPECIAL 0x800 /* software: special page */ 54f15cbe6fSPaul Mundt 55f15cbe6fSPaul Mundt #define _PAGE_SZ_MASK (_PAGE_SZ0 | _PAGE_SZ1) 56f15cbe6fSPaul Mundt #define _PAGE_PR_MASK (_PAGE_RW | _PAGE_USER) 57f15cbe6fSPaul Mundt 58f15cbe6fSPaul Mundt /* Extended mode bits */ 59f15cbe6fSPaul Mundt #define _PAGE_EXT_ESZ0 0x0010 /* ESZ0-bit: Size of page */ 60f15cbe6fSPaul Mundt #define _PAGE_EXT_ESZ1 0x0020 /* ESZ1-bit: Size of page */ 61f15cbe6fSPaul Mundt #define _PAGE_EXT_ESZ2 0x0040 /* ESZ2-bit: Size of page */ 62f15cbe6fSPaul Mundt #define _PAGE_EXT_ESZ3 0x0080 /* ESZ3-bit: Size of page */ 63f15cbe6fSPaul Mundt 64f15cbe6fSPaul Mundt #define _PAGE_EXT_USER_EXEC 0x0100 /* EPR0-bit: User space executable */ 65f15cbe6fSPaul Mundt #define _PAGE_EXT_USER_WRITE 0x0200 /* EPR1-bit: User space writable */ 66f15cbe6fSPaul Mundt #define _PAGE_EXT_USER_READ 0x0400 /* EPR2-bit: User space readable */ 67f15cbe6fSPaul Mundt 68f15cbe6fSPaul Mundt #define _PAGE_EXT_KERN_EXEC 0x0800 /* EPR3-bit: Kernel space executable */ 69f15cbe6fSPaul Mundt #define _PAGE_EXT_KERN_WRITE 0x1000 /* EPR4-bit: Kernel space writable */ 70f15cbe6fSPaul Mundt #define _PAGE_EXT_KERN_READ 0x2000 /* EPR5-bit: Kernel space readable */ 71f15cbe6fSPaul Mundt 728eda5514SMatt Fleming #define _PAGE_EXT_WIRED 0x4000 /* software: Wire TLB entry */ 738eda5514SMatt Fleming 74f15cbe6fSPaul Mundt /* Wrapper for extended mode pgprot twiddling */ 75f15cbe6fSPaul Mundt #define _PAGE_EXT(x) ((unsigned long long)(x) << 32) 76f15cbe6fSPaul Mundt 77efb3e34bSPaul Mundt #ifdef CONFIG_X2TLB 78efb3e34bSPaul Mundt #define _PAGE_PCC_MASK 0x00000000 /* No legacy PTEA support */ 79efb3e34bSPaul Mundt #else 80efb3e34bSPaul Mundt 81f15cbe6fSPaul Mundt /* software: moves to PTEA.TC (Timing Control) */ 82f15cbe6fSPaul Mundt #define _PAGE_PCC_AREA5 0x00000000 /* use BSC registers for area5 */ 83f15cbe6fSPaul Mundt #define _PAGE_PCC_AREA6 0x80000000 /* use BSC registers for area6 */ 84f15cbe6fSPaul Mundt 85f15cbe6fSPaul Mundt /* software: moves to PTEA.SA[2:0] (Space Attributes) */ 86f15cbe6fSPaul Mundt #define _PAGE_PCC_IODYN 0x00000001 /* IO space, dynamically sized bus */ 87f15cbe6fSPaul Mundt #define _PAGE_PCC_IO8 0x20000000 /* IO space, 8 bit bus */ 88f15cbe6fSPaul Mundt #define _PAGE_PCC_IO16 0x20000001 /* IO space, 16 bit bus */ 89f15cbe6fSPaul Mundt #define _PAGE_PCC_COM8 0x40000000 /* Common Memory space, 8 bit bus */ 90f15cbe6fSPaul Mundt #define _PAGE_PCC_COM16 0x40000001 /* Common Memory space, 16 bit bus */ 91f15cbe6fSPaul Mundt #define _PAGE_PCC_ATR8 0x60000000 /* Attribute Memory space, 8 bit bus */ 92f15cbe6fSPaul Mundt #define _PAGE_PCC_ATR16 0x60000001 /* Attribute Memory space, 6 bit bus */ 93f15cbe6fSPaul Mundt 94efb3e34bSPaul Mundt #define _PAGE_PCC_MASK 0xe0000001 95efb3e34bSPaul Mundt 966503fe4aSMichael Trimarchi /* copy the ptea attributes */ 976503fe4aSMichael Trimarchi static inline unsigned long copy_ptea_attributes(unsigned long x) 986503fe4aSMichael Trimarchi { 996503fe4aSMichael Trimarchi return ((x >> 28) & 0xe) | (x & 0x1); 1006503fe4aSMichael Trimarchi } 1016503fe4aSMichael Trimarchi #endif 1026503fe4aSMichael Trimarchi 103f15cbe6fSPaul Mundt /* Mask which drops unused bits from the PTEL value */ 104f15cbe6fSPaul Mundt #if defined(CONFIG_CPU_SH3) 105f15cbe6fSPaul Mundt #define _PAGE_CLEAR_FLAGS (_PAGE_PROTNONE | _PAGE_ACCESSED| \ 1068b70beacSKirill A. Shutemov _PAGE_SZ1 | _PAGE_HW_SHARED) 107f15cbe6fSPaul Mundt #elif defined(CONFIG_X2TLB) 108f15cbe6fSPaul Mundt /* Get rid of the legacy PR/SZ bits when using extended mode */ 109f15cbe6fSPaul Mundt #define _PAGE_CLEAR_FLAGS (_PAGE_PROTNONE | _PAGE_ACCESSED | \ 1108b70beacSKirill A. Shutemov _PAGE_PR_MASK | _PAGE_SZ_MASK) 111f15cbe6fSPaul Mundt #else 1128b70beacSKirill A. Shutemov #define _PAGE_CLEAR_FLAGS (_PAGE_PROTNONE | _PAGE_ACCESSED) 113f15cbe6fSPaul Mundt #endif 114f15cbe6fSPaul Mundt 1151f69b6afSMatt Fleming #define _PAGE_FLAGS_HARDWARE_MASK (phys_addr_mask() & ~(_PAGE_CLEAR_FLAGS)) 116f15cbe6fSPaul Mundt 117f15cbe6fSPaul Mundt /* Hardware flags, page size encoding */ 118f15cbe6fSPaul Mundt #if !defined(CONFIG_MMU) 119f15cbe6fSPaul Mundt # define _PAGE_FLAGS_HARD 0ULL 120f15cbe6fSPaul Mundt #elif defined(CONFIG_X2TLB) 121f15cbe6fSPaul Mundt # if defined(CONFIG_PAGE_SIZE_4KB) 122f15cbe6fSPaul Mundt # define _PAGE_FLAGS_HARD _PAGE_EXT(_PAGE_EXT_ESZ0) 123f15cbe6fSPaul Mundt # elif defined(CONFIG_PAGE_SIZE_8KB) 124f15cbe6fSPaul Mundt # define _PAGE_FLAGS_HARD _PAGE_EXT(_PAGE_EXT_ESZ1) 125f15cbe6fSPaul Mundt # elif defined(CONFIG_PAGE_SIZE_64KB) 126f15cbe6fSPaul Mundt # define _PAGE_FLAGS_HARD _PAGE_EXT(_PAGE_EXT_ESZ2) 127f15cbe6fSPaul Mundt # endif 128f15cbe6fSPaul Mundt #else 129f15cbe6fSPaul Mundt # if defined(CONFIG_PAGE_SIZE_4KB) 130f15cbe6fSPaul Mundt # define _PAGE_FLAGS_HARD _PAGE_SZ0 131f15cbe6fSPaul Mundt # elif defined(CONFIG_PAGE_SIZE_64KB) 132f15cbe6fSPaul Mundt # define _PAGE_FLAGS_HARD _PAGE_SZ1 133f15cbe6fSPaul Mundt # endif 134f15cbe6fSPaul Mundt #endif 135f15cbe6fSPaul Mundt 136f15cbe6fSPaul Mundt #if defined(CONFIG_X2TLB) 137f15cbe6fSPaul Mundt # if defined(CONFIG_HUGETLB_PAGE_SIZE_64K) 138f15cbe6fSPaul Mundt # define _PAGE_SZHUGE (_PAGE_EXT_ESZ2) 139f15cbe6fSPaul Mundt # elif defined(CONFIG_HUGETLB_PAGE_SIZE_256K) 140f15cbe6fSPaul Mundt # define _PAGE_SZHUGE (_PAGE_EXT_ESZ0 | _PAGE_EXT_ESZ2) 141f15cbe6fSPaul Mundt # elif defined(CONFIG_HUGETLB_PAGE_SIZE_1MB) 142f15cbe6fSPaul Mundt # define _PAGE_SZHUGE (_PAGE_EXT_ESZ0 | _PAGE_EXT_ESZ1 | _PAGE_EXT_ESZ2) 143f15cbe6fSPaul Mundt # elif defined(CONFIG_HUGETLB_PAGE_SIZE_4MB) 144f15cbe6fSPaul Mundt # define _PAGE_SZHUGE (_PAGE_EXT_ESZ3) 145f15cbe6fSPaul Mundt # elif defined(CONFIG_HUGETLB_PAGE_SIZE_64MB) 146f15cbe6fSPaul Mundt # define _PAGE_SZHUGE (_PAGE_EXT_ESZ2 | _PAGE_EXT_ESZ3) 147f15cbe6fSPaul Mundt # endif 148046581f9SPaul Mundt # define _PAGE_WIRED (_PAGE_EXT(_PAGE_EXT_WIRED)) 149f15cbe6fSPaul Mundt #else 150f15cbe6fSPaul Mundt # if defined(CONFIG_HUGETLB_PAGE_SIZE_64K) 151f15cbe6fSPaul Mundt # define _PAGE_SZHUGE (_PAGE_SZ1) 152f15cbe6fSPaul Mundt # elif defined(CONFIG_HUGETLB_PAGE_SIZE_1MB) 153f15cbe6fSPaul Mundt # define _PAGE_SZHUGE (_PAGE_SZ0 | _PAGE_SZ1) 154f15cbe6fSPaul Mundt # endif 155046581f9SPaul Mundt # define _PAGE_WIRED (0) 156f15cbe6fSPaul Mundt #endif 157f15cbe6fSPaul Mundt 158f15cbe6fSPaul Mundt /* 159f15cbe6fSPaul Mundt * Stub out _PAGE_SZHUGE if we don't have a good definition for it, 160f15cbe6fSPaul Mundt * to make pte_mkhuge() happy. 161f15cbe6fSPaul Mundt */ 162f15cbe6fSPaul Mundt #ifndef _PAGE_SZHUGE 163f15cbe6fSPaul Mundt # define _PAGE_SZHUGE (_PAGE_FLAGS_HARD) 164f15cbe6fSPaul Mundt #endif 165f15cbe6fSPaul Mundt 166c0b96cf6SPaul Mundt /* 16725985edcSLucas De Marchi * Mask of bits that are to be preserved across pgprot changes. 168c0b96cf6SPaul Mundt */ 169f15cbe6fSPaul Mundt #define _PAGE_CHG_MASK \ 170c0b96cf6SPaul Mundt (PTE_MASK | _PAGE_ACCESSED | _PAGE_CACHABLE | \ 171c0b96cf6SPaul Mundt _PAGE_DIRTY | _PAGE_SPECIAL) 172f15cbe6fSPaul Mundt 173f15cbe6fSPaul Mundt #ifndef __ASSEMBLY__ 174f15cbe6fSPaul Mundt 175f15cbe6fSPaul Mundt #if defined(CONFIG_X2TLB) /* SH-X2 TLB */ 176f15cbe6fSPaul Mundt #define PAGE_NONE __pgprot(_PAGE_PROTNONE | _PAGE_CACHABLE | \ 177f15cbe6fSPaul Mundt _PAGE_ACCESSED | _PAGE_FLAGS_HARD) 178f15cbe6fSPaul Mundt 179f15cbe6fSPaul Mundt #define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED | \ 180f15cbe6fSPaul Mundt _PAGE_CACHABLE | _PAGE_FLAGS_HARD | \ 181f15cbe6fSPaul Mundt _PAGE_EXT(_PAGE_EXT_KERN_READ | \ 182f15cbe6fSPaul Mundt _PAGE_EXT_KERN_WRITE | \ 183f15cbe6fSPaul Mundt _PAGE_EXT_USER_READ | \ 184f15cbe6fSPaul Mundt _PAGE_EXT_USER_WRITE)) 185f15cbe6fSPaul Mundt 186f15cbe6fSPaul Mundt #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED | \ 187f15cbe6fSPaul Mundt _PAGE_CACHABLE | _PAGE_FLAGS_HARD | \ 188f15cbe6fSPaul Mundt _PAGE_EXT(_PAGE_EXT_KERN_EXEC | \ 189f15cbe6fSPaul Mundt _PAGE_EXT_KERN_READ | \ 190f15cbe6fSPaul Mundt _PAGE_EXT_USER_EXEC | \ 191f15cbe6fSPaul Mundt _PAGE_EXT_USER_READ)) 192f15cbe6fSPaul Mundt 193f15cbe6fSPaul Mundt #define PAGE_COPY PAGE_EXECREAD 194f15cbe6fSPaul Mundt 195f15cbe6fSPaul Mundt #define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED | \ 196f15cbe6fSPaul Mundt _PAGE_CACHABLE | _PAGE_FLAGS_HARD | \ 197f15cbe6fSPaul Mundt _PAGE_EXT(_PAGE_EXT_KERN_READ | \ 198f15cbe6fSPaul Mundt _PAGE_EXT_USER_READ)) 199f15cbe6fSPaul Mundt 200f15cbe6fSPaul Mundt #define PAGE_WRITEONLY __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED | \ 201f15cbe6fSPaul Mundt _PAGE_CACHABLE | _PAGE_FLAGS_HARD | \ 202f15cbe6fSPaul Mundt _PAGE_EXT(_PAGE_EXT_KERN_WRITE | \ 203f15cbe6fSPaul Mundt _PAGE_EXT_USER_WRITE)) 204f15cbe6fSPaul Mundt 205f15cbe6fSPaul Mundt #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED | \ 206f15cbe6fSPaul Mundt _PAGE_CACHABLE | _PAGE_FLAGS_HARD | \ 207f15cbe6fSPaul Mundt _PAGE_EXT(_PAGE_EXT_KERN_WRITE | \ 208f15cbe6fSPaul Mundt _PAGE_EXT_KERN_READ | \ 209f15cbe6fSPaul Mundt _PAGE_EXT_KERN_EXEC | \ 210f15cbe6fSPaul Mundt _PAGE_EXT_USER_WRITE | \ 211f15cbe6fSPaul Mundt _PAGE_EXT_USER_READ | \ 212f15cbe6fSPaul Mundt _PAGE_EXT_USER_EXEC)) 213f15cbe6fSPaul Mundt 214f15cbe6fSPaul Mundt #define PAGE_KERNEL __pgprot(_PAGE_PRESENT | _PAGE_CACHABLE | \ 215f15cbe6fSPaul Mundt _PAGE_DIRTY | _PAGE_ACCESSED | \ 216f15cbe6fSPaul Mundt _PAGE_HW_SHARED | _PAGE_FLAGS_HARD | \ 217f15cbe6fSPaul Mundt _PAGE_EXT(_PAGE_EXT_KERN_READ | \ 218f15cbe6fSPaul Mundt _PAGE_EXT_KERN_WRITE | \ 219f15cbe6fSPaul Mundt _PAGE_EXT_KERN_EXEC)) 220f15cbe6fSPaul Mundt 221f15cbe6fSPaul Mundt #define PAGE_KERNEL_NOCACHE \ 222f15cbe6fSPaul Mundt __pgprot(_PAGE_PRESENT | _PAGE_DIRTY | \ 223f15cbe6fSPaul Mundt _PAGE_ACCESSED | _PAGE_HW_SHARED | \ 224f15cbe6fSPaul Mundt _PAGE_FLAGS_HARD | \ 225f15cbe6fSPaul Mundt _PAGE_EXT(_PAGE_EXT_KERN_READ | \ 226f15cbe6fSPaul Mundt _PAGE_EXT_KERN_WRITE | \ 227f15cbe6fSPaul Mundt _PAGE_EXT_KERN_EXEC)) 228f15cbe6fSPaul Mundt 229f15cbe6fSPaul Mundt #define PAGE_KERNEL_RO __pgprot(_PAGE_PRESENT | _PAGE_CACHABLE | \ 230f15cbe6fSPaul Mundt _PAGE_DIRTY | _PAGE_ACCESSED | \ 231f15cbe6fSPaul Mundt _PAGE_HW_SHARED | _PAGE_FLAGS_HARD | \ 232f15cbe6fSPaul Mundt _PAGE_EXT(_PAGE_EXT_KERN_READ | \ 233f15cbe6fSPaul Mundt _PAGE_EXT_KERN_EXEC)) 234f15cbe6fSPaul Mundt 235f15cbe6fSPaul Mundt #define PAGE_KERNEL_PCC(slot, type) \ 23611e1ed6eSPaul Mundt __pgprot(0) 237f15cbe6fSPaul Mundt 238f15cbe6fSPaul Mundt #elif defined(CONFIG_MMU) /* SH-X TLB */ 239f15cbe6fSPaul Mundt #define PAGE_NONE __pgprot(_PAGE_PROTNONE | _PAGE_CACHABLE | \ 240f15cbe6fSPaul Mundt _PAGE_ACCESSED | _PAGE_FLAGS_HARD) 241f15cbe6fSPaul Mundt 242f15cbe6fSPaul Mundt #define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | \ 243f15cbe6fSPaul Mundt _PAGE_CACHABLE | _PAGE_ACCESSED | \ 244f15cbe6fSPaul Mundt _PAGE_FLAGS_HARD) 245f15cbe6fSPaul Mundt 246f15cbe6fSPaul Mundt #define PAGE_COPY __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_CACHABLE | \ 247f15cbe6fSPaul Mundt _PAGE_ACCESSED | _PAGE_FLAGS_HARD) 248f15cbe6fSPaul Mundt 249f15cbe6fSPaul Mundt #define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_CACHABLE | \ 250f15cbe6fSPaul Mundt _PAGE_ACCESSED | _PAGE_FLAGS_HARD) 251f15cbe6fSPaul Mundt 252f15cbe6fSPaul Mundt #define PAGE_EXECREAD PAGE_READONLY 253f15cbe6fSPaul Mundt #define PAGE_RWX PAGE_SHARED 254f15cbe6fSPaul Mundt #define PAGE_WRITEONLY PAGE_SHARED 255f15cbe6fSPaul Mundt 256f15cbe6fSPaul Mundt #define PAGE_KERNEL __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_CACHABLE | \ 257f15cbe6fSPaul Mundt _PAGE_DIRTY | _PAGE_ACCESSED | \ 258f15cbe6fSPaul Mundt _PAGE_HW_SHARED | _PAGE_FLAGS_HARD) 259f15cbe6fSPaul Mundt 260f15cbe6fSPaul Mundt #define PAGE_KERNEL_NOCACHE \ 261f15cbe6fSPaul Mundt __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | \ 262f15cbe6fSPaul Mundt _PAGE_ACCESSED | _PAGE_HW_SHARED | \ 263f15cbe6fSPaul Mundt _PAGE_FLAGS_HARD) 264f15cbe6fSPaul Mundt 265f15cbe6fSPaul Mundt #define PAGE_KERNEL_RO __pgprot(_PAGE_PRESENT | _PAGE_CACHABLE | \ 266f15cbe6fSPaul Mundt _PAGE_DIRTY | _PAGE_ACCESSED | \ 267f15cbe6fSPaul Mundt _PAGE_HW_SHARED | _PAGE_FLAGS_HARD) 268f15cbe6fSPaul Mundt 269f15cbe6fSPaul Mundt #define PAGE_KERNEL_PCC(slot, type) \ 270f15cbe6fSPaul Mundt __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | \ 271f15cbe6fSPaul Mundt _PAGE_ACCESSED | _PAGE_FLAGS_HARD | \ 272f15cbe6fSPaul Mundt (slot ? _PAGE_PCC_AREA5 : _PAGE_PCC_AREA6) | \ 273f15cbe6fSPaul Mundt (type)) 274f15cbe6fSPaul Mundt #else /* no mmu */ 275f15cbe6fSPaul Mundt #define PAGE_NONE __pgprot(0) 276f15cbe6fSPaul Mundt #define PAGE_SHARED __pgprot(0) 277f15cbe6fSPaul Mundt #define PAGE_COPY __pgprot(0) 278f15cbe6fSPaul Mundt #define PAGE_EXECREAD __pgprot(0) 279f15cbe6fSPaul Mundt #define PAGE_RWX __pgprot(0) 280f15cbe6fSPaul Mundt #define PAGE_READONLY __pgprot(0) 281f15cbe6fSPaul Mundt #define PAGE_WRITEONLY __pgprot(0) 282f15cbe6fSPaul Mundt #define PAGE_KERNEL __pgprot(0) 283f15cbe6fSPaul Mundt #define PAGE_KERNEL_NOCACHE __pgprot(0) 284f15cbe6fSPaul Mundt #define PAGE_KERNEL_RO __pgprot(0) 285f15cbe6fSPaul Mundt 286f15cbe6fSPaul Mundt #define PAGE_KERNEL_PCC(slot, type) \ 287f15cbe6fSPaul Mundt __pgprot(0) 288f15cbe6fSPaul Mundt #endif 289f15cbe6fSPaul Mundt 290f15cbe6fSPaul Mundt #endif /* __ASSEMBLY__ */ 291f15cbe6fSPaul Mundt 292f15cbe6fSPaul Mundt #ifndef __ASSEMBLY__ 293f15cbe6fSPaul Mundt 294f15cbe6fSPaul Mundt /* 295f15cbe6fSPaul Mundt * Certain architectures need to do special things when PTEs 296f15cbe6fSPaul Mundt * within a page table are directly modified. Thus, the following 297f15cbe6fSPaul Mundt * hook is made available. 298f15cbe6fSPaul Mundt */ 299f15cbe6fSPaul Mundt #ifdef CONFIG_X2TLB 300f15cbe6fSPaul Mundt static inline void set_pte(pte_t *ptep, pte_t pte) 301f15cbe6fSPaul Mundt { 302f15cbe6fSPaul Mundt ptep->pte_high = pte.pte_high; 303f15cbe6fSPaul Mundt smp_wmb(); 304f15cbe6fSPaul Mundt ptep->pte_low = pte.pte_low; 305f15cbe6fSPaul Mundt } 306f15cbe6fSPaul Mundt #else 307f15cbe6fSPaul Mundt #define set_pte(pteptr, pteval) (*(pteptr) = pteval) 308f15cbe6fSPaul Mundt #endif 309f15cbe6fSPaul Mundt 310f15cbe6fSPaul Mundt #define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval) 311f15cbe6fSPaul Mundt 312f15cbe6fSPaul Mundt /* 313f15cbe6fSPaul Mundt * (pmds are folded into pgds so this doesn't get actually called, 314f15cbe6fSPaul Mundt * but the define is needed for a generic inline function.) 315f15cbe6fSPaul Mundt */ 316f15cbe6fSPaul Mundt #define set_pmd(pmdptr, pmdval) (*(pmdptr) = pmdval) 317f15cbe6fSPaul Mundt 318f15cbe6fSPaul Mundt #define pfn_pte(pfn, prot) \ 319f15cbe6fSPaul Mundt __pte(((unsigned long long)(pfn) << PAGE_SHIFT) | pgprot_val(prot)) 320f15cbe6fSPaul Mundt #define pfn_pmd(pfn, prot) \ 321f15cbe6fSPaul Mundt __pmd(((unsigned long long)(pfn) << PAGE_SHIFT) | pgprot_val(prot)) 322f15cbe6fSPaul Mundt 323f15cbe6fSPaul Mundt #define pte_none(x) (!pte_val(x)) 324f15cbe6fSPaul Mundt #define pte_present(x) ((x).pte_low & (_PAGE_PRESENT | _PAGE_PROTNONE)) 325f15cbe6fSPaul Mundt 326f15cbe6fSPaul Mundt #define pte_clear(mm,addr,xp) do { set_pte_at(mm, addr, xp, __pte(0)); } while (0) 327f15cbe6fSPaul Mundt 328f15cbe6fSPaul Mundt #define pmd_none(x) (!pmd_val(x)) 329f15cbe6fSPaul Mundt #define pmd_present(x) (pmd_val(x)) 330f15cbe6fSPaul Mundt #define pmd_clear(xp) do { set_pmd(xp, __pmd(0)); } while (0) 331f15cbe6fSPaul Mundt #define pmd_bad(x) (pmd_val(x) & ~PAGE_MASK) 332f15cbe6fSPaul Mundt 333f15cbe6fSPaul Mundt #define pages_to_mb(x) ((x) >> (20-PAGE_SHIFT)) 334f15cbe6fSPaul Mundt #define pte_page(x) pfn_to_page(pte_pfn(x)) 335f15cbe6fSPaul Mundt 336f15cbe6fSPaul Mundt /* 337f15cbe6fSPaul Mundt * The following only work if pte_present() is true. 338f15cbe6fSPaul Mundt * Undefined behaviour if not.. 339f15cbe6fSPaul Mundt */ 340f15cbe6fSPaul Mundt #define pte_not_present(pte) (!((pte).pte_low & _PAGE_PRESENT)) 341f15cbe6fSPaul Mundt #define pte_dirty(pte) ((pte).pte_low & _PAGE_DIRTY) 342f15cbe6fSPaul Mundt #define pte_young(pte) ((pte).pte_low & _PAGE_ACCESSED) 343c0b96cf6SPaul Mundt #define pte_special(pte) ((pte).pte_low & _PAGE_SPECIAL) 344f15cbe6fSPaul Mundt 345f15cbe6fSPaul Mundt #ifdef CONFIG_X2TLB 346fcb4ebd6SMatt Fleming #define pte_write(pte) \ 347fcb4ebd6SMatt Fleming ((pte).pte_high & (_PAGE_EXT_USER_WRITE | _PAGE_EXT_KERN_WRITE)) 348f15cbe6fSPaul Mundt #else 349f15cbe6fSPaul Mundt #define pte_write(pte) ((pte).pte_low & _PAGE_RW) 350f15cbe6fSPaul Mundt #endif 351f15cbe6fSPaul Mundt 352f15cbe6fSPaul Mundt #define PTE_BIT_FUNC(h,fn,op) \ 353f15cbe6fSPaul Mundt static inline pte_t pte_##fn(pte_t pte) { pte.pte_##h op; return pte; } 354f15cbe6fSPaul Mundt 355f15cbe6fSPaul Mundt #ifdef CONFIG_X2TLB 356f15cbe6fSPaul Mundt /* 357f15cbe6fSPaul Mundt * We cheat a bit in the SH-X2 TLB case. As the permission bits are 358f15cbe6fSPaul Mundt * individually toggled (and user permissions are entirely decoupled from 359f15cbe6fSPaul Mundt * kernel permissions), we attempt to couple them a bit more sanely here. 360f15cbe6fSPaul Mundt */ 361fcb4ebd6SMatt Fleming PTE_BIT_FUNC(high, wrprotect, &= ~(_PAGE_EXT_USER_WRITE | _PAGE_EXT_KERN_WRITE)); 362f15cbe6fSPaul Mundt PTE_BIT_FUNC(high, mkwrite, |= _PAGE_EXT_USER_WRITE | _PAGE_EXT_KERN_WRITE); 363f15cbe6fSPaul Mundt PTE_BIT_FUNC(high, mkhuge, |= _PAGE_SZHUGE); 364f15cbe6fSPaul Mundt #else 365f15cbe6fSPaul Mundt PTE_BIT_FUNC(low, wrprotect, &= ~_PAGE_RW); 366f15cbe6fSPaul Mundt PTE_BIT_FUNC(low, mkwrite, |= _PAGE_RW); 367f15cbe6fSPaul Mundt PTE_BIT_FUNC(low, mkhuge, |= _PAGE_SZHUGE); 368f15cbe6fSPaul Mundt #endif 369f15cbe6fSPaul Mundt 370f15cbe6fSPaul Mundt PTE_BIT_FUNC(low, mkclean, &= ~_PAGE_DIRTY); 371f15cbe6fSPaul Mundt PTE_BIT_FUNC(low, mkdirty, |= _PAGE_DIRTY); 372f15cbe6fSPaul Mundt PTE_BIT_FUNC(low, mkold, &= ~_PAGE_ACCESSED); 373f15cbe6fSPaul Mundt PTE_BIT_FUNC(low, mkyoung, |= _PAGE_ACCESSED); 374c0b96cf6SPaul Mundt PTE_BIT_FUNC(low, mkspecial, |= _PAGE_SPECIAL); 375f15cbe6fSPaul Mundt 376f15cbe6fSPaul Mundt /* 377f15cbe6fSPaul Mundt * Macro and implementation to make a page protection as uncachable. 378f15cbe6fSPaul Mundt */ 379f15cbe6fSPaul Mundt #define pgprot_writecombine(prot) \ 380f15cbe6fSPaul Mundt __pgprot(pgprot_val(prot) & ~_PAGE_CACHABLE) 381f15cbe6fSPaul Mundt 382f15cbe6fSPaul Mundt #define pgprot_noncached pgprot_writecombine 383f15cbe6fSPaul Mundt 384f15cbe6fSPaul Mundt /* 385f15cbe6fSPaul Mundt * Conversion functions: convert a page and protection to a page entry, 386f15cbe6fSPaul Mundt * and a page entry and page directory to the page they refer to. 387f15cbe6fSPaul Mundt * 388f15cbe6fSPaul Mundt * extern pte_t mk_pte(struct page *page, pgprot_t pgprot) 389f15cbe6fSPaul Mundt */ 390f15cbe6fSPaul Mundt #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot)) 391f15cbe6fSPaul Mundt 392f15cbe6fSPaul Mundt static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) 393f15cbe6fSPaul Mundt { 394f15cbe6fSPaul Mundt pte.pte_low &= _PAGE_CHG_MASK; 395f15cbe6fSPaul Mundt pte.pte_low |= pgprot_val(newprot); 396f15cbe6fSPaul Mundt 397f15cbe6fSPaul Mundt #ifdef CONFIG_X2TLB 398f15cbe6fSPaul Mundt pte.pte_high |= pgprot_val(newprot) >> 32; 399f15cbe6fSPaul Mundt #endif 400f15cbe6fSPaul Mundt 401f15cbe6fSPaul Mundt return pte; 402f15cbe6fSPaul Mundt } 403f15cbe6fSPaul Mundt 404974b9b2cSMike Rapoport static inline unsigned long pmd_page_vaddr(pmd_t pmd) 405974b9b2cSMike Rapoport { 406974b9b2cSMike Rapoport return (unsigned long)pmd_val(pmd); 407974b9b2cSMike Rapoport } 408974b9b2cSMike Rapoport 409*7106c51eSMike Rapoport #define pmd_pfn(pmd) (__pa(pmd_val(pmd)) >> PAGE_SHIFT) 410f15cbe6fSPaul Mundt #define pmd_page(pmd) (virt_to_page(pmd_val(pmd))) 411f15cbe6fSPaul Mundt 412f15cbe6fSPaul Mundt #ifdef CONFIG_X2TLB 413f15cbe6fSPaul Mundt #define pte_ERROR(e) \ 414f15cbe6fSPaul Mundt printk("%s:%d: bad pte %p(%08lx%08lx).\n", __FILE__, __LINE__, \ 415f15cbe6fSPaul Mundt &(e), (e).pte_high, (e).pte_low) 416f15cbe6fSPaul Mundt #define pgd_ERROR(e) \ 417f15cbe6fSPaul Mundt printk("%s:%d: bad pgd %016llx.\n", __FILE__, __LINE__, pgd_val(e)) 418f15cbe6fSPaul Mundt #else 419f15cbe6fSPaul Mundt #define pte_ERROR(e) \ 420f15cbe6fSPaul Mundt printk("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, pte_val(e)) 421f15cbe6fSPaul Mundt #define pgd_ERROR(e) \ 422f15cbe6fSPaul Mundt printk("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e)) 423f15cbe6fSPaul Mundt #endif 424f15cbe6fSPaul Mundt 425f15cbe6fSPaul Mundt /* 426f15cbe6fSPaul Mundt * Encode and de-code a swap entry 427f15cbe6fSPaul Mundt * 428f15cbe6fSPaul Mundt * Constraints: 429f15cbe6fSPaul Mundt * _PAGE_PRESENT at bit 8 430f15cbe6fSPaul Mundt * _PAGE_PROTNONE at bit 9 431f15cbe6fSPaul Mundt * 432f15cbe6fSPaul Mundt * For the normal case, we encode the swap type into bits 0:7 and the 433f15cbe6fSPaul Mundt * swap offset into bits 10:30. For the 64-bit PTE case, we keep the 434f15cbe6fSPaul Mundt * preserved bits in the low 32-bits and use the upper 32 as the swap 435f15cbe6fSPaul Mundt * offset (along with a 5-bit type), following the same approach as x86 4368b70beacSKirill A. Shutemov * PAE. This keeps the logic quite simple. 437f15cbe6fSPaul Mundt * 438f15cbe6fSPaul Mundt * As is evident by the Alpha code, if we ever get a 64-bit unsigned 439f15cbe6fSPaul Mundt * long (swp_entry_t) to match up with the 64-bit PTEs, this all becomes 440f15cbe6fSPaul Mundt * much cleaner.. 441f15cbe6fSPaul Mundt * 442f15cbe6fSPaul Mundt * NOTE: We should set ZEROs at the position of _PAGE_PRESENT 443f15cbe6fSPaul Mundt * and _PAGE_PROTNONE bits 444f15cbe6fSPaul Mundt */ 445f15cbe6fSPaul Mundt #ifdef CONFIG_X2TLB 446f15cbe6fSPaul Mundt #define __swp_type(x) ((x).val & 0x1f) 447f15cbe6fSPaul Mundt #define __swp_offset(x) ((x).val >> 5) 448f15cbe6fSPaul Mundt #define __swp_entry(type, offset) ((swp_entry_t){ (type) | (offset) << 5}) 449f15cbe6fSPaul Mundt #define __pte_to_swp_entry(pte) ((swp_entry_t){ (pte).pte_high }) 450f15cbe6fSPaul Mundt #define __swp_entry_to_pte(x) ((pte_t){ 0, (x).val }) 451f15cbe6fSPaul Mundt 452f15cbe6fSPaul Mundt #else 453f15cbe6fSPaul Mundt #define __swp_type(x) ((x).val & 0xff) 454f15cbe6fSPaul Mundt #define __swp_offset(x) ((x).val >> 10) 455f15cbe6fSPaul Mundt #define __swp_entry(type, offset) ((swp_entry_t){(type) | (offset) <<10}) 456f15cbe6fSPaul Mundt 457f15cbe6fSPaul Mundt #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) >> 1 }) 458f15cbe6fSPaul Mundt #define __swp_entry_to_pte(x) ((pte_t) { (x).val << 1 }) 459f15cbe6fSPaul Mundt #endif 460f15cbe6fSPaul Mundt 461f15cbe6fSPaul Mundt #endif /* __ASSEMBLY__ */ 462f15cbe6fSPaul Mundt #endif /* __ASM_SH_PGTABLE_32_H */ 463