Home | History | Annotate | Line # | Download | only in include
pmap.h revision 1.5.2.2
      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  *	$Id: pmap.h,v 1.5.2.2 1993/10/15 13:12:48 mycroft Exp $
     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	_I386_PMAP_H_
     52 #define	_I386_PMAP_H_
     53 
     54 #include <machine/pte.h>
     55 
     56 /*
     57  * 386 page table entry and page table directory
     58  * W.Jolitz, 8/89
     59  */
     60 
     61 /*
     62  * One page directory, shared between
     63  * kernel and user modes.
     64  */
     65 #define I386_PAGE_SIZE	NBPG
     66 #define I386_PDR_SIZE	NBPD
     67 
     68 #define	UPTDI		0x3f6		/* ptd entry for u./kernel&user stack */
     69 #define	PTDPTDI		0x3f7		/* ptd entry that points to ptd! */
     70 #define	KPTDI_FIRST	0x3f8		/* start of kernel virtual pde's */
     71 #define	KPTDI_LAST	0x3fA		/* last of kernel virtual pde's */
     72 
     73 /*
     74  * Address of current and alternate address space page table maps
     75  * and directories.
     76  */
     77 #ifdef KERNEL
     78 extern struct pte	PTmap[], APTmap[], Upte;
     79 extern struct pde	PTD[], APTD[], PTDpde, APTDpde, Upde;
     80 extern	pt_entry_t	*Sysmap;
     81 
     82 extern int	IdlePTD;	/* physical address of "Idle" state directory */
     83 #endif
     84 
     85 /*
     86  * virtual address to page table entry and
     87  * to physical address. Likewise for alternate address space.
     88  * Note: these work recursively, thus vtopte of a pte will give
     89  * the corresponding pde that in turn maps it.
     90  */
     91 #define	vtopte(va)	(PTmap + i386_btop(va))
     92 #define	kvtopte(va)	vtopte(va)
     93 #define	ptetov(pt)	(i386_ptob(pt - PTmap))
     94 #define	vtophys(va)  (i386_ptob(vtopte(va)->pg_pfnum) | ((int)(va) & PGOFSET))
     95 
     96 #define	avtopte(va)	(APTmap + i386_btop(va))
     97 #define	ptetoav(pt)	(i386_ptob(pt - APTmap))
     98 #define	avtophys(va)  (i386_ptob(avtopte(va)->pg_pfnum) | ((int)(va) & PGOFSET))
     99 
    100 /*
    101  * macros to generate page directory/table indicies
    102  */
    103 
    104 #define	pdei(va)	(((va)&PD_MASK)>>PDSHIFT)
    105 #define	ptei(va)	(((va)&PT_MASK)>>PGSHIFT)
    106 
    107 /*
    108  * Pmap stuff
    109  */
    110 
    111 struct pmap {
    112 	pd_entry_t		*pm_pdir;	/* KVA of page directory */
    113 	boolean_t		pm_pdchanged;	/* pdir changed */
    114 	short			pm_dref;	/* page directory ref count */
    115 	short			pm_count;	/* pmap reference count */
    116 	simple_lock_data_t	pm_lock;	/* lock on pmap */
    117 	struct pmap_statistics	pm_stats;	/* pmap statistics */
    118 	long			pm_ptpages;	/* more stats: PT pages */
    119 };
    120 
    121 typedef struct pmap	*pmap_t;
    122 
    123 #ifdef KERNEL
    124 extern pmap_t		kernel_pmap;
    125 #endif
    126 
    127 /*
    128  * Macros for speed
    129  */
    130 #define PMAP_ACTIVATE(pmapp, pcbp) \
    131 	if ((pmapp) != NULL /*&& (pmapp)->pm_pdchanged */) {  \
    132 		(pcbp)->pcb_cr3 = \
    133 		    pmap_extract(kernel_pmap, (pmapp)->pm_pdir); \
    134 		if ((pmapp) == &curproc->p_vmspace->vm_pmap) \
    135 			lcr3((pcbp)->pcb_cr3); \
    136 		(pmapp)->pm_pdchanged = FALSE; \
    137 	}
    138 
    139 #define PMAP_DEACTIVATE(pmapp, pcbp)
    140 
    141 /*
    142  * For each vm_page_t, there is a list of all currently valid virtual
    143  * mappings of that page.  An entry is a pv_entry_t, the list is pv_table.
    144  */
    145 typedef struct pv_entry {
    146 	struct pv_entry	*pv_next;	/* next pv_entry */
    147 	pmap_t		pv_pmap;	/* pmap where mapping lies */
    148 	vm_offset_t	pv_va;		/* virtual address for mapping */
    149 	int		pv_flags;	/* flags */
    150 } *pv_entry_t;
    151 
    152 #ifdef	KERNEL
    153 
    154 pv_entry_t	pv_table;		/* array of entries, one per page */
    155 
    156 #define pa_to_pvh(pa)		(&pv_table[pmap_page_index(pa)])
    157 void		pmap_bootstrap __P((vm_offset_t start));
    158 
    159 #define	pmap_resident_count(pmap)	((pmap)->pm_stats.resident_count)
    160 
    161 #endif	/* KERNEL */
    162 
    163 #endif /* _I386_PMAP_H_ */
    164