pmap.h revision 1.2
11.2Ssekiya/* $NetBSD: pmap.h,v 1.2 2004/06/04 07:42:34 sekiya Exp $ */ 21.1Sfvdl 31.1Sfvdl/* 41.1Sfvdl * 51.1Sfvdl * Copyright (c) 1997 Charles D. Cranor and Washington University. 61.1Sfvdl * All rights reserved. 71.1Sfvdl * 81.1Sfvdl * Redistribution and use in source and binary forms, with or without 91.1Sfvdl * modification, are permitted provided that the following conditions 101.1Sfvdl * are met: 111.1Sfvdl * 1. Redistributions of source code must retain the above copyright 121.1Sfvdl * notice, this list of conditions and the following disclaimer. 131.1Sfvdl * 2. Redistributions in binary form must reproduce the above copyright 141.1Sfvdl * notice, this list of conditions and the following disclaimer in the 151.1Sfvdl * documentation and/or other materials provided with the distribution. 161.1Sfvdl * 3. All advertising materials mentioning features or use of this software 171.1Sfvdl * must display the following acknowledgment: 181.1Sfvdl * This product includes software developed by Charles D. Cranor and 191.1Sfvdl * Washington University. 201.1Sfvdl * 4. The name of the author may not be used to endorse or promote products 211.1Sfvdl * derived from this software without specific prior written permission. 221.1Sfvdl * 231.1Sfvdl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 241.1Sfvdl * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 251.1Sfvdl * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 261.1Sfvdl * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 271.1Sfvdl * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 281.1Sfvdl * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 291.1Sfvdl * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 301.1Sfvdl * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 311.1Sfvdl * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 321.1Sfvdl * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 331.1Sfvdl */ 341.1Sfvdl 351.1Sfvdl/* 361.1Sfvdl * Copyright (c) 2001 Wasabi Systems, Inc. 371.1Sfvdl * All rights reserved. 381.1Sfvdl * 391.1Sfvdl * Written by Frank van der Linden for Wasabi Systems, Inc. 401.1Sfvdl * 411.1Sfvdl * Redistribution and use in source and binary forms, with or without 421.1Sfvdl * modification, are permitted provided that the following conditions 431.1Sfvdl * are met: 441.1Sfvdl * 1. Redistributions of source code must retain the above copyright 451.1Sfvdl * notice, this list of conditions and the following disclaimer. 461.1Sfvdl * 2. Redistributions in binary form must reproduce the above copyright 471.1Sfvdl * notice, this list of conditions and the following disclaimer in the 481.1Sfvdl * documentation and/or other materials provided with the distribution. 491.1Sfvdl * 3. All advertising materials mentioning features or use of this software 501.1Sfvdl * must display the following acknowledgement: 511.1Sfvdl * This product includes software developed for the NetBSD Project by 521.1Sfvdl * Wasabi Systems, Inc. 531.1Sfvdl * 4. The name of Wasabi Systems, Inc. may not be used to endorse 541.1Sfvdl * or promote products derived from this software without specific prior 551.1Sfvdl * written permission. 561.1Sfvdl * 571.1Sfvdl * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 581.1Sfvdl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 591.1Sfvdl * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 601.1Sfvdl * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 611.1Sfvdl * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 621.1Sfvdl * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 631.1Sfvdl * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 641.1Sfvdl * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 651.1Sfvdl * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 661.1Sfvdl * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 671.1Sfvdl * POSSIBILITY OF SUCH DAMAGE. 681.1Sfvdl */ 691.1Sfvdl 701.1Sfvdl/* 711.1Sfvdl * pmap.h: see pmap.c for the history of this pmap module. 721.1Sfvdl */ 731.1Sfvdl 741.1Sfvdl#ifndef _AMD64_PMAP_H_ 751.1Sfvdl#define _AMD64_PMAP_H_ 761.1Sfvdl 771.1Sfvdl#ifndef _LOCORE 781.1Sfvdl#if defined(_KERNEL_OPT) 791.1Sfvdl#include "opt_largepages.h" 801.1Sfvdl#endif 811.1Sfvdl 821.1Sfvdl#include <machine/cpufunc.h> 831.1Sfvdl#include <machine/pte.h> 841.1Sfvdl#include <machine/segments.h> 851.1Sfvdl#include <uvm/uvm_object.h> 861.1Sfvdl#endif 871.1Sfvdl 881.1Sfvdl/* 891.1Sfvdl * The x86_64 pmap module closely resembles the i386 one. It uses 901.1Sfvdl * the same recursive entry scheme, and the same alternate area 911.1Sfvdl * trick for accessing non-current pmaps. See the i386 pmap.h 921.1Sfvdl * for a description. The obvious difference is that 3 extra 931.1Sfvdl * levels of page table need to be dealt with. The level 1 page 941.1Sfvdl * table pages are at: 951.1Sfvdl * 961.1Sfvdl * l1: 0x00007f8000000000 - 0x00007fffffffffff (39 bits, needs PML4 entry) 971.1Sfvdl * 981.1Sfvdl * The alternate space is at: 991.1Sfvdl * 1001.1Sfvdl * l1: 0xffffff8000000000 - 0xffffffffffffffff (39 bits, needs PML4 entry) 1011.1Sfvdl * 1021.1Sfvdl * The rest is kept as physical pages in 3 UVM objects, and is 1031.1Sfvdl * temporarily mapped for virtual access when needed. 1041.1Sfvdl * 1051.1Sfvdl * Note that address space is signed, so the layout for 48 bits is: 1061.1Sfvdl * 1071.1Sfvdl * +---------------------------------+ 0xffffffffffffffff 1081.1Sfvdl * | | 1091.1Sfvdl * | alt.L1 table (PTE pages) | 1101.1Sfvdl * | | 1111.1Sfvdl * +---------------------------------+ 0xffffff8000000000 1121.1Sfvdl * ~ ~ 1131.1Sfvdl * | | 1141.1Sfvdl * | Kernel Space | 1151.1Sfvdl * | | 1161.1Sfvdl * | | 1171.1Sfvdl * +---------------------------------+ 0xffff800000000000 = 0x0000008000000000 1181.1Sfvdl * | | 1191.1Sfvdl * | alt.L1 table (PTE pages) | 1201.1Sfvdl * | | 1211.1Sfvdl * +---------------------------------+ 0x00007f8000000000 1221.1Sfvdl * ~ ~ 1231.1Sfvdl * | | 1241.1Sfvdl * | User Space | 1251.1Sfvdl * | | 1261.1Sfvdl * | | 1271.1Sfvdl * +---------------------------------+ 0x0000000000000000 1281.1Sfvdl * 1291.1Sfvdl * In other words, there is a 'VA hole' at 0x0000008000000000 - 1301.1Sfvdl * 0xffff800000000000 which will trap, just as on, for example, 1311.1Sfvdl * sparcv9. 1321.1Sfvdl * 1331.1Sfvdl * The unused space can be used if needed, but it adds a little more 1341.1Sfvdl * complexity to the calculations. 1351.1Sfvdl */ 1361.1Sfvdl 1371.1Sfvdl/* 1381.1Sfvdl * The first generation of Hammer processors can use 48 bits of 1391.1Sfvdl * virtual memory, and 40 bits of physical memory. This will be 1401.1Sfvdl * more for later generations. These defines can be changed to 1411.1Sfvdl * variable names containing the # of bits, extracted from an 1421.1Sfvdl * extended cpuid instruction (variables are harder to use during 1431.1Sfvdl * bootstrap, though) 1441.1Sfvdl */ 1451.1Sfvdl#define VIRT_BITS 48 1461.1Sfvdl#define PHYS_BITS 40 1471.1Sfvdl 1481.1Sfvdl/* 1491.1Sfvdl * Mask to get rid of the sign-extended part of addresses. 1501.1Sfvdl */ 1511.1Sfvdl#define VA_SIGN_MASK 0xffff000000000000 1521.1Sfvdl#define VA_SIGN_NEG(va) ((va) | VA_SIGN_MASK) 1531.1Sfvdl/* 1541.1Sfvdl * XXXfvdl this one's not right. 1551.1Sfvdl */ 1561.1Sfvdl#define VA_SIGN_POS(va) ((va) & ~VA_SIGN_MASK) 1571.1Sfvdl 1581.1Sfvdl#define L4_SLOT_PTE 255 1591.1Sfvdl#define L4_SLOT_KERN 256 1601.1Sfvdl#define L4_SLOT_KERNBASE 511 1611.1Sfvdl#define L4_SLOT_APTE 510 1621.1Sfvdl 1631.1Sfvdl#define PDIR_SLOT_KERN L4_SLOT_KERN 1641.1Sfvdl#define PDIR_SLOT_PTE L4_SLOT_PTE 1651.1Sfvdl#define PDIR_SLOT_APTE L4_SLOT_APTE 1661.1Sfvdl 1671.1Sfvdl/* 1681.1Sfvdl * the following defines give the virtual addresses of various MMU 1691.1Sfvdl * data structures: 1701.1Sfvdl * PTE_BASE and APTE_BASE: the base VA of the linear PTE mappings 1711.1Sfvdl * PTD_BASE and APTD_BASE: the base VA of the recursive mapping of the PTD 1721.1Sfvdl * PDP_PDE and APDP_PDE: the VA of the PDE that points back to the PDP/APDP 1731.1Sfvdl * 1741.1Sfvdl */ 1751.1Sfvdl 1761.1Sfvdl#define PTE_BASE ((pt_entry_t *) (L4_SLOT_PTE * NBPD_L4)) 1771.1Sfvdl#define APTE_BASE ((pt_entry_t *) (VA_SIGN_NEG((L4_SLOT_APTE * NBPD_L4)))) 1781.1Sfvdl 1791.1Sfvdl#define L1_BASE PTE_BASE 1801.1Sfvdl#define AL1_BASE APTE_BASE 1811.1Sfvdl 1821.1Sfvdl#define L2_BASE ((pd_entry_t *)((char *)L1_BASE + L4_SLOT_PTE * NBPD_L3)) 1831.1Sfvdl#define L3_BASE ((pd_entry_t *)((char *)L2_BASE + L4_SLOT_PTE * NBPD_L2)) 1841.1Sfvdl#define L4_BASE ((pd_entry_t *)((char *)L3_BASE + L4_SLOT_PTE * NBPD_L1)) 1851.1Sfvdl 1861.1Sfvdl#define AL2_BASE ((pd_entry_t *)((char *)AL1_BASE + L4_SLOT_PTE * NBPD_L3)) 1871.1Sfvdl#define AL3_BASE ((pd_entry_t *)((char *)AL2_BASE + L4_SLOT_PTE * NBPD_L2)) 1881.1Sfvdl#define AL4_BASE ((pd_entry_t *)((char *)AL3_BASE + L4_SLOT_PTE * NBPD_L1)) 1891.1Sfvdl 1901.1Sfvdl#define PDP_PDE (L4_BASE + PDIR_SLOT_PTE) 1911.1Sfvdl#define APDP_PDE (L4_BASE + PDIR_SLOT_APTE) 1921.1Sfvdl 1931.1Sfvdl#define PDP_BASE L4_BASE 1941.1Sfvdl#define APDP_BASE AL4_BASE 1951.1Sfvdl 1961.1Sfvdl#define NKL4_MAX_ENTRIES (unsigned long)1 1971.1Sfvdl#define NKL3_MAX_ENTRIES (unsigned long)(NKL4_MAX_ENTRIES * 512) 1981.1Sfvdl#define NKL2_MAX_ENTRIES (unsigned long)(NKL3_MAX_ENTRIES * 512) 1991.1Sfvdl#define NKL1_MAX_ENTRIES (unsigned long)(NKL2_MAX_ENTRIES * 512) 2001.1Sfvdl 2011.1Sfvdl#define NKL4_KIMG_ENTRIES 1 2021.1Sfvdl#define NKL3_KIMG_ENTRIES 1 2031.1Sfvdl#define NKL2_KIMG_ENTRIES 8 2041.1Sfvdl 2051.1Sfvdl/* 2061.1Sfvdl * Since kva space is below the kernel in its entirety, we start off 2071.1Sfvdl * with zero entries on each level. 2081.1Sfvdl */ 2091.1Sfvdl#define NKL4_START_ENTRIES 0 2101.1Sfvdl#define NKL3_START_ENTRIES 0 2111.1Sfvdl#define NKL2_START_ENTRIES 0 2121.1Sfvdl#define NKL1_START_ENTRIES 0 /* XXX */ 2131.1Sfvdl 2141.1Sfvdl#define NTOPLEVEL_PDES (PAGE_SIZE / (sizeof (pd_entry_t))) 2151.1Sfvdl 2161.1Sfvdl#define KERNSPACE (NKL4_ENTRIES * NBPD_L4) 2171.1Sfvdl 2181.1Sfvdl#define NPDPG (PAGE_SIZE / sizeof (pd_entry_t)) 2191.1Sfvdl 2201.1Sfvdl#define ptei(VA) (((VA_SIGN_POS(VA)) & L1_MASK) >> L1_SHIFT) 2211.1Sfvdl 2221.1Sfvdl/* 2231.1Sfvdl * pl*_pi: index in the ptp page for a pde mapping a VA. 2241.1Sfvdl * (pl*_i below is the index in the virtual array of all pdes per level) 2251.1Sfvdl */ 2261.1Sfvdl#define pl1_pi(VA) (((VA_SIGN_POS(VA)) & L1_MASK) >> L1_SHIFT) 2271.1Sfvdl#define pl2_pi(VA) (((VA_SIGN_POS(VA)) & L2_MASK) >> L2_SHIFT) 2281.1Sfvdl#define pl3_pi(VA) (((VA_SIGN_POS(VA)) & L3_MASK) >> L3_SHIFT) 2291.1Sfvdl#define pl4_pi(VA) (((VA_SIGN_POS(VA)) & L4_MASK) >> L4_SHIFT) 2301.1Sfvdl 2311.1Sfvdl/* 2321.1Sfvdl * pl*_i: generate index into pde/pte arrays in virtual space 2331.1Sfvdl */ 2341.1Sfvdl#define pl1_i(VA) (((VA_SIGN_POS(VA)) & L1_FRAME) >> L1_SHIFT) 2351.1Sfvdl#define pl2_i(VA) (((VA_SIGN_POS(VA)) & L2_FRAME) >> L2_SHIFT) 2361.1Sfvdl#define pl3_i(VA) (((VA_SIGN_POS(VA)) & L3_FRAME) >> L3_SHIFT) 2371.1Sfvdl#define pl4_i(VA) (((VA_SIGN_POS(VA)) & L4_FRAME) >> L4_SHIFT) 2381.1Sfvdl#define pl_i(va, lvl) \ 2391.1Sfvdl (((VA_SIGN_POS(va)) & ptp_masks[(lvl)-1]) >> ptp_shifts[(lvl)-1]) 2401.1Sfvdl 2411.1Sfvdl#define PTP_MASK_INITIALIZER { L1_FRAME, L2_FRAME, L3_FRAME, L4_FRAME } 2421.1Sfvdl#define PTP_SHIFT_INITIALIZER { L1_SHIFT, L2_SHIFT, L3_SHIFT, L4_SHIFT } 2431.1Sfvdl#define NKPTP_INITIALIZER { NKL1_START_ENTRIES, NKL2_START_ENTRIES, \ 2441.1Sfvdl NKL3_START_ENTRIES, NKL4_START_ENTRIES } 2451.1Sfvdl#define NKPTPMAX_INITIALIZER { NKL1_MAX_ENTRIES, NKL2_MAX_ENTRIES, \ 2461.1Sfvdl NKL3_MAX_ENTRIES, NKL4_MAX_ENTRIES } 2471.1Sfvdl#define NBPD_INITIALIZER { NBPD_L1, NBPD_L2, NBPD_L3, NBPD_L4 } 2481.1Sfvdl#define PDES_INITIALIZER { L2_BASE, L3_BASE, L4_BASE } 2491.1Sfvdl#define APDES_INITIALIZER { AL2_BASE, AL3_BASE, AL4_BASE } 2501.1Sfvdl 2511.1Sfvdl/* 2521.1Sfvdl * PTP macros: 2531.1Sfvdl * a PTP's index is the PD index of the PDE that points to it 2541.1Sfvdl * a PTP's offset is the byte-offset in the PTE space that this PTP is at 2551.1Sfvdl * a PTP's VA is the first VA mapped by that PTP 2561.1Sfvdl * 2571.1Sfvdl * note that PAGE_SIZE == number of bytes in a PTP (4096 bytes == 1024 entries) 2581.1Sfvdl * NBPD == number of bytes a PTP can map (4MB) 2591.1Sfvdl */ 2601.1Sfvdl 2611.1Sfvdl#define ptp_va2o(va, lvl) (pl_i(va, (lvl)+1) * PAGE_SIZE) 2621.1Sfvdl 2631.1Sfvdl#define PTP_LEVELS 4 2641.1Sfvdl 2651.1Sfvdl/* 2661.1Sfvdl * PG_AVAIL usage: we make use of the ignored bits of the PTE 2671.1Sfvdl */ 2681.1Sfvdl 2691.1Sfvdl#define PG_W PG_AVAIL1 /* "wired" mapping */ 2701.1Sfvdl#define PG_PVLIST PG_AVAIL2 /* mapping has entry on pvlist */ 2711.1Sfvdl/* PG_AVAIL3 not used */ 2721.1Sfvdl 2731.1Sfvdl/* 2741.1Sfvdl * Number of PTE's per cache line. 8 byte pte, 64-byte cache line 2751.1Sfvdl * Used to avoid false sharing of cache lines. 2761.1Sfvdl */ 2771.1Sfvdl#define NPTECL 8 2781.1Sfvdl 2791.1Sfvdl 2801.1Sfvdl#if defined(_KERNEL) && !defined(_LOCORE) 2811.1Sfvdl/* 2821.1Sfvdl * pmap data structures: see pmap.c for details of locking. 2831.1Sfvdl */ 2841.1Sfvdl 2851.1Sfvdlstruct pmap; 2861.1Sfvdltypedef struct pmap *pmap_t; 2871.1Sfvdl 2881.1Sfvdl/* 2891.1Sfvdl * we maintain a list of all non-kernel pmaps 2901.1Sfvdl */ 2911.1Sfvdl 2921.1SfvdlLIST_HEAD(pmap_head, pmap); /* struct pmap_head: head of a pmap list */ 2931.1Sfvdl 2941.1Sfvdl/* 2951.1Sfvdl * the pmap structure 2961.1Sfvdl * 2971.1Sfvdl * note that the pm_obj contains the simple_lock, the reference count, 2981.1Sfvdl * page list, and number of PTPs within the pmap. 2991.1Sfvdl * 3001.1Sfvdl * pm_lock is the same as the spinlock for vm object 0. Changes to 3011.1Sfvdl * the other objects may only be made if that lock has been taken 3021.1Sfvdl * (the other object locks are only used when uvm_pagealloc is called) 3031.1Sfvdl */ 3041.1Sfvdl 3051.1Sfvdlstruct pmap { 3061.1Sfvdl struct uvm_object pm_obj[PTP_LEVELS-1]; /* objects for lvl >= 1) */ 3071.1Sfvdl#define pm_lock pm_obj[0].vmobjlock 3081.1Sfvdl#define pm_obj_l1 pm_obj[0] 3091.1Sfvdl#define pm_obj_l2 pm_obj[1] 3101.1Sfvdl#define pm_obj_l3 pm_obj[2] 3111.1Sfvdl LIST_ENTRY(pmap) pm_list; /* list (lck by pm_list lock) */ 3121.1Sfvdl pd_entry_t *pm_pdir; /* VA of PD (lck by object lock) */ 3131.1Sfvdl paddr_t pm_pdirpa; /* PA of PD (read-only after create) */ 3141.1Sfvdl struct vm_page *pm_ptphint[PTP_LEVELS-1]; 3151.1Sfvdl /* pointer to a PTP in our pmap */ 3161.1Sfvdl struct pmap_statistics pm_stats; /* pmap stats (lck by object lock) */ 3171.1Sfvdl 3181.1Sfvdl int pm_flags; /* see below */ 3191.1Sfvdl 3201.1Sfvdl union descriptor *pm_ldt; /* user-set LDT */ 3211.1Sfvdl int pm_ldt_len; /* number of LDT entries */ 3221.1Sfvdl int pm_ldt_sel; /* LDT selector */ 3231.1Sfvdl u_int32_t pm_cpus; /* mask of CPUs using pmap */ 3241.1Sfvdl}; 3251.1Sfvdl 3261.1Sfvdl/* pm_flags */ 3271.1Sfvdl#define PMF_USER_LDT 0x01 /* pmap has user-set LDT */ 3281.1Sfvdl 3291.1Sfvdl/* 3301.1Sfvdl * for each managed physical page we maintain a list of <PMAP,VA>'s 3311.1Sfvdl * which it is mapped at. the list is headed by a pv_head structure. 3321.1Sfvdl * there is one pv_head per managed phys page (allocated at boot time). 3331.1Sfvdl * the pv_head structure points to a list of pv_entry structures (each 3341.1Sfvdl * describes one mapping). 3351.1Sfvdl */ 3361.1Sfvdl 3371.2Ssekiyastruct pv_entry { /* locked by its list's pvh_lock */ 3381.2Ssekiya SPLAY_ENTRY(pv_entry) pv_node; /* splay-tree node */ 3391.2Ssekiya struct pmap *pv_pmap; /* the pmap */ 3401.2Ssekiya vaddr_t pv_va; /* the virtual address */ 3411.2Ssekiya struct vm_page *pv_ptp; /* the vm_page of the PTP */ 3421.2Ssekiya}; 3431.1Sfvdl 3441.1Sfvdl/* 3451.1Sfvdl * pv_entrys are dynamically allocated in chunks from a single page. 3461.1Sfvdl * we keep track of how many pv_entrys are in use for each page and 3471.1Sfvdl * we can free pv_entry pages if needed. there is one lock for the 3481.1Sfvdl * entire allocation system. 3491.1Sfvdl */ 3501.1Sfvdl 3511.1Sfvdlstruct pv_page_info { 3521.1Sfvdl TAILQ_ENTRY(pv_page) pvpi_list; 3531.1Sfvdl struct pv_entry *pvpi_pvfree; 3541.1Sfvdl int pvpi_nfree; 3551.1Sfvdl}; 3561.1Sfvdl 3571.1Sfvdl/* 3581.1Sfvdl * number of pv_entry's in a pv_page 3591.1Sfvdl * (note: won't work on systems where NPBG isn't a constant) 3601.1Sfvdl */ 3611.1Sfvdl 3621.1Sfvdl#define PVE_PER_PVPAGE ((PAGE_SIZE - sizeof(struct pv_page_info)) / \ 3631.1Sfvdl sizeof(struct pv_entry)) 3641.1Sfvdl 3651.1Sfvdl/* 3661.1Sfvdl * a pv_page: where pv_entrys are allocated from 3671.1Sfvdl */ 3681.1Sfvdl 3691.1Sfvdlstruct pv_page { 3701.1Sfvdl struct pv_page_info pvinfo; 3711.1Sfvdl struct pv_entry pvents[PVE_PER_PVPAGE]; 3721.1Sfvdl}; 3731.1Sfvdl 3741.1Sfvdl/* 3751.1Sfvdl * pmap_remove_record: a record of VAs that have been unmapped, used to 3761.1Sfvdl * flush TLB. if we have more than PMAP_RR_MAX then we stop recording. 3771.1Sfvdl */ 3781.1Sfvdl 3791.1Sfvdl#define PMAP_RR_MAX 16 /* max of 16 pages (64K) */ 3801.1Sfvdl 3811.1Sfvdlstruct pmap_remove_record { 3821.1Sfvdl int prr_npages; 3831.1Sfvdl vaddr_t prr_vas[PMAP_RR_MAX]; 3841.1Sfvdl}; 3851.1Sfvdl 3861.1Sfvdl/* 3871.1Sfvdl * global kernel variables 3881.1Sfvdl */ 3891.1Sfvdl 3901.1Sfvdl/* PTDpaddr: is the physical address of the kernel's PDP */ 3911.1Sfvdlextern u_long PTDpaddr; 3921.1Sfvdl 3931.1Sfvdlextern struct pmap kernel_pmap_store; /* kernel pmap */ 3941.1Sfvdlextern int pmap_pg_g; /* do we support PG_G? */ 3951.1Sfvdl 3961.1Sfvdlextern paddr_t ptp_masks[]; 3971.1Sfvdlextern int ptp_shifts[]; 3981.1Sfvdlextern long nkptp[], nbpd[], nkptpmax[]; 3991.1Sfvdlextern pd_entry_t *pdes[]; 4001.1Sfvdl 4011.1Sfvdl/* 4021.1Sfvdl * macros 4031.1Sfvdl */ 4041.1Sfvdl 4051.1Sfvdl#define pmap_kernel() (&kernel_pmap_store) 4061.1Sfvdl#define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count) 4071.1Sfvdl#define pmap_wired_count(pmap) ((pmap)->pm_stats.wired_count) 4081.1Sfvdl#define pmap_update(pmap) /* nothing (yet) */ 4091.1Sfvdl 4101.1Sfvdl#define pmap_clear_modify(pg) pmap_clear_attrs(pg, PG_M) 4111.1Sfvdl#define pmap_clear_reference(pg) pmap_clear_attrs(pg, PG_U) 4121.1Sfvdl#define pmap_copy(DP,SP,D,L,S) 4131.1Sfvdl#define pmap_is_modified(pg) pmap_test_attrs(pg, PG_M) 4141.1Sfvdl#define pmap_is_referenced(pg) pmap_test_attrs(pg, PG_U) 4151.1Sfvdl#define pmap_move(DP,SP,D,L,S) 4161.1Sfvdl#define pmap_phys_address(ppn) ptob(ppn) 4171.1Sfvdl#define pmap_valid_entry(E) ((E) & PG_V) /* is PDE or PTE valid? */ 4181.1Sfvdl 4191.1Sfvdl 4201.1Sfvdl/* 4211.1Sfvdl * prototypes 4221.1Sfvdl */ 4231.1Sfvdl 4241.1Sfvdlvoid pmap_activate __P((struct lwp *)); 4251.1Sfvdlvoid pmap_bootstrap __P((vaddr_t)); 4261.1Sfvdlboolean_t pmap_clear_attrs __P((struct vm_page *, unsigned)); 4271.1Sfvdlvoid pmap_deactivate __P((struct lwp *)); 4281.1Sfvdlstatic void pmap_page_protect __P((struct vm_page *, vm_prot_t)); 4291.1Sfvdlvoid pmap_page_remove __P((struct vm_page *)); 4301.1Sfvdlstatic void pmap_protect __P((struct pmap *, vaddr_t, 4311.1Sfvdl vaddr_t, vm_prot_t)); 4321.1Sfvdlvoid pmap_remove __P((struct pmap *, vaddr_t, vaddr_t)); 4331.1Sfvdlboolean_t pmap_test_attrs __P((struct vm_page *, unsigned)); 4341.1Sfvdlstatic void pmap_update_pg __P((vaddr_t)); 4351.1Sfvdlstatic void pmap_update_2pg __P((vaddr_t,vaddr_t)); 4361.1Sfvdlvoid pmap_write_protect __P((struct pmap *, vaddr_t, 4371.1Sfvdl vaddr_t, vm_prot_t)); 4381.1Sfvdl 4391.1Sfvdlvaddr_t reserve_dumppages __P((vaddr_t)); /* XXX: not a pmap fn */ 4401.1Sfvdl 4411.1Sfvdlvoid pmap_tlb_shootdown __P((pmap_t, vaddr_t, pt_entry_t, int32_t *)); 4421.1Sfvdlvoid pmap_tlb_shootnow __P((int32_t)); 4431.1Sfvdlvoid pmap_do_tlb_shootdown __P((struct cpu_info *)); 4441.1Sfvdlvoid pmap_prealloc_lowmem_ptps __P((void)); 4451.1Sfvdl 4461.1Sfvdl#define PMAP_GROWKERNEL /* turn on pmap_growkernel interface */ 4471.1Sfvdl 4481.1Sfvdl/* 4491.1Sfvdl * Do idle page zero'ing uncached to avoid polluting the cache. 4501.1Sfvdl */ 4511.1Sfvdlboolean_t pmap_pageidlezero __P((paddr_t)); 4521.1Sfvdl#define PMAP_PAGEIDLEZERO(pa) pmap_pageidlezero((pa)) 4531.1Sfvdl 4541.1Sfvdl/* 4551.1Sfvdl * inline functions 4561.1Sfvdl */ 4571.1Sfvdl 4581.1Sfvdlstatic __inline void 4591.1Sfvdlpmap_remove_all(struct pmap *pmap) 4601.1Sfvdl{ 4611.1Sfvdl /* Nothing. */ 4621.1Sfvdl} 4631.1Sfvdl 4641.1Sfvdl/* 4651.1Sfvdl * pmap_update_pg: flush one page from the TLB (or flush the whole thing 4661.1Sfvdl * if hardware doesn't support one-page flushing) 4671.1Sfvdl */ 4681.1Sfvdl 4691.1Sfvdl__inline static void 4701.1Sfvdlpmap_update_pg(va) 4711.1Sfvdl vaddr_t va; 4721.1Sfvdl{ 4731.1Sfvdl invlpg(va); 4741.1Sfvdl} 4751.1Sfvdl 4761.1Sfvdl/* 4771.1Sfvdl * pmap_update_2pg: flush two pages from the TLB 4781.1Sfvdl */ 4791.1Sfvdl 4801.1Sfvdl__inline static void 4811.1Sfvdlpmap_update_2pg(va, vb) 4821.1Sfvdl vaddr_t va, vb; 4831.1Sfvdl{ 4841.1Sfvdl invlpg(va); 4851.1Sfvdl invlpg(vb); 4861.1Sfvdl} 4871.1Sfvdl 4881.1Sfvdl/* 4891.1Sfvdl * pmap_page_protect: change the protection of all recorded mappings 4901.1Sfvdl * of a managed page 4911.1Sfvdl * 4921.1Sfvdl * => this function is a frontend for pmap_page_remove/pmap_clear_attrs 4931.1Sfvdl * => we only have to worry about making the page more protected. 4941.1Sfvdl * unprotecting a page is done on-demand at fault time. 4951.1Sfvdl */ 4961.1Sfvdl 4971.1Sfvdl__inline static void 4981.1Sfvdlpmap_page_protect(struct vm_page *pg, vm_prot_t prot) 4991.1Sfvdl{ 5001.1Sfvdl if ((prot & VM_PROT_WRITE) == 0) { 5011.1Sfvdl if (prot & (VM_PROT_READ|VM_PROT_EXECUTE)) { 5021.1Sfvdl (void) pmap_clear_attrs(pg, PG_RW); 5031.1Sfvdl } else { 5041.1Sfvdl pmap_page_remove(pg); 5051.1Sfvdl } 5061.1Sfvdl } 5071.1Sfvdl} 5081.1Sfvdl 5091.1Sfvdl/* 5101.1Sfvdl * pmap_protect: change the protection of pages in a pmap 5111.1Sfvdl * 5121.1Sfvdl * => this function is a frontend for pmap_remove/pmap_write_protect 5131.1Sfvdl * => we only have to worry about making the page more protected. 5141.1Sfvdl * unprotecting a page is done on-demand at fault time. 5151.1Sfvdl */ 5161.1Sfvdl 5171.1Sfvdl__inline static void 5181.1Sfvdlpmap_protect(pmap, sva, eva, prot) 5191.1Sfvdl struct pmap *pmap; 5201.1Sfvdl vaddr_t sva, eva; 5211.1Sfvdl vm_prot_t prot; 5221.1Sfvdl{ 5231.1Sfvdl if ((prot & VM_PROT_WRITE) == 0) { 5241.1Sfvdl if (prot & (VM_PROT_READ|VM_PROT_EXECUTE)) { 5251.1Sfvdl pmap_write_protect(pmap, sva, eva, prot); 5261.1Sfvdl } else { 5271.1Sfvdl pmap_remove(pmap, sva, eva); 5281.1Sfvdl } 5291.1Sfvdl } 5301.1Sfvdl} 5311.1Sfvdl 5321.1Sfvdl/* 5331.1Sfvdl * various address inlines 5341.1Sfvdl * 5351.1Sfvdl * vtopte: return a pointer to the PTE mapping a VA, works only for 5361.1Sfvdl * user and PT addresses 5371.1Sfvdl * 5381.1Sfvdl * kvtopte: return a pointer to the PTE mapping a kernel VA 5391.1Sfvdl */ 5401.1Sfvdl 5411.1Sfvdl#include <lib/libkern/libkern.h> 5421.1Sfvdl 5431.1Sfvdlstatic __inline pt_entry_t * 5441.1Sfvdlvtopte(vaddr_t va) 5451.1Sfvdl{ 5461.1Sfvdl 5471.1Sfvdl KASSERT(va < (L4_SLOT_KERN * NBPD_L4)); 5481.1Sfvdl 5491.1Sfvdl return (PTE_BASE + pl1_i(va)); 5501.1Sfvdl} 5511.1Sfvdl 5521.1Sfvdlstatic __inline pt_entry_t * 5531.1Sfvdlkvtopte(vaddr_t va) 5541.1Sfvdl{ 5551.1Sfvdl 5561.1Sfvdl KASSERT(va >= (L4_SLOT_KERN * NBPD_L4)); 5571.1Sfvdl 5581.1Sfvdl#ifdef LARGEPAGES 5591.1Sfvdl { 5601.1Sfvdl pd_entry_t *pde; 5611.1Sfvdl 5621.1Sfvdl pde = L1_BASE + pl2_i(va); 5631.1Sfvdl if (*pde & PG_PS) 5641.1Sfvdl return ((pt_entry_t *)pde); 5651.1Sfvdl } 5661.1Sfvdl#endif 5671.1Sfvdl 5681.1Sfvdl return (PTE_BASE + pl1_i(va)); 5691.1Sfvdl} 5701.1Sfvdl 5711.1Sfvdl#define pmap_pte_set(p, n) x86_atomic_testset_u64(p, n) 5721.1Sfvdl#define pmap_pte_clearbits(p, b) x86_atomic_clearbits_u64(p, b) 5731.1Sfvdl#define pmap_cpu_has_pg_n() (1) 5741.1Sfvdl#define pmap_cpu_has_invlpg (1) 5751.1Sfvdl 5761.1Sfvdlpaddr_t vtophys __P((vaddr_t)); 5771.1Sfvdlvaddr_t pmap_map __P((vaddr_t, paddr_t, paddr_t, vm_prot_t)); 5781.1Sfvdl 5791.1Sfvdl#if 0 /* XXXfvdl was USER_LDT, need to check if that can be supported */ 5801.1Sfvdlvoid pmap_ldt_cleanup __P((struct lwp *)); 5811.1Sfvdl#define PMAP_FORK 5821.1Sfvdl#endif /* USER_LDT */ 5831.1Sfvdl 5841.1Sfvdl/* 5851.1Sfvdl * Hooks for the pool allocator. 5861.1Sfvdl */ 5871.1Sfvdl#define POOL_VTOPHYS(va) vtophys((vaddr_t) (va)) 5881.1Sfvdl 5891.1Sfvdl#endif /* _KERNEL && !_LOCORE */ 5901.1Sfvdl#endif /* _AMD64_PMAP_H_ */ 591