1b2b3ffcdSSimon Schubert /*- 2b2b3ffcdSSimon Schubert * Copyright (c) 1991 Regents of the University of California. 3b2b3ffcdSSimon Schubert * Copyright (c) 2003 Peter Wemm. 4b2b3ffcdSSimon Schubert * Copyright (c) 2008 The DragonFly Project. 5b2b3ffcdSSimon Schubert * All rights reserved. 6b2b3ffcdSSimon Schubert * 7b2b3ffcdSSimon Schubert * This code is derived from software contributed to Berkeley by 8b2b3ffcdSSimon Schubert * the Systems Programming Group of the University of Utah Computer 9b2b3ffcdSSimon Schubert * Science Department and William Jolitz of UUNET Technologies Inc. 10b2b3ffcdSSimon Schubert * 11b2b3ffcdSSimon Schubert * Redistribution and use in source and binary forms, with or without 12b2b3ffcdSSimon Schubert * modification, are permitted provided that the following conditions 13b2b3ffcdSSimon Schubert * are met: 14b2b3ffcdSSimon Schubert * 1. Redistributions of source code must retain the above copyright 15b2b3ffcdSSimon Schubert * notice, this list of conditions and the following disclaimer. 16b2b3ffcdSSimon Schubert * 2. Redistributions in binary form must reproduce the above copyright 17b2b3ffcdSSimon Schubert * notice, this list of conditions and the following disclaimer in the 18b2b3ffcdSSimon Schubert * documentation and/or other materials provided with the distribution. 19c66c7e2fSzrj * 3. Neither the name of the University nor the names of its contributors 20b2b3ffcdSSimon Schubert * may be used to endorse or promote products derived from this software 21b2b3ffcdSSimon Schubert * without specific prior written permission. 22b2b3ffcdSSimon Schubert * 23b2b3ffcdSSimon Schubert * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24b2b3ffcdSSimon Schubert * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25b2b3ffcdSSimon Schubert * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26b2b3ffcdSSimon Schubert * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27b2b3ffcdSSimon Schubert * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28b2b3ffcdSSimon Schubert * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29b2b3ffcdSSimon Schubert * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30b2b3ffcdSSimon Schubert * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31b2b3ffcdSSimon Schubert * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32b2b3ffcdSSimon Schubert * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33b2b3ffcdSSimon Schubert * SUCH DAMAGE. 34b2b3ffcdSSimon Schubert * 35b2b3ffcdSSimon Schubert * Derived from hp300 version by Mike Hibler, this version by William 36b2b3ffcdSSimon Schubert * Jolitz uses a recursive map [a pde points to the page directory] to 37b2b3ffcdSSimon Schubert * map the page tables using the pagetables themselves. This is done to 38b2b3ffcdSSimon Schubert * reduce the impact on kernel virtual memory for lots of sparse address 39b2b3ffcdSSimon Schubert * space, and to reduce the cost of memory to each process. 40b2b3ffcdSSimon Schubert * 41b2b3ffcdSSimon Schubert * from: hp300: @(#)pmap.h 7.2 (Berkeley) 12/16/90 42b2b3ffcdSSimon Schubert * from: @(#)pmap.h 7.4 (Berkeley) 5/12/91 43b2b3ffcdSSimon Schubert */ 44b2b3ffcdSSimon Schubert 45b2b3ffcdSSimon Schubert #ifndef _CPU_PMAP_H_ 46b2b3ffcdSSimon Schubert #define _CPU_PMAP_H_ 47b2b3ffcdSSimon Schubert 4840209b5bSzrj #ifndef LOCORE 4940209b5bSzrj 5040209b5bSzrj #include <machine/stdint.h> 5140209b5bSzrj 5240209b5bSzrj /* 5340209b5bSzrj * MMU page tables, keep public for VM_MAX_USER_ADDRESS/PS_STRINGS. 5440209b5bSzrj */ 5540209b5bSzrj typedef __uint64_t pml4_entry_t; 5640209b5bSzrj typedef __uint64_t pdp_entry_t; 5740209b5bSzrj typedef __uint64_t pd_entry_t; 5840209b5bSzrj typedef __uint64_t pt_entry_t; 5940209b5bSzrj 6040209b5bSzrj #endif /* !LOCORE */ 6140209b5bSzrj 62b2b3ffcdSSimon Schubert /* 63b2b3ffcdSSimon Schubert * Page-directory and page-table entries follow this format, with a few 64b2b3ffcdSSimon Schubert * of the fields not present here and there, depending on a lot of things. 65b2b3ffcdSSimon Schubert */ 66b2b3ffcdSSimon Schubert /* ---- Intel Nomenclature ---- */ 67a86ce0cdSMatthew Dillon #define X86_PG_V 0x001 /* P Valid */ 68a86ce0cdSMatthew Dillon #define X86_PG_RW 0x002 /* R/W Read/Write */ 69a86ce0cdSMatthew Dillon #define X86_PG_U 0x004 /* U/S User/Supervisor */ 70a86ce0cdSMatthew Dillon #define X86_PG_NC_PWT 0x008 /* PWT Write through */ 71a86ce0cdSMatthew Dillon #define X86_PG_NC_PCD 0x010 /* PCD Cache disable */ 72a86ce0cdSMatthew Dillon #define X86_PG_A 0x020 /* A Accessed */ 73a86ce0cdSMatthew Dillon #define X86_PG_M 0x040 /* D Dirty */ 74a86ce0cdSMatthew Dillon #define X86_PG_PS 0x080 /* PS Page size (0=4k,1=2M) */ 75a86ce0cdSMatthew Dillon #define X86_PG_PTE_PAT 0x080 /* PAT PAT index */ 76a86ce0cdSMatthew Dillon #define X86_PG_G 0x100 /* G Global */ 77a86ce0cdSMatthew Dillon #define X86_PG_AVAIL1 0x200 /* / Available for system */ 78a86ce0cdSMatthew Dillon #define X86_PG_AVAIL2 0x400 /* < programmers use */ 79a86ce0cdSMatthew Dillon #define X86_PG_AVAIL3 0x800 /* \ */ 80a86ce0cdSMatthew Dillon #define X86_PG_PDE_PAT 0x1000 /* PAT PAT index */ 81a69b35e0SAaron LI #define X86_PG_NX (1UL << 63) /* No-execute */ 82b2b3ffcdSSimon Schubert 83a69b35e0SAaron LI /* 84a69b35e0SAaron LI * Intel Extended Page Table (EPT) bit definitions. 85a69b35e0SAaron LI */ 86a69b35e0SAaron LI #define EPT_PG_READ (1UL << 0) /* R: Read */ 87a69b35e0SAaron LI #define EPT_PG_WRITE (1UL << 1) /* W: Write */ 88a69b35e0SAaron LI #define EPT_PG_EXECUTE (1UL << 2) /* X: Execute */ 89a69b35e0SAaron LI #define EPT_PG_IGNORE_PAT (1UL << 6) /* IPAT: Ignore PAT */ 90a69b35e0SAaron LI #define EPT_PG_PS (1UL << 7) /* PS: Page size */ 91a69b35e0SAaron LI #define EPT_PG_A (1UL << 8) /* A: Accessed */ 92a69b35e0SAaron LI #define EPT_PG_M (1UL << 9) /* D: Dirty */ 93*13fa9066SAaron LI #define EPT_PG_EXECUTE_USER (1UL << 10) /* XU: Execure for user-mode */ 94*13fa9066SAaron LI #define EPT_PG_AVAIL1 (1UL << 11) /* ignored */ 95*13fa9066SAaron LI #define EPT_PG_AVAIL2 (1UL << 52) /* ignored (bits 59-52) */ 96*13fa9066SAaron LI #define EPT_PG_AVAIL3 (1UL << 53) 97a69b35e0SAaron LI /* Memory Type (MT) definitions */ 98a69b35e0SAaron LI #define EPT_MEM_TYPE_UC (0UL << 3) /* Uncacheable */ 99a69b35e0SAaron LI #define EPT_MEM_TYPE_WC (1UL << 3) /* Write combining */ 100a69b35e0SAaron LI #define EPT_MEM_TYPE_WT (4UL << 3) /* Write through */ 101a69b35e0SAaron LI #define EPT_MEM_TYPE_WP (5UL << 3) /* Write protected */ 102a69b35e0SAaron LI #define EPT_MEM_TYPE_WB (6UL << 3) /* Write back */ 103a69b35e0SAaron LI #define EPT_MEM_TYPE_MASK (7UL << 3) 104b2b3ffcdSSimon Schubert 105b2b3ffcdSSimon Schubert /* Our various interpretations of the above */ 106a86ce0cdSMatthew Dillon //#define PG_W PG_AVAIL1 /* "Wired" pseudoflag */ 107a86ce0cdSMatthew Dillon //#define PG_MANAGED PG_AVAIL2 108a86ce0cdSMatthew Dillon //#define PG_DEVICE PG_AVAIL3 109a69b35e0SAaron LI #define PG_FRAME (0x000ffffffffff000UL) 110a69b35e0SAaron LI #define PG_PS_FRAME (0x000fffffffe00000UL) 111a86ce0cdSMatthew Dillon //#define PG_PROT (PG_RW|PG_U) /* all protection bits . */ 112a86ce0cdSMatthew Dillon //#define PG_N (PG_NC_PWT|PG_NC_PCD) /* Non-cacheable */ 113b2b3ffcdSSimon Schubert 114b2b3ffcdSSimon Schubert /* 115b2b3ffcdSSimon Schubert * Promotion to a 2MB (PDE) page mapping requires that the corresponding 4KB 116b2b3ffcdSSimon Schubert * (PTE) page mappings have identical settings for the following fields: 117b2b3ffcdSSimon Schubert */ 118a86ce0cdSMatthew Dillon /* 119b2b3ffcdSSimon Schubert #define PG_PTE_PROMOTE (PG_NX | PG_MANAGED | PG_W | PG_G | PG_PTE_PAT | \ 120b2b3ffcdSSimon Schubert PG_M | PG_A | PG_NC_PCD | PG_NC_PWT | PG_U | PG_RW | PG_V) 121a86ce0cdSMatthew Dillon */ 122a69b35e0SAaron LI 123b2b3ffcdSSimon Schubert /* 124b2b3ffcdSSimon Schubert * Page Protection Exception bits 125b2b3ffcdSSimon Schubert */ 126b2b3ffcdSSimon Schubert #define PGEX_P 0x01 /* Protection violation vs. not present */ 127b2b3ffcdSSimon Schubert #define PGEX_W 0x02 /* during a Write cycle */ 128b2b3ffcdSSimon Schubert #define PGEX_U 0x04 /* access from User mode (UPL) */ 129b2b3ffcdSSimon Schubert #define PGEX_RSV 0x08 /* reserved PTE field is non-zero */ 130b2b3ffcdSSimon Schubert #define PGEX_I 0x10 /* during an instruction fetch */ 131b2b3ffcdSSimon Schubert 132b2b3ffcdSSimon Schubert /* 133b2b3ffcdSSimon Schubert * Virtual kernel bits, managed by software. Stored in tf_xflags. 134b2b3ffcdSSimon Schubert * 135b2b3ffcdSSimon Schubert * PGEX_FPFAULT - Force the FP unit to generate a T_DNA fault if an 136b2b3ffcdSSimon Schubert * emulated user process tried to use it. This bit is 137b2b3ffcdSSimon Schubert * only used by vmspace_ctl(). 138b2b3ffcdSSimon Schubert */ 139b2b3ffcdSSimon Schubert #define PGEX_FPFAULT 0x80 140b2b3ffcdSSimon Schubert 141b2b3ffcdSSimon Schubert #endif /* !_CPU_PMAP_H_ */ 142