1412042e2SAndrew Turner /*- 2412042e2SAndrew Turner * Copyright (c) 1991 Regents of the University of California. 3412042e2SAndrew Turner * All rights reserved. 4412042e2SAndrew Turner * 5412042e2SAndrew Turner * This code is derived from software contributed to Berkeley by 6412042e2SAndrew Turner * the Systems Programming Group of the University of Utah Computer 7412042e2SAndrew Turner * Science Department and William Jolitz of UUNET Technologies Inc. 8412042e2SAndrew Turner * 9412042e2SAndrew Turner * Redistribution and use in source and binary forms, with or without 10412042e2SAndrew Turner * modification, are permitted provided that the following conditions 11412042e2SAndrew Turner * are met: 12412042e2SAndrew Turner * 1. Redistributions of source code must retain the above copyright 13412042e2SAndrew Turner * notice, this list of conditions and the following disclaimer. 14412042e2SAndrew Turner * 2. Redistributions in binary form must reproduce the above copyright 15412042e2SAndrew Turner * notice, this list of conditions and the following disclaimer in the 16412042e2SAndrew Turner * documentation and/or other materials provided with the distribution. 17*f72c920cSEd Maste * 3. Neither the name of the University nor the names of its contributors 18412042e2SAndrew Turner * may be used to endorse or promote products derived from this software 19412042e2SAndrew Turner * without specific prior written permission. 20412042e2SAndrew Turner * 21412042e2SAndrew Turner * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22412042e2SAndrew Turner * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23412042e2SAndrew Turner * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24412042e2SAndrew Turner * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25412042e2SAndrew Turner * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26412042e2SAndrew Turner * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27412042e2SAndrew Turner * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28412042e2SAndrew Turner * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29412042e2SAndrew Turner * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30412042e2SAndrew Turner * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31412042e2SAndrew Turner * SUCH DAMAGE. 32412042e2SAndrew Turner * 33412042e2SAndrew Turner * $FreeBSD$ 34412042e2SAndrew Turner */ 35412042e2SAndrew Turner 36412042e2SAndrew Turner #ifndef _MACHINE_PMAP_H_ 37412042e2SAndrew Turner #define _MACHINE_PMAP_H_ 38412042e2SAndrew Turner 39412042e2SAndrew Turner #include <machine/pte.h> 40412042e2SAndrew Turner 41412042e2SAndrew Turner #ifndef LOCORE 42412042e2SAndrew Turner 43412042e2SAndrew Turner #include <sys/queue.h> 44412042e2SAndrew Turner #include <sys/_lock.h> 45412042e2SAndrew Turner #include <sys/_mutex.h> 46412042e2SAndrew Turner 47412042e2SAndrew Turner #ifdef _KERNEL 48412042e2SAndrew Turner 49412042e2SAndrew Turner #define vtophys(va) pmap_kextract((vm_offset_t)(va)) 50412042e2SAndrew Turner 51412042e2SAndrew Turner #endif 52412042e2SAndrew Turner 53412042e2SAndrew Turner #define pmap_page_get_memattr(m) ((m)->md.pv_memattr) 54412042e2SAndrew Turner #define pmap_page_is_write_mapped(m) (((m)->aflags & PGA_WRITEABLE) != 0) 55412042e2SAndrew Turner void pmap_page_set_memattr(vm_page_t m, vm_memattr_t ma); 56412042e2SAndrew Turner 57412042e2SAndrew Turner /* 58412042e2SAndrew Turner * Pmap stuff 59412042e2SAndrew Turner */ 60412042e2SAndrew Turner 61412042e2SAndrew Turner struct md_page { 62412042e2SAndrew Turner TAILQ_HEAD(,pv_entry) pv_list; 63412042e2SAndrew Turner int pv_gen; 64412042e2SAndrew Turner vm_memattr_t pv_memattr; 65412042e2SAndrew Turner }; 66412042e2SAndrew Turner 67412042e2SAndrew Turner /* 68412042e2SAndrew Turner * This structure is used to hold a virtual<->physical address 69412042e2SAndrew Turner * association and is used mostly by bootstrap code 70412042e2SAndrew Turner */ 71412042e2SAndrew Turner struct pv_addr { 72412042e2SAndrew Turner SLIST_ENTRY(pv_addr) pv_list; 73412042e2SAndrew Turner vm_offset_t pv_va; 74412042e2SAndrew Turner vm_paddr_t pv_pa; 75412042e2SAndrew Turner }; 76412042e2SAndrew Turner 77412042e2SAndrew Turner 78412042e2SAndrew Turner struct pmap { 79412042e2SAndrew Turner struct mtx pm_mtx; 80412042e2SAndrew Turner struct pmap_statistics pm_stats; /* pmap statictics */ 81412042e2SAndrew Turner pd_entry_t *pm_l1; 82412042e2SAndrew Turner TAILQ_HEAD(,pv_chunk) pm_pvchunk; /* list of mappings in pmap */ 83412042e2SAndrew Turner }; 84412042e2SAndrew Turner 85412042e2SAndrew Turner typedef struct pv_entry { 86412042e2SAndrew Turner vm_offset_t pv_va; /* virtual address for mapping */ 87412042e2SAndrew Turner TAILQ_ENTRY(pv_entry) pv_next; 88412042e2SAndrew Turner } *pv_entry_t; 89412042e2SAndrew Turner 90412042e2SAndrew Turner /* 91412042e2SAndrew Turner * pv_entries are allocated in chunks per-process. This avoids the 92412042e2SAndrew Turner * need to track per-pmap assignments. 93412042e2SAndrew Turner */ 94412042e2SAndrew Turner #define _NPCM 3 95412042e2SAndrew Turner #define _NPCPV 168 96412042e2SAndrew Turner struct pv_chunk { 97412042e2SAndrew Turner struct pmap * pc_pmap; 98412042e2SAndrew Turner TAILQ_ENTRY(pv_chunk) pc_list; 99412042e2SAndrew Turner uint64_t pc_map[_NPCM]; /* bitmap; 1 = free */ 100412042e2SAndrew Turner TAILQ_ENTRY(pv_chunk) pc_lru; 101412042e2SAndrew Turner struct pv_entry pc_pventry[_NPCPV]; 102412042e2SAndrew Turner }; 103412042e2SAndrew Turner 104412042e2SAndrew Turner typedef struct pmap *pmap_t; 105412042e2SAndrew Turner 106412042e2SAndrew Turner #ifdef _KERNEL 107412042e2SAndrew Turner extern struct pmap kernel_pmap_store; 108412042e2SAndrew Turner #define kernel_pmap (&kernel_pmap_store) 109412042e2SAndrew Turner #define pmap_kernel() kernel_pmap 110412042e2SAndrew Turner 111412042e2SAndrew Turner #define PMAP_ASSERT_LOCKED(pmap) \ 112412042e2SAndrew Turner mtx_assert(&(pmap)->pm_mtx, MA_OWNED) 113412042e2SAndrew Turner #define PMAP_LOCK(pmap) mtx_lock(&(pmap)->pm_mtx) 114412042e2SAndrew Turner #define PMAP_LOCK_ASSERT(pmap, type) \ 115412042e2SAndrew Turner mtx_assert(&(pmap)->pm_mtx, (type)) 116412042e2SAndrew Turner #define PMAP_LOCK_DESTROY(pmap) mtx_destroy(&(pmap)->pm_mtx) 117412042e2SAndrew Turner #define PMAP_LOCK_INIT(pmap) mtx_init(&(pmap)->pm_mtx, "pmap", \ 118412042e2SAndrew Turner NULL, MTX_DEF | MTX_DUPOK) 119412042e2SAndrew Turner #define PMAP_OWNED(pmap) mtx_owned(&(pmap)->pm_mtx) 120412042e2SAndrew Turner #define PMAP_MTX(pmap) (&(pmap)->pm_mtx) 121412042e2SAndrew Turner #define PMAP_TRYLOCK(pmap) mtx_trylock(&(pmap)->pm_mtx) 122412042e2SAndrew Turner #define PMAP_UNLOCK(pmap) mtx_unlock(&(pmap)->pm_mtx) 123412042e2SAndrew Turner 124412042e2SAndrew Turner #define PHYS_AVAIL_SIZE 10 125412042e2SAndrew Turner extern vm_paddr_t phys_avail[]; 126412042e2SAndrew Turner extern vm_paddr_t dump_avail[]; 127412042e2SAndrew Turner extern vm_offset_t virtual_avail; 128412042e2SAndrew Turner extern vm_offset_t virtual_end; 129412042e2SAndrew Turner 130412042e2SAndrew Turner /* 131412042e2SAndrew Turner * Macros to test if a mapping is mappable with an L1 Section mapping 132412042e2SAndrew Turner * or an L2 Large Page mapping. 133412042e2SAndrew Turner */ 134412042e2SAndrew Turner #define L1_MAPPABLE_P(va, pa, size) \ 135412042e2SAndrew Turner ((((va) | (pa)) & L1_OFFSET) == 0 && (size) >= L1_SIZE) 136412042e2SAndrew Turner 137412042e2SAndrew Turner void pmap_bootstrap(vm_offset_t, vm_paddr_t, vm_size_t); 138412042e2SAndrew Turner void pmap_kenter(vm_offset_t, vm_paddr_t); 139412042e2SAndrew Turner void pmap_kenter_device(vm_offset_t, vm_paddr_t); 140412042e2SAndrew Turner vm_paddr_t pmap_kextract(vm_offset_t va); 141412042e2SAndrew Turner void pmap_kremove(vm_offset_t); 142412042e2SAndrew Turner 143412042e2SAndrew Turner void *pmap_mapdev(vm_offset_t, vm_size_t); 144412042e2SAndrew Turner void pmap_unmapdev(vm_offset_t, vm_size_t); 145412042e2SAndrew Turner 146412042e2SAndrew Turner boolean_t pmap_map_io_transient(vm_page_t *, vm_offset_t *, int, boolean_t); 147412042e2SAndrew Turner void pmap_unmap_io_transient(vm_page_t *, vm_offset_t *, int, boolean_t); 148412042e2SAndrew Turner 149412042e2SAndrew Turner #define pmap_page_is_mapped(m) (!TAILQ_EMPTY(&(m)->md.pv_list)) 150412042e2SAndrew Turner 151412042e2SAndrew Turner #endif /* _KERNEL */ 152412042e2SAndrew Turner 153412042e2SAndrew Turner #endif /* !LOCORE */ 154412042e2SAndrew Turner 155412042e2SAndrew Turner #endif /* !_MACHINE_PMAP_H_ */ 156