1*36fd90dcSjsg /* $OpenBSD: pte.h,v 1.10 2021/03/11 11:16:55 jsg Exp $ */ 2e1e4f5b1Sdrahn /* $NetBSD: pte.h,v 1.6 2003/04/18 11:08:28 scw Exp $ */ 3e1e4f5b1Sdrahn 4e1e4f5b1Sdrahn /* 5e1e4f5b1Sdrahn * Copyright (c) 2001, 2002 Wasabi Systems, Inc. 6e1e4f5b1Sdrahn * All rights reserved. 7e1e4f5b1Sdrahn * 8e1e4f5b1Sdrahn * Written by Jason R. Thorpe for Wasabi Systems, Inc. 9e1e4f5b1Sdrahn * 10e1e4f5b1Sdrahn * Redistribution and use in source and binary forms, with or without 11e1e4f5b1Sdrahn * modification, are permitted provided that the following conditions 12e1e4f5b1Sdrahn * are met: 13e1e4f5b1Sdrahn * 1. Redistributions of source code must retain the above copyright 14e1e4f5b1Sdrahn * notice, this list of conditions and the following disclaimer. 15e1e4f5b1Sdrahn * 2. Redistributions in binary form must reproduce the above copyright 16e1e4f5b1Sdrahn * notice, this list of conditions and the following disclaimer in the 17e1e4f5b1Sdrahn * documentation and/or other materials provided with the distribution. 18e1e4f5b1Sdrahn * 3. All advertising materials mentioning features or use of this software 19e1e4f5b1Sdrahn * must display the following acknowledgement: 20e1e4f5b1Sdrahn * This product includes software developed for the NetBSD Project by 21e1e4f5b1Sdrahn * Wasabi Systems, Inc. 22e1e4f5b1Sdrahn * 4. The name of Wasabi Systems, Inc. may not be used to endorse 23e1e4f5b1Sdrahn * or promote products derived from this software without specific prior 24e1e4f5b1Sdrahn * written permission. 25e1e4f5b1Sdrahn * 26e1e4f5b1Sdrahn * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 27e1e4f5b1Sdrahn * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28e1e4f5b1Sdrahn * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29e1e4f5b1Sdrahn * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 30e1e4f5b1Sdrahn * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31e1e4f5b1Sdrahn * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32e1e4f5b1Sdrahn * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33e1e4f5b1Sdrahn * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34e1e4f5b1Sdrahn * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35e1e4f5b1Sdrahn * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36e1e4f5b1Sdrahn * POSSIBILITY OF SUCH DAMAGE. 37e1e4f5b1Sdrahn */ 38e1e4f5b1Sdrahn 39e1e4f5b1Sdrahn #ifndef _ARM_PTE_H_ 40e1e4f5b1Sdrahn #define _ARM_PTE_H_ 41e1e4f5b1Sdrahn 42e1e4f5b1Sdrahn /* 43e1e4f5b1Sdrahn * The ARM MMU architecture was introduced with ARM v3 (previous ARM 44e1e4f5b1Sdrahn * architecture versions used an optional off-CPU memory controller 45e1e4f5b1Sdrahn * to perform address translation). 46e1e4f5b1Sdrahn * 47e1e4f5b1Sdrahn * The ARM MMU consists of a TLB and translation table walking logic. 48e1e4f5b1Sdrahn * There is typically one TLB per memory interface (or, put another 49e1e4f5b1Sdrahn * way, one TLB per software-visible cache). 50e1e4f5b1Sdrahn * 51e1e4f5b1Sdrahn * The ARM MMU is capable of mapping memory in the following chunks: 52e1e4f5b1Sdrahn * 53e1e4f5b1Sdrahn * 1M Sections (L1 table) 54e1e4f5b1Sdrahn * 55e1e4f5b1Sdrahn * 64K Large Pages (L2 table) 56e1e4f5b1Sdrahn * 57e1e4f5b1Sdrahn * 4K Small Pages (L2 table) 58e1e4f5b1Sdrahn * 59e1e4f5b1Sdrahn * 1K Tiny Pages (L2 table) 60e1e4f5b1Sdrahn * 61e1e4f5b1Sdrahn * There are two types of L2 tables: Coarse Tables and Fine Tables. 62e1e4f5b1Sdrahn * Coarse Tables can map Large and Small Pages. Fine Tables can 63e1e4f5b1Sdrahn * map Tiny Pages. 64e1e4f5b1Sdrahn * 65e1e4f5b1Sdrahn * Coarse Tables can define 4 Subpages within Large and Small pages. 66e1e4f5b1Sdrahn * Subpages define different permissions for each Subpage within 67e1e4f5b1Sdrahn * a Page. 68e1e4f5b1Sdrahn * 69e1e4f5b1Sdrahn * Coarse Tables are 1K in length. Fine tables are 4K in length. 70e1e4f5b1Sdrahn * 71e1e4f5b1Sdrahn * The Translation Table Base register holds the pointer to the 72e1e4f5b1Sdrahn * L1 Table. The L1 Table is a 16K contiguous chunk of memory 73e1e4f5b1Sdrahn * aligned to a 16K boundary. Each entry in the L1 Table maps 74e1e4f5b1Sdrahn * 1M of virtual address space, either via a Section mapping or 75e1e4f5b1Sdrahn * via an L2 Table. 76e1e4f5b1Sdrahn * 77e1e4f5b1Sdrahn * In addition, the Fast Context Switching Extension (FCSE) is available 78e1e4f5b1Sdrahn * on some ARM v4 and ARM v5 processors. FCSE is a way of eliminating 79e1e4f5b1Sdrahn * TLB/cache flushes on context switch by use of a smaller address space 80e1e4f5b1Sdrahn * and a "process ID" that modifies the virtual address before being 81e1e4f5b1Sdrahn * presented to the translation logic. 82e1e4f5b1Sdrahn */ 83e1e4f5b1Sdrahn 84e1e4f5b1Sdrahn #ifndef _LOCORE 85e1e4f5b1Sdrahn typedef uint32_t pd_entry_t; /* L1 table entry */ 86e1e4f5b1Sdrahn typedef uint32_t pt_entry_t; /* L2 table entry */ 87e1e4f5b1Sdrahn #endif /* _LOCORE */ 88e1e4f5b1Sdrahn 89e1e4f5b1Sdrahn #define L1_S_SIZE 0x00100000 /* 1M */ 90e1e4f5b1Sdrahn #define L1_S_OFFSET (L1_S_SIZE - 1) 91e1e4f5b1Sdrahn #define L1_S_FRAME (~L1_S_OFFSET) 92e1e4f5b1Sdrahn #define L1_S_SHIFT 20 93e1e4f5b1Sdrahn 94e1e4f5b1Sdrahn #define L2_L_SIZE 0x00010000 /* 64K */ 95e1e4f5b1Sdrahn #define L2_L_OFFSET (L2_L_SIZE - 1) 96e1e4f5b1Sdrahn #define L2_L_FRAME (~L2_L_OFFSET) 97e1e4f5b1Sdrahn #define L2_L_SHIFT 16 98e1e4f5b1Sdrahn 99e1e4f5b1Sdrahn #define L2_S_SIZE 0x00001000 /* 4K */ 100e1e4f5b1Sdrahn #define L2_S_OFFSET (L2_S_SIZE - 1) 101e1e4f5b1Sdrahn #define L2_S_FRAME (~L2_S_OFFSET) 102e1e4f5b1Sdrahn #define L2_S_SHIFT 12 103e1e4f5b1Sdrahn 104e1e4f5b1Sdrahn #define L2_T_SIZE 0x00000400 /* 1K */ 105e1e4f5b1Sdrahn #define L2_T_OFFSET (L2_T_SIZE - 1) 106e1e4f5b1Sdrahn #define L2_T_FRAME (~L2_T_OFFSET) 107e1e4f5b1Sdrahn #define L2_T_SHIFT 10 108e1e4f5b1Sdrahn 109e1e4f5b1Sdrahn /* 110e1e4f5b1Sdrahn * The NetBSD VM implementation only works on whole pages (4K), 111e1e4f5b1Sdrahn * whereas the ARM MMU's Coarse tables are sized in terms of 1K 112e1e4f5b1Sdrahn * (16K L1 table, 1K L2 table). 113e1e4f5b1Sdrahn * 114e1e4f5b1Sdrahn * So, we allocate L2 tables 4 at a time, thus yielding a 4K L2 115e1e4f5b1Sdrahn * table. 116e1e4f5b1Sdrahn */ 117e1e4f5b1Sdrahn #define L1_ADDR_BITS 0xfff00000 /* L1 PTE address bits */ 118e1e4f5b1Sdrahn #define L2_ADDR_BITS 0x000ff000 /* L2 PTE address bits */ 119e1e4f5b1Sdrahn 120e1e4f5b1Sdrahn #define L1_TABLE_SIZE 0x4000 /* 16K */ 121e1e4f5b1Sdrahn #define L2_TABLE_SIZE 0x1000 /* 4K */ 122e1e4f5b1Sdrahn /* 123e1e4f5b1Sdrahn * The new pmap deals with the 1KB coarse L2 tables by 124e1e4f5b1Sdrahn * allocating them from a pool. Until every port has been converted, 125e1e4f5b1Sdrahn * keep the old L2_TABLE_SIZE define lying around. Converted ports 126e1e4f5b1Sdrahn * should use L2_TABLE_SIZE_REAL until then. 127e1e4f5b1Sdrahn */ 128e1e4f5b1Sdrahn #define L2_TABLE_SIZE_REAL 0x400 /* 1K */ 129e1e4f5b1Sdrahn 130e1e4f5b1Sdrahn /* 131e1e4f5b1Sdrahn * ARM L1 Descriptors 132e1e4f5b1Sdrahn */ 133e1e4f5b1Sdrahn 134e1e4f5b1Sdrahn #define L1_TYPE_INV 0x00 /* Invalid (fault) */ 135e1e4f5b1Sdrahn #define L1_TYPE_C 0x01 /* Coarse L2 */ 136207aa54fSpatrick #define L1_TYPE_S 0x02 /* Section or Supersection */ 137207aa54fSpatrick #define L1_TYPE_F 0x03 /* Fine L2 (pre-V7) */ 138e1e4f5b1Sdrahn #define L1_TYPE_MASK 0x03 /* mask of type bits */ 139e1e4f5b1Sdrahn 140e1e4f5b1Sdrahn /* L1 Section Descriptor */ 141e1e4f5b1Sdrahn #define L1_S_B 0x00000004 /* bufferable Section */ 142e1e4f5b1Sdrahn #define L1_S_C 0x00000008 /* cacheable Section */ 143e1e4f5b1Sdrahn #define L1_S_IMP 0x00000010 /* implementation defined */ 144e1e4f5b1Sdrahn #define L1_S_DOM(x) ((x) << 5) /* domain */ 145e1e4f5b1Sdrahn #define L1_S_DOM_MASK L1_S_DOM(0xf) 146e1e4f5b1Sdrahn #define L1_S_AP(x) ((x) << 10) /* access permissions */ 147e1e4f5b1Sdrahn #define L1_S_ADDR_MASK 0xfff00000 /* phys address of section */ 148e1e4f5b1Sdrahn 149207aa54fSpatrick #define L1_S_V7_TEX(x) (((x) & 0x7) << 12) /* Type Extension */ 150207aa54fSpatrick #define L1_S_V7_TEX_MASK (0x7 << 12) /* Type Extension */ 151207aa54fSpatrick #define L1_S_V7_NS 0x00080000 /* Non-secure */ 152207aa54fSpatrick #define L1_S_V7_SS 0x00040000 /* Supersection */ 153207aa54fSpatrick #define L1_S_V7_nG 0x00020000 /* not Global */ 154207aa54fSpatrick #define L1_S_V7_S 0x00010000 /* Shareable */ 155df4e081dSkettenis #define L1_S_V7_AP(x) ((((x) & 0x4) << 13) | (((x) & 0x2) << 10)) /* AP */ 156df4e081dSkettenis #define L1_S_V7_AF 0x00000400 /* Access Flag */ 157207aa54fSpatrick #define L1_S_V7_IMP 0x00000200 /* implementation defined */ 158207aa54fSpatrick #define L1_S_V7_XN 0x00000010 /* eXecute Never */ 1597680ffd3Skettenis #define L1_S_V7_PXN 0x00000001 /* Privileged eXecute Never */ 1600b0e92f9Sdrahn 161e1e4f5b1Sdrahn /* L1 Coarse Descriptor */ 162e1e4f5b1Sdrahn #define L1_C_IMP0 0x00000004 /* implementation defined */ 163e1e4f5b1Sdrahn #define L1_C_IMP1 0x00000008 /* implementation defined */ 164e1e4f5b1Sdrahn #define L1_C_IMP2 0x00000010 /* implementation defined */ 165e1e4f5b1Sdrahn #define L1_C_DOM(x) ((x) << 5) /* domain */ 166e1e4f5b1Sdrahn #define L1_C_DOM_MASK L1_C_DOM(0xf) 167e1e4f5b1Sdrahn #define L1_C_ADDR_MASK 0xfffffc00 /* phys address of L2 Table */ 168e1e4f5b1Sdrahn 169207aa54fSpatrick #define L1_C_V7_IMP 0x00000200 /* implementation defined */ 1707680ffd3Skettenis #define L1_C_V7_NS 0x00000008 /* Non-secure */ 1717680ffd3Skettenis #define L1_C_V7_PXN 0x00000004 /* Privileged eXecute Never */ 172207aa54fSpatrick 173e1e4f5b1Sdrahn /* L1 Fine Descriptor */ 174e1e4f5b1Sdrahn #define L1_F_IMP0 0x00000004 /* implementation defined */ 175e1e4f5b1Sdrahn #define L1_F_IMP1 0x00000008 /* implementation defined */ 176e1e4f5b1Sdrahn #define L1_F_IMP2 0x00000010 /* implementation defined */ 177e1e4f5b1Sdrahn #define L1_F_DOM(x) ((x) << 5) /* domain */ 178e1e4f5b1Sdrahn #define L1_F_DOM_MASK L1_F_DOM(0xf) 179e1e4f5b1Sdrahn #define L1_F_ADDR_MASK 0xfffff000 /* phys address of L2 Table */ 180e1e4f5b1Sdrahn 181e1e4f5b1Sdrahn /* 182e1e4f5b1Sdrahn * ARM L2 Descriptors 183e1e4f5b1Sdrahn */ 184e1e4f5b1Sdrahn 185e1e4f5b1Sdrahn #define L2_TYPE_INV 0x00 /* Invalid (fault) */ 186e1e4f5b1Sdrahn #define L2_TYPE_L 0x01 /* Large Page */ 187e1e4f5b1Sdrahn #define L2_TYPE_S 0x02 /* Small Page */ 188207aa54fSpatrick #define L2_TYPE_T 0x03 /* Tiny Page (pre-V7) */ 189e1e4f5b1Sdrahn #define L2_TYPE_MASK 0x03 /* mask of type bits */ 190e1e4f5b1Sdrahn 191e1e4f5b1Sdrahn #define L2_B 0x00000004 /* Bufferable page */ 192e1e4f5b1Sdrahn #define L2_C 0x00000008 /* Cacheable page */ 193e1e4f5b1Sdrahn #define L2_AP0(x) ((x) << 4) /* access permissions (sp 0) */ 194e1e4f5b1Sdrahn #define L2_AP1(x) ((x) << 6) /* access permissions (sp 1) */ 195e1e4f5b1Sdrahn #define L2_AP2(x) ((x) << 8) /* access permissions (sp 2) */ 196e1e4f5b1Sdrahn #define L2_AP3(x) ((x) << 10) /* access permissions (sp 3) */ 197e1e4f5b1Sdrahn #define L2_AP(x) (L2_AP0(x) | L2_AP1(x) | L2_AP2(x) | L2_AP3(x)) 198e1e4f5b1Sdrahn 199207aa54fSpatrick #define L2_V7_L_TEX(x) (((x) & 0x7) << 12) /* Type Extension */ 200207aa54fSpatrick #define L2_V7_L_TEX_MASK (0x7 << 12) /* Type Extension */ 201207aa54fSpatrick #define L2_V7_L_XN 0x00008000 /* eXecute Never */ 202207aa54fSpatrick #define L2_V7_S_TEX(x) (((x) & 0x7) << 6) /* Type Extension */ 203207aa54fSpatrick #define L2_V7_S_TEX_MASK (0x7 << 6) /* Type Extension */ 204207aa54fSpatrick #define L2_V7_S_XN 0x00000001 /* eXecute Never */ 2050b0e92f9Sdrahn 206df4e081dSkettenis #define L2_V7_AP(x) ((((x) & 0x4) << 7) | (((x) & 0x2) << 4)) /* AP */ 207df4e081dSkettenis #define L2_V7_AF 0x00000010 /* Access Flag */ 208*36fd90dcSjsg #define L2_V7_S 0x00000400 /* Shareable */ 2098ab96db0Skettenis #define L2_V7_nG 0x00000800 /* not Global */ 2100b0e92f9Sdrahn 211e1e4f5b1Sdrahn /* 212e1e4f5b1Sdrahn * Short-hand for common AP_* constants. 213e1e4f5b1Sdrahn * 214e1e4f5b1Sdrahn * Note: These values assume the S (System) bit is set and 215e1e4f5b1Sdrahn * the R (ROM) bit is clear in CP15 register 1. 216e1e4f5b1Sdrahn */ 217e1e4f5b1Sdrahn #define AP_KR 0x00 /* kernel read */ 218207aa54fSpatrick #define AP_V7_KR 0x05 219e1e4f5b1Sdrahn #define AP_KRW 0x01 /* kernel read/write */ 220e1e4f5b1Sdrahn #define AP_KRWUR 0x02 /* kernel read/write usr read */ 221f976bc9bSkettenis #define AP_V7_KRUR 0x07 /* kernel read usr read */ 222e1e4f5b1Sdrahn #define AP_KRWURW 0x03 /* kernel read/write usr read/write */ 223e1e4f5b1Sdrahn 224e1e4f5b1Sdrahn /* 225e1e4f5b1Sdrahn * Domain Types for the Domain Access Control Register. 226e1e4f5b1Sdrahn */ 227e1e4f5b1Sdrahn #define DOMAIN_FAULT 0x00 /* no access */ 228e1e4f5b1Sdrahn #define DOMAIN_CLIENT 0x01 /* client */ 229e1e4f5b1Sdrahn #define DOMAIN_RESERVED 0x02 /* reserved */ 230e1e4f5b1Sdrahn #define DOMAIN_MANAGER 0x03 /* manager */ 231e1e4f5b1Sdrahn 232e1e4f5b1Sdrahn #endif /* _ARM_PTE_H_ */ 233