pmap.h revision 1.7
11.1Scgd/* 21.1Scgd * Copyright (c) 1991 Regents of the University of California. 31.1Scgd * All rights reserved. 41.1Scgd * 51.1Scgd * This code is derived from software contributed to Berkeley by 61.1Scgd * the Systems Programming Group of the University of Utah Computer 71.1Scgd * Science Department and William Jolitz of UUNET Technologies Inc. 81.1Scgd * 91.1Scgd * Redistribution and use in source and binary forms, with or without 101.1Scgd * modification, are permitted provided that the following conditions 111.1Scgd * are met: 121.1Scgd * 1. Redistributions of source code must retain the above copyright 131.1Scgd * notice, this list of conditions and the following disclaimer. 141.1Scgd * 2. Redistributions in binary form must reproduce the above copyright 151.1Scgd * notice, this list of conditions and the following disclaimer in the 161.1Scgd * documentation and/or other materials provided with the distribution. 171.1Scgd * 3. All advertising materials mentioning features or use of this software 181.1Scgd * must display the following acknowledgement: 191.1Scgd * This product includes software developed by the University of 201.1Scgd * California, Berkeley and its contributors. 211.1Scgd * 4. Neither the name of the University nor the names of its contributors 221.1Scgd * may be used to endorse or promote products derived from this software 231.1Scgd * without specific prior written permission. 241.1Scgd * 251.1Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 261.1Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 271.1Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 281.1Scgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 291.1Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 301.1Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 311.1Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 321.1Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 331.1Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 341.1Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 351.1Scgd * SUCH DAMAGE. 361.1Scgd * 371.2Scgd * from: @(#)pmap.h 7.4 (Berkeley) 5/12/91 381.7Smycroft * $Id: pmap.h,v 1.7 1994/01/05 16:02:38 mycroft Exp $ 391.1Scgd */ 401.1Scgd 411.1Scgd/* 421.1Scgd * Derived from hp300 version by Mike Hibler, this version by William 431.1Scgd * Jolitz uses a recursive map [a pde points to the page directory] to 441.1Scgd * map the page tables using the pagetables themselves. This is done to 451.1Scgd * reduce the impact on kernel virtual memory for lots of sparse address 461.1Scgd * space, and to reduce the cost of memory to each process. 471.1Scgd * 481.1Scgd * from hp300: @(#)pmap.h 7.2 (Berkeley) 12/16/90 491.1Scgd */ 501.1Scgd 511.6Smycroft#ifndef _I386_PMAP_H_ 521.6Smycroft#define _I386_PMAP_H_ 531.6Smycroft 541.6Smycroft#include <machine/pte.h> 551.1Scgd 561.1Scgd/* 571.1Scgd * 386 page table entry and page table directory 581.1Scgd * W.Jolitz, 8/89 591.1Scgd */ 601.1Scgd 611.1Scgd/* 621.1Scgd * One page directory, shared between 631.1Scgd * kernel and user modes. 641.1Scgd */ 651.7Smycroft#define UPTDI 0x3de /* ptd entry for u./kernel&user stack */ 661.7Smycroft#define PTDPTDI 0x3df /* ptd entry that points to ptd! */ 671.7Smycroft#define KPTDI 0x3e0 /* start of kernel virtual pde's */ 681.6Smycroft#define NKPDE 7 691.6Smycroft#define APTDPTDI 0x3ff /* start of alternate page directory */ 701.1Scgd 711.1Scgd/* 721.1Scgd * Address of current and alternate address space page table maps 731.1Scgd * and directories. 741.1Scgd */ 751.1Scgd#ifdef KERNEL 761.1Scgdextern struct pte PTmap[], APTmap[], Upte; 771.1Scgdextern struct pde PTD[], APTD[], PTDpde, APTDpde, Upde; 781.6Smycroftextern pt_entry_t *Sysmap; 791.1Scgd 801.1Scgdextern int IdlePTD; /* physical address of "Idle" state directory */ 811.1Scgd#endif 821.1Scgd 831.1Scgd/* 841.1Scgd * virtual address to page table entry and 851.1Scgd * to physical address. Likewise for alternate address space. 861.1Scgd * Note: these work recursively, thus vtopte of a pte will give 871.1Scgd * the corresponding pde that in turn maps it. 881.1Scgd */ 891.1Scgd#define vtopte(va) (PTmap + i386_btop(va)) 901.1Scgd#define kvtopte(va) vtopte(va) 911.1Scgd#define ptetov(pt) (i386_ptob(pt - PTmap)) 921.6Smycroft#define vtophys(va) \ 931.6Smycroft (i386_ptob(vtopte(va)->pg_pfnum) | ((int)(va) & PGOFSET)) 941.1Scgd 951.1Scgd#define avtopte(va) (APTmap + i386_btop(va)) 961.1Scgd#define ptetoav(pt) (i386_ptob(pt - APTmap)) 971.6Smycroft#define avtophys(va) \ 981.6Smycroft (i386_ptob(avtopte(va)->pg_pfnum) | ((int)(va) & PGOFSET)) 991.1Scgd 1001.1Scgd/* 1011.1Scgd * macros to generate page directory/table indicies 1021.1Scgd */ 1031.6Smycroft#define pdei(va) (((va)&PD_MASK)>>PDSHIFT) 1041.6Smycroft#define ptei(va) (((va)&PT_MASK)>>PGSHIFT) 1051.1Scgd 1061.1Scgd/* 1071.1Scgd * Pmap stuff 1081.1Scgd */ 1091.1Scgdstruct pmap { 1101.1Scgd pd_entry_t *pm_pdir; /* KVA of page directory */ 1111.1Scgd boolean_t pm_pdchanged; /* pdir changed */ 1121.1Scgd short pm_dref; /* page directory ref count */ 1131.1Scgd short pm_count; /* pmap reference count */ 1141.1Scgd simple_lock_data_t pm_lock; /* lock on pmap */ 1151.1Scgd struct pmap_statistics pm_stats; /* pmap statistics */ 1161.1Scgd long pm_ptpages; /* more stats: PT pages */ 1171.1Scgd}; 1181.1Scgd 1191.1Scgdtypedef struct pmap *pmap_t; 1201.1Scgd 1211.1Scgd#ifdef KERNEL 1221.1Scgdextern pmap_t kernel_pmap; 1231.1Scgd#endif 1241.1Scgd 1251.1Scgd/* 1261.1Scgd * Macros for speed 1271.1Scgd */ 1281.1Scgd#define PMAP_ACTIVATE(pmapp, pcbp) \ 1291.1Scgd if ((pmapp) != NULL /*&& (pmapp)->pm_pdchanged */) { \ 1301.1Scgd (pcbp)->pcb_cr3 = \ 1311.1Scgd pmap_extract(kernel_pmap, (pmapp)->pm_pdir); \ 1321.1Scgd if ((pmapp) == &curproc->p_vmspace->vm_pmap) \ 1331.6Smycroft lcr3((pcbp)->pcb_cr3); \ 1341.1Scgd (pmapp)->pm_pdchanged = FALSE; \ 1351.1Scgd } 1361.1Scgd 1371.1Scgd#define PMAP_DEACTIVATE(pmapp, pcbp) 1381.1Scgd 1391.1Scgd/* 1401.1Scgd * For each vm_page_t, there is a list of all currently valid virtual 1411.1Scgd * mappings of that page. An entry is a pv_entry_t, the list is pv_table. 1421.1Scgd */ 1431.1Scgdtypedef struct pv_entry { 1441.1Scgd struct pv_entry *pv_next; /* next pv_entry */ 1451.1Scgd pmap_t pv_pmap; /* pmap where mapping lies */ 1461.1Scgd vm_offset_t pv_va; /* virtual address for mapping */ 1471.1Scgd int pv_flags; /* flags */ 1481.1Scgd} *pv_entry_t; 1491.1Scgd 1501.1Scgd#ifdef KERNEL 1511.1Scgd 1521.1Scgdpv_entry_t pv_table; /* array of entries, one per page */ 1531.1Scgd 1541.6Smycroft#define pa_to_pvh(pa) (&pv_table[pmap_page_index(pa)]) 1551.6Smycroftvoid pmap_bootstrap __P((vm_offset_t start)); 1561.1Scgd 1571.1Scgd#define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count) 1581.1Scgd 1591.3Sjtc#endif /* KERNEL */ 1601.1Scgd 1611.6Smycroft#endif /* _I386_PMAP_H_ */ 162