pmap.h revision 202031
1187301Sgonzo/*- 2178172Simp * Copyright (c) 1991 Regents of the University of California. 3178172Simp * All rights reserved. 4178172Simp * 5178172Simp * This code is derived from software contributed to Berkeley by 6178172Simp * the Systems Programming Group of the University of Utah Computer 7178172Simp * Science Department and William Jolitz of UUNET Technologies Inc. 8178172Simp * 9178172Simp * Redistribution and use in source and binary forms, with or without 10178172Simp * modification, are permitted provided that the following conditions 11178172Simp * are met: 12178172Simp * 1. Redistributions of source code must retain the above copyright 13178172Simp * notice, this list of conditions and the following disclaimer. 14178172Simp * 2. Redistributions in binary form must reproduce the above copyright 15178172Simp * notice, this list of conditions and the following disclaimer in the 16178172Simp * documentation and/or other materials provided with the distribution. 17178172Simp * 4. Neither the name of the University nor the names of its contributors 18178172Simp * may be used to endorse or promote products derived from this software 19178172Simp * without specific prior written permission. 20178172Simp * 21178172Simp * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22178172Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23178172Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24178172Simp * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25178172Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26178172Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27178172Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28178172Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29178172Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30178172Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31178172Simp * SUCH DAMAGE. 32178172Simp * 33178172Simp * Derived from hp300 version by Mike Hibler, this version by William 34178172Simp * Jolitz uses a recursive map [a pde points to the page directory] to 35178172Simp * map the page tables using the pagetables themselves. This is done to 36178172Simp * reduce the impact on kernel virtual memory for lots of sparse address 37178172Simp * space, and to reduce the cost of memory to each process. 38178172Simp * 39178172Simp * from: hp300: @(#)pmap.h 7.2 (Berkeley) 12/16/90 40178172Simp * from: @(#)pmap.h 7.4 (Berkeley) 5/12/91 41178172Simp * from: src/sys/i386/include/pmap.h,v 1.65.2.2 2000/11/30 01:54:42 peter 42178172Simp * JNPR: pmap.h,v 1.7.2.1 2007/09/10 07:44:12 girish 43178172Simp * $FreeBSD: head/sys/mips/include/pmap.h 202031 2010-01-10 19:50:24Z imp $ 44178172Simp */ 45178172Simp 46178172Simp#ifndef _MACHINE_PMAP_H_ 47178172Simp#define _MACHINE_PMAP_H_ 48178172Simp 49178172Simp#include <machine/vmparam.h> 50187301Sgonzo#include <machine/pte.h> 51178172Simp 52178172Simp#define VADDR(pdi, pti) ((vm_offset_t)(((pdi)<<PDRSHIFT)|((pti)<<PAGE_SHIFT))) 53178172Simp 54178172Simp#define NKPT 120 /* actual number of kernel page tables */ 55178172Simp 56178172Simp#ifndef NKPDE 57178172Simp#define NKPDE 255 /* addressable number of page tables/pde's */ 58178172Simp#endif 59178172Simp 60178172Simp#define KPTDI (VM_MIN_KERNEL_ADDRESS >> SEGSHIFT) 61178172Simp#define NUSERPGTBLS (VM_MAXUSER_ADDRESS >> SEGSHIFT) 62178172Simp 63178172Simp#ifndef LOCORE 64178172Simp 65178172Simp#include <sys/queue.h> 66178172Simp#include <sys/_lock.h> 67178172Simp#include <sys/_mutex.h> 68178172Simp 69178172Simp/* 70178172Simp * Pmap stuff 71178172Simp */ 72178172Simpstruct pv_entry; 73178172Simp 74178172Simpstruct md_page { 75178172Simp int pv_list_count; 76178172Simp int pv_flags; 77191735Salc TAILQ_HEAD(, pv_entry) pv_list; 78178172Simp}; 79178172Simp 80178172Simp#define PV_TABLE_MOD 0x01 /* modified */ 81178172Simp#define PV_TABLE_REF 0x02 /* referenced */ 82178172Simp 83178172Simp#define ASID_BITS 8 84178172Simp#define ASIDGEN_BITS (32 - ASID_BITS) 85178172Simp#define ASIDGEN_MASK ((1 << ASIDGEN_BITS) - 1) 86178172Simp 87178172Simpstruct pmap { 88178172Simp pd_entry_t *pm_segtab; /* KVA of segment table */ 89191735Salc TAILQ_HEAD(, pv_entry) pm_pvlist; /* list of mappings in 90191735Salc * pmap */ 91178172Simp int pm_active; /* active on cpus */ 92178172Simp struct { 93178172Simp u_int32_t asid:ASID_BITS; /* TLB address space tag */ 94178172Simp u_int32_t gen:ASIDGEN_BITS; /* its generation number */ 95178172Simp } pm_asid[MAXSMPCPU]; 96178172Simp struct pmap_statistics pm_stats; /* pmap statistics */ 97178172Simp struct vm_page *pm_ptphint; /* pmap ptp hint */ 98178172Simp struct mtx pm_mtx; 99178172Simp}; 100178172Simp 101178172Simptypedef struct pmap *pmap_t; 102178172Simp 103187301Sgonzo#ifdef _KERNEL 104178172Simp 105178172Simppt_entry_t *pmap_pte(pmap_t, vm_offset_t); 106178172Simppd_entry_t pmap_segmap(pmap_t pmap, vm_offset_t va); 107178172Simpvm_offset_t pmap_kextract(vm_offset_t va); 108178172Simp 109178172Simp#define vtophys(va) pmap_kextract(((vm_offset_t) (va))) 110178172Simp 111191735Salcextern struct pmap kernel_pmap_store; 112191735Salc#define kernel_pmap (&kernel_pmap_store) 113191735Salc 114178172Simp#define PMAP_LOCK(pmap) mtx_lock(&(pmap)->pm_mtx) 115178172Simp#define PMAP_LOCK_ASSERT(pmap, type) mtx_assert(&(pmap)->pm_mtx, (type)) 116178172Simp#define PMAP_LOCK_DESTROY(pmap) mtx_destroy(&(pmap)->pm_mtx) 117178172Simp#define PMAP_LOCK_INIT(pmap) mtx_init(&(pmap)->pm_mtx, "pmap", \ 118178172Simp NULL, MTX_DEF) 119178172Simp#define PMAP_LOCKED(pmap) mtx_owned(&(pmap)->pm_mtx) 120178172Simp#define PMAP_MTX(pmap) (&(pmap)->pm_mtx) 121178172Simp#define PMAP_TRYLOCK(pmap) mtx_trylock(&(pmap)->pm_mtx) 122178172Simp#define PMAP_UNLOCK(pmap) mtx_unlock(&(pmap)->pm_mtx) 123178172Simp 124178172Simp#define PMAP_LGMEM_LOCK_INIT(sysmap) mtx_init(&(sysmap)->lock, "pmap-lgmem", \ 125178172Simp "per-cpu-map", (MTX_DEF| MTX_DUPOK)) 126178172Simp#define PMAP_LGMEM_LOCK(sysmap) mtx_lock(&(sysmap)->lock) 127178172Simp#define PMAP_LGMEM_UNLOCK(sysmap) mtx_unlock(&(sysmap)->lock) 128178172Simp#define PMAP_LGMEM_DESTROY(sysmap) mtx_destroy(&(sysmap)->lock) 129178172Simp 130178172Simp/* 131178172Simp * For each vm_page_t, there is a list of all currently valid virtual 132178172Simp * mappings of that page. An entry is a pv_entry_t, the list is pv_table. 133178172Simp */ 134178172Simptypedef struct pv_entry { 135178172Simp pmap_t pv_pmap; /* pmap where mapping lies */ 136178172Simp vm_offset_t pv_va; /* virtual address for mapping */ 137191735Salc TAILQ_ENTRY(pv_entry) pv_list; 138191735Salc TAILQ_ENTRY(pv_entry) pv_plist; 139178172Simp vm_page_t pv_ptem; /* VM page for pte */ 140178172Simp boolean_t pv_wired; /* whether this entry is wired */ 141178172Simp} *pv_entry_t; 142178172Simp 143178172Simp 144178172Simp#if defined(DIAGNOSTIC) 145178172Simp#define PMAP_DIAGNOSTIC 146178172Simp#endif 147178172Simp 148202031Simp/* 149202031Simp * physmem_desc[] is a superset of phys_avail[] and describes all the 150202031Simp * memory present in the system. 151202031Simp * 152202031Simp * phys_avail[] is similar but does not include the memory stolen by 153202031Simp * pmap_steal_memory(). 154202031Simp * 155202031Simp * Each memory region is described by a pair of elements in the array 156202031Simp * so we can describe up to (PHYS_AVAIL_ENTRIES / 2) distinct memory 157202031Simp * regions. 158202031Simp */ 159202031Simp#define PHYS_AVAIL_ENTRIES 10 160202031Simpextern vm_offset_t phys_avail[PHYS_AVAIL_ENTRIES + 2]; 161202031Simpextern vm_offset_t physmem_desc[PHYS_AVAIL_ENTRIES + 2]; 162202031Simp 163178172Simpextern char *ptvmmap; /* poor name! */ 164178172Simpextern vm_offset_t virtual_avail; 165178172Simpextern vm_offset_t virtual_end; 166178172Simpextern pd_entry_t *segbase; 167178172Simp 168178172Simpextern vm_paddr_t mips_wired_tlb_physmem_start; 169178172Simpextern vm_paddr_t mips_wired_tlb_physmem_end; 170178172Simpextern u_int need_wired_tlb_page_pool; 171178172Simp 172195649Salc#define pmap_page_get_memattr(m) VM_MEMATTR_DEFAULT 173178172Simp#define pmap_page_is_mapped(m) (!TAILQ_EMPTY(&(m)->md.pv_list)) 174195649Salc#define pmap_page_set_memattr(m, ma) (void)0 175178172Simp 176178172Simpvoid pmap_bootstrap(void); 177178172Simpvoid *pmap_mapdev(vm_offset_t, vm_size_t); 178178172Simpvoid pmap_unmapdev(vm_offset_t, vm_size_t); 179178172Simpvm_offset_t pmap_steal_memory(vm_size_t size); 180178172Simpvoid pmap_set_modified(vm_offset_t pa); 181178172Simpint page_is_managed(vm_offset_t pa); 182178172Simpvoid pmap_page_is_free(vm_page_t m); 183187327Simpvoid pmap_kenter(vm_offset_t va, vm_paddr_t pa); 184187327Simpvoid pmap_kremove(vm_offset_t va); 185178172Simpvoid *pmap_kenter_temporary(vm_paddr_t pa, int i); 186178172Simpvoid pmap_kenter_temporary_free(vm_paddr_t pa); 187178172Simpint pmap_compute_pages_to_dump(void); 188178172Simpvoid pmap_update_page(pmap_t pmap, vm_offset_t va, pt_entry_t pte); 189202031Simpvoid pmap_flush_pvcache(vm_page_t m); 190178172Simp 191178172Simp/* 192178172Simp * floating virtual pages (FPAGES) 193178172Simp * 194178172Simp * These are the reserved virtual memory areas which can be 195178172Simp * mapped to any physical memory. 196178172Simp */ 197178172Simp#define FPAGES 2 198178172Simp#define FPAGES_SHARED 2 199178172Simp#define FSPACE ((FPAGES * MAXCPU + FPAGES_SHARED) * PAGE_SIZE) 200178172Simp#define PMAP_FPAGE1 0x00 /* Used by pmap_zero_page & 201178172Simp * pmap_copy_page */ 202178172Simp#define PMAP_FPAGE2 0x01 /* Used by pmap_copy_page */ 203178172Simp 204178172Simp#define PMAP_FPAGE3 0x00 /* Used by pmap_zero_page_idle */ 205178172Simp#define PMAP_FPAGE_KENTER_TEMP 0x01 /* Used by coredump */ 206178172Simp 207178172Simpstruct fpage { 208178172Simp vm_offset_t kva; 209178172Simp u_int state; 210178172Simp}; 211178172Simp 212178172Simpstruct sysmaps { 213178172Simp struct mtx lock; 214178172Simp struct fpage fp[FPAGES]; 215178172Simp}; 216178172Simp 217178172Simpvm_offset_t 218178172Simppmap_map_fpage(vm_paddr_t pa, struct fpage *fp, 219178172Simp boolean_t check_unmaped); 220178172Simpvoid pmap_unmap_fpage(vm_paddr_t pa, struct fpage *fp); 221178172Simp 222178172Simp#endif /* _KERNEL */ 223178172Simp 224178172Simp#endif /* !LOCORE */ 225178172Simp 226178172Simp#endif /* !_MACHINE_PMAP_H_ */ 227