1 /* $NetBSD: pmap.h,v 1.40 2005/12/11 12:16:36 christos Exp $ */ 2 3 /* 4 * Copyright (c) 1991 Regents of the University of California. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * the Systems Programming Group of the University of Utah Computer 9 * Science Department. 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. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * @(#)pmap.h 7.6 (Berkeley) 5/10/91 36 */ 37 /* 38 * Copyright (c) 1987 Carnegie-Mellon University 39 * 40 * This code is derived from software contributed to Berkeley by 41 * the Systems Programming Group of the University of Utah Computer 42 * Science Department. 43 * 44 * Redistribution and use in source and binary forms, with or without 45 * modification, are permitted provided that the following conditions 46 * are met: 47 * 1. Redistributions of source code must retain the above copyright 48 * notice, this list of conditions and the following disclaimer. 49 * 2. Redistributions in binary form must reproduce the above copyright 50 * notice, this list of conditions and the following disclaimer in the 51 * documentation and/or other materials provided with the distribution. 52 * 3. All advertising materials mentioning features or use of this software 53 * must display the following acknowledgement: 54 * This product includes software developed by the University of 55 * California, Berkeley and its contributors. 56 * 4. Neither the name of the University nor the names of its contributors 57 * may be used to endorse or promote products derived from this software 58 * without specific prior written permission. 59 * 60 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 61 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 62 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 63 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 64 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 65 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 66 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 67 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 68 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 69 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 70 * SUCH DAMAGE. 71 * 72 * @(#)pmap.h 7.6 (Berkeley) 5/10/91 73 */ 74 #ifndef _MACHINE_PMAP_H_ 75 #define _MACHINE_PMAP_H_ 76 77 /* 78 * Pmap stuff 79 */ 80 struct pmap { 81 pt_entry_t *pm_ptab; /* KVA of page table */ 82 st_entry_t *pm_stab; /* KVA of segment table */ 83 int pm_stfree; /* 040: free lev2 blocks */ 84 u_int *pm_stpa; /* 040: ST phys addr */ 85 short pm_sref; /* segment table ref count */ 86 short pm_count; /* pmap reference count */ 87 long pm_ptpages; /* more stats: PT pages */ 88 struct simplelock pm_lock; /* lock on pmap */ 89 struct pmap_statistics pm_stats; /* pmap statistics */ 90 }; 91 92 typedef struct pmap *pmap_t; 93 94 /* 95 * On the 040 we keep track of which level 2 blocks are already in use 96 * with the pm_stfree mask. Bits are arranged from LSB (block 0) to MSB 97 * (block 31). For convenience, the level 1 table is considered to be 98 * block 0. 99 * 100 * MAX[KU]L2SIZE control how many pages of level 2 descriptors are allowed. 101 * for the kernel and users. 16 implies only the initial "segment table" 102 * page is used. WARNING: don't change MAXUL2SIZE unless you can allocate 103 * physically contiguous pages for the ST in pmap.c! 104 */ 105 #define MAXKL2SIZE 32 106 #define MAXUL2SIZE 16 107 #define l2tobm(n) (1 << (n)) 108 #define bmtol2(n) (ffs(n) - 1) 109 110 /* 111 * Macros for speed 112 */ 113 #define PMAP_ACTIVATE(pmap, loadhw) \ 114 { \ 115 if ((loadhw)) \ 116 loadustp(m68k_btop((paddr_t)(pmap)->pm_stpa)); \ 117 } 118 119 /* 120 * For each struct vm_page, there is a list of all currently valid virtual 121 * mappings of that page. An entry is a pv_entry_t, the list is pv_table. 122 */ 123 typedef struct pv_entry { 124 struct pv_entry *pv_next; /* next pv_entry */ 125 struct pmap *pv_pmap; /* pmap where mapping lies */ 126 vaddr_t pv_va; /* virtual address for mapping */ 127 u_int *pv_ptste; /* non-zero if VA maps a PT page */ 128 struct pmap *pv_ptpmap; /* if pv_ptste, pmap for PT page */ 129 int pv_flags; /* flags */ 130 } *pv_entry_t; 131 132 #define PV_CI 0x01 /* all entries must be cache inhibited */ 133 #define PV_PTPAGE 0x02 /* entry maps a page table page */ 134 135 struct pv_page; 136 137 struct pv_page_info { 138 TAILQ_ENTRY(pv_page) pgi_list; 139 struct pv_entry *pgi_freelist; 140 int pgi_nfree; 141 }; 142 143 /* 144 * This is basically: 145 * ((PAGE_SIZE - sizeof(struct pv_page_info)) / sizeof(struct pv_entry)) 146 */ 147 #define NPVPPG 340 148 149 struct pv_page { 150 struct pv_page_info pvp_pgi; 151 struct pv_entry pvp_pv[NPVPPG]; 152 }; 153 154 #ifdef _KERNEL 155 extern u_int *Sysmap; 156 extern caddr_t vmmap; /* map for mem, dumps, etc. */ 157 extern struct pmap kernel_pmap_store; 158 159 #define pmap_kernel() (&kernel_pmap_store) 160 161 #define active_pmap(pm) \ 162 ((pm) == pmap_kernel() || \ 163 (pm) == curproc->p_vmspace->vm_map.pmap) 164 #define active_user_pmap(pm) \ 165 (curproc && \ 166 (pm) != pmap_kernel() && \ 167 (pm) == curproc->p_vmspace->vm_map.pmap) 168 169 #define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count) 170 #define pmap_wired_count(pmap) ((pmap)->pm_stats.wired_count) 171 172 #define pmap_update(pmap) /* nothing (yet) */ 173 174 static __inline void 175 pmap_remove_all(struct pmap *pmap) 176 { 177 /* Nothing. */ 178 } 179 180 vaddr_t pmap_map __P((vaddr_t, paddr_t, paddr_t, int)); 181 void pmap_procwr __P((struct proc *, vaddr_t, u_long)); 182 #define PMAP_NEED_PROCWR 183 184 #endif /* _KERNEL */ 185 186 #endif /* !_MACHINE_PMAP_H_ */ 187