pmap.h revision 1.54.26.21 1 1.54.26.21 matt /* $NetBSD: pmap.h,v 1.54.26.21 2011/12/27 01:56:33 matt 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.54.26.17 cliff #ifdef _KERNEL_OPT
78 1.54.26.16 cliff #include "opt_multiprocessor.h"
79 1.54.26.17 cliff #endif
80 1.54.26.16 cliff
81 1.24 castor #include <mips/cpuregs.h> /* for KSEG0 below */
82 1.54.26.3 matt //#include <mips/pte.h>
83 1.18 thorpej
84 1.54.26.21 matt #if !defined(_MODULE)
85 1.1 deraadt /*
86 1.3 glass * The user address space is 2Gb (0x0 - 0x80000000).
87 1.3 glass * User programs are laid out in memory as follows:
88 1.3 glass * address
89 1.3 glass * USRTEXT 0x00001000
90 1.3 glass * USRDATA USRTEXT + text_size
91 1.3 glass * USRSTACK 0x7FFFFFFF
92 1.3 glass *
93 1.3 glass * The user address space is mapped using a two level structure where
94 1.3 glass * virtual address bits 30..22 are used to index into a segment table which
95 1.3 glass * points to a page worth of PTEs (4096 page can hold 1024 PTEs).
96 1.26 simonb * Bits 21..12 are then used to index a PTE which describes a page within
97 1.3 glass * a segment.
98 1.3 glass *
99 1.1 deraadt * The wired entries in the TLB will contain the following:
100 1.3 glass * 0-1 (UPAGES) for curproc user struct and kernel stack.
101 1.3 glass *
102 1.3 glass * Note: The kernel doesn't use the same data structures as user programs.
103 1.3 glass * All the PTE entries are stored in a single array in Sysmap which is
104 1.3 glass * dynamically allocated at boot time.
105 1.1 deraadt */
106 1.1 deraadt
107 1.22 nisimura #define mips_trunc_seg(x) ((vaddr_t)(x) & ~SEGOFSET)
108 1.22 nisimura #define mips_round_seg(x) (((vaddr_t)(x) + SEGOFSET) & ~SEGOFSET)
109 1.3 glass
110 1.54.26.14 matt #ifdef _LP64
111 1.54.26.14 matt #define PMAP_SEGTABSIZE NSEGPG
112 1.54.26.14 matt #else
113 1.54.26.1 matt #define PMAP_SEGTABSIZE (1 << (31 - SEGSHIFT))
114 1.54.26.14 matt #endif
115 1.3 glass
116 1.3 glass union pt_entry;
117 1.3 glass
118 1.54.26.14 matt union segtab {
119 1.54.26.14 matt #ifdef _LP64
120 1.54.26.14 matt union segtab *seg_seg[PMAP_SEGTABSIZE];
121 1.54.26.14 matt #endif
122 1.3 glass union pt_entry *seg_tab[PMAP_SEGTABSIZE];
123 1.3 glass };
124 1.54.26.21 matt #else
125 1.54.26.21 matt /*
126 1.54.26.21 matt * Modules don't need to know this.
127 1.54.26.21 matt */
128 1.54.26.21 matt union segtab;
129 1.54.26.21 matt #endif
130 1.1 deraadt
131 1.54.26.5 matt /*
132 1.54.26.5 matt * Structure defining an tlb entry data set.
133 1.54.26.5 matt */
134 1.54.26.5 matt struct tlb {
135 1.54.26.5 matt vaddr_t tlb_hi; /* should be 64 bits */
136 1.54.26.5 matt uint32_t tlb_lo0; /* XXX maybe 64 bits (only 32 really used) */
137 1.54.26.5 matt uint32_t tlb_lo1; /* XXX maybe 64 bits (only 32 really used) */
138 1.54.26.5 matt };
139 1.54.26.5 matt
140 1.54.26.5 matt struct tlbmask {
141 1.54.26.5 matt vaddr_t tlb_hi; /* should be 64 bits */
142 1.54.26.5 matt uint32_t tlb_lo0; /* XXX maybe 64 bits (only 32 really used) */
143 1.54.26.5 matt uint32_t tlb_lo1; /* XXX maybe 64 bits (only 32 really used) */
144 1.54.26.5 matt uint32_t tlb_mask;
145 1.54.26.5 matt };
146 1.54.26.5 matt
147 1.54.26.9 matt #ifdef _KERNEL
148 1.54.26.2 matt struct pmap;
149 1.54.26.3 matt typedef bool (*pte_callback_t)(struct pmap *, vaddr_t, vaddr_t,
150 1.54.26.3 matt union pt_entry *, uintptr_t);
151 1.54.26.3 matt union pt_entry *pmap_pte_lookup(struct pmap *, vaddr_t);
152 1.54.26.3 matt union pt_entry *pmap_pte_reserve(struct pmap *, vaddr_t, int);
153 1.54.26.2 matt void pmap_pte_process(struct pmap *, vaddr_t, vaddr_t, pte_callback_t,
154 1.54.26.2 matt uintptr_t);
155 1.54.26.9 matt void pmap_segtab_activate(struct pmap *, struct lwp *);
156 1.54.26.14 matt void pmap_segtab_init(struct pmap *);
157 1.54.26.14 matt void pmap_segtab_destroy(struct pmap *);
158 1.54.26.9 matt #endif /* _KERNEL */
159 1.54.26.2 matt
160 1.1 deraadt /*
161 1.54.26.9 matt * Per TLB (normally same as CPU) asid info
162 1.54.26.5 matt */
163 1.54.26.5 matt struct pmap_asid_info {
164 1.54.26.9 matt LIST_ENTRY(pmap_asid_info) pai_link;
165 1.54.26.9 matt uint32_t pai_asid; /* TLB address space tag */
166 1.54.26.5 matt };
167 1.54.26.5 matt
168 1.54.26.10 matt #define TLBINFO_LOCK(ti) mutex_spin_enter((ti)->ti_lock)
169 1.54.26.10 matt #define TLBINFO_UNLOCK(ti) mutex_spin_exit((ti)->ti_lock)
170 1.54.26.10 matt #define PMAP_PAI_ASIDVALID_P(pai, ti) ((pai)->pai_asid != 0)
171 1.54.26.10 matt #define PMAP_PAI(pmap, ti) (&(pmap)->pm_pai[tlbinfo_index(ti)])
172 1.54.26.9 matt #define PAI_PMAP(pai, ti) \
173 1.54.26.9 matt ((pmap_t)((intptr_t)(pai) \
174 1.54.26.9 matt - offsetof(struct pmap, pm_pai[tlbinfo_index(ti)])))
175 1.54.26.6 matt
176 1.54.26.5 matt /*
177 1.1 deraadt * Machine dependent pmap structure.
178 1.1 deraadt */
179 1.3 glass typedef struct pmap {
180 1.54.26.5 matt #ifdef MULTIPROCESSOR
181 1.54.26.9 matt volatile uint32_t pm_active; /* pmap was active on ... */
182 1.54.26.9 matt volatile uint32_t pm_onproc; /* pmap is active on ... */
183 1.54.26.9 matt volatile u_int pm_shootdown_pending;
184 1.54.26.5 matt #endif
185 1.54.26.14 matt union segtab *pm_segtab; /* pointers to pages of PTEs */
186 1.54.26.9 matt u_int pm_count; /* pmap reference count */
187 1.54.26.13 matt u_int pm_flags;
188 1.54.26.13 matt #define PMAP_DEFERRED_ACTIVATE 0x0001
189 1.54.26.1 matt struct pmap_statistics pm_stats; /* pmap statistics */
190 1.54.26.5 matt struct pmap_asid_info pm_pai[1];
191 1.3 glass } *pmap_t;
192 1.1 deraadt
193 1.54.26.9 matt enum tlb_invalidate_op {
194 1.54.26.9 matt TLBINV_NOBODY=0,
195 1.54.26.9 matt TLBINV_ONE=1,
196 1.54.26.9 matt TLBINV_ALLUSER=2,
197 1.54.26.9 matt TLBINV_ALLKERNEL=3,
198 1.54.26.9 matt TLBINV_ALL=4
199 1.54.26.9 matt };
200 1.54.26.9 matt
201 1.54.26.9 matt struct pmap_tlb_info {
202 1.54.26.12 matt char ti_name[8];
203 1.54.26.9 matt uint32_t ti_asid_hint; /* probable next ASID to use */
204 1.54.26.9 matt uint32_t ti_asids_free; /* # of ASIDs free */
205 1.54.26.10 matt #define tlbinfo_noasids_p(ti) ((ti)->ti_asids_free == 0)
206 1.54.26.9 matt kmutex_t *ti_lock;
207 1.54.26.10 matt u_int ti_wired; /* # of wired TLB entries */
208 1.54.26.10 matt uint32_t ti_asid_mask;
209 1.54.26.10 matt uint32_t ti_asid_max;
210 1.54.26.9 matt LIST_HEAD(, pmap_asid_info) ti_pais; /* list of active ASIDs */
211 1.54.26.20 matt uint32_t ti_syncicache_bitmap; /* page indices needing a syncicache */
212 1.54.26.20 matt struct evcnt ti_evcnt_syncicache_asts;
213 1.54.26.20 matt struct evcnt ti_evcnt_syncicache_all;
214 1.54.26.20 matt struct evcnt ti_evcnt_syncicache_pages;
215 1.54.26.20 matt struct evcnt ti_evcnt_syncicache_desired;
216 1.54.26.20 matt struct evcnt ti_evcnt_syncicache_duplicate;
217 1.54.26.10 matt #ifdef MULTIPROCESSOR
218 1.54.26.19 matt kmutex_t *ti_hwlock;
219 1.54.26.9 matt pmap_t ti_victim;
220 1.54.26.9 matt uint32_t ti_cpu_mask; /* bitmask of CPUs sharing this TLB */
221 1.54.26.9 matt enum tlb_invalidate_op ti_tlbinvop;
222 1.54.26.9 matt u_int ti_index;
223 1.54.26.9 matt #define tlbinfo_index(ti) ((ti)->ti_index)
224 1.54.26.20 matt struct evcnt ti_evcnt_syncipage_deferred;
225 1.54.26.9 matt #else
226 1.54.26.9 matt #define tlbinfo_index(ti) (0)
227 1.54.26.10 matt #endif
228 1.54.26.18 matt struct evcnt ti_evcnt_asid_reinits;
229 1.54.26.20 matt struct evcnt ti_evcnt_asid_reclaims;
230 1.54.26.20 matt u_long ti_asid_bitmap[1024 / (sizeof(u_long) * 8)];
231 1.54.26.9 matt };
232 1.54.26.9 matt
233 1.8 mellon #ifdef _KERNEL
234 1.13 jonathan
235 1.54.26.6 matt struct pmap_kernel {
236 1.54.26.6 matt struct pmap kernel_pmap;
237 1.54.26.6 matt #ifdef MULTIPROCESSOR
238 1.54.26.6 matt struct pmap_asid_info kernel_pai[MAXCPUS-1];
239 1.54.26.6 matt #endif
240 1.54.26.6 matt };
241 1.54.26.6 matt
242 1.54.26.6 matt extern struct pmap_kernel kernel_pmap_store;
243 1.54.26.11 matt extern struct pmap_tlb_info pmap_tlb0_info;
244 1.54.26.12 matt #ifdef MULTIPROCESSOR
245 1.54.26.12 matt extern struct pmap_tlb_info *pmap_tlbs[MAXCPUS];
246 1.54.26.12 matt extern u_int pmap_ntlbs;
247 1.54.26.12 matt #endif
248 1.54.26.20 matt extern u_int pmap_syncipage_page_mask;
249 1.54.26.20 matt extern u_int pmap_syncipage_map_mask;
250 1.54.26.4 matt extern paddr_t mips_avail_start;
251 1.54.26.4 matt extern paddr_t mips_avail_end;
252 1.54.26.4 matt extern vaddr_t mips_virtual_end;
253 1.7 mycroft
254 1.54.26.6 matt #define pmap_kernel() (&kernel_pmap_store.kernel_pmap)
255 1.3 glass #define pmap_wired_count(pmap) ((pmap)->pm_stats.wired_count)
256 1.14 mhitch #define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count)
257 1.31 thorpej
258 1.51 macallan #define pmap_phys_address(x) mips_ptob(x)
259 1.39 chs
260 1.12 jonathan /*
261 1.13 jonathan * Bootstrap the system enough to run with virtual memory.
262 1.13 jonathan */
263 1.38 simonb void pmap_bootstrap(void);
264 1.20 mhitch
265 1.54.26.12 matt void pmap_remove_all(pmap_t);
266 1.38 simonb void pmap_set_modified(paddr_t);
267 1.38 simonb void pmap_procwr(struct proc *, vaddr_t, size_t);
268 1.25 is #define PMAP_NEED_PROCWR
269 1.13 jonathan
270 1.54.26.9 matt #ifdef MULTIPROCESSOR
271 1.54.26.9 matt void pmap_tlb_shootdown_process(void);
272 1.54.26.9 matt bool pmap_tlb_shootdown_bystanders(pmap_t pmap);
273 1.54.26.9 matt void pmap_tlb_info_attach(struct pmap_tlb_info *, struct cpu_info *);
274 1.54.26.20 matt void pmap_syncicache_wanted(struct cpu_info *);
275 1.54.26.20 matt void pmap_syncicache(uint32_t, uint32_t);
276 1.54.26.9 matt #endif
277 1.54.26.20 matt void pmap_syncicache_page(struct vm_page *, uint32_t);
278 1.54.26.20 matt void pmap_syncicache_init(void);
279 1.54.26.20 matt void pmap_syncicache_ast(struct cpu_info *);
280 1.54.26.10 matt void pmap_tlb_info_init(struct pmap_tlb_info *);
281 1.54.26.18 matt void pmap_tlb_info_evcnt_attach(struct pmap_tlb_info *);
282 1.54.26.9 matt void pmap_tlb_asid_acquire(pmap_t pmap, struct lwp *l);
283 1.54.26.9 matt void pmap_tlb_asid_deactivate(pmap_t pmap);
284 1.54.26.15 matt void pmap_tlb_asid_check(void);
285 1.54.26.9 matt void pmap_tlb_asid_release_all(pmap_t pmap);
286 1.54.26.9 matt int pmap_tlb_update_addr(pmap_t pmap, vaddr_t, uint32_t, bool);
287 1.54.26.7 matt void pmap_tlb_invalidate_addr(pmap_t pmap, vaddr_t);
288 1.54.26.7 matt
289 1.13 jonathan /*
290 1.28 soren * pmap_prefer() helps reduce virtual-coherency exceptions in
291 1.13 jonathan * the virtually-indexed cache on mips3 CPUs.
292 1.13 jonathan */
293 1.38 simonb #ifdef MIPS3_PLUS
294 1.54.26.8 matt #define PMAP_PREFER(pa, va, sz, td) pmap_prefer((pa), (va), (sz), (td))
295 1.54.26.8 matt void pmap_prefer(vaddr_t, vaddr_t *, vsize_t, int);
296 1.38 simonb #endif /* MIPS3_PLUS */
297 1.13 jonathan
298 1.17 thorpej #define PMAP_STEAL_MEMORY /* enable pmap_steal_memory() */
299 1.18 thorpej
300 1.18 thorpej /*
301 1.18 thorpej * Alternate mapping hooks for pool pages. Avoids thrashing the TLB.
302 1.18 thorpej */
303 1.47 tsutsui vaddr_t mips_pmap_map_poolpage(paddr_t);
304 1.47 tsutsui paddr_t mips_pmap_unmap_poolpage(vaddr_t);
305 1.54.26.2 matt struct vm_page *mips_pmap_alloc_poolpage(int);
306 1.54.26.2 matt #define PMAP_ALLOC_POOLPAGE(flags) mips_pmap_alloc_poolpage(flags)
307 1.54.26.2 matt #define PMAP_MAP_POOLPAGE(pa) mips_pmap_map_poolpage(pa)
308 1.54.26.2 matt #define PMAP_UNMAP_POOLPAGE(va) mips_pmap_unmap_poolpage(va)
309 1.42 thorpej
310 1.42 thorpej /*
311 1.42 thorpej * Other hooks for the pool allocator.
312 1.42 thorpej */
313 1.54.26.1 matt #ifdef _LP64
314 1.54.26.1 matt #define POOL_VTOPHYS(va) (MIPS_KSEG0_P(va) \
315 1.54.26.1 matt ? MIPS_KSEG0_TO_PHYS(va) \
316 1.54.26.1 matt : MIPS_XKPHYS_TO_PHYS(va))
317 1.54.26.1 matt #else
318 1.43 thorpej #define POOL_VTOPHYS(va) MIPS_KSEG0_TO_PHYS((vaddr_t)(va))
319 1.54.26.1 matt #endif
320 1.38 simonb
321 1.38 simonb /*
322 1.38 simonb * Select CCA to use for unmanaged pages.
323 1.38 simonb */
324 1.54.26.1 matt #define PMAP_CCA_FOR_PA(pa) CCA_UNCACHED /* uncached */
325 1.13 jonathan
326 1.52 macallan #if defined(_MIPS_PADDR_T_64BIT) || defined(_LP64)
327 1.52 macallan #define PMAP_NOCACHE 0x4000000000000000ULL
328 1.52 macallan #endif
329 1.52 macallan
330 1.54.26.18 matt uint16_t pmap_pvlist_lock(struct vm_page_md *, bool);
331 1.54.26.18 matt
332 1.6 jtc #endif /* _KERNEL */
333 1.41 simonb #endif /* _MIPS_PMAP_H_ */
334