pmap.h revision 18896
18876Srgrimes/* 24Srgrimes * Copyright (c) 1991 Regents of the University of California. 34Srgrimes * All rights reserved. 44Srgrimes * 54Srgrimes * This code is derived from software contributed to Berkeley by 64Srgrimes * the Systems Programming Group of the University of Utah Computer 74Srgrimes * Science Department and William Jolitz of UUNET Technologies Inc. 84Srgrimes * 94Srgrimes * Redistribution and use in source and binary forms, with or without 104Srgrimes * modification, are permitted provided that the following conditions 114Srgrimes * are met: 124Srgrimes * 1. Redistributions of source code must retain the above copyright 134Srgrimes * notice, this list of conditions and the following disclaimer. 144Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 154Srgrimes * notice, this list of conditions and the following disclaimer in the 164Srgrimes * documentation and/or other materials provided with the distribution. 174Srgrimes * 3. All advertising materials mentioning features or use of this software 184Srgrimes * must display the following acknowledgement: 194Srgrimes * This product includes software developed by the University of 204Srgrimes * California, Berkeley and its contributors. 214Srgrimes * 4. Neither the name of the University nor the names of its contributors 224Srgrimes * may be used to endorse or promote products derived from this software 234Srgrimes * without specific prior written permission. 244Srgrimes * 254Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 264Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 274Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 284Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 294Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 304Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 314Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 324Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 334Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 344Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 354Srgrimes * SUCH DAMAGE. 364Srgrimes * 374Srgrimes * Derived from hp300 version by Mike Hibler, this version by William 384Srgrimes * Jolitz uses a recursive map [a pde points to the page directory] to 394Srgrimes * map the page tables using the pagetables themselves. This is done to 404Srgrimes * reduce the impact on kernel virtual memory for lots of sparse address 414Srgrimes * space, and to reduce the cost of memory to each process. 424Srgrimes * 43607Srgrimes * from: hp300: @(#)pmap.h 7.2 (Berkeley) 12/16/90 44607Srgrimes * from: @(#)pmap.h 7.4 (Berkeley) 5/12/91 4518896Sbde * $Id: pmap.h,v 1.43 1996/09/08 16:57:45 dyson Exp $ 464Srgrimes */ 474Srgrimes 484471Sbde#ifndef _MACHINE_PMAP_H_ 494471Sbde#define _MACHINE_PMAP_H_ 504Srgrimes 5115565Sphk/* 5215565Sphk * Page-directory and page-table entires follow this format, with a few 5315565Sphk * of the fields not present here and there, depending on a lot of things. 5415565Sphk */ 5515565Sphk /* ---- Intel Nomenclature ---- */ 5615565Sphk#define PG_V 0x001 /* P Valid */ 5715565Sphk#define PG_RW 0x002 /* R/W Read/Write */ 5815565Sphk#define PG_U 0x004 /* U/S User/Supervisor */ 5915565Sphk#define PG_NC_PWT 0x008 /* PWT Write through */ 6015565Sphk#define PG_NC_PCD 0x010 /* PCD Cache disable */ 6115565Sphk#define PG_A 0x020 /* A Accessed */ 6215565Sphk#define PG_M 0x040 /* D Dirty */ 6315565Sphk#define PG_PS 0x080 /* PS Page size (0=4k,1=4M) */ 6415565Sphk#define PG_G 0x100 /* G Global */ 6515565Sphk#define PG_AVAIL1 0x200 /* / Available for system */ 6615565Sphk#define PG_AVAIL2 0x400 /* < programmers use */ 6715565Sphk#define PG_AVAIL3 0x800 /* \ */ 684Srgrimes 694Srgrimes 7015565Sphk/* Our various interpretations of the above */ 7115565Sphk#define PG_W PG_AVAIL1 /* "Wired" pseudoflag */ 7215809Sdyson#define PG_MANAGED PG_AVAIL2 7315565Sphk#define PG_FRAME (~PAGE_MASK) 7415565Sphk#define PG_PROT (PG_RW|PG_U) /* all protection bits . */ 7515565Sphk#define PG_N (PG_NC_PWT|PG_NC_PCD) /* Non-cacheable */ 7615565Sphk 774Srgrimes/* 7815543Sphk * Page Protection Exception bits 7915543Sphk */ 8015543Sphk 8115543Sphk#define PGEX_P 0x01 /* Protection violation vs. not present */ 8215543Sphk#define PGEX_W 0x02 /* during a Write cycle */ 8315543Sphk#define PGEX_U 0x04 /* access from User mode (UPL) */ 8415543Sphk 8515543Sphk/* 8615543Sphk * Pte related macros 8715543Sphk */ 8815543Sphk#define VADDR(pdi, pti) ((vm_offset_t)(((pdi)<<PDRSHIFT)|((pti)<<PAGE_SHIFT))) 8915543Sphk 90974Sdg#ifndef NKPT 915455Sdg#define NKPT 9 /* actual number of kernel page tables */ 92974Sdg#endif 93974Sdg#ifndef NKPDE 942246Sdg#define NKPDE 63 /* addressable number of page tables/pde's */ 95974Sdg#endif 96974Sdg 97974Sdg/* 98588Srgrimes * The *PTDI values control the layout of virtual memory 99588Srgrimes * 100588Srgrimes * XXX This works for now, but I am not real happy with it, I'll fix it 101588Srgrimes * right after I fix locore.s and the magic 28K hole 102588Srgrimes */ 10315543Sphk#define APTDPTDI (NPDEPG-1) /* alt ptd entry that points to APTD */ 104607Srgrimes#define KPTDI (APTDPTDI-NKPDE)/* start of kernel virtual pde's */ 105589Srgrimes#define PTDPTDI (KPTDI-1) /* ptd entry that points to ptd! */ 106757Sdg#define KSTKPTDI (PTDPTDI-1) /* ptd entry for u./kernel&user stack */ 10715472Sphk#define KSTKPTEOFF (NPTEPG-UPAGES) /* pte entry for kernel stack */ 1084Srgrimes 10915565Sphk/* 11015565Sphk * XXX doesn't really belong here I guess... 11115565Sphk */ 11215565Sphk#define ISA_HOLE_START 0xa0000 11315565Sphk#define ISA_HOLE_LENGTH (0x100000-ISA_HOLE_START) 11415565Sphk 11515543Sphk#ifndef LOCORE 11618163Sdyson 11718163Sdyson#include <sys/queue.h> 11818163Sdyson 11915543Sphktypedef unsigned int *pd_entry_t; 12015543Sphktypedef unsigned int *pt_entry_t; 12115543Sphk 1221246Sdg#define PDESIZE sizeof(pd_entry_t) /* for assembly files */ 1231246Sdg#define PTESIZE sizeof(pt_entry_t) /* for assembly files */ 124757Sdg 1254Srgrimes/* 1264Srgrimes * Address of current and alternate address space page table maps 1274Srgrimes * and directories. 1284Srgrimes */ 1294Srgrimes#ifdef KERNEL 1301246Sdgextern pt_entry_t PTmap[], APTmap[], Upte; 1311246Sdgextern pd_entry_t PTD[], APTD[], PTDpde, APTDpde, Upde; 1324Srgrimes 1334Srgrimesextern int IdlePTD; /* physical address of "Idle" state directory */ 1344Srgrimes#endif 1354Srgrimes 1364Srgrimes/* 1374Srgrimes * virtual address to page table entry and 1384Srgrimes * to physical address. Likewise for alternate address space. 1394Srgrimes * Note: these work recursively, thus vtopte of a pte will give 1404Srgrimes * the corresponding pde that in turn maps it. 1414Srgrimes */ 1424Srgrimes#define vtopte(va) (PTmap + i386_btop(va)) 14315543Sphk#define vtophys(va) (((int) (*vtopte(va))&PG_FRAME) | ((int)(va) & PAGE_MASK)) 1444Srgrimes 1454Srgrimes#define avtopte(va) (APTmap + i386_btop(va)) 14615543Sphk#define avtophys(va) (((int) (*avtopte(va))&PG_FRAME) | ((int)(va) & PAGE_MASK)) 1474Srgrimes 1481310Sdg#ifdef KERNEL 1494Srgrimes/* 1501307Sdg * Routine: pmap_kextract 1511307Sdg * Function: 1521307Sdg * Extract the physical page address associated 1531307Sdg * kernel virtual address. 1541307Sdg */ 1554471Sbdestatic __inline vm_offset_t 1564471Sbdepmap_kextract(vm_offset_t va) 1571307Sdg{ 1581307Sdg vm_offset_t pa = *(int *)vtopte(va); 15915565Sphk pa = (pa & PG_FRAME) | (va & PAGE_MASK); 1601307Sdg return pa; 1611307Sdg} 1621310Sdg#endif 1631307Sdg 1641307Sdg/* 1654Srgrimes * Pmap stuff 1664Srgrimes */ 16718163Sdysonstruct pv_entry; 16818163Sdysontypedef struct { 16918163Sdyson int pv_list_count; 17018163Sdyson struct vm_page *pv_vm_page; 17118163Sdyson TAILQ_HEAD(,pv_entry) pv_list; 17218163Sdyson} pv_table_t; 1734Srgrimes 1744Srgrimesstruct pmap { 1754Srgrimes pd_entry_t *pm_pdir; /* KVA of page directory */ 17615809Sdyson vm_object_t pm_pteobj; /* Container for pte's */ 17718163Sdyson TAILQ_HEAD(,pv_entry) pm_pvlist; /* list of mappings in pmap */ 17818163Sdyson int pm_count; /* reference count */ 17918163Sdyson int pm_flags; /* pmap flags */ 1804Srgrimes struct pmap_statistics pm_stats; /* pmap statistics */ 18118163Sdyson struct vm_page *pm_ptphint; /* pmap ptp hint */ 1824Srgrimes}; 1834Srgrimes 18418163Sdyson#define PM_FLAG_LOCKED 0x1 18518163Sdyson#define PM_FLAG_WANTED 0x2 18618163Sdyson 1874Srgrimestypedef struct pmap *pmap_t; 1884Srgrimes 1894Srgrimes#ifdef KERNEL 1904Srgrimesextern pmap_t kernel_pmap; 1914Srgrimes#endif 1924Srgrimes 1934Srgrimes/* 1944Srgrimes * For each vm_page_t, there is a list of all currently valid virtual 1954Srgrimes * mappings of that page. An entry is a pv_entry_t, the list is pv_table. 1964Srgrimes */ 1974Srgrimestypedef struct pv_entry { 1984Srgrimes pmap_t pv_pmap; /* pmap where mapping lies */ 1994Srgrimes vm_offset_t pv_va; /* virtual address for mapping */ 20018163Sdyson TAILQ_ENTRY(pv_entry) pv_list; 20118163Sdyson TAILQ_ENTRY(pv_entry) pv_plist; 20214243Sdyson vm_page_t pv_ptem; /* VM page for pte */ 2034Srgrimes} *pv_entry_t; 2044Srgrimes 2054Srgrimes#define PV_ENTRY_NULL ((pv_entry_t) 0) 2064Srgrimes 2074Srgrimes#define PV_CI 0x01 /* all entries must be cache inhibited */ 208588Srgrimes#define PV_PTPAGE 0x02 /* entry maps a page table page */ 2094Srgrimes 2104Srgrimes#ifdef KERNEL 2114Srgrimes 2127090Sbdeextern caddr_t CADDR1; 2137090Sbdeextern pt_entry_t *CMAP1; 2147090Sbdeextern vm_offset_t avail_end; 2157090Sbdeextern vm_offset_t avail_start; 2169578Sdgextern vm_offset_t phys_avail[]; 2177090Sbdeextern vm_offset_t virtual_avail; 2187090Sbdeextern vm_offset_t virtual_end; 2194Srgrimes 22012905Sbdevoid pmap_bootstrap __P(( vm_offset_t, vm_offset_t)); 2214471Sbdepmap_t pmap_kernel __P((void)); 22212905Sbdevoid *pmap_mapdev __P((vm_offset_t, vm_size_t)); 22318896Sbdeunsigned *pmap_pte __P((pmap_t, vm_offset_t)) __pure2; 22414243Sdysonvm_page_t pmap_use_pt __P((pmap_t, vm_offset_t)); 2254471Sbde 226719Swollman#endif /* KERNEL */ 22718896Sbde 22815543Sphk#endif /* !LOCORE */ 2294Srgrimes 2304471Sbde#endif /* !_MACHINE_PMAP_H_ */ 231