pmap.h revision 1.46 1 1.46 atatat /* $NetBSD: pmap.h,v 1.46 2005/01/17 04:54:14 atatat Exp $ */
2 1.5 cgd
3 1.26 simonb /*
4 1.3 glass * Copyright (c) 1992, 1993
5 1.3 glass * The Regents of the University of California. All rights reserved.
6 1.44 agc *
7 1.44 agc * This code is derived from software contributed to Berkeley by
8 1.44 agc * Ralph Campbell.
9 1.44 agc *
10 1.44 agc * Redistribution and use in source and binary forms, with or without
11 1.44 agc * modification, are permitted provided that the following conditions
12 1.44 agc * are met:
13 1.44 agc * 1. Redistributions of source code must retain the above copyright
14 1.44 agc * notice, this list of conditions and the following disclaimer.
15 1.44 agc * 2. Redistributions in binary form must reproduce the above copyright
16 1.44 agc * notice, this list of conditions and the following disclaimer in the
17 1.44 agc * documentation and/or other materials provided with the distribution.
18 1.44 agc * 3. Neither the name of the University nor the names of its contributors
19 1.44 agc * may be used to endorse or promote products derived from this software
20 1.44 agc * without specific prior written permission.
21 1.44 agc *
22 1.44 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.44 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.44 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.44 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.44 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.44 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.44 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.44 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.44 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.44 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.44 agc * SUCH DAMAGE.
33 1.44 agc *
34 1.44 agc * @(#)pmap.h 8.1 (Berkeley) 6/10/93
35 1.44 agc */
36 1.44 agc
37 1.44 agc /*
38 1.44 agc * Copyright (c) 1987 Carnegie-Mellon University
39 1.1 deraadt *
40 1.1 deraadt * This code is derived from software contributed to Berkeley by
41 1.1 deraadt * Ralph Campbell.
42 1.1 deraadt *
43 1.1 deraadt * Redistribution and use in source and binary forms, with or without
44 1.1 deraadt * modification, are permitted provided that the following conditions
45 1.1 deraadt * are met:
46 1.1 deraadt * 1. Redistributions of source code must retain the above copyright
47 1.1 deraadt * notice, this list of conditions and the following disclaimer.
48 1.1 deraadt * 2. Redistributions in binary form must reproduce the above copyright
49 1.1 deraadt * notice, this list of conditions and the following disclaimer in the
50 1.1 deraadt * documentation and/or other materials provided with the distribution.
51 1.1 deraadt * 3. All advertising materials mentioning features or use of this software
52 1.1 deraadt * must display the following acknowledgement:
53 1.1 deraadt * This product includes software developed by the University of
54 1.1 deraadt * California, Berkeley and its contributors.
55 1.1 deraadt * 4. Neither the name of the University nor the names of its contributors
56 1.1 deraadt * may be used to endorse or promote products derived from this software
57 1.1 deraadt * without specific prior written permission.
58 1.1 deraadt *
59 1.1 deraadt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 1.1 deraadt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 1.1 deraadt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 1.1 deraadt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 1.1 deraadt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 1.1 deraadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 1.1 deraadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 1.1 deraadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 1.1 deraadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 1.1 deraadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 1.1 deraadt * SUCH DAMAGE.
70 1.1 deraadt *
71 1.5 cgd * @(#)pmap.h 8.1 (Berkeley) 6/10/93
72 1.1 deraadt */
73 1.1 deraadt
74 1.41 simonb #ifndef _MIPS_PMAP_H_
75 1.41 simonb #define _MIPS_PMAP_H_
76 1.1 deraadt
77 1.24 castor #include <mips/cpuregs.h> /* for KSEG0 below */
78 1.18 thorpej
79 1.1 deraadt /*
80 1.3 glass * The user address space is 2Gb (0x0 - 0x80000000).
81 1.3 glass * User programs are laid out in memory as follows:
82 1.3 glass * address
83 1.3 glass * USRTEXT 0x00001000
84 1.3 glass * USRDATA USRTEXT + text_size
85 1.3 glass * USRSTACK 0x7FFFFFFF
86 1.3 glass *
87 1.3 glass * The user address space is mapped using a two level structure where
88 1.3 glass * virtual address bits 30..22 are used to index into a segment table which
89 1.3 glass * points to a page worth of PTEs (4096 page can hold 1024 PTEs).
90 1.26 simonb * Bits 21..12 are then used to index a PTE which describes a page within
91 1.3 glass * a segment.
92 1.3 glass *
93 1.1 deraadt * The wired entries in the TLB will contain the following:
94 1.3 glass * 0-1 (UPAGES) for curproc user struct and kernel stack.
95 1.3 glass *
96 1.3 glass * Note: The kernel doesn't use the same data structures as user programs.
97 1.3 glass * All the PTE entries are stored in a single array in Sysmap which is
98 1.3 glass * dynamically allocated at boot time.
99 1.1 deraadt */
100 1.1 deraadt
101 1.22 nisimura #define mips_trunc_seg(x) ((vaddr_t)(x) & ~SEGOFSET)
102 1.22 nisimura #define mips_round_seg(x) (((vaddr_t)(x) + SEGOFSET) & ~SEGOFSET)
103 1.3 glass #define pmap_segmap(m, v) ((m)->pm_segtab->seg_tab[((v) >> SEGSHIFT)])
104 1.3 glass
105 1.3 glass #define PMAP_SEGTABSIZE 512
106 1.3 glass
107 1.3 glass union pt_entry;
108 1.3 glass
109 1.3 glass struct segtab {
110 1.3 glass union pt_entry *seg_tab[PMAP_SEGTABSIZE];
111 1.3 glass };
112 1.1 deraadt
113 1.1 deraadt /*
114 1.1 deraadt * Machine dependent pmap structure.
115 1.1 deraadt */
116 1.3 glass typedef struct pmap {
117 1.1 deraadt int pm_count; /* pmap reference count */
118 1.34 chs struct simplelock pm_lock; /* lock on pmap */
119 1.1 deraadt struct pmap_statistics pm_stats; /* pmap statistics */
120 1.27 nisimura unsigned pm_asid; /* TLB address space tag */
121 1.27 nisimura unsigned pm_asidgen; /* its generation number */
122 1.3 glass struct segtab *pm_segtab; /* pointers to pages of PTEs */
123 1.3 glass } *pmap_t;
124 1.1 deraadt
125 1.17 thorpej /*
126 1.35 chs * For each struct vm_page, there is a list of all currently valid virtual
127 1.17 thorpej * mappings of that page. An entry is a pv_entry_t, the list is pv_table.
128 1.17 thorpej * XXX really should do this as a part of the higher level code.
129 1.17 thorpej */
130 1.17 thorpej typedef struct pv_entry {
131 1.17 thorpej struct pv_entry *pv_next; /* next pv_entry */
132 1.17 thorpej struct pmap *pv_pmap; /* pmap where mapping lies */
133 1.27 nisimura vaddr_t pv_va; /* virtual address for mapping */
134 1.17 thorpej int pv_flags; /* some flags for the mapping */
135 1.17 thorpej } *pv_entry_t;
136 1.17 thorpej
137 1.17 thorpej #define PV_UNCACHED 0x0001 /* page is mapped uncached */
138 1.20 mhitch #define PV_MODIFIED 0x0002 /* page has been modified */
139 1.21 jonathan #define PV_REFERENCED 0x0004 /* page has been recently referenced */
140 1.1 deraadt
141 1.13 jonathan
142 1.8 mellon #ifdef _KERNEL
143 1.13 jonathan
144 1.27 nisimura extern char *pmap_attributes; /* reference and modify bits */
145 1.27 nisimura extern struct pmap kernel_pmap_store;
146 1.7 mycroft
147 1.27 nisimura #define pmap_kernel() (&kernel_pmap_store)
148 1.3 glass #define pmap_wired_count(pmap) ((pmap)->pm_stats.wired_count)
149 1.14 mhitch #define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count)
150 1.31 thorpej
151 1.37 chris #define pmap_update(pmap) /* nothing (yet) */
152 1.39 chs
153 1.39 chs static __inline void
154 1.40 chs pmap_remove_all(struct pmap *pmap)
155 1.39 chs {
156 1.39 chs /* Nothing. */
157 1.39 chs }
158 1.12 jonathan
159 1.12 jonathan /*
160 1.13 jonathan * Bootstrap the system enough to run with virtual memory.
161 1.13 jonathan */
162 1.38 simonb void pmap_bootstrap(void);
163 1.20 mhitch
164 1.38 simonb void pmap_set_modified(paddr_t);
165 1.25 is
166 1.38 simonb void pmap_procwr(struct proc *, vaddr_t, size_t);
167 1.25 is #define PMAP_NEED_PROCWR
168 1.13 jonathan
169 1.13 jonathan /*
170 1.28 soren * pmap_prefer() helps reduce virtual-coherency exceptions in
171 1.13 jonathan * the virtually-indexed cache on mips3 CPUs.
172 1.13 jonathan */
173 1.38 simonb #ifdef MIPS3_PLUS
174 1.46 atatat #define PMAP_PREFER(pa, va, sz, td) pmap_prefer((pa), (va), (td))
175 1.46 atatat void pmap_prefer(vaddr_t, vaddr_t *, int);
176 1.38 simonb #endif /* MIPS3_PLUS */
177 1.13 jonathan
178 1.17 thorpej #define PMAP_STEAL_MEMORY /* enable pmap_steal_memory() */
179 1.18 thorpej
180 1.18 thorpej /*
181 1.18 thorpej * Alternate mapping hooks for pool pages. Avoids thrashing the TLB.
182 1.18 thorpej */
183 1.18 thorpej #define PMAP_MAP_POOLPAGE(pa) MIPS_PHYS_TO_KSEG0((pa))
184 1.19 simonb #define PMAP_UNMAP_POOLPAGE(va) MIPS_KSEG0_TO_PHYS((va))
185 1.42 thorpej
186 1.42 thorpej /*
187 1.42 thorpej * Other hooks for the pool allocator.
188 1.42 thorpej */
189 1.43 thorpej #define POOL_VTOPHYS(va) MIPS_KSEG0_TO_PHYS((vaddr_t)(va))
190 1.38 simonb
191 1.38 simonb /*
192 1.38 simonb * Select CCA to use for unmanaged pages.
193 1.38 simonb */
194 1.38 simonb #define PMAP_CCA_FOR_PA(pa) 2 /* uncached */
195 1.13 jonathan
196 1.6 jtc #endif /* _KERNEL */
197 1.41 simonb #endif /* _MIPS_PMAP_H_ */
198