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