1 /* $NetBSD: pmap.h,v 1.41 2002/11/30 01:52:32 simonb Exp $ */ 2 3 /* 4 * Copyright (c) 1987 Carnegie-Mellon University 5 * Copyright (c) 1992, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * Ralph Campbell. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by the University of 22 * California, Berkeley and its contributors. 23 * 4. Neither the name of the University nor the names of its contributors 24 * may be used to endorse or promote products derived from this software 25 * without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * 39 * @(#)pmap.h 8.1 (Berkeley) 6/10/93 40 */ 41 42 #ifndef _MIPS_PMAP_H_ 43 #define _MIPS_PMAP_H_ 44 45 #include <mips/cpuregs.h> /* for KSEG0 below */ 46 47 /* 48 * The user address space is 2Gb (0x0 - 0x80000000). 49 * User programs are laid out in memory as follows: 50 * address 51 * USRTEXT 0x00001000 52 * USRDATA USRTEXT + text_size 53 * USRSTACK 0x7FFFFFFF 54 * 55 * The user address space is mapped using a two level structure where 56 * virtual address bits 30..22 are used to index into a segment table which 57 * points to a page worth of PTEs (4096 page can hold 1024 PTEs). 58 * Bits 21..12 are then used to index a PTE which describes a page within 59 * a segment. 60 * 61 * The wired entries in the TLB will contain the following: 62 * 0-1 (UPAGES) for curproc user struct and kernel stack. 63 * 64 * Note: The kernel doesn't use the same data structures as user programs. 65 * All the PTE entries are stored in a single array in Sysmap which is 66 * dynamically allocated at boot time. 67 */ 68 69 #define mips_trunc_seg(x) ((vaddr_t)(x) & ~SEGOFSET) 70 #define mips_round_seg(x) (((vaddr_t)(x) + SEGOFSET) & ~SEGOFSET) 71 #define pmap_segmap(m, v) ((m)->pm_segtab->seg_tab[((v) >> SEGSHIFT)]) 72 73 #define PMAP_SEGTABSIZE 512 74 75 union pt_entry; 76 77 struct segtab { 78 union pt_entry *seg_tab[PMAP_SEGTABSIZE]; 79 }; 80 81 /* 82 * Machine dependent pmap structure. 83 */ 84 typedef struct pmap { 85 int pm_count; /* pmap reference count */ 86 struct simplelock pm_lock; /* lock on pmap */ 87 struct pmap_statistics pm_stats; /* pmap statistics */ 88 unsigned pm_asid; /* TLB address space tag */ 89 unsigned pm_asidgen; /* its generation number */ 90 struct segtab *pm_segtab; /* pointers to pages of PTEs */ 91 } *pmap_t; 92 93 /* 94 * For each struct vm_page, there is a list of all currently valid virtual 95 * mappings of that page. An entry is a pv_entry_t, the list is pv_table. 96 * XXX really should do this as a part of the higher level code. 97 */ 98 typedef struct pv_entry { 99 struct pv_entry *pv_next; /* next pv_entry */ 100 struct pmap *pv_pmap; /* pmap where mapping lies */ 101 vaddr_t pv_va; /* virtual address for mapping */ 102 int pv_flags; /* some flags for the mapping */ 103 } *pv_entry_t; 104 105 #define PV_UNCACHED 0x0001 /* page is mapped uncached */ 106 #define PV_MODIFIED 0x0002 /* page has been modified */ 107 #define PV_REFERENCED 0x0004 /* page has been recently referenced */ 108 109 110 #ifdef _KERNEL 111 112 extern char *pmap_attributes; /* reference and modify bits */ 113 extern struct pmap kernel_pmap_store; 114 115 #define pmap_kernel() (&kernel_pmap_store) 116 #define pmap_wired_count(pmap) ((pmap)->pm_stats.wired_count) 117 #define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count) 118 119 #define pmap_update(pmap) /* nothing (yet) */ 120 121 static __inline void 122 pmap_remove_all(struct pmap *pmap) 123 { 124 /* Nothing. */ 125 } 126 127 /* 128 * Bootstrap the system enough to run with virtual memory. 129 */ 130 void pmap_bootstrap(void); 131 132 void pmap_set_modified(paddr_t); 133 134 void pmap_procwr(struct proc *, vaddr_t, size_t); 135 #define PMAP_NEED_PROCWR 136 137 /* 138 * pmap_prefer() helps reduce virtual-coherency exceptions in 139 * the virtually-indexed cache on mips3 CPUs. 140 */ 141 #ifdef MIPS3_PLUS 142 #define PMAP_PREFER(pa, va) pmap_prefer((pa), (va)) 143 void pmap_prefer(vaddr_t, vaddr_t *); 144 #endif /* MIPS3_PLUS */ 145 146 #define PMAP_STEAL_MEMORY /* enable pmap_steal_memory() */ 147 148 /* 149 * Alternate mapping hooks for pool pages. Avoids thrashing the TLB. 150 */ 151 #define PMAP_MAP_POOLPAGE(pa) MIPS_PHYS_TO_KSEG0((pa)) 152 #define PMAP_UNMAP_POOLPAGE(va) MIPS_KSEG0_TO_PHYS((va)) 153 154 /* 155 * Select CCA to use for unmanaged pages. 156 */ 157 #define PMAP_CCA_FOR_PA(pa) 2 /* uncached */ 158 159 #endif /* _KERNEL */ 160 #endif /* _MIPS_PMAP_H_ */ 161