1 /* 2 * Copyright (c) 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This software was developed by the Computer Systems Engineering group 6 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 7 * contributed to Berkeley. 8 * 9 * All advertising materials mentioning features or use of this software 10 * must display the following acknowledgement: 11 * This product includes software developed by the University of 12 * California, Lawrence Berkeley Laboratory. 13 * 14 * Redistribution and use in source and binary forms, with or without 15 * modification, are permitted provided that the following conditions 16 * are met: 17 * 1. Redistributions of source code must retain the above copyright 18 * notice, this list of conditions and the following disclaimer. 19 * 2. Redistributions in binary form must reproduce the above copyright 20 * notice, this list of conditions and the following disclaimer in the 21 * documentation and/or other materials provided with the distribution. 22 * 3. All advertising materials mentioning features or use of this software 23 * must display the following acknowledgement: 24 * This product includes software developed by the University of 25 * California, Berkeley and its contributors. 26 * 4. Neither the name of the University nor the names of its contributors 27 * may be used to endorse or promote products derived from this software 28 * without specific prior written permission. 29 * 30 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 31 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 33 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 40 * SUCH DAMAGE. 41 * 42 * @(#)pmap.h 8.1 (Berkeley) 6/11/93 43 * 44 * from: Header: pmap.h,v 1.11 93/05/25 10:36:09 torek Exp 45 * $Id: pmap.h,v 1.2 1993/10/11 02:28:28 deraadt Exp $ 46 */ 47 48 #ifndef _SPARC_PMAP_H_ 49 #define _SPARC_PMAP_H_ 50 51 #include <machine/pte.h> 52 53 /* 54 * Pmap structure. 55 * 56 * The pmap structure really comes in two variants, one---a single 57 * instance---for kernel virtual memory and the other---up to nproc 58 * instances---for user virtual memory. Unfortunately, we have to mash 59 * both into the same structure. Fortunately, they are almost the same. 60 * 61 * The kernel begins at 0xf8000000 and runs to 0xffffffff (although 62 * some of this is not actually used). Kernel space, including DVMA 63 * space (for now?), is mapped identically into all user contexts. 64 * There is no point in duplicating this mapping in each user process 65 * so they do not appear in the user structures. 66 * 67 * User space begins at 0x00000000 and runs through 0x1fffffff, 68 * then has a `hole', then resumes at 0xe0000000 and runs until it 69 * hits the kernel space at 0xf8000000. This can be mapped 70 * contiguously by ignorning the top two bits and pretending the 71 * space goes from 0 to 37ffffff. Typically the lower range is 72 * used for text+data and the upper for stack, but the code here 73 * makes no such distinction. 74 * 75 * Since each virtual segment covers 256 kbytes, the user space 76 * requires 3584 segments, while the kernel (including DVMA) requires 77 * only 512 segments. 78 * 79 * The segment map entry for virtual segment vseg is offset in 80 * pmap->pm_rsegmap by 0 if pmap is not the kernel pmap, or by 81 * NUSEG if it is. We keep a pointer called pmap->pm_segmap 82 * pre-offset by this value. pmap->pm_segmap thus contains the 83 * values to be loaded into the user portion of the hardware segment 84 * map so as to reach the proper PMEGs within the MMU. The kernel 85 * mappings are `set early' and are always valid in every context 86 * (every change is always propagated immediately). 87 * 88 * The PMEGs within the MMU are loaded `on demand'; when a PMEG is 89 * taken away from context `c', the pmap for context c has its 90 * corresponding pm_segmap[vseg] entry marked invalid (the MMU segment 91 * map entry is also made invalid at the same time). Thus 92 * pm_segmap[vseg] is the `invalid pmeg' number (127 or 511) whenever 93 * the corresponding PTEs are not actually in the MMU. On the other 94 * hand, pm_pte[vseg] is NULL only if no pages in that virtual segment 95 * are in core; otherwise it points to a copy of the 32 or 64 PTEs that 96 * must be loaded in the MMU in order to reach those pages. 97 * pm_npte[vseg] counts the number of valid pages in each vseg. 98 * 99 * XXX performance: faster to count valid bits? 100 * 101 * The kernel pmap cannot malloc() PTEs since malloc() will sometimes 102 * allocate a new virtual segment. Since kernel mappings are never 103 * `stolen' out of the the MMU, we just keep all its PTEs there, and 104 * have no software copies. Its mmu entries are nonetheless kept on lists 105 * so that the code that fiddles with mmu lists has something to fiddle. 106 */ 107 #define NKSEG ((int)((-(unsigned)KERNBASE) / NBPSG)) /* i.e., 512 */ 108 #define NUSEG (4096 - NKSEG) /* i.e., 3584 */ 109 110 /* data appearing in both user and kernel pmaps */ 111 struct pmap_common { 112 union ctxinfo *pmc_ctx; /* current context, if any */ 113 int pmc_ctxnum; /* current context's number */ 114 #if NCPUS > 1 115 simple_lock_data_t pmc_lock; /* spinlock */ 116 #endif 117 int pmc_refcount; /* just what it says */ 118 struct mmuentry *pmc_mmuforw; /* pmap pmeg chain */ 119 struct mmuentry **pmc_mmuback; /* (two way street) */ 120 pmeg_t *pmc_segmap; /* points to pm_rsegmap per above */ 121 u_char *pmc_npte; /* points to pm_rnpte */ 122 int **pmc_pte; /* points to pm_rpte */ 123 }; 124 125 /* data appearing only in user pmaps */ 126 struct pmap { 127 struct pmap_common pmc; 128 pmeg_t pm_rsegmap[NUSEG]; /* segment map */ 129 u_char pm_rnpte[NUSEG]; /* number of valid PTEs per seg */ 130 int *pm_rpte[NUSEG]; /* points to PTEs for valid segments */ 131 }; 132 133 /* data appearing only in the kernel pmap */ 134 struct kpmap { 135 struct pmap_common pmc; 136 pmeg_t pm_rsegmap[NKSEG]; /* segment map */ 137 u_char pm_rnpte[NKSEG]; /* number of valid PTEs per kseg */ 138 int *pm_rpte[NKSEG]; /* always NULL */ 139 }; 140 141 #define pm_ctx pmc.pmc_ctx 142 #define pm_ctxnum pmc.pmc_ctxnum 143 #define pm_lock pmc.pmc_lock 144 #define pm_refcount pmc.pmc_refcount 145 #define pm_mmuforw pmc.pmc_mmuforw 146 #define pm_mmuback pmc.pmc_mmuback 147 #define pm_segmap pmc.pmc_segmap 148 #define pm_npte pmc.pmc_npte 149 #define pm_pte pmc.pmc_pte 150 151 #ifdef KERNEL 152 153 typedef struct pmap *pmap_t; 154 #define PMAP_NULL ((pmap_t)0) 155 156 extern struct kpmap kernel_pmap_store; 157 158 #define PMAP_ACTIVATE(pmap, pcb, iscurproc) 159 #define PMAP_DEACTIVATE(pmap, pcb) 160 161 /* 162 * Since PTEs also contain type bits, we have to have some way 163 * to tell pmap_enter `this is an IO page' or `this is not to 164 * be cached'. Since physical addresses are always aligned, we 165 * can do this with the low order bits. 166 * 167 * The ordering below is important: PMAP_PGTYPE << PG_TNC must give 168 * exactly the PG_NC and PG_TYPE bits. 169 */ 170 #define PMAP_OBIO 1 /* tells pmap_enter to use PG_OBIO */ 171 #define PMAP_VME16 2 /* etc */ 172 #define PMAP_VME32 3 /* etc */ 173 #define PMAP_NC 4 /* tells pmap_enter to set PG_NC */ 174 #define PMAP_TNC 7 /* mask to get PG_TYPE & PG_NC */ 175 176 void pmap_bootstrap __P((int nmmu, int nctx)); 177 void pmap_init __P((vm_offset_t phys_start, vm_offset_t phys_end)); 178 #endif /* KERNEL */ 179 180 #endif /* _SPARC_PMAP_H_ */ 181