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. 24ae115bc7Smrj */ 25ae115bc7Smrj 26ae115bc7Smrj #ifndef _SYS_MACH_MMU_H 27ae115bc7Smrj #define _SYS_MACH_MMU_H 28ae115bc7Smrj 29ae115bc7Smrj #pragma ident "%Z%%M% %I% %E% SMI" 30ae115bc7Smrj 31ae115bc7Smrj #ifdef __cplusplus 32ae115bc7Smrj extern "C" { 33ae115bc7Smrj #endif 34ae115bc7Smrj 35ae115bc7Smrj #ifndef _ASM 36ae115bc7Smrj 37ae115bc7Smrj #include <sys/types.h> 38ae115bc7Smrj #include <sys/systm.h> 39ae115bc7Smrj 40ae115bc7Smrj /* 41ae115bc7Smrj * Platform-dependent MMU routines and types. 42ae115bc7Smrj * 43ae115bc7Smrj * WARNING: this header file is used by both dboot and i86pc, so don't go using 44ae115bc7Smrj * normal kernel headers. 45ae115bc7Smrj */ 46ae115bc7Smrj 47ae115bc7Smrj #define TWO_MEG (2 * 1024 * 1024) 48ae115bc7Smrj 49ae115bc7Smrj /* 50ae115bc7Smrj * This is: 51ae115bc7Smrj * The kernel nucleus pagesizes, ie: bi->bi_kseg_size 52ae115bc7Smrj * The grub 64 bit file load address (see multiboot header in dboot_grub.s) 53ae115bc7Smrj * The grub 32 bit and hypervisor physical load addresses of 54ae115bc7Smrj * the kernel text/data (see Mapfile.unix) 55ae115bc7Smrj */ 56ae115bc7Smrj #define FOUR_MEG (4 * 1024 * 1024) 57ae115bc7Smrj 58ae115bc7Smrj #define ONE_GIG (1024 * 1024 * 1024) 59ae115bc7Smrj #define FOUR_GIG ((uint64_t)4 * ONE_GIG) 60ae115bc7Smrj 61ae115bc7Smrj #define MMU_STD_PAGESIZE 4096 62ae115bc7Smrj #ifdef __amd64 63ae115bc7Smrj #define MMU_STD_PAGEMASK 0xFFFFFFFFFFFFF000ULL 64ae115bc7Smrj #else 65ae115bc7Smrj #define MMU_STD_PAGEMASK 0xFFFFF000UL 66ae115bc7Smrj #endif 67ae115bc7Smrj 68ae115bc7Smrj /* 69ae115bc7Smrj * Defines for the bits in X86 and AMD64 Page Tables 70ae115bc7Smrj * 71ae115bc7Smrj * Notes: 72ae115bc7Smrj * 73ae115bc7Smrj * Largepages and PAT bits: 74ae115bc7Smrj * 75ae115bc7Smrj * bit 7 at level 0 is the PAT bit 76ae115bc7Smrj * bit 7 above level 0 is the Pagesize bit (set for large page) 77ae115bc7Smrj * bit 12 (when a large page) is the PAT bit 78ae115bc7Smrj * 79ae115bc7Smrj * In Solaris the PAT/PWT/PCD values are set up so that: 80ae115bc7Smrj * 81ae115bc7Smrj * PAT & PWT -> Write Protected 82ae115bc7Smrj * PAT & PCD -> Write Combining 83ae115bc7Smrj * PAT by itself (PWT == 0 && PCD == 0) yields uncacheable (same as PCD == 1) 84ae115bc7Smrj * 85ae115bc7Smrj * 86ae115bc7Smrj * Permission bits: 87ae115bc7Smrj * 88ae115bc7Smrj * - PT_USER must be set in all levels for user pages 89ae115bc7Smrj * - PT_WRITE must be set in all levels for user writable pages 90ae115bc7Smrj * - PT_NX applies if set at any level 91ae115bc7Smrj * 92ae115bc7Smrj * For these, we use the "allow" settings in all tables above level 0 and only 93ae115bc7Smrj * ever disable things in PTEs. 94ae115bc7Smrj * 95ae115bc7Smrj * The use of PT_GLOBAL and PT_NX depend on being enabled in processor 96ae115bc7Smrj * control registers. Hence, we use a variable to reference these bit 97ae115bc7Smrj * masks. During hat_kern_setup() if the feature isn't enabled we 98ae115bc7Smrj * clear out the variables. 99ae115bc7Smrj */ 100ae115bc7Smrj #define PT_VALID (0x001) /* a valid translation is present */ 101ae115bc7Smrj #define PT_WRITABLE (0x002) /* the page is writable */ 102ae115bc7Smrj #define PT_USER (0x004) /* the page is accessible by user mode */ 103ae115bc7Smrj #define PT_WRITETHRU (0x008) /* write back caching is disabled (non-PAT) */ 104ae115bc7Smrj #define PT_NOCACHE (0x010) /* page is not cacheable (non-PAT) */ 105ae115bc7Smrj #define PT_REF (0x020) /* page was referenced */ 106ae115bc7Smrj #define PT_MOD (0x040) /* page was modified */ 107ae115bc7Smrj #define PT_PAGESIZE (0x080) /* above level 0, indicates a large page */ 108ae115bc7Smrj #define PT_PAT_4K (0x080) /* at level 0, used for write combining */ 109ae115bc7Smrj #define PT_GLOBAL (0x100) /* the mapping is global */ 110ae115bc7Smrj #define PT_SOFTWARE (0xe00) /* software bits */ 111ae115bc7Smrj 112ae115bc7Smrj #define PT_PAT_LARGE (0x1000) /* PAT bit for large pages */ 113ae115bc7Smrj 114ae115bc7Smrj #define PT_PTPBITS (PT_VALID | PT_USER | PT_WRITABLE | PT_REF) 115ae115bc7Smrj #define PT_FLAGBITS (0xfff) /* for masking off flag bits */ 116ae115bc7Smrj 117ae115bc7Smrj /* 118ae115bc7Smrj * The software bits are used by the HAT to track attributes. 119ae115bc7Smrj * Note that the attributes are inclusive as the values increase. 120ae115bc7Smrj * 121ae115bc7Smrj * PT_NOSYNC - The PT_REF/PT_MOD bits are not sync'd to page_t. 122ae115bc7Smrj * The hat will install them as always set. 123ae115bc7Smrj * 124ae115bc7Smrj * PT_NOCONSIST - There is no hment entry for this mapping. 125ae115bc7Smrj * 126*843e1988Sjohnlev * PT_FOREIGN - used for the hypervisor, check via 127*843e1988Sjohnlev * (pte & PT_SOFTWARE) >= PT_FOREIGN 128*843e1988Sjohnlev * as it might set 0x800 for foreign grant table mappings. 129ae115bc7Smrj */ 130ae115bc7Smrj #define PT_NOSYNC (0x200) /* PTE was created with HAT_NOSYNC */ 131ae115bc7Smrj #define PT_NOCONSIST (0x400) /* PTE was created with HAT_LOAD_NOCONSIST */ 132*843e1988Sjohnlev #define PT_FOREIGN (0x600) /* MFN mapped on the hypervisor has no PFN */ 133ae115bc7Smrj 134*843e1988Sjohnlev #ifdef __xpv 135*843e1988Sjohnlev #include <sys/xen_mmu.h> 136*843e1988Sjohnlev #else 137ae115bc7Smrj #include <sys/pc_mmu.h> 138*843e1988Sjohnlev #endif 139ae115bc7Smrj 140ae115bc7Smrj /* 141ae115bc7Smrj * The software extraction for a single Page Table Entry will always 142ae115bc7Smrj * be a 64 bit unsigned int. If running a non-PAE hat, the page table 143ae115bc7Smrj * access routines know to extend/shorten it to 32 bits. 144ae115bc7Smrj */ 145ae115bc7Smrj typedef uint64_t x86pte_t; 146ae115bc7Smrj typedef uint32_t x86pte32_t; 147ae115bc7Smrj 148ae115bc7Smrj x86pte_t get_pteval(paddr_t, uint_t); 149ae115bc7Smrj void set_pteval(paddr_t, uint_t, uint_t, x86pte_t); 150ae115bc7Smrj paddr_t make_ptable(x86pte_t *, uint_t); 151ae115bc7Smrj x86pte_t *find_pte(uint64_t, paddr_t *, uint_t, uint_t); 152ae115bc7Smrj x86pte_t *map_pte(paddr_t, uint_t); 153ae115bc7Smrj 154ae115bc7Smrj #ifndef _BOOT 155ae115bc7Smrj ulong_t getcr3(); 156ae115bc7Smrj #endif 157ae115bc7Smrj 158ae115bc7Smrj extern uint_t *shift_amt; 159ae115bc7Smrj extern uint_t ptes_per_table; 160ae115bc7Smrj extern paddr_t top_page_table; 161ae115bc7Smrj extern uint_t top_level; 162ae115bc7Smrj extern uint_t pte_size; 163ae115bc7Smrj extern uint_t shift_amt_nopae[]; 164ae115bc7Smrj extern uint_t shift_amt_pae[]; 165ae115bc7Smrj extern uint32_t lpagesize; 166ae115bc7Smrj 167ae115bc7Smrj #ifdef __cplusplus 168ae115bc7Smrj } 169ae115bc7Smrj #endif 170ae115bc7Smrj 171ae115bc7Smrj #endif /* _ASM */ 172ae115bc7Smrj 173ae115bc7Smrj #endif /* _SYS_MACH_MMU_H */ 174