Home | History | Annotate | Line # | Download | only in include
pmap.h revision 1.13
      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.13 1994/10/09 13:11:18 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	UPTDI		0x3de		/* ptd entry for u./kernel&user stack */
     66 #define	PTDPTDI		0x3df		/* ptd entry that points to ptd! */
     67 #define	KPTDI		0x3e0		/* start of kernel virtual pde's */
     68 #define	NKPDE		11
     69 #define	APTDPTDI	0x3ff		/* start of alternate page directory */
     70 
     71 /*
     72  * Address of current and alternate address space page table maps
     73  * and directories.
     74  */
     75 #ifdef KERNEL
     76 extern pt_entry_t	PTmap[], APTmap[], Upte;
     77 extern pd_entry_t	PTD[], APTD[], PTDpde, APTDpde, Upde;
     78 extern pt_entry_t	*Sysmap;
     79 
     80 extern int	IdlePTD;	/* physical address of "Idle" state directory */
     81 
     82 void pmap_bootstrap __P((vm_offset_t start));
     83 boolean_t pmap_testbit __P((vm_offset_t, int));
     84 void pmap_changebit __P((vm_offset_t, int, int));
     85 __pure u_int pmap_page_index __P((vm_offset_t));
     86 #endif
     87 
     88 /*
     89  * virtual address to page table entry and
     90  * to physical address. Likewise for alternate address space.
     91  * Note: these work recursively, thus vtopte of a pte will give
     92  * the corresponding pde that in turn maps it.
     93  */
     94 #define	vtopte(va)	(PTmap + i386_btop(va))
     95 #define	kvtopte(va)	vtopte(va)
     96 #define	ptetov(pt)	(i386_ptob(pt - PTmap))
     97 #define	vtophys(va) \
     98 	((*vtopte(va) & PG_FRAME) | ((unsigned)(va) & ~PG_FRAME))
     99 
    100 #define	avtopte(va)	(APTmap + i386_btop(va))
    101 #define	ptetoav(pt)	(i386_ptob(pt - APTmap))
    102 #define	avtophys(va) \
    103 	((*avtopte(va) & PG_FRAME) | ((unsigned)(va) & ~PG_FRAME))
    104 
    105 /*
    106  * macros to generate page directory/table indicies
    107  */
    108 #define	pdei(va)	(((va) & PD_MASK) >> PDSHIFT)
    109 #define	ptei(va)	(((va) & PT_MASK) >> PGSHIFT)
    110 
    111 /*
    112  * Pmap stuff
    113  */
    114 typedef struct pmap {
    115 	pd_entry_t		*pm_pdir;	/* KVA of page directory */
    116 	boolean_t		pm_pdchanged;	/* pdir changed */
    117 	short			pm_dref;	/* page directory ref count */
    118 	short			pm_count;	/* pmap reference count */
    119 	simple_lock_data_t	pm_lock;	/* lock on pmap */
    120 	struct pmap_statistics	pm_stats;	/* pmap statistics */
    121 	long			pm_ptpages;	/* more stats: PT pages */
    122 } *pmap_t;
    123 
    124 /*
    125  * For each vm_page_t, there is a list of all currently valid virtual
    126  * mappings of that page.  An entry is a pv_entry, the list is pv_table.
    127  */
    128 struct pv_entry {
    129 	struct pv_entry	*pv_next;	/* next pv_entry */
    130 	pmap_t		pv_pmap;	/* pmap where mapping lies */
    131 	vm_offset_t	pv_va;		/* virtual address for mapping */
    132 };
    133 
    134 struct pv_page;
    135 
    136 struct pv_page_info {
    137 	TAILQ_ENTRY(pv_page) pgi_list;
    138 	struct pv_entry *pgi_freelist;
    139 	int pgi_nfree;
    140 };
    141 
    142 /*
    143  * This is basically:
    144  * ((NBPG - sizeof(struct pv_page_info)) / sizeof(struct pv_entry))
    145  */
    146 #define	NPVPPG	340
    147 
    148 struct pv_page {
    149 	struct pv_page_info pvp_pgi;
    150 	struct pv_entry pvp_pv[NPVPPG];
    151 };
    152 
    153 #ifdef	KERNEL
    154 extern struct pmap	kernel_pmap_store;
    155 struct pv_entry		*pv_table;	/* array of entries, one per page */
    156 
    157 #define	kernel_pmap			(&kernel_pmap_store)
    158 #define	pmap_resident_count(pmap)	((pmap)->pm_stats.resident_count)
    159 #define	pmap_update()			tlbflush()
    160 
    161 static __inline void
    162 pmap_clear_modify(vm_offset_t pa)
    163 {
    164 	pmap_changebit(pa, 0, ~PG_M);
    165 }
    166 
    167 static __inline void
    168 pmap_clear_reference(vm_offset_t pa)
    169 {
    170 	pmap_changebit(pa, 0, ~PG_U);
    171 }
    172 
    173 static __inline void
    174 pmap_copy_on_write(vm_offset_t pa)
    175 {
    176 	pmap_changebit(pa, PG_RO, ~PG_RW);
    177 }
    178 
    179 static __inline boolean_t
    180 pmap_is_modified(vm_offset_t pa)
    181 {
    182 	return pmap_testbit(pa, PG_M);
    183 }
    184 
    185 static __inline boolean_t
    186 pmap_is_referenced(vm_offset_t pa)
    187 {
    188 	return pmap_testbit(pa, PG_U);
    189 }
    190 
    191 static __inline vm_offset_t
    192 pmap_phys_address(int ppn)
    193 {
    194 	return i386_ptob(ppn);
    195 }
    196 
    197 #endif	/* KERNEL */
    198 
    199 #endif /* _I386_PMAP_H_ */
    200