18d7e7a98SRuslan Bukin /*- 28d7e7a98SRuslan Bukin * Copyright (c) 1991 Regents of the University of California. 38d7e7a98SRuslan Bukin * All rights reserved. 48d7e7a98SRuslan Bukin * 58d7e7a98SRuslan Bukin * This code is derived from software contributed to Berkeley by 68d7e7a98SRuslan Bukin * the Systems Programming Group of the University of Utah Computer 78d7e7a98SRuslan Bukin * Science Department and William Jolitz of UUNET Technologies Inc. 88d7e7a98SRuslan Bukin * 98d7e7a98SRuslan Bukin * Redistribution and use in source and binary forms, with or without 108d7e7a98SRuslan Bukin * modification, are permitted provided that the following conditions 118d7e7a98SRuslan Bukin * are met: 128d7e7a98SRuslan Bukin * 1. Redistributions of source code must retain the above copyright 138d7e7a98SRuslan Bukin * notice, this list of conditions and the following disclaimer. 148d7e7a98SRuslan Bukin * 2. Redistributions in binary form must reproduce the above copyright 158d7e7a98SRuslan Bukin * notice, this list of conditions and the following disclaimer in the 168d7e7a98SRuslan Bukin * documentation and/or other materials provided with the distribution. 178d7e7a98SRuslan Bukin * 3. Neither the name of the University nor the names of its contributors 188d7e7a98SRuslan Bukin * may be used to endorse or promote products derived from this software 198d7e7a98SRuslan Bukin * without specific prior written permission. 208d7e7a98SRuslan Bukin * 218d7e7a98SRuslan Bukin * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 228d7e7a98SRuslan Bukin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 238d7e7a98SRuslan Bukin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 248d7e7a98SRuslan Bukin * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 258d7e7a98SRuslan Bukin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 268d7e7a98SRuslan Bukin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 278d7e7a98SRuslan Bukin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 288d7e7a98SRuslan Bukin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 298d7e7a98SRuslan Bukin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 308d7e7a98SRuslan Bukin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 318d7e7a98SRuslan Bukin * SUCH DAMAGE. 328d7e7a98SRuslan Bukin * 338d7e7a98SRuslan Bukin * $FreeBSD$ 348d7e7a98SRuslan Bukin */ 358d7e7a98SRuslan Bukin 368d7e7a98SRuslan Bukin #ifndef _MACHINE_PMAP_H_ 378d7e7a98SRuslan Bukin #define _MACHINE_PMAP_H_ 388d7e7a98SRuslan Bukin 398d7e7a98SRuslan Bukin #include <machine/pte.h> 408d7e7a98SRuslan Bukin 418d7e7a98SRuslan Bukin #ifndef LOCORE 428d7e7a98SRuslan Bukin 438d7e7a98SRuslan Bukin #include <sys/queue.h> 448d7e7a98SRuslan Bukin #include <sys/_lock.h> 458d7e7a98SRuslan Bukin #include <sys/_mutex.h> 468d7e7a98SRuslan Bukin 478d7e7a98SRuslan Bukin #ifdef _KERNEL 488d7e7a98SRuslan Bukin 498d7e7a98SRuslan Bukin #define vtophys(va) pmap_kextract((vm_offset_t)(va)) 508d7e7a98SRuslan Bukin 518d7e7a98SRuslan Bukin #endif 528d7e7a98SRuslan Bukin 538d7e7a98SRuslan Bukin #define pmap_page_get_memattr(m) ((m)->md.pv_memattr) 548d7e7a98SRuslan Bukin #define pmap_page_is_write_mapped(m) (((m)->aflags & PGA_WRITEABLE) != 0) 558d7e7a98SRuslan Bukin void pmap_page_set_memattr(vm_page_t m, vm_memattr_t ma); 568d7e7a98SRuslan Bukin 578d7e7a98SRuslan Bukin /* 588d7e7a98SRuslan Bukin * Pmap stuff 598d7e7a98SRuslan Bukin */ 608d7e7a98SRuslan Bukin 618d7e7a98SRuslan Bukin struct md_page { 628d7e7a98SRuslan Bukin TAILQ_HEAD(,pv_entry) pv_list; 638d7e7a98SRuslan Bukin int pv_gen; 648d7e7a98SRuslan Bukin vm_memattr_t pv_memattr; 658d7e7a98SRuslan Bukin }; 668d7e7a98SRuslan Bukin 678d7e7a98SRuslan Bukin /* 688d7e7a98SRuslan Bukin * This structure is used to hold a virtual<->physical address 698d7e7a98SRuslan Bukin * association and is used mostly by bootstrap code 708d7e7a98SRuslan Bukin */ 718d7e7a98SRuslan Bukin struct pv_addr { 728d7e7a98SRuslan Bukin SLIST_ENTRY(pv_addr) pv_list; 738d7e7a98SRuslan Bukin vm_offset_t pv_va; 748d7e7a98SRuslan Bukin vm_paddr_t pv_pa; 758d7e7a98SRuslan Bukin }; 768d7e7a98SRuslan Bukin 778d7e7a98SRuslan Bukin struct pmap { 788d7e7a98SRuslan Bukin struct mtx pm_mtx; 798d7e7a98SRuslan Bukin struct pmap_statistics pm_stats; /* pmap statictics */ 808d7e7a98SRuslan Bukin pd_entry_t *pm_l1; 818d7e7a98SRuslan Bukin TAILQ_HEAD(,pv_chunk) pm_pvchunk; /* list of mappings in pmap */ 829af94226SRuslan Bukin LIST_ENTRY(pmap) pm_list; /* List of all pmaps */ 838d7e7a98SRuslan Bukin }; 848d7e7a98SRuslan Bukin 858d7e7a98SRuslan Bukin typedef struct pv_entry { 868d7e7a98SRuslan Bukin vm_offset_t pv_va; /* virtual address for mapping */ 878d7e7a98SRuslan Bukin TAILQ_ENTRY(pv_entry) pv_next; 888d7e7a98SRuslan Bukin } *pv_entry_t; 898d7e7a98SRuslan Bukin 908d7e7a98SRuslan Bukin /* 918d7e7a98SRuslan Bukin * pv_entries are allocated in chunks per-process. This avoids the 928d7e7a98SRuslan Bukin * need to track per-pmap assignments. 938d7e7a98SRuslan Bukin */ 948d7e7a98SRuslan Bukin #define _NPCM 3 958d7e7a98SRuslan Bukin #define _NPCPV 168 968d7e7a98SRuslan Bukin struct pv_chunk { 978d7e7a98SRuslan Bukin struct pmap * pc_pmap; 988d7e7a98SRuslan Bukin TAILQ_ENTRY(pv_chunk) pc_list; 998d7e7a98SRuslan Bukin uint64_t pc_map[_NPCM]; /* bitmap; 1 = free */ 1008d7e7a98SRuslan Bukin TAILQ_ENTRY(pv_chunk) pc_lru; 1018d7e7a98SRuslan Bukin struct pv_entry pc_pventry[_NPCPV]; 1028d7e7a98SRuslan Bukin }; 1038d7e7a98SRuslan Bukin 1048d7e7a98SRuslan Bukin typedef struct pmap *pmap_t; 1058d7e7a98SRuslan Bukin 1068d7e7a98SRuslan Bukin #ifdef _KERNEL 1078d7e7a98SRuslan Bukin extern struct pmap kernel_pmap_store; 1088d7e7a98SRuslan Bukin #define kernel_pmap (&kernel_pmap_store) 1098d7e7a98SRuslan Bukin #define pmap_kernel() kernel_pmap 1108d7e7a98SRuslan Bukin 1118d7e7a98SRuslan Bukin #define PMAP_ASSERT_LOCKED(pmap) \ 1128d7e7a98SRuslan Bukin mtx_assert(&(pmap)->pm_mtx, MA_OWNED) 1138d7e7a98SRuslan Bukin #define PMAP_LOCK(pmap) mtx_lock(&(pmap)->pm_mtx) 1148d7e7a98SRuslan Bukin #define PMAP_LOCK_ASSERT(pmap, type) \ 1158d7e7a98SRuslan Bukin mtx_assert(&(pmap)->pm_mtx, (type)) 1168d7e7a98SRuslan Bukin #define PMAP_LOCK_DESTROY(pmap) mtx_destroy(&(pmap)->pm_mtx) 1178d7e7a98SRuslan Bukin #define PMAP_LOCK_INIT(pmap) mtx_init(&(pmap)->pm_mtx, "pmap", \ 1188d7e7a98SRuslan Bukin NULL, MTX_DEF | MTX_DUPOK) 1198d7e7a98SRuslan Bukin #define PMAP_OWNED(pmap) mtx_owned(&(pmap)->pm_mtx) 1208d7e7a98SRuslan Bukin #define PMAP_MTX(pmap) (&(pmap)->pm_mtx) 1218d7e7a98SRuslan Bukin #define PMAP_TRYLOCK(pmap) mtx_trylock(&(pmap)->pm_mtx) 1228d7e7a98SRuslan Bukin #define PMAP_UNLOCK(pmap) mtx_unlock(&(pmap)->pm_mtx) 1238d7e7a98SRuslan Bukin 1248d7e7a98SRuslan Bukin #define PHYS_AVAIL_SIZE 10 1258d7e7a98SRuslan Bukin extern vm_paddr_t phys_avail[]; 1268d7e7a98SRuslan Bukin extern vm_paddr_t dump_avail[]; 1278d7e7a98SRuslan Bukin extern vm_offset_t virtual_avail; 1288d7e7a98SRuslan Bukin extern vm_offset_t virtual_end; 1298d7e7a98SRuslan Bukin 1308d7e7a98SRuslan Bukin /* 1318d7e7a98SRuslan Bukin * Macros to test if a mapping is mappable with an L1 Section mapping 1328d7e7a98SRuslan Bukin * or an L2 Large Page mapping. 1338d7e7a98SRuslan Bukin */ 1348d7e7a98SRuslan Bukin #define L1_MAPPABLE_P(va, pa, size) \ 1358d7e7a98SRuslan Bukin ((((va) | (pa)) & L1_OFFSET) == 0 && (size) >= L1_SIZE) 1368d7e7a98SRuslan Bukin 1378d7e7a98SRuslan Bukin void pmap_bootstrap(vm_offset_t, vm_paddr_t, vm_size_t); 1388d7e7a98SRuslan Bukin void pmap_kenter_device(vm_offset_t, vm_size_t, vm_paddr_t); 1398d7e7a98SRuslan Bukin vm_paddr_t pmap_kextract(vm_offset_t va); 1408d7e7a98SRuslan Bukin void pmap_kremove(vm_offset_t); 1418d7e7a98SRuslan Bukin void pmap_kremove_device(vm_offset_t, vm_size_t); 1428d7e7a98SRuslan Bukin 1438d7e7a98SRuslan Bukin void *pmap_mapdev(vm_offset_t, vm_size_t); 1448d7e7a98SRuslan Bukin void *pmap_mapbios(vm_paddr_t, vm_size_t); 1458d7e7a98SRuslan Bukin void pmap_unmapdev(vm_offset_t, vm_size_t); 1468d7e7a98SRuslan Bukin void pmap_unmapbios(vm_offset_t, vm_size_t); 1478d7e7a98SRuslan Bukin 1488d7e7a98SRuslan Bukin boolean_t pmap_map_io_transient(vm_page_t *, vm_offset_t *, int, boolean_t); 1498d7e7a98SRuslan Bukin void pmap_unmap_io_transient(vm_page_t *, vm_offset_t *, int, boolean_t); 1508d7e7a98SRuslan Bukin 1518d7e7a98SRuslan Bukin bool pmap_get_tables(pmap_t, vm_offset_t, pd_entry_t **, pd_entry_t **, 1528d7e7a98SRuslan Bukin pt_entry_t **); 1538d7e7a98SRuslan Bukin 1548d7e7a98SRuslan Bukin #define pmap_page_is_mapped(m) (!TAILQ_EMPTY(&(m)->md.pv_list)) 1558d7e7a98SRuslan Bukin 156*b977d819SRuslan Bukin int pmap_fault_fixup(pmap_t, vm_offset_t, vm_prot_t); 157*b977d819SRuslan Bukin 1588d7e7a98SRuslan Bukin #endif /* _KERNEL */ 1598d7e7a98SRuslan Bukin 1608d7e7a98SRuslan Bukin #endif /* !LOCORE */ 1618d7e7a98SRuslan Bukin 1628d7e7a98SRuslan Bukin #endif /* !_MACHINE_PMAP_H_ */ 163