pmap.h revision 139825
1164633Ssam/*- 2164633Ssam * Copyright (c) 1991 Regents of the University of California. 3164633Ssam * All rights reserved. 4164633Ssam * 5164633Ssam * This code is derived from software contributed to Berkeley by 6164633Ssam * the Systems Programming Group of the University of Utah Computer 7164633Ssam * Science Department and William Jolitz of UUNET Technologies Inc. 8164633Ssam * 9164633Ssam * Redistribution and use in source and binary forms, with or without 10164633Ssam * modification, are permitted provided that the following conditions 11164633Ssam * are met: 12164633Ssam * 1. Redistributions of source code must retain the above copyright 13164633Ssam * notice, this list of conditions and the following disclaimer. 14164633Ssam * 2. Redistributions in binary form must reproduce the above copyright 15164633Ssam * notice, this list of conditions and the following disclaimer in the 16164633Ssam * documentation and/or other materials provided with the distribution. 17164633Ssam * 4. Neither the name of the University nor the names of its contributors 18164633Ssam * may be used to endorse or promote products derived from this software 19164633Ssam * without specific prior written permission. 20164633Ssam * 21164633Ssam * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22164633Ssam * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23164633Ssam * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24164633Ssam * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25164633Ssam * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26164633Ssam * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27164633Ssam * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28164633Ssam * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29164633Ssam * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30164633Ssam * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31164633Ssam * SUCH DAMAGE. 32164633Ssam * 33164633Ssam * from: hp300: @(#)pmap.h 7.2 (Berkeley) 12/16/90 34164633Ssam * from: @(#)pmap.h 7.4 (Berkeley) 5/12/91 35178354Ssam * from: FreeBSD: src/sys/i386/include/pmap.h,v 1.70 2000/11/30 36164633Ssam * $FreeBSD: head/sys/sparc64/include/pmap.h 139825 2005-01-07 02:29:27Z imp $ 37164633Ssam */ 38164633Ssam 39164633Ssam#ifndef _MACHINE_PMAP_H_ 40178354Ssam#define _MACHINE_PMAP_H_ 41164633Ssam 42164633Ssam#include <sys/queue.h> 43164633Ssam#include <sys/_lock.h> 44164633Ssam#include <sys/_mutex.h> 45164633Ssam#include <machine/cache.h> 46164633Ssam#include <machine/tte.h> 47164633Ssam 48164633Ssam#define PMAP_CONTEXT_MAX 8192 49164633Ssam 50178354Ssamtypedef struct pmap *pmap_t; 51178354Ssam 52178354Ssamstruct md_page { 53178354Ssam TAILQ_HEAD(, tte) tte_list; 54178354Ssam struct pmap *pmap; 55164633Ssam uint32_t colors[DCACHE_COLORS]; 56178354Ssam int32_t color; 57164633Ssam uint32_t flags; 58164633Ssam}; 59164633Ssam 60164633Ssamstruct pmap { 61164633Ssam struct mtx pm_mtx; 62 struct tte *pm_tsb; 63 vm_object_t pm_tsb_obj; 64 u_int pm_active; 65 u_int pm_context[MAXCPU]; 66 struct pmap_statistics pm_stats; 67}; 68 69#define PMAP_LOCK(pmap) mtx_lock(&(pmap)->pm_mtx) 70#define PMAP_LOCK_ASSERT(pmap, type) \ 71 mtx_assert(&(pmap)->pm_mtx, (type)) 72#define PMAP_LOCK_DESTROY(pmap) mtx_destroy(&(pmap)->pm_mtx) 73#define PMAP_LOCK_INIT(pmap) mtx_init(&(pmap)->pm_mtx, "pmap", \ 74 NULL, MTX_DEF) 75#define PMAP_LOCKED(pmap) mtx_owned(&(pmap)->pm_mtx) 76#define PMAP_MTX(pmap) (&(pmap)->pm_mtx) 77#define PMAP_TRYLOCK(pmap) mtx_trylock(&(pmap)->pm_mtx) 78#define PMAP_UNLOCK(pmap) mtx_unlock(&(pmap)->pm_mtx) 79 80void pmap_bootstrap(vm_offset_t ekva); 81vm_paddr_t pmap_kextract(vm_offset_t va); 82void pmap_kenter(vm_offset_t va, vm_page_t m); 83void pmap_kremove(vm_offset_t); 84void pmap_kenter_flags(vm_offset_t va, vm_paddr_t pa, u_long flags); 85void pmap_kremove_flags(vm_offset_t va); 86boolean_t pmap_page_is_mapped(vm_page_t m); 87 88int pmap_cache_enter(vm_page_t m, vm_offset_t va); 89void pmap_cache_remove(vm_page_t m, vm_offset_t va); 90 91int pmap_remove_tte(struct pmap *pm1, struct pmap *pm2, struct tte *tp, 92 vm_offset_t va); 93int pmap_protect_tte(struct pmap *pm1, struct pmap *pm2, struct tte *tp, 94 vm_offset_t va); 95 96void pmap_map_tsb(void); 97 98void pmap_clear_write(vm_page_t m); 99 100#define vtophys(va) pmap_kextract(((vm_offset_t)(va))) 101 102extern struct pmap kernel_pmap_store; 103#define kernel_pmap (&kernel_pmap_store) 104extern vm_paddr_t phys_avail[]; 105extern vm_offset_t virtual_avail; 106extern vm_offset_t virtual_end; 107 108extern vm_paddr_t msgbuf_phys; 109 110static __inline int 111pmap_track_modified(pmap_t pm, vm_offset_t va) 112{ 113 if (pm == kernel_pmap) 114 return ((va < kmi.clean_sva) || (va >= kmi.clean_eva)); 115 else 116 return (1); 117} 118 119#ifdef PMAP_STATS 120 121SYSCTL_DECL(_debug_pmap_stats); 122 123#define PMAP_STATS_VAR(name) \ 124 static long name; \ 125 SYSCTL_LONG(_debug_pmap_stats, OID_AUTO, name, CTLFLAG_RW, \ 126 &name, 0, "") 127 128#define PMAP_STATS_INC(var) \ 129 atomic_add_long(&var, 1) 130 131#else 132 133#define PMAP_STATS_VAR(name) 134#define PMAP_STATS_INC(var) 135 136#endif 137 138#endif /* !_MACHINE_PMAP_H_ */ 139