1129198Scognet/* $NetBSD: pte.h,v 1.1 2001/11/23 17:39:04 thorpej Exp $ */ 2129198Scognet 3139735Simp/*- 4129198Scognet * Copyright (c) 1994 Mark Brinicombe. 5129198Scognet * All rights reserved. 6129198Scognet * 7129198Scognet * Redistribution and use in source and binary forms, with or without 8129198Scognet * modification, are permitted provided that the following conditions 9129198Scognet * are met: 10129198Scognet * 1. Redistributions of source code must retain the above copyright 11129198Scognet * notice, this list of conditions and the following disclaimer. 12129198Scognet * 2. Redistributions in binary form must reproduce the above copyright 13129198Scognet * notice, this list of conditions and the following disclaimer in the 14129198Scognet * documentation and/or other materials provided with the distribution. 15129198Scognet * 3. All advertising materials mentioning features or use of this software 16129198Scognet * must display the following acknowledgement: 17129198Scognet * This product includes software developed by the RiscBSD team. 18129198Scognet * 4. The name "RiscBSD" nor the name of the author may be used to 19129198Scognet * endorse or promote products derived from this software without specific 20129198Scognet * prior written permission. 21129198Scognet * 22129198Scognet * THIS SOFTWARE IS PROVIDED BY RISCBSD ``AS IS'' AND ANY EXPRESS OR IMPLIED 23129198Scognet * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24129198Scognet * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25129198Scognet * IN NO EVENT SHALL RISCBSD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 26129198Scognet * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27129198Scognet * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28129198Scognet * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29129198Scognet * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30129198Scognet * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31129198Scognet * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32129198Scognet * SUCH DAMAGE. 33129198Scognet * 34129198Scognet * $FreeBSD: releng/10.3/sys/arm/include/pte.h 254918 2013-08-26 17:12:30Z raj $ 35129198Scognet */ 36129198Scognet 37129198Scognet#ifndef _MACHINE_PTE_H_ 38129198Scognet#define _MACHINE_PTE_H_ 39129198Scognet 40129198Scognet#ifndef LOCORE 41129198Scognettypedef uint32_t pd_entry_t; /* page directory entry */ 42129198Scognettypedef uint32_t pt_entry_t; /* page table entry */ 43129198Scognet#endif 44129198Scognet 45129198Scognet#define PG_FRAME 0xfffff000 46129198Scognet 47129198Scognet/* The PT_SIZE definition is misleading... A page table is only 0x400 48129198Scognet * bytes long. But since VM mapping can only be done to 0x1000 a single 49129198Scognet * 1KB blocks cannot be steered to a va by itself. Therefore the 50129198Scognet * pages tables are allocated in blocks of 4. i.e. if a 1 KB block 51129198Scognet * was allocated for a PT then the other 3KB would also get mapped 52129198Scognet * whenever the 1KB was mapped. 53129198Scognet */ 54236992Simp 55129198Scognet#define PT_RSIZE 0x0400 /* Real page table size */ 56129198Scognet#define PT_SIZE 0x1000 57129198Scognet#define PD_SIZE 0x4000 58129198Scognet 59129198Scognet/* Page table types and masks */ 60129198Scognet#define L1_PAGE 0x01 /* L1 page table mapping */ 61129198Scognet#define L1_SECTION 0x02 /* L1 section mapping */ 62129198Scognet#define L1_FPAGE 0x03 /* L1 fine page mapping */ 63129198Scognet#define L1_MASK 0x03 /* Mask for L1 entry type */ 64129198Scognet#define L2_LPAGE 0x01 /* L2 large page (64KB) */ 65129198Scognet#define L2_SPAGE 0x02 /* L2 small page (4KB) */ 66129198Scognet#define L2_MASK 0x03 /* Mask for L2 entry type */ 67129198Scognet#define L2_INVAL 0x00 /* L2 invalid type */ 68129198Scognet 69129198Scognet/* L1 and L2 address masks */ 70129198Scognet#define L1_ADDR_MASK 0xfffffc00 71129198Scognet#define L2_ADDR_MASK 0xfffff000 72129198Scognet 73129198Scognet/* 74129198Scognet * The ARM MMU architecture was introduced with ARM v3 (previous ARM 75129198Scognet * architecture versions used an optional off-CPU memory controller 76129198Scognet * to perform address translation). 77129198Scognet * 78129198Scognet * The ARM MMU consists of a TLB and translation table walking logic. 79129198Scognet * There is typically one TLB per memory interface (or, put another 80129198Scognet * way, one TLB per software-visible cache). 81129198Scognet * 82129198Scognet * The ARM MMU is capable of mapping memory in the following chunks: 83129198Scognet * 84129198Scognet * 1M Sections (L1 table) 85129198Scognet * 86129198Scognet * 64K Large Pages (L2 table) 87129198Scognet * 88129198Scognet * 4K Small Pages (L2 table) 89129198Scognet * 90129198Scognet * 1K Tiny Pages (L2 table) 91129198Scognet * 92129198Scognet * There are two types of L2 tables: Coarse Tables and Fine Tables. 93129198Scognet * Coarse Tables can map Large and Small Pages. Fine Tables can 94129198Scognet * map Tiny Pages. 95129198Scognet * 96129198Scognet * Coarse Tables can define 4 Subpages within Large and Small pages. 97129198Scognet * Subpages define different permissions for each Subpage within 98129198Scognet * a Page. 99129198Scognet * 100129198Scognet * Coarse Tables are 1K in length. Fine tables are 4K in length. 101129198Scognet * 102129198Scognet * The Translation Table Base register holds the pointer to the 103129198Scognet * L1 Table. The L1 Table is a 16K contiguous chunk of memory 104129198Scognet * aligned to a 16K boundary. Each entry in the L1 Table maps 105129198Scognet * 1M of virtual address space, either via a Section mapping or 106129198Scognet * via an L2 Table. 107129198Scognet * 108129198Scognet * In addition, the Fast Context Switching Extension (FCSE) is available 109129198Scognet * on some ARM v4 and ARM v5 processors. FCSE is a way of eliminating 110129198Scognet * TLB/cache flushes on context switch by use of a smaller address space 111129198Scognet * and a "process ID" that modifies the virtual address before being 112129198Scognet * presented to the translation logic. 113129198Scognet */ 114129198Scognet 115170582Scognet/* ARMv6 super-sections. */ 116170582Scognet#define L1_SUP_SIZE 0x01000000 /* 16M */ 117170582Scognet#define L1_SUP_OFFSET (L1_SUP_SIZE - 1) 118170582Scognet#define L1_SUP_FRAME (~L1_SUP_OFFSET) 119170582Scognet#define L1_SUP_SHIFT 24 120170582Scognet 121129198Scognet#define L1_S_SIZE 0x00100000 /* 1M */ 122129198Scognet#define L1_S_OFFSET (L1_S_SIZE - 1) 123129198Scognet#define L1_S_FRAME (~L1_S_OFFSET) 124129198Scognet#define L1_S_SHIFT 20 125129198Scognet 126129198Scognet#define L2_L_SIZE 0x00010000 /* 64K */ 127129198Scognet#define L2_L_OFFSET (L2_L_SIZE - 1) 128129198Scognet#define L2_L_FRAME (~L2_L_OFFSET) 129129198Scognet#define L2_L_SHIFT 16 130129198Scognet 131129198Scognet#define L2_S_SIZE 0x00001000 /* 4K */ 132129198Scognet#define L2_S_OFFSET (L2_S_SIZE - 1) 133129198Scognet#define L2_S_FRAME (~L2_S_OFFSET) 134129198Scognet#define L2_S_SHIFT 12 135129198Scognet 136129198Scognet#define L2_T_SIZE 0x00000400 /* 1K */ 137129198Scognet#define L2_T_OFFSET (L2_T_SIZE - 1) 138129198Scognet#define L2_T_FRAME (~L2_T_OFFSET) 139129198Scognet#define L2_T_SHIFT 10 140129198Scognet 141129198Scognet/* 142129198Scognet * The NetBSD VM implementation only works on whole pages (4K), 143129198Scognet * whereas the ARM MMU's Coarse tables are sized in terms of 1K 144129198Scognet * (16K L1 table, 1K L2 table). 145129198Scognet * 146129198Scognet * So, we allocate L2 tables 4 at a time, thus yielding a 4K L2 147129198Scognet * table. 148129198Scognet */ 149129198Scognet#define L1_ADDR_BITS 0xfff00000 /* L1 PTE address bits */ 150129198Scognet#define L2_ADDR_BITS 0x000ff000 /* L2 PTE address bits */ 151129198Scognet 152129198Scognet#define L1_TABLE_SIZE 0x4000 /* 16K */ 153129198Scognet#define L2_TABLE_SIZE 0x1000 /* 4K */ 154129198Scognet/* 155129198Scognet * The new pmap deals with the 1KB coarse L2 tables by 156129198Scognet * allocating them from a pool. Until every port has been converted, 157129198Scognet * keep the old L2_TABLE_SIZE define lying around. Converted ports 158129198Scognet * should use L2_TABLE_SIZE_REAL until then. 159129198Scognet */ 160129198Scognet#define L2_TABLE_SIZE_REAL 0x400 /* 1K */ 161129198Scognet 162254918Sraj/* Total number of page table entries in L2 table */ 163254918Sraj#define L2_PTE_NUM_TOTAL (L2_TABLE_SIZE_REAL / sizeof(pt_entry_t)) 164254918Sraj 165129198Scognet/* 166129198Scognet * ARM L1 Descriptors 167129198Scognet */ 168129198Scognet 169129198Scognet#define L1_TYPE_INV 0x00 /* Invalid (fault) */ 170129198Scognet#define L1_TYPE_C 0x01 /* Coarse L2 */ 171129198Scognet#define L1_TYPE_S 0x02 /* Section */ 172129198Scognet#define L1_TYPE_F 0x03 /* Fine L2 */ 173129198Scognet#define L1_TYPE_MASK 0x03 /* mask of type bits */ 174129198Scognet 175129198Scognet/* L1 Section Descriptor */ 176129198Scognet#define L1_S_B 0x00000004 /* bufferable Section */ 177129198Scognet#define L1_S_C 0x00000008 /* cacheable Section */ 178129198Scognet#define L1_S_IMP 0x00000010 /* implementation defined */ 179254918Sraj#define L1_S_XN (1 << 4) /* execute not */ 180129198Scognet#define L1_S_DOM(x) ((x) << 5) /* domain */ 181129198Scognet#define L1_S_DOM_MASK L1_S_DOM(0xf) 182129198Scognet#define L1_S_AP(x) ((x) << 10) /* access permissions */ 183129198Scognet#define L1_S_ADDR_MASK 0xfff00000 /* phys address of section */ 184239268Sgonzo#define L1_S_TEX(x) (((x) & 0x7) << 12) /* Type Extension */ 185239268Sgonzo#define L1_S_TEX_MASK (0x7 << 12) /* Type Extension */ 186239268Sgonzo#define L1_S_APX (1 << 15) 187239268Sgonzo#define L1_SHARED (1 << 16) 188129198Scognet 189129198Scognet#define L1_S_XSCALE_P 0x00000200 /* ECC enable for this section */ 190129198Scognet#define L1_S_XSCALE_TEX(x) ((x) << 12) /* Type Extension */ 191129198Scognet 192170582Scognet#define L1_S_SUPERSEC ((1) << 18) /* Section is a super-section. */ 193170582Scognet 194129198Scognet/* L1 Coarse Descriptor */ 195129198Scognet#define L1_C_IMP0 0x00000004 /* implementation defined */ 196129198Scognet#define L1_C_IMP1 0x00000008 /* implementation defined */ 197129198Scognet#define L1_C_IMP2 0x00000010 /* implementation defined */ 198129198Scognet#define L1_C_DOM(x) ((x) << 5) /* domain */ 199129198Scognet#define L1_C_DOM_MASK L1_C_DOM(0xf) 200129198Scognet#define L1_C_ADDR_MASK 0xfffffc00 /* phys address of L2 Table */ 201129198Scognet 202129198Scognet#define L1_C_XSCALE_P 0x00000200 /* ECC enable for this section */ 203129198Scognet 204129198Scognet/* L1 Fine Descriptor */ 205129198Scognet#define L1_F_IMP0 0x00000004 /* implementation defined */ 206129198Scognet#define L1_F_IMP1 0x00000008 /* implementation defined */ 207129198Scognet#define L1_F_IMP2 0x00000010 /* implementation defined */ 208129198Scognet#define L1_F_DOM(x) ((x) << 5) /* domain */ 209129198Scognet#define L1_F_DOM_MASK L1_F_DOM(0xf) 210129198Scognet#define L1_F_ADDR_MASK 0xfffff000 /* phys address of L2 Table */ 211129198Scognet 212129198Scognet#define L1_F_XSCALE_P 0x00000200 /* ECC enable for this section */ 213129198Scognet 214129198Scognet/* 215129198Scognet * ARM L2 Descriptors 216129198Scognet */ 217129198Scognet 218129198Scognet#define L2_TYPE_INV 0x00 /* Invalid (fault) */ 219129198Scognet#define L2_TYPE_L 0x01 /* Large Page */ 220129198Scognet#define L2_TYPE_S 0x02 /* Small Page */ 221129198Scognet#define L2_TYPE_T 0x03 /* Tiny Page */ 222129198Scognet#define L2_TYPE_MASK 0x03 /* mask of type bits */ 223129198Scognet 224129198Scognet /* 225129198Scognet * This L2 Descriptor type is available on XScale processors 226129198Scognet * when using a Coarse L1 Descriptor. The Extended Small 227129198Scognet * Descriptor has the same format as the XScale Tiny Descriptor, 228129198Scognet * but describes a 4K page, rather than a 1K page. 229129198Scognet */ 230129198Scognet#define L2_TYPE_XSCALE_XS 0x03 /* XScale Extended Small Page */ 231129198Scognet 232129198Scognet#define L2_B 0x00000004 /* Bufferable page */ 233129198Scognet#define L2_C 0x00000008 /* Cacheable page */ 234129198Scognet#define L2_AP0(x) ((x) << 4) /* access permissions (sp 0) */ 235129198Scognet#define L2_AP1(x) ((x) << 6) /* access permissions (sp 1) */ 236129198Scognet#define L2_AP2(x) ((x) << 8) /* access permissions (sp 2) */ 237129198Scognet#define L2_AP3(x) ((x) << 10) /* access permissions (sp 3) */ 238129198Scognet 239239268Sgonzo#define L2_SHARED (1 << 10) 240239268Sgonzo#define L2_APX (1 << 9) 241239268Sgonzo#define L2_XN (1 << 0) 242239268Sgonzo#define L2_L_TEX_MASK (0x7 << 12) /* Type Extension */ 243239268Sgonzo#define L2_L_TEX(x) (((x) & 0x7) << 12) 244239268Sgonzo#define L2_S_TEX_MASK (0x7 << 6) /* Type Extension */ 245239268Sgonzo#define L2_S_TEX(x) (((x) & 0x7) << 6) 246239268Sgonzo 247129198Scognet#define L2_XSCALE_L_TEX(x) ((x) << 12) /* Type Extension */ 248170582Scognet#define L2_XSCALE_L_S(x) (1 << 15) /* Shared */ 249129198Scognet#define L2_XSCALE_T_TEX(x) ((x) << 6) /* Type Extension */ 250129198Scognet 251129198Scognet/* 252129198Scognet * Access Permissions for L1 and L2 Descriptors. 253129198Scognet */ 254129198Scognet#define AP_W 0x01 /* writable */ 255254918Sraj#define AP_REF 0x01 /* referenced flag */ 256129198Scognet#define AP_U 0x02 /* user */ 257129198Scognet 258129198Scognet/* 259129198Scognet * Short-hand for common AP_* constants. 260129198Scognet * 261129198Scognet * Note: These values assume the S (System) bit is set and 262129198Scognet * the R (ROM) bit is clear in CP15 register 1. 263129198Scognet */ 264129198Scognet#define AP_KR 0x00 /* kernel read */ 265129198Scognet#define AP_KRW 0x01 /* kernel read/write */ 266129198Scognet#define AP_KRWUR 0x02 /* kernel read/write usr read */ 267129198Scognet#define AP_KRWURW 0x03 /* kernel read/write usr read/write */ 268129198Scognet 269129198Scognet/* 270129198Scognet * Domain Types for the Domain Access Control Register. 271129198Scognet */ 272129198Scognet#define DOMAIN_FAULT 0x00 /* no access */ 273129198Scognet#define DOMAIN_CLIENT 0x01 /* client */ 274129198Scognet#define DOMAIN_RESERVED 0x02 /* reserved */ 275129198Scognet#define DOMAIN_MANAGER 0x03 /* manager */ 276129198Scognet 277129198Scognet/* 278129198Scognet * Type Extension bits for XScale processors. 279129198Scognet * 280129198Scognet * Behavior of C and B when X == 0: 281129198Scognet * 282129198Scognet * C B Cacheable Bufferable Write Policy Line Allocate Policy 283129198Scognet * 0 0 N N - - 284129198Scognet * 0 1 N Y - - 285129198Scognet * 1 0 Y Y Write-through Read Allocate 286129198Scognet * 1 1 Y Y Write-back Read Allocate 287129198Scognet * 288129198Scognet * Behavior of C and B when X == 1: 289129198Scognet * C B Cacheable Bufferable Write Policy Line Allocate Policy 290129198Scognet * 0 0 - - - - DO NOT USE 291129198Scognet * 0 1 N Y - - 292129198Scognet * 1 0 Mini-Data - - - 293129198Scognet * 1 1 Y Y Write-back R/W Allocate 294129198Scognet */ 295129198Scognet#define TEX_XSCALE_X 0x01 /* X modifies C and B */ 296170582Scognet#define TEX_XSCALE_E 0x02 297170582Scognet#define TEX_XSCALE_T 0x04 298170582Scognet 299170582Scognet/* Xscale core 3 */ 300170582Scognet 301170582Scognet/* 302170582Scognet * 303170582Scognet * Cache attributes with L2 present, S = 0 304170582Scognet * T E X C B L1 i-cache L1 d-cache L1 DC WP L2 cacheable write coalesce 305236992Simp * 0 0 0 0 0 N N - N N 306170582Scognet * 0 0 0 0 1 N N - N Y 307170582Scognet * 0 0 0 1 0 Y Y WT N Y 308170582Scognet * 0 0 0 1 1 Y Y WB Y Y 309170582Scognet * 0 0 1 0 0 N N - Y Y 310170582Scognet * 0 0 1 0 1 N N - N N 311170582Scognet * 0 0 1 1 0 Y Y - - N 312170582Scognet * 0 0 1 1 1 Y Y WT Y Y 313170582Scognet * 0 1 0 0 0 N N - N N 314170582Scognet * 0 1 0 0 1 N/A N/A N/A N/A N/A 315170582Scognet * 0 1 0 1 0 N/A N/A N/A N/A N/A 316170582Scognet * 0 1 0 1 1 N/A N/A N/A N/A N/A 317170582Scognet * 0 1 1 X X N/A N/A N/A N/A N/A 318170582Scognet * 1 X 0 0 0 N N - N Y 319171621Scognet * 1 X 0 0 1 Y N WB N Y 320171621Scognet * 1 X 0 1 0 Y N WT N Y 321171621Scognet * 1 X 0 1 1 Y N WB Y Y 322170582Scognet * 1 X 1 0 0 N N - Y Y 323171621Scognet * 1 X 1 0 1 Y Y WB Y Y 324170582Scognet * 1 X 1 1 0 Y Y WT Y Y 325171621Scognet * 1 X 1 1 1 Y Y WB Y Y 326170582Scognet * 327170582Scognet * 328170582Scognet * 329170582Scognet * 330170582Scognet * Cache attributes with L2 present, S = 1 331170582Scognet * T E X C B L1 i-cache L1 d-cache L1 DC WP L2 cacheable write coalesce 332236992Simp * 0 0 0 0 0 N N - N N 333170582Scognet * 0 0 0 0 1 N N - N Y 334170582Scognet * 0 0 0 1 0 Y Y - N Y 335170582Scognet * 0 0 0 1 1 Y Y WT Y Y 336170582Scognet * 0 0 1 0 0 N N - Y Y 337170582Scognet * 0 0 1 0 1 N N - N N 338170582Scognet * 0 0 1 1 0 Y Y - - N 339170582Scognet * 0 0 1 1 1 Y Y WT Y Y 340170582Scognet * 0 1 0 0 0 N N - N N 341170582Scognet * 0 1 0 0 1 N/A N/A N/A N/A N/A 342170582Scognet * 0 1 0 1 0 N/A N/A N/A N/A N/A 343170582Scognet * 0 1 0 1 1 N/A N/A N/A N/A N/A 344170582Scognet * 0 1 1 X X N/A N/A N/A N/A N/A 345170582Scognet * 1 X 0 0 0 N N - N Y 346170582Scognet * 1 X 0 0 1 Y N - N Y 347170582Scognet * 1 X 0 1 0 Y N - N Y 348170582Scognet * 1 X 0 1 1 Y N - Y Y 349170582Scognet * 1 X 1 0 0 N N - Y Y 350170582Scognet * 1 X 1 0 1 Y Y WT Y Y 351170582Scognet * 1 X 1 1 0 Y Y WT Y Y 352170582Scognet * 1 X 1 1 1 Y Y WT Y Y 353170582Scognet */ 354129198Scognet#endif /* !_MACHINE_PTE_H_ */ 355129198Scognet 356129198Scognet/* End of pte.h */ 357