1 /* 2 * Copyright (c) 1992 The Regents of the University of California. 3 * 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 * %sccs.include.redist.c% 10 * 11 * @(#)pmap.h 7.1 (Berkeley) 07/13/92 12 * 13 * from: $Header: pmap.h,v 1.9 92/06/17 06:10:22 torek Exp $ 14 */ 15 16 #ifndef _SPARC_PMAP_H_ 17 #define _SPARC_PMAP_H_ 18 19 #include "machine/pte.h" 20 21 /* 22 * Pmap structure. 23 * 24 * The pmap structure really comes in two variants, one---a single 25 * instance---for kernel virtual memory and the other---up to nproc 26 * instances---for user virtual memory. Unfortunately, we have to mash 27 * both into the same structure. Fortunately, they are almost the same. 28 * 29 * The kernel begins at 0xf8000000 and runs to 0xffffffff (although 30 * some of this is not actually used). Kernel space, including DVMA 31 * space (for now?), is mapped identically into all user contexts. 32 * There is no point in duplicating this mapping in each user process 33 * so they do not appear in the user structures. 34 * 35 * User space begins at 0x00000000 and runs through 0x1fffffff, 36 * then has a `hole', then resumes at 0xe0000000 and runs until it 37 * hits the kernel space at 0xf8000000. This can be mapped 38 * contiguously by ignorning the top two bits and pretending the 39 * space goes from 0 to 37ffffff. Typically the lower range is 40 * used for text+data and the upper for stack, but the code here 41 * makes no such distinction. 42 * 43 * Since each virtual segment covers 256 kbytes, the user space 44 * requires 3584 segments, while the kernel (including DVMA) requires 45 * only 512 segments. 46 * 47 * The segment map entry for virtual segment vseg is offset in 48 * pmap->pm_rsegmap by 0 if pmap is not the kernel pmap, or by 49 * NUSEG if it is. We keep a pointer called pmap->pm_segmap 50 * pre-offset by this value. pmap->pm_segmap thus contains the 51 * values to be loaded into the user portion of the hardware segment 52 * map so as to reach the proper PMEGs within the MMU. The kernel 53 * mappings are `set early' and are always valid in every context 54 * (every change is always propagated immediately). 55 * 56 * The PMEGs within the MMU are loaded `on demand'; when a PMEG is 57 * taken away from context `c', the pmap for context c has its 58 * corresponding pm_segmap[vseg] entry marked invalid (the MMU segment 59 * map entry is also made invalid at the same time). Thus 60 * pm_segmap[vseg] is the `invalid pmeg' number (127 or 511) whenever 61 * the corresponding PTEs are not actually in the MMU. On the other 62 * hand, pm_pte[vseg] is NULL only if no pages in that virtual segment 63 * are in core; otherwise it points to a copy of the 32 or 64 PTEs that 64 * must be loaded in the MMU in order to reach those pages. 65 * pm_npte[vseg] counts the number of valid pages in each vseg. 66 * 67 * XXX performance: faster to count valid bits? 68 * 69 * The kernel pmap cannot malloc() PTEs since malloc() will sometimes 70 * allocate a new virtual segment. Since kernel mappings are never 71 * `stolen' out of the the MMU, we just keep all its PTEs there, and 72 * have no software copies. Its mmu entries are nonetheless kept on lists 73 * so that the code that fiddles with mmu lists has something to fiddle. 74 */ 75 #define NKSEG ((int)((-(unsigned)KERNBASE) / NBPSG)) /* i.e., 512 */ 76 #define NUSEG (4096 - NKSEG) /* i.e., 3584 */ 77 78 /* data appearing in both user and kernel pmaps */ 79 struct pmap_common { 80 union ctxinfo *pmc_ctx; /* current context, if any */ 81 int pmc_ctxnum; /* current context's number */ 82 #if NCPUS > 1 83 simple_lock_data_t pmc_lock; /* spinlock */ 84 #endif 85 int pmc_refcount; /* just what it says */ 86 struct mmuentry *pmc_mmuforw; /* pmap pmeg chain */ 87 struct mmuentry **pmc_mmuback; /* (two way street) */ 88 pmeg_t *pmc_segmap; /* points to pm_rsegmap per above */ 89 u_char *pmc_npte; /* points to pm_rnpte */ 90 int **pmc_pte; /* points to pm_rpte */ 91 }; 92 93 /* data appearing only in user pmaps */ 94 struct pmap { 95 struct pmap_common pmc; 96 pmeg_t pm_rsegmap[NUSEG]; /* segment map */ 97 u_char pm_rnpte[NUSEG]; /* number of valid PTEs per seg */ 98 int *pm_rpte[NUSEG]; /* points to PTEs for valid segments */ 99 }; 100 101 /* data appearing only in the kernel pmap */ 102 struct kpmap { 103 struct pmap_common pmc; 104 pmeg_t pm_rsegmap[NKSEG]; /* segment map */ 105 u_char pm_rnpte[NKSEG]; /* number of valid PTEs per kseg */ 106 int *pm_rpte[NKSEG]; /* always NULL */ 107 }; 108 109 #define pm_ctx pmc.pmc_ctx 110 #define pm_ctxnum pmc.pmc_ctxnum 111 #define pm_lock pmc.pmc_lock 112 #define pm_refcount pmc.pmc_refcount 113 #define pm_mmuforw pmc.pmc_mmuforw 114 #define pm_mmuback pmc.pmc_mmuback 115 #define pm_segmap pmc.pmc_segmap 116 #define pm_npte pmc.pmc_npte 117 #define pm_pte pmc.pmc_pte 118 119 #ifdef KERNEL 120 121 typedef struct pmap *pmap_t; 122 #define PMAP_NULL ((pmap_t)0) 123 124 extern struct kpmap kernel_pmap_store; 125 #define kernel_pmap ((struct pmap *)(&kernel_pmap_store)) 126 127 #define PMAP_ACTIVATE(pmap, pcb, iscurproc) 128 #define PMAP_DEACTIVATE(pmap, pcb) 129 130 /* 131 * Since PTEs also contain type bits, we have to have some way 132 * to tell pmap_enter `this is an IO page' or `this is not to 133 * be cached'. Since physical addresses are always aligned, we 134 * can do this with the low order bits. 135 * 136 * The ordering below is important: PMAP_PGTYPE << PG_TNC must give 137 * exactly the PG_NC and PG_TYPE bits. 138 */ 139 #define PMAP_OBIO 1 /* tells pmap_enter to use PG_OBIO */ 140 #define PMAP_VME16 2 /* etc */ 141 #define PMAP_VME32 3 /* etc */ 142 #define PMAP_NC 4 /* tells pmap_enter to set PG_NC */ 143 #define PMAP_TNC 7 /* mask to get PG_TYPE & PG_NC */ 144 145 #endif KERNEL 146 147 #endif /* _SPARC_PMAP_H_ */ 148