160727d8bSWarner Losh /*- 251369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 351369649SPedro F. Giffuni * 4df8bae1dSRodney W. Grimes * Copyright (c) 1991, 1993 5df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved. 6df8bae1dSRodney W. Grimes * 7df8bae1dSRodney W. Grimes * This code is derived from software contributed to Berkeley by 8df8bae1dSRodney W. Grimes * The Mach Operating System project at Carnegie-Mellon University. 9df8bae1dSRodney W. Grimes * 10df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 11df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 12df8bae1dSRodney W. Grimes * are met: 13df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 14df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 15df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 16df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 17df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 18fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors 19df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 20df8bae1dSRodney W. Grimes * without specific prior written permission. 21df8bae1dSRodney W. Grimes * 22df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32df8bae1dSRodney W. Grimes * SUCH DAMAGE. 33df8bae1dSRodney W. Grimes * 343c4dd356SDavid Greenman * from: @(#)pmap.h 8.1 (Berkeley) 6/11/93 35df8bae1dSRodney W. Grimes * 36df8bae1dSRodney W. Grimes * 37df8bae1dSRodney W. Grimes * Copyright (c) 1987, 1990 Carnegie-Mellon University. 38df8bae1dSRodney W. Grimes * All rights reserved. 39df8bae1dSRodney W. Grimes * 40df8bae1dSRodney W. Grimes * Author: Avadis Tevanian, Jr. 41df8bae1dSRodney W. Grimes * 42df8bae1dSRodney W. Grimes * Permission to use, copy, modify and distribute this software and 43df8bae1dSRodney W. Grimes * its documentation is hereby granted, provided that both the copyright 44df8bae1dSRodney W. Grimes * notice and this permission notice appear in all copies of the 45df8bae1dSRodney W. Grimes * software, derivative works or modified versions, and any portions 46df8bae1dSRodney W. Grimes * thereof, and that both notices appear in supporting documentation. 47df8bae1dSRodney W. Grimes * 48df8bae1dSRodney W. Grimes * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 49df8bae1dSRodney W. Grimes * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 50df8bae1dSRodney W. Grimes * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 51df8bae1dSRodney W. Grimes * 52df8bae1dSRodney W. Grimes * Carnegie Mellon requests users of this software to return to 53df8bae1dSRodney W. Grimes * 54df8bae1dSRodney W. Grimes * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 55df8bae1dSRodney W. Grimes * School of Computer Science 56df8bae1dSRodney W. Grimes * Carnegie Mellon University 57df8bae1dSRodney W. Grimes * Pittsburgh PA 15213-3890 58df8bae1dSRodney W. Grimes * 59df8bae1dSRodney W. Grimes * any improvements or extensions that they make and grant Carnegie the 60df8bae1dSRodney W. Grimes * rights to redistribute these changes. 613c4dd356SDavid Greenman * 62c3aac50fSPeter Wemm * $FreeBSD$ 63df8bae1dSRodney W. Grimes */ 64df8bae1dSRodney W. Grimes 65df8bae1dSRodney W. Grimes /* 66df8bae1dSRodney W. Grimes * Machine address mapping definitions -- machine-independent 67df8bae1dSRodney W. Grimes * section. [For machine-dependent section, see "machine/pmap.h".] 68df8bae1dSRodney W. Grimes */ 69df8bae1dSRodney W. Grimes 70df8bae1dSRodney W. Grimes #ifndef _PMAP_VM_ 71df8bae1dSRodney W. Grimes #define _PMAP_VM_ 72df8bae1dSRodney W. Grimes /* 73df8bae1dSRodney W. Grimes * Each machine dependent implementation is expected to 74df8bae1dSRodney W. Grimes * keep certain statistics. They may do this anyway they 75df8bae1dSRodney W. Grimes * so choose, but are expected to return the statistics 76df8bae1dSRodney W. Grimes * in the following structure. 77df8bae1dSRodney W. Grimes */ 78df8bae1dSRodney W. Grimes struct pmap_statistics { 79df8bae1dSRodney W. Grimes long resident_count; /* # of pages mapped (total) */ 80df8bae1dSRodney W. Grimes long wired_count; /* # of pages wired */ 81df8bae1dSRodney W. Grimes }; 82df8bae1dSRodney W. Grimes typedef struct pmap_statistics *pmap_statistics_t; 83df8bae1dSRodney W. Grimes 843153e878SAlan Cox /* 856031c68dSAlan Cox * Each machine-dependent implementation is required to provide: 863153e878SAlan Cox * 873153e878SAlan Cox * vm_memattr_t pmap_page_get_memattr(vm_page_t); 883153e878SAlan Cox * boolean_t pmap_page_is_mapped(vm_page_t); 896031c68dSAlan Cox * boolean_t pmap_page_is_write_mapped(vm_page_t); 903153e878SAlan Cox * void pmap_page_set_memattr(vm_page_t, vm_memattr_t); 913153e878SAlan Cox */ 92df8bae1dSRodney W. Grimes #include <machine/pmap.h> 93df8bae1dSRodney W. Grimes 94c4473420SPeter Wemm #ifdef _KERNEL 95b40ce416SJulian Elischer struct thread; 968bcc577eSBruce Evans 9753b19636SAlan Cox /* 9853b19636SAlan Cox * Updates to kernel_vm_end are synchronized by the kernel_map's system mutex. 9953b19636SAlan Cox */ 10053b19636SAlan Cox extern vm_offset_t kernel_vm_end; 10153b19636SAlan Cox 10239ffa8c1SKonstantin Belousov /* 10339ffa8c1SKonstantin Belousov * Flags for pmap_enter(). The bits in the low-order byte are reserved 10439ffa8c1SKonstantin Belousov * for the protection code (vm_prot_t) that describes the fault type. 105782e8960SAlan Cox * Bits 24 through 31 are reserved for the pmap's internal use. 10639ffa8c1SKonstantin Belousov */ 107782e8960SAlan Cox #define PMAP_ENTER_NOSLEEP 0x00000100 108782e8960SAlan Cox #define PMAP_ENTER_WIRED 0x00000200 109782e8960SAlan Cox #define PMAP_ENTER_RESERVED 0xFF000000 11039ffa8c1SKonstantin Belousov 1118cb0c102SAlan Cox /* 1128cb0c102SAlan Cox * Define the maximum number of machine-dependent reference bits that are 1138cb0c102SAlan Cox * cleared by a call to pmap_ts_referenced(). This limit serves two purposes. 1148cb0c102SAlan Cox * First, it bounds the cost of reference bit maintenance on widely shared 1158cb0c102SAlan Cox * pages. Second, it prevents numeric overflow during maintenance of a 1168cb0c102SAlan Cox * widely shared page's "act_count" field. An overflow could result in the 1178cb0c102SAlan Cox * premature deactivation of the page. 1188cb0c102SAlan Cox */ 1198cb0c102SAlan Cox #define PMAP_TS_REFERENCED_MAX 5 1208cb0c102SAlan Cox 1219454f828SAlan Cox void pmap_activate(struct thread *td); 12251321f7cSAlan Cox void pmap_advise(pmap_t pmap, vm_offset_t sva, vm_offset_t eva, 12351321f7cSAlan Cox int advice); 124d3249b14SAlan Cox void pmap_align_superpage(vm_object_t, vm_ooffset_t, vm_offset_t *, 125d3249b14SAlan Cox vm_size_t); 12611caded3SAlfred Perlstein void pmap_clear_modify(vm_page_t m); 12711caded3SAlfred Perlstein void pmap_copy(pmap_t, pmap_t, vm_offset_t, vm_size_t, vm_offset_t); 1281a87a0daSPeter Wemm void pmap_copy_page(vm_page_t, vm_page_t); 129e8a4a618SKonstantin Belousov void pmap_copy_pages(vm_page_t ma[], vm_offset_t a_offset, 130e8a4a618SKonstantin Belousov vm_page_t mb[], vm_offset_t b_offset, int xfersize); 13139ffa8c1SKonstantin Belousov int pmap_enter(pmap_t pmap, vm_offset_t va, vm_page_t m, 13239ffa8c1SKonstantin Belousov vm_prot_t prot, u_int flags, int8_t psind); 133ce142d9eSAlan Cox void pmap_enter_object(pmap_t pmap, vm_offset_t start, 134ce142d9eSAlan Cox vm_offset_t end, vm_page_t m_start, vm_prot_t prot); 1359454f828SAlan Cox void pmap_enter_quick(pmap_t pmap, vm_offset_t va, vm_page_t m, 1369454f828SAlan Cox vm_prot_t prot); 137227f9a1cSJake Burkholder vm_paddr_t pmap_extract(pmap_t pmap, vm_offset_t va); 138b9850eb2SAlan Cox vm_page_t pmap_extract_and_hold(pmap_t pmap, vm_offset_t va, 139b9850eb2SAlan Cox vm_prot_t prot); 14011caded3SAlfred Perlstein void pmap_growkernel(vm_offset_t); 141bdb93eb2SAlan Cox void pmap_init(void); 14211caded3SAlfred Perlstein boolean_t pmap_is_modified(vm_page_t m); 143566526a9SAlan Cox boolean_t pmap_is_prefaultable(pmap_t pmap, vm_offset_t va); 1447b85f591SAlan Cox boolean_t pmap_is_referenced(vm_page_t m); 145e45b89d2SKonstantin Belousov boolean_t pmap_is_valid_memattr(pmap_t, vm_memattr_t); 146227f9a1cSJake Burkholder vm_offset_t pmap_map(vm_offset_t *, vm_paddr_t, vm_paddr_t, int); 147567e51e1SAlan Cox int pmap_mincore(pmap_t pmap, vm_offset_t addr, 148567e51e1SAlan Cox vm_paddr_t *locked_pa); 14911caded3SAlfred Perlstein void pmap_object_init_pt(pmap_t pmap, vm_offset_t addr, 1501f78f902SAlan Cox vm_object_t object, vm_pindex_t pindex, vm_size_t size); 15111caded3SAlfred Perlstein boolean_t pmap_page_exists_quick(pmap_t pmap, vm_page_t m); 1521c245ae7SAlan Cox void pmap_page_init(vm_page_t m); 15359677d3cSAlan Cox int pmap_page_wired_mappings(vm_page_t m); 15489b57fcfSKonstantin Belousov int pmap_pinit(pmap_t); 15511caded3SAlfred Perlstein void pmap_pinit0(pmap_t); 15611caded3SAlfred Perlstein void pmap_protect(pmap_t, vm_offset_t, vm_offset_t, vm_prot_t); 15711caded3SAlfred Perlstein void pmap_qenter(vm_offset_t, vm_page_t *, int); 15811caded3SAlfred Perlstein void pmap_qremove(vm_offset_t, int); 1590a3e1547SJason A. Harmening vm_offset_t pmap_quick_enter_page(vm_page_t); 1600a3e1547SJason A. Harmening void pmap_quick_remove_page(vm_offset_t); 16111caded3SAlfred Perlstein void pmap_release(pmap_t); 16211caded3SAlfred Perlstein void pmap_remove(pmap_t, vm_offset_t, vm_offset_t); 1636372d61eSAlan Cox void pmap_remove_all(vm_page_t m); 164b9eee07eSPeter Wemm void pmap_remove_pages(pmap_t); 16578985e42SAlan Cox void pmap_remove_write(vm_page_t m); 1661a4fcaebSMarcel Moolenaar void pmap_sync_icache(pmap_t, vm_offset_t, vm_size_t); 167*b93a053cSEd Maste int pmap_ts_referenced(vm_page_t m); 16809132ba6SAlan Cox void pmap_unwire(pmap_t pmap, vm_offset_t start, vm_offset_t end); 1691a87a0daSPeter Wemm void pmap_zero_page(vm_page_t); 1701a87a0daSPeter Wemm void pmap_zero_page_area(vm_page_t, int off, int size); 1712bc7dd56SBruce M Simpson 1722bc7dd56SBruce M Simpson #define pmap_resident_count(pm) ((pm)->pm_stats.resident_count) 1732bc7dd56SBruce M Simpson #define pmap_wired_count(pm) ((pm)->pm_stats.wired_count) 1742bc7dd56SBruce M Simpson 175c4473420SPeter Wemm #endif /* _KERNEL */ 176df8bae1dSRodney W. Grimes #endif /* _PMAP_VM_ */ 177