pmap.h revision 1.70 1 1.70 mrg /* $NetBSD: pmap.h,v 1.70 2017/07/24 09:56:45 mrg 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.60 matt #ifdef _KERNEL_OPT
78 1.60 matt #include "opt_multiprocessor.h"
79 1.68 matt #include "opt_uvmhist.h"
80 1.70 mrg #include "opt_cputype.h"
81 1.60 matt #endif
82 1.60 matt
83 1.64 matt #include <sys/evcnt.h>
84 1.65 matt #include <sys/kcpuset.h>
85 1.68 matt #include <sys/kernhist.h>
86 1.64 matt
87 1.68 matt #ifndef __BSD_PTENTRY_T__
88 1.68 matt #define __BSD_PTENTRY_T__
89 1.68 matt typedef uint32_t pt_entry_t;
90 1.68 matt #define PRIxPTE PRIx32
91 1.68 matt #endif /* __BSD_PTENTRY_T__ */
92 1.68 matt
93 1.68 matt #define KERNEL_PID 0
94 1.68 matt
95 1.68 matt #if defined(__PMAP_PRIVATE)
96 1.68 matt
97 1.68 matt #include <mips/locore.h>
98 1.68 matt #include <mips/cache.h>
99 1.68 matt
100 1.68 matt #define PMAP_VIRTUAL_CACHE_ALIASES
101 1.68 matt #define PMAP_INVALID_SEGTAB_ADDRESS ((pmap_segtab_t *)NULL)
102 1.68 matt #define PMAP_TLB_NEED_SHOOTDOWN
103 1.68 matt #define PMAP_TLB_FLUSH_ASID_ON_RESET false
104 1.68 matt #if UPAGES > 1
105 1.68 matt #define PMAP_TLB_WIRED_UPAGES MIPS3_TLB_WIRED_UPAGES
106 1.68 matt #endif
107 1.68 matt #define pmap_md_tlb_asid_max() (MIPS_TLB_NUM_PIDS - 1)
108 1.68 matt #ifdef MULTIPROCESSOR
109 1.68 matt #define PMAP_NO_PV_UNCACHED
110 1.68 matt #endif
111 1.68 matt
112 1.68 matt /*
113 1.68 matt * We need the pmap_segtab's to be aligned on MIPS*R2 so we can use the
114 1.68 matt * EXT/INS instructions on their addresses.
115 1.68 matt */
116 1.68 matt #if (MIPS32R2 + MIPS64R2 + MIPS64R2_RMIXL) > 0
117 1.68 matt #define PMAP_SEGTAB_ALIGN __aligned(sizeof(void *)*NSEGPG) __section(".data1")
118 1.68 matt #endif
119 1.68 matt
120 1.69 cherry #include <uvm/uvm_physseg.h>
121 1.68 matt
122 1.68 matt void pmap_md_init(void);
123 1.68 matt void pmap_md_icache_sync_all(void);
124 1.68 matt void pmap_md_icache_sync_range_index(vaddr_t, vsize_t);
125 1.68 matt void pmap_md_page_syncicache(struct vm_page *, const kcpuset_t *);
126 1.68 matt bool pmap_md_vca_add(struct vm_page *, vaddr_t, pt_entry_t *);
127 1.68 matt void pmap_md_vca_clean(struct vm_page *, int);
128 1.68 matt void pmap_md_vca_remove(struct vm_page *, vaddr_t, bool, bool);
129 1.69 cherry bool pmap_md_ok_to_steal_p(const uvm_physseg_t, size_t);
130 1.68 matt bool pmap_md_tlb_check_entry(void *, vaddr_t, tlb_asid_t, pt_entry_t);
131 1.68 matt
132 1.68 matt static inline bool
133 1.68 matt pmap_md_virtual_cache_aliasing_p(void)
134 1.68 matt {
135 1.68 matt return MIPS_CACHE_VIRTUAL_ALIAS;
136 1.68 matt }
137 1.68 matt
138 1.68 matt static inline vsize_t
139 1.68 matt pmap_md_cache_prefer_mask(void)
140 1.68 matt {
141 1.68 matt return MIPS_HAS_R4K_MMU ? mips_cache_info.mci_cache_prefer_mask : 0;
142 1.68 matt }
143 1.68 matt #endif /* __PMAP_PRIVATE */
144 1.68 matt
145 1.68 matt struct tlbmask {
146 1.68 matt vaddr_t tlb_hi;
147 1.68 matt #ifdef __mips_o32
148 1.68 matt uint32_t tlb_lo0;
149 1.68 matt uint32_t tlb_lo1;
150 1.68 matt #else
151 1.68 matt uint64_t tlb_lo0;
152 1.68 matt uint64_t tlb_lo1;
153 1.68 matt #endif
154 1.68 matt uint32_t tlb_mask;
155 1.68 matt };
156 1.68 matt
157 1.68 matt #ifdef _LP64
158 1.68 matt #define PMAP_SEGTABSIZE NSEGPG
159 1.68 matt #else
160 1.68 matt #define PMAP_SEGTABSIZE (1 << (31 - SEGSHIFT))
161 1.68 matt #endif
162 1.68 matt
163 1.68 matt #include <uvm/pmap/vmpagemd.h>
164 1.68 matt #include <uvm/pmap/pmap.h>
165 1.68 matt #include <uvm/pmap/pmap_tlb.h>
166 1.68 matt #include <uvm/pmap/pmap_synci.h>
167 1.68 matt
168 1.68 matt #ifdef _KERNEL
169 1.68 matt /*
170 1.68 matt * Select CCA to use for unmanaged pages.
171 1.68 matt */
172 1.68 matt #define PMAP_CCA_FOR_PA(pa) CCA_UNCACHED /* uncached */
173 1.68 matt
174 1.68 matt #if defined(_MIPS_PADDR_T_64BIT) || defined(_LP64)
175 1.68 matt #define PGC_NOCACHE 0x4000000000000000ULL
176 1.68 matt #define PGC_PREFETCH 0x2000000000000000ULL
177 1.68 matt #endif
178 1.68 matt
179 1.68 matt #if defined(__PMAP_PRIVATE)
180 1.68 matt #include <mips/pte.h>
181 1.68 matt #endif
182 1.18 thorpej
183 1.1 deraadt /*
184 1.3 glass * The user address space is 2Gb (0x0 - 0x80000000).
185 1.3 glass * User programs are laid out in memory as follows:
186 1.3 glass * address
187 1.3 glass * USRTEXT 0x00001000
188 1.3 glass * USRDATA USRTEXT + text_size
189 1.3 glass * USRSTACK 0x7FFFFFFF
190 1.3 glass *
191 1.3 glass * The user address space is mapped using a two level structure where
192 1.3 glass * virtual address bits 30..22 are used to index into a segment table which
193 1.3 glass * points to a page worth of PTEs (4096 page can hold 1024 PTEs).
194 1.26 simonb * Bits 21..12 are then used to index a PTE which describes a page within
195 1.3 glass * a segment.
196 1.3 glass *
197 1.1 deraadt * The wired entries in the TLB will contain the following:
198 1.3 glass * 0-1 (UPAGES) for curproc user struct and kernel stack.
199 1.3 glass *
200 1.3 glass * Note: The kernel doesn't use the same data structures as user programs.
201 1.3 glass * All the PTE entries are stored in a single array in Sysmap which is
202 1.3 glass * dynamically allocated at boot time.
203 1.1 deraadt */
204 1.1 deraadt
205 1.51 macallan #define pmap_phys_address(x) mips_ptob(x)
206 1.39 chs
207 1.12 jonathan /*
208 1.13 jonathan * Bootstrap the system enough to run with virtual memory.
209 1.13 jonathan */
210 1.38 simonb void pmap_bootstrap(void);
211 1.68 matt void pmap_md_alloc_ephemeral_address_space(struct cpu_info *);
212 1.38 simonb void pmap_procwr(struct proc *, vaddr_t, size_t);
213 1.25 is #define PMAP_NEED_PROCWR
214 1.13 jonathan
215 1.13 jonathan /*
216 1.28 soren * pmap_prefer() helps reduce virtual-coherency exceptions in
217 1.13 jonathan * the virtually-indexed cache on mips3 CPUs.
218 1.13 jonathan */
219 1.38 simonb #ifdef MIPS3_PLUS
220 1.60 matt #define PMAP_PREFER(pa, va, sz, td) pmap_prefer((pa), (va), (sz), (td))
221 1.60 matt void pmap_prefer(vaddr_t, vaddr_t *, vsize_t, int);
222 1.38 simonb #endif /* MIPS3_PLUS */
223 1.13 jonathan
224 1.63 skrll #define PMAP_ENABLE_PMAP_KMPAGE /* enable the PMAP_KMPAGE flag */
225 1.18 thorpej
226 1.68 matt // these use register_t so we can pass XKPHYS adddresses to them on N32
227 1.68 matt bool pmap_md_direct_mapped_vaddr_p(register_t);
228 1.68 matt paddr_t pmap_md_direct_mapped_vaddr_to_paddr(register_t);
229 1.68 matt bool pmap_md_io_vaddr_p(vaddr_t);
230 1.66 matt
231 1.18 thorpej /*
232 1.18 thorpej * Alternate mapping hooks for pool pages. Avoids thrashing the TLB.
233 1.18 thorpej */
234 1.68 matt vaddr_t pmap_md_map_poolpage(paddr_t, size_t);
235 1.68 matt paddr_t pmap_md_unmap_poolpage(vaddr_t, size_t);
236 1.68 matt struct vm_page *pmap_md_alloc_poolpage(int);
237 1.42 thorpej
238 1.42 thorpej /*
239 1.42 thorpej * Other hooks for the pool allocator.
240 1.42 thorpej */
241 1.68 matt paddr_t pmap_md_pool_vtophys(vaddr_t);
242 1.68 matt vaddr_t pmap_md_pool_phystov(paddr_t);
243 1.68 matt #define POOL_VTOPHYS(va) pmap_md_pool_vtophys((vaddr_t)va)
244 1.68 matt #define POOL_PHYSTOV(pa) pmap_md_pool_phystov((paddr_t)pa)
245 1.60 matt
246 1.70 mrg #ifdef MIPS64_SB1
247 1.70 mrg /* uncached accesses are bad; all accesses should be cached (and coherent) */
248 1.70 mrg #undef PMAP_PAGEIDLEZERO
249 1.70 mrg #define PMAP_PAGEIDLEZERO(pa) (pmap_zero_page(pa), true)
250 1.70 mrg
251 1.70 mrg int sbmips_cca_for_pa(paddr_t);
252 1.70 mrg
253 1.70 mrg #undef PMAP_CCA_FOR_PA
254 1.70 mrg #define PMAP_CCA_FOR_PA(pa) sbmips_cca_for_pa(pa)
255 1.70 mrg #endif
256 1.70 mrg
257 1.6 jtc #endif /* _KERNEL */
258 1.41 simonb #endif /* _MIPS_PMAP_H_ */
259