1f15cbe6fSPaul Mundt #ifndef __ASM_SH_PGTABLE_32_H 2f15cbe6fSPaul Mundt #define __ASM_SH_PGTABLE_32_H 3f15cbe6fSPaul Mundt 4f15cbe6fSPaul Mundt /* 5f15cbe6fSPaul Mundt * Linux PTEL encoding. 6f15cbe6fSPaul Mundt * 7f15cbe6fSPaul Mundt * Hardware and software bit definitions for the PTEL value (see below for 8f15cbe6fSPaul Mundt * notes on SH-X2 MMUs and 64-bit PTEs): 9f15cbe6fSPaul Mundt * 10f15cbe6fSPaul Mundt * - Bits 0 and 7 are reserved on SH-3 (_PAGE_WT and _PAGE_SZ1 on SH-4). 11f15cbe6fSPaul Mundt * 12f15cbe6fSPaul Mundt * - Bit 1 is the SH-bit, but is unused on SH-3 due to an MMU bug (the 13f15cbe6fSPaul Mundt * hardware PTEL value can't have the SH-bit set when MMUCR.IX is set, 14f15cbe6fSPaul Mundt * which is the default in cpu-sh3/mmu_context.h:MMU_CONTROL_INIT). 15f15cbe6fSPaul Mundt * 16f15cbe6fSPaul Mundt * In order to keep this relatively clean, do not use these for defining 17f15cbe6fSPaul Mundt * SH-3 specific flags until all of the other unused bits have been 18f15cbe6fSPaul Mundt * exhausted. 19f15cbe6fSPaul Mundt * 20f15cbe6fSPaul Mundt * - Bit 9 is reserved by everyone and used by _PAGE_PROTNONE. 21f15cbe6fSPaul Mundt * 22f15cbe6fSPaul Mundt * - Bits 10 and 11 are low bits of the PPN that are reserved on >= 4K pages. 23c0b96cf6SPaul Mundt * Bit 10 is used for _PAGE_ACCESSED, and bit 11 is used for _PAGE_SPECIAL. 24f15cbe6fSPaul Mundt * 25f15cbe6fSPaul Mundt * - On 29 bit platforms, bits 31 to 29 are used for the space attributes 26f15cbe6fSPaul Mundt * and timing control which (together with bit 0) are moved into the 27f15cbe6fSPaul Mundt * old-style PTEA on the parts that support it. 28f15cbe6fSPaul Mundt * 29f15cbe6fSPaul Mundt * XXX: Leave the _PAGE_FILE and _PAGE_WT overhaul for a rainy day. 30f15cbe6fSPaul Mundt * 31f15cbe6fSPaul Mundt * SH-X2 MMUs and extended PTEs 32f15cbe6fSPaul Mundt * 33f15cbe6fSPaul Mundt * SH-X2 supports an extended mode TLB with split data arrays due to the 34f15cbe6fSPaul Mundt * number of bits needed for PR and SZ (now EPR and ESZ) encodings. The PR and 35f15cbe6fSPaul Mundt * SZ bit placeholders still exist in data array 1, but are implemented as 36f15cbe6fSPaul Mundt * reserved bits, with the real logic existing in data array 2. 37f15cbe6fSPaul Mundt * 38f15cbe6fSPaul Mundt * The downside to this is that we can no longer fit everything in to a 32-bit 39f15cbe6fSPaul Mundt * PTE encoding, so a 64-bit pte_t is necessary for these parts. On the plus 40f15cbe6fSPaul Mundt * side, this gives us quite a few spare bits to play with for future usage. 41f15cbe6fSPaul Mundt */ 42f15cbe6fSPaul Mundt /* Legacy and compat mode bits */ 43f15cbe6fSPaul Mundt #define _PAGE_WT 0x001 /* WT-bit on SH-4, 0 on SH-3 */ 44f15cbe6fSPaul Mundt #define _PAGE_HW_SHARED 0x002 /* SH-bit : shared among processes */ 45f15cbe6fSPaul Mundt #define _PAGE_DIRTY 0x004 /* D-bit : page changed */ 46f15cbe6fSPaul Mundt #define _PAGE_CACHABLE 0x008 /* C-bit : cachable */ 47f15cbe6fSPaul Mundt #define _PAGE_SZ0 0x010 /* SZ0-bit : Size of page */ 48f15cbe6fSPaul Mundt #define _PAGE_RW 0x020 /* PR0-bit : write access allowed */ 49f15cbe6fSPaul Mundt #define _PAGE_USER 0x040 /* PR1-bit : user space access allowed*/ 50f15cbe6fSPaul Mundt #define _PAGE_SZ1 0x080 /* SZ1-bit : Size of page (on SH-4) */ 51f15cbe6fSPaul Mundt #define _PAGE_PRESENT 0x100 /* V-bit : page is valid */ 52f15cbe6fSPaul Mundt #define _PAGE_PROTNONE 0x200 /* software: if not present */ 53f15cbe6fSPaul Mundt #define _PAGE_ACCESSED 0x400 /* software: page referenced */ 54f15cbe6fSPaul Mundt #define _PAGE_FILE _PAGE_WT /* software: pagecache or swap? */ 55c0b96cf6SPaul Mundt #define _PAGE_SPECIAL 0x800 /* software: special page */ 56f15cbe6fSPaul Mundt 57f15cbe6fSPaul Mundt #define _PAGE_SZ_MASK (_PAGE_SZ0 | _PAGE_SZ1) 58f15cbe6fSPaul Mundt #define _PAGE_PR_MASK (_PAGE_RW | _PAGE_USER) 59f15cbe6fSPaul Mundt 60f15cbe6fSPaul Mundt /* Extended mode bits */ 61f15cbe6fSPaul Mundt #define _PAGE_EXT_ESZ0 0x0010 /* ESZ0-bit: Size of page */ 62f15cbe6fSPaul Mundt #define _PAGE_EXT_ESZ1 0x0020 /* ESZ1-bit: Size of page */ 63f15cbe6fSPaul Mundt #define _PAGE_EXT_ESZ2 0x0040 /* ESZ2-bit: Size of page */ 64f15cbe6fSPaul Mundt #define _PAGE_EXT_ESZ3 0x0080 /* ESZ3-bit: Size of page */ 65f15cbe6fSPaul Mundt 66f15cbe6fSPaul Mundt #define _PAGE_EXT_USER_EXEC 0x0100 /* EPR0-bit: User space executable */ 67f15cbe6fSPaul Mundt #define _PAGE_EXT_USER_WRITE 0x0200 /* EPR1-bit: User space writable */ 68f15cbe6fSPaul Mundt #define _PAGE_EXT_USER_READ 0x0400 /* EPR2-bit: User space readable */ 69f15cbe6fSPaul Mundt 70f15cbe6fSPaul Mundt #define _PAGE_EXT_KERN_EXEC 0x0800 /* EPR3-bit: Kernel space executable */ 71f15cbe6fSPaul Mundt #define _PAGE_EXT_KERN_WRITE 0x1000 /* EPR4-bit: Kernel space writable */ 72f15cbe6fSPaul Mundt #define _PAGE_EXT_KERN_READ 0x2000 /* EPR5-bit: Kernel space readable */ 73f15cbe6fSPaul Mundt 74f15cbe6fSPaul Mundt /* Wrapper for extended mode pgprot twiddling */ 75f15cbe6fSPaul Mundt #define _PAGE_EXT(x) ((unsigned long long)(x) << 32) 76f15cbe6fSPaul Mundt 77f15cbe6fSPaul Mundt /* software: moves to PTEA.TC (Timing Control) */ 78f15cbe6fSPaul Mundt #define _PAGE_PCC_AREA5 0x00000000 /* use BSC registers for area5 */ 79f15cbe6fSPaul Mundt #define _PAGE_PCC_AREA6 0x80000000 /* use BSC registers for area6 */ 80f15cbe6fSPaul Mundt 81f15cbe6fSPaul Mundt /* software: moves to PTEA.SA[2:0] (Space Attributes) */ 82f15cbe6fSPaul Mundt #define _PAGE_PCC_IODYN 0x00000001 /* IO space, dynamically sized bus */ 83f15cbe6fSPaul Mundt #define _PAGE_PCC_IO8 0x20000000 /* IO space, 8 bit bus */ 84f15cbe6fSPaul Mundt #define _PAGE_PCC_IO16 0x20000001 /* IO space, 16 bit bus */ 85f15cbe6fSPaul Mundt #define _PAGE_PCC_COM8 0x40000000 /* Common Memory space, 8 bit bus */ 86f15cbe6fSPaul Mundt #define _PAGE_PCC_COM16 0x40000001 /* Common Memory space, 16 bit bus */ 87f15cbe6fSPaul Mundt #define _PAGE_PCC_ATR8 0x60000000 /* Attribute Memory space, 8 bit bus */ 88f15cbe6fSPaul Mundt #define _PAGE_PCC_ATR16 0x60000001 /* Attribute Memory space, 6 bit bus */ 89f15cbe6fSPaul Mundt 906503fe4aSMichael Trimarchi #ifndef CONFIG_X2TLB 916503fe4aSMichael Trimarchi /* copy the ptea attributes */ 926503fe4aSMichael Trimarchi static inline unsigned long copy_ptea_attributes(unsigned long x) 936503fe4aSMichael Trimarchi { 946503fe4aSMichael Trimarchi return ((x >> 28) & 0xe) | (x & 0x1); 956503fe4aSMichael Trimarchi } 966503fe4aSMichael Trimarchi #endif 976503fe4aSMichael Trimarchi 98f15cbe6fSPaul Mundt /* Mask which drops unused bits from the PTEL value */ 99f15cbe6fSPaul Mundt #if defined(CONFIG_CPU_SH3) 100f15cbe6fSPaul Mundt #define _PAGE_CLEAR_FLAGS (_PAGE_PROTNONE | _PAGE_ACCESSED| \ 101f15cbe6fSPaul Mundt _PAGE_FILE | _PAGE_SZ1 | \ 102f15cbe6fSPaul Mundt _PAGE_HW_SHARED) 103f15cbe6fSPaul Mundt #elif defined(CONFIG_X2TLB) 104f15cbe6fSPaul Mundt /* Get rid of the legacy PR/SZ bits when using extended mode */ 105f15cbe6fSPaul Mundt #define _PAGE_CLEAR_FLAGS (_PAGE_PROTNONE | _PAGE_ACCESSED | \ 106f15cbe6fSPaul Mundt _PAGE_FILE | _PAGE_PR_MASK | _PAGE_SZ_MASK) 107f15cbe6fSPaul Mundt #else 108f15cbe6fSPaul Mundt #define _PAGE_CLEAR_FLAGS (_PAGE_PROTNONE | _PAGE_ACCESSED | _PAGE_FILE) 109f15cbe6fSPaul Mundt #endif 110f15cbe6fSPaul Mundt 111*1f69b6afSMatt Fleming #define _PAGE_FLAGS_HARDWARE_MASK (phys_addr_mask() & ~(_PAGE_CLEAR_FLAGS)) 112f15cbe6fSPaul Mundt 113f15cbe6fSPaul Mundt /* Hardware flags, page size encoding */ 114f15cbe6fSPaul Mundt #if !defined(CONFIG_MMU) 115f15cbe6fSPaul Mundt # define _PAGE_FLAGS_HARD 0ULL 116f15cbe6fSPaul Mundt #elif defined(CONFIG_X2TLB) 117f15cbe6fSPaul Mundt # if defined(CONFIG_PAGE_SIZE_4KB) 118f15cbe6fSPaul Mundt # define _PAGE_FLAGS_HARD _PAGE_EXT(_PAGE_EXT_ESZ0) 119f15cbe6fSPaul Mundt # elif defined(CONFIG_PAGE_SIZE_8KB) 120f15cbe6fSPaul Mundt # define _PAGE_FLAGS_HARD _PAGE_EXT(_PAGE_EXT_ESZ1) 121f15cbe6fSPaul Mundt # elif defined(CONFIG_PAGE_SIZE_64KB) 122f15cbe6fSPaul Mundt # define _PAGE_FLAGS_HARD _PAGE_EXT(_PAGE_EXT_ESZ2) 123f15cbe6fSPaul Mundt # endif 124f15cbe6fSPaul Mundt #else 125f15cbe6fSPaul Mundt # if defined(CONFIG_PAGE_SIZE_4KB) 126f15cbe6fSPaul Mundt # define _PAGE_FLAGS_HARD _PAGE_SZ0 127f15cbe6fSPaul Mundt # elif defined(CONFIG_PAGE_SIZE_64KB) 128f15cbe6fSPaul Mundt # define _PAGE_FLAGS_HARD _PAGE_SZ1 129f15cbe6fSPaul Mundt # endif 130f15cbe6fSPaul Mundt #endif 131f15cbe6fSPaul Mundt 132f15cbe6fSPaul Mundt #if defined(CONFIG_X2TLB) 133f15cbe6fSPaul Mundt # if defined(CONFIG_HUGETLB_PAGE_SIZE_64K) 134f15cbe6fSPaul Mundt # define _PAGE_SZHUGE (_PAGE_EXT_ESZ2) 135f15cbe6fSPaul Mundt # elif defined(CONFIG_HUGETLB_PAGE_SIZE_256K) 136f15cbe6fSPaul Mundt # define _PAGE_SZHUGE (_PAGE_EXT_ESZ0 | _PAGE_EXT_ESZ2) 137f15cbe6fSPaul Mundt # elif defined(CONFIG_HUGETLB_PAGE_SIZE_1MB) 138f15cbe6fSPaul Mundt # define _PAGE_SZHUGE (_PAGE_EXT_ESZ0 | _PAGE_EXT_ESZ1 | _PAGE_EXT_ESZ2) 139f15cbe6fSPaul Mundt # elif defined(CONFIG_HUGETLB_PAGE_SIZE_4MB) 140f15cbe6fSPaul Mundt # define _PAGE_SZHUGE (_PAGE_EXT_ESZ3) 141f15cbe6fSPaul Mundt # elif defined(CONFIG_HUGETLB_PAGE_SIZE_64MB) 142f15cbe6fSPaul Mundt # define _PAGE_SZHUGE (_PAGE_EXT_ESZ2 | _PAGE_EXT_ESZ3) 143f15cbe6fSPaul Mundt # endif 144f15cbe6fSPaul Mundt #else 145f15cbe6fSPaul Mundt # if defined(CONFIG_HUGETLB_PAGE_SIZE_64K) 146f15cbe6fSPaul Mundt # define _PAGE_SZHUGE (_PAGE_SZ1) 147f15cbe6fSPaul Mundt # elif defined(CONFIG_HUGETLB_PAGE_SIZE_1MB) 148f15cbe6fSPaul Mundt # define _PAGE_SZHUGE (_PAGE_SZ0 | _PAGE_SZ1) 149f15cbe6fSPaul Mundt # endif 150f15cbe6fSPaul Mundt #endif 151f15cbe6fSPaul Mundt 152f15cbe6fSPaul Mundt /* 153f15cbe6fSPaul Mundt * Stub out _PAGE_SZHUGE if we don't have a good definition for it, 154f15cbe6fSPaul Mundt * to make pte_mkhuge() happy. 155f15cbe6fSPaul Mundt */ 156f15cbe6fSPaul Mundt #ifndef _PAGE_SZHUGE 157f15cbe6fSPaul Mundt # define _PAGE_SZHUGE (_PAGE_FLAGS_HARD) 158f15cbe6fSPaul Mundt #endif 159f15cbe6fSPaul Mundt 160c0b96cf6SPaul Mundt /* 161c0b96cf6SPaul Mundt * Mask of bits that are to be preserved accross pgprot changes. 162c0b96cf6SPaul Mundt */ 163f15cbe6fSPaul Mundt #define _PAGE_CHG_MASK \ 164c0b96cf6SPaul Mundt (PTE_MASK | _PAGE_ACCESSED | _PAGE_CACHABLE | \ 165c0b96cf6SPaul Mundt _PAGE_DIRTY | _PAGE_SPECIAL) 166f15cbe6fSPaul Mundt 167f15cbe6fSPaul Mundt #ifndef __ASSEMBLY__ 168f15cbe6fSPaul Mundt 169f15cbe6fSPaul Mundt #if defined(CONFIG_X2TLB) /* SH-X2 TLB */ 170f15cbe6fSPaul Mundt #define PAGE_NONE __pgprot(_PAGE_PROTNONE | _PAGE_CACHABLE | \ 171f15cbe6fSPaul Mundt _PAGE_ACCESSED | _PAGE_FLAGS_HARD) 172f15cbe6fSPaul Mundt 173f15cbe6fSPaul Mundt #define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED | \ 174f15cbe6fSPaul Mundt _PAGE_CACHABLE | _PAGE_FLAGS_HARD | \ 175f15cbe6fSPaul Mundt _PAGE_EXT(_PAGE_EXT_KERN_READ | \ 176f15cbe6fSPaul Mundt _PAGE_EXT_KERN_WRITE | \ 177f15cbe6fSPaul Mundt _PAGE_EXT_USER_READ | \ 178f15cbe6fSPaul Mundt _PAGE_EXT_USER_WRITE)) 179f15cbe6fSPaul Mundt 180f15cbe6fSPaul Mundt #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED | \ 181f15cbe6fSPaul Mundt _PAGE_CACHABLE | _PAGE_FLAGS_HARD | \ 182f15cbe6fSPaul Mundt _PAGE_EXT(_PAGE_EXT_KERN_EXEC | \ 183f15cbe6fSPaul Mundt _PAGE_EXT_KERN_READ | \ 184f15cbe6fSPaul Mundt _PAGE_EXT_USER_EXEC | \ 185f15cbe6fSPaul Mundt _PAGE_EXT_USER_READ)) 186f15cbe6fSPaul Mundt 187f15cbe6fSPaul Mundt #define PAGE_COPY PAGE_EXECREAD 188f15cbe6fSPaul Mundt 189f15cbe6fSPaul Mundt #define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED | \ 190f15cbe6fSPaul Mundt _PAGE_CACHABLE | _PAGE_FLAGS_HARD | \ 191f15cbe6fSPaul Mundt _PAGE_EXT(_PAGE_EXT_KERN_READ | \ 192f15cbe6fSPaul Mundt _PAGE_EXT_USER_READ)) 193f15cbe6fSPaul Mundt 194f15cbe6fSPaul Mundt #define PAGE_WRITEONLY __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED | \ 195f15cbe6fSPaul Mundt _PAGE_CACHABLE | _PAGE_FLAGS_HARD | \ 196f15cbe6fSPaul Mundt _PAGE_EXT(_PAGE_EXT_KERN_WRITE | \ 197f15cbe6fSPaul Mundt _PAGE_EXT_USER_WRITE)) 198f15cbe6fSPaul Mundt 199f15cbe6fSPaul Mundt #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED | \ 200f15cbe6fSPaul Mundt _PAGE_CACHABLE | _PAGE_FLAGS_HARD | \ 201f15cbe6fSPaul Mundt _PAGE_EXT(_PAGE_EXT_KERN_WRITE | \ 202f15cbe6fSPaul Mundt _PAGE_EXT_KERN_READ | \ 203f15cbe6fSPaul Mundt _PAGE_EXT_KERN_EXEC | \ 204f15cbe6fSPaul Mundt _PAGE_EXT_USER_WRITE | \ 205f15cbe6fSPaul Mundt _PAGE_EXT_USER_READ | \ 206f15cbe6fSPaul Mundt _PAGE_EXT_USER_EXEC)) 207f15cbe6fSPaul Mundt 208f15cbe6fSPaul Mundt #define PAGE_KERNEL __pgprot(_PAGE_PRESENT | _PAGE_CACHABLE | \ 209f15cbe6fSPaul Mundt _PAGE_DIRTY | _PAGE_ACCESSED | \ 210f15cbe6fSPaul Mundt _PAGE_HW_SHARED | _PAGE_FLAGS_HARD | \ 211f15cbe6fSPaul Mundt _PAGE_EXT(_PAGE_EXT_KERN_READ | \ 212f15cbe6fSPaul Mundt _PAGE_EXT_KERN_WRITE | \ 213f15cbe6fSPaul Mundt _PAGE_EXT_KERN_EXEC)) 214f15cbe6fSPaul Mundt 215f15cbe6fSPaul Mundt #define PAGE_KERNEL_NOCACHE \ 216f15cbe6fSPaul Mundt __pgprot(_PAGE_PRESENT | _PAGE_DIRTY | \ 217f15cbe6fSPaul Mundt _PAGE_ACCESSED | _PAGE_HW_SHARED | \ 218f15cbe6fSPaul Mundt _PAGE_FLAGS_HARD | \ 219f15cbe6fSPaul Mundt _PAGE_EXT(_PAGE_EXT_KERN_READ | \ 220f15cbe6fSPaul Mundt _PAGE_EXT_KERN_WRITE | \ 221f15cbe6fSPaul Mundt _PAGE_EXT_KERN_EXEC)) 222f15cbe6fSPaul Mundt 223f15cbe6fSPaul Mundt #define PAGE_KERNEL_RO __pgprot(_PAGE_PRESENT | _PAGE_CACHABLE | \ 224f15cbe6fSPaul Mundt _PAGE_DIRTY | _PAGE_ACCESSED | \ 225f15cbe6fSPaul Mundt _PAGE_HW_SHARED | _PAGE_FLAGS_HARD | \ 226f15cbe6fSPaul Mundt _PAGE_EXT(_PAGE_EXT_KERN_READ | \ 227f15cbe6fSPaul Mundt _PAGE_EXT_KERN_EXEC)) 228f15cbe6fSPaul Mundt 229f15cbe6fSPaul Mundt #define PAGE_KERNEL_PCC(slot, type) \ 230f15cbe6fSPaul Mundt __pgprot(_PAGE_PRESENT | _PAGE_DIRTY | \ 231f15cbe6fSPaul Mundt _PAGE_ACCESSED | _PAGE_FLAGS_HARD | \ 232f15cbe6fSPaul Mundt _PAGE_EXT(_PAGE_EXT_KERN_READ | \ 233f15cbe6fSPaul Mundt _PAGE_EXT_KERN_WRITE | \ 234f15cbe6fSPaul Mundt _PAGE_EXT_KERN_EXEC) \ 235f15cbe6fSPaul Mundt (slot ? _PAGE_PCC_AREA5 : _PAGE_PCC_AREA6) | \ 236f15cbe6fSPaul Mundt (type)) 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) 343f15cbe6fSPaul Mundt #define pte_file(pte) ((pte).pte_low & _PAGE_FILE) 344c0b96cf6SPaul Mundt #define pte_special(pte) ((pte).pte_low & _PAGE_SPECIAL) 345f15cbe6fSPaul Mundt 346f15cbe6fSPaul Mundt #ifdef CONFIG_X2TLB 347f15cbe6fSPaul Mundt #define pte_write(pte) ((pte).pte_high & _PAGE_EXT_USER_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 */ 361f15cbe6fSPaul Mundt PTE_BIT_FUNC(high, wrprotect, &= ~_PAGE_EXT_USER_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 376c0b96cf6SPaul Mundt #define __HAVE_ARCH_PTE_SPECIAL 377f15cbe6fSPaul Mundt 378f15cbe6fSPaul Mundt /* 379f15cbe6fSPaul Mundt * Macro and implementation to make a page protection as uncachable. 380f15cbe6fSPaul Mundt */ 381f15cbe6fSPaul Mundt #define pgprot_writecombine(prot) \ 382f15cbe6fSPaul Mundt __pgprot(pgprot_val(prot) & ~_PAGE_CACHABLE) 383f15cbe6fSPaul Mundt 384f15cbe6fSPaul Mundt #define pgprot_noncached pgprot_writecombine 385f15cbe6fSPaul Mundt 386f15cbe6fSPaul Mundt /* 387f15cbe6fSPaul Mundt * Conversion functions: convert a page and protection to a page entry, 388f15cbe6fSPaul Mundt * and a page entry and page directory to the page they refer to. 389f15cbe6fSPaul Mundt * 390f15cbe6fSPaul Mundt * extern pte_t mk_pte(struct page *page, pgprot_t pgprot) 391f15cbe6fSPaul Mundt */ 392f15cbe6fSPaul Mundt #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot)) 393f15cbe6fSPaul Mundt 394f15cbe6fSPaul Mundt static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) 395f15cbe6fSPaul Mundt { 396f15cbe6fSPaul Mundt pte.pte_low &= _PAGE_CHG_MASK; 397f15cbe6fSPaul Mundt pte.pte_low |= pgprot_val(newprot); 398f15cbe6fSPaul Mundt 399f15cbe6fSPaul Mundt #ifdef CONFIG_X2TLB 400f15cbe6fSPaul Mundt pte.pte_high |= pgprot_val(newprot) >> 32; 401f15cbe6fSPaul Mundt #endif 402f15cbe6fSPaul Mundt 403f15cbe6fSPaul Mundt return pte; 404f15cbe6fSPaul Mundt } 405f15cbe6fSPaul Mundt 406f15cbe6fSPaul Mundt #define pmd_page_vaddr(pmd) ((unsigned long)pmd_val(pmd)) 407f15cbe6fSPaul Mundt #define pmd_page(pmd) (virt_to_page(pmd_val(pmd))) 408f15cbe6fSPaul Mundt 409f15cbe6fSPaul Mundt /* to find an entry in a page-table-directory. */ 410f15cbe6fSPaul Mundt #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1)) 411f15cbe6fSPaul Mundt #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address)) 4120906a3adSPaul Mundt #define __pgd_offset(address) pgd_index(address) 413f15cbe6fSPaul Mundt 414f15cbe6fSPaul Mundt /* to find an entry in a kernel page-table-directory */ 415f15cbe6fSPaul Mundt #define pgd_offset_k(address) pgd_offset(&init_mm, address) 416f15cbe6fSPaul Mundt 4170906a3adSPaul Mundt #define __pud_offset(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD-1)) 4180906a3adSPaul Mundt #define __pmd_offset(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1)) 4190906a3adSPaul Mundt 420f15cbe6fSPaul Mundt /* Find an entry in the third-level page table.. */ 421f15cbe6fSPaul Mundt #define pte_index(address) ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)) 4220906a3adSPaul Mundt #define __pte_offset(address) pte_index(address) 4230906a3adSPaul Mundt 424f15cbe6fSPaul Mundt #define pte_offset_kernel(dir, address) \ 425f15cbe6fSPaul Mundt ((pte_t *) pmd_page_vaddr(*(dir)) + pte_index(address)) 426f15cbe6fSPaul Mundt #define pte_offset_map(dir, address) pte_offset_kernel(dir, address) 427f15cbe6fSPaul Mundt #define pte_offset_map_nested(dir, address) pte_offset_kernel(dir, address) 428f15cbe6fSPaul Mundt 429f15cbe6fSPaul Mundt #define pte_unmap(pte) do { } while (0) 430f15cbe6fSPaul Mundt #define pte_unmap_nested(pte) do { } while (0) 431f15cbe6fSPaul Mundt 432f15cbe6fSPaul Mundt #ifdef CONFIG_X2TLB 433f15cbe6fSPaul Mundt #define pte_ERROR(e) \ 434f15cbe6fSPaul Mundt printk("%s:%d: bad pte %p(%08lx%08lx).\n", __FILE__, __LINE__, \ 435f15cbe6fSPaul Mundt &(e), (e).pte_high, (e).pte_low) 436f15cbe6fSPaul Mundt #define pgd_ERROR(e) \ 437f15cbe6fSPaul Mundt printk("%s:%d: bad pgd %016llx.\n", __FILE__, __LINE__, pgd_val(e)) 438f15cbe6fSPaul Mundt #else 439f15cbe6fSPaul Mundt #define pte_ERROR(e) \ 440f15cbe6fSPaul Mundt printk("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, pte_val(e)) 441f15cbe6fSPaul Mundt #define pgd_ERROR(e) \ 442f15cbe6fSPaul Mundt printk("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e)) 443f15cbe6fSPaul Mundt #endif 444f15cbe6fSPaul Mundt 445f15cbe6fSPaul Mundt /* 446f15cbe6fSPaul Mundt * Encode and de-code a swap entry 447f15cbe6fSPaul Mundt * 448f15cbe6fSPaul Mundt * Constraints: 449f15cbe6fSPaul Mundt * _PAGE_FILE at bit 0 450f15cbe6fSPaul Mundt * _PAGE_PRESENT at bit 8 451f15cbe6fSPaul Mundt * _PAGE_PROTNONE at bit 9 452f15cbe6fSPaul Mundt * 453f15cbe6fSPaul Mundt * For the normal case, we encode the swap type into bits 0:7 and the 454f15cbe6fSPaul Mundt * swap offset into bits 10:30. For the 64-bit PTE case, we keep the 455f15cbe6fSPaul Mundt * preserved bits in the low 32-bits and use the upper 32 as the swap 456f15cbe6fSPaul Mundt * offset (along with a 5-bit type), following the same approach as x86 457f15cbe6fSPaul Mundt * PAE. This keeps the logic quite simple, and allows for a full 32 458f15cbe6fSPaul Mundt * PTE_FILE_MAX_BITS, as opposed to the 29-bits we're constrained with 459f15cbe6fSPaul Mundt * in the pte_low case. 460f15cbe6fSPaul Mundt * 461f15cbe6fSPaul Mundt * As is evident by the Alpha code, if we ever get a 64-bit unsigned 462f15cbe6fSPaul Mundt * long (swp_entry_t) to match up with the 64-bit PTEs, this all becomes 463f15cbe6fSPaul Mundt * much cleaner.. 464f15cbe6fSPaul Mundt * 465f15cbe6fSPaul Mundt * NOTE: We should set ZEROs at the position of _PAGE_PRESENT 466f15cbe6fSPaul Mundt * and _PAGE_PROTNONE bits 467f15cbe6fSPaul Mundt */ 468f15cbe6fSPaul Mundt #ifdef CONFIG_X2TLB 469f15cbe6fSPaul Mundt #define __swp_type(x) ((x).val & 0x1f) 470f15cbe6fSPaul Mundt #define __swp_offset(x) ((x).val >> 5) 471f15cbe6fSPaul Mundt #define __swp_entry(type, offset) ((swp_entry_t){ (type) | (offset) << 5}) 472f15cbe6fSPaul Mundt #define __pte_to_swp_entry(pte) ((swp_entry_t){ (pte).pte_high }) 473f15cbe6fSPaul Mundt #define __swp_entry_to_pte(x) ((pte_t){ 0, (x).val }) 474f15cbe6fSPaul Mundt 475f15cbe6fSPaul Mundt /* 476f15cbe6fSPaul Mundt * Encode and decode a nonlinear file mapping entry 477f15cbe6fSPaul Mundt */ 478f15cbe6fSPaul Mundt #define pte_to_pgoff(pte) ((pte).pte_high) 479f15cbe6fSPaul Mundt #define pgoff_to_pte(off) ((pte_t) { _PAGE_FILE, (off) }) 480f15cbe6fSPaul Mundt 481f15cbe6fSPaul Mundt #define PTE_FILE_MAX_BITS 32 482f15cbe6fSPaul Mundt #else 483f15cbe6fSPaul Mundt #define __swp_type(x) ((x).val & 0xff) 484f15cbe6fSPaul Mundt #define __swp_offset(x) ((x).val >> 10) 485f15cbe6fSPaul Mundt #define __swp_entry(type, offset) ((swp_entry_t){(type) | (offset) <<10}) 486f15cbe6fSPaul Mundt 487f15cbe6fSPaul Mundt #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) >> 1 }) 488f15cbe6fSPaul Mundt #define __swp_entry_to_pte(x) ((pte_t) { (x).val << 1 }) 489f15cbe6fSPaul Mundt 490f15cbe6fSPaul Mundt /* 491f15cbe6fSPaul Mundt * Encode and decode a nonlinear file mapping entry 492f15cbe6fSPaul Mundt */ 493f15cbe6fSPaul Mundt #define PTE_FILE_MAX_BITS 29 494f15cbe6fSPaul Mundt #define pte_to_pgoff(pte) (pte_val(pte) >> 1) 495f15cbe6fSPaul Mundt #define pgoff_to_pte(off) ((pte_t) { ((off) << 1) | _PAGE_FILE }) 496f15cbe6fSPaul Mundt #endif 497f15cbe6fSPaul Mundt 498f15cbe6fSPaul Mundt #endif /* __ASSEMBLY__ */ 499f15cbe6fSPaul Mundt #endif /* __ASM_SH_PGTABLE_32_H */ 500