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