Home | History | Annotate | Line # | Download | only in include
pmap.h revision 1.38
      1 /*	$NetBSD: pmap.h,v 1.38 1998/08/15 05:10:25 mycroft Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Charles M. Hannum.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * Copyright (c) 1991 Regents of the University of California.
     41  * All rights reserved.
     42  *
     43  * This code is derived from software contributed to Berkeley by
     44  * the Systems Programming Group of the University of Utah Computer
     45  * Science Department and William Jolitz of UUNET Technologies Inc.
     46  *
     47  * Redistribution and use in source and binary forms, with or without
     48  * modification, are permitted provided that the following conditions
     49  * are met:
     50  * 1. Redistributions of source code must retain the above copyright
     51  *    notice, this list of conditions and the following disclaimer.
     52  * 2. Redistributions in binary form must reproduce the above copyright
     53  *    notice, this list of conditions and the following disclaimer in the
     54  *    documentation and/or other materials provided with the distribution.
     55  * 3. All advertising materials mentioning features or use of this software
     56  *    must display the following acknowledgement:
     57  *	This product includes software developed by the University of
     58  *	California, Berkeley and its contributors.
     59  * 4. Neither the name of the University nor the names of its contributors
     60  *    may be used to endorse or promote products derived from this software
     61  *    without specific prior written permission.
     62  *
     63  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     64  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     65  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     66  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     67  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     68  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     69  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     70  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     71  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     72  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     73  * SUCH DAMAGE.
     74  *
     75  *	@(#)pmap.h	7.4 (Berkeley) 5/12/91
     76  */
     77 
     78 /*
     79  * Derived from hp300 version by Mike Hibler, this version by William
     80  * Jolitz uses a recursive map [a pde points to the page directory] to
     81  * map the page tables using the pagetables themselves. This is done to
     82  * reduce the impact on kernel virtual memory for lots of sparse address
     83  * space, and to reduce the cost of memory to each process.
     84  *
     85  * from hp300:	@(#)pmap.h	7.2 (Berkeley) 12/16/90
     86  */
     87 
     88 #if defined(_KERNEL) && !defined(_LKM)
     89 #include "opt_pmap_new.h"
     90 #endif
     91 
     92 #ifdef PMAP_NEW			/* redirect */
     93 #include <machine/pmap.new.h>	/* defines _I386_PMAP_H_ */
     94 #endif
     95 
     96 #ifndef	_I386_PMAP_H_
     97 #define	_I386_PMAP_H_
     98 
     99 #include <machine/cpufunc.h>
    100 #include <machine/pte.h>
    101 
    102 /*
    103  * 386 page table entry and page table directory
    104  * W.Jolitz, 8/89
    105  */
    106 
    107 /*
    108  * PG_AVAIL usage ...
    109  */
    110 
    111 #define PG_W         PG_AVAIL1       /* "wired" mapping */
    112 
    113 /*
    114  * One page directory, shared between
    115  * kernel and user modes.
    116  */
    117 #define	PTDPTDI		0x3bf		/* ptd entry that points to ptd! */
    118 #define	KPTDI		0x3c0		/* start of kernel virtual pde's */
    119 #define	NKPDE_BASE	4		/* min. # of kernel PDEs */
    120 #define	NKPDE_MAX	63		/* max. # of kernel PDEs */
    121 #define	NKPDE_SCALE	1		/* # of kernel PDEs to add per meg. */
    122 #define	APTDPTDI	0x3ff		/* start of alternate page directory */
    123 
    124 #define UPT_MIN_ADDRESS	(PTDPTDI<<PDSHIFT)
    125 #define UPT_MAX_ADDRESS	(UPT_MIN_ADDRESS + (PTDPTDI<<PGSHIFT))
    126 
    127 /*
    128  * Address of current and alternate address space page table maps
    129  * and directories.
    130  */
    131 #ifdef _KERNEL
    132 extern pt_entry_t	PTmap[], APTmap[], Upte;
    133 extern pd_entry_t	PTD[], APTD[], PTDpde, APTDpde, Upde;
    134 extern pt_entry_t	*Sysmap;
    135 
    136 extern u_long	PTDpaddr;	/* physical address of kernel PTD */
    137 
    138 void pmap_bootstrap __P((vaddr_t start));
    139 boolean_t pmap_testbit __P((paddr_t, int));
    140 void pmap_changebit __P((paddr_t, int, int));
    141 #endif
    142 
    143 /*
    144  * virtual address to page table entry and
    145  * to physical address. Likewise for alternate address space.
    146  * Note: these work recursively, thus vtopte of a pte will give
    147  * the corresponding pde that in turn maps it.
    148  */
    149 #define	vtopte(va)	(PTmap + i386_btop(va))
    150 #define	kvtopte(va)	vtopte(va)
    151 #define	ptetov(pt)	(i386_ptob(pt - PTmap))
    152 #define	vtophys(va) \
    153 	((*vtopte(va) & PG_FRAME) | ((unsigned)(va) & ~PG_FRAME))
    154 
    155 #define	avtopte(va)	(APTmap + i386_btop(va))
    156 #define	ptetoav(pt)	(i386_ptob(pt - APTmap))
    157 #define	avtophys(va) \
    158 	((*avtopte(va) & PG_FRAME) | ((unsigned)(va) & ~PG_FRAME))
    159 
    160 /*
    161  * macros to generate page directory/table indicies
    162  */
    163 #define	pdei(va)	(((va) & PD_MASK) >> PDSHIFT)
    164 #define	ptei(va)	(((va) & PT_MASK) >> PGSHIFT)
    165 
    166 /*
    167  * Pmap stuff
    168  */
    169 typedef struct pmap {
    170 	pd_entry_t		*pm_pdir;	/* KVA of page directory */
    171 	short			pm_dref;	/* page directory ref count */
    172 	short			pm_count;	/* pmap reference count */
    173 	simple_lock_data_t	pm_lock;	/* lock on pmap */
    174 	struct pmap_statistics	pm_stats;	/* pmap statistics */
    175 	long			pm_ptpages;	/* more stats: PT pages */
    176 } *pmap_t;
    177 
    178 /*
    179  * For each vm_page_t, there is a list of all currently valid virtual
    180  * mappings of that page.  An entry is a pv_entry, the list is pv_table.
    181  */
    182 struct pv_entry {
    183 	struct pv_entry	*pv_next;	/* next pv_entry */
    184 	pmap_t		pv_pmap;	/* pmap where mapping lies */
    185 	vaddr_t		pv_va;		/* virtual address for mapping */
    186 };
    187 
    188 struct pv_page;
    189 
    190 struct pv_page_info {
    191 	TAILQ_ENTRY(pv_page) pgi_list;
    192 	struct pv_entry *pgi_freelist;
    193 	int pgi_nfree;
    194 };
    195 
    196 /*
    197  * This is basically:
    198  * ((NBPG - sizeof(struct pv_page_info)) / sizeof(struct pv_entry))
    199  */
    200 #define	NPVPPG	340
    201 
    202 struct pv_page {
    203 	struct pv_page_info pvp_pgi;
    204 	struct pv_entry pvp_pv[NPVPPG];
    205 };
    206 
    207 #ifdef	_KERNEL
    208 extern int		nkpde;		/* number of kernel page dir. ents */
    209 extern struct pmap	kernel_pmap_store;
    210 
    211 #define	pmap_kernel()			(&kernel_pmap_store)
    212 #define	pmap_resident_count(pmap)	((pmap)->pm_stats.resident_count)
    213 #define	pmap_update()			tlbflush()
    214 
    215 vaddr_t reserve_dumppages __P((vaddr_t));
    216 
    217 static __inline void
    218 pmap_clear_modify(paddr_t pa)
    219 {
    220 	pmap_changebit(pa, 0, ~PG_M);
    221 }
    222 
    223 static __inline void
    224 pmap_clear_reference(paddr_t pa)
    225 {
    226 	pmap_changebit(pa, 0, ~PG_U);
    227 }
    228 
    229 static __inline void
    230 pmap_copy_on_write(paddr_t pa)
    231 {
    232 	pmap_changebit(pa, PG_RO, ~PG_RW);
    233 }
    234 
    235 static __inline boolean_t
    236 pmap_is_modified(paddr_t pa)
    237 {
    238 	return pmap_testbit(pa, PG_M);
    239 }
    240 
    241 static __inline boolean_t
    242 pmap_is_referenced(paddr_t pa)
    243 {
    244 	return pmap_testbit(pa, PG_U);
    245 }
    246 
    247 static __inline paddr_t
    248 pmap_phys_address(int ppn)
    249 {
    250 	return i386_ptob(ppn);
    251 }
    252 
    253 vaddr_t	pmap_map __P((vaddr_t, paddr_t, paddr_t, int));
    254 
    255 #endif	/* _KERNEL */
    256 
    257 #endif /* _I386_PMAP_H_ */
    258