pmap.h revision 161223
1249259Sdim/*- 2249259Sdim * Copyright (c) 1991 Regents of the University of California. 3249259Sdim * All rights reserved. 4249259Sdim * 5249259Sdim * This code is derived from software contributed to Berkeley by 6249259Sdim * the Systems Programming Group of the University of Utah Computer 7249259Sdim * Science Department and William Jolitz of UUNET Technologies Inc. 8249259Sdim * 9249259Sdim * Redistribution and use in source and binary forms, with or without 10249259Sdim * modification, are permitted provided that the following conditions 11249259Sdim * are met: 12249259Sdim * 1. Redistributions of source code must retain the above copyright 13249259Sdim * notice, this list of conditions and the following disclaimer. 14249259Sdim * 2. Redistributions in binary form must reproduce the above copyright 15249259Sdim * notice, this list of conditions and the following disclaimer in the 16249259Sdim * documentation and/or other materials provided with the distribution. 17249259Sdim * 4. Neither the name of the University nor the names of its contributors 18263508Sdim * may be used to endorse or promote products derived from this software 19249259Sdim * without specific prior written permission. 20249259Sdim * 21249259Sdim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22249259Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23249259Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24249259Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25249259Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26249259Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27249259Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28249259Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29249259Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30249259Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31263508Sdim * SUCH DAMAGE. 32249259Sdim * 33249259Sdim * Derived from hp300 version by Mike Hibler, this version by William 34249259Sdim * Jolitz uses a recursive map [a pde points to the page directory] to 35263508Sdim * map the page tables using the pagetables themselves. This is done to 36249259Sdim * reduce the impact on kernel virtual memory for lots of sparse address 37263508Sdim * space, and to reduce the cost of memory to each process. 38249259Sdim * 39249259Sdim * from: hp300: @(#)pmap.h 7.2 (Berkeley) 12/16/90 40263508Sdim * from: @(#)pmap.h 7.4 (Berkeley) 5/12/91 41263508Sdim * from: i386 pmap.h,v 1.54 1997/11/20 19:30:35 bde Exp 42263508Sdim * $FreeBSD: head/sys/ia64/include/pmap.h 161223 2006-08-11 19:22:57Z jhb $ 43249259Sdim */ 44249259Sdim 45263508Sdim#ifndef _MACHINE_PMAP_H_ 46263508Sdim#define _MACHINE_PMAP_H_ 47249259Sdim 48263508Sdim#include <sys/queue.h> 49263508Sdim#include <sys/_lock.h> 50249259Sdim#include <sys/_mutex.h> 51249259Sdim#include <machine/atomic.h> 52263508Sdim#include <machine/pte.h> 53263508Sdim 54263508Sdim#ifdef _KERNEL 55263508Sdim 56263508Sdim#ifndef NKPT 57263508Sdim#define NKPT 30 /* initial number of kernel page tables */ 58249259Sdim#endif 59249259Sdim#define MAXKPT (PAGE_SIZE/sizeof(vm_offset_t)) 60249259Sdim 61249259Sdim#define vtophys(va) pmap_kextract((vm_offset_t)(va)) 62263508Sdim 63263508Sdim#endif /* _KERNEL */ 64249259Sdim 65263508Sdim/* 66263508Sdim * Pmap stuff 67263508Sdim */ 68263508Sdimstruct pv_entry; 69249259Sdim 70263508Sdimstruct md_page { 71263508Sdim int pv_list_count; 72263508Sdim TAILQ_HEAD(,pv_entry) pv_list; 73263508Sdim}; 74263508Sdim 75263508Sdimstruct pmap { 76263508Sdim struct mtx pm_mtx; 77263508Sdim TAILQ_HEAD(,pv_entry) pm_pvlist; /* list of mappings in pmap */ 78263508Sdim u_int32_t pm_rid[5]; /* base RID for pmap */ 79263508Sdim int pm_active; /* active flag */ 80263508Sdim struct pmap_statistics pm_stats; /* pmap statistics */ 81263508Sdim}; 82263508Sdim 83263508Sdimtypedef struct pmap *pmap_t; 84263508Sdim 85263508Sdim#ifdef _KERNEL 86263508Sdimextern struct pmap kernel_pmap_store; 87263508Sdim#define kernel_pmap (&kernel_pmap_store) 88263508Sdim 89263508Sdim#define PMAP_LOCK(pmap) mtx_lock(&(pmap)->pm_mtx) 90263508Sdim#define PMAP_LOCK_ASSERT(pmap, type) \ 91263508Sdim mtx_assert(&(pmap)->pm_mtx, (type)) 92263508Sdim#define PMAP_LOCK_DESTROY(pmap) mtx_destroy(&(pmap)->pm_mtx) 93263508Sdim#define PMAP_LOCK_INIT(pmap) mtx_init(&(pmap)->pm_mtx, "pmap", \ 94263508Sdim NULL, MTX_DEF) 95263508Sdim#define PMAP_LOCKED(pmap) mtx_owned(&(pmap)->pm_mtx) 96263508Sdim#define PMAP_MTX(pmap) (&(pmap)->pm_mtx) 97249259Sdim#define PMAP_TRYLOCK(pmap) mtx_trylock(&(pmap)->pm_mtx) 98249259Sdim#define PMAP_UNLOCK(pmap) mtx_unlock(&(pmap)->pm_mtx) 99263508Sdim#endif 100263508Sdim 101263508Sdim/* 102263508Sdim * For each vm_page_t, there is a list of all currently valid virtual 103249259Sdim * mappings of that page. An entry is a pv_entry_t, the list is pv_table. 104263508Sdim */ 105249259Sdimtypedef struct pv_entry { 106249259Sdim pmap_t pv_pmap; /* pmap where mapping lies */ 107249259Sdim vm_offset_t pv_va; /* virtual address for mapping */ 108249259Sdim TAILQ_ENTRY(pv_entry) pv_list; 109249259Sdim TAILQ_ENTRY(pv_entry) pv_plist; 110249259Sdim} *pv_entry_t; 111249259Sdim 112249259Sdim#ifdef _KERNEL 113249259Sdim 114249259Sdimextern vm_offset_t phys_avail[]; 115249259Sdimextern vm_offset_t virtual_avail; 116249259Sdimextern vm_offset_t virtual_end; 117249259Sdim 118249259Sdimextern uint64_t pmap_vhpt_base[]; 119249259Sdimextern int pmap_vhpt_log2size; 120249259Sdim 121249259Sdim#define pmap_page_is_mapped(m) (!TAILQ_EMPTY(&(m)->md.pv_list)) 122249259Sdim#define pmap_mapbios(pa, sz) pmap_mapdev(pa, sz) 123249259Sdim#define pmap_unmapbios(va, sz) pmap_unmapdev(va, sz) 124249259Sdim 125249259Sdimvm_offset_t pmap_steal_memory(vm_size_t); 126263508Sdimvoid pmap_bootstrap(void); 127249259Sdimvoid pmap_kenter(vm_offset_t va, vm_offset_t pa); 128249259Sdimvm_paddr_t pmap_kextract(vm_offset_t va); 129263508Sdimvoid pmap_kremove(vm_offset_t); 130249259Sdimvoid pmap_setdevram(unsigned long long basea, vm_offset_t sizea); 131249259Sdimint pmap_uses_prom_console(void); 132249259Sdimvoid *pmap_mapdev(vm_offset_t, vm_size_t); 133249259Sdimvoid pmap_unmapdev(vm_offset_t, vm_size_t); 134249259Sdimunsigned *pmap_pte(pmap_t, vm_offset_t) __pure2; 135249259Sdimvoid pmap_set_opt (unsigned *); 136249259Sdimvoid pmap_set_opt_bsp (void); 137249259Sdimstruct pmap *pmap_switch(struct pmap *pmap); 138249259Sdim 139249259Sdim#endif /* _KERNEL */ 140249259Sdim 141249259Sdim#endif /* !_MACHINE_PMAP_H_ */ 142249259Sdim