1ae115bc7Smrj /* 2ae115bc7Smrj * CDDL HEADER START 3ae115bc7Smrj * 4ae115bc7Smrj * The contents of this file are subject to the terms of the 5ae115bc7Smrj * Common Development and Distribution License (the "License"). 6ae115bc7Smrj * You may not use this file except in compliance with the License. 7ae115bc7Smrj * 8ae115bc7Smrj * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9ae115bc7Smrj * or http://www.opensolaris.org/os/licensing. 10ae115bc7Smrj * See the License for the specific language governing permissions 11ae115bc7Smrj * and limitations under the License. 12ae115bc7Smrj * 13ae115bc7Smrj * When distributing Covered Code, include this CDDL HEADER in each 14ae115bc7Smrj * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15ae115bc7Smrj * If applicable, add the following below this CDDL HEADER, with the 16ae115bc7Smrj * fields enclosed by brackets "[]" replaced with your own identifying 17ae115bc7Smrj * information: Portions Copyright [yyyy] [name of copyright owner] 18ae115bc7Smrj * 19ae115bc7Smrj * CDDL HEADER END 20ae115bc7Smrj */ 21ae115bc7Smrj /* 22ae115bc7Smrj * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23ae115bc7Smrj * Use is subject to license terms. 2474ecdb51SJohn Levon * 2574ecdb51SJohn Levon * Copyright 2018 Joyent, Inc. 26*e3092845SStuart Maybee * Copyright 2022 Tintri by DDN, Inc. All rights reserved. 27ae115bc7Smrj */ 28ae115bc7Smrj 29ae115bc7Smrj #ifndef _SYS_MACH_MMU_H 30ae115bc7Smrj #define _SYS_MACH_MMU_H 31ae115bc7Smrj 32ae115bc7Smrj #ifdef __cplusplus 33ae115bc7Smrj extern "C" { 34ae115bc7Smrj #endif 35ae115bc7Smrj 36ae115bc7Smrj #ifndef _ASM 37ae115bc7Smrj 38ae115bc7Smrj #include <sys/types.h> 39ae115bc7Smrj #include <sys/systm.h> 40ae115bc7Smrj 41ae115bc7Smrj /* 42ae115bc7Smrj * Platform-dependent MMU routines and types. 43ae115bc7Smrj * 44ae115bc7Smrj * WARNING: this header file is used by both dboot and i86pc, so don't go using 45ae115bc7Smrj * normal kernel headers. 46ae115bc7Smrj */ 47ae115bc7Smrj 48ae115bc7Smrj #define TWO_MEG (2 * 1024 * 1024) 49ae115bc7Smrj 50ae115bc7Smrj /* 51ae115bc7Smrj * This is: 52ae115bc7Smrj * The kernel nucleus pagesizes, ie: bi->bi_kseg_size 53ae115bc7Smrj * The grub 64 bit file load address (see multiboot header in dboot_grub.s) 54ae115bc7Smrj * The grub 32 bit and hypervisor physical load addresses of 55ae115bc7Smrj * the kernel text/data (see Mapfile.unix) 56ae115bc7Smrj */ 57ae115bc7Smrj #define FOUR_MEG (4 * 1024 * 1024) 58ae115bc7Smrj 59ae115bc7Smrj #define ONE_GIG (1024 * 1024 * 1024) 60ae115bc7Smrj #define FOUR_GIG ((uint64_t)4 * ONE_GIG) 61ae115bc7Smrj 62ae115bc7Smrj #define MMU_STD_PAGESIZE 4096 63*e3092845SStuart Maybee 64*e3092845SStuart Maybee /* 65*e3092845SStuart Maybee * Defines for 4 and 5 level Virtual address ranges 66*e3092845SStuart Maybee */ 67*e3092845SStuart Maybee #define MMU_NPGOFFBITS 12 68*e3092845SStuart Maybee #define MMU_NPTIXBITS 9 69*e3092845SStuart Maybee #define MMU_MAX4LEVELVABITS (4 * MMU_NPTIXBITS + MMU_NPGOFFBITS) 70*e3092845SStuart Maybee #define MMU_MAX5LEVELVABITS (5 * MMU_NPTIXBITS + MMU_NPGOFFBITS) 71*e3092845SStuart Maybee 72ae115bc7Smrj #ifdef __amd64 73ae115bc7Smrj #define MMU_STD_PAGEMASK 0xFFFFFFFFFFFFF000ULL 74ae115bc7Smrj #else 75ae115bc7Smrj #define MMU_STD_PAGEMASK 0xFFFFF000UL 76ae115bc7Smrj #endif 77ae115bc7Smrj 78ae115bc7Smrj /* 79ae115bc7Smrj * Defines for the bits in X86 and AMD64 Page Tables 80ae115bc7Smrj * 81ae115bc7Smrj * Notes: 82ae115bc7Smrj * 83ae115bc7Smrj * Largepages and PAT bits: 84ae115bc7Smrj * 85ae115bc7Smrj * bit 7 at level 0 is the PAT bit 86ae115bc7Smrj * bit 7 above level 0 is the Pagesize bit (set for large page) 87ae115bc7Smrj * bit 12 (when a large page) is the PAT bit 88ae115bc7Smrj * 89ae115bc7Smrj * In Solaris the PAT/PWT/PCD values are set up so that: 90ae115bc7Smrj * 91ae115bc7Smrj * PAT & PWT -> Write Protected 92ae115bc7Smrj * PAT & PCD -> Write Combining 93ae115bc7Smrj * PAT by itself (PWT == 0 && PCD == 0) yields uncacheable (same as PCD == 1) 94ae115bc7Smrj * 95ae115bc7Smrj * 96ae115bc7Smrj * Permission bits: 97ae115bc7Smrj * 98ae115bc7Smrj * - PT_USER must be set in all levels for user pages 99ae115bc7Smrj * - PT_WRITE must be set in all levels for user writable pages 100ae115bc7Smrj * - PT_NX applies if set at any level 101ae115bc7Smrj * 102ae115bc7Smrj * For these, we use the "allow" settings in all tables above level 0 and only 103ae115bc7Smrj * ever disable things in PTEs. 104ae115bc7Smrj * 105ae115bc7Smrj * The use of PT_GLOBAL and PT_NX depend on being enabled in processor 106ae115bc7Smrj * control registers. Hence, we use a variable to reference these bit 107ae115bc7Smrj * masks. During hat_kern_setup() if the feature isn't enabled we 108ae115bc7Smrj * clear out the variables. 109ae115bc7Smrj */ 110ae115bc7Smrj #define PT_VALID (0x001) /* a valid translation is present */ 111ae115bc7Smrj #define PT_WRITABLE (0x002) /* the page is writable */ 112ae115bc7Smrj #define PT_USER (0x004) /* the page is accessible by user mode */ 113ae115bc7Smrj #define PT_WRITETHRU (0x008) /* write back caching is disabled (non-PAT) */ 114ae115bc7Smrj #define PT_NOCACHE (0x010) /* page is not cacheable (non-PAT) */ 115ae115bc7Smrj #define PT_REF (0x020) /* page was referenced */ 116ae115bc7Smrj #define PT_MOD (0x040) /* page was modified */ 117ae115bc7Smrj #define PT_PAGESIZE (0x080) /* above level 0, indicates a large page */ 118ae115bc7Smrj #define PT_PAT_4K (0x080) /* at level 0, used for write combining */ 119ae115bc7Smrj #define PT_GLOBAL (0x100) /* the mapping is global */ 120ae115bc7Smrj #define PT_SOFTWARE (0xe00) /* software bits */ 121ae115bc7Smrj 122ae115bc7Smrj #define PT_PAT_LARGE (0x1000) /* PAT bit for large pages */ 123ae115bc7Smrj 124ae115bc7Smrj #define PT_PTPBITS (PT_VALID | PT_USER | PT_WRITABLE | PT_REF) 125ae115bc7Smrj #define PT_FLAGBITS (0xfff) /* for masking off flag bits */ 126ae115bc7Smrj 127ae115bc7Smrj /* 128ae115bc7Smrj * The software bits are used by the HAT to track attributes. 129ae115bc7Smrj * Note that the attributes are inclusive as the values increase. 130ae115bc7Smrj * 131ae115bc7Smrj * PT_NOSYNC - The PT_REF/PT_MOD bits are not sync'd to page_t. 132ae115bc7Smrj * The hat will install them as always set. 133ae115bc7Smrj * 134ae115bc7Smrj * PT_NOCONSIST - There is no hment entry for this mapping. 135ae115bc7Smrj * 136843e1988Sjohnlev * PT_FOREIGN - used for the hypervisor, check via 137843e1988Sjohnlev * (pte & PT_SOFTWARE) >= PT_FOREIGN 138843e1988Sjohnlev * as it might set 0x800 for foreign grant table mappings. 139ae115bc7Smrj */ 140ae115bc7Smrj #define PT_NOSYNC (0x200) /* PTE was created with HAT_NOSYNC */ 141ae115bc7Smrj #define PT_NOCONSIST (0x400) /* PTE was created with HAT_LOAD_NOCONSIST */ 142843e1988Sjohnlev #define PT_FOREIGN (0x600) /* MFN mapped on the hypervisor has no PFN */ 143ae115bc7Smrj 14474ecdb51SJohn Levon #ifndef _BOOT 14574ecdb51SJohn Levon 14674ecdb51SJohn Levon extern ulong_t getcr3(void); 14774ecdb51SJohn Levon extern void setcr3(ulong_t); 14874ecdb51SJohn Levon 14974ecdb51SJohn Levon #define getcr3_pa() (getcr3() & MMU_PAGEMASK) 15074ecdb51SJohn Levon #define getpcid() ((getcr4() & CR4_PCIDE) ? \ 15174ecdb51SJohn Levon (getcr3() & MMU_PAGEOFFSET) : PCID_NONE) 15274ecdb51SJohn Levon 15374ecdb51SJohn Levon extern void mmu_invlpg(caddr_t); 15474ecdb51SJohn Levon 15574ecdb51SJohn Levon #endif 15674ecdb51SJohn Levon 157843e1988Sjohnlev #ifdef __xpv 158843e1988Sjohnlev #include <sys/xen_mmu.h> 159843e1988Sjohnlev #else 160ae115bc7Smrj #include <sys/pc_mmu.h> 161843e1988Sjohnlev #endif 162ae115bc7Smrj 163ae115bc7Smrj /* 164ae115bc7Smrj * The software extraction for a single Page Table Entry will always 165ae115bc7Smrj * be a 64 bit unsigned int. If running a non-PAE hat, the page table 166ae115bc7Smrj * access routines know to extend/shorten it to 32 bits. 167ae115bc7Smrj */ 168ae115bc7Smrj typedef uint64_t x86pte_t; 169ae115bc7Smrj typedef uint32_t x86pte32_t; 170ae115bc7Smrj 171ae115bc7Smrj x86pte_t get_pteval(paddr_t, uint_t); 172ae115bc7Smrj void set_pteval(paddr_t, uint_t, uint_t, x86pte_t); 173ae115bc7Smrj paddr_t make_ptable(x86pte_t *, uint_t); 174ae115bc7Smrj x86pte_t *find_pte(uint64_t, paddr_t *, uint_t, uint_t); 175ae115bc7Smrj x86pte_t *map_pte(paddr_t, uint_t); 176ae115bc7Smrj 177ae115bc7Smrj extern uint_t *shift_amt; 178ae115bc7Smrj extern uint_t ptes_per_table; 179ae115bc7Smrj extern paddr_t top_page_table; 180ae115bc7Smrj extern uint_t top_level; 181ae115bc7Smrj extern uint_t pte_size; 182ae115bc7Smrj extern uint_t shift_amt_nopae[]; 183ae115bc7Smrj extern uint_t shift_amt_pae[]; 184ae115bc7Smrj extern uint32_t lpagesize; 185ae115bc7Smrj 186ae115bc7Smrj #ifdef __cplusplus 187ae115bc7Smrj } 188ae115bc7Smrj #endif 189ae115bc7Smrj 190ae115bc7Smrj #endif /* _ASM */ 191ae115bc7Smrj 192ae115bc7Smrj #endif /* _SYS_MACH_MMU_H */ 193