1 /* 2 * Copyright (c) 1991 Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * the Systems Programming Group of the University of Utah Computer 7 * Science Department and William Jolitz of UUNET Technologies Inc. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed by the University of 20 * California, Berkeley and its contributors. 21 * 4. Neither the name of the University nor the names of its contributors 22 * may be used to endorse or promote products derived from this software 23 * without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. 36 * 37 * from: @(#)pmap.h 7.4 (Berkeley) 5/12/91 38 * 386BSD: $Id: pmap.h,v 1.2 93/08/05 17:03:26 bill Exp Locker: root $ 39 */ 40 41 /* 42 * Derived from hp300 version by Mike Hibler, this version by William 43 * Jolitz uses a recursive map [a pde points to the page directory] to 44 * map the page tables using the pagetables themselves. This is done to 45 * reduce the impact on kernel virtual memory for lots of sparse address 46 * space, and to reduce the cost of memory to each process. 47 * 48 * from hp300: @(#)pmap.h 7.2 (Berkeley) 12/16/90 49 */ 50 51 #ifndef _PMAP_MACHINE_ 52 #define _PMAP_MACHINE_ 53 54 /* 55 * 386 page table entry and page table directory 56 * W.Jolitz, 8/89 57 */ 58 59 #ifndef LOCORE 60 struct pde 61 { 62 unsigned int 63 pd_v:1, /* valid bit */ 64 pd_prot:2, /* access control */ 65 pd_mbz1:2, /* reserved, must be zero */ 66 pd_u:1, /* hardware maintained 'used' bit */ 67 :1, /* not used */ 68 pd_mbz2:2, /* reserved, must be zero */ 69 :3, /* reserved for software */ 70 pd_pfnum:20; /* physical page frame number of pte's*/ 71 }; 72 #endif 73 74 #define PD_MASK 0xffc00000 /* page directory address bits */ 75 #define PT_MASK 0x003ff000 /* page table address bits */ 76 #define PD_SHIFT 22 /* page directory address shift */ 77 #define PG_SHIFT 12 /* page table address shift */ 78 79 #ifndef LOCORE 80 struct pte 81 { 82 unsigned int 83 pg_v:1, /* valid bit */ 84 pg_prot:2, /* access control */ 85 /*pg_mbz1:1, /* reserved, must be zero */ 86 pg_wt:1, /* 'write thru' bit */ 87 pg_cd:1, /* 'uncacheable page' bit */ 88 /*pg_mbz1:2, /* reserved, must be zero */ 89 pg_u:1, /* hardware maintained 'used' bit */ 90 pg_m:1, /* hardware maintained modified bit */ 91 pg_mbz2:2, /* reserved, must be zero */ 92 pg_w:1, /* software, wired down page */ 93 :1, /* software (unused) */ 94 /* pg_nc:1, /* 'uncacheable page' bit */ 95 :1, /* software (unused) */ 96 pg_pfnum:20; /* physical page frame number */ 97 }; 98 #endif 99 100 #define PG_V 0x00000001 101 #define PG_RO 0x00000000 102 #define PG_RW 0x00000002 103 #define PG_u 0x00000004 104 #define PG_PROT 0x00000006 /* all protection bits . */ 105 #define PG_W 0x00000200 106 /*#define PG_N 0x00000800 /* Non-cacheable */ 107 #define PG_CD 0x00000010 /* Non-cacheable */ 108 #define PG_WT 0x00000008 /* write thru */ 109 #define PG_M 0x00000040 110 #define PG_U 0x00000020 111 #define PG_FRAME 0xfffff000 112 113 #define PG_NOACC 0 114 #define PG_KR 0x00000000 115 #define PG_KW 0x00000002 116 #define PG_URKR 0x00000004 117 #define PG_URKW 0x00000004 118 #define PG_UW 0x00000006 119 120 /* Garbage for current bastardized pager that assumes a hp300 */ 121 #define PG_NV 0 122 #define PG_CI 0 123 /* 124 * Page Protection Exception bits 125 */ 126 127 #define PGEX_P 0x01 /* Protection violation vs. not present */ 128 #define PGEX_W 0x02 /* during a Write cycle */ 129 #define PGEX_U 0x04 /* access from User mode (UPL) */ 130 131 #ifndef LOCORE 132 typedef struct pde pd_entry_t; /* page directory entry */ 133 typedef struct pte pt_entry_t; /* page table entry */ 134 #endif 135 136 /* 137 * One page directory, shared between 138 * kernel and user modes. 139 */ 140 #define I386_PAGE_SIZE NBPG 141 #define I386_PDR_SIZE NBPDR 142 143 #define KPTDI_LAST 0x3ff /* last of kernel virtual pde's */ 144 #define KPTDI_FIRST (KERNBASE >> PD_SHIFT) /* start of kernel virtual pde's */ 145 #define PTDPTDI (KPTDI_FIRST - 1) /* ptd entry that points to ptd! */ 146 147 /* 148 * Current and alternate address space page table maps 149 * and directories. These are defined as absolute addresses in locore. 150 */ 151 #ifndef LOCORE 152 #ifdef KERNEL 153 extern struct pte PTmap[], APTmap[]; 154 extern struct pde PTD[], APTD[], PTDpde, APTDpde; 155 156 extern int KernelPTD; /* physical address of "Idle" state directory */ 157 #endif 158 159 /* 160 * Virtual address to page table entry and to physical address. 161 * Likewise for alternate address space. 162 * N.B.: these work recursively, thus vtopte of a pte will give 163 * the corresponding pde that in turn maps it. 164 */ 165 #define vtopte(va) (PTmap + i386_btop(va)) 166 #define kvtopte(va) vtopte(va) 167 #define ptetov(pt) (i386_ptob(pt - PTmap)) 168 #define vtophys(va) (i386_ptob(vtopte(va)->pg_pfnum) | ((int)(va) & PGOFSET)) 169 170 #define avtopte(va) (APTmap + i386_btop(va)) 171 #define ptetoav(pt) (i386_ptob(pt - APTmap)) 172 #define avtophys(va) (i386_ptob(avtopte(va)->pg_pfnum) | ((int)(va) & PGOFSET)) 173 174 /* 175 * Macros to generate page directory/table indicies 176 */ 177 178 #define pdei(va) (((va)&PD_MASK)>>PD_SHIFT) 179 #define ptei(va) (((va)&PT_MASK)>>PG_SHIFT) 180 181 /* 182 * Pmap instance definition. 183 */ 184 185 struct pmap { 186 pd_entry_t *pm_pdir; /* KVA of page directory */ 187 boolean_t pm_ptchanged; /* page tables changed */ 188 short pm_dref; /* page directory ref count */ 189 short pm_count; /* pmap reference count */ 190 struct pmap_statistics pm_stats; /* pmap statistics */ 191 long pm_ptpages; /* more stats: PT pages */ 192 vm_object_t pm_ptobject; /* pagetable pages in here */ 193 struct proc *pm_proc; /* associated process XXX */ 194 }; 195 196 typedef struct pmap *pmap_t; 197 198 #ifdef KERNEL 199 extern pmap_t kernel_pmap; 200 #endif 201 202 /* 203 * Each logical page (vm_page_t) has an entry in the physical to virtual table, 204 * pv_table, even if the page is not mapped to a virtual address. If mapped to 205 * more than one virtual address or in other virtual address space(s), the 206 * entry is the head of a list of address spaces and virtual addresses to 207 * which the page is mapped. This is used to locate all instances of address 208 * translation mappings of a page so that the can be altered if the state of 209 * the page changes (i.e. if reclaimed, or if contents are affected). 210 */ 211 typedef struct pv_entry { 212 struct pv_entry *pv_next; /* next pv_entry */ 213 pmap_t pv_pmap; /* pmap where mapping lies */ 214 vm_offset_t pv_va; /* virtual address for mapping */ 215 int pv_flags; /* flags */ 216 int pv_am; /* address mapping class */ 217 } *pv_entry_t; 218 219 #define PV_ENTRY_NULL ((pv_entry_t) 0) 220 221 #define PV_CI 0x01 /* all entries must be cache inhibited */ 222 #define PV_PTPAGE 0x02 /* entry maps a page table page */ 223 224 #ifdef KERNEL 225 226 pv_entry_t pv_table; /* array of entries, one per page */ 227 228 #define pa_index(pa) atop(pa - vm_first_phys) 229 #define pa_to_pvh(pa) (&pv_table[pa_index(pa)]) 230 231 #define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count) 232 233 #endif KERNEL 234 #endif LOCORE 235 236 #endif _PMAP_MACHINE_ 237