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