pmap.h revision 1.5.2.2 1 1.1 cgd /*
2 1.1 cgd * Copyright (c) 1991 Regents of the University of California.
3 1.1 cgd * All rights reserved.
4 1.1 cgd *
5 1.1 cgd * This code is derived from software contributed to Berkeley by
6 1.1 cgd * the Systems Programming Group of the University of Utah Computer
7 1.1 cgd * Science Department and William Jolitz of UUNET Technologies Inc.
8 1.1 cgd *
9 1.1 cgd * Redistribution and use in source and binary forms, with or without
10 1.1 cgd * modification, are permitted provided that the following conditions
11 1.1 cgd * are met:
12 1.1 cgd * 1. Redistributions of source code must retain the above copyright
13 1.1 cgd * notice, this list of conditions and the following disclaimer.
14 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 cgd * notice, this list of conditions and the following disclaimer in the
16 1.1 cgd * documentation and/or other materials provided with the distribution.
17 1.1 cgd * 3. All advertising materials mentioning features or use of this software
18 1.1 cgd * must display the following acknowledgement:
19 1.1 cgd * This product includes software developed by the University of
20 1.1 cgd * California, Berkeley and its contributors.
21 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
22 1.1 cgd * may be used to endorse or promote products derived from this software
23 1.1 cgd * without specific prior written permission.
24 1.1 cgd *
25 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 1.1 cgd * SUCH DAMAGE.
36 1.1 cgd *
37 1.2 cgd * from: @(#)pmap.h 7.4 (Berkeley) 5/12/91
38 1.5.2.2 mycroft * $Id: pmap.h,v 1.5.2.2 1993/10/15 13:12:48 mycroft Exp $
39 1.1 cgd */
40 1.1 cgd
41 1.1 cgd /*
42 1.1 cgd * Derived from hp300 version by Mike Hibler, this version by William
43 1.1 cgd * Jolitz uses a recursive map [a pde points to the page directory] to
44 1.1 cgd * map the page tables using the pagetables themselves. This is done to
45 1.1 cgd * reduce the impact on kernel virtual memory for lots of sparse address
46 1.1 cgd * space, and to reduce the cost of memory to each process.
47 1.1 cgd *
48 1.1 cgd * from hp300: @(#)pmap.h 7.2 (Berkeley) 12/16/90
49 1.1 cgd */
50 1.1 cgd
51 1.5.2.2 mycroft #ifndef _I386_PMAP_H_
52 1.5.2.2 mycroft #define _I386_PMAP_H_
53 1.1 cgd
54 1.5.2.2 mycroft #include <machine/pte.h>
55 1.5.2.2 mycroft
56 1.1 cgd /*
57 1.1 cgd * 386 page table entry and page table directory
58 1.1 cgd * W.Jolitz, 8/89
59 1.1 cgd */
60 1.1 cgd
61 1.1 cgd /*
62 1.1 cgd * One page directory, shared between
63 1.1 cgd * kernel and user modes.
64 1.1 cgd */
65 1.1 cgd #define I386_PAGE_SIZE NBPG
66 1.5.2.2 mycroft #define I386_PDR_SIZE NBPD
67 1.1 cgd
68 1.1 cgd #define UPTDI 0x3f6 /* ptd entry for u./kernel&user stack */
69 1.1 cgd #define PTDPTDI 0x3f7 /* ptd entry that points to ptd! */
70 1.1 cgd #define KPTDI_FIRST 0x3f8 /* start of kernel virtual pde's */
71 1.1 cgd #define KPTDI_LAST 0x3fA /* last of kernel virtual pde's */
72 1.1 cgd
73 1.1 cgd /*
74 1.1 cgd * Address of current and alternate address space page table maps
75 1.1 cgd * and directories.
76 1.1 cgd */
77 1.1 cgd #ifdef KERNEL
78 1.1 cgd extern struct pte PTmap[], APTmap[], Upte;
79 1.1 cgd extern struct pde PTD[], APTD[], PTDpde, APTDpde, Upde;
80 1.1 cgd extern pt_entry_t *Sysmap;
81 1.1 cgd
82 1.1 cgd extern int IdlePTD; /* physical address of "Idle" state directory */
83 1.1 cgd #endif
84 1.1 cgd
85 1.1 cgd /*
86 1.1 cgd * virtual address to page table entry and
87 1.1 cgd * to physical address. Likewise for alternate address space.
88 1.1 cgd * Note: these work recursively, thus vtopte of a pte will give
89 1.1 cgd * the corresponding pde that in turn maps it.
90 1.1 cgd */
91 1.1 cgd #define vtopte(va) (PTmap + i386_btop(va))
92 1.1 cgd #define kvtopte(va) vtopte(va)
93 1.1 cgd #define ptetov(pt) (i386_ptob(pt - PTmap))
94 1.1 cgd #define vtophys(va) (i386_ptob(vtopte(va)->pg_pfnum) | ((int)(va) & PGOFSET))
95 1.1 cgd
96 1.1 cgd #define avtopte(va) (APTmap + i386_btop(va))
97 1.1 cgd #define ptetoav(pt) (i386_ptob(pt - APTmap))
98 1.1 cgd #define avtophys(va) (i386_ptob(avtopte(va)->pg_pfnum) | ((int)(va) & PGOFSET))
99 1.1 cgd
100 1.1 cgd /*
101 1.1 cgd * macros to generate page directory/table indicies
102 1.1 cgd */
103 1.1 cgd
104 1.5.2.2 mycroft #define pdei(va) (((va)&PD_MASK)>>PDSHIFT)
105 1.5.2.2 mycroft #define ptei(va) (((va)&PT_MASK)>>PGSHIFT)
106 1.1 cgd
107 1.1 cgd /*
108 1.1 cgd * Pmap stuff
109 1.1 cgd */
110 1.1 cgd
111 1.1 cgd struct pmap {
112 1.1 cgd pd_entry_t *pm_pdir; /* KVA of page directory */
113 1.1 cgd boolean_t pm_pdchanged; /* pdir changed */
114 1.1 cgd short pm_dref; /* page directory ref count */
115 1.1 cgd short pm_count; /* pmap reference count */
116 1.1 cgd simple_lock_data_t pm_lock; /* lock on pmap */
117 1.1 cgd struct pmap_statistics pm_stats; /* pmap statistics */
118 1.1 cgd long pm_ptpages; /* more stats: PT pages */
119 1.1 cgd };
120 1.1 cgd
121 1.1 cgd typedef struct pmap *pmap_t;
122 1.1 cgd
123 1.1 cgd #ifdef KERNEL
124 1.1 cgd extern pmap_t kernel_pmap;
125 1.1 cgd #endif
126 1.1 cgd
127 1.1 cgd /*
128 1.1 cgd * Macros for speed
129 1.1 cgd */
130 1.1 cgd #define PMAP_ACTIVATE(pmapp, pcbp) \
131 1.1 cgd if ((pmapp) != NULL /*&& (pmapp)->pm_pdchanged */) { \
132 1.1 cgd (pcbp)->pcb_cr3 = \
133 1.1 cgd pmap_extract(kernel_pmap, (pmapp)->pm_pdir); \
134 1.1 cgd if ((pmapp) == &curproc->p_vmspace->vm_pmap) \
135 1.5.2.1 mycroft lcr3((pcbp)->pcb_cr3); \
136 1.1 cgd (pmapp)->pm_pdchanged = FALSE; \
137 1.1 cgd }
138 1.1 cgd
139 1.1 cgd #define PMAP_DEACTIVATE(pmapp, pcbp)
140 1.1 cgd
141 1.1 cgd /*
142 1.1 cgd * For each vm_page_t, there is a list of all currently valid virtual
143 1.1 cgd * mappings of that page. An entry is a pv_entry_t, the list is pv_table.
144 1.1 cgd */
145 1.1 cgd typedef struct pv_entry {
146 1.1 cgd struct pv_entry *pv_next; /* next pv_entry */
147 1.1 cgd pmap_t pv_pmap; /* pmap where mapping lies */
148 1.1 cgd vm_offset_t pv_va; /* virtual address for mapping */
149 1.1 cgd int pv_flags; /* flags */
150 1.1 cgd } *pv_entry_t;
151 1.1 cgd
152 1.1 cgd #ifdef KERNEL
153 1.1 cgd
154 1.1 cgd pv_entry_t pv_table; /* array of entries, one per page */
155 1.1 cgd
156 1.4 brezak #define pa_to_pvh(pa) (&pv_table[pmap_page_index(pa)])
157 1.5 brezak void pmap_bootstrap __P((vm_offset_t start));
158 1.1 cgd
159 1.1 cgd #define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count)
160 1.1 cgd
161 1.3 jtc #endif /* KERNEL */
162 1.1 cgd
163 1.5.2.2 mycroft #endif /* _I386_PMAP_H_ */
164